summaryrefslogtreecommitdiff
path: root/src/task_cc.cc
diff options
context:
space:
mode:
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