Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 20 Aug 2004 10:44:58 +0200
From:      Oliver Eikemeier <eikemeier@fillmore-labs.com>
To:        current@freebsd.org
Subject:   setting CFLAGS in /etc/make.conf
Message-ID:  <377474F4-F285-11D8-A951-00039312D914@fillmore-labs.com>

next in thread | raw e-mail | index | archive | help
I have a problem with the following recommendation in 
src/share/examples/etc/make.conf:

# CFLAGS controls the compiler settings used when compiling C code.
# Note that optimization settings other than -O and -O2 are not 
recommended
# 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:

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

.ifmake cflags
CFLAGS+=        -DBAR
.endif

cflags:
	@${ECHO} "CFLAGS=${CFLAGS}"

with the output:

CFLAGS=-O -pipe ${_CPUCFLAGS} -DFOO ${_CPUCFLAGS} -DBAR

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

CFLAGS=	-O -pipe

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

CFLAGS=-O -pipe ${_CPUCFLAGS} -DBAR

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

One solution would be to set __MAKE_CONF=/dev/null in bsd.port.mk, 
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 
value.

Thoughs?
-Oliver



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?377474F4-F285-11D8-A951-00039312D914>