This repository has been archived by the owner on Apr 16, 2024. It is now read-only.
forked from kaldi-asr/kaldi
-
Notifications
You must be signed in to change notification settings - Fork 65
/
Makefile
184 lines (145 loc) · 6.54 KB
/
Makefile
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
# This is the top-level Makefile for Kaldi.
# Also see kaldi.mk which supplies options and some rules
# used by the Makefiles in the subdirectories.
SHELL := /bin/bash
SUBDIRS = base matrix util feat tree thread gmm transform sgmm \
fstext hmm lm decoder lat kws cudamatrix nnet \
bin fstbin gmmbin fgmmbin sgmmbin featbin \
nnetbin latbin sgmm2 sgmm2bin nnet2 nnet3 chain ctc nnet3bin nnet2bin kwsbin \
ivector ivectorbin online2 online2bin lmbin chainbin ctcbin
MEMTESTDIRS = base matrix util feat tree thread gmm transform sgmm \
fstext hmm lm decoder lat nnet kws chain ctc \
bin fstbin gmmbin fgmmbin sgmmbin featbin \
nnetbin latbin sgmm2 nnet2 nnet3 nnet2bin nnet3bin sgmm2bin kwsbin \
ivector ivectorbin online2 online2bin lmbin
CUDAMEMTESTDIR = cudamatrix
SUBDIRS_LIB = $(filter-out %bin, $(SUBDIRS))
KALDI_SONAME ?= libkaldi.so
# Optional subdirectories
EXT_SUBDIRS = online onlinebin # python-kaldi-decoding
EXT_SUBDIRS_LIB = $(filter-out %bin, $(EXT_SUBDIRS))
include kaldi.mk
# Reset the default goal, so that the all target will become default
.DEFAULT_GOAL :=
all: checkversion test_dependencies kaldi.mk mklibdir $(SUBDIRS)
-echo Done
mklibdir:
test -d $(KALDILIBDIR) || mkdir $(KALDILIBDIR)
#I don't want to call rm -rf
rmlibdir:
ifneq ($(KALDILIBDIR), )
-rm $(KALDILIBDIR)/*{.so,.a,.o}
-rmdir $(KALDILIBDIR)
else
@true
endif
.PHONY: checkversion
checkversion:
ifeq ($(shell ./configure --version),$(CONFIGURE_VERSION))
@echo "The version of configure script matches kaldi.mk version. Good."
else
@echo "The kaldi.mk file was generated using a different version of configure script. Please rerun the configure again"
@test -f ./kaldi.mk && echo "Hint: Previous configure command line: " && head -n 2 ./kaldi.mk | grep configure | sed 's/^# *//g'
@false
endif
biglib: $(SUBDIRS_LIB)
ifeq ($(KALDI_FLAVOR), dynamic)
ifeq ($(shell uname), Darwin)
$(CXX) -dynamiclib -o $(KALDILIBDIR)/libkaldi.dylib -install_name @rpath/libkaldi.dylib -framework Accelerate $(LDFLAGS) $(SUBDIRS_LIB:=/*.dylib)
else
ifeq ($(shell uname), Linux)
#$(warning the following command will probably fail, in that case add -fPIC to your CXXFLAGS and remake all)
$(CXX) -shared -o $(KALDILIBDIR)/$(KALDI_SONAME) -Wl,-soname=$(KALDI_SONAME),--whole-archive $(SUBDIRS_LIB:=/kaldi-*.a) $(LDLIBS) -Wl,--no-whole-archive
else
$(error Dynamic libraries not supported on this platform. Run configure with --static flag. )
endif
endif
endif
biglibext: $(EXT_SUBDIRS_LIB)
ifeq ($(KALDI_FLAVOR), dynamic)
ifeq ($(shell uname), Darwin)
$(CXX) -dynamiclib -o $(KALDILIBDIR)/libkaldi_ext.dylib -install_name @rpath/libkaldi_ext.dylib -framework Accelerate $(LDFLAGS) $(EXT_SUBDIRS_LIB:=/*.dylib)
else
ifeq ($(shell uname), Linux)
#$(warning The following command will probably fail, in that case add -fPIC to your CXXFLAGS and remake all.)
$(CXX) -shared -o $(KALDILIBDIR)/libkaldi_ext.so -Wl,-soname=libkaldi_ext.so,--whole-archive $(EXT_SUBDIRS_LIB:=/kaldi-*.a) -Wl,--no-whole-archive
else
$(error Dynamic libraries not supported on this platform. Run configure with --static flag. )
endif
endif
endif
kaldi.mk:
@[ -f kaldi.mk ] || { echo "kaldi.mk does not exist; you have to run ./configure"; exit 1; }
# Compile optional stuff
ext: test_dependencies ext_depend $(SUBDIRS) $(EXT_SUBDIRS)
-echo Done
ifndef OPENFST_VER
$(error Please rerun configure: OPENFST_VER is not defined, likely kaldi.mk was produced by older configure script.)
endif
# Note: OPENFST_VER is determined by configure and added to kaldi.mk
OPENFST_VER_NUM := $(shell echo $(OPENFST_VER) | sed 's/\./ /g' | xargs printf "%d%02d%02d")
test_dependencies:
ifeq ("$(shell expr $(OPENFST_VER_NUM) \< 10302)","1")
$(error OpenFst $(OPENFST_VER) is not supported. You now need OpenFst >= 1.3.2.)
endif
check_portaudio:
@[ -d ../tools/portaudio ] || ( cd ../tools; ./install_portaudio.sh )
clean: rmlibdir
-for x in $(SUBDIRS) $(EXT_SUBDIRS); do $(MAKE) -C $$x clean; done
test: $(addsuffix /test, $(SUBDIRS))
ext_test: $(addsuffix /test, $(EXT_SUBDIRS))
# Define an implicit rule, expands to e.g.:
# base/test: base
# $(MAKE) -C base test
%/test: % mklibdir
$(MAKE) -C $< test
cudavalgrind:
-for x in $(CUDAMEMTESTDIR); do $(MAKE) -C $$x valgrind || { echo "valgrind on $$x failed"; exit 1; }; done
valgrind:
-for x in $(MEMTESTDIRS); do $(MAKE) -C $$x valgrind || { echo "valgrind on $$x failed"; exit 1; }; done
depend: $(addsuffix /depend, $(SUBDIRS))
%/depend:
$(MAKE) -C $(dir $@) depend
ext_depend: check_portaudio
-for x in $(EXT_SUBDIRS); do $(MAKE) -C $$x depend; done
.PHONY: $(SUBDIRS)
$(SUBDIRS) : mklibdir
$(MAKE) -C $@
.PHONY: $(EXT_SUBDIRS)
$(EXT_SUBDIRS) : mklibdir
$(MAKE) -C $@
### Dependency list ###
# this is necessary for correct parallel compilation
#1)The tools depend on all the libraries
bin fstbin gmmbin fgmmbin sgmmbin sgmm2bin featbin nnetbin nnet2bin nnet3bin chainbin ctcbin latbin ivectorbin lmbin kwsbin online2bin: \
base matrix util feat tree thread gmm transform sgmm sgmm2 fstext hmm \
lm decoder lat cudamatrix nnet nnet2 nnet3 ivector chain ctc kws online2
#2)The libraries have inter-dependencies
base:
matrix: base
thread: base
util: base matrix thread
feat: base matrix util gmm transform tree thread
tree: base util thread matrix
gmm: base util matrix tree thread
transform: base util matrix gmm tree thread
sgmm: base util matrix gmm tree transform thread hmm
sgmm2: base util matrix gmm tree transform thread hmm
fstext: base util thread matrix tree
hmm: base tree matrix util thread
lm: base util thread matrix fstext
decoder: base util thread matrix gmm sgmm hmm tree transform lat
lat: base util thread hmm tree matrix
cudamatrix: base util thread matrix
nnet: base util hmm tree thread matrix cudamatrix
nnet2: base util matrix thread lat gmm hmm tree transform cudamatrix
nnet3: base util matrix thread lat gmm hmm tree transform cudamatrix chain fstext
chain: lat hmm tree fstext matrix cudamatrix util thread base
ctc: nnet2 lat hmm tree fstext matrix cudamatrix util thread base
ivector: base util matrix thread transform tree gmm
#3)Dependencies for optional parts of Kaldi
onlinebin: base matrix util feat tree gmm transform sgmm sgmm2 fstext hmm lm decoder lat cudamatrix nnet nnet2 online thread
# python-kaldi-decoding: base matrix util feat tree thread gmm transform sgmm sgmm2 fstext hmm decoder lat online
online: decoder gmm transform feat matrix util base lat hmm thread tree
online2: decoder gmm transform feat matrix util base lat hmm thread tree ivector cudamatrix nnet2 nnet3 chain
kws: base util thread hmm tree matrix lat