Difference between revisions of "Releasing units without source code"

From Free Pascal wiki
Jump to navigationJump to search
(Page creation)
 
(Made the explanation about the checksum of the System unit more precise)
Line 13: Line 13:
 
'''Notes'''
 
'''Notes'''
 
* The '''Target OS''' of the provided unit should match the target OS used for compiling the using program.
 
* The '''Target OS''' of the provided unit should match the target OS used for compiling the using program.
* The '''System unit''' of the provided unit should be ''compatible'' with the System unit used for compiling the using program.  That is, the compiler versions for compiling the provided unit and the using program should be ''compatible''. (The compiler checks for compatibility by comparing the checksum of the System unit embedded in the '''*.ppu''' file with that of the current System unit.  If the checksums differ, the compiler will attempt to recompile the provided unit, and will fail because the source is missing.  With the compiler option '''-vu''' you get more information on the handling of unit files, and you can spot a line stating ''Recompiling ..., checksum changed for System''.)
+
* The '''System unit''' of the provided unit should be ''compatible'' with the System unit used for compiling the using program.  That is, the compiler versions for compiling the provided unit and the using program should be ''compatible''. The compiler checks for compatibility by comparing the checksum of the '''interface section''' of the System unit used for compiling the provided unit (this checksum is embedded in the '''*.ppu''' file) with that of the current System unit.  If the checksums differ, then the compiler will attempt to recompile the provided unit, and will fail because the source is missing.  With the compiler option '''-vu''' you get more information on the handling of unit files, and you can spot a line stating ''Recompiling ..., checksum changed for System''.
 
* There may be some other compiler options to worry about:
 
* There may be some other compiler options to worry about:
 
** '''-M''' (''Mode'')
 
** '''-M''' (''Mode'')

Revision as of 22:10, 6 April 2006

It can be useful to release a FreePascal unit without publishing its source code:

  • The source code contains proprietary information.
  • In teaching, because you want to force students to use a unit by its interface (contract) only, and not by looking at its implementation.

FreePascal allows you to do so in the following way.

The provider of the unit (and owner of its source code) should:

  • Compile the unit separately; it is recommended to use the compiler option -Ur (Generate release unit files; see User's Manual for details).
  • Publish both the resulting *.ppu and *.o files. Also see Section 3.3 of the User's Manual (Compiling a unit).

The user of the provided unit should:

  • Compile the using program (the client), such that the compiler can find both the *.ppu and *.o files of the unit (e.g. through the compiler option -Fu).

Notes

  • The Target OS of the provided unit should match the target OS used for compiling the using program.
  • The System unit of the provided unit should be compatible with the System unit used for compiling the using program. That is, the compiler versions for compiling the provided unit and the using program should be compatible. The compiler checks for compatibility by comparing the checksum of the interface section of the System unit used for compiling the provided unit (this checksum is embedded in the *.ppu file) with that of the current System unit. If the checksums differ, then the compiler will attempt to recompile the provided unit, and will fail because the source is missing. With the compiler option -vu you get more information on the handling of unit files, and you can spot a line stating Recompiling ..., checksum changed for System.
  • There may be some other compiler options to worry about:
    • -M (Mode)
    • -C (Checking), such as -Cr (range checking), -Ci (i/o checking), -Co (overflow checking), -Ct (stack checking)
    • -O (Optimization)
    • -gl (Generating lineinfo code)
  • For older versions of the FreePascal compiler, the name of the provided unit's source file should be in all lower case letters. For recent version of the compiler, this is no longer an issue. (The User's Manual is not up to date, I believe.)