1#---------------------------------------------------------------------------------
2.SUFFIXES:
3#---------------------------------------------------------------------------------
4
5ifeq ($(strip $(DEVKITARM)),)
6$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
7endif
8
9TOPDIR ?= $(CURDIR)
10include $(DEVKITARM)/3ds_rules
11
12#---------------------------------------------------------------------------------
13# TARGET is the name of the output
14# BUILD is the directory where object files & intermediate files will be placed
15# SOURCES is a list of directories containing source code
16# DATA is a list of directories containing data files
17# INCLUDES is a list of directories containing header files
18#
19# NO_SMDH: if set to anything, no SMDH file is generated.
20# ROMFS is the directory which contains the RomFS, relative to the Makefile (Optional)
21# APP_TITLE is the name of the app stored in the SMDH file (Optional)
22# APP_DESCRIPTION is the description of the app stored in the SMDH file (Optional)
23# APP_AUTHOR is the author of the app stored in the SMDH file (Optional)
24# ICON is the filename of the icon (.png), relative to the project folder.
25#   If not set, it attempts to use one of the following (in this order):
26#     - <Project name>.png
27#     - icon.png
28#     - <libctru folder>/default_icon.png
29#---------------------------------------------------------------------------------
30TARGET		:=	OpenJazz
31BUILD		:=	build
32SOURCES		:=	src src/game src/io src/io/gfx src/jj1bonuslevel \
33                src/jj1bonuslevel/jj1bonuslevelplayer src/jj1level \
34                src/jj1level/jj1event src/jj1level/jj1levelplayer src/jj1planet \
35                src/jj1scene src/jj2level src/jj2level/jj2event \
36                src/jj2level/jj2levelplayer src/level src/menu src/player
37DATA		:=	data
38INCLUDES	:=	src
39#ROMFS		:=	romfs
40APP_TITLE	:= OpenJazz
41#APP_DESCRIPTION:=
42APP_AUTHOR	:= AlisterT & carstene1ns
43
44#---------------------------------------------------------------------------------
45# options for code generation
46#---------------------------------------------------------------------------------
47ARCH	:=	-march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
48
49CFLAGS	:=	-g -Wall -O2 -mword-relocations \
50			-fomit-frame-pointer -ffunction-sections \
51			$(ARCH)
52
53CFLAGS	+=	$(INCLUDE) -DARM11 -D_3DS -DUSE_XMP -DDATAPATH=\"sdmc:/3ds/OJ/\"
54
55CXXFLAGS	:= $(CFLAGS) -frtti -fexceptions -std=gnu++11
56
57ASFLAGS	:=	-g $(ARCH)
58LDFLAGS	=	-specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
59
60LIBS	:= -lSDL -lxmp -lcitro3d -lctru -lz -lm
61
62#---------------------------------------------------------------------------------
63# list of directories containing libraries, this must be the top level containing
64# include and lib
65#---------------------------------------------------------------------------------
66LIBDIRS	:= $(CTRULIB) $(CURDIR)/deps
67
68
69#---------------------------------------------------------------------------------
70# no real need to edit anything past this point unless you need to add additional
71# rules for different file extensions
72#---------------------------------------------------------------------------------
73ifneq ($(BUILD),$(notdir $(CURDIR)))
74#---------------------------------------------------------------------------------
75
76export OUTPUT	:=	$(CURDIR)/$(TARGET)
77export TOPDIR	:=	$(CURDIR)
78
79export VPATH	:=	$(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
80			$(foreach dir,$(DATA),$(CURDIR)/$(dir))
81
82export DEPSDIR	:=	$(CURDIR)/$(BUILD)
83
84CFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
85CPPFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
86SFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
87PICAFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica)))
88SHLISTFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist)))
89BINFILES	:=	$(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
90
91#---------------------------------------------------------------------------------
92# use CXX for linking C++ projects, CC for standard C
93#---------------------------------------------------------------------------------
94ifeq ($(strip $(CPPFILES)),)
95#---------------------------------------------------------------------------------
96	export LD	:=	$(CC)
97#---------------------------------------------------------------------------------
98else
99#---------------------------------------------------------------------------------
100	export LD	:=	$(CXX)
101#---------------------------------------------------------------------------------
102endif
103#---------------------------------------------------------------------------------
104
105export OFILES	:=	$(addsuffix .o,$(BINFILES)) \
106			$(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o) \
107			$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
108
109export INCLUDE	:=	$(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
110			$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
111			-I$(CURDIR)/$(BUILD)
112
113export LIBPATHS	:=	$(foreach dir,$(LIBDIRS),-L$(dir)/lib)
114
115ifeq ($(strip $(ICON)),)
116	icons := $(wildcard *.png)
117	ifneq (,$(findstring $(TARGET).png,$(icons)))
118		export APP_ICON := $(TOPDIR)/$(TARGET).png
119	else
120		ifneq (,$(findstring icon.png,$(icons)))
121			export APP_ICON := $(TOPDIR)/icon.png
122		endif
123	endif
124else
125	export APP_ICON := $(TOPDIR)/$(ICON)
126endif
127
128ifeq ($(strip $(NO_SMDH)),)
129	export _3DSXFLAGS += --smdh=$(CURDIR)/$(TARGET).smdh
130endif
131
132ifneq ($(ROMFS),)
133	export _3DSXFLAGS += --romfs=$(CURDIR)/$(ROMFS)
134endif
135
136.PHONY: $(BUILD) clean all
137
138#---------------------------------------------------------------------------------
139all: $(BUILD)
140
141$(BUILD):
142	@[ -d $@ ] || mkdir -p $@
143	@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile.3ds
144
145#---------------------------------------------------------------------------------
146clean:
147	@echo clean ...
148	@rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf
149
150
151#---------------------------------------------------------------------------------
152else
153
154DEPENDS	:=	$(OFILES:.o=.d)
155
156#---------------------------------------------------------------------------------
157# main targets
158#---------------------------------------------------------------------------------
159ifeq ($(strip $(NO_SMDH)),)
160$(OUTPUT).3dsx	:	$(OUTPUT).elf $(OUTPUT).smdh
161else
162$(OUTPUT).3dsx	:	$(OUTPUT).elf
163endif
164
165$(OUTPUT).elf	:	$(OFILES)
166
167#---------------------------------------------------------------------------------
168# you need a rule like this for each extension you use as binary data
169#---------------------------------------------------------------------------------
170%.bin.o	:	%.bin
171#---------------------------------------------------------------------------------
172	@echo $(notdir $<)
173	@$(bin2o)
174
175#---------------------------------------------------------------------------------
176# rules for assembling GPU shaders
177#---------------------------------------------------------------------------------
178define shader-as
179	$(eval CURBIN := $(patsubst %.shbin.o,%.shbin,$(notdir $@)))
180	picasso -o $(CURBIN) $1
181	bin2s $(CURBIN) | $(AS) -o $@
182	echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN) | tr . _)`.h
183	echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN) | tr . _)`.h
184	echo "extern const u32" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN) | tr . _)`.h
185endef
186
187%.shbin.o : %.v.pica %.g.pica
188	@echo $(notdir $^)
189	@$(call shader-as,$^)
190
191%.shbin.o : %.v.pica
192	@echo $(notdir $<)
193	@$(call shader-as,$<)
194
195%.shbin.o : %.shlist
196	@echo $(notdir $<)
197	@$(call shader-as,$(foreach file,$(shell cat $<),$(dir $<)/$(file)))
198
199-include $(DEPENDS)
200
201#---------------------------------------------------------------------------------------
202endif
203#---------------------------------------------------------------------------------------
204
205