Autoconf.Pdf
Total Page:16
File Type:pdf, Size:1020Kb
Autoconf Creating Automatic Configuration Scripts for version 2.59, 5 November 2003 David MacKenzie Ben Elliston Akim Demaille This manual is for gnu Autoconf (version 2.59, 5 November 2003), 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 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.1 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 Libtool ................................................... 3 2.3 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 ............ 12 4 Initialization and Output Files............. 15 4.1 Initializing configure .................................... 15 4.2 Notices in configure ..................................... 15 4.3 Finding configure Input ................................. 16 4.4 Outputting Files ......................................... 17 4.5 Performing Configuration Actions.......................... 18 4.6 Creating Configuration Files............................... 19 4.7 Substitutions in Makefiles ................................. 20 4.7.1 Preset Output Variables ............................ 20 4.7.2 Installation Directory Variables...................... 22 4.7.3 Build Directories ................................... 25 4.7.4 Automatic Remaking ............................... 25 4.8 Configuration Header Files ................................ 26 4.8.1 Configuration Header Templates..................... 27 4.8.2 Using autoheader to Create ‘config.h.in’ .......... 28 4.8.3 Autoheader Macros................................. 29 4.9 Running Arbitrary Configuration Commands ............... 30 4.10 Creating Configuration Links ............................. 30 4.11 Configuring Other Packages in Subdirectories .............. 31 4.12 Default Prefix ........................................... 32 ii Autoconf 5 Existing Tests ............................ 33 5.1 Common Behavior ........................................ 33 5.1.1 Standard Symbols .................................. 33 5.1.2 Default Includes.................................... 33 5.2 Alternative Programs ..................................... 34 5.2.1 Particular Program Checks.......................... 35 5.2.2 Generic Program and File Checks ................... 37 5.3 Files..................................................... 38 5.4 Library Files ............................................. 38 5.5 Library Functions ........................................ 39 5.5.1 Portability of C Functions .......................... 39 5.5.2 Particular Function Checks ......................... 41 5.5.3 Generic Function Checks............................ 46 5.6 Header Files ............................................. 48 5.6.1 Portability of Headers .............................. 48 5.6.2 Particular Header Checks ........................... 49 5.6.3 Generic Header Checks ............................. 53 5.7 Declarations ............................................. 54 5.7.1 Particular Declaration Checks ....................... 54 5.7.2 Generic Declaration Checks ......................... 54 5.8 Structures ............................................... 55 5.8.1 Particular Structure Checks ......................... 55 5.8.2 Generic Structure Checks ........................... 56 5.9 Types ................................................... 56 5.9.1 Particular Type Checks ............................. 56 5.9.2 Generic Type Checks ............................... 57 5.10 Compilers and Preprocessors ............................. 58 5.10.1 Specific Compiler Characteristics ................... 58 5.10.2 Generic Compiler Characteristics ................... 58 5.10.3 C Compiler Characteristics ........................ 59 5.10.4 C++ Compiler Characteristics ...................... 63 5.10.5 Fortran Compiler Characteristics ................... 63 5.11 System Services ......................................... 68 5.12 UNIX Variants .......................................... 69 6 Writing Tests............................. 71 6.1 Language Choice ......................................... 71 6.2 Writing Test Programs .................................... 72 6.2.1 Guidelines for Test Programs........................ 72 6.2.2 Test Functions ..................................... 73 6.2.3 Generating Sources ................................. 74 6.3 Running the Preprocessor ................................. 76 6.4 Running the Compiler .................................... 77 6.5 Running the Linker ....................................... 77 6.6 Checking Run Time Behavior ............................. 78 6.7 Systemology ............................................. 79 6.8 Multiple Cases ........................................... 79 iii 7 Results of Tests........................... 81 7.1 Defining C Preprocessor Symbols .......................... 81 7.2 Setting Output Variables .................................. 82 7.3 Caching Results .......................................... 83 7.3.1 Cache Variable Names .............................. 85 7.3.2 Cache Files ........................................ 85 7.3.3 Cache Checkpointing ............................... 86 7.4 Printing Messages ........................................ 86 8 Programming in M4 ...................... 89 8.1 M4 Quotation ............................................ 89 8.1.1 Active Characters .................................. 89 8.1.2 One Macro Call .................................... 90 8.1.3 Quotation and Nested Macros ....................... 90 8.1.4 changequote is Evil ................................ 92 8.1.5 Quadrigraphs ...................................... 93 8.1.6 Quotation Rule Of Thumb .......................... 94 8.2 Using autom4te .......................................... 95 8.2.1 Invoking autom4te ................................. 95 8.2.2 Customizing autom4te.............................. 99 8.3 Programming in M4sugar ................................ 100 8.3.1 Redefined M4 Macros.............................. 100 8.3.2 Evaluation Macros ................................ 101 8.3.3 Forbidden Patterns ................................ 101 8.4 Programming in M4sh ................................... 102 9 Writing Autoconf Macros ................ 103 9.1 Macro Definitions ....................................... 103 9.2 Macro Names ........................................... 103 9.3 Reporting Messages...................................... 104 9.4 Dependencies Between Macros............................ 105 9.4.1 Prerequisite Macros ............................... 105 9.4.2 Suggested Ordering................................ 106 9.5 Obsoleting Macros....................................... 107 9.6 Coding Style ............................................ 107 10 Portable Shell Programming ............ 111 10.1 Shellology.............................................. 111 10.2 Here-Documents........................................ 113 10.3 File Descriptors ........................................ 114 10.4 File System Conventions ................................ 115 10.5 Shell Substitutions ..................................... 116 10.6 Assignments ........................................... 119 10.7 Parentheses in Shell Scripts ............................. 120 10.8 Special Shell Variables .................................. 120 10.9 Limitations of Shell Builtins ............................. 124 10.10 Limitations of Usual Tools ............................. 131 10.11 Limitations of Make ................................... 138 iv Autoconf 11 Manual Configuration................... 149 11.1 Specifying the System Type ............................. 149 11.2 Getting the Canonical System Type ..................... 150 11.3 Using the System Type ................................. 150 12 Site Configuration ...................... 153 12.1 Working With External Software ........................ 153 12.2 Choosing Package Options .............................. 154 12.3 Making Your Help Strings Look Pretty................... 155 12.4 Configuring Site Details................................. 155 12.5 Transforming Program Names When Installing ........... 156 12.5.1 Transformation Options .......................... 156 12.5.2 Transformation Examples ........................