s4-waf: support the use of system libraries
authorAndrew Tridgell <tridge@samba.org>
Sun, 28 Mar 2010 05:38:27 +0000 (16:38 +1100)
committerAndrew Tridgell <tridge@samba.org>
Tue, 6 Apr 2010 10:27:13 +0000 (20:27 +1000)
distros can set --bundled-libraries=NONE to force use of all system
libraries. If the right version isn't found then configure will fail.

Users may choose which libraries to use from the system, and which to
use bundled libs. The default is to try system libs, and use them if
their version matches the one in the source tree.

buildtools/wafsamba/samba_autoconf.py
buildtools/wafsamba/samba_bundled.py
buildtools/wafsamba/wscript
lib/talloc/wscript
lib/tdb/wscript
lib/tevent/wscript
source4/lib/ldb/wscript

index b2f1d82040b4c9700ca9d601f7a781051ed65f09..ff2fa012c44e24b98d5a2b07f8943b367d4feb1a 100644 (file)
@@ -399,8 +399,9 @@ def CHECK_LIB(conf, libs, mandatory=False):
         (ccflags, ldflags) = library_flags(conf, lib)
 
         if not conf.check(lib=lib, uselib_store=lib, ccflags=ccflags, ldflags=ldflags):
-            conf.ASSERT(not mandatory,
-                        "Mandatory library '%s' not found for functions '%s'" % (lib, list))
+            if mandatory:
+                print("Mandatory library '%s' not found for functions '%s'" % (lib, list))
+                sys.exit(1)
             # if it isn't a mandatory library, then remove it from dependency lists
             SET_TARGET_TYPE(conf, lib, 'EMPTY')
             ret = False
@@ -449,8 +450,9 @@ def CHECK_FUNCS_IN(conf, list, library, mandatory=False, checklibc=False, header
     conf.CHECK_LIB(liblist)
     for lib in liblist[:]:
         if not GET_TARGET_TYPE(conf, lib) == 'SYSLIB':
-            conf.ASSERT(not mandatory,
-                        "Mandatory library '%s' not found for functions '%s'" % (lib, list))
+            if mandatory:
+                print("Mandatory library '%s' not found for functions '%s'" % (lib, list))
+                sys.exit(1)
             # if it isn't a mandatory library, then remove it from dependency lists
             liblist.remove(lib)
             continue
@@ -462,6 +464,11 @@ def CHECK_FUNCS_IN(conf, list, library, mandatory=False, checklibc=False, header
 
     return ret
 
+@conf
+def IN_LAUNCH_DIR(conf):
+    '''return True if this rule is being run from the launch directory'''
+    return os.path.realpath(conf.curdir) == os.path.realpath(Options.launch_dir)
+
 
 #################################################
 # write out config.h in the right directory
@@ -469,7 +476,7 @@ def CHECK_FUNCS_IN(conf, list, library, mandatory=False, checklibc=False, header
 def SAMBA_CONFIG_H(conf, path=None):
     # we don't want to produce a config.h in places like lib/replace
     # when we are building projects that depend on lib/replace
-    if os.path.realpath(conf.curdir) != os.path.realpath(Options.launch_dir):
+    if not IN_LAUNCH_DIR(conf):
         return
 
     if Options.options.developer:
index d4dbe221db68363553f9e7fe38d95856aab2b999..2a6d75f7c9baa99d1a1ff59a3fbe5d68007895f4 100644 (file)
@@ -40,3 +40,18 @@ def BUNDLED_EXTENSION_DEFAULT(opt, extension, noextenion=''):
     Options.options['BUNDLED_EXTENSION_DEFAULT'] = extension
     Options.options['BUNDLED_EXTENSION_EXCEPTION'] = noextenion
 Options.Handler.BUNDLED_EXTENSION_DEFAULT = BUNDLED_EXTENSION_DEFAULT
+
+
+@conf
+def CHECK_BUNDLED_SYSTEM(conf, libname, minversion='0.0.0'):
+    if 'ALL' in conf.env.BUNDLED_LIBS or libname in conf.env.BUNDLED_LIBS:
+        return False
+    if conf.check_cfg(package=libname,
+                      args='"%s >= %s" --cflags --libs' % (libname, minversion),
+                      msg='Checking for system %s >= %s' % (libname, minversion)):
+        conf.SET_TARGET_TYPE(libname, 'SYSLIB')
+        return True
+    if 'NONE' in conf.env.BUNDLED_LIBS or '!'+libname in conf.env.BUNDLED_LIBS:
+        print('ERROR: System library %s of version %s not found, and bundling disabled' % (libname, minversion))
+        sys.exit(1)
+    return False
index 315c3e58a9a1695adc03d1a4d1cf5b658d6d1381..1ff0fd3cb324019c23d064aa1b80db0a0d5be78b 100644 (file)
@@ -12,7 +12,7 @@ def set_options(opt):
     opt.tool_options('gnu_dirs')
 
     opt.add_option('--bundled-libraries',
-                   help=("list of bundled libraries. Can be 'NONE' or 'ALL' [auto]"),
+                   help=("comma separated list of bundled libraries. May include !LIBNAME to disable bundling a library. Can be 'NONE' or 'ALL' [auto]"),
                    action="store", dest='BUNDLED_LIBS', default='')
 
     extension_default = Options.options['BUNDLED_EXTENSION_DEFAULT']
@@ -22,12 +22,12 @@ def set_options(opt):
 
     extension_exception = Options.options['BUNDLED_EXTENSION_EXCEPTION']
     opt.add_option('--bundled-extension-exception',
-                   help=("list of libraries to not apply extension to [%s]" % extension_exception),
+                   help=("comman separated list of libraries to not apply extension to [%s]" % extension_exception),
                    action="store", dest='BUNDLED_EXTENSION_EXCEPTION', default=extension_exception)
 
     builtin_defauilt = Options.options['BUILTIN_LIBRARIES_DEFAULT']
     opt.add_option('--builtin-libraries',
-                   help=("list of libraries to build directly into binaries [%s]" % builtin_defauilt),
+                   help=("command separated list of libraries to build directly into binaries [%s]" % builtin_defauilt),
                    action="store", dest='BUILTIN_LIBRARIES', default=builtin_defauilt)
 
     opt.add_option('--libdir',
index 6d16e15d537fcca28bffebd346d3726e5fe4fcdf..be21bde18c02f08a98a36e8352702ed224dd9c75 100644 (file)
@@ -18,15 +18,22 @@ def set_options(opt):
 
 def configure(conf):
     conf.sub_config(LIBREPLACE_DIR)
+
+    if conf.CHECK_BUNDLED_SYSTEM('talloc', minversion=VERSION):
+        conf.define('USING_SYSTEM_TALLOC', 1)
+
     conf.SAMBA_CONFIG_H()
 
+
+
 def build(bld):
     bld.BUILD_SUBDIR(LIBREPLACE_DIR)
 
-    bld.SAMBA_LIBRARY('talloc',
-                      'talloc.c',
-                      deps='replace',
-                      vnum=VERSION)
+    if not bld.CONFIG_SET('USING_SYSTEM_TALLOC'):
+        bld.SAMBA_LIBRARY('talloc',
+                          'talloc.c',
+                          deps='replace',
+                          vnum=VERSION)
 
     bld.SAMBA_BINARY('talloc_testsuite',
                      'testsuite.c testsuite_main.c',
index e146ba79b0c3e1389b371a90ad2eeeddf8f5982b..365c3842016dc512af764410e4227ecc0a84711e 100644 (file)
@@ -19,6 +19,10 @@ def set_options(opt):
 
 def configure(conf):
     conf.sub_config(LIBREPLACE_DIR)
+
+    if conf.CHECK_BUNDLED_SYSTEM('tdb', minversion=VERSION):
+        conf.define('USING_SYSTEM_TDB', 1)
+
     conf.SAMBA_CONFIG_H()
 
 def build(bld):
@@ -29,11 +33,12 @@ def build(bld):
                             freelistcheck.c lock.c dump.c freelist.c
                             io.c open.c transaction.c''')
 
-    bld.SAMBA_LIBRARY('tdb',
-                      COMMON_SRC,
-                      deps='replace rt',
-                      includes='include',
-                      vnum=VERSION)
+    if not bld.CONFIG_SET('USING_SYSTEM_TDB'):
+        bld.SAMBA_LIBRARY('tdb',
+                          COMMON_SRC,
+                          deps='replace rt',
+                          includes='include',
+                          vnum=VERSION)
 
     bld.SAMBA_BINARY('tdbtorture',
                      'tools/tdbtorture.c',
index f017581fae61c54fd10827ceca58d6935103e55f..e6ef67a8d674d41ecd86d2f36033ed6cb01912de 100644 (file)
@@ -22,6 +22,9 @@ def configure(conf):
     conf.sub_config(LIBREPLACE_DIR)
     conf.sub_config(LIBTALLOC_DIR)
 
+    if conf.CHECK_BUNDLED_SYSTEM('tevent', minversion=VERSION):
+        conf.define('USING_SYSTEM_TEVENT', 1)
+
     if conf.CHECK_FUNCS('epoll_create', headers='sys/epoll.h'):
         conf.DEFINE('HAVE_EPOLL', 1)
 
@@ -38,7 +41,9 @@ def build(bld):
     if bld.CONFIG_SET('HAVE_EPOLL'):
         SRC += ' tevent_epoll.c'
 
-    bld.SAMBA_LIBRARY('tevent',
-                      SRC,
-                      deps='replace talloc',
-                      vnum=VERSION)
+    if not bld.CONFIG_SET('USING_SYSTEM_TEVENT'):
+        bld.SAMBA_LIBRARY('tevent',
+                          SRC,
+                          deps='replace talloc',
+                          enabled= not bld.CONFIG_SET('USING_SYSTEM_TEVENT'),
+                          vnum=VERSION)
index ad875374db56ad1077dbb2fc5593db2769ebf7c9..97e345b8346303fb24e1d7f98cbd6e60e156a898 100644 (file)
@@ -27,7 +27,10 @@ def configure(conf):
 
     s4_build = getattr(conf.env, '_SAMBA_BUILD_', 0) == 4
 
+
     if not s4_build:
+        if conf.CHECK_BUNDLED_SYSTEM('ldb', minversion=VERSION):
+            conf.define('USING_SYSTEM_LDB', 1)
         # we need this for the ldap backend
         conf.CHECK_FUNCS_IN('ber_flush ldap_open', 'lber ldap', headers='lber.h ldap.h', mandatory=True)
 
@@ -130,13 +133,14 @@ def build(bld):
     if s4_build:
         ldb_deps += ' LDBSAMBA POPT_CREDENTIALS POPT_SAMBA LIBCMDLINE_CREDENTIALS gensec'
 
-    bld.SAMBA_LIBRARY('ldb',
-                     COMMON_SRC + ' ' + LDB_MAP_SRC,
-                     deps=ldb_deps,
-                     includes='include',
-                      public_headers='include/ldb.h include/ldb_errors.h',
-                      pc_files='ldb.pc',
-                      vnum=VERSION)
+    if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
+        bld.SAMBA_LIBRARY('ldb',
+                          COMMON_SRC + ' ' + LDB_MAP_SRC,
+                          deps=ldb_deps,
+                          includes='include',
+                          public_headers='include/ldb.h include/ldb_errors.h',
+                          pc_files='ldb.pc',
+                          vnum=VERSION)
 
     bld.SAMBA_SUBSYSTEM('LIBLDB_CMDLINE',
                         'tools/ldbutil.c tools/cmdline.c',