# Note: Override PKGVER.
if ab_match_arch amd64; then
    PKGVER="${__VER__AMD64}"
elif ab_match_arch arm64; then
    PKGVER="${__VER__ARM64}"
elif ab_match_arch loongarch64; then
    PKGVER="${__VER__LOONGARCH64}"
fi

for i in postinst prerm; do
    abinfo "Generating $i ..."
    sed -e \
        "s/%PKGVER%/${PKGVER}/g" \
        "$SRCDIR/autobuild/$i.in" > \
        "$SRCDIR/autobuild/$i"
done

if ab_match_arch loongarch64; then
    # Note: Debian uses a different architecture name than we do.
    GLENFLY_DEB_ARCH="loong64"
fi

abinfo "Unpacking upstream deb package ..."
dpkg-deb -X "$SRCDIR"/gf-arise-linux-graphics-driver-glvnd-dri_${PKGVER}_${GLENFLY_DEB_ARCH:-$ARCH}.deb "$SRCDIR"

abinfo "Entering kernel module sources directory"
cd "$SRCDIR"/usr/src/arise-"$PKGVER"

abinfo "Patching kernel module sources ..."
ab_apply_patches "$SRCDIR"/autobuild/module-patches/${PKGVER}/*.patch
ab_apply_patches "$SRCDIR"/autobuild/module-patches/${PKGVER}/*.patch.${ARCH}
