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.
 
 

92 lines
2.0 KiB

#!/bin/bash
# Builds fat lib for macOS (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"
mkdir -p "${INCLUDE_DIR}"
mkdir -p "${LIB_DIR}"
mkdir -p "${TMP_DIR}"
MACOSX_DEPLOYMENT_TARGET_INTEL=$("${SCRIPT_DIR}"/get-config-macos-deployment-target-x86_64.sh)
MACOSX_DEPLOYMENT_TARGET_ARM=$("${SCRIPT_DIR}"/get-config-macos-deployment-target-M1.sh)
# Funcs
buildLib()
{
ARCH=$1
TARGET=$2
HOST=$3
SDK=$4
SDK_PATH=`xcrun -sdk ${SDK} --show-sdk-path`
if [ "${ARCH}" == "x86_64" ]; then
export MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET_INTEL}
elif [ "${ARCH}" == "arm64" ]; then
export MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET_ARM}
else
echo "Error: Unhandled arch!"
exit 1
fi
CURRENT_LIB_DIR="${TMP_DIR}/${ARCH}"
mkdir -p "${CURRENT_LIB_DIR}/lib"
mkdir -p "${CURRENT_LIB_DIR}/include"
# START: Lib Specific Code
BUILD_CODE
# END: Lib Specific Code
}
# Cleanup
cleanup()
{
rm -rf "${TMP_DIR}/x86_64"
rm -rf "${TMP_DIR}/arm64"
export MACOSX_DEPLOYMENT_TARGET=10.10
}
cleanup
# Setup
mkdir -p "${TMP_DIR}"
mkdir -p "${PREFIX}"
# Build
pushd "${TMP_DIR}"
buildLib "x86_64" "x86_64-apple-macos10.10" "x86_64-apple-darwin" "macosx"
buildLib "arm64" "arm64-apple-macos11.1" "aarch64-apple-darwin" "macosx"
popd
# Make Fat Lib
sh "${SCRIPT_DIR}/build-fat-libs.sh" "${TMP_DIR}/arm64/lib" "${TMP_DIR}/x86_64/lib" "${LIB_DIR}"
# Copy Headers
ARM64_INCLUDE_DIR="${TMP_DIR}/arm64/include"
cp -r "${ARM64_INCLUDE_DIR}"/* "${INCLUDE_DIR}"
# Cleanup
cleanup