This file documents a feature of GPC which makes it superfluos to use `make' (and to write a Makefile) in most cases.
(For those who know Borland Pascal: `bpc -m foo' ("make") is now `gpc --automake foo.pas.')
When you invoke GPC with the command line option --automake
, it
checks whether the Modules/Units your program uses must be
recompiled. If so, it recursively calls GPC -c
to compile them.
Furthermore, the names of user-written object files are
automatically passed to the linker. This means that you can
compile (and link) your program with a line like
gpc --automake foo.pas
even if foo
is a large project with a lot of Modules/Units and
include files. (Yes, when you have modified an include file, GPC
recognizes which Modules/Units must be recompiled!)
If you want to pass command line options to such second-level compiles, specify them with the --automake option:
gpc --automake="-g -O6 -D TERMCAP" foo.pas
Don't forget the quotes if the string contains blanks. When you omit this specification, top level command line options are not automatically passed through.
When a Program/Module/Unit imports (uses) an Interface, GPC searches for the GPI file (see GPI.DOC) 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 Borland
Pascal Units, almost never with Extended Pascal Modules. With
Extended Pascal, compile the Module once manually in order to
produce a GPI file.
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 gpc-module.c
, but there are
also some hacks in gcc.c
, additional command line options in
gpc-options.h
and gpc-decl.c
, and gpc-defs.h
is
adapted to support new functions and global variables.