28116fcd696bee8cc1c1d1a86da062b857dc1f56
[nivanova/samba-autobuild/.git] / buildtools / wafsamba / samba_bundled.py
1 # functions to support bundled libraries
2
3 from Configure import conf
4 from samba_utils import *
5
6 def BUNDLED_NAME(bld, name, bundled_extension):
7     '''possibly rename a library to include a bundled extension'''
8     if bld.env.DISABLE_SHARED or not bundled_extension:
9         return name
10     if name in bld.env.BUNDLED_EXTENSION_EXCEPTION:
11         return name
12     extension = getattr(bld.env, 'BUNDLED_EXTENSION', '')
13     if extension:
14         return name + '-' + extension
15     return name
16
17
18 def BUILTIN_LIBRARY(bld, name):
19     '''return True if a library should be builtin
20        instead of being built as a shared lib'''
21     if bld.env.DISABLE_SHARED:
22         return True
23     if name in bld.env.BUILTIN_LIBRARIES:
24         return True
25     return False
26
27
28 def BUILTIN_DEFAULT(opt, builtins):
29     '''set a comma separated default list of builtin libraries for this package'''
30     if 'BUILTIN_LIBRARIES_DEFAULT' in Options.options:
31         return
32     Options.options['BUILTIN_LIBRARIES_DEFAULT'] = builtins
33 Options.Handler.BUILTIN_DEFAULT = BUILTIN_DEFAULT
34
35
36 def BUNDLED_EXTENSION_DEFAULT(opt, extension, noextenion=''):
37     '''set a default bundled library extension'''
38     if 'BUNDLED_EXTENSION_DEFAULT' in Options.options:
39         return
40     Options.options['BUNDLED_EXTENSION_DEFAULT'] = extension
41     Options.options['BUNDLED_EXTENSION_EXCEPTION'] = noextenion
42 Options.Handler.BUNDLED_EXTENSION_DEFAULT = BUNDLED_EXTENSION_DEFAULT
43
44
45
46 @runonce
47 @conf
48 def CHECK_BUNDLED_SYSTEM(conf, libname, minversion='0.0.0',
49                          checkfunctions=None, headers=None,
50                          onlyif=None, implied_deps=None):
51     '''check if a library is available as a system library.
52     this first tries via pkg-config, then if that fails
53     tries by testing for a specified function in the specified lib
54     '''
55     if 'ALL' in conf.env.BUNDLED_LIBS or libname in conf.env.BUNDLED_LIBS:
56         return False
57     found = 'FOUND_SYSTEMLIB_%s' % libname
58     if found in conf.env:
59         return conf.env[found]
60
61     # see if the library should only use a system version if another dependent
62     # system version is found. That prevents possible use of mixed library
63     # versions
64     if onlyif:
65         for syslib in TO_LIST(onlyif):
66             f = 'FOUND_SYSTEM_%s' % syslib
67             if not f in conf.env:
68                 if 'NONE' in conf.env.BUNDLED_LIBS or '!'+libname in conf.env.BUNDLED_LIBS:
69                     print('ERROR: Use of system library %s depends on missing system library %s' % (libname, syslib))
70                     sys.exit(1)
71                 conf.env[found] = False
72                 return False
73
74     # try pkgconfig first
75     if conf.check_cfg(package=libname,
76                       args='"%s >= %s" --cflags --libs' % (libname, minversion),
77                       msg='Checking for system %s >= %s' % (libname, minversion)):
78         conf.SET_TARGET_TYPE(libname, 'SYSLIB')
79         conf.env[found] = True
80         if implied_deps:
81             conf.SET_SYSLIB_DEPS(libname, implied_deps)
82         return True
83     if checkfunctions is not None:
84         if conf.CHECK_FUNCS_IN(checkfunctions, libname, headers=headers, empty_decl=False):
85             conf.env[found] = True
86             if implied_deps:
87                 conf.SET_SYSLIB_DEPS(libname, implied_deps)
88             return True
89     conf.env[found] = False
90     if 'NONE' in conf.env.BUNDLED_LIBS or '!'+libname in conf.env.BUNDLED_LIBS:
91         print('ERROR: System library %s of version %s not found, and bundling disabled' % (libname, minversion))
92         sys.exit(1)
93     return False