summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorAnghelo Carvajal <angheloalf95@gmail.com>2023-03-28 23:42:56 -0300
committerGitHub <noreply@github.com>2023-03-29 03:42:56 +0100
commitd66a21685f45d130f980e8a5ec7b08cfe189e40b (patch)
treef11b3b09dc5772e419fe08d3d0ead4e778def57f /Makefile
parent6a5e64cc4c26398cc607bb02cdc12a056ddf42d1 (diff)
Initial repo setup (#1)
* git subrepo clone git@github.com:ethteck/splat.git tools/splat subrepo: subdir: "tools/splat" merged: "4fec014" upstream: origin: "git@github.com:ethteck/splat.git" branch: "master" commit: "4fec014" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * gitignore * decompress_baserom.py * Initial yaml * run flib * more yaml stuff * Builds an uncompressed ROM * setup ido download * git subrepo clone git@github.com:simonlindholm/asm-differ.git tools/asm-differ subrepo: subdir: "tools/asm-differ" merged: "ae40866" upstream: origin: "git@github.com:simonlindholm/asm-differ.git" branch: "main" commit: "ae40866" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo clone git@github.com:simonlindholm/asm-processor.git tools/asm-processor subrepo: subdir: "tools/asm-processor" merged: "bbd86ea" upstream: origin: "git@github.com:simonlindholm/asm-processor.git" branch: "main" commit: "bbd86ea" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo clone (merge) git@github.com:EllipticEllipsis/fado.git tools/fado subrepo: subdir: "tools/fado" merged: "8d896ee" upstream: origin: "git@github.com:EllipticEllipsis/fado.git" branch: "master" commit: "8d896ee" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * setup ido in makefile * data and rodata * add automatic file splits * bootstrap most symbol_addrs * git subrepo clone --branch=irix git@github.com:hensldm/ultralib.git lib/ultralib subrepo: subdir: "lib/ultralib" merged: "0d1e095" upstream: origin: "git@github.com:hensldm/ultralib.git" branch: "irix" commit: "0d1e095" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * setup ido building * various tooling * git subrepo pull tools/asm-differ subrepo: subdir: "tools/asm-differ" merged: "857b398" upstream: origin: "git@github.com:simonlindholm/asm-differ.git" branch: "main" commit: "857b398" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * Change defines to match IDO * review * newlin * update gitignore * Windows error * D_01000000 * yeet settings.json * yeet * git subrepo clone git@github.com:decompals/ultralib.git lib/ultralib subrepo: subdir: "lib/ultralib" merged: "d03b2a3" upstream: origin: "git@github.com:decompals/ultralib.git" branch: "main" commit: "d03b2a3" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * clangformat and clangtidy * Setup a bunch of headers * bootstrap boot and code functions and variables headers * global.h * update format.py includes * -D_MIPS_SZLONG=32 * format.py: --verbose * Update tools/decompress_baserom.py Co-authored-by: Derek Hensley <hensley.derek58@gmail.com> * Add libc to global.h * review * yeet saved_regs * yeet headers * yeet _MSC_VER * more header cleanup * add readme licensing note --------- Co-authored-by: Derek Hensley <hensley.derek58@gmail.com>
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile276
1 files changed, 276 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..f600f2b
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,276 @@
+# Build options can be changed by modifying the makefile or by building with 'make SETTING=value'.
+# It is also possible to override the settings in Defaults in a file called .make_options as 'SETTING=value'.
+
+-include .make_options
+
+MAKEFLAGS += --no-builtin-rules
+
+#### Defaults ####
+
+# If COMPARE is 1, check the output md5sum after building
+COMPARE ?= 1
+# If NON_MATCHING is 1, define the NON_MATCHING C flag when building
+NON_MATCHING ?= 0
+# if WERROR is 1, pass -Werror to CC_CHECK, so warnings would be treated as errors
+WERROR ?= 0
+# Keep .mdebug section in build
+KEEP_MDEBUG ?= 0
+# Check code syntax with host compiler
+RUN_CC_CHECK ?= 1
+CC_CHECK_COMP ?= clang
+# Dump build object files
+OBJDUMP_BUILD ?= 1
+
+# Set prefix to mips binutils binaries (mips-linux-gnu-ld => 'mips-linux-gnu-') - Change at your own risk!
+# In nearly all cases, not having 'mips-linux-gnu-*' binaries on the PATH is indicative of missing dependencies
+MIPS_BINUTILS_PREFIX ?= mips-linux-gnu-
+
+
+VERSION ?= jp
+
+BASEROM := baserom.$(VERSION).z64
+BASEROM_UNCOMPRESSED := baserom_uncompressed.$(VERSION).z64
+TARGET := animalforest
+
+
+### Output ###
+
+BUILD_DIR := build
+ROM := $(BUILD_DIR)/$(TARGET)_uncompressed.$(VERSION).z64
+ELF := $(BUILD_DIR)/$(TARGET).$(VERSION).elf
+LD_MAP := $(BUILD_DIR)/$(TARGET).$(VERSION).map
+LD_SCRIPT := linker_scripts/$(VERSION)/$(TARGET).ld
+ROMC := $(BUILD_DIR)/$(TARGET).$(VERSION).z64
+
+
+#### Setup ####
+
+BUILD_DEFINES ?=
+
+ifeq ($(VERSION),jp)
+ BUILD_DEFINES += -DVERSION_JP=1
+else
+ifeq ($(VERSION),cn)
+ BUILD_DEFINES += -DVERSION_CN=1 -DBBPLAYER=1
+else
+$(error Invalid VERSION variable detected. Please use either 'jp' or 'cn')
+endif
+endif
+
+
+ifeq ($(NON_MATCHING),1)
+ BUILD_DEFINES += -DNON_MATCHING -DAVOID_UB
+ COMPARE := 0
+endif
+
+MAKE = make
+CPPFLAGS += -fno-dollars-in-identifiers -P
+LDFLAGS := --no-check-sections --accept-unknown-input-arch --emit-relocs
+
+UNAME_S := $(shell uname -s)
+ifeq ($(OS),Windows_NT)
+$(error Native Windows is currently unsupported for building this repository, use WSL instead c:)
+else ifeq ($(UNAME_S),Linux)
+ DETECTED_OS := linux
+else ifeq ($(UNAME_S),Darwin)
+ DETECTED_OS := mac
+ MAKE := gmake
+ CPPFLAGS += -xc++
+endif
+
+#### Tools ####
+ifneq ($(shell type $(MIPS_BINUTILS_PREFIX)ld >/dev/null 2>/dev/null; echo $$?), 0)
+$(error Unable to find $(MIPS_BINUTILS_PREFIX)ld. Please install or build MIPS binutils, commonly mips-linux-gnu. (or set MIPS_BINUTILS_PREFIX if your MIPS binutils install uses another prefix))
+endif
+
+
+CC := tools/ido/$(DETECTED_OS)/7.1/cc
+CC_OLD := tools/ido/$(DETECTED_OS)/5.3/cc
+
+
+AS := $(MIPS_BINUTILS_PREFIX)as
+LD := $(MIPS_BINUTILS_PREFIX)ld
+OBJCOPY := $(MIPS_BINUTILS_PREFIX)objcopy
+OBJDUMP := $(MIPS_BINUTILS_PREFIX)objdump
+CPP := cpp
+ICONV := iconv
+ASM_PROC := python3 tools/asm-processor/build.py
+
+ASM_PROC_FLAGS := --input-enc=utf-8 --output-enc=euc-jp --convert-statics=global-with-filename
+
+SPLAT ?= tools/splat/split.py
+SPLAT_YAML ?= $(TARGET).$(VERSION).yaml
+
+
+
+IINC := -Iinclude -Ibin/$(VERSION) -I.
+IINC += -Ilib/ultralib/include -Ilib/ultralib/include/PR
+
+ifeq ($(KEEP_MDEBUG),0)
+ RM_MDEBUG = $(OBJCOPY) --remove-section .mdebug $@
+else
+ RM_MDEBUG = @:
+endif
+
+# Check code syntax with host compiler
+CHECK_WARNINGS := -Wall -Wextra -Wimplicit-fallthrough -Wno-unknown-pragmas -Wno-missing-braces -Wno-sign-compare -Wno-uninitialized
+# Have CC_CHECK pretend to be a MIPS compiler
+MIPS_BUILTIN_DEFS := -DMIPSEB -D_MIPS_FPSET=16 -D_MIPS_ISA=2 -D_ABIO32=1 -D_MIPS_SIM=_ABIO32 -D_MIPS_SZINT=32 -D_MIPS_SZPTR=32
+ifneq ($(RUN_CC_CHECK),0)
+# The -MMD flags additionaly creates a .d file with the same name as the .o file.
+ CC_CHECK := $(CC_CHECK_COMP)
+ CC_CHECK_FLAGS := -MMD -MP -fno-builtin -fsyntax-only -funsigned-char -fdiagnostics-color -std=gnu89 -m32 -DNON_MATCHING -DAVOID_UB -DCC_CHECK=1
+ ifneq ($(WERROR), 0)
+ CHECK_WARNINGS += -Werror
+ endif
+else
+ CC_CHECK := @:
+endif
+
+
+CFLAGS += -G 0 -non_shared -Xcpluscomm -nostdinc -Wab,-r4300_mul
+
+WARNINGS := -fullwarn -verbose -woff 624,649,838,712,516,513,596,564,594
+ASFLAGS := -march=vr4300 -32 -G0
+COMMON_DEFINES := -D_MIPS_SZLONG=32
+GBI_DEFINES := -DF3DEX_GBI_2
+RELEASE_DEFINES := -DNDEBUG -D_FINALROM
+AS_DEFINES := -DMIPSEB -D_LANGUAGE_ASSEMBLY -D_ULTRA64
+C_DEFINES := -DLANGUAGE_C -D_LANGUAGE_C
+ENDIAN := -EB
+
+OPTFLAGS := -O2
+MIPS_VERSION := -mips2
+ICONV_FLAGS := --from-code=UTF-8 --to-code=EUC-JP
+
+# Use relocations and abi fpr names in the dump
+OBJDUMP_FLAGS := --disassemble --reloc --disassemble-zeroes -Mreg-names=32 -Mno-aliases
+
+ifneq ($(OBJDUMP_BUILD), 0)
+ OBJDUMP_CMD = $(OBJDUMP) $(OBJDUMP_FLAGS) $@ > $(@:.o=.dump.s)
+ OBJCOPY_BIN = $(OBJCOPY) -O binary $@ $@.bin
+else
+ OBJDUMP_CMD = @:
+ OBJCOPY_BIN = @:
+endif
+
+
+#### Files ####
+
+$(shell mkdir -p asm bin linker_scripts/$(VERSION)/auto)
+
+SRC_DIRS := $(shell find src -type d)
+ASM_DIRS := $(shell find asm/$(VERSION) -type d -not -path "asm/$(VERSION)/nonmatchings/*")
+BIN_DIRS := $(shell find bin -type d)
+
+C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
+S_FILES := $(foreach dir,$(ASM_DIRS) $(SRC_DIRS),$(wildcard $(dir)/*.s))
+BIN_FILES := $(foreach dir,$(BIN_DIRS),$(wildcard $(dir)/*.bin))
+O_FILES := $(foreach f,$(C_FILES:.c=.o),$(BUILD_DIR)/$f) \
+ $(foreach f,$(S_FILES:.s=.o),$(BUILD_DIR)/$f) \
+ $(foreach f,$(BIN_FILES:.bin=.o),$(BUILD_DIR)/$f)
+
+
+# Automatic dependency files
+DEP_FILES := $(O_FILES:.o=.d) \
+ $(O_FILES:.o=.asmproc.d)
+
+# create build directories
+$(shell mkdir -p $(BUILD_DIR)/linker_scripts/$(VERSION) $(BUILD_DIR)/linker_scripts/$(VERSION)/auto $(foreach dir,$(SRC_DIRS) $(ASM_DIRS) $(BIN_DIRS),$(BUILD_DIR)/$(dir)))
+
+
+# directory flags
+
+# per-file flags
+
+# cc & asm-processor
+build/src/%.o: CC := $(ASM_PROC) $(ASM_PROC_FLAGS) $(CC) -- $(AS) $(ASFLAGS) --
+
+
+#### Main Targets ###
+
+all: uncompressed
+
+uncompressed: $(ROM)
+ifneq ($(COMPARE),0)
+ @md5sum $(ROM)
+ @md5sum -c $(TARGET)_uncompressed.$(VERSION).md5
+endif
+
+# TODO
+# compressed: $(ROMC)
+# ifneq ($(COMPARE),0)
+# @md5sum $(ROMC)
+# @md5sum -c $(TARGET).$(VERSION).md5
+# endif
+
+clean:
+ $(RM) -r $(BUILD_DIR)/asm $(BUILD_DIR)/bin $(BUILD_DIR)/src $(ROM) $(ROMC) $(ELF)
+
+libclean:
+ $(RM) -r $(BUILD_DIR)/lib
+
+distclean: clean
+ $(RM) -r $(BUILD_DIR) asm/ bin/ .splat/
+ $(RM) -r linker_scripts/$(VERSION)/auto $(LD_SCRIPT)
+ $(MAKE) -C tools distclean
+
+setup:
+ $(MAKE) -C tools
+ python3 tools/decompress_baserom.py
+
+extract:
+ $(RM) -r asm/$(VERSION) bin/$(VERSION)
+ $(SPLAT) $(SPLAT_YAML)
+
+diff-init: all
+ $(RM) -rf expected/
+ mkdir -p expected/
+ cp -r $(BUILD_DIR) expected/$(BUILD_DIR)
+
+init:
+ $(MAKE) distclean
+ $(MAKE) setup
+ $(MAKE) extract
+ $(MAKE) all
+ $(MAKE) diff-init
+
+.PHONY: all compressed uncompressed clean distclean setup extract diff-init init
+.DEFAULT_GOAL := all
+# Prevent removing intermediate files
+.SECONDARY:
+
+
+#### Various Recipes ####
+
+$(ROM): $(ELF)
+ $(OBJCOPY) -O binary --pad-to=0x1914000 --gap-fill=0xFF $< $@
+
+# TODO: avoid using auto/undefined
+$(ELF): $(O_FILES) $(LD_SCRIPT) $(BUILD_DIR)/linker_scripts/$(VERSION)/hardware_regs.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/undefined_syms.ld $(BUILD_DIR)/linker_scripts/common_undef_syms.ld $(BUILD_DIR)/linker_scripts/libultra_syms.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/auto/undefined_syms_auto.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/auto/undefined_funcs_auto.ld
+ $(LD) $(LDFLAGS) -T $(LD_SCRIPT) \
+ -T $(BUILD_DIR)/linker_scripts/$(VERSION)/hardware_regs.ld -T $(BUILD_DIR)/linker_scripts/$(VERSION)/undefined_syms.ld -T $(BUILD_DIR)/linker_scripts/common_undef_syms.ld -T $(BUILD_DIR)/linker_scripts/libultra_syms.ld \
+ -T $(BUILD_DIR)/linker_scripts/$(VERSION)/auto/undefined_syms_auto.ld -T $(BUILD_DIR)/linker_scripts/$(VERSION)/auto/undefined_funcs_auto.ld \
+ -Map $(LD_MAP) -o $@
+
+
+$(BUILD_DIR)/%.ld: %.ld
+ $(CPP) $(CPPFLAGS) $(BUILD_DEFINES) $(IINC) $< > $@
+
+$(BUILD_DIR)/%.o: %.bin
+ $(OBJCOPY) -I binary -O elf32-big $< $@
+
+$(BUILD_DIR)/%.o: %.s
+ $(CPP) $(CPPFLAGS) $(BUILD_DEFINES) $(IINC) -I $(dir $*) $(COMMON_DEFINES) $(RELEASE_DEFINES) $(GBI_DEFINES) $(AS_DEFINES) $< | $(ICONV) $(ICONV_FLAGS) | $(AS) $(ASFLAGS) $(ENDIAN) $(IINC) -I $(dir $*) -o $@
+ $(OBJDUMP_CMD)
+
+$(BUILD_DIR)/%.o: %.c
+ $(CC_CHECK) $(CC_CHECK_FLAGS) $(IINC) -I $(dir $*) $(CHECK_WARNINGS) $(BUILD_DEFINES) $(COMMON_DEFINES) $(RELEASE_DEFINES) $(GBI_DEFINES) $(C_DEFINES) $(MIPS_BUILTIN_DEFS) -o $@ $<
+ $(CC) -c $(CFLAGS) $(BUILD_DEFINES) $(IINC) $(WARNINGS) $(MIPS_VERSION) $(ENDIAN) $(COMMON_DEFINES) $(RELEASE_DEFINES) $(GBI_DEFINES) $(C_DEFINES) $(OPTFLAGS) -o $@ $<
+ $(OBJDUMP_CMD)
+ $(RM_MDEBUG)
+
+-include $(DEP_FILES)
+
+# Print target for debugging
+print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true