abinfo "Enabling Bash extended globbing support ..."
shopt -s extglob

abinfo "Configuring ZFS userspace tools ..."
mkdir -pv "$SRCDIR"/build
cd "$SRCDIR"/build
"$SRCDIR"/configure \
    --prefix=/usr \
    --sysconfdir=/etc \
    --sbindir=/usr/bin \
    --with-mounthelperdir=/usr/bin \
    --libdir=/usr/lib \
    --datadir=/usr/share \
    --includedir=/usr/include \
    --with-udevdir=/usr/lib/udev \
    --libexecdir=/usr/libexec/zfs \
    --with-dracutdir=/usr/lib/dracut \
    --with-config=user \
    PYTHON=/usr/bin/python3

abinfo "Building ZFS userspace tools ..."
cp -rv "$SRCDIR"/{contrib,build/}
make

abinfo "Installing ZFS userspace tools ..."
make DESTDIR="${PKGDIR}" install

cd "$SRCDIR"

abinfo "Installing ZFS kernel module sources ..."
install -dv "${PKGDIR}"/usr/src/zfs-${PKGVER}
cp -Rvf "$SRCDIR"/!(abdist|build) \
    "${PKGDIR}"/usr/src/zfs-${PKGVER}

abinfo "Cleaning up ZFS kernel module source tree ..."
find "${PKGDIR}"/usr/src/zfs-${PKGVER} -name ".git*" -print0 | \
    xargs -0 rm -vfr --

abinfo "Generating DKMS configuration ..."
"${PKGDIR}"/usr/src/zfs-${PKGVER}/scripts/dkms.mkconf \
    -v ${PKGVER} \
    -f "${PKGDIR}"/usr/src/zfs-${PKGVER}/dkms.conf \
    -n zfs
rm -rfv "${PKGDIR}"/usr/src/zfs-${PKGVER}/{autobuild,abdist,acbs-build_*.log}
chmod -v g-w,o-w -R "${PKGDIR}"/usr/src/zfs-${PKGVER}
