This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
/
fatbuild.sh
executable file
·386 lines (360 loc) · 10.8 KB
1
2
3
4
#!/bin/sh
#
# Build a fat binary on Mac OS X, thanks Ryan!
5
6
# Number of CPUs (for make -j)
NCPU=`sysctl -n hw.ncpu`
7
8
9
if test x$NJOB = x; then
NJOB=$NCPU
fi
10
11
12
13
# Generic, cross-platform CFLAGS you always want go here.
CFLAGS="-O3 -g -pipe"
14
# PowerPC 32-bit configure flags (10.4 runtime compatibility)
15
16
17
18
# We dynamically load X11, so using the system X11 headers is fine.
CONFIG_PPC="--build=`uname -p`-apple-darwin --host=powerpc-apple-darwin \
--x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
19
# PowerPC 32-bit compiler flags
20
21
CC_PPC="gcc-4.0 -arch ppc"
CXX_PPC="g++-4.0 -arch ppc"
22
CFLAGS_PPC="-mmacosx-version-min=10.4"
23
CPPFLAGS_PPC="-DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \
24
-nostdinc \
25
26
27
-F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks \
-I/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/powerpc-apple-darwin10/4.0.1/include \
-isystem /Developer/SDKs/MacOSX10.4u.sdk/usr/include"
28
29
30
# PowerPC 32-bit linker flags
LFLAGS_PPC="-arch ppc -mmacosx-version-min=10.4 \
31
32
33
-F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks \
-L/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/powerpc-apple-darwin10/4.0.1 \
-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk"
34
35
36
37
38
39
40
41
42
# PowerPC 64-bit configure flags (10.5 runtime compatibility)
# We dynamically load X11, so using the system X11 headers is fine.
CONFIG_PPC64="--build=`uname -p`-apple-darwin --host=powerpc-apple-darwin \
--x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
# PowerPC 64-bit compiler flags
CC_PPC64="gcc-4.0 -arch ppc64"
CXX_PPC64="g++-4.0 -arch ppc64"
43
CFLAGS_PPC64="-mmacosx-version-min=10.5"
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
CPPFLAGS_PPC64="-DMAC_OS_X_VERSION_MIN_REQUIRED=1050 \
-nostdinc \
-F/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks \
-I/Developer/SDKs/MacOSX10.5.sdk/usr/lib/gcc/powerpc-apple-darwin10/4.0.1/include \
-isystem /Developer/SDKs/MacOSX10.5.sdk/usr/include"
# PowerPC 64-bit linker flags
LFLAGS_PPC64="-arch ppc64 -mmacosx-version-min=10.5 \
-F/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks \
-L/Developer/SDKs/MacOSX10.5.sdk/usr/lib/gcc/powerpc-apple-darwin10/4.0.1/ppc64 \
-Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk"
# Intel 32-bit configure flags (10.4 runtime compatibility)
# We dynamically load X11, so using the system X11 headers is fine.
CONFIG_X86="--build=`uname -p`-apple-darwin --host=i386-apple-darwin \
--x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
# Intel 32-bit configure flags (10.4 runtime compatibility)
62
63
64
65
# We dynamically load X11, so using the system X11 headers is fine.
CONFIG_X86="--build=`uname -p`-apple-darwin --host=i386-apple-darwin \
--x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
66
# Intel 32-bit compiler flags
67
CC_X86="gcc-4.0 -arch i386"
68
CXX_X86="g++-4.0 -arch i386"
69
CFLAGS_X86="-mmacosx-version-min=10.4"
70
CPPFLAGS_X86="-DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \
71
-nostdinc \
72
-F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks \
73
-I/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin10/4.0.1/include \
74
-isystem /Developer/SDKs/MacOSX10.4u.sdk/usr/include"
75
76
# Intel 32-bit linker flags
77
LFLAGS_X86="-arch i386 -mmacosx-version-min=10.4 \
78
79
-F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks \
-L/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin10/4.0.1 \
80
81
-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk"
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Intel 64-bit configure flags (10.5 runtime compatibility)
# We dynamically load X11, so using the system X11 headers is fine.
CONFIG_X64="--build=`uname -p`-apple-darwin --host=i386-apple-darwin \
--x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
# Intel 64-bit compiler flags
CC_X64="gcc-4.0 -arch x86_64"
CXX_X64="g++-4.0 -arch x86_64"
CFLAGS_X64="-mmacosx-version-min=10.5"
CPPFLAGS_X64="-DMAC_OS_X_VERSION_MIN_REQUIRED=1050 \
-nostdinc \
-F/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks \
-I/Developer/SDKs/MacOSX10.5.sdk/usr/lib/gcc/i686-apple-darwin10/4.0.1/include \
-isystem /Developer/SDKs/MacOSX10.5.sdk/usr/include"
# Intel 64-bit linker flags
LFLAGS_X64="-arch x86_64 -mmacosx-version-min=10.5 \
-F/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks \
-L/Developer/SDKs/MacOSX10.5.sdk/usr/lib/gcc/i686-apple-darwin10/4.0.1/x86_64 \
-Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk"
103
104
105
#
# Find the configure script
#
106
107
108
srcdir=`dirname $0`/..
auxdir=$srcdir/build-scripts
cd $srcdir
109
110
111
112
#
# Figure out which phase to build:
# all,
113
114
# configure, configure-ppc, configure-ppc64, configure-x86, configure-x64
# make, make-ppc, make-ppc64, make-x86, make-x64, merge
115
# install
116
# clean
117
118
119
120
121
122
123
124
if test x"$1" = x; then
phase=all
else
phase="$1"
fi
case $phase in
all)
configure_ppc="yes"
125
configure_ppc64="yes"
126
configure_x86="yes"
127
configure_x64="yes"
128
make_ppc="yes"
129
make_ppc64="yes"
130
make_x86="yes"
131
make_x64="yes"
132
133
134
135
merge="yes"
;;
configure)
configure_ppc="yes"
136
configure_ppc64="yes"
137
configure_x86="yes"
138
configure_x64="yes"
139
140
141
142
;;
configure-ppc)
configure_ppc="yes"
;;
143
144
145
configure-ppc64)
configure_ppc64="yes"
;;
146
147
148
configure-x86)
configure_x86="yes"
;;
149
150
151
configure-x64)
configure_x64="yes"
;;
152
153
make)
make_ppc="yes"
154
make_ppc64="yes"
155
make_x86="yes"
156
make_x64="yes"
157
158
159
160
161
merge="yes"
;;
make-ppc)
make_ppc="yes"
;;
162
163
164
make-ppc64)
make_ppc64="yes"
;;
165
166
167
make-x86)
make_x86="yes"
;;
168
169
170
make-x64)
make_x64="yes"
;;
171
172
173
174
merge)
merge="yes"
;;
install)
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
install_bin="yes"
install_hdrs="yes"
install_lib="yes"
install_data="yes"
install_man="yes"
;;
install-bin)
install_bin="yes"
;;
install-hdrs)
install_hdrs="yes"
;;
install-lib)
install_lib="yes"
;;
install-data)
install_data="yes"
;;
install-man)
install_man="yes"
;;
196
197
clean)
clean_ppc="yes"
198
clean_ppc64="yes"
199
clean_x86="yes"
200
clean_x64="yes"
201
202
203
204
;;
clean-ppc)
clean_ppc="yes"
;;
205
206
207
clean-ppc64)
clean_ppc64="yes"
;;
208
209
210
clean-x86)
clean_x86="yes"
;;
211
212
213
clean-x64)
clean_x64="yes"
;;
214
*)
215
echo "Usage: $0 [all|configure[-ppc|-ppc64|-x86|-x64]|make[-ppc|-ppc64|-x86|-x64]|merge|install|clean[-ppc|-ppc64|-x86|-x64]]"
216
217
218
219
220
221
222
exit 1
;;
esac
case `uname -p` in
powerpc)
native_path=ppc
;;
223
224
225
powerpc64)
native_path=ppc64
;;
226
227
228
*86)
native_path=x86
;;
229
230
231
x86_64)
native_path=x64
;;
232
233
234
*)
echo "Couldn't figure out native architecture path"
exit 1
235
236
237
238
239
240
;;
esac
#
# Create the build directories
#
241
for dir in build build/ppc build/ppc64 build/x86 build/x64; do
242
243
244
245
246
247
248
249
if test -d $dir; then
:
else
mkdir $dir || exit 1
fi
done
#
250
# Build the PowerPC 32-bit binary
251
252
253
#
if test x$configure_ppc = xyes; then
(cd build/ppc && \
254
sh ../../configure $CONFIG_PPC CC="$CC_PPC" CXX="$CXX_PPC" CFLAGS="$CFLAGS $CFLAGS_PPC" CPPFLAGS="$CPPFLAGS_PPC" LDFLAGS="$LFLAGS_PPC") || exit 2
255
256
fi
if test x$make_ppc = xyes; then
257
(cd build/ppc && ls include && make -j$NJOB) || exit 3
258
259
260
fi
#
261
262
263
264
265
266
267
268
269
270
271
272
# Build the PowerPC 64-bit binary
#
if test x$configure_ppc64 = xyes; then
(cd build/ppc64 && \
sh ../../configure $CONFIG_PPC64 CC="$CC_PPC64" CXX="$CXX_PPC64" CFLAGS="$CFLAGS $CFLAGS_PPC64" CPPFLAGS="$CPPFLAGS_PPC64" LDFLAGS="$LFLAGS_PPC64") || exit 2
fi
if test x$make_ppc64 = xyes; then
(cd build/ppc64 && ls include && make -j$NJOB) || exit 3
fi
#
# Build the Intel 32-bit binary
273
274
275
#
if test x$configure_x86 = xyes; then
(cd build/x86 && \
276
sh ../../configure $CONFIG_X86 CC="$CC_X86" CXX="$CXX_X86" CFLAGS="$CFLAGS $CFLAGS_X86" CPPFLAGS="$CPPFLAGS_X86" LDFLAGS="$LFLAGS_X86") || exit 2
277
278
fi
if test x$make_x86 = xyes; then
279
(cd build/x86 && make -j$NJOB) || exit 3
280
281
fi
282
283
284
285
286
287
288
289
290
291
292
#
# Build the Intel 32-bit binary
#
if test x$configure_x64 = xyes; then
(cd build/x64 && \
sh ../../configure $CONFIG_X64 CC="$CC_X64" CXX="$CXX_X64" CFLAGS="$CFLAGS $CFLAGS_X64" CPPFLAGS="$CPPFLAGS_X64" LDFLAGS="$LFLAGS_X64") || exit 2
fi
if test x$make_x64 = xyes; then
(cd build/x64 && make -j$NJOB) || exit 3
fi
293
294
295
296
#
# Combine into fat binary
#
if test x$merge = xyes; then
297
298
299
output=.libs
sh $auxdir/mkinstalldirs build/$output
cd build
300
301
target=`find . -mindepth 4 -maxdepth 4 -type f -name '*.dylib' | head -1 | sed 's|.*/||'`
(lipo -create -o $output/$target `find . -mindepth 4 -maxdepth 4 -type f -name "*.dylib"` &&
302
303
304
305
306
307
ln -sf $target $output/libSDL.dylib &&
lipo -create -o $output/libSDL.a */build/.libs/libSDL.a &&
cp $native_path/build/.libs/libSDL.la $output &&
cp $native_path/build/.libs/libSDL.lai $output &&
cp $native_path/build/libSDL.la . &&
lipo -create -o libSDLmain.a */build/libSDLmain.a &&
308
309
echo "Build complete!" &&
echo "Files can be found in the build directory.") || exit 4
310
cd ..
311
312
313
314
315
fi
#
# Install
#
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
do_install()
{
echo $*
$* || exit 5
}
if test x$prefix = x; then
prefix=/usr/local
fi
if test x$exec_prefix = x; then
exec_prefix=$prefix
fi
if test x$bindir = x; then
bindir=$exec_prefix/bin
fi
if test x$libdir = x; then
libdir=$exec_prefix/lib
fi
if test x$includedir = x; then
includedir=$prefix/include
fi
if test x$datadir = x; then
datadir=$prefix/share
fi
if test x$mandir = x; then
mandir=$prefix/man
fi
if test x$install_bin = xyes; then
do_install sh $auxdir/mkinstalldirs $bindir
do_install /usr/bin/install -c -m 755 build/$native_path/sdl-config $bindir/sdl-config
fi
if test x$install_hdrs = xyes; then
do_install sh $auxdir/mkinstalldirs $includedir/SDL
for src in $srcdir/include/*.h; do \
file=`echo $src | sed -e 's|^.*/||'`; \
do_install /usr/bin/install -c -m 644 $src $includedir/SDL/$file; \
done
do_install /usr/bin/install -c -m 644 $srcdir/include/SDL_config_macosx.h $includedir/SDL/SDL_config.h
fi
if test x$install_lib = xyes; then
do_install sh $auxdir/mkinstalldirs $libdir
do_install sh build/$native_path/libtool --mode=install /usr/bin/install -c build/libSDL.la $libdir/libSDL.la
do_install /usr/bin/install -c -m 644 build/libSDLmain.a $libdir/libSDLmain.a
do_install ranlib $libdir/libSDLmain.a
fi
if test x$install_data = xyes; then
do_install sh $auxdir/mkinstalldirs $datadir/aclocal
do_install /usr/bin/install -c -m 644 $srcdir/sdl.m4 $datadir/aclocal/sdl.m4
fi
if test x$install_man = xyes; then
do_install sh $auxdir/mkinstalldirs $mandir/man3
for src in $srcdir/docs/man3/*.3; do \
file=`echo $src | sed -e 's|^.*/||'`; \
do_install /usr/bin/install -c -m 644 $src $mandir/man3/$file; \
done
370
fi
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
#
# Clean up
#
do_clean()
{
echo $*
$* || exit 6
}
if test x$clean_x86 = xyes; then
do_clean rm -r build/x86
fi
if test x$clean_ppc = xyes; then
do_clean rm -r build/ppc
fi