Skip to content

Latest commit

 

History

History
executable file
·
299 lines (281 loc) · 7.61 KB

fatbuild.sh

File metadata and controls

executable file
·
299 lines (281 loc) · 7.61 KB
 
1
2
3
4
#!/bin/sh
#
# Build a fat binary on Mac OS X, thanks Ryan!
Apr 27, 2006
Apr 27, 2006
5
6
# Number of CPUs (for make -j)
NCPU=`sysctl -n hw.ncpu`
Aug 14, 2011
Aug 14, 2011
7
8
if test x$NJOB = x; then
NJOB=$NCPU
Jan 17, 2010
Jan 17, 2010
9
10
fi
Aug 14, 2011
Aug 14, 2011
11
12
13
14
# SDK path
if test x$SDK_PATH = x; then
SDK_PATH=/Developer/SDKs
fi
Aug 14, 2011
Aug 14, 2011
16
17
# Generic, cross-platform CFLAGS you always want go here.
CFLAGS="-O3 -g -pipe"
May 10, 2006
May 10, 2006
18
Aug 14, 2011
Aug 14, 2011
19
# Intel 32-bit configure flags (10.4 runtime compatibility)
Jan 17, 2010
Jan 17, 2010
20
21
22
# 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"
Oct 28, 2009
Oct 28, 2009
23
Aug 14, 2011
Aug 14, 2011
24
25
26
27
28
# They changed this from "darwin9" to "darwin10" in Xcode 3.2 (Snow Leopard).
GCCUSRPATH_X86=`ls -d $SDK_PATH/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin*/4.0.1`
if [ ! -d "$GCCUSRPATH_X86" ]; then
echo "Couldn't find any GCC usr path for 32-bit x86"
exit 1
Jan 17, 2010
Jan 17, 2010
29
fi
Sep 16, 2011
Sep 16, 2011
30
GCCUSRPATH_X64=`ls -d $SDK_PATH/MacOSX10.6.sdk/usr/lib/gcc/i686-apple-darwin*/4.2.1`
Aug 14, 2011
Aug 14, 2011
31
32
if [ ! -d "$GCCUSRPATH_X64" ]; then
echo "Couldn't find any GCC usr path for 64-bit x86"
Jan 17, 2010
Jan 17, 2010
33
34
35
exit 1
fi
Aug 14, 2011
Aug 14, 2011
36
# Intel 32-bit compiler flags
Apr 27, 2006
Apr 27, 2006
37
CC_X86="gcc-4.0 -arch i386"
Apr 28, 2006
Apr 28, 2006
38
CXX_X86="g++-4.0 -arch i386"
Apr 27, 2006
Apr 27, 2006
39
CFLAGS_X86="-mmacosx-version-min=10.4"
Apr 22, 2006
Apr 22, 2006
40
CPPFLAGS_X86="-DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \
Apr 28, 2006
Apr 28, 2006
41
-nostdinc \
Jan 17, 2010
Jan 17, 2010
42
-F$SDK_PATH/MacOSX10.4u.sdk/System/Library/Frameworks \
Aug 14, 2011
Aug 14, 2011
43
-I$GCCUSRPATH_X86/include \
Jan 17, 2010
Jan 17, 2010
44
-isystem $SDK_PATH/MacOSX10.4u.sdk/usr/include"
Aug 14, 2011
Aug 14, 2011
46
47
48
49
# Intel 32-bit linker flags
LFLAGS_X86="-arch i386 -Wl,-headerpad_max_install_names -mmacosx-version-min=10.4 \
-F$SDK_PATH/MacOSX10.4u.sdk/System/Library/Frameworks \
-L$GCCUSRPATH_X86 \
Jan 17, 2010
Jan 17, 2010
50
-Wl,-syslibroot,$SDK_PATH/MacOSX10.4u.sdk"
Sep 16, 2011
Sep 16, 2011
52
# Intel 64-bit configure flags (10.6 runtime compatibility)
Aug 14, 2011
Aug 14, 2011
53
54
55
56
57
# 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
Sep 16, 2011
Sep 16, 2011
58
59
60
61
CC_X64="gcc-4.2 -arch x86_64"
CXX_X64="g++-4.2 -arch x86_64"
CFLAGS_X64="-mmacosx-version-min=10.6"
CPPFLAGS_X64="-DMAC_OS_X_VERSION_MIN_REQUIRED=1060 \
Aug 14, 2011
Aug 14, 2011
62
-nostdinc \
Sep 16, 2011
Sep 16, 2011
63
-F$SDK_PATH/MacOSX10.6.sdk/System/Library/Frameworks \
Aug 14, 2011
Aug 14, 2011
64
-I$GCCUSRPATH_X64/include \
Sep 16, 2011
Sep 16, 2011
65
-isystem $SDK_PATH/MacOSX10.6.sdk/usr/include"
Aug 14, 2011
Aug 14, 2011
66
67
# Intel 64-bit linker flags
Sep 16, 2011
Sep 16, 2011
68
69
LFLAGS_X64="-arch x86_64 -Wl,-headerpad_max_install_names -mmacosx-version-min=10.6 \
-F$SDK_PATH/MacOSX10.6.sdk/System/Library/Frameworks \
Aug 14, 2011
Aug 14, 2011
70
-L$GCCUSRPATH_X64/x86_64 \
Sep 16, 2011
Sep 16, 2011
71
-Wl,-syslibroot,$SDK_PATH/MacOSX10.6.sdk"
Aug 14, 2011
Aug 14, 2011
72
73
74
75
#
# Find the configure script
#
Apr 22, 2006
Apr 22, 2006
76
77
78
srcdir=`dirname $0`/..
auxdir=$srcdir/build-scripts
cd $srcdir
79
80
81
82
#
# Figure out which phase to build:
# all,
Aug 14, 2011
Aug 14, 2011
83
84
# configure, configure-x86, configure-x64
# make, make-x86, make-x64, merge
Apr 27, 2006
Apr 27, 2006
86
# clean
87
88
89
90
91
92
93
94
if test x"$1" = x; then
phase=all
else
phase="$1"
fi
case $phase in
all)
configure_x86="yes"
Aug 14, 2011
Aug 14, 2011
95
configure_x64="yes"
Aug 14, 2011
Aug 14, 2011
97
make_x64="yes"
98
99
100
101
merge="yes"
;;
configure)
configure_x86="yes"
Aug 14, 2011
Aug 14, 2011
102
configure_x64="yes"
103
104
105
106
;;
configure-x86)
configure_x86="yes"
;;
Aug 14, 2011
Aug 14, 2011
107
108
109
configure-x64)
configure_x64="yes"
;;
110
111
make)
make_x86="yes"
Aug 14, 2011
Aug 14, 2011
112
make_x64="yes"
113
114
115
116
117
merge="yes"
;;
make-x86)
make_x86="yes"
;;
Aug 14, 2011
Aug 14, 2011
118
119
120
make-x64)
make_x64="yes"
;;
121
122
123
124
merge)
merge="yes"
;;
install)
Apr 22, 2006
Apr 22, 2006
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
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"
;;
Apr 27, 2006
Apr 27, 2006
146
147
clean)
clean_x86="yes"
Aug 14, 2011
Aug 14, 2011
148
clean_x64="yes"
Apr 27, 2006
Apr 27, 2006
149
150
151
152
;;
clean-x86)
clean_x86="yes"
;;
Aug 14, 2011
Aug 14, 2011
153
154
155
clean-x64)
clean_x64="yes"
;;
Apr 22, 2006
Apr 22, 2006
156
*)
Aug 14, 2011
Aug 14, 2011
157
echo "Usage: $0 [all|configure[-x86|-x64]|make[-x86|-x64]|merge|install|clean[-x86|-x64]]"
Apr 22, 2006
Apr 22, 2006
158
159
160
161
162
163
164
exit 1
;;
esac
case `uname -p` in
*86)
native_path=x86
;;
Aug 14, 2011
Aug 14, 2011
165
166
167
x86_64)
native_path=x64
;;
Apr 22, 2006
Apr 22, 2006
168
169
170
*)
echo "Couldn't figure out native architecture path"
exit 1
171
172
173
174
175
176
;;
esac
#
# Create the build directories
#
Aug 14, 2011
Aug 14, 2011
177
for dir in build build/x86 build/x64; do
178
179
180
181
182
183
184
185
if test -d $dir; then
:
else
mkdir $dir || exit 1
fi
done
#
Aug 14, 2011
Aug 14, 2011
186
# Build the Intel 32-bit binary
187
188
189
#
if test x$configure_x86 = xyes; then
(cd build/x86 && \
May 10, 2006
May 10, 2006
190
sh ../../configure $CONFIG_X86 CC="$CC_X86" CXX="$CXX_X86" CFLAGS="$CFLAGS $CFLAGS_X86" CPPFLAGS="$CPPFLAGS_X86" LDFLAGS="$LFLAGS_X86") || exit 2
191
192
fi
if test x$make_x86 = xyes; then
Apr 28, 2006
Apr 28, 2006
193
(cd build/x86 && make -j$NJOB) || exit 3
Aug 14, 2011
Aug 14, 2011
196
197
198
199
200
201
202
203
204
205
206
#
# 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
207
208
209
210
#
# Combine into fat binary
#
if test x$merge = xyes; then
Apr 22, 2006
Apr 22, 2006
211
212
213
output=.libs
sh $auxdir/mkinstalldirs build/$output
cd build
Aug 14, 2011
Aug 14, 2011
214
215
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"` &&
Apr 22, 2006
Apr 22, 2006
216
217
218
219
220
221
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 &&
222
223
echo "Build complete!" &&
echo "Files can be found in the build directory.") || exit 4
Apr 22, 2006
Apr 22, 2006
224
cd ..
225
226
227
228
229
fi
#
# Install
#
Apr 22, 2006
Apr 22, 2006
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
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
Apr 27, 2006
Apr 27, 2006
285
286
287
288
289
290
291
292
293
294
295
296
#
# Clean up
#
do_clean()
{
echo $*
$* || exit 6
}
if test x$clean_x86 = xyes; then
do_clean rm -r build/x86
fi
Aug 14, 2011
Aug 14, 2011
297
298
if test x$clean_x64 = xyes; then
do_clean rm -r build/x64
Apr 27, 2006
Apr 27, 2006
299
fi