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 if not private_library:
13 # we now use the same private name for libraries as the public name.
14 # see http://git.samba.org/?p=tridge/junkcode.git;a=tree;f=shlib for a
15 # demonstration that this is the right thing to do
16 # also see http://lists.samba.org/archive/samba-technical/2011-January/075816.html
20 extension = bld.env.PRIVATE_EXTENSION
22 if extension and name.startswith('%s' % extension):
25 if extension and name.endswith('%s' % extension):
28 return "%s-%s" % (name, extension)
31 def target_in_list(target, lst, default):
44 def BUILTIN_LIBRARY(bld, name):
45 '''return True if a library should be builtin
46 instead of being built as a shared lib'''
47 return target_in_list(name, bld.env.BUILTIN_LIBRARIES, False)
48 Build.BuildContext.BUILTIN_LIBRARY = BUILTIN_LIBRARY
51 def BUILTIN_DEFAULT(opt, builtins):
52 '''set a comma separated default list of builtin libraries for this package'''
53 if 'BUILTIN_LIBRARIES_DEFAULT' in Options.options:
55 Options.options['BUILTIN_LIBRARIES_DEFAULT'] = builtins
56 Options.Handler.BUILTIN_DEFAULT = BUILTIN_DEFAULT
59 def PRIVATE_EXTENSION_DEFAULT(opt, extension, noextension=''):
60 '''set a default private library extension'''
61 if 'PRIVATE_EXTENSION_DEFAULT' in Options.options:
63 Options.options['PRIVATE_EXTENSION_DEFAULT'] = extension
64 Options.options['PRIVATE_EXTENSION_EXCEPTION'] = noextension
65 Options.Handler.PRIVATE_EXTENSION_DEFAULT = PRIVATE_EXTENSION_DEFAULT
68 def minimum_library_version(conf, libname, default):
69 '''allow override of mininum system library version'''
71 minlist = Options.options.MINIMUM_LIBRARY_VERSION
75 for m in minlist.split(','):
78 Logs.error("Bad syntax for --minimum-library-version of %s" % m)
86 def LIB_MAY_BE_BUNDLED(conf, libname):
87 if libname in conf.env.BUNDLED_LIBS:
89 if '!%s' % libname in conf.env.BUNDLED_LIBS:
91 if 'NONE' in conf.env.BUNDLED_LIBS:
96 def LIB_MUST_BE_BUNDLED(conf, libname):
97 if libname in conf.env.BUNDLED_LIBS:
99 if '!%s' % libname in conf.env.BUNDLED_LIBS:
101 if 'ALL' in conf.env.BUNDLED_LIBS:
106 def LIB_MUST_BE_PRIVATE(conf, libname):
107 return ('ALL' in conf.env.PRIVATE_LIBS or
108 libname in conf.env.PRIVATE_LIBS)
111 def CHECK_PREREQUISITES(conf, prereqs):
113 for syslib in TO_LIST(prereqs):
114 f = 'FOUND_SYSTEMLIB_%s' % syslib
115 if not f in conf.env:
116 missing.append(syslib)
122 def CHECK_BUNDLED_SYSTEM_PKG(conf, libname, minversion='0.0.0',
123 onlyif=None, implied_deps=None, pkg=None):
124 '''check if a library is available as a system library.
126 This only tries using pkg-config
128 return conf.CHECK_BUNDLED_SYSTEM(libname,
129 minversion=minversion,
131 implied_deps=implied_deps,
136 def CHECK_BUNDLED_SYSTEM(conf, libname, minversion='0.0.0',
137 checkfunctions=None, headers=None, checkcode=None,
138 onlyif=None, implied_deps=None,
139 require_headers=True, pkg=None, set_target=True):
140 '''check if a library is available as a system library.
141 this first tries via pkg-config, then if that fails
142 tries by testing for a specified function in the specified lib
144 if conf.LIB_MUST_BE_BUNDLED(libname):
146 found = 'FOUND_SYSTEMLIB_%s' % libname
147 if found in conf.env:
148 return conf.env[found]
150 def check_functions_headers_code():
151 '''helper function for CHECK_BUNDLED_SYSTEM'''
152 if require_headers and headers and not conf.CHECK_HEADERS(headers, lib=libname):
154 if checkfunctions is not None:
155 ok = conf.CHECK_FUNCS_IN(checkfunctions, libname, headers=headers,
156 empty_decl=False, set_target=False)
159 if checkcode is not None:
160 define='CHECK_BUNDLED_SYSTEM_%s' % libname.upper()
161 ok = conf.CHECK_CODE(checkcode, lib=libname,
162 headers=headers, local_include=False,
163 msg=msg, define=define)
164 conf.CONFIG_RESET(define)
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 uselib_store=libname.upper()
192 # try pkgconfig first
193 if (conf.check_cfg(package=pkg,
194 args='"%s >= %s" --cflags --libs' % (pkg, minversion),
195 msg=msg, uselib_store=uselib_store) and
196 check_functions_headers_code()):
198 conf.SET_TARGET_TYPE(libname, 'SYSLIB')
199 conf.env[found] = True
201 conf.SET_SYSLIB_DEPS(libname, implied_deps)
203 if checkfunctions is not None:
204 if check_functions_headers_code():
205 conf.env[found] = True
207 conf.SET_SYSLIB_DEPS(libname, implied_deps)
209 conf.SET_TARGET_TYPE(libname, 'SYSLIB')
211 conf.env[found] = False
212 if not conf.LIB_MAY_BE_BUNDLED(libname):
213 Logs.error('ERROR: System library %s of version %s not found, and bundling disabled' % (libname, minversion))
218 def tuplize_version(version):
219 return tuple([int(x) for x in version.split(".")])
223 def CHECK_BUNDLED_SYSTEM_PYTHON(conf, libname, modulename, minversion='0.0.0'):
224 '''check if a python module is available on the system and
225 has the specified minimum version.
227 if conf.LIB_MUST_BE_BUNDLED(libname):
230 # see if the library should only use a system version if another dependent
231 # system version is found. That prevents possible use of mixed library
233 minversion = minimum_library_version(conf, libname, minversion)
236 m = __import__(modulename)
241 version = m.__version__
242 except AttributeError:
245 found = tuplize_version(version) >= tuplize_version(minversion)
246 if not found and not conf.LIB_MAY_BE_BUNDLED(libname):
247 Logs.error('ERROR: Python module %s of version %s not found, and bundling disabled' % (libname, minversion))
252 def NONSHARED_BINARY(bld, name):
253 '''return True if a binary should be built without non-system shared libs'''
254 return target_in_list(name, bld.env.NONSHARED_BINARIES, False)
255 Build.BuildContext.NONSHARED_BINARY = NONSHARED_BINARY