Skip to content

Commit c8d2e55

Browse files
committed
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
1 parent de35468 commit c8d2e55

File tree

8 files changed

+97
-2
lines changed

8 files changed

+97
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ config.h.in
112112
# SAPIs specific ignores
113113
# ------------------------------------------------------------------------------
114114
/sapi/apache2handler/libphp.module
115+
/sapi/embed/php-embed.pc
115116
/sapi/fpm/fpm/php-cgi
116117
/sapi/fpm/init.d.php-fpm
117118
/sapi/fpm/php-fpm.conf
@@ -129,6 +130,7 @@ config.h.in
129130
/sapi/fpm/php-fpm
130131
/sapi/phpdbg/phpdbg
131132
/scripts/php-config
133+
/scripts/php.pc
132134
/scripts/phpize
133135
php
134136

build/php.m4

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2850,3 +2850,16 @@ AS_VAR_IF([php_var], [yes],
28502850
[Define to 1 if the compiler supports the '$1' variable attribute.])])
28512851
AS_VAR_POPDEF([php_var])
28522852
])
2853+
2854+
dnl
2855+
dnl PHP_SET_LIBS_PRIVATE
2856+
dnl
2857+
dnl Get a list of all external libraries that were linked to PHP. For using in
2858+
dnl templates, such as php.pc.in.
2859+
dnl
2860+
AC_DEFUN([PHP_SET_LIBS_PRIVATE],
2861+
[PHP_LIBS_PRIVATE=$EXTRA_LIBS
2862+
AS_VAR_SET_IF([ZEND_EXTRA_LIBS],
2863+
[AS_VAR_APPEND([PHP_LIBS_PRIVATE], [" $ZEND_EXTRA_LIBS"])])
2864+
AC_SUBST([PHP_LIBS_PRIVATE])
2865+
])

configure.ac

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,8 @@ EXTRA_LDFLAGS_PROGRAM="$EXTRA_LDFLAGS_PROGRAM $LDFLAGS"
13491349
EXTRA_LIBS="$EXTRA_LIBS $LIBS"
13501350
unset LIBS LDFLAGS
13511351

1352+
PHP_SET_LIBS_PRIVATE
1353+
13521354
AC_ARG_PROGRAM
13531355

13541356
test "$prefix" = "NONE" && prefix=/usr/local
@@ -1645,7 +1647,7 @@ else
16451647
fi;
16461648

16471649
all_targets="\$(OVERALL_TARGET) \$(PHP_MODULES) \$(PHP_ZEND_EX) \$(PHP_BINARIES) $pharcmd"
1648-
install_targets="$install_sapi $install_modules $install_binaries install-build install-headers install-programs $install_pear $pharcmd_install"
1650+
install_targets="$install_sapi $install_modules $install_binaries install-build install-headers install-programs $install_pear $pharcmd_install $install_embed"
16491651

16501652
PHP_SUBST([all_targets])
16511653
PHP_SUBST([install_targets])
@@ -1798,7 +1800,7 @@ PHP_ADD_BUILD_DIR([m4_normalize([
17981800
])])
17991801

18001802
ALL_OUTPUT_FILES="main/build-defs.h \
1801-
scripts/phpize scripts/man1/phpize.1 \
1803+
scripts/php.pc scripts/phpize scripts/man1/phpize.1 \
18021804
scripts/php-config scripts/man1/php-config.1 \
18031805
$PHP_OUTPUT_FILES"
18041806

sapi/embed/Makefile.frag

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
install-embed:
2+
@echo "Installing PHP Embed SAPI: $(INSTALL_ROOT)$(libdir)"
3+
@$(mkinstalldirs) $(INSTALL_ROOT)$(libdir)/pkgconfig
4+
@$(INSTALL_DATA) sapi/embed/php-embed.pc $(INSTALL_ROOT)$(libdir)/pkgconfig/$(program_prefix)php-embed$(program_suffix).pc

sapi/embed/config.m4

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ if test "$PHP_EMBED" != "no"; then
3030
fi
3131
AC_MSG_RESULT([$PHP_EMBED_TYPE])
3232
AC_SUBST([PHP_EMBED_TYPE])
33+
34+
PHP_ADD_MAKEFILE_FRAGMENT([$abs_srcdir/sapi/embed/Makefile.frag], [$abs_srcdir/sapi/embed], [$abs_builddir/sapi/embed])
35+
PHP_OUTPUT([sapi/embed/php-embed.pc])
36+
37+
install_embed=install-embed
3338
else
3439
AC_MSG_RESULT([no])
3540
fi

sapi/embed/php-embed.pc.in

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# The .pc file for pkg-config command-line utility.
2+
# https://en.wikipedia.org/wiki/Pkg-config
3+
#
4+
# Usage:
5+
# pkg-config --cflags php-embed
6+
# pkg-config --cflags-only-I php-embed
7+
# pkg-config --libs php-embed
8+
# pkg-config --mod-version php-embed
9+
# pkg-config --print-variables php-embed
10+
# pkg-config --variable=php_vernum php-embed
11+
12+
prefix=@prefix@
13+
exec_prefix=@exec_prefix@
14+
includedir=@includedir@/php
15+
libdir=@exec_prefix@/lib
16+
# The extension_dir PHP INI directive absolute path.
17+
extensiondir=@PHP_EXTENSION_DIR@
18+
# PHP version as integer.
19+
php_vernum=@PHP_VERSION_ID@
20+
# The path where to scan for additional INI configuration files.
21+
php_inidir=@PHP_CONFIG_FILE_SCAN_DIR@
22+
# The path in which to look for php.ini.
23+
php_inipath=@PHP_CONFIG_FILE_PATH@
24+
25+
Name: PHP Embed SAPI
26+
Description: A lightweight SAPI to embed PHP into application using C bindings
27+
URL: https://www.php.net
28+
License: PHP
29+
Version: @PHP_VERSION@
30+
Cflags.private: @PHP_CFLAGS_PRIVATE@
31+
Cflags: -I${includedir} -I${includedir}/main -I${includedir}/TSRM -I${includedir}/Zend -I${includedir}/ext -I${includedir}/ext/date/lib
32+
Libs.private: @PHP_LIBS_PRIVATE@
33+
Libs: -L${libdir} -lphp

scripts/Makefile.frag

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ install-programs: $(builddir)/phpize $(builddir)/php-config
4646
echo " page: $(program_prefix)$${page}$(program_suffix).1"; \
4747
$(INSTALL_DATA) $(builddir)/man1/$${page}.1 $(INSTALL_ROOT)$(mandir)/man1/$(program_prefix)$${page}$(program_suffix).1; \
4848
done
49+
@echo "Installing pkgconf .pc file: $(INSTALL_ROOT)$(libdir)/pkgconfig/php.pc"
50+
@$(mkinstalldirs) $(INSTALL_ROOT)$(libdir)/pkgconfig
51+
@$(INSTALL_DATA) $(builddir)/php.pc $(INSTALL_ROOT)$(libdir)/pkgconfig/$(program_prefix)php$(program_suffix).pc
4952

5053
$(builddir)/phpize: $(srcdir)/phpize.in $(top_builddir)/config.status
5154
(CONFIG_FILES=$@ CONFIG_HEADERS= $(top_builddir)/config.status)

scripts/php.pc.in

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# The .pc file for pkg-config command-line utility.
2+
# https://en.wikipedia.org/wiki/Pkg-config
3+
#
4+
# Usage:
5+
# pkg-config --cflags php
6+
# pkg-config --cflags-only-I php
7+
# pkg-config --libs php
8+
# pkg-config --mod-version php
9+
# pkg-config --print-variables php
10+
# pkg-config --variable=php_vernum php
11+
12+
prefix=@prefix@
13+
exec_prefix=@exec_prefix@
14+
includedir=@includedir@/php
15+
libdir=@exec_prefix@/lib
16+
# The extension_dir PHP INI directive absolute path.
17+
extensiondir=@PHP_EXTENSION_DIR@
18+
# PHP version as integer.
19+
php_vernum=@PHP_VERSION_ID@
20+
# The path where to scan for additional INI configuration files.
21+
php_inidir=@PHP_CONFIG_FILE_SCAN_DIR@
22+
# The path in which to look for php.ini.
23+
php_inipath=@PHP_CONFIG_FILE_PATH@
24+
25+
Name: PHP
26+
Description: Build extension for a PHP general-purpose scripting language
27+
URL: https://www.php.net
28+
License: PHP
29+
Version: @PHP_VERSION@
30+
Cflags.private: @PHP_CFLAGS_PRIVATE@
31+
CFlags: -I${includedir} -I${includedir}/main -I${includedir}/TSRM -I${includedir}/Zend -I${includedir}/ext -I${includedir}/ext/date/lib
32+
Libs.private: @PHP_LIBS_PRIVATE@
33+
Libs:

0 commit comments

Comments
 (0)