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 = application.o 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 piece.o \
38 position.o direction.o tt.o uci.o ucioption.o \
39 mersenne.o book.o bitbase.o san.o benchmark.o timeman.o
42 ### ==========================================================================
43 ### Section 2. High-level Configuration
44 ### ==========================================================================
46 # flag --- Comp switch --- Description
47 # ----------------------------------------------------------------------------
49 # debug = no/yes --- -DNDEBUG --- Enable/Disable debug mode
50 # optimize = yes/no --- (-O3/-fast etc.) --- Enable/Disable optimizations
51 # arch = (name) --- (-arch) --- Target architecture
52 # os = (name) --- --- Target operating system
53 # bits = 64/32 --- -DIS_64BIT --- 64-/32-bit operating system
54 # bigendian = no/yes --- -DBIGENDIAN --- big/little-endian byte order
55 # prefetch = no/yes --- -DUSE_PREFETCH --- Use prefetch x86 asm-instruction
56 # bsfq = no/yes --- -DUSE_BSFQ --- Use bsfq x86_64 asm-instruction
57 # --- (Works only with GCC and ICC 64-bit)
58 # popcnt = no/yes --- -DUSE_POPCNT --- Use popcnt x86_64 asm-instruction
60 # Note that Makefile is space sensitive, so when adding new architectures
61 # or modifying existing flags, you have to make sure there are no extra spaces
62 # at the end of the line for flag values.
68 ### 2.2 Architecture specific
71 ifeq ($(ARCH),general-64)
81 ifeq ($(ARCH),general-32)
91 ifeq ($(ARCH),bigendian-64)
101 ifeq ($(ARCH),bigendian-32)
112 ifeq ($(ARCH),x86-64)
122 ifeq ($(ARCH),x86-64-modern)
132 ifeq ($(ARCH),x86-32)
142 ifeq ($(ARCH),x86-32-old)
153 ifeq ($(ARCH),osx-ppc-64)
163 ifeq ($(ARCH),osx-ppc-32)
173 ifeq ($(ARCH),osx-x86-64)
183 ifeq ($(ARCH),osx-x86-32)
194 ### ==========================================================================
195 ### Section 3. Low-level configuration
196 ### ==========================================================================
198 ### 3.1 Selecting compiler (default = gcc)
206 profile_prepare = gcc-profile-prepare
207 profile_make = gcc-profile-make
208 profile_use = gcc-profile-use
209 profile_clean = gcc-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
224 profile_prepare = icc-profile-prepare
225 profile_make = icc-profile-make
226 profile_use = icc-profile-use
227 profile_clean = icc-profile-clean
230 ### 3.2 General compiler settings
231 CXXFLAGS = -g -Wall -Wcast-qual -fno-exceptions -fno-rtti $(EXTRACXXFLAGS)
234 CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra
238 CXXFLAGS += -Wno-long-long -Wextra
242 CXXFLAGS += -wd383,981,10187,10188,11505,11503 -Wcheck -Wabi -Wdeprecated -strict-ansi
246 CXXFLAGS += -arch $(arch)
249 ### 3.3 General linker settings
250 LDFLAGS = -lpthread $(EXTRALDFLAGS)
253 LDFLAGS += -arch $(arch)
262 ifeq ($(optimize),yes)
269 CXXFLAGS += -mdynamic-no-pic
271 ifeq ($(arch),x86_64)
272 CXXFLAGS += -mdynamic-no-pic
285 CXXFLAGS += -mdynamic-no-pic
292 CXXFLAGS += -DIS_64BIT
296 ifeq ($(bigendian),yes)
297 CXXFLAGS += -DBIGENDIAN
301 ifeq ($(prefetch),yes)
305 CXXFLAGS += -DNO_PREFETCH
310 CXXFLAGS += -DUSE_BSFQ
315 CXXFLAGS += -DUSE_POPCNT
318 ### ==========================================================================
319 ### Section 4. Public targets
320 ### ==========================================================================
323 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) build
327 @echo "To compile stockfish, type: "
329 @echo "make target ARCH=arch [COMP=comp]"
331 @echo "Supported targets:"
333 @echo "build > Build unoptimized version"
334 @echo "profile-build > Build PGO-optimized version"
335 @echo "popcnt-profile-build > Build PGO-optimized version with optional popcnt-support"
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 very 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"
353 @echo "bigendian-64 > unspecified 64-bit with bigendian byte order"
354 @echo "bigendian-32 > unspecified 32-bit with bigendian byte order"
356 @echo "Supported comps:"
358 @echo "gcc > Gnu compiler (default)"
359 @echo "icc > Intel compiler"
360 @echo "mingw > Gnu compiler with MinGW under Windows"
362 @echo "Non-standard targets:"
364 @echo "make hpux > Compile for HP-UX. Compiler = aCC"
366 @echo "Examples. If you don't know what to do, you likely want to run: "
368 @echo "make profile-build ARCH=x86-64 (This is for 64-bit systems)"
369 @echo "make profile-build ARCH=x86-32 (This is for 32-bit systems)"
373 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
374 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
377 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
379 @echo "Step 0/4. Preparing for profile build."
380 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
382 @echo "Step 1/4. Building executable for benchmark ..."
384 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
386 @echo "Step 2/4. Running benchmark for pgo-build ..."
387 @$(PGOBENCH) > /dev/null
389 @echo "Step 3/4. Building final executable ..."
391 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
393 @echo "Step 4/4. Deleting profile data ..."
394 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
396 popcnt-profile-build:
397 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
399 @echo "Step 0/6. Preparing for profile build."
400 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
402 @echo "Step 1/6. Building executable for benchmark (popcnt disabled)..."
404 $(MAKE) ARCH=x86-64 COMP=$(COMP) $(profile_make)
406 @echo "Step 2/6. Running benchmark for pgo-build (popcnt disabled)..."
407 @$(PGOBENCH) > /dev/null
409 @echo "Step 3/6. Building executable for benchmark (popcnt enabled)..."
411 $(MAKE) ARCH=x86-64-modern COMP=$(COMP) $(profile_make)
413 @echo "Step 4/6. Running benchmark for pgo-build (popcnt enabled)..."
414 @$(PGOBENCH) > /dev/null
416 @echo "Step 5/6. Building final executable ..."
418 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
420 @echo "Step 6/6. Deleting profile data ..."
421 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
428 -mkdir -p -m 755 $(BINDIR)
430 -strip $(BINDIR)/$(EXE)
433 $(RM) $(EXE) *.o .depend *~ core bench.txt *.gcda
438 ### ==========================================================================
439 ### Section 5. Private targets
440 ### ==========================================================================
447 @echo "debug: '$(debug)'"
448 @echo "optimize: '$(optimize)'"
449 @echo "arch: '$(arch)'"
451 @echo "bits: '$(bits)'"
452 @echo "bigendian: '$(bigendian)'"
453 @echo "prefetch: '$(prefetch)'"
454 @echo "bsfq: '$(bsfq)'"
455 @echo "popcnt: '$(popcnt)'"
459 @echo "CXXFLAGS: $(CXXFLAGS)"
460 @echo "LDFLAGS: $(LDFLAGS)"
462 @echo "Testing config sanity. If this fails, try 'make help' ..."
464 @test "$(debug)" = "yes" || test "$(debug)" = "no"
465 @test "$(optimize)" = "yes" || test "$(optimize)" = "no"
466 @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
467 test "$(arch)" = "ppc64" || test "$(arch)" = "ppc"
468 @test "$(os)" = "any" || test "$(os)" = "osx"
469 @test "$(bits)" = "32" || test "$(bits)" = "64"
470 @test "$(bigendian)" = "yes" || test "$(bigendian)" = "no"
471 @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
472 @test "$(bsfq)" = "yes" || test "$(bsfq)" = "no"
473 @test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
474 @test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw"
477 $(CXX) -o $@ $(OBJS) $(LDFLAGS)
480 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) gcc-profile-clean
483 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
484 EXTRACXXFLAGS='-fprofile-generate' \
485 EXTRALDFLAGS='-lgcov' \
489 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
490 EXTRACXXFLAGS='-fprofile-use' \
494 @rm -rf *.gcda *.gcno bench.txt
497 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) icc-profile-clean
501 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
502 EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
506 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
507 EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
511 @rm -rf profdir bench.txt
514 -@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
519 ### ==========================================================================
520 ### Section 6. Non-standard targets
521 ### ==========================================================================
525 CXX='/opt/aCC/bin/aCC -AA +hpxstd98 -DBIGENDIAN -mt +O3 -DNDEBUG -DNO_PREFETCH' \