diff --git a/Makefile b/Makefile index 40a44ceed4..f9023b08eb 100644 --- a/Makefile +++ b/Makefile @@ -44,9 +44,9 @@ VERSION ?= gc-eu-mq-dbg N_THREADS ?= $(shell nproc) # If DEBUG_OBJECTS is 1, produce additional debugging files such as objdump output or raw binaries for assets DEBUG_OBJECTS ?= 0 -# 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 indicates missing dependencies. -MIPS_BINUTILS_PREFIX ?= mips-linux-gnu- +# Supply a MIPS toolchain prefix to use (e.g. 'mips-linux-gnu-' or 'mips64-elf-') +# In nearly all cases, leave this blank. The most commonly used prefixes are automatically detected when this is blank. +MIPS_BINUTILS_PREFIX ?= # Emulator w/ flags for 'make run'. N64_EMULATOR ?= # Set to override game region in the ROM header (options: JP, US, EU). This can be used to build a fake US version @@ -270,12 +270,41 @@ else 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)) + +ifeq ($(MIPS_BINUTILS_PREFIX),) + # Try to find a known MIPS toolchain if one wasn't set + # - practicerom: https://github.com/PracticeROM/packages + # - libdragon: https://github.com/DragonMinded/libdragon/releases/tag/toolchain-continuous-prerelease + # - various mips-linux-gnu / mips64-linux-gnu packages available on common package managers + ifeq ($(shell type mips64-ultra-elf-ld >/dev/null 2>/dev/null; echo $$?), 0) # practicerom + MIPS_BINUTILS_PREFIX := mips64-ultra-elf- + else ifeq ($(shell type $(N64_GCCPREFIX)/bin/mips64-elf-ld >/dev/null 2>/dev/null; echo $$?), 0) # libdragon + MIPS_BINUTILS_PREFIX := $(N64_GCCPREFIX)/bin/mips64-elf- + else ifeq ($(shell type $(N64_INST)/bin/mips64-elf-ld >/dev/null 2>/dev/null; echo $$?), 0) # libdragon + MIPS_BINUTILS_PREFIX := $(N64_INST)/bin/mips64-elf- + else ifeq ($(shell type mips64-elf-ld >/dev/null 2>/dev/null; echo $$?), 0) # libdragon + MIPS_BINUTILS_PREFIX := mips64-elf- + else ifeq ($(shell type mips64-ld >/dev/null 2>/dev/null; echo $$?), 0) # practicerom + MIPS_BINUTILS_PREFIX := mips64- + else ifeq ($(shell type mips-linux-gnu-ld >/dev/null 2>/dev/null; echo $$?), 0) # on package managers + MIPS_BINUTILS_PREFIX := mips-linux-gnu- + else ifeq ($(shell type mips64-linux-gnu-ld >/dev/null 2>/dev/null; echo $$?), 0) # on package managers + MIPS_BINUTILS_PREFIX := mips64-linux-gnu- + else + $(error Unable to find a known MIPS toolchain. Refer to the README.) + endif +else + # If one was set, make sure it's present + ifneq ($(shell type $(MIPS_BINUTILS_PREFIX)ld >/dev/null 2>/dev/null; echo $$?), 0) + $(error Unable to find $(MIPS_BINUTILS_PREFIX)ld. Is $(MIPS_BINUTILS_PREFIX) correct?)) + endif endif # Detect compiler and set variables appropriately. ifeq ($(COMPILER),gcc) + ifneq ($(shell type $(MIPS_BINUTILS_PREFIX)gcc >/dev/null 2>/dev/null; echo $$?), 0) + $(error Unable to find $(MIPS_BINUTILS_PREFIX)gcc. Please install or build the corresponding MIPS gcc for this toolchain.) + endif CC := $(MIPS_BINUTILS_PREFIX)gcc CCAS := $(CC) -x assembler-with-cpp else ifeq ($(COMPILER),ido) diff --git a/README.md b/README.md index 5fd0e03b0e..89c87b13db 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,6 @@ The build process has the following package requirements: * git * build-essential -* binutils-mips-linux-gnu * curl * python3 * python3-pip @@ -96,18 +95,18 @@ Under Debian / Ubuntu (which we recommend using), you can install them with the ```bash sudo apt-get update -sudo apt-get install git build-essential binutils-mips-linux-gnu curl python3 python3-pip python3-venv libxml2-dev +sudo apt-get install git build-essential curl python3 python3-pip python3-venv libxml2-dev ``` -If you are using GCC as the compiler for Ocarina of Time, you will also need: +In addition to these packages, a MIPS binutils installation is required. The project aims to support a couple of commonly-encountered MIPS toolchains out-of-the-box, only one is required and is automatically detected: -* gcc-mips-linux-gnu +* mips64-ultra-elf- or mips64- from the [practicerom toolchain](https://github.com/PracticeROM/packages) +* mips64-elf- from the [libdragon n64 homebrew library](https://github.com/DragonMinded/libdragon/releases/tag/toolchain-continuous-prerelease) +* mips-linux-gnu- or mips64-linux-gnu- found in common distribution package managers as e.g. `binutils-mips-linux-gnu` -which can be installed under Debian / Ubuntu with: +If none of these are available to install, the makefile exposes `MIPS_BINUTILS_PREFIX` as a means to set your own toolchain prefix. Otherwise, consider building one of the first two options from source. -```bash -sudo apt-get install gcc-mips-linux-gnu -``` +If you are using GCC as the compiler for Ocarina of Time, you will also need the corresponding gcc compiler for the chosen toolchain. For the first two options above, gcc is included automatically. For mips-linux-gnu- or mips64-linux-gnu- it is often a separate package, e.g. `gcc-mips-linux-gnu`. #### 2. Clone the repository