test: protect more yacc declarations against C vs. C++ linkage.
[automake.git] / t / yacc-line.sh
blob6c5282fadaa111c2cbce197b6bc95fd850bd6856
1 #! /bin/sh
2 # Copyright (C) 2001-2024 Free Software Foundation, Inc.
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.
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.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
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'.
22 required='cc yacc'
23 . test-init.sh
25 cat >> configure.ac << 'END'
26 AC_CONFIG_FILES([sub/Makefile])
27 AC_PROG_CC
28 AC_PROG_YACC
29 AC_OUTPUT
30 END
32 mkdir dir sub sub/dir
34 cat > Makefile.am << 'END'
35 AM_LFLAGS = --never-interactive
37 SUBDIRS = sub
38 bin_PROGRAMS = foo bar
39 AM_YFLAGS = -d
40 bar_YFLAGS =
41 foo_SOURCES = zardoz.y
42 bar_SOURCES = dir/quux.y
43 ## Avoid spurious failures with Solaris make.
44 zardoz.@OBJEXT@: zardoz.c
45 bar-quux.@OBJEXT@: bar-quux.c
46 END
48 cat > sub/Makefile.am << 'END'
49 AUTOMAKE_OPTIONS = subdir-objects
50 AM_LFLAGS = --never-interactive
52 noinst_PROGRAMS = foo bar
53 foo_YFLAGS = -d
54 foo_SOURCES = zardoz.y
55 bar_SOURCES = dir/quux.y
56 ## Avoid spurious failures with Solaris make.
57 foo-zardoz.@OBJEXT@: foo-zardoz.c
58 dir/quux.@OBJEXT@: dir/quux.c
59 END
61 cat > zardoz.y << 'END'
63 int yylex () { return 0; }
64 void yyerror (const char *s) {}
67 x : 'x' {};
69 int main(void)
71 return yyparse ();
73 END
75 cp zardoz.y dir/quux.y
76 cp zardoz.y sub/zardoz.y
77 cp zardoz.y sub/dir/quux.y
79 c_outputs='zardoz.c bar-quux.c sub/foo-zardoz.c sub/dir/quux.c'
81 $ACLOCAL
82 $AUTOCONF
83 # FIXME: stop disabling the warnings in the 'unsupported' category
84 # FIXME: once the 'subdir-objects' option has been mandatory.
85 $AUTOMAKE -a -Wno-unsupported
87 for vpath in : false; do
89 if $vpath; then
90 srcdir=..
91 mkdir build
92 cd build
93 else
94 srcdir=.
97 $srcdir/configure
98 $MAKE
100 # For debugging,
101 ls -l . sub sub/dir
102 $EGREP 'line|\.y' $c_outputs
104 # Adjusted "#line" should not contain reference to the builddir.
105 grep '#.*line.*build.*\.y' $c_outputs && exit 1
106 # Adjusted "#line" should not contain reference to the absolute
107 # srcdir.
108 $EGREP '#.*line *"?/.*\.y' $c_outputs && exit 1
109 # Adjusted "#line" should not contain reference to the default
110 # output file names, e.g., 'y.tab.c' and 'y.tab.h'.
111 grep '#.*line.*y\.tab\.' $c_outputs && exit 1
112 # Look out for a silly regression.
113 grep "#.*\.y.*\.y" $c_outputs && exit 1
114 if $vpath; then
115 grep '#.*line.*"\.\./zardoz\.y"' zardoz.c
116 grep '#.*line.*"\.\./dir/quux\.y"' bar-quux.c
117 grep '#.*line.*"\.\./\.\./sub/zardoz\.y"' sub/foo-zardoz.c
118 grep '#.*line.*"\.\./\.\./sub/dir/quux\.y"' sub/dir/quux.c
119 else
120 grep '#.*line.*"zardoz\.y"' zardoz.c
121 grep '#.*line.*"dir/quux\.y"' bar-quux.c
122 grep '#.*line.*"zardoz\.y"' sub/foo-zardoz.c
123 grep '#.*line.*"dir/quux\.y"' sub/dir/quux.c
126 cd $srcdir
128 done