-
Notifications
You must be signed in to change notification settings - Fork 744
/
build.sh
executable file
·65 lines (58 loc) · 1.67 KB
/
build.sh
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
#!/bin/bash
#
# Build OpenSSL's libcrypto for use in strongSwan's Android app. Requires
# passing the path to the Android NDK as well as that to the OpenSSL sources,
# for instance:
#
# ANDROID_NDK_ROOT=~/android-ndk OPENSSL_SRC=~/openssl ./build.sh
#
# The files are written to the jni/openssl directory of the app, by default, but
# that can be changed via $OUT variable.
#
# Setting $NO_DOCKER disables the use of Docker (requires the necessary build
# tools on the system), otherwise, setting $TAG allows using a custom tag for
# the Docker image.
#
set -e
if [ -z "${ANDROID_NDK_ROOT}" ]; then
echo "ANDROID_NDK_ROOT is not set"
exit 1
elif [ ! -d "${ANDROID_NDK_ROOT}" ]; then
echo "ANDROID_NDK_ROOT=${ANDROID_NDK_ROOT} is not a directory"
exit 1
fi
if [ -z "${OPENSSL_SRC}" ]; then
echo "OPENSSL_SRC is not set"
exit 1
elif [ ! -d "${OPENSSL_SRC}" ]; then
echo "OPENSSL_SRC=${OPENSSL_SRC} is not a directory"
exit 1
fi
: ${TAG=strongswan-android-openssl-builder}
DIR=$(dirname `readlink -f $0`)
: ${OUT=$DIR/../app/src/main/jni/openssl}
mkdir -p $OUT
if [ -z "${NO_DOCKER}" ]; then
docker build -t ${TAG} ${DIR}
docker run --rm -ti \
-u $(id -u ${USER}):$(id -g ${USER}) \
-v ${ANDROID_NDK_ROOT}:/ndk \
-v ${OPENSSL_SRC}:/src \
-v ${OUT}:/out \
${TAG}
else
pushd $OPENSSL_SRC
OUT_DIR=${OUT} $DIR/compile.sh
popd
fi
if [ ! -f "${OUT}/Android.mk" ]; then
echo "## Creating Android.mk for OpenSSL's libcrypto"
cat << EOF > ${OUT}/Android.mk
LOCAL_PATH := \$(call my-dir)
include \$(CLEAR_VARS)
LOCAL_MODULE := libcrypto_static
LOCAL_SRC_FILES := \$(TARGET_ARCH_ABI)/libcrypto.a
LOCAL_EXPORT_C_INCLUDES := \$(LOCAL_PATH)/include
include \$(PREBUILT_STATIC_LIBRARY)
EOF
fi