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 ### ==========================================================================
26 ### Installation dir definitions
28 BINDIR = $(PREFIX)/bin
30 ### Built-in benchmark for pgo-builds
31 PGOBENCH = ./$(EXE) bench 32 1 10 default depth
34 OBJS = benchmark.o bitbase.o bitboard.o book.o endgame.o evaluate.o main.o \
35 material.o misc.o movegen.o movepick.o notation.o pawns.o position.o \
36 search.o thread.o timeman.o tt.o uci.o ucioption.o
38 ### ==========================================================================
39 ### Section 2. High-level Configuration
40 ### ==========================================================================
42 # flag --- Comp switch --- Description
43 # ----------------------------------------------------------------------------
45 # debug = yes/no --- -DNDEBUG --- Enable/Disable debug mode
46 # optimize = yes/no --- (-O3/-fast etc.) --- Enable/Disable optimizations
47 # arch = (name) --- (-arch) --- Target architecture
48 # os = (name) --- --- Target operating system
49 # bits = 64/32 --- -DIS_64BIT --- 64-/32-bit operating system
50 # prefetch = yes/no --- -DUSE_PREFETCH --- Use prefetch x86 asm-instruction
51 # bsfq = yes/no --- -DUSE_BSFQ --- Use bsfq x86_64 asm-instruction (only
52 # with GCC and ICC 64-bit)
53 # popcnt = yes/no --- -DUSE_POPCNT --- Use popcnt x86_64 asm-instruction
55 # Note that Makefile is space sensitive, so when adding new architectures
56 # or modifying existing flags, you have to make sure there are no extra spaces
57 # at the end of the line for flag values.
63 ### 2.2 Architecture specific
66 ifeq ($(ARCH),general-64)
75 ifeq ($(ARCH),general-32)
94 ifeq ($(ARCH),x86-64-modern)
103 ifeq ($(ARCH),x86-32)
112 ifeq ($(ARCH),x86-32-old)
122 ifeq ($(ARCH),osx-ppc-64)
131 ifeq ($(ARCH),osx-ppc-32)
140 ifeq ($(ARCH),osx-x86-64)
149 ifeq ($(ARCH),osx-x86-32)
159 ### ==========================================================================
160 ### Section 3. Low-level configuration
161 ### ==========================================================================
163 ### 3.1 Selecting compiler (default = gcc)
171 profile_prepare = gcc-profile-prepare
172 profile_make = gcc-profile-make
173 profile_use = gcc-profile-use
174 profile_clean = gcc-profile-clean
180 profile_prepare = gcc-profile-prepare
181 profile_make = gcc-profile-make
182 profile_use = gcc-profile-use
183 profile_clean = gcc-profile-clean
189 profile_prepare = icc-profile-prepare
190 profile_make = icc-profile-make
191 profile_use = icc-profile-use
192 profile_clean = icc-profile-clean
198 profile_prepare = gcc-profile-prepare
199 profile_make = gcc-profile-make
200 profile_use = gcc-profile-use
201 profile_clean = gcc-profile-clean
204 ### 3.2 General compiler settings
205 CXXFLAGS = -g -Wall -Wcast-qual -fno-exceptions -fno-rtti $(EXTRACXXFLAGS)
208 CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra -Wshadow
212 CXXFLAGS += -Wextra -Wshadow
216 CXXFLAGS += -wd383,981,1418,1419,10187,10188,11505,11503 -Wcheck -Wabi -Wdeprecated -strict-ansi
220 CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra -Wshadow
224 CXXFLAGS += -arch $(arch)
227 ### 3.3 General linker settings
228 LDFLAGS = $(EXTRALDFLAGS)
230 ### On mingw use Windows threads, otherwise POSIX
231 ifneq ($(comp),mingw)
236 LDFLAGS += -arch $(arch)
245 ifeq ($(optimize),yes)
252 CXXFLAGS += -mdynamic-no-pic
254 ifeq ($(arch),x86_64)
255 CXXFLAGS += -mdynamic-no-pic
266 CXXFLAGS += -fast -mdynamic-no-pic
273 ### -O4 requires a linker that supports LLVM's LTO
278 CXXFLAGS += -mdynamic-no-pic
280 ifeq ($(arch),x86_64)
281 CXXFLAGS += -mdynamic-no-pic
289 CXXFLAGS += -DIS_64BIT
293 ifeq ($(prefetch),yes)
297 CXXFLAGS += -DNO_PREFETCH
302 CXXFLAGS += -DUSE_BSFQ
307 CXXFLAGS += -msse3 -DUSE_POPCNT
310 ### 3.10 Link Time Optimization, it works since gcc 4.5 but not on mingw.
311 ### This is a mix of compile and link time options because the lto link phase
312 ### needs access to the optimization flags.
314 GCC_MAJOR := `$(CXX) -dumpversion | cut -f1 -d.`
315 GCC_MINOR := `$(CXX) -dumpversion | cut -f2 -d.`
316 ifeq (1,$(shell expr \( $(GCC_MAJOR) \> 4 \) \| \( $(GCC_MAJOR) \= 4 \& $(GCC_MINOR) \>= 5 \)))
318 LDFLAGS += $(CXXFLAGS)
322 ### ==========================================================================
323 ### Section 4. Public targets
324 ### ==========================================================================
328 @echo "To compile stockfish, type: "
330 @echo "make target ARCH=arch [COMP=comp]"
332 @echo "Supported targets:"
334 @echo "build > Build unoptimized version"
335 @echo "profile-build > Build PGO-optimized version"
336 @echo "strip > Strip executable"
337 @echo "install > Install executable"
338 @echo "clean > Clean up"
339 @echo "testrun > Make sample run"
341 @echo "Supported archs:"
343 @echo "x86-64 > x86 64-bit"
344 @echo "x86-64-modern > x86 64-bit with runtime support for popcnt instruction"
345 @echo "x86-32 > x86 32-bit excluding old hardware without SSE-support"
346 @echo "x86-32-old > x86 32-bit including also very old hardware"
347 @echo "osx-ppc-64 > PPC-Mac OS X 64 bit"
348 @echo "osx-ppc-32 > PPC-Mac OS X 32 bit"
349 @echo "osx-x86-64 > x86-Mac OS X 64 bit"
350 @echo "osx-x86-32 > x86-Mac OS X 32 bit"
351 @echo "general-64 > unspecified 64-bit"
352 @echo "general-32 > unspecified 32-bit"
354 @echo "Supported comps:"
356 @echo "gcc > Gnu compiler (default)"
357 @echo "icc > Intel compiler"
358 @echo "mingw > Gnu compiler with MinGW under Windows"
359 @echo "clang > LLVM Clang compiler"
361 @echo "Non-standard targets:"
363 @echo "make hpux > Compile for HP-UX. Compiler = aCC"
365 @echo "Examples. If you don't know what to do, you likely want to run: "
367 @echo "make profile-build ARCH=x86-64 (This is for 64-bit systems)"
368 @echo "make profile-build ARCH=x86-32 (This is for 32-bit systems)"
372 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
373 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
376 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
378 @echo "Step 0/4. Preparing for profile build."
379 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
381 @echo "Step 1/4. Building executable for benchmark ..."
383 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
385 @echo "Step 2/4. Running benchmark for pgo-build ..."
386 @$(PGOBENCH) > /dev/null
388 @echo "Step 3/4. Building final executable ..."
390 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
392 @echo "Step 4/4. Deleting profile data ..."
393 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
399 -mkdir -p -m 755 $(BINDIR)
401 -strip $(BINDIR)/$(EXE)
404 $(RM) $(EXE) $(EXE).exe *.o .depend *~ core bench.txt *.gcda
412 ### ==========================================================================
413 ### Section 5. Private targets
414 ### ==========================================================================
421 @echo "debug: '$(debug)'"
422 @echo "optimize: '$(optimize)'"
423 @echo "arch: '$(arch)'"
425 @echo "bits: '$(bits)'"
426 @echo "prefetch: '$(prefetch)'"
427 @echo "bsfq: '$(bsfq)'"
428 @echo "popcnt: '$(popcnt)'"
432 @echo "CXXFLAGS: $(CXXFLAGS)"
433 @echo "LDFLAGS: $(LDFLAGS)"
435 @echo "Testing config sanity. If this fails, try 'make help' ..."
437 @test "$(debug)" = "yes" || test "$(debug)" = "no"
438 @test "$(optimize)" = "yes" || test "$(optimize)" = "no"
439 @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
440 test "$(arch)" = "ppc64" || test "$(arch)" = "ppc"
441 @test "$(os)" = "any" || test "$(os)" = "osx"
442 @test "$(bits)" = "32" || test "$(bits)" = "64"
443 @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
444 @test "$(bsfq)" = "yes" || test "$(bsfq)" = "no"
445 @test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
446 @test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw" || test "$(comp)" = "clang"
449 $(CXX) -o $@ $(OBJS) $(LDFLAGS)
452 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) gcc-profile-clean
455 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
456 EXTRACXXFLAGS='-fprofile-generate' \
457 EXTRALDFLAGS='-lgcov' \
461 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
462 EXTRACXXFLAGS='-fprofile-use' \
463 EXTRALDFLAGS='-lgcov' \
467 @rm -rf *.gcda *.gcno bench.txt
470 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) icc-profile-clean
474 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
475 EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
479 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
480 EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
484 @rm -rf profdir bench.txt
487 -@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
492 ### ==========================================================================
493 ### Section 6. Non-standard targets
494 ### ==========================================================================
498 CXX='/opt/aCC/bin/aCC -AA +hpxstd98 -mt +O3 -DNDEBUG -DNO_PREFETCH' \