-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
147 lines (121 loc) · 4.58 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
const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const build_tools = b.option(bool, "tools", "Build the gifsicle tools") orelse true;
const dynamic = b.option(bool, "dynamic", "Build dynamic library") orelse false;
const terminalAvailable = b.option(bool, "terminal", "Output gif to terminal") orelse true;
const gifsicle_upstream = b.dependency("gifsicle_upstream", .{});
const lib_config = .{
.name = "gifsicle",
.target = target,
.optimize = optimize,
.link_libc = true,
.pic = true,
};
const lib = if (dynamic) b.addSharedLibrary(lib_config) else b.addStaticLibrary(lib_config);
lib.addIncludePath(gifsicle_upstream.path("include"));
const version = "1.95-zig"; // TODO: import version
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 = version,
});
lib.root_module.addCMacro("HAVE_CONFIG_H", "1");
lib.installHeader(gifsicle_upstream.path("src/gifsicle.h"), "gifsicle.h");
lib.installHeadersDirectory(gifsicle_upstream.path("include"), ".", .{});
lib.addConfigHeader(config_h);
lib.installConfigHeader(config_h);
lib.addCSourceFiles(.{ .root = gifsicle_upstream.path("."), .files = &gifsicle_sources, .flags = gifsicle_cflags });
b.installArtifact(lib);
////
const gifsicle = b.addExecutable(.{
.name = "gifsicle-cli",
.target = target,
.optimize = optimize,
.link_libc = true,
});
gifsicle.linkLibrary(lib);
// gifsicle.addConfigHeader(config_h);
gifsicle.addCSourceFile(.{ .file = gifsicle_upstream.path("src/gifsicle.c"), .flags = &.{} });
const gifview = b.addExecutable(.{
.name = "gifview-cli",
.target = target,
.optimize = optimize,
.link_libc = true,
});
gifview.linkLibrary(lib);
// gifview.addConfigHeader(config_h);
gifview.addCSourceFiles(.{ .root = gifsicle_upstream.path("."), .files = &gifview_sources });
gifview.linkSystemLibrary2("X11", .{});
gifview.root_module.addCMacro("HAVE_CONFIG_H", "1");
const gifdiff = b.addExecutable(.{
.name = "gifdiff-cli",
.target = target,
.optimize = optimize,
.link_libc = true,
});
gifdiff.linkLibrary(lib);
// gifdiff.addConfigHeader(config_h);
gifdiff.addCSourceFile(.{ .file = gifsicle_upstream.path("src/gifdiff.c"), .flags = &.{} });
if (build_tools) {
b.installArtifact(gifsicle);
if (!dynamic) {
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"
};