1 #include <msp/fs/dir.h>
2 #include <msp/fs/utils.h>
5 #include "executable.h"
8 #include "objectfile.h"
10 #include "sharedlibrary.h"
11 #include "staticlibrary.h"
12 #include "systemlibrary.h"
17 Link::Link(Builder &b, const Binary &bin):
20 const Component &comp = bin.get_component();
22 work_dir = comp.get_package().get_source();
24 //XXX Determine whether to use g++ or gcc
26 argv.push_back(builder.get_current_arch().get_tool(tool));
28 if(comp.get_type()==Component::LIBRARY || comp.get_type()==Component::MODULE)
29 argv.push_back("-shared");
30 else if(comp.get_package().get_library_mode()==ALL_STATIC)
31 argv.push_back("-static");
33 if(const SharedLibrary *lib = dynamic_cast<const SharedLibrary *>(&bin))
34 if(!lib->get_soname().empty())
35 argv.push_back("-Wl,-soname,"+lib->get_soname());
37 const BuildInfo &binfo = comp.get_build_info();
38 for(list<string>::const_iterator i=binfo.ldflags.begin(); i!=binfo.ldflags.end(); ++i)
40 for(list<string>::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
41 argv.push_back("-L"+*i);
44 argv.push_back(relative(bin.get_path(), work_dir).str());
45 const TargetList &deps = bin.get_depends();
46 for(TargetList::const_iterator i=deps.begin(); i!=deps.end(); ++i)
48 Target *tgt = (*i)->get_real_target();
50 if(ObjectFile *obj = dynamic_cast<ObjectFile *>(tgt))
51 argv.push_back(relative(obj->get_path(), work_dir).str());
52 else if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(tgt))
53 argv.push_back(stlib->get_path().str());
54 else if(Library *lib = dynamic_cast<Library *>(tgt))
55 argv.push_back("-l"+lib->get_libname());
58 FS::Path binpath = bin.get_path();
59 if(!builder.get_dry_run())
60 FS::mkpath(FS::dirname(binpath), 0755);
62 announce(comp.get_package().get_name(), tool, relative(binpath, work_dir).str().substr(2));