GNU Autotools will be considered as the ideal tool to manage Fortran project after creating a basic program structure by using Eclipse IDE. Eclipse IDE is quite convenient for developing a simple project, however, only one target binary can be generated, i.e. a single binary executable or library. Therefore, it is still not good enough to manage a large or a collaborated project in which a couple of binaries should be generated with various types, such as executable binaries, static or shared libraries and test programs. One more comment should be added here: for a collaborated project, each team member has his own scope of module to be implemented and modules contributed from different members should cooperate seamlessly. This usually requires each member write his own test code to ensure quality and validity of the program. Therefore, there must be at least a couple of executable binaries in a collaborated project, which can’t be directly handled by Eclipse IDE. This is what GNU Autotools aim for.
GNU Autotools comprise two parts: Autoconf and Automake. Autoconf is used to create automation scripts for performing system tests (such as dependencies on some header files, libraries, etc.) and configurations which are adapted to different system architectures. Hence, the source code can be made cross-platform. Automake is useful for transforming a user maintained file Makefile.am into Makefile.in by conforming to GNU Make standard. Makefile plays the core role to record source code file dependencies and to determine the execution process of compiler and linker. In the following, only the concept of dependency tree is described, which provides you with most of the underlying ideas about what GNU Make is for.
If we want to compile a program executing some mathematical calculations, we create a file named main.f90, which contains the source code of main program. Let’s assume that main.f90 depends on two modules: MathFunc and Defs. MathFunc is defined and implemented in MathFunc.f90 and it contains user defined mathematical functions and constants. Defs is defined and implemented in Defs.f90 and it contains some special ID numbers for the standard I/O and other files. Furthermore, module MathFunc depends on Defs because some constants defined in Defs may be used. With these relations, a dependency tree can be generated as in Figure 1. We can see that a Fortran source file is compiled into an object file (*.o) and object files are linked into a binary file main.exe. If a module is defined in a source file, a *.mod file will also be generated. This *.mod file contains information about function, subroutine and variable declarations, which is equivalent to header file in C or C++ with the difference that it is automatically generated by Fortran compiler.
After the dependency relation is clear, GNU Make takes over the responsibility to ensure that if any node in the dependency tree has some changes, then this node and all of its parent nodes will be recompiled and the generated object files will be relinked into the final binary target. During this procedure, file timestamp is used to determine if there is any file changes and it is obvious to see that only requisite compiling is performed by GNU Make, which will greatly reduce the compiling time when the project gradually becomes larger.
With the above short introductions, we’ve got a basic concept of program development by using GNU tool chains. And this lays out a foundation for possible detailed learning of Autoconf and Automake in the future.
Figure 1 Dependency tree
Basics on GNU autotools developing environment,布布扣,bubuko.com