1
#---------------------------------------------------------------------------------
2
.SUFFIXES:
3
#---------------------------------------------------------------------------------
4
5
ifeq ($(strip $(DEVKITARM)),)
6
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
7
endif
8
9
include $(DEVKITARM)/ds_rules
10
11
#---------------------------------------------------------------------------------
12
# TARGET is the name of the output
13
# BUILD is the directory where object files & intermediate files will be placed
14
# SOURCES is a list of directories containing source code
15
# INCLUDES is a list of directories containing extra header files
16
#---------------------------------------------------------------------------------
17
TARGET		:=	$(shell basename $(CURDIR))
18
BUILD		:=	build
19
SOURCES		:=	source
20
DATA		:=	data  
21
INCLUDES	:=	include
22
MUSIC       :=  maxmod_data
23
24
#---------------------------------------------------------------------------------
25
# options for code generation
26
#---------------------------------------------------------------------------------
27
ARCH	:=	-mthumb -mthumb-interwork
28
29
CFLAGS	:=	-g -Wall -O2\
30
 			-march=armv5te -mtune=arm946e-s -fomit-frame-pointer\
31
			-ffast-math \
32
			$(ARCH)
33
34
CFLAGS	+=	$(INCLUDE) -DARM9
35
CXXFLAGS	:= $(CFLAGS) -fno-rtti -fno-exceptions -fno-exceptions -fno-rtti
36
37
ASFLAGS	:=	-g $(ARCH)
38
LDFLAGS	=	-specs=ds_arm9.specs -g $(ARCH) -mno-fpu -Wl,-Map,$(notdir $*.map)
39
40
#---------------------------------------------------------------------------------
41
# any extra libraries we wish to link with the project
42
#---------------------------------------------------------------------------------
43
LIBS	:= -lmm9 -lnds9
44
 
45
 
46
#---------------------------------------------------------------------------------
47
# list of directories containing libraries, this must be the top level containing
48
# include and lib
49
#---------------------------------------------------------------------------------
50
LIBDIRS	:=	$(LIBNDS)
51
 
52
#---------------------------------------------------------------------------------
53
# no real need to edit anything past this point unless you need to add additional
54
# rules for different file extensions
55
#---------------------------------------------------------------------------------
56
ifneq ($(BUILD),$(notdir $(CURDIR)))
57
#---------------------------------------------------------------------------------
58
 
59
export OUTPUT	:=	$(CURDIR)/$(TARGET)
60
 
61
export VPATH	:=	$(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
62
					$(foreach dir,$(DATA),$(CURDIR)/$(dir))
63
64
export DEPSDIR	:=	$(CURDIR)/$(BUILD)
65
66
CFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
67
CPPFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
68
SFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
69
BINFILES	:=	$(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) soundbank.bin
70
71
export AUDIOFILES	:=	$(foreach dir,$(notdir $(wildcard $(MUSIC)/*.*)),$(CURDIR)/$(MUSIC)/$(dir))
72
 
73
#---------------------------------------------------------------------------------
74
# use CXX for linking C++ projects, CC for standard C
75
#---------------------------------------------------------------------------------
76
ifeq ($(strip $(CPPFILES)),)
77
#---------------------------------------------------------------------------------
78
	export LD	:=	$(CC)
79
#---------------------------------------------------------------------------------
80
else
81
#---------------------------------------------------------------------------------
82
	export LD	:=	$(CXX)
83
#---------------------------------------------------------------------------------
84
endif
85
#---------------------------------------------------------------------------------
86
87
export OFILES	:=	$(addsuffix .o,$(BINFILES)) \
88
					$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
89
 
90
export INCLUDE	:=	$(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
91
					$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
92
					-I$(CURDIR)/$(BUILD)
93
 
94
export LIBPATHS	:=	$(foreach dir,$(LIBDIRS),-L$(dir)/lib)
95
 
96
.PHONY: $(BUILD) clean
97
 
98
#---------------------------------------------------------------------------------
99
$(BUILD):
100
	@[ -d $@ ] || mkdir -p $@
101
	@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
102
 
103
#---------------------------------------------------------------------------------
104
clean:
105
	@echo clean ...
106
	@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(TARGET).ds.gba 
107
 
108
 
109
#---------------------------------------------------------------------------------
110
else
111
 
112
DEPENDS	:=	$(OFILES:.o=.d)
113
 
114
#---------------------------------------------------------------------------------
115
# main targets
116
#---------------------------------------------------------------------------------
117
$(OUTPUT).nds	: 	$(OUTPUT).elf
118
$(OUTPUT).elf	:	$(OFILES)
119
 
120
#---------------------------------------------------------------------------------
121
%.pcx.o	:	%.pcx
122
#---------------------------------------------------------------------------------
123
	@echo $(notdir $<)
124
	@$(bin2o)
125
126
#---------------------------------------------------------------------------------
127
# rule to build soundbank from music files
128
#---------------------------------------------------------------------------------
129
soundbank.bin : $(AUDIOFILES)
130
#---------------------------------------------------------------------------------
131
	@mmutil $^ -d -osoundbank.bin -hsoundbank.h
132
 
133
134
#---------------------------------------------------------------------------------
135
# This rule links in binary data with the .bin extension
136
#---------------------------------------------------------------------------------
137
%.bin.o	:	%.bin
138
#---------------------------------------------------------------------------------
139
	@echo $(notdir $<)
140
	@$(bin2o)
141
142
 
143
#-include $(DEPENDS)
144
-include $(DEPSDIR)/*.d
145
146
#---------------------------------------------------------------------------------------
147
endif
148
#---------------------------------------------------------------------------------------