diff --git a/aksetup_helper.py b/aksetup_helper.py index d02c9e36667ab5934bc94393b548521c13f0611c..a52976dc03d310ab43e2cde42dc2a0b371ddae9c 100644 --- a/aksetup_helper.py +++ b/aksetup_helper.py @@ -181,6 +181,39 @@ def default_or(a, b): +def expand_str(s, options): + import re + + def my_repl(match): + sym = match.group(1) + try: + repl = options[sym] + except KeyError: + from os import environ + repl = environ[sym] + + return expand_str(repl, options) + + return re.subn(r"\$\{([a-zA-Z0-9_]+)\}", my_repl, s)[0] + +def expand_value(v, options): + if isinstance(v, (str, unicode)): + return expand_str(v, options) + elif isinstance(v, list): + return [expand_value(i, options) for i in v] + else: + return v + + +def expand_options(options): + for k in options.keys(): + options[k] = expand_value(options[k], options) + return options + + + + + class ConfigSchema: def __init__(self, options, conf_file="siteconf.py", conf_dir="."): @@ -299,6 +332,8 @@ class ConfigSchema: raise KeyError, "invalid config key in %s: %s" % ( cfile, key) + expand_options(result) + return result def add_to_configparser(self, parser, def_config=None): @@ -313,6 +348,7 @@ class ConfigSchema: result = {} for opt in self.options: result[opt.name] = opt.take_from_configparser(options) + expand_options(result) return result def write_config(self, config): @@ -430,6 +466,21 @@ class Libraries(StringListOption): help=help or ("Library names for %s (without lib or .so)" % (human_name or humanize(lib_name)))) +class BoostLibraries(Libraries): + def __init__(self, lib_base_name): + Libraries.__init__(self, "BOOST_%s" % lib_base_name.upper(), + ["boost_%s-${BOOST_COMPILER}-mt" % lib_base_name], + help="Library names for Boost C++ %s library (without lib or .so)" + % humanize(lib_base_name)) + +def make_boost_base_options(): + return [ + IncludeDir("BOOST", []), + LibraryDir("BOOST", []), + Option("BOOST_COMPILER", default="gcc43", + help="The compiler with which Boost C++ was compiled, e.g. gcc43"), + ] + @@ -520,7 +571,7 @@ def substitute(substitutions, fname): l = l[:match.start()] + subst + l[match.end():] made_change = True new_lines.append(l) - new_lines.insert(1, "# DO NOT EDIT THIS FILE -- it is generated by configure\n") + new_lines.insert(1, "# DO NOT EDIT THIS FILE -- it was generated by configure.py\n") import sys new_lines.insert(2, "# %s\n" % (" ".join(sys.argv))) open(fname, "w").write("".join(new_lines)) diff --git a/setup.py b/setup.py index a707197cfc95cdd45e474e0f0a6656eb45221e4d..6fcddce88f7b997c257f6c1eb1fb61f5651fe56e 100644 --- a/setup.py +++ b/setup.py @@ -2,13 +2,11 @@ def get_config_schema(): from aksetup_helper import ConfigSchema, Option, \ - IncludeDir, LibraryDir, Libraries, \ - Switch, StringListOption + IncludeDir, LibraryDir, Libraries, BoostLibraries, \ + Switch, StringListOption, make_boost_base_options - return ConfigSchema([ - IncludeDir("BOOST", []), - LibraryDir("BOOST", []), - Libraries("BOOST_PYTHON", ["boost_python-gcc42-mt"]), + return ConfigSchema(make_boost_base_options() + [ + BoostLibraries("python"), StringListOption("CXXFLAGS", [], help="Any extra C++ compiler options to include"),