test harness: improve catching of usage errors in script 'test-driver'
[platform/upstream/automake.git] / t / lex-clean.sh
1 #! /bin/sh
2 # Copyright (C) 2011-2013 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 files derived from non-distributed .l sources
18 # are cleaned by "make clean", while .c files derived from
19 # distributed .l sources are cleaned by "make maintainer-clean".
20 # See also sister test 'lex-clean-cxx.sh'.
21
22 required='cc lex'
23 . test-init.sh
24
25 cat >> configure.ac << 'END'
26 AC_PROG_CC
27 AC_PROG_LEX
28 AC_OUTPUT
29 END
30
31 cat > Makefile.am << 'END'
32 bin_PROGRAMS = foo bar baz qux
33
34 foo_SOURCES = main.c lexer.l
35
36 bar_SOURCES = main.c lexer.l
37 bar_LFLAGS = $(AM_LFLAGS)
38
39 baz_SOURCES = main.c
40 nodist_baz_SOURCES = baz.l
41
42 qux_SOURCES = main.c
43 nodist_qux_SOURCES = baz.l
44 qux_LFLAGS = $(AM_LFLAGS)
45
46 baz.l:
47         cp $(srcdir)/lexer.l $@
48
49 CLEANFILES = baz.l
50
51 LDADD = $(LEXLIB)
52 END
53
54 cat > lexer.l << 'END'
55 %{
56 #define YY_NO_UNISTD_H 1
57 %}
58 %%
59 "GOOD"   return EOF;
60 .
61 END
62
63 cat > main.c << 'END'
64 int main (void)
65 {
66   return yylex ();
67 }
68
69 /* Avoid possible link errors. */
70 int yywrap (void)
71 {
72   return 1;
73 }
74 END
75
76 $ACLOCAL
77 $AUTOCONF
78 $AUTOMAKE -a
79
80 ./configure
81
82 cp config.status config.sav
83
84 $MAKE
85 ls -l
86 # Sanity checks.
87 test -f lexer.l
88 test -f lexer.c
89 test -f bar-lexer.c
90 test -f baz.l
91 test -f baz.c
92 test -f qux-baz.c
93
94 for target in clean distclean; do
95   $MAKE $target
96   ls -l
97   test -f lexer.l
98   test -f lexer.c
99   test -f bar-lexer.c
100   test ! -e baz.l
101   test ! -e baz.c
102   test ! -e qux-baz.c
103 done
104
105 cp config.sav config.status
106 ./config.status # re-create Makefile
107
108 $MAKE maintainer-clean
109 ls -l
110 test -f lexer.l
111 test ! -e lexer.c
112 test ! -e bar-lexer.c
113
114 :