]> git.tdb.fi Git - builder.git/blobdiff - source/gnulinker.cpp
Using different out directories per build type is more trouble than it's worth
[builder.git] / source / gnulinker.cpp
index 719780bb0441c0cc65e8c02f49ee300666cd1c20..f7982f7a626c9ac927c2e20b7db42794a72416ff 100644 (file)
@@ -63,7 +63,7 @@ Target *GnuLinker::create_target(const list<Target *> &sources, const string &ar
                        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);
@@ -121,8 +121,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)
@@ -136,12 +134,14 @@ Task *GnuLinker::Linker::run(const Target &target) const
        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();
@@ -151,9 +151,15 @@ Task *GnuLinker::Linker::run(const Target &target) const
                else if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(tgt))
                        argv.push_back(stlib->get_path().str());
                else if(SharedLibrary *shlib = dynamic_cast<SharedLibrary *>(tgt))
+               {
                        argv.push_back("-l"+shlib->get_libname());
+                       static_link_ok = false;
+               }
        }
 
+       if(static_link_ok)
+               argv.push_back("-static");
+
        if(!builder.get_dry_run())
                FS::mkpath(FS::dirname(bin.get_path()), 0755);