Debian Codegraph @

gcc/ada/gnatls.adb

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- G N A T L S --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2025, Free Software Foundation, Inc. --
10 -- --
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. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
25
26 pragma Ada_2012;
27
28 with ALI; use ALI;
29 with ALI.Util; use ALI.Util;
30 with Binderr; use Binderr;
31 with Butil; use Butil;
32 with Csets;
33 with Fname; use Fname;
34 with Gnatvsn; use Gnatvsn;
35 with Make_Util; use Make_Util;
36 with Namet; use Namet;
37 with Opt; use Opt;
38 with Osint; use Osint;
39 with Osint.L; use Osint.L;
40 with Output; use Output;
41 with Rident; use Rident;
42 with Sdefault;
43 with Snames;
44 with Stringt;
45 with Switch; use Switch;
46 with Types; use Types;
47 with Uintp;
48
49 with GNAT.Case_Util; use GNAT.Case_Util;
50 with GNAT.Command_Line; use GNAT.Command_Line;
51 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
52 with GNAT.OS_Lib; use GNAT.OS_Lib;
53
54 procedure Gnatls is
55 pragma Ident (Gnat_Static_Version_String);
56
57 -- NOTE : The following string may be used by other tools, such as
58 -- GNAT Studio. So it can only be modified if these other uses are checked
59 -- and coordinated.
60
61 Project_Search_Path : constant String := "Project Search Path:";
62 -- Label displayed in verbose mode before the directories in the project
63 -- search path. Do not modify without checking NOTE above.
64
65 Prj_Path : String_Access;
66
67 Max_Column : constant := 80;
68
69 No_Obj : aliased String := "<no_obj>";
70
71 No_Runtime : Boolean := False;
72 -- Set to True if there is no default runtime and --RTS= is not specified
73
74 type File_Status is (
75 OK, -- matching timestamp
76 Checksum_OK, -- only matching checksum
77 Not_Found, -- file not found on source PATH
78 Not_Same, -- neither checksum nor timestamp matching
79 Not_First_On_PATH); -- matching file hidden by Not_Same file on path
80
81 type Dir_Data;
82 type Dir_Ref is access Dir_Data;
83
84 type Dir_Data is record
85 Value : String_Access;
86 Next : Dir_Ref;
87 end record;
88 -- Simply linked list of dirs
89
90 First_Source_Dir : Dir_Ref;
91 Last_Source_Dir : Dir_Ref;
92 -- The list of source directories from the command line.
93 -- These directories are added using Osint.Add_Src_Search_Dir
94 -- after those of the GNAT Project File, if any.
95
96 First_Lib_Dir : Dir_Ref;
97 Last_Lib_Dir : Dir_Ref;
98 -- The list of object directories from the command line.
99 -- These directories are added using Osint.Add_Lib_Search_Dir
100 -- after those of the GNAT Project File, if any.
101
102 Main_File : File_Name_Type;
103 Ali_File : File_Name_Type;
104 Text : Text_Buffer_Ptr;
105 Next_Arg : Positive;
106
107 Too_Long : Boolean := False;
108 -- When True, lines are too long for multi-column output and each
109 -- item of information is on a different line.
110
111 Selective_Output : Boolean := False;
112 Print_Usage : Boolean := False;
113 Print_Unit : Boolean := True;
114 Print_Source : Boolean := True;
115 Print_Object : Boolean := True;
116 -- Flags controlling the form of the output
117
118 Also_Predef : Boolean := False; -- -a
119 Dependable : Boolean := False; -- -d
120 License : Boolean := False; -- -l
121 Very_Verbose_Mode : Boolean := False; -- -V
122 -- Command line flags
123
124 Unit_Start : Integer;
125 Unit_End : Integer;
126 Source_Start : Integer;
127 Source_End : Integer;
128 Object_Start : Integer;
129 Object_End : Integer;
130 -- Various column starts and ends
131
132 Spaces : constant String (1 .. Max_Column) := (others => ' ');
133
134 RTS_Specified : String_Access := null;
135 -- Used to detect multiple use of --RTS= switch
136
137 Exit_Status : Exit_Code_Type := E_Success;
138 -- Reset to E_Fatal if bad error found
139
140 -----------------------
141 -- Local Subprograms --
142 -----------------------
143
144 procedure Add_Lib_Dir (Dir : String);
145 -- Add an object directory in the list First_Lib_Dir-Last_Lib_Dir
146
147 procedure Add_Source_Dir (Dir : String);
148 -- Add a source directory in the list First_Source_Dir-Last_Source_Dir
149
150 procedure Find_General_Layout;
151 -- Determine the structure of the output (multi columns or not, etc)
152
153 procedure Find_Status
154 (FS : in out File_Name_Type;
155 Stamp : Time_Stamp_Type;
156 Checksum : Word;
157 Status : out File_Status);
158 -- Determine the file status (Status) of the file represented by FS with
159 -- the expected Stamp and checksum given as argument. FS will be updated
160 -- to the full file name if available.
161
162 function Corresponding_Sdep_Entry (A : ALI_Id; U : Unit_Id) return Sdep_Id;
163 -- Give the Sdep entry corresponding to the unit U in ali record A
164
165 procedure Output_Object (O : File_Name_Type);
166 -- Print out the name of the object when requested
167
168 procedure Output_Source (Sdep_I : Sdep_Id);
169 -- Print out the name and status of the source corresponding to this
170 -- sdep entry.
171
172 procedure Output_Status (FS : File_Status; Verbose : Boolean);
173 -- Print out FS either in a coded form if verbose is false or in an
174 -- expanded form otherwise.
175
176 procedure Output_Unit (ALI : ALI_Id; U_Id : Unit_Id);
177 -- Print out information on the unit when requested
178
179 procedure Reset_Print;
180 -- Reset Print flags properly when selective output is chosen
181
182 procedure Scan_Ls_Arg (Argv : String);
183 -- Scan and process user specific arguments (Argv is a single argument)
184
185 procedure Search_RTS (Name : String);
186 -- Find include and objects path for the RTS name.
187
188 procedure Usage;
189 -- Print usage message
190
191 procedure Output_License_Information;
192 -- Output license statement, and if not found, output reference to COPYING
193
194 function Image (Restriction : Restriction_Id) return String;
195 -- Returns the capitalized image of Restriction
196
197 function Normalize (Path : String) return String;
198 -- Returns a normalized path name. On Windows, the directory separators are
199 -- set to '\' in Normalize_Pathname.
200
201 ------------------------------------------
202 -- GNATDIST specific output subprograms --
203 ------------------------------------------
204
205 package GNATDIST is
206
207 -- Any modification to this subunit requires synchronization with the
208 -- GNATDIST sources.
209
210 procedure Output_ALI (A : ALI_Id);
211 -- Comment required saying what this routine does ???
212
213 procedure Output_No_ALI (Afile : File_Name_Type);
214 -- Comments required saying what this routine does ???
215
216 end GNATDIST;
217
218 ------------------------------
219 -- Support for project path --
220 ------------------------------
221
222 package Prj_Env is
223
224 procedure Initialize_Default_Project_Path
225 (Self : in out String_Access;
226 Target_Name : String;
227 Runtime_Name : String := "");
228 -- Initialize Self. It will then contain the default project path on
229 -- the given target and runtime (including directories specified by the
230 -- environment variables GPR_PROJECT_PATH_FILE, GPR_PROJECT_PATH and
231 -- ADA_PROJECT_PATH). If one of the directory or Target_Name is "-",
232 -- then the path contains only those directories specified by the
233 -- environment variables (except "-"). This does nothing if Self has
234 -- already been initialized.
235
236 procedure Add_Directories
237 (Self : in out String_Access;
238 Path : String);
239 -- Add one or more directories to the path. Directories added with this
240 -- procedure are added in order after the current directory and before
241 -- the path given by the environment variable GPR_PROJECT_PATH. A value
242 -- of "-" will remove the default project directory from the project
243 -- path.
244 --
245 -- Calls to this subprogram must be performed before the first call to
246 -- Find_Project below, or PATH will be added at the end of the search
247 -- path.
248
249 function Get_Runtime_Path
250 (Self : String_Access;
251 Path : String) return String_Access;
252 -- Compute the full path for the project-based runtime name.
253 -- Path is simply searched on the project path.
254
255 end Prj_Env;
256
257 -----------------
258 -- Add_Lib_Dir --
259 -----------------
260
261 procedure Add_Lib_Dir (Dir : String) is
262 begin
263 if First_Lib_Dir = null then
264 First_Lib_Dir :=
265 new Dir_Data'
266 (Value => new String'(Dir),
267 Next => null);
268 Last_Lib_Dir := First_Lib_Dir;
269
270 else
271 Last_Lib_Dir.Next :=
272 new Dir_Data'
273 (Value => new String'(Dir),
274 Next => null);
275 Last_Lib_Dir := Last_Lib_Dir.Next;
276 end if;
277 end Add_Lib_Dir;
278
279 --------------------
280 -- Add_Source_Dir --
281 --------------------
282
283 procedure Add_Source_Dir (Dir : String) is
284 begin
285 if First_Source_Dir = null then
286 First_Source_Dir :=
287 new Dir_Data'
288 (Value => new String'(Dir),
289 Next => null);
290 Last_Source_Dir := First_Source_Dir;
291
292 else
293 Last_Source_Dir.Next :=
294 new Dir_Data'
295 (Value => new String'(Dir),
296 Next => null);
297 Last_Source_Dir := Last_Source_Dir.Next;
298 end if;
299 end Add_Source_Dir;
300
301 ------------------------------
302 -- Corresponding_Sdep_Entry --
303 ------------------------------
304
305 function Corresponding_Sdep_Entry
306 (A : ALI_Id;
307 U : Unit_Id) return Sdep_Id
308 is
309 begin
310 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
311 if Sdep.Table (D).Sfile = Units.Table (U).Sfile then
312 return D;
313 end if;
314 end loop;
315
316 Error_Msg_Unit_1 := Units.Table (U).Uname;
317 Error_Msg_File_1 := ALIs.Table (A).Afile;
318 Write_Eol;
319 Error_Msg ("wrong ALI format, can't find dependency line for $ in {");
320 Exit_Program (E_Fatal);
321 end Corresponding_Sdep_Entry;
322
323 -------------------------
324 -- Find_General_Layout --
325 -------------------------
326
327 procedure Find_General_Layout is
328 Max_Unit_Length : Integer := 11;
329 Max_Src_Length : Integer := 11;
330 Max_Obj_Length : Integer := 11;
331
332 Len : Integer;
333 FS : File_Name_Type;
334
335 begin
336 -- Compute maximum of each column
337
338 for Id in ALIs.First .. ALIs.Last loop
339 Get_Name_String (Units.Table (ALIs.Table (Id).First_Unit).Uname);
340 if Also_Predef or else not Is_Internal_Unit then
341
342 if Print_Unit then
343 Len := Name_Len - 1;
344 Max_Unit_Length := Integer'Max (Max_Unit_Length, Len);
345 end if;
346
347 if Print_Source then
348 FS := Full_Source_Name (ALIs.Table (Id).Sfile);
349
350 if FS = No_File then
351 Get_Name_String (ALIs.Table (Id).Sfile);
352 Name_Len := Name_Len + 13;
353 else
354 Get_Name_String (FS);
355 end if;
356
357 Max_Src_Length := Integer'Max (Max_Src_Length, Name_Len + 1);
358 end if;
359
360 if Print_Object then
361 if ALIs.Table (Id).No_Object then
362 Max_Obj_Length :=
363 Integer'Max (Max_Obj_Length, No_Obj'Length);
364 else
365 Get_Name_String (ALIs.Table (Id).Ofile_Full_Name);
366 Max_Obj_Length := Integer'Max (Max_Obj_Length, Name_Len + 1);
367 end if;
368 end if;
369 end if;
370 end loop;
371
372 -- Verify is output is not wider than maximum number of columns
373
374 Too_Long :=
375 Verbose_Mode
376 or else
377 (Max_Unit_Length + Max_Src_Length + Max_Obj_Length) > Max_Column;
378
379 -- Set start and end of columns
380
381 Object_Start := 1;
382 Object_End := Object_Start - 1;
383
384 if Print_Object then
385 Object_End := Object_Start + Max_Obj_Length;
386 end if;
387
388 Unit_Start := Object_End + 1;
389 Unit_End := Unit_Start - 1;
390
391 if Print_Unit then
392 Unit_End := Unit_Start + Max_Unit_Length;
393 end if;
394
395 Source_Start := Unit_End + 1;
396
397 if Source_Start > Spaces'Last then
398 Source_Start := Spaces'Last;
399 end if;
400
401 Source_End := Source_Start - 1;
402
403 if Print_Source then
404 Source_End := Source_Start + Max_Src_Length;
405 end if;
406 end Find_General_Layout;
407
408 -----------------
409 -- Find_Status --
410 -----------------
411
412 procedure Find_Status
413 (FS : in out File_Name_Type;
414 Stamp : Time_Stamp_Type;
415 Checksum : Word;
416 Status : out File_Status)
417 is
418 Tmp1 : File_Name_Type;
419 Tmp2 : File_Name_Type;
420
421 begin
422 Tmp1 := Full_Source_Name (FS);
423
424 if Tmp1 = No_File then
425 Status := Not_Found;
426
427 elsif File_Stamp (Tmp1) = Stamp then
428 FS := Tmp1;
429 Status := OK;
430
431 elsif Checksums_Match (Get_File_Checksum (FS), Checksum) then
432 FS := Tmp1;
433 Status := Checksum_OK;
434
435 else
436 Tmp2 := Matching_Full_Source_Name (FS, Stamp);
437
438 if Tmp2 = No_File then
439 Status := Not_Same;
440 FS := Tmp1;
441
442 else
443 Status := Not_First_On_PATH;
444 FS := Tmp2;
445 end if;
446 end if;
447 end Find_Status;
448
449 --------------
450 -- GNATDIST --
451 --------------
452
453 package body GNATDIST is
454
455 N_Flags : Natural;
456 N_Indents : Natural := 0;
457
458 type Token_Type is
459 (T_No_ALI,
460 T_ALI,
461 T_Unit,
462 T_With,
463 T_Source,
464 T_Afile,
465 T_Ofile,
466 T_Sfile,
467 T_Name,
468 T_Main,
469 T_Kind,
470 T_Flags,
471 T_Preelaborated,
472 T_Pure,
473 T_Has_RACW,
474 T_Remote_Types,
475 T_Shared_Passive,
476 T_RCI,
477 T_Predefined,
478 T_Internal,
479 T_Is_Generic,
480 T_Procedure,
481 T_Function,
482 T_Package,
483 T_Subprogram,
484 T_Spec,
485 T_Body);
486
487 Image : constant array (Token_Type) of String_Access :=
488 (T_No_ALI => new String'("No_ALI"),
489 T_ALI => new String'("ALI"),
490 T_Unit => new String'("Unit"),
491 T_With => new String'("With"),
492 T_Source => new String'("Source"),
493 T_Afile => new String'("Afile"),
494 T_Ofile => new String'("Ofile"),
495 T_Sfile => new String'("Sfile"),
496 T_Name => new String'("Name"),
497 T_Main => new String'("Main"),
498 T_Kind => new String'("Kind"),
499 T_Flags => new String'("Flags"),
500 T_Preelaborated => new String'("Preelaborated"),
501 T_Pure => new String'("Pure"),
502 T_Has_RACW => new String'("Has_RACW"),
503 T_Remote_Types => new String'("Remote_Types"),
504 T_Shared_Passive => new String'("Shared_Passive"),
505 T_RCI => new String'("RCI"),
506 T_Predefined => new String'("Predefined"),
507 T_Internal => new String'("Internal"),
508 T_Is_Generic => new String'("Is_Generic"),
509 T_Procedure => new String'("procedure"),
510 T_Function => new String'("function"),
511 T_Package => new String'("package"),
512 T_Subprogram => new String'("subprogram"),
513 T_Spec => new String'("spec"),
514 T_Body => new String'("body"));
515
516 procedure Output_Name (N : Name_Id);
517 -- Remove any encoding info (%b and %s) and output N
518
519 procedure Output_Afile (A : File_Name_Type);
520 procedure Output_Ofile (O : File_Name_Type);
521 procedure Output_Sfile (S : File_Name_Type);
522 -- Output various names. Check that the name is different from no name.
523 -- Otherwise, skip the output.
524
525 procedure Output_Token (T : Token_Type);
526 -- Output token using specific format. That is several indentations and:
527 --
528 -- T_No_ALI .. T_With : <token> & " =>" & NL
529 -- T_Source .. T_Kind : <token> & " => "
530 -- T_Flags : <token> & " =>"
531 -- T_Preelab .. T_Body : " " & <token>
532
533 procedure Output_Sdep (S : Sdep_Id);
534 procedure Output_Unit (U : Unit_Id);
535 procedure Output_With (W : With_Id);
536 -- Output this entry as a global section (like ALIs)
537
538 ------------------
539 -- Output_Afile --
540 ------------------
541
542 procedure Output_Afile (A : File_Name_Type) is
543 begin
544 if A /= No_File then
545 Output_Token (T_Afile);
546 Write_Name (A);
547 Write_Eol;
548 end if;
549 end Output_Afile;
550
551 ----------------
552 -- Output_ALI --
553 ----------------
554
555 procedure Output_ALI (A : ALI_Id) is
556 begin
557 Output_Token (T_ALI);
558 N_Indents := N_Indents + 1;
559
560 Output_Afile (ALIs.Table (A).Afile);
561 Output_Ofile (ALIs.Table (A).Ofile_Full_Name);
562 Output_Sfile (ALIs.Table (A).Sfile);
563
564 -- Output Main
565
566 if ALIs.Table (A).Main_Program /= None then
567 Output_Token (T_Main);
568
569 if ALIs.Table (A).Main_Program = Proc then
570 Output_Token (T_Procedure);
571 else
572 Output_Token (T_Function);
573 end if;
574
575 Write_Eol;
576 end if;
577
578 -- Output Units
579
580 for U in ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit loop
581 Output_Unit (U);
582 end loop;
583
584 -- Output Sdeps
585
586 for S in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
587 Output_Sdep (S);
588 end loop;
589
590 N_Indents := N_Indents - 1;
591 end Output_ALI;
592
593 -------------------
594 -- Output_No_ALI --
595 -------------------
596
597 procedure Output_No_ALI (Afile : File_Name_Type) is
598 begin
599 Output_Token (T_No_ALI);
600 N_Indents := N_Indents + 1;
601 Output_Afile (Afile);
602 N_Indents := N_Indents - 1;
603 end Output_No_ALI;
604
605 -----------------
606 -- Output_Name --
607 -----------------
608
609 procedure Output_Name (N : Name_Id) is
610 begin
611 -- Remove any encoding info (%s or %b)
612
613 Get_Name_String (N);
614
615 if Name_Len > 2
616 and then Name_Buffer (Name_Len - 1) = '%'
617 then
618 Name_Len := Name_Len - 2;
619 end if;
620
621 Output_Token (T_Name);
622 Write_Str (Name_Buffer (1 .. Name_Len));
623 Write_Eol;
624 end Output_Name;
625
626 ------------------
627 -- Output_Ofile --
628 ------------------
629
630 procedure Output_Ofile (O : File_Name_Type) is
631 begin
632 if O /= No_File then
633 Output_Token (T_Ofile);
634 Write_Name (O);
635 Write_Eol;
636 end if;
637 end Output_Ofile;
638
639 -----------------
640 -- Output_Sdep --
641 -----------------
642
643 procedure Output_Sdep (S : Sdep_Id) is
644 begin
645 Output_Token (T_Source);
646 Write_Name (Sdep.Table (S).Sfile);
647 Write_Eol;
648 end Output_Sdep;
649
650 ------------------
651 -- Output_Sfile --
652 ------------------
653
654 procedure Output_Sfile (S : File_Name_Type) is
655 FS : File_Name_Type := S;
656
657 begin
658 if FS /= No_File then
659
660 -- We want to output the full source name
661
662 FS := Full_Source_Name (FS);
663
664 -- There is no full source name. This occurs for instance when a
665 -- withed unit has a spec file but no body file. This situation is
666 -- not a problem for GNATDIST since the unit may be located on a
667 -- partition we do not want to build. However, we need to locate
668 -- the spec file and to find its full source name. Replace the
669 -- body file name with the spec file name used to compile the
670 -- current unit when possible.
671
672 if FS = No_File then
673 Get_Name_String (S);
674
675 if Name_Len > 4
676 and then Name_Buffer (Name_Len - 3 .. Name_Len) = ".adb"
677 then
678 Name_Buffer (Name_Len) := 's';
679 FS := Full_Source_Name (Name_Find);
680 end if;
681 end if;
682 end if;
683
684 if FS /= No_File then
685 Output_Token (T_Sfile);
686 Write_Name (FS);
687 Write_Eol;
688 end if;
689 end Output_Sfile;
690
691 ------------------
692 -- Output_Token --
693 ------------------
694
695 procedure Output_Token (T : Token_Type) is
696 begin
697 case T is
698 when T_No_ALI .. T_Flags =>
699 for J in 1 .. N_Indents loop
700 Write_Str (" ");
701 end loop;
702
703 Write_Str (Image (T).all);
704
705 for J in Image (T)'Length .. 12 loop
706 Write_Char (' ');
707 end loop;
708
709 Write_Str ("=>");
710
711 if T in T_No_ALI .. T_With then
712 Write_Eol;
713 elsif T in T_Source .. T_Name then
714 Write_Char (' ');
715 end if;
716
717 when T_Preelaborated .. T_Body =>
718 if T in T_Preelaborated .. T_Is_Generic then
719 if N_Flags = 0 then
720 Output_Token (T_Flags);
721 end if;
722
723 N_Flags := N_Flags + 1;
724 end if;
725
726 Write_Char (' ');
727 Write_Str (Image (T).all);
728 end case;
729 end Output_Token;
730
731 -----------------
732 -- Output_Unit --
733 -----------------
734
735 procedure Output_Unit (U : Unit_Id) is
736 begin
737 Output_Token (T_Unit);
738 N_Indents := N_Indents + 1;
739
740 -- Output Name
741
742 Output_Name (Name_Id (Units.Table (U).Uname));
743
744 -- Output Kind
745
746 Output_Token (T_Kind);
747
748 if Units.Table (U).Unit_Kind = 'p' then
749 Output_Token (T_Package);
750 else
751 Output_Token (T_Subprogram);
752 end if;
753
754 if Name_Buffer (Name_Len) = 's' then
755 Output_Token (T_Spec);
756 else
757 Output_Token (T_Body);
758 end if;
759
760 Write_Eol;
761
762 -- Output source file name
763
764 Output_Sfile (Units.Table (U).Sfile);
765
766 -- Output Flags
767
768 N_Flags := 0;
769
770 if Units.Table (U).Preelab then
771 Output_Token (T_Preelaborated);
772 end if;
773
774 if Units.Table (U).Pure then
775 Output_Token (T_Pure);
776 end if;
777
778 if Units.Table (U).Has_RACW then
779 Output_Token (T_Has_RACW);
780 end if;
781
782 if Units.Table (U).Remote_Types then
783 Output_Token (T_Remote_Types);
784 end if;
785
786 if Units.Table (U).Shared_Passive then
787 Output_Token (T_Shared_Passive);
788 end if;
789
790 if Units.Table (U).RCI then
791 Output_Token (T_RCI);
792 end if;
793
794 if Units.Table (U).Predefined then
795 Output_Token (T_Predefined);
796 end if;
797
798 if Units.Table (U).Internal then
799 Output_Token (T_Internal);
800 end if;
801
802 if Units.Table (U).Is_Generic then
803 Output_Token (T_Is_Generic);
804 end if;
805
806 if N_Flags > 0 then
807 Write_Eol;
808 end if;
809
810 -- Output Withs
811
812 for W in Units.Table (U).First_With .. Units.Table (U).Last_With loop
813 Output_With (W);
814 end loop;
815
816 N_Indents := N_Indents - 1;
817 end Output_Unit;
818
819 -----------------
820 -- Output_With --
821 -----------------
822
823 procedure Output_With (W : With_Id) is
824 begin
825 Output_Token (T_With);
826 N_Indents := N_Indents + 1;
827
828 Output_Name (Name_Id (Withs.Table (W).Uname));
829
830 -- Output Kind
831
832 Output_Token (T_Kind);
833
834 if Name_Buffer (Name_Len) = 's' then
835 Output_Token (T_Spec);
836 else
837 Output_Token (T_Body);
838 end if;
839
840 Write_Eol;
841
842 Output_Afile (Withs.Table (W).Afile);
843 Output_Sfile (Withs.Table (W).Sfile);
844
845 N_Indents := N_Indents - 1;
846 end Output_With;
847
848 end GNATDIST;
849
850 -----------
851 -- Image --
852 -----------
853
854 function Image (Restriction : Restriction_Id) return String is
855 Result : String := Restriction'Img;
856 Skip : Boolean := True;
857
858 begin
859 for J in Result'Range loop
860 if Skip then
861 Skip := False;
862 Result (J) := To_Upper (Result (J));
863
864 elsif Result (J) = '_' then
865 Skip := True;
866
867 else
868 Result (J) := To_Lower (Result (J));
869 end if;
870 end loop;
871
872 return Result;
873 end Image;
874
875 ---------------
876 -- Normalize --
877 ---------------
878
879 function Normalize (Path : String) return String is
880 begin
881 return Normalize_Pathname (Path);
882 end Normalize;
883
884 --------------------------------
885 -- Output_License_Information --
886 --------------------------------
887
888 procedure Output_License_Information is
889 begin
890 case Build_Type is
891 when others =>
892 Write_Str ("Please refer to file COPYING in your distribution"
893 & " for license terms.");
894 Write_Eol;
895 end case;
896 end Output_License_Information;
897
898 -------------------
899 -- Output_Object --
900 -------------------
901
902 procedure Output_Object (O : File_Name_Type) is
903 Object_Name : String_Access;
904
905 begin
906 if Print_Object then
907 if O /= No_File then
908 Get_Name_String (O);
909 Object_Name := To_Host_File_Spec (Name_Buffer (1 .. Name_Len));
910 else
911 Object_Name := No_Obj'Unchecked_Access;
912 end if;
913
914 Write_Str (Object_Name.all);
915
916 if Print_Source or else Print_Unit then
917 if Too_Long then
918 Write_Eol;
919 Write_Str (" ");
920 else
921 Write_Str (Spaces
922 (Object_Start + Object_Name'Length .. Object_End));
923 end if;
924 end if;
925 end if;
926 end Output_Object;
927
928 -------------------
929 -- Output_Source --
930 -------------------
931
932 procedure Output_Source (Sdep_I : Sdep_Id) is
933 Stamp : Time_Stamp_Type;
934 Checksum : Word;
935 FS : File_Name_Type;
936 Status : File_Status;
937 Object_Name : String_Access;
938
939 begin
940 if Sdep_I = No_Sdep_Id then
941 return;
942 end if;
943
944 Stamp := Sdep.Table (Sdep_I).Stamp;
945 Checksum := Sdep.Table (Sdep_I).Checksum;
946 FS := Sdep.Table (Sdep_I).Sfile;
947
948 if Print_Source then
949 Find_Status (FS, Stamp, Checksum, Status);
950 Get_Name_String (FS);
951
952 Object_Name := To_Host_File_Spec (Name_Buffer (1 .. Name_Len));
953
954 if Verbose_Mode then
955 Write_Str (" Source => ");
956 Write_Str (Object_Name.all);
957
958 if not Too_Long then
959 Write_Str
960 (Spaces (Source_Start + Object_Name'Length .. Source_End));
961 end if;
962
963 Output_Status (Status, Verbose => True);
964 Write_Eol;
965 Write_Str (" ");
966
967 else
968 if not Selective_Output then
969 Output_Status (Status, Verbose => False);
970 end if;
971
972 Write_Str (Object_Name.all);
973 end if;
974 end if;
975 end Output_Source;
976
977 -------------------
978 -- Output_Status --
979 -------------------
980
981 procedure Output_Status (FS : File_Status; Verbose : Boolean) is
982 begin
983 if Verbose then
984 case FS is
985 when OK =>
986 Write_Str (" unchanged");
987
988 when Checksum_OK =>
989 Write_Str (" slightly modified");
990
991 when Not_Found =>
992 Write_Str (" file not found");
993
994 when Not_Same =>
995 Write_Str (" modified");
996
997 when Not_First_On_PATH =>
998 Write_Str (" unchanged version not first on PATH");
999 end case;
1000
1001 else
1002 case FS is
1003 when OK =>
1004 Write_Str (" OK ");
1005
1006 when Checksum_OK =>
1007 Write_Str (" MOK ");
1008
1009 when Not_Found =>
1010 Write_Str (" ??? ");
1011
1012 when Not_Same =>
1013 Write_Str (" DIF ");
1014
1015 when Not_First_On_PATH =>
1016 Write_Str (" HID ");
1017 end case;
1018 end if;
1019 end Output_Status;
1020
1021 -----------------
1022 -- Output_Unit --
1023 -----------------
1024
1025 procedure Output_Unit (ALI : ALI_Id; U_Id : Unit_Id) is
1026 Kind : Character;
1027 U : Unit_Record renames Units.Table (U_Id);
1028
1029 begin
1030 if Print_Unit then
1031 Get_Name_String (U.Uname);
1032 Kind := Name_Buffer (Name_Len);
1033 Name_Len := Name_Len - 2;
1034
1035 if not Verbose_Mode then
1036 Write_Str (Name_Buffer (1 .. Name_Len));
1037
1038 else
1039 Write_Str ("Unit => ");
1040 Write_Eol;
1041 Write_Str (" Name => ");
1042 Write_Str (Name_Buffer (1 .. Name_Len));
1043 Write_Eol;
1044 Write_Str (" Kind => ");
1045
1046 if Units.Table (U_Id).Unit_Kind = 'p' then
1047 Write_Str ("package ");
1048 else
1049 Write_Str ("subprogram ");
1050 end if;
1051
1052 if Kind = 's' then
1053 Write_Str ("spec");
1054 else
1055 Write_Str ("body");
1056 end if;
1057 end if;
1058
1059 if Verbose_Mode then
1060 if U.Preelab or else
1061 U.No_Elab or else
1062 U.Pure or else
1063 U.Dynamic_Elab or else
1064 U.Has_RACW or else
1065 U.Remote_Types or else
1066 U.Shared_Passive or else
1067 U.RCI or else
1068 U.Predefined or else
1069 U.Internal or else
1070 U.Is_Generic or else
1071 U.Init_Scalars or else
1072 U.SAL_Interface or else
1073 U.Body_Needed_For_SAL or else
1074 U.Elaborate_Body
1075 then
1076 Write_Eol;
1077 Write_Str (" Flags =>");
1078
1079 if U.Preelab then
1080 Write_Str (" Preelaborable");
1081 end if;
1082
1083 if U.No_Elab then
1084 Write_Str (" No_Elab_Code");
1085 end if;
1086
1087 if U.Pure then
1088 Write_Str (" Pure");
1089 end if;
1090
1091 if U.Dynamic_Elab then
1092 Write_Str (" Dynamic_Elab");
1093 end if;
1094
1095 if U.Has_RACW then
1096 Write_Str (" Has_RACW");
1097 end if;
1098
1099 if U.Remote_Types then
1100 Write_Str (" Remote_Types");
1101 end if;
1102
1103 if U.Shared_Passive then
1104 Write_Str (" Shared_Passive");
1105 end if;
1106
1107 if U.RCI then
1108 Write_Str (" RCI");
1109 end if;
1110
1111 if U.Predefined then
1112 Write_Str (" Predefined");
1113 end if;
1114
1115 if U.Internal then
1116 Write_Str (" Internal");
1117 end if;
1118
1119 if U.Is_Generic then
1120 Write_Str (" Is_Generic");
1121 end if;
1122
1123 if U.Init_Scalars then
1124 Write_Str (" Init_Scalars");
1125 end if;
1126
1127 if U.SAL_Interface then
1128 Write_Str (" SAL_Interface");
1129 end if;
1130
1131 if U.Body_Needed_For_SAL then
1132 Write_Str (" Body_Needed_For_SAL");
1133 end if;
1134
1135 if U.Elaborate_Body then
1136 Write_Str (" Elaborate Body");
1137 end if;
1138
1139 if U.Remote_Types then
1140 Write_Str (" Remote_Types");
1141 end if;
1142
1143 if U.Shared_Passive then
1144 Write_Str (" Shared_Passive");
1145 end if;
1146
1147 if U.Predefined then
1148 Write_Str (" Predefined");
1149 end if;
1150 end if;
1151
1152 declare
1153 Restrictions : constant Restrictions_Info :=
1154 ALIs.Table (ALI).Restrictions;
1155
1156 begin
1157 -- If the source was compiled with pragmas Restrictions,
1158 -- Display these restrictions.
1159
1160 if Restrictions.Set /= (All_Restrictions => False) then
1161 Write_Eol;
1162 Write_Str (" pragma Restrictions =>");
1163
1164 -- For boolean restrictions, just display the name of the
1165 -- restriction; for valued restrictions, also display the
1166 -- restriction value.
1167
1168 for Restriction in All_Restrictions loop
1169 if Restrictions.Set (Restriction) then
1170 Write_Eol;
1171 Write_Str (" ");
1172 Write_Str (Image (Restriction));
1173
1174 if Restriction in All_Parameter_Restrictions then
1175 Write_Str (" =>");
1176 Write_Str (Restrictions.Value (Restriction)'Img);
1177 end if;
1178 end if;
1179 end loop;
1180 end if;
1181
1182 -- If the unit violates some Restrictions, display the list of
1183 -- these restrictions.
1184
1185 if Restrictions.Violated /= (All_Restrictions => False) then
1186 Write_Eol;
1187 Write_Str (" Restrictions violated =>");
1188
1189 -- For boolean restrictions, just display the name of the
1190 -- restriction. For valued restrictions, also display the
1191 -- restriction value.
1192
1193 for Restriction in All_Restrictions loop
1194 if Restrictions.Violated (Restriction) then
1195 Write_Eol;
1196 Write_Str (" ");
1197 Write_Str (Image (Restriction));
1198
1199 if Restriction in All_Parameter_Restrictions then
1200 if Restrictions.Count (Restriction) > 0 then
1201 Write_Str (" =>");
1202
1203 if Restrictions.Unknown (Restriction) then
1204 Write_Str (" at least");
1205 end if;
1206
1207 Write_Str (Restrictions.Count (Restriction)'Img);
1208 end if;
1209 end if;
1210 end if;
1211 end loop;
1212 end if;
1213 end;
1214 end if;
1215
1216 if Print_Source then
1217 if Too_Long then
1218 Write_Eol;
1219 Write_Str (" ");
1220 else
1221 Write_Str (Spaces (Unit_Start + Name_Len + 1 .. Unit_End));
1222 end if;
1223 end if;
1224 end if;
1225 end Output_Unit;
1226
1227 package body Prj_Env is
1228
1229 Uninitialized_Prefix : constant String := '#' & Path_Separator;
1230 -- Prefix to indicate that the project path has not been initialized
1231 -- yet. Must be two characters long.
1232
1233 ---------------------
1234 -- Add_Directories --
1235 ---------------------
1236
1237 procedure Add_Directories
1238 (Self : in out String_Access;
1239 Path : String)
1240 is
1241 Tmp : String_Access;
1242
1243 begin
1244 if Self = null then
1245 Self := new String'(Uninitialized_Prefix & Path);
1246 else
1247 Tmp := Self;
1248 Self := new String'(Tmp.all & Path_Separator & Path);
1249 Free (Tmp);
1250 end if;
1251 end Add_Directories;
1252
1253 -------------------------------------
1254 -- Initialize_Default_Project_Path --
1255 -------------------------------------
1256
1257 procedure Initialize_Default_Project_Path
1258 (Self : in out String_Access;
1259 Target_Name : String;
1260 Runtime_Name : String := "")
1261 is
1262 Add_Default_Dir : Boolean := Target_Name /= "-";
1263 First : Positive;
1264 Last : Positive;
1265
1266 Ada_Project_Path : constant String := "ADA_PROJECT_PATH";
1267 Gpr_Project_Path : constant String := "GPR_PROJECT_PATH";
1268 Gpr_Project_Path_File : constant String := "GPR_PROJECT_PATH_FILE";
1269 -- Names of alternate env. variables that contain path name(s) of
1270 -- directories where project files may reside. They are taken into
1271 -- account in this order: GPR_PROJECT_PATH_FILE, GPR_PROJECT_PATH,
1272 -- ADA_PROJECT_PATH.
1273
1274 Gpr_Prj_Path_File : String_Access;
1275 Gpr_Prj_Path : String_Access;
1276 Ada_Prj_Path : String_Access;
1277 -- The path name(s) of directories where project files may reside.
1278 -- May be empty.
1279
1280 Prefix : String_Ptr;
1281 Runtime : String_Ptr;
1282
1283 procedure Add_Target (Suffix : String);
1284 -- Add :<prefix>/<target>/Suffix to the project path
1285
1286 FD : File_Descriptor;
1287 Len : Integer;
1288
1289 ----------------
1290 -- Add_Target --
1291 ----------------
1292
1293 procedure Add_Target (Suffix : String) is
1294 Extra_Sep : constant String :=
1295 (if Target_Name (Target_Name'Last) = '/' then
1296 ""
1297 else
1298 (1 => Directory_Separator));
1299 -- Note: Target_Name has a trailing / when it comes from Sdefault
1300
1301 begin
1302 Add_Str_To_Name_Buffer
1303 (Path_Separator & Prefix.all & Target_Name & Extra_Sep & Suffix);
1304 end Add_Target;
1305
1306 -- Start of processing for Initialize_Default_Project_Path
1307
1308 begin
1309 if Self /= null
1310 and then (Self'Length = 0
1311 or else Self (Self'First) /= '#')
1312 then
1313 return;
1314 end if;
1315
1316 -- The current directory is always first in the search path. Since
1317 -- the Project_Path currently starts with '#:' as a sign that it is
1318 -- not initialized, we simply replace '#' with '.'
1319
1320 if Self = null then
1321 Self := new String'('.' & Path_Separator);
1322 else
1323 Self (Self'First) := '.';
1324 end if;
1325
1326 -- Then the reset of the project path (if any) currently contains the
1327 -- directories added through Add_Search_Project_Directory
1328
1329 -- If environment variables are defined and not empty, add their
1330 -- content
1331
1332 Gpr_Prj_Path_File := Getenv (Gpr_Project_Path_File);
1333 Gpr_Prj_Path := Getenv (Gpr_Project_Path);
1334 Ada_Prj_Path := Getenv (Ada_Project_Path);
1335
1336 if Gpr_Prj_Path_File.all /= "" then
1337 FD := Open_Read (Gpr_Prj_Path_File.all, GNAT.OS_Lib.Text);
1338
1339 if FD /= Invalid_FD then
1340 Len := Integer (File_Length (FD));
1341
1342 declare
1343 Buffer : String (1 .. Len);
1344 Index : Positive := 1;
1345 Last : Positive;
1346 Tmp : String_Access;
1347
1348 begin
1349 -- Read the file
1350
1351 Len := Read (FD, Buffer (1)'Address, Len);
1352 Close (FD);
1353
1354 -- Scan the file line by line
1355
1356 while Index < Buffer'Last loop
1357
1358 -- Find the end of line
1359
1360 Last := Index;
1361 while Last <= Buffer'Last
1362 and then Buffer (Last) /= ASCII.LF
1363 and then Buffer (Last) /= ASCII.CR
1364 loop
1365 Last := Last + 1;
1366 end loop;
1367
1368 -- Ignore empty lines
1369
1370 if Last > Index then
1371 Tmp := Self;
1372 Self :=
1373 new String'
1374 (Tmp.all & Path_Separator &
1375 Buffer (Index .. Last - 1));
1376 Free (Tmp);
1377 end if;
1378
1379 -- Find the beginning of the next line
1380
1381 Index := Last;
1382 while Buffer (Index) = ASCII.CR or else
1383 Buffer (Index) = ASCII.LF
1384 loop
1385 Index := Index + 1;
1386 end loop;
1387 end loop;
1388 end;
1389 end if;
1390
1391 end if;
1392
1393 if Gpr_Prj_Path.all /= "" then
1394 Add_Directories (Self, Gpr_Prj_Path.all);
1395 end if;
1396
1397 Free (Gpr_Prj_Path);
1398
1399 if Ada_Prj_Path.all /= "" then
1400 Add_Directories (Self, Ada_Prj_Path.all);
1401 end if;
1402
1403 Free (Ada_Prj_Path);
1404
1405 -- Copy to Name_Buffer, since we will need to manipulate the path
1406
1407 Name_Len := Self'Length;
1408 Name_Buffer (1 .. Name_Len) := Self.all;
1409
1410 -- Scan the directory path to see if "-" is one of the directories.
1411 -- Remove each occurrence of "-" and set Add_Default_Dir to False.
1412 -- Also resolve relative paths and symbolic links.
1413
1414 First := 3;
1415 loop
1416 while First <= Name_Len
1417 and then Name_Buffer (First) = Path_Separator
1418 loop
1419 First := First + 1;
1420 end loop;
1421
1422 exit when First > Name_Len;
1423
1424 Last := First;
1425
1426 while Last < Name_Len
1427 and then Name_Buffer (Last + 1) /= Path_Separator
1428 loop
1429 Last := Last + 1;
1430 end loop;
1431
1432 -- If the directory is "-", set Add_Default_Dir to False and
1433 -- remove from path.
1434
1435 if Name_Buffer (First .. Last) = "-" then
1436 Add_Default_Dir := False;
1437
1438 for J in Last + 1 .. Name_Len loop
1439 Name_Buffer (J - 2) := Name_Buffer (J);
1440 end loop;
1441
1442 Name_Len := Name_Len - 2;
1443
1444 -- After removing the '-', go back one character to get the
1445 -- next directory correctly.
1446
1447 Last := Last - 1;
1448
1449 else
1450 declare
1451 New_Dir : constant String :=
1452 Normalize_Pathname
1453 (Name_Buffer (First .. Last),
1454 Resolve_Links => Opt.Follow_Links_For_Dirs);
1455 New_Len : Positive;
1456 New_Last : Positive;
1457
1458 begin
1459 -- If the absolute path was resolved and is different from
1460 -- the original, replace original with the resolved path.
1461
1462 if New_Dir /= Name_Buffer (First .. Last)
1463 and then New_Dir'Length /= 0
1464 then
1465 New_Len := Name_Len + New_Dir'Length - (Last - First + 1);
1466 New_Last := First + New_Dir'Length - 1;
1467 Name_Buffer (New_Last + 1 .. New_Len) :=
1468 Name_Buffer (Last + 1 .. Name_Len);
1469 Name_Buffer (First .. New_Last) := New_Dir;
1470 Name_Len := New_Len;
1471 Last := New_Last;
1472 end if;
1473 end;
1474 end if;
1475
1476 First := Last + 1;
1477 end loop;
1478
1479 Free (Self);
1480
1481 -- Set the initial value of Current_Project_Path
1482
1483 if Add_Default_Dir then
1484 if Sdefault.Search_Dir_Prefix = null then
1485
1486 -- gprbuild case
1487
1488 Prefix := new String'(Executable_Prefix_Path);
1489
1490 else
1491 Prefix := new String'(Sdefault.Search_Dir_Prefix.all
1492 & ".." & Dir_Separator
1493 & ".." & Dir_Separator
1494 & ".." & Dir_Separator
1495 & ".." & Dir_Separator);
1496 end if;
1497
1498 if Prefix.all /= "" then
1499 if Target_Name /= "" then
1500
1501 if Runtime_Name /= "" then
1502 if Base_Name (Runtime_Name) = Runtime_Name then
1503
1504 -- $prefix/$target/$runtime/lib/gnat
1505
1506 Add_Target
1507 (Runtime_Name & Directory_Separator &
1508 "lib" & Directory_Separator & "gnat");
1509
1510 -- $prefix/$target/$runtime/share/gpr
1511
1512 Add_Target
1513 (Runtime_Name & Directory_Separator &
1514 "share" & Directory_Separator & "gpr");
1515
1516 else
1517 Runtime :=
1518 new String'(Normalize_Pathname (Runtime_Name));
1519
1520 -- $runtime_dir/lib/gnat
1521
1522 Add_Str_To_Name_Buffer
1523 (Path_Separator & Runtime.all & Directory_Separator &
1524 "lib" & Directory_Separator & "gnat");
1525
1526 -- $runtime_dir/share/gpr
1527
1528 Add_Str_To_Name_Buffer
1529 (Path_Separator & Runtime.all & Directory_Separator &
1530 "share" & Directory_Separator & "gpr");
1531 end if;
1532 end if;
1533
1534 -- $prefix/$target/lib/gnat
1535
1536 Add_Target
1537 ("lib" & Directory_Separator & "gnat");
1538
1539 -- $prefix/$target/share/gpr
1540
1541 Add_Target
1542 ("share" & Directory_Separator & "gpr");
1543 end if;
1544
1545 -- $prefix/share/gpr
1546
1547 Add_Str_To_Name_Buffer
1548 (Path_Separator & Prefix.all & "share"
1549 & Directory_Separator & "gpr");
1550
1551 -- $prefix/lib/gnat
1552
1553 Add_Str_To_Name_Buffer
1554 (Path_Separator & Prefix.all & "lib"
1555 & Directory_Separator & "gnat");
1556 end if;
1557
1558 Free (Prefix);
1559 end if;
1560
1561 Self := new String'(Name_Buffer (1 .. Name_Len));
1562 end Initialize_Default_Project_Path;
1563
1564 -----------------------
1565 -- Get_Runtime_Path --
1566 -----------------------
1567
1568 function Get_Runtime_Path
1569 (Self : String_Access;
1570 Path : String) return String_Access
1571 is
1572 First : Natural;
1573 Last : Natural;
1574
1575 begin
1576 if Is_Absolute_Path (Path) then
1577 if Is_Directory (Path) then
1578 return new String'(Path);
1579 else
1580 return null;
1581 end if;
1582
1583 else
1584 -- Because we do not want to resolve symbolic links, we cannot
1585 -- use Locate_Regular_File. Instead we try each possible path
1586 -- successively.
1587
1588 First := Self'First;
1589 while First <= Self'Last loop
1590 while First <= Self'Last
1591 and then Self (First) = Path_Separator
1592 loop
1593 First := First + 1;
1594 end loop;
1595
1596 exit when First > Self'Last;
1597
1598 Last := First;
1599 while Last < Self'Last
1600 and then Self (Last + 1) /= Path_Separator
1601 loop
1602 Last := Last + 1;
1603 end loop;
1604
1605 Name_Len := 0;
1606
1607 if not Is_Absolute_Path (Self (First .. Last)) then
1608 Add_Str_To_Name_Buffer (Get_Current_Dir); -- ??? System call
1609 Add_Char_To_Name_Buffer (Directory_Separator);
1610 end if;
1611
1612 Add_Str_To_Name_Buffer (Self (First .. Last));
1613 Add_Char_To_Name_Buffer (Directory_Separator);
1614 Add_Str_To_Name_Buffer (Path);
1615
1616 if Is_Directory (Name_Buffer (1 .. Name_Len)) then
1617 return new String'(Name_Buffer (1 .. Name_Len));
1618 end if;
1619
1620 First := Last + 1;
1621 end loop;
1622 end if;
1623
1624 return null;
1625 end Get_Runtime_Path;
1626
1627 end Prj_Env;
1628
1629 -----------------
1630 -- Reset_Print --
1631 -----------------
1632
1633 procedure Reset_Print is
1634 begin
1635 if not Selective_Output then
1636 Selective_Output := True;
1637 Print_Source := False;
1638 Print_Object := False;
1639 Print_Unit := False;
1640 end if;
1641 end Reset_Print;
1642
1643 ----------------
1644 -- Search_RTS --
1645 ----------------
1646
1647 procedure Search_RTS (Name : String) is
1648 Src_Path : String_Ptr;
1649 Lib_Path : String_Ptr;
1650 -- Paths for source and include subdirs
1651
1652 Rts_Full_Path : String_Access;
1653 -- Full path for RTS project
1654
1655 begin
1656 -- Try to find the RTS
1657
1658 Src_Path := Get_RTS_Search_Dir (Name, Include);
1659 Lib_Path := Get_RTS_Search_Dir (Name, Objects);
1660
1661 -- For non-project RTS, both the include and the objects directories
1662 -- must be present.
1663
1664 if Src_Path /= null and then Lib_Path /= null then
1665 Add_Search_Dirs (Src_Path, Include);
1666 Add_Search_Dirs (Lib_Path, Objects);
1667 Prj_Env.Initialize_Default_Project_Path
1668 (Prj_Path,
1669 Target_Name => Sdefault.Target_Name.all,
1670 Runtime_Name => Name);
1671 return;
1672 end if;
1673
1674 if Lib_Path /= null then
1675 Osint.Fail
1676 ("RTS path """ & Name
1677 & """ not valid: missing adainclude directory");
1678 elsif Src_Path /= null then
1679 Osint.Fail
1680 ("RTS path """ & Name
1681 & """ not valid: missing adalib directory");
1682 end if;
1683
1684 -- Try to find the RTS on the project path. First setup the project path
1685
1686 Prj_Env.Initialize_Default_Project_Path
1687 (Prj_Path,
1688 Target_Name => Sdefault.Target_Name.all,
1689 Runtime_Name => Name);
1690
1691 Rts_Full_Path := Prj_Env.Get_Runtime_Path (Prj_Path, Name);
1692
1693 if Rts_Full_Path /= null then
1694
1695 -- Directory name was found on the project path. Look for the
1696 -- include subdirectory(s).
1697
1698 Src_Path := Get_RTS_Search_Dir (Rts_Full_Path.all, Include);
1699
1700 if Src_Path /= null then
1701 Add_Search_Dirs (Src_Path, Include);
1702
1703 -- Add the lib subdirectory if it exists
1704
1705 Lib_Path := Get_RTS_Search_Dir (Rts_Full_Path.all, Objects);
1706
1707 if Lib_Path /= null then
1708 Add_Search_Dirs (Lib_Path, Objects);
1709 end if;
1710
1711 return;
1712 end if;
1713 end if;
1714
1715 Osint.Fail
1716 ("RTS path """ & Name
1717 & """ not valid: missing adainclude and adalib directories");
1718 end Search_RTS;
1719
1720 -------------------
1721 -- Scan_Ls_Arg --
1722 -------------------
1723
1724 procedure Scan_Ls_Arg (Argv : String) is
1725 FD : File_Descriptor;
1726 Len : Integer;
1727 OK : Boolean;
1728
1729 begin
1730 pragma Assert (Argv'First = 1);
1731
1732 if Argv'Length = 0 then
1733 return;
1734 end if;
1735
1736 OK := True;
1737 if Argv (1) = '-' then
1738 if Argv'Length = 1 then
1739 Fail ("switch character cannot be followed by a blank");
1740
1741 -- Processing for -I-
1742
1743 elsif Argv (2 .. Argv'Last) = "I-" then
1744 Opt.Look_In_Primary_Dir := False;
1745
1746 -- Forbid -?- or -??- where ? is any character
1747
1748 elsif (Argv'Length = 3 and then Argv (3) = '-')
1749 or else (Argv'Length = 4 and then Argv (4) = '-')
1750 then
1751 Fail ("Trailing ""-"" at the end of " & Argv & " forbidden.");
1752
1753 -- Processing for -Idir
1754
1755 elsif Argv (2) = 'I' then
1756 Add_Source_Dir (Argv (3 .. Argv'Last));
1757 Add_Lib_Dir (Argv (3 .. Argv'Last));
1758
1759 -- Processing for -aIdir (to gcc this is like a -I switch)
1760
1761 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aI" then
1762 Add_Source_Dir (Argv (4 .. Argv'Last));
1763
1764 -- Processing for -aOdir
1765
1766 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aO" then
1767 Add_Lib_Dir (Argv (4 .. Argv'Last));
1768
1769 -- Processing for -aLdir (to gnatbind this is like a -aO switch)
1770
1771 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aL" then
1772 Add_Lib_Dir (Argv (4 .. Argv'Last));
1773
1774 -- Processing for -aP<dir>
1775
1776 elsif Argv'Length > 3 and then Argv (1 .. 3) = "-aP" then
1777 Prj_Env.Add_Directories (Prj_Path, Argv (4 .. Argv'Last));
1778
1779 -- Processing for -nostdinc
1780
1781 elsif Argv (2 .. Argv'Last) = "nostdinc" then
1782 Opt.No_Stdinc := True;
1783
1784 -- Processing for one character switches
1785
1786 elsif Argv'Length = 2 then
1787 case Argv (2) is
1788 when 'a' => Also_Predef := True;
1789 when 'h' => Print_Usage := True;
1790 when 'u' => Reset_Print; Print_Unit := True;
1791 when 's' => Reset_Print; Print_Source := True;
1792 when 'o' => Reset_Print; Print_Object := True;
1793 when 'v' => Verbose_Mode := True;
1794 when 'd' => Dependable := True;
1795 when 'l' => License := True;
1796 when 'V' => Very_Verbose_Mode := True;
1797
1798 when others => OK := False;
1799 end case;
1800
1801 -- Processing for -files=file
1802
1803 elsif Argv'Length > 7 and then Argv (1 .. 7) = "-files=" then
1804 FD := Open_Read (Argv (8 .. Argv'Last), GNAT.OS_Lib.Text);
1805
1806 if FD = Invalid_FD then
1807 Osint.Fail ("could not find text file """ &
1808 Argv (8 .. Argv'Last) & '"');
1809 end if;
1810
1811 Len := Integer (File_Length (FD));
1812
1813 declare
1814 Buffer : String (1 .. Len + 1);
1815 Index : Positive := 1;
1816 Last : Positive;
1817
1818 begin
1819 -- Read the file
1820
1821 Len := Read (FD, Buffer (1)'Address, Len);
1822 Buffer (Buffer'Last) := ASCII.NUL;
1823 Close (FD);
1824
1825 -- Scan the file line by line
1826
1827 while Index < Buffer'Last loop
1828
1829 -- Find the end of line
1830
1831 Last := Index;
1832 while Last <= Buffer'Last
1833 and then Buffer (Last) /= ASCII.LF
1834 and then Buffer (Last) /= ASCII.CR
1835 loop
1836 Last := Last + 1;
1837 end loop;
1838
1839 -- Ignore empty lines
1840
1841 if Last > Index then
1842 Add_File (Buffer (Index .. Last - 1));
1843 end if;
1844
1845 -- Find the beginning of the next line
1846
1847 Index := Last;
1848 while Buffer (Index) = ASCII.CR or else
1849 Buffer (Index) = ASCII.LF
1850 loop
1851 Index := Index + 1;
1852 end loop;
1853 end loop;
1854 end;
1855
1856 -- Processing for --RTS=path
1857
1858 elsif Argv'Length >= 5 and then Argv (1 .. 5) = "--RTS" then
1859 if Argv'Length <= 6 or else Argv (6) /= '='then
1860 Osint.Fail ("missing path for --RTS");
1861
1862 else
1863 -- Check that it is the first time we see this switch or, if
1864 -- it is not the first time, the same path is specified.
1865
1866 if RTS_Specified = null then
1867 RTS_Specified := new String'(Argv (7 .. Argv'Last));
1868
1869 elsif RTS_Specified.all /= Argv (7 .. Argv'Last) then
1870 Osint.Fail ("--RTS cannot be specified multiple times");
1871 end if;
1872
1873 -- Valid --RTS switch
1874
1875 Opt.No_Stdinc := True;
1876 Opt.RTS_Switch := True;
1877 end if;
1878
1879 else
1880 OK := False;
1881 end if;
1882
1883 -- If not a switch, it must be a file name
1884
1885 else
1886 Add_File (Argv);
1887 end if;
1888
1889 if not OK then
1890 Write_Str ("warning: unknown switch """);
1891 Write_Str (Argv);
1892 Write_Line ("""");
1893 end if;
1894
1895 end Scan_Ls_Arg;
1896
1897 -----------
1898 -- Usage --
1899 -----------
1900
1901 procedure Usage is
1902 begin
1903 -- Usage line
1904
1905 Write_Str ("Usage: ");
1906 Osint.Write_Program_Name;
1907 Write_Str (" switches [list of object files]");
1908 Write_Eol;
1909 Write_Eol;
1910
1911 -- GNATLS switches
1912
1913 Write_Str ("switches:");
1914 Write_Eol;
1915
1916 Display_Usage_Version_And_Help;
1917
1918 -- Line for -a
1919
1920 Write_Str (" -a also output relevant predefined units");
1921 Write_Eol;
1922
1923 -- Line for -u
1924
1925 Write_Str (" -u output only relevant unit names");
1926 Write_Eol;
1927
1928 -- Line for -h
1929
1930 Write_Str (" -h output this help message");
1931 Write_Eol;
1932
1933 -- Line for -s
1934
1935 Write_Str (" -s output only relevant source names");
1936 Write_Eol;
1937
1938 -- Line for -o
1939
1940 Write_Str (" -o output only relevant object names");
1941 Write_Eol;
1942
1943 -- Line for -d
1944
1945 Write_Str (" -d output sources on which specified units " &
1946 "depend");
1947 Write_Eol;
1948
1949 -- Line for -l
1950
1951 Write_Str (" -l output license information");
1952 Write_Eol;
1953
1954 -- Line for -v
1955
1956 Write_Str (" -v verbose output, full path and unit " &
1957 "information");
1958 Write_Eol;
1959 Write_Eol;
1960
1961 -- Line for -files=
1962
1963 Write_Str (" -files=fil files are listed in text file 'fil'");
1964 Write_Eol;
1965
1966 -- Line for -aI switch
1967
1968 Write_Str (" -aIdir specify source files search path");
1969 Write_Eol;
1970
1971 -- Line for -aO switch
1972
1973 Write_Str (" -aOdir specify object files search path");
1974 Write_Eol;
1975
1976 -- Line for -aP switch
1977
1978 Write_Str (" -aPdir specify project search path");
1979 Write_Eol;
1980
1981 -- Line for -I switch
1982
1983 Write_Str (" -Idir like -aIdir -aOdir");
1984 Write_Eol;
1985
1986 -- Line for -I- switch
1987
1988 Write_Str (" -I- do not look for sources & object files");
1989 Write_Str (" in the default directory");
1990 Write_Eol;
1991
1992 -- Line for -nostdinc
1993
1994 Write_Str (" -nostdinc do not look for source files");
1995 Write_Str (" in the system default directory");
1996 Write_Eol;
1997
1998 -- Line for --RTS
1999
2000 Write_Str (" --RTS=dir specify the default source and object search"
2001 & " path");
2002 Write_Eol;
2003
2004 -- File Status explanation
2005
2006 Write_Eol;
2007 Write_Str (" file status can be:");
2008 Write_Eol;
2009
2010 for ST in File_Status loop
2011 Write_Str (" ");
2012 Output_Status (ST, Verbose => False);
2013 Write_Str (" ==> ");
2014 Output_Status (ST, Verbose => True);
2015 Write_Eol;
2016 end loop;
2017 end Usage;
2018
2019 procedure Check_Version_And_Help is new Check_Version_And_Help_G (Usage);
2020
2021 -- Start of processing for Gnatls
2022
2023 begin
2024 -- Initialize standard packages
2025
2026 Csets.Initialize;
2027 Uintp.Initialize;
2028 Snames.Initialize;
2029 Stringt.Initialize;
2030
2031 -- First check for --version or --help
2032
2033 Check_Version_And_Help ("GNATLS", "1992");
2034
2035 -- Loop to scan out arguments
2036
2037 Next_Arg := 1;
2038 Scan_Args : while Next_Arg < Arg_Count loop
2039 declare
2040 Next_Argv : String (1 .. Len_Arg (Next_Arg));
2041 begin
2042 Fill_Arg (Next_Argv'Address, Next_Arg);
2043 Scan_Ls_Arg (Next_Argv);
2044 end;
2045
2046 Next_Arg := Next_Arg + 1;
2047 end loop Scan_Args;
2048
2049 -- If -l (output license information) is given, it must be the only switch
2050
2051 if License then
2052 if Arg_Count = 2 then
2053 Output_License_Information;
2054
2055 else
2056 Set_Standard_Error;
2057 Write_Str ("Can't use -l with another switch");
2058 Write_Eol;
2059 Try_Help;
2060 Exit_Program (E_Fatal);
2061 end if;
2062 end if;
2063
2064 -- Handle --RTS switch
2065
2066 if RTS_Specified /= null then
2067 Search_RTS (RTS_Specified.all);
2068 end if;
2069
2070 -- Add the source and object directories specified on the command line, if
2071 -- any, to the searched directories.
2072
2073 while First_Source_Dir /= null loop
2074 Add_Src_Search_Dir (First_Source_Dir.Value.all);
2075 First_Source_Dir := First_Source_Dir.Next;
2076 end loop;
2077
2078 while First_Lib_Dir /= null loop
2079 Add_Lib_Search_Dir (First_Lib_Dir.Value.all);
2080 First_Lib_Dir := First_Lib_Dir.Next;
2081 end loop;
2082
2083 -- Finally, add the default directories
2084
2085 Osint.Add_Default_Search_Dirs;
2086
2087 -- If --RTS= is not specified, check if there is a default runtime
2088
2089 if RTS_Specified = null then
2090 declare
2091 FD : File_Descriptor;
2092 Text : Source_Buffer_Ptr;
2093 Hi : Source_Ptr;
2094
2095 begin
2096 Read_Source_File (Name_Find ("system.ads"), 0, Hi, Text, FD);
2097
2098 if Null_Source_Buffer_Ptr (Text) then
2099 No_Runtime := True;
2100 end if;
2101 end;
2102 end if;
2103
2104 if Verbose_Mode then
2105 Write_Eol;
2106 Display_Version ("GNATLS", "1997");
2107 Write_Eol;
2108
2109 if No_Runtime then
2110 Write_Str
2111 ("Default runtime not available. Use --RTS= with a valid runtime");
2112 Write_Eol;
2113 Write_Eol;
2114 Exit_Status := E_Warnings;
2115 end if;
2116
2117 Write_Str ("Source Search Path:");
2118 Write_Eol;
2119
2120 for J in 1 .. Nb_Dir_In_Src_Search_Path loop
2121 Write_Str (" ");
2122
2123 if Dir_In_Src_Search_Path (J)'Length = 0 then
2124 Write_Str ("<Current_Directory>");
2125 Write_Eol;
2126
2127 elsif not No_Runtime then
2128 Write_Str
2129 (Normalize
2130 (To_Host_Dir_Spec
2131 (Dir_In_Src_Search_Path (J).all, True).all));
2132 Write_Eol;
2133 end if;
2134 end loop;
2135
2136 Write_Eol;
2137 Write_Eol;
2138 Write_Str ("Object Search Path:");
2139 Write_Eol;
2140
2141 for J in 1 .. Nb_Dir_In_Obj_Search_Path loop
2142 Write_Str (" ");
2143
2144 if Dir_In_Obj_Search_Path (J)'Length = 0 then
2145 Write_Str ("<Current_Directory>");
2146 Write_Eol;
2147
2148 elsif not No_Runtime then
2149 Write_Str
2150 (Normalize
2151 (To_Host_Dir_Spec
2152 (Dir_In_Obj_Search_Path (J).all, True).all));
2153 Write_Eol;
2154 end if;
2155 end loop;
2156
2157 Write_Eol;
2158 Write_Eol;
2159 Write_Str (Project_Search_Path);
2160 Write_Eol;
2161 Write_Str (" <Current_Directory>");
2162 Write_Eol;
2163
2164 Prj_Env.Initialize_Default_Project_Path
2165 (Prj_Path, Target_Name => Sdefault.Target_Name.all);
2166
2167 declare
2168 First : Natural;
2169 Last : Natural;
2170
2171 begin
2172
2173 if Prj_Path.all /= "" then
2174 First := Prj_Path'First;
2175 loop
2176 while First <= Prj_Path'Last
2177 and then Prj_Path (First) = Path_Separator
2178 loop
2179 First := First + 1;
2180 end loop;
2181
2182 exit when First > Prj_Path'Last;
2183
2184 Last := First;
2185 while Last < Prj_Path'Last
2186 and then Prj_Path (Last + 1) /= Path_Separator
2187 loop
2188 Last := Last + 1;
2189 end loop;
2190
2191 if First /= Last or else Prj_Path (First) /= '.' then
2192
2193 -- If the directory is ".", skip it as it is the current
2194 -- directory and it is already the first directory in the
2195 -- project path.
2196
2197 Write_Str (" ");
2198 Write_Str
2199 (Normalize
2200 (To_Host_Dir_Spec
2201 (Prj_Path (First .. Last), True).all));
2202 Write_Eol;
2203 end if;
2204
2205 First := Last + 1;
2206 end loop;
2207 end if;
2208 end;
2209
2210 Write_Eol;
2211 end if;
2212
2213 -- Output usage information when requested
2214
2215 if Print_Usage then
2216 Usage;
2217 end if;
2218
2219 if not More_Lib_Files then
2220 if not Print_Usage and then not Verbose_Mode then
2221 if Arg_Count = 1 then
2222 Usage;
2223 else
2224 Try_Help;
2225 Exit_Status := E_Fatal;
2226 end if;
2227 end if;
2228
2229 Exit_Program (Exit_Status);
2230 end if;
2231
2232 Initialize_ALI;
2233 Initialize_ALI_Source;
2234
2235 -- Print out all libraries for which no ALI files can be located
2236
2237 while More_Lib_Files loop
2238 Main_File := Next_Main_Lib_File;
2239 Ali_File := Full_Lib_File_Name (Lib_File_Name (Main_File));
2240
2241 if Ali_File = No_File then
2242 if Very_Verbose_Mode then
2243 GNATDIST.Output_No_ALI (Lib_File_Name (Main_File));
2244
2245 else
2246 Set_Standard_Error;
2247 Write_Str ("Can't find library info for ");
2248 Get_Name_String (Main_File);
2249 Write_Char ('"'); -- "
2250 Write_Str (Name_Buffer (1 .. Name_Len));
2251 Write_Char ('"'); -- "
2252 Write_Eol;
2253 Exit_Status := E_Fatal;
2254 end if;
2255
2256 else
2257 Ali_File := Strip_Directory (Ali_File);
2258
2259 if Get_Name_Table_Int (Ali_File) = 0 then
2260 Text := Read_Library_Info (Ali_File, True);
2261
2262 declare
2263 Discard : ALI_Id;
2264 begin
2265 Discard :=
2266 Scan_ALI
2267 (Ali_File,
2268 Text,
2269 Err => False,
2270 Ignore_Errors => True);
2271 end;
2272
2273 Free (Text);
2274 end if;
2275 end if;
2276 end loop;
2277
2278 -- Reset default output file descriptor, if needed
2279
2280 Set_Standard_Output;
2281
2282 if Very_Verbose_Mode then
2283 for A in ALIs.First .. ALIs.Last loop
2284 GNATDIST.Output_ALI (A);
2285 end loop;
2286
2287 return;
2288 end if;
2289
2290 Find_General_Layout;
2291
2292 for Id in ALIs.First .. ALIs.Last loop
2293 declare
2294 Last_U : Unit_Id;
2295
2296 begin
2297 Get_Name_String (Units.Table (ALIs.Table (Id).First_Unit).Uname);
2298
2299 if Also_Predef or else not Is_Internal_Unit then
2300 if ALIs.Table (Id).No_Object then
2301 Output_Object (No_File);
2302 else
2303 Output_Object (ALIs.Table (Id).Ofile_Full_Name);
2304 end if;
2305
2306 -- In verbose mode print all main units in the ALI file, otherwise
2307 -- just print the first one to ease columnwise printout
2308
2309 if Verbose_Mode then
2310 Last_U := ALIs.Table (Id).Last_Unit;
2311 else
2312 Last_U := ALIs.Table (Id).First_Unit;
2313 end if;
2314
2315 for U in ALIs.Table (Id).First_Unit .. Last_U loop
2316 if U /= ALIs.Table (Id).First_Unit
2317 and then Selective_Output
2318 and then Print_Unit
2319 then
2320 Write_Eol;
2321 end if;
2322
2323 Output_Unit (Id, U);
2324
2325 -- Output source now, unless if it will be done as part of
2326 -- outputing dependencies.
2327
2328 if not (Dependable and then Print_Source) then
2329 Output_Source (Corresponding_Sdep_Entry (Id, U));
2330 end if;
2331 end loop;
2332
2333 -- Print out list of units on which this unit depends (D lines)
2334
2335 if Dependable and then Print_Source then
2336 if Verbose_Mode then
2337 Write_Str ("depends upon");
2338 Write_Eol;
2339 Write_Str (" ");
2340 else
2341 Write_Eol;
2342 end if;
2343
2344 for D in
2345 ALIs.Table (Id).First_Sdep .. ALIs.Table (Id).Last_Sdep
2346 loop
2347 if Also_Predef
2348 or else not Is_Internal_File_Name (Sdep.Table (D).Sfile)
2349 then
2350 if Verbose_Mode then
2351 Write_Str (" ");
2352 Output_Source (D);
2353
2354 elsif Too_Long then
2355 Write_Str (" ");
2356 Output_Source (D);
2357 Write_Eol;
2358
2359 else
2360 Write_Str (Spaces (1 .. Source_Start - 2));
2361 Output_Source (D);
2362 Write_Eol;
2363 end if;
2364 end if;
2365 end loop;
2366 end if;
2367
2368 Write_Eol;
2369 end if;
2370 end;
2371 end loop;
2372
2373 -- All done. Set proper exit status
2374
2375 Namet.Finalize;
2376 Exit_Program (Exit_Status);
2377 end Gnatls;