]> git.tdb.fi Git - builder.git/blob - source/link.cpp
Add basic support for tools (not configurable yet)
[builder.git] / source / link.cpp
1 #include <msp/path/utils.h>
2 #include "builder.h"
3 #include "component.h"
4 #include "executable.h"
5 #include "install.h"
6 #include "link.h"
7 #include "objectfile.h"
8 #include "package.h"
9 #include "sharedlibrary.h"
10 #include "staticlibrary.h"
11 #include "systemlibrary.h"
12
13 using namespace std;
14 using namespace Msp;
15
16 Link::Link(Builder &b, const Executable &exe):
17         ExternalAction(b)
18 {
19         const Component &comp=exe.get_component();
20
21         //XXX Determine whether to use g++ or gcc
22         argv.push_back(builder.get_tool("LDXX", exe.get_package()->get_arch()));
23         
24         if(comp.get_type()==Component::LIBRARY || comp.get_type()==Component::MODULE)
25                 argv.push_back("-shared");
26         else if(comp.get_package().get_library_mode()==ALL_STATIC)
27                 argv.push_back("-static");
28
29         const BuildInfo &binfo=comp.get_build_info();
30         for(list<string>::const_iterator i=binfo.ldflags.begin(); i!=binfo.ldflags.end(); ++i)
31                 argv.push_back(*i);
32         for(list<string>::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
33                 argv.push_back("-L"+*i);
34         
35         argv.push_back("-o");
36         argv.push_back(exe.get_name());
37         const TargetList &deps=exe.get_depends();
38         for(TargetList::const_iterator i=deps.begin(); i!=deps.end(); ++i)
39         {
40                 Target *tgt=*i;
41                 if(dynamic_cast<Install *>(tgt))
42                         tgt=tgt->get_depends().front();
43
44                 if(dynamic_cast<ObjectFile *>(tgt))
45                         argv.push_back((*i)->get_name());
46                 else if(SharedLibrary *shlib=dynamic_cast<SharedLibrary *>(tgt))
47                         argv.push_back("-l"+shlib->get_libname());
48                 else if(dynamic_cast<StaticLibrary *>(tgt))
49                         argv.push_back((*i)->get_name());
50                 else if(SystemLibrary *syslib=dynamic_cast<SystemLibrary *>(tgt))
51                         argv.push_back("-l"+syslib->get_libname());
52         }
53
54         Path::Path epath=exe.get_name();
55         if(!builder.get_dry_run())
56                 Path::mkpath(epath.subpath(0, epath.size()-1), 0755);
57
58         announce(comp.get_package().get_name(), "LINK", relative(epath, comp.get_package().get_source()).str());
59
60         launch();
61 }