This is the second part of our series on the GNU autotools system, looking at autoconf, automake and libtool. In the
previous installment, we looked at building a very simple C program, with just one source file, using autotools. In this article, we'll extend our program slightly, by shifting some data into a header file, and adding a man page.
The EXTRA_DIST target
Create a file called
hello.h in the
hello/src directory, with the following contents:
#ifndef HELLO_H
#define HELLO_H
#define GREETING "Hello world\n"
#endif
And now replace your existing file
hello.c with the following:
#include <stdio.h>
#include "hello.h"
int main(int argc,char **argv) {
printf( GREETING );
}
All we've done here is move the string "Hello world" into the
hello.h header file; nothing particularly complex. We now have to add this new file into our
Makefile.am:
bin_PROGRAMS = hello
hello_SOURCES = hello.c hello.h
As you can see, it's just another source file for the program, so we can add it to the
hello_SOURCES line. The same goes for any other sources files that are required to create your binary; just list all of the filenames in the
SOURCES primary, separated by spaces.
Occasionally, programmers like to group all of their program's header files together in a single directory, usually called
include and placed immediately below the top-level directory. Typically this is done when the headers are required to be shared between multiple binaries, and as a result of them being in a different directory from the rest of the source, you won't be able to add them to the
_SOURCES primary. In a case like this, you'll need to use the
EXTRA_DIST target to tell automake that the header files should be included in the distribution. For example:
EXTRA_DIST = data.h client.h bindings.h
In fact, the
EXTRA_DIST target can be used with any file that you'd like to add to the distribution. Create a file in the top level
hello/ directory called
BUGS, with a few sentences in it; the actual content of the file is irrevelent. We'd like to make sure that automake adds this file to the archive when we run
make dist, so change the top-level Makefile.am to look like this:
SUBDIRS = src
EXTRA_DIST = BUGS
Since we've made a few changes to our program, we'll release this as version 0.0.2. Open up
configure.ac in an editor and change the line that says
AC_INIT([hello],[0.0.1]) to:
AC_INIT([hello],[0.0.2])
Now, rebuild the entire distribution:
automake
autoconf
make clean
./configure
make
make dist
You'll now have a new archive in your top-level directory called
hello-0.0.2.tar.gz, and if you untar it, you'll see it included your new
BUGS file.
This story has been submitted to fsdaily.com! If you think this story should be read by the free software community, come vote it up and discuss it here: http://www.fsdaily.com/HighEnd/GNU_autotools_primer_part_two
Tracked: Jun 16, 09:53
This story has been submitted to fsdaily.com! If you think this story should be read by the free software community, come vote it up and discuss it here: http://www.fsdaily.com/HighEnd/GNU_autotools_primer_part_two-1
Tracked: Jun 16, 18:49