-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.zig
More file actions
236 lines (221 loc) · 6.82 KB
/
Copy pathbuild.zig
File metadata and controls
236 lines (221 loc) · 6.82 KB
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
const std = @import("std");
const Build = std.Build;
pub fn build(b: *Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const awk_dep = b.dependency("mawk", .{});
const version = std.SemanticVersion.parse(@import("build.zig.zon").version) catch unreachable;
const mod = b.addModule("awk", .{
.target = target,
.optimize = optimize,
.link_libc = true,
});
mod.addIncludePath(awk_dep.path(""));
const only_posix: ?i64 = if (target.result.os.tag == .windows) null else 1;
const config_h = b.addConfigHeader(.{
.style = .{ .autoconf_undef = awk_dep.path("config_h.in") },
.include_path = "config.h",
}, .{
.DECL_ENVIRON = only_posix,
.FPE_TRAPS_ON = null,
.GCC_NORETURN = null,
.GCC_PRINTFLIKE = null,
.GCC_SCANFLIKE = null,
.GCC_UNUSED = null,
.HAVE_BSD_STDLIB_H = null,
.HAVE_CLOCK_GETTIME = 1,
.HAVE_ENVIRON = only_posix,
.HAVE_ERRNO_H = 1,
.HAVE_FCNTL_H = 1,
.HAVE_FORK = only_posix,
.HAVE_FSEEKO = 1,
.HAVE_FSTAT = 1,
.HAVE_GETTIMEOFDAY = null,
.HAVE_INT64_T = 1,
.HAVE_INTTYPES_H = 1,
.HAVE_ISINF = only_posix,
.HAVE_ISNAN = 1,
.HAVE_LIMITS_H = 1,
.HAVE_LONG_LONG = 1,
.HAVE_MATHERR = null,
.HAVE_MATH__LIB_VERSION = null,
.HAVE_MEMORY_H = 1,
.HAVE_MKTIME = 1,
.HAVE_PIPE = only_posix,
.HAVE_REAL_PIPES = only_posix,
.HAVE_REGEXPR_H_FUNCS = null,
.HAVE_REGEXP_H_FUNCS = null,
.HAVE_REGEX_H_FUNCS = null,
.HAVE_SIGACTION = only_posix,
.HAVE_SIGACTION_SA_SIGACTION = only_posix,
.HAVE_SIGINFO_H = null,
.HAVE_STDINT_H = 1,
.HAVE_STDLIB_H = 1,
.HAVE_STRFTIME = 1,
.HAVE_STRINGS_H = 1,
.HAVE_STRING_H = 1,
.HAVE_STRTOD_OVF_BUG = null,
.HAVE_SYS_STAT_H = 1,
.HAVE_SYS_TYPES_H = 1,
.HAVE_SYS_WAIT_H = null,
.HAVE_TDESTROY = null,
.HAVE_TSEARCH = 1,
.HAVE_UINT64_T = 1,
.HAVE_UNISTD_H = 1,
.HAVE_WAIT = only_posix,
.LOCALE = 1,
.LOCAL_REGEXP = 1,
.MAWK_RAND_MAX = @as(enum { INT_MAX, RAND_MAX }, switch (target.result.os.tag) {
.windows => .RAND_MAX,
else => .INT_MAX,
}),
.MAX__INT = null,
.MAX__LONG = null,
.MAX__UINT = null,
.MAX__ULONG = null,
.NAME_RANDOM = switch (target.result.os.tag) {
.windows => "srand/rand",
else => "srandom/random",
},
.NOINFO_SIGFPE = null,
.NO_GAWK_OPTIONS = null,
.NO_INIT_SRAND = null,
.NO_INTERVAL_EXPR = null,
.NO_LEAKS = null,
.SIZEOF_DOUBLE = 8,
.SIZEOF_FLOAT = 4,
.SIZEOF_INT64_T = 8,
.SIZEOF_LONG = 8,
.SIZEOF_LONG_LONG = 8,
.SIZE_T_STDDEF_H = 1,
.SIZE_T_TYPES_H = null,
.STDC_HEADERS = 1,
.SYSTEM_NAME = b.fmt("{s}-{s}", .{
@tagName(target.result.cpu.arch),
@tagName(target.result.os.tag),
}),
.TURN_OFF_FPE_TRAPS = null,
.TURN_ON_FPE_TRAPS = null,
.USE_IEEEFP_H = null,
.YY_NO_LEAKS = null,
.@"const" = null,
.mawk_rand = null,
.mawk_srand = null,
});
mod.addIncludePath(config_h.getOutputDir());
mod.addCMacro("_XOPEN_SOURCE", "500");
mod.addCMacro("_DEFAULT_SOURCE", "");
mod.addCMacro("_HAVE_CONFIG_H", "");
const makesrc_wf = b.addWriteFiles();
mod.addIncludePath(makesrc_wf.getDirectory().path(b, "include"));
const makebits = b.createModule(.{
.target = b.graph.host,
.optimize = optimize,
.link_libc = true,
});
makebits.addIncludePath(config_h.getOutputDir());
makebits.addCSourceFile(.{ .file = awk_dep.path("makebits.c") });
const makebits_exe = b.addExecutable(.{
.name = "makebits",
.root_module = makebits,
});
const makebits_run = b.addRunArtifact(makebits_exe);
_ = makesrc_wf.addCopyFile(makebits_run.captureStdOut(.{}), "include/makebits.h");
const makescan = b.createModule(.{
.target = b.graph.host,
.optimize = optimize,
.link_libc = true,
});
makescan.addIncludePath(config_h.getOutputDir());
makescan.addIncludePath(awk_dep.path(""));
makescan.addCSourceFile(.{ .file = awk_dep.path("makescan.c") });
const makescan_exe = b.addExecutable(.{
.name = "makescan",
.root_module = makescan,
});
const makescan_run = b.addRunArtifact(makescan_exe);
const makescan_c = makesrc_wf.addCopyFile(makescan_run.captureStdOut(.{}), "src/scancode.c");
mod.addCSourceFile(.{
.file = makescan_c,
.flags = flags,
.language = .c,
});
mod.addCSourceFiles(.{
.files = &.{
"parse.c",
"scan.c",
"memory.c",
"main.c",
"hash.c",
"execute.c",
"code.c",
"da.c",
"error.c",
"init.c",
"bi_vars.c",
"cast.c",
"print.c",
"bi_funct.c",
"kw.c",
"jmp.c",
"array.c",
"field.c",
"split.c",
"re_cmpl.c",
"regexp.c",
"zmalloc.c",
"fin.c",
"files.c",
"matherr.c",
"fcall.c",
"version.c",
},
.root = awk_dep.path(""),
.flags = flags,
});
const exe = b.addExecutable(.{
.name = "awk",
.root_module = mod,
});
b.installArtifact(exe);
const version_check = b.addRunArtifact(exe);
version_check.addArg("-Wversion");
version_check.addCheck(.{
.expect_stdout_match = b.fmt("mawk {d}.{d}.{d} {s}", .{
version.major,
version.minor,
version.patch,
version.pre.?,
}),
});
b.step("version-check", "run awk and check the version output").dependOn(&version_check.step);
const fmt = addFmt(b);
b.step("fmt", "zig fmt").dependOn(&fmt.step);
}
inline fn addFmt(b: *Build) *Build.Step.Fmt {
if (comptime @import("builtin").zig_version.order(std.SemanticVersion.parse("0.16.0") catch unreachable) == .gt) {
return b.addFmt(.{
.paths = &.{
b.path("build.zig"),
b.path("build.zig.zon"),
},
});
} else {
return b.addFmt(.{
.paths = &.{
"build.zig",
"build.zig.zon",
},
});
}
}
const flags = &.{
"-fno-optimize-sibling-calls",
"-Wall",
"-Wextra",
"-Werror",
"-pedantic",
"-Wno-unused-parameter",
"-Wno-format",
"-Wno-implicit-function-declaration",
};