⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 autoconf.texi

📁 autoconf是一个产生可以自动配置源代码包
💻 TEXI
📖 第 1 页 / 共 5 页
字号:
configuration scripts can be regenerated automatically to take advantageof the updated code.The Metaconfig package is similar in purpose to Autoconf, but thescripts it produces require manual user intervention, which is quiteinconvenient when configuring large source trees.  Unlike Metaconfigscripts, Autoconf scripts can support cross-compiling, if some care istaken in writing them.Autoconf does not solve all problems related to making portablesoftware packages---for a more complete solution, it should be used inconcert with other @acronym{GNU} build tools like Automake andLibtool.  These other tools take on jobs like the creation of aportable, recursive makefile with all of the standard targets,linking of shared libraries, and so on.  @xref{The GNU Build System},for more information.Autoconf imposes some restrictions on the names of macros used with@code{#if} in C programs (@pxref{Preprocessor Symbol Index}).Autoconf requires @acronym{GNU} M4 in order to generate the scripts.  It usesfeatures that some versions of M4, including @acronym{GNU} M4 1.3,do not have.  You should use version 1.4.4 or later of @acronym{GNU} M4.@xref{Autoconf 1}, for information about upgrading from version 1.@xref{History}, for the story of Autoconf's development.  @xref{FAQ},for answers to some common questions about Autoconf.See the @uref{http://www.gnu.org/software/autoconf/,Autoconf web page} for up-to-date information, details on the mailinglists, pointers to a list of known bugs, etc.Mail suggestions to @email{autoconf@@gnu.org, the Autoconf mailinglist}.  Past suggestions are@uref{http://lists.gnu.org/archive/html/autoconf/, archived}.Mail bug reports to @email{bug-autoconf@@gnu.org, theAutoconf Bugs mailing list}.  Past bug reports are@uref{http://lists.gnu.org/archive/html/bug-autoconf/, archived}.If possible, first check that your bug isnot already solved in current development versions, and that it has notbeen reported yet.  Be sure to include all the needed information and ashort @file{configure.ac} that demonstrates the problem.Autoconf's development tree is accessible via anonymous @acronym{CVS}; see the@uref{http://savannah.gnu.org/projects/autoconf/, AutoconfSummary} for details.  Patches relative to thecurrent @acronym{CVS} version can be sent for review to the@email{autoconf-patches@@gnu.org, Autoconf Patches mailing list}.Past patches are@uref{http://lists.gnu.org/@/archive/@/html/@/autoconf-patches/, archived}.Because of its mission, the Autoconf package itselfincludes only a set of often-usedmacros that have already demonstrated their usefulness.  Nevertheless,if you wish to share your macros, or find existing ones, see the@uref{http://autoconf-archive.cryp.to/, Autoconf MacroArchive}, which is kindly run by @email{simons@@cryp.to,Peter Simons}.@c ================================================= The GNU Build System@node The GNU Build System@chapter The @acronym{GNU} Build System@cindex @acronym{GNU} build systemAutoconf solves an important problem---reliable discovery ofsystem-specific build and runtime information---but this is only onepiece of the puzzle for the development of portable software.  To thisend, the @acronym{GNU} project has developed a suite of integratedutilities to finish the job Autoconf started: the @acronym{GNU} buildsystem, whose most important components are Autoconf, Automake, andLibtool.  In this chapter, we introduce you to those tools, point youto sources of more information, and try to convince you to use theentire @acronym{GNU} build system for your software.@menu* Automake::                    Escaping makefile hell* Gnulib::                      The @acronym{GNU} portability library* Libtool::                     Building libraries portably* Pointers::                    More info on the @acronym{GNU} build system@end menu@node Automake@section AutomakeThe ubiquity of @command{make} means that a makefile is almost theonly viable way to distribute automatic build rules for software, butone quickly runs into its numerous limitations.  Its lack ofsupport for automatic dependency tracking, recursive builds insubdirectories, reliable timestamps (e.g., for network file systems), andso on, mean that developers must painfully (and often incorrectly)reinvent the wheel for each project.  Portability is non-trivial, thanksto the quirks of @command{make} on many systems.  On top of all this is themanual labor required to implement the many standard targets that usershave come to expect (@code{make install}, @code{make distclean},@code{make uninstall}, etc.).  Since you are, of course, using Autoconf,you also have to insert repetitive code in your @code{Makefile.in} torecognize @code{@@CC@@}, @code{@@CFLAGS@@}, and other substitutionsprovided by @command{configure}.  Into this mess steps @dfn{Automake}.@cindex AutomakeAutomake allows you to specify your build needs in a @code{Makefile.am}file with a vastly simpler and more powerful syntax than that of a plainmakefile, and then generates a portable @code{Makefile.in} foruse with Autoconf.  For example, the @code{Makefile.am} to build andinstall a simple ``Hello world'' program might look like:@examplebin_PROGRAMS = hellohello_SOURCES = hello.c@end example@noindentThe resulting @code{Makefile.in} (~400 lines) automatically supports allthe standard targets, the substitutions provided by Autoconf, automaticdependency tracking, @code{VPATH} building, and so on.  @command{make}builds the @code{hello} program, and @code{make install} installs itin @file{/usr/local/bin} (or whatever prefix was given to@command{configure}, if not @file{/usr/local}).The benefits of Automake increase for larger packages (especially oneswith subdirectories), but even for small programs the added convenienceand portability can be substantial.  And that's not all@enddots{}@node Gnulib@section Gnulib@acronym{GNU} software has a well-deserved reputation for running onmany different types of systems.  While our primary goal is to writesoftware for the @acronym{GNU} system, many users and developers havebeen introduced to us through the systems that they were already using.@cindex GnulibGnulib is a central location for common @acronym{GNU} code, intended tobe shared among free software packages.  Its components are typicallyshared at the source level, rather than being a library that gets built,installed, and linked against.  The idea is to copy files from Gnulibinto your own source tree.  There is no distribution tarball; developersshould just grab source modules from the repository.  The source filesare available online, under various licenses, mostly @acronym{GNU}@acronym{GPL} or @acronym{GNU} @acronym{LGPL}.Gnulib modules typically contain C source code along with Autoconfmacros used to configure the source code.  For example, the Gnulib@code{stdbool} module implements a @file{stdbool.h} header that nearlyconforms to C99, even on old-fashioned hosts that lack @file{stdbool.h}.This module contains a source file for the replacement header, alongwith an Autoconf macro that arranges to use the replacement header onold-fashioned systems.@node Libtool@section LibtoolOften, one wants to build not only programs, but libraries, so thatother programs can benefit from the fruits of your labor.  Ideally, onewould like to produce @emph{shared} (dynamically linked) libraries,which can be used by multiple programs without duplication on disk or inmemory and can be updated independently of the linked programs.Producing shared libraries portably, however, is the stuff ofnightmares---each system has its own incompatible tools, compiler flags,and magic incantations.  Fortunately, @acronym{GNU} provides a solution:@dfn{Libtool}.@cindex LibtoolLibtool handles all the requirements of building shared libraries foryou, and at this time seems to be the @emph{only} way to do so with anyportability.  It also handles many other headaches, such as: theinteraction of Make rules with the variable suffixes ofshared libraries, linking reliably with shared libraries before they areinstalled by the superuser, and supplying a consistent versioning system(so that different versions of a library can be installed or upgradedwithout breaking binary compatibility).  Although Libtool, likeAutoconf, can be used without Automake, it is most simply utilized inconjunction with Automake---there, Libtool is used automaticallywhenever shared libraries are needed, and you need not know its syntax.@node Pointers@section PointersDevelopers who are used to the simplicity of @command{make} for smallprojects on a single system might be daunted at the prospect oflearning to use Automake and Autoconf.  As your software isdistributed to more and more users, however, you otherwisequickly find yourself putting lots of effort into reinventing theservices that the @acronym{GNU} build tools provide, and making thesame mistakes that they once made and overcame.  (Besides, sinceyou're already learning Autoconf, Automake is a piece of cake.)There are a number of places that you can go to for more information onthe @acronym{GNU} build tools.@itemize @minus@item WebThe home pages for@uref{http://www.gnu.org/@/software/@/autoconf/, Autoconf},@uref{http://www.gnu.org/@/software/@/automake/, Automake},@uref{http://www.gnu.org/@/software/@/gnulib/, Gnulib}, and@uref{http://www.gnu.org/@/software/@/libtool/, Libtool}.@item Automake Manual@xref{Top, , Automake, automake, @acronym{GNU} Automake}, for moreinformation on Automake.@item BooksThe book @cite{@acronym{GNU} Autoconf, Automake andLibtool}@footnote{@cite{@acronym{GNU} Autoconf, Automake and Libtool},by G. V. Vaughan, B. Elliston, T. Tromey, and I. L. Taylor.  SAMS (originallyNew Riders), 2000, ISBN 1578701902.} describes the complete @acronym{GNU}build environment.  You can also find@uref{http://sources.redhat.com/@/autobook/, the entire book on-line}.@end itemize@c ================================================= Making configure Scripts.@node Making configure Scripts@chapter Making @command{configure} Scripts@cindex @file{aclocal.m4}@cindex @command{configure}The configuration scripts that Autoconf produces are by conventioncalled @command{configure}.  When run, @command{configure} creates severalfiles, replacing configuration parameters in them with appropriatevalues.  The files that @command{configure} creates are:@itemize @minus@itemone or more @file{Makefile} files, usually one in each subdirectory of thepackage (@pxref{Makefile Substitutions});@itemoptionally, a C header file, the name of which is configurable,containing @code{#define} directives (@pxref{Configuration Headers});@itema shell script called @file{config.status} that, when run, recreatesthe files listed above (@pxref{config.status Invocation});@iteman optional shell script normally called @file{config.cache}(created when using @samp{configure --config-cache}) thatsaves the results of running many of the tests (@pxref{Cache Files});@itema file called @file{config.log} containing any messages produced bycompilers, to help debugging if @command{configure} makes a mistake.@end itemize@cindex @file{configure.in}@cindex @file{configure.ac}To create a @command{configure} script with Autoconf, you need to write anAutoconf input file @file{configure.ac} (or @file{configure.in}) and run@command{autoconf} on it.  If you write your own feature tests tosupplement those that come with Autoconf, you might also write filescalled @file{aclocal.m4} and @file{acsite.m4}.  If you use a C headerfile to contain @code{#define} directives, you might also run@command{autoheader}, and you can distribute the generated file@file{config.h.in} with the package.Here is a diagram showing how the files that can be used inconfiguration are produced.  Programs that are executed are suffixed by@samp{*}.  Optional files are enclosed in square brackets (@samp{[]}).@command{autoconf} and @command{autoheader} also read the installed Autoconfmacro files (by reading @file{autoconf.m4}).@noindentFiles used in preparing a software package for distribution:@exampleyour source files --> [autoscan*] --> [configure.scan] --> configure.ac@groupconfigure.ac --.               |   .------> autoconf* -----> configure[aclocal.m4] --+---+               |   `-----> [autoheader*] --> [config.h.in][acsite.m4] ---'@end groupMakefile.in -------------------------------> Makefile.in@end example@noindentFiles used in configuring a software package:@example@group                       .-------------> [config.cache]configure* ------------+-------------> config.log                       |[config.h.in] -.       v            .-> [config.h] -.               +--> config.status* -+               +--> make*Makefile.in ---'                    `-> Makefile ---'@end group@end example@menu* Writing configure.ac::        What to put in an Autoconf input file* autoscan Invocation::         Semi-automatic @file{configure.ac} writing* ifnames Invocation::          Listing the conditionals in source code* autoconf Invocation::         How to create configuration scripts* autoreconf Invocation::       Remaking multiple @command{configure} scripts@end menu@node Writing configure.ac@section Writing @file{configure.ac}To produce a @command{configure} script for a software package, create afile called @file{configure.ac} that contains invocations of theAutoconf macros that test the system features your package needs or canuse.  Autoconf macros already exist to check for many features; see@ref{Existing Tests}, for their descriptions.  For most other features,you can use Autoconf template macros to produce custom checks; see@ref{Writing Tests}, for information about them.  For especially trickyor specialized features, @file{configure.ac} might need to contain somehand-crafted shell commands; see @ref{Portable Shell}.  The@command{autoscan} program can give you a good start in writing@file{configure.ac} (@pxref{autoscan Invocation}, for more information).Previous versions of Autoconf promoted the name @file{configure.in},which is somewhat ambiguous (the tool needed to process this file is notdescribed by its extension), and introduces a slight confusion with@file{config.h.in} and so on (for which @samp{.in} means ``to beprocessed by @command{configure}'').  Using @file{configure.ac} is nowpreferred.@menu* Shell Script Compiler::       Autoconf as solution of a problem* Autoconf Language::           Programming in Autoconf* configure.ac Layout::         Standard organization of @file{configure.ac}

⌨️ 快捷键说明

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