s3-smbldap: move ldap_open_with_timeout out of smb_ldap.h to ads where it lives.
[Samba/gebeck_regimport.git] / buildtools / wafsamba / samba_bundled.py
bloba29b3aa220974a09638dbe166b0e39f55f33649e
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 for syslib in TO_LIST(prereqs):
88 f = 'FOUND_SYSTEMLIB_%s' % syslib
89 if not f in conf.env:
90 return False
91 return True
94 @runonce
95 @conf
96 def CHECK_BUNDLED_SYSTEM_PKG(conf, libname, minversion='0.0.0',
97 onlyif=None, implied_deps=None, pkg=None):
98 '''check if a library is available as a system library.
100 This only tries using pkg-config
102 if conf.LIB_MUST_BE_BUNDLED(libname):
103 return False
104 found = 'FOUND_SYSTEMLIB_%s' % libname
105 if found in conf.env:
106 return conf.env[found]
108 # see if the library should only use a system version if another dependent
109 # system version is found. That prevents possible use of mixed library
110 # versions
111 if onlyif:
112 if not conf.CHECK_PREREQUISITES(onlyif):
113 if not conf.LIB_MAY_BE_BUNDLED(libname):
114 Logs.error('ERROR: Use of system library %s depends on missing system library %s' % (libname, syslib))
115 sys.exit(1)
116 conf.env[found] = False
117 return False
119 minversion = minimum_library_version(conf, libname, minversion)
121 msg = 'Checking for system %s' % libname
122 if minversion != '0.0.0':
123 msg += ' >= %s' % minversion
125 if pkg is None:
126 pkg = libname
128 if conf.check_cfg(package=pkg,
129 args='"%s >= %s" --cflags --libs' % (pkg, minversion),
130 msg=msg, uselib_store=libname.upper()):
131 conf.SET_TARGET_TYPE(libname, 'SYSLIB')
132 conf.env[found] = True
133 if implied_deps:
134 conf.SET_SYSLIB_DEPS(libname, implied_deps)
135 return True
136 conf.env[found] = False
137 if not conf.LIB_MAY_BE_BUNDLED(libname):
138 Logs.error('ERROR: System library %s of version %s not found, and bundling disabled' % (libname, minversion))
139 sys.exit(1)
140 return False
143 @runonce
144 @conf
145 def CHECK_BUNDLED_SYSTEM(conf, libname, minversion='0.0.0',
146 checkfunctions=None, headers=None,
147 onlyif=None, implied_deps=None,
148 require_headers=True):
149 '''check if a library is available as a system library.
150 this first tries via pkg-config, then if that fails
151 tries by testing for a specified function in the specified lib
153 if conf.LIB_MUST_BE_BUNDLED(libname):
154 return False
155 found = 'FOUND_SYSTEMLIB_%s' % libname
156 if found in conf.env:
157 return conf.env[found]
159 def check_functions_headers():
160 '''helper function for CHECK_BUNDLED_SYSTEM'''
161 if checkfunctions is None:
162 return True
163 if require_headers and headers and not conf.CHECK_HEADERS(headers, lib=libname):
164 return False
165 return conf.CHECK_FUNCS_IN(checkfunctions, libname, headers=headers,
166 empty_decl=False, set_target=False)
168 # see if the library should only use a system version if another dependent
169 # system version is found. That prevents possible use of mixed library
170 # versions
171 if onlyif:
172 if not conf.CHECK_PREREQUISITES(onlyif):
173 if not conf.LIB_MAY_BE_BUNDLED(libname):
174 Logs.error('ERROR: Use of system library %s depends on missing system library %s' % (libname, syslib))
175 sys.exit(1)
176 conf.env[found] = False
177 return False
179 minversion = minimum_library_version(conf, libname, minversion)
181 msg = 'Checking for system %s' % libname
182 if minversion != '0.0.0':
183 msg += ' >= %s' % minversion
185 # try pkgconfig first
186 if (conf.check_cfg(package=libname,
187 args='"%s >= %s" --cflags --libs' % (libname, minversion),
188 msg=msg) and
189 check_functions_headers()):
190 conf.SET_TARGET_TYPE(libname, 'SYSLIB')
191 conf.env[found] = True
192 if implied_deps:
193 conf.SET_SYSLIB_DEPS(libname, implied_deps)
194 return True
195 if checkfunctions is not None:
196 if check_functions_headers():
197 conf.env[found] = True
198 if implied_deps:
199 conf.SET_SYSLIB_DEPS(libname, implied_deps)
200 conf.SET_TARGET_TYPE(libname, 'SYSLIB')
201 return True
202 conf.env[found] = False
203 if not conf.LIB_MAY_BE_BUNDLED(libname):
204 Logs.error('ERROR: System library %s of version %s not found, and bundling disabled' % (libname, minversion))
205 sys.exit(1)
206 return False
209 @runonce
210 @conf
211 def CHECK_BUNDLED_SYSTEM_PYTHON(conf, libname, modulename, minversion='0.0.0'):
212 '''check if a python module is available on the system and
213 has the specified minimum version.
215 if conf.LIB_MUST_BE_BUNDLED(libname):
216 return False
218 # see if the library should only use a system version if another dependent
219 # system version is found. That prevents possible use of mixed library
220 # versions
221 minversion = minimum_library_version(conf, libname, minversion)
223 try:
224 m = __import__(modulename)
225 except ImportError:
226 found = False
227 else:
228 try:
229 version = m.__version__
230 except AttributeError:
231 found = False
232 else:
233 found = tuple(version.split(".")) >= tuple(minversion.split("."))
234 if not found and not conf.LIB_MAY_BE_BUNDLED(libname):
235 Logs.error('ERROR: Python module %s of version %s not found, and bundling disabled' % (libname, minversion))
236 sys.exit(1)
237 return found
240 def NONSHARED_BINARY(bld, name):
241 '''return True if a binary should be built without non-system shared libs'''
242 if bld.env.DISABLE_SHARED:
243 return True
244 return target_in_list(name, bld.env.NONSHARED_BINARIES, False)
245 Build.BuildContext.NONSHARED_BINARY = NONSHARED_BINARY