diff options
Diffstat (limited to 'src/task_so.cc')
-rw-r--r-- | src/task_so.cc | 76 |
1 files changed, 53 insertions, 23 deletions
diff --git a/src/task_so.cc b/src/task_so.cc index 8c6dbd4..92aeefe 100644 --- a/src/task_so.cc +++ b/src/task_so.cc @@ -6,25 +6,29 @@ #include <iostream> #include <fstream> -#include "libctor.h" +#include "ctor.h" #include "execute.h" #include "util.h" #include "tools.h" -TaskSO::TaskSO(const BuildConfiguration& config, - const Settings& settings, +TaskSO::TaskSO(const ctor::build_configuration& config_, + const ctor::settings& settings_, const std::string& target, const std::vector<std::string>& objects, - const std::string& sourceDir) - : Task(config, settings, sourceDir) - , config(config) - , settings(settings) - , sourceDir(sourceDir) + const std::string& sourceDir_) + : Task(config_, settings_, sourceDir_) + , config(config_) + , settings(settings_) + , sourceDir(sourceDir_) { std::filesystem::path base = sourceDir; - std::filesystem::create_directories(std::filesystem::path(settings.builddir) / base); + + target_type = ctor::target_type::dynamic_library; + output_system = config.system; _targetFile = base / target; + auto toolchain = getToolChain(config.system); + _targetFile = extension(toolchain, target_type, config.system, _targetFile); for(const auto& object : objects) { std::filesystem::path objectFile = object; @@ -34,23 +38,24 @@ TaskSO::TaskSO(const BuildConfiguration& config, for(const auto& dep : config.depends) { - depFiles.push_back(dep); + depFiles.emplace_back(dep); } flagsFile = std::filesystem::path(settings.builddir) / cleanUp(sourceDir) / targetFile().stem(); flagsFile += ".flags"; - target_type = TargetType::DynamicLibrary; - source_language = Language::C; + source_language = ctor::language::c; for(const auto& source : config.sources) { std::filesystem::path sourceFile(source.file); // TODO: Use task languages instead if(sourceFile.extension().string() != ".c") { - source_language = Language::Cpp; + source_language = ctor::language::cpp; } } + + std::filesystem::create_directories(targetFile().parent_path()); } bool TaskSO::dirtyInner() @@ -79,21 +84,24 @@ bool TaskSO::dirtyInner() int TaskSO::runInner() { - auto tool_chain = getToolChain(config.system); + auto toolchain = getToolChain(config.system); std::vector<std::string> args; - append(args, getOption(tool_chain, opt::position_independent_code)); - append(args, getOption(tool_chain, opt::build_shared)); + append(args, ld_option(toolchain, ctor::ld_opt::position_independent_code)); + append(args, ld_option(toolchain, ctor::ld_opt::build_shared)); - append(args, getOption(tool_chain, opt::output, targetFile().string())); + append(args, ld_option(toolchain, ctor::ld_opt::output, targetFile().string())); for(const auto& task : getDependsTasks()) { args.push_back(task->targetFile().string()); } - append(args, config.flags.ldflags); + for(const auto& flag : config.flags.ldflags) + { + append(args, to_strings(toolchain, flag)); + } { // Write flags to file. std::ofstream flagsStream(flagsFile); @@ -102,11 +110,24 @@ int TaskSO::runInner() if(settings.verbose == 0) { - std::cout << "LD => " << targetFile().string() << "\n"; + std::string output = "LD => " + targetFile().string() + '\n'; + std::cout << output << std::flush; } auto tool = compiler(); - return execute(tool, args, settings.verbose > 0); + const auto& cfg = ctor::get_configuration(); + auto ldflags = cfg.getenv("LDFLAGS"); + if(!ldflags.empty()) + { + append(args, ld_option(toolchain, ctor::ld_opt::custom, ldflags)); + } + auto res = execute(settings, tool, args, cfg.env); + if(res != 0) + { + std::filesystem::remove(targetFile()); + } + + return res; } int TaskSO::clean() @@ -159,12 +180,21 @@ bool TaskSO::derived() const std::string TaskSO::flagsString() const { - std::string flagsStr = compiler(); + auto toolchain = getToolChain(config.system); + std::string flagsStr; + bool first{true}; for(const auto& flag : config.flags.ldflags) { - flagsStr += " " + flag; + for(const auto& str : to_strings(toolchain, flag)) + { + if(first) + { + flagsStr += " "; + first = false; + } + flagsStr += str; + } } - flagsStr += "\n"; for(const auto& dep : config.depends) { |