Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile variables from command line vs. environment

Tags:

Is there a way to detect whether a variable has been set from the environment vs. on the command line?

I would like to distinguish between someone invoking make with make LIB=mylib vs. make and $LIB being defined.

like image 208
pythonic metaphor Avatar asked Oct 21 '09 19:10

pythonic metaphor


1 Answers

Yes. You can use the origin function to determine where a variable was defined.

ifneq (,$(findstring environment,$(origin LIB)))
    # LIB was defined by the environment
else
    # LIB was defined some other way
endif
like image 70
Michael Aaron Safyan Avatar answered Sep 22 '22 02:09

Michael Aaron Safyan