I am trying to use a conditional in my makefile. I need to set a variable depending on the presence or absence of a command line option.
There’s an example here:
This example shows how to test make flags with
findstringandMAKEFLAGS. Run this example withmake -ito see it print out the echo statement.
all:
# Search for the "-i" flag. MAKEFLAGS is just a list of single characters, one per flag. So look for "i" in this case.
ifneq (,$(findstring i, $(MAKEFLAGS)))
echo "i was passed to MAKEFLAGS"
endif
Now, i seems to be a special case. I changed i which works to a and got an error
make: invalid option -- 'a'
There’s a similar example on the GNU site which uses t. When I tried that, the echo was ignored, but the command touch all was executed.
It seems to me that I cannot use an undefined option letter. If I reuse an existing letter, sometimes it overrides the default meaning (I cannot use -i both for my conditional and also to ignore errors), and sometimes the conditional fails.
What’s going on? How can I control a make variable from the command line?
I am using GNU make 4.3 on Linux Mint 22.3.