const std = @import("std"); pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const gloves_module = b.createModule(.{ .root_source_file = b.path("src/gloves.zig"), .target = target, .optimize = optimize, .link_libc = true, }); const capstone_dep = b.dependency("capstone", .{}); const translate_c = b.addTranslateC(.{ .root_source_file = capstone_dep.path("include/capstone/capstone.h"), .target = target, .optimize = optimize, .link_libc = true, }); // translate const c_mod = translate_c.createModule(); const capstone_lib = b.addLibrary(.{ .name = "capstone", .linkage = .static, .root_module = c_mod, }); capstone_lib.root_module.addIncludePath(capstone_dep.path("include")); capstone_lib.root_module.addIncludePath(capstone_dep.path("include/capstone")); capstone_lib.root_module.addIncludePath(capstone_dep.path("include/capstone/X86")); capstone_lib.installHeadersDirectory(capstone_dep.path("include/capstone"), "capstone", .{}); capstone_lib.installHeader(capstone_dep.path("include/platform.h"), "capstone/platform.h"); if (optimize == .Debug) capstone_lib.root_module.addCMacro("CAPSTONE_DEBUG", ""); capstone_lib.root_module.addCMacro("CAPSTONE_HAS_X86", ""); capstone_lib.root_module.addCMacro("CAPSTONE_BUILD_CSTOOL", "OFF"); capstone_lib.root_module.addCMacro("CAPSTONE_USE_SYS_DYN_MEM", "OFF"); capstone_lib.root_module.addCSourceFiles(.{ .root = capstone_dep.path(""), .files = common_sources }); // capstone_lib.root_module.addCSourceFiles(.{ // .root = capstone_dep.path("arch/AArch64"), // .files = &.{ // "AArch64BaseInfo.c", // "AArch64Disassembler.c", // "AArch64DisassemblerExtension.c", // "AArch64InstPrinter.c", // "AArch64Mapping.c", // "AArch64Module.c", // }, // }); capstone_lib.root_module.addCSourceFiles(.{ .root = capstone_dep.path("arch/X86"), .files = &.{ "X86Disassembler.c", "X86DisassemblerDecoder.c", "X86IntelInstPrinter.c", "X86ATTInstPrinter.c", "X86InstPrinterCommon.c", "X86Mapping.c", "X86Module.c", }, }); b.installArtifact(capstone_lib); const elfo = b.addExecutable(.{ .name = "elfo-pretty", .root_module = b.createModule(.{ .root_source_file = b.path("src/elfo-pretty.zig"), .target = target, .optimize = optimize, }), }); elfo.root_module.linkLibrary(capstone_lib); elfo.root_module.addImport("capstone", capstone_lib.root_module); const gloves = b.addExecutable(.{ .name = "gloves", .root_module = gloves_module, }); // elfo.linkLibrary(cs.artifact); b.installArtifact(elfo); b.installArtifact(gloves); const run_elfo_cmd = b.addRunArtifact(elfo); const run_elfo_step = b.step("elfo", "See the pretty elfo!"); run_elfo_step.dependOn(&run_elfo_cmd.step); const run_gloves_cmd = b.addRunArtifact(gloves); const run_gloves_step = b.step("gloves", "See the pretty gloves!"); run_gloves_step.dependOn(&run_gloves_cmd.step); // TODO: add flag to run on gdb } const common_sources: []const []const u8 = &.{ "cs.c", "Mapping.c", "MCInst.c", "MCInstrDesc.c", "MCInstPrinter.c", "MCRegisterInfo.c", "SStream.c", "utils.c", }; // .AArch64 // .ARC // .ARM // .Alpha // .BPF // .EVM // .HPPA // .LoongArch // .M680X // .M68K // .MOS65XX // .Mips // .PowerPC // .RISCV // .SH // .Sparc // .SystemZ // .TMS320C64x // .TriCore // .WASM // .X86 // .XCore // .Xtensa