From a1b7bc0c8148eaf728fccdffe147e3bc0c03f18e Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Mon, 11 Mar 2019 02:01:25 +0100 Subject: [PATCH] Integrate README.EXT_SKEL to help option - Sync help output using heredoc - Add extension building instructions - Building with phpize is preferred option. Mention also tests - Refactor print_success() --- README.EXT_SKEL | 43 ------------ README.SELF-CONTAINED-EXTENSIONS | 4 +- ext/ext_skel.php | 110 +++++++++++++++++++++++++------ 3 files changed, 91 insertions(+), 66 deletions(-) delete mode 100644 README.EXT_SKEL diff --git a/README.EXT_SKEL b/README.EXT_SKEL deleted file mode 100644 index ea450c045ab..00000000000 --- a/README.EXT_SKEL +++ /dev/null @@ -1,43 +0,0 @@ -WHAT IT IS - - It's a tool for automatically creating the basic framework for a PHP extension. - -HOW TO USE IT - - Very simple. First, change to the ext/ directory of the PHP sources. Then - run the following - - php ext_skel.php --ext extension_name - - and everything you need will be placed in directory ext/extension_name. - - If you don't need to test the existence of any external header files, - libraries or functions in them, the extension is ready to be compiled in - PHP. To compile the extension, run the following: - - ./buildconf; ./configure --enable-extension_name; make - - The definition of PHP_extension_NAME_VERSION will be present in the - php_extension_name.h and injected into the zend_extension_entry definition. This - is required by the PECL website for the version string conformity checks - against package.xml - -SOURCE AND HEADER FILE NAME - - The ext_skel.php script generates 'extension_name.c' and 'php_extension_name.h' - as the main source and header files. Keep these names. - - extension functions (User functions) must be named - - extension_name_function() - - When you need to expose extension functions to other extensions, expose functions - strictly needed by others. Exposed internal function must be named - - php_extension_name_function() - - See also CODING_STANDARDS. - -OTHER OPTIONS - - Run php ext_skel.php --help to see the available options. diff --git a/README.SELF-CONTAINED-EXTENSIONS b/README.SELF-CONTAINED-EXTENSIONS index e28ec4d6db5..1aaec6d6c4a 100644 --- a/README.SELF-CONTAINED-EXTENSIONS +++ b/README.SELF-CONTAINED-EXTENSIONS @@ -104,8 +104,8 @@ CREATING SOURCE FILES ext_skel can be of great help when creating the common code for all modules in PHP for you and also writing basic function definitions and C code for - handling arguments passed to your functions. See README.EXT_SKEL for further - information. + handling arguments passed to your functions. See `./ext/ext_skel.php --help` + for further information. As for the rest, you are currently alone here. There are a lot of existing modules, use a simple module as a starting point and add your own code. diff --git a/ext/ext_skel.php b/ext/ext_skel.php index ff41ee8ccf1..4623910ecfd 100755 --- a/ext/ext_skel.php +++ b/ext/ext_skel.php @@ -31,23 +31,91 @@ function error($message) { /* {{{ print_help */ function print_help() { - printf('php ext_skel.php --ext [--experimental] [--author ]%s', PHP_EOL); - printf(' [--dir ] [--std] [--onlyunix]%s', PHP_EOL); - printf(' [--onlywindows] [--help]%1$s%1$s', PHP_EOL); - printf(' --ext The name of the extension defined as %s', PHP_EOL); - printf(' --experimental Passed if this extension is experimental, this creates%s', PHP_EOL); - printf(' the EXPERIMENTAL file in the root of the extension%s', PHP_EOL); - printf(' --author Your name, this is used if --std is passed and%s', PHP_EOL); - printf(' for the CREDITS file%s', PHP_EOL); - printf(' --dir Path to the directory for where extension should be%s', PHP_EOL); - printf(' created. Defaults to the directory of where this script%s', PHP_EOL); - printf(' lives%s', PHP_EOL); - printf(' --std If passed, the standard header used%s', PHP_EOL); - printf(' in extensions that is included in the core, will be used%s', PHP_EOL); - printf(' --onlyunix Only generate configure scripts for Unix%s', PHP_EOL); - printf(' --onlywindows Only generate configure scripts for Windows%s', PHP_EOL); - printf(' --help This help%s', PHP_EOL); + if (PHP_OS_FAMILY != 'Windows') { + $file_prefix = './'; + $make_prefix = ''; + } else { + $file_prefix = ''; + $make_prefix = 'n'; + } + echo << [--experimental] [--author ] + [--dir ] [--std] [--onlyunix] + [--onlywindows] [--help] + + --ext The name of the extension defined as + --experimental Passed if this extension is experimental, this creates + the EXPERIMENTAL file in the root of the extension + --author Your name, this is used if --std is passed and for the + CREDITS file + --dir Path to the directory for where extension should be + created. Defaults to the directory of where this script + lives + --std If passed, the standard header used in extensions that + is included in the core, will be used + --onlyunix Only generate configure scripts for Unix + --onlywindows Only generate configure scripts for Windows + --help This help + +HELP; exit; } /* }}} */ @@ -76,14 +144,14 @@ function print_success() { $make_prefix = 'n'; } - printf('%1$sSuccess. The extension is now ready to be compiled into PHP. To do so, use the%s', PHP_EOL); + printf('%1$sSuccess. The extension is now ready to be compiled. To do so, use the%s', PHP_EOL); printf('following steps:%1$s%1$s', PHP_EOL); - printf('cd /path/to/php-src%s', PHP_EOL); - printf('%sbuildconf%s', $file_prefix, PHP_EOL); - printf('%sconfigure --enable-%s%s', $file_prefix, $options['ext'], PHP_EOL); + printf('cd /path/to/php-src/%s%s', $options['ext'], PHP_EOL); + printf('phpize%s', PHP_EOL); + printf('%sconfigure%s', $file_prefix, PHP_EOL); printf('%smake%2$s%2$s', $make_prefix, PHP_EOL); printf('Don\'t forget to run tests once the compilation is done:%s', PHP_EOL); - printf('%smake test TESTS=ext/%s/tests%3$s%3$s', $make_prefix, $options['ext'], PHP_EOL); + printf('%smake test%2$s%2$s', $make_prefix, PHP_EOL); printf('Thank you for using PHP!%s', PHP_EOL); } /* }}} */