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 psqt.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 OBJS = $(notdir $(SRCS:.cpp=.o))
62 VPATH = syzygy:nnue:nnue/features
64 ### ==========================================================================
65 ### Section 2. High-level Configuration
66 ### ==========================================================================
68 # flag --- Comp switch --- Description
69 # ----------------------------------------------------------------------------
71 # debug = yes/no --- -DNDEBUG --- Enable/Disable debug mode
72 # sanitize = none/<sanitizer> ... (-fsanitize )
73 # --- ( undefined ) --- enable undefined behavior checks
74 # --- ( thread ) --- enable threading error checks
75 # --- ( address ) --- enable memory access checks
76 # --- ...etc... --- see compiler documentation for supported sanitizers
77 # optimize = yes/no --- (-O3/-fast etc.) --- Enable/Disable optimizations
78 # arch = (name) --- (-arch) --- Target architecture
79 # bits = 64/32 --- -DIS_64BIT --- 64-/32-bit operating system
80 # prefetch = yes/no --- -DUSE_PREFETCH --- Use prefetch asm-instruction
81 # popcnt = yes/no --- -DUSE_POPCNT --- Use popcnt asm-instruction
82 # pext = yes/no --- -DUSE_PEXT --- Use pext x86_64 asm-instruction
83 # sse = yes/no --- -msse --- Use Intel Streaming SIMD Extensions
84 # mmx = yes/no --- -mmmx --- Use Intel MMX instructions
85 # sse2 = yes/no --- -msse2 --- Use Intel Streaming SIMD Extensions 2
86 # ssse3 = yes/no --- -mssse3 --- Use Intel Supplemental Streaming SIMD Extensions 3
87 # sse41 = yes/no --- -msse4.1 --- Use Intel Streaming SIMD Extensions 4.1
88 # avx2 = yes/no --- -mavx2 --- Use Intel Advanced Vector Extensions 2
89 # avxvnni = yes/no --- -mavxvnni --- Use Intel Vector Neural Network Instructions AVX
90 # avx512 = yes/no --- -mavx512bw --- Use Intel Advanced Vector Extensions 512
91 # vnni256 = yes/no --- -mavx256vnni --- Use Intel Vector Neural Network Instructions 512 with 256bit operands
92 # vnni512 = yes/no --- -mavx512vnni --- Use Intel Vector Neural Network Instructions 512
93 # neon = yes/no --- -DUSE_NEON --- Use ARM SIMD architecture
94 # dotprod = yes/no --- -DUSE_NEON_DOTPROD --- Use ARM advanced SIMD Int8 dot product instructions
96 # Note that Makefile is space sensitive, so when adding new architectures
97 # or modifying existing flags, you have to make sure there are no extra spaces
98 # at the end of the line for flag values.
100 # Example of use for these flags:
101 # make build ARCH=x86-64-avx512 debug=yes sanitize="address undefined"
104 ### 2.1. General and architecture defaults
108 help_skip_sanity = yes
110 # explicitly check for the list of supported architectures (as listed with make help),
111 # the user can override with `make ARCH=x86-32-vnni256 SUPPORTED_ARCH=true`
112 ifeq ($(ARCH), $(filter $(ARCH), \
113 x86-64-vnni512 x86-64-vnni256 x86-64-avx512 x86-64-avxvnni x86-64-bmi2 \
114 x86-64-avx2 x86-64-sse41-popcnt x86-64-modern x86-64-ssse3 x86-64-sse3-popcnt \
115 x86-64 x86-32-sse41-popcnt x86-32-sse2 x86-32 ppc-64 ppc-32 e2k \
116 armv7 armv7-neon armv8 armv8-dotprod apple-silicon general-64 general-32 riscv64))
144 ### 2.2 Architecture specific
146 ifeq ($(findstring x86,$(ARCH)),x86)
150 ifeq ($(findstring x86-32,$(ARCH)),x86-32)
161 ifeq ($(findstring -sse,$(ARCH)),-sse)
165 ifeq ($(findstring -popcnt,$(ARCH)),-popcnt)
169 ifeq ($(findstring -mmx,$(ARCH)),-mmx)
173 ifeq ($(findstring -sse2,$(ARCH)),-sse2)
178 ifeq ($(findstring -ssse3,$(ARCH)),-ssse3)
184 ifeq ($(findstring -sse41,$(ARCH)),-sse41)
191 ifeq ($(findstring -modern,$(ARCH)),-modern)
199 ifeq ($(findstring -avx2,$(ARCH)),-avx2)
208 ifeq ($(findstring -avxvnni,$(ARCH)),-avxvnni)
219 ifeq ($(findstring -bmi2,$(ARCH)),-bmi2)
229 ifeq ($(findstring -avx512,$(ARCH)),-avx512)
240 ifeq ($(findstring -vnni256,$(ARCH)),-vnni256)
251 ifeq ($(findstring -vnni512,$(ARCH)),-vnni512)
267 # 64-bit pext is not available on x86-32
274 # all other architectures
276 ifeq ($(ARCH),general-32)
281 ifeq ($(ARCH),general-64)
292 ifeq ($(ARCH),armv7-neon)
309 ifeq ($(ARCH),armv8-dotprod)
318 ifeq ($(ARCH),apple-silicon)
327 ifeq ($(ARCH),ppc-32)
332 ifeq ($(ARCH),ppc-64)
338 ifeq ($(findstring e2k,$(ARCH)),e2k)
349 ifeq ($(ARCH),riscv64)
355 ### ==========================================================================
356 ### Section 3. Low-level Configuration
357 ### ==========================================================================
359 ### 3.1 Selecting compiler (default = gcc)
360 ifeq ($(MAKELEVEL),0)
361 export ENV_CXXFLAGS := $(CXXFLAGS)
362 export ENV_DEPENDFLAGS := $(DEPENDFLAGS)
363 export ENV_LDFLAGS := $(LDFLAGS)
366 CXXFLAGS = $(ENV_CXXFLAGS) -Wall -Wcast-qual -fno-exceptions -std=c++17 $(EXTRACXXFLAGS)
367 DEPENDFLAGS = $(ENV_DEPENDFLAGS) -std=c++17
368 LDFLAGS = $(ENV_LDFLAGS) $(EXTRALDFLAGS)
377 CXXFLAGS += -pedantic -Wextra -Wshadow -Wmissing-declarations
379 ifeq ($(arch),$(filter $(arch),armv7 armv8 riscv64))
381 CXXFLAGS += -m$(bits)
384 ifeq ($(ARCH),riscv64)
388 CXXFLAGS += -m$(bits)
392 ifeq ($(arch),$(filter $(arch),armv7))
396 ifneq ($(KERNEL),Darwin)
397 LDFLAGS += -Wl,--no-as-needed
401 ifeq ($(target_windows),yes)
409 ifeq ($(shell which x86_64-w64-mingw32-c++-posix 2> /dev/null),)
410 CXX=x86_64-w64-mingw32-c++
412 CXX=x86_64-w64-mingw32-c++-posix
415 ifeq ($(shell which i686-w64-mingw32-c++-posix 2> /dev/null),)
416 CXX=i686-w64-mingw32-c++
418 CXX=i686-w64-mingw32-c++-posix
421 CXXFLAGS += -pedantic -Wextra -Wshadow -Wmissing-declarations
427 CXXFLAGS += --intel -pedantic -Wextra -Wshadow -Wmissing-prototypes \
428 -Wconditional-uninitialized -Wabi -Wdeprecated
434 ifeq ($(target_windows),yes)
435 CXX=x86_64-w64-mingw32-clang++
438 CXXFLAGS += -pedantic -Wextra -Wshadow -Wmissing-prototypes \
439 -Wconditional-uninitialized
441 ifeq ($(filter $(KERNEL),Darwin OpenBSD FreeBSD),)
442 ifeq ($(target_windows),)
443 ifneq ($(RTLIB),compiler-rt)
449 ifeq ($(arch),$(filter $(arch),armv7 armv8 riscv64))
451 CXXFLAGS += -m$(bits)
454 ifeq ($(ARCH),riscv64)
458 CXXFLAGS += -m$(bits)
463 ifeq ($(KERNEL),Darwin)
464 CXXFLAGS += -mmacosx-version-min=10.14
465 LDFLAGS += -mmacosx-version-min=10.14
467 CXXFLAGS += -arch $(arch)
468 LDFLAGS += -arch $(arch)
473 # To cross-compile for Android, NDK version r21 or later is recommended.
474 # In earlier NDK versions, you'll need to pass -fno-addrsig if using GNU binutils.
475 # Currently we don't know how to make PGO builds with the NDK yet.
477 CXXFLAGS += -stdlib=libc++ -fPIE
480 CXX=armv7a-linux-androideabi16-clang++
481 CXXFLAGS += -mthumb -march=armv7-a -mfloat-abi=softfp -mfpu=neon
482 ifneq ($(shell which arm-linux-androideabi-strip 2>/dev/null),)
483 STRIP=arm-linux-androideabi-strip
489 CXX=aarch64-linux-android21-clang++
490 ifneq ($(shell which aarch64-linux-android-strip 2>/dev/null),)
491 STRIP=aarch64-linux-android-strip
496 LDFLAGS += -static-libstdc++ -pie -lm -latomic
500 profile_make = icx-profile-make
501 profile_use = icx-profile-use
502 else ifeq ($(comp),clang)
503 profile_make = clang-profile-make
504 profile_use = clang-profile-use
506 profile_make = gcc-profile-make
507 profile_use = gcc-profile-use
508 ifeq ($(KERNEL),Darwin)
509 EXTRAPROFILEFLAGS = -fvisibility=hidden
513 ### Travis CI script uses COMPILER to overwrite CXX
518 ### Allow overwriting CXX from command line
523 ### Sometimes gcc is really clang
525 gccversion = $(shell $(CXX) --version 2>/dev/null)
526 gccisclang = $(findstring clang,$(gccversion))
527 ifneq ($(gccisclang),)
528 profile_make = clang-profile-make
529 profile_use = clang-profile-use
533 ### On mingw use Windows threads, otherwise POSIX
534 ifneq ($(comp),mingw)
535 CXXFLAGS += -DUSE_PTHREADS
536 # On Android Bionic's C library comes with its own pthread implementation bundled in
537 ifneq ($(OS),Android)
538 # Haiku has pthreads in its libroot, so only link it in on other platforms
539 ifneq ($(KERNEL),Haiku)
554 ### 3.2.2 Debugging with undefined behavior sanitizers
555 ifneq ($(sanitize),none)
556 CXXFLAGS += -g3 $(addprefix -fsanitize=,$(sanitize))
557 LDFLAGS += $(addprefix -fsanitize=,$(sanitize))
561 ifeq ($(optimize),yes)
566 ifeq ($(OS), Android)
567 CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
571 ifeq ($(KERNEL),Darwin)
572 ifeq ($(comp),$(filter $(comp),clang icx))
573 CXXFLAGS += -mdynamic-no-pic
577 ifneq ($(arch),arm64)
578 CXXFLAGS += -mdynamic-no-pic
584 clangmajorversion = $(shell $(CXX) -dumpversion 2>/dev/null | cut -f1 -d.)
585 ifeq ($(shell expr $(clangmajorversion) \< 16),1)
586 CXXFLAGS += -fexperimental-new-pass-manager
593 CXXFLAGS += -DIS_64BIT
596 ### 3.5 prefetch and popcount
597 ifeq ($(prefetch),yes)
602 CXXFLAGS += -DNO_PREFETCH
606 ifeq ($(arch),$(filter $(arch),ppc64 armv7 armv8 arm64))
607 CXXFLAGS += -DUSE_POPCNT
609 CXXFLAGS += -msse3 -mpopcnt -DUSE_POPCNT
613 ### 3.6 SIMD architectures
615 CXXFLAGS += -DUSE_AVX2
616 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
617 CXXFLAGS += -mavx2 -mbmi
621 ifeq ($(avxvnni),yes)
622 CXXFLAGS += -DUSE_VNNI -DUSE_AVXVNNI
623 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
624 CXXFLAGS += -mavxvnni
629 CXXFLAGS += -DUSE_AVX512
630 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
631 CXXFLAGS += -mavx512f -mavx512bw
635 ifeq ($(vnni256),yes)
636 CXXFLAGS += -DUSE_VNNI
637 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
638 CXXFLAGS += -mavx512f -mavx512bw -mavx512vnni -mavx512dq -mavx512vl -mprefer-vector-width=256
642 ifeq ($(vnni512),yes)
643 CXXFLAGS += -DUSE_VNNI
644 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
645 CXXFLAGS += -mavx512f -mavx512bw -mavx512vnni -mavx512dq -mavx512vl -mprefer-vector-width=512
650 CXXFLAGS += -DUSE_SSE41
651 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
657 CXXFLAGS += -DUSE_SSSE3
658 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
664 CXXFLAGS += -DUSE_SSE2
665 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
671 CXXFLAGS += -DUSE_MMX
672 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
678 CXXFLAGS += -DUSE_NEON=$(arm_version)
679 ifeq ($(KERNEL),Linux)
681 ifneq ($(arch),armv8)
682 CXXFLAGS += -mfpu=neon
688 ifeq ($(dotprod),yes)
689 CXXFLAGS += -march=armv8.2-a+dotprod -DUSE_NEON_DOTPROD
694 CXXFLAGS += -DUSE_PEXT
695 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
700 ### 3.7.1 Try to include git commit sha for versioning
701 GIT_SHA = $(shell git rev-parse HEAD 2>/dev/null | cut -c 1-8)
703 CXXFLAGS += -DGIT_SHA=$(GIT_SHA)
706 ### 3.7.2 Try to include git commit date for versioning
707 GIT_DATE = $(shell git show -s --date=format:'%Y%m%d' --format=%cd HEAD 2>/dev/null)
708 ifneq ($(GIT_DATE), )
709 CXXFLAGS += -DGIT_DATE=$(GIT_DATE)
712 ### 3.8 Link Time Optimization
713 ### This is a mix of compile and link time options because the lto link phase
714 ### needs access to the optimization flags.
715 ifeq ($(optimize),yes)
717 ifeq ($(comp),$(filter $(comp),clang icx))
718 CXXFLAGS += -flto=full
720 CXXFLAGS += -fwhole-program-vtables
722 ifeq ($(target_windows),yes)
723 CXXFLAGS += -fuse-ld=lld
725 LDFLAGS += $(CXXFLAGS)
727 # GCC and CLANG use different methods for parallelizing LTO and CLANG pretends to be
728 # GCC on some systems.
729 else ifeq ($(comp),gcc)
730 ifeq ($(gccisclang),)
731 CXXFLAGS += -flto -flto-partition=one
732 LDFLAGS += $(CXXFLAGS) -flto=jobserver
734 CXXFLAGS += -flto=full
735 LDFLAGS += $(CXXFLAGS)
738 # To use LTO and static linking on Windows,
739 # the tool chain requires gcc version 10.1 or later.
740 else ifeq ($(comp),mingw)
741 CXXFLAGS += -flto -flto-partition=one
742 LDFLAGS += $(CXXFLAGS) -save-temps
747 ### 3.9 Android 5 can only run position independent executables. Note that this
748 ### breaks Android 4.0 and earlier.
749 ifeq ($(OS), Android)
751 LDFLAGS += -fPIE -pie
754 ### ==========================================================================
755 ### Section 4. Public Targets
756 ### ==========================================================================
761 @echo "To compile stockfish, type: "
763 @echo "make target ARCH=arch [COMP=compiler] [COMPCXX=cxx]"
765 @echo "Supported targets:"
767 @echo "help > Display architecture details"
768 @echo "profile-build > standard build with profile-guided optimization"
769 @echo "build > skip profile-guided optimization"
770 @echo "net > Download the default nnue net"
771 @echo "strip > Strip executable"
772 @echo "install > Install executable"
773 @echo "clean > Clean up"
775 @echo "Supported archs:"
777 @echo "x86-64-vnni512 > x86 64-bit with vnni 512bit support"
778 @echo "x86-64-vnni256 > x86 64-bit with vnni 512bit support, limit operands to 256bit wide"
779 @echo "x86-64-avx512 > x86 64-bit with avx512 support"
780 @echo "x86-64-avxvnni > x86 64-bit with vnni 256bit support"
781 @echo "x86-64-bmi2 > x86 64-bit with bmi2 support"
782 @echo "x86-64-avx2 > x86 64-bit with avx2 support"
783 @echo "x86-64-sse41-popcnt > x86 64-bit with sse41 and popcnt support"
784 @echo "x86-64-modern > common modern CPU, currently x86-64-sse41-popcnt"
785 @echo "x86-64-ssse3 > x86 64-bit with ssse3 support"
786 @echo "x86-64-sse3-popcnt > x86 64-bit with sse3 and popcnt support"
787 @echo "x86-64 > x86 64-bit generic (with sse2 support)"
788 @echo "x86-32-sse41-popcnt > x86 32-bit with sse41 and popcnt support"
789 @echo "x86-32-sse2 > x86 32-bit with sse2 support"
790 @echo "x86-32 > x86 32-bit generic (with mmx and sse support)"
791 @echo "ppc-64 > PPC 64-bit"
792 @echo "ppc-32 > PPC 32-bit"
793 @echo "armv7 > ARMv7 32-bit"
794 @echo "armv7-neon > ARMv7 32-bit with popcnt and neon"
795 @echo "armv8 > ARMv8 64-bit with popcnt and neon"
796 @echo "armv8-dotprod > ARMv8 64-bit with popcnt, neon and dot product support"
797 @echo "e2k > Elbrus 2000"
798 @echo "apple-silicon > Apple silicon ARM64"
799 @echo "general-64 > unspecified 64-bit"
800 @echo "general-32 > unspecified 32-bit"
801 @echo "riscv64 > RISC-V 64-bit"
803 @echo "Supported compilers:"
805 @echo "gcc > Gnu compiler (default)"
806 @echo "mingw > Gnu compiler with MinGW under Windows"
807 @echo "clang > LLVM Clang compiler"
808 @echo "icx > Intel oneAPI DPC++/C++ Compiler"
809 @echo "ndk > Google NDK to cross-compile for Android"
811 @echo "Simple examples. If you don't know what to do, you likely want to run one of: "
813 @echo "make -j profile-build ARCH=x86-64-avx2 # typically a fast compile for common systems "
814 @echo "make -j profile-build ARCH=x86-64-modern # A more portable compile for 64-bit systems "
815 @echo "make -j profile-build ARCH=x86-64 # A portable compile for 64-bit systems "
817 @echo "Advanced examples, for experienced users: "
819 @echo "make -j profile-build ARCH=x86-64-bmi2"
820 @echo "make -j profile-build ARCH=x86-64-bmi2 COMP=gcc COMPCXX=g++-9.0"
821 @echo "make -j build ARCH=x86-64-ssse3 COMP=clang"
823 @echo "-------------------------------"
824 ifeq ($(SUPPORTED_ARCH)$(help_skip_sanity), true)
825 @echo "The selected architecture $(ARCH) will enable the following configuration: "
826 @$(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
828 @echo "Specify a supported architecture with the ARCH option for more details"
833 .PHONY: help build profile-build strip install clean net objclean profileclean \
835 icx-profile-use icx-profile-make \
836 gcc-profile-use gcc-profile-make \
837 clang-profile-use clang-profile-make FORCE
839 build: net config-sanity
840 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
842 profile-build: net config-sanity objclean profileclean
844 @echo "Step 1/4. Building instrumented executable ..."
845 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
847 @echo "Step 2/4. Running benchmark for pgo-build ..."
848 $(PGOBENCH) > PGOBENCH.out 2>&1
849 tail -n 4 PGOBENCH.out
851 @echo "Step 3/4. Building optimized executable ..."
852 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) objclean
853 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
855 @echo "Step 4/4. Deleting profile data ..."
856 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) profileclean
862 -mkdir -p -m 755 $(BINDIR)
864 $(STRIP) $(BINDIR)/$(EXE)
867 clean: objclean profileclean
868 @rm -f .depend *~ core
870 # evaluation network (nnue)
872 $(eval nnuenet := $(shell grep EvalFileDefaultName evaluate.h | grep define | sed 's/.*\(nn-[a-z0-9]\{12\}.nnue\).*/\1/'))
873 @echo "Default net: $(nnuenet)"
874 $(eval nnuedownloadurl1 := https://tests.stockfishchess.org/api/nn/$(nnuenet))
875 $(eval nnuedownloadurl2 := https://github.com/official-stockfish/networks/raw/master/$(nnuenet))
876 $(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))
877 @if [ "x$(curl_or_wget)" = "x" ]; then \
878 echo "Neither curl nor wget is installed. Install one of these tools unless the net has been downloaded manually"; \
880 $(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))
881 @if [ "x$(shasum_command)" = "x" ]; then \
882 echo "shasum / sha256sum not found, skipping net validation"; \
884 @for nnuedownloadurl in "$(nnuedownloadurl1)" "$(nnuedownloadurl2)"; do \
885 if test -f "$(nnuenet)"; then \
886 echo "$(nnuenet) available."; \
888 if [ "x$(curl_or_wget)" != "x" ]; then \
889 echo "Downloading $${nnuedownloadurl}"; $(curl_or_wget) $${nnuedownloadurl} > $(nnuenet);\
891 echo "No net found and download not possible"; exit 1;\
894 if [ "x$(shasum_command)" != "x" ]; then \
895 if [ "$(nnuenet)" != "nn-"`$(shasum_command) $(nnuenet) | cut -c1-12`".nnue" ]; then \
896 echo "Removing failed download"; rm -f $(nnuenet); \
898 echo "Network validated"; break; \
902 @if ! test -f "$(nnuenet)"; then \
903 echo "Failed to download $(nnuenet)."; \
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
923 ### ==========================================================================
924 ### Section 5. Private Targets
925 ### ==========================================================================
932 @echo "debug: '$(debug)'"
933 @echo "sanitize: '$(sanitize)'"
934 @echo "optimize: '$(optimize)'"
935 @echo "arch: '$(arch)'"
936 @echo "bits: '$(bits)'"
937 @echo "kernel: '$(KERNEL)'"
939 @echo "prefetch: '$(prefetch)'"
940 @echo "popcnt: '$(popcnt)'"
941 @echo "pext: '$(pext)'"
942 @echo "sse: '$(sse)'"
943 @echo "mmx: '$(mmx)'"
944 @echo "sse2: '$(sse2)'"
945 @echo "ssse3: '$(ssse3)'"
946 @echo "sse41: '$(sse41)'"
947 @echo "avx2: '$(avx2)'"
948 @echo "avxvnni: '$(avxvnni)'"
949 @echo "avx512: '$(avx512)'"
950 @echo "vnni256: '$(vnni256)'"
951 @echo "vnni512: '$(vnni512)'"
952 @echo "neon: '$(neon)'"
953 @echo "dotprod: '$(dotprod)'"
954 @echo "arm_version: '$(arm_version)'"
955 @echo "target_windows: '$(target_windows)'"
959 @echo "CXXFLAGS: $(CXXFLAGS)"
960 @echo "LDFLAGS: $(LDFLAGS)"
962 @echo "Testing config sanity. If this fails, try 'make help' ..."
964 @test "$(debug)" = "yes" || test "$(debug)" = "no"
965 @test "$(optimize)" = "yes" || test "$(optimize)" = "no"
966 @test "$(SUPPORTED_ARCH)" = "true"
967 @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
968 test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "e2k" || \
969 test "$(arch)" = "armv7" || test "$(arch)" = "armv8" || test "$(arch)" = "arm64" || test "$(arch)" = "riscv64"
970 @test "$(bits)" = "32" || test "$(bits)" = "64"
971 @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
972 @test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
973 @test "$(pext)" = "yes" || test "$(pext)" = "no"
974 @test "$(sse)" = "yes" || test "$(sse)" = "no"
975 @test "$(mmx)" = "yes" || test "$(mmx)" = "no"
976 @test "$(sse2)" = "yes" || test "$(sse2)" = "no"
977 @test "$(ssse3)" = "yes" || test "$(ssse3)" = "no"
978 @test "$(sse41)" = "yes" || test "$(sse41)" = "no"
979 @test "$(avx2)" = "yes" || test "$(avx2)" = "no"
980 @test "$(avx512)" = "yes" || test "$(avx512)" = "no"
981 @test "$(vnni256)" = "yes" || test "$(vnni256)" = "no"
982 @test "$(vnni512)" = "yes" || test "$(vnni512)" = "no"
983 @test "$(neon)" = "yes" || test "$(neon)" = "no"
984 @test "$(comp)" = "gcc" || test "$(comp)" = "icx" || test "$(comp)" = "mingw" || test "$(comp)" = "clang" \
985 || test "$(comp)" = "armv7a-linux-androideabi16-clang" || test "$(comp)" = "aarch64-linux-android21-clang"
988 +$(CXX) -o $@ $(OBJS) $(LDFLAGS)
990 # Force recompilation to ensure version info is up-to-date
995 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
996 EXTRACXXFLAGS='-fprofile-instr-generate ' \
997 EXTRALDFLAGS=' -fprofile-instr-generate' \
1001 $(XCRUN) llvm-profdata merge -output=stockfish.profdata *.profraw
1002 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1003 EXTRACXXFLAGS='-fprofile-instr-use=stockfish.profdata' \
1004 EXTRALDFLAGS='-fprofile-use ' \
1009 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1010 EXTRACXXFLAGS='-fprofile-generate=profdir' \
1011 EXTRACXXFLAGS+=$(EXTRAPROFILEFLAGS) \
1012 EXTRALDFLAGS='-lgcov' \
1016 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1017 EXTRACXXFLAGS='-fprofile-use=profdir -fno-peel-loops -fno-tracer' \
1018 EXTRACXXFLAGS+=$(EXTRAPROFILEFLAGS) \
1019 EXTRALDFLAGS='-lgcov' \
1023 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1024 EXTRACXXFLAGS='-fprofile-instr-generate ' \
1025 EXTRALDFLAGS=' -fprofile-instr-generate' \
1029 $(XCRUN) llvm-profdata merge -output=stockfish.profdata *.profraw
1030 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1031 EXTRACXXFLAGS='-fprofile-instr-use=stockfish.profdata' \
1032 EXTRALDFLAGS='-fprofile-use ' \
1036 -@$(CXX) $(DEPENDFLAGS) -MM $(SRCS) > $@ 2> /dev/null
1038 ifeq (, $(filter $(MAKECMDGOALS), help strip install clean net objclean profileclean config-sanity))