internals2.buildsys.configunix.html
来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 373 行 · 第 1/2 页
HTML
373 行
use this as the default for the option which enables the extension, as it will be overridden by <strong class="command">phpize</strong> for extensions built separately, and should not clutter the extension space by default when being built into PHP. The code to process the three options is by far the most complicated. </p> <div id="internals2.buildsys.configunix.processing.with-example" class="sect3"> <h4 class="title">Handling the --with-example[=FILE] option</h4> <p class="para"> The first check made of the <span class="option">--with-example[=FILE]</span> option is whether it was set at all. As this option controls the inclusion of the entire extension, if it was unspecified, given in the negative form (<span class="option">--without-example</span>), or given the value "no", nothing else is done at all. In the example above, it is specified with the value <i>/some/library/path/example-config</i>, so the first test succeeds. </p> <p class="para"> Next, the code calls <b>AC_MSG_CHECKING()</b>, an <strong class="command">autoconf</strong> macro which outputs a standard "checking for something" line, and checks whether the user gave an explicit path to the fictional <strong class="command">example-config</strong>. In this example, <i>PHP_EXAMPLE</i> got the value <i>/some/library/path/example-config</i>, which is now copied into the EXAMPLE_PATH variable. Had the user specified only <span class="option">--with-example</span>, the code would have executed <strong class="command">$php_shtool path $EXAMPLE_CONFIG</strong>, which would try to guess the location of <strong class="command">example-config</strong> using the user's current <i>PATH</i>. Either way, the next step is to check whether the chosen <i>EXAMPLE_PATH</i> is a regular file, is executable, and can be run successfully. If so, <b>AC_MSG_RESULT()</b> is called, which completes the output line started by <b>AC_MSG_CHECKING()</b>. Otherwise, <b>AC_MSG_ERROR()</b> is called, which prints the given message and halts <strong class="command">configure</strong> immediately. </p> <p class="para"> The code now determines some site-specific configuration information by running <strong class="command">example-config</strong> several times. The next call is to <b>PHP_CHECK_LIBRARY()</b>, a macro provided by the PHP buildsystem as a wrapper around <strong class="command">autoconf</strong>'s <b>AC_CHECK_LIB()</b>. <b>PHP_CHECK_LIBRARY()</b> attempts to compile, link, and run a program which calls the symbol specified by the second parameter in the library specified by the first, using the string given in the fifth as extra linker options. If the attempt succeeds, the script given in the third parameter is run. This script tells the PHP buildsystem to extract include paths, library paths, and library names from the raw option strings <strong class="command">example-config</strong> provided. If the attempt fails, the script in the fourth parameter is run instead. In this case, <b>AC_MSG_ERROR()</b> is called to stop processing. </p> </div> <div id="internals2.buildsys.configunix.processing.enable-example-debug" class="sect3"> <h4 class="title">Handling the --enable-example-debug option</h4> <p class="para"> Processing the <span class="option">--enable-example-debug</span> is much simpler. A simple check for its truth value is performed. If that check succeeds, <b>AC_DEFINE()</b> is called to make the C macro <i>USE_EXAMPLE_DEBUG</i> available to the source of the extension. The third parameter is a comment string for <var class="filename">config.h</var>; it is safe to leave this empty, and often is. </p> </div> <div id="internals2.buildsys.configunix.processing.with-example-extra" class="sect3"> <h4 class="title">Handling the --with-example-extra=DIR option</h4> <p class="para"> For the sake of this example, the fictional "extra" functionality requested by the <span class="option">--with-example-extra=DIR</span> option does not share the fictional <strong class="command">example-config</strong> program, nor does it have any default paths to search. Therefore, the user is required to provide the installation prefix of the necessary library. This setup is somewhat unlikely in a real-world extension, but is considered illustrative. </p> <p class="para"> The code begins in a now-familiar way by checking the truth value of <i>PHP_EXAMPLE_EXTRA</i>. If a negative form was provided, no further processing is done; the user did not request extra functionality. If a positive form was provided without a parameter, <b>AC_MSG_ERROR()</b> is called to halt processing. The next step is another invocation of <b>PHP_CHECK_LIBRARY()</b>. This time, since there is no set of predefined compiler options provided, <b>PHP_ADD_INCLUDE()</b> and <b>PHP_ADD_LIBRARY_WITH_PATH()</b> are used to construct the necessary include paths, library paths, and library flags for the extra functionality. <b>AC_DEFINE()</b> is also called to indicate to the code that the extra functionality was both requested and available, and a variable is set to tell later code that there are extra source files to build. If the check fails, the familiar <b>AC_MSG_ERROR()</b> is called. A different way to handle the failure would have been to call <b>AC_MSG_WARNING()</b> instead, e.g.: </p> <div class="informalexample"> <div class="example-contents"><div class="cdata"><pre> AC_MSG_WARNING([example-extra lib not found. example will be built without extra functionality.])</pre></div> </div> </div> <p class="para"> In this case, <strong class="command">configure</strong> would print a warning message rather than an error, and continue processing. Which way such failures are handled is a design decision left to the extension developer. </p> </div> </div> <div id="internals2.buildsys.configunix.finishing" class="sect2"> <h3 class="title">Telling the buildsystem what was decided</h3> <p class="para"> With all the necessary includes and libraries specified, with all the options processed and macros defined, one more thing remains to be done: The build system must be told to build the extension itself, and which files are to be used for that. To do this, the <b>PHP_NEW_EXTENSION()</b> macro is called. The first parameter is the name of the extension, which is the same as the name of the directory containing it. The second parameter is the list of all source files which are part of the extension. See <b>PHP_ADD_BUILD_DIR()</b> for information about adding source files in subdirectories to the build process. The third parameter should always be <i>$ext_shared</i>, a value which was determined by <strong class="command">configure</strong> when <b>PHP_ARG_WITH()</b> was called for <span class="option">--with-example[=FILE]</span>. The fourth parameter specifies a "SAPI class", and is only useful for extensions which require the CGI or CLI SAPIs specifically. It should be left empty in all other cases. The fifth parameter specifies a list of flags to be added to <i>CFLAGS</i> while building the extension; the sixth is a boolean value which, if "yes", will force the entire extension to be built using <i>$CXX</i> instead of <i>$CC</i>. All parameters after the third are optional. Finally, <b>PHP_SUBST()</b> is called to enable shared builds of the extension. See <a href="internals2.faq.html" class="xref">Extension FAQs</a> for more information on disabling support for building an extension in shared mode. </p> </div> <div id="internals2.buildsys.configunix.counter" class="sect2"> <h3 class="title">The counter extension's config.m4 file</h3> <p class="para"> The counter extension previously documented has a much simpler <var class="filename">config.m4</var> file than that described above, as it doesn't make use of many buildsystem features. This is a preferred method of operation for any extension that doesn't use an external or bundled library. </p> <div class="example" id="internals2.buildsys.configunix.counter.configunix" name="internals2.buildsys.configunix.counter.configunix"> <p><b>Example #3 counter's config.m4 file</b></p> <div class="example-contents"><div class="cdata"><pre>dnl </pre></div><div class="cdata"><pre>$</pre></div><div class="cdata"><pre>Id$dnl config.m4 for extension counterPHP_ARG_ENABLE(counter, for counter support,[ --enable-counter Include counter support])dnl Check whether the extension is enabled at allif test "$PHP_COUNTER" != "no"; then dnl Finally, tell the build system about the extension and what files are needed PHP_NEW_EXTENSION(counter, counter.c counter_util.c, $ext_shared) PHP_SUBST(COUNTER_SHARED_LIBADD)fi</pre></div> </div> </div> </div> </div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="internals2.buildsys.skeleton.html">The ext_skel script</a></div> <div class="next" style="text-align: right; float: right;"><a href="internals2.buildsys.configwin.html">Talking to the Windows build system: config.w32</a></div> <div class="up"><a href="internals2.buildsys.html">The PHP 5 build system</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?