Merge branch 'yacc-quote-fix'
[automake.git] / tests / lex-line.test
blob641bcaf14ed30fa413b532fe7c7f6a58eeab449e
1 #! /bin/sh
2 # Copyright (C) 2011-2012 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 <http://www.gnu.org/licenses/>.
17 # Check that automake lex support ensures that lex-generated C
18 # files use correct "#line" directives. Try also with the
19 # `subdir-object' option enabled.
20 # See also sister test `yacc-line.test'.
22 required=lex
23 . ./defs || Exit 1
25 set -e
27 cat >> configure.in << 'END'
28 AC_CONFIG_FILES([sub/Makefile])
29 AC_PROG_CC
30 AM_PROG_CC_C_O
31 AC_PROG_LEX
32 AC_OUTPUT
33 END
35 mkdir dir sub sub/dir
37 cat > Makefile.am << 'END'
38 SUBDIRS = sub
39 bin_PROGRAMS = foo bar
40 LDADD = $(LEXLIB)
41 bar_LFLAGS = -v
42 foo_SOURCES = zardoz.l
43 bar_SOURCES = dir/quux.l
44 ## Avoid spurious failures with Solaris make.
45 zardoz.@OBJEXT@: zardoz.c
46 bar-quux.@OBJEXT@: bar-quux.c
47 END
49 cat > sub/Makefile.am << 'END'
50 AUTOMAKE_OPTIONS = subdir-objects
51 noinst_PROGRAMS = foo bar
52 ## We already used $(LEXLIB) above, so try @LEXLIB@ now.
53 LDADD = @LEXLIB@
54 foo_LFLAGS = -v
55 foo_SOURCES = zardoz.l
56 bar_SOURCES = dir/quux.l
57 ## Avoid spurious failures with Solaris make.
58 foo-zardoz.@OBJEXT@: foo-zardoz.c
59 dir/quux.@OBJEXT@: dir/quux.c
60 END
62 cat > zardoz.l << 'END'
64 "END" return EOF;
67 int main ()
69 while (yylex () != EOF)
71 return 0;
74 /* Avoid possible link errors. */
75 int yywrap (void)
77 return 1;
79 END
81 cp zardoz.l dir/quux.l
82 cp zardoz.l sub/zardoz.l
83 cp zardoz.l sub/dir/quux.l
85 c_outputs='zardoz.c bar-quux.c sub/foo-zardoz.c sub/dir/quux.c'
87 $ACLOCAL
88 $AUTOCONF
89 $AUTOMAKE -a
91 for vpath in : false; do
93 if $vpath; then
94 srcdir=..
95 mkdir build
96 cd build
97 else
98 srcdir=.
101 $srcdir/configure
102 $MAKE
104 # For debugging,
105 ls -l . sub sub/dir
106 $FGREP '.l' $c_outputs
108 # Adjusted "#line" should not contain reference to the builddir.
109 $EGREP '#.*line.*(build|\.\.).*\.l' $c_outputs && Exit 1
110 # Adjusted "#line" should not contain reference to the default
111 # output file names, e.g., `lex.yy.c'.
112 $EGREP '#.*line.*lex\.yy' $c_outputs && Exit 1
113 # Don't be excessively strict in grepping, to avoid spurious failures.
114 grep '#.*line.*zardoz\.l' zardoz.c
115 grep '#.*line.*quux\.l' bar-quux.c
116 grep '#.*line.*zardoz\.l' sub/foo-zardoz.c
117 grep '#.*line.*quux\.l' sub/dir/quux.c
118 cd $srcdir
120 done