Previous: Avoid Duplication With Variables, Up: Building With Projects
Sometimes an Ada software system is ported from one compilation environment to another (say GNAT), and the file are not named using the default GNAT conventions. Instead of changing all the file names, which for a variety of reasons might not be possible, you can define the relevant file naming scheme in the Naming package of your project file.
The naming scheme has two distinct goals for the project manager: it allows finding of source files when searching in the source directories, and given a source file name it makes it possible to guess the associated language, and thus the compiler to use.
Note that the use by the Ada compiler of pragmas Source_File_Name is not supported when using project files. You must use the features described in this paragraph. You can however specify other configuration pragmas (see Specifying Configuration Pragmas).
The following attributes can be defined in package Naming
:
"lowercase"
(the default if
unspecified), "uppercase"
or "mixedcase"
. It describes the
casing of file names with regards to the Ada unit name. Given an Ada unit
My_Unit, the file name will respectively be my_unit.adb (lowercase),
MY_UNIT.ADB (uppercase) or My_Unit.adb (mixedcase).
On Windows, file names are case insensitive, so this attribute is
irrelevant.
"-"
so that a unit
Parent.Child
is expected to be found in the file
parent-child.adb. The replacement string must satisfy the following
requirements to avoid ambiguities in the naming scheme:
'.'
except if the entire string
is "."
Spec_Suffix ("Ada")
is not specified, then the default is
"^.ads^.ADS^"
.
The value must satisfy the following requirements:
These attributes must satisfy the same requirements as Spec_Suffix
.
In addition, they must be different from any of the values in
Spec_Suffix
.
If Body_Suffix ("Ada")
is not specified, then the default is
"^.adb^.ADB^"
.
If Body_Suffix ("Ada")
and Spec_Suffix ("Ada")
end with the
same string, then a file name that ends with the longest of these two
suffixes will be a body if the longest suffix is Body_Suffix ("Ada")
or a spec if the longest suffix is Spec_Suffix ("Ada")
.
If the suffix does not start with a '.', a file with a name exactly equal
to the suffix will also be part of the project (for instance if you define
the suffix as Makefile
, a file called Makefile will be part
of the project. This capability is usually not interesting when building.
However, it might become useful when a project is also used to
find the list of source files in an editor, like the GNAT Programming System
(GPS).
Body_Suffix ("Ada")
. The same rules apply as for the
Body_Suffix
attribute. The only accepted index is "Ada".
Spec
can be used to define the source file name for a
given Ada compilation unit's spec. The index is the literal name of the Ada
unit (case insensitive). The value is the literal base name of the file that
contains this unit's spec (case sensitive or insensitive depending on the
operating system). This attribute allows the definition of exceptions to the
general naming scheme, in case some files do not follow the usual
convention.
When a source file contains several units, the relative position of the unit can be indicated. The first unit in the file is at position 1
for Spec ("MyPack.MyChild") use "mypack.mychild.spec"; for Spec ("top") use "foo.a" at 1; for Spec ("foo") use "foo.a" at 2;
For example, the following package models the Apex file naming rules:
package Naming is for Casing use "lowercase"; for Dot_Replacement use "."; for Spec_Suffix ("Ada") use ".1.ada"; for Body_Suffix ("Ada") use ".2.ada"; end Naming;