# Maintainer: Developer <dev@opalos.org>
# Maintainer: Developer <dev@opalos.org>

pkgname=nvme-cli
pkgver=%version%
pkgrel=%release%
pkgdesc="NVM-Express user space tooling for Linux"
arch=('x86_64')
url="https://github.com/linux-nvme/nvme-cli"
license=('GPL')
makedepends=('systemd' 'meson' 'git' 'asciidoc' 'xmlto' 'swig')
depends=('util-linux' 'libsystemd' 'libnvme')
options=(strip)
install=nvme-cli.install
# checkdepends=('python2-nose' 'python-nose')
source=("$pkgname-$pkgver.tar.gz::https://github.com/linux-nvme/${pkgname}/archive/v${pkgver}.tar.gz")
sha256sums=('0743d9188792a87d39187ae5e5cb31e8f46cca8c6f100547c50ec0dd659d2531')

build() {
	cd "${pkgname}-${pkgver}"

	# this uses malloc_usable_size, which is incompatible with fortification level 3
	export CFLAGS="${CFLAGS/_FORTIFY_SOURCE=3/_FORTIFY_SOURCE=2}"
	export CXXFLAGS="${CXXFLAGS/_FORTIFY_SOURCE=3/_FORTIFY_SOURCE=2}"

	meson setup \
	--prefix /usr \
	--sysconfdir /etc \
	--libexecdir lib \
	--sbindir bin \
	--buildtype plain \
	--auto-features enabled \
	-D b_lto=true -D b_pie=true \
	-D docs=man -D docs-build=true \
	-D systemddir=lib/systemd/system/ \
	-D udevrulesdir=lib/udev/rules.d \
	.build
}

# Tests require a working NVME disk.
# check() {
# 	cd "${pkgname}-${pkgver}"
# 	make test
# }

package() {
	cd "${pkgname}-${pkgver}"

	# this uses malloc_usable_size, which is incompatible with fortification level 3
	export CFLAGS="${CFLAGS/_FORTIFY_SOURCE=3/_FORTIFY_SOURCE=2}"
	export CXXFLAGS="${CXXFLAGS/_FORTIFY_SOURCE=3/_FORTIFY_SOURCE=2}"

	DESTDIR="$pkgdir" meson install -C .build
}
