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'''
9 if bld
.env
.DISABLE_SHARED
or not private_extension
:
11 if name
in bld
.env
.PRIVATE_EXTENSION_EXCEPTION
and not private_library
:
13 if private_library
and bld
.EXPAND_VARIABLES(bld
.env
.LIBDIR
) != bld
.EXPAND_VARIABLES(bld
.env
.PRIVATELIBDIR
):
14 # Private libraries already have their own namespace in another way
16 extension
= getattr(bld
.env
, 'PRIVATE_EXTENSION', '')
18 return name
+ '-' + extension
22 def target_in_list(target
, lst
, default
):
35 def BUILTIN_LIBRARY(bld
, name
):
36 '''return True if a library should be builtin
37 instead of being built as a shared lib'''
38 if bld
.env
.DISABLE_SHARED
:
40 return target_in_list(name
, bld
.env
.BUILTIN_LIBRARIES
, False)
41 Build
.BuildContext
.BUILTIN_LIBRARY
= BUILTIN_LIBRARY
44 def BUILTIN_DEFAULT(opt
, builtins
):
45 '''set a comma separated default list of builtin libraries for this package'''
46 if 'BUILTIN_LIBRARIES_DEFAULT' in Options
.options
:
48 Options
.options
['BUILTIN_LIBRARIES_DEFAULT'] = builtins
49 Options
.Handler
.BUILTIN_DEFAULT
= BUILTIN_DEFAULT
52 def PRIVATE_EXTENSION_DEFAULT(opt
, extension
, noextension
=''):
53 '''set a default private library extension'''
54 if 'PRIVATE_EXTENSION_DEFAULT' in Options
.options
:
56 Options
.options
['PRIVATE_EXTENSION_DEFAULT'] = extension
57 Options
.options
['PRIVATE_EXTENSION_EXCEPTION'] = noextension
58 Options
.Handler
.PRIVATE_EXTENSION_DEFAULT
= PRIVATE_EXTENSION_DEFAULT
61 def minimum_library_version(conf
, libname
, default
):
62 '''allow override of mininum system library version'''
64 minlist
= Options
.options
.MINIMUM_LIBRARY_VERSION
68 for m
in minlist
.split(','):
71 Logs
.error("Bad syntax for --minimum-library-version of %s" % m
)
79 def LIB_MAY_BE_BUNDLED(conf
, libname
):
80 return ('NONE' not in conf
.env
.BUNDLED_LIBS
and
81 '!%s' % libname
not in conf
.env
.BUNDLED_LIBS
)
85 def LIB_MUST_BE_BUNDLED(conf
, libname
):
86 return ('ALL' in conf
.env
.BUNDLED_LIBS
or
87 libname
in conf
.env
.BUNDLED_LIBS
)
92 def CHECK_BUNDLED_SYSTEM(conf
, libname
, minversion
='0.0.0',
93 checkfunctions
=None, headers
=None,
94 onlyif
=None, implied_deps
=None,
95 require_headers
=True):
96 '''check if a library is available as a system library.
97 this first tries via pkg-config, then if that fails
98 tries by testing for a specified function in the specified lib
100 if conf
.LIB_MUST_BE_BUNDLED(libname
):
102 found
= 'FOUND_SYSTEMLIB_%s' % libname
103 if found
in conf
.env
:
104 return conf
.env
[found
]
106 def check_functions_headers():
107 '''helper function for CHECK_BUNDLED_SYSTEM'''
108 if checkfunctions
is None:
110 if require_headers
and headers
and not conf
.CHECK_HEADERS(headers
, lib
=libname
):
112 return conf
.CHECK_FUNCS_IN(checkfunctions
, libname
, headers
=headers
,
113 empty_decl
=False, set_target
=False)
115 # see if the library should only use a system version if another dependent
116 # system version is found. That prevents possible use of mixed library
119 for syslib
in TO_LIST(onlyif
):
120 f
= 'FOUND_SYSTEMLIB_%s' % syslib
121 if not f
in conf
.env
:
122 if not conf
.LIB_MAY_BE_BUNDLED(libname
):
123 Logs
.error('ERROR: Use of system library %s depends on missing system library %s' % (libname
, syslib
))
125 conf
.env
[found
] = False
128 minversion
= minimum_library_version(conf
, libname
, minversion
)
130 # try pkgconfig first
131 if (conf
.check_cfg(package
=libname
,
132 args
='"%s >= %s" --cflags --libs' % (libname
, minversion
),
133 msg
='Checking for system %s >= %s' % (libname
, minversion
)) and
134 check_functions_headers()):
135 conf
.SET_TARGET_TYPE(libname
, 'SYSLIB')
136 conf
.env
[found
] = True
138 conf
.SET_SYSLIB_DEPS(libname
, implied_deps
)
140 if checkfunctions
is not None:
141 if check_functions_headers():
142 conf
.env
[found
] = True
144 conf
.SET_SYSLIB_DEPS(libname
, implied_deps
)
145 conf
.SET_TARGET_TYPE(libname
, 'SYSLIB')
147 conf
.env
[found
] = False
148 if not conf
.LIB_MAY_BE_BUNDLED(libname
):
149 Logs
.error('ERROR: System library %s of version %s not found, and bundling disabled' % (libname
, minversion
))
156 def CHECK_BUNDLED_SYSTEM_PYTHON(conf
, libname
, modulename
, minversion
='0.0.0'):
157 '''check if a python module is available on the system and
158 has the specified minimum version.
160 if conf
.LIB_MUST_BE_BUNDLED(libname
):
163 # see if the library should only use a system version if another dependent
164 # system version is found. That prevents possible use of mixed library
166 minversion
= minimum_library_version(conf
, libname
, minversion
)
169 m
= __import__(modulename
)
174 version
= m
.__version
__
175 except AttributeError:
178 found
= tuple(minversion
.split(".")) >= tuple(version
.split("."))
179 if not found
and not conf
.LIB_MAY_BE_BUNDLED(libname
):
180 Logs
.error('ERROR: Python module %s of version %s not found, and bundling disabled' % (libname
, minversion
))
185 def NONSHARED_BINARY(bld
, name
):
186 '''return True if a binary should be built without non-system shared libs'''
187 if bld
.env
.DISABLE_SHARED
:
189 return target_in_list(name
, bld
.env
.NONSHARED_BINARIES
, False)
190 Build
.BuildContext
.NONSHARED_BINARY
= NONSHARED_BINARY