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-2012 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
38 PGOBENCH = ./$(EXE) bench 32 1 10 default depth
41 OBJS = benchmark.o bitbase.o bitboard.o book.o endgame.o evaluate.o main.o \
42 material.o misc.o movegen.o movepick.o notation.o pawns.o position.o \
43 search.o thread.o timeman.o tt.o uci.o ucioption.o
45 ### ==========================================================================
46 ### Section 2. High-level Configuration
47 ### ==========================================================================
49 # flag --- Comp switch --- Description
50 # ----------------------------------------------------------------------------
52 # debug = yes/no --- -DNDEBUG --- Enable/Disable debug mode
53 # optimize = yes/no --- (-O3/-fast etc.) --- Enable/Disable optimizations
54 # arch = (name) --- (-arch) --- Target architecture
55 # os = (name) --- --- Target operating system
56 # bits = 64/32 --- -DIS_64BIT --- 64-/32-bit operating system
57 # prefetch = yes/no --- -DUSE_PREFETCH --- Use prefetch x86 asm-instruction
58 # bsfq = yes/no --- -DUSE_BSFQ --- Use bsfq x86_64 asm-instruction (only
59 # with GCC and ICC 64-bit)
60 # popcnt = yes/no --- -DUSE_POPCNT --- Use popcnt x86_64 asm-instruction
62 # Note that Makefile is space sensitive, so when adding new architectures
63 # or modifying existing flags, you have to make sure there are no extra spaces
64 # at the end of the line for flag values.
70 ### 2.2 Architecture specific
73 ifeq ($(ARCH),general-64)
82 ifeq ($(ARCH),general-32)
101 ifeq ($(ARCH),x86-64-modern)
110 ifeq ($(ARCH),x86-32)
119 ifeq ($(ARCH),x86-32-old)
139 ifeq ($(ARCH),osx-ppc-64)
148 ifeq ($(ARCH),osx-ppc-32)
157 ifeq ($(ARCH),osx-x86-64)
166 ifeq ($(ARCH),osx-x86-32)
176 ### ==========================================================================
177 ### Section 3. Low-level configuration
178 ### ==========================================================================
180 ### 3.1 Selecting compiler (default = gcc)
188 profile_prepare = gcc-profile-prepare
189 profile_make = gcc-profile-make
190 profile_use = gcc-profile-use
191 profile_clean = gcc-profile-clean
197 profile_prepare = gcc-profile-prepare
198 profile_make = gcc-profile-make
199 profile_use = gcc-profile-use
200 profile_clean = gcc-profile-clean
206 profile_prepare = icc-profile-prepare
207 profile_make = icc-profile-make
208 profile_use = icc-profile-use
209 profile_clean = icc-profile-clean
215 profile_prepare = gcc-profile-prepare
216 profile_make = gcc-profile-make
217 profile_use = gcc-profile-use
218 profile_clean = gcc-profile-clean
221 ### 3.2 General compiler settings
222 CXXFLAGS = -g -Wall -Wcast-qual -fno-exceptions -fno-rtti $(EXTRACXXFLAGS)
225 CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra -Wshadow
229 CXXFLAGS += -Wextra -Wshadow
233 CXXFLAGS += -wd383,981,1418,1419,10187,10188,11505,11503 -Wcheck -Wabi -Wdeprecated -strict-ansi
237 CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra -Wshadow
241 CXXFLAGS += -arch $(arch) -mmacosx-version-min=10.6
244 ### 3.3 General linker settings
245 LDFLAGS = $(EXTRALDFLAGS)
247 ### On mingw use Windows threads, otherwise POSIX
248 ifneq ($(comp),mingw)
249 # Haiku has pthreads in its libroot, so only link it in on other platforms
250 ifneq ($(UNAME),Haiku)
256 LDFLAGS += -arch $(arch) -mmacosx-version-min=10.6
265 ifeq ($(optimize),yes)
272 CXXFLAGS += -mdynamic-no-pic
274 ifeq ($(arch),x86_64)
275 CXXFLAGS += -mdynamic-no-pic
280 CXXFLAGS += -fno-gcse
290 CXXFLAGS += -fast -mdynamic-no-pic
297 ### -O4 requires a linker that supports LLVM's LTO
302 CXXFLAGS += -mdynamic-no-pic
304 ifeq ($(arch),x86_64)
305 CXXFLAGS += -mdynamic-no-pic
313 CXXFLAGS += -DIS_64BIT
317 ifeq ($(prefetch),yes)
318 ifneq ($(arch),armv7)
323 CXXFLAGS += -DNO_PREFETCH
328 CXXFLAGS += -DUSE_BSFQ
333 CXXFLAGS += -msse3 -DUSE_POPCNT
336 ### 3.10 Link Time Optimization, it works since gcc 4.5 but not on mingw.
337 ### This is a mix of compile and link time options because the lto link phase
338 ### needs access to the optimization flags.
340 ifeq ($(optimize),yes)
341 GCC_MAJOR := `$(CXX) -dumpversion | cut -f1 -d.`
342 GCC_MINOR := `$(CXX) -dumpversion | cut -f2 -d.`
343 ifeq (1,$(shell expr \( $(GCC_MAJOR) \> 4 \) \| \( $(GCC_MAJOR) \= 4 \& $(GCC_MINOR) \>= 5 \)))
345 LDFLAGS += $(CXXFLAGS)
350 ### ==========================================================================
351 ### Section 4. Public targets
352 ### ==========================================================================
356 @echo "To compile stockfish, type: "
358 @echo "make target ARCH=arch [COMP=comp]"
360 @echo "Supported targets:"
362 @echo "build > Build unoptimized version"
363 @echo "profile-build > Build PGO-optimized version"
364 @echo "strip > Strip executable"
365 @echo "install > Install executable"
366 @echo "clean > Clean up"
367 @echo "testrun > Make sample run"
369 @echo "Supported archs:"
371 @echo "x86-64 > x86 64-bit"
372 @echo "x86-64-modern > x86 64-bit with runtime support for popcnt instruction"
373 @echo "x86-32 > x86 32-bit excluding old hardware without SSE-support"
374 @echo "x86-32-old > x86 32-bit including also very old hardware"
375 @echo "osx-ppc-64 > PPC-Mac OS X 64 bit"
376 @echo "osx-ppc-32 > PPC-Mac OS X 32 bit"
377 @echo "osx-x86-64 > x86-Mac OS X 64 bit"
378 @echo "osx-x86-32 > x86-Mac OS X 32 bit"
379 @echo "armv7 > ARMv7 32 bit"
380 @echo "general-64 > unspecified 64-bit"
381 @echo "general-32 > unspecified 32-bit"
383 @echo "Supported comps:"
385 @echo "gcc > Gnu compiler (default)"
386 @echo "icc > Intel compiler"
387 @echo "mingw > Gnu compiler with MinGW under Windows"
388 @echo "clang > LLVM Clang compiler"
390 @echo "Non-standard targets:"
392 @echo "make hpux > Compile for HP-UX. Compiler = aCC"
394 @echo "Examples. If you don't know what to do, you likely want to run: "
396 @echo "make profile-build ARCH=x86-64 (This is for 64-bit systems)"
397 @echo "make profile-build ARCH=x86-32 (This is for 32-bit systems)"
401 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
402 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
405 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
407 @echo "Step 0/4. Preparing for profile build."
408 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
410 @echo "Step 1/4. Building executable for benchmark ..."
412 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
414 @echo "Step 2/4. Running benchmark for pgo-build ..."
415 @$(PGOBENCH) > /dev/null
417 @echo "Step 3/4. Building final executable ..."
419 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
421 @echo "Step 4/4. Deleting profile data ..."
422 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
428 -mkdir -p -m 755 $(BINDIR)
430 -strip $(BINDIR)/$(EXE)
433 $(RM) $(EXE) $(EXE).exe *.o .depend *~ core bench.txt *.gcda
441 ### ==========================================================================
442 ### Section 5. Private targets
443 ### ==========================================================================
450 @echo "debug: '$(debug)'"
451 @echo "optimize: '$(optimize)'"
452 @echo "arch: '$(arch)'"
454 @echo "bits: '$(bits)'"
455 @echo "prefetch: '$(prefetch)'"
456 @echo "bsfq: '$(bsfq)'"
457 @echo "popcnt: '$(popcnt)'"
461 @echo "CXXFLAGS: $(CXXFLAGS)"
462 @echo "LDFLAGS: $(LDFLAGS)"
464 @echo "Testing config sanity. If this fails, try 'make help' ..."
466 @test "$(debug)" = "yes" || test "$(debug)" = "no"
467 @test "$(optimize)" = "yes" || test "$(optimize)" = "no"
468 @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
469 test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "armv7"
470 @test "$(os)" = "any" || test "$(os)" = "osx"
471 @test "$(bits)" = "32" || test "$(bits)" = "64"
472 @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
473 @test "$(bsfq)" = "yes" || test "$(bsfq)" = "no"
474 @test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
475 @test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw" || test "$(comp)" = "clang"
478 $(CXX) -o $@ $(OBJS) $(LDFLAGS)
481 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) gcc-profile-clean
484 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
485 EXTRACXXFLAGS='-fprofile-generate' \
486 EXTRALDFLAGS='-lgcov' \
490 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
491 EXTRACXXFLAGS='-fprofile-use' \
492 EXTRALDFLAGS='-lgcov' \
496 @rm -rf *.gcda *.gcno bench.txt
499 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) icc-profile-clean
503 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
504 EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
508 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
509 EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
513 @rm -rf profdir bench.txt
516 -@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
521 ### ==========================================================================
522 ### Section 6. Non-standard targets
523 ### ==========================================================================
527 CXX='/opt/aCC/bin/aCC -AA +hpxstd98 -mt +O3 -DNDEBUG -DNO_PREFETCH' \