You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

103 lines
2.3 KiB

# Builds fat lib for iOS (ARM64 & x86_64).
# Pass PREFIX as argument. If not passed, "local/" is used as deafult.
# Exit on errors
set -e
SCRIPT_DIR=$(dirname "$0")
PREFIX=$1
# Get Absolute Paths & Setup
SCRIPT_DIR=$(dirname "$0")
pushd "${SCRIPT_DIR}"
SCRIPT_DIR=$(pwd)
popd
if [ "${PREFIX}" = "" ]; then
PREFIX="${SCRIPT_DIR}/local"
fi
mkdir -p "${PREFIX}"
pushd "${PREFIX}"
PREFIX=$(pwd)
popd
TMP_DIR="${SCRIPT_DIR}/tmp"
INCLUDE_DIR="${PREFIX}/include"
LIB_DIR="${PREFIX}/lib"
BIN_DIR="${PREFIX}/bin"
mkdir -p "${INCLUDE_DIR}"
mkdir -p "${LIB_DIR}"
mkdir -p "${TMP_DIR}"
IOS_DEPLOYMENT_TARGET=$(sh "${SCRIPT_DIR}"/get-config-ios-deployment-target.sh)
# Funcs
buildLib()
{
ARCH=$1
TARGET=$2
HOST=$3
SDK=$4
SDK_PATH=`xcrun -sdk ${SDK} --show-sdk-path`
CURRENT_LIB_DIR="${TMP_DIR}/${ARCH}"
mkdir -p "${CURRENT_LIB_DIR}/lib"
mkdir -p "${CURRENT_LIB_DIR}/include"
mkdir -p "${CURRENT_LIB_DIR}/bin"
# Set CFLAGS that fit most targets. Can be overrriden in .code file
if [[ $TARGET == *"ios"* ]]; then
export CFLAGS="-arch ${ARCH} -isysroot ${SDK_PATH} -std=c99 -miphoneos-version-min=${IOS_DEPLOYMENT_TARGET}"
else
if [[ $ARCH == "arm64" ]]; then
export CFLAGS="-arch ${ARCH} -isysroot ${SDK_PATH} -std=c99 -mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET_ARM}"
elif [[ $ARCH == "x86_64" ]]; then
export CFLAGS="-arch ${ARCH} -isysroot ${SDK_PATH} -std=c99 -mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET_INTEL}"
else
echo "Unhandled arch"
exit 1
fi
fi
# START: Lib Specific Code
BUILD_CODE
# END: Lib Specific Code
unset CFLAGS
unset LDFLAGS
unset CC
}
cleanup()
{
rm -rf "${TMP_DIR}/x86_64"
rm -rf "${TMP_DIR}/arm64"
}
# Setup
cleanup
mkdir -p "${TMP_DIR}"
mkdir -p "${PREFIX}"
# Build
pushd "${TMP_DIR}"
buildLib "arm64" "aarch64-apple-ios" "aarch64-apple-darwin" "iphoneos"
buildLib "x86_64" "x86_64-apple-ios" "x86_64-apple-darwin" "iphonesimulator"
popd
# Make Fat Lib
sh "${SCRIPT_DIR}/build-fat-libs.sh" "${TMP_DIR}/arm64/lib" "${TMP_DIR}/x86_64/lib" "${LIB_DIR}"
# Copy Headers If Currently Building Lib
ARM64_INCLUDE_DIR="${TMP_DIR}/arm64/include"
cp -r "${ARM64_INCLUDE_DIR}"/* "${INCLUDE_DIR}" 2>/dev/null || :
# Cleanup
cleanup