File Naming Rules (GNAT User’s Guide for Native Platforms)

#### 3.3.1 File Naming Rules ¶

GNAT determines the default file name by the name of the unit that the file contains. The name is formed by taking the full expanded name of the unit, replacing the separating dots with hyphens, and using lowercase for all letters.

An exception occurs if the file name generated by the above rules starts with one of the characters `a`, `g`, `i`, or `s` and the second character is a hyphen. In this case, the character tilde is used in place of the hyphen. This special rule avoids clashes with the standard names for child units of the packages `System`, `Ada`, `Interfaces`, and `GNAT`, which use the prefixes `s-`, `a-`, `i-`, and `g-`, respectively.

The file extension is `.ads` for a spec and `.adb` for a body. The following table shows some examples of these rules.

> Source File | Ada Compilation Unit
> `main.ads` | Main (spec)
> `main.adb` | Main (body)
> `arith_functions.ads` | Arith_Functions (package spec)
> `arith_functions.adb` | Arith_Functions (package body)
> `func-spec.ads` | Func.Spec (child package spec)
> `func-spec.adb` | Func.Spec (child package body)
> `main-sub.adb` | Sub (subunit of Main)
> `a~bad.adb` | A.Bad (child package body)

Following these rules can result in excessively long file names if corresponding unit names are long (for example, if child units or subunits are heavily nested). An option is available to shorten such long file names (called file name ‘krunching’). You may find this particularly useful when programs being developed with GNAT are to be used on operating systems with limited file name lengths. Using gnatkr.

Of course, no file shortening algorithm can guarantee uniqueness over all possible unit names; if file name krunching is used, it is your responsibility to ensure no name clashes occur. Alternatively, you can specify the exact file names that you want used, as described in the next section. Finally, if your Ada programs are migrating from a compiler with a different naming convention, you can use the `gnatchop` utility to produce source files that follow the GNAT naming conventions. (For details see Renaming Files with gnatchop.)

Note: in the case of Windows or Mac OS operating systems, case is not significant. So, for example, on Windows if the canonical name is `main-sub.adb`, you can use the file name `Main-Sub.adb` instead. However, case is significant for other operating systems, so, for example, if you want to use other than canonically cased file names on a Unix system, you need to follow the procedures described in the next section.