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