genfiles 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/bin/sh
  2. #
  3. # +----------------------------------------------------------------------+
  4. # | Copyright (c) The PHP Group |
  5. # +----------------------------------------------------------------------+
  6. # | This source file is subject to version 3.01 of the PHP license, |
  7. # | that is bundled with this package in the file LICENSE, and is |
  8. # | available through the world-wide-web at the following url: |
  9. # | https://php.net/license/3_01.txt |
  10. # | If you did not receive a copy of the PHP license and are unable to |
  11. # | obtain it through the world-wide-web, please send a note to |
  12. # | license@php.net so we can mail you a copy immediately. |
  13. # +----------------------------------------------------------------------+
  14. # | Authors: Sascha Schumann <sascha@schumann.cx> |
  15. # +----------------------------------------------------------------------+
  16. #
  17. # This script generates PHP lexer and parser files required to build PHP. The
  18. # generated files are ignored in the Git repository and packaged during the PHP
  19. # release process into the release installation archive download. This way the
  20. # bison and re2c dependencies are not required to build PHP when downloading
  21. # release archive.
  22. #
  23. # Usage: genfiles
  24. #
  25. # Environment:
  26. # The following environment variables can override default generators paths.
  27. #
  28. # YACC Parser generator program, default bison
  29. # RE2C Lexer generator program, default re2c
  30. # SED Path to sed program, default sed
  31. # MAKE Path to make program, default make
  32. #
  33. # For example:
  34. # YACC=/path/to/bison ./genfiles
  35. YACC=${YACC:-bison}
  36. YACC="$YACC -l"
  37. RE2C=${RE2C:-re2c}
  38. RE2C_FLAGS="-i"
  39. SED=${SED:-sed}
  40. MAKE=${MAKE:-make}
  41. # Go to project root.
  42. cd $(CDPATH= cd -- "$(dirname -- "$0")/../../" && pwd -P)
  43. # Check required bison version from the configure.ac file.
  44. required_bison_version=$($SED -n 's/PHP_PROG_BISON(\[\([0-9\.]*\)\].*/\1/p' configure.ac)
  45. set -f; IFS='.'; set -- $required_bison_version; set +f; IFS=' '
  46. required_bison_num="$(expr ${1:-0} \* 10000 + ${2:-0} \* 100 + ${3:-0})"
  47. current_version=$($YACC --version 2> /dev/null | grep 'GNU Bison' | cut -d ' ' -f 4 | tr -d a-z)
  48. set -f; IFS='.'; set -- $current_version; set +f; IFS=' '
  49. current_bison_num="$(expr ${1:-0} \* 10000 + ${2:-0} \* 100 + ${3:-0})"
  50. if test -z "$current_version"; then
  51. echo "genfiles: bison not found." >&2
  52. echo " You need bison version $required_bison_version or newer installed" >&2
  53. echo " to regenerate parser files." >&2
  54. exit 1
  55. fi
  56. if test "$current_bison_num" -lt "$required_bison_num"; then
  57. echo "genfiles: bison version $current_version found." >&2
  58. echo " You need bison version $required_bison_version or newer installed" >&2
  59. echo " to build parser files." >&2
  60. exit 1
  61. else
  62. echo "genfiles: bison version $current_version (ok)"
  63. fi
  64. # Check required re2c version from the configure.ac file.
  65. required_re2c_version=$($SED -n 's/PHP_PROG_RE2C(\[\(.*\)\])/\1/p' configure.ac)
  66. set -f; IFS='.'; set -- $required_re2c_version; set +f; IFS=' '
  67. required_re2c_num="$(expr ${1:-0} \* 10000 + ${2:-0} \* 100 + ${3:-0})"
  68. current_version="$($RE2C --version | cut -d ' ' -f 2 2>/dev/null)"
  69. set -f; IFS='.'; set -- $current_version; set +f; IFS=' '
  70. current_re2c_num="$(expr ${1:-0} \* 10000 + ${2:-0} \* 100 + ${3:-0})"
  71. if test -z "$current_version"; then
  72. echo "genfiles: re2c not found." >&2
  73. echo " You need re2c version $required_re2c_version or newer installed" >&2
  74. echo " to regenerate lexer files." >&2
  75. exit 1
  76. fi
  77. if test "$current_re2c_num" -lt "$required_re2c_num"; then
  78. echo "genfiles: re2c version $current_version found." >&2
  79. echo " You need re2c version $required_re2c_version or newer installed" >&2
  80. echo " to build lexer files." >&2
  81. exit 1
  82. else
  83. echo "genfiles: re2c version $current_version (ok)"
  84. fi
  85. # Check if make exists.
  86. if ! test -x "$(command -v $MAKE)"; then
  87. echo "genfiles: make not found. Please install make to generate files." >&2
  88. exit 1
  89. fi
  90. echo "genfiles: Generating Zend parser and lexer files"
  91. $MAKE RE2C="$RE2C" RE2C_FLAGS="$RE2C_FLAGS" YACC="$YACC" SED="$SED" srcdir=Zend builddir=Zend top_srcdir=. \
  92. -f Zend/Makefile.frag \
  93. Zend/zend_language_parser.c \
  94. Zend/zend_language_scanner.c \
  95. Zend/zend_ini_parser.c \
  96. Zend/zend_ini_scanner.c
  97. echo "genfiles: Generating phpdbg parser and lexer files"
  98. $MAKE RE2C="$RE2C" RE2C_FLAGS="$RE2C_FLAGS" YACC="$YACC" srcdir=sapi/phpdbg builddir=sapi/phpdbg top_srcdir=. \
  99. -f sapi/phpdbg/Makefile.frag \
  100. sapi/phpdbg/phpdbg_parser.c \
  101. sapi/phpdbg/phpdbg_lexer.c
  102. echo "genfiles: Generating json extension parser and lexer files"
  103. $MAKE RE2C="$RE2C" RE2C_FLAGS="$RE2C_FLAGS" YACC="$YACC" srcdir=ext/json builddir=ext/json top_srcdir=. \
  104. -f ext/json/Makefile.frag \
  105. ext/json/json_parser.tab.c \
  106. ext/json/json_scanner.c
  107. echo "genfiles: Generating PDO lexer file"
  108. $MAKE RE2C="$RE2C" RE2C_FLAGS="$RE2C_FLAGS" srcdir=ext/pdo builddir=ext/pdo top_srcdir=. \
  109. -f ext/pdo/Makefile.frag \
  110. ext/pdo/pdo_sql_parser.c
  111. echo "genfiles: Generating standard extension lexer files"
  112. $MAKE RE2C="$RE2C" RE2C_FLAGS="$RE2C_FLAGS" srcdir=ext/standard builddir=ext/standard top_srcdir=. \
  113. -f ext/standard/Makefile.frag \
  114. ext/standard/var_unserializer.c \
  115. ext/standard/url_scanner_ex.c
  116. echo "genfiles: Generating phar extension lexer file"
  117. $MAKE RE2C="$RE2C" RE2C_FLAGS="$RE2C_FLAGS" srcdir=ext/phar builddir=ext/phar top_srcdir=. \
  118. -f ext/phar/Makefile.frag \
  119. ext/phar/phar_path_check.c