diff options
author | Guy Harris <gharris@sonic.net> | 2020-10-19 15:26:37 -0700 |
---|---|---|
committer | Guy Harris <gharris@sonic.net> | 2020-10-19 15:26:37 -0700 |
commit | 657407ff45e268eb8659842543f9a0f74569d2de (patch) | |
tree | ace86909d5310700dbb2fcb81f2f76a68802acec | |
parent | fd429636811d9b2c3564b09df81649e55d37d13c (diff) | |
download | libpcap-657407ff45e268eb8659842543f9a0f74569d2de.tar.gz |
Use "%define api.pure" if supported, otherwise use "%pure-parser".
That squelches whining from Bison about "%define api.pure" being
deprecated without breaking builds if you have an older versions of
Bison that doesn't support "%define api.pure" or if you have Berkeley
YACC, which doesn't support "%define api.pure".
-rw-r--r-- | CMakeLists.txt | 27 | ||||
-rwxr-xr-x | configure | 65 | ||||
-rw-r--r-- | configure.ac | 59 | ||||
-rw-r--r-- | grammar.y.in (renamed from grammar.y) | 2 |
4 files changed, 122 insertions, 31 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index ddbe4a63..4bdedccd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2058,6 +2058,27 @@ find_program(YACC_EXECUTABLE NAMES bison win_bison byacc yacc) if(YACC_EXECUTABLE STREQUAL "YACC_EXECUTABLE-NOTFOUND") message(FATAL_ERROR "Neither bison nor win_bison nor byacc nor yacc was found.") endif() + +if(YACC_EXECUTABLE MATCHES "byacc" OR YACC_EXECUTABLE MATCHES "yacc") + # + # Berkeley YACC doesn't support "%define api.pure", so use + # "%pure-parser". + # + set(REENTRANT_PARSER "%pure-parser") +else() + # + # Bison prior to 2.4(.1) doesn't support "%define api.pure", so use + # "%pure-parser". + # + execute_process(COMMAND ${YACC_EXECUTABLE} -V OUTPUT_VARIABLE bison_full_version) + string(REGEX MATCH "[1-9][0-9]*[.][1-9][0-9]*" bison_major_minor ${bison_full_version}) + if (bison_major_minor VERSION_LESS "2.4") + set(REENTRANT_PARSER "%pure-parser") + else() + set(REENTRANT_PARSER "%define api.pure") + endif() +endif() + message(STATUS "Parser generator: ${YACC_EXECUTABLE}") # @@ -2458,6 +2479,12 @@ endif() configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h) ###################################### +# Write out the grammar.y file +###################################### + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/grammar.y.in ${CMAKE_CURRENT_BINARY_DIR}/grammar.y @ONLY) + +###################################### # Install pcap library, include files, and man pages ###################################### @@ -665,6 +665,7 @@ DEPENDENCY_CFLAG LN_S AR RANLIB +REENTRANT_PARSER YFLAGS YACC LEXLIB @@ -8514,7 +8515,7 @@ fi # # Look for yacc/bison/byacc. # -for ac_prog in 'bison -y' byacc +for ac_prog in 'boson -y' byacc do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 @@ -8558,28 +8559,59 @@ done test -n "$YACC" || YACC="yacc" -# -# Make sure it supports the -p flag and supports processing our -# grammar.y. -# -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for capable yacc/bison" >&5 -$as_echo_n "checking for capable yacc/bison... " >&6; } +case "$YACC" in + +*yacc) + # + # Make sure this is Berkeley YACC, not AT&T YACC; the latter + # doesn't support reentrant parsers. Run it with "-V"; + # that succeeds and reports the version number with + # Berkeley YACC, but will (probably) fail with various + # vendor flavors of AT&T YACC. + # + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for capable yacc" >&5 +$as_echo_n "checking for capable yacc... " >&6; } if ${tcpdump_cv_capable_yacc+:} false; then : $as_echo_n "(cached) " >&6 else - if $YACC -p pcap_ -o /dev/null $srcdir/grammar.y >/dev/null 2>&1; then - tcpdump_cv_capable_yacc=yes - else - tcpdump_cv_capable_yacc=insufficient - fi + if $YACC -V >/dev/null 2>&1; then + tcpdump_cv_capable_yacc=yes + else + tcpdump_cv_capable_yacc=insufficient + fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcpdump_cv_capable_yacc" >&5 $as_echo "$tcpdump_cv_capable_yacc" >&6; } -if test $tcpdump_cv_capable_yacc = insufficient ; then - as_fn_error $? "$YACC is insufficient to compile libpcap. + if test $tcpdump_cv_capable_yacc = insufficient ; then + as_fn_error $? "$YACC is insufficient to compile libpcap. libpcap requires Bison, a newer version of Berkeley YACC with support for reentrant parsers, or another YACC compatible with them." "$LINENO" 5 -fi + fi + + # + # Berkeley YACC doesn't support "%define api.pure", so use + # "%pure-parser". + # + REENTRANT_PARSER="%pure-parser" + ;; + +*) + # + # Bison prior to 2.4(.1) doesn't support "%define api.pure", so use + # "%pure-parser". + # + bison_major_version=`$YACC -V | sed -n 's/.* \([1-9][0-9]*\)\.[1-9][0-9.]*/\1/p'` + bison_minor_version=`$YACC -V | sed -n 's/.* [1-9][0-9]*\.\([1-9][0-9]*\).*/\1/p'` + if test "$bison_major_version" -lt 2 -o \ + \( "$bison_major_version" -eq 2 -a "$bison_major_version" -lt 4 \) + then + REENTRANT_PARSER="%pure-parser" + else + REENTRANT_PARSER="%define api.pure" + fi + ;; +esac + # # Do various checks for various OSes and versions of those OSes. @@ -11845,7 +11877,7 @@ ac_config_headers="$ac_config_headers config.h" ac_config_commands="$ac_config_commands default-1" -ac_config_files="$ac_config_files Makefile pcap-filter.manmisc pcap-linktype.manmisc pcap-tstamp.manmisc pcap-savefile.manfile pcap.3pcap pcap_compile.3pcap pcap_datalink.3pcap pcap_dump_open.3pcap pcap_get_tstamp_precision.3pcap pcap_list_datalinks.3pcap pcap_list_tstamp_types.3pcap pcap_open_dead.3pcap pcap_open_offline.3pcap pcap_set_immediate_mode.3pcap pcap_set_tstamp_precision.3pcap pcap_set_tstamp_type.3pcap rpcapd/Makefile rpcapd/rpcapd.manadmin rpcapd/rpcapd-config.manfile testprogs/Makefile" +ac_config_files="$ac_config_files Makefile grammar.y pcap-filter.manmisc pcap-linktype.manmisc pcap-tstamp.manmisc pcap-savefile.manfile pcap.3pcap pcap_compile.3pcap pcap_datalink.3pcap pcap_dump_open.3pcap pcap_get_tstamp_precision.3pcap pcap_list_datalinks.3pcap pcap_list_tstamp_types.3pcap pcap_open_dead.3pcap pcap_open_offline.3pcap pcap_set_immediate_mode.3pcap pcap_set_tstamp_precision.3pcap pcap_set_tstamp_type.3pcap rpcapd/Makefile rpcapd/rpcapd.manadmin rpcapd/rpcapd-config.manfile testprogs/Makefile" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -12549,6 +12581,7 @@ do "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; "default-1") CONFIG_COMMANDS="$CONFIG_COMMANDS default-1" ;; "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; + "grammar.y") CONFIG_FILES="$CONFIG_FILES grammar.y" ;; "pcap-filter.manmisc") CONFIG_FILES="$CONFIG_FILES pcap-filter.manmisc" ;; "pcap-linktype.manmisc") CONFIG_FILES="$CONFIG_FILES pcap-linktype.manmisc" ;; "pcap-tstamp.manmisc") CONFIG_FILES="$CONFIG_FILES pcap-tstamp.manmisc" ;; diff --git a/configure.ac b/configure.ac index ac3cc7b7..2ad28bbe 100644 --- a/configure.ac +++ b/configure.ac @@ -1742,21 +1742,52 @@ fi # AC_PROG_YACC -# -# Make sure it supports the -p flag and supports processing our -# grammar.y. -# -AC_CACHE_CHECK([for capable yacc/bison], tcpdump_cv_capable_yacc, - if $YACC -p pcap_ -o /dev/null $srcdir/grammar.y >/dev/null 2>&1; then - tcpdump_cv_capable_yacc=yes - else - tcpdump_cv_capable_yacc=insufficient - fi) -if test $tcpdump_cv_capable_yacc = insufficient ; then - AC_MSG_ERROR([$YACC is insufficient to compile libpcap. +case "$YACC" in + +*yacc) + # + # Make sure this is Berkeley YACC, not AT&T YACC; the latter + # doesn't support reentrant parsers. Run it with "-V"; + # that succeeds and reports the version number with + # Berkeley YACC, but will (probably) fail with various + # vendor flavors of AT&T YACC. + # + AC_CACHE_CHECK([for capable yacc], tcpdump_cv_capable_yacc, + if $YACC -V >/dev/null 2>&1; then + tcpdump_cv_capable_yacc=yes + else + tcpdump_cv_capable_yacc=insufficient + fi) + if test $tcpdump_cv_capable_yacc = insufficient ; then + AC_MSG_ERROR([$YACC is insufficient to compile libpcap. libpcap requires Bison, a newer version of Berkeley YACC with support for reentrant parsers, or another YACC compatible with them.]) -fi + fi + + # + # Berkeley YACC doesn't support "%define api.pure", so use + # "%pure-parser". + # + REENTRANT_PARSER="%pure-parser" + ;; + +*) + # + # Bison prior to 2.4(.1) doesn't support "%define api.pure", so use + # "%pure-parser". + # + bison_major_version=`$YACC -V | sed -n 's/.* \(@<:@1-9@:>@@<:@0-9@:>@*\)\.@<:@1-9@:>@@<:@0-9.@:>@*/\1/p'` + bison_minor_version=`$YACC -V | sed -n 's/.* @<:@1-9@:>@@<:@0-9@:>@*\.\(@<:@1-9@:>@@<:@0-9@:>@*\).*/\1/p'` + if test "$bison_major_version" -lt 2 -o \ + \( "$bison_major_version" -eq 2 -a "$bison_major_version" -lt 4 \) + then + REENTRANT_PARSER="%pure-parser" + else + REENTRANT_PARSER="%define api.pure" + fi + ;; +esac +AC_SUBST(REENTRANT_PARSER) # # Do various checks for various OSes and versions of those OSes. @@ -2797,7 +2828,7 @@ AC_OUTPUT_COMMANDS([if test -f .devel; then cat $srcdir/Makefile-devel-adds >> Makefile make depend fi]) -AC_OUTPUT(Makefile pcap-filter.manmisc pcap-linktype.manmisc +AC_OUTPUT(Makefile grammar.y pcap-filter.manmisc pcap-linktype.manmisc pcap-tstamp.manmisc pcap-savefile.manfile pcap.3pcap pcap_compile.3pcap pcap_datalink.3pcap pcap_dump_open.3pcap pcap_get_tstamp_precision.3pcap pcap_list_datalinks.3pcap diff --git a/grammar.y b/grammar.y.in index 8492378e..fe565155 100644 --- a/grammar.y +++ b/grammar.y.in @@ -1,7 +1,7 @@ /* * We want a reentrant parser. */ -%pure-parser +@REENTRANT_PARSER@ /* * We also want a reentrant scanner, so we have to pass the |