9ff2dbc000908b6f3938a3ee9bed86324c439ecf
[platform/upstream/automake.git] / tests / lex-clean-cxx.test
1 #! /bin/sh
2 # Copyright (C) 2011-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 # 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 'lex-clean.test'.
22
23 required=lex
24 . ./defs || Exit 1
25
26 cat >> configure.ac << 'END'
27 AC_PROG_CXX
28 AC_PROG_LEX
29 AC_OUTPUT
30 END
31
32 cat > Makefile.am << 'END'
33 bin_PROGRAMS = foo bar baz qux
34
35 foo_SOURCES = mainfoo.cc parsefoo.lxx
36
37 bar_SOURCES = mainbar.cpp parsebar.ll
38 bar_LFLAGS = $(AM_LFLAGS)
39
40 baz_SOURCES = mainbaz.c++
41 nodist_baz_SOURCES = parsebaz.l++
42
43 qux_SOURCES = mainqux.cxx
44 nodist_qux_SOURCES = parsequx.lpp
45 qux_LFLAGS = $(AM_LFLAGS)
46
47 parsebaz.l++ parsequx.lpp:
48         cp $(srcdir)/parsefoo.lxx $@
49
50 CLEANFILES = parsebaz.l++ parsequx.lpp
51
52 LDADD = $(LEXLIB)
53 END
54
55 cat > parsefoo.lxx << 'END'
56 %{
57 #define YY_NO_UNISTD_H 1
58 %}
59 %option never-interactive
60 %%
61 "GOOD"   return EOF;
62 .
63 %%
64 int yywrap (void)
65 {
66   return 1;
67 }
68 END
69 cp parsefoo.lxx parsebar.ll
70
71 cat > mainfoo.cc << 'END'
72 // This file should contain valid C++ but invalid C.
73 using namespace std;
74 int main (int argc, char **argv)
75 {
76   extern int yylex (void);
77   return yylex ();
78 }
79 END
80 cp mainfoo.cc mainbar.cpp
81 cp mainfoo.cc mainbaz.c++
82 cp mainfoo.cc mainqux.cxx
83
84 $ACLOCAL
85 $AUTOCONF
86 $AUTOMAKE -a
87
88 ./configure
89
90 cp config.status config.sav
91
92 $MAKE
93 ls -l
94 # Sanity checks.
95 test -f parsefoo.cxx
96 test -f bar-parsebar.cc
97 test -f parsebaz.l++
98 test -f parsebaz.c++
99 test -f parsequx.lpp
100 test -f qux-parsequx.cpp
101
102 for target in clean distclean; do
103   $MAKE $target
104   ls -l
105   test -f parsefoo.cxx
106   test -f bar-parsebar.cc
107   test ! -r parsebaz.l++
108   test ! -r parsebaz.c++
109   test ! -r parsequx.lpp
110   test ! -r qux-parsequx.cpp
111 done
112
113 cp config.sav config.status
114 ./config.status # re-create Makefile
115
116 $MAKE maintainer-clean
117 ls -l
118 test -f parsefoo.lxx
119 test -f parsebar.ll
120 test ! -r parsefoo.cxx
121 test ! -r bar-parsebar.cc
122 test -f parsefoo.lxx
123 test -f parsebar.ll
124 test ! -r parsefoo.cxx
125 test ! -r bar-parsebar.cc
126
127 :