1、编译环境

Mac系统版本:10.15.2

Android NDK版本:android-ndk-r14b

OpenSSL地址:https://www.openssl.org/source/

OpenSSL github:https://github.com/openssl/openssl

编译脚本地址 github:https://github.com/leenjewel/openssl_for_ios_and_android

2、下载编译脚本

openssl_for_ios_and_android

|____ example

|____ tools

|____ _shared.sh
        |____ build-curl4android.sh
        |____ build-curl4ios.sh
        |____ build-openssl4android.sh
        |____ build-openssl4ios.sh
        |____ build-openssl_111_4android.sh

_shared.sh

#!/bin/bashTOOLS_ROOT=`pwd`#
# Warning !!! Android Build !!!
#
# Default to API 21 for it is the minimum requirement for 64 bit archs.
# IF you need to build for min api level 16, you need to modify it to 14 and will not build for 64 bit archs.
# api level 16 build is better because api level 21 and higher may have problem like
#
#     https://github.com/openssl/openssl/issues/988
#     http://stackoverflow.com/questions/37122126/whats-the-exact-significance-of-android-ndk-platform-version-compared-to-api-le
#
# So if you not need 64 bit arch api level 16 is better
#
# But but but cURL could not build by android-20 and earlier :-(
# So you can build openssl with android-16 then build cURL with android-21
#
if [ "${1}" == "cURL" ]; thenANDROID_API=${ANDROID_API:-21}
elseANDROID_API=${ANDROID_API:-16}
fi
echo ANDROID_API=${ANDROID_API}
# ARCHS=("android" "android-armeabi" "android-x86" "android-mips")
# ABIS=("armeabi" "armeabi-v7a" "x86" "mips")
ANDROID_API=${ANDROID_API:-21}
echo ANDROID_API=${ANDROID_API}
ANDROID_API=21
echo ANDROID_API=${ANDROID_API}
read -n1 -p "Press any key to continue..."# ARCHS=("android" "android-armeabi" "android64-aarch64" "android-x86" "android64" "android-mips" "android-mips64")
# ABIS=("armeabi" "armeabi-v7a" "arm64-v8a" "x86" "x86_64" "mips" "mips64")ARCHS=("android" "android-armeabi" "android64-aarch64" "android-x86" "android64")
ABIS=("armeabi" "armeabi-v7a" "arm64-v8a" "x86" "x86_64")ANDROID_NDK=/Users/yu.zuo/Library/Android/sdk/ndk-bundle
NDK=${ANDROID_NDK}configure_macro() {ARCH=$1; OUT=$2; CLANG=${3:-""};CLANG="TEST_CLANG"echo "CLANG" ${CLANG}TOOLCHAIN_ROOT=${TOOLS_ROOT}/${OUT}-android-toolchainif [ "$ARCH" == "android" ]; thenexport ARCH_FLAGS="-mthumb"export ARCH_LINK=""export TOOL="arm-linux-androideabi"NDK_FLAGS="--arch=arm"elif [ "$ARCH" == "android-armeabi" ]; thenexport ARCH_FLAGS="-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -mfpu=neon"export ARCH_LINK="-march=armv7-a -Wl,--fix-cortex-a8"export TOOL="arm-linux-androideabi"NDK_FLAGS="--arch=arm"elif [ "$ARCH" == "android64-aarch64" ]; thenexport ARCH_FLAGS=""export ARCH_LINK=""export TOOL="aarch64-linux-android"NDK_FLAGS="--arch=arm64"elif [ "$ARCH" == "android-x86" ]; thenexport ARCH_FLAGS="-march=i686 -mtune=intel -msse3 -mfpmath=sse -m32"export ARCH_LINK=""export TOOL="i686-linux-android"NDK_FLAGS="--arch=x86"elif [ "$ARCH" == "android64" ]; thenexport ARCH_FLAGS="-march=x86-64 -msse4.2 -mpopcnt -m64 -mtune=intel"export ARCH_LINK=""export TOOL="x86_64-linux-android"NDK_FLAGS="--arch=x86_64"elif [ "$ARCH" == "android-mips" ]; thenexport ARCH_FLAGS=""export ARCH_LINK=""export TOOL="mipsel-linux-android"NDK_FLAGS="--arch=mips"elif [ "$ARCH" == "android-mips64" ]; thenexport ARCH="linux64-mips64"export ARCH_FLAGS=""export ARCH_LINK=""export TOOL="mips64el-linux-android"NDK_FLAGS="--arch=mips64"elseecho "not support."fi;[ -d ${TOOLCHAIN_ROOT} ] || python $NDK/build/tools/make_standalone_toolchain.py \--api ${ANDROID_API} \--stl libc++ \--install-dir=${TOOLCHAIN_ROOT} \$NDK_FLAGS# [ -d ${TOOLCHAIN_ROOT} ] || sh $NDK/build/tools/make-standalone-toolchain.sh --install-dir=${TOOLCHAIN_ROOT} $NDK_FLAGSexport TOOLCHAIN_PATH=${TOOLCHAIN_ROOT}/binexport NDK_TOOLCHAIN_BASENAME=${TOOLCHAIN_PATH}/${TOOL}export SYSROOT=${TOOLCHAIN_ROOT}/sysrootexport CROSS_SYSROOT=$SYSROOTif [ -z "${CLANG}" ]; thenexport CC=${NDK_TOOLCHAIN_BASENAME}-gccexport CXX=${NDK_TOOLCHAIN_BASENAME}-g++elseexport CC=${NDK_TOOLCHAIN_BASENAME}-clangexport CXX=${NDK_TOOLCHAIN_BASENAME}-clang++fi;export LINK=${CXX}export LD=${NDK_TOOLCHAIN_BASENAME}-ldexport AR=${NDK_TOOLCHAIN_BASENAME}-arexport RANLIB=${NDK_TOOLCHAIN_BASENAME}-ranlibexport STRIP=${NDK_TOOLCHAIN_BASENAME}-stripexport CPPFLAGS=${CPPFLAGS:-""}export LIBS=${LIBS:-""}export CFLAGS="${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64"export CXXFLAGS="${CFLAGS} -std=c++11 -frtti -fexceptions"export LDFLAGS="${ARCH_LINK}"echo "**********************************************"echo "use ANDROID_API=${ANDROID_API}"echo "use NDK=${NDK}"echo "export ARCH=${ARCH}"echo "export NDK_TOOLCHAIN_BASENAME=${NDK_TOOLCHAIN_BASENAME}"echo "export SYSROOT=${SYSROOT}"echo "export CC=${CC}"echo "export CXX=${CXX}"echo "export LINK=${LINK}"echo "export LD=${LD}"echo "export AR=${AR}"echo "export RANLIB=${RANLIB}"echo "export STRIP=${STRIP}"echo "export CPPFLAGS=${CPPFLAGS}"echo "export CFLAGS=${CFLAGS}"echo "export CXXFLAGS=${CXXFLAGS}"echo "export LDFLAGS=${LDFLAGS}"echo "export LIBS=${LIBS}"echo "**********************************************"
}

build-curl4android.sh

#!/bin/bash
#
# Copyright 2016 leenjewel
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.set -usource ./_shared.sh cURL# Setup architectures, library name and other vars + cleanup from previous runs
TOOLS_ROOT=`pwd`
LIB_NAME="curl-7.66.0"
LIB_DEST_DIR=${TOOLS_ROOT}/libs
[ -f ${LIB_NAME}.tar.gz ] || wget https://curl.haxx.se/download/${LIB_NAME}.tar.gz
# Unarchive library, then configure and make for specified architectures
configure_make() {ARCH=$1; ABI=$2;[ -d "${LIB_NAME}" ] && rm -rf "${LIB_NAME}"tar xfz "${LIB_NAME}.tar.gz"pushd "${LIB_NAME}";configure_macro $*# fix meecho ARCH=${ARCH}echo ABI=${ABI}echo SYSROOT=${SYSROOT}cp ${TOOLS_ROOT}/../output/android/openssl-${ABI}/lib/libssl.a ${SYSROOT}/usr/libcp ${TOOLS_ROOT}/../output/android/openssl-${ABI}/lib/libcrypto.a ${SYSROOT}/usr/libcp -r ${TOOLS_ROOT}/../output/android/openssl-${ABI}/include/openssl ${SYSROOT}/usr/includemkdir -p ${LIB_DEST_DIR}/${ABI}./configure --prefix=${LIB_DEST_DIR}/${ABI} --with-sysroot=${SYSROOT} --host=${TOOL} \--enable-static \--disable-shared \--enable-threaded-resolver \--enable-ipv6 \--with-ssl=${SYSROOT}/usr PATH=$TOOLCHAIN_PATH:$PATHmake cleanif make -j4thenmake installOUTPUT_ROOT=${TOOLS_ROOT}/../output/android/curl-${ABI}[ -d ${OUTPUT_ROOT}/include ] || mkdir -p ${OUTPUT_ROOT}/includecp -r ${LIB_DEST_DIR}/${ABI}/include/curl ${OUTPUT_ROOT}/include[ -d ${OUTPUT_ROOT}/lib ] || mkdir -p ${OUTPUT_ROOT}/libcp ${LIB_DEST_DIR}/${ABI}/lib/libcurl.a ${OUTPUT_ROOT}/libfi;popd;
}for ((i=0; i < ${#ARCHS[@]}; i++))
doif [[ $# -eq 0 ]] || [[ "$1" == "${ARCHS[i]}" ]]; then[[ ${ANDROID_API} < 21 ]] && ( echo "${ABIS[i]}" | grep 64 > /dev/null ) && continue;configure_make "${ARCHS[i]}" "${ABIS[i]}"fi
done

build-curl4ios.sh

#!/bin/bash
#
# Copyright 2016 leenjewel
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.set -uSOURCE="$0"
echo SOURCE=${SOURCE}
read -n1 -p "Press any key to continue..."
while [ -h "$SOURCE" ]; doDIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"SOURCE="$(readlink "$SOURCE")"[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
pwd_path="$( cd -P "$( dirname "$SOURCE" )" && pwd )"# Setup architectures, library name and other vars + cleanup from previous runs
ARCHS=("arm64" "armv7s" "armv7" "i386" "x86_64")
SDKS=("iphoneos" "iphoneos" "iphoneos" "iphonesimulator" "iphonesimulator")
PLATFORMS=("iPhoneOS" "iPhoneOS" "iPhoneOS" "iPhoneSimulator" "iPhoneSimulator")
LIB_NAME="curl-7.66.0"
# LIB_NAME="curl-7_53_1"
DEVELOPER=`xcode-select -print-path`
# TOOLCHAIN=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
TOOLCHAIN=${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain
echo TOOLCHAIN=${TOOLCHAIN}
read -n1 -p "Press any key to continue..."# If you can't compile with this version, please modify the version to it which on your mac.
# SDK_VERSION=""10.3""
SDK_VERSION=""
IPHONEOS_DEPLOYMENT_TARGET="9.0"
LIB_DEST_DIR="${pwd_path}/../output/ios/curl-universal"
HEADER_DEST_DIR="include"
rm -rf "${HEADER_DEST_DIR}" "${LIB_DEST_DIR}" "${LIB_NAME}"# https://github.com/openssl/openssl/archive/OpenSSL_1_1_1d.tar.gz
# https://github.com/curl/curl/archive/curl-7_66_0.tar.gz #not
# https://github.com/curl/curl/releases/download/curl-7_66_0/curl-7.66.0.tar.gz[ -f "${LIB_NAME}.tar.gz" ] || curl https://curl.haxx.se/download/${LIB_NAME}.tar.gz > ${LIB_NAME}.tar.gz# Unarchive library, then configure and make for specified architectures
configure_make()
{ARCH=$1; SDK=$2; PLATFORM=$3;echo ARCH=$1echo SDK=$2echo PLATFORM=$3
#    read -n1 -p "Press any key to continue..."export PATH="${TOOLCHAIN}/usr/bin:${PATH}"export CROSS_TOP="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer"export CROSS_SDK="${PLATFORM}${SDK_VERSION}.sdk"export SYSROOT="${CROSS_TOP}/SDKs/${CROSS_SDK}"export CFLAGS="-arch ${ARCH} -pipe -Os -gdwarf-2 -isysroot ${SYSROOT} -miphoneos-version-min=${IPHONEOS_DEPLOYMENT_TARGET} -fembed-bitcode"export LDFLAGS="-arch ${ARCH} -isysroot ${SYSROOT}"if [ -d "${LIB_NAME}" ]; thenrm -fr "${LIB_NAME}"fitar xfz "${LIB_NAME}.tar.gz"pushd .; cd "${LIB_NAME}";# read -n1 -p "Press any key to continue..."PREFIX_DIR="${pwd_path}/../output/ios/curl-${ARCH}"if [ -d "${PREFIX_DIR}" ]; thenrm -fr "${PREFIX_DIR}"fimkdir -p "${PREFIX_DIR}"if [ "${ARCH}" == "arm64" ]; thenHOST="--host=arm-apple-darwin"elseHOST="--host=${ARCH}-apple-darwin"fi./configure --prefix=${PREFIX_DIR} \--with-sysroot=${CROSS_TOP}/SDKs/${CROSS_SDK} \${HOST} \--with-darwinssl \--enable-static \--disable-shared \--disable-verbose \--enable-threaded-resolver \--enable-ipv6make cleanif make -j8thenif [[ -d "curl-${ARCH}" ]]; thenrm -fr "curl-${ARCH}"fimkdir -p "curl-${ARCH}"make installpopd; rm -fr ${LIB_NAME}fi
}
for ((i=0; i < ${#ARCHS[@]}; i++))
doif [[ $# -eq 0 || "$1" == "${ARCHS[i]}" ]]; thenconfigure_make "${ARCHS[i]}" "${SDKS[i]}" "${PLATFORMS[i]}"fi
done# Combine libraries for different architectures into one
# Use .a files from the temp directory by providing relative paths
create_lib()
{LIB_SRC=$1; LIB_DST=$2;LIB_PATHS=( "${ARCHS[@]/#/${pwd_path}/../output/ios/curl-}" )LIB_PATHS=( "${LIB_PATHS[@]/%//${LIB_SRC}}" )lipo ${LIB_PATHS[@]} -create -output "${LIB_DST}"
}
mkdir "${LIB_DEST_DIR}";
create_lib "lib/libcurl.a" "${LIB_DEST_DIR}/libcurl.a"

build-openssl4android.sh

#!/bin/bash
#
# Copyright 2016 leenjewel
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.set -esource ./_shared.sh openssl# Setup architectures, library name and other vars + cleanup from previous runs
LIB_NAME="openssl-1.1.0f"
LIB_DEST_DIR=${TOOLS_ROOT}/libs
echo LIB_DEST_DIR="${LIB_DEST_DIR}"
read -n1 -p "Press any key to continue..."
[ -d ${LIB_DEST_DIR} ] && rm -rf ${LIB_DEST_DIR}
[ -f "${LIB_NAME}.tar.gz" ] || wget https://www.openssl.org/source/${LIB_NAME}.tar.gz;
# Unarchive library, then configure and make for specified architectures
configure_make() {ARCH=$1; ABI=$2;rm -rf "${LIB_NAME}"tar xfz "${LIB_NAME}.tar.gz"pushd "${LIB_NAME}"configure_macro $*#support openssl-1.0.xif [[ $LIB_NAME != openssl-1.1.* ]]; thenecho LIB_NAME="${LIB_NAME}"if [[ $ARCH == "android-armeabi" ]]; thenARCH="android-armv7"elif [[ $ARCH == "android64" ]]; then ARCH="linux-x86_64 shared no-ssl2 no-ssl3 no-hw "elif [[ "$ARCH" == "android64-aarch64" ]]; thenARCH="android shared no-ssl2 no-ssl3 no-hw "fifi# read -n1 -p "Press any key to continue..."./Configure $ARCH \--prefix=${LIB_DEST_DIR}/${ABI} \--with-zlib-include=$SYSROOT/usr/include \--with-zlib-lib=$SYSROOT/usr/lib \zlib \no-asm \no-shared \no-unit-testPATH=$TOOLCHAIN_PATH:$PATHsed -ie 's/-mandroid//g' "Makefile"OUTPUT_ROOT=${TOOLS_ROOT}/../output/android/openssl-${ABI}mkdir -p ${OUTPUT_ROOT}/logmake clean &> "${OUTPUT_ROOT}/log/${ABI}.log"if make -j4 >> "${OUTPUT_ROOT}/log/${ABI}.log" 2>&1; then# make installmake install_sw >> "${OUTPUT_ROOT}/log/${ABI}.log" 2>&1make install_ssldirs >> "${OUTPUT_ROOT}/log/${ABI}.log" 2>&1OUTPUT_ROOT=${TOOLS_ROOT}/../output/android/openssl-${ABI}[ -d ${OUTPUT_ROOT}/include ] || mkdir -p ${OUTPUT_ROOT}/includecp -r ${LIB_DEST_DIR}/${ABI}/include/openssl ${OUTPUT_ROOT}/include[ -d ${OUTPUT_ROOT}/lib ] || mkdir -p ${OUTPUT_ROOT}/libcp ${LIB_DEST_DIR}/${ABI}/lib/libcrypto.a ${OUTPUT_ROOT}/libcp ${LIB_DEST_DIR}/${ABI}/lib/libssl.a ${OUTPUT_ROOT}/libfi;popd}for ((i=0; i < ${#ARCHS[@]}; i++))
doecho ${ARCHS[i]}echo $1if [[ $# -eq 0 ]] || [[ "$1" == "${ARCHS[i]}" ]]; then# Do not build 64 bit arch if ANDROID_API is less than 21 which is# the minimum supported API level for 64 bit.[[ ${ANDROID_API} < 21 ]] && ( echo "${ABIS[i]}" | grep 64 > /dev/null ) && continue;configure_make "${ARCHS[i]}" "${ABIS[i]}"fi
done

build-openssl4ios.sh

#!/bin/bash
#
# Copyright 2016 leenjewel
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.set -uTOOLS_ROOT=`pwd`SOURCE="$0"
while [ -h "$SOURCE" ]; doDIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"SOURCE="$(readlink "$SOURCE")"[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
pwd_path="$( cd -P "$( dirname "$SOURCE" )" && pwd )"echo pwd_path=${pwd_path}
echo TOOLS_ROOT=${TOOLS_ROOT}
# read -n1 -p "Press any key to continue..."# Setting
IOS_MIN_TARGET="8.0"
LIB_NAME="openssl-1.1.0f"
LIB_DEST_DIR="${pwd_path}/../output/ios/openssl-universal"
HEADER_DEST_DIR="include"# Setup architectures, library name and other vars + cleanup from previous runs
# ARCHS=("arm64" "armv7s" "armv7" "i386" "x86_64")
# SDKS=("iphoneos" "iphoneos" "iphoneos" "iphonesimulator" "iphonesimulator")
# PLATFORMS=("iPhoneOS" "iPhoneOS" "iPhoneOS" "iPhoneSimulator" "iPhoneSimulator")ARCHS=("arm64" "armv7s" "armv7" "x86_64")
SDKS=("iphoneos" "iphoneos" "iphoneos" "iphonesimulator")
PLATFORMS=("iPhoneOS" "iPhoneOS" "iPhoneOS" "iPhoneSimulator")# ARCHS=("arm64")
# SDKS=("iphoneos")
# PLATFORMS=("iPhoneOS")DEVELOPER=`xcode-select -print-path`
SDK_VERSION=`xcrun -sdk iphoneos --show-sdk-version`
rm -rf "${HEADER_DEST_DIR}" "${LIB_DEST_DIR}" "${LIB_NAME}"
[ -f "${LIB_NAME}.tar.gz" ] || curl https://www.openssl.org/source/${LIB_NAME}.tar.gz > ${LIB_NAME}.tar.gz# Unarchive library, then configure and make for specified architectures
configure_make()
{ARCH=$1; SDK=$2; PLATFORM=$3;if [ -d "${LIB_NAME}" ]; thenrm -fr "${LIB_NAME}"fitar xfz "${LIB_NAME}.tar.gz"pushd .; cd "${LIB_NAME}";if [[ "${ARCH}" == "i386" || "${ARCH}" == "x86_64" ]]; thenecho ""elsesed -ie "s!static volatile sig_atomic_t intr_signal;!static volatile intr_signal;!" "crypto/ui/ui_openssl.c"fiexport CROSS_TOP="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer"export CROSS_SDK="${PLATFORM}${SDK_VERSION}.sdk"export TOOLS="${DEVELOPER}"export CC="${TOOLS}/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch ${ARCH}"PREFIX_DIR="${pwd_path}/../output/ios/openssl-${ARCH}"if [ -d "${PREFIX_DIR}" ]; thenrm -fr "${PREFIX_DIR}"fimkdir -p "${PREFIX_DIR}"if [[ "${ARCH}" == "x86_64" ]]; thenunset IPHONEOS_DEPLOYMENT_TARGET./Configure darwin64-x86_64-cc --prefix="${PREFIX_DIR}" "-isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK}"elif [[ "${ARCH}" == "i386" ]]; thenunset IPHONEOS_DEPLOYMENT_TARGET./Configure darwin-i386-cc --prefix="${PREFIX_DIR}" "-isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK}"else# instruction: # 1.no-shared and -fembed-bitcode is not compatibility# 2.advise use only .a static library on iOSexport IPHONEOS_DEPLOYMENT_TARGET=${IOS_MIN_TARGET}./Configure iphoneos-cross no-shared --prefix="${PREFIX_DIR}" "-fembed-bitcode"fi
#    read -n1 -p "Press any key to continue..."if [ ! -d ${CROSS_TOP}/SDKs/${CROSS_SDK} ]; thenecho "ERROR: iOS SDK version:'${SDK_VERSION}' incorrect, SDK in your system is:"xcodebuild -showsdks | grep iOSexit -1fiOUTPUT_ROOT=${TOOLS_ROOT}/../output/ios/openssl-${ARCH}mkdir -p ${OUTPUT_ROOT}/logmake clean &> "${OUTPUT_ROOT}/log/${ARCH}.log"if make -j8 >> "${OUTPUT_ROOT}/log/${ARCH}.log" 2>&1then# make install;make install_sw >> "${OUTPUT_ROOT}/log/${ARCH}.log" 2>&1make install_ssldirs >> "${OUTPUT_ROOT}/log/${ARCH}.log" 2>&1      fipopd
}
for ((i=0; i < ${#ARCHS[@]}; i++))
doif [[ $# -eq 0 || "$1" == "${ARCHS[i]}" ]]; thenconfigure_make "${ARCHS[i]}" "${SDKS[i]}" "${PLATFORMS[i]}"fi
done# Combine libraries for different architectures into one
# Use .a files from the temp directory by providing relative paths
create_lib()
{LIB_SRC=$1; LIB_DST=$2;LIB_PATHS=( "${ARCHS[@]/#/${pwd_path}/../output/ios/openssl-}" )LIB_PATHS=( "${LIB_PATHS[@]/%//lib/${LIB_SRC}}" )lipo ${LIB_PATHS[@]} -create -output "${LIB_DST}"
}
mkdir -p "${LIB_DEST_DIR}";
create_lib "libcrypto.a" "${LIB_DEST_DIR}/libcrypto.a"
create_lib "libssl.a" "${LIB_DEST_DIR}/libssl.a"

build-openssl_111_4android.sh

#!/bin/sh
#
# Copyright 2019 leenjewel
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.# Thanks https://stackoverflow.com/questions/52717228/how-to-compile-openssl-1-1-1-for-androidset -uOPENSSL_VERSION=1.1.1aAPI_LEVEL=16SOURCE="$0"
while [ -h "$SOURCE" ]; doDIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"SOURCE="$(readlink "$SOURCE")"[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
PWDPATH="$( cd -P "$( dirname "$SOURCE" )" && pwd )"unameOut="$(uname -s)"
case "${unameOut}" inLinux*)     MACHINE=Linux;;Darwin*)    MACHINE=Mac;;CYGWIN*)    MACHINE=Cygwin;;MINGW*)     MACHINE=MinGw;;*)          MACHINE="UNKNOWN:${unameOut}"
esacBUILD_DIR=$PWDPATH/../output/openssl_111_android_build
OUT_DIR=$PWDPATH/../output/openssl_111_androidBUILD_TARGETS="armeabi armeabi-v7a arm64-v8a x86 x86_64"if [ ! -d openssl-${OPENSSL_VERSION} ]
thenif [ ! -f openssl-${OPENSSL_VERSION}.tar.gz ]thenwget https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz || exit 128fitar xzf openssl-${OPENSSL_VERSION}.tar.gz || exit 128
ficd openssl-${OPENSSL_VERSION} || exit 128##### remove output-directory #####
rm -rf $OUT_DIR##### export ndk directory. Required by openssl-build-scripts #####
export ANDROID_NDK##### build-function #####
build_the_thing() {if [[ "$MACHINE" == "Mac" ]]; thenTOOLCHAIN=$ANDROID_NDK/toolchains/llvm/prebuilt/darwin-x86_64elif [[ "$MACHINE" == "Linux" ]]; thenTOOLCHAIN=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64fiexport PATH=$TOOLCHAIN/$TRIBLE/bin:$TOOLCHAIN/bin:"$PATH"
echo $PATHmake clean#./Configure $SSL_TARGET $OPTIONS -fuse-ld="$TOOLCHAIN/$TRIBLE/bin/ld" "-gcc-toolchain $TOOLCHAIN" && \./Configure $SSL_TARGET $OPTIONS -fuse-ld="$TOOLCHAIN/$TRIBLE/bin/ld" zlib \no-asm \no-shared \no-unit-test && \make && \make install DESTDIR=$DESTDIR || exit 128
}##### set variables according to build-tagret #####
for build_target in $BUILD_TARGETS
docase $build_target inarmeabi)TRIBLE="arm-linux-androideabi"TC_NAME="arm-linux-androideabi-4.9"#OPTIONS="--target=armv5te-linux-androideabi -mthumb -fPIC -latomic -D__ANDROID_API__=$API_LEVEL"OPTIONS="--target=armv5te-linux-androideabi -mthumb -fPIC -latomic -D__ANDROID_API__=$API_LEVEL"DESTDIR="$BUILD_DIR/armeabi"SSL_TARGET="android-arm";;armeabi-v7a)TRIBLE="arm-linux-androideabi"TC_NAME="arm-linux-androideabi-4.9"OPTIONS="--target=armv7a-linux-androideabi -Wl,--fix-cortex-a8 -fPIC -D__ANDROID_API__=$API_LEVEL"DESTDIR="$BUILD_DIR/armeabi-v7a"SSL_TARGET="android-arm";;x86)TRIBLE="i686-linux-android"TC_NAME="x86-4.9"OPTIONS="-fPIC -D__ANDROID_API__=${API_LEVEL}"DESTDIR="$BUILD_DIR/x86"SSL_TARGET="android-x86";;x86_64)TRIBLE="x86_64-linux-android"TC_NAME="x86_64-4.9"OPTIONS="-fPIC -D__ANDROID_API__=${API_LEVEL}"DESTDIR="$BUILD_DIR/x86_64"SSL_TARGET="android-x86_64";;arm64-v8a)TRIBLE="aarch64-linux-android"TC_NAME="aarch64-linux-android-4.9"OPTIONS="-fPIC -D__ANDROID_API__=${API_LEVEL}"DESTDIR="$BUILD_DIR/arm64-v8a"SSL_TARGET="android-arm64";;esacrm -rf $DESTDIRbuild_the_thing
#### copy libraries and includes to output-directory #####mkdir -p $OUT_DIR/inc/$build_targetcp -R $DESTDIR/usr/local/include/* $OUT_DIR/inc/$build_targetmkdir -p $OUT_DIR/lib/$build_targetcp -R $DESTDIR/usr/local/lib/*.so $OUT_DIR/lib/$build_targetcp -R $DESTDIR/usr/local/lib/*.a $OUT_DIR/lib/$build_target
doneecho Success

3、开始编译

进入到编译脚本目录

➜  openssl_for_ios_and_android-master ls
README.md example   output    tools
➜  openssl_for_ios_and_android-master cd tools
➜  tools ls
_shared.sh                    build-curl4ios.sh             build-openssl4ios.sh          openssl-1.1.1g
build-curl4android.sh         build-openssl4android.sh      build-openssl_111_4android.sh openssl-1.1.1g.tar.gz
➜  tools 

运行./build-openssl_111_4android.sh

编译成功后在根目录下的output文件夹内。

如果需要编译动态so库则需要修改编译脚本中no-shared改为shared即可。

Mac 编译OpenSSL 静态库、动态链接库相关推荐

  1. 【转】iOS编译OpenSSL静态库(使用脚本自动编译)

    原文网址:https://www.jianshu.com/p/651513cab181 本篇文章为大家推荐两个脚本,用来iOS系统下编译OpenSSL通用库,如果想了解编译具体过程,请参看<iO ...

  2. linux调用qt生成静态库文件下载,Centos7下编译openssl静态库与QT引用

    1.下载openssl版本:https://www.openssl.org/source/old/ 下载地址 2.我们下载版本为:openssl-1.0.2k 3.拷贝到Linux服务器任意目录 4. ...

  3. android编译openssl静态库.a 动态库.so

    环境: Ubuntu 32位 NDK R8D 编译静态库:./make_static.sh 编译动态库:./make_share.sh openssl-sdk-demo:包括ssl-client.c和 ...

  4. 用vs编译openssl静态库

    Perl Configure VC-WIN64A no-asm --openssldir="D:\openssl_lib" perl Configure VC-WIN32 no-a ...

  5. iOS架构-C/C++lame库在Mac下编译通用静态库.a库(13)

    C/C++ 有很多成熟的库,还有很多特殊功能的库,有时候iOS 平台开发一些比较前沿或者冷门的功能时,iOS并没有提供解决方案,这时候就可以研究C/C++的一些库,为我们使用.但是在Xcode编译C/ ...

  6. linux 编译mqtt静态库_编译MQTT C++ Client

    nmake  -f  ms\nt.mak(这是静态库,动态库是ntdll.mak) nmake  -f  ms\nt.mak test(测试命令,如果成功则最后显示"passed all t ...

  7. pytorch 矩阵相乘_编译PyTorch静态库

    背景 众所周知,PyTorch项目作为一个C++工程,是基于CMake进行构建的.然而当你想基于CMake来构建PyTorch静态库时,你会发现: 静态编译相关的文档不全: CMake文件bug太多, ...

  8. linux编译poco静态库,iOS——为Xcode编译POCO C++静态库

    一.POCO C++ library简介 POCO C++ library是一个C++编写的跨平台库,主要实现网络连接.数据库管理以及服务器,适用于跨平台.嵌入式. 二.为Xcode编译POCO C+ ...

  9. 解决引用openssl静态库libcrypto.a和libssl.a出现undefined reference to错误的问题

    解决引用openssl静态库libcrypto.a和libssl.a出现undefined reference to错误的问题 最近在做使用openssl链接http和https的项目,编译时出现以下 ...

最新文章

  1. linux下安装redmine1.2.1全记录
  2. sizeof 使用注意
  3. Python学习笔记——文件写入和读取
  4. 6.2 常见多媒体标准及压缩技术
  5. C语言文件读写操作之换行符处理
  6. js和python哪个好_Python与Node.JS:哪一个比较适合您的项目?
  7. iPhone 12系列起售价又要涨了?128GB起步...
  8. 代码统计工具有哪几种_DevOps:优秀代码分析工具的自我修养
  9. 微型计算机接口期末,微机接口技术期末复习题及其答案 (2)
  10. CSS——行内元素的margin与padding
  11. 【多媒体封装格式详解】---MKV【3】完
  12. 细述 wxWindows
  13. 局域网共享工具_Win10局域网共享开启工具
  14. 500G JAVA视频网盘分享 (JEECG开源社区)
  15. android systrace log,Android优化之Systrace
  16. 电子书阅读器背景颜色修改方法
  17. 学嵌入式有必要参加培训吗
  18. 商鼎云|亚马逊云盘关停了?你需要了解分布式存储云盘
  19. 图像增强(1-灰度级变换)—内涵MATLAB源码
  20. 【山大智云】SeafileServer源码分析之CDC(基于内容长度可变分块)

热门文章

  1. java hotspot 默认垃圾回收器_怎么查看服务器默认的垃圾的收集器是哪个?生产环境上如何配置垃圾回收收集器?谈谈你对垃圾收集器的理解?...
  2. 计算机网络笔记Part2 物理层(Physical Layer)
  3. 清华梦的粉碎——写给清华大学的退学申请by王垠
  4. 使用Matlab提取ADC数据占空比变化的波形
  5. python爬取虎扑评论_python爬取网站数据
  6. AT24C04 eeprom读写测试
  7. 笔记 | 百度飞浆AI达人创造营:深度学习模型训练和关键参数调优详解
  8. 【Linux工具】-vim介绍
  9. 无线服务器怎么开启,无线wifi路由器关了怎么开启
  10. 百度飞桨图像分类------第三天(实现蝴蝶图像分类)