Conditional Makefile Error

I am trying to make a make statement to test the architecture. I am very close to getting it to work:

test: ifeq ("$(shell arch)", "armv7l") echo "This is an arm system" else echo "This is not an arm system." endif 

I have one problem: although this seems to resolve ifeq ("i386", "armv7l") , which should be false, I get the following error:

 $ make ifeq ("i386", "armv7l") /bin/sh: -c: line 0: syntax error near unexpected token `"i386",' /bin/sh: -c: line 0: `ifeq ("i386", "armv7l")' make: *** [test] Error 2 

Thus, it solves two lines in comparison with each other, but there is a syntax error. What is wrong here?

+6
source share
2 answers

You cannot use ifeq type ifeq inside a recipe. Recipes (lines starting with TAB) are passed to the shell. The shell does not understand ifeq ; what make make.

You will need to use if shell instructions inside the recipe. And you do not need to use $(shell ...) in the recipe because you are already in the shell.

 test: if [ `arch` = armv7l ]; then \ echo "This is an arm system"; \ else \ echo "This is not an arm system."; \ fi 

Most likely, this is not the best way to handle this, but since you have not provided any information about what you are really trying to do with it, all that we can say.

+9
source

As MadScientist said, make passes ifeq strings to the shell, but if you write them correctly, you can mix make make like ifeq with the commands in the recipe. You just need to understand how make parses a Makefile :

If a line begins with TAB , it is considered a command for the shell , regardless of where the line is inside the file .

If it does not start with TAB , make interprets it as part of its language.

So, to fix your file, just don't run conditional make statements with TAB :

 test: ifeq ("$(shell arch)", "armv7l") echo "This is an arm system" else echo "This is not an arm system." endif 
+11
source

Source: https://habr.com/ru/post/949331/


All Articles