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