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:: 2008-10-28#$
15# $Rev: 9128 $
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
88ifndef	USE_MY_RULE_BIN
89$(BINDIR)/%.bin $(BINDIR)/%.srl: $(SDEPENDS_BIN) $(ROM_SPEC) $(LDEPENDS_BIN) $(EDEPENDS_BIN)
90ifdef SILENT
91	echo $(TWLSDK_MSG_MAKE_SRL) $(notdir $@)
92endif
93	$(MAKEROM) $(MAKEROM_FLAGS) $(MAKEROM_DEFS) $(ROM_SPEC_M) $(call empath,$@)
94endif	# -USE_MY_RULE_BIN
95
96#$(BINDIR)/$(TARGET_SIGN_BIN): $(BINDIR)/$(TARGET_BIN)
97#	$(TWLSDK_ROOT)/tools/bin/attachsign.exe -D $(addprefix $(BINDIR)/,$(TARGET_BIN))
98
99else	# !NITRO_MAKEROM
100#
101# ELFTOBIN
102#
103ifndef	USE_MY_RULE_BIN
104ifeq	($(CODEGEN_PROC),ARM9)
105$(BINDIR)/%.bin $(BINDIR)/%.srl: $(BINDIR)/%.$(NITRO_ELF_EXT) $(LDEPENDS_BIN) $(EDEPENDS_BIN)
106	$(ELFTOBIN) $< $(ELFTOBIN_ARM7) $(ELFTOBIN_ROMHEADER) -o $@
107else	# !ARM9
108$(BINDIR)/%.bin $(BINDIR)/%.srl: $(BINDIR)/%.$(NITRO_ELF_EXT) $(LDEPENDS_BIN) $(EDEPENDS_BIN)
109	$(ELFTOBIN) $(ELFTOBIN_ARM9) $< $(ELFTOBIN_ROMHEADER) -o $@
110endif	# -ARM9
111endif	# -USE_MY_RULE_BIN
112endif	# -NITRO_MAKEROM
113
114endif	# -FORCE_BUILD
115
116# .bnr .bsf
117%.bnr:		%.bsf
118ifdef SILENT
119	echo $(TWLSDK_MSG_MAKE_BNR) $(notdir $@)
120endif
121		$(MAKEBANNER) $(MAKEBANNER_FLAGS) $< $@
122
123%.nbfs %.nbfc %.nbfp:	%.bmp
124		$(NTEXCONV) -no -bg -bgb -bgnc $(NTEXCONV_FLAGS) $< >/dev/null
125
126# .sbin
127# The .sbin files are created by the linker at the same time as the .nef files
128%.sbin:			%.$(NITRO_ELF_EXT);
129%_defs.sbin:	%.$(NITRO_ELF_EXT);
130%_table.sbin:	%.$(NITRO_ELF_EXT);
131
132#----------------------------------------------------------------------------
133#  MAKE TARGETS
134#----------------------------------------------------------------------------
135
136%_for_arm:   CODEGEN_ARCH=
137%_for_arm:   BUILD_CODEGEN=ARM
138%_for_thumb: CODEGEN_ARCH=.thumb
139%_for_thumb: BUILD_CODEGEN=THUMB
140
141#----------------------------------------------------------------------------
142#  Make build
143#----------------------------------------------------------------------------
144.PHONY: do-build build_and_install
145.PHONY: build_for_% build_platform
146
147ifeq	($(PARALLEL_BUILD),TRUE)
148build_platform:  build_for_thumb build_for_arm
149else
150build_platform:  build_for_thumb
151build_for_thumb: build_for_arm
152endif
153
154build_for_%:
155	+$(if $(filter $(BUILD_CODEGEN),$(TARGET_CODEGEN_LIST)),		\
156		@$(ECHO_CURDIR)												\
157		$(DO_MAKEDIR)												\
158		$(REMAKE) TARGET_CODEGEN=$(BUILD_CODEGEN) SKIP_SUBDIR=TRUE INSTALL_DEPENDS=do-build INSTALL_FOR=$* build_and_install)
159
160build_and_install: install_for_$(INSTALL_FOR)
161
162#----------------------------------------------------------------------------
163#  Make install
164#----------------------------------------------------------------------------
165
166.PHONY: install_for_% install_platform
167
168ifeq	($(PARALLEL_BUILD),TRUE)
169install_platform:  install_for_thumb install_for_arm
170else
171install_platform:  install_for_thumb
172install_for_thumb: install_for_arm
173endif
174
175install_for_%: $(INSTALL_DEPENDS)
176	$(if $(filter $(BUILD_CODEGEN),$(TARGET_CODEGEN_LIST)),	\
177		$(if $(INSTALL_TARGETS),							\
178			@$(ECHO_CURDIR)									\
179			$(DO_INSTALL) ))
180
181#----------------------------------------------------------------------------
182#  Autotest using IS-NITRO-EMULATOR
183#----------------------------------------------------------------------------
184ifdef	IS_NITRO_DIR
185
186AUTOTESTLOG	:= $(ROOT)/autotest.log
187
188.PHONY: 	autotest do-autotest do-autotest-test
189
190autotest:
191	@+$(REMAKE) clobber
192	@+$(REMAKE) build NITRO_AUTOTEST=TRUE
193	@$(RM) $(AUTOTESTLOG)
194	@+$(REMAKE) do-autotest
195	@$(SED) -e 's/\r//g;s/$$/\r/g;' $(AUTOTESTLOG) > $(AUTOTESTLOG).tmp
196	@$(MV)  $(AUTOTESTLOG).tmp $(AUTOTESTLOG)
197
198do-autotest: make-sub
199	@$(ECHO_CURDIR)
200ifneq	($(TARGET_ROM),)
201	@+$(REMAKE) test-run
202endif
203endif
204
205
206#----------------------------------------------------------------------------
207#  Make clobber & clean
208#----------------------------------------------------------------------------
209.PHONY: 	clobber-installed
210.PHONY:		clobber_for_%
211
212clobber-installed: clobber_for_thumb
213clobber_for_thumb: clobber_for_arm
214
215clobber_for_%:
216	+-$(if $(filter $(BUILD_CODEGEN),$(TARGET_CODEGEN_LIST)),		\
217		$(RM) $(GDIRT_INSTALLED))
218
219#----------------------------------------------------------------------------
220#  Source file dependencies
221#----------------------------------------------------------------------------
222
223#
224# Dynamic dependency generation
225#   Like as $(OBJDIR)/main.o: main.c
226#
227DEP_SRCS_ALL = $(SRCS) $(SRCS_AUTOLOAD) $(SRCS_OVERLAY)
228
229define RuleCtoObj
230$$(OBJDIR)/$$(notdir $$(basename $(1))).o: $(1)
231
232endef
233endif	# NITROSDK_MODULERULES_
234
235# Put this sentence out of include-guard to avoid $(eval xxx) limitation
236$(foreach FILE,$(DEP_SRCS_ALL),$(eval $(call RuleCtoObj,$(FILE))))
237
238
239ifndef	NITROSDK_MODULERULES_
240#
241# Include dependencies file
242#
243ifneq	($(filter build_and_install,$(MAKECMDGOALS)),)
244ifdef	SRCS
245-include $(DEPENDDIR)/*.d
246endif
247endif
248
249#----------------------------------------------------------------------------
250#  For IS-NITRO-EMULATOR
251#----------------------------------------------------------------------------
252ifdef	IS_TWL_DIR
253-include $(NITRO_BUILDTOOLSDIR)/modulerules.emtype.IS
254else
255ifdef	IS_NITRO_DIR
256-include $(NITRO_BUILDTOOLSDIR)/modulerules.emtype.IS
257endif
258endif
259
260#----------------------------------------------------------------------------
261#  Load add-ins' modulerules
262#----------------------------------------------------------------------------
263-include $(NITRO_BUILDTOOLSDIR)/modulerules.add-ins.*
264
265#----------------------------------------------------------------------------
266NITROSDK_MODULERULES_ = TRUE
267endif	# NITROSDK_MODULERULES_
268#----- End of modulerules -----
269