Subject: Re: mk.conf & compiler flags
To: Dunric <dunric@centrum.cz>
From: Tyler Mitchell <fission@ldx.ca>
List: netbsd-help
Date: 02/02/2005 18:58:55
On Thu, 3 Feb 2005, Dunric wrote:

> Are there some rules how C/C++ compiler flags has to be properly set in 
> /etc/mk.conf ?
> 
> NetBSD's kernel + userland are using COPTS, both CFLAGS and CXXFLAGS 
> applies too. NetBSD's X11 on the other hand ignores COPTS completely - a 
> bit confusing.
>
> Pkgsrc ports are ignoring COPTS too, again CFLAGS & CXXFLAGS are used.

It's for this reason that I've found it easiest to simply use CFLAGS. 
Some packages (and perhaps parts of the system) don't use it, but as long 
as most do, that's good enough for me.

> There is another problem, because some ports define in CFLAGS some 
> important options(defines,paths) without them compilation fails so I 
> cann't replace it with my own :( When I add my options(+=), some builds 
> are compiled in some cases with wild collision flags like "-mcpu=i386" 
> ...

To avoid this, I do the following in /etc/mk.conf:


THECFLAGS=-O2 -pipe -march=athlon-tbird -mmmx -m3dnow
.if !defined(COPTS)
CFLAGS+=${THECFLAGS}
.else
.if empty(COPTS:M-mcpu*) && empty(COPTS:M-O[01s])
CFLAGS+=${THECFLAGS}
.endif
.endif


That avoids the problems I used to encounter doing full builds.  This 
particular example is good only for i386 builds; I suppose I'd have to add 
some more conditions for other ports.

IIRC, you should only add (+=) to CFLAGS, or else things break.

[Aside: does anyone know why .elif didn't work there?  I'm stumped.]

-- 
Tyler Mitchell <fission@ldx.ca> . . . . . . . . http://www.ldx.ca/