1 # functions to support bundled libraries
4 from waflib
import Build
, Options
, Logs
5 from waflib
.Configure
import conf
6 from wafsamba
import samba_utils
8 def PRIVATE_NAME(bld
, name
):
9 '''possibly rename a library to include a bundled extension'''
11 extension
= bld
.env
.PRIVATE_EXTENSION
13 if name
in bld
.env
.PRIVATE_EXTENSION_EXCEPTION
:
16 if extension
and name
.startswith('%s' % extension
):
19 if extension
and name
.endswith('%s' % extension
):
22 return "%s-%s" % (name
, extension
)
25 def target_in_list(target
, lst
, default
):
38 def BUILTIN_LIBRARY(bld
, name
):
39 '''return True if a library should be builtin
40 instead of being built as a shared lib'''
41 return target_in_list(name
, bld
.env
.BUILTIN_LIBRARIES
, False)
42 Build
.BuildContext
.BUILTIN_LIBRARY
= BUILTIN_LIBRARY
45 def BUILTIN_DEFAULT(opt
, builtins
):
46 '''set a comma separated default list of builtin libraries for this package'''
47 if 'BUILTIN_LIBRARIES_DEFAULT' in Options
.options
.__dict
__:
49 Options
.options
.__dict
__['BUILTIN_LIBRARIES_DEFAULT'] = builtins
50 Options
.OptionsContext
.BUILTIN_DEFAULT
= BUILTIN_DEFAULT
53 def PRIVATE_EXTENSION_DEFAULT(opt
, extension
, noextension
=''):
54 '''set a default private library extension'''
55 if 'PRIVATE_EXTENSION_DEFAULT' in Options
.options
.__dict
__:
57 Options
.options
.__dict
__['PRIVATE_EXTENSION_DEFAULT'] = extension
58 Options
.options
.__dict
__['PRIVATE_EXTENSION_EXCEPTION'] = noextension
59 Options
.OptionsContext
.PRIVATE_EXTENSION_DEFAULT
= PRIVATE_EXTENSION_DEFAULT
62 def minimum_library_version(conf
, libname
, default
):
63 '''allow override of minimum system library version'''
65 minlist
= Options
.options
.MINIMUM_LIBRARY_VERSION
69 for m
in minlist
.split(','):
72 Logs
.error("Bad syntax for --minimum-library-version of %s" % m
)
80 def LIB_MAY_BE_BUNDLED(conf
, libname
):
81 if libname
in conf
.env
.SYSTEM_LIBS
:
83 if libname
in conf
.env
.BUNDLED_LIBS
:
85 if '!%s' % libname
in conf
.env
.BUNDLED_LIBS
:
87 if 'NONE' in conf
.env
.BUNDLED_LIBS
:
91 def __LIB_MUST_BE(liblist_in
, defaults
, libname
):
93 for lib
in liblist_in
:
99 if libname
in liblist
:
101 if '!%s' % libname
in liblist
:
108 def LIB_MUST_BE_BUNDLED(conf
, libname
):
109 return __LIB_MUST_BE(conf
.env
.BUNDLED_LIBS
, [], libname
)
112 def LIB_MUST_BE_PRIVATE(conf
, libname
):
113 return __LIB_MUST_BE(conf
.env
.PRIVATE_LIBS
, conf
.env
.DEFAULT_PRIVATE_LIBS
, libname
)
116 def CHECK_BUNDLED_SYSTEM_PKG(conf
, libname
, minversion
='0.0.0',
117 maxversion
=None, version_blacklist
=None,
118 onlyif
=None, implied_deps
=None, pkg
=None):
119 '''check if a library is available as a system library.
121 This only tries using pkg-config
123 if version_blacklist
is None:
124 version_blacklist
= []
125 return conf
.CHECK_BUNDLED_SYSTEM(libname
,
126 minversion
=minversion
,
127 maxversion
=maxversion
,
128 version_blacklist
=version_blacklist
,
130 implied_deps
=implied_deps
,
134 def CHECK_BUNDLED_SYSTEM(conf
, libname
, minversion
='0.0.0',
135 maxversion
=None, version_blacklist
=None,
136 checkfunctions
=None, headers
=None, checkcode
=None,
137 onlyif
=None, implied_deps
=None,
138 require_headers
=True, pkg
=None, set_target
=True):
139 '''check if a library is available as a system library.
140 this first tries via pkg-config, then if that fails
141 tries by testing for a specified function in the specified lib
143 # We always do a logic validation of 'onlyif' first
144 if version_blacklist
is None:
145 version_blacklist
= []
148 for l
in samba_utils
.TO_LIST(onlyif
):
149 f
= 'FOUND_SYSTEMLIB_%s' % l
150 if not f
in conf
.env
:
151 Logs
.error('ERROR: CHECK_BUNDLED_SYSTEM(%s) - ' % (libname
) +
152 'missing prerequisite check for ' +
153 'system library %s, onlyif=%r' % (l
, onlyif
))
157 found
= 'FOUND_SYSTEMLIB_%s' % libname
158 if found
in conf
.env
:
159 return conf
.env
[found
]
160 if conf
.LIB_MUST_BE_BUNDLED(libname
):
161 conf
.env
[found
] = False
164 # see if the library should only use a system version if another dependent
165 # system version is found. That prevents possible use of mixed library
168 if not conf
.LIB_MAY_BE_BUNDLED(libname
):
169 Logs
.error('ERROR: Use of system library %s depends on missing system library/libraries %r' % (libname
, missing
))
171 conf
.env
[found
] = False
174 def check_functions_headers_code():
175 '''helper function for CHECK_BUNDLED_SYSTEM'''
176 if require_headers
and headers
and not conf
.CHECK_HEADERS(headers
, lib
=libname
):
178 if checkfunctions
is not None:
179 ok
= conf
.CHECK_FUNCS_IN(checkfunctions
, libname
, headers
=headers
,
180 empty_decl
=False, set_target
=False)
183 if checkcode
is not None:
184 define
='CHECK_BUNDLED_SYSTEM_%s' % libname
.upper()
185 ok
= conf
.CHECK_CODE(checkcode
, lib
=libname
,
186 headers
=headers
, local_include
=False,
187 msg
=msg
, define
=define
)
188 conf
.CONFIG_RESET(define
)
193 minversion
= minimum_library_version(conf
, libname
, minversion
)
195 msg
= 'Checking for system %s' % libname
197 if minversion
!= '0.0.0':
198 msg_ver
.append('>=%s' % minversion
)
199 if maxversion
is not None:
200 msg_ver
.append('<=%s' % maxversion
)
201 for v
in version_blacklist
:
202 msg_ver
.append('!=%s' % v
)
204 msg
+= " (%s)" % (" ".join(msg_ver
))
206 uselib_store
=libname
.upper()
210 version_checks
= '%s >= %s' % (pkg
, minversion
)
211 if maxversion
is not None:
212 version_checks
+= ' %s <= %s' % (pkg
, maxversion
)
214 version_checks
+= "".join(' %s != %s' % (pkg
, v
) for v
in version_blacklist
)
216 # try pkgconfig first
217 if (conf
.CHECK_CFG(package
=pkg
,
218 args
='"%s" --cflags --libs' % (version_checks
),
219 msg
=msg
, uselib_store
=uselib_store
) and
220 check_functions_headers_code()):
222 conf
.SET_TARGET_TYPE(libname
, 'SYSLIB')
223 conf
.env
[found
] = True
225 conf
.SET_SYSLIB_DEPS(libname
, implied_deps
)
227 if checkfunctions
is not None:
228 if check_functions_headers_code():
229 conf
.env
[found
] = True
231 conf
.SET_SYSLIB_DEPS(libname
, implied_deps
)
233 conf
.SET_TARGET_TYPE(libname
, 'SYSLIB')
235 conf
.env
[found
] = False
236 if not conf
.LIB_MAY_BE_BUNDLED(libname
):
237 Logs
.error('ERROR: System library %s of version %s not found, and bundling disabled' % (libname
, minversion
))
242 def tuplize_version(version
):
243 return tuple([int(x
) for x
in version
.split(".")])
246 def CHECK_BUNDLED_SYSTEM_PYTHON(conf
, libname
, modulename
, minversion
='0.0.0'):
247 '''check if a python module is available on the system and
248 has the specified minimum version.
250 if conf
.LIB_MUST_BE_BUNDLED(libname
):
253 # see if the library should only use a system version if another dependent
254 # system version is found. That prevents possible use of mixed library
256 minversion
= minimum_library_version(conf
, libname
, minversion
)
259 m
= __import__(modulename
)
264 version
= m
.__version
__
265 except AttributeError:
268 found
= tuplize_version(version
) >= tuplize_version(minversion
)
269 if not found
and not conf
.LIB_MAY_BE_BUNDLED(libname
):
270 Logs
.error('ERROR: Python module %s of version %s not found, and bundling disabled' % (libname
, minversion
))
275 def NONSHARED_BINARY(bld
, name
):
276 '''return True if a binary should be built without non-system shared libs'''
277 return target_in_list(name
, bld
.env
.NONSHARED_BINARIES
, False)
278 Build
.BuildContext
.NONSHARED_BINARY
= NONSHARED_BINARY