2 # Copyright (C) 2011-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)
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 # Tests Yacc support with yacc-generated headers
18 # (i.e., '-d' in *YFLAGS).
19 # Keep in sync with sister test 'yacc-d-cxx.sh'.
24 cat >> configure.ac
<< 'END'
27 AC_CONFIG_FILES
([foo
/Makefile bar
/Makefile baz
/Makefile
])
31 cat > Makefile.am
<<'END'
37 cat > foo
/Makefile.am
<<'END'
38 AM_LFLAGS = --never-interactive
41 zardoz_SOURCES = parse.y main.c
44 @echo ' ' $(DIST_COMMON) ' '
46 cp foo
/Makefile.am bar
/Makefile.am
47 cp foo
/Makefile.am baz
/Makefile.am
49 cat > foo
/parse.y
<< 'END'
52 int yylex
() { return 0; }
53 void yyerror
(const char
*s
) {}
59 # Using ylwrap, we actually generate y.tab.[ch]. Unfortunately, we
60 # forgot to rename #include "y.tab.h" into #include "parse.h" during
61 # the conversion from y.tab.c to parse.c. This was OK when Bison was
62 # not issuing such an #include (up to 2.6).
64 # To make sure that we perform this conversion even with version of
65 # Bison that do not generate this include, in bar/parse.y, use y.tab.h
66 # instead of parse.h, and check the ylwrap does replace "y.tab.h" with
68 sed -e 's/parse\.h/y.tab.h/' <foo
/parse.y
>bar
/parse.y
70 cat > foo
/main.c
<< 'END'
77 cp foo
/main.c bar
/main.c
79 # Even the generated header file is renamed when target-specific YFLAGS
80 # are used. This might not be the best behavior, but it has been in
81 # place for quite a long time, so just go along with it for now.
82 sed 's/"parse\.h"/"zardoz-parse.h"/' foo
/parse.y
> baz
/parse.y
83 sed 's/"parse\.h"/"zardoz-parse.h"/' foo
/main.c
> baz
/main.c
89 $FGREP parse.h foo
/Makefile.
in bar
/Makefile.
in baz
/Makefile.
in && exit 1
91 cat >> foo
/Makefile.am
<<END
92 BUILT_SOURCES = parse.h
96 $AUTOMAKE -Wno-gnu foo
/Makefile
98 sed 's/EOL$//' >> bar
/Makefile.am
<<END
99 AM_YFLAGS${tab}= -d EOL
100 BUILT_SOURCES = parse.h
102 $AUTOMAKE bar
/Makefile
104 cat >> baz
/Makefile.am
<<END
105 BUILT_SOURCES = zardoz-parse.h
106 zardoz_YFLAGS =-d${tab}
108 $AUTOMAKE baz
/Makefile
123 for i
in $generated; do
127 # There must remain no obsolete header guard.
128 grep Y_TAB_H
$generated && exit 1
130 # The generated C source and header files must be shipped.
131 for dir
in foo bar
; do
134 $MAKE -s echo-distcom |
grep '[ /]parse.c '
135 $MAKE -s echo-distcom |
grep '[ /]parse.h '
140 $MAKE -s echo-distcom |
grep '[ /]zardoz-parse.c '
141 $MAKE -s echo-distcom |
grep '[ /]zardoz-parse.h '
146 for i
in $generated; do
150 # Sanity check the distribution.
153 # While we are at it, make sure that 'parse.c' and 'parse.h' are erased
154 # by maintainer-clean, and not by distclean.
156 for i
in $generated; do
159 .
/configure
# Re-create 'Makefile'.
160 $MAKE maintainer-clean
161 for i
in $generated; do