summaryrefslogtreecommitdiff
path: root/task_ld.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2021-06-13 18:24:16 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2021-06-13 18:24:16 +0200
commit19195e2bbdcd7a0db8f84732ce54b1c9d07c006c (patch)
treeb974b648ebacd645fbee000575268326f3b7bfbc /task_ld.cc
parentf6f5f31067cdee2d7003d8209361ac9e5b6975c5 (diff)
Make task an abstract class and make CC and LD versions of it.
Diffstat (limited to 'task_ld.cc')
-rw-r--r--task_ld.cc89
1 files changed, 89 insertions, 0 deletions
diff --git a/task_ld.cc b/task_ld.cc
new file mode 100644
index 0000000..235523f
--- /dev/null
+++ b/task_ld.cc
@@ -0,0 +1,89 @@
+#include "task_ld.h"
+
+#include <iostream>
+#include <fstream>
+#include <unistd.h>
+#include <cstring>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <spawn.h>
+
+#include "libcppbuild.h"
+#include "settings.h"
+
+TaskLD::TaskLD(const BuildConfiguration& config,
+ const Settings& settings,
+ const std::string& target,
+ const std::vector<std::string>& objects)
+ : config(config)
+ , settings(settings)
+{
+ targetFile = settings.builddir;
+ targetFile /= target;
+ for(const auto& object : objects)
+ {
+ //std::filesystem::path objectFile = settings.builddir;
+ //objectFile /= object;
+ std::filesystem::path objectFile = object;
+ objectFiles.push_back(objectFile);
+ }
+}
+
+bool TaskLD::dirty()
+{
+ if(!std::filesystem::exists(targetFile))
+ {
+ return true;
+ }
+
+ for(const auto& objectFile : objectFiles)
+ {
+ if(std::filesystem::last_write_time(targetFile) <=
+ std::filesystem::last_write_time(objectFile))
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+int TaskLD::run()
+{
+ std::string objectlist;
+ for(const auto& objectFile : objectFiles)
+ {
+ if(!objectlist.empty())
+ {
+ objectlist += " ";
+ }
+ objectlist += std::string(objectFile);
+ }
+
+ std::string compiler = "g++ " + objectlist + " " +
+ config.ldflags + " " +
+ "-o " + std::string(targetFile);
+ std::cout << compiler << "\n";
+ if(system(compiler.data()))
+ {
+ return 1;
+ }
+ return 0;
+}
+
+int TaskLD::clean()
+{
+ std::filesystem::remove(targetFile);
+ return 0;
+}
+
+std::vector<std::string> TaskLD::depends() const
+{
+ return {};
+}
+
+std::string TaskLD::target() const
+{
+ std::cout << "Removing " << std::string(targetFile) << "\n";
+ return std::string(targetFile);
+}