OSDN Git Service

2009-11-30 Thomas Quinot <quinot@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / makeutl.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                              M A K E U T L                               --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 2004-2009, 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 with ALI;      use ALI;
27 with Debug;
28 with Fname;
29 with Osint;    use Osint;
30 with Output;   use Output;
31 with Opt;      use Opt;
32 with Prj.Ext;
33 with Prj.Util;
34 with Snames;   use Snames;
35 with Table;
36
37 with Ada.Command_Line;  use Ada.Command_Line;
38
39 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
40
41 with System.Case_Util; use System.Case_Util;
42 with System.HTable;
43
44 package body Makeutl is
45
46    type Mark_Key is record
47       File  : File_Name_Type;
48       Index : Int;
49    end record;
50    --  Identify either a mono-unit source (when Index = 0) or a specific unit
51    --  (index = 1's origin index of unit) in a multi-unit source.
52
53    --  There follow many global undocumented declarations, comments needed ???
54
55    Max_Mask_Num : constant := 2048;
56
57    subtype Mark_Num is Union_Id range 0 .. Max_Mask_Num - 1;
58
59    function Hash (Key : Mark_Key) return Mark_Num;
60
61    package Marks is new System.HTable.Simple_HTable
62      (Header_Num => Mark_Num,
63       Element    => Boolean,
64       No_Element => False,
65       Key        => Mark_Key,
66       Hash       => Hash,
67       Equal      => "=");
68    --  A hash table to keep tracks of the marked units
69
70    type Linker_Options_Data is record
71       Project : Project_Id;
72       Options : String_List_Id;
73    end record;
74
75    Linker_Option_Initial_Count : constant := 20;
76
77    Linker_Options_Buffer : String_List_Access :=
78      new String_List (1 .. Linker_Option_Initial_Count);
79
80    Last_Linker_Option : Natural := 0;
81
82    package Linker_Opts is new Table.Table (
83      Table_Component_Type => Linker_Options_Data,
84      Table_Index_Type     => Integer,
85      Table_Low_Bound      => 1,
86      Table_Initial        => 10,
87      Table_Increment      => 100,
88      Table_Name           => "Make.Linker_Opts");
89
90    procedure Add_Linker_Option (Option : String);
91
92    ---------
93    -- Add --
94    ---------
95
96    procedure Add
97      (Option : String_Access;
98       To     : in out String_List_Access;
99       Last   : in out Natural)
100    is
101    begin
102       if Last = To'Last then
103          declare
104             New_Options : constant String_List_Access :=
105                             new String_List (1 .. To'Last * 2);
106
107          begin
108             New_Options (To'Range) := To.all;
109
110             --  Set all elements of the original options to null to avoid
111             --  deallocation of copies.
112
113             To.all := (others => null);
114
115             Free (To);
116             To := New_Options;
117          end;
118       end if;
119
120       Last := Last + 1;
121       To (Last) := Option;
122    end Add;
123
124    procedure Add
125      (Option : String;
126       To     : in out String_List_Access;
127       Last   : in out Natural)
128    is
129    begin
130       Add (Option => new String'(Option), To => To, Last => Last);
131    end Add;
132
133    -----------------------
134    -- Add_Linker_Option --
135    -----------------------
136
137    procedure Add_Linker_Option (Option : String) is
138    begin
139       if Option'Length > 0 then
140          if Last_Linker_Option = Linker_Options_Buffer'Last then
141             declare
142                New_Buffer : constant String_List_Access :=
143                               new String_List
144                                 (1 .. Linker_Options_Buffer'Last +
145                                         Linker_Option_Initial_Count);
146             begin
147                New_Buffer (Linker_Options_Buffer'Range) :=
148                  Linker_Options_Buffer.all;
149                Linker_Options_Buffer.all := (others => null);
150                Free (Linker_Options_Buffer);
151                Linker_Options_Buffer := New_Buffer;
152             end;
153          end if;
154
155          Last_Linker_Option := Last_Linker_Option + 1;
156          Linker_Options_Buffer (Last_Linker_Option) := new String'(Option);
157       end if;
158    end Add_Linker_Option;
159
160    -------------------------
161    -- Base_Name_Index_For --
162    -------------------------
163
164    function Base_Name_Index_For
165      (Main            : String;
166       Main_Index      : Int;
167       Index_Separator : Character) return File_Name_Type
168    is
169       Result : File_Name_Type;
170    begin
171       Name_Len := 0;
172       Add_Str_To_Name_Buffer (Base_Name (Main));
173
174       --  Remove the extension, if any, that is the last part of the base
175       --  name starting with a dot and following some characters.
176
177       for J in reverse 2 .. Name_Len loop
178          if Name_Buffer (J) = '.' then
179             Name_Len := J - 1;
180             exit;
181          end if;
182       end loop;
183
184       --  Add the index info, if index is different from 0
185
186       if Main_Index > 0 then
187          Add_Char_To_Name_Buffer (Index_Separator);
188
189          declare
190             Img : constant String := Main_Index'Img;
191          begin
192             Add_Str_To_Name_Buffer (Img (2 .. Img'Last));
193          end;
194       end if;
195       Result := Name_Find;
196       return Result;
197    end Base_Name_Index_For;
198
199    ------------------------------
200    -- Check_Source_Info_In_ALI --
201    ------------------------------
202
203    function Check_Source_Info_In_ALI (The_ALI : ALI_Id) return Boolean is
204       Unit_Name : Name_Id;
205
206    begin
207       --  Loop through units
208
209       for U in ALIs.Table (The_ALI).First_Unit ..
210                ALIs.Table (The_ALI).Last_Unit
211       loop
212          --  Check if the file name is one of the source of the unit
213
214          Get_Name_String (Units.Table (U).Uname);
215          Name_Len  := Name_Len - 2;
216          Unit_Name := Name_Find;
217
218          if File_Not_A_Source_Of (Unit_Name, Units.Table (U).Sfile) then
219             return False;
220          end if;
221
222          --  Loop to do same check for each of the withed units
223
224          for W in Units.Table (U).First_With .. Units.Table (U).Last_With loop
225             declare
226                WR : ALI.With_Record renames Withs.Table (W);
227
228             begin
229                if WR.Sfile /= No_File then
230                   Get_Name_String (WR.Uname);
231                   Name_Len  := Name_Len - 2;
232                   Unit_Name := Name_Find;
233
234                   if File_Not_A_Source_Of (Unit_Name, WR.Sfile) then
235                      return False;
236                   end if;
237                end if;
238             end;
239          end loop;
240       end loop;
241
242       --  Loop to check subunits
243
244       for D in ALIs.Table (The_ALI).First_Sdep ..
245                ALIs.Table (The_ALI).Last_Sdep
246       loop
247          declare
248             SD : Sdep_Record renames Sdep.Table (D);
249
250          begin
251             Unit_Name := SD.Subunit_Name;
252
253             if Unit_Name /= No_Name then
254
255                --  For separates, the file is no longer associated with the
256                --  unit ("proc-sep.adb" is not associated with unit "proc.sep")
257                --  so we need to check whether the source file still exists in
258                --  the source tree: it will if it matches the naming scheme
259                --  (and then will be for the same unit).
260
261                if Find_Source
262                     (In_Tree   => Project_Tree,
263                      Project   => No_Project,
264                      Base_Name => SD.Sfile) = No_Source
265                then
266                   --  If this is not a runtime file or if, when gnatmake switch
267                   --  -a is used, we are not able to find this subunit in the
268                   --  source directories, then recompilation is needed.
269
270                   if not Fname.Is_Internal_File_Name (SD.Sfile)
271                     or else
272                       (Check_Readonly_Files
273                         and then Find_File (SD.Sfile, Osint.Source) = No_File)
274                   then
275                      if Verbose_Mode then
276                         Write_Line
277                           ("While parsing ALI file, file "
278                            & Get_Name_String (SD.Sfile)
279                            & " is indicated as containing subunit "
280                            & Get_Name_String (Unit_Name)
281                            & " but this does not match what was found while"
282                            & " parsing the project. Will recompile");
283                      end if;
284
285                      return False;
286                   end if;
287                end if;
288             end if;
289          end;
290       end loop;
291
292       return True;
293    end Check_Source_Info_In_ALI;
294
295    -----------------
296    -- Create_Name --
297    -----------------
298
299    function Create_Name (Name : String) return File_Name_Type is
300    begin
301       Name_Len := 0;
302       Add_Str_To_Name_Buffer (Name);
303       return Name_Find;
304    end Create_Name;
305
306    function Create_Name (Name : String) return Name_Id is
307    begin
308       Name_Len := 0;
309       Add_Str_To_Name_Buffer (Name);
310       return Name_Find;
311    end Create_Name;
312
313    function Create_Name (Name : String) return Path_Name_Type is
314    begin
315       Name_Len := 0;
316       Add_Str_To_Name_Buffer (Name);
317       return Name_Find;
318    end Create_Name;
319
320    ----------------------
321    -- Delete_All_Marks --
322    ----------------------
323
324    procedure Delete_All_Marks is
325    begin
326       Marks.Reset;
327    end Delete_All_Marks;
328
329    ----------------------------
330    -- Executable_Prefix_Path --
331    ----------------------------
332
333    function Executable_Prefix_Path return String is
334       Exec_Name : constant String := Command_Name;
335
336       function Get_Install_Dir (S : String) return String;
337       --  S is the executable name preceded by the absolute or relative path,
338       --  e.g. "c:\usr\bin\gcc.exe". Returns the absolute directory where "bin"
339       --  lies (in the example "C:\usr"). If the executable is not in a "bin"
340       --  directory, return "".
341
342       ---------------------
343       -- Get_Install_Dir --
344       ---------------------
345
346       function Get_Install_Dir (S : String) return String is
347          Exec      : String  := S;
348          Path_Last : Integer := 0;
349
350       begin
351          for J in reverse Exec'Range loop
352             if Exec (J) = Directory_Separator then
353                Path_Last := J - 1;
354                exit;
355             end if;
356          end loop;
357
358          if Path_Last >= Exec'First + 2 then
359             To_Lower (Exec (Path_Last - 2 .. Path_Last));
360          end if;
361
362          if Path_Last < Exec'First + 2
363            or else Exec (Path_Last - 2 .. Path_Last) /= "bin"
364            or else (Path_Last - 3 >= Exec'First
365                      and then Exec (Path_Last - 3) /= Directory_Separator)
366          then
367             return "";
368          end if;
369
370          return Normalize_Pathname
371                   (Exec (Exec'First .. Path_Last - 4),
372                    Resolve_Links => Opt.Follow_Links_For_Dirs)
373            & Directory_Separator;
374       end Get_Install_Dir;
375
376    --  Beginning of Executable_Prefix_Path
377
378    begin
379       --  First determine if a path prefix was placed in front of the
380       --  executable name.
381
382       for J in reverse Exec_Name'Range loop
383          if Exec_Name (J) = Directory_Separator then
384             return Get_Install_Dir (Exec_Name);
385          end if;
386       end loop;
387
388       --  If we get here, the user has typed the executable name with no
389       --  directory prefix.
390
391       declare
392          Path : String_Access := Locate_Exec_On_Path (Exec_Name);
393       begin
394          if Path = null then
395             return "";
396          else
397             declare
398                Dir : constant String := Get_Install_Dir (Path.all);
399             begin
400                Free (Path);
401                return Dir;
402             end;
403          end if;
404       end;
405    end Executable_Prefix_Path;
406
407    --------------------------
408    -- File_Not_A_Source_Of --
409    --------------------------
410
411    function File_Not_A_Source_Of
412      (Uname : Name_Id;
413       Sfile : File_Name_Type) return Boolean
414    is
415       Unit : constant Unit_Index :=
416                Units_Htable.Get (Project_Tree.Units_HT, Uname);
417
418       At_Least_One_File : Boolean := False;
419
420    begin
421       if Unit /= No_Unit_Index then
422          for F in Unit.File_Names'Range loop
423             if Unit.File_Names (F) /= null then
424                At_Least_One_File := True;
425                if Unit.File_Names (F).File = Sfile then
426                   return False;
427                end if;
428             end if;
429          end loop;
430
431          if not At_Least_One_File then
432
433             --  The unit was probably created initially for a separate unit
434             --  (which are initially created as IMPL when both suffixes are the
435             --  same). Later on, Override_Kind changed the type of the file,
436             --  and the unit is no longer valid in fact.
437
438             return False;
439          end if;
440
441          Verbose_Msg (Uname, "sources do not include ", Name_Id (Sfile));
442          return True;
443       end if;
444
445       return False;
446    end File_Not_A_Source_Of;
447
448    ----------
449    -- Hash --
450    ----------
451
452    function Hash (Key : Mark_Key) return Mark_Num is
453    begin
454       return Union_Id (Key.File) mod Max_Mask_Num;
455    end Hash;
456
457    ------------
458    -- Inform --
459    ------------
460
461    procedure Inform (N : File_Name_Type; Msg : String) is
462    begin
463       Inform (Name_Id (N), Msg);
464    end Inform;
465
466    procedure Inform (N : Name_Id := No_Name; Msg : String) is
467    begin
468       Osint.Write_Program_Name;
469
470       Write_Str (": ");
471
472       if N /= No_Name then
473          Write_Str ("""");
474
475          declare
476             Name : constant String := Get_Name_String (N);
477          begin
478             if Debug.Debug_Flag_F and then Is_Absolute_Path (Name) then
479                Write_Str (File_Name (Name));
480             else
481                Write_Str (Name);
482             end if;
483          end;
484
485          Write_Str (""" ");
486       end if;
487
488       Write_Str (Msg);
489       Write_Eol;
490    end Inform;
491
492    ----------------------------
493    -- Is_External_Assignment --
494    ----------------------------
495
496    function Is_External_Assignment
497      (Tree : Prj.Tree.Project_Node_Tree_Ref;
498       Argv : String) return Boolean
499    is
500       Start     : Positive := 3;
501       Finish    : Natural := Argv'Last;
502
503       pragma Assert (Argv'First = 1);
504       pragma Assert (Argv (1 .. 2) = "-X");
505
506    begin
507       if Argv'Last < 5 then
508          return False;
509
510       elsif Argv (3) = '"' then
511          if Argv (Argv'Last) /= '"' or else Argv'Last < 7 then
512             return False;
513          else
514             Start := 4;
515             Finish := Argv'Last - 1;
516          end if;
517       end if;
518
519       return Prj.Ext.Check
520         (Tree        => Tree,
521          Declaration => Argv (Start .. Finish));
522    end Is_External_Assignment;
523
524    ---------------
525    -- Is_Marked --
526    ---------------
527
528    function Is_Marked
529      (Source_File : File_Name_Type;
530       Index       : Int := 0) return Boolean
531    is
532    begin
533       return Marks.Get (K => (File => Source_File, Index => Index));
534    end Is_Marked;
535
536    -----------------------------
537    -- Linker_Options_Switches --
538    -----------------------------
539
540    function Linker_Options_Switches
541      (Project  : Project_Id;
542       In_Tree  : Project_Tree_Ref) return String_List
543    is
544       procedure Recursive_Add (Proj : Project_Id; Dummy : in out Boolean);
545       --  The recursive routine used to add linker options
546
547       -------------------
548       -- Recursive_Add --
549       -------------------
550
551       procedure Recursive_Add (Proj : Project_Id; Dummy : in out Boolean) is
552          pragma Unreferenced (Dummy);
553
554          Linker_Package : Package_Id;
555          Options        : Variable_Value;
556
557       begin
558          Linker_Package :=
559            Prj.Util.Value_Of
560              (Name        => Name_Linker,
561               In_Packages => Proj.Decl.Packages,
562               In_Tree     => In_Tree);
563
564          Options :=
565            Prj.Util.Value_Of
566              (Name                    => Name_Ada,
567               Index                   => 0,
568               Attribute_Or_Array_Name => Name_Linker_Options,
569               In_Package              => Linker_Package,
570               In_Tree                 => In_Tree);
571
572          --  If attribute is present, add the project with
573          --  the attribute to table Linker_Opts.
574
575          if Options /= Nil_Variable_Value then
576             Linker_Opts.Increment_Last;
577             Linker_Opts.Table (Linker_Opts.Last) :=
578               (Project => Proj, Options => Options.Values);
579          end if;
580       end Recursive_Add;
581
582       procedure For_All_Projects is
583         new For_Every_Project_Imported (Boolean, Recursive_Add);
584
585       Dummy : Boolean := False;
586
587    --  Start of processing for Linker_Options_Switches
588
589    begin
590       Linker_Opts.Init;
591
592       For_All_Projects (Project, Dummy, Imported_First => True);
593
594       Last_Linker_Option := 0;
595
596       for Index in reverse 1 .. Linker_Opts.Last loop
597          declare
598             Options : String_List_Id;
599             Proj    : constant Project_Id :=
600                         Linker_Opts.Table (Index).Project;
601             Option  : Name_Id;
602             Dir_Path : constant String :=
603                          Get_Name_String (Proj.Directory.Name);
604
605          begin
606             Options := Linker_Opts.Table (Index).Options;
607             while Options /= Nil_String loop
608                Option := In_Tree.String_Elements.Table (Options).Value;
609                Get_Name_String (Option);
610
611                --  Do not consider empty linker options
612
613                if Name_Len /= 0 then
614                   Add_Linker_Option (Name_Buffer (1 .. Name_Len));
615
616                   --  Object files and -L switches specified with relative
617                   --  paths must be converted to absolute paths.
618
619                   Test_If_Relative_Path
620                     (Switch => Linker_Options_Buffer (Last_Linker_Option),
621                      Parent => Dir_Path,
622                      Including_L_Switch => True);
623                end if;
624
625                Options := In_Tree.String_Elements.Table (Options).Next;
626             end loop;
627          end;
628       end loop;
629
630       return Linker_Options_Buffer (1 .. Last_Linker_Option);
631    end Linker_Options_Switches;
632
633    -----------
634    -- Mains --
635    -----------
636
637    package body Mains is
638
639       type File_And_Loc is record
640          File_Name : File_Name_Type;
641          Index     : Int := 0;
642          Location  : Source_Ptr := No_Location;
643       end record;
644
645       package Names is new Table.Table
646         (Table_Component_Type => File_And_Loc,
647          Table_Index_Type     => Integer,
648          Table_Low_Bound      => 1,
649          Table_Initial        => 10,
650          Table_Increment      => 100,
651          Table_Name           => "Makeutl.Mains.Names");
652       --  The table that stores the mains
653
654       Current : Natural := 0;
655       --  The index of the last main retrieved from the table
656
657       --------------
658       -- Add_Main --
659       --------------
660
661       procedure Add_Main (Name : String) is
662       begin
663          Name_Len := 0;
664          Add_Str_To_Name_Buffer (Name);
665          Names.Increment_Last;
666          Names.Table (Names.Last) := (Name_Find, 0, No_Location);
667       end Add_Main;
668
669       ------------
670       -- Delete --
671       ------------
672
673       procedure Delete is
674       begin
675          Names.Set_Last (0);
676          Mains.Reset;
677       end Delete;
678
679       ---------------
680       -- Get_Index --
681       ---------------
682
683       function Get_Index return Int is
684       begin
685          if Current in Names.First .. Names.Last then
686             return Names.Table (Current).Index;
687          else
688             return 0;
689          end if;
690       end Get_Index;
691
692       ------------------
693       -- Get_Location --
694       ------------------
695
696       function Get_Location return Source_Ptr is
697       begin
698          if Current in Names.First .. Names.Last then
699             return Names.Table (Current).Location;
700          else
701             return No_Location;
702          end if;
703       end Get_Location;
704
705       ---------------
706       -- Next_Main --
707       ---------------
708
709       function Next_Main return String is
710       begin
711          if Current >= Names.Last then
712             return "";
713          else
714             Current := Current + 1;
715             return Get_Name_String (Names.Table (Current).File_Name);
716          end if;
717       end Next_Main;
718
719       ---------------------
720       -- Number_Of_Mains --
721       ---------------------
722
723       function Number_Of_Mains return Natural is
724       begin
725          return Names.Last;
726       end Number_Of_Mains;
727
728       -----------
729       -- Reset --
730       -----------
731
732       procedure Reset is
733       begin
734          Current := 0;
735       end Reset;
736
737       ---------------
738       -- Set_Index --
739       ---------------
740
741       procedure Set_Index (Index : Int) is
742       begin
743          if Names.Last > 0 then
744             Names.Table (Names.Last).Index := Index;
745          end if;
746       end Set_Index;
747
748       ------------------
749       -- Set_Location --
750       ------------------
751
752       procedure Set_Location (Location : Source_Ptr) is
753       begin
754          if Names.Last > 0 then
755             Names.Table (Names.Last).Location := Location;
756          end if;
757       end Set_Location;
758
759       -----------------
760       -- Update_Main --
761       -----------------
762
763       procedure Update_Main (Name : String) is
764       begin
765          if Current in Names.First .. Names.Last then
766             Name_Len := 0;
767             Add_Str_To_Name_Buffer (Name);
768             Names.Table (Current).File_Name := Name_Find;
769          end if;
770       end Update_Main;
771    end Mains;
772
773    ----------
774    -- Mark --
775    ----------
776
777    procedure Mark (Source_File : File_Name_Type; Index : Int := 0) is
778    begin
779       Marks.Set (K => (File => Source_File, Index => Index), E => True);
780    end Mark;
781
782    -----------------------
783    -- Path_Or_File_Name --
784    -----------------------
785
786    function Path_Or_File_Name (Path : Path_Name_Type) return String is
787       Path_Name : constant String := Get_Name_String (Path);
788    begin
789       if Debug.Debug_Flag_F then
790          return File_Name (Path_Name);
791       else
792          return Path_Name;
793       end if;
794    end Path_Or_File_Name;
795
796    ---------------------------
797    -- Test_If_Relative_Path --
798    ---------------------------
799
800    procedure Test_If_Relative_Path
801      (Switch               : in out String_Access;
802       Parent               : String;
803       Including_L_Switch   : Boolean := True;
804       Including_Non_Switch : Boolean := True;
805       Including_RTS        : Boolean := False)
806    is
807    begin
808       if Switch /= null then
809          declare
810             Sw    : String (1 .. Switch'Length);
811             Start : Positive;
812
813          begin
814             Sw := Switch.all;
815
816             if Sw (1) = '-' then
817                if Sw'Length >= 3
818                  and then (Sw (2) = 'A'
819                             or else Sw (2) = 'I'
820                             or else (Including_L_Switch and then Sw (2) = 'L'))
821                then
822                   Start := 3;
823
824                   if Sw = "-I-" then
825                      return;
826                   end if;
827
828                elsif Sw'Length >= 4
829                  and then (Sw (2 .. 3) = "aL"
830                             or else Sw (2 .. 3) = "aO"
831                             or else Sw (2 .. 3) = "aI")
832                then
833                   Start := 4;
834
835                elsif Including_RTS
836                  and then Sw'Length >= 7
837                  and then Sw (2 .. 6) = "-RTS="
838                then
839                   Start := 7;
840
841                else
842                   return;
843                end if;
844
845                --  Because relative path arguments to --RTS= may be relative
846                --  to the search directory prefix, those relative path
847                --  arguments are converted only when they include directory
848                --  information.
849
850                if not Is_Absolute_Path (Sw (Start .. Sw'Last)) then
851                   if Parent'Length = 0 then
852                      Do_Fail
853                        ("relative search path switches ("""
854                         & Sw
855                         & """) are not allowed");
856
857                   elsif Including_RTS then
858                      for J in Start .. Sw'Last loop
859                         if Sw (J) = Directory_Separator then
860                            Switch :=
861                              new String'
862                                (Sw (1 .. Start - 1) &
863                                 Parent &
864                                 Directory_Separator &
865                                 Sw (Start .. Sw'Last));
866                            return;
867                         end if;
868                      end loop;
869
870                   else
871                      Switch :=
872                        new String'
873                          (Sw (1 .. Start - 1) &
874                           Parent &
875                           Directory_Separator &
876                           Sw (Start .. Sw'Last));
877                   end if;
878                end if;
879
880             elsif Including_Non_Switch then
881                if not Is_Absolute_Path (Sw) then
882                   if Parent'Length = 0 then
883                      Do_Fail
884                        ("relative paths (""" & Sw & """) are not allowed");
885                   else
886                      Switch := new String'(Parent & Directory_Separator & Sw);
887                   end if;
888                end if;
889             end if;
890          end;
891       end if;
892    end Test_If_Relative_Path;
893
894    -------------------
895    -- Unit_Index_Of --
896    -------------------
897
898    function Unit_Index_Of (ALI_File : File_Name_Type) return Int is
899       Start  : Natural;
900       Finish : Natural;
901       Result : Int := 0;
902
903    begin
904       Get_Name_String (ALI_File);
905
906       --  First, find the last dot
907
908       Finish := Name_Len;
909
910       while Finish >= 1 and then Name_Buffer (Finish) /= '.' loop
911          Finish := Finish - 1;
912       end loop;
913
914       if Finish = 1 then
915          return 0;
916       end if;
917
918       --  Now check that the dot is preceded by digits
919
920       Start := Finish;
921       Finish := Finish - 1;
922
923       while Start >= 1 and then Name_Buffer (Start - 1) in '0' .. '9' loop
924          Start := Start - 1;
925       end loop;
926
927       --  If there are no digits, or if the digits are not preceded by the
928       --  character that precedes a unit index, this is not the ALI file of
929       --  a unit in a multi-unit source.
930
931       if Start > Finish
932         or else Start = 1
933         or else Name_Buffer (Start - 1) /= Multi_Unit_Index_Character
934       then
935          return 0;
936       end if;
937
938       --  Build the index from the digit(s)
939
940       while Start <= Finish loop
941          Result := Result * 10 +
942                      Character'Pos (Name_Buffer (Start)) - Character'Pos ('0');
943          Start := Start + 1;
944       end loop;
945
946       return Result;
947    end Unit_Index_Of;
948
949    -----------------
950    -- Verbose_Msg --
951    -----------------
952
953    procedure Verbose_Msg
954      (N1                : Name_Id;
955       S1                : String;
956       N2                : Name_Id := No_Name;
957       S2                : String  := "";
958       Prefix            : String := "  -> ";
959       Minimum_Verbosity : Opt.Verbosity_Level_Type := Opt.Low)
960    is
961    begin
962       if not Opt.Verbose_Mode
963         or else Minimum_Verbosity > Opt.Verbosity_Level
964       then
965          return;
966       end if;
967
968       Write_Str (Prefix);
969       Write_Str ("""");
970       Write_Name (N1);
971       Write_Str (""" ");
972       Write_Str (S1);
973
974       if N2 /= No_Name then
975          Write_Str (" """);
976          Write_Name (N2);
977          Write_Str (""" ");
978       end if;
979
980       Write_Str (S2);
981       Write_Eol;
982    end Verbose_Msg;
983
984    procedure Verbose_Msg
985      (N1                : File_Name_Type;
986       S1                : String;
987       N2                : File_Name_Type := No_File;
988       S2                : String  := "";
989       Prefix            : String := "  -> ";
990       Minimum_Verbosity : Opt.Verbosity_Level_Type := Opt.Low)
991    is
992    begin
993       Verbose_Msg
994         (Name_Id (N1), S1, Name_Id (N2), S2, Prefix, Minimum_Verbosity);
995    end Verbose_Msg;
996
997 end Makeutl;