Skip to content

Commit 009b5e2

Browse files
committedMar 12, 2025
fix GH-8533: dynamic libphp linking on Mac
Pass the -dynamiclib flag to libtool to build a valid Mac dylib. Closes GH-8533.
1 parent 25887b3 commit 009b5e2

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed
 

‎.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
# Libtool library files generated during build process
3030
*.la
3131

32+
# Mac shared library files generated during build process
33+
*.dylib
34+
3235
# Directories created by Libtool for storing generated library files
3336
.libs/
3437

‎NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ PHP NEWS
99
. Fixed bug GH-17984 (calls with arguments as array with references).
1010
(David Carlier)
1111

12+
- Embed:
13+
. Fixed bug GH-8533 (Unable to link dynamic libphp on Mac). (Kévin Dunglas)
14+
1215
- Mbstring:
1316
. Fixed bug GH-17989 (mb_output_handler crash with unset
1417
http_output_conv_mimetypes). (nielsdos)

‎build/Makefile.global

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ libphp.la: $(PHP_GLOBAL_OBJS) $(PHP_SAPI_OBJS)
1919
$(LIBTOOL) --tag=CC --mode=link $(CC) $(LIBPHP_CFLAGS) $(CFLAGS) $(EXTRA_CFLAGS) -rpath $(phptempdir) $(EXTRA_LDFLAGS) $(LDFLAGS) $(PHP_RPATHS) $(PHP_GLOBAL_OBJS) $(PHP_SAPI_OBJS) $(EXTRA_LIBS) $(ZEND_EXTRA_LIBS) -o $@
2020
-@$(LIBTOOL) --silent --tag=CC --mode=install cp $@ $(phptempdir)/$@ >/dev/null 2>&1
2121

22+
libphp.dylib: libphp.la
23+
$(LIBTOOL) --tag=CC --mode=link $(CC) -dynamiclib $(LIBPHP_CFLAGS) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) -rpath $(phptempdir) -install_name @rpath/$@ $(EXTRA_LDFLAGS) $(LDFLAGS) $(PHP_RPATHS) $(PHP_GLOBAL_OBJS) $(PHP_SAPI_OBJS) $(EXTRA_LIBS) $(ZEND_EXTRA_LIBS) -o $@
24+
-@$(LIBTOOL) --silent --tag=CC --mode=install cp $@ $(phptempdir)/$@ >/dev/null 2>&1
25+
2226
libs/libphp.bundle: $(PHP_GLOBAL_OBJS) $(PHP_SAPI_OBJS)
2327
$(CC) $(MH_BUNDLE_FLAGS) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) $(LDFLAGS) $(EXTRA_LDFLAGS) $(PHP_GLOBAL_OBJS:.lo=.o) $(PHP_SAPI_OBJS:.lo=.o) $(PHP_FRAMEWORKS) $(EXTRA_LIBS) $(ZEND_EXTRA_LIBS) -o $@ && cp $@ libs/libphp.so
2428

‎build/php.m4

+9
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,14 @@ AC_DEFUN([PHP_BUILD_SHARED],[
764764
php_lo=$shared_lo
765765
])
766766

767+
dnl
768+
dnl PHP_BUILD_SHARED_DYLIB
769+
dnl
770+
AC_DEFUN([PHP_BUILD_SHARED_DYLIB],[
771+
PHP_BUILD_SHARED
772+
OVERALL_TARGET=libphp.dylib
773+
])
774+
767775
dnl
768776
dnl PHP_BUILD_STATIC
769777
dnl
@@ -876,6 +884,7 @@ AC_DEFUN([PHP_SELECT_SAPI],[
876884
case "$2" in
877885
static[)] PHP_BUILD_STATIC;;
878886
shared[)] PHP_BUILD_SHARED;;
887+
shared-dylib[)] PHP_BUILD_SHARED_DYLIB;;
879888
bundle[)] PHP_BUILD_BUNDLE;;
880889
esac
881890
install_sapi="install-sapi"

‎sapi/embed/config.m4

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ if test "$PHP_EMBED" != "no"; then
1111
case "$PHP_EMBED" in
1212
yes|shared)
1313
LIBPHP_CFLAGS="-shared"
14-
PHP_EMBED_TYPE=shared
14+
AS_CASE(["$host_alias"], [*darwin*], [
15+
SAPI_SHARED="libs/libphp.dylib"
16+
PHP_EMBED_TYPE=shared-dylib
17+
], [PHP_EMBED_TYPE=shared])
1518
INSTALL_IT="\$(mkinstalldirs) \$(INSTALL_ROOT)\$(prefix)/lib; \$(INSTALL) -m 0755 $SAPI_SHARED \$(INSTALL_ROOT)\$(prefix)/lib"
1619
;;
1720
static)

0 commit comments

Comments
 (0)