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
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 = -g -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,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)
259 ### On mingw use Windows threads, otherwise POSIX
260 ifneq ($(comp),mingw)
261 # Haiku has pthreads in its libroot, so only link it in on other platforms
262 ifneq ($(UNAME),Haiku)
268 LDFLAGS += -arch $(arch) -mmacosx-version-min=10.0
277 ifeq ($(optimize),yes)
284 CXXFLAGS += -mdynamic-no-pic
286 ifeq ($(arch),x86_64)
287 CXXFLAGS += -mdynamic-no-pic
292 CXXFLAGS += -fno-gcse
302 CXXFLAGS += -fast -mdynamic-no-pic
309 ### -O4 requires a linker that supports LLVM's LTO
314 CXXFLAGS += -mdynamic-no-pic
316 ifeq ($(arch),x86_64)
317 CXXFLAGS += -mdynamic-no-pic
325 CXXFLAGS += -DIS_64BIT
329 ifeq ($(prefetch),yes)
335 CXXFLAGS += -DNO_PREFETCH
340 CXXFLAGS += -DUSE_BSFQ
345 CXXFLAGS += -msse3 -DUSE_POPCNT
348 ### 3.10 Link Time Optimization, it works since gcc 4.5 but not on mingw.
349 ### This is a mix of compile and link time options because the lto link phase
350 ### needs access to the optimization flags.
352 ifeq ($(optimize),yes)
353 GCC_MAJOR := `$(CXX) -dumpversion | cut -f1 -d.`
354 GCC_MINOR := `$(CXX) -dumpversion | cut -f2 -d.`
355 ifeq (1,$(shell expr \( $(GCC_MAJOR) \> 4 \) \| \( $(GCC_MAJOR) \= 4 \& $(GCC_MINOR) \>= 5 \)))
357 LDFLAGS += $(CXXFLAGS)
362 ### ==========================================================================
363 ### Section 4. Public targets
364 ### ==========================================================================
368 @echo "To compile stockfish, type: "
370 @echo "make target ARCH=arch [COMP=comp]"
372 @echo "Supported targets:"
374 @echo "build > Build unoptimized version"
375 @echo "profile-build > Build PGO-optimized version"
376 @echo "strip > Strip executable"
377 @echo "install > Install executable"
378 @echo "clean > Clean up"
379 @echo "testrun > Make sample run"
381 @echo "Supported archs:"
383 @echo "x86-64 > x86 64-bit"
384 @echo "x86-64-modern > x86 64-bit with runtime support for popcnt instruction"
385 @echo "x86-32 > x86 32-bit excluding old hardware without SSE-support"
386 @echo "x86-32-old > x86 32-bit including also very old hardware"
387 @echo "osx-ppc-64 > PPC-Mac OS X 64 bit"
388 @echo "osx-ppc-32 > PPC-Mac OS X 32 bit"
389 @echo "osx-x86-64 > x86-Mac OS X 64 bit"
390 @echo "osx-x86-32 > x86-Mac OS X 32 bit"
391 @echo "armv7 > ARMv7 32 bit"
392 @echo "general-64 > unspecified 64-bit"
393 @echo "general-32 > unspecified 32-bit"
395 @echo "Supported comps:"
397 @echo "gcc > Gnu compiler (default)"
398 @echo "icc > Intel compiler"
399 @echo "mingw > Gnu compiler with MinGW under Windows"
400 @echo "clang > LLVM Clang compiler"
402 @echo "Non-standard targets:"
404 @echo "make hpux > Compile for HP-UX. Compiler = aCC"
406 @echo "Examples. If you don't know what to do, you likely want to run: "
408 @echo "make profile-build ARCH=x86-64 (This is for 64-bit systems)"
409 @echo "make profile-build ARCH=x86-32 (This is for 32-bit systems)"
413 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
414 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
417 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
419 @echo "Step 0/4. Preparing for profile build."
420 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
422 @echo "Step 1/4. Building executable for benchmark ..."
424 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
426 @echo "Step 2/4. Running benchmark for pgo-build ..."
427 @$(PGOBENCH) > /dev/null
429 @echo "Step 3/4. Building final executable ..."
431 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
433 @echo "Step 4/4. Deleting profile data ..."
434 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
440 -mkdir -p -m 755 $(BINDIR)
442 -strip $(BINDIR)/$(EXE)
445 $(RM) $(EXE) $(EXE).exe *.o .depend *~ core bench.txt *.gcda
453 ### ==========================================================================
454 ### Section 5. Private targets
455 ### ==========================================================================
462 @echo "debug: '$(debug)'"
463 @echo "optimize: '$(optimize)'"
464 @echo "arch: '$(arch)'"
466 @echo "bits: '$(bits)'"
467 @echo "prefetch: '$(prefetch)'"
468 @echo "bsfq: '$(bsfq)'"
469 @echo "popcnt: '$(popcnt)'"
470 @echo "sse: '$(sse)'"
474 @echo "CXXFLAGS: $(CXXFLAGS)"
475 @echo "LDFLAGS: $(LDFLAGS)"
477 @echo "Testing config sanity. If this fails, try 'make help' ..."
479 @test "$(debug)" = "yes" || test "$(debug)" = "no"
480 @test "$(optimize)" = "yes" || test "$(optimize)" = "no"
481 @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
482 test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "armv7"
483 @test "$(os)" = "any" || test "$(os)" = "osx"
484 @test "$(bits)" = "32" || test "$(bits)" = "64"
485 @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
486 @test "$(bsfq)" = "yes" || test "$(bsfq)" = "no"
487 @test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
488 @test "$(sse)" = "yes" || test "$(sse)" = "no"
489 @test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw" || test "$(comp)" = "clang"
492 $(CXX) -o $@ $(OBJS) $(LDFLAGS)
495 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) gcc-profile-clean
498 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
499 EXTRACXXFLAGS='-fprofile-generate' \
500 EXTRALDFLAGS='-lgcov' \
504 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
505 EXTRACXXFLAGS='-fprofile-use' \
506 EXTRALDFLAGS='-lgcov' \
510 @rm -rf *.gcda *.gcno bench.txt
513 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) icc-profile-clean
517 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
518 EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
522 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
523 EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
527 @rm -rf profdir bench.txt
530 -@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
535 ### ==========================================================================
536 ### Section 6. Non-standard targets
537 ### ==========================================================================
541 CXX='/opt/aCC/bin/aCC -AA +hpxstd98 -mt +O3 -DNDEBUG -DNO_PREFETCH' \