Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 106 lines (101 sloc) 2.88 KB
#!/bin/bash
# Attempt to build a universal library for OSX
done=
dp="$(xcode-select -print-path 2>/dev/null)"
: ${dp:=/Developer}
gc40="$(type -P gcc-4.0 2>/dev/null)"
gc42="$(type -P gcc-4.2 2>/dev/null)"
mp42="$(type -P gcc-apple-4.2 2>/dev/null)"
lv42="$(type -P llvm-gcc-4.2 2>/dev/null)"
gca0=
gca2=
if [ -n "$gc42" ]; then
gca2="$gc42"
elif [ -n "$mp42" ]; then
gca2="$mp42"
elif [ -n "$lv42" ]; then
gca2="$lv42"
fi
if [ -n "$gc40" ]; then
gca0="$gc40"
elif [ -n "$gca2" ]; then
gca0="$gca2"
fi
if [ -d "$dp/SDKs" ]; then
# First see if 10.4u is available and gcc-4.0
if [ -z "$done" -a -r "$dp/SDKs/MacOSX10.4u.sdk/SDKSettings.plist" -a -n "$gc40" ]; then
done=1
NEWCC="$gc40"
NEWCFLAGS="-arch x86_64 -arch ppc64 -arch i386 -arch ppc"
NEWCFLAGS="$NEWCFLAGS -isysroot$dp/SDKs/MacOSX10.4u.sdk"
fi
# Or see if 10.5 is available, any compiler will do
if [ -z "$done" -a -r "$dp/SDKs/MacOSX10.5.sdk/SDKSettings.plist" -a -n "$gca0" ]; then
done=1
NEWCC="$gca0"
NEWCFLAGS="-arch x86_64 -arch ppc64 -arch i386 -arch ppc"
NEWCFLAGS="$NEWCFLAGS -isysroot$dp/SDKs/MacOSX10.5.sdk"
fi
# Or see if 10.6 is available, any 4.2 compiler will do
if [ -z "$done" -a -r "$dp/SDKs/MacOSX10.6.sdk/SDKSettings.plist" -a -n "$gca2" ]; then
done=1
NEWCC="$gca2"
NEWCFLAGS="-arch x86_64 -arch i386 -arch ppc"
NEWCFLAGS="$NEWCFLAGS -isysroot$dp/SDKs/MacOSX10.6.sdk"
fi
# Or see if 10.7 is available, any 4.2 compiler will do
if [ -z "$done" -a -r "$dp/SDKs/MacOSX10.7.sdk/SDKSettings.plist" -a -n "$gca2" ]; then
done=1
NEWCC="$gca2"
NEWCFLAGS="-arch x86_64 -arch i386"
NEWCFLAGS="$NEWCFLAGS -isysroot$dp/SDKs/MacOSX10.7.sdk"
fi
fi
if [ -z "$done" ]; then
# Select by OS version as we have no SDKs
dv="$(sysctl -n kern.osrelease 2>/dev/null | cut -d. -f1 2>/dev/null)"
if [ -z "$done" -a "$dv" = "8" ]; then
# Tiger 10.4.x
done=1
NEWCC="$gca0"
# Tiger's system libraries are not guaranteed to be universal
fi
if [ -z "$done" -a "$dv" = "9" ]; then
# Leopard 10.5.x
done=1
NEWCC="$gca0"
NEWCFLAGS="-arch x86_64 -arch ppc64 -arch i386 -arch ppc"
fi
if [ -z "$done" -a "$dv" = "10" ]; then
# Snow Leopard 10.6.x
done=1
NEWCC="$gca2"
NEWCFLAGS="-arch x86_64 -arch i386 -arch ppc"
fi
if [ -z "$done" -a "$dv" = "11" ]; then
# Lion 10.7.x
done=1
NEWCC="$gca2"
NEWCFLAGS="-arch x86_64 -arch i386"
fi
fi
if [ -n "$NEWCC" -a -z "$CC" ]; then
export CC="$NEWCC"
fi
if [ -n "$done" ]; then
if [ -z "$MACOSX_DEPLOYMENT_TARGET" ]; then
export MACOSX_DEPLOYMENT_TARGET=10.4
fi
fi
if [ -n "$NEWCFLAGS" ]; then
if [ -z "$CFLAGS" ]; then
export CFLAGS="-O2 $NEWCFLAGS"
else
export CFLAGS="$CFLAGS $NEWCFLAGS"
fi
fi
build="$(dirname "$0")/buildlib"
if [ -n "$MACOSX_DEPLOYMENT_TARGET" ]; then
echo "MACOSX_DEPLOYMENT_TARGET=$MACOSX_DEPLOYMENT_TARGET"
fi
exec "$build"