wafsamba: filter out standard library paths from RPATH and LIBPATH
authorMichael Adam <obnox@samba.org>
Thu, 18 Dec 2014 20:36:07 +0000 (21:36 +0100)
committerJeremy Allison <jra@samba.org>
Thu, 8 Jan 2015 22:38:07 +0000 (23:38 +0100)
We should avoid passing them explicitly to the compiler/linker.

We ask the compiler with the '-print-search-dirs' argument
or fallback to [ '/usr/lib', '/usr/lib64' ].

Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>

Signed-off-by: Michael Adam <obnox@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
buildtools/wafsamba/samba_conftests.py
buildtools/wafsamba/samba_optimisation.py
buildtools/wafsamba/wscript

index 07dda2a3f8ba8f77037def0fa32c21eb5a9b5fca..1afc6c94fbe817d89043f2f806208995f11efcca 100644 (file)
@@ -508,6 +508,35 @@ def CHECK_XSLTPROC_MANPAGES(conf):
         print "A local copy of the docbook.xsl wasn't found on your system" \
               " consider installing package like docbook-xsl"
 
+#
+# Determine the standard libpath for the used compiler,
+# so we can later use that to filter out these standard
+# library paths when some tools like cups-config or
+# python-config report standard lib paths with their
+# ldflags (-L...)
+#
+@conf
+def CHECK_STANDARD_LIBPATH(conf):
+    # at least gcc and clang support this:
+    try:
+        cmd = conf.env.CC + ['-print-search-dirs']
+        out = Utils.cmd_output(cmd).split('\n')
+    except ValueError:
+        # option not supported by compiler - use a standard list of directories
+        dirlist = [ '/usr/lib', '/usr/lib64' ]
+    except:
+        raise Utils.WafError('Unexpected error running "%s"' % (cmd))
+    else:
+        dirlist = []
+        for line in out:
+            line = line.strip()
+            if line.startswith("libraries: ="):
+                dirliststr = line[len("libraries: ="):]
+                dirlist = [ os.path.normpath(x) for x in dirliststr.split(':') ]
+                break
+
+    conf.env.STANDARD_LIBPATH = dirlist
+
 
 waf_config_c_parse_flags = config_c.parse_flags;
 def samba_config_c_parse_flags(line1, uselib, env):
index 1333f8b740791f83b7c75a8e644870b0b3021337..583a6514d7811b1827debbfe9e08b928b800fbd3 100644 (file)
@@ -6,8 +6,9 @@
 
 # overall this makes some build tasks quite a bit faster
 
+import os
 import Build, Utils, Node
-from TaskGen import feature, after
+from TaskGen import feature, after, before
 import preproc, Task
 
 @feature('cc', 'cxx')
@@ -308,3 +309,25 @@ def apply_lib_vars(self):
             val = self.env[v + '_' + x]
             if val:
                 self.env.append_value(v, val)
+
+@feature('cprogram', 'cshlib', 'cstaticlib')
+@after('apply_lib_vars')
+@before('apply_obj_vars')
+def samba_before_apply_obj_vars(self):
+    """before apply_obj_vars for uselib, this removes the standard pathes"""
+
+    def is_standard_libpath(env, path):
+        for _path in env.STANDARD_LIBPATH:
+            if _path == os.path.normpath(path):
+                return True
+        return False
+
+    v = self.env
+
+    for i in v['RPATH']:
+        if is_standard_libpath(v, i):
+            v['RPATH'].remove(i)
+
+    for i in v['LIBPATH']:
+        if is_standard_libpath(v, i):
+            v['LIBPATH'].remove(i)
index c49b20e1153ab2b259c9f09eb0cbea75c90cadf5..c81a7b3b098adb031fd4f4f32a2b3a50bf493065 100755 (executable)
@@ -211,6 +211,8 @@ def configure(conf):
 
     conf.check_tool('compiler_cc')
 
+    conf.CHECK_STANDARD_LIBPATH()
+
     # we need git for 'waf dist'
     conf.find_program('git', var='GIT')