-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
289 lines (243 loc) · 9.82 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
PROJECT_DIR := $(shell pwd)
USER ?= $(shell id -un)
JOBS ?= $$(( $$(grep processor /proc/cpuinfo|tail -1|cut -d: -f2) + 1))
VERBOSE ?= 0
SRC_DIR ?= ${PROJECT_DIR}/src
EXTERNAL_DIR ?= ${PROJECT_DIR}/external
BSD_DIR ?= ${EXTERNAL_DIR}/bsd
INSTALL_DIR ?= ${PROJECT_DIR}/opt
BUILD_DIR ?= ${PROJECT_DIR}/build
CMAKE ?= cmake
PLATFORM = $(shell uname -n | tr a-z A-Z)
CC := ${INSTALL_DIR}/bin/clang
.SUFFIXES: .o .c .h
SRC_DIRS = \
${SRC_DIR} \
${SRC_DIR}/txm \
${SRC_DIR}/sm \
${SRC_DIR}/bench \
${SRC_DIR}/lib/liblatch \
${SRC_DIR}/lib/libmsg
CFLAGS += -std=c99
CFLAGS += -Werror
CFLAGS += -g -ggdb
CFLAGS += -march=native -O3 -fno-omit-frame-pointer
CPPFLAGS ?=
CPPFLAGS += -D_GNU_SOURCE -D${PLATFORM}
CPPFLAGS += $(foreach dir, $(SRC_DIRS), -I$(dir)/)
LDFLAGS += -lpthread -lm -lrt -lnuma
SRCS = $(foreach dir, $(SRC_DIRS), $(wildcard $(dir)/*.c))
OBJS = $(SRCS:.c=.o)
DEPS = $(wildcard *.h)
all: llvm | trireme
@echo "-----------------------------------------------------------------------"
@echo ""
trireme: ${OBJS}
@echo "[LD] $(subst ${SRC_DIR}/,,$@)"
${CC} -o $@ $^ ${LDFLAGS}
%.o: %.c ${DEPS}
@echo "[CC] $(subst ${SRC_DIR}/,,$@)"
${CC} -c ${CFLAGS} ${CPPFLAGS} -o $@ $<
#######################################################################
# top-level targets, checks if a call to make is required before
# calling it.
#######################################################################
.PHONY: llvm
llvm: .llvm.install_done
#######################################################################
# Install targets
#######################################################################
#######################################################################
# Build targets
#######################################################################
do-build-llvm: .llvm.configure_done
cd ${BUILD_DIR}/llvm && \
make -j ${JOBS}
#######################################################################
# Configure targets
#######################################################################
COMMON_ENV := \
PATH=${INSTALL_DIR}/bin:${PATH} \
CC=${INSTALL_DIR}/bin/clang \
CXX=${INSTALL_DIR}/bin/clang++ \
CPP=${INSTALL_DIR}/bin/clang\ -E
# LLVM_ENABLE_CXX11: Make sure everything compiles using C++11
# LLVM_ENABLE_EH: required for throwing exceptions
# LLVM_ENABLE_RTTI: required for dynamic_cast
# LLVM_REQUIRE_RTTI: required for dynamic_cast
LLVM_TARGETS_TO_BUILD:= \
$$(case $$(uname -m) in \
x86|x86_64) echo "X86";; \
ppc64le) echo "PowerPC";; \
esac)
do-conf-llvm: .llvm.checkout_done
[ -d ${BUILD_DIR}/llvm ] || mkdir -p ${BUILD_DIR}/llvm
cd ${BUILD_DIR}/llvm && $(CMAKE) ${BSD_DIR}/llvm \
-DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DLLVM_ENABLE_CXX11=ON \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_ENABLE_PIC=ON \
-DLLVM_ENABLE_EH=ON \
-DLLVM_ENABLE_RTTI=ON \
-DLLVM_REQUIRES_RTTI=ON \
-DBUILD_SHARED_LIBS=ON \
-DLLVM_USE_INTEL_JITEVENTS:BOOL=ON \
-DLLVM_TARGETS_TO_BUILD="${LLVM_TARGETS_TO_BUILD}" \
-Wno-dev
#######################################################################
# Checkout sources as needed
#######################################################################
.PRECIOUS: ${BSD_DIR}/clang
.PRECIOUS: ${BSD_DIR}/compiler-rt
.PRECIOUS: ${BSD_DIR}/libcxx
.PRECIOUS: ${BSD_DIR}/libcxxabi
.PRECIOUS: ${BSD_DIR}/libunwind
.PRECIOUS: ${BSD_DIR}/llvm
do-checkout-llvm:
# No way of adding from a top level submodules within sub-
# modules, so stickying to this method.
git submodule update --init --recursive ${BSD_DIR}/llvm ${BSD_DIR}/clang ${BSD_DIR}/compiler-rt ${BSD_DIR}/libcxx ${BSD_DIR}/libcxxabi ${BSD_DIR}/libunwind
ln -sf ../../clang ${BSD_DIR}/llvm/tools/clang
ln -sf ../../compiler-rt ${BSD_DIR}/llvm/projects/compiler-rt
ln -sf ../../libcxx ${BSD_DIR}/llvm/projects/libcxx
ln -sf ../../libcxxabi ${BSD_DIR}/llvm/projects/libcxxabi
ln -sf ../../libunwind ${BSD_DIR}/llvm/projects/libunwind
# for CUDA 9.1+ support on LLVM 6:
# git cherry-pick ccacb5ddbcbb10d9b3a4b7e2780875d1e5537063
cd ${BSD_DIR}/llvm/tools/clang && git cherry-pick ccacb5ddbcbb10d9b3a4b7e2780875d1e5537063
# for CUDA 9.2 support on LLVM 6:
# git cherry-pick 5f76154960a51843d2e49c9ae3481378e09e61ef
cd ${BSD_DIR}/llvm/tools/clang && git cherry-pick 5f76154960a51843d2e49c9ae3481378e09e61ef
#######################################################################
# Clean targets
#######################################################################
clean-trireme:
-rm -f trireme ${OBJS}
# LSC: FIXME, objects should be moved to BUILD_DIR/trireme
#-rm .$$(echo $@ | sed -e 's,clean-,,').*_done
#-rm -rf ${BUILD_DIR}/$$(echo $@ | sed -e 's,clean-,,')
#######################################################################
# Makefile utils / Generic targets
#######################################################################
ifeq (${VERBOSE},0)
# Do not echo the commands before executing them.
.SILENT:
endif
ifeq (${COVERAGE},1)
# Compile with code coverage options
CFLAGS += -fprofile-instr-generate -fcoverage-mapping
LDFLAGS += -fprofile-instr-generate
default.merge:
${INSTALL_DIR}/bin/llvm-profdata merge -output=default.merge -instr default.profraw
.PHONY: cov-merge
cov-merge: default.merge
.PHONY: cov-show
cov-show: default.merge
${INSTALL_DIR}/bin/llvm-cov show trireme -instr-profile=default.merge
.PHONY: cov-report
cov-report: default.merge
${INSTALL_DIR}/bin/llvm-cov report trireme -instr-profile=default.merge
.PHONY: cov
cov: default.merge
${INSTALL_DIR}/bin/llvm-cov cov trireme -instr-profile=default.merge
endif
.PHONY: help
help:
@echo "-----------------------------------------------------------------------"
@echo "The general commands are available:"
@echo " * show-config Display configuration variables such as paths,"
@echo " number of jobs and other tunable options."
@echo " * clean Remove trireme object files and binaries."
@echo " * dist-clean Cleans the repository to a pristine state,"
@echo " just like after a new clone of the sources."
@echo "-----------------------------------------------------------------------"
@echo "If the COVERAGE variable is set to '1' while building, the following "
@echo "target can be used as well while COVERAGE=1 is set: "
@echo " * cov-merge After running the program, use this to prepare"
@echo " the profile data for reporting."
@echo " This is called automatically when needed"
@echo " from the two following targets."
@echo " * cov-show Show each line of code and the number of"
@echo " execution of that line."
@echo " * cov-report Show a table with filename and the percentage "
@echo " of line executed in that file."
@echo "-----------------------------------------------------------------------"
@echo " In the following targets, '%' can be replaced by one of the external"
@echo " project among the following list: llvm"
@echo ""
@echo " * clean-% Removes the object files of '%'"
@echo " * dist-clean-% Removes everything from project '%', forcing a"
@echo " build from scratch of '%'."
@echo "-----------------------------------------------------------------------"
.PHONY: show-config
show-config:
@echo "-----------------------------------------------------------------------"
@echo "Configuration:"
@echo "-----------------------------------------------------------------------"
@echo "PROJECT_DIR := ${PROJECT_DIR}"
@echo "SRC_DIR := ${SRC_DIR}"
@echo "EXTERNAL_DIR := ${EXTERNAL_DIR}"
@echo "BSD_DIR := ${BSD_DIR}"
@echo "BUILD_DIR := ${BUILD_DIR}"
@echo "INSTALL_DIR := ${INSTALL_DIR}"
@echo "JOBS := ${JOBS}"
@echo "USER := ${USER}"
@echo "VERBOSE := ${VERBOSE}"
@echo "-----------------------------------------------------------------------"
.PHONY: dist-clean
dist-clean:
-rm -rf ${EXTERNAL_DIR}
-git clean -dxf .
.PHONY: clean
clean: clean-trireme
PHONY: dist-clean-%
dist-clean-%: clean-%
-rm -rf ${EXTERNAL_DIR}/*/$$(echo $@ | sed -e 's,dist-clean-,,')
.PHONY: clean-%
clean-%:
-rm .$$(echo $@ | sed -e 's,clean-,,').*_done
-rm -rf ${BUILD_DIR}/$$(echo $@ | sed -e 's,clean-,,')
%: .%.install_done
.PHONY: do-install-%
do-install-%: .%.build_done
[ -d ${INSTALL_DIR} ] || mkdir -p ${INSTALL_DIR}
cd ${BUILD_DIR}/$$(echo $@ | sed -e 's,do-install-,,') && \
make -j ${JOBS} install
.PHONY: do-build-%
do-build-%: .%.configure_done
cd ${BUILD_DIR}/$$(echo $@ | sed -e 's,do-build-,,') && \
make -j ${JOBS}
.PHONY: do-conf-%
.PHONY: do-checkout-%
do-checkout-%:
git submodule update --init --recursive \
$$(git submodule status | grep $$(echo $@ | sed -e 's,do-checkout-,,') | cut -d ' ' -f 3)
.PRECIOUS: .%.install_done
.%.install_done: .%.build_done
@echo "-----------------------------------------------------------------------"
@echo "-- $$(echo $@ | sed -e 's,^[.],,' -e 's,_done,,')..."
make do-install-$$(echo $@ | sed -e 's,^[.],,' -e 's,.install_done,,')
@echo "-- $$(echo $@ | sed -e 's,^[.],,' -e 's,_done,,') done."
touch $@
.PRECIOUS: .%.build_done
.%.build_done: .%.configure_done
@echo "-----------------------------------------------------------------------"
@echo "-- $$(echo $@ | sed -e 's,^[.],,' -e 's,_done,,')..."
make do-build-$$(echo $@ | sed -e 's,^[.],,' -e 's,.build_done,,')
@echo "-- $$(echo $@ | sed -e 's,^[.],,' -e 's,_done,,') done."
touch $@
.PRECIOUS: .%.configure_done
.%.configure_done: .%.checkout_done
@echo "-----------------------------------------------------------------------"
@echo "-- $$(echo $@ | sed -e 's,^[.],,' -e 's,_done,,')..."
make do-conf-$$(echo $@ | sed -e 's,^[.],,' -e 's,.configure_done,,')
@echo "-- $$(echo $@ | sed -e 's,^[.],,' -e 's,_done,,') done."
touch $@
.PRECIOUS: .%.checkout_done
.%.checkout_done:
@echo "-----------------------------------------------------------------------"
@echo "-- $$(echo $@ | sed -e 's,^[.],,' -e 's,_done,,')..."
make do-checkout-$$(echo $@ | sed -e 's,^[.],,' -e 's,.checkout_done,,')
@echo "-- $$(echo $@ | sed -e 's,^[.],,' -e 's,_done,,') done."
touch $@