7 #include <msp/core/application.h>
8 #include <msp/datafile/loader.h>
9 #include <msp/fs/path.h>
10 #include "architecture.h"
11 #include "buildtype.h"
14 #include "packagemanager.h"
17 #include "toolchain.h"
18 #include "virtualfilesystem.h"
26 The main application class. Handles command line options and supervises the
29 class Builder: public Msp::RegisteredApplication<Builder>
32 class Loader: public Msp::DataFile::ObjectLoader<Builder>
37 void architecture(const std::string &);
38 void binpkg(const std::string &);
39 void build_type(const std::string &);
40 void profile(const std::string &);
41 void package(const std::string &);
45 typedef std::map<std::string, Target *> TargetMap;
48 typedef std::list<std::string> NameList;
49 typedef std::map<std::string, BuildType> BuildTypeMap;
50 typedef std::list<Problem> ProblemList;
52 NameList cmdline_targets;
53 Config::InputOptions cmdline_options;
56 PackageManager package_manager;
57 SourcePackage *main_pkg;
61 Architecture native_arch;
62 Architecture *current_arch;
63 BuildTypeMap build_types;
64 BuildType *build_type;
66 VirtualFileSystem vfs;
76 std::string build_file;
84 Msp::FS::Path tempdir;
86 static std::string usagemsg;
87 static std::string helpmsg;
90 Builder(int, char **);
95 PackageManager &get_package_manager() { return package_manager; }
97 /** Looks up a target by name. Returns 0 if no such target exists. */
98 Target *get_target(const std::string &) const;
100 const TargetMap &get_targets() const { return targets; }
102 const Msp::FS::Path &get_work_directory() const { return cwd; }
103 const Architecture &get_current_arch() const { return *current_arch; }
104 const Architecture &get_native_arch() const { return native_arch; }
105 const Msp::FS::Path &get_prefix() const { return prefix; }
106 const Msp::FS::Path &get_temp_directory() const { return tempdir; }
108 const Toolchain &get_toolchain() const { return toolchain; }
109 VirtualFileSystem &get_vfs() { return vfs; }
110 const Logger &get_logger() const { return logger; }
112 /** Adds a target. It can later be retrieved by name. Called from Target
114 void add_target(Target *);
116 /** Adds a target that is a primary build goal. Such targets will be added
117 as dependencies of the "world" virtual target. If the target belongs to a
118 default component of the main package, it's also added to the "default"
120 void add_primary_target(Target &);
122 /** Adds a target that will be installed. A new InstalledFile target is
123 created and added as a dependency to the "install" virtual target. */
124 void add_installed_target(Target &);
126 void problem(const std::string &, const std::string &);
128 static void usage(const char *, const char *, bool);
130 /** Loads a build file. Returns 0 on success or -1 if the file could not be
132 void load_build_file(const Msp::FS::Path &);
135 /** Prepares packages and targets for building. Returns true if everything
136 went ok, or false if something bad happened and a build shouldn't be
138 bool prepare_build();
140 /** Supervises the build process, starting new tasks when slots become
144 /** Cleans buildable targets. If clean is 1, cleans only the default
145 package. If clean is 2 or greater, cleans all buildable packages.
149 int do_create_makefile();
151 /** Prints out information about the default package. */