0
votes

AFAICT, ifdef in make works only for variables defined in the Makefile. Is there a way to check whether an environment variable is defined?

1
Not sure but... you might be looking for the origin function?G.M.
@G.M. Looked it up and looks very promising. Will give it a shot tomorrow. Thanks!bob.sacamento
All variables from the environment are imported as make variables. So ifdef works for environment variables as well. You only need origin if you want to behave differently depending on whether the variable was defined in the environment vs. makefile vs. command line etc.MadScientist
@MadScientist Don't know what the deal is, but I tried and tried with ifdef. Just would not give me anything. origin gives me what I need. Thanks.bob.sacamento

1 Answers

0
votes

I don't know what you're doing (it's always best to include an actual example of what you have tried) but it definitely works:

$ cat Makefile
ifdef FOO
$(info FOO is defined)
endif
all:;@:

$ make

$ FOO=1 make
FOO is defined