1- ROOTDIR = $( N64_INST )
2- GCCN64PREFIX = $( ROOTDIR ) /bin/mips64-elf-
3- CHKSUM64PATH = $( ROOTDIR ) /bin/chksum64
4- MKDFSPATH = $( ROOTDIR ) /bin/mkdfs
5- MKSPRITE = $( ROOTDIR ) /bin/mksprite
6- N64TOOL = $( ROOTDIR ) /bin/n64tool
7- LINK_FLAGS = -L $( ROOTDIR ) /lib -L $( ROOTDIR ) /mips64-elf/lib -ldragon -lc -lm -ldragonsys -Tn64.ld
8- PROG_NAME = 2048-64
9- CFLAGS = -std=gnu99 -march=vr4300 -mtune=vr4300 -O2 -Wall -Werror -I $( ROOTDIR ) /mips64-elf/include -Iinclude -I/usr/local/include/
10- ASFLAGS = -mtune=vr4300 -march=vr4300
11- CC = $( GCCN64PREFIX ) gcc
12- AS = $( GCCN64PREFIX ) as
13- LD = $( GCCN64PREFIX ) ld
14- OBJCOPY = $( GCCN64PREFIX ) objcopy
1+ ARES_BIN := /Applications/ares.app/Contents/MacOS/ares
2+
3+ BUILD_DIR := build
4+ SOURCE_DIR := src
5+ ROM_NAME := 2048-64
6+ N64_ROM_TITLE := "2048-64"
7+
8+ N64_MK_PATH := $( N64_INST ) /include/n64.mk
9+ ifneq (, $( wildcard $( N64_MK_PATH ) ) )
10+ include $( N64_MK_PATH )
11+ endif
12+
13+ N64_CFLAGS += -Iinclude
14+ N64_ASFLAGS += -Iinclude
1515
1616all : build
1717
1818build : # # Create rom.
19- @docker --version & > /dev/null
20- @if [ $$ ? -ne 0 ]; then echo " Building rom..." && make $(PROG_NAME ) .z64; fi
21- @if [ $$ ? -eq 0 ]; then echo " Building rom inside docker environment..." && make docker; fi
19+ @if command -v docker > /dev/null 2>&1 ; then \
20+ echo " Building rom inside docker environment..." ; \
21+ $(MAKE ) docker; \
22+ else \
23+ echo " Building rom..." ; \
24+ $(MAKE ) $(ROM_NAME ) .z64; \
25+ fi
2226
2327docker : setup
24- @docker run --user $(shell id -u) :$(shell id -g) -v ${CURDIR} :/game build make $(PROG_NAME ) .z64
28+ @docker run --user $(shell id -u) :$(shell id -g) -v ${CURDIR} :/game build make $(ROM_NAME ) .z64
2529
2630rebuild : clean build # # Erase temp files and create the rom.
2731
@@ -30,11 +34,7 @@ PNGS := $(wildcard resources/gfx/*/*.png) $(wildcard resources/gfx/*/*/*.png)
3034SPRITES := $(subst .png,.sprite,$(subst resources/,filesystem/,$(PNGS ) ) )
3135filesystem/gfx/sprites/% .sprite : resources/gfx/sprites/% .png
3236 @mkdir -p ` echo $@ | xargs dirname`
33- $(MKSPRITE ) 16 1 1 $< $@
34-
35- filesystem/gfx/maps/% .sprite : resources/gfx/maps/% .png
36- @mkdir -p ` echo $@ | xargs dirname`
37- $(MKSPRITE ) 16 1 1 $< $@
37+ $(N64_MKSPRITE ) 16 1 1 $< $@
3838
3939# sfx #
4040MP3S := $(wildcard resources/sfx/bgms/* .mp3)
@@ -44,43 +44,42 @@ filesystem/sfx/bgms/%.raw: resources/sfx/bgms/%.mp3
4444 sox $< -b 16 -e signed-integer -B -r 11025 $@ remix -
4545
4646# code #
47- SRCS := $(wildcard src/* .c)
48- OBJS := $(SRCS:.c=.o )
49- $(PROG_NAME ) .elf : $(OBJS )
50- $(LD ) -o $@ $^ $(LINK_FLAGS )
47+ SRCS := $(wildcard $(SOURCE_DIR ) /* .c)
48+ OBJS := $(SRCS:$(SOURCE_DIR ) /%.c=$(BUILD_DIR ) /%.o )
49+
50+ $(BUILD_DIR ) /$(ROM_NAME ) .elf : $(OBJS ) $(N64_LIBDIR ) /libdragon.a $(N64_LIBDIR ) /libdragonsys.a $(N64_LIBDIR ) /n64.ld
51+ @mkdir -p $(dir $@ )
52+ @echo " [LD] $@ "
53+ $(N64_CXX ) -o $@ $(filter % .o, $^ ) $(filter-out $(N64_LIBDIR ) /libdragon.a $(N64_LIBDIR ) /libdragonsys.a, $(filter % .a, $^ ) ) \
54+ -lc -mabi=o64 $(patsubst % ,-Wl$(COMMA ) % ,$(LDFLAGS ) ) -Wl,-Map=$(BUILD_DIR ) /$(ROM_NAME ) .map
55+ $(N64_SIZE ) -G $@
5156
52- $(PROG_NAME ) .bin : $(PROG_NAME ) .elf
53- $( OBJCOPY ) -O binary $< $@
57+ $(ROM_NAME ) .z64 : $(BUILD_DIR ) / $( ROM_NAME ) .elf
58+ $( ROM_NAME ) .z64 : $( ROM_NAME ) .dfs
5459
5560# dfs #
56- $(PROG_NAME ) .dfs : $(SPRITES ) $(BGMS )
61+ $(ROM_NAME ) .dfs : $(SPRITES ) $(BGMS )
5762 @mkdir -p ./filesystem/
5863 @echo ` git rev-parse HEAD` > ./filesystem/hash
59- $(MKDFSPATH ) $@ ./filesystem/
60-
61- # rom
62- $(PROG_NAME ) .z64 : $(PROG_NAME ) .bin $(PROG_NAME ) .dfs
63- @rm -f $@
64- $(N64TOOL ) -l 16M -t " $( PROG_NAME) " -h $(ROOTDIR ) /mips64-elf/lib/header -o $(PROG_NAME ) .z64 $(PROG_NAME ) .bin -s 1M $(PROG_NAME ) .dfs
65- $(CHKSUM64PATH ) $@
64+ $(N64_MKDFS ) $@ ./filesystem/ > /dev/null
6665
6766setup : # # Create dev environment (docker image).
68- @docker build -q -t build - < Dockerfile > /dev/null
67+ @docker build --platform linux/amd64 -t build - < Dockerfile
6968
7069resetup : # # Force recreate the dev environment (docker image).
7170 @echo " Rebuilding dev environment in docker..."
72- @docker build -q -t build --no-cache - < Dockerfile > /dev/null
71+ @docker build --platform linux/amd64 -t build --no-cache - < Dockerfile
7372
74- cen64 : # # Start rom in CEN64 emulator.
75- @echo " Starting cen64 ..."
76- $(CEN64_DIR ) /cen64 -multithread -controller num=1,pak=rumble $( CEN64_DIR ) /pifdata.bin $( PROG_NAME ) .z64
73+ ares : # # Start rom in Ares emulator.
74+ @echo " Starting ares ..."
75+ $(ARES_BIN ) $( ROM_NAME ) .z64
7776
7877flashair : # # Flash rom to EverDrive using a flashair SD card.
79- curl -X POST -F ' file=@$(PROG_NAME ).z64' http://flashair/upload.cgi
78+ curl -X POST -F ' file=@$(ROM_NAME ).z64' http://flashair/upload.cgi
8079
8180clean : # # Cleanup temp files.
8281 @echo " Cleaning up temp files..."
83- rm -rf * .z64 * .elf src/* .o * .bin * .dfs filesystem/
82+ rm -rf $( BUILD_DIR ) * .z64 * .elf src/* .o * .bin * .dfs filesystem/
8483
8584help : # # Show this help.
8685 @fgrep -h " ##" $(MAKEFILE_LIST ) | fgrep -v fgrep | sed -e ' s/:.*##/:/'
0 commit comments