Using the autotools on a C++ project

November 2011


  1. Place the source

    Create a dir src and put the entire source tree in it.

  2. Create configure.ac

    Create configure.ac (or generate it with autoscan && mv configure.scan configure.ac and then hand-edit:

    #                                               -*- Autoconf -*-                                                                                                                    
    # Process this file with autoconf to produce a configure script.                                                                                                                    
                                                                                                                                                                        
    AC_PREREQ([2.68])                                                                                                                                                                   
    AC_INIT([mainfix], [0.00.00], [j.bokma@rug.nl])                                                                                                                                     
    AM_INIT_AUTOMAKE([1.10 -Wall no-define foreign])                                                                                                                                    
    AC_CONFIG_SRCDIR([src/main.cc])                                                                                                                                                     
    AC_CONFIG_HEADERS([config.h])
    
    # Checks for programs.
    AC_PROG_CXX
    AC_PROG_CC
    
    # Checks for libraries.
    
    # Checks for header files.
    
    # Checks for typedefs, structures, and compiler characteristics.
    AC_HEADER_STDBOOL
    AC_C_INLINE
    AC_TYPE_SIZE_T
    
    # Checks for library functions.
    
    AC_CONFIG_FILES([Makefile])
    AC_OUTPUT
    	  

  3. Create Makefile.am

    Create Makefile.am by hand:

    AUTOMAKE_OPTIONS = subdir-objects
    ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS}
    
    bin_PROGRAMS = mainfix
    mainfix_SOURCES = src/main.cc \
    src/angle/add.cc \
    src/angle/set2.cc \
    <snip>
    	  

    [Note]Note

    The longish file list can be generated with:

    find ./ -iname \*.cc -printf '%P \\ \n'

  4. Create autogen.sh

    Create autogen.sh:

    ! /bin/sh
    
    aclocal \
    && automake --add-missing \
    && autoconf
    	  

  5. Go ahead and build

    apprentice@progbox:~/dev/c++/myproj/$ autoreconf
    apprentice@progbox:~/dev/c++/myproj/$ automake --add-missing
    apprentice@progbox:~/dev/c++/myproj/$ autoreconf
    apprentice@progbox:~/dev/c++/myproj/$ ./configure
    apprentice@progbox:~/dev/c++/myproj/$ make