From f6686f1e86927f038086023362251ebe78ce5ad6 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Wed, 2 Jun 2021 17:26:08 +0200 Subject: Init repo with basic BG framebuffer renderer --- Makefile | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 Makefile (limited to 'Makefile') diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1dd6375 --- /dev/null +++ b/Makefile @@ -0,0 +1,79 @@ +.POSIX: +.SUFFIXES: + +# Path to the development kit (devkitARM) and the GBA library. +DEVKITPRO := /opt/devkitpro +DEVKITBIN := $(DEVKITPRO)/devkitARM/bin +DEVKITTOOLS := $(DEVKITPRO)/tools/bin +LIBGBA_DIR := $(DEVKITPRO)/libgba +LIBGBA_SRC := $(DEVKITPRO)/libgba/include/ +LIBGBA := $(LIBGBA_DIR)/lib/libgba.a +LIBGBA += $(LIBGBA_DIR)/lib/libfat.a +LIBGBA += $(LIBGBA_DIR)/lib/libmm.a + +# Source code location and files to watch for changes. +SRC_DIR := src +BUILD_DIR := build +SRC_MAIN := $(SRC_DIR)/main.c +ASM_FILES := $(wildcard $(SRC_DIR)/*.s) +WATCH_SRC := $(shell find $(SRC_DIR) -name *.c -or -name *.s -or -name *.h) +INC_DIRS := $(shell find $(SRC_DIR) -type d) +INC_DIRS += $(BUILD_DIR) +INC_FLAGS := $(addprefix -I,$(INC_DIRS)) +INC_FLAGS += -I$(LIBGBA_SRC) + +# Output library names and executables. +TARGET := sequencer +ELF := $(BUILD_DIR)/$(TARGET).elf +BIN := $(BUILD_DIR)/$(TARGET).gba + +# Compiler and linker configuration. +CC := $(DEVKITBIN)/arm-none-eabi-gcc +OBJCOPY := $(DEVKITBIN)/arm-none-eabi-objcopy +ARCH := -mthumb -mthumb-interwork +SPECS := -specs=gba.specs +CONFIG := +CFLAGS := -Wall -Wextra -pedantic -Wno-incompatible-pointer-types +CFLAGS += -fno-strict-aliasing +CFLAGS += -mcpu=arm7tdmi -mtune=arm7tdmi $(ARCH) +CFLAGS += $(INC_FLAGS) +CFLAGS += $(CONFIG) +LDFLAGS := $(ARCH) $(SPECS) +LDLIBS := $(LIBGBA) +RELEASE_CFLAGS := -DNDEBUG -O3 +DEBUG_CFLAGS := -DDEBUG -O2 -g + +.PHONY: clean run + +# Setup debug/release builds. +# make clean && make DEBUG=0 +# make clean && make DEBUG=1 +DEBUG ?= 0 +ifeq ($(DEBUG), 1) + CFLAGS += $(DEBUG_CFLAGS) +else + CFLAGS += $(RELEASE_CFLAGS) +endif + +main: $(BUILD_DIR) $(BIN) + +# Strip and fix header to create final .gba file. +$(BIN): $(ELF) + $(OBJCOPY) -v -O binary $(ELF) $(BIN) + $(DEVKITTOOLS)/gbafix $(BIN) + +# Link files. +$(ELF): $(SRC_MAIN) $(WATCH_SRC) + $(CC) $(CFLAGS) $(LDFLAGS) -o $(ELF) $(SRC_MAIN) $(ASM_FILES) $(LDLIBS) + +# Create build directory if needed. +$(BUILD_DIR): + mkdir -p $(BUILD_DIR) + +# Test the output .gba in an emulator. +run: main + mgba-qt $(BIN) + +# Remove build directory. +clean: + rm -rf $(BUILD_DIR) -- cgit v1.2.1