Merge branch 'micro' into maint
[platform/upstream/automake.git] / t / cscope.tap
1 #! /bin/sh
2 # Copyright (C) 2009-2013 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 . test-init.sh
20
21 plan_ 18
22
23 ocwd=$(pwd) || fatal_ "getting top-level directory"
24
25 cat > configure.ac << 'END'
26 AC_INIT([cscope-test], [1.0])
27 AM_INIT_AUTOMAKE([subdir-objects])
28 AC_CONFIG_FILES([Makefile sub/Makefile])
29 AC_SUBST([CC],  [who-cares])
30 AC_SUBST([CXX], [who-cares])
31 AC_SUBST([FC],  [who-cares])
32 AC_SUBST([GCJ], [who-cares])
33 AM_PATH_LISPDIR
34 AC_OUTPUT
35 END
36
37 mkdir sub sub/subsub
38
39 cat > Makefile.am <<'END'
40 SUBDIRS = sub
41 bin_PROGRAMS = foo
42 foo_SOURCES = foo.c bar.cpp baz.f90
43 lisp_LISP = foo.el
44 EXTRA_DIST = foo.el
45 END
46
47 cat > sub/Makefile.am <<'END'
48 bin_PROGRAMS = bar
49 bar_SOURCES = subsub/dist.c
50 nodist_bar_SOURCES = subsub/gen.c
51 subsub/gen.c:
52         $(MKDIR_P) subsub
53         echo 'int generated_subsub () { return 0; }' > $@
54 CLEANFILES = subsub/gen.c
55 END
56
57 echo 'int foo_func () { return 0; }' > foo.c
58 echo 'int main () { return 0; }' > bar.cpp
59 cat > baz.f90 <<'END'
60       subroutine baz
61       end
62 END
63 : > foo.el
64 echo 'int main () { return 0; }' > sub/subsub/dist.c
65
66 $ACLOCAL || fatal_ "aclocal failed"
67 $AUTOCONF || fatal_ "autoconf failed"
68 $AUTOMAKE -i -a || fatal_ "automake -i -a failed"
69
70 # Sun cscope is interactive without redirection; also, it might not
71 # support the '-q' option, which is required by our generated recipes.
72 if cscope -q --version </dev/null; then
73   have_cscope=yes
74 else
75   have_cscope=no
76 fi
77
78 test_cleanup ()
79 {
80   r=ok
81   if test -f configure; then
82     # In-tree build.
83     $MAKE distclean
84   else
85     # VPATH build.
86     $MAKE distcleancheck
87   fi \
88     && test ! -e cscope.files \
89     && test ! -e cscope.out \
90     && test ! -e cscope.in.out \
91     && test ! -e cscope.po.out \
92     || r='not ok'
93   result_ "$r" "[$pfx] make distcheck"
94 }
95
96 test_cscope ()
97 {
98   r=ok
99   $MAKE -n cscope || r='not ok'
100   result_ "$r" "[$pfx] make -n cscope"
101
102   if test $have_cscope = no; then
103     # For later tests.
104     touch cscope.files cscope.out cscope.in.out cscope.po.out
105     skip_row_ 3 -r "no proper cscope program available"
106     return 0
107   fi
108
109   r=ok
110   $MAKE cscope 2>stderr || r='not ok'
111   cat stderr >&2
112   grep 'cannot find file' stderr && r='not ok'
113   rm -f stderr
114   result_ "$r" "[$pfx] make cscope"
115
116   r=ok
117   test -f cscope.files \
118     && $FGREP foo.c cscope.files \
119     && $FGREP bar.cpp cscope.files \
120     && $FGREP sub/subsub/dist.c cscope.files \
121     && $FGREP sub/subsub/gen.c cscope.files \
122     || r='not ok'
123   result_ "$r" "[$pfx] cscope.files looks correct"
124
125   r=ok
126   # cscope.files might not exist of the earlier "make cscope" failed.
127   cp cscope.files cscope.files1 \
128     && $MAKE cscope \
129     && diff cscope.files cscope.files1 \
130     || r='not ok'
131   rm -f cscope.files1
132   result_ "$r" "[$pfx] second \"make cscope\" is consistent"
133 }
134
135 my_configure ()
136 {
137   command_ok_ "[$pfx] configure" \
138               "$1"/configure EMACS=no --with-lispdir=/who/cares
139 }
140
141 if using_gmake; then
142
143   cd "$ocwd"
144   pfx="relative VPATH"
145   mkdir build
146   cd build
147   my_configure ..
148   test_cscope
149   test_cleanup
150
151   cd "$ocwd"
152   pfx="absolute VPATH"
153   mkdir build2
154   cd build2
155   my_configure "$ocwd"
156   test_cscope
157   test_cleanup
158
159 else
160
161   skip_row_ 12 -r "cscope in VPATH requires GNU make"
162
163 fi
164
165 cd "$ocwd"
166 pfx="in-tree build"
167 my_configure .
168 test_cscope
169 test_cleanup
170
171 :