]> git.sesse.net Git - stockfish/blobdiff - src/Makefile
Restore development version
[stockfish] / src / Makefile
index a7d749a4d44707696810d13247f1733a45006a5a..935445e052b9cca92eb6469fb82311642de75af6 100644 (file)
 ### ==========================================================================
 
 ### Establish the operating system name
-UNAME = $(shell uname)
+KERNEL = $(shell uname -s)
+ifeq ($(KERNEL),Linux)
+       OS = $(shell uname -o)
+endif
 
 ### Executable name
 EXE = stockfish
@@ -32,7 +35,7 @@ PREFIX = /usr/local
 BINDIR = $(PREFIX)/bin
 
 ### Built-in benchmark for pgo-builds
-PGOBENCH = ./$(EXE) bench 16 1 1000 default time
+PGOBENCH = ./$(EXE) bench
 
 ### Object files
 OBJS = benchmark.o bitbase.o bitboard.o endgame.o evaluate.o main.o \
@@ -47,6 +50,7 @@ OBJS = benchmark.o bitbase.o bitboard.o endgame.o evaluate.o main.o \
 # ----------------------------------------------------------------------------
 #
 # debug = yes/no      --- -DNDEBUG         --- Enable/Disable debug mode
+# sanitize = yes/no   --- (-fsanitize )    --- enable undefined behavior checks
 # optimize = yes/no   --- (-O3/-fast etc.) --- Enable/Disable optimizations
 # arch = (name)       --- (-arch)          --- Target architecture
 # bits = 64/32        --- -DIS_64BIT       --- 64-/32-bit operating system
@@ -62,6 +66,7 @@ OBJS = benchmark.o bitbase.o bitboard.o endgame.o evaluate.o main.o \
 ### 2.1. General and architecture defaults
 optimize = yes
 debug = no
+sanitize = no
 bits = 32
 prefetch = no
 popcnt = no
@@ -145,8 +150,17 @@ endif
 ifeq ($(COMP),gcc)
        comp=gcc
        CXX=g++
-       CXXFLAGS += -pedantic -Wextra -Wshadow -m$(bits)
-       ifneq ($(UNAME),Darwin)
+       CXXFLAGS += -pedantic -Wextra -Wshadow
+
+       ifeq ($(ARCH),armv7)
+               ifeq ($(OS),Android)
+                       CXXFLAGS += -m$(bits)
+               endif
+       else
+               CXXFLAGS += -m$(bits)
+       endif
+
+       ifneq ($(KERNEL),Darwin)
           LDFLAGS += -Wl,--no-as-needed
        endif
 endif
@@ -154,7 +168,7 @@ endif
 ifeq ($(COMP),mingw)
        comp=mingw
 
-       ifeq ($(UNAME),Linux)
+       ifeq ($(KERNEL),Linux)
                ifeq ($(bits),64)
                        ifeq ($(shell which x86_64-w64-mingw32-c++-posix),)
                                CXX=x86_64-w64-mingw32-c++
@@ -185,9 +199,19 @@ endif
 ifeq ($(COMP),clang)
        comp=clang
        CXX=clang++
-       CXXFLAGS += -pedantic -Wextra -Wshadow -m$(bits)
-       LDFLAGS += -m$(bits)
-       ifeq ($(UNAME),Darwin)
+       CXXFLAGS += -pedantic -Wextra -Wshadow
+
+       ifeq ($(ARCH),armv7)
+               ifeq ($(OS),Android)
+                       CXXFLAGS += -m$(bits)
+                       LDFLAGS += -m$(bits)
+               endif
+       else
+               CXXFLAGS += -m$(bits)
+               LDFLAGS += -m$(bits)
+       endif
+
+       ifeq ($(KERNEL),Darwin)
                CXXFLAGS += -stdlib=libc++
                DEPENDFLAGS += -stdlib=libc++
        endif
@@ -205,7 +229,7 @@ else
        profile_clean = gcc-profile-clean
 endif
 
-ifeq ($(UNAME),Darwin)
+ifeq ($(KERNEL),Darwin)
        CXXFLAGS += -arch $(arch) -mmacosx-version-min=10.9
        LDFLAGS += -arch $(arch) -mmacosx-version-min=10.9
 endif
@@ -223,21 +247,27 @@ endif
 ### On mingw use Windows threads, otherwise POSIX
 ifneq ($(comp),mingw)
        # On Android Bionic's C library comes with its own pthread implementation bundled in
-       ifneq ($(arch),armv7)
+       ifneq ($(OS),Android)
                # Haiku has pthreads in its libroot, so only link it in on other platforms
-               ifneq ($(UNAME),Haiku)
+               ifneq ($(KERNEL),Haiku)
                        LDFLAGS += -lpthread
                endif
        endif
 endif
 
-### 3.2 Debugging
+### 3.2.1 Debugging
 ifeq ($(debug),no)
        CXXFLAGS += -DNDEBUG
 else
        CXXFLAGS += -g
 endif
 
+### 3.2.2 Debugging with undefined behavior sanitizers
+ifeq ($(sanitize),yes)
+        CXXFLAGS += -g3 -fsanitize=undefined
+        LDFLAGS += -fsanitize=undefined
+endif
+
 ### 3.3 Optimization
 ifeq ($(optimize),yes)
 
@@ -245,7 +275,7 @@ ifeq ($(optimize),yes)
 
        ifeq ($(comp),gcc)
 
-               ifeq ($(UNAME),Darwin)
+               ifeq ($(KERNEL),Darwin)
                        ifeq ($(arch),i386)
                                CXXFLAGS += -mdynamic-no-pic
                        endif
@@ -254,19 +284,19 @@ ifeq ($(optimize),yes)
                        endif
                endif
 
-               ifeq ($(arch),armv7)
+               ifeq ($(OS), Android)
                        CXXFLAGS += -fno-gcse -mthumb -march=armv7-a -mfloat-abi=softfp
                endif
        endif
 
        ifeq ($(comp),icc)
-               ifeq ($(UNAME),Darwin)
+               ifeq ($(KERNEL),Darwin)
                        CXXFLAGS += -mdynamic-no-pic
                endif
        endif
 
        ifeq ($(comp),clang)
-               ifeq ($(UNAME),Darwin)
+               ifeq ($(KERNEL),Darwin)
                        ifeq ($(pext),no)
                                CXXFLAGS += -flto
                                LDFLAGS += $(CXXFLAGS)
@@ -309,7 +339,7 @@ endif
 ifeq ($(pext),yes)
        CXXFLAGS += -DUSE_PEXT
        ifeq ($(comp),$(filter $(comp),gcc clang mingw))
-               CXXFLAGS += -mbmi -mbmi2
+               CXXFLAGS += -mbmi2
        endif
 endif
 
@@ -326,7 +356,7 @@ ifeq ($(comp),gcc)
 endif
 
 ifeq ($(comp),mingw)
-       ifeq ($(UNAME),Linux)
+       ifeq ($(KERNEL),Linux)
        ifeq ($(optimize),yes)
        ifeq ($(debug),no)
                CXXFLAGS += -flto
@@ -338,7 +368,7 @@ endif
 
 ### 3.9 Android 5 can only run position independent executables. Note that this
 ### breaks Android 4.0 and earlier.
-ifeq ($(arch),armv7)
+ifeq ($(OS), Android)
        CXXFLAGS += -fPIE
        LDFLAGS += -fPIE -pie
 endif
@@ -443,9 +473,12 @@ config-sanity:
        @echo ""
        @echo "Config:"
        @echo "debug: '$(debug)'"
+       @echo "sanitize: '$(sanitize)'"
        @echo "optimize: '$(optimize)'"
        @echo "arch: '$(arch)'"
        @echo "bits: '$(bits)'"
+       @echo "kernel: '$(KERNEL)'"
+       @echo "os: '$(OS)'"
        @echo "prefetch: '$(prefetch)'"
        @echo "popcnt: '$(popcnt)'"
        @echo "sse: '$(sse)'"
@@ -459,6 +492,7 @@ config-sanity:
        @echo "Testing config sanity. If this fails, try 'make help' ..."
        @echo ""
        @test "$(debug)" = "yes" || test "$(debug)" = "no"
+       @test "$(sanitize)" = "yes" || test "$(sanitize)" = "no"
        @test "$(optimize)" = "yes" || test "$(optimize)" = "no"
        @test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
         test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "armv7"