summaryrefslogtreecommitdiff
path: root/src/task_cc.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2021-09-25 11:06:50 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2021-09-25 11:14:36 +0200
commit019ee9f3026a419cd25916974d32fe1ebcff9578 (patch)
tree0e4edbdc40db6cff21d85613decb176ad2dd5378 /src/task_cc.cc
parentdcd084fa4abcde59d8e69c3fd24ec8685ad5065c (diff)
Add support for (optionally) explicitly declaring source language type in build configurations.
Diffstat (limited to 'src/task_cc.cc')
-rw-r--r--src/task_cc.cc66
1 files changed, 51 insertions, 15 deletions
diff --git a/src/task_cc.cc b/src/task_cc.cc
index 8256c70..eb361cb 100644
--- a/src/task_cc.cc
+++ b/src/task_cc.cc
@@ -5,6 +5,7 @@
#include <iostream>
#include <fstream>
+#include <cassert>
#include "libctor.h"
#include "settings.h"
@@ -84,30 +85,75 @@ std::vector<std::string> readDeps(const std::string& depFile)
return output;
}
+
+Language languageFromExtension(const std::filesystem::path& file)
+{
+ auto ext = file.extension().string();
+ if(ext == ".c")
+ {
+ return Language::C;
+ }
+
+ if(ext == ".C" ||
+ ext == ".cc" ||
+ ext == ".cpp" ||
+ ext == ".CPP" ||
+ ext == ".c++" ||
+ ext == ".cp" ||
+ ext == ".cxx")
+ {
+ return Language::Cpp;
+ }
+
+ if(ext == ".s" ||
+ ext == ".S" ||
+ ext == ".asm")
+ {
+ return Language::Asm;
+ }
+
+ std::cerr << "Could not deduce language from " << file.string() << "\n";
+ exit(1);
+ return {};
+}
} // namespace ::
TaskCC::TaskCC(const BuildConfiguration& config, const Settings& settings,
- const std::string& sourceDir, const std::string& source)
+ const std::string& sourceDir, const Source& source)
: Task(config)
, config(config)
, settings(settings)
, sourceDir(sourceDir)
{
sourceFile = sourceDir;
- sourceFile /= source;
+ sourceFile /= source.file;
std::filesystem::path base = settings.builddir;
base /= config.target;
base += "-";
base += sourceFile.stem();
- if(sourceFile.extension().string() == ".c")
+ target_type = TargetType::Object;
+ source_language = source.language;
+ if(source_language == Language::Auto)
{
- base += "_c";
+ source_language = languageFromExtension(sourceFile);
}
- else
+
+ switch(source_language)
{
+ case Language::C:
+ base += "_c";
+ break;
+ case Language::Cpp:
base += "_cc";
+ break;
+ case Language::Asm:
+ base += "_asm";
+ break;
+ case Language::Auto:
+ assert(0 && "This should never happen");
+ break;
}
targetFile = base;
@@ -116,16 +162,6 @@ TaskCC::TaskCC(const BuildConfiguration& config, const Settings& settings,
depsFile += ".d";
flagsFile = base;
flagsFile += ".flags";
-
- target_type = TargetType::Object;
- if(sourceFile.extension().string() == ".c")
- {
- source_language = Language::C;
- }
- else
- {
- source_language = Language::Cpp;
- }
}
std::string TaskCC::name() const