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 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:
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:
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
61 for m in minlist.split(','):
64 Logs.error("Bad syntax for --minimum-library-version of %s" % m)
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)
78 def LIB_MUST_BE_BUNDLED(conf, libname):
79 return ('ALL' in conf.env.BUNDLED_LIBS or
80 libname in conf.env.BUNDLED_LIBS)
83 def LIB_MUST_BE_PRIVATE(conf, libname):
84 return ('ALL' in conf.env.PRIVATE_LIBS or
85 libname in conf.env.PRIVATE_LIBS)
88 def CHECK_PREREQUISITES(conf, prereqs):
90 for syslib in TO_LIST(prereqs):
91 f = 'FOUND_SYSTEMLIB_%s' % syslib
93 missing.append(syslib)
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 return conf.CHECK_BUNDLED_SYSTEM(libname,
106 minversion=minversion,
108 implied_deps=implied_deps,
113 def CHECK_BUNDLED_SYSTEM(conf, libname, minversion='0.0.0',
114 checkfunctions=None, headers=None,
115 onlyif=None, implied_deps=None,
116 require_headers=True, pkg=None):
117 '''check if a library is available as a system library.
118 this first tries via pkg-config, then if that fails
119 tries by testing for a specified function in the specified lib
121 if conf.LIB_MUST_BE_BUNDLED(libname):
123 found = 'FOUND_SYSTEMLIB_%s' % libname
124 if found in conf.env:
125 return conf.env[found]
127 def check_functions_headers():
128 '''helper function for CHECK_BUNDLED_SYSTEM'''
129 if require_headers and headers and not conf.CHECK_HEADERS(headers, lib=libname):
131 if checkfunctions is not None:
132 ok = conf.CHECK_FUNCS_IN(checkfunctions, libname, headers=headers,
133 empty_decl=False, set_target=False)
139 # see if the library should only use a system version if another dependent
140 # system version is found. That prevents possible use of mixed library
143 missing = conf.CHECK_PREREQUISITES(onlyif)
145 if not conf.LIB_MAY_BE_BUNDLED(libname):
146 Logs.error('ERROR: Use of system library %s depends on missing system library/libraries %r' % (libname, missing))
148 conf.env[found] = False
151 minversion = minimum_library_version(conf, libname, minversion)
153 msg = 'Checking for system %s' % libname
154 if minversion != '0.0.0':
155 msg += ' >= %s' % minversion
157 uselib_store=libname.upper()
161 # try pkgconfig first
162 if (conf.check_cfg(package=pkg,
163 args='"%s >= %s" --cflags --libs' % (pkg, minversion),
164 msg=msg, uselib_store=uselib_store) and
165 check_functions_headers()):
166 conf.SET_TARGET_TYPE(libname, 'SYSLIB')
167 conf.env[found] = True
169 conf.SET_SYSLIB_DEPS(libname, implied_deps)
171 if checkfunctions is not None:
172 if check_functions_headers():
173 conf.env[found] = True
175 conf.SET_SYSLIB_DEPS(libname, implied_deps)
176 conf.SET_TARGET_TYPE(libname, 'SYSLIB')
178 conf.env[found] = False
179 if not conf.LIB_MAY_BE_BUNDLED(libname):
180 Logs.error('ERROR: System library %s of version %s not found, and bundling disabled' % (libname, minversion))
185 def tuplize_version(version):
186 return tuple([int(x) for x in version.split(".")])
190 def CHECK_BUNDLED_SYSTEM_PYTHON(conf, libname, modulename, minversion='0.0.0'):
191 '''check if a python module is available on the system and
192 has the specified minimum version.
194 if conf.LIB_MUST_BE_BUNDLED(libname):
197 # see if the library should only use a system version if another dependent
198 # system version is found. That prevents possible use of mixed library
200 minversion = minimum_library_version(conf, libname, minversion)
203 m = __import__(modulename)
208 version = m.__version__
209 except AttributeError:
212 found = tuplize_version(version) >= tuplize_version(minversion)
213 if not found and not conf.LIB_MAY_BE_BUNDLED(libname):
214 Logs.error('ERROR: Python module %s of version %s not found, and bundling disabled' % (libname, minversion))
219 def NONSHARED_BINARY(bld, name):
220 '''return True if a binary should be built without non-system shared libs'''
221 return target_in_list(name, bld.env.NONSHARED_BINARIES, False)
222 Build.BuildContext.NONSHARED_BINARY = NONSHARED_BINARY