]> git.tdb.fi Git - builder.git/blob - source/builder.h
Reorder class members
[builder.git] / source / builder.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 BUILDER_H_
9 #define BUILDER_H_
10
11 #include <list>
12 #include <map>
13 #include <string>
14 #include <msp/core/application.h>
15 #include <msp/datafile/loader.h>
16 #include <msp/fs/path.h>
17 #include "architecture.h"
18 #include "config.h"
19 #include "misc.h"
20 #include "problem.h"
21 #include "target.h"
22
23 class Analyzer;
24 class Config;
25 class Package;
26 class SourcePackage;
27
28 /**
29 The main application class.  Controls and owns everything.  Rules the world.
30 */
31 class Builder: public Msp::Application
32 {
33 private:
34         class Loader: public Msp::DataFile::Loader
35         {
36         private:
37                 Builder &bld;
38                 Msp::FS::Path src;
39
40         public:
41                 Loader(Builder &, const Msp::FS::Path &);
42         private:
43                 void architecture(const std::string &);
44                 void binpkg(const std::string &);
45                 void profile(const std::string &);
46                 void package(const std::string &);
47         };
48
49         class ProfileLoader: public Msp::DataFile::Loader
50         {
51         private:
52                 StringMap &profile;
53
54         public:
55                 ProfileLoader(StringMap &);
56         private:
57                 void option(const std::string &, const std::string &);
58         };
59
60         typedef std::list<Package *> PackageList;
61         typedef std::map<std::string, Package *> PackageMap;
62         typedef std::map<std::string, StringMap> ProfileTemplateMap;
63
64         StringList cmdline_targets;
65         StringMap cmdline_options;
66         Msp::FS::Path cwd;
67
68         PackageMap packages;
69         SourcePackage *main_pkg;
70         PathList pkg_path;
71         PathList pkg_dirs;
72
73         TargetMap targets;
74         TargetList new_tgts;
75         TargetMap includes;
76         TargetMap libraries;
77
78         ArchMap archs;
79         Architecture *native_arch;
80         const Architecture *current_arch;
81         ProfileTemplateMap profile_tmpl;
82
83         ProblemList problems;
84         Analyzer *analyzer;
85         bool build;
86         unsigned clean;
87         bool dry_run;
88         bool help;
89         unsigned verbose;
90         bool show_progress;
91         std::string build_file;
92         unsigned jobs;
93         StringList what_if;
94         bool conf_all;
95         bool conf_only;
96         bool build_all;
97         bool create_makefile;
98         Msp::FS::Path prefix;
99         StringList warnings;
100
101         static Msp::Application::RegApp<Builder> reg;
102
103 public:
104         Builder(int, char **);
105         ~Builder();
106
107         int main();
108         unsigned get_verbose() const { return verbose; }
109         bool get_dry_run() const { return dry_run; }
110         bool get_build_all() const { return build_all; }
111
112         /** Gets a package by name, possibly creating it.  Returns 0 if the package
113         could not be located. */
114         Package *get_package(const std::string &);
115
116         SourcePackage *get_main_package() const { return main_pkg; }
117
118         /** Looks up a target by name.  Returns 0 if no such target exists. */
119         Target *get_target(const std::string &) const;
120
121         const TargetMap &get_targets() const { return targets; }
122
123         /** Tries to locate a header based on location of including file and include
124         path.  Considers known targets as well as existing files.  If a matching
125         target is not found but a file exists, a new SystemHeader target will be
126         created and returned. */
127         Target *get_header(const std::string &, const std::string &, const StringList &);
128
129         /** Tries to locate a library in a library path.  The library name should be
130         the same as would be given to the linker with -l, i.e. without the "lib"
131         prefix or extension.  Considers known targets as well as existing files.  If
132         a matching target is not found but a file exists, a new SystemLibrary target
133         will be created and returned. */
134         Target *get_library(const std::string &, const StringList &, LibMode);
135
136         const Msp::FS::Path &get_cwd() const { return cwd; }
137         const Architecture &get_architecture(const std::string &) const;
138         const Architecture &get_current_arch() const { return *current_arch; }
139         const Architecture &get_native_arch() const { return *native_arch; }
140         const Msp::FS::Path &get_prefix() const { return prefix; }
141         const StringList &get_warnings() const { return warnings; }
142         void apply_profile_template(Config &, const std::string &) const;
143
144         /** Adds a target to both the target map and the new target queue.  Called
145         from Target constructor. */
146         void add_target(Target *);
147
148         void problem(const std::string &, const std::string &);
149
150         static void usage(const char *, const char *, bool);
151
152 private:
153         /** Determines the source directory of a package.  Pkg-config is consulted
154         first, and if it fails, the package path is searched for matches. */
155         Msp::FS::Path get_package_location(const std::string &);
156
157         /** Loads a build file.  Returns 0 on success or -1 if the file could not be
158         opened. */
159         int load_build_file(const Msp::FS::Path &);
160
161         /** Creates targets for all packages and prepares them for building.
162         Returns 0 if everything went ok, -1 if something bad happened and a build
163         shouldn't be attempted. */
164         int create_targets();
165
166         /**
167         Check if a header exists, either as a target or a file.  Returns an existing
168         target of one was found, or a new SystemHeader target if there was no known
169         target but the file exists.
170         */
171         Target *get_header(const Msp::FS::Path &);
172
173         Target *get_library(const std::string &, const Msp::FS::Path &, LibMode);
174
175         /** Supervises the build process, starting new actions when slots become
176         available. */
177         int do_build();
178
179         /** Cleans buildable targets.  If clean is 1, cleans only the default
180         package.  If clean is 2 or greater, cleans all buildable packages.
181         */
182         int do_clean();
183
184         int do_create_makefile();
185
186         /** Prints out information about the default package. */
187         void package_help();
188 };
189
190 #endif