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-10-19 23:29:40 +02:00
|
|
|
WORLD_AREAS := $(foreach dir, $(wildcard src/world/*), $(dir:src/world/%=%))
|
2020-10-19 06:42:17 +02:00
|
|
|
|
|
|
|
SRC_DIRS := src src/os src/os/nusys $(foreach area,$(WORLD_AREAS),src/world/$(area))
|
2020-08-02 06:29:52 +02:00
|
|
|
ASM_DIRS := asm asm/os
|
2020-10-15 01:31:16 +02:00
|
|
|
INCLUDE_DIRS := include include/PR src
|
2020-10-19 06:42:17 +02:00
|
|
|
DATA_DIRS := bin bin/world $(foreach area,$(WORLD_AREAS),bin/world/$(area))
|
2020-10-17 23:08:57 +02:00
|
|
|
YAY0_DIRS := bin/Yay0
|
2020-10-18 05:54:32 +02:00
|
|
|
ASSETS_FS_DIRS := assets/fs
|
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-15 01:12:41 +02:00
|
|
|
ifdef PM_HEADER_REBUILD
|
|
|
|
H_FILES := $(foreach dir,$(INCLUDE_DIRS),$(wildcard $(dir)/*.h))
|
|
|
|
endif
|
2020-04-28 02:22:56 +02:00
|
|
|
DATA_FILES := $(foreach dir,$(DATA_DIRS),$(wildcard $(dir)/*.bin))
|
2020-10-17 22:37:46 +02:00
|
|
|
YAY0_FILES := $(foreach dir,$(YAY0_DIRS),$(wildcard $(dir)/*.bin))
|
2020-10-18 05:54:32 +02:00
|
|
|
ASSETS_FS_FILES := $(foreach dir,$(ASSETS_FS_DIRS),$(wildcard $(dir)/*.*))
|
2020-04-28 02:22:56 +02:00
|
|
|
|
|
|
|
# Object files
|
|
|
|
O_FILES := $(foreach file,$(C_FILES),$(BUILD_DIR)/$(file:.c=.o)) \
|
2020-10-18 05:54:32 +02:00
|
|
|
$(foreach file,$(S_FILES),$(BUILD_DIR)/$(file:.s=.o)) \
|
|
|
|
$(foreach file,$(DATA_FILES),$(BUILD_DIR)/$(file:.bin=.o)) \
|
|
|
|
$(foreach dir,$(ASSETS_FS_DIRS),$(BUILD_DIR)/$(dir).o) \
|
2020-10-19 23:29:40 +02:00
|
|
|
$(foreach file,$(YAY0_FILES),$(BUILD_DIR)/$(file:.bin=.Yay0.o))
|
2020-04-28 02:22:56 +02:00
|
|
|
|
2020-10-19 23:29:40 +02:00
|
|
|
####################### Tools #########################
|
2020-08-13 04:13:48 +02:00
|
|
|
|
2020-10-19 23:29:40 +02:00
|
|
|
TOOLS = tools
|
|
|
|
N64CKSUM = $(TOOLS)/n64crc
|
|
|
|
SPLAT = ./$(TOOLS)/n64splat/split.py baserom.z64 $(TOOLS)/splat.yaml .
|
2019-03-07 00:33:29 +01:00
|
|
|
|
2020-05-12 05:00:21 +02:00
|
|
|
##################### Compiler Options #######################
|
|
|
|
CROSS = mips-linux-gnu-
|
|
|
|
AS = $(CROSS)as
|
2020-10-19 23:29:40 +02:00
|
|
|
OLD_AS = $(TOOLS)/mips-nintendo-nu64-as
|
|
|
|
CC = $(TOOLS)/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-09-11 22:29:52 +02:00
|
|
|
CPPFLAGS = -Iinclude -D _LANGUAGE_C -ffreestanding -DF3DEX_GBI_2
|
2020-09-02 20:35:25 +02:00
|
|
|
ASFLAGS = -EB -Iinclude -march=vr4300 -mtune=vr4300
|
2020-10-05 22:04:33 +02:00
|
|
|
OLDASFLAGS = -EB -Iinclude -G 0
|
2020-09-11 22:29:52 +02:00
|
|
|
CFLAGS = -O2 -quiet -G 0 -mcpu=vr4300 -mfix4300 -mips3 -mgp32 -mfp32
|
2020-10-15 06:18:54 +02:00
|
|
|
LDFLAGS = -T undefined_syms.txt -T undefined_funcs.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
|
|
|
|
2020-10-18 05:54:32 +02:00
|
|
|
$(foreach dir,$(SRC_DIRS) $(ASM_DIRS) $(DATA_DIRS) $(ASSETS_FS_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-10-14 22:00:38 +02:00
|
|
|
all: $(TARGET).ld $(BUILD_DIR) $(TARGET).z64 verify
|
2019-03-07 00:33:29 +01:00
|
|
|
|
|
|
|
clean:
|
2020-08-14 17:18:05 +02:00
|
|
|
rm -rf $(BUILD_DIR) $(TARGET).z64
|
2020-08-13 04:13:48 +02:00
|
|
|
|
|
|
|
submodules:
|
|
|
|
git submodule update --init --recursive
|
|
|
|
|
|
|
|
split:
|
2020-10-19 23:29:40 +02:00
|
|
|
rm -rf $(DATA_DIRS) && $(SPLAT) --modes ld bin Yay0 PaperMarioMapFS
|
2020-08-13 04:13:48 +02:00
|
|
|
|
2020-10-16 00:11:56 +02:00
|
|
|
split-all:
|
2020-10-19 23:29:40 +02:00
|
|
|
rm -rf $(DATA_DIRS) && $(SPLAT) --modes all
|
2020-10-12 20:46:04 +02:00
|
|
|
|
2020-08-20 07:42:31 +02:00
|
|
|
setup: clean submodules split
|
2020-10-19 23:29:40 +02:00
|
|
|
make -C $(TOOLS)
|
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
|
|
|
|
|
|
|
$(BUILD_DIR):
|
2020-08-15 04:52:44 +02:00
|
|
|
mkdir -p $(BUILD_DIR)
|
2019-03-07 00:33:29 +01: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-10-15 01:31:16 +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-10-18 05:54:32 +02:00
|
|
|
$(BUILD_DIR)/assets/fs/%: $(ASSETS_FS_FILES)
|
2020-10-19 23:29:40 +02:00
|
|
|
$(TOOLS)/build_assets_fs.py $*
|
2020-10-18 05:54:32 +02:00
|
|
|
|
2020-10-19 23:29:40 +02:00
|
|
|
$(BUILD_DIR)/assets/fs.bin: assets/fs.json $(TOOLS)/build_assets_fs.py $(foreach file,$(ASSETS_FS_FILES),build/$(file))
|
|
|
|
$(TOOLS)/build_assets_fs.py
|
2020-10-18 05:54:32 +02:00
|
|
|
|
|
|
|
$(BUILD_DIR)/assets/fs.o: $(BUILD_DIR)/assets/fs.bin
|
|
|
|
$(LD) -r -b binary -o $@ $<
|
|
|
|
|
2020-10-19 23:29:40 +02:00
|
|
|
$(BUILD_DIR)/%.Yay0.o: %.bin
|
|
|
|
mkdir -p build/bin/Yay0
|
|
|
|
$(TOOLS)/Yay0compress $< $<.Yay0
|
|
|
|
$(LD) -r -b binary -o $@ $<.Yay0
|
|
|
|
|
|
|
|
$(LD_SCRIPT): $(TOOLS)/splat.yaml
|
|
|
|
$(SPLAT) --modes ld
|
|
|
|
|
|
|
|
$(BUILD_DIR)/$(TARGET).elf: $(O_FILES) $(LD_SCRIPT)
|
|
|
|
@$(LD) $(LDFLAGS) -o $@ $(O_FILES)
|
|
|
|
|
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
|
|
|
|
2020-10-12 20:53:30 +02:00
|
|
|
.PHONY: all clean default
|