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   run_make -E cscope || r='not ok'
111   grep 'cannot find file' stderr && r='not ok'
112   rm -f stderr
113   result_ "$r" "[$pfx] make cscope"
114
115   r=ok
116   test -f cscope.files \
117     && $FGREP foo.c cscope.files \
118     && $FGREP bar.cpp cscope.files \
119     && $FGREP sub/subsub/dist.c cscope.files \
120     && $FGREP sub/subsub/gen.c cscope.files \
121     || r='not ok'
122   result_ "$r" "[$pfx] cscope.files looks correct"
123
124   r=ok
125   # cscope.files might not exist of the earlier "make cscope" failed.
126   cp cscope.files cscope.files1 \
127     && $MAKE cscope \
128     && diff cscope.files cscope.files1 \
129     || r='not ok'
130   rm -f cscope.files1
131   result_ "$r" "[$pfx] second \"make cscope\" is consistent"
132 }
133
134 my_configure ()
135 {
136   command_ok_ "[$pfx] configure" \
137               "$1"/configure EMACS=no --with-lispdir=/who/cares
138 }
139
140 if using_gmake; then
141
142   cd "$ocwd"
143   pfx="relative VPATH"
144   mkdir build
145   cd build
146   my_configure ..
147   test_cscope
148   test_cleanup
149
150   cd "$ocwd"
151   pfx="absolute VPATH"
152   mkdir build2
153   cd build2
154   my_configure "$ocwd"
155   test_cscope
156   test_cleanup
157
158 else
159
160   skip_row_ 12 -r "cscope in VPATH requires GNU make"
161
162 fi
163
164 cd "$ocwd"
165 pfx="in-tree build"
166 my_configure .
167 test_cscope
168 test_cleanup
169
170 :