-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
145 lines (116 loc) · 2.78 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
#libs
LIBS = -lm
MAKE = make
RM = rm -f
BIN = .
DEFINE = -D_GNU_SOURCE -DUSE_GCC_X64
EXE = mperft
ifeq ($(BUILD),)
BUILD = fast
endif
ifeq ($(CC),)
CC = gcc
endif
ifeq ($(CC),cc)
CC = gcc
endif
ifeq ($(EXT),)
EXT=popcount
endif
ifeq ($(ARCH),)
ARCH=native
endif
#clang
ifeq ($(CC),clang)
CFLAGS = -std=c11 -Wall -W -pedantic $(DEFINE)
ifeq ($(BUILD),fast)
CFLAGS += -O3 -flto -DNDEBUG
else ifeq ($(BUILD),profile)
CFLAGS += -O3 -fno-inline -DNDEBUG
LIBS += -lprofiler
else
CFLAGS += -O0 -g -fno-inline -ftrapv
endif
ifeq ($(EXT),popcount)
DEFINE += -DPOPCOUNT
CFLAGS += -mpopcnt
else ifeq ($(EXT),pext)
DEFINE += -DUSE_PEXT -DPOPCOUNT
CFLAGS += -mbmi2 -mpopcnt
endif
PGO_GEN = -fprofile-instr-generate
PGO_USE = -fprofile-instr-use=mperft.profdata
PGO_MERGE = llvm-profdata merge -output=mperft.profdata mperft-*.profraw
endif
#gcc
ifeq ($(CC),gcc)
CFLAGS = -pipe -Wall -W -Wextra -pedantic -std=c11 $(DEFINE)
ifeq ($(BUILD),fast)
CFLAGS += -Ofast -flto -DNDEBUG
else ifeq ($(BUILD),profile)
CFLAGS += -O3 -pg -DNDEBUG
else ifeq ($(BUILD),cov)
CFLAGS += -O0 -fno-inline -fprofile-arcs -ftest-coverage -DNDEBUG
else
CFLAGS += -O0 -g -fno-inline -fstack-protector
endif
ifeq ($(EXT),popcount)
DEFINE += -DPOPCOUNT
CFLAGS += -mpopcnt
else ifeq ($(EXT),pext)
DEFINE += -DUSE_PEXT -DPOPCOUNT
CFLAGS += -mbmi2 -mpopcnt
endif
PGO_GEN = -fprofile-generate -lgcov
PGO_USE = -fprofile-use
PGO_MERGE =
endif
#mingw 64 bits
ifeq ($(CC),x86_64-w64-mingw32-gcc)
CFLAGS = -pipe -Wall -W -Wextra -pedantic -std=c11 $(DEFINE) -D__USE_MINGW_ANSI_STDIO -DWINVER=0x501
EXE = mperft.exe
ifeq ($(BUILD),fast)
CFLAGS += -O3 -flto -fwhole-program -DNDEBUG
else
CFLAGS += -O0 -g -fno-inline -fstack-protector
endif
ifeq ($(EXT),popcount)
DEFINE += -DPOPCOUNT
CFLAGS += -mpopcnt
else ifeq ($(EXT),pext)
DEFINE += -DUSE_PEXT -DPOPCOUNT
CFLAGS += -mbmi2 -mpopcnt
endif
PGO_GEN = -fprofile-generate -lgcov
PGO_USE = -fprofile-use
PGO_MERGE =
endif
#commands
all :
$(CC) $(CFLAGS) -march=$(ARCH) mperft.c -o $(BIN)/$(EXE) $(LIBS)
pgo :
@echo $(CFLAGS)
$(MAKE) clean
$(CC) $(CFLAGS) -march=$(ARCH) $(PGO_GEN) mperft.c -o $(BIN)/$(EXE) $(LIBS)
cd $(BIN); LLVM_PROFILE_FILE=mperft-%p.profraw ./$(EXE) -d 6 -b | grep perft;
cd $(BIN); LLVM_PROFILE_FILE=mperft-%p.profraw ./$(EXE) -d 7 -b -H 24 | grep perft;
$(PGO_MERGE)
$(CC) $(CFLAGS) -march=$(ARCH) $(PGO_USE) mperft.c -o $(BIN)/$(EXE) $(LIBS)
pext:$(SRC)
$(MAKE) pgo EXT=pext
prof:
$(MAKE) BUILD=profile
debug :
$(MAKE) BUILD=debug
cov :
$(MAKE) BUILD=cov
clean:
$(RM) *.o *.dyn *.gcda *.gcno pgopti* *.prof*
cd $(BIN); $(RM) *.prof*
test:
$(BIN)/mperft --test
.PHONY : all pgo prof release debug clean
SUFFIXES: .o .c
.c.o:
$(CC) $(CFLAGS) -DNOINCLUDE -c $< -o $@
# Dependencies