]> git.tdb.fi Git - builder.git/blob - source/package.h
Better encapsulation of config inside Package
[builder.git] / source / package.h
1 #ifndef PACKAGE_H_
2 #define PACKAGE_H_
3
4 #include <list>
5 #include <string>
6 #include <msp/parser/loader.h>
7 #include "buildinfo.h"
8 #include "component.h"
9 #include "config.h"
10 #include "packageref.h"
11
12 class Builder;
13 class Package;
14
15 typedef std::list<Package *> PackageList;
16
17 /**
18 A package is a distributable piece of software.  They consist of one or more
19 Components and may depend on other packages.  Packages also have configuration
20 to determine where files are installed and which features to include (features
21 NYI).
22 */
23 class Package
24 {
25 public:
26         enum InstallFlags
27         {
28                 INCLUDE=1,
29                 BIN=2,
30                 LIB=4,
31                 DATA=8
32         };
33
34         /// Loads a package from a file.
35         class Loader: public Msp::Parser::Loader
36         {
37         public:
38                 Loader(Package &);
39                 Package &get_object() { return pkg; }
40         private:
41                 Package &pkg;
42                 
43                 void require(const std::string &);
44                 void program(const std::string &);
45                 void library(const std::string &);
46                 void headers(const std::string &);
47                 void build_info();
48         };
49
50         Package(Builder &, const std::string &, const Msp::Path::Path &);
51         void                set_path(const Msp::Path::Path &);
52         const std::string   &get_name() const           { return name; }
53         const std::string   &get_version() const        { return version; }
54         const std::string   &get_description() const    { return description; }
55         const Msp::Path::Path &get_source() const       { return source; }
56         Msp::Path::Path     get_temp_dir() const;
57         Msp::Path::Path     get_out_dir() const;
58         Msp::Path::Path     get_prefix() const          { return config.get_option("prefix").value; }
59         const ComponentList &get_components() const     { return components; }
60         bool                get_buildable() const       { return buildable; }
61         const Config        &get_config() const         { return config; }
62         const PkgRefList    &get_requires() const       { return requires; }
63         const BuildInfo     &get_build_info() const     { return build_info; }
64         const BuildInfo     &get_exported_binfo() const { return export_binfo; }
65         Builder             &get_builder() const        { return builder; }
66         bool                get_need_path() const       { return need_path; }
67         unsigned            get_install_flags();
68         bool                get_use_pkgconfig() const   { return use_pkgconfig; }
69         const std::string   &get_arch() const           { return config.get_option("arch").value; }
70         LibMode             get_library_mode() const;
71         void                resolve_refs();
72         void                configure(const RawOptionMap &, unsigned);
73
74         static Package *create(Builder &, const std::string &);
75 private:
76         Builder       &builder;
77         
78         std::string   name;
79         std::string   version;
80         std::string   description;
81         
82         bool          buildable;
83         Msp::Path::Path source;
84         PkgRefList    requires;
85         PackageList   all_reqs;
86         BuildInfo     build_info;
87         BuildInfo     export_binfo;
88         ComponentList components;
89         Config        config;
90         bool          conf_done;
91
92         bool          use_pkgconfig;
93         bool          need_path;
94         Msp::Path::Path path;
95
96         Package(Builder &, const std::string &, const std::vector<std::string> &);
97         void     init_config();
98         void     create_build_info();
99 };
100
101 #endif