Rev 154 | Rev 182 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 154 | Rev 169 | ||
---|---|---|---|
Line 2... | Line 2... | ||
2 | # Copyright (C) 2004-2008 Tord Romstad (Glaurung author) |
2 | # Copyright (C) 2004-2008 Tord Romstad (Glaurung author) |
3 | # Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad |
3 | # Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad |
4 | # Copyright (C) 2015- |
4 | # Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad |
5 | # |
5 | # |
6 | # Stockfish is free software: you can redistribute it and/or modify |
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 |
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 |
8 | # the Free Software Foundation, either version 3 of the License, or |
9 | # (at your option) any later version. |
9 | # (at your option) any later version. |
Line 48... | Line 48... | ||
48 | # |
48 | # |
49 | # flag --- Comp switch --- Description |
49 | # flag --- Comp switch --- Description |
50 | # ---------------------------------------------------------------------------- |
50 | # ---------------------------------------------------------------------------- |
51 | # |
51 | # |
52 | # debug = yes/no --- -DNDEBUG --- Enable/Disable debug mode |
52 | # debug = yes/no --- -DNDEBUG --- Enable/Disable debug mode |
- | 53 | # sanitize = undefined/thread/no (-fsanitize ) |
|
53 | # |
54 | # --- ( undefined ) --- enable undefined behavior checks |
- | 55 | # --- ( thread ) --- enable threading error checks |
|
54 | # optimize = yes/no --- (-O3/-fast etc.) --- Enable/Disable optimizations |
56 | # optimize = yes/no --- (-O3/-fast etc.) --- Enable/Disable optimizations |
55 | # arch = (name) --- (-arch) --- Target architecture |
57 | # arch = (name) --- (-arch) --- Target architecture |
56 | # bits = 64/32 --- -DIS_64BIT --- 64-/32-bit operating system |
58 | # bits = 64/32 --- -DIS_64BIT --- 64-/32-bit operating system |
57 | # prefetch = yes/no --- -DUSE_PREFETCH --- Use prefetch asm-instruction |
59 | # prefetch = yes/no --- -DUSE_PREFETCH --- Use prefetch asm-instruction |
58 | # popcnt = yes/no --- -DUSE_POPCNT --- Use popcnt asm-instruction |
60 | # popcnt = yes/no --- -DUSE_POPCNT --- Use popcnt asm-instruction |
Line 137... | Line 139... | ||
137 | ### Section 3. Low-level configuration |
139 | ### Section 3. Low-level configuration |
138 | ### ========================================================================== |
140 | ### ========================================================================== |
139 | 141 | ||
140 | ### 3.1 Selecting compiler (default = gcc) |
142 | ### 3.1 Selecting compiler (default = gcc) |
141 | 143 | ||
142 | CXXFLAGS += -Wall -Wcast-qual -fno-exceptions |
144 | CXXFLAGS += -Wall -Wcast-qual -fno-exceptions -std=c++11 $(EXTRACXXFLAGS) |
143 | DEPENDFLAGS += -std=c++11 |
145 | DEPENDFLAGS += -std=c++11 |
144 | LDFLAGS += $(EXTRALDFLAGS) |
146 | LDFLAGS += $(EXTRALDFLAGS) |
145 | 147 | ||
146 | ifeq ($(COMP),) |
148 | ifeq ($(COMP),) |
147 | COMP=gcc |
149 | COMP=gcc |
Line 153... | Line 155... | ||
153 | CXXFLAGS += -pedantic -Wextra -Wshadow |
155 | CXXFLAGS += -pedantic -Wextra -Wshadow |
154 | 156 | ||
155 | ifeq ($(ARCH),armv7) |
157 | ifeq ($(ARCH),armv7) |
156 | ifeq ($(OS),Android) |
158 | ifeq ($(OS),Android) |
157 | CXXFLAGS += -m$(bits) |
159 | CXXFLAGS += -m$(bits) |
- | 160 | LDFLAGS += -m$(bits) |
|
158 | endif |
161 | endif |
159 | else |
162 | else |
160 | CXXFLAGS += -m$(bits) |
163 | CXXFLAGS += -m$(bits) |
- | 164 | LDFLAGS += -m$(bits) |
|
161 | endif |
165 | endif |
162 | 166 | ||
163 | ifneq ($(KERNEL),Darwin) |
167 | ifneq ($(KERNEL),Darwin) |
164 | LDFLAGS += -Wl,--no-as-needed |
168 | LDFLAGS += -Wl,--no-as-needed |
165 | endif |
169 | endif |
Line 198... | Line 202... | ||
198 | 202 | ||
199 | ifeq ($(COMP),clang) |
203 | ifeq ($(COMP),clang) |
200 | comp=clang |
204 | comp=clang |
201 | CXX=clang++ |
205 | CXX=clang++ |
202 | CXXFLAGS += -pedantic -Wextra -Wshadow |
206 | CXXFLAGS += -pedantic -Wextra -Wshadow |
- | 207 | ifneq ($(KERNEL),Darwin) |
|
- | 208 | ifneq ($(KERNEL),OpenBSD) |
|
- | 209 | LDFLAGS += -latomic |
|
- | 210 | endif |
|
- | 211 | endif |
|
203 | 212 | ||
204 | ifeq ($(ARCH),armv7) |
213 | ifeq ($(ARCH),armv7) |
205 | ifeq ($(OS),Android) |
214 | ifeq ($(OS),Android) |
206 | CXXFLAGS += -m$(bits) |
215 | CXXFLAGS += -m$(bits) |
207 | LDFLAGS += -m$(bits) |
216 | LDFLAGS += -m$(bits) |
208 | endif |
217 | endif |
209 | else |
218 | else |
210 | CXXFLAGS += -m$(bits) |
219 | CXXFLAGS += -m$(bits) |
211 | LDFLAGS += -m$(bits) |
220 | LDFLAGS += -m$(bits) |
212 | endif |
- | |
213 | - | ||
214 | ifeq ($(KERNEL),Darwin) |
- | |
215 | CXXFLAGS += -stdlib=libc++ |
- | |
216 | DEPENDFLAGS += -stdlib=libc++ |
- | |
217 | endif |
221 | endif |
218 | endif |
222 | endif |
219 | 223 | ||
220 | ifeq ($(comp),icc) |
224 | ifeq ($(comp),icc) |
221 | profile_prepare = icc-profile-prepare |
- | |
222 | profile_make = icc-profile-make |
225 | profile_make = icc-profile-make |
223 | profile_use = icc-profile-use |
226 | profile_use = icc-profile-use |
224 | profile_clean = icc-profile-clean |
- | |
225 | else |
227 | else |
- | 228 | ifeq ($(comp),clang) |
|
226 |
|
229 | profile_make = clang-profile-make |
- | 230 | profile_use = clang-profile-use |
|
- | 231 | else |
|
227 | profile_make = gcc-profile-make |
232 | profile_make = gcc-profile-make |
228 | profile_use = gcc-profile-use |
233 | profile_use = gcc-profile-use |
229 |
|
234 | endif |
230 | endif |
235 | endif |
231 | 236 | ||
232 | ifeq ($(KERNEL),Darwin) |
237 | ifeq ($(KERNEL),Darwin) |
233 | CXXFLAGS += -arch $(arch) -mmacosx-version-min=10.9 |
238 | CXXFLAGS += -arch $(arch) -mmacosx-version-min=10.9 |
234 | LDFLAGS += -arch $(arch) -mmacosx-version-min=10.9 |
239 | LDFLAGS += -arch $(arch) -mmacosx-version-min=10.9 |
Line 261... | Line 266... | ||
261 | else |
266 | else |
262 | CXXFLAGS += -g |
267 | CXXFLAGS += -g |
263 | endif |
268 | endif |
264 | 269 | ||
265 | ### 3.2.2 Debugging with undefined behavior sanitizers |
270 | ### 3.2.2 Debugging with undefined behavior sanitizers |
266 |
|
271 | ifneq ($(sanitize),no) |
267 |
|
272 | CXXFLAGS += -g3 -fsanitize=$(sanitize) -fuse-ld=gold |
- | 273 | LDFLAGS += -fsanitize=$(sanitize) -fuse-ld=gold |
|
268 | endif |
274 | endif |
269 | 275 | ||
270 | ### 3.3 Optimization |
276 | ### 3.3 Optimization |
271 | ifeq ($(optimize),yes) |
277 | ifeq ($(optimize),yes) |
272 | 278 | ||
Line 294... | Line 300... | ||
294 | endif |
300 | endif |
295 | endif |
301 | endif |
296 | 302 | ||
297 | ifeq ($(comp),clang) |
303 | ifeq ($(comp),clang) |
298 | ifeq ($(KERNEL),Darwin) |
304 | ifeq ($(KERNEL),Darwin) |
299 | ifeq ($(pext),no) |
- | |
300 | CXXFLAGS += -flto |
305 | CXXFLAGS += -flto |
301 | LDFLAGS += $(CXXFLAGS) |
306 | LDFLAGS += $(CXXFLAGS) |
302 | endif |
- | |
303 | ifeq ($(arch),i386) |
307 | ifeq ($(arch),i386) |
304 | CXXFLAGS += -mdynamic-no-pic |
308 | CXXFLAGS += -mdynamic-no-pic |
305 | endif |
309 | endif |
306 | ifeq ($(arch),x86_64) |
310 | ifeq ($(arch),x86_64) |
307 | CXXFLAGS += -mdynamic-no-pic |
311 | CXXFLAGS += -mdynamic-no-pic |
Line 421... | Line 425... | ||
421 | @echo "make build ARCH=x86-64 COMP=clang" |
425 | @echo "make build ARCH=x86-64 COMP=clang" |
422 | @echo "make profile-build ARCH=x86-64-modern COMP=gcc COMPCXX=g++-4.8" |
426 | @echo "make profile-build ARCH=x86-64-modern COMP=gcc COMPCXX=g++-4.8" |
423 | @echo "" |
427 | @echo "" |
424 | 428 | ||
425 | 429 | ||
- | 430 | .PHONY: help build profile-build strip install clean objclean profileclean help \ |
|
- | 431 | config-sanity icc-profile-use icc-profile-make gcc-profile-use gcc-profile-make \ |
|
426 |
|
432 | clang-profile-use clang-profile-make |
427 | build: |
433 | |
428 |
|
434 | build: config-sanity |
429 | $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all |
435 | $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all |
430 | 436 | ||
431 | profile-build: |
- | |
432 | $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity |
- | |
433 | @echo "" |
- | |
434 |
|
437 | profile-build: config-sanity objclean profileclean |
435 | $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare) |
- | |
436 | @echo "" |
438 | @echo "" |
437 | @echo "Step 1/4. Building |
439 | @echo "Step 1/4. Building instrumented executable ..." |
438 | @touch *.cpp *.h syzygy/*.cpp syzygy/*.h |
- | |
439 | $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make) |
440 | $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make) |
440 | @echo "" |
441 | @echo "" |
441 | @echo "Step 2/4. Running benchmark for pgo-build ..." |
442 | @echo "Step 2/4. Running benchmark for pgo-build ..." |
442 | $(PGOBENCH) > /dev/null |
443 | $(PGOBENCH) > /dev/null |
443 | @echo "" |
444 | @echo "" |
444 | @echo "Step 3/4. Building |
445 | @echo "Step 3/4. Building optimized executable ..." |
445 |
|
446 | $(MAKE) ARCH=$(ARCH) COMP=$(COMP) objclean |
446 | $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use) |
447 | $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use) |
447 | @echo "" |
448 | @echo "" |
448 | @echo "Step 4/4. Deleting profile data ..." |
449 | @echo "Step 4/4. Deleting profile data ..." |
449 | $(MAKE) ARCH=$(ARCH) COMP=$(COMP) |
450 | $(MAKE) ARCH=$(ARCH) COMP=$(COMP) profileclean |
450 | 451 | ||
451 | strip: |
452 | strip: |
452 | strip $(EXE) |
453 | strip $(EXE) |
453 | 454 | ||
454 | install: |
455 | install: |
455 | -mkdir -p -m 755 $(BINDIR) |
456 | -mkdir -p -m 755 $(BINDIR) |
456 | -cp $(EXE) $(BINDIR) |
457 | -cp $(EXE) $(BINDIR) |
457 | -strip $(BINDIR)/$(EXE) |
458 | -strip $(BINDIR)/$(EXE) |
458 | 459 | ||
- | 460 | #clean all |
|
- | 461 | clean: objclean profileclean |
|
- | 462 | @rm -f .depend *~ core |
|
- | 463 | ||
- | 464 | # clean binaries and objects |
|
459 |
|
465 | objclean: |
- | 466 | @rm -f $(EXE) $(EXE).exe *.o ./syzygy/*.o |
|
- | 467 | ||
- | 468 | # clean auxiliary profiling files |
|
- | 469 | profileclean: |
|
- | 470 | @rm -rf profdir |
|
460 |
|
471 | @rm -f bench.txt *.gcda ./syzygy/*.gcda *.gcno ./syzygy/*.gcno |
- | 472 | @rm -f stockfish.profdata *.profraw |
|
461 | 473 | ||
462 | default: |
474 | default: |
463 | help |
475 | help |
464 | 476 | ||
465 | ### ========================================================================== |
477 | ### ========================================================================== |
Line 470... | Line 482... | ||
470 | 482 | ||
471 | config-sanity: |
483 | config-sanity: |
472 | @echo "" |
484 | @echo "" |
473 | @echo "Config:" |
485 | @echo "Config:" |
474 | @echo "debug: '$(debug)'" |
486 | @echo "debug: '$(debug)'" |
- | 487 | @echo "sanitize: '$(sanitize)'" |
|
475 | @echo "optimize: '$(optimize)'" |
488 | @echo "optimize: '$(optimize)'" |
476 | @echo "arch: '$(arch)'" |
489 | @echo "arch: '$(arch)'" |
477 | @echo "bits: '$(bits)'" |
490 | @echo "bits: '$(bits)'" |
478 | @echo "kernel: '$(KERNEL)'" |
491 | @echo "kernel: '$(KERNEL)'" |
479 | @echo "os: '$(OS)'" |
492 | @echo "os: '$(OS)'" |
Line 488... | Line 501... | ||
488 | @echo "LDFLAGS: $(LDFLAGS)" |
501 | @echo "LDFLAGS: $(LDFLAGS)" |
489 | @echo "" |
502 | @echo "" |
490 | @echo "Testing config sanity. If this fails, try 'make help' ..." |
503 | @echo "Testing config sanity. If this fails, try 'make help' ..." |
491 | @echo "" |
504 | @echo "" |
492 | @test "$(debug)" = "yes" || test "$(debug)" = "no" |
505 | @test "$(debug)" = "yes" || test "$(debug)" = "no" |
- | 506 | @test "$(sanitize)" = "undefined" || test "$(sanitize)" = "thread" || test "$(sanitize)" = "no" |
|
493 | @test "$(optimize)" = "yes" || test "$(optimize)" = "no" |
507 | @test "$(optimize)" = "yes" || test "$(optimize)" = "no" |
494 | @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \ |
508 | @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \ |
495 | test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "armv7" |
509 | test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "armv7" |
496 | @test "$(bits)" = "32" || test "$(bits)" = "64" |
510 | @test "$(bits)" = "32" || test "$(bits)" = "64" |
497 | @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no" |
511 | @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no" |
Line 501... | Line 515... | ||
501 | @test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw" || test "$(comp)" = "clang" |
515 | @test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw" || test "$(comp)" = "clang" |
502 | 516 | ||
503 | $(EXE): $(OBJS) |
517 | $(EXE): $(OBJS) |
504 | $(CXX) -o $@ $(OBJS) $(LDFLAGS) |
518 | $(CXX) -o $@ $(OBJS) $(LDFLAGS) |
505 | 519 | ||
506 |
|
520 | clang-profile-make: |
- | 521 | $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \ |
|
- | 522 | EXTRACXXFLAGS='-fprofile-instr-generate ' \ |
|
- | 523 | EXTRALDFLAGS=' -fprofile-instr-generate' \ |
|
- | 524 | all |
|
- | 525 | ||
- | 526 | clang-profile-use: |
|
- | 527 | llvm-profdata merge -output=stockfish.profdata *.profraw |
|
507 | $(MAKE) ARCH=$(ARCH) COMP=$(COMP) |
528 | $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \ |
- | 529 | EXTRACXXFLAGS='-fprofile-instr-use=stockfish.profdata' \ |
|
- | 530 | EXTRALDFLAGS='-fprofile-use ' \ |
|
- | 531 | all |
|
508 | 532 | ||
509 | gcc-profile-make: |
533 | gcc-profile-make: |
510 | $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \ |
534 | $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \ |
511 | EXTRACXXFLAGS='-fprofile-generate' \ |
535 | EXTRACXXFLAGS='-fprofile-generate' \ |
512 | EXTRALDFLAGS='-lgcov' \ |
536 | EXTRALDFLAGS='-lgcov' \ |
Line 515... | Line 539... | ||
515 | gcc-profile-use: |
539 | gcc-profile-use: |
516 | $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \ |
540 | $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \ |
517 | EXTRACXXFLAGS='-fprofile-use -fno-peel-loops -fno-tracer' \ |
541 | EXTRACXXFLAGS='-fprofile-use -fno-peel-loops -fno-tracer' \ |
518 | EXTRALDFLAGS='-lgcov' \ |
542 | EXTRALDFLAGS='-lgcov' \ |
519 | all |
543 | all |
520 | - | ||
521 | gcc-profile-clean: |
- | |
522 | @rm -rf *.gcda *.gcno syzygy/*.gcda syzygy/*.gcno bench.txt |
- | |
523 | - | ||
524 | icc-profile-prepare: |
- | |
525 | $(MAKE) ARCH=$(ARCH) COMP=$(COMP) icc-profile-clean |
- | |
526 | @mkdir profdir |
- | |
527 | 544 | ||
528 | icc-profile-make: |
545 | icc-profile-make: |
- | 546 | @mkdir -p profdir |
|
529 | $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \ |
547 | $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \ |
530 | EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \ |
548 | EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \ |
531 | all |
549 | all |
532 | 550 | ||
533 | icc-profile-use: |
551 | icc-profile-use: |
534 | $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \ |
552 | $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \ |
535 | EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \ |
553 | EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \ |
536 | all |
554 | all |
537 | - | ||
538 | icc-profile-clean: |
- | |
539 | @rm -rf profdir bench.txt |
- | |
540 | 555 | ||
541 | .depend: |
556 | .depend: |
542 | -@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null |
557 | -@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null |
543 | 558 | ||
544 | -include .depend |
559 | -include .depend |