Home | History | Annotate | Line # | Download | only in dist-build
      1 #! /bin/sh
      2 
      3 if [ -z "$NDK_PLATFORM" ]; then
      4   export NDK_PLATFORM="android-16"
      5 fi
      6 export NDK_PLATFORM_COMPAT="${NDK_PLATFORM_COMPAT:-${NDK_PLATFORM}}"
      7 export NDK_API_VERSION=$(echo "$NDK_PLATFORM" | sed 's/^android-//')
      8 export NDK_API_VERSION_COMPAT=$(echo "$NDK_PLATFORM_COMPAT" | sed 's/^android-//')
      9 
     10 if [ -z "$ANDROID_NDK_HOME" ]; then
     11   echo "You should probably set ANDROID_NDK_HOME to the directory containing"
     12   echo "the Android NDK"
     13   exit
     14 fi
     15 
     16 if [ ! -f ./configure ]; then
     17   echo "Can't find ./configure. Wrong directory or haven't run autogen.sh?" >&2
     18   exit 1
     19 fi
     20 
     21 if [ "x$TARGET_ARCH" = 'x' ] || [ "x$ARCH" = 'x' ] || [ "x$HOST_COMPILER" = 'x' ]; then
     22   echo "You shouldn't use android-build.sh directly, use android-[arch].sh instead" >&2
     23   exit 1
     24 fi
     25 
     26 export MAKE_TOOLCHAIN="${ANDROID_NDK_HOME}/build/tools/make_standalone_toolchain.py"
     27 
     28 export PREFIX="$(pwd)/libsodium-android-${TARGET_ARCH}"
     29 export TOOLCHAIN_DIR="$(pwd)/android-toolchain-${TARGET_ARCH}"
     30 export PATH="${PATH}:${TOOLCHAIN_DIR}/bin"
     31 
     32 export CC=${CC:-"${HOST_COMPILER}-clang"}
     33 
     34 rm -rf "${TOOLCHAIN_DIR}" "${PREFIX}"
     35 
     36 echo
     37 if [ "$NDK_PLATFORM" != "$NDK_PLATFORM_COMPAT" ]; then
     38   echo "Building for platform [${NDK_PLATFORM}], retaining compatibility with platform [${NDK_PLATFORM_COMPAT}]"
     39 else
     40   echo "Building for platform [${NDK_PLATFORM}]"
     41 fi
     42 echo
     43 
     44 env - PATH="$PATH" \
     45     "$MAKE_TOOLCHAIN" --force --api="$NDK_API_VERSION_COMPAT" \
     46     --arch="$ARCH" --install-dir="$TOOLCHAIN_DIR" || exit 1
     47 
     48 ./configure \
     49     --disable-soname-versions \
     50     --enable-minimal \
     51     --host="${HOST_COMPILER}" \
     52     --prefix="${PREFIX}" \
     53     --with-sysroot="${TOOLCHAIN_DIR}/sysroot" || exit 1
     54 
     55 if [ "$NDK_PLATFORM" != "$NDK_PLATFORM_COMPAT" ]; then
     56   egrep '^#define ' config.log | sort -u > config-def-compat.log
     57   echo
     58   echo "Configuring again for platform [${NDK_PLATFORM}]"
     59   echo
     60   env - PATH="$PATH" \
     61       "$MAKE_TOOLCHAIN" --force --api="$NDK_API_VERSION" \
     62       --arch="$ARCH" --install-dir="$TOOLCHAIN_DIR" || exit 1
     63 
     64   ./configure \
     65       --disable-soname-versions \
     66       --enable-minimal \
     67       --host="${HOST_COMPILER}" \
     68       --prefix="${PREFIX}" \
     69       --with-sysroot="${TOOLCHAIN_DIR}/sysroot" || exit 1
     70 
     71   egrep '^#define ' config.log | sort -u > config-def.log
     72   if ! cmp config-def.log config-def-compat.log; then
     73     echo "Platform [${NDK_PLATFORM}] is not backwards-compatible with [${NDK_PLATFORM_COMPAT}]" >&2
     74     diff -u config-def.log config-def-compat.log >&2
     75     exit 1
     76   fi
     77   rm -f config-def.log config-def-compat.log
     78 fi
     79 
     80 make clean && \
     81 make -j3 install && \
     82 echo "libsodium has been installed into ${PREFIX}"
     83