# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# This file is included at the top of all native android mozconfigs
if [ "x$IS_NIGHTLY" = "xyes" ]; then
  MOZ_AUTOMATION_UPLOAD_SYMBOLS=${MOZ_AUTOMATION_UPLOAD_SYMBOLS-1}
fi

MOZ_AUTOMATION_L10N_CHECK=0
. "$topsrcdir/build/mozconfig.common"

# In TaskCluster, the Java JRE/JDK are installed from tooltool, but that
# install doesn't work on the old Buildbot mock builders (CentOS 6.2), so
# the relevant env vars are not set up in that case, leaving the build to
# run from the JRE/JDK in /usr/lib/jvm.
if [ ! -f /etc/redhat-release ] || [ "$(< /etc/redhat-release)" != "CentOS release 6.2 (Final)" ]; then
    # set JAVA_HOME to find the JRE/JDK from tooltool.  Several scripts in the JDK
    # assume `java` is in PATH, so set that too.  To see how this tarball is built,
    # see testing/taskcluster/scripts/misc/repackage-jdk.sh
    export JAVA_HOME="$topsrcdir/java_home"
    export PATH="$PATH:$topsrcdir/java_home/bin"

    mk_add_options "export JAVA_HOME=$topsrcdir/java_home"
    mk_add_options "export PATH=$PATH:$topsrcdir/java_home/bin"
fi

# Set the most aggressive settings for szip. Not the default because it's
# much slower and we didn't want to slow down developers builds.
# Has no effect when MOZ_ENABLE_SZIP is not set in mobile/android/confvars.sh.
MOZ_SZIP_FLAGS="-D auto -f auto"

ac_add_options --enable-elf-hack

ANDROID_NDK_VERSION="r10e"
ANDROID_NDK_VERSION_32BIT="r8c"

# Build Fennec
ac_add_options --enable-application=mobile/android
ac_add_options --with-android-sdk="$topsrcdir/android-sdk-linux"

if [ -z "$NO_NDK" ]; then
    ac_add_options --with-android-ndk="$topsrcdir/android-ndk"
    ac_add_options --with-android-gnu-compiler-version=4.9
fi

ac_add_options --with-android-version=9
ac_add_options --with-system-zlib
ac_add_options --enable-update-channel=${MOZ_UPDATE_CHANNEL}

# Treat warnings as errors (modulo ALLOW_COMPILER_WARNINGS).
ac_add_options --enable-warnings-as-errors

ac_add_options --with-mozilla-api-keyfile=/builds/mozilla-fennec-geoloc-api.key
if test "$MOZ_UPDATE_CHANNEL" = "release" ; then
    ac_add_options --with-adjust-sdk-keyfile=/builds/adjust-sdk.token
elif test "$MOZ_UPDATE_CHANNEL" = "beta" ; then
    ac_add_options --with-adjust-sdk-keyfile=/builds/adjust-sdk-beta.token
else
    # (bug 1277553) In Aurora -> Beta simulation builds, no update channel is
    # specified, causing an assertion to throw that MOZ_INSTALL_TRACKING is
    # specified but the keyfile is not. In this case, we add a default keyfile.
    # This has the disadvantage that if our beta/release checks above ever
    # fail, we'll come to this default case and the compile-time check to
    # specify a valid keyfile will be broken. I don't have any better
    # alternatives.
    ac_add_options --with-adjust-sdk-keyfile="$topsrcdir/mobile/android/base/adjust-sdk-sandbox.token"
fi
export SOCORRO_SYMBOL_UPLOAD_TOKEN_FILE=/builds/crash-stats-api.token

# Package js shell.
export MOZ_PACKAGE_JSSHELL=1

# Use ccache
. "$topsrcdir/build/mozconfig.cache"

HOST_CC="$topsrcdir/gcc/bin/gcc"
HOST_CXX="$topsrcdir/gcc/bin/g++"

# Avoid dependency on libstdc++ 4.7
ac_add_options --enable-stdcxx-compat

# Use libc++ as our C++ standard library
ac_add_options --with-android-cxx-stl=libc++

JS_BINARY="$topsrcdir/mobile/android/config/js_wrapper.sh"
