1 #include <msp/path/utils.h>
4 #include "executable.h"
7 #include "objectfile.h"
9 #include "sharedlibrary.h"
10 #include "staticlibrary.h"
11 #include "systemlibrary.h"
16 Link::Link(Builder &b, const Executable &exe):
19 const Component &comp=exe.get_component();
21 const string &prefix=b.get_arch_prefix(exe.get_package()->get_arch());
23 //XXX Determine whether to use g++ or gcc
24 argv.push_back(prefix+"g++");
26 if(comp.get_type()==Component::LIBRARY)
27 argv.push_back("-shared");
28 else if(comp.get_package().get_library_mode()==ALL_STATIC)
29 argv.push_back("-static");
31 const BuildInfo &binfo=comp.get_build_info();
32 for(list<string>::const_iterator i=binfo.ldflags.begin(); i!=binfo.ldflags.end(); ++i)
34 for(list<string>::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
35 argv.push_back("-L"+*i);
38 argv.push_back(exe.get_name());
39 const TargetList &deps=exe.get_depends();
40 for(TargetList::const_iterator i=deps.begin(); i!=deps.end(); ++i)
43 if(dynamic_cast<Install *>(tgt))
44 tgt=tgt->get_depends().front();
46 if(dynamic_cast<ObjectFile *>(tgt))
47 argv.push_back((*i)->get_name());
48 else if(SharedLibrary *shlib=dynamic_cast<SharedLibrary *>(tgt))
49 argv.push_back("-l"+shlib->get_libname());
50 else if(dynamic_cast<StaticLibrary *>(tgt))
51 argv.push_back((*i)->get_name());
52 else if(SystemLibrary *syslib=dynamic_cast<SystemLibrary *>(tgt))
53 argv.push_back("-l"+syslib->get_libname());
56 Path::Path epath=exe.get_name();
57 if(!builder.get_dry_run())
58 Path::mkpath(epath.subpath(0, epath.size()-1), 0755);
60 announce(comp.get_package().get_name(), "LINK", relative(epath, comp.get_package().get_source()).str());