]> git.tdb.fi Git - builder.git/blob - source/link.cpp
7cbdc03c84db1b0b7dbaaa4f96d54fcfc6935d74
[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 "link.h"
6 #include "objectfile.h"
7 #include "package.h"
8
9 using namespace std;
10 using namespace Msp;
11
12 Link::Link(Builder &b, const Executable &exe):
13         ExternalAction(b)
14 {
15         const Component &comp=exe.get_component();
16
17         //XXX Determine whether to use g++ or gcc
18         argv.push_back("g++");
19         
20         if(comp.get_type()==Component::LIBRARY)
21                 argv.push_back("-shared");
22
23         const BuildInfo &binfo=comp.get_build_info();
24         for(list<string>::const_iterator i=binfo.ldflags.begin(); i!=binfo.ldflags.end(); ++i)
25                 argv.push_back(*i);
26         for(list<string>::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
27                 argv.push_back("-L"+*i);
28         for(list<string>::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i)
29                 argv.push_back("-l"+*i);
30         
31         argv.push_back("-o");
32         argv.push_back(exe.get_name());
33         const TargetList &deps=exe.get_depends();
34         for(TargetList::const_iterator i=deps.begin(); i!=deps.end(); ++i)
35                 if(dynamic_cast<ObjectFile *>(*i))
36                         argv.push_back((*i)->get_name());
37
38         Path::Path epath=exe.get_name();
39         if(!builder.get_dry_run())
40                 Path::mkpath(epath.subpath(0, epath.size()-1), 0755);
41
42         announce(comp.get_package().get_name(), "LINK", relative(epath, comp.get_package().get_source()).str());
43
44         launch();
45 }