From bc474f716407dec521626e76b6101df4a2f1a40a Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 30 Oct 2021 18:02:10 +0200 Subject: Add external configs. --- src/libctor.cc | 5 +++++ src/libctor.h | 16 +++++++++++++++- src/rebuild.cc | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/rebuild.h | 9 +++++++++ src/task_ar.cc | 4 ---- src/tasks.cc | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 6 files changed, 129 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/libctor.cc b/src/libctor.cc index ca60de2..0ec6c6c 100644 --- a/src/libctor.cc +++ b/src/libctor.cc @@ -185,6 +185,11 @@ Options: files.insert(configFiles[i].file); } + for(std::size_t i = 0; i < numExternalConfigFiles; ++i) + { + files.insert(externalConfigFiles[i].file); + } + for(const auto& file : files) { std::cout << file << "\n"; diff --git a/src/libctor.h b/src/libctor.h index 5c22614..2a10c53 100644 --- a/src/libctor.h +++ b/src/libctor.h @@ -51,17 +51,31 @@ struct BuildConfiguration OutputSystem system{OutputSystem::Host}; std::string target; // Output target file for this configuration std::vector sources; // source list - std::vector depends; // internal dependencies + std::vector depends; // internal target dependencies std::vector cxxflags; // flags for c++ compiler std::vector cflags; // flags for c compiler std::vector ldflags; // flags for linker std::vector asmflags; // flags for asm translator + std::vector externals; // externals used by this configuration }; using BuildConfigurations = std::vector; int reg(const char* location, BuildConfigurations (*cb)()); +struct ExternalConfiguration +{ + std::string name; // Name for configuration + std::vector cxxflags; // flags for c++ compiler + std::vector cflags; // flags for c compiler + std::vector ldflags; // flags for linker + std::vector asmflags; // flags for asm translator +}; + +using ExternalConfigurations = std::vector; + +int reg(const char* location, ExternalConfigurations (*cb)()); + // Convenience macro - ugly but keeps things simple(r) #define CONCAT(a, b) CONCAT_INNER(a, b) #define CONCAT_INNER(a, b) a ## b diff --git a/src/rebuild.cc b/src/rebuild.cc index c1f2a4a..3492955 100644 --- a/src/rebuild.cc +++ b/src/rebuild.cc @@ -55,9 +55,48 @@ int unreg(const char* location) } } + for(std::size_t i = 0; i < numExternalConfigFiles;) + { + if(std::string(location) == externalConfigFiles[i].file) + { + ++found; + for(std::size_t j = i; j < numExternalConfigFiles; ++j) + { + externalConfigFiles[j] = externalConfigFiles[j + 1]; + } + --numExternalConfigFiles; + } + else + { + ++i; + } + } + return found; } +std::array externalConfigFiles; +std::size_t numExternalConfigFiles{0}; + +// TODO: Use c++20 when ready, somehing like this: +//int reg(const std::source_location location = std::source_location::current()) +int reg(const char* location, std::vector (*cb)()) +{ + // NOTE: std::cout cannot be used here + if(numExternalConfigFiles >= externalConfigFiles.size()) + { + fprintf(stderr, "Max %d external configurations currently supported.\n", + (int)externalConfigFiles.size()); + exit(1); + } + + externalConfigFiles[numExternalConfigFiles].file = location; + externalConfigFiles[numExternalConfigFiles].cb = cb; + ++numExternalConfigFiles; + + return 0; +} + namespace { bool contains(const std::vector& sources, const std::string& file) @@ -130,6 +169,21 @@ void recompileCheck(const Settings& global_settings, int argc, char* argv[], } } + for(std::size_t i = 0; i < numExternalConfigFiles; ++i) + { + std::string location = externalConfigFiles[i].file; + if(global_settings.verbose > 1) + { + std::cout << " - " << location << "\n"; + } + + // Ensure that files containing multiple configurations are only added once. + if(!contains(config.sources, location)) + { + config.sources.push_back(location); + } + } + auto tasks = taskFactory({config}, settings, {}); for(auto task : tasks) diff --git a/src/rebuild.h b/src/rebuild.h index 906d089..ae3e408 100644 --- a/src/rebuild.h +++ b/src/rebuild.h @@ -16,9 +16,18 @@ struct BuildConfigurationEntry std::vector (*cb)(); }; +struct ExternalConfigurationEntry +{ + const char* file; + std::vector (*cb)(); +}; + extern std::array configFiles; extern std::size_t numConfigFiles; +extern std::array externalConfigFiles; +extern std::size_t numExternalConfigFiles; + //int reg(const char* location, std::vector (*cb)()); int unreg(const char* location); diff --git a/src/task_ar.cc b/src/task_ar.cc index fdd29b1..9658953 100644 --- a/src/task_ar.cc +++ b/src/task_ar.cc @@ -107,10 +107,6 @@ int TaskAR::runInner() { args.push_back(objectFile.string()); } - for(const auto& flag : config.ldflags) - { - args.push_back(flag); - } { // Write flags to file. std::ofstream flagsStream(flagsFile); diff --git a/src/tasks.cc b/src/tasks.cc index 56988f9..8efc98e 100644 --- a/src/tasks.cc +++ b/src/tasks.cc @@ -23,6 +23,17 @@ const std::deque& getTargets(const Settings& settings) static std::deque targets; if(!initialised) { + + // Generate externals + std::vector externalConfigs; + for(std::size_t i = 0; i < numExternalConfigFiles; ++i) + { + auto newExternalConfigs = externalConfigFiles[i].cb(); + externalConfigs.insert(externalConfigs.end(), + newExternalConfigs.begin(), + newExternalConfigs.end()); + } + for(std::size_t i = 0; i < numConfigFiles; ++i) { std::string path = @@ -32,8 +43,42 @@ const std::deque& getTargets(const Settings& settings) std::cout << configFiles[i].file << " in path " << path << "\n"; } auto configs = configFiles[i].cb(); - for(const auto& config : configs) + 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; + config.cflags.insert(config.cflags.end(), + externalConfig.cflags.begin(), + externalConfig.cflags.end()); + config.cxxflags.insert(config.cxxflags.end(), + externalConfig.cxxflags.begin(), + externalConfig.cxxflags.end()); + config.ldflags.insert(config.ldflags.end(), + externalConfig.ldflags.begin(), + externalConfig.ldflags.end()); + config.asmflags.insert(config.asmflags.end(), + externalConfig.asmflags.begin(), + externalConfig.asmflags.end()); + } + } + if(!found) + { + std::cout << "External '" << external << "' not found.\n"; + exit(1); + } + + } + + targets.push_back({config, path}); } } -- cgit v1.2.3