modname=amneziawg
modver=3.1.20260812
built_modules='amneziawg.ko'

build() {
	# Patch blake2s API incompatibility introduced in kernel 6.19.
	if grep -q "blake2s_ctx" "$kernel_srcdir/include/crypto/blake2s.h" 2>/dev/null; then
		patch -p1 -N -d "$builddir" < "$builddir/blake2s-6.19.patch"
	fi

	# Patch udp_tunnel_sock_release/setup_udp_tunnel_sock API change (kernel 7.1+).
	if grep -q "udp_tunnel_sock_release(struct sock \*sk)" "$kernel_srcdir/include/net/udp_tunnel.h" 2>/dev/null; then
		patch -p1 -N -d "$builddir" < "$builddir/udp-tunnel-sock-7.1.patch"
	fi

	make -C "$kernel_srcdir" M="$builddir" modules > "$builddir/make.log" 2>&1
}
