Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to "unset" an environment variable in a Makefile?

Tags:

I'm using GNU make, and including a 3rd party library in a project that has a build system that goes berserk if CFLAGS is defined in the environment when it is called. I like to have CFLAGS defined in my environment for other reasons. The library's build is being invoked from another makefile, so that I say e.g.:

3rdparty: $(MAKE) -f Makefile.3rdparty

But I would like to be sure that CFLAGS is unset when I invoke make on the 3rd party Makefile. The nearest thing I can find is to say:

CFLAGS:=

But this still leaves CFLAGS set in the environment, it's just an empty string. Apart from doing something hideous like saying:

3rdparty: bash -c "unset CFLAGS; $(MAKE) -f Makefile.3rdparty"

Is there an easy way to "unset" the CFLAGS variable from within my primary makefile, so that it isn't present at all in the environment when the third party library is invoked?

like image 676
Jay Walker Avatar asked Feb 02 '10 22:02

Jay Walker


People also ask

How do you unset a variable in Makefile?

You have to give the NAME of the variable to undefine. Make will expand the argument to undefine so if the variable ENV_VAR_TEST is set to the value foo , then undefine ${ENV_VAR_TEST} runs undefine foo . You want to use undefine ENV_VAR_TEST .

How do I unset an environment variable?

To unset an environment variable from Command Prompt, type the command setx variable_name “”. For example, we typed setx TEST “” and this environment variable now had an empty value.

Are Makefile variables environment variables?

Variables in make can come from the environment in which make is run. Every environment variable that make sees when it starts up is transformed into a make variable with the same name and value. However, an explicit assignment in the makefile, or with a command argument, overrides the environment.

How do I unset an environment variable in terminal?

To unset the variable simply set the value of variable to '' . c.) Here, we created a local variable VAR2 and set it to a value. Then in-order to run a command temporarily clearing out all local and other environment variables, we executed 'env –i' command.


1 Answers

Doesn't the following work for you?

unexport CFLAGS 3rdparty:         $(MAKE) -f Makefile.3rdparty 
like image 97
P Shved Avatar answered Sep 30 '22 18:09

P Shved