1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, 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 ------------------------------------------------------------------------------
27 with ALI
.Util
; use ALI
.Util
;
28 with Binderr
; use Binderr
;
29 with Butil
; use Butil
;
30 with Csets
; use Csets
;
31 with Fname
; use Fname
;
32 with Gnatvsn
; use Gnatvsn
;
33 with GNAT
.OS_Lib
; use GNAT
.OS_Lib
;
34 with Namet
; use Namet
;
36 with Osint
; use Osint
;
37 with Osint
.L
; use Osint
.L
;
38 with Output
; use Output
;
39 with Prj
.Env
; use Prj
.Env
;
40 with Rident
; use Rident
;
44 with Switch
; use Switch
;
45 with Targparm
; use Targparm
;
46 with Types
; use Types
;
48 with Ada
.Command_Line
; use Ada
.Command_Line
;
50 with GNAT
.Command_Line
; use GNAT
.Command_Line
;
51 with GNAT
.Case_Util
; use GNAT
.Case_Util
;
54 pragma Ident
(Gnat_Static_Version_String
);
56 -- NOTE : The following string may be used by other tools, such as GPS. So
57 -- it can only be modified if these other uses are checked and coordinated.
59 Project_Search_Path
: constant String := "Project Search Path:";
60 -- Label displayed in verbose mode before the directories in the project
61 -- search path. Do not modify without checking NOTE above.
63 Prj_Path
: Prj
.Env
.Project_Search_Path
;
65 Max_Column
: constant := 80;
67 No_Obj
: aliased String := "<no_obj>";
70 OK
, -- matching timestamp
71 Checksum_OK
, -- only matching checksum
72 Not_Found
, -- file not found on source PATH
73 Not_Same
, -- neither checksum nor timestamp matching
74 Not_First_On_PATH
); -- matching file hidden by Not_Same file on path
77 type Dir_Ref
is access Dir_Data
;
79 type Dir_Data
is record
80 Value
: String_Access
;
83 -- Simply linked list of dirs
85 First_Source_Dir
: Dir_Ref
;
86 Last_Source_Dir
: Dir_Ref
;
87 -- The list of source directories from the command line.
88 -- These directories are added using Osint.Add_Src_Search_Dir
89 -- after those of the GNAT Project File, if any.
91 First_Lib_Dir
: Dir_Ref
;
92 Last_Lib_Dir
: Dir_Ref
;
93 -- The list of object directories from the command line.
94 -- These directories are added using Osint.Add_Lib_Search_Dir
95 -- after those of the GNAT Project File, if any.
97 Main_File
: File_Name_Type
;
98 Ali_File
: File_Name_Type
;
99 Text
: Text_Buffer_Ptr
;
102 Too_Long
: Boolean := False;
103 -- When True, lines are too long for multi-column output and each
104 -- item of information is on a different line.
106 Selective_Output
: Boolean := False;
107 Print_Usage
: Boolean := False;
108 Print_Unit
: Boolean := True;
109 Print_Source
: Boolean := True;
110 Print_Object
: Boolean := True;
111 -- Flags controlling the form of the output
113 Also_Predef
: Boolean := False; -- -a
114 Dependable
: Boolean := False; -- -d
115 License
: Boolean := False; -- -l
116 Very_Verbose_Mode
: Boolean := False; -- -V
117 -- Command line flags
119 Unit_Start
: Integer;
121 Source_Start
: Integer;
122 Source_End
: Integer;
123 Object_Start
: Integer;
124 Object_End
: Integer;
125 -- Various column starts and ends
127 Spaces
: constant String (1 .. Max_Column
) := (others => ' ');
129 RTS_Specified
: String_Access
:= null;
130 -- Used to detect multiple use of --RTS= switch
132 -----------------------
133 -- Local Subprograms --
134 -----------------------
136 procedure Add_Lib_Dir
(Dir
: String);
137 -- Add an object directory in the list First_Lib_Dir-Last_Lib_Dir
139 procedure Add_Source_Dir
(Dir
: String);
140 -- Add a source directory in the list First_Source_Dir-Last_Source_Dir
142 procedure Find_General_Layout
;
143 -- Determine the structure of the output (multi columns or not, etc)
145 procedure Find_Status
146 (FS
: in out File_Name_Type
;
147 Stamp
: Time_Stamp_Type
;
149 Status
: out File_Status
);
150 -- Determine the file status (Status) of the file represented by FS
151 -- with the expected Stamp and checksum given as argument. FS will be
152 -- updated to the full file name if available.
154 function Corresponding_Sdep_Entry
(A
: ALI_Id
; U
: Unit_Id
) return Sdep_Id
;
155 -- Give the Sdep entry corresponding to the unit U in ali record A
157 procedure Output_Object
(O
: File_Name_Type
);
158 -- Print out the name of the object when requested
160 procedure Output_Source
(Sdep_I
: Sdep_Id
);
161 -- Print out the name and status of the source corresponding to this
164 procedure Output_Status
(FS
: File_Status
; Verbose
: Boolean);
165 -- Print out FS either in a coded form if verbose is false or in an
166 -- expanded form otherwise.
168 procedure Output_Unit
(ALI
: ALI_Id
; U_Id
: Unit_Id
);
169 -- Print out information on the unit when requested
171 procedure Reset_Print
;
172 -- Reset Print flags properly when selective output is chosen
174 procedure Scan_Ls_Arg
(Argv
: String);
175 -- Scan and process lser specific arguments. Argv is a single argument
177 procedure Search_RTS
(Name
: String);
178 -- Find include and objects path for the RTS name.
181 -- Print usage message
183 procedure Output_License_Information
;
184 -- Output license statement, and if not found, output reference to
187 function Image
(Restriction
: Restriction_Id
) return String;
188 -- Returns the capitalized image of Restriction
190 function Normalize
(Path
: String) return String;
191 -- Returns a normalized path name, except on VMS where the argument Path
192 -- is returned, to keep the host pathname syntax. On Windows, the directory
193 -- separators are set to '\' in Normalize_Pathname.
195 ------------------------------------------
196 -- GNATDIST specific output subprograms --
197 ------------------------------------------
201 -- Any modification to this subunit requires synchronization with the
204 procedure Output_ALI
(A
: ALI_Id
);
205 -- Comment required saying what this routine does ???
207 procedure Output_No_ALI
(Afile
: File_Name_Type
);
208 -- Comments required saying what this routine does ???
216 procedure Add_Lib_Dir
(Dir
: String) is
218 if First_Lib_Dir
= null then
221 (Value => new String'(Dir
),
223 Last_Lib_Dir
:= First_Lib_Dir
;
228 (Value => new String'(Dir
),
230 Last_Lib_Dir
:= Last_Lib_Dir
.Next
;
238 procedure Add_Source_Dir
(Dir
: String) is
240 if First_Source_Dir
= null then
243 (Value => new String'(Dir
),
245 Last_Source_Dir
:= First_Source_Dir
;
248 Last_Source_Dir
.Next
:=
250 (Value => new String'(Dir
),
252 Last_Source_Dir
:= Last_Source_Dir
.Next
;
256 ------------------------------
257 -- Corresponding_Sdep_Entry --
258 ------------------------------
260 function Corresponding_Sdep_Entry
262 U
: Unit_Id
) return Sdep_Id
265 for D
in ALIs
.Table
(A
).First_Sdep
.. ALIs
.Table
(A
).Last_Sdep
loop
266 if Sdep
.Table
(D
).Sfile
= Units
.Table
(U
).Sfile
then
271 Error_Msg_Unit_1
:= Units
.Table
(U
).Uname
;
272 Error_Msg_File_1
:= ALIs
.Table
(A
).Afile
;
274 Error_Msg
("wrong ALI format, can't find dependency line for $ in {");
275 Exit_Program
(E_Fatal
);
277 end Corresponding_Sdep_Entry
;
279 -------------------------
280 -- Find_General_Layout --
281 -------------------------
283 procedure Find_General_Layout
is
284 Max_Unit_Length
: Integer := 11;
285 Max_Src_Length
: Integer := 11;
286 Max_Obj_Length
: Integer := 11;
292 -- Compute maximum of each column
294 for Id
in ALIs
.First
.. ALIs
.Last
loop
295 Get_Name_String
(Units
.Table
(ALIs
.Table
(Id
).First_Unit
).Uname
);
296 if Also_Predef
or else not Is_Internal_Unit
then
300 Max_Unit_Length
:= Integer'Max (Max_Unit_Length
, Len
);
304 FS
:= Full_Source_Name
(ALIs
.Table
(Id
).Sfile
);
307 Get_Name_String
(ALIs
.Table
(Id
).Sfile
);
308 Name_Len
:= Name_Len
+ 13;
310 Get_Name_String
(FS
);
313 Max_Src_Length
:= Integer'Max (Max_Src_Length
, Name_Len
+ 1);
317 if ALIs
.Table
(Id
).No_Object
then
319 Integer'Max (Max_Obj_Length
, No_Obj
'Length);
321 Get_Name_String
(ALIs
.Table
(Id
).Ofile_Full_Name
);
322 Max_Obj_Length
:= Integer'Max (Max_Obj_Length
, Name_Len
+ 1);
328 -- Verify is output is not wider than maximum number of columns
333 (Max_Unit_Length
+ Max_Src_Length
+ Max_Obj_Length
) > Max_Column
;
335 -- Set start and end of columns
338 Object_End
:= Object_Start
- 1;
341 Object_End
:= Object_Start
+ Max_Obj_Length
;
344 Unit_Start
:= Object_End
+ 1;
345 Unit_End
:= Unit_Start
- 1;
348 Unit_End
:= Unit_Start
+ Max_Unit_Length
;
351 Source_Start
:= Unit_End
+ 1;
353 if Source_Start
> Spaces
'Last then
354 Source_Start
:= Spaces
'Last;
357 Source_End
:= Source_Start
- 1;
360 Source_End
:= Source_Start
+ Max_Src_Length
;
362 end Find_General_Layout
;
368 procedure Find_Status
369 (FS
: in out File_Name_Type
;
370 Stamp
: Time_Stamp_Type
;
372 Status
: out File_Status
)
374 Tmp1
: File_Name_Type
;
375 Tmp2
: File_Name_Type
;
378 Tmp1
:= Full_Source_Name
(FS
);
380 if Tmp1
= No_File
then
383 elsif File_Stamp
(Tmp1
) = Stamp
then
387 elsif Checksums_Match
(Get_File_Checksum
(FS
), Checksum
) then
389 Status
:= Checksum_OK
;
392 Tmp2
:= Matching_Full_Source_Name
(FS
, Stamp
);
394 if Tmp2
= No_File
then
399 Status
:= Not_First_On_PATH
;
409 package body GNATDIST
is
412 N_Indents
: Natural := 0;
443 Image
: constant array (Token_Type
) of String_Access
:=
444 (T_No_ALI
=> new String'("No_ALI"),
445 T_ALI => new String'("ALI"),
446 T_Unit
=> new String'("Unit"),
447 T_With => new String'("With"),
448 T_Source
=> new String'("Source"),
449 T_Afile => new String'("Afile"),
450 T_Ofile
=> new String'("Ofile"),
451 T_Sfile => new String'("Sfile"),
452 T_Name
=> new String'("Name"),
453 T_Main => new String'("Main"),
454 T_Kind
=> new String'("Kind"),
455 T_Flags => new String'("Flags"),
456 T_Preelaborated
=> new String'("Preelaborated"),
457 T_Pure => new String'("Pure"),
458 T_Has_RACW
=> new String'("Has_RACW"),
459 T_Remote_Types => new String'("Remote_Types"),
460 T_Shared_Passive
=> new String'("Shared_Passive"),
461 T_RCI => new String'("RCI"),
462 T_Predefined
=> new String'("Predefined"),
463 T_Internal => new String'("Internal"),
464 T_Is_Generic
=> new String'("Is_Generic"),
465 T_Procedure => new String'("procedure"),
466 T_Function
=> new String'("function"),
467 T_Package => new String'("package"),
468 T_Subprogram
=> new String'("subprogram"),
469 T_Spec => new String'("spec"),
470 T_Body
=> new String'("body"));
472 procedure Output_Name (N : Name_Id);
473 -- Remove any encoding info (%b and %s) and output N
475 procedure Output_Afile (A : File_Name_Type);
476 procedure Output_Ofile (O : File_Name_Type);
477 procedure Output_Sfile (S : File_Name_Type);
478 -- Output various names. Check that the name is different from no name.
479 -- Otherwise, skip the output.
481 procedure Output_Token (T : Token_Type);
482 -- Output token using specific format. That is several indentations and:
484 -- T_No_ALI .. T_With : <token> & " =>" & NL
485 -- T_Source .. T_Kind : <token> & " => "
486 -- T_Flags : <token> & " =>"
487 -- T_Preelab .. T_Body : " " & <token>
489 procedure Output_Sdep (S : Sdep_Id);
490 procedure Output_Unit (U : Unit_Id);
491 procedure Output_With (W : With_Id);
492 -- Output this entry as a global section (like ALIs)
498 procedure Output_Afile (A : File_Name_Type) is
501 Output_Token (T_Afile);
511 procedure Output_ALI (A : ALI_Id) is
513 Output_Token (T_ALI);
514 N_Indents := N_Indents + 1;
516 Output_Afile (ALIs.Table (A).Afile);
517 Output_Ofile (ALIs.Table (A).Ofile_Full_Name);
518 Output_Sfile (ALIs.Table (A).Sfile);
522 if ALIs.Table (A).Main_Program /= None then
523 Output_Token (T_Main);
525 if ALIs.Table (A).Main_Program = Proc then
526 Output_Token (T_Procedure);
528 Output_Token (T_Function);
536 for U in ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit loop
542 for S in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
546 N_Indents := N_Indents - 1;
553 procedure Output_No_ALI (Afile : File_Name_Type) is
555 Output_Token (T_No_ALI);
556 N_Indents := N_Indents + 1;
557 Output_Afile (Afile);
558 N_Indents := N_Indents - 1;
565 procedure Output_Name (N : Name_Id) is
567 -- Remove any encoding info (%s or %b)
572 and then Name_Buffer (Name_Len - 1) = '%'
574 Name_Len := Name_Len - 2;
577 Output_Token (T_Name);
578 Write_Str (Name_Buffer (1 .. Name_Len));
586 procedure Output_Ofile (O : File_Name_Type) is
589 Output_Token (T_Ofile);
599 procedure Output_Sdep (S : Sdep_Id) is
601 Output_Token (T_Source);
602 Write_Name (Sdep.Table (S).Sfile);
610 procedure Output_Sfile (S : File_Name_Type) is
611 FS : File_Name_Type := S;
614 if FS /= No_File then
616 -- We want to output the full source name
618 FS := Full_Source_Name (FS);
620 -- There is no full source name. This occurs for instance when a
621 -- withed unit has a spec file but no body file. This situation is
622 -- not a problem for GNATDIST since the unit may be located on a
623 -- partition we do not want to build. However, we need to locate
624 -- the spec file and to find its full source name. Replace the
625 -- body file name with the spec file name used to compile the
626 -- current unit when possible.
632 and then Name_Buffer (Name_Len - 3 .. Name_Len) = ".adb"
634 Name_Buffer (Name_Len) := 's
';
635 FS := Full_Source_Name (Name_Find);
640 if FS /= No_File then
641 Output_Token (T_Sfile);
651 procedure Output_Token (T : Token_Type) is
653 if T in T_No_ALI .. T_Flags then
654 for J in 1 .. N_Indents loop
658 Write_Str (Image (T).all);
660 for J in Image (T)'Length .. 12 loop
666 if T in T_No_ALI .. T_With then
668 elsif T in T_Source .. T_Name then
672 elsif T in T_Preelaborated .. T_Body then
673 if T in T_Preelaborated .. T_Is_Generic then
675 Output_Token (T_Flags);
678 N_Flags := N_Flags + 1;
682 Write_Str (Image (T).all);
685 Write_Str (Image (T).all);
693 procedure Output_Unit (U : Unit_Id) is
695 Output_Token (T_Unit);
696 N_Indents := N_Indents + 1;
700 Output_Name (Name_Id (Units.Table (U).Uname));
704 Output_Token (T_Kind);
706 if Units.Table (U).Unit_Kind = 'p
' then
707 Output_Token (T_Package);
709 Output_Token (T_Subprogram);
712 if Name_Buffer (Name_Len) = 's
' then
713 Output_Token (T_Spec);
715 Output_Token (T_Body);
720 -- Output source file name
722 Output_Sfile (Units.Table (U).Sfile);
728 if Units.Table (U).Preelab then
729 Output_Token (T_Preelaborated);
732 if Units.Table (U).Pure then
733 Output_Token (T_Pure);
736 if Units.Table (U).Has_RACW then
737 Output_Token (T_Has_RACW);
740 if Units.Table (U).Remote_Types then
741 Output_Token (T_Remote_Types);
744 if Units.Table (U).Shared_Passive then
745 Output_Token (T_Shared_Passive);
748 if Units.Table (U).RCI then
749 Output_Token (T_RCI);
752 if Units.Table (U).Predefined then
753 Output_Token (T_Predefined);
756 if Units.Table (U).Internal then
757 Output_Token (T_Internal);
760 if Units.Table (U).Is_Generic then
761 Output_Token (T_Is_Generic);
770 for W in Units.Table (U).First_With .. Units.Table (U).Last_With loop
774 N_Indents := N_Indents - 1;
781 procedure Output_With (W : With_Id) is
783 Output_Token (T_With);
784 N_Indents := N_Indents + 1;
786 Output_Name (Name_Id (Withs.Table (W).Uname));
790 Output_Token (T_Kind);
792 if Name_Buffer (Name_Len) = 's
' then
793 Output_Token (T_Spec);
795 Output_Token (T_Body);
800 Output_Afile (Withs.Table (W).Afile);
801 Output_Sfile (Withs.Table (W).Sfile);
803 N_Indents := N_Indents - 1;
812 function Image (Restriction : Restriction_Id) return String is
813 Result : String := Restriction'Img;
814 Skip : Boolean := True;
817 for J in Result'Range loop
820 Result (J) := To_Upper (Result (J));
822 elsif Result (J) = '_
' then
826 Result (J) := To_Lower (Result (J));
837 function Normalize (Path : String) return String is
839 if OpenVMS_On_Target then
842 return Normalize_Pathname (Path);
846 --------------------------------
847 -- Output_License_Information --
848 --------------------------------
850 procedure Output_License_Information is
854 Write_Str ("Please refer to file COPYING in your distribution"
855 & " for license terms.");
859 Exit_Program (E_Success);
860 end Output_License_Information;
866 procedure Output_Object (O : File_Name_Type) is
867 Object_Name : String_Access;
873 Object_Name := To_Host_File_Spec (Name_Buffer (1 .. Name_Len));
875 Object_Name := No_Obj'Unchecked_Access;
878 Write_Str (Object_Name.all);
880 if Print_Source or else Print_Unit then
886 (Object_Start + Object_Name'Length .. Object_End));
896 procedure Output_Source (Sdep_I : Sdep_Id) is
897 Stamp : Time_Stamp_Type;
900 Status : File_Status;
901 Object_Name : String_Access;
904 if Sdep_I = No_Sdep_Id then
908 Stamp := Sdep.Table (Sdep_I).Stamp;
909 Checksum := Sdep.Table (Sdep_I).Checksum;
910 FS := Sdep.Table (Sdep_I).Sfile;
913 Find_Status (FS, Stamp, Checksum, Status);
914 Get_Name_String (FS);
916 Object_Name := To_Host_File_Spec (Name_Buffer (1 .. Name_Len));
919 Write_Str (" Source => ");
920 Write_Str (Object_Name.all);
924 (Spaces (Source_Start + Object_Name'Length .. Source_End));
927 Output_Status (Status, Verbose => True);
932 if not Selective_Output then
933 Output_Status (Status, Verbose => False);
936 Write_Str (Object_Name.all);
945 procedure Output_Status (FS : File_Status; Verbose : Boolean) is
950 Write_Str (" unchanged");
953 Write_Str (" slightly modified");
956 Write_Str (" file not found");
959 Write_Str (" modified");
961 when Not_First_On_PATH =>
962 Write_Str (" unchanged version not first on PATH");
979 when Not_First_On_PATH =>
989 procedure Output_Unit (ALI : ALI_Id; U_Id : Unit_Id) is
991 U : Unit_Record renames Units.Table (U_Id);
995 Get_Name_String (U.Uname);
996 Kind := Name_Buffer (Name_Len);
997 Name_Len := Name_Len - 2;
999 if not Verbose_Mode then
1000 Write_Str (Name_Buffer (1 .. Name_Len));
1003 Write_Str ("Unit => ");
1005 Write_Str (" Name => ");
1006 Write_Str (Name_Buffer (1 .. Name_Len));
1008 Write_Str (" Kind => ");
1010 if Units.Table (U_Id).Unit_Kind = 'p
' then
1011 Write_Str ("package ");
1013 Write_Str ("subprogram ");
1023 if Verbose_Mode then
1024 if U.Preelab or else
1027 U.Dynamic_Elab or else
1029 U.Remote_Types or else
1030 U.Shared_Passive or else
1032 U.Predefined or else
1034 U.Is_Generic or else
1035 U.Init_Scalars or else
1036 U.SAL_Interface or else
1037 U.Body_Needed_For_SAL or else
1041 Write_Str (" Flags =>");
1044 Write_Str (" Preelaborable");
1048 Write_Str (" No_Elab_Code");
1052 Write_Str (" Pure");
1055 if U.Dynamic_Elab then
1056 Write_Str (" Dynamic_Elab");
1060 Write_Str (" Has_RACW");
1063 if U.Remote_Types then
1064 Write_Str (" Remote_Types");
1067 if U.Shared_Passive then
1068 Write_Str (" Shared_Passive");
1075 if U.Predefined then
1076 Write_Str (" Predefined");
1080 Write_Str (" Internal");
1083 if U.Is_Generic then
1084 Write_Str (" Is_Generic");
1087 if U.Init_Scalars then
1088 Write_Str (" Init_Scalars");
1091 if U.SAL_Interface then
1092 Write_Str (" SAL_Interface");
1095 if U.Body_Needed_For_SAL then
1096 Write_Str (" Body_Needed_For_SAL");
1099 if U.Elaborate_Body then
1100 Write_Str (" Elaborate Body");
1103 if U.Remote_Types then
1104 Write_Str (" Remote_Types");
1107 if U.Shared_Passive then
1108 Write_Str (" Shared_Passive");
1111 if U.Predefined then
1112 Write_Str (" Predefined");
1117 Restrictions : constant Restrictions_Info :=
1118 ALIs.Table (ALI).Restrictions;
1121 -- If the source was compiled with pragmas Restrictions,
1122 -- Display these restrictions.
1124 if Restrictions.Set /= (All_Restrictions => False) then
1126 Write_Str (" pragma Restrictions =>");
1128 -- For boolean restrictions, just display the name of the
1129 -- restriction; for valued restrictions, also display the
1130 -- restriction value.
1132 for Restriction in All_Restrictions loop
1133 if Restrictions.Set (Restriction) then
1136 Write_Str (Image (Restriction));
1138 if Restriction in All_Parameter_Restrictions then
1140 Write_Str (Restrictions.Value (Restriction)'Img);
1146 -- If the unit violates some Restrictions, display the list of
1147 -- these restrictions.
1149 if Restrictions.Violated /= (All_Restrictions => False) then
1151 Write_Str (" Restrictions violated =>");
1153 -- For boolean restrictions, just display the name of the
1154 -- restriction. For valued restrictions, also display the
1155 -- restriction value.
1157 for Restriction in All_Restrictions loop
1158 if Restrictions.Violated (Restriction) then
1161 Write_Str (Image (Restriction));
1163 if Restriction in All_Parameter_Restrictions then
1164 if Restrictions.Count (Restriction) > 0 then
1167 if Restrictions.Unknown (Restriction) then
1168 Write_Str (" at least");
1171 Write_Str (Restrictions.Count (Restriction)'Img);
1180 if Print_Source then
1185 Write_Str (Spaces (Unit_Start + Name_Len + 1 .. Unit_End));
1195 procedure Reset_Print is
1197 if not Selective_Output then
1198 Selective_Output := True;
1199 Print_Source := False;
1200 Print_Object := False;
1201 Print_Unit := False;
1209 procedure Search_RTS (Name : String) is
1210 Src_Path : String_Ptr;
1211 Lib_Path : String_Ptr;
1212 -- Paths for source and include subdirs
1214 Rts_Full_Path : String_Access;
1215 -- Full path for RTS project
1218 -- Try to find the RTS
1220 Src_Path := Get_RTS_Search_Dir (Name, Include);
1221 Lib_Path := Get_RTS_Search_Dir (Name, Objects);
1223 -- For non-project RTS, both the include and the objects directories
1226 if Src_Path /= null and then Lib_Path /= null then
1227 Add_Search_Dirs (Src_Path, Include);
1228 Add_Search_Dirs (Lib_Path, Objects);
1232 if Lib_Path /= null then
1233 Osint.Fail ("RTS path not valid: missing adainclude directory");
1234 elsif Src_Path /= null then
1235 Osint.Fail ("RTS path not valid: missing adalib directory");
1238 -- Try to find the RTS on the project path. First setup the project path
1240 Initialize_Default_Project_Path
1241 (Prj_Path, Target_Name => Sdefault.Target_Name.all);
1243 Rts_Full_Path := Get_Runtime_Path (Prj_Path, Name);
1245 if Rts_Full_Path /= null then
1247 -- Directory name was found on the project path. Look for the
1248 -- include subdirectory(s).
1250 Src_Path := Get_RTS_Search_Dir (Rts_Full_Path.all, Include);
1252 if Src_Path /= null then
1253 Add_Search_Dirs (Src_Path, Include);
1255 -- Add the lib subdirectory if it exists
1257 Lib_Path := Get_RTS_Search_Dir (Rts_Full_Path.all, Objects);
1259 if Lib_Path /= null then
1260 Add_Search_Dirs (Lib_Path, Objects);
1268 ("RTS path not valid: missing adainclude and adalib directories");
1275 procedure Scan_Ls_Arg (Argv : String) is
1276 FD : File_Descriptor;
1281 pragma Assert (Argv'First = 1);
1283 if Argv'Length = 0 then
1288 if Argv (1) = '-' then
1289 if Argv'Length = 1 then
1290 Fail ("switch character cannot be followed by a blank");
1292 -- Processing for -I-
1294 elsif Argv (2 .. Argv'Last) = "I-" then
1295 Opt.Look_In_Primary_Dir := False;
1297 -- Forbid -?- or -??- where ? is any character
1299 elsif (Argv'Length = 3 and then Argv (3) = '-')
1300 or else (Argv'Length = 4 and then Argv (4) = '-')
1302 Fail ("Trailing ""-"" at the end of " & Argv & " forbidden.");
1304 -- Processing for -Idir
1306 elsif Argv (2) = 'I
' then
1307 Add_Source_Dir (Argv (3 .. Argv'Last));
1308 Add_Lib_Dir (Argv (3 .. Argv'Last));
1310 -- Processing for -aIdir (to gcc this is like a -I switch)
1312 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aI" then
1313 Add_Source_Dir (Argv (4 .. Argv'Last));
1315 -- Processing for -aOdir
1317 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aO" then
1318 Add_Lib_Dir (Argv (4 .. Argv'Last));
1320 -- Processing for -aLdir (to gnatbind this is like a -aO switch)
1322 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aL" then
1323 Add_Lib_Dir (Argv (4 .. Argv'Last));
1325 -- Processing for -aP<dir>
1327 elsif Argv'Length > 3 and then Argv (1 .. 3) = "-aP" then
1328 Add_Directories (Prj_Path, Argv (4 .. Argv'Last));
1330 -- Processing for -nostdinc
1332 elsif Argv (2 .. Argv'Last) = "nostdinc" then
1333 Opt.No_Stdinc := True;
1335 -- Processing for one character switches
1337 elsif Argv'Length = 2 then
1339 when 'a
' => Also_Predef := True;
1340 when 'h
' => Print_Usage := True;
1341 when 'u
' => Reset_Print; Print_Unit := True;
1342 when 's
' => Reset_Print; Print_Source := True;
1343 when 'o
' => Reset_Print; Print_Object := True;
1344 when 'v
' => Verbose_Mode := True;
1345 when 'd
' => Dependable := True;
1346 when 'l
' => License := True;
1347 when 'V
' => Very_Verbose_Mode := True;
1349 when others => OK := False;
1352 -- Processing for -files=file
1354 elsif Argv'Length > 7 and then Argv (1 .. 7) = "-files=" then
1355 FD := Open_Read (Argv (8 .. Argv'Last), GNAT.OS_Lib.Text);
1357 if FD = Invalid_FD then
1358 Osint.Fail ("could not find text file """ &
1359 Argv (8 .. Argv'Last) & '"');
1362 Len := Integer (File_Length (FD));
1365 Buffer : String (1 .. Len + 1);
1366 Index : Positive := 1;
1372 Len := Read (FD, Buffer (1)'Address, Len);
1373 Buffer (Buffer'Last) := ASCII.NUL;
1376 -- Scan the file line by line
1378 while Index < Buffer'Last loop
1380 -- Find the end of line
1383 while Last <= Buffer'Last
1384 and then Buffer (Last) /= ASCII.LF
1385 and then Buffer (Last) /= ASCII.CR
1390 -- Ignore empty lines
1392 if Last > Index then
1393 Add_File (Buffer (Index .. Last - 1));
1396 -- Find the beginning of the next line
1399 while Buffer (Index) = ASCII.CR or else
1400 Buffer (Index) = ASCII.LF
1407 -- Processing for --RTS=path
1409 elsif Argv'Length >= 5 and then Argv (1 .. 5) = "--RTS" then
1410 if Argv
'Length <= 6 or else Argv
(6) /= '='then
1411 Osint
.Fail
("missing path for --RTS");
1414 -- Check that it is the first time we see this switch or, if
1415 -- it is not the first time, the same path is specified.
1417 if RTS_Specified
= null then
1418 RTS_Specified
:= new String'(Argv (7 .. Argv'Last));
1420 elsif RTS_Specified.all /= Argv (7 .. Argv'Last) then
1421 Osint.Fail ("--RTS cannot be specified multiple times");
1424 -- Valid --RTS switch
1426 Opt.No_Stdinc := True;
1427 Opt.RTS_Switch := True;
1434 -- If not a switch, it must be a file name
1441 Write_Str ("warning: unknown switch """);
1456 Write_Str ("Usage: ");
1457 Osint.Write_Program_Name;
1458 Write_Str (" switches [list of object files]");
1464 Write_Str ("switches:");
1467 Display_Usage_Version_And_Help;
1471 Write_Str (" -a also output relevant predefined units");
1476 Write_Str (" -u output only relevant unit names");
1481 Write_Str (" -h output this help message");
1486 Write_Str (" -s output only relevant source names");
1491 Write_Str (" -o output only relevant object names");
1496 Write_Str (" -d output sources on which specified units " &
1502 Write_Str (" -l output license information");
1507 Write_Str (" -v verbose output, full path and unit " &
1514 Write_Str (" -files=fil files are listed in text file 'fil
'");
1517 -- Line for -aI switch
1519 Write_Str (" -aIdir specify source files search path");
1522 -- Line for -aO switch
1524 Write_Str (" -aOdir specify object files search path");
1527 -- Line for -aP switch
1529 Write_Str (" -aPdir specify project search path");
1532 -- Line for -I switch
1534 Write_Str (" -Idir like -aIdir -aOdir");
1537 -- Line for -I- switch
1539 Write_Str (" -I- do not look for sources & object files");
1540 Write_Str (" in the default directory");
1543 -- Line for -nostdinc
1545 Write_Str (" -nostdinc do not look for source files");
1546 Write_Str (" in the system default directory");
1551 Write_Str (" --RTS=dir specify the default source and object search"
1555 -- File Status explanation
1558 Write_Str (" file status can be:");
1561 for ST in File_Status loop
1563 Output_Status (ST, Verbose => False);
1564 Write_Str (" ==> ");
1565 Output_Status (ST, Verbose => True);
1570 procedure Check_Version_And_Help is new Check_Version_And_Help_G (Usage);
1572 -- Start of processing for Gnatls
1575 -- Initialize standard packages
1581 -- First check for --version or --help
1583 Check_Version_And_Help ("GNATLS", "1992");
1585 -- Loop to scan out arguments
1588 Scan_Args : while Next_Arg < Arg_Count loop
1590 Next_Argv : String (1 .. Len_Arg (Next_Arg));
1592 Fill_Arg (Next_Argv'Address, Next_Arg);
1593 Scan_Ls_Arg (Next_Argv);
1596 Next_Arg := Next_Arg + 1;
1599 -- If -l (output license information) is given, it must be the only switch
1601 if License and then Arg_Count /= 2 then
1603 Write_Str ("Can't use -l with another switch");
1606 Exit_Program (E_Fatal);
1609 -- Handle --RTS switch
1611 if RTS_Specified /= null then
1612 Search_RTS (RTS_Specified.all);
1615 -- Add the source and object directories specified on the command line, if
1616 -- any, to the searched directories.
1618 while First_Source_Dir /= null loop
1619 Add_Src_Search_Dir (First_Source_Dir.Value.all);
1620 First_Source_Dir := First_Source_Dir.Next;
1623 while First_Lib_Dir /= null loop
1624 Add_Lib_Search_Dir (First_Lib_Dir.Value.all);
1625 First_Lib_Dir := First_Lib_Dir.Next;
1628 -- Finally, add the default directories
1630 Osint.Add_Default_Search_Dirs;
1632 -- Get the target parameters to know if the target is OpenVMS, but only if
1633 -- switch -nostdinc was not specified.
1635 if not Opt.No_Stdinc then
1636 Get_Target_Parameters;
1639 if Verbose_Mode then
1641 Display_Version ("GNATLS", "1997");
1643 Write_Str ("Source Search Path:");
1646 for J in 1 .. Nb_Dir_In_Src_Search_Path loop
1649 if Dir_In_Src_Search_Path (J)'Length = 0 then
1650 Write_Str ("<Current_Directory>");
1655 (Dir_In_Src_Search_Path (J).all, True).all));
1663 Write_Str ("Object Search Path:");
1666 for J in 1 .. Nb_Dir_In_Obj_Search_Path loop
1669 if Dir_In_Obj_Search_Path (J)'Length = 0 then
1670 Write_Str ("<Current_Directory>");
1675 (Dir_In_Obj_Search_Path (J).all, True).all));
1683 Write_Str (Project_Search_Path);
1685 Write_Str (" <Current_Directory>");
1688 Initialize_Default_Project_Path
1689 (Prj_Path, Target_Name => Sdefault.Target_Name.all);
1692 Project_Path : String_Access;
1697 Get_Path (Prj_Path, Project_Path);
1699 if Project_Path.all /= "" then
1700 First := Project_Path'First;
1702 while First <= Project_Path'Last
1703 and then (Project_Path (First) = Path_Separator)
1708 exit when First > Project_Path'Last;
1711 while Last < Project_Path'Last
1712 and then Project_Path (Last + 1) /= Path_Separator
1717 if First /= Last or else Project_Path (First) /= '.' then
1719 -- If the directory is ".", skip it as it is the current
1720 -- directory and it is already the first directory in the
1727 (Project_Path (First .. Last), True).all));
1739 -- Output usage information when requested
1745 -- Output license information when requested
1748 Output_License_Information;
1749 Exit_Program (E_Success);
1752 if not More_Lib_Files then
1753 if not Print_Usage and then not Verbose_Mode then
1754 if Argument_Count = 0 then
1761 Exit_Program (E_Fatal);
1765 Initialize_ALI_Source;
1767 -- Print out all library for which no ALI files can be located
1769 while More_Lib_Files loop
1770 Main_File := Next_Main_Lib_File;
1771 Ali_File := Full_Lib_File_Name (Lib_File_Name (Main_File));
1773 if Ali_File = No_File then
1774 if Very_Verbose_Mode then
1775 GNATDIST.Output_No_ALI (Lib_File_Name (Main_File));
1779 Write_Str ("Can't find library info for ");
1780 Get_Name_String (Main_File);
1781 Write_Char ('"'); -- "
1782 Write_Str
(Name_Buffer
(1 .. Name_Len
));
1783 Write_Char
('"'); -- "
1788 Ali_File
:= Strip_Directory
(Ali_File
);
1790 if Get_Name_Table_Info
(Ali_File
) = 0 then
1791 Text
:= Read_Library_Info
(Ali_File
, True);
1795 pragma Unreferenced
(Discard
);
1803 Ignore_Errors
=> True);
1811 -- Reset default output file descriptor, if needed
1813 Set_Standard_Output
;
1815 if Very_Verbose_Mode
then
1816 for A
in ALIs
.First
.. ALIs
.Last
loop
1817 GNATDIST
.Output_ALI
(A
);
1823 Find_General_Layout
;
1825 for Id
in ALIs
.First
.. ALIs
.Last
loop
1830 Get_Name_String
(Units
.Table
(ALIs
.Table
(Id
).First_Unit
).Uname
);
1832 if Also_Predef
or else not Is_Internal_Unit
then
1833 if ALIs
.Table
(Id
).No_Object
then
1834 Output_Object
(No_File
);
1836 Output_Object
(ALIs
.Table
(Id
).Ofile_Full_Name
);
1839 -- In verbose mode print all main units in the ALI file, otherwise
1840 -- just print the first one to ease columnwise printout
1842 if Verbose_Mode
then
1843 Last_U
:= ALIs
.Table
(Id
).Last_Unit
;
1845 Last_U
:= ALIs
.Table
(Id
).First_Unit
;
1848 for U
in ALIs
.Table
(Id
).First_Unit
.. Last_U
loop
1849 if U
/= ALIs
.Table
(Id
).First_Unit
1850 and then Selective_Output
1856 Output_Unit
(Id
, U
);
1858 -- Output source now, unless if it will be done as part of
1859 -- outputing dependencies.
1861 if not (Dependable
and then Print_Source
) then
1862 Output_Source
(Corresponding_Sdep_Entry
(Id
, U
));
1866 -- Print out list of units on which this unit depends (D lines)
1868 if Dependable
and then Print_Source
then
1869 if Verbose_Mode
then
1870 Write_Str
("depends upon");
1878 ALIs
.Table
(Id
).First_Sdep
.. ALIs
.Table
(Id
).Last_Sdep
1881 or else not Is_Internal_File_Name
(Sdep
.Table
(D
).Sfile
)
1883 if Verbose_Mode
then
1893 Write_Str
(Spaces
(1 .. Source_Start
- 2));
1906 -- All done. Set proper exit status
1909 Exit_Program
(E_Success
);