talloc: Add a separate pool size
[Samba.git] / buildtools / wafsamba / samba_bundled.py
blobafcf708e10f0dac9d5ec8a20d0a09425aeadd09d
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 return target_in_list(name, bld.env.BUILTIN_LIBRARIES, False)
34 Build.BuildContext.BUILTIN_LIBRARY = BUILTIN_LIBRARY
37 def BUILTIN_DEFAULT(opt, builtins):
38 '''set a comma separated default list of builtin libraries for this package'''
39 if 'BUILTIN_LIBRARIES_DEFAULT' in Options.options:
40 return
41 Options.options['BUILTIN_LIBRARIES_DEFAULT'] = builtins
42 Options.Handler.BUILTIN_DEFAULT = BUILTIN_DEFAULT
45 def PRIVATE_EXTENSION_DEFAULT(opt, extension, noextension=''):
46 '''set a default private library extension'''
47 if 'PRIVATE_EXTENSION_DEFAULT' in Options.options:
48 return
49 Options.options['PRIVATE_EXTENSION_DEFAULT'] = extension
50 Options.options['PRIVATE_EXTENSION_EXCEPTION'] = noextension
51 Options.Handler.PRIVATE_EXTENSION_DEFAULT = PRIVATE_EXTENSION_DEFAULT
54 def minimum_library_version(conf, libname, default):
55 '''allow override of mininum system library version'''
57 minlist = Options.options.MINIMUM_LIBRARY_VERSION
58 if not minlist:
59 return default
61 for m in minlist.split(','):
62 a = m.split(':')
63 if len(a) != 2:
64 Logs.error("Bad syntax for --minimum-library-version of %s" % m)
65 sys.exit(1)
66 if a[0] == libname:
67 return a[1]
68 return default
71 @conf
72 def LIB_MAY_BE_BUNDLED(conf, libname):
73 return ('NONE' not in conf.env.BUNDLED_LIBS and
74 '!%s' % libname not in conf.env.BUNDLED_LIBS)
77 @conf
78 def LIB_MUST_BE_BUNDLED(conf, libname):
79 return ('ALL' in conf.env.BUNDLED_LIBS or
80 libname in conf.env.BUNDLED_LIBS)
82 @conf
83 def LIB_MUST_BE_PRIVATE(conf, libname):
84 return ('ALL' in conf.env.PRIVATE_LIBS or
85 libname in conf.env.PRIVATE_LIBS)
87 @conf
88 def CHECK_PREREQUISITES(conf, prereqs):
89 missing = []
90 for syslib in TO_LIST(prereqs):
91 f = 'FOUND_SYSTEMLIB_%s' % syslib
92 if not f in conf.env:
93 missing.append(syslib)
94 return missing
97 @runonce
98 @conf
99 def CHECK_BUNDLED_SYSTEM_PKG(conf, libname, minversion='0.0.0',
100 onlyif=None, implied_deps=None, pkg=None):
101 '''check if a library is available as a system library.
103 This only tries using pkg-config
105 if conf.LIB_MUST_BE_BUNDLED(libname):
106 return False
107 found = 'FOUND_SYSTEMLIB_%s' % libname
108 if found in conf.env:
109 return conf.env[found]
111 # see if the library should only use a system version if another dependent
112 # system version is found. That prevents possible use of mixed library
113 # versions
114 if onlyif:
115 missing = conf.CHECK_PREREQUISITES(onlyif)
116 if missing:
117 if not conf.LIB_MAY_BE_BUNDLED(libname):
118 Logs.error('ERROR: Use of system library %s depends on missing system library/libraries %r' % (libname, missing))
119 sys.exit(1)
120 conf.env[found] = False
121 return False
123 minversion = minimum_library_version(conf, libname, minversion)
125 msg = 'Checking for system %s' % libname
126 if minversion != '0.0.0':
127 msg += ' >= %s' % minversion
129 if pkg is None:
130 pkg = libname
132 if conf.check_cfg(package=pkg,
133 args='"%s >= %s" --cflags --libs' % (pkg, minversion),
134 msg=msg, uselib_store=libname.upper()):
135 conf.SET_TARGET_TYPE(libname, 'SYSLIB')
136 conf.env[found] = True
137 if implied_deps:
138 conf.SET_SYSLIB_DEPS(libname, implied_deps)
139 return True
140 conf.env[found] = False
141 if not conf.LIB_MAY_BE_BUNDLED(libname):
142 Logs.error('ERROR: System library %s of version %s not found, and bundling disabled' % (libname, minversion))
143 sys.exit(1)
144 return False
147 @runonce
148 @conf
149 def CHECK_BUNDLED_SYSTEM(conf, libname, minversion='0.0.0',
150 checkfunctions=None, headers=None,
151 onlyif=None, implied_deps=None,
152 require_headers=True):
153 '''check if a library is available as a system library.
154 this first tries via pkg-config, then if that fails
155 tries by testing for a specified function in the specified lib
157 if conf.LIB_MUST_BE_BUNDLED(libname):
158 return False
159 found = 'FOUND_SYSTEMLIB_%s' % libname
160 if found in conf.env:
161 return conf.env[found]
163 def check_functions_headers():
164 '''helper function for CHECK_BUNDLED_SYSTEM'''
165 if checkfunctions is None:
166 return True
167 if require_headers and headers and not conf.CHECK_HEADERS(headers, lib=libname):
168 return False
169 return conf.CHECK_FUNCS_IN(checkfunctions, libname, headers=headers,
170 empty_decl=False, set_target=False)
172 # see if the library should only use a system version if another dependent
173 # system version is found. That prevents possible use of mixed library
174 # versions
175 if onlyif:
176 missing = conf.CHECK_PREREQUISITES(onlyif)
177 if missing:
178 if not conf.LIB_MAY_BE_BUNDLED(libname):
179 Logs.error('ERROR: Use of system library %s depends on missing system library/libraries %r' % (libname, missing))
180 sys.exit(1)
181 conf.env[found] = False
182 return False
184 minversion = minimum_library_version(conf, libname, minversion)
186 msg = 'Checking for system %s' % libname
187 if minversion != '0.0.0':
188 msg += ' >= %s' % minversion
190 # try pkgconfig first
191 if (conf.check_cfg(package=libname,
192 args='"%s >= %s" --cflags --libs' % (libname, minversion),
193 msg=msg) and
194 check_functions_headers()):
195 conf.SET_TARGET_TYPE(libname, 'SYSLIB')
196 conf.env[found] = True
197 if implied_deps:
198 conf.SET_SYSLIB_DEPS(libname, implied_deps)
199 return True
200 if checkfunctions is not None:
201 if check_functions_headers():
202 conf.env[found] = True
203 if implied_deps:
204 conf.SET_SYSLIB_DEPS(libname, implied_deps)
205 conf.SET_TARGET_TYPE(libname, 'SYSLIB')
206 return True
207 conf.env[found] = False
208 if not conf.LIB_MAY_BE_BUNDLED(libname):
209 Logs.error('ERROR: System library %s of version %s not found, and bundling disabled' % (libname, minversion))
210 sys.exit(1)
211 return False
214 def tuplize_version(version):
215 return tuple([int(x) for x in version.split(".")])
217 @runonce
218 @conf
219 def CHECK_BUNDLED_SYSTEM_PYTHON(conf, libname, modulename, minversion='0.0.0'):
220 '''check if a python module is available on the system and
221 has the specified minimum version.
223 if conf.LIB_MUST_BE_BUNDLED(libname):
224 return False
226 # see if the library should only use a system version if another dependent
227 # system version is found. That prevents possible use of mixed library
228 # versions
229 minversion = minimum_library_version(conf, libname, minversion)
231 try:
232 m = __import__(modulename)
233 except ImportError:
234 found = False
235 else:
236 try:
237 version = m.__version__
238 except AttributeError:
239 found = False
240 else:
241 found = tuplize_version(version) >= tuplize_version(minversion)
242 if not found and not conf.LIB_MAY_BE_BUNDLED(libname):
243 Logs.error('ERROR: Python module %s of version %s not found, and bundling disabled' % (libname, minversion))
244 sys.exit(1)
245 return found
248 def NONSHARED_BINARY(bld, name):
249 '''return True if a binary should be built without non-system shared libs'''
250 return target_in_list(name, bld.env.NONSHARED_BINARIES, False)
251 Build.BuildContext.NONSHARED_BINARY = NONSHARED_BINARY