tony / oxwm

Branch: 767ae8e
Switch branches/tags
master
tonybanters Removed uninstall duplicate from build.zig 767ae8e 2026-02-16
140 lines · 5.2 KB Raw Blame History
1 const std = @import("std");
2
3 pub fn build(b: *std.Build) void {
4 const target = b.standardTargetOptions(.{});
5 const optimize = b.standardOptimizeOption(.{});
6
7 const exe = b.addExecutable(.{
8 .name = "oxwm",
9 .root_module = b.createModule(.{
10 .root_source_file = b.path("src/main.zig"),
11 .target = target,
12 .optimize = optimize,
13 }),
14 });
15
16 exe.linkSystemLibrary("lua5.4");
17 exe.linkSystemLibrary("X11");
18 exe.linkSystemLibrary("Xinerama");
19 exe.linkSystemLibrary("Xft");
20 exe.linkSystemLibrary("fontconfig");
21 exe.linkLibC();
22
23 b.installArtifact(exe);
24
25 const run_step = b.step("run", "Run oxwm");
26 const run_cmd = b.addRunArtifact(exe);
27 run_step.dependOn(&run_cmd.step);
28 run_cmd.step.dependOn(b.getInstallStep());
29 if (b.args) |args| {
30 run_cmd.addArgs(args);
31 }
32
33 const test_step = b.step("test", "Run unit tests");
34 const unit_tests = b.addTest(.{
35 .root_module = b.createModule(.{
36 .root_source_file = b.path("tests/main_tests.zig"),
37 .target = target,
38 .optimize = optimize,
39 }),
40 });
41 test_step.dependOn(&b.addRunArtifact(unit_tests).step);
42
43 const src_main_unit_tests = b.addTest(.{
44 .root_module = b.createModule(.{
45 .root_source_file = b.path("src/main.zig"),
46 .target = target,
47 .optimize = optimize,
48 }),
49 });
50 src_main_unit_tests.linkLibC();
51 test_step.dependOn(&b.addRunArtifact(src_main_unit_tests).step);
52
53 const lua_config_tests = b.addTest(.{
54 .root_module = b.createModule(.{
55 .root_source_file = b.path("tests/lua_config_tests.zig"),
56 .target = target,
57 .optimize = optimize,
58 }),
59 });
60 lua_config_tests.root_module.addImport("lua", b.createModule(.{
61 .root_source_file = b.path("src/config/lua.zig"),
62 .target = target,
63 .optimize = optimize,
64 }));
65 lua_config_tests.linkSystemLibrary("lua5.4");
66 lua_config_tests.linkLibC();
67 test_step.dependOn(&b.addRunArtifact(lua_config_tests).step);
68
69 const xephyr_step = b.step("xephyr", "Run in Xephyr (1280x800 on :2)");
70 xephyr_step.dependOn(&add_xephyr_run(b, exe, false).step);
71
72 const xephyr_multi_step = b.step("xephyr-multi", "Run in Xephyr multi-monitor on :2");
73 xephyr_multi_step.dependOn(&add_xephyr_run(b, exe, true).step);
74
75 const multimon_step = b.step("multimon", "Alias for xephyr-multi");
76 multimon_step.dependOn(&add_xephyr_run(b, exe, true).step);
77
78 const xwayland_step = b.step("xwayland", "Run in Xwayland on :2");
79 xwayland_step.dependOn(&add_xwayland_run(b, exe).step);
80
81 const kill_step = b.step("kill", "Kill Xephyr and oxwm");
82 kill_step.dependOn(&b.addSystemCommand(&.{ "sh", "-c", "pkill -9 Xephyr || true; pkill -9 oxwm || true" }).step);
83
84 const fmt_step = b.step("fmt", "Format source files");
85 fmt_step.dependOn(&b.addFmt(.{ .paths = &.{"src/"} }).step);
86
87 const clean_step = b.step("clean", "Remove build artifacts");
88 clean_step.dependOn(&b.addSystemCommand(&.{ "rm", "-rf", "zig-out", ".zig-cache" }).step);
89
90 const install_step = b.step("install-system", "Install oxwm system-wide (requires sudo)");
91 install_step.dependOn(b.getInstallStep());
92 install_step.dependOn(&b.addSystemCommand(&.{
93 "sudo", "sh", "-c",
94 "cp zig-out/bin/oxwm /usr/bin/oxwm && " ++
95 "chmod +x /usr/bin/oxwm && " ++
96 "mkdir -p /usr/share/xsessions && " ++
97 "cp resources/oxwm.desktop /usr/share/xsessions/oxwm.desktop && " ++
98 "mkdir -p /usr/share/man/man1 && " ++
99 "cp resources/oxwm.1 /usr/share/man/man1/oxwm.1 && " ++
100 "mkdir -p /usr/share/oxwm && " ++
101 "cp templates/oxwm.lua /usr/share/oxwm/oxwm.lua && " ++
102 "echo 'oxwm installed to /usr/bin/oxwm'",
103 }).step);
104
105 const uninstall_step = b.step("uninstall-system", "Uninstall oxwm from system");
106 uninstall_step.dependOn(&b.addSystemCommand(&.{
107 "sudo", "sh", "-c",
108 "rm -f /usr/bin/oxwm /usr/share/xsessions/oxwm.desktop /usr/share/man/man1/oxwm.1 && " ++
109 "rm -rf /usr/share/oxwm && " ++
110 "echo 'oxwm uninstalled (config at ~/.config/oxwm preserved)'",
111 }).step);
112 }
113
114 fn add_xephyr_run(b: *std.Build, exe: *std.Build.Step.Compile, multimon: bool) *std.Build.Step.Run {
115 const kill_cmd = if (multimon)
116 "pkill -9 Xephyr || true; Xephyr +xinerama -glamor -screen 640x480 -screen 640x480 :2 & sleep 1"
117 else
118 "pkill -9 Xephyr || true; Xephyr -screen 1280x800 :2 & sleep 1";
119
120 const setup = b.addSystemCommand(&.{ "sh", "-c", kill_cmd });
121
122 const run_wm = b.addRunArtifact(exe);
123 run_wm.step.dependOn(&setup.step);
124 run_wm.setEnvironmentVariable("DISPLAY", ":2");
125 run_wm.addArgs(&.{ "-c", "resources/test-config.lua" });
126
127 return run_wm;
128 }
129
130 fn add_xwayland_run(b: *std.Build, exe: *std.Build.Step.Compile) *std.Build.Step.Run {
131 const cmd = "Xwayland -retro -noreset :2 & sleep 1";
132
133 const setup = b.addSystemCommand(&.{ "sh", "-c", cmd });
134
135 const run_wm = b.addRunArtifact(exe);
136 run_wm.step.dependOn(&setup.step);
137 run_wm.setEnvironmentVariable("DISPLAY", ":2");
138
139 return run_wm;
140 }