summaryrefslogtreecommitdiff
path: root/vere/pkg/c3/build.zig
blob: 3c5a89cd20a0a4e4f415f897740838b7c5709189 (plain)
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
const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});
    const t = target.result;

    const copts: []const []const u8 =
        b.option([]const []const u8, "copt", "") orelse &.{};

    const pkg_c3 = b.addStaticLibrary(.{
        .name = "c3",
        .target = target,
        .optimize = optimize,
    });

    if (target.result.os.tag.isDarwin() and !target.query.isNative()) {
        const macos_sdk = b.lazyDependency("macos_sdk", .{
            .target = target,
            .optimize = optimize,
        });
        if (macos_sdk != null) {
            pkg_c3.addSystemIncludePath(macos_sdk.?.path("usr/include"));
            pkg_c3.addLibraryPath(macos_sdk.?.path("usr/lib"));
            pkg_c3.addFrameworkPath(macos_sdk.?.path("System/Library/Frameworks"));
        }
    }

    pkg_c3.linkLibC();

    pkg_c3.addIncludePath(b.path(""));

    pkg_c3.addCSourceFiles(.{
        .root = b.path(""),
        .files = &.{"defs.c"},
        .flags = copts,
    });

    if (t.os.tag == .windows) {
        pkg_c3.addIncludePath(b.path("platform/windows"));
        pkg_c3.installHeadersDirectory(b.path("platform/windows"), "", .{});
        pkg_c3.addCSourceFiles(.{
        .root = b.path(""),
        .files = &.{"platform/windows/compat.c"},
        .flags = copts,
    });
    }

    pkg_c3.installHeader(b.path("c3.h"), "c3/c3.h");
    pkg_c3.installHeader(b.path("defs.h"), "c3/defs.h");
    pkg_c3.installHeader(b.path("motes.h"), "c3/motes.h");
    pkg_c3.installHeader(b.path("portable.h"), "c3/portable.h");
    pkg_c3.installHeader(b.path("types.h"), "c3/types.h");

    b.installArtifact(pkg_c3);
}