mfc-badge/Makefile

223 lines
8.4 KiB
Makefile
Raw Permalink Normal View History

2024-02-18 12:09:13 +00:00
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
include $(DEVKITARM)/ds_rules
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
2024-02-19 05:10:01 +00:00
# DATA is a list of directories containing binary files embedded using bin2o
# GRAPHICS is a list of directories containing image files to be converted with grit
# AUDIO is a list of directories containing audio to be converted by maxmod
# ICON is the image used to create the game icon, leave blank to use default rule
# NITRO is a directory that will be accessible via NitroFS
#---------------------------------------------------------------------------------
TARGET := $(shell basename $(CURDIR))
BUILD := build
SOURCES := source
INCLUDES := include
DATA := data
2024-02-23 03:20:50 +00:00
GRAPHICS :=
2024-02-19 05:10:01 +00:00
AUDIO :=
ICON :=
# specify a directory which contains the nitro filesystem
# this is relative to the Makefile
NITRO := nitrofiles
2024-02-18 12:09:13 +00:00
2024-02-23 03:20:50 +00:00
# These set the information text in the nds file
2024-02-23 22:10:43 +00:00
GAME_TITLE := Kitsch Badge
GAME_SUBTITLE1 := For MFC 2024
GAME_SUBTITLE2 :=
2024-02-23 03:20:50 +00:00
2024-02-18 12:09:13 +00:00
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
2024-02-19 05:10:01 +00:00
ARCH := -marm -mthumb-interwork -march=armv5te -mtune=arm946e-s
2024-02-18 12:09:13 +00:00
2024-02-19 05:10:01 +00:00
CFLAGS := -g -Wall -O3\
$(ARCH) $(INCLUDE) -DARM9
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
2024-02-18 12:09:13 +00:00
#---------------------------------------------------------------------------------
2024-02-19 05:10:01 +00:00
# any extra libraries we wish to link with the project (order is important)
2024-02-18 12:09:13 +00:00
#---------------------------------------------------------------------------------
2024-02-23 07:01:35 +00:00
LIBS := -lNE -lnflib
2024-02-19 05:10:01 +00:00
# automatigically add libraries for NitroFS
ifneq ($(strip $(NITRO)),)
2024-02-23 03:20:50 +00:00
LIBS := -lfilesystem -lfat $(LIBS)
2024-02-19 05:10:01 +00:00
endif
# automagically add maxmod library
ifneq ($(strip $(AUDIO)),)
2024-02-23 03:20:50 +00:00
LIBS := -lmm9 $(LIBS)
2024-02-19 05:10:01 +00:00
endif
2024-02-23 07:01:35 +00:00
LIBS := $(LIBS) -lnds9
2024-02-18 12:09:13 +00:00
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
2024-02-23 03:41:47 +00:00
LIBDIRS := $(LIBNDS) $(PORTLIBS) $(DEVKITPRO)/nitro-engine $(DEVKITPRO)/nflib
2024-02-19 05:10:01 +00:00
2024-02-18 12:09:13 +00:00
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
2024-02-19 05:10:01 +00:00
export OUTPUT := $(CURDIR)/$(TARGET)
export VPATH := $(CURDIR)/$(subst /,,$(dir $(ICON)))\
$(foreach dir,$(SOURCES),$(CURDIR)/$(dir))\
$(foreach dir,$(DATA),$(CURDIR)/$(dir))\
$(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
PNGFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.png)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
# prepare NitroFS directory
ifneq ($(strip $(NITRO)),)
export NITRO_FILES := $(CURDIR)/$(NITRO)
endif
# get audio list for maxmod
ifneq ($(strip $(AUDIO)),)
export MODFILES := $(foreach dir,$(notdir $(wildcard $(AUDIO)/*.*)),$(CURDIR)/$(AUDIO)/$(dir))
# place the soundbank file in NitroFS if using it
ifneq ($(strip $(NITRO)),)
export SOUNDBANK := $(NITRO_FILES)/soundbank.bin
# otherwise, needs to be loaded from memory
else
export SOUNDBANK := soundbank.bin
BINFILES += $(SOUNDBANK)
endif
endif
2024-02-18 12:09:13 +00:00
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
2024-02-19 05:10:01 +00:00
export LD := $(CC)
2024-02-18 12:09:13 +00:00
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
2024-02-19 05:10:01 +00:00
export LD := $(CXX)
2024-02-18 12:09:13 +00:00
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
2024-02-19 05:10:01 +00:00
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES := $(PNGFILES:.png=.o) $(OFILES_BIN) $(OFILES_SOURCES)
export HFILES := $(PNGFILES:.png=.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)
ifeq ($(strip $(ICON)),)
icons := $(wildcard *.bmp)
ifneq (,$(findstring $(TARGET).bmp,$(icons)))
export GAME_ICON := $(CURDIR)/$(TARGET).bmp
else
ifneq (,$(findstring icon.bmp,$(icons)))
export GAME_ICON := $(CURDIR)/icon.bmp
endif
endif
else
ifeq ($(suffix $(ICON)), .grf)
export GAME_ICON := $(CURDIR)/$(ICON)
else
export GAME_ICON := $(CURDIR)/$(BUILD)/$(notdir $(basename $(ICON))).grf
endif
endif
2024-02-18 12:09:13 +00:00
.PHONY: $(BUILD) clean
2024-02-19 05:10:01 +00:00
2024-02-18 12:09:13 +00:00
#---------------------------------------------------------------------------------
$(BUILD):
2024-02-19 05:10:01 +00:00
@mkdir -p $@
2024-02-18 12:09:13 +00:00
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
2024-02-19 05:10:01 +00:00
2024-02-18 12:09:13 +00:00
#---------------------------------------------------------------------------------
clean:
@echo clean ...
2024-02-19 05:10:01 +00:00
@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(SOUNDBANK)
2024-02-18 12:09:13 +00:00
#---------------------------------------------------------------------------------
else
2024-02-19 05:10:01 +00:00
2024-02-18 12:09:13 +00:00
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
2024-02-23 03:20:50 +00:00
$(OUTPUT).nds: $(OUTPUT).elf $(GAME_ICON)
2024-02-19 05:10:01 +00:00
$(OUTPUT).elf: $(OFILES)
# source files depend on generated headers
$(OFILES_SOURCES) : $(HFILES)
# need to build soundbank first
$(OFILES): $(SOUNDBANK)
#---------------------------------------------------------------------------------
# rule to build solution from music files
2024-02-18 12:09:13 +00:00
#---------------------------------------------------------------------------------
2024-02-19 05:10:01 +00:00
$(SOUNDBANK) : $(MODFILES)
#---------------------------------------------------------------------------------
mmutil $^ -d -o$@ -hsoundbank.h
#---------------------------------------------------------------------------------
%.bin.o %_bin.h : %.bin
2024-02-18 12:09:13 +00:00
#---------------------------------------------------------------------------------
@echo $(notdir $<)
2024-02-19 05:10:01 +00:00
@$(bin2o)
#---------------------------------------------------------------------------------
# This rule creates assembly source files using grit
# grit takes an image file and a .grit describing how the file is to be processed
# add additional rules like this for each image extension
# you use in the graphics folders
#---------------------------------------------------------------------------------
%.s %.h: %.png %.grit
#---------------------------------------------------------------------------------
grit $< -fts -o$*
#---------------------------------------------------------------------------------
# Convert non-GRF game icon to GRF if needed
#---------------------------------------------------------------------------------
$(GAME_ICON): $(notdir $(ICON))
#---------------------------------------------------------------------------------
@echo convert $(notdir $<)
@grit $< -g -gt -gB4 -gT FF00FF -m! -p -pe 16 -fh! -ftr
-include $(DEPSDIR)/*.d
2024-02-18 12:09:13 +00:00
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------