diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/configure.cc | 97 | ||||
-rw-r--r-- | src/externals.h | 6 | ||||
-rw-r--r-- | src/externals_manual.cc | 33 | ||||
-rw-r--r-- | src/externals_manual.h | 13 | ||||
-rw-r--r-- | src/libctor.h | 10 |
5 files changed, 137 insertions, 22 deletions
diff --git a/src/configure.cc b/src/configure.cc index 4df6026..02e8224 100644 --- a/src/configure.cc +++ b/src/configure.cc @@ -15,10 +15,14 @@ #include "libctor.h" #include "tasks.h" #include "rebuild.h" +#include "externals.h" std::filesystem::path configurationFile("configuration.cc"); std::filesystem::path configHeaderFile("config.h"); +std::map<std::string, std::string> external_includedir; +std::map<std::string, std::string> external_libdir; + const Configuration default_configuration{}; const Configuration& __attribute__((weak)) configuration() { @@ -143,6 +147,9 @@ public: } }; +// helper constant for the visitor +template<class> inline constexpr bool always_false_v = false; + int regenerateCache(const Settings& default_settings, const std::vector<std::string>& args, const std::map<std::string, std::string>& env) @@ -249,6 +256,51 @@ int regenerateCache(const Settings& default_settings, return 0; }); + // 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()); + } + + auto add_path_args = + [&](const std::string& name) + { + opt.add(name + "-includedir", required_argument, key++, + "Set path to " + name + " header file.", + [&]() { + external_includedir[name] = optarg; + return 0; + }); + + opt.add(name + "-libdir", required_argument, key++, + "Set path to " + name + " libraries.", + [&]() { + external_libdir[name] = optarg; + return 0; + }); + }; + + for(const auto& ext : externalConfigs) + { + std::visit([&](auto&& arg) + { + using T = std::decay_t<decltype(arg)>; + if constexpr (std::is_same_v<T, ExternalManual>) + { + add_path_args(ext.name); + } + else + { + static_assert(always_false_v<T>, "non-exhaustive visitor!"); + } + }, ext.external); + + } + opt.add("help", no_argument, 'h', "Print this help text.", [&]() { @@ -325,16 +377,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); - // 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()); - } - std::cout << "Writing results to: " << configurationFile.string() << "\n"; { std::ofstream istr(configurationFile); @@ -380,44 +422,59 @@ int regenerateCache(const Settings& default_settings, istr << " },\n"; istr << " .externals = {\n"; - for(const auto& externalConfig : externalConfigs) + for(const auto& ext : externalConfigs) { - istr << " { \"" << externalConfig.name << "\", {\n"; + istr << " { \"" << ext.name << "\", {\n"; + Flags resolved_flags; + if(std::holds_alternative<ExternalManual>(ext.external)) + { + if(auto ret = resolv(settings, ext.name, + std::get<ExternalManual>(ext.external), + resolved_flags)) + { + return ret; + } + } + else + { + std::cout << "Unknown external type\n"; + return 1; + } - if(!externalConfig.flags.cxxflags.empty()) + if(!resolved_flags.cxxflags.empty()) { istr << " .cxxflags = {"; - for(const auto& flag : externalConfig.flags.cxxflags) + for(const auto& flag : resolved_flags.cxxflags) { istr << "\"" << flag << "\","; } istr << "},\n"; } - if(!externalConfig.flags.cflags.empty()) + if(!resolved_flags.cflags.empty()) { istr << " .cflags = {"; - for(const auto& flag : externalConfig.flags.cflags) + for(const auto& flag : resolved_flags.cflags) { istr << "\"" << flag << "\","; } istr << "},\n"; } - if(!externalConfig.flags.ldflags.empty()) + if(!resolved_flags.ldflags.empty()) { istr << " .ldflags = {"; - for(const auto& flag : externalConfig.flags.ldflags) + for(const auto& flag : resolved_flags.ldflags) { istr << "\"" << flag << "\","; } istr << "},\n"; } - if(!externalConfig.flags.asmflags.empty()) + if(!resolved_flags.asmflags.empty()) { istr << " .asmflags = {"; - for(const auto& flag : externalConfig.flags.asmflags) + for(const auto& flag : resolved_flags.asmflags) { istr << "\"" << flag << "\","; } diff --git a/src/externals.h b/src/externals.h new file mode 100644 index 0000000..7b4aa23 --- /dev/null +++ b/src/externals.h @@ -0,0 +1,6 @@ +// -*- c++ -*- +// Distributed under the BSD 2-Clause License. +// See accompanying file LICENSE for details. +#pragma once + +#include "externals_manual.h" diff --git a/src/externals_manual.cc b/src/externals_manual.cc new file mode 100644 index 0000000..afea257 --- /dev/null +++ b/src/externals_manual.cc @@ -0,0 +1,33 @@ +// -*- c++ -*- +// Distributed under the BSD 2-Clause License. +// See accompanying file LICENSE for details. +#include "externals_manual.h" + +#include <map> + +#include "libctor.h" +#include "settings.h" + +extern std::map<std::string, std::string> external_includedir; +extern std::map<std::string, std::string> external_libdir; + +int resolv(const Settings& settings, const std::string& name, + const ExternalManual& ext, Flags& flags) +{ + flags = ext.flags; + + auto inc = external_includedir.find(name); + if(inc != external_includedir.end()) + { + flags.cflags.push_back("-I" + inc->second); + flags.cxxflags.push_back("-I" + inc->second); + } + + auto lib = external_libdir.find(name); + if(lib != external_libdir.end()) + { + flags.ldflags.push_back("-L" + lib->second); + } + + return 0; +} diff --git a/src/externals_manual.h b/src/externals_manual.h new file mode 100644 index 0000000..c7e3b9a --- /dev/null +++ b/src/externals_manual.h @@ -0,0 +1,13 @@ +// -*- c++ -*- +// Distributed under the BSD 2-Clause License. +// See accompanying file LICENSE for details. +#pragma once + +#include <string> + +struct Settings; +struct ExternalManual; +struct Flags; + +int resolv(const Settings& settings, const std::string& name, + const ExternalManual& ext, Flags& flags); diff --git a/src/libctor.h b/src/libctor.h index 0af33cb..721ac6a 100644 --- a/src/libctor.h +++ b/src/libctor.h @@ -7,6 +7,7 @@ #include <string> #include <vector> #include <map> +#include <variant> enum class TargetType { @@ -70,12 +71,17 @@ using BuildConfigurations = std::vector<BuildConfiguration>; int reg(BuildConfigurations (*cb)(), const std::source_location location = std::source_location::current()); +// This type will use flags verbatim +struct ExternalManual +{ + Flags flags; +}; + struct ExternalConfiguration { std::string name; // Name for configuration - Flags flags; - std::vector<std::string> libs; // libraries + std::variant<ExternalManual> external; }; using ExternalConfigurations = std::vector<ExternalConfiguration>; |