diff options
Diffstat (limited to 'src/bootstrap.cc')
-rw-r--r-- | src/bootstrap.cc | 102 |
1 files changed, 86 insertions, 16 deletions
diff --git a/src/bootstrap.cc b/src/bootstrap.cc index 6e4ef19..836504e 100644 --- a/src/bootstrap.cc +++ b/src/bootstrap.cc @@ -3,10 +3,12 @@ // See accompanying file LICENSE for details. #include <iostream> #include <array> +#include <cstdlib> +#include <span> #define BOOTSTRAP -#include "libctor.h" +#include "ctor.h" #include "util.cc" #include "rebuild.cc" @@ -16,39 +18,107 @@ #include "execute.cc" #include "tasks.cc" #include "build.cc" +#include "tools.cc" +#include "pointerlist.cc" -std::filesystem::path configurationFile("configuration.cc"); -std::filesystem::path configHeaderFile("config.h"); +const std::filesystem::path configurationFile("configuration.cc"); +const std::filesystem::path configHeaderFile("config.h"); -const Configuration default_configuration{}; -const Configuration& configuration() +const ctor::configuration& ctor::get_configuration() { - return default_configuration; + static ctor::configuration cfg; + static bool initialised{false}; + if(!initialised) + { + cfg.build_toolchain = getToolChain(cfg.get(ctor::cfg::build_cxx, "/usr/bin/g++")); + initialised = true; + } + + return cfg; } -bool hasConfiguration(const std::string& key) +bool ctor::configuration::has(const std::string& key) const { return false; } -const std::string& getConfiguration(const std::string& key, - const std::string& defaultValue) +std::string ctor::configuration::get(const std::string& key, const std::string& default_value) const +{ + static auto paths = get_paths(); + auto cxx_env = std::getenv("CXX"); + if(key == ctor::cfg::build_cxx && cxx_env) + { + static auto cxx_prog = locate(cxx_env, paths); + return cxx_prog; + } + + auto cc_env = std::getenv("CC"); + if(key == ctor::cfg::build_cc && cc_env) + { + static auto cc_prog = locate(cc_env, paths); + return cc_prog; + } + + auto ld_env = std::getenv("LD"); + if(key == ctor::cfg::build_ld && ld_env) + { + static auto ld_prog = locate(ld_env, paths); + return ld_prog; + } + + auto ar_env = std::getenv("AR"); + if(key == ctor::cfg::build_ar && ar_env) + { + static auto ar_prog = locate(ar_env, paths); + return ar_prog; + } + + auto builddir_env = std::getenv("BUILDDIR"); + if(key == ctor::cfg::builddir && builddir_env) + { + return builddir_env; + } + + return default_value; +} + +std::string ctor::configuration::getenv(const std::string& key) const +{ + auto envit = env.find(key); + if(envit != env.end()) + { + return envit->second; + } + + auto env = std::getenv(key.data()); + if(env) + { + return env; + } + + return {}; +} + +std::vector<std::string> readDeps(const std::string& depFile, + ctor::toolchain toolchain) { - return defaultValue; + return {}; } int main(int argc, char* argv[]) { - if(argc > 1) + auto args = std::span(argv, static_cast<std::size_t>(argc)); + if(args.size() > 1) { - std::cerr << "This is a minimal bootstrap version of " << argv[0] << + std::cerr << "This is a minimal bootstrap version of " << args[0] << " which doesn't support any arguments\n"; return 1; } - Settings settings{}; + ctor::settings settings{}; - settings.builddir = getConfiguration(cfg::builddir, "build"); + const auto& c = ctor::get_configuration(); + settings.builddir = c.get(ctor::cfg::builddir, settings.builddir); settings.parallel_processes = std::max(1u, std::thread::hardware_concurrency() * 2 - 1); settings.verbose = 0; @@ -65,8 +135,8 @@ int main(int argc, char* argv[]) auto& targets = getTargets(settings); for(const auto& target : targets) { - if(target.config.type != TargetType::UnitTest && - target.config.type != TargetType::UnitTestLib) + if(target.config.type != ctor::target_type::unit_test && + target.config.type != ctor::target_type::unit_test_library) { non_unittest_targets.push_back(target); } |