Skip to content

Commit 503a8ee

Browse files
committed
bring build and tools up to date with pw64
1 parent b9e5672 commit 503a8ee

14 files changed

Lines changed: 318 additions & 23 deletions

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,16 @@
4646
asm/
4747
bin/
4848
build/
49+
nonmatchings/
4950

5051
# debug information files
5152
*.dwo
5253

5354
# miscellaneous
5455
*.swp
55-
56+
.venv/
57+
src/ultralib
58+
tools/n64crc
59+
.vscode/
60+
ctx.c
61+
__pycache__/

Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM ubuntu:24.04
2+
3+
# Create directory for mount
4+
RUN mkdir /superman64
5+
WORKDIR /superman64
6+
7+
# Install required packages
8+
ENV DEBIAN_FRONTEND=noninteractive
9+
10+
COPY packages.txt ./
11+
RUN apt-get update && \
12+
apt-get install -y $(cat packages.txt | tr '\n' ' ') && \
13+
rm -rf /var/lib/apt/lists/*
14+
15+
COPY requirements.txt ./
16+
RUN pip3 install -r requirements.txt --break-system-packages
17+
18+
# Set up user (if they don't exist)
19+
ARG login=manofsteel
20+
ARG uid=1001
21+
RUN id -u $uid &>/dev/null || adduser --system --uid $uid --group $login
22+
23+
# Set entrypoint
24+
RUN echo "#!/bin/bash\nexec \"\$@\"" > /entrypoint.sh && chmod +x /entrypoint.sh
25+
USER $uid
26+
ENTRYPOINT ["/entrypoint.sh"]

Makefile

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ ifeq ($(VERBOSE),0)
2020
V := @
2121
endif
2222

23+
RECOMP_BUILD ?= 0
24+
2325
# ------------------------------------------------------------------------------
2426
# Toolchain
2527
# ------------------------------------------------------------------------------
@@ -36,14 +38,29 @@ else
3638
$(error Unable to detect a suitable MIPS toolchain installed.)
3739
endif
3840

41+
# Prefer clang as C preprocessor if installed on the system
42+
ifneq (,$(call find-command,clang))
43+
CPP := clang
44+
CPPFLAGS := -E -P -x c -Wno-trigraphs -Wmissing-prototypes -Wstrict-prototypes -D_LANGUAGE_ASSEMBLY
45+
else
46+
CPP := cpp
47+
CPPFLAGS := -P -Wno-trigraphs -Wmissing-prototypes -Wstrict-prototypes -D_LANGUAGE_ASSEMBLY
48+
endif
49+
3950
TOOLS_DIR = tools
4051

4152
AS := $(CROSS)as
4253
LD := $(CROSS)ld
4354
OBJCOPY := $(CROSS)objcopy
4455
PYTHON := python3
45-
GCC_HOST := gcc
4656
GREP := grep -rl
57+
# prefer clang as host compiler if installed on the system.
58+
# this allows certain 32-bit CC_CHECK flags to work on arm hosts
59+
ifneq (,$(call find-command,clang))
60+
CC_CHECK := clang
61+
else
62+
CC_CHECK := gcc
63+
endif
4764

4865
CC := $(TOOLS_DIR)/ido-static-recomp/build/5.3/out/cc
4966

@@ -96,6 +113,9 @@ CRC := $(TOOLS_DIR)/n64crc
96113
OPT_FLAGS = -O2
97114
LOOP_UNROLL =
98115

116+
ASM_PROC_FLAGS = $(OPT_FLAGS)
117+
ASM_DEFINES = -D_LANGUAGE_ASSEMBLY
118+
99119
MIPSISET = -mips2 -32
100120

101121
INCLUDE_CFLAGS = -I. -Isrc -Iinclude -Iinclude/libultra -Iinclude/libultra/PR -Iinclude/libultra/compiler/ido -Ibin
@@ -109,6 +129,11 @@ GLOBAL_ASM_O_FILES := $(foreach file,$(GLOBAL_ASM_C_FILES:.c=.o),$(BUILD_DIR)/$(
109129

110130
DEFINES := -D_LANGUAGE_C -D_FINALROM -DWIN32 -DNDEBUG -DTARGET_N64 -DCOMPILING_LIBULTRA
111131
DEFINES += -DVERSION_US
132+
DEFINES += -DBUILD_VERSION=VERSION_I
133+
134+
ifneq ($(RECOMP_BUILD),0)
135+
DEFINES += -DRECOMP_BUILD
136+
endif
112137

113138
VERIFY = verify
114139

@@ -118,8 +143,13 @@ CFLAGS += $(DEFINES)
118143
CFLAGS += -woff 624,649,838,712,516,513,596,564,594,709,807
119144
CFLAGS += $(INCLUDE_CFLAGS)
120145

146+
# -m32 has compiler treat code as 32-bit, but only works on clang and x86_64 gcc
147+
# other architectures may need to rely on clang or a cross-compiler
148+
ifeq ($(shell getconf LONG_BIT),64)
149+
CHECK_ARCH := -m32
150+
endif
121151
CHECK_WARNINGS := -Wall -Wextra -Wno-format-security -Wno-unknown-pragmas -Wunused-function -Wno-unused-parameter -Wno-unused-variable -Wno-missing-braces -Wno-int-conversion -Wno-multichar
122-
CC_CHECK := $(GCC_HOST) -fsyntax-only -fno-builtin -fsigned-char -std=gnu90 -m32 $(CHECK_WARNINGS) $(INCLUDE_CFLAGS) $(DEFINES)
152+
CHECK_CFLAGS := -fsyntax-only -fno-builtin -fsigned-char -std=gnu90 $(CHECK_ARCH) $(CHECK_WARNINGS) $(INCLUDE_CFLAGS) $(DEFINES)
123153

124154
LD_FLAGS := -T $(LD_SCRIPT)
125155
LD_FLAGS += -T config/$(VERSION)/sym/hardware_regs.ld
@@ -144,6 +174,8 @@ endif
144174
# $(BUILD_DIR)/src/libultra/gu/lookathil.o: OPT_FLAGS := -O2
145175
# $(BUILD_DIR)/src/libultra/os/osVirtualtoPhysical.o: OPT_FLAGS := -O1
146176
# $(BUILD_DIR)/src/libultra/io/%.o: OPT_FLAGS := -O1
177+
$(BUILD_DIR)/src/libultra/libc/ll.o: OPT_FLAGS := -O1 -g0
178+
$(BUILD_DIR)/src/libultra/libc/ll.o: MIPSISET := -mips3 -32
147179

148180
# ------------------------------------------------------------------------------
149181
# Targets
@@ -165,7 +197,7 @@ no_verify: $(ROM_Z64)
165197
init: $(TOOLS_DIR)
166198
$(MAKE) clean
167199
$(MAKE) extract
168-
$(MAKE) -j
200+
$(MAKE) -j$(nproc)
169201

170202
extract: $(TOOLS_DIR)
171203
rm -rf asm
@@ -200,20 +232,29 @@ $(ROM_ELF): $(LD_SCRIPT) $(BUILD_DIR)/$(LIBULTRA) $(O_FILES) $(LANG_RNC_O_FILES)
200232
ifndef PERMUTER
201233
$(GLOBAL_ASM_O_FILES): $(BUILD_DIR)/%.o: %.c
202234
@printf "[$(YELLOW) syntax $(NO_COL)] $<\n"
203-
$(V)$(CC_CHECK) -MMD -MP -MT $@ -MF $(BUILD_DIR)/$*.d $<
235+
$(V)$(CC_CHECK) $(CHECK_CFLAGS) -MMD -MP -MT $@ -MF $(BUILD_DIR)/$*.d $<
204236
@printf "[$(GREEN) ido5.3 $(NO_COL)] $<\n"
205-
$(V)$(ASM_PROCESSOR) $(OPT_FLAGS) $< > $(BUILD_DIR)/$<
237+
$(V)$(ASM_PROCESSOR) $(ASM_PROC_FLAGS) $< > $(BUILD_DIR)/$<
206238
$(V)$(CC) -c $(CFLAGS) $(OPT_FLAGS) $(LOOP_UNROLL) $(MIPSISET) -o $@ $(BUILD_DIR)/$<
207-
$(V)$(ASM_PROCESSOR) $(OPT_FLAGS) $< --post-process $@ \
239+
$(V)$(ASM_PROCESSOR) $(ASM_PROC_FLAGS) $< --post-process $@ \
208240
--assembler "$(AS) $(ASFLAGS)" --asm-prelude $(ASM_PROCESSOR_DIR)/prelude.inc
209241
endif
210242

211243
# non asm-processor recipe
212244
$(BUILD_DIR)/%.o: %.c
213245
@printf "[$(YELLOW) syntax $(NO_COL)] $<\n"
214-
$(V)$(CC_CHECK) -MMD -MP -MT $@ -MF $(BUILD_DIR)/$*.d $<
246+
$(V)$(CC_CHECK) $(CHECK_CFLAGS) -MMD -MP -MT $@ -MF $(BUILD_DIR)/$*.d $<
247+
@printf "[$(GREEN) ido5.3 $(NO_COL)] $<\n"
248+
$(V)$(CC) -c $(CFLAGS) $(OPT_FLAGS) $(LOOP_UNROLL) $(MIPSISET) -o $@ $<
249+
250+
# Patch ll.o
251+
$(BUILD_DIR)/src/libultra/libc/ll.o: src/libultra/libc/ll.c
252+
@printf "[$(YELLOW) syntax $(NO_COL)] $<\n"
253+
$(V)$(CC_CHECK) $(CHECK_CFLAGS) -MMD -MP -MT $@ -MF $*.d $<
215254
@printf "[$(GREEN) ido5.3 $(NO_COL)] $<\n"
216255
$(V)$(CC) -c $(CFLAGS) $(OPT_FLAGS) $(LOOP_UNROLL) $(MIPSISET) -o $@ $<
256+
@printf "[$(CYAN) patch $(NO_COL)] $<\n"
257+
$(V)$(PYTHON) $(TOOLS_DIR)/set_o32abi_bit.py $@
217258

218259
$(BUILD_DIR)/$(LIBULTRA): $(LIBULTRA)
219260
$(V)mkdir -p $$(dirname $@)
@@ -222,7 +263,7 @@ $(BUILD_DIR)/$(LIBULTRA): $(LIBULTRA)
222263

223264
$(BUILD_DIR)/%.o: %.s
224265
@printf "[$(GREEN) as $(NO_COL)] $<\n"
225-
$(V)$(AS) $(ASFLAGS) -o $@ $<
266+
$(V)$(CPP) $(CPPFLAGS) $(INCLUDE_CFLAGS) -I $(dir $*) $(ASM_DEFINES) $< | $(AS) $(ASFLAGS) $(INCLUDE_CFLAGS) -o $@ -
226267

227268
$(BUILD_DIR)/%.o: %.bin
228269
@printf "[$(PINK) linker $(NO_COL)] $<\n"

diff_settings.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env python3
2+
3+
def apply(config, args):
4+
config['baseimg'] = 'baserom.us.z64'
5+
config['myimg'] = 'build/superman.us.z64'
6+
config['mapfile'] = 'build/superman.us.map'
7+
config['source_directories'] = ['./src','./include']
8+
config['objdump_flags'] = ['-M','reg-names=32']
9+
config['makeflags'] = ["KEEP_MDEBUG=1"]

packages.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
binutils-mips-linux-gnu
2+
gcc
3+
libc-dev
4+
libc6-dev
5+
python3
6+
python3-pip

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
ipl3checksum>=1.0.0,<2.0.0
2-
splat64[mips]==0.35.2
2+
splat64[mips]==0.39.1
33
mapfile_parser>=2.12.1,<3.0.0
4+
GitPython
45

src/libultra/libc/ldiv.c

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
1-
#include "common.h"
1+
#include "os_version.h"
2+
#include "stdlib.h"
23

3-
#pragma GLOBAL_ASM("asm/nonmatchings/libultra/libc/ldiv/lldiv.s")
4+
// TODO: these come from headers
5+
#ident "$Revision: 1.34 $"
6+
#ident "$Revision: 1.5 $"
7+
8+
lldiv_t lldiv(long long num, long long denom) {
9+
lldiv_t ret;
10+
11+
ret.quot = num / denom;
12+
ret.rem = num - denom * ret.quot;
13+
14+
if (ret.quot < 0 && ret.rem > 0) {
15+
ret.quot += 1;
16+
ret.rem -= denom;
17+
}
18+
19+
return ret;
20+
}
21+
22+
ldiv_t ldiv(long num, long denom) {
23+
ldiv_t ret;
24+
25+
ret.quot = num / denom;
26+
ret.rem = num - denom * ret.quot;
27+
28+
if (ret.quot < 0 && ret.rem > 0) {
29+
ret.quot += 1;
30+
ret.rem -= denom;
31+
}
32+
33+
return ret;
34+
}
435

5-
#pragma GLOBAL_ASM("asm/nonmatchings/libultra/libc/ldiv/ldiv.s")

src/libultra/libc/ll.c

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,48 @@
11
#include "common.h"
22

3-
#pragma GLOBAL_ASM("asm/nonmatchings/libultra/libc/ll/__ull_rshift.s")
3+
unsigned long long __ull_rshift(unsigned long long a0, unsigned long long a1) {
4+
return a0 >> a1;
5+
}
46

5-
#pragma GLOBAL_ASM("asm/nonmatchings/libultra/libc/ll/__ull_rem.s")
7+
unsigned long long __ull_rem(unsigned long long a0, unsigned long long a1) {
8+
return a0 % a1;
9+
}
610

7-
#pragma GLOBAL_ASM("asm/nonmatchings/libultra/libc/ll/__ull_div.s")
11+
unsigned long long __ull_div(unsigned long long a0, unsigned long long a1) {
12+
return a0 / a1;
13+
}
814

9-
#pragma GLOBAL_ASM("asm/nonmatchings/libultra/libc/ll/__ll_lshift.s")
15+
unsigned long long __ll_lshift(unsigned long long a0, unsigned long long a1) {
16+
return a0 << a1;
17+
}
1018

11-
#pragma GLOBAL_ASM("asm/nonmatchings/libultra/libc/ll/__ll_rem.s")
19+
long long __ll_rem(unsigned long long a0, long long a1) {
20+
return a0 % a1;
21+
}
1222

13-
#pragma GLOBAL_ASM("asm/nonmatchings/libultra/libc/ll/__ll_div.s")
23+
long long __ll_div(long long a0, long long a1) {
24+
return a0 / a1;
25+
}
1426

15-
#pragma GLOBAL_ASM("asm/nonmatchings/libultra/libc/ll/__ll_mul.s")
27+
unsigned long long __ll_mul(unsigned long long a0, unsigned long long a1) {
28+
return a0 * a1;
29+
}
1630

17-
#pragma GLOBAL_ASM("asm/nonmatchings/libultra/libc/ll/__ull_divremi.s")
31+
void __ull_divremi(unsigned long long* div, unsigned long long* rem, unsigned long long a2, unsigned short a3) {
32+
*div = a2 / a3;
33+
*rem = a2 % a3;
34+
}
1835

19-
#pragma GLOBAL_ASM("asm/nonmatchings/libultra/libc/ll/__ll_mod.s")
36+
long long __ll_mod(long long a0, long long a1) {
37+
long long tmp = a0 % a1;
2038

21-
#pragma GLOBAL_ASM("asm/nonmatchings/libultra/libc/ll/__ll_rshift.s")
39+
if ((tmp < 0 && a1 > 0) || (tmp > 0 && a1 < 0)) {
40+
tmp += a1;
41+
}
42+
43+
return tmp;
44+
}
45+
46+
long long __ll_rshift(long long a0, long long a1) {
47+
return a0 >> a1;
48+
}

tools/diff.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
asm-differ/diff.py

tools/discord_progress.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import requests
5+
import subprocess
6+
from git import Repo
7+
8+
repo = Repo('.')
9+
10+
def main(args):
11+
progress = subprocess.run(
12+
[ "python3", "-m", "mapfile_parser", "objdiff_report", "--version", args.version ],
13+
capture_output=True, text=True, check=True
14+
)
15+
progress_msg = progress.stdout
16+
17+
commit = repo.heads.main.commit
18+
commit_msg = commit.message.splitlines()[0]
19+
20+
content = {
21+
"embeds": [{
22+
"title": f"{commit_msg}",
23+
"description": f"{progress_msg}",
24+
"url": f"https://github.com/gcsmith/Pilotwings64Decomp/commit/{commit.hexsha}",
25+
"color": commit.authored_date & 0xFFFFFF
26+
}]
27+
}
28+
if args.skip_post:
29+
print(f"content: {content}");
30+
else:
31+
requests.post(args.discord_url, json=content)
32+
33+
if __name__ == "__main__":
34+
parser = argparse.ArgumentParser(description="Publish objdiff_report to Discord server")
35+
parser.add_argument("--discord_url", help="Discord webhook URL", required=True)
36+
parser.add_argument("--version", help="Select ROM version", default="us")
37+
parser.add_argument("--skip_post", help="Skip the post step", action='store_true')
38+
args = parser.parse_args()
39+
main(args)
40+

0 commit comments

Comments
 (0)