Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ BINUTILS_URL = https://ftp.gnu.org/gnu/binutils/$(BINUTILS_VERS
GCC_URL = https://ftp.gnu.org/gnu/gcc/$(GCC_VERSION)/$(GCC_VERSION).tar.xz
NEWLIB_URL = https://sourceware.org/pub/newlib/$(NEWLIB_VERSION).tar.gz
GDB_URL = https://ftp.gnu.org/gnu/gdb/$(GDB_VERSION).tar.xz
N64_TOOLCHAIN_ARCHIVE_DIR = @N64_TOOLCHAIN_ARCHIVE_DIR@
BINUTILS_ARCHIVE = @BINUTILS_ARCHIVE@
GCC_ARCHIVE = @GCC_ARCHIVE@
NEWLIB_ARCHIVE = @NEWLIB_ARCHIVE@
GDB_ARCHIVE = @GDB_ARCHIVE@
BINUTILS_SUBDIRS = bfd binutils cpu gas ld libctf libsframe opcodes
NEWLIB_SUBDIRS = libgloss newlib
GDB_SUBDIRS = gdb gdbsupport gnulib readline sim
Expand All @@ -27,11 +32,17 @@ NEWLIB_SYMLINKS = $(NEWLIB_SUBDIRS:%=$(GCC_VERSION)/%)
GDB_SYMLINKS = $(GDB_SUBDIRS:%=$(GCC_VERSION)/%)
GCC_IN_TREE_DEPS = @GCC_IN_TREE_DEPS@
CONFIG_TOOLCHAIN = @CONFIG_TOOLCHAIN@
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
CFLAGS_FOR_TARGET = @CFLAGS_FOR_TARGET@
CXXFLAGS_FOR_TARGET = @CXXFLAGS_FOR_TARGET@
MKDIR_P = @MKDIR_P@
WGET = @WGET@
TOOLCHAIN_PATH = @TOOLCHAIN_PATH@

ifneq ($(strip $(TOOLCHAIN_PATH)),)
export PATH := $(TOOLCHAIN_PATH):$(PATH)
endif

all:

Expand Down Expand Up @@ -91,27 +102,33 @@ $(DISTCLEANPROGS):
$(MKDIR_P) $(@)

src-binutils:
$(WGET) - "$(BINUTILS_URL)" | tar xJ
archive="$(BINUTILS_ARCHIVE)"; \
if test -z "$$archive" && test -n "$(N64_TOOLCHAIN_ARCHIVE_DIR)"; then archive="$(N64_TOOLCHAIN_ARCHIVE_DIR)/$(BINUTILS_VERSION).tar.xz"; fi; \
if test -n "$$archive"; then test -f "$$archive" || { echo "Missing local archive: $$archive" >&2; exit 1; }; cat "$$archive"; else $(WGET) - "$(BINUTILS_URL)"; fi | tar xJ
touch $(@)

src-gcc:
$(WGET) - "$(GCC_URL)" | tar xJ
archive="$(GCC_ARCHIVE)"; \
if test -z "$$archive" && test -n "$(N64_TOOLCHAIN_ARCHIVE_DIR)"; then archive="$(N64_TOOLCHAIN_ARCHIVE_DIR)/$(GCC_VERSION).tar.xz"; fi; \
if test -n "$$archive"; then test -f "$$archive" || { echo "Missing local archive: $$archive" >&2; exit 1; }; cat "$$archive"; else $(WGET) - "$(GCC_URL)"; fi | tar xJ
if [ x"$(GCC_IN_TREE_DEPS)" = x"yes" ]; then \
cd $(GCC_VERSION) && ./contrib/download_prerequisites; \
fi
for d in $(BINUTILS_SUBDIRS); do \
sed -i s@module_srcdir=$${d}\\b@module_srcdir=../$(BINUTILS_VERSION)/$${d}@g $(GCC_VERSION)/Makefile.in; \
"$(srcdir)/config/replace-module-srcdir" "$(GCC_VERSION)/Makefile.in" "$${d}" "../$(BINUTILS_VERSION)/$${d}"; \
done
for d in $(NEWLIB_SUBDIRS); do \
sed -i s@module_srcdir=$${d}\\b@module_srcdir=../$(NEWLIB_VERSION)/$${d}@g $(GCC_VERSION)/Makefile.in; \
"$(srcdir)/config/replace-module-srcdir" "$(GCC_VERSION)/Makefile.in" "$${d}" "../$(NEWLIB_VERSION)/$${d}"; \
done
for d in $(GDB_SUBDIRS); do \
sed -i s@module_srcdir=$${d}\\b@module_srcdir=../$(GDB_VERSION)/$${d}@g $(GCC_VERSION)/Makefile.in; \
"$(srcdir)/config/replace-module-srcdir" "$(GCC_VERSION)/Makefile.in" "$${d}" "../$(GDB_VERSION)/$${d}"; \
done
touch $(@)

src-newlib:
$(WGET) - "$(NEWLIB_URL)" | tar xz
archive="$(NEWLIB_ARCHIVE)"; \
if test -z "$$archive" && test -n "$(N64_TOOLCHAIN_ARCHIVE_DIR)"; then archive="$(N64_TOOLCHAIN_ARCHIVE_DIR)/$(NEWLIB_VERSION).tar.gz"; fi; \
if test -n "$$archive"; then test -f "$$archive" || { echo "Missing local archive: $$archive" >&2; exit 1; }; cat "$$archive"; else $(WGET) - "$(NEWLIB_URL)"; fi | tar xz
# for newlib = 4.6.0.20260123
if patch -t -N --dry-run -d $(NEWLIB_VERSION) -p 1 <"$(srcdir)/config/newlib/fix-mips3.diff"; then \
patch -t -N -d $(NEWLIB_VERSION) -p 1 <"$(srcdir)/config/newlib/fix-mips3.diff"; \
Expand All @@ -123,7 +140,9 @@ src-newlib:
touch $(@)

src-gdb:
$(WGET) - "$(GDB_URL)" | tar xJ
archive="$(GDB_ARCHIVE)"; \
if test -z "$$archive" && test -n "$(N64_TOOLCHAIN_ARCHIVE_DIR)"; then archive="$(N64_TOOLCHAIN_ARCHIVE_DIR)/$(GDB_VERSION).tar.xz"; fi; \
if test -n "$$archive"; then test -f "$$archive" || { echo "Missing local archive: $$archive" >&2; exit 1; }; cat "$$archive"; else $(WGET) - "$(GDB_URL)"; fi | tar xJ
touch $(@)

src-all: src-binutils src-gcc src-newlib src-gdb
Expand Down Expand Up @@ -205,6 +224,7 @@ build-toolchain/config.status: | build-toolchain/
--disable-multilib \
--disable-threads \
--disable-nls \
CPPFLAGS="$(CPPFLAGS)" \
LDFLAGS="$(LDFLAGS)" \
CFLAGS_FOR_TARGET="$(CFLAGS_FOR_TARGET)" \
CXXFLAGS_FOR_TARGET="$(CXXFLAGS_FOR_TARGET)" \
Expand Down
25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,40 @@ mips64, with `-march=vr4300` and `-mabi=32` as defaults for `gcc`.

## Prerequisites
You'll need to have these packages installed: `wget tar make diffutils texinfo
gcc g++ lua5.3 jansson libusb-1.0 libgmp`. See Installation, step 4. If you
want to use the included `luapatch` program with BizHawk, you should set the
gcc g++ lua zlib jansson libusb-1.0 libgmp libmpfr libmpc`. See Installation,
step 3. If you want to use the included `luapatch` program with BizHawk, you should set the
`EMUDIR` environment variable to the path to your BizHawk installation.

## Installation
### Prebuilt packages
Binary packages are available, see https://github.com/PracticeROM/packages.
Packages are built from the `n64-ultra` branch and target `mips64-ultra-elf`

### macOS
Install the Xcode command-line tools and Homebrew, then run `./install_deps`.
Use `gmake` for the toolchain targets. Homebrew dependency paths and keg-only
GNU sed and texinfo tools are detected automatically during configuration.

On Apple Silicon, current independently released GDB and binutils sources may
not be compatible when combined. GDB is enabled by default for source builds;
configure with `--disable-toolchain-gdb` when it is not needed. Homebrew
formulae may select this option automatically on affected hosts.

### Local toolchain archives
Network downloads remain the default. To use local archives, set
`N64_TOOLCHAIN_ARCHIVE_DIR` to a directory containing files named like
`binutils-X.Y.tar.xz`, `gcc-X.Y.Z.tar.xz`, `newlib-X.Y.Z.YYYYMMDD.tar.gz`, and
`gdb-X.Y.tar.xz`. Individual archives can be selected with `BINUTILS_ARCHIVE`,
`GCC_ARCHIVE`, `NEWLIB_ARCHIVE`, and `GDB_ARCHIVE`.

### Building from source
1. If you're on Windows, download and install MSYS2 from
[here](https://msys2.github.io/). Open a `MSYS2 MinGW 64-bit` shell.
2. Clone the repository and navigate into it by running
`git clone https://github.com/glankk/n64 && cd n64`.
3. Optionally, have the included script try to install the prerequisite
packages automatically by running `./install_deps`. You'll need root
privileges for this.
packages automatically by running `./install_deps`. Homebrew runs without
root; other package managers may require administrator privileges.
4. Configure the package with `./configure --prefix=/opt/n64`. You may use
another installation prefix if you wish. To enable Wii VC compatibility,
append ` --enable-vc` to the configure command. To produce portable Windows
Expand Down
35 changes: 35 additions & 0 deletions config/replace-module-srcdir
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env sh
# Portably update a GCC top-level module_srcdir assignment. This replaces the
# previous GNU-sed-only use of sed -i and GNU word-boundary matching.
set -eu

if test "$#" -ne 3; then
echo "usage: $0 FILE MODULE REPLACEMENT" >&2
exit 2
fi

file=$1
module=$2
replacement=$3
tmp="${file}.n64-tmp.$$"
trap 'rm -f "$tmp"' EXIT HUP INT TERM

awk -v module="$module" -v replacement="$replacement" '
{
needle = "module_srcdir=" module
content = $0
sub(/^[[:space:]]*/, "", content)
indent_length = length($0) - length(content)
if (index(content, needle) == 1) {
suffix = substr(content, length(needle) + 1)
if (suffix == "" || suffix ~ /^[[:space:]]/) {
indent = substr($0, 1, indent_length)
$0 = indent "module_srcdir=" replacement suffix
}
}
print
}
' "$file" > "$tmp"

mv "$tmp" "$file"
trap - EXIT HUP INT TERM
19 changes: 19 additions & 0 deletions config/version-sort
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env sh
# Sort archive stems containing dotted numeric versions without GNU sort -V.
# Input examples: gcc-15.1.0, newlib-4.6.0.20260123.
set -e
LC_ALL=C awk '
{
original = $0
version = $0
sub(/^[^0-9]*/, "", version)
count = split(version, part, ".")
key = ""
for (i = 1; i <= 12; ++i) {
value = (i <= count ? part[i] : 0)
sub(/[^0-9].*$/, "", value)
key = key sprintf("%012d", value + 0)
}
print key "\t" original
}
' | LC_ALL=C sort | cut -f2-
Loading