diff --git a/Makefile b/Makefile index 33f7fd95..906c4097 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,9 @@ MAKEFLAGS += --no-builtin-rules --no-print-directory +# Returns the path to the command $(1) if exists. Otherwise returns an empty string. +find-command = $(shell which $(1) 2>/dev/null) + #### Defaults #### # If COMPARE is 1, check the output md5sum after building @@ -30,8 +33,16 @@ VERBOSE ?= 0 PRINT ?= printf # 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- +# Auto-detect prefix for MIPS toolchain +ifneq ($(call find-command,mips-linux-gnu-ld),) + MIPS_BINUTILS_PREFIX := mips-linux-gnu- +else ifneq ($(call find-command,mips64-linux-gnu-ld),) + MIPS_BINUTILS_PREFIX := mips64-linux-gnu- +else ifneq ($(call find-command,mips64-elf-ld),) + MIPS_BINUTILS_PREFIX := mips64-elf- +else + $(error Unable to detect a suitable MIPS toolchain installed) +endif VERSION ?= us @@ -81,7 +92,7 @@ else ifeq ($(UNAME_S),Linux) CC_CHECK_COMP := arm-linux-gnueabihf-gcc endif else ifeq ($(UNAME_S),Darwin) - DETECTED_OS := mac + DETECTED_OS := macos MAKE := gmake CPPFLAGS += -xc++ endif @@ -123,11 +134,19 @@ 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 := $(PYTHON) $(TOOLS)/asm-processor/build.py CAT := cat +# Prefer clang as C preprocessor if installed on the system +ifneq (,$(call find-command,clang)) + CPP := clang + CPPFLAGS := -E -P -x c -Wno-trigraphs -D_LANGUAGE_ASSEMBLY +else + CPP := cpp + CPPFLAGS := -P -Wno-trigraphs -D_LANGUAGE_ASSEMBLY +endif + ASM_PROC_FLAGS := --input-enc=utf-8 --output-enc=euc-jp --convert-statics=global-with-filename SPLAT ?= $(PYTHON) $(TOOLS)/splat/split.py @@ -286,7 +305,7 @@ init: SF := ___ ___\n/ __|| _|\n\__ \| _|\n|___/|_|\n uncompressed: $(ROM) ifneq ($(COMPARE),0) - @echo "$(GREEN)Calculating Rom Header Checksum... $(YELLOW)$<$(NO_COL)" + @echo "$(GREEN)Calculating Rom Header Checksum... $(YELLOW)$<$(NO_COL)" @$(PYTHON) $(COMPTOOL) -r $(ROM) . @md5sum --status -c $(TARGET).$(VERSION).uncompressed.md5 && \ $(PRINT) "$(BLUE)$(TARGET).$(VERSION).uncompressed.z64$(NO_COL): $(GREEN)OK$(NO_COL)\n$(YELLOW) $(SF)" || \ diff --git a/README.md b/README.md index c937880b..cd982062 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,16 @@ Under Debian / Ubuntu (which we recommend using), you can install them with the ```bash sudo apt update -sudo apt install make git build-essential binutils-mips-linux-gnu python3 python3-pip clang-format-14 clang-tidy +sudo apt install make git build-essential binutils-mips-linux-gnu python3 python3-pip clang-format-14 clang-tidy +``` + +### MacOS + +#### 1. Install build dependencies +Install [Homebrew](https://brew.sh) and the following dependencies: +``` +brew update +brew install coreutils make pkg-config tehzz/n64-dev/mips64-elf-binutils ``` #### 2. Clone the repository diff --git a/tools/Makefile b/tools/Makefile index 8b8ac768..9feee76a 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -2,11 +2,13 @@ CC = gcc UNAME_S := $(shell uname -s) ifeq ($(OS),Windows_NT) - $(error Native Windows is currently unsupported for building this repository, use WSL instead c:) + $(error Native Windows is currently unsupported for building this repository, use WSL instead c:) else ifeq ($(UNAME_S),Linux) DETECTED_OS := linux + MIO0_FLAGS := --gc-sections else ifeq ($(UNAME_S),Darwin) - DETECTED_OS := mac + DETECTED_OS := macos + MIO0_FLAGS := endif RECOMP_DIR := ido-recomp/$(DETECTED_OS) @@ -30,6 +32,6 @@ recomp: mio0: @echo "Building mio0..." - $(CC) -Wall -Wextra -Wno-format-overflow -O2 -ffunction-sections -fdata-sections -DMIO0_STANDALONE -s -Wl,--gc-sections -o mio0 mio0-decompressor/libmio0.c + $(CC) -Wall -Wextra -Wno-format-overflow -O2 -ffunction-sections -fdata-sections -DMIO0_STANDALONE -s -Wl,${MIO0_FLAGS} -o mio0 mio0-decompressor/libmio0.c .PHONY: all clean distclean default diff --git a/tools/requirements-python.txt b/tools/requirements-python.txt index 9d8bda30..1f5686f7 100644 --- a/tools/requirements-python.txt +++ b/tools/requirements-python.txt @@ -1,4 +1,4 @@ -spimdisasm==1.17.0 +spimdisasm==1.20.0 rabbitizer==1.7.0 PyYAML pylibyaml