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

Matthias Andree ma at
Wed Sep 8 06:12:45 PDT 2004

John Polstra <jdp at> writes:

> I'm afraid if I do that, I'll get even more bug reports.

Likely, because it tells the user what NOT to do,
but does not tell him what to do, and he'll inquire about that.

The BROKEN message should print that the user must use -O1 rather than
-O2 or -O3 for this particular port.

Note that "-O." isn't a sufficient regexp, some users use -O99 which,
when it becomes -O19 or -O9 still hoses the build of the b0rked

How about:

CFLAGS:=    ${CFLAGS:C/-O[s1-9][0-9]*/-O1/g}

This degrades all -O options (including -Os!) to -O1 but leaves -O and
-O0 alone.

> 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.

I second that.

> 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.

Let's just write the Makefile line given above into the porters-handbook ;-)

Matthias Andree

Encrypted mail welcome: my GnuPG key ID is 0x052E7D95 (PGP/MIME preferred)

More information about the freebsd-ports mailing list