GNU autoconf (automake) "Hello World" step-by-step example
September 25, 2012 19:33:02 Last update: September 25, 2012 19:33:02
This a step-by-step example of how to create the files for GNU automake.
- 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; }
- Run
autoscanto generateconfigure.scan. - Rename
configure.scan:mv configure.scan configure.ac
- Edit
autoscan.ac. Update this line:AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
- Add this line after
AC_INIT:AM_INIT_AUTOMAKE([foreign -Wall -Werror])
- Add this line before
AC_OUTPUT:AC_CONFIG_FILES([Makefile src/Makefile])
- Create file
Makefile.am(cat Makefile.am):SUBDIRS = src
- Create file
src/Makefile.am(cat src/Makefile.am):bin_PROGRAMS = hello hello_SOURCES = hello.c
- Run these commands:
$ aclocal $ autoheader $ automake --add-missing $ autoconf
The fileconfigureis generated afterautoconfis run. - Build with:
$ ./configure $ make
- Create tarball for distribution with:
$ make dist
or$ make distcheck