summaryrefslogtreecommitdiff
path: root/src/task_cc.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2022-07-10 17:24:16 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2022-07-15 10:11:05 +0200
commitae1871ca0ffcac3e8bd337f8d8bb4e7fd6c59295 (patch)
treed15df8a03fab6bdacebb6ba53c8ad30c290781fc /src/task_cc.cc
parent2a55edcc40372403fb2de8ed20ed5c44464d416e (diff)
Make tools abstraction around compiler options to better support tool agnostic arguments.
Diffstat (limited to 'src/task_cc.cc')
-rw-r--r--src/task_cc.cc37
1 files changed, 20 insertions, 17 deletions
diff --git a/src/task_cc.cc b/src/task_cc.cc
index a55a619..c2dd5d6 100644
--- a/src/task_cc.cc
+++ b/src/task_cc.cc
@@ -10,6 +10,7 @@
#include "libctor.h"
#include "execute.h"
#include "util.h"
+#include "tools.h"
TaskCC::TaskCC(const BuildConfiguration& config, const Settings& settings,
const std::string& sourceDir, const Source& source)
@@ -267,39 +268,41 @@ std::string TaskCC::flagsString() const
std::vector<std::string> TaskCC::getCompilerArgs() const
{
+ auto tool_chain = getToolChain(config.system);
+
auto compiler_flags = flags();
std::vector<std::string> args;
- args.push_back("-MMD");
+ append(args, getOption(tool_chain, opt::generate_dep_tree));
if(std::filesystem::path(config.target).extension() == ".so")
{
// Add -fPIC arg to all contained object files
- args.push_back("-fPIC");
+ append(args, getOption(tool_chain, opt::position_independent_code));
}
- args.push_back("-c");
+ append(args, getOption(tool_chain, opt::no_link));
args.push_back(sourceFile.string());
- args.push_back("-o");
- args.push_back(targetFile().string());
+ append(args, getOption(tool_chain, opt::output, targetFile().string()));
for(const auto& flag : compiler_flags)
{
- // Is arg an added include path?
- if(flag.substr(0, 2) == "-I")
+ auto option = getOption(flag);
+ switch(option.first)
{
- std::string include_path = flag.substr(2);
- include_path.erase(0, include_path.find_first_not_of(' '));
- std::filesystem::path path(include_path);
-
- // Is it relative?
- if(path.is_relative())
+ // Relative include paths has to be altered to be relative to sourceDir
+ case opt::include_path:
{
- path = (sourceDir / path).lexically_normal();
- std::string new_include_path = "-I" + path.string();
- args.push_back(new_include_path);
- continue;
+ std::filesystem::path path(option.second);
+ if(path.is_relative())
+ {
+ path = (sourceDir / path).lexically_normal();
+ append(args, getOption(tool_chain, opt::include_path, path.string()));
+ }
}
+ continue;
+ default:
+ break;
}
args.push_back(flag);