# Template file for 'ngspice'
pkgname=ngspice
version=44.2
revision=1
build_style=gnu-configure
configure_args="--enable-xspice --enable-cider"
hostmakedepends="bison byacc"
makedepends="readline-devel libX11-devel libXaw-devel libgomp-devel"
checkdepends="perl xvfb-run"
short_desc="Mixed Mode Mixed Level Circuit Simulator based on Spice3F5"
maintainer="Toyam Cox <Vaelatern@voidlinux.org>"
license="BSD-3-Clause"
homepage="https://ngspice.sourceforge.io"
changelog="https://sourceforge.net/p/ngspice/ngspice/ci/master/tree/NEWS?format=raw"
distfiles="${SOURCEFORGE_SITE}/ngspice/ng-spice-rework/${version}/${pkgname}-${version}.tar.gz"
checksum=e7dadfb7bd5474fd22409c1e5a67acdec19f77e597df68e17c5549bc1390d7fd

# ngshared binary and shared library can't be built in the same pass
# --ngshared builds the shared library, and readline should only be enabled for the binary
# see: https://github.com/imr/ngspice/commit/b86c85f85bbba6e45dc030af3e853edf8b9cfa3d
do_configure() {
	mkdir build
	cd build
	../configure --with-readline=yes $configure_args
	mkdir ../build-lib
	cd ../build-lib
	../configure --with-ngshared $configure_args
}

do_build() {
	make -C build $makejobs
	make -C build-lib $makejobs
}

# Starting with v34, some tests fail with "No compatability mode selected!"
# Solution is to add this line to a .spiceinit file in the home directory,
# see: https://sourceforge.net/p/ngspice/bugs/554/#b513
do_check() {
	export HOME="${PWD}/.home_dir"
	install -d "$HOME"
	printf 'set ngbehavior=mc\n' > "${HOME}/.spiceinit"
	xvfb-run make -C build check
}

do_install() {
	make DESTDIR=${DESTDIR} -C build install
	make DESTDIR=${DESTDIR} -C build-lib install
	vlicense COPYING
}

ngspice-devel_package() {
	short_desc+=" - development files"
	depends="${sourcepkg}>=${version}_${revision}"
	pkg_install() {
		vmove usr/include
		vmove "usr/lib/*.so"
		vmove usr/lib/pkgconfig
	}
}
