# 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/.

# Browser branding
ac_add_options --with-app-name=${binName}
ac_add_options --with-app-basename=Zen

# Localization (Must be an absolute path)
ac_add_options --with-l10n-base="${topsrcdir}/browser/locales"

export MOZ_APP_BASENAME=Zen
export MOZ_BRANDING_DIRECTORY=${brandingDir}
export MOZ_OFFICIAL_BRANDING_DIRECTORY=${brandingDir}

ac_add_options --with-distribution-id=app.zen-browser

# Uncomment if builds are too resource hungry
# mk_add_options MOZ_MAKE_FLAGS="-j4"
# ac_add_options --enable-linker=gold

# Misc
export MOZ_SOURCE_REPO=https://github.com/zen-browser/desktop
export MOZ_SOURCE_CHANGESET=${changeset}
export MOZ_INCLUDE_SOURCE_INFO=1

ac_add_options --enable-application=browser

if test "$SCCACHE_GHA_ENABLED" = "true"; then
  if test -x "$(command -v sccache)"; then
    ac_add_options --with-ccache=sccache
  elif test -f "$HOME/.mozbuild/sccache/sccache"; then
    ac_add_options --with-ccache="$HOME"/.mozbuild/sccache/sccache
  fi

  mk_add_options 'export RUSTC_WRAPPER=sccache'
  mk_add_options 'export CCACHE_CPP2=yes'
fi

# add API keys if it exists on a file
if test -f "$HOME/.zen-keys/safebrowsing.dat"; then
  ac_add_options --with-google-safebrowsing-api-keyfile="$HOME/.zen-keys/safebrowsing.dat"
fi

if test -f "$HOME/.zen-keys/mozilla.dat"; then
  ac_add_options --with-mozilla-api-keyfile="$HOME/.zen-keys/mozilla.dat"
fi

if test -f "$HOME/.zen-keys/google_location_service.dat"; then
  ac_add_options --with-google-location-service-api-keyfile="$HOME/.zen-keys/google_location_service.dat"
fi

if test "$ZEN_RELEASE"; then

  ac_add_options --enable-clang-plugin
  ac_add_options --enable-bootstrap=-sccache

  ac_add_options --enable-optimize

  ac_add_options --enable-release
  ac_add_options --disable-debug
  ac_add_options --disable-debug-symbols
  ac_add_options --disable-debug-js-modules
  ac_add_options --disable-tests

  ac_add_options --enable-rust-simd
  ac_add_options --enable-wasm-simd

  ac_add_options --disable-geckodriver
  ac_add_options --disable-rust-tests

  if ! test "$ZEN_DISABLE_LTO"; then
    # only enable full LTO when ZEN_RELEASE_BRANCH is 'release'
    if test "$ZEN_RELEASE_BRANCH" = "release"; then
      # TODO: make it "full" once we have the resources to build it
      export MOZ_LTO=cross,full
      ac_add_options --enable-lto=cross,full
    else
      export MOZ_LTO=cross,thin
      ac_add_options --enable-lto=cross,thin
    fi
  fi

  mk_add_options MOZILLA_OFFICIAL=1
  MOZILLA_OFFICIAL=1
  export MOZILLA_OFFICIAL=1

  mk_add_options AUTOCLOBBER=1
  export AUTOCLOBBER=1

  export MOZ_PACKAGE_JSSHELL=1

  ac_add_options --disable-crashreporter

  # Experimental flag, enabled only on nightly for Firefox.
  # Should bring in some nice performance improvements, 
  # but may cause stability issues.
  ac_add_options --enable-replace-malloc
fi

ac_add_options --enable-jxl

ac_add_options --with-unsigned-addon-scopes=app,system

mk_add_options MOZ_DATA_REPORTING=
mk_add_options MOZ_SERVICES_HEALTHREPORT=
mk_add_options MOZ_TELEMETRY_REPORTING=

ac_add_options MOZ_DATA_REPORTING=
ac_add_options MOZ_TELEMETRY_REPORTING=

# Allow loading unsigned extensions
export MOZ_REQUIRE_SIGNING=
mk_add_options MOZ_REQUIRE_SIGNING=
