Using Automake and Autoconf


Automake and autoconf tools enable the developer to get rid of the tedium of writing complicated Makefiles for large projects and also avail portability across various platforms. These tools have been specifically designed for managing GNU projects. Software developed using automake and autoconf needs to adhere to the GNU software engineering principles.

Project directory structure


The project directory is recommeded to have the following subdirectories
and files.

src : Contains the actual source code that gets compiled. Every library shud have it’s over subdirectory. Every executable shud have it’s own subdirectory as well. If the each executable needs only one or two source files it’s sensible to keep all the source files in the same directory.

lib : An optional directory in which you place portablity code like implementations of system calls that are not avaliable of certian platforms.

• doc : Directory containing documentation for your package.

m4 : A directory containing ‘m4’ files that you package may need to install. These files define new ‘autoconf’ macros that you should make available to other developers who want to use your libraries.

intl : Portability source code which allows your program to talk in various languages.

po: Directory containing message catalogs for your software package. Automake makes it really easy to manage multi-directory source code packages so you shudn’t be shy taking advantage of it.



Enabling Portablity


Inorder to make your C/C++ project protable across different platforms you need to add the following lines of code to all of the source files before any include statements

 #ifdef 
HAVE_CONFIG_H
#include <config.h>
#endif

The config.h file is generated by the tools (or the configure script not quite sure!!) and the HAVE CONFIG H flag is passed along with the -D option of the compiler by the generated scripts at the time of building the project. Use the autoheader utility to generate the config.h file for the project.



Configuration files in brief

There are two main configuration files used by these tools.

• configure.ac : Used by the autoconf tool to generate plaform specific configure script.

• Makefile.am : Used by the automake tool to generate the Makefile for the sources present in the directory containing the Makefile.am file.

NOTE : There exists a single configure.ac for a project however you need to
create a distinct Makefile.am for each sub directory in the project





No comments:

Post a Comment