delete cxx_linker;
}
-Target *GnuLinker::create_target(const list<Target *> &sources, const string &arg)
+Target *GnuLinker::create_target(const vector<Target *> &sources, const string &arg)
{
if(sources.empty())
throw invalid_argument("GnuLinker::create_target");
- list<ObjectFile *> objs;
+ vector<ObjectFile *> objs;
+ objs.reserve(sources.size());
Linker *linker = default_linker;
for(Target *s: sources)
{
- if(ObjectFile *obj = dynamic_cast<ObjectFile *>(s))
- {
- objs.push_back(obj);
- if(obj->get_tool()->get_tag()=="CXX")
- linker = cxx_linker;
- }
- else
- throw invalid_argument("GnuLinker::create_target");
+ ObjectFile &obj = dynamic_cast<ObjectFile &>(*s);
+ objs.push_back(&obj);
+ if(obj.get_tool()->get_tag()=="CXX")
+ linker = cxx_linker;
}
const Component &comp = *objs.front()->get_component();
if(!sysroot.empty())
argv.push_back("--sysroot="+sysroot.str());
- builder.get_logger().log("auxcommands", format("Running %s", join(argv.begin(), argv.end())));
+ builder.get_logger().log("auxcommands", "Running %s", join(argv.begin(), argv.end()));
try
{
string output = ExternalTask::run_and_capture_output(argv, FS::Path(), true);
}
path /= output.substr(search_dir, end-search_dir);
- builder.get_logger().log("tools", format("Got %s system path: %s", tag, path));
+ builder.get_logger().log("tools", "Got %s system path: %s", tag, path);
system_path.push_back(path);
path_found = true;
if(!path_found)
{
- builder.get_logger().log("tools", format("No %s system path found, using defaults", tag));
+ builder.get_logger().log("tools", "No %s system path found, using defaults", tag);
if(!sysroot.empty())
system_path.push_back(sysroot/"usr/lib");
else if(architecture->is_native())
}
}
-Task *GnuLinker::run(const Target &) const
-{
- throw logic_error("GnuLinker should not be run directly");
-}
-
GnuLinker::Linker::Linker(GnuLinker &p, const string &ct):
SubTool(p),
set_command("g++", true);
else
throw invalid_argument("GnuLinker::Linker::Linker");
+
+ set_run(_run);
}
string GnuLinker::Linker::create_build_signature(const BuildInfo &binfo) const
}
}
-Task *GnuLinker::Linker::run(const Target &target) const
+Task *GnuLinker::Linker::_run(const Binary &bin)
{
- const Binary &bin = dynamic_cast<const Binary &>(target);
+ const Linker &tool = dynamic_cast<const Linker &>(*bin.get_tool());
+ const Builder &builder = tool.get_builder();
+ const Architecture &arch = *tool.get_architecture();
ExternalTask::Arguments argv;
- argv.push_back(executable->get_path().str());
+ argv.push_back(tool.get_executable()->get_path().str());
FS::Path work_dir = bin.get_component()->get_package().get_source_directory();
{
argv.push_back("-shared");
argv.push_back("-fPIC");
- if(architecture->get_system()!="windows" && !shlib->get_soname().empty())
+ if(arch.get_system()!="windows" && !shlib->get_soname().empty())
{
- if(architecture->get_system()=="darwin")
+ if(arch.get_system()=="darwin")
{
argv.push_back("-install_name");
argv.push_back(shlib->get_soname());
}
BuildInfo binfo;
- target.collect_build_info(binfo);
+ bin.collect_build_info(binfo);
const FS::Path &sysroot = binfo.sysroot;
if(!sysroot.empty())
argv.push_back("-L"+p.str());
if(binfo.strip)
argv.push_back("-s");
- if(binfo.threads && architecture->get_system()!="windows" && architecture->get_system()!="darwin")
+ if(binfo.threads && arch.get_system()!="windows" && arch.get_system()!="darwin")
argv.push_back("-pthread");
const Architecture &native_arch = builder.get_native_arch();
- if(architecture->is_native() && architecture->get_bits()!=native_arch.get_bits())
- argv.push_back(format("-m%d", architecture->get_bits()));
+ if(arch.is_native() && arch.get_bits()!=native_arch.get_bits())
+ argv.push_back(format("-m%d", arch.get_bits()));
argv.push_back("-o");
argv.push_back(relative(bin.get_path(), work_dir).str());
bool static_link_ok = (binfo.libmode<=BuildInfo::STATIC);
- for(Target *d: target.get_dependencies())
+ for(Target *d: bin.get_dependencies())
{
FileTarget *file = dynamic_cast<FileTarget *>(d);
Target *tgt = d->get_real_target();
argv.push_back("-static");
else
{
- if(compiler_tag=="CXX")
+ if(tool.compiler_tag=="CXX")
{
auto i = binfo.libmodes.find("stdc++");
if(i!=binfo.libmodes.end() && i->second<=BuildInfo::STATIC)
argv.push_back("-static-libstdc++");
}
- if(architecture->get_system()=="windows")
+ if(arch.get_system()=="windows")
argv.push_back("-Wl,--enable-auto-import");
}