Merge branch 'maint'
[platform/upstream/automake.git] / t / lex-header.sh
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 # Automake lex support can work with flex '--header-file' option (see
18 # bugs #8844 and #9933).
19
20 required='cc flex'
21 . ./defs || exit 1
22
23 cat >> configure.ac << 'END'
24 AC_PROG_CC
25 AC_PROG_LEX
26 AC_OUTPUT
27 END
28
29 cat > Makefile.am << 'END'
30 bin_PROGRAMS = foo
31 foo_SOURCES = lexer.l main.c mylex.h
32 foo_LFLAGS = --header-file=mylex.h
33 BUILT_SOURCES = mylex.h
34 # Recover from removal of header.
35 mylex.h: foo-lexer.c
36         test -f $@ || rm -f foo-lexer.c
37         test -f $@ || $(MAKE) $(AM_MAKEFLAGS) foo-lexer.c
38 END
39
40 cat > lexer.l << 'END'
41 %option noyywrap
42 %{
43 #define YY_NO_UNISTD_H 1
44 %}
45 %%
46 "GOOD"   return EOF;
47 .
48 %%
49 END
50
51 cat > main.c <<'END'
52 #include "mylex.h"
53 int main (void)
54 {
55   /* We don't use a 'while' loop here (like a real lexer would do)
56      to avoid possible hangs. */
57   if (yylex () == EOF)
58     return 0;
59   else
60     return 1;
61 }
62 END
63
64 $ACLOCAL
65 $AUTOCONF
66 $AUTOMAKE -a
67
68 ./configure
69
70 # Program should build and run.
71 $MAKE
72 if ! cross_compiling; then
73   echo GOOD | ./foo
74   echo BAD | ./foo && exit 1
75   : For shells with busted 'set -e'.
76 fi
77
78 # Recovering from header removal.
79 rm -f mylex.h
80 $MAKE
81 test -f mylex.h
82
83 # Sanity check on distribution.
84 yl_distcheck
85
86 :