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 if bld
.env
.DISABLE_SHARED
:
35 return target_in_list(name
, bld
.env
.BUILTIN_LIBRARIES
, False)
36 Build
.BuildContext
.BUILTIN_LIBRARY
= BUILTIN_LIBRARY
39 def BUILTIN_DEFAULT(opt
, builtins
):
40 '''set a comma separated default list of builtin libraries for this package'''
41 if 'BUILTIN_LIBRARIES_DEFAULT' in Options
.options
:
43 Options
.options
['BUILTIN_LIBRARIES_DEFAULT'] = builtins
44 Options
.Handler
.BUILTIN_DEFAULT
= BUILTIN_DEFAULT
47 def PRIVATE_EXTENSION_DEFAULT(opt
, extension
, noextension
=''):
48 '''set a default private library extension'''
49 if 'PRIVATE_EXTENSION_DEFAULT' in Options
.options
:
51 Options
.options
['PRIVATE_EXTENSION_DEFAULT'] = extension
52 Options
.options
['PRIVATE_EXTENSION_EXCEPTION'] = noextension
53 Options
.Handler
.PRIVATE_EXTENSION_DEFAULT
= PRIVATE_EXTENSION_DEFAULT
56 def minimum_library_version(conf
, libname
, default
):
57 '''allow override of mininum system library version'''
59 minlist
= Options
.options
.MINIMUM_LIBRARY_VERSION
63 for m
in minlist
.split(','):
66 Logs
.error("Bad syntax for --minimum-library-version of %s" % m
)
74 def LIB_MAY_BE_BUNDLED(conf
, libname
):
75 return ('NONE' not in conf
.env
.BUNDLED_LIBS
and
76 '!%s' % libname
not in conf
.env
.BUNDLED_LIBS
)
80 def LIB_MUST_BE_BUNDLED(conf
, libname
):
81 return ('ALL' in conf
.env
.BUNDLED_LIBS
or
82 libname
in conf
.env
.BUNDLED_LIBS
)
85 def LIB_MUST_BE_PRIVATE(conf
, libname
):
86 return ('ALL' in conf
.env
.PRIVATE_LIBS
or
87 libname
in conf
.env
.PRIVATE_LIBS
)
90 def CHECK_PREREQUISITES(conf
, prereqs
):
92 for syslib
in TO_LIST(prereqs
):
93 f
= 'FOUND_SYSTEMLIB_%s' % syslib
95 missing
.append(syslib
)
101 def CHECK_BUNDLED_SYSTEM_PKG(conf
, libname
, minversion
='0.0.0',
102 onlyif
=None, implied_deps
=None, pkg
=None):
103 '''check if a library is available as a system library.
105 This only tries using pkg-config
107 if conf
.LIB_MUST_BE_BUNDLED(libname
):
109 found
= 'FOUND_SYSTEMLIB_%s' % libname
110 if found
in conf
.env
:
111 return conf
.env
[found
]
113 # see if the library should only use a system version if another dependent
114 # system version is found. That prevents possible use of mixed library
117 missing
= conf
.CHECK_PREREQUISITES(onlyif
)
119 if not conf
.LIB_MAY_BE_BUNDLED(libname
):
120 Logs
.error('ERROR: Use of system library %s depends on missing system library/libraries %r' % (libname
, missing
))
122 conf
.env
[found
] = False
125 minversion
= minimum_library_version(conf
, libname
, minversion
)
127 msg
= 'Checking for system %s' % libname
128 if minversion
!= '0.0.0':
129 msg
+= ' >= %s' % minversion
134 if conf
.check_cfg(package
=pkg
,
135 args
='"%s >= %s" --cflags --libs' % (pkg
, minversion
),
136 msg
=msg
, uselib_store
=libname
.upper()):
137 conf
.SET_TARGET_TYPE(libname
, 'SYSLIB')
138 conf
.env
[found
] = True
140 conf
.SET_SYSLIB_DEPS(libname
, implied_deps
)
142 conf
.env
[found
] = False
143 if not conf
.LIB_MAY_BE_BUNDLED(libname
):
144 Logs
.error('ERROR: System library %s of version %s not found, and bundling disabled' % (libname
, minversion
))
151 def CHECK_BUNDLED_SYSTEM(conf
, libname
, minversion
='0.0.0',
152 checkfunctions
=None, headers
=None,
153 onlyif
=None, implied_deps
=None,
154 require_headers
=True):
155 '''check if a library is available as a system library.
156 this first tries via pkg-config, then if that fails
157 tries by testing for a specified function in the specified lib
159 if conf
.LIB_MUST_BE_BUNDLED(libname
):
161 found
= 'FOUND_SYSTEMLIB_%s' % libname
162 if found
in conf
.env
:
163 return conf
.env
[found
]
165 def check_functions_headers():
166 '''helper function for CHECK_BUNDLED_SYSTEM'''
167 if checkfunctions
is None:
169 if require_headers
and headers
and not conf
.CHECK_HEADERS(headers
, lib
=libname
):
171 return conf
.CHECK_FUNCS_IN(checkfunctions
, libname
, headers
=headers
,
172 empty_decl
=False, set_target
=False)
174 # see if the library should only use a system version if another dependent
175 # system version is found. That prevents possible use of mixed library
178 missing
= conf
.CHECK_PREREQUISITES(onlyif
)
180 if not conf
.LIB_MAY_BE_BUNDLED(libname
):
181 Logs
.error('ERROR: Use of system library %s depends on missing system library/libraries %r' % (libname
, missing
))
183 conf
.env
[found
] = False
186 minversion
= minimum_library_version(conf
, libname
, minversion
)
188 msg
= 'Checking for system %s' % libname
189 if minversion
!= '0.0.0':
190 msg
+= ' >= %s' % minversion
192 # try pkgconfig first
193 if (conf
.check_cfg(package
=libname
,
194 args
='"%s >= %s" --cflags --libs' % (libname
, minversion
),
196 check_functions_headers()):
197 conf
.SET_TARGET_TYPE(libname
, 'SYSLIB')
198 conf
.env
[found
] = True
200 conf
.SET_SYSLIB_DEPS(libname
, implied_deps
)
202 if checkfunctions
is not None:
203 if check_functions_headers():
204 conf
.env
[found
] = True
206 conf
.SET_SYSLIB_DEPS(libname
, implied_deps
)
207 conf
.SET_TARGET_TYPE(libname
, 'SYSLIB')
209 conf
.env
[found
] = False
210 if not conf
.LIB_MAY_BE_BUNDLED(libname
):
211 Logs
.error('ERROR: System library %s of version %s not found, and bundling disabled' % (libname
, minversion
))
216 def tuplize_version(version
):
217 return tuple([int(x
) for x
in version
.split(".")])
221 def CHECK_BUNDLED_SYSTEM_PYTHON(conf
, libname
, modulename
, minversion
='0.0.0'):
222 '''check if a python module is available on the system and
223 has the specified minimum version.
225 if conf
.LIB_MUST_BE_BUNDLED(libname
):
228 # see if the library should only use a system version if another dependent
229 # system version is found. That prevents possible use of mixed library
231 minversion
= minimum_library_version(conf
, libname
, minversion
)
234 m
= __import__(modulename
)
239 version
= m
.__version
__
240 except AttributeError:
243 found
= tuplize_version(version
) >= tuplize_version(minversion
)
244 if not found
and not conf
.LIB_MAY_BE_BUNDLED(libname
):
245 Logs
.error('ERROR: Python module %s of version %s not found, and bundling disabled' % (libname
, minversion
))
250 def NONSHARED_BINARY(bld
, name
):
251 '''return True if a binary should be built without non-system shared libs'''
252 if bld
.env
.DISABLE_SHARED
:
254 return target_in_list(name
, bld
.env
.NONSHARED_BINARIES
, False)
255 Build
.BuildContext
.NONSHARED_BINARY
= NONSHARED_BINARY