# Template file for 'stockfish'
pkgname=stockfish
version=16.1
revision=1
_net_file_big=nn-b1a57edbea57.nnue
_net_file_small=nn-baff1ede1f90.nnue
build_wrksrc=src
build_style=gnu-makefile
make_build_target=build
make_use_env=yes
hostmakedepends="tar"
short_desc="Free UCI chess engine derived from Glaurung"
maintainer="shtayerc <david.murko@mailbox.org>"
license="GPL-3.0-or-later"
homepage="http://stockfishchess.org/"
distfiles="https://github.com/official-stockfish/Stockfish/archive/sf_${version}.tar.gz
 https://tests.stockfishchess.org/api/nn/${_net_file_big}
 https://tests.stockfishchess.org/api/nn/${_net_file_small}"
checksum="a5f94793b5d4155310397ba89e9c4266570ef0f24cd47de41a9103556f811b82
 b1a57edbea574ca8b88d6837473845791beb53d885f87f86d5ccdd5659fbf3b2
 baff1ede1f90c1dd1b4f772f1eff29848821801e8186345da7f0eb4121bd6f63"
skip_extraction="${_net_file_big} ${_net_file_small}"

LDFLAGS+="-lpthread -Wl,-z,stack-size=2097152"

# We know how to optimize ourselves
make_build_args="optimize=no "

case $XBPS_TARGET_MACHINE in
	x86_64*) make_build_args+="ARCH=x86-64" ;;
	i686*) make_build_args+="ARCH=x86-32" ;;
	aarch64*) make_build_args+="ARCH=armv8" ;;
	armv[56]*) make_build_args+="ARCH=general-32";;
	armv7*) make_build_args+="ARCH=armv7" ;;
	ppc64*) make_build_args+="ARCH=ppc-64" ;;
	ppc*) make_build_args+="ARCH=ppc-32" ;;
	*) broken="not supported" ;;
esac

post_extract() {
	cp $XBPS_SRCDISTDIR/${pkgname}-${version}/${_net_file_big} ./src
	cp $XBPS_SRCDISTDIR/${pkgname}-${version}/${_net_file_small} ./src
}

do_install() {
	vbin stockfish
}
