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 subtype SA is String_Access;
123 Naming_String : constant SA := new String'("naming");
124 Binder_String : constant SA := new String'("binder");
125 Compiler_String : constant SA := new String'("compiler");
126 Check_String : constant SA := new String'("check");
127 Synchronize_String : constant SA := new String'("synchronize");
128 Eliminate_String : constant SA := new String'("eliminate");
129 Finder_String : constant SA := new String'("finder");
130 Linker_String : constant SA := new String'("linker");
131 Gnatls_String : constant SA := new String'("gnatls");
132 Pretty_String : constant SA := new String'("pretty_printer");
133 Stack_String : constant SA := new String'("stack");
134 Gnatstub_String : constant SA := new String'("gnatstub");
135 Metric_String : constant SA := new String'("metrics");
136 Xref_String : constant SA := new String'("cross_reference");
138 Packages_To_Check_By_Binder : constant String_List_Access :=
139 new String_List'((Naming_String, Binder_String));
141 Packages_To_Check_By_Check : constant String_List_Access :=
142 new String_List'((Naming_String, Check_String, Compiler_String));
144 Packages_To_Check_By_Sync : constant String_List_Access :=
145 new String_List'((Naming_String, Synchronize_String, Compiler_String));
147 Packages_To_Check_By_Eliminate : constant String_List_Access :=
148 new String_List'((Naming_String, Eliminate_String, Compiler_String));
150 Packages_To_Check_By_Finder : constant String_List_Access :=
151 new String_List'((Naming_String, Finder_String));
153 Packages_To_Check_By_Linker : constant String_List_Access :=
154 new String_List'((Naming_String, Linker_String));
156 Packages_To_Check_By_Gnatls : constant String_List_Access :=
157 new String_List'((Naming_String, Gnatls_String));
159 Packages_To_Check_By_Pretty : constant String_List_Access :=
160 new String_List'((Naming_String, Pretty_String, Compiler_String));
162 Packages_To_Check_By_Stack : constant String_List_Access :=
163 new String_List'((Naming_String, Stack_String));
165 Packages_To_Check_By_Gnatstub : constant String_List_Access :=
166 new String_List'((Naming_String, Gnatstub_String, Compiler_String));
168 Packages_To_Check_By_Metric : constant String_List_Access :=
169 new String_List'((Naming_String, Metric_String, Compiler_String));
171 Packages_To_Check_By_Xref : constant String_List_Access :=
172 new String_List'((Naming_String, Xref_String));
174 Packages_To_Check : String_List_Access := Prj.All_Packages;
176 ----------------------------------
177 -- Declarations for GNATCMD use --
178 ----------------------------------
180 The_Command : Command_Type;
181 -- The command specified in the invocation of the GNAT driver
183 Command_Arg : Positive := 1;
184 -- The index of the command in the arguments of the GNAT driver
186 My_Exit_Status : Exit_Status := Success;
187 -- The exit status of the spawned tool. Used to set the correct VMS
190 Current_Work_Dir : constant String := Get_Current_Dir;
191 -- The path of the working directory
193 All_Projects : Boolean := False;
194 -- Flag used for GNAT CHECK, GNAT PRETTY, GNAT METRIC, and GNAT STACK to
195 -- indicate that the underlying tool (gnatcheck, gnatpp or gnatmetric)
196 -- should be invoked for all sources of all projects.
198 -----------------------
199 -- Local Subprograms --
200 -----------------------
202 procedure Add_To_Carg_Switches (Switch : String_Access);
203 -- Add a switch to the Carg_Switches table. If it is the first one, put the
204 -- switch "-cargs" at the beginning of the table.
206 procedure Add_To_Rules_Switches (Switch : String_Access);
207 -- Add a switch to the Rules_Switches table. If it is the first one, put
208 -- the switch "-crules" at the beginning of the table.
210 procedure Check_Files;
211 -- For GNAT LIST, GNAT PRETTY, GNAT METRIC, and GNAT STACK, check if a
212 -- project file is specified, without any file arguments. If it is the
213 -- case, invoke the GNAT tool with the proper list of files, derived from
214 -- the sources of the project.
216 function Check_Project
217 (Project : Project_Id;
218 Root_Project : Project_Id) return Boolean;
219 -- Returns True if Project = Root_Project or if we want to consider all
220 -- sources of all projects. For GNAT METRIC, also returns True if Project
221 -- is extended by Root_Project.
223 procedure Check_Relative_Executable (Name : in out String_Access);
224 -- Check if an executable is specified as a relative path. If it is, and
225 -- the path contains directory information, fail. Otherwise, prepend the
226 -- exec directory. This procedure is only used for GNAT LINK when a project
227 -- file is specified.
229 function Configuration_Pragmas_File return Path_Name_Type;
230 -- Return an argument, if there is a configuration pragmas file to be
231 -- specified for Project, otherwise return No_Name. Used for gnatstub (GNAT
232 -- STUB), gnatpp (GNAT PRETTY), gnatelim (GNAT ELIM), and gnatmetric (GNAT
235 procedure Delete_Temp_Config_Files;
236 -- Delete all temporary config files
238 procedure Get_Closure;
239 -- Get the sources in the closure of the ASIS_Main and add them to the
240 -- list of arguments.
242 function Index (Char : Character; Str : String) return Natural;
243 -- Returns first occurrence of Char in Str, returns 0 if Char not in Str
245 procedure Non_VMS_Usage;
246 -- Display usage for platforms other than VMS
248 procedure Process_Link;
249 -- Process GNAT LINK, when there is a project file specified
251 procedure Set_Library_For
252 (Project : Project_Id;
253 There_Are_Libraries : in out Boolean);
254 -- If Project is a library project, add the correct -L and -l switches to
255 -- the linker invocation.
257 procedure Set_Libraries is
258 new For_Every_Project_Imported (Boolean, Set_Library_For);
259 -- Add the -L and -l switches to the linker for all of the library
262 procedure Test_If_Relative_Path
263 (Switch : in out String_Access;
265 -- Test if Switch is a relative search path switch. If it is and it
266 -- includes directory information, prepend the path with Parent. This
267 -- subprogram is only called when using project files.
269 --------------------------
270 -- Add_To_Carg_Switches --
271 --------------------------
273 procedure Add_To_Carg_Switches (Switch : String_Access) is
275 -- If the Carg_Switches table is empty, put "-cargs" at the beginning
277 if Carg_Switches.Last = 0 then
278 Carg_Switches.Increment_Last;
279 Carg_Switches.Table (Carg_Switches.Last) := new String'("-cargs");
282 Carg_Switches.Increment_Last;
283 Carg_Switches.Table (Carg_Switches.Last) := Switch;
284 end Add_To_Carg_Switches;
286 ---------------------------
287 -- Add_To_Rules_Switches --
288 ---------------------------
290 procedure Add_To_Rules_Switches (Switch : String_Access) is
292 -- If the Rules_Switches table is empty, put "-rules" at the beginning
294 if Rules_Switches.Last = 0 then
295 Rules_Switches.Increment_Last;
296 Rules_Switches.Table (Rules_Switches.Last) := new String'("-rules");
299 Rules_Switches.Increment_Last;
300 Rules_Switches.Table (Rules_Switches.Last) := Switch;
301 end Add_To_Rules_Switches;
307 procedure Check_Files is
308 Add_Sources : Boolean := True;
309 Unit_Data : Prj.Unit_Data;
310 Subunit : Boolean := False;
313 -- Check if there is at least one argument that is not a switch
315 for Index in 1 .. Last_Switches.Last loop
316 if Last_Switches.Table (Index) (1) /= '-' then
317 Add_Sources := False;
322 -- If all arguments were switches, add the path names of all the sources
323 -- of the main project.
327 Current_Last : constant Integer := Last_Switches.Last;
329 -- Gnatstack needs to add the the .ci file for the binder
330 -- generated files corresponding to all of the library projects
331 -- and main units belonging to the application.
333 if The_Command = Stack then
334 for Proj in Project_Table.First ..
335 Project_Table.Last (Project_Tree.Projects)
337 if Check_Project (Proj, Project) then
339 Data : Project_Data renames
340 Project_Tree.Projects.Table (Proj);
341 Main : String_List_Id := Data.Mains;
342 File : String_Access;
345 -- Include binder generated files for main programs
347 while Main /= Nil_String loop
350 (Get_Name_String (Data.Object_Directory) &
351 Directory_Separator &
355 (Project_Tree.String_Elements.Table
359 if Is_Regular_File (File.all) then
360 Last_Switches.Increment_Last;
361 Last_Switches.Table (Last_Switches.Last) := File;
365 Project_Tree.String_Elements.Table (Main).Next;
370 -- Include the .ci file for the binder generated
371 -- files that contains the initialization and
372 -- finalization of the library.
376 (Get_Name_String (Data.Object_Directory) &
377 Directory_Separator &
379 Get_Name_String (Data.Library_Name) &
382 if Is_Regular_File (File.all) then
383 Last_Switches.Increment_Last;
384 Last_Switches.Table (Last_Switches.Last) := File;
392 for Unit in Unit_Table.First ..
393 Unit_Table.Last (Project_Tree.Units)
395 Unit_Data := Project_Tree.Units.Table (Unit);
397 -- For gnatls, we only need to put the library units, body or
398 -- spec, but not the subunits.
400 if The_Command = List then
402 Unit_Data.File_Names (Body_Part).Name /= No_File
404 Unit_Data.File_Names (Body_Part).Path /= Slash
406 -- There is a body, check if it is for this project
408 if All_Projects or else
409 Unit_Data.File_Names (Body_Part).Project = Project
414 Unit_Data.File_Names (Specification).Name = No_File
416 Unit_Data.File_Names (Specification).Path = Slash
418 -- We have a body with no spec: we need to check if
419 -- this is a subunit, because gnatls will complain
423 Src_Ind : Source_File_Index;
426 Src_Ind := Sinput.P.Load_Project_File
428 (Unit_Data.File_Names
432 Sinput.P.Source_File_Is_Subunit
438 Last_Switches.Increment_Last;
439 Last_Switches.Table (Last_Switches.Last) :=
442 (Unit_Data.File_Names
443 (Body_Part).Display_Name));
448 Unit_Data.File_Names (Specification).Name /= No_File
450 Unit_Data.File_Names (Specification).Path /= Slash
452 -- We have a spec with no body; check if it is for this
455 if All_Projects or else
456 Unit_Data.File_Names (Specification).Project = Project
458 Last_Switches.Increment_Last;
459 Last_Switches.Table (Last_Switches.Last) :=
462 (Unit_Data.File_Names
463 (Specification).Display_Name));
467 -- For gnatstack, we put the .ci files corresponding to the
468 -- different units, including the binder generated files. We
469 -- only need to do that for the library units, body or spec,
470 -- but not the subunits.
472 elsif The_Command = Stack then
474 Unit_Data.File_Names (Body_Part).Name /= No_File
476 Unit_Data.File_Names (Body_Part).Path /= Slash
478 -- There is a body. Check if .ci files for this project
483 (Unit_Data.File_Names (Body_Part).Project, Project)
488 Unit_Data.File_Names (Specification).Name = No_File
490 Unit_Data.File_Names (Specification).Path = Slash
492 -- We have a body with no spec: we need to check
493 -- if this is a subunit, because .ci files are not
494 -- generated for subunits.
497 Src_Ind : Source_File_Index;
500 Src_Ind := Sinput.P.Load_Project_File
502 (Unit_Data.File_Names (Body_Part).Path));
505 Sinput.P.Source_File_Is_Subunit (Src_Ind);
510 Last_Switches.Increment_Last;
511 Last_Switches.Table (Last_Switches.Last) :=
514 (Project_Tree.Projects.Table
515 (Unit_Data.File_Names
516 (Body_Part).Project).
518 Directory_Separator &
521 (Unit_Data.File_Names
522 (Body_Part).Display_Name),
528 Unit_Data.File_Names (Specification).Name /= No_File
530 Unit_Data.File_Names (Specification).Path /= Slash
532 -- We have a spec with no body. Check if it is for this
537 (Unit_Data.File_Names (Specification).Project,
540 Last_Switches.Increment_Last;
541 Last_Switches.Table (Last_Switches.Last) :=
544 (Project_Tree.Projects.Table
545 (Unit_Data.File_Names
546 (Specification).Project).
551 (Unit_Data.File_Names
552 (Specification).Name),
558 -- For gnatcheck, gnatsync, gnatpp and gnatmetric, put all
559 -- sources of the project, or of all projects if -U was
562 for Kind in Spec_Or_Body loop
564 (Unit_Data.File_Names (Kind).Project, Project)
565 and then Unit_Data.File_Names (Kind).Name /= No_File
566 and then Unit_Data.File_Names (Kind).Path /= Slash
568 Last_Switches.Increment_Last;
569 Last_Switches.Table (Last_Switches.Last) :=
572 (Unit_Data.File_Names
573 (Kind).Display_Path));
579 -- If the list of files is too long, create a temporary text file
580 -- that lists these files, and pass this temp file to gnatcheck,
581 -- gnatpp or gnatmetric using switch -files=.
583 if Last_Switches.Last - Current_Last >
584 Max_Files_On_The_Command_Line
587 Temp_File_FD : File_Descriptor;
588 Buffer : String (1 .. 1_000);
590 OK : Boolean := True;
593 Create_Temp_File (Temp_File_FD, Temp_File_Name);
595 if Temp_File_Name /= null then
596 for Index in Current_Last + 1 ..
599 Len := Last_Switches.Table (Index)'Length;
600 Buffer (1 .. Len) := Last_Switches.Table (Index).all;
602 Buffer (Len) := ASCII.LF;
603 Buffer (Len + 1) := ASCII.NUL;
612 Close (Temp_File_FD, OK);
614 Close (Temp_File_FD, OK);
618 -- If there were any problem creating the temp file, then
619 -- pass the list of files.
623 -- Replace list of files with -files=<temp file name>
625 Last_Switches.Set_Last (Current_Last + 1);
626 Last_Switches.Table (Last_Switches.Last) :=
627 new String'("-files=" & Temp_File_Name.all);
640 function Check_Project
641 (Project : Project_Id;
642 Root_Project : Project_Id) return Boolean
645 if Project = No_Project then
648 elsif All_Projects or Project = Root_Project then
651 elsif The_Command = Metric then
656 Data := Project_Tree.Projects.Table (Root_Project);
657 while Data.Extends /= No_Project loop
658 if Project = Data.Extends then
662 Data := Project_Tree.Projects.Table (Data.Extends);
670 -------------------------------
671 -- Check_Relative_Executable --
672 -------------------------------
674 procedure Check_Relative_Executable (Name : in out String_Access) is
675 Exec_File_Name : constant String := Name.all;
678 if not Is_Absolute_Path (Exec_File_Name) then
679 for Index in Exec_File_Name'Range loop
680 if Exec_File_Name (Index) = Directory_Separator then
681 Fail ("relative executable (""" &
683 """) with directory part not allowed " &
684 "when using project files");
688 Get_Name_String (Project_Tree.Projects.Table
689 (Project).Exec_Directory);
691 if Name_Buffer (Name_Len) /= Directory_Separator then
692 Name_Len := Name_Len + 1;
693 Name_Buffer (Name_Len) := Directory_Separator;
696 Name_Buffer (Name_Len + 1 ..
697 Name_Len + Exec_File_Name'Length) :=
699 Name_Len := Name_Len + Exec_File_Name'Length;
700 Name := new String'(Name_Buffer (1 .. Name_Len));
702 end Check_Relative_Executable;
704 --------------------------------
705 -- Configuration_Pragmas_File --
706 --------------------------------
708 function Configuration_Pragmas_File return Path_Name_Type is
710 Prj.Env.Create_Config_Pragmas_File
711 (Project, Project, Project_Tree, Include_Config_Files => False);
712 return Project_Tree.Projects.Table (Project).Config_File_Name;
713 end Configuration_Pragmas_File;
715 ------------------------------
716 -- Delete_Temp_Config_Files --
717 ------------------------------
719 procedure Delete_Temp_Config_Files is
721 pragma Warnings (Off, Success);
724 if not Keep_Temporary_Files then
725 if Project /= No_Project then
726 for Prj in Project_Table.First ..
727 Project_Table.Last (Project_Tree.Projects)
730 Project_Tree.Projects.Table (Prj).Config_File_Temp
733 Output.Write_Str ("Deleting temp configuration file """);
736 (Project_Tree.Projects.Table
737 (Prj).Config_File_Name));
738 Output.Write_Line ("""");
742 (Name => Get_Name_String
743 (Project_Tree.Projects.Table
744 (Prj).Config_File_Name),
750 -- If a temporary text file that contains a list of files for a tool
751 -- has been created, delete this temporary file.
753 if Temp_File_Name /= null then
754 Delete_File (Temp_File_Name.all, Success);
757 end Delete_Temp_Config_Files;
763 procedure Get_Closure is
764 Args : constant Argument_List :=
765 (1 => new String'("-q"),
766 2 => new String'("-b"),
767 3 => new String'("-P"),
770 6 => new String'("-bargs"),
771 7 => new String'("-R"),
772 8 => new String'("-Z"));
773 -- Arguments of the invocation of gnatmake to get the list of
775 FD : File_Descriptor;
776 -- File descriptor for the temp file that will get the output of the
777 -- invocation of gnatmake.
779 Name : Path_Name_Type;
780 -- Path of the file FD
782 GN_Name : constant String := Program_Name ("gnatmake").all;
785 GN_Path : constant String_Access := Locate_Exec_On_Path (GN_Name);
788 Return_Code : Integer;
791 pragma Warnings (Off, Unused);
793 File : Ada.Text_IO.File_Type;
794 Line : String (1 .. 250);
798 Path : Path_Name_Type;
801 if GN_Path = null then
802 Put_Line (Standard_Error, "could not locate " & GN_Name);
806 -- Create the temp file
808 Tempdir.Create_Temp_File (FD, Name);
810 -- And close it, because on VMS Spawn with a file descriptor created
811 -- with Create_Temp_File does not redirect output.
815 -- Spawn "gnatmake -q -b -P <project> <main> -bargs -R -Z"
818 (Program_Name => GN_Path.all,
820 Output_File => Get_Name_String (Name),
822 Return_Code => Return_Code,
827 -- Read the output of the invocation of gnatmake
829 Open (File, In_File, Get_Name_String (Name));
831 -- If it was unsuccessful, display the first line in the file and exit
834 if Return_Code /= 0 then
835 Get_Line (File, Line, Last);
837 if not Keep_Temporary_Files then
843 Put_Line (Standard_Error, Line (1 .. Last));
845 (Standard_Error, "could not get closure of " & ASIS_Main.all);
849 -- Get each file name in the file, find its path and add it the the
850 -- list of arguments.
852 while not End_Of_File (File) loop
853 Get_Line (File, Line, Last);
856 for Unit in Unit_Table.First ..
857 Unit_Table.Last (Project_Tree.Units)
859 Udata := Project_Tree.Units.Table (Unit);
861 if Udata.File_Names (Specification).Name /= No_File
863 Get_Name_String (Udata.File_Names (Specification).Name) =
866 Path := Udata.File_Names (Specification).Path;
869 elsif Udata.File_Names (Body_Part).Name /= No_File
871 Get_Name_String (Udata.File_Names (Body_Part).Name) =
874 Path := Udata.File_Names (Body_Part).Path;
879 Last_Switches.Increment_Last;
881 if Path /= No_Path then
882 Last_Switches.Table (Last_Switches.Last) :=
883 new String'(Get_Name_String (Path));
886 Last_Switches.Table (Last_Switches.Last) :=
887 new String'(Line (1 .. Last));
891 if not Keep_Temporary_Files then
904 function Index (Char : Character; Str : String) return Natural is
906 for Index in Str'Range loop
907 if Str (Index) = Char then
919 procedure Process_Link is
920 Look_For_Executable : Boolean := True;
921 There_Are_Libraries : Boolean := False;
922 Path_Option : constant String_Access :=
923 MLib.Linker_Library_Path_Option;
924 Prj : Project_Id := Project;
927 Skip_Executable : Boolean := False;
930 -- Add the default search directories, to be able to find
931 -- libgnat in call to MLib.Utl.Lib_Directory.
933 Add_Default_Search_Dirs;
935 Library_Paths.Set_Last (0);
937 -- Check if there are library project files
939 if MLib.Tgt.Support_For_Libraries /= None then
940 Set_Libraries (Project, Project_Tree, There_Are_Libraries);
943 -- If there are, add the necessary additional switches
945 if There_Are_Libraries then
947 -- Add -L<lib_dir> -lgnarl -lgnat -Wl,-rpath,<lib_dir>
949 Last_Switches.Increment_Last;
950 Last_Switches.Table (Last_Switches.Last) :=
951 new String'("-L" & MLib.Utl.Lib_Directory);
952 Last_Switches.Increment_Last;
953 Last_Switches.Table (Last_Switches.Last) :=
954 new String'("-lgnarl");
955 Last_Switches.Increment_Last;
956 Last_Switches.Table (Last_Switches.Last) :=
957 new String'("-lgnat");
959 -- If Path_Option is not null, create the switch ("-Wl,-rpath," or
960 -- equivalent) with all the library dirs plus the standard GNAT
963 if Path_Option /= null then
965 Option : String_Access;
966 Length : Natural := Path_Option'Length;
970 -- First, compute the exact length for the switch
973 Library_Paths.First .. Library_Paths.Last
975 -- Add the length of the library dir plus one for the
976 -- directory separator.
980 Library_Paths.Table (Index)'Length + 1;
983 -- Finally, add the length of the standard GNAT library dir
985 Length := Length + MLib.Utl.Lib_Directory'Length;
986 Option := new String (1 .. Length);
987 Option (1 .. Path_Option'Length) := Path_Option.all;
988 Current := Path_Option'Length;
990 -- Put each library dir followed by a dir separator
993 Library_Paths.First .. Library_Paths.Last
998 Library_Paths.Table (Index)'Length) :=
999 Library_Paths.Table (Index).all;
1002 Library_Paths.Table (Index)'Length + 1;
1003 Option (Current) := Path_Separator;
1006 -- Finally put the standard GNAT library dir
1010 Current + MLib.Utl.Lib_Directory'Length) :=
1011 MLib.Utl.Lib_Directory;
1013 -- And add the switch to the last switches
1015 Last_Switches.Increment_Last;
1016 Last_Switches.Table (Last_Switches.Last) :=
1022 -- Check if the first ALI file specified can be found, either in the
1023 -- object directory of the main project or in an object directory of a
1024 -- project file extended by the main project. If the ALI file can be
1025 -- found, replace its name with its absolute path.
1027 Skip_Executable := False;
1029 Switch_Loop : for J in 1 .. Last_Switches.Last loop
1031 -- If we have an executable just reset the flag
1033 if Skip_Executable then
1034 Skip_Executable := False;
1036 -- If -o, set flag so that next switch is not processed
1038 elsif Last_Switches.Table (J).all = "-o" then
1039 Skip_Executable := True;
1045 Switch : constant String :=
1046 Last_Switches.Table (J).all;
1048 ALI_File : constant String (1 .. Switch'Length + 4) :=
1051 Test_Existence : Boolean := False;
1054 Last := Switch'Length;
1056 -- Skip real switches
1058 if Switch'Length /= 0
1059 and then Switch (Switch'First) /= '-'
1061 -- Append ".ali" if file name does not end with it
1063 if Switch'Length <= 4
1064 or else Switch (Switch'Last - 3 .. Switch'Last)
1067 Last := ALI_File'Last;
1070 -- If file name includes directory information, stop if ALI
1073 if Is_Absolute_Path (ALI_File (1 .. Last)) then
1074 Test_Existence := True;
1077 for K in Switch'Range loop
1078 if Switch (K) = '/' or else
1079 Switch (K) = Directory_Separator
1081 Test_Existence := True;
1087 if Test_Existence then
1088 if Is_Regular_File (ALI_File (1 .. Last)) then
1092 -- Look in object directories if ALI file exists
1097 Dir : constant String :=
1099 (Project_Tree.Projects.Table
1100 (Prj).Object_Directory);
1104 Directory_Separator &
1105 ALI_File (1 .. Last))
1107 -- We have found the correct project, so we
1108 -- replace the file with the absolute path.
1110 Last_Switches.Table (J) :=
1112 (Dir & Directory_Separator &
1113 ALI_File (1 .. Last));
1121 -- Go to the project being extended, if any
1124 Project_Tree.Projects.Table (Prj).Extends;
1125 exit Project_Loop when Prj = No_Project;
1126 end loop Project_Loop;
1131 end loop Switch_Loop;
1133 -- If a relative path output file has been specified, we add the exec
1136 for J in reverse 1 .. Last_Switches.Last - 1 loop
1137 if Last_Switches.Table (J).all = "-o" then
1138 Check_Relative_Executable
1139 (Name => Last_Switches.Table (J + 1));
1140 Look_For_Executable := False;
1145 if Look_For_Executable then
1146 for J in reverse 1 .. First_Switches.Last - 1 loop
1147 if First_Switches.Table (J).all = "-o" then
1148 Look_For_Executable := False;
1149 Check_Relative_Executable
1150 (Name => First_Switches.Table (J + 1));
1156 -- If no executable is specified, then find the name of the first ALI
1157 -- file on the command line and issue a -o switch with the absolute path
1158 -- of the executable in the exec directory.
1160 if Look_For_Executable then
1161 for J in 1 .. Last_Switches.Last loop
1162 Arg := Last_Switches.Table (J);
1165 if Arg'Length /= 0 and then Arg (Arg'First) /= '-' then
1167 and then Arg (Arg'Last - 3 .. Arg'Last) = ".ali"
1169 Last := Arg'Last - 4;
1171 elsif Is_Regular_File (Arg.all & ".ali") then
1176 Last_Switches.Increment_Last;
1177 Last_Switches.Table (Last_Switches.Last) :=
1180 (Project_Tree.Projects.Table
1181 (Project).Exec_Directory);
1182 Last_Switches.Increment_Last;
1183 Last_Switches.Table (Last_Switches.Last) :=
1184 new String'(Name_Buffer (1 .. Name_Len) &
1185 Directory_Separator &
1187 (Base_Name (Arg (Arg'First .. Last))));
1195 ---------------------
1196 -- Set_Library_For --
1197 ---------------------
1199 procedure Set_Library_For
1200 (Project : Project_Id;
1201 There_Are_Libraries : in out Boolean)
1203 Path_Option : constant String_Access :=
1204 MLib.Linker_Library_Path_Option;
1207 -- Case of library project
1209 if Project_Tree.Projects.Table (Project).Library then
1210 There_Are_Libraries := True;
1212 -- Add the -L switch
1214 Last_Switches.Increment_Last;
1215 Last_Switches.Table (Last_Switches.Last) :=
1218 (Project_Tree.Projects.Table
1219 (Project).Library_Dir));
1221 -- Add the -l switch
1223 Last_Switches.Increment_Last;
1224 Last_Switches.Table (Last_Switches.Last) :=
1227 (Project_Tree.Projects.Table
1228 (Project).Library_Name));
1230 -- Add the directory to table Library_Paths, to be processed later
1231 -- if library is not static and if Path_Option is not null.
1233 if Project_Tree.Projects.Table (Project).Library_Kind /=
1235 and then Path_Option /= null
1237 Library_Paths.Increment_Last;
1238 Library_Paths.Table (Library_Paths.Last) :=
1239 new String'(Get_Name_String
1240 (Project_Tree.Projects.Table
1241 (Project).Library_Dir));
1244 end Set_Library_For;
1246 ---------------------------
1247 -- Test_If_Relative_Path --
1248 ---------------------------
1250 procedure Test_If_Relative_Path
1251 (Switch : in out String_Access;
1255 if Switch /= null then
1258 Sw : String (1 .. Switch'Length);
1259 Start : Positive := 1;
1264 if Sw (1) = '-' then
1266 and then (Sw (2) = 'A' or else
1267 Sw (2) = 'I' or else
1276 elsif Sw'Length >= 4
1277 and then (Sw (2 .. 3) = "aL" or else
1278 Sw (2 .. 3) = "aO" or else
1283 elsif Sw'Length >= 7
1284 and then Sw (2 .. 6) = "-RTS="
1292 -- If the path is relative, test if it includes directory
1293 -- information. If it does, prepend Parent to the path.
1295 if not Is_Absolute_Path (Sw (Start .. Sw'Last)) then
1296 for J in Start .. Sw'Last loop
1297 if Sw (J) = Directory_Separator then
1300 (Sw (1 .. Start - 1) &
1302 Directory_Separator &
1303 Sw (Start .. Sw'Last));
1310 end Test_If_Relative_Path;
1316 procedure Non_VMS_Usage is
1320 Put_Line ("List of available commands");
1323 for C in Command_List'Range loop
1324 if not Command_List (C).VMS_Only then
1325 Put ("gnat " & To_Lower (Command_List (C).Cname.all));
1327 Put (Command_List (C).Unixcmd.all);
1330 Sws : Argument_List_Access renames Command_List (C).Unixsws;
1333 for J in Sws'Range loop
1345 Put_Line ("Commands find, list, metric, pretty, stack, stub and xref " &
1346 "accept project file switches -vPx, -Pprj and -Xnam=val");
1350 -------------------------------------
1351 -- Start of processing for GNATCmd --
1352 -------------------------------------
1362 Prj.Initialize (Project_Tree);
1365 Last_Switches.Set_Last (0);
1367 First_Switches.Init;
1368 First_Switches.Set_Last (0);
1370 Carg_Switches.Set_Last (0);
1371 Rules_Switches.Init;
1372 Rules_Switches.Set_Last (0);
1374 VMS_Conv.Initialize;
1376 Set_Mode (Ada_Only);
1378 -- Add the directory where the GNAT driver is invoked in front of the path,
1379 -- if the GNAT driver is invoked with directory information. Do not do this
1380 -- for VMS, where the notion of path does not really exist.
1384 Command : constant String := Command_Name;
1387 for Index in reverse Command'Range loop
1388 if Command (Index) = Directory_Separator then
1390 Absolute_Dir : constant String :=
1392 (Command (Command'First .. Index));
1394 PATH : constant String :=
1397 Getenv ("PATH").all;
1400 Setenv ("PATH", PATH);
1409 -- If on VMS, or if VMS emulation is on, convert VMS style /qualifiers,
1410 -- filenames and pathnames to Unix style.
1413 or else To_Lower (Getenv ("EMULATE_VMS").all) = "true"
1415 VMS_Conversion (The_Command);
1417 B_Start := new String'("b__");
1419 -- If not on VMS, scan the command line directly
1422 if Argument_Count = 0 then
1428 if Argument_Count > Command_Arg
1429 and then Argument (Command_Arg) = "-v"
1431 Verbose_Mode := True;
1432 Command_Arg := Command_Arg + 1;
1434 elsif Argument_Count > Command_Arg
1435 and then Argument (Command_Arg) = "-dn"
1437 Keep_Temporary_Files := True;
1438 Command_Arg := Command_Arg + 1;
1445 The_Command := Real_Command_Type'Value (Argument (Command_Arg));
1447 if Command_List (The_Command).VMS_Only then
1451 Command_List (The_Command).Cname.all,
1452 """ can only be used on VMS");
1456 when Constraint_Error =>
1458 -- Check if it is an alternate command
1461 Alternate : Alternate_Command;
1464 Alternate := Alternate_Command'Value
1465 (Argument (Command_Arg));
1466 The_Command := Corresponding_To (Alternate);
1469 when Constraint_Error =>
1471 Fail ("Unknown command: ", Argument (Command_Arg));
1475 -- Get the arguments from the command line and from the eventual
1476 -- argument file(s) specified on the command line.
1478 for Arg in Command_Arg + 1 .. Argument_Count loop
1480 The_Arg : constant String := Argument (Arg);
1483 -- Check if an argument file is specified
1485 if The_Arg (The_Arg'First) = '@' then
1487 Arg_File : Ada.Text_IO.File_Type;
1488 Line : String (1 .. 256);
1492 -- Open the file and fail if the file cannot be found
1497 The_Arg (The_Arg'First + 1 .. The_Arg'Last));
1502 (Standard_Error, "Cannot open argument file """);
1505 The_Arg (The_Arg'First + 1 .. The_Arg'Last));
1507 Put_Line (Standard_Error, """");
1511 -- Read line by line and put the content of each non-
1512 -- empty line in the Last_Switches table.
1514 while not End_Of_File (Arg_File) loop
1515 Get_Line (Arg_File, Line, Last);
1518 Last_Switches.Increment_Last;
1519 Last_Switches.Table (Last_Switches.Last) :=
1520 new String'(Line (1 .. Last));
1528 -- It is not an argument file; just put the argument in
1529 -- the Last_Switches table.
1531 Last_Switches.Increment_Last;
1532 Last_Switches.Table (Last_Switches.Last) :=
1533 new String'(The_Arg);
1541 Program : constant String :=
1542 Program_Name (Command_List (The_Command).Unixcmd.all).all;
1544 Exec_Path : String_Access;
1547 -- Locate the executable for the command
1549 Exec_Path := Locate_Exec_On_Path (Program);
1551 if Exec_Path = null then
1552 Put_Line (Standard_Error, "could not locate " & Program);
1556 -- If there are switches for the executable, put them as first switches
1558 if Command_List (The_Command).Unixsws /= null then
1559 for J in Command_List (The_Command).Unixsws'Range loop
1560 First_Switches.Increment_Last;
1561 First_Switches.Table (First_Switches.Last) :=
1562 Command_List (The_Command).Unixsws (J);
1566 -- For BIND, CHECK, ELIM, FIND, LINK, LIST, PRETTY, STACK, STUB,
1567 -- METRIC ad XREF, look for project file related switches.
1569 if The_Command = Bind
1570 or else The_Command = Check
1571 or else The_Command = Sync
1572 or else The_Command = Elim
1573 or else The_Command = Find
1574 or else The_Command = Link
1575 or else The_Command = List
1576 or else The_Command = Xref
1577 or else The_Command = Pretty
1578 or else The_Command = Stack
1579 or else The_Command = Stub
1580 or else The_Command = Metric
1584 Tool_Package_Name := Name_Binder;
1585 Packages_To_Check := Packages_To_Check_By_Binder;
1587 Tool_Package_Name := Name_Check;
1588 Packages_To_Check := Packages_To_Check_By_Check;
1590 Tool_Package_Name := Name_Synchronize;
1591 Packages_To_Check := Packages_To_Check_By_Sync;
1593 Tool_Package_Name := Name_Eliminate;
1594 Packages_To_Check := Packages_To_Check_By_Eliminate;
1596 Tool_Package_Name := Name_Finder;
1597 Packages_To_Check := Packages_To_Check_By_Finder;
1599 Tool_Package_Name := Name_Linker;
1600 Packages_To_Check := Packages_To_Check_By_Linker;
1602 Tool_Package_Name := Name_Gnatls;
1603 Packages_To_Check := Packages_To_Check_By_Gnatls;
1605 Tool_Package_Name := Name_Metrics;
1606 Packages_To_Check := Packages_To_Check_By_Metric;
1608 Tool_Package_Name := Name_Pretty_Printer;
1609 Packages_To_Check := Packages_To_Check_By_Pretty;
1611 Tool_Package_Name := Name_Stack;
1612 Packages_To_Check := Packages_To_Check_By_Stack;
1614 Tool_Package_Name := Name_Gnatstub;
1615 Packages_To_Check := Packages_To_Check_By_Gnatstub;
1617 Tool_Package_Name := Name_Cross_Reference;
1618 Packages_To_Check := Packages_To_Check_By_Xref;
1623 -- Check that the switches are consistent. Detect project file
1624 -- related switches.
1628 Arg_Num : Positive := 1;
1629 Argv : String_Access;
1631 procedure Remove_Switch (Num : Positive);
1632 -- Remove a project related switch from table Last_Switches
1638 procedure Remove_Switch (Num : Positive) is
1640 Last_Switches.Table (Num .. Last_Switches.Last - 1) :=
1641 Last_Switches.Table (Num + 1 .. Last_Switches.Last);
1642 Last_Switches.Decrement_Last;
1645 -- Start of processing for Inspect_Switches
1648 while Arg_Num <= Last_Switches.Last loop
1649 Argv := Last_Switches.Table (Arg_Num);
1651 if Argv (Argv'First) = '-' then
1652 if Argv'Length = 1 then
1654 ("switch character cannot be followed by a blank");
1657 -- The two style project files (-p and -P) cannot be used
1660 if (The_Command = Find or else The_Command = Xref)
1661 and then Argv (2) = 'p'
1663 Old_Project_File_Used := True;
1664 if Project_File /= null then
1665 Fail ("-P and -p cannot be used together");
1669 -- -aPdir Add dir to the project search path
1672 and then Argv (Argv'First + 1 .. Argv'First + 2) = "aP"
1674 Add_Search_Project_Directory
1675 (Argv (Argv'First + 3 .. Argv'Last));
1677 Remove_Switch (Arg_Num);
1679 -- -vPx Specify verbosity while parsing project files
1681 elsif Argv'Length = 4
1682 and then Argv (Argv'First + 1 .. Argv'First + 2) = "vP"
1684 case Argv (Argv'Last) is
1686 Current_Verbosity := Prj.Default;
1688 Current_Verbosity := Prj.Medium;
1690 Current_Verbosity := Prj.High;
1692 Fail ("Invalid switch: ", Argv.all);
1695 Remove_Switch (Arg_Num);
1697 -- -Pproject_file Specify project file to be used
1699 elsif Argv (Argv'First + 1) = 'P' then
1701 -- Only one -P switch can be used
1703 if Project_File /= null then
1706 ": second project file forbidden (first is """,
1707 Project_File.all & """)");
1709 -- The two style project files (-p and -P) cannot be
1712 elsif Old_Project_File_Used then
1713 Fail ("-p and -P cannot be used together");
1715 elsif Argv'Length = 2 then
1717 -- There is space between -P and the project file
1718 -- name. -P cannot be the last option.
1720 if Arg_Num = Last_Switches.Last then
1721 Fail ("project file name missing after -P");
1724 Remove_Switch (Arg_Num);
1725 Argv := Last_Switches.Table (Arg_Num);
1727 -- After -P, there must be a project file name,
1728 -- not another switch.
1730 if Argv (Argv'First) = '-' then
1731 Fail ("project file name missing after -P");
1734 Project_File := new String'(Argv.all);
1739 -- No space between -P and project file name
1742 new String'(Argv (Argv'First + 2 .. Argv'Last));
1745 Remove_Switch (Arg_Num);
1747 -- -Xexternal=value Specify an external reference to be
1748 -- used in project files
1750 elsif Argv'Length >= 5
1751 and then Argv (Argv'First + 1) = 'X'
1754 Equal_Pos : constant Natural :=
1757 Argv (Argv'First + 2 .. Argv'Last));
1759 if Equal_Pos >= Argv'First + 3 and then
1760 Equal_Pos /= Argv'Last then
1761 Add (External_Name =>
1762 Argv (Argv'First + 2 .. Equal_Pos - 1),
1763 Value => Argv (Equal_Pos + 1 .. Argv'Last));
1767 " is not a valid external assignment.");
1771 Remove_Switch (Arg_Num);
1774 (The_Command = Check or else
1775 The_Command = Sync or else
1776 The_Command = Pretty or else
1777 The_Command = Metric or else
1778 The_Command = Stack or else
1780 and then Argv'Length = 2
1781 and then Argv (2) = 'U'
1783 All_Projects := True;
1784 Remove_Switch (Arg_Num);
1787 Arg_Num := Arg_Num + 1;
1790 elsif ((The_Command = Check and then Argv (Argv'First) /= '+')
1791 or else The_Command = Sync
1792 or else The_Command = Metric
1793 or else The_Command = Pretty)
1794 and then Project_File /= null
1795 and then All_Projects
1797 if ASIS_Main /= null then
1798 Fail ("cannot specify more than one main after -U");
1801 Remove_Switch (Arg_Num);
1805 Arg_Num := Arg_Num + 1;
1808 end Inspect_Switches;
1811 -- If there is a project file specified, parse it, get the switches
1812 -- for the tool and setup PATH environment variables.
1814 if Project_File /= null then
1815 Prj.Pars.Set_Verbosity (To => Current_Verbosity);
1818 (Project => Project,
1819 In_Tree => Project_Tree,
1820 Project_File_Name => Project_File.all,
1821 Packages_To_Check => Packages_To_Check);
1823 if Project = Prj.No_Project then
1824 Fail ("""", Project_File.all, """ processing failed");
1827 -- Check if a package with the name of the tool is in the project
1828 -- file and if there is one, get the switches, if any, and scan them.
1831 Data : constant Prj.Project_Data :=
1832 Project_Tree.Projects.Table (Project);
1834 Pkg : constant Prj.Package_Id :=
1836 (Name => Tool_Package_Name,
1837 In_Packages => Data.Decl.Packages,
1838 In_Tree => Project_Tree);
1840 Element : Package_Element;
1842 Default_Switches_Array : Array_Element_Id;
1844 The_Switches : Prj.Variable_Value;
1845 Current : Prj.String_List_Id;
1846 The_String : String_Element;
1849 if Pkg /= No_Package then
1850 Element := Project_Tree.Packages.Table (Pkg);
1852 -- Packages Gnatls and Gnatstack have a single attribute
1853 -- Switches, that is not an associative array.
1855 if The_Command = List or else The_Command = Stack then
1858 (Variable_Name => Snames.Name_Switches,
1859 In_Variables => Element.Decl.Attributes,
1860 In_Tree => Project_Tree);
1862 -- Packages Binder (for gnatbind), Cross_Reference (for
1863 -- gnatxref), Linker (for gnatlink), Finder (for gnatfind),
1864 -- Pretty_Printer (for gnatpp), Eliminate (for gnatelim), Check
1865 -- (for gnatcheck), and Metric (for gnatmetric) have an
1866 -- attributed Switches, an associative array, indexed by the
1867 -- name of the file.
1869 -- They also have an attribute Default_Switches, indexed by the
1870 -- name of the programming language.
1873 if The_Switches.Kind = Prj.Undefined then
1874 Default_Switches_Array :=
1876 (Name => Name_Default_Switches,
1877 In_Arrays => Element.Decl.Arrays,
1878 In_Tree => Project_Tree);
1879 The_Switches := Prj.Util.Value_Of
1882 In_Array => Default_Switches_Array,
1883 In_Tree => Project_Tree);
1887 -- If there are switches specified in the package of the
1888 -- project file corresponding to the tool, scan them.
1890 case The_Switches.Kind is
1891 when Prj.Undefined =>
1896 Switch : constant String :=
1897 Get_Name_String (The_Switches.Value);
1900 if Switch'Length > 0 then
1901 First_Switches.Increment_Last;
1902 First_Switches.Table (First_Switches.Last) :=
1903 new String'(Switch);
1908 Current := The_Switches.Values;
1909 while Current /= Prj.Nil_String loop
1910 The_String := Project_Tree.String_Elements.
1914 Switch : constant String :=
1915 Get_Name_String (The_String.Value);
1918 if Switch'Length > 0 then
1919 First_Switches.Increment_Last;
1920 First_Switches.Table (First_Switches.Last) :=
1921 new String'(Switch);
1925 Current := The_String.Next;
1931 if The_Command = Bind
1932 or else The_Command = Link
1933 or else The_Command = Elim
1937 (Project_Tree.Projects.Table
1938 (Project).Object_Directory));
1941 -- Set up the env vars for project path files
1943 Prj.Env.Set_Ada_Paths
1944 (Project, Project_Tree, Including_Libraries => False);
1946 -- For gnatcheck, gnatstub, gnatmetric, gnatpp and gnatelim, create
1947 -- a configuration pragmas file, if necessary.
1949 if The_Command = Pretty
1950 or else The_Command = Metric
1951 or else The_Command = Stub
1952 or else The_Command = Elim
1953 or else The_Command = Check
1954 or else The_Command = Sync
1956 -- If there are switches in package Compiler, put them in the
1957 -- Carg_Switches table.
1960 Data : constant Prj.Project_Data :=
1961 Project_Tree.Projects.Table (Project);
1963 Pkg : constant Prj.Package_Id :=
1965 (Name => Name_Compiler,
1966 In_Packages => Data.Decl.Packages,
1967 In_Tree => Project_Tree);
1969 Element : Package_Element;
1971 Default_Switches_Array : Array_Element_Id;
1973 The_Switches : Prj.Variable_Value;
1974 Current : Prj.String_List_Id;
1975 The_String : String_Element;
1978 if Pkg /= No_Package then
1979 Element := Project_Tree.Packages.Table (Pkg);
1981 Default_Switches_Array :=
1983 (Name => Name_Default_Switches,
1984 In_Arrays => Element.Decl.Arrays,
1985 In_Tree => Project_Tree);
1986 The_Switches := Prj.Util.Value_Of
1989 In_Array => Default_Switches_Array,
1990 In_Tree => Project_Tree);
1992 -- If there are switches specified in the package of the
1993 -- project file corresponding to the tool, scan them.
1995 case The_Switches.Kind is
1996 when Prj.Undefined =>
2001 Switch : constant String :=
2002 Get_Name_String (The_Switches.Value);
2004 if Switch'Length > 0 then
2005 Add_To_Carg_Switches (new String'(Switch));
2010 Current := The_Switches.Values;
2011 while Current /= Prj.Nil_String loop
2013 Project_Tree.String_Elements.Table (Current);
2016 Switch : constant String :=
2017 Get_Name_String (The_String.Value);
2019 if Switch'Length > 0 then
2020 Add_To_Carg_Switches (new String'(Switch));
2024 Current := The_String.Next;
2030 -- If -cargs is one of the switches, move the following switches
2031 -- to the Carg_Switches table.
2033 for J in 1 .. First_Switches.Last loop
2034 if First_Switches.Table (J).all = "-cargs" then
2040 -- Move the switches that are before -rules when the
2041 -- command is CHECK.
2044 while K <= First_Switches.Last
2046 (The_Command /= Check
2047 or else First_Switches.Table (K).all /= "-rules")
2049 Add_To_Carg_Switches (First_Switches.Table (K));
2053 if K > First_Switches.Last then
2054 First_Switches.Set_Last (J - 1);
2058 while K <= First_Switches.Last loop
2060 First_Switches.Table (Last) :=
2061 First_Switches.Table (K);
2065 First_Switches.Set_Last (Last);
2073 for J in 1 .. Last_Switches.Last loop
2074 if Last_Switches.Table (J).all = "-cargs" then
2080 -- Move the switches that are before -rules when the
2081 -- command is CHECK.
2084 while K <= Last_Switches.Last
2086 (The_Command /= Check
2088 Last_Switches.Table (K).all /= "-rules")
2090 Add_To_Carg_Switches (Last_Switches.Table (K));
2094 if K > Last_Switches.Last then
2095 Last_Switches.Set_Last (J - 1);
2099 while K <= Last_Switches.Last loop
2101 Last_Switches.Table (Last) :=
2102 Last_Switches.Table (K);
2106 Last_Switches.Set_Last (Last);
2115 CP_File : constant Path_Name_Type := Configuration_Pragmas_File;
2118 if CP_File /= No_Path then
2119 if The_Command = Elim then
2120 First_Switches.Increment_Last;
2121 First_Switches.Table (First_Switches.Last) :=
2122 new String'("-C" & Get_Name_String (CP_File));
2125 Add_To_Carg_Switches
2126 (new String'("-gnatec=" & Get_Name_String (CP_File)));
2132 if The_Command = Link then
2136 if The_Command = Link or The_Command = Bind then
2138 -- For files that are specified as relative paths with directory
2139 -- information, we convert them to absolute paths, with parent
2140 -- being the current working directory if specified on the command
2141 -- line and the project directory if specified in the project
2142 -- file. This is what gnatmake is doing for linker and binder
2145 for J in 1 .. Last_Switches.Last loop
2146 Test_If_Relative_Path
2147 (Last_Switches.Table (J), Current_Work_Dir);
2151 (Project_Tree.Projects.Table (Project).Directory);
2154 Project_Dir : constant String := Name_Buffer (1 .. Name_Len);
2156 for J in 1 .. First_Switches.Last loop
2157 Test_If_Relative_Path
2158 (First_Switches.Table (J), Project_Dir);
2162 elsif The_Command = Stub then
2164 Data : constant Prj.Project_Data :=
2165 Project_Tree.Projects.Table (Project);
2166 File_Index : Integer := 0;
2167 Dir_Index : Integer := 0;
2168 Last : constant Integer := Last_Switches.Last;
2171 for Index in 1 .. Last loop
2172 if Last_Switches.Table (Index)
2173 (Last_Switches.Table (Index)'First) /= '-'
2175 File_Index := Index;
2180 -- If the naming scheme of the project file is not standard,
2181 -- and if the file name ends with the spec suffix, then
2182 -- indicate to gnatstub the name of the body file with
2185 if Body_Suffix_Id_Of (Project_Tree, "ada", Data.Naming) /=
2186 Prj.Default_Ada_Spec_Suffix
2188 if File_Index /= 0 then
2190 Spec : constant String :=
2191 Base_Name (Last_Switches.Table (File_Index).all);
2192 Last : Natural := Spec'Last;
2197 (Project_Tree, "ada", Data.Naming));
2199 if Spec'Length > Name_Len
2200 and then Spec (Last - Name_Len + 1 .. Last) =
2201 Name_Buffer (1 .. Name_Len)
2203 Last := Last - Name_Len;
2206 (Project_Tree, "ada", Data.Naming));
2207 Last_Switches.Increment_Last;
2208 Last_Switches.Table (Last_Switches.Last) :=
2210 Last_Switches.Increment_Last;
2211 Last_Switches.Table (Last_Switches.Last) :=
2212 new String'(Spec (Spec'First .. Last) &
2213 Name_Buffer (1 .. Name_Len));
2219 -- Add the directory of the spec as the destination directory
2220 -- of the body, if there is no destination directory already
2223 if File_Index /= 0 then
2224 for Index in File_Index + 1 .. Last loop
2225 if Last_Switches.Table (Index)
2226 (Last_Switches.Table (Index)'First) /= '-'
2233 if Dir_Index = 0 then
2234 Last_Switches.Increment_Last;
2235 Last_Switches.Table (Last_Switches.Last) :=
2237 (Dir_Name (Last_Switches.Table (File_Index).all));
2243 -- For gnatmetric, the generated files should be put in the object
2244 -- directory. This must be the first switch, because it may be
2245 -- overriden by a switch in package Metrics in the project file or
2246 -- by a command line option. Note that we don't add the -d= switch
2247 -- if there is no object directory available.
2249 if The_Command = Metric
2251 Project_Tree.Projects.Table (Project).Object_Directory /= No_Path
2253 First_Switches.Increment_Last;
2254 First_Switches.Table (2 .. First_Switches.Last) :=
2255 First_Switches.Table (1 .. First_Switches.Last - 1);
2256 First_Switches.Table (1) :=
2259 (Project_Tree.Projects.Table
2260 (Project).Object_Directory));
2263 -- For gnat check, -rules and the following switches need to be the
2264 -- last options. So, we move all these switches to table
2267 if The_Command = Check then
2270 -- Set to rank of options preceding "-rules"
2272 In_Rules_Switches : Boolean;
2273 -- Set to True when options "-rules" is found
2276 New_Last := First_Switches.Last;
2277 In_Rules_Switches := False;
2279 for J in 1 .. First_Switches.Last loop
2280 if In_Rules_Switches then
2281 Add_To_Rules_Switches (First_Switches.Table (J));
2283 elsif First_Switches.Table (J).all = "-rules" then
2285 In_Rules_Switches := True;
2289 if In_Rules_Switches then
2290 First_Switches.Set_Last (New_Last);
2293 New_Last := Last_Switches.Last;
2294 In_Rules_Switches := False;
2296 for J in 1 .. Last_Switches.Last loop
2297 if In_Rules_Switches then
2298 Add_To_Rules_Switches (Last_Switches.Table (J));
2300 elsif Last_Switches.Table (J).all = "-rules" then
2302 In_Rules_Switches := True;
2306 if In_Rules_Switches then
2307 Last_Switches.Set_Last (New_Last);
2312 -- For gnat check, sync, metric or pretty with -U + a main, get the
2313 -- list of sources from the closure and add them to the arguments.
2315 if ASIS_Main /= null then
2318 -- On VMS, set up the env var again for source dirs file. This is
2319 -- because the call to gnatmake has set this env var to another
2320 -- file that has now been deleted.
2322 if Hostparm.OpenVMS then
2324 -- First make sure that the recorded file names are empty
2328 Prj.Env.Set_Ada_Paths
2329 (Project, Project_Tree, Including_Libraries => False);
2332 -- For gnat check, gnat sync, gnat pretty, gnat metric, gnat list,
2333 -- and gnat stack, if no file has been put on the command line, call
2334 -- tool with all the sources of the main project.
2336 elsif The_Command = Check or else
2337 The_Command = Sync or else
2338 The_Command = Pretty or else
2339 The_Command = Metric or else
2340 The_Command = List or else
2347 -- Gather all the arguments and invoke the executable
2350 The_Args : Argument_List
2351 (1 .. First_Switches.Last +
2352 Last_Switches.Last +
2353 Carg_Switches.Last +
2354 Rules_Switches.Last);
2355 Arg_Num : Natural := 0;
2358 for J in 1 .. First_Switches.Last loop
2359 Arg_Num := Arg_Num + 1;
2360 The_Args (Arg_Num) := First_Switches.Table (J);
2363 for J in 1 .. Last_Switches.Last loop
2364 Arg_Num := Arg_Num + 1;
2365 The_Args (Arg_Num) := Last_Switches.Table (J);
2368 for J in 1 .. Carg_Switches.Last loop
2369 Arg_Num := Arg_Num + 1;
2370 The_Args (Arg_Num) := Carg_Switches.Table (J);
2373 for J in 1 .. Rules_Switches.Last loop
2374 Arg_Num := Arg_Num + 1;
2375 The_Args (Arg_Num) := Rules_Switches.Table (J);
2378 -- If Display_Command is on, only display the generated command
2380 if Display_Command then
2381 Put (Standard_Error, "generated command -->");
2382 Put (Standard_Error, Exec_Path.all);
2384 for Arg in The_Args'Range loop
2385 Put (Standard_Error, " ");
2386 Put (Standard_Error, The_Args (Arg).all);
2389 Put (Standard_Error, "<--");
2390 New_Line (Standard_Error);
2394 if Verbose_Mode then
2395 Output.Write_Str (Exec_Path.all);
2397 for Arg in The_Args'Range loop
2398 Output.Write_Char (' ');
2399 Output.Write_Str (The_Args (Arg).all);
2406 Exit_Status (Spawn (Exec_Path.all, The_Args));
2413 if not Keep_Temporary_Files then
2414 Prj.Env.Delete_All_Path_Files (Project_Tree);
2415 Delete_Temp_Config_Files;
2418 Set_Exit_Status (Failure);
2421 if not Keep_Temporary_Files then
2422 Prj.Env.Delete_All_Path_Files (Project_Tree);
2423 Delete_Temp_Config_Files;
2426 -- Since GNATCmd is normally called from DCL (the VMS shell), it must
2427 -- return an understandable VMS exit status. However the exit status
2428 -- returned *to* GNATCmd is a Posix style code, so we test it and return
2429 -- just a simple success or failure on VMS.
2431 if Hostparm.OpenVMS and then My_Exit_Status /= Success then
2432 Set_Exit_Status (Failure);
2434 Set_Exit_Status (My_Exit_Status);