1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
// file : build/install/module.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
#include <build/install/module>
#include <build/scope>
#include <build/target>
#include <build/rule>
#include <build/operation>
#include <build/diagnostics>
#include <build/config/utility>
#include <build/install/rule>
#include <build/install/utility>
#include <build/install/operation>
using namespace std;
using namespace butl;
namespace build
{
namespace install
{
// Set install.<name>.* values based on config.install.<name>.* ones
// or the defaults. If none of config.install.* values were specified,
// then we do omitted/delayed configuration. Note that we still need
// to set all the install.* values to defaults, as if we had the
// default configuration.
//
template <typename T>
static void
set_var (bool spec,
scope& r,
const char* name,
const char* var,
const T* dv)
{
string vn;
const value* cv (nullptr);
if (spec)
{
vn = "config.install.";
vn += name;
vn += var;
const variable& vr (
variable_pool.find (move (vn), &value_traits<T>::value_type));
cv = dv != nullptr
? &config::required (r, vr, *dv).first.get ()
: &config::optional (r, vr);
}
vn = "install.";
vn += name;
vn += var;
const variable& vr (
variable_pool.find (move (vn), &value_traits<T>::value_type));
value& v (r.assign (vr));
if (spec)
{
if (cv != nullptr && *cv && !cv->empty ())
v = *cv;
}
else
{
if (dv != nullptr)
v = *dv;
}
}
static void
set_dir (bool s,
scope& r,
const char* name,
const dir_path& path,
const string& fmode = string (),
const string& dmode = string (),
const string& cmd = string ())
{
set_var (s, r, name, "", path.empty () ? nullptr : &path);
set_var (s, r, name, ".mode", fmode.empty () ? nullptr : &fmode);
set_var (s, r, name, ".dir_mode", dmode.empty () ? nullptr : &dmode);
set_var (s, r, name, ".cmd", cmd.empty () ? nullptr : &cmd);
set_var<strings> (s, r, name, ".options", nullptr);
}
static rule rule_;
extern "C" void
install_init (scope& r,
scope& b,
const location& l,
unique_ptr<build::module>&,
bool first)
{
tracer trace ("install::init");
if (&r != &b)
fail (l) << "install module must be initialized in bootstrap.build";
if (!first)
{
warn (l) << "multiple install module initializations";
return;
}
const dir_path& out_root (r.path ());
level4 ([&]{trace << "for " << out_root;});
// Register the install operation.
//
r.operations.insert (install_id, install);
// Register rules.
//
{
auto& rs (b.rules);
// Register the standard alias rule for the install operation.
//
rs.insert<alias> (install_id, "alias", alias_rule::instance);
// Register our file installer rule.
//
rs.insert<file> (install_id, "install", rule_);
}
// Enter module variables.
//
// Note that the set_dir() calls below enter some more.
//
if (first)
{
variable_pool.find ("install", dir_path_type);
}
// Configuration.
//
// Note that we don't use any defaults for root -- the location
// must be explicitly specified or the installer will complain
// if and when we try to install.
//
if (first)
{
bool s (config::specified (r, "config.install"));
const string& n (as<string> (*r["project"]));
set_dir (s, r, "root", dir_path (), "", "755", "install");
set_dir (s, r, "data_root", dir_path ("root"), "644");
set_dir (s, r, "exec_root", dir_path ("root"), "755");
set_dir (s, r, "sbin", dir_path ("exec_root/sbin"));
set_dir (s, r, "bin", dir_path ("exec_root/bin"));
set_dir (s, r, "lib", dir_path ("exec_root/lib"));
set_dir (s, r, "libexec", dir_path ("exec_root/libexec/" + n));
set_dir (s, r, "data", dir_path ("data_root/share/" + n));
set_dir (s, r, "include", dir_path ("data_root/include"));
set_dir (s, r, "doc", dir_path ("data_root/share/doc/" + n));
set_dir (s, r, "man", dir_path ("data_root/share/man"));
set_dir (s, r, "man1", dir_path ("man/man1"));
}
// Configure "installability" for built-in target types.
//
path<doc> (b, dir_path ("doc")); // Install into install.doc.
path<man> (b, dir_path ("man")); // Install into install.man.
path<man1> (b, dir_path ("man1")); // Install into install.man1.
}
}
}
|