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