[build] Cosmetic fix in Makefile
[processor-sdk/kaldi.git] / src / makefiles / default_rules.mk
2 SHELL := /bin/bash
4 ifeq ($(KALDI_FLAVOR), dynamic)
5   ifeq ($(shell uname), Darwin)
6     ifdef LIBNAME
7       LIBFILE = lib$(LIBNAME).dylib
8     endif
9     LDFLAGS += -Wl,-rpath -Wl,$(KALDILIBDIR)
10     EXTRA_LDLIBS += $(foreach dep,$(ADDLIBS), $(dir $(dep))lib$(notdir $(basename $(dep))).dylib)
11   else ifeq ($(shell uname), Linux)
12     ifdef LIBNAME
13       LIBFILE = lib$(LIBNAME).so
14     endif
15     LDFLAGS += -Wl,-rpath=$(shell readlink -f $(KALDILIBDIR))
16     EXTRA_LDLIBS += $(foreach dep,$(ADDLIBS), $(dir $(dep))lib$(notdir $(basename $(dep))).so)
17   else  # Platform not supported
18     $(error Dynamic libraries not supported on this platform. Run configure with --static flag.)
19   endif
20   XDEPENDS =
21 else
22   ifdef LIBNAME
23     LIBFILE = $(LIBNAME).a
24   endif
25   XDEPENDS = $(ADDLIBS)
26 endif
28 all: $(LIBFILE) $(BINFILES)
30 $(LIBFILE): $(OBJFILES)
31         $(AR) -cru $(LIBNAME).a $(OBJFILES)
32         $(RANLIB) $(LIBNAME).a
33 ifeq ($(KALDI_FLAVOR), dynamic)
34   ifeq ($(shell uname), Darwin)
35         $(CXX) -dynamiclib -o $@ -install_name @rpath/$@ $(LDFLAGS) $(OBJFILES) $(LDLIBS)
36         rm -f $(KALDILIBDIR)/$@; ln -s $(shell pwd)/$@ $(KALDILIBDIR)/$@
37   else ifeq ($(shell uname), Linux)
38         # Building shared library from static (static was compiled with -fPIC)
39         $(CXX) -shared -o $@ -Wl,--no-undefined -Wl,--as-needed  -Wl,-soname=$@,--whole-archive $(LIBNAME).a -Wl,--no-whole-archive $(LDFLAGS) $(LDLIBS)
40         rm -f $(KALDILIBDIR)/$@; ln -s $(shell pwd)/$@ $(KALDILIBDIR)/$@
41   else  # Platform not supported
42         $(error Dynamic libraries not supported on this platform. Run configure with --static flag.)
43   endif
44 endif
46 # By default (GNU) make uses the C compiler $(CC) for linking object files even
47 # if they were compiled from a C++ source. Below redefinition forces make to
48 # use the C++ compiler $(CXX) instead.
49 LINK.o = $(CXX) $(LDFLAGS) $(TARGET_ARCH)
51 $(BINFILES): $(LIBFILE) $(XDEPENDS)
53 # When building under CI, CI_NOLINKBINARIES is set to skip linking of binaries.
54 ifdef CI_NOLINKBINARIES
55 $(BINFILES): %: %.o
56         touch $@
57 endif
59 # Rule below would expand to, e.g.:
60 # ../base/kaldi-base.a:
61 #       make -C ../base kaldi-base.a
62 # -C option to make is same as changing directory.
63 %.a:
64         $(MAKE) -C ${@D} ${@F}
66 %.so:
67         $(MAKE) -C ${@D} ${@F}
69 clean:
70         -rm -f *.o *.a *.so $(TESTFILES) $(BINFILES) $(TESTOUTPUTS) tmp* *.tmp *.testlog
72 distclean: clean
73         -rm -f .depend.mk
75 $(TESTFILES): $(LIBFILE) $(XDEPENDS)
77 test_compile: $(TESTFILES)
79 test: test_compile
80         @{ result=0;                    \
81         for x in $(TESTFILES); do       \
82           printf "Running $$x ...";     \
83       timestamp1=$$(date +"%s"); \
84           ./$$x >$$x.testlog 2>&1;      \
85       ret=$$? \
86       timestamp2=$$(date +"%s"); \
87       time_taken=$$[timestamp2-timestamp1]; \
88           if [ $$ret -ne 0 ]; then \
89             echo " $${time_taken}s... FAIL $$x"; \
90             result=1;                   \
91             if [ -n "$TRAVIS" ] && [ -f core ] && command -v gdb >/dev/null 2>&1; then  \
92               gdb $$x core -ex "thread apply all bt" -batch >>$$x.testlog 2>&1;         \
93               rm -rf core;              \
94             fi;                         \
95           else                          \
96             echo " $${time_taken}s... SUCCESS $$x";             \
97             rm -f $$x.testlog;          \
98           fi;                           \
99         done;                           \
100         exit $$result; }
102 # Rules that enable valgrind debugging ("make valgrind")
104 valgrind: .valgrind
106 .valgrind: $(TESTFILES)
107         echo -n > valgrind.out
108         for x in $(TESTFILES); do \
109                 echo $$x >>valgrind.out; \
110                 valgrind ./$$x >/dev/null 2>> valgrind.out; \
111         done
112         ! ( grep 'ERROR SUMMARY' valgrind.out | grep -v '0 errors' )
113         ! ( grep 'definitely lost' valgrind.out | grep -v -w 0 )
114         rm valgrind.out
115         touch .valgrind
117 depend:
118         -$(CXX) -M $(CXXFLAGS) *.cc > .depend.mk
120 # removing automatic making of "depend" as it's quite slow.
121 #.depend.mk: depend
122 -include .depend.mk