-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
-
100
-
101
-
102
-
103
-
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
-
146
-
147
-
148
-
149
-
150
-
151
-
152
-
153
-
154
-
155
-
156
-
157
-
158
-
159
-
160
-
161
-
162
-
163
-
164
-
165
-
166
-
167
-
168
-
169
// Copyright (C) 2025 Shota FUJI
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: GPL-3.0-only
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const man_opt = b.option(bool, "man", "Builds and installs man pages") orelse false;
const zig_main = b.option(bool, "zigmain", "Use Zig rewrite") orelse false;
const version = b.option([]const u8, "version", "Application version, without \"v\" prefix") orelse "dev";
const exe = addExe(b, .{
.target = target,
.optimize = optimize,
.zig_main = zig_main,
.version = version,
});
// "zig build run"
{
const step = b.step("run", "Build and run sunwait");
const run = b.addRunArtifact(exe);
if (b.args) |args| {
run.addArgs(args);
}
step.dependOn(&run.step);
}
const man = man: {
const cmd = b.addSystemCommand(&.{"asciidoctor"});
cmd.addArgs(&.{ "-b", "manpage" });
cmd.addFileArg(b.path("docs/sunwait.adoc"));
cmd.addArg("--out-file");
const out = cmd.addOutputFileArg("sunwait.1");
break :man b.addInstallFile(out, "share/man/man1/sunwait.1");
};
// "zig build man"
{
const step = b.step("man", "Build man pages");
step.dependOn(&man.step);
}
// "zig build"
{
b.installArtifact(exe);
if (man_opt) {
b.getInstallStep().dependOn(&man.step);
}
}
// "zig build test"
{
const step = b.step("test", "Run unit tests");
const t = b.addTest(.{
.name = "unit_test",
.target = target,
.optimize = optimize,
.root_source_file = b.path("src/main.zig"),
});
t.linkLibC();
t.addCSourceFiles(.{
.files = &.{
"src/print.c",
"src/sunriset.c",
"src/sunwait.c",
},
});
t.addIncludePath(b.path("src"));
t.root_module.addCMacro("SUNWAIT_NOMAIN", "");
const run = b.addRunArtifact(t);
step.dependOn(&run.step);
}
// "zig build behavior_test"
{
const step = b.step("behavior_test", "Run behavior matching tests");
const legacy_exe = addExe(b, .{
.target = target,
.optimize = optimize,
.version = "0.91",
});
const new_exe = addExe(b, .{
.target = target,
.optimize = optimize,
.zig_main = true,
.version = version,
});
const t = b.addTest(.{
.name = "behavior_matching_test",
.target = target,
.optimize = optimize,
.root_source_file = b.path("tests/main.zig"),
});
const config = b.addOptions();
config.addOptionPath("legacy_bin", legacy_exe.getEmittedBin());
config.addOptionPath("new_bin", new_exe.getEmittedBin());
t.root_module.addOptions("config", config);
const run = b.addRunArtifact(t);
step.dependOn(&run.step);
}
}
const AddExeOptions = struct {
target: ?std.Build.ResolvedTarget = null,
optimize: std.builtin.OptimizeMode,
zig_main: bool = false,
version: []const u8,
};
fn addExe(b: *std.Build, opts: AddExeOptions) *std.Build.Step.Compile {
const exe = b.addExecutable(.{
.name = "sunwait",
.target = opts.target,
.optimize = opts.optimize,
});
if (opts.zig_main) {
exe.root_module.root_source_file = b.path("src/main.zig");
exe.root_module.addCMacro("SUNWAIT_NOMAIN", "");
const config = b.addOptions();
config.addOption([]const u8, "version", opts.version);
exe.root_module.addOptions("config", config);
}
exe.linkLibC();
exe.addCSourceFiles(.{
.files = &.{
"src/print.c",
"src/sunriset.c",
"src/sunwait.c",
},
});
exe.addIncludePath(b.path("src"));
return exe;
}