1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1996-2004 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
30 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;
41 with Snames; use Snames;
43 with Types; use Types;
44 with Hostparm; use Hostparm;
45 -- Used to determine if we are in VMS or not for error message purposes
47 with Ada.Characters.Handling; use Ada.Characters.Handling;
48 with Ada.Command_Line; use Ada.Command_Line;
49 with Ada.Text_IO; use Ada.Text_IO;
51 with GNAT.OS_Lib; use GNAT.OS_Lib;
55 with VMS_Conv; use VMS_Conv;
58 Project_File : String_Access;
59 Project : Prj.Project_Id;
60 Current_Verbosity : Prj.Verbosity := Prj.Default;
61 Tool_Package_Name : Name_Id := No_Name;
63 -- This flag indicates a switch -p (for gnatxref and gnatfind) for
64 -- an old fashioned project file. -p cannot be used in conjonction
67 Old_Project_File_Used : Boolean := False;
69 -- A table to keep the switches from the project file
71 package First_Switches is new Table.Table
72 (Table_Component_Type => String_Access,
73 Table_Index_Type => Integer,
76 Table_Increment => 100,
77 Table_Name => "Gnatcmd.First_Switches");
79 package Library_Paths is new Table.Table (
80 Table_Component_Type => String_Access,
81 Table_Index_Type => Integer,
84 Table_Increment => 100,
85 Table_Name => "Make.Library_Path");
87 -- Packages of project files to pass to Prj.Pars.Parse, depending on the
88 -- tool. We allocate objects because we cannot declare aliased objects
89 -- as we are in a procedure, not a library level package.
91 Naming_String : constant String_Access := new String'("naming");
92 Binder_String : constant String_Access := new String'("binder");
93 Eliminate_String : constant String_Access := new String'("eliminate");
94 Finder_String : constant String_Access := new String'("finder");
95 Linker_String : constant String_Access := new String'("linker");
96 Gnatls_String : constant String_Access := new String'("gnatls");
97 Pretty_String : constant String_Access := new String'("pretty_printer");
98 Gnatstub_String : constant String_Access := new String'("gnatstub");
99 Xref_String : constant String_Access := new String'("cross_reference");
101 Packages_To_Check_By_Binder : constant String_List_Access :=
102 new String_List'((Naming_String, Binder_String));
104 Packages_To_Check_By_Eliminate : constant String_List_Access :=
105 new String_List'((Naming_String, Eliminate_String));
107 Packages_To_Check_By_Finder : constant String_List_Access :=
108 new String_List'((Naming_String, Finder_String));
110 Packages_To_Check_By_Linker : constant String_List_Access :=
111 new String_List'((Naming_String, Linker_String));
113 Packages_To_Check_By_Gnatls : constant String_List_Access :=
114 new String_List'((Naming_String, Gnatls_String));
116 Packages_To_Check_By_Pretty : constant String_List_Access :=
117 new String_List'((Naming_String, Pretty_String));
119 Packages_To_Check_By_Gnatstub : constant String_List_Access :=
120 new String_List'((Naming_String, Gnatstub_String));
122 Packages_To_Check_By_Xref : constant String_List_Access :=
123 new String_List'((Naming_String, Xref_String));
125 Packages_To_Check : String_List_Access := Prj.All_Packages;
127 ----------------------------------
128 -- Declarations for GNATCMD use --
129 ----------------------------------
131 The_Command : Command_Type;
133 Command_Arg : Positive := 1;
135 My_Exit_Status : Exit_Status := Success;
137 Current_Work_Dir : constant String := Get_Current_Dir;
139 -----------------------
140 -- Local Subprograms --
141 -----------------------
143 procedure Check_Relative_Executable (Name : in out String_Access);
144 -- Check if an executable is specified as a relative path.
145 -- If it is, and the path contains directory information, fail.
146 -- Otherwise, prepend the exec directory.
147 -- This procedure is only used for GNAT LINK when a project file
150 function Configuration_Pragmas_File return Name_Id;
151 -- Return an argument, if there is a configuration pragmas file to be
152 -- specified for Project, otherwise return No_Name.
153 -- Used for gnatstub (GNAT STUB), gnatpp (GNAT PRETTY) and gnatelim
156 procedure Delete_Temp_Config_Files;
157 -- Delete all temporary config files
159 function Index (Char : Character; Str : String) return Natural;
160 -- Returns the first occurrence of Char in Str.
161 -- Returns 0 if Char is not in Str.
163 procedure Non_VMS_Usage;
164 -- Display usage for platforms other than VMS
166 procedure Set_Library_For
167 (Project : Project_Id;
168 There_Are_Libraries : in out Boolean);
169 -- If Project is a library project, add the correct
170 -- -L and -l switches to the linker invocation.
172 procedure Set_Libraries is
173 new For_Every_Project_Imported (Boolean, Set_Library_For);
174 -- Add the -L and -l switches to the linker for all
175 -- of the library projects.
177 procedure Test_If_Relative_Path
178 (Switch : in out String_Access;
180 -- Test if Switch is a relative search path switch.
181 -- If it is and it includes directory information, prepend the path with
182 -- Parent.This subprogram is only called when using project files.
184 -------------------------------
185 -- Check_Relative_Executable --
186 -------------------------------
188 procedure Check_Relative_Executable (Name : in out String_Access) is
189 Exec_File_Name : constant String := Name.all;
192 if not Is_Absolute_Path (Exec_File_Name) then
193 for Index in Exec_File_Name'Range loop
194 if Exec_File_Name (Index) = Directory_Separator then
195 Fail ("relative executable (""" &
197 """) with directory part not allowed " &
198 "when using project files");
202 Get_Name_String (Projects.Table
203 (Project).Exec_Directory);
205 if Name_Buffer (Name_Len) /= Directory_Separator then
206 Name_Len := Name_Len + 1;
207 Name_Buffer (Name_Len) := Directory_Separator;
210 Name_Buffer (Name_Len + 1 ..
211 Name_Len + Exec_File_Name'Length) :=
213 Name_Len := Name_Len + Exec_File_Name'Length;
214 Name := new String'(Name_Buffer (1 .. Name_Len));
216 end Check_Relative_Executable;
218 --------------------------------
219 -- Configuration_Pragmas_File --
220 --------------------------------
222 function Configuration_Pragmas_File return Name_Id is
224 Prj.Env.Create_Config_Pragmas_File
225 (Project, Project, Include_Config_Files => False);
226 return Projects.Table (Project).Config_File_Name;
227 end Configuration_Pragmas_File;
229 ------------------------------
230 -- Delete_Temp_Config_Files --
231 ------------------------------
233 procedure Delete_Temp_Config_Files is
237 if Project /= No_Project then
238 for Prj in 1 .. Projects.Last loop
239 if Projects.Table (Prj).Config_File_Temp then
240 if Opt.Verbose_Mode then
241 Output.Write_Str ("Deleting temp configuration file """);
242 Output.Write_Str (Get_Name_String
243 (Projects.Table (Prj).Config_File_Name));
244 Output.Write_Line ("""");
248 (Name => Get_Name_String
249 (Projects.Table (Prj).Config_File_Name),
254 end Delete_Temp_Config_Files;
260 function Index (Char : Character; Str : String) return Natural is
262 for Index in Str'Range loop
263 if Str (Index) = Char then
271 ---------------------
272 -- Set_Library_For --
273 ---------------------
275 procedure Set_Library_For
276 (Project : Project_Id;
277 There_Are_Libraries : in out Boolean)
279 Path_Option : constant String_Access :=
280 MLib.Tgt.Linker_Library_Path_Option;
283 -- Case of library project
285 if Projects.Table (Project).Library then
286 There_Are_Libraries := True;
290 Last_Switches.Increment_Last;
291 Last_Switches.Table (Last_Switches.Last) :=
294 (Projects.Table (Project).Library_Dir));
298 Last_Switches.Increment_Last;
299 Last_Switches.Table (Last_Switches.Last) :=
302 (Projects.Table (Project).Library_Name));
304 -- Add the directory to table Library_Paths, to be processed later
305 -- if library is not static and if Path_Option is not null.
307 if Projects.Table (Project).Library_Kind /= Static
308 and then Path_Option /= null
310 Library_Paths.Increment_Last;
311 Library_Paths.Table (Library_Paths.Last) :=
312 new String'(Get_Name_String
313 (Projects.Table (Project).Library_Dir));
319 ---------------------------
320 -- Test_If_Relative_Path --
321 ---------------------------
323 procedure Test_If_Relative_Path
324 (Switch : in out String_Access;
328 if Switch /= null then
331 Sw : String (1 .. Switch'Length);
332 Start : Positive := 1;
339 and then (Sw (2) = 'A'
341 or else Sw (2) = 'L')
350 and then (Sw (2 .. 3) = "aL"
351 or else Sw (2 .. 3) = "aO"
352 or else Sw (2 .. 3) = "aI")
357 and then Sw (2 .. 6) = "-RTS="
365 -- If the path is relative, test if it includes directory
366 -- information. If it does, prepend Parent to the path.
368 if not Is_Absolute_Path (Sw (Start .. Sw'Last)) then
369 for J in Start .. Sw'Last loop
370 if Sw (J) = Directory_Separator then
373 (Sw (1 .. Start - 1) &
375 Directory_Separator &
376 Sw (Start .. Sw'Last));
383 end Test_If_Relative_Path;
389 procedure Non_VMS_Usage is
393 Put_Line ("List of available commands");
396 for C in Command_List'Range loop
397 if not Command_List (C).VMS_Only then
398 Put ("GNAT " & Command_List (C).Cname.all);
400 Put (Command_List (C).Unixcmd.all);
403 Sws : Argument_List_Access renames Command_List (C).Unixsws;
406 for J in Sws'Range loop
418 Put_Line ("Commands FIND, LIST, PRETTY, STUB and XREF accept " &
419 "project file switches -vPx, -Pprj and -Xnam=val");
423 -------------------------------------
424 -- Start of processing for GNATCmd --
425 -------------------------------------
438 Last_Switches.Set_Last (0);
441 First_Switches.Set_Last (0);
445 -- If on VMS, or if VMS emulation is on, convert VMS style /qualifiers,
446 -- filenames and pathnames to Unix style.
449 or else To_Lower (Getenv ("EMULATE_VMS").all) = "true"
451 VMS_Conversion (The_Command);
453 -- If not on VMS, scan the command line directly
456 if Argument_Count = 0 then
461 if Argument_Count > 1 and then Argument (1) = "-v" then
462 Opt.Verbose_Mode := True;
466 The_Command := Real_Command_Type'Value (Argument (Command_Arg));
468 if Command_List (The_Command).VMS_Only then
472 Command_List (The_Command).Cname.all,
473 """ can only be used on VMS");
477 when Constraint_Error =>
479 -- Check if it is an alternate command
482 Alternate : Alternate_Command;
485 Alternate := Alternate_Command'Value
486 (Argument (Command_Arg));
487 The_Command := Corresponding_To (Alternate);
490 when Constraint_Error =>
492 Fail ("Unknown command: ", Argument (Command_Arg));
496 -- Get the arguments from the command line and from the eventual
497 -- argument file(s) specified on the command line.
499 for Arg in Command_Arg + 1 .. Argument_Count loop
501 The_Arg : constant String := Argument (Arg);
503 -- Check if an argument file is specified
505 if The_Arg (The_Arg'First) = '@' then
507 Arg_File : Ada.Text_IO.File_Type;
508 Line : String (1 .. 256);
512 -- Open the file. Fail if the file cannot be found.
517 The_Arg (The_Arg'First + 1 .. The_Arg'Last));
522 (Standard_Error, "Cannot open argument file """);
525 The_Arg (The_Arg'First + 1 .. The_Arg'Last));
527 Put_Line (Standard_Error, """");
531 -- Read line by line and put the content of each
532 -- non empty line in the Last_Switches table.
534 while not End_Of_File (Arg_File) loop
535 Get_Line (Arg_File, Line, Last);
538 Last_Switches.Increment_Last;
539 Last_Switches.Table (Last_Switches.Last) :=
540 new String'(Line (1 .. Last));
548 -- It is not an argument file; just put the argument in
549 -- the Last_Switches table.
551 Last_Switches.Increment_Last;
552 Last_Switches.Table (Last_Switches.Last) :=
553 new String'(The_Arg);
561 Program : constant String :=
562 Program_Name (Command_List (The_Command).Unixcmd.all).all;
564 Exec_Path : String_Access;
567 -- Locate the executable for the command
569 Exec_Path := Locate_Exec_On_Path (Program);
571 if Exec_Path = null then
572 Put_Line (Standard_Error, "Couldn't locate " & Program);
576 -- If there are switches for the executable, put them as first switches
578 if Command_List (The_Command).Unixsws /= null then
579 for J in Command_List (The_Command).Unixsws'Range loop
580 First_Switches.Increment_Last;
581 First_Switches.Table (First_Switches.Last) :=
582 Command_List (The_Command).Unixsws (J);
586 -- For BIND, FIND, LINK, LIST, PRETTY ad XREF, look for project file
589 if The_Command = Bind
590 or else The_Command = Elim
591 or else The_Command = Find
592 or else The_Command = Link
593 or else The_Command = List
594 or else The_Command = Xref
595 or else The_Command = Pretty
596 or else The_Command = Stub
600 Tool_Package_Name := Name_Binder;
601 Packages_To_Check := Packages_To_Check_By_Binder;
603 Tool_Package_Name := Name_Eliminate;
604 Packages_To_Check := Packages_To_Check_By_Eliminate;
606 Tool_Package_Name := Name_Finder;
607 Packages_To_Check := Packages_To_Check_By_Finder;
609 Tool_Package_Name := Name_Linker;
610 Packages_To_Check := Packages_To_Check_By_Linker;
612 Tool_Package_Name := Name_Gnatls;
613 Packages_To_Check := Packages_To_Check_By_Gnatls;
615 Tool_Package_Name := Name_Pretty_Printer;
616 Packages_To_Check := Packages_To_Check_By_Pretty;
618 Tool_Package_Name := Name_Gnatstub;
619 Packages_To_Check := Packages_To_Check_By_Gnatstub;
621 Tool_Package_Name := Name_Cross_Reference;
622 Packages_To_Check := Packages_To_Check_By_Xref;
627 -- Check that the switches are consistent.
628 -- Detect project file related switches.
632 Arg_Num : Positive := 1;
633 Argv : String_Access;
635 procedure Remove_Switch (Num : Positive);
636 -- Remove a project related switch from table Last_Switches
642 procedure Remove_Switch (Num : Positive) is
644 Last_Switches.Table (Num .. Last_Switches.Last - 1) :=
645 Last_Switches.Table (Num + 1 .. Last_Switches.Last);
646 Last_Switches.Decrement_Last;
649 -- Start of processing for Inspect_Switches
652 while Arg_Num <= Last_Switches.Last loop
653 Argv := Last_Switches.Table (Arg_Num);
655 if Argv (Argv'First) = '-' then
656 if Argv'Length = 1 then
658 ("switch character cannot be followed by a blank");
661 -- The two style project files (-p and -P) cannot be used
664 if (The_Command = Find or else The_Command = Xref)
665 and then Argv (2) = 'p'
667 Old_Project_File_Used := True;
668 if Project_File /= null then
669 Fail ("-P and -p cannot be used together");
673 -- -vPx Specify verbosity while parsing project files
676 and then Argv (Argv'First + 1 .. Argv'First + 2) = "vP"
678 case Argv (Argv'Last) is
680 Current_Verbosity := Prj.Default;
682 Current_Verbosity := Prj.Medium;
684 Current_Verbosity := Prj.High;
686 Fail ("Invalid switch: ", Argv.all);
689 Remove_Switch (Arg_Num);
691 -- -Pproject_file Specify project file to be used
693 elsif Argv (Argv'First + 1) = 'P' then
695 -- Only one -P switch can be used
697 if Project_File /= null then
700 ": second project file forbidden (first is """,
701 Project_File.all & """)");
703 -- The two style project files (-p and -P) cannot be
706 elsif Old_Project_File_Used then
707 Fail ("-p and -P cannot be used together");
709 elsif Argv'Length = 2 then
710 -- There is space between -P and the project file
711 -- name. -P cannot be the last option.
713 if Arg_Num = Last_Switches.Last then
714 Fail ("project file name missing after -P");
717 Remove_Switch (Arg_Num);
718 Argv := Last_Switches.Table (Arg_Num);
720 -- After -P, there must be a project file name,
721 -- not another switch.
723 if Argv (Argv'First) = '-' then
724 Fail ("project file name missing after -P");
727 Project_File := new String'(Argv.all);
732 -- No space between -P and project file name
735 new String'(Argv (Argv'First + 2 .. Argv'Last));
738 Remove_Switch (Arg_Num);
740 -- -Xexternal=value Specify an external reference to be
741 -- used in project files
743 elsif Argv'Length >= 5
744 and then Argv (Argv'First + 1) = 'X'
747 Equal_Pos : constant Natural :=
748 Index ('=', Argv (Argv'First + 2 .. Argv'Last));
750 if Equal_Pos >= Argv'First + 3 and then
751 Equal_Pos /= Argv'Last then
752 Add (External_Name =>
753 Argv (Argv'First + 2 .. Equal_Pos - 1),
754 Value => Argv (Equal_Pos + 1 .. Argv'Last));
758 " is not a valid external assignment.");
762 Remove_Switch (Arg_Num);
765 Arg_Num := Arg_Num + 1;
769 Arg_Num := Arg_Num + 1;
772 end Inspect_Switches;
775 -- If there is a project file specified, parse it, get the switches
776 -- for the tool and setup PATH environment variables.
778 if Project_File /= null then
779 Prj.Pars.Set_Verbosity (To => Current_Verbosity);
783 Project_File_Name => Project_File.all,
784 Packages_To_Check => Packages_To_Check);
786 if Project = Prj.No_Project then
787 Fail ("""", Project_File.all, """ processing failed");
790 -- Check if a package with the name of the tool is in the project
791 -- file and if there is one, get the switches, if any, and scan them.
794 Data : constant Prj.Project_Data :=
795 Prj.Projects.Table (Project);
797 Pkg : constant Prj.Package_Id :=
799 (Name => Tool_Package_Name,
800 In_Packages => Data.Decl.Packages);
802 Element : Package_Element;
804 Default_Switches_Array : Array_Element_Id;
806 The_Switches : Prj.Variable_Value;
807 Current : Prj.String_List_Id;
808 The_String : String_Element;
811 if Pkg /= No_Package then
812 Element := Packages.Table (Pkg);
814 -- Packages Gnatls has a single attribute Switches, that is
815 -- not an associative array.
817 if The_Command = List then
820 (Variable_Name => Snames.Name_Switches,
821 In_Variables => Element.Decl.Attributes);
823 -- Packages Binder (for gnatbind), Cross_Reference (for
824 -- gnatxref), Linker (for gnatlink) Finder (for gnatfind),
825 -- Pretty_Printer (for gnatpp) and Eliminate (for gnatelim)
826 -- have an attributed Switches, an associative array, indexed
827 -- by the name of the file.
828 -- They also have an attribute Default_Switches, indexed
829 -- by the name of the programming language.
832 if The_Switches.Kind = Prj.Undefined then
833 Default_Switches_Array :=
835 (Name => Name_Default_Switches,
836 In_Arrays => Packages.Table (Pkg).Decl.Arrays);
837 The_Switches := Prj.Util.Value_Of
839 In_Array => Default_Switches_Array);
843 -- If there are switches specified in the package of the
844 -- project file corresponding to the tool, scan them.
846 case The_Switches.Kind is
847 when Prj.Undefined =>
852 Switch : constant String :=
853 Get_Name_String (The_Switches.Value);
856 if Switch'Length > 0 then
857 First_Switches.Increment_Last;
858 First_Switches.Table (First_Switches.Last) :=
864 Current := The_Switches.Values;
865 while Current /= Prj.Nil_String loop
866 The_String := String_Elements.Table (Current);
869 Switch : constant String :=
870 Get_Name_String (The_String.Value);
873 if Switch'Length > 0 then
874 First_Switches.Increment_Last;
875 First_Switches.Table (First_Switches.Last) :=
880 Current := The_String.Next;
886 if The_Command = Bind
887 or else The_Command = Link
888 or else The_Command = Elim
892 (Projects.Table (Project).Object_Directory));
895 -- Set up the env vars for project path files
897 Prj.Env.Set_Ada_Paths (Project, Including_Libraries => False);
899 -- For gnatstub, gnatpp and gnatelim, create a configuration pragmas
900 -- file, if necessary.
902 if The_Command = Pretty
903 or else The_Command = Stub
904 or else The_Command = Elim
907 CP_File : constant Name_Id := Configuration_Pragmas_File;
910 if CP_File /= No_Name then
911 First_Switches.Increment_Last;
913 if The_Command = Elim then
914 First_Switches.Table (First_Switches.Last) :=
915 new String'("-C" & Get_Name_String (CP_File));
918 First_Switches.Table (First_Switches.Last) :=
919 new String'("-gnatec=" & Get_Name_String (CP_File));
925 if The_Command = Link then
927 -- Add the default search directories, to be able to find
928 -- libgnat in call to MLib.Utl.Lib_Directory.
930 Add_Default_Search_Dirs;
933 There_Are_Libraries : Boolean := False;
934 Path_Option : constant String_Access :=
935 MLib.Tgt.Linker_Library_Path_Option;
938 Library_Paths.Set_Last (0);
940 -- Check if there are library project files
942 if MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None then
943 Set_Libraries (Project, There_Are_Libraries);
946 -- If there are, add the necessary additional switches
948 if There_Are_Libraries then
950 -- Add -L<lib_dir> -lgnarl -lgnat -Wl,-rpath,<lib_dir>
952 Last_Switches.Increment_Last;
953 Last_Switches.Table (Last_Switches.Last) :=
954 new String'("-L" & MLib.Utl.Lib_Directory);
955 Last_Switches.Increment_Last;
956 Last_Switches.Table (Last_Switches.Last) :=
957 new String'("-lgnarl");
958 Last_Switches.Increment_Last;
959 Last_Switches.Table (Last_Switches.Last) :=
960 new String'("-lgnat");
962 -- If Path_Option is not null, create the switch
963 -- ("-Wl,-rpath," or equivalent) with all the library dirs
964 -- plus the standard GNAT library dir.
966 if Path_Option /= null then
968 Option : String_Access;
969 Length : Natural := Path_Option'Length;
973 -- First, compute the exact length for the switch
976 Library_Paths.First .. Library_Paths.Last
978 -- Add the length of the library dir plus one
979 -- for the directory separator.
983 Library_Paths.Table (Index)'Length + 1;
986 -- Finally, add the length of the standard GNAT
989 Length := Length + MLib.Utl.Lib_Directory'Length;
990 Option := new String (1 .. Length);
991 Option (1 .. Path_Option'Length) := Path_Option.all;
992 Current := Path_Option'Length;
994 -- Put each library dir followed by a dir separator
997 Library_Paths.First .. Library_Paths.Last
1002 Library_Paths.Table (Index)'Length) :=
1003 Library_Paths.Table (Index).all;
1006 Library_Paths.Table (Index)'Length + 1;
1007 Option (Current) := Path_Separator;
1010 -- Finally put the standard GNAT library dir
1014 Current + MLib.Utl.Lib_Directory'Length) :=
1015 MLib.Utl.Lib_Directory;
1017 -- And add the switch to the last switches
1019 Last_Switches.Increment_Last;
1020 Last_Switches.Table (Last_Switches.Last) :=
1027 -- Check if the first ALI file specified can be found, either
1028 -- in the object directory of the main project or in an object
1029 -- directory of a project file extended by the main project.
1030 -- If the ALI file can be found, replace its name with its
1034 Skip_Executable : Boolean := False;
1037 Switch_Loop : for J in 1 .. Last_Switches.Last loop
1039 -- If we have an executable just reset the flag
1041 if Skip_Executable then
1042 Skip_Executable := False;
1044 -- If -o, set flag so that next switch is not processed
1046 elsif Last_Switches.Table (J).all = "-o" then
1047 Skip_Executable := True;
1053 Switch : constant String :=
1054 Last_Switches.Table (J).all;
1056 ALI_File : constant String (1 .. Switch'Length + 4) :=
1059 Last : Natural := Switch'Length;
1060 Test_Existence : Boolean := False;
1063 -- Skip real switches
1065 if Switch'Length /= 0 and then
1066 Switch (Switch'First) /= '-'
1068 -- Append ".ali" if file name does not end with it
1070 if Switch'Length <= 4 or else
1071 Switch (Switch'Last - 3 .. Switch'Last) /= ".ali"
1073 Last := ALI_File'Last;
1076 -- If file name includes directory information,
1077 -- stop if ALI file exists.
1079 if Is_Absolute_Path (ALI_File (1 .. Last)) then
1080 Test_Existence := True;
1083 for K in Switch'Range loop
1084 if Switch (K) = '/' or else
1085 Switch (K) = Directory_Separator
1087 Test_Existence := True;
1093 if Test_Existence then
1094 if Is_Regular_File (ALI_File (1 .. Last)) then
1099 -- Look in the object directories if the ALI
1103 Prj : Project_Id := Project;
1108 Dir : constant String :=
1110 (Projects.Table (Prj).
1114 (Dir & Directory_Separator &
1115 ALI_File (1 .. Last))
1117 -- We have found the correct
1118 -- project, so we replace the file
1119 -- with the absolute path.
1121 Last_Switches.Table (J) :=
1123 (Dir & Directory_Separator &
1124 ALI_File (1 .. Last));
1132 -- Go to the project being extended,
1135 Prj := Projects.Table (Prj).Extends;
1136 exit Project_Loop when Prj = No_Project;
1137 end loop Project_Loop;
1143 end loop Switch_Loop;
1146 -- If a relative path output file has been specified, we add
1147 -- the exec directory.
1150 Look_For_Executable : Boolean := True;
1154 for J in reverse 1 .. Last_Switches.Last - 1 loop
1155 if Last_Switches.Table (J).all = "-o" then
1156 Check_Relative_Executable
1157 (Name => Last_Switches.Table (J + 1));
1158 Look_For_Executable := False;
1163 if Look_For_Executable then
1164 for J in reverse 1 .. First_Switches.Last - 1 loop
1165 if First_Switches.Table (J).all = "-o" then
1166 Look_For_Executable := False;
1167 Check_Relative_Executable
1168 (Name => First_Switches.Table (J + 1));
1174 -- If no executable is specified, then find the name
1175 -- of the first ALI file on the command line and issue
1176 -- a -o switch with the absolute path of the executable
1177 -- in the exec directory.
1179 if Look_For_Executable then
1180 for J in 1 .. Last_Switches.Last loop
1182 Arg : constant String_Access :=
1183 Last_Switches.Table (J);
1184 Last : Natural := 0;
1187 if Arg'Length /= 0 and then Arg (Arg'First) /= '-' then
1189 and then Arg (Arg'Last - 3 .. Arg'Last) = ".ali"
1191 Last := Arg'Last - 4;
1193 elsif Is_Regular_File (Arg.all & ".ali") then
1199 Executable_Name : constant String :=
1200 Base_Name (Arg (Arg'First .. Last));
1202 Last_Switches.Increment_Last;
1203 Last_Switches.Table (Last_Switches.Last) :=
1206 (Projects.Table (Project).Exec_Directory);
1207 Last_Switches.Increment_Last;
1208 Last_Switches.Table (Last_Switches.Last) :=
1209 new String'(Name_Buffer (1 .. Name_Len) &
1210 Directory_Separator &
1212 Get_Executable_Suffix.all);
1223 if The_Command = Link or The_Command = Bind then
1225 -- For files that are specified as relative paths with directory
1226 -- information, we convert them to absolute paths, with parent
1227 -- being the current working directory if specified on the command
1228 -- line and the project directory if specified in the project
1229 -- file. This is what gnatmake is doing for linker and binder
1232 for J in 1 .. Last_Switches.Last loop
1233 Test_If_Relative_Path
1234 (Last_Switches.Table (J), Current_Work_Dir);
1237 Get_Name_String (Projects.Table (Project).Directory);
1240 Project_Dir : constant String := Name_Buffer (1 .. Name_Len);
1243 for J in 1 .. First_Switches.Last loop
1244 Test_If_Relative_Path
1245 (First_Switches.Table (J), Project_Dir);
1249 elsif The_Command = Stub then
1251 Data : constant Prj.Project_Data :=
1252 Prj.Projects.Table (Project);
1253 File_Index : Integer := 0;
1254 Dir_Index : Integer := 0;
1255 Last : constant Integer := Last_Switches.Last;
1258 for Index in 1 .. Last loop
1259 if Last_Switches.Table (Index)
1260 (Last_Switches.Table (Index)'First) /= '-'
1262 File_Index := Index;
1267 -- If the naming scheme of the project file is not standard,
1268 -- and if the file name ends with the spec suffix, then
1269 -- indicate to gnatstub the name of the body file with
1272 if Data.Naming.Current_Spec_Suffix /=
1273 Prj.Default_Ada_Spec_Suffix
1275 if File_Index /= 0 then
1277 Spec : constant String :=
1278 Base_Name (Last_Switches.Table (File_Index).all);
1279 Last : Natural := Spec'Last;
1282 Get_Name_String (Data.Naming.Current_Spec_Suffix);
1284 if Spec'Length > Name_Len
1285 and then Spec (Last - Name_Len + 1 .. Last) =
1286 Name_Buffer (1 .. Name_Len)
1288 Last := Last - Name_Len;
1289 Get_Name_String (Data.Naming.Current_Body_Suffix);
1290 Last_Switches.Increment_Last;
1291 Last_Switches.Table (Last_Switches.Last) :=
1293 Last_Switches.Increment_Last;
1294 Last_Switches.Table (Last_Switches.Last) :=
1295 new String'(Spec (Spec'First .. Last) &
1296 Name_Buffer (1 .. Name_Len));
1302 -- Add the directory of the spec as the destination directory
1303 -- of the body, if there is no destination directory already
1306 if File_Index /= 0 then
1307 for Index in File_Index + 1 .. Last loop
1308 if Last_Switches.Table (Index)
1309 (Last_Switches.Table (Index)'First) /= '-'
1316 if Dir_Index = 0 then
1317 Last_Switches.Increment_Last;
1318 Last_Switches.Table (Last_Switches.Last) :=
1320 (Dir_Name (Last_Switches.Table (File_Index).all));
1327 -- Gather all the arguments and invoke the executable
1330 The_Args : Argument_List
1331 (1 .. First_Switches.Last + Last_Switches.Last);
1332 Arg_Num : Natural := 0;
1334 for J in 1 .. First_Switches.Last loop
1335 Arg_Num := Arg_Num + 1;
1336 The_Args (Arg_Num) := First_Switches.Table (J);
1339 for J in 1 .. Last_Switches.Last loop
1340 Arg_Num := Arg_Num + 1;
1341 The_Args (Arg_Num) := Last_Switches.Table (J);
1344 -- If Display_Command is on, only display the generated command
1346 if Display_Command then
1347 Put (Standard_Error, "generated command -->");
1348 Put (Standard_Error, Exec_Path.all);
1350 for Arg in The_Args'Range loop
1351 Put (Standard_Error, " ");
1352 Put (Standard_Error, The_Args (Arg).all);
1355 Put (Standard_Error, "<--");
1356 New_Line (Standard_Error);
1360 if Opt.Verbose_Mode then
1361 Output.Write_Str (Exec_Path.all);
1363 for Arg in The_Args'Range loop
1364 Output.Write_Char (' ');
1365 Output.Write_Str (The_Args (Arg).all);
1372 Exit_Status (Spawn (Exec_Path.all, The_Args));
1379 Prj.Env.Delete_All_Path_Files;
1380 Delete_Temp_Config_Files;
1381 Set_Exit_Status (Failure);
1384 Prj.Env.Delete_All_Path_Files;
1385 Delete_Temp_Config_Files;
1387 -- Since GNATCmd is normally called from DCL (the VMS shell),
1388 -- it must return an understandable VMS exit status. However
1389 -- the exit status returned *to* GNATCmd is a Posix style code,
1390 -- so we test it and return just a simple success or failure on VMS.
1392 if Hostparm.OpenVMS and then My_Exit_Status /= Success then
1393 Set_Exit_Status (Failure);
1395 Set_Exit_Status (My_Exit_Status);