internals2.buildsys.configunix.html

来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 373 行 · 第 1/2 页

HTML
373 行
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Talking to the UNIX build system: config.m4</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><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><hr /><div id="internals2.buildsys.configunix" class="sect1">  <h2 class="title">Talking to the UNIX build system: config.m4</h2>  <p class="para">   The <var class="filename">config.m4</var> file for an extension tells the UNIX   build system what <var class="filename">configure</var> options your extension   supports, what external libraries and includes you require, and what source   files are to be compiled as part of it. A reference to all the commonly used   autoconf macros, both PHP-specific and those built into autoconf, is given   in the <a href="internals2.apiref.html" class="xref">Zend Engine 2 API reference</a> section.  </p>    <div class="tip"><b class="tip">Tip</b>   <p class="para">    When developing a PHP extension, it is <em class="emphasis">strongly</em>    recommended that <strong class="command">autoconf</strong> version 2.13 be installed,    despite the newer releases which are available. Version 2.13 is recognized    as a common denominator of <strong class="command">autoconf</strong> availability,    usability, and user base. Using later versions will sometimes produce    cosmetic differences from the expected output of    <strong class="command">configure</strong>.   </p>  </div>    <div class="example" id="internals2.buildsys.configunix.sample-config" name="internals2.buildsys.configunix.sample-config">   <p><b>Example #1 An example config.m4 file</b></p>   <div class="example-contents"><div class="cdata"><pre>dnl $Id$dnl config.m4 for extension example</pre></div><div class="cdata"><pre>PHP_ARG_WITH(example, for example support,[  --with-example[=FILE]       Include example support. File is the optional path to example-config])PHP_ARG_ENABLE(example-debug, whether to enable debugging support in example,[  --enable-example-debug        example: Enable debugging support in example], no, no)PHP_ARG_WITH(example-extra, for extra libraries for example,[  --with-example-extra=DIR      example: Location of extra libraries for example], no, no)dnl Check whether the extension is enabled at allif test &quot;$PHP_EXAMPLE&quot; != &quot;no&quot;; then    dnl Check for example-config. First try any path that was given to us, then look in $PATH  AC_MSG_CHECKING([for example-config])  EXAMPLE_CONFIG=&quot;example-config&quot;  if test &quot;$PHP_EXAMPLE&quot; != &quot;yes&quot;; then    EXAMPLE_PATH=$PHP_EXAMPLE  else    EXAMPLE_PATH=`$php_shtool path $EXAMPLE_CONFIG`  fi    dnl If a usable example-config was found, use it  if test -f &quot;$EXAMPLE_PATH&quot; &amp;&amp; test -x &quot;$EXAMPLE_PATH&quot; &amp;&amp; $EXAMPLE_PATH --version &gt; /dev/null 2&gt;&amp;1; then    AC_MSG_RESULT([$EXAMPLE_PATH])    EXAMPLE_LIB_NAME=`$EXAMPLE_PATH --libname`    EXAMPLE_INCDIRS=`$EXAMPLE_PATH --incdirs`    EXAMPLE_LIBS=`$EXAMPLE_PATH --libs`        dnl Check that the library works properly    PHP_CHECK_LIBRARY($EXAMPLE_LIB_NAME, example_critical_function,    [      dnl Add the necessary include dirs      PHP_EVAL_INCLINE($EXAMPLE_INCDIRS)      dnl Add the necessary libraries and library dirs      PHP_EVAL_LIBLINE($EXAMPLE_LIBS, EXAMPLE_SHARED_LIBADD)    ],[      dnl Bail out      AC_MSG_ERROR([example library not found. Check config.log for more information.])    ],[$EXAMPLE_LIBS]    )  else    dnl No usable example-config, bail      AC_MSG_RESULT([not found])    AC_MSG_ERROR([Please check your example installation.])  fi    dnl Check whether to enable debugging  if test &quot;$PHP_EXAMPLE_DEBUG&quot; != &quot;no&quot;; then    dnl Yes, so set the C macro    AC_DEFINE(USE_EXAMPLE_DEBUG,1,[Include debugging support in example])  fi    dnl Check for the extra support  if test &quot;$PHP_EXAMPLE_EXTRA&quot; != &quot;no&quot;; then    if test &quot;$PHP_EXAMPLE_EXTRA&quot; == &quot;yes&quot;; then      AC_MSG_ERROR([You must specify a path when using --with-example-extra])    fi        PHP_CHECK_LIBRARY(example-extra, example_critical_extra_function,    [      dnl Add the neccessary paths      PHP_ADD_INCLUDE($PHP_EXAMPLE_EXTRA/include)      PHP_ADD_LIBRARY_WITH_PATH(example-extra, $PHP_EXAMPLE_EXTRA/lib, EXAMPLE_SHARED_LIBADD)      AC_DEFINE(HAVE_EXAMPLEEXTRALIB,1,[Whether example-extra support is present and requested])      EXAMPLE_SOURCES=&quot;$EXAMPLE_SOURCES example_extra.c&quot;    ],[      AC_MSG_ERROR([example-extra lib not found. See config.log for more information.])    ],[-L$PHP_EXAMPLE_EXTRA/lib]    )  fi    dnl Finally, tell the build system about the extension and what files are needed  PHP_NEW_EXTENSION(example, example.c $EXAMPLE_SOURCES, $ext_shared)  PHP_SUBST(EXAMPLE_SHARED_LIBADD)fi</pre></div>   </div>  </div>    <div id="internals2.buildsys.configunix.autoconf" class="sect2">   <h3 class="title">A short introduction to autoconf syntax</h3>   <p class="para">    <var class="filename">config.m4</var> files are written using the GNU    <strong class="command">autoconf</strong> syntax. It can be described in a nutshell as    shell scripting augmented by a powerful macro language. Comments are    delimited by the string <i>dnl</i>, and strings are quoted    using left and right brackets (e.g. <i>[</i> and    <i>]</i>). Quoting of strings can be nested as many times as    needed. A full reference to the syntax can be found in the    <strong class="command">autoconf</strong> manual at    <a href="http://www.gnu.org/software/autoconf/manual/" class="link external">&raquo; http://www.gnu.org/software/autoconf/manual/</a>.   </p>  </div>    <div id="internals2.buildsys.configunix.php-arg" class="sect2">   <h3 class="title">PHP_ARG_*: Giving users the option</h3>   <p class="para">    The very first thing seen in the example <var class="filename">config.m4</var>    above, aside from a couple of comments, are three lines using    <b>PHP_ARG_WITH()</b> and <b>PHP_ARG_ENABLE()</b>.    These provide <strong class="command">configure</strong> with the options and help text    seen when running <strong class="command">./configure --help</strong>. As the names    suggest, the difference between the two is whether they create a    <span class="option">--with-*</span> option or an    <span class="option">--enable-*</span> option. Every extension should    provide at least one or the other with the extension name, so that users    can choose whether or not to build the extension into PHP. By convention,    <b>PHP_ARG_WITH()</b> is used for an option which takes a    parameter, such as the location of a library or program required by an    extension, while <b>PHP_ARG_ENABLE()</b> is used for an option    which represents a simple flag.   </p>   <div class="example" id="internals2.buildsys.configunix.php-arg.configure-out" name="internals2.buildsys.configunix.php-arg.configure-out">    <p><b>Example #2 Sample configure output</b></p>    <div class="example-contents"><pre><div class="cdata"><pre>$ ./configure --help...  --with-example[=FILE]       Include example support. FILE is the optional path to example-config  --enable-example-debug        example: Enable debugging support in example  --with-example-extra=DIR      example: Location of extra libraries for example...$ ./configure --with-example=/some/library/path/example-config --disable-example-debug --with-example-extra=/another/library/path...checking for example support... yeschecking whether to enable debugging support in example... nochecking for extra libraries for example... /another/library/path...</pre></div>    </pre></div>   </div>   <blockquote><p><b class="note">Note</b>:          Regardless of the order in which options are specified on the command line     when <strong class="command">configure</strong> is called, the checks will be run in the     order they are specified in <var class="filename">config.m4</var>.    <br />   </p></blockquote>  </div>    <div id="internals2.buildsys.configunix.processing" class="sect2">   <h3 class="title">Processing the user&#039;s choices</h3>   <p class="para">    Now that <var class="filename">config.m4</var> can provide the user with some    choices of what to do, it&#039;s time to act upon those choices. In the example    above, the obvious default for all three options, if any of them are    unspecified, is &quot;no&quot;. As a matter of convention, it is best to

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?