]> git.tdb.fi Git - builder.git/blob - source/component.h
b1b6aea994d3142ceb89f33dc3afb2c770c0790f
[builder.git] / source / component.h
1 /* $Id$
2
3 This file is part of builder
4 Copyright © 2006-2009  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #ifndef COMPONENT_H_
9 #define COMPONENT_H_
10
11 #include <string>
12 #include <msp/datafile/loader.h>
13 #include <msp/fs/path.h>
14 #include "buildinfo.h"
15 #include "misc.h"
16 #include "package.h"
17
18 class SourcePackage;
19
20 /**
21 Components specify things to be built.  Each component may build one binary (it
22 may also build none), as well as install a bunch of headers.  Components inherit
23 dependencies and build info from the package they belong to, and may also add
24 their own.
25 */
26 class Component
27 {
28 public:
29         class Loader: public Msp::DataFile::Loader
30         {
31         private:
32                 Component &comp;
33                 std::string inst_hdr;
34
35         public:
36                 Loader(Component &);
37                 Component &get_object() { return comp; }
38         private:
39                 virtual void finish();
40                 void source(const std::string &);
41                 void require(const std::string &);
42                 void modular();
43                 void host(const std::string &);
44                 void install_headers(const std::string &);
45                 void build_info();
46         };
47
48         enum Type
49         {
50                 HEADERS,
51                 PROGRAM,
52                 LIBRARY,
53                 MODULE,
54                 TARBALL
55         };
56
57 protected:
58         SourcePackage &pkg;
59         Type type;
60         std::string name;
61         PathList sources;
62         bool install;
63         const Component *module_host;
64         bool modular;
65         BuildInfo build_info;
66         PackageList requires;
67         bool deflt;
68
69 public:
70         Component(SourcePackage &, Type, const std::string &);
71         const SourcePackage &get_package() const { return pkg; }
72         Type get_type() const { return type; }
73         const std::string &get_name() const { return name; }
74         const PathList &get_sources() const { return sources; }
75         const BuildInfo &get_build_info() const { return build_info; }
76         bool get_install() const { return install; }
77         bool get_modular() const { return modular; }
78         const PackageList &get_requires() const { return requires; }
79         bool get_default() const { return deflt; }
80
81         /** Prepares the build information for building.  Pulls build info from the
82         parent and dependency packages, and adds any component-specific flags. */
83         void create_build_info();
84
85         void create_targets() const;
86
87 protected:
88         /** Returns a list of all source files for the component. */
89         PathList collect_source_files() const;
90 };
91
92 typedef std::list<Component> ComponentList;
93
94 #endif