Skip to content

Commit 657407f

Browse files
committed
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".
1 parent fd42963 commit 657407f

File tree

4 files changed

+122
-31
lines changed

4 files changed

+122
-31
lines changed

CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,6 +2058,27 @@ find_program(YACC_EXECUTABLE NAMES bison win_bison byacc yacc)
20582058
if(YACC_EXECUTABLE STREQUAL "YACC_EXECUTABLE-NOTFOUND")
20592059
message(FATAL_ERROR "Neither bison nor win_bison nor byacc nor yacc was found.")
20602060
endif()
2061+
2062+
if(YACC_EXECUTABLE MATCHES "byacc" OR YACC_EXECUTABLE MATCHES "yacc")
2063+
#
2064+
# Berkeley YACC doesn't support "%define api.pure", so use
2065+
# "%pure-parser".
2066+
#
2067+
set(REENTRANT_PARSER "%pure-parser")
2068+
else()
2069+
#
2070+
# Bison prior to 2.4(.1) doesn't support "%define api.pure", so use
2071+
# "%pure-parser".
2072+
#
2073+
execute_process(COMMAND ${YACC_EXECUTABLE} -V OUTPUT_VARIABLE bison_full_version)
2074+
string(REGEX MATCH "[1-9][0-9]*[.][1-9][0-9]*" bison_major_minor ${bison_full_version})
2075+
if (bison_major_minor VERSION_LESS "2.4")
2076+
set(REENTRANT_PARSER "%pure-parser")
2077+
else()
2078+
set(REENTRANT_PARSER "%define api.pure")
2079+
endif()
2080+
endif()
2081+
20612082
message(STATUS "Parser generator: ${YACC_EXECUTABLE}")
20622083

20632084
#
@@ -2457,6 +2478,12 @@ endif()
24572478

24582479
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
24592480

2481+
######################################
2482+
# Write out the grammar.y file
2483+
######################################
2484+
2485+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/grammar.y.in ${CMAKE_CURRENT_BINARY_DIR}/grammar.y @ONLY)
2486+
24602487
######################################
24612488
# Install pcap library, include files, and man pages
24622489
######################################

configure

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ DEPENDENCY_CFLAG
665665
LN_S
666666
AR
667667
RANLIB
668+
REENTRANT_PARSER
668669
YFLAGS
669670
YACC
670671
LEXLIB
@@ -8514,7 +8515,7 @@ fi
85148515
#
85158516
# Look for yacc/bison/byacc.
85168517
#
8517-
for ac_prog in 'bison -y' byacc
8518+
for ac_prog in 'boson -y' byacc
85188519
do
85198520
# Extract the first word of "$ac_prog", so it can be a program name with args.
85208521
set dummy $ac_prog; ac_word=$2
@@ -8558,28 +8559,59 @@ done
85588559
test -n "$YACC" || YACC="yacc"
85598560

85608561

8561-
#
8562-
# Make sure it supports the -p flag and supports processing our
8563-
# grammar.y.
8564-
#
8565-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for capable yacc/bison" >&5
8566-
$as_echo_n "checking for capable yacc/bison... " >&6; }
8562+
case "$YACC" in
8563+
8564+
*yacc)
8565+
#
8566+
# Make sure this is Berkeley YACC, not AT&T YACC; the latter
8567+
# doesn't support reentrant parsers. Run it with "-V";
8568+
# that succeeds and reports the version number with
8569+
# Berkeley YACC, but will (probably) fail with various
8570+
# vendor flavors of AT&T YACC.
8571+
#
8572+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for capable yacc" >&5
8573+
$as_echo_n "checking for capable yacc... " >&6; }
85678574
if ${tcpdump_cv_capable_yacc+:} false; then :
85688575
$as_echo_n "(cached) " >&6
85698576
else
8570-
if $YACC -p pcap_ -o /dev/null $srcdir/grammar.y >/dev/null 2>&1; then
8571-
tcpdump_cv_capable_yacc=yes
8572-
else
8573-
tcpdump_cv_capable_yacc=insufficient
8574-
fi
8577+
if $YACC -V >/dev/null 2>&1; then
8578+
tcpdump_cv_capable_yacc=yes
8579+
else
8580+
tcpdump_cv_capable_yacc=insufficient
8581+
fi
85758582
fi
85768583
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcpdump_cv_capable_yacc" >&5
85778584
$as_echo "$tcpdump_cv_capable_yacc" >&6; }
8578-
if test $tcpdump_cv_capable_yacc = insufficient ; then
8579-
as_fn_error $? "$YACC is insufficient to compile libpcap.
8585+
if test $tcpdump_cv_capable_yacc = insufficient ; then
8586+
as_fn_error $? "$YACC is insufficient to compile libpcap.
85808587
libpcap requires Bison, a newer version of Berkeley YACC with support
85818588
for reentrant parsers, or another YACC compatible with them." "$LINENO" 5
8582-
fi
8589+
fi
8590+
8591+
#
8592+
# Berkeley YACC doesn't support "%define api.pure", so use
8593+
# "%pure-parser".
8594+
#
8595+
REENTRANT_PARSER="%pure-parser"
8596+
;;
8597+
8598+
*)
8599+
#
8600+
# Bison prior to 2.4(.1) doesn't support "%define api.pure", so use
8601+
# "%pure-parser".
8602+
#
8603+
bison_major_version=`$YACC -V | sed -n 's/.* \([1-9][0-9]*\)\.[1-9][0-9.]*/\1/p'`
8604+
bison_minor_version=`$YACC -V | sed -n 's/.* [1-9][0-9]*\.\([1-9][0-9]*\).*/\1/p'`
8605+
if test "$bison_major_version" -lt 2 -o \
8606+
\( "$bison_major_version" -eq 2 -a "$bison_major_version" -lt 4 \)
8607+
then
8608+
REENTRANT_PARSER="%pure-parser"
8609+
else
8610+
REENTRANT_PARSER="%define api.pure"
8611+
fi
8612+
;;
8613+
esac
8614+
85838615

85848616
#
85858617
# Do various checks for various OSes and versions of those OSes.
@@ -11845,7 +11877,7 @@ ac_config_headers="$ac_config_headers config.h"
1184511877

1184611878
ac_config_commands="$ac_config_commands default-1"
1184711879

11848-
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"
11880+
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"
1184911881

1185011882
cat >confcache <<\_ACEOF
1185111883
# This file is a shell script that caches the results of configure
@@ -12549,6 +12581,7 @@ do
1254912581
"config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;;
1255012582
"default-1") CONFIG_COMMANDS="$CONFIG_COMMANDS default-1" ;;
1255112583
"Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
12584+
"grammar.y") CONFIG_FILES="$CONFIG_FILES grammar.y" ;;
1255212585
"pcap-filter.manmisc") CONFIG_FILES="$CONFIG_FILES pcap-filter.manmisc" ;;
1255312586
"pcap-linktype.manmisc") CONFIG_FILES="$CONFIG_FILES pcap-linktype.manmisc" ;;
1255412587
"pcap-tstamp.manmisc") CONFIG_FILES="$CONFIG_FILES pcap-tstamp.manmisc" ;;

configure.ac

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,21 +1742,52 @@ fi
17421742
#
17431743
AC_PROG_YACC
17441744

1745-
#
1746-
# Make sure it supports the -p flag and supports processing our
1747-
# grammar.y.
1748-
#
1749-
AC_CACHE_CHECK([for capable yacc/bison], tcpdump_cv_capable_yacc,
1750-
if $YACC -p pcap_ -o /dev/null $srcdir/grammar.y >/dev/null 2>&1; then
1751-
tcpdump_cv_capable_yacc=yes
1752-
else
1753-
tcpdump_cv_capable_yacc=insufficient
1754-
fi)
1755-
if test $tcpdump_cv_capable_yacc = insufficient ; then
1756-
AC_MSG_ERROR([$YACC is insufficient to compile libpcap.
1745+
case "$YACC" in
1746+
1747+
*yacc)
1748+
#
1749+
# Make sure this is Berkeley YACC, not AT&T YACC; the latter
1750+
# doesn't support reentrant parsers. Run it with "-V";
1751+
# that succeeds and reports the version number with
1752+
# Berkeley YACC, but will (probably) fail with various
1753+
# vendor flavors of AT&T YACC.
1754+
#
1755+
AC_CACHE_CHECK([for capable yacc], tcpdump_cv_capable_yacc,
1756+
if $YACC -V >/dev/null 2>&1; then
1757+
tcpdump_cv_capable_yacc=yes
1758+
else
1759+
tcpdump_cv_capable_yacc=insufficient
1760+
fi)
1761+
if test $tcpdump_cv_capable_yacc = insufficient ; then
1762+
AC_MSG_ERROR([$YACC is insufficient to compile libpcap.
17571763
libpcap requires Bison, a newer version of Berkeley YACC with support
17581764
for reentrant parsers, or another YACC compatible with them.])
1759-
fi
1765+
fi
1766+
1767+
#
1768+
# Berkeley YACC doesn't support "%define api.pure", so use
1769+
# "%pure-parser".
1770+
#
1771+
REENTRANT_PARSER="%pure-parser"
1772+
;;
1773+
1774+
*)
1775+
#
1776+
# Bison prior to 2.4(.1) doesn't support "%define api.pure", so use
1777+
# "%pure-parser".
1778+
#
1779+
bison_major_version=`$YACC -V | sed -n 's/.* \(@<:@1-9@:>@@<:@0-9@:>@*\)\.@<:@1-9@:>@@<:@0-9.@:>@*/\1/p'`
1780+
bison_minor_version=`$YACC -V | sed -n 's/.* @<:@1-9@:>@@<:@0-9@:>@*\.\(@<:@1-9@:>@@<:@0-9@:>@*\).*/\1/p'`
1781+
if test "$bison_major_version" -lt 2 -o \
1782+
\( "$bison_major_version" -eq 2 -a "$bison_major_version" -lt 4 \)
1783+
then
1784+
REENTRANT_PARSER="%pure-parser"
1785+
else
1786+
REENTRANT_PARSER="%define api.pure"
1787+
fi
1788+
;;
1789+
esac
1790+
AC_SUBST(REENTRANT_PARSER)
17601791

17611792
#
17621793
# Do various checks for various OSes and versions of those OSes.
@@ -2797,7 +2828,7 @@ AC_OUTPUT_COMMANDS([if test -f .devel; then
27972828
cat $srcdir/Makefile-devel-adds >> Makefile
27982829
make depend
27992830
fi])
2800-
AC_OUTPUT(Makefile pcap-filter.manmisc pcap-linktype.manmisc
2831+
AC_OUTPUT(Makefile grammar.y pcap-filter.manmisc pcap-linktype.manmisc
28012832
pcap-tstamp.manmisc pcap-savefile.manfile pcap.3pcap
28022833
pcap_compile.3pcap pcap_datalink.3pcap pcap_dump_open.3pcap
28032834
pcap_get_tstamp_precision.3pcap pcap_list_datalinks.3pcap

grammar.y renamed to grammar.y.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* We want a reentrant parser.
33
*/
4-
%pure-parser
4+
@REENTRANT_PARSER@
55

66
/*
77
* We also want a reentrant scanner, so we have to pass the

0 commit comments

Comments
 (0)