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-2010 Marco Costalba, Joona Kiiski, Tord Romstad
5 # This file is part of Stockfish.
7 # Stockfish is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # Stockfish is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ### ==========================================================================
22 ### Section 1. General Configuration
23 ### ==========================================================================
28 ### Installation dir definitions
30 BINDIR = $(PREFIX)/bin
32 ### Built-in benchmark for pgo-builds
33 PGOBENCH = ./$(EXE) bench 32 1 10 default depth
36 OBJS = bitboard.o pawns.o material.o endgame.o evaluate.o main.o \
37 misc.o move.o movegen.o history.o movepick.o search.o position.o \
38 direction.o tt.o uci.o ucioption.o book.o bitbase.o san.o benchmark.o timeman.o
41 ### ==========================================================================
42 ### Section 2. High-level Configuration
43 ### ==========================================================================
45 # flag --- Comp switch --- Description
46 # ----------------------------------------------------------------------------
48 # debug = no/yes --- -DNDEBUG --- Enable/Disable debug mode
49 # optimize = yes/no --- (-O3/-fast etc.) --- Enable/Disable optimizations
50 # arch = (name) --- (-arch) --- Target architecture
51 # os = (name) --- --- Target operating system
52 # bits = 64/32 --- -DIS_64BIT --- 64-/32-bit operating system
53 # bigendian = no/yes --- -DBIGENDIAN --- big/little-endian byte order
54 # prefetch = no/yes --- -DUSE_PREFETCH --- Use prefetch x86 asm-instruction
55 # bsfq = no/yes --- -DUSE_BSFQ --- Use bsfq x86_64 asm-instruction
56 # --- (Works only with GCC and ICC 64-bit)
57 # popcnt = no/yes --- -DUSE_POPCNT --- Use popcnt x86_64 asm-instruction
59 # Note that Makefile is space sensitive, so when adding new architectures
60 # or modifying existing flags, you have to make sure there are no extra spaces
61 # at the end of the line for flag values.
67 ### 2.2 Architecture specific
70 ifeq ($(ARCH),general-64)
80 ifeq ($(ARCH),general-32)
90 ifeq ($(ARCH),bigendian-64)
100 ifeq ($(ARCH),bigendian-32)
111 ifeq ($(ARCH),x86-64)
121 ifeq ($(ARCH),x86-64-modern)
131 ifeq ($(ARCH),x86-32)
141 ifeq ($(ARCH),x86-32-old)
152 ifeq ($(ARCH),osx-ppc-64)
162 ifeq ($(ARCH),osx-ppc-32)
172 ifeq ($(ARCH),osx-x86-64)
182 ifeq ($(ARCH),osx-x86-32)
193 ### ==========================================================================
194 ### Section 3. Low-level configuration
195 ### ==========================================================================
197 ### 3.1 Selecting compiler (default = gcc)
205 profile_prepare = gcc-profile-prepare
206 profile_make = gcc-profile-make
207 profile_use = gcc-profile-use
208 profile_clean = gcc-profile-clean
214 profile_prepare = gcc-profile-prepare
215 profile_make = gcc-profile-make
216 profile_use = gcc-profile-use
217 profile_clean = gcc-profile-clean
223 profile_prepare = icc-profile-prepare
224 profile_make = icc-profile-make
225 profile_use = icc-profile-use
226 profile_clean = icc-profile-clean
229 ### 3.2 General compiler settings
230 CXXFLAGS = -g -Wall -Wcast-qual -fno-exceptions -fno-rtti $(EXTRACXXFLAGS)
233 CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra
237 CXXFLAGS += -Wno-long-long -Wextra
241 CXXFLAGS += -wd383,981,10187,10188,11505,11503 -Wcheck -Wabi -Wdeprecated -strict-ansi
245 CXXFLAGS += -arch $(arch)
248 ### 3.3 General linker settings
249 LDFLAGS = -lpthread $(EXTRALDFLAGS)
252 LDFLAGS += -arch $(arch)
261 ifeq ($(optimize),yes)
268 CXXFLAGS += -mdynamic-no-pic
270 ifeq ($(arch),x86_64)
271 CXXFLAGS += -mdynamic-no-pic
284 CXXFLAGS += -mdynamic-no-pic
291 CXXFLAGS += -DIS_64BIT
295 ifeq ($(bigendian),yes)
296 CXXFLAGS += -DBIGENDIAN
300 ifeq ($(prefetch),yes)
304 CXXFLAGS += -DNO_PREFETCH
309 CXXFLAGS += -DUSE_BSFQ
314 CXXFLAGS += -DUSE_POPCNT
317 ### ==========================================================================
318 ### Section 4. Public targets
319 ### ==========================================================================
322 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) build
326 @echo "To compile stockfish, type: "
328 @echo "make target ARCH=arch [COMP=comp]"
330 @echo "Supported targets:"
332 @echo "build > Build unoptimized version"
333 @echo "profile-build > Build PGO-optimized version"
334 @echo "popcnt-profile-build > Build PGO-optimized version with optional popcnt-support"
335 @echo "strip > Strip executable"
336 @echo "install > Install executable"
337 @echo "clean > Clean up"
338 @echo "testrun > Make sample run"
340 @echo "Supported archs:"
342 @echo "x86-64 > x86 64-bit"
343 @echo "x86-64-modern > x86 64-bit with runtime support for popcnt-instruction"
344 @echo "x86-32 > x86 32-bit excluding very old hardware without SSE-support"
345 @echo "x86-32-old > x86 32-bit including also very old hardware"
346 @echo "osx-ppc-64 > PPC-Mac OS X 64 bit"
347 @echo "osx-ppc-32 > PPC-Mac OS X 32 bit"
348 @echo "osx-x86-64 > x86-Mac OS X 64 bit"
349 @echo "osx-x86-32 > x86-Mac OS X 32 bit"
350 @echo "general-64 > unspecified 64-bit"
351 @echo "general-32 > unspecified 32-bit"
352 @echo "bigendian-64 > unspecified 64-bit with bigendian byte order"
353 @echo "bigendian-32 > unspecified 32-bit with bigendian byte order"
355 @echo "Supported comps:"
357 @echo "gcc > Gnu compiler (default)"
358 @echo "icc > Intel compiler"
359 @echo "mingw > Gnu compiler with MinGW under Windows"
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)
395 popcnt-profile-build:
396 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
398 @echo "Step 0/6. Preparing for profile build."
399 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
401 @echo "Step 1/6. Building executable for benchmark (popcnt disabled)..."
403 $(MAKE) ARCH=x86-64 COMP=$(COMP) $(profile_make)
405 @echo "Step 2/6. Running benchmark for pgo-build (popcnt disabled)..."
406 @$(PGOBENCH) > /dev/null
408 @echo "Step 3/6. Building executable for benchmark (popcnt enabled)..."
410 $(MAKE) ARCH=x86-64-modern COMP=$(COMP) $(profile_make)
412 @echo "Step 4/6. Running benchmark for pgo-build (popcnt enabled)..."
413 @$(PGOBENCH) > /dev/null
415 @echo "Step 5/6. Building final executable ..."
417 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
419 @echo "Step 6/6. Deleting profile data ..."
420 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
427 -mkdir -p -m 755 $(BINDIR)
429 -strip $(BINDIR)/$(EXE)
432 $(RM) $(EXE) $(EXE).exe *.o .depend *~ core bench.txt *.gcda
437 ### ==========================================================================
438 ### Section 5. Private targets
439 ### ==========================================================================
446 @echo "debug: '$(debug)'"
447 @echo "optimize: '$(optimize)'"
448 @echo "arch: '$(arch)'"
450 @echo "bits: '$(bits)'"
451 @echo "bigendian: '$(bigendian)'"
452 @echo "prefetch: '$(prefetch)'"
453 @echo "bsfq: '$(bsfq)'"
454 @echo "popcnt: '$(popcnt)'"
458 @echo "CXXFLAGS: $(CXXFLAGS)"
459 @echo "LDFLAGS: $(LDFLAGS)"
461 @echo "Testing config sanity. If this fails, try 'make help' ..."
463 @test "$(debug)" = "yes" || test "$(debug)" = "no"
464 @test "$(optimize)" = "yes" || test "$(optimize)" = "no"
465 @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
466 test "$(arch)" = "ppc64" || test "$(arch)" = "ppc"
467 @test "$(os)" = "any" || test "$(os)" = "osx"
468 @test "$(bits)" = "32" || test "$(bits)" = "64"
469 @test "$(bigendian)" = "yes" || test "$(bigendian)" = "no"
470 @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
471 @test "$(bsfq)" = "yes" || test "$(bsfq)" = "no"
472 @test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
473 @test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw"
476 $(CXX) -o $@ $(OBJS) $(LDFLAGS)
479 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) gcc-profile-clean
482 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
483 EXTRACXXFLAGS='-fprofile-generate' \
484 EXTRALDFLAGS='-lgcov' \
488 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
489 EXTRACXXFLAGS='-fprofile-use' \
493 @rm -rf *.gcda *.gcno bench.txt
496 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) icc-profile-clean
500 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
501 EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
505 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
506 EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
510 @rm -rf profdir bench.txt
513 -@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
518 ### ==========================================================================
519 ### Section 6. Non-standard targets
520 ### ==========================================================================
524 CXX='/opt/aCC/bin/aCC -AA +hpxstd98 -DBIGENDIAN -mt +O3 -DNDEBUG -DNO_PREFETCH' \