diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/configure.cc | 64 | ||||
-rw-r--r-- | src/libctor.h | 20 | ||||
-rw-r--r-- | src/rebuild.cc | 11 | ||||
-rw-r--r-- | src/task_ar.cc | 4 | ||||
-rw-r--r-- | src/task_cc.cc | 4 | ||||
-rw-r--r-- | src/task_ld.cc | 6 | ||||
-rw-r--r-- | src/task_so.cc | 4 | ||||
-rw-r--r-- | src/tasks.cc | 99 |
8 files changed, 70 insertions, 142 deletions
diff --git a/src/configure.cc b/src/configure.cc index 98f68d7..cc963f8 100644 --- a/src/configure.cc +++ b/src/configure.cc @@ -325,7 +325,6 @@ int regenerateCache(const Settings& default_settings, std::string build_ar = locate(build_arch, ar_prog); std::string build_ld = locate(build_arch, ld_prog); - // TODO: Centralize // Resolv externals ExternalConfigurations externalConfigs; for(std::size_t i = 0; i < numExternalConfigFiles; ++i) @@ -379,69 +378,52 @@ int regenerateCache(const Settings& default_settings, } istr << " },\n"; - istr << " .externals = {\n"; + istr << " .externals = {\n"; for(const auto& externalConfig : externalConfigs) { - if(!externalConfig.cflags.empty()) - { - istr << " { \"" << externalConfig.name << "-cflags\",\n"; - istr << " {\n"; - for(const auto& cflag : externalConfig.cflags) - { - istr << " \"" << cflag << "\",\n"; - } - istr << " },\n"; - istr << " },\n"; - } + istr << " { \"" << externalConfig.name << "\", {\n"; - if(!externalConfig.cxxflags.empty()) + if(!externalConfig.flags.cxxflags.empty()) { - istr << " { \"" << externalConfig.name << "-cxxflags\",\n"; - istr << " {\n"; - for(const auto& cxxflag : externalConfig.cxxflags) + istr << " .cxxflags = {"; + for(const auto& flag : externalConfig.flags.cxxflags) { - istr << " \"" << cxxflag << "\",\n"; + istr << "\"" << flag << "\","; } - istr << " },\n"; - istr << " },\n"; + istr << "},\n"; } - if(!externalConfig.ldflags.empty()) + if(!externalConfig.flags.cflags.empty()) { - istr << " { \"" << externalConfig.name << "-ldflags\",\n"; - istr << " {\n"; - for(const auto& ldflag : externalConfig.ldflags) + istr << " .cflags = {"; + for(const auto& flag : externalConfig.flags.cflags) { - istr << " \"" << ldflag << "\",\n"; + istr << "\"" << flag << "\","; } - istr << " },\n"; - istr << " },\n"; + istr << "},\n"; } - if(!externalConfig.libs.empty()) + if(!externalConfig.flags.ldflags.empty()) { - istr << " { \"" << externalConfig.name << "-libs\",\n"; - istr << " {\n"; - for(const auto& lib : externalConfig.libs) + istr << " .ldflags = {"; + for(const auto& flag : externalConfig.flags.ldflags) { - istr << " \"" << lib << "\",\n"; + istr << "\"" << flag << "\","; } - istr << " },\n"; - istr << " },\n"; + istr << "},\n"; } - if(!externalConfig.asmflags.empty()) + if(!externalConfig.flags.asmflags.empty()) { - istr << " { \"" << externalConfig.name << "-asmflags\",\n"; - istr << " {\n"; - for(const auto& asmflag : externalConfig.asmflags) + istr << " .asmflags = {"; + for(const auto& flag : externalConfig.flags.asmflags) { - istr << " \"" << asmflag << "\",\n"; + istr << "\"" << flag << "\","; } - istr << " },\n"; - istr << " },\n"; + istr << "},\n"; } + istr << " }},\n"; } istr << " },\n"; diff --git a/src/libctor.h b/src/libctor.h index a5fd249..0af33cb 100644 --- a/src/libctor.h +++ b/src/libctor.h @@ -45,6 +45,14 @@ struct Source Language language{Language::Auto}; }; +struct Flags +{ + std::vector<std::string> cxxflags; // flags for c++ compiler + std::vector<std::string> cflags; // flags for c compiler + std::vector<std::string> ldflags; // flags for linker + std::vector<std::string> asmflags; // flags for asm translator +}; + struct BuildConfiguration { std::string name; // Name - used for referring in other configurations. @@ -53,10 +61,7 @@ struct BuildConfiguration std::string target; // Output target file for this configuration std::vector<Source> sources; // source list std::vector<std::string> depends; // internal target dependencies - std::vector<std::string> cxxflags; // flags for c++ compiler - std::vector<std::string> cflags; // flags for c compiler - std::vector<std::string> ldflags; // flags for linker - std::vector<std::string> asmflags; // flags for asm translator + Flags flags; std::vector<std::string> externals; // externals used by this configuration }; @@ -69,10 +74,7 @@ int reg(BuildConfigurations (*cb)(), struct ExternalConfiguration { std::string name; // Name for configuration - std::vector<std::string> cxxflags; // flags for c++ compiler - std::vector<std::string> cflags; // flags for c compiler - std::vector<std::string> ldflags; // flags for linker - std::vector<std::string> asmflags; // flags for asm translator + Flags flags; std::vector<std::string> libs; // libraries }; @@ -112,7 +114,7 @@ struct Configuration std::map<std::string, std::string> env; // env used when last calling configure std::map<std::string, std::string> tools; // tools - std::map<std::string, std::vector<std::string>> externals; + std::map<std::string, Flags> externals; }; const Configuration& configuration(); diff --git a/src/rebuild.cc b/src/rebuild.cc index ff61695..50d7540 100644 --- a/src/rebuild.cc +++ b/src/rebuild.cc @@ -144,17 +144,18 @@ bool recompileCheck(const Settings& global_settings, int argc, char* argv[], BuildConfiguration config; config.name = "ctor"; - config.cxxflags = std::vector<std::string>({ "-s", "-O3", "-std=c++20" }); + config.flags.cxxflags = + std::vector<std::string>({ "-s", "-O3", "-std=c++20" }); if(hasConfiguration(cfg::ctor_includedir)) { - config.cxxflags.push_back("-I"s + getConfiguration(cfg::ctor_includedir)); + config.flags.cxxflags.push_back("-I"s + getConfiguration(cfg::ctor_includedir)); } if(hasConfiguration(cfg::ctor_libdir)) { - config.ldflags.push_back("-L"s + getConfiguration(cfg::ctor_libdir)); + config.flags.ldflags.push_back("-L"s + getConfiguration(cfg::ctor_libdir)); } - config.ldflags.push_back("-lctor"); - config.ldflags.push_back("-pthread"); + config.flags.ldflags.push_back("-lctor"); + config.flags.ldflags.push_back("-pthread"); Settings settings{global_settings}; diff --git a/src/task_ar.cc b/src/task_ar.cc index 0bcad0c..d4a4447 100644 --- a/src/task_ar.cc +++ b/src/task_ar.cc @@ -178,9 +178,9 @@ bool TaskAR::derived() const std::string TaskAR::flagsString() const { std::string flagsStr; - for(const auto& flag : config.ldflags) + for(const auto& flag : config.flags.ldflags) { - if(flag != config.ldflags[0]) + if(flag != config.flags.ldflags[0]) { flagsStr += " "; } diff --git a/src/task_cc.cc b/src/task_cc.cc index 61f5977..1db9767 100644 --- a/src/task_cc.cc +++ b/src/task_cc.cc @@ -246,9 +246,9 @@ std::vector<std::string> TaskCC::flags() const switch(sourceLanguage()) { case Language::C: - return config.cflags; + return config.flags.cflags; case Language::Cpp: - return config.cxxflags; + return config.flags.cxxflags; default: std::cerr << "Unknown CC target type\n"; exit(1); diff --git a/src/task_ld.cc b/src/task_ld.cc index 2a3c8c4..82c26a9 100644 --- a/src/task_ld.cc +++ b/src/task_ld.cc @@ -139,7 +139,7 @@ int TaskLD::runInner() } } - for(const auto& flag : config.ldflags) + for(const auto& flag : config.flags.ldflags) { args.push_back(flag); } @@ -206,9 +206,9 @@ bool TaskLD::derived() const std::string TaskLD::flagsString() const { std::string flagsStr; - for(const auto& flag : config.ldflags) + for(const auto& flag : config.flags.ldflags) { - if(flag != config.ldflags[0]) + if(flag != config.flags.ldflags[0]) { flagsStr += " "; } diff --git a/src/task_so.cc b/src/task_so.cc index 5aa5723..bf47e05 100644 --- a/src/task_so.cc +++ b/src/task_so.cc @@ -118,7 +118,7 @@ int TaskSO::runInner() args.push_back(depFile.string()); } - for(const auto& flag : config.ldflags) + for(const auto& flag : config.flags.ldflags) { args.push_back(flag); } @@ -183,7 +183,7 @@ bool TaskSO::derived() const std::string TaskSO::flagsString() const { std::string flagsStr = compiler(); - for(const auto& flag : config.ldflags) + for(const auto& flag : config.flags.ldflags) { flagsStr += " " + flag; } diff --git a/src/tasks.cc b/src/tasks.cc index 8a85fc8..3bfff8b 100644 --- a/src/tasks.cc +++ b/src/tasks.cc @@ -24,18 +24,7 @@ const std::deque<Target>& getTargets(const Settings& settings) static std::deque<Target> targets; if(!initialised) { - // TODO: Centralize - // Resolv externals - ExternalConfigurations externalConfigs; - for(std::size_t i = 0; i < numExternalConfigFiles; ++i) - { - auto newExternalConfigs = externalConfigFiles[i].cb(); - externalConfigs.insert(externalConfigs.end(), - newExternalConfigs.begin(), - newExternalConfigs.end()); - } - - const auto& extMap = configuration().externals; + const auto& externals = configuration().externals; for(std::size_t i = 0; i < numConfigFiles; ++i) { std::string path = @@ -47,77 +36,31 @@ const std::deque<Target>& getTargets(const Settings& settings) auto configs = configFiles[i].cb(); for(auto& config : configs) { - // Resolv config externals for(const auto& external : config.externals) { - bool found{false}; - for(const auto& externalConfig : externalConfigs) - { - if(externalConfig.name == external) - { - found = true; - try - { - auto cflags = extMap.at(external+"-cflags"); - config.cflags.insert(config.cflags.end(), - cflags.begin(), - cflags.end()); - } - catch(...) - { - } - - try - { - auto cxxflags = extMap.at(external+"-cxxflags"); - config.cxxflags.insert(config.cxxflags.end(), - cxxflags.begin(), - cxxflags.end()); - } - catch(...) - { - } - - try - { - auto ldflags = extMap.at(external+"-ldflags"); - config.ldflags.insert(config.ldflags.end(), - ldflags.begin(), - ldflags.end()); - } - catch(...) - { - } - - try - { - auto asmflags = extMap.at(external+"-asmflags"); - config.asmflags.insert(config.asmflags.end(), - asmflags.begin(), - asmflags.end()); - } - catch(...) - { - } - - try - { - auto libs = extMap.at(external+"-libs"); - //config.libs.insert(config.libs.end(), - // libs.begin(), - // libs.end()); - } - catch(...) - { - } - } - } - if(!found) + if(externals.find(external) == externals.end()) { - std::cout << "External '" << external << "' not found.\n"; - exit(1); + std::cout << "External '" << external << + "' not found cache - run configure.\n"; + continue; } + const auto& flags = externals.at(external); + config.flags.cflags.insert(config.flags.cflags.end(), + flags.cflags.begin(), + flags.cflags.end()); + config.flags.cxxflags.insert(config.flags.cxxflags.end(), + flags.cxxflags.begin(), + flags.cxxflags.end()); + config.flags.ldflags.insert(config.flags.ldflags.end(), + flags.ldflags.begin(), + flags.ldflags.end()); + config.flags.asmflags.insert(config.flags.asmflags.end(), + flags.asmflags.begin(), + flags.asmflags.end()); + //config.libs.insert(config.libs.end(), + // libs.begin(), + // libs.end()); } targets.push_back({config, path}); |