# For successfull LTO build, we need to use matching LLVM version

if test `lsb_release -sc` = "buster" || test `lsb_release -sc` = "stretch"; then
export PATH=/usr/lib/llvm-11/bin/:$PATH
fi

if test `lsb_release -sc` = "bionic"; then
export PATH=/usr/lib/llvm-10/bin/:$PATH
fi

if test `lsb_release -sc` = "focal" || test `lsb_release -sc` = "impish"; then
export PATH=/usr/lib/llvm-12/bin/:$PATH
fi

if test `lsb_release -sc` = "xenial"; then
export PATH=/usr/lib/llvm-8/bin/:$PATH
fi

export CC=clang
export CXX=clang++
export AR=llvm-ar
export NM=llvm-nm
export RANLIB=llvm-ranlib

if test `lsb_release -sc` = "xenial" || test `lsb_release -sc` = "bionic" || test `lsb_release -sc` = "eoan" || test `lsb_release -sc` = "focal" || test `lsb_release -sc` = "stretch"; then
export NODEJS=/usr/lib/nodejs-mozilla/bin/node
fi

if test `lsb_release -sc` = "xenial" || test `lsb_release -sc` = "bionic" || test `lsb_release -sc` = "stretch"; then
export NASM=/usr/lib/nasm-mozilla/bin/nasm
fi

ac_add_options --prefix=/usr

ac_add_options --enable-optimize
ac_add_options --enable-eme=widevine
ac_add_options --enable-rust-simd
ac_add_options --enable-lto

if test `lsb_release -sc` = "bionic" || test `lsb_release -sc` = "buster" || test `lsb_release -sc` = "bullseye"; then
ac_add_options --enable-linker=gold
else
ac_add_options --enable-linker=lld
fi

ac_add_options --disable-elf-hack

export MOZ_PGO=1

ac_add_options --enable-pulseaudio
ac_add_options --enable-alsa
ac_add_options --enable-jack

mk_add_options AUTOCLOBBER=1

ac_add_options --disable-debug
ac_add_options --disable-debug-symbols
ac_add_options --disable-crashreporter
ac_add_options --disable-profiling
ac_add_options --disable-verify-mar
ac_add_options --disable-dmd
ac_add_options --disable-geckodriver

ac_add_options --enable-application=browser
ac_add_options --disable-updater

ac_add_options --enable-hardening

ac_add_options --with-app-name=waterfox-g3
ac_add_options --with-app-basename=Waterfox
ac_add_options --with-branding=browser/branding/waterfox
ac_add_options --with-unsigned-addon-scopes=app,system
ac_add_options --allow-addon-sideload

ac_add_options --enable-default-toolkit=cairo-gtk3-wayland

export MOZ_REQUIRE_SIGNING=0
export MOZ_INCLUDE_SOURCE_INFO=1
ac_add_options "MOZ_ALLOW_LEGACY_EXTENSIONS=1"

X=$(($(nproc --all)/2))
mk_add_options MOZ_MAKE_FLAGS="-j${X%.*}"
