GNU Automake for Version 1.11.1, 8 December 2009
Total Page:16
File Type:pdf, Size:1020Kb
GNU Automake For version 1.11.1, 8 December 2009 David MacKenzie Tom Tromey Alexandre Duret-Lutz This manual is for GNU Automake (version 1.11.1, 8 December 2009), a program that creates GNU standards-compliant Makefiles from template files. Copyright c 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 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.3 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled \GNU Free Documentation License." Chapter 2: An Introduction to the Autotools 1 1 Introduction Automake is a tool for automatically generating `Makefile.in's from files called `Makefile.am'. Each `Makefile.am' is basically a series of make variable definitions1, with rules being thrown in occasionally. The generated `Makefile.in's are compliant with the GNU Makefile standards. The GNU Makefile Standards Document (see Section \Makefile Conventions" in The GNU Coding Standards) is long, complicated, and subject to change. The goal of Automake is to remove the burden of Makefile maintenance from the back of the individual GNU maintainer (and put it on the back of the Automake maintainers). The typical Automake input file is simply a series of variable definitions. Each suchfile is processed to create a `Makefile.in'. There should generally be one `Makefile.am' per directory of a project. Automake does constrain a project in certain ways; for instance, it assumes that the project uses Autoconf (see Section \Introduction" in The Autoconf Manual), and enforces certain restrictions on the `configure.ac' contents2. Automake requires perl in order to generate the `Makefile.in's. However, the distri- butions created by Automake are fully GNU standards-compliant, and do not require perl in order to be built. Mail suggestions and bug reports for Automake to [email protected]. 2 An Introduction to the Autotools If you are new to Automake, maybe you know that it is part of a set of tools called The Autotools. Maybe you've already delved into a package full of files namedconfigure ` ', `configure.ac', `Makefile.in', `Makefile.am', `aclocal.m4', . ., some of them claiming to be generated by Autoconf or Automake. But the exact purpose of these files and their relations is probably fuzzy. The goal of this chapter is to introduce you to this machinery, to show you how it works and how powerful it is. If you've never installed or seen such a package, do not worry: this chapter will walk you through it. If you need some teaching material, more illustrations, or a less automake-centered continuation, some slides for this introduction are available in Alexandre Duret-Lutz's Autotools Tutorial. This chapter is the written version of the first part of his tutorial. 2.1 Introducing the GNU Build System It is a truth universally acknowledged, that a developer in possession of a new package, must be in want of a build system. In the Unix world, such a build system is traditionally achieved using the command make (see Section \Overview" in The GNU Make Manual). The developer expresses the recipe to 1 These variables are also called make macros in Make terminology, however in this manual we reserve the term macro for Autoconf's macros. 2 Older Autoconf versions used `configure.in'. Autoconf 2.50 and greater promotes `configure.ac' over `configure.in'. The rest of this documentation will refer to `configure.ac', but Automake also supports `configure.in' for backward compatibility. Chapter 2: An Introduction to the Autotools 2 build his package in a `Makefile'. This file is a set of rules to build the files in the package. For instance the program `prog' may be built by running the linker on the filesmain.o ` ', `foo.o', and `bar.o'; the filemain.o ` ' may be built by running the compiler on `main.c'; etc. Each time make is run, it reads `Makefile', checks the existence and modification time of the files mentioned, decides what files need to be built (or rebuilt), and runsthe associated commands. When a package needs to be built on a different platform than the one it was developed on, its `Makefile' usually needs to be adjusted. For instance the compiler may have another name or require more options. In 1991, David J. MacKenzie got tired of customizing `Makefile' for the 20 platforms he had to deal with. Instead, he handcrafted a little shell script called `configure' to automatically adjust the `Makefile' (see Section \Genesis" in The Autoconf Manual). Compiling his package was now as simple as running ./configure && make. Today this process has been standardized in the GNU project. The GNU Coding Stan- dards (see Section \Managing Releases" in The GNU Coding Standards) explains how each package of the GNU project should have a `configure' script, and the minimal interface it should have. The `Makefile' too should follow some established conventions. The result? A unified build system that makes all packages almost indistinguishable by the installer. In its simplest scenario, all the installer has to do is to unpack the package, run ./configure && make && make install, and repeat with the next package to install. We call this build system the GNU Build System, since it was grown out of the GNU project. However it is used by a vast number of other packages: following any existing convention has its advantages. The Autotools are tools that will create a GNU Build System for your package. Autoconf mostly focuses on `configure' and Automake on `Makefile's. It is entirely possible to create a GNU Build System without the help of these tools. However it is rather burdensome and error-prone. We will discuss this again after some illustration of the GNU Build System in action. 2.2 Use Cases for the GNU Build System In this section we explore several use cases for the GNU Build System. You can re- play all these examples on the `amhello-1.0.tar.gz' package distributed with Automake. If Automake is installed on your system, you should find a copy of this filepre- in` fix/share/doc/automake/amhello-1.0.tar.gz', where prefix is the installation prefix specified during configurationprefix ( defaults to `/usr/local', however if Automake was installed by some GNU/Linux distribution it most likely has been set to `/usr'). If you do not have a copy of Automake installed, you can find a copy of this file insidedoc/ the` ' directory of the Automake package. Some of the following use cases present features that are in fact extensions to the GNU Build System. Read: they are not specified by the GNU Coding Standards, but they are nonetheless part of the build system created by the Autotools. To keep things simple, we do not point out the difference. Our objective is to show you many of the features that the build system created by the Autotools will offer to you. Chapter 2: An Introduction to the Autotools 3 2.2.1 Basic Installation The most common installation procedure looks as follows. ~ % tar zxf amhello-1.0.tar.gz ~ % cd amhello-1.0 ~/amhello-1.0 % ./configure ... config.status: creating Makefile config.status: creating src/Makefile ... ~/amhello-1.0 % make ... ~/amhello-1.0 % make check ... ~/amhello-1.0 % su Password: /home/adl/amhello-1.0 # make install ... /home/adl/amhello-1.0 # exit ~/amhello-1.0 % make installcheck ... The user first unpacks the package. Here, and in the following examples, we will usethe non-portable tar zxf command for simplicity. On a system without GNU tar installed, this command should read gunzip -c amhello-1.0.tar.gz | tar xf -. The user then enters the newly created directory to run the `configure' script. This script probes the system for various features, and finally creates theMakefile ` 's. In this toy example there are only two `Makefile's, but in real-world projects, there may be many more, usually one `Makefile' per directory. It is now possible to run make. This will construct all the programs, libraries, and scripts that need to be constructed for the package. In our example, this compiles the `hello' program. All files are constructed in place, in the source tree; we will see laterhow this can be changed. make check causes the package's tests to be run. This step is not mandatory, but it is often good to make sure the programs that have been built behave as they should, before you decide to install them. Our example does not contain any tests, so running make check is a no-op. After everything has been built, and maybe tested, it is time to install it on the sys- tem. That means copying the programs, libraries, header files, scripts, and other data files from the source directory to their final destination on the system. Thecommand make install will do that. However, by default everything will be installed in subdirec- tories of `/usr/local': binaries will go into `/usr/local/bin', libraries will end up in `/usr/local/lib', etc. This destination is usually not writable by any user, so we as- sume that we have to become root before we can run make install. In our example, running make install will copy the program `hello' into `/usr/local/bin' and `README' into `/usr/local/share/doc/amhello'. Chapter 2: An Introduction to the Autotools 4 A last and optional step is to run make installcheck.