Targets genererate their own firmware
[yari.git] / shared / SDL-1.2 / build-scripts / fatbuild.sh
blobb4b16167469651536d3c45348eab276cbb10730f
1 #!/bin/sh
3 # Build a fat binary on Mac OS X, thanks Ryan!
5 # Number of CPUs (for make -j)
6 NCPU=`sysctl -n hw.ncpu`
7 NJOB=$NCPU
8 #NJOB=`expr $NCPU + 1`
10 # Generic, cross-platform CFLAGS you always want go here.
11 CFLAGS="-O3 -g -pipe"
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
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"
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"
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"
43 else # 10.2 or 10.3 SDK
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"
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"
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"
66 fi # 10.2 or 10.3 SDK
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"
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"
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"
89 # Find the configure script
91 srcdir=`dirname $0`/..
92 auxdir=$srcdir/build-scripts
93 cd $srcdir
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"
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"
115 configure)
116 configure_ppc="yes"
117 configure_x86="yes"
119 configure-ppc)
120 configure_ppc="yes"
122 configure-x86)
123 configure_x86="yes"
125 make)
126 make_ppc="yes"
127 make_x86="yes"
128 merge="yes"
130 make-ppc)
131 make_ppc="yes"
133 make-x86)
134 make_x86="yes"
136 merge)
137 merge="yes"
139 install)
140 install_bin="yes"
141 install_hdrs="yes"
142 install_lib="yes"
143 install_data="yes"
144 install_man="yes"
146 install-bin)
147 install_bin="yes"
149 install-hdrs)
150 install_hdrs="yes"
152 install-lib)
153 install_lib="yes"
155 install-data)
156 install_data="yes"
158 install-man)
159 install_man="yes"
161 clean)
162 clean_ppc="yes"
163 clean_x86="yes"
165 clean-ppc)
166 clean_ppc="yes"
168 clean-x86)
169 clean_x86="yes"
172 echo "Usage: $0 [all|configure[-ppc|-x86]|make[-ppc|-x86]|merge|install|clean]"
173 exit 1
175 esac
176 case `uname -p` in
177 powerpc)
178 native_path=ppc
180 *86)
181 native_path=x86
184 echo "Couldn't figure out native architecture path"
185 exit 1
187 esac
190 # Create the build directories
192 for dir in build build/ppc build/x86; do
193 if test -d $dir; then
195 else
196 mkdir $dir || exit 1
198 done
201 # Build the PowerPC binary
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
207 if test x$make_ppc = xyes; then
208 (cd build/ppc && ls include && make -j$NJOB) || exit 3
212 # Build the Intel binary
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
218 if test x$make_x86 = xyes; then
219 (cd build/x86 && make -j$NJOB) || exit 3
223 # Combine into fat binary
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 ..
244 # Install
246 do_install()
248 echo $*
249 $* || exit 5
251 if test x$prefix = x; then
252 prefix=/usr/local
254 if test x$exec_prefix = x; then
255 exec_prefix=$prefix
257 if test x$bindir = x; then
258 bindir=$exec_prefix/bin
260 if test x$libdir = x; then
261 libdir=$exec_prefix/lib
263 if test x$includedir = x; then
264 includedir=$prefix/include
266 if test x$datadir = x; then
267 datadir=$prefix/share
269 if test x$mandir = x; then
270 mandir=$prefix/man
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
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
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
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
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
303 # Clean up
305 do_clean()
307 echo $*
308 $* || exit 6
310 if test x$clean_x86 = xyes; then
311 do_clean rm -r build/x86
313 if test x$clean_ppc = xyes; then
314 do_clean rm -r build/ppc