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 ### ==========================================================================
23 ### Establish the operating system name
24 UNAME = $(shell uname)
29 ### Installation dir definitions
31 # Haiku has a non-standard filesystem layout
35 BINDIR = $(PREFIX)/bin
37 ### Built-in benchmark for pgo-builds
38 PGOBENCH = ./$(EXE) bench 32 1 10 default depth
41 OBJS = benchmark.o bitbase.o bitboard.o book.o endgame.o evaluate.o main.o \
42 material.o misc.o movegen.o movepick.o notation.o pawns.o position.o \
43 search.o thread.o timeman.o tt.o uci.o ucioption.o
45 ### ==========================================================================
46 ### Section 2. High-level Configuration
47 ### ==========================================================================
49 # flag --- Comp switch --- Description
50 # ----------------------------------------------------------------------------
52 # debug = yes/no --- -DNDEBUG --- Enable/Disable debug mode
53 # optimize = yes/no --- (-O3/-fast etc.) --- Enable/Disable optimizations
54 # arch = (name) --- (-arch) --- Target architecture
55 # os = (name) --- --- Target operating system
56 # bits = 64/32 --- -DIS_64BIT --- 64-/32-bit operating system
57 # prefetch = yes/no --- -DUSE_PREFETCH --- Use prefetch x86 asm-instruction
58 # bsfq = yes/no --- -DUSE_BSFQ --- Use bsfq x86_64 asm-instruction (only
59 # with GCC and ICC 64-bit)
60 # popcnt = yes/no --- -DUSE_POPCNT --- Use popcnt x86_64 asm-instruction
62 # Note that Makefile is space sensitive, so when adding new architectures
63 # or modifying existing flags, you have to make sure there are no extra spaces
64 # at the end of the line for flag values.
70 ### 2.2 Architecture specific
73 ifeq ($(ARCH),general-64)
82 ifeq ($(ARCH),general-32)
101 ifeq ($(ARCH),x86-64-modern)
110 ifeq ($(ARCH),x86-32)
119 ifeq ($(ARCH),x86-32-old)
129 ifeq ($(ARCH),osx-ppc-64)
138 ifeq ($(ARCH),osx-ppc-32)
147 ifeq ($(ARCH),osx-x86-64)
156 ifeq ($(ARCH),osx-x86-32)
166 ### ==========================================================================
167 ### Section 3. Low-level configuration
168 ### ==========================================================================
170 ### 3.1 Selecting compiler (default = gcc)
178 profile_prepare = gcc-profile-prepare
179 profile_make = gcc-profile-make
180 profile_use = gcc-profile-use
181 profile_clean = gcc-profile-clean
187 profile_prepare = gcc-profile-prepare
188 profile_make = gcc-profile-make
189 profile_use = gcc-profile-use
190 profile_clean = gcc-profile-clean
196 profile_prepare = icc-profile-prepare
197 profile_make = icc-profile-make
198 profile_use = icc-profile-use
199 profile_clean = icc-profile-clean
205 profile_prepare = gcc-profile-prepare
206 profile_make = gcc-profile-make
207 profile_use = gcc-profile-use
208 profile_clean = gcc-profile-clean
211 ### 3.2 General compiler settings
212 CXXFLAGS = -g -Wall -Wcast-qual -fno-exceptions -fno-rtti $(EXTRACXXFLAGS)
215 CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra -Wshadow
219 CXXFLAGS += -Wextra -Wshadow
223 CXXFLAGS += -wd383,981,1418,1419,10187,10188,11505,11503 -Wcheck -Wabi -Wdeprecated -strict-ansi
227 CXXFLAGS += -ansi -pedantic -Wno-long-long -Wextra -Wshadow
231 CXXFLAGS += -arch $(arch)
234 ### 3.3 General linker settings
235 LDFLAGS = $(EXTRALDFLAGS)
237 ### On mingw use Windows threads, otherwise POSIX
238 ifneq ($(comp),mingw)
239 # Haiku has pthreads in its libroot, so only link it in on other platforms
240 ifneq ($(UNAME),Haiku)
246 LDFLAGS += -arch $(arch)
255 ifeq ($(optimize),yes)
262 CXXFLAGS += -mdynamic-no-pic
264 ifeq ($(arch),x86_64)
265 CXXFLAGS += -mdynamic-no-pic
276 CXXFLAGS += -fast -mdynamic-no-pic
283 ### -O4 requires a linker that supports LLVM's LTO
288 CXXFLAGS += -mdynamic-no-pic
290 ifeq ($(arch),x86_64)
291 CXXFLAGS += -mdynamic-no-pic
299 CXXFLAGS += -DIS_64BIT
303 ifeq ($(prefetch),yes)
307 CXXFLAGS += -DNO_PREFETCH
312 CXXFLAGS += -DUSE_BSFQ
317 CXXFLAGS += -msse3 -DUSE_POPCNT
320 ### 3.10 Link Time Optimization, it works since gcc 4.5 but not on mingw.
321 ### This is a mix of compile and link time options because the lto link phase
322 ### needs access to the optimization flags.
324 ifeq ($(optimize),yes)
325 GCC_MAJOR := `$(CXX) -dumpversion | cut -f1 -d.`
326 GCC_MINOR := `$(CXX) -dumpversion | cut -f2 -d.`
327 ifeq (1,$(shell expr \( $(GCC_MAJOR) \> 4 \) \| \( $(GCC_MAJOR) \= 4 \& $(GCC_MINOR) \>= 5 \)))
329 LDFLAGS += $(CXXFLAGS)
334 ### ==========================================================================
335 ### Section 4. Public targets
336 ### ==========================================================================
340 @echo "To compile stockfish, type: "
342 @echo "make target ARCH=arch [COMP=comp]"
344 @echo "Supported targets:"
346 @echo "build > Build unoptimized version"
347 @echo "profile-build > Build PGO-optimized version"
348 @echo "strip > Strip executable"
349 @echo "install > Install executable"
350 @echo "clean > Clean up"
351 @echo "testrun > Make sample run"
353 @echo "Supported archs:"
355 @echo "x86-64 > x86 64-bit"
356 @echo "x86-64-modern > x86 64-bit with runtime support for popcnt instruction"
357 @echo "x86-32 > x86 32-bit excluding old hardware without SSE-support"
358 @echo "x86-32-old > x86 32-bit including also very old hardware"
359 @echo "osx-ppc-64 > PPC-Mac OS X 64 bit"
360 @echo "osx-ppc-32 > PPC-Mac OS X 32 bit"
361 @echo "osx-x86-64 > x86-Mac OS X 64 bit"
362 @echo "osx-x86-32 > x86-Mac OS X 32 bit"
363 @echo "general-64 > unspecified 64-bit"
364 @echo "general-32 > unspecified 32-bit"
366 @echo "Supported comps:"
368 @echo "gcc > Gnu compiler (default)"
369 @echo "icc > Intel compiler"
370 @echo "mingw > Gnu compiler with MinGW under Windows"
371 @echo "clang > LLVM Clang compiler"
373 @echo "Non-standard targets:"
375 @echo "make hpux > Compile for HP-UX. Compiler = aCC"
377 @echo "Examples. If you don't know what to do, you likely want to run: "
379 @echo "make profile-build ARCH=x86-64 (This is for 64-bit systems)"
380 @echo "make profile-build ARCH=x86-32 (This is for 32-bit systems)"
384 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
385 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
388 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) config-sanity
390 @echo "Step 0/4. Preparing for profile build."
391 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
393 @echo "Step 1/4. Building executable for benchmark ..."
395 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
397 @echo "Step 2/4. Running benchmark for pgo-build ..."
398 @$(PGOBENCH) > /dev/null
400 @echo "Step 3/4. Building final executable ..."
402 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
404 @echo "Step 4/4. Deleting profile data ..."
405 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_clean)
411 -mkdir -p -m 755 $(BINDIR)
413 -strip $(BINDIR)/$(EXE)
416 $(RM) $(EXE) $(EXE).exe *.o .depend *~ core bench.txt *.gcda
424 ### ==========================================================================
425 ### Section 5. Private targets
426 ### ==========================================================================
433 @echo "debug: '$(debug)'"
434 @echo "optimize: '$(optimize)'"
435 @echo "arch: '$(arch)'"
437 @echo "bits: '$(bits)'"
438 @echo "prefetch: '$(prefetch)'"
439 @echo "bsfq: '$(bsfq)'"
440 @echo "popcnt: '$(popcnt)'"
444 @echo "CXXFLAGS: $(CXXFLAGS)"
445 @echo "LDFLAGS: $(LDFLAGS)"
447 @echo "Testing config sanity. If this fails, try 'make help' ..."
449 @test "$(debug)" = "yes" || test "$(debug)" = "no"
450 @test "$(optimize)" = "yes" || test "$(optimize)" = "no"
451 @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
452 test "$(arch)" = "ppc64" || test "$(arch)" = "ppc"
453 @test "$(os)" = "any" || test "$(os)" = "osx"
454 @test "$(bits)" = "32" || test "$(bits)" = "64"
455 @test "$(prefetch)" = "yes" || test "$(prefetch)" = "no"
456 @test "$(bsfq)" = "yes" || test "$(bsfq)" = "no"
457 @test "$(popcnt)" = "yes" || test "$(popcnt)" = "no"
458 @test "$(comp)" = "gcc" || test "$(comp)" = "icc" || test "$(comp)" = "mingw" || test "$(comp)" = "clang"
461 $(CXX) -o $@ $(OBJS) $(LDFLAGS)
464 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) gcc-profile-clean
467 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
468 EXTRACXXFLAGS='-fprofile-generate' \
469 EXTRALDFLAGS='-lgcov' \
473 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
474 EXTRACXXFLAGS='-fprofile-use' \
475 EXTRALDFLAGS='-lgcov' \
479 @rm -rf *.gcda *.gcno bench.txt
482 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) icc-profile-clean
486 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
487 EXTRACXXFLAGS='-prof-gen=srcpos -prof_dir ./profdir' \
491 $(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
492 EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
496 @rm -rf profdir bench.txt
499 -@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
504 ### ==========================================================================
505 ### Section 6. Non-standard targets
506 ### ==========================================================================
510 CXX='/opt/aCC/bin/aCC -AA +hpxstd98 -mt +O3 -DNDEBUG -DNO_PREFETCH' \