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 # 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 = bitboard.o pawns.o material.o endgame.o evaluate.o main.o \
35 misc.o move.o movegen.o movepick.o search.o position.o \
36 tt.o uci.o ucioption.o book.o bitbase.o benchmark.o timeman.o
39 ### ==========================================================================
40 ### Section 2. High-level Configuration
41 ### ==========================================================================
43 # flag --- Comp switch --- Description
44 # ----------------------------------------------------------------------------
46 # debug = no/yes --- -DNDEBUG --- Enable/Disable debug mode
47 # optimize = yes/no --- (-O3/-fast etc.) --- Enable/Disable optimizations
48 # arch = (name) --- (-arch) --- Target architecture
49 # os = (name) --- --- Target operating system
50 # bits = 64/32 --- -DIS_64BIT --- 64-/32-bit operating system
51 # bigendian = no/yes --- -DBIGENDIAN --- big/little-endian byte order
52 # prefetch = no/yes --- -DUSE_PREFETCH --- Use prefetch x86 asm-instruction
53 # bsfq = no/yes --- -DUSE_BSFQ --- Use bsfq x86_64 asm-instruction
54 # --- (Works only with GCC and ICC 64-bit)
55 # popcnt = no/yes --- -DUSE_POPCNT --- Use popcnt x86_64 asm-instruction
57 # Note that Makefile is space sensitive, so when adding new architectures
58 # or modifying existing flags, you have to make sure there are no extra spaces
59 # at the end of the line for flag values.
65 ### 2.2 Architecture specific
68 ifeq ($(ARCH),general-64)
78 ifeq ($(ARCH),general-32)
88 ifeq ($(ARCH),bigendian-64)
98 ifeq ($(ARCH),bigendian-32)
109 ifeq ($(ARCH),x86-64)
119 ifeq ($(ARCH),x86-64-modern)
129 ifeq ($(ARCH),x86-32)
139 ifeq ($(ARCH),x86-32-old)
150 ifeq ($(ARCH),osx-ppc-64)
160 ifeq ($(ARCH),osx-ppc-32)
170 ifeq ($(ARCH),osx-x86-64)
180 ifeq ($(ARCH),osx-x86-32)
191 ### ==========================================================================
192 ### Section 3. Low-level configuration
193 ### ==========================================================================
195 ### 3.1 Selecting compiler (default = gcc)
203 profile_prepare = gcc-profile-prepare
204 profile_make = gcc-profile-make
205 profile_use = gcc-profile-use
206 profile_clean = gcc-profile-clean
212 profile_prepare = gcc-profile-prepare
213 profile_make = gcc-profile-make
214 profile_use = gcc-profile-use
215 profile_clean = gcc-profile-clean
221 profile_prepare = icc-profile-prepare
222 profile_make = icc-profile-make
223 profile_use = icc-profile-use
224 profile_clean = icc-profile-clean
227 ### 3.2 General compiler settings
228 CXXFLAGS = -g -Wall -Wcast-qual -fno-exceptions -fno-rtti $(EXTRACXXFLAGS)
231 CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra -Wshadow
235 CXXFLAGS += -Wextra -Wshadow
239 CXXFLAGS += -wd383,981,1418,1419,10187,10188,11505,11503 -Wcheck -Wabi -Wdeprecated -strict-ansi
243 CXXFLAGS += -arch $(arch)
246 ### 3.3 General linker settings
247 LDFLAGS = -lpthread $(EXTRALDFLAGS)
250 LDFLAGS += -arch $(arch)
259 ifeq ($(optimize),yes)
266 CXXFLAGS += -mdynamic-no-pic
268 ifeq ($(arch),x86_64)
269 CXXFLAGS += -mdynamic-no-pic
280 CXXFLAGS += -fast -mdynamic-no-pic
289 CXXFLAGS += -DIS_64BIT
293 ifeq ($(bigendian),yes)
294 CXXFLAGS += -DBIGENDIAN
298 ifeq ($(prefetch),yes)
302 CXXFLAGS += -DNO_PREFETCH
307 CXXFLAGS += -DUSE_BSFQ
312 CXXFLAGS += -DUSE_POPCNT
315 ### ==========================================================================
316 ### Section 4. Public targets
317 ### ==========================================================================
320 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) build
324 @echo "To compile stockfish, type: "
326 @echo "make target ARCH=arch [COMP=comp]"
328 @echo "Supported targets:"
330 @echo "build > Build unoptimized version"
331 @echo "profile-build > Build PGO-optimized version"
332 @echo "popcnt-profile-build > Build PGO-optimized version with optional popcnt-support"
333 @echo "strip > Strip executable"
334 @echo "install > Install executable"
335 @echo "clean > Clean up"
336 @echo "testrun > Make sample run"
338 @echo "Supported archs:"
340 @echo "x86-64 > x86 64-bit"
341 @echo "x86-64-modern > x86 64-bit with runtime support for popcnt-instruction"
342 @echo "x86-32 > x86 32-bit excluding very old hardware without SSE-support"
343 @echo "x86-32-old > x86 32-bit including also very old hardware"
344 @echo "osx-ppc-64 > PPC-Mac OS X 64 bit"
345 @echo "osx-ppc-32 > PPC-Mac OS X 32 bit"
346 @echo "osx-x86-64 > x86-Mac OS X 64 bit"
347 @echo "osx-x86-32 > x86-Mac OS X 32 bit"
348 @echo "general-64 > unspecified 64-bit"
349 @echo "general-32 > unspecified 32-bit"
350 @echo "bigendian-64 > unspecified 64-bit with bigendian byte order"
351 @echo "bigendian-32 > unspecified 32-bit with bigendian byte order"
353 @echo "Supported comps:"
355 @echo "gcc > Gnu compiler (default)"
356 @echo "icc > Intel compiler"
357 @echo "mingw > Gnu compiler with MinGW under Windows"
359 @echo "Non-standard targets:"
361 @echo "make hpux > Compile for HP-UX. Compiler = aCC"
363 @echo "Examples. If you don't know what to do, you likely want to run: "
365 @echo "make profile-build ARCH=x86-64 (This is for 64-bit systems)"
366 @echo "make profile-build ARCH=x86-32 (This is for 32-bit systems)"
370 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
371 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
374 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
376 @echo "Step 0/4. Preparing for profile build."
377 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
379 @echo "Step 1/4. Building executable for benchmark ..."
381 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
383 @echo "Step 2/4. Running benchmark for pgo-build ..."
384 @$(PGOBENCH) > /dev/null
386 @echo "Step 3/4. Building final executable ..."
388 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
390 @echo "Step 4/4. Deleting profile data ..."
391 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
393 popcnt-profile-build:
394 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
396 @echo "Step 0/6. Preparing for profile build."
397 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
399 @echo "Step 1/6. Building executable for benchmark (popcnt disabled)..."
401 $(MAKE) ARCH=x86-64 COMP=$(COMP) $(profile_make)
403 @echo "Step 2/6. Running benchmark for pgo-build (popcnt disabled)..."
404 @$(PGOBENCH) > /dev/null
406 @echo "Step 3/6. Building executable for benchmark (popcnt enabled)..."
408 $(MAKE) ARCH=x86-64-modern COMP=$(COMP) $(profile_make)
410 @echo "Step 4/6. Running benchmark for pgo-build (popcnt enabled)..."
411 @$(PGOBENCH) > /dev/null
413 @echo "Step 5/6. Building final executable ..."
415 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
417 @echo "Step 6/6. Deleting profile data ..."
418 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
425 -mkdir -p -m 755 $(BINDIR)
427 -strip $(BINDIR)/$(EXE)
430 $(RM) $(EXE) $(EXE).exe *.o .depend *~ core bench.txt *.gcda
435 ### ==========================================================================
436 ### Section 5. Private targets
437 ### ==========================================================================
444 @echo "debug: '$(debug)'"
445 @echo "optimize: '$(optimize)'"
446 @echo "arch: '$(arch)'"
448 @echo "bits: '$(bits)'"
449 @echo "bigendian: '$(bigendian)'"
450 @echo "prefetch: '$(prefetch)'"
451 @echo "bsfq: '$(bsfq)'"
452 @echo "popcnt: '$(popcnt)'"
456 @echo "CXXFLAGS: $(CXXFLAGS)"
457 @echo "LDFLAGS: $(LDFLAGS)"
459 @echo "Testing config sanity. If this fails, try 'make help' ..."
461 @test "$(debug)" = "yes" || test "$(debug)" = "no"
462 @test "$(optimize)" = "yes" || test "$(optimize)" = "no"
463 @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
464 test "$(arch)" = "ppc64" || test "$(arch)" = "ppc"
465 @test "$(os)" = "any" || test "$(os)" = "osx"
466 @test "$(bits)" = "32" || test "$(bits)" = "64"
467 @test "$(bigendian)" = "yes" || test "$(bigendian)" = "no"
468 @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
469 @test "$(bsfq)" = "yes" || test "$(bsfq)" = "no"
470 @test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
471 @test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw"
474 $(CXX) -o $@ $(OBJS) $(LDFLAGS)
477 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) gcc-profile-clean
480 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
481 EXTRACXXFLAGS='-fprofile-generate' \
482 EXTRALDFLAGS='-lgcov' \
486 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
487 EXTRACXXFLAGS='-fprofile-use' \
491 @rm -rf *.gcda *.gcno bench.txt
494 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) icc-profile-clean
498 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
499 EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
503 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
504 EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
508 @rm -rf profdir bench.txt
511 -@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
516 ### ==========================================================================
517 ### Section 6. Non-standard targets
518 ### ==========================================================================
522 CXX='/opt/aCC/bin/aCC -AA +hpxstd98 -DBIGENDIAN -mt +O3 -DNDEBUG -DNO_PREFETCH' \