Types of Package
The compiler can build two types of package: a complete program or a library. The term 'package' will be used in discussions that apply to both programs and libraries.
A program is a complete, self-contained runnable package. A program can be compiled to run immediately or be saved as a file to be run later.
If you want to build a program for later use then you should use the "-prg" flag on the command line ( this can only be done with the professional version of the system ). If you want to run the program immediately you need to specify one of the image file options ( e.g. "-png" ) on the command line.
A library is a set of data and routines that can be included into any number of other programs to provide some commonly used functionality.
These allow third parties to supply function units without releasing the source code. They also prevent tampering. The free version does not allow libraries to be accessed.
If you want to build a library you need to specify the "-lib" flag on the command line. You will need the professional version of the system in order to build ( and use ) libraries.
Components of a Package
A package is built from two types of file :- source files ( with extension ".grs" ) and library files ( extension ".grl" ). A program build with the free version of the system can only have a single source file and no library files. A package ( program or library ) built with the professional version can have any number of each ( within some system limit ).
Primary Source File
The primary source file in the one vital component of a package. For a library it will contain the list of secondary source files and the list of dependent libraries. The primary source for a program will also contain the program's entry point - a special routine called Program.
Subsidiary Source Files
A subsidiary source file is used to store general program elements. Any subsidiary source file must be listed in the main program module using the Source statement.
All the subsidiary source files must be listed in the primary source file with a Source statement of the following form :-
sourcespec ::= Source sourcefile ;
The sourcefile is the name of a source file written with single quotes. The path will be relative to the primary source file.
Source statement can be placed anywhere in the file outside routines and after all the Library statements. The code will be ordered as if all the code had been placed at that location - although the used of the Private scope will limit visibility. This will affect the ways global public variable interact ( this can get complicate and will be discussed elsewhere ).
All libraries accessed must be listed in the primary source file, before any other code, using the Library statement :-
libspec ::= Library libident = sourcefile ;
The libident is an identifier used to resolve ambiguities between items in libraries and other libraries or the main package.
The sourcefile is the name of a library file written with single quotes. The path will be relative to the primary source file - although you would normally use an absolute path.
Here is an example :-
Library TestLib2A = 'MYPROJ:/LibTest1/libtest2a.grl';