1
0

build-wolfssl-framework.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/bin/bash
  2. # build-wolfssl-framework.sh
  3. #
  4. # Copyright (C) 2006-2023 wolfSSL Inc.
  5. #
  6. # This file is part of wolfSSL.
  7. #
  8. # wolfSSL is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # wolfSSL is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  21. set -euo pipefail
  22. WOLFSSL_DIR=$(pwd)/../../
  23. OUTDIR=$(pwd)/artifacts
  24. LIPODIR=${OUTDIR}/lib
  25. SDK_OUTPUT_DIR=${OUTDIR}/xcframework
  26. CFLAGS_COMMON=""
  27. # Base configure flags
  28. CONF_OPTS="--disable-shared --enable-static"
  29. helpFunction()
  30. {
  31. echo ""
  32. echo "Usage: $0 [-c <config flags>]"
  33. echo -e "\t-c Extra flags to be passed to ./configure"
  34. exit 1 # Exit script after printing help
  35. }
  36. # Parse command line arguments
  37. while getopts ":c:" opt; do
  38. case $opt in
  39. c)
  40. CONF_OPTS+=" $OPTARG"
  41. ;;
  42. \?)
  43. echo "Invalid option: -$OPTARG" >&2; helpFunction
  44. ;;
  45. esac
  46. done
  47. rm -rf $OUTDIR
  48. mkdir -p $LIPODIR
  49. mkdir -p $SDK_OUTPUT_DIR
  50. build() { # <ARCH=arm64|x86_64> <TYPE=iphonesimulator|iphoneos|macosx|watchos|watchsimulator|appletvos|appletvsimulator>
  51. set -x
  52. pushd .
  53. cd $WOLFSSL_DIR
  54. ARCH=$1
  55. HOST="${ARCH}-apple-darwin"
  56. TYPE=$2
  57. SDK_ROOT=$(xcrun --sdk ${TYPE} --show-sdk-path)
  58. ./configure -prefix=${OUTDIR}/wolfssl-${TYPE}-${ARCH} ${CONF_OPTS} --host=${HOST} \
  59. CFLAGS="${CFLAGS_COMMON} -arch ${ARCH} -isysroot ${SDK_ROOT}"
  60. make -j src/libwolfssl.la
  61. make install
  62. popd
  63. set +x
  64. }
  65. XCFRAMEWORKS=
  66. for type in iphonesimulator macosx appletvsimulator watchsimulator ; do
  67. build arm64 ${type}
  68. build x86_64 ${type}
  69. # Create universal binaries from architecture-specific static libraries
  70. lipo \
  71. "$OUTDIR/wolfssl-${type}-x86_64/lib/libwolfssl.a" \
  72. "$OUTDIR/wolfssl-${type}-arm64/lib/libwolfssl.a" \
  73. -create -output $LIPODIR/libwolfssl-${type}.a
  74. echo "Checking libraries"
  75. xcrun -sdk ${type} lipo -info $LIPODIR/libwolfssl-${type}.a
  76. XCFRAMEWORKS+=" -library ${LIPODIR}/libwolfssl-${type}.a -headers ${OUTDIR}/wolfssl-${type}-arm64/include"
  77. done
  78. for type in iphoneos appletvos ; do
  79. build arm64 ${type}
  80. # Create universal binaries from architecture-specific static libraries
  81. lipo \
  82. "$OUTDIR/wolfssl-${type}-arm64/lib/libwolfssl.a" \
  83. -create -output $LIPODIR/libwolfssl-${type}.a
  84. echo "Checking libraries"
  85. xcrun -sdk ${type} lipo -info $LIPODIR/libwolfssl-${type}.a
  86. XCFRAMEWORKS+=" -library ${LIPODIR}/libwolfssl-${type}.a -headers ${OUTDIR}/wolfssl-${type}-arm64/include"
  87. done
  88. ############################################################################################################################################
  89. # ********** BUILD FRAMEWORK
  90. ############################################################################################################################################
  91. xcodebuild -create-xcframework ${XCFRAMEWORKS} -output ${SDK_OUTPUT_DIR}/libwolfssl.xcframework