1 # Stockfish, a UCI chess playing engine derived from Glaurung 2.1
2 # Copyright (C) 2004-2023 The Stockfish developers (see AUTHORS file)
4 # Stockfish is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # Stockfish is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 ### ==========================================================================
19 ### Section 1. General Configuration
20 ### ==========================================================================
22 ### Establish the operating system name
23 KERNEL = $(shell uname -s)
24 ifeq ($(KERNEL),Linux)
25 OS = $(shell uname -o)
29 ifeq ($(OS),Windows_NT)
33 else ifeq ($(COMP),mingw)
36 WINE_PATH = $(shell which wine)
41 ifeq ($(target_windows),yes)
47 ### Installation dir definitions
49 BINDIR = $(PREFIX)/bin
51 ### Built-in benchmark for pgo-builds
53 PGOBENCH = $(WINE_PATH) ./$(EXE) bench
55 PGOBENCH = $(SDE_PATH) -- $(WINE_PATH) ./$(EXE) bench
58 ### Source and object files
59 SRCS = benchmark.cpp bitboard.cpp evaluate.cpp main.cpp \
60 misc.cpp movegen.cpp movepick.cpp position.cpp psqt.cpp \
61 search.cpp thread.cpp timeman.cpp tt.cpp uci.cpp ucioption.cpp tune.cpp syzygy/tbprobe.cpp \
62 nnue/evaluate_nnue.cpp nnue/features/half_ka_v2_hm.cpp \
63 hashprobe.grpc.pb.cc hashprobe.pb.cc
64 CLISRCS = client.cpp hashprobe.grpc.pb.cc hashprobe.pb.cc uci.cpp
66 OBJS = $(notdir $(SRCS:.cpp=.o))
67 CLIOBJS = $(notdir $(CLISRCS:.cpp=.o))
69 VPATH = syzygy:nnue:nnue/features
71 ### ==========================================================================
72 ### Section 2. High-level Configuration
73 ### ==========================================================================
75 # flag --- Comp switch --- Description
76 # ----------------------------------------------------------------------------
78 # debug = yes/no --- -DNDEBUG --- Enable/Disable debug mode
79 # sanitize = none/<sanitizer> ... (-fsanitize )
80 # --- ( undefined ) --- enable undefined behavior checks
81 # --- ( thread ) --- enable threading error checks
82 # --- ( address ) --- enable memory access checks
83 # --- ...etc... --- see compiler documentation for supported sanitizers
84 # optimize = yes/no --- (-O3/-fast etc.) --- Enable/Disable optimizations
85 # arch = (name) --- (-arch) --- Target architecture
86 # bits = 64/32 --- -DIS_64BIT --- 64-/32-bit operating system
87 # prefetch = yes/no --- -DUSE_PREFETCH --- Use prefetch asm-instruction
88 # popcnt = yes/no --- -DUSE_POPCNT --- Use popcnt asm-instruction
89 # pext = yes/no --- -DUSE_PEXT --- Use pext x86_64 asm-instruction
90 # sse = yes/no --- -msse --- Use Intel Streaming SIMD Extensions
91 # mmx = yes/no --- -mmmx --- Use Intel MMX instructions
92 # sse2 = yes/no --- -msse2 --- Use Intel Streaming SIMD Extensions 2
93 # ssse3 = yes/no --- -mssse3 --- Use Intel Supplemental Streaming SIMD Extensions 3
94 # sse41 = yes/no --- -msse4.1 --- Use Intel Streaming SIMD Extensions 4.1
95 # avx2 = yes/no --- -mavx2 --- Use Intel Advanced Vector Extensions 2
96 # avxvnni = yes/no --- -mavxvnni --- Use Intel Vector Neural Network Instructions AVX
97 # avx512 = yes/no --- -mavx512bw --- Use Intel Advanced Vector Extensions 512
98 # vnni256 = yes/no --- -mavx256vnni --- Use Intel Vector Neural Network Instructions 512 with 256bit operands
99 # vnni512 = yes/no --- -mavx512vnni --- Use Intel Vector Neural Network Instructions 512
100 # neon = yes/no --- -DUSE_NEON --- Use ARM SIMD architecture
101 # dotprod = yes/no --- -DUSE_NEON_DOTPROD --- Use ARM advanced SIMD Int8 dot product instructions
103 # Note that Makefile is space sensitive, so when adding new architectures
104 # or modifying existing flags, you have to make sure there are no extra spaces
105 # at the end of the line for flag values.
107 # Example of use for these flags:
108 # make build ARCH=x86-64-avx512 debug=yes sanitize="address undefined"
111 ### 2.1. General and architecture defaults
115 help_skip_sanity = yes
117 # explicitly check for the list of supported architectures (as listed with make help),
118 # the user can override with `make ARCH=x86-32-vnni256 SUPPORTED_ARCH=true`
119 ifeq ($(ARCH), $(filter $(ARCH), \
120 x86-64-vnni512 x86-64-vnni256 x86-64-avx512 x86-64-avxvnni x86-64-bmi2 \
121 x86-64-avx2 x86-64-sse41-popcnt x86-64-modern x86-64-ssse3 x86-64-sse3-popcnt \
122 x86-64 x86-32-sse41-popcnt x86-32-sse2 x86-32 ppc-64 ppc-32 e2k \
123 armv7 armv7-neon armv8 armv8-dotprod apple-silicon general-64 general-32 riscv64))
151 ### 2.2 Architecture specific
153 ifeq ($(findstring x86,$(ARCH)),x86)
157 ifeq ($(findstring x86-32,$(ARCH)),x86-32)
168 ifeq ($(findstring -sse,$(ARCH)),-sse)
172 ifeq ($(findstring -popcnt,$(ARCH)),-popcnt)
176 ifeq ($(findstring -mmx,$(ARCH)),-mmx)
180 ifeq ($(findstring -sse2,$(ARCH)),-sse2)
185 ifeq ($(findstring -ssse3,$(ARCH)),-ssse3)
191 ifeq ($(findstring -sse41,$(ARCH)),-sse41)
198 ifeq ($(findstring -modern,$(ARCH)),-modern)
206 ifeq ($(findstring -avx2,$(ARCH)),-avx2)
215 ifeq ($(findstring -avxvnni,$(ARCH)),-avxvnni)
226 ifeq ($(findstring -bmi2,$(ARCH)),-bmi2)
236 ifeq ($(findstring -avx512,$(ARCH)),-avx512)
247 ifeq ($(findstring -vnni256,$(ARCH)),-vnni256)
258 ifeq ($(findstring -vnni512,$(ARCH)),-vnni512)
274 # 64-bit pext is not available on x86-32
281 # all other architectures
283 ifeq ($(ARCH),general-32)
288 ifeq ($(ARCH),general-64)
299 ifeq ($(ARCH),armv7-neon)
316 ifeq ($(ARCH),armv8-dotprod)
325 ifeq ($(ARCH),apple-silicon)
334 ifeq ($(ARCH),ppc-32)
339 ifeq ($(ARCH),ppc-64)
345 ifeq ($(findstring e2k,$(ARCH)),e2k)
356 ifeq ($(ARCH),riscv64)
362 ### ==========================================================================
363 ### Section 3. Low-level Configuration
364 ### ==========================================================================
366 ### 3.1 Selecting compiler (default = gcc)
367 ifeq ($(MAKELEVEL),0)
368 export ENV_CXXFLAGS := $(CXXFLAGS)
369 export ENV_DEPENDFLAGS := $(DEPENDFLAGS)
370 export ENV_LDFLAGS := $(LDFLAGS)
373 CXXFLAGS = $(ENV_CXXFLAGS) -Wall -Wcast-qual -fno-exceptions -std=c++17 $(EXTRACXXFLAGS)
374 DEPENDFLAGS = $(ENV_DEPENDFLAGS) -std=c++17
375 LDFLAGS = $(ENV_LDFLAGS) $(EXTRALDFLAGS)
384 CXXFLAGS += -pedantic -Wextra -Wmissing-declarations
386 ifeq ($(arch),$(filter $(arch),armv7 armv8 riscv64))
388 CXXFLAGS += -m$(bits)
391 ifeq ($(ARCH),riscv64)
395 CXXFLAGS += -m$(bits)
399 ifeq ($(arch),$(filter $(arch),armv7))
403 ifneq ($(KERNEL),Darwin)
404 LDFLAGS += -Wl,--no-as-needed
408 ifeq ($(target_windows),yes)
416 ifeq ($(shell which x86_64-w64-mingw32-c++-posix 2> /dev/null),)
417 CXX=x86_64-w64-mingw32-c++
419 CXX=x86_64-w64-mingw32-c++-posix
422 ifeq ($(shell which i686-w64-mingw32-c++-posix 2> /dev/null),)
423 CXX=i686-w64-mingw32-c++
425 CXX=i686-w64-mingw32-c++-posix
428 CXXFLAGS += -pedantic -Wextra -Wshadow -Wmissing-declarations
434 CXXFLAGS += --intel -pedantic -Wextra -Wshadow -Wmissing-prototypes \
435 -Wconditional-uninitialized -Wabi -Wdeprecated
441 ifeq ($(target_windows),yes)
442 CXX=x86_64-w64-mingw32-clang++
445 CXXFLAGS += -pedantic -Wextra -Wshadow -Wmissing-prototypes \
446 -Wconditional-uninitialized
448 ifeq ($(filter $(KERNEL),Darwin OpenBSD FreeBSD),)
449 ifeq ($(target_windows),)
450 ifneq ($(RTLIB),compiler-rt)
456 ifeq ($(arch),$(filter $(arch),armv7 armv8 riscv64))
458 CXXFLAGS += -m$(bits)
461 ifeq ($(ARCH),riscv64)
465 CXXFLAGS += -m$(bits)
470 ifeq ($(KERNEL),Darwin)
471 CXXFLAGS += -mmacosx-version-min=10.14
472 LDFLAGS += -mmacosx-version-min=10.14
474 CXXFLAGS += -arch $(arch)
475 LDFLAGS += -arch $(arch)
480 # To cross-compile for Android, NDK version r21 or later is recommended.
481 # In earlier NDK versions, you'll need to pass -fno-addrsig if using GNU binutils.
482 # Currently we don't know how to make PGO builds with the NDK yet.
484 CXXFLAGS += -stdlib=libc++ -fPIE
487 CXX=armv7a-linux-androideabi16-clang++
488 CXXFLAGS += -mthumb -march=armv7-a -mfloat-abi=softfp -mfpu=neon
489 ifneq ($(shell which arm-linux-androideabi-strip 2>/dev/null),)
490 STRIP=arm-linux-androideabi-strip
496 CXX=aarch64-linux-android21-clang++
497 ifneq ($(shell which aarch64-linux-android-strip 2>/dev/null),)
498 STRIP=aarch64-linux-android-strip
503 LDFLAGS += -static-libstdc++ -pie -lm -latomic
507 profile_make = icx-profile-make
508 profile_use = icx-profile-use
509 else ifeq ($(comp),clang)
510 profile_make = clang-profile-make
511 profile_use = clang-profile-use
513 profile_make = gcc-profile-make
514 profile_use = gcc-profile-use
515 ifeq ($(KERNEL),Darwin)
516 EXTRAPROFILEFLAGS = -fvisibility=hidden
520 ### Travis CI script uses COMPILER to overwrite CXX
525 ### Allow overwriting CXX from command line
530 ### Sometimes gcc is really clang
532 gccversion = $(shell $(CXX) --version 2>/dev/null)
533 gccisclang = $(findstring clang,$(gccversion))
534 ifneq ($(gccisclang),)
535 profile_make = clang-profile-make
536 profile_use = clang-profile-use
540 ### On mingw use Windows threads, otherwise POSIX
541 ifneq ($(comp),mingw)
542 CXXFLAGS += -DUSE_PTHREADS
543 # On Android Bionic's C library comes with its own pthread implementation bundled in
544 ifneq ($(OS),Android)
545 # Haiku has pthreads in its libroot, so only link it in on other platforms
546 ifneq ($(KERNEL),Haiku)
561 ### 3.2.2 Debugging with undefined behavior sanitizers
562 ifneq ($(sanitize),none)
563 CXXFLAGS += -g3 $(addprefix -fsanitize=,$(sanitize))
564 LDFLAGS += $(addprefix -fsanitize=,$(sanitize))
568 ifeq ($(optimize),yes)
573 ifeq ($(OS), Android)
574 CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
578 ifeq ($(KERNEL),Darwin)
579 ifeq ($(comp),$(filter $(comp),clang icx))
580 CXXFLAGS += -mdynamic-no-pic
584 ifneq ($(arch),arm64)
585 CXXFLAGS += -mdynamic-no-pic
591 clangmajorversion = $(shell $(CXX) -dumpversion 2>/dev/null | cut -f1 -d.)
592 ifeq ($(shell expr $(clangmajorversion) \< 16),1)
593 CXXFLAGS += -fexperimental-new-pass-manager
600 CXXFLAGS += -DIS_64BIT
603 ### 3.5 prefetch and popcount
604 ifeq ($(prefetch),yes)
609 CXXFLAGS += -DNO_PREFETCH
613 ifeq ($(arch),$(filter $(arch),ppc64 armv7 armv8 arm64))
614 CXXFLAGS += -DUSE_POPCNT
616 CXXFLAGS += -msse3 -mpopcnt -DUSE_POPCNT
620 ### 3.6 SIMD architectures
622 CXXFLAGS += -DUSE_AVX2
623 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
624 CXXFLAGS += -mavx2 -mbmi
628 ifeq ($(avxvnni),yes)
629 CXXFLAGS += -DUSE_VNNI -DUSE_AVXVNNI
630 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
631 CXXFLAGS += -mavxvnni
636 CXXFLAGS += -DUSE_AVX512
637 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
638 CXXFLAGS += -mavx512f -mavx512bw
642 ifeq ($(vnni256),yes)
643 CXXFLAGS += -DUSE_VNNI
644 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
645 CXXFLAGS += -mavx512f -mavx512bw -mavx512vnni -mavx512dq -mavx512vl -mprefer-vector-width=256
649 ifeq ($(vnni512),yes)
650 CXXFLAGS += -DUSE_VNNI
651 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
652 CXXFLAGS += -mavx512f -mavx512bw -mavx512vnni -mavx512dq -mavx512vl -mprefer-vector-width=512
657 CXXFLAGS += -DUSE_SSE41
658 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
664 CXXFLAGS += -DUSE_SSSE3
665 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
671 CXXFLAGS += -DUSE_SSE2
672 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
678 CXXFLAGS += -DUSE_MMX
679 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
685 CXXFLAGS += -DUSE_NEON=$(arm_version)
686 ifeq ($(KERNEL),Linux)
688 ifneq ($(arch),armv8)
689 CXXFLAGS += -mfpu=neon
695 ifeq ($(dotprod),yes)
696 CXXFLAGS += -march=armv8.2-a+dotprod -DUSE_NEON_DOTPROD
701 CXXFLAGS += -DUSE_PEXT
702 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
707 ### 3.7.1 Try to include git commit sha for versioning
708 GIT_SHA = $(shell git rev-parse HEAD 2>/dev/null | cut -c 1-8)
710 CXXFLAGS += -DGIT_SHA=$(GIT_SHA)
713 ### 3.7.2 Try to include git commit date for versioning
714 GIT_DATE = $(shell git show -s --date=format:'%Y%m%d' --format=%cd HEAD 2>/dev/null)
715 ifneq ($(GIT_DATE), )
716 CXXFLAGS += -DGIT_DATE=$(GIT_DATE)
719 ### 3.8 Link Time Optimization
720 ### This is a mix of compile and link time options because the lto link phase
721 ### needs access to the optimization flags.
722 ifeq ($(optimize),yes)
724 ifeq ($(comp),$(filter $(comp),clang icx))
725 CXXFLAGS += -flto=full
727 CXXFLAGS += -fwhole-program-vtables
729 ifeq ($(target_windows),yes)
730 CXXFLAGS += -fuse-ld=lld
732 LDFLAGS += $(CXXFLAGS)
734 # GCC and CLANG use different methods for parallelizing LTO and CLANG pretends to be
735 # GCC on some systems.
736 else ifeq ($(comp),gcc)
737 ifeq ($(gccisclang),)
738 CXXFLAGS += -flto -flto-partition=one
739 LDFLAGS += $(CXXFLAGS) -flto=jobserver
741 CXXFLAGS += -flto=full
742 LDFLAGS += $(CXXFLAGS)
745 # To use LTO and static linking on Windows,
746 # the tool chain requires gcc version 10.1 or later.
747 else ifeq ($(comp),mingw)
748 CXXFLAGS += -flto -flto-partition=one
749 LDFLAGS += $(CXXFLAGS) -save-temps
754 ### 3.9 Android 5 can only run position independent executables. Note that this
755 ### breaks Android 4.0 and earlier.
756 ifeq ($(OS), Android)
758 LDFLAGS += -fPIE -pie
761 ### ==========================================================================
762 ### Section 4. Public Targets
763 ### ==========================================================================
768 @echo "To compile stockfish, type: "
770 @echo "make target ARCH=arch [COMP=compiler] [COMPCXX=cxx]"
772 @echo "Supported targets:"
774 @echo "help > Display architecture details"
775 @echo "profile-build > standard build with profile-guided optimization"
776 @echo "build > skip profile-guided optimization"
777 @echo "net > Download the default nnue net"
778 @echo "strip > Strip executable"
779 @echo "install > Install executable"
780 @echo "clean > Clean up"
782 @echo "Supported archs:"
784 @echo "x86-64-vnni512 > x86 64-bit with vnni 512bit support"
785 @echo "x86-64-vnni256 > x86 64-bit with vnni 512bit support, limit operands to 256bit wide"
786 @echo "x86-64-avx512 > x86 64-bit with avx512 support"
787 @echo "x86-64-avxvnni > x86 64-bit with vnni 256bit support"
788 @echo "x86-64-bmi2 > x86 64-bit with bmi2 support"
789 @echo "x86-64-avx2 > x86 64-bit with avx2 support"
790 @echo "x86-64-sse41-popcnt > x86 64-bit with sse41 and popcnt support"
791 @echo "x86-64-modern > common modern CPU, currently x86-64-sse41-popcnt"
792 @echo "x86-64-ssse3 > x86 64-bit with ssse3 support"
793 @echo "x86-64-sse3-popcnt > x86 64-bit with sse3 and popcnt support"
794 @echo "x86-64 > x86 64-bit generic (with sse2 support)"
795 @echo "x86-32-sse41-popcnt > x86 32-bit with sse41 and popcnt support"
796 @echo "x86-32-sse2 > x86 32-bit with sse2 support"
797 @echo "x86-32 > x86 32-bit generic (with mmx and sse support)"
798 @echo "ppc-64 > PPC 64-bit"
799 @echo "ppc-32 > PPC 32-bit"
800 @echo "armv7 > ARMv7 32-bit"
801 @echo "armv7-neon > ARMv7 32-bit with popcnt and neon"
802 @echo "armv8 > ARMv8 64-bit with popcnt and neon"
803 @echo "armv8-dotprod > ARMv8 64-bit with popcnt, neon and dot product support"
804 @echo "e2k > Elbrus 2000"
805 @echo "apple-silicon > Apple silicon ARM64"
806 @echo "general-64 > unspecified 64-bit"
807 @echo "general-32 > unspecified 32-bit"
808 @echo "riscv64 > RISC-V 64-bit"
810 @echo "Supported compilers:"
812 @echo "gcc > Gnu compiler (default)"
813 @echo "mingw > Gnu compiler with MinGW under Windows"
814 @echo "clang > LLVM Clang compiler"
815 @echo "icx > Intel oneAPI DPC++/C++ Compiler"
816 @echo "ndk > Google NDK to cross-compile for Android"
818 @echo "Simple examples. If you don't know what to do, you likely want to run one of: "
820 @echo "make -j profile-build ARCH=x86-64-avx2 # typically a fast compile for common systems "
821 @echo "make -j profile-build ARCH=x86-64-modern # A more portable compile for 64-bit systems "
822 @echo "make -j profile-build ARCH=x86-64 # A portable compile for 64-bit systems "
824 @echo "Advanced examples, for experienced users: "
826 @echo "make -j profile-build ARCH=x86-64-bmi2"
827 @echo "make -j profile-build ARCH=x86-64-bmi2 COMP=gcc COMPCXX=g++-9.0"
828 @echo "make -j build ARCH=x86-64-ssse3 COMP=clang"
830 @echo "-------------------------------"
831 ifeq ($(SUPPORTED_ARCH)$(help_skip_sanity), true)
832 @echo "The selected architecture $(ARCH) will enable the following configuration: "
833 @$(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
835 @echo "Specify a supported architecture with the ARCH option for more details"
840 .PHONY: help build profile-build strip install clean net objclean profileclean \
842 icx-profile-use icx-profile-make \
843 gcc-profile-use gcc-profile-make \
844 clang-profile-use clang-profile-make FORCE
846 build: net config-sanity
847 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
849 profile-build: net config-sanity objclean profileclean
851 @echo "Step 1/4. Building instrumented executable ..."
852 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
854 @echo "Step 2/4. Running benchmark for pgo-build ..."
855 $(PGOBENCH) 2>&1 | tail -n 4
857 @echo "Step 3/4. Building optimized executable ..."
858 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) objclean
859 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
861 @echo "Step 4/4. Deleting profile data ..."
862 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) profileclean
868 -mkdir -p -m 755 $(BINDIR)
870 $(STRIP) $(BINDIR)/$(EXE)
873 clean: objclean profileclean
874 @rm -f .depend *~ core
876 # evaluation network (nnue)
878 $(eval nnuenet := $(shell grep EvalFileDefaultName evaluate.h | grep define | sed 's/.*\(nn-[a-z0-9]\{12\}.nnue\).*/\1/'))
879 @echo "Default net: $(nnuenet)"
880 $(eval nnuedownloadurl1 := https://tests.stockfishchess.org/api/nn/$(nnuenet))
881 $(eval nnuedownloadurl2 := https://github.com/official-stockfish/networks/raw/master/$(nnuenet))
882 $(eval curl_or_wget := $(shell if hash curl 2>/dev/null; then echo "curl -skL"; elif hash wget 2>/dev/null; then echo "wget -qO-"; fi))
883 @if [ "x$(curl_or_wget)" = "x" ]; then \
884 echo "Neither curl nor wget is installed. Install one of these tools unless the net has been downloaded manually"; \
886 $(eval shasum_command := $(shell if hash shasum 2>/dev/null; then echo "shasum -a 256 "; elif hash sha256sum 2>/dev/null; then echo "sha256sum "; fi))
887 @if [ "x$(shasum_command)" = "x" ]; then \
888 echo "shasum / sha256sum not found, skipping net validation"; \
890 @for nnuedownloadurl in "$(nnuedownloadurl1)" "$(nnuedownloadurl2)"; do \
891 if test -f "$(nnuenet)"; then \
892 echo "$(nnuenet) available."; \
894 if [ "x$(curl_or_wget)" != "x" ]; then \
895 echo "Downloading $${nnuedownloadurl}"; $(curl_or_wget) $${nnuedownloadurl} > $(nnuenet);\
897 echo "No net found and download not possible"; exit 1;\
900 if [ "x$(shasum_command)" != "x" ]; then \
901 if [ "$(nnuenet)" != "nn-"`$(shasum_command) $(nnuenet) | cut -c1-12`".nnue" ]; then \
902 echo "Removing failed download"; rm -f $(nnuenet); \
904 echo "Network validated"; break; \
908 @if ! test -f "$(nnuenet)"; then \
909 echo "Failed to download $(nnuenet)."; \
912 # clean binaries and objects
914 @rm -f stockfish stockfish.exe *.o ./syzygy/*.o ./nnue/*.o ./nnue/features/*.o
916 # clean auxiliary profiling files
919 @rm -f bench.txt *.gcda *.gcno ./syzygy/*.gcda ./nnue/*.gcda ./nnue/features/*.gcda *.s
920 @rm -f stockfish.profdata *.profraw
921 @rm -f stockfish.*args*
922 @rm -f stockfish.*lt*
924 @rm -f ./-lstdc++.res
929 ### ==========================================================================
930 ### Section 5. Private Targets
931 ### ==========================================================================
933 all: $(EXE) client .depend
938 @echo "debug: '$(debug)'"
939 @echo "sanitize: '$(sanitize)'"
940 @echo "optimize: '$(optimize)'"
941 @echo "arch: '$(arch)'"
942 @echo "bits: '$(bits)'"
943 @echo "kernel: '$(KERNEL)'"
945 @echo "prefetch: '$(prefetch)'"
946 @echo "popcnt: '$(popcnt)'"
947 @echo "pext: '$(pext)'"
948 @echo "sse: '$(sse)'"
949 @echo "mmx: '$(mmx)'"
950 @echo "sse2: '$(sse2)'"
951 @echo "ssse3: '$(ssse3)'"
952 @echo "sse41: '$(sse41)'"
953 @echo "avx2: '$(avx2)'"
954 @echo "avxvnni: '$(avxvnni)'"
955 @echo "avx512: '$(avx512)'"
956 @echo "vnni256: '$(vnni256)'"
957 @echo "vnni512: '$(vnni512)'"
958 @echo "neon: '$(neon)'"
959 @echo "dotprod: '$(dotprod)'"
960 @echo "arm_version: '$(arm_version)'"
961 @echo "target_windows: '$(target_windows)'"
965 @echo "CXXFLAGS: $(CXXFLAGS)"
966 @echo "LDFLAGS: $(LDFLAGS)"
968 @echo "Testing config sanity. If this fails, try 'make help' ..."
970 @test "$(debug)" = "yes" || test "$(debug)" = "no"
971 @test "$(optimize)" = "yes" || test "$(optimize)" = "no"
972 @test "$(SUPPORTED_ARCH)" = "true"
973 @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
974 test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "e2k" || \
975 test "$(arch)" = "armv7" || test "$(arch)" = "armv8" || test "$(arch)" = "arm64" || test "$(arch)" = "riscv64"
976 @test "$(bits)" = "32" || test "$(bits)" = "64"
977 @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
978 @test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
979 @test "$(pext)" = "yes" || test "$(pext)" = "no"
980 @test "$(sse)" = "yes" || test "$(sse)" = "no"
981 @test "$(mmx)" = "yes" || test "$(mmx)" = "no"
982 @test "$(sse2)" = "yes" || test "$(sse2)" = "no"
983 @test "$(ssse3)" = "yes" || test "$(ssse3)" = "no"
984 @test "$(sse41)" = "yes" || test "$(sse41)" = "no"
985 @test "$(avx2)" = "yes" || test "$(avx2)" = "no"
986 @test "$(avx512)" = "yes" || test "$(avx512)" = "no"
987 @test "$(vnni256)" = "yes" || test "$(vnni256)" = "no"
988 @test "$(vnni512)" = "yes" || test "$(vnni512)" = "no"
989 @test "$(neon)" = "yes" || test "$(neon)" = "no"
990 @test "$(comp)" = "gcc" || test "$(comp)" = "icx" || test "$(comp)" = "mingw" || test "$(comp)" = "clang" \
991 || test "$(comp)" = "armv7a-linux-androideabi16-clang" || test "$(comp)" = "aarch64-linux-android21-clang"
994 +$(CXX) -o $@ $(OBJS) $(LDFLAGS)
996 # Force recompilation to ensure version info is up-to-date
1001 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1002 EXTRACXXFLAGS='-fprofile-instr-generate ' \
1003 EXTRALDFLAGS=' -fprofile-instr-generate' \
1007 $(XCRUN) llvm-profdata merge -output=stockfish.profdata *.profraw
1008 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1009 EXTRACXXFLAGS='-fprofile-instr-use=stockfish.profdata' \
1010 EXTRALDFLAGS='-fprofile-use ' \
1015 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1016 EXTRACXXFLAGS='-fprofile-generate=profdir' \
1017 EXTRACXXFLAGS+=$(EXTRAPROFILEFLAGS) \
1018 EXTRALDFLAGS='-lgcov' \
1022 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1023 EXTRACXXFLAGS='-fprofile-use=profdir -fno-peel-loops -fno-tracer' \
1024 EXTRACXXFLAGS+=$(EXTRAPROFILEFLAGS) \
1025 EXTRALDFLAGS='-lgcov' \
1029 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1030 EXTRACXXFLAGS='-fprofile-instr-generate ' \
1031 EXTRALDFLAGS=' -fprofile-instr-generate' \
1035 $(XCRUN) llvm-profdata merge -output=stockfish.profdata *.profraw
1036 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1037 EXTRACXXFLAGS='-fprofile-instr-use=stockfish.profdata' \
1038 EXTRALDFLAGS='-fprofile-use ' \
1045 GRPC_CPP_PLUGIN = grpc_cpp_plugin
1046 GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)`
1048 %.grpc.pb.h %.grpc.pb.cc: %.proto
1049 $(PROTOC) -I $(PROTOS_PATH) --grpc_out=. --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $<
1055 %.pb.h %.pb.cc: %.proto
1056 $(PROTOC) -I $(PROTOS_PATH) --cpp_out=. $<
1058 #LDFLAGS += -Wl,-Bstatic -Wl,-\( -lprotobuf -lgrpc++_unsecure -lgrpc_unsecure -lgrpc -lz -Wl,-\) -Wl,-Bdynamic -ldl
1059 LDFLAGS += -Wl,--start-group /usr/lib/x86_64-linux-gnu/libprotobuf.a /usr/lib/x86_64-linux-gnu/libgrpc++_unsecure.a /usr/lib/x86_64-linux-gnu/libgrpc_unsecure.a /usr/lib/x86_64-linux-gnu/libgrpc.a /usr/lib/x86_64-linux-gnu/libaddress_sorting.a /usr/lib/x86_64-linux-gnu/libupb.a /usr/lib/x86_64-linux-gnu/libcares.a /usr/lib/x86_64-linux-gnu/libgpr.a /usr/lib/x86_64-linux-gnu/libabsl_*.a -Wl,--end-group -ldl -lz
1060 #LDFLAGS += /usr/lib/x86_64-linux-gnu/libprotobuf.a /usr/lib/libgrpc++_unsecure.a /usr/lib/libgrpc_unsecure.a /usr/lib/libgrpc.a /usr/lib/x86_64-linux-gnu/libcares.a -ldl -lz
1063 $(CXX) -o $@ $(CLIOBJS) $(LDFLAGS)
1068 -@$(CXX) $(DEPENDFLAGS) -MM $(SRCS) > $@ 2> /dev/null
1070 ifeq (, $(filter $(MAKECMDGOALS), help strip install clean net objclean profileclean config-sanity))