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