summaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile72
1 files changed, 72 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..46564cc
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,72 @@
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
17WATCH_SRC := $(wildcard $(SRC_DIR)/*.c)
18WATCH_SRC += $(wildcard $(SRC_DIR)/*.h)
19
20# Output library names and executables.
21BIN_NAME := template
22BUILD_DIR := build
23ELF := $(BUILD_DIR)/$(BIN_NAME).elf
24BIN := $(BUILD_DIR)/$(BIN_NAME).gba
25
26# Compiler and linker configuration.
27CC := arm-none-eabi-gcc
28OBJCOPY := arm-none-eabi-objcopy
29ARCH := -mthumb -mthumb-interwork
30SPECS := -specs=gba.specs
31CFLAGS := -g -Wall -Wextra -pedantic
32CFLAGS += -mcpu=arm7tdmi -mtune=arm7tdmi $(ARCH)
33CFLAGS += -I$(LIBGBA_SRC)
34LDFLAGS := $(ARCH) $(SPECS)
35LDLIBS := $(LIBGBA)
36RELEASE_CFLAGS := -DNDEBUG -O2
37DEBUG_CFLAGS := -DDEBUG -O2
38
39.PHONY: clean run
40
41# Setup debug/release builds.
42# make clean && make <target> DEBUG=0
43# make clean && make <target> DEBUG=1
44DEBUG ?= 0
45ifeq ($(DEBUG), 1)
46 CFLAGS += $(DEBUG_CFLAGS)
47else
48 CFLAGS += $(RELEASE_CFLAGS)
49endif
50
51main: $(BUILD_DIR) $(BIN)
52
53# Strip and fix header to create final .gba file.
54$(BIN): $(ELF)
55 $(OBJCOPY) -v -O binary $(ELF) $(BIN)
56 gbafix $(BIN)
57
58# Link files.
59$(ELF): $(SRC_MAIN) $(WATCH_SRC)
60 $(CC) $(CFLAGS) $(LDFLAGS) -o $(ELF) $(SRC_MAIN) $(LDLIBS)
61
62# Create build directory if needed.
63$(BUILD_DIR):
64 mkdir -p $(BUILD_DIR)
65
66# Test the output .gba in an emulator.
67run: main
68 mgba-qt $(BIN)
69
70# Remove build directory.
71clean:
72 rm -r $(BUILD_DIR)