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_FILES="nn-b1a57edbea57.nnue nn-baff1ede1f90.nnue"
13 SRC_URI="https://github.com/official-stockfish/Stockfish/archive/sf_${PV}.tar.gz -> ${P}.tar.gz"
15 for i in $NNUE_FILES; do
16 SRC_URI+=" https://tests.stockfishchess.org/api/nn/${i} -> ${P}-${i}"
21 KEYWORDS="~amd64 ~arm64 ~loong ~riscv ~x86"
22 IUSE="cpu_flags_arm_v7 cpu_flags_x86_avx2 cpu_flags_x86_popcnt cpu_flags_x86_sse cpu_flags_x86_avx512f
23 cpu_flags_x86_avx512dq debug general-32 general-64 +optimize"
25 DEPEND="|| ( app-arch/unzip app-arch/zip )"
27 S="${WORKDIR}/Stockfish-sf_${PV}/src"
30 if ! tc-is-clang && ! tc-is-gcc; then
31 die "Unsupported compiler: $(tc-getCC)"
38 # remove config sanity check that doesn't like our COMPILER settings
39 sed -i -e 's/ config-sanity//g' Makefile || die
41 for i in $NNUE_FILES; do
42 cp "${DISTDIR}"/${P}-${i} ${i} || die "copying the nnue file failed"
45 # prevent pre-stripping
46 sed -e 's:-strip $(BINDIR)/$(EXE)::' -i Makefile \
47 || die 'failed to disable stripping in the Makefile'
49 # Makefile is a bit optimistic
50 sed -e 's:-flto=full:-flto:g' -i Makefile || die
56 # generic unoptimized first
57 use general-32 && my_arch=general-32
58 use general-64 && my_arch=general-64
61 use x86 && my_arch=x86-32-old
62 use cpu_flags_x86_sse && my_arch=x86-32
65 use amd64 && my_arch=x86-64
66 use cpu_flags_x86_popcnt && my_arch=x86-64-modern
68 # both bmi2 and avx2 are part of hni (haswell new instructions)
69 use cpu_flags_x86_avx2 && my_arch=x86-64-bmi2
72 # we currently can't express 'avx512vnni' 'avx512dq' 'avx512f' 'avx512bw' 'avx512vl'
73 # so only enable basic support
74 use cpu_flags_x86_avx512f && use cpu_flags_x86_avx512dq && my_arch=x86-64-avx512
77 use cpu_flags_arm_v7 && my_arch=armv7
78 use ppc && my_arch=ppc
79 use ppc64 && my_arch=ppc64
81 # Bug 919781: COMP is a fixed string like clang/gcc to set tools for PGO
83 tc-is-gcc && comp="gcc"
84 tc-is-clang && comp="clang"
86 # There's a nice hack in the Makefile that overrides the value of CXX with
87 # COMPILER to support Travis CI and we abuse it to make sure that we
88 # build with our compiler of choice.
89 emake profile-build ARCH="${my_arch}" \
91 COMPILER="$(tc-getCXX)" \
92 debug=$(usex debug "yes" "no") \
93 optimize=$(usex optimize "yes" "no")
98 dodoc ../AUTHORS ../README.md