]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
lex tests: avoid spurious failures when LEXLIB isn't found
authorStefano Lattarini <stefano.lattarini@gmail.com>
Wed, 25 May 2011 17:05:15 +0000 (19:05 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Thu, 26 May 2011 15:16:49 +0000 (17:16 +0200)
The AC_PROG_LEX Autoconf macro does not diagnose a failure to find
the "lex library" expected to provide a `yywrap' function (function
which is required to link most lex-generated programs).  On the
contrary, when all the link attempts (i.e., with `-ll' and `-lfl')
fail, configure declares that no lex library is needed, and simply
proceeds with the configuration process -- only for the build to
possibly fail later, at make time.

This behaviour might be (partly) intended; the Autoconf manual
reads:
 ``You are encouraged to use Flex in your sources, since it is
   both more pleasant to use than plain Lex and the C source
   it produces is portable.  In order to ensure portability,
   however, you must either provide a function `yywrap' or, if
   you don't use it (e.g., your scanner has no `#include'-like
   feature), simply include a `%noyywrap' statement in the
   scanner's source.''

This AC_PROG_LEX behaviour is causing some spurious failures of the
Automake testsuite in environments which lack a proper library
providing `yywrap' (this happens for example in Linux->MinGW cross
compilations).  But at this point is clear that a proper workaround
is to simply provide a fall-back implementation of `yywrap' in our
lexers.

* tests/cond35.test: Provide a dummy `yywrap' function.
* tests/lex3.test: Likewise.
* tests/lexvpath.test: Likewise.
* tests/silent-many-gcc.test: Likewise.
* tests/silent-many-generic.test: Likewise.
* tests/silent-lex-gcc.test: Likewise, and a dummy `main' too.
* tests/silent-lex-generic.test: Likewise.
* tests/lex-lib.test: New test.
* tests/lex-libobj.test: New test.
* tests/lex-nowrap.test: New test.
* tests/Makefile.am (TESTS): Update.
* THANKS: Update.

Thanks to Russ Allbery for the suggestion.

14 files changed:
ChangeLog
THANKS
tests/Makefile.am
tests/Makefile.in
tests/cond35.test
tests/lex-lib.test [new file with mode: 0755]
tests/lex-libobj.test [new file with mode: 0755]
tests/lex-noyywrap.test [new file with mode: 0755]
tests/lex3.test
tests/lexvpath.test
tests/silent-lex-gcc.test
tests/silent-lex-generic.test
tests/silent-many-gcc.test
tests/silent-many-generic.test

index d26268d15cb0d1a1a61429c0438a84a8c15bad66..3e6269bc036a1c00f4740372a41cdb2471b439b2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,42 @@
+2011-05-25  Stefano Lattarini  <stefano.lattarini@gmail.com>
+
+       lex tests: avoid spurious failures when LEXLIB isn't found
+       The AC_PROG_LEX Autoconf macro does not diagnose a failure to find
+       the "lex library" expected to provide a `yywrap' function (function
+       which is required to link most lex-generated programs).  On the
+       contrary, when all the link attempts (i.e., with `-ll' and `-lfl')
+       fail, configure declares that no lex library is needed, and simply
+       proceeds with the configuration process -- only for the build to
+       possibly fail later, at make time.
+       This behaviour might be (partly) intended; the Autoconf manual
+       reads:
+        ``You are encouraged to use Flex in your sources, since it is
+          both more pleasant to use than plain Lex and the C source
+          it produces is portable.  In order to ensure portability,
+          however, you must either provide a function `yywrap' or, if
+          you don't use it (e.g., your scanner has no `#include'-like
+          feature), simply include a `%noyywrap' statement in the
+          scanner's source.''
+       This AC_PROG_LEX behaviour is causing some spurious failures of the
+       Automake testsuite in environments which lack a proper library
+       providing `yywrap' (this happens for example in Linux->MinGW cross
+       compilations).  But at this point is clear that a proper workaround
+       is to simply provide a fall-back implementation of `yywrap' in our
+       lexers.
+       * tests/cond35.test: Provide a dummy `yywrap' function.
+       * tests/lex3.test: Likewise.
+       * tests/lexvpath.test: Likewise.
+       * tests/silent-many-gcc.test: Likewise.
+       * tests/silent-many-generic.test: Likewise.
+       * tests/silent-lex-gcc.test: Likewise, and a dummy `main' too.
+       * tests/silent-lex-generic.test: Likewise.
+       * tests/lex-lib.test: New test.
+       * tests/lex-libobj.test: New test.
+       * tests/lex-nowrap.test: New test.
+       * tests/Makefile.am (TESTS): Update.
+       * THANKS: Update.
+       Thanks to Russ Allbery for the suggestion.
+
 2011-05-25  Stefano Lattarini  <stefano.lattarini@gmail.com>
 
        testsuite: require C++ compiler explicitly in tests needing it
diff --git a/THANKS b/THANKS
index 5ee0e4c7c8fbacee04fece0bc5155cbe43d9e963..96d215e60b86d670edaf74ad34f3833d61129fe6 100644 (file)
--- a/THANKS
+++ b/THANKS
@@ -310,6 +310,7 @@ Roberto Bagnara             bagnara@cs.unipr.it
 Roman Fietze           roman.fietze@telemotive.de
 Ronald Landheer                ronald@landheer.com
 Roumen Petrov          bugtrack@roumenpetrov.info
+Russ Allbery           rra@stanford.edu
 Rusty Ballinger                rusty@rlyeh.engr.sgi.com
 Ryan T. Sammartino     ryants@shaw.ca
 Sam Hocevar            sam@zoy.org
index ff20e25d78b29322dcc6b8bb9c23a1c02f5cf8bf..976883341fc3af5599ce7aae4ff22321b2cc68da 100644 (file)
@@ -566,6 +566,9 @@ lex5.test \
 lexcpp.test \
 lexvpath.test \
 lex-subobj-nodep.test \
+lex-lib.test \
+lex-libobj.test \
+lex-noyywrap.test \
 lflags.test \
 lflags2.test \
 libexec.test \
index 55647eeeafa87eeff3de41c1f6563230a501eb2c..55fb244fd75a02f456c15ba270b74fb7505f3bc2 100644 (file)
@@ -831,6 +831,9 @@ lex5.test \
 lexcpp.test \
 lexvpath.test \
 lex-subobj-nodep.test \
+lex-lib.test \
+lex-libobj.test \
+lex-noyywrap.test \
 lflags.test \
 lflags2.test \
 libexec.test \
index 2fba1f1e1473f0c83a39b5622c02f8fcd3b20969..348b9c7c26b98851b9cf0601189c8ef55ea7fc87 100755 (executable)
@@ -59,6 +59,12 @@ test `grep tparse.h: Makefile.in | wc -l` = 1
 cat > tscan.l << 'END'
 %%
 "END"   return EOF;
+%%
+/* Avoid possible link errors. */
+int yywrap (void)
+{
+  return 0;
+}
 END
 
 cat > tparse.y << 'END'
diff --git a/tests/lex-lib.test b/tests/lex-lib.test
new file mode 100755 (executable)
index 0000000..07af3ff
--- /dev/null
@@ -0,0 +1,67 @@
+#! /bin/sh
+# Copyright (C) 1999, 2001, 2002, 2003, 2004, 2010, 2011 Free Software
+# Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Check that we can provide a personal `yywrap' function in a custom
+# library.
+
+required='cc lex'
+. ./defs || Exit 1
+
+cat >> configure.in << 'END'
+AC_PROG_CC
+AC_PROG_RANLIB
+LEXLIB=libmylex.a
+AC_PROG_LEX
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = lexer
+lexer_SOURCES = foo.l
+lexer_LDADD = $(LEXLIB)
+EXTRA_lexer_DEPENDENCIES = $(LEXLIB)
+noinst_LIBRARIES = libmylex.a
+libmylex_a_SOURCES = mu.c
+END
+
+cat > mu.c << 'END'
+int yywrap (void)
+{
+  return 0;
+}
+END
+
+cat > foo.l <<'END'
+%%
+.
+%%
+int main (void)
+{
+  return 0;
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE
+test -f foo.c
+test -f libmylex.a
+
+:
diff --git a/tests/lex-libobj.test b/tests/lex-libobj.test
new file mode 100755 (executable)
index 0000000..1ca1d4c
--- /dev/null
@@ -0,0 +1,75 @@
+#! /bin/sh
+# Copyright (C) 1999, 2001, 2002, 2003, 2004, 2010, 2011 Free Software
+# Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Check that we can provide a personal `yywrap' function through the
+# LIBOBJ machinery.
+
+required='cc lex'
+. ./defs || Exit 1
+
+cat >> configure.in << 'END'
+AC_PROG_CC
+AC_PROG_RANLIB
+AC_PROG_LEX
+save_LIBS=$LIBS
+LIBS="$LEXLIB $LIBS"
+AC_REPLACE_FUNCS([yywrap])
+LIBS=$save_LIBS
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+noinst_PROGRAMS = foo
+foo_SOURCES = foo.l
+foo_LDADD = $(LEXLIB) $(LIBOBJS)
+END
+
+cat > yywrap.c << 'END'
+int yywrap (void)
+{
+  return 0;
+}
+END
+
+cat > foo.l <<'END'
+%%
+.
+%%
+int main (void)
+{
+  return 0;
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+grep LIBOBJS Makefile # For debugging.
+$MAKE
+$MAKE distclean
+
+# Force no "system lex library".
+./configure LEXLIB='-L /lib'
+grep LIBOBJS Makefile # For debugging.
+grep '^LIBOBJS *=.*yywrap.*\.o' Makefile # Sanity check.
+$MAKE
+
+$MAKE distcheck
+
+:
diff --git a/tests/lex-noyywrap.test b/tests/lex-noyywrap.test
new file mode 100755 (executable)
index 0000000..9431970
--- /dev/null
@@ -0,0 +1,72 @@
+#! /bin/sh
+# Copyright (C) 1999, 2001, 2002, 2003, 2004, 2010, 2011 Free Software
+# Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Check Lex support with flex using the `%noyywrap' option.
+
+required='cc flex'
+. ./defs || Exit 1
+
+cat >> configure.in << 'END'
+AC_PROG_CC
+AM_PROG_LEX
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+foo_SOURCES = foo.l
+
+.PHONY: test-no-lexlib
+check-local: test-no-lexlib
+test-no-lexlib:
+       test x'$(LEXLIB)' = x'none needed'
+END
+
+cat > foo.l << 'END'
+%option noyywrap
+%%
+"GOOD"   return EOF;
+.
+%%
+int main (void)
+{
+  /* We don't use a 'while' loop here (like a real lexer would do)
+     to avoid possible hangs. */
+  if (yylex () == EOF)
+    return 0;
+  else
+    return 1;
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure LEXLIB="none needed"
+
+# Program should build and run.
+$MAKE
+if cross_compiling; then :; else
+  echo GOOD | ./foo
+  echo BAD | ./foo && Exit 1
+fi
+
+# Sanity check on distribution.
+$MAKE distcheck DISTCHECK_CONFIGURE_FLAGS='LEXLIB="none needed"'
+
+:
index 7def55ad99682716160e35b01c2b0d4c541b3c9b..9c2f5b49207eb68edadd95cb5420f4257e8a41ee 100755 (executable)
@@ -39,8 +39,8 @@ cat > foo.l << 'END'
 "GOOD"   return EOF;
 .
 %%
-int
-main ()
+
+int main (void)
 {
   /* We don't use a 'while' loop here (like a real lexer would do)
      to avoid possible hangs. */
@@ -49,6 +49,12 @@ main ()
   else
     return 1;
 }
+
+/* Avoid possible link errors. */
+int yywrap (void)
+{
+  return 0;
+}
 END
 
 $ACLOCAL
index 212db31433db901dd209a91c65eb7ee554df4775..93902b30365ae5c55c2d283bebc66068583a4346 100755 (executable)
@@ -52,7 +52,15 @@ cat > lexer.l << 'END'
 END
 
 cat > foo.c << 'END'
-int main () { return 0; }
+int main (void)
+{
+  return 0;
+}
+/* Avoid possible link errors. */
+int yywrap (void)
+{
+  return 0;
+}
 END
 
 $ACLOCAL
@@ -61,7 +69,7 @@ $AUTOMAKE -a
 
 mkdir sub
 
-# We must run configure early, to find out whay $LEX_OUTPUT_ROOT is.
+# We must run configure early, to find out why $LEX_OUTPUT_ROOT is.
 cd sub
 ../configure
 . ./lexoutroot
index a55f3580253cecc25694b0e7d898a31de10f9da8..2a691c3142605f6cd7cb70a72e395caa0e633576 100755 (executable)
@@ -55,6 +55,15 @@ cat > foo.l <<'EOF'
 "END"   return EOF;
 .
 %%
+/* Avoid possible link errors. */
+int yywrap (void)
+{
+  return 0;
+}
+int main (void)
+{
+  return 0;
+}
 EOF
 cp foo.l sub/bar.l
 
index 7e74d6466579fd3d210b9fc52237fb2e0a93bd92..bc3ffffae37366e158cd70d5be896aeed84bdcc0 100755 (executable)
@@ -55,6 +55,15 @@ cat > foo.l <<'EOF'
 "END"   return EOF;
 .
 %%
+/* Avoid possible link errors. */
+int yywrap (void)
+{
+  return 0;
+}
+int main (void)
+{
+  return 0;
+}
 EOF
 cp foo.l sub/bar.l
 
index 79fa4a634c3cf672cf02b4f2926f070ec894c9b6..8cdb35b9fc492e71a0101db5791f400d8c506551 100755 (executable)
@@ -158,6 +158,11 @@ cat > foo5.l <<'EOF'
 "END"   return EOF;
 .
 %%
+/* Avoid possible link errors. */
+int yywrap (void)
+{
+  return 0;
+}
 EOF
 cat > foo6.y <<'EOF'
 %{
index 9897b0c298d7abd97d753d7d9ff63dabc60a935d..c81f52c88830f40e43a222f52b4e43876a6f7a43 100755 (executable)
@@ -160,6 +160,11 @@ cat > foo5.l <<'EOF'
 "END"   return EOF;
 .
 %%
+/* Avoid possible link errors. */
+int yywrap (void)
+{
+  return 0;
+}
 EOF
 cat > foo6.y <<'EOF'
 %{