Neil Santos wrote:
Hi guys.
I've been scratching my head for about two hours now, trying to figure out what kind of incantation I need to do in order to compile a module whose interface and implementation sections reside in different files.
File `mod1.pas': module mod1 interface; export mod1 = (c, f); const c = 0; function f: integer; end .
File `mod1-imp.pas': module mod1 implementation; function f: integer; begin f := 1 end; end .
File `pp.pas': program pp; import mod1; begin writeln ('f = ', f) end .
I can compile it with:
gpc --automake pp.pas mod1-imp.pas
(that command recompiles all interfaces, also it may fail due to `automake' design bug).
I can also compile parts separately:
gpc --automake --interface-only mod1.pas gpc -c --implementation-only mod1-imp.pas gpc pp.pas mod1-imp.o
Note that with gpc-20030830 I got incomplete mod1-imp.o, but with gpc-20040516 that works OK.
The first way means full rebuild of implementations (that remove main motivation to keep interfaces separate).
AFAIKS there are two remaining problems: 1) There is no default way to find implementation so plain `--automake' (or `gp' (alias `cgp', alias `gpmake')) can not find them. IMHO we need to introduce a convention here. I propose to have `module.p' for interface and `module-imp.p' for implementation.
2) gpc writes to the GPI files compiling implementation. That is disastrous for using `make' (one can not have dependencies on `.gpi' files) and limits `--automake' utility. Ideally gpc should write implementation info to a separate file. As a workaround I added to my version `--disable-gpi-extension' option which just disables writing to GPI files after creation -- that is enough to enable use of `make'. In fact, recent improvements to `--automake' and that option enabled me first time to compile some sources with cyclic dependencies.