Make an error for ifeq: syntax error near unexpected token

I am writing a Makefile that does string matching in one place, the code is similar:

if test ...; \ then \ shell scripts... \ fi ifeq ($(DIST_TYPE),nightly) shell scripts ... endif 

Here, the first if is the shell of the script, the second ifeq is the GNU Make conditional. However, the following error generates:

ifeq (night, night)

/ bin / sh: -c: line 0: syntax error near unexpected token `nightly, nightly '

/ bin / sh: -c: line 0: `ifeq (night, night) '

What's going on here? Make seems to be trying to invoke a wrapper.

Thank.

+38
makefile
Dec 19 2018-10-19
source share
2 answers

I played around the code and found that conditional statements should be written without indentation, and this solved my problem.

If there is no indentation, Make will consider it as a directive for himself; otherwise, it is treated as a shell script.

Code example

Wrong:

 target: ifeq (foo, bar) ... endif 

Right:

 target: ifeq (foo, bar) ... endif 
+133
Dec 19 '10 at 14:50
source share

In addition, if conditional statements are used in the definition functions, for example:

 define myFunc ifeq (foo, bar) ... endif enddef 

In this case, Make will also treat it as a shell script.

This problem can be solved using an if function:

 define myFunc $(if condition,then-part[,else-part]) enddef 
+2
Oct 16 '16 at 4:37
source share



All Articles