# Setting the compiler based on the existence of clang bin directory
if test -d "$HOME/.mozbuild/clang/bin"; then
    export CC="$HOME/.mozbuild/clang/bin/clang"
    export CXX="$HOME/.mozbuild/clang/bin/clang++"
else
    export CC=clang
    export CXX=clang++
fi

if test "$SURFER_COMPAT" = "x86_64"; then
    ac_add_options --target=x86_64-pc-linux
    ac_add_options --enable-eme=widevine

    # Enable Profile Guided Optimization
    if test "$ZEN_GA_DISABLE_PGO"; then
      export ZEN_DUMMY=1
    else
      export MOZ_PGO=1
      ac_add_options MOZ_PGO=1
    fi

    # Optimization flags for SURFER_COMPAT
    ac_add_options --enable-optimize="-O3 -w -ftree-vectorize -mfpmath=sse -mprfchw -msse3 -mcx16 -msahf"

    export LDFLAGS="$LDFLAGS -Wl,-O3"
    export RUSTFLAGS="$RUSTFLAGS -Clink-args=--icf=safe"
elif test "$SURFER_COMPAT" = "aarch64"; then
    ac_add_options --target=aarch64-linux-gnu

    ac_add_options --enable-optimize="-O3"

    # override LTO settings
    export MOZ_LTO=cross,thin
    ac_add_options --enable-lto=cross,thin

    export CFLAGS="$CFLAGS -O3"
    export CPPFLAGS="$CPPFLAGS -O3"
    export CXXFLAGS="$CXXFLAGS -O3"
    export LDFLAGS="$LDFLAGS -Wl,-O3"
    export RUSTFLAGS="$RUSTFLAGS -Clink-args=--icf=safe"
fi

    export VERBOSE=1
    # Uncomment if you want to enable Polly optimizations
    #export POLLY="-mllvm -polly -mllvm -polly-2nd-level-tiling -mllvm -polly-loopfusion-greedy -mllvm -polly-pattern-matching-based-opts -mllvm -polly-position=before-vectorizer -mllvm -polly-vectorizer=stripmine"

# Common options
ac_add_options --enable-alsa
ac_add_options --enable-pulseaudio

if test "$ZEN_RELEASE"; then
    # Disable DMD and ELF hacks, enable linker lld
    ac_add_options --disable-dmd
    ac_add_options --enable-linker=lld
    ac_add_options --disable-elf-hack
    ac_add_options --disable-necko-wifi

    # Stripping options for release builds
    ac_add_options --enable-install-strip
    ac_add_options --enable-strip
    export STRIP_FLAGS="--strip-debug --strip-unneeded"
fi
