1#!/bin/sh
2APPBUNDLE=wop.app
3BINARY=wop-engine.ub
4DEDBIN=ioq3ded.ub
5PKGINFO=APPWOP
6ICNS=code/unix/MacSupport/wop.icns
7DESTDIR=build/release-darwin-ub
8BASEDIR=baseq3
9MPACKDIR=missionpack
10Q3_VERSION=`grep "\#define Q3_VERSION" code/qcommon/q_shared.h | \
11	sed -e 's/.*".* \([^ ]*\)"/\1/'`;
12
13BIN_OBJ="
14	build/release-darwin-ppc/wop-engine.ppc
15	build/release-darwin-i386/wop-engine.i386
16"
17BIN_DEDOBJ="
18	build/release-darwin-ub/ioq3ded.ppc
19	build/release-darwin-i386/ioq3ded.i386
20"
21BASE_OBJ="
22	build/release-darwin-ppc/$BASEDIR/cgameppc.dylib
23	build/release-darwin-i386/$BASEDIR/cgamei386.dylib
24	build/release-darwin-ppc/$BASEDIR/uippc.dylib
25	build/release-darwin-i386/$BASEDIR/uii386.dylib
26	build/release-darwin-ppc/$BASEDIR/qagameppc.dylib
27	build/release-darwin-i386/$BASEDIR/qagamei386.dylib
28"
29MPACK_OBJ="
30	build/release-darwin-ppc/$MPACKDIR/cgameppc.dylib
31	build/release-darwin-i386/$MPACKDIR/cgamei386.dylib
32	build/release-darwin-ppc/$MPACKDIR/uippc.dylib
33	build/release-darwin-i386/$MPACKDIR/uii386.dylib
34	build/release-darwin-ppc/$MPACKDIR/qagameppc.dylib
35	build/release-darwin-i386/$MPACKDIR/qagamei386.dylib
36"
37if [ ! -f Makefile ]; then
38	echo "This script must be run from the WoP build directory";
39fi
40
41TIGERHOST=0
42if uname -r | grep ^8. > /dev/null; then
43	TIGERHOST=1
44fi
45
46# we want to use the oldest available SDK for max compatiblity
47unset PPC_CLIENT_SDK
48PPC_CLIENT_CC=gcc
49unset PPC_CLIENT_CFLAGS
50unset PPC_CLIENT_LDFLAGS
51unset PPC_SERVER_SDK
52unset PPC_SERVER_CFLAGS
53unset PPC_SERVER_LDFLAGS
54unset X86_SDK
55unset X86_CFLAGS
56unset X86_LDFLAGS
57if [ -d /Developer/SDKs/MacOSX10.5.sdk ]; then
58	PPC_CLIENT_SDK=/Developer/SDKs/MacOSX10.5.sdk
59	PPC_CLIENT_CC=gcc-4.0
60	PPC_CLIENT_CFLAGS="-arch ppc -isysroot /Developer/SDKs/MacOSX10.5.sdk \
61			-DMAC_OS_X_VERSION_MIN_REQUIRED=1050"
62	PPC_CLIENT_LDFLAGS="-arch ppc \
63			-isysroot /Developer/SDKs/MacOSX10.5.sdk \
64			-mmacosx-version-min=10.5"
65	PPC_SERVER_SDK=/Developer/SDKs/MacOSX10.5.sdk
66	PPC_SERVER_CFLAGS=$PPC_CLIENT_CFLAGS
67	PPC_SERVER_LDFLAGS=$PPC_CLIENT_LDFLAGS
68
69	X86_SDK=/Developer/SDKs/MacOSX10.5.sdk
70	X86_CFLAGS="-arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk \
71			-DMAC_OS_X_VERSION_MIN_REQUIRED=1050"
72	X86_LDFLAGS="-arch i386 \
73			-isysroot /Developer/SDKs/MacOSX10.5.sdk \
74			-mmacosx-version-min=10.5"
75	X86_ENV="CFLAGS=$CFLAGS LDFLAGS=$LDFLAGS"
76fi
77
78if [ -d /Developer/SDKs/MacOSX10.4u.sdk ]; then
79	PPC_CLIENT_SDK=/Developer/SDKs/MacOSX10.4u.sdk
80	PPC_CLIENT_CC=gcc-4.0
81	PPC_CLIENT_CFLAGS="-arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk \
82			-DMAC_OS_X_VERSION_MIN_REQUIRED=1040"
83	PPC_CLIENT_LDFLAGS="-arch ppc \
84			-isysroot /Developer/SDKs/MacOSX10.4u.sdk \
85			-mmacosx-version-min=10.4"
86	PPC_SERVER_SDK=/Developer/SDKs/MacOSX10.4u.sdk
87	PPC_SERVER_CFLAGS=$PPC_CLIENT_CFLAGS
88	PPC_SERVER_LDFLAGS=$PPC_CLIENT_LDFLAGS
89
90	X86_SDK=/Developer/SDKs/MacOSX10.4u.sdk
91	X86_CFLAGS="-arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk \
92			-DMAC_OS_X_VERSION_MIN_REQUIRED=1040"
93	X86_LDFLAGS="-arch i386 \
94			-isysroot /Developer/SDKs/MacOSX10.4u.sdk \
95			-mmacosx-version-min=10.4"
96	X86_ENV="CFLAGS=$CFLAGS LDFLAGS=$LDFLAGS"
97fi
98
99if [ -d /Developer/SDKs/MacOSX10.3.9.sdk ] && [ $TIGERHOST ]; then
100	PPC_CLIENT_SDK=/Developer/SDKs/MacOSX10.3.9.sdk
101	PPC_CLIENT_CC=gcc-4.0
102	PPC_CLIENT_CFLAGS="-arch ppc -isysroot /Developer/SDKs/MacOSX10.3.9.sdk \
103			-DMAC_OS_X_VERSION_MIN_REQUIRED=1030"
104	PPC_CLIENT_LDFLAGS="-arch ppc \
105			-isysroot /Developer/SDKs/MacOSX10.3.9.sdk \
106			-mmacosx-version-min=10.3"
107	PPC_SERVER_SDK=/Developer/SDKs/MacOSX10.3.9.sdk
108	PPC_SERVER_CFLAGS=$PPC_CLIENT_CFLAGS
109	PPC_SERVER_LDFLAGS=$PPC_CLIENT_LDFLAGS
110fi
111
112if [ -d /Developer/SDKs/MacOSX10.2.8.sdk ] && [ -x /usr/bin/gcc-3.3 ] && [ $TIGERHOST ]; then
113	PPC_CLIENT_SDK=/Developer/SDKs/MacOSX10.2.8.sdk
114	PPC_CLIENT_CC=gcc-3.3
115	PPC_CLIENT_CFLAGS="-arch ppc \
116		-nostdinc \
117		-F/Developer/SDKs/MacOSX10.2.8.sdk/System/Library/Frameworks \
118		-I/Developer/SDKs/MacOSX10.2.8.sdk/usr/include/gcc/darwin/3.3 \
119		-isystem /Developer/SDKs/MacOSX10.2.8.sdk/usr/include \
120		-DMAC_OS_X_VERSION_MIN_REQUIRED=1020"
121	PPC_CLIENT_LDFLAGS="-arch ppc \
122		-L/Developer/SDKs/MacOSX10.2.8.sdk/usr/lib/gcc/darwin/3.3 \
123		-F/Developer/SDKs/MacOSX10.2.8.sdk/System/Library/Frameworks \
124		-Wl,-syslibroot,/Developer/SDKs/MacOSX10.2.8.sdk,-m"
125fi
126
127echo "Building PPC Dedicated Server against \"$PPC_SERVER_SDK\""
128echo "Building PPC Client against \"$PPC_CLIENT_SDK\""
129echo "Building X86 Client/Dedicated Server against \"$X86_SDK\""
130if [ "$PPC_CLIENT_SDK" != "/Developer/SDKs/MacOSX10.2.8.sdk" ] || \
131	[ "$PPC_SERVER_SDK" != "/Developer/SDKs/MacOSX10.3.9.sdk" ] || \
132	[ "$X86_SDK" != "/Developer/SDKs/MacOSX10.4u.sdk" ]; then
133	echo "\
134WARNING: in order to build a binary with maximum compatibility you must
135         build on Mac OS X 10.4 using Xcode 2.3 or 2.5 and have the
136         MacOSX10.2.8, MacOSX10.3.9, and MacOSX10.4u SDKs installed
137         from the Xcode install disk Packages folder."
138fi
139
140if [ -z $PPC_CLIENT_SDK ] || [ -z $PPC_SERVER_SDK ] || [ -z $X86_SDK ]; then
141	echo "\
142ERROR: This script is for building a Universal Binary.  You cannot build
143       for a different architecture unless you have the proper Mac OS X SDKs
144       installed.  If you just want to to compile for your own system run
145       'make' instead of this script."
146	exit 1
147fi
148sleep 3
149
150if [ ! -d $DESTDIR ]; then
151	mkdir -p $DESTDIR
152fi
153
154# ppc dedicated server
155echo "Building Dedicated Server using $PPC_SERVER_SDK"
156sleep 2
157if [ -d build/release-darwin-ppc ]; then
158	rm -r build/release-darwin-ppc
159fi
160(ARCH=ppc BUILD_CLIENT_SMP=0 BUILD_CLIENT=0 BUILD_GAME_VM=0 BUILD_GAME_SO=0 \
161	CFLAGS=$PPC_SERVER_CFLAGS LDFLAGS=$PPC_SERVER_LDFLAGS make) || exit 1;
162cp build/release-darwin-ppc/ioq3ded.ppc $DESTDIR
163
164# ppc client
165if [ -d build/release-darwin-ppc ]; then
166	rm -r build/release-darwin-ppc
167fi
168(ARCH=ppc USE_OPENAL_DLOPEN=1 BUILD_SERVER=0 CC=$PPC_CLIENT_CC \
169	CFLAGS=$PPC_CLIENT_CFLAGS LDFLAGS=$PPC_CLIENT_LDFLAGS make) || exit 1;
170
171# intel client and server
172if [ -d build/release-darwin-i386 ]; then
173	rm -r build/release-darwin-i386
174fi
175(ARCH=i386 CFLAGS=$X86_CFLAGS LDFLAGS=$X86_LDFLAGS make) || exit 1;
176
177echo "Creating .app bundle $DESTDIR/$APPBUNDLE"
178if [ ! -d $DESTDIR/$APPBUNDLE/Contents/MacOS/$BASEDIR ]; then
179	mkdir -p $DESTDIR/$APPBUNDLE/Contents/MacOS/$BASEDIR || exit 1;
180fi
181if [ ! -d $DESTDIR/$APPBUNDLE/Contents/MacOS/$MPACKDIR ]; then
182	mkdir -p $DESTDIR/$APPBUNDLE/Contents/MacOS/$MPACKDIR || exit 1;
183fi
184if [ ! -d $DESTDIR/$APPBUNDLE/Contents/Resources ]; then
185	mkdir -p $DESTDIR/$APPBUNDLE/Contents/Resources
186fi
187cp $ICNS $DESTDIR/$APPBUNDLE/Contents/Resources/wop.icns || exit 1;
188echo $PKGINFO > $DESTDIR/$APPBUNDLE/Contents/PkgInfo
189echo "
190	<?xml version=\"1.0\" encoding="UTF-8"?>
191	<!DOCTYPE plist
192		PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\"
193		\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
194	<plist version=\"1.0\">
195	<dict>
196		<key>CFBundleDevelopmentRegion</key>
197		<string>English</string>
198		<key>CFBundleExecutable</key>
199		<string>$BINARY</string>
200		<key>CFBundleGetInfoString</key>
201		<string>ioquake3 $Q3_VERSION</string>
202		<key>CFBundleIconFile</key>
203		<string>wop.icns</string>
204		<key>CFBundleIdentifier</key>
205		<string>org.icculus.quake3</string>
206		<key>CFBundleInfoDictionaryVersion</key>
207		<string>6.0</string>
208		<key>CFBundleName</key>
209		<string>WorldOfPadman</string>
210		<key>CFBundlePackageType</key>
211		<string>APPL</string>
212		<key>CFBundleShortVersionString</key>
213		<string>$Q3_VERSION</string>
214		<key>CFBundleSignature</key>
215		<string>$PKGINFO</string>
216		<key>CFBundleVersion</key>
217		<string>$Q3_VERSION</string>
218		<key>NSExtensions</key>
219		<dict/>
220		<key>NSPrincipalClass</key>
221		<string>NSApplication</string>
222	</dict>
223	</plist>
224	" > $DESTDIR/$APPBUNDLE/Contents/Info.plist
225
226lipo -create -o $DESTDIR/$APPBUNDLE/Contents/MacOS/$BINARY $BIN_OBJ
227lipo -create -o $DESTDIR/$APPBUNDLE/Contents/MacOS/$DEDBIN $BIN_DEDOBJ
228rm $DESTDIR/ioq3ded.ppc
229cp $BASE_OBJ $DESTDIR/$APPBUNDLE/Contents/MacOS/$BASEDIR/
230cp $MPACK_OBJ $DESTDIR/$APPBUNDLE/Contents/MacOS/$MPACKDIR/
231cp code/libs/macosx/*.dylib $DESTDIR/$APPBUNDLE/Contents/MacOS/
232
233