-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathbuild.sh
executable file
·347 lines (318 loc) · 11.4 KB
/
build.sh
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
#!/bin/bash
set -u
TOP_DIR="$(dirname "$0")"
TOP_DIR="$(readlink --canonicalize-existing ${TOP_DIR} 2> /dev/null)"
if (( $? != 0 )); then
# Fall back to bash function `pwd`. Note that this fallback
# depends on using bash.
TOP_DIR=$(pwd -P $TOP_DIR)
fi
: ${BUILD_DIR:=${TOP_DIR}/build}
: ${INSTALL_DIR:=${TOP_DIR}/install}
: ${PARALLEL_TEST_JOBS:=1}
: ${TESTING_EXTRA_ARGS:=}
: ${VERBOSE_MAKEFILE:=no}
LOG_FILE="${TOP_DIR}/build.log"
help() {
cat <<EOF
Usage:
This script can be used to build and test the bml library. The script has to
be given a command. Known commands are:
cleanup - Clean up and remove build and install directories
create - Create the build and install directories
configure - Configure the build system
compile - Compile the sources
install - Install the compiled sources
testing - Run the test suite
docs - Generate the API documentation
indent - Indent the sources
check_indent - Check the indentation of the sources
tags - Create tags file for vim and emacs
dist - Generate a tar file (this only works with git)
The following environment variables can be set to influence the configuration
step and the build:
EOF
set_defaults
echo "CMAKE_BUILD_TYPE {Release,Debug} (default is ${CMAKE_BUILD_TYPE})"
echo "BUILD_SHARED_LIBS Build a shared library (default is ${BUILD_SHARED_LIBS})"
echo "CC Path to C compiler (default is ${CC})"
echo "CXX Path to C++ compiler (default is ${CXX})"
echo "FC Path to Fortran compiler (default is ${FC})"
echo "BML_OPENMP {yes,no} (default is ${BML_OPENMP})"
echo "BML_MPI {yes,no} (default is ${BML_MPI})"
echo "BML_COMPLEX {yes,no} (default is ${BML_COMPLEX})"
echo "BML_TESTING {yes,no} (default is ${BML_TESTING})"
echo "BML_VALGRIND {yes,no} (default is ${BML_VALGRIND})"
echo "BML_COVERAGE {yes,no} (default is ${BML_COVERAGE})"
echo "BUILD_DIR Path to build dir (default is ${BUILD_DIR})"
echo "BLAS_VENDOR {,Intel,MKL,ACML,GNU,IBM,Auto} (default is '${BLAS_VENDOR}')"
echo "BML_INTERNAL_BLAS {yes,no} (default is ${BML_INTERNAL_BLAS})"
echo "PARALLEL_TEST_JOBS The number of test jobs (default is ${PARALLEL_TEST_JOBS})"
echo "INSTALL_DIR Path to install dir (default is ${INSTALL_DIR})"
echo "CMAKE_C_FLAGS Set C compiler flags (default is '${CMAKE_C_FLAGS}')"
echo "CMAKE_CXX_FLAGS Set C++ compiler flags (default is '${CMAKE_CXX_FLAGS}')"
echo "CMAKE_Fortran_FLAGS Set Fortran compiler flags (default is '${CMAKE_Fortran_FLAGS}')"
echo "BLAS_LIBRARIES Blas libraries (default is '${BLAS_LIBRARIES}')"
echo "LAPACK LIBRARIES Lapack libraries (default is '${LAPACK_LIBRARIES}')"
echo "EXTRA_CFLAGS Extra C flags (default is '${EXTRA_CFLAGS}')"
echo "EXTRA_FFLAGS Extra fortran flags (default is '${EXTRA_FFLAGS}')"
echo "EXTRA_LINK_FLAGS Add extra link flags (default is '${EXTRA_LINK_FLAGS}')"
echo "BML_OMP_OFFLOAD {yes,no} (default is ${BML_OMP_OFFLOAD})"
echo "GPU_ARCH GPU architecture (default is ${GPU_ARCH})"
echo "BML_CUDA Build with CUDA (default is ${BML_CUDA})"
echo "BML_MAGMA Build with MAGMA (default is ${BML_MAGMA})"
echo "BML_CUSOLVER Build with cuSOLVER (default is ${BML_CUSOLVER})"
echo "BML_XSMM Build with XSMM (default is ${BML_XSMM})"
echo "BML_ELLBLOCK_MEMPOOL Use ellblock memory pool (default is ${BML_ELLBLOCK_MEMPOOL}"
echo "CUDA_TOOLKIT_ROOT_DIR Path to CUDA dir (default is ${CUDA_TOOLKIT_ROOT_DIR})"
echo "INTEL_OPT {yes, no} (default is ${INTEL_OPT})"
}
set_defaults() {
: ${CMAKE_BUILD_TYPE:=Release}
: ${BUILD_SHARED_LIBS:=no}
: ${CC:=gcc}
: ${CXX:=g++}
: ${FC:=gfortran}
: ${BML_OPENMP:=yes}
: ${BML_MPI:=no}
: ${BML_COMPLEX:=yes}
: ${BLAS_VENDOR:=}
: ${BML_INTERNAL_BLAS:=no}
: ${EXTRA_CFLAGS:=}
: ${EXTRA_FFLAGS:=}
: ${CMAKE_C_FLAGS:=}
: ${CMAKE_CXX_FLAGS:=}
: ${CMAKE_Fortran_FLAGS:=}
: ${BLAS_LIBRARIES:=}
: ${LAPACK_LIBRARIES:=}
: ${BML_TESTING:=yes}
: ${BML_VALGRIND:=no}
: ${BML_COVERAGE:=no}
: ${FORTRAN_FLAGS:=}
: ${EXTRA_LINK_FLAGS:=}
: ${BML_OMP_OFFLOAD:=no}
: ${GPU_ARCH:=}
: ${BML_CUDA:=no}
: ${BML_MAGMA:=no}
: ${BML_CUSOLVER:=no}
: ${BML_XSMM:=no}
: ${BML_ELLBLOCK_MEMPOOL:=yes}
: ${CUDA_TOOLKIT_ROOT_DIR:=}
: ${INTEL_OPT:=no}
}
die() {
echo "fatal error"
if [[ -f "${BUILD_DIR}/CMakeFiles/CMakeOutput.log" ]]; then
echo "appending CMake output"
echo "*********** CMake Output ***********" >> ${LOG_FILE}
cat "${BUILD_DIR}/CMakeFiles/CMakeOutput.log" >> ${LOG_FILE}
fi
if [[ -f "${BUILD_DIR}/CMakeFiles/CMakeError.log" ]]; then
echo "appending CMake error"
echo "*********** CMake Error ***********" >> ${LOG_FILE}
cat "${BUILD_DIR}/CMakeFiles/CMakeError.log" >> ${LOG_FILE}
fi
echo "the output from this build was written to ${LOG_FILE}"
if [[ $# -gt 1 ]]; then
exit $1
else
exit 1
fi
}
check_pipe_error() {
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
die ${PIPESTATUS[0]}
fi
}
cleanup() {
rm -vrf "${BUILD_DIR}" || die
rm -vrf "${INSTALL_DIR}" || die
}
create() {
mkdir -v -p "${BUILD_DIR}" || die
mkdir -v -p "${INSTALL_DIR}" || die
}
configure() {
cd "${BUILD_DIR}"
if [[ -f "${BUILD_DIR}/CMakeCache.txt" ]]; then
rm -v "${BUILD_DIR}/CMakeCache.txt" || die
fi
${CMAKE:=cmake} .. \
-DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \
-DCMAKE_C_COMPILER="${CC}" \
-DCMAKE_CXX_COMPILER="${CXX}" \
-DCMAKE_Fortran_COMPILER="${FC}" \
${CMAKE_C_FLAGS:+-DCMAKE_C_FLAGS="${CMAKE_C_FLAGS}"} \
${CMAKE_CXX_FLAGS:+-DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS}"} \
${CMAKE_Fortran_FLAGS:+-DCMAKE_Fortran_FLAGS="${CMAKE_Fortran_FLAGS}"} \
-DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
-DBLAS_LIBRARIES="${BLAS_LIBRARIES}" \
-DLAPACK_LIBRARIES="${LAPACK_LIBRARIES}" \
-DBML_OPENMP="${BML_OPENMP}" \
-DBML_MPI="${BML_MPI}" \
-DBML_COMPLEX="${BML_COMPLEX}" \
-DBUILD_SHARED_LIBS="${BUILD_SHARED_LIBS}" \
-DBML_TESTING="${BML_TESTING:=yes}" \
-DBML_VALGRIND="${BML_VALGRIND:=no}" \
-DBML_COVERAGE="${BML_COVERAGE:=no}" \
-DBLAS_VENDOR="${BLAS_VENDOR}" \
-DBML_INTERNAL_BLAS="${BML_INTERNAL_BLAS}" \
${EXTRA_CFLAGS:+-DEXTRA_CFLAGS="${EXTRA_CFLAGS}"} \
${EXTRA_FFLAGS:+-DEXTRA_FFLAGS="${EXTRA_FFLAGS}"} \
${EXTRA_LINK_FLAGS:+-DBML_LINK_FLAGS="${EXTRA_LINK_FLAGS}"} \
-DCMAKE_VERBOSE_MAKEFILE=${VERBOSE_MAKEFILE} \
-DBML_OMP_OFFLOAD="${BML_OMP_OFFLOAD}" \
-DGPU_ARCH="${GPU_ARCH}" \
-DBML_CUDA="${BML_CUDA}" \
-DBML_MAGMA="${BML_MAGMA}" \
-DBML_CUSOLVER="${BML_CUSOLVER}" \
-DBML_XSMM="${BML_XSMM}" \
-DBML_ELLBLOCK_MEMPOOL="${BML_ELLBLOCK_MEMPOOL}" \
-DCUDA_TOOLKIT_ROOT_DIR="${CUDA_TOOLKIT_ROOT_DIR}" \
-DINTEL_OPT="${INTEL_OPT:=no}" \
| tee --append "${LOG_FILE}"
check_pipe_error
cd "${TOP_DIR}"
}
compile() {
make -C "${BUILD_DIR}" | tee --append "${LOG_FILE}"
check_pipe_error
}
docs() {
make -C "${BUILD_DIR}" docs 2>&1 | tee --append "${LOG_FILE}"
check_pipe_error
#make -C "${BUILD_DIR}/doc/latex" 2>&1 | tee -a "${LOG_FILE}"
#check_pipe_error
#if test -f "${BUILD_DIR}/doc/latex/refman.pdf"; then
#cp -v "${BUILD_DIR}/doc/latex/refman.pdf" "${TOP_DIR}/bml-manual.pdf"
#fi
}
install() {
make -C "${BUILD_DIR}" install 2>&1 | tee --append "${LOG_FILE}"
check_pipe_error
}
testing() {
cd "${BUILD_DIR}"
ctest --output-on-failure \
--parallel ${PARALLEL_TEST_JOBS} \
${TESTING_EXTRA_ARGS} \
2>&1 | tee --append "${LOG_FILE}"
check_pipe_error
# Get skipped tests and re-run them with verbose output.
local SKIPPED_TESTS
readarray -t SKIPPED_TESTS < <(sed -E '0,/The following tests did not run:.*$/d; s/^\s*[0-9]+\s-\s([^ ]+) .*/\1/' "${LOG_FILE}")
if (( ${#SKIPPED_TESTS[@]} > 0 )); then
echo "Found skipped tests: ${SKIPPED_TESTS[*]}"
local skipped
for skipped in "${SKIPPED_TESTS[@]}"; do
echo "Re-running skipped test ${skipped}"
ctest --verbose \
${TESTING_EXTRA_ARGS} \
--tests-regex "${skipped}" \
2>&1 | tee --append "${LOG_FILE}"
done
fi
cd "${TOP_DIR}"
}
indent() {
cd "${BUILD_DIR}"
"${TOP_DIR}/indent.sh" 2>&1 | tee --append "${LOG_FILE}"
check_pipe_error
}
check_indent() {
cd "${TOP_DIR}"
"${TOP_DIR}/indent.sh" 2>&1 | tee --append "${LOG_FILE}"
check_pipe_error
git diff 2>&1 | tee --append "${LOG_FILE}"
check_pipe_error
LINES=$(git diff | wc -l)
if test ${LINES} -gt 0; then
echo "sources were not formatted correctly"
die
fi
}
tags() {
"${TOP_DIR}/update_tags.sh" 2>&1 | tee --append "${LOG_FILE}"
check_pipe_error
}
dist() {
make -C "${BUILD_DIR}" dist 2>&1 | tee --append "${LOG_FILE}"
check_pipe_error
}
echo "Writing output to ${LOG_FILE}"
set_defaults
if [[ $# -gt 0 ]]; then
if [[ $1 = "-h" || $1 = "--help" ]]; then
help
shift
fi
if [[ $1 = "--debug" ]]; then
PS4='+(${BASH_SOURCE##*/}:${LINENO}) ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
set -x
shift
fi
while [[ $# -gt 0 ]]; do
echo "Running command $1"
case "$1" in
"cleanup")
cleanup
;;
"create")
create
;;
"configure")
create
configure
;;
"compile")
create
configure
compile
;;
"install")
create
configure
install
;;
"testing")
if [[ ${BML_TESTING} != "yes" ]]; then
echo "The testing step requires BML_TESTING to be true"
exit 1
fi
create
configure
compile
testing
;;
"docs")
create
configure
docs
;;
"indent")
indent
;;
"check_indent")
create
check_indent
;;
"tags")
tags
;;
"dist")
create
configure
dist
;;
*)
echo "unknown command $1"
exit 1
;;
esac
shift
done
else
echo "missing action"
help
fi
echo "The output was written to ${LOG_FILE}"