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

📄 autoconf.texi

📁 autoconf 2.59版,可用于redhat系统.用于编译原码,编写makefile文件.
💻 TEXI
📖 第 1 页 / 共 5 页
字号:
Autoconf solves an important problem---reliable discovery ofsystem-specific build and run-time 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* 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 @file{Makefile} is almost theonly viable way to distribute automatic build rules for software, butone quickly runs into @command{make}'s numerous limitations.  Its lack ofsupport for automatic dependency tracking, recursive builds insubdirectories, reliable timestamps (e.g., for network filesystems), 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 plain@code{Makefile}, 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} willbuild the @code{hello} program, and @code{make install} will install 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 Libtool@section LibtoolVery often, 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 @code{Makefile} 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 on its own, 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 will 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 will be 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@href{http://www.gnu.org/software/autoconf/,Autoconf},@href{http://www.gnu.org/software/automake/,Automake}, and@href{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.  NewRiders, 2000, ISBN 1578701902.}  describes the complete @acronym{GNU}build environment.  You can also find the entire book on-line at@href{http://sources.redhat.com/autobook/,``The Goat Book'' homepage}.@item Tutorials and ExamplesThe @href{http://sources.redhat.com/autoconf/,Autoconf Developer Page}maintains links to a number of Autoconf/Automake tutorials online, andalso links to the @href{http://www.gnu.org/software/ac-archive/,Autoconf Macro Archive}.@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, will recreatethe 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 will 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}@end menu@node Shell Script Compiler@subsection A Shell Script CompilerJust as for any other computer language, in order to properly program@file{configure.ac} in Autoconf you must understand @emph{what} problemthe language tries to address and @emph{how} it does so.The problem Autoconf addresses is that the world is a mess.  After all,you are using Autoconf in order to have your package compile easily onall sorts of different systems, some of them being extremely hostile.Autoconf itself bears the price for these differences: @command{configure}must run on all those systems, and thus @command{configure} must limit itselfto their lowest common denominator of features.Naturally, you might then think of shell scripts; who needs@command{autoconf}?  A set of properly written shell functions is enough tomake it easy to write @command{configure} scripts by hand.  Sigh!Unfortunately, shell functions do not belong to the least commondenominator; therefore, where you would like to define a function anduse it ten times, you would instead need to copy its body ten times.So, what is really needed is some kind of compiler, @command{autoconf},that takes an Autoconf program, @file{configure.ac}, and transforms itinto a portable shell script, @command{configure}.How does @command{autoconf} perform this task?There are two obvious possibilities: creating a brand new language orextending an existing one.  The former option is very attractive: allsorts of optimizations could easily be implemented in the compiler andmany rigorous checks could be performed on the Autoconf program(e.g., rejecting any non-portable construct).  Alternatively, you canextend an existing language, such as the @code{sh} (Bourne shell)language.Autoconf does the latter: it is a layer on top of @code{sh}.  It wastherefore most convenient to implement @command{autoconf} as a macroexpander: a program that repeatedly performs @dfn{macro expansions} ontext input, replacing macro calls with macro bodies and producing a pure@code{sh} script in the end.  Instead of implementing a dedicatedAutoconf macro expander, it is natural to use an existinggeneral-purpose macro language, such as M4, and implement the extensionsas a set of M4 macros.@node Autoconf Language@subsection The Autoconf Language@cindex quotationThe Autoconf language is very different from many other computerlanguages because it treats actual code the same as plain text.  Whereasin C, for instance, data and instructions have very different syntacticstatus, in Autoconf their status is rigorously the same.  Therefore, weneed a means to distinguish literal strings from text to be expanded:quotation.When calling macros that take arguments, there must not be any blankspace between the macro name and the open parenthesis.  Arguments shouldbe enclosed within the M4 quote characters @samp{[} and @samp{]}, and beseparated by commas.  Any leading spaces in arguments are ignored,unless they are quoted.  You may safely leave out the quotes when theargument is simple text, but @emph{always} quote complex arguments suchas other macro calls.  This rule applies recursively for every macrocall, including macros called from other macros.For instance:@exampleAC_CHECK_HEADER([stdio.h],                [AC_DEFINE([HAVE_STDIO_H])],                [AC_MSG_ERROR([Sorry, can't do anything for you])])@end example@noindentis quoted properly.  You may safely simplify its quotation to:@exampleAC_CHECK_HEADER(stdio.h,                [AC_DEFINE(HAVE_STDIO_H)],                [AC_MSG_ERROR([Sorry, can't do anything for you])])@end example@noindentNotice that the argument of @code{AC_MSG_ERROR} is still quoted;otherwise, its comma would have been interpreted as an argument separator.The following example is wrong and dangerous, as it is underquoted:@exampleAC_CHECK_HEADER(stdio.h,                AC_DEFINE(HAVE_STDIO_H),                AC_MSG_ERROR([Sorry, can't do anything for you]))@end exampleIn other cases, you may have to use text that also resembles a macrocall.  You must quote that text even when it is not passed as a macro

⌨️ 快捷键说明

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