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
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
61 # sse = yes/no --- -msse --- Use Intel Streaming SIMD Extensions
63 # Note that Makefile is space sensitive, so when adding new architectures
64 # or modifying existing flags, you have to make sure there are no extra spaces
65 # at the end of the line for flag values.
71 ### 2.2 Architecture specific
74 ifeq ($(ARCH),general-64)
84 ifeq ($(ARCH),general-32)
105 ifeq ($(ARCH),x86-64-modern)
115 ifeq ($(ARCH),x86-32)
125 ifeq ($(ARCH),x86-32-old)
147 ifeq ($(ARCH),osx-ppc-64)
157 ifeq ($(ARCH),osx-ppc-32)
167 ifeq ($(ARCH),osx-x86-64)
177 ifeq ($(ARCH),osx-x86-32)
188 ### ==========================================================================
189 ### Section 3. Low-level configuration
190 ### ==========================================================================
192 ### 3.1 Selecting compiler (default = gcc)
200 profile_prepare = gcc-profile-prepare
201 profile_make = gcc-profile-make
202 profile_use = gcc-profile-use
203 profile_clean = gcc-profile-clean
209 profile_prepare = gcc-profile-prepare
210 profile_make = gcc-profile-make
211 profile_use = gcc-profile-use
212 profile_clean = gcc-profile-clean
218 profile_prepare = icc-profile-prepare
219 profile_make = icc-profile-make
220 profile_use = icc-profile-use
221 profile_clean = icc-profile-clean
227 profile_prepare = gcc-profile-prepare
228 profile_make = gcc-profile-make
229 profile_use = gcc-profile-use
230 profile_clean = gcc-profile-clean
233 ### 3.2 General compiler settings
234 CXXFLAGS = -Wall -Wcast-qual -fno-exceptions -fno-rtti $(EXTRACXXFLAGS)
237 CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra -Wshadow
241 CXXFLAGS += -Wextra -Wshadow
245 CXXFLAGS += -wd383,981,1418,1419,1476,10187,10188,11505,11503 -Wcheck -Wabi -Wdeprecated -strict-ansi
249 CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra -Wshadow
253 CXXFLAGS += -arch $(arch) -mmacosx-version-min=10.0
256 ### 3.3 General linker settings
257 LDFLAGS = $(EXTRALDFLAGS)
260 LDFLAGS += -static-libstdc++ -static-libgcc
263 ### On mingw use Windows threads, otherwise POSIX
264 ifneq ($(comp),mingw)
265 # Haiku has pthreads in its libroot, so only link it in on other platforms
266 ifneq ($(UNAME),Haiku)
272 LDFLAGS += -arch $(arch) -mmacosx-version-min=10.0
283 ifeq ($(optimize),yes)
290 CXXFLAGS += -mdynamic-no-pic
292 ifeq ($(arch),x86_64)
293 CXXFLAGS += -mdynamic-no-pic
298 CXXFLAGS += -fno-gcse
308 CXXFLAGS += -fast -mdynamic-no-pic
315 ### -O4 requires a linker that supports LLVM's LTO
320 CXXFLAGS += -mdynamic-no-pic
322 ifeq ($(arch),x86_64)
323 CXXFLAGS += -mdynamic-no-pic
331 CXXFLAGS += -DIS_64BIT
335 ifeq ($(prefetch),yes)
341 CXXFLAGS += -DNO_PREFETCH
346 CXXFLAGS += -DUSE_BSFQ
351 CXXFLAGS += -msse3 -DUSE_POPCNT
354 ### 3.10 Link Time Optimization, it works since gcc 4.5 but not on mingw.
355 ### This is a mix of compile and link time options because the lto link phase
356 ### needs access to the optimization flags.
358 ifeq ($(optimize),yes)
360 GCC_MAJOR := `$(CXX) -dumpversion | cut -f1 -d.`
361 GCC_MINOR := `$(CXX) -dumpversion | cut -f2 -d.`
362 ifeq (1,$(shell expr \( $(GCC_MAJOR) \> 4 \) \| \( $(GCC_MAJOR) \= 4 \& $(GCC_MINOR) \>= 5 \)))
364 LDFLAGS += $(CXXFLAGS)
370 ### ==========================================================================
371 ### Section 4. Public targets
372 ### ==========================================================================
376 @echo "To compile stockfish, type: "
378 @echo "make target ARCH=arch [COMP=comp]"
380 @echo "Supported targets:"
382 @echo "build > Build unoptimized version"
383 @echo "profile-build > Build PGO-optimized version"
384 @echo "strip > Strip executable"
385 @echo "install > Install executable"
386 @echo "clean > Clean up"
387 @echo "testrun > Make sample run"
389 @echo "Supported archs:"
391 @echo "x86-64 > x86 64-bit"
392 @echo "x86-64-modern > x86 64-bit with runtime support for popcnt instruction"
393 @echo "x86-32 > x86 32-bit excluding old hardware without SSE-support"
394 @echo "x86-32-old > x86 32-bit including also very old hardware"
395 @echo "osx-ppc-64 > PPC-Mac OS X 64 bit"
396 @echo "osx-ppc-32 > PPC-Mac OS X 32 bit"
397 @echo "osx-x86-64 > x86-Mac OS X 64 bit"
398 @echo "osx-x86-32 > x86-Mac OS X 32 bit"
399 @echo "armv7 > ARMv7 32 bit"
400 @echo "general-64 > unspecified 64-bit"
401 @echo "general-32 > unspecified 32-bit"
403 @echo "Supported comps:"
405 @echo "gcc > Gnu compiler (default)"
406 @echo "icc > Intel compiler"
407 @echo "mingw > Gnu compiler with MinGW under Windows"
408 @echo "clang > LLVM Clang compiler"
410 @echo "Non-standard targets:"
412 @echo "make hpux > Compile for HP-UX. Compiler = aCC"
414 @echo "Examples. If you don't know what to do, you likely want to run: "
416 @echo "make profile-build ARCH=x86-64 (This is for 64-bit systems)"
417 @echo "make profile-build ARCH=x86-32 (This is for 32-bit systems)"
421 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
422 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
425 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
427 @echo "Step 0/4. Preparing for profile build."
428 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
430 @echo "Step 1/4. Building executable for benchmark ..."
432 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
434 @echo "Step 2/4. Running benchmark for pgo-build ..."
435 @$(PGOBENCH) > /dev/null
437 @echo "Step 3/4. Building final executable ..."
439 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
441 @echo "Step 4/4. Deleting profile data ..."
442 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
448 -mkdir -p -m 755 $(BINDIR)
450 -strip $(BINDIR)/$(EXE)
453 $(RM) $(EXE) $(EXE).exe *.o .depend *~ core bench.txt *.gcda
461 ### ==========================================================================
462 ### Section 5. Private targets
463 ### ==========================================================================
470 @echo "debug: '$(debug)'"
471 @echo "optimize: '$(optimize)'"
472 @echo "arch: '$(arch)'"
474 @echo "bits: '$(bits)'"
475 @echo "prefetch: '$(prefetch)'"
476 @echo "bsfq: '$(bsfq)'"
477 @echo "popcnt: '$(popcnt)'"
478 @echo "sse: '$(sse)'"
482 @echo "CXXFLAGS: $(CXXFLAGS)"
483 @echo "LDFLAGS: $(LDFLAGS)"
485 @echo "Testing config sanity. If this fails, try 'make help' ..."
487 @test "$(debug)" = "yes" || test "$(debug)" = "no"
488 @test "$(optimize)" = "yes" || test "$(optimize)" = "no"
489 @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
490 test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "armv7"
491 @test "$(os)" = "any" || test "$(os)" = "osx"
492 @test "$(bits)" = "32" || test "$(bits)" = "64"
493 @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
494 @test "$(bsfq)" = "yes" || test "$(bsfq)" = "no"
495 @test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
496 @test "$(sse)" = "yes" || test "$(sse)" = "no"
497 @test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw" || test "$(comp)" = "clang"
500 $(CXX) -o $@ $(OBJS) $(LDFLAGS)
503 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) gcc-profile-clean
506 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
507 EXTRACXXFLAGS='-fprofile-generate' \
508 EXTRALDFLAGS='-lgcov' \
512 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
513 EXTRACXXFLAGS='-fprofile-use' \
514 EXTRALDFLAGS='-lgcov' \
518 @rm -rf *.gcda *.gcno bench.txt
521 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) icc-profile-clean
525 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
526 EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
530 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
531 EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
535 @rm -rf profdir bench.txt
538 -@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
543 ### ==========================================================================
544 ### Section 6. Non-standard targets
545 ### ==========================================================================
549 CXX='/opt/aCC/bin/aCC -AA +hpxstd98 -mt +O3 -DNDEBUG -DNO_PREFETCH' \