]> granicus.if.org Git - php/commitdiff
Refactor PHP_PROG_BISON and PHP_PROG_RE2C
authorPeter Kokot <peterkokot@gmail.com>
Sun, 17 Mar 2019 15:22:02 +0000 (16:22 +0100)
committerPeter Kokot <peterkokot@gmail.com>
Sat, 30 Mar 2019 01:01:02 +0000 (02:01 +0100)
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

Zend/Zend.m4
Zend/acinclude.m4
acinclude.m4
configure.ac
scripts/dev/genfiles
scripts/dev/makedist
scripts/phpize.m4

index ad8c296cdf6b42650246d1f59dd86098c86c8bf2..29404631eb53b76623cce0d0cf77072da01423a3 100644 (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 \
index 6e072f2db6f1981e3233cc75563d0e9426b1e097..a2930b62cde05aa03cb652f58d2c360a8387045f 100644 (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],[
index 067865d7b8c7cdc37c90ca572a3d438cef4af6a8..6e2e4ceae64b20eb95530b50465b7d0c1debd8a3 100644 (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)
 ])
 
index 2205c11bd8d727a07dc3df76b6458e464eb60ebf..e79be39572b2667a06766baccb3ce606e71c97bd 100644 (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],
index c633429e0f8a8d64807b15353428d055e22caf74..89fdc2d6ca697802fc5286864f53571ac614c30e 100755 (executable)
 #
 #     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}
+
+# Go to project root.
+cd $(CDPATH= cd -- "$(dirname -- "$0")/../../" && pwd -P)
+
+# 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})"
+
+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
 
-# Current path to return to it later. This enables running script from any path.
-original_path=`pwd`
+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
 
-# Project root directory
-project_root=`CDPATH= cd -- "$(dirname -- "$0")/../../" && pwd -P`
-cd $project_root
+# 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})"
 
-echo "Generating Zend parser and lexer files"
-make RE2C="$RE2C" RE2C_FLAGS="$RE2C_FLAGS" YACC="$YACC" srcdir=Zend builddir=Zend top_srcdir=. \
+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
index e19df2a0de41b5d7ca18bd8fcc55e53f29ff9ebe..588a7e344b5d3322d8247cbc3a5aba24d17a2342 100755 (executable)
 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
index 76559d0c872262edba87603c2715259e0f95d6ea..9b89d1b9cd602f832ce4efdf21c6b496e7436aca 100644 (file)
@@ -137,7 +137,6 @@ dnl Always shared
 PHP_BUILD_SHARED
 
 dnl Required programs
-PHP_PROG_RE2C
 PHP_PROG_AWK
 
 sinclude(config.m4)