build/autoconf/android.m4

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/build/autoconf/android.m4	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,369 @@
     1.4 +dnl This Source Code Form is subject to the terms of the Mozilla Public
     1.5 +dnl License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 +dnl file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.7 +
     1.8 +AC_DEFUN([MOZ_ANDROID_NDK],
     1.9 +[
    1.10 +
    1.11 +MOZ_ARG_WITH_STRING(android-ndk,
    1.12 +[  --with-android-ndk=DIR
    1.13 +                          location where the Android NDK can be found],
    1.14 +    android_ndk=$withval)
    1.15 +
    1.16 +MOZ_ARG_WITH_STRING(android-toolchain,
    1.17 +[  --with-android-toolchain=DIR
    1.18 +                          location of the android toolchain],
    1.19 +    android_toolchain=$withval)
    1.20 +
    1.21 +MOZ_ARG_WITH_STRING(android-gnu-compiler-version,
    1.22 +[  --with-android-gnu-compiler-version=VER
    1.23 +                          gnu compiler version to use],
    1.24 +    android_gnu_compiler_version=$withval)
    1.25 +
    1.26 +MOZ_ARG_ENABLE_BOOL(android-libstdcxx,
    1.27 +[  --enable-android-libstdcxx
    1.28 +                          use GNU libstdc++ instead of STLPort],
    1.29 +    MOZ_ANDROID_LIBSTDCXX=1,
    1.30 +    MOZ_ANDROID_LIBSTDCXX= )
    1.31 +
    1.32 +define([MIN_ANDROID_VERSION], [9])
    1.33 +android_version=MIN_ANDROID_VERSION
    1.34 +
    1.35 +MOZ_ARG_WITH_STRING(android-version,
    1.36 +[  --with-android-version=VER
    1.37 +                          android platform version, default] MIN_ANDROID_VERSION,
    1.38 +    android_version=$withval)
    1.39 +
    1.40 +if test $android_version -lt MIN_ANDROID_VERSION ; then
    1.41 +    AC_MSG_ERROR([--with-android-version must be at least MIN_ANDROID_VERSION.])
    1.42 +fi
    1.43 +
    1.44 +case "$target" in
    1.45 +arm-linux*-android*|*-linuxandroid*)
    1.46 +    android_tool_prefix="arm-linux-androideabi"
    1.47 +    ;;
    1.48 +i?86-*android*)
    1.49 +    android_tool_prefix="i686-linux-android"
    1.50 +    ;;
    1.51 +mipsel-*android*)
    1.52 +    android_tool_prefix="mipsel-linux-android"
    1.53 +    ;;
    1.54 +*)
    1.55 +    android_tool_prefix="$target_os"
    1.56 +    ;;
    1.57 +esac
    1.58 +
    1.59 +case "$target" in
    1.60 +*-android*|*-linuxandroid*)
    1.61 +    if test -z "$android_ndk" ; then
    1.62 +        AC_MSG_ERROR([You must specify --with-android-ndk=/path/to/ndk when targeting Android.])
    1.63 +    fi
    1.64 +
    1.65 +    if test -z "$android_toolchain" ; then
    1.66 +        AC_MSG_CHECKING([for android toolchain directory])
    1.67 +
    1.68 +        kernel_name=`uname -s | tr "[[:upper:]]" "[[:lower:]]"`
    1.69 +
    1.70 +        for version in $android_gnu_compiler_version 4.7 4.6 4.4.3 ; do
    1.71 +            case "$target_cpu" in
    1.72 +            arm)
    1.73 +                target_name=arm-linux-androideabi-$version
    1.74 +                ;;
    1.75 +            i?86)
    1.76 +                target_name=x86-$version
    1.77 +                ;;
    1.78 +            mipsel)
    1.79 +                target_name=mipsel-linux-android-$version
    1.80 +                ;;
    1.81 +            *)
    1.82 +                AC_MSG_ERROR([target cpu is not supported])
    1.83 +                ;;
    1.84 +            esac
    1.85 +            case "$host_cpu" in
    1.86 +            i*86)
    1.87 +                android_toolchain="$android_ndk"/toolchains/$target_name/prebuilt/$kernel_name-x86
    1.88 +                ;;
    1.89 +            x86_64)
    1.90 +                android_toolchain="$android_ndk"/toolchains/$target_name/prebuilt/$kernel_name-x86_64
    1.91 +                if ! test -d "$android_toolchain" ; then
    1.92 +                    android_toolchain="$android_ndk"/toolchains/$target_name/prebuilt/$kernel_name-x86
    1.93 +                fi
    1.94 +                ;;
    1.95 +            *)
    1.96 +                AC_MSG_ERROR([No known toolchain for your host cpu])
    1.97 +                ;;
    1.98 +            esac
    1.99 +            if test -d "$android_toolchain" ; then
   1.100 +                android_gnu_compiler_version=$version
   1.101 +                break
   1.102 +            elif test -n "$android_gnu_compiler_version" ; then
   1.103 +                AC_MSG_ERROR([not found. Your --with-android-gnu-compiler-version may be wrong.])
   1.104 +            fi
   1.105 +        done
   1.106 +
   1.107 +        if test -z "$android_gnu_compiler_version" ; then
   1.108 +            AC_MSG_ERROR([not found. You have to specify --with-android-toolchain=/path/to/ndk/toolchain.])
   1.109 +        else
   1.110 +            AC_MSG_RESULT([$android_toolchain])
   1.111 +        fi
   1.112 +        NSPR_CONFIGURE_ARGS="$NSPR_CONFIGURE_ARGS --with-android-toolchain=$android_toolchain"
   1.113 +    fi
   1.114 +
   1.115 +    NSPR_CONFIGURE_ARGS="$NSPR_CONFIGURE_ARGS --with-android-version=$android_version"
   1.116 +
   1.117 +    AC_MSG_CHECKING([for android platform directory])
   1.118 +
   1.119 +    case "$target_cpu" in
   1.120 +    arm)
   1.121 +        target_name=arm
   1.122 +        ;;
   1.123 +    i?86)
   1.124 +        target_name=x86
   1.125 +        ;;
   1.126 +    mipsel)
   1.127 +        target_name=mips
   1.128 +        ;;
   1.129 +    esac
   1.130 +
   1.131 +    android_platform="$android_ndk"/platforms/android-"$android_version"/arch-"$target_name"
   1.132 +
   1.133 +    if test -d "$android_platform" ; then
   1.134 +        AC_MSG_RESULT([$android_platform])
   1.135 +    else
   1.136 +        AC_MSG_ERROR([not found. Please check your NDK. With the current configuration, it should be in $android_platform])
   1.137 +    fi
   1.138 +
   1.139 +    dnl Old NDK support. If minimum requirement is changed to NDK r8b,
   1.140 +    dnl please remove this.
   1.141 +    case "$target_cpu" in
   1.142 +    i?86)
   1.143 +        if ! test -e "$android_toolchain"/bin/"$android_tool_prefix"-gcc; then
   1.144 +            dnl Old NDK toolchain name
   1.145 +            android_tool_prefix="i686-android-linux"
   1.146 +        fi
   1.147 +        ;;
   1.148 +    esac
   1.149 +
   1.150 +    dnl set up compilers
   1.151 +    TOOLCHAIN_PREFIX="$android_toolchain/bin/$android_tool_prefix-"
   1.152 +    AS="$android_toolchain"/bin/"$android_tool_prefix"-as
   1.153 +    if test -z "$CC"; then
   1.154 +        CC="$android_toolchain"/bin/"$android_tool_prefix"-gcc
   1.155 +    fi
   1.156 +    if test -z "$CXX"; then
   1.157 +        CXX="$android_toolchain"/bin/"$android_tool_prefix"-g++
   1.158 +    fi
   1.159 +    if test -z "$CPP"; then
   1.160 +        CPP="$android_toolchain"/bin/"$android_tool_prefix"-cpp
   1.161 +    fi
   1.162 +    LD="$android_toolchain"/bin/"$android_tool_prefix"-ld
   1.163 +    AR="$android_toolchain"/bin/"$android_tool_prefix"-ar
   1.164 +    RANLIB="$android_toolchain"/bin/"$android_tool_prefix"-ranlib
   1.165 +    STRIP="$android_toolchain"/bin/"$android_tool_prefix"-strip
   1.166 +    OBJCOPY="$android_toolchain"/bin/"$android_tool_prefix"-objcopy
   1.167 +
   1.168 +    CPPFLAGS="-idirafter $android_platform/usr/include $CPPFLAGS"
   1.169 +    CFLAGS="-mandroid -fno-short-enums -fno-exceptions $CFLAGS"
   1.170 +    CXXFLAGS="-mandroid -fno-short-enums -fno-exceptions -Wno-psabi $CXXFLAGS"
   1.171 +    ASFLAGS="-idirafter $android_platform/usr/include -DANDROID $ASFLAGS"
   1.172 +
   1.173 +    dnl Add -llog by default, since we use it all over the place.
   1.174 +    dnl Add --allow-shlib-undefined, because libGLESv2 links to an
   1.175 +    dnl undefined symbol (present on the hardware, just not in the
   1.176 +    dnl NDK.)
   1.177 +    LDFLAGS="-mandroid -L$android_platform/usr/lib -Wl,-rpath-link=$android_platform/usr/lib --sysroot=$android_platform -llog -Wl,--allow-shlib-undefined $LDFLAGS"
   1.178 +    dnl prevent cross compile section from using these flags as host flags
   1.179 +    if test -z "$HOST_CPPFLAGS" ; then
   1.180 +        HOST_CPPFLAGS=" "
   1.181 +    fi
   1.182 +    if test -z "$HOST_CFLAGS" ; then
   1.183 +        HOST_CFLAGS=" "
   1.184 +    fi
   1.185 +    if test -z "$HOST_CXXFLAGS" ; then
   1.186 +        HOST_CXXFLAGS=" "
   1.187 +    fi
   1.188 +    if test -z "$HOST_LDFLAGS" ; then
   1.189 +        HOST_LDFLAGS=" "
   1.190 +    fi
   1.191 +
   1.192 +    ANDROID_NDK="${android_ndk}"
   1.193 +    ANDROID_TOOLCHAIN="${android_toolchain}"
   1.194 +    ANDROID_PLATFORM="${android_platform}"
   1.195 +
   1.196 +    AC_DEFINE(ANDROID)
   1.197 +    AC_SUBST(ANDROID_NDK)
   1.198 +    AC_SUBST(ANDROID_TOOLCHAIN)
   1.199 +    AC_SUBST(ANDROID_PLATFORM)
   1.200 +
   1.201 +    ;;
   1.202 +esac
   1.203 +
   1.204 +])
   1.205 +    
   1.206 +AC_DEFUN([MOZ_ANDROID_STLPORT],
   1.207 +[
   1.208 +
   1.209 +if test "$OS_TARGET" = "Android" -a -z "$gonkdir"; then
   1.210 +    case "${CPU_ARCH}-${MOZ_ARCH}" in
   1.211 +    arm-armv7*)
   1.212 +        ANDROID_CPU_ARCH=armeabi-v7a
   1.213 +        ;;
   1.214 +    arm-*)
   1.215 +        ANDROID_CPU_ARCH=armeabi
   1.216 +        ;;
   1.217 +    x86-*)
   1.218 +        ANDROID_CPU_ARCH=x86
   1.219 +        ;;
   1.220 +    mips-*) # When target_cpu is mipsel, CPU_ARCH is mips
   1.221 +        ANDROID_CPU_ARCH=mips
   1.222 +        ;;
   1.223 +    esac
   1.224 +
   1.225 +    AC_SUBST(ANDROID_CPU_ARCH)
   1.226 +
   1.227 +    if test -z "$STLPORT_CPPFLAGS$STLPORT_LDFLAGS$STLPORT_LIBS"; then
   1.228 +        if test -n "$MOZ_ANDROID_LIBSTDCXX" ; then
   1.229 +            if test -e "$android_ndk/sources/cxx-stl/gnu-libstdc++/$android_gnu_compiler_version/libs/$ANDROID_CPU_ARCH/libgnustl_static.a"; then
   1.230 +                # android-ndk-r8b
   1.231 +                STLPORT_LIBS="-L$android_ndk/sources/cxx-stl/gnu-libstdc++/$android_gnu_compiler_version/libs/$ANDROID_CPU_ARCH/ -lgnustl_static"
   1.232 +                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"
   1.233 +            elif test -e "$android_ndk/sources/cxx-stl/gnu-libstdc++/libs/$ANDROID_CPU_ARCH/libgnustl_static.a"; then
   1.234 +                # android-ndk-r7, android-ndk-r7b, android-ndk-r8
   1.235 +                STLPORT_LIBS="-L$android_ndk/sources/cxx-stl/gnu-libstdc++/libs/$ANDROID_CPU_ARCH/ -lgnustl_static"
   1.236 +                STLPORT_CPPFLAGS="-I$android_ndk/sources/cxx-stl/gnu-libstdc++/include -I$android_ndk/sources/cxx-stl/gnu-libstdc++/libs/$ANDROID_CPU_ARCH/include"
   1.237 +            elif test -e "$android_ndk/sources/cxx-stl/gnu-libstdc++/libs/$ANDROID_CPU_ARCH/libstdc++.a"; then
   1.238 +                # android-ndk-r5c, android-ndk-r6, android-ndk-r6b
   1.239 +                STLPORT_CPPFLAGS="-I$android_ndk/sources/cxx-stl/gnu-libstdc++/include -I$android_ndk/sources/cxx-stl/gnu-libstdc++/libs/$ANDROID_CPU_ARCH/include"
   1.240 +                STLPORT_LIBS="-L$android_ndk/sources/cxx-stl/gnu-libstdc++/libs/$ANDROID_CPU_ARCH/ -lstdc++"
   1.241 +            else
   1.242 +                AC_MSG_ERROR([Couldn't find path to gnu-libstdc++ in the android ndk])
   1.243 +            fi
   1.244 +        else
   1.245 +            STLPORT_CPPFLAGS="-isystem $_topsrcdir/build/stlport/stlport -isystem $android_ndk/sources/cxx-stl/system/include"
   1.246 +            STLPORT_LIBS="$_objdir/build/stlport/libstlport_static.a -static-libstdc++"
   1.247 +        fi
   1.248 +    fi
   1.249 +    CXXFLAGS="$CXXFLAGS $STLPORT_CPPFLAGS"
   1.250 +fi
   1.251 +AC_SUBST([MOZ_ANDROID_LIBSTDCXX])
   1.252 +AC_SUBST([STLPORT_LIBS])
   1.253 +
   1.254 +])
   1.255 +
   1.256 +AC_DEFUN([MOZ_ANDROID_SDK],
   1.257 +[
   1.258 +
   1.259 +MOZ_ARG_WITH_STRING(android-sdk,
   1.260 +[  --with-android-sdk=DIR
   1.261 +                          location where the Android SDK can be found (base directory, e.g. .../android/platforms/android-6)],
   1.262 +    android_sdk=$withval)
   1.263 +
   1.264 +android_sdk_root=${withval%/platforms/android-*}
   1.265 +
   1.266 +case "$target" in
   1.267 +*-android*|*-linuxandroid*)
   1.268 +    if test -z "$android_sdk" ; then
   1.269 +        AC_MSG_ERROR([You must specify --with-android-sdk=/path/to/sdk when targeting Android.])
   1.270 +    else
   1.271 +        if ! test -e "$android_sdk"/source.properties ; then
   1.272 +            AC_MSG_ERROR([The path in --with-android-sdk isn't valid (source.properties hasn't been found).])
   1.273 +        fi
   1.274 +
   1.275 +        # Get the api level from "$android_sdk"/source.properties.
   1.276 +        ANDROID_TARGET_SDK=`$AWK -F = changequote(<<, >>)'<<$>>1 == "AndroidVersion.ApiLevel" {print <<$>>2}'changequote([, ]) "$android_sdk"/source.properties`
   1.277 +
   1.278 +        if test -z "$ANDROID_TARGET_SDK" ; then
   1.279 +            AC_MSG_ERROR([Unexpected error: no AndroidVersion.ApiLevel field has been found in source.properties.])
   1.280 +        fi
   1.281 +
   1.282 +	AC_DEFINE_UNQUOTED(ANDROID_TARGET_SDK,$ANDROID_TARGET_SDK)
   1.283 +	AC_SUBST(ANDROID_TARGET_SDK)
   1.284 +
   1.285 +        if ! test "$ANDROID_TARGET_SDK" -eq "$ANDROID_TARGET_SDK" ; then
   1.286 +            AC_MSG_ERROR([Unexpected error: the found android api value isn't a number! (found $ANDROID_TARGET_SDK)])
   1.287 +        fi
   1.288 +
   1.289 +        if test $ANDROID_TARGET_SDK -lt $1 ; then
   1.290 +            AC_MSG_ERROR([The given Android SDK provides API level $ANDROID_TARGET_SDK ($1 or higher required).])
   1.291 +        fi
   1.292 +    fi
   1.293 +
   1.294 +    android_tools="$android_sdk_root"/tools
   1.295 +    android_platform_tools="$android_sdk_root"/platform-tools
   1.296 +    if test ! -d "$android_platform_tools" ; then
   1.297 +        android_platform_tools="$android_sdk"/tools # SDK Tools < r8
   1.298 +    fi
   1.299 +
   1.300 +    dnl The build tools got moved around to different directories in SDK
   1.301 +    dnl Tools r22. Try to locate them. This is awful, but, from
   1.302 +    dnl http://stackoverflow.com/a/4495368, the following sorts versions
   1.303 +    dnl of the form x.y.z.a.b from newest to oldest:
   1.304 +    dnl sort -t. -k 1,1nr -k 2,2nr -k 3,3nr -k 4,4nr -k 5,5nr
   1.305 +    dnl We want to favour the newer versions that start with 'android-';
   1.306 +    dnl that's what the sed is about.
   1.307 +    dnl We might iterate over directories that aren't build-tools at all;
   1.308 +    dnl we use the presence of aapt as a marker.
   1.309 +    AC_MSG_CHECKING([for android build-tools directory])
   1.310 +    android_build_tools=""
   1.311 +    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
   1.312 +        tools_directory=`echo "$android_sdk_root/build-tools/$suffix" | sed -e "s,999.,android-,"`
   1.313 +        if test -d "$tools_directory" -a -f "$tools_directory/aapt"; then
   1.314 +            android_build_tools="$tools_directory"
   1.315 +            break
   1.316 +        fi
   1.317 +    done
   1.318 +    if test -z "$android_build_tools" ; then
   1.319 +        android_build_tools="$android_platform_tools" # SDK Tools < r22
   1.320 +    fi
   1.321 +
   1.322 +    if test -d "$android_build_tools" -a -f "$android_build_tools/aapt"; then
   1.323 +        AC_MSG_RESULT([$android_build_tools])
   1.324 +    else
   1.325 +        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])
   1.326 +    fi
   1.327 +
   1.328 +    ANDROID_SDK="${android_sdk}"
   1.329 +    ANDROID_SDK_ROOT="${android_sdk_root}"
   1.330 +    if test -e "${ANDROID_SDK_ROOT}/extras/android/compatibility/v4/android-support-v4.jar" ; then
   1.331 +        ANDROID_COMPAT_LIB="${ANDROID_SDK_ROOT}/extras/android/compatibility/v4/android-support-v4.jar"
   1.332 +    else
   1.333 +        ANDROID_COMPAT_LIB="${ANDROID_SDK_ROOT}/extras/android/support/v4/android-support-v4.jar";
   1.334 +    fi
   1.335 +    ANDROID_TOOLS="${android_tools}"
   1.336 +    ANDROID_PLATFORM_TOOLS="${android_platform_tools}"
   1.337 +    ANDROID_BUILD_TOOLS="${android_build_tools}"
   1.338 +    AC_SUBST(ANDROID_SDK_ROOT)
   1.339 +    AC_SUBST(ANDROID_SDK)
   1.340 +    AC_SUBST(ANDROID_COMPAT_LIB)
   1.341 +    if ! test -e $ANDROID_COMPAT_LIB ; then
   1.342 +        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)])
   1.343 +    fi
   1.344 +
   1.345 +    dnl Google has a history of moving the Android tools around.  We don't
   1.346 +    dnl care where they are, so let's try to find them anywhere we can.
   1.347 +    ALL_ANDROID_TOOLS_PATHS="$ANDROID_TOOLS:$ANDROID_BUILD_TOOLS:$ANDROID_PLATFORM_TOOLS"
   1.348 +    MOZ_PATH_PROG(ZIPALIGN, zipalign, :, [$ALL_ANDROID_TOOLS_PATHS])
   1.349 +    MOZ_PATH_PROG(DX, dx, :, [$ALL_ANDROID_TOOLS_PATHS])
   1.350 +    MOZ_PATH_PROG(AAPT, aapt, :, [$ALL_ANDROID_TOOLS_PATHS])
   1.351 +    MOZ_PATH_PROG(AIDL, aidl, :, [$ALL_ANDROID_TOOLS_PATHS])
   1.352 +    MOZ_PATH_PROG(ADB, adb, :, [$ALL_ANDROID_TOOLS_PATHS])
   1.353 +
   1.354 +    if test -z "$ZIPALIGN" -o "$ZIPALIGN" = ":"; then
   1.355 +      AC_MSG_ERROR([The program zipalign was not found.  Use --with-android-sdk={android-sdk-dir}.])
   1.356 +    fi
   1.357 +    if test -z "$DX" -o "$DX" = ":"; then
   1.358 +      AC_MSG_ERROR([The program dx was not found.  Use --with-android-sdk={android-sdk-dir}.])
   1.359 +    fi
   1.360 +    if test -z "$AAPT" -o "$AAPT" = ":"; then
   1.361 +      AC_MSG_ERROR([The program aapt was not found.  Use --with-android-sdk={android-sdk-dir}.])
   1.362 +    fi
   1.363 +    if test -z "$AIDL" -o "$AIDL" = ":"; then
   1.364 +      AC_MSG_ERROR([The program aidl was not found.  Use --with-android-sdk={android-sdk-dir}.])
   1.365 +    fi
   1.366 +    if test -z "$ADB" -o "$ADB" = ":"; then
   1.367 +      AC_MSG_ERROR([The program adb was not found.  Use --with-android-sdk={android-sdk-dir}.])
   1.368 +    fi
   1.369 +    ;;
   1.370 +esac
   1.371 +
   1.372 +])

mercurial