2019-03-07 00:33:29 +01:00
|
|
|
# Makefile to rebuild SM64 split image
|
|
|
|
|
2020-05-12 07:04:13 +02:00
|
|
|
SHELL=/bin/bash -o pipefail
|
|
|
|
|
2019-03-07 00:33:29 +01:00
|
|
|
################ Target Executable and Sources ###############
|
|
|
|
|
|
|
|
# BUILD_DIR is location where all build artifacts are placed
|
|
|
|
BUILD_DIR = build
|
|
|
|
|
2020-08-04 08:49:11 +02:00
|
|
|
SRC_DIRS := src src/os
|
2020-08-02 06:29:52 +02:00
|
|
|
ASM_DIRS := asm asm/os
|
2020-08-14 22:10:34 +02:00
|
|
|
INCLUDE_DIRS := include include/PR
|
2020-04-28 02:22:56 +02:00
|
|
|
DATA_DIRS := bin
|
2020-04-28 12:45:56 +02:00
|
|
|
COMPRESSED_DIRS := yay0
|
2020-04-28 02:22:56 +02:00
|
|
|
MAP_DIRS := Map_Assets.FS
|
2020-04-28 12:45:56 +02:00
|
|
|
BGM_DIRS := bgm
|
2020-08-14 22:10:34 +02:00
|
|
|
STAR_ROD_STRUCT_DIRS := tools/star-rod/database/structs/ram tools/star-rod/database/structs/rom tools/star-rod/database/structs/wip
|
2020-04-28 02:22:56 +02:00
|
|
|
|
|
|
|
# Source code files
|
|
|
|
C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
|
|
|
|
S_FILES := $(foreach dir,$(ASM_DIRS),$(wildcard $(dir)/*.s))
|
2020-08-14 22:10:34 +02:00
|
|
|
H_FILES := $(foreach dir,$(INCLUDE_DIRS),$(wildcard $(dir)/*.h))
|
2020-04-28 02:22:56 +02:00
|
|
|
DATA_FILES := $(foreach dir,$(DATA_DIRS),$(wildcard $(dir)/*.bin))
|
2020-04-28 12:45:56 +02:00
|
|
|
COMPRESSED_FILES := $(foreach dir,$(COMPRESSED_DIRS),$(wildcard $(dir)/*.yay0))
|
2020-04-28 02:22:56 +02:00
|
|
|
MAP_FILES := $(foreach dir,$(MAP_DIRS),$(wildcard $(dir)/*.FS))
|
2020-04-28 12:45:56 +02:00
|
|
|
BGM_FILES := $(foreach dir,$(BGM_DIRS),$(wildcard $(dir)/*.bgm))
|
2020-08-14 22:10:34 +02:00
|
|
|
STAR_ROD_STRUCT_FILES := $(foreach dir,$(STAR_ROD_STRUCT_DIRS),$(wildcard $(dir)/*.struct))
|
2020-04-28 02:22:56 +02:00
|
|
|
|
|
|
|
# Object files
|
|
|
|
O_FILES := $(foreach file,$(C_FILES),$(BUILD_DIR)/$(file:.c=.o)) \
|
|
|
|
$(foreach file,$(S_FILES),$(BUILD_DIR)/$(file:.s=.o)) \
|
|
|
|
$(foreach file,$(DATA_FILES),$(BUILD_DIR)/$(file:.bin=.o)) \
|
2020-04-28 12:45:56 +02:00
|
|
|
$(foreach file,$(COMPRESSED_FILES),$(BUILD_DIR)/$(file:.yay0=.yay0.o)) \
|
2020-04-28 02:22:56 +02:00
|
|
|
$(foreach file,$(MAP_FILES),$(BUILD_DIR)/$(file:.FS=.FS.o)) \
|
2020-04-28 12:45:56 +02:00
|
|
|
$(foreach file,$(BGM_FILES),$(BUILD_DIR)/$(file:.bgm=.bgm.o))
|
2020-04-28 02:22:56 +02:00
|
|
|
|
2020-08-13 04:13:48 +02:00
|
|
|
|
2019-03-07 00:33:29 +01:00
|
|
|
####################### Other Tools #########################
|
|
|
|
|
|
|
|
# N64 tools
|
2020-04-28 12:45:56 +02:00
|
|
|
TOOLS_DIR = tools
|
2019-03-07 00:33:29 +01:00
|
|
|
MIO0TOOL = $(TOOLS_DIR)/mio0
|
2020-04-28 12:45:56 +02:00
|
|
|
N64CKSUM = $(TOOLS_DIR)/n64crc
|
2019-03-07 00:33:29 +01:00
|
|
|
|
2020-05-12 05:00:21 +02:00
|
|
|
##################### Compiler Options #######################
|
|
|
|
CROSS = mips-linux-gnu-
|
|
|
|
CROSS_IRIX = mips-sgi-irix5-
|
|
|
|
AS = $(CROSS)as
|
|
|
|
OLD_AS = $(TOOLS_DIR)/mips-nintendo-nu64-as
|
|
|
|
CC = $(TOOLS_DIR)/cc1
|
2020-08-10 08:16:13 +02:00
|
|
|
LD = $(CROSS)ld
|
2020-05-12 05:00:21 +02:00
|
|
|
OBJDUMP = $(CROSS)objdump
|
|
|
|
OBJCOPY = $(CROSS)objcopy
|
|
|
|
|
2020-08-13 04:13:48 +02:00
|
|
|
TARGET = papermario
|
|
|
|
|
2020-08-04 00:47:02 +02:00
|
|
|
CPPFLAGS = -Iinclude -D _LANGUAGE_C -ffreestanding -DF3DEX_GBI_2
|
2020-08-01 18:55:49 +02:00
|
|
|
ASFLAGS = -EB -march=vr4300 -mtune=vr4300 -Iinclude
|
2020-08-02 06:29:52 +02:00
|
|
|
OLDASFLAGS= -EB -Iinclude
|
2020-08-08 07:25:36 +02:00
|
|
|
CFLAGS = -O2 -quiet -G 0 -mcpu=vr4300 -mfix4300 -mips3 -mgp32 -mfp32
|
2020-06-24 21:53:29 +02:00
|
|
|
LDFLAGS = -T undefined_syms.txt -T $(LD_SCRIPT) -Map $(BUILD_DIR)/papermario.map --no-check-sections
|
2020-05-12 05:00:21 +02:00
|
|
|
|
2019-03-07 00:33:29 +01:00
|
|
|
######################## Targets #############################
|
2020-04-28 12:45:56 +02:00
|
|
|
|
|
|
|
$(foreach dir,$(SRC_DIRS) $(ASM_DIRS) $(DATA_DIRS) $(COMPRESSED_DIRS) $(MAP_DIRS) $(BGM_DIRS),$(shell mkdir -p build/$(dir)))
|
2019-03-07 00:33:29 +01:00
|
|
|
|
|
|
|
default: all
|
|
|
|
|
2020-06-25 18:03:00 +02:00
|
|
|
LD_SCRIPT = $(TARGET).ld
|
2019-03-07 00:33:29 +01:00
|
|
|
|
2020-08-12 04:08:48 +02:00
|
|
|
all: $(BUILD_DIR) $(TARGET).z64 verify
|
2019-03-07 00:33:29 +01:00
|
|
|
|
|
|
|
clean:
|
2020-08-13 04:13:48 +02:00
|
|
|
rm -rf build $(TARGET).z64
|
|
|
|
|
|
|
|
submodules:
|
|
|
|
git submodule update --init --recursive
|
|
|
|
|
2020-08-13 04:32:41 +02:00
|
|
|
n64split:
|
|
|
|
make -C tools/n64splitter
|
|
|
|
|
2020-08-13 04:13:48 +02:00
|
|
|
split:
|
|
|
|
rm -rf $(DATA_DIRS) $(BGM_DIRS) && ./tools/n64splitter/bin/n64split -b -v -o . -c tools/n64split.yaml baserom.z64
|
|
|
|
|
2020-08-13 04:32:41 +02:00
|
|
|
setup: clean submodules n64split split
|
2019-03-07 00:33:29 +01:00
|
|
|
|
2020-04-28 02:22:56 +02:00
|
|
|
print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true
|
2019-03-07 00:33:29 +01:00
|
|
|
|
2020-08-14 22:10:34 +02:00
|
|
|
include/common_structs.h: tools/starrod_structs_to_h.py $(STAR_ROD_STRUCT_FILES)
|
|
|
|
python3 tools/starrod_structs_to_h.py
|
|
|
|
|
2019-03-07 00:33:29 +01:00
|
|
|
$(BUILD_DIR):
|
|
|
|
mkdir $(BUILD_DIR)
|
|
|
|
|
2020-05-12 05:00:21 +02:00
|
|
|
$(BUILD_DIR)/$(TARGET).elf: $(O_FILES) $(LD_SCRIPT)
|
2020-04-28 12:45:56 +02:00
|
|
|
@$(LD) $(LDFLAGS) -o $@ $(O_FILES)
|
2020-04-28 02:22:56 +02:00
|
|
|
|
2020-05-12 05:00:21 +02:00
|
|
|
$(BUILD_DIR)/%.o: %.s
|
|
|
|
$(AS) $(ASFLAGS) -o $@ $<
|
2020-04-28 02:22:56 +02:00
|
|
|
|
2020-08-14 22:10:34 +02:00
|
|
|
$(BUILD_DIR)/%.o: %.c $(H_FILES)
|
2020-08-02 06:29:52 +02:00
|
|
|
cpp $(CPPFLAGS) $< | $(CC) $(CFLAGS) -o - | $(OLD_AS) $(OLDASFLAGS) - -o $@
|
2020-04-28 02:22:56 +02:00
|
|
|
|
2020-05-12 05:00:21 +02:00
|
|
|
$(BUILD_DIR)/%.o: %.bin
|
|
|
|
$(LD) -r -b binary -o $@ $<
|
2020-04-28 02:22:56 +02:00
|
|
|
|
2020-05-12 05:00:21 +02:00
|
|
|
$(BUILD_DIR)/%.yay0.o: %.yay0
|
|
|
|
$(LD) -r -b binary -o $@ $<
|
2020-04-28 02:22:56 +02:00
|
|
|
|
2020-05-12 05:00:21 +02:00
|
|
|
$(BUILD_DIR)/%.FS.o: %.FS
|
|
|
|
$(LD) -r -b binary -o $@ $<
|
2020-04-28 12:45:56 +02:00
|
|
|
|
2020-05-12 05:00:21 +02:00
|
|
|
$(BUILD_DIR)/%.bgm.o: %.bgm
|
|
|
|
$(LD) -r -b binary -o $@ $<
|
2019-03-07 00:33:29 +01:00
|
|
|
|
|
|
|
$(BUILD_DIR)/$(TARGET).bin: $(BUILD_DIR)/$(TARGET).elf
|
|
|
|
$(OBJCOPY) $< $@ -O binary
|
|
|
|
|
|
|
|
# final z64 updates checksum
|
|
|
|
$(TARGET).z64: $(BUILD_DIR)/$(TARGET).bin
|
2020-04-28 12:45:56 +02:00
|
|
|
@cp $< $@
|
|
|
|
$(N64CKSUM) $@
|
2019-03-07 00:33:29 +01:00
|
|
|
|
2020-04-25 07:52:11 +02:00
|
|
|
verify: $(TARGET).z64
|
2020-04-28 12:45:56 +02:00
|
|
|
sha1sum -c checksum.sha1
|
2020-04-25 07:52:11 +02:00
|
|
|
|
2019-03-07 00:33:29 +01:00
|
|
|
.PHONY: all clean default diff test
|