# 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 [ -z "$NO_NDK" -a -z "$USE_ARTIFACT" ]; then
  . "$topsrcdir/build/mozconfig.stylo"
fi

. "$topsrcdir/build/mozconfig.common"

# For Android builds in TaskCluster, the system image is Debian, and
# we use the Java JRE/JDK from the system.  We use a custom clang for
# the host compiler. Make sure clang uses the c++ headers included with
# clang, rather than the system headers which leads to incompatibility
# later (when linking against the clang-provided libstdc++).
HOST_CC="$MOZ_FETCHES_DIR/clang/bin/clang --gcc-toolchain=$MOZ_FETCHES_DIR/clang"
HOST_CXX="$MOZ_FETCHES_DIR/clang/bin/clang++ --gcc-toolchain=$MOZ_FETCHES_DIR/clang"

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

ac_add_options --with-gradle="$MOZ_FETCHES_DIR/android-gradle-dependencies/gradle-dist/bin/gradle"
export GRADLE_MAVEN_REPOSITORIES="file://$MOZ_FETCHES_DIR/android-gradle-dependencies/google","file://$MOZ_FETCHES_DIR/android-gradle-dependencies/jcenter","file://$MOZ_FETCHES_DIR/android-gradle-dependencies/gradle-plugins"

if [ -z "$NO_NDK" -a -z "$USE_ARTIFACT" ]; then
    # We use our own clang instead of the NDK's clang.
    CC="$MOZ_FETCHES_DIR/clang/bin/clang"
    CXX="$MOZ_FETCHES_DIR/clang/bin/clang++"
    ac_add_options --with-android-ndk="$MOZ_FETCHES_DIR/android-ndk"
    # Make sure that any host binaries we build use whatever libraries clang
    # linked against, rather than what's on the system.
    mk_add_options "export LD_LIBRARY_PATH=$MOZ_FETCHES_DIR/clang/lib"
    # Enable static analysis plugin
    export ENABLE_CLANG_PLUGIN=1
fi

ac_add_options --enable-update-channel=${MOZ_UPDATE_CHANNEL}

ac_add_options --with-google-safebrowsing-api-keyfile=/builds/sb-gapi.data
ac_add_options --with-google-location-service-api-keyfile=/builds/gls-gapi.data
ac_add_options --with-mozilla-api-keyfile=/builds/mozilla-fennec-geoloc-api.key

if [ -n "$TASKCLUSTER_PGO_PROFILE_USE" ]; then
    export MOZ_LTO=cross
    export LLVM_PROFDATA="$MOZ_FETCHES_DIR/clang/bin/llvm-profdata"

    ac_add_options --enable-profile-use

    # This is disabled because jarlog re-ordering breaks apk publishing tasks,
    # see bug 1539933.
    # ac_add_options --with-pgo-jarlog=${MOZ_FETCHES_DIR}/en-US.log
    ac_add_options --with-pgo-profile-path=${MOZ_FETCHES_DIR}/merged.profdata
fi

# Package js shell.
export MOZ_PACKAGE_JSSHELL=1

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