# 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_USER_DIR="${name}"
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

# Anything except 'SCCACHE_GHA_ENABLED == false'
if ! test "$SCCACHE_GHA_ENABLED" = "false"; 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
fi

# add safe browsing key 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 "$ZEN_RELEASE"; then

  # TODO: Make this successful in builds
  # ac_add_options --enable-clang-plugin
  ac_add_options --enable-bootstrap=-sccache

  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 --disable-js-shell

  ac_add_options --disable-vtune

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

  mk_add_options MOZ_PARALLEL_COMPILE=1

  ac_add_options --enable-proxy-bypass-protection
  ac_add_options --enable-hardening
  ac_add_options --disable-profiling

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

  ac_add_options --disable-default-browser-agent

  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

  ac_add_options --enable-jemalloc

  mk_add_options MOZILLA_OFFICIAL=1
  MOZILLA_OFFICIAL=1
  export MOZILLA_OFFICIAL=1

  export OPT_LEVEL="3"
  ac_add_options OPT_LEVEL="3"

  export RUSTC_OPT_LEVEL="3"
  ac_add_options RUSTC_OPT_LEVEL="3"

  mk_add_options AUTOCLOBBER=1
  export AUTOCLOBBER=1

  ac_add_options --enable-updater

  export MOZ_PACKAGE_JSSHELL=1
fi

ac_add_options --enable-unverified-updates

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=
