1#!/usr/bin/env bash
2
3echo "Downloading OpenSSL"
4if ! curl -L -k -s -o openssl-1.1.1d.tar.gz https://www.openssl.org/source/openssl-1.1.1d.tar.gz;
5then
6    echo "Failed to download OpenSSL"
7    exit 1
8fi
9
10echo "Unpacking OpenSSL"
11rm -rf ./openssl-1.1.1d
12if ! tar -xf openssl-1.1.1d.tar.gz;
13then
14    echo "Failed to unpack OpenSSL"
15    exit 1
16fi
17
18cd openssl-1.1.1d || exit 1
19
20if ! cp ../contrib/ios/15-ios.conf Configurations/; then
21    echo "Failed to copy OpenSSL ios config"
22    exit 1
23fi
24
25# OpenSSL 1.1.1d patch. OK to remove once OpenSSL version is bumped.
26# ocsp.c:947:23: error: 'fork' is unavailable: not available on tvOS and watchOS.
27# Also see https://github.com/openssl/openssl/issues/7607.
28if ! patch -u -p0 < ../contrib/ios/openssl.patch; then
29    echo "Failed to patch OpenSSL"
30    exit 1
31fi
32
33echo "Configuring OpenSSL"
34if ! ./Configure "$OPENSSL_HOST" -DNO_FORK no-comp no-asm no-hw no-engine no-tests no-unit-test \
35       --prefix="$IOS_PREFIX" --openssldir="$IOS_PREFIX"; then
36    echo "Failed to configure OpenSSL"
37    exit 1
38fi
39
40echo "Building OpenSSL"
41if ! make; then
42    echo "Failed to build OpenSSL"
43    exit 1
44fi
45
46echo "Installing OpenSSL"
47if ! make install_sw; then
48    echo "Failed to install OpenSSL"
49    exit 1
50fi
51
52exit 0
53