Download Developing software with GNU

Transcript
62
Developing software with GNU
4.4 Understanding the hello world example
When you made the `hello-0.1.tar.gz' distribution, most of the les were automatically generated. The only les that were actually written by your ngers were:
`hello.c'
#include <stdio.h>
main()
{
printf("Howdy, world!\n");
}
`Makefile.am'
`configure.in'
bin_PROGRAMS = hello
hello_SOURCES = hello.c
AC_INIT(hello.cc)
AM_INIT_AUTOMAKE(hello,1.0)
AC_PROG_CC
AC_PROG_INSTALL
AC_OUTPUT(Makefile)
In this section we explain briey what the les `Makefile.am' and `configure.in' mean.
The language of `Makefile.am' is a logic language. There is no explicit statement of
execution. Only a statement of relations from which execution is inferred. On the other
hand, the language of `configure.in' is procedural. Each line of `configure.in' is a
command that is executed.
Seen in this light, here's what the `configure.in' commands shown do:
The AC_INIT command initializes the congure script. It must be passed as argument
the name of one of the source les. Any source le will do.
The AM_INIT_AUTOMAKE performs some further initializations that are related to the
fact that we are using `automake'. If you are writing your `Makefile.in' by hand,
then you don't need to call this command. The two comma-separated arguments are
the name of the package and the version number.
The AC_PROG_CC checks to see which C compiler you have.
The AC_PROG_INSTALL checks to see whether your system has a BSD compatible install
utility. If not then it uses `install-sh' which `automake' will install at the root of
your package directory if it's not there yet.
The AC_OUTPUT tells the congure script to generate `Makefile' from `Makefile.in'
The `Makefile.am' is more obvious. The rst line species the name of the program we
are building. The second line species the source les that compose the program.
For now, as far as `configure.in' is concerned you need to know the following additional
facts:
If you are building a library, then your congure script must determine how to handle
`ranlib'. To do that, add the AC_PROG_RANLIB command.
If your source code contains C++ les, you need to add the AC_PROG_CXX to your
`configure.in'.