summaryrefslogtreecommitdiff
path: root/build/capstone.zig
blob: ed4f534b4db48b01f6cadefa3de09bb87ae5e965 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//! Capstone, built from source for x86 alone, with the one function the
//! debugger asks of it (src/cli/disasm.c). After the build in 03-codenomicom.
const std = @import("std");
const Ctx = @import("../build.zig").Ctx;

pub fn add(ctx: Ctx) *std.Build.Step.Compile {
    const b = ctx.b;
    const upstream = b.dependency("capstone", .{});
    // Its tables are large and it is someone else's code: always optimized, never sanitized.
    const mod = b.createModule(.{ .target = ctx.target, .optimize = .ReleaseFast, .link_libc = true, .sanitize_c = .off });
    mod.addIncludePath(upstream.path("include"));
    mod.addCMacro("CAPSTONE_HAS_X86", "");
    mod.addCMacro("CAPSTONE_USE_SYS_DYN_MEM", "");
    mod.addCSourceFiles(.{ .root = upstream.path(""), .files = &.{
        "cs.c",                             "Mapping.c",                 "MCInst.c",                         "MCInstrDesc.c",
        "MCInstPrinter.c",                  "MCRegisterInfo.c",          "SStream.c",                        "utils.c",
        "arch/X86/X86Disassembler.c",       "arch/X86/X86DisassemblerDecoder.c", "arch/X86/X86IntelInstPrinter.c", "arch/X86/X86ATTInstPrinter.c",
        "arch/X86/X86InstPrinterCommon.c",  "arch/X86/X86Mapping.c",     "arch/X86/X86Module.c",
    } });
    mod.addCSourceFile(.{ .file = b.path("src/cli/disasm.c") });
    return b.addLibrary(.{ .name = "capstone", .linkage = .static, .root_module = mod });
}