Merge branch 'maint'
[platform/upstream/automake.git] / t / cscope.tap
1 #! /bin/sh
2 # Copyright (C) 2009-2012 Free Software Foundation, Inc.
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
7 # any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 # Test cscope functionality.
18
19 . ./defs || Exit 1
20
21 plan_ 18
22
23 ocwd=`pwd` || fatal_ "getting top-level directory"
24
25 cat >> configure.ac << 'END'
26 AC_CONFIG_FILES([sub/Makefile])
27 AC_SUBST([CC],  [who-cares])
28 AC_SUBST([CXX], [who-cares])
29 AC_SUBST([FC],  [who-cares])
30 AC_SUBST([GCJ], [who-cares])
31 AM_PATH_LISPDIR
32 AC_OUTPUT
33 END
34
35 mkdir sub sub/subsub
36
37 cat > Makefile.am <<'END'
38 SUBDIRS = sub
39 bin_PROGRAMS = foo
40 foo_SOURCES = foo.c bar.cpp baz.f90
41 lisp_LISP = foo.el
42 EXTRA_DIST = foo.el
43 END
44
45 cat > sub/Makefile.am <<'END'
46 bin_PROGRAMS = bar
47 bar_SOURCES = subsub/dist.c
48 nodist_bar_SOURCES = subsub/gen.c
49 subsub/gen.c:
50         $(MKDIR_P) subsub
51         echo 'int generated_subsub () { return 0; }' > $@
52 CLEANFILES = subsub/gen.c
53 END
54
55 echo 'int foo_func () { return 0; }' > foo.c
56 echo 'int main () { return 0; }' > bar.cpp
57 cat > baz.f90 <<'END'
58       subroutine baz
59       end
60 END
61 : > foo.el
62 echo 'int main () { return 0; }' > sub/subsub/dist.c
63
64 $ACLOCAL || fatal_ "aclocal failed"
65 $AUTOCONF || fatal_ "autoconf failed"
66 $AUTOMAKE -i -a || fatal_ "automake -i -a failed"
67
68 # Sun cscope is interactive without redirection.
69 if cscope --version </dev/null; then
70   have_cscope=yes
71 else
72   have_cscope=no
73 fi
74
75 test_cleanup ()
76 {
77   r=ok
78   if test -f configure; then
79     # In-tree build.
80     $MAKE distclean
81   else
82     # VPATH build.
83     $MAKE distcleancheck
84   fi \
85     && test ! -f cscope.files \
86     && test ! -f cscope.out \
87     && test ! -f cscope.in.out \
88     && test ! -f cscope.po.out \
89     || r='not ok'
90   result_ "$r" "[$pfx] make distcheck"
91 }
92
93 test_cscope ()
94 {
95   r=ok
96   $MAKE -n cscope || r='not ok'
97   result_ "$r" "[$pfx] make -n cscope"
98
99   if test $have_cscope = no; then
100     # For later tests.
101     touch cscope.files cscope.out cscope.in.out cscope.po.out
102     skip_row_ 3 -r "no cscope program avaiable"
103     return 0
104   fi
105
106   r=ok
107   $MAKE cscope 2>stderr || r='not ok'
108   cat stderr >&2
109   grep 'cannot find file' stderr && r='not ok'
110   rm -f stderr
111   result_ "$r" "[$pfx] make cscope"
112
113   r=ok
114   test -f cscope.files \
115     && $FGREP foo.c cscope.files \
116     && $FGREP bar.cpp cscope.files \
117     && $FGREP sub/subsub/dist.c cscope.files \
118     && $FGREP sub/subsub/gen.c cscope.files \
119     || r='not ok'
120   result_ "$r" "[$pfx] cscope.files looks correct"
121
122   r=ok
123   # cscope.files might not exist of the earlier "make cscope" failed.
124   cp cscope.files cscope.files1 \
125     && $MAKE cscope \
126     && diff cscope.files cscope.files1 \
127     || r='not ok'
128   rm -f cscope.files1
129   result_ "$r" "[$pfx] second \"make cscope\" is consistent"
130 }
131
132 my_configure ()
133 {
134   command_ok_ "[$pfx] configure" \
135               "$1"/configure EMACS=no --with-lispdir=/who/cares
136 }
137
138 if using_gmake; then
139
140   cd "$ocwd"
141   pfx="relative VPATH"
142   mkdir build
143   cd build
144   my_configure ..
145   test_cscope
146   test_cleanup
147
148   cd "$ocwd"
149   pfx="absolute VPATH"
150   mkdir build2
151   cd build2
152   my_configure "$ocwd"
153   test_cscope
154   test_cleanup
155
156 else
157
158   skip_row_ 12 -r "cscope in VPATH required GNU make"
159
160 fi
161
162 cd "$ocwd"
163 pfx="in-tree build"
164 my_configure .
165 test_cscope
166 test_cleanup
167
168 :