]> git.tdb.fi Git - builder.git/blob - source/builder.h
4811493e005e649dcaeba5f24c89f976a880454d
[builder.git] / source / builder.h
1 /* $Id$
2
3 This file is part of builder
4 Copyright © 2006-2007 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/path/path.h>
17 #include "config.h"
18 #include "misc.h"
19 #include "problem.h"
20 #include "target.h"
21
22 class Analyzer;
23 class Config;
24 class Package;
25 class SourcePackage;
26
27 /**
28 The main application class.  Controls and owns everything.  Rules the world.
29 */
30 class Builder: public Msp::Application
31 {
32 public:
33         Builder(int, char **);
34         unsigned get_verbose() const   { return verbose; }
35         bool     get_dry_run() const   { return dry_run; }
36         bool     get_build_all() const { return build_all; }
37         Package  *get_package(const std::string &);
38         SourcePackage *get_main_package() const { return main_pkg; }
39         Target   *get_target(const std::string &) const;
40         const TargetMap &get_targets() const { return targets; }
41         Target   *get_header(const std::string &, const std::string &, const std::string &, const StringList &);
42         Target   *get_library(const std::string &, const std::string &, const StringList &, LibMode);
43         const Msp::Path::Path &get_cwd() const { return cwd; }
44         const std::string &get_arch_prefix(const std::string &) const;
45         std::string get_tool(const std::string &, const std::string &);
46         void     apply_profile_template(Config &, const std::string &) const;
47         void     add_target(Target *);
48         void     problem(const std::string &, const std::string &);
49         int      main();
50         ~Builder();
51
52         static void usage(const char *, const char *, bool);
53 private:
54         class Loader: public Msp::DataFile::Loader
55         {
56         public:
57                 Loader(Builder &, const Msp::Path::Path &);
58         private:
59                 Builder         &bld;
60                 Msp::Path::Path src;
61
62                 void architecture(const std::string &, const std::string &);
63                 void binpkg(const std::string &);
64                 void profile(const std::string &);
65                 void package(const std::string &);
66         };
67
68         class ProfileLoader: public Msp::DataFile::Loader
69         {
70         public:
71                 ProfileLoader(StringMap &);
72         private:
73                 StringMap &profile;
74
75                 void option(const std::string &, const std::string &);
76         };
77
78         typedef std::list<Package *>               PackageList;
79         typedef std::map<std::string, Package *>   PackageMap;
80         typedef std::map<std::string, StringMap>   ToolMap;
81         typedef std::map<std::string, StringMap>   ProfileTemplateMap;
82
83         StringList   cmdline_targets;
84         StringMap    cmdline_options;
85         Msp::Path::Path cwd;
86
87         PackageMap   packages;
88         SourcePackage *main_pkg;
89
90         TargetMap    targets;
91         TargetList   new_tgts;
92         TargetMap    includes;
93         TargetMap    libraries;
94
95         ToolMap      tools;    //< arch, tool name -> program name
96         StringMap    archs;    //< arch -> prefix
97         ProfileTemplateMap profile_tmpl;
98
99         ProblemList     problems;
100         Analyzer        *analyzer;
101         bool            build;
102         unsigned        clean;
103         bool            dry_run;
104         bool            help;
105         unsigned        verbose;
106         bool            chrome;
107         std::string     build_file;
108         unsigned        jobs;
109         StringList      what_if;
110         bool            conf_all;
111         bool            conf_only;
112         bool            build_all;
113         bool            create_makefile;
114
115         int    load_build_file(const Msp::Path::Path &);
116         int    create_targets();
117         Target *get_header(const Msp::Path::Path &);
118         Target *get_library(const std::string &, const std::string &, const Msp::Path::Path &, LibMode);
119         void   update_hash(std::string &, const std::string &);
120         int    do_build();
121         int    do_clean();
122         int    do_create_makefile();
123         void   package_help();
124
125         static Msp::Application::RegApp<Builder> reg;
126 };
127
128 #endif