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

  1. # Builds fat lib for iOS (ARM64 & x86_64).
  2. # Pass PREFIX as argument. If not passed, "local/" is used as deafult.
  3. # Exit on errors
  4. set -e
  5. SCRIPT_DIR=$(dirname "$0")
  6. PREFIX=$1
  7. # Get Absolute Paths & Setup
  8. SCRIPT_DIR=$(dirname "$0")
  9. pushd "${SCRIPT_DIR}"
  10. SCRIPT_DIR=$(pwd)
  11. popd
  12. if [ "${PREFIX}" = "" ]; then
  13. PREFIX="${SCRIPT_DIR}/local"
  14. fi
  15. mkdir -p "${PREFIX}"
  16. pushd "${PREFIX}"
  17. PREFIX=$(pwd)
  18. popd
  19. TMP_DIR="${SCRIPT_DIR}/tmp"
  20. INCLUDE_DIR="${PREFIX}/include"
  21. LIB_DIR="${PREFIX}/lib"
  22. BIN_DIR="${PREFIX}/bin"
  23. mkdir -p "${INCLUDE_DIR}"
  24. mkdir -p "${LIB_DIR}"
  25. mkdir -p "${TMP_DIR}"
  26. IOS_DEPLOYMENT_TARGET=$(sh "${SCRIPT_DIR}"/get-config-ios-deployment-target.sh)
  27. # Funcs
  28. buildLib()
  29. {
  30. ARCH=$1
  31. TARGET=$2
  32. HOST=$3
  33. SDK=$4
  34. SDK_PATH=`xcrun -sdk ${SDK} --show-sdk-path`
  35. CURRENT_LIB_DIR="${TMP_DIR}/${ARCH}"
  36. mkdir -p "${CURRENT_LIB_DIR}/lib"
  37. mkdir -p "${CURRENT_LIB_DIR}/include"
  38. mkdir -p "${CURRENT_LIB_DIR}/bin"
  39. # Set CFLAGS that fit most targets. Can be overrriden in .code file
  40. if [[ $TARGET == *"ios"* ]]; then
  41. export CFLAGS="-arch ${ARCH} -isysroot ${SDK_PATH} -std=c99 -miphoneos-version-min=${IOS_DEPLOYMENT_TARGET}"
  42. else
  43. if [[ $ARCH == "arm64" ]]; then
  44. export CFLAGS="-arch ${ARCH} -isysroot ${SDK_PATH} -std=c99 -mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET_ARM}"
  45. elif [[ $ARCH == "x86_64" ]]; then
  46. export CFLAGS="-arch ${ARCH} -isysroot ${SDK_PATH} -std=c99 -mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET_INTEL}"
  47. else
  48. echo "Unhandled arch"
  49. exit 1
  50. fi
  51. fi
  52. # START: Lib Specific Code
  53. BUILD_CODE
  54. # END: Lib Specific Code
  55. unset CFLAGS
  56. unset LDFLAGS
  57. unset CC
  58. }
  59. cleanup()
  60. {
  61. rm -rf "${TMP_DIR}/x86_64"
  62. rm -rf "${TMP_DIR}/arm64"
  63. }
  64. # Setup
  65. cleanup
  66. mkdir -p "${TMP_DIR}"
  67. mkdir -p "${PREFIX}"
  68. # Build
  69. pushd "${TMP_DIR}"
  70. buildLib "arm64" "aarch64-apple-ios" "aarch64-apple-darwin" "iphoneos"
  71. buildLib "x86_64" "x86_64-apple-ios" "x86_64-apple-darwin" "iphonesimulator"
  72. popd
  73. # Make Fat Lib
  74. sh "${SCRIPT_DIR}/build-fat-libs.sh" "${TMP_DIR}/arm64/lib" "${TMP_DIR}/x86_64/lib" "${LIB_DIR}"
  75. # Copy Headers If Currently Building Lib
  76. ARM64_INCLUDE_DIR="${TMP_DIR}/arm64/include"
  77. cp -r "${ARM64_INCLUDE_DIR}"/* "${INCLUDE_DIR}" 2>/dev/null || :
  78. # Cleanup
  79. cleanup