1#! make -f
2#----------------------------------------------------------------------------
3# Project:  TwlSDK
4# File:     modulerules
5#
6# Copyright 2007-2008 Nintendo. All rights reserved.
7#
8# These coded instructions, statements, and computer programs contain
9# proprietary information of Nintendo of America Inc. and/or Nintendo
10# Company Ltd., and are protected by Federal copyright law. They may
11# not be disclosed to third parties or copied or duplicated in any form,
12# in whole or in part, without the prior written consent of Nintendo.
13#
14# $Date:: 2009-08-28#$
15# $Rev: 11023 $
16# $Author: okubata_ryoma $
17#----------------------------------------------------------------------------
18ifndef NITROSDK_MODULERULES_
19
20ifneq	($(FORCE_BUILD),)
21
22ifeq	($(filter clean clobber,$(MAKECMDGOALS)),)
23include $(BUILDTOOLSDIR)/modulerules.cctype.$(NITRO_CCTYPE)
24include $(NITRO_BUILDTOOLSDIR)/modulerules.cctype.$(NITRO_CCTYPE)
25endif
26
27# Common Rules
28
29# .bin .srl
30ifdef	NITRO_MAKEROM
31#
32# MAKEROM
33#
34
35ROM_SPEC				?= $(DEFAULT_ROM_SPEC)
36MAKEROM_ARM9			?= $(DEFAULT_MAKEROM_ARM9)
37MAKEROM_ARM7			?= $(DEFAULT_MAKEROM_ARM7)
38MAKEROM_ROMROOT			?= $(DEFAULT_MAKEROM_ROMROOT)
39MAKEROM_ROMFILES		?= $(DEFAULT_MAKEROM_ROMFILES)
40MAKEROM_ROMSPEED		?= $(DEFAULT_MAKEROM_ROMSPEED)
41MAKEROM_FLAGS			?=
42MAKEROM_FLAGS			+= $(if $(NITRO_FINALROM),,-F)
43
44# Convert Unix and Windows format paths
45ROOT_M					:= $(call empath,$(ROOT))
46MAKEROM_ROMROOT_M		:= $(call empath,$(MAKEROM_ROMROOT))
47NITRO_COMPONENTSDIR_M	:= $(ROOT_M)/components
48
49MAKEROM_ARM7_M			:= $(call empath,$(basename $(MAKEROM_ARM7)))
50MAKEROM_ARM9_M			:= $(call empath,$(basename $(MAKEROM_ARM9)))
51ROM_SPEC_M				:= $(call empath,$(ROM_SPEC))
52
53MAKEROM_DEFS			 = -DNITROSDK_ROOT='$(ROOT_M)'				\
54						   -DTARGET_NAME='$(TARGET_NAME)'			\
55						   -DMAKEROM_ROMROOT='$(MAKEROM_ROMROOT_M)'	\
56						   -DMAKEROM_ROMFILES='$(MAKEROM_ROMFILES)'	\
57						   -DMAKEROM_ROMSPEED='$(MAKEROM_ROMSPEED)'	\
58						   -DBINDIR='$(BINDIR)'						\
59						   -DCOMPDIR='$(NITRO_COMPONENTSDIR_M)'		\
60						   -DCOMPTYPE9='$(NITRO_BUILDTYPE_ARM9)'	\
61						   -DCOMPTYPE7='$(NITRO_BUILDTYPE_ARM7)'	\
62						   -DPROC='$(CODEGEN_PROC)'					\
63						   -DPLATFORM='$(NITRO_PLATFORM)'			\
64						   -DCODEGEN='$(NITRO_LIBSUFFIX)'			\
65						   -DBUILD='$(NITRO_BUILD_DIR)'				\
66						   -DCOMPSUFFIX9='$(COMPSUFFIX)'			\
67						   -DCOMPSUFFIX7=''
68
69TARGET_ROM		 = $(strip $(findstring .srl,$(TARGET_BIN))			\
70				   $(findstring .bin,$(TARGET_BIN)))
71
72ifneq	($(strip $(OBJS) $(LLIBRARIES)),)	# Any object?
73ifeq	($(CODEGEN_PROC),ARM9)
74SDEPENDS_BIN	 = $(BINDIR)/%.$(NITRO_ELF_EXT) $(MAKEROM_ARM7)
75MAKEROM_DEFS	+= -DMAKEROM_ARM9='$(BINDIR)/$(TARGET_NAME)'	\
76			-DMAKEROM_ARM7='$(MAKEROM_ARM7_M)'
77else	# !ARM9
78SDEPENDS_BIN	 = $(BINDIR)/%.$(NITRO_ELF_EXT) $(MAKEROM_ARM9)
79MAKEROM_DEFS	+= -DMAKEROM_ARM9='$(MAKEROM_ARM9_M)'				\
80			-DMAKEROM_ARM7='$(call empath,$(basename $@))'
81endif	# -ARM9
82else	# !OBJS !LLIBRARIES
83SDEPENDS_BIN	 = $(MAKEROM_ARM9) $(MAKEROM_ARM7)
84MAKEROM_DEFS	+= -DMAKEROM_ARM9='$(MAKEROM_ARM9_M)'				\
85				   -DMAKEROM_ARM7='$(MAKEROM_ARM7_M)'
86endif	# -OBJS -LLIBRARIES
87
88# Unnecessary during clean or clobber (supports make 3.80)
89ifneq	($(filter clean clobber,$(MAKECMDGOALS)),)
90else
91ifndef	USE_MY_RULE_BIN
92$(BINDIR)/%.bin $(BINDIR)/%.srl: $(SDEPENDS_BIN) $(ROM_SPEC) $(LDEPENDS_BIN) $(EDEPENDS_BIN)
93ifdef SILENT
94	echo $(TWLSDK_MSG_MAKE_SRL) $(notdir $@)
95endif
96	$(MAKEROM) $(MAKEROM_FLAGS) $(MAKEROM_DEFS) $(ROM_SPEC_M) $(call empath,$@)
97endif	# -USE_MY_RULE_BIN
98endif	# not clean/clobber
99
100#$(BINDIR)/$(TARGET_SIGN_BIN): $(BINDIR)/$(TARGET_BIN)
101#	$(TWLSDK_ROOT)/tools/bin/attachsign.exe -D $(addprefix $(BINDIR)/,$(TARGET_BIN))
102
103else	# !NITRO_MAKEROM
104#
105# ELFTOBIN
106#
107ifndef	USE_MY_RULE_BIN
108ifeq	($(CODEGEN_PROC),ARM9)
109$(BINDIR)/%.bin $(BINDIR)/%.srl: $(BINDIR)/%.$(NITRO_ELF_EXT) $(LDEPENDS_BIN) $(EDEPENDS_BIN)
110	$(ELFTOBIN) $< $(ELFTOBIN_ARM7) $(ELFTOBIN_ROMHEADER) -o $@
111else	# !ARM9
112$(BINDIR)/%.bin $(BINDIR)/%.srl: $(BINDIR)/%.$(NITRO_ELF_EXT) $(LDEPENDS_BIN) $(EDEPENDS_BIN)
113	$(ELFTOBIN) $(ELFTOBIN_ARM9) $< $(ELFTOBIN_ROMHEADER) -o $@
114endif	# -ARM9
115endif	# -USE_MY_RULE_BIN
116endif	# -NITRO_MAKEROM
117
118endif	# -FORCE_BUILD
119
120# .bnr .bsf
121%.bnr:		%.bsf
122ifdef SILENT
123	echo $(TWLSDK_MSG_MAKE_BNR) $(notdir $@)
124endif
125		$(MAKEBANNER) $(MAKEBANNER_FLAGS) $< $@
126
127%.nbfs %.nbfc %.nbfp:	%.bmp
128		$(NTEXCONV) -no -bg -bgb -bgnc $(NTEXCONV_FLAGS) $< >/dev/null
129
130# .sbin
131# The SBIN files are created by the linker at the same time as the NEF files
132%.sbin:			%.$(NITRO_ELF_EXT);
133%_defs.sbin:	%.$(NITRO_ELF_EXT);
134%_table.sbin:	%.$(NITRO_ELF_EXT);
135
136#----------------------------------------------------------------------------
137#  MAKE TARGETS
138#----------------------------------------------------------------------------
139
140%_for_arm:   CODEGEN_ARCH=
141%_for_arm:   BUILD_CODEGEN=ARM
142%_for_thumb: CODEGEN_ARCH=.thumb
143%_for_thumb: BUILD_CODEGEN=THUMB
144
145#----------------------------------------------------------------------------
146#  Make build
147#----------------------------------------------------------------------------
148.PHONY: do-build build_and_install
149.PHONY: build_for_% build_platform
150
151ifeq	($(PARALLEL_BUILD),TRUE)
152build_platform:  build_for_thumb build_for_arm
153else
154build_platform:  build_for_thumb
155build_for_thumb: build_for_arm
156endif
157
158build_for_%:
159	+$(if $(filter $(BUILD_CODEGEN),$(TARGET_CODEGEN_LIST)),		\
160		@$(ECHO_CURDIR)												\
161		$(DO_MAKEDIR)												\
162		$(REMAKE) TARGET_CODEGEN=$(BUILD_CODEGEN) SKIP_SUBDIR=TRUE INSTALL_DEPENDS=do-build INSTALL_FOR=$* build_and_install)
163
164build_and_install: install_for_$(INSTALL_FOR)
165
166#----------------------------------------------------------------------------
167#  Make install
168#----------------------------------------------------------------------------
169
170.PHONY: install_for_% install_platform
171
172ifeq	($(PARALLEL_BUILD),TRUE)
173install_platform:  install_for_thumb install_for_arm
174else
175install_platform:  install_for_thumb
176install_for_thumb: install_for_arm
177endif
178
179install_for_%: $(INSTALL_DEPENDS)
180	$(if $(filter $(BUILD_CODEGEN),$(TARGET_CODEGEN_LIST)),	\
181		$(if $(INSTALL_TARGETS),							\
182			@$(ECHO_CURDIR)									\
183			$(DO_INSTALL) ))
184
185#----------------------------------------------------------------------------
186#  Autotest using IS-NITRO-EMULATOR
187#----------------------------------------------------------------------------
188ifdef	IS_NITRO_DIR
189
190AUTOTESTLOG	:= $(ROOT)/autotest.log
191
192.PHONY: 	autotest do-autotest do-autotest-test
193
194autotest:
195	@+$(REMAKE) clobber
196	@+$(REMAKE) build NITRO_AUTOTEST=TRUE
197	@$(RM) $(AUTOTESTLOG)
198	@+$(REMAKE) do-autotest
199	@$(SED) -e 's/\r//g;s/$$/\r/g;' $(AUTOTESTLOG) > $(AUTOTESTLOG).tmp
200	@$(MV)  $(AUTOTESTLOG).tmp $(AUTOTESTLOG)
201
202do-autotest: make-sub
203	@$(ECHO_CURDIR)
204ifneq	($(TARGET_ROM),)
205	@+$(REMAKE) test-run
206endif
207endif
208
209
210#----------------------------------------------------------------------------
211#  Make clobber & clean
212#----------------------------------------------------------------------------
213.PHONY: 	clobber-installed
214.PHONY:		clobber_for_%
215
216clobber-installed: clobber_for_thumb
217clobber_for_thumb: clobber_for_arm
218
219clobber_for_%:
220	+-$(if $(filter $(BUILD_CODEGEN),$(TARGET_CODEGEN_LIST)),		\
221		$(RM) $(GDIRT_INSTALLED))
222
223#----------------------------------------------------------------------------
224#  Source file dependencies
225#----------------------------------------------------------------------------
226
227#
228# Dynamic dependency generation
229#   Like as $(OBJDIR)/main.o: main.c
230#
231DEP_SRCS_ALL = $(SRCS) $(SRCS_AUTOLOAD) $(SRCS_OVERLAY)
232
233define RuleCtoObj
234$$(OBJDIR)/$$(notdir $$(basename $(1))).o: $(1)
235
236endef
237endif	# NITROSDK_MODULERULES_
238
239# Put this sentence out of include-guard to avoid $(eval xxx) limitation
240$(foreach FILE,$(DEP_SRCS_ALL),$(eval $(call RuleCtoObj,$(FILE))))
241
242
243ifndef	NITROSDK_MODULERULES_
244#
245# Include dependencies file
246#
247ifneq	($(filter build_and_install,$(MAKECMDGOALS)),)
248ifdef	SRCS
249-include $(DEPENDDIR)/*.d
250endif
251endif
252
253#----------------------------------------------------------------------------
254#  For IS-NITRO-EMULATOR
255#----------------------------------------------------------------------------
256ifdef	IS_TWL_DIR
257-include $(NITRO_BUILDTOOLSDIR)/modulerules.emtype.IS
258else
259ifdef	IS_NITRO_DIR
260-include $(NITRO_BUILDTOOLSDIR)/modulerules.emtype.IS
261endif
262endif
263
264#----------------------------------------------------------------------------
265#  Load add-ins' modulerules
266#----------------------------------------------------------------------------
267-include $(NITRO_BUILDTOOLSDIR)/modulerules.add-ins.*
268
269#----------------------------------------------------------------------------
270NITROSDK_MODULERULES_ = TRUE
271endif	# NITROSDK_MODULERULES_
272#----- End of modulerules -----
273