build: add a function to test if -lc is needed
authorMatthieu Patou <mat@matws.net>
Fri, 10 Dec 2010 20:16:28 +0000 (23:16 +0300)
committerMatthieu Patou <mat@matws.net>
Fri, 10 Dec 2010 20:22:28 +0000 (23:22 +0300)
This is needed on openbsd as some linking flags makes mandatory to
specify the libc for the linking

buildtools/wafsamba/samba_conftests.py
source4/wscript

index 2246ac3fa5cb0016ca63e028aa1e7f2f5ac1d07a..c7e596d27aad48ec793a06ecf0ed6e5caed951a2 100644 (file)
@@ -107,6 +107,51 @@ int foo(int v) {
 '''
     return conf.check(features='cc cshlib',vnum="1",fragment=snip,msg=msg)
 
+@conf
+def CHECK_NEED_LC(conf, msg):
+    '''check if we need -lc'''
+
+    dir = find_config_dir(conf)
+
+    env = conf.env
+
+    bdir = os.path.join(dir, 'testbuild2')
+    if not os.path.exists(bdir):
+        os.makedirs(bdir)
+
+
+    subdir = os.path.join(dir, "liblctest")
+
+    os.makedirs(subdir)
+
+    dest = open(os.path.join(subdir, 'liblc1.c'), 'w')
+    dest.write('#include <stdio.h>\nint lib_func(void) { FILE *f = fopen("foo", "r");}\n')
+    dest.close()
+
+    bld = Build.BuildContext()
+    bld.log = conf.log
+    bld.all_envs.update(conf.all_envs)
+    bld.all_envs['default'] = env
+    bld.lst_variants = bld.all_envs.keys()
+    bld.load_dirs(dir, bdir)
+
+    bld.rescan(bld.srcnode)
+
+    bld(features='cc cshlib',
+        source='liblctest/liblc1.c',
+        ldflags=conf.env['EXTRA_LDFLAGS'],
+        target='liblc',
+        name='liblc')
+
+    try:
+        bld.compile()
+        conf.check_message(msg, '', True)
+        return True
+    except:
+        conf.check_message(msg, '', False)
+        return False
+
+
 @conf
 def CHECK_SHLIB_W_PYTHON(conf, msg):
     '''check if we need -undefined dynamic_lookup'''
index 3213e7c4e4ea420f6ec46c3bcf624350ccace381..93391dacd1ea0199487cc4b74e1585c095a6ac2d 100644 (file)
@@ -113,6 +113,8 @@ def configure(conf):
     # allows us to find problems on our development hosts faster.
     # It also results in faster load time.
     conf.ADD_LDFLAGS('-Wl,--as-needed', testflags=True)
+    if not conf.CHECK_NEED_LC("-lc not needed"):
+        conf.ADD_LDFLAGS('-lc', testflags=False)
 
     # we don't want PYTHONDIR in config.h, as otherwise changing
     # --prefix causes a complete rebuild