From b3ed03b72c490919ac487492de3e52ea64c222e2 Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Wed, 3 Jul 2024 01:07:14 +0200 Subject: [PATCH 1/6] Add PHP pkg-config .pc metadata files Since PHP *nix Autotools build system already extensively relies on pkgconf (pkg-config) command-line tool to find dependencies it should also provide its .pc metadata file(s). [1] This adds an initial php.pc.in and php-embed.pc.in templates that are created during the configuration and build phase. They are installed in the provided system pkgconfig directory. For example: /usr/lib/pkgconfig/php.pc /usr/lib/pkgconfig/php-embed.pc /usr/lib/pkgconfig/php-embed8.pc /usr/lib/pkgconfig/php-embed8.4.pc /usr/lib/x86_64-linux-gnu/pkgconfig/php.pc Pkgconf [2] is a maintained continuation of the initial Freedesktop's pkg-config project [3]. Extensions and applications embedding the PHP Embed SAPI can then use also pkgconf to get the required PHP CFLAGS and/or LIBS. For PHP extensions: pkgconf --cflags php pkgconf --libs php pkgconf --modversion php pkgconf --cflags php8.4 Applications embedding the PHP Embed SAPI: pkgconf --libs php-embed pkgconf --cflags php-embed pkgconf --modversion php-embed pkgconf --cflags php-embed8.4 [1]: https://people.freedesktop.org/~dbn/pkg-config-guide.html [2]: https://github.com/pkgconf/pkgconf [3]: https://gitlab.freedesktop.org/pkg-config/pkg-config --- .gitignore | 2 ++ build/Makefile.global | 1 + configure.ac | 7 +++++-- sapi/embed/Makefile.frag | 4 ++++ sapi/embed/config.m4 | 5 +++++ sapi/embed/php-embed.pc.in | 36 ++++++++++++++++++++++++++++++++++++ scripts/Makefile.frag | 3 +++ scripts/php.pc.in | 36 ++++++++++++++++++++++++++++++++++++ 8 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 sapi/embed/Makefile.frag create mode 100644 sapi/embed/php-embed.pc.in create mode 100644 scripts/php.pc.in diff --git a/.gitignore b/.gitignore index d54334f599a57..34c1deae0c313 100644 --- a/.gitignore +++ b/.gitignore @@ -112,6 +112,7 @@ config.h.in # SAPIs specific ignores # ------------------------------------------------------------------------------ /sapi/apache2handler/libphp.module +/sapi/embed/php-embed.pc /sapi/fpm/fpm/php-cgi /sapi/fpm/init.d.php-fpm /sapi/fpm/php-fpm.conf @@ -129,6 +130,7 @@ config.h.in /sapi/fpm/php-fpm /sapi/phpdbg/phpdbg /scripts/php-config +/scripts/php.pc /scripts/phpize php diff --git a/build/Makefile.global b/build/Makefile.global index 37b48ba2980ea..618ad0368cc80 100644 --- a/build/Makefile.global +++ b/build/Makefile.global @@ -131,6 +131,7 @@ distclean: clean rm -f scripts/man1/phpize.1 scripts/php-config scripts/man1/php-config.1 sapi/cli/php.1 sapi/cgi/php-cgi.1 sapi/phpdbg/phpdbg.1 ext/phar/phar.1 ext/phar/phar.phar.1 rm -f sapi/fpm/php-fpm.conf sapi/fpm/init.d.php-fpm sapi/fpm/php-fpm.service sapi/fpm/php-fpm.8 sapi/fpm/status.html rm -f ext/phar/phar.phar ext/phar/phar.php + rm -f scripts/php.pc sapi/embed/php-embed.pc if test "$(srcdir)" != "$(builddir)"; then \ rm -f ext/phar/phar/phar.inc; \ fi diff --git a/configure.ac b/configure.ac index c7e36ca70c9fe..8ad99c7cbb4a4 100644 --- a/configure.ac +++ b/configure.ac @@ -1392,6 +1392,8 @@ AC_SUBST([SAPI_LIBNAME_STATIC]) AC_SUBST([PHP_VERSION]) AC_SUBST([PHP_VERSION_ID]) AC_SUBST([PHP_LDFLAGS]) +AC_SUBST([PHP_THREAD_SAFETY]) +AC_SUBST([ZEND_DEBUG]) PHP_UTILIZE_RPATHS @@ -1467,7 +1469,7 @@ PHP_SUBST_OLD([EXTENSION_DIR]) PHP_SUBST([EXTRA_LDFLAGS]) PHP_SUBST([EXTRA_LDFLAGS_PROGRAM]) PHP_SUBST_OLD([EXTRA_LIBS]) -PHP_SUBST([ZEND_EXTRA_LIBS]) +PHP_SUBST_OLD([ZEND_EXTRA_LIBS]) PHP_SUBST([INCLUDES]) PHP_SUBST([EXTRA_INCLUDES]) PHP_SUBST([INSTALL_IT]) @@ -1604,7 +1606,7 @@ else fi; all_targets="\$(OVERALL_TARGET) \$(PHP_MODULES) \$(PHP_ZEND_EX) \$(PHP_BINARIES) $pharcmd" -install_targets="$install_sapi $install_modules $install_binaries install-build install-headers install-programs $install_pear $pharcmd_install" +install_targets="$install_sapi $install_modules $install_binaries install-build install-headers install-programs $install_pear $pharcmd_install $install_embed" PHP_SUBST([all_targets]) PHP_SUBST([install_targets]) @@ -1804,6 +1806,7 @@ AC_CONFIG_FILES([ scripts/man1/php-config.1 scripts/man1/phpize.1 scripts/php-config + scripts/php.pc scripts/phpize ]) diff --git a/sapi/embed/Makefile.frag b/sapi/embed/Makefile.frag new file mode 100644 index 0000000000000..8547166135813 --- /dev/null +++ b/sapi/embed/Makefile.frag @@ -0,0 +1,4 @@ +install-embed: + @echo "Installing PHP Embed .pc file: $(INSTALL_ROOT)$(orig_libdir)/pkgconfig/" + @$(mkinstalldirs) $(INSTALL_ROOT)$(orig_libdir)/pkgconfig + @$(INSTALL_DATA) sapi/embed/php-embed.pc $(INSTALL_ROOT)$(orig_libdir)/pkgconfig/$(program_prefix)php-embed$(program_suffix).pc diff --git a/sapi/embed/config.m4 b/sapi/embed/config.m4 index c385e289a70ee..4f84d9138ea9f 100644 --- a/sapi/embed/config.m4 +++ b/sapi/embed/config.m4 @@ -30,6 +30,11 @@ if test "$PHP_EMBED" != "no"; then [php_embed.c], [-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1]) PHP_INSTALL_HEADERS([sapi/embed], [php_embed.h]) + PHP_ADD_MAKEFILE_FRAGMENT([$abs_srcdir/sapi/embed/Makefile.frag], + [$abs_srcdir/sapi/embed], + [sapi/embed]) + AC_CONFIG_FILES([sapi/embed/php-embed.pc]) + install_embed=install-embed ]) else AC_MSG_RESULT([no]) diff --git a/sapi/embed/php-embed.pc.in b/sapi/embed/php-embed.pc.in new file mode 100644 index 0000000000000..1f8778091c165 --- /dev/null +++ b/sapi/embed/php-embed.pc.in @@ -0,0 +1,36 @@ +# The .pc file for the pkg-config command-line utility. +# https://en.wikipedia.org/wiki/Pkg-config +# +# Usage: +# pkg-config --cflags php-embed +# pkg-config --cflags-only-I php-embed +# pkg-config --libs php-embed +# pkg-config --mod-version php-embed +# pkg-config --print-variables php-embed +# pkg-config --variable=php_vernum php-embed + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +includedir=@includedir@/php +libdir=@exec_prefix@/lib +# The extension_dir PHP INI directive absolute path. +extensiondir=@EXPANDED_EXTENSION_DIR@ +# PHP version as integer. +php_vernum=@PHP_VERSION_ID@ +# The path where to scan for additional INI configuration files. +php_inidir=@EXPANDED_PHP_CONFIG_FILE_SCAN_DIR@ +# The path in which to look for php.ini. +php_inipath=@EXPANDED_PHP_CONFIG_FILE_PATH@ +# Whether PHP is built in debug mode (yes) or not (no). +php_debug=@ZEND_DEBUG@ +# Whether PHP is built with thread safety (yes) or not (no). +php_zts=@PHP_THREAD_SAFETY@ + +Name: PHP Embed SAPI +Description: A lightweight SAPI to embed PHP into application using C bindings +URL: https://www.php.net +License: PHP +Version: @PHP_VERSION@ +Cflags: -I${includedir} -I${includedir}/main -I${includedir}/TSRM -I${includedir}/Zend -I${includedir}/ext -I${includedir}/ext/date/lib +Libs.private: @EXTRA_LIBS@ @ZEND_EXTRA_LIBS@ +Libs: -L${libdir} -lphp diff --git a/scripts/Makefile.frag b/scripts/Makefile.frag index cf56852c2b113..8dce5a4153bf8 100644 --- a/scripts/Makefile.frag +++ b/scripts/Makefile.frag @@ -46,3 +46,6 @@ install-programs: echo " page: $(program_prefix)$${page}$(program_suffix).1"; \ $(INSTALL_DATA) $(builddir)/man1/$${page}.1 $(INSTALL_ROOT)$(mandir)/man1/$(program_prefix)$${page}$(program_suffix).1; \ done + @echo "Installing PHP .pc file: $(INSTALL_ROOT)$(orig_libdir)/pkgconfig/" + @$(mkinstalldirs) $(INSTALL_ROOT)$(orig_libdir)/pkgconfig + @$(INSTALL_DATA) $(builddir)/php.pc $(INSTALL_ROOT)$(orig_libdir)/pkgconfig/$(program_prefix)php$(program_suffix).pc diff --git a/scripts/php.pc.in b/scripts/php.pc.in new file mode 100644 index 0000000000000..098a4e87d3105 --- /dev/null +++ b/scripts/php.pc.in @@ -0,0 +1,36 @@ +# The .pc file for the pkg-config command-line utility. +# https://en.wikipedia.org/wiki/Pkg-config +# +# Usage: +# pkg-config --cflags php +# pkg-config --cflags-only-I php +# pkg-config --libs php +# pkg-config --mod-version php +# pkg-config --print-variables php +# pkg-config --variable=php_vernum php + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +includedir=@includedir@/php +libdir=@exec_prefix@/lib +# The extension_dir PHP INI directive absolute path. +extensiondir=@EXPANDED_EXTENSION_DIR@ +# PHP version as integer. +php_vernum=@PHP_VERSION_ID@ +# The path where to scan for additional INI configuration files. +php_inidir=@EXPANDED_PHP_CONFIG_FILE_SCAN_DIR@ +# The path in which to look for php.ini. +php_inipath=@EXPANDED_PHP_CONFIG_FILE_PATH@ +# Whether PHP is built in debug mode (yes) or not (no). +php_debug=@ZEND_DEBUG@ +# Whether PHP is built with thread safety (yes) or not (no). +php_zts=@PHP_THREAD_SAFETY@ + +Name: PHP +Description: Build extension for a PHP general-purpose scripting language +URL: https://www.php.net +License: PHP +Version: @PHP_VERSION@ +CFlags: -I${includedir} -I${includedir}/main -I${includedir}/TSRM -I${includedir}/Zend -I${includedir}/ext -I${includedir}/ext/date/lib +Libs.private: @EXTRA_LIBS@ @ZEND_EXTRA_LIBS@ +Libs: From 782626e06748ba6156a5fd30e62a2c27b78a4870 Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Sat, 17 Aug 2024 15:33:42 +0200 Subject: [PATCH 2/6] Fix lib directory path When customizing the Autoconf's lib directory option with for example: ./configure --libdir=--libdir=/usr/lib/x86_64-linux-gnu This lib directory should be also inserted in the generated *.pc files. --- sapi/embed/php-embed.pc.in | 2 +- scripts/php.pc.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sapi/embed/php-embed.pc.in b/sapi/embed/php-embed.pc.in index 1f8778091c165..a5fff204f8003 100644 --- a/sapi/embed/php-embed.pc.in +++ b/sapi/embed/php-embed.pc.in @@ -12,7 +12,7 @@ prefix=@prefix@ exec_prefix=@exec_prefix@ includedir=@includedir@/php -libdir=@exec_prefix@/lib +libdir=@orig_libdir@ # The extension_dir PHP INI directive absolute path. extensiondir=@EXPANDED_EXTENSION_DIR@ # PHP version as integer. diff --git a/scripts/php.pc.in b/scripts/php.pc.in index 098a4e87d3105..b056f9c9e98af 100644 --- a/scripts/php.pc.in +++ b/scripts/php.pc.in @@ -12,7 +12,7 @@ prefix=@prefix@ exec_prefix=@exec_prefix@ includedir=@includedir@/php -libdir=@exec_prefix@/lib +libdir=@orig_libdir@ # The extension_dir PHP INI directive absolute path. extensiondir=@EXPANDED_EXTENSION_DIR@ # PHP version as integer. From 1de4e4b29386f9dcd7c923d8cb5f458e5d16223e Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Thu, 5 Sep 2024 12:43:29 +0200 Subject: [PATCH 3/6] Simplify .pc.in templates - variables renamed and synced further to match php-config a bit - Redundant comments removed and refactored - Typos fixed - Extension directory template placeholder replaced with @EXTENSION_DIR@ so it's possible to insert variables directly `$prefix/php/...` --- sapi/embed/php-embed.pc.in | 21 ++++++--------------- scripts/php.pc.in | 21 ++++++--------------- 2 files changed, 12 insertions(+), 30 deletions(-) diff --git a/sapi/embed/php-embed.pc.in b/sapi/embed/php-embed.pc.in index a5fff204f8003..7b985d2a0f76c 100644 --- a/sapi/embed/php-embed.pc.in +++ b/sapi/embed/php-embed.pc.in @@ -1,26 +1,17 @@ -# The .pc file for the pkg-config command-line utility. -# https://en.wikipedia.org/wiki/Pkg-config -# -# Usage: -# pkg-config --cflags php-embed -# pkg-config --cflags-only-I php-embed -# pkg-config --libs php-embed -# pkg-config --mod-version php-embed -# pkg-config --print-variables php-embed -# pkg-config --variable=php_vernum php-embed +# The pkg-config .pc file for PHP Embed SAPI. prefix=@prefix@ exec_prefix=@exec_prefix@ includedir=@includedir@/php libdir=@orig_libdir@ -# The extension_dir PHP INI directive absolute path. -extensiondir=@EXPANDED_EXTENSION_DIR@ +# PHP extension directory containing dynamically loadable PHP extensions. +php_extension_dir=@EXTENSION_DIR@ # PHP version as integer. -php_vernum=@PHP_VERSION_ID@ +php_version_id=@PHP_VERSION_ID@ # The path where to scan for additional INI configuration files. -php_inidir=@EXPANDED_PHP_CONFIG_FILE_SCAN_DIR@ +php_ini_dir=@EXPANDED_PHP_CONFIG_FILE_SCAN_DIR@ # The path in which to look for php.ini. -php_inipath=@EXPANDED_PHP_CONFIG_FILE_PATH@ +php_ini_path=@EXPANDED_PHP_CONFIG_FILE_PATH@ # Whether PHP is built in debug mode (yes) or not (no). php_debug=@ZEND_DEBUG@ # Whether PHP is built with thread safety (yes) or not (no). diff --git a/scripts/php.pc.in b/scripts/php.pc.in index b056f9c9e98af..d61f2f939605d 100644 --- a/scripts/php.pc.in +++ b/scripts/php.pc.in @@ -1,26 +1,17 @@ -# The .pc file for the pkg-config command-line utility. -# https://en.wikipedia.org/wiki/Pkg-config -# -# Usage: -# pkg-config --cflags php -# pkg-config --cflags-only-I php -# pkg-config --libs php -# pkg-config --mod-version php -# pkg-config --print-variables php -# pkg-config --variable=php_vernum php +# The pkg-config .pc file for PHP. prefix=@prefix@ exec_prefix=@exec_prefix@ includedir=@includedir@/php libdir=@orig_libdir@ -# The extension_dir PHP INI directive absolute path. -extensiondir=@EXPANDED_EXTENSION_DIR@ +# PHP extension directory containing dynamically loadable PHP extensions. +php_extension_dir=@EXTENSION_DIR@ # PHP version as integer. php_vernum=@PHP_VERSION_ID@ # The path where to scan for additional INI configuration files. -php_inidir=@EXPANDED_PHP_CONFIG_FILE_SCAN_DIR@ +php_ini_dir=@EXPANDED_PHP_CONFIG_FILE_SCAN_DIR@ # The path in which to look for php.ini. -php_inipath=@EXPANDED_PHP_CONFIG_FILE_PATH@ +php_ini_path=@EXPANDED_PHP_CONFIG_FILE_PATH@ # Whether PHP is built in debug mode (yes) or not (no). php_debug=@ZEND_DEBUG@ # Whether PHP is built with thread safety (yes) or not (no). @@ -31,6 +22,6 @@ Description: Build extension for a PHP general-purpose scripting language URL: https://www.php.net License: PHP Version: @PHP_VERSION@ -CFlags: -I${includedir} -I${includedir}/main -I${includedir}/TSRM -I${includedir}/Zend -I${includedir}/ext -I${includedir}/ext/date/lib +Cflags: -I${includedir} -I${includedir}/main -I${includedir}/TSRM -I${includedir}/Zend -I${includedir}/ext -I${includedir}/ext/date/lib Libs.private: @EXTRA_LIBS@ @ZEND_EXTRA_LIBS@ Libs: From 33c26fb51f473d86eaa89dd3d08020536716e18d Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Mon, 9 Sep 2024 18:47:18 +0200 Subject: [PATCH 4/6] [skip ci] Add notes to CONTRIBUTING.md and sync variable names --- CONTRIBUTING.md | 5 ++++- sapi/embed/php-embed.pc.in | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2318f896b7a9b..30cd60e932e57 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -235,8 +235,11 @@ locations. └─ cli/ ├─ mime_type_map.h # Generated by `sapi/cli/generate_mime_type_map.php` └─ ... + └─ embed/ + ├─ php-embed.pc.in # pkg-config metadata file + └─ ... └─ ... - ├─ scripts/ # php-config, phpize and internal development scripts + ├─ scripts/ # php-config, phpize, pkg-config, and internal development scripts ├─ tests/ # Core features tests └─ win32/ # Windows build system files ├─ cp_enc_map.c # Generated by `win32/cp_enc_map_gen.exe` diff --git a/sapi/embed/php-embed.pc.in b/sapi/embed/php-embed.pc.in index 7b985d2a0f76c..102f582ca2b53 100644 --- a/sapi/embed/php-embed.pc.in +++ b/sapi/embed/php-embed.pc.in @@ -7,7 +7,7 @@ libdir=@orig_libdir@ # PHP extension directory containing dynamically loadable PHP extensions. php_extension_dir=@EXTENSION_DIR@ # PHP version as integer. -php_version_id=@PHP_VERSION_ID@ +php_vernum=@PHP_VERSION_ID@ # The path where to scan for additional INI configuration files. php_ini_dir=@EXPANDED_PHP_CONFIG_FILE_SCAN_DIR@ # The path in which to look for php.ini. From 177a6e4ddda4a835f61ccd73e67e1cca3c5f0505 Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Mon, 9 Sep 2024 20:14:30 +0200 Subject: [PATCH 5/6] [skip ci] Add "Requires" keyword to php-embed .pc file The "Requires" inherits all Cflags, Libs and their ".private" fields and adds it to the output, which simplifies writing templates a bit. --- sapi/embed/php-embed.pc.in | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sapi/embed/php-embed.pc.in b/sapi/embed/php-embed.pc.in index 102f582ca2b53..7686ef78f2a77 100644 --- a/sapi/embed/php-embed.pc.in +++ b/sapi/embed/php-embed.pc.in @@ -22,6 +22,5 @@ Description: A lightweight SAPI to embed PHP into application using C bindings URL: https://www.php.net License: PHP Version: @PHP_VERSION@ -Cflags: -I${includedir} -I${includedir}/main -I${includedir}/TSRM -I${includedir}/Zend -I${includedir}/ext -I${includedir}/ext/date/lib -Libs.private: @EXTRA_LIBS@ @ZEND_EXTRA_LIBS@ +Requires: php Libs: -L${libdir} -lphp From 1e6acee8eb3f32b7f5b5a5b0e3c7c3790ec34135 Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Mon, 9 Sep 2024 20:41:09 +0200 Subject: [PATCH 6/6] [skip ci] Remove Requires section for now --- sapi/embed/php-embed.pc.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sapi/embed/php-embed.pc.in b/sapi/embed/php-embed.pc.in index 7686ef78f2a77..102f582ca2b53 100644 --- a/sapi/embed/php-embed.pc.in +++ b/sapi/embed/php-embed.pc.in @@ -22,5 +22,6 @@ Description: A lightweight SAPI to embed PHP into application using C bindings URL: https://www.php.net License: PHP Version: @PHP_VERSION@ -Requires: php +Cflags: -I${includedir} -I${includedir}/main -I${includedir}/TSRM -I${includedir}/Zend -I${includedir}/ext -I${includedir}/ext/date/lib +Libs.private: @EXTRA_LIBS@ @ZEND_EXTRA_LIBS@ Libs: -L${libdir} -lphp