]> git.tdb.fi Git - builder.git/blob - source/link.cpp
Move class PackageRef to its own files
[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, const Component &comp):
13         ExternalAction(b)
14 {
15         argv.push_back("g++");
16         
17         if(comp.get_type()==Component::LIBRARY)
18                 argv.push_back("-shared");
19
20         const BuildInfo &binfo=comp.get_build_info();
21         for(list<string>::const_iterator i=binfo.ldflags.begin(); i!=binfo.ldflags.end(); ++i)
22                 argv.push_back(*i);
23         for(list<string>::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
24                 argv.push_back("-L"+*i);
25         for(list<string>::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i)
26                 argv.push_back("-l"+*i);
27         
28         argv.push_back("-o");
29         argv.push_back(exe.get_name());
30         const list<Target *> &deps=exe.get_depends();
31         for(list<Target *>::const_iterator i=deps.begin(); i!=deps.end(); ++i)
32                 if(dynamic_cast<ObjectFile *>(*i))
33                         argv.push_back((*i)->get_name());
34
35         Path::Path epath=exe.get_name();
36         if(!builder.get_dry_run())
37                 Path::mkpath(epath.subpath(0, epath.size()-1), 0755);
38
39         announce(comp.get_package().get_name(), "LINK", relative(epath, comp.get_package().get_source()).str());
40
41         launch();
42 }