]> git.tdb.fi Git - builder.git/blob - source/component.cpp
Adjust requires to library changes
[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 { }
15
16 /**
17 Tries to resolve all references to packages.
18 */
19 void Component::resolve_refs()
20 {
21         for(PkgRefList::iterator i=requires.begin(); i!=requires.end(); ++i)
22                 i->resolve();
23 }
24
25 /**
26 Prepares the build information for building.
27 */
28 void Component::create_build_info()
29 {
30         build_info.add(pkg.get_build_info());
31
32         for(PkgRefList::iterator i=requires.begin(); i!=requires.end(); ++i)
33         {
34                 if(!i->get_package())
35                         continue;
36                 //i->get_package()->create_build_info();
37                 build_info.add(i->get_package()->get_exported_binfo());
38         }
39
40         if(modular)
41         {
42                 build_info.ldflags.push_back("-rdynamic");
43                 build_info.libs.push_back("dl");
44         }
45         else if(module_host)
46         {
47                 const PathList &host_src=module_host->get_sources();
48                 for(PathList::const_iterator i=host_src.begin(); i!=host_src.end(); ++i)
49                         build_info.incpath.push_back(i->str());
50         }
51
52         build_info.unique();
53 }
54
55 Component::Loader::Loader(Component &c):
56         comp(c)
57 {
58         add("source",          &Loader::source);
59         add("install",         &Component::install);
60         add("install_headers", &Component::install_headers);
61         add("build_info",      &Loader::build_info);
62         add("require",         &Loader::require);
63         add("modular",         &Loader::modular);
64         add("host",            &Loader::host);
65 }
66
67 void Component::Loader::source(const string &s)
68 {
69         comp.sources.push_back(comp.pkg.get_source()/s);
70 }
71
72 void Component::Loader::require(const string &n)
73 {
74         comp.requires.push_back(PackageRef(comp.pkg.get_builder(), n));
75 }
76
77 void Component::Loader::modular()
78 {
79         if(comp.type!=PROGRAM)
80                 throw Msp::Exception("Only programs can be modular");
81         comp.modular=true;
82 }
83
84 void Component::Loader::host(const string &n)
85 {
86         const ComponentList &comps=comp.pkg.get_components();
87         for(ComponentList::const_iterator i=comps.begin(); i!=comps.end(); ++i)
88                 if(i->get_name()==n)
89                 {
90                         if(i->get_type()!=PROGRAM || !i->get_modular())
91                                 throw Msp::Exception("Module host must be a modular program");
92                         comp.module_host=&*i;
93                         return;
94                 }
95
96         throw Msp::Exception("Unknown component");
97 }
98
99 void Component::Loader::build_info()
100 {
101         load_sub(comp.build_info);
102 }