diff options
| author | Gabriel Schneider <[email protected]> | 2026-02-23 15:07:43 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-02-23 15:07:43 -0300 |
| commit | a3d5a50b58eb90521924dd5e6b594939713c6705 (patch) | |
| tree | e39cd64303357db35c9d4ff98d5eccb8c24c376a /build/capstone.zig | |
| parent | 169ba71c6ca54be373a3bbccf17ba199bba17ca8 (diff) | |
| download | codenomicon-a3d5a50b58eb90521924dd5e6b594939713c6705.tar.gz codenomicon-a3d5a50b58eb90521924dd5e6b594939713c6705.zip | |
organized build functions
Diffstat (limited to 'build/capstone.zig')
| -rw-r--r-- | build/capstone.zig | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/build/capstone.zig b/build/capstone.zig new file mode 100644 index 0000000..fa17784 --- /dev/null +++ b/build/capstone.zig @@ -0,0 +1,110 @@ +const std = @import("std"); + +pub fn capstone(b: *std.Build, opts: struct { + target: std.Build.ResolvedTarget, + optimize: std.builtin.OptimizeMode, +}) *std.Build.Step.Compile { + const capstone_dep = b.dependency("capstone", .{}); + + // later I'll use this + const translate_c = b.addTranslateC(.{ + .root_source_file = capstone_dep.path("include/capstone/capstone.h"), + .target = opts.target, + .optimize = opts.optimize, + // .optimize = .Debug, + .link_libc = true, + }); + + const mod = translate_c.createModule(); + + // const mod = b.createModule(.{ + // .optimize = opts.optimize, + // .target = opts.target, + // .link_libc = true, + // }); + + mod.addIncludePath(capstone_dep.path("include")); + mod.addIncludePath(capstone_dep.path("include/capstone")); + mod.addIncludePath(capstone_dep.path("include/capstone/X86")); + mod.addIncludePath(capstone_dep.path("include/capstone/ARM")); + + if (opts.optimize == .Debug) mod.addCMacro("CAPSTONE_DEBUG", ""); + mod.addCMacro("CAPSTONE_HAS_X86", ""); + mod.addCMacro("CAPSTONE_HAS_ARM", ""); + mod.addCMacro("CAPSTONE_HAS_AArch64", ""); + mod.addCMacro("CAPSTONE_BUILD_CSTOOL", "OFF"); + mod.addCMacro("CAPSTONE_USE_SYS_DYN_MEM", "1"); + mod.addCMacro("CAPSTONE_BUILD_DIET", "1"); + mod.addCMacro("CAPSTONE_X86_REDUCE", "1"); + + mod.addCSourceFiles(.{ .root = capstone_dep.path(""), .files = common_sources }); + + mod.addCSourceFiles(.{ + .root = capstone_dep.path("arch/ARM"), + .files = &.{ + "ARMBaseInfo.c", + "ARMDisassembler.c", + "ARMDisassemblerExtension.c", + "ARMInstPrinter.c", + "ARMMapping.c", + "ARMModule.c", + }, + }); + mod.addCSourceFiles(.{ + .root = capstone_dep.path("arch/X86"), + .files = &.{ + "X86Disassembler.c", + "X86DisassemblerDecoder.c", + "X86IntelInstPrinter.c", + "X86ATTInstPrinter.c", + "X86InstPrinterCommon.c", + "X86Mapping.c", + "X86Module.c", + }, + }); + + const capstone_lib = b.addLibrary(.{ + .name = "capstone", + .linkage = .static, + .root_module = mod, + }); + + capstone_lib.installHeadersDirectory(capstone_dep.path("include/capstone"), "capstone", .{}); + capstone_lib.installHeader(capstone_dep.path("include/platform.h"), "capstone/platform.h"); + + return capstone_lib; +} +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 |
