Node:Automake, Next:File Layout, Previous:GPI files, Up:Internals

### GPC's Automake Mechanism - How it Works

When a program/module/unit imports (uses) an interface, GPC searches for the GPI file (see GPI files) derived from the name of the interface.

Case 1: A GPI file was found.

Each GPI file contains the name of the primary source file (normally a `.pas` or `.p` file) of the module/unit, and the names of all interfaces imported. GPC reads this information and invokes itself with a command like

    gpc foo.pas -M -o foo.d

This means: preprocess the file, and write down the name of the object file and those of all its source files in `foo.d`. GPC reads `foo.d` and looks if the object file exists and if the source was modified since the creation of the object file and the gpi file. If so, GPC calls itself again to compile the primary source file. When everything is done, the `.d` file is removed. If there was no need to recompile, all interfaces imported by the module/unit are processed in the same way as this one.

Case 2: No GPI file was found.

In this case, GPC derives the name of the source file from that of the interface by trying first `interface.p`, then `interface.pas`. This will almost always work with UCSD/Borland Pascal units, but not always with Extended Pascal modules. The programmer can override this assumption using `uses ... in` or `import ... in`.

All this is done by the function `gpi_open()` which uses some auxiliary functions such as `module_must_be_recompiled()` and `compile_module()`.

Each time an object file is compiled or recognized as being up-to-date, its name is stored in a temporary file with the same base name as all the other temporary files used by GPC but the extension `.gpc`. When the top-level `gpc` is invoked (which calls `gpc1` later on), it passes the name of this temporary file as an additional command line parameter to `gpc1`. After compilation has been completed, the top-level `gpc` reads the temporary file and adds the new object files to the arguments passed to the linker.

The additional command `--amtmpfile` (not to be specified by the user!) is passed to child GPC processes, so all compiles use the same temporary file.

The source for this is merely in `module.c`, but there are also some hacks in `gpc.c`, additional command line options in `lang-options.h` and `options.c`, and `gpc.h` contains declarations for the functions and global variables.