Merge branch 'minor'
[automake.git] / t / yacc-clean.sh
blobbbda4a2757e849a8a84ede050208926e0de522b9
1 #! /bin/sh
2 # Copyright (C) 2011-2017 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 .c and .h files derived from non-distributed .y sources
18 # are cleaned by "make clean", while .c and .h files derived from
19 # distributed .y sources are cleaned by "make maintainer-clean".
20 # See also sister test 'yacc-cxx-clean.sh'.
22 required='cc yacc'
23 . test-init.sh
25 cat >> configure.ac << 'END'
26 AC_PROG_CC
27 AC_PROG_YACC
28 AC_CONFIG_FILES([sub1/Makefile sub2/Makefile])
29 AC_OUTPUT
30 END
32 cat > Makefile.am << 'END'
33 # Use two subdirectories, one to test with '-d' in YFLAGS, the
34 # other one to test with empty YFLAGS.
35 SUBDIRS = sub1 sub2
36 END
38 mkdir sub1 sub2
40 cat > sub1/Makefile.am << 'END'
41 bin_PROGRAMS = foo bar baz qux
43 foo_SOURCES = main.c parse.y
45 bar_SOURCES = main.c parse.y
46 bar_YFLAGS = $(AM_YFLAGS)
48 baz_SOURCES = main.c
49 nodist_baz_SOURCES = baz.y
51 qux_SOURCES = main.c
52 nodist_qux_SOURCES = baz.y
53 qux_YFLAGS = $(AM_YFLAGS)
55 baz.y:
56 cp $(srcdir)/parse.y $@
58 CLEANFILES = baz.y
59 END
61 cat > sub2/Makefile.am << 'END'
62 include $(top_srcdir)/sub1/Makefile.am
63 AM_YFLAGS = -d
64 END
66 cat > sub1/parse.y << 'END'
68 int yylex () { return (getchar ()); }
69 void yyerror (char *s) {}
72 x : 'x' { };
73 END
74 cp sub1/parse.y sub2/parse.y
76 cat > sub1/main.c << 'END'
77 int main ()
79 return yyparse ();
81 END
82 cp sub1/main.c sub2/main.c
84 $ACLOCAL
85 $AUTOCONF
86 $AUTOMAKE -a
88 ./configure
90 cp config.status config.sav
92 $MAKE
93 ls -l . sub1 sub2
94 # Sanity checks.
95 test -f sub1/parse.y
96 test -f sub1/parse.c
97 test -f sub1/bar-parse.c
98 test -f sub1/baz.y
99 test -f sub1/baz.c
100 test -f sub1/qux-baz.c
101 test -f sub2/parse.y
102 test -f sub2/parse.c
103 test -f sub2/parse.h
104 test -f sub2/bar-parse.c
105 test -f sub2/bar-parse.h
106 test -f sub2/baz.y
107 test -f sub2/baz.c
108 test -f sub2/baz.h
109 test -f sub2/qux-baz.c
110 test -f sub2/qux-baz.h
112 for target in clean distclean; do
113 $MAKE $target
114 ls -l . sub1 sub2
115 test -f sub1/parse.y
116 test -f sub1/parse.c
117 test -f sub1/bar-parse.c
118 test ! -e sub1/baz.y
119 test ! -e sub1/baz.c
120 test ! -e sub1/qux-baz.c
121 test -f sub2/parse.y
122 test -f sub2/parse.c
123 test -f sub2/parse.h
124 test -f sub2/bar-parse.c
125 test -f sub2/bar-parse.h
126 test ! -e sub2/baz.y
127 test ! -e sub2/baz.c
128 test ! -e sub2/baz.h
129 test ! -e sub2/qux-baz.c
130 test ! -e sub2/qux-baz.h
131 done
133 cp config.sav config.status
134 ./config.status # Re-create 'Makefile'.
136 $MAKE maintainer-clean
137 ls -l . sub1 sub2
138 test -f sub1/parse.y
139 test ! -e sub1/parse.c
140 test ! -e sub1/bar-parse.c
141 test -f sub2/parse.y
142 test ! -e sub2/parse.c
143 test ! -e sub2/parse.h
144 test ! -e sub2/bar-parse.c
145 test ! -e sub2/bar-parse.h