generated from zPSP-Dev/Zig-PSP-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
109 lines (92 loc) · 3.54 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
const Builder = @import("std").build.Builder;
const z = @import("std").zig;
const std = @import("std");
const builtin = @import("builtin");
//Optional customizations
const icon0 = "NULL"; //REPLACE WITH PATH TO ICON0.PNG 144 x 80 Thumbnail
const icon1 = "NULL"; //REPLACE WITH PATH TO ICON1.PMF 144 x 80 animation
const pic0 = "NULL"; //REPLACE WITH PATH TO PIC0.PNG 480 x 272 Background
const pic1 = "NULL"; //REPLACE WITH PATH TO PIC1.PMF 480 x 272 Animation
const snd0 = "NULL"; //REPLACE WITH PATH TO SND0.AT3 Music
const psp_app_name = "zTetris";
pub fn build(b: *Builder) void {
var feature_set : std.Target.Cpu.Feature.Set = std.Target.Cpu.Feature.Set.empty;
feature_set.addFeature(@enumToInt(std.Target.mips.Feature.single_float));
//PSP-Specific Build Options
const target = z.CrossTarget{
.cpu_arch = .mipsel,
.os_tag = .freestanding,
.cpu_model = .{ .explicit = &std.Target.mips.cpu.mips2 },
.cpu_features_add = feature_set
};
//All of the release modes work
//Debug Mode can cause issues with trap instructions - use ReleaseSafe for "Debug" builds
const mode = builtin.Mode.ReleaseSmall;
//Build from your main file!
const exe = b.addExecutable("main", "src/main.zig");
//Output to zig cache for now
exe.setOutputDir("zig-cache/");
//Set mode & target
exe.setTarget(target);
exe.setBuildMode(mode);
exe.setLinkerScriptPath("src/Zig-PSP/tools/linkfile.ld");
exe.link_eh_frame_hdr = true;
exe.link_emit_relocs = true;
//Post-build actions
const hostTarget = b.standardTargetOptions(.{});
const prx = b.addExecutable("prxgen", "src/Zig-PSP/tools/prxgen/stub.zig");
prx.setTarget(hostTarget);
prx.addCSourceFile("src/Zig-PSP/tools/prxgen/psp-prxgen.c", &[_][]const u8{"-std=c99", "-Wno-address-of-packed-member", "-D_CRT_SECURE_NO_WARNINGS"});
prx.linkLibC();
prx.setBuildMode(builtin.Mode.ReleaseFast);
prx.setOutputDir("src/Zig-PSP/tools/bin");
prx.install();
prx.step.dependOn(&exe.step);
const append : []const u8 = switch(builtin.os.tag){
.windows => ".exe",
else => "",
};
const generate_prx = b.addSystemCommand(&[_][]const u8{
"./src/Zig-PSP/tools/bin/prxgen" ++ append,
"zig-cache/main",
"app.prx"
});
generate_prx.step.dependOn(&prx.step);
//Build SFO
const sfo = b.addExecutable("sfotool", "./src/Zig-PSP/tools/sfo/src/main.zig");
sfo.setTarget(hostTarget);
sfo.setBuildMode(builtin.Mode.ReleaseFast);
sfo.setOutputDir("src/Zig-PSP/tools/bin");
sfo.install();
sfo.step.dependOn(&generate_prx.step);
//Make the SFO file
const mk_sfo = b.addSystemCommand(&[_][]const u8{
"./src/Zig-PSP/tools/bin/sfotool" ++ append, "write",
psp_app_name,
"PARAM.SFO"
});
mk_sfo.step.dependOn(&sfo.step);
//Build PBP
const PBP = b.addExecutable("pbptool", "./src/Zig-PSP/tools/pbp/src/main.zig");
PBP.setTarget(hostTarget);
PBP.setBuildMode(builtin.Mode.ReleaseFast);
PBP.setOutputDir("src/Zig-PSP/tools/bin");
PBP.install();
PBP.step.dependOn(&generate_prx.step);
//Pack the PBP executable
const pack_pbp = b.addSystemCommand(&[_][]const u8{
"./src/Zig-PSP/tools/bin/pbptool" ++ append, "pack",
"EBOOT.PBP",
"PARAM.SFO",
icon0,
icon1,
pic0,
pic1,
snd0,
"app.prx",
"NULL" //DATA.PSAR not necessary.
});
pack_pbp.step.dependOn(&PBP.step);
//Enable the build
b.default_step.dependOn(&pack_pbp.step);
}