]> git.tdb.fi Git - builder.git/blob - source/component.cpp
Add an option to component to specify whether or not it should be built by default
[builder.git] / source / component.cpp
1 #include <msp/core/error.h>
2 #include "component.h"
3 #include "package.h"
4
5 using namespace std;
6
7 Component::Component(Package &p, Type t, const string &n):
8         pkg(p),
9         type(t),
10         name(n),
11         install(false),
12         module_host(0),
13         modular(false),
14         deflt(true)
15 { }
16
17 /**
18 Tries to resolve all references to packages.
19 */
20 void Component::resolve_refs()
21 {
22         for(PkgRefList::iterator i=requires.begin(); i!=requires.end(); ++i)
23                 i->resolve();
24 }
25
26 /**
27 Prepares the build information for building.
28 */
29 void Component::create_build_info()
30 {
31         build_info.add(pkg.get_build_info());
32
33         for(PkgRefList::iterator i=requires.begin(); i!=requires.end(); ++i)
34         {
35                 if(!i->get_package())
36                         continue;
37                 //i->get_package()->create_build_info();
38                 build_info.add(i->get_package()->get_exported_binfo());
39         }
40
41         if(modular)
42         {
43                 build_info.ldflags.push_back("-rdynamic");
44                 build_info.libs.push_back("dl");
45         }
46         else if(module_host)
47         {
48                 const PathList &host_src=module_host->get_sources();
49                 for(PathList::const_iterator i=host_src.begin(); i!=host_src.end(); ++i)
50                         build_info.incpath.push_back(i->str());
51         }
52
53         build_info.unique();
54 }
55
56 Component::Loader::Loader(Component &c):
57         comp(c)
58 {
59         add("source",          &Loader::source);
60         add("install",         &Component::install);
61         add("install_headers", &Component::install_headers);
62         add("build_info",      &Loader::build_info);
63         add("require",         &Loader::require);
64         add("modular",         &Loader::modular);
65         add("host",            &Loader::host);
66         add("default",         &Component::deflt);
67 }
68
69 void Component::Loader::source(const string &s)
70 {
71         comp.sources.push_back(comp.pkg.get_source()/s);
72 }
73
74 void Component::Loader::require(const string &n)
75 {
76         comp.requires.push_back(PackageRef(comp.pkg.get_builder(), n));
77 }
78
79 void Component::Loader::modular()
80 {
81         if(comp.type!=PROGRAM)
82                 throw Msp::Exception("Only programs can be modular");
83         comp.modular=true;
84 }
85
86 void Component::Loader::host(const string &n)
87 {
88         const ComponentList &comps=comp.pkg.get_components();
89         for(ComponentList::const_iterator i=comps.begin(); i!=comps.end(); ++i)
90                 if(i->get_name()==n)
91                 {
92                         if(i->get_type()!=PROGRAM || !i->get_modular())
93                                 throw Msp::Exception("Module host must be a modular program");
94                         comp.module_host=&*i;
95                         return;
96                 }
97
98         throw Msp::Exception("Unknown component");
99 }
100
101 void Component::Loader::build_info()
102 {
103         load_sub(comp.build_info);
104 }