3 This file is part of builder
4 Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
14 #include <msp/core/application.h>
15 #include <msp/datafile/loader.h>
16 #include <msp/fs/path.h>
17 #include "architecture.h"
29 The main application class. Controls and owns everything. Rules the world.
31 class Builder: public Msp::Application
34 class Loader: public Msp::DataFile::Loader
41 Loader(Builder &, const Msp::FS::Path &);
43 void architecture(const std::string &);
44 void binpkg(const std::string &);
45 void profile(const std::string &);
46 void package(const std::string &);
49 class ProfileLoader: public Msp::DataFile::Loader
55 ProfileLoader(StringMap &);
57 void option(const std::string &, const std::string &);
60 typedef std::list<Package *> PackageList;
61 typedef std::map<std::string, Package *> PackageMap;
62 typedef std::map<std::string, StringMap> ProfileTemplateMap;
64 StringList cmdline_targets;
65 StringMap cmdline_options;
69 SourcePackage *main_pkg;
79 Architecture *native_arch;
80 const Architecture *current_arch;
81 ProfileTemplateMap profile_tmpl;
91 std::string build_file;
101 static Msp::Application::RegApp<Builder> reg;
102 static std::string usagemsg;
103 static std::string helpmsg;
106 Builder(int, char **);
110 unsigned get_verbose() const { return verbose; }
111 bool get_dry_run() const { return dry_run; }
112 bool get_build_all() const { return build_all; }
114 /** Gets a package by name, possibly creating it. Returns 0 if the package
115 could not be located. */
116 Package *get_package(const std::string &);
118 SourcePackage *get_main_package() const { return main_pkg; }
120 /** Looks up a target by name. Returns 0 if no such target exists. */
121 Target *get_target(const std::string &) const;
123 const TargetMap &get_targets() const { return targets; }
125 /** Tries to locate a header based on location of including file and include
126 path. Considers known targets as well as existing files. If a matching
127 target is not found but a file exists, a new SystemHeader target will be
128 created and returned. */
129 Target *get_header(const std::string &, const Msp::FS::Path &, const StringList &);
131 /** Tries to locate a library in a library path. The library name should be
132 the same as would be given to the linker with -l, i.e. without the "lib"
133 prefix or extension. Considers known targets as well as existing files. If
134 a matching target is not found but a file exists, a new SystemLibrary target
135 will be created and returned. */
136 Target *get_library(const std::string &, const StringList &, LibMode);
138 const Msp::FS::Path &get_cwd() const { return cwd; }
139 const Architecture &get_architecture(const std::string &) const;
140 const Architecture &get_current_arch() const { return *current_arch; }
141 const Architecture &get_native_arch() const { return *native_arch; }
142 const Msp::FS::Path &get_prefix() const { return prefix; }
143 const StringList &get_warnings() const { return warnings; }
144 void apply_profile_template(Config &, const std::string &) const;
146 /** Adds a target to both the target map and the new target queue. Called
147 from Target constructor. */
148 void add_target(Target *);
150 void problem(const std::string &, const std::string &);
152 static void usage(const char *, const char *, bool);
155 /** Determines the source directory of a package. Pkg-config is consulted
156 first, and if it fails, the package path is searched for matches. */
157 Msp::FS::Path get_package_location(const std::string &);
159 /** Loads a build file. Returns 0 on success or -1 if the file could not be
161 int load_build_file(const Msp::FS::Path &);
163 /** Creates targets for all packages and prepares them for building.
164 Returns 0 if everything went ok, -1 if something bad happened and a build
165 shouldn't be attempted. */
166 int create_targets();
169 Check if a header exists, either as a target or a file. Returns an existing
170 target of one was found, or a new SystemHeader target if there was no known
171 target but the file exists.
173 Target *get_header(const Msp::FS::Path &);
175 Target *get_library(const std::string &, const Msp::FS::Path &, LibMode);
177 /** Supervises the build process, starting new actions when slots become
181 /** Cleans buildable targets. If clean is 1, cleans only the default
182 package. If clean is 2 or greater, cleans all buildable packages.
186 int do_create_makefile();
188 /** Prints out information about the default package. */