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
60 HEADERS = benchmark.h bitboard.h evaluate.h misc.h movegen.h movepick.h \
61 nnue/evaluate_nnue.h nnue/features/half_ka_v2_hm.h nnue/layers/affine_transform.h \
62 nnue/layers/affine_transform_sparse_input.h nnue/layers/clipped_relu.h nnue/layers/simd.h \
63 nnue/layers/sqr_clipped_relu.h nnue/nnue_accumulator.h nnue/nnue_architecture.h \
64 nnue/nnue_common.h nnue/nnue_feature_transformer.h position.h \
65 search.h syzygy/tbprobe.h thread.h thread_win32_osx.h timeman.h \
66 tt.h tune.h types.h uci.h
68 OBJS = $(notdir $(SRCS:.cpp=.o))
70 VPATH = syzygy:nnue:nnue/features
72 ### ==========================================================================
73 ### Section 2. High-level Configuration
74 ### ==========================================================================
76 # flag --- Comp switch --- Description
77 # ----------------------------------------------------------------------------
79 # debug = yes/no --- -DNDEBUG --- Enable/Disable debug mode
80 # sanitize = none/<sanitizer> ... (-fsanitize )
81 # --- ( undefined ) --- enable undefined behavior checks
82 # --- ( thread ) --- enable threading error checks
83 # --- ( address ) --- enable memory access checks
84 # --- ...etc... --- see compiler documentation for supported sanitizers
85 # optimize = yes/no --- (-O3/-fast etc.) --- Enable/Disable optimizations
86 # arch = (name) --- (-arch) --- Target architecture
87 # bits = 64/32 --- -DIS_64BIT --- 64-/32-bit operating system
88 # prefetch = yes/no --- -DUSE_PREFETCH --- Use prefetch asm-instruction
89 # popcnt = yes/no --- -DUSE_POPCNT --- Use popcnt asm-instruction
90 # pext = yes/no --- -DUSE_PEXT --- Use pext x86_64 asm-instruction
91 # sse = yes/no --- -msse --- Use Intel Streaming SIMD Extensions
92 # mmx = yes/no --- -mmmx --- Use Intel MMX instructions
93 # sse2 = yes/no --- -msse2 --- Use Intel Streaming SIMD Extensions 2
94 # ssse3 = yes/no --- -mssse3 --- Use Intel Supplemental Streaming SIMD Extensions 3
95 # sse41 = yes/no --- -msse4.1 --- Use Intel Streaming SIMD Extensions 4.1
96 # avx2 = yes/no --- -mavx2 --- Use Intel Advanced Vector Extensions 2
97 # avxvnni = yes/no --- -mavxvnni --- Use Intel Vector Neural Network Instructions AVX
98 # avx512 = yes/no --- -mavx512bw --- Use Intel Advanced Vector Extensions 512
99 # vnni256 = yes/no --- -mavx256vnni --- Use Intel Vector Neural Network Instructions 512 with 256bit operands
100 # vnni512 = yes/no --- -mavx512vnni --- Use Intel Vector Neural Network Instructions 512
101 # neon = yes/no --- -DUSE_NEON --- Use ARM SIMD architecture
102 # dotprod = yes/no --- -DUSE_NEON_DOTPROD --- Use ARM advanced SIMD Int8 dot product instructions
104 # Note that Makefile is space sensitive, so when adding new architectures
105 # or modifying existing flags, you have to make sure there are no extra spaces
106 # at the end of the line for flag values.
108 # Example of use for these flags:
109 # make build ARCH=x86-64-avx512 debug=yes sanitize="address undefined"
112 ### 2.1. General and architecture defaults
118 ifeq ($(ARCH), native)
119 override ARCH := $(shell $(SHELL) ../scripts/get_native_properties.sh | cut -d " " -f 1)
122 # explicitly check for the list of supported architectures (as listed with make help),
123 # the user can override with `make ARCH=x86-32-vnni256 SUPPORTED_ARCH=true`
124 ifeq ($(ARCH), $(filter $(ARCH), \
125 x86-64-vnni512 x86-64-vnni256 x86-64-avx512 x86-64-avxvnni x86-64-bmi2 \
126 x86-64-avx2 x86-64-sse41-popcnt x86-64-modern x86-64-ssse3 x86-64-sse3-popcnt \
127 x86-64 x86-32-sse41-popcnt x86-32-sse2 x86-32 ppc-64 ppc-32 e2k \
128 armv7 armv7-neon armv8 armv8-dotprod apple-silicon general-64 general-32 riscv64 loongarch64))
156 ifneq ($(shell which clang-format-17 2> /dev/null),)
157 CLANG-FORMAT = clang-format-17
159 CLANG-FORMAT = clang-format
162 ### 2.2 Architecture specific
164 ifeq ($(findstring x86,$(ARCH)),x86)
168 ifeq ($(findstring x86-32,$(ARCH)),x86-32)
179 ifeq ($(findstring -sse,$(ARCH)),-sse)
183 ifeq ($(findstring -popcnt,$(ARCH)),-popcnt)
187 ifeq ($(findstring -mmx,$(ARCH)),-mmx)
191 ifeq ($(findstring -sse2,$(ARCH)),-sse2)
196 ifeq ($(findstring -ssse3,$(ARCH)),-ssse3)
202 ifeq ($(findstring -sse41,$(ARCH)),-sse41)
209 ifeq ($(findstring -modern,$(ARCH)),-modern)
210 $(warning *** ARCH=$(ARCH) is deprecated, defaulting to ARCH=x86-64-sse41-popcnt. Execute `make help` for a list of available architectures. ***)
219 ifeq ($(findstring -avx2,$(ARCH)),-avx2)
228 ifeq ($(findstring -avxvnni,$(ARCH)),-avxvnni)
239 ifeq ($(findstring -bmi2,$(ARCH)),-bmi2)
249 ifeq ($(findstring -avx512,$(ARCH)),-avx512)
260 ifeq ($(findstring -vnni256,$(ARCH)),-vnni256)
271 ifeq ($(findstring -vnni512,$(ARCH)),-vnni512)
287 # 64-bit pext is not available on x86-32
294 # all other architectures
296 ifeq ($(ARCH),general-32)
301 ifeq ($(ARCH),general-64)
312 ifeq ($(ARCH),armv7-neon)
329 ifeq ($(ARCH),armv8-dotprod)
338 ifeq ($(ARCH),apple-silicon)
347 ifeq ($(ARCH),ppc-32)
352 ifeq ($(ARCH),ppc-64)
358 ifeq ($(findstring e2k,$(ARCH)),e2k)
369 ifeq ($(ARCH),riscv64)
373 ifeq ($(ARCH),loongarch64)
379 ### ==========================================================================
380 ### Section 3. Low-level Configuration
381 ### ==========================================================================
383 ### 3.1 Selecting compiler (default = gcc)
384 ifeq ($(MAKELEVEL),0)
385 export ENV_CXXFLAGS := $(CXXFLAGS)
386 export ENV_DEPENDFLAGS := $(DEPENDFLAGS)
387 export ENV_LDFLAGS := $(LDFLAGS)
390 CXXFLAGS = $(ENV_CXXFLAGS) -Wall -Wcast-qual -fno-exceptions -std=c++17 $(EXTRACXXFLAGS)
391 DEPENDFLAGS = $(ENV_DEPENDFLAGS) -std=c++17
392 LDFLAGS = $(ENV_LDFLAGS) $(EXTRALDFLAGS)
401 CXXFLAGS += -pedantic -Wextra -Wshadow -Wmissing-declarations
403 ifeq ($(arch),$(filter $(arch),armv7 armv8 riscv64))
405 CXXFLAGS += -m$(bits)
408 ifeq ($(ARCH),riscv64)
411 else ifeq ($(ARCH),loongarch64)
414 CXXFLAGS += -m$(bits)
418 ifeq ($(arch),$(filter $(arch),armv7))
422 ifneq ($(KERNEL),Darwin)
423 LDFLAGS += -Wl,--no-as-needed
427 ifeq ($(target_windows),yes)
435 ifeq ($(shell which x86_64-w64-mingw32-c++-posix 2> /dev/null),)
436 CXX=x86_64-w64-mingw32-c++
438 CXX=x86_64-w64-mingw32-c++-posix
441 ifeq ($(shell which i686-w64-mingw32-c++-posix 2> /dev/null),)
442 CXX=i686-w64-mingw32-c++
444 CXX=i686-w64-mingw32-c++-posix
447 CXXFLAGS += -pedantic -Wextra -Wshadow -Wmissing-declarations
453 CXXFLAGS += --intel -pedantic -Wextra -Wshadow -Wmissing-prototypes \
454 -Wconditional-uninitialized -Wabi -Wdeprecated
460 ifeq ($(target_windows),yes)
461 CXX=x86_64-w64-mingw32-clang++
464 CXXFLAGS += -pedantic -Wextra -Wshadow -Wmissing-prototypes \
465 -Wconditional-uninitialized
467 ifeq ($(filter $(KERNEL),Darwin OpenBSD FreeBSD),)
468 ifeq ($(target_windows),)
469 ifneq ($(RTLIB),compiler-rt)
475 ifeq ($(arch),$(filter $(arch),armv7 armv8 riscv64))
477 CXXFLAGS += -m$(bits)
480 ifeq ($(ARCH),riscv64)
483 else ifeq ($(ARCH),loongarch64)
486 CXXFLAGS += -m$(bits)
491 ifeq ($(KERNEL),Darwin)
492 CXXFLAGS += -mmacosx-version-min=10.14
493 LDFLAGS += -mmacosx-version-min=10.14
495 CXXFLAGS += -arch $(arch)
496 LDFLAGS += -arch $(arch)
501 # To cross-compile for Android, NDK version r21 or later is recommended.
502 # In earlier NDK versions, you'll need to pass -fno-addrsig if using GNU binutils.
503 # Currently we don't know how to make PGO builds with the NDK yet.
505 CXXFLAGS += -stdlib=libc++ -fPIE
508 CXX=armv7a-linux-androideabi16-clang++
509 CXXFLAGS += -mthumb -march=armv7-a -mfloat-abi=softfp -mfpu=neon
510 ifneq ($(shell which arm-linux-androideabi-strip 2>/dev/null),)
511 STRIP=arm-linux-androideabi-strip
517 CXX=aarch64-linux-android21-clang++
518 ifneq ($(shell which aarch64-linux-android-strip 2>/dev/null),)
519 STRIP=aarch64-linux-android-strip
524 LDFLAGS += -static-libstdc++ -pie -lm -latomic
528 profile_make = icx-profile-make
529 profile_use = icx-profile-use
530 else ifeq ($(comp),clang)
531 profile_make = clang-profile-make
532 profile_use = clang-profile-use
534 profile_make = gcc-profile-make
535 profile_use = gcc-profile-use
536 ifeq ($(KERNEL),Darwin)
537 EXTRAPROFILEFLAGS = -fvisibility=hidden
541 ### Travis CI script uses COMPILER to overwrite CXX
546 ### Allow overwriting CXX from command line
551 ### Sometimes gcc is really clang
553 gccversion := $(shell $(CXX) --version 2>/dev/null)
554 gccisclang := $(findstring clang,$(gccversion))
555 ifneq ($(gccisclang),)
556 profile_make = clang-profile-make
557 profile_use = clang-profile-use
561 ### On mingw use Windows threads, otherwise POSIX
562 ifneq ($(comp),mingw)
563 CXXFLAGS += -DUSE_PTHREADS
564 # On Android Bionic's C library comes with its own pthread implementation bundled in
565 ifneq ($(OS),Android)
566 # Haiku has pthreads in its libroot, so only link it in on other platforms
567 ifneq ($(KERNEL),Haiku)
582 ### 3.2.2 Debugging with undefined behavior sanitizers
583 ifneq ($(sanitize),none)
584 CXXFLAGS += -g3 $(addprefix -fsanitize=,$(sanitize))
585 LDFLAGS += $(addprefix -fsanitize=,$(sanitize))
589 ifeq ($(optimize),yes)
591 CXXFLAGS += -O3 -funroll-loops
594 ifeq ($(OS), Android)
595 CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
599 ifeq ($(KERNEL),Darwin)
600 ifeq ($(comp),$(filter $(comp),clang icx))
601 CXXFLAGS += -mdynamic-no-pic
605 ifneq ($(arch),arm64)
606 CXXFLAGS += -mdynamic-no-pic
612 clangmajorversion := $(shell $(CXX) -dumpversion 2>/dev/null | cut -f1 -d.)
613 ifeq ($(shell expr $(clangmajorversion) \< 16),1)
614 CXXFLAGS += -fexperimental-new-pass-manager
621 CXXFLAGS += -DIS_64BIT
624 ### 3.5 prefetch and popcount
625 ifeq ($(prefetch),yes)
630 CXXFLAGS += -DNO_PREFETCH
634 ifeq ($(arch),$(filter $(arch),ppc64 armv7 armv8 arm64))
635 CXXFLAGS += -DUSE_POPCNT
637 CXXFLAGS += -msse3 -mpopcnt -DUSE_POPCNT
641 ### 3.6 SIMD architectures
643 CXXFLAGS += -DUSE_AVX2
644 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
645 CXXFLAGS += -mavx2 -mbmi
649 ifeq ($(avxvnni),yes)
650 CXXFLAGS += -DUSE_VNNI -DUSE_AVXVNNI
651 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
652 CXXFLAGS += -mavxvnni
657 CXXFLAGS += -DUSE_AVX512
658 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
659 CXXFLAGS += -mavx512f -mavx512bw
663 ifeq ($(vnni256),yes)
664 CXXFLAGS += -DUSE_VNNI
665 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
666 CXXFLAGS += -mavx512f -mavx512bw -mavx512vnni -mavx512dq -mavx512vl -mprefer-vector-width=256
670 ifeq ($(vnni512),yes)
671 CXXFLAGS += -DUSE_VNNI
672 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
673 CXXFLAGS += -mavx512f -mavx512bw -mavx512vnni -mavx512dq -mavx512vl -mprefer-vector-width=512
678 CXXFLAGS += -DUSE_SSE41
679 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
685 CXXFLAGS += -DUSE_SSSE3
686 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
692 CXXFLAGS += -DUSE_SSE2
693 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
699 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
705 CXXFLAGS += -DUSE_NEON=$(arm_version)
706 ifeq ($(KERNEL),Linux)
708 ifneq ($(arch),armv8)
709 CXXFLAGS += -mfpu=neon
715 ifeq ($(dotprod),yes)
716 CXXFLAGS += -march=armv8.2-a+dotprod -DUSE_NEON_DOTPROD
721 CXXFLAGS += -DUSE_PEXT
722 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
727 ### 3.8.1 Try to include git commit sha for versioning
728 GIT_SHA := $(shell git rev-parse HEAD 2>/dev/null | cut -c 1-8)
730 CXXFLAGS += -DGIT_SHA=$(GIT_SHA)
733 ### 3.8.2 Try to include git commit date for versioning
734 GIT_DATE := $(shell git show -s --date=format:'%Y%m%d' --format=%cd HEAD 2>/dev/null)
735 ifneq ($(GIT_DATE), )
736 CXXFLAGS += -DGIT_DATE=$(GIT_DATE)
739 ### 3.8.3 Try to include architecture
741 CXXFLAGS += -DARCH=$(ARCH)
744 ### 3.9 Link Time Optimization
745 ### This is a mix of compile and link time options because the lto link phase
746 ### needs access to the optimization flags.
747 ifeq ($(optimize),yes)
749 ifeq ($(comp),$(filter $(comp),clang icx))
750 CXXFLAGS += -flto=full
752 CXXFLAGS += -fwhole-program-vtables
754 ifeq ($(target_windows),yes)
755 CXXFLAGS += -fuse-ld=lld
757 LDFLAGS += $(CXXFLAGS)
759 # GCC and CLANG use different methods for parallelizing LTO and CLANG pretends to be
760 # GCC on some systems.
761 else ifeq ($(comp),gcc)
762 ifeq ($(gccisclang),)
763 CXXFLAGS += -flto -flto-partition=one
764 LDFLAGS += $(CXXFLAGS) -flto=jobserver
766 CXXFLAGS += -flto=full
767 LDFLAGS += $(CXXFLAGS)
770 # To use LTO and static linking on Windows,
771 # the tool chain requires gcc version 10.1 or later.
772 else ifeq ($(comp),mingw)
773 CXXFLAGS += -flto -flto-partition=one
774 LDFLAGS += $(CXXFLAGS) -save-temps
779 ### 3.10 Android 5 can only run position independent executables. Note that this
780 ### breaks Android 4.0 and earlier.
781 ifeq ($(OS), Android)
783 LDFLAGS += -fPIE -pie
786 ### ==========================================================================
787 ### Section 4. Public Targets
788 ### ==========================================================================
792 @echo "To compile stockfish, type: "
794 @echo "make -j target [ARCH=arch] [COMP=compiler] [COMPCXX=cxx]"
796 @echo "Supported targets:"
798 @echo "help > Display architecture details"
799 @echo "profile-build > standard build with profile-guided optimization"
800 @echo "build > skip profile-guided optimization"
801 @echo "net > Download the default nnue net"
802 @echo "strip > Strip executable"
803 @echo "install > Install executable"
804 @echo "clean > Clean up"
806 @echo "Supported archs:"
808 @echo "native > select the best architecture for the host processor (default)"
809 @echo "x86-64-vnni512 > x86 64-bit with vnni 512bit support"
810 @echo "x86-64-vnni256 > x86 64-bit with vnni 512bit support, limit operands to 256bit wide"
811 @echo "x86-64-avx512 > x86 64-bit with avx512 support"
812 @echo "x86-64-avxvnni > x86 64-bit with vnni 256bit support"
813 @echo "x86-64-bmi2 > x86 64-bit with bmi2 support"
814 @echo "x86-64-avx2 > x86 64-bit with avx2 support"
815 @echo "x86-64-sse41-popcnt > x86 64-bit with sse41 and popcnt support"
816 @echo "x86-64-modern > deprecated, currently x86-64-sse41-popcnt"
817 @echo "x86-64-ssse3 > x86 64-bit with ssse3 support"
818 @echo "x86-64-sse3-popcnt > x86 64-bit with sse3 compile and popcnt support"
819 @echo "x86-64 > x86 64-bit generic (with sse2 support)"
820 @echo "x86-32-sse41-popcnt > x86 32-bit with sse41 and popcnt support"
821 @echo "x86-32-sse2 > x86 32-bit with sse2 support"
822 @echo "x86-32 > x86 32-bit generic (with mmx compile support)"
823 @echo "ppc-64 > PPC 64-bit"
824 @echo "ppc-32 > PPC 32-bit"
825 @echo "armv7 > ARMv7 32-bit"
826 @echo "armv7-neon > ARMv7 32-bit with popcnt and neon"
827 @echo "armv8 > ARMv8 64-bit with popcnt and neon"
828 @echo "armv8-dotprod > ARMv8 64-bit with popcnt, neon and dot product support"
829 @echo "e2k > Elbrus 2000"
830 @echo "apple-silicon > Apple silicon ARM64"
831 @echo "general-64 > unspecified 64-bit"
832 @echo "general-32 > unspecified 32-bit"
833 @echo "riscv64 > RISC-V 64-bit"
834 @echo "loongarch64 > LoongArch 64-bit"
836 @echo "Supported compilers:"
838 @echo "gcc > GNU compiler (default)"
839 @echo "mingw > GNU compiler with MinGW under Windows"
840 @echo "clang > LLVM Clang compiler"
841 @echo "icx > Intel oneAPI DPC++/C++ Compiler"
842 @echo "ndk > Google NDK to cross-compile for Android"
844 @echo "Simple examples. If you don't know what to do, you likely want to run one of: "
846 @echo "make -j profile-build ARCH=x86-64-avx2 # typically a fast compile for common systems "
847 @echo "make -j profile-build ARCH=x86-64-sse41-popcnt # A more portable compile for 64-bit systems "
848 @echo "make -j profile-build ARCH=x86-64 # A portable compile for 64-bit systems "
850 @echo "Advanced examples, for experienced users: "
852 @echo "make -j profile-build ARCH=x86-64-avxvnni"
853 @echo "make -j profile-build ARCH=x86-64-avxvnni COMP=gcc COMPCXX=g++-12.0"
854 @echo "make -j build ARCH=x86-64-ssse3 COMP=clang"
856 ifneq ($(SUPPORTED_ARCH), true)
857 @echo "Specify a supported architecture with the ARCH option for more details"
862 .PHONY: help analyze build profile-build strip install clean net \
863 objclean profileclean config-sanity \
864 icx-profile-use icx-profile-make \
865 gcc-profile-use gcc-profile-make \
866 clang-profile-use clang-profile-make FORCE \
869 analyze: net config-sanity objclean
870 $(MAKE) -k ARCH=$(ARCH) COMP=$(COMP) $(OBJS)
872 build: net config-sanity
873 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
875 profile-build: net config-sanity objclean profileclean
877 @echo "Step 1/4. Building instrumented executable ..."
878 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
880 @echo "Step 2/4. Running benchmark for pgo-build ..."
881 $(PGOBENCH) > PGOBENCH.out 2>&1
882 tail -n 4 PGOBENCH.out
884 @echo "Step 3/4. Building optimized executable ..."
885 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) objclean
886 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
888 @echo "Step 4/4. Deleting profile data ..."
889 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) profileclean
895 -mkdir -p -m 755 $(BINDIR)
897 $(STRIP) $(BINDIR)/$(EXE)
900 clean: objclean profileclean
901 @rm -f .depend *~ core
903 # clean binaries and objects
905 @rm -f stockfish stockfish.exe *.o ./syzygy/*.o ./nnue/*.o ./nnue/features/*.o
907 # clean auxiliary profiling files
910 @rm -f bench.txt *.gcda *.gcno ./syzygy/*.gcda ./nnue/*.gcda ./nnue/features/*.gcda *.s PGOBENCH.out
911 @rm -f stockfish.profdata *.profraw
912 @rm -f stockfish.*args*
913 @rm -f stockfish.*lt*
915 @rm -f ./-lstdc++.res
917 # set up shell variables for the net stuff
919 $(eval nnuenet := $(shell grep EvalFileDefaultName evaluate.h | grep define | sed 's/.*\(nn-[a-z0-9]\{12\}.nnue\).*/\1/'))
920 $(eval nnuedownloadurl1 := https://tests.stockfishchess.org/api/nn/$(nnuenet))
921 $(eval nnuedownloadurl2 := https://github.com/official-stockfish/networks/raw/master/$(nnuenet))
922 $(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))
923 $(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))
925 # evaluation network (nnue)
927 @echo "Default net: $(nnuenet)"
928 @if [ "x$(curl_or_wget)" = "x" ]; then \
929 echo "Neither curl nor wget is installed. Install one of these tools unless the net has been downloaded manually"; \
931 @if [ "x$(shasum_command)" = "x" ]; then \
932 echo "shasum / sha256sum not found, skipping net validation"; \
933 elif test -f "$(nnuenet)"; then \
934 if [ "$(nnuenet)" != "nn-"`$(shasum_command) $(nnuenet) | cut -c1-12`".nnue" ]; then \
935 echo "Removing invalid network"; rm -f $(nnuenet); \
938 @for nnuedownloadurl in "$(nnuedownloadurl1)" "$(nnuedownloadurl2)"; do \
939 if test -f "$(nnuenet)"; then \
940 echo "$(nnuenet) available : OK"; break; \
942 if [ "x$(curl_or_wget)" != "x" ]; then \
943 echo "Downloading $${nnuedownloadurl}"; $(curl_or_wget) $${nnuedownloadurl} > $(nnuenet);\
945 echo "No net found and download not possible"; exit 1;\
948 if [ "x$(shasum_command)" != "x" ]; then \
949 if [ "$(nnuenet)" != "nn-"`$(shasum_command) $(nnuenet) | cut -c1-12`".nnue" ]; then \
950 echo "Removing failed download"; rm -f $(nnuenet); \
954 @if ! test -f "$(nnuenet)"; then \
955 echo "Failed to download $(nnuenet)."; \
957 @if [ "x$(shasum_command)" != "x" ]; then \
958 if [ "$(nnuenet)" = "nn-"`$(shasum_command) $(nnuenet) | cut -c1-12`".nnue" ]; then \
959 echo "Network validated"; break; \
964 $(CLANG-FORMAT) -i $(SRCS) $(HEADERS) -style=file
970 ### ==========================================================================
971 ### Section 5. Private Targets
972 ### ==========================================================================
979 @echo "debug: '$(debug)'"
980 @echo "sanitize: '$(sanitize)'"
981 @echo "optimize: '$(optimize)'"
982 @echo "arch: '$(arch)'"
983 @echo "bits: '$(bits)'"
984 @echo "kernel: '$(KERNEL)'"
986 @echo "prefetch: '$(prefetch)'"
987 @echo "popcnt: '$(popcnt)'"
988 @echo "pext: '$(pext)'"
989 @echo "sse: '$(sse)'"
990 @echo "mmx: '$(mmx)'"
991 @echo "sse2: '$(sse2)'"
992 @echo "ssse3: '$(ssse3)'"
993 @echo "sse41: '$(sse41)'"
994 @echo "avx2: '$(avx2)'"
995 @echo "avxvnni: '$(avxvnni)'"
996 @echo "avx512: '$(avx512)'"
997 @echo "vnni256: '$(vnni256)'"
998 @echo "vnni512: '$(vnni512)'"
999 @echo "neon: '$(neon)'"
1000 @echo "dotprod: '$(dotprod)'"
1001 @echo "arm_version: '$(arm_version)'"
1002 @echo "target_windows: '$(target_windows)'"
1006 @echo "CXXFLAGS: $(CXXFLAGS)"
1007 @echo "LDFLAGS: $(LDFLAGS)"
1009 @echo "Testing config sanity. If this fails, try 'make help' ..."
1011 @test "$(debug)" = "yes" || test "$(debug)" = "no"
1012 @test "$(optimize)" = "yes" || test "$(optimize)" = "no"
1013 @test "$(SUPPORTED_ARCH)" = "true"
1014 @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
1015 test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "e2k" || \
1016 test "$(arch)" = "armv7" || test "$(arch)" = "armv8" || test "$(arch)" = "arm64" || test "$(arch)" = "riscv64" || test "$(arch)" = "loongarch64"
1017 @test "$(bits)" = "32" || test "$(bits)" = "64"
1018 @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
1019 @test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
1020 @test "$(pext)" = "yes" || test "$(pext)" = "no"
1021 @test "$(sse)" = "yes" || test "$(sse)" = "no"
1022 @test "$(mmx)" = "yes" || test "$(mmx)" = "no"
1023 @test "$(sse2)" = "yes" || test "$(sse2)" = "no"
1024 @test "$(ssse3)" = "yes" || test "$(ssse3)" = "no"
1025 @test "$(sse41)" = "yes" || test "$(sse41)" = "no"
1026 @test "$(avx2)" = "yes" || test "$(avx2)" = "no"
1027 @test "$(avx512)" = "yes" || test "$(avx512)" = "no"
1028 @test "$(vnni256)" = "yes" || test "$(vnni256)" = "no"
1029 @test "$(vnni512)" = "yes" || test "$(vnni512)" = "no"
1030 @test "$(neon)" = "yes" || test "$(neon)" = "no"
1031 @test "$(comp)" = "gcc" || test "$(comp)" = "icx" || test "$(comp)" = "mingw" || test "$(comp)" = "clang" \
1032 || test "$(comp)" = "armv7a-linux-androideabi16-clang" || test "$(comp)" = "aarch64-linux-android21-clang"
1035 +$(CXX) -o $@ $(OBJS) $(LDFLAGS)
1037 # Force recompilation to ensure version info is up-to-date
1042 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1043 EXTRACXXFLAGS='-fprofile-instr-generate ' \
1044 EXTRALDFLAGS=' -fprofile-instr-generate' \
1048 $(XCRUN) llvm-profdata merge -output=stockfish.profdata *.profraw
1049 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1050 EXTRACXXFLAGS='-fprofile-instr-use=stockfish.profdata' \
1051 EXTRALDFLAGS='-fprofile-use ' \
1056 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1057 EXTRACXXFLAGS='-fprofile-generate=profdir' \
1058 EXTRACXXFLAGS+=$(EXTRAPROFILEFLAGS) \
1059 EXTRALDFLAGS='-lgcov' \
1063 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1064 EXTRACXXFLAGS='-fprofile-use=profdir -fno-peel-loops -fno-tracer' \
1065 EXTRACXXFLAGS+=$(EXTRAPROFILEFLAGS) \
1066 EXTRALDFLAGS='-lgcov' \
1070 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1071 EXTRACXXFLAGS='-fprofile-instr-generate ' \
1072 EXTRALDFLAGS=' -fprofile-instr-generate' \
1076 $(XCRUN) llvm-profdata merge -output=stockfish.profdata *.profraw
1077 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1078 EXTRACXXFLAGS='-fprofile-instr-use=stockfish.profdata' \
1079 EXTRALDFLAGS='-fprofile-use ' \
1083 -@$(CXX) $(DEPENDFLAGS) -MM $(SRCS) > $@ 2> /dev/null
1085 ifeq (, $(filter $(MAKECMDGOALS), help strip install clean net objclean profileclean config-sanity))