question about CFLAGS, CXXFLAGS and DEBUG_FLAGS

Peter Pentchev roam at ringlet.net
Sun Dec 19 12:11:10 UTC 2010


On Sat, Dec 18, 2010 at 09:24:31PM +0000, Alexander Best wrote:
> On Sat Dec 18 10, Peter Pentchev wrote:
> > On Sat, Dec 18, 2010 at 08:09:37PM +0000, Alexander Best wrote:
> > > hi there,
> > > 
> > > i just stumbled over these lines:
> > > 
> > > otaku% grep -n \${DEBUG_FLAGS} /usr/share/mk/bsd.prog.mk
> > > 24:CFLAGS+=${DEBUG_FLAGS}
> > > 25:CXXFLAGS+=${DEBUG_FLAGS}
> > > 
> > > is it really necessary to assign the debug flags to both CFLAGS *and* CXXFLAGS?
> > 
> > Uhm... yes, so they can be used in both C and C++ programs :)
> > ...or are you making the mistake I've made too many times (and still
> > make sometimes) of confusing CXXFLAGS with CPPFLAGS? :)
> 
> *hehehe* i don't think so.

Nah, just making sure, no offense intended :)

> i just saw a lot of these lines in buildworld:
> 
> clang++ -O2 -pipe -DNDEBUG -g -I/usr/obj/usr/subversion-src/tmp/legacy/usr/include -I/usr/subversion-src/gnu/usr.bin/gperf/../../../contrib/gperf/lib -I/usr/subversion-src/gnu/usr.bin/gperf -g -c /usr/subversion-src/gnu/usr.bin/gperf/../../../contrib/gperf/lib/hash.cc
> clang++: warning: argument unused during compilation: '-g'
> clang++: warning: argument unused during compilation: '-g'
> 
> as you can see -g gets specified twice, so i thought maybe adding -g to
> CFLAGS makes adding it to CXXFLAGS obsolete.

Well, according to my copy of src/share/mk/sys.mk (8.x-STABLE),
if the user does not override CXXFLAGS, they are copied from CFLAGS
with some exceptions.  Thus, it does seem sensible to add -g to
both sets of flags - yes, if no CXXFLAGS are specified, the -g will
be doubled, but if CXXFLAGS *are* specified in the environment or on
the make(1) command line, then only one -g will be added.

Maybe a better solution could be to somehow test for empty CXXFLAGS
in sys.mk and set another variable that says "we've copied those over",
and then only add DEBUG_FLAGS to CXXFLAGS if that variable is not set,
but I'm not sure if it's really worth it.

Thanks for bringing this up - I wasn't aware of the fact that CXXFLAGS
were copied over unless overridden :)  Learn something new every day,
I guess.

G'luck,
Peter

-- 
Peter Pentchev	roam at space.bg    roam at ringlet.net    roam at FreeBSD.org
PGP key:	http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint	FDBA FD79 C26F 3C51 C95E  DF9E ED18 B68D 1619 4553
No language can express every thought unambiguously, least of all this one.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20101219/a93c59b4/attachment.pgp


More information about the freebsd-hackers mailing list