s4-waf: cleanup use of LIBPOPT vs popt dependency
[samba.git] / buildtools / wafsamba / samba_bundled.py
1 # functions to support bundled libraries
2
3 from Configure import conf
4 from samba_utils import *
5
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
16
17
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
26
27
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
34
35
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
43
44
45 @runonce
46 @conf
47 def CHECK_BUNDLED_SYSTEM(conf, libname, minversion='0.0.0',
48                          checkfunctions=None, headers=None):
49     if 'ALL' in conf.env.BUNDLED_LIBS or libname in conf.env.BUNDLED_LIBS:
50         return False
51     found = 'FOUND_SYSTEMLIB_%s' % libname
52     if found in conf.env:
53         return conf.env[found]
54     # try pkgconfig first
55     if conf.check_cfg(package=libname,
56                       args='"%s >= %s" --cflags --libs' % (libname, minversion),
57                       msg='Checking for system %s >= %s' % (libname, minversion)):
58         conf.SET_TARGET_TYPE(libname, 'SYSLIB')
59         conf.env[found] = True
60         return True
61     if checkfunctions is not None:
62         if conf.CHECK_FUNCS_IN(checkfunctions, libname, headers=headers):
63             conf.env[found] = True
64             return True
65     conf.env[found] = False
66     if 'NONE' in conf.env.BUNDLED_LIBS or '!'+libname in conf.env.BUNDLED_LIBS:
67         print('ERROR: System library %s of version %s not found, and bundling disabled' % (libname, minversion))
68         sys.exit(1)
69     return False