Following is autotools buildsystem example/introduction that can be used to create build system that:
- creates libraries
- creates binaries
- creates tests
- executes tests
It is intended for C/C++ project.
Following directory structure used:
project/ +-- reconfig.sh
+-- configure.ac
+-- Makefile.am
+-- src +
tests+
lib/libname/
project/reconfig.sh :
#!/bin/sh
# after editing configure.ac and|or Makefile.am
aclocal
autoheader
autoconf
automake -a
./configure
project/Automake.am :
SUBDIRS = lib/libname src tests
project_pre = 1.0
project/configure.ac :
AC_PREREQ(2.59)
AC_INIT(src/project.h)
AM_INIT_AUTOMAKE(project,1.0)
AC_CONFIG_HEADER([config.h])
# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
# Checks for libraries.
AC_PROG_RANLIB
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
# Checks for library functions.
AC_HEADER_STDC
AC_CHECK_FUNCS([memset])
AC_OUTPUT([Makefile src/Makefile
lib/libname/Makefile
tests/Makefile])
project/src/Makefile.am
bin_PROGRAMS = project
clones_SOURCES = main.cpp
clones_LDADD = ../lib/libname/libname.a
#clones_LIBADD = ../lib/libname/libname.a
AM_CPPFLAGS = -I$(top_srcdir)/lib/libname/ -I$(top_builddir)/lib/libname/
project/src/libname/Makefile.am:
noinst_LIBRARIES = libname.a
libname_a_SOURCES = libname.c
project/tests/Makefile.am:
bin_PROGRAMS = libname_test test_test
libname_test_SOURCES = libname_test.c
test_test_SOURCES = test_test.c
critbit_test_LDADD = ../lib/libname/libname.a
check_PROGRAMS = libname_test test_test
TESTS = $(check_PROGRAMS)
AM_CPPFLAGS = -I$(top_srcdir)/lib/libname/ -I$(top_builddir)/lib/libname/
To try this example:
- create directory structure;
- create .sh , .in and .ac files described above
- Create .c files with names defined in .am files above in corresponding dirs.
reconfig.sh should create makefiles that could be used.
make - creates binaries
make check - performs tests
another introduction could be found there:
http://www.gnu.org/software/automake/manual/html_node/Creating-amhello.html#Creating-amhello
No comments:
Post a Comment