summaryrefslogtreecommitdiff
path: root/task_cc.cc
diff options
context:
space:
mode:
Diffstat (limited to 'task_cc.cc')
-rw-r--r--task_cc.cc75
1 files changed, 67 insertions, 8 deletions
diff --git a/task_cc.cc b/task_cc.cc
index 34129a3..bef108e 100644
--- a/task_cc.cc
+++ b/task_cc.cc
@@ -89,10 +89,15 @@ TaskCC::TaskCC(const BuildConfiguration& config, const Settings& settings,
, settings(settings)
{
sourceFile = source;
+
targetFile = settings.builddir / sourceFile.stem();
targetFile += ".o";
+
depsFile = settings.builddir / sourceFile.stem();
depsFile += ".d";
+
+ flagsFile = settings.builddir / sourceFile.stem();
+ flagsFile += ".flags";
}
bool TaskCC::dirty()
@@ -115,6 +120,12 @@ bool TaskCC::dirty()
return true;
}
+ if(!std::filesystem::exists(flagsFile))
+ {
+ //std::cout << "Missing flagsFile\n";
+ return true;
+ }
+
if(std::filesystem::last_write_time(sourceFile) >
std::filesystem::last_write_time(depsFile))
{
@@ -122,6 +133,15 @@ bool TaskCC::dirty()
return true;
}
+ {
+ auto lastFlags = readFile(flagsFile);
+ if(flagsString() != lastFlags)
+ {
+ //std::cout << "The compiler flags changed\n";
+ return true;
+ }
+ }
+
auto depList = readDeps(depsFile);
for(const auto& dep : depList)
{
@@ -152,13 +172,9 @@ int TaskCC::run()
return 1;
}
- std::string comp = "/usr/bin/g++";
- auto flags = config.cxxflags;
- if(std::string(sourceFile.extension()) == ".c")
- {
- comp = "/usr/bin/gcc";
- flags = config.cflags;
- }
+ std::string comp = compiler();
+ auto compiler_flags = flags();
+
std::vector<std::string> args;
args.push_back("-MMD");
args.push_back("-c");
@@ -166,11 +182,16 @@ int TaskCC::run()
args.push_back("-o");
args.push_back(std::string(targetFile));
- for(const auto& flag : flags)
+ for(const auto& flag : compiler_flags)
{
args.push_back(flag);
}
+ { // Write flags to file.
+ std::ofstream flagsStream(flagsFile);
+ flagsStream << flagsString();
+ }
+
return execute(comp, args);
}
@@ -188,6 +209,12 @@ int TaskCC::clean()
std::filesystem::remove(depsFile);
}
+ if(std::filesystem::exists(flagsFile))
+ {
+ std::cout << "Removing " << std::string(flagsFile) << "\n";
+ std::filesystem::remove(flagsFile);
+ }
+
return 0;
}
@@ -200,3 +227,35 @@ std::string TaskCC::target() const
{
return targetFile;
}
+
+std::vector<std::string> TaskCC::flags() const
+{
+ if(std::string(sourceFile.extension()) == ".c")
+ {
+ return config.cflags;
+ }
+ return config.cxxflags;
+}
+
+std::string TaskCC::flagsString() const
+{
+ std::string flagsStr;
+ for(const auto& flag : flags())
+ {
+ if(!flagsStr.empty())
+ {
+ flagsStr += " ";
+ }
+ flagsStr += flag;
+ }
+ return flagsStr;
+}
+
+std::string TaskCC::compiler() const
+{
+ if(std::string(sourceFile.extension()) == ".c")
+ {
+ return "/usr/bin/gcc";
+ }
+ return "/usr/bin/g++";
+}