1 #!/bin/bash
3 # This configure script is hand-generated, not auto-generated.
4 # It creates the file kaldi.mk, which is %included by the Makefiles
5 # in the subdirectories.
6 # The file kaldi.mk is editable by hand -- for example, you may want to
7 # remove the options -g -O0 -DKALDI_PARANOID, or edit the
8 # DOUBLE_PRECISION variable (to be 1 not 0).
11 # Example command lines:
12 # ./configure --shared ## shared libraries.
13 # ./configure
14 # ./configure --mkl-root=/opt/intel/mkl
15 # ./configure --mkl-root=/opt/intel/mkl --threaded-math=yes
16 # ./configure --mkl-root=/opt/intel/mkl --threaded-math=yes --mkl-threading=tbb
17 # # This is for MKL 11.3, which does not seem to provide Intel OMP libs
18 # ./configure --openblas-root=../tools/OpenBLAS/install
19 # # Before doing this, cd to ../tools and type "make openblas".
20 # # Note: this is not working correctly on all platforms, do "make test"
21 # # and look out for segmentation faults.
22 # ./configure --atlas-root=../tools/ATLAS/build
23 # ./configure --use-cuda=no # disable CUDA detection (will build cpu-only
24 # # version of kaldi even on CUDA-enabled machine
25 # ./configure --static --fst-root=/opt/cross/armv8hf \
26 # --atlas-root=/opt/cross/armv8hf --host=armv8-rpi3-linux-gnueabihf
27 # # Cross compile for armv8hf, this assumes that you have openfst built
28 # # with the armv8-rpi3-linux-gnueabihf toolchain and installed to
29 # # /opt/cross/armv8hf. It also assumes that you have an ATLAS library
30 # # built for the target install to /opt/cross/armv8hf and that the
31 # # armv8-rpi3-linux-gnueabihf toolchain is available in your path
32 # ./configure --static --openblas-root=/opt/cross/arm-linux-androideabi \
33 # --fst-root=/opt/cross/arm-linux-androideabi --fst-version=1.4.1 \
34 # --android-incdir=/opt/cross/arm-linux-androideabi/sysroot/usr/include \
35 # --host=arm-linux-androideabi
36 # # Cross compile for Android on arm. The only difference here is the
37 # # addition of the the --android-includes flag because the toolchains
38 # # produced by the Android NDK don't always include the C++ stdlib
39 # # headers in the normal cross compile include path.
41 # This should be incremented after any significant change to the configure
42 # script, i.e. any change affecting kaldi.mk or the build system as a whole.
43 CONFIGURE_VERSION=6
45 if ! [ -x "$PWD/configure" ]; then
46 echo 'You must run "configure" from the src/ directory.'
47 exit 1
48 fi
50 function usage {
51 cat <<EOF
52 'configure' configures Kaldi installation.
54 Usage: [VAR=VALUE]... $0 [OPTION]...
56 The default configuration is to build and link against static Kaldi libraries.
57 OpenFst and Math libraries are linked dynamically.
59 Configuration options:
60 --help Display this help message and exit
61 --version Display the version of 'configure' and exit
62 --static Build and link against static libraries [default=no]
63 --shared Build and link against shared libraries [default=no]
64 --use-cuda Build with CUDA [default=yes]
65 --cudatk-dir=DIR CUDA toolkit directory
66 --double-precision Build with BaseFloat set to double if yes [default=no],
67 mostly useful for testing purposes.
68 --static-fst Build with static OpenFst libraries [default=no]
69 --fst-root=DIR OpenFst root directory [default=../tools/openfst/]
70 --fst-version=STR OpenFst version string
71 --mathlib=LIB Math library [default=ATLAS]
72 Supported libraries: ATLAS, MKL, CLAPACK, OPENBLAS.
73 --static-math Build with static math libraries [default=no]
74 --threaded-math Build with multi-threaded math libraries [default=no]
75 --threaded-atlas Build with multi-threaded ATLAS libraries [default=no]
76 --atlas-root=DIR ATLAS root directory [default=../tools/ATLAS/]
77 --openblas-root=DIR OpenBLAS root directory
78 --clapack-root=DIR CLAPACK root directory
79 --mkl-root=DIR MKL root directory
80 --mkl-libdir=DIR MKL library directory
81 --mkl-threading=LIB MKL threading layer [default=sequential]
82 Supported layers: sequential, iomp, tbb, gomp.
83 --omp-libdir=DIR OpenMP directory
84 --speex-root=DIR SPEEX root directory
85 --speex-libdir=DIR SPEEX library directory
86 --speex-incdir=DIR SPEEX include directory
87 --host=HOST Host triple in the format 'cpu-vendor-os'
88 If provided, it is prepended to all toolchain programs.
89 --android-incdir=DIR Andraid include directory
91 Following environment variables can be used to override the default toolchain.
92 CXX C++ compiler [default=g++]
93 AR Archive maintenance utility [default=ar]
94 AS Assembler [default=as]
95 RANLIB Archive indexing utility [default=ranlib]
97 If a host triple is provided, it is prepended to CXX, AR, AS and RANLIB.
99 Following environment variables can be used to provide additional flags to the
100 compiler/linker.
101 CXXFLAGS Additional C++ compiler flags, e.g. -I<include-dir>
102 LDFLAGS Additional linker flags, e.g. -L<lib-dir>
103 LDLIBS Additional libraries to pass to the linker, e.g. -l<lib>
105 EOF
106 }
108 function rel2abs {
109 if [ ! -z "$1" ]; then
110 local retval=`cd $1 2>/dev/null && pwd || exit 1`
111 echo $retval
112 fi
113 }
115 function read_dirname {
116 local dir_name=`expr "X$1" : '[^=]*=\(.*\)'`;
117 local retval=`rel2abs $dir_name`
118 [ -z $retval ] && echo "Bad option '$1': no such directory" && exit 1;
119 echo $retval
120 }
122 function is_set {
123 local myvar=${1:-notset}
124 if [ "$myvar" == "notset" ]; then
125 return 1
126 else
127 return 0
128 fi
129 }
131 function failure {
132 echo "***configure failed: $* ***" >&2
133 if [ -f kaldi.mk ]; then rm kaldi.mk; fi
134 exit 1;
135 }
137 function check_exists {
138 if [ ! -f $1 ]; then failure "$1 not found."; fi
139 }
141 function check_library {
142 local libpath=$1
143 local libname=$2
144 local libext=$3
145 local full_libname="$libpath/$libname.$libext"
146 ##echo "Testing $full_libname" >&2
147 test -f "$full_libname" && return ;
148 return 1
149 }
151 function check_compiler {
152 COMPILER=$1
153 if ! which $COMPILER >&/dev/null; then
154 failure "$COMPILER is not installed.
155 You need g++ >= 4.7, Apple clang >= 5.0 or LLVM clang >= 3.3."
156 else
157 COMPILER_VER_INFO=$($COMPILER --version 2>/dev/null)
158 if [[ $COMPILER_VER_INFO == *"g++"* ]]; then
159 GCC_VER=$($COMPILER -dumpversion)
160 GCC_VER_NUM=$(echo $GCC_VER | sed 's/\./ /g' | xargs printf "%d%02d%02d")
161 if [ $GCC_VER_NUM -lt 40700 ]; then
162 failure "$COMPILER (g++-$GCC_VER) is not supported.
163 You need g++ >= 4.7, Apple clang >= 5.0 or LLVM clang >= 3.3."
164 elif [ $GCC_VER_NUM == 40801 ] || [ $GCC_VER_NUM == 40802 ]; then
165 failure "$COMPILER (g++-$GCC_VER) is not supported.
166 GCC 4.8.1 and 4.8.2 have a bug in the implementation of
167 the nth_element algorithm provided by the standard library.
168 This will cause Kaldi to crash (make test would fail).
169 Please use another C++ compiler with C++11 support.
170 You need g++ >= 4.7, Apple clang >= 5.0 or LLVM clang >= 3.3."
171 fi
172 elif [[ $COMPILER_VER_INFO == *"Apple"* ]]; then
173 CLANG_VER=$(echo $COMPILER_VER_INFO | grep version | sed "s/.*version \([0-9\.]*\).*/\1/")
174 CLANG_VER_NUM=$(echo $COMPILER_VER_INFO | grep version | sed "s/.*clang-\([0-9]*\).*/\1/")
175 if [ $CLANG_VER_NUM -lt 500 ]; then
176 failure "$COMPILER (Apple clang-$CLANG_VER) is not supported.
177 You need g++ >= 4.7, Apple clang >= 5.0 or LLVM clang >= 3.3."
178 fi
179 elif [[ $COMPILER_VER_INFO == *"LLVM"* ]]; then
180 CLANG_VER=$(echo $COMPILER_VER_INFO | grep version | sed "s/.*version \([0-9\.]*\).*/\1/")
181 CLANG_VER_NUM=$(echo $CLANG_VER | sed 's/\./ /g' | xargs printf "%d%02d")
182 if [ $CLANG_VER_NUM -lt 303 ]; then
183 failure "$COMPILER (LLVM clang-$CLANG_VER) is not supported.
184 You need g++ >= 4.7, Apple clang >= 5.0 or LLVM clang >= 3.3."
185 fi
186 fi
187 fi
188 }
190 function check_for_slow_expf {
191 # We cannot run this test if we are cross compiling.
192 if [[ "$TARGET_ARCH" == "`uname -m`" ]] ; then
193 cd probe
194 rm -f exp-test
195 make -f Makefile.slow_expf 1>/dev/null
196 ./exp-test
197 if [ $? -eq 1 ]; then
198 echo "*** WARNING: expf() seems to be slower than exp() on your machine. This is a known bug in old versions of glibc. Please consider updating glibc. ***"
199 echo "*** Kaldi will be configured to use exp() instead of expf() in base/kaldi-math.h Exp() routine for single-precision floats. ***"
200 echo "CXXFLAGS += -DKALDI_NO_EXPF" >> ../kaldi.mk
201 fi
202 cd ..
203 fi
204 }
206 # MKL functions
207 function linux_configure_mkllibdir {
208 local mklroot=$1
210 if [ -d $mklroot/lib/em64t ]; then
211 echo $mklroot/lib/em64t
212 elif [ -d $mklroot/lib/intel64 ]; then
213 echo $mklroot/lib/intel64
214 else
215 return 1;
216 fi
217 }
219 function linux_configure_mkl_includes {
220 test -d $1/include && echo "$1/include" && return;
221 test -d $2/../../include && echo "$2/../../include" && return;
222 failure "Could not find the MKL include directory"
223 }
225 function linux_configure_mkl_libraries {
226 local mkllibdir=$1
227 local static=$2
228 local threaded=$3
229 local mplib=$4
231 declare -A mkl_libs
232 mkl_libs=(
233 [sequential]="mkl_intel_lp64 mkl_core mkl_sequential"
234 [gomp]="mkl_intel_lp64 mkl_core mkl_gnu_thread"
235 [iomp]="mkl_intel_lp64 mkl_core mkl_intel_thread "
236 [tbb]="mkl_intel_lp64 mkl_core mkl_tbb_thread "
237 )
239 if [ -z "${mkl_libs[$threaded]}" ]; then
240 echo >&2 "Unknown threading mode: $threaded"
241 return 1;
242 fi
244 local linkline=""
245 if ! $static ; then
246 linkline="-L$mkllibdir -Wl,-rpath=$mkllibdir"
247 for file in ${mkl_libs[$threaded]}; do
248 local libfile=$mkllibdir/lib$file.so
249 check_exists $libfile
250 linkline+=" -l$file "
251 done
252 else
253 if [ $threaded == "sequential" ] ; then
254 test -f "$mkllibdir/libmkl_solver_lp64.a" && \
255 linkline="$linkline $mkllibdir/libmkl_solver_lp64.a"
256 else
257 test -f "$mkllibdir/libmkl_solver_lp64_sequential.a" && \
258 linkline="$linkline $mkllibdir/libmkl_solver_lp64_sequential.a"
259 fi
260 linkline="$linkline -Wl,--start-group"
261 for file in ${mkl_libs[$threaded]}; do
262 local libfile=$mkllibdir/lib${file}.a
263 check_exists $libfile
264 linkline="$linkline $libfile"
265 done
266 linkline="$linkline -Wl,--end-group "
267 fi
268 echo "$linkline"
269 }
271 function linux_configure_mkl_extra {
272 local static=$1
273 local threaded=$2
275 declare -A extra_libs
276 extra_libs=(
277 [sequential]="-ldl -lpthread -lm"
278 [gomp]="-lgomp -ldl -lpthread -lm"
279 [iomp]="-ldl -lpthread -lm"
280 [tbb]=" -ldl -lpthread -lm "
281 )
282 echo "$linkline ${extra_libs[$threaded]}"
283 }
285 function linux_configure_threadinglibdir {
286 local library=$1
287 local mklroot=$2
288 local mkllibdir=$3
289 local libexts=$4
291 ##First we try to use the library in the same directory
292 ##where the mkl libraries reside
293 ##Afterwards, just try some possibilities for different MKL layouts
294 for libext in $libexts; do
295 check_library $mkllibdir "lib$library" $libext \
296 && echo `readlink -f $mkllibdir` && return 0
298 local testdir=`(cd $mklroot; cd ..; cd lib/intel64;pwd)`
299 test -d $testdir && check_library $testdir "lib$library" $libext && echo `readlink -f $testdir` && return 0;
300 local testdir=`(cd $mklroot; cd ..; cd lib/em64t;pwd)`
301 test -d $testdir && check_library $testdir "lib$library" $libext && echo `readlink -f $testdir` && return 0;
303 local testdir=`(cd $mkllibdir; cd ../../..; cd lib/intel64;pwd)`
304 test -d $testdir && check_library $testdir "lib$library" $libext && echo `readlink -f $testdir` && return 0;
305 local testdir=`(cd $mklroot; cd ../../..; cd lib/em64t;pwd)`
306 test -d $testdir && check_library $testdir "lib$library" $libext && echo `readlink -f $testdir` && return 0;
307 done
309 #failure "Could not find the library iomp5, use the configure switch --omp-libdir"
310 return 1
311 }
313 function linux_configure_mkl_threading {
314 local mklroot=$1
315 local mkllibdir=$2
316 local static=$3
317 local threading=$4
319 declare -A libs
320 libs=(
321 [sequential]=""
322 [gomp]=""
323 [iomp]="iomp5"
324 [tbb]="tbb"
325 )
327 echo >&2 "Configuring MKL threading as $threading"
328 library=${libs[$threading]}
329 if [ -z "$library" ]; then
330 return 0
331 fi
333 if ! is_set $OMPLIBDIR ; then
334 if $static ; then
335 OMPLIBDIR=`linux_configure_threadinglibdir $library "$MKLROOT" "$MKLLIBDIR" "a"`
336 else
337 OMPLIBDIR=`linux_configure_threadinglibdir $library "$MKLROOT" "$MKLLIBDIR" "so"`
338 fi
339 fi
341 check_library $OMPLIBDIR "lib$library" "a" || \
342 check_library $OMPLIBDIR "lib$library" "so" || \
343 failure "Could not find the $library library, have your tried the --omp-libdir switch?"
345 OMP_LINK_LINE=''
346 # TODO(arnab): in the following conditional, the $static_math test is
347 # needed since the OpenMP library is assumed to be dynamic.
348 if [ "$OMPLIBDIR" != "$MKLLIBDIR" ] ; then
349 OMP_LINK_LINE="-L${OMPLIBDIR}"
350 fi
351 #if the libiomp5 library is dynamic, we add the rpath attribute
352 if ! $static_math ; then
353 OMP_LINK_LINE="$OMP_LINK_LINE -Wl,-rpath=$OMPLIBDIR -l$library"
354 else
355 OMP_LINK_LINE="$OMP_LINK_LINE -Wl,-Bstatic -l$library -Wl,-Bdynamic"
356 fi
357 echo "$OMP_LINK_LINE"
358 }
361 # CUDA is used only in selected directories including src/cudamatrix, src/nnet*
362 # and src/chain*. It is used to accelerate the neural network training.
363 # The rest of Kaldi runs on CPUs.
365 function configure_cuda {
366 # Check for CUDA toolkit in the system
367 if [ ! -d "$CUDATKDIR" ]; then
368 for base in /Developer/NVIDIA/CUDA-6.0 /usr/local/share/cuda /usr/local/cuda /pkgs_local/cuda-3.2/ /opt/nvidia_cuda/cuda-6.0/ /usr/; do
369 if [ -f $base/bin/nvcc ]; then
370 CUDATKDIR=$base
371 fi
372 done
373 fi
375 if [ -d "$CUDATKDIR" ]; then
376 if [ ! -f $CUDATKDIR/bin/nvcc ]; then
377 failure "Cannnot find nvcc in CUDATKDIR=$CUDATKDIR"
378 fi
380 if [[ "$TARGET_ARCH" != "`uname -m`" ]] ; then
381 failure "Cannot cross compile with CUDA support"
382 fi
384 # Determine 'CUDA_ARCH',
385 CUDA_VERSION=$($CUDATKDIR/bin/nvcc -V | tr '.,' '_ ' | awk '/release/{sub(/.*release/,""); print $1;}') # MAJOR_MINOR,
386 if [ -z "$CUDA_VERSION" ] ; then
387 echo "Cannot figure out CUDA_VERSION from the nvcc output. Either your CUDA is too new or too old."
388 exit 1
389 fi
391 COMPILER_VER_INFO=$($CXX --version 2>/dev/null)
392 if [[ $COMPILER_VER_INFO == *"g++"* ]]; then
393 GCC_VER=$($COMPILER -dumpversion)
394 GCC_VER_NUM=$(echo $GCC_VER | sed 's/\./ /g' | xargs printf "%d%02d%02d")
395 case $CUDA_VERSION in
396 5_5)
397 MIN_UNSUPPORTED_GCC_VER="5.0"
398 MIN_UNSUPPORTED_GCC_VER_NUM=50000;
399 ;;
400 6_*)
401 MIN_UNSUPPORTED_GCC_VER="5.0"
402 MIN_UNSUPPORTED_GCC_VER_NUM=50000;
403 ;;
404 7_*)
405 MIN_UNSUPPORTED_GCC_VER="5.0"
406 MIN_UNSUPPORTED_GCC_VER_NUM=50000;
407 ;;
408 8_*)
409 MIN_UNSUPPORTED_GCC_VER="6.0"
410 MIN_UNSUPPORTED_GCC_VER_NUM=60000;
411 ;;
412 9_*)
413 MIN_UNSUPPORTED_GCC_VER="7.0"
414 MIN_UNSUPPORTED_GCC_VER_NUM=70000;
415 ;;
416 *)
417 echo "Unsupported CUDA_VERSION (CUDA_VERSION=$CUDA_VERSION), please report it to Kaldi mailing list, together with 'nvcc -h' or 'ptxas -h' which lists allowed -gencode values..."; exit 1;
418 ;;
419 esac
420 if [ $GCC_VER_NUM -ge $MIN_UNSUPPORTED_GCC_VER_NUM ]; then
421 failure "CUDA $CUDA_VERSION does not support $CXX (g++-$GCC_VER).
422 You need g++ < $MIN_UNSUPPORTED_GCC_VER."
423 fi
424 fi
426 case $CUDA_VERSION in
427 5_5) CUDA_ARCH="-gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35" ;;
428 6_*) CUDA_ARCH="-gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_50,code=sm_50" ;;
429 7_*) CUDA_ARCH="-gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_53,code=sm_53" ;;
430 8_*) CUDA_ARCH="-gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_53,code=sm_53 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_62,code=sm_62" ;;
431 9_*) CUDA_ARCH="-gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_53,code=sm_53 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_62,code=sm_62 -gencode arch=compute_70,code=sm_70" ;;
432 *) echo "Unsupported CUDA_VERSION (CUDA_VERSION=$CUDA_VERSION), please report it to Kaldi mailing list, together with 'nvcc -h' or 'ptxas -h' which lists allowed -gencode values..."; exit 1 ;;
433 esac
435 echo "Using CUDA toolkit $CUDATKDIR (nvcc compiler and runtime libraries)"
436 echo >> kaldi.mk
437 echo "# CUDA configuration" >> kaldi.mk
438 echo >> kaldi.mk
439 echo CUDA = true >> kaldi.mk
440 echo CUDATKDIR = $CUDATKDIR >> kaldi.mk
441 echo "CUDA_ARCH = $CUDA_ARCH" >> kaldi.mk
442 echo >> kaldi.mk
444 # 64bit/32bit? We do not support cross compilation with CUDA so, use direct calls to uname -m here
445 if [ "`uname -m`" == "x86_64" ]; then
446 if [ "`uname`" == "Darwin" ]; then
447 sed 's/lib64/lib/g' < makefiles/cuda_64bit.mk >> kaldi.mk
448 else
449 cat makefiles/cuda_64bit.mk >> kaldi.mk
450 fi
451 elif [ "`uname -m`" == "ppc64le" ]; then
452 cat makefiles/cuda_64bit.mk >> kaldi.mk
453 else
454 cat makefiles/cuda_32bit.mk >> kaldi.mk
455 fi
457 else
458 echo "CUDA will not be used! If you have already installed cuda drivers "
459 echo "and cuda toolkit, try using --cudatk-dir=... option. Note: this is"
460 echo "only relevant for neural net experiments"
461 fi
462 }
464 function linux_configure_speex {
465 # Check whether the user has called tools/extras/install_speex.sh or not
466 [ ! -z "$SPEEXROOT" ] || SPEEXROOT=`pwd`/../tools/speex
467 [ ! -z "$SPEEXLIBDIR" ] || SPEEXLIBDIR="$SPEEXROOT"/lib
468 [ ! -z "$SPEEXINCDIR" ] || SPEEXINCDIR="$SPEEXROOT"/include
469 static_speex=$1
470 if [ "foo"$static_speex == "foo" ]; then
471 static_speex=false
472 fi
474 if $static_speex; then
475 spx_type=a
476 else
477 spx_type=so
478 fi
479 if [ ! -f "$SPEEXLIBDIR/libspeex.${spx_type}" ];then
480 echo "Info: configuring Kaldi not to link with Speex (don't worry, it's only needed if you"
481 echo "intend to use 'compress-uncompress-speex', which is very unlikely)"
482 return
483 fi
485 if [ -f $SPEEXINCDIR/speex/speex.h ]; then
486 echo >> kaldi.mk
487 echo CXXFLAGS += -DHAVE_SPEEX -I${SPEEXINCDIR} >> kaldi.mk
489 if $static_speex; then
490 echo LDLIBS += $SPEEXLIBDIR/libspeex.a
491 else
492 echo LDLIBS += -L${SPEEXLIBDIR} -lspeex >> kaldi.mk
493 echo LDFLAGS += -Wl,-rpath=${SPEEXLIBDIR} >> kaldi.mk
494 fi
496 echo "Successfully configured with Speex at $SPEEXROOT, (static=[$static_speex])"
497 else
498 echo "Speex will not be used. If you want to use it, run tools/extras/install_speex.sh first."
499 fi
500 }
502 function linux_atlas_failure {
503 echo ATLASINC = $ATLASROOT/include >> kaldi.mk
504 echo ATLASLIBS = [somewhere]/liblapack.a [somewhere]/libcblas.a [somewhere]/libatlas.a [somewhere]/libf77blas.a $ATLASLIBDIR >> kaldi.mk
505 echo >> kaldi.mk
506 if [[ "$TARGET_ARCH" == arm* ]]; then
507 cat makefiles/linux_atlas_arm.mk >> kaldi.mk
508 elif [[ "$TARGET_ARCH" == ppc64le ]]; then
509 cat makefiles/linux_atlas_ppc64le.mk >> kaldi.mk
510 else
511 cat makefiles/linux_atlas.mk >> kaldi.mk
512 fi
513 echo "** $* ***"
514 echo "** ERROR **"
515 echo "** Configure cannot proceed automatically."
516 echo "** If you know that you have ATLAS installed somewhere on your machine, you"
517 echo "** may be able to proceed by replacing [somewhere] in kaldi.mk with a directory."
518 echo "** If you have sudo (root) access you could install the ATLAS package on your"
519 echo "** machine, e.g. 'sudo apt-get install libatlas-dev libatlas-base-dev' or"
520 echo "** 'sudo yum install atlas.x86_64' or 'sudo zypper install libatlas3-devel',"
521 echo "** or on cygwin, install atlas from the installer GUI; and then run ./configure"
522 echo "** again."
523 echo "**"
524 echo "** Otherwise (or if you prefer OpenBLAS for speed), you could go the OpenBLAS"
525 echo "** route: cd to ../tools, type 'extras/install_openblas.sh', cd back to here,"
526 echo "** and type './configure --openblas-root=../tools/OpenBLAS/install'"
527 exit 1;
528 }
530 function linux_check_static {
531 # will exit with success if $dir seems to contain ATLAS libraries with
532 # right architecture (compatible with default "nm")
533 echo "int main(void) { return 0; }" > test_linking.cc;
534 if [ -f $dir/libatlas.a ]; then # candidate...
535 # Note: on the next line, the variable assignment
536 # LANG=en_US should apply just to the program called on that line.
537 if LANG=en_US $CXX -o test_linking test_linking.cc -u ATL_flushcache $dir/libatlas.a 2>&1 | grep -i "incompatible" >/dev/null; then
538 echo "Directory $dir may contain ATLAS libraries but seems to be wrong architecture";
539 rm test_linking test_linking.cc 2>/dev/null
540 return 1;
541 fi
542 rm test_linking test_linking.cc 2>/dev/null
543 return 0;
544 else
545 rm test_linking.cc
546 return 1;
547 fi
548 }
550 function linux_configure_debian_ubuntu {
551 m=$1
552 ATLASLIBS="/usr/lib$m/atlas-base/libatlas.so.3gf /usr/lib$m/atlas-base/libf77blas.so.3gf /usr/lib$m/atlas-base/libcblas.so.3gf /usr/lib$m/atlas-base/liblapack_atlas.so.3gf"
553 for f in $ATLASLIBS; do
554 [ ! -f $f ] && return 1;
555 done
556 lapacklib=$(echo $ATLASLIBS | awk '{print $NF}')
557 if ! nm --dynamic $lapacklib | grep ATL_cgetrf >/dev/null; then
558 exit 1;
559 fi
560 echo ATLASINC = $ATLASROOT/include >> kaldi.mk
561 echo ATLASLIBS = $ATLASLIBS >> kaldi.mk
562 echo >> kaldi.mk
563 if [[ "$TARGET_ARCH" == arm* ]]; then
564 cat makefiles/linux_atlas_arm.mk >> kaldi.mk
565 elif [[ "$TARGET_ARCH" == ppc64le ]]; then
566 cat makefiles/linux_atlas_ppc64le.mk >> kaldi.mk
567 else
568 cat makefiles/linux_atlas.mk >> kaldi.mk
569 fi
570 echo "Successfully configured for Debian/Ubuntu Linux [dynamic libraries] with ATLASLIBS =$ATLASLIBS"
571 $use_cuda && configure_cuda
572 linux_configure_speex
573 }
575 function linux_configure_debian_ubuntu3 {
576 ATLASLIBS="/usr/lib/libatlas.so.3 /usr/lib/libf77blas.so.3 /usr/lib/libcblas.so.3 /usr/lib/liblapack_atlas.so.3"
577 for f in $ATLASLIBS; do
578 [ ! -f $f ] && return 1;
579 done
580 lapacklib=$(echo $ATLASLIBS | awk '{print $NF}')
581 if ! nm --dynamic $lapacklib | grep ATL_cgetrf >/dev/null; then
582 exit 1;
583 fi
584 echo ATLASINC = $ATLASROOT/include >> kaldi.mk
585 echo ATLASLIBS = $ATLASLIBS >> kaldi.mk
586 echo >> kaldi.mk
587 if [[ "$TARGET_ARCH" == arm* ]]; then
588 cat makefiles/linux_atlas_arm.mk >> kaldi.mk
589 elif [[ "$TARGET_ARCH" == ppc64le ]]; then
590 cat makefiles/linux_atlas_ppc64le.mk >> kaldi.mk
591 else
592 cat makefiles/linux_atlas.mk >> kaldi.mk
593 fi
594 echo "Successfully configured for Debian/Ubuntu Linux [dynamic libraries] with ATLASLIBS =$ATLASLIBS"
595 $use_cuda && configure_cuda
596 linux_configure_speex
597 }
599 function linux_configure_debian7 {
600 ATLASLIBS="/usr/lib/atlas-base/libatlas.so.3.0 /usr/lib/atlas-base/libf77blas.so.3.0 /usr/lib/atlas-base/libcblas.so.3 /usr/lib/atlas-base/liblapack_atlas.so.3"
601 for f in $ATLASLIBS; do
602 [ ! -f $f ] && return 1;
603 done
604 lapacklib=$(echo $ATLASLIBS | awk '{print $NF}')
605 if ! nm --dynamic $lapacklib | grep ATL_cgetrf >/dev/null; then
606 exit 1;
607 fi
608 libdir=$(dirname $(echo $ATLASLIBS | awk '{print $1}'))
609 [ -z "$libdir" ] && echo "Error getting libdir in linux_configure_debian7" && exit 1;
610 echo ATLASINC = $ATLASROOT/include >> kaldi.mk
611 echo ATLASLIBS = $ATLASLIBS -Wl,-rpath=$libdir >> kaldi.mk
612 echo >> kaldi.mk
613 if [[ "$TARGET_ARCH" == arm* ]]; then
614 cat makefiles/linux_atlas_arm.mk >> kaldi.mk
615 elif [[ "$TARGET_ARCH" == ppc64le ]]; then
616 cat makefiles/linux_atlas_ppc64le.mk >> kaldi.mk
617 else
618 cat makefiles/linux_atlas.mk >> kaldi.mk
619 fi
620 echo "Successfully configured for Debian 7 [dynamic libraries] with ATLASLIBS =$ATLASLIBS"
621 $use_cuda && configure_cuda
622 linux_configure_speex
623 }
625 function linux_configure_redhat {
626 m=$1 # 64 or empty.
627 ATLASLIBS="/usr/lib$m/atlas/libatlas.so.3 /usr/lib$m/atlas/libf77blas.so.3 /usr/lib$m/atlas/libcblas.so.3 /usr/lib$m/atlas/libclapack.so.3"
628 for f in $ATLASLIBS; do
629 [ ! -f $f ] && return 1;
630 done
631 libdir=$(dirname $(echo $ATLASLIBS | awk '{print $1}'))
632 [ -z "$libdir" ] && echo "Error getting libdir in linux_configure_redhat" && exit 1;
633 echo ATLASINC = $ATLASROOT/include >> kaldi.mk
634 echo ATLASLIBS = $ATLASLIBS -Wl,-rpath=$libdir >> kaldi.mk
635 echo >> kaldi.mk
636 if [[ "$TARGET_ARCH" == arm* ]]; then
637 cat makefiles/linux_atlas_arm.mk >> kaldi.mk
638 elif [[ "$TARGET_ARCH" == ppc64le ]]; then
639 cat makefiles/linux_atlas_ppc64le.mk >> kaldi.mk
640 else
641 cat makefiles/linux_atlas.mk >> kaldi.mk
642 fi
643 echo "Successfully configured for red hat [dynamic libraries] with ATLASLIBS =$ATLASLIBS"
644 $use_cuda && configure_cuda
645 }
647 function linux_configure_redhat_fat {
648 # This is for when only two so-called 'fat' ATLAS libs are provided:
649 # libsatlas.so.3 and libtatlas.so.3.
650 # See http://stackoverflow.com/questions/13439296/build-shared-libraries-in-atlas.
651 m=$1 # 64 or empty.
652 ATLASLIBS="/usr/lib$m/atlas/libsatlas.so.3 /usr/lib$m/atlas/libtatlas.so.3"
653 for f in $ATLASLIBS; do
654 [ ! -f $f ] && return 1;
655 done
656 libdir=$(dirname $(echo $ATLASLIBS | awk '{print $1}'))
657 [ -z "$libdir" ] && echo "Error getting libdir in linux_configure_redhat_fat" && exit 1;
658 echo ATLASINC = $ATLASROOT/include >> kaldi.mk
659 echo ATLASLIBS = $ATLASLIBS -Wl,-rpath=$libdir >> kaldi.mk
660 echo >> kaldi.mk
661 if [[ "$TARGET_ARCH" == arm* ]]; then
662 cat makefiles/linux_atlas_arm.mk >> kaldi.mk
663 elif [[ "$TARGET_ARCH" == ppc64le ]]; then
664 cat makefiles/linux_atlas_ppc64le.mk >> kaldi.mk
665 else
666 cat makefiles/linux_atlas.mk >> kaldi.mk
667 fi
668 echo "Successfully configured for red hat [dynamic libraries, fat] with ATLASLIBS =$ATLASLIBS"
669 $use_cuda && configure_cuda
670 }
672 function linux_configure_static {
673 if $threaded_atlas; then pt=pt; else pt=""; fi
675 if [ -z $ATLASLIBDIR ]; then # Note: it'll pick up the last one below.
676 for dir in /usr{,/local}/lib{64,}{,/atlas,/atlas-sse2,/atlas-sse3} \
677 /usr/local/atlas/lib{,64} `pwd`/../tools/ATLAS/build/install/lib/ $ATLASROOT/lib; do
678 linux_check_static && ATLASLIBDIR=$dir
679 done
680 if [ -z $ATLASLIBDIR ]; then # Note: it'll pick up the last one below.
681 echo "Could not find libatlas.a in any of the generic-Linux places, but we'll try other stuff..."
682 return 1;
683 fi
684 elif [ ! -f $ATLASLIBDIR/libatlas.a ]; then
685 echo "Could not find libatlas.a in '$ATLASLIBDIR'"
686 return 1;
687 fi
688 echo "Validating presence of ATLAS libs in $ATLASLIBDIR"
689 ATLASLIBS=
690 # The Lapack part of ATLAS seems to appear under various different names.. but it
691 # should always have symbols like ATL_cgetrf defined, so we test for this,
692 # for all the names we have encountered.
693 for libname in liblapack liblapack_atlas libclapack; do
694 if [ -f $ATLASLIBDIR/${libname}.a -a "$ATLASLIBS" == "" ]; then
695 if nm $ATLASLIBDIR/${libname}.a | grep ATL_cgetrf >/dev/null; then
696 ATLASLIBS=$ATLASLIBDIR/${libname}.a
697 echo "Using library $ATLASLIBS as ATLAS's CLAPACK library."
698 fi
699 fi
700 done
701 if [ "$ATLASLIBS" == "" ]; then
702 echo Could not find any libraries $ATLASLIBDIR/{liblapack,liblapack_atlas,libclapack} that seem to be an ATLAS CLAPACK library.
703 return 1;
704 fi
706 for x in lib${pt}cblas.a libatlas.a lib${pt}f77blas.a; do
707 if [ ! -f $ATLASLIBDIR/$x ]; then
708 echo "Configuring static ATLAS libraries failed: Could not find library $x in directory $ATLASLIBDIR"
709 return 1;
710 fi
711 ATLASLIBS="$ATLASLIBS $ATLASLIBDIR/$x"
712 done
713 if $threaded_atlas; then ATLASLIBS="$ATLASLIBS"; fi
715 echo ATLASINC = $ATLASROOT/include >> kaldi.mk
716 echo ATLASLIBS = $ATLASLIBS >> kaldi.mk
717 echo >> kaldi.mk
718 if [[ "$TARGET_ARCH" == arm* ]]; then
719 cat makefiles/linux_atlas_arm.mk >> kaldi.mk
720 elif [[ "$TARGET_ARCH" == ppc64le ]]; then
721 cat makefiles/linux_atlas_ppc64le.mk >> kaldi.mk
722 else
723 cat makefiles/linux_atlas.mk >> kaldi.mk
724 fi
725 $use_cuda && configure_cuda
726 linux_configure_speex
727 echo "Successfully configured for Linux [static libraries] with ATLASLIBS =$ATLASLIBS"
728 }
730 function linux_check_dynamic {
731 # will exit with success if $dir seems to contain ATLAS libraries with
732 # right architecture (compatible with default "nm")
733 if $threaded_atlas; then pt=t; else pt=s; fi
734 for atlas_libname in libatlas.so lib${pt}atlas.so; do
735 if [ -f $dir/$atlas_libname ]; then # candidate...
736 if nm --dynamic $dir/$atlas_libname 2>&1 | grep "File format not recognized" >/dev/null; then
737 echo "Directory $dir may contain dynamic ATLAS libraries but seems to be wrong architecture";
738 return 1;
739 fi
740 echo "Atlas found in $dir";
741 return 0;
742 fi
743 done
744 # echo "... no {libatlas,lib${pt}atlas}.so in $dir";
745 return 1;
746 }
748 function linux_configure_dynamic {
749 if $threaded_atlas; then pt=t; else pt=s; fi # relevant to "fat" libraries, will change later for separate ones
750 if [ -z $ATLASLIBDIR ]; then # Note: it'll pick up the last one below.
751 for dir in /usr{,/local}/lib{,64}{,/atlas,/atlas-sse2,/atlas-sse3} \
752 `pwd`/../tools/ATLAS/build/install/lib/ $ATLASROOT/lib; do
753 linux_check_dynamic && ATLASLIBDIR=$dir && ATLASLIBNAME=$atlas_libname
754 done
755 if [ -z $ATLASLIBDIR -o -z $ATLASLIBNAME ]; then
756 echo "Could not find {libatlas,lib${pt}atlas}.so in any of the obvious places, will most likely try static:"
757 return 1;
758 fi
759 fi
761 # If using "fat" libraries we only need one file to link against
762 if [ $ATLASLIBNAME != libatlas.so ]; then
763 if [ -f $ATLASLIBDIR/$ATLASLIBNAME ]; then
764 ATLASLIBS="$ATLASLIBDIR/$ATLASLIBNAME"
765 else
766 echo "Configuring dynamic ATLAS library failed: library $ATLASLIBNAME not found in $ATLASLIBDIR"
767 return 1;
768 fi
769 else # with "thin" libraries, we have several object to link against, and different single/multi-thread names
770 if $threaded_atlas; then pt=pt; else pt=""; fi
771 echo "Validating presence of ATLAS libs in $ATLASLIBDIR"
772 ATLASLIBS=
773 # The Lapack part of ATLAS seems to appear under various different names.. but it
774 # should always have symbols like ATL_cgetrf defined, so we test for this,
775 # for all the names we have encountered.
776 for libname in lapack lapack_atlas clapack; do
777 if [ -f $ATLASLIBDIR/lib${libname}.so -a "$ATLASLIBS" == "" ]; then
778 if nm --dynamic $ATLASLIBDIR/lib${libname}.so | grep ATL_cgetrf >/dev/null; then
779 ATLASLIBS="$ATLASLIBDIR/lib${libname}.so"
780 echo "Using library $ATLASLIBS as ATLAS's CLAPACK library."
781 fi
782 fi
783 done
784 if [ "$ATLASLIBS" == "" ]; then
785 echo Could not find any libraries $ATLASLIBDIR/{liblapack,liblapack_atlas,libclapack} that seem to be an ATLAS CLAPACK library.
786 return 1;
787 fi
789 for x in ${pt}cblas atlas ${pt}f77blas; do
790 if [ ! -f $ATLASLIBDIR/lib$x.so ]; then
791 echo "Configuring dynamic ATLAS libraries failed: Could not find library $x in directory $ATLASLIBDIR"
792 return 1;
793 fi
794 ATLASLIBS="$ATLASLIBS $ATLASLIBDIR/lib${x}.so"
795 done
796 if $threaded_atlas; then ATLASLIBS="$ATLASLIBS"; fi
797 fi
799 echo ATLASINC = $ATLASROOT/include >> kaldi.mk
800 echo ATLASLIBS = $ATLASLIBS >> kaldi.mk
801 echo >> kaldi.mk
802 if [[ "$TARGET_ARCH" == arm* ]]; then
803 cat makefiles/linux_atlas_arm.mk >> kaldi.mk
804 elif [[ "$TARGET_ARCH" == ppc64le ]]; then
805 cat makefiles/linux_atlas_ppc64le.mk >> kaldi.mk
806 else
807 cat makefiles/linux_atlas.mk >> kaldi.mk
808 fi
809 $use_cuda && configure_cuda
810 linux_configure_speex
811 echo "Successfully configured for Linux [dynamic libraries] with ATLASLIBS =$ATLASLIBS"
812 }
814 ############################# CONFIGURATION #############################
816 # If configuration sets any of these variables, we will switch the external
817 # math library. Here we unset them so that we can check later.
818 unset MKLROOT
819 unset CLAPACKROOT
820 unset OPENBLASROOT
821 unset MKLLIBDIR
823 # This variable identifies the type of system where built programs and
824 # libraries will run. It is set by the configure script when cross compiling.
825 unset HOST
827 # These environment variables can be used to override the default toolchain.
828 CXX=${CXX:-g++}
829 AR=${AR:-ar}
830 AS=${AS:-as}
831 RANLIB=${RANLIB:-ranlib}
833 # These environment variables can be used to provide additional flags to the
834 # compiler/linker. We want these flags to override the flags determined by the
835 # configure script, so we append them to the appropriate variables (CXXFLAGS,
836 # LDFLAGS and LDLIBS) after those variables are set by the configure script.
837 ENV_CXXFLAGS=$CXXFLAGS
838 ENV_LDFLAGS=$LDFLAGS
839 ENV_LDLIBS=$LDLIBS
841 # Default configuration
842 double_precision=false
843 dynamic_kaldi=false
844 use_cuda=true
845 static_fst=false
846 static_math=false
847 threaded_atlas=false
848 mkl_threading=sequential
849 android=false
851 MATHLIB='ATLAS'
852 ATLASROOT=`rel2abs ../tools/ATLAS/`
853 FSTROOT=`rel2abs ../tools/openfst`
855 # Save the command line to include in kaldi.mk
856 cmd_line="$0 $@"
858 while [ $# -gt 0 ];
859 do
860 case "$1" in
861 --help)
862 usage; exit 0 ;;
863 --version)
864 echo $CONFIGURE_VERSION; exit 0 ;;
865 --static)
866 dynamic_kaldi=false;
867 static_math=true;
868 static_fst=true;
869 shift ;;
870 --shared)
871 dynamic_kaldi=true;
872 static_math=false;
873 static_fst=false;
874 shift ;;
875 --double-precision)
876 double_precision=true;
877 shift ;;
878 --double-precision=yes)
879 double_precision=true;
880 shift ;;
881 --double-precision=no)
882 double_precision=false;
883 shift ;;
884 --atlas-root=*)
885 ATLASROOT=`read_dirname $1`;
886 shift ;;
887 --threaded-atlas)
888 threaded_atlas=true;
889 shift ;;
890 --threaded-atlas=yes)
891 threaded_atlas=true;
892 shift ;;
893 --threaded-atlas=no)
894 threaded_atlas=false;
895 shift ;;
896 --threaded-math)
897 threaded_atlas=true;
898 mkl_threading=iomp
899 shift ;;
900 --threaded-math=yes)
901 threaded_atlas=true;
902 mkl_threading=iomp
903 shift ;;
904 --threaded-math=no)
905 threaded_atlas=false;
906 mkl_threading=sequential
907 shift ;;
908 --use-cuda)
909 use_cuda=true;
910 shift ;;
911 --use-cuda=yes)
912 use_cuda=true;
913 shift ;;
914 --use-cuda=no)
915 use_cuda=false;
916 shift ;;
917 --static-math)
918 static_math=true;
919 shift ;;
920 --static-math=yes)
921 static_math=true;
922 shift ;;
923 --static-math=no)
924 static_math=false;
925 shift ;;
926 --static-fst)
927 static_fst=true;
928 shift ;;
929 --static-fst=yes)
930 static_fst=true;
931 shift ;;
932 --static-fst=no)
933 static_fst=false;
934 shift ;;
935 --mkl-threading=sequential)
936 threaded_atlas=false;
937 mkl_threading=sequential;
938 shift ;;
939 --mkl-threading=*)
940 mkl_threading=`expr "X$1" : '[^=]*=\(.*\)'`;
941 threaded_atlas=true;
942 shift ;;
943 --fst-root=*)
944 FSTROOT=`read_dirname $1`;
945 shift ;;
946 --clapack-root=*)
947 CLAPACKROOT=`read_dirname $1`;
948 shift ;;
949 --openblas-root=*)
950 OPENBLASROOT=`read_dirname $1`;
951 shift ;;
952 --mkl-root=*)
953 MKLROOT=`read_dirname $1`;
954 shift ;;
955 --mkl-libdir=*)
956 MKLLIBDIR=`read_dirname $1`;
957 shift ;;
958 --speex-root=*)
959 SPEEXROOT=`read_dirname $1`;
960 shift ;;
961 --speex-libdir=*)
962 SPEEXLIBDIR=`read_dirname $1`;
963 shift ;;
964 --speex-incdir=*)
965 SPEEXINCDIR=`read_dirname $1`;
966 shift ;;
967 --omp-libdir=*)
968 OMPLIBDIR=`read_dirname $1`;
969 shift ;;
970 --mathlib=*)
971 MATHLIB=`expr "X$1" : '[^=]*=\(.*\)'`;
972 shift ;;
973 --cudatk-dir=*)
974 CUDATKDIR=`read_dirname $1`;
975 shift ;; #CUDA is used in src/cudamatrix and src/nnet{,bin} only
976 --fst-version=*)
977 OPENFST_VER=`expr "X$1" : '[^=]*=\(.*\)'`;
978 shift;;
979 --host=*)
980 # The type of system where built programs and libraries will run.
981 # It should be in the format cpu-vendor-os. If specified, this script
982 # will infer the target architecture from the specified host triple.
983 HOST=`expr "X$1" : '[^=]*=\(.*\)'`;
984 shift ;;
985 --android-incdir=*)
986 android=true;
987 threaded_math=false;
988 static_math=true;
989 static_fst=true;
990 dynamic_kaldi=false;
991 MATHLIB='OPENBLAS';
992 ANDROIDINC=`read_dirname $1`;
993 shift;;
994 *) echo "Unknown argument: $1, exiting"; usage; exit 1 ;;
995 esac
996 done
998 # The idea here is that if you change the configuration options from using
999 # CUDA to not using it, or vice versa, we want to recompile all parts of the
1000 # code that may use a GPU. Touching this file is a way to force this.
1001 touch cudamatrix/cu-common.h 2>/dev/null
1003 if $android && [[ "$CXX" != *clang++* ]] ; then
1004 failure "Android build requires clang++. Make sure you have clang++ installed
1005 on your system and then override the default compiler by setting CXX, e.g.
1006 CXX=clang++ ./configure"
1007 fi
1009 # If HOST is set
1010 # 1. We prepend it to CXX, AR, AS and RANLIB.
1011 # 2. We parse the target architecture from the HOST triple.
1012 # Otherwise we set the target architecture to the output of `uname -m`.
1013 if is_set $HOST; then
1014 CXX="$HOST-$CXX"
1015 AR="$HOST-$AR"
1016 AS="$HOST-$AS"
1017 RANLIB="$HOST-$RANLIB"
1019 # The host triple will be something like "armv8-rpi3-linux-gnueabihf". We
1020 # need the first field which is the target architecture for this build. The
1021 # following command will take the host triple "armv8-rpi3-linux-gnueabihf"
1022 # and return ["armv8", "rpi3", "linux", "gnueabihf"] in PARTS.
1023 IFS='-' read -ra PARTS <<< "$HOST"
1024 # The first field in the PARTS list is the target architecture.
1025 TARGET_ARCH="$PARTS"
1026 if [[ "$TARGET_ARCH" != arm* && "$TARGET_ARCH" != ppc64le && "$TARGET_ARCH" != x86* ]] ; then
1027 # We currently only support building for x86[_64], arm*, and ppc64le.
1028 # If TARGET_ARCH was read from the HOST variable, it must be one of these.
1029 failure "$TARGET_ARCH is not a supported architecture.
1030 Supported architectures: x86[_64], arm*, ppc64le."
1031 fi
1032 else
1033 TARGET_ARCH="`uname -m`"
1034 fi
1036 # If one of these variables is set, we switch the external math library.
1037 is_set $MKLLIBDIR && echo "Configuring KALDI to use MKL" && export MATHLIB="MKL"
1038 is_set $MKLROOT && echo "Configuring KALDI to use MKL"&& export MATHLIB="MKL"
1039 is_set $CLAPACKROOT && echo "Configuring KALDI to use CLAPACK"&& export MATHLIB="CLAPACK"
1040 is_set $OPENBLASROOT && echo "Configuring KALDI to use OPENBLAS"&& export MATHLIB="OPENBLAS"
1042 echo "Configuring ..."
1044 # Back up the old kaldi.mk in case we modified it
1045 if [ -f kaldi.mk ]; then
1046 echo "Backing up kaldi.mk to kaldi.mk.bak ..."
1047 cp kaldi.mk kaldi.mk.bak
1048 fi
1050 # Generate the new kaldi.mk file
1051 echo "# This file was generated using the following command:" > kaldi.mk
1052 echo "# $cmd_line" >> kaldi.mk
1053 echo >> kaldi.mk
1054 echo "CONFIGURE_VERSION := $CONFIGURE_VERSION" >> kaldi.mk
1055 echo >> kaldi.mk
1057 echo "# Toolchain configuration" >> kaldi.mk
1058 echo >> kaldi.mk
1059 echo "CXX = $CXX" >> kaldi.mk
1060 echo "AR = $AR" >> kaldi.mk
1061 echo "AS = $AS" >> kaldi.mk
1062 echo "RANLIB = $RANLIB" >> kaldi.mk
1063 echo >> kaldi.mk
1065 echo "Checking compiler $CXX ..."
1066 check_compiler $CXX
1068 echo "# Base configuration" >> kaldi.mk
1069 echo >> kaldi.mk
1070 if $dynamic_kaldi ; then
1071 KALDILIBDIR=`pwd`/lib
1072 echo "KALDI_FLAVOR := dynamic" >> kaldi.mk
1073 echo "KALDILIBDIR := $KALDILIBDIR" >> kaldi.mk
1074 fi
1075 if $double_precision; then
1076 echo "DOUBLE_PRECISION = 1" >> kaldi.mk
1077 else
1078 echo "DOUBLE_PRECISION = 0" >> kaldi.mk
1079 fi
1080 echo "Checking OpenFst library in $FSTROOT ..."
1081 if [ ! -f $FSTROOT/include/fst/fst.h ]; then
1082 failure "Could not find file $FSTROOT/include/fst/fst.h:
1083 you may not have installed OpenFst. See ../tools/INSTALL"
1084 fi
1085 OPENFST_VER=${OPENFST_VER:-$(grep 'PACKAGE_VERSION' $FSTROOT/Makefile | sed -e 's:.*= ::')}
1086 OPENFST_VER_NUM=$(echo $OPENFST_VER | sed 's/\./ /g' | xargs printf "%d%02d%02d")
1087 if [ $OPENFST_VER_NUM -lt 10600 ]; then
1088 failure "OpenFst-$OPENFST_VER is not supported. You need OpenFst >= 1.6.0.)"
1089 fi
1090 echo "OPENFSTINC = $FSTROOT/include" >> kaldi.mk
1091 if $static_fst ; then
1092 OPENFSTLIBS="$FSTROOT/lib/libfst.a"
1093 else
1094 if [ "`uname`" == "Darwin" ]; then
1095 OPENFSTLIBS="$FSTROOT/lib/libfst.dylib"
1096 OPENFSTLDFLAGS="-Wl,-rpath -Wl,${FSTROOT}/lib"
1097 elif [ "`uname`" == "Linux" ]; then
1098 OPENFSTLIBS="$FSTROOT/lib/libfst.so"
1099 OPENFSTLDFLAGS="-Wl,-rpath=${FSTROOT}/lib"
1100 else
1101 failure "Dynamic libraries are not supported on this platform.
1102 Run configure with --static --static-fst=no flag."
1103 fi
1104 fi
1105 if [ ! -f "$OPENFSTLIBS" ]; then
1106 failure "Static=[$static_fst] OpenFST library not found: See ../tools/INSTALL"
1107 fi
1108 echo "OPENFSTLIBS = $OPENFSTLIBS" >> kaldi.mk
1109 echo "OPENFSTLDFLAGS = $OPENFSTLDFLAGS" >> kaldi.mk
1110 echo >> kaldi.mk
1112 # OS-specific steps given below append to kaldi.mk
1113 echo "Doing OS specific configurations ..."
1115 if $android ; then
1116 if [ -z $ANDROIDINC ] ; then
1117 failure "--android-incdir must be specified for android builds."
1118 fi
1120 if ! is_set $HOST; then
1121 failure "HOST must be specified for android builds."
1122 fi
1124 OPENBLASROOT=`rel2abs "$OPENBLASROOT"`
1125 if [ -z "$OPENBLASROOT" ]; then
1126 failure "The location of OPENBLAS must be specified for android builds
1127 using --openblas-root (and it must exist)"
1128 fi
1129 if [ ! -f $OPENBLASROOT/lib/libopenblas.a ]; then
1130 failure "Expected to find the file $OPENBLASROOT/lib/libopenblas.a"
1131 fi
1132 echo "Using OpenBLAS as the linear algebra library."
1134 OPENBLASLIBS="$OPENBLASROOT/lib/libopenblas.a $OPENBLASROOT/lib/libclapack.a $OPENBLASROOT/lib/liblapack.a $OPENBLASROOT/lib/libblas.a $OPENBLASROOT/lib/libf2c.a"
1135 echo "OPENBLASINC = $OPENBLASROOT/include" >> kaldi.mk
1136 echo "OPENBLASLIBS = $OPENBLASLIBS" >> kaldi.mk
1137 echo "ANDROIDINC = $ANDROIDINC" >> kaldi.mk
1139 cat makefiles/android_openblas.mk >> kaldi.mk
1141 echo "Successfully configured for Android with OpenBLAS from $OPENBLASROOT."
1143 elif [ "`uname`" == "Darwin" ]; then
1144 # Check for Darwin first, because we later call uname -o (for Cygwin)
1145 # which crashes on Darwin.
1147 echo "On Darwin: Checking for Accelerate framework ..."
1148 if [ ! -e /System/Library/Frameworks/Accelerate.framework ]; then
1149 failure "Need the Accelerate framework to compile on Darwin."
1150 fi
1151 OSX_VER=$(sw_vers | grep ProductVersion | awk '{print $2}' | awk '{split($0,a,"."); print a[1] "." a[2]; }')
1152 OSX_VER_NUM=$(echo $OSX_VER | sed 's/\./ /g' | xargs printf "%d%02d")
1153 echo "Configuring for OS X version $OSX_VER ..."
1154 if [ $OSX_VER_NUM -ge 1005 ]; then
1155 cat makefiles/darwin.mk >> kaldi.mk
1156 else
1157 failure "Mac OS X version '$OSX_VER' is not supported."
1158 fi
1160 if [ $OSX_VER_NUM == 1011 ]; then
1161 echo "**BAD WARNING**: You are using OS X El Capitan. Some versions of this OS"
1162 echo "**BAD WARNING**: have a bug in the BLAS implementation that affects Kaldi."
1163 echo "**BAD WARNING**: After compiling, cd to matrix/ and type 'make test'. The"
1164 echo "**BAD WARNING**: test will fail if the problem exists in your version. "
1165 echo "**BAD WARNING**: Eventually this issue will be fixed by system updates from"
1166 echo "**BAD WARNING**: Apple. Unexplained crashes with reports of NaNs will"
1167 echo "**BAD WARNING**: be caused by this bug, but some recipes will (sometimes) work."
1168 sleep 1; echo -n .; sleep 1; echo -n .; sleep 1; echo .
1169 fi
1170 echo "Successfully configured for Darwin with Accelerate framework."
1171 $use_cuda && configure_cuda
1173 elif [ "`uname -o`" == "Cygwin" ]; then
1174 echo "On Cygwin: Checking for linear algebra libraries ..."
1175 if [ ! -f ../tools/CLAPACK/clapack.h ]; then
1176 failure "could not find file ../tools/CLAPACK/clapack.h"
1177 fi
1178 if [ ! -f /usr/lib/lapack/cygblas-0.dll ]; then
1179 failure "please first install package liblapack0"
1180 fi
1181 cat makefiles/cygwin.mk >> kaldi.mk
1182 echo "Successfully configured for Cygwin with CLAPACK."
1184 elif [ "`uname`" == "Linux" ]; then
1185 echo "On Linux: Checking for linear algebra header files ..."
1186 if [ "$MATHLIB" == "ATLAS" ]; then
1187 if [ ! -f $ATLASROOT/include/cblas.h ] || [ ! -f $ATLASROOT/include/clapack.h ] ; then
1188 failure "Could not find required header files cblas.h or clapack.h in ATLAS dir '$ATLASROOT/include'"
1189 fi
1190 echo "Using ATLAS as the linear algebra library."
1192 # Finding out where the libraries are located:
1193 # First we look for the static libraries and then look for dynamic ones.
1194 # We're looking for four libraries, all in the same directory, named
1195 # libcblas.a, libatlas.a, libf77blas.a, and a library that's variously
1196 # named liblapack.a, libclapack.a, or liblapack_atlas.a, but which exports
1197 # the symbol ATL_cgetrf.
1198 # Note: there is a different type of ATLAS installation that is not
1199 # covered. We saw a case where there was a directory called /usr/lib/atlas
1200 # containing {liblapack.a,libblas.a}, and linking against just these two
1201 # libraries worked.
1203 if $static_math; then
1204 # Prefer static to dynamic math.
1205 linux_configure_static || \
1206 linux_configure_debian_ubuntu3 || \
1207 linux_configure_dynamic || \
1208 linux_configure_debian_ubuntu 64 || \
1209 linux_configure_debian_ubuntu || \
1210 linux_configure_debian7 || \
1211 linux_configure_redhat 64 || \
1212 linux_configure_redhat || \
1213 linux_configure_redhat_fat 64 || \
1214 linux_configure_redhat_fat || \
1215 linux_atlas_failure "Failed to configure ATLAS libraries";
1216 else
1217 # Prefer dynamic to static math.
1218 linux_configure_debian_ubuntu3 || \
1219 linux_configure_dynamic || \
1220 linux_configure_static || \
1221 linux_configure_debian_ubuntu 64 || \
1222 linux_configure_debian_ubuntu || \
1223 linux_configure_debian7 || \
1224 linux_configure_redhat 64 || \
1225 linux_configure_redhat || \
1226 linux_configure_redhat_fat 64 || \
1227 linux_configure_redhat_fat || \
1228 linux_atlas_failure "Failed to configure ATLAS libraries";
1229 fi
1231 elif [ "$MATHLIB" == "MKL" ]; then
1232 if [ "$TARGET_ARCH" != "x86_64" ]; then
1233 failure "MKL on Linux only supported for Intel(R) 64 architecture (x86_64).
1234 See makefiles/linux_64_mkl.mk to manually configure for other platforms."
1235 fi
1237 if ( is_set "$MKLROOT" && ! is_set "$MKLLIBDIR" ); then
1238 echo -n "Configuring MKL library directory: "
1239 MKLLIBDIR=`linux_configure_mkllibdir $MKLROOT`
1240 if [ $? -ne 0 ]; then
1241 failure "MKL libraries could not be found. Please use the switch --mkl-libdir "
1242 else
1243 echo "Found: $MKLLIBDIR"
1244 fi
1245 fi
1247 MKL_LINK_LINE=`linux_configure_mkl_libraries "$MKLLIBDIR" $static_math $mkl_threading` || exit 1
1248 echo "MKL configured with threading: $mkl_threading, libs: $MKL_LINK_LINE"
1250 MKL_COMPILE_LINE=`linux_configure_mkl_includes "$MKLROOT" "$MKLLIBDIR"` || exit 1
1251 echo "MKL include directory configured as: $MKL_COMPILE_LINE"
1252 MKL_COMPILE_LINE=" -I${MKL_COMPILE_LINE} "
1254 THREADING_LINE=`linux_configure_mkl_threading $MKLROOT $MKLLIBDIR $static_math $mkl_threading` || exit 1
1255 EXTRA_LIBS=`linux_configure_mkl_extra $static_math $mkl_threading` || exit 1
1256 if [ ! -z "$THREADING_LINE" ] || [ ! -z "$EXTRA_LIBS" ]; then
1257 echo "MKL threading libraries configured as $THREADING_LINE $EXTRA_LIBS"
1258 fi
1260 echo "Using Intel MKL as the linear algebra library."
1261 (
1262 cd probe; rm -f mkl-test;
1263 g++ mkl-test.cc -o mkl-test $MKL_COMPILE_LINE $MKL_LINK_LINE $THREADING_LINE $EXTRA_LIBS || exit 1
1264 test -f ./mkl-test || exit 1
1265 ./mkl-test || exit 1
1266 cd ..
1267 ) || failure "Cannot validate the MKL switches"
1269 echo MKLROOT = $MKLROOT >> kaldi.mk
1270 if [ ! -z $MKLLIBDIR ]; then
1271 echo MKLLIB = $MKLLIBDIR >> kaldi.mk
1272 fi
1273 echo >> kaldi.mk
1274 check_exists makefiles/linux_x86_64_mkl.mk
1275 cat makefiles/linux_x86_64_mkl.mk >> kaldi.mk
1276 echo "MKLFLAGS = ${MKL_LINK_LINE} ${THREADING_LINE} $EXTRA_LIBS " >> kaldi.mk
1277 echo "Successfully configured for Linux with MKL libs from $MKLROOT"
1278 $use_cuda && configure_cuda
1279 linux_configure_speex
1281 elif [ "$MATHLIB" == "CLAPACK" ]; then
1282 if [ -z "$CLAPACKROOT" ]; then
1283 failure "Must specify the location of CLAPACK with --clapack-root option (and it must exist)"
1284 fi
1285 if [ ! -f ../tools/CLAPACK/clapack.h ]; then
1286 failure "could not find file ../tools/CLAPACK/clapack.h"
1287 fi
1288 if [ ! -d "$CLAPACKROOT" ]; then
1289 failure "The directory $CLAPACKROOT does not exist"
1290 fi
1291 # Also check for cblas.h and f2c.h
1292 echo "Using CLAPACK libs from $CLAPACKROOT as the linear algebra library."
1293 if [ ! -f makefiles/linux_clapack.mk ]; then
1294 failure "makefiles/linux_clapack.mk not found."
1295 fi
1296 if [[ "$TARGET_ARCH" == arm* ]]; then
1297 cat makefiles/linux_clapack_arm.mk >> kaldi.mk
1298 else
1299 cat makefiles/linux_clapack.mk >> kaldi.mk
1300 fi
1301 echo "Warning (CLAPACK): this part of the configure process is not properly tested and may not work."
1302 echo "Successfully configured for Linux with CLAPACK libs from $CLAPACKROOT"
1303 $use_cuda && configure_cuda
1304 linux_configure_speex
1306 elif [ "$MATHLIB" == "OPENBLAS" ]; then
1307 OPENBLASROOT=`rel2abs "$OPENBLASROOT"`
1308 if [ -z "$OPENBLASROOT" ]; then
1309 failure "Must specify the location of OPENBLAS with --openblas-root option (and it must exist)"
1310 fi
1311 if [ ! -f $OPENBLASROOT/lib/libopenblas.so ]; then
1312 failure "Expected to find the file $OPENBLASROOT/lib/libopenblas.so"
1313 fi
1314 echo "Your math library seems to be OpenBLAS from $OPENBLASROOT. Configuring appropriately."
1315 if $static_math; then
1316 echo "Configuring static OpenBlas since --static-math=yes"
1317 OPENBLASLIBS="$OPENBLASROOT/lib/libopenblas.a -lgfortran"
1318 else
1319 echo "Configuring dynamically loaded OpenBlas since --static-math=no (the default)"
1320 OPENBLASLIBS="-L$OPENBLASROOT/lib -lopenblas -lgfortran -Wl,-rpath=$OPENBLASROOT/lib"
1321 fi
1322 echo "OPENBLASINC = $OPENBLASROOT/include" >> kaldi.mk
1323 echo "OPENBLASLIBS = $OPENBLASLIBS" >> kaldi.mk
1324 echo >> kaldi.mk
1325 if [[ "$TARGET_ARCH" == arm* ]]; then
1326 cat makefiles/linux_openblas_arm.mk >> kaldi.mk
1327 elif [[ "$TARGET_ARCH" == ppc64le ]]; then
1328 cat makefiles/linux_openblas_ppc64le.mk >> kaldi.mk
1329 else
1330 cat makefiles/linux_openblas.mk >> kaldi.mk
1331 fi
1332 echo "Successfully configured for Linux with OpenBLAS from $OPENBLASROOT"
1333 $use_cuda && configure_cuda
1334 linux_configure_speex
1336 else
1337 failure "Unsupported linear algebra library '$MATHLIB'"
1338 fi
1339 else
1340 failure "Could not detect the platform or we have not yet worked out the
1341 appropriate configuration for this platform. Please contact the developers."
1342 fi
1344 # Append the flags set by environment variables last so they can be used
1345 # to override the automatically generated configuration.
1346 echo >> kaldi.mk
1347 echo "# Environment configuration" >> kaldi.mk
1348 echo >> kaldi.mk
1349 if [ -n "$ENV_CXXFLAGS" ]; then echo "CXXFLAGS += $ENV_CXXFLAGS" >> kaldi.mk; fi
1350 if [ -n "$ENV_LDFLAGS" ]; then echo "LDFLAGS += $ENV_LDFLAGS" >> kaldi.mk; fi
1351 if [ -n "$ENV_LDLIBS" ]; then echo "LDLIBS += $ENV_LDLIBS" >> kaldi.mk; fi
1353 # We check for slow exp implementation just before we exit. This check uses
1354 # and possibly modifies the kaldi.mk file that we just generated.
1355 check_for_slow_expf;
1356 echo "SUCCESS"
1357 echo "To compile: make clean -j; make depend -j; make -j"
1358 echo " ... or e.g. -j 10, instead of -j, to use a specified number of CPUs"
1359 exit 0;