]> git.sesse.net Git - stockfish/blob - src/Makefile
Fix compilation after recent merge.
[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         hashprobe.grpc.pb.cc hashprobe.pb.cc
44 CLISRCS = client.cpp hashprobe.grpc.pb.cc hashprobe.pb.cc uci.cpp
45
46 OBJS = $(notdir $(SRCS:.cpp=.o))
47 CLIOBJS = $(notdir $(CLISRCS:.cpp=.o))
48
49 VPATH = syzygy:nnue:nnue/features
50
51 ### Establish the operating system name
52 KERNEL = $(shell uname -s)
53 ifeq ($(KERNEL),Linux)
54         OS = $(shell uname -o)
55 endif
56
57 ### ==========================================================================
58 ### Section 2. High-level Configuration
59 ### ==========================================================================
60 #
61 # flag                --- Comp switch      --- Description
62 # ----------------------------------------------------------------------------
63 #
64 # debug = yes/no      --- -DNDEBUG         --- Enable/Disable debug mode
65 # sanitize = undefined/thread/no (-fsanitize )
66 #                     --- ( undefined )    --- enable undefined behavior checks
67 #                     --- ( thread    )    --- enable threading error  checks
68 # optimize = yes/no   --- (-O3/-fast etc.) --- Enable/Disable optimizations
69 # arch = (name)       --- (-arch)          --- Target architecture
70 # bits = 64/32        --- -DIS_64BIT       --- 64-/32-bit operating system
71 # prefetch = yes/no   --- -DUSE_PREFETCH   --- Use prefetch asm-instruction
72 # popcnt = yes/no     --- -DUSE_POPCNT     --- Use popcnt asm-instruction
73 # sse = yes/no        --- -msse            --- Use Intel Streaming SIMD Extensions
74 # sse3 = yes/no       --- -msse3           --- Use Intel Streaming SIMD Extensions 3
75 # ssse3 = yes/no      --- -mssse3          --- Use Intel Supplemental Streaming SIMD Extensions 3
76 # sse41 = yes/no      --- -msse4.1         --- Use Intel Streaming SIMD Extensions 4.1
77 # sse42 = yes/no      --- -msse4.2         --- Use Intel Streaming SIMD Extensions 4.2
78 # avx2 = yes/no       --- -mavx2           --- Use Intel Advanced Vector Extensions 2
79 # pext = yes/no       --- -DUSE_PEXT       --- Use pext x86_64 asm-instruction
80 # avx512 = yes/no     --- -mavx512bw       --- Use Intel Advanced Vector Extensions 512
81 # neon = yes/no       --- -DUSE_NEON       --- Use ARM SIMD architecture
82 #
83 # Note that Makefile is space sensitive, so when adding new architectures
84 # or modifying existing flags, you have to make sure there are no extra spaces
85 # at the end of the line for flag values.
86
87 ### 2.1. General and architecture defaults
88 optimize = yes
89 debug = no
90 sanitize = no
91 bits = 64
92 prefetch = no
93 popcnt = no
94 sse = no
95 sse3 = no
96 ssse3 = no
97 sse41 = no
98 sse42 = no
99 avx2 = no
100 pext = no
101 avx512 = no
102 neon = no
103 ARCH = x86-64-modern
104
105 ### 2.2 Architecture specific
106 ifeq ($(ARCH),general-32)
107         arch = any
108         bits = 32
109 endif
110
111 ifeq ($(ARCH),x86-32-old)
112         arch = i386
113         bits = 32
114 endif
115
116 ifeq ($(ARCH),x86-32)
117         arch = i386
118         bits = 32
119         prefetch = yes
120         sse = yes
121 endif
122
123 ifeq ($(ARCH),general-64)
124         arch = any
125 endif
126
127 ifeq ($(ARCH),x86-64)
128         arch = x86_64
129         prefetch = yes
130         sse = yes
131 endif
132
133 ifeq ($(ARCH),x86-64-sse3)
134         arch = x86_64
135         prefetch = yes
136         sse = yes
137         sse3 = yes
138 endif
139
140 ifeq ($(ARCH),x86-64-sse3-popcnt)
141         arch = x86_64
142         prefetch = yes
143         sse = yes
144         sse3 = yes
145         popcnt = yes
146 endif
147
148 ifeq ($(ARCH),x86-64-ssse3)
149         arch = x86_64
150         prefetch = yes
151         sse = yes
152         sse3 = yes
153         ssse3 = yes
154 endif
155
156 ifeq ($(ARCH),x86-64-sse41)
157         arch = x86_64
158         prefetch = yes
159         popcnt = yes
160         sse = yes
161         sse3 = yes
162         ssse3 = yes
163         sse41 = yes
164 endif
165
166 ifeq ($(ARCH),x86-64-modern)
167         arch = x86_64
168         prefetch = yes
169         popcnt = yes
170         sse = yes
171         sse3 = yes
172         ssse3 = yes
173         sse41 = yes
174 endif
175
176 ifeq ($(ARCH),x86-64-sse42)
177         arch = x86_64
178         prefetch = yes
179         popcnt = yes
180         sse = yes
181         sse3 = yes
182         ssse3 = yes
183         sse41 = yes
184         sse42 = yes
185 endif
186
187 ifeq ($(ARCH),x86-64-avx2)
188         arch = x86_64
189         prefetch = yes
190         popcnt = yes
191         sse = yes
192         sse3 = yes
193         ssse3 = yes
194         sse41 = yes
195         sse42 = yes
196         avx2 = yes
197 endif
198
199 ifeq ($(ARCH),x86-64-bmi2)
200         arch = x86_64
201         prefetch = yes
202         popcnt = yes
203         sse = yes
204         sse3 = yes
205         ssse3 = yes
206         sse41 = yes
207         sse42 = yes
208         avx2 = yes
209         pext = yes
210 endif
211
212 ifeq ($(ARCH),x86-64-avx512)
213         arch = x86_64
214         prefetch = yes
215         popcnt = yes
216         sse = yes
217         sse3 = yes
218         ssse3 = yes
219         sse41 = yes
220         sse42 = yes
221         avx2 = yes
222         pext = yes
223         avx512 = yes
224 endif
225
226 ifeq ($(ARCH),armv7)
227         arch = armv7
228         prefetch = yes
229         bits = 32
230 endif
231
232 ifeq ($(ARCH),armv8)
233         arch = armv8-a
234         prefetch = yes
235         popcnt = yes
236         neon = yes
237 endif
238
239 ifeq ($(ARCH),apple-silicon)
240         arch = arm64
241         prefetch = yes
242         popcnt = yes
243         neon = yes
244 endif
245
246 ifeq ($(ARCH),ppc-32)
247         arch = ppc
248         bits = 32
249 endif
250
251 ifeq ($(ARCH),ppc-64)
252         arch = ppc64
253         popcnt = yes
254         prefetch = yes
255 endif
256
257 ### ==========================================================================
258 ### Section 3. Low-level Configuration
259 ### ==========================================================================
260
261 ### 3.1 Selecting compiler (default = gcc)
262 CXXFLAGS += -Wall -Wcast-qual -fno-exceptions -std=c++17 $(EXTRACXXFLAGS)
263 DEPENDFLAGS += -std=c++17
264 LDFLAGS += $(EXTRALDFLAGS)
265
266 ifeq ($(COMP),)
267         COMP=gcc
268 endif
269
270 ifeq ($(COMP),gcc)
271         comp=gcc
272         CXX=g++
273         CXXFLAGS += -pedantic -Wextra
274
275         ifeq ($(ARCH),$(filter $(ARCH),armv7 armv8))
276                 ifeq ($(OS),Android)
277                         CXXFLAGS += -m$(bits)
278                         LDFLAGS += -m$(bits)
279                 endif
280         else
281                 CXXFLAGS += -m$(bits)
282                 LDFLAGS += -m$(bits)
283         endif
284
285         ifneq ($(KERNEL),Darwin)
286            LDFLAGS += -Wl,--no-as-needed
287         endif
288 endif
289
290 ifeq ($(COMP),mingw)
291         comp=mingw
292
293         ifeq ($(KERNEL),Linux)
294                 ifeq ($(bits),64)
295                         ifeq ($(shell which x86_64-w64-mingw32-c++-posix),)
296                                 CXX=x86_64-w64-mingw32-c++
297                         else
298                                 CXX=x86_64-w64-mingw32-c++-posix
299                         endif
300                 else
301                         ifeq ($(shell which i686-w64-mingw32-c++-posix),)
302                                 CXX=i686-w64-mingw32-c++
303                         else
304                                 CXX=i686-w64-mingw32-c++-posix
305                         endif
306                 endif
307         else
308                 CXX=g++
309         endif
310
311         CXXFLAGS += -Wextra -Wshadow
312         LDFLAGS += -static
313 endif
314
315 ifeq ($(COMP),icc)
316         comp=icc
317         CXX=icpc
318         CXXFLAGS += -diag-disable 1476,10120 -Wcheck -Wabi -Wdeprecated -strict-ansi
319 endif
320
321 ifeq ($(COMP),clang)
322         comp=clang
323         CXX=clang++
324         CXXFLAGS += -pedantic -Wextra -Wshadow
325
326         ifneq ($(KERNEL),Darwin)
327         ifneq ($(KERNEL),OpenBSD)
328                 LDFLAGS += -latomic
329         endif
330         endif
331
332         ifeq ($(ARCH),$(filter $(ARCH),armv7 armv8))
333                 ifeq ($(OS),Android)
334                         CXXFLAGS += -m$(bits)
335                         LDFLAGS += -m$(bits)
336                 endif
337         else
338                 CXXFLAGS += -m$(bits)
339                 LDFLAGS += -m$(bits)
340         endif
341 endif
342
343 ifeq ($(comp),icc)
344         profile_make = icc-profile-make
345         profile_use = icc-profile-use
346 else
347 ifeq ($(comp),clang)
348         profile_make = clang-profile-make
349         profile_use = clang-profile-use
350 else
351         profile_make = gcc-profile-make
352         profile_use = gcc-profile-use
353 endif
354 endif
355
356 ifeq ($(KERNEL),Darwin)
357         CXXFLAGS += -arch $(arch) -mmacosx-version-min=10.15
358         LDFLAGS += -arch $(arch) -mmacosx-version-min=10.15
359 endif
360
361 ### Travis CI script uses COMPILER to overwrite CXX
362 ifdef COMPILER
363         COMPCXX=$(COMPILER)
364 endif
365
366 ### Allow overwriting CXX from command line
367 ifdef COMPCXX
368         CXX=$(COMPCXX)
369 endif
370
371 ### On mingw use Windows threads, otherwise POSIX
372 ifneq ($(comp),mingw)
373         # On Android Bionic's C library comes with its own pthread implementation bundled in
374         ifneq ($(OS),Android)
375                 # Haiku has pthreads in its libroot, so only link it in on other platforms
376                 ifneq ($(KERNEL),Haiku)
377                         LDFLAGS += -lpthread
378                 endif
379         endif
380 endif
381
382 ### 3.2.1 Debugging
383 ifeq ($(debug),no)
384         CXXFLAGS += -DNDEBUG
385 else
386         CXXFLAGS += -g
387 endif
388
389 ### 3.2.2 Debugging with undefined behavior sanitizers
390 ifneq ($(sanitize),no)
391         CXXFLAGS += -g3 -fsanitize=$(sanitize)
392         LDFLAGS += -fsanitize=$(sanitize)
393 endif
394
395 ### 3.3 Optimization
396 ifeq ($(optimize),yes)
397
398         CXXFLAGS += -O3 -g
399
400         ifeq ($(comp),gcc)
401                 ifeq ($(OS), Android)
402                         CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
403                 endif
404         endif
405
406         ifeq ($(comp),$(filter $(comp),gcc clang icc))
407                 ifeq ($(KERNEL),Darwin)
408                         CXXFLAGS += -mdynamic-no-pic
409                 endif
410         endif
411 endif
412
413 ### 3.4 Bits
414 ifeq ($(bits),64)
415         CXXFLAGS += -DIS_64BIT
416 endif
417
418 ### 3.5 prefetch
419 ifeq ($(prefetch),yes)
420         ifeq ($(sse),yes)
421                 CXXFLAGS += -msse
422                 DEPENDFLAGS += -msse
423         endif
424 else
425         CXXFLAGS += -DNO_PREFETCH
426 endif
427
428 ### 3.6 popcnt
429 ifeq ($(popcnt),yes)
430         ifeq ($(arch),$(filter $(arch),ppc64 armv8-a arm64))
431                 CXXFLAGS += -DUSE_POPCNT
432         else ifeq ($(comp),icc)
433                 CXXFLAGS += -msse3 -DUSE_POPCNT
434         else
435                 CXXFLAGS += -msse3 -mpopcnt -DUSE_POPCNT
436         endif
437 endif
438
439 ifeq ($(avx2),yes)
440         CXXFLAGS += -DUSE_AVX2
441         ifeq ($(comp),$(filter $(comp),gcc clang mingw))
442                 CXXFLAGS += -mavx2
443         endif
444 endif
445
446 ifeq ($(avx512),yes)
447         CXXFLAGS += -DUSE_AVX512
448         ifeq ($(comp),$(filter $(comp),gcc clang mingw))
449                 CXXFLAGS += -mavx512bw
450         endif
451 endif
452
453 ifeq ($(sse42),yes)
454         CXXFLAGS += -DUSE_SSE42
455         ifeq ($(comp),$(filter $(comp),gcc clang mingw))
456                 CXXFLAGS += -msse4.2
457         endif
458 endif
459
460 ifeq ($(sse41),yes)
461         CXXFLAGS += -DUSE_SSE41
462         ifeq ($(comp),$(filter $(comp),gcc clang mingw))
463                 CXXFLAGS += -msse4.1
464         endif
465 endif
466
467 ifeq ($(ssse3),yes)
468         CXXFLAGS += -DUSE_SSSE3
469         ifeq ($(comp),$(filter $(comp),gcc clang mingw))
470                 CXXFLAGS += -mssse3
471         endif
472 endif
473
474 ifeq ($(sse3),yes)
475         CXXFLAGS += -DUSE_SSE3
476         ifeq ($(comp),$(filter $(comp),gcc clang mingw))
477                 CXXFLAGS += -msse3
478         endif
479 endif
480
481 ifeq ($(neon),yes)
482         CXXFLAGS += -DUSE_NEON
483 endif
484
485 ifeq ($(arch),x86_64)
486         CXXFLAGS += -DUSE_SSE2
487 endif
488
489 ### 3.7 pext
490 ifeq ($(pext),yes)
491         CXXFLAGS += -DUSE_PEXT
492         ifeq ($(comp),$(filter $(comp),gcc clang mingw))
493                 CXXFLAGS += -mbmi2
494         endif
495 endif
496
497 ### 3.8 Link Time Optimization
498 ### This is a mix of compile and link time options because the lto link phase
499 ### needs access to the optimization flags.
500 ifeq ($(optimize),yes)
501 ifeq ($(debug), no)
502         ifeq ($(comp),$(filter $(comp),gcc clang))
503                 CXXFLAGS += -flto
504                 LDFLAGS += $(CXXFLAGS)
505         endif
506
507 # To use LTO and static linking on windows, the tool chain requires a recent gcc:
508 # gcc version 10.1 in msys2 or TDM-GCC version 9.2 are know to work, older might not.
509 # So, only enable it for a cross from Linux by default.
510         ifeq ($(comp),mingw)
511         ifeq ($(KERNEL),Linux)
512                 CXXFLAGS += -flto
513                 LDFLAGS += $(CXXFLAGS)
514         endif
515         endif
516 endif
517 endif
518
519 ### 3.9 Android 5 can only run position independent executables. Note that this
520 ### breaks Android 4.0 and earlier.
521 ifeq ($(OS), Android)
522         CXXFLAGS += -fPIE
523         LDFLAGS += -fPIE -pie
524 endif
525
526 ### ==========================================================================
527 ### Section 4. Public Targets
528 ### ==========================================================================
529
530 help:
531         @echo ""
532         @echo "To compile stockfish, type: "
533         @echo ""
534         @echo "make target ARCH=arch [COMP=compiler] [COMPCXX=cxx]"
535         @echo ""
536         @echo "Supported targets:"
537         @echo ""
538         @echo "build                   > Standard build"
539         @echo "profile-build           > Standard build with PGO"
540         @echo "strip                   > Strip executable"
541         @echo "install                 > Install executable"
542         @echo "clean                   > Clean up"
543         @echo "net                     > Download the default nnue net"
544         @echo ""
545         @echo "Supported archs:"
546         @echo ""
547         @echo "x86-64-avx512           > x86 64-bit with avx512 support"
548         @echo "x86-64-bmi2             > x86 64-bit with bmi2 support"
549         @echo "x86-64-avx2             > x86 64-bit with avx2 support"
550         @echo "x86-64-sse42            > x86 64-bit with sse42 support"
551         @echo "x86-64-modern           > x86 64-bit with sse41 support (x86-64-sse41)"
552         @echo "x86-64-sse41            > x86 64-bit with sse41 support"
553         @echo "x86-64-ssse3            > x86 64-bit with ssse3 support"
554         @echo "x86-64-sse3-popcnt      > x86 64-bit with sse3 and popcnt support"
555         @echo "x86-64-sse3             > x86 64-bit with sse3 support"
556         @echo "x86-64                  > x86 64-bit generic"
557         @echo "x86-32                  > x86 32-bit (also enables SSE)"
558         @echo "x86-32-old              > x86 32-bit fall back for old hardware"
559         @echo "ppc-64                  > PPC 64-bit"
560         @echo "ppc-32                  > PPC 32-bit"
561         @echo "armv7                   > ARMv7 32-bit"
562         @echo "armv8                   > ARMv8 64-bit"
563         @echo "apple-silicon           > Apple silicon ARM64"
564         @echo "general-64              > unspecified 64-bit"
565         @echo "general-32              > unspecified 32-bit"
566         @echo ""
567         @echo "Supported compilers:"
568         @echo ""
569         @echo "gcc                     > Gnu compiler (default)"
570         @echo "mingw                   > Gnu compiler with MinGW under Windows"
571         @echo "clang                   > LLVM Clang compiler"
572         @echo "icc                     > Intel compiler"
573         @echo ""
574         @echo "Simple examples. If you don't know what to do, you likely want to run: "
575         @echo ""
576         @echo "make -j build ARCH=x86-64    (This is for 64-bit systems)"
577         @echo "make -j build ARCH=x86-32    (This is for 32-bit systems)"
578         @echo ""
579         @echo "Advanced examples, for experienced users: "
580         @echo ""
581         @echo "make -j build ARCH=x86-64-modern COMP=clang"
582         @echo "make -j profile-build ARCH=x86-64-bmi2 COMP=gcc COMPCXX=g++-4.8"
583         @echo ""
584         @echo "The selected architecture $(ARCH) enables the following configuration: "
585         @echo ""
586         @$(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
587
588
589 .PHONY: help build profile-build strip install clean net objclean profileclean \
590         config-sanity icc-profile-use icc-profile-make gcc-profile-use gcc-profile-make \
591         clang-profile-use clang-profile-make
592
593 build: config-sanity
594         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
595
596 profile-build: config-sanity objclean profileclean
597         @echo ""
598         @echo "Step 1/4. Building instrumented executable ..."
599         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
600         @echo ""
601         @echo "Step 2/4. Running benchmark for pgo-build ..."
602         $(PGOBENCH) > /dev/null
603         @echo ""
604         @echo "Step 3/4. Building optimized executable ..."
605         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) objclean
606         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
607         @echo ""
608         @echo "Step 4/4. Deleting profile data ..."
609         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) profileclean
610
611 strip:
612         strip $(EXE)
613
614 install:
615         -mkdir -p -m 755 $(BINDIR)
616         -cp $(EXE) $(BINDIR)
617         -strip $(BINDIR)/$(EXE)
618
619 #clean all
620 clean: objclean profileclean
621         @rm -f .depend *~ core
622
623 net:
624         $(eval nnuenet := $(shell grep EvalFile ucioption.cpp | grep Option | sed 's/.*\(nn-[a-z0-9]\{12\}.nnue\).*/\1/'))
625         @echo "Default net: $(nnuenet)"
626         $(eval nnuedownloadurl := https://tests.stockfishchess.org/api/nn/$(nnuenet))
627         $(eval curl_or_wget := $(shell if hash curl 2>/dev/null; then echo "curl -sL"; elif hash wget 2>/dev/null; then echo "wget -qO-"; fi))
628         @if test -f "$(nnuenet)"; then echo "Already available."; else echo "Downloading $(nnuedownloadurl)"; $(curl_or_wget) $(nnuedownloadurl) > $(nnuenet); fi
629
630 # clean binaries and objects
631 objclean:
632         @rm -f $(EXE) *.o ./syzygy/*.o ./nnue/*.o ./nnue/features/*.o
633
634 # clean auxiliary profiling files
635 profileclean:
636         @rm -rf profdir
637         @rm -f bench.txt *.gcda *.gcno ./syzygy/*.gcda ./nnue/*.gcda ./nnue/features/*.gcda
638         @rm -f stockfish.profdata *.profraw
639
640 default:
641         help
642
643 ### ==========================================================================
644 ### Section 5. Private Targets
645 ### ==========================================================================
646
647 all: $(EXE) client .depend
648
649 config-sanity:
650         @echo ""
651         @echo "Config:"
652         @echo "debug: '$(debug)'"
653         @echo "sanitize: '$(sanitize)'"
654         @echo "optimize: '$(optimize)'"
655         @echo "arch: '$(arch)'"
656         @echo "bits: '$(bits)'"
657         @echo "kernel: '$(KERNEL)'"
658         @echo "os: '$(OS)'"
659         @echo "prefetch: '$(prefetch)'"
660         @echo "popcnt: '$(popcnt)'"
661         @echo "sse: '$(sse)'"
662         @echo "sse3: '$(sse3)'"
663         @echo "ssse3: '$(ssse3)'"
664         @echo "sse41: '$(sse41)'"
665         @echo "sse42: '$(sse42)'"
666         @echo "avx2: '$(avx2)'"
667         @echo "pext: '$(pext)'"
668         @echo "avx512: '$(avx512)'"
669         @echo "neon: '$(neon)'"
670         @echo ""
671         @echo "Flags:"
672         @echo "CXX: $(CXX)"
673         @echo "CXXFLAGS: $(CXXFLAGS)"
674         @echo "LDFLAGS: $(LDFLAGS)"
675         @echo ""
676         @echo "Testing config sanity. If this fails, try 'make help' ..."
677         @echo ""
678         @test "$(debug)" = "yes" || test "$(debug)" = "no"
679         @test "$(sanitize)" = "undefined" || test "$(sanitize)" = "thread" || test "$(sanitize)" = "address" || test "$(sanitize)" = "no"
680         @test "$(optimize)" = "yes" || test "$(optimize)" = "no"
681         @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
682          test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || \
683          test "$(arch)" = "armv7" || test "$(arch)" = "armv8-a" || test "$(arch)" = "arm64"
684         @test "$(bits)" = "32" || test "$(bits)" = "64"
685         @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
686         @test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
687         @test "$(sse)" = "yes" || test "$(sse)" = "no"
688         @test "$(sse3)" = "yes" || test "$(sse3)" = "no"
689         @test "$(ssse3)" = "yes" || test "$(ssse3)" = "no"
690         @test "$(sse41)" = "yes" || test "$(sse41)" = "no"
691         @test "$(sse42)" = "yes" || test "$(sse42)" = "no"
692         @test "$(avx2)" = "yes" || test "$(avx2)" = "no"
693         @test "$(pext)" = "yes" || test "$(pext)" = "no"
694         @test "$(avx512)" = "yes" || test "$(avx512)" = "no"
695         @test "$(neon)" = "yes" || test "$(neon)" = "no"
696         @test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw" || test "$(comp)" = "clang"
697
698 $(EXE): $(OBJS)
699         $(CXX) -o $@ $(OBJS) $(LDFLAGS)
700
701 clang-profile-make:
702         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
703         EXTRACXXFLAGS='-fprofile-instr-generate ' \
704         EXTRALDFLAGS=' -fprofile-instr-generate' \
705         all
706
707 clang-profile-use:
708         llvm-profdata merge -output=stockfish.profdata *.profraw
709         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
710         EXTRACXXFLAGS='-fprofile-instr-use=stockfish.profdata' \
711         EXTRALDFLAGS='-fprofile-use ' \
712         all
713
714 gcc-profile-make:
715         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
716         EXTRACXXFLAGS='-fprofile-generate' \
717         EXTRALDFLAGS='-lgcov' \
718         all
719
720 gcc-profile-use:
721         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
722         EXTRACXXFLAGS='-fprofile-use -fno-peel-loops -fno-tracer' \
723         EXTRALDFLAGS='-lgcov' \
724         all
725
726 icc-profile-make:
727         @mkdir -p profdir
728         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
729         EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
730         all
731
732 icc-profile-use:
733         $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
734         EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
735         all
736
737 ### GRPC
738
739 PROTOS_PATH = .
740 PROTOC = protoc
741 GRPC_CPP_PLUGIN = grpc_cpp_plugin
742 GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)`
743
744 %.grpc.pb.h %.grpc.pb.cc: %.proto
745         $(PROTOC) -I $(PROTOS_PATH) --grpc_out=. --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $<
746
747 # oh my
748 %.cpp: %.cc
749         cp $< $@
750
751 %.pb.h %.pb.cc: %.proto
752         $(PROTOC) -I $(PROTOS_PATH) --cpp_out=. $<
753
754 #LDFLAGS += -Wl,-Bstatic -Wl,-\( -lprotobuf -lgrpc++_unsecure -lgrpc_unsecure -lgrpc -lz -Wl,-\) -Wl,-Bdynamic -ldl
755 LDFLAGS += /usr/lib/x86_64-linux-gnu/libprotobuf.a /usr/lib/x86_64-linux-gnu/libgrpc++_unsecure.a /usr/lib/x86_64-linux-gnu/libgrpc_unsecure.a /usr/lib/x86_64-linux-gnu/libgrpc.a /usr/lib/x86_64-linux-gnu/libcares.a -ldl -lz
756 #LDFLAGS += /usr/lib/x86_64-linux-gnu/libprotobuf.a /usr/lib/libgrpc++_unsecure.a /usr/lib/libgrpc_unsecure.a /usr/lib/libgrpc.a /usr/lib/x86_64-linux-gnu/libcares.a -ldl -lz
757
758 client: $(CLIOBJS)
759         $(CXX) -o $@ $(CLIOBJS) $(LDFLAGS)
760
761 # Other stuff
762
763 .depend:
764         -@$(CXX) $(DEPENDFLAGS) -MM $(SRCS) > $@ 2> /dev/null
765
766 -include .depend