doc: typos in test file.
[automake.git] / t / yacc-basic.sh
blobd86fa3b1918491ce3094387c14a59b75ff0510cc
1 #! /bin/sh
2 # Copyright (C) 2010-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 # Basic semantic checks on Yacc support (without yacc-generated headers).
18 # Keep in sync with sister test 'yacc-cxx.sh'.
20 required='cc yacc'
21 . test-init.sh
23 cat >> configure.ac << 'END'
24 AC_PROG_CC
25 AC_PROG_YACC
26 AC_OUTPUT
27 END
29 cat > Makefile.am << 'END'
30 AM_LFLAGS = --never-interactive
32 bin_PROGRAMS = foo bar
33 foo_SOURCES = parse.y foo.c
34 bar_SOURCES = $(foo_SOURCES)
35 bar_YFLAGS = -v
37 .PHONY: echo-distcom
38 echo-distcom:
39 @echo ' ' $(DIST_COMMON) ' '
40 END
42 cat > parse.y << 'END'
44 #include <stdio.h>
45 #include <stdlib.h>
46 int yylex () { return getchar (); }
47 void yyerror (const char *s) {}
50 a : 'a' { exit(0); };
51 END
53 cat > foo.c << 'END'
54 extern int yyparse(void);
55 int main () { yyparse (); return 1; }
56 END
58 $ACLOCAL
59 $AUTOCONF
60 $AUTOMAKE -a
62 ./configure
63 $MAKE
64 ls -l
65 # The Yacc-derived C sources must be created, and not removed once
66 # compiled (i.e., not treated like "intermediate files" in the GNU
67 # make sense).
68 test -f parse.c
69 test -f bar-parse.c
70 # Check that per-object flags are honored.
71 test -f bar-parse.output
73 if ! cross_compiling; then
74 echo a | ./foo
75 echo b | ./foo && exit 1
76 echo a | ./bar
77 echo b | ./bar && exit 1
78 : For shells with busted 'set -e'.
81 # The Yacc-derived C sources must be shipped.
82 $MAKE echo-distcom
83 $MAKE -s echo-distcom | grep '[ /]parse\.c '
84 $MAKE -s echo-distcom | grep '[ /]bar-parse\.c '
85 $MAKE distdir
86 ls -l $distdir
87 test -f $distdir/parse.c
88 test -f $distdir/bar-parse.c
90 # Sanity check on distribution.
91 # Note that, for this to succeed, bar-parse.output must either not
92 # be distributed, or properly cleaned by automake-generated rules.
93 # We don't want to set the exact semantics yet, but want to ensure
94 # they are are consistent.
95 yl_distcheck
97 # Make sure that the Yacc-derived C sources are erased by
98 # maintainer-clean, and not by distclean.
99 test -f parse.c
100 test -f bar-parse.c
101 $MAKE distclean
102 ls -l
103 test -f parse.c
104 test -f bar-parse.c
105 ./configure # We must re-create 'Makefile'.
106 $MAKE maintainer-clean
107 ls -l
108 test ! -e parse.c
109 test ! -e bar-parse.c