abinfo 'Declaring $SHELL as /bin/bash ...'
export SHELL=/bin/bash

abinfo "Removing bundled zlib ..."
rm -rv "$SRCDIR"/modules/zlib

abinfo "Adapted from FC42: Remove undeeded bundles ..."
rm -rv js/src/devtools/automation/variants/
rm -rv js/src/octane/
rm -rv js/src/ctypes/libffi/

abinfo "Appending LDFLAGS to LINKFLAGS ..."
export LINKFLAGS="${LDFLAGS}"

abinfo "Adapted from FC42: icu >= 76 link fix:"
sed -i 's/icu-i18n/icu-uc &/' js/moz.configure

abinfo "Adapted from FC43: Fixup permissions"
chmod -x third_party/rust/bumpalo/src/lib.rs

if ab_match_arch riscv64; then
    abinfo "Disabling JIT for riscv64 ..."
    echo "ac_add_options --disable-jit" \
        >> "$SRCDIR"/autobuild/mozconfig
elif ab_match_arch loongson3; then
    abinfo "Setting toolchains for loongson3 ..."
    echo "ac_add_options --host=mips64el-aosc-linux-gnuabi64" \
        >> "$SRCDIR"/autobuild/mozconfig
    echo "ac_add_options --target=mips64el-aosc-linux-gnuabi64" \
        >> "$SRCDIR"/autobuild/mozconfig

    abinfo "Disabling JIT for loongson3 ..."
    echo "ac_add_options --disable-jit" \
        >> "$SRCDIR"/autobuild/mozconfig
fi

abinfo "Setting object file directory ..."
echo "mk_add_options MOZ_OBJDIR=${SRCDIR}/obj" \
    >> "$SRCDIR"/autobuild/mozconfig

cp -v "$SRCDIR"/{autobuild/,}mozconfig

abinfo 'Making sure $SHELL is set ...'
export SHELL=/bin/bash

abinfo "Removing existing obj directory ..."
rm -rfv "$SRCDIR"/obj-*

abinfo "Setting MACH_BUILD_PYTHON_NATIVE_PACKAGE_SOURCE=pip for installing Python dependencies ..."
export MACH_BUILD_PYTHON_NATIVE_PACKAGE_SOURCE=pip

# FIXME: mozbuild.configure.options.InvalidOptionError: RUSTFLAGS takes 1 value
# Ref: https://src.fedoraproject.org/rpms/redhat-rpm-config/pull-request/243.
abinfo "Unsetting RUSTFLAGS to workaround the broken Mozilla build system ..."
unset RUSTFLAGS
