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 if libname in conf.env.BUNDLED_LIBS:
75 if '!%s' % libname in conf.env.BUNDLED_LIBS:
77 if 'NONE' in conf.env.BUNDLED_LIBS:
82 def LIB_MUST_BE_BUNDLED(conf, libname):
83 if libname in conf.env.BUNDLED_LIBS:
85 if '!%s' % libname in conf.env.BUNDLED_LIBS:
87 if 'ALL' in conf.env.BUNDLED_LIBS:
92 def LIB_MUST_BE_PRIVATE(conf, libname):
93 return ('ALL' in conf.env.PRIVATE_LIBS or
94 libname in conf.env.PRIVATE_LIBS)
97 def CHECK_PREREQUISITES(conf, prereqs):
99 for syslib in TO_LIST(prereqs):
100 f = 'FOUND_SYSTEMLIB_%s' % syslib
101 if not f in conf.env:
102 missing.append(syslib)
108 def CHECK_BUNDLED_SYSTEM_PKG(conf, libname, minversion='0.0.0',
109 onlyif=None, implied_deps=None, pkg=None):
110 '''check if a library is available as a system library.
112 This only tries using pkg-config
114 return conf.CHECK_BUNDLED_SYSTEM(libname,
115 minversion=minversion,
117 implied_deps=implied_deps,
122 def CHECK_BUNDLED_SYSTEM(conf, libname, minversion='0.0.0',
123 checkfunctions=None, headers=None, checkcode=None,
124 onlyif=None, implied_deps=None,
125 require_headers=True, pkg=None, set_target=True):
126 '''check if a library is available as a system library.
127 this first tries via pkg-config, then if that fails
128 tries by testing for a specified function in the specified lib
130 if conf.LIB_MUST_BE_BUNDLED(libname):
132 found = 'FOUND_SYSTEMLIB_%s' % libname
133 if found in conf.env:
134 return conf.env[found]
136 def check_functions_headers_code():
137 '''helper function for CHECK_BUNDLED_SYSTEM'''
138 if require_headers and headers and not conf.CHECK_HEADERS(headers, lib=libname):
140 if checkfunctions is not None:
141 ok = conf.CHECK_FUNCS_IN(checkfunctions, libname, headers=headers,
142 empty_decl=False, set_target=False)
145 if checkcode is not None:
146 define='CHECK_BUNDLED_SYSTEM_%s' % libname.upper()
147 ok = conf.CHECK_CODE(checkcode, lib=libname,
148 headers=headers, local_include=False,
149 msg=msg, define=define)
150 conf.CONFIG_RESET(define)
156 # see if the library should only use a system version if another dependent
157 # system version is found. That prevents possible use of mixed library
160 missing = conf.CHECK_PREREQUISITES(onlyif)
162 if not conf.LIB_MAY_BE_BUNDLED(libname):
163 Logs.error('ERROR: Use of system library %s depends on missing system library/libraries %r' % (libname, missing))
165 conf.env[found] = False
168 minversion = minimum_library_version(conf, libname, minversion)
170 msg = 'Checking for system %s' % libname
171 if minversion != '0.0.0':
172 msg += ' >= %s' % minversion
174 uselib_store=libname.upper()
178 # try pkgconfig first
179 if (conf.check_cfg(package=pkg,
180 args='"%s >= %s" --cflags --libs' % (pkg, minversion),
181 msg=msg, uselib_store=uselib_store) and
182 check_functions_headers_code()):
184 conf.SET_TARGET_TYPE(libname, 'SYSLIB')
185 conf.env[found] = True
187 conf.SET_SYSLIB_DEPS(libname, implied_deps)
189 if checkfunctions is not None:
190 if check_functions_headers_code():
191 conf.env[found] = True
193 conf.SET_SYSLIB_DEPS(libname, implied_deps)
195 conf.SET_TARGET_TYPE(libname, 'SYSLIB')
197 conf.env[found] = False
198 if not conf.LIB_MAY_BE_BUNDLED(libname):
199 Logs.error('ERROR: System library %s of version %s not found, and bundling disabled' % (libname, minversion))
204 def tuplize_version(version):
205 return tuple([int(x) for x in version.split(".")])
209 def CHECK_BUNDLED_SYSTEM_PYTHON(conf, libname, modulename, minversion='0.0.0'):
210 '''check if a python module is available on the system and
211 has the specified minimum version.
213 if conf.LIB_MUST_BE_BUNDLED(libname):
216 # see if the library should only use a system version if another dependent
217 # system version is found. That prevents possible use of mixed library
219 minversion = minimum_library_version(conf, libname, minversion)
222 m = __import__(modulename)
227 version = m.__version__
228 except AttributeError:
231 found = tuplize_version(version) >= tuplize_version(minversion)
232 if not found and not conf.LIB_MAY_BE_BUNDLED(libname):
233 Logs.error('ERROR: Python module %s of version %s not found, and bundling disabled' % (libname, minversion))
238 def NONSHARED_BINARY(bld, name):
239 '''return True if a binary should be built without non-system shared libs'''
240 return target_in_list(name, bld.env.NONSHARED_BINARIES, False)
241 Build.BuildContext.NONSHARED_BINARY = NONSHARED_BINARY