am-ft: make the environment available earlier
[platform/upstream/automake.git] / t / lex-line.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 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.sh'.
21
22 required='cc lex'
23 . test-init.sh
24
25 cat >> configure.ac << 'END'
26 AC_CONFIG_FILES([sub/Makefile])
27 AC_PROG_CC
28 AC_PROG_LEX
29 AC_OUTPUT
30 END
31
32 mkdir dir sub sub/dir
33
34 cat > Makefile.am << 'END'
35 SUBDIRS = sub
36 bin_PROGRAMS = foo bar
37 LDADD = $(LEXLIB)
38 bar_LFLAGS = -v
39 foo_SOURCES = zardoz.l
40 bar_SOURCES = dir/quux.l
41 ## Avoid spurious failures with Solaris make.
42 zardoz.@OBJEXT@: zardoz.c
43 bar-quux.@OBJEXT@: bar-quux.c
44 END
45
46 cat > sub/Makefile.am << 'END'
47 AUTOMAKE_OPTIONS = subdir-objects
48 noinst_PROGRAMS = foo bar
49 ## We already used $(LEXLIB) above, so try @LEXLIB@ now.
50 LDADD = @LEXLIB@
51 foo_LFLAGS = -v
52 foo_SOURCES = zardoz.l
53 bar_SOURCES = dir/quux.l
54 ## Avoid spurious failures with Solaris make.
55 foo-zardoz.@OBJEXT@: foo-zardoz.c
56 dir/quux.@OBJEXT@: dir/quux.c
57 END
58
59 cat > zardoz.l << 'END'
60 %{
61 #define YY_NO_UNISTD_H 1
62 %}
63 %%
64 "END"  return EOF;
65 .
66 %%
67 int main ()
68 {
69   while (yylex () != EOF)
70     ;
71   return 0;
72 }
73
74 /* Avoid possible link errors. */
75 int yywrap (void)
76 {
77   return 1;
78 }
79 END
80
81 cp zardoz.l dir/quux.l
82 cp zardoz.l sub/zardoz.l
83 cp zardoz.l sub/dir/quux.l
84
85 c_outputs='zardoz.c bar-quux.c sub/foo-zardoz.c sub/dir/quux.c'
86
87 $ACLOCAL
88 $AUTOCONF
89 # FIXME: stop disabling the warnings in the 'unsupported' category
90 # FIXME: once the 'subdir-objects' option has been mandatory.
91 $AUTOMAKE -a -Wno-unsupported
92
93 for vpath in : false; do
94
95   if $vpath; then
96     srcdir=..
97     mkdir build
98     cd build
99   else
100     srcdir=.
101   fi
102
103   $srcdir/configure
104   $MAKE
105
106   # For debugging,
107   ls -l . sub sub/dir
108   $EGREP 'line|\.l' $c_outputs
109
110   grep '#.*line.*build.*\.l' $c_outputs && exit 1
111   # Adjusted "#line" should not contain reference to the absolute
112   # srcdir.
113   $EGREP '#.*line *"?/.*\.l' $c_outputs && exit 1
114   # Adjusted "#line" should not contain reference to the default
115   # output file names, e.g., 'lex.yy.c'.
116   grep '#.*line.*lex\.yy' $c_outputs && exit 1
117   # Look out for a silly regression.
118   grep "#.*\.l.*\.l" $c_outputs && exit 1
119   if $vpath; then
120     grep '#.*line.*"\.\./zardoz\.l"' zardoz.c
121     grep '#.*line.*"\.\./dir/quux\.l"' bar-quux.c
122     grep '#.*line.*"\.\./\.\./sub/zardoz\.l"' sub/foo-zardoz.c
123     grep '#.*line.*"\.\./\.\./sub/dir/quux\.l"' sub/dir/quux.c
124   else
125     grep '#.*line.*"zardoz\.l"' zardoz.c
126     grep '#.*line.*"dir/quux\.l"' bar-quux.c
127     grep '#.*line.*"zardoz\.l"' sub/foo-zardoz.c
128     grep '#.*line.*"dir/quux\.l"' sub/dir/quux.c
129   fi
130
131   cd $srcdir
132
133 done
134
135 :