pmd-red/Makefile

177 lines
4.5 KiB
Makefile
Raw Normal View History

2021-01-11 21:34:01 +00:00
TOOLCHAIN := $(DEVKITARM)
ifeq ($(CC),)
HOSTCC := gcc
else
HOSTCC := $(CC)
endif
ifeq ($(CXX),)
HOSTCXX := g++
else
HOSTCXX := $(CXX)
endif
ifneq (,$(wildcard $(TOOLCHAIN)/base_tools))
include $(TOOLCHAIN)/base_tools
else
export PATH := $(TOOLCHAIN)/bin:$(PATH)
PREFIX := arm-none-eabi-
OBJCOPY := $(PREFIX)objcopy
export CC := $(PREFIX)gcc
export AS := $(PREFIX)as
endif
export CPP := $(PREFIX)cpp
export LD := $(PREFIX)ld
ifeq ($(OS),Windows_NT)
EXE := .exe
else
EXE :=
endif
2021-01-11 21:34:01 +00:00
TITLE := POKE DUNGEON
GAME_CODE := B24E
MAKER_CODE := 01
REVISION := 0
2021-01-11 21:34:01 +00:00
ifeq ($(OS),Windows_NT)
LIB := ../../tools/agbcc/lib/libc.a ../../tools/agbcc/lib/libgcc.a ../../libagbsyscall/libagbsyscall.a
else
LIB := -L ../../tools/agbcc/lib -lc -lgcc -L ../../libagbsyscall -lagbsyscall
endif
#### Tools ####
SHELL := /bin/bash -o pipefail
CC1 := tools/agbcc/bin/agbcc
SHA1SUM := sha1sum -c
GBAGFX := tools/gbagfx/gbagfx
GBAFIX := tools/gbafix/gbafix
AIF2PCM := tools/aif2pcm/aif2pcm
MID2AGB := tools/mid2agb/mid2agb
PREPROC := tools/preproc/preproc
SCANINC := tools/scaninc/scaninc
RAMSCRGEN := tools/ramscrgen/ramscrgen
2017-12-11 06:41:46 +00:00
2021-01-11 21:34:01 +00:00
TOOLDIRS := $(filter-out tools/agbcc tools/binutils,$(wildcard tools/*))
TOOLBASE = $(TOOLDIRS:tools/%=%)
TOOLS = $(foreach tool,$(TOOLBASE),tools/$(tool)/$(tool)$(EXE))
ASFLAGS := -mcpu=arm7tdmi
2021-01-11 21:34:01 +00:00
override CC1FLAGS += -mthumb-interwork -Wimplicit -Wparentheses -Wunused -Werror -O2 -fhex-asm
CPPFLAGS := -I tools/agbcc/include -iquote include -nostdinc -undef
2017-12-11 06:41:46 +00:00
#### Files ####
2017-12-11 06:41:46 +00:00
BUILD_NAME = red
2017-12-11 06:41:46 +00:00
ROM := pmd_$(BUILD_NAME).gba
MAP := $(ROM:%.gba=%.map)
2017-12-11 06:41:46 +00:00
BUILD_DIR := build/pmd_$(BUILD_NAME)
2017-12-11 06:41:46 +00:00
C_SOURCES := $(wildcard src/*.c)
ASM_SOURCES := $(wildcard asm/*.s data/*.s)
2017-12-11 06:41:46 +00:00
C_OBJECTS := $(addprefix $(BUILD_DIR)/, $(C_SOURCES:%.c=%.o))
ASM_OBJECTS := $(addprefix $(BUILD_DIR)/, $(ASM_SOURCES:%.s=%.o))
ALL_OBJECTS := $(C_OBJECTS) $(ASM_OBJECTS)
2017-12-11 06:41:46 +00:00
SUBDIRS := $(sort $(dir $(ALL_OBJECTS)))
2017-12-11 06:41:46 +00:00
LD_SCRIPT := $(BUILD_DIR)/ld_script.ld
2017-12-11 06:41:46 +00:00
# Special configurations required for lib files
$(BUILD_DIR)/src/agb_flash.o : CC1FLAGS := -O -mthumb-interwork
$(BUILD_DIR)/src/agb_flash_1m.o: CC1FLAGS := -O -mthumb-interwork
$(BUILD_DIR)/src/agb_flash_mx.o: CC1FLAGS := -O -mthumb-interwork
2017-12-11 06:41:46 +00:00
2019-08-11 14:31:39 +00:00
$(BUILD_DIR)/src/m4a.o: CC1 := tools/agbcc/bin/old_agbcc
#### Main Rules ####
2017-12-11 06:41:46 +00:00
# Disable dependency scanning when NODEP is used for quick building
2021-01-11 21:34:01 +00:00
# TODO enable when NODEP is fixed
#ifeq ($(NODEP),)
#$(BUILD_DIR)/src/%.o: C_DEP = $(shell $(SCANINC) -I include src/$(*F).c)
#$(BUILD_DIR)/asm/%.o: ASM_DEP = $(shell $(SCANINC) asm/$(*F).s)
#$(BUILD_DIR)/data/%.o: ASM_DEP = $(shell $(SCANINC) data/$(*F).s)
#endif
ALL_BUILDS := red
2017-12-11 06:41:46 +00:00
# Available targets
2021-01-11 21:34:01 +00:00
.PHONY: all clean tidy libagbsyscall tools clean-tools $(TOOLDIRS)
2017-12-11 06:41:46 +00:00
MAKEFLAGS += --no-print-directory
# Secondary expansion is required for dependency variables in object rules.
.SECONDEXPANSION:
# Clear the default suffixes
.SUFFIXES:
# Don't delete intermediate files
.SECONDARY:
# Delete files that weren't built properly
.DELETE_ON_ERROR:
2017-12-11 06:41:46 +00:00
.PRECIOUS: %.1bpp %.4bpp %.8bpp %.gbapal %.lz %.rl %.pcm %.bin
2017-12-11 06:41:46 +00:00
# Create build subdirectories
2017-12-11 06:41:46 +00:00
$(shell mkdir -p $(SUBDIRS))
2017-12-11 06:41:46 +00:00
all: $(ROM)
2021-01-11 21:34:01 +00:00
tools: $(TOOLDIRS)
$(TOOLDIRS):
@$(MAKE) -C $@ CC=$(HOSTCC) CXX=$(HOSTCXX)
2019-08-04 10:07:21 +00:00
compare: all
@$(SHA1SUM) $(BUILD_NAME).sha1
2017-12-11 06:41:46 +00:00
2021-01-11 21:34:01 +00:00
clean: tidy clean-tools
$(RM) $(ALL_OBJECTS)
2021-01-11 21:34:01 +00:00
clean-tools:
@$(foreach tooldir,$(TOOLDIRS),$(MAKE) clean -C $(tooldir);)
tidy:
$(RM) $(ALL_BUILDS:%=pmd_%{.gba,.elf,.map})
$(RM) -r build
@$(MAKE) clean -C libagbsyscall
2017-12-11 06:41:46 +00:00
2021-01-11 21:34:01 +00:00
$(ROM): %.gba: %.elf tools
$(OBJCOPY) -O binary --gap-fill 0xFF --pad-to 0xA000000 $< $@
$(GBAFIX) $@ -p -t"$(TITLE)" -c$(GAME_CODE) -m$(MAKER_CODE) -r$(REVISION) --silent
2017-12-11 06:41:46 +00:00
%.elf: $(LD_SCRIPT) $(ALL_OBJECTS) $(LIBC) libagbsyscall
cd $(BUILD_DIR) && $(LD) -T ld_script.ld -Map ../../$(MAP) -o ../../$@ $(LIB)
2017-12-11 06:41:46 +00:00
$(LD_SCRIPT): ld_script.txt $(BUILD_DIR)/sym_ewram.ld $(BUILD_DIR)/sym_ewram2.ld $(BUILD_DIR)/sym_iwram.ld
cd $(BUILD_DIR) && sed -e "s#tools/#../../tools/#g" ../../ld_script.txt >ld_script.ld
$(BUILD_DIR)/sym_%.ld: sym_%.txt
$(CPP) -P $(CPPFLAGS) $< | sed -e "s#tools/#../../tools/#g" > $@
2017-12-11 06:41:46 +00:00
$(C_OBJECTS): $(BUILD_DIR)/%.o: %.c $$(C_DEP)
@$(CPP) $(CPPFLAGS) $< -o $(BUILD_DIR)/$*.i
@$(CC1) $(CC1FLAGS) $(BUILD_DIR)/$*.i -o $(BUILD_DIR)/$*.s
@printf ".text\n\t.align\t2, 0\n" >> $(BUILD_DIR)/$*.s
$(AS) $(ASFLAGS) -o $@ $(BUILD_DIR)/$*.s
2017-12-11 06:41:46 +00:00
$(BUILD_DIR)/data/%.o: data/%.s $$(ASM_DEP)
$(PREPROC) $< charmap.txt | $(CPP) -I include | $(AS) $(ASFLAGS) -o $@
2017-12-11 06:41:46 +00:00
$(BUILD_DIR)/%.o: %.s $$(ASM_DEP)
2019-08-04 10:07:21 +00:00
$(AS) $(ASFLAGS) $< -o $@
libagbsyscall:
@$(MAKE) -C libagbsyscall TOOLCHAIN=$(TOOLCHAIN)