Merge branch 'fix-pr14560' into micro
[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 AM_PROG_CC_C_O
29 AC_PROG_YACC
30 AC_OUTPUT
31 END
32
33 mkdir dir sub sub/dir
34
35 cat > Makefile.am << 'END'
36 SUBDIRS = sub
37 bin_PROGRAMS = foo bar
38 AM_YFLAGS = -d
39 bar_YFLAGS =
40 foo_SOURCES = zardoz.y
41 bar_SOURCES = dir/quux.y
42 ## Avoid spurious failures with Solaris make.
43 zardoz.@OBJEXT@: zardoz.c
44 bar-quux.@OBJEXT@: bar-quux.c
45 END
46
47 cat > sub/Makefile.am << 'END'
48 AUTOMAKE_OPTIONS = subdir-objects
49 noinst_PROGRAMS = foo bar
50 foo_YFLAGS = -d
51 foo_SOURCES = zardoz.y
52 bar_SOURCES = dir/quux.y
53 ## Avoid spurious failures with Solaris make.
54 foo-zardoz.@OBJEXT@: foo-zardoz.c
55 dir/quux.@OBJEXT@: dir/quux.c
56 END
57
58 cat > zardoz.y << 'END'
59 %{
60 int yylex () { return 0; }
61 void yyerror (char *s) { return; }
62 %}
63 %%
64 x : 'x' {};
65 %%
66 int main(void)
67 {
68   return yyparse ();
69 }
70 END
71
72 cp zardoz.y dir/quux.y
73 cp zardoz.y sub/zardoz.y
74 cp zardoz.y sub/dir/quux.y
75
76 c_outputs='zardoz.c bar-quux.c sub/foo-zardoz.c sub/dir/quux.c'
77
78 $ACLOCAL
79 $AUTOCONF
80 $AUTOMAKE -a
81
82 for vpath in : false; do
83
84   if $vpath; then
85     srcdir=..
86     mkdir build
87     cd build
88   else
89     srcdir=.
90   fi
91
92   $srcdir/configure
93   $MAKE
94
95   # For debugging,
96   ls -l . sub sub/dir
97   $EGREP 'line|\.y' $c_outputs
98
99   # Adjusted "#line" should not contain reference to the builddir.
100   grep '#.*line.*build.*\.y' $c_outputs && exit 1
101   # Adjusted "#line" should not contain reference to the absolute
102   # srcdir.
103   $EGREP '#.*line *"?/.*\.y' $c_outputs && exit 1
104   # Adjusted "#line" should not contain reference to the default
105   # output file names, e.g., 'y.tab.c' and 'y.tab.h'.
106   grep '#.*line.*y\.tab\.' $c_outputs && exit 1
107   # Look out for a silly regression.
108   grep "#.*\.y.*\.y" $c_outputs && exit 1
109   if $vpath; then
110     grep '#.*line.*"\.\./zardoz\.y"' zardoz.c
111     grep '#.*line.*"\.\./dir/quux\.y"' bar-quux.c
112     grep '#.*line.*"\.\./\.\./sub/zardoz\.y"' sub/foo-zardoz.c
113     grep '#.*line.*"\.\./\.\./sub/dir/quux\.y"' sub/dir/quux.c
114   else
115     grep '#.*line.*"zardoz\.y"' zardoz.c
116     grep '#.*line.*"dir/quux\.y"' bar-quux.c
117     grep '#.*line.*"zardoz\.y"' sub/foo-zardoz.c
118     grep '#.*line.*"dir/quux\.y"' sub/dir/quux.c
119   fi
120
121   cd $srcdir
122
123 done
124
125 :