forked from kaldi-asr/kaldi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default_rules.mk
122 lines (103 loc) · 3.48 KB
/
default_rules.mk
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
SHELL := /bin/bash
ifeq ($(KALDI_FLAVOR), dynamic)
ifeq ($(shell uname), Darwin)
ifdef LIBNAME
LIBFILE = lib$(LIBNAME).dylib
endif
LDFLAGS += -Wl,-rpath -Wl,$(KALDILIBDIR)
EXTRA_LDLIBS += $(foreach dep,$(ADDLIBS), $(dir $(dep))lib$(notdir $(basename $(dep))).dylib)
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)
$(LIBFILE): $(OBJFILES)
$(AR) -cr $(LIBNAME).a $(OBJFILES)
$(RANLIB) $(LIBNAME).a
ifeq ($(KALDI_FLAVOR), dynamic)
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
# 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
depend:
-$(CXX) -M $(CXXFLAGS) *.cc > .depend.mk
# removing automatic making of "depend" as it's quite slow.
#.depend.mk: depend
-include .depend.mk