aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-06-02 17:26:08 +0200
committerBad Diode <bd@badd10de.dev>2021-06-02 17:26:08 +0200
commitf6686f1e86927f038086023362251ebe78ce5ad6 (patch)
treed196fc1c32c55442a2ac75d4ce046b1c0e0d6d48 /Makefile
downloadstepper-f6686f1e86927f038086023362251ebe78ce5ad6.tar.gz
stepper-f6686f1e86927f038086023362251ebe78ce5ad6.zip
Init repo with basic BG framebuffer renderer
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile79
1 files changed, 79 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..1dd6375
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,79 @@
1.POSIX:
2.SUFFIXES:
3
4# Path to the development kit (devkitARM) and the GBA library.
5DEVKITPRO := /opt/devkitpro
6DEVKITBIN := $(DEVKITPRO)/devkitARM/bin
7DEVKITTOOLS := $(DEVKITPRO)/tools/bin
8LIBGBA_DIR := $(DEVKITPRO)/libgba
9LIBGBA_SRC := $(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
16BUILD_DIR := build
17SRC_MAIN := $(SRC_DIR)/main.c
18ASM_FILES := $(wildcard $(SRC_DIR)/*.s)
19WATCH_SRC := $(shell find $(SRC_DIR) -name *.c -or -name *.s -or -name *.h)
20INC_DIRS := $(shell find $(SRC_DIR) -type d)
21INC_DIRS += $(BUILD_DIR)
22INC_FLAGS := $(addprefix -I,$(INC_DIRS))
23INC_FLAGS += -I$(LIBGBA_SRC)
24
25# Output library names and executables.
26TARGET := sequencer
27ELF := $(BUILD_DIR)/$(TARGET).elf
28BIN := $(BUILD_DIR)/$(TARGET).gba
29
30# Compiler and linker configuration.
31CC := $(DEVKITBIN)/arm-none-eabi-gcc
32OBJCOPY := $(DEVKITBIN)/arm-none-eabi-objcopy
33ARCH := -mthumb -mthumb-interwork
34SPECS := -specs=gba.specs
35CONFIG :=
36CFLAGS := -Wall -Wextra -pedantic -Wno-incompatible-pointer-types
37CFLAGS += -fno-strict-aliasing
38CFLAGS += -mcpu=arm7tdmi -mtune=arm7tdmi $(ARCH)
39CFLAGS += $(INC_FLAGS)
40CFLAGS += $(CONFIG)
41LDFLAGS := $(ARCH) $(SPECS)
42LDLIBS := $(LIBGBA)
43RELEASE_CFLAGS := -DNDEBUG -O3
44DEBUG_CFLAGS := -DDEBUG -O2 -g
45
46.PHONY: clean run
47
48# Setup debug/release builds.
49# make clean && make <target> DEBUG=0
50# make clean && make <target> DEBUG=1
51DEBUG ?= 0
52ifeq ($(DEBUG), 1)
53 CFLAGS += $(DEBUG_CFLAGS)
54else
55 CFLAGS += $(RELEASE_CFLAGS)
56endif
57
58main: $(BUILD_DIR) $(BIN)
59
60# Strip and fix header to create final .gba file.
61$(BIN): $(ELF)
62 $(OBJCOPY) -v -O binary $(ELF) $(BIN)
63 $(DEVKITTOOLS)/gbafix $(BIN)
64
65# Link files.
66$(ELF): $(SRC_MAIN) $(WATCH_SRC)
67 $(CC) $(CFLAGS) $(LDFLAGS) -o $(ELF) $(SRC_MAIN) $(ASM_FILES) $(LDLIBS)
68
69# Create build directory if needed.
70$(BUILD_DIR):
71 mkdir -p $(BUILD_DIR)
72
73# Test the output .gba in an emulator.
74run: main
75 mgba-qt $(BIN)
76
77# Remove build directory.
78clean:
79 rm -rf $(BUILD_DIR)