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