Skip to content

Commit 036ff64

Browse files
committed
lets try mawk in comparison
1 parent b835c65 commit 036ff64

2 files changed

Lines changed: 151 additions & 47 deletions

File tree

build.zig

Lines changed: 148 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,164 @@ const std = @import("std");
33
pub fn build(b: *std.Build) void {
44
const target = b.standardTargetOptions(.{});
55
const optimize = b.standardOptimizeOption(.{});
6-
const awk_dep = b.dependency("awk", .{});
7-
const yacc_dep = b.dependency("oyacc", .{});
6+
const awk_dep = b.dependency("mawk", .{});
7+
const mod = b.addModule("awk", .{
8+
.target = target,
9+
.optimize = optimize,
10+
.link_libc = true,
11+
});
12+
mod.addIncludePath(awk_dep.path(""));
13+
const config_h = b.addConfigHeader(.{
14+
.style = .{ .autoconf_undef = awk_dep.path("config_h.in") },
15+
.include_path = "config.h",
16+
}, .{
17+
.DECL_ENVIRON = 1,
18+
.FPE_TRAPS_ON = null,
19+
.GCC_NORETURN = null,
20+
.GCC_PRINTFLIKE = null,
21+
.GCC_SCANFLIKE = null,
22+
.GCC_UNUSED = null,
23+
.HAVE_BSD_STDLIB_H = null,
24+
.HAVE_CLOCK_GETTIME = 1,
25+
.HAVE_ENVIRON = 1,
26+
.HAVE_ERRNO_H = 1,
27+
.HAVE_FCNTL_H = 1,
28+
.HAVE_FORK = 1,
29+
.HAVE_FSEEKO = 1,
30+
.HAVE_FSTAT = 1,
31+
.HAVE_GETTIMEOFDAY = null,
32+
.HAVE_INT64_T = 1,
33+
.HAVE_INTTYPES_H = 1,
34+
.HAVE_ISINF = 1,
35+
.HAVE_ISNAN = 1,
36+
.HAVE_LIMITS_H = 1,
37+
.HAVE_LONG_LONG = 1,
38+
.HAVE_MATHERR = null,
39+
.HAVE_MATH__LIB_VERSION = null,
40+
.HAVE_MEMORY_H = 1,
41+
.HAVE_MKTIME = 1,
42+
.HAVE_PIPE = 1,
43+
.HAVE_REAL_PIPES = 1,
44+
.HAVE_REGEXPR_H_FUNCS = null,
45+
.HAVE_REGEXP_H_FUNCS = null,
46+
.HAVE_REGEX_H_FUNCS = null,
47+
.HAVE_SIGACTION = 1,
48+
.HAVE_SIGACTION_SA_SIGACTION = 1,
49+
.HAVE_SIGINFO_H = null,
50+
.HAVE_STDINT_H = 1,
51+
.HAVE_STDLIB_H = 1,
52+
.HAVE_STRFTIME = 1,
53+
.HAVE_STRINGS_H = 1,
54+
.HAVE_STRING_H = 1,
55+
.HAVE_STRTOD_OVF_BUG = null,
56+
.HAVE_SYS_STAT_H = 1,
57+
.HAVE_SYS_TYPES_H = 1,
58+
.HAVE_SYS_WAIT_H = 1,
59+
.HAVE_TDESTROY = null,
60+
.HAVE_TSEARCH = 1,
61+
.HAVE_UINT64_T = 1,
62+
.HAVE_UNISTD_H = 1,
63+
.HAVE_WAIT = 1,
64+
.LOCALE = 1,
65+
.LOCAL_REGEXP = 1,
66+
.MAWK_RAND_MAX = .INT_MAX,
67+
.MAX__INT = null,
68+
.MAX__LONG = null,
69+
.MAX__UINT = null,
70+
.MAX__ULONG = null,
71+
.NAME_RANDOM = "srand/rand",
72+
.NOINFO_SIGFPE = null,
73+
.NO_GAWK_OPTIONS = null,
74+
.NO_INIT_SRAND = null,
75+
.NO_INTERVAL_EXPR = null,
76+
.NO_LEAKS = null,
77+
.SIZEOF_DOUBLE = 8,
78+
.SIZEOF_FLOAT = 4,
79+
.SIZEOF_INT64_T = 8,
80+
.SIZEOF_LONG = 8,
81+
.SIZEOF_LONG_LONG = 8,
82+
.SIZE_T_STDDEF_H = 1,
83+
.SIZE_T_TYPES_H = null,
84+
.STDC_HEADERS = 1,
85+
.SYSTEM_NAME = "linux-gnu",
86+
.TURN_OFF_FPE_TRAPS = null,
87+
.TURN_ON_FPE_TRAPS = null,
88+
.USE_IEEEFP_H = null,
89+
.YY_NO_LEAKS = null,
90+
.@"const" = null,
91+
.mawk_rand = .rand,
92+
.mawk_srand = .srand,
93+
});
94+
mod.addIncludePath(config_h.getOutputDir());
95+
mod.addCMacro("_XOPEN_SOURCE", "500");
96+
mod.addCMacro("_DEFAULT_SOURCE", "");
97+
mod.addCMacro("_HAVE_CONFIG_H", "");
898

9-
const yacc = b.addRunArtifact(yacc_dep.artifact("yacc"));
10-
yacc.addArgs(&.{ "-d", "-b", "awkgram", "-o" });
11-
const awkgram_tab = yacc.addOutputFileArg("awkgram.tab.c");
12-
yacc.addFileArg(awk_dep.path("awkgram.y"));
99+
const makeh_wf = b.addWriteFiles();
100+
mod.addIncludePath(makeh_wf.getDirectory());
13101

14-
const maketab = b.addExecutable(.{
15-
.name = "maketab",
102+
const makebits = b.addExecutable(.{
103+
.name = "makebits",
16104
.root_module = b.createModule(.{
17105
.target = b.graph.host,
18-
.optimize = .ReleaseSmall,
106+
.optimize = optimize,
19107
.link_libc = true,
20108
}),
21109
});
22-
maketab.addIncludePath(awkgram_tab.dirname());
23-
maketab.addCSourceFile(.{
24-
.file = awk_dep.path("maketab.c"),
25-
.flags = flags,
26-
});
27-
const mt_run = b.addRunArtifact(maketab);
28-
mt_run.addFileArg(awkgram_tab.dirname().path(b, "awkgram.tab.h"));
29-
const w_proc = b.addWriteFiles();
30-
const proctab = w_proc.addCopyFile(mt_run.captureStdOut(), "proctab.c");
110+
makebits.addIncludePath(config_h.getOutputDir());
111+
makebits.addCSourceFile(.{ .file = awk_dep.path("makebits.c") });
112+
const makebits_run = b.addRunArtifact(makebits);
113+
_ = makeh_wf.addCopyFile(makebits_run.captureStdOut(), "makebits.h");
114+
// mod.addIncludePath(makebits_h.dirname());
31115

32-
const mod = b.addModule("awk", .{
33-
.target = target,
34-
.optimize = optimize,
35-
.link_libc = true,
36-
});
37-
mod.addIncludePath(awk_dep.path(""));
38-
mod.addIncludePath(awkgram_tab.dirname());
39-
mod.addCSourceFile(.{
40-
.file = proctab,
41-
.flags = flags,
116+
const makescan = b.addExecutable(.{
117+
.name = "makescan",
118+
.root_module = b.createModule(.{
119+
.target = b.graph.host,
120+
.optimize = optimize,
121+
.link_libc = true,
122+
}),
42123
});
124+
makescan.addIncludePath(config_h.getOutputDir());
125+
makescan.addIncludePath(awk_dep.path(""));
126+
makescan.addCSourceFile(.{ .file = awk_dep.path("makescan.c") });
127+
const makescan_run = b.addRunArtifact(makescan);
128+
const makescan_c = makeh_wf.addCopyFile(makescan_run.captureStdOut(), "scancode.c");
43129
mod.addCSourceFile(.{
44-
.file = awkgram_tab,
130+
.file = makescan_c,
45131
.flags = flags,
132+
.language = .c,
46133
});
134+
47135
mod.addCSourceFiles(.{
48136
.files = &.{
49-
"tran.c",
50-
"lib.c",
51-
"run.c",
52-
"lex.c",
53-
"main.c",
54137
"parse.c",
55-
"b.c",
138+
"scan.c",
139+
"memory.c",
140+
"main.c",
141+
"hash.c",
142+
"execute.c",
143+
"code.c",
144+
"da.c",
145+
"error.c",
146+
"init.c",
147+
"bi_vars.c",
148+
"cast.c",
149+
"print.c",
150+
"bi_funct.c",
151+
"kw.c",
152+
"jmp.c",
153+
"array.c",
154+
"field.c",
155+
"split.c",
156+
"re_cmpl.c",
157+
"regexp.c",
158+
"zmalloc.c",
159+
"fin.c",
160+
"files.c",
161+
"matherr.c",
162+
"fcall.c",
163+
"version.c",
56164
},
57165
.root = awk_dep.path(""),
58166
.flags = flags,
@@ -70,11 +178,11 @@ const flags = &.{
70178
"-fno-optimize-sibling-calls",
71179
"-Wall",
72180
"-Wextra",
73-
"-Werror",
74-
"-pedantic",
75-
"-Wno-unused-parameter",
76-
"-Wno-unused-but-set-variable",
77-
"-Wno-strict-prototypes",
181+
// "-Werror",
182+
// "-pedantic",
183+
// "-Wno-unused-parameter",
184+
// "-Wno-unused-but-set-variable",
185+
// "-Wno-strict-prototypes",
78186
// "-Wno-inconsistent-dllimport",
79187
// "-Wno-implicit-function-declaration",
80188
// "-Wno-void-pointer-to-int-cast",

build.zig.zon

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@
44
.minimum_zig_version = "0.15.1",
55
.fingerprint = 0xc4a2fe42a08b135,
66
.dependencies = .{
7-
.awk = .{
8-
.url = "git+https://github.com/onetrueawk/awk.git#d7f37646965ee26214da0e1d97f3c1d54349ae2d",
9-
.hash = "N-V-__8AAFMBaQCmtxd6CBzAIJ8sBzEIwVIQ1r9jsy-bkJ8K",
10-
},
11-
.oyacc = .{
12-
.url = "git+https://github.com/dasimmet/zig-oyacc.git#e1c49f8ae9b1722a6592198736147708d8ae9bf9",
13-
.hash = "oyacc-6.6.0-08n9NCsKAACFbsndggD_f7zdlLGfNoHEvR9JNLxRwlUC",
7+
.mawk = .{
8+
.url = "https://invisible-island.net/archives/mawk/mawk-1.3.4-20250131.tgz",
9+
.hash = "N-V-__8AAL6_GQAf7euJ5ASn0CsnxtwKtqzHtXx1cQ9DPITv",
1410
},
1511
},
1612
.paths = .{

0 commit comments

Comments
 (0)