GNU Autotools Tutorial Copyright c 2010 Nils Turner Chapter 1: Introduction 1 1 Introduction Those of us that have installed software from source code at some time in our career have no doubt become familiar with (and appreciate) the ./configure; make; make in- stall mantra. With a few easy steps, you too can get your code to build and install using autotools. This tutorial makes use of the distillations of the autotools concepts of Alexandre Duret-Lutz (http://www.lrde.epita.fr/~adl/dl/autotools.pdf), the Auto- conf manual (http://www.gnu.org/software/autoconf/manual/autoconf.pdf), and the Automake manual (http://www.gnu.org/software/automake/manual/automake.pdf). Chapter 2: The Basics 2 2 The Basics You want to put a simple c program into the autotools paradigm. The program has number of dot-c and dot-h files, and maybe calls some library functions. First you need to create a Makefile.am file and then a configure.ac file. 2.1 Makefile.am This is fairly straightforward. Let’s say there’s an executable called foo. It’s made from the files foo.c, print.c, and foo.h. The contents of Makefile.am should read: bin_PROGRAMS = foo foo_SOURCES = foo.c foo.h print.c 2.2 configure.ac To generate a preliminary configure.ac file, run the command: autoscan This will generate a file called configure.scan. This could be renamed to configure.ac and it would probably work, but it is more likely to need some additional information. The AC_INIT will need some modification. It probably reads something like: AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS) which should be filled in with accurate information, something like: AC_INIT([foo], [1.6], [[email protected]]) The square braces are important, they ensure that GNU m4 parses the config file cor- rectly. autotools packages create a number of helper scripts which we might want to isolate into a separate directory. This is purely optional, but if you want to use it, add the following line (right after the AC_INIT line): AC_CONFIG_AUX_DIR([build-aux]) Since you’re probably not generating a GNU coding standards-compliant software pack- age, add the following line (after the AC_CONFIG_HEADERS line but before the AC_PROG_CC line): AM_INIT_AUTOMAKE([-Wall -Werror foreign]) We know that foo requires the routine gizmo found in the bar library. We also know that the bar library uses routines from the standard math library (m), so we want to check for the existence of these libraries and generate the correct linker flags: -lbar -lm We do this by testing the library for the existence of a routine. The order is important. You want to test the library with the dependency on the other library (bar) after the library without dependencies (m) using the following lines: AC_CHECK_LIB([m],[sin]) AC_CHECK_LIB([bar],[gizmo]) autotools will create a small test program to see if the routine sin is in the -lm library and then if the routine gizmo is in the -lbar library. These lines should go after the AC_PROG_CC line. Chapter 2: The Basics 3 2.3 Create the configure script At this point, you can generate the configure script with the following command: autoreconf --install There are many, many more options that could be added to configure.ac, but the current one will generate a workable configure script. A call of: ./configure will generate a useful Makefile. The most common option to the configure script is: ./configure --prefix=/usr which will change the default installation location prefix from /usr/local to /usr. Of course, any prefix could follow the equal sign. 2.4 Makefile targets By default, ./configure generates a Makefile with a number of useful targets, the follow- ing being the most commonly used: make Self-explanatory make install Self-explanatory make clean Self-explanatory make dist Makes a distribution directory (with program name and version), copies the relevent files (source .c and .h files and autotools configuration files), and bundles them into a tarball i Table of Contents 1 Introduction............................... 1 2 The Basics ................................ 2 2.1 Makefile.am......................................... ........ 2 2.2 configure.ac........................................ ......... 2 2.3 Create the configure script ................................... 3 2.4 Makefile targets ............................................ 3.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages6 Page
-
File Size-