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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With