-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathMakefile
102 lines (87 loc) · 2.72 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
# \
Weiss is a UCI compliant chess engine. \
Copyright (C) 2023 Terje Kirstihagen \
\
This program is free software: you can redistribute it and/or modify \
it under the terms of the GNU General Public License as published by \
the Free Software Foundation, either version 3 of the License, or \
(at your option) any later version. \
\
This program is distributed in the hope that it will be useful, \
but WITHOUT ANY WARRANTY; without even the implied warranty of \
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \
GNU General Public License for more details. \
\
You should have received a copy of the GNU General Public License \
along with this program. If not, see <https://www.gnu.org/licenses/>. \
# \
# General
EXE = weiss
SRC = *.c pyrrhic/tbprobe.c tuner/*.c query/*.c noobprobe/*.c onlinesyzygy/*.c
CC = gcc
# Defines
POPCNT = -msse3 -mpopcnt
PEXT = $(POPCNT) -DUSE_PEXT -mbmi2
# Flags
STD = -std=gnu11
LIBS = -pthread -lm
WARN = -Wall -Wextra -Wshadow -Werror -Wmissing-declarations
NDEBUG = -DNDEBUG
FLAGS = $(STD) $(WARN) -O3 -flto=auto
CFLAGS = $(FLAGS) -march=native
RFLAGS = $(FLAGS) -static
# Use pext if supported and not a ryzen 1/2 cpu
PROPS = $(shell echo | $(CC) -march=native -E -dM -)
ifneq ($(findstring __BMI2__, $(PROPS)),)
ifeq ($(findstring __znver1, $(PROPS)),)
ifeq ($(findstring __znver2, $(PROPS)),)
CFLAGS += -DUSE_PEXT
endif
endif
endif
# PGO
ifneq ($(findstring gcc, $(CC)),)
PGO_DIR = "pgo"
PGO_GEN = -fprofile-generate=$(PGO_DIR)
PGO_USE = -fprofile-use=$(PGO_DIR)
else ifneq ($(findstring clang, $(CC)),)
PGO_MERGE = llvm-profdata merge -output=weiss.profdata *.profraw
PGO_GEN = -fprofile-instr-generate
PGO_USE = -fprofile-instr-use=weiss.profdata
endif
# Try to detect windows environment by seeing
# whether the shell filters out " or not.
ifeq ($(shell echo "test"), "test")
PGO_BENCH = $(EXE) bench 12 > nul 2>&1
PGO_CLEAN = rmdir /s /q $(PGO_DIR)
else
PGO_BENCH = ./$(EXE) bench 12 > /dev/null 2>&1
PGO_CLEAN = $(RM) -rf $(PGO_DIR)
endif
# Link winsock32 on windows for NoobBook
ifeq ($(OS), Windows_NT)
LIBS += -lwsock32
endif
# Compilations
BASIC = $(CC) $(CFLAGS) $(NDEBUG) $(SRC) $(LIBS) -o $(EXE)
RELEASE = $(CC) $(RFLAGS) $(NDEBUG) $(SRC) $(LIBS) -o $(EXE)
# Targets
pgo: clean
$(BASIC) $(PGO_GEN)
$(PGO_BENCH)
$(PGO_MERGE)
$(BASIC) $(PGO_USE)
@$(PGO_CLEAN)
basic: clean
$(BASIC)
dev: clean
$(BASIC) -DDEV
tune: clean
$(BASIC) -DTUNE -fopenmp
release: clean
$(RELEASE)-nopopcnt.exe
$(RELEASE)-popcnt.exe $(POPCNT)
$(RELEASE)-pext.exe $(PEXT)
clean:
@$(RM) -f $(EXE)
@$(PGO_CLEAN)