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