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