summaryrefslogtreecommitdiff
path: root/src/GNUmakefile
blob: 601a362c1ab937a75bdaa16db87b363080c4bda6 (plain)
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# Makefile (for typhoon/GNU-style make).  Recognized gmake variables:
#
#  DEBUG=1: make debug version (includes asserts and sanity checks)
#  TEST=1: include self-test code in the binary produced
#  ASM=1: create assembly code, does not link final binary
#  EVAL_DUMP=1: make a version that can dump eval breakdowns
#  EVAL_TIME=1: make a version that counts cycles spent in eval
#  PERF_COUNTERS=1: make version with perf counters enabled
#  BOUNDS_CHECKING=1: make version with bounds checking enabled
#  MP=1: make version for multi-processor machine
#  DUMP_TREE=1: internal tree dumping version
#  SEE_HEAPS=1: use minheaps in the SEE code
#  OSX=1: build for an Intel-based Apple Mac (omit this for FreeBSD/Linux)
#  USE_READLINE=1: link against the GNU readline library
#  SIXTYFOUR=1: make an X64 binary
#  CROUTINES=1: use the C versions of the asm routines [slower]
#  GETATTACKS_BITBOARD=1: use the bbPieces/bbPawns-backed _GetAttacksBB
#    instead of the asm/CROUTINES GetAttacks -- see
#    board_representation/MIGRATION.md section 6
#  EVERYTHING=1: everything everything everything everything
#
# $Id$
#
CC 		= 	clang
CXX		=	clang++
NASM		=	yasm

# Default to a 64-bit build -- 32-bit clang isn't available in this
# environment anyway (see CLAUDE.md). Still overridable in principle
# (e.g. `gmake SIXTYFOUR=` won't un-set it since ?= only fires when
# unset, but this matches how every build in this session has actually
# been invoked).
SIXTYFOUR	?=	1
ifdef OSX
 LIBRARIES	=	-pthread -lc
 ifdef SIXTYFOUR
  $(warning you will need to use yasm for now to get x64 on OSX)
  NASMFLAGS	=	-f macho64 -dOSX -d_X64_
 else
  NASMFLAGS	=	-f macho -dOSX
 endif
else
 LIBRARIES	=	-pthread -lc -lstdc++ 
 ifdef SIXTYFOUR
  NASMFLAGS	=	-f elf64 -d__GNUC__
 else
  NASMFLAGS	=	-f elf -d__GNUC__
 endif
endif
RM		= 	/bin/rm

#
# Setup commandline based on make defines
#
ifdef ASM
 ifdef SIXTYFOUR
  PROFILE	=	-S -fverbose-asm -D_X64_
 else
  PROFILE	=	-S -fverbose-asm -D_X86_
 endif
else
 ifdef SIXTYFOUR
  PROFILE 	=	-D_X64_
 else
  PROFILE 	=	-D_X86_
 endif
endif

ifdef OSX
 PROFILE	+=	-DOSX
endif

ifdef GENETIC
 PROFILE	+=	-DGENETIC
endif

ifdef DEBUG
 PROFILE 	+=	-g -O2 -DDEBUG
 BINARY 	=	_typhoon
else
 PROFILE	+=	-g -O3 -ffast-math -finline-functions
 BINARY 	=	typhoon
endif

ifdef USE_READLINE
 LIBRARIES	+=	-lreadline
 PROFILE	+=	-DUSE_READLINE
endif

ifdef SIXTYFOUR
 PROFILE	+=	-m64
 NASMFLAGS	+=	-d_X64_
else
 PROFILE	+=	-m32
 NASMFLAGS	+=	-d_X86_
endif

ifdef CROUTINES
 PROFILE	+=	-DCROUTINES
endif

ifdef GETATTACKS_BITBOARD
 PROFILE	+=	-DGETATTACKS_BITBOARD
endif

ifdef EVERYTHING
PROFILE 	+=	-DEVAL_DUMP -DEVAL_TIME -DPERF_COUNTERS -DMP -DSMP -DTEST_NULL -DDUMP_TREE -fbounds-checking
else
ifdef EVAL_DUMP
PROFILE		+= 	-DEVAL_DUMP
endif
ifdef EVAL_TIME
PROFILE		+= 	-DEVAL_TIME
endif
ifdef PERF_COUNTERS
PROFILE		+=	-DPERF_COUNTERS
endif
ifdef BOUNDS_CHECKING
PROFILE		+=	-fbounds-checking
endif
ifdef MP
PROFILE		+=	-DMP -DSMP
endif
ifdef TEST_NULL
PROFILE		+=	-DTEST_NULL
endif
ifdef DUMP_TREE
PROFILE 	+=  -DDUMP_TREE
endif
endif # EVERYTHING

# Short commit hash (plus a -dirty suffix if the working tree has
# uncommitted changes) baked into the binary so a --logfile trace can
# be tied back to the exact source state, not just a build timestamp --
# distinguishing rebuilds of the same day/commit during A/B testing was
# previously only possible by diffing binaries. Placed here, after all
# the PROFILE-overwriting `=` assignments above (not `+=`), so it
# survives into CFLAGS instead of being wiped out by them.
GIT_COMMIT	:=	$(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
GIT_DIRTY	:=	$(shell git diff --quiet 2>/dev/null || echo -dirty)
# Kept out of PROFILE itself (not folded in via +=): PROFILE gets
# stringified whole into -DPROFILE="..." below for the "Make profile
# used" trace line, and this value's embedded quotes broke that outer
# string literal when it was included there.
CFLAGS		=	-DPROFILE="\"$(PROFILE)\"" -DGIT_COMMIT=\"$(GIT_COMMIT)$(GIT_DIRTY)\" $(PROFILE) -Wall -Wno-nan-infinity-disabled -Ifathom
HEADERS 	=	chess.h compiler.h
FATHOM_CFLAGS	=	-std=gnu99 -O2 -Ifathom $(filter -m32 -m64,$(PROFILE))

#
# ---> .o, not .c! <---
# 
OBJS    =       main.o root.o search.o searchsup.o draw.o dynamic.o \
		hash.o eval.o evalhash.o x86.o pawnhash.o bitboard.o \
		generate.o see.o move.o movesup.o command.o script.o \
		input.o vars.o util.o unix.o gamelist.o mersenne.o \
		sig.o piece.o ics.o san.o fen.o book.o bench.o board.o \
		data.o probe.o fathom.o recogn.o list.o x64.o

ifdef TEST
# ---> .o, not .c! <---
# 
OBJS    +=      testdraw.o testmove.o testfen.o testgenerate.o \
		testsan.o testics.o testeval.o testbitboard.o \
		testhash.o testsee.o testsearch.o testsup.o
PROFILE +=	-DTEST
else
ifdef EVAL_DUMP
OBJS	+=	testeval.o testsup.o
endif
endif
ifdef DUMP_TREE
OBJS	+=	dumptree.o
endif
ifdef MP
OBJS	+=	split.o
endif

.SUFFIXES:	.c .o
.SUFFIXES:	.cpp .o
.SUFFIXES:	.asm .o

.PHONY:		all
all:		$(BINARY)

$(BINARY):	$(OBJS)
		$(CXX) $(PROFILE) -o $(BINARY) -Wall $(LIBRARIES) \
		$(OBJS)

%.o:        %.c $(HEADERS)
		$(CC) $(CFLAGS) -c $< -o $@

fathom.o:	fathom/tbprobe.c fathom/tbchess.c fathom/tbconfig.h fathom/tbprobe.h fathom/stdendian.h
		$(CC) $(FATHOM_CFLAGS) -c fathom/tbprobe.c -o $@

%.o:        %.cpp $(HEADERS)
		$(CXX) $(CFLAGS) -c -w $< -o $@

%.o:        %.asm $(HEADERS)
		$(NASM) $(NASMFLAGS) -o $@ $<

.PHONY:		release
release:
		$(MAKE) -j5 MP=1 GENETIC=1

.PHONY:		debug
debug:
		$(MAKE) -j5 DEBUG=1 PERF_COUNTERS=1 GENETIC=1

.PHONY:		clean
clean:
		$(RM) -f *.o *.core *~ *.gmon \#*\# typhoon _typhoon