If you are programming C/C++ on Linux, it is good to maintain codes with autoconf / automake, because 1) it is easier for you to maintain Makefile & sources & docs 2) others feel comfortable to understand how to build your code 3) it is convenient to distribute source package in this form
Many people think it is not easy to dive into the world of autotools, so here I introduce a simple example.
The example assumes the case where src/ has the source codes.
Create configure.ac
# give any path to the source for sanity check
AC_INIT(src/counter.c)
# For automake
AM_INIT_AUTOMAKE(PROJECT_NAME, VERSION)
AM_CONFIG_HEADER(config.h)
# check for programs (just use that is necessary)
AC_PROG_CC # check for gcc
AC_PROG_CXX # check for g++
AC_PROG_INSTALL # check for install
# check header files
AC_HEADER_STDC
# Output of configure. Usually location of the Makefile to be placed
AC_OUTPUT(Makefile \
src/Makefile )
Create Makefile.am
# file: Makefile
SUBDIRS=src #list of subdirectories (delimiter is space)
# file: src/Makefile
bin_PROGRAMS=prog1 # list of executable to produce (make will create these binaries)
prog1_SOURCES=sourceA.c # list of sources/headers that builds binaryA. This line should be added per bin in $bin_PROGRAMS
prog1_LDADD=-llib1 -llib2 … # (optional) list of libraries for linking prog1
prog1_LDFLAGS= -L/path/to/lib # (optional) linker parameters
# below is global properties
INCLUDES=-I/path/to/include -I/path/to/include2 …
LDADD=-lz -lpthread … # list of libraries
Run autotools
Execute below commands
aclocal
autoheader
autoconf
touch NEWS README AUTHORS ChangeLog
automake -a -c
autoconf creates configure from configure.ac, and automake creates Makefile.in from Makefile.am.
Compile
Now you can follow traditional compiling steps
./configure
make
By default it creates conventional rules in Makefile such as
make clean
make distclean
make install
Also configure has the default options to set the prefix, and other directories
./configure –help
configure creates Makefile from Makefile.in.
Maintaining the codes
Adding a source code
Modify the Makefile.am in the same directory where the new sources are placed. Then run automake
Adding a directory
Modify configure.ac (AC_OUTPUT), and add Makefile.am to the new directory. Then run autoconf, and automake
References
For more detail: