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