-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
158 lines (132 loc) · 5.08 KB
/
build.zig
File metadata and controls
158 lines (132 loc) · 5.08 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
const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const versionString = @import("./build.zig.zon").version;
const version = std.SemanticVersion.parse(versionString) catch @panic("OOM");
const build_tools = b.option(bool, "tools", "Build the gifsicle tools") orelse true;
const linkage = b.option(std.builtin.LinkMode, "linkage", "Link mode for the library") orelse .static;
const terminalAvailable = b.option(bool, "terminal", "Output gif to terminal") orelse true;
const gifsicle_upstream = b.dependency("gifsicle_upstream", .{});
const lib_mod = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
.pic = true,
});
const lib = b.addLibrary(.{
.name = "gifsicle",
.root_module = lib_mod,
.version = version,
.linkage = linkage,
});
lib_mod.addIncludePath(gifsicle_upstream.path("include"));
const t = lib.rootModuleTarget();
const is32Bit = t.ptrBitWidth() == 32;
const isWindows = t.os.tag == .windows;
const haveX11 = !isWindows;
// std.Target.x86.featureSetHas(t.getCpuFeatures(), .simd);
const config_h = b.addConfigHeader(.{ .style = .{ .cmake = b.path("winconf.h.in") }, .include_path = "config.h" }, .{
.GIF_ALLOCATOR_DEFINED = 1,
.HAVE_INT64_T = 1,
.X_DISPLAY_MISSING = @intFromBool(!haveX11),
.HAVE_MKSTEMP = @intFromBool(!isWindows),
.HAVE_POW = 1,
.HAVE_STRERROR = 1,
.HAVE_STRTOUL = 1,
.HAVE_UINT64_T = 1, // search for unused types
.HAVE_UINTPTR_T = 1,
.OUTPUT_GIF_TO_TERMINAL = if (terminalAvailable) null else @as(?u1, 1),
.ENABLE_THREADS = @intFromBool(!isWindows), // pthread.h not on windows
.HAVE_SIMD = 1, // TODO: check target and enable as needed
.HAVE_VECTOR_SIZE_VECTOR_TYPES = 1,
//HAVE___BUILTIN_SHUFFLEVECTOR
//HAVE___SYNC_ADD_AND_FETCH
.HAVE_STDINT_H = 1,
.HAVE_INTTYPES_H = 1,
.HAVE_SYS_STAT_H = 1,
.HAVE_SYS_TYPES_H = 1,
.HAVE_UNISTD_H = @intFromBool(terminalAvailable),
.SIZEOF_FLOAT = 4,
.SIZEOF_UNSIGNED_INT = 4,
.SIZEOF_VOID_P = @as(u8, if (is32Bit) 4 else 8),
.SIZEOF_UNSIGNED_LONG = @as(u8, if (is32Bit or isWindows) 4 else 8),
.PATHNAME_SEPARATOR = if (isWindows) "\\\\" else "/",
.RANDOM = "rand",
.GIF_FREE = "free",
.IS_WINDOWS = @intFromBool(isWindows),
.VERSION = versionString, // b.fmt("{f}", .{version}),
});
lib_mod.addCMacro("HAVE_CONFIG_H", "1");
lib.installHeader(gifsicle_upstream.path("src/gifsicle.h"), "gifsicle.h");
lib.installHeadersDirectory(gifsicle_upstream.path("include"), ".", .{});
lib_mod.addConfigHeader(config_h);
// lib.installConfigHeader(config_h);
lib_mod.addCSourceFiles(.{ .root = gifsicle_upstream.path("."), .files = &gifsicle_sources, .flags = gifsicle_cflags });
b.installArtifact(lib);
////
const gifsicle = b.addExecutable(.{
.name = "gifsicle-cli",
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
gifsicle.root_module.linkLibrary(lib);
gifsicle.root_module.addConfigHeader(config_h);
gifsicle.root_module.addCSourceFile(.{ .file = gifsicle_upstream.path("src/gifsicle.c"), .flags = &.{} });
const gifview = b.addExecutable(.{
.name = "gifview-cli",
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
gifview.root_module.linkLibrary(lib);
gifview.root_module.addConfigHeader(config_h);
gifview.root_module.addCSourceFiles(.{ .root = gifsicle_upstream.path("."), .files = &gifview_sources });
gifview.root_module.linkSystemLibrary("X11", .{});
gifview.root_module.addCMacro("HAVE_CONFIG_H", "1");
const gifdiff = b.addExecutable(.{
.name = "gifdiff-cli",
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
gifdiff.root_module.linkLibrary(lib);
gifdiff.root_module.addConfigHeader(config_h);
gifdiff.root_module.addCSourceFile(.{ .file = gifsicle_upstream.path("src/gifdiff.c"), .flags = &.{} });
if (build_tools) {
b.installArtifact(gifsicle);
if (linkage == .static) {
if (haveX11) b.installArtifact(gifview);
b.installArtifact(gifdiff);
}
}
}
const gifsicle_sources = [_][]const u8{
"src/clp.c",
"src/fmalloc.c",
"src/giffunc.c",
"src/gifread.c",
"src/gifunopt.c",
"src/gifwrite.c",
"src/merge.c",
"src/optimize.c",
"src/quantize.c",
"src/support.c",
"src/xform.c",
"src/kcolor.c",
};
const gifview_sources = [_][]const u8{
"src/gifview.c",
"src/gifx.c",
};
const gifsicle_cflags: []const []const u8 = &.{
// "-std=c89",
// "-W", "-Wall"
};