Sections
Documentation
Patrice Koehl's research web site

Room 4319, Genome Center, GBSF
University of California Davis
451 East Health Sciences Drive
Davis, CA 95616

(530) 754 5121 phone
(530) 754 9658 fax

 
Personal tools

How to use autotools

How to use Gnu autotools

Form your Makefile to Autotools?


One of the many original Makefiles used for smesh, one of Xinwei's program:
#
NAME1=smesh
DIR=.
CPU=ifc
NAMEFUL1=$(DIR)/$(NAME1).$(CPU)
NAMEFUL2=$(DIR)/$(NAME2).$(CPU)
FC = ifort
FFLAGS = -c -u -p -g -mp1 -w90 -w95 -cpp
CC = icc
LD = icc
CFLAGS = -c -p -g -mp1 -Kc++ -Dintel
LDFLAGS = -p -g -Kc++ -mp1 -bind_at_load
LIBRARIES= -L/opt/intel/fc/9.1.029/lib/ -lgmp -lifcore -lm -limf -lirc

.c.o :
$(CC) $(CFLAGS) ___FCKpd___0lt;

.cpp.o :
$(CC) $(CFLAGS) ___FCKpd___0lt;


.f.o :
$(FC) $(FFLAGS) ___FCKpd___0lt;

OBJECTS1 = \
$(NAME1).o \
skinmesh.o mixcx.o triring.o basic.o\
delone.o add_vertex2C.o vertex_tet_star.o delete_vertexC.o locate2C.o alfcx.o delcx.o \
sos_minor_copy.o locate_copy.o\
regularC.o alf_gmp.o sos_minor_gmp.o reset_delaunayC.o\
adjust.o truncate_real.o tetra_center.o

$(NAMEFUL1) : $(OBJECTS1)
$(LD) -o $(NAMEFUL1) $(LDFLAGS) $(OBJECTS1) $(LIBRARIES)

all: $(OBJECTS1)
$(LD) -o $(NAMEFUL1) $(LDFLAGS) $(OBJECTS1) $(LIBRARIES)

clean:
rm -f *.o $(NAMEFUL2)

$(OBJECTS1) : defines.h delone.h basic.h tdclass.h triring.h mixcx.h skinmesh.h
This file only works for rapa and not on any other computer. Furthermore, if we change the intel compiler version this file will have to be modified again, here are the simple steps to help you with your Makefiles:
  • In your program directory create a directory name src (when creating a package, this will make sense when we will need to create packages)
  • move your source code in it
  • Move away every possible Makefile you have in the package
  • run autoscan
$ autoscan 
autom4te: configure.ac: no such file or directory
autoscan: /usr/bin/autom4te failed with exit status: 1
  • rename configure.scam (created by autoscan) to configure.ac
$ mv configure.scan configure.ac
  • create two files: Makefile.am and src/Makefile.am

    • Makefile.am
SUBDIRS=src
      • src/Makefile.am
# this lists the binaries to produce
#bin_PROGRAMS = targetbinary1 targetbinary2 [...] targetbinaryN
bin_PROGRAMS = smesh

#targetbinary1_SOURCES = targetbinary1.c myheader.h [...]
smesh_SOURCES = smesh.cpp skinmesh.cpp mixcx.cpp triring.cpp basic.cpp
delone.c add_vertex2C.f vertex_tet_star.f delete_vertexC.f locate2C.f
alfcx.f delcx.f so s_minor_copy.c locate_copy.f regularC.f convex_new.f
alf_gmp.c sos_minor_gmp.c reset_delaunayC.f adjust.f truncate_real.f
tetra_center.f
    • customize the configure.ac file

-*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)

 AC_INIT(smech, 1.0, BUG-REPORT-ADDRESS) AC_INIT(smech, 1.0, mymail@phonymail.com)

 AM_INIT_AUTOMAKE([foreign])
AC_CONFIG_SRCDIR([src/alf_gmp.c])
 # Checks for programs.  This part really neads to be customized if you intent to use diffrent compilers
 AC_PROG_INSTALL  
AC_PROG_CXX
 AC_PROG_CC


 # Checks for libraries.  This part really neads to be customized to check if the library you intend to use are here
 # Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([float.h stddef.h stdlib.h string.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_CONST
AC_C_INLINE
 AC_FUNC_OBSTACK
AC_TYPE_SIZE_T
# Checks for library functions.
AC_FUNC_ERROR_AT_LINE
AC_FUNC_MALLOC
AC_CHECK_FUNCS([floor modf sqrt])

 AC_CONFIG_FILES([src/Makefile])
AC_OUTPUT
 AC_CONFIG_FILES([Makefile src/Makefile])
AC_OUTPUT
    • If you don't need to specify the flags nore the compilers go directly here
    • Specifying default compilers (ther might be other way, but I don't know how that would be done)
#if a compiler is not specified by the user use intel compilers
AC_PATH_PROG(CC_PATH, $CC, NO_PATH)
if test "$CC_PATH" = NO_PATH; then
CC="icc"
fi

AC_PATH_PROG(FC_PATH, $F77, NO_PATH)
if test "$FC_PATH" = NO_PATH; then
F77="ifort"
fi

#check if compilers are present and specify which ones to use
AC_PROG_F77([$F77])
AC_PROG_CC([$CC])
AC_PROG_CXX([$CC])
    • Specifying the flags and the libraies.
There are several places where you can specify the flags, but here we will specify them in the configure.ac file, this will enable us to change the flags and the libraries according to the os.
# Check system type
case "$OSTYPE" in
#linux configuration
linux*)
case "${F77}" in
# Intel compiler
*ifort*)
LIBRARIES="-L"`echo $LD_LIBRARY_PATH | sed -e "s/:/ -L/"`
LDFLAGS="-C -Kc++ -mp1 $LDFLAGS $LIBRARIES"
FFLAGS="-c -u -C -mp1 -w90 -w95 -cpp $FFLAGS"
AC_CHECK_LIB(ifcore,main,,AC_MSG_ERROR(Cannot find lib ifcore $LIBS))
;;
*g77*)
LIBRARIES="-L"`locate libg2c.a | sed -e "s/libg2c.a//"`
LDFLAGS="-O $LDFLAGS $LIBRARIES"
FFLAGS="-c -u -O -x f77-cpp-input $FFLAGS"
AC_CHECK_LIB([g2c], [main],,AC_MSG_ERROR(Cannot find lib g2c in $LIBRARIES))
AC_CHECK_LIB(stdc++,main,,AC_MSG_ERROR(Cannot find lib stdc++))
AC_CHECK_LIB(gcc,main,,AC_MSG_ERROR(Cannot find lib gcc))
AC_CHECK_LIB(c,main,,AC_MSG_ERROR(Cannot find lib c))
;;
esac
case "${CC}" in
# Intel compiler
*icc*)
CPPFLAGS="-c -C -mp1 -Kc++ -Dintel $CPPFLAGS"
;;
*g++*)
CPPFLAGS="-c -Wall -O $CPPFLAGS"
;;
esac
;;
*)
AC_MSG_RESULT(Unrecognised OS $OSTYPE)
;;
esac

#common libraries
AC_CHECK_LIB(gmp,main,,AC_MSG_ERROR(Cannot find lib gmp ))
AC_CHECK_LIB(m, main,,AC_MSG_ERROR(Cannot find lib m ))


# substitutions
AC_SUBST(LDFLAGS)
AC_SUBST(CPPFLAGS)
AC_SUBST(FFLAGS)
  • run autoreconf --install (creates the missing files needed for the program)
$autoreconf --install
configure.ac: installing `./install-sh'
configure.ac: installing `./missing'
src/Makefile.am: installing `./depcomp'
  • run ./configure
    $ ./configure 
    checking for a BSD-compatible install... /usr/bin/install -c
    checking whether build environment is sane... yes
    checking for gawk... gawk
    ..
    config.status: creating Makefile
    config.status: creating src/Makefile
    config.status: creating config.h
    config.status: executing depfiles commands
  • or specify other compiler than ifort or icc
$ ./configure  F77=g77 CC=g++
  • run make:
$make
make all-recursive
make[1]: Entering directory `/home/renault/program/example_test_smesh'
Making all in src
....
icc -g -O2 -C -Kc++ -mp1 -L/opt/intel/fc/9.1.041/lib -L/opt/intel/cc/9.1.042/lib -o
smesh smesh.o skinmesh.o mixcx.o triring.o basic.o delone.o add_vertex2C.o vertex_tet_star.o
delete_vertexC.o locate2C.o alfcx.o delcx.o sos_minor_copy.o locate_copy.o regularC.o
convex_new.o alf_gmp.o sos_minor_gmp.o reset_delaunayC.o adjust.o truncate_real.o
tetra_center.o -lm -lgmp -lifcore
make[2]: Leaving directory `/home/renault/program/example_test_smesh/src'
make[2]: Entering directory `/home/renault/program/example_test_smesh'
make[2]: Nothing to be done for `all-am'.
make[2]: Leaving directory `/home/renault/program/example_test_smesh'
make[1]: Leaving directory `/home/renault/program/example_test_smesh'


run your program: you are done everything is working....