forked from srvk/eesen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·868 lines (779 loc) · 31.4 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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
#!/bin/bash
#
# This configure script is hand-generated, not auto-generated.
# It creates the file config.mk, which is %included by the Makefiles
# in the subdirectories.
# The file config.mk is editable by hand-- for example, you may want to
# remove the options -g -O0 -DKALDI_PARANOID, or edit the
# -DKALDI_DOUBLE_PRECISION option (to be 1 not 0),
# Example command lines:
# ./configure
# ./configure --shared ## shared libraries.
# ./configure --mkl-root=/opt/intel/mkl
# ./configure --mkl-root=/opt/intel/mkl --threaded-math=yes
# ./configure --openblas-root=../tools/OpenBLAS/install # before doing
# # this, cd to ../tools and type "make openblas". Note:
# # this is not working correctly on all platforms, do "make test"
# # and look out for segmentation faults.
# ./configure --atlas-root=../tools/ATLAS/build
#This should be incremented after every significant change of the configure script
#I.e. after each change that affects the config.mk or the build system as whole
CONFIGURE_VERSION=2
function rel2abs {
if [ ! -z "$1" ]; then
local retval=`cd $1 2>/dev/null && pwd || exit 1`
echo $retval
fi
}
function read_dirname {
local dir_name=`expr "X$1" : '[^=]*=\(.*\)'`;
local retval=`rel2abs $dir_name`
[ -z $retval ] && echo "Bad option '$1': no such directory" && exit 1;
echo $retval
}
function is_set {
local myvar=${1:-notset}
if [ "$myvar" == "notset" ]; then
return 1
else
return 0
fi
}
## First do some checks. These verify that all the things are
## here that should be here.
if [ "`basename $PWD`" != "src" ]; then
echo 'You must run "configure" from the src/ directory.'
exit 1
fi
## Default locations for FST and linear algebra libraries.
MATHLIB='ATLAS'
ATLASROOT=`rel2abs ../tools/ATLAS/`
FSTROOT=`rel2abs ../tools/openfst`
# Avoid using any variables that are set in the shell.
unset MKLROOT
unset CLAPACKROOT
unset OPENBLASROOT
unset MKLLIBDIR
function usage {
echo 'Usage: ./configure [--static|--shared] [--threaded-atlas={yes|no}] [--atlas-root=ATLASROOT] [--fst-root=FSTROOT]
[--openblas-root=OPENBLASROOOT] [--clapack-root=CLAPACKROOT] [--mkl-root=MKLROOT] [--mkl-libdir=MKLLIBDIR]
[--omp-libdir=OMPDIR] [--static-fst={yes|no}] [--static-math={yes|no}] [--threaded-math={yes|no}] [--mathlib=ATLAS|MKL|CLAPACK|OPENBLAS]
[--use-cuda={yes|no}] [--cudatk-dir=CUDATKDIR]';
}
threaded_atlas=false # By default, use the un-threaded version of ATLAS.
threaded_math=${threaded_atlas}
static_math=false
static_fst=false
use_cuda=true
dynamic_kaldi=false
cmd_line="$0 $@" # Save the command line to include in config.mk
while [ $# -gt 0 ];
do
case "$1" in
--help) usage; exit 0 ;;
--version) echo $CONFIGURE_VERSION; exit 0 ;;
--static)
# FIXME depends on order of options first--static/--shared then --static-math -> it will override it
dynamic_kaldi=false;
static_math=true;
static_fst=true;
shift ;;
--shared)
dynamic_kaldi=true;
static_math=false;
static_fst=false;
shift ;;
--atlas-root=*)
ATLASROOT=`read_dirname $1`; shift ;;
--threaded-atlas=yes)
threaded_atlas=true; shift ;;
--threaded-atlas=no)
threaded_atlas=false; shift ;;
--threaded-math=yes)
threaded_atlas=true; threaded_math=true; shift ;;
--threaded-math=no)
threaded_atlas=false; threaded_math=false; shift ;;
--use-cuda=yes)
use_cuda=true; shift ;;
--use-cuda=no)
use_cuda=false; shift ;;
--static-math=yes)
static_math=true; shift ;;
--static-math=no)
static_math=false; shift ;;
--static-fst=yes)
static_fst=true; shift ;;
--static-fst=no)
static_fst=false; shift ;;
--fst-root=*)
FSTROOT=`read_dirname $1`; shift ;;
--clapack-root=*)
CLAPACKROOT=`read_dirname $1`; shift ;;
--openblas-root=*)
OPENBLASROOT=`read_dirname $1`; shift ;;
--mkl-root=*)
MKLROOT=`read_dirname $1`; shift ;;
--mkl-libdir=*)
MKLLIBDIR=`read_dirname $1`; shift ;;
--omp-libdir=*)
OMPLIBDIR=`read_dirname $1`; shift ;;
--mathlib=*)
MATHLIB=`expr "X$1" : '[^=]*=\(.*\)'`; shift ;;
--cudatk-dir=*)
CUDATKDIR=`read_dirname $1`; shift ;;
*) echo "Unknown argument: $1, exiting"; usage; exit 1 ;;
esac
done
function failure {
echo "***configure failed: $* ***" >&2
if [ -f config.mk ]; then rm config.mk; fi
exit 1;
}
function check_exists {
if [ ! -f $1 ]; then failure "$1 not found."; fi
}
function check_for_bad_gcc {
if which gcc >&/dev/null; then # gcc is on the path
gcc_version=$(gcc -dumpspecs 2>&1 | grep -A1 -F '*version:' | grep -v version)
if [ "$gcc_version" == "4.8.2" ]; then
echo "*** WARNING: your version of gcc seems to be 4.8.2. ***"
echo "*** This version of gcc has a bug in nth_element ***"
echo "*** in its implementation of the standard library ***"
echo "*** This will cause Kaldi to crash (make test ***"
echo "*** should fail). Please either upgrade or downgrade gcc. ***"
fi
fi
}
function exit_success {
check_for_bad_gcc;
# check_for_slow_expf;
exit 0;
}
function linux_configure_mkllibdir {
local mklroot=$1
if [ -d $mklroot/lib/em64t ]; then
echo $mklroot/lib/em64t
elif [ -d $mklroot/lib/intel64 ]; then
echo $mklroot/lib/intel64
else
return 1;
fi
}
function linux_configure_mkl_libraries {
local mkllibdir=$1
local static=$2
local threaded=$3
#these lines were generated using the Intel Link Line Advisor 2.2
local threaded_libs="mkl_intel_lp64 mkl_intel_thread mkl_core"
local sequential_libs="mkl_intel_lp64 mkl_sequential mkl_core"
if ! $static && $threaded ; then
for file in $threaded_libs; do
local libfile=$mkllibdir/lib$file.so
check_exists $libfile
done
echo "-L$mkllibdir -Wl,-rpath=$mkllibdir -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -liomp5 -lpthread -lm"
elif ! $static && ! $threaded ; then
for file in $sequential_libs; do
local libfile=$mkllibdir/lib$file.so
check_exists $libfile
done
echo "-L$mkllibdir -Wl,-rpath=$mkllibdir -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -liomp5 -lpthread -lm"
elif $static && $threaded ; then
local linkline=""
test -f "$mkllibdir/libmkl_solver_lp64.a" && linkline="$linkline $mkllibdir/libmkl_solver_lp64.a"
linkline="$linkline -Wl,--start-group"
for file in $threaded_libs; do
local libfile=$mkllibdir/lib$file.a
check_exists $libfile
linkline="$linkline $libfile"
done
#linkline="$linkline -Wl,--end-group -liomp5 -lpthread -lm "
linkline="$linkline -Wl,--end-group "
echo $linkline
elif $static && ! $threaded ; then
local linkline=""
test -f "$mkllibdir/libmkl_solver_lp64_sequential.a" && linkline="$linkline $mkllibdir/libmkl_solver_lp64_sequential.a"
linkline="$linkline -Wl,--start-group"
for file in $sequential_libs; do
local libfile=$mkllibdir/lib$file.a
check_exists $libfile
linkline="$linkline $libfile"
done
#linkline="$linkline -Wl,--end-group -liomp5 -lpthread -lm "
linkline="$linkline -Wl,--end-group "
echo $linkline
else
return 1;
fi
}
function linux_configure_mkl_includes {
test -d $1/include && echo "$1/include" && return;
test -d $2/../../include && echo "$2/../../include" && return;
failure "Could not find the MKL include directory"
}
function check_library {
local libpath=$1
local libname=$2
local libext=$3
local full_libname="$libpath/$libname.$libext"
##echo "Testing $full_libname" >&2
test -f "$full_libname" && return ;
return 1
}
function linux_configure_omplibdir {
local mklroot=$1
local mkllibdir=$2
local libexts=$3
##First we try to use the library in the same directory
##where the mkl libraries reside
##Afterwards, just try some possibilities for different MKL layouts
for libext in $libexts; do
echo "Testing $libext from [$libexts] " >&2
check_library $mkllibdir "libiomp5" $libext \
&& echo `readlink -f $mkllibdir` && return
local testdir=`(cd $mklroot; cd ..; cd lib/intel64;pwd)`
test -d $testdir && check_library $testdir "libiomp5" $libext && echo `readlink -f $testdir` && return;
local testdir=`(cd $mklroot; cd ..; cd lib/em64t;pwd)`
test -d $testdir && check_library $testdir "libiomp5" $libext && echo `readlink -f $testdir` && return;
local testdir=`(cd $mkllibdir; cd ../../..; cd lib/intel64;pwd)`
test -d $testdir && check_library $testdir "libiomp5" $libext && echo `readlink -f $testdir` && return;
local testdir=`(cd $mklroot; cd ../../..; cd lib/em64t;pwd)`
test -d $testdir && check_library $testdir "libiomp5" $libext && echo `readlink -f $testdir` && return;
done
#failure "Could not find the library iomp5, use the configure switch --omp-libdir"
return 1
}
#Check if at least one of these variables is set
#If yes, we want to switch to using the MKL
is_set $MKLLIBDIR && echo "Force-configuring KALDI to use MKL" && export MATHLIB="MKL"
is_set $MKLROOT && echo "Force-configuring KALDI to use MKL"&& export MATHLIB="MKL"
is_set $CLAPACKROOT && echo "Force-configuring KALDI to use CLAPACK"&& export MATHLIB="CLAPACK"
is_set $OPENBLASROOT && echo "Force-configuring KALDI to use OPENBLAS"&& export MATHLIB="OPENBLAS"
##
##CUDA is used in src/gpucompute and src/nnet{,bin} only.
##It is used to accelerate the neural network training,
##the rest of kaldi is running on CPUs.
##
function linux_configure_cuda {
#check for CUDA toolkit in the system
if [ ! $CUDATKDIR ]; then
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
if [ -f $base/bin/nvcc ]; then
CUDATKDIR=$base
fi
done
fi
if [ $CUDATKDIR ]; then
if [ ! -f $CUDATKDIR/bin/nvcc ]; then
failure "Cannnot find nvcc in CUDATKDIR=$CUDATKDIR"
fi
echo "Using CUDA toolkit $CUDATKDIR (nvcc compiler and runtime libraries)"
echo >> config.mk
echo "#Next section enables CUDA for compilation" >> config.mk
echo CUDA = true >> config.mk
echo CUDATKDIR = $CUDATKDIR >> config.mk
if [ "`uname -m`" == "x86_64" ]; then
cat makefiles/linux_x86_64_cuda.mk >> config.mk
else
cat makefiles/linux_cuda.mk >> config.mk
fi
else
echo "CUDA will not be used! If you have already installed cuda drivers and cuda toolkit, try using --cudatk-dir=... option. Note: this is only relevant for neural net experiments"
fi
}
function linux_configure_speex {
#check whether the user has called tools/extras/install_speex.sh or not
SPEEXROOT=`pwd`/../tools/speex
static_speex=$1
if [ "foo"$static_speex == "foo" ]; then
static_speex=false
fi
if $static_speex; then
spx_type=a
else
spx_type=so
fi
if [ ! -f "$SPEEXROOT/lib/libspeex.${spx_type}" ];then
echo "Static=[$static_speex] Speex library not found: You can still build Kaldi without Speex."
return
fi
if [ -f $SPEEXROOT/include/speex/speex.h ]; then
echo >> config.mk
echo CXXFLAGS += -DHAVE_SPEEX -I${SPEEXROOT}/include >> config.mk
if $static_speex; then
echo LDLIBS += $SPEEXROOT/lib/libspeex.a
else
echo LDLIBS += -L${SPEEXROOT}/lib -lspeex >> config.mk
echo LDFLAGS += -Wl,-rpath=${SPEEXROOT}/lib >> config.mk
fi
echo "Successfully configured with Speex at $SPEEXROOT, (static=[$static_speex])"
else
echo "Speex will not be used. If you want to use it, run tools/extras/install_speex.sh first."
fi
}
function fix_cxx_flag {
CXXCOMPILER=`grep "CXX = " config.mk | awk '{print $3}'`
if [ $CXXCOMPILER=="g++" ]; then
$CXXCOMPILER -dumpversion | \
awk '{if(NR==1 && $1<"4.4") print "sed \"s/-Wno-unused-local-typedefs//g\" \
config.mk > tmpf; mv tmpf config.mk; "}' | sh -
fi
}
function linux_atlas_failure { # function we use when we couldn't find
# ATLAS libs.
echo ATLASINC = [somewhere]/include >> config.mk
echo ATLASLIBS = [somewhere]/liblapack.a [somewhere]/libcblas.a [somewhere]/libatlas.a [somewhere]/libf77blas.a $ATLASLIBDIR >> config.mk
cat makefiles/linux_atlas.mk >> config.mk
fix_cxx_flag
echo "** $* ***"
echo "** ERROR **"
echo "**Configure cannot proceed automatically, but by editing config.mk"
echo "** you may be able to proceed (replace [somewhere] with a directory);"
echo "** or install the ATLAS package on your machine (if you are system "
echo " administrator, you can do it easily by searching the atlas packages "
echo " with commands like 'apt-cache search libatlas' or 'yum search atlas',"
echo " and install the packages with commands 'apt-get install' or 'yum install') "
echo " e.g. 'apt-get install libatlas-dev libatlas-base-dev';"
echo "** or try going to ../tools and running install_atlas.sh, and running"
echo " this script (configure) again."
exit 1;
}
function linux_check_static {
# will exit with success if $dir seems to contain ATLAS libraries with
# right architecture (compatible with default "nm")
echo "int main(void) { return 0; }" > test_linking.cc;
if [ -f $dir/libatlas.a ]; then # candidate...
# Note: on the next line, the variable assignment
# LANG=en_US should apply just to the program called on that line.
if LANG=en_US gcc -o test_linking test_linking.cc -u ATL_flushcache $dir/libatlas.a 2>&1 | grep -i "incompatible" >/dev/null; then
echo "Directory $dir may contain ATLAS libraries but seems to be wrong architecture";
rm test_linking test_linking.cc 2>/dev/null
return 1;
fi
rm test_linking test_linking.cc 2>/dev/null
return 0;
else
rm test_linking.cc
return 1;
fi
}
function linux_configure_debian_ubuntu {
m=$1
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"
for f in $ATLASLIBS; do
[ ! -f $f ] && return 1;
done
echo ATLASINC = $ATLASROOT/include >> config.mk
echo ATLASLIBS = $ATLASLIBS >> config.mk
cat makefiles/linux_atlas.mk >> config.mk
fix_cxx_flag
echo "Successfully configured for Debian/Ubuntu Linux [dynamic libraries] with ATLASLIBS =$ATLASLIBS"
$use_cuda && linux_configure_cuda
linux_configure_speex
exit_success;
}
function linux_configure_debian7 {
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"
for f in $ATLASLIBS; do
[ ! -f $f ] && return 1;
done
libdir=$(dirname $(echo $ATLASLIBS | awk '{print $1}'))
[ -z "$libdir" ] && echo "Error getting libdir in linux_configure_debian7" && exit 1;
echo ATLASINC = $ATLASROOT/include >> config.mk
echo ATLASLIBS = $ATLASLIBS -Wl,-rpath=$libdir >> config.mk
echo
cat makefiles/linux_atlas.mk >> config.mk
fix_cxx_flag
echo "Successfully configured for Debian 7 [dynamic libraries] with ATLASLIBS =$ATLASLIBS"
$use_cuda && linux_configure_cuda
linux_configure_speex
exit_success;
}
function linux_configure_redhat {
m=$1 # 64 or empty.
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"
for f in $ATLASLIBS; do
[ ! -f $f ] && return 1;
done
libdir=$(dirname $(echo $ATLASLIBS | awk '{print $1}'))
[ -z "$libdir" ] && echo "Error getting libdir in linux_configure_redhat" && exit 1;
echo ATLASINC = $ATLASROOT/include >> config.mk
echo ATLASLIBS = $ATLASLIBS -Wl,-rpath=$libdir >> config.mk
echo
cat makefiles/linux_atlas.mk >> config.mk
fix_cxx_flag
echo "Successfully configured for red hat [dynamic libraries] with ATLASLIBS =$ATLASLIBS"
$use_cuda && linux_configure_cuda
exit_success;
}
function linux_configure_static {
if $threaded_atlas; then pt=pt; else pt=""; fi
if [ -z $ATLASLIBDIR ]; then # Note: it'll pick up the last one below.
for dir in /usr{,/local}/lib{64,}{,/atlas,/atlas-sse2,/atlas-sse3} \
/usr/local/atlas/lib{,64} `pwd`/../tools/ATLAS/build/install/lib/ $ATLASROOT/lib; do
linux_check_static && ATLASLIBDIR=$dir
done
if [ -z $ATLASLIBDIR ]; then # Note: it'll pick up the last one below.
echo "Could not find libatlas.a in any of the generic-Linux places, but we'll try other stuff..."
return 1;
fi
elif [ ! -f $ATLASLIBDIR/libatlas.a ]; then
echo "Could not find libatlas.a in '$ATLASLIBDIR'"
return 1;
fi
echo "Validating presence of ATLAS libs in $ATLASLIBDIR"
ATLASLIBS=
# The Lapack part of ATLAS seems to appear under various different names.. but it
# should always have symbols like ATL_cgetrf defined, so we test for this,
# for all the names we have encountered.
for libname in liblapack liblapack_atlas libclapack; do
if [ -f $ATLASLIBDIR/${libname}.a -a "$ATLASLIBS" == "" ]; then
if nm $ATLASLIBDIR/${libname}.a | grep ATL_cgetrf >/dev/null; then
ATLASLIBS=$ATLASLIBDIR/${libname}.a
echo "Using library $ATLASLIBS as ATLAS's CLAPACK library."
fi
fi
done
if [ "$ATLASLIBS" == "" ]; then
echo Could not find any libraries $ATLASLIBDIR/{liblapack,liblapack_atlas,libclapack} that seem to be an ATLAS CLAPACK library.
return ;
fi
for x in lib${pt}cblas.a libatlas.a lib${pt}f77blas.a; do
if [ ! -f $ATLASLIBDIR/$x ]; then
echo "Configuring static ATLAS libraries failed: Could not find library $x in directory $ATLASLIBDIR"
return 1;
fi
ATLASLIBS="$ATLASLIBS $ATLASLIBDIR/$x"
done
if $threaded_atlas; then ATLASLIBS="$ATLASLIBS"; fi
echo ATLASINC = $ATLASROOT/include >> config.mk
echo ATLASLIBS = $ATLASLIBS >> config.mk
cat makefiles/linux_atlas.mk >> config.mk
fix_cxx_flag
$use_cuda && linux_configure_cuda
linux_configure_speex
echo "Successfully configured for Linux [static libraries] with ATLASLIBS =$ATLASLIBS"
exit_success;
}
function linux_check_dynamic {
# will exit with success if $dir seems to contain ATLAS libraries with
# right architecture (compatible with default "nm")
if [ -f $dir/libatlas.so ]; then # candidate...
if nm --dynamic $dir/libatlas.so 2>&1 | grep "File format not recognized" >/dev/null; then
echo "Directory $dir may contain dynamic ATLAS libraries but seems to be wrong architecture";
return 1;
fi
echo "Atlas found in $dir";
return 0;
else
echo "... no libatlas.so in $dir";
return 1;
fi
}
function linux_configure_dynamic {
if $threaded_atlas; then pt=pt; else pt=""; fi
if [ -z $ATLASLIBDIR ]; then # Note: it'll pick up the last one below.
for dir in /usr{,/local}/lib{,64}{,/atlas,/atlas-sse2,/atlas-sse3} \
`pwd`/../tools/ATLAS/build/install/lib/ $ATLASROOT/lib; do
linux_check_dynamic && ATLASLIBDIR=$dir
done
if [ -z $ATLASLIBDIR ]; then
echo "Could not find libatlas.so in any of the obvious places, will most likely try static:"
return 1;
fi
elif [ ! -f $ATLASLIBDIR/libatlas.so ]; then
echo "Could not find libatlas.so in '$ATLASLIBDIR'"
return 1;
fi
echo "Validating presence of ATLAS libs in $ATLASLIBDIR"
ATLASLIBS=
# The Lapack part of ATLAS seems to appear under various different names.. but it
# should always have symbols like ATL_cgetrf defined, so we test for this,
# for all the names we have encountered.
for libname in lapack lapack_atlas clapack; do
if [ -f $ATLASLIBDIR/lib${libname}.so -a "$ATLASLIBS" == "" ]; then
if nm --dynamic $ATLASLIBDIR/lib${libname}.so | grep ATL_cgetrf >/dev/null; then
ATLASLIBS="$ATLASLIBDIR/lib${libname}.so"
echo "Using library $ATLASLIBS as ATLAS's CLAPACK library."
fi
fi
done
if [ "$ATLASLIBS" == "" ]; then
echo Could not find any libraries $ATLASLIBDIR/{liblapack,liblapack_atlas,libclapack} that seem to be an ATLAS CLAPACK library.
return 1;
fi
for x in ${pt}cblas atlas ${pt}f77blas; do
if [ ! -f $ATLASLIBDIR/lib$x.so ]; then
echo "Configuring dynamic ATLAS libraries failed: Could not find library $x in directory $ATLASLIBDIR"
return 1;
fi
ATLASLIBS="$ATLASLIBS $ATLASLIBDIR/lib${x}.so"
done
if $threaded_atlas; then ATLASLIBS="$ATLASLIBS"; fi
echo ATLASINC = $ATLASROOT/include >> config.mk
echo ATLASLIBS = $ATLASLIBS >> config.mk
cat makefiles/linux_atlas.mk >> config.mk
fix_cxx_flag
$use_cuda && linux_configure_cuda
linux_configure_speex
echo "Successfully configured for Linux [dynamic libraries] with ATLASLIBS =$ATLASLIBS"
exit_success;
}
echo "Configuring ..."
if [ ! -f makefiles/common.mk ]; then
failure makefiles/common.mk not found
fi
echo "Checking OpenFST library in $FSTROOT ..."
if [ ! -f $FSTROOT/include/fst/fst.h ]; then
failure "Could not find file $FSTROOT/include/fst/fst.h:
you may not have installed OpenFst. See ../tools/INSTALL"
fi
echo Checking OpenFst library was patched.
if ! grep "multiple repeated" $FSTROOT/include/fst/minimize.h >/dev/null; then
echo "** ERROR **"
echo "** $FSTROOT/include/fst/minimize.h seems not to be patched:"
echo "patch not applied? FST tools will not work in our recipe."
exit 1;
fi
# back up the old one in case we modified it
if [ -f config.mk ]; then
echo "Backing up config.mk to config.mk.bak"
cp config.mk config.mk.bak
fi
printf "# This file was generated using the following command:\n# $cmd_line\n\n" > config.mk
cat makefiles/common.mk >> config.mk
if $dynamic_kaldi ; then
KALDILIBDIR=`pwd`/lib
echo "KALDI_FLAVOR := dynamic" >> config.mk
echo "KALDILIBDIR := $KALDILIBDIR" >> config.mk
fi
echo "CONFIGURE_VERSION := $CONFIGURE_VERSION" >> config.mk
echo "FSTROOT = $FSTROOT" >> config.mk
# Check installed OpenFst version and add C++11 flags if OpenFst >= 1.4
OPENFST_VER=`grep 'PACKAGE_VERSION' $FSTROOT/Makefile | sed -e 's:.*= ::'`
echo "OPENFST_VER = $OPENFST_VER" >> config.mk
OPENFST_VER_NUM=`echo $OPENFST_VER | sed 's/\./ /g' | xargs printf "%d%02d%02d"`
if [ $OPENFST_VER_NUM -ge 10400 ]; then
echo "OPENFST_GE_10400 = 1" >> config.mk
if [ $OPENFST_VER_NUM -ge 10500 ]; then
echo "OPENFST_GE_10500 = 1" >> config.mk
echo "EXTRA_CXXFLAGS += -DHAVE_OPENFST_GE_10500 -DHAVE_OPENFST_GE_10400 -std=c++0x" >> config.mk
else
echo "EXTRA_CXXFLAGS += -DHAVE_OPENFST_GE_10400 -std=c++0x" >> config.mk
fi
else
echo "OPENFST_GE_10400 = 0" >> config.mk
fi
# Most of the OS-specific steps below will append to config.mk
echo "Doing OS specific configurations ..."
# Check for Darwin at first, because we later call uname -o (for Cygwin)
# which crashes on Darwin. Also the linear algebra libraries on Macs are
# used differently (through the Accelerate framework) than on Linux.
if [ "`uname`" == "Darwin" ]; then
$use_cuda && linux_configure_cuda
echo "On Darwin: checking for Accelerate framework ..."
if [ ! -e /System/Library/Frameworks/Accelerate.framework ]; then
failure "Need the Accelerate.framework to compile on Darwin."
fi
if [ $static_fst != false -a ! -f $FSTROOT/src/lib/libfst.a ]; then
failure "Static OpenFST library not found: See ../tools/INSTALL"
fi
# posix_memalign and gcc -rdynamic options not present on OS X 10.5.*
osx_ver=`sw_vers | grep ProductVersion | awk '{print $2}' | awk '{split($0,a,"\."); print a[1] "." a[2]; }'`
echo "Configuring for macOS version $osx_ver ..."
if [ "$osx_ver" == "10.0" ] || [ "$osx_ver" == "10.1" ] || [ "$osx_ver" == "10.2" ] || [ "$osx_ver" == "10.3" ] || [ "$osx_ver" == "10.4" ]; then
failure "macOS version must be at least 10.5"
elif [ "$osx_ver" == "10.5" ]; then
check_exists makefiles/darwin_10_5.mk
cat makefiles/darwin_10_5.mk >> config.mk
elif [ "$osx_ver" == "10.6" ]; then
check_exists makefiles/darwin_10_6.mk
cat makefiles/darwin_10_6.mk >> config.mk
elif [ "$osx_ver" == "10.7" ]; then
check_exists makefiles/darwin_10_7.mk
cat makefiles/darwin_10_7.mk >> config.mk
elif [ "$osx_ver" == "10.8" ]; then
check_exists makefiles/darwin_10_8.mk
cat makefiles/darwin_10_8.mk >> config.mk
elif [ "$osx_ver" == "10.9" ]; then
check_exists makefiles/darwin_10_9.mk
cat makefiles/darwin_10_9.mk >> config.mk
elif [ "$osx_ver" == "10.10" ]; then
check_exists makefiles/darwin_10_10.mk
cat makefiles/darwin_10_10.mk >> config.mk
elif [[ "$osx_ver" == 10.* ]]; then
check_exists makefiles/darwin_10_11.mk
cat makefiles/darwin_10_11.mk >> config.mk
else
failure "macOS version '$osx_ver' not supported"
fi
echo "Configuration succeeded for platform Darwin."
exit_success;
fi
if [ "`uname -o`" == "Cygwin" ]; then
echo "On Cygwin: checking for linear algebra libraries ..."
if [ ! -f ../tools/CLAPACK/clapack.h ]; then
failure "could not find file ../tools/CLAPACK/clapack.h"
fi
if [ ! -f /usr/lib/lapack/cygblas-0.dll ]; then
failure "please first install package liblapack0"
fi
cat makefiles/cygwin.mk >> config.mk
echo "Configuration succeeded for platform cygwin"
exit_success;
fi
if [ "`uname`" == "Linux" ]; then
if $static_fst ; then
OPENFSTLIBS="$FSTROOT/lib/libfst.a"
fst_type='a'
else
OPENFSTLIBS="-L${FSTROOT}/lib -lfst"
OPENFSTLDFLAGS="-Wl,-rpath=${FSTROOT}/lib"
fst_type='so'
fi
if [ ! -f "$FSTROOT/lib/libfst.${fst_type}" ]; then
failure "Static=[$static_fst] OpenFST library not found: See ../tools/INSTALL"
fi
echo OPENFSTLIBS = $OPENFSTLIBS >> config.mk
echo OPENFSTLDFLAGS = $OPENFSTLDFLAGS >> config.mk
echo "On Linux: Checking for linear algebra header files ..."
if [ "$MATHLIB" == "ATLAS" ]; then
if [ ! -f $ATLASROOT/include/cblas.h ] || [ ! -f $ATLASROOT/include/clapack.h ] ; then
failure "Could not find required header files cblas.h or clapack.h in ATLAS dir '$ATLASROOT/include'"
fi
echo "Using ATLAS as the linear algebra library."
# Finding out where the libraries are located:
# First we look for the static libraries and then look for dynamic ones.
# We're looking for four libraries, all in the same directory, named
# libcblas.a, libatlas.a, libf77blas.a, and a library that's variously
# named liblapack.a, libclapack.a, or liblapack_atlas.a, but which exports
# the symbol ATL_cgetrf.
# Note: there is a different type of ATLAS installation that is not
# covered. We saw a case where there was a directory called /usr/lib/atlas
# containing {liblapack.a,libblas.a}, and linking against just these two
# libraries worked.
if $static_math; then
# Prefer static to dynamic math.
linux_configure_static || \
linux_configure_dynamic || \
linux_configure_debian_ubuntu 64 || \
linux_configure_debian_ubuntu || \
linux_configure_debian7 || \
linux_configure_redhat 64 || \
linux_configure_redhat || \
linux_atlas_failure "Failed to configure ATLAS libraries";
else
# Prefer dynamic to static math.
linux_configure_dynamic || \
linux_configure_static || \
linux_configure_debian_ubuntu 64 || \
linux_configure_debian_ubuntu || \
linux_configure_debian7 || \
linux_configure_redhat 64 || \
linux_configure_redhat || \
linux_atlas_failure "Failed to configure ATLAS libraries";
fi
elif [ "$MATHLIB" == "MKL" ]; then
if [ "`uname -m`" != "x86_64" ]; then
failure "MKL on Linux only supported for Intel(R) 64 architecture (x86_64).
See makefiles/linux_64_mkl.mk to manually configure for other platforms."
fi
if is_set "$MKLROOT" -a ! is_set "$MKLLIBDIR"; then
echo -n "Configuring MKL library directory: "
MKLLIBDIR=`linux_configure_mkllibdir $MKLROOT`
if [ $? -ne 0 ]; then
failure "MKL libraries could not be found. Please use the switch --mkl-libdir "
else
echo "Found: $MKLLIBDIR"
fi
fi
MKL_LINK_LINE=`linux_configure_mkl_libraries "$MKLLIBDIR" $static_math $threaded_math` || exit 1
MKL_COMPILE_LINE=`linux_configure_mkl_includes "$MKLROOT" "$MKLLIBDIR"` || exit 1
echo "MKL include directory configured as: $MKL_COMPILE_LINE"
MKL_COMPILE_LINE=" -I${MKL_COMPILE_LINE} "
if ! is_set $OMPLIBDIR ; then
if $static_math ; then
OMPLIBDIR=`linux_configure_omplibdir "$MKLROOT" "$MKLLIBDIR" "a"`
else
OMPLIBDIR=`linux_configure_omplibdir "$MKLROOT" "$MKLLIBDIR" "so"`
fi
fi
check_library $OMPLIBDIR "libiomp5" "a" || check_library $OMPLIBDIR "libiomp5" "so" \
|| failure "Could not find the iomp5 library, have your tried the --omp-libdir switch?"
echo "OMP library directory configured as: $OMPLIBDIR"
OMP_LINK_LINE=''
# TODO(arnab): in the following conditional, the $static_math test is
# needed since the OpenMP library is assumed to be dynamic.
if [ "$OMPLIBDIR" != "$MKLLIBDIR" ] ; then
OMP_LINK_LINE="-L${OMPLIBDIR}"
#if the libiomp5 library is dynamic, we add the rpath attribute
if ! $static_math ; then
OMP_LINK_LINE="$OMP_LINK_LINE -Wl,-rpath=$OMPLIBDIR"
else
OMP_LINK_LINE="$OMP_LINK_LINE -Wl,-Bstatic -liomp5 -Wl,-Bdynamic"
fi
fi
echo "Using Intel MKL as the linear algebra library."
echo MKLROOT = $MKLROOT >> config.mk
if [ ! -z $MKLLIBDIR ]; then
echo MKLLIB = $MKLLIBDIR >> config.mk
fi
check_exists makefiles/linux_x86_64_mkl.mk
cat makefiles/linux_x86_64_mkl.mk >> config.mk
fix_cxx_flag
echo "MKLFLAGS = ${MKL_LINK_LINE} ${OMP_LINK_LINE} " >> config.mk
$use_cuda && linux_configure_cuda
linux_configure_speex
echo "Successfully configured for Linux with MKL libs from $MKLROOT"
exit_success;
elif [ "$MATHLIB" == "CLAPACK" ]; then
if [ -z "$CLAPACKROOT" ]; then
failure "Must specify the location of CLAPACK with --clapack-root option (and it must exist)"
fi
if [ ! -f ../tools/CLAPACK/clapack.h ]; then
failure could not find file ../tools/CLAPACK/clapack.h
fi
if [ ! -d "$CLAPACKROOT" ]; then
failure "The directory $CLAPACKROOT does not exist"
fi
# Also check for cblas.h and f2c.h
echo "Using CLAPACK as the linear algebra library."
if [ ! -f makefiles/linux_clapack.mk ]; then
failure "makefiles/linux_clapack.mk not found."
fi
cat makefiles/linux_clapack.mk >> config.mk
fix_cxx_flag
echo "Warning (CLAPACK): this part of the configure process is not properly tested and will not work."
$use_cuda && linux_configure_cuda
linux_configure_speex
echo "Successfully configured for Linux with CLAPACK libs from $CLAPACKROOT"
exit_success;
elif [ "$MATHLIB" == "OPENBLAS" ]; then
OPENBLASROOT=`rel2abs "$OPENBLASROOT"`
if [ -z "$OPENBLASROOT" ]; then
failure "Must specify the location of OPENBLAS with --openblas-root option (and it must exist)"
fi
if [ ! -f $OPENBLASROOT/lib/libopenblas.so ]; then
failure "Expected to find the file $OPENBLASROOT/lib/libopenblas.so"
fi
echo "Your math library seems to be OpenBLAS. Configuring appropriately."
if $static_math; then
echo "Configuring static OpenBlas since --static-math=yes"
OPENBLASLIBS="$OPENBLASROOT/lib/libopenblas.a -lgfortran"
else
echo "Configuring dynamically loaded OpenBlas since --static-math=no (the default)"
OPENBLASLIBS="-L$OPENBLASROOT/lib -lopenblas -lgfortran -Wl,-rpath=$OPENBLASROOT/lib"
fi
echo "OPENBLASLIBS = $OPENBLASLIBS" >> config.mk
echo "OPENBLASROOT = $OPENBLASROOT" >> config.mk
cat makefiles/linux_openblas.mk >> config.mk
fix_cxx_flag
$use_cuda && linux_configure_cuda
linux_configure_speex
echo "Successfully configured OpenBLAS from $OPENBLASROOT."
exit_success;
else
failure "Unsupported linear algebra library '$MATHLIB'"
fi
fi
failure Could not detect platform or we have not yet worked out the appropriate configuration for this platform. Please contact the developers.