You are on page 1of 3

Autoconf: ========= 1. Create configure.ac AC_INIT([program name], [0.01]) AC_OUTPUT AC_PREREQ([2.68]) AC_CONFIG_SRCDIR([hello.c]) AC_CONFIG_HEADERS([config.

h])

autoconf version >= 2.68 Safety. File must exist Put configuration results here, so we can easily "#include" them. make config header AC_CONFIG_AUX_DIR([build-aux]) Auxilary files go here (auto tools create lot of auxilary files). Keep src directory cleaner. AM_INIT_AUTOMAKE([1.11 -Wall -Werror]) Init automake AC_CONFIG_FILES([Makefile]) "configure" creates Makefile AC_PROG_CC Find and probe "C" compiler. AC_PROG_CXX Find and probe "C++" compiler AC_PROG_LEX Find flex/lex AC_PROG_YACC Find bison/yacc a. "GNU autoconf archive" has lot of predefined autoconf macros. b. Written in special language. Really a Bourne shell script processed by m4 macro processor, but usually use pre-created definitions. c. "#" is comment character. d. Bracket parameters with [] (integers don't need it). e. White space matters. White space before parameter OK(ignore outside []) No white space before macro invocation's "(" No white space after parameters (before "," or ")")

Automake: ========= 1. Need Makefile.am. Automake read this file. bin_PROGRAMS = hello hello_SOURCES = hello.c 2. bin_PROGRAMS hello --> Lists programs to be installed in "bin" directory. Identified by bindir variable in make --> List of targets

{WHERE}_{PRIMARY} = target --> Create taget types {PRIMARY} and put in {WHERE} {WHERE} Makefile ending in "dir" "bin" = $(bindir) for executables, defaults to $(prefix)/bin "lib" = $(libdir) for libraries, defaults to $prefix/lib "noinst" = not installed "check" = for "make check" {PRIMARY} Type of file PROGRAMS = excutable(binary) SCRIPTS = excutable scripts DATA = data 3. {TARGET}_{SOURCES} --> Sets target specfic info hello_SOURCES --> List of sourcefiles needed to generate target "hello" {TARGET}_SOURCES --> this target's source files {TARGET}_LDADD --> Extra objects for program. {TARGET}_CPPFLAGS --> This targets C preprocessor flags. hello_CPPFLAGS = -DDEBUG 2. AM_... variables. AM_CPPFALGS --> Default C preprocessor flags

AM_CFLAGS --> Default C compiler flags AM_CXXFALGS --> Default C++ compiler flags Do not set these and leave them be, so users can set them. PKG_CHECK_MODULES: -----------------1. "pkg-config" --> Easy way to use libraries. Ensure pkg-config is installed (Not all libraries use it) 2. In configure.ac add PKG_CHECK_MODULES([DEPS), [list-of-libs space seperated]) Library name may add ">= version number" Sets makefile DEPS_CFLAGS and DEPS_LIBS 3. In Makefile.am use those varaibles. AM_CFLAGS = $(DEPS_CFLAGS) AM_LIBS = $(DEPS_LIBS) Libtool: -------Automake for libraries 1. Intialize libtool: Add "LT_INIT" to configure.ac 2. Sample Makefile.am ACLOCAL_AMFLAGS = -I m4 --install lib_LTLIBRARIES = libwhine-1.0.la /* in lib install library */ libwhine_1_0_la_SOURCES = src/whine.c src/whine.h libwhine_1_0_la_LDFLAGS = -version-info 0:0:0 include_HEADERS = src/whine.h /* in include, install header */ bin_PROGRAMS = hello hello_SOURCES = src/hello.c hello_LDADD = $(lib_LTLIBRARIES) /* program uses library */ TODO: ----1. Write your program. 2. Run "autoreconf -i" a. Generates "configure" file and "autom4te.cache" directory. b. Need INSTALL, NEWS, README, AUTHORS, ChangeLog, COPYING files. Touch them. 3. Run "./configure" Creates config.status, config.log files 4. Run "make" Compile the files. 5. make install ---> Install the binary in /usr/local/bin (check with DESTDIR and "mktemp -d" Uninstall the binary. Make tarball. Make tarball and check installation.

make uninstall ---> make dist ---> make distcheck --->

Titbits: 1. Modern convention: use "m4" subdirectory for internal "m4" files (do not default to aclocal.m4) a. Make the m4 dierctory (rm aclocal.m4 && mkdir m4) b. Tell autoconf to use it, by adding in configure.ac AC_CONFIG_MACRO_DIR([m4]) c. Add in Makefile.am ACLOCAL_AMFALGS = -I m4 --install

d. But "autoreconf -i" fails (bug in autoconf version 1.68) To solve, create dummy file in m4 directory. touch m4/NOTES and add to SCM. Add EXTRA_DIST = m4/NOTES to Makefile.am to force redistribution. 2. Non-recursive make in subdirectories. a. Modify AM_INIT_AUTOMAKE in configure.ac to add option "subdir-objects"(so objects are placed in subdirs) AM_INIT_AUTOMAKE([1.11 subdir-objects -Wall -Werror]) b. Modidy AC_CONFIG_SRCDIR in configure.ac so that it says "src/hello.c" instead of "hello.c" c. Change Makefile.am to use new location. bin_PROGRAMS = hello hello_SOURCES = src/hello.c

You might also like