waf vs enrionment CPPFLAGS and LDFLAGS

Ralph Böhme rb at sernet.de
Tue Oct 28 11:24:02 MDT 2014


On Tue, Oct 28, 2014 at 09:26:42AM -0700, Jeremy Allison wrote:
> On Tue, Oct 28, 2014 at 12:22:50PM +0100, Ralph Böhme wrote:
> > On Tue, Oct 28, 2014 at 12:05:00PM +0100, Ralph Böhme wrote:
> > > Hi Jeremy,
> > > 
> > > On Mon, Oct 27, 2014 at 05:04:26PM -0700, Jeremy Allison wrote:
> > > > On Mon, Oct 27, 2014 at 06:25:28PM +0100, Ralph Böhme wrote:
> > > > > Hi all,
> > > > > 
> > > > > I think I've come across a behaviour in waf which I'd consider a bug [1]:
> > > > > 
> > > > > when building the C compiler invocation for compiling or linking, waf
> > > > > places the environment varialbles CPPFLAGS and LDFLAGS *before* all
> > > > > internal flags computed at the configuration stage.
> > > > > 
> > > > > The templates come from buildtools/wafadmin/Tools/cc.py:
> > > > > 
> > > > > cc_str = '${CC} ${CCFLAGS} ${CPPFLAGS} ${_CCINCFLAGS} ${_CCDEFFLAGS} ${CC_SRC_F}${SRC} ${CC_TGT_F}${TGT}'
> > > > > link_str = '${LINK_CC} ${CCLNK_SRC_F}${SRC} ${CCLNK_TGT_F}${TGT[0].abspath(env)} ${LINKFLAGS}'
> > > > > 
> > > > > As a result, a Samba build will erroneously pick up headers or
> > > > > libraries from the paths specified in the environment variables, no
> > > > > matter what the waf build script intention is.
> > > > > 
> > > > > This manifested in a broken build of Samba 4.1.12 with Macport on OS
> > > > > X. Macports passed CPPFLAGS=-I/some/path to waf configure where in
> > > > > /some/path happened to exist GSSAPI headers. The internal heimdal
> > > > > build then picked up those headers instead of the internal copies,
> > > > > because -I/some/path was put infront of the internal include.
> > > > > 
> > > > > Note that this is NOT specifically related to our GSSAPI/Heimdal
> > > > > build, it's a general waf bug. The immediate fix is:
> > > > > 
> > > > > <http://git.samba.org/?p=slow/samba.git;a=commitdiff;h=2429a9f65c0da893c5e843fa52568a913b388bfc>
> > > > > 
> > > > > Fwiw, this bug is still present in upstream waf.
> > > > 
> > > > Ralph, have you submitted this upstream ?
> > > 
> > > I tried, but I failed. :/ Thomas silently dropped my posts to
> > > waf-users twice. After pinging him by mail all I could get out of him
> > > was a request to file a bugreport. I'll do that now.
> > 
> > <https://code.google.com/p/waf/issues/detail?id=1505>
> 
> Great - thanks. Can you re-submit your waf fix for
> the Samba tree and I'll review asap.

It's a hack, not a fix! ;) From the commit message:

    Just a hack to show what's needed, the proper fix would habe to
    somehow fixup the template strings in wafsamba/.

Cheerio!
-slow
-------------- next part --------------
>From 2429a9f65c0da893c5e843fa52568a913b388bfc Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Sat, 25 Oct 2014 04:56:23 +0200
Subject: [PATCH] waf-bug: fix: change CPPFLAGS and LDFLAGS ordering

Just a hack to show what's needed, the proper fix would habe to
somehow fixup the template strings in wafsamba/.

Signed-off-by: Ralph Boehme <slow at samba.org>
---
 buildtools/wafadmin/Tools/cc.py       | 4 ++--
 buildtools/wafadmin/Tools/config_c.py | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/buildtools/wafadmin/Tools/cc.py b/buildtools/wafadmin/Tools/cc.py
index 903a1c5..fc52fdf 100644
--- a/buildtools/wafadmin/Tools/cc.py
+++ b/buildtools/wafadmin/Tools/cc.py
@@ -88,12 +88,12 @@ def c_hook(self, node):
 		raise Utils.WafError('Have you forgotten to set the feature "cc" on %s?' % str(self))
 	return task
 
-cc_str = '${CC} ${CCFLAGS} ${CPPFLAGS} ${_CCINCFLAGS} ${_CCDEFFLAGS} ${CC_SRC_F}${SRC} ${CC_TGT_F}${TGT}'
+cc_str = '${CC} ${_CCINCFLAGS} ${_CCDEFFLAGS} ${CCFLAGS} ${CPPFLAGS} ${CC_SRC_F}${SRC} ${CC_TGT_F}${TGT}'
 cls = Task.simple_task_type('cc', cc_str, 'GREEN', ext_out='.o', ext_in='.c', shell=False)
 cls.scan = ccroot.scan
 cls.vars.append('CCDEPS')
 
-link_str = '${LINK_CC} ${CCLNK_SRC_F}${SRC} ${CCLNK_TGT_F}${TGT[0].abspath(env)} ${LINKFLAGS}'
+link_str = '${LINK_CC} ${CCLNK_SRC_F}${SRC} ${CCLNK_TGT_F}${TGT[0].abspath(env)} ${LINKFLAGS} ${LDFLAGS}'
 cls = Task.simple_task_type('cc_link', link_str, color='YELLOW', ext_in='.o', ext_out='.bin', shell=False)
 cls.maxjobs = 1
 cls.install = Utils.nada
diff --git a/buildtools/wafadmin/Tools/config_c.py b/buildtools/wafadmin/Tools/config_c.py
index d0bc617..eba4b39 100644
--- a/buildtools/wafadmin/Tools/config_c.py
+++ b/buildtools/wafadmin/Tools/config_c.py
@@ -737,7 +737,7 @@ def cxx_add_flags(conf):
 @conftest
 def link_add_flags(conf):
 	conf.add_os_flags('LINKFLAGS')
-	conf.add_os_flags('LDFLAGS', 'LINKFLAGS')
+	conf.add_os_flags('LDFLAGS')
 
 @conftest
 def cc_load_tools(conf):
-- 
1.9.3



More information about the samba-technical mailing list