build: waf update to fix macos build error
[Samba/gebeck_regimport.git] / buildtools / wafsamba / samba_bundled.py
blob34199381b396390814a513d2762955ce365e091a
1 # functions to support bundled libraries
3 from Configure import conf
4 from samba_utils import *
6 def BUNDLED_NAME(bld, name, bundled_extension):
7 '''possibly rename a library to include a bundled extension'''
8 if bld.env.DISABLE_SHARED or not bundled_extension:
9 return name
10 if name in bld.env.BUNDLED_EXTENSION_EXCEPTION:
11 return name
12 extension = getattr(bld.env, 'BUNDLED_EXTENSION', '')
13 if extension:
14 return name + '-' + extension
15 return name
18 def BUILTIN_LIBRARY(bld, name):
19 '''return True if a library should be builtin
20 instead of being built as a shared lib'''
21 if bld.env.DISABLE_SHARED:
22 return True
23 if name in bld.env.BUILTIN_LIBRARIES:
24 return True
25 return False
28 def BUILTIN_DEFAULT(opt, builtins):
29 '''set a comma separated default list of builtin libraries for this package'''
30 if 'BUILTIN_LIBRARIES_DEFAULT' in Options.options:
31 return
32 Options.options['BUILTIN_LIBRARIES_DEFAULT'] = builtins
33 Options.Handler.BUILTIN_DEFAULT = BUILTIN_DEFAULT
36 def BUNDLED_EXTENSION_DEFAULT(opt, extension, noextenion=''):
37 '''set a default bundled library extension'''
38 if 'BUNDLED_EXTENSION_DEFAULT' in Options.options:
39 return
40 Options.options['BUNDLED_EXTENSION_DEFAULT'] = extension
41 Options.options['BUNDLED_EXTENSION_EXCEPTION'] = noextenion
42 Options.Handler.BUNDLED_EXTENSION_DEFAULT = BUNDLED_EXTENSION_DEFAULT
46 @runonce
47 @conf
48 def CHECK_BUNDLED_SYSTEM(conf, libname, minversion='0.0.0',
49 checkfunctions=None, headers=None,
50 onlyif=None, implied_deps=None,
51 require_headers=True):
52 '''check if a library is available as a system library.
53 this first tries via pkg-config, then if that fails
54 tries by testing for a specified function in the specified lib
55 '''
56 if 'ALL' in conf.env.BUNDLED_LIBS or libname in conf.env.BUNDLED_LIBS:
57 return False
58 found = 'FOUND_SYSTEMLIB_%s' % libname
59 if found in conf.env:
60 return conf.env[found]
62 # see if the library should only use a system version if another dependent
63 # system version is found. That prevents possible use of mixed library
64 # versions
65 if onlyif:
66 for syslib in TO_LIST(onlyif):
67 f = 'FOUND_SYSTEM_%s' % syslib
68 if not f in conf.env:
69 if 'NONE' in conf.env.BUNDLED_LIBS or '!'+libname in conf.env.BUNDLED_LIBS:
70 print('ERROR: Use of system library %s depends on missing system library %s' % (libname, syslib))
71 sys.exit(1)
72 conf.env[found] = False
73 return False
75 # try pkgconfig first
76 if conf.check_cfg(package=libname,
77 args='"%s >= %s" --cflags --libs' % (libname, minversion),
78 msg='Checking for system %s >= %s' % (libname, minversion)):
79 conf.SET_TARGET_TYPE(libname, 'SYSLIB')
80 conf.env[found] = True
81 if implied_deps:
82 conf.SET_SYSLIB_DEPS(libname, implied_deps)
83 return True
84 if checkfunctions is not None:
85 headers_ok = True
86 if require_headers and headers and not conf.CHECK_HEADERS(headers):
87 headers_ok = False
88 if headers_ok and conf.CHECK_FUNCS_IN(checkfunctions, libname, headers=headers, empty_decl=False):
89 conf.env[found] = True
90 if implied_deps:
91 conf.SET_SYSLIB_DEPS(libname, implied_deps)
92 return True
93 conf.env[found] = False
94 if 'NONE' in conf.env.BUNDLED_LIBS or '!'+libname in conf.env.BUNDLED_LIBS:
95 print('ERROR: System library %s of version %s not found, and bundling disabled' % (libname, minversion))
96 sys.exit(1)
97 return False