1.2. How to Recompile a Program

As you work on a program, you keep track of which units you modify and make sure you not only recompile these units, but also any units that depend on units you have modified.

The binder, gnatbind, will warn you if you forget one of these compilation steps, so it is never possible to generate an inconsistent program as a result of forgetting to do a compilation, but it can be annoying to keep track of the dependencies. One approach would be to use a the UNIX make program, but the trouble with make files is that the dependencies may change as you change the program, and you must make sure that the make file is kept up to date manually, an error-prone process.

The Ada make tool, gnatmake takes care of these details automatically. In the following example we recompile and rebuild the example program, which has been updated.

Example 1-5. Using gnatmake to Recompile

$ m1750-coff-gnatmake hello.adb
$ m1750-coff-gnatmake -v hello
GNATMAKE 1.7 Copyright 1995-2001 Free Software Foundation, Inc.
  "hello.ali" being checked ...
  -> "hello.adb" time stamp mismatch
m1750-coff-gcc -c hello.adb
End of compilation
m1750-coff-gnatbind -x hello.ali
m1750-coff-gnatlink hello.ali

The argument is the file containing the main program or alternatively the name of the main unit. gnatmake examines the environment, automatically recompiles any files that need recompiling, and binds and links the resulting set of object files, generating the executable file, hello. In a large program, it can be extremely helpful to use gnatmake, because working out by hand what needs to be recompiled can be difficult.

Note that gnatmake takes into account all the intricate rules in Ada 95 for determining dependencies. These include paying attention to inlining dependencies and generic instantiation dependencies. Unlike some other Ada make tools, gnatmake does not rely on the dependencies that were found by the compiler on a previous compilation, which may possibly be wrong due to source changes. It works out the exact set of dependencies from scratch each time it is run.

The linker is configured so that there are defaults for the start file and the library libgcc, libc and libada. Other libraries, such as the standard C math library libm.a, are not included by default, and must be mentioned on the linker's command line.