@@ -32,6 +32,10 @@ Environment variables:
3232 Explicit OpenSSL compile flags. Appended before configure.
3333 KING_OPENSSL_LIBS
3434 Explicit OpenSSL linker flags. Appended before configure.
35+ PHP_BIN PHP binary used by matching smoke scripts. Also used to infer
36+ phpizeX.Y/php-configX.Y when PHPIZE/PHP_CONFIG are unset.
37+ PHPIZE phpize binary to use for this profile build.
38+ PHP_CONFIG php-config binary to pass to configure.
3539EOF
3640}
3741
@@ -142,6 +146,7 @@ BASE_CPPFLAGS="${CPPFLAGS:-}"
142146BASE_LDFLAGS=" ${LDFLAGS:- } "
143147BASE_CC=" ${CC:- } "
144148BASE_CXX=" ${CXX:- } "
149+ PHP_BIN=" ${PHP_BIN:- php} "
145150
146151profile_cc=" "
147152profile_cxx=" "
@@ -150,6 +155,8 @@ profile_cppflags="${BASE_CPPFLAGS}"
150155profile_ldflags=" ${BASE_LDFLAGS} "
151156sanitizer_kind=" "
152157lsquic_runtime_prefix=" ${KING_LSQUIC_RUNTIME_PREFIX:- } "
158+ phpize_bin=" "
159+ php_config_bin=" "
153160declare -a PHPIZE_GENERATED_RELATIVE_PATHS=()
154161declare -a CONFIGURE_ENV=()
155162PHPIZE_SNAPSHOT_DIR=" "
@@ -162,6 +169,97 @@ trim_ascii_whitespace() {
162169 printf ' %s\n' " ${value} "
163170}
164171
172+ php_binary_suffix () {
173+ local binary_name=" "
174+
175+ binary_name=" $( basename " ${PHP_BIN} " ) "
176+ case " ${binary_name} " in
177+ php[0-9].[0-9])
178+ printf ' %s\n' " ${binary_name# php} "
179+ return 0
180+ ;;
181+ esac
182+
183+ return 1
184+ }
185+
186+ php_runtime_api () {
187+ " ${PHP_BIN} " -i 2> /dev/null | awk -F' => ' ' /^PHP API/ { print $2; exit }'
188+ }
189+
190+ phpize_api () {
191+ " ${phpize_bin} " -v 2> /dev/null | awk -F' : *' ' /^PHP Api Version/ { print $2; exit }'
192+ }
193+
194+ resolve_php_toolchain () {
195+ local suffix=" "
196+ local runtime_api=" "
197+ local config_api=" "
198+ local phpize_reported_api=" "
199+
200+ phpize_bin=" ${PHPIZE:- } "
201+ php_config_bin=" ${PHP_CONFIG:- } "
202+
203+ if [[ -z " ${phpize_bin} " || -z " ${php_config_bin} " ]]; then
204+ suffix=" $( php_binary_suffix || true) "
205+ if [[ -n " ${suffix} " ]]; then
206+ if [[ -z " ${phpize_bin} " ]] && command -v " phpize${suffix} " > /dev/null 2>&1 ; then
207+ phpize_bin=" phpize${suffix} "
208+ fi
209+ if [[ -z " ${php_config_bin} " ]] && command -v " php-config${suffix} " > /dev/null 2>&1 ; then
210+ php_config_bin=" php-config${suffix} "
211+ fi
212+ fi
213+ fi
214+
215+ phpize_bin=" ${phpize_bin:- phpize} "
216+ php_config_bin=" ${php_config_bin:- php-config} "
217+
218+ if ! command -v " ${phpize_bin} " > /dev/null 2>&1 ; then
219+ echo " Missing phpize binary: ${phpize_bin} " >&2
220+ exit 1
221+ fi
222+
223+ if ! command -v " ${php_config_bin} " > /dev/null 2>&1 ; then
224+ echo " Missing php-config binary: ${php_config_bin} " >&2
225+ exit 1
226+ fi
227+
228+ if ! command -v " ${PHP_BIN} " > /dev/null 2>&1 ; then
229+ echo " Missing PHP binary: ${PHP_BIN} " >&2
230+ exit 1
231+ fi
232+
233+ runtime_api=" $( php_runtime_api) "
234+ config_api=" $( " ${php_config_bin} " --phpapi 2> /dev/null || true) "
235+ phpize_reported_api=" $( phpize_api) "
236+
237+ if [[ -z " ${runtime_api} " ]]; then
238+ echo " Failed to resolve PHP runtime API from ${PHP_BIN} ." >&2
239+ exit 1
240+ fi
241+
242+ if [[ -z " ${config_api} " ]]; then
243+ echo " Failed to resolve PHP config API from ${php_config_bin} ." >&2
244+ exit 1
245+ fi
246+
247+ if [[ -z " ${phpize_reported_api} " ]]; then
248+ echo " Failed to resolve phpize API from ${phpize_bin} ." >&2
249+ exit 1
250+ fi
251+
252+ if [[ " ${runtime_api} " != " ${config_api} " || " ${runtime_api} " != " ${phpize_reported_api} " ]]; then
253+ {
254+ echo " PHP toolchain API mismatch:"
255+ echo " ${PHP_BIN} : ${runtime_api} "
256+ echo " ${php_config_bin} : ${config_api} "
257+ echo " ${phpize_bin} : ${phpize_reported_api} "
258+ } >&2
259+ exit 1
260+ fi
261+ }
262+
165263load_phpize_generated_relative_paths () {
166264 local raw_line=" "
167265 local normalized_line=" "
@@ -482,6 +580,11 @@ echo "Building King profile: ${PROFILE}"
482580echo " Compiler: ${profile_cc} "
483581echo " Jobs: ${JOBS} "
484582
583+ resolve_php_toolchain
584+ echo " PHP binary: ${PHP_BIN} "
585+ echo " phpize: ${phpize_bin} "
586+ echo " php-config: ${php_config_bin} "
587+
485588load_phpize_generated_relative_paths
486589snapshot_phpize_generated_files
487590trap restore_phpize_generated_files EXIT
@@ -492,15 +595,16 @@ if [[ -f Makefile ]]; then
492595 make clean > /dev/null 2>&1 || true
493596fi
494597
495- phpize --clean > /dev/null 2>&1 || true
496- phpize
598+ " ${phpize_bin} " --clean > /dev/null 2>&1 || true
599+ " ${phpize_bin} "
497600
498601CONFIGURE_ENV=(
499602 CC=" ${profile_cc} "
500603 CXX=" ${profile_cxx} "
501604 CFLAGS=" ${profile_cflags} "
502605 CPPFLAGS=" ${profile_cppflags} "
503606 LDFLAGS=" ${profile_ldflags} "
607+ PHP_CONFIG=" ${php_config_bin} "
504608)
505609
506610if [[ " $( host_os) " == " darwin" ]]; then
@@ -519,7 +623,7 @@ if [[ -n "${lsquic_runtime_prefix}" ]]; then
519623 )
520624fi
521625
522- env " ${CONFIGURE_ENV[@]} " ./configure --enable-king
626+ env " ${CONFIGURE_ENV[@]} " ./configure --enable-king --with-php-config= " ${php_config_bin} "
523627patch_generated_libtool_for_host
524628
525629make -j" ${JOBS} "
0 commit comments