makefile if condition outside rule

makefile if condition outside rule

Problem Description:

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 [email protected]:/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};

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

Solution – 1

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 [email protected]:/media/data/external/${BINARY} . && 
    echo "" > CHECK)
Rate this post
We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Accept
Reject