diff options
author | Bad Diode <bd@badd10de.dev> | 2021-06-02 17:26:08 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2021-06-02 17:26:08 +0200 |
commit | f6686f1e86927f038086023362251ebe78ce5ad6 (patch) | |
tree | d196fc1c32c55442a2ac75d4ce046b1c0e0d6d48 /Makefile | |
download | stepper-f6686f1e86927f038086023362251ebe78ce5ad6.tar.gz stepper-f6686f1e86927f038086023362251ebe78ce5ad6.zip |
Init repo with basic BG framebuffer renderer
Diffstat (limited to 'Makefile')
-rw-r--r-- | Makefile | 79 |
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. | ||
5 | DEVKITPRO := /opt/devkitpro | ||
6 | DEVKITBIN := $(DEVKITPRO)/devkitARM/bin | ||
7 | DEVKITTOOLS := $(DEVKITPRO)/tools/bin | ||
8 | LIBGBA_DIR := $(DEVKITPRO)/libgba | ||
9 | LIBGBA_SRC := $(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 | BUILD_DIR := build | ||
17 | SRC_MAIN := $(SRC_DIR)/main.c | ||
18 | ASM_FILES := $(wildcard $(SRC_DIR)/*.s) | ||
19 | WATCH_SRC := $(shell find $(SRC_DIR) -name *.c -or -name *.s -or -name *.h) | ||
20 | INC_DIRS := $(shell find $(SRC_DIR) -type d) | ||
21 | INC_DIRS += $(BUILD_DIR) | ||
22 | INC_FLAGS := $(addprefix -I,$(INC_DIRS)) | ||
23 | INC_FLAGS += -I$(LIBGBA_SRC) | ||
24 | |||
25 | # Output library names and executables. | ||
26 | TARGET := sequencer | ||
27 | ELF := $(BUILD_DIR)/$(TARGET).elf | ||
28 | BIN := $(BUILD_DIR)/$(TARGET).gba | ||
29 | |||
30 | # Compiler and linker configuration. | ||
31 | CC := $(DEVKITBIN)/arm-none-eabi-gcc | ||
32 | OBJCOPY := $(DEVKITBIN)/arm-none-eabi-objcopy | ||
33 | ARCH := -mthumb -mthumb-interwork | ||
34 | SPECS := -specs=gba.specs | ||
35 | CONFIG := | ||
36 | CFLAGS := -Wall -Wextra -pedantic -Wno-incompatible-pointer-types | ||
37 | CFLAGS += -fno-strict-aliasing | ||
38 | CFLAGS += -mcpu=arm7tdmi -mtune=arm7tdmi $(ARCH) | ||
39 | CFLAGS += $(INC_FLAGS) | ||
40 | CFLAGS += $(CONFIG) | ||
41 | LDFLAGS := $(ARCH) $(SPECS) | ||
42 | LDLIBS := $(LIBGBA) | ||
43 | RELEASE_CFLAGS := -DNDEBUG -O3 | ||
44 | DEBUG_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 | ||
51 | DEBUG ?= 0 | ||
52 | ifeq ($(DEBUG), 1) | ||
53 | CFLAGS += $(DEBUG_CFLAGS) | ||
54 | else | ||
55 | CFLAGS += $(RELEASE_CFLAGS) | ||
56 | endif | ||
57 | |||
58 | main: $(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. | ||
74 | run: main | ||
75 | mgba-qt $(BIN) | ||
76 | |||
77 | # Remove build directory. | ||
78 | clean: | ||
79 | rm -rf $(BUILD_DIR) | ||