aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-05-18 16:40:24 +0200
committerBad Diode <bd@badd10de.dev>2021-05-18 16:40:24 +0200
commit0c7265cf0de9d4ec95d28c5e103c00a63f4a1697 (patch)
tree4a1145e849e078395430a8d718c4bd69a06fb29f /Makefile
downloaduxngba-0c7265cf0de9d4ec95d28c5e103c00a63f4a1697.tar.gz
uxngba-0c7265cf0de9d4ec95d28c5e103c00a63f4a1697.zip
Proof of concept of UXN on the GBA
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile74
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.
5DEVKITPRO := /opt/devkitpro
6DEVKITARM := /opt/devkitpro/devkitARM
7PATH := $(DEVKITARM)/bin:$(PATH)
8LIBGBA_DIR := $(DEVKITPRO)/libgba
9LIBGBA_SRC := /opt/devkitpro/libgba/include/
10LIBGBA := $(LIBGBA_DIR)/lib/libgba.a
11LIBGBA += $(LIBGBA_DIR)/lib/libfat.a
12LIBGBA += $(LIBGBA_DIR)/lib/libmm.a
13
14# Source code location and files to watch for changes.
15SRC_DIR := src
16SRC_MAIN := $(SRC_DIR)/main.c
17ASM_FILES := $(wildcard $(SRC_DIR)/*.s)
18WATCH_SRC := $(wildcard $(SRC_DIR)/*.c)
19WATCH_SRC += $(wildcard $(SRC_DIR)/*.h)
20WATCH_SRC += $(wildcard $(SRC_DIR)/*.s)
21
22# Output library names and executables.
23TARGET := uxngba
24BUILD_DIR := build
25ELF := $(BUILD_DIR)/$(TARGET).elf
26BIN := $(BUILD_DIR)/$(TARGET).gba
27
28# Compiler and linker configuration.
29CC := arm-none-eabi-gcc
30OBJCOPY := arm-none-eabi-objcopy
31ARCH := -mthumb -mthumb-interwork
32SPECS := -specs=gba.specs
33CFLAGS := -Wall -Wextra -pedantic -fno-strict-aliasing -Wno-incompatible-pointer-types
34CFLAGS += -mcpu=arm7tdmi -mtune=arm7tdmi $(ARCH)
35CFLAGS += -I$(LIBGBA_SRC)
36LDFLAGS := $(ARCH) $(SPECS)
37LDLIBS := $(LIBGBA)
38RELEASE_CFLAGS := -DNDEBUG -O2 -g
39DEBUG_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
46DEBUG ?= 0
47ifeq ($(DEBUG), 1)
48 CFLAGS += $(DEBUG_CFLAGS)
49else
50 CFLAGS += $(RELEASE_CFLAGS)
51endif
52
53main: $(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.
69run: main
70 mgba-qt $(BIN)
71
72# Remove build directory.
73clean:
74 rm -r $(BUILD_DIR)