Previous: Avoid Duplication With Variables, Up: Building With Projects


11.2.8 Naming Schemes

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:

Casing:
Its value must be one of "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.
Dot_Replacement:
This attribute specifies the string that should replace the "." in unit names. Its default value is "-" 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:
Spec_Suffix and Specification_Suffix:
For Ada, these attributes give the suffix used in file names that contain specifications. For other languages, they give the extension for files that contain declaration (header files in C for instance). The attribute is indexed on the language. The two attributes are equivalent, but the latter is obsolescent. If Spec_Suffix ("Ada") is not specified, then the default is "^.ads^.ADS^". The value must satisfy the following requirements:
Body_Suffix and Implementation_Suffix:
These attributes give the extension used for file names that contain code (bodies in Ada). They are indexed on the language. The second version is obsolescent and fully replaced by the first attribute.

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).

Separate_Suffix:
This attribute is specific to Ada. It denotes the suffix used in file names that contain separate bodies. If it is not specified, then it defaults to same value as Body_Suffix ("Ada"). The same rules apply as for the Body_Suffix attribute. The only accepted index is "Ada".
Spec or Specification:
This attribute 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;

Body or Implementation:
These attribute play the same role as Spec for Ada bodies.
Specification_Exceptions and Implementation_Exceptions:
These attributes define exceptions to the naming scheme for languages other than Ada. They are indexed on the language name, and contain a list of file names respectively for headers and source code.

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;