summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libctor.cc5
-rw-r--r--src/libctor.h16
-rw-r--r--src/rebuild.cc54
-rw-r--r--src/rebuild.h9
-rw-r--r--src/task_ar.cc4
-rw-r--r--src/tasks.cc47
6 files changed, 129 insertions, 6 deletions
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<Source> sources; // source list
- std::vector<std::string> depends; // internal dependencies
+ 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
+ std::vector<std::string> externals; // externals used by this configuration
};
using BuildConfigurations = std::vector<BuildConfiguration>;
int reg(const char* location, 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
+};
+
+using ExternalConfigurations = std::vector<ExternalConfiguration>;
+
+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<ExternalConfigurationEntry, 1024> 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<ExternalConfiguration> (*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<Source>& 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<BuildConfiguration> (*cb)();
};
+struct ExternalConfigurationEntry
+{
+ const char* file;
+ std::vector<ExternalConfiguration> (*cb)();
+};
+
extern std::array<BuildConfigurationEntry, 1024> configFiles;
extern std::size_t numConfigFiles;
+extern std::array<ExternalConfigurationEntry, 1024> externalConfigFiles;
+extern std::size_t numExternalConfigFiles;
+
//int reg(const char* location, std::vector<BuildConfiguration> (*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<Target>& getTargets(const Settings& settings)
static std::deque<Target> targets;
if(!initialised)
{
+
+ // Generate externals
+ std::vector<ExternalConfiguration> 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<Target>& 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});
}
}