Skip to content

Commit 25aee9c

Browse files
author
Jani Taskinen
committed
- Implemented FR #53271, FR #52410 (Building multiple PHP binary SAPIs and one SAPI module the same time)
# Bug #53271, Bug #52410
1 parent 200dcee commit 25aee9c

14 files changed

+148
-105
lines changed

Makefile.global

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ all: $(all_targets)
1313

1414
build-modules: $(PHP_MODULES) $(PHP_ZEND_EX)
1515

16+
build-binaries: $(PHP_BINARIES)
17+
1618
libphp$(PHP_MAJOR_VERSION).la: $(PHP_GLOBAL_OBJS) $(PHP_SAPI_OBJS)
1719
$(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -rpath $(phptempdir) $(EXTRA_LDFLAGS) $(LDFLAGS) $(PHP_RPATHS) $(PHP_GLOBAL_OBJS) $(PHP_SAPI_OBJS) $(EXTRA_LIBS) $(ZEND_EXTRA_LIBS) -o $@
1820
-@$(LIBTOOL) --silent --mode=install cp $@ $(phptempdir)/$@ >/dev/null 2>&1
@@ -35,6 +37,8 @@ install-sapi: $(OVERALL_TARGET)
3537
fi
3638
@$(INSTALL_IT)
3739

40+
install-binaries: build-binaries $(install_binary_targets)
41+
3842
install-modules: build-modules
3943
@test -d modules && \
4044
$(mkinstalldirs) $(INSTALL_ROOT)$(EXTENSION_DIR)

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ PHP NEWS
136136

137137
- Deprecated mysql_list_dbs() (Request #50667). (Andrey)
138138

139+
- Implemented FR #53271, FR #52410 (Building multiple PHP binary SAPIs and
140+
one SAPI module the same time). (Jani)
139141
- Implemented FR #53238 (Make third parameter of preg_match_all optional).
140142
(Adam)
141143
- Implemented FR #53213 (Adler32 algorithm is very slow).

acinclude.m4

+37-13
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ dnl the path is interpreted relative to the top build-directory.
194194
dnl
195195
dnl which array to append to?
196196
AC_DEFUN([PHP_ADD_SOURCES],[
197-
PHP_ADD_SOURCES_X($1, $2, $3, ifelse($4,cli,PHP_CLI_OBJS,ifelse($4,sapi,PHP_SAPI_OBJS,PHP_GLOBAL_OBJS)))
197+
PHP_ADD_SOURCES_X($1, $2, $3, ifelse($4,sapi,PHP_SAPI_OBJS,PHP_GLOBAL_OBJS))
198198
])
199199

200200
dnl
@@ -777,7 +777,7 @@ dnl
777777
AC_DEFUN([PHP_BUILD_SHARED],[
778778
PHP_BUILD_PROGRAM
779779
OVERALL_TARGET=libphp[]$PHP_MAJOR_VERSION[.la]
780-
php_build_target=shared
780+
php_sapi_module=shared
781781
782782
php_c_pre=$shared_c_pre
783783
php_c_meta=$shared_c_meta
@@ -794,7 +794,7 @@ dnl
794794
AC_DEFUN([PHP_BUILD_STATIC],[
795795
PHP_BUILD_PROGRAM
796796
OVERALL_TARGET=libphp[]$PHP_MAJOR_VERSION[.la]
797-
php_build_target=static
797+
php_sapi_module=static
798798
])
799799

800800
dnl
@@ -803,14 +803,13 @@ dnl
803803
AC_DEFUN([PHP_BUILD_BUNDLE],[
804804
PHP_BUILD_PROGRAM
805805
OVERALL_TARGET=libs/libphp[]$PHP_MAJOR_VERSION[.bundle]
806-
php_build_target=static
806+
php_sapi_module=static
807807
])
808808

809809
dnl
810810
dnl PHP_BUILD_PROGRAM
811811
dnl
812812
AC_DEFUN([PHP_BUILD_PROGRAM],[
813-
OVERALL_TARGET=[]ifelse($1,,php,$1)
814813
php_c_pre='$(LIBTOOL) --mode=compile $(CC)'
815814
php_c_meta='$(COMMON_FLAGS) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS)'
816815
php_c_post=
@@ -832,7 +831,7 @@ AC_DEFUN([PHP_BUILD_PROGRAM],[
832831
shared_cxx_post=
833832
shared_lo=lo
834833
835-
php_build_target=program
834+
php_sapi_module=program
836835
])
837836

838837
dnl
@@ -878,21 +877,46 @@ EOF
878877
dnl
879878
dnl PHP_SELECT_SAPI(name, type[, sources [, extra-cflags [, build-target]]])
880879
dnl
881-
dnl Selects the SAPI name and type (static, shared, programm)
880+
dnl Selects the SAPI name and type (static, shared, bundle, program)
882881
dnl and optionally also the source-files for the SAPI-specific
883882
dnl objects.
884883
dnl
885884
AC_DEFUN([PHP_SELECT_SAPI],[
886-
PHP_SAPI=$1
887-
885+
if test "$2" = "program"; then
886+
PHP_BINARIES="$PHP_BINARIES $1"
887+
elif test "$PHP_SAPI" != "none"; then
888+
AC_MSG_ERROR([
889+
+--------------------------------------------------------------------+
890+
| *** ATTENTION *** |
891+
| |
892+
| You've configured multiple SAPIs to be build. You can build only |
893+
| one SAPI module plus CGI, CLI and FPM binaries at the same time. |
894+
+--------------------------------------------------------------------+
895+
])
896+
else
897+
PHP_SAPI=$1
898+
fi
899+
900+
PHP_ADD_BUILD_DIR([sapi/$1])
901+
902+
PHP_INSTALLED_SAPIS="$PHP_INSTALLED_SAPIS $1"
903+
888904
case "$2" in
889905
static[)] PHP_BUILD_STATIC;;
890906
shared[)] PHP_BUILD_SHARED;;
891907
bundle[)] PHP_BUILD_BUNDLE;;
892-
program[)] PHP_BUILD_PROGRAM($5);;
908+
program[)] PHP_BUILD_PROGRAM;;
893909
esac
894-
895-
ifelse($3,,,[PHP_ADD_SOURCES([sapi/$1],[$3],[$4],[sapi])])
910+
911+
ifelse($2,program,[
912+
install_binaries="install-binaries"
913+
install_binary_targets="$install_binary_targets install-$1"
914+
PHP_SUBST(PHP_[]translit($1,a-z0-9-,A-Z0-9_)[]_OBJS)
915+
ifelse($3,,,[PHP_ADD_SOURCES_X([sapi/$1],[$3],[$4],PHP_[]translit($1,a-z0-9-,A-Z0-9_)[]_OBJS)])
916+
],[
917+
install_sapi="install-sapi"
918+
ifelse($3,,,[PHP_ADD_SOURCES([sapi/$1],[$3],[$4],[sapi])])
919+
])
896920
])
897921

898922
dnl deprecated
@@ -2912,7 +2936,7 @@ dnl DTrace objects
29122936
PHP_DTRACE_OBJS="[$]PHP_DTRACE_OBJS [$]ac_bdir[$]ac_obj.lo"
29132937
done;
29142938
2915-
case [$]php_build_target in
2939+
case [$]php_sapi_module in
29162940
program|static)
29172941
dtrace_objs='$(PHP_DTRACE_OBJS:.lo=.o)'
29182942
;;

configure.in

+30-34
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ dnl -------------------------------------------------------------------------
304304
PTHREADS_CHECK
305305
PHP_HELP_SEPARATOR([SAPI modules:])
306306
PHP_SHLIB_SUFFIX_NAMES
307-
PHP_SAPI=default
308307
PHP_BUILD_PROGRAM
308+
PHP_SAPI=none
309309

310310

311311
dnl SAPI configuration.
@@ -324,6 +324,20 @@ dnl Show which main SAPI was selected
324324
AC_MSG_CHECKING([for chosen SAPI module])
325325
AC_MSG_RESULT([$PHP_SAPI])
326326

327+
dnl Show which binaries were selected
328+
AC_MSG_CHECKING([for executable SAPI binaries])
329+
if test "$PHP_BINARIES"; then
330+
AC_MSG_RESULT([$PHP_BINARIES])
331+
else
332+
AC_MSG_RESULT([none])
333+
fi
334+
335+
dnl Exit early
336+
if test -z "$PHP_INSTALLED_SAPIS"; then
337+
AC_MSG_ERROR([Nothing to build.])
338+
fi
339+
340+
dnl force ZTS
327341
if test "$enable_maintainer_zts" = "yes"; then
328342
PTHREADS_ASSIGN_VARS
329343
PTHREADS_FLAGS
@@ -954,14 +968,8 @@ dnl -------------------------------------------------------------------------
954968
enable_shared=yes
955969
enable_static=yes
956970

957-
case $php_build_target in
958-
program|static)
959-
standard_libtool_flag='-prefer-non-pic -static'
960-
if test -z "$PHP_MODULES" && test -z "$PHP_ZEND_EX"; then
961-
enable_shared=no
962-
fi
963-
;;
964-
shared)
971+
case $php_sapi_module in
972+
shared[)]
965973
enable_static=no
966974
case $with_pic in
967975
yes)
@@ -973,6 +981,12 @@ case $php_build_target in
973981
esac
974982
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -avoid-version -module"
975983
;;
984+
*[)]
985+
standard_libtool_flag='-prefer-non-pic -static'
986+
if test -z "$PHP_MODULES" && test -z "$PHP_ZEND_EX"; then
987+
enable_shared=no
988+
fi
989+
;;
976990
esac
977991

978992
EXTRA_LIBS="$EXTRA_LIBS $DLIBS $LIBS"
@@ -1208,24 +1222,15 @@ case $host_alias in
12081222
;;
12091223
esac
12101224

1211-
if test "$PHP_CLI" != "no"; then
1212-
PHP_CLI_TARGET="\$(SAPI_CLI_PATH)"
1213-
PHP_INSTALL_CLI_TARGET="install-cli"
1214-
PHP_ADD_SOURCES(sapi/cli, php_cli.c php_cli_readline.c,, cli)
1215-
PHP_INSTALLED_SAPIS="cli $PHP_SAPI"
1216-
PHP_EXECUTABLE="\$(top_builddir)/\$(SAPI_CLI_PATH)"
1217-
else
1218-
PHP_INSTALLED_SAPIS="$PHP_SAPI"
1219-
fi
1220-
12211225
PHP_SUBST_OLD(PHP_INSTALLED_SAPIS)
12221226

12231227
PHP_SUBST(PHP_EXECUTABLE)
1224-
PHP_SUBST(PHP_CLI_TARGET)
1228+
12251229
PHP_SUBST(PHP_SAPI_OBJS)
1226-
PHP_SUBST(PHP_CLI_OBJS)
1230+
PHP_SUBST(PHP_BINARY_OBJS)
12271231
PHP_SUBST(PHP_GLOBAL_OBJS)
12281232

1233+
PHP_SUBST(PHP_BINARIES)
12291234
PHP_SUBST(PHP_MODULES)
12301235
PHP_SUBST(PHP_ZEND_EX)
12311236

@@ -1369,20 +1374,12 @@ else
13691374
pharcmd_install=
13701375
fi;
13711376

1372-
all_targets="$lcov_target \$(OVERALL_TARGET) \$(PHP_MODULES) \$(PHP_ZEND_EX) \$(PHP_CLI_TARGET) $pharcmd"
1373-
install_targets="$install_modules install-build install-headers install-programs $install_pear $pharcmd_install"
1374-
1375-
case $PHP_SAPI in
1376-
cli)
1377-
install_targets="$PHP_INSTALL_CLI_TARGET $install_targets"
1378-
;;
1379-
*)
1380-
install_targets="install-sapi $PHP_INSTALL_CLI_TARGET $install_targets"
1381-
;;
1382-
esac
1377+
all_targets="$lcov_target \$(OVERALL_TARGET) \$(PHP_MODULES) \$(PHP_ZEND_EX) \$(PHP_BINARIES) $pharcmd"
1378+
install_targets="$install_sapi $install_modules $install_binaries install-build install-headers install-programs $install_pear $pharcmd_install"
13831379

13841380
PHP_SUBST(all_targets)
13851381
PHP_SUBST(install_targets)
1382+
PHP_SUBST(install_binary_targets)
13861383

13871384
PHP_INSTALL_HEADERS([Zend/ TSRM/ include/ main/ main/streams/])
13881385

@@ -1407,7 +1404,7 @@ case $host_alias in
14071404
PHP_ADD_BUILD_DIR(netware)
14081405
;;
14091406
*)
1410-
PHP_ADD_SOURCES(/main, internal_functions_cli.c,, cli)
1407+
PHP_ADD_SOURCES_X(/main, internal_functions_cli.c,, PHP_BINARY_OBJS)
14111408
;;
14121409
esac
14131410

@@ -1438,7 +1435,6 @@ fi
14381435
PHP_ADD_SOURCES_X(Zend, zend_execute.c,,PHP_GLOBAL_OBJS,,$flag)
14391436

14401437
PHP_ADD_BUILD_DIR(main main/streams)
1441-
PHP_ADD_BUILD_DIR(sapi/$PHP_SAPI sapi/cli)
14421438
PHP_ADD_BUILD_DIR(TSRM)
14431439
PHP_ADD_BUILD_DIR(Zend)
14441440

sapi/cgi/Makefile.frag

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1-
$(SAPI_CGI_PATH): $(PHP_GLOBAL_OBJS) $(PHP_SAPI_OBJS)
1+
cgi: $(SAPI_CGI_PATH)
2+
3+
$(SAPI_CGI_PATH): $(PHP_GLOBAL_OBJS) $(PHP_BINARY_OBJS) $(PHP_CGI_OBJS)
24
$(BUILD_CGI)
5+
6+
install-cgi: $(SAPI_CGI_PATH)
7+
@echo "Installing PHP CGI binary: $(INSTALL_ROOT)$(bindir)/"
8+
@$(INSTALL) -m 0755 $(SAPI_CGI_PATH) $(INSTALL_ROOT)$(bindir)/$(program_prefix)php-cgi$(program_suffix)$(EXEEXT)
9+

sapi/cgi/config9.m4

+14-18
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ PHP_ARG_ENABLE(cgi,,
88
dnl
99
dnl CGI setup
1010
dnl
11-
if test "$PHP_SAPI" = "default"; then
12-
AC_MSG_CHECKING(whether to build CGI binary)
13-
if test "$PHP_CGI" != "no"; then
11+
AC_MSG_CHECKING(for CGI build)
12+
if test "$PHP_CGI" != "no"; then
1413
AC_MSG_RESULT(yes)
15-
1614
AC_MSG_CHECKING([for socklen_t in sys/socket.h])
1715
AC_EGREP_HEADER([socklen_t], [sys/socket.h],
1816
[AC_MSG_RESULT([yes])
@@ -50,31 +48,29 @@ if test "$PHP_SAPI" = "default"; then
5048
SAPI_CGI_PATH=sapi/cgi/php-cgi
5149
;;
5250
esac
53-
PHP_SUBST(SAPI_CGI_PATH)
5451

55-
dnl Set install target and select SAPI
56-
INSTALL_IT="@echo \"Installing PHP CGI binary: \$(INSTALL_ROOT)\$(bindir)/\"; \$(INSTALL) -m 0755 \$(SAPI_CGI_PATH) \$(INSTALL_ROOT)\$(bindir)/\$(program_prefix)php-cgi\$(program_suffix)\$(EXEEXT)"
52+
dnl Select SAPI
5753
PHP_SELECT_SAPI(cgi, program, cgi_main.c fastcgi.c,, '$(SAPI_CGI_PATH)')
5854

5955
case $host_alias in
6056
*aix*)
61-
BUILD_CGI="echo '\#! .' > php.sym && echo >>php.sym && nm -BCpg \`echo \$(PHP_GLOBAL_OBJS) \$(PHP_SAPI_OBJS) | sed 's/\([A-Za-z0-9_]*\)\.lo/\1.o/g'\` | \$(AWK) '{ if (((\$\$2 == \"T\") || (\$\$2 == \"D\") || (\$\$2 == \"B\")) && (substr(\$\$3,1,1) != \".\")) { print \$\$3 } }' | sort -u >> php.sym && \$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) -Wl,-brtl -Wl,-bE:php.sym \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_SAPI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CGI_PATH)"
57+
if test "$php_sapi_module" = "shared"; then
58+
BUILD_CGI="echo '\#! .' > php.sym && echo >>php.sym && nm -BCpg \`echo \$(PHP_GLOBAL_OBJS) \$(PHP_BINARY_OBJS) \$(PHP_CGI_OBJS) | sed 's/\([A-Za-z0-9_]*\)\.lo/.libs\/\1.o/g'\` | \$(AWK) '{ if (((\$\$2 == \"T\") || (\$\$2 == \"D\") || (\$\$2 == \"B\")) && (substr(\$\$3,1,1) != \".\")) { print \$\$3 } }' | sort -u >> php.sym && \$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) -Wl,-brtl -Wl,-bE:php.sym \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_CGI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CGI_PATH)"
59+
else
60+
BUILD_CGI="echo '\#! .' > php.sym && echo >>php.sym && nm -BCpg \`echo \$(PHP_GLOBAL_OBJS) \$(PHP_BINARY_OBJS) \$(PHP_CGI_OBJS) | sed 's/\([A-Za-z0-9_]*\)\.lo/\1.o/g'\` | \$(AWK) '{ if (((\$\$2 == \"T\") || (\$\$2 == \"D\") || (\$\$2 == \"B\")) && (substr(\$\$3,1,1) != \".\")) { print \$\$3 } }' | sort -u >> php.sym && \$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) -Wl,-brtl -Wl,-bE:php.sym \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_CGI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CGI_PATH)"
61+
fi
6262
;;
6363
*darwin*)
64-
BUILD_CGI="\$(CC) \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(NATIVE_RPATHS) \$(PHP_GLOBAL_OBJS:.lo=.o) \$(PHP_SAPI_OBJS:.lo=.o) \$(PHP_FRAMEWORKS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CGI_PATH)"
64+
BUILD_CGI="\$(CC) \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(NATIVE_RPATHS) \$(PHP_GLOBAL_OBJS:.lo=.o) \$(PHP_BINARY_OBJS:.lo=.o) \$(PHP_CGI_OBJS:.lo=.o) \$(PHP_FRAMEWORKS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CGI_PATH)"
6565
;;
6666
*)
67-
BUILD_CGI="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_SAPI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CGI_PATH)"
67+
BUILD_CGI="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_BINARY_OBJS) \$(PHP_CGI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CGI_PATH)"
6868
;;
6969
esac
7070

71+
dnl Expose to Makefile
72+
PHP_SUBST(SAPI_CGI_PATH)
7173
PHP_SUBST(BUILD_CGI)
72-
73-
elif test "$PHP_CLI" != "no"; then
74-
AC_MSG_RESULT(no)
75-
OVERALL_TARGET=
76-
PHP_SAPI=cli
77-
else
78-
AC_MSG_ERROR([No SAPIs selected.])
79-
fi
74+
else
75+
AC_MSG_RESULT(yes)
8076
fi

sapi/cli/Makefile.frag

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
cli: $(SAPI_CLI_PATH)
22

3-
$(SAPI_CLI_PATH): $(PHP_GLOBAL_OBJS) $(PHP_CLI_OBJS)
3+
$(SAPI_CLI_PATH): $(PHP_GLOBAL_OBJS) $(PHP_BINARY_OBJS) $(PHP_CLI_OBJS)
44
$(BUILD_CLI)
55

66
install-cli: $(SAPI_CLI_PATH)
77
@echo "Installing PHP CLI binary: $(INSTALL_ROOT)$(bindir)/"
8-
@$(INSTALL_CLI)
8+
@$(INSTALL) -m 0755 $(SAPI_CLI_PATH) $(INSTALL_ROOT)$(bindir)/$(program_prefix)php$(program_suffix)$(EXEEXT)
99
@echo "Installing PHP CLI man page: $(INSTALL_ROOT)$(mandir)/man1/"
1010
@$(mkinstalldirs) $(INSTALL_ROOT)$(mandir)/man1
11-
@$(INSTALL_DATA) $(builddir)/php.1 $(INSTALL_ROOT)$(mandir)/man1/$(program_prefix)php$(program_suffix).1
11+
@$(INSTALL_DATA) sapi/cli/php.1 $(INSTALL_ROOT)$(mandir)/man1/$(program_prefix)php$(program_suffix).1
12+

0 commit comments

Comments
 (0)