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-5af11540bbfe.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 ~arm64 ~loong ~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"
26 if ! tc-is-clang && ! tc-is-gcc; then
27 die "Unsupported compiler: $(tc-getCC)"
34 # remove config sanity check that doesn't like our COMPILER settings
35 sed -i -e 's/ config-sanity//g' Makefile || die
37 cp "${DISTDIR}"/${P}-${NNUE_FILE} ${NNUE_FILE} || die "copying the nnue file failed"
39 # prevent pre-stripping
40 sed -e 's:-strip $(BINDIR)/$(EXE)::' -i Makefile \
41 || die 'failed to disable stripping in the Makefile'
43 # Makefile is a bit optimistic
44 sed -e 's:-flto=full:-flto:g' -i Makefile || die
50 # generic unoptimized first
51 use general-32 && my_arch=general-32
52 use general-64 && my_arch=general-64
55 use x86 && my_arch=x86-32-old
56 use cpu_flags_x86_sse && my_arch=x86-32
59 use amd64 && my_arch=x86-64
60 use cpu_flags_x86_popcnt && my_arch=x86-64-modern
62 # both bmi2 and avx2 are part of hni (haswell new instructions)
63 use cpu_flags_x86_avx2 && my_arch=x86-64-bmi2
66 use cpu_flags_arm_v7 && my_arch=armv7
67 use ppc && my_arch=ppc
68 use ppc64 && my_arch=ppc64
70 # Bug 919781: COMP is a fixed string like clang/gcc to set tools for PGO
72 tc-is-gcc && comp="gcc"
73 tc-is-clang && comp="clang"
75 # There's a nice hack in the Makefile that overrides the value of CXX with
76 # COMPILER to support Travis CI and we abuse it to make sure that we
77 # build with our compiler of choice.
78 emake profile-build ARCH="${my_arch}" \
80 COMPILER="$(tc-getCXX)" \
81 debug=$(usex debug "yes" "no") \
82 optimize=$(usex optimize "yes" "no")
87 dodoc ../AUTHORS ../README.md