Autoconf Creating Automatic Configuration Scripts for Version 2.61, 16 November 2006
Total Page:16
File Type:pdf, Size:1020Kb
Autoconf Creating Automatic Configuration Scripts for version 2.61, 16 November 2006 David MacKenzie Ben Elliston Akim Demaille This manual is for GNU Autoconf (version 2.61, 16 November 2006), a package for creating scripts to configure source code packages using templates and an M4 macro package. Copyright c 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, with the Front-Cover texts being “A GNU Manual,” and with the Back-Cover Texts as in (a) below. A copy of the license is included in the section entitled “GNU Free Documentation License.” (a) The FSF’s Back-Cover Text is: “You have freedom to copy and modify this GNU Manual, like GNU software. Copies published by the Free Software Foundation raise funds for GNU development.” i Table of Contents 1 Introduction ............................... 1 2 The GNU Build System .................... 3 2.1 Automake .................................................. 3 2.2 Gnulib ..................................................... 3 2.3 Libtool ..................................................... 4 2.4 Pointers .................................................... 4 3 Making configure Scripts................... 5 3.1 Writing ‘configure.ac’...................................... 6 3.1.1 A Shell Script Compiler ................................. 6 3.1.2 The Autoconf Language ................................. 7 3.1.3 Standard ‘configure.ac’ Layout ........................ 8 3.2 Using autoscan to Create ‘configure.ac’ .................... 9 3.3 Using ifnames to List Conditionals .......................... 10 3.4 Using autoconf to Create configure ........................ 10 3.5 Using autoreconf to Update configure Scripts .............. 13 4 Initialization and Output Files............. 15 4.1 Initializing configure ...................................... 15 4.2 Notices in configure ....................................... 16 4.3 Finding configure Input ................................... 16 4.4 Outputting Files ........................................... 17 4.5 Performing Configuration Actions ........................... 18 4.6 Creating Configuration Files ................................ 20 4.7 Substitutions in Makefiles ................................... 20 4.7.1 Preset Output Variables................................ 21 4.7.2 Installation Directory Variables ......................... 23 4.7.3 Changed Directory Variables ........................... 27 4.7.4 Build Directories ...................................... 28 4.7.5 Automatic Remaking .................................. 28 4.8 Configuration Header Files .................................. 29 4.8.1 Configuration Header Templates ........................ 30 4.8.2 Using autoheader to Create ‘config.h.in’.............. 31 4.8.3 Autoheader Macros .................................... 32 4.9 Running Arbitrary Configuration Commands ................. 33 4.10 Creating Configuration Links............................... 34 4.11 Configuring Other Packages in Subdirectories................ 34 4.12 Default Prefix............................................. 35 ii Autoconf 5 Existing Tests ............................ 37 5.1 Common Behavior ......................................... 37 5.1.1 Standard Symbols ..................................... 37 5.1.2 Default Includes ....................................... 37 5.2 Alternative Programs ....................................... 38 5.2.1 Particular Program Checks ............................. 39 5.2.2 Generic Program and File Checks ....................... 41 5.3 Files ...................................................... 43 5.4 Library Files ............................................... 44 5.5 Library Functions .......................................... 45 5.5.1 Portability of C Functions .............................. 45 5.5.2 Particular Function Checks ............................. 48 5.5.3 Generic Function Checks ............................... 54 5.6 Header Files ............................................... 56 5.6.1 Portability of Headers .................................. 56 5.6.2 Particular Header Checks............................... 58 5.6.3 Generic Header Checks ................................. 62 5.7 Declarations ............................................... 63 5.7.1 Particular Declaration Checks .......................... 64 5.7.2 Generic Declaration Checks............................. 64 5.8 Structures ................................................. 65 5.8.1 Particular Structure Checks ............................ 65 5.8.2 Generic Structure Checks............................... 66 5.9 Types ..................................................... 66 5.9.1 Particular Type Checks ................................ 66 5.9.2 Generic Type Checks .................................. 69 5.10 Compilers and Preprocessors ............................... 69 5.10.1 Specific Compiler Characteristics ...................... 69 5.10.2 Generic Compiler Characteristics ...................... 70 5.10.3 C Compiler Characteristics ............................ 70 5.10.4 C++ Compiler Characteristics .......................... 75 5.10.5 Objective C Compiler Characteristics .................. 76 5.10.6 Erlang Compiler and Interpreter Characteristics......... 77 5.10.7 Fortran Compiler Characteristics....................... 77 5.11 System Services ........................................... 82 5.12 Posix Variants ............................................ 83 5.13 Erlang Libraries........................................... 84 6 Writing Tests............................. 87 6.1 Language Choice ........................................... 87 6.2 Writing Test Programs ..................................... 88 6.2.1 Guidelines for Test Programs ........................... 89 6.2.2 Test Functions......................................... 89 6.2.3 Generating Sources .................................... 90 6.3 Running the Preprocessor ................................... 92 6.4 Running the Compiler ...................................... 93 6.5 Running the Linker......................................... 94 6.6 Checking Runtime Behavior................................. 94 iii 6.7 Systemology ............................................... 96 6.8 Multiple Cases ............................................. 96 7 Results of Tests........................... 99 7.1 Defining C Preprocessor Symbols ............................ 99 7.2 Setting Output Variables .................................. 100 7.3 Special Characters in Output Variables ..................... 102 7.4 Caching Results ........................................... 102 7.4.1 Cache Variable Names ................................ 104 7.4.2 Cache Files .......................................... 104 7.4.3 Cache Checkpointing.................................. 105 7.5 Printing Messages ......................................... 105 8 Programming in M4 ..................... 107 8.1 M4 Quotation............................................. 107 8.1.1 Active Characters .................................... 107 8.1.2 One Macro Call ...................................... 108 8.1.3 Quotation and Nested Macros ......................... 109 8.1.4 changequote is Evil .................................. 110 8.1.5 Quadrigraphs......................................... 111 8.1.6 Quotation Rule Of Thumb ............................ 112 8.2 Using autom4te ........................................... 113 8.2.1 Invoking autom4te.................................... 113 8.2.2 Customizing autom4te ................................ 117 8.3 Programming in M4sugar .................................. 118 8.3.1 Redefined M4 Macros ................................. 118 8.3.2 Looping constructs ................................... 119 8.3.3 Evaluation Macros .................................... 120 8.3.4 Text processing Macros ............................... 120 8.3.5 Forbidden Patterns ................................... 121 8.4 Programming in M4sh ..................................... 121 8.5 File Descriptor Macros .................................... 123 9 Writing Autoconf Macros ................ 125 9.1 Macro Definitions ......................................... 125 9.2 Macro Names ............................................. 125 9.3 Reporting Messages ....................................... 126 9.4 Dependencies Between Macros ............................. 127 9.4.1 Prerequisite Macros ................................... 127 9.4.2 Suggested Ordering ................................... 128 9.4.3 One-Shot Macros ..................................... 129 9.5 Obsoleting Macros ........................................ 129 9.6 Coding Style .............................................. 130 iv Autoconf 10 Portable Shell Programming ............ 133 10.1 Shellology ............................................... 133 10.2 Here-Documents ......................................... 135 10.3 File Descriptors .......................................... 136 10.4 File System Conventions .................................. 138 10.5 Shell Substitutions ....................................... 140 10.6 Assignments ............................................. 144 10.7 Parentheses in Shell Scripts ............................... 144 10.8 Slashes in