]> git.tdb.fi Git - builder.git/blob - source/component.h
Reimplement datafile building
[builder.git] / source / component.h
1 #ifndef COMPONENT_H_
2 #define COMPONENT_H_
3
4 #include <string>
5 #include <msp/datafile/objectloader.h>
6 #include <msp/fs/path.h>
7 #include "buildinfo.h"
8 #include "installmap.h"
9 #include "package.h"
10
11 class SourcePackage;
12
13 /**
14 Components specify things to be built.  Each component may build one binary (it
15 may also build none), as well as install a bunch of headers.  Components inherit
16 dependencies and build info from the package they belong to, and may also add
17 their own.
18 */
19 class Component
20 {
21 public:
22         class Loader: public Msp::DataFile::ObjectLoader<Component>
23         {
24         public:
25                 Loader(Component &);
26         private:
27                 void build_info();
28                 void if_arch(const std::string &);
29                 void if_feature(const std::string &);
30                 void install_map();
31                 void require(const std::string &);
32                 void source(const std::string &);
33                 void use(const std::string &);
34         };
35
36         enum Type
37         {
38                 LIBRARY,
39                 PROGRAM,
40                 MODULE,
41                 DATAPACK,
42                 INSTALL,
43                 TARBALL
44         };
45
46         typedef std::list<Msp::FS::Path> SourceList;
47         typedef std::list<const Component *> UseList;
48
49 protected:
50         SourcePackage &package;
51         Type type;
52         std::string name;
53         SourceList sources;
54         bool install;
55         BuildInfo build_info;
56         Package::Requirements requires;
57         UseList uses;
58         bool deflt;
59         InstallMap install_map;
60
61 public:
62         Component(SourcePackage &, Type, const std::string &);
63
64         const SourcePackage &get_package() const { return package; }
65         Type get_type() const { return type; }
66         const std::string &get_name() const { return name; }
67
68         /** Returns a list of sources for the component.  They may refer to
69         directories or individual files. */
70         const SourceList &get_sources() const { return sources; }
71
72 protected:
73         /** Returns a list of all source files for the component. */
74         SourceList collect_source_files() const;
75
76 public:
77         bool get_install() const { return install; }
78         const InstallMap &get_install_map() const { return install_map; }
79         const Package::Requirements &get_required_packages() const { return requires; }
80         const UseList &get_used_components() const { return uses; }
81         bool is_default() const { return deflt; }
82
83         /** Prepares any required packages. */
84         void prepare();
85
86         /** Prepares the build information for building.  Pulls build info from the
87         parent and dependency packages, and adds any component-specific flags. */
88         void create_build_info();
89
90         const BuildInfo &get_build_info() const { return build_info; }
91
92         void create_targets() const;
93 };
94
95 #endif