forked from bwalex/tc-play
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.zig
154 lines (142 loc) · 4.71 KB
/
build.zig
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
const std = @import("std");
const CFLAGS_WARN = &[_][]const u8{
"-Wsystem-headers",
"-Wall",
"-W",
"-Wno-unused-parameter",
"-Wstrict-prototypes",
"-Wmissing-prototypes",
"-Wpointer-arith",
"-Wold-style-definition",
"-Wreturn-type",
"-Wwrite-strings",
"-Wswitch",
"-Wshadow",
"-Wcast-align",
"-Wunused-parameter",
"-Wchar-subscripts",
"-Winline",
"-Wnested-externs",
};
fn common(step: *std.Build.Step.Compile) void {
const SRCS_COMMON = &[_][]const u8{
"tcplay.c",
"main.c",
"safe_mem.c",
"io.c",
"hdr.c",
"humanize.c",
"crypto.c",
};
step.addCSourceFiles(.{
.files = SRCS_COMMON,
.flags = CFLAGS_WARN,
});
step.addSystemIncludePath(.{ .path = "/usr/include" });
step.linkSystemLibrary("devmapper");
step.linkSystemLibrary("uuid");
step.defineCMacro("MAJ_VER", "3");
step.defineCMacro("MIN_VER", "3");
}
// Although this function looks imperative, note that its job is to
// declaratively construct a build graph that will be executed by an external
// runner.
pub fn build(b: *std.Build) void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});
// Standard optimization options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});
const options = .{
.name = "tcplay",
.target = target,
.optimize = optimize,
.link_libc = true,
};
const exe = b.addExecutable(options);
common(exe);
// replace zig-out/bin path with with build
const artifact_dest = std.Build.Step.InstallArtifact.Options{
.dest_dir = std.Build.Step.InstallArtifact.Options.Dir{
.override = std.Build.InstallDir{ .custom = "../build" },
},
};
const exe_install_artifact = b.addInstallArtifact(
exe,
artifact_dest,
);
b.getInstallStep().dependOn(&exe_install_artifact.step);
const lib_static = b.addStaticLibrary(options);
common(lib_static);
const t = .{
.files = &[_][]const u8{
"tcplay_api.c",
},
.flags = CFLAGS_WARN,
};
lib_static.addCSourceFiles(t);
lib_static.version_script = .{ .path = "tcplay.map" };
const lib_static_artifact = b.addInstallArtifact(
lib_static,
artifact_dest,
);
b.getInstallStep().dependOn(&lib_static_artifact.step);
const lib_shared = b.addSharedLibrary(options);
common(lib_shared);
lib_shared.addCSourceFiles(t);
const lib_shared_artifact = b.addInstallArtifact(
lib_shared,
artifact_dest,
);
lib_shared.version_script = .{ .path = "tcplay.map" };
b.getInstallStep().dependOn(&lib_shared_artifact.step);
const crc32 = b.addObject(.{
.name = "crc32",
.root_source_file = .{ .path = "crc32.zig" },
.target = target,
.optimize = optimize,
.pic = true,
});
exe.addObject(crc32);
lib_static.addObject(crc32);
lib_shared.addObject(crc32);
const pbkdf2 = b.addObject(.{
.name = "pbkdf2_",
.root_source_file = .{ .path = "pbkdf2.zig" },
.target = target,
.optimize = optimize,
.link_libc = true,
});
pbkdf2.addIncludePath(.{ .path = "." });
exe.addObject(pbkdf2);
lib_static.addObject(pbkdf2);
lib_shared.addObject(pbkdf2);
const libcrypto_dep = b.dependency("libcrypto", .{
.target = target,
.optimize = optimize,
});
const libcrypto_mod = libcrypto_dep.module("libcrypto");
pbkdf2.root_module.addImport("libcrypto", libcrypto_mod);
const crypto = b.addObject(.{
.name = "crypto",
.root_source_file = .{ .path = "crypto-libcrypto.zig" },
.target = target,
.optimize = optimize,
.link_libc = true,
});
crypto.addIncludePath(.{ .path = "." });
exe.addObject(crypto);
lib_static.addObject(crypto);
lib_shared.addObject(crypto);
crypto.root_module.addImport("libcrypto", libcrypto_mod);
exe.defineCMacro("_GNU_SOURCE", "");
lib_static.defineCMacro("_GNU_SOURCE", "");
lib_shared.defineCMacro("_GNU_SOURCE", "");
exe.defineCMacro("_DEFAULT_SOURCE", "");
lib_static.defineCMacro("_DEFAULT_SOURCE", "");
lib_shared.defineCMacro("_DEFAULT_SOURCE", "");
}