X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgnulinker.cpp;h=d2ea51e96c9a3e36387f0f64198aa2c4242443f9;hb=cbc6c684472ee8120f29358c0167d98524f1f939;hp=6eef8b3268da567f17385307e5c3022825fcd68a;hpb=37ffa892c453a91f06d34068e239e1ba316d7700;p=builder.git diff --git a/source/gnulinker.cpp b/source/gnulinker.cpp index 6eef8b3..d2ea51e 100644 --- a/source/gnulinker.cpp +++ b/source/gnulinker.cpp @@ -3,11 +3,12 @@ #include #include #include +#include #include "builder.h" #include "component.h" #include "executable.h" #include "externaltask.h" -#include "gnucxxcompiler.h" +#include "gnucompiler.h" #include "gnulinker.h" #include "objectfile.h" #include "sharedlibrary.h" @@ -17,24 +18,23 @@ using namespace std; using namespace Msp; -GnuLinker::GnuLinker(Builder &b): - Tool(b, "LINK") +GnuLinker::GnuLinker(Builder &b, const Architecture &a): + Tool(b, a, "LINK") { input_suffixes.push_back(".o"); input_suffixes.push_back(".a"); - const Architecture &arch = builder.get_current_arch(); - if(arch.is_native()) + if(architecture->is_native()) { system_path.push_back("/lib"); system_path.push_back("/usr/lib"); - if(arch.match_name("pc-32-linux")) + if(architecture->match_name("pc-32-linux")) system_path.push_back("/usr/lib/i386-linux-gnu"); - else if(arch.match_name("pc-64-linux")) + else if(architecture->match_name("pc-64-linux")) system_path.push_back("/usr/lib/x86_64-linux-gnu"); } else - system_path.push_back("/usr/"+arch.get_cross_prefix()+"/lib"); + system_path.push_back("/usr/"+architecture->get_cross_prefix()+"/lib"); default_linker = new Linker(*this, "CC"); cxx_linker = new Linker(*this, "CXX"); @@ -46,7 +46,7 @@ GnuLinker::~GnuLinker() delete cxx_linker; } -Target *GnuLinker::create_target(const list &sources, const std::string &arg) const +Target *GnuLinker::create_target(const list &sources, const string &arg) const { if(sources.empty()) throw invalid_argument("GnuLinker::create_target"); @@ -64,7 +64,7 @@ Target *GnuLinker::create_target(const list &sources, const std::strin throw invalid_argument("GnuLinker::create_target"); } - const Component &comp = objs.front()->get_component(); + const Component &comp = *objs.front()->get_component(); Binary *bin = 0; if(arg=="shared") bin = new SharedLibrary(builder, comp, objs); @@ -83,12 +83,22 @@ Task *GnuLinker::run(const Target &) const GnuLinker::Linker::Linker(GnuLinker &p, const string &compiler_tag): SubTool(p) { - if(compiler_tag=="CC") - command = "gcc"; - else if(compiler_tag=="CXX") - command = "g++"; + const Tool &compiler = builder.get_toolchain().get_tool(compiler_tag); + if(dynamic_cast(&compiler)) + executable = compiler.get_executable(); else - throw invalid_argument("GnuLinker::Linker::Linker"); + { + string command; + if(compiler_tag=="CC") + command = "gcc"; + else if(compiler_tag=="CXX") + command = "g++"; + else + throw invalid_argument("GnuLinker::Linker::Linker"); + if(architecture->is_cross()) + command = format("%s-%s", architecture->get_cross_prefix(), command); + executable = builder.get_vfs().find_binary(command); + } } Target *GnuLinker::Linker::create_target(const list &sources, const string &arg) const @@ -96,12 +106,27 @@ Target *GnuLinker::Linker::create_target(const list &sources, const st return parent.create_target(sources, arg); } +string GnuLinker::Linker::create_build_signature(const BuildInfo &binfo) const +{ + string result = FS::basename(executable->get_path()); + result += ','; + if(binfo.libmode<=BuildInfo::STATIC) + result += 't'; + else + result += 'd'; + if(binfo.strip) + result += 's'; + result += ",l"; + result += join(binfo.libs.begin(), binfo.libs.end(), ",l"); + return result; +} + Task *GnuLinker::Linker::run(const Target &target) const { const Binary &bin = dynamic_cast(target); vector argv; - argv.push_back(command); + argv.push_back(executable->get_path().str()); const Component &comp = *bin.get_component(); @@ -112,8 +137,6 @@ Task *GnuLinker::Linker::run(const Target &target) const if(!shlib->get_soname().empty()) argv.push_back("-Wl,-soname,"+shlib->get_soname()); } - else if(comp.get_package().get_library_mode()==ALL_STATIC) - argv.push_back("-static"); const BuildInfo &binfo = comp.get_build_info(); for(BuildInfo::PathList::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i) @@ -123,17 +146,18 @@ Task *GnuLinker::Linker::run(const Target &target) const if(binfo.threads) argv.push_back("-pthread"); - const Architecture &arch = builder.get_current_arch(); const Architecture &native_arch = builder.get_native_arch(); - if(arch.get_bits()!=native_arch.get_bits()) - argv.push_back(format("-m%d", arch.get_bits())); + if(architecture->get_bits()!=native_arch.get_bits()) + argv.push_back(format("-m%d", architecture->get_bits())); - FS::Path work_dir = comp.get_package().get_source(); + FS::Path work_dir = comp.get_package().get_source_directory(); argv.push_back("-o"); argv.push_back(relative(bin.get_path(), work_dir).str()); - const Target::Dependencies &depends = target.get_depends(); + bool static_link_ok = (binfo.libmode<=BuildInfo::STATIC); + + const Target::Dependencies &depends = target.get_dependencies(); for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i) { Target *tgt = (*i)->get_real_target(); @@ -143,11 +167,16 @@ Task *GnuLinker::Linker::run(const Target &target) const else if(StaticLibrary *stlib = dynamic_cast(tgt)) argv.push_back(stlib->get_path().str()); else if(SharedLibrary *shlib = dynamic_cast(tgt)) + { argv.push_back("-l"+shlib->get_libname()); + static_link_ok = false; + } } - if(!builder.get_dry_run()) - FS::mkpath(FS::dirname(bin.get_path()), 0755); + if(static_link_ok) + argv.push_back("-static"); + else if(architecture->get_system()=="windows") + argv.push_back("-Wl,--enable-auto-import"); return new ExternalTask(argv, work_dir); }