diff --git a/sapi/cli/cli.h b/sapi/cli/cli.h index 85b55af3845d8..114481050027c 100644 --- a/sapi/cli/cli.h +++ b/sapi/cli/cli.h @@ -56,4 +56,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 */ diff --git a/sapi/cli/cli_win32.c b/sapi/cli/cli_win32.c index 4407fd088f688..de7d0a0282fd6 100644 --- a/sapi/cli/cli_win32.c +++ b/sapi/cli/cli_win32.c @@ -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); +} diff --git a/sapi/cli/config.m4 b/sapi/cli/config.m4 index 76c2d64e8c8a3..b318baf57ee91 100644 --- a/sapi/cli/config.m4 +++ b/sapi/cli/config.m4 @@ -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]) @@ -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], diff --git a/sapi/cli/config.w32 b/sapi/cli/config.w32 index 5dff4054b69d6..695a5b46ec104 100644 --- a/sapi/cli/config.w32 +++ b/sapi/cli/config.w32 @@ -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"); diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index d1781eab671c9..b0e6d7c2a5950 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -1179,18 +1179,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; @@ -1393,6 +1385,6 @@ int main(int argc, char *argv[]) * exiting. */ cleanup_ps_args(argv); - exit(exit_status); + return exit_status; } /* }}} */ diff --git a/sapi/cli/php_cli_main.c b/sapi/cli/php_cli_main.c new file mode 100644 index 0000000000000..a90c27e7ff98d --- /dev/null +++ b/sapi/cli/php_cli_main.c @@ -0,0 +1,21 @@ +/* + +----------------------------------------------------------------------+ + | Copyright (c) The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | https://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ +*/ + +#include "php.h" +#include "cli.h" + +int main(int argc, char *argv[]) +{ + return do_php_cli(argc, argv); +} diff --git a/sapi/embed/config.m4 b/sapi/embed/config.m4 index 2bb5ed4df4da4..567b5d05bf6cb 100644 --- a/sapi/embed/config.m4 +++ b/sapi/embed/config.m4 @@ -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 @@ -33,6 +26,12 @@ 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. + PHP_ADD_SOURCES([sapi/cli], + [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]) diff --git a/sapi/embed/config.w32 b/sapi/embed/config.w32 index 394982126cadb..e588c354925e8 100644 --- a/sapi/embed/config.w32 +++ b/sapi/embed/config.w32 @@ -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"); + ADD_FLAG("LIBS_EMBED", "ws2_32.lib"); + ADD_FLAG("LIBS_EMBED", "shell32.lib"); PHP_INSTALL_HEADERS("sapi/embed", "php_embed.h"); } diff --git a/sapi/embed/config0.m4 b/sapi/embed/config0.m4 new file mode 100644 index 0000000000000..f1c05b8ea01a6 --- /dev/null +++ b/sapi/embed/config0.m4 @@ -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])