I've got a Makefile that includes another makefile that sets a lot of defaults. I can't edit the included makefile and I'd like to change the value of C++FLAGS in my makefile even though it is set in the included makefile. Specifically, I'd like to remove the optimization flag from C++FLAGS whenever debug=1.
I tried the following:
C++FLAGS=$(filter-out -O3,$(C++FLAGS))
Which fails with the following error:
Recursive variable `C++FLAGS' references itself (eventually). Stop.
It seems like doing something like this should be possible, anybody know the secret?
CFLAGS and CXXFLAGS are either the name of environment variables or of Makefile variables that can be set to specify additional switches to be passed to a compiler in the process of building computer software.
It should be CFLAGS := -Wall -Wextra $(CFLAGS) , the difference is that CFLAGS is explicitly appended. So for example, you may set -Og , but user don't want optimization and passes CFLAGS=-O0 on command line. By using CFLAGS += -Og your -Og will take over the user provided value.
The only way of doing that is to edit the makefile to change the options. There is no convenient way to override the options without modifying the makefile . This is where make flags come into play. Flags in make are just variables containing options that should be passed to the tools used in the compilation process.
C++FLAGS:=$(filter-out -O3,$(C++FLAGS))
The :=
assignment immediately evaluates the rvalue and this should therefore work. =
on the other hand has delayed expansion semantics (i.e. the C++FLAGS
will expand whenever the lvalue gets used, which leads to recursion).
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