#include "task_ld.h" #include #include #include #include #include #include #include #include "libcppbuild.h" #include "settings.h" TaskLD::TaskLD(const BuildConfiguration& config, const Settings& settings, const std::string& target, const std::vector& 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 TaskLD::depends() const { return {}; } std::string TaskLD::target() const { std::cout << "Removing " << std::string(targetFile) << "\n"; return std::string(targetFile); }