📄 z69.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html> <head> <title> configure.in </title> <meta name="GENERATOR" content= "Modular DocBook HTML Stylesheet Version 1.45"> <link rel="HOME" title="GTK+ / Gnome Application Development" href="ggad.html"> <link rel="UP" title="Creating Your Source Tree" href= "cha-source.html"> <link rel="PREVIOUS" title="Source Tree Checklist" href= "z68.html"> <link rel="NEXT" title="Makefile.am" href="z70.html"> </head> <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink= "#840084" alink="#0000FF"> <div class="NAVHEADER"> <table width="100%" border="0" bgcolor="#ffffff" cellpadding= "1" cellspacing="0"> <tr> <th colspan="4" align="center"> <font color="#000000" size="2">GTK+ / Gnome Application Development</font> </th> </tr> <tr> <td width="25%" bgcolor="#ffffff" align="left"> <a href="z68.html"><font color="#0000ff" size="2"><b> <<< Previous</b></font></a> </td> <td width="25%" colspan="2" bgcolor="#ffffff" align= "center"> <font color="#0000ff" size="2"><b><a href="ggad.html"> <font color="#0000ff" size="2"><b> Home</b></font></a></b></font> </td> <td width="25%" bgcolor="#ffffff" align="right"> <a href="z70.html"><font color="#0000ff" size="2"><b> Next >>></b></font></a> </td> </tr> </table> </div> <div class="SECT1"> <h1 class="SECT1"> <a name="Z69"><tt class="FILENAME">configure.in</tt></a> </h1> <p> <tt class="APPLICATION">autoconf</tt> processes <tt class= "FILENAME">configure.in</tt> to produce a <tt class= "FILENAME">configure</tt> script. <tt class="FILENAME"> configure</tt> is a portable shell script which examines the build environment to determine which libraries are available, which features the platform has, where libraries and headers are located, and so on. Based on this information, it modifies compiler flags, generates makefiles, and/or outputs the file <tt class="FILENAME"> config.h</tt> with appropriate preprocessor symbols defined. Again, <tt class="FILENAME">configure</tt> does not require <tt class="APPLICATION">autoconf</tt> to run; you generate it before distributing your software, so users do not have to have <tt class="APPLICATION">autoconf</tt>. </p> <p> Your job is to write <tt class="FILENAME"> configure.in</tt>. The file is basically a series of <tt class="APPLICATION">m4</tt> macros, which expand to snippets of shell script according to the parameters you pass them. You can also write shell code manually. Really understanding how to write a <tt class="FILENAME"> configure.in</tt> requires some knowledge of <tt class= "APPLICATION">m4</tt> (which is pretty simple) and some knowledge of the Bourne shell (which is a black art). Fortunately, you can cheat: start with an existing <tt class="FILENAME">configure.in</tt> and modify it slightly to suit your application. There's also an extensive <tt class="APPLICATION">autoconf</tt> manual, which describes the many pre-written macros shipped with <tt class= "APPLICATION">autoconf</tt>. </p> <p> The GTK+ and Gnome developers have simplified things still further, by providing macros to locate GTK+ and Gnome on the user's system. </p> <p> Here is a sample <tt class="FILENAME">configure.in</tt>, from a Gnome version of "Hello, World": </p> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="PROGRAMLISTING"> AC_INIT(src/hello.c)AM_CONFIG_HEADER(config.h)AM_INIT_AUTOMAKE(GnomeHello, 0.1)AM_MAINTAINER_MODEAM_ACLOCAL_INCLUDE(macros)GNOME_INITAC_PROG_CCAC_ISC_POSIXAC_HEADER_STDCAC_ARG_PROGRAMAM_PROG_LIBTOOLGNOME_COMPILE_WARNINGSALL_LINGUAS="da de es fr gl nl no pl ru sv fi uk"AM_GNU_GETTEXTAC_SUBST(CFLAGS)AC_SUBST(CPPFLAGS)AC_SUBST(LDFLAGS)AC_OUTPUT([Makefilemacros/Makefilesrc/Makefileintl/Makefilepo/Makefile.inpixmaps/Makefiledoc/Makefiledoc/C/Makefiledoc/es/Makefile]) </pre> </td> </tr> </table> <p> Before describing each macro, some general points should be made. First, those macros that begin with <tt class= "APPLICATION">AC</tt> come with <tt class="APPLICATION"> autoconf</tt>, and those that begin with <tt class= "APPLICATION">AM</tt> usually come with <tt class= "APPLICATION">automake</tt>. (This is useful when you're trying to find documentation for them.) The macros that begin with <tt class="APPLICATION">GNOME</tt> come in the Gnome <tt class="FILENAME">macros</tt> directory. These macros are written in <tt class="APPLICATION">m4</tt>; the standard ones from <tt class="APPLICATION"> autoconf</tt>/<tt class="APPLICATION">automake</tt> reside in <tt class="FILENAME">/usr/share/aclocal</tt>, if you installed <tt class="APPLICATION">autoconf</tt>/<tt class= "APPLICATION">automake</tt> under <tt class="FILENAME"> /usr</tt>. (An aside: the <tt class="FILENAME">macros</tt> directory is not a good thing; each Gnome package should install its own <tt class="APPLICATION">m4</tt> files to <tt class="FILENAME">/usr/share/aclocal</tt>. Newer Gnome versions attempt to fix the problem.) </p> <ul> <li> <p> <span class="SYMBOL">AC_INIT</span> is always the first macro in <tt class="FILENAME">configure.in</tt>. It expands to a lot of boilerplate code shared by all <tt class="FILENAME">configure</tt> scripts; this code parses the command line arguments to <tt class= "FILENAME">configure</tt>. The macro's one argument is a file that should be present in the source directory; this is used as a sanity check, to be sure <tt class= "FILENAME">configure</tt> has correctly located the source directory. </p> </li> <li> <p> <span class="SYMBOL">AM_CONFIG_HEADER</span> specifies a header file to create; this will almost always be <tt class="FILENAME">config.h</tt>. The created header file will contain C preprocessor symbols defined by <tt class="FILENAME">configure</tt>. At a minimum, the symbols <span class="STRUCTNAME">PACKAGE</span> and <span class="STRUCTNAME">VERSION</span> will be defined, which makes it easy to put the name and version of your program in your code without hard-coding them. (Your non-public source files should <tt class="APPLICATION">#include <config.h></tt> to take advantage of its definitions; however, <tt class="APPLICATION">config.h</tt> should never be installed, because it would conflict with other packages.) </p> </li> <li> <p> <span class="SYMBOL">AM_INIT_AUTOMAKE</span> initializes <tt class="APPLICATION">automake</tt>; the arguments to this macro are the name and version of the package being compiled. (These arguments become the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -