1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1996-2009, 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 Makeutl
; use Makeutl
;
30 with MLib
.Tgt
; use MLib
.Tgt
;
33 with Namet
; use Namet
;
35 with Osint
; use Osint
;
39 with Prj
.Ext
; use Prj
.Ext
;
41 with Prj
.Tree
; use Prj
.Tree
;
42 with Prj
.Util
; use Prj
.Util
;
44 with Snames
; use Snames
;
48 with Types
; use Types
;
49 with Hostparm
; use Hostparm
;
50 -- Used to determine if we are in VMS or not for error message purposes
52 with Ada
.Characters
.Handling
; use Ada
.Characters
.Handling
;
53 with Ada
.Command_Line
; use Ada
.Command_Line
;
54 with Ada
.Text_IO
; use Ada
.Text_IO
;
56 with GNAT
.OS_Lib
; use GNAT
.OS_Lib
;
58 with VMS_Conv
; use VMS_Conv
;
61 Project_Node_Tree
: Project_Node_Tree_Ref
;
62 Project_File
: String_Access
;
63 Project
: Prj
.Project_Id
;
64 Current_Verbosity
: Prj
.Verbosity
:= Prj
.Default
;
65 Tool_Package_Name
: Name_Id
:= No_Name
;
67 B_Start
: String_Ptr
:= new String'("b~");
68 -- Prefix of binder generated file, changed to b__ for VMS
70 Old_Project_File_Used : Boolean := False;
71 -- This flag indicates a switch -p (for gnatxref and gnatfind) for
72 -- an old fashioned project file. -p cannot be used in conjunction
75 Temp_File_Name : Path_Name_Type := No_Path;
76 -- The name of the temporary text file to put a list of source/object
77 -- files to pass to a tool.
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. The caller is responsible for
237 -- ensuring that Keep_Temporary_Files is False.
239 procedure Get_Closure;
240 -- Get the sources in the closure of the ASIS_Main and add them to the
241 -- list of arguments.
243 function Index (Char : Character; Str : String) return Natural;
244 -- Returns first occurrence of Char in Str, returns 0 if Char not in Str
246 procedure Non_VMS_Usage;
247 -- Display usage for platforms other than VMS
249 procedure Process_Link;
250 -- Process GNAT LINK, when there is a project file specified
252 procedure Set_Library_For
253 (Project : Project_Id;
254 Libraries_Present : in out Boolean);
255 -- If Project is a library project, add the correct -L and -l switches to
256 -- the linker invocation.
258 procedure Set_Libraries is
259 new For_Every_Project_Imported (Boolean, Set_Library_For);
260 -- Add the -L and -l switches to the linker for all of the library
263 procedure Test_If_Relative_Path
264 (Switch : in out String_Access;
266 -- Test if Switch is a relative search path switch. If it is and it
267 -- includes directory information, prepend the path with Parent. This
268 -- subprogram is only called when using project files.
270 --------------------------
271 -- Add_To_Carg_Switches --
272 --------------------------
274 procedure Add_To_Carg_Switches (Switch : String_Access) is
276 -- If the Carg_Switches table is empty, put "-cargs" at the beginning
278 if Carg_Switches.Last = 0 then
279 Carg_Switches.Increment_Last;
280 Carg_Switches.Table (Carg_Switches.Last) := new String'("-cargs");
283 Carg_Switches
.Increment_Last
;
284 Carg_Switches
.Table
(Carg_Switches
.Last
) := Switch
;
285 end Add_To_Carg_Switches
;
287 ---------------------------
288 -- Add_To_Rules_Switches --
289 ---------------------------
291 procedure Add_To_Rules_Switches
(Switch
: String_Access
) is
293 -- If the Rules_Switches table is empty, put "-rules" at the beginning
295 if Rules_Switches
.Last
= 0 then
296 Rules_Switches
.Increment_Last
;
297 Rules_Switches
.Table
(Rules_Switches
.Last
) := new String'("-rules");
300 Rules_Switches.Increment_Last;
301 Rules_Switches.Table (Rules_Switches.Last) := Switch;
302 end Add_To_Rules_Switches;
308 procedure Check_Files is
309 Add_Sources : Boolean := True;
310 Unit : Prj.Unit_Index;
311 Subunit : Boolean := False;
312 FD : File_Descriptor := Invalid_FD;
317 -- Check if there is at least one argument that is not a switch
319 for Index in 1 .. Last_Switches.Last loop
320 if Last_Switches.Table (Index) (1) /= '-' then
325 Last_Switches.Table (Index - 1).all /= "-o")
327 (The_Command = Pretty
329 Last_Switches.Table (Index - 1).all /= "-o" and then
330 Last_Switches.Table (Index - 1).all /= "-of")
332 (The_Command = Metric
334 Last_Switches.Table (Index - 1).all /= "-o" and then
335 Last_Switches.Table (Index - 1).all /= "-og" and then
336 Last_Switches.Table (Index - 1).all /= "-ox" and then
337 Last_Switches.Table (Index - 1).all /= "-d")
339 (The_Command /= Check and then
340 The_Command /= Pretty and then
341 The_Command /= Metric)
343 Add_Sources := False;
349 -- If all arguments were switches, add the path names of all the sources
350 -- of the main project.
354 -- For gnatcheck, gnatpp and gnatmetric , create a temporary file and
355 -- put the list of sources in it.
357 if The_Command = Check or else
358 The_Command = Pretty or else
361 Tempdir.Create_Temp_File (FD, Temp_File_Name);
362 Last_Switches.Increment_Last;
363 Last_Switches.Table (Last_Switches.Last) :=
364 new String'("-files=" & Get_Name_String
(Temp_File_Name
));
371 -- Gnatstack needs to add the .ci file for the binder generated
372 -- files corresponding to all of the library projects and main
373 -- units belonging to the application.
375 if The_Command
= Stack
then
376 Proj
:= Project_Tree
.Projects
;
377 while Proj
/= null loop
378 if Check_Project
(Proj
.Project
, Project
) then
380 Main
: String_List_Id
;
381 File
: String_Access
;
384 -- Include binder generated files for main programs
386 Main
:= Proj
.Project
.Mains
;
387 while Main
/= Nil_String
loop
391 (Proj.Project.Object_Directory.Name) &
395 (Project_Tree.String_Elements.Table
399 if Is_Regular_File (File.all) then
400 Last_Switches.Increment_Last;
401 Last_Switches.Table (Last_Switches.Last) := File;
405 Project_Tree.String_Elements.Table (Main).Next;
408 if Proj.Project.Library then
410 -- Include the .ci file for the binder generated
411 -- files that contains the initialization and
412 -- finalization of the library.
417 (Proj
.Project
.Object_Directory
.Name
) &
419 Get_Name_String
(Proj
.Project
.Library_Name
) &
422 if Is_Regular_File
(File
.all) then
423 Last_Switches
.Increment_Last
;
424 Last_Switches
.Table
(Last_Switches
.Last
) := File
;
434 Unit
:= Units_Htable
.Get_First
(Project_Tree
.Units_HT
);
435 while Unit
/= No_Unit_Index
loop
437 -- For gnatls, we only need to put the library units, body or
438 -- spec, but not the subunits.
440 if The_Command
= List
then
441 if Unit
.File_Names
(Impl
) /= null
442 and then not Unit
.File_Names
(Impl
).Locally_Removed
444 -- There is a body, check if it is for this project
446 if All_Projects
or else
447 Unit
.File_Names
(Impl
).Project
= Project
451 if Unit
.File_Names
(Spec
) = null
452 or else Unit
.File_Names
(Spec
).Locally_Removed
454 -- We have a body with no spec: we need to check if
455 -- this is a subunit, because gnatls will complain
459 Src_Ind
: constant Source_File_Index
:=
460 Sinput
.P
.Load_Project_File
466 Sinput
.P
.Source_File_Is_Subunit
(Src_Ind
);
471 Last_Switches
.Increment_Last
;
472 Last_Switches
.Table
(Last_Switches
.Last
) :=
476 (Impl).Display_File));
480 elsif Unit.File_Names (Spec) /= null
481 and then not Unit.File_Names (Spec).Locally_Removed
483 -- We have a spec with no body. Check if it is for this
486 if All_Projects or else
487 Unit.File_Names (Spec).Project = Project
489 Last_Switches.Increment_Last;
490 Last_Switches.Table (Last_Switches.Last) :=
491 new String'(Get_Name_String
492 (Unit
.File_Names
(Spec
).Display_File
));
496 -- For gnatstack, we put the .ci files corresponding to the
497 -- different units, including the binder generated files. We
498 -- only need to do that for the library units, body or spec,
499 -- but not the subunits.
501 elsif The_Command
= Stack
then
502 if Unit
.File_Names
(Impl
) /= null
503 and then not Unit
.File_Names
(Impl
).Locally_Removed
505 -- There is a body. Check if .ci files for this project
509 (Unit
.File_Names
(Impl
).Project
, Project
)
513 if Unit
.File_Names
(Spec
) = null
514 or else Unit
.File_Names
(Spec
).Locally_Removed
516 -- We have a body with no spec: we need to check
517 -- if this is a subunit, because .ci files are not
518 -- generated for subunits.
521 Src_Ind
: constant Source_File_Index
:=
522 Sinput
.P
.Load_Project_File
528 Sinput
.P
.Source_File_Is_Subunit
(Src_Ind
);
533 Last_Switches
.Increment_Last
;
534 Last_Switches
.Table
(Last_Switches
.Last
) :=
538 (Impl).Project. Object_Directory.Name) &
541 (Unit.File_Names (Impl).Display_File),
546 elsif Unit.File_Names (Spec) /= null
547 and then not Unit.File_Names (Spec).Locally_Removed
549 -- Spec with no body, check if it is for this project
552 (Unit.File_Names (Spec).Project, Project)
554 Last_Switches.Increment_Last;
555 Last_Switches.Table (Last_Switches.Last) :=
559 (Spec
).Project
. Object_Directory
.Name
) &
562 (Get_Name_String
(Unit
.File_Names
(Spec
).File
),
568 -- For gnatcheck, gnatsync, gnatpp and gnatmetric, put all
569 -- sources of the project, or of all projects if -U was
572 for Kind
in Spec_Or_Body
loop
573 if Unit
.File_Names
(Kind
) /= null
574 and then Check_Project
575 (Unit
.File_Names
(Kind
).Project
, Project
)
576 and then not Unit
.File_Names
(Kind
).Locally_Removed
579 Add_Char_To_Name_Buffer
('"');
580 Add_Str_To_Name_Buffer
582 (Unit
.File_Names
(Kind
).Path
.Display_Name
));
583 Add_Char_To_Name_Buffer
('"');
585 if FD
/= Invalid_FD
then
586 Name_Len
:= Name_Len
+ 1;
587 Name_Buffer
(Name_Len
) := ASCII
.LF
;
589 Write
(FD
, Name_Buffer
(1)'Address, Name_Len
);
591 if Status
/= Name_Len
then
592 Osint
.Fail
("disk full");
596 Last_Switches
.Increment_Last
;
597 Last_Switches
.Table
(Last_Switches
.Last
) :=
598 new String'(Get_Name_String
600 (Kind).Path.Display_Name));
606 Unit := Units_Htable.Get_Next (Project_Tree.Units_HT);
610 if FD /= Invalid_FD then
614 Osint.Fail ("disk full");
624 function Check_Project
625 (Project : Project_Id;
626 Root_Project : Project_Id) return Boolean
631 if Project = No_Project then
634 elsif All_Projects or else Project = Root_Project then
637 elsif The_Command = Metric then
638 Proj := Root_Project;
639 while Proj.Extends /= No_Project loop
640 if Project = Proj.Extends then
644 Proj := Proj.Extends;
651 -------------------------------
652 -- Check_Relative_Executable --
653 -------------------------------
655 procedure Check_Relative_Executable (Name : in out String_Access) is
656 Exec_File_Name : constant String := Name.all;
659 if not Is_Absolute_Path (Exec_File_Name) then
660 for Index in Exec_File_Name'Range loop
661 if Exec_File_Name (Index) = Directory_Separator then
662 Fail ("relative executable (""" &
664 """) with directory part not allowed " &
665 "when using project files");
669 Get_Name_String (Project.Exec_Directory.Name);
671 if Name_Buffer (Name_Len) /= Directory_Separator then
672 Name_Len := Name_Len + 1;
673 Name_Buffer (Name_Len) := Directory_Separator;
676 Name_Buffer (Name_Len + 1 ..
677 Name_Len + Exec_File_Name'Length) :=
679 Name_Len := Name_Len + Exec_File_Name'Length;
680 Name := new String'(Name_Buffer
(1 .. Name_Len
));
682 end Check_Relative_Executable
;
684 --------------------------------
685 -- Configuration_Pragmas_File --
686 --------------------------------
688 function Configuration_Pragmas_File
return Path_Name_Type
is
690 Prj
.Env
.Create_Config_Pragmas_File
(Project
, Project_Tree
);
691 return Project
.Config_File_Name
;
692 end Configuration_Pragmas_File
;
694 ------------------------------
695 -- Delete_Temp_Config_Files --
696 ------------------------------
698 procedure Delete_Temp_Config_Files
is
701 pragma Warnings
(Off
, Success
);
704 -- This should only be called if Keep_Temporary_Files is False
706 pragma Assert
(not Keep_Temporary_Files
);
708 if Project
/= No_Project
then
709 Proj
:= Project_Tree
.Projects
;
710 while Proj
/= null loop
711 if Proj
.Project
.Config_File_Temp
then
712 Delete_Temporary_File
713 (Project_Tree
, Proj
.Project
.Config_File_Name
);
720 -- If a temporary text file that contains a list of files for a tool
721 -- has been created, delete this temporary file.
723 if Temp_File_Name
/= No_Path
then
724 Delete_Temporary_File
(Project_Tree
, Temp_File_Name
);
726 end Delete_Temp_Config_Files
;
732 procedure Get_Closure
is
733 Args
: constant Argument_List
:=
734 (1 => new String'("-q"),
735 2 => new String'("-b"),
736 3 => new String'("-P"),
739 6 => new String'("-bargs"),
740 7 => new String'("-R"),
741 8 => new String'("-Z"));
742 -- Arguments for the invocation of gnatmake which are added to the
743 -- Last_Arguments list by this procedure.
745 FD
: File_Descriptor
;
746 -- File descriptor for the temp file that will get the output of the
747 -- invocation of gnatmake.
749 Name
: Path_Name_Type
;
750 -- Path of the file FD
752 GN_Name
: constant String := Program_Name
("gnatmake", "gnat").all;
755 GN_Path
: constant String_Access
:= Locate_Exec_On_Path
(GN_Name
);
758 Return_Code
: Integer;
761 pragma Warnings
(Off
, Unused
);
763 File
: Ada
.Text_IO
.File_Type
;
764 Line
: String (1 .. 250);
766 -- Used to read file if there is an error, it is good enough to display
767 -- just 250 characters if the first line of the file is very long.
770 Path
: Path_Name_Type
;
773 if GN_Path
= null then
774 Put_Line
(Standard_Error
, "could not locate " & GN_Name
);
778 -- Create the temp file
780 Tempdir
.Create_Temp_File
(FD
, Name
);
782 -- And close it, because on VMS Spawn with a file descriptor created
783 -- with Create_Temp_File does not redirect output.
787 -- Spawn "gnatmake -q -b -P <project> <main> -bargs -R -Z"
790 (Program_Name
=> GN_Path
.all,
792 Output_File
=> Get_Name_String
(Name
),
794 Return_Code
=> Return_Code
,
799 -- Read the output of the invocation of gnatmake
801 Open
(File
, In_File
, Get_Name_String
(Name
));
803 -- If it was unsuccessful, display the first line in the file and exit
806 if Return_Code
/= 0 then
807 Get_Line
(File
, Line
, Last
);
809 if not Keep_Temporary_Files
then
815 Put_Line
(Standard_Error
, Line
(1 .. Last
));
817 (Standard_Error
, "could not get closure of " & ASIS_Main
.all);
821 -- Get each file name in the file, find its path and add it the
822 -- list of arguments.
824 while not End_Of_File
(File
) loop
825 Get_Line
(File
, Line
, Last
);
828 Unit
:= Units_Htable
.Get_First
(Project_Tree
.Units_HT
);
829 while Unit
/= No_Unit_Index
loop
830 if Unit
.File_Names
(Spec
) /= null
832 Get_Name_String
(Unit
.File_Names
(Spec
).File
) =
835 Path
:= Unit
.File_Names
(Spec
).Path
.Name
;
838 elsif Unit
.File_Names
(Impl
) /= null
840 Get_Name_String
(Unit
.File_Names
(Impl
).File
) =
843 Path
:= Unit
.File_Names
(Impl
).Path
.Name
;
847 Unit
:= Units_Htable
.Get_Next
(Project_Tree
.Units_HT
);
850 Last_Switches
.Increment_Last
;
852 if Path
/= No_Path
then
853 Last_Switches
.Table
(Last_Switches
.Last
) :=
854 new String'(Get_Name_String (Path));
857 Last_Switches.Table (Last_Switches.Last) :=
858 new String'(Line
(1 .. Last
));
862 if not Keep_Temporary_Files
then
874 function Index
(Char
: Character; Str
: String) return Natural is
876 for Index
in Str
'Range loop
877 if Str
(Index
) = Char
then
889 procedure Process_Link
is
890 Look_For_Executable
: Boolean := True;
891 Libraries_Present
: Boolean := False;
892 Path_Option
: constant String_Access
:=
893 MLib
.Linker_Library_Path_Option
;
894 Prj
: Project_Id
:= Project
;
897 Skip_Executable
: Boolean := False;
900 -- Add the default search directories, to be able to find
901 -- libgnat in call to MLib.Utl.Lib_Directory.
903 Add_Default_Search_Dirs
;
905 Library_Paths
.Set_Last
(0);
907 -- Check if there are library project files
909 if MLib
.Tgt
.Support_For_Libraries
/= None
then
910 Set_Libraries
(Project
, Libraries_Present
);
913 -- If there are, add the necessary additional switches
915 if Libraries_Present
then
917 -- Add -L<lib_dir> -lgnarl -lgnat -Wl,-rpath,<lib_dir>
919 Last_Switches
.Increment_Last
;
920 Last_Switches
.Table
(Last_Switches
.Last
) :=
921 new String'("-L" & MLib.Utl.Lib_Directory);
922 Last_Switches.Increment_Last;
923 Last_Switches.Table (Last_Switches.Last) :=
924 new String'("-lgnarl");
925 Last_Switches
.Increment_Last
;
926 Last_Switches
.Table
(Last_Switches
.Last
) :=
927 new String'("-lgnat");
929 -- If Path_Option is not null, create the switch ("-Wl,-rpath," or
930 -- equivalent) with all the library dirs plus the standard GNAT
933 if Path_Option /= null then
935 Option : String_Access;
936 Length : Natural := Path_Option'Length;
940 if MLib.Separate_Run_Path_Options then
942 -- We are going to create one switch of the form
943 -- "-Wl,-rpath,dir_N" for each directory to consider.
945 -- One switch for each library directory
948 Library_Paths.First .. Library_Paths.Last
950 Last_Switches.Increment_Last;
952 (Last_Switches.Last) := new String'
954 Last_Switches
.Table
(Index
).all);
957 -- One switch for the standard GNAT library dir
959 Last_Switches
.Increment_Last
;
961 (Last_Switches
.Last
) := new String'
962 (Path_Option.all & MLib.Utl.Lib_Directory);
965 -- First, compute the exact length for the switch
968 Library_Paths.First .. Library_Paths.Last
970 -- Add the length of the library dir plus one for the
971 -- directory separator.
975 Library_Paths.Table (Index)'Length + 1;
978 -- Finally, add the length of the standard GNAT library dir
980 Length := Length + MLib.Utl.Lib_Directory'Length;
981 Option := new String (1 .. Length);
982 Option (1 .. Path_Option'Length) := Path_Option.all;
983 Current := Path_Option'Length;
985 -- Put each library dir followed by a dir separator
988 Library_Paths.First .. Library_Paths.Last
993 Library_Paths.Table (Index)'Length) :=
994 Library_Paths.Table (Index).all;
997 Library_Paths.Table (Index)'Length + 1;
998 Option (Current) := Path_Separator;
1001 -- Finally put the standard GNAT library dir
1005 Current + MLib.Utl.Lib_Directory'Length) :=
1006 MLib.Utl.Lib_Directory;
1008 -- And add the switch to the last switches
1010 Last_Switches.Increment_Last;
1011 Last_Switches.Table (Last_Switches.Last) :=
1018 -- Check if the first ALI file specified can be found, either in the
1019 -- object directory of the main project or in an object directory of a
1020 -- project file extended by the main project. If the ALI file can be
1021 -- found, replace its name with its absolute path.
1023 Skip_Executable := False;
1025 Switch_Loop : for J in 1 .. Last_Switches.Last loop
1027 -- If we have an executable just reset the flag
1029 if Skip_Executable then
1030 Skip_Executable := False;
1032 -- If -o, set flag so that next switch is not processed
1034 elsif Last_Switches.Table (J).all = "-o" then
1035 Skip_Executable := True;
1041 Switch : constant String :=
1042 Last_Switches.Table (J).all;
1043 ALI_File : constant String (1 .. Switch'Length + 4) :=
1046 Test_Existence : Boolean := False;
1049 Last := Switch'Length;
1051 -- Skip real switches
1053 if Switch'Length /= 0
1054 and then Switch (Switch'First) /= '-'
1056 -- Append ".ali" if file name does not end with it
1058 if Switch'Length <= 4
1059 or else Switch (Switch'Last - 3 .. Switch'Last)
1062 Last := ALI_File'Last;
1065 -- If file name includes directory information, stop if ALI
1068 if Is_Absolute_Path (ALI_File (1 .. Last)) then
1069 Test_Existence := True;
1072 for K in Switch'Range loop
1073 if Switch (K) = '/' or else
1074 Switch (K) = Directory_Separator
1076 Test_Existence := True;
1082 if Test_Existence then
1083 if Is_Regular_File (ALI_File (1 .. Last)) then
1087 -- Look in object directories if ALI file exists
1092 Dir : constant String :=
1093 Get_Name_String (Prj.Object_Directory.Name);
1097 ALI_File (1 .. Last))
1099 -- We have found the correct project, so we
1100 -- replace the file with the absolute path.
1102 Last_Switches.Table (J) :=
1103 new String'(Dir
& ALI_File
(1 .. Last
));
1111 -- Go to the project being extended, if any
1114 exit Project_Loop
when Prj
= No_Project
;
1115 end loop Project_Loop
;
1120 end loop Switch_Loop
;
1122 -- If a relative path output file has been specified, we add the exec
1125 for J
in reverse 1 .. Last_Switches
.Last
- 1 loop
1126 if Last_Switches
.Table
(J
).all = "-o" then
1127 Check_Relative_Executable
1128 (Name
=> Last_Switches
.Table
(J
+ 1));
1129 Look_For_Executable
:= False;
1134 if Look_For_Executable
then
1135 for J
in reverse 1 .. First_Switches
.Last
- 1 loop
1136 if First_Switches
.Table
(J
).all = "-o" then
1137 Look_For_Executable
:= False;
1138 Check_Relative_Executable
1139 (Name
=> First_Switches
.Table
(J
+ 1));
1145 -- If no executable is specified, then find the name of the first ALI
1146 -- file on the command line and issue a -o switch with the absolute path
1147 -- of the executable in the exec directory.
1149 if Look_For_Executable
then
1150 for J
in 1 .. Last_Switches
.Last
loop
1151 Arg
:= Last_Switches
.Table
(J
);
1154 if Arg
'Length /= 0 and then Arg
(Arg
'First) /= '-' then
1156 and then Arg
(Arg
'Last - 3 .. Arg
'Last) = ".ali"
1158 Last
:= Arg
'Last - 4;
1160 elsif Is_Regular_File
(Arg
.all & ".ali") then
1165 Last_Switches
.Increment_Last
;
1166 Last_Switches
.Table
(Last_Switches
.Last
) :=
1168 Get_Name_String (Project.Exec_Directory.Name);
1169 Last_Switches.Increment_Last;
1170 Last_Switches.Table (Last_Switches.Last) :=
1171 new String'(Name_Buffer
(1 .. Name_Len
) &
1173 (Base_Name
(Arg
(Arg
'First .. Last
))));
1181 ---------------------
1182 -- Set_Library_For --
1183 ---------------------
1185 procedure Set_Library_For
1186 (Project
: Project_Id
;
1187 Libraries_Present
: in out Boolean)
1189 Path_Option
: constant String_Access
:=
1190 MLib
.Linker_Library_Path_Option
;
1193 -- Case of library project
1195 if Project
.Library
then
1196 Libraries_Present
:= True;
1198 -- Add the -L switch
1200 Last_Switches
.Increment_Last
;
1201 Last_Switches
.Table
(Last_Switches
.Last
) :=
1202 new String'("-L" & Get_Name_String (Project.Library_Dir.Name));
1204 -- Add the -l switch
1206 Last_Switches.Increment_Last;
1207 Last_Switches.Table (Last_Switches.Last) :=
1208 new String'("-l" & Get_Name_String
(Project
.Library_Name
));
1210 -- Add the directory to table Library_Paths, to be processed later
1211 -- if library is not static and if Path_Option is not null.
1213 if Project
.Library_Kind
/= Static
1214 and then Path_Option
/= null
1216 Library_Paths
.Increment_Last
;
1217 Library_Paths
.Table
(Library_Paths
.Last
) :=
1218 new String'(Get_Name_String (Project.Library_Dir.Name));
1221 end Set_Library_For;
1223 ---------------------------
1224 -- Test_If_Relative_Path --
1225 ---------------------------
1227 procedure Test_If_Relative_Path
1228 (Switch : in out String_Access;
1232 Makeutl.Test_If_Relative_Path
1233 (Switch, Parent, Including_Non_Switch => False, Including_RTS => True);
1234 end Test_If_Relative_Path;
1240 procedure Non_VMS_Usage is
1244 Put_Line ("List of available commands");
1247 for C in Command_List'Range loop
1248 if not Command_List (C).VMS_Only then
1249 if Targparm.AAMP_On_Target then
1255 Put (To_Lower (Command_List (C).Cname.all));
1258 -- Never call gnatstack with a prefix
1261 Put (Command_List (C).Unixcmd.all);
1263 Put (Program_Name (Command_List (C).Unixcmd.all, "gnat").all);
1267 Sws : Argument_List_Access renames Command_List (C).Unixsws;
1270 for J in Sws'Range loop
1282 Put_Line ("Commands find, list, metric, pretty, stack, stub and xref " &
1283 "accept project file switches -vPx, -Pprj and -Xnam=val");
1287 -------------------------------------
1288 -- Start of processing for GNATCmd --
1289 -------------------------------------
1299 Project_Node_Tree := new Project_Node_Tree_Data;
1300 Prj.Tree.Initialize (Project_Node_Tree);
1302 Prj.Initialize (Project_Tree);
1305 Last_Switches.Set_Last (0);
1307 First_Switches.Init;
1308 First_Switches.Set_Last (0);
1310 Carg_Switches.Set_Last (0);
1311 Rules_Switches.Init;
1312 Rules_Switches.Set_Last (0);
1314 VMS_Conv.Initialize;
1316 -- Add the default search directories, to be able to find system.ads in the
1317 -- subsequent call to Targparm.Get_Target_Parameters.
1319 Add_Default_Search_Dirs;
1321 -- Get target parameters so that AAMP_On_Target will be set, for testing in
1322 -- Osint.Program_Name to handle the mapping of GNAAMP tool names.
1324 Targparm.Get_Target_Parameters;
1326 -- Add the directory where the GNAT driver is invoked in front of the path,
1327 -- if the GNAT driver is invoked with directory information. Do not do this
1328 -- for VMS, where the notion of path does not really exist.
1332 Command : constant String := Command_Name;
1335 for Index in reverse Command'Range loop
1336 if Command (Index) = Directory_Separator then
1338 Absolute_Dir : constant String :=
1340 (Command (Command'First .. Index));
1342 PATH : constant String :=
1343 Absolute_Dir & Path_Separator & Getenv ("PATH").all;
1346 Setenv ("PATH", PATH);
1355 -- If on VMS, or if VMS emulation is on, convert VMS style /qualifiers,
1356 -- filenames and pathnames to Unix style.
1359 or else To_Lower (Getenv ("EMULATE_VMS").all) = "true"
1361 VMS_Conversion (The_Command);
1363 B_Start := new String'("b__");
1365 -- If not on VMS, scan the command line directly
1368 if Argument_Count
= 0 then
1374 if Argument_Count
> Command_Arg
1375 and then Argument
(Command_Arg
) = "-v"
1377 Verbose_Mode
:= True;
1378 Command_Arg
:= Command_Arg
+ 1;
1380 elsif Argument_Count
> Command_Arg
1381 and then Argument
(Command_Arg
) = "-dn"
1383 Keep_Temporary_Files
:= True;
1384 Command_Arg
:= Command_Arg
+ 1;
1391 The_Command
:= Real_Command_Type
'Value (Argument
(Command_Arg
));
1393 if Command_List
(The_Command
).VMS_Only
then
1397 & Command_List
(The_Command
).Cname
.all
1398 & """ can only be used on VMS");
1402 when Constraint_Error
=>
1404 -- Check if it is an alternate command
1407 Alternate
: Alternate_Command
;
1410 Alternate
:= Alternate_Command
'Value
1411 (Argument
(Command_Arg
));
1412 The_Command
:= Corresponding_To
(Alternate
);
1415 when Constraint_Error
=>
1417 Fail
("Unknown command: " & Argument
(Command_Arg
));
1421 -- Get the arguments from the command line and from the eventual
1422 -- argument file(s) specified on the command line.
1424 for Arg
in Command_Arg
+ 1 .. Argument_Count
loop
1426 The_Arg
: constant String := Argument
(Arg
);
1429 -- Check if an argument file is specified
1431 if The_Arg
(The_Arg
'First) = '@' then
1433 Arg_File
: Ada
.Text_IO
.File_Type
;
1434 Line
: String (1 .. 256);
1438 -- Open the file and fail if the file cannot be found
1443 The_Arg
(The_Arg
'First + 1 .. The_Arg
'Last));
1448 (Standard_Error
, "Cannot open argument file """);
1451 The_Arg
(The_Arg
'First + 1 .. The_Arg
'Last));
1453 Put_Line
(Standard_Error
, """");
1457 -- Read line by line and put the content of each non-
1458 -- empty line in the Last_Switches table.
1460 while not End_Of_File
(Arg_File
) loop
1461 Get_Line
(Arg_File
, Line
, Last
);
1464 Last_Switches
.Increment_Last
;
1465 Last_Switches
.Table
(Last_Switches
.Last
) :=
1466 new String'(Line (1 .. Last));
1474 -- It is not an argument file; just put the argument in
1475 -- the Last_Switches table.
1477 Last_Switches.Increment_Last;
1478 Last_Switches.Table (Last_Switches.Last) :=
1479 new String'(The_Arg
);
1487 Program
: String_Access
;
1488 Exec_Path
: String_Access
;
1491 if The_Command
= Stack
then
1493 -- Never call gnatstack with a prefix
1495 Program
:= new String'(Command_List (The_Command).Unixcmd.all);
1499 Program_Name (Command_List (The_Command).Unixcmd.all, "gnat");
1502 -- Locate the executable for the command
1504 Exec_Path := Locate_Exec_On_Path (Program.all);
1506 if Exec_Path = null then
1507 Put_Line (Standard_Error, "could not locate " & Program.all);
1511 -- If there are switches for the executable, put them as first switches
1513 if Command_List (The_Command).Unixsws /= null then
1514 for J in Command_List (The_Command).Unixsws'Range loop
1515 First_Switches.Increment_Last;
1516 First_Switches.Table (First_Switches.Last) :=
1517 Command_List (The_Command).Unixsws (J);
1521 -- For BIND, CHECK, ELIM, FIND, LINK, LIST, METRIC, PRETTY, STACK, STUB,
1522 -- SYNC and XREF, look for project file related switches.
1526 Tool_Package_Name := Name_Binder;
1527 Packages_To_Check := Packages_To_Check_By_Binder;
1529 Tool_Package_Name := Name_Check;
1530 Packages_To_Check := Packages_To_Check_By_Check;
1532 Tool_Package_Name := Name_Eliminate;
1533 Packages_To_Check := Packages_To_Check_By_Eliminate;
1535 Tool_Package_Name := Name_Finder;
1536 Packages_To_Check := Packages_To_Check_By_Finder;
1538 Tool_Package_Name := Name_Linker;
1539 Packages_To_Check := Packages_To_Check_By_Linker;
1541 Tool_Package_Name := Name_Gnatls;
1542 Packages_To_Check := Packages_To_Check_By_Gnatls;
1544 Tool_Package_Name := Name_Metrics;
1545 Packages_To_Check := Packages_To_Check_By_Metric;
1547 Tool_Package_Name := Name_Pretty_Printer;
1548 Packages_To_Check := Packages_To_Check_By_Pretty;
1550 Tool_Package_Name := Name_Stack;
1551 Packages_To_Check := Packages_To_Check_By_Stack;
1553 Tool_Package_Name := Name_Gnatstub;
1554 Packages_To_Check := Packages_To_Check_By_Gnatstub;
1556 Tool_Package_Name := Name_Synchronize;
1557 Packages_To_Check := Packages_To_Check_By_Sync;
1559 Tool_Package_Name := Name_Cross_Reference;
1560 Packages_To_Check := Packages_To_Check_By_Xref;
1562 Tool_Package_Name := No_Name;
1565 if Tool_Package_Name /= No_Name then
1567 -- Check that the switches are consistent. Detect project file
1568 -- related switches.
1570 Inspect_Switches : declare
1571 Arg_Num : Positive := 1;
1572 Argv : String_Access;
1574 procedure Remove_Switch (Num : Positive);
1575 -- Remove a project related switch from table Last_Switches
1581 procedure Remove_Switch (Num : Positive) is
1583 Last_Switches.Table (Num .. Last_Switches.Last - 1) :=
1584 Last_Switches.Table (Num + 1 .. Last_Switches.Last);
1585 Last_Switches.Decrement_Last;
1588 -- Start of processing for Inspect_Switches
1591 while Arg_Num <= Last_Switches.Last loop
1592 Argv := Last_Switches.Table (Arg_Num);
1594 if Argv (Argv'First) = '-' then
1595 if Argv'Length = 1 then
1597 ("switch character cannot be followed by a blank");
1600 -- The two style project files (-p and -P) cannot be used
1603 if (The_Command = Find or else The_Command = Xref)
1604 and then Argv (2) = 'p
'
1606 Old_Project_File_Used := True;
1607 if Project_File /= null then
1608 Fail ("-P and -p cannot be used together");
1612 -- --subdirs=... Specify Subdirs
1614 if Argv'Length > Makeutl.Subdirs_Option'Length and then
1617 Argv'First + Makeutl.Subdirs_Option'Length - 1) =
1618 Makeutl.Subdirs_Option
1623 (Argv
'First + Makeutl
.Subdirs_Option
'Length ..
1626 Remove_Switch
(Arg_Num
);
1628 -- -aPdir Add dir to the project search path
1630 elsif Argv
'Length > 3
1631 and then Argv
(Argv
'First + 1 .. Argv
'First + 2) = "aP"
1633 Add_Search_Project_Directory
1634 (Project_Node_Tree
, Argv
(Argv
'First + 3 .. Argv
'Last));
1636 Remove_Switch
(Arg_Num
);
1638 -- -eL Follow links for files
1640 elsif Argv
.all = "-eL" then
1641 Follow_Links_For_Files
:= True;
1642 Follow_Links_For_Dirs
:= True;
1644 Remove_Switch
(Arg_Num
);
1646 -- -vPx Specify verbosity while parsing project files
1648 elsif Argv
'Length = 4
1649 and then Argv
(Argv
'First + 1 .. Argv
'First + 2) = "vP"
1651 case Argv
(Argv
'Last) is
1653 Current_Verbosity
:= Prj
.Default
;
1655 Current_Verbosity
:= Prj
.Medium
;
1657 Current_Verbosity
:= Prj
.High
;
1659 Fail
("Invalid switch: " & Argv
.all);
1662 Remove_Switch
(Arg_Num
);
1664 -- -Pproject_file Specify project file to be used
1666 elsif Argv
(Argv
'First + 1) = 'P' then
1668 -- Only one -P switch can be used
1670 if Project_File
/= null then
1673 & ": second project file forbidden (first is """
1677 -- The two style project files (-p and -P) cannot be
1680 elsif Old_Project_File_Used
then
1681 Fail
("-p and -P cannot be used together");
1683 elsif Argv
'Length = 2 then
1685 -- There is space between -P and the project file
1686 -- name. -P cannot be the last option.
1688 if Arg_Num
= Last_Switches
.Last
then
1689 Fail
("project file name missing after -P");
1692 Remove_Switch
(Arg_Num
);
1693 Argv
:= Last_Switches
.Table
(Arg_Num
);
1695 -- After -P, there must be a project file name,
1696 -- not another switch.
1698 if Argv
(Argv
'First) = '-' then
1699 Fail
("project file name missing after -P");
1702 Project_File
:= new String'(Argv.all);
1707 -- No space between -P and project file name
1710 new String'(Argv
(Argv
'First + 2 .. Argv
'Last));
1713 Remove_Switch
(Arg_Num
);
1715 -- -Xexternal=value Specify an external reference to be
1716 -- used in project files
1718 elsif Argv
'Length >= 5
1719 and then Argv
(Argv
'First + 1) = 'X'
1722 Equal_Pos
: constant Natural :=
1725 Argv
(Argv
'First + 2 .. Argv
'Last));
1727 if Equal_Pos
>= Argv
'First + 3 and then
1728 Equal_Pos
/= Argv
'Last then
1729 Add
(Project_Node_Tree
,
1731 Argv
(Argv
'First + 2 .. Equal_Pos
- 1),
1732 Value
=> Argv
(Equal_Pos
+ 1 .. Argv
'Last));
1736 & " is not a valid external assignment.");
1740 Remove_Switch
(Arg_Num
);
1743 (The_Command
= Check
or else
1744 The_Command
= Sync
or else
1745 The_Command
= Pretty
or else
1746 The_Command
= Metric
or else
1747 The_Command
= Stack
or else
1749 and then Argv
'Length = 2
1750 and then Argv
(2) = 'U'
1752 All_Projects
:= True;
1753 Remove_Switch
(Arg_Num
);
1756 Arg_Num
:= Arg_Num
+ 1;
1759 elsif ((The_Command
= Check
and then Argv
(Argv
'First) /= '+')
1760 or else The_Command
= Sync
1761 or else The_Command
= Metric
1762 or else The_Command
= Pretty
)
1763 and then Project_File
/= null
1764 and then All_Projects
1766 if ASIS_Main
/= null then
1767 Fail
("cannot specify more than one main after -U");
1770 Remove_Switch
(Arg_Num
);
1774 Arg_Num
:= Arg_Num
+ 1;
1777 end Inspect_Switches
;
1780 -- If there is a project file specified, parse it, get the switches
1781 -- for the tool and setup PATH environment variables.
1783 if Project_File
/= null then
1784 Prj
.Pars
.Set_Verbosity
(To
=> Current_Verbosity
);
1787 (Project
=> Project
,
1788 In_Tree
=> Project_Tree
,
1789 In_Node_Tree
=> Project_Node_Tree
,
1790 Project_File_Name
=> Project_File
.all,
1791 Flags
=> Gnatmake_Flags
,
1792 Packages_To_Check
=> Packages_To_Check
);
1794 if Project
= Prj
.No_Project
then
1795 Fail
("""" & Project_File
.all & """ processing failed");
1798 -- Check if a package with the name of the tool is in the project
1799 -- file and if there is one, get the switches, if any, and scan them.
1802 Pkg
: constant Prj
.Package_Id
:=
1804 (Name
=> Tool_Package_Name
,
1805 In_Packages
=> Project
.Decl
.Packages
,
1806 In_Tree
=> Project_Tree
);
1808 Element
: Package_Element
;
1810 Switches_Array
: Array_Element_Id
;
1812 The_Switches
: Prj
.Variable_Value
;
1813 Current
: Prj
.String_List_Id
;
1814 The_String
: String_Element
;
1816 Main
: String_Access
:= null;
1819 if Pkg
/= No_Package
then
1820 Element
:= Project_Tree
.Packages
.Table
(Pkg
);
1822 -- Packages Gnatls and Gnatstack have a single attribute
1823 -- Switches, that is not an associative array.
1825 if The_Command
= List
or else The_Command
= Stack
then
1828 (Variable_Name
=> Snames
.Name_Switches
,
1829 In_Variables
=> Element
.Decl
.Attributes
,
1830 In_Tree
=> Project_Tree
);
1832 -- Packages Binder (for gnatbind), Cross_Reference (for
1833 -- gnatxref), Linker (for gnatlink), Finder (for gnatfind),
1834 -- Pretty_Printer (for gnatpp), Eliminate (for gnatelim), Check
1835 -- (for gnatcheck), and Metric (for gnatmetric) have an
1836 -- attributed Switches, an associative array, indexed by the
1837 -- name of the file.
1839 -- They also have an attribute Default_Switches, indexed by the
1840 -- name of the programming language.
1843 -- First check if there is a single main
1845 for J
in 1 .. Last_Switches
.Last
loop
1846 if Last_Switches
.Table
(J
) (1) /= '-' then
1848 Main
:= Last_Switches
.Table
(J
);
1857 if Main
/= null then
1860 (Name
=> Name_Switches
,
1861 In_Arrays
=> Element
.Decl
.Arrays
,
1862 In_Tree
=> Project_Tree
);
1864 Add_Str_To_Name_Buffer
(Main
.all);
1865 The_Switches
:= Prj
.Util
.Value_Of
1866 (Index
=> Name_Find
,
1868 In_Array
=> Switches_Array
,
1869 In_Tree
=> Project_Tree
);
1872 if The_Switches
.Kind
= Prj
.Undefined
then
1875 (Name
=> Name_Default_Switches
,
1876 In_Arrays
=> Element
.Decl
.Arrays
,
1877 In_Tree
=> Project_Tree
);
1878 The_Switches
:= Prj
.Util
.Value_Of
1881 In_Array
=> Switches_Array
,
1882 In_Tree
=> Project_Tree
);
1886 -- If there are switches specified in the package of the
1887 -- project file corresponding to the tool, scan them.
1889 case The_Switches
.Kind
is
1890 when Prj
.Undefined
=>
1895 Switch
: constant String :=
1896 Get_Name_String
(The_Switches
.Value
);
1899 if Switch
'Length > 0 then
1900 First_Switches
.Increment_Last
;
1901 First_Switches
.Table
(First_Switches
.Last
) :=
1902 new String'(Switch);
1907 Current := The_Switches.Values;
1908 while Current /= Prj.Nil_String loop
1909 The_String := Project_Tree.String_Elements.
1913 Switch : constant String :=
1914 Get_Name_String (The_String.Value);
1917 if Switch'Length > 0 then
1918 First_Switches.Increment_Last;
1919 First_Switches.Table (First_Switches.Last) :=
1920 new String'(Switch
);
1924 Current
:= The_String
.Next
;
1930 if The_Command
= Bind
1931 or else The_Command
= Link
1932 or else The_Command
= Elim
1934 Change_Dir
(Get_Name_String
(Project
.Object_Directory
.Name
));
1937 -- Set up the env vars for project path files
1939 Prj
.Env
.Set_Ada_Paths
1940 (Project
, Project_Tree
, Including_Libraries
=> False);
1942 -- For gnatcheck, gnatstub, gnatmetric, gnatpp and gnatelim, create
1943 -- a configuration pragmas file, if necessary.
1945 if The_Command
= Pretty
1946 or else The_Command
= Metric
1947 or else The_Command
= Stub
1948 or else The_Command
= Elim
1949 or else The_Command
= Check
1950 or else The_Command
= Sync
1952 -- If there are switches in package Compiler, put them in the
1953 -- Carg_Switches table.
1956 Pkg
: constant Prj
.Package_Id
:=
1958 (Name
=> Name_Compiler
,
1959 In_Packages
=> Project
.Decl
.Packages
,
1960 In_Tree
=> Project_Tree
);
1962 Element
: Package_Element
;
1964 Switches_Array
: Array_Element_Id
;
1966 The_Switches
: Prj
.Variable_Value
;
1967 Current
: Prj
.String_List_Id
;
1968 The_String
: String_Element
;
1970 Main
: String_Access
:= null;
1974 if Pkg
/= No_Package
then
1976 -- First, check if there is a single main specified.
1978 for J
in 1 .. Last_Switches
.Last
loop
1979 if Last_Switches
.Table
(J
) (1) /= '-' then
1981 Main
:= Last_Switches
.Table
(J
);
1990 Element
:= Project_Tree
.Packages
.Table
(Pkg
);
1992 -- If there is a single main and there is compilation
1993 -- switches specified in the project file, use them.
1995 if Main
/= null and then not All_Projects
then
1996 Name_Len
:= Main
'Length;
1997 Name_Buffer
(1 .. Name_Len
) := Main
.all;
1998 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
1999 Main_Id
:= Name_Find
;
2003 (Name
=> Name_Switches
,
2004 In_Arrays
=> Element
.Decl
.Arrays
,
2005 In_Tree
=> Project_Tree
);
2006 The_Switches
:= Prj
.Util
.Value_Of
2009 In_Array
=> Switches_Array
,
2010 In_Tree
=> Project_Tree
);
2013 -- Otherwise, get the Default_Switches ("Ada")
2015 if The_Switches
.Kind
= Undefined
then
2018 (Name
=> Name_Default_Switches
,
2019 In_Arrays
=> Element
.Decl
.Arrays
,
2020 In_Tree
=> Project_Tree
);
2021 The_Switches
:= Prj
.Util
.Value_Of
2024 In_Array
=> Switches_Array
,
2025 In_Tree
=> Project_Tree
);
2028 -- If there are switches specified, put them in the
2029 -- Carg_Switches table.
2031 case The_Switches
.Kind
is
2032 when Prj
.Undefined
=>
2037 Switch
: constant String :=
2038 Get_Name_String
(The_Switches
.Value
);
2040 if Switch
'Length > 0 then
2041 Add_To_Carg_Switches
(new String'(Switch));
2046 Current := The_Switches.Values;
2047 while Current /= Prj.Nil_String loop
2049 Project_Tree.String_Elements.Table (Current);
2052 Switch : constant String :=
2053 Get_Name_String (The_String.Value);
2055 if Switch'Length > 0 then
2056 Add_To_Carg_Switches (new String'(Switch
));
2060 Current
:= The_String
.Next
;
2066 -- If -cargs is one of the switches, move the following switches
2067 -- to the Carg_Switches table.
2069 for J
in 1 .. First_Switches
.Last
loop
2070 if First_Switches
.Table
(J
).all = "-cargs" then
2076 -- Move the switches that are before -rules when the
2077 -- command is CHECK.
2080 while K
<= First_Switches
.Last
2082 (The_Command
/= Check
2083 or else First_Switches
.Table
(K
).all /= "-rules")
2085 Add_To_Carg_Switches
(First_Switches
.Table
(K
));
2089 if K
> First_Switches
.Last
then
2090 First_Switches
.Set_Last
(J
- 1);
2094 while K
<= First_Switches
.Last
loop
2096 First_Switches
.Table
(Last
) :=
2097 First_Switches
.Table
(K
);
2101 First_Switches
.Set_Last
(Last
);
2109 for J
in 1 .. Last_Switches
.Last
loop
2110 if Last_Switches
.Table
(J
).all = "-cargs" then
2116 -- Move the switches that are before -rules when the
2117 -- command is CHECK.
2120 while K
<= Last_Switches
.Last
2122 (The_Command
/= Check
2124 Last_Switches
.Table
(K
).all /= "-rules")
2126 Add_To_Carg_Switches
(Last_Switches
.Table
(K
));
2130 if K
> Last_Switches
.Last
then
2131 Last_Switches
.Set_Last
(J
- 1);
2135 while K
<= Last_Switches
.Last
loop
2137 Last_Switches
.Table
(Last
) :=
2138 Last_Switches
.Table
(K
);
2142 Last_Switches
.Set_Last
(Last
);
2151 CP_File
: constant Path_Name_Type
:= Configuration_Pragmas_File
;
2154 if CP_File
/= No_Path
then
2155 if The_Command
= Elim
then
2156 First_Switches
.Increment_Last
;
2157 First_Switches
.Table
(First_Switches
.Last
) :=
2158 new String'("-C" & Get_Name_String (CP_File));
2161 Add_To_Carg_Switches
2162 (new String'("-gnatec=" & Get_Name_String
(CP_File
)));
2168 if The_Command
= Link
then
2172 if The_Command
= Link
or else The_Command
= Bind
then
2174 -- For files that are specified as relative paths with directory
2175 -- information, we convert them to absolute paths, with parent
2176 -- being the current working directory if specified on the command
2177 -- line and the project directory if specified in the project
2178 -- file. This is what gnatmake is doing for linker and binder
2181 for J
in 1 .. Last_Switches
.Last
loop
2182 GNATCmd
.Test_If_Relative_Path
2183 (Last_Switches
.Table
(J
), Current_Work_Dir
);
2186 Get_Name_String
(Project
.Directory
.Name
);
2189 Project_Dir
: constant String := Name_Buffer
(1 .. Name_Len
);
2191 for J
in 1 .. First_Switches
.Last
loop
2192 GNATCmd
.Test_If_Relative_Path
2193 (First_Switches
.Table
(J
), Project_Dir
);
2197 elsif The_Command
= Stub
then
2199 File_Index
: Integer := 0;
2200 Dir_Index
: Integer := 0;
2201 Last
: constant Integer := Last_Switches
.Last
;
2202 Lang
: constant Language_Ptr
:=
2203 Get_Language_From_Name
(Project
, "ada");
2206 for Index
in 1 .. Last
loop
2207 if Last_Switches
.Table
(Index
)
2208 (Last_Switches
.Table
(Index
)'First) /= '-'
2210 File_Index
:= Index
;
2215 -- If the project file naming scheme is not standard, and if
2216 -- the file name ends with the spec suffix, then indicate to
2217 -- gnatstub the name of the body file with a -o switch.
2219 if not Is_Standard_GNAT_Naming
(Lang
.Config
.Naming_Data
) then
2220 if File_Index
/= 0 then
2222 Spec
: constant String :=
2224 (Last_Switches
.Table
(File_Index
).all);
2225 Last
: Natural := Spec
'Last;
2228 Get_Name_String
(Lang
.Config
.Naming_Data
.Spec_Suffix
);
2230 if Spec
'Length > Name_Len
2231 and then Spec
(Last
- Name_Len
+ 1 .. Last
) =
2232 Name_Buffer
(1 .. Name_Len
)
2234 Last
:= Last
- Name_Len
;
2236 (Lang
.Config
.Naming_Data
.Body_Suffix
);
2237 Last_Switches
.Increment_Last
;
2238 Last_Switches
.Table
(Last_Switches
.Last
) :=
2240 Last_Switches.Increment_Last;
2241 Last_Switches.Table (Last_Switches.Last) :=
2242 new String'(Spec
(Spec
'First .. Last
) &
2243 Name_Buffer
(1 .. Name_Len
));
2249 -- Add the directory of the spec as the destination directory
2250 -- of the body, if there is no destination directory already
2253 if File_Index
/= 0 then
2254 for Index
in File_Index
+ 1 .. Last
loop
2255 if Last_Switches
.Table
(Index
)
2256 (Last_Switches
.Table
(Index
)'First) /= '-'
2263 if Dir_Index
= 0 then
2264 Last_Switches
.Increment_Last
;
2265 Last_Switches
.Table
(Last_Switches
.Last
) :=
2267 (Dir_Name (Last_Switches.Table (File_Index).all));
2273 -- For gnatmetric, the generated files should be put in the object
2274 -- directory. This must be the first switch, because it may be
2275 -- overridden by a switch in package Metrics in the project file or
2276 -- by a command line option. Note that we don't add the -d= switch
2277 -- if there is no object directory available.
2279 if The_Command = Metric
2280 and then Project.Object_Directory /= No_Path_Information
2282 First_Switches.Increment_Last;
2283 First_Switches.Table (2 .. First_Switches.Last) :=
2284 First_Switches.Table (1 .. First_Switches.Last - 1);
2285 First_Switches.Table (1) :=
2287 Get_Name_String
(Project
.Object_Directory
.Name
));
2290 -- For gnat check, -rules and the following switches need to be the
2291 -- last options, so move all these switches to table Rules_Switches.
2293 if The_Command
= Check
then
2296 -- Set to rank of options preceding "-rules"
2298 In_Rules_Switches
: Boolean;
2299 -- Set to True when options "-rules" is found
2302 New_Last
:= First_Switches
.Last
;
2303 In_Rules_Switches
:= False;
2305 for J
in 1 .. First_Switches
.Last
loop
2306 if In_Rules_Switches
then
2307 Add_To_Rules_Switches
(First_Switches
.Table
(J
));
2309 elsif First_Switches
.Table
(J
).all = "-rules" then
2311 In_Rules_Switches
:= True;
2315 if In_Rules_Switches
then
2316 First_Switches
.Set_Last
(New_Last
);
2319 New_Last
:= Last_Switches
.Last
;
2320 In_Rules_Switches
:= False;
2322 for J
in 1 .. Last_Switches
.Last
loop
2323 if In_Rules_Switches
then
2324 Add_To_Rules_Switches
(Last_Switches
.Table
(J
));
2326 elsif Last_Switches
.Table
(J
).all = "-rules" then
2328 In_Rules_Switches
:= True;
2332 if In_Rules_Switches
then
2333 Last_Switches
.Set_Last
(New_Last
);
2338 -- For gnat check, sync, metric or pretty with -U + a main, get the
2339 -- list of sources from the closure and add them to the arguments.
2341 if ASIS_Main
/= null then
2344 -- On VMS, set up the env var again for source dirs file. This is
2345 -- because the call to gnatmake has set this env var to another
2346 -- file that has now been deleted.
2348 if Hostparm
.OpenVMS
then
2350 -- First make sure that the recorded file names are empty
2352 Prj
.Env
.Initialize
(Project_Tree
);
2354 Prj
.Env
.Set_Ada_Paths
2355 (Project
, Project_Tree
, Including_Libraries
=> False);
2358 -- For gnat check, gnat sync, gnat pretty, gnat metric, gnat list,
2359 -- and gnat stack, if no file has been put on the command line, call
2360 -- tool with all the sources of the main project.
2362 elsif The_Command
= Check
or else
2363 The_Command
= Sync
or else
2364 The_Command
= Pretty
or else
2365 The_Command
= Metric
or else
2366 The_Command
= List
or else
2373 -- Gather all the arguments and invoke the executable
2376 The_Args
: Argument_List
2377 (1 .. First_Switches
.Last
+
2378 Last_Switches
.Last
+
2379 Carg_Switches
.Last
+
2380 Rules_Switches
.Last
);
2381 Arg_Num
: Natural := 0;
2384 for J
in 1 .. First_Switches
.Last
loop
2385 Arg_Num
:= Arg_Num
+ 1;
2386 The_Args
(Arg_Num
) := First_Switches
.Table
(J
);
2389 for J
in 1 .. Last_Switches
.Last
loop
2390 Arg_Num
:= Arg_Num
+ 1;
2391 The_Args
(Arg_Num
) := Last_Switches
.Table
(J
);
2394 for J
in 1 .. Carg_Switches
.Last
loop
2395 Arg_Num
:= Arg_Num
+ 1;
2396 The_Args
(Arg_Num
) := Carg_Switches
.Table
(J
);
2399 for J
in 1 .. Rules_Switches
.Last
loop
2400 Arg_Num
:= Arg_Num
+ 1;
2401 The_Args
(Arg_Num
) := Rules_Switches
.Table
(J
);
2404 -- If Display_Command is on, only display the generated command
2406 if Display_Command
then
2407 Put
(Standard_Error
, "generated command -->");
2408 Put
(Standard_Error
, Exec_Path
.all);
2410 for Arg
in The_Args
'Range loop
2411 Put
(Standard_Error
, " ");
2412 Put
(Standard_Error
, The_Args
(Arg
).all);
2415 Put
(Standard_Error
, "<--");
2416 New_Line
(Standard_Error
);
2420 if Verbose_Mode
then
2421 Output
.Write_Str
(Exec_Path
.all);
2423 for Arg
in The_Args
'Range loop
2424 Output
.Write_Char
(' ');
2425 Output
.Write_Str
(The_Args
(Arg
).all);
2432 Exit_Status
(Spawn
(Exec_Path
.all, The_Args
));
2439 if not Keep_Temporary_Files
then
2440 Prj
.Delete_All_Temp_Files
(Project_Tree
);
2441 Delete_Temp_Config_Files
;
2444 Set_Exit_Status
(Failure
);
2447 if not Keep_Temporary_Files
then
2448 Prj
.Delete_All_Temp_Files
(Project_Tree
);
2449 Delete_Temp_Config_Files
;
2452 -- Since GNATCmd is normally called from DCL (the VMS shell), it must
2453 -- return an understandable VMS exit status. However the exit status
2454 -- returned *to* GNATCmd is a Posix style code, so we test it and return
2455 -- just a simple success or failure on VMS.
2457 if Hostparm
.OpenVMS
and then My_Exit_Status
/= Success
then
2458 Set_Exit_Status
(Failure
);
2460 Set_Exit_Status
(My_Exit_Status
);