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