]> git.tdb.fi Git - builder.git/blobdiff - source/link.cpp
Replace per-file copyright notices with a single file
[builder.git] / source / link.cpp
index e2c0f1222a83cb9d7baea296f8fcda4da17c0130..5cee28753405a5158cdf5abfa6d6fdf69fa00aee 100644 (file)
@@ -1,38 +1,65 @@
-#include <msp/path/utils.h>
+#include <msp/fs/dir.h>
+#include <msp/fs/utils.h>
+#include "builder.h"
 #include "component.h"
 #include "executable.h"
+#include "install.h"
 #include "link.h"
+#include "objectfile.h"
 #include "package.h"
+#include "sharedlibrary.h"
+#include "staticlibrary.h"
+#include "systemlibrary.h"
 
 using namespace std;
 using namespace Msp;
 
-Link::Link(Builder &b, const Executable &exe, const Component &comp):
+Link::Link(Builder &b, const Binary &bin):
        ExternalAction(b)
 {
-       argv.push_back("g++");
-       
-       if(comp.get_type()==Component::LIBRARY)
+       const Component &comp = bin.get_component();
+
+       work_dir = comp.get_package().get_source();
+
+       //XXX Determine whether to use g++ or gcc
+       string tool = "LXX";
+       argv.push_back(builder.get_current_arch().get_tool(tool));
+
+       if(comp.get_type()==Component::LIBRARY || comp.get_type()==Component::MODULE)
                argv.push_back("-shared");
+       else if(comp.get_package().get_library_mode()==ALL_STATIC)
+               argv.push_back("-static");
 
-       const BuildInfo &binfo=comp.get_build_info();
+       if(const SharedLibrary *lib = dynamic_cast<const SharedLibrary *>(&bin))
+               if(!lib->get_soname().empty())
+                       argv.push_back("-Wl,-soname,"+lib->get_soname());
+
+       const BuildInfo &binfo = comp.get_build_info();
        for(list<string>::const_iterator i=binfo.ldflags.begin(); i!=binfo.ldflags.end(); ++i)
                argv.push_back(*i);
        for(list<string>::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
                argv.push_back("-L"+*i);
-       for(list<string>::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i)
-               argv.push_back("-l"+*i);
-       
+
        argv.push_back("-o");
-       argv.push_back(exe.get_name());
-       const list<Target *> &deps=exe.get_depends();
-       for(list<Target *>::const_iterator i=deps.begin(); i!=deps.end(); ++i)
-               argv.push_back((*i)->get_name());
+       argv.push_back(relative(bin.get_path(), work_dir).str());
+       const TargetList &deps = bin.get_depends();
+       for(TargetList::const_iterator i=deps.begin(); i!=deps.end(); ++i)
+       {
+               Target *tgt = (*i)->get_real_target();
+
+               if(ObjectFile *obj = dynamic_cast<ObjectFile *>(tgt))
+                       argv.push_back(relative(obj->get_path(), work_dir).str());
+               else if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(tgt))
+                       argv.push_back(stlib->get_path().str());
+               else if(Library *lib = dynamic_cast<Library *>(tgt))
+                       argv.push_back("-l"+lib->get_libname());
+       }
 
-       Path::Path epath=exe.get_name();
-       Path::mkpath(epath.subpath(0, epath.size()-1), 0755);
+       FS::Path binpath = bin.get_path();
+       if(!builder.get_dry_run())
+               FS::mkpath(FS::dirname(binpath), 0755);
 
-       announce(comp.get_package().get_name(), "LINK", relative(epath, comp.get_package().get_source()).str());
+       announce(comp.get_package().get_name(), tool, relative(binpath, work_dir).str().substr(2));
 
        launch();
 }