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?
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 .
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.
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.
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.
Doesn't the following work for you?
unexport CFLAGS 3rdparty: $(MAKE) -f Makefile.3rdparty
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