]> git.tdb.fi Git - builder.git/blobdiff - source/gnulinker.cpp
Remove the -lmingw32 hack
[builder.git] / source / gnulinker.cpp
index adc3efcfcf6ad72d933b8e401836cbd935e34091..9f6230e481f2f0260275d19d9a88e2ff4a41e46e 100644 (file)
@@ -21,7 +21,7 @@
 using namespace std;
 using namespace Msp;
 
-GnuLinker::GnuLinker(Builder &b, const Architecture &a, const FS::Path &sysroot):
+GnuLinker::GnuLinker(Builder &b, const Architecture &a):
        Tool(b, a, "LINK")
 {
        input_suffixes.push_back(".o");
@@ -29,9 +29,6 @@ GnuLinker::GnuLinker(Builder &b, const Architecture &a, const FS::Path &sysroot)
 
        processing_unit = COMPONENT;
 
-       if(!sysroot.empty())
-               build_info.sysroot = sysroot;
-
        default_linker = new Linker(*this, "CC");
        cxx_linker = new Linker(*this, "CXX");
 }
@@ -220,6 +217,10 @@ string GnuLinker::Linker::create_build_signature(const BuildInfo &binfo) const
 
 void GnuLinker::Linker::do_prepare()
 {
+       parent.prepare();
+       build_info = parent.get_build_info();
+       system_path = parent.get_system_path();
+
        Tool &compiler = builder.get_toolchain().get_tool(compiler_tag);
        if(dynamic_cast<GnuCompiler *>(&compiler))
        {
@@ -270,6 +271,16 @@ Task *GnuLinker::Linker::run(const Target &target) const
        if(!sysroot.empty())
                argv.push_back("--sysroot="+sysroot.str());
 
+       FS::Path lib_dir = builder.get_prefix()/"lib";
+       if(binfo.rpath_mode==BuildInfo::ABSOLUTE)
+               argv.push_back("-Wl,-rpath,"+lib_dir.str());
+       else
+       {
+               if(binfo.rpath_mode==BuildInfo::RELATIVE)
+                       argv.push_back("-Wl,-rpath,$ORIGIN/../lib");
+               argv.push_back("-Wl,-rpath-link,"+lib_dir.str());
+       }
+
        for(BuildInfo::PathList::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
                argv.push_back("-L"+i->str());
        if(binfo.strip)
@@ -289,9 +300,6 @@ Task *GnuLinker::Linker::run(const Target &target) const
 
        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)
        {
@@ -327,8 +335,18 @@ Task *GnuLinker::Linker::run(const Target &target) const
 
        if(static_link_ok)
                argv.push_back("-static");
-       else if(architecture->get_system()=="windows")
-               argv.push_back("-Wl,--enable-auto-import");
+       else
+       {
+               if(compiler_tag=="CXX")
+               {
+                       BuildInfo::LibModeMap::const_iterator i = binfo.libmodes.find("stdc++");
+                       if(i!=binfo.libmodes.end() && i->second<=BuildInfo::STATIC)
+                               argv.push_back("-static-libstdc++");
+               }
+
+               if(architecture->get_system()=="windows")
+                       argv.push_back("-Wl,--enable-auto-import");
+       }
 
        return new ExternalTask(argv, work_dir);
 }