-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.zig
59 lines (52 loc) · 1.91 KB
/
build.zig
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
57
58
59
const std = @import("std");
const builtin = @import("builtin");
const emulator = "desmume";
const flags = .{"-lnds9"};
const devkitpro = "/opt/devkitpro";
pub fn build(b: *std.build.Builder) void {
const mode = b.standardReleaseOptions();
const obj = b.addObject("zig-nds", "src/main.zig");
obj.setOutputDir("zig-out");
obj.linkLibC();
obj.setLibCFile(std.build.FileSource{ .path = "libc.txt" });
obj.addIncludeDir(devkitpro ++ "/libnds/include");
obj.addIncludeDir(devkitpro ++ "/portlibs/nds/include");
obj.addIncludeDir(devkitpro ++ "/portlibs/armv5te/include");
obj.setTarget(.{
.cpu_arch = .thumb,
.os_tag = .freestanding,
.cpu_model = .{ .explicit = &std.Target.arm.cpu.arm946e_s },
});
obj.setBuildMode(mode);
const extension = if (builtin.target.os.tag == .windows) ".exe" else "";
const elf = b.addSystemCommand(&(.{
devkitpro ++ "/devkitARM/bin/arm-none-eabi-gcc" ++ extension,
"-g",
"-mthumb",
"-mthumb-interwork",
"-Wl,-Map,zig-out/zig-nds.map",
"-specs=" ++ devkitpro ++ "/devkitARM/arm-none-eabi/lib/ds_arm9.specs",
"zig-out/zig-nds.o",
"-L" ++ devkitpro ++ "/libnds/lib",
"-L" ++ devkitpro ++ "/portlibs/nds/lib",
"-L" ++ devkitpro ++ "/portlibs/armv5te/lib",
} ++ flags ++ .{
"-o",
"zig-out/zig-nds.elf",
}));
const nds = b.addSystemCommand(&.{
devkitpro ++ "/tools/bin/ndstool" ++ extension,
"-9",
"zig-out/zig-nds.elf",
"-c",
"zig-out/zig-nds.nds",
});
nds.stdout_action = .ignore;
b.default_step.dependOn(&nds.step);
nds.step.dependOn(&elf.step);
elf.step.dependOn(&obj.step);
const run_step = b.step("run", "Run in DeSmuME");
const desmume = b.addSystemCommand(&.{ emulator, "zig-out/zig-nds.nds" });
run_step.dependOn(&nds.step);
run_step.dependOn(&desmume.step);
}