# Copyright 1999-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
inherit linux-mod-r1 linux-info

DESCRIPTION="Virtual SCSI Host Adapter (VHBA) kernel module"
HOMEPAGE="https://cdemu.sourceforge.io/"
SRC_URI="https://downloads.sourceforge.net/cdemu/vhba-module-${PV}.tar.xz"

LICENSE="GPL-2+"
SLOT="0"
KEYWORDS="amd64 x86"

S="${WORKDIR}/vhba-module-${PV}"
CONFIG_CHECK="~BLK_DEV_SR"

pkg_setup() {
	linux-mod-r1_pkg_setup
}

src_prepare() {
	default

	if kernel_is -ge 7 0 0; then
		sed -i -e '1i #include <scsi/scsi_cmnd.h>' vhba.c || die
		sed -i -e 's/static int vhba_queuecommand/static enum scsi_qc_status vhba_queuecommand/' vhba.c || die
	fi

	if [[ -f Makefile ]]; then
		sed -i -e 's/-Werror//g' Makefile || die
	fi
}

src_compile() {
	local modlist=( vhba )
	local modargs=(
		KDIR="${KERNEL_DIR}"
		VHBA_VERSION="${PV}"
	)
	linux-mod-r1_src_compile
}

src_install() {
	linux-mod-r1_src_install
	dodoc README AUTHORS ChangeLog
}