2010-03-28 07:09:36 +04:00
# functions to support bundled libraries
2015-10-27 22:46:46 +03:00
import sys
import Build , Options , Logs
2010-03-28 07:09:36 +04:00
from Configure import conf
2015-11-05 04:06:42 +03:00
from samba_utils import TO_LIST
2010-03-28 07:09:36 +04:00
2010-11-05 02:33:51 +03:00
def PRIVATE_NAME ( bld , name , private_extension , private_library ) :
2010-03-28 07:09:36 +04:00
''' possibly rename a library to include a bundled extension '''
2011-01-19 03:04:05 +03:00
2014-12-18 17:05:12 +03:00
if not private_library :
return name
2011-01-19 03:04:05 +03:00
# we now use the same private name for libraries as the public name.
# see http://git.samba.org/?p=tridge/junkcode.git;a=tree;f=shlib for a
# demonstration that this is the right thing to do
# also see http://lists.samba.org/archive/samba-technical/2011-January/075816.html
2014-12-18 17:05:12 +03:00
if private_extension :
return name
extension = bld . env . PRIVATE_EXTENSION
if extension and name . startswith ( ' %s ' % extension ) :
return name
if extension and name . endswith ( ' %s ' % extension ) :
return name
return " %s - %s " % ( name , extension )
2010-03-28 07:09:36 +04:00
2010-04-06 13:31:39 +04:00
def target_in_list ( target , lst , default ) :
for l in lst :
if target == l :
return True
if ' ! ' + target == l :
return False
if l == ' ALL ' :
return True
if l == ' NONE ' :
return False
return default
2010-03-28 07:09:36 +04:00
def BUILTIN_LIBRARY ( bld , name ) :
''' return True if a library should be builtin
instead of being built as a shared lib '''
2010-04-06 13:31:39 +04:00
return target_in_list ( name , bld . env . BUILTIN_LIBRARIES , False )
2010-04-18 06:43:15 +04:00
Build . BuildContext . BUILTIN_LIBRARY = BUILTIN_LIBRARY
2010-03-28 08:41:49 +04:00
def BUILTIN_DEFAULT ( opt , builtins ) :
''' set a comma separated default list of builtin libraries for this package '''
if ' BUILTIN_LIBRARIES_DEFAULT ' in Options . options :
return
Options . options [ ' BUILTIN_LIBRARIES_DEFAULT ' ] = builtins
Options . Handler . BUILTIN_DEFAULT = BUILTIN_DEFAULT
2010-10-24 01:26:43 +04:00
def PRIVATE_EXTENSION_DEFAULT ( opt , extension , noextension = ' ' ) :
''' set a default private library extension '''
if ' PRIVATE_EXTENSION_DEFAULT ' in Options . options :
2010-03-28 08:41:49 +04:00
return
2010-10-24 01:26:43 +04:00
Options . options [ ' PRIVATE_EXTENSION_DEFAULT ' ] = extension
Options . options [ ' PRIVATE_EXTENSION_EXCEPTION ' ] = noextension
Options . Handler . PRIVATE_EXTENSION_DEFAULT = PRIVATE_EXTENSION_DEFAULT
2010-03-28 09:38:27 +04:00
2010-04-12 03:49:56 +04:00
def minimum_library_version ( conf , libname , default ) :
''' allow override of mininum system library version '''
minlist = Options . options . MINIMUM_LIBRARY_VERSION
if not minlist :
return default
for m in minlist . split ( ' , ' ) :
a = m . split ( ' : ' )
if len ( a ) != 2 :
Logs . error ( " Bad syntax for --minimum-library-version of %s " % m )
sys . exit ( 1 )
if a [ 0 ] == libname :
return a [ 1 ]
return default
2010-03-28 15:01:04 +04:00
2010-06-19 15:47:11 +04:00
@conf
def LIB_MAY_BE_BUNDLED ( conf , libname ) :
2014-03-14 13:48:56 +04:00
if libname in conf . env . BUNDLED_LIBS :
return True
2014-03-14 13:47:30 +04:00
if ' ! %s ' % libname in conf . env . BUNDLED_LIBS :
return False
if ' NONE ' in conf . env . BUNDLED_LIBS :
return False
return True
2010-06-19 15:47:11 +04:00
@conf
def LIB_MUST_BE_BUNDLED ( conf , libname ) :
2014-03-14 13:48:12 +04:00
if libname in conf . env . BUNDLED_LIBS :
return True
2014-03-14 13:48:56 +04:00
if ' ! %s ' % libname in conf . env . BUNDLED_LIBS :
return False
2014-03-14 13:48:12 +04:00
if ' ALL ' in conf . env . BUNDLED_LIBS :
return True
return False
2010-06-19 15:47:11 +04:00
2012-04-19 09:34:48 +04:00
@conf
def LIB_MUST_BE_PRIVATE ( conf , libname ) :
return ( ' ALL ' in conf . env . PRIVATE_LIBS or
libname in conf . env . PRIVATE_LIBS )
2010-06-19 15:47:11 +04:00
2011-11-12 19:35:11 +04:00
@conf
def CHECK_BUNDLED_SYSTEM_PKG ( conf , libname , minversion = ' 0.0.0 ' ,
onlyif = None , implied_deps = None , pkg = None ) :
''' check if a library is available as a system library.
This only tries using pkg - config
'''
2014-03-14 12:55:45 +04:00
return conf . CHECK_BUNDLED_SYSTEM ( libname ,
minversion = minversion ,
onlyif = onlyif ,
implied_deps = implied_deps ,
pkg = pkg )
2011-11-12 19:35:11 +04:00
2010-03-28 09:38:27 +04:00
@conf
2010-03-28 10:05:30 +04:00
def CHECK_BUNDLED_SYSTEM ( conf , libname , minversion = ' 0.0.0 ' ,
2014-03-14 13:19:41 +04:00
checkfunctions = None , headers = None , checkcode = None ,
2010-03-30 15:06:32 +04:00
onlyif = None , implied_deps = None ,
2014-01-20 15:37:44 +04:00
require_headers = True , pkg = None , set_target = True ) :
2010-03-28 15:01:04 +04:00
''' check if a library is available as a system library.
this first tries via pkg - config , then if that fails
tries by testing for a specified function in the specified lib
'''
2015-08-27 11:47:05 +03:00
# We always do a logic validation of 'onlyif' first
missing = [ ]
if onlyif :
for l in TO_LIST ( onlyif ) :
f = ' FOUND_SYSTEMLIB_ %s ' % l
if not f in conf . env :
Logs . error ( ' ERROR: CHECK_BUNDLED_SYSTEM( %s ) - ' % ( libname ) +
' missing prerequisite check for ' +
' system library %s , onlyif= %r ' % ( l , onlyif ) )
sys . exit ( 1 )
if not conf . env [ f ] :
missing . append ( l )
2010-03-28 10:05:30 +04:00
found = ' FOUND_SYSTEMLIB_ %s ' % libname
if found in conf . env :
return conf . env [ found ]
2015-08-27 11:47:05 +03:00
if conf . LIB_MUST_BE_BUNDLED ( libname ) :
conf . env [ found ] = False
return False
# see if the library should only use a system version if another dependent
# system version is found. That prevents possible use of mixed library
# versions
if missing :
if not conf . LIB_MAY_BE_BUNDLED ( libname ) :
Logs . error ( ' ERROR: Use of system library %s depends on missing system library/libraries %r ' % ( libname , missing ) )
sys . exit ( 1 )
conf . env [ found ] = False
return False
2010-03-28 17:08:38 +04:00
2014-03-14 13:19:41 +04:00
def check_functions_headers_code ( ) :
2010-10-06 08:23:58 +04:00
''' helper function for CHECK_BUNDLED_SYSTEM '''
2010-10-16 02:41:34 +04:00
if require_headers and headers and not conf . CHECK_HEADERS ( headers , lib = libname ) :
2010-10-06 08:23:58 +04:00
return False
2014-03-14 13:18:18 +04:00
if checkfunctions is not None :
ok = conf . CHECK_FUNCS_IN ( checkfunctions , libname , headers = headers ,
empty_decl = False , set_target = False )
if not ok :
return False
2014-03-14 13:19:41 +04:00
if checkcode is not None :
define = ' CHECK_BUNDLED_SYSTEM_ %s ' % libname . upper ( )
ok = conf . CHECK_CODE ( checkcode , lib = libname ,
headers = headers , local_include = False ,
msg = msg , define = define )
conf . CONFIG_RESET ( define )
if not ok :
return False
2014-03-14 13:18:18 +04:00
return True
2010-04-12 03:49:56 +04:00
minversion = minimum_library_version ( conf , libname , minversion )
2011-01-25 04:15:49 +03:00
msg = ' Checking for system %s ' % libname
if minversion != ' 0.0.0 ' :
msg + = ' >= %s ' % minversion
2014-03-14 12:52:51 +04:00
uselib_store = libname . upper ( )
if pkg is None :
pkg = libname
2010-03-28 10:05:30 +04:00
# try pkgconfig first
2015-06-19 00:46:04 +03:00
if ( conf . CHECK_CFG ( package = pkg ,
2014-03-14 12:52:51 +04:00
args = ' " %s >= %s " --cflags --libs ' % ( pkg , minversion ) ,
msg = msg , uselib_store = uselib_store ) and
2014-03-14 13:19:41 +04:00
check_functions_headers_code ( ) ) :
2014-01-20 15:37:44 +04:00
if set_target :
conf . SET_TARGET_TYPE ( libname , ' SYSLIB ' )
2010-03-28 10:05:30 +04:00
conf . env [ found ] = True
2010-03-29 15:27:17 +04:00
if implied_deps :
conf . SET_SYSLIB_DEPS ( libname , implied_deps )
2010-03-28 09:38:27 +04:00
return True
2010-03-28 10:05:30 +04:00
if checkfunctions is not None :
2014-03-14 13:19:41 +04:00
if check_functions_headers_code ( ) :
2010-03-28 10:05:30 +04:00
conf . env [ found ] = True
2010-03-29 15:27:17 +04:00
if implied_deps :
conf . SET_SYSLIB_DEPS ( libname , implied_deps )
2014-01-20 15:37:44 +04:00
if set_target :
conf . SET_TARGET_TYPE ( libname , ' SYSLIB ' )
2010-03-28 10:05:30 +04:00
return True
conf . env [ found ] = False
2010-06-19 16:02:18 +04:00
if not conf . LIB_MAY_BE_BUNDLED ( libname ) :
2010-04-09 15:12:02 +04:00
Logs . error ( ' ERROR: System library %s of version %s not found, and bundling disabled ' % ( libname , minversion ) )
2010-03-28 09:38:27 +04:00
sys . exit ( 1 )
return False
2010-04-12 03:49:56 +04:00
2010-10-04 15:38:25 +04:00
2012-04-10 02:45:20 +04:00
def tuplize_version ( version ) :
2012-04-09 22:05:06 +04:00
return tuple ( [ int ( x ) for x in version . split ( " . " ) ] )
2010-10-04 15:38:25 +04:00
@conf
def CHECK_BUNDLED_SYSTEM_PYTHON ( conf , libname , modulename , minversion = ' 0.0.0 ' ) :
''' check if a python module is available on the system and
has the specified minimum version .
'''
if conf . LIB_MUST_BE_BUNDLED ( libname ) :
return False
# see if the library should only use a system version if another dependent
# system version is found. That prevents possible use of mixed library
# versions
minversion = minimum_library_version ( conf , libname , minversion )
try :
m = __import__ ( modulename )
except ImportError :
found = False
else :
try :
version = m . __version__
except AttributeError :
found = False
else :
2012-04-09 22:05:06 +04:00
found = tuplize_version ( version ) > = tuplize_version ( minversion )
2010-10-04 15:38:25 +04:00
if not found and not conf . LIB_MAY_BE_BUNDLED ( libname ) :
Logs . error ( ' ERROR: Python module %s of version %s not found, and bundling disabled ' % ( libname , minversion ) )
sys . exit ( 1 )
return found
2010-04-21 11:13:16 +04:00
def NONSHARED_BINARY ( bld , name ) :
''' return True if a binary should be built without non-system shared libs '''
return target_in_list ( name , bld . env . NONSHARED_BINARIES , False )
Build . BuildContext . NONSHARED_BINARY = NONSHARED_BINARY