1#! /bin/sh
2# Copyright (C) 2011-2021 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 <https://www.gnu.org/licenses/>.
16
17# Check that C++ source and header files derived from non-distributed
18# Yacc sources are cleaned by "make clean", while C++ source and
19# header files derived from distributed Yacc sources are cleaned by
20# "make maintainer-clean".
21# See also sister test 'yacc-clean.sh'.
22
23required='c++ yacc'
24. test-init.sh
25
26cat >> configure.ac << 'END'
27AC_PROG_CXX
28AC_PROG_YACC
29AC_CONFIG_FILES([sub1/Makefile sub2/Makefile])
30AC_OUTPUT
31END
32
33cat > Makefile.am << 'END'
34# Use two subdirectories, one to test with '-d' in YFLAGS, the
35# other one to test with empty YFLAGS.
36SUBDIRS = sub1 sub2
37END
38
39mkdir sub1 sub2
40
41cat > sub1/Makefile.am << 'END'
42bin_PROGRAMS = foo bar baz qux
43
44foo_SOURCES = mainfoo.cc parsefoo.yxx
45
46bar_SOURCES = mainbar.cpp parsebar.yy
47bar_YFLAGS = $(AM_YFLAGS)
48
49baz_SOURCES = mainbaz.c++
50nodist_baz_SOURCES = parsebaz.y++
51
52qux_SOURCES = mainqux.cxx
53nodist_qux_SOURCES = parsequx.ypp
54qux_YFLAGS = $(AM_YFLAGS)
55
56parsebaz.y++ parsequx.ypp:
57	cp $(srcdir)/parsefoo.yxx $@
58
59CLEANFILES = parsebaz.y++ parsequx.ypp
60END
61
62cat > sub2/Makefile.am << 'END'
63include $(top_srcdir)/sub1/Makefile.am
64AM_YFLAGS = -d
65END
66
67cat > sub1/parsefoo.yxx << 'END'
68%{
69// This file should contain valid C++ but invalid C.
70#include <cstdio>
71// "std::" qualification required by Sun C++ 5.9.
72int yylex (void) { return std::getchar (); }
73void yyerror (const char *s) {}
74%}
75%%
76x : 'x' { };
77END
78cp sub1/parsefoo.yxx sub1/parsebar.yy
79cp sub1/parsefoo.yxx sub2/parsefoo.yxx
80cp sub1/parsefoo.yxx sub2/parsebar.yy
81
82cat > sub1/mainfoo.cc << 'END'
83// This file should contain valid C++ but invalid C.
84using namespace std;
85int main (int argc, char **argv)
86{
87  extern int yyparse (void);
88  return yyparse ();
89}
90END
91cp sub1/mainfoo.cc sub1/mainbar.cpp
92cp sub1/mainfoo.cc sub1/mainbaz.c++
93cp sub1/mainfoo.cc sub1/mainqux.cxx
94cp sub1/main???.c* sub2
95
96$ACLOCAL
97$AUTOCONF
98$AUTOMAKE -a
99
100./configure
101
102cp config.status config.sav
103
104$MAKE
105ls -l . sub1 sub2
106# Sanity checks.
107test -f sub1/parsefoo.cxx
108test -f sub1/bar-parsebar.cc
109test -f sub1/parsebaz.y++
110test -f sub1/parsebaz.c++
111test -f sub1/parsequx.ypp
112test -f sub1/qux-parsequx.cpp
113test -f sub2/parsefoo.cxx
114test -f sub2/parsefoo.hxx
115test -f sub2/bar-parsebar.cc
116test -f sub2/bar-parsebar.hh
117test -f sub2/parsebaz.y++
118test -f sub2/parsebaz.c++
119test -f sub2/parsebaz.h++
120test -f sub2/parsequx.ypp
121test -f sub2/qux-parsequx.cpp
122test -f sub2/qux-parsequx.hpp
123
124for target in clean distclean; do
125  $MAKE $target
126  ls -l . sub1 sub2
127  test -f sub1/parsefoo.cxx
128  test -f sub1/bar-parsebar.cc
129  test ! -e sub1/parsebaz.y++
130  test ! -e sub1/parsebaz.c++
131  test ! -e sub1/parsequx.ypp
132  test ! -e sub1/qux-parsequx.cpp
133  test -f sub2/parsefoo.cxx
134  test -f sub2/parsefoo.hxx
135  test -f sub2/bar-parsebar.cc
136  test -f sub2/bar-parsebar.hh
137  test ! -e sub2/parsebaz.y++
138  test ! -e sub2/parsebaz.c++
139  test ! -e sub2/parsebaz.h++
140  test ! -e sub2/parsequx.ypp
141  test ! -e sub2/qux-parsequx.cpp
142  test ! -e sub2/qux-parsequx.hpp
143done
144
145cp config.sav config.status
146./config.status # re-create Makefile
147
148$MAKE maintainer-clean
149ls -l . sub1 sub2
150test -f sub1/parsefoo.yxx
151test -f sub1/parsebar.yy
152test ! -e sub1/parsefoo.cxx
153test ! -e sub1/bar-parsebar.cc
154test -f sub2/parsefoo.yxx
155test -f sub2/parsebar.yy
156test ! -e sub2/parsefoo.cxx
157test ! -e sub2/parsefoo.hxx
158test ! -e sub2/bar-parsebar.cc
159test ! -e sub2/bar-parsebar.hh
160
161:
162