/[autoconf]/autoconf/doc/autoconf.texi
ViewVC logotype

Diff of /autoconf/doc/autoconf.texi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.698 by akim, Sun Oct 27 18:17:28 2002 UTC revision 1.699 by akim, Sun Oct 27 18:19:39 2002 UTC
# Line 283  Writing Tests Line 283  Writing Tests
283    
284  * Language Choice::             Selecting which language to use for testing  * Language Choice::             Selecting which language to use for testing
285  * Writing Test Programs::       Forging source files for compilers  * Writing Test Programs::       Forging source files for compilers
286  * Examining Declarations::      Detecting header files and declarations  * Running the Preprocessor::    Detecting preprocessor symbols
287  * Examining Syntax::            Detecting language syntax features  * Running the Compiler::        Detecting language or header features
288  * Examining Libraries::         Detecting functions and global variables  * Examining Libraries::         Detecting functions and global variables
289  * Run Time::                    Testing for run-time features  * Run Time::                    Testing for run-time features
290  * Systemology::                 A zoology of operating systems  * Systemology::                 A zoology of operating systems
# Line 294  Writing Test Programs Line 294  Writing Test Programs
294    
295  * Guidelines::                  General rules for writing test programs  * Guidelines::                  General rules for writing test programs
296  * Test Functions::              Avoiding pitfalls in test programs  * Test Functions::              Avoiding pitfalls in test programs
297    * Generating Sources::          Source Program Boilerplates
298    
299  Results of Tests  Results of Tests
300    
# Line 418  Upgrading From Version 2.13 Line 419  Upgrading From Version 2.13
419  * New Macros::                  Interaction with foreign macros  * New Macros::                  Interaction with foreign macros
420  * Hosts and Cross-Compilation::  Bugward compatibility kludges  * Hosts and Cross-Compilation::  Bugward compatibility kludges
421  * AC_LIBOBJ vs LIBOBJS::        LIBOBJS is a forbidden token  * AC_LIBOBJ vs LIBOBJS::        LIBOBJS is a forbidden token
422    * AC_FOO_IFELSE vs AC_TRY_FOO::  A more generic scheme for testing sources
423    
424  Generating Test Suites with Autotest  Generating Test Suites with Autotest
425    
# Line 4522  accepted by the preprocessor.  This was Line 4524  accepted by the preprocessor.  This was
4524  inappropriate for typical uses.  Headers are typically used to compile,  inappropriate for typical uses.  Headers are typically used to compile,
4525  not merely to preprocess, and the old behavior sometimes accepted  not merely to preprocess, and the old behavior sometimes accepted
4526  headers that clashed at compile-time.  If you need to check whether a  headers that clashed at compile-time.  If you need to check whether a
4527  header is preprocessable, you can use @code{AC_TRY_CPP} or one of its  header is preprocessable, you can use @code{AC_PREPROC_IFELSE}
4528  variants (@pxref{Examining Declarations}).  (@pxref{Running the Preprocessor}).
4529    
4530  This scheme, which improves the robustness of the test, also requires  This scheme, which improves the robustness of the test, also requires
4531  that you make sure that headers that must be included before the  that you make sure that headers that must be included before the
# Line 4549  The following macros check for the decla Line 4551  The following macros check for the decla
4551  functions.  If there is no macro specifically defined to check for a  functions.  If there is no macro specifically defined to check for a
4552  symbol you need, then you can use the general macros (@pxref{Generic  symbol you need, then you can use the general macros (@pxref{Generic
4553  Declarations}) or, for more complex tests, you may use  Declarations}) or, for more complex tests, you may use
4554  @code{AC_TRY_COMPILE} (@pxref{Examining Syntax}).  @code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}).
4555    
4556  @menu  @menu
4557  * Particular Declarations::     Macros to check for certain declarations  * Particular Declarations::     Macros to check for certain declarations
# Line 4635  The following macros check for the prese Line 4637  The following macros check for the prese
4637  structures.  If there is no macro specifically defined to check for a  structures.  If there is no macro specifically defined to check for a
4638  member you need, then you can use the general structure-member macros  member you need, then you can use the general structure-member macros
4639  (@pxref{Generic Structures}) or, for more complex tests, you may use  (@pxref{Generic Structures}) or, for more complex tests, you may use
4640  @code{AC_TRY_COMPILE} (@pxref{Examining Syntax}).  @code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}).
4641    
4642  @menu  @menu
4643  * Particular Structures::       Macros to check for certain structure members  * Particular Structures::       Macros to check for certain structure members
# Line 5018  C preprocessor.  If @samp{$CC -E} doesn' Line 5020  C preprocessor.  If @samp{$CC -E} doesn'
5020  It is only portable to run @code{CPP} on files with a @file{.c}  It is only portable to run @code{CPP} on files with a @file{.c}
5021  extension.  extension.
5022    
 If the current language is C (@pxref{Language Choice}), many of the  
 specific test macros use the value of @code{CPP} indirectly by calling  
 @code{AC_TRY_CPP}, @code{AC_CHECK_HEADER}, @code{AC_EGREP_HEADER}, or  
 @code{AC_EGREP_CPP}.  
   
5023  Some preprocessors don't indicate missing include files by the error  Some preprocessors don't indicate missing include files by the error
5024  status.  For such preprocessors an internal variable is set that causes  status.  For such preprocessors an internal variable is set that causes
5025  other macros to check the standard error from the preprocessor and  other macros to check the standard error from the preprocessor and
# Line 5032  consider the test failed if any warnings Line 5029  consider the test failed if any warnings
5029    
5030  The following macros check for C compiler or machine architecture  The following macros check for C compiler or machine architecture
5031  features.  To check for characteristics not listed here, use  features.  To check for characteristics not listed here, use
5032  @code{AC_TRY_COMPILE} (@pxref{Examining Syntax}) or @code{AC_TRY_RUN}  @code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}) or
5033  (@pxref{Run Time})  @code{AC_TRY_RUN} (@pxref{Run Time})
5034    
5035  @defmac AC_C_BACKSLASH_A  @defmac AC_C_BACKSLASH_A
5036  @acindex HAVE_C_BACKSLASH_A  @acindex HAVE_C_BACKSLASH_A
# Line 5236  preprocessor.  If @samp{$CXX -E} doesn't Line 5233  preprocessor.  If @samp{$CXX -E} doesn't
5233  It is only portable to run @code{CXXCPP} on files with a @file{.c},  It is only portable to run @code{CXXCPP} on files with a @file{.c},
5234  @file{.C}, or @file{.cc} extension.  @file{.C}, or @file{.cc} extension.
5235    
 If the current language is C++ (@pxref{Language Choice}), many of the  
 specific test macros use the value of @code{CXXCPP} indirectly by  
 calling @code{AC_TRY_CPP}, @code{AC_CHECK_HEADER},  
 @code{AC_EGREP_HEADER}, or @code{AC_EGREP_CPP}.  
   
5236  Some preprocessors don't indicate missing include files by the error  Some preprocessors don't indicate missing include files by the error
5237  status.  For such preprocessors an internal variable is set that causes  status.  For such preprocessors an internal variable is set that causes
5238  other macros to check the standard error from the preprocessor and  other macros to check the standard error from the preprocessor and
# Line 5291  does not. Line 5283  does not.
5283    
5284    
5285  The following macros check for Fortran 77 compiler characteristics.  To  The following macros check for Fortran 77 compiler characteristics.  To
5286  check for characteristics not listed here, use @code{AC_TRY_COMPILE}  check for characteristics not listed here, use @code{AC_COMPILE_IFELSE}
5287  (@pxref{Examining Syntax}) or @code{AC_TRY_RUN} (@pxref{Run Time}),  (@pxref{Running the Compiler}) or @code{AC_TRY_RUN} (@pxref{Run Time}),
5288  making sure to first set the current language to Fortran 77  making sure to first set the current language to Fortran 77
5289  @code{AC_LANG(Fortran 77)} (@pxref{Language Choice}).  @code{AC_LANG(Fortran 77)} (@pxref{Language Choice}).
5290    
# Line 5636  software package, the best thing to do i Line 5628  software package, the best thing to do i
5628  @menu  @menu
5629  * Language Choice::             Selecting which language to use for testing  * Language Choice::             Selecting which language to use for testing
5630  * Writing Test Programs::       Forging source files for compilers  * Writing Test Programs::       Forging source files for compilers
5631  * Examining Declarations::      Detecting header files and declarations  * Running the Preprocessor::    Detecting preprocessor symbols
5632  * Examining Syntax::            Detecting language syntax features  * Running the Compiler::        Detecting language or header features
5633  * Examining Libraries::         Detecting functions and global variables  * Examining Libraries::         Detecting functions and global variables
5634  * Run Time::                    Testing for run-time features  * Run Time::                    Testing for run-time features
5635  * Systemology::                 A zoology of operating systems  * Systemology::                 A zoology of operating systems
# Line 5719  This section is dedicated to these sourc Line 5711  This section is dedicated to these sourc
5711  @menu  @menu
5712  * Guidelines::                  General rules for writing test programs  * Guidelines::                  General rules for writing test programs
5713  * Test Functions::              Avoiding pitfalls in test programs  * Test Functions::              Avoiding pitfalls in test programs
5714    * Generating Sources::          Source Program Boilerplates
5715  @end menu  @end menu
5716    
5717  @node Guidelines  @node Guidelines
5718  @subsection Guidelines for Test Programs  @subsection Guidelines for Test Programs
5719    
5720    The most important rule to follow when writing testing samples is:
5721    
5722    @center @emph{Look for realism.}
5723    
5724    This motto means that testing samples must be written with the same
5725    strictness as real programs are written.  In particular, you should
5726    avoid ``shortcuts'' and simplifications.
5727    
5728    Don't just play with the preprocessor if you want to prepare a
5729    compilation.  For instance, using @command{cpp} to check if a header is
5730    functional might let your @command{configure} accept a header which will
5731    cause some @emph{compiler} error.  Do not hesitate checking header with
5732    other headers included before, especially required headers.
5733    
5734    Make sure the symbols you use are properly defined, i.e., refrain for
5735    simply declaring a function yourself instead of including the proper
5736    header.
5737    
5738  Test programs should not write anything to the standard output.  They  Test programs should not write anything to the standard output.  They
5739  should return 0 if the test succeeds, nonzero otherwise, so that success  should return 0 if the test succeeds, nonzero otherwise, so that success
5740  can be distinguished easily from a core dump or other failure;  can be distinguished easily from a core dump or other failure;
# Line 5794  them, either pass them the correct numbe Line 5805  them, either pass them the correct numbe
5805  with a different return type (such as @code{char}).  with a different return type (such as @code{char}).
5806    
5807    
5808    @node Generating Sources
5809    @subsection Generating Sources
5810    
5811    Autoconf provides a set of macros that can be used to generate test
5812    source files.  They are written to be language generic, i.e., they
5813    actually depend on the current language (@pxref{Language Choice}) to
5814    ``format'' the output properly.
5815    
 @node Examining Declarations  
 @section Examining Declarations  
5816    
5817  The macro @code{AC_TRY_CPP} is used to check whether particular header  @defmac AC_LANG_CONFTEST (@var{source})
5818  files exist.  You can check for one at a time, or more than one if you  @acindex LANG_CONFTEST
5819  need several header files to all exist for some purpose.  Save the @var{source} text in the current test source file:
5820    @file{conftest.@var{extension}} where the @var{extension} depends on the
5821    current language.
5822    
5823  @defmac AC_TRY_CPP (@var{input}, @ovar{action-if-true}, @ovar{action-if-false})  Note that the @var{source} is evaluated exactly once, like regular
5824  @acindex TRY_CPP  Autoconf macro arguments, and therefore (i) you may pass a macro
5825  If the preprocessor produces no error messages while processing the  invocation, (ii) if not, be sure to double quote if needed.
5826  @var{input} (typically includes), run shell commands  @end defmac
5827  @var{action-if-true}.  Otherwise run shell commands  
5828  @var{action-if-false}.  Beware that @var{input} is double quoted.  Shell  @defmac AC_LANG_SOURCE (@var{source})
5829  variable, back quote, and backslash substitutions are performed on  @acindex LANG_SOURCE
5830  @var{input}.  Expands into the @var{source}, with proper definition of the current
5831    location (e.g., @samp{#line 1234 "configure"} in C), and definition of
5832    all the @code{AC_DEFINE} performed so far.
5833    @end defmac
5834    
5835    For instance executing (observe the double quotation!):
5836    
5837    @example
5838    AC_INIT(Autoconf Documentation, @value{VERSION}, bug-autoconf@@gnu.org)
5839    AC_DEFINE([HELLO_WORLD], ["Hello, World\n"])
5840    AC_LANG_CONFTEST(
5841       [AC_LANG_SOURCE([[const char hw[] = "Hello, World\n";]])])
5842    gcc -E -dD conftest.c -o -
5843    @end example
5844    
5845    @noindent
5846    results in:
5847    
5848    @example
5849    # 1 "conftest.c"
5850    # 1169 "configure"
5851    
5852    # 1 "confdefs.h" 1
5853    
5854    #define PACKAGE_NAME "Autoconf Documentation"
5855    #define PACKAGE_TARNAME "autoconf-documentation"
5856    #define PACKAGE_VERSION "@value{VERSION}"
5857    #define PACKAGE_STRING "Autoconf Documentation @value{VERSION}"
5858    #define PACKAGE_BUGREPORT "bug-autoconf@@gnu.org"
5859    #define HELLO_WORLD "Hello, World\n"
5860    # 1170 "configure" 2
5861    
5862    const char hw[] = "Hello, World\n";
5863    @end example
5864    
5865    @defmac AC_LANG_PROGRAM (@var{prologue}, @var{body})
5866    @acindex LANG_PROGRAM
5867    Expands into a source file which consists of the @var{prologue}, and
5868    then @var{body} as body of the main function (e.g., @code{main} in
5869    C).  Since it uses @code{AC_LANG_SOURCE}, the feature of the latter are
5870    available.
5871    @end defmac
5872    
5873    For instance:
5874    
5875    @example
5876    AC_INIT(Autoconf Documentation, @value{VERSION}, bug-autoconf@@gnu.org)
5877    AC_DEFINE([HELLO_WORLD], ["Hello, World\n"])
5878    AC_LANG_CONFTEST(
5879    [AC_LANG_PROGRAM([[const char hw[] = "Hello, World\n";]],
5880                     [[fputs (hw, stdout);]])])
5881    gcc -E -dD conftest.c -o -
5882    @end example
5883    
5884    @noindent
5885    results in:
5886    
5887    @example
5888    # 1 "conftest.c"
5889    # 1169 "configure"
5890    
5891    # 1 "confdefs.h" 1
5892    
5893    #define PACKAGE_NAME "Autoconf Documentation"
5894    #define PACKAGE_TARNAME "autoconf-documentation"
5895    #define PACKAGE_VERSION "@value{VERSION}"
5896    #define PACKAGE_STRING "Autoconf Documentation @value{VERSION}"
5897    #define PACKAGE_BUGREPORT "bug-autoconf@@gnu.org"
5898    #define HELLO_WORLD "Hello, World\n"
5899    # 1170 "configure" 2
5900    
5901    const char hw[] = "Hello, World\n";
5902    int
5903    main ()
5904    @{
5905    fputs (hw, stdout);
5906      ;
5907      return 0;
5908    @}
5909    @end example
5910    
5911    @node Running the Preprocessor
5912    @section Running the Preprocessor
5913    
5914    Sometimes one might need to run the preprocessor on some source file.
5915    @emph{Usually it is a bad idea}, as you typically need to @emph{compile}
5916    your project, not merely run the preprocessor on it; therefore you
5917    certainly want to run the compiler, not the preprocessor.  Resist to the
5918    temptation of following the easiest path.
5919    
5920    Nevertheless, if you need to run the preprocessor, then use
5921    @code{AC_PREPROC_IFELSE}.
5922    
5923    @defmac AC_PREPROC_IFELSE (@var{input}, @ovar{action-if-true}, @ovar{action-if-false})
5924    @acindex PREPROC_IFELSE
5925    Run the preprocessor of the current language (@pxref{Language Choice})
5926    on the @var{input}, run the shell commands @var{action-if-true} on
5927    success, @var{action-if-false} otherwise.  The @var{input} can be made
5928    by @code{AC_LANG_PROGRAM} and friends.
5929    
5930  This macro uses @code{CPPFLAGS}, but not @code{CFLAGS}, because  This macro uses @code{CPPFLAGS}, but not @code{CFLAGS}, because
5931  @option{-g}, @option{-O}, etc.@: are not valid options to many C  @option{-g}, @option{-O}, etc.@: are not valid options to many C
5932  preprocessors.  preprocessors.
5933    
5934    It is customary to report unexpected failures with
5935    @code{AC_MSG_FAILURE}.
5936  @end defmac  @end defmac
5937    
5938  Here is how to find out whether a header file contains a particular  For instance:
5939  declaration, such as a typedef, a structure, a structure member, or a  
5940  function.  Use @code{AC_EGREP_HEADER} instead of running @code{grep}  @example
5941  directly on the header file; on some systems the symbol might be defined  AC_INIT(Autoconf Documentation, @value{VERSION}, bug-autoconf@@gnu.org)
5942  in another header file that the file you are checking @samp{#include}s.  AC_DEFINE([HELLO_WORLD], ["Hello, World\n"])
5943    AC_PREPROC_IFELSE(
5944       [AC_LANG_PROGRAM([[const char hw[] = "Hello, World\n";]],
5945                        [[fputs (hw, stdout);]])],
5946       [AC_MSG_RESULT([OK])],
5947       [AC_MSG_FAILURE([unexpected preprocessor failure])])
5948    @end example
5949    
5950    @noindent
5951    results in:
5952    
5953    @example
5954    checking for gcc... gcc
5955    checking for C compiler default output... a.out
5956    checking whether the C compiler works... yes
5957    checking whether we are cross compiling... no
5958    checking for suffix of executables...
5959    checking for suffix of object files... o
5960    checking whether we are using the GNU C compiler... yes
5961    checking whether gcc accepts -g... yes
5962    checking for gcc option to accept ANSI C... none needed
5963    checking how to run the C preprocessor... gcc -E
5964    OK
5965    @end example
5966    
5967    @sp 1
5968    
5969    The macro @code{AC_TRY_CPP} (@pxref{Obsolete Macros}) used to play the
5970    role of @code{AC_PREPROC_IFELSE}, but double quotes its argument, making
5971    it impossible to use it to ellaborate sources.  You are encouraged to
5972    get rid of your old use of the macro @code{AC_TRY_CPP} in favor of
5973    @code{AC_PREPROC_IFELSE}, but, in the first place, are you sure you need
5974    to run the @emph{preprocessor} and not the compiler?
5975    
5976  @defmac AC_EGREP_HEADER (@var{pattern}, @var{header-file}, @var{action-if-found}, @ovar{action-if-not-found})  @defmac AC_EGREP_HEADER (@var{pattern}, @var{header-file}, @var{action-if-found}, @ovar{action-if-not-found})
5977  @acindex EGREP_HEADER  @acindex EGREP_HEADER
# Line 5831  If the output of running the preprocesso Line 5981  If the output of running the preprocesso
5981  execute @var{action-if-not-found}.  execute @var{action-if-not-found}.
5982  @end defmac  @end defmac
5983    
 To check for C preprocessor symbols, either defined by header files or  
 predefined by the C preprocessor, use @code{AC_EGREP_CPP}.  Here is an  
 example of the latter:  
   
 @example  
 AC_EGREP_CPP(yes,  
 [#ifdef _AIX  
   yes  
 #endif  
 ], is_aix=yes, is_aix=no)  
 @end example  
   
5984  @defmac AC_EGREP_CPP (@var{pattern}, @var{program}, @ovar{action-if-found}, @ovar{action-if-not-found})  @defmac AC_EGREP_CPP (@var{pattern}, @var{program}, @ovar{action-if-found}, @ovar{action-if-not-found})
5985  @acindex EGREP_CPP  @acindex EGREP_CPP
5986  @var{program} is the text of a C or C++ program, on which shell  @var{program} is the text of a C or C++ program, on which shell
# Line 5850  variable, back quote, and backslash subs Line 5988  variable, back quote, and backslash subs
5988  output of running the preprocessor on @var{program} matches the  output of running the preprocessor on @var{program} matches the
5989  extended regular expression @var{pattern}, execute shell commands  extended regular expression @var{pattern}, execute shell commands
5990  @var{action-if-found}, otherwise execute @var{action-if-not-found}.  @var{action-if-found}, otherwise execute @var{action-if-not-found}.
   
 This macro calls @code{AC_PROG_CPP} or @code{AC_PROG_CXXCPP} (depending  
 on which language is current, @pxref{Language Choice}), if it hasn't  
 been called already.  
5991  @end defmac  @end defmac
5992    
 @node Examining Syntax  
 @section Examining Syntax  
   
 To check for a syntax feature of the C, C++, or Fortran 77 compiler, such  
 as whether it recognizes a certain keyword, use @code{AC_TRY_COMPILE} to  
 try to compile a small program that uses that feature.  You can also use  
 it to check for structures and structure members that are not present on  
 all systems.  
5993    
 @defmac AC_TRY_COMPILE (@var{includes}, @var{function-body}, @ovar{action-if-found}, @ovar{action-if-not-found})  
 @acindex TRY_COMPILE  
 Create a test program in the current language (@pxref{Language Choice})  
 to see whether a function whose body consists of @var{function-body} can  
 be compiled.  If the file compiles successfully, run shell commands  
 @var{action-if-found}, otherwise run @var{action-if-not-found}.  
5994    
5995  This macro double quotes both @var{includes} and @var{function-body}.  @node Running the Compiler
5996    @section Running the Compiler
5997    
5998  For C and C++, @var{includes} is any @code{#include} statements needed  To check for a syntax feature of the (C, C++, or Fortran 77) compiler,
5999  by the code in @var{function-body} (@var{includes} will be ignored if  such as whether it recognizes a certain keyword, or simply to try some
6000  the currently selected language is Fortran 77).  This macro also uses  library feature, use @code{AC_COMPILE_IFELSE} to try to compile a small
6001  @code{CFLAGS} or @code{CXXFLAGS} if either C or C++ is the currently  program that uses that feature.
6002  selected language, as well as @code{CPPFLAGS}, when compiling.  If  
6003  Fortran 77 is the currently selected language then @code{FFLAGS} will be  
6004  used when compiling.  @defmac AC_COMPILE_IFELSE (@var{input}, @ovar{action-if-found}, @ovar{action-if-not-found})
6005    @acindex COMPILE_IFELSE
6006    Run the compiler of the current language (@pxref{Language Choice}) on
6007    the @var{input}, run the shell commands @var{action-if-true} on success,
6008    @var{action-if-false} otherwise. The @var{input} can be made by
6009    @code{AC_LANG_PROGRAM} and friends.
6010    
6011    This macro uses @code{CFLAGS} or @code{CXXFLAGS} if either C or C++ is
6012    the currently selected language, as well as @code{CPPFLAGS}, when
6013    compiling.  If Fortran 77 is the currently selected language then
6014    @code{FFLAGS} will be used when compiling.
6015    
6016  This macro does not try to link; use @code{AC_TRY_LINK} if you need to  This macro does not try to link; use @code{AC_LINK_IFELSE} if you need
6017  do that (@pxref{Examining Libraries}).  to do that (@pxref{Examining Libraries}).
6018  @end defmac  @end defmac
6019    
6020  @node Examining Libraries  @node Examining Libraries
# Line 6639  The @var{error-description} should start Line 6770  The @var{error-description} should start
6770  ``cannot'' is preferred to ``can't''.  ``cannot'' is preferred to ``can't''.
6771  @end defmac  @end defmac
6772    
6773    @defmac AC_MSG_FAILURE (@var{error-description}, @ovar{exit-status})
6774    @acindex MSG_FAILURE
6775    This @code{AC_MSG_ERROR} wrapper notifies the user of an error that
6776    prevents @command{configure} from completing @emph{and} that additional
6777    details are provided in @file{config.log}.  This is typically used when
6778    abnormal results are found during a compilation.
6779    @end defmac
6780    
6781  @defmac AC_MSG_WARN (@var{problem-description})  @defmac AC_MSG_WARN (@var{problem-description})
6782  @acindex MSG_WARN  @acindex MSG_WARN
6783  Notify the @command{configure} user of a possible problem.  This macro  Notify the @command{configure} user of a possible problem.  This macro
# Line 12842  issue. Line 12981  issue.
12981  @code{AC_HEADER_TIME}  @code{AC_HEADER_TIME}
12982  @end defmac  @end defmac
12983    
12984    @defmac AC_TRY_COMPILE (@var{includes}, @var{function-body}, @ovar{action-if-found}, @ovar{action-if-not-found})
12985    @acindex TRY_COMPILE
12986    Same as @samp{AC_COMPILE_IFELSE([AC_LANG_SOURCE([[@var{includes}]],
12987    [[@var{function-body}]])], [@var{action-if-true}],
12988    [@var{action-if-false}])} (@pxref{Running the Compiler}).
12989    
12990    This macro double quotes both @var{includes} and @var{function-body}.
12991    
12992    For C and C++, @var{includes} is any @code{#include} statements needed
12993    by the code in @var{function-body} (@var{includes} will be ignored if
12994    the currently selected language is Fortran 77).  This macro also uses
12995    @code{CFLAGS} or @code{CXXFLAGS} if either C or C++ is the currently
12996    selected language, as well as @code{CPPFLAGS}, when compiling.  If
12997    Fortran 77 is the currently selected language then @code{FFLAGS} will be
12998    used when compiling.
12999    @end defmac
13000    
13001    @defmac AC_TRY_CPP (@var{input}, @ovar{action-if-true}, @ovar{action-if-false})
13002    @acindex TRY_CPP
13003    Same as @samp{AC_PREPROC_IFELSE([AC_LANG_SOURCE([[@var{input}]])],
13004    [@var{action-if-true}], [@var{action-if-false}])} (@pxref{Running the
13005    Preprocessor}).
13006    
13007    This macro double quotes the @var{input}.
13008    @end defmac
13009    
13010  @defmac AC_UID_T  @defmac AC_UID_T
13011  @acindex UID_T  @acindex UID_T
13012  @code{AC_TYPE_UID_T}  @code{AC_TYPE_UID_T}
# Line 13132  features in version 2.50; the changes ar Line 13297  features in version 2.50; the changes ar
13297  * New Macros::                  Interaction with foreign macros  * New Macros::                  Interaction with foreign macros
13298  * Hosts and Cross-Compilation::  Bugward compatibility kludges  * Hosts and Cross-Compilation::  Bugward compatibility kludges
13299  * AC_LIBOBJ vs LIBOBJS::        LIBOBJS is a forbidden token  * AC_LIBOBJ vs LIBOBJS::        LIBOBJS is a forbidden token
13300    * AC_FOO_IFELSE vs AC_TRY_FOO::  A more generic scheme for testing sources
13301  @end menu  @end menu
13302    
13303  @node Changed Quotation  @node Changed Quotation
# Line 13457  cannot handle this task, since this is n Line 13623  cannot handle this task, since this is n
13623  Note that @code{U} must not be used in your Makefiles.  Note that @code{U} must not be used in your Makefiles.
13624    
13625    
13626    @node AC_FOO_IFELSE vs AC_TRY_FOO
13627    @subsection @code{AC_FOO_IFELSE} vs.@: @code{AC_TRY_FOO}
13628    
13629    Since Autoconf 2.50, internal codes uses @code{AC_PREPROC_IFELSE},
13630    @code{AC_COMPILE_IFELSE}, @code{AC_LINK_IFELSE}, and
13631    @code{AC_RUN_IFELSE} on the other one hand and @code{AC_LANG_SOURCES},
13632    and @code{AC_LANG_PROGRAM} on the other hand instead of the deprecated
13633    @code{AC_TRY_CPP}, @code{AC_TRY_COMPILE}, @code{AC_TRY_LINK}, and
13634    @code{AC_TRY_RUN}.  The motivations where:
13635    @itemize @minus
13636    @item
13637    a more consistent interface: @code{AC_TRY_COMPILE} etc. were double
13638    quoting their arguments;
13639    
13640    @item
13641    the combinatoric explosion is solved by decomposing on the one hand the
13642    generation of sources, and on the other hand executing the program;
13643    
13644    @item
13645    this scheme helps supporting more languages than plain C and C++.
13646    @end itemize
13647    
13648    In addition to the change of syntax, the philosphy has changed too:
13649    while emphasis was put on speed at the expense of accuracy, today's
13650    Autoconf promotes accuracy of the testing framework at, ahem..., the
13651    expense of speed.
13652    
13653    
13654    As a perfect example of what is @emph{not} to be done, here is how to
13655    find out whether a header file contains a particular declaration, such
13656    as a typedef, a structure, a structure member, or a function.  Use
13657    @code{AC_EGREP_HEADER} instead of running @code{grep} directly on the
13658    header file; on some systems the symbol might be defined in another
13659    header file that the file you are checking @samp{#include}s.
13660    
13661    As a (bad) example, here is how you should not check for C preprocessor
13662    symbols, either defined by header files or predefined by the C
13663    preprocessor: using @code{AC_EGREP_CPP}:
13664    
13665    @example
13666    @group
13667    AC_EGREP_CPP(yes,
13668    [#ifdef _AIX
13669      yes
13670    #endif
13671    ], is_aix=yes, is_aix=no)
13672    @end group
13673    @end example
13674    
13675    The above example, properly written would (i) use
13676    @code{AC_LANG_PROGRAM}, and (ii) run the compiler:
13677    
13678    @example
13679    @group
13680    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
13681    [[#if !defined _AIX
13682    # error _AIX not defined
13683    #endif
13684    ]])],
13685                       [is_aix=yes],
13686                       [is_aix=no])
13687    @end group
13688    @end example
13689    
13690    
13691  @c ============================= Generating Test Suites with Autotest  @c ============================= Generating Test Suites with Autotest
13692    
13693  @node Using Autotest  @node Using Autotest

Legend:
Removed from v.1.698  
changed lines
  Added in v.1.699

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26