# along with this program. If not, see <http://www.gnu.org/licenses/>.
-###
-### Files
-###
-
+### Executable name. Do not change
EXE = stockfish
-OBJS = application.o bitboard.o pawns.o material.o endgame.o evaluate.o main.o \
- misc.o move.o movegen.o history.o movepick.o search.o piece.o \
- position.o direction.o tt.o value.o uci.o ucioption.o \
- mersenne.o book.o bitbase.o san.o benchmark.o
-
-
-###
-### Rules
-###
-
-all: $(EXE) .depend
-
-clean:
- $(RM) *.o .depend stockfish
-
-
-###
-### Compiler:
-###
-
-CXX = g++-4.2
-# CXX = icpc
-
-
-###
-### Dependencies
-###
-
-$(EXE): $(OBJS)
- $(CXX) $(LDFLAGS) -o $@ $(OBJS)
-
-.depend:
- $(CXX) -MM $(OBJS:.o=.cpp) > $@
-
-include .depend
+### Installation dir definitions
+PREFIX = /usr/local
+BINDIR = $(PREFIX)/bin
+### ==========================================================================
+### Compiler speed switches for both GCC and ICC. These settings are generally
+### fast on a broad range of systems, but may be changed experimentally
+### ==========================================================================
+GCCFLAGS = -O3 -msse
+ICCFLAGS = -fast -msse
+ICCFLAGS-OSX = -fast -mdynamic-no-pic
-###
-### Compiler and linker switches
-###
-# Enable/disable debugging, disabled by default
+### ==========================================================================
+### Enable/disable debugging, disabled by default
+### ==========================================================================
+GCCFLAGS += -DNDEBUG
+ICCFLAGS += -DNDEBUG
+ICCFLAGS-OSX += -DNDEBUG
-# CXXFLAGS += -DNDEBUG
+### ==========================================================================
+### Remove below comments to compile for a big-endian machine
+### ==========================================================================
+#GCCFLAGS += -DBIGENDIAN
+#ICCFLAGS += -DBIGENDIAN
+#ICCFLAGS-OSX += -DBIGENDIAN
-# Compile with full warnings, and symbol names stripped, you can use
-# -g instead of -s to compile symbol's table in, useful for debugging.
-CXXFLAGS += -Wall -s
+### ==========================================================================
+### Run built-in benchmark for pgo-builds with: 32MB hash 1 thread 10 depth
+### These settings are generally fast, but may be changed experimentally
+### ==========================================================================
+PGOBENCH = ./$(EXE) bench 32 1 10 default depth
+### General compiler settings. Do not change
+GCCFLAGS += -g -Wall -fno-exceptions -fno-rtti
+ICCFLAGS += -g -Wall -fno-exceptions -fno-rtti -wd383,869,981,10187,10188,11505,11503
+ICCFLAGS-OSX += -g -Wall -fno-exceptions -fno-rtti -wd383,869,981,10187,10188,11505,11503
-# General optimization flags. Note that -O2 might be faster than -O3 on some
-# systems; this requires testing.
-CXXFLAGS += -O3 -fno-exceptions -fno-rtti -fno-strict-aliasing
+### General linker settings. Do not change
+LDFLAGS = -lpthread
-# Disable most annoying warnings for the Intel C++ compiler
-
-# CXXFLAGS += -wd383,869,981
-
-
-# Compiler optimization flags for the Intel C++ compiler in Mac OS X:
-
-# CXXFLAGS += -mdynamic-no-pic -no-prec-div -ipo -static -xP
-
-
-# Profiler guided optimization with the Intel C++ compiler v11. To use it, first
-# create the directory ./profdata if it does not already exist, and delete its
-# contents if it does exist. Then compile with -prof_gen, and run the
-# resulting binary for a while (for instance, do ./stockfish bench 128 1, and
-# wait 15 minutes for the benchmark to complete). Then do a 'make clean', and
-# recompile with -prof_use.
-
-# CXXFLAGS += -prof-gen -prof-dir./profdata
-# CXXFLAGS += -prof-use -ipo -prof_dir./profdata
-
-
-# Profiler guided optimization with GCC. I've never been able to make this
-# work.
-
-# CXXFLAGS += -fprofile-generate
-# LDFLAGS += -fprofile-generate
-# CXXFLAGS += -fprofile-use
-# CXXFLAGS += -fprofile-use
-
-
-# General linker flags
-
-LDFLAGS += -lm -lpthread
+### Object files. Do not change
+OBJS = application.o bitboard.o pawns.o material.o endgame.o evaluate.o main.o \
+ misc.o move.o movegen.o history.o movepick.o search.o piece.o \
+ position.o direction.o tt.o value.o uci.o ucioption.o \
+ mersenne.o book.o bitbase.o san.o benchmark.o
-# Compiler switches for generating binaries for various CPUs in Mac OS X.
-# Note that 'arch ppc' and 'arch ppc64' only works with g++, and not with
-# the intel compiler.
-# CXXFLAGS += -arch ppc
-# CXXFLAGS += -arch ppc64
-# CXXFLAGS += -arch i386
-# CXXFLAGS += -arch x86_64
-# LDFLAGS += -arch ppc
-# LDFLAGS += -arch ppc64
-# LDFLAGS += -arch i386
-# LDFLAGS += -arch x86_64
+### General rules. Do not change
+default:
+ $(MAKE) gcc
+
+help:
+ @echo ""
+ @echo "Makefile options:"
+ @echo ""
+ @echo "make > Default: Compiler = g++"
+ @echo "make gcc-profile > Compiler = g++ + automatic pgo-build"
+ @echo "make gcc-popcnt > Compiler = g++ + popcnt-support"
+ @echo "make icc > Compiler = icpc"
+ @echo "make icc-profile > Compiler = icpc + automatic pgo-build"
+ @echo "make icc-profile-popcnt > Compiler = icpc + automatic pgo-build + popcnt-support"
+ @echo "make osx-ppc32 > PPC-Mac OS X 32 bit. Compiler = g++"
+ @echo "make osx-ppc64 > PPC-Mac OS X 64 bit. Compiler = g++"
+ @echo "make osx-x86 > x86-Mac OS X 32 bit. Compiler = g++"
+ @echo "make osx-x86_64 > x86-Mac OS X 64 bit. Compiler = g++"
+ @echo "make osx-icc32 > x86-Mac OS X 32 bit. Compiler = icpc"
+ @echo "make osx-icc64 > x86-Mac OS X 64 bit. Compiler = icpc"
+ @echo "make osx-icc32-profile > OSX 32 bit. Compiler = icpc + automatic pgo-build"
+ @echo "make osx-icc64-profile > OSX 64 bit. Compiler = icpc + automatic pgo-build"
+ @echo "make hpux > HP-UX. Compiler = aCC"
+ @echo "make strip > Strip executable"
+ @echo "make clean > Clean up"
+ @echo ""
+all: $(EXE) .depend
-# Backwards compatibility with Mac OS X 10.4 when compiling under 10.5 with
-# GCC 4.0. I haven't found a way to make it work with GCC 4.2.
+test check: default
+ @$(PGOBENCH)
-# CXXFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk
-# CXXFLAGS += -mmacosx-version-min=10.4
-# LDFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk
-# LDFLAGS += -Wl,-syslibroot /Developer/SDKs/MacOSX10.4u.sdk
-# LDFLAGS += -mmacosx-version-min=10.4
+clean:
+ $(RM) *.o .depend *~ $(EXE) core bench.txt
+
+
+### Possible targets. You may add your own ones here
+gcc:
+ $(MAKE) \
+ CXX='g++' \
+ CXXFLAGS="$(GCCFLAGS)" \
+ all
+
+gcc-profile-make:
+ $(MAKE) \
+ CXX='g++' \
+ CXXFLAGS="$(GCCFLAGS)" \
+ CXXFLAGS+='-fprofile-generate' \
+ LDFLAGS="$(LDFLAGS)" \
+ LDFLAGS+=" -lgcov" \
+ all
+
+gcc-profile-use:
+ $(MAKE) \
+ CXX='g++' \
+ CXXFLAGS="$(GCCFLAGS)" \
+ CXXFLAGS+='-fprofile-use' \
+ all
+
+gcc-profile:
+ @touch *.cpp *.h
+ $(MAKE) gcc-profile-make
+ @echo ""
+ @echo "Running benchmark for pgo-build ..."
+ @$(PGOBENCH) > /dev/null
+ @echo "Benchmark finished. Build final executable now ..."
+ @echo ""
+ @touch *.cpp *.h
+ $(MAKE) gcc-profile-use
+ @rm -rf *.gcda bench.txt
+
+gcc-popcnt:
+ $(MAKE) \
+ CXX='g++' \
+ CXXFLAGS="$(GCCFLAGS) -DUSE_POPCNT" \
+ all
+
+icc:
+ $(MAKE) \
+ CXX='icpc' \
+ CXXFLAGS="$(ICCFLAGS)" \
+ all
+
+icc-profile-make:
+ $(MAKE) \
+ CXX='icpc' \
+ CXXFLAGS="$(ICCFLAGS)" \
+ CXXFLAGS+='-prof-gen=srcpos -prof_dir ./profdir' \
+ all
+
+icc-profile-use:
+ $(MAKE) \
+ CXX='icpc' \
+ CXXFLAGS="$(ICCFLAGS)" \
+ CXXFLAGS+='-prof_use -prof_dir ./profdir' \
+ all
+
+icc-profile:
+ @rm -rf profdir
+ @mkdir profdir
+ @touch *.cpp *.h
+ $(MAKE) icc-profile-make
+ @echo ""
+ @echo "Running benchmark for pgo-build ..."
+ @$(PGOBENCH) > /dev/null
+ @echo "Benchmark finished. Build final executable now ..."
+ @echo ""
+ @touch *.cpp *.h
+ $(MAKE) icc-profile-use
+ @rm -rf profdir bench.txt
+
+icc-profile-make-with-popcnt:
+ $(MAKE) \
+ CXX='icpc' \
+ CXXFLAGS="$(ICCFLAGS) -DUSE_POPCNT" \
+ CXXFLAGS+='-prof-gen=srcpos -prof_dir ./profdir' \
+ all
+
+icc-profile-use-with-popcnt:
+ $(MAKE) \
+ CXX='icpc' \
+ CXXFLAGS="$(ICCFLAGS) -DUSE_POPCNT" \
+ CXXFLAGS+='-prof_use -prof_dir ./profdir' \
+ all
+
+icc-profile-popcnt:
+ @rm -rf profdir
+ @mkdir profdir
+ @touch *.cpp *.h
+ $(MAKE) icc-profile-make
+ @echo ""
+ @echo "Running benchmark for pgo-build (popcnt disabled)..."
+ @$(PGOBENCH) > /dev/null
+ @touch *.cpp *.h
+ $(MAKE) icc-profile-make-with-popcnt
+ @echo ""
+ @echo "Running benchmark for pgo-build (popcnt enabled)..."
+ @$(PGOBENCH) > /dev/null
+ @echo "Benchmarks finished. Build final executable now ..."
+ @echo ""
+ @touch *.cpp *.h
+ $(MAKE) icc-profile-use-with-popcnt
+ @rm -rf profdir bench.txt
+
+
+osx-ppc32:
+ $(MAKE) \
+ CXX='g++' \
+ CXXFLAGS="$(GCCFLAGS)" \
+ CXXFLAGS+='-arch ppc' \
+ CXXFLAGS+='-DBIGENDIAN' \
+ LDFLAGS+='-arch ppc' \
+ all
+
+osx-ppc64:
+ $(MAKE) \
+ CXX='g++' \
+ CXXFLAGS="$(GCCFLAGS)" \
+ CXXFLAGS+='-arch ppc64' \
+ CXXFLAGS+='-DBIGENDIAN' \
+ LDFLAGS+='-arch ppc64' \
+ all
+
+osx-x86:
+ $(MAKE) \
+ CXX='g++' \
+ CXXFLAGS="$(GCCFLAGS)" \
+ CXXFLAGS+='-arch i386 -mdynamic-no-pic' \
+ LDFLAGS+='-arch i386 -mdynamic-no-pic' \
+ all
+
+osx-x86_64:
+ $(MAKE) \
+ CXX='g++' \
+ CXXFLAGS="$(GCCFLAGS)" \
+ CXXFLAGS+='-arch x86_64 -mdynamic-no-pic' \
+ LDFLAGS+='-arch x86_64 -mdynamic-no-pic' \
+ all
+
+osx-icc32:
+ $(MAKE) \
+ CXX='icpc' \
+ CXXFLAGS="$(ICCFLAGS-OSX)" \
+ CXXFLAGS+='-arch i386' \
+ LDFLAGS+='-arch i386' \
+ all
+
+osx-icc64:
+ $(MAKE) \
+ CXX='icpc' \
+ CXXFLAGS="$(ICCFLAGS-OSX)" \
+ CXXFLAGS+='-arch x86_64' \
+ LDFLAGS+='-arch x86_64' \
+ all
+
+osx-icc32-profile-make:
+ $(MAKE) \
+ CXX='icpc' \
+ CXXFLAGS="$(ICCFLAGS-OSX)" \
+ CXXFLAGS+='-arch i386' \
+ CXXFLAGS+='-prof_gen -prof_dir ./profdir' \
+ LDFLAGS+='-arch i386' \
+ all
+
+osx-icc32-profile-use:
+ $(MAKE) \
+ CXX='icpc' \
+ CXXFLAGS="$(ICCFLAGS-OSX)" \
+ CXXFLAGS+='-arch i386' \
+ CXXFLAGS+='-prof_use -prof_dir ./profdir' \
+ LDFLAGS+='-arch i386' \
+ all
+
+osx-icc32-profile:
+ @rm -rf profdir
+ @mkdir profdir
+ @touch *.cpp *.h
+ $(MAKE) osx-icc32-profile-make
+ @echo ""
+ @echo "Running benchmark for pgo-build ..."
+ @$(PGOBENCH) > /dev/null
+ @echo "Benchmark finished. Build final executable now ..."
+ @echo ""
+ @touch *.cpp *.h
+ $(MAKE) osx-icc32-profile-use
+ @rm -rf profdir bench.txt
+
+osx-icc64-profile-make:
+ $(MAKE) \
+ CXX='icpc' \
+ CXXFLAGS="$(ICCFLAGS-OSX)" \
+ CXXFLAGS+='-arch x86_64' \
+ CXXFLAGS+='-prof_gen -prof_dir ./profdir' \
+ LDFLAGS+='-arch x86_64' \
+ all
+
+osx-icc64-profile-use:
+ $(MAKE) \
+ CXX='icpc' \
+ CXXFLAGS="$(ICCFLAGS-OSX)" \
+ CXXFLAGS+='-arch x86_64' \
+ CXXFLAGS+='-prof_use -prof_dir ./profdir' \
+ LDFLAGS+='-arch x86_64' \
+ all
+
+osx-icc64-profile:
+ @rm -rf profdir
+ @mkdir profdir
+ @touch *.cpp *.h
+ $(MAKE) osx-icc64-profile-make
+ @echo ""
+ @echo "Running benchmark for pgo-build ..."
+ @$(PGOBENCH) > /dev/null
+ @echo "Benchmark finished. Build final executable now ..."
+ @echo ""
+ @touch *.cpp *.h
+ $(MAKE) osx-icc64-profile-use
+ @rm -rf profdir bench.txt
+
+hpux:
+ $(MAKE) \
+ CXX='/opt/aCC/bin/aCC -AA +hpxstd98 -DBIGENDIAN -mt +O3 -DNDEBUG' \
+ CXXFLAGS="" \
+ LDFLAGS="" \
+ all
+
+
+strip:
+ strip $(EXE)
+
+
+### Compilation. Do not change
+$(EXE): $(OBJS)
+ $(CXX) -o $@ $(OBJS) $(LDFLAGS)
+### Installation
+install: default
+ -mkdir -p -m 755 $(BINDIR)
+ -cp $(EXE) $(BINDIR)
+ -strip $(BINDIR)/$(EXE)
-# Backwards compatibility with Mac OS X 10.4 when compiling with ICC. Doesn't
-# work yet. :-(
+### Dependencies. Do not change
+.depend:
+ -@$(CXX) -msse -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
-# CXXFLAGS += -DMAC_OS_X_VERSION_MIN_REQUIRED=1040
-# CXXFLAGS += -DMAC_OS_X_VERSION_MAX_ALLOWED=1040
-# CXXFLAGS += -D__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__=1040
-# CXXFLAGS += -F/Developer/SDKs/MacOSX10.4u.sdk/
-# LDFLAGS += -Wl,-syslibroot -Wl,/Developer/SDKs/MacOSX10.4u.sdk
+-include .depend