]> git.tdb.fi Git - builder.git/blob - source/executable.cpp
8f8c9a2dc0f2c3d35ff93b0206acc45b6befd26b
[builder.git] / source / executable.cpp
1 #include "builder.h"
2 #include "component.h"
3 #include "executable.h"
4 #include "link.h"
5 #include "objectfile.h"
6 #include "package.h"
7
8 using namespace std;
9
10 Executable::Executable(Builder &b, const Component &c, const list<ObjectFile *> &objs):
11         Target(b, &c.get_package(), generate_target_name(c)),
12         comp(c)
13 {
14         buildable=true;
15         for(list<ObjectFile *>::const_iterator i=objs.begin(); i!=objs.end(); ++i)
16                 add_depend(*i);
17 }
18
19 /**
20 Finds and adds any required libraries to the dependencies.
21 */
22 void Executable::find_depends()
23 {
24         const list<string> &libs=comp.get_build_info().libs;
25         for(list<string>::const_iterator i=libs.begin(); i!=libs.end(); ++i)
26         {
27                 Target *lib=builder.get_library(*i, comp.get_build_info().libpath);
28                 if(lib)
29                         add_depend(lib);
30         }
31
32         deps_ready=true;
33 }
34
35 Action *Executable::build()
36 {
37         return Target::build(new Link(builder, *this));;
38 }
39
40 /**
41 Returns the name for the executable.  We can't do this in the constructor since
42 we need to pass the value to the Target c'tor.
43 */
44 string Executable::generate_target_name(const Component &c)
45 {
46         string prefix,suffix;
47
48         if(c.get_type()==Component::LIBRARY)
49         {
50                 prefix="lib";
51                 suffix=".so";
52         }
53
54         return (c.get_package().get_source()/(prefix+c.get_name()+suffix)).str();
55 }