-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
butano and tools: wonderful toolchain wip support
- Loading branch information
Showing
12 changed files
with
520 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,253 +1,12 @@ | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
.SUFFIXES: | ||
# Toolchain auto detection: | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
|
||
ifeq ($(strip $(DEVKITARM)),) | ||
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM") | ||
endif | ||
|
||
include $(DEVKITARM)/gba_rules | ||
BN_GRIT := grit | ||
BN_MMUTIL := mmutil | ||
|
||
#--------------------------------------------------------------------------------------------------------------------- | ||
# Butano custom IWRAM base rules without flto: | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
%.bn_iwram.o: %.bn_iwram.cpp | ||
$(SILENTMSG) $(notdir $<) | ||
ifdef ADD_COMPILE_COMMAND | ||
$(ADD_COMPILE_COMMAND) add $(CXX) "$(CPPFLAGS) $(CXXFLAGS) -fno-lto -marm -mlong-calls -c $< -o $@" $< | ||
endif | ||
$(SILENTCMD)$(CXX) -MMD -MP -MF $(DEPSDIR)/$*.bn_iwram.d $(CPPFLAGS) $(CXXFLAGS) -fno-lto -marm -mlong-calls -c $< -o $@ $(ERROR_FILTER) | ||
|
||
%.bn_iwram.o: %.bn_iwram.c | ||
$(SILENTMSG) $(notdir $<) | ||
ifdef ADD_COMPILE_COMMAND | ||
$(ADD_COMPILE_COMMAND) add $(CC) "$(CPPFLAGS) $(CFLAGS) -fno-lto -marm -mlong-calls -c $< -o $@" $< | ||
endif | ||
$(SILENTCMD)$(CC) -MMD -MP -MF $(DEPSDIR)/$*.bn_iwram.d $(CPPFLAGS) $(CFLAGS) -fno-lto -marm -mlong-calls -c $< -o $@ $(ERROR_FILTER) | ||
|
||
#--------------------------------------------------------------------------------------------------------------------- | ||
# Butano custom EWRAM base rules without flto: | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
%.bn_ewram.o: %.bn_ewram.cpp | ||
$(SILENTMSG) $(notdir $<) | ||
ifdef ADD_COMPILE_COMMAND | ||
$(ADD_COMPILE_COMMAND) add $(CXX) "$(CPPFLAGS) $(CXXFLAGS) -fno-lto -c $< -o $@" $< | ||
endif | ||
$(SILENTCMD)$(CXX) -MMD -MP -MF $(DEPSDIR)/$*.bn_ewram.d $(CPPFLAGS) $(CXXFLAGS) -fno-lto -c $< -o $@ $(ERROR_FILTER) | ||
|
||
%.bn_ewram.o: %.bn_ewram.c | ||
$(SILENTMSG) $(notdir $<) | ||
ifdef ADD_COMPILE_COMMAND | ||
$(ADD_COMPILE_COMMAND) add $(CC) "$(CPPFLAGS) $(CFLAGS) -fno-lto -c $< -o $@" $< | ||
endif | ||
$(SILENTCMD)$(CC) -MMD -MP -MF $(DEPSDIR)/$*.bn_ewram.d $(CPPFLAGS) $(CFLAGS) -fno-lto -c $< -o $@ $(ERROR_FILTER) | ||
|
||
#--------------------------------------------------------------------------------------------------------------------- | ||
# Butano custom ROM base rules without flto: | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
%.bn_noflto.o: %.bn_noflto.cpp | ||
$(SILENTMSG) $(notdir $<) | ||
ifdef ADD_COMPILE_COMMAND | ||
$(ADD_COMPILE_COMMAND) add $(CXX) "$(CPPFLAGS) $(CXXFLAGS) -fno-lto -c $< -o $@" $< | ||
endif | ||
$(SILENTCMD)$(CXX) -MMD -MP -MF $(DEPSDIR)/$*.bn_noflto.d $(CPPFLAGS) $(CXXFLAGS) -fno-lto -c $< -o $@ $(ERROR_FILTER) | ||
|
||
%.bn_noflto.o: %.bn_noflto.c | ||
$(SILENTMSG) $(notdir $<) | ||
ifdef ADD_COMPILE_COMMAND | ||
$(ADD_COMPILE_COMMAND) add $(CC) "$(CPPFLAGS) $(CFLAGS) -fno-lto -c $< -o $@" $< | ||
endif | ||
$(SILENTCMD)$(CC) -MMD -MP -MF $(DEPSDIR)/$*.bn_noflto.d $(CPPFLAGS) $(CFLAGS) -fno-lto -c $< -o $@ $(ERROR_FILTER) | ||
|
||
#--------------------------------------------------------------------------------------------------------------------- | ||
# Butano custom link rule for avoiding issues when linking too much object files: | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
%.elf: | ||
$(SILENTMSG) Linking ROM... | ||
ifdef ADD_COMPILE_COMMAND | ||
$(ADD_COMPILE_COMMAND) end | ||
endif | ||
@echo $(OFILES) > bn_ofiles.txt | ||
$(SILENTCMD)$(LD) $(LDFLAGS) -specs=gba.specs @bn_ofiles.txt $(LIBPATHS) $(LIBS) -o $@ | ||
|
||
#--------------------------------------------------------------------------------------------------------------------- | ||
# Options for code generation: | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
ARCH := -mthumb -mthumb-interwork | ||
CWARNINGS := -Wall -Wextra -Wpedantic -Wshadow -Wundef -Wunused-parameter -Wmisleading-indentation \ | ||
-Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wnull-dereference -Wswitch-default \ | ||
-Wstack-usage=16384 | ||
|
||
CFLAGS := $(CWARNINGS) -gdwarf-4 -O2 -mcpu=arm7tdmi -mtune=arm7tdmi -ffast-math -ffunction-sections \ | ||
-fdata-sections $(ARCH) | ||
CFLAGS += $(INCLUDE) | ||
CFLAGS += $(USERFLAGS) | ||
|
||
CPPWARNINGS := -Wuseless-cast -Wnon-virtual-dtor -Woverloaded-virtual | ||
CXXFLAGS := $(CFLAGS) $(CPPWARNINGS) -std=c++20 -fno-rtti -fno-exceptions -fno-threadsafe-statics \ | ||
-fuse-cxa-atexit | ||
|
||
ASFLAGS := -gdwarf-4 $(ARCH) $(USERASFLAGS) | ||
|
||
ifndef DEFAULTLIBS | ||
LDFLAGS = -gdwarf-4 $(ARCH) -nodefaultlibs -Wl,-Map,$(notdir $*.map) $(USERLDFLAGS) | ||
ifneq ($(strip $(DEVKITARM)),) | ||
include $(LIBBUTANOABS)/butano_dka.mak | ||
else | ||
LDFLAGS = -gdwarf-4 $(ARCH) -Wl,-Map,$(notdir $*.map) $(USERLDFLAGS) | ||
ifneq ($(strip $(WONDERFUL_TOOLCHAIN)),) | ||
include $(LIBBUTANOABS)/butano_wt.mak | ||
else | ||
$(error "DEVKITARM and WONDERFUL_TOOLCHAIN not found") | ||
endif | ||
endif | ||
|
||
#--------------------------------------------------------------------------------------------------------------------- | ||
# Any extra libraries we wish to link with the project: | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
LIBS := -lgcc $(USERLIBS) | ||
|
||
#--------------------------------------------------------------------------------------------------------------------- | ||
# List of directories containing libraries, this must be the top level containing include and lib directories: | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
LIBDIRS := $(LIBBUTANOABS) $(LIBBUTANOABS)/hw/3rd_party/libtonc $(LIBBUTANOABS)/hw/3rd_party/libugba \ | ||
$(LIBBUTANOABS)/hw/3rd_party/maxmod $(USERLIBDIRS) | ||
|
||
#--------------------------------------------------------------------------------------------------------------------- | ||
# List of directories containing all butano source files: | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
BNSOURCES := $(LIBBUTANOABS)/src $(LIBBUTANOABS)/hw/src \ | ||
$(LIBBUTANOABS)/hw/3rd_party/libtonc/asm \ | ||
$(LIBBUTANOABS)/hw/3rd_party/libtonc/src \ | ||
$(LIBBUTANOABS)/hw/3rd_party/libtonc/src/font \ | ||
$(LIBBUTANOABS)/hw/3rd_party/libtonc/src/tte \ | ||
$(LIBBUTANOABS)/hw/3rd_party/libugba/src \ | ||
$(LIBBUTANOABS)/hw/3rd_party/posprintf/src \ | ||
$(LIBBUTANOABS)/hw/3rd_party/agbabi/src \ | ||
$(LIBBUTANOABS)/hw/3rd_party/gba-modern/src \ | ||
$(LIBBUTANOABS)/hw/3rd_party/cult-of-gba-bios/src \ | ||
$(LIBBUTANOABS)/hw/3rd_party/gbt-player/src \ | ||
$(LIBBUTANOABS)/hw/3rd_party/vgm-player/src \ | ||
$(LIBBUTANOABS)/hw/3rd_party/maxmod/source \ | ||
$(LIBBUTANOABS)/hw/3rd_party/maxmod/source_gba | ||
|
||
#--------------------------------------------------------------------------------------------------------------------- | ||
# Don't remove intermediary files (avoid rebuilding graphics files more than once): | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
.SECONDARY: | ||
|
||
ifneq ($(BUILD),$(notdir $(CURDIR))) | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
|
||
export OUTPUT := $(CURDIR)/$(TARGET) | ||
|
||
export VPATH := $(foreach dir, $(SOURCES), $(CURDIR)/$(dir)) \ | ||
$(foreach dir, $(BNSOURCES), $(dir)) \ | ||
$(foreach dir, $(DATA), $(CURDIR)/$(dir)) \ | ||
$(foreach dir, $(DMGAUDIO), $(CURDIR)/$(dir)) \ | ||
$(foreach dir, $(GRAPHICS), $(CURDIR)/$(dir)) | ||
|
||
export DEPSDIR := $(CURDIR)/$(BUILD) | ||
|
||
CFILES := $(foreach dir, $(SOURCES), $(notdir $(wildcard $(dir)/*.c))) \ | ||
$(foreach dir, $(BNSOURCES), $(notdir $(wildcard $(dir)/*.c))) | ||
|
||
CPPFILES := $(foreach dir, $(SOURCES), $(notdir $(wildcard $(dir)/*.cpp))) \ | ||
$(foreach dir, $(BNSOURCES), $(notdir $(wildcard $(dir)/*.cpp))) | ||
|
||
SFILES := $(foreach dir, $(SOURCES), $(notdir $(wildcard $(dir)/*.s))) \ | ||
$(foreach dir, $(BNSOURCES), $(notdir $(wildcard $(dir)/*.s))) | ||
|
||
BINFILES := $(foreach dir, $(DATA), $(notdir $(wildcard $(dir)/*.*))) \ | ||
_bn_audio_soundbank.bin | ||
|
||
DMGMODFILES := $(foreach dir, $(DMGAUDIO), $(notdir $(wildcard $(dir)/*.mod))) | ||
|
||
DMGS3MFILES := $(foreach dir, $(DMGAUDIO), $(notdir $(wildcard $(dir)/*.s3m))) | ||
|
||
DMGVGMFILES := $(foreach dir, $(DMGAUDIO), $(notdir $(wildcard $(dir)/*.vgm))) | ||
|
||
GRAPHICSFILES := $(foreach dir, $(GRAPHICS), $(notdir $(wildcard $(dir)/*.bmp))) | ||
|
||
#--------------------------------------------------------------------------------------------------------------------- | ||
# Use CXX for linking C++ projects, CC for standard C: | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
ifeq ($(strip $(CPPFILES)),) | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
export LD := $(CC) | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
else | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
export LD := $(CXX) | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
endif | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
|
||
export OFILES_BIN := $(addsuffix .o,$(BINFILES)) | ||
|
||
export OFILES_DMG := $(DMGMODFILES:.mod=_bn_dmg.o) $(DMGS3MFILES:.s3m=_bn_dmg.o) $(DMGVGMFILES:.vgm=_bn_dmg.o) | ||
|
||
export OFILES_GRAPHICS := $(GRAPHICSFILES:.bmp=_bn_gfx.o) | ||
|
||
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) | ||
|
||
export OFILES := $(OFILES_BIN) $(OFILES_DMG) $(OFILES_GRAPHICS) $(OFILES_SOURCES) | ||
|
||
#--------------------------------------------------------------------------------------------------------------------- | ||
# Don't generate header files from audio soundbank (avoid rebuilding all sources when audio files are updated): | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
export HFILES := $(filter-out _bn_audio_soundbank_bin.h,$(addsuffix .h,$(subst .,_,$(BINFILES)))) | ||
|
||
export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir)) \ | ||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \ | ||
-I$(CURDIR)/$(BUILD) | ||
|
||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) | ||
|
||
.PHONY: $(BUILD) clean | ||
|
||
#--------------------------------------------------------------------------------- | ||
all: | ||
@[ -d $(BUILD) ] || mkdir -p $(BUILD) | ||
@$(EXTTOOL) | ||
@$(MAKE) --no-print-directory $(BUILD) | ||
|
||
#--------------------------------------------------------------------------------- | ||
$(BUILD): | ||
@$(PYTHON) -B $(LIBBUTANOABS)/tools/butano_assets_tool.py --grit="$(BN_GRIT)" --mmutil="$(BN_MMUTIL)" \ | ||
--audio="$(AUDIO)" --dmg_audio="$(DMGAUDIO)" --graphics="$(GRAPHICS)" --build=$(BUILD) | ||
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile | ||
|
||
#--------------------------------------------------------------------------------------------------------------------- | ||
clean: | ||
@echo clean ... | ||
@rm -fr $(BUILD) $(TARGET).elf $(TARGET).elf.* $(TARGET).gba $(USERBUILD) | ||
|
||
#--------------------------------------------------------------------------------------------------------------------- | ||
else | ||
|
||
#--------------------------------------------------------------------------------------------------------------------- | ||
# Main targets: | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
|
||
$(OUTPUT).gba : $(OUTPUT).elf | ||
$(SILENTCMD)$(OBJCOPY) -O binary $< $@ | ||
@echo Fixing $(notdir $@) ... | ||
$(SILENTCMD)gbafix -t"$(ROMTITLE)" -c"$(ROMCODE)" $@ | ||
|
||
$(OUTPUT).elf : $(OFILES) | ||
|
||
$(OFILES_SOURCES) : $(HFILES) | ||
|
||
#--------------------------------------------------------------------------------------------------------------------- | ||
# The bin2o rule should be copied and modified for each extension used in the data directories: | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
|
||
#--------------------------------------------------------------------------------------------------------------------- | ||
# This rule links in binary data with the .bin extension: | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
%.bin.o %_bin.h : %.bin | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
@echo $(notdir $<) | ||
@$(bin2o) | ||
|
||
-include $(DEPSDIR)/*.d | ||
|
||
#--------------------------------------------------------------------------------------------------------------------- | ||
endif | ||
#--------------------------------------------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
.SUFFIXES: | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
|
||
ifeq ($(strip $(DEVKITARM)),) | ||
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM") | ||
endif | ||
|
||
BN_TOOLS := $(LIBBUTANOABS)/tools | ||
include $(DEVKITARM)/gba_rules | ||
|
||
BN_TOOLCHAIN_CFLAGS := | ||
BN_GRIT := grit | ||
BN_MMUTIL := mmutil | ||
|
||
#--------------------------------------------------------------------------------------------------------------------- | ||
# Butano custom base rules without flto: | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
include $(BN_TOOLS)/custom_base_rules.mak | ||
|
||
#--------------------------------------------------------------------------------------------------------------------- | ||
# Butano custom link rule for avoiding issues when linking too much object files: | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
%.elf: | ||
$(SILENTMSG) Linking ROM... | ||
ifdef ADD_COMPILE_COMMAND | ||
$(ADD_COMPILE_COMMAND) end | ||
endif | ||
@echo $(OFILES) > bn_ofiles.txt | ||
$(SILENTCMD)$(LD) $(LDFLAGS) -specs=gba.specs @bn_ofiles.txt $(LIBPATHS) $(LIBS) -o $@ | ||
|
||
#--------------------------------------------------------------------------------------------------------------------- | ||
# Options for code generation: | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
include $(BN_TOOLS)/codegen_options.mak | ||
|
||
ifndef DEFAULTLIBS | ||
LDFLAGS = -gdwarf-4 $(ARCH) -nodefaultlibs -Wl,-Map,$(notdir $*.map) $(USERLDFLAGS) | ||
else | ||
LDFLAGS = -gdwarf-4 $(ARCH) -Wl,-Map,$(notdir $*.map) $(USERLDFLAGS) | ||
endif | ||
|
||
#--------------------------------------------------------------------------------------------------------------------- | ||
# Sources setup: | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
include $(BN_TOOLS)/sources_setup.mak | ||
|
||
#--------------------------------------------------------------------------------------------------------------------- | ||
# Don't remove intermediary files (avoid rebuilding graphics files more than once): | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
.SECONDARY: | ||
|
||
ifneq ($(BUILD),$(notdir $(CURDIR))) | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
# Common setup: | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
include $(BN_TOOLS)/common_setup.mak | ||
|
||
#--------------------------------------------------------------------------------------------------------------------- | ||
else | ||
|
||
#--------------------------------------------------------------------------------------------------------------------- | ||
# Main targets: | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
|
||
$(OUTPUT).gba : $(OUTPUT).elf | ||
$(SILENTCMD)$(OBJCOPY) -O binary $< $@ | ||
@echo Fixing $(notdir $@) ... | ||
$(SILENTCMD)gbafix -t"$(ROMTITLE)" -c"$(ROMCODE)" $@ | ||
|
||
$(OUTPUT).elf : $(OFILES) | ||
|
||
$(OFILES_SOURCES) : $(HFILES) | ||
|
||
#--------------------------------------------------------------------------------------------------------------------- | ||
# The bin2o rule should be copied and modified for each extension used in the data directories: | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
|
||
#--------------------------------------------------------------------------------------------------------------------- | ||
# This rule links in binary data with the .bin extension: | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
%.bin.o %_bin.h : %.bin | ||
#--------------------------------------------------------------------------------------------------------------------- | ||
@echo $(notdir $<) | ||
@$(bin2o) | ||
|
||
-include $(DEPSDIR)/*.d | ||
|
||
#--------------------------------------------------------------------------------------------------------------------- | ||
endif | ||
#--------------------------------------------------------------------------------------------------------------------- |
Oops, something went wrong.