GNU Build System

From Schmid.wiki
Jump to: navigation, search
This page is about the GNU Build System

A developer can use these tools to create scripts and makefiles that enables end-users to compile and install software on an arbitrary POSIX system.

Contents

Components

  • autoconf
  • automake
  • libtool

HOWTO Create Install Package

This HOWTO describes in detail how to create a *NIX install package, from sources to tarball, using the GNU Build System (automake/autoconf). It is based on a running example, the fictional package of ultrapacman.

Structure

Create a new directory for the package

mkdir packagename-version

where version is major.minor[.revision[.build]], e.g.:

mkdir ultrapacman-0.1.1

Create directories in the new directory, e.g.:

cd ultrapacman-0.1.1/
mkdir doc man src

Copy source code to src/ and documentation to doc/.

Makefile.am

Create Makefile.am:

AUTOMAKE_OPTIONS=foreign
SUBDIRS=src man doc

Create src/Makefile.am, e.g.:

bin_PROGRAMS=ultrapacman
ultrapacman_SOURCES=main.cpp header.h

Create man/Makefile.am, e.g.:

man_MANS=ultrapacman.1
man_aux=$(man_MANS:.1=.x)

Create doc/Makefile.am, e.g.:

docdir=$(datadir)/doc/@PACKAGE@
doc_DATA=README TODO

configure.ac

Run autoscan to create a configure.ac stub file:

touch configure.ac
autoscan 
mv configure.scan configure.ac
rm autoscan*.log

Edit configure.ac and change these lines:

AC_INIT(packagename, version, BUG-REPORT-ADDRESS)
AM_INIT_AUTOMAKE(packagename, version)                  <- add this

e.g.

AC_INIT(ultrapacman, 0.1.1, someone@somewhere.org)
AM_INIT_AUTOMAKE( ultrapacman, 0.1.1 )                  <- add this

autogen.sh

Create auto build script autogen.sh:

aclocal
autoheader
automake -a
autoconf

And make it executable:

chmod 755 autogen.sh

Documentation

Create INSTALL file, e.g.:

Install with:
    ./autogen.sh
    ./configure
    make
    make install

Create README file, e.g.:

See INSTALL for install instructions

Create manual man/programname.1, e.g.:

.TH ULTRAPACMAN 1 "Version 0.1.1: 2006-05-26"
.SH NAME
ultrapacman \- a pacman clone
.SH SYNOPSIS
ultrapacman
.SH DESCRIPTION
.B ultrapacman
is a game.
.SH USAGE
It is used for playing.
.SH COPYRIGHT
Copyright \(co 2006 Svend Skimmel.
.SH SEE ALSO
xmame(6)

Make any missing documentation files in doc/, e.g.:

touch doc/{README,TODO}

External Libraries

Should your code use external libraries, add them to configure.ac before AC_CONFIG_FILES, e.g.:

# Checks for libraries.
PKG_CHECK_MODULES(DEPS, libpng >= 1.2)
AC_SUBST(DEPS_CFLAGS)
AC_SUBST(DEPS_LIBS)

Add these lines to src/Makefile.am:

INCLUDES=$(DEPS_CFLAGS)
LIBS=$(DEPS_LIBS)

Create Tarball

e.g.:

cd ..
tar -cjvf ultrapacman-0.1.1.tbz2 ultrapacman

References

Personal tools