Refactor PHP_PROG_BISON and PHP_PROG_RE2C

This patch refactors these macros to also checks for the required given
versions of bison and re2c.

- PHP_PROG_RE2C and PHP_PROG_BISON take optional args - minmimum version
  required, and bison also excluded versions.
- Instead of caching values this uses manual checking and messaging
  outputs.
- It looks like the minimum version of RE2C 0.13.4 is working ok so far.

The genfiles script improvements:
- Add make override in genfiles
- Move checkings from makedist to genfiles
- Refactored output messages
- Various minor enhancements
This commit is contained in:
Peter Kokot 2019-03-17 16:22:02 +01:00
parent 072eb6dd77
commit 3207741df0
7 changed files with 195 additions and 127 deletions

View File

@ -3,11 +3,8 @@ dnl This file contains Zend specific autoconf functions.
dnl
AC_DEFUN([LIBZEND_BASIC_CHECKS],[
AC_REQUIRE([AC_PROG_CC])
LIBZEND_BISON_CHECK
AC_CHECK_HEADERS(
inttypes.h \
stdint.h \

View File

@ -1,47 +1,5 @@
dnl This file contains local autoconf functions.
AC_DEFUN([LIBZEND_BISON_CHECK],[
# we only support certain bison versions;
# min: 2.4 (i.e. 204, major * 100 + minor for easier comparison)
bison_version_min="300"
# non-working versions, e.g. "3.0 3.2";
# remove "none" when introducing the first incompatible bison version an
# separate any following additions by spaces
bison_version_exclude=""
# for standalone build of Zend Engine
test -z "$SED" && SED=sed
bison_version=none
if test "$YACC"; then
AC_CACHE_CHECK([for bison version], php_cv_bison_version, [
bison_version_vars=`$YACC --version 2> /dev/null | grep 'GNU Bison' | cut -d ' ' -f 4 | $SED -e 's/\./ /g' | tr -d a-z`
php_cv_bison_version=invalid
if test -n "$bison_version_vars"; then
set $bison_version_vars
bison_version="${1}.${2}"
bison_version_num="`expr ${1} \* 100 + ${2}`"
if test $bison_version_num -ge $bison_version_min; then
php_cv_bison_version="$bison_version (ok)"
for bison_check_version in $bison_version_exclude; do
if test "$bison_version" = "$bison_check_version"; then
php_cv_bison_version=invalid
break
fi
done
fi
fi
])
fi
case $php_cv_bison_version in
""|invalid[)]
bison_msg="This bison version is not supported for regeneration of the Zend/PHP parsers (found: $bison_version, min: $bison_version_min, excluded: $bison_version_exclude)."
AC_MSG_WARN([$bison_msg])
YACC="exit 0;"
;;
esac
])
dnl x87 floating point internal precision control checks
dnl See: http://wiki.php.net/rfc/rounding
AC_DEFUN([ZEND_CHECK_FLOAT_PRECISION],[

View File

@ -1818,44 +1818,126 @@ AC_DEFUN([PHP_PROG_AWK], [
])
dnl
dnl PHP_PROG_BISON
dnl PHP_PROG_BISON([MIN-VERSION], [EXCLUDED-VERSION...])
dnl
dnl Search for bison and check it's version
dnl Search for bison and optionally check if version is at least the minimum
dnl required version MIN-VERSION and doesn't match any of the blank separated
dnl list of excluded versions EXCLUDED-VERSION (for example "3.0 3.2").
dnl
AC_DEFUN([PHP_PROG_BISON], [
AC_CHECK_PROG(YACC, bison, bison)
LIBZEND_BISON_CHECK
ifelse($1,,php_bison_required_version='',php_bison_required_version="$1")
ifelse($2,,php_bison_excluded_versions='none',php_bison_excluded_versions="$2")
if test -n "$YACC"; then
AC_MSG_CHECKING([for bison version])
php_bison_version=$($YACC --version 2> /dev/null | grep 'GNU Bison' | cut -d ' ' -f 4 | tr -d a-z)
ac_IFS=$IFS; IFS="."
set $php_bison_version
IFS=$ac_IFS
php_bison_num=`expr [$]{1:-0} \* 10000 + [$]{2:-0} \* 100 + [$]{3:-0}`
php_bison_branch="[$]1.[$]2"
php_bison_check=ok
if test -z "$php_bison_required_version" && test -z "$php_bison_num"; then
php_bison_check=invalid
elif test -n "$php_bison_required_version"; then
ac_IFS=$IFS; IFS="."
set $php_bison_required_version
IFS=$ac_IFS
php_bison_required_num=`expr [$]{1:-0} \* 10000 + [$]{2:-0} \* 100 + [$]{3:-0}`
php_bison_required_version="$php_bison_required_version or later"
if test -z "$php_bison_num" || test "$php_bison_num" -lt "$php_bison_required_num"; then
php_bison_check=invalid
fi
fi
for php_bison_check_version in $php_bison_excluded_versions; do
if test "$php_bison_version" = "$php_bison_check_version" || test "$php_bison_branch" = "$php_bison_check_version"; then
php_bison_check=invalid
break
fi
done
if test "$php_bison_check" != "invalid"; then
AC_MSG_RESULT([$php_bison_version (ok)])
else
AC_MSG_RESULT([$php_bison_version])
fi
fi
case $php_bison_check in
""|invalid[)]
if test -f "$abs_srcdir/Zend/zend_language_parser.h" && test -f "$abs_srcdir/Zend/zend_language_parser.c"; then
AC_MSG_WARN([bison $php_bison_required_version is required if you want to regenerate PHP parsers (excluded versions: $php_bison_excluded_versions)])
else
AC_MSG_ERROR([bison $php_bison_required_version is required to generate PHP parsers (excluded versions: $php_bison_excluded_versions).])
fi
YACC="exit 0;"
;;
esac
PHP_SUBST(YACC)
])
dnl
dnl PHP_PROG_RE2C
dnl PHP_PROG_RE2C([MIN-VERSION])
dnl
dnl Search for the re2c binary and check the version
dnl Search for the re2c and optionally check if version is at least the minimum
dnl required version MIN-VERSION.
dnl
AC_DEFUN([PHP_PROG_RE2C],[
AC_CHECK_PROG(RE2C, re2c, re2c)
ifelse($1,,php_re2c_required_version='',php_re2c_required_version="$1")
if test -n "$RE2C"; then
AC_CACHE_CHECK([for re2c version], php_cv_re2c_version, [
re2c_vernum=`$RE2C --vernum 2>/dev/null`
if test -z "$re2c_vernum" || test "$re2c_vernum" -lt "1304"; then
php_cv_re2c_version=invalid
else
php_cv_re2c_version="`$RE2C --version | cut -d ' ' -f 2 2>/dev/null` (ok)"
AC_MSG_CHECKING([for re2c version])
php_re2c_version=$($RE2C --version | cut -d ' ' -f 2 2>/dev/null)
ac_IFS=$IFS; IFS="."
set $php_re2c_version
IFS=$ac_IFS
php_re2c_num=`expr [$]{1:-0} \* 10000 + [$]{2:-0} \* 100 + [$]{3:-0}`
php_re2c_check=ok
if test -z "$php_re2c_required_version" && test -z "$php_re2c_num"; then
php_re2c_check=invalid
elif test -n "$php_re2c_required_version"; then
ac_IFS=$IFS; IFS="."
set $php_re2c_required_version
IFS=$ac_IFS
php_re2c_required_num=`expr [$]{1:-0} \* 10000 + [$]{2:-0} \* 100 + [$]{3:-0}`
php_re2c_required_version="$php_re2c_required_version or later"
if test -z "$php_re2c_num" || test "$php_re2c_num" -lt "$php_re2c_required_num"; then
php_re2c_check=invalid
fi
])
fi
if test "$php_re2c_check" != "invalid"; then
AC_MSG_RESULT([$php_re2c_version (ok)])
else
AC_MSG_RESULT([$php_re2c_version])
fi
fi
case $php_cv_re2c_version in
case $php_re2c_check in
""|invalid[)]
if test -f "$abs_srcdir/Zend/zend_language_scanner.c"; then
AC_MSG_WARN([You will need re2c 0.13.4 or later if you want to regenerate PHP lexers.])
AC_MSG_WARN([re2c $php_re2c_required_version is required if you want to regenerate PHP lexers.])
else
AC_MSG_ERROR([You will need re2c 0.13.4 or later to generate PHP lexers.])
AC_MSG_ERROR([re2c $php_re2c_required_version is required to generate PHP lexers.])
fi
RE2C="exit 0;"
;;
esac
PHP_SUBST(RE2C)
])

View File

@ -194,17 +194,8 @@ PHP_RUNPATH_SWITCH
dnl Checks for some support/generator progs
PHP_PROG_AWK
PHP_PROG_BISON
PHP_PROG_RE2C
dnl Check if bison generated files exist when bison does not..
case $php_cv_bison_version in
""|invalid[)]
if ! test -f "$abs_srcdir/Zend/zend_language_parser.h" || ! test -f "$abs_srcdir/Zend/zend_language_parser.c" ; then
AC_MSG_ERROR([bison is required to build PHP/Zend when building a GIT checkout!])
fi
;;
esac
PHP_PROG_BISON([3.0.0])
PHP_PROG_RE2C([0.13.4])
PHP_ARG_ENABLE([re2c-cgoto],
[whether to enable computed goto gcc extension with re2c],

View File

@ -29,60 +29,110 @@
#
# YACC Parser generator program, default bison
# RE2C Lexer generator program, default re2c
# SED Path to sed program, default sed
# MAKE Path to make program, default make
#
# For example:
# YACC=/path/to/bison ./genfiles
# Parser generator
YACC=${YACC:-bison}
YACC="$YACC -l"
# Lexer generator
RE2C=${RE2C:-re2c}
RE2C_FLAGS="-i"
SED=${SED:-sed}
MAKE=${MAKE:-make}
# Current path to return to it later. This enables running script from any path.
original_path=`pwd`
# Go to project root.
cd $(CDPATH= cd -- "$(dirname -- "$0")/../../" && pwd -P)
# Project root directory
project_root=`CDPATH= cd -- "$(dirname -- "$0")/../../" && pwd -P`
cd $project_root
# Check required bison version from the configure.ac file.
required_bison_version=$($SED -n 's/PHP_PROG_BISON(\[\([0-9\.]*\)\].*/\1/p' configure.ac)
set -f; IFS='.'; set -- $required_bison_version; set +f; IFS=' '
required_bison_num="$(expr ${1:-0} \* 10000 + ${2:-0} \* 100 + ${3:-0})"
echo "Generating Zend parser and lexer files"
make RE2C="$RE2C" RE2C_FLAGS="$RE2C_FLAGS" YACC="$YACC" srcdir=Zend builddir=Zend top_srcdir=. \
current_version=$($YACC --version 2> /dev/null | grep 'GNU Bison' | cut -d ' ' -f 4 | tr -d a-z)
set -f; IFS='.'; set -- $current_version; set +f; IFS=' '
current_bison_num="$(expr ${1:-0} \* 10000 + ${2:-0} \* 100 + ${3:-0})"
if test -z "$current_version"; then
echo "genfiles: bison not found." >&2
echo " You need bison version $required_bison_version or newer installed" >&2
echo " to regenerate parser files." >&2
exit 1
fi
if test "$current_bison_num" -lt "$required_bison_num"; then
echo "genfiles: bison version $current_version found." >&2
echo " You need bison version $required_bison_version or newer installed" >&2
echo " to build parser files." >&2
exit 1
else
echo "genfiles: bison version $current_version (ok)"
fi
# Check required re2c version from the configure.ac file.
required_re2c_version=$($SED -n 's/PHP_PROG_RE2C(\[\(.*\)\])/\1/p' configure.ac)
set -f; IFS='.'; set -- $required_re2c_version; set +f; IFS=' '
required_re2c_num="$(expr ${1:-0} \* 10000 + ${2:-0} \* 100 + ${3:-0})"
current_version="$($RE2C --version | cut -d ' ' -f 2 2>/dev/null)"
set -f; IFS='.'; set -- $current_version; set +f; IFS=' '
current_re2c_num="$(expr ${1:-0} \* 10000 + ${2:-0} \* 100 + ${3:-0})"
if test -z "$current_version"; then
echo "genfiles: re2c not found." >&2
echo " You need re2c version $required_re2c_version or newer installed" >&2
echo " to regenerate lexer files." >&2
exit 1
fi
if test "$current_re2c_num" -lt "$required_re2c_num"; then
echo "genfiles: re2c version $current_version found." >&2
echo " You need re2c version $required_re2c_version or newer installed" >&2
echo " to build lexer files." >&2
exit 1
else
echo "genfiles: re2c version $current_version (ok)"
fi
# Check if make exists.
if ! test -x "$(command -v $MAKE)"; then
echo "genfiles: make not found. Please install make to generate files." >&2
exit 1
fi
echo "genfiles: Generating Zend parser and lexer files"
$MAKE RE2C="$RE2C" RE2C_FLAGS="$RE2C_FLAGS" YACC="$YACC" srcdir=Zend builddir=Zend top_srcdir=. \
-f Zend/Makefile.frag \
Zend/zend_language_parser.c \
Zend/zend_language_scanner.c \
Zend/zend_ini_parser.c \
Zend/zend_ini_scanner.c
echo "Generating phpdbg parser and lexer files"
make RE2C="$RE2C" RE2C_FLAGS="$RE2C_FLAGS" YACC="$YACC" srcdir=sapi/phpdbg builddir=sapi/phpdbg top_srcdir=. \
echo "genfiles: Generating phpdbg parser and lexer files"
$MAKE RE2C="$RE2C" RE2C_FLAGS="$RE2C_FLAGS" YACC="$YACC" srcdir=sapi/phpdbg builddir=sapi/phpdbg top_srcdir=. \
-f sapi/phpdbg/Makefile.frag \
sapi/phpdbg/phpdbg_parser.c \
sapi/phpdbg/phpdbg_lexer.c
echo "Generating json extension parser and lexer files"
make RE2C="$RE2C" RE2C_FLAGS="$RE2C_FLAGS" YACC="$YACC" srcdir=ext/json builddir=ext/json top_srcdir=. \
echo "genfiles: enerating json extension parser and lexer files"
$MAKE RE2C="$RE2C" RE2C_FLAGS="$RE2C_FLAGS" YACC="$YACC" srcdir=ext/json builddir=ext/json top_srcdir=. \
-f ext/json/Makefile.frag \
ext/json/json_parser.tab.c \
ext/json/json_scanner.c
echo "Generating PDO lexer file"
make RE2C="$RE2C" RE2C_FLAGS="$RE2C_FLAGS" srcdir=ext/pdo builddir=ext/pdo top_srcdir=. \
echo "genfiles: Generating PDO lexer file"
$MAKE RE2C="$RE2C" RE2C_FLAGS="$RE2C_FLAGS" srcdir=ext/pdo builddir=ext/pdo top_srcdir=. \
-f ext/pdo/Makefile.frag \
ext/pdo/pdo_sql_parser.c
echo "Generating standard extension lexer files"
make RE2C="$RE2C" RE2C_FLAGS="$RE2C_FLAGS" srcdir=ext/standard builddir=ext/standard top_srcdir=. \
echo "genfiles: Generating standard extension lexer files"
$MAKE RE2C="$RE2C" RE2C_FLAGS="$RE2C_FLAGS" srcdir=ext/standard builddir=ext/standard top_srcdir=. \
-f ext/standard/Makefile.frag \
ext/standard/var_unserializer.c \
ext/standard/url_scanner_ex.c
echo "Generating phar extension lexer file"
make RE2C="$RE2C" RE2C_FLAGS="$RE2C_FLAGS" srcdir=ext/phar builddir=ext/phar top_srcdir=. \
echo "genfiles: Generating phar extension lexer file"
$MAKE RE2C="$RE2C" RE2C_FLAGS="$RE2C_FLAGS" srcdir=ext/phar builddir=ext/phar top_srcdir=. \
-f ext/phar/Makefile.frag \
ext/phar/phar_path_check.c
# Return to the original directory.
cd $original_path

View File

@ -22,39 +22,25 @@
cd $(CDPATH= cd -- "$(dirname -- "$0")/../../" && pwd -P)
if test "$#" != "1"; then
echo "Usage: makedist <version>" >&2
exit 1
echo "Usage: makedist <version>" >&2
exit 1
fi
VER=$1 ; shift
old_IFS="$IFS"
IFS=.
eval set `bison --version| grep 'GNU Bison' | cut -d ' ' -f 4 | sed -e 's/\./ /g'`
if test "${1}" -lt "3" -o "${1}" = "3" -a "${2}" -eq "0" -a "${3}" -lt "2"; then
echo "You will need bison >= 3.0.2 if you want to regenerate the Zend parser (found ${1}.${2}.${3})."
exit 2
fi
eval set `re2c --version| grep 're2c' | cut -d ' ' -f 2 | sed -e 's/\./ /g'`
if test "${2}" -lt "13" -o "${2}" -eq "13" -a "${3}" -lt "5"; then
echo "You will need re2c >= 0.13.5 if you want to regenerate the Zend scanner (found ${1}.${2}.${3})."
exit 2
fi
IFS="$old_IFS"
if test "x$PHPROOT" = "x"; then
PHPROOT=git@git.php.net:php-src.git;
PHPROOT=git@git.php.net:php-src.git;
fi
LT_TARGETS='build/ltmain.sh build/config.guess build/config.sub'
if echo '\c' | grep -s c >/dev/null 2>&1
then
ECHO_N="echo -n"
ECHO_C=""
ECHO_N="echo -n"
ECHO_C=""
else
ECHO_N="echo"
ECHO_C='\c'
ECHO_N="echo"
ECHO_C='\c'
fi
MY_OLDPWD=`pwd`
@ -67,9 +53,9 @@ DIR=php-$VER
DIRPATH=$MY_OLDPWD/$DIR
if test -d "$DIRPATH"; then
echo "The directory $DIR" >&2
echo "already exists, rename or remove it and run makedist again." >&2
exit 1
echo "The directory $DIR" >&2
echo "already exists, rename or remove it and run makedist again." >&2
exit 1
fi
# Export PHP
@ -96,7 +82,12 @@ set -x
# when a user runs buildconf in the distribution.
rm -f buildmk.stamp
# Generate lexer and parser files
./scripts/dev/genfiles
exit_code=$?
if test "$exit_code" != "0"; then
exit $exit_code
fi
# now restore our versions of libtool-generated files
for i in $LT_TARGETS; do
@ -119,15 +110,15 @@ sed -i 's,^#ifndef YYTOKENTYPE,#include "zend.h"\n#ifndef YYTOKENTYPE,g' $MY_OLD
# download pear
$ECHO_N "makedist: Attempting to download PEAR's phar archive"
if test ! -x wget; then
wget https://pear.php.net/install-pear-nozlib.phar -nd -P pear/
if [ "x$?" != "x0" ]
then
$ECHO_N "Pear download failed";
exit 7
fi
wget https://pear.php.net/install-pear-nozlib.phar -nd -P pear/
if [ "x$?" != "x0" ]
then
$ECHO_N "Pear download failed";
exit 7
fi
else
$ECHO_N "Missing wget binary needed for pear download";
exit 7
$ECHO_N "Missing wget binary needed for pear download";
exit 7
fi
cd $MY_OLDPWD

View File

@ -137,7 +137,6 @@ dnl Always shared
PHP_BUILD_SHARED
dnl Required programs
PHP_PROG_RE2C
PHP_PROG_AWK
sinclude(config.m4)