Reputation: 33
gnatmake xx.ada xx_.ada
gcc -c -x ada xx.ada
xx.ada:44:14: warning: file name does not match unit name, should be
"xx.adb"
xx.ada:44:14: file "xx.ads" not found
gnatmake: "xx.ada" compilation error
Tried compiling using gnatmake..its not working.
Upvotes: 3
Views: 892
Reputation: 25501
Unless there’s some really really important reason that you have to stick with that file naming convention, it will be much easier if you go with the default GNAT convention: spec files are named .ads
, body files .adb
.
As it is, when you say gnatmake xx.ada
, you get the warning that the file name isn’t as expected, and then the compiler continues; it sees that xx.ada
is a package body, and goes to look for the spec (in xx.ads
, because you haven’t told it any different) and can’t find it.
There is a utility gnatname (see here) which you can run over your sources (gnatname *.ada
worked for me, with only 4 files) to produce a "configuration file" gnat.adc
, that gnatmake reads first to tell it explicitly which file contains what. My test resulted in
pragma Source_File_Name
(Linked_List,
Body_File_Name => "linked_list.ada");
pragma Source_File_Name
(Lists,
Spec_File_Name => "lists_.ada");
pragma Source_File_Name
(Lists,
Body_File_Name => "lists.ada");
pragma Source_File_Name
(Linked_List,
Spec_File_Name => "linked_list_.ada");
Or, you could use the equivalent in the GNAT Project Manager by writing a project file e.g. t.gpr
containing
project T is
package Naming is
for Spec_Suffix ("ada") use "_.ada";
for Body_Suffix ("ada") use ".ada";
end Naming;
end T;
and compiling with gnatmake -P t.gpr
.
(Newer releases of GNAT include a utility gprbuild which understands .gpr
files; gnatmake will actually invoke gprbuild if it finds it, so what you’re effectively saying is gprbuild -P t.gpr
.)
Upvotes: 4
Reputation: 3341
To complement Simon Wright anwser, if you are able to edit source files, some additional hints.
As documented here
Pragma Source_File_Name
Quoting link:
Use this to override the normal naming convention. It is a configuration pragma, and so has the usual applicability of configuration pragmas (i.e. it applies to either an entire partition, or to all units in a compilation, or to a single unit, depending on how it is used. unit_name is mapped to file_name_literal. The identifier for the second argument is required, and indicates whether this is the file name for the spec or for the body.
and
Another form of the Source_File_Name pragma allows the specification of patterns defining alternative file naming schemes to apply to all files.
pragma Source_File_Name
( [Spec_File_Name =>] STRING_LITERAL
[,[Casing =>] CASING_SPEC]
[,[Dot_Replacement =>] STRING_LITERAL]);
pragma Source_File_Name
( [Body_File_Name =>] STRING_LITERAL
[,[Casing =>] CASING_SPEC]
[,[Dot_Replacement =>] STRING_LITERAL]);
pragma Source_File_Name
( [Subunit_File_Name =>] STRING_LITERAL
[,[Casing =>] CASING_SPEC]
[,[Dot_Replacement =>] STRING_LITERAL]);
CASING_SPEC ::= Lowercase | Uppercase | Mixedcase
The first argument is a pattern that contains a single asterisk indicating the point at which the unit name is to be inserted in the pattern string to form the file name. The second argument is optional. If present it specifies the casing of the unit name in the resulting file name string. The default is lower case. Finally the third argument allows for systematic replacement of any dots in the unit name by the specified string literal.
And the warning:
Note that Source_File_Name pragmas should not be used if you are using project files. The reason for this rule is that the project manager is not aware of these pragmas, and so other tools that use the projet file would not be aware of the intended naming conventions. If you are using project files, file naming is controlled by Source_File_Name_Project pragmas, which are usually supplied automatically by the project manager. A pragma Source_File_Name cannot appear after a Pragma Source_File_Name_Project.
As far as I can tell, these seems to basicaly be what gnatname does according to Simon's link, quoting:
To help maintain the correspondence between compilation unit names and source file names within the compiler, GNAT provides a tool gnatname to generate the required pragmas for a set of files.
Upvotes: 1