setting CFLAGS in /etc/make.conf

Oliver Eikemeier eikemeier at
Fri Aug 20 01:45:04 PDT 2004

I have a problem with the following recommendation in 

# CFLAGS controls the compiler settings used when compiling C code.
# Note that optimization settings other than -O and -O2 are not 
# or supported for compiling the world or the kernel - please revert any
# nonstandard optimization settings to "-O" before submitting bug reports
# without patches to the developers.
# Note also that at this time the -O2 setting is known to expose bugs in
# libalias(3), and possibly other parts of the system.
#CFLAGS= -O -pipe

Basically, when a port tries to pass CFLAGS to the distribution 
Makefile, this is done by
   env CFLAGS="${CFLAGS}" make
which is effectively overwritten by users setting CFLAGS in 
make.conf(5). OTOH when += is used, it inherits the previous values, so 
when someone would do
CFLAGS+=	-O -pipe
in make.conf(5) the effective value passed is "-O -pipe -O -pipe 
${_CPUCFLAGS}", which is not harmful, but not good either. This is 
especially problematic when the port uses CFLAGS="${PTHREAD_CFLAGS}" or 
CFLAGS="-DMY_OPTION", and a lot of ports use CFLAGS. This is no problem 
when the port has USE_GMAKE, since gmake doesn't read make.conf(5).

The following Makefile illustrates the problem:

	@env CFLAGS="${CFLAGS} -DFOO" ${MAKE} cflags

.ifmake cflags
CFLAGS+=        -DBAR


with the output:


Basically this is the expected result, although the ${_CPUCFLAGS} is 
unfortunately doubled. This is what a typical port would see. When I now 

CFLAGS=	-O -pipe

in make.conf(5), which is the example given in 
share/examples/etc/make.conf, I get:


so I loose the settings done in the ports Makefile (-DFOO).

One solution would be to set __MAKE_CONF=/dev/null in, 
another solution is to deprecate setting CFLAGS in make.conf(5), or use 
an alternate variable.

Generally I believe it is unexpected that an reexecution of make(1) 
overwrites CFLAGS explicitly passed in the environment, so deprecating 
its usage is my favorite option here. Btw, passing CFLAGS in the command 
line is not an option, since Makefiles need to be able to add to the 


More information about the freebsd-current mailing list