]> git.tdb.fi Git - builder.git/blob - source/builder.h
Add gcc's private library directory to ClangLinker's system path
[builder.git] / source / builder.h
1 #ifndef BUILDER_H_
2 #define BUILDER_H_
3
4 #include <map>
5 #include <string>
6 #include <msp/datafile/loader.h>
7 #include <msp/fs/path.h>
8 #include "architecture.h"
9 #include "buildgraph.h"
10 #include "buildtype.h"
11 #include "config.h"
12 #include "logger.h"
13 #include "packagemanager.h"
14 #include "target.h"
15 #include "toolchain.h"
16 #include "virtualfilesystem.h"
17
18 class FileTarget;
19 class Package;
20 class SourcePackage;
21
22 /**
23 This class ties everything else together.  It also contains code for loading
24 build files and supervising the build process.
25 */
26 class Builder
27 {
28 private:
29         class Loader: public Msp::DataFile::ObjectLoader<Builder>
30         {
31         private:
32                 const Config::InputOptions *options;
33                 bool conf_all;
34
35         public:
36                 Loader(Builder &, const Config::InputOptions * = 0, bool = false);
37                 ~Loader();
38
39         private:
40                 void architecture(const std::string &);
41                 void binpkg(const std::string &);
42                 void build_type(const std::string &);
43                 void package(const std::string &);
44         };
45
46 private:
47         PackageManager package_manager;
48
49         Architecture native_arch;
50         Architecture *current_arch = 0;
51         std::map<std::string, BuildType> build_types;
52         BuildType *build_type = 0;
53         Toolchain toolchain;
54         VirtualFileSystem vfs;
55         BuildGraph build_graph;
56         Logger default_logger;
57         const Logger *logger;
58
59         bool auto_prefix = true;
60         Msp::FS::Path prefix;
61         Msp::FS::Path tempdir = "temp";
62
63         Loader *top_loader = 0;
64
65 public:
66         Builder();
67         ~Builder();
68
69         PackageManager &get_package_manager() { return package_manager; }
70
71         void set_architecture(const std::string &);
72         const Architecture &get_current_arch() const { return *current_arch; }
73         const Architecture &get_native_arch() const { return native_arch; }
74         void set_build_type(const std::string &);
75         std::vector<std::string> get_build_types() const;
76         const BuildType &get_build_type() const;
77         BuildGraph &get_build_graph() { return build_graph; }
78         void set_prefix(const Msp::FS::Path &);
79         void set_temp_directory(const Msp::FS::Path &);
80         const Msp::FS::Path &get_prefix() const { return prefix; }
81         const Msp::FS::Path &get_temp_directory() const { return tempdir; }
82
83 private:
84         void update_auto_prefix();
85
86 public:
87         void add_default_tools();
88         const Toolchain &get_toolchain() const { return toolchain; }
89         VirtualFileSystem &get_vfs() { return vfs; }
90         void set_logger(const Logger *);
91         const Logger &get_logger() const { return *logger; }
92
93         std::vector<std::string> collect_problems() const;
94
95         /** Loads a build file.  If opts is not null, it is used to configure any
96         packages loaded from this file.  If all is true, external packages are also
97         configured. */
98         void load_build_file(const Msp::FS::Path &, const Config::InputOptions *opts = 0, bool all = false);
99
100         /** Saves package configuration and dependency caches. */
101         void save_caches();
102
103         /** Builds the goal targets.  The build graph must be prepared first. */
104         int build(unsigned jobs = 1, bool dry_run = false, bool show_progress = false);
105
106         /** Cleans buildable targets.  If all is true, cleans all packages.
107         Otherwise cleans only the default package. */
108         int clean(bool all = false, bool dry_run = false);
109
110         int do_create_makefile();
111 };
112
113 #endif