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