summaryrefslogtreecommitdiff
path: root/src/task_ld.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/task_ld.cc')
-rw-r--r--src/task_ld.cc58
1 files changed, 37 insertions, 21 deletions
diff --git a/src/task_ld.cc b/src/task_ld.cc
index 20e823d..b0aa4ae 100644
--- a/src/task_ld.cc
+++ b/src/task_ld.cc
@@ -6,13 +6,13 @@
#include <iostream>
#include <fstream>
-#include "libctor.h"
+#include "ctor.h"
#include "execute.h"
#include "util.h"
#include "tools.h"
-TaskLD::TaskLD(const BuildConfiguration& config,
- const Settings& settings,
+TaskLD::TaskLD(const ctor::build_configuration& config,
+ const ctor::settings& settings,
const std::string& target,
const std::vector<std::string>& objects,
const std::string& sourceDir)
@@ -22,14 +22,16 @@ TaskLD::TaskLD(const BuildConfiguration& config,
, sourceDir(sourceDir)
{
target_type = config.type;
- if(target_type == TargetType::Auto)
+ output_system = config.system;
+
+ if(target_type == ctor::target_type::automatic)
{
- target_type = TargetType::Executable;
+ target_type = ctor::target_type::executable;
}
- std::filesystem::create_directories(std::filesystem::path(settings.builddir) / sourceDir);
-
_targetFile = target;
+ auto toolchain = getToolChain(config.system);
+ _targetFile = extension(toolchain, target_type, config.system, _targetFile);
for(const auto& object : objects)
{
std::filesystem::path objectFile = object;
@@ -45,15 +47,17 @@ TaskLD::TaskLD(const BuildConfiguration& config,
flagsFile = std::filesystem::path(settings.builddir) / cleanUp(sourceDir) / targetFile().stem();
flagsFile += ".flags";
- source_language = Language::C;
+ source_language = ctor::language::c;
for(const auto& source : config.sources)
{
std::filesystem::path sourceFile(source.file);
if(sourceFile.extension().string() != ".c")
{
- source_language = Language::Cpp;
+ source_language = ctor::language::cpp;
}
}
+
+ std::filesystem::create_directories(targetFile().parent_path());
}
bool TaskLD::dirtyInner()
@@ -82,27 +86,33 @@ bool TaskLD::dirtyInner()
int TaskLD::runInner()
{
- auto tool_chain = getToolChain(config.system);
+ auto toolchain = getToolChain(config.system);
std::vector<std::string> args;
for(const auto& dep : getDependsTasks())
{
auto depFile = dep->targetFile();
- if(depFile.extension() == ".so")
+ auto dep_type = target_type_from_extension(toolchain, depFile);
+ if(dep_type == ctor::target_type::dynamic_library)
{
- append(args, getOption(tool_chain, opt::library_path,
+ append(args, ld_option(toolchain, ctor::ld_opt::library_path,
targetFile().parent_path().string()));
auto lib = depFile.stem().string().substr(3); // strip 'lib' prefix
- append(args, getOption(tool_chain, opt::link, lib));
+ append(args, ld_option(toolchain, ctor::ld_opt::link, lib));
}
- else if(depFile.extension() == ".a" || depFile.extension() == ".o")
+ else if(dep_type == ctor::target_type::static_library ||
+ dep_type == ctor::target_type::object)
{
args.push_back(depFile.string());
}
}
- append(args, config.flags.ldflags);
- append(args, getOption(tool_chain, opt::output, targetFile().string()));
+ for(const auto& flag : config.flags.ldflags)
+ {
+ append(args, to_strings(toolchain, flag));
+ }
+
+ append(args, ld_option(toolchain, ctor::ld_opt::output, targetFile().string()));
{ // Write flags to file.
std::ofstream flagsStream(flagsFile);
@@ -111,11 +121,11 @@ int TaskLD::runInner()
if(settings.verbose == 0)
{
- std::cout << "LD => " << targetFile().string() << "\n";
+ std::cout << "LD => " << targetFile().string() << std::endl;
}
auto tool = compiler();
- return execute(tool, args, settings.verbose > 0);
+ return execute(tool, args, {}, settings.verbose > 0);
}
int TaskLD::clean()
@@ -168,14 +178,20 @@ bool TaskLD::derived() const
std::string TaskLD::flagsString() const
{
+ auto toolchain = getToolChain(config.system);
std::string flagsStr;
+ bool first{true};
for(const auto& flag : config.flags.ldflags)
{
- if(flag != config.flags.ldflags[0])
+ for(const auto& str : to_strings(toolchain, flag))
{
- flagsStr += " ";
+ if(first)
+ {
+ flagsStr += " ";
+ first = false;
+ }
+ flagsStr += str;
}
- flagsStr += flag;
}
flagsStr += "\n";