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