Typical makefiles often use the built-in variables CFLAGS
, CXXFLAGS
, CPPFLAGS
and so on1 to set the flags passed to the C,
Just stumbled upon the same question while building an RPM with debuginfo package.
The requirement for debuginfo generation is to pass -g
in CFLAGS
while preserving whatever CFLAGS
the software has in its Makefile
.
So if you want to add some extra bits to CFLAGS
, without overwriting the ones present in Makefile
, you can simply use CFLAGS
as an environment variable. But only as long as the Makefile
in question uses CFLAGS += ...
notation.
Example, suppose that you have software with Makefile
having:
CFLAGS += $(ARCH) -O3 -std=gnu11 -Wall ...
To have it build with all those flags and -g
, you will do:
CFLAGS='-g' make
Note that passing it as an argument to make
won't work, as in: make CFLAGS='-g'
is wrong, because it will overwrite internal CFLAGS
.
More on the solution to pass -g for building debuginfo packages properly
Here's reference on make: appending to variables.