3 # WARNING! Do not edit! https://waf.io/book/index.html#_obtaining_the_waf_file
6 # -*- coding: utf-8 -*-
7 # Tool to extend c_config.check_cfg()
9 __author__ = __maintainer__ = "Jérôme Carretero <cJ-waf@zougloub.eu>"
10 __copyright__ = "Jérôme Carretero, 2014"
14 This tool allows to work around the absence of ``*-config`` programs
15 on systems, by keeping the same clean configuration syntax but inferring
16 values or permitting their modification via the options interface.
18 Note that pkg-config can also support setting ``PKG_CONFIG_PATH``,
19 so you can put custom files in a folder containing new .pc files.
20 This tool could also be implemented by taking advantage of this fact.
25 opt.load('c_config_alt')
26 opt.add_package_option('package')
29 conf.load('c_config_alt')
34 - Behavior with different build contexts...
40 from waflib import Configure, Options, Errors
43 return x.lower().replace('-', '_')
48 dest = name_to_dest(param)
49 gr = opt.get_option_group("configure options")
50 gr.add_option('--%s-root' % dest,
51 help="path containing include and lib subfolders for %s" \
55 opt.add_package_option = functools.partial(x, opt)
58 check_cfg_old = getattr(Configure.ConfigurationContext, 'check_cfg')
61 def check_cfg(conf, *k, **kw):
64 kw['package'] = lst[0]
65 kw['args'] = ' '.join(lst[1:])
67 if not 'package' in kw:
68 return check_cfg_old(conf, **kw)
70 package = kw['package']
72 package_lo = name_to_dest(package)
73 package_hi = package.upper().replace('-', '_') # TODO FIXME
74 package_hi = kw.get('uselib_store', package_hi)
76 def check_folder(path, name):
78 assert os.path.isdir(path)
79 except AssertionError:
80 raise Errors.ConfigurationError(
81 "%s_%s (%s) is not a folder!" \
82 % (package_lo, name, path))
85 root = getattr(Options.options, '%s_root' % package_lo, None)
88 return check_cfg_old(conf, **kw)
90 def add_manual_var(k, v):
91 conf.start_msg('Adding for %s a manual var' % (package))
92 conf.env["%s_%s" % (k, package_hi)] = v
93 conf.end_msg("%s = %s" % (k, v))
96 check_folder(root, 'root')
98 pkg_inc = check_folder(os.path.join(root, "include"), 'inc')
99 add_manual_var('INCLUDES', [pkg_inc])
100 pkg_lib = check_folder(os.path.join(root, "lib"), 'libpath')
101 add_manual_var('LIBPATH', [pkg_lib])
102 add_manual_var('LIB', [package])
104 for x in kw.get('manual_deps', []):
105 for k, v in sorted(conf.env.get_merged_dict().items()):
106 if k.endswith('_%s' % x):
107 k = k.replace('_%s' % x, '')
108 conf.start_msg('Adding for %s a manual dep' \
110 conf.env["%s_%s" % (k, package_hi)] += v
111 conf.end_msg('%s += %s' % (k, v))