]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/kaldi.git/blob - src/Makefile
[build] Change to compilation flags for Sequitur on Mac (#1716)
[processor-sdk/kaldi.git] / src / Makefile
1 # This is the top-level Makefile for Kaldi.
2 # Also see kaldi.mk which supplies options and some rules
3 # used by the Makefiles in the subdirectories.
5 SHELL := /bin/bash
8 SUBDIRS = base matrix util feat tree gmm transform \
9           fstext hmm lm decoder lat kws cudamatrix nnet \
10           bin fstbin gmmbin fgmmbin featbin \
11           nnetbin latbin sgmm2 sgmm2bin nnet2 nnet3 chain nnet3bin nnet2bin kwsbin \
12           ivector ivectorbin online2 online2bin lmbin chainbin
14 MEMTESTDIRS = base matrix util feat tree gmm transform \
15           fstext hmm lm decoder lat nnet kws chain \
16           bin fstbin gmmbin fgmmbin featbin \
17           nnetbin latbin sgmm2 nnet2 nnet3 nnet2bin nnet3bin sgmm2bin kwsbin \
18           ivector ivectorbin online2 online2bin lmbin
20 CUDAMEMTESTDIR = cudamatrix
22 SUBDIRS_LIB = $(filter-out %bin, $(SUBDIRS))
24 KALDI_SONAME ?= libkaldi.so
26 # Optional subdirectories
27 EXT_SUBDIRS = online onlinebin  # python-kaldi-decoding
28 EXT_SUBDIRS_LIB = $(filter-out %bin, $(EXT_SUBDIRS))
30 include kaldi.mk
32 # Reset the default goal, so that the all target will become default
33 .DEFAULT_GOAL :=
34 all:
35         $(MAKE) checkversion
36         $(MAKE) kaldi.mk
37         $(MAKE) mklibdir
38         $(MAKE) subdirs
39         -echo Done
41 subdirs: $(SUBDIRS)
43 mklibdir:
44         test -d $(KALDILIBDIR) || mkdir $(KALDILIBDIR)
46 #I don't want to call rm -rf
47 rmlibdir:
48 ifneq ($(KALDILIBDIR), )
49         -rm $(KALDILIBDIR)/*{.so,.a,.o}
50         -rmdir $(KALDILIBDIR)
51 else
52         @true
53 endif
55 .PHONY: checkversion
56 checkversion:
57 ifeq ($(shell ./configure --version),$(CONFIGURE_VERSION))
58         @echo "The version of configure script matches kaldi.mk version. Good."
59 else
60         @echo ""
61         @echo "The kaldi.mk file was generated using a different version of configure script. Please rerun the configure again"
62         @test -f ./kaldi.mk && echo  "Hint: Previous configure command line: " && head -n 2 ./kaldi.mk | grep configure | sed 's/^# *//g'
63         @echo ""
64         @false
65 endif
67 biglib: $(SUBDIRS_LIB)
68 ifeq ($(KALDI_FLAVOR), dynamic)
69 ifeq ($(shell uname), Darwin)
70         $(CXX) -dynamiclib -o $(KALDILIBDIR)/libkaldi.dylib -install_name @rpath/libkaldi.dylib -framework Accelerate $(LDFLAGS) $(SUBDIRS_LIB:=/*.dylib)
71 else
72 ifeq ($(shell uname), Linux)
73         #$(warning the following command will probably fail, in that case add -fPIC to your CXXFLAGS and remake all)
74         $(CXX) -shared -o $(KALDILIBDIR)/$(KALDI_SONAME) -Wl,-soname=$(KALDI_SONAME),--whole-archive  $(SUBDIRS_LIB:=/kaldi-*.a) $(LDLIBS) -Wl,--no-whole-archive
75 else
76         $(error Dynamic libraries not supported on this platform. Run configure with --static flag. )
77 endif
78 endif
79 endif
81 biglibext: $(EXT_SUBDIRS_LIB)
82 ifeq ($(KALDI_FLAVOR), dynamic)
83 ifeq ($(shell uname), Darwin)
84         $(CXX) -dynamiclib -o $(KALDILIBDIR)/libkaldi_ext.dylib -install_name @rpath/libkaldi_ext.dylib -framework Accelerate $(LDFLAGS) $(EXT_SUBDIRS_LIB:=/*.dylib)
85 else
86 ifeq ($(shell uname), Linux)
87         #$(warning The following command will probably fail, in that case add -fPIC to your CXXFLAGS and remake all.)
88         $(CXX) -shared -o $(KALDILIBDIR)/libkaldi_ext.so -Wl,-soname=libkaldi_ext.so,--whole-archive  $(EXT_SUBDIRS_LIB:=/kaldi-*.a) -Wl,--no-whole-archive
89 else
90         $(error Dynamic libraries not supported on this platform. Run configure with --static flag. )
91 endif
92 endif
93 endif
95 kaldi.mk:
96         @[ -f kaldi.mk ] || { echo "kaldi.mk does not exist; you have to run ./configure"; exit 1; }
98 # Compile optional stuff
99 ext: ext_depend $(SUBDIRS) $(EXT_SUBDIRS)
100         -echo Done
102 check_portaudio:
103         @[ -d ../tools/portaudio ] || ( cd ../tools;  ./install_portaudio.sh )
105 clean: rmlibdir
106         -for x in $(SUBDIRS) $(EXT_SUBDIRS); do $(MAKE) -C $$x clean; done
108 distclean: clean
109         -for x in $(SUBDIRS) $(EXT_SUBDIRS); do $(MAKE) -C $$x distclean; done
111 test: $(addsuffix /test, $(SUBDIRS_LIB))
113 ext_test: $(addsuffix /test, $(EXT_SUBDIRS_LIB))
115 # Define an implicit rule, expands to e.g.:
116 #  base/test: base
117 #     $(MAKE) -C base test
118 %/test: % mklibdir
119         $(MAKE) -C $< test
121 cudavalgrind:
122         -for x in $(CUDAMEMTESTDIR); do $(MAKE) -C $$x valgrind || { echo "valgrind on $$x failed"; exit 1; }; done
124 valgrind:
125         -for x in $(MEMTESTDIRS); do $(MAKE) -C $$x valgrind || { echo "valgrind on $$x failed"; exit 1; }; done
127 base/.depend.mk:
128         $(MAKE) depend
130 depend: $(addsuffix /depend, $(SUBDIRS))
132 %/depend:
133         $(MAKE) -C $(dir $@) depend
136 ext_depend: check_portaudio
137         -for x in $(EXT_SUBDIRS); do $(MAKE) -C $$x depend; done
140 .PHONY: $(SUBDIRS)
141 $(SUBDIRS) : mklibdir
142         $(MAKE) -C $@
144 .PHONY: $(EXT_SUBDIRS)
145 $(EXT_SUBDIRS) : mklibdir ext_depend
146         $(MAKE) -C $@
149 ### Dependency list ###
150 # this is necessary for correct parallel compilation
151 #1)The tools depend on all the libraries
152 bin fstbin gmmbin fgmmbin sgmm2bin featbin nnetbin nnet2bin nnet3bin chainbin latbin ivectorbin lmbin kwsbin online2bin: \
153  base matrix util feat tree gmm transform sgmm2 fstext hmm \
154  lm decoder lat cudamatrix nnet nnet2 nnet3 ivector chain kws online2
156 #2)The libraries have inter-dependencies
157 base: base/.depend.mk
158 matrix: base
159 util: base matrix
160 feat: base matrix util gmm transform tree
161 tree: base util matrix
162 gmm: base util matrix tree
163 transform: base util matrix gmm tree
164 sgmm2: base util matrix gmm tree transform hmm
165 fstext: base util matrix tree
166 hmm: base tree matrix util
167 lm: base util matrix fstext
168 decoder: base util matrix gmm hmm tree transform lat
169 lat: base util hmm tree matrix
170 cudamatrix: base util matrix
171 nnet: base util hmm tree matrix cudamatrix
172 nnet2: base util matrix lat gmm hmm tree transform cudamatrix
173 nnet3: base util matrix lat gmm hmm tree transform cudamatrix chain fstext
174 chain: lat hmm tree fstext matrix cudamatrix util base
175 ivector: base util matrix transform tree gmm
176 #3)Dependencies for optional parts of Kaldi
177 onlinebin: base matrix util feat tree gmm transform sgmm2 fstext hmm lm decoder lat cudamatrix nnet nnet2 online
178 # python-kaldi-decoding: base matrix util feat tree gmm transform sgmm2 fstext hmm decoder lat online
179 online: decoder gmm transform feat matrix util base lat hmm tree
180 online2: decoder gmm transform feat matrix util base lat hmm tree ivector cudamatrix nnet2 nnet3 chain
181 kws: base util hmm tree matrix lat