1381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes#---------------------------------------------------------------------------------
2381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes.SUFFIXES:
3381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes#---------------------------------------------------------------------------------
4381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
5381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughesifeq ($(strip $(DEVKITARM)),)
6381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
7381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughesendif
8381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
9381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughesinclude $(DEVKITARM)/ds_rules
10381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
11381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes#---------------------------------------------------------------------------------
12381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes# TARGET is the name of the output
13381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes# BUILD is the directory where object files & intermediate files will be placed
14381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes# SOURCES is a list of directories containing source code
15381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes# DATA is a list of directories containing data files
16381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes# INCLUDES is a list of directories containing header files
17381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes#---------------------------------------------------------------------------------
18381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesTARGET		:=	$(shell basename $(CURDIR))
19381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesBUILD		:=	build
20381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesSOURCES		:=	../../
21381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesDATA		:=	data
22381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesINCLUDES	:=	include
23381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
24381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes#---------------------------------------------------------------------------------
25381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes# options for code generation
26381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes#---------------------------------------------------------------------------------
27381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesARCH	:=	-mthumb -mthumb-interwork
28381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
29381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesCFLAGS	:=	-Wall -O2\
30381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes		-march=armv5te -mtune=arm946e-s \
31381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes		-fomit-frame-pointer -ffast-math \
32381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes		$(ARCH)
33381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
34381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesCFLAGS	+=	$(INCLUDE) -DARM9
35381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesCXXFLAGS	:= $(CFLAGS) -fno-rtti -fno-exceptions
36381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
37381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesASFLAGS	:=	$(ARCH) -march=armv5te -mtune=arm946e-s
38381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesLDFLAGS	=	-specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
39381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
40381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes#---------------------------------------------------------------------------------
41381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes# list of directories containing libraries, this must be the top level containing
42381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes# include and lib
43381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes#---------------------------------------------------------------------------------
44381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesLIBDIRS	:=	$(LIBNDS)
45381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
46381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes#---------------------------------------------------------------------------------
47381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes# no real need to edit anything past this point unless you need to add additional
48381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes# rules for different file extensions
49381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes#---------------------------------------------------------------------------------
50381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughesifneq ($(BUILD),$(notdir $(CURDIR)))
51381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes#---------------------------------------------------------------------------------
52381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
53381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughesexport OUTPUT	:=	$(CURDIR)/lib/libz.a
54381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
55381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughesexport VPATH	:=	$(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
56381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes			$(foreach dir,$(DATA),$(CURDIR)/$(dir))
57381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
58381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughesexport DEPSDIR	:=	$(CURDIR)/$(BUILD)
59381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
60381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesCFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
61381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesCPPFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
62381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesSFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
63381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesBINFILES	:=	$(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
64381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
65381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes#---------------------------------------------------------------------------------
66381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes# use CXX for linking C++ projects, CC for standard C
67381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes#---------------------------------------------------------------------------------
68381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughesifeq ($(strip $(CPPFILES)),)
69381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes#---------------------------------------------------------------------------------
70381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes	export LD	:=	$(CC)
71381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes#---------------------------------------------------------------------------------
72381716e9396b55b1adb8235b020c37344f60ab07Elliott Hugheselse
73381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes#---------------------------------------------------------------------------------
74381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes	export LD	:=	$(CXX)
75381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes#---------------------------------------------------------------------------------
76381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughesendif
77381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes#---------------------------------------------------------------------------------
78381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
79381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughesexport OFILES	:=	$(addsuffix .o,$(BINFILES)) \
80381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes			$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
81381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
82381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughesexport INCLUDE	:=	$(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
83381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes			$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
84381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes			-I$(CURDIR)/$(BUILD)
85381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
86381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes.PHONY: $(BUILD) clean all
87381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
88381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes#---------------------------------------------------------------------------------
89381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughesall: $(BUILD)
90381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes	@[ -d $@ ] || mkdir -p include
91381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes	@cp ../../*.h include
92381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
93381716e9396b55b1adb8235b020c37344f60ab07Elliott Hugheslib:
94381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes	@[ -d $@ ] || mkdir -p $@
95381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes	
96381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes$(BUILD): lib
97381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes	@[ -d $@ ] || mkdir -p $@
98381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes	@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
99381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
100381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes#---------------------------------------------------------------------------------
101381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughesclean:
102381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes	@echo clean ...
103381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes	@rm -fr $(BUILD) lib
104381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
105381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes#---------------------------------------------------------------------------------
106381716e9396b55b1adb8235b020c37344f60ab07Elliott Hugheselse
107381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
108381716e9396b55b1adb8235b020c37344f60ab07Elliott HughesDEPENDS	:=	$(OFILES:.o=.d)
109381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
110381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes#---------------------------------------------------------------------------------
111381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes# main targets
112381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes#---------------------------------------------------------------------------------
113381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes$(OUTPUT)	:	$(OFILES)
114381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
115381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes#---------------------------------------------------------------------------------
116381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes%.bin.o	:	%.bin
117381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes#---------------------------------------------------------------------------------
118381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes	@echo $(notdir $<)
119381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes	@$(bin2o)
120381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
121381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
122381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes-include $(DEPENDS)
123381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes
124381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes#---------------------------------------------------------------------------------------
125381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughesendif
126381716e9396b55b1adb8235b020c37344f60ab07Elliott Hughes#---------------------------------------------------------------------------------------
127