Difference between revisions of "Autotools"

From HCL
Jump to: navigation, search
 
(17 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
http://en.wikipedia.org/wiki/Autoconf
 
http://en.wikipedia.org/wiki/Autoconf
  
http://sources.redhat.com/autobook/autobook/autobook.html
+
http://sourceware.org/autobook/autobook/autobook_toc.html
  
 
== Manuals ==
 
== Manuals ==
Line 7: Line 7:
 
* http://www.gnu.org/software/automake/manual/index.html
 
* http://www.gnu.org/software/automake/manual/index.html
 
* http://www.gnu.org/software/libtool/manual/index.html
 
* http://www.gnu.org/software/libtool/manual/index.html
 +
 +
== Tutorials ==
 +
* http://www.lrde.epita.fr/~adl/autotools.html (very nice set of slides)
  
 
== Libraries ==
 
== Libraries ==
Line 12: Line 15:
 
* library: static <code>lib_LIBRARIES = library.a</code> or dynamic <code>lib_LTLIBRARIES = library.la</code>
 
* library: static <code>lib_LIBRARIES = library.a</code> or dynamic <code>lib_LTLIBRARIES = library.la</code>
 
* sources (internal C data structures and C++ template classes): <code>library_X_SOURCES = library.h ...</code>, where <code>X</code> = <code>a</code> or <code>la</code>
 
* sources (internal C data structures and C++ template classes): <code>library_X_SOURCES = library.h ...</code>, where <code>X</code> = <code>a</code> or <code>la</code>
** <code>library.h</code> is a [http://en.wikipedia.org/wiki/Precompiled_header precompiled header] (contains common headers and symbols), which is to be included in most of source files of the library
 
  
For example, http://hcl.ucd.ie/repos/CPM/trunk/MPIBlib/benchmarks/Makefile.am
+
[http://gforge.ucd.ie/scm/viewvc.php/*checkout*/trunk/MPIBlib/benchmarks/Makefile.am?root=cpm Example]
  
 
== Configured headers ==
 
== Configured headers ==
 
Configured headers (created from *.h.in) must not be included into the package, that is <code>include_HEADERS</code> or <code>*_SOURCES</code>
 
Configured headers (created from *.h.in) must not be included into the package, that is <code>include_HEADERS</code> or <code>*_SOURCES</code>
 
* <code>nodist_include_HEADERS = *.h</code> for the configured headers as includes
 
* <code>nodist_include_HEADERS = *.h</code> for the configured headers as includes
* <code>nodist_*_SOURCES = *.h</code> for the configured headers as sources
+
* <code>nodist_*_SOURCES = *.h</code> or <code>BUILT_SOURCES = *.h</code> for the configured headers as sources
  
For example, http://hcl.ucd.ie/repos/CPM/trunk/MPIBlib/collectives/Makefile.am
+
[http://gforge.ucd.ie/scm/viewvc.php/*checkout*/trunk/MPIBlib/collectives/Makefile.am?root=cpm Example]
  
 
== Extra files ==
 
== Extra files ==
To add extra files into package, use <code>EXTRA_DIST = *</code>. For example, For example, http://hcl.ucd.ie/repos/CPM/trunk/MPIBlib/tools/Makefile.am
+
To add extra files into package, use <code>EXTRA_DIST = *</code>.
 +
 
 +
[http://gforge.ucd.ie/scm/viewvc.php/*checkout*/trunk/MPIBlib/tools/Makefile.am?root=cpm Example]
 +
 
 +
== Conditional building ==
 +
* http://www.gnu.org/software/hello/manual/automake/Conditionals.html
 +
* In the source code, use macros
 +
<source lang="C">
 +
#ifdef SYMBOL
 +
...
 +
#endif
 +
</source>
 +
 
 +
== MPI support ==
 +
* Define MPI compilers/linkers in configure.ac
 +
<source lang="text">
 +
AC_PROG_CC([mpicc])
 +
AC_PROG_CXX([mpic++ mpicxx])
 +
</source>
 +
 
 +
== C/C++ support ==
 +
* To check C++ features, switch to C++ language in configure.ac
 +
<source lang="text">
 +
AC_LANG_PUSH(C++)
 +
AC_CHECK_HEADER([header.hpp])
 +
AC_LANG_POP(C++)
 +
</source>
 +
* To link C code with C++ libraries, add a non-existent C++ file dummy.cpp to sources in Makefile.am
 +
<source lang="text">
 +
bin_PROGRAMS = program
 +
program_SOURCES = program.c
 +
nodist_EXTRA_program_SOURCES = dummy.cpp
 +
program_LDADD = cpplibrary.a
 +
</source>
 +
 
 +
== Script for downloading & installing recent versions (in March 2010) of m4, libtool, autoconf, automake==
 +
 
 +
#!/bin/bash
 +
parent_dir=$PWD
 +
export PATH=$HOME/$ARCH/bin:$PATH
 +
wget http://ftp.gnu.org/gnu/libtool/libtool-2.2.6b.tar.gz
 +
tar xzf libtool-2.2.6b.tar.gz
 +
cd libtool-2.2.6b
 +
./configure --prefix=$HOME/$ARCH
 +
make install
 +
cd $parent_dir
 +
wget http://ftp.gnu.org/gnu/m4/m4-1.4.14.tar.gz
 +
tar xfz m4-1.4.14.tar.gz
 +
cd m4-1.4.14
 +
./configure --prefix=$HOME/$ARCH
 +
make install
 +
cd $parent_dir
 +
wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.65.tar.bz2
 +
tar xjf autoconf-2.65.tar.bz2
 +
cd autoconf-2.65
 +
./configure --prefix=$HOME/$ARCH
 +
make install
 +
cd $parent_dir
 +
wget http://ftp.gnu.org/gnu/automake/automake-1.10.3.tar.bz2
 +
tar xjf automake-1.10.3.tar.bz2
 +
cd automake-1.10.3
 +
./configure --prefix=$HOME/$ARCH
 +
make install
 +
cd $parent_dir

Latest revision as of 10:01, 16 August 2012

http://en.wikipedia.org/wiki/Autoconf

http://sourceware.org/autobook/autobook/autobook_toc.html

Manuals

Tutorials

Libraries

  • includes (for the include directory): include_HEADERS = ...
  • library: static lib_LIBRARIES = library.a or dynamic lib_LTLIBRARIES = library.la
  • sources (internal C data structures and C++ template classes): library_X_SOURCES = library.h ..., where X = a or la

Example

Configured headers

Configured headers (created from *.h.in) must not be included into the package, that is include_HEADERS or *_SOURCES

  • nodist_include_HEADERS = *.h for the configured headers as includes
  • nodist_*_SOURCES = *.h or BUILT_SOURCES = *.h for the configured headers as sources

Example

Extra files

To add extra files into package, use EXTRA_DIST = *.

Example

Conditional building

#ifdef SYMBOL
...
#endif

MPI support

  • Define MPI compilers/linkers in configure.ac
AC_PROG_CC([mpicc])
AC_PROG_CXX([mpic++ mpicxx])

C/C++ support

  • To check C++ features, switch to C++ language in configure.ac
AC_LANG_PUSH(C++)
AC_CHECK_HEADER([header.hpp])
AC_LANG_POP(C++)
  • To link C code with C++ libraries, add a non-existent C++ file dummy.cpp to sources in Makefile.am
bin_PROGRAMS = program
program_SOURCES = program.c
nodist_EXTRA_program_SOURCES = dummy.cpp
program_LDADD = cpplibrary.a

Script for downloading & installing recent versions (in March 2010) of m4, libtool, autoconf, automake

#!/bin/bash
parent_dir=$PWD
export PATH=$HOME/$ARCH/bin:$PATH
wget http://ftp.gnu.org/gnu/libtool/libtool-2.2.6b.tar.gz
tar xzf libtool-2.2.6b.tar.gz
cd libtool-2.2.6b
./configure --prefix=$HOME/$ARCH
make install
cd $parent_dir
wget http://ftp.gnu.org/gnu/m4/m4-1.4.14.tar.gz
tar xfz m4-1.4.14.tar.gz
cd m4-1.4.14
./configure --prefix=$HOME/$ARCH
make install
cd $parent_dir
wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.65.tar.bz2
tar xjf autoconf-2.65.tar.bz2
cd autoconf-2.65
./configure --prefix=$HOME/$ARCH
make install
cd $parent_dir
wget http://ftp.gnu.org/gnu/automake/automake-1.10.3.tar.bz2
tar xjf automake-1.10.3.tar.bz2
cd automake-1.10.3
./configure --prefix=$HOME/$ARCH
make install
cd $parent_dir