-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathconfigure
executable file
·221 lines (176 loc) · 6.02 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
#!/bin/bash
## BM++ config script
function print_help
{
echo "" ;
echo -e "\x1B[32mBM++ Configuration Options:\033[0m" >&2 ;
echo "-c Coverage build" ;
echo "-d Development build" ;
echo "-g Debugging build (optimization flags set to -O0 -g)" ;
echo "-h Print help" ;
echo "-i Install path (default: current directory)" ;
echo " Example: /usr/local" ;
echo "-m Specify the BLAS and Lapack libraries to link against" ;
echo " Examples: -m \"-lopenblas\" or -m \"-framework Accelerate\"" ;
echo "-o Compiler optimization options; defaults to:" ;
echo " -O3 -march=native -ffp-contract=fast -flto -DARMA_NO_DEBUG" ;
echo "-p Enable OpenMP parallelization features" ;
echo "" ;
}
while getopts hcdgi:m:o:p option; do
case "${option}" in
h) print_help; exit 2;;
c) BM_COVERAGE_BUILD="y";;
d) BM_DEV_BUILD="y";;
g) BM_DEBUG_BUILD="y";;
i) BM_INSTALL_PATH=${OPTARG};;
m) BM_MATRIX_OPS=${OPTARG};;
o) BM_OPT=${OPTARG};;
p) BM_PARALLEL="y";;
?) print_help; exit 2;;
esac
done
if [ -z ${CC+x} ]; then
CC=gcc
fi
if [ -z ${CXX+x} ]; then
CXX=g++
fi
if [ -z ${FC+x} ]; then
FC=gfortran
fi
#
echo ""
echo -e "\x1B[32mBM++ Configuration...\033[0m" >&2 ;
echo ""
# compiler checks
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')
# get working directory
WDIR=${PWD}
# look for Armadillo
if [ -z ${ARMA_INCLUDE_PATH+x} ]; then
declare -a ARMA_DIRS=("${WDIR}/include" "/usr/include" "/usr/local/include" "/opt/include" "/opt/local/include")
ARMA_INCLUDE_PATH=
for i in "${ARMA_DIRS[@]}"; do
if [ -f "$i"/armadillo ]; then
ARMA_INCLUDE_PATH="$i"
break
fi
done
if [[ $ARMA_INCLUDE_PATH == "" ]]; then
echo -e "\x1B[31m - note: cannot find Armadillo files. Cloning from GitLab\033[0m" >&2 ;
echo ""
mkdir ${WDIR}/arma_tmp
git clone -b unstable --single-branch https://gitlab.com/conradsnicta/armadillo-code.git ${WDIR}/arma_tmp > /dev/null 2>&1
mv ${WDIR}/arma_tmp/include/* ${WDIR}/include
rm -rf ${WDIR}/arma_tmp
ARMA_INCLUDE_PATH="./include"
fi
fi
# set build and optimization flags
if [[ "${BM_COVERAGE_BUILD}" == "y" ]]; then
if [ "$GCC_COMPILER" -eq "1" ]; then
BM_OPT_FLAGS="-g -O0 --coverage -fno-inline -fno-inline-small-functions -fno-default-inline"
else # clang:
BM_OPT_FLAGS="-g -O0 --coverage -fno-inline"
fi
elif [[ "${BM_DEBUG_BUILD}" == "y" ]]; then
BM_OPT_FLAGS="-O0 -g"
else
if [[ "${BM_OPT}" == "" ]]; then
BM_OPT_FLAGS="-O3 -march=native -ffp-contract=fast -flto -DNDEBUG -DARMA_NO_DEBUG"
else
BM_OPT_FLAGS="${BM_OPT}"
fi
if [[ "${BM_PARALLEL}" == "y" ]]; then
BM_OPT_FLAGS="${BM_OPT_FLAGS} -fopenmp"
fi
fi
BM_WARN_FLAGS="-Wall"
# shared library name and install path
BM_SHLIB_NAME="liboptim.so"
if [[ "${BM_INSTALL_PATH}" == "" ]]; then
BM_INSTALL_PATH="${WDIR}"
BM_INSTALL_LIB_PATH="${WDIR}"
else
BM_INSTALL_LIB_PATH="${BM_INSTALL_PATH}/lib"
fi
if [[ $OSTYPE == darwin* ]] ; then
BM_SHLIB_FLAGS="-dynamiclib -install_name ${BM_INSTALL_LIB_PATH}/${BM_SHLIB_NAME} -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress"
BM_BLAS_LAPACK="-framework Accelerate"
elif [[ $OSTYPE == *linux* ]] ; then
BM_OPT_FLAGS="-fPIC ${BM_OPT_FLAGS}"
BM_SHLIB_FLAGS="-fPIC -shared -L${BM_INSTALL_LIB_PATH} -Wl,-Bsymbolic-functions -Wl,-z,relro"
BM_BLAS_LAPACK="-lblas -llapack"
else
BM_BLAS_LAPACK="-lblas -llapack"
fi
if [[ !(-z ${BM_MATRIX_OPS+x}) ]]; then
BM_BLAS_LAPACK="${BM_MATRIX_OPS}"
fi
if [ "$IS_DARWIN" -eq "1" ] && [ "$GCC_COMPILER" -eq "1" ]; then
BM_OPT_FLAGS="-Wa,-q ${BM_OPT_FLAGS}"
fi
# final optimization checks
if [[ "${BM_COVERAGE_BUILD}" == "y" ]]; then
BM_SHLIB_FLAGS="--coverage ${BM_SHLIB_FLAGS}"
else
BM_SHLIB_FLAGS="${BM_OPT_FLAGS} ${BM_SHLIB_FLAGS}"
fi
#
# final print:
echo " - OS: ${OSTYPE}"
echo " - C++ compiler: ${CXX}"
if [[ "${BM_DEV_BUILD}" == "y" ]]; then
echo " - Build version: development"
elif [[ "${BM_COVERAGE_BUILD}" == "y" ]]; then
echo " - Build version: coverage"
elif [[ "${BM_DEBUG_BUILD}" == "y" ]]; then
echo " - Build version: debug"
else
echo " - Build version: release"
fi
echo ""
echo " - ARMA_INCLUDE_PATH set to:"
echo " ${ARMA_INCLUDE_PATH}"
echo " - BLAS and Lapack libraries set to:"
echo " ${BM_BLAS_LAPACK}"
echo ""
if [[ "${BM_PARALLEL}" == "y" ]]; then
echo -e " - OpenMP features: \x1B[32menabled\033[0m" >&2 ;
else
echo -e " - OpenMP features: \x1B[31mdisabled\033[0m" >&2 ;
fi
echo " - optimization flags:"
echo " ${BM_OPT_FLAGS}"
echo ""
echo " - BM++ install path:"
echo " ${BM_INSTALL_PATH}"
echo ""
echo " - Additional notes:"
if [ "$APPLE_COMPILER" -eq "1" ] && [[ "${BM_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|@CC@|${CC}|" \
-e "s|@CXX@|${CXX}|" \
-e "s|@FC@|${FC}|" \
-e "s|@ARMA_INCLUDE_PATH@|${ARMA_INCLUDE_PATH}|" \
-e "s|@BM_BLAS_LAPACK@|${BM_BLAS_LAPACK}|" \
-e "s|@BM_WARN_FLAGS@|${BM_WARN_FLAGS}|" \
-e "s|@BM_OPT_FLAGS@|${BM_OPT_FLAGS}|" \
-e "s|@BM_SHLIB_NAME@|${BM_SHLIB_NAME}|" \
-e "s|@BM_SHLIB_FLAGS@|${BM_SHLIB_FLAGS}|" \
-e "s|@BM_INSTALL_PATH@|${BM_INSTALL_PATH}|" \
Makefile.in > Makefile
echo -e "\x1B[32mdone.\033[0m" >&2 ;
echo ""