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 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
110 ifeq ($(ARCH), native)
111 override ARCH = $(shell ../scripts/get_native_properties.sh | cut -d " " -f 1)
114 # explicitly check for the list of supported architectures (as listed with make help),
115 # the user can override with `make ARCH=x86-32-vnni256 SUPPORTED_ARCH=true`
116 ifeq ($(ARCH), $(filter $(ARCH), \
117 x86-64-vnni512 x86-64-vnni256 x86-64-avx512 x86-64-avxvnni x86-64-bmi2 \
118 x86-64-avx2 x86-64-sse41-popcnt x86-64-modern x86-64-ssse3 x86-64-sse3-popcnt \
119 x86-64 x86-32-sse41-popcnt x86-32-sse2 x86-32 ppc-64 ppc-32 e2k \
120 armv7 armv7-neon armv8 armv8-dotprod apple-silicon general-64 general-32 riscv64))
148 ### 2.2 Architecture specific
150 ifeq ($(findstring x86,$(ARCH)),x86)
154 ifeq ($(findstring x86-32,$(ARCH)),x86-32)
165 ifeq ($(findstring -sse,$(ARCH)),-sse)
169 ifeq ($(findstring -popcnt,$(ARCH)),-popcnt)
173 ifeq ($(findstring -mmx,$(ARCH)),-mmx)
177 ifeq ($(findstring -sse2,$(ARCH)),-sse2)
182 ifeq ($(findstring -ssse3,$(ARCH)),-ssse3)
188 ifeq ($(findstring -sse41,$(ARCH)),-sse41)
195 ifeq ($(findstring -modern,$(ARCH)),-modern)
196 $(warning *** ARCH=$(ARCH) is deprecated, defaulting to ARCH=x86-64-sse41-popcnt. Execute `make help` for a list of available architectures. ***)
205 ifeq ($(findstring -avx2,$(ARCH)),-avx2)
214 ifeq ($(findstring -avxvnni,$(ARCH)),-avxvnni)
225 ifeq ($(findstring -bmi2,$(ARCH)),-bmi2)
235 ifeq ($(findstring -avx512,$(ARCH)),-avx512)
246 ifeq ($(findstring -vnni256,$(ARCH)),-vnni256)
257 ifeq ($(findstring -vnni512,$(ARCH)),-vnni512)
273 # 64-bit pext is not available on x86-32
280 # all other architectures
282 ifeq ($(ARCH),general-32)
287 ifeq ($(ARCH),general-64)
298 ifeq ($(ARCH),armv7-neon)
315 ifeq ($(ARCH),armv8-dotprod)
324 ifeq ($(ARCH),apple-silicon)
333 ifeq ($(ARCH),ppc-32)
338 ifeq ($(ARCH),ppc-64)
344 ifeq ($(findstring e2k,$(ARCH)),e2k)
355 ifeq ($(ARCH),riscv64)
361 ### ==========================================================================
362 ### Section 3. Low-level Configuration
363 ### ==========================================================================
365 ### 3.1 Selecting compiler (default = gcc)
366 ifeq ($(MAKELEVEL),0)
367 export ENV_CXXFLAGS := $(CXXFLAGS)
368 export ENV_DEPENDFLAGS := $(DEPENDFLAGS)
369 export ENV_LDFLAGS := $(LDFLAGS)
372 CXXFLAGS = $(ENV_CXXFLAGS) -Wall -Wcast-qual -fno-exceptions -std=c++17 $(EXTRACXXFLAGS)
373 DEPENDFLAGS = $(ENV_DEPENDFLAGS) -std=c++17
374 LDFLAGS = $(ENV_LDFLAGS) $(EXTRALDFLAGS)
383 CXXFLAGS += -pedantic -Wextra -Wshadow -Wmissing-declarations
385 ifeq ($(arch),$(filter $(arch),armv7 armv8 riscv64))
387 CXXFLAGS += -m$(bits)
390 ifeq ($(ARCH),riscv64)
394 CXXFLAGS += -m$(bits)
398 ifeq ($(arch),$(filter $(arch),armv7))
402 ifneq ($(KERNEL),Darwin)
403 LDFLAGS += -Wl,--no-as-needed
407 ifeq ($(target_windows),yes)
415 ifeq ($(shell which x86_64-w64-mingw32-c++-posix 2> /dev/null),)
416 CXX=x86_64-w64-mingw32-c++
418 CXX=x86_64-w64-mingw32-c++-posix
421 ifeq ($(shell which i686-w64-mingw32-c++-posix 2> /dev/null),)
422 CXX=i686-w64-mingw32-c++
424 CXX=i686-w64-mingw32-c++-posix
427 CXXFLAGS += -pedantic -Wextra -Wshadow -Wmissing-declarations
433 CXXFLAGS += --intel -pedantic -Wextra -Wshadow -Wmissing-prototypes \
434 -Wconditional-uninitialized -Wabi -Wdeprecated
440 ifeq ($(target_windows),yes)
441 CXX=x86_64-w64-mingw32-clang++
444 CXXFLAGS += -pedantic -Wextra -Wshadow -Wmissing-prototypes \
445 -Wconditional-uninitialized
447 ifeq ($(filter $(KERNEL),Darwin OpenBSD FreeBSD),)
448 ifeq ($(target_windows),)
449 ifneq ($(RTLIB),compiler-rt)
455 ifeq ($(arch),$(filter $(arch),armv7 armv8 riscv64))
457 CXXFLAGS += -m$(bits)
460 ifeq ($(ARCH),riscv64)
464 CXXFLAGS += -m$(bits)
469 ifeq ($(KERNEL),Darwin)
470 CXXFLAGS += -mmacosx-version-min=10.14
471 LDFLAGS += -mmacosx-version-min=10.14
473 CXXFLAGS += -arch $(arch)
474 LDFLAGS += -arch $(arch)
479 # To cross-compile for Android, NDK version r21 or later is recommended.
480 # In earlier NDK versions, you'll need to pass -fno-addrsig if using GNU binutils.
481 # Currently we don't know how to make PGO builds with the NDK yet.
483 CXXFLAGS += -stdlib=libc++ -fPIE
486 CXX=armv7a-linux-androideabi16-clang++
487 CXXFLAGS += -mthumb -march=armv7-a -mfloat-abi=softfp -mfpu=neon
488 ifneq ($(shell which arm-linux-androideabi-strip 2>/dev/null),)
489 STRIP=arm-linux-androideabi-strip
495 CXX=aarch64-linux-android21-clang++
496 ifneq ($(shell which aarch64-linux-android-strip 2>/dev/null),)
497 STRIP=aarch64-linux-android-strip
502 LDFLAGS += -static-libstdc++ -pie -lm -latomic
506 profile_make = icx-profile-make
507 profile_use = icx-profile-use
508 else ifeq ($(comp),clang)
509 profile_make = clang-profile-make
510 profile_use = clang-profile-use
512 profile_make = gcc-profile-make
513 profile_use = gcc-profile-use
514 ifeq ($(KERNEL),Darwin)
515 EXTRAPROFILEFLAGS = -fvisibility=hidden
519 ### Travis CI script uses COMPILER to overwrite CXX
524 ### Allow overwriting CXX from command line
529 ### Sometimes gcc is really clang
531 gccversion = $(shell $(CXX) --version 2>/dev/null)
532 gccisclang = $(findstring clang,$(gccversion))
533 ifneq ($(gccisclang),)
534 profile_make = clang-profile-make
535 profile_use = clang-profile-use
539 ### On mingw use Windows threads, otherwise POSIX
540 ifneq ($(comp),mingw)
541 CXXFLAGS += -DUSE_PTHREADS
542 # On Android Bionic's C library comes with its own pthread implementation bundled in
543 ifneq ($(OS),Android)
544 # Haiku has pthreads in its libroot, so only link it in on other platforms
545 ifneq ($(KERNEL),Haiku)
560 ### 3.2.2 Debugging with undefined behavior sanitizers
561 ifneq ($(sanitize),none)
562 CXXFLAGS += -g3 $(addprefix -fsanitize=,$(sanitize))
563 LDFLAGS += $(addprefix -fsanitize=,$(sanitize))
567 ifeq ($(optimize),yes)
569 CXXFLAGS += -O3 -funroll-loops
572 ifeq ($(OS), Android)
573 CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
577 ifeq ($(KERNEL),Darwin)
578 ifeq ($(comp),$(filter $(comp),clang icx))
579 CXXFLAGS += -mdynamic-no-pic
583 ifneq ($(arch),arm64)
584 CXXFLAGS += -mdynamic-no-pic
590 clangmajorversion = $(shell $(CXX) -dumpversion 2>/dev/null | cut -f1 -d.)
591 ifeq ($(shell expr $(clangmajorversion) \< 16),1)
592 CXXFLAGS += -fexperimental-new-pass-manager
599 CXXFLAGS += -DIS_64BIT
602 ### 3.5 prefetch and popcount
603 ifeq ($(prefetch),yes)
608 CXXFLAGS += -DNO_PREFETCH
612 ifeq ($(arch),$(filter $(arch),ppc64 armv7 armv8 arm64))
613 CXXFLAGS += -DUSE_POPCNT
615 CXXFLAGS += -msse3 -mpopcnt -DUSE_POPCNT
619 ### 3.6 SIMD architectures
621 CXXFLAGS += -DUSE_AVX2
622 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
623 CXXFLAGS += -mavx2 -mbmi
627 ifeq ($(avxvnni),yes)
628 CXXFLAGS += -DUSE_VNNI -DUSE_AVXVNNI
629 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
630 CXXFLAGS += -mavxvnni
635 CXXFLAGS += -DUSE_AVX512
636 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
637 CXXFLAGS += -mavx512f -mavx512bw
641 ifeq ($(vnni256),yes)
642 CXXFLAGS += -DUSE_VNNI
643 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
644 CXXFLAGS += -mavx512f -mavx512bw -mavx512vnni -mavx512dq -mavx512vl -mprefer-vector-width=256
648 ifeq ($(vnni512),yes)
649 CXXFLAGS += -DUSE_VNNI
650 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
651 CXXFLAGS += -mavx512f -mavx512bw -mavx512vnni -mavx512dq -mavx512vl -mprefer-vector-width=512
656 CXXFLAGS += -DUSE_SSE41
657 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
663 CXXFLAGS += -DUSE_SSSE3
664 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
670 CXXFLAGS += -DUSE_SSE2
671 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
677 CXXFLAGS += -DUSE_MMX
678 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
684 CXXFLAGS += -DUSE_NEON=$(arm_version)
685 ifeq ($(KERNEL),Linux)
687 ifneq ($(arch),armv8)
688 CXXFLAGS += -mfpu=neon
694 ifeq ($(dotprod),yes)
695 CXXFLAGS += -march=armv8.2-a+dotprod -DUSE_NEON_DOTPROD
700 CXXFLAGS += -DUSE_PEXT
701 ifeq ($(comp),$(filter $(comp),gcc clang mingw icx))
706 ### 3.7.1 Try to include git commit sha for versioning
707 GIT_SHA = $(shell git rev-parse HEAD 2>/dev/null | cut -c 1-8)
709 CXXFLAGS += -DGIT_SHA=$(GIT_SHA)
712 ### 3.7.2 Try to include git commit date for versioning
713 GIT_DATE = $(shell git show -s --date=format:'%Y%m%d' --format=%cd HEAD 2>/dev/null)
714 ifneq ($(GIT_DATE), )
715 CXXFLAGS += -DGIT_DATE=$(GIT_DATE)
718 ### 3.7.3 Try to include architecture
720 CXXFLAGS += -DARCH=$(ARCH)
723 ### 3.8 Link Time Optimization
724 ### This is a mix of compile and link time options because the lto link phase
725 ### needs access to the optimization flags.
726 ifeq ($(optimize),yes)
728 ifeq ($(comp),$(filter $(comp),clang icx))
729 CXXFLAGS += -flto=full
731 CXXFLAGS += -fwhole-program-vtables
733 ifeq ($(target_windows),yes)
734 CXXFLAGS += -fuse-ld=lld
736 LDFLAGS += $(CXXFLAGS)
738 # GCC and CLANG use different methods for parallelizing LTO and CLANG pretends to be
739 # GCC on some systems.
740 else ifeq ($(comp),gcc)
741 ifeq ($(gccisclang),)
742 CXXFLAGS += -flto -flto-partition=one
743 LDFLAGS += $(CXXFLAGS) -flto=jobserver
745 CXXFLAGS += -flto=full
746 LDFLAGS += $(CXXFLAGS)
749 # To use LTO and static linking on Windows,
750 # the tool chain requires gcc version 10.1 or later.
751 else ifeq ($(comp),mingw)
752 CXXFLAGS += -flto -flto-partition=one
753 LDFLAGS += $(CXXFLAGS) -save-temps
758 ### 3.9 Android 5 can only run position independent executables. Note that this
759 ### breaks Android 4.0 and earlier.
760 ifeq ($(OS), Android)
762 LDFLAGS += -fPIE -pie
765 ### ==========================================================================
766 ### Section 4. Public Targets
767 ### ==========================================================================
771 @echo "To compile stockfish, type: "
773 @echo "make -j target [ARCH=arch] [COMP=compiler] [COMPCXX=cxx]"
775 @echo "Supported targets:"
777 @echo "help > Display architecture details"
778 @echo "profile-build > standard build with profile-guided optimization"
779 @echo "build > skip profile-guided optimization"
780 @echo "net > Download the default nnue net"
781 @echo "strip > Strip executable"
782 @echo "install > Install executable"
783 @echo "clean > Clean up"
785 @echo "Supported archs:"
787 @echo "native > select the best architecture for the host processor (default)"
788 @echo "x86-64-vnni512 > x86 64-bit with vnni 512bit support"
789 @echo "x86-64-vnni256 > x86 64-bit with vnni 512bit support, limit operands to 256bit wide"
790 @echo "x86-64-avx512 > x86 64-bit with avx512 support"
791 @echo "x86-64-avxvnni > x86 64-bit with vnni 256bit support"
792 @echo "x86-64-bmi2 > x86 64-bit with bmi2 support"
793 @echo "x86-64-avx2 > x86 64-bit with avx2 support"
794 @echo "x86-64-sse41-popcnt > x86 64-bit with sse41 and popcnt support"
795 @echo "x86-64-modern > deprecated, currently x86-64-sse41-popcnt"
796 @echo "x86-64-ssse3 > x86 64-bit with ssse3 support"
797 @echo "x86-64-sse3-popcnt > x86 64-bit with sse3 and popcnt support"
798 @echo "x86-64 > x86 64-bit generic (with sse2 support)"
799 @echo "x86-32-sse41-popcnt > x86 32-bit with sse41 and popcnt support"
800 @echo "x86-32-sse2 > x86 32-bit with sse2 support"
801 @echo "x86-32 > x86 32-bit generic (with mmx and sse support)"
802 @echo "ppc-64 > PPC 64-bit"
803 @echo "ppc-32 > PPC 32-bit"
804 @echo "armv7 > ARMv7 32-bit"
805 @echo "armv7-neon > ARMv7 32-bit with popcnt and neon"
806 @echo "armv8 > ARMv8 64-bit with popcnt and neon"
807 @echo "armv8-dotprod > ARMv8 64-bit with popcnt, neon and dot product support"
808 @echo "e2k > Elbrus 2000"
809 @echo "apple-silicon > Apple silicon ARM64"
810 @echo "general-64 > unspecified 64-bit"
811 @echo "general-32 > unspecified 32-bit"
812 @echo "riscv64 > RISC-V 64-bit"
814 @echo "Supported compilers:"
816 @echo "gcc > GNU compiler (default)"
817 @echo "mingw > GNU compiler with MinGW under Windows"
818 @echo "clang > LLVM Clang compiler"
819 @echo "icx > Intel oneAPI DPC++/C++ Compiler"
820 @echo "ndk > Google NDK to cross-compile for Android"
822 @echo "Simple examples. If you don't know what to do, you likely want to run one of: "
824 @echo "make -j profile-build ARCH=x86-64-avx2 # typically a fast compile for common systems "
825 @echo "make -j profile-build ARCH=x86-64-sse41-popcnt # A more portable compile for 64-bit systems "
826 @echo "make -j profile-build ARCH=x86-64 # A portable compile for 64-bit systems "
828 @echo "Advanced examples, for experienced users: "
830 @echo "make -j profile-build ARCH=x86-64-avxvnni"
831 @echo "make -j profile-build ARCH=x86-64-avxvnni COMP=gcc COMPCXX=g++-12.0"
832 @echo "make -j build ARCH=x86-64-ssse3 COMP=clang"
834 ifneq ($(SUPPORTED_ARCH), true)
835 @echo "Specify a supported architecture with the ARCH option for more details"
840 .PHONY: help analyze build profile-build strip install clean net \
841 objclean profileclean config-sanity \
842 icx-profile-use icx-profile-make \
843 gcc-profile-use gcc-profile-make \
844 clang-profile-use clang-profile-make FORCE
846 analyze: net config-sanity objclean
847 $(MAKE) -k ARCH=$(ARCH) COMP=$(COMP) $(OBJS)
849 build: net config-sanity
850 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
852 profile-build: net config-sanity objclean profileclean
854 @echo "Step 1/4. Building instrumented executable ..."
855 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
857 @echo "Step 2/4. Running benchmark for pgo-build ..."
858 $(PGOBENCH) > PGOBENCH.out 2>&1
859 tail -n 4 PGOBENCH.out
861 @echo "Step 3/4. Building optimized executable ..."
862 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) objclean
863 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
865 @echo "Step 4/4. Deleting profile data ..."
866 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) profileclean
872 -mkdir -p -m 755 $(BINDIR)
874 $(STRIP) $(BINDIR)/$(EXE)
877 clean: objclean profileclean
878 @rm -f .depend *~ core
880 # clean binaries and objects
882 @rm -f stockfish stockfish.exe *.o ./syzygy/*.o ./nnue/*.o ./nnue/features/*.o
884 # clean auxiliary profiling files
887 @rm -f bench.txt *.gcda *.gcno ./syzygy/*.gcda ./nnue/*.gcda ./nnue/features/*.gcda *.s PGOBENCH.out
888 @rm -f stockfish.profdata *.profraw
889 @rm -f stockfish.*args*
890 @rm -f stockfish.*lt*
892 @rm -f ./-lstdc++.res
894 # set up shell variables for the net stuff
896 $(eval nnuenet := $(shell grep EvalFileDefaultName evaluate.h | grep define | sed 's/.*\(nn-[a-z0-9]\{12\}.nnue\).*/\1/'))
897 $(eval nnuedownloadurl1 := https://tests.stockfishchess.org/api/nn/$(nnuenet))
898 $(eval nnuedownloadurl2 := https://github.com/official-stockfish/networks/raw/master/$(nnuenet))
899 $(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))
900 $(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))
902 # evaluation network (nnue)
904 @echo "Default net: $(nnuenet)"
905 @if [ "x$(curl_or_wget)" = "x" ]; then \
906 echo "Neither curl nor wget is installed. Install one of these tools unless the net has been downloaded manually"; \
908 @if [ "x$(shasum_command)" = "x" ]; then \
909 echo "shasum / sha256sum not found, skipping net validation"; \
910 elif test -f "$(nnuenet)"; then \
911 if [ "$(nnuenet)" != "nn-"`$(shasum_command) $(nnuenet) | cut -c1-12`".nnue" ]; then \
912 echo "Removing invalid network"; rm -f $(nnuenet); \
915 @for nnuedownloadurl in "$(nnuedownloadurl1)" "$(nnuedownloadurl2)"; do \
916 if test -f "$(nnuenet)"; then \
917 echo "$(nnuenet) available : OK"; break; \
919 if [ "x$(curl_or_wget)" != "x" ]; then \
920 echo "Downloading $${nnuedownloadurl}"; $(curl_or_wget) $${nnuedownloadurl} > $(nnuenet);\
922 echo "No net found and download not possible"; exit 1;\
925 if [ "x$(shasum_command)" != "x" ]; then \
926 if [ "$(nnuenet)" != "nn-"`$(shasum_command) $(nnuenet) | cut -c1-12`".nnue" ]; then \
927 echo "Removing failed download"; rm -f $(nnuenet); \
931 @if ! test -f "$(nnuenet)"; then \
932 echo "Failed to download $(nnuenet)."; \
934 @if [ "x$(shasum_command)" != "x" ]; then \
935 if [ "$(nnuenet)" = "nn-"`$(shasum_command) $(nnuenet) | cut -c1-12`".nnue" ]; then \
936 echo "Network validated"; break; \
944 ### ==========================================================================
945 ### Section 5. Private Targets
946 ### ==========================================================================
953 @echo "debug: '$(debug)'"
954 @echo "sanitize: '$(sanitize)'"
955 @echo "optimize: '$(optimize)'"
956 @echo "arch: '$(arch)'"
957 @echo "bits: '$(bits)'"
958 @echo "kernel: '$(KERNEL)'"
960 @echo "prefetch: '$(prefetch)'"
961 @echo "popcnt: '$(popcnt)'"
962 @echo "pext: '$(pext)'"
963 @echo "sse: '$(sse)'"
964 @echo "mmx: '$(mmx)'"
965 @echo "sse2: '$(sse2)'"
966 @echo "ssse3: '$(ssse3)'"
967 @echo "sse41: '$(sse41)'"
968 @echo "avx2: '$(avx2)'"
969 @echo "avxvnni: '$(avxvnni)'"
970 @echo "avx512: '$(avx512)'"
971 @echo "vnni256: '$(vnni256)'"
972 @echo "vnni512: '$(vnni512)'"
973 @echo "neon: '$(neon)'"
974 @echo "dotprod: '$(dotprod)'"
975 @echo "arm_version: '$(arm_version)'"
976 @echo "target_windows: '$(target_windows)'"
980 @echo "CXXFLAGS: $(CXXFLAGS)"
981 @echo "LDFLAGS: $(LDFLAGS)"
983 @echo "Testing config sanity. If this fails, try 'make help' ..."
985 @test "$(debug)" = "yes" || test "$(debug)" = "no"
986 @test "$(optimize)" = "yes" || test "$(optimize)" = "no"
987 @test "$(SUPPORTED_ARCH)" = "true"
988 @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
989 test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "e2k" || \
990 test "$(arch)" = "armv7" || test "$(arch)" = "armv8" || test "$(arch)" = "arm64" || test "$(arch)" = "riscv64"
991 @test "$(bits)" = "32" || test "$(bits)" = "64"
992 @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
993 @test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
994 @test "$(pext)" = "yes" || test "$(pext)" = "no"
995 @test "$(sse)" = "yes" || test "$(sse)" = "no"
996 @test "$(mmx)" = "yes" || test "$(mmx)" = "no"
997 @test "$(sse2)" = "yes" || test "$(sse2)" = "no"
998 @test "$(ssse3)" = "yes" || test "$(ssse3)" = "no"
999 @test "$(sse41)" = "yes" || test "$(sse41)" = "no"
1000 @test "$(avx2)" = "yes" || test "$(avx2)" = "no"
1001 @test "$(avx512)" = "yes" || test "$(avx512)" = "no"
1002 @test "$(vnni256)" = "yes" || test "$(vnni256)" = "no"
1003 @test "$(vnni512)" = "yes" || test "$(vnni512)" = "no"
1004 @test "$(neon)" = "yes" || test "$(neon)" = "no"
1005 @test "$(comp)" = "gcc" || test "$(comp)" = "icx" || test "$(comp)" = "mingw" || test "$(comp)" = "clang" \
1006 || test "$(comp)" = "armv7a-linux-androideabi16-clang" || test "$(comp)" = "aarch64-linux-android21-clang"
1009 +$(CXX) -o $@ $(OBJS) $(LDFLAGS)
1011 # Force recompilation to ensure version info is up-to-date
1016 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1017 EXTRACXXFLAGS='-fprofile-instr-generate ' \
1018 EXTRALDFLAGS=' -fprofile-instr-generate' \
1022 $(XCRUN) llvm-profdata merge -output=stockfish.profdata *.profraw
1023 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1024 EXTRACXXFLAGS='-fprofile-instr-use=stockfish.profdata' \
1025 EXTRALDFLAGS='-fprofile-use ' \
1030 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1031 EXTRACXXFLAGS='-fprofile-generate=profdir' \
1032 EXTRACXXFLAGS+=$(EXTRAPROFILEFLAGS) \
1033 EXTRALDFLAGS='-lgcov' \
1037 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1038 EXTRACXXFLAGS='-fprofile-use=profdir -fno-peel-loops -fno-tracer' \
1039 EXTRACXXFLAGS+=$(EXTRAPROFILEFLAGS) \
1040 EXTRALDFLAGS='-lgcov' \
1044 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1045 EXTRACXXFLAGS='-fprofile-instr-generate ' \
1046 EXTRALDFLAGS=' -fprofile-instr-generate' \
1050 $(XCRUN) llvm-profdata merge -output=stockfish.profdata *.profraw
1051 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
1052 EXTRACXXFLAGS='-fprofile-instr-use=stockfish.profdata' \
1053 EXTRALDFLAGS='-fprofile-use ' \
1057 -@$(CXX) $(DEPENDFLAGS) -MM $(SRCS) > $@ 2> /dev/null
1059 ifeq (, $(filter $(MAKECMDGOALS), help strip install clean net objclean profileclean config-sanity))