2020-04-12 04:37:18 -07:00
|
|
|
const std = @import("std");
|
2021-03-22 05:16:24 -07:00
|
|
|
const assert = std.debug.assert;
|
2021-03-22 03:54:02 -07:00
|
|
|
const fs = std.fs;
|
2021-03-22 05:16:24 -07:00
|
|
|
const mem = std.mem;
|
2020-11-03 15:23:21 -08:00
|
|
|
const zbs = std.build;
|
2020-03-19 08:29:22 -07:00
|
|
|
|
2020-11-02 04:59:59 -08:00
|
|
|
const ScanProtocolsStep = @import("deps/zig-wayland/build.zig").ScanProtocolsStep;
|
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
pub fn build(b: *zbs.Builder) !void {
|
2020-03-19 08:29:22 -07:00
|
|
|
const target = b.standardTargetOptions(.{});
|
|
|
|
const mode = b.standardReleaseOptions();
|
|
|
|
|
2020-05-04 02:10:23 -07:00
|
|
|
const xwayland = b.option(
|
|
|
|
bool,
|
|
|
|
"xwayland",
|
|
|
|
"Set to true to enable xwayland support",
|
|
|
|
) orelse false;
|
|
|
|
|
2020-06-15 04:16:38 -07:00
|
|
|
const man_pages = b.option(
|
|
|
|
bool,
|
|
|
|
"man-pages",
|
|
|
|
"Set to true to build man pages. Requires scdoc. Defaults to true if scdoc is found.",
|
2020-06-15 05:22:09 -07:00
|
|
|
) orelse scdoc_found: {
|
|
|
|
_ = b.findProgram(&[_][]const u8{"scdoc"}, &[_][]const u8{}) catch |err| switch (err) {
|
|
|
|
error.FileNotFound => break :scdoc_found false,
|
|
|
|
else => return err,
|
|
|
|
};
|
|
|
|
break :scdoc_found true;
|
|
|
|
};
|
2020-06-15 04:16:38 -07:00
|
|
|
|
2021-03-13 08:54:15 -08:00
|
|
|
const bash_completion = b.option(
|
|
|
|
bool,
|
|
|
|
"bash-completion",
|
|
|
|
"Set to true to install bash completion for riverctl. Defaults to true.",
|
|
|
|
) orelse true;
|
|
|
|
|
2021-03-13 08:06:39 -08:00
|
|
|
const zsh_completion = b.option(
|
|
|
|
bool,
|
|
|
|
"zsh-completion",
|
|
|
|
"Set to true to install zsh completion for riverctl. Defaults to true.",
|
|
|
|
) orelse true;
|
|
|
|
|
2021-03-16 08:16:47 -07:00
|
|
|
const fish_completion = b.option(
|
|
|
|
bool,
|
|
|
|
"fish-completion",
|
|
|
|
"Set to true to install fish completion for riverctl. Defaults to true.",
|
|
|
|
) orelse true;
|
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
const examples = b.option(bool, "examples", "Set to true to build examples") orelse false;
|
2020-11-02 04:59:59 -08:00
|
|
|
|
2021-03-22 05:16:24 -07:00
|
|
|
// This logic must match std.build.resolveInstallPrefix()
|
|
|
|
const prefix = b.install_prefix orelse if (b.dest_dir) |_| "/usr" else b.cache_root;
|
|
|
|
const rel_config_path = if (mem.eql(u8, try fs.path.resolve(b.allocator, &[_][]const u8{prefix}), "/usr"))
|
|
|
|
"../etc/river/init"
|
|
|
|
else
|
|
|
|
"etc/river/init";
|
2021-01-01 12:20:29 -08:00
|
|
|
b.installFile("example/init", rel_config_path);
|
2021-03-22 05:16:24 -07:00
|
|
|
const abs_config_path = try fs.path.resolve(b.allocator, &[_][]const u8{ prefix, rel_config_path });
|
|
|
|
assert(fs.path.isAbsolute(abs_config_path));
|
2020-12-30 11:29:28 -08:00
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
const scanner = ScanProtocolsStep.create(b);
|
|
|
|
scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml");
|
2021-02-14 10:32:04 -08:00
|
|
|
scanner.addSystemProtocol("unstable/pointer-gestures/pointer-gestures-unstable-v1.xml");
|
2021-01-17 07:30:47 -08:00
|
|
|
scanner.addSystemProtocol("unstable/xdg-output/xdg-output-unstable-v1.xml");
|
2021-02-15 12:07:29 -08:00
|
|
|
scanner.addSystemProtocol("unstable/pointer-constraints/pointer-constraints-unstable-v1.xml");
|
2020-11-02 04:59:59 -08:00
|
|
|
scanner.addProtocolPath("protocol/river-control-unstable-v1.xml");
|
2021-01-15 10:54:19 -08:00
|
|
|
scanner.addProtocolPath("protocol/river-options-unstable-v1.xml");
|
2020-11-03 15:23:21 -08:00
|
|
|
scanner.addProtocolPath("protocol/river-status-unstable-v1.xml");
|
|
|
|
scanner.addProtocolPath("protocol/wlr-layer-shell-unstable-v1.xml");
|
|
|
|
scanner.addProtocolPath("protocol/wlr-output-power-management-unstable-v1.xml");
|
2020-04-12 04:37:18 -07:00
|
|
|
|
2020-05-19 09:22:22 -07:00
|
|
|
{
|
2020-06-01 06:56:50 -07:00
|
|
|
const river = b.addExecutable("river", "river/main.zig");
|
2020-05-19 09:22:22 -07:00
|
|
|
river.setTarget(target);
|
|
|
|
river.setBuildMode(mode);
|
|
|
|
river.addBuildOption(bool, "xwayland", xwayland);
|
2021-03-22 03:54:02 -07:00
|
|
|
river.addBuildOption([]const u8, "default_config_path", abs_config_path);
|
2020-04-12 04:37:18 -07:00
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
addServerDeps(river, scanner);
|
2020-04-08 15:05:28 -07:00
|
|
|
|
2020-05-19 09:22:22 -07:00
|
|
|
river.install();
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2020-06-01 06:56:50 -07:00
|
|
|
const riverctl = b.addExecutable("riverctl", "riverctl/main.zig");
|
2020-05-19 09:22:22 -07:00
|
|
|
riverctl.setTarget(target);
|
|
|
|
riverctl.setBuildMode(mode);
|
|
|
|
|
2020-11-02 04:59:59 -08:00
|
|
|
riverctl.step.dependOn(&scanner.step);
|
|
|
|
riverctl.addPackage(scanner.getPkg());
|
2020-05-19 09:22:22 -07:00
|
|
|
riverctl.linkLibC();
|
|
|
|
riverctl.linkSystemLibrary("wayland-client");
|
|
|
|
|
2020-11-02 04:59:59 -08:00
|
|
|
scanner.addCSource(riverctl);
|
|
|
|
|
2020-05-19 09:22:22 -07:00
|
|
|
riverctl.install();
|
|
|
|
}
|
|
|
|
|
2020-06-16 05:48:30 -07:00
|
|
|
{
|
|
|
|
const rivertile = b.addExecutable("rivertile", "rivertile/main.zig");
|
|
|
|
rivertile.setTarget(target);
|
|
|
|
rivertile.setBuildMode(mode);
|
|
|
|
rivertile.install();
|
|
|
|
}
|
|
|
|
|
2020-06-15 05:22:09 -07:00
|
|
|
if (man_pages) {
|
2020-06-15 04:16:38 -07:00
|
|
|
const scdoc_step = ScdocStep.create(b);
|
|
|
|
try scdoc_step.install();
|
|
|
|
}
|
|
|
|
|
2021-03-13 08:54:15 -08:00
|
|
|
if (bash_completion) {
|
|
|
|
b.installFile(
|
|
|
|
"completions/bash/riverctl",
|
|
|
|
"share/bash-completion/completions/riverctl",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-03-13 08:06:39 -08:00
|
|
|
if (zsh_completion) {
|
|
|
|
b.installFile(
|
|
|
|
"completions/zsh/_riverctl",
|
|
|
|
"share/zsh/site-functions/_riverctl",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-03-16 08:16:47 -07:00
|
|
|
if (fish_completion) {
|
|
|
|
b.installFile(
|
|
|
|
"completions/fish/riverctl.fish",
|
|
|
|
"share/fish/vendor_completions.d/riverctl.fish",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-06-04 15:24:17 -07:00
|
|
|
if (examples) {
|
2021-01-15 10:54:19 -08:00
|
|
|
inline for (.{ "status", "options" }) |example_name| {
|
|
|
|
const example = b.addExecutable(example_name, "example/" ++ example_name ++ ".zig");
|
|
|
|
example.setTarget(target);
|
|
|
|
example.setBuildMode(mode);
|
2020-06-04 15:24:17 -07:00
|
|
|
|
2021-01-15 10:54:19 -08:00
|
|
|
example.step.dependOn(&scanner.step);
|
|
|
|
example.addPackage(scanner.getPkg());
|
|
|
|
example.linkLibC();
|
|
|
|
example.linkSystemLibrary("wayland-client");
|
2020-06-04 15:24:17 -07:00
|
|
|
|
2021-01-15 10:54:19 -08:00
|
|
|
scanner.addCSource(example);
|
2020-11-03 15:23:21 -08:00
|
|
|
|
2021-01-15 10:54:19 -08:00
|
|
|
example.install();
|
|
|
|
}
|
2020-06-04 15:24:17 -07:00
|
|
|
}
|
|
|
|
|
2020-05-19 09:22:22 -07:00
|
|
|
{
|
2020-06-01 06:56:50 -07:00
|
|
|
const river_test = b.addTest("river/test_main.zig");
|
2020-05-19 09:22:22 -07:00
|
|
|
river_test.setTarget(target);
|
|
|
|
river_test.setBuildMode(mode);
|
|
|
|
river_test.addBuildOption(bool, "xwayland", xwayland);
|
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
addServerDeps(river_test, scanner);
|
2020-05-19 09:22:22 -07:00
|
|
|
|
|
|
|
const test_step = b.step("test", "Run the tests");
|
|
|
|
test_step.dependOn(&river_test.step);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
fn addServerDeps(exe: *zbs.LibExeObjStep, scanner: *ScanProtocolsStep) void {
|
|
|
|
const wayland = scanner.getPkg();
|
|
|
|
const xkbcommon = zbs.Pkg{ .name = "xkbcommon", .path = "deps/zig-xkbcommon/src/xkbcommon.zig" };
|
|
|
|
const pixman = zbs.Pkg{ .name = "pixman", .path = "deps/zig-pixman/pixman.zig" };
|
|
|
|
const wlroots = zbs.Pkg{
|
|
|
|
.name = "wlroots",
|
|
|
|
.path = "deps/zig-wlroots/src/wlroots.zig",
|
|
|
|
.dependencies = &[_]zbs.Pkg{ wayland, xkbcommon, pixman },
|
|
|
|
};
|
|
|
|
|
|
|
|
exe.step.dependOn(&scanner.step);
|
2020-04-03 09:53:36 -07:00
|
|
|
|
2020-04-12 04:54:03 -07:00
|
|
|
exe.linkLibC();
|
2020-08-24 05:52:47 -07:00
|
|
|
exe.linkSystemLibrary("libevdev");
|
2020-04-12 04:37:18 -07:00
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
exe.addPackage(wayland);
|
|
|
|
exe.linkSystemLibrary("wayland-server");
|
2020-04-12 04:37:18 -07:00
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
exe.addPackage(xkbcommon);
|
|
|
|
exe.linkSystemLibrary("xkbcommon");
|
2020-04-12 04:37:18 -07:00
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
exe.addPackage(pixman);
|
|
|
|
exe.linkSystemLibrary("pixman-1");
|
2020-04-12 04:37:18 -07:00
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
exe.addPackage(wlroots);
|
|
|
|
exe.linkSystemLibrary("wlroots");
|
2020-05-19 09:22:22 -07:00
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
// TODO: remove when zig issue #131 is implemented
|
|
|
|
scanner.addCSource(exe);
|
|
|
|
}
|
2020-06-15 04:16:38 -07:00
|
|
|
|
|
|
|
const ScdocStep = struct {
|
|
|
|
const scd_paths = [_][]const u8{
|
|
|
|
"doc/river.1.scd",
|
|
|
|
"doc/riverctl.1.scd",
|
2020-06-16 08:06:24 -07:00
|
|
|
"doc/rivertile.1.scd",
|
2020-06-17 01:39:48 -07:00
|
|
|
"doc/river-layouts.7.scd",
|
2020-06-15 04:16:38 -07:00
|
|
|
};
|
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
builder: *zbs.Builder,
|
|
|
|
step: zbs.Step,
|
2020-06-15 04:16:38 -07:00
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
fn create(builder: *zbs.Builder) *ScdocStep {
|
2020-07-05 13:49:17 -07:00
|
|
|
const self = builder.allocator.create(ScdocStep) catch @panic("out of memory");
|
2020-06-15 04:16:38 -07:00
|
|
|
self.* = init(builder);
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
fn init(builder: *zbs.Builder) ScdocStep {
|
2020-06-15 04:16:38 -07:00
|
|
|
return ScdocStep{
|
|
|
|
.builder = builder,
|
2020-11-03 15:23:21 -08:00
|
|
|
.step = zbs.Step.init(.Custom, "Generate man pages", builder.allocator, make),
|
2020-06-15 04:16:38 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
fn make(step: *zbs.Step) !void {
|
2020-06-15 04:16:38 -07:00
|
|
|
const self = @fieldParentPtr(ScdocStep, "step", step);
|
|
|
|
for (scd_paths) |path| {
|
|
|
|
const command = try std.fmt.allocPrint(
|
|
|
|
self.builder.allocator,
|
|
|
|
"scdoc < {} > {}",
|
|
|
|
.{ path, path[0..(path.len - 4)] },
|
|
|
|
);
|
|
|
|
_ = try self.builder.exec(&[_][]const u8{ "sh", "-c", command });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn install(self: *ScdocStep) !void {
|
|
|
|
self.builder.getInstallStep().dependOn(&self.step);
|
|
|
|
|
|
|
|
for (scd_paths) |path| {
|
|
|
|
const path_no_ext = path[0..(path.len - 4)];
|
2021-03-22 03:54:02 -07:00
|
|
|
const basename_no_ext = fs.path.basename(path_no_ext);
|
2020-06-15 04:16:38 -07:00
|
|
|
const section = path_no_ext[(path_no_ext.len - 1)..];
|
|
|
|
|
|
|
|
const output = try std.fmt.allocPrint(
|
|
|
|
self.builder.allocator,
|
|
|
|
"share/man/man{}/{}",
|
|
|
|
.{ section, basename_no_ext },
|
|
|
|
);
|
|
|
|
|
|
|
|
self.builder.installFile(path_no_ext, output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|