default_rules.mk
4.42 KB
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
SHELL := /bin/bash
ifeq ($(KALDI_FLAVOR), dynamic)
ifeq ($(shell uname), Darwin)
ifdef ANDROIDINC # cross-compiling enabled on host MacOS
ifdef LIBNAME
LIBFILE = lib$(LIBNAME).so
endif
LDFLAGS += -Wl,-rpath -Wl,$(KALDILIBDIR)
EXTRA_LDLIBS += $(foreach dep,$(ADDLIBS), $(dir $(dep))$(notdir $(basename $(dep))).a)
else
ifdef LIBNAME
LIBFILE = lib$(LIBNAME).dylib
endif
LDFLAGS += -Wl,-rpath -Wl,$(KALDILIBDIR)
EXTRA_LDLIBS += $(foreach dep,$(ADDLIBS), $(dir $(dep))lib$(notdir $(basename $(dep))).dylib)
endif
else ifeq ($(shell uname), Linux)
ifdef LIBNAME
LIBFILE = lib$(LIBNAME).so
endif
LDFLAGS += -Wl,-rpath=$(shell readlink -f $(KALDILIBDIR))
EXTRA_LDLIBS += $(foreach dep,$(ADDLIBS), $(dir $(dep))lib$(notdir $(basename $(dep))).so)
else # Platform not supported
$(error Dynamic libraries not supported on this platform. Run configure with --static flag.)
endif
XDEPENDS =
else
ifdef LIBNAME
LIBFILE = $(LIBNAME).a
endif
XDEPENDS = $(ADDLIBS)
endif
all: $(LIBFILE) $(BINFILES)
ifdef LIBNAME
$(LIBNAME).a: $(OBJFILES)
$(AR) -cr $(LIBNAME).a $(OBJFILES)
$(RANLIB) $(LIBNAME).a
ifeq ($(KALDI_FLAVOR), dynamic)
# the LIBFILE is not the same as $(LIBNAME).a
$(LIBFILE): $(LIBNAME).a
ifeq ($(shell uname), Darwin)
$(CXX) -dynamiclib -o $@ -install_name @rpath/$@ $(LDFLAGS) $(OBJFILES) $(LDLIBS)
ln -sf $(shell pwd)/$@ $(KALDILIBDIR)/$@
else ifeq ($(shell uname), Linux)
# Building shared library from static (static was compiled with -fPIC)
$(CXX) -shared -o $@ -Wl,--no-undefined -Wl,--as-needed -Wl,-soname=$@,--whole-archive $(LIBNAME).a -Wl,--no-whole-archive $(LDFLAGS) $(LDLIBS)
ln -sf $(shell pwd)/$@ $(KALDILIBDIR)/$@
else # Platform not supported
$(error Dynamic libraries not supported on this platform. Run configure with --static flag.)
endif
endif # ifeq ($(KALDI_FLAVOR), dynamic)
endif # ifdef LIBNAME
# By default (GNU) make uses the C compiler $(CC) for linking object files even
# if they were compiled from a C++ source. Below redefinition forces make to
# use the C++ compiler $(CXX) instead.
LINK.o = $(CXX) $(LDFLAGS) $(TARGET_ARCH)
$(BINFILES): $(LIBFILE) $(XDEPENDS)
# When building under CI, CI_NOLINKBINARIES is set to skip linking of binaries.
ifdef CI_NOLINKBINARIES
$(BINFILES): %: %.o
touch $@
endif
# Rule below would expand to, e.g.:
# ../base/kaldi-base.a:
# make -C ../base kaldi-base.a
# -C option to make is same as changing directory.
%.a:
$(MAKE) -C ${@D} ${@F}
%.so:
$(MAKE) -C ${@D} ${@F}
clean:
-rm -f *.o *.a *.so $(TESTFILES) $(BINFILES) $(TESTOUTPUTS) tmp* *.tmp *.testlog
distclean: clean
-rm -f .depend.mk
$(TESTFILES): $(LIBFILE) $(XDEPENDS)
test_compile: $(TESTFILES)
test: test_compile
@{ result=0; \
for x in $(TESTFILES); do \
printf "Running $$x ..."; \
timestamp1=$$(date +"%s"); \
./$$x >$$x.testlog 2>&1; \
ret=$$? \
timestamp2=$$(date +"%s"); \
time_taken=$$[timestamp2-timestamp1]; \
if [ $$ret -ne 0 ]; then \
echo " $${time_taken}s... FAIL $$x"; \
result=1; \
if [ -n "$TRAVIS" ] && [ -f core ] && command -v gdb >/dev/null 2>&1; then \
gdb $$x core -ex "thread apply all bt" -batch >>$$x.testlog 2>&1; \
rm -rf core; \
fi; \
else \
echo " $${time_taken}s... SUCCESS $$x"; \
rm -f $$x.testlog; \
fi; \
done; \
exit $$result; }
# Rules that enable valgrind debugging ("make valgrind")
valgrind: .valgrind
.valgrind: $(TESTFILES)
echo -n > valgrind.out
for x in $(TESTFILES); do \
echo $$x >>valgrind.out; \
valgrind ./$$x >/dev/null 2>> valgrind.out; \
done
! ( grep 'ERROR SUMMARY' valgrind.out | grep -v '0 errors' )
! ( grep 'definitely lost' valgrind.out | grep -v -w 0 )
rm valgrind.out
touch .valgrind
#buid up dependency commands
CC_SRCS=$(wildcard *.cc)
#check if files exist to run dependency commands on
ifneq ($(CC_SRCS),)
CC_DEP_COMMAND=$(CXX) -M $(CXXFLAGS) $(CC_SRCS)
endif
ifeq ($(CUDA), true)
CUDA_SRCS=$(wildcard *.cu)
#check if files exist to run dependency commands on
ifneq ($(CUDA_SRCS),)
NVCC_DEP_COMMAND = $(CUDATKDIR)/bin/nvcc -M $(CUDA_FLAGS) $(CUDA_INCLUDE) $(CUDA_SRCS)
endif
endif
depend:
rm -f .depend.mk
ifneq ($(CC_DEP_COMMAND),)
$(CC_DEP_COMMAND) >> .depend.mk
endif
ifneq ($(NVCC_DEP_COMMAND),)
$(NVCC_DEP_COMMAND) >> .depend.mk
endif
# removing automatic making of "depend" as it's quite slow.
#.depend.mk: depend
-include .depend.mk