]> git.sesse.net Git - stockfish/blob - src/Makefile
E2K: added support for MCST Elbrus 2000 CPU architecture
[stockfish] / src / Makefile
1 # Stockfish, a UCI chess playing engine derived from Glaurung 2.1
2 # Copyright (C) 2004-2021 The Stockfish developers (see AUTHORS file)
3 #
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.
8 #
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.
13 #
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/>.
16
17
18 ### ==========================================================================
19 ### Section 1. General Configuration
20 ### ==========================================================================
21
22 ### Executable name
23 ifeq ($(COMP),mingw)
24 EXE = stockfish.exe
25 else
26 EXE = stockfish
27 endif
28
29 ### Installation dir definitions
30 PREFIX = /usr/local
31 BINDIR = $(PREFIX)/bin
32
33 ### Built-in benchmark for pgo-builds
34 ifeq ($(SDE_PATH),)
35         PGOBENCH = ./$(EXE) bench
36 else
37         PGOBENCH = $(SDE_PATH) -- ./$(EXE) bench
38 endif
39
40 ### Source and object files
41 SRCS = benchmark.cpp bitbase.cpp bitboard.cpp endgame.cpp evaluate.cpp main.cpp \
42         material.cpp misc.cpp movegen.cpp movepick.cpp pawns.cpp position.cpp psqt.cpp \
43         search.cpp thread.cpp timeman.cpp tt.cpp uci.cpp ucioption.cpp tune.cpp syzygy/tbprobe.cpp \
44         nnue/evaluate_nnue.cpp nnue/features/half_kp.cpp
45
46 OBJS = $(notdir $(SRCS:.cpp=.o))
47
48 VPATH = syzygy:nnue:nnue/features
49
50 ### Establish the operating system name
51 KERNEL = $(shell uname -s)
52 ifeq ($(KERNEL),Linux)
53         OS = $(shell uname -o)
54 endif
55
56 ### ==========================================================================
57 ### Section 2. High-level Configuration
58 ### ==========================================================================
59 #
60 # flag                --- Comp switch      --- Description
61 # ----------------------------------------------------------------------------
62 #
63 # debug = yes/no      --- -DNDEBUG         --- Enable/Disable debug mode
64 # sanitize = undefined/thread/no (-fsanitize )
65 #                     --- ( undefined )    --- enable undefined behavior checks
66 #                     --- ( thread    )    --- enable threading error  checks
67 # optimize = yes/no   --- (-O3/-fast etc.) --- Enable/Disable optimizations
68 # arch = (name)       --- (-arch)          --- Target architecture
69 # bits = 64/32        --- -DIS_64BIT       --- 64-/32-bit operating system
70 # prefetch = yes/no   --- -DUSE_PREFETCH   --- Use prefetch asm-instruction
71 # popcnt = yes/no     --- -DUSE_POPCNT     --- Use popcnt asm-instruction
72 # pext = yes/no       --- -DUSE_PEXT       --- Use pext x86_64 asm-instruction
73 # sse = yes/no        --- -msse            --- Use Intel Streaming SIMD Extensions
74 # mmx = yes/no        --- -mmmx            --- Use Intel MMX instructions
75 # sse2 = yes/no       --- -msse2           --- Use Intel Streaming SIMD Extensions 2
76 # ssse3 = yes/no      --- -mssse3          --- Use Intel Supplemental Streaming SIMD Extensions 3
77 # sse41 = yes/no      --- -msse4.1         --- Use Intel Streaming SIMD Extensions 4.1
78 # avx2 = yes/no       --- -mavx2           --- Use Intel Advanced Vector Extensions 2
79 # avx512 = yes/no     --- -mavx512bw       --- Use Intel Advanced Vector Extensions 512
80 # vnni256 = yes/no    --- -mavx512vnni     --- Use Intel Vector Neural Network Instructions 256
81 # vnni512 = yes/no    --- -mavx512vnni     --- Use Intel Vector Neural Network Instructions 512
82 # neon = yes/no       --- -DUSE_NEON       --- Use ARM SIMD architecture
83 #
84 # Note that Makefile is space sensitive, so when adding new architectures
85 # or modifying existing flags, you have to make sure there are no extra spaces
86 # at the end of the line for flag values.
87
88 ### 2.1. General and architecture defaults
89
90 ifeq ($(ARCH),)
91    ARCH = x86-64-modern
92    help_skip_sanity = yes
93 endif
94 # explicitly check for the list of supported architectures (as listed with make help),
95 # the user can override with `make ARCH=x86-32-vnni256 SUPPORTED_ARCH=true`
96 ifeq ($(ARCH), $(filter $(ARCH), \
97                  x86-64-vnni512 x86-64-vnni256 x86-64-avx512 x86-64-bmi2 x86-64-avx2 \
98                  x86-64-sse41-popcnt x86-64-modern x86-64-ssse3 x86-64-sse3-popcnt \
99                  x86-64 x86-32-sse41-popcnt x86-32-sse2 x86-32 ppc-64 ppc-32 \
100                  e2k \
101                  armv7 armv7-neon armv8 apple-silicon general-64 general-32))
102    SUPPORTED_ARCH=true
103 else
104    SUPPORTED_ARCH=false
105 endif
106
107 optimize = yes
108 debug = no
109 sanitize = no
110 bits = 64
111 prefetch = no
112 popcnt = no
113 pext = no
114 sse = no
115 mmx = no
116 sse2 = no
117 ssse3 = no
118 sse41 = no
119 avx2 = no
120 avx512 = no
121 vnni256 = no
122 vnni512 = no
123 neon = no
124 STRIP = strip
125
126 ### 2.2 Architecture specific
127
128 ifeq ($(findstring x86,$(ARCH)),x86)
129
130 # x86-32/64
131
132 ifeq ($(findstring x86-32,$(ARCH)),x86-32)
133         arch = i386
134         bits = 32
135         sse = yes
136         mmx = yes
137 else
138         arch = x86_64
139         sse = yes
140         sse2 = yes
141 endif
142
143 ifeq ($(findstring -sse,$(ARCH)),-sse)
144         sse = yes
145 endif
146
147 ifeq ($(findstring -popcnt,$(ARCH)),-popcnt)
148         popcnt = yes
149 endif
150
151 ifeq ($(findstring -mmx,$(ARCH)),-mmx)
152         mmx = yes
153 endif
154
155 ifeq ($(findstring -sse2,$(ARCH)),-sse2)
156         sse = yes
157         sse2 = yes
158 endif
159
160 ifeq ($(findstring -ssse3,$(ARCH)),-ssse3)
161         sse = yes
162         sse2 = yes
163         ssse3 = yes
164 endif
165
166 ifeq ($(findstring -sse41,$(ARCH)),-sse41)
167         sse = yes
168         sse2 = yes
169         ssse3 = yes
170         sse41 = yes
171 endif
172
173 ifeq ($(findstring -modern,$(ARCH)),-modern)
174         popcnt = yes
175         sse = yes
176         sse2 = yes
177         ssse3 = yes
178         sse41 = yes
179 endif
180
181 ifeq ($(findstring -avx2,$(ARCH)),-avx2)
182         popcnt = yes
183         sse = yes
184         sse2 = yes
185         ssse3 = yes
186         sse41 = yes
187         avx2 = yes
188 endif
189
190 ifeq ($(findstring -bmi2,$(ARCH)),-bmi2)
191         popcnt = yes
192         sse = yes
193         sse2 = yes
194         ssse3 = yes
195         sse41 = yes
196         avx2 = yes
197         pext = yes
198 endif
199
200 ifeq ($(findstring -avx512,$(ARCH)),-avx512)
201         popcnt = yes
202         sse = yes
203         sse2 = yes
204         ssse3 = yes
205         sse41 = yes
206         avx2 = yes
207         pext = yes
208         avx512 = yes
209 endif
210
211 ifeq ($(findstring -vnni256,$(ARCH)),-vnni256)
212         popcnt = yes
213         sse = yes
214         sse2 = yes
215         ssse3 = yes
216         sse41 = yes
217         avx2 = yes
218         pext = yes
219         vnni256 = yes
220 endif
221
222 ifeq ($(findstring -vnni512,$(ARCH)),-vnni512)
223         popcnt = yes
224         sse = yes
225         sse2 = yes
226         ssse3 = yes
227         sse41 = yes
228         avx2 = yes
229         pext = yes
230         avx512 = yes
231         vnni512 = yes
232 endif
233
234 ifeq ($(sse),yes)
235         prefetch = yes
236 endif
237
238 # 64-bit pext is not available on x86-32
239 ifeq ($(bits),32)
240         pext = no
241 endif
242
243 else
244
245 # all other architectures
246
247 ifeq ($(ARCH),general-32)
248         arch = any
249         bits = 32
250 endif
251
252 ifeq ($(ARCH),general-64)
253         arch = any
254 endif
255
256 ifeq ($(ARCH),armv7)
257         arch = armv7
258         prefetch = yes
259         bits = 32
260 endif
261
262 ifeq ($(ARCH),armv7-neon)
263         arch = armv7
264         prefetch = yes
265         popcnt = yes
266         neon = yes
267         bits = 32
268 endif
269
270 ifeq ($(ARCH),armv8)
271         arch = armv8
272         prefetch = yes
273         popcnt = yes
274         neon = yes
275 endif
276
277 ifeq ($(ARCH),apple-silicon)
278         arch = arm64
279         prefetch = yes
280         popcnt = yes
281         neon = yes
282 endif
283
284 ifeq ($(ARCH),ppc-32)
285         arch = ppc
286         bits = 32
287 endif
288
289 ifeq ($(ARCH),ppc-64)
290         arch = ppc64
291         popcnt = yes
292         prefetch = yes
293 endif
294
295 ifeq ($(findstring e2k,$(ARCH)),e2k)
296         arch = e2k
297         mmx = yes
298         bits = 64
299         sse = yes
300         sse2 = yes
301         ssse3 = yes
302         sse41 = yes
303         popcnt = yes
304 endif
305
306 endif
307
308 ### ==========================================================================
309 ### Section 3. Low-level Configuration
310 ### ==========================================================================
311
312 ### 3.1 Selecting compiler (default = gcc)
313 CXXFLAGS += -Wall -Wcast-qual -fno-exceptions -std=c++17 $(EXTRACXXFLAGS)
314 DEPENDFLAGS += -std=c++17
315 LDFLAGS += $(EXTRALDFLAGS)
316
317 ifeq ($(COMP),)
318         COMP=gcc
319 endif
320
321 ifeq ($(COMP),gcc)
322         comp=gcc
323         CXX=g++
324         CXXFLAGS += -pedantic -Wextra -Wshadow
325
326         ifeq ($(arch),$(filter $(arch),armv7 armv8))
327                 ifeq ($(OS),Android)
328                         CXXFLAGS += -m$(bits)
329                         LDFLAGS += -m$(bits)
330                 endif
331         else
332                 CXXFLAGS += -m$(bits)
333                 LDFLAGS += -m$(bits)
334         endif
335
336         ifeq ($(arch),$(filter $(arch),armv7))
337                 LDFLAGS += -latomic
338         endif
339
340         ifneq ($(KERNEL),Darwin)
341            LDFLAGS += -Wl,--no-as-needed
342         endif
343 endif
344
345 ifeq ($(COMP),mingw)
346         comp=mingw
347
348         ifeq ($(KERNEL),Linux)
349                 ifeq ($(bits),64)
350                         ifeq ($(shell which x86_64-w64-mingw32-c++-posix),)
351                                 CXX=x86_64-w64-mingw32-c++
352                         else
353                                 CXX=x86_64-w64-mingw32-c++-posix
354                         endif
355                 else
356                         ifeq ($(shell which i686-w64-mingw32-c++-posix),)
357                                 CXX=i686-w64-mingw32-c++
358                         else
359                                 CXX=i686-w64-mingw32-c++-posix
360                         endif
361                 endif
362         else
363                 CXX=g++
364         endif
365
366         CXXFLAGS += -Wextra -Wshadow
367         LDFLAGS += -static
368 endif
369
370 ifeq ($(COMP),icc)
371         comp=icc
372         CXX=icpc
373         CXXFLAGS += -diag-disable 1476,10120 -Wcheck -Wabi -Wdeprecated -strict-ansi
374 endif
375
376 ifeq ($(COMP),clang)
377         comp=clang
378         CXX=clang++
379         CXXFLAGS += -pedantic -Wextra -Wshadow
380
381         ifneq ($(KERNEL),Darwin)
382         ifneq ($(KERNEL),OpenBSD)
383         ifneq ($(KERNEL),FreeBSD)
384                 LDFLAGS += -latomic
385         endif
386         endif
387         endif
388
389         ifeq ($(arch),$(filter $(arch),armv7 armv8))
390                 ifeq ($(OS),Android)
391                         CXXFLAGS += -m$(bits)
392                         LDFLAGS += -m$(bits)
393                 endif
394         else
395                 CXXFLAGS += -m$(bits)
396                 LDFLAGS += -m$(bits)
397         endif
398 endif
399
400 ifeq ($(KERNEL),Darwin)
401         CXXFLAGS += -arch $(arch) -mmacosx-version-min=10.14
402         LDFLAGS += -arch $(arch) -mmacosx-version-min=10.14
403         XCRUN = xcrun
404 endif
405
406 # To cross-compile for Android, NDK version r21 or later is recommended.
407 # In earlier NDK versions, you'll need to pass -fno-addrsig if using GNU binutils.
408 # Currently we don't know how to make PGO builds with the NDK yet.
409 ifeq ($(COMP),ndk)
410         CXXFLAGS += -stdlib=libc++ -fPIE
411         comp=clang
412         ifeq ($(arch),armv7)
413                 CXX=armv7a-linux-androideabi16-clang++
414                 CXXFLAGS += -mthumb -march=armv7-a -mfloat-abi=softfp -mfpu=neon
415                 STRIP=arm-linux-androideabi-strip
416         endif
417         ifeq ($(arch),armv8)
418                 CXX=aarch64-linux-android21-clang++
419                 STRIP=aarch64-linux-android-strip
420         endif
421         LDFLAGS += -static-libstdc++ -pie -lm -latomic
422 endif
423
424 ifeq ($(comp),icc)
425         profile_make = icc-profile-make
426         profile_use = icc-profile-use
427 else ifeq ($(comp),clang)
428         profile_make = clang-profile-make
429         profile_use = clang-profile-use
430 else
431         profile_make = gcc-profile-make
432         profile_use = gcc-profile-use
433 endif
434
435 ### Travis CI script uses COMPILER to overwrite CXX
436 ifdef COMPILER
437         COMPCXX=$(COMPILER)
438 endif
439
440 ### Allow overwriting CXX from command line
441 ifdef COMPCXX
442         CXX=$(COMPCXX)
443 endif
444
445 ### Sometimes gcc is really clang
446 ifeq ($(COMP),gcc)
447         gccversion = $(shell $(CXX) --version)
448         gccisclang = $(findstring clang,$(gccversion))
449         ifneq ($(gccisclang),)
450                 profile_make = clang-profile-make
451                 profile_use = clang-profile-use
452         endif
453 endif
454
455 ### On mingw use Windows threads, otherwise POSIX
456 ifneq ($(comp),mingw)
457         CXXFLAGS += -DUSE_PTHREADS
458         # On Android Bionic's C library comes with its own pthread implementation bundled in
459         ifneq ($(OS),Android)
460                 # Haiku has pthreads in its libroot, so only link it in on other platforms
461                 ifneq ($(KERNEL),Haiku)
462                         ifneq ($(COMP),ndk)
463                                 LDFLAGS += -lpthread
464                         endif
465                 endif
466         endif
467 endif
468
469 ### 3.2.1 Debugging
470 ifeq ($(debug),no)
471         CXXFLAGS += -DNDEBUG
472 else
473         CXXFLAGS += -g
474 endif
475
476 ### 3.2.2 Debugging with undefined behavior sanitizers
477 ifneq ($(sanitize),no)
478         CXXFLAGS += -g3 -fsanitize=$(sanitize)
479         LDFLAGS += -fsanitize=$(sanitize)
480 endif
481
482 ### 3.3 Optimization
483 ifeq ($(optimize),yes)
484
485         CXXFLAGS += -O3
486
487         ifeq ($(comp),gcc)
488                 ifeq ($(OS), Android)
489                         CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
490                 endif
491         endif
492
493         ifeq ($(comp),$(filter $(comp),gcc clang icc))
494                 ifeq ($(KERNEL),Darwin)
495                         CXXFLAGS += -mdynamic-no-pic
496                 endif
497         endif
498
499         ifeq ($(comp),clang)
500                 CXXFLAGS += -fexperimental-new-pass-manager
501         endif
502 endif
503
504 ### 3.4 Bits
505 ifeq ($(bits),64)
506         CXXFLAGS += -DIS_64BIT
507 endif
508
509 ### 3.5 prefetch
510 ifeq ($(prefetch),yes)
511         ifeq ($(sse),yes)
512                 CXXFLAGS += -msse
513         endif
514 else
515         CXXFLAGS += -DNO_PREFETCH
516 endif
517
518 ### 3.6 popcnt
519 ifeq ($(popcnt),yes)
520         ifeq ($(arch),$(filter $(arch),ppc64 armv7 armv8 arm64))
521                 CXXFLAGS += -DUSE_POPCNT
522         else ifeq ($(comp),icc)
523                 CXXFLAGS += -msse3 -DUSE_POPCNT
524         else
525                 CXXFLAGS += -msse3 -mpopcnt -DUSE_POPCNT
526         endif
527 endif
528
529 ifeq ($(avx2),yes)
530         CXXFLAGS += -DUSE_AVX2
531         ifeq ($(comp),$(filter $(comp),gcc clang mingw))
532                 CXXFLAGS += -mavx2
533         endif
534 endif
535
536 ifeq ($(avx512),yes)
537         CXXFLAGS += -DUSE_AVX512
538         ifeq ($(comp),$(filter $(comp),gcc clang mingw))
539                 CXXFLAGS += -mavx512f -mavx512bw
540         endif
541 endif
542
543 ifeq ($(vnni256),yes)
544         CXXFLAGS += -DUSE_VNNI
545         ifeq ($(comp),$(filter $(comp),gcc clang mingw))
546                 CXXFLAGS += -mavx512f -mavx512bw -mavx512vnni -mavx512dq -mavx512vl -mprefer-vector-width=256
547         endif
548 endif
549
550 ifeq ($(vnni512),yes)
551         CXXFLAGS += -DUSE_VNNI
552         ifeq ($(comp),$(filter $(comp),gcc clang mingw))
553                 CXXFLAGS += -mavx512vnni -mavx512dq -mavx512vl
554         endif
555 endif
556
557 ifeq ($(sse41),yes)
558         CXXFLAGS += -DUSE_SSE41
559         ifeq ($(comp),$(filter $(comp),gcc clang mingw))
560                 CXXFLAGS += -msse4.1
561         endif
562 endif
563
564 ifeq ($(ssse3),yes)
565         CXXFLAGS += -DUSE_SSSE3
566         ifeq ($(comp),$(filter $(comp),gcc clang mingw))
567                 CXXFLAGS += -mssse3
568         endif
569 endif
570
571 ifeq ($(sse2),yes)
572         CXXFLAGS += -DUSE_SSE2
573         ifeq ($(comp),$(filter $(comp),gcc clang mingw))
574                 CXXFLAGS += -msse2
575         endif
576 endif
577
578 ifeq ($(mmx),yes)
579         CXXFLAGS += -DUSE_MMX
580         ifeq ($(comp),$(filter $(comp),gcc clang mingw))
581                 CXXFLAGS += -mmmx
582         endif
583 endif
584
585 ifeq ($(neon),yes)
586         CXXFLAGS += -DUSE_NEON
587         ifeq ($(KERNEL),Linux)
588         ifneq ($(COMP),ndk)
589         ifneq ($(arch),armv8)
590                 CXXFLAGS += -mfpu=neon
591         endif
592         endif
593         endif
594 endif
595
596 ### 3.7 pext
597 ifeq ($(pext),yes)
598         CXXFLAGS += -DUSE_PEXT
599         ifeq ($(comp),$(filter $(comp),gcc clang mingw))
600                 CXXFLAGS += -mbmi2
601         endif
602 endif
603
604 ### 3.8 Link Time Optimization
605 ### This is a mix of compile and link time options because the lto link phase
606 ### needs access to the optimization flags.
607 ifeq ($(optimize),yes)
608 ifeq ($(debug), no)
609         ifeq ($(comp),clang)
610                 CXXFLAGS += -flto
611                 ifneq ($(findstring MINGW,$(KERNEL)),)
612                         CXXFLAGS += -fuse-ld=lld
613                 else ifneq ($(findstring MSYS,$(KERNEL)),)
614                         CXXFLAGS += -fuse-ld=lld
615                 endif
616                 LDFLAGS += $(CXXFLAGS)
617
618 # GCC and CLANG use different methods for parallelizing LTO and CLANG pretends to be
619 # GCC on some systems.
620         else ifeq ($(comp),gcc)
621         ifeq ($(gccisclang),)
622                 CXXFLAGS += -flto
623                 LDFLAGS += $(CXXFLAGS) -flto=jobserver
624                 ifneq ($(findstring MINGW,$(KERNEL)),)
625                         LDFLAGS += -save-temps
626                 else ifneq ($(findstring MSYS,$(KERNEL)),)
627                         LDFLAGS += -save-temps
628                 endif
629         else
630                 CXXFLAGS += -flto
631                 LDFLAGS += $(CXXFLAGS)
632         endif
633
634 # To use LTO and static linking on windows, the tool chain requires a recent gcc:
635 # gcc version 10.1 in msys2 or TDM-GCC version 9.2 are known to work, older might not.
636 # So, only enable it for a cross from Linux by default.
637         else ifeq ($(comp),mingw)
638         ifeq ($(KERNEL),Linux)
639         ifneq ($(arch),i386)
640                 CXXFLAGS += -flto
641                 LDFLAGS += $(CXXFLAGS) -flto=jobserver
642         endif
643         endif
644         endif
645 endif
646 endif
647
648 ### 3.9 Android 5 can only run position independent executables. Note that this
649 ### breaks Android 4.0 and earlier.
650 ifeq ($(OS), Android)
651         CXXFLAGS += -fPIE
652         LDFLAGS += -fPIE -pie
653 endif
654
655 ### ==========================================================================
656 ### Section 4. Public Targets
657 ### ==========================================================================
658
659
660 help:
661         @echo ""
662         @echo "To compile stockfish, type: "
663         @echo ""
664         @echo "make target ARCH=arch [COMP=compiler] [COMPCXX=cxx]"
665         @echo ""
666         @echo "Supported targets:"
667         @echo ""
668         @echo "help                    > Display architecture details"
669         @echo "build                   > Standard build"
670         @echo "net                     > Download the default nnue net"
671         @echo "profile-build           > Faster build (with profile-guided optimization)"
672         @echo "strip                   > Strip executable"
673         @echo "install                 > Install executable"
674         @echo "clean                   > Clean up"
675         @echo ""
676         @echo "Supported archs:"
677         @echo ""
678         @echo "x86-64-vnni512          > x86 64-bit with vnni support 512bit wide"
679         @echo "x86-64-vnni256          > x86 64-bit with vnni support 256bit wide"
680         @echo "x86-64-avx512           > x86 64-bit with avx512 support"
681         @echo "x86-64-bmi2             > x86 64-bit with bmi2 support"
682         @echo "x86-64-avx2             > x86 64-bit with avx2 support"
683         @echo "x86-64-sse41-popcnt     > x86 64-bit with sse41 and popcnt support"
684         @echo "x86-64-modern           > common modern CPU, currently x86-64-sse41-popcnt"
685         @echo "x86-64-ssse3            > x86 64-bit with ssse3 support"
686         @echo "x86-64-sse3-popcnt      > x86 64-bit with sse3 and popcnt support"
687         @echo "x86-64                  > x86 64-bit generic (with sse2 support)"
688         @echo "x86-32-sse41-popcnt     > x86 32-bit with sse41 and popcnt support"
689         @echo "x86-32-sse2             > x86 32-bit with sse2 support"
690         @echo "x86-32                  > x86 32-bit generic (with mmx and sse support)"
691         @echo "ppc-64                  > PPC 64-bit"
692         @echo "ppc-32                  > PPC 32-bit"
693         @echo "armv7                   > ARMv7 32-bit"
694         @echo "armv7-neon              > ARMv7 32-bit with popcnt and neon"
695         @echo "armv8                   > ARMv8 64-bit with popcnt and neon"
696         @echo "e2k                     > Elbrus 2000"
697         @echo "apple-silicon           > Apple silicon ARM64"
698         @echo "general-64              > unspecified 64-bit"
699         @echo "general-32              > unspecified 32-bit"
700         @echo ""
701         @echo "Supported compilers:"
702         @echo ""
703         @echo "gcc                     > Gnu compiler (default)"
704         @echo "mingw                   > Gnu compiler with MinGW under Windows"
705         @echo "clang                   > LLVM Clang compiler"
706         @echo "icc                     > Intel compiler"
707         @echo "ndk                     > Google NDK to cross-compile for Android"
708         @echo ""
709         @echo "Simple examples. If you don't know what to do, you likely want to run: "
710         @echo ""
711         @echo "make -j build ARCH=x86-64  (A portable, slow compile for 64-bit systems)"
712         @echo "make -j build ARCH=x86-32  (A portable, slow compile for 32-bit systems)"
713         @echo ""
714         @echo "Advanced examples, for experienced users looking for performance: "
715         @echo ""
716         @echo "make    help  ARCH=x86-64-bmi2"
717         @echo "make -j profile-build ARCH=x86-64-bmi2 COMP=gcc COMPCXX=g++-9.0"
718         @echo "make -j build ARCH=x86-64-ssse3 COMP=clang"
719         @echo ""
720         @echo "-------------------------------"
721 ifeq ($(SUPPORTED_ARCH)$(help_skip_sanity), true)
722         @echo "The selected architecture $(ARCH) will enable the following configuration: "
723         @$(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
724 else
725         @echo "Specify a supported architecture with the ARCH option for more details"
726         @echo ""
727 endif
728
729
730 .PHONY: help build profile-build strip install clean net objclean profileclean \
731         config-sanity icc-profile-use icc-profile-make gcc-profile-use gcc-profile-make \
732         clang-profile-use clang-profile-make
733
734 build: net config-sanity
735         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
736
737 profile-build: net config-sanity objclean profileclean
738         @echo ""
739         @echo "Step 1/4. Building instrumented executable ..."
740         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
741         @echo ""
742         @echo "Step 2/4. Running benchmark for pgo-build ..."
743         $(PGOBENCH) > /dev/null
744         @echo ""
745         @echo "Step 3/4. Building optimized executable ..."
746         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) objclean
747         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
748         @echo ""
749         @echo "Step 4/4. Deleting profile data ..."
750         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) profileclean
751
752 strip:
753         $(STRIP) $(EXE)
754
755 install:
756         -mkdir -p -m 755 $(BINDIR)
757         -cp $(EXE) $(BINDIR)
758         -strip $(BINDIR)/$(EXE)
759
760 # clean all
761 clean: objclean profileclean
762         @rm -f .depend *~ core
763
764 # evaluation network (nnue)
765 net:
766         $(eval nnuenet := $(shell grep EvalFileDefaultName evaluate.h | grep define | sed 's/.*\(nn-[a-z0-9]\{12\}.nnue\).*/\1/'))
767         @echo "Default net: $(nnuenet)"
768         $(eval nnuedownloadurl := https://tests.stockfishchess.org/api/nn/$(nnuenet))
769         $(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))
770         @if test -f "$(nnuenet)"; then \
771             echo "Already available."; \
772          else \
773             if [ "x$(curl_or_wget)" = "x" ]; then \
774                echo "Automatic download failed: neither curl nor wget is installed. Install one of these tools or download the net manually"; exit 1; \
775             else \
776                echo "Downloading $(nnuedownloadurl)"; $(curl_or_wget) $(nnuedownloadurl) > $(nnuenet);\
777             fi; \
778         fi;
779         $(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))
780         @if [ "x$(shasum_command)" != "x" ]; then \
781             if [ "$(nnuenet)" != "nn-"`$(shasum_command) $(nnuenet) | cut -c1-12`".nnue" ]; then \
782                 echo "Failed download or $(nnuenet) corrupted, please delete!"; exit 1; \
783             fi \
784          else \
785             echo "shasum / sha256sum not found, skipping net validation"; \
786         fi
787
788 # clean binaries and objects
789 objclean:
790         @rm -f $(EXE) *.o ./syzygy/*.o ./nnue/*.o ./nnue/features/*.o
791
792 # clean auxiliary profiling files
793 profileclean:
794         @rm -rf profdir
795         @rm -f bench.txt *.gcda *.gcno ./syzygy/*.gcda ./nnue/*.gcda ./nnue/features/*.gcda *.s
796         @rm -f stockfish.profdata *.profraw
797
798 default:
799         help
800
801 ### ==========================================================================
802 ### Section 5. Private Targets
803 ### ==========================================================================
804
805 all: $(EXE) .depend
806
807 config-sanity: net
808         @echo ""
809         @echo "Config:"
810         @echo "debug: '$(debug)'"
811         @echo "sanitize: '$(sanitize)'"
812         @echo "optimize: '$(optimize)'"
813         @echo "arch: '$(arch)'"
814         @echo "bits: '$(bits)'"
815         @echo "kernel: '$(KERNEL)'"
816         @echo "os: '$(OS)'"
817         @echo "prefetch: '$(prefetch)'"
818         @echo "popcnt: '$(popcnt)'"
819         @echo "pext: '$(pext)'"
820         @echo "sse: '$(sse)'"
821         @echo "mmx: '$(mmx)'"
822         @echo "sse2: '$(sse2)'"
823         @echo "ssse3: '$(ssse3)'"
824         @echo "sse41: '$(sse41)'"
825         @echo "avx2: '$(avx2)'"
826         @echo "avx512: '$(avx512)'"
827         @echo "vnni256: '$(vnni256)'"
828         @echo "vnni512: '$(vnni512)'"
829         @echo "neon: '$(neon)'"
830         @echo ""
831         @echo "Flags:"
832         @echo "CXX: $(CXX)"
833         @echo "CXXFLAGS: $(CXXFLAGS)"
834         @echo "LDFLAGS: $(LDFLAGS)"
835         @echo ""
836         @echo "Testing config sanity. If this fails, try 'make help' ..."
837         @echo ""
838         @test "$(debug)" = "yes" || test "$(debug)" = "no"
839         @test "$(sanitize)" = "undefined" || test "$(sanitize)" = "thread" || test "$(sanitize)" = "address" || test "$(sanitize)" = "no"
840         @test "$(optimize)" = "yes" || test "$(optimize)" = "no"
841         @test "$(SUPPORTED_ARCH)" = "true"
842         @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
843          test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || \
844          test "$(arch)" = "e2k" || \
845          test "$(arch)" = "armv7" || test "$(arch)" = "armv8" || test "$(arch)" = "arm64"
846         @test "$(bits)" = "32" || test "$(bits)" = "64"
847         @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
848         @test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
849         @test "$(pext)" = "yes" || test "$(pext)" = "no"
850         @test "$(sse)" = "yes" || test "$(sse)" = "no"
851         @test "$(mmx)" = "yes" || test "$(mmx)" = "no"
852         @test "$(sse2)" = "yes" || test "$(sse2)" = "no"
853         @test "$(ssse3)" = "yes" || test "$(ssse3)" = "no"
854         @test "$(sse41)" = "yes" || test "$(sse41)" = "no"
855         @test "$(avx2)" = "yes" || test "$(avx2)" = "no"
856         @test "$(avx512)" = "yes" || test "$(avx512)" = "no"
857         @test "$(vnni256)" = "yes" || test "$(vnni256)" = "no"
858         @test "$(vnni512)" = "yes" || test "$(vnni512)" = "no"
859         @test "$(neon)" = "yes" || test "$(neon)" = "no"
860         @test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw" || test "$(comp)" = "clang" \
861         || test "$(comp)" = "armv7a-linux-androideabi16-clang"  || test "$(comp)" = "aarch64-linux-android21-clang"
862
863 $(EXE): $(OBJS)
864         +$(CXX) -o $@ $(OBJS) $(LDFLAGS)
865
866 clang-profile-make:
867         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
868         EXTRACXXFLAGS='-fprofile-instr-generate ' \
869         EXTRALDFLAGS=' -fprofile-instr-generate' \
870         all
871
872 clang-profile-use:
873         $(XCRUN) llvm-profdata merge -output=stockfish.profdata *.profraw
874         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
875         EXTRACXXFLAGS='-fprofile-instr-use=stockfish.profdata' \
876         EXTRALDFLAGS='-fprofile-use ' \
877         all
878
879 gcc-profile-make:
880         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
881         EXTRACXXFLAGS='-fprofile-generate' \
882         EXTRALDFLAGS='-lgcov' \
883         all
884
885 gcc-profile-use:
886         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
887         EXTRACXXFLAGS='-fprofile-use -fno-peel-loops -fno-tracer' \
888         EXTRALDFLAGS='-lgcov' \
889         all
890
891 icc-profile-make:
892         @mkdir -p profdir
893         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
894         EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
895         all
896
897 icc-profile-use:
898         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
899         EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
900         all
901
902 .depend:
903         -@$(CXX) $(DEPENDFLAGS) -MM $(SRCS) > $@ 2> /dev/null
904
905 -include .depend