Skip to content
Permalink
Browse files

Getting openssl to compile on android-x86

  • Loading branch information...
asajeffrey committed Jul 12, 2018
1 parent 2465587 commit ffd30d8eb9dee662fb0afbbeda62599d25e68943
Showing with 49 additions and 25 deletions.
  1. +49 −25 support/android/openssl.sh
@@ -31,38 +31,42 @@ _ANDROID_NDK="android-ndk-r9"
case $RUST_TARGET in
armv7*)
_ANDROID_TARGET="arm-linux-androideabi"
_ANDROID_ARCH=arch-arm
_ANDROID_ARCH="arch-arm"
_ANDROID_GCC="arm-linux-androideabi"
_OPENSSL_MACHINE="armv7"
_OPENSSL_ARCH="arm"
_OPENSSL_CONFIG="linux-generic32"
;;
arm*)
_ANDROID_TARGET=$RUST_TARGET
_ANDROID_ARCH=arch-arm
_ANDROID_ARCH="arch-arm"
_ANDROID_GCC="arm-linux-androideabi"
_OPENSSL_MACHINE="arm"
_OPENSSL_ARCH="arm"
_OPENSSL_CONFIG="linux-generic32"
;;
aarch64*)
_ANDROID_TARGET=$RUST_TARGET
_ANDROID_ARCH=arch-arm64
_ANDROID_ARCH="arch-arm64"
_ANDROID_GCC="aarch64-linux-android"
_OPENSSL_MACHINE="armv7"
_OPENSSL_ARCH="arm64"
_OPENSSL_CONFIG="linux-generic64 -DB_ENDIAN"
;;
x86* | i686*)
_ANDROID_TARGET=$RUST_TARGET
_ANDROID_ARCH=arch-x86
_ANDROID_ARCH="arch-x86"
_ANDROID_GCC="x86"
_OPENSSL_MACHINE="x86"
_OPENSSL_ARCH="arm"
_OPENSSL_CONFIG="android-x86"
_OPENSSL_ARCH="x86"
_OPENSSL_CONFIG="linux-generic32"
;;
*)
echo "Error: Invalid TARGET platform: $RUST_TARGET"
;;
esac

_ANDROID_EABI="$ANDROID_TOOLCHAIN_NAME"
_ANDROID_EABI="llvm"


# Set _ANDROID_API to the API you want to use. You should set it
@@ -87,22 +91,22 @@ echo $ANDROID_NDK_ROOT
# http://groups.google.com/group/android-ndk/browse_thread/thread/a998e139aca71d77
if [ -z "$ANDROID_NDK_ROOT" ] || [ ! -d "$ANDROID_NDK_ROOT" ]; then
echo "Error: ANDROID_NDK_ROOT is not a valid path. Please edit this script."
# echo "$ANDROID_NDK_ROOT"
# exit 1
echo "$ANDROID_NDK_ROOT"
exit 1
fi

# Error checking
if [ ! -d "$ANDROID_NDK_ROOT/toolchains" ]; then
echo "Error: ANDROID_NDK_ROOT/toolchains is not a valid path. Please edit this script."
# echo "$ANDROID_NDK_ROOT/toolchains"
# exit 1
echo "$ANDROID_NDK_ROOT/toolchains"
exit 1
fi

# Error checking
if [ ! -d "$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI" ]; then
echo "Error: ANDROID_EABI is not a valid path. Please edit this script."
# echo "$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI"
# exit 1
echo "$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI"
exit 1
fi

#####################################################################
@@ -114,38 +118,51 @@ fi
# https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.html

ANDROID_TOOLCHAIN=""
ANDROID_GCC_TOOLCHAIN=""
for host in "linux-x86_64" "linux-x86" "darwin-x86_64" "darwin-x86"
do
if [ -d "$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI/prebuilt/$host/bin" ]; then
ANDROID_TOOLCHAIN="$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI/prebuilt/$host/bin"
ANDROID_GCC_TOOLCHAIN="$ANDROID_NDK_ROOT/toolchains/$_ANDROID_GCC-4.9/prebuilt/$host/$_ANDROID_TARGET/bin"
break
fi
done

# Error checking
if [ -z "$ANDROID_TOOLCHAIN" ] || [ ! -d "$ANDROID_TOOLCHAIN" ]; then
echo "Error: ANDROID_TOOLCHAIN is not valid. Please edit this script."
# echo "$ANDROID_TOOLCHAIN"
# exit 1
echo "$ANDROID_TOOLCHAIN"
exit 1
fi

#ANDROID_TOOLS="$_ANDROID_TARGET-gcc $_ANDROID_TARGET-ranlib $_ANDROID_TARGET-ld"
ANDROID_TOOLS="clang"

for tool in $ANDROID_TOOLS
do
# Error checking
if [ ! -e "$ANDROID_TOOLCHAIN/$tool" ]; then
echo "Error: Failed to find $tool. Please edit this script."
# echo "$ANDROID_TOOLCHAIN/$tool"
# exit 1
echo "$ANDROID_TOOLCHAIN/$tool"
exit 1
fi
done

GCC_TOOLS="ar ranlib ld"

for tool in $GCC_TOOLS
do
# Error checking
if [ ! -e "$ANDROID_GCC_TOOLCHAIN/$tool" ]; then
echo "Error: Failed to find $tool. Please edit this script."
echo "$ANDROID_GCC_TOOLCHAIN/$tool"
exit 1
fi
done

# Only modify/export PATH if ANDROID_TOOLCHAIN good
if [ ! -z "$ANDROID_TOOLCHAIN" ]; then
export ANDROID_TOOLCHAIN="$ANDROID_TOOLCHAIN"
export PATH="$ANDROID_TOOLCHAIN":"$PATH"
export PATH="$ANDROID_TOOLCHAIN":"$ANDROID_GCC_TOOLCHAIN":"$PATH"
fi

#####################################################################
@@ -159,8 +176,8 @@ export NDK_SYSROOT="$ANDROID_SYSROOT"
# Error checking
if [ -z "$ANDROID_SYSROOT" ] || [ ! -d "$ANDROID_SYSROOT" ]; then
echo "Error: ANDROID_SYSROOT is not valid. Please edit this script."
# echo "$ANDROID_SYSROOT"
# exit 1
echo "$ANDROID_SYSROOT"
exit 1
fi

#####################################################################
@@ -188,14 +205,21 @@ export ANDROID_API="$_ANDROID_API"
export ANDROID_DEV="$ANDROID_NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH/usr"
export HOSTCC=gcc
export CC=clang
export RANLIB="$ANDROID_NDK_ROOT/toolchains/$_ANDROID_TARGET-4.9/prebuilt/$host/$_ANDROID_TARGET/bin/ranlib"
export AR="$ANDROID_NDK_ROOT/toolchains/$_ANDROID_TARGET-4.9/prebuilt/$host/$_ANDROID_TARGET/bin/ar"
export LD="$ANDROID_NDK_ROOT/toolchains/$_ANDROID_TARGET-4.9/prebuilt/$host/$_ANDROID_TARGET/bin"

# See https://github.com/cocochpie/android-openssl/blob/master/build-all-arch.sh
#+xCFLAGS="-DSHARED_EXTENSION=.so -fPIC -DOPENSSL_PIC -DDSO_DLFCN -DHAVE_DLFCN_H -B$ANDROID_DEV/lib -O3 -fomit-frame-pointer -Wall -D__ANDROID_API__=18 --target=armv7a-none-linux-androideabi --gcc-toolchain=$ANDROID_NDK_ROOT/toolchains/$_ANDROID_TARGET-4.9/prebuilt/$host --sysroot=$ANDROID_SYSROOT -I$ANDROID_DEV/include -I$ANDROID_DEV/include/$_ANDROID_TARGET -L$ANDROID_NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH/usr/lib -B$ANDROID_NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH/usr/lib"

xCFLAGS="-DSHARED_EXTENSION=.so -fPIC -DOPENSSL_PIC -DDSO_DLFCN -DHAVE_DLFCN_H -I$ANDROID_DEV/include -B$ANDROID_DEV/lib -O3 -fomit-frame-pointer -Wall --gcc-toolchain=$ANDROID_NDK_ROOT/toolchains/$_ANDROID_TARGET-4.9/prebuilt/$host -Wno-error=macro-redefined -B$LD -L$ANDROID_NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH/usr/lib -L$ANDROID_NDK_ROOT/toolchains/$_ANDROID_TARGET-4.9/prebuilt/$host/lib/gcc/$_ANDROID_TARGET/4.9.x/ -B$ANDROID_NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH/usr/lib --sysroot=$ANDROID_SYSROOT --target=armv7a-none-linux-androideabi -v"
xCFLAGS="-DSHARED_EXTENSION=.so -DOPENSSL_PIC -DDSO_DLFCN -DHAVE_DLFCN_H \
-fPIC -fomit-frame-pointer \
-Wall -Wno-error=macro-redefined \
-O3 \
-I$ANDROID_DEV/include \
-B$ANDROID_DEV/lib -B$LD -B$ANDROID_NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH/usr/lib \
-L$ANDROID_NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH/usr/lib -L$ANDROID_NDK_ROOT/toolchains/$_ANDROID_GCC-4.9/prebuilt/$host/lib/gcc/$_ANDROID_TARGET/4.9.x/ \
--gcc-toolchain=$ANDROID_GCC_TOOLCHAIN \
--sysroot=$ANDROID_SYSROOT \
--target=$RUST_TARGET \
-v"

VERBOSE=1
if [ ! -z "$VERBOSE" ] && [ "$VERBOSE" != "0" ]; then

0 comments on commit ffd30d8

Please sign in to comment.
You can’t perform that action at this time.