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 if conf
.LIB_MUST_BE_BUNDLED(libname
):
107 found
= 'FOUND_SYSTEMLIB_%s' % libname
108 if found
in conf
.env
:
109 return conf
.env
[found
]
111 # see if the library should only use a system version if another dependent
112 # system version is found. That prevents possible use of mixed library
115 missing
= conf
.CHECK_PREREQUISITES(onlyif
)
117 if not conf
.LIB_MAY_BE_BUNDLED(libname
):
118 Logs
.error('ERROR: Use of system library %s depends on missing system library/libraries %r' % (libname
, missing
))
120 conf
.env
[found
] = False
123 minversion
= minimum_library_version(conf
, libname
, minversion
)
125 msg
= 'Checking for system %s' % libname
126 if minversion
!= '0.0.0':
127 msg
+= ' >= %s' % minversion
132 if conf
.check_cfg(package
=pkg
,
133 args
='"%s >= %s" --cflags --libs' % (pkg
, minversion
),
134 msg
=msg
, uselib_store
=libname
.upper()):
135 conf
.SET_TARGET_TYPE(libname
, 'SYSLIB')
136 conf
.env
[found
] = True
138 conf
.SET_SYSLIB_DEPS(libname
, implied_deps
)
140 conf
.env
[found
] = False
141 if not conf
.LIB_MAY_BE_BUNDLED(libname
):
142 Logs
.error('ERROR: System library %s of version %s not found, and bundling disabled' % (libname
, minversion
))
149 def CHECK_BUNDLED_SYSTEM(conf
, libname
, minversion
='0.0.0',
150 checkfunctions
=None, headers
=None,
151 onlyif
=None, implied_deps
=None,
152 require_headers
=True):
153 '''check if a library is available as a system library.
154 this first tries via pkg-config, then if that fails
155 tries by testing for a specified function in the specified lib
157 if conf
.LIB_MUST_BE_BUNDLED(libname
):
159 found
= 'FOUND_SYSTEMLIB_%s' % libname
160 if found
in conf
.env
:
161 return conf
.env
[found
]
163 def check_functions_headers():
164 '''helper function for CHECK_BUNDLED_SYSTEM'''
165 if checkfunctions
is None:
167 if require_headers
and headers
and not conf
.CHECK_HEADERS(headers
, lib
=libname
):
169 return conf
.CHECK_FUNCS_IN(checkfunctions
, libname
, headers
=headers
,
170 empty_decl
=False, set_target
=False)
172 # see if the library should only use a system version if another dependent
173 # system version is found. That prevents possible use of mixed library
176 missing
= conf
.CHECK_PREREQUISITES(onlyif
)
178 if not conf
.LIB_MAY_BE_BUNDLED(libname
):
179 Logs
.error('ERROR: Use of system library %s depends on missing system library/libraries %r' % (libname
, missing
))
181 conf
.env
[found
] = False
184 minversion
= minimum_library_version(conf
, libname
, minversion
)
186 msg
= 'Checking for system %s' % libname
187 if minversion
!= '0.0.0':
188 msg
+= ' >= %s' % minversion
190 # try pkgconfig first
191 if (conf
.check_cfg(package
=libname
,
192 args
='"%s >= %s" --cflags --libs' % (libname
, minversion
),
194 check_functions_headers()):
195 conf
.SET_TARGET_TYPE(libname
, 'SYSLIB')
196 conf
.env
[found
] = True
198 conf
.SET_SYSLIB_DEPS(libname
, implied_deps
)
200 if checkfunctions
is not None:
201 if check_functions_headers():
202 conf
.env
[found
] = True
204 conf
.SET_SYSLIB_DEPS(libname
, implied_deps
)
205 conf
.SET_TARGET_TYPE(libname
, 'SYSLIB')
207 conf
.env
[found
] = False
208 if not conf
.LIB_MAY_BE_BUNDLED(libname
):
209 Logs
.error('ERROR: System library %s of version %s not found, and bundling disabled' % (libname
, minversion
))
214 def tuplize_version(version
):
215 return tuple([int(x
) for x
in version
.split(".")])
219 def CHECK_BUNDLED_SYSTEM_PYTHON(conf
, libname
, modulename
, minversion
='0.0.0'):
220 '''check if a python module is available on the system and
221 has the specified minimum version.
223 if conf
.LIB_MUST_BE_BUNDLED(libname
):
226 # see if the library should only use a system version if another dependent
227 # system version is found. That prevents possible use of mixed library
229 minversion
= minimum_library_version(conf
, libname
, minversion
)
232 m
= __import__(modulename
)
237 version
= m
.__version
__
238 except AttributeError:
241 found
= tuplize_version(version
) >= tuplize_version(minversion
)
242 if not found
and not conf
.LIB_MAY_BE_BUNDLED(libname
):
243 Logs
.error('ERROR: Python module %s of version %s not found, and bundling disabled' % (libname
, minversion
))
248 def NONSHARED_BINARY(bld
, name
):
249 '''return True if a binary should be built without non-system shared libs'''
250 return target_in_list(name
, bld
.env
.NONSHARED_BINARIES
, False)
251 Build
.BuildContext
.NONSHARED_BINARY
= NONSHARED_BINARY