-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
190 lines (148 loc) · 7.17 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
.PHONY: all _all clean test
DBGFLAGS := -g3
FEATURE_SUPPORT_SANITIZE ?= $(shell ./scripts/compiler_support_sanitize $(CC))
FEATURE_SUPPORT_PGO ?= $(shell ./scripts/compiler_support_pgo $(CXX))
FEATURE_SUPPORT_GCC ?= $(shell ./scripts/compiler_support_gccflags $(CXX))
FEATURE_SUPPORT_CLANG ?= $(shell ./scripts/compiler_support_clangflags $(CXX))
FEATURE_SUPPORT_LIBBSD ?= $(shell ./scripts/compiler_support_libbsd $(CXX))
FEATURE_SUPPORT_JEMALLOC ?= $(shell ./scripts/compiler_support_jemalloc $(CXX))
FEATURE_SUPPORT_STDRANGES ?= $(shell ./scripts/compiler_support_stdranges $(CXX))
FEATURE_SUPPORT_GPROF ?= $(shell ./scripts/compiler_support_gprof $(CC))
FLAG_THREADS ?= $(shell ./scripts/compiler_flag_threads $(CXX))
$(info CXX is $(CXX))
$(info FEATURE_SUPPORT_SANITIZE is $(FEATURE_SUPPORT_SANITIZE))
$(info FEATURE_SUPPORT_PGO is $(FEATURE_SUPPORT_PGO))
$(info FEATURE_SUPPORT_GCC is $(FEATURE_SUPPORT_GCC))
$(info FEATURE_SUPPORT_CLANG is $(FEATURE_SUPPORT_CLANG))
$(info FEATURE_SUPPORT_LIBBSD is $(FEATURE_SUPPORT_LIBBSD))
$(info FEATURE_SUPPORT_JEMALLOC is $(FEATURE_SUPPORT_JEMALLOC))
$(info FEATURE_SUPPORT_STDRANGES is $(FEATURE_SUPPORT_STDRANGES))
$(info FLAG_THREADS is "$(FLAG_THREADS)")
# sanitization
ifeq ($(FEATURE_SUPPORT_SANITIZE),enabled)
ifeq ($(FEATURE_SUPPORT_GCC),gcc)
DBGFLAGS := -static-libasan $(DBGFLAGS)
endif
DBGFLAGS := $(DBGFLAGS) -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer
else ifeq ($(FEATURE_SUPPORT_SANITIZE),minimal)
DBGFLAGS := $(DBGFLAGS) -fsanitize-minimal-runtime -fno-omit-frame-pointer
endif
PROFFLAGS = -O1 -DNDEBUG -DFLAG_PROFILING -flto=auto -DUSE_INTRIN -pg
OPTFLAGS := -O3 -ffast-math -DNDEBUG -flto=auto -fno-trapping-math -fno-signed-zeros -march=native -DUSE_INTRIN -fno-exceptions
ifeq ($(shell arch),x86_64)
OPTFLAGS := $(OPTFLAGS) -m64
endif
PKGCONFIG ?= $(shell ./scripts/command_pkgconfig)
CXXFLAGS := -std=c++20 -I. -Wall -Wextra -fno-stack-protector
LDFLAGS := $(FLAG_THREADS)
# compiler-specific
ifeq ($(FEATURE_SUPPORT_GCC),gcc)
OPTFLAGS := -fwhole-program $(OPTFLAGS)
CXXFLAGS := $(CXXFLAGS) -Wno-unused -Wno-parentheses
else ifeq ($(FEATURE_SUPPORT_CLANG),clang)
CXXFLAGS := $(CXXFLAGS) -Wno-unused-parameter -Wno-unused-variable -Wno-unused-but-set-variable \
-Wno-range-loop-construct -Wno-unknown-attributes -Wno-parentheses
endif
# bsd
ifeq ($(FEATURE_SUPPORT_LIBBSD),disabled)
CXXFLAGS := $(CXXFLAGS) -DFLAG_BSD
LDFLAGS := -lbsd $(LDFLAGS)
endif
# jemalloc
ifeq ($(FEATURE_SUPPORT_JEMALLOC),builtin)
CXXFLAGS := $(CXXFLAGS) -DFLAG_JEMALLOC_BUILTIN
else ifeq ($(FEATURE_SUPPORT_JEMALLOC),external)
CXXFLAGS := $(CXXFLAGS) $(shell $(PKGCONFIG) --cflags jemalloc) -DFLAG_JEMALLOC_EXTERNAL
LDFLAGS := $(LDFLAGS) $(shell $(PKGCONFIG) --libs jemalloc)
else ifeq ($(FEATURE_SUPPORT_JEMALLOC),disabled)
CXXFLAGS := $(CXXFLAGS) -DFLAG_JEMALLOC_DISABLED
endif
# ranges
ifeq ($(FEATURE_SUPPORT_STDRANGES),disabled)
CXXFLAGS := $(CXXFLAGS) -DFLAG_STDRANGES
endif
# CXXFLAGS += -fopt-info
NC_CFLAGS = $(shell $(PKGCONFIG) --cflags ncursesw)
NC_LDFLAGS = $(shell $(PKGCONFIG) --libs ncursesw)
HPPFILES = $(wildcard *.hpp) m42.h tbconfig.h
SOURCE_DEPS = external/syzygy external/fathom
SOURCES = m42.cpp
SHARED_LIB_EXT := so
ifeq ($(shell uname),Darwin)
SHARED_LIB_EXT := dylib
endif
TARGETS := dummy_chess dummy_chess_curses dummy_chess_bench
ifeq ($(FEATURE_SUPPORT_GPROF),enabled)
TARGETS := $(TARGETS) dummy_chess_alphabeta
endif
LIBDUMMYCHESS := libdummychess.$(SHARED_LIB_EXT)
TARGETS += dummy_chess_uci dummy_chess_uci_dbg $(LIBDUMMYCHESS) libdummychess.a
CORES = $(shell getconf _NPROCESSORS_ONLN)
all :; @$(MAKE) _all -j$(CORES)
_all : $(TARGETS) $(SOURCE_DEPS)
external/syzygy:
./scripts/syzygy_download
external/fathom:
./scripts/fathom_download
m42.cpp:
./scripts/m42_download
m42.h:
./scripts/m42_download
dummy_chess: simple.cpp $(SOURCES) $(HPPFILES) Makefile $(SOURCE_DEPS)
$(CXX) $(DBGFLAGS) $(CXXFLAGS) simple.cpp $(SOURCES) $(LDFLAGS) -o $@
dummy_chess_curses: ui.cpp $(SOURCES) $(HPPFILES) Makefile $(SOURCE_DEPS)
$(CXX) $(OPTFLAGS) $(CXXFLAGS) $(NC_CFLAGS) ui.cpp $(SOURCES) $(LDFLAGS) $(NC_LDFLAGS) $(LDFLAGS) -o $@
DEPS_SHARED := shared_object.cpp $(SOURCES) $(HPPFILES) Makefile $(SOURCE_DEPS)
DEPS_STATIC := $(SOURCES) $(HPPFILES) Makefile $(SOURCE_DEPS)
DEPS_BENCH := bench.cpp $(DEPS_SHARED)
DEPS_ALPHABETA := alphabeta.cpp $(DEPS_SHARED)
DEPS_UCI := uci.cpp $(DEPS_SHARED)
ifeq ($(FEATURE_SUPPORT_PGO),disabled)
dummy_chess_bench: $(DEPS_BENCH)
$(CXX) $(OPTFLAGS) $(CXXFLAGS) bench.cpp $(SOURCES) $(LDFLAGS) -o $@
dummy_chess_alphabeta: $(DEPS_ALPHABETA)
$(CXX) $(PROFFLAGS) $(CXXFLAGS) alphabeta.cpp $(SOURCES) $(LDFLAGS) -o $@
dummy_chess_uci: $(DEPS_UCI)
$(CXX) $(OPTFLAGS) $(CXXFLAGS) -DMUTE_ERRORS uci.cpp $(SOURCES) $(LDFLAGS) -o $@
$(LIBDUMMYCHESS): $(DEPS_SHARED)
$(CXX) $(OPTFLAGS) $(CXXFLAGS) -DMUTE_ERRORS $(SOURCES) $(LDFLAGS) -fPIC -shared -o $@
else ifeq ($(FEATURE_SUPPORT_PGO),gcc)
dummy_chess_bench: $(DEPS_BENCH) dummy_chess_uci
$(CXX) $(OPTFLAGS) -fprofile-use $(CXXFLAGS) bench.cpp $(SOURCES) $(LDFLAGS) -o $@
dummy_chess_alphabeta: $(DEPS_ALPHABETA) dummy_chess_uci
$(CXX) $(PROFFLAGS) -fprofile-use -fprofile-correction $(CXXFLAGS) alphabeta.cpp $(SOURCES) $(LDFLAGS) -o $@
dummy_chess_uci: $(DEPS_UCI)
rm -vf *.gcda
$(CXX) $(OPTFLAGS) -fprofile-generate $(CXXFLAGS) -DMUTE_ERRORS uci.cpp $(SOURCES) $(LDFLAGS) -o $@
./scripts/pgo_bench.py "./dummy_chess_uci"
$(CXX) $(OPTFLAGS) -fprofile-use -fprofile-correction $(CXXFLAGS) -DMUTE_ERRORS uci.cpp $(SOURCES) $(LDFLAGS) -o $@
$(LIBDUMMYCHESS): $(DEPS_SHARED)
$(CXX) $(OPTFLAGS) -fprofile-use -fprofile-correction $(CXXFLAGS) -DMUTE_ERRORS $(SOURCES) $(LDFLAGS) -fPIC -shared -o $@
else ifeq ($(FEATURE_SUPPORT_PGO),clang)
LLVM_PROFDATA = $(shell $(CXX) -print-prog-name=llvm-profdata)
dummy_chess_bench: $(DEPS_BENCH) dummy_chess_uci
$(CXX) $(OPTFLAGS) -fprofile-use=uci.profdata $(CXXFLAGS) bench.cpp $(SOURCES) $(LDFLAGS) -o $@
dummy_chess_alphabeta: $(DEPS_ALPHABETA) dummy_chess_uci
$(CXX) $(PROFFLAGS) -fprofile-use=uci.profdata $(CXXFLAGS) -Wno-backend-plugin alphabeta.cpp $(SOURCES) $(LDFLAGS) -o $@
dummy_chess_uci: $(DEPS_UCI)
rm -rvf uci.d.profdata
rm -vf uci.profdata
$(CXX) $(OPTFLAGS) -fprofile-generate=uci.d.profdata -DMUTE_ERRORS $(CXXFLAGS) uci.cpp $(SOURCES) $(LDFLAGS) -o $@
./scripts/pgo_bench.py "./dummy_chess_uci"
$(LLVM_PROFDATA) merge -output=uci.profdata uci.d.profdata
$(CXX) $(OPTFLAGS) -fprofile-use=uci.profdata $(CXXFLAGS) -DMUTE_ERRORS uci.cpp $(SOURCES) $(LDFLAGS) -o $@
$(LIBDUMMYCHESS): $(DEPS_SHARED)
$(CXX) $(OPTFLAGS) -fprofile-use=uci.profdata $(CXXFLAGS) -DMUTE_ERRORS $(SOURCES) $(LDFLAGS) -fPIC -shared -o $@
endif
dummy_chess_uci_dbg: $(DEPS_UCI)
$(CXX) $(DBGFLAGS) $(CXXFLAGS) uci.cpp $(SOURCES) $(LDFLAGS) -o $@
libdummychess.a: $(DEPS_STATIC)
$(CXX) $(OPTFLAGS) $(CXXFLAGS) -c shared_object.cpp $(LDFLAGS) -o shared_object.o
$(CXX) $(OPTFLAGS) $(CXXFLAGS) -c m42.cpp $(LDFLAGS) -o m42.o
ar rcs "$@" shared_object.o m42.o
test:
./scripts/perft_test.py
clean:
rm -vf *.o *.gcda uci.profdata
rm -rvf uci.d.profdata
rm -vf dummy_chess dummy_chess_opt dummy_chess_curses dummy_chess_bench dummy_chess_alphabeta dummy_chess_uci dummy_chess_uci_dbg $(LIBDUMMYCHESS) libdummychess.a