]> git.tdb.fi Git - builder.git/blob - source/builder.h
Better way to set cross_prefix in architectures
[builder.git] / source / builder.h
1 #ifndef BUILDER_H_
2 #define BUILDER_H_
3
4 #include <list>
5 #include <map>
6 #include <string>
7 #include <msp/core/application.h>
8 #include <msp/datafile/loader.h>
9 #include <msp/fs/path.h>
10 #include "architecture.h"
11 #include "config.h"
12 #include "logger.h"
13 #include "misc.h"
14 #include "packagemanager.h"
15 #include "problem.h"
16 #include "target.h"
17 #include "toolchain.h"
18 #include "virtualfilesystem.h"
19
20 class Analyzer;
21 class Config;
22 class FileTarget;
23 class Package;
24 class SourcePackage;
25 class VirtualTarget;
26
27 /**
28 The main application class.  Controls and owns everything.  Rules the world.
29 */
30 class Builder: public Msp::RegisteredApplication<Builder>
31 {
32 private:
33         class Loader: public Msp::DataFile::ObjectLoader<Builder>
34         {
35         private:
36                 Msp::FS::Path src;
37
38         public:
39                 Loader(Builder &, const Msp::FS::Path &);
40         private:
41                 void architecture(const std::string &);
42                 void binpkg(const std::string &);
43                 void profile(const std::string &);
44                 void package(const std::string &);
45         };
46
47         class ProfileLoader: public Msp::DataFile::Loader
48         {
49         private:
50                 StringMap &profile;
51
52         public:
53                 ProfileLoader(StringMap &);
54         private:
55                 void option(const std::string &, const std::string &);
56         };
57
58 public:
59         typedef std::map<std::string, Target *> TargetMap;
60         typedef std::list<Target *> TargetList;
61
62 private:
63         typedef std::map<std::string, StringMap> ProfileTemplateMap;
64
65         StringList cmdline_targets;
66         StringMap cmdline_options;
67         Msp::FS::Path cwd;
68
69         PackageManager package_manager;
70         SourcePackage *main_pkg;
71
72         TargetMap targets;
73
74         Architecture native_arch;
75         Architecture *current_arch;
76         ProfileTemplateMap profile_tmpl;
77         Toolchain toolchain;
78         VirtualFileSystem vfs;
79         Logger logger;
80
81         ProblemList problems;
82         Analyzer *analyzer;
83         bool build;
84         unsigned clean;
85         bool dry_run;
86         bool help;
87         bool show_progress;
88         std::string build_file;
89         unsigned jobs;
90         StringList what_if;
91         bool conf_all;
92         bool conf_only;
93         bool build_all;
94         bool create_makefile;
95         Msp::FS::Path prefix;
96         StringList warnings;
97
98         static std::string usagemsg;
99         static std::string helpmsg;
100
101 public:
102         Builder(int, char **);
103         ~Builder();
104
105         int main();
106         bool get_dry_run() const { return dry_run; }
107
108         PackageManager &get_package_manager() { return package_manager; }
109         SourcePackage *get_main_package() const { return main_pkg; }
110
111         /** Looks up a target by name.  Returns 0 if no such target exists. */
112         Target *get_target(const std::string &) const;
113
114         const TargetMap &get_targets() const { return targets; }
115
116         const Msp::FS::Path &get_cwd() const { return cwd; }
117         const Architecture &get_current_arch() const { return *current_arch; }
118         const Architecture &get_native_arch() const { return native_arch; }
119         const Msp::FS::Path &get_prefix() const { return prefix; }
120         const StringList &get_warnings() const { return warnings; }
121         void apply_profile_template(Config &, const std::string &) const;
122
123         const Toolchain &get_toolchain() const { return toolchain; }
124         VirtualFileSystem &get_vfs() { return vfs; }
125         const Logger &get_logger() const { return logger; }
126
127         /** Adds a target to both the target map and the new target queue.  Called
128         from Target constructor. */
129         void add_target(Target *);
130         void register_path(const Msp::FS::Path &, FileTarget *);
131
132         void problem(const std::string &, const std::string &);
133
134         static void usage(const char *, const char *, bool);
135
136         /** Loads a build file.  Returns 0 on success or -1 if the file could not be
137         opened. */
138         int load_build_file(const Msp::FS::Path &);
139
140 private:
141         /** Creates targets for all packages and prepares them for building.
142         Returns 0 if everything went ok, -1 if something bad happened and a build
143         shouldn't be attempted. */
144         int create_targets();
145
146         /** Supervises the build process, starting new actions when slots become
147         available. */
148         int do_build();
149
150         /** Cleans buildable targets.  If clean is 1, cleans only the default
151         package.  If clean is 2 or greater, cleans all buildable packages.
152         */
153         int do_clean();
154
155         int do_create_makefile();
156
157         /** Prints out information about the default package. */
158         void package_help();
159 };
160
161 #endif