A first disclaimer is that I don't really like autoconf and automake. This is
not the place for longer dissertations, so I won't spend more words on this.
However, it is a matter of facts that many users just like to fetch your
application, and issue the usual ./configure && make &&
make install right ahead.
So, this is a synthetic tutorial for moving a Makefile-based program to an
autohell- (this is a popular way to refer to { autoconf, automake, libtool }
that I will encourage) enabled package.
A somewhat complete, likely example is given here. If your PRE is not exactly like the one proposed, you just probably won't need to perform the corresponding following steps.
Definition of the problem:
PRE: you have a tree with
So, this is what to do for moving with the very minimum effort:
$ autoscanautoscan tries to produce a suitable configure.ac file (autoconf's driver) by performing simple analyses on the files in the package. This is enough for the moment (many people are just happy with it as permanent). Autoscan actually produces a configure.scan file, so let it have the name autoconf will look for:
$ mv configure.scan configure.ac-- note: configure.in was the name used for autoconf files, now deprecated.
$ vim configure.aclook in the very first lines for the following:
AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)and replace with your stuff, e.g.:
AC_INIT(pippo, 2.6, paperino@staff.pippo.org)
$ autoconfThis produces two files: autom4te.cache and configure. The first one is a directory used for speeding up the job of autohell tools, and may be removed when releasing the package. The latter is the shell script called by final users.
$ vim Makefile.amlist the subdirectories where work is needed:
AUTOMAKE_OPTIONS = foreign SUBDIRS = src doc examples man scriptsthe first line sets the mode automake will behave like. "foreign" means not GNU, and is common for avoiding boring messages about files organized differently from what gnu expects.
$ vim src/Makefile.amand insert:
# what flags you want to pass to the C compiler & linker CFLAGS = --pedantic -Wall -std=c99 -O2 LDFLAGS = # this lists the binaries to produce, the (non-PHONY, binary) targets in # the previous manual Makefile bin_PROGRAMS = targetbinary1 targetbinary2 [...] targetbinaryN targetbinary1_SOURCES = targetbinary1.c myheader.h [...] targetbinary2_SOURCES = targetbinary2.c . . targetbinaryN_SOURCES = targetbinaryN.cThis was the most difficult one. In general, the uppercase, suffix part like "_PROGRAMS" is called primary and tells partially what to perform on the argument; the lowecase, prefix (it's not given a name) tells the directory where to install.
bin_PROGRAMSinstalls binaries in $(PREFIX)/bin , and
sbin_PROGRAMSinstalls in $(PREFIX)/sbin . More primaries will appear in the following, and here is a complete list of primaries. Not all can be prefixed to such primaries (see later for how to work around this problem).
$ vim man/Makefile.aminsert the following in it:
man_MANS = firstman.1 secondman.8 thirdman.3 [...]yes, automake will deduce by itself what's needed for installing from this. Now edit for scripts:
$ vim scripts/Makefile.aminsert:
bin_SCRIPTS = script1.sh script2.sh [...]The primary "SCRIPTS" instruct makefiles to just install the arguments, without compiling of course.
$ vim doc/Makefile.am
docdir = $(datadir)/doc/@PACKAGE@ doc_DATA = README DONTSif "abc" is wanted for prefix, "abcdir" is to be specified. E.g. the code above expands to /usr/local/share/doc/pippo ("@PACKAGE@" will be expanded by autoconf when producing the final Makefile, see below). $(datadir) is known by all configure scripts it generates. You may look for the list of directory variables.
$ vim examples/Makefile.am
exampledir = $(datarootdir)/doc/@PACKAGE@ example_DATA = sample1.dat sample2.dat [...]All these Makefile.am files now exist, but autoconf has now to be told about them.
$ vim configure.acright after AC_INIT(), let initialize automake:
AM_INIT_AUTOMAKE(pippo, 2.6)then, let autoconf generate a configure script that will output Makefiles for all of the above directories:
AC_OUTPUT(Makefile src/Makefile doc/Makefile examples/Makefile man/Makefile scripts/Makefile)
$ aclocalThis generates a file aclocal.m4 that contains macros for automake things, e.g. AM_INIT_AUTOMAKE.
$ automake --add-missingAutomake now reads configure.ac and the top-level Makefile.am, interprets them (e.g. see further work has to be done in some subdirectories) and, for each Makefile.am produces a Makefile.in. The argument --add-missing tells automake to provide default scripts for reporting errors, installing etc, so it can be omitted in the next runs.
$ autoconfThis produces the final, full-featured configure shell script.
$ ./configureThe shell script just generated will:
$ makeThe target all from the main Makefile will be worked. This target expands into all the hidden targets to first build what you requested. Then, by mean of
# make installeverything is installed.