Best way to override user's CFLAGS in a port?

John Polstra jdp at
Tue Sep 7 11:48:18 PDT 2004

On 07-Sep-2004 Oliver Eikemeier wrote:
> John Polstra wrote:
>> The ezm3 port has to be built with an optimization level of -O, and
>> that's not likely to change any time soon.  Some users, especially
>> users of -current where -O2 is officially supported, are getting
>> burned by that.  What is the best way for me to change the ezm3 port's
>> Makefile so that -O will be used regardless of the user's environment
>> or /etc/make.conf settings?
> The Porters Handbook 
> <
> handbook/dads-cflags.html> tells you to respect CFLAGS, which means you 
> should add
> .if defined(CFLAGS) && !empty(CFLAGS:M-O[2-9]*)
> BROKEN=               "Doesn't build with ${CFLAGS:M-O[2-9]*}"
> .endif
> to your port, so that a user could use a workaround in make.conf(5) when 
> necessary.

I'm afraid if I do that, I'll get even more bug reports.  More and
more -current users are adding -O2 to their CFLAGS in /etc/make.conf.
Surely all of them would prefer having the port build properly than
having it fail intentionally.

The Porter's Handbook text seems mainly to say that the port should
append to CFLAGS with "+=" rather than simply clobbering it with "=".
That makes sense.  But it seems reasonable for the port to remove a
specific setting (-O[2-9]) from CFLAGS if the porter knows that that
setting will break the port.  It's not quite the same as clobbering
CFLAGS totally.

> Specifying CFLAGS in make.conf(5) is problematic for ports 
> anyways, see <
> current/2004-August/034763.html> (an example for a problematic port is 
> net/obnc, which misses -DIPSEC).
> If you just want a dirty hack, you could use
> CFLAGS:=              ${CFLAGS:N-O*} -O
> but this won't work with recent make(1)s when CFLAGS is specified on the 
> command line, and might lead to other problems. I guess the first 
> solution is preferred.

The ezm3 port's Makefile is already a bit strange, because it invokes
${GMAKE} itself in a special do-install target.  I can strip off the
-O[2-9] there.  I was just wondering if there was a more official
way to do it.


More information about the freebsd-ports mailing list