1###############################################################################
2# Relocatable module demo
3#
4# Copyright (C) 2001-2006 Nintendo  All rights reserved.
5#
6# These coded instructions, statements, and computer programs contain
7# proprietary information of Nintendo of America Inc. and/or Nintendo
8# Company Ltd., and are protected by Federal copyright law.  They may
9# not be disclosed to third parties or copied or duplicated in any form,
10# in whole or in part, without the prior written consent of Nintendo.
11#
12# $Log: makefile,v $
13# Revision 1.4  2009/01/16 07:03:45  ooizumi
14# Changed to use makerel, not makerelD.
15#
16# Revision 1.3  2008/09/05 09:42:00  nrs_buildsystem
17# Changed all command to adopt "make -j option(parallel processing)" (by yasuh-to).
18#
19# Revision 1.2  2006/05/30 02:59:45  kawaset
20# use REVOLUTION_SDK_ROOT instead of BUILDTOOLS_ROOT.
21#
22# Revision 1.1  2006/01/26 08:02:48  hiratsu
23# makefile for relocatable module demo.
24#
25#
26#   15    9/27/02 13:24 Shiki
27#   Modified not to sort 'import.lst' manually as makerel now does that.
28#
29#   14    8/23/02 17:44 Shiki
30#   Modified to generate EXCLUDEFILES directive in REL_LCF_FILE.
31#
32#   13    5/13/02 9:21 Shiki
33#   Added __global_destructor_chain to the relocatable module's active list
34#   just to make sure.
35#
36#   12    11/27/01 9:25 Shiki
37#   Modified to link global_destructor_chain.c from MSL.
38#
39#   11    5/21/01 9:45a Shiki
40#   Modified to evaluate static$(STRSUFFIX) target after setup.
41#
42#   10    5/14/01 3:13p Shiki
43#   Defined PREREL_LCF_FILE.
44#
45#   9     01/05/09 15:48 Shiki
46#   Revised.
47#
48#   8     01/04/02 15:00 Shiki
49#   Added an echo message for ignorable warnings.
50#
51#   7     01/04/02 14:44 Shiki
52#   Initial check-in.
53# $NoKeywords: $
54#
55###############################################################################
56
57##################################
58# QUICK START INSTRUCTIONS
59# Type "make" at /dolphin/build/demos/reldemo to build DEBUG versions.
60# Type "make NDEBUG=TRUE" to build OPTIMIZED versions.
61#
62# Copy bin/$(PLATFORM)/*.str and bin/$(PLATFORM)/*.rel to the emulation
63# drive root.
64##################################
65
66# commondefs must be included near the top so that all common variables
67# will be defined before their use.
68include $(REVOLUTION_SDK_ROOT)/build/buildtools/commondefs
69
70# build any code modules and module name string table
71all:
72	$(MAKE) setup
73	$(MAKE) build
74	$(MAKE) install
75
76# module name should be set to the name of this subdirectory
77# DEMO = TRUE indicates that this module resides under the "demos" subtree.
78# The list of selectable paths can be found in modulerules.
79MODULENAME  = reldemo
80DEMO        = TRUE
81
82# small data sections are not supported by relocatable modules
83CCFLAGS += -sdata 0 -sdata2 0
84
85ifdef MAC
86
87else
88# EPPC
89
90# CSRCS lists all C files that should be built
91# The makefile determines which objects are linked into which binaries
92# based on the dependencies you fill in at the bottom of this file
93CSRCS = static.c
94
95# CPPSRCS lists all C++ files that should be built
96# The makefile determines which objects are linked into which binaries
97# based on the dependencies you fill in at the bottom of this file
98CPPSRCS = a.cpp b.cpp
99
100# BINNAMES specifies the static portion of the program.  Note that no suffix
101# is required, as that will depend on whether this is a DEBUG build or not.
102# The final name of the binaries will be $(STATIC)$(BINSUFFIX)
103BINNAMES    = static
104
105# RELNAMES lists all relocatable modules that will be linked.
106# Note that no suffix is required, as that will depend on whether
107# this is a DEBUG build or not.
108# The final name of the modules will be $(RELNAMES)$(RELSUFFIX)
109RELNAMES    = a b
110
111# linker command file for building the static module
112LCF_FILE        = static$(LCFSUFFIX)
113
114# linker command file for building relocatable modules (for 1st step)
115PREREL_LCF_FILE = $(INC_ROOT)/dolphin/eppc.lcf
116
117# linker command file for building relocatable modules (for 2nd step)
118REL_LCF_FILE    = partial$(LCFSUFFIX)
119
120# filename of the force active symbol name list
121LST_FILE        = active$(LSTSUFFIX)
122
123endif
124
125# modulerules contains the rules that will use the above variables
126# and dependencies below to construct the binaries specified.
127include $(REVOLUTION_SDK_ROOT)/build/buildtools/modulerules
128
129# all build targets that depend on 'setup' target must be listed as
130# prerequisites  for 'dobuild'.
131dobuild: static$(STRSUFFIX)
132
133# dependencies and rules for any added rules may be placed here to take
134# advantage of commondefs.
135# $(FULLBIN_ROOT) is the location of the local bin directory
136# $(BINSUFFIX) depends on whether this is a debug build or not
137# $(DOLPHINLIBS) includes all the Dolphin libraries.
138
139# generate the module name string table. *.rel files are also generated.
140static$(STRSUFFIX): $(FULLBIN_ROOT)/static$(BINSUFFIX) $(TARGET_PLFS)
141	@echo
142	@echo ">> $(notdir $+) --> $@"
143	"$(ROOT)/X86/bin/makerel.exe" $+
144
145# $(PREPLFSUFFIX) are for the 1st .plf file build without .lcf file
146# $(PLFSUFFIX)    are for the 2nd .plf file build with .lcf file
147
148$(FULLBIN_ROOT)/a$(PREPLFSUFFIX): a.o \
149	$(BINOBJ_ROOT)/global_destructor_chain.o
150
151$(FULLBIN_ROOT)/b$(PREPLFSUFFIX): b.o \
152	$(BINOBJ_ROOT)/global_destructor_chain.o
153
154$(FULLBIN_ROOT)/static$(BINSUFFIX): static.o $(REVOLUTION_LIBS) $(LCF_FILE)
155
156$(FULLBIN_ROOT)/a$(PLFSUFFIX): a.o \
157	$(FULLBIN_ROOT)/static$(BINSUFFIX) \
158	$(BINOBJ_ROOT)/global_destructor_chain.o $(REL_LCF_FILE)
159
160$(FULLBIN_ROOT)/b$(PLFSUFFIX): b.o \
161	$(FULLBIN_ROOT)/static$(BINSUFFIX) \
162	$(BINOBJ_ROOT)/global_destructor_chain.o $(REL_LCF_FILE)
163
164# generate force active symbol list.
165$(LST_FILE): $(TARGET_PREPLFS)
166	@echo
167	@echo ">> $(notdir $+) --> $@"
168	"$(ROOT)/X86/bin/makerel.exe" $(TARGET_PREPLFS)
169	cat import.lst > $(LST_FILE)
170
171# generate linker command file for the static module.
172$(LCF_FILE): $(LST_FILE)
173	@echo
174	@echo ">> $+ --> $@"
175	cat $(INC_ROOT)/revolution/eppc.$(ARCH_TARGET).lcf > $@
176	echo "FORCEACTIVE { " >> $@
177	cat $(LST_FILE) >> $@
178	echo "    OSLink" >> $@
179	echo "    OSUnlink" >> $@
180	echo "}" >> $@
181
182# generate linker command file for relocatable modules.
183$(REL_LCF_FILE): $(LST_FILE)
184	@echo
185	@echo ">> $+ --> $@"
186	cat $(PREREL_LCF_FILE) > $@
187	echo "FORCEACTIVE { " >> $@
188	echo "    _prolog" >> $@
189	echo "    _epilog" >> $@
190	echo "    _unresolved" >> $@
191	echo "    __global_destructor_chain" >> $@
192	cat $(LST_FILE) >> $@
193	echo "}" >> $@
194	echo "EXCLUDEFILES { " >> $@
195	echo -n "    " >> $@
196	echo static$(BINSUFFIX) >> $@
197	echo " }" >> $@
198
199clean:
200	rm -f *.lst
201	rm -f *.lcf
202
203$(BINOBJ_ROOT)/global_destructor_chain.o:
204	$(CC) $(CCFLAGS) $(INCLUDES) \
205        $(COMPILE) $(MWDIR)/PowerPC_EABI_Support/Runtime/Src/global_destructor_chain.c \
206        -o $@
207