1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1996-2007, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
29 with MLib.Tgt; use MLib.Tgt;
32 with Namet; use Namet;
34 with Osint; use Osint;
38 with Prj.Ext; use Prj.Ext;
40 with Prj.Util; use Prj.Util;
42 with Snames; use Snames;
45 with Types; use Types;
46 with Hostparm; use Hostparm;
47 -- Used to determine if we are in VMS or not for error message purposes
49 with Ada.Characters.Handling; use Ada.Characters.Handling;
50 with Ada.Command_Line; use Ada.Command_Line;
51 with Ada.Text_IO; use Ada.Text_IO;
53 with GNAT.OS_Lib; use GNAT.OS_Lib;
55 with VMS_Conv; use VMS_Conv;
58 Project_Tree : constant Project_Tree_Ref := new Project_Tree_Data;
59 Project_File : String_Access;
60 Project : Prj.Project_Id;
61 Current_Verbosity : Prj.Verbosity := Prj.Default;
62 Tool_Package_Name : Name_Id := No_Name;
64 B_Start : String_Ptr := new String'("b~");
65 -- Prefix of binder generated file, changed to b__ for VMS
67 Old_Project_File_Used : Boolean := False;
68 -- This flag indicates a switch -p (for gnatxref and gnatfind) for
69 -- an old fashioned project file. -p cannot be used in conjonction
72 Max_Files_On_The_Command_Line : constant := 30; -- Arbitrary
74 Temp_File_Name : String_Access := null;
75 -- The name of the temporary text file to put a list of source/object
76 -- files to pass to a tool, when there are more than
77 -- Max_Files_On_The_Command_Line files.
79 ASIS_Main : String_Access := null;
80 -- Main for commands Check, Metric and Pretty, when -U is used
82 package First_Switches is new Table.Table
83 (Table_Component_Type => String_Access,
84 Table_Index_Type => Integer,
87 Table_Increment => 100,
88 Table_Name => "Gnatcmd.First_Switches");
89 -- A table to keep the switches from the project file
91 package Carg_Switches is new Table.Table
92 (Table_Component_Type => String_Access,
93 Table_Index_Type => Integer,
96 Table_Increment => 100,
97 Table_Name => "Gnatcmd.Carg_Switches");
98 -- A table to keep the switches following -cargs for ASIS tools
100 package Rules_Switches is new Table.Table
101 (Table_Component_Type => String_Access,
102 Table_Index_Type => Integer,
103 Table_Low_Bound => 1,
105 Table_Increment => 100,
106 Table_Name => "Gnatcmd.Rules_Switches");
107 -- A table to keep the switches following -rules for gnatcheck
109 package Library_Paths is new Table.Table (
110 Table_Component_Type => String_Access,
111 Table_Index_Type => Integer,
112 Table_Low_Bound => 1,
114 Table_Increment => 100,
115 Table_Name => "Make.Library_Path");
117 -- Packages of project files to pass to Prj.Pars.Parse, depending on the
118 -- tool. We allocate objects because we cannot declare aliased objects
119 -- as we are in a procedure, not a library level package.
121 Naming_String : constant String_Access := new String'("naming");
122 Binder_String : constant String_Access := new String'("binder");
123 Compiler_String : constant String_Access := new String'("compiler");
124 Check_String : constant String_Access := new String'("check");
125 Eliminate_String : constant String_Access := new String'("eliminate");
126 Finder_String : constant String_Access := new String'("finder");
127 Linker_String : constant String_Access := new String'("linker");
128 Gnatls_String : constant String_Access := new String'("gnatls");
129 Pretty_String : constant String_Access := new String'("pretty_printer");
130 Stack_String : constant String_Access := new String'("stack");
131 Gnatstub_String : constant String_Access := new String'("gnatstub");
132 Metric_String : constant String_Access := new String'("metrics");
133 Xref_String : constant String_Access := new String'("cross_reference");
135 Packages_To_Check_By_Binder : constant String_List_Access :=
136 new String_List'((Naming_String, Binder_String));
138 Packages_To_Check_By_Check : constant String_List_Access :=
139 new String_List'((Naming_String, Check_String, Compiler_String));
141 Packages_To_Check_By_Eliminate : constant String_List_Access :=
142 new String_List'((Naming_String, Eliminate_String, Compiler_String));
144 Packages_To_Check_By_Finder : constant String_List_Access :=
145 new String_List'((Naming_String, Finder_String));
147 Packages_To_Check_By_Linker : constant String_List_Access :=
148 new String_List'((Naming_String, Linker_String));
150 Packages_To_Check_By_Gnatls : constant String_List_Access :=
151 new String_List'((Naming_String, Gnatls_String));
153 Packages_To_Check_By_Pretty : constant String_List_Access :=
154 new String_List'((Naming_String, Pretty_String, Compiler_String));
156 Packages_To_Check_By_Stack : constant String_List_Access :=
157 new String_List'((Naming_String, Stack_String));
159 Packages_To_Check_By_Gnatstub : constant String_List_Access :=
160 new String_List'((Naming_String, Gnatstub_String, Compiler_String));
162 Packages_To_Check_By_Metric : constant String_List_Access :=
163 new String_List'((Naming_String, Metric_String, Compiler_String));
165 Packages_To_Check_By_Xref : constant String_List_Access :=
166 new String_List'((Naming_String, Xref_String));
168 Packages_To_Check : String_List_Access := Prj.All_Packages;
170 ----------------------------------
171 -- Declarations for GNATCMD use --
172 ----------------------------------
174 The_Command : Command_Type;
175 -- The command specified in the invocation of the GNAT driver
177 Command_Arg : Positive := 1;
178 -- The index of the command in the arguments of the GNAT driver
180 My_Exit_Status : Exit_Status := Success;
181 -- The exit status of the spawned tool. Used to set the correct VMS
184 Current_Work_Dir : constant String := Get_Current_Dir;
185 -- The path of the working directory
187 All_Projects : Boolean := False;
188 -- Flag used for GNAT CHECK, GNAT PRETTY, GNAT METRIC, and GNAT STACK to
189 -- indicate that the underlying tool (gnatcheck, gnatpp or gnatmetric)
190 -- should be invoked for all sources of all projects.
192 -----------------------
193 -- Local Subprograms --
194 -----------------------
196 procedure Add_To_Carg_Switches (Switch : String_Access);
197 -- Add a switch to the Carg_Switches table. If it is the first one, put the
198 -- switch "-cargs" at the beginning of the table.
200 procedure Add_To_Rules_Switches (Switch : String_Access);
201 -- Add a switch to the Rules_Switches table. If it is the first one, put
202 -- the switch "-crules" at the beginning of the table.
204 procedure Check_Files;
205 -- For GNAT LIST, GNAT PRETTY, GNAT METRIC, and GNAT STACK, check if a
206 -- project file is specified, without any file arguments. If it is the
207 -- case, invoke the GNAT tool with the proper list of files, derived from
208 -- the sources of the project.
210 function Check_Project
211 (Project : Project_Id;
212 Root_Project : Project_Id) return Boolean;
213 -- Returns True if Project = Root_Project or if we want to consider all
214 -- sources of all projects. For GNAT METRIC, also returns True if Project
215 -- is extended by Root_Project.
217 procedure Check_Relative_Executable (Name : in out String_Access);
218 -- Check if an executable is specified as a relative path. If it is, and
219 -- the path contains directory information, fail. Otherwise, prepend the
220 -- exec directory. This procedure is only used for GNAT LINK when a project
221 -- file is specified.
223 function Configuration_Pragmas_File return Path_Name_Type;
224 -- Return an argument, if there is a configuration pragmas file to be
225 -- specified for Project, otherwise return No_Name. Used for gnatstub (GNAT
226 -- STUB), gnatpp (GNAT PRETTY), gnatelim (GNAT ELIM), and gnatmetric (GNAT
229 procedure Delete_Temp_Config_Files;
230 -- Delete all temporary config files
232 procedure Get_Closure;
233 -- Get the sources in the closure of the ASIS_Main and add them to the
234 -- list of arguments.
236 function Index (Char : Character; Str : String) return Natural;
237 -- Returns first occurrence of Char in Str, returns 0 if Char not in Str
239 procedure Non_VMS_Usage;
240 -- Display usage for platforms other than VMS
242 procedure Process_Link;
243 -- Process GNAT LINK, when there is a project file specified
245 procedure Set_Library_For
246 (Project : Project_Id;
247 There_Are_Libraries : in out Boolean);
248 -- If Project is a library project, add the correct -L and -l switches to
249 -- the linker invocation.
251 procedure Set_Libraries is
252 new For_Every_Project_Imported (Boolean, Set_Library_For);
253 -- Add the -L and -l switches to the linker for all of the library
256 procedure Test_If_Relative_Path
257 (Switch : in out String_Access;
259 -- Test if Switch is a relative search path switch. If it is and it
260 -- includes directory information, prepend the path with Parent. This
261 -- subprogram is only called when using project files.
263 --------------------------
264 -- Add_To_Carg_Switches --
265 --------------------------
267 procedure Add_To_Carg_Switches (Switch : String_Access) is
269 -- If the Carg_Switches table is empty, put "-cargs" at the beginning
271 if Carg_Switches.Last = 0 then
272 Carg_Switches.Increment_Last;
273 Carg_Switches.Table (Carg_Switches.Last) := new String'("-cargs");
276 Carg_Switches.Increment_Last;
277 Carg_Switches.Table (Carg_Switches.Last) := Switch;
278 end Add_To_Carg_Switches;
280 ---------------------------
281 -- Add_To_Rules_Switches --
282 ---------------------------
284 procedure Add_To_Rules_Switches (Switch : String_Access) is
286 -- If the Rules_Switches table is empty, put "-rules" at the beginning
288 if Rules_Switches.Last = 0 then
289 Rules_Switches.Increment_Last;
290 Rules_Switches.Table (Rules_Switches.Last) := new String'("-rules");
293 Rules_Switches.Increment_Last;
294 Rules_Switches.Table (Rules_Switches.Last) := Switch;
295 end Add_To_Rules_Switches;
301 procedure Check_Files is
302 Add_Sources : Boolean := True;
303 Unit_Data : Prj.Unit_Data;
304 Subunit : Boolean := False;
307 -- Check if there is at least one argument that is not a switch
309 for Index in 1 .. Last_Switches.Last loop
310 if Last_Switches.Table (Index) (1) /= '-' then
311 Add_Sources := False;
316 -- If all arguments were switches, add the path names of all the sources
317 -- of the main project.
321 Current_Last : constant Integer := Last_Switches.Last;
323 -- Gnatstack needs to add the the .ci file for the binder
324 -- generated files corresponding to all of the library projects
325 -- and main units belonging to the application.
327 if The_Command = Stack then
328 for Proj in Project_Table.First ..
329 Project_Table.Last (Project_Tree.Projects)
331 if Check_Project (Proj, Project) then
333 Data : Project_Data renames
334 Project_Tree.Projects.Table (Proj);
335 Main : String_List_Id := Data.Mains;
336 File : String_Access;
339 -- Include binder generated files for main programs
341 while Main /= Nil_String loop
344 (Get_Name_String (Data.Object_Directory) &
345 Directory_Separator &
349 (Project_Tree.String_Elements.Table
353 if Is_Regular_File (File.all) then
354 Last_Switches.Increment_Last;
355 Last_Switches.Table (Last_Switches.Last) := File;
359 Project_Tree.String_Elements.Table (Main).Next;
364 -- Include the .ci file for the binder generated
365 -- files that contains the initialization and
366 -- finalization of the library.
370 (Get_Name_String (Data.Object_Directory) &
371 Directory_Separator &
373 Get_Name_String (Data.Library_Name) &
376 if Is_Regular_File (File.all) then
377 Last_Switches.Increment_Last;
378 Last_Switches.Table (Last_Switches.Last) := File;
386 for Unit in Unit_Table.First ..
387 Unit_Table.Last (Project_Tree.Units)
389 Unit_Data := Project_Tree.Units.Table (Unit);
391 -- For gnatls, we only need to put the library units, body or
392 -- spec, but not the subunits.
394 if The_Command = List then
396 Unit_Data.File_Names (Body_Part).Name /= No_File
398 -- There is a body, check if it is for this project
400 if All_Projects or else
401 Unit_Data.File_Names (Body_Part).Project = Project
406 Unit_Data.File_Names (Specification).Name = No_File
408 -- We have a body with no spec: we need to check if
409 -- this is a subunit, because gnatls will complain
413 Src_Ind : Source_File_Index;
416 Src_Ind := Sinput.P.Load_Project_File
418 (Unit_Data.File_Names
422 Sinput.P.Source_File_Is_Subunit
428 Last_Switches.Increment_Last;
429 Last_Switches.Table (Last_Switches.Last) :=
432 (Unit_Data.File_Names
433 (Body_Part).Display_Name));
438 Unit_Data.File_Names (Specification).Name /= No_File
440 -- We have a spec with no body; check if it is for this
443 if All_Projects or else
444 Unit_Data.File_Names (Specification).Project = Project
446 Last_Switches.Increment_Last;
447 Last_Switches.Table (Last_Switches.Last) :=
450 (Unit_Data.File_Names
451 (Specification).Display_Name));
455 -- For gnatstack, we put the .ci files corresponding to the
456 -- different units, including the binder generated files. We
457 -- only need to do that for the library units, body or spec,
458 -- but not the subunits.
460 elsif The_Command = Stack then
462 Unit_Data.File_Names (Body_Part).Name /= No_File
464 -- There is a body. Check if .ci files for this project
469 (Unit_Data.File_Names (Body_Part).Project, Project)
474 Unit_Data.File_Names (Specification).Name = No_File
476 -- We have a body with no spec: we need to check
477 -- if this is a subunit, because .ci files are not
478 -- generated for subunits.
481 Src_Ind : Source_File_Index;
484 Src_Ind := Sinput.P.Load_Project_File
486 (Unit_Data.File_Names (Body_Part).Path));
489 Sinput.P.Source_File_Is_Subunit (Src_Ind);
494 Last_Switches.Increment_Last;
495 Last_Switches.Table (Last_Switches.Last) :=
498 (Project_Tree.Projects.Table
499 (Unit_Data.File_Names
500 (Body_Part).Project).
502 Directory_Separator &
505 (Unit_Data.File_Names
506 (Body_Part).Display_Name),
512 Unit_Data.File_Names (Specification).Name /= No_File
514 -- We have a spec with no body. Check if it is for this
519 (Unit_Data.File_Names (Specification).Project,
522 Last_Switches.Increment_Last;
523 Last_Switches.Table (Last_Switches.Last) :=
526 (Project_Tree.Projects.Table
527 (Unit_Data.File_Names
528 (Specification).Project).
533 (Unit_Data.File_Names
534 (Specification).Name),
540 -- For gnatcheck, gnatpp and gnatmetric, put all sources
541 -- of the project, or of all projects if -U was specified.
543 for Kind in Spec_Or_Body loop
545 -- Put only sources that belong to the main project
548 (Unit_Data.File_Names (Kind).Project, Project)
550 Last_Switches.Increment_Last;
551 Last_Switches.Table (Last_Switches.Last) :=
554 (Unit_Data.File_Names
555 (Kind).Display_Path));
561 -- If the list of files is too long, create a temporary text file
562 -- that lists these files, and pass this temp file to gnatcheck,
563 -- gnatpp or gnatmetric using switch -files=.
565 if Last_Switches.Last - Current_Last >
566 Max_Files_On_The_Command_Line
569 Temp_File_FD : File_Descriptor;
570 Buffer : String (1 .. 1_000);
572 OK : Boolean := True;
575 Create_Temp_File (Temp_File_FD, Temp_File_Name);
577 if Temp_File_Name /= null then
578 for Index in Current_Last + 1 ..
581 Len := Last_Switches.Table (Index)'Length;
582 Buffer (1 .. Len) := Last_Switches.Table (Index).all;
584 Buffer (Len) := ASCII.LF;
585 Buffer (Len + 1) := ASCII.NUL;
594 Close (Temp_File_FD, OK);
596 Close (Temp_File_FD, OK);
600 -- If there were any problem creating the temp file, then
601 -- pass the list of files.
605 -- Replace list of files with -files=<temp file name>
607 Last_Switches.Set_Last (Current_Last + 1);
608 Last_Switches.Table (Last_Switches.Last) :=
609 new String'("-files=" & Temp_File_Name.all);
622 function Check_Project
623 (Project : Project_Id;
624 Root_Project : Project_Id) return Boolean
627 if Project = No_Project then
630 elsif All_Projects or Project = Root_Project then
633 elsif The_Command = Metric then
638 Data := Project_Tree.Projects.Table (Root_Project);
639 while Data.Extends /= No_Project loop
640 if Project = Data.Extends then
644 Data := Project_Tree.Projects.Table (Data.Extends);
652 -------------------------------
653 -- Check_Relative_Executable --
654 -------------------------------
656 procedure Check_Relative_Executable (Name : in out String_Access) is
657 Exec_File_Name : constant String := Name.all;
660 if not Is_Absolute_Path (Exec_File_Name) then
661 for Index in Exec_File_Name'Range loop
662 if Exec_File_Name (Index) = Directory_Separator then
663 Fail ("relative executable (""" &
665 """) with directory part not allowed " &
666 "when using project files");
670 Get_Name_String (Project_Tree.Projects.Table
671 (Project).Exec_Directory);
673 if Name_Buffer (Name_Len) /= Directory_Separator then
674 Name_Len := Name_Len + 1;
675 Name_Buffer (Name_Len) := Directory_Separator;
678 Name_Buffer (Name_Len + 1 ..
679 Name_Len + Exec_File_Name'Length) :=
681 Name_Len := Name_Len + Exec_File_Name'Length;
682 Name := new String'(Name_Buffer (1 .. Name_Len));
684 end Check_Relative_Executable;
686 --------------------------------
687 -- Configuration_Pragmas_File --
688 --------------------------------
690 function Configuration_Pragmas_File return Path_Name_Type is
692 Prj.Env.Create_Config_Pragmas_File
693 (Project, Project, Project_Tree, Include_Config_Files => False);
694 return Project_Tree.Projects.Table (Project).Config_File_Name;
695 end Configuration_Pragmas_File;
697 ------------------------------
698 -- Delete_Temp_Config_Files --
699 ------------------------------
701 procedure Delete_Temp_Config_Files is
705 if not Keep_Temporary_Files then
706 if Project /= No_Project then
707 for Prj in Project_Table.First ..
708 Project_Table.Last (Project_Tree.Projects)
711 Project_Tree.Projects.Table (Prj).Config_File_Temp
714 Output.Write_Str ("Deleting temp configuration file """);
717 (Project_Tree.Projects.Table
718 (Prj).Config_File_Name));
719 Output.Write_Line ("""");
723 (Name => Get_Name_String
724 (Project_Tree.Projects.Table
725 (Prj).Config_File_Name),
731 -- If a temporary text file that contains a list of files for a tool
732 -- has been created, delete this temporary file.
734 if Temp_File_Name /= null then
735 Delete_File (Temp_File_Name.all, Success);
738 end Delete_Temp_Config_Files;
744 procedure Get_Closure is
745 Args : constant Argument_List :=
746 (1 => new String'("-q"),
747 2 => new String'("-b"),
748 3 => new String'("-P"),
751 6 => new String'("-bargs"),
752 7 => new String'("-R"),
753 8 => new String'("-Z"));
754 -- Arguments of the invocation of gnatmake to get the list of
756 FD : File_Descriptor;
757 -- File descriptor for the temp file that will get the output of the
758 -- invocation of gnatmake.
760 Name : Path_Name_Type;
761 -- Path of the file FD
763 GN_Name : constant String := Program_Name ("gnatmake").all;
766 GN_Path : constant String_Access := Locate_Exec_On_Path (GN_Name);
769 Return_Code : Integer;
772 pragma Warnings (Off, Unused);
774 File : Ada.Text_IO.File_Type;
775 Line : String (1 .. 250);
779 Path : Path_Name_Type;
782 if GN_Path = null then
783 Put_Line (Standard_Error, "could not locate " & GN_Name);
787 -- Create the temp file
789 Tempdir.Create_Temp_File (FD, Name);
791 -- And close it, because on VMS Spawn with a file descriptor created
792 -- with Create_Temp_File does not redirect output.
796 -- Spawn "gnatmake -q -b -P <project> <main> -bargs -R -Z"
799 (Program_Name => GN_Path.all,
801 Output_File => Get_Name_String (Name),
803 Return_Code => Return_Code,
808 -- Read the output of the invocation of gnatmake
810 Open (File, In_File, Get_Name_String (Name));
812 -- If it was unsuccessful, display the first line in the file and exit
815 if Return_Code /= 0 then
816 Get_Line (File, Line, Last);
818 if not Keep_Temporary_Files then
824 Put_Line (Standard_Error, Line (1 .. Last));
826 (Standard_Error, "could not get closure of " & ASIS_Main.all);
830 -- Get each file name in the file, find its path and add it the the
831 -- list of arguments.
833 while not End_Of_File (File) loop
834 Get_Line (File, Line, Last);
837 for Unit in Unit_Table.First ..
838 Unit_Table.Last (Project_Tree.Units)
840 Udata := Project_Tree.Units.Table (Unit);
842 if Udata.File_Names (Specification).Name /= No_File
844 Get_Name_String (Udata.File_Names (Specification).Name) =
847 Path := Udata.File_Names (Specification).Path;
850 elsif Udata.File_Names (Body_Part).Name /= No_File
852 Get_Name_String (Udata.File_Names (Body_Part).Name) =
855 Path := Udata.File_Names (Body_Part).Path;
860 Last_Switches.Increment_Last;
862 if Path /= No_Path then
863 Last_Switches.Table (Last_Switches.Last) :=
864 new String'(Get_Name_String (Path));
867 Last_Switches.Table (Last_Switches.Last) :=
868 new String'(Line (1 .. Last));
872 if not Keep_Temporary_Files then
885 function Index (Char : Character; Str : String) return Natural is
887 for Index in Str'Range loop
888 if Str (Index) = Char then
900 procedure Process_Link is
901 Look_For_Executable : Boolean := True;
902 There_Are_Libraries : Boolean := False;
903 Path_Option : constant String_Access :=
904 MLib.Linker_Library_Path_Option;
905 Prj : Project_Id := Project;
908 Skip_Executable : Boolean := False;
911 -- Add the default search directories, to be able to find
912 -- libgnat in call to MLib.Utl.Lib_Directory.
914 Add_Default_Search_Dirs;
916 Library_Paths.Set_Last (0);
918 -- Check if there are library project files
920 if MLib.Tgt.Support_For_Libraries /= None then
921 Set_Libraries (Project, Project_Tree, There_Are_Libraries);
924 -- If there are, add the necessary additional switches
926 if There_Are_Libraries then
928 -- Add -L<lib_dir> -lgnarl -lgnat -Wl,-rpath,<lib_dir>
930 Last_Switches.Increment_Last;
931 Last_Switches.Table (Last_Switches.Last) :=
932 new String'("-L" & MLib.Utl.Lib_Directory);
933 Last_Switches.Increment_Last;
934 Last_Switches.Table (Last_Switches.Last) :=
935 new String'("-lgnarl");
936 Last_Switches.Increment_Last;
937 Last_Switches.Table (Last_Switches.Last) :=
938 new String'("-lgnat");
940 -- If Path_Option is not null, create the switch ("-Wl,-rpath," or
941 -- equivalent) with all the library dirs plus the standard GNAT
944 if Path_Option /= null then
946 Option : String_Access;
947 Length : Natural := Path_Option'Length;
951 -- First, compute the exact length for the switch
954 Library_Paths.First .. Library_Paths.Last
956 -- Add the length of the library dir plus one for the
957 -- directory separator.
961 Library_Paths.Table (Index)'Length + 1;
964 -- Finally, add the length of the standard GNAT library dir
966 Length := Length + MLib.Utl.Lib_Directory'Length;
967 Option := new String (1 .. Length);
968 Option (1 .. Path_Option'Length) := Path_Option.all;
969 Current := Path_Option'Length;
971 -- Put each library dir followed by a dir separator
974 Library_Paths.First .. Library_Paths.Last
979 Library_Paths.Table (Index)'Length) :=
980 Library_Paths.Table (Index).all;
983 Library_Paths.Table (Index)'Length + 1;
984 Option (Current) := Path_Separator;
987 -- Finally put the standard GNAT library dir
991 Current + MLib.Utl.Lib_Directory'Length) :=
992 MLib.Utl.Lib_Directory;
994 -- And add the switch to the last switches
996 Last_Switches.Increment_Last;
997 Last_Switches.Table (Last_Switches.Last) :=
1003 -- Check if the first ALI file specified can be found, either in the
1004 -- object directory of the main project or in an object directory of a
1005 -- project file extended by the main project. If the ALI file can be
1006 -- found, replace its name with its absolute path.
1008 Skip_Executable := False;
1010 Switch_Loop : for J in 1 .. Last_Switches.Last loop
1012 -- If we have an executable just reset the flag
1014 if Skip_Executable then
1015 Skip_Executable := False;
1017 -- If -o, set flag so that next switch is not processed
1019 elsif Last_Switches.Table (J).all = "-o" then
1020 Skip_Executable := True;
1026 Switch : constant String :=
1027 Last_Switches.Table (J).all;
1029 ALI_File : constant String (1 .. Switch'Length + 4) :=
1032 Test_Existence : Boolean := False;
1035 Last := Switch'Length;
1037 -- Skip real switches
1039 if Switch'Length /= 0
1040 and then Switch (Switch'First) /= '-'
1042 -- Append ".ali" if file name does not end with it
1044 if Switch'Length <= 4
1045 or else Switch (Switch'Last - 3 .. Switch'Last)
1048 Last := ALI_File'Last;
1051 -- If file name includes directory information, stop if ALI
1054 if Is_Absolute_Path (ALI_File (1 .. Last)) then
1055 Test_Existence := True;
1058 for K in Switch'Range loop
1059 if Switch (K) = '/' or else
1060 Switch (K) = Directory_Separator
1062 Test_Existence := True;
1068 if Test_Existence then
1069 if Is_Regular_File (ALI_File (1 .. Last)) then
1073 -- Look in object directories if ALI file exists
1078 Dir : constant String :=
1080 (Project_Tree.Projects.Table
1081 (Prj).Object_Directory);
1085 Directory_Separator &
1086 ALI_File (1 .. Last))
1088 -- We have found the correct project, so we
1089 -- replace the file with the absolute path.
1091 Last_Switches.Table (J) :=
1093 (Dir & Directory_Separator &
1094 ALI_File (1 .. Last));
1102 -- Go to the project being extended, if any
1105 Project_Tree.Projects.Table (Prj).Extends;
1106 exit Project_Loop when Prj = No_Project;
1107 end loop Project_Loop;
1112 end loop Switch_Loop;
1114 -- If a relative path output file has been specified, we add the exec
1117 for J in reverse 1 .. Last_Switches.Last - 1 loop
1118 if Last_Switches.Table (J).all = "-o" then
1119 Check_Relative_Executable
1120 (Name => Last_Switches.Table (J + 1));
1121 Look_For_Executable := False;
1126 if Look_For_Executable then
1127 for J in reverse 1 .. First_Switches.Last - 1 loop
1128 if First_Switches.Table (J).all = "-o" then
1129 Look_For_Executable := False;
1130 Check_Relative_Executable
1131 (Name => First_Switches.Table (J + 1));
1137 -- If no executable is specified, then find the name of the first ALI
1138 -- file on the command line and issue a -o switch with the absolute path
1139 -- of the executable in the exec directory.
1141 if Look_For_Executable then
1142 for J in 1 .. Last_Switches.Last loop
1143 Arg := Last_Switches.Table (J);
1146 if Arg'Length /= 0 and then Arg (Arg'First) /= '-' then
1148 and then Arg (Arg'Last - 3 .. Arg'Last) = ".ali"
1150 Last := Arg'Last - 4;
1152 elsif Is_Regular_File (Arg.all & ".ali") then
1157 Last_Switches.Increment_Last;
1158 Last_Switches.Table (Last_Switches.Last) :=
1161 (Project_Tree.Projects.Table
1162 (Project).Exec_Directory);
1163 Last_Switches.Increment_Last;
1164 Last_Switches.Table (Last_Switches.Last) :=
1165 new String'(Name_Buffer (1 .. Name_Len) &
1166 Directory_Separator &
1168 (Base_Name (Arg (Arg'First .. Last))));
1176 ---------------------
1177 -- Set_Library_For --
1178 ---------------------
1180 procedure Set_Library_For
1181 (Project : Project_Id;
1182 There_Are_Libraries : in out Boolean)
1184 Path_Option : constant String_Access :=
1185 MLib.Linker_Library_Path_Option;
1188 -- Case of library project
1190 if Project_Tree.Projects.Table (Project).Library then
1191 There_Are_Libraries := True;
1193 -- Add the -L switch
1195 Last_Switches.Increment_Last;
1196 Last_Switches.Table (Last_Switches.Last) :=
1199 (Project_Tree.Projects.Table
1200 (Project).Library_Dir));
1202 -- Add the -l switch
1204 Last_Switches.Increment_Last;
1205 Last_Switches.Table (Last_Switches.Last) :=
1208 (Project_Tree.Projects.Table
1209 (Project).Library_Name));
1211 -- Add the directory to table Library_Paths, to be processed later
1212 -- if library is not static and if Path_Option is not null.
1214 if Project_Tree.Projects.Table (Project).Library_Kind /=
1216 and then Path_Option /= null
1218 Library_Paths.Increment_Last;
1219 Library_Paths.Table (Library_Paths.Last) :=
1220 new String'(Get_Name_String
1221 (Project_Tree.Projects.Table
1222 (Project).Library_Dir));
1225 end Set_Library_For;
1227 ---------------------------
1228 -- Test_If_Relative_Path --
1229 ---------------------------
1231 procedure Test_If_Relative_Path
1232 (Switch : in out String_Access;
1236 if Switch /= null then
1239 Sw : String (1 .. Switch'Length);
1240 Start : Positive := 1;
1245 if Sw (1) = '-' then
1247 and then (Sw (2) = 'A' or else
1248 Sw (2) = 'I' or else
1257 elsif Sw'Length >= 4
1258 and then (Sw (2 .. 3) = "aL" or else
1259 Sw (2 .. 3) = "aO" or else
1264 elsif Sw'Length >= 7
1265 and then Sw (2 .. 6) = "-RTS="
1273 -- If the path is relative, test if it includes directory
1274 -- information. If it does, prepend Parent to the path.
1276 if not Is_Absolute_Path (Sw (Start .. Sw'Last)) then
1277 for J in Start .. Sw'Last loop
1278 if Sw (J) = Directory_Separator then
1281 (Sw (1 .. Start - 1) &
1283 Directory_Separator &
1284 Sw (Start .. Sw'Last));
1291 end Test_If_Relative_Path;
1297 procedure Non_VMS_Usage is
1301 Put_Line ("List of available commands");
1304 for C in Command_List'Range loop
1305 if not Command_List (C).VMS_Only then
1306 Put ("gnat " & To_Lower (Command_List (C).Cname.all));
1308 Put (Command_List (C).Unixcmd.all);
1311 Sws : Argument_List_Access renames Command_List (C).Unixsws;
1314 for J in Sws'Range loop
1326 Put_Line ("Commands find, list, metric, pretty, stack, stub and xref " &
1327 "accept project file switches -vPx, -Pprj and -Xnam=val");
1331 -------------------------------------
1332 -- Start of processing for GNATCmd --
1333 -------------------------------------
1343 Prj.Initialize (Project_Tree);
1346 Last_Switches.Set_Last (0);
1348 First_Switches.Init;
1349 First_Switches.Set_Last (0);
1351 Carg_Switches.Set_Last (0);
1352 Rules_Switches.Init;
1353 Rules_Switches.Set_Last (0);
1355 VMS_Conv.Initialize;
1357 Set_Mode (Ada_Only);
1359 -- Add the directory where the GNAT driver is invoked in front of the path,
1360 -- if the GNAT driver is invoked with directory information. Do not do this
1361 -- for VMS, where the notion of path does not really exist.
1365 Command : constant String := Command_Name;
1368 for Index in reverse Command'Range loop
1369 if Command (Index) = Directory_Separator then
1371 Absolute_Dir : constant String :=
1373 (Command (Command'First .. Index));
1375 PATH : constant String :=
1378 Getenv ("PATH").all;
1381 Setenv ("PATH", PATH);
1390 -- If on VMS, or if VMS emulation is on, convert VMS style /qualifiers,
1391 -- filenames and pathnames to Unix style.
1394 or else To_Lower (Getenv ("EMULATE_VMS").all) = "true"
1396 VMS_Conversion (The_Command);
1398 B_Start := new String'("b__");
1400 -- If not on VMS, scan the command line directly
1403 if Argument_Count = 0 then
1409 if Argument_Count > Command_Arg
1410 and then Argument (Command_Arg) = "-v"
1412 Verbose_Mode := True;
1413 Command_Arg := Command_Arg + 1;
1415 elsif Argument_Count > Command_Arg
1416 and then Argument (Command_Arg) = "-dn"
1418 Keep_Temporary_Files := True;
1419 Command_Arg := Command_Arg + 1;
1426 The_Command := Real_Command_Type'Value (Argument (Command_Arg));
1428 if Command_List (The_Command).VMS_Only then
1432 Command_List (The_Command).Cname.all,
1433 """ can only be used on VMS");
1437 when Constraint_Error =>
1439 -- Check if it is an alternate command
1442 Alternate : Alternate_Command;
1445 Alternate := Alternate_Command'Value
1446 (Argument (Command_Arg));
1447 The_Command := Corresponding_To (Alternate);
1450 when Constraint_Error =>
1452 Fail ("Unknown command: ", Argument (Command_Arg));
1456 -- Get the arguments from the command line and from the eventual
1457 -- argument file(s) specified on the command line.
1459 for Arg in Command_Arg + 1 .. Argument_Count loop
1461 The_Arg : constant String := Argument (Arg);
1464 -- Check if an argument file is specified
1466 if The_Arg (The_Arg'First) = '@' then
1468 Arg_File : Ada.Text_IO.File_Type;
1469 Line : String (1 .. 256);
1473 -- Open the file and fail if the file cannot be found
1478 The_Arg (The_Arg'First + 1 .. The_Arg'Last));
1483 (Standard_Error, "Cannot open argument file """);
1486 The_Arg (The_Arg'First + 1 .. The_Arg'Last));
1488 Put_Line (Standard_Error, """");
1492 -- Read line by line and put the content of each non-
1493 -- empty line in the Last_Switches table.
1495 while not End_Of_File (Arg_File) loop
1496 Get_Line (Arg_File, Line, Last);
1499 Last_Switches.Increment_Last;
1500 Last_Switches.Table (Last_Switches.Last) :=
1501 new String'(Line (1 .. Last));
1509 -- It is not an argument file; just put the argument in
1510 -- the Last_Switches table.
1512 Last_Switches.Increment_Last;
1513 Last_Switches.Table (Last_Switches.Last) :=
1514 new String'(The_Arg);
1522 Program : constant String :=
1523 Program_Name (Command_List (The_Command).Unixcmd.all).all;
1525 Exec_Path : String_Access;
1528 -- Locate the executable for the command
1530 Exec_Path := Locate_Exec_On_Path (Program);
1532 if Exec_Path = null then
1533 Put_Line (Standard_Error, "could not locate " & Program);
1537 -- If there are switches for the executable, put them as first switches
1539 if Command_List (The_Command).Unixsws /= null then
1540 for J in Command_List (The_Command).Unixsws'Range loop
1541 First_Switches.Increment_Last;
1542 First_Switches.Table (First_Switches.Last) :=
1543 Command_List (The_Command).Unixsws (J);
1547 -- For BIND, CHECK, ELIM, FIND, LINK, LIST, PRETTY, STACK, STUB,
1548 -- METRIC ad XREF, look for project file related switches.
1550 if The_Command = Bind
1551 or else The_Command = Check
1552 or else The_Command = Elim
1553 or else The_Command = Find
1554 or else The_Command = Link
1555 or else The_Command = List
1556 or else The_Command = Xref
1557 or else The_Command = Pretty
1558 or else The_Command = Stack
1559 or else The_Command = Stub
1560 or else The_Command = Metric
1564 Tool_Package_Name := Name_Binder;
1565 Packages_To_Check := Packages_To_Check_By_Binder;
1567 Tool_Package_Name := Name_Check;
1568 Packages_To_Check := Packages_To_Check_By_Check;
1570 Tool_Package_Name := Name_Eliminate;
1571 Packages_To_Check := Packages_To_Check_By_Eliminate;
1573 Tool_Package_Name := Name_Finder;
1574 Packages_To_Check := Packages_To_Check_By_Finder;
1576 Tool_Package_Name := Name_Linker;
1577 Packages_To_Check := Packages_To_Check_By_Linker;
1579 Tool_Package_Name := Name_Gnatls;
1580 Packages_To_Check := Packages_To_Check_By_Gnatls;
1582 Tool_Package_Name := Name_Metrics;
1583 Packages_To_Check := Packages_To_Check_By_Metric;
1585 Tool_Package_Name := Name_Pretty_Printer;
1586 Packages_To_Check := Packages_To_Check_By_Pretty;
1588 Tool_Package_Name := Name_Stack;
1589 Packages_To_Check := Packages_To_Check_By_Stack;
1591 Tool_Package_Name := Name_Gnatstub;
1592 Packages_To_Check := Packages_To_Check_By_Gnatstub;
1594 Tool_Package_Name := Name_Cross_Reference;
1595 Packages_To_Check := Packages_To_Check_By_Xref;
1600 -- Check that the switches are consistent. Detect project file
1601 -- related switches.
1605 Arg_Num : Positive := 1;
1606 Argv : String_Access;
1608 procedure Remove_Switch (Num : Positive);
1609 -- Remove a project related switch from table Last_Switches
1615 procedure Remove_Switch (Num : Positive) is
1617 Last_Switches.Table (Num .. Last_Switches.Last - 1) :=
1618 Last_Switches.Table (Num + 1 .. Last_Switches.Last);
1619 Last_Switches.Decrement_Last;
1622 -- Start of processing for Inspect_Switches
1625 while Arg_Num <= Last_Switches.Last loop
1626 Argv := Last_Switches.Table (Arg_Num);
1628 if Argv (Argv'First) = '-' then
1629 if Argv'Length = 1 then
1631 ("switch character cannot be followed by a blank");
1634 -- The two style project files (-p and -P) cannot be used
1637 if (The_Command = Find or else The_Command = Xref)
1638 and then Argv (2) = 'p'
1640 Old_Project_File_Used := True;
1641 if Project_File /= null then
1642 Fail ("-P and -p cannot be used together");
1646 -- -aPdir Add dir to the project search path
1649 and then Argv (Argv'First + 1 .. Argv'First + 2) = "aP"
1651 Add_Search_Project_Directory
1652 (Argv (Argv'First + 3 .. Argv'Last));
1654 Remove_Switch (Arg_Num);
1656 -- -vPx Specify verbosity while parsing project files
1658 elsif Argv'Length = 4
1659 and then Argv (Argv'First + 1 .. Argv'First + 2) = "vP"
1661 case Argv (Argv'Last) is
1663 Current_Verbosity := Prj.Default;
1665 Current_Verbosity := Prj.Medium;
1667 Current_Verbosity := Prj.High;
1669 Fail ("Invalid switch: ", Argv.all);
1672 Remove_Switch (Arg_Num);
1674 -- -Pproject_file Specify project file to be used
1676 elsif Argv (Argv'First + 1) = 'P' then
1678 -- Only one -P switch can be used
1680 if Project_File /= null then
1683 ": second project file forbidden (first is """,
1684 Project_File.all & """)");
1686 -- The two style project files (-p and -P) cannot be
1689 elsif Old_Project_File_Used then
1690 Fail ("-p and -P cannot be used together");
1692 elsif Argv'Length = 2 then
1694 -- There is space between -P and the project file
1695 -- name. -P cannot be the last option.
1697 if Arg_Num = Last_Switches.Last then
1698 Fail ("project file name missing after -P");
1701 Remove_Switch (Arg_Num);
1702 Argv := Last_Switches.Table (Arg_Num);
1704 -- After -P, there must be a project file name,
1705 -- not another switch.
1707 if Argv (Argv'First) = '-' then
1708 Fail ("project file name missing after -P");
1711 Project_File := new String'(Argv.all);
1716 -- No space between -P and project file name
1719 new String'(Argv (Argv'First + 2 .. Argv'Last));
1722 Remove_Switch (Arg_Num);
1724 -- -Xexternal=value Specify an external reference to be
1725 -- used in project files
1727 elsif Argv'Length >= 5
1728 and then Argv (Argv'First + 1) = 'X'
1731 Equal_Pos : constant Natural :=
1734 Argv (Argv'First + 2 .. Argv'Last));
1736 if Equal_Pos >= Argv'First + 3 and then
1737 Equal_Pos /= Argv'Last then
1738 Add (External_Name =>
1739 Argv (Argv'First + 2 .. Equal_Pos - 1),
1740 Value => Argv (Equal_Pos + 1 .. Argv'Last));
1744 " is not a valid external assignment.");
1748 Remove_Switch (Arg_Num);
1751 (The_Command = Check or else
1752 The_Command = Pretty or else
1753 The_Command = Metric or else
1754 The_Command = Stack or else
1756 and then Argv'Length = 2
1757 and then Argv (2) = 'U'
1759 All_Projects := True;
1760 Remove_Switch (Arg_Num);
1763 Arg_Num := Arg_Num + 1;
1766 elsif ((The_Command = Check and then Argv (Argv'First) /= '+')
1767 or else The_Command = Metric
1768 or else The_Command = Pretty)
1769 and then Project_File /= null
1770 and then All_Projects
1772 if ASIS_Main /= null then
1773 Fail ("cannot specify more than one main after -U");
1776 Remove_Switch (Arg_Num);
1780 Arg_Num := Arg_Num + 1;
1783 end Inspect_Switches;
1786 -- If there is a project file specified, parse it, get the switches
1787 -- for the tool and setup PATH environment variables.
1789 if Project_File /= null then
1790 Prj.Pars.Set_Verbosity (To => Current_Verbosity);
1793 (Project => Project,
1794 In_Tree => Project_Tree,
1795 Project_File_Name => Project_File.all,
1796 Packages_To_Check => Packages_To_Check);
1798 if Project = Prj.No_Project then
1799 Fail ("""", Project_File.all, """ processing failed");
1802 -- Check if a package with the name of the tool is in the project
1803 -- file and if there is one, get the switches, if any, and scan them.
1806 Data : constant Prj.Project_Data :=
1807 Project_Tree.Projects.Table (Project);
1809 Pkg : constant Prj.Package_Id :=
1811 (Name => Tool_Package_Name,
1812 In_Packages => Data.Decl.Packages,
1813 In_Tree => Project_Tree);
1815 Element : Package_Element;
1817 Default_Switches_Array : Array_Element_Id;
1819 The_Switches : Prj.Variable_Value;
1820 Current : Prj.String_List_Id;
1821 The_String : String_Element;
1824 if Pkg /= No_Package then
1825 Element := Project_Tree.Packages.Table (Pkg);
1827 -- Packages Gnatls and Gnatstack have a single attribute
1828 -- Switches, that is not an associative array.
1830 if The_Command = List or else The_Command = Stack then
1833 (Variable_Name => Snames.Name_Switches,
1834 In_Variables => Element.Decl.Attributes,
1835 In_Tree => Project_Tree);
1837 -- Packages Binder (for gnatbind), Cross_Reference (for
1838 -- gnatxref), Linker (for gnatlink), Finder (for gnatfind),
1839 -- Pretty_Printer (for gnatpp), Eliminate (for gnatelim), Check
1840 -- (for gnatcheck), and Metric (for gnatmetric) have an
1841 -- attributed Switches, an associative array, indexed by the
1842 -- name of the file.
1844 -- They also have an attribute Default_Switches, indexed by the
1845 -- name of the programming language.
1848 if The_Switches.Kind = Prj.Undefined then
1849 Default_Switches_Array :=
1851 (Name => Name_Default_Switches,
1852 In_Arrays => Element.Decl.Arrays,
1853 In_Tree => Project_Tree);
1854 The_Switches := Prj.Util.Value_Of
1857 In_Array => Default_Switches_Array,
1858 In_Tree => Project_Tree);
1862 -- If there are switches specified in the package of the
1863 -- project file corresponding to the tool, scan them.
1865 case The_Switches.Kind is
1866 when Prj.Undefined =>
1871 Switch : constant String :=
1872 Get_Name_String (The_Switches.Value);
1875 if Switch'Length > 0 then
1876 First_Switches.Increment_Last;
1877 First_Switches.Table (First_Switches.Last) :=
1878 new String'(Switch);
1883 Current := The_Switches.Values;
1884 while Current /= Prj.Nil_String loop
1885 The_String := Project_Tree.String_Elements.
1889 Switch : constant String :=
1890 Get_Name_String (The_String.Value);
1893 if Switch'Length > 0 then
1894 First_Switches.Increment_Last;
1895 First_Switches.Table (First_Switches.Last) :=
1896 new String'(Switch);
1900 Current := The_String.Next;
1906 if The_Command = Bind
1907 or else The_Command = Link
1908 or else The_Command = Elim
1912 (Project_Tree.Projects.Table
1913 (Project).Object_Directory));
1916 -- Set up the env vars for project path files
1918 Prj.Env.Set_Ada_Paths
1919 (Project, Project_Tree, Including_Libraries => False);
1921 -- For gnatcheck, gnatstub, gnatmetric, gnatpp and gnatelim, create
1922 -- a configuration pragmas file, if necessary.
1924 if The_Command = Pretty
1925 or else The_Command = Metric
1926 or else The_Command = Stub
1927 or else The_Command = Elim
1928 or else The_Command = Check
1930 -- If there are switches in package Compiler, put them in the
1931 -- Carg_Switches table.
1934 Data : constant Prj.Project_Data :=
1935 Project_Tree.Projects.Table (Project);
1937 Pkg : constant Prj.Package_Id :=
1939 (Name => Name_Compiler,
1940 In_Packages => Data.Decl.Packages,
1941 In_Tree => Project_Tree);
1943 Element : Package_Element;
1945 Default_Switches_Array : Array_Element_Id;
1947 The_Switches : Prj.Variable_Value;
1948 Current : Prj.String_List_Id;
1949 The_String : String_Element;
1952 if Pkg /= No_Package then
1953 Element := Project_Tree.Packages.Table (Pkg);
1955 Default_Switches_Array :=
1957 (Name => Name_Default_Switches,
1958 In_Arrays => Element.Decl.Arrays,
1959 In_Tree => Project_Tree);
1960 The_Switches := Prj.Util.Value_Of
1963 In_Array => Default_Switches_Array,
1964 In_Tree => Project_Tree);
1966 -- If there are switches specified in the package of the
1967 -- project file corresponding to the tool, scan them.
1969 case The_Switches.Kind is
1970 when Prj.Undefined =>
1975 Switch : constant String :=
1976 Get_Name_String (The_Switches.Value);
1978 if Switch'Length > 0 then
1979 Add_To_Carg_Switches (new String'(Switch));
1984 Current := The_Switches.Values;
1985 while Current /= Prj.Nil_String loop
1987 Project_Tree.String_Elements.Table (Current);
1990 Switch : constant String :=
1991 Get_Name_String (The_String.Value);
1993 if Switch'Length > 0 then
1994 Add_To_Carg_Switches (new String'(Switch));
1998 Current := The_String.Next;
2004 -- If -cargs is one of the switches, move the following switches
2005 -- to the Carg_Switches table.
2007 for J in 1 .. First_Switches.Last loop
2008 if First_Switches.Table (J).all = "-cargs" then
2009 for K in J + 1 .. First_Switches.Last loop
2010 Add_To_Carg_Switches (First_Switches.Table (K));
2012 First_Switches.Set_Last (J - 1);
2017 for J in 1 .. Last_Switches.Last loop
2018 if Last_Switches.Table (J).all = "-cargs" then
2019 for K in J + 1 .. Last_Switches.Last loop
2020 Add_To_Carg_Switches (Last_Switches.Table (K));
2022 Last_Switches.Set_Last (J - 1);
2028 CP_File : constant Path_Name_Type := Configuration_Pragmas_File;
2031 if CP_File /= No_Path then
2032 if The_Command = Elim then
2033 First_Switches.Increment_Last;
2034 First_Switches.Table (First_Switches.Last) :=
2035 new String'("-C" & Get_Name_String (CP_File));
2038 Add_To_Carg_Switches
2039 (new String'("-gnatec=" & Get_Name_String (CP_File)));
2045 if The_Command = Link then
2049 if The_Command = Link or The_Command = Bind then
2051 -- For files that are specified as relative paths with directory
2052 -- information, we convert them to absolute paths, with parent
2053 -- being the current working directory if specified on the command
2054 -- line and the project directory if specified in the project
2055 -- file. This is what gnatmake is doing for linker and binder
2058 for J in 1 .. Last_Switches.Last loop
2059 Test_If_Relative_Path
2060 (Last_Switches.Table (J), Current_Work_Dir);
2064 (Project_Tree.Projects.Table (Project).Directory);
2067 Project_Dir : constant String := Name_Buffer (1 .. Name_Len);
2069 for J in 1 .. First_Switches.Last loop
2070 Test_If_Relative_Path
2071 (First_Switches.Table (J), Project_Dir);
2075 elsif The_Command = Stub then
2077 Data : constant Prj.Project_Data :=
2078 Project_Tree.Projects.Table (Project);
2079 File_Index : Integer := 0;
2080 Dir_Index : Integer := 0;
2081 Last : constant Integer := Last_Switches.Last;
2084 for Index in 1 .. Last loop
2085 if Last_Switches.Table (Index)
2086 (Last_Switches.Table (Index)'First) /= '-'
2088 File_Index := Index;
2093 -- If the naming scheme of the project file is not standard,
2094 -- and if the file name ends with the spec suffix, then
2095 -- indicate to gnatstub the name of the body file with
2098 if Body_Suffix_Id_Of (Project_Tree, "ada", Data.Naming) /=
2099 Prj.Default_Ada_Spec_Suffix
2101 if File_Index /= 0 then
2103 Spec : constant String :=
2104 Base_Name (Last_Switches.Table (File_Index).all);
2105 Last : Natural := Spec'Last;
2110 (Project_Tree, "ada", Data.Naming));
2112 if Spec'Length > Name_Len
2113 and then Spec (Last - Name_Len + 1 .. Last) =
2114 Name_Buffer (1 .. Name_Len)
2116 Last := Last - Name_Len;
2119 (Project_Tree, "ada", Data.Naming));
2120 Last_Switches.Increment_Last;
2121 Last_Switches.Table (Last_Switches.Last) :=
2123 Last_Switches.Increment_Last;
2124 Last_Switches.Table (Last_Switches.Last) :=
2125 new String'(Spec (Spec'First .. Last) &
2126 Name_Buffer (1 .. Name_Len));
2132 -- Add the directory of the spec as the destination directory
2133 -- of the body, if there is no destination directory already
2136 if File_Index /= 0 then
2137 for Index in File_Index + 1 .. Last loop
2138 if Last_Switches.Table (Index)
2139 (Last_Switches.Table (Index)'First) /= '-'
2146 if Dir_Index = 0 then
2147 Last_Switches.Increment_Last;
2148 Last_Switches.Table (Last_Switches.Last) :=
2150 (Dir_Name (Last_Switches.Table (File_Index).all));
2156 -- For gnatmetric, the generated files should be put in the object
2157 -- directory. This must be the first switch, because it may be
2158 -- overriden by a switch in package Metrics in the project file or by
2159 -- a command line option.
2161 if The_Command = Metric then
2162 First_Switches.Increment_Last;
2163 First_Switches.Table (2 .. First_Switches.Last) :=
2164 First_Switches.Table (1 .. First_Switches.Last - 1);
2165 First_Switches.Table (1) :=
2168 (Project_Tree.Projects.Table
2169 (Project).Object_Directory));
2172 -- For gnat check, -rules and the following switches need to be the
2173 -- last options. So, we move all these switches to table
2176 if The_Command = Check then
2179 -- Set to rank of options preceding "-rules"
2181 In_Rules_Switches : Boolean;
2182 -- Set to True when options "-rules" is found
2185 New_Last := First_Switches.Last;
2186 In_Rules_Switches := False;
2188 for J in 1 .. First_Switches.Last loop
2189 if In_Rules_Switches then
2190 Add_To_Rules_Switches (First_Switches.Table (J));
2192 elsif First_Switches.Table (J).all = "-rules" then
2194 In_Rules_Switches := True;
2198 if In_Rules_Switches then
2199 First_Switches.Set_Last (New_Last);
2202 New_Last := Last_Switches.Last;
2203 In_Rules_Switches := False;
2205 for J in 1 .. Last_Switches.Last loop
2206 if In_Rules_Switches then
2207 Add_To_Rules_Switches (Last_Switches.Table (J));
2209 elsif Last_Switches.Table (J).all = "-rules" then
2211 In_Rules_Switches := True;
2215 if In_Rules_Switches then
2216 Last_Switches.Set_Last (New_Last);
2221 -- For gnat check, metric or pretty with -U + a main, get the list
2222 -- of sources from the closure and add them to the arguments.
2224 if ASIS_Main /= null then
2227 -- On VMS, set up again the env var for source dirs file. This is
2228 -- because the call to gnatmake has set this env var to another
2229 -- file that has now been deleted.
2231 if Hostparm.OpenVMS then
2233 (Project_Include_Path_File,
2234 Prj.Env.Ada_Include_Path
2235 (Project, Project_Tree, Recursive => True));
2238 -- For gnat check, gnat pretty, gnat metric, gnat list, and gnat
2239 -- stack, if no file has been put on the command line, call tool
2240 -- with all the sources of the main project.
2242 elsif The_Command = Check or else
2243 The_Command = Pretty or else
2244 The_Command = Metric or else
2245 The_Command = List or else
2252 -- Gather all the arguments and invoke the executable
2255 The_Args : Argument_List
2256 (1 .. First_Switches.Last +
2257 Last_Switches.Last +
2258 Carg_Switches.Last +
2259 Rules_Switches.Last);
2260 Arg_Num : Natural := 0;
2263 for J in 1 .. First_Switches.Last loop
2264 Arg_Num := Arg_Num + 1;
2265 The_Args (Arg_Num) := First_Switches.Table (J);
2268 for J in 1 .. Last_Switches.Last loop
2269 Arg_Num := Arg_Num + 1;
2270 The_Args (Arg_Num) := Last_Switches.Table (J);
2273 for J in 1 .. Carg_Switches.Last loop
2274 Arg_Num := Arg_Num + 1;
2275 The_Args (Arg_Num) := Carg_Switches.Table (J);
2278 for J in 1 .. Rules_Switches.Last loop
2279 Arg_Num := Arg_Num + 1;
2280 The_Args (Arg_Num) := Rules_Switches.Table (J);
2283 -- If Display_Command is on, only display the generated command
2285 if Display_Command then
2286 Put (Standard_Error, "generated command -->");
2287 Put (Standard_Error, Exec_Path.all);
2289 for Arg in The_Args'Range loop
2290 Put (Standard_Error, " ");
2291 Put (Standard_Error, The_Args (Arg).all);
2294 Put (Standard_Error, "<--");
2295 New_Line (Standard_Error);
2299 if Verbose_Mode then
2300 Output.Write_Str (Exec_Path.all);
2302 for Arg in The_Args'Range loop
2303 Output.Write_Char (' ');
2304 Output.Write_Str (The_Args (Arg).all);
2311 Exit_Status (Spawn (Exec_Path.all, The_Args));
2318 if not Keep_Temporary_Files then
2319 Prj.Env.Delete_All_Path_Files (Project_Tree);
2320 Delete_Temp_Config_Files;
2323 Set_Exit_Status (Failure);
2326 if not Keep_Temporary_Files then
2327 Prj.Env.Delete_All_Path_Files (Project_Tree);
2328 Delete_Temp_Config_Files;
2331 -- Since GNATCmd is normally called from DCL (the VMS shell), it must
2332 -- return an understandable VMS exit status. However the exit status
2333 -- returned *to* GNATCmd is a Posix style code, so we test it and return
2334 -- just a simple success or failure on VMS.
2336 if Hostparm.OpenVMS and then My_Exit_Status /= Success then
2337 Set_Exit_Status (Failure);
2339 Set_Exit_Status (My_Exit_Status);