michael@0: dnl This Source Code Form is subject to the terms of the Mozilla Public michael@0: dnl License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: dnl file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: AC_DEFUN([MOZ_ANDROID_NDK], michael@0: [ michael@0: michael@0: MOZ_ARG_WITH_STRING(android-ndk, michael@0: [ --with-android-ndk=DIR michael@0: location where the Android NDK can be found], michael@0: android_ndk=$withval) michael@0: michael@0: MOZ_ARG_WITH_STRING(android-toolchain, michael@0: [ --with-android-toolchain=DIR michael@0: location of the android toolchain], michael@0: android_toolchain=$withval) michael@0: michael@0: MOZ_ARG_WITH_STRING(android-gnu-compiler-version, michael@0: [ --with-android-gnu-compiler-version=VER michael@0: gnu compiler version to use], michael@0: android_gnu_compiler_version=$withval) michael@0: michael@0: MOZ_ARG_ENABLE_BOOL(android-libstdcxx, michael@0: [ --enable-android-libstdcxx michael@0: use GNU libstdc++ instead of STLPort], michael@0: MOZ_ANDROID_LIBSTDCXX=1, michael@0: MOZ_ANDROID_LIBSTDCXX= ) michael@0: michael@0: define([MIN_ANDROID_VERSION], [9]) michael@0: android_version=MIN_ANDROID_VERSION michael@0: michael@0: MOZ_ARG_WITH_STRING(android-version, michael@0: [ --with-android-version=VER michael@0: android platform version, default] MIN_ANDROID_VERSION, michael@0: android_version=$withval) michael@0: michael@0: if test $android_version -lt MIN_ANDROID_VERSION ; then michael@0: AC_MSG_ERROR([--with-android-version must be at least MIN_ANDROID_VERSION.]) michael@0: fi michael@0: michael@0: case "$target" in michael@0: arm-linux*-android*|*-linuxandroid*) michael@0: android_tool_prefix="arm-linux-androideabi" michael@0: ;; michael@0: i?86-*android*) michael@0: android_tool_prefix="i686-linux-android" michael@0: ;; michael@0: mipsel-*android*) michael@0: android_tool_prefix="mipsel-linux-android" michael@0: ;; michael@0: *) michael@0: android_tool_prefix="$target_os" michael@0: ;; michael@0: esac michael@0: michael@0: case "$target" in michael@0: *-android*|*-linuxandroid*) michael@0: if test -z "$android_ndk" ; then michael@0: AC_MSG_ERROR([You must specify --with-android-ndk=/path/to/ndk when targeting Android.]) michael@0: fi michael@0: michael@0: if test -z "$android_toolchain" ; then michael@0: AC_MSG_CHECKING([for android toolchain directory]) michael@0: michael@0: kernel_name=`uname -s | tr "[[:upper:]]" "[[:lower:]]"` michael@0: michael@0: for version in $android_gnu_compiler_version 4.7 4.6 4.4.3 ; do michael@0: case "$target_cpu" in michael@0: arm) michael@0: target_name=arm-linux-androideabi-$version michael@0: ;; michael@0: i?86) michael@0: target_name=x86-$version michael@0: ;; michael@0: mipsel) michael@0: target_name=mipsel-linux-android-$version michael@0: ;; michael@0: *) michael@0: AC_MSG_ERROR([target cpu is not supported]) michael@0: ;; michael@0: esac michael@0: case "$host_cpu" in michael@0: i*86) michael@0: android_toolchain="$android_ndk"/toolchains/$target_name/prebuilt/$kernel_name-x86 michael@0: ;; michael@0: x86_64) michael@0: android_toolchain="$android_ndk"/toolchains/$target_name/prebuilt/$kernel_name-x86_64 michael@0: if ! test -d "$android_toolchain" ; then michael@0: android_toolchain="$android_ndk"/toolchains/$target_name/prebuilt/$kernel_name-x86 michael@0: fi michael@0: ;; michael@0: *) michael@0: AC_MSG_ERROR([No known toolchain for your host cpu]) michael@0: ;; michael@0: esac michael@0: if test -d "$android_toolchain" ; then michael@0: android_gnu_compiler_version=$version michael@0: break michael@0: elif test -n "$android_gnu_compiler_version" ; then michael@0: AC_MSG_ERROR([not found. Your --with-android-gnu-compiler-version may be wrong.]) michael@0: fi michael@0: done michael@0: michael@0: if test -z "$android_gnu_compiler_version" ; then michael@0: AC_MSG_ERROR([not found. You have to specify --with-android-toolchain=/path/to/ndk/toolchain.]) michael@0: else michael@0: AC_MSG_RESULT([$android_toolchain]) michael@0: fi michael@0: NSPR_CONFIGURE_ARGS="$NSPR_CONFIGURE_ARGS --with-android-toolchain=$android_toolchain" michael@0: fi michael@0: michael@0: NSPR_CONFIGURE_ARGS="$NSPR_CONFIGURE_ARGS --with-android-version=$android_version" michael@0: michael@0: AC_MSG_CHECKING([for android platform directory]) michael@0: michael@0: case "$target_cpu" in michael@0: arm) michael@0: target_name=arm michael@0: ;; michael@0: i?86) michael@0: target_name=x86 michael@0: ;; michael@0: mipsel) michael@0: target_name=mips michael@0: ;; michael@0: esac michael@0: michael@0: android_platform="$android_ndk"/platforms/android-"$android_version"/arch-"$target_name" michael@0: michael@0: if test -d "$android_platform" ; then michael@0: AC_MSG_RESULT([$android_platform]) michael@0: else michael@0: AC_MSG_ERROR([not found. Please check your NDK. With the current configuration, it should be in $android_platform]) michael@0: fi michael@0: michael@0: dnl Old NDK support. If minimum requirement is changed to NDK r8b, michael@0: dnl please remove this. michael@0: case "$target_cpu" in michael@0: i?86) michael@0: if ! test -e "$android_toolchain"/bin/"$android_tool_prefix"-gcc; then michael@0: dnl Old NDK toolchain name michael@0: android_tool_prefix="i686-android-linux" michael@0: fi michael@0: ;; michael@0: esac michael@0: michael@0: dnl set up compilers michael@0: TOOLCHAIN_PREFIX="$android_toolchain/bin/$android_tool_prefix-" michael@0: AS="$android_toolchain"/bin/"$android_tool_prefix"-as michael@0: if test -z "$CC"; then michael@0: CC="$android_toolchain"/bin/"$android_tool_prefix"-gcc michael@0: fi michael@0: if test -z "$CXX"; then michael@0: CXX="$android_toolchain"/bin/"$android_tool_prefix"-g++ michael@0: fi michael@0: if test -z "$CPP"; then michael@0: CPP="$android_toolchain"/bin/"$android_tool_prefix"-cpp michael@0: fi michael@0: LD="$android_toolchain"/bin/"$android_tool_prefix"-ld michael@0: AR="$android_toolchain"/bin/"$android_tool_prefix"-ar michael@0: RANLIB="$android_toolchain"/bin/"$android_tool_prefix"-ranlib michael@0: STRIP="$android_toolchain"/bin/"$android_tool_prefix"-strip michael@0: OBJCOPY="$android_toolchain"/bin/"$android_tool_prefix"-objcopy michael@0: michael@0: CPPFLAGS="-idirafter $android_platform/usr/include $CPPFLAGS" michael@0: CFLAGS="-mandroid -fno-short-enums -fno-exceptions $CFLAGS" michael@0: CXXFLAGS="-mandroid -fno-short-enums -fno-exceptions -Wno-psabi $CXXFLAGS" michael@0: ASFLAGS="-idirafter $android_platform/usr/include -DANDROID $ASFLAGS" michael@0: michael@0: dnl Add -llog by default, since we use it all over the place. michael@0: dnl Add --allow-shlib-undefined, because libGLESv2 links to an michael@0: dnl undefined symbol (present on the hardware, just not in the michael@0: dnl NDK.) michael@0: LDFLAGS="-mandroid -L$android_platform/usr/lib -Wl,-rpath-link=$android_platform/usr/lib --sysroot=$android_platform -llog -Wl,--allow-shlib-undefined $LDFLAGS" michael@0: dnl prevent cross compile section from using these flags as host flags michael@0: if test -z "$HOST_CPPFLAGS" ; then michael@0: HOST_CPPFLAGS=" " michael@0: fi michael@0: if test -z "$HOST_CFLAGS" ; then michael@0: HOST_CFLAGS=" " michael@0: fi michael@0: if test -z "$HOST_CXXFLAGS" ; then michael@0: HOST_CXXFLAGS=" " michael@0: fi michael@0: if test -z "$HOST_LDFLAGS" ; then michael@0: HOST_LDFLAGS=" " michael@0: fi michael@0: michael@0: ANDROID_NDK="${android_ndk}" michael@0: ANDROID_TOOLCHAIN="${android_toolchain}" michael@0: ANDROID_PLATFORM="${android_platform}" michael@0: michael@0: AC_DEFINE(ANDROID) michael@0: AC_SUBST(ANDROID_NDK) michael@0: AC_SUBST(ANDROID_TOOLCHAIN) michael@0: AC_SUBST(ANDROID_PLATFORM) michael@0: michael@0: ;; michael@0: esac michael@0: michael@0: ]) michael@0: michael@0: AC_DEFUN([MOZ_ANDROID_STLPORT], michael@0: [ michael@0: michael@0: if test "$OS_TARGET" = "Android" -a -z "$gonkdir"; then michael@0: case "${CPU_ARCH}-${MOZ_ARCH}" in michael@0: arm-armv7*) michael@0: ANDROID_CPU_ARCH=armeabi-v7a michael@0: ;; michael@0: arm-*) michael@0: ANDROID_CPU_ARCH=armeabi michael@0: ;; michael@0: x86-*) michael@0: ANDROID_CPU_ARCH=x86 michael@0: ;; michael@0: mips-*) # When target_cpu is mipsel, CPU_ARCH is mips michael@0: ANDROID_CPU_ARCH=mips michael@0: ;; michael@0: esac michael@0: michael@0: AC_SUBST(ANDROID_CPU_ARCH) michael@0: michael@0: if test -z "$STLPORT_CPPFLAGS$STLPORT_LDFLAGS$STLPORT_LIBS"; then michael@0: if test -n "$MOZ_ANDROID_LIBSTDCXX" ; then michael@0: if test -e "$android_ndk/sources/cxx-stl/gnu-libstdc++/$android_gnu_compiler_version/libs/$ANDROID_CPU_ARCH/libgnustl_static.a"; then michael@0: # android-ndk-r8b michael@0: STLPORT_LIBS="-L$android_ndk/sources/cxx-stl/gnu-libstdc++/$android_gnu_compiler_version/libs/$ANDROID_CPU_ARCH/ -lgnustl_static" michael@0: STLPORT_CPPFLAGS="-I$android_ndk/sources/cxx-stl/gnu-libstdc++/$android_gnu_compiler_version/include -I$android_ndk/sources/cxx-stl/gnu-libstdc++/$android_gnu_compiler_version/libs/$ANDROID_CPU_ARCH/include -I$android_ndk/sources/cxx-stl/gnu-libstdc++/$android_gnu_compiler_version/include/backward" michael@0: elif test -e "$android_ndk/sources/cxx-stl/gnu-libstdc++/libs/$ANDROID_CPU_ARCH/libgnustl_static.a"; then michael@0: # android-ndk-r7, android-ndk-r7b, android-ndk-r8 michael@0: STLPORT_LIBS="-L$android_ndk/sources/cxx-stl/gnu-libstdc++/libs/$ANDROID_CPU_ARCH/ -lgnustl_static" michael@0: STLPORT_CPPFLAGS="-I$android_ndk/sources/cxx-stl/gnu-libstdc++/include -I$android_ndk/sources/cxx-stl/gnu-libstdc++/libs/$ANDROID_CPU_ARCH/include" michael@0: elif test -e "$android_ndk/sources/cxx-stl/gnu-libstdc++/libs/$ANDROID_CPU_ARCH/libstdc++.a"; then michael@0: # android-ndk-r5c, android-ndk-r6, android-ndk-r6b michael@0: STLPORT_CPPFLAGS="-I$android_ndk/sources/cxx-stl/gnu-libstdc++/include -I$android_ndk/sources/cxx-stl/gnu-libstdc++/libs/$ANDROID_CPU_ARCH/include" michael@0: STLPORT_LIBS="-L$android_ndk/sources/cxx-stl/gnu-libstdc++/libs/$ANDROID_CPU_ARCH/ -lstdc++" michael@0: else michael@0: AC_MSG_ERROR([Couldn't find path to gnu-libstdc++ in the android ndk]) michael@0: fi michael@0: else michael@0: STLPORT_CPPFLAGS="-isystem $_topsrcdir/build/stlport/stlport -isystem $android_ndk/sources/cxx-stl/system/include" michael@0: STLPORT_LIBS="$_objdir/build/stlport/libstlport_static.a -static-libstdc++" michael@0: fi michael@0: fi michael@0: CXXFLAGS="$CXXFLAGS $STLPORT_CPPFLAGS" michael@0: fi michael@0: AC_SUBST([MOZ_ANDROID_LIBSTDCXX]) michael@0: AC_SUBST([STLPORT_LIBS]) michael@0: michael@0: ]) michael@0: michael@0: AC_DEFUN([MOZ_ANDROID_SDK], michael@0: [ michael@0: michael@0: MOZ_ARG_WITH_STRING(android-sdk, michael@0: [ --with-android-sdk=DIR michael@0: location where the Android SDK can be found (base directory, e.g. .../android/platforms/android-6)], michael@0: android_sdk=$withval) michael@0: michael@0: android_sdk_root=${withval%/platforms/android-*} michael@0: michael@0: case "$target" in michael@0: *-android*|*-linuxandroid*) michael@0: if test -z "$android_sdk" ; then michael@0: AC_MSG_ERROR([You must specify --with-android-sdk=/path/to/sdk when targeting Android.]) michael@0: else michael@0: if ! test -e "$android_sdk"/source.properties ; then michael@0: AC_MSG_ERROR([The path in --with-android-sdk isn't valid (source.properties hasn't been found).]) michael@0: fi michael@0: michael@0: # Get the api level from "$android_sdk"/source.properties. michael@0: ANDROID_TARGET_SDK=`$AWK -F = changequote(<<, >>)'<<$>>1 == "AndroidVersion.ApiLevel" {print <<$>>2}'changequote([, ]) "$android_sdk"/source.properties` michael@0: michael@0: if test -z "$ANDROID_TARGET_SDK" ; then michael@0: AC_MSG_ERROR([Unexpected error: no AndroidVersion.ApiLevel field has been found in source.properties.]) michael@0: fi michael@0: michael@0: AC_DEFINE_UNQUOTED(ANDROID_TARGET_SDK,$ANDROID_TARGET_SDK) michael@0: AC_SUBST(ANDROID_TARGET_SDK) michael@0: michael@0: if ! test "$ANDROID_TARGET_SDK" -eq "$ANDROID_TARGET_SDK" ; then michael@0: AC_MSG_ERROR([Unexpected error: the found android api value isn't a number! (found $ANDROID_TARGET_SDK)]) michael@0: fi michael@0: michael@0: if test $ANDROID_TARGET_SDK -lt $1 ; then michael@0: AC_MSG_ERROR([The given Android SDK provides API level $ANDROID_TARGET_SDK ($1 or higher required).]) michael@0: fi michael@0: fi michael@0: michael@0: android_tools="$android_sdk_root"/tools michael@0: android_platform_tools="$android_sdk_root"/platform-tools michael@0: if test ! -d "$android_platform_tools" ; then michael@0: android_platform_tools="$android_sdk"/tools # SDK Tools < r8 michael@0: fi michael@0: michael@0: dnl The build tools got moved around to different directories in SDK michael@0: dnl Tools r22. Try to locate them. This is awful, but, from michael@0: dnl http://stackoverflow.com/a/4495368, the following sorts versions michael@0: dnl of the form x.y.z.a.b from newest to oldest: michael@0: dnl sort -t. -k 1,1nr -k 2,2nr -k 3,3nr -k 4,4nr -k 5,5nr michael@0: dnl We want to favour the newer versions that start with 'android-'; michael@0: dnl that's what the sed is about. michael@0: dnl We might iterate over directories that aren't build-tools at all; michael@0: dnl we use the presence of aapt as a marker. michael@0: AC_MSG_CHECKING([for android build-tools directory]) michael@0: android_build_tools="" michael@0: for suffix in `ls "$android_sdk_root/build-tools" | sed -e "s,android-,999.," | sort -t. -k 1,1nr -k 2,2nr -k 3,3nr -k 4,4nr -k 5,5nr`; do michael@0: tools_directory=`echo "$android_sdk_root/build-tools/$suffix" | sed -e "s,999.,android-,"` michael@0: if test -d "$tools_directory" -a -f "$tools_directory/aapt"; then michael@0: android_build_tools="$tools_directory" michael@0: break michael@0: fi michael@0: done michael@0: if test -z "$android_build_tools" ; then michael@0: android_build_tools="$android_platform_tools" # SDK Tools < r22 michael@0: fi michael@0: michael@0: if test -d "$android_build_tools" -a -f "$android_build_tools/aapt"; then michael@0: AC_MSG_RESULT([$android_build_tools]) michael@0: else michael@0: AC_MSG_ERROR([not found. Please check your SDK for the subdirectory of build-tools. With the current configuration, it should be in $android_sdk_root/build_tools]) michael@0: fi michael@0: michael@0: ANDROID_SDK="${android_sdk}" michael@0: ANDROID_SDK_ROOT="${android_sdk_root}" michael@0: if test -e "${ANDROID_SDK_ROOT}/extras/android/compatibility/v4/android-support-v4.jar" ; then michael@0: ANDROID_COMPAT_LIB="${ANDROID_SDK_ROOT}/extras/android/compatibility/v4/android-support-v4.jar" michael@0: else michael@0: ANDROID_COMPAT_LIB="${ANDROID_SDK_ROOT}/extras/android/support/v4/android-support-v4.jar"; michael@0: fi michael@0: ANDROID_TOOLS="${android_tools}" michael@0: ANDROID_PLATFORM_TOOLS="${android_platform_tools}" michael@0: ANDROID_BUILD_TOOLS="${android_build_tools}" michael@0: AC_SUBST(ANDROID_SDK_ROOT) michael@0: AC_SUBST(ANDROID_SDK) michael@0: AC_SUBST(ANDROID_COMPAT_LIB) michael@0: if ! test -e $ANDROID_COMPAT_LIB ; then michael@0: AC_MSG_ERROR([You must download the Android support library when targeting Android. Run the Android SDK tool and install Android Support Library under Extras. See https://developer.android.com/tools/extras/support-library.html for more info. (looked for $ANDROID_COMPAT_LIB)]) michael@0: fi michael@0: michael@0: dnl Google has a history of moving the Android tools around. We don't michael@0: dnl care where they are, so let's try to find them anywhere we can. michael@0: ALL_ANDROID_TOOLS_PATHS="$ANDROID_TOOLS:$ANDROID_BUILD_TOOLS:$ANDROID_PLATFORM_TOOLS" michael@0: MOZ_PATH_PROG(ZIPALIGN, zipalign, :, [$ALL_ANDROID_TOOLS_PATHS]) michael@0: MOZ_PATH_PROG(DX, dx, :, [$ALL_ANDROID_TOOLS_PATHS]) michael@0: MOZ_PATH_PROG(AAPT, aapt, :, [$ALL_ANDROID_TOOLS_PATHS]) michael@0: MOZ_PATH_PROG(AIDL, aidl, :, [$ALL_ANDROID_TOOLS_PATHS]) michael@0: MOZ_PATH_PROG(ADB, adb, :, [$ALL_ANDROID_TOOLS_PATHS]) michael@0: michael@0: if test -z "$ZIPALIGN" -o "$ZIPALIGN" = ":"; then michael@0: AC_MSG_ERROR([The program zipalign was not found. Use --with-android-sdk={android-sdk-dir}.]) michael@0: fi michael@0: if test -z "$DX" -o "$DX" = ":"; then michael@0: AC_MSG_ERROR([The program dx was not found. Use --with-android-sdk={android-sdk-dir}.]) michael@0: fi michael@0: if test -z "$AAPT" -o "$AAPT" = ":"; then michael@0: AC_MSG_ERROR([The program aapt was not found. Use --with-android-sdk={android-sdk-dir}.]) michael@0: fi michael@0: if test -z "$AIDL" -o "$AIDL" = ":"; then michael@0: AC_MSG_ERROR([The program aidl was not found. Use --with-android-sdk={android-sdk-dir}.]) michael@0: fi michael@0: if test -z "$ADB" -o "$ADB" = ":"; then michael@0: AC_MSG_ERROR([The program adb was not found. Use --with-android-sdk={android-sdk-dir}.]) michael@0: fi michael@0: ;; michael@0: esac michael@0: michael@0: ])