1 # functions to support bundled libraries
3 from Configure
import conf
5 from samba_utils
import *
7 def BUNDLED_NAME(bld
, name
, bundled_extension
):
8 '''possibly rename a library to include a bundled extension'''
9 if bld
.env
.DISABLE_SHARED
or not bundled_extension
:
11 if name
in bld
.env
.BUNDLED_EXTENSION_EXCEPTION
:
13 extension
= getattr(bld
.env
, 'BUNDLED_EXTENSION', '')
15 return name
+ '-' + extension
19 def target_in_list(target
, lst
, default
):
32 def BUILTIN_LIBRARY(bld
, name
):
33 '''return True if a library should be builtin
34 instead of being built as a shared lib'''
35 if bld
.env
.DISABLE_SHARED
:
37 return target_in_list(name
, bld
.env
.BUILTIN_LIBRARIES
, False)
38 Build
.BuildContext
.BUILTIN_LIBRARY
= BUILTIN_LIBRARY
41 def BUILTIN_DEFAULT(opt
, builtins
):
42 '''set a comma separated default list of builtin libraries for this package'''
43 if 'BUILTIN_LIBRARIES_DEFAULT' in Options
.options
:
45 Options
.options
['BUILTIN_LIBRARIES_DEFAULT'] = builtins
46 Options
.Handler
.BUILTIN_DEFAULT
= BUILTIN_DEFAULT
49 def BUNDLED_EXTENSION_DEFAULT(opt
, extension
, noextension
=''):
50 '''set a default bundled library extension'''
51 if 'BUNDLED_EXTENSION_DEFAULT' in Options
.options
:
53 Options
.options
['BUNDLED_EXTENSION_DEFAULT'] = extension
54 Options
.options
['BUNDLED_EXTENSION_EXCEPTION'] = noextension
55 Options
.Handler
.BUNDLED_EXTENSION_DEFAULT
= BUNDLED_EXTENSION_DEFAULT
58 def minimum_library_version(conf
, libname
, default
):
59 '''allow override of mininum system library version'''
61 minlist
= Options
.options
.MINIMUM_LIBRARY_VERSION
65 for m
in minlist
.split(','):
68 Logs
.error("Bad syntax for --minimum-library-version of %s" % m
)
76 def LIB_MAY_BE_BUNDLED(conf
, libname
):
77 return ('NONE' not in conf
.env
.BUNDLED_LIBS
and
78 '!%s' % libname
not in conf
.env
.BUNDLED_LIBS
)
82 def LIB_MUST_BE_BUNDLED(conf
, libname
):
83 return ('ALL' in conf
.env
.BUNDLED_LIBS
or
84 libname
in conf
.env
.BUNDLED_LIBS
)
89 def CHECK_BUNDLED_SYSTEM(conf
, libname
, minversion
='0.0.0',
90 checkfunctions
=None, headers
=None,
91 onlyif
=None, implied_deps
=None,
92 require_headers
=True):
93 '''check if a library is available as a system library.
94 this first tries via pkg-config, then if that fails
95 tries by testing for a specified function in the specified lib
97 if conf
.LIB_MUST_BE_BUNDLED(libname
):
99 found
= 'FOUND_SYSTEMLIB_%s' % libname
100 if found
in conf
.env
:
101 return conf
.env
[found
]
103 def check_functions_headers():
104 '''helper function for CHECK_BUNDLED_SYSTEM'''
105 if checkfunctions
is None:
107 if require_headers
and headers
and not conf
.CHECK_HEADERS(headers
):
109 return conf
.CHECK_FUNCS_IN(checkfunctions
, libname
, headers
=headers
,
110 empty_decl
=False, set_target
=False)
112 # see if the library should only use a system version if another dependent
113 # system version is found. That prevents possible use of mixed library
116 for syslib
in TO_LIST(onlyif
):
117 f
= 'FOUND_SYSTEMLIB_%s' % syslib
118 if not f
in conf
.env
:
119 if not conf
.LIB_MAY_BE_BUNDLED(libname
):
120 Logs
.error('ERROR: Use of system library %s depends on missing system library %s' % (libname
, syslib
))
122 conf
.env
[found
] = False
125 minversion
= minimum_library_version(conf
, libname
, minversion
)
127 # try pkgconfig first
128 if (conf
.check_cfg(package
=libname
,
129 args
='"%s >= %s" --cflags --libs' % (libname
, minversion
),
130 msg
='Checking for system %s >= %s' % (libname
, minversion
)) and
131 check_functions_headers()):
132 conf
.SET_TARGET_TYPE(libname
, 'SYSLIB')
133 conf
.env
[found
] = True
135 conf
.SET_SYSLIB_DEPS(libname
, implied_deps
)
137 if checkfunctions
is not None:
138 if check_functions_headers():
139 conf
.env
[found
] = True
141 conf
.SET_SYSLIB_DEPS(libname
, implied_deps
)
142 conf
.SET_TARGET_TYPE(libname
, 'SYSLIB')
144 conf
.env
[found
] = False
145 if not conf
.LIB_MAY_BE_BUNDLED(libname
):
146 Logs
.error('ERROR: System library %s of version %s not found, and bundling disabled' % (libname
, minversion
))
153 def CHECK_BUNDLED_SYSTEM_PYTHON(conf
, libname
, modulename
, minversion
='0.0.0'):
154 '''check if a python module is available on the system and
155 has the specified minimum version.
157 if conf
.LIB_MUST_BE_BUNDLED(libname
):
160 # see if the library should only use a system version if another dependent
161 # system version is found. That prevents possible use of mixed library
163 minversion
= minimum_library_version(conf
, libname
, minversion
)
166 m
= __import__(modulename
)
171 version
= m
.__version
__
172 except AttributeError:
175 found
= tuple(minversion
.split(".")) >= tuple(version
.split("."))
176 if not found
and not conf
.LIB_MAY_BE_BUNDLED(libname
):
177 Logs
.error('ERROR: Python module %s of version %s not found, and bundling disabled' % (libname
, minversion
))
182 def NONSHARED_BINARY(bld
, name
):
183 '''return True if a binary should be built without non-system shared libs'''
184 if bld
.env
.DISABLE_SHARED
:
186 return target_in_list(name
, bld
.env
.NONSHARED_BINARIES
, False)
187 Build
.BuildContext
.NONSHARED_BINARY
= NONSHARED_BINARY