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