Skip to content

Commit

Permalink
buildlib-osx: minor cleanup
Browse files Browse the repository at this point in the history
Switch to /bin/sh, zap out bashisms, add set -e and
pass any extra arguments along to buildlib.

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
  • Loading branch information
mackyle committed Oct 28, 2017
1 parent c74ff14 commit 85f4d8d
Showing 1 changed file with 79 additions and 76 deletions.
155 changes: 79 additions & 76 deletions buildlib-osx
@@ -1,105 +1,108 @@
#!/bin/bash
#!/bin/sh

# Attempt to build a universal library for OSX

set -e

done=
dp="$(xcode-select -print-path 2>/dev/null)"
: ${dp:=/Developer}
: "${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)"
gc40="$(command -v gcc-4.0 2>/dev/null)"
gc42="$(command -v gcc-4.2 2>/dev/null)"
mp42="$(command -v gcc-apple-4.2 2>/dev/null)"
lv42="$(command -v llvm-gcc-4.2 2>/dev/null)"
gca0=
gca2=
if [ -n "$gc42" ]; then
gca2="$gc42"
gca2="$gc42"
elif [ -n "$mp42" ]; then
gca2="$mp42"
gca2="$mp42"
elif [ -n "$lv42" ]; then
gca2="$lv42"
gca2="$lv42"
fi
if [ -n "$gc40" ]; then
gca0="$gc40"
gca0="$gc40"
elif [ -n "$gca2" ]; then
gca0="$gca2"
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
# 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
# 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"
CC="$NEWCC" && export CC
fi
if [ -n "$done" ]; then
if [ -z "$MACOSX_DEPLOYMENT_TARGET" ]; then
export MACOSX_DEPLOYMENT_TARGET=10.4
fi
if [ -z "$MACOSX_DEPLOYMENT_TARGET" ]; then
MACOSX_DEPLOYMENT_TARGET=10.4 && export MACOSX_DEPLOYMENT_TARGET
fi
fi
if [ -n "$NEWCFLAGS" ]; then
if [ -z "$CFLAGS" ]; then
export CFLAGS="-O2 $NEWCFLAGS"
else
export CFLAGS="$CFLAGS $NEWCFLAGS"
fi
if [ -z "$CFLAGS" ]; then
CFLAGS="-O2 $NEWCFLAGS" && export CFLAGS
else
CFLAGS="$CFLAGS $NEWCFLAGS" && export CFLAGS
fi
fi
build="$(dirname "$0")/buildlib"
if [ -n "$MACOSX_DEPLOYMENT_TARGET" ]; then
echo "MACOSX_DEPLOYMENT_TARGET=$MACOSX_DEPLOYMENT_TARGET"
echo "MACOSX_DEPLOYMENT_TARGET=$MACOSX_DEPLOYMENT_TARGET"
fi
exec "$build"
exec "$build" "$@"

0 comments on commit 85f4d8d

Please sign in to comment.