aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/build-openssl4android.sh
blob: 2d5c0905e8a1a2181d9e63150ca95dfa846533ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/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 -ux

source $BASE_DIR/scripts/_shared.sh

cd external
# Setup architectures, library name and other vars + cleanup from previous runs
LIB_NAME="openssl-1.1.0f"
LIB_DEST_DIR=`pwd`/install_openssl/libs
#[ -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}"
  if [ ! -d ${LIB_NAME} ]; then
    #exit 1
     tar xfz "${LIB_NAME}.tar.gz"
     echo "correct openssl configuration file"
     if [ $OS = darwin ]; then
        sed -i '' 's/-mandroid//g' ${LIB_NAME}/Configurations/10-main.conf
     else
        sed -i 's/-mandroid//g' ${LIB_NAME}/Configurations/10-main.conf
     fi
     
     #exit 1
  fi
  pushd "${LIB_NAME}"

  configure $*

  #support openssl-1.0.x
  if [[ $LIB_NAME != openssl-1.1.* ]]; then
    if [[ $ARCH == "android-armeabi" ]]; then
        ARCH="android-armv7"
    elif [[ $ARCH == "android64" ]]; then 
        ARCH="linux-x86_64 shared no-ssl2 no-ssl3 no-hw "
    elif [[ "$ARCH" == "android64-aarch64" ]]; then
        ARCH="android shared no-ssl2 no-ssl3 no-hw "
    fi
  fi
echo "-->${LIB_DEST_DIR}/${ABI}"
#exit 1
  ./Configure $ARCH \
              --prefix=${LIB_DEST_DIR}/${ABI} \
              --with-zlib-include=$SYSROOT/usr/include \
              --with-zlib-lib=$SYSROOT/usr/lib \
               no-hw no-dso \
              zlib-dynamic \
              no-asm \
              no-shared \
              no-unit-test
  PATH=$TOOLCHAIN_PATH:$PATH

  make clean
  
  if make -j4; then
    # make install
    make install_sw
    make install_ssldirs

    OUTPUT_ROOT=${TOOLS_ROOT}/../output/$ABI
    [ -d ${OUTPUT_ROOT}/include ] || mkdir -p ${OUTPUT_ROOT}/include
    cp -r ${LIB_DEST_DIR}/${ABI}/include/openssl ${OUTPUT_ROOT}/include

    [ -d ${OUTPUT_ROOT}/lib ] || mkdir -p ${OUTPUT_ROOT}/lib
    cp ${LIB_DEST_DIR}/${ABI}/lib/libcrypto.a ${OUTPUT_ROOT}/lib
    cp ${LIB_DEST_DIR}/${ABI}/lib/libssl.a ${OUTPUT_ROOT}/lib
  fi;
  popd

}

for ((i=0; i < ${#ARCHS[@]}; i++))
do
  if [[ $# -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