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