abinfo "Preparing build environment ..."
export QTDIR="$SRCDIR"
export LD_LIBRARY_PATH="${QTDIR}/qtbase/lib:${QTDIR}/qttools/lib:${LD_LIBRARY_PATH}"
export QT_PLUGIN_PATH="${QTDIR}/qtbase/plugins"

if [[ "${CROSS:-$ARCH}" = "riscv64" ]]; then
    abinfo "RISC-V: injecting -latomic ..."
    export LIBS="-latomic"
fi

abinfo "Using -pthread instead of -lpthread for threading support ..."
for i in "$SRCDIR"/qtbase/mkspecs/common/linux.conf \
         "$SRCDIR"/qtbase/src/corelib/configure.json; do
    sed -e 's/-lpthread/-pthread/g' \
        -i "$i"
done

abinfo "Attempting to address QTBUG-67612 ..."
sed -e 's|FC_MONO|FC_DUAL|' \
    -i "$SRCDIR"/qtbase/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp

abinfo "Setting Qt module versions to correspond to main package version ..."
sed -e "s|^MODULE_VERSION = 5.15.*|MODULE_VERSION = ${PKGVER%%+*}|g" \
    -i "$SRCDIR"/*/.qmake.conf
