1 # Copyright 1999-2024 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 inherit toolchain-funcs
8 DESCRIPTION="Free UCI chess engine, claimed to be the strongest in the world"
9 HOMEPAGE="https://stockfishchess.org/"
11 NNUE_FILE="nn-ad9b42354671.nnue"
13 SRC_URI="https://github.com/official-stockfish/Stockfish/archive/sf_${PV}.tar.gz -> ${P}.tar.gz
14 https://tests.stockfishchess.org/api/nn/${NNUE_FILE} -> ${P}-${NNUE_FILE}"
17 KEYWORDS="~amd64 ~riscv ~x86"
18 IUSE="cpu_flags_arm_v7 cpu_flags_x86_avx2 cpu_flags_x86_popcnt cpu_flags_x86_sse debug
19 general-32 general-64 +optimize"
21 DEPEND="|| ( app-arch/unzip app-arch/zip )"
23 S="${WORKDIR}/Stockfish-sf_${PV}/src"
28 # remove config sanity check that doesn't like our COMPILER settings
29 sed -i -e 's/ config-sanity//g' Makefile || die
31 cp "${DISTDIR}"/${P}-${NNUE_FILE} ${NNUE_FILE} || die "copying the nnue file failed"
33 # prevent pre-stripping
34 sed -e 's:-strip $(BINDIR)/$(EXE)::' -i Makefile \
35 || die 'failed to disable stripping in the Makefile'
41 # generic unoptimized first
42 use general-32 && my_arch=general-32
43 use general-64 && my_arch=general-64
46 use x86 && my_arch=x86-32-old
47 use cpu_flags_x86_sse && my_arch=x86-32
50 use amd64 && my_arch=x86-64
51 use cpu_flags_x86_popcnt && my_arch=x86-64-modern
53 # both bmi2 and avx2 are part of hni (haswell new instructions)
54 use cpu_flags_x86_avx2 && my_arch=x86-64-bmi2
57 use cpu_flags_arm_v7 && my_arch=armv7
58 use ppc && my_arch=ppc
59 use ppc64 && my_arch=ppc64
61 # There's a nice hack in the Makefile that overrides the value of CXX with
62 # COMPILER to support Travis CI and we abuse it to make sure that we
63 # build with our compiler of choice.
64 emake profile-build ARCH="${my_arch}" \
66 COMPILER="$(tc-getCXX)" \
67 debug=$(usex debug "yes" "no") \
68 optimize=$(usex optimize "yes" "no")
73 dodoc ../AUTHORS ../README.md