Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

makefile if condition outside rule

I have makefile if condition like this outside of rules:

ifneq ("$(wildcard ${EXT}/CHECK)","")
    $(info "external binaries exist")
else
    @mkdir -p ${EXT}; \
    cd ${EXT}; \
    scp sam@192.168.10.1:/media/data/external/${BINARY} . ; \
    echo "" > CHECK; \
    cd ..;
endif

I am ggeting following error:

 *** recipe commences before first target.  Stop.

at this line: @mkdir -p ${EXT}; \

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I want to make sure this lines are running before any rule. Because I set some variables based on this.

>Solution :

This doesn’t have anything to do with if conditions.

Makefiles are not shell scripts. You can’t just write a shell script into a makefile and expect them to be executed. They are syntax errors, as you’ve seen, because makefiles are not shell scripts.

Makefiles can contain shell scripts, but only in the context of a recipe of a rule.

I don’t understand why you want to do this outside the context of a rule but the only way to do it is with the shell function:

_dummy := $(shell mkdir -p ${EXT} && \
    cd ${EXT} && \
    scp sam@192.168.10.1:/media/data/external/${BINARY} . && \
    echo "" > CHECK)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading