7 #include <msp/core/application.h>
8 #include <msp/datafile/loader.h>
9 #include <msp/fs/path.h>
10 #include "architecture.h"
24 The main application class. Controls and owns everything. Rules the world.
26 class Builder: public Msp::RegisteredApplication<Builder>
29 class Loader: public Msp::DataFile::Loader
36 Loader(Builder &, const Msp::FS::Path &);
38 void binpkg(const std::string &);
39 void cross_prefix(const std::string &, const std::string &);
40 void profile(const std::string &);
41 void package(const std::string &);
44 class ProfileLoader: public Msp::DataFile::Loader
50 ProfileLoader(StringMap &);
52 void option(const std::string &, const std::string &);
55 typedef std::list<Package *> PackageList;
56 typedef std::map<std::string, Package *> PackageMap;
57 typedef std::map<std::string, StringMap> ProfileTemplateMap;
59 StringList cmdline_targets;
60 StringMap cmdline_options;
64 SourcePackage *main_pkg;
74 Architecture native_arch;
75 Architecture *current_arch;
76 StringMap cross_prefixes;
77 ProfileTemplateMap profile_tmpl;
87 std::string build_file;
97 static std::string usagemsg;
98 static std::string helpmsg;
101 Builder(int, char **);
105 unsigned get_verbose() const { return verbose; }
106 bool get_dry_run() const { return dry_run; }
107 bool get_build_all() const { return build_all; }
109 /** Gets a package by name, possibly creating it. Returns 0 if the package
110 could not be located. */
111 Package *get_package(const std::string &);
113 SourcePackage *get_main_package() const { return main_pkg; }
115 std::string run_pkgconfig(const std::string &, const std::string &);
117 /** Looks up a target by name. Returns 0 if no such target exists. */
118 Target *get_target(const std::string &) const;
120 const TargetMap &get_targets() const { return targets; }
122 /** Tries to locate a header based on location of including file and include
123 path. Considers known targets as well as existing files. If a matching
124 target is not found but a file exists, a new SystemHeader target will be
125 created and returned. */
126 Target *get_header(const std::string &, const Msp::FS::Path &, const StringList &);
128 /** Tries to locate a library in a library path. The library name should be
129 the same as would be given to the linker with -l, i.e. without the "lib"
130 prefix or extension. Considers known targets as well as existing files. If
131 a matching target is not found but a file exists, a new SystemLibrary target
132 will be created and returned. */
133 Target *get_library(const std::string &, const StringList &, LibMode);
135 const Msp::FS::Path &get_cwd() const { return cwd; }
136 const Architecture &get_current_arch() const { return *current_arch; }
137 const Architecture &get_native_arch() const { return native_arch; }
138 const Msp::FS::Path &get_prefix() const { return prefix; }
139 const StringList &get_warnings() const { return warnings; }
140 void apply_profile_template(Config &, const std::string &) const;
142 /** Adds a target to both the target map and the new target queue. Called
143 from Target constructor. */
144 void add_target(FileTarget *);
145 void add_target(VirtualTarget *);
147 void problem(const std::string &, const std::string &);
149 static void usage(const char *, const char *, bool);
152 /** Determines the source directory of a package. Pkg-config is consulted
153 first, and if it fails, the package path is searched for matches. */
154 Msp::FS::Path get_package_location(const std::string &);
156 /** Loads a build file. Returns 0 on success or -1 if the file could not be
158 int load_build_file(const Msp::FS::Path &);
160 /** Creates targets for all packages and prepares them for building.
161 Returns 0 if everything went ok, -1 if something bad happened and a build
162 shouldn't be attempted. */
163 int create_targets();
166 Check if a header exists, either as a target or a file. Returns an existing
167 target of one was found, or a new SystemHeader target if there was no known
168 target but the file exists.
170 Target *get_header(const Msp::FS::Path &);
172 Target *get_library(const std::string &, const Msp::FS::Path &, LibMode);
174 /** Supervises the build process, starting new actions when slots become
178 /** Cleans buildable targets. If clean is 1, cleans only the default
179 package. If clean is 2 or greater, cleans all buildable packages.
183 int do_create_makefile();
185 /** Prints out information about the default package. */