tests: cosmetic changes in t/extra-sources.sh
[platform/upstream/automake.git] / t / yacc-line.sh
1 #! /bin/sh
2 # Copyright (C) 2001-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 # Check that automake yacc support ensures that yacc-generated C
18 # files use correct "#line" directives.  Try also with the
19 # 'subdir-object' option enabled.
20 # See also sister test 'lex-line.sh'.
21
22 required='cc yacc'
23 . test-init.sh
24
25 cat >> configure.ac << 'END'
26 AC_CONFIG_FILES([sub/Makefile])
27 AC_PROG_CC
28 AC_PROG_YACC
29 AC_OUTPUT
30 END
31
32 mkdir dir sub sub/dir
33
34 cat > Makefile.am << 'END'
35 SUBDIRS = sub
36 bin_PROGRAMS = foo bar
37 AM_YFLAGS = -d
38 bar_YFLAGS =
39 foo_SOURCES = zardoz.y
40 bar_SOURCES = dir/quux.y
41 ## Avoid spurious failures with Solaris make.
42 zardoz.@OBJEXT@: zardoz.c
43 bar-quux.@OBJEXT@: bar-quux.c
44 END
45
46 cat > sub/Makefile.am << 'END'
47 AUTOMAKE_OPTIONS = subdir-objects
48 noinst_PROGRAMS = foo bar
49 foo_YFLAGS = -d
50 foo_SOURCES = zardoz.y
51 bar_SOURCES = dir/quux.y
52 ## Avoid spurious failures with Solaris make.
53 foo-zardoz.@OBJEXT@: foo-zardoz.c
54 dir/quux.@OBJEXT@: dir/quux.c
55 END
56
57 cat > zardoz.y << 'END'
58 %{
59 int yylex () { return 0; }
60 void yyerror (char *s) { return; }
61 %}
62 %%
63 x : 'x' {};
64 %%
65 int main(void)
66 {
67   return yyparse ();
68 }
69 END
70
71 cp zardoz.y dir/quux.y
72 cp zardoz.y sub/zardoz.y
73 cp zardoz.y sub/dir/quux.y
74
75 c_outputs='zardoz.c bar-quux.c sub/foo-zardoz.c sub/dir/quux.c'
76
77 $ACLOCAL
78 $AUTOCONF
79 # FIXME: stop disabling the warnings in the 'unsupported' category
80 # FIXME: once the 'subdir-objects' option has been mandatory.
81 $AUTOMAKE -a -Wno-unsupported
82
83 for vpath in : false; do
84
85   if $vpath; then
86     srcdir=..
87     mkdir build
88     cd build
89   else
90     srcdir=.
91   fi
92
93   $srcdir/configure
94   $MAKE
95
96   # For debugging,
97   ls -l . sub sub/dir
98   $EGREP 'line|\.y' $c_outputs
99
100   # Adjusted "#line" should not contain reference to the builddir.
101   grep '#.*line.*build.*\.y' $c_outputs && exit 1
102   # Adjusted "#line" should not contain reference to the absolute
103   # srcdir.
104   $EGREP '#.*line *"?/.*\.y' $c_outputs && exit 1
105   # Adjusted "#line" should not contain reference to the default
106   # output file names, e.g., 'y.tab.c' and 'y.tab.h'.
107   grep '#.*line.*y\.tab\.' $c_outputs && exit 1
108   # Look out for a silly regression.
109   grep "#.*\.y.*\.y" $c_outputs && exit 1
110   if $vpath; then
111     grep '#.*line.*"\.\./zardoz\.y"' zardoz.c
112     grep '#.*line.*"\.\./dir/quux\.y"' bar-quux.c
113     grep '#.*line.*"\.\./\.\./sub/zardoz\.y"' sub/foo-zardoz.c
114     grep '#.*line.*"\.\./\.\./sub/dir/quux\.y"' sub/dir/quux.c
115   else
116     grep '#.*line.*"zardoz\.y"' zardoz.c
117     grep '#.*line.*"dir/quux\.y"' bar-quux.c
118     grep '#.*line.*"zardoz\.y"' sub/foo-zardoz.c
119     grep '#.*line.*"dir/quux\.y"' sub/dir/quux.c
120   fi
121
122   cd $srcdir
123
124 done
125
126 :