diff options
Diffstat (limited to 'src/configure.cc')
-rw-r--r-- | src/configure.cc | 90 |
1 files changed, 48 insertions, 42 deletions
diff --git a/src/configure.cc b/src/configure.cc index 11caa92..910b878 100644 --- a/src/configure.cc +++ b/src/configure.cc @@ -32,11 +32,7 @@ const ctor::configuration& __attribute__((weak)) ctor::get_configuration() if(!initialised) { std::string cxx_prog{"c++"}; - auto cxx_env = std::getenv("CXX"); - if(cxx_env) - { - cxx_prog = cxx_env; - } + get_env("CXX", cxx_prog); cfg.build_toolchain = getToolChain(cfg.get(ctor::cfg::build_cxx, cxx_prog)); @@ -100,11 +96,32 @@ std::string ctor::configuration::get(const std::string& key, return ctor::conf_values[key]; } - if(has(key)) + if(tools.find(key) != tools.end()) { return tools.at(key); } + std::string value; + if(key == ctor::cfg::build_cxx && get_env("CXX", value)) + { + return value; + } + + if(key == ctor::cfg::build_cc && get_env("CC", value)) + { + return value; + } + + if(key == ctor::cfg::build_ld && get_env("LD", value)) + { + return value; + } + + if(key == ctor::cfg::build_ar && get_env("AR", value)) + { + return value; + } + return default_value; } @@ -116,10 +133,9 @@ std::string ctor::configuration::getenv(const std::string& key) const return envit->second; } - auto sysenv = std::getenv(key.data()); - if(sysenv) + if(std::string value; get_env(key.data(), value)) { - return sysenv; + return value; } return {}; @@ -132,20 +148,16 @@ public: Args(const std::vector<std::string>& args) { resize(args.size() + 1); - (*this)[0] = strdup("./ctor"); + owning_container.push_back("./ctor"); + (*this)[0] = owning_container.back().data(); for(std::size_t i = 0; i < size() - 1; ++i) { - (*this)[i + 1] = strdup(args[i].data()); + owning_container.push_back(args[i]); + (*this)[i + 1] = owning_container.back().data(); } } - ~Args() - { - for(std::size_t i = 0; i < size(); ++i) - { - free((*this)[i]); - } - } + std::deque<std::string> owning_container; }; namespace { @@ -730,6 +742,7 @@ int regenerateCache(ctor::settings& settings, { ctor::conf_values[ctor::cfg::builddir] = builddir; } + ctor::conf_values[ctor::cfg::host_cxx] = host_cxx; ctor::conf_values[ctor::cfg::build_cxx] = build_cxx; @@ -912,52 +925,45 @@ int configure(const ctor::settings& global_settings, int argc, char* argv[]) } std::map<std::string, std::string> env; - auto cc_env = getenv("CC"); - if(cc_env) + std::string value; + if(get_env("CC", value)) { - env["CC"] = cc_env; + env["CC"] = value; } - auto cflags_env = getenv("CFLAGS"); - if(cflags_env) + if(get_env("CFLAGS", value)) { - env["CFLAGS"] = cflags_env; + env["CFLAGS"] = value; } - auto cxx_env = getenv("CXX"); - if(cxx_env) + if(get_env("CXX", value)) { - env["CXX"] = cxx_env; + env["CXX"] = value; } - auto cxxflags_env = getenv("CXXFLAGS"); - if(cxxflags_env) + if(get_env("CXXFLAGS", value)) { - env["CXXFLAGS"] = cxxflags_env; + env["CXXFLAGS"] = value; } - auto ar_env = getenv("AR"); - if(ar_env) + if(get_env("AR", value)) { - env["AR"] = ar_env; + env["AR"] = value; } - auto ld_env = getenv("LD"); - if(ld_env) + if(get_env("LD", value)) { - env["LD"] = ld_env; + env["LD"] = value; } - auto ldflags_env = getenv("LDFLAGS"); - if(ldflags_env) + if(get_env("LDFLAGS", value)) { - env["LDFLAGS"] = ldflags_env; + env["LDFLAGS"] = value; } - auto path_env = getenv("PATH"); - if(path_env) + if(get_env("PATH", value)) { - env["PATH"] = path_env; + env["PATH"] = value; } auto ret = regenerateCache(settings, args_span[0], args, env); |