19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#!/bin/sh
29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#
39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# Build a fat binary on Mac OS X, thanks Ryan!
49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# Number of CPUs (for make -j)
69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallNCPU=`sysctl -n hw.ncpu`
79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallif test x$NJOB = x; then
89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    NJOB=$NCPU
99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallfi
109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# SDK path
129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallif test x$SDK_PATH = x; then
139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDK_PATH=/Developer/SDKs
149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallfi
159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# Generic, cross-platform CFLAGS you always want go here.
179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallCFLAGS="-O3 -g -pipe"
189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# We dynamically load X11, so using the system X11 headers is fine.
209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallBASE_CONFIG_FLAGS="--build=`uname -p`-apple-darwin \
219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall--x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# PowerPC 32-bit compiler flags
249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallCONFIG_PPC="--host=powerpc-apple-darwin"
259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallCC_PPC="gcc-4.0"
269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallCXX_PPC="g++-4.0"
279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallBUILD_FLAGS_PPC="-arch ppc -mmacosx-version-min=10.4"
289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# Intel 32-bit compiler flags
309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallCONFIG_X86="--host=i386-apple-darwin"
319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallCC_X86="gcc"
329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallCXX_X86="g++"
339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallBUILD_FLAGS_X86="-arch i386 -mmacosx-version-min=10.4"
349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# Intel 64-bit compiler flags
369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallCONFIG_X64="--host=x86_64-apple-darwin"
379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallCC_X64="gcc"
389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallCXX_X64="g++"
399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallBUILD_FLAGS_X64="-arch x86_64 -mmacosx-version-min=10.6"
409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#
429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# Find the configure script
439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#
449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallsrcdir=`dirname $0`/..
459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallauxdir=$srcdir/build-scripts
469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallcd $srcdir
479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallallow_ppc="yes"
499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallwhich gcc-4.0 >/dev/null 2>/dev/null
509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallif [ "x$?" = "x1" ]; then
519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    #echo "WARNING: Can't find gcc-4.0, which means you don't have Xcode 3."
529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    #echo "WARNING: Therefore, we can't do PowerPC support."
539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    allow_ppc="no"
549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallfi
559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#
579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# Figure out which phase to build:
589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# all,
599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# configure, configure-ppc, configure-x86, configure-x64
609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# make, make-ppc, make-x86, make-x64, merge
619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# install
629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# clean
639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallif test x"$1" = x; then
649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    phase=all
659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallelse
669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    phase="$1"
679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallfi
689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallcase $phase in
699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    all)
709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        configure_ppc="$allow_ppc"
719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        configure_x86="yes"
729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        configure_x64="yes"
739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        make_ppc="$allow_ppc"
749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        make_x86="yes"
759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        make_x64="yes"
769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        merge="yes"
779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ;;
789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    configure)
799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        configure_ppc="$allow_ppc"
809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        configure_x86="yes"
819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        configure_x64="yes"
829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ;;
839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    configure-ppc)
849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        configure_ppc="$allow_ppc"
859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ;;
869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    configure-x86)
879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        configure_x86="yes"
889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ;;
899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    configure-x64)
909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        configure_x64="yes"
919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ;;
929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    make)
939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        make_ppc="$allow_ppc"
949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        make_x86="yes"
959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        make_x64="yes"
969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        merge="yes"
979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ;;
989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    make-ppc)
999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        make_ppc="$allow_ppc"
1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ;;
1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    make-x86)
1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        make_x86="yes"
1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ;;
1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    make-x64)
1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        make_x64="yes"
1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ;;
1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    merge)
1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        merge="yes"
1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ;;
1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    install)
1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        install_bin="yes"
1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        install_hdrs="yes"
1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        install_lib="yes"
1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        install_data="yes"
1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        install_man="yes"
1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ;;
1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    install-bin)
1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        install_bin="yes"
1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ;;
1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    install-hdrs)
1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        install_hdrs="yes"
1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ;;
1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    install-lib)
1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        install_lib="yes"
1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ;;
1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    install-data)
1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        install_data="yes"
1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ;;
1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    install-man)
1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        install_man="yes"
1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ;;
1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    clean)
1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        clean_ppc="yes"
1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        clean_x86="yes"
1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        clean_x64="yes"
1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ;;
1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    clean-ppc)
1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        clean_ppc="yes"
1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ;;
1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    clean-x86)
1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        clean_x86="yes"
1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ;;
1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    clean-x64)
1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        clean_x64="yes"
1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ;;
1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    *)
1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        echo "Usage: $0 [all|configure[-ppc|-x86|-x64]|make[-ppc|-x86|-x64]|merge|install|clean[-ppc|-x86|-x64]]"
1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        exit 1
1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ;;
1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallesac
1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallcase `uname -p` in
1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    *86)
1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        native_path=x86
1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ;;
1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    *powerpc)
1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        native_path=ppc
1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ;;
1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    x86_64)
1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        native_path=x64
1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ;;
1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    *)
1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        echo "Couldn't figure out native architecture path"
1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        exit 1
1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ;;
1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallesac
1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#
1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# Create the build directories
1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#
1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallfor dir in build build/ppc build/x86 build/x64; do
1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if test -d $dir; then
1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        :
1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    else
1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mkdir $dir || exit 1
1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    fi
1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Halldone
1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#
1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# Build the PowerPC 32-bit binary
1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#
1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallif test x$configure_ppc = xyes; then
1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    (cd build/ppc && \
1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     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
1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallfi
1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallif test x$make_ppc = xyes; then
1879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    (cd build/ppc && make -j$NJOB) || exit 3
1889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallfi
1899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#
1909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# Build the Intel 32-bit binary
1919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#
1929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallif test x$configure_x86 = xyes; then
1939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    (cd build/x86 && \
1949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     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
1959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallfi
1969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallif test x$make_x86 = xyes; then
1979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    (cd build/x86 && make -j$NJOB) || exit 3
1989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallfi
1999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#
2019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# Build the Intel 64-bit binary
2029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#
2039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallif test x$configure_x64 = xyes; then
2049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    (cd build/x64 && \
2059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     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
2069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallfi
2079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallif test x$make_x64 = xyes; then
2089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    (cd build/x64 && make -j$NJOB) || exit 3
2099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallfi
2109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#
2129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# Combine into fat binary
2139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#
2149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallif test x$merge = xyes; then
2159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    output=.libs
2169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    sh $auxdir/mkinstalldirs build/$output
2179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    cd build
2189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    target=`find . -mindepth 4 -maxdepth 4 -type f -name '*.dylib' | head -1 | sed 's|.*/||'`
2199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    (lipo -create -o $output/$target `find . -mindepth 4 -maxdepth 4 -type f -name "*.dylib"` &&
2209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     ln -sf $target $output/libSDL.dylib &&
2219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     lipo -create -o $output/libSDL.a */build/.libs/libSDL.a &&
2229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     cp $native_path/build/.libs/libSDL.la $output &&
2239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     cp $native_path/build/.libs/libSDL.lai $output &&
2249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     cp $native_path/build/libSDL.la . &&
2259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     lipo -create -o $output/libSDLmain.a */build/.libs/libSDLmain.a &&
2269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     cp $native_path/build/.libs/libSDLmain.la $output &&
2279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     cp $native_path/build/.libs/libSDLmain.lai $output &&
2289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     cp $native_path/build/libSDLmain.la . &&
2299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     echo "Build complete!" &&
2309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     echo "Files can be found in the build directory.") || exit 4
2319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    cd ..
2329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallfi
2339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#
2359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# Install
2369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#
2379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Halldo_install()
2389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
2399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    echo $*
2409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    $* || exit 5
2419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallif test x$prefix = x; then
2439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    prefix=/usr/local
2449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallfi
2459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallif test x$exec_prefix = x; then
2469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    exec_prefix=$prefix
2479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallfi
2489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallif test x$bindir = x; then
2499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    bindir=$exec_prefix/bin
2509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallfi
2519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallif test x$libdir = x; then
2529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    libdir=$exec_prefix/lib
2539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallfi
2549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallif test x$includedir = x; then
2559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    includedir=$prefix/include
2569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallfi
2579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallif test x$datadir = x; then
2589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    datadir=$prefix/share
2599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallfi
2609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallif test x$mandir = x; then
2619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mandir=$prefix/man
2629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallfi
2639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallif test x$install_bin = xyes; then
2649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    do_install sh $auxdir/mkinstalldirs $bindir
2659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    do_install /usr/bin/install -c -m 755 build/$native_path/sdl-config $bindir/sdl-config
2669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallfi
2679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallif test x$install_hdrs = xyes; then
2689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    do_install sh $auxdir/mkinstalldirs $includedir/SDL
2699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    for src in $srcdir/include/*.h; do \
2709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        file=`echo $src | sed -e 's|^.*/||'`; \
2719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        do_install /usr/bin/install -c -m 644 $src $includedir/SDL/$file; \
2729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    done
2739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    do_install /usr/bin/install -c -m 644 $srcdir/include/SDL_config_macosx.h $includedir/SDL/SDL_config.h
2749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallfi
2759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallif test x$install_lib = xyes; then
2769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    do_install sh $auxdir/mkinstalldirs $libdir
2779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    do_install sh build/$native_path/libtool --mode=install /usr/bin/install -c  build/libSDL.la $libdir/libSDL.la
2789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    do_install sh build/$native_path/libtool --mode=install /usr/bin/install -c  build/libSDLmain.la $libdir/libSDLmain.la
2799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallfi
2809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallif test x$install_data = xyes; then
2819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    do_install sh $auxdir/mkinstalldirs $datadir/aclocal
2829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    do_install /usr/bin/install -c -m 644 $srcdir/sdl.m4 $datadir/aclocal/sdl.m4
2839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    do_install sh $auxdir/mkinstalldirs $libdir/pkgconfig
2849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    do_install /usr/bin/install -m 644 build/$native_path/sdl.pc $libdir/pkgconfig/sdl.pc
2859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallfi
2869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallif test x$install_man = xyes; then
2879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    do_install sh $auxdir/mkinstalldirs $mandir/man3
2889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    for src in $srcdir/docs/man3/*.3; do \
2899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        file=`echo $src | sed -e 's|^.*/||'`; \
2909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        do_install /usr/bin/install -c -m 644 $src $mandir/man3/$file; \
2919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    done
2929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallfi
2939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#
2959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# Clean up
2969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#
2979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Halldo_clean()
2989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
2999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    echo $*
3009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    $* || exit 6
3019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
3029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallif test x$clean_ppc = xyes; then
3039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    do_clean rm -r build/ppc
3049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallfi
3059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallif test x$clean_x86 = xyes; then
3069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    do_clean rm -r build/x86
3079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallfi
3089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallif test x$clean_x64 = xyes; then
3099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    do_clean rm -r build/x64
3109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallfi
311