Hi.

 In reference to:
https://lists.gnu.org/archive/html/automake/2023-07/msg00007.html.

 The attached patch allows the AM_PROG_LEX macro to accept
parameters, to accommodate for the fact that AC_PROG_LEX now (since
Autoconf 2.70) requires one. The values accepted by AM_PROG_LEX are
passed to AC_PROG_LEX the following way:
- an empty value is passed as empty, resulting in an Autoconf warning
(just like it is now),
- the word 'yywrap' is passed unchanged,
- the word 'noyywrap' is passed unchanged,
- the word 'empty' results in an empty value (and thus an Autoconf
warning)
- any other word results in a syntax warning and an empty value being
passed (resulting in an Autoconf warning).

 Since it's Autoconf 2.70 that started using the parameter, I've
bumped the required value. You may change back if needed.

 My M4 "knowledge" is simply basing on other examples and doing
whatever that doesn't result in an error, so you may change the code
as needed (m4_define, m4_warn, m4_expand).

 Test for the parameters is added. All tests matching *lex*sh pass.
+11-20s to testing time.

--
Regards - Bogdan ('bogdro') D.                 (GNU/Linux & FreeDOS)
X86 assembly (DOS, GNU/Linux):    http://bogdro.evai.pl/index-en.php
Soft(EN): http://bogdro.evai.pl/soft  http://bogdro.evai.pl/soft4asm
www.Xiph.org  www.TorProject.org  www.LibreOffice.org  www.GnuPG.org
From b159d82cb474d8ff4fc76e843b871a6d808e70bc Mon Sep 17 00:00:00 2001
From: Bogdan Drozdowski <>
Date: Tue, 29 Aug 2023 20:31:55 +0200
Subject: [PATCH] Add params to AM_PROG_LEX

---
 m4/lex.m4          |  15 ++++++-
 t/lex-args.sh      | 104 +++++++++++++++++++++++++++++++++++++++++++++
 t/list-of-tests.mk |   1 +
 3 files changed, 118 insertions(+), 2 deletions(-)
 create mode 100644 t/lex-args.sh

diff --git a/m4/lex.m4 b/m4/lex.m4
index 7b0511526..bc3555773 100644
--- a/m4/lex.m4
+++ b/m4/lex.m4
@@ -10,10 +10,21 @@
 # -----------
 # Autoconf leaves LEX=: if lex or flex can't be found.  Change that to a
 # "missing" invocation, for better error output.
+# Make sure to pass any supported parameters (since Autoconf 2.70).
 AC_DEFUN([AM_PROG_LEX],
-[AC_PREREQ([2.50])dnl
+[AC_PREREQ([2.70])dnl
 AC_REQUIRE([AM_MISSING_HAS_RUN])dnl
-AC_REQUIRE([AC_PROG_LEX])dnl
+m4_define([params], [])dnl
+m4_case([$1],
+  [],         [m4_define([params], [])],
+  [yywrap],   [m4_define([params], [yywrap])],
+  [noyywrap], [m4_define([params], [noyywrap])],
+  [empty],    [m4_define([params], [])],
+  [m4_define([params], [])
+m4_warn([syntax], ['$0': calling AM_PROG_LEX with an unknown argument '$1'.
+You should use one of: 'yywrap', 'noyywrap', 'empty', or an empty value. Using an empty value.])])
+
+AC_PROG_LEX(m4_expand([params]))
 if test "$LEX" = :; then
   LEX=${am_missing_run}flex
 fi])
diff --git a/t/lex-args.sh b/t/lex-args.sh
new file mode 100644
index 000000000..eea1e34f6
--- /dev/null
+++ b/t/lex-args.sh
@@ -0,0 +1,104 @@
+#! /bin/sh
+# Copyright (C) 2023 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 <https://www.gnu.org/licenses/>.
+
+# Autoconf new requires AC_PROG_LEX to be called with either 'yywrap'
+# or 'noyywrap' as the parameter (previously, the macro had no parameters).
+# After updating AM_PROG_LEX, check that either the required parameter values
+# are passed down to AC_PROG_LEX, the defaults are used, or a warning is
+# issued (and the default is used).
+# (parts copied from t/lex-clean.sh)
+
+required='cc lex'
+. test-init.sh
+
+expected_errmsg='AC_PROG_LEX without either yywrap or noyywrap'
+
+cp configure.ac configure.bak
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = foo
+foo_SOURCES = main.c lexer.l
+LDADD = $(LEXLIB)
+END
+
+cat > lexer.l << 'END'
+%{
+#define YY_NO_UNISTD_H 1
+%}
+%%
+"GOOD"   return EOF;
+.
+END
+
+cat > main.c << 'END'
+int main (void) { return yylex (); }
+int yywrap (void) { return 1; }
+END
+
+for failing in '' '([empty])' '([])' '()';
+do
+	echo "============== Testing AM_PROG_LEX with >$failing<"
+
+	cat configure.bak - > configure.ac <<END
+AC_PROG_CC
+AM_PROG_LEX$failing
+AC_OUTPUT
+END
+	# debug:
+	#cat configure.ac
+
+	# aclocal seems required every time (at least, if 'make' would be run)
+	$ACLOCAL
+	# we expect the message, so missing is an error:
+	($AUTOCONF 2>&1 | grep "$expected_errmsg") \
+		|| (cat configure.ac && exit 1)
+	rm -rf autom4te*.cache
+done;
+
+for working in '([noyywrap])' '([yywrap])';
+do
+	echo "============== Testing AM_PROG_LEX with >$working<"
+
+	cat configure.bak - > configure.ac <<END
+AC_PROG_CC
+AM_PROG_LEX$working
+AC_OUTPUT
+END
+	# debug:
+	#cat configure.ac
+
+	$ACLOCAL
+	# we don't expect the message, so it is an error if found:
+	($AUTOCONF 2>&1 | grep "$expected_errmsg") \
+		&& cat configure.ac && exit 2
+	rm -rf autom4te*.cache
+done;
+
+echo "============== Testing AM_PROG_LEX with '([lex-blah])'"
+
+cat configure.bak - > configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_LEX([lex-blah])
+AC_OUTPUT
+END
+
+# debug:
+#cat configure.ac
+
+$ACLOCAL
+($AUTOCONF 2>&1 | grep lex-blah) || (cat configure.ac && exit 3)
+
+:
diff --git a/t/list-of-tests.mk b/t/list-of-tests.mk
index 94781d9b0..3701fb0bb 100644
--- a/t/list-of-tests.mk
+++ b/t/list-of-tests.mk
@@ -592,6 +592,7 @@ t/lex3.sh \
 t/lex5.sh \
 t/lexcpp.sh \
 t/lexvpath.sh \
+t/lex-args.sh \
 t/lex-subobj-nodep.sh \
 t/lex-header.sh \
 t/lex-lib.sh \
-- 
2.35.1

Reply via email to