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-2013 Marco Costalba, Joona Kiiski, Tord Romstad
5 # Stockfish is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # Stockfish is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 ### ==========================================================================
20 ### Section 1. General Configuration
21 ### ==========================================================================
23 ### Establish the operating system name
24 UNAME = $(shell uname)
29 ### Installation dir definitions
31 # Haiku has a non-standard filesystem layout
35 BINDIR = $(PREFIX)/bin
37 ### Built-in benchmark for pgo-builds and signature
38 PGOBENCH = ./$(EXE) bench 32 1 10 default depth
39 SIGNBENCH = ./$(EXE) bench
42 OBJS = benchmark.o bitbase.o bitboard.o book.o endgame.o evaluate.o main.o \
43 material.o misc.o movegen.o movepick.o notation.o pawns.o position.o \
44 search.o thread.o timeman.o tt.o uci.o ucioption.o
46 ### ==========================================================================
47 ### Section 2. High-level Configuration
48 ### ==========================================================================
50 # flag --- Comp switch --- Description
51 # ----------------------------------------------------------------------------
53 # debug = yes/no --- -DNDEBUG --- Enable/Disable debug mode
54 # optimize = yes/no --- (-O3/-fast etc.) --- Enable/Disable optimizations
55 # arch = (name) --- (-arch) --- Target architecture
56 # os = (name) --- --- Target operating system
57 # bits = 64/32 --- -DIS_64BIT --- 64-/32-bit operating system
58 # prefetch = yes/no --- -DUSE_PREFETCH --- Use prefetch x86 asm-instruction
59 # bsfq = yes/no --- -DUSE_BSFQ --- Use bsfq x86_64 asm-instruction (only
60 # with GCC and ICC 64-bit)
61 # popcnt = yes/no --- -DUSE_POPCNT --- Use popcnt x86_64 asm-instruction
62 # sse = yes/no --- -msse --- Use Intel Streaming SIMD Extensions
64 # Note that Makefile is space sensitive, so when adding new architectures
65 # or modifying existing flags, you have to make sure there are no extra spaces
66 # at the end of the line for flag values.
72 ### 2.2 Architecture specific
75 ifeq ($(ARCH),general-64)
85 ifeq ($(ARCH),general-32)
106 ifeq ($(ARCH),x86-64-modern)
116 ifeq ($(ARCH),x86-32)
126 ifeq ($(ARCH),x86-32-old)
148 ifeq ($(ARCH),osx-ppc-64)
158 ifeq ($(ARCH),osx-ppc-32)
168 ifeq ($(ARCH),linux-ppc-64)
178 ifeq ($(ARCH),osx-x86-64)
188 ifeq ($(ARCH),osx-x86-32)
199 ### ==========================================================================
200 ### Section 3. Low-level configuration
201 ### ==========================================================================
203 ### 3.1 Selecting compiler (default = gcc)
211 profile_prepare = gcc-profile-prepare
212 profile_make = gcc-profile-make
213 profile_use = gcc-profile-use
214 profile_clean = gcc-profile-clean
220 profile_prepare = gcc-profile-prepare
221 profile_make = gcc-profile-make
222 profile_use = gcc-profile-use
223 profile_clean = gcc-profile-clean
229 profile_prepare = icc-profile-prepare
230 profile_make = icc-profile-make
231 profile_use = icc-profile-use
232 profile_clean = icc-profile-clean
238 profile_prepare = gcc-profile-prepare
239 profile_make = gcc-profile-make
240 profile_use = gcc-profile-use
241 profile_clean = gcc-profile-clean
244 ### 3.2 General compiler settings
245 CXXFLAGS = -Wall -Wcast-qual -fno-exceptions -fno-rtti $(EXTRACXXFLAGS)
248 CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra -Wshadow
252 CXXFLAGS += -Wextra -Wshadow
256 CXXFLAGS += -diag-disable 1476,10120 -Wcheck -Wabi -Wdeprecated -strict-ansi
260 CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra -Wshadow
264 CXXFLAGS += -arch $(arch) -mmacosx-version-min=10.0
267 ### 3.3 General linker settings
268 LDFLAGS = $(EXTRALDFLAGS)
271 LDFLAGS += -static-libstdc++ -static-libgcc
274 ### On mingw use Windows threads, otherwise POSIX
275 ifneq ($(comp),mingw)
276 # On Android Bionic's C library comes with its own pthread implementation bundled in
277 ifneq ($(arch),armv7)
278 # Haiku has pthreads in its libroot, so only link it in on other platforms
279 ifneq ($(UNAME),Haiku)
286 LDFLAGS += -arch $(arch) -mmacosx-version-min=10.0
297 ifeq ($(optimize),yes)
304 CXXFLAGS += -mdynamic-no-pic
306 ifeq ($(arch),x86_64)
307 CXXFLAGS += -mdynamic-no-pic
312 CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
322 CXXFLAGS += -fast -mdynamic-no-pic
329 ### -O4 requires a linker that supports LLVM's LTO
334 CXXFLAGS += -mdynamic-no-pic
336 ifeq ($(arch),x86_64)
337 CXXFLAGS += -mdynamic-no-pic
345 CXXFLAGS += -DIS_64BIT
349 ifeq ($(prefetch),yes)
355 CXXFLAGS += -DNO_PREFETCH
360 CXXFLAGS += -DUSE_BSFQ
365 CXXFLAGS += -msse3 -DUSE_POPCNT
368 ### 3.10 Link Time Optimization, it works since gcc 4.5 but not on mingw.
369 ### This is a mix of compile and link time options because the lto link phase
370 ### needs access to the optimization flags.
372 ifeq ($(optimize),yes)
374 GCC_MAJOR := `$(CXX) -dumpversion | cut -f1 -d.`
375 GCC_MINOR := `$(CXX) -dumpversion | cut -f2 -d.`
376 ifeq (1,$(shell expr \( $(GCC_MAJOR) \> 4 \) \| \( $(GCC_MAJOR) \= 4 \& $(GCC_MINOR) \>= 5 \)))
378 LDFLAGS += $(CXXFLAGS)
384 ### ==========================================================================
385 ### Section 4. Public targets
386 ### ==========================================================================
390 @echo "To compile stockfish, type: "
392 @echo "make target ARCH=arch [COMP=comp]"
394 @echo "Supported targets:"
396 @echo "build > Standard build"
397 @echo "signature-build > Standard build with embedded signature"
398 @echo "profile-build > PGO build"
399 @echo "signature-profile-build > PGO build with embedded signature"
400 @echo "strip > Strip executable"
401 @echo "install > Install executable"
402 @echo "clean > Clean up"
404 @echo "Supported archs:"
406 @echo "x86-64 > x86 64-bit"
407 @echo "x86-64-modern > x86 64-bit with popcnt support"
408 @echo "x86-32 > x86 32-bit with SSE support"
409 @echo "x86-32-old > x86 32-bit fall back for old hardware"
410 @echo "linux-ppc-64 > PPC-Linux 64 bit"
411 @echo "osx-ppc-64 > PPC-Mac OS X 64 bit"
412 @echo "osx-ppc-32 > PPC-Mac OS X 32 bit"
413 @echo "osx-x86-64 > x86-Mac OS X 64 bit"
414 @echo "osx-x86-32 > x86-Mac OS X 32 bit"
415 @echo "armv7 > ARMv7 32 bit"
416 @echo "general-64 > unspecified 64-bit"
417 @echo "general-32 > unspecified 32-bit"
419 @echo "Supported compilers:"
421 @echo "gcc > Gnu compiler (default)"
422 @echo "mingw > Gnu compiler with MinGW under Windows"
423 @echo "clang > LLVM Clang compiler"
424 @echo "icc > Intel compiler"
426 @echo "Non-standard targets:"
428 @echo "make hpux > Compile for HP-UX. Compiler = aCC"
430 @echo "Examples. If you don't know what to do, you likely want to run: "
432 @echo "make build ARCH=x86-64 (This is for 64-bit systems)"
433 @echo "make build ARCH=x86-32 (This is for 32-bit systems)"
436 .PHONY: build profile-build embed-signature
438 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
439 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
442 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
444 @echo "Step 0/4. Preparing for profile build."
445 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
447 @echo "Step 1/4. Building executable for benchmark ..."
449 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
451 @echo "Step 2/4. Running benchmark for pgo-build ..."
452 @$(PGOBENCH) > /dev/null
454 @echo "Step 3/4. Building final executable ..."
456 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
458 @echo "Step 4/4. Deleting profile data ..."
459 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
462 @echo "Running benchmark for getting the signature ..."
463 @$(SIGNBENCH) 2>&1 | sed -n 's/Nodes searched : \(.*\)/\/string Version\/s\/"\\(.*\\)"\/"sig-\1"\//p' > sign.txt
464 @sed -f sign.txt misc.cpp > misc2.cpp
465 @mv misc2.cpp misc.cpp
468 signature-build: build embed-signature
469 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
471 signature-profile-build: build embed-signature profile-build
477 -mkdir -p -m 755 $(BINDIR)
479 -strip $(BINDIR)/$(EXE)
482 $(RM) $(EXE) $(EXE).exe *.o .depend *~ core bench.txt *.gcda
487 ### ==========================================================================
488 ### Section 5. Private targets
489 ### ==========================================================================
496 @echo "debug: '$(debug)'"
497 @echo "optimize: '$(optimize)'"
498 @echo "arch: '$(arch)'"
500 @echo "bits: '$(bits)'"
501 @echo "prefetch: '$(prefetch)'"
502 @echo "bsfq: '$(bsfq)'"
503 @echo "popcnt: '$(popcnt)'"
504 @echo "sse: '$(sse)'"
508 @echo "CXXFLAGS: $(CXXFLAGS)"
509 @echo "LDFLAGS: $(LDFLAGS)"
511 @echo "Testing config sanity. If this fails, try 'make help' ..."
513 @test "$(debug)" = "yes" || test "$(debug)" = "no"
514 @test "$(optimize)" = "yes" || test "$(optimize)" = "no"
515 @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
516 test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "armv7"
517 @test "$(os)" = "any" || test "$(os)" = "osx"
518 @test "$(bits)" = "32" || test "$(bits)" = "64"
519 @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
520 @test "$(bsfq)" = "yes" || test "$(bsfq)" = "no"
521 @test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
522 @test "$(sse)" = "yes" || test "$(sse)" = "no"
523 @test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw" || test "$(comp)" = "clang"
526 $(CXX) -o $@ $(OBJS) $(LDFLAGS)
529 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) gcc-profile-clean
532 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
533 EXTRACXXFLAGS='-fprofile-generate' \
534 EXTRALDFLAGS='-lgcov' \
538 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
539 EXTRACXXFLAGS='-fprofile-use' \
540 EXTRALDFLAGS='-lgcov' \
544 @rm -rf *.gcda *.gcno bench.txt
547 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) icc-profile-clean
551 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
552 EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
556 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
557 EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
561 @rm -rf profdir bench.txt
564 -@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
569 ### ==========================================================================
570 ### Section 6. Non-standard targets
571 ### ==========================================================================
575 CXX='/opt/aCC/bin/aCC -AA +hpxstd98 -mt +O3 -DNDEBUG -DNO_PREFETCH' \