build-scripts/g++-fat.sh
changeset 7255 ea30c1b99365
child 7507 885b4aab4190
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/build-scripts/g++-fat.sh	Sat Jun 01 12:53:06 2013 -0700
     1.3 @@ -0,0 +1,103 @@
     1.4 +#!/bin/sh
     1.5 +#
     1.6 +# Build Universal binaries on Mac OS X, thanks Ryan!
     1.7 +#
     1.8 +# Usage: ./configure CXX="sh g++-fat.sh" && make && rm -rf x86 x64
     1.9 +
    1.10 +DEVELOPER="`xcode-select -print-path`/Platforms/MacOSX.platform/Developer"
    1.11 +
    1.12 +# Intel 32-bit compiler flags (10.6 runtime compatibility)
    1.13 +GCC_COMPILE_X86="g++ -arch i386 -mmacosx-version-min=10.6 \
    1.14 +-DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \
    1.15 +-I/usr/local/include"
    1.16 +
    1.17 +GCC_LINK_X86="-mmacosx-version-min=10.6"
    1.18 +
    1.19 +# Intel 64-bit compiler flags (10.6 runtime compatibility)
    1.20 +GCC_COMPILE_X64="g++ -arch x86_64 -mmacosx-version-min=10.6 \
    1.21 +-DMAC_OS_X_VERSION_MIN_REQUIRED=1050 \
    1.22 +-I/usr/local/include"
    1.23 +
    1.24 +GCC_LINK_X64="-mmacosx-version-min=10.6"
    1.25 +
    1.26 +# Output both PowerPC and Intel object files
    1.27 +args="$*"
    1.28 +compile=yes
    1.29 +link=yes
    1.30 +while test x$1 != x; do
    1.31 +    case $1 in
    1.32 +        --version) exec g++ $1;;
    1.33 +        -v) exec g++ $1;;
    1.34 +        -V) exec g++ $1;;
    1.35 +        -print-prog-name=*) exec g++ $1;;
    1.36 +        -print-search-dirs) exec g++ $1;;
    1.37 +        -E) GCC_COMPILE_X86="$GCC_COMPILE_X86 -E"
    1.38 +            GCC_COMPILE_X64="$GCC_COMPILE_X64 -E"
    1.39 +            compile=no; link=no;;
    1.40 +        -c) link=no;;
    1.41 +        -o) output=$2;;
    1.42 +        *.c|*.cc|*.cpp|*.S) source=$1;;
    1.43 +    esac
    1.44 +    shift
    1.45 +done
    1.46 +if test x$link = xyes; then
    1.47 +    GCC_COMPILE_X86="$GCC_COMPILE_X86 $GCC_LINK_X86"
    1.48 +    GCC_COMPILE_X64="$GCC_COMPILE_X64 $GCC_LINK_X64"
    1.49 +fi
    1.50 +if test x"$output" = x; then
    1.51 +    if test x$link = xyes; then
    1.52 +        output=a.out
    1.53 +    elif test x$compile = xyes; then
    1.54 +        output=`echo $source | sed -e 's|.*/||' -e 's|\(.*\)\.[^\.]*|\1|'`.o
    1.55 +    fi
    1.56 +fi
    1.57 +
    1.58 +# Compile X86 32-bit
    1.59 +if test x"$output" != x; then
    1.60 +    dir=x86/`dirname $output`
    1.61 +    if test -d $dir; then
    1.62 +        :
    1.63 +    else
    1.64 +        mkdir -p $dir
    1.65 +    fi
    1.66 +fi
    1.67 +set -- $args
    1.68 +while test x$1 != x; do
    1.69 +    if test -f "x86/$1" && test "$1" != "$output"; then
    1.70 +        x86_args="$x86_args x86/$1"
    1.71 +    else
    1.72 +        x86_args="$x86_args $1"
    1.73 +    fi
    1.74 +    shift
    1.75 +done
    1.76 +$GCC_COMPILE_X86 $x86_args || exit $?
    1.77 +if test x"$output" != x; then
    1.78 +    cp $output x86/$output
    1.79 +fi
    1.80 +
    1.81 +# Compile X86 32-bit
    1.82 +if test x"$output" != x; then
    1.83 +    dir=x64/`dirname $output`
    1.84 +    if test -d $dir; then
    1.85 +        :
    1.86 +    else
    1.87 +        mkdir -p $dir
    1.88 +    fi
    1.89 +fi
    1.90 +set -- $args
    1.91 +while test x$1 != x; do
    1.92 +    if test -f "x64/$1" && test "$1" != "$output"; then
    1.93 +        x64_args="$x64_args x64/$1"
    1.94 +    else
    1.95 +        x64_args="$x64_args $1"
    1.96 +    fi
    1.97 +    shift
    1.98 +done
    1.99 +$GCC_COMPILE_X64 $x64_args || exit $?
   1.100 +if test x"$output" != x; then
   1.101 +    cp $output x64/$output
   1.102 +fi
   1.103 +
   1.104 +if test x"$output" != x; then
   1.105 +    lipo -create -o $output x86/$output x64/$output
   1.106 +fi