Bumping manifests a=b2g-bump
[gecko.git] / build / autoconf / android.m4
blob8d57aa5b7555fb8e27044086cb758194dfd7969a
1 dnl This Source Code Form is subject to the terms of the Mozilla Public
2 dnl License, v. 2.0. If a copy of the MPL was not distributed with this
3 dnl file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 AC_DEFUN([MOZ_ANDROID_NDK],
8 MOZ_ARG_WITH_STRING(android-ndk,
9 [  --with-android-ndk=DIR
10                           location where the Android NDK can be found],
11     android_ndk=$withval)
13 MOZ_ARG_WITH_STRING(android-toolchain,
14 [  --with-android-toolchain=DIR
15                           location of the android toolchain],
16     android_toolchain=$withval)
18 MOZ_ARG_WITH_STRING(android-gnu-compiler-version,
19 [  --with-android-gnu-compiler-version=VER
20                           gnu compiler version to use],
21     android_gnu_compiler_version=$withval)
23 MOZ_ARG_ENABLE_BOOL(android-libstdcxx,
24 [  --enable-android-libstdcxx
25                           use GNU libstdc++ instead of STLPort],
26     MOZ_ANDROID_LIBSTDCXX=1,
27     MOZ_ANDROID_LIBSTDCXX= )
29 define([MIN_ANDROID_VERSION], [9])
30 android_version=MIN_ANDROID_VERSION
32 MOZ_ARG_WITH_STRING(android-version,
33 [  --with-android-version=VER
34                           android platform version, default] MIN_ANDROID_VERSION,
35     android_version=$withval)
37 if test $android_version -lt MIN_ANDROID_VERSION ; then
38     AC_MSG_ERROR([--with-android-version must be at least MIN_ANDROID_VERSION.])
41 case "$target" in
42 arm-linux*-android*|*-linuxandroid*)
43     android_tool_prefix="arm-linux-androideabi"
44     ;;
45 i?86-*android*)
46     android_tool_prefix="i686-linux-android"
47     ;;
48 mipsel-*android*)
49     android_tool_prefix="mipsel-linux-android"
50     ;;
52     android_tool_prefix="$target_os"
53     ;;
54 esac
56 case "$target" in
57 *-android*|*-linuxandroid*)
58     if test -z "$android_ndk" ; then
59         AC_MSG_ERROR([You must specify --with-android-ndk=/path/to/ndk when targeting Android.])
60     fi
62     if test -z "$android_toolchain" ; then
63         AC_MSG_CHECKING([for android toolchain directory])
65         kernel_name=`uname -s | tr "[[:upper:]]" "[[:lower:]]"`
67         for version in $android_gnu_compiler_version 4.8 4.7 4.6 4.4.3; do
68             case "$target_cpu" in
69             arm)
70                 target_name=arm-linux-androideabi-$version
71                 ;;
72             i?86)
73                 target_name=x86-$version
74                 ;;
75             mipsel)
76                 target_name=mipsel-linux-android-$version
77                 ;;
78             *)
79                 AC_MSG_ERROR([target cpu is not supported])
80                 ;;
81             esac
82             case "$host_cpu" in
83             i*86)
84                 android_toolchain="$android_ndk"/toolchains/$target_name/prebuilt/$kernel_name-x86
85                 ;;
86             x86_64)
87                 android_toolchain="$android_ndk"/toolchains/$target_name/prebuilt/$kernel_name-x86_64
88                 if ! test -d "$android_toolchain" ; then
89                     android_toolchain="$android_ndk"/toolchains/$target_name/prebuilt/$kernel_name-x86
90                 fi
91                 ;;
92             *)
93                 AC_MSG_ERROR([No known toolchain for your host cpu])
94                 ;;
95             esac
96             if test -d "$android_toolchain" ; then
97                 android_gnu_compiler_version=$version
98                 break
99             elif test -n "$android_gnu_compiler_version" ; then
100                 AC_MSG_ERROR([not found. Your --with-android-gnu-compiler-version may be wrong.])
101             fi
102         done
104         if test -z "$android_gnu_compiler_version" ; then
105             AC_MSG_ERROR([not found. You have to specify --with-android-toolchain=/path/to/ndk/toolchain.])
106         else
107             AC_MSG_RESULT([$android_toolchain])
108         fi
109         NSPR_CONFIGURE_ARGS="$NSPR_CONFIGURE_ARGS --with-android-toolchain=$android_toolchain"
110     fi
112     NSPR_CONFIGURE_ARGS="$NSPR_CONFIGURE_ARGS --with-android-version=$android_version"
114     AC_MSG_CHECKING([for android platform directory])
116     case "$target_cpu" in
117     arm)
118         target_name=arm
119         ;;
120     i?86)
121         target_name=x86
122         ;;
123     mipsel)
124         target_name=mips
125         ;;
126     esac
128     android_platform="$android_ndk"/platforms/android-"$android_version"/arch-"$target_name"
130     if test -d "$android_platform" ; then
131         AC_MSG_RESULT([$android_platform])
132     else
133         AC_MSG_ERROR([not found. Please check your NDK. With the current configuration, it should be in $android_platform])
134     fi
136     dnl Old NDK support. If minimum requirement is changed to NDK r8b,
137     dnl please remove this.
138     case "$target_cpu" in
139     i?86)
140         if ! test -e "$android_toolchain"/bin/"$android_tool_prefix"-gcc; then
141             dnl Old NDK toolchain name
142             android_tool_prefix="i686-android-linux"
143         fi
144         ;;
145     esac
147     dnl set up compilers
148     TOOLCHAIN_PREFIX="$android_toolchain/bin/$android_tool_prefix-"
149     AS="$android_toolchain"/bin/"$android_tool_prefix"-as
150     if test -z "$CC"; then
151         CC="$android_toolchain"/bin/"$android_tool_prefix"-gcc
152     fi
153     if test -z "$CXX"; then
154         CXX="$android_toolchain"/bin/"$android_tool_prefix"-g++
155     fi
156     if test -z "$CPP"; then
157         CPP="$android_toolchain"/bin/"$android_tool_prefix"-cpp
158     fi
159     LD="$android_toolchain"/bin/"$android_tool_prefix"-ld
160     AR="$android_toolchain"/bin/"$android_tool_prefix"-ar
161     RANLIB="$android_toolchain"/bin/"$android_tool_prefix"-ranlib
162     STRIP="$android_toolchain"/bin/"$android_tool_prefix"-strip
163     OBJCOPY="$android_toolchain"/bin/"$android_tool_prefix"-objcopy
165     CPPFLAGS="-idirafter $android_platform/usr/include $CPPFLAGS"
166     CFLAGS="-mandroid -fno-short-enums -fno-exceptions $CFLAGS"
167     CXXFLAGS="-mandroid -fno-short-enums -fno-exceptions -Wno-psabi $CXXFLAGS"
168     ASFLAGS="-idirafter $android_platform/usr/include -DANDROID $ASFLAGS"
170     dnl Add -llog by default, since we use it all over the place.
171     dnl Add --allow-shlib-undefined, because libGLESv2 links to an
172     dnl undefined symbol (present on the hardware, just not in the
173     dnl NDK.)
174     LDFLAGS="-mandroid -L$android_platform/usr/lib -Wl,-rpath-link=$android_platform/usr/lib --sysroot=$android_platform -llog -Wl,--allow-shlib-undefined $LDFLAGS"
175     dnl prevent cross compile section from using these flags as host flags
176     if test -z "$HOST_CPPFLAGS" ; then
177         HOST_CPPFLAGS=" "
178     fi
179     if test -z "$HOST_CFLAGS" ; then
180         HOST_CFLAGS=" "
181     fi
182     if test -z "$HOST_CXXFLAGS" ; then
183         HOST_CXXFLAGS=" "
184     fi
185     if test -z "$HOST_LDFLAGS" ; then
186         HOST_LDFLAGS=" "
187     fi
189     ANDROID_NDK="${android_ndk}"
190     ANDROID_TOOLCHAIN="${android_toolchain}"
191     ANDROID_PLATFORM="${android_platform}"
193     AC_DEFINE(ANDROID)
194     AC_SUBST(ANDROID_NDK)
195     AC_SUBST(ANDROID_TOOLCHAIN)
196     AC_SUBST(ANDROID_PLATFORM)
198     ;;
199 esac
202     
203 AC_DEFUN([MOZ_ANDROID_STLPORT],
206 if test "$OS_TARGET" = "Android" -a -z "$gonkdir"; then
207     case "${CPU_ARCH}-${MOZ_ARCH}" in
208     arm-armv7*)
209         ANDROID_CPU_ARCH=armeabi-v7a
210         ;;
211     arm-*)
212         ANDROID_CPU_ARCH=armeabi
213         ;;
214     x86-*)
215         ANDROID_CPU_ARCH=x86
216         ;;
217     mips-*) # When target_cpu is mipsel, CPU_ARCH is mips
218         ANDROID_CPU_ARCH=mips
219         ;;
220     esac
222     AC_SUBST(ANDROID_CPU_ARCH)
224     if test -z "$STLPORT_CPPFLAGS$STLPORT_LIBS"; then
225         if test -n "$MOZ_ANDROID_LIBSTDCXX" ; then
226             if test -e "$android_ndk/sources/cxx-stl/gnu-libstdc++/$android_gnu_compiler_version/libs/$ANDROID_CPU_ARCH/libgnustl_static.a"; then
227                 # android-ndk-r8b
228                 STLPORT_LIBS="-L$android_ndk/sources/cxx-stl/gnu-libstdc++/$android_gnu_compiler_version/libs/$ANDROID_CPU_ARCH/ -lgnustl_static"
229                 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"
230             elif test -e "$android_ndk/sources/cxx-stl/gnu-libstdc++/libs/$ANDROID_CPU_ARCH/libgnustl_static.a"; then
231                 # android-ndk-r7, android-ndk-r7b, android-ndk-r8
232                 STLPORT_LIBS="-L$android_ndk/sources/cxx-stl/gnu-libstdc++/libs/$ANDROID_CPU_ARCH/ -lgnustl_static"
233                 STLPORT_CPPFLAGS="-I$android_ndk/sources/cxx-stl/gnu-libstdc++/include -I$android_ndk/sources/cxx-stl/gnu-libstdc++/libs/$ANDROID_CPU_ARCH/include"
234             elif test -e "$android_ndk/sources/cxx-stl/gnu-libstdc++/libs/$ANDROID_CPU_ARCH/libstdc++.a"; then
235                 # android-ndk-r5c, android-ndk-r6, android-ndk-r6b
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"
237                 STLPORT_LIBS="-L$android_ndk/sources/cxx-stl/gnu-libstdc++/libs/$ANDROID_CPU_ARCH/ -lstdc++"
238             else
239                 AC_MSG_ERROR([Couldn't find path to gnu-libstdc++ in the android ndk])
240             fi
241         else
242             STLPORT_CPPFLAGS="-isystem $_topsrcdir/build/stlport/stlport -isystem $android_ndk/sources/cxx-stl/system/include"
243             STLPORT_LIBS="$_objdir/build/stlport/libstlport_static.a -static-libstdc++"
244         fi
245     fi
246     CXXFLAGS="$CXXFLAGS $STLPORT_CPPFLAGS"
248 AC_SUBST([MOZ_ANDROID_LIBSTDCXX])
249 AC_SUBST([STLPORT_LIBS])
253 AC_DEFUN([MOZ_ANDROID_SDK],
256 MOZ_ARG_WITH_STRING(android-sdk,
257 [  --with-android-sdk=DIR
258                           location where the Android SDK can be found (base directory, e.g. .../android/platforms/android-6)],
259     android_sdk=$withval)
261 android_sdk_root=${withval%/platforms/android-*}
263 case "$target" in
264 *-android*|*-linuxandroid*)
265     if test -z "$android_sdk" ; then
266         AC_MSG_ERROR([You must specify --with-android-sdk=/path/to/sdk when targeting Android.])
267     else
268         if ! test -e "$android_sdk"/source.properties ; then
269             AC_MSG_ERROR([The path in --with-android-sdk isn't valid (source.properties hasn't been found).])
270         fi
272         # Get the api level from "$android_sdk"/source.properties.
273         ANDROID_TARGET_SDK=`$AWK -F = changequote(<<, >>)'<<$>>1 == "AndroidVersion.ApiLevel" {print <<$>>2}'changequote([, ]) "$android_sdk"/source.properties`
275         if test -z "$ANDROID_TARGET_SDK" ; then
276             AC_MSG_ERROR([Unexpected error: no AndroidVersion.ApiLevel field has been found in source.properties.])
277         fi
279         AC_DEFINE_UNQUOTED(ANDROID_TARGET_SDK,$ANDROID_TARGET_SDK)
280         AC_SUBST(ANDROID_TARGET_SDK)
282         if ! test "$ANDROID_TARGET_SDK" -eq "$ANDROID_TARGET_SDK" ; then
283             AC_MSG_ERROR([Unexpected error: the found android api value isn't a number! (found $ANDROID_TARGET_SDK)])
284         fi
286         if test $ANDROID_TARGET_SDK -lt $1 ; then
287             AC_MSG_ERROR([The given Android SDK provides API level $ANDROID_TARGET_SDK ($1 or higher required).])
288         fi
289     fi
291     android_tools="$android_sdk_root"/tools
292     android_platform_tools="$android_sdk_root"/platform-tools
293     if test ! -d "$android_platform_tools" ; then
294         android_platform_tools="$android_sdk"/tools # SDK Tools < r8
295     fi
297     dnl The build tools got moved around to different directories in SDK
298     dnl Tools r22. Try to locate them. This is awful, but, from
299     dnl http://stackoverflow.com/a/4495368, the following sorts versions
300     dnl of the form x.y.z.a.b from newest to oldest:
301     dnl sort -t. -k 1,1nr -k 2,2nr -k 3,3nr -k 4,4nr -k 5,5nr
302     dnl We want to favour the newer versions that start with 'android-';
303     dnl that's what the sed is about.
304     dnl We might iterate over directories that aren't build-tools at all;
305     dnl we use the presence of aapt as a marker.
306     AC_MSG_CHECKING([for android build-tools directory])
307     android_build_tools=""
308     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
309         tools_directory=`echo "$android_sdk_root/build-tools/$suffix" | sed -e "s,999.,android-,"`
310         if test -d "$tools_directory" -a -f "$tools_directory/aapt"; then
311             android_build_tools="$tools_directory"
312             break
313         fi
314     done
315     if test -z "$android_build_tools" ; then
316         android_build_tools="$android_platform_tools" # SDK Tools < r22
317     fi
319     if test -d "$android_build_tools" -a -f "$android_build_tools/aapt"; then
320         AC_MSG_RESULT([$android_build_tools])
321     else
322         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])
323     fi
325     ANDROID_SDK="${android_sdk}"
326     ANDROID_SDK_ROOT="${android_sdk_root}"
328     AC_MSG_CHECKING([for compat library dirs])
329     if test -e "${android_sdk_root}/extras/android/compatibility/v4/android-support-v4.jar" ; then
330         ANDROID_COMPAT_DIR_BASE="${android_sdk_root}/extras/android/compatibility";
331     else
332         ANDROID_COMPAT_DIR_BASE="${android_sdk_root}/extras/android/support";
333     fi
334     AC_MSG_RESULT([$ANDROID_COMPAT_DIR_BASE])
336     ANDROID_TOOLS="${android_tools}"
337     ANDROID_PLATFORM_TOOLS="${android_platform_tools}"
338     ANDROID_BUILD_TOOLS="${android_build_tools}"
339     AC_SUBST(ANDROID_SDK_ROOT)
340     AC_SUBST(ANDROID_SDK)
341     AC_SUBST(ANDROID_TOOLS)
342     AC_SUBST(ANDROID_PLATFORM_TOOLS)
343     AC_SUBST(ANDROID_BUILD_TOOLS)
345     ANDROID_COMPAT_LIB=$ANDROID_COMPAT_DIR_BASE/v4/android-support-v4.jar
346     AC_MSG_CHECKING([for v4 compat library])
347     AC_SUBST(ANDROID_COMPAT_LIB)
348     if ! test -e $ANDROID_COMPAT_LIB ; then
349         AC_MSG_ERROR([You must download the Android v4 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)])
350     fi
351     AC_MSG_RESULT([$ANDROID_COMPAT_LIB])
353     if test -n "$MOZ_NATIVE_DEVICES" ; then
354         AC_SUBST(MOZ_NATIVE_DEVICES)
356         AC_MSG_CHECKING([for google play services])
357         GOOGLE_PLAY_SERVICES_LIB="${ANDROID_SDK_ROOT}/extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar"
358         GOOGLE_PLAY_SERVICES_RES="${ANDROID_SDK_ROOT}/extras/google/google_play_services/libproject/google-play-services_lib/res"
359         AC_SUBST(GOOGLE_PLAY_SERVICES_LIB)
360         AC_SUBST(GOOGLE_PLAY_SERVICES_RES)
361         if ! test -e $GOOGLE_PLAY_SERVICES_LIB ; then
362             AC_MSG_ERROR([You must download Google Play Services to build with native video casting support enabled.  Run the Android SDK tool and install Google Play Services under Extras.  See http://developer.android.com/google/play-services/setup.html for more info. (looked for $GOOGLE_PLAY_SERVICES_LIB) ])
363         fi
364         AC_MSG_RESULT([$GOOGLE_PLAY_SERVICES_LIB])
366         ANDROID_APPCOMPAT_LIB="$ANDROID_COMPAT_DIR_BASE/v7/appcompat/libs/android-support-v7-appcompat.jar"
367         ANDROID_APPCOMPAT_RES="$ANDROID_COMPAT_DIR_BASE/v7/appcompat/res"
368         AC_MSG_CHECKING([for v7 appcompat library])
369         if ! test -e $ANDROID_APPCOMPAT_LIB ; then
370             AC_MSG_ERROR([You must download the v7 app compat Android support library when targeting Android with native video casting support enabled.  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_APPCOMPAT_LIB)])
371         fi
372         AC_MSG_RESULT([$ANDROID_APPCOMPAT_LIB])
373         AC_SUBST(ANDROID_APPCOMPAT_LIB)
374         AC_SUBST(ANDROID_APPCOMPAT_RES)
376         ANDROID_MEDIAROUTER_LIB="$ANDROID_COMPAT_DIR_BASE/v7/mediarouter/libs/android-support-v7-mediarouter.jar"
377         ANDROID_MEDIAROUTER_RES="$ANDROID_COMPAT_DIR_BASE/v7/mediarouter/res"
378         AC_MSG_CHECKING([for v7 mediarouter library])
379         if ! test -e $ANDROID_MEDIAROUTER_LIB ; then
380             AC_MSG_ERROR([You must download the v7 media router Android support library when targeting Android with native video casting support enabled.  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_MEDIAROUTER_LIB)])
381         fi
382         AC_MSG_RESULT([$ANDROID_MEDIAROUTER_LIB])
383         AC_SUBST(ANDROID_MEDIAROUTER_LIB)
384         AC_SUBST(ANDROID_MEDIAROUTER_RES)
385     fi
387     dnl Google has a history of moving the Android tools around.  We don't
388     dnl care where they are, so let's try to find them anywhere we can.
389     ALL_ANDROID_TOOLS_PATHS="$ANDROID_TOOLS:$ANDROID_BUILD_TOOLS:$ANDROID_PLATFORM_TOOLS"
390     MOZ_PATH_PROG(ZIPALIGN, zipalign, :, [$ALL_ANDROID_TOOLS_PATHS])
391     MOZ_PATH_PROG(DX, dx, :, [$ALL_ANDROID_TOOLS_PATHS])
392     MOZ_PATH_PROG(AAPT, aapt, :, [$ALL_ANDROID_TOOLS_PATHS])
393     MOZ_PATH_PROG(AIDL, aidl, :, [$ALL_ANDROID_TOOLS_PATHS])
394     MOZ_PATH_PROG(ADB, adb, :, [$ALL_ANDROID_TOOLS_PATHS])
396     if test -z "$ZIPALIGN" -o "$ZIPALIGN" = ":"; then
397       AC_MSG_ERROR([The program zipalign was not found.  Use --with-android-sdk={android-sdk-dir}.])
398     fi
399     if test -z "$DX" -o "$DX" = ":"; then
400       AC_MSG_ERROR([The program dx was not found.  Use --with-android-sdk={android-sdk-dir}.])
401     fi
402     if test -z "$AAPT" -o "$AAPT" = ":"; then
403       AC_MSG_ERROR([The program aapt was not found.  Use --with-android-sdk={android-sdk-dir}.])
404     fi
405     if test -z "$AIDL" -o "$AIDL" = ":"; then
406       AC_MSG_ERROR([The program aidl was not found.  Use --with-android-sdk={android-sdk-dir}.])
407     fi
408     if test -z "$ADB" -o "$ADB" = ":"; then
409       AC_MSG_ERROR([The program adb was not found.  Use --with-android-sdk={android-sdk-dir}.])
410     fi
411     ;;
412 esac
414 MOZ_ARG_WITH_STRING(android-min-sdk,
415 [  --with-android-min-sdk=[VER]     Impose a minimum Firefox for Android SDK version],
416 [ MOZ_ANDROID_MIN_SDK_VERSION=$withval ])
418 MOZ_ARG_WITH_STRING(android-max-sdk,
419 [  --with-android-max-sdk=[VER]     Impose a maximum Firefox for Android SDK version],
420 [ MOZ_ANDROID_MAX_SDK_VERSION=$withval ])
422 if test -n "$MOZ_ANDROID_MIN_SDK_VERSION"; then
423     if test -n "$MOZ_ANDROID_MAX_SDK_VERSION"; then
424         if test $MOZ_ANDROID_MAX_SDK_VERSION -lt $MOZ_ANDROID_MIN_SDK_VERSION ; then
425             AC_MSG_ERROR([--with-android-max-sdk must be at least the value of --with-android-min-sdk.])
426         fi
427     fi
429     if test $MOZ_ANDROID_MIN_SDK_VERSION -gt $ANDROID_TARGET_SDK ; then
430         AC_MSG_ERROR([--with-android-min-sdk is expected to be less than $ANDROID_TARGET_SDK])
431     fi
433     AC_DEFINE_UNQUOTED(MOZ_ANDROID_MIN_SDK_VERSION, $MOZ_ANDROID_MIN_SDK_VERSION)
436 if test -n "$MOZ_ANDROID_MAX_SDK_VERSION"; then
437     AC_DEFINE_UNQUOTED(MOZ_ANDROID_MAX_SDK_VERSION, $MOZ_ANDROID_MAX_SDK_VERSION)