aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2022-10-15 13:06:31 +0200
committerBad Diode <bd@badd10de.dev>2022-10-15 13:06:31 +0200
commit7086953c37c98df53b7f13351e9ab07fc3cca6a1 (patch)
tree4fb5aa301568b4bb42565a9fbd9304749dc5182a /Makefile
downloaduxn64-7086953c37c98df53b7f13351e9ab07fc3cca6a1.tar.gz
uxn64-7086953c37c98df53b7f13351e9ab07fc3cca6a1.zip
Initial commit preparing the makefile
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile93
1 files changed, 93 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..62f0c8d
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,93 @@
1.POSIX:
2.SUFFIXES:
3
4# Paths for SDK.
5SDK_BASE := /opt/n64sdk
6SDK_BIN := $(SDK_BASE)/bin
7LIBULTRA_DIR := $(SDK_BASE)/libultra
8LIBULTRA_INC := $(LIBULTRA_DIR)/usr/include
9LIBULTRA := $(LIBULTRA_DIR)/usr/lib/libgultra.a
10
11# Source code location and files to watch for changes.
12SRC_DIR := src
13BUILD_DIR := build
14SRC_MAIN := $(SRC_DIR)/onetri.c \
15 $(SRC_DIR)/dram_stack.c \
16 $(SRC_DIR)/rdp_output.c
17SRC_OBJ := $(SRC_DIR)/static.c \
18 $(SRC_DIR)/cfb.c \
19 $(SRC_DIR)/rsp_cfb.c
20OBJECTS := $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(SRC_OBJ))
21
22WATCH_SRC := $(shell find $(SRC_DIR) -name "*.c" -or -name "*.s" -or -name "*.h")
23INC_DIRS := $(shell find $(SRC_DIR) -type d)
24INC_DIRS += $(LIBULTRA_INC)
25INC_FLAGS := $(addprefix -I,$(INC_DIRS))
26
27datafiles = $(SRC_DIR)/static.c $(SRC_DIR)/cfb.c $(SRC_DIR)/rsp_cfb.c
28dataobjects = $(datafiles:.c=.o)
29
30# Output names and executables.
31TARGET := blank
32ELF := $(BUILD_DIR)/$(TARGET).elf
33BIN := $(BUILD_DIR)/$(TARGET).n64
34
35# Main compilation tool paths.
36CC := $(SDK_BIN)/mips32-elf-gcc
37LD := $(SDK_BIN)/mips32-elf-ld
38AS := $(SDK_BIN)/mips32-elf-as
39OBJDUMP := $(SDK_BIN)/mips32-elf-objdump
40# TODO: Replace with internal tools to avoid dependencies.
41SPICY := $(SDK_BIN)/spicy
42MAKEMASK := $(SDK_BIN)/makemask
43
44# Compiler and linker configuration.
45CFLAGS := -Wall -Wextra -pedantic
46CFLAGS += -mabi=32 -mfix4300
47CFLAGS += -ffreestanding -G 0
48CFLAGS += $(INC_FLAGS)
49CFLAGS += -DF3DEX_GBI_2 -nostdlib -r
50LDFLAGS := -nostdlib -r
51LDLIBS := $(LIBULTRA) $(SDK_BASE)/lib/gcc/mips32-elf/13.0.0/libgcc.a
52RELEASE_CFLAGS := -O2 -DNDEBUG -D_FINALROM
53DEBUG_CFLAGS := -O0 -DDEBUG -D_FINALROM
54
55# Setup debug/release builds.
56# make clean && make <target> DEBUG=0
57# make clean && make <target> DEBUG=1
58DEBUG ?= 0
59ifeq ($(DEBUG), 1)
60 CFLAGS += $(DEBUG_CFLAGS)
61else
62 CFLAGS += $(RELEASE_CFLAGS)
63endif
64
65main: $(BIN)
66
67$(ELF): $(SRC_MAIN) $(WATCH_SRC)
68 mkdir -p $(BUILD_DIR)
69 $(CC) $(CFLAGS) $(LDFLAGS) -o $(ELF) $(SRC_MAIN) $(LDLIBS)
70
71$(BIN): $(ELF) $(OBJECTS) $(WATCH_SRC)
72 $(SPICY) -r $@ $(SRC_DIR)/spec \
73 --as_command="$(SDK_BIN)/mips32-elf-as" \
74 --cpp_command="$(SDK_BIN)/mips32-elf-gcc" \
75 --ld_command="$(SDK_BIN)/mips32-elf-ld" \
76 --objcopy_command="$(SDK_BIN)/mips32-elf-objcopy"
77 $(MAKEMASK) $(BIN)
78
79# Test the output .n64 in an emulator.
80run: $(BIN)
81 # TODO: Test roms with MAME or cen64 instead of mupen64 for better accuracy.
82 mupen64plus $(BIN)
83
84# Remove build directory.
85clean:
86 rm -rf $(BUILD_DIR)
87
88.PHONY: main run clean
89
90# Inference rules.
91$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
92 mkdir -p $(BUILD_DIR)
93 $(CC) $(CFLAGS) $< -o $@