diff options
author | Bad Diode <bd@badd10de.dev> | 2022-10-15 13:06:31 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2022-10-15 13:06:31 +0200 |
commit | 7086953c37c98df53b7f13351e9ab07fc3cca6a1 (patch) | |
tree | 4fb5aa301568b4bb42565a9fbd9304749dc5182a /Makefile | |
download | uxn64-7086953c37c98df53b7f13351e9ab07fc3cca6a1.tar.gz uxn64-7086953c37c98df53b7f13351e9ab07fc3cca6a1.zip |
Initial commit preparing the makefile
Diffstat (limited to 'Makefile')
-rw-r--r-- | Makefile | 93 |
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. | ||
5 | SDK_BASE := /opt/n64sdk | ||
6 | SDK_BIN := $(SDK_BASE)/bin | ||
7 | LIBULTRA_DIR := $(SDK_BASE)/libultra | ||
8 | LIBULTRA_INC := $(LIBULTRA_DIR)/usr/include | ||
9 | LIBULTRA := $(LIBULTRA_DIR)/usr/lib/libgultra.a | ||
10 | |||
11 | # Source code location and files to watch for changes. | ||
12 | SRC_DIR := src | ||
13 | BUILD_DIR := build | ||
14 | SRC_MAIN := $(SRC_DIR)/onetri.c \ | ||
15 | $(SRC_DIR)/dram_stack.c \ | ||
16 | $(SRC_DIR)/rdp_output.c | ||
17 | SRC_OBJ := $(SRC_DIR)/static.c \ | ||
18 | $(SRC_DIR)/cfb.c \ | ||
19 | $(SRC_DIR)/rsp_cfb.c | ||
20 | OBJECTS := $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(SRC_OBJ)) | ||
21 | |||
22 | WATCH_SRC := $(shell find $(SRC_DIR) -name "*.c" -or -name "*.s" -or -name "*.h") | ||
23 | INC_DIRS := $(shell find $(SRC_DIR) -type d) | ||
24 | INC_DIRS += $(LIBULTRA_INC) | ||
25 | INC_FLAGS := $(addprefix -I,$(INC_DIRS)) | ||
26 | |||
27 | datafiles = $(SRC_DIR)/static.c $(SRC_DIR)/cfb.c $(SRC_DIR)/rsp_cfb.c | ||
28 | dataobjects = $(datafiles:.c=.o) | ||
29 | |||
30 | # Output names and executables. | ||
31 | TARGET := blank | ||
32 | ELF := $(BUILD_DIR)/$(TARGET).elf | ||
33 | BIN := $(BUILD_DIR)/$(TARGET).n64 | ||
34 | |||
35 | # Main compilation tool paths. | ||
36 | CC := $(SDK_BIN)/mips32-elf-gcc | ||
37 | LD := $(SDK_BIN)/mips32-elf-ld | ||
38 | AS := $(SDK_BIN)/mips32-elf-as | ||
39 | OBJDUMP := $(SDK_BIN)/mips32-elf-objdump | ||
40 | # TODO: Replace with internal tools to avoid dependencies. | ||
41 | SPICY := $(SDK_BIN)/spicy | ||
42 | MAKEMASK := $(SDK_BIN)/makemask | ||
43 | |||
44 | # Compiler and linker configuration. | ||
45 | CFLAGS := -Wall -Wextra -pedantic | ||
46 | CFLAGS += -mabi=32 -mfix4300 | ||
47 | CFLAGS += -ffreestanding -G 0 | ||
48 | CFLAGS += $(INC_FLAGS) | ||
49 | CFLAGS += -DF3DEX_GBI_2 -nostdlib -r | ||
50 | LDFLAGS := -nostdlib -r | ||
51 | LDLIBS := $(LIBULTRA) $(SDK_BASE)/lib/gcc/mips32-elf/13.0.0/libgcc.a | ||
52 | RELEASE_CFLAGS := -O2 -DNDEBUG -D_FINALROM | ||
53 | DEBUG_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 | ||
58 | DEBUG ?= 0 | ||
59 | ifeq ($(DEBUG), 1) | ||
60 | CFLAGS += $(DEBUG_CFLAGS) | ||
61 | else | ||
62 | CFLAGS += $(RELEASE_CFLAGS) | ||
63 | endif | ||
64 | |||
65 | main: $(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. | ||
80 | run: $(BIN) | ||
81 | # TODO: Test roms with MAME or cen64 instead of mupen64 for better accuracy. | ||
82 | mupen64plus $(BIN) | ||
83 | |||
84 | # Remove build directory. | ||
85 | clean: | ||
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 $@ | ||