1#! make -f
2#----------------------------------------------------------------------------
3# Project:  RVLDWC - Library - build - buildtools
4# File:     modulerules
5#
6# Copyright 2005 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# $Revision: 1.4 $
15#----------------------------------------------------------------------------
16
17ifndef RVLDWC_MODULERULES_
18
19#----------------------------------------------------------------------------
20#	Implicit RULES
21#----------------------------------------------------------------------------
22
23.SUFFIXES:	# Delete all suffix rules
24
25VPATH		= $(SRCDIR)
26
27SSRCFILES	= $(addprefix $(OBJDIR)/,$(notdir $(SRCS)))
28
29SOBJS_CC	= $(filter %.o,$(SSRCFILES:.c=.o))
30SOBJS_AS	= $(filter %.o,$(SSRCFILES:.s=.o))
31SOBJS_CXX	= $(filter %.o,$(SSRCFILES:.cpp=.o))
32
33OBJS_CC		= $(SOBJS_CC)  $(AOBJS_CC)  $(VOBJS_CC)
34OBJS_AS		= $(SOBJS_AS)  $(AOBJS_AS)  $(VOBJS_AS)
35OBJS_CXX	= $(SOBJS_CXX) $(AOBJS_CXX) $(VOBJS_CXX)
36OBJS_STATIC	= $(SOBJS_CC)  $(SOBJS_AS) $(SOBJS_CXX) $(EXT_OBJS)
37
38OBJS		= $(OBJS_STATIC)
39
40
41#----------------------------------------------------------------------------
42# Precompile header
43
44PCHSRCS		= $(filter %.pch,$(SRCS))
45PCHFILES	= $(addprefix $(PCHDIR)/,$(notdir $(SRCS)))
46
47
48-include $(RVLDWC_BUILDTOOLSDIR)/compiler/modulerules.cctype.$(RVLDWC_CCTYPE)
49
50
51#----------------------------------------------------------------------------
52#  MAKE TARGETS
53#----------------------------------------------------------------------------
54
55.PHONY:	all default build install clean clobber full
56
57BUILDCMDS = all default build
58
59#----------------------------------------------------------------------------
60#SUBDIR_FLAGS	+= $(if $(NITRO_CODEGEN_ALL),NITRO_CODEGEN_ALL=)
61
62define MAKE_SUBDIR
63    +$(foreach DIR,$(SUBDIRS),$(MAKE) $(SUBDIR_FLAGS) -C $(DIR) $(MAKECMDGOALS) $(AND)) true
64    +$(foreach FILE,$(SUBMAKES),$(MAKE) $(SUBDIR_FLAGS) -C $(dir $(FILE)) -f $(notdir $(FILE)) $(MAKECMDGOALS) $(AND)) true
65endef
66
67
68# -----------------------------------------------------------------------------
69#
70#	echo current directory name.
71
72ifeq ($(MAKEFILE),Makefile)
73MAKEFILE_	=
74else
75MAKEFILE_	= /$(MAKEFILE)
76endif
77
78define ECHO_CURDIR
79	$(ECHO)
80	$(ECHO) "==== $(CURDIR)$(MAKEFILE_)";
81endef
82
83
84# -----------------------------------------------------------------------------
85#
86#	install file.
87
88define DO_INSTALL_FILES
89	$(INSTALL) -d $(1) $(AND)					\
90	$(foreach FILE, $(2),						\
91		if [ ! -e $(1)/$(notdir $(FILE)) -o			\
92			$(FILE) -nt $(1)/$(notdir $(FILE)) ];		\
93		then 							\
94			$(ECHO) "  install: $(FILE) -> $(1)" $(AND)	\
95			$(INSTALL) $(FILE) $(1)/$(notdir $(FILE));	\
96		fi $(AND) ) true
97endef
98
99DO_INSTALL	= $(call DO_INSTALL_FILES,$(INSTALL_DIR),$(INSTALL_TARGETS))
100
101
102#----------------------------------------------------------------------------
103#  make parallelly
104#----------------------------------------------------------------------------
105
106SUBDIRS_PREFIX	 = make-subdir-p-
107SUBDIRS_PARALLEL = $(addprefix $(SUBDIRS_PREFIX),$(SUBDIRS_P))
108
109$(SUBDIRS_PARALLEL):$(SUBDIRS_PREFIX)%:
110	$(MAKE) -C $(*F) $(MAKECMDGOALS)
111
112
113#----------------------------------------------------------------------------
114#  make build
115#----------------------------------------------------------------------------
116.PHONY:	do-build do-install
117
118build:
119	@$(MAKE_SUBDIR)
120	@$(ECHO_CURDIR)
121ifneq	($(strip $(NEWDIRS)),)
122	@$(MKDIRP) $(NEWDIRS)
123endif
124	@+$(REMAKE) do-build
125ifdef	INSTALL_TARGETS
126	@$(DO_INSTALL)
127endif
128	@+$(REMAKE) do-install
129
130
131#----------------------------------------------------------------------------
132#  make install
133#----------------------------------------------------------------------------
134
135install:
136	@$(MAKE_SUBDIR)
137	@$(ECHO_CURDIR)
138ifdef	INSTALL_TARGETS
139	@$(DO_INSTALL)
140endif
141	@+$(REMAKE) do-install
142
143
144#----------------------------------------------------------------------------
145#  make full
146#----------------------------------------------------------------------------
147
148define makefull
149	@echo [[[ make full $(1) $(CURDIR) ]]]
150	@+unset RVLDWC_DEBUG RVLDWC_RELEASE RVLDWC_FINAL;	\
151	$(foreach a,FINAL RELEASE DEBUG, \
152		$(REMAKE) RVLDWC_$a=TRUE $(1) $(AND) \
153	) true
154endef
155
156full:
157	$(call makefull,build)
158
159full-install:
160	$(call makefull,install)
161
162
163#----------------------------------------------------------------------------
164#  make super-full
165#----------------------------------------------------------------------------
166
167define makesuperfull
168	@echo [[[ make super-full $(1) $(CURDIR) ]]]
169	@+unset RVLDWC_DEBUG RVLDWC_RELEASE RVLDWC_FINAL;	\
170	$(foreach p,RVL0 GC, \
171		$(foreach a,FINAL RELEASE DEBUG, \
172			$(REMAKE) RVLDWC_$a=TRUE RVLDWC_PLATFORM=$p $(1) $(AND) \
173		)\
174	) true
175endef
176
177super-full:
178	$(call makesuperfull,build)
179
180super-full-install:
181	$(call makesuperfull,install)
182
183
184#----------------------------------------------------------------------------
185#  make clobber & clean
186#----------------------------------------------------------------------------
187.PHONY: 	clobber-installed
188
189clobber:
190	@$(MAKE_SUBDIR)
191	@$(ECHO_CURDIR)
192	-$(RM) $(GDIRT_CLEAN) $(LDIRT_CLEAN) $(GDIRT_CLOBBER) $(LDIRT_CLOBBER)
193ifneq	($(GDIRT_INSTALLED),)
194	$(call makefull,clobber-installed)
195endif
196
197clobber-installed:
198	-$(RM) $(GDIRT_INSTALLED)
199
200
201#----------------------------------------------------------------------------
202
203clean:
204	@$(MAKE_SUBDIR)
205	@$(ECHO_CURDIR)
206	-$(RM) $(GDIRT_CLEAN) $(LDIRT_CLEAN)
207
208
209-include $(RVLDWC_BUILDTOOLSDIR)/emulator/modulerules.emtype.$(RVLDWC_EMTYPE)
210
211#----------------------------------------------------------------------------
212#  source file dependancies
213#----------------------------------------------------------------------------
214
215#
216# dynamic dependancy generation
217#   like as $(OBJDIR)/main.o: main.c
218#
219DEP_SRCS_ALL = $(SRCS)
220
221define RuleCtoObj
222$$(OBJDIR)/$$(notdir $$(basename $(1))).o: $(1)
223
224endef
225endif	# RVLDWC_MODULERULES_
226
227# Put this sentance out of include-guard to avoid $(eval xxx) limitation
228$(foreach FILE,$(DEP_SRCS_ALL),$(eval $(call RuleCtoObj,$(FILE))))
229
230
231ifndef	RVLDWC_MODULERULES_
232#
233# include dependancies file
234#
235
236ifeq	($(MAKECMDGOALS),do-build)
237ifdef	SRCS
238-include $(DEPDIR)/*.d
239endif
240endif
241
242
243#----------------------------------------------------------------------------
244#  PRIVATE FLAGS
245#
246-include $(RVLDWC_BUILDTOOLSDIR)/_privaterules
247
248
249#----------------------------------------------------------------------------
250RVLDWC_MODULERULES_ = TRUE
251endif	# RVLDWC_MODULERULES_
252