# Contributor: Duncan Bellamy <dunk@denkimushi.com>
# Maintainer: Duncan Bellamy <dunk@denkimushi.com>
pkgname=dpdk
# so name version may be different from version, includes major bumps of either
pkgver=24.11.2
pkgrel=0
pkgdesc="Data Plane Development Kit"
url="https://dpdk.org/"
# s390x is not supported, 32bit not supported
# loongarch64 currently broken
arch="aarch64 ppc64le riscv64 x86_64"
license="BSD-3-Clause AND GPL-2.0-only"
makedepends="
	bsd-compat-headers
	dtc-dev
	isa-l-dev
	jansson-dev
	libarchive-dev
	libpcap-dev
	linux-headers
	meson
	numactl-dev
	openssl-dev
	py3-elftools
	rdma-core-dev
	zlib-dev
	"
subpackages="$pkgname-static $pkgname-dev $pkgname-utils"
source="https://fast.dpdk.org/rel/dpdk-$pkgver.tar.xz
	ppc.patch"
# at least half tests fail on each platform
options="!check"
builddir="$srcdir/dpdk-stable-$pkgver"

_libs="
	acl
	argparse
	baseband_acc
	baseband_fpga_5gnr_fec
	baseband_fpga_lte_fec
	baseband_la12xx
	baseband_null
	baseband_turbo_sw
	bbdev
	bitratestats
	bpf
	bus_auxiliary
	bus_cdx
	bus_dpaa
	bus_fslmc
	bus_ifpga
	bus_pci
	bus_platform
	bus_uacce
	bus_vdev
	bus_vmbus
	cfgfile
	cmdline
	common_cnxk
	common_cpt
	common_dpaax
	common_iavf
	common_idpf
	common_ionic
	common_mlx5
	common_octeontx
	common_nfp
	common_nitrox
	common_qat
	compress_isal
	compress_mlx5
	compress_octeontx
	compress_nitrox
	compress_zlib
	compressdev
	crypto_bcmfs
	crypto_caam_jr
	crypto_ccp
	crypto_cnxk
	crypto_dpaa2_sec
	crypto_dpaa_sec
	crypto_mlx5
	crypto_nitrox
	crypto_null
	crypto_octeontx
	crypto_openssl
	crypto_scheduler
	crypto_virtio
	cryptodev
	distributor
	dma_cnxk
	dma_dpaa
	dma_dpaa2
	dma_skeleton
	dmadev
	eal
	efd
	ethdev
	event_cnxk
	event_dpaa
	event_dpaa2
	event_dsw
	event_octeontx
	event_opdl
	event_skeleton
	event_sw
	eventdev
	dispatcher
	fib
	gpudev
	graph
	gro
	gso
	hash
	ip_frag
	ipsec
	jobstats
	kvargs
	latencystats
	log
	lpm
	mbuf
	member
	mempool
	mempool_bucket
	mempool_cnxk
	mempool_dpaa
	mempool_dpaa2
	mempool_octeontx
	mempool_ring
	mempool_stack
	meter
	metrics
	ml_cnxk
	mldev
	net
	net_af_packet
	net_ark
	net_atlantic
	net_avp
	net_axgbe
	net_bnx2x
	net_bnxt
	net_bond
	net_cnxk
	net_cpfl
	net_cxgbe
	net_dpaa
	net_dpaa2
	net_e1000
	net_ena
	net_enetc
	net_enetfec
	net_enic
	net_failsafe
	net_fm10k
	net_gve
	net_hinic
	net_iavf
	net_ice
	net_idpf
	net_igc
	net_ionic
	net_ipn3ke
	net_ixgbe
	net_memif
	net_mlx4
	net_mlx5
	net_netvsc
	net_nfp
	net_ngbe
	net_null
	net_octeon_ep
	net_octeontx
	net_pcap
	net_pfe
	net_qede
	net_ring
	net_softnic
	net_tap
	net_thunderx
	net_txgbe
	net_vdev_netvsc
	net_vhost
	net_virtio
	net_vmxnet3
	node
	pcapng
	pci
	pdcp
	pdump
	pipeline
	port
	power
	raw_cnxk_bphy
	raw_cnxk_gpio
	raw_dpaa2_cmdif
	raw_ntb
	raw_skeleton
	rawdev
	rcu
	regex_cn9k
	regex_mlx5
	regexdev
	reorder
	rib
	ring
	sched
	security
	stack
	table
	telemetry
	timer
	vdpa_ifc
	vdpa_mlx5
	vdpa_nfp
	vhost
	"
_x86_64_libs="
	common_sfc_efx
	dma_ioat
	dma_idxd
	dma_hisilicon
	event_dlb2
	net_i40e
	net_hns3
	net_mana
	net_sfc
	raw_ifpga
	vdpa_sfc
	"
_aarch64_libs="
	common_sfc_efx
	dma_hisilicon
	net_hns3
	net_i40e
	net_sfc
	raw_ifpga
	vdpa_sfc
	"
_ppc64_libs="
	net_i40e
	raw_ifpga
	"
case $CARCH in
aarch64)
	_libs="$_libs $_aarch64_libs"
	;;
ppc64le)
	_libs="$_libs $_ppc64_libs"
	;;
x86_64)
	_libs="$_libs $_x86_64_libs"
	;;
esac
for _lib in $_libs; do
	subpackages="$subpackages $pkgname-${_lib//_/-}:splitlib"
done

build() {
	abuild-meson \
		--default-library=shared \
		-Denable_docs=false \
		-Dmbuf_refcnt_atomic=false \
		-Dtests="$(want_check && echo true || echo false)" \
		-Dplatform=generic \
		. output
	meson compile -C output
}

check() {
	meson test --print-errorlogs -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output
	rm -rf "$pkgdir"/usr/bin/dpdk-test*
	rm -r "$pkgdir"/usr/share/dpdk/examples
}

dev() {
	default_dev
	amove usr/lib/dpdk/pmds-*/*.so
}

utils() {
	pkgdesc="command line utilities for $pkgname"
	depends="python3"
	amove usr/bin
}

splitlib() {
	pkgdesc="DPDK library: $subpkgname"

	local libname="${subpkgname#"$pkgname"-}"
	libname=${libname//-/_}
	cd "$pkgdir"
	local _f
	find . -name "librte_$libname.so.*" | while read -r _f
	do
		amove "$_f"
	done
}

sha512sums="
4a7a47b095ed6b9433ad900fff613690ba4d4c7d109045ef01dac612f971b038226b43d3665cf08306c41cf96f3de1be1862365c3f66f3b4f749807666284d78  dpdk-24.11.2.tar.xz
8499daf14b4a174d2d760da9509374e35261dd2f920aec630f5d784109c387ab9331178a150b1b52564d417375db395b2eda3a731d7b408f10a35ee507b2701d  ppc.patch
"
