setting CFLAGS in /etc/make.conf

Garance A Drosihn drosih at
Fri Aug 20 03:52:52 PDT 2004

At 10:44 AM +0200 8/20/04, Oliver Eikemeier wrote:
>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).

Back in March I was working on an updated version of the net/cap
port, and I noticed this problem with CFLAGS in /etc/make.conf vs
CFLAGS in the makefile of a port.  (So I am pretty sure this issue
has nothing to do with the recent changes to `make'.)

What I ended up doing was changing the net/cap/Makefile to set
CAP_CFLAGS instead of CFLAGS.  The distributed net/cap source has
a bunch of Makefile.m4 files which are used to generate the real
makefiles, and those Makefile.m4 files were already adding a bunch
of values to CFLAGS.  So, I changed a line (in net/cap/Makefile)

${FIND} ${WRKSRC} -name Makefile.m4 \
                   -exec ${REINPLACE_CMD} \
                   -e 's/CFLAGS=/CFLAGS+=/' \{\} \;


${FIND} ${WRKSRC} -name Makefile.m4 \
                   -exec ${REINPLACE_CMD} \
                   -e "s/CFLAGS=/CFLAGS+=${CAP_CFLAGS} /" \{\} \;

I meant to follow up on this issue on the freebsd-ports mailing
list, but I guess I never got around to mentioning it.  As near as
I could tell, it is just a bad idea for a ports-makefile to depend
on setting CFLAGS.  The fix I went with for net/cap probably will
not make sense for many other ports, but it was the easy fix based
on what net/cap/Makefile was already doing.

[note that I have not sent in that updated CAP port.  What I have
seems to work fine on FreeBSD-5.x on i386, but I wanted to see if
I could get it working on sparc64, and to also include some bug
fixes that I have made to cap at RPI]

Garance Alistair Drosehn            =   gad at
Senior Systems Programmer           or  gad at
Rensselaer Polytechnic Institute    or  drosih at

More information about the freebsd-current mailing list