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.
68 ### 2.1. General and architecture defaults
80 ### 2.2 Architecture specific
82 ifeq ($(ARCH),x86-32-old)
93 ifeq ($(ARCH),general-64)
105 ifeq ($(ARCH),x86-64-modern)
121 ifeq ($(ARCH),osx-ppc-32)
127 ifeq ($(ARCH),osx-ppc-64)
133 ifeq ($(ARCH),linux-ppc-64)
138 ifeq ($(ARCH),osx-x86-64)
147 ifeq ($(ARCH),osx-x86-64-modern)
157 ifeq ($(ARCH),osx-x86-32)
168 ### ==========================================================================
169 ### Section 3. Low-level configuration
170 ### ==========================================================================
172 ### 3.1 Selecting compiler (default = gcc)
198 profile_prepare = icc-profile-prepare
199 profile_make = icc-profile-make
200 profile_use = icc-profile-use
201 profile_clean = icc-profile-clean
203 profile_prepare = gcc-profile-prepare
204 profile_make = gcc-profile-make
205 profile_use = gcc-profile-use
206 profile_clean = gcc-profile-clean
209 ### 3.2 General compiler and linker settings
210 CXXFLAGS = -Wall -Wcast-qual -fno-exceptions -fno-rtti $(EXTRACXXFLAGS)
211 LDFLAGS += $(EXTRALDFLAGS)
214 CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra -Wshadow
218 CXXFLAGS += -Wextra -Wshadow
219 LDFLAGS += -static-libstdc++ -static-libgcc
223 CXXFLAGS += -diag-disable 1476,10120 -Wcheck -Wabi -Wdeprecated -strict-ansi
227 CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra -Wshadow
231 CXXFLAGS += -arch $(arch) -mmacosx-version-min=10.6
232 LDFLAGS += -arch $(arch) -mmacosx-version-min=10.6
235 ### On mingw use Windows threads, otherwise POSIX
236 ifneq ($(comp),mingw)
237 # On Android Bionic's C library comes with its own pthread implementation bundled in
238 ifneq ($(arch),armv7)
239 # Haiku has pthreads in its libroot, so only link it in on other platforms
240 ifneq ($(UNAME),Haiku)
254 ifeq ($(optimize),yes)
261 CXXFLAGS += -mdynamic-no-pic
263 ifeq ($(arch),x86_64)
264 CXXFLAGS += -mdynamic-no-pic
269 CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
279 CXXFLAGS += -fast -mdynamic-no-pic
287 # Clang on OS X supports LTO
295 CXXFLAGS += -mdynamic-no-pic
297 ifeq ($(arch),x86_64)
298 CXXFLAGS += -mdynamic-no-pic
306 CXXFLAGS += -DIS_64BIT
310 ifeq ($(prefetch),yes)
316 CXXFLAGS += -DNO_PREFETCH
321 CXXFLAGS += -DUSE_BSFQ
326 CXXFLAGS += -msse3 -DUSE_POPCNT
329 ### 3.10 Link Time Optimization, it works since gcc 4.5 but not on mingw.
330 ### This is a mix of compile and link time options because the lto link phase
331 ### needs access to the optimization flags.
333 ifeq ($(optimize),yes)
335 GCC_MAJOR := `$(CXX) -dumpversion | cut -f1 -d.`
336 GCC_MINOR := `$(CXX) -dumpversion | cut -f2 -d.`
337 ifeq (1,$(shell expr \( $(GCC_MAJOR) \> 4 \) \| \( $(GCC_MAJOR) \= 4 \& $(GCC_MINOR) \>= 5 \)))
339 LDFLAGS += $(CXXFLAGS)
345 ### ==========================================================================
346 ### Section 4. Public targets
347 ### ==========================================================================
351 @echo "To compile stockfish, type: "
353 @echo "make target ARCH=arch [COMP=comp]"
355 @echo "Supported targets:"
357 @echo "build > Standard build"
358 @echo "signature-build > Standard build with embedded signature"
359 @echo "profile-build > PGO build"
360 @echo "signature-profile-build > PGO build with embedded signature"
361 @echo "strip > Strip executable"
362 @echo "install > Install executable"
363 @echo "clean > Clean up"
365 @echo "Supported archs:"
367 @echo "x86-64 > x86 64-bit"
368 @echo "x86-64-modern > x86 64-bit with popcnt support"
369 @echo "x86-32 > x86 32-bit with SSE support"
370 @echo "x86-32-old > x86 32-bit fall back for old hardware"
371 @echo "linux-ppc-64 > PPC-Linux 64 bit"
372 @echo "osx-ppc-64 > PPC-Mac OS X 64 bit"
373 @echo "osx-ppc-32 > PPC-Mac OS X 32 bit"
374 @echo "osx-x86-64-modern > x86-Mac OS X 64 bit with popcnt support"
375 @echo "osx-x86-64 > x86-Mac OS X 64 bit"
376 @echo "osx-x86-32 > x86-Mac OS X 32 bit"
377 @echo "armv7 > ARMv7 32 bit"
378 @echo "general-64 > unspecified 64-bit"
379 @echo "general-32 > unspecified 32-bit"
381 @echo "Supported compilers:"
383 @echo "gcc > Gnu compiler (default)"
384 @echo "mingw > Gnu compiler with MinGW under Windows"
385 @echo "clang > LLVM Clang compiler"
386 @echo "icc > Intel compiler"
388 @echo "Non-standard targets:"
390 @echo "make hpux > Compile for HP-UX. Compiler = aCC"
392 @echo "Examples. If you don't know what to do, you likely want to run: "
394 @echo "make build ARCH=x86-64 (This is for 64-bit systems)"
395 @echo "make build ARCH=x86-32 (This is for 32-bit systems)"
398 .PHONY: build profile-build embed-signature
400 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
401 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
404 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
406 @echo "Step 0/4. Preparing for profile build."
407 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
409 @echo "Step 1/4. Building executable for benchmark ..."
411 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
413 @echo "Step 2/4. Running benchmark for pgo-build ..."
414 @$(PGOBENCH) > /dev/null
416 @echo "Step 3/4. Building final executable ..."
418 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
420 @echo "Step 4/4. Deleting profile data ..."
421 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
424 @echo "Running benchmark for getting the signature ..."
425 @$(SIGNBENCH) 2>&1 | sed -n 's/Nodes searched : \(.*\)/\/string Version\/s\/"\\(.*\\)"\/"sig-\1"\//p' > sign.txt
426 @sed -f sign.txt misc.cpp > misc2.cpp
427 @mv misc2.cpp misc.cpp
430 signature-build: build embed-signature
431 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
433 signature-profile-build: build embed-signature profile-build
439 -mkdir -p -m 755 $(BINDIR)
441 -strip $(BINDIR)/$(EXE)
444 $(RM) $(EXE) $(EXE).exe *.o .depend *~ core bench.txt *.gcda
449 ### ==========================================================================
450 ### Section 5. Private targets
451 ### ==========================================================================
458 @echo "debug: '$(debug)'"
459 @echo "optimize: '$(optimize)'"
460 @echo "arch: '$(arch)'"
462 @echo "bits: '$(bits)'"
463 @echo "prefetch: '$(prefetch)'"
464 @echo "bsfq: '$(bsfq)'"
465 @echo "popcnt: '$(popcnt)'"
466 @echo "sse: '$(sse)'"
470 @echo "CXXFLAGS: $(CXXFLAGS)"
471 @echo "LDFLAGS: $(LDFLAGS)"
473 @echo "Testing config sanity. If this fails, try 'make help' ..."
475 @test "$(debug)" = "yes" || test "$(debug)" = "no"
476 @test "$(optimize)" = "yes" || test "$(optimize)" = "no"
477 @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
478 test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "armv7"
479 @test "$(os)" = "any" || test "$(os)" = "osx"
480 @test "$(bits)" = "32" || test "$(bits)" = "64"
481 @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
482 @test "$(bsfq)" = "yes" || test "$(bsfq)" = "no"
483 @test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
484 @test "$(sse)" = "yes" || test "$(sse)" = "no"
485 @test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw" || test "$(comp)" = "clang"
488 $(CXX) -o $@ $(OBJS) $(LDFLAGS)
491 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) gcc-profile-clean
494 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
495 EXTRACXXFLAGS='-fprofile-generate' \
496 EXTRALDFLAGS='-lgcov' \
500 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
501 EXTRACXXFLAGS='-fprofile-use' \
502 EXTRALDFLAGS='-lgcov' \
506 @rm -rf *.gcda *.gcno bench.txt
509 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) icc-profile-clean
513 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
514 EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
518 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
519 EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
523 @rm -rf profdir bench.txt
526 -@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
531 ### ==========================================================================
532 ### Section 6. Non-standard targets
533 ### ==========================================================================
537 CXX='/opt/aCC/bin/aCC -AA +hpxstd98 -mt +O3 -DNDEBUG -DNO_PREFETCH' \