1 # functions to support bundled libraries
3 from Configure import conf
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
17 def target_in_list(target, lst, 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:
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:
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:
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
63 for m in minlist.split(','):
66 Logs.error("Bad syntax for --minimum-library-version of %s" % m)
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)
80 def LIB_MUST_BE_BUNDLED(conf, libname):
81 return ('ALL' in conf.env.BUNDLED_LIBS or
82 libname in conf.env.BUNDLED_LIBS)
86 def CHECK_PREREQUISITES(conf, prereqs):
88 for syslib in TO_LIST(prereqs):
89 f = 'FOUND_SYSTEMLIB_%s' % syslib
91 missing.append(syslib)
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):
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
113 missing = conf.CHECK_PREREQUISITES(onlyif)
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))
118 conf.env[found] = 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
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
136 conf.SET_SYSLIB_DEPS(libname, implied_deps)
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))
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):
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:
165 if require_headers and headers and not conf.CHECK_HEADERS(headers, lib=libname):
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
174 missing = conf.CHECK_PREREQUISITES(onlyif)
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))
179 conf.env[found] = 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),
192 check_functions_headers()):
193 conf.SET_TARGET_TYPE(libname, 'SYSLIB')
194 conf.env[found] = True
196 conf.SET_SYSLIB_DEPS(libname, implied_deps)
198 if checkfunctions is not None:
199 if check_functions_headers():
200 conf.env[found] = True
202 conf.SET_SYSLIB_DEPS(libname, implied_deps)
203 conf.SET_TARGET_TYPE(libname, 'SYSLIB')
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))
214 def CHECK_BUNDLED_SYSTEM_PYTHON(conf, libname, modulename, minversion='0.0.0'):
215 '''check if a python module is available on the system and
216 has the specified minimum version.
218 if conf.LIB_MUST_BE_BUNDLED(libname):
221 # see if the library should only use a system version if another dependent
222 # system version is found. That prevents possible use of mixed library
224 minversion = minimum_library_version(conf, libname, minversion)
227 m = __import__(modulename)
232 version = m.__version__
233 except AttributeError:
236 found = tuple(version.split(".")) >= tuple(minversion.split("."))
237 if not found and not conf.LIB_MAY_BE_BUNDLED(libname):
238 Logs.error('ERROR: Python module %s of version %s not found, and bundling disabled' % (libname, minversion))
243 def NONSHARED_BINARY(bld, name):
244 '''return True if a binary should be built without non-system shared libs'''
245 if bld.env.DISABLE_SHARED:
247 return target_in_list(name, bld.env.NONSHARED_BINARIES, False)
248 Build.BuildContext.NONSHARED_BINARY = NONSHARED_BINARY