]> git.tdb.fi Git - builder.git/blobdiff - source/gnulinker.cpp
Add a list of symbols to keep in the binary to BuildInfo
[builder.git] / source / gnulinker.cpp
index a56d716780817cdd63f3e9536584bc242ac19b78..75a1bac280609086da046f86e3c71e1cc115d5e5 100644 (file)
 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");
@@ -144,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;
 }
 
@@ -166,9 +174,7 @@ Task *GnuLinker::Linker::run(const Target &target) const
        vector<string> 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<const SharedLibrary *>(&bin))
        {
@@ -196,7 +202,13 @@ Task *GnuLinker::Linker::run(const Target &target) const
                }
        }
 
-       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)
@@ -205,14 +217,16 @@ Task *GnuLinker::Linker::run(const Target &target) const
                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);
-       bool need_l_objc = false;
 
        const Target::Dependencies &depends = target.get_dependencies();
        for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
@@ -221,13 +235,7 @@ Task *GnuLinker::Linker::run(const Target &target) const
                Target *tgt = (*i)->get_real_target();
 
                if(ObjectFile *obj = dynamic_cast<ObjectFile *>(tgt))
-               {
                        argv.push_back(relative(obj->get_path(), work_dir).str());
-                       /* XXX This is a hack.  A more generic way is needed for tools to pass
-                       information down the chain. */
-                       if(obj->get_tool()->get_tag()=="OBJC")
-                               need_l_objc = true;
-               }
                else if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(tgt))
                        argv.push_back((file?file:stlib)->get_path().str());
                else if(SharedLibrary *shlib = dynamic_cast<SharedLibrary *>(tgt))
@@ -253,8 +261,6 @@ Task *GnuLinker::Linker::run(const Target &target) const
                        argv.push_back(i->substr(0, i->size()-10));
                }
 
-       if(need_l_objc)
-               argv.push_back("-lobjc");
        if(static_link_ok)
                argv.push_back("-static");
        else if(architecture->get_system()=="windows")