Autotools examples explained

From Colettapedia
Jump to navigation Jump to search

Fixing Autotools problems

Hello world example: Required 5 files

  • configure.ac
  • Makefile.am
  • README
  • src/
    • Makefile.am
    • helloworld.c

src/helloworld.c

    #include <config.h>  
    #include <stdio.h>  
      
    int main (void) {  
        puts ("Hello World!");  
        puts ("This is " PACKAGE_STRING ".");  
        return 0;  
    }  

src/Makefile.am

  • Makefile.am files have the same syntax
  • Automake turns Makefile.am's into Makefile.in's
  • baseline file
    bin_PROGRAMS = helloworld  
    helloworld_SOURCES = helloworld.c  
  • additional flags
helloworld_LDADD = $(LIBOBJS)
info_TEXINFOS = helloworld.texi

uniform naming scheme

  • directory variables
    • bin_PROGRAMS is a concatenation of the ${bindir} and the primary token PROGRAMS
    • also applicable: sbin_PROGRAMS
    • also:
xmldir = $(datadir)/xml
xml_DATA = file.xml
  • list of primaries: ‘PROGRAMS’, ‘LIBRARIES’, ‘LTLIBRARIES’, ‘LISP’, ‘PYTHON’, ‘JAVA’, ‘SCRIPTS’, ‘DATA’, ‘HEADERS’, ‘MANS’, and ‘TEXINFOS’

Makefile.am

    SUBDIRS=src  
    dist_doc_DATA=README  

README

    This is a demonstration HelloWorld package for GNU Automake.  
    Type `info Automake' to read the Automake manual.  

config.ac

    AC_INIT([helloworld], [1.0], [emailid@provider.com])  
    AM_INIT_AUTOMAKE([-Wall -Werror foreign])  
    AC_PROG_CC  
    AC_CONFIG_HEADERS([config.h])  
    AC_CONFIG_FILES([  
     Makefile  
     src/Makefile  
    ])  
    AC_OUTPUT  
  • AC_INIT( [name of package], [version of package], [contact address for bug reports] )
  • AM_INIT_AUTOMAKE( [ compiler flags ] )
    • foreign means don't complaing that we don't have an authors or a changelog file
  • AC_PROG_CC
    • look for cc
  • AC_CONFIG_HEADERS( [name of config file that you #included in your source code] )
  • AC_CONFIG_FILES( [ newline delimited list of paths to all applicable Makefile.am's ] )
  • AC_OUTPUT - the closing command that produces all the rest of the code.

wndchrm's

configure.ac

AC_INIT(wndchrm,1.30)
AM_INIT_AUTOMAKE
AC_PROG_CC
AC_PROG_RANLIB

# set the default c++ flags
# Need to make the default CXXFLAGS be blank instead of -g -O2.  Use these in AM_CXXFLAGS instead
if test x"${CXXFLAGS+set}" = xset; then 
  # the user set CXXFLAGS; don't override it.
  # Much more clever would be to issue a warning if users' CXXFLAGS have optimization higher than 0
  # Cleverer still would be to figure out which versions of g++ barf when compiling FeatureNames.cpp with optimization.
	MY_CXXFLAGS="${CXXFLAGS}"
else 
	MY_CXXFLAGS=""
fi 
# This sets the default CXXFLAGS (user/environment/or built-in default)
AC_PROG_CXX
# And here we overwrite it based on our test above
CXXFLAGS=$MY_CXXFLAGS
# Put the usual defualt into AM_CXXFLAGS
AM_CXXFLAGS="-Wall -g -O2"

SVNREV=`( svnversion $srcdir | sed 's/:/_/' ) 2>/dev/null`
if { ! ( svnversion ) >/dev/null 2>&1 || test "$SVNREV" = "exported"; } ;
	then SVNREV=`cat $srcdir/SVNREV`
	else echo $SVNREV>$srcdir/SVNREV
fi
AC_SUBST(SVNREV)

AC_DEFINE_UNQUOTED([SVNREV],["$SVNREV"], [SVN Revision from svnversion command])
AC_DEFINE_UNQUOTED([PACKAGE_VERSION],["$VERSION-$SVNREV"], [Version string, including SVNREV])
AC_DEFINE_UNQUOTED([PACKAGE_STRING],["$PACKAGE_NAME $VERSION-$SVNREV"], [Package string with version+SVNREV])


AM_CONFIG_HEADER(config.h)

AC_CHECK_HEADER(math.h, [],
        AC_MSG_ERROR([the <math.h> header file could not be found.]))

# ------------------------------------------------------------
# check for FFTW3
# ------------------------------------------------------------
AC_CHECK_LIB(fftw3,fftw_execute,[AC_DEFINE(HAVE_FFTW3,1,"Turn on FFTW3 support.")],
	[AC_MSG_ERROR([
    FFTW3 library not found.
    Please download+install FFTW 3.x from http://www.fftw.org/download.html
])]
)
AC_CHECK_HEADER(fftw3.h, [],
        AC_MSG_ERROR([
    the <fftw3.h> header file from FFTW3 could not be found.
    Please download+install FFTW 3.x from http://www.fftw.org/download.html
]))


# ------------------------------------------------------------
# check for libtiff
# ------------------------------------------------------------
AC_CHECK_LIB(tiff, TIFFReadScanline)
AC_CHECK_HEADER(tiffio.h,LIBTIFF='yes',AC_MSG_ERROR([
    *** WND_CHARM requires libtiff; (Required TIFF headers not found) ***
    Please download+install libtiff from http://www.libtiff.org/
]))


# ------------------------------------------------------------
# check for TR1 stuff individually
# ------------------------------------------------------------
# AC_HEADER_TR1_UNORDERED_MAP
AC_DEFUN([AC_HEADER_TR1_UNORDERED_MAP], [
  AC_CACHE_CHECK(for tr1/unordered_map,
  ac_cv_cxx_tr1_unordered_map,
  [AC_LANG_SAVE
  AC_LANG_CPLUSPLUS
  AC_TRY_COMPILE([#include <tr1/unordered_map>], [using std::tr1::unordered_map;],
  ac_cv_cxx_tr1_unordered_map=yes, ac_cv_cxx_tr1_unordered_map=no)
  AC_LANG_RESTORE
  ])
  if test "$ac_cv_cxx_tr1_unordered_map" = yes; then
    AC_DEFINE(HAVE_TR1_UNORDERED_MAP,,[Define if tr1/unordered_map is present. ])
  fi
])
AC_HEADER_TR1_UNORDERED_MAP
# AC_HEADER_TR1_UNORDERED_SET
AC_DEFUN([AC_HEADER_TR1_UNORDERED_SET], [
  AC_CACHE_CHECK(for tr1/unordered_set,
  ac_cv_cxx_tr1_unordered_set,
  [AC_LANG_SAVE
  AC_LANG_CPLUSPLUS
  AC_TRY_COMPILE([#include <tr1/unordered_set>], [using std::tr1::unordered_set;],
  ac_cv_cxx_tr1_unordered_set=yes, ac_cv_cxx_tr1_unordered_set=no)
  AC_LANG_RESTORE
  ])
  if test "$ac_cv_cxx_tr1_unordered_set" = yes; then
    AC_DEFINE(HAVE_TR1_UNORDERED_SET,,[Define if tr1/unordered_set is present. ])
  fi
])
AC_HEADER_TR1_UNORDERED_SET

# Write out our compile flags
AC_SUBST(CXXFLAGS)
AC_SUBST(AM_CXXFLAGS)

AC_OUTPUT(Makefile)

Makefile.am

EXTRA_DIST = SVNREV
distdir = $(PACKAGE)-$(VERSION).$(SVNREV)

noinst_LIBRARIES = libimfit.a libFeatureNames.a

# This is set up as a separate target because g++ barfs compiling this with optimization.
# gcc 4.2.1 tries to allocate several gigs of RAM, and fails with an out-of-memory error
# Apparently fixed in 4.3 or 4.4, but have not checked.
libFeatureNames_a_SOURCES = \
	FeatureNames.cpp \
	FeatureNames.hpp

# Our special optimization flags, which over-ride AM_CXXFLAGS.
# Note that the user's CXXFLAGS always go at the end, which
# get set to "-g -O2" if they are not set, which blows up.
# I thought they were strictly for the user, so why are they set to a default?
# configure.ac has some checks to not stomp on the user's CXXFLAGS, but also
# not use the defaults provided by AC_PROG_CXX (which is where -g -O2 comes from).
# The default options -g -O2 are set in AM_CXXFLAGS, which is as it should be.
# The result is that it only blows up if the user has -O set in their CXXFLAGS.
libFeatureNames_a_CXXFLAGS = -Wall -g -O0

libimfit_a_SOURCES = \
	gsl/specfunc.cpp \
	gsl/specfunc.h \
	wndchrm_error.cpp \
	wndchrm_error.h \
	cmatrix.cpp \
	cmatrix.h \
	colors/FuzzyCalc.cpp \
	colors/FuzzyCalc.h \
	signatures.cpp \
	signatures.h \
	statistics/CombFirst4Moments.cpp \
	statistics/CombFirst4Moments.h \
	statistics/FeatureStatistics.cpp \
	statistics/FeatureStatistics.h \
	textures/gabor.cpp \
	textures/gabor.h \
	textures/haarlick/CVIPtexture.cpp \
	textures/haarlick/CVIPtexture.h \
	textures/haarlick/haarlick.cpp \
	textures/haarlick/haarlick.h \
	textures/haarlick/mapkit.cpp \
	textures/haarlick/mapkit.h \
	textures/haarlick/mapkit_generic.cpp \
	textures/haarlick/mapkit_generic.h \
	textures/tamura.cpp \
	textures/tamura.h \
	textures/zernike/zernike.cpp \
	textures/zernike/zernike.h \
	TrainingSet.cpp \
	TrainingSet.h \
	transforms/ChebishevFourier.cpp \
	transforms/ChebishevFourier.h \
	transforms/chevishev.cpp \
	transforms/chevishev.h \
	transforms/fft/bcb_fftw3/fftw3.h \
	transforms/fft/fftw3.h \
	transforms/radon.cpp \
	transforms/radon.h \
	transforms/wavelet/Common.cpp \
	transforms/wavelet/Common.h \
	transforms/wavelet/convolution.cpp \
	transforms/wavelet/convolution.h \
	transforms/wavelet/DataGrid.h \
	transforms/wavelet/DataGrid2D.cpp \
	transforms/wavelet/DataGrid2D.h \
    transforms/wavelet/DataGrid3D.cpp \
	transforms/wavelet/DataGrid3D.h \
	transforms/wavelet/Filter.cpp \
	transforms/wavelet/Filter.h \
	transforms/wavelet/FilterSet.cpp \
	transforms/wavelet/FilterSet.h \
	transforms/wavelet/Symlet5.cpp \
	transforms/wavelet/Symlet5.h \
	transforms/wavelet/Wavelet.cpp \
	transforms/wavelet/Wavelet.h \
	transforms/wavelet/WaveletHigh.cpp \
	transforms/wavelet/WaveletHigh.h \
	transforms/wavelet/WaveletLow.cpp \
	transforms/wavelet/WaveletLow.h \
	transforms/wavelet/WaveletMedium.cpp \
	transforms/wavelet/WaveletMedium.h \
	transforms/wavelet/wt.cpp \
	transforms/wavelet/wt.h

AM_CPPFLAGS = -fPIC

bin_PROGRAMS=wndchrm util/color_deconvolution

wndchrm_SOURCES = wndchrm.cpp

wndchrm_LDADD = libFeatureNames.a libimfit.a -lm -ltiff -L. -lFeatureNames -limfit -lfftw3

util_color_deconvolution_SOURCES = 	\
	util/readTiffData.c \
	util/readTIFF.h \
	util/color_deconvolution.c

util_color_deconvolution_LDADD = -lm -ltiff

aclocal

  • a part of automake that will be deprecated in the future