# Template file for 'stockfish'
pkgname=stockfish
version=18
revision=1
_net_file_big=nn-c288c895ea92.nnue
_net_file_small=nn-37f18f62d772.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="22a195567e3493e7c9ca8bf8fa2339f4ffc876384849ac8a417ff4b919607e7b
 c288c895ea924429ea9092e3f36b2b3c1f00f2a3a4c759ff7e57e79e3b43e4a7
 37f18f62d772f3107e1d6aaca3898c130c3c86f2ab63e6555fbbca20635a899d"
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
}
