2019-09-05 22:09:40 +00:00
|
|
|
# User configurable
|
|
|
|
|
|
|
|
REGION=ntsc
|
|
|
|
RELEASE=final
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Not user configurable
|
|
|
|
|
|
|
|
ROMID := $(REGION)-$(RELEASE)
|
|
|
|
E_DIR := extracted/$(ROMID)
|
|
|
|
B_DIR := build/$(ROMID)
|
2019-09-07 06:12:32 +00:00
|
|
|
|
|
|
|
QEMU_IRIX := tools/irix/qemu-irix
|
|
|
|
IRIX_ROOT := tools/irix/root
|
|
|
|
|
|
|
|
ifeq ($(shell type mips-linux-gnu-ld >/dev/null 2>/dev/null; echo $$?), 0)
|
|
|
|
TOOLCHAIN := mips-linux-gnu
|
|
|
|
else
|
|
|
|
TOOLCHAIN := mips64-elf
|
|
|
|
endif
|
|
|
|
|
2019-09-10 07:54:17 +00:00
|
|
|
ifeq ($(REGION),ntsc)
|
|
|
|
VERSION_CFLAGS := -DNTSC=1 -DPAL=0 -DJAP=0
|
|
|
|
endif
|
|
|
|
ifeq ($(REGION),pal)
|
|
|
|
VERSION_CFLAGS := -DNTSC=0 -DPAL=1 -DJAP=0
|
|
|
|
endif
|
|
|
|
ifeq ($(REGION),jap)
|
|
|
|
VERSION_CFLAGS := -DNTSC=0 -DPAL=0 -DJAP=1
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(RELEASE),beta)
|
|
|
|
RELEASE_CFLAGS := -DBETA=1 -DREL1_0 -DFINAL=0
|
|
|
|
endif
|
|
|
|
ifeq ($(RELEASE),1.0)
|
|
|
|
RELEASE_CFLAGS := -DBETA=0 -DREL1_1 -DFINAL=0
|
|
|
|
endif
|
|
|
|
ifeq ($(RELEASE),final)
|
|
|
|
RELEASE_CFLAGS := -DBETA=0 -DREL1_0 -DFINAL=1
|
|
|
|
endif
|
|
|
|
|
2019-10-07 07:50:26 +00:00
|
|
|
CFLAGS := $(VERSION_CFLAGS) $(RELEASE_CFLAGS) -Wo,-loopunroll,0 -Wab,-r4300_mul -non_shared -G 0 -Xcpluscomm -woff 819,820,852,821 -signed -I src/include -mips2
|
|
|
|
|
|
|
|
C_FILES := $(shell find src -name '*.c')
|
|
|
|
O_FILES := $(patsubst %.c, %.o, $(C_FILES))
|
2019-09-05 22:09:40 +00:00
|
|
|
|
2019-09-07 12:07:13 +00:00
|
|
|
default: all
|
2019-09-05 22:09:40 +00:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Extract related
|
|
|
|
|
|
|
|
extract:
|
|
|
|
tools/extract $(ROMID)
|
|
|
|
|
|
|
|
################################################################################
|
2019-09-07 12:07:13 +00:00
|
|
|
# Stage setup files
|
2019-09-05 22:09:40 +00:00
|
|
|
|
2019-10-07 07:50:26 +00:00
|
|
|
SETUP_C_FILES := $(wildcard src/files/setup/*.c)
|
|
|
|
SETUP_BIN_FILES := $(patsubst src/files/setup/%.c, $(B_DIR)/files/setup/U%.bin, $(SETUP_C_FILES))
|
|
|
|
SETUP_BINZ_FILES := $(patsubst src/files/setup/%.c, $(B_DIR)/files/U%Z, $(SETUP_C_FILES))
|
2019-09-05 22:09:40 +00:00
|
|
|
|
2019-10-07 07:50:26 +00:00
|
|
|
$(B_DIR)/files/setup/%.elf: src/files/setup/%.o
|
2019-09-07 12:07:13 +00:00
|
|
|
mkdir -p $(B_DIR)/files/setup
|
2019-09-29 01:57:51 +00:00
|
|
|
cp $< build/zero.tmp.o
|
|
|
|
$(TOOLCHAIN)-ld -T ld/zero.ld -o $@
|
|
|
|
rm -f build/zero.tmp.o
|
2019-09-07 12:07:13 +00:00
|
|
|
|
|
|
|
$(B_DIR)/files/setup/U%.bin: $(B_DIR)/files/setup/%.elf
|
|
|
|
$(TOOLCHAIN)-objcopy $< $@ -O binary
|
2019-09-05 22:09:40 +00:00
|
|
|
|
2019-09-07 12:07:13 +00:00
|
|
|
$(B_DIR)/files/U%Z: $(B_DIR)/files/setup/U%.bin
|
|
|
|
tools/rarezip $< > $@
|
|
|
|
|
2019-10-07 07:50:26 +00:00
|
|
|
stagesetup: $(SETUP_BIN_FILES)
|
|
|
|
|
2019-10-28 23:10:46 +00:00
|
|
|
################################################################################
|
|
|
|
# Tile files
|
|
|
|
|
|
|
|
TILE_S_FILES := $(wildcard src/files/bgdata/bg_*_tiles.s)
|
|
|
|
TILE_BIN_FILES := $(patsubst src/files/bgdata/%.s, $(B_DIR)/files/bgdata/bgdata/%.bin, $(TILE_S_FILES))
|
|
|
|
|
|
|
|
src/files/bgdata/%.o: src/files/bgdata/%.s
|
|
|
|
$(TOOLCHAIN)-as -I src/include -EB -o $@ $<
|
|
|
|
|
|
|
|
$(B_DIR)/files/bgdata/bgdata/%.elf: src/files/bgdata/%.o
|
|
|
|
mkdir -p $(B_DIR)/files/bgdata/bgdata
|
|
|
|
cp $< build/zero.tmp.o
|
|
|
|
$(TOOLCHAIN)-ld -T ld/zero.ld -o $@
|
|
|
|
rm -f build/zero.tmp.o
|
|
|
|
|
|
|
|
$(B_DIR)/files/bgdata/bgdata/%.bin: $(B_DIR)/files/bgdata/bgdata/%.elf
|
|
|
|
$(TOOLCHAIN)-objcopy $< $@ -O binary
|
|
|
|
|
|
|
|
tiles: $(TILE_BIN_FILES)
|
|
|
|
|
2019-09-07 12:07:13 +00:00
|
|
|
################################################################################
|
|
|
|
# Lang files
|
|
|
|
|
2019-10-07 07:50:26 +00:00
|
|
|
LANG_C_FILES := $(wildcard src/files/lang/*.c)
|
|
|
|
LANG_BIN_FILES := $(patsubst src/files/lang/%.c, $(B_DIR)/files/lang/L%.bin, $(LANG_C_FILES))
|
|
|
|
LANG_BINZ_FILES := $(patsubst src/files/lang/%.c, $(B_DIR)/files/L%, $(LANG_C_FILES))
|
2019-09-07 12:07:13 +00:00
|
|
|
|
2019-10-07 07:50:26 +00:00
|
|
|
$(B_DIR)/files/lang/%.elf: src/files/lang/%.o
|
2019-09-07 12:07:13 +00:00
|
|
|
mkdir -p $(B_DIR)/files/lang
|
2019-09-29 01:57:51 +00:00
|
|
|
cp $< build/zero.tmp.o
|
|
|
|
$(TOOLCHAIN)-ld -T ld/zero.ld -o $@
|
|
|
|
rm -f build/zero.tmp.o
|
2019-09-05 22:09:40 +00:00
|
|
|
|
2019-09-07 12:07:13 +00:00
|
|
|
$(B_DIR)/files/lang/L%.bin: $(B_DIR)/files/lang/%.elf
|
|
|
|
$(TOOLCHAIN)-objcopy $< $@ -O binary
|
|
|
|
|
|
|
|
$(B_DIR)/files/L%E: $(B_DIR)/files/lang/L%E.bin
|
|
|
|
tools/rarezip $< > $@
|
|
|
|
|
|
|
|
$(B_DIR)/files/L%J: $(B_DIR)/files/lang/L%J.bin
|
|
|
|
tools/rarezip $< > $@
|
|
|
|
|
|
|
|
$(B_DIR)/files/L%P: $(B_DIR)/files/lang/L%P.bin
|
|
|
|
tools/rarezip $< > $@
|
|
|
|
|
|
|
|
$(B_DIR)/files/L%Z: $(B_DIR)/files/lang/L%.bin
|
2019-09-05 22:09:40 +00:00
|
|
|
tools/rarezip $< > $@
|
|
|
|
|
2019-10-07 07:50:26 +00:00
|
|
|
lang: $(LANG_BIN_FILES)
|
|
|
|
|
2019-10-01 22:23:06 +00:00
|
|
|
################################################################################
|
|
|
|
# Boot
|
|
|
|
|
2019-10-31 11:37:26 +00:00
|
|
|
$(B_DIR)/ucode/boot.bin: $(B_DIR)/stage1.bin
|
2019-10-01 22:23:06 +00:00
|
|
|
mkdir -p $(B_DIR)/ucode
|
2019-10-31 11:37:26 +00:00
|
|
|
B_DIR=$(B_DIR) tools/extract-segment boot
|
2019-10-01 22:23:06 +00:00
|
|
|
|
2019-10-07 07:50:26 +00:00
|
|
|
boot: $(B_DIR)/ucode/boot.bin
|
|
|
|
|
2019-09-29 05:18:36 +00:00
|
|
|
################################################################################
|
|
|
|
# Library
|
|
|
|
|
2019-10-31 11:37:26 +00:00
|
|
|
$(B_DIR)/ucode/library.bin: $(B_DIR)/stage1.bin
|
2019-09-29 05:18:36 +00:00
|
|
|
mkdir -p $(B_DIR)/ucode
|
2019-10-31 11:37:26 +00:00
|
|
|
B_DIR=$(B_DIR) tools/extract-segment library
|
2019-09-29 05:18:36 +00:00
|
|
|
|
2019-10-07 07:50:26 +00:00
|
|
|
library: $(B_DIR)/ucode/library.bin
|
|
|
|
|
2019-09-05 22:09:40 +00:00
|
|
|
################################################################################
|
2019-09-29 01:57:51 +00:00
|
|
|
# Game setup file
|
2019-09-05 22:09:40 +00:00
|
|
|
|
2019-10-31 11:37:26 +00:00
|
|
|
$(B_DIR)/ucode/setup.bin: $(B_DIR)/stage1.bin
|
2019-09-29 01:57:51 +00:00
|
|
|
mkdir -p $(B_DIR)/ucode
|
2019-10-31 11:37:26 +00:00
|
|
|
B_DIR=$(B_DIR) tools/extract-segment setup
|
2019-09-05 22:09:40 +00:00
|
|
|
|
2019-10-07 07:50:26 +00:00
|
|
|
setup: $(B_DIR)/ucode/setup.bin
|
|
|
|
|
2019-09-10 07:54:17 +00:00
|
|
|
################################################################################
|
|
|
|
# Rarezip
|
|
|
|
|
2019-10-31 11:37:26 +00:00
|
|
|
$(B_DIR)/ucode/rarezip.bin: $(B_DIR)/stage1.bin
|
2019-10-07 07:50:26 +00:00
|
|
|
mkdir -p $(B_DIR)/ucode
|
2019-10-31 11:37:26 +00:00
|
|
|
B_DIR=$(B_DIR) tools/extract-segment rarezip
|
2019-09-10 07:54:17 +00:00
|
|
|
|
2019-10-07 07:50:26 +00:00
|
|
|
rarezip: $(B_DIR)/ucode/rarezip.bin
|
|
|
|
|
2019-09-07 12:07:13 +00:00
|
|
|
################################################################################
|
2019-10-04 07:29:31 +00:00
|
|
|
# Main game
|
|
|
|
|
2019-10-31 11:37:26 +00:00
|
|
|
$(B_DIR)/ucode/game.bin: $(B_DIR)/stage1.bin
|
2019-10-04 07:29:31 +00:00
|
|
|
mkdir -p $(B_DIR)/ucode
|
2019-10-31 11:37:26 +00:00
|
|
|
B_DIR=$(B_DIR) tools/extract-segment game
|
2019-10-04 07:29:31 +00:00
|
|
|
|
2019-10-07 07:50:26 +00:00
|
|
|
game: $(B_DIR)/ucode/game.bin
|
|
|
|
|
2019-10-04 13:28:39 +00:00
|
|
|
################################################################################
|
|
|
|
# gVars
|
|
|
|
|
2019-10-31 11:37:26 +00:00
|
|
|
$(B_DIR)/ucode/gvars.bin: $(B_DIR)/stage1.bin
|
2019-10-04 13:28:39 +00:00
|
|
|
mkdir -p $(B_DIR)/ucode
|
2019-10-31 11:37:26 +00:00
|
|
|
B_DIR=$(B_DIR) tools/extract-segment gvars
|
2019-10-04 13:28:39 +00:00
|
|
|
|
2019-10-07 07:50:26 +00:00
|
|
|
gvars: $(B_DIR)/ucode/gvars.bin
|
|
|
|
|
2019-10-04 07:29:31 +00:00
|
|
|
################################################################################
|
2019-09-07 12:07:13 +00:00
|
|
|
# Test related
|
|
|
|
|
2019-10-07 07:50:26 +00:00
|
|
|
test: all
|
|
|
|
@rm -f $(B_DIR)/*.elf
|
2019-10-28 23:10:46 +00:00
|
|
|
@diff -q $(E_DIR)/files/bgdata/bgdata/ $(B_DIR)/files/bgdata/bgdata/
|
2019-10-07 07:50:26 +00:00
|
|
|
@diff -q $(E_DIR)/files/lang/ $(B_DIR)/files/lang/
|
|
|
|
@diff -q $(E_DIR)/files/setup/ $(B_DIR)/files/setup/
|
2019-10-12 01:02:00 +00:00
|
|
|
@diff -rq --exclude=gvars.bin --exclude=rspboot.bin $(E_DIR)/ucode/ $(B_DIR)/ucode/
|
2019-09-07 12:07:13 +00:00
|
|
|
|
2019-09-05 22:09:40 +00:00
|
|
|
################################################################################
|
|
|
|
# Miscellaneous
|
|
|
|
|
2019-10-07 07:50:26 +00:00
|
|
|
%.o: %.c
|
|
|
|
python tools/asmpreproc/asm-processor.py -O2 $< | $(QEMU_IRIX) -silent -L $(IRIX_ROOT) $(IRIX_ROOT)/usr/bin/cc -c $(CFLAGS) tools/asmpreproc/include-stdin.c -o $@ -O2
|
|
|
|
python tools/asmpreproc/asm-processor.py -O2 $< --post-process $@ --assembler "$(TOOLCHAIN)-as -march=vr4300 -mabi=32" --asm-prelude tools/asmpreproc/prelude.s
|
|
|
|
|
2019-10-31 11:37:26 +00:00
|
|
|
$(B_DIR)/stage1.elf: $(O_FILES)
|
|
|
|
mkdir -p $(B_DIR)
|
|
|
|
$(TOOLCHAIN)-ld -T ld/stage1.ld --print-map -o $@ > $(B_DIR)/stage1.map
|
|
|
|
|
|
|
|
$(B_DIR)/stage1.bin: $(B_DIR)/stage1.elf
|
|
|
|
mkdir -p $(B_DIR)/ucode
|
|
|
|
$(TOOLCHAIN)-objcopy $< $@ -O binary
|
|
|
|
|
2019-10-28 23:10:46 +00:00
|
|
|
all: stagesetup lang boot library setup tiles rarezip game gvars
|
2019-09-07 12:07:13 +00:00
|
|
|
|
2019-10-07 07:50:26 +00:00
|
|
|
rom: all
|
2019-09-05 22:09:40 +00:00
|
|
|
tools/inject pd.$(ROMID).z64
|
|
|
|
|
|
|
|
clean:
|
|
|
|
rm -rf build/*
|
2019-10-07 07:50:26 +00:00
|
|
|
find src -name '*.o' -delete
|
2019-09-05 22:09:40 +00:00
|
|
|
|
2019-10-09 08:16:46 +00:00
|
|
|
binclean:
|
|
|
|
rm -f build/ntsc-final/ucode/*.bin
|
2019-10-12 01:02:00 +00:00
|
|
|
find src/{boot,game,gvars,library,rarezip,setup} -name '*.o' -delete
|