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
52 PGOBENCH = $(WINE_PATH) ./$(EXE) bench
54 ### Source and object files
55 SRCS = benchmark.cpp bitboard.cpp evaluate.cpp main.cpp \
56 misc.cpp movegen.cpp movepick.cpp position.cpp \
57 search.cpp thread.cpp timeman.cpp tt.cpp uci.cpp ucioption.cpp tune.cpp syzygy/tbprobe.cpp \
58 nnue/evaluate_nnue.cpp nnue/features/half_ka_v2_hm.cpp \
59 hashprobe.grpc.pb.cc hashprobe.pb.cc
60 CLISRCS = client.cpp hashprobe.grpc.pb.cc hashprobe.pb.cc uci.cpp
62 HEADERS = benchmark.h bitboard.h evaluate.h misc.h movegen.h movepick.h \
63 nnue/evaluate_nnue.h nnue/features/half_ka_v2_hm.h nnue/layers/affine_transform.h \
64 nnue/layers/affine_transform_sparse_input.h nnue/layers/clipped_relu.h nnue/layers/simd.h \
65 nnue/layers/sqr_clipped_relu.h nnue/nnue_accumulator.h nnue/nnue_architecture.h \
66 nnue/nnue_common.h nnue/nnue_feature_transformer.h position.h \
67 search.h syzygy/tbprobe.h thread.h thread_win32_osx.h timeman.h \
68 tt.h tune.h types.h uci.h
70 OBJS = $(notdir $(SRCS:.cpp=.o))
71 CLIOBJS = $(notdir $(CLISRCS:.cpp=.o))
73 VPATH = syzygy:nnue:nnue/features
75 ### ==========================================================================
76 ### Section 2. High-level Configuration
77 ### ==========================================================================
79 # flag --- Comp switch --- Description
80 # ----------------------------------------------------------------------------
82 # debug = yes/no --- -DNDEBUG --- Enable/Disable debug mode
83 # sanitize = none/<sanitizer> ... (-fsanitize )
84 # --- ( undefined ) --- enable undefined behavior checks
85 # --- ( thread ) --- enable threading error checks
86 # --- ( address ) --- enable memory access checks
87 # --- ...etc... --- see compiler documentation for supported sanitizers
88 # optimize = yes/no --- (-O3/-fast etc.) --- Enable/Disable optimizations
89 # arch = (name) --- (-arch) --- Target architecture
90 # bits = 64/32 --- -DIS_64BIT --- 64-/32-bit operating system
91 # prefetch = yes/no --- -DUSE_PREFETCH --- Use prefetch asm-instruction
92 # popcnt = yes/no --- -DUSE_POPCNT --- Use popcnt asm-instruction
93 # pext = yes/no --- -DUSE_PEXT --- Use pext x86_64 asm-instruction
94 # sse = yes/no --- -msse --- Use Intel Streaming SIMD Extensions
95 # mmx = yes/no --- -mmmx --- Use Intel MMX instructions
96 # sse2 = yes/no --- -msse2 --- Use Intel Streaming SIMD Extensions 2
97 # ssse3 = yes/no --- -mssse3 --- Use Intel Supplemental Streaming SIMD Extensions 3
98 # sse41 = yes/no --- -msse4.1 --- Use Intel Streaming SIMD Extensions 4.1
99 # avx2 = yes/no --- -mavx2 --- Use Intel Advanced Vector Extensions 2
100 # avxvnni = yes/no --- -mavxvnni --- Use Intel Vector Neural Network Instructions AVX
101 # avx512 = yes/no --- -mavx512bw --- Use Intel Advanced Vector Extensions 512
102 # vnni256 = yes/no --- -mavx256vnni --- Use Intel Vector Neural Network Instructions 512 with 256bit operands
103 # vnni512 = yes/no --- -mavx512vnni --- Use Intel Vector Neural Network Instructions 512
104 # neon = yes/no --- -DUSE_NEON --- Use ARM SIMD architecture
105 # dotprod = yes/no --- -DUSE_NEON_DOTPROD --- Use ARM advanced SIMD Int8 dot product instructions
107 # Note that Makefile is space sensitive, so when adding new architectures
108 # or modifying existing flags, you have to make sure there are no extra spaces
109 # at the end of the line for flag values.
111 # Example of use for these flags:
112 # make build ARCH=x86-64-avx512 debug=yes sanitize="address undefined"
115 ### 2.1. General and architecture defaults
121 ifeq ($(ARCH), native)
122 override ARCH := $(shell $(SHELL) ../scripts/get_native_properties.sh | cut -d " " -f 1)
125 # explicitly check for the list of supported architectures (as listed with make help),
126 # the user can override with `make ARCH=x86-32-vnni256 SUPPORTED_ARCH=true`
127 ifeq ($(ARCH), $(filter $(ARCH), \
128 x86-64-vnni512 x86-64-vnni256 x86-64-avx512 x86-64-avxvnni x86-64-bmi2 \
129 x86-64-avx2 x86-64-sse41-popcnt x86-64-modern x86-64-ssse3 x86-64-sse3-popcnt \
130 x86-64 x86-32-sse41-popcnt x86-32-sse2 x86-32 ppc-64 ppc-32 e2k \
131 armv7 armv7-neon armv8 armv8-dotprod apple-silicon general-64 general-32 riscv64 loongarch64))
159 ifneq ($(shell which clang-format-17 2> /dev/null),)
160 CLANG-FORMAT = clang-format-17
162 CLANG-FORMAT = clang-format
165 ### 2.2 Architecture specific
167 ifeq ($(findstring x86,$(ARCH)),x86)
171 ifeq ($(findstring x86-32,$(ARCH)),x86-32)
182 ifeq ($(findstring -sse,$(ARCH)),-sse)
186 ifeq ($(findstring -popcnt,$(ARCH)),-popcnt)
190 ifeq ($(findstring -mmx,$(ARCH)),-mmx)
194 ifeq ($(findstring -sse2,$(ARCH)),-sse2)
199 ifeq ($(findstring -ssse3,$(ARCH)),-ssse3)
205 ifeq ($(findstring -sse41,$(ARCH)),-sse41)
212 ifeq ($(findstring -modern,$(ARCH)),-modern)
213 $(warning *** ARCH=$(ARCH) is deprecated, defaulting to ARCH=x86-64-sse41-popcnt. Execute `make help` for a list of available architectures. ***)
222 ifeq ($(findstring -avx2,$(ARCH)),-avx2)
231 ifeq ($(findstring -avxvnni,$(ARCH)),-avxvnni)
242 ifeq ($(findstring -bmi2,$(ARCH)),-bmi2)
252 ifeq ($(findstring -avx512,$(ARCH)),-avx512)
263 ifeq ($(findstring -vnni256,$(ARCH)),-vnni256)
274 ifeq ($(findstring -vnni512,$(ARCH)),-vnni512)
290 # 64-bit pext is not available on x86-32
297 # all other architectures
299 ifeq ($(ARCH),general-32)
304 ifeq ($(ARCH),general-64)
315 ifeq ($(ARCH),armv7-neon)
332 ifeq ($(ARCH),armv8-dotprod)
341 ifeq ($(ARCH),apple-silicon)
350 ifeq ($(ARCH),ppc-32)
355 ifeq ($(ARCH),ppc-64)
361 ifeq ($(findstring e2k,$(ARCH)),e2k)
372 ifeq ($(ARCH),riscv64)
376 ifeq ($(ARCH),loongarch64)
382 ### ==========================================================================
383 ### Section 3. Low-level Configuration
384 ### ==========================================================================
386 ### 3.1 Selecting compiler (default = gcc)
387 ifeq ($(MAKELEVEL),0)
388 export ENV_CXXFLAGS := $(CXXFLAGS)
389 export ENV_DEPENDFLAGS := $(DEPENDFLAGS)
390 export ENV_LDFLAGS := $(LDFLAGS)
393 CXXFLAGS = $(ENV_CXXFLAGS) -Wall -Wcast-qual -fno-exceptions -std=c++17 $(EXTRACXXFLAGS)
394 DEPENDFLAGS = $(ENV_DEPENDFLAGS) -std=c++17
395 LDFLAGS = $(ENV_LDFLAGS) $(EXTRALDFLAGS)
404 CXXFLAGS += -pedantic -Wextra -Wmissing-declarations
406 ifeq ($(arch),$(filter $(arch),armv7 armv8 riscv64))
408 CXXFLAGS += -m$(bits)
411 ifeq ($(ARCH),riscv64)
414 else ifeq ($(ARCH),loongarch64)
417 CXXFLAGS += -m$(bits)
421 ifeq ($(arch),$(filter $(arch),armv7))
425 ifneq ($(KERNEL),Darwin)
426 LDFLAGS += -Wl,--no-as-needed
430 ifeq ($(target_windows),yes)
438 ifeq ($(shell which x86_64-w64-mingw32-c++-posix 2> /dev/null),)
439 CXX=x86_64-w64-mingw32-c++
441 CXX=x86_64-w64-mingw32-c++-posix
444 ifeq ($(shell which i686-w64-mingw32-c++-posix 2> /dev/null),)
445 CXX=i686-w64-mingw32-c++
447 CXX=i686-w64-mingw32-c++-posix
450 CXXFLAGS += -pedantic -Wextra -Wshadow -Wmissing-declarations
456 CXXFLAGS += --intel -pedantic -Wextra -Wshadow -Wmissing-prototypes \
457 -Wconditional-uninitialized -Wabi -Wdeprecated
463 ifeq ($(target_windows),yes)
464 CXX=x86_64-w64-mingw32-clang++
467 CXXFLAGS += -pedantic -Wextra -Wshadow -Wmissing-prototypes \
468 -Wconditional-uninitialized
470 ifeq ($(filter $(KERNEL),Darwin OpenBSD FreeBSD),)
471 ifeq ($(target_windows),)
472 ifneq ($(RTLIB),compiler-rt)
478 ifeq ($(arch),$(filter $(arch),armv7 armv8 riscv64))
480 CXXFLAGS += -m$(bits)
483 ifeq ($(ARCH),riscv64)
486 else ifeq ($(ARCH),loongarch64)
489 CXXFLAGS += -m$(bits)
494 ifeq ($(KERNEL),Darwin)
495 CXXFLAGS += -mmacosx-version-min=10.14
496 LDFLAGS += -mmacosx-version-min=10.14
498 CXXFLAGS += -arch $(arch)
499 LDFLAGS += -arch $(arch)
504 # To cross-compile for Android, NDK version r21 or later is recommended.
505 # In earlier NDK versions, you'll need to pass -fno-addrsig if using GNU binutils.
506 # Currently we don't know how to make PGO builds with the NDK yet.
508 CXXFLAGS += -stdlib=libc++ -fPIE
511 CXX=armv7a-linux-androideabi16-clang++
512 CXXFLAGS += -mthumb -march=armv7-a -mfloat-abi=softfp -mfpu=neon
513 ifneq ($(shell which arm-linux-androideabi-strip 2>/dev/null),)
514 STRIP=arm-linux-androideabi-strip
520 CXX=aarch64-linux-android21-clang++
521 ifneq ($(shell which aarch64-linux-android-strip 2>/dev/null),)
522 STRIP=aarch64-linux-android-strip
527 LDFLAGS += -static-libstdc++ -pie -lm -latomic
531 profile_make = icx-profile-make
532 profile_use = icx-profile-use
533 else ifeq ($(comp),clang)
534 profile_make = clang-profile-make
535 profile_use = clang-profile-use
537 profile_make = gcc-profile-make
538 profile_use = gcc-profile-use
539 ifeq ($(KERNEL),Darwin)
540 EXTRAPROFILEFLAGS = -fvisibility=hidden
544 ### Travis CI script uses COMPILER to overwrite CXX
549 ### Allow overwriting CXX from command line
554 ### Sometimes gcc is really clang
556 gccversion := $(shell $(CXX) --version 2>/dev/null)
557 gccisclang := $(findstring clang,$(gccversion))
558 ifneq ($(gccisclang),)
559 profile_make = clang-profile-make
560 profile_use = clang-profile-use
564 ### On mingw use Windows threads, otherwise POSIX
565 ifneq ($(comp),mingw)
566 CXXFLAGS += -DUSE_PTHREADS
567 # On Android Bionic's C library comes with its own pthread implementation bundled in
568 ifneq ($(OS),Android)
569 # Haiku has pthreads in its libroot, so only link it in on other platforms
570 ifneq ($(KERNEL),Haiku)
585 ### 3.2.2 Debugging with undefined behavior sanitizers
586 ifneq ($(sanitize),none)
587 CXXFLAGS += -g3 $(addprefix -fsanitize=,$(sanitize))
588 LDFLAGS += $(addprefix -fsanitize=,$(sanitize))
592 ifeq ($(optimize),yes)
594 CXXFLAGS += -O3 -g -funroll-loops
597 ifeq ($(OS), Android)
598 CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
602 ifeq ($(KERNEL),Darwin)
603 ifeq ($(comp),$(filter $(comp),clang icx))
604 CXXFLAGS += -mdynamic-no-pic
608 ifneq ($(arch),arm64)
609 CXXFLAGS += -mdynamic-no-pic
615 clangmajorversion := $(shell $(CXX) -dumpversion 2>/dev/null | cut -f1 -d.)
616 ifeq ($(shell expr $(clangmajorversion) \< 16),1)
617 CXXFLAGS += -fexperimental-new-pass-manager
624 CXXFLAGS += -DIS_64BIT
627 ### 3.5 prefetch and popcount
628 ifeq ($(prefetch),yes)
633 CXXFLAGS += -DNO_PREFETCH
637 ifeq ($(arch),$(filter $(arch),ppc64 armv7 armv8 arm64))
638 CXXFLAGS += -DUSE_POPCNT
640 CXXFLAGS += -msse3 -mpopcnt -DUSE_POPCNT
644 ### 3.6 SIMD architectures
646 CXXFLAGS += -DUSE_AVX2
647 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
648 CXXFLAGS += -mavx2 -mbmi
652 ifeq ($(avxvnni),yes)
653 CXXFLAGS += -DUSE_VNNI -DUSE_AVXVNNI
654 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
655 CXXFLAGS += -mavxvnni
660 CXXFLAGS += -DUSE_AVX512
661 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
662 CXXFLAGS += -mavx512f -mavx512bw
666 ifeq ($(vnni256),yes)
667 CXXFLAGS += -DUSE_VNNI
668 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
669 CXXFLAGS += -mavx512f -mavx512bw -mavx512vnni -mavx512dq -mavx512vl -mprefer-vector-width=256
673 ifeq ($(vnni512),yes)
674 CXXFLAGS += -DUSE_VNNI
675 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
676 CXXFLAGS += -mavx512f -mavx512bw -mavx512vnni -mavx512dq -mavx512vl -mprefer-vector-width=512
681 CXXFLAGS += -DUSE_SSE41
682 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
688 CXXFLAGS += -DUSE_SSSE3
689 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
695 CXXFLAGS += -DUSE_SSE2
696 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
702 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
708 CXXFLAGS += -DUSE_NEON=$(arm_version)
709 ifeq ($(KERNEL),Linux)
711 ifneq ($(arch),armv8)
712 CXXFLAGS += -mfpu=neon
718 ifeq ($(dotprod),yes)
719 CXXFLAGS += -march=armv8.2-a+dotprod -DUSE_NEON_DOTPROD
724 CXXFLAGS += -DUSE_PEXT
725 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
730 ### 3.8.1 Try to include git commit sha for versioning
731 GIT_SHA := $(shell git rev-parse HEAD 2>/dev/null | cut -c 1-8)
733 CXXFLAGS += -DGIT_SHA=$(GIT_SHA)
736 ### 3.8.2 Try to include git commit date for versioning
737 GIT_DATE := $(shell git show -s --date=format:'%Y%m%d' --format=%cd HEAD 2>/dev/null)
738 ifneq ($(GIT_DATE), )
739 CXXFLAGS += -DGIT_DATE=$(GIT_DATE)
742 ### 3.8.3 Try to include architecture
744 CXXFLAGS += -DARCH=$(ARCH)
747 ### 3.9 Link Time Optimization
748 ### This is a mix of compile and link time options because the lto link phase
749 ### needs access to the optimization flags.
750 ifeq ($(optimize),yes)
752 ifeq ($(comp),$(filter $(comp),clang icx))
753 CXXFLAGS += -flto=full
755 CXXFLAGS += -fwhole-program-vtables
757 ifeq ($(target_windows),yes)
758 CXXFLAGS += -fuse-ld=lld
760 LDFLAGS += $(CXXFLAGS)
762 # GCC and CLANG use different methods for parallelizing LTO and CLANG pretends to be
763 # GCC on some systems.
764 else ifeq ($(comp),gcc)
765 ifeq ($(gccisclang),)
766 CXXFLAGS += -flto -flto-partition=one
767 LDFLAGS += $(CXXFLAGS) -flto=jobserver
769 CXXFLAGS += -flto=full
770 LDFLAGS += $(CXXFLAGS)
773 # To use LTO and static linking on Windows,
774 # the tool chain requires gcc version 10.1 or later.
775 else ifeq ($(comp),mingw)
776 CXXFLAGS += -flto -flto-partition=one
777 LDFLAGS += $(CXXFLAGS) -save-temps
782 ### 3.10 Android 5 can only run position independent executables. Note that this
783 ### breaks Android 4.0 and earlier.
784 ifeq ($(OS), Android)
786 LDFLAGS += -fPIE -pie
789 ### ==========================================================================
790 ### Section 4. Public Targets
791 ### ==========================================================================
795 @echo "To compile stockfish, type: "
797 @echo "make -j target [ARCH=arch] [COMP=compiler] [COMPCXX=cxx]"
799 @echo "Supported targets:"
801 @echo "help > Display architecture details"
802 @echo "profile-build > standard build with profile-guided optimization"
803 @echo "build > skip profile-guided optimization"
804 @echo "net > Download the default nnue net"
805 @echo "strip > Strip executable"
806 @echo "install > Install executable"
807 @echo "clean > Clean up"
809 @echo "Supported archs:"
811 @echo "native > select the best architecture for the host processor (default)"
812 @echo "x86-64-vnni512 > x86 64-bit with vnni 512bit support"
813 @echo "x86-64-vnni256 > x86 64-bit with vnni 512bit support, limit operands to 256bit wide"
814 @echo "x86-64-avx512 > x86 64-bit with avx512 support"
815 @echo "x86-64-avxvnni > x86 64-bit with vnni 256bit support"
816 @echo "x86-64-bmi2 > x86 64-bit with bmi2 support"
817 @echo "x86-64-avx2 > x86 64-bit with avx2 support"
818 @echo "x86-64-sse41-popcnt > x86 64-bit with sse41 and popcnt support"
819 @echo "x86-64-modern > deprecated, currently x86-64-sse41-popcnt"
820 @echo "x86-64-ssse3 > x86 64-bit with ssse3 support"
821 @echo "x86-64-sse3-popcnt > x86 64-bit with sse3 compile and popcnt support"
822 @echo "x86-64 > x86 64-bit generic (with sse2 support)"
823 @echo "x86-32-sse41-popcnt > x86 32-bit with sse41 and popcnt support"
824 @echo "x86-32-sse2 > x86 32-bit with sse2 support"
825 @echo "x86-32 > x86 32-bit generic (with mmx compile support)"
826 @echo "ppc-64 > PPC 64-bit"
827 @echo "ppc-32 > PPC 32-bit"
828 @echo "armv7 > ARMv7 32-bit"
829 @echo "armv7-neon > ARMv7 32-bit with popcnt and neon"
830 @echo "armv8 > ARMv8 64-bit with popcnt and neon"
831 @echo "armv8-dotprod > ARMv8 64-bit with popcnt, neon and dot product support"
832 @echo "e2k > Elbrus 2000"
833 @echo "apple-silicon > Apple silicon ARM64"
834 @echo "general-64 > unspecified 64-bit"
835 @echo "general-32 > unspecified 32-bit"
836 @echo "riscv64 > RISC-V 64-bit"
837 @echo "loongarch64 > LoongArch 64-bit"
839 @echo "Supported compilers:"
841 @echo "gcc > GNU compiler (default)"
842 @echo "mingw > GNU compiler with MinGW under Windows"
843 @echo "clang > LLVM Clang compiler"
844 @echo "icx > Intel oneAPI DPC++/C++ Compiler"
845 @echo "ndk > Google NDK to cross-compile for Android"
847 @echo "Simple examples. If you don't know what to do, you likely want to run one of: "
849 @echo "make -j profile-build ARCH=x86-64-avx2 # typically a fast compile for common systems "
850 @echo "make -j profile-build ARCH=x86-64-sse41-popcnt # A more portable compile for 64-bit systems "
851 @echo "make -j profile-build ARCH=x86-64 # A portable compile for 64-bit systems "
853 @echo "Advanced examples, for experienced users: "
855 @echo "make -j profile-build ARCH=x86-64-avxvnni"
856 @echo "make -j profile-build ARCH=x86-64-avxvnni COMP=gcc COMPCXX=g++-12.0"
857 @echo "make -j build ARCH=x86-64-ssse3 COMP=clang"
859 ifneq ($(SUPPORTED_ARCH), true)
860 @echo "Specify a supported architecture with the ARCH option for more details"
865 .PHONY: help analyze build profile-build strip install clean net \
866 objclean profileclean config-sanity \
867 icx-profile-use icx-profile-make \
868 gcc-profile-use gcc-profile-make \
869 clang-profile-use clang-profile-make FORCE \
872 analyze: net config-sanity objclean
873 $(MAKE) -k ARCH=$(ARCH) COMP=$(COMP) $(OBJS)
875 build: net config-sanity
876 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
878 profile-build: net config-sanity objclean profileclean
880 @echo "Step 1/4. Building instrumented executable ..."
881 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
883 @echo "Step 2/4. Running benchmark for pgo-build ..."
884 $(PGOBENCH) > PGOBENCH.out 2>&1
885 tail -n 4 PGOBENCH.out
887 @echo "Step 3/4. Building optimized executable ..."
888 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) objclean
889 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
891 @echo "Step 4/4. Deleting profile data ..."
892 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) profileclean
898 -mkdir -p -m 755 $(BINDIR)
900 $(STRIP) $(BINDIR)/$(EXE)
903 clean: objclean profileclean
904 @rm -f .depend *~ core
906 # clean binaries and objects
908 @rm -f stockfish stockfish.exe *.o ./syzygy/*.o ./nnue/*.o ./nnue/features/*.o
910 # clean auxiliary profiling files
913 @rm -f bench.txt *.gcda *.gcno ./syzygy/*.gcda ./nnue/*.gcda ./nnue/features/*.gcda *.s PGOBENCH.out
914 @rm -f stockfish.profdata *.profraw
915 @rm -f stockfish.*args*
916 @rm -f stockfish.*lt*
918 @rm -f ./-lstdc++.res
920 # set up shell variables for the net stuff
922 $(eval nnuenet := $(shell grep EvalFileDefaultName evaluate.h | grep define | sed 's/.*\(nn-[a-z0-9]\{12\}.nnue\).*/\1/'))
923 $(eval nnuedownloadurl1 := https://tests.stockfishchess.org/api/nn/$(nnuenet))
924 $(eval nnuedownloadurl2 := https://github.com/official-stockfish/networks/raw/master/$(nnuenet))
925 $(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))
926 $(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))
928 # evaluation network (nnue)
930 @echo "Default net: $(nnuenet)"
931 @if [ "x$(curl_or_wget)" = "x" ]; then \
932 echo "Neither curl nor wget is installed. Install one of these tools unless the net has been downloaded manually"; \
934 @if [ "x$(shasum_command)" = "x" ]; then \
935 echo "shasum / sha256sum not found, skipping net validation"; \
936 elif test -f "$(nnuenet)"; then \
937 if [ "$(nnuenet)" != "nn-"`$(shasum_command) $(nnuenet) | cut -c1-12`".nnue" ]; then \
938 echo "Removing invalid network"; rm -f $(nnuenet); \
941 @for nnuedownloadurl in "$(nnuedownloadurl1)" "$(nnuedownloadurl2)"; do \
942 if test -f "$(nnuenet)"; then \
943 echo "$(nnuenet) available : OK"; break; \
945 if [ "x$(curl_or_wget)" != "x" ]; then \
946 echo "Downloading $${nnuedownloadurl}"; $(curl_or_wget) $${nnuedownloadurl} > $(nnuenet);\
948 echo "No net found and download not possible"; exit 1;\
951 if [ "x$(shasum_command)" != "x" ]; then \
952 if [ "$(nnuenet)" != "nn-"`$(shasum_command) $(nnuenet) | cut -c1-12`".nnue" ]; then \
953 echo "Removing failed download"; rm -f $(nnuenet); \
957 @if ! test -f "$(nnuenet)"; then \
958 echo "Failed to download $(nnuenet)."; \
960 @if [ "x$(shasum_command)" != "x" ]; then \
961 if [ "$(nnuenet)" = "nn-"`$(shasum_command) $(nnuenet) | cut -c1-12`".nnue" ]; then \
962 echo "Network validated"; break; \
967 $(CLANG-FORMAT) -i $(SRCS) $(HEADERS) -style=file
973 ### ==========================================================================
974 ### Section 5. Private Targets
975 ### ==========================================================================
977 all: $(EXE) client .depend
982 @echo "debug: '$(debug)'"
983 @echo "sanitize: '$(sanitize)'"
984 @echo "optimize: '$(optimize)'"
985 @echo "arch: '$(arch)'"
986 @echo "bits: '$(bits)'"
987 @echo "kernel: '$(KERNEL)'"
989 @echo "prefetch: '$(prefetch)'"
990 @echo "popcnt: '$(popcnt)'"
991 @echo "pext: '$(pext)'"
992 @echo "sse: '$(sse)'"
993 @echo "mmx: '$(mmx)'"
994 @echo "sse2: '$(sse2)'"
995 @echo "ssse3: '$(ssse3)'"
996 @echo "sse41: '$(sse41)'"
997 @echo "avx2: '$(avx2)'"
998 @echo "avxvnni: '$(avxvnni)'"
999 @echo "avx512: '$(avx512)'"
1000 @echo "vnni256: '$(vnni256)'"
1001 @echo "vnni512: '$(vnni512)'"
1002 @echo "neon: '$(neon)'"
1003 @echo "dotprod: '$(dotprod)'"
1004 @echo "arm_version: '$(arm_version)'"
1005 @echo "target_windows: '$(target_windows)'"
1009 @echo "CXXFLAGS: $(CXXFLAGS)"
1010 @echo "LDFLAGS: $(LDFLAGS)"
1012 @echo "Testing config sanity. If this fails, try 'make help' ..."
1014 @test "$(debug)" = "yes" || test "$(debug)" = "no"
1015 @test "$(optimize)" = "yes" || test "$(optimize)" = "no"
1016 @test "$(SUPPORTED_ARCH)" = "true"
1017 @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
1018 test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "e2k" || \
1019 test "$(arch)" = "armv7" || test "$(arch)" = "armv8" || test "$(arch)" = "arm64" || test "$(arch)" = "riscv64" || test "$(arch)" = "loongarch64"
1020 @test "$(bits)" = "32" || test "$(bits)" = "64"
1021 @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
1022 @test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
1023 @test "$(pext)" = "yes" || test "$(pext)" = "no"
1024 @test "$(sse)" = "yes" || test "$(sse)" = "no"
1025 @test "$(mmx)" = "yes" || test "$(mmx)" = "no"
1026 @test "$(sse2)" = "yes" || test "$(sse2)" = "no"
1027 @test "$(ssse3)" = "yes" || test "$(ssse3)" = "no"
1028 @test "$(sse41)" = "yes" || test "$(sse41)" = "no"
1029 @test "$(avx2)" = "yes" || test "$(avx2)" = "no"
1030 @test "$(avx512)" = "yes" || test "$(avx512)" = "no"
1031 @test "$(vnni256)" = "yes" || test "$(vnni256)" = "no"
1032 @test "$(vnni512)" = "yes" || test "$(vnni512)" = "no"
1033 @test "$(neon)" = "yes" || test "$(neon)" = "no"
1034 @test "$(comp)" = "gcc" || test "$(comp)" = "icx" || test "$(comp)" = "mingw" || test "$(comp)" = "clang" \
1035 || test "$(comp)" = "armv7a-linux-androideabi16-clang" || test "$(comp)" = "aarch64-linux-android21-clang"
1038 +$(CXX) -o $@ $(OBJS) $(LDFLAGS)
1040 # Force recompilation to ensure version info is up-to-date
1045 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1046 EXTRACXXFLAGS='-fprofile-instr-generate ' \
1047 EXTRALDFLAGS=' -fprofile-instr-generate' \
1051 $(XCRUN) llvm-profdata merge -output=stockfish.profdata *.profraw
1052 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1053 EXTRACXXFLAGS='-fprofile-instr-use=stockfish.profdata' \
1054 EXTRALDFLAGS='-fprofile-use ' \
1059 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1060 EXTRACXXFLAGS='-fprofile-generate=profdir' \
1061 EXTRACXXFLAGS+=$(EXTRAPROFILEFLAGS) \
1062 EXTRALDFLAGS='-lgcov' \
1066 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1067 EXTRACXXFLAGS='-fprofile-use=profdir -fno-peel-loops -fno-tracer' \
1068 EXTRACXXFLAGS+=$(EXTRAPROFILEFLAGS) \
1069 EXTRALDFLAGS='-lgcov' \
1073 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1074 EXTRACXXFLAGS='-fprofile-instr-generate ' \
1075 EXTRALDFLAGS=' -fprofile-instr-generate' \
1079 $(XCRUN) llvm-profdata merge -output=stockfish.profdata *.profraw
1080 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1081 EXTRACXXFLAGS='-fprofile-instr-use=stockfish.profdata' \
1082 EXTRALDFLAGS='-fprofile-use ' \
1089 GRPC_CPP_PLUGIN = grpc_cpp_plugin
1090 GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)`
1092 %.grpc.pb.h %.grpc.pb.cc: %.proto
1093 $(PROTOC) -I $(PROTOS_PATH) --grpc_out=. --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $<
1099 %.pb.h %.pb.cc: %.proto
1100 $(PROTOC) -I $(PROTOS_PATH) --cpp_out=. $<
1102 #LDFLAGS += -Wl,-Bstatic -Wl,-\( -lprotobuf -lgrpc++_unsecure -lgrpc_unsecure -lgrpc -lz -Wl,-\) -Wl,-Bdynamic -ldl
1103 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
1104 #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
1107 $(CXX) -o $@ $(CLIOBJS) $(LDFLAGS)
1112 -@$(CXX) $(DEPENDFLAGS) -MM $(SRCS) > $@ 2> /dev/null
1114 ifeq (, $(filter $(MAKECMDGOALS), help strip install clean net objclean profileclean config-sanity))