s3: Add messaging_tdb_event()
[Samba/gebeck_regimport.git] / buildtools / wafsamba / samba_bundled.py
blobc5b402229752d3a59777f13c49460ac05d7baa64
1 # functions to support bundled libraries
3 from Configure import conf
4 import sys, Logs
5 from samba_utils import *
7 def PRIVATE_NAME(bld, name, private_extension, private_library):
8 '''possibly rename a library to include a bundled extension'''
10 # we now use the same private name for libraries as the public name.
11 # see http://git.samba.org/?p=tridge/junkcode.git;a=tree;f=shlib for a
12 # demonstration that this is the right thing to do
13 # also see http://lists.samba.org/archive/samba-technical/2011-January/075816.html
14 return name
17 def target_in_list(target, lst, default):
18 for l in lst:
19 if target == l:
20 return True
21 if '!' + target == l:
22 return False
23 if l == 'ALL':
24 return True
25 if l == 'NONE':
26 return False
27 return default
30 def BUILTIN_LIBRARY(bld, name):
31 '''return True if a library should be builtin
32 instead of being built as a shared lib'''
33 if bld.env.DISABLE_SHARED:
34 return True
35 return target_in_list(name, bld.env.BUILTIN_LIBRARIES, False)
36 Build.BuildContext.BUILTIN_LIBRARY = BUILTIN_LIBRARY
39 def BUILTIN_DEFAULT(opt, builtins):
40 '''set a comma separated default list of builtin libraries for this package'''
41 if 'BUILTIN_LIBRARIES_DEFAULT' in Options.options:
42 return
43 Options.options['BUILTIN_LIBRARIES_DEFAULT'] = builtins
44 Options.Handler.BUILTIN_DEFAULT = BUILTIN_DEFAULT
47 def PRIVATE_EXTENSION_DEFAULT(opt, extension, noextension=''):
48 '''set a default private library extension'''
49 if 'PRIVATE_EXTENSION_DEFAULT' in Options.options:
50 return
51 Options.options['PRIVATE_EXTENSION_DEFAULT'] = extension
52 Options.options['PRIVATE_EXTENSION_EXCEPTION'] = noextension
53 Options.Handler.PRIVATE_EXTENSION_DEFAULT = PRIVATE_EXTENSION_DEFAULT
56 def minimum_library_version(conf, libname, default):
57 '''allow override of mininum system library version'''
59 minlist = Options.options.MINIMUM_LIBRARY_VERSION
60 if not minlist:
61 return default
63 for m in minlist.split(','):
64 a = m.split(':')
65 if len(a) != 2:
66 Logs.error("Bad syntax for --minimum-library-version of %s" % m)
67 sys.exit(1)
68 if a[0] == libname:
69 return a[1]
70 return default
73 @conf
74 def LIB_MAY_BE_BUNDLED(conf, libname):
75 return ('NONE' not in conf.env.BUNDLED_LIBS and
76 '!%s' % libname not in conf.env.BUNDLED_LIBS)
79 @conf
80 def LIB_MUST_BE_BUNDLED(conf, libname):
81 return ('ALL' in conf.env.BUNDLED_LIBS or
82 libname in conf.env.BUNDLED_LIBS)
85 @conf
86 def CHECK_PREREQUISITES(conf, prereqs):
87 missing = []
88 for syslib in TO_LIST(prereqs):
89 f = 'FOUND_SYSTEMLIB_%s' % syslib
90 if not f in conf.env:
91 missing.append(syslib)
92 return missing
95 @runonce
96 @conf
97 def CHECK_BUNDLED_SYSTEM_PKG(conf, libname, minversion='0.0.0',
98 onlyif=None, implied_deps=None, pkg=None):
99 '''check if a library is available as a system library.
101 This only tries using pkg-config
103 if conf.LIB_MUST_BE_BUNDLED(libname):
104 return False
105 found = 'FOUND_SYSTEMLIB_%s' % libname
106 if found in conf.env:
107 return conf.env[found]
109 # see if the library should only use a system version if another dependent
110 # system version is found. That prevents possible use of mixed library
111 # versions
112 if onlyif:
113 missing = conf.CHECK_PREREQUISITES(onlyif)
114 if missing:
115 if not conf.LIB_MAY_BE_BUNDLED(libname):
116 Logs.error('ERROR: Use of system library %s depends on missing system library/libraries %r' % (libname, missing))
117 sys.exit(1)
118 conf.env[found] = False
119 return False
121 minversion = minimum_library_version(conf, libname, minversion)
123 msg = 'Checking for system %s' % libname
124 if minversion != '0.0.0':
125 msg += ' >= %s' % minversion
127 if pkg is None:
128 pkg = libname
130 if conf.check_cfg(package=pkg,
131 args='"%s >= %s" --cflags --libs' % (pkg, minversion),
132 msg=msg, uselib_store=libname.upper()):
133 conf.SET_TARGET_TYPE(libname, 'SYSLIB')
134 conf.env[found] = True
135 if implied_deps:
136 conf.SET_SYSLIB_DEPS(libname, implied_deps)
137 return True
138 conf.env[found] = False
139 if not conf.LIB_MAY_BE_BUNDLED(libname):
140 Logs.error('ERROR: System library %s of version %s not found, and bundling disabled' % (libname, minversion))
141 sys.exit(1)
142 return False
145 @runonce
146 @conf
147 def CHECK_BUNDLED_SYSTEM(conf, libname, minversion='0.0.0',
148 checkfunctions=None, headers=None,
149 onlyif=None, implied_deps=None,
150 require_headers=True):
151 '''check if a library is available as a system library.
152 this first tries via pkg-config, then if that fails
153 tries by testing for a specified function in the specified lib
155 if conf.LIB_MUST_BE_BUNDLED(libname):
156 return False
157 found = 'FOUND_SYSTEMLIB_%s' % libname
158 if found in conf.env:
159 return conf.env[found]
161 def check_functions_headers():
162 '''helper function for CHECK_BUNDLED_SYSTEM'''
163 if checkfunctions is None:
164 return True
165 if require_headers and headers and not conf.CHECK_HEADERS(headers, lib=libname):
166 return False
167 return conf.CHECK_FUNCS_IN(checkfunctions, libname, headers=headers,
168 empty_decl=False, set_target=False)
170 # see if the library should only use a system version if another dependent
171 # system version is found. That prevents possible use of mixed library
172 # versions
173 if onlyif:
174 missing = conf.CHECK_PREREQUISITES(onlyif)
175 if missing:
176 if not conf.LIB_MAY_BE_BUNDLED(libname):
177 Logs.error('ERROR: Use of system library %s depends on missing system library/libraries %r' % (libname, missing))
178 sys.exit(1)
179 conf.env[found] = False
180 return False
182 minversion = minimum_library_version(conf, libname, minversion)
184 msg = 'Checking for system %s' % libname
185 if minversion != '0.0.0':
186 msg += ' >= %s' % minversion
188 # try pkgconfig first
189 if (conf.check_cfg(package=libname,
190 args='"%s >= %s" --cflags --libs' % (libname, minversion),
191 msg=msg) and
192 check_functions_headers()):
193 conf.SET_TARGET_TYPE(libname, 'SYSLIB')
194 conf.env[found] = True
195 if implied_deps:
196 conf.SET_SYSLIB_DEPS(libname, implied_deps)
197 return True
198 if checkfunctions is not None:
199 if check_functions_headers():
200 conf.env[found] = True
201 if implied_deps:
202 conf.SET_SYSLIB_DEPS(libname, implied_deps)
203 conf.SET_TARGET_TYPE(libname, 'SYSLIB')
204 return True
205 conf.env[found] = False
206 if not conf.LIB_MAY_BE_BUNDLED(libname):
207 Logs.error('ERROR: System library %s of version %s not found, and bundling disabled' % (libname, minversion))
208 sys.exit(1)
209 return False
212 def tuplize_version(version):
213 return tuple([int(x) for x in version.split(".")])
215 @runonce
216 @conf
217 def CHECK_BUNDLED_SYSTEM_PYTHON(conf, libname, modulename, minversion='0.0.0'):
218 '''check if a python module is available on the system and
219 has the specified minimum version.
221 if conf.LIB_MUST_BE_BUNDLED(libname):
222 return False
224 # see if the library should only use a system version if another dependent
225 # system version is found. That prevents possible use of mixed library
226 # versions
227 minversion = minimum_library_version(conf, libname, minversion)
229 try:
230 m = __import__(modulename)
231 except ImportError:
232 found = False
233 else:
234 try:
235 version = m.__version__
236 except AttributeError:
237 found = False
238 else:
239 found = tuplize_version(version) >= tuplize_version(minversion)
240 if not found and not conf.LIB_MAY_BE_BUNDLED(libname):
241 Logs.error('ERROR: Python module %s of version %s not found, and bundling disabled' % (libname, minversion))
242 sys.exit(1)
243 return found
246 def NONSHARED_BINARY(bld, name):
247 '''return True if a binary should be built without non-system shared libs'''
248 if bld.env.DISABLE_SHARED:
249 return True
250 return target_in_list(name, bld.env.NONSHARED_BINARIES, False)
251 Build.BuildContext.NONSHARED_BINARY = NONSHARED_BINARY