From eb4a1d7fafde8e6d00ab0db3ea369c3927754e21 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Thu, 16 Jul 2020 09:46:28 -0700
Subject: [PATCH] Fix AC_PROG_LEX regression

Problem reported by Ross Burton in:
https://savannah.gnu.org/support/?110269
* lib/autoconf/programs.m4 (_AC_PROG_LEX_YYTEXT_DECL):
If tests indicate that LEX or LEXLIB does not work, set LEX to ":"
and LEXLIB empty, instead of failing out of 'configure' entirely.
---
 lib/autoconf/programs.m4 | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/lib/autoconf/programs.m4 b/lib/autoconf/programs.m4
index 43f3b14e..4f910fb0 100644
--- a/lib/autoconf/programs.m4
+++ b/lib/autoconf/programs.m4
@@ -740,15 +740,17 @@ main (void)
   return ! yylex () + ! yywrap ();
 }
 ]_ACEOF
-_AC_DO_VAR(LEX conftest.l)
 AC_CACHE_CHECK([for lex output file root], [ac_cv_prog_lex_root], [
+ac_cv_prog_lex_root=unknown
+_AC_DO_VAR(LEX conftest.l) &&
 if test -f lex.yy.c; then
   ac_cv_prog_lex_root=lex.yy
 elif test -f lexyy.c; then
   ac_cv_prog_lex_root=lexyy
-else
-  AC_MSG_ERROR([cannot find output from $LEX; giving up])
 fi])
+AS_IF([test "$ac_cv_prog_lex_root" = unknown],
+  [AC_MSG_WARN([cannot find output from $LEX; giving up on $LEX])
+   LEX=: LEXLIB=])
 AC_SUBST([LEX_OUTPUT_ROOT], [$ac_cv_prog_lex_root])dnl
 
 AS_VAR_SET_IF([LEXLIB], [], [
@@ -765,13 +767,15 @@ AS_VAR_SET_IF([LEXLIB], [], [
   ])
   AS_IF(
      [test "$ac_cv_lib_lex" = 'not found'],
-	[AC_MSG_ERROR([required lex library not found])],
+	[AC_MSG_WARN([required lex library not found; giving up on $LEX])
+	 LEX=: LEXLIB=],
      [test "$ac_cv_lib_lex" = 'none needed'],
         [LEXLIB=''],
 	[LEXLIB=$ac_cv_lib_lex])
 ])
 AC_SUBST(LEXLIB)
 
+AS_IF([test "$LEX" != :], [
 AC_CACHE_CHECK(whether yytext is a pointer, ac_cv_prog_lex_yytext_pointer,
 [# POSIX says lex can declare yytext either as a pointer or an array; the
 # default is implementation-dependent.  Figure out which it is, since
@@ -791,6 +795,7 @@ if test $ac_cv_prog_lex_yytext_pointer = yes; then
 	    [Define to 1 if `lex' declares `yytext' as a `char *' by default,
 	     not a `char[]'.])
 fi
+])
 rm -f conftest.l $LEX_OUTPUT_ROOT.c
 ])# _AC_PROG_LEX_YYTEXT_DECL
 
-- 
2.17.1

