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 . + +# 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 <&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 <&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