GNU autoconf (automake) "Hello World" step-by-step example 

Joined:
04/07/2009
Posts:
178

September 25, 2012 19:33:02    Last update: October 31, 2014 12:34:25
This a step-by-step example of how to create the files for GNU automake.
  1. Put the C source file in directory src (cat src/hello.c):
    #include <config.h>
    #include <stdio.h>
              
    int  main (void) {
                puts ("Hello World!");
                puts ("This is " PACKAGE_STRING ".");
                return 0;
    }
    

  2. Run autoscan to generate configure.scan.
  3. Rename configure.scan:
    mv configure.scan configure.ac
    

  4. Edit configure.ac. Update this line:
    AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
    

  5. Add this line after AC_INIT:
    AM_INIT_AUTOMAKE([foreign -Wall -Werror])
    

  6. Add this line before AC_OUTPUT:
    AC_CONFIG_FILES([Makefile src/Makefile])
    

  7. Create file Makefile.am (cat Makefile.am):
    SUBDIRS = src
    

  8. Create file src/Makefile.am (cat src/Makefile.am):
    bin_PROGRAMS = hello
    hello_SOURCES = hello.c
    

  9. Run these commands:
    $ aclocal
    $ autoheader
    $ automake --add-missing
    $ autoconf
    

    The file configure is generated after autoconf is run.
  10. Build with:
    $ ./configure
    $ make
    

  11. Create tarball for distribution with:
    $ make dist
    

    or
    $ make distcheck
    



Update: to add a library, add this line to src/Makefile.am (using libcrypt as example):
hello_LDADD = -lcrypt
Share |
| Comment  | Tags