forked from marler8997/ziglibc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgnumakebuild.zig
More file actions
194 lines (181 loc) · 8.33 KB
/
gnumakebuild.zig
File metadata and controls
194 lines (181 loc) · 8.33 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
const std = @import("std");
const GitRepoStep = @import("GitRepoStep.zig");
pub fn addGnuMake(
b: *std.Build,
target: anytype,
optimize: anytype,
libc_only_std_static: *std.Build.Step.Compile,
zig_start: *std.Build.Step.Compile,
zig_posix: *std.Build.Step.Compile,
) *std.Build.Step.Compile {
const repo = GitRepoStep.create(b, .{
.url = "https://git.savannah.gnu.org/git/make.git",
.sha = "ed493f6c9116cc217b99c2cfa6a95f15803235a2",
.branch = "4.4",
});
const config_step = b.allocator.create(std.Build.Step) catch unreachable;
config_step.* = std.Build.Step.init(.{
.id = .custom,
.name = "configure GNU Make",
.owner = b,
});
// note: this MUST be the first dependency
config_step.dependOn(&repo.step);
const gen_config_h = b.addWriteFile(b.pathJoin(&.{ repo.path, "src", "config.h" }),
\\/* Name of package */
\\#define PACKAGE "GNUMake"
\\/* Define to the address where bug reports for this package should be sent. */
\\#define PACKAGE_BUGREPORT "dontsendmebugreports.com"
\\/* Define to the full name of this package. */
\\#define PACKAGE_NAME "GNUMake"
\\/* Define to the full name and version of this package. */
\\#define PACKAGE_STRING "GNUMake 4.4"
\\/* Define to the one symbol short name of this package. */
\\#define PACKAGE_TARNAME "gnumake"
\\/* Define to the home page for this package. */
\\#define PACKAGE_URL "https://www.gnu.org/software/make/"
\\/* Define to the version of this package. */
\\#define PACKAGE_VERSION "4.4"
\\
\\#define HAVE_STRING_H 1
\\#define HAVE_STDLIB_H 1
\\#define HAVE_INTTYPES_H 1
\\#define HAVE_STDINT_H 1
\\#define HAVE_SYS_TIME_H 1
\\#define HAVE_DIRENT_H 1
\\#define HAVE_FCNTL_H 1
\\#define HAVE_ALLOCA_H 1
\\#define HAVE_LOCALE_H 1
\\#define HAVE_UNISTD_H 1
\\#define HAVE_LIMITS_H 1
\\#define HAVE_UMASK 1
\\#define HAVE_MEMCPY 1
\\#define HAVE_ATEXIT 1
\\
\\#define FILE_TIMESTAMP_HI_RES 0
\\/* not sure what this is, but default.c seems to need it */
\\#define SCCS_GET "get"
\\
);
//\\#define __ptr_t char *
//\\#define HAVE_GETOPT_H 1
//\\#define HAVE_ALLOCA 1
config_step.dependOn(&gen_config_h.step);
// gcc -DHAVE_CONFIG_H -Isrc -I./src -Ilib -I./lib -DLIBDIR=\"/usr/local/lib\" -DLOCALEDIR=\"/usr/local/share/locale\" -DMAKE_MAINTAINER_MODE -C -Wall -Wextra -Werror -Wwrite-strings -Wshadow -Wdeclaration-after-statement -Wbad-function-cast -Wformat-security -Wtype-limits -Wunused-but-set-parameter -Wlogical-op -Wpointer-arith -Wignored-qualifiers -Wformat-signedness -Wduplicated-cond -g -O2 -MT src/hash.o -MD -MP -MF $depbase.Tpo -c -o src/hash.o src/hash.c &&\
// home/marler8997/zig/0.11.0-dev.12+ebf9ffd34/files/zig build-exe -cflags -std=c11 -- /home/marler8997/git/ziglibc/dep/make.git/src/ar.c /home/marler8997/git/ziglibc/dep/make.git/src/arscan.c /home/marler8997/git/ziglibc/dep/make.git/src/commands.c /home/marler8997/git/ziglibc/dep/make.git/src/default.c /home/marler8997/git/ziglibc/dep/make.git/src/dir.c /home/marler8997/git/ziglibc/dep/make.git/src/expand.c /home/marler8997/git/ziglibc/dep/make.git/src/file.c /home/marler8997/git/ziglibc/dep/make.git/src/function.c /home/marler8997/git/ziglibc/dep/make.git/src/getopt.c /home/marler8997/git/ziglibc/dep/make.git/src/getopt1.c /home/marler8997/git/ziglibc/dep/make.git/src/guile.c /home/marler8997/git/ziglibc/dep/make.git/src/hash.c /home/marler8997/git/ziglibc/dep/make.git/src/implicit.c /home/marler8997/git/ziglibc/dep/make.git/src/job.c /home/marler8997/git/ziglibc/dep/make.git/src/load.c /home/marler8997/git/ziglibc/dep/make.git/src/loadapi.c /home/marler8997/git/ziglibc/dep/make.git/src/main.c /home/marler8997/git/ziglibc/dep/make.git/src/misc.c /home/marler8997/git/ziglibc/dep/make.git/src/output.c /home/marler8997/git/ziglibc/dep/make.git/src/read.c /home/marler8997/git/ziglibc/dep/make.git/src/remake.c /home/marler8997/git/ziglibc/dep/make.git/src/rule.c /home/marler8997/git/ziglibc/dep/make.git/src/shuffle.c /home/marler8997/git/ziglibc/dep/make.git/src/signame.c /home/marler8997/git/ziglibc/dep/make.git/src/strcache.c /home/marler8997/git/ziglibc/dep/make.git/src/variable.c /home/marler8997/git/ziglibc/dep/make.git/src/version.c /home/marler8997/git/ziglibc/dep/make.git/src/vpath.c /home/marler8997/git/ziglibc/dep/make.git/src/posixos.c /home/marler8997/git/ziglibc/dep/make.git/src/remote-stub.c /home/marler8997/git/ziglibc/zig-cache/o/b2ab2b27dd98ed5352486d2081cf35bf/libc-only-std.a /home/marler8997/git/ziglibc/zig-cache/o/4d76e73699236d8f95a7f75ae51db269/libc-only-posix.a /home/marler8997/git/ziglibc/zig-cache/o/f647e7cbfedb41adc3d86981e126be58/libstart.a --verbose-cc --cache-dir /home/marler8997/git/ziglibc/zig-cache --global-cache-dir /home/marler8997/.cache/zig --name make -I /home/marler8997/git/ziglibc/inc/libc -I /home/marler8997/git/ziglibc/inc/posix -I /home/marler8997/git/ziglibc/inc/gnu --enable-cache
const exe = addExecutableCompat(b, .{
.name = "make",
.target = target,
.optimize = optimize,
});
const install = b.addInstallArtifact(exe, .{});
exe.step.dependOn(&repo.step);
exe.step.dependOn(config_step);
const repo_path = repo.getPath(&exe.step);
var files = std.array_list.Managed([]const u8).init(b.allocator);
for (src_filenames) |src| {
files.append(b.pathJoin(&.{ repo_path, "src", src })) catch unreachable;
}
exe.addIncludePath(lazyPath(b, b.pathJoin(&.{ repo_path, "src" })));
addCSourceFilesCompat(exe, files.toOwnedSlice() catch unreachable, &.{
"-std=c99",
"-DHAVE_CONFIG_H",
"-Wall",
"-Wextra",
"-Werror",
"-Wwrite-strings",
"-Wshadow",
"-Wdeclaration-after-statement",
"-Wbad-function-cast",
"-Wformat-security",
"-Wtype-limits",
"-Wunused-but-set-parameter",
"-Wpointer-arith",
"-Wignored-qualifiers",
// ignore unused parameter errors because the ATTRIBUTE define isn't working in makeint.h
"-Wno-unused-parameter",
"-Wno-dangling-else",
//"-Wlogical-op", "-Wformat-signedness", "-Wduplicated-cond",
});
exe.addIncludePath(lazyPath(b, "inc/libc"));
exe.addIncludePath(lazyPath(b, "inc/posix"));
exe.addIncludePath(lazyPath(b, "inc/gnu"));
exe.addIncludePath(lazyPath(b, "inc/alloca"));
exe.linkLibrary(libc_only_std_static);
exe.linkLibrary(zig_start);
exe.linkLibrary(zig_posix);
// TODO: should libc_only_std_static and zig_start be able to add library dependencies?
if (target.result.os.tag == .windows) {
exe.linkSystemLibrary("ntdll");
exe.linkSystemLibrary("kernel32");
}
const step = b.step("make", "build GNU make");
step.dependOn(&install.step);
return exe;
}
const src_filenames = &[_][]const u8{
"ar.c",
"arscan.c",
"commands.c",
"default.c",
"dir.c",
"expand.c",
"file.c",
"function.c",
"getopt.c",
"getopt1.c",
"guile.c",
"hash.c",
"implicit.c",
"job.c",
"load.c",
"loadapi.c",
"main.c",
"misc.c",
"output.c",
"read.c",
"remake.c",
"rule.c",
"shuffle.c",
"signame.c",
"strcache.c",
"variable.c",
"version.c",
"vpath.c",
"posixos.c",
"remote-stub.c",
};
fn addExecutableCompat(
b: *std.Build,
opt: struct {
name: []const u8,
target: ?std.Build.ResolvedTarget = null,
optimize: ?std.builtin.OptimizeMode = null,
},
) *std.Build.Step.Compile {
return b.addExecutable(.{
.name = opt.name,
.root_module = b.createModule(.{
.target = opt.target orelse b.graph.host,
.optimize = opt.optimize orelse .Debug,
}),
});
}
fn addCSourceFilesCompat(
step: *std.Build.Step.Compile,
files: []const []const u8,
flags: []const []const u8,
) void {
for (files) |file| {
step.addCSourceFile(.{
.file = lazyPath(step.step.owner, file),
.flags = flags,
});
}
}
fn lazyPath(b: *std.Build, path: []const u8) std.Build.LazyPath {
return if (std.fs.path.isAbsolute(path))
.{ .cwd_relative = path }
else
b.path(path);
}