Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ifdef command not found (GNU make 3.81)

Tags:

gnu-make

I have the following makefile for a simple helloWorld program:

helloWorld: helloWorld.cpp
        echo "Argument entered is $(foo)"
        ifdef foo
        echo "Defined.";
        else
        echo "Not defined.";
        endif
        g++ -Wall -pedantic -g helloWorld.cpp -o h 

When I invoke make from the command line like so: make foo=bar, I get the following error:

bar
"not set"
echo "Argument entered is bar"
Argument entered is bar
ifdef foo
make: ifdef: Command not found
make: *** [helloWorld] Error 127

I have gone through some of the links here on SO regarding this error but have not yet been able to solve this issue.

like image 944
Sriram Avatar asked Jun 03 '15 16:06

Sriram


1 Answers

Your syntax is wrong. You have the make directives (ifdef, else and endif) indented like shell commands.

See Example of a Conditional in the GNU make manual for how to do exactly this sort of thing.

libs_for_gcc = -lgnu
normal_libs =

foo: $(objects)
ifeq ($(CC),gcc)
        $(CC) -o foo $(objects) $(libs_for_gcc)
else
        $(CC) -o foo $(objects) $(normal_libs)
endif
like image 124
Etan Reisner Avatar answered Nov 14 '22 04:11

Etan Reisner