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 = benchmark.o bitbase.o bitboard.o book.o endgame.o evaluate.o main.o \
35 material.o misc.o move.o movegen.o movepick.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 # bigendian = yes/no --- -DBIGENDIAN --- big/little-endian byte order
51 # prefetch = yes/no --- -DUSE_PREFETCH --- Use prefetch x86 asm-instruction
52 # bsfq = yes/no --- -DUSE_BSFQ --- Use bsfq x86_64 asm-instruction (only
53 # with GCC and ICC 64-bit)
54 # popcnt = yes/no --- -DUSE_POPCNT --- Use popcnt x86_64 asm-instruction
56 # Note that Makefile is space sensitive, so when adding new architectures
57 # or modifying existing flags, you have to make sure there are no extra spaces
58 # at the end of the line for flag values.
64 ### 2.2 Architecture specific
67 ifeq ($(ARCH),general-64)
77 ifeq ($(ARCH),general-32)
87 ifeq ($(ARCH),bigendian-64)
97 ifeq ($(ARCH),bigendian-32)
108 ifeq ($(ARCH),x86-64)
118 ifeq ($(ARCH),x86-64-modern)
128 ifeq ($(ARCH),x86-32)
138 ifeq ($(ARCH),x86-32-old)
149 ifeq ($(ARCH),osx-ppc-64)
159 ifeq ($(ARCH),osx-ppc-32)
169 ifeq ($(ARCH),osx-x86-64)
179 ifeq ($(ARCH),osx-x86-32)
190 ### ==========================================================================
191 ### Section 3. Low-level configuration
192 ### ==========================================================================
194 ### 3.1 Selecting compiler (default = gcc)
202 profile_prepare = gcc-profile-prepare
203 profile_make = gcc-profile-make
204 profile_use = gcc-profile-use
205 profile_clean = gcc-profile-clean
211 profile_prepare = gcc-profile-prepare
212 profile_make = gcc-profile-make
213 profile_use = gcc-profile-use
214 profile_clean = gcc-profile-clean
220 profile_prepare = icc-profile-prepare
221 profile_make = icc-profile-make
222 profile_use = icc-profile-use
223 profile_clean = icc-profile-clean
226 ### 3.2 General compiler settings
227 CXXFLAGS = -g -Wall -Wcast-qual -fno-exceptions -fno-rtti $(EXTRACXXFLAGS)
230 CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra -Wshadow
234 CXXFLAGS += -Wextra -Wshadow
238 CXXFLAGS += -wd383,981,1418,1419,10187,10188,11505,11503 -Wcheck -Wabi -Wdeprecated -strict-ansi
242 CXXFLAGS += -arch $(arch)
245 ### 3.3 General linker settings
246 LDFLAGS = -lpthread $(EXTRALDFLAGS)
249 LDFLAGS += -arch $(arch)
258 ifeq ($(optimize),yes)
265 CXXFLAGS += -mdynamic-no-pic
267 ifeq ($(arch),x86_64)
268 CXXFLAGS += -mdynamic-no-pic
279 CXXFLAGS += -fast -mdynamic-no-pic
288 CXXFLAGS += -DIS_64BIT
292 ifeq ($(bigendian),yes)
293 CXXFLAGS += -DBIGENDIAN
297 ifeq ($(prefetch),yes)
301 CXXFLAGS += -DNO_PREFETCH
306 CXXFLAGS += -DUSE_BSFQ
311 CXXFLAGS += -DUSE_POPCNT
313 ### For gcc we add also msse3 support and Link Time Optimization, note that
314 ### this is a mix of compile and link time options because the lto link phase
315 ### needs access to the optimization flags.
317 CXXFLAGS += -msse3 -flto
318 LDFLAGS += $(CXXFLAGS) -static
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 "double-profile-build > Build PGO-optimized version with and without popcnt support"
337 @echo "strip > Strip executable"
338 @echo "install > Install executable"
339 @echo "clean > Clean up"
340 @echo "testrun > Make sample run"
342 @echo "Supported archs:"
344 @echo "x86-64 > x86 64-bit"
345 @echo "x86-64-modern > x86 64-bit with runtime support for popcnt instruction"
346 @echo "x86-32 > x86 32-bit excluding very old hardware without SSE-support"
347 @echo "x86-32-old > x86 32-bit including also very old hardware"
348 @echo "osx-ppc-64 > PPC-Mac OS X 64 bit"
349 @echo "osx-ppc-32 > PPC-Mac OS X 32 bit"
350 @echo "osx-x86-64 > x86-Mac OS X 64 bit"
351 @echo "osx-x86-32 > x86-Mac OS X 32 bit"
352 @echo "general-64 > unspecified 64-bit"
353 @echo "general-32 > unspecified 32-bit"
354 @echo "bigendian-64 > unspecified 64-bit with bigendian byte order"
355 @echo "bigendian-32 > unspecified 32-bit with bigendian byte order"
357 @echo "Supported comps:"
359 @echo "gcc > Gnu compiler (default)"
360 @echo "icc > Intel compiler"
361 @echo "mingw > Gnu compiler with MinGW under Windows"
363 @echo "Non-standard targets:"
365 @echo "make hpux > Compile for HP-UX. Compiler = aCC"
367 @echo "Examples. If you don't know what to do, you likely want to run: "
369 @echo "make profile-build ARCH=x86-64 (This is for 64-bit systems)"
370 @echo "make profile-build ARCH=x86-32 (This is for 32-bit systems)"
374 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
375 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
378 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
380 @echo "Step 0/4. Preparing for profile build."
381 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
383 @echo "Step 1/4. Building executable for benchmark ..."
385 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
387 @echo "Step 2/4. Running benchmark for pgo-build ..."
388 @$(PGOBENCH) > /dev/null
390 @echo "Step 3/4. Building final executable ..."
392 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
394 @echo "Step 4/4. Deleting profile data ..."
395 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
397 double-profile-build:
398 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
400 @echo "Step 0/6. Preparing for profile build."
401 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
403 @echo "Step 1/6. Building executable for benchmark (popcnt disabled)..."
405 $(MAKE) ARCH=x86-64 COMP=$(COMP) $(profile_make)
407 @echo "Step 2/6. Running benchmark for pgo-build (popcnt disabled)..."
408 @$(PGOBENCH) > /dev/null
410 @echo "Step 3/6. Building executable for benchmark (popcnt enabled)..."
412 $(MAKE) ARCH=x86-64-modern COMP=$(COMP) $(profile_make)
414 @echo "Step 4/6. Running benchmark for pgo-build (popcnt enabled)..."
415 @$(PGOBENCH) > /dev/null
417 @echo "Step 5/6. Building final executable ..."
419 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
421 @echo "Step 6/6. Deleting profile data ..."
422 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
429 -mkdir -p -m 755 $(BINDIR)
431 -strip $(BINDIR)/$(EXE)
434 $(RM) $(EXE) $(EXE).exe *.o .depend *~ core bench.txt *.gcda
442 ### ==========================================================================
443 ### Section 5. Private targets
444 ### ==========================================================================
451 @echo "debug: '$(debug)'"
452 @echo "optimize: '$(optimize)'"
453 @echo "arch: '$(arch)'"
455 @echo "bits: '$(bits)'"
456 @echo "bigendian: '$(bigendian)'"
457 @echo "prefetch: '$(prefetch)'"
458 @echo "bsfq: '$(bsfq)'"
459 @echo "popcnt: '$(popcnt)'"
463 @echo "CXXFLAGS: $(CXXFLAGS)"
464 @echo "LDFLAGS: $(LDFLAGS)"
466 @echo "Testing config sanity. If this fails, try 'make help' ..."
468 @test "$(debug)" = "yes" || test "$(debug)" = "no"
469 @test "$(optimize)" = "yes" || test "$(optimize)" = "no"
470 @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
471 test "$(arch)" = "ppc64" || test "$(arch)" = "ppc"
472 @test "$(os)" = "any" || test "$(os)" = "osx"
473 @test "$(bits)" = "32" || test "$(bits)" = "64"
474 @test "$(bigendian)" = "yes" || test "$(bigendian)" = "no"
475 @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
476 @test "$(bsfq)" = "yes" || test "$(bsfq)" = "no"
477 @test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
478 @test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw"
481 $(CXX) -o $@ $(OBJS) $(LDFLAGS)
484 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) gcc-profile-clean
487 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
488 EXTRACXXFLAGS='-fprofile-generate' \
489 EXTRALDFLAGS='-lgcov' \
493 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
494 EXTRACXXFLAGS='-fprofile-use' \
498 @rm -rf *.gcda *.gcno bench.txt
501 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) icc-profile-clean
505 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
506 EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
510 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
511 EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
515 @rm -rf profdir bench.txt
518 -@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
523 ### ==========================================================================
524 ### Section 6. Non-standard targets
525 ### ==========================================================================
529 CXX='/opt/aCC/bin/aCC -AA +hpxstd98 -DBIGENDIAN -mt +O3 -DNDEBUG -DNO_PREFETCH' \