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

📄 autoconf.texi

📁 autoconf是一个产生可以自动配置源代码包
💻 TEXI
📖 第 1 页 / 共 5 页
字号:
@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 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 differs from many other computerlanguages because it treats actual code the same as plain text.  Whereasin C, for instance, data and instructions have 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 whitespace 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 blanks or newlines in arguments are ignored,unless they are quoted.  You should always quote an argument thatmight contain a macro name, comma, parenthesis, or a leading blank ornewline.  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], [1],                   [Define to 1 if you 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], 1,                   [Define to 1 if you have <stdio.h>.])],                [AC_MSG_ERROR([Sorry, can't do anything for you])])@end example@noindentbecause @samp{1} cannot contain a macro call.  Here, the argument of@code{AC_MSG_ERROR} must be quoted; otherwise, its comma would beinterpreted as an argument separator.  Also, the second and third argumentsof @samp{AC_CHECK_HEADER} must be quoted, since they containmacro calls.  The three arguments @samp{HAVE_STDIO_H}, @samp{stdio.h},and @samp{Define to 1 if you have <stdio.h>.} do not need quoting, butif you unwisely defined a macro with a name like @samp{Define} or@samp{stdio} then they would need quoting.  Cautious Autoconf userswould keep the quotes, but many Autoconf users find such precautionsannoying, and would rewrite the example as follows:@exampleAC_CHECK_HEADER(stdio.h,                [AC_DEFINE(HAVE_STDIO_H, 1,                   [Define to 1 if you have <stdio.h>.])],                [AC_MSG_ERROR([Sorry, can't do anything for you])])@end example@noindentThis is safe, so long as you adopt good naming conventions and do notdefine macros with names like @samp{HAVE_STDIO_H}, @samp{stdio}, or@samp{h}.  Though it is also safe here to omit the quotes around@samp{Define to 1 if you have <stdio.h>.} this is not recommended, asmessage strings are more likely to inadvertently contain commas.The following example is wrong and dangerous, as it is underquoted:@exampleAC_CHECK_HEADER(stdio.h,                AC_DEFINE(HAVE_STDIO_H, 1,                   Define to 1 if you 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 macroargument:@exampleecho "Hard rock was here!  --[AC_DC]"@end example@noindentwhich results in:@exampleecho "Hard rock was here!  --AC_DC"@end example@noindentWhen you use the same text in a macro argument, you must therefore havean extra quotation level (since one is stripped away by the macrosubstitution).  In general, then, it is a good idea to @emph{use doublequoting for all literal string arguments}:@exampleAC_MSG_WARN([[AC_DC stinks  --Iron Maiden]])@end exampleYou are now able to understand one of the constructs of Autoconf thathas been continually misunderstood@dots{}  The rule of thumb is that@emph{whenever you expect macro expansion, expect quote expansion};i.e., expect one level of quotes to be lost.  For instance:@exampleAC_COMPILE_IFELSE([char b[10];], [], [AC_MSG_ERROR([you lose])])@end example@noindentis incorrect: here, the first argument of @code{AC_COMPILE_IFELSE} is@samp{char b[10];} and is expanded once, which results in@samp{char b10;}.  (There was an idiom common in Autoconf's past toaddress this issue via the M4 @code{changequote} primitive, but do notuse it!)  Let's take a closer look: the author meant the first argumentto be understood as a literal, and therefore it must be quoted twice:@exampleAC_COMPILE_IFELSE([[char b[10];]], [], [AC_MSG_ERROR([you lose])])@end example@noindentVoil@`a, you actually produce @samp{char b[10];} this time!On the other hand, descriptions (e.g., the last parameter of@code{AC_DEFINE} or @code{AS_HELP_STRING}) are not literals---theyare subject to line breaking, for example---and should not be double quoted.Even if these descriptions are short and are not actually broken, doublequoting them yields weird results.Some macros take optional arguments, which this documentation representsas @ovar{arg} (not to be confused with the quote characters).  You mayjust leave them empty, or use @samp{[]} to make the emptiness of theargument explicit, or you may simply omit the trailing commas.  Thethree lines below are equivalent:@exampleAC_CHECK_HEADERS([stdio.h], [], [], [])AC_CHECK_HEADERS([stdio.h],,,)AC_CHECK_HEADERS([stdio.h])@end exampleIt is best to put each macro call on its own line in@file{configure.ac}.  Most of the macros don't add extra newlines; theyrely on the newline after the macro call to terminate the commands.This approach makes the generated @command{configure} script a littleeasier to read by not inserting lots of blank lines.  It is generallysafe to set shell variables on the same line as a macro call, becausethe shell allows assignments without intervening newlines.You can include comments in @file{configure.ac} files by starting themwith the @samp{#}.  For example, it is helpful to begin@file{configure.ac} files with a line like this:@example# Process this file with autoconf to produce a configure script.@end example@node configure.ac Layout@subsection Standard @file{configure.ac} LayoutThe order in which @file{configure.ac} calls the Autoconf macros is notimportant, with a few exceptions.  Every @file{configure.ac} mustcontain a call to @code{AC_INIT} before the checks, and a call to@code{AC_OUTPUT} at the end (@pxref{Output}).  Additionally, some macrosrely on other macros having been called first, because they checkpreviously set values of some variables to decide what to do.  Thesemacros are noted in the individual descriptions (@pxref{ExistingTests}), and they also warn you when @command{configure} is created if theyare called out of order.To encourage consistency, here is a suggested order for calling theAutoconf macros.  Generally speaking, the things near the end of thislist are those that could depend on things earlier in it.  For example,library functions could be affected by types and libraries.@display@groupAutoconf requirements@code{AC_INIT(@var{package}, @var{version}, @var{bug-report-address})}information on the packagechecks for programschecks for librarieschecks for header fileschecks for typeschecks for structureschecks for compiler characteristicschecks for library functionschecks for system services@code{AC_CONFIG_FILES(@r{[}@var{file@dots{}}@r{]})}@code{AC_OUTPUT}@end group@end display@node autoscan Invocation@section Using @command{autoscan} to Create @file{configure.ac}@cindex @command{autoscan}The @command{autoscan} program can help you create and/or maintain a@file{configure.ac} file for a software package.  @command{autoscan}examines source files in the directory tree rooted at a directory givenas a command line argument, or the current directory if none is given.It searches the source files for common portability problems and createsa file @file{configure.scan} which is a preliminary @file{configure.ac}for that package, and checks a possibly existing @file{configure.ac} forcompleteness.When using @command{autoscan} to create a @file{configure.ac}, youshould manually examine @file{configure.scan} before renaming it to@file{configure.ac}; it probably needs some adjustments.Occasionally, @command{autoscan} outputs a macro in the wrong orderrelative to another macro, so that @command{autoconf} produces a warning;you need to move such macros manually.  Also, if you want the package touse a configuration header file, you must add a call to@code{AC_CONFIG_HEADERS} (@pxref{Configuration Headers}).  You mightalso have to change or add some @code{#if} directives to your program inorder to make it work with Autoconf (@pxref{ifnames Invocation}, forinformation about a program that can help with that job).When using @command{autoscan} to maintain a @file{configure.ac}, simplyconsider adding its suggestions.  The file @file{autoscan.log}contains detailed information on why a macro is requested.@command{autoscan} uses several data files (installed along with Autoconf)to determine which macros to output when it finds particular symbols ina package's source files.  These data files all have the same format:each line consists of a symbol, one or more blanks, and the Autoconf macro tooutput if that symbol is encountered.  Lines starting with @samp{#} arecomments.@command{autoscan} accepts the following options:@table @option@item --help@itemx -hPrint a summary of the command line options and exit.@item --version@itemx -VPrint the version number of Autoconf and exit.@item --verbose@itemx -vPrint the names of the files it examines and the potentially interestingsymbols it finds in them.  This output can be voluminous.@item --include=@var{dir}@itemx -I @var{dir}Append @var{dir} to the include path.  Multiple invocations accumulate.@item --prepend-include=@var{dir}@item -B @var{dir}Prepend @var{dir} to the include path.  Multiple invocations accumulate.@end table@node ifnames Invocation@section Using @command{ifnames} to List Conditionals@cindex @command{ifnames}@command{ifnames} can help you write @file{configure.ac} for a softwarepackage.  It prints the identifiers that the package already uses in Cpreprocessor conditionals.  If a package has already been set up to havesome portability, @command{ifnames} can thus help you figure out what its@command{configure} needs to check for.  It may help fill in some gaps in a@file{configure.ac} generated by @command{autoscan} (@pxref{autoscanInvocation}).@command{ifnames} scans all of the C source files named on the command line(or the standard input, if none are given) and writes to the standardoutput a sorted list of all the identifiers that appear in those filesin @code{#if}, @code{#elif}, @code{#ifdef}, or @code{#ifndef}directives.  It prints each identifier on a line, followed by aspace-separated list of the files in which that identifier occurs.@noindent@command{ifnames} accepts the following options:@table @option@item --help@itemx -hPrint a summary of the command line options and exit.@item --version@itemx -VPrint the version number of Autoconf and exit.@end table@node autoconf Invocation

⌨️ 快捷键说明

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