Skip to content

Commit

Permalink
zig build: adjust DESTDIR logic
Browse files Browse the repository at this point in the history
now if DESTDIR is provided then the default install prefix is /usr.
otherwise the default install prefix is still zig-cache directly.

DESTDIR is prepended to the prefix to match what make install does.
  • Loading branch information
andrewrk committed Jul 22, 2019
1 parent 77c2ac3 commit d6d0bb0
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions std/build.zig
Expand Up @@ -44,6 +44,7 @@ pub const Builder = struct {
dest_dir: ?[]const u8,
lib_dir: ?[]const u8,
exe_dir: ?[]const u8,
install_path: []const u8,
search_prefixes: ArrayList([]const u8),
installed_files: ArrayList(InstalledFile),
build_root: []const u8,
Expand Down Expand Up @@ -144,6 +145,7 @@ pub const Builder = struct {
.is_release = false,
.override_std_dir = null,
.override_lib_dir = null,
.install_path = undefined,
};
try self.top_level_steps.append(&self.install_tls);
try self.top_level_steps.append(&self.uninstall_tls);
Expand All @@ -166,14 +168,19 @@ pub const Builder = struct {
}

fn resolveInstallPrefix(self: *Builder) void {
const dest_dir = self.dest_dir orelse blk: {
const dest_dir = self.install_prefix orelse self.cache_root;
self.dest_dir = dest_dir;
break :blk dest_dir;
};
self.dest_dir = dest_dir;
self.lib_dir = fs.path.join(self.allocator, [_][]const u8{ dest_dir, "lib" }) catch unreachable;
self.exe_dir = fs.path.join(self.allocator, [_][]const u8{ dest_dir, "bin" }) catch unreachable;
if (self.dest_dir) |dest_dir| {
const install_prefix = self.install_prefix orelse "/usr";
self.install_path = fs.path.join(self.allocator, [_][]const u8{ dest_dir, install_prefix }) catch unreachable;
} else {
const install_prefix = self.install_prefix orelse blk: {
const p = self.cache_root;
self.install_prefix = p;
break :blk p;
};
self.install_path = install_prefix;
}
self.lib_dir = fs.path.join(self.allocator, [_][]const u8{ self.install_path, "lib" }) catch unreachable;
self.exe_dir = fs.path.join(self.allocator, [_][]const u8{ self.install_path, "bin" }) catch unreachable;
}

pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
Expand Down Expand Up @@ -886,7 +893,7 @@ pub const Builder = struct {

fn getInstallPath(self: *Builder, dir: InstallDir, dest_rel_path: []const u8) []const u8 {
const base_dir = switch (dir) {
.Prefix => self.dest_dir.?,
.Prefix => self.install_path,
.Bin => self.exe_dir.?,
.Lib => self.lib_dir.?,
};
Expand Down

0 comments on commit d6d0bb0

Please sign in to comment.