forked from stople/OpenTitus
-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.zig
130 lines (114 loc) · 4.89 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//
// Copyright (C) 2008 - 2024 The OpenTitus team
//
// Authors:
// Eirik Stople
// Petr Mrázek
//
// "Titus the Fox: To Marrakech and Back" (1992) and
// "Lagaf': Les Aventures de Moktar - Vol 1: La Zoubida" (1991)
// was developed by, and is probably copyrighted by Titus Software,
// which, according to Wikipedia, stopped buisness in 2005.
//
// OpenTitus is not affiliated with Titus Software.
//
// OpenTitus is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 3 of the License,
// or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
const std = @import("std");
const Step = std.Build.Step;
const ResolvedTarget = std.Build.ResolvedTarget;
const LazyPath = std.Build.LazyPath;
const C_STANDARD = std.Build.CStd.C11;
fn build_game(b: *std.Build, name: []const u8, target: ResolvedTarget, optimize: std.builtin.Mode) *Step.Compile {
const exe = b.addExecutable(.{
.name = name,
.root_source_file = .{ .path = "main.zig" },
.target = target,
.optimize = optimize,
});
if (target.query.os_tag == .windows) {
exe.subsystem = .Windows;
}
// NOTE: the use of bit shifts of negative numbers is quite extensive, so we disable ubsan shooting us in the foot with those...
// FIXME: remove the UB-ness
exe.addCSourceFiles(.{ .files = &.{
"src/enemies.c",
"src/objects.c",
"src/player.c",
"src/audio/opl3/opl3.c",
"src/audio/miniaudio/miniaudio.c",
"src/audio/pocketmod/pocketmod.c",
}, .flags = &.{
"-fno-sanitize=shift",
} });
exe.addIncludePath(LazyPath.relative("src/"));
exe.addIncludePath(LazyPath.relative("src/audio/opl3/"));
exe.addIncludePath(LazyPath.relative("src/audio/miniaudio/"));
exe.addIncludePath(LazyPath.relative("src/audio/pocketmod/"));
exe.linkLibC();
exe.linkSystemLibrary("m");
exe.linkSystemLibrary("SDL2");
exe.linkSystemLibrary("SDL2main");
const game_tests = b.addTest(.{
.root_source_file = .{ .path = "main.zig" },
.target = target,
.optimize = optimize,
});
game_tests.addCSourceFiles(.{ .files = &.{
"src/enemies.c",
"src/objects.c",
"src/player.c",
"src/audio/opl3/opl3.c",
"src/audio/miniaudio/miniaudio.c",
"src/audio/pocketmod/pocketmod.c",
}, .flags = &.{
"-fno-sanitize=shift",
} });
game_tests.addIncludePath(LazyPath.relative("src/"));
game_tests.addIncludePath(LazyPath.relative("src/audio/opl3/"));
game_tests.addIncludePath(LazyPath.relative("src/audio/miniaudio/"));
game_tests.addIncludePath(LazyPath.relative("src/audio/pocketmod/"));
game_tests.linkLibC();
game_tests.linkSystemLibrary("m");
game_tests.linkSystemLibrary("SDL2");
game_tests.linkSystemLibrary("SDL2main");
const run_game_tests = b.addRunArtifact(game_tests);
// This creates a build step. It will be visible in the `zig build --help` menu,
// and can be selected like this: `zig build test`
// This will evaluate the `test` step rather than the default, which is "install".
const test_step = b.step("test", "Run tests");
test_step.dependOn(&run_game_tests.step);
return exe;
}
// Although this function looks imperative, note that its job is to
// declaratively construct a build graph that will be executed by an external
// runner.
pub fn build(b: *std.Build) void {
// TODO: we first need to set up SDL2 for cross-compilation
//const target = TARGETS[0];
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});
// Standard optimization options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});
const game = build_game(b, "game", target, optimize);
// This declares intent for the library to be installed into the standard
// location when the user invokes the "install" step (the default step when
// running `zig build`).
const wf = b.addWriteFiles();
wf.addCopyFileToSource(game.getEmittedBin(), "bin/moktar/openmoktar");
wf.addCopyFileToSource(game.getEmittedBin(), "bin/titus/opentitus");
b.getInstallStep().dependOn(&wf.step);
}