kusano fc6ab3
#---------------------------------------------------------------------------------
kusano fc6ab3
.SUFFIXES:
kusano fc6ab3
#---------------------------------------------------------------------------------
kusano fc6ab3
kusano fc6ab3
ifeq ($(strip $(DEVKITARM)),)
kusano fc6ab3
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to="">devkitARM")</path>
kusano fc6ab3
endif
kusano fc6ab3
kusano fc6ab3
include $(DEVKITARM)/ds_rules
kusano fc6ab3
kusano fc6ab3
#---------------------------------------------------------------------------------
kusano fc6ab3
# TARGET is the name of the output
kusano fc6ab3
# BUILD is the directory where object files & intermediate files will be placed
kusano fc6ab3
# SOURCES is a list of directories containing source code
kusano fc6ab3
# DATA is a list of directories containing data files
kusano fc6ab3
# INCLUDES is a list of directories containing header files
kusano fc6ab3
#---------------------------------------------------------------------------------
kusano fc6ab3
TARGET		:=	$(shell basename $(CURDIR))
kusano fc6ab3
BUILD		:=	build
kusano fc6ab3
SOURCES		:=	../../
kusano fc6ab3
DATA		:=	data
kusano fc6ab3
INCLUDES	:=	include
kusano fc6ab3
kusano fc6ab3
#---------------------------------------------------------------------------------
kusano fc6ab3
# options for code generation
kusano fc6ab3
#---------------------------------------------------------------------------------
kusano fc6ab3
ARCH	:=	-mthumb -mthumb-interwork
kusano fc6ab3
kusano fc6ab3
CFLAGS	:=	-Wall -O2\
kusano fc6ab3
		-march=armv5te -mtune=arm946e-s \
kusano fc6ab3
		-fomit-frame-pointer -ffast-math \
kusano fc6ab3
		$(ARCH)
kusano fc6ab3
kusano fc6ab3
CFLAGS	+=	$(INCLUDE) -DARM9
kusano fc6ab3
CXXFLAGS	:= $(CFLAGS) -fno-rtti -fno-exceptions
kusano fc6ab3
kusano fc6ab3
ASFLAGS	:=	$(ARCH) -march=armv5te -mtune=arm946e-s
kusano fc6ab3
LDFLAGS	=	-specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
kusano fc6ab3
kusano fc6ab3
#---------------------------------------------------------------------------------
kusano fc6ab3
# list of directories containing libraries, this must be the top level containing
kusano fc6ab3
# include and lib
kusano fc6ab3
#---------------------------------------------------------------------------------
kusano fc6ab3
LIBDIRS	:=	$(LIBNDS)
kusano fc6ab3
kusano fc6ab3
#---------------------------------------------------------------------------------
kusano fc6ab3
# no real need to edit anything past this point unless you need to add additional
kusano fc6ab3
# rules for different file extensions
kusano fc6ab3
#---------------------------------------------------------------------------------
kusano fc6ab3
ifneq ($(BUILD),$(notdir $(CURDIR)))
kusano fc6ab3
#---------------------------------------------------------------------------------
kusano fc6ab3
kusano fc6ab3
export OUTPUT	:=	$(CURDIR)/lib/libz.a
kusano fc6ab3
kusano fc6ab3
export VPATH	:=	$(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
kusano fc6ab3
			$(foreach dir,$(DATA),$(CURDIR)/$(dir))
kusano fc6ab3
kusano fc6ab3
export DEPSDIR	:=	$(CURDIR)/$(BUILD)
kusano fc6ab3
kusano fc6ab3
CFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
kusano fc6ab3
CPPFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
kusano fc6ab3
SFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
kusano fc6ab3
BINFILES	:=	$(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
kusano fc6ab3
kusano fc6ab3
#---------------------------------------------------------------------------------
kusano fc6ab3
# use CXX for linking C++ projects, CC for standard C
kusano fc6ab3
#---------------------------------------------------------------------------------
kusano fc6ab3
ifeq ($(strip $(CPPFILES)),)
kusano fc6ab3
#---------------------------------------------------------------------------------
kusano fc6ab3
	export LD	:=	$(CC)
kusano fc6ab3
#---------------------------------------------------------------------------------
kusano fc6ab3
else
kusano fc6ab3
#---------------------------------------------------------------------------------
kusano fc6ab3
	export LD	:=	$(CXX)
kusano fc6ab3
#---------------------------------------------------------------------------------
kusano fc6ab3
endif
kusano fc6ab3
#---------------------------------------------------------------------------------
kusano fc6ab3
kusano fc6ab3
export OFILES	:=	$(addsuffix .o,$(BINFILES)) \
kusano fc6ab3
			$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
kusano fc6ab3
kusano fc6ab3
export INCLUDE	:=	$(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
kusano fc6ab3
			$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
kusano fc6ab3
			-I$(CURDIR)/$(BUILD)
kusano fc6ab3
kusano fc6ab3
.PHONY: $(BUILD) clean all
kusano fc6ab3
kusano fc6ab3
#---------------------------------------------------------------------------------
kusano fc6ab3
all: $(BUILD)
kusano fc6ab3
	@[ -d $@ ] || mkdir -p include
kusano fc6ab3
	@cp ../../*.h include
kusano fc6ab3
kusano fc6ab3
lib:
kusano fc6ab3
	@[ -d $@ ] || mkdir -p $@
kusano fc6ab3
	
kusano fc6ab3
$(BUILD): lib
kusano fc6ab3
	@[ -d $@ ] || mkdir -p $@
kusano fc6ab3
	@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
kusano fc6ab3
kusano fc6ab3
#---------------------------------------------------------------------------------
kusano fc6ab3
clean:
kusano fc6ab3
	@echo clean ...
kusano fc6ab3
	@rm -fr $(BUILD) lib
kusano fc6ab3
kusano fc6ab3
#---------------------------------------------------------------------------------
kusano fc6ab3
else
kusano fc6ab3
kusano fc6ab3
DEPENDS	:=	$(OFILES:.o=.d)
kusano fc6ab3
kusano fc6ab3
#---------------------------------------------------------------------------------
kusano fc6ab3
# main targets
kusano fc6ab3
#---------------------------------------------------------------------------------
kusano fc6ab3
$(OUTPUT)	:	$(OFILES)
kusano fc6ab3
kusano fc6ab3
#---------------------------------------------------------------------------------
kusano fc6ab3
%.bin.o	:	%.bin
kusano fc6ab3
#---------------------------------------------------------------------------------
kusano fc6ab3
	@echo $(notdir $<)
kusano fc6ab3
	@$(bin2o)
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
-include $(DEPENDS)
kusano fc6ab3
kusano fc6ab3
#---------------------------------------------------------------------------------------
kusano fc6ab3
endif
kusano fc6ab3
#---------------------------------------------------------------------------------------