GNAT's Project facility provides a simple way of building and installing
stand-alone libraries; see Stand-alone Library Projects.
To be a Stand-alone Library Project, in addition to the two attributes
that make a project a Library Project (
Library_Dir; see Library Projects), the attribute
Library_Interface must be defined. For example:
for Library_Dir use "lib_dir"; for Library_Name use "dummy"; for Library_Interface use ("int1", "int1.child");
Library_Interface has a non-empty string list value,
each string in the list designating a unit contained in an immediate source
of the project file.
When a Stand-alone Library is built, first the binder is invoked to build
a package whose name depends on the library name
(b~dummy.ads/b in the example above).
This binder-generated package includes initialization and
finalization procedures whose
names depend on the library name (
in the example
above). The object corresponding to this package is included in the library.
You must ensure timely (e.g., prior to any use of interfaces in the SAL)
calling of these procedures if a static SAL is built, or if a shared SAL
with the project-level attribute
Library_Auto_Init set to
For a Stand-Alone Library, only the ALI files of the Interface Units
(those that are listed in attribute
Library_Interface) are copied to
the Library Directory. As a consequence, only the Interface Units may be
imported from Ada units outside of the library. If other units are imported,
the binding phase will fail.
Library_Src_Dir may be specified for a
Library_Src_Dir is a simple attribute that has a
single string value. Its value must be the path (absolute or relative to the
project directory) of an existing directory. This directory cannot be the
object directory or one of the source directories, but it can be the same as
the library directory. The sources of the Interface
Units of the library that are needed by an Ada client of the library will be
copied to the designated directory, called the Interface Copy directory.
These sources include the specs of the Interface Units, but they may also
include bodies and subunits, when pragmas
are used, or when there is a generic unit in the spec. Before the sources
are copied to the Interface Copy directory, an attempt is made to delete all
files in the Interface Copy directory.
Building stand-alone libraries by hand is somewhat tedious, but for those occasions when it is necessary here are the steps that you need to perform:
finalprocedures. For example:
gnatbind -n int1.ali int2.ali -Lsal1
gcc -c b~int2.adb
final) procedures for automatic initialization (and finalization). The built library should be placed in a directory different from the object directory.
ALIfiles of the interface to the library directory, add in this copy an indication that it is an interface to a SAL (i.e., add a word SL on the line in the ALI file that starts with letter “P”) and make the modified copy of the ALI file read-only.
Using SALs is not different from using other libraries (see Using a library).