-
Notifications
You must be signed in to change notification settings - Fork 46
/
configure
executable file
·343 lines (275 loc) · 10.1 KB
/
configure
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
#!/bin/bash
## MCMCLib config script
function print_help
{
echo "" ;
echo -e "\x1B[32mMCMCLib Configuration\033[0m" >&2 ;
echo "";
echo -e "Main options:" >&2 ;
echo " -c Code coverage build" ;
echo " (default: disabled)" ;
echo " -d Developmental build" ;
echo " (default: disabled)" ;
echo " -f Floating-point number type" ;
echo " (default: double)" ;
echo " -g Debugging build (optimization flags set to -O0 -g)" ;
echo " (default: disabled)" ;
echo " -h Print help" ;
echo " -i Install path (default: current directory)" ;
echo " Example: /usr/local" ;
echo " -l Choice of linear algebra library" ;
echo " Examples: -l arma or -l eigen" ;
echo " -m Specify the BLAS and Lapack libraries to link against" ;
echo " Examples: -m \"-lopenblas\" or -m \"-framework Accelerate\"" ;
echo " -o Compiler optimization options" ;
echo " (default: -O3 -march=native -ffp-contract=fast -flto -DARMA_NO_DEBUG)" ;
echo " -p Enable OpenMP parallelization features" ;
echo " (default: disabled)" ;
echo "" ;
echo "Special options:" ;
echo " --header-only-version Generate a header-only version of MCMCLib" ;
echo "" ;
}
while getopts hcdgf:i:l:m:o:pr:-: option; do
case "${option}" in
-)
case "${OPTARG}" in
header-only-version)
MCMC_GEN_NEW_HEADERS="y";;
?) print_help; exit 2;;
esac;;
h) print_help; exit 2;;
c) MCMC_COVERAGE_BUILD="y";;
d) MCMC_DEV_BUILD="y";;
f) MCMC_FPN_TYPE=${OPTARG};;
g) MCMC_DEBUG_BUILD="y";;
i) MCMC_INSTALL_PATH=${OPTARG};;
l) MCMC_LINEAR_ALG_LIB=${OPTARG};;
m) MCMC_MATRIX_OPS=${OPTARG};;
o) MCMC_OPT=${OPTARG};;
p) MCMC_PARALLEL="y";;
r) MCMC_R_BUILD=${OPTARG};;
?) print_help; exit 2;;
esac
done
if [ -z ${CXX+x} ]; then
CXX=g++
fi
# get working directory
WDIR=${PWD}
# compiler and system checks
ARCH=$(uname -m)
IS_ARM=$(echo $ARCH | grep -i -c "arm")
IS_DARWIN=$($CXX -dumpmachine 2>&1 | grep -i -c "darwin")
GCC_COMPILER=$($CXX --version 2>&1 | grep -i -c -E "gcc")
CLANG_COMPILER=$($CXX --version 2>&1 | grep -i -c -E "clang")
APPLE_COMPILER=$($CXX --version 2>&1 | grep -i -c -E 'apple llvm')
# generate header-only version of MCMCLib
if [[ "${MCMC_GEN_NEW_HEADERS}" == "y" ]]; then
rm -rf ./header_only_version
mkdir ./header_only_version
cp -rf ./include/* ./header_only_version/
#
declare -a DIRS=("mcmc")
for dir_ in "${DIRS[@]}"; do
cd "$WDIR"/header_only_version/"$dir_"
file_names=`ls *.hpp`
for file_ in $file_names; do
file_=${file_%.hpp}
#
if [[ "${file_}" == "mcmc_algos" ]]; then
continue
fi
if [ "$IS_DARWIN" -eq "1" ]; then # syntax for inplace replacement on macOS is a bit different
sed -i '' -e "s|#endif|//\n|" $file_.hpp
else
sed -i -e "s|#endif|//\n|" $file_.hpp
fi
sed -e '1,/\[MCMC_BEGIN\]/ d' $WDIR/src/"$file_".cpp | sed -e "s|mcmclib_inline|inline|" -e "s|mcmc::||" >> "$file_".hpp
echo -e "\n#endif" >> "$file_".hpp
done
done
exit 0
fi
#
echo ""
echo -e "\x1B[32mMCMCLib Configuration\033[0m" >&2 ;
echo ""
declare -a MCMC_MATLIB_DIRS=("${WDIR}/../../include" "/usr/include" "/usr/local/include" "/opt/include" "/opt/local/include")
# look for linear algebra library header files
if [[ "${MCMC_LINEAR_ALG_LIB}" == "arma" ]]; then
if [ -z ${ARMA_INCLUDE_PATH+x} ]; then
ARMA_INCLUDE_PATH=
for i in "${MCMC_MATLIB_DIRS[@]}"; do
if [ -f "$i"/armadillo ]; then
ARMA_INCLUDE_PATH="$i"
break
fi
done
if [[ $ARMA_INCLUDE_PATH == "" ]]; then
echo -e " \x1B[31m- error: cannot find the Armadillo library header files.\033[0m" >&2 ;
echo -e " \x1B[31m Please set the ARMA_INCLUDE_PATH environment variable.\033[0m" >&2 ;
echo -e " \x1B[31m Exiting.\033[0m" >&2 ;
echo ""
exit 1
fi
fi
MCMC_CXX_STD="-std=c++11"
MCMC_MATLIB_FLAGS="-DMCMC_ENABLE_ARMA_WRAPPERS -DARMA_NO_DEBUG"
MCMC_MATLIB_INCLUDE_PATH=$ARMA_INCLUDE_PATH
elif [[ "${MCMC_LINEAR_ALG_LIB}" == "blaze" ]]; then
# MCMC_CXX_STD="-std=c++14"
# MCMC_MATLIB_FLAGS="-DMCMC_ENABLE_BLAZE_WRAPPERS"
# MCMC_MATLIB_INCLUDE_PATH=$BLAZE_INCLUDE_PATH
echo -e " \x1B[31m- error: Blaze not yet supported. Exiting.\033[0m" >&2 ;
echo ""
exit 1
elif [[ "${MCMC_LINEAR_ALG_LIB}" == "eigen" ]]; then
if [ -z ${EIGEN_INCLUDE_PATH+x} ]; then
EIGEN_INCLUDE_PATH=
for i in "${MCMC_MATLIB_DIRS[@]}"; do
if [ -f "$i"/Eigen ]; then
EIGEN_INCLUDE_PATH="$i"
break
fi
done
if [[ $EIGEN_INCLUDE_PATH == "" ]]; then
echo -e " \x1B[31m- error: cannot find the Eigen library header files.\033[0m" >&2 ;
echo -e " \x1B[31m Please set the EIGEN_INCLUDE_PATH environment variable.\033[0m" >&2 ;
echo -e " \x1B[31m Exiting.\033[0m" >&2 ;
echo ""
exit 1
fi
fi
MCMC_CXX_STD="-std=c++14"
MCMC_MATLIB_FLAGS="-DMCMC_ENABLE_EIGEN_WRAPPERS"
MCMC_MATLIB_INCLUDE_PATH=$EIGEN_INCLUDE_PATH
else
echo -e " \x1B[31m- error: unrecognized linear algebra library.\033[0m" >&2 ;
echo ""
exit 1
fi
# set build and optimization flags
if [[ "${MCMC_COVERAGE_BUILD}" == "y" ]]; then
if [ "$GCC_COMPILER" -eq "1" ]; then
MCMC_OPT_FLAGS="-g -O0 --coverage -fno-inline -fno-inline-small-functions -fno-default-inline"
else # clang:
MCMC_OPT_FLAGS="-g -O0 --coverage -fno-inline"
fi
elif [[ "${MCMC_DEBUG_BUILD}" == "y" ]]; then
MCMC_OPT_FLAGS="-O0 -g"
else
if [[ "${MCMC_OPT}" == "" ]]; then
MCMC_OPT_FLAGS="-O3 -ffp-contract=fast -flto -DNDEBUG"
if [ "$IS_ARM" -eq "1" ]; then
MCMC_OPT_FLAGS="-mcpu=native ${MCMC_OPT_FLAGS}"
else
# assumes x86
MCMC_OPT_FLAGS="-march=native ${MCMC_OPT_FLAGS}"
fi
else
MCMC_OPT_FLAGS="${MCMC_OPT}"
fi
if [[ "${MCMC_R_BUILD}" != "" ]]; then
MCMC_OPT_FLAGS="${MCMC_OPT_FLAGS} -DUSE_RCPP_ARMADILLO"
fi
if [[ "${MCMC_PARALLEL}" == "y" ]]; then
MCMC_OPT_FLAGS="${MCMC_OPT_FLAGS} -fopenmp"
fi
fi
MCMC_WARN_FLAGS="-Wall"
# floating-point number type
if [[ "${MCMC_FPN_TYPE}" == "" ]]; then
MCMC_FPN_TYPE="double"
fi
# shared library name and install path
MCMC_SHLIB_NAME="libmcmc.so"
if [[ "${MCMC_INSTALL_PATH}" == "" ]]; then
MCMC_INSTALL_PATH="${WDIR}"
MCMC_INSTALL_LIB_PATH="${WDIR}"
else
MCMC_INSTALL_LIB_PATH="${MCMC_INSTALL_PATH}/lib"
fi
if [[ $OSTYPE == darwin* ]] ; then
MCMC_SHLIB_FLAGS="-dynamiclib -install_name ${MCMC_INSTALL_LIB_PATH}/${MCMC_SHLIB_NAME} -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress"
MCMC_BLAS_LAPACK="-framework Accelerate"
elif [[ $OSTYPE == *linux* ]] ; then
MCMC_OPT_FLAGS="-fPIC ${MCMC_OPT_FLAGS}"
MCMC_SHLIB_FLAGS="-fPIC -shared -L${MCMC_INSTALL_LIB_PATH} -Wl,-Bsymbolic-functions -Wl,-z,relro"
MCMC_BLAS_LAPACK="-lblas -llapack"
else
MCMC_BLAS_LAPACK="-lblas -llapack"
fi
if [[ !(-z ${MCMC_MATRIX_OPS+x}) ]]; then
MCMC_BLAS_LAPACK="${MCMC_MATRIX_OPS}"
fi
if [ "$IS_DARWIN" -eq "1" ] && [ "$GCC_COMPILER" -eq "1" ]; then
MCMC_OPT_FLAGS="-Wa,-q ${MCMC_OPT_FLAGS}"
fi
# final optimization checks
if [[ "${MCMC_COVERAGE_BUILD}" == "y" ]]; then
MCMC_SHLIB_FLAGS="--coverage ${MCMC_SHLIB_FLAGS}"
else
MCMC_SHLIB_FLAGS="${MCMC_OPT_FLAGS} ${MCMC_SHLIB_FLAGS}"
fi
#
# final print:
echo "Summary:"
echo " - OS: ${OSTYPE}"
echo " - Arch: ${ARCH}"
echo " - C++ compiler: ${CXX}"
if [[ "${MCMC_DEV_BUILD}" == "y" ]]; then
echo " - Build version: development"
elif [[ "${MCMC_COVERAGE_BUILD}" == "y" ]]; then
echo " - Build version: coverage"
elif [[ "${MCMC_DEBUG_BUILD}" == "y" ]]; then
echo " - Build version: debug"
elif [[ "${MCMC_R_BUILD}" != "" ]]; then
echo " - Build version: RcppArmadillo"
else
echo " - Build version: release"
fi
echo ""
echo " - MCMC_LINEAR_ALG_LIB set to: ${MCMC_LINEAR_ALG_LIB}"
echo " - MCMC_MATLIB_INCLUDE_PATH set to:"
echo " ${MCMC_MATLIB_INCLUDE_PATH}"
echo " - BLAS and Lapack libraries set to:"
echo " ${MCMC_BLAS_LAPACK}"
echo ""
if [[ "${MCMC_PARALLEL}" == "y" ]]; then
echo -e " - OpenMP features: \x1B[32menabled\033[0m" >&2 ;
else
echo -e " - OpenMP features: \x1B[31mdisabled\033[0m" >&2 ;
fi
echo " - floating-point number type: ${MCMC_FPN_TYPE}"
echo " - optimization flags:"
echo " ${MCMC_OPT_FLAGS}"
echo ""
echo " - MCMCLib install path:"
echo " ${MCMC_INSTALL_PATH}"
echo ""
echo " - Additional notes:"
if [ "$APPLE_COMPILER" -eq "1" ] && [[ "${MCMC_PARALLEL}" == "y" ]]; then
echo -e " \x1B[31m- You have enabled OpenMP, but your C++ compiler does not\033[0m" >&2 ;
echo -e " \x1B[31m support this feature!\033[0m" >&2 ;
fi
if [ "$IS_DARWIN" -eq "1" ] && [ "$GCC_COMPILER" -eq "1" ]; then
echo " - To enable AVX features, your compiler will use the Apple LLVM"
echo " assembler"
fi
echo ""
echo -e "\x1B[32mConfiguration completed. Creating Makefile... \c\033[0m" >&2 ;
sed -e "s|@CXX@|${CXX}|" \
-e "s|@MCMC_CXX_STD@|${MCMC_CXX_STD}|" \
-e "s|@MCMC_MATLIB_FLAGS@|${MCMC_MATLIB_FLAGS}|" \
-e "s|@MCMC_MATLIB_INCLUDE_PATH@|${MCMC_MATLIB_INCLUDE_PATH}|" \
-e "s|@MCMC_BLAS_LAPACK@|${MCMC_BLAS_LAPACK}|" \
-e "s|@MCMC_WARN_FLAGS@|${MCMC_WARN_FLAGS}|" \
-e "s|@MCMC_OPT_FLAGS@|${MCMC_OPT_FLAGS}|" \
-e "s|@MCMC_FPN_TYPE@|${MCMC_FPN_TYPE}|" \
-e "s|@MCMC_SHLIB_NAME@|${MCMC_SHLIB_NAME}|" \
-e "s|@MCMC_SHLIB_FLAGS@|${MCMC_SHLIB_FLAGS}|" \
-e "s|@MCMC_INSTALL_PATH@|${MCMC_INSTALL_PATH}|" \
Makefile.in > Makefile
echo -e "\x1B[32mdone.\033[0m" >&2 ;
echo ""