From 75588a553c9eaaa7aa50c96c03cb7b15ffb4955b Mon Sep 17 00:00:00 2001 From: Alex Mohr Date: Fri, 1 Jan 2021 12:20:29 -0800 Subject: [PATCH] build: derive default config path from install prefix - Add `default_config_path` build option for the river executable --- build.zig | 16 ++++++++++------ river/main.zig | 4 +++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/build.zig b/build.zig index 62f4afc..494f0ce 100644 --- a/build.zig +++ b/build.zig @@ -27,13 +27,16 @@ pub fn build(b: *zbs.Builder) !void { const examples = b.option(bool, "examples", "Set to true to build examples") orelse false; - // Sigh, why are the conventions inconsistent like this. const resolved_prefix = try std.fs.path.resolve(b.allocator, &[_][]const u8{b.install_prefix.?}); - if (std.mem.eql(u8, resolved_prefix, "/usr")) { - b.installFile("example/init", "../etc/river/init"); - } else { - b.installFile("example/init", "etc/river/init"); - } + const rel_config_path = if (std.mem.eql(u8, resolved_prefix, "/usr")) + "../etc/river/init" + else + "etc/river/init"; + b.installFile("example/init", rel_config_path); + const default_config_path = try std.fs.path.resolve( + b.allocator, + &[_][]const u8{ resolved_prefix, rel_config_path }, + ); const scanner = ScanProtocolsStep.create(b); scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml"); @@ -47,6 +50,7 @@ pub fn build(b: *zbs.Builder) !void { river.setTarget(target); river.setBuildMode(mode); river.addBuildOption(bool, "xwayland", xwayland); + river.addBuildOption([]const u8, "default_config_path", default_config_path); addServerDeps(river, scanner); diff --git a/river/main.zig b/river/main.zig index d576bb2..635e30e 100644 --- a/river/main.zig +++ b/river/main.zig @@ -18,6 +18,8 @@ const std = @import("std"); const wlr = @import("wlroots"); +const build_options = @import("build_options"); + const c = @import("c.zig"); const log = @import("log.zig"); const util = @import("util.zig"); @@ -52,7 +54,7 @@ fn getStartupCommand() std.fmt.AllocPrintError!?[:0]const u8 { return path; } } - if (try testConfigPath("/etc/river/init", .{})) |path| { + if (try testConfigPath(build_options.default_config_path, .{})) |path| { return path; } return null;