authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-07-21 18:04:23-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-07-21 18:04:23-04:00
log77c2ac3fcd27b114b0068d3b64b3d884aa71e4ef
tree380d6bc5c3d2f352dc5fbe95246c7c623e8f2b42
parentf429f4dcabec2324b76b900f5785204897ea7685
signaturelock-open Commit is signed but in an unrecognized format.

zig build: support DESTDIR environment variable

closes #2929

1 files changed, 12 insertions(+), 10 deletions(-)

std/build.zig+12-10
......@@ -41,9 +41,10 @@ pub const Builder = struct {
4141 env_map: *BufMap,
4242 top_level_steps: ArrayList(*TopLevelStep),
4343 install_prefix: ?[]const u8,
44 search_prefixes: ArrayList([]const u8),
44 dest_dir: ?[]const u8,
4545 lib_dir: ?[]const u8,
4646 exe_dir: ?[]const u8,
47 search_prefixes: ArrayList([]const u8),
4748 installed_files: ArrayList(InstalledFile),
4849 build_root: []const u8,
4950 cache_root: []const u8,
......@@ -125,10 +126,11 @@ pub const Builder = struct {
125126 .top_level_steps = ArrayList(*TopLevelStep).init(allocator),
126127 .default_step = undefined,
127128 .env_map = env_map,
128 .install_prefix = null,
129129 .search_prefixes = ArrayList([]const u8).init(allocator),
130 .install_prefix = null,
130131 .lib_dir = null,
131132 .exe_dir = null,
133 .dest_dir = env_map.get("DESTDIR"),
132134 .installed_files = ArrayList(InstalledFile).init(allocator),
133135 .install_tls = TopLevelStep{
134136 .step = Step.initNoOp("install", allocator),
......@@ -164,14 +166,14 @@ pub const Builder = struct {
164166 }
165167
166168 fn resolveInstallPrefix(self: *Builder) void {
167 const prefix = if (self.install_prefix) |prefix| prefix else blk: {
168 const prefix = self.cache_root;
169 self.install_prefix = prefix;
170 break :blk prefix;
169 const dest_dir = self.dest_dir orelse blk: {
170 const dest_dir = self.install_prefix orelse self.cache_root;
171 self.dest_dir = dest_dir;
172 break :blk dest_dir;
171173 };
172
173 self.lib_dir = fs.path.join(self.allocator, [_][]const u8{ prefix, "lib" }) catch unreachable;
174 self.exe_dir = fs.path.join(self.allocator, [_][]const u8{ prefix, "bin" }) catch unreachable;
174 self.dest_dir = dest_dir;
175 self.lib_dir = fs.path.join(self.allocator, [_][]const u8{ dest_dir, "lib" }) catch unreachable;
176 self.exe_dir = fs.path.join(self.allocator, [_][]const u8{ dest_dir, "bin" }) catch unreachable;
175177 }
176178
177179 pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
......@@ -884,7 +886,7 @@ pub const Builder = struct {
884886
885887 fn getInstallPath(self: *Builder, dir: InstallDir, dest_rel_path: []const u8) []const u8 {
886888 const base_dir = switch (dir) {
887 .Prefix => self.install_prefix.?,
889 .Prefix => self.dest_dir.?,
888890 .Bin => self.exe_dir.?,
889891 .Lib => self.lib_dir.?,
890892 };