24.4 Example: The Full Pull
Suppose instead that I wanted to fully autoconfiscate
ignore for now that
zip can build on systems to which the
GNU Autotools have not been ported, like TOPS-20---perhaps a big
problem back in the real world.
The first step should always be to run
is a program which examines your source code and then generates a file
called `configure.scan' which can be used as a rough draft of a
autoscan isn't perfect, and in fact in some
situations can generate a `configure.scan' which
won't directly accept, so you should examine this file by hand before
renaming it to `configure.in'.
autoscan doesn't take into account macro names used by your
program. For instance, if
autoscan decides to generate a check
for `<fcntl.h>', it will just generate ordinary
code which in turn might define `HAVE_FCNTL_H' at
time. This just means that
autoscan isn't a panacea -- you will
probably have to modify your source to take advantage of the code that
Here is the `configure.scan' I get when I run
dnl Process this file with autoconf to produce a configure script.
dnl Checks for programs.
dnl Checks for libraries.
dnl Replace `main' with a function in -lx:
dnl Checks for header files.
AC_CHECK_HEADERS(fcntl.h malloc.h sgtty.h strings.h sys/ioctl.h \
dnl Checks for typedefs, structures, and compiler characteristics.
dnl Checks for library functions.
AC_CHECK_FUNCS(getcwd mktime regcomp rmdir strstr)
AC_OUTPUT(acorn/makefile unix/Makefile Makefile atari/Makefile)
As you can see, this isn't suitable for immediate use as
`configure.in'. For instance, it generates several
`Makefile's which we know we won't need. At this point there are
two things to do in order to fix this file.
First, we must fix outright flaws in `configure.scan', add checks
for libraries, and the like. For instance, we might also add code to
see if we are building on Windows and set a variable appropriately:
case "$target" in
*-cygwin* | *-mingw*)
# Assume Unix.
Second, we must make sure that the
zip sources use the results we
compute. So, for instance, we would check the
zip source to see
if we should use `HAVE_MMAP', which is the result of calling
At this point you might also consider using a configuration header such
as is generated by
AC_CONFIG_HEADER. Typically this involves
editing all your source files to include the header, but in the long run
this is probably a cleaner way to go than using many
on the command line. If you are making major source changes in order to
fully adapt your code to
autoconf's output, adding a
`#include' to each file will not be difficult.
This step can be quite difficult if done thoroughly, as it can involve
radical changes to the source. After this you will have a minimal but
functional `configure.in' and a knowledge of what portability
information your program has already incorporated.
Next, you want to write your `Makefile.am's. This might involve
restructuring your package so that it can more easily conform to what
Automake expects. This work might also involve source code changes if
the program makes assumptions about the layout of the install tree --
these assumptions might very well break if you follow the GNU rules
about the install layout.
At the same time as you are writing your `Makefile.am's, you might
consider libtoolizing your package. This makes sense if you want
to export shared libraries, or if you have libraries which several
executables in your package use.
In our example, since there is no library involved, we won't use Libtool.
The `Makefile.am' used in the minimal example is nearly sufficient
for our use, but not quite. Here's how we change it to add dependency
The extremely long `EXTRA_DIST' macro above has be truncated for
brevity, denoted by the `...' line.
## Process this file with automake to create Makefile.in.
bin_PROGRAMS = zip
bin_SCRIPTS = unix/zipgrep
os_sources = unix/unix.c
os_sources = win32/win32.c win32zip.c
zip_SOURCES = zip.c zipfile.c zipup.c fileio.c util.c globals.c \
crypt.c ttyio.c crc32.c crctab.c deflate.c trees.c \
## It was easier to just list all the source files than to pick out the
## non-source files.
EXTRA_DIST = algorith.doc README TODO Where crc_i386.S bits.c crc32.c \
acorn/RunMe1st acorn/ReadMe acorn/acornzip.c acorn/makefile \
acorn/match.s acorn/osdep.h acorn/riscos.c acorn/riscos.h \
acorn/sendbits.s acorn/swiven.h acorn/swiven.s acorn/zipup.h crctab.c \
crypt.c crypt.h deflate.c ebcdic.h fileio.c globals.c history \
wizdll/wizdll.def wizdll/wizmain.c wizdll/wizzip.h wizdll/zipdll16.mak \
Note that we no longer define
INCLUDES -- it is now automatically
configure. Note also that, due to a small
technicality, this `Makefile.am' won't really work with Automake
1.4. Instead, we must modify things so that we don't try to compile
`unix/unix.c' or other files from subdirectories.