Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sapi/cli/cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ typedef struct php_cli_server_context {
php_cli_mode mode;
} php_cli_server_context;

extern PHP_CLI_API int do_php_cli(int argc, char *argv[]);

#endif /* CLI_H */
5 changes: 5 additions & 0 deletions sapi/cli/cli_win32.c
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
#define PHP_CLI_WIN32_NO_CONSOLE 1
#include "php_cli.c"

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
return do_php_cli(__argc, __argv);
}
7 changes: 6 additions & 1 deletion sapi/cli/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ PHP_ARG_ENABLE([cli],
[yes],
[no])

dnl The embed SAPI requires the CLI sources for do_php_cli().
if test "$PHP_EMBED" != "no" -a "$PHP_CLI" = "no"; then
AC_MSG_ERROR([--enable-embed requires the CLI SAPI, do not use --disable-cli with --enable-embed])
fi

if test "$PHP_CLI" != "no"; then
AC_CHECK_FUNCS([setproctitle])

Expand Down Expand Up @@ -32,7 +37,7 @@ if test "$PHP_CLI" != "no"; then
dnl Select SAPI.
PHP_SELECT_SAPI([cli],
[program],
[php_cli.c php_http_parser.c php_cli_server.c ps_title.c php_cli_process_title.c],
[php_cli.c php_cli_main.c php_http_parser.c php_cli_server.c ps_title.c php_cli_process_title.c],
[-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1])

AS_CASE([$host_alias],
Expand Down
7 changes: 6 additions & 1 deletion sapi/cli/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
ARG_ENABLE('cli', 'Build CLI version of PHP', 'yes');
ARG_ENABLE('cli-win32', 'Build console-less CLI version of PHP', 'no');

// The embed SAPI requires the CLI sources for do_php_cli().
if (PHP_EMBED != "no" && PHP_CLI != "yes") {
ERROR("--enable-embed requires the CLI SAPI, do not use --disable-cli with --enable-embed");
}

if (PHP_CLI == "yes") {
SAPI('cli', 'php_cli.c php_http_parser.c php_cli_server.c', 'php.exe', '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1');
SAPI('cli', 'php_cli.c php_cli_main.c php_http_parser.c php_cli_server.c', 'php.exe', '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1');
ADD_SOURCES(configure_module_dirname, 'php_cli_process_title.c ps_title.c', 'cli');
ADD_FLAG("LIBS_CLI", "ws2_32.lib");
ADD_FLAG("LIBS_CLI", "shell32.lib");
Expand Down
14 changes: 3 additions & 11 deletions sapi/cli/php_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -1187,18 +1187,10 @@ static int do_cli(int argc, char **argv) /* {{{ */
}
/* }}} */

/* {{{ main */
#ifdef PHP_CLI_WIN32_NO_CONSOLE
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
#else
int main(int argc, char *argv[])
#endif
/* {{{ do_php_cli */
PHP_CLI_API int do_php_cli(int argc, char *argv[])
{
#if defined(PHP_WIN32)
# ifdef PHP_CLI_WIN32_NO_CONSOLE
int argc = __argc;
char **argv = __argv;
# endif
int num_args;
wchar_t **argv_wide;
char **argv_save = argv;
Expand Down Expand Up @@ -1401,6 +1393,6 @@ int main(int argc, char *argv[])
* exiting.
*/
cleanup_ps_args(argv);
exit(exit_status);
return exit_status;
}
/* }}} */
19 changes: 19 additions & 0 deletions sapi/cli/php_cli_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
+----------------------------------------------------------------------+
| Copyright © The PHP Group and Contributors. |
+----------------------------------------------------------------------+
| This source file is subject to the Modified BSD License that is |
| bundled with this package in the file LICENSE, and is available |
| through the World Wide Web at <https://www.php.net/license/>. |
| |
| SPDX-License-Identifier: BSD-3-Clause |
+----------------------------------------------------------------------+
*/

#include "php.h"
#include "cli.h"

int main(int argc, char *argv[])
{
return do_php_cli(argc, argv);
}
14 changes: 7 additions & 7 deletions sapi/embed/config.m4
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
PHP_ARG_ENABLE([embed],,
[AS_HELP_STRING([[--enable-embed[=TYPE]]],
[Enable building of embedded SAPI library TYPE is either
'shared' or 'static'. [TYPE=shared]])],
[no],
[no])

AC_MSG_CHECKING([for embedded SAPI library support])

if test "$PHP_EMBED" != "no"; then
Expand Down Expand Up @@ -33,6 +26,13 @@ if test "$PHP_EMBED" != "no"; then
[php_embed.c],
[-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1])
PHP_INSTALL_HEADERS([sapi/embed], [php_embed.h])

dnl Include CLI sources for do_php_cli() in libphp.
dnl We rebuild them here because cli isn't guaranteed to compile with -fPIC
PHP_ADD_SOURCES([sapi/cli],
Comment thread
arnaud-lb marked this conversation as resolved.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When building with --enable-cli --enable-embed this creates duplicate recipes as the source files are added twice. make complains about it:

Makefile:470: warning: overriding recipe for target 'sapi/cli/php_cli.lo'
Makefile:449: warning: ignoring old recipe for target 'sapi/cli/php_cli.lo'
Makefile:473: warning: overriding recipe for target 'sapi/cli/php_http_parser.lo'
Makefile:455: warning: ignoring old recipe for target 'sapi/cli/php_http_parser.lo'
Makefile:476: warning: overriding recipe for target 'sapi/cli/php_cli_server.lo'
Makefile:458: warning: ignoring old recipe for target 'sapi/cli/php_cli_server.lo'
Makefile:479: warning: overriding recipe for target 'sapi/cli/ps_title.lo'
Makefile:461: warning: ignoring old recipe for target 'sapi/cli/ps_title.lo'
Makefile:482: warning: overriding recipe for target 'sapi/cli/php_cli_process_title.lo'
Makefile:464: warning: ignoring old recipe for target 'sapi/cli/php_cli_process_title.lo'

can't do it on Unix because CLI may be compiled non-PIC which will not work for embed, so they need to be recompiled.

I'm not a build system expert, but I believe that our system uses libtool to deal with this: libtool builds everything in both PIC and non-PIC mode by default (e.g. php_cli.c is compiled to php_cli.o (non-pic) and .libs/php_cli.o (pic)). The right object is selected during linking. We should be able to leverage that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I linked the wrong objects in then. Should be an easy fix tomorrow, thank you.

[php_cli.c php_http_parser.c php_cli_server.c ps_title.c php_cli_process_title.c],
[-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1],
[sapi])
])
else
AC_MSG_RESULT([no])
Expand Down
3 changes: 3 additions & 0 deletions sapi/embed/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ var PHP_EMBED_PGO = false;

if (PHP_EMBED != "no") {
SAPI('embed', 'php_embed.c', 'php' + PHP_VERSION + 'embed.lib', '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1');
ADD_SOURCES("sapi/cli", "php_cli.c php_http_parser.c php_cli_server.c ps_title.c php_cli_process_title.c", "embed", undefined, true);
ADD_FLAG("LIBS_EMBED", "ws2_32.lib");
ADD_FLAG("LIBS_EMBED", "shell32.lib");
PHP_INSTALL_HEADERS("sapi/embed", "php_embed.h");
}
6 changes: 6 additions & 0 deletions sapi/embed/config0.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
PHP_ARG_ENABLE([embed],,
[AS_HELP_STRING([[--enable-embed[=TYPE]]],
[Enable building of embedded SAPI library TYPE is either
'shared' or 'static'. [TYPE=shared]])],
[no],
[no])
4 changes: 0 additions & 4 deletions sapi/embed/php_embed.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ static const char HARDCODED_INI[] =
"max_execution_time=0\n"
"max_input_time=-1\n\0";

#if defined(PHP_WIN32) && defined(ZTS)
ZEND_TSRMLS_CACHE_DEFINE()
#endif

static char* php_embed_read_cookies(void)
{
return NULL;
Expand Down
Loading