Update setenv-macos.sh for old world Macs

This commit is contained in:
Jeffrey Walton 2021-03-10 19:09:56 -05:00
parent 73e5cb5f7c
commit d890c0201b
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
4 changed files with 199 additions and 66 deletions

View File

@ -87,7 +87,33 @@ unset ANDROID_CXXFLAGS
unset ANDROID_LDFLAGS
unset ANDROID_SYSROOT
#####################################################################
#########################################
##### Small Fixups, if needed #####
#########################################
ANDROID_CPU=$(tr '[:upper:]' '[:lower:]' <<< "${ANDROID_CPU}")
if [[ "$ANDROID_CPU" == "amd64" || "$ANDROID_CPU" == "x86_64" ]] ; then
ANDROID_CPU=x86_64
fi
if [[ "$ANDROID_CPU" == "i386" || "$ANDROID_CPU" == "i686" ]] ; then
ANDROID_CPU=i686
fi
if [[ "$ANDROID_CPU" == "armv7"* || "$ANDROID_CPU" == "armeabi"* ]] ; then
ANDROID_CPU=armeabi-v7a
fi
if [[ "$ANDROID_CPU" == "aarch64" || "$ANDROID_CPU" == "arm64"* || "$ANDROID_CPU" == "armv8"* ]] ; then
ANDROID_CPU=arm64-v8a
fi
echo "Configuring for $ANDROID_SDK ($ANDROID_CPU)"
########################################
##### Environment #####
########################################
# ANDROID_NDK_ROOT should always be set by the user (even when not running this script)
# http://groups.google.com/group/android-ndk/browse_thread/thread/a998e139aca71d77.
@ -162,14 +188,13 @@ fi
#####################################################################
THE_ARCH=$(tr '[:upper:]' '[:lower:]' <<< "${ANDROID_CPU}")
# https://developer.android.com/ndk/guides/abis.html and
# https://developer.android.com/ndk/guides/cpp-support.
# Since NDK r16 the only STL available is libc++, so we
# add -std=c++11 -stdlib=libc++ to CXXFLAGS. This is
# consistent with Android.mk and 'APP_STL := c++_shared'.
case "$THE_ARCH" in
case "$ANDROID_CPU" in
armv7*|armeabi*)
CC="armv7a-linux-androideabi${ANDROID_API}-clang"
CXX="armv7a-linux-androideabi${ANDROID_API}-clang++"
@ -189,6 +214,7 @@ case "$THE_ARCH" in
ANDROID_CXXFLAGS="${ANDROID_CXXFLAGS} -fstack-protector-strong -funwind-tables -fexceptions -frtti"
ANDROID_CXXFLAGS="${ANDROID_CXXFLAGS} -fno-addrsig -fno-experimental-isel"
;;
armv8*|aarch64|arm64*)
CC="aarch64-linux-android${ANDROID_API}-clang"
CXX="aarch64-linux-android${ANDROID_API}-clang++"
@ -207,6 +233,7 @@ case "$THE_ARCH" in
ANDROID_CXXFLAGS="${ANDROID_CXXFLAGS} -fstack-protector-strong -funwind-tables -fexceptions -frtti"
ANDROID_CXXFLAGS="${ANDROID_CXXFLAGS} -fno-addrsig -fno-experimental-isel"
;;
i686|x86)
CC="i686-linux-android${ANDROID_API}-clang"
CXX="i686-linux-android${ANDROID_API}-clang++"
@ -226,6 +253,7 @@ case "$THE_ARCH" in
ANDROID_CXXFLAGS="${ANDROID_CXXFLAGS} -fstack-protector-strong -funwind-tables -fexceptions -frtti"
ANDROID_CXXFLAGS="${ANDROID_CXXFLAGS} -fno-addrsig -fno-experimental-isel"
;;
x86_64|x64)
CC="x86_64-linux-android${ANDROID_API}-clang"
CXX="x86_64-linux-android${ANDROID_API}-clang++"
@ -251,6 +279,8 @@ case "$THE_ARCH" in
;;
esac
echo "Configuring for Android API ${ANDROID_API} ($ANDROID_CPU)"
#####################################################################
# Common to all builds

View File

@ -39,7 +39,9 @@ unset ARM_EMBEDDED_CXXFLAGS
unset ARM_EMBEDDED_LDFLAGS
unset ARM_EMBEDDED_SYSROOT
#####################################################################
########################################
##### Environment #####
########################################
if [ -z "${ARM_EMBEDDED_TOOLCHAIN-}" ]; then
ARM_EMBEDDED_TOOLCHAIN="/usr/bin"

View File

@ -88,26 +88,47 @@ unset IOS_SYSROOT
##### Small Fixups, if needed #####
#########################################
IOS_CPU=$(tr '[:upper:]' '[:lower:]' <<< "${IOS_CPU}")
ALT_SDK=$(tr '[:upper:]' '[:lower:]' <<< "${IOS_SDK}")
if [[ "$IOS_SDK" == "iPhone" ]]; then
IOS_SDK=iPhoneOS
elif [[ "$ALT_SDK" == "iphone" || "$ALT_SDK" == "iphoneos" ]]; then
IOS_SDK=iPhoneOS
fi
if [[ "$IOS_SDK" == "iPhoneOSSimulator" ]]; then
if [[ "$IOS_SDK" == "iPhoneSimulator" || "$IOS_SDK" == "iPhoneOSSimulator" ]]; then
IOS_SDK=iPhoneSimulator
elif [[ "$ALT_SDK" == "iphonesimulator" || "$ALT_SDK" == "iphoneossimulator" ]]; then
IOS_SDK=iPhoneSimulator
fi
if [[ "$IOS_SDK" == "TV" || "$IOS_SDK" == "AppleTV" ]]; then
IOS_SDK=AppleTVOS
elif [[ "$ALT_SDK" == "tv" || "$ALT_SDK" == "appletv" || "$ALT_SDK" == "appletvos" ]]; then
IOS_SDK=AppleTVOS
fi
if [[ "$IOS_SDK" == "Watch" || "$IOS_SDK" == "AppleWatch" ]]; then
IOS_SDK=WatchOS
elif [[ "$ALT_SDK" == "watch" || "$ALT_SDK" == "applewatch" || "$ALT_SDK" == "applewatchos" ]]; then
IOS_SDK=WatchOS
fi
if [[ "$IOS_CPU" == "amd64" || "$IOS_CPU" == "x86_64" ]] ; then
IOS_CPU=x86_64
fi
if [[ "$IOS_CPU" == "i386" || "$IOS_CPU" == "i586" || "$IOS_CPU" == "i686" ]] ; then
IOS_CPU=i386
fi
if [[ "$IOS_CPU" == "aarch64" || "$IOS_CPU" == "arm64"* || "$IOS_CPU" == "armv8"* ]] ; then
IOS_CPU=arm64
fi
echo "Configuring for $IOS_SDK ($IOS_CPU)"
########################################
##### Environment #####
########################################
@ -249,14 +270,17 @@ fi
IOS_CXXFLAGS="-arch $IOS_CPU $MIN_VER"
IOS_SYSROOT="$XCODE_DEVELOPER_SDK/Developer/SDKs/$XCODE_SDK"
if [ -z "$IOS_SYSROOT" ] || [ ! -d "$IOS_SYSROOT" ]; then
echo "ERROR: unable to find Xcode sysroot."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# The simulators need to disable ASM. They don't receive arch flags.
# https://github.com/weidai11/cryptopp/issues/635
if [[ "$IOS_SDK" == "iPhoneSimulator" || "$IOS_SDK" == "AppleTVSimulator" || "$IOS_SDK" == "WatchSimulator" ]]; then
IOS_CPPFLAGS="$IOS_CPPFLAGS -DCRYPTOPP_DISABLE_ASM"
fi
echo "Configuring for $IOS_SDK ($IOS_CPU)"
#####################################################################
CPP="cpp"; CC="clang"; CXX="clang++"; LD="ld"

View File

@ -49,7 +49,11 @@ fi
if [ -z "$MACOS_CPU" ]; then
MACOS_CPU="$(uname -m 2>/dev/null)"
if [[ "$MACOS_CPU" == "Power Macintosh" ]] ; then
MACOS_CPU="ppc"
if [[ $(sysctl -a 2>/dev/null | grep "hw.cpu64bit_capable: 1") ]]; then
MACOS_CPU="ppc64"
else
MACOS_CPU="ppc"
fi
fi
fi
@ -80,11 +84,17 @@ unset MACOS_SYSROOT
##### Small Fixups, if needed #####
#########################################
MACOS_CPU=$(tr '[:upper:]' '[:lower:]' <<< "${MACOS_CPU}")
# Old world Macs
if [[ "$MACOS_CPU" == "Power Macintosh" ]] ; then
if [[ "$MACOS_CPU" == "power macintosh" || "$MACOS_CPU" == "powerpc" ]] ; then
MACOS_CPU=ppc
fi
if [[ "$MACOS_CPU" == "ppc64" || "$MACOS_CPU" == "powerpc64" ]] ; then
MACOS_CPU=ppc64
fi
if [[ "$MACOS_CPU" == "386" || "$MACOS_CPU" == "i686" || "$MACOS_CPU" == "686" ]] ; then
MACOS_CPU=i386
fi
@ -97,6 +107,8 @@ if [[ "$MACOS_CPU" == "aarch64" || "$MACOS_CPU" == "arm64"* || "$MACOS_CPU" == "
MACOS_CPU=arm64
fi
echo "Configuring for $MACOS_SDK ($MACOS_CPU)"
########################################
##### Environment #####
########################################
@ -110,18 +122,21 @@ fi
# Also see https://github.com/rust-lang/rust/issues/48862
# and https://developer.apple.com/documentation/bundleresources/information_property_list/minimumosversion
# iPhones can be either 32-bit or 64-bit
# PowerMacs and Intels can be either 32-bit or 64-bit
if [[ "$MACOS_CPU" == "ppc" ]]; then
MIN_VER=-mmacosx-version-min=10
MIN_VER="-mmacosx-version-min=10.4"
elif [[ "$MACOS_CPU" == "ppc64" ]]; then
MIN_VER="-mmacosx-version-min=10.4"
elif [[ "$MACOS_CPU" == "i386" ]]; then
MIN_VER=-mmacosx-version-min=10.7
MIN_VER="-mmacosx-version-min=10.7"
elif [[ "$MACOS_CPU" == "x86_64" ]]; then
MIN_VER=-mmacosx-version-min=10.7
MIN_VER="-mmacosx-version-min=10.7"
elif [[ "$MACOS_CPU" == "arm64" ]]; then
MIN_VER=-mmacosx-version-min=11.0
MIN_VER="-mmacosx-version-min=11.0"
# And the final catch-all
else
@ -133,72 +148,121 @@ fi
# gets the major version. The second cut gets the minor version.
MAJOR_VER=$(echo "${MIN_VER}" | head -n 1 | cut -f2 -d"=" | cut -f1 -d".")
MINOR_VER=$(echo "${MIN_VER}" | head -n 1 | cut -f2 -d"=" | cut -f2 -d".")
if [ -z "$MAJOR_VER" ]; then MAJOR_VER=0; fi
if [ -z "$MINOR_VER" ]; then MINOR_VER=0; fi
if [ -z "${MAJOR_VER}" ]; then MAJOR_VER=0; fi
if [ -z "${MINOR_VER}" ]; then MINOR_VER=0; fi
# OS X 10.7 minimum required for LLVM and -stdlib=libc++
if [[ "$MAJOR_VER" -eq 10 && "$MINOR_VER" -ge 7 ]]; then
MACOS_STDLIB="-stdlib=libc++"
elif [[ "$MAJOR_VER" -gt 10 ]]; then
MACOS_STDLIB="-stdlib=libc++"
if [[ "${MAJOR_VER}" -eq 10 && "${MINOR_VER}" -ge 7 ]]; then
MACOS_STDLIB="-stdlib=libc++"
elif [[ "${MAJOR_VER}" -gt 10 ]]; then
MACOS_STDLIB="-stdlib=libc++"
fi
#####################################################################
# Allow a user override? I think we should be doing this. The use case is:
# move /Applications/Xcode somewhere else for a side-by-side installation.
if [ -z "${XCODE_DEVELOPER-}" ]; then
XCODE_DEVELOPER=$(xcode-select -print-path 2>/dev/null)
fi
if [ ! -d "$XCODE_DEVELOPER" ]; then
if [ ! -d "${XCODE_DEVELOPER}" ]; then
echo "ERROR: unable to find XCODE_DEVELOPER directory."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
if [[ "${XCODE_DEVELOPER}" == "/Developer"* ]]; then
ANTIQUE_XCODE=1
DEF_CXXFLAGS=$(echo "$DEF_CXXFLAGS" | sed 's/-Wall //g')
fi
# XCODE_DEVELOPER_SDK is the SDK location.
XCODE_DEVELOPER_SDK="$XCODE_DEVELOPER/Platforms/$MACOS_SDK.platform"
if [[ "${ANTIQUE_XCODE}" == "1" ]]
then
if [[ -d "${XCODE_DEVELOPER}/SDKs" ]]; then
XCODE_DEVELOPER_SDK="${XCODE_DEVELOPER}/SDKs"
fi
if [ ! -d "$XCODE_DEVELOPER_SDK" ]; then
echo "ERROR: unable to find XCODE_DEVELOPER_SDK directory."
echo " Is the SDK supported by Xcode and installed?"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
if [ ! -d "${XCODE_DEVELOPER_SDK}" ]; then
echo "ERROR: unable to find XCODE_DEVELOPER_SDK directory."
echo " Is the SDK supported by Xcode and installed?"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# XCODE_TOOLCHAIN is the location of the actual compiler tools.
if [ -d "$XCODE_DEVELOPER/Toolchains/XcodeDefault.xctoolchain/usr/bin/" ]; then
XCODE_TOOLCHAIN="$XCODE_DEVELOPER/Toolchains/XcodeDefault.xctoolchain/usr/bin/"
elif [ -d "$XCODE_DEVELOPER_SDK/Developer/usr/bin/" ]; then
XCODE_TOOLCHAIN="$XCODE_DEVELOPER_SDK/Developer/usr/bin/"
fi
if [ -z "$XCODE_TOOLCHAIN" ] || [ ! -d "$XCODE_TOOLCHAIN" ]; then
echo "ERROR: unable to find Xcode cross-compiler tools."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
else
if [[ -d "${XCODE_DEVELOPER}/Platforms/${MACOS_SDK}.platform" ]]; then
XCODE_DEVELOPER_SDK="${XCODE_DEVELOPER}/Platforms/${MACOS_SDK}.platform/Developer/SDKs"
fi
fi
# XCODE_SDK is the SDK name/version being used - adjust the list as appropriate.
# For example, remove 4.3, 6.2, and 6.1 if they are not installed. We go back to
# the 1.0 SDKs because Apple WatchOS uses low numbers, like 2.0 and 2.1.
XCODE_SDK=""
for i in $(seq -f "%.1f" 30.0 -0.1 1.0)
do
if [ -d "$XCODE_DEVELOPER_SDK/Developer/SDKs/$MACOS_SDK$i.sdk" ]; then
XCODE_SDK="$MACOS_SDK$i.sdk"
break
fi
done
if [[ "${ANTIQUE_XCODE}" == "1" ]]
then
for i in 10.7 10.6 10.5 10.4 10.3 10.2 10.0
do
if [ -d "${XCODE_DEVELOPER_SDK}/${MACOS_SDK}$i.sdk" ]; then
XCODE_SDK="${MACOS_SDK}$i.sdk"
break
fi
done
else
for i in $(seq -f "%.1f" 30.0 -0.1 1.0)
do
if [ -d "${XCODE_DEVELOPER_SDK}/${MACOS_SDK}$i.sdk" ]; then
XCODE_SDK="${MACOS_SDK}$i.sdk"
break
fi
done
fi
# Error checking
if [ -z "$XCODE_SDK" ]; then
if [ -z "${XCODE_SDK}" ]; then
echo "ERROR: unable to find a SDK."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
MACOS_CXXFLAGS="-arch $MACOS_CPU $MIN_VER ${MACOS_STDLIB}"
MACOS_SYSROOT="$XCODE_DEVELOPER_SDK/Developer/SDKs/$XCODE_SDK"
# XCODE_DEVELOPER_SDK is the SDK location.
if [[ "${ANTIQUE_XCODE}" == "1" ]]
then
# XCODE_DEVELOPER_SDK for old Xcode is above
:
else
if [ ! -d "${XCODE_DEVELOPER_SDK}" ]; then
echo "ERROR: unable to find XCODE_DEVELOPER_SDK directory."
echo " Is the SDK supported by Xcode and installed?"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
fi
echo "Configuring for $MACOS_SDK ($MACOS_CPU)"
# XCODE_TOOLCHAIN is the location of the actual compiler tools.
if [[ "${ANTIQUE_XCODE}" == "1" ]]
then
if [ -d "${XCODE_DEVELOPER}/usr/bin" ]; then
XCODE_TOOLCHAIN="${XCODE_DEVELOPER}/usr/bin"
fi
else
if [ -d "${XCODE_DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/" ]; then
XCODE_TOOLCHAIN="${XCODE_DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/"
elif [ -d "${XCODE_DEVELOPER_SDK}/Developer/usr/bin/" ]; then
XCODE_TOOLCHAIN="${XCODE_DEVELOPER_SDK}/Developer/usr/bin/"
elif [ -d "${XCODE_DEVELOPER_SDK}/usr/bin/" ]; then
XCODE_TOOLCHAIN="${XCODE_DEVELOPER_SDK}/usr/bin/"
fi
fi
if [ -z "${XCODE_TOOLCHAIN}" ] || [ ! -d "${XCODE_TOOLCHAIN}" ]; then
echo "ERROR: unable to find Xcode cross-compiler tools."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
MACOS_CXXFLAGS="-arch $MACOS_CPU $MIN_VER ${MACOS_STDLIB}"
MACOS_SYSROOT="${XCODE_DEVELOPER_SDK}/${MACOS_SDK}$i.sdk"
if [ -z "${MACOS_SYSROOT}" ] || [ ! -d "${MACOS_SYSROOT}" ]; then
echo "ERROR: unable to find Xcode sysroot."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
#####################################################################
@ -206,38 +270,43 @@ CPP="cpp"; CC="clang"; CXX="clang++"; LD="ld"
AS="as"; AR="libtool"; RANLIB="ranlib"
STRIP="strip"; OBJDUMP="objdump"
if [[ "${ANTIQUE_XCODE}" == "1" ]]
then
CC="gcc"; CXX="g++";
fi
# Error checking
if [ ! -e "$XCODE_TOOLCHAIN/$CC" ]; then
if [ ! -e "${XCODE_TOOLCHAIN}/$CC" ]; then
echo "ERROR: Failed to find MacOS clang. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Error checking
if [ ! -e "$XCODE_TOOLCHAIN/$CXX" ]; then
if [ ! -e "${XCODE_TOOLCHAIN}/$CXX" ]; then
echo "ERROR: Failed to find MacOS clang++. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Error checking
if [ ! -e "$XCODE_TOOLCHAIN/$RANLIB" ]; then
if [ ! -e "${XCODE_TOOLCHAIN}/$RANLIB" ]; then
echo "ERROR: Failed to find MacOS ranlib. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Error checking
if [ ! -e "$XCODE_TOOLCHAIN/$AR" ]; then
if [ ! -e "${XCODE_TOOLCHAIN}/$AR" ]; then
echo "ERROR: Failed to find MacOS ar. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Error checking
if [ ! -e "$XCODE_TOOLCHAIN/$AS" ]; then
if [ ! -e "${XCODE_TOOLCHAIN}/$AS" ]; then
echo "ERROR: Failed to find MacOS as. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Error checking
if [ ! -e "$XCODE_TOOLCHAIN/$LD" ]; then
if [ ! -e "${XCODE_TOOLCHAIN}/$LD" ]; then
echo "ERROR: Failed to find MacOS ld. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
@ -247,18 +316,19 @@ fi
# Add tools to head of path, if not present already
LENGTH=${#XCODE_TOOLCHAIN}
SUBSTR=${PATH:0:$LENGTH}
if [ "$SUBSTR" != "$XCODE_TOOLCHAIN" ]; then
export PATH="$XCODE_TOOLCHAIN:$PATH"
if [ "${SUBSTR}" != "${XCODE_TOOLCHAIN}" ]; then
PATH="${XCODE_TOOLCHAIN}:$PATH"
export PATH
fi
#####################################################################
VERBOSE=${VERBOSE:-1}
if [ "$VERBOSE" -gt 0 ]; then
echo "XCODE_TOOLCHAIN: $XCODE_TOOLCHAIN"
echo "MACOS_SDK: $MACOS_SDK"
echo "MACOS_CPU: $MACOS_CPU"
echo "MACOS_SYSROOT: $MACOS_SYSROOT"
echo "XCODE_TOOLCHAIN: ${XCODE_TOOLCHAIN}"
echo "MACOS_SDK: ${MACOS_SDK}"
echo "MACOS_CPU: ${MACOS_CPU}"
echo "MACOS_SYSROOT: ${MACOS_SYSROOT}"
if [ -n "${MACOS_CPPFLAGS}" ]; then
echo "MACOS_CPPFLAGS: ${MACOS_CPPFLAGS}"
fi
@ -277,9 +347,16 @@ fi
export IS_MACOS=1
export CPP CC CXX LD AS AR RANLIB STRIP OBJDUMP
CPPFLAGS="${DEF_CPPFLAGS} ${MACOS_CPPFLAGS} -isysroot \"${MACOS_SYSROOT}\""
CXXFLAGS="${DEF_CXXFLAGS} ${MACOS_CXXFLAGS} --sysroot \"${MACOS_SYSROOT}\""
LDFLAGS="${DEF_LDFLAGS} ${MACOS_LDFLAGS}"
if [[ "${ANTIQUE_XCODE}" == "1" ]]
then
CPPFLAGS="${DEF_CPPFLAGS} ${MACOS_CPPFLAGS} -isysroot \"${MACOS_SYSROOT}\""
CXXFLAGS="${DEF_CXXFLAGS} ${MACOS_CXXFLAGS}"
LDFLAGS="${DEF_LDFLAGS} ${MACOS_LDFLAGS} -sysroot=\"${MACOS_SYSROOT}\""
else
CPPFLAGS="${DEF_CPPFLAGS} ${MACOS_CPPFLAGS} -isysroot \"${MACOS_SYSROOT}\""
CXXFLAGS="${DEF_CXXFLAGS} ${MACOS_CXXFLAGS} --sysroot \"${MACOS_SYSROOT}\""
LDFLAGS="${DEF_LDFLAGS} ${MACOS_LDFLAGS}"
fi
# Trim whitespace as needed
CPPFLAGS=$(echo "${CPPFLAGS}" | awk '{$1=$1;print}')