diff options
author | Bad Diode <bd@badd10de.dev> | 2021-05-18 16:40:24 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2021-05-18 16:40:24 +0200 |
commit | 0c7265cf0de9d4ec95d28c5e103c00a63f4a1697 (patch) | |
tree | 4a1145e849e078395430a8d718c4bd69a06fb29f /Makefile | |
download | uxngba-0c7265cf0de9d4ec95d28c5e103c00a63f4a1697.tar.gz uxngba-0c7265cf0de9d4ec95d28c5e103c00a63f4a1697.zip |
Proof of concept of UXN on the GBA
Diffstat (limited to 'Makefile')
-rw-r--r-- | Makefile | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6d7a5ec --- /dev/null +++ b/Makefile | |||
@@ -0,0 +1,74 @@ | |||
1 | .POSIX: | ||
2 | .SUFFIXES: | ||
3 | |||
4 | # Path to the development kit (devkitARM) and the GBA library. | ||
5 | DEVKITPRO := /opt/devkitpro | ||
6 | DEVKITARM := /opt/devkitpro/devkitARM | ||
7 | PATH := $(DEVKITARM)/bin:$(PATH) | ||
8 | LIBGBA_DIR := $(DEVKITPRO)/libgba | ||
9 | LIBGBA_SRC := /opt/devkitpro/libgba/include/ | ||
10 | LIBGBA := $(LIBGBA_DIR)/lib/libgba.a | ||
11 | LIBGBA += $(LIBGBA_DIR)/lib/libfat.a | ||
12 | LIBGBA += $(LIBGBA_DIR)/lib/libmm.a | ||
13 | |||
14 | # Source code location and files to watch for changes. | ||
15 | SRC_DIR := src | ||
16 | SRC_MAIN := $(SRC_DIR)/main.c | ||
17 | ASM_FILES := $(wildcard $(SRC_DIR)/*.s) | ||
18 | WATCH_SRC := $(wildcard $(SRC_DIR)/*.c) | ||
19 | WATCH_SRC += $(wildcard $(SRC_DIR)/*.h) | ||
20 | WATCH_SRC += $(wildcard $(SRC_DIR)/*.s) | ||
21 | |||
22 | # Output library names and executables. | ||
23 | TARGET := uxngba | ||
24 | BUILD_DIR := build | ||
25 | ELF := $(BUILD_DIR)/$(TARGET).elf | ||
26 | BIN := $(BUILD_DIR)/$(TARGET).gba | ||
27 | |||
28 | # Compiler and linker configuration. | ||
29 | CC := arm-none-eabi-gcc | ||
30 | OBJCOPY := arm-none-eabi-objcopy | ||
31 | ARCH := -mthumb -mthumb-interwork | ||
32 | SPECS := -specs=gba.specs | ||
33 | CFLAGS := -Wall -Wextra -pedantic -fno-strict-aliasing -Wno-incompatible-pointer-types | ||
34 | CFLAGS += -mcpu=arm7tdmi -mtune=arm7tdmi $(ARCH) | ||
35 | CFLAGS += -I$(LIBGBA_SRC) | ||
36 | LDFLAGS := $(ARCH) $(SPECS) | ||
37 | LDLIBS := $(LIBGBA) | ||
38 | RELEASE_CFLAGS := -DNDEBUG -O2 -g | ||
39 | DEBUG_CFLAGS := -DDEBUG -O2 -g | ||
40 | |||
41 | .PHONY: clean run | ||
42 | |||
43 | # Setup debug/release builds. | ||
44 | # make clean && make <target> DEBUG=0 | ||
45 | # make clean && make <target> DEBUG=1 | ||
46 | DEBUG ?= 0 | ||
47 | ifeq ($(DEBUG), 1) | ||
48 | CFLAGS += $(DEBUG_CFLAGS) | ||
49 | else | ||
50 | CFLAGS += $(RELEASE_CFLAGS) | ||
51 | endif | ||
52 | |||
53 | main: $(BUILD_DIR) $(BIN) | ||
54 | |||
55 | # Strip and fix header to create final .gba file. | ||
56 | $(BIN): $(ELF) | ||
57 | $(OBJCOPY) -v -O binary $(ELF) $(BIN) | ||
58 | gbafix $(BIN) | ||
59 | |||
60 | # Link files. | ||
61 | $(ELF): $(SRC_MAIN) $(WATCH_SRC) | ||
62 | $(CC) $(CFLAGS) $(LDFLAGS) -o $(ELF) $(SRC_MAIN) $(ASM_FILES) $(LDLIBS) | ||
63 | |||
64 | # Create build directory if needed. | ||
65 | $(BUILD_DIR): | ||
66 | mkdir -p $(BUILD_DIR) | ||
67 | |||
68 | # Test the output .gba in an emulator. | ||
69 | run: main | ||
70 | mgba-qt $(BIN) | ||
71 | |||
72 | # Remove build directory. | ||
73 | clean: | ||
74 | rm -r $(BUILD_DIR) | ||