X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgnulinker.cpp;h=1b969b4c06882755926da76c57ec83e73144fddf;hb=36f162eedf3772d2c0373651795e7e38b6d28fb4;hp=02708cc9b68d2a2587d92691fa72d788f6e329bd;hpb=7ed7c30ee0ceb734f17fe0c6d4bc6d37fb2ab5a7;p=builder.git diff --git a/source/gnulinker.cpp b/source/gnulinker.cpp index 02708cc..1b969b4 100644 --- a/source/gnulinker.cpp +++ b/source/gnulinker.cpp @@ -21,13 +21,18 @@ using namespace std; using namespace Msp; -GnuLinker::GnuLinker(Builder &b, const Architecture &a): +GnuLinker::GnuLinker(Builder &b, const Architecture &a, const FS::Path &sysroot): Tool(b, a, "LINK") { input_suffixes.push_back(".o"); input_suffixes.push_back(".a"); - if(architecture->is_native()) + if(!sysroot.empty()) + { + build_info.sysroot = sysroot; + system_path.push_back(sysroot/"usr"/"lib"); + } + else if(architecture->is_native()) { system_path.push_back("/lib"); system_path.push_back("/usr/lib"); @@ -115,7 +120,14 @@ Task *GnuLinker::run(const Target &) const GnuLinker::Linker::Linker(GnuLinker &p, const string &ct): SubTool(p), compiler_tag(ct) -{ } +{ + if(compiler_tag=="CC") + set_command("gcc", true); + else if(compiler_tag=="CXX") + set_command("g++", true); + else + throw invalid_argument("GnuLinker::Linker::Linker"); +} Target *GnuLinker::Linker::create_target(const list &sources, const string &arg) { @@ -137,8 +149,11 @@ string GnuLinker::Linker::create_build_signature(const BuildInfo &binfo) const result += 'd'; if(binfo.strip) result += 's'; - result += ",l"; - result += join(binfo.libs.begin(), binfo.libs.end(), ",l"); + if(!binfo.libs.empty()) + { + result += ",l"; + result += join(binfo.libs.begin(), binfo.libs.end(), ",l"); + } return result; } @@ -150,18 +165,6 @@ void GnuLinker::Linker::do_prepare() compiler.prepare(); executable = compiler.get_executable(); } - else - { - string command; - if(compiler_tag=="CC") - command = "gcc"; - else if(compiler_tag=="CXX") - command = "g++"; - else - throw invalid_argument("GnuLinker::Linker::Linker"); - - set_executable(command, true); - } } Task *GnuLinker::Linker::run(const Target &target) const @@ -171,35 +174,63 @@ Task *GnuLinker::Linker::run(const Target &target) const vector argv; argv.push_back(executable->get_path().str()); - const Component &comp = *bin.get_component(); - - FS::Path work_dir = comp.get_package().get_source_directory(); + FS::Path work_dir = bin.get_component()->get_package().get_source_directory(); if(const SharedLibrary *shlib = dynamic_cast(&bin)) { argv.push_back("-shared"); argv.push_back("-fPIC"); if(architecture->get_system()!="windows" && !shlib->get_soname().empty()) - argv.push_back("-Wl,-soname,"+shlib->get_soname()); + { + if(architecture->get_system()=="darwin") + { + argv.push_back("-install_name"); + argv.push_back(shlib->get_soname()); + + const string &ver = shlib->get_package()->get_version(); + const string &if_ver = shlib->get_package()->get_interface_version(); + if(!ver.empty() && !if_ver.empty()) + { + argv.push_back("-current_version"); + argv.push_back(ver); + argv.push_back("-compatibility_version"); + argv.push_back(if_ver); + } + } + else + argv.push_back("-Wl,-soname,"+shlib->get_soname()); + } } - const BuildInfo &binfo = comp.get_build_info(); + BuildInfo binfo; + target.collect_build_info(binfo); + + const FS::Path &sysroot = binfo.sysroot; + if(!sysroot.empty()) + argv.push_back("--sysroot="+sysroot.str()); + for(BuildInfo::PathList::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i) argv.push_back("-L"+i->str()); if(binfo.strip) argv.push_back("-s"); - if(binfo.threads) + if(binfo.threads && architecture->get_system()!="windows" && architecture->get_system()!="darwin") argv.push_back("-pthread"); const Architecture &native_arch = builder.get_native_arch(); - if(architecture->get_bits()!=native_arch.get_bits()) + if(architecture->is_native() && architecture->get_bits()!=native_arch.get_bits()) argv.push_back(format("-m%d", architecture->get_bits())); argv.push_back("-o"); argv.push_back(relative(bin.get_path(), work_dir).str()); + for(BuildInfo::WordList::const_iterator i=binfo.keep_symbols.begin(); i!=binfo.keep_symbols.end(); ++i) + argv.push_back("-u"+*i); + bool static_link_ok = (binfo.libmode<=BuildInfo::STATIC); + if(architecture->get_system()=="windows" && architecture->get_cross_prefix().find("mingw")!=string::npos) + argv.push_back("-lmingw32"); + const Target::Dependencies &depends = target.get_dependencies(); for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i) { @@ -226,6 +257,13 @@ Task *GnuLinker::Linker::run(const Target &target) const } } + for(BuildInfo::WordList::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i) + if(i->size()>10 && !i->compare(i->size()-10, 10, ".framework")) + { + argv.push_back("-framework"); + argv.push_back(i->substr(0, i->size()-10)); + } + if(static_link_ok) argv.push_back("-static"); else if(architecture->get_system()=="windows")