|
1 | 1 | const std = @import("std"); |
| 2 | +const LinkMode = std.builtin.LinkMode; |
2 | 3 |
|
3 | | -pub fn build(b: *std.Build) void { |
| 4 | +const manifest = @import("build.zig.zon"); |
| 5 | + |
| 6 | +pub fn build(b: *std.Build) !void { |
4 | 7 | const target = b.standardTargetOptions(.{}); |
5 | 8 | const optimize = b.standardOptimizeOption(.{}); |
6 | | - const linkage = b.option(std.builtin.LinkMode, "linkage", "Library linkage type") orelse .static; |
| 9 | + const os = target.result.os.tag; |
| 10 | + const arch = target.result.cpu.arch; |
| 11 | + |
| 12 | + const options = .{ |
| 13 | + .linkage = b.option(LinkMode, "linkage", "Library linkage type") orelse |
| 14 | + .static, |
| 15 | + }; |
7 | 16 |
|
8 | 17 | const upstream = b.dependency("upstream", .{}); |
9 | | - const src = upstream.path(""); |
| 18 | + const mod = b.createModule(.{ |
| 19 | + .target = target, |
| 20 | + .optimize = optimize, |
| 21 | + .link_libc = true, |
| 22 | + }); |
10 | 23 |
|
11 | | - const os = target.result.os.tag; |
12 | | - const arch = target.result.cpu.arch; |
| 24 | + mod.addIncludePath(upstream.path("include")); |
| 25 | + |
| 26 | + mod.addCMacro("HasTHREADS", "1"); |
| 27 | + mod.addCMacro("HAVE_TIMESPEC_GET", "1"); |
| 28 | + if (os != .windows) { |
| 29 | + mod.addCMacro("HAVE_FUNC_ATTRIBUTE_VISIBILITY", "1"); |
| 30 | + mod.addCMacro("HAVE_GMTIME_R", "1"); |
| 31 | + } |
| 32 | + if (arch.endian() == .big) mod.addCMacro("WORDS_BIGENDIAN", "1"); |
| 33 | + if (arch != .x86_64 and arch != .x86) mod.addCMacro("CMS_DONT_USE_SSE2", "1"); |
| 34 | + |
| 35 | + mod.addCSourceFiles(.{ |
| 36 | + .root = upstream.path(""), |
| 37 | + .files = src, |
| 38 | + .flags = if (os != .windows) &.{"-fvisibility=hidden"} else &.{}, |
| 39 | + }); |
13 | 40 |
|
14 | | - const mod = b.createModule(.{ .target = target, .optimize = optimize, .link_libc = true }); |
15 | | - mod.addIncludePath(src.path(b, "include")); |
16 | | - mod.addCSourceFiles(.{ .root = src, .files = sources, .flags = &((if (os != .windows) .{ |
17 | | - "-fvisibility=hidden", |
18 | | - "-DHAVE_FUNC_ATTRIBUTE_VISIBILITY=1", |
19 | | - "-DHAVE_GMTIME_R=1", |
20 | | - } else .{ "", "", "" }) ++ |
21 | | - .{ "-DHasTHREADS=1", "-DHAVE_TIMESPEC_GET=1" } ++ |
22 | | - .{if (arch.endian() == .big) "-DWORDS_BIGENDIAN=1" else ""} ++ |
23 | | - .{if (arch != .x86_64 and arch != .x86) "-DCMS_DONT_USE_SSE2=1" else ""}) }); |
24 | | - |
25 | | - const lib = b.addLibrary(.{ .name = "lcms2", .root_module = mod, .linkage = linkage }); |
26 | | - inline for (.{ "lcms2.h", "lcms2_plugin.h" }) |h| lib.installHeader(src.path(b, "include/" ++ h), h); |
| 41 | + const lib = b.addLibrary(.{ |
| 42 | + .name = "lcms2", |
| 43 | + .root_module = mod, |
| 44 | + .linkage = options.linkage, |
| 45 | + .version = try .parse(manifest.version), |
| 46 | + }); |
| 47 | + inline for (.{ "lcms2.h", "lcms2_plugin.h" }) |h| lib.installHeader(upstream.path("include/" ++ h), h); |
27 | 48 | b.installArtifact(lib); |
28 | 49 | } |
29 | 50 |
|
30 | | -const sources: []const []const u8 = &.{ |
| 51 | +const src: []const []const u8 = &.{ |
31 | 52 | "src/cmsalpha.c", "src/cmscam02.c", "src/cmscgats.c", "src/cmscnvrt.c", |
32 | 53 | "src/cmserr.c", "src/cmsgamma.c", "src/cmsgmt.c", "src/cmshalf.c", |
33 | 54 | "src/cmsintrp.c", "src/cmsio0.c", "src/cmsio1.c", "src/cmslut.c", |
|
0 commit comments