1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
27 ------------------------------------------------------------------------------
29 with Ada.Exceptions; use Ada.Exceptions;
30 with Ada.Command_Line; use Ada.Command_Line;
32 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
33 with GNAT.OS_Lib; use GNAT.OS_Lib;
36 with ALI.Util; use ALI.Util;
39 with Fname; use Fname;
40 with Fname.SF; use Fname.SF;
41 with Fname.UF; use Fname.UF;
42 with Gnatvsn; use Gnatvsn;
43 with Hostparm; use Hostparm;
48 with Namet; use Namet;
50 with Osint; use Osint;
52 with Output; use Output;
61 with Snames; use Snames;
62 with Stringt; use Stringt;
64 with Types; use Types;
65 with Switch; use Switch;
67 with System.WCh_Con; use System.WCh_Con;
72 -- Make control characters visible
74 Standard_Library_Package_Body_Name : constant String := "s-stalib.adb";
75 -- Every program depends on this package, that must then be checked,
76 -- especially when -f and -a are used.
78 -------------------------
79 -- Note on terminology --
80 -------------------------
82 -- In this program, we use the phrase "termination" of a file name to
83 -- refer to the suffix that appears after the unit name portion. Very
84 -- often this is simply the extension, but in some cases, the sequence
85 -- may be more complex, for example in main.1.ada, the termination in
86 -- this name is ".1.ada" and in main_.ada the termination is "_.ada".
88 -------------------------------------
89 -- Queue (Q) Manipulation Routines --
90 -------------------------------------
92 -- The Q is used in Compile_Sources below. Its implementation uses the
93 -- GNAT generic package Table (basically an extensible array). Q_Front
94 -- points to the first valid element in the Q, whereas Q.First is the first
95 -- element ever enqueued, while Q.Last - 1 is the last element in the Q.
97 -- +---+--------------+---+---+---+-----------+---+--------
98 -- Q | | ........ | | | | ....... | |
99 -- +---+--------------+---+---+---+-----------+---+--------
101 -- Q.First Q_Front Q.Last - 1
103 -- The elements comprised between Q.First and Q_Front - 1 are the
104 -- elements that have been enqueued and then dequeued, while the
105 -- elements between Q_Front and Q.Last - 1 are the elements currently
106 -- in the Q. When the Q is initialized Q_Front = Q.First = Q.Last.
107 -- After Compile_Sources has terminated its execution, Q_Front = Q.Last
108 -- and the elements contained between Q.Front and Q.Last-1 are those that
109 -- were explored and thus marked by Compile_Sources. Whenever the Q is
110 -- reinitialized, the elements between Q.First and Q.Last - 1 are unmarked.
113 -- Must be called to (re)initialize the Q.
116 (Source_File : File_Name_Type;
117 Source_Unit : Unit_Name_Type := No_Name);
118 -- Inserts Source_File at the end of Q. Provide Source_Unit when
119 -- possible for external use (gnatdist).
121 function Empty_Q return Boolean;
122 -- Returns True if Q is empty.
124 procedure Extract_From_Q
125 (Source_File : out File_Name_Type;
126 Source_Unit : out Unit_Name_Type);
127 -- Extracts the first element from the Q.
129 procedure Insert_Project_Sources
130 (The_Project : Project_Id;
132 -- If Into_Q is True, insert all sources of the project file that are not
133 -- already marked into the Q. If Into_Q is False, call Osint.Add_File for
134 -- all sources of the project file.
136 First_Q_Initialization : Boolean := True;
137 -- Will be set to false after Init_Q has been called once.
140 -- Points to the first valid element in the Q.
142 Unique_Compile : Boolean := False;
144 type Q_Record is record
145 File : File_Name_Type;
146 Unit : Unit_Name_Type;
148 -- File is the name of the file to compile. Unit is for gnatdist
149 -- use in order to easily get the unit name of a file to compile
150 -- when its name is krunched or declared in gnat.adc.
152 package Q is new Table.Table (
153 Table_Component_Type => Q_Record,
154 Table_Index_Type => Natural,
155 Table_Low_Bound => 0,
156 Table_Initial => 4000,
157 Table_Increment => 100,
158 Table_Name => "Make.Q");
159 -- This is the actual Q.
161 -- The following instantiations and variables are necessary to save what
162 -- is found on the command line, in case there is a project file specified.
164 package Saved_Gcc_Switches is new Table.Table (
165 Table_Component_Type => String_Access,
166 Table_Index_Type => Integer,
167 Table_Low_Bound => 1,
169 Table_Increment => 100,
170 Table_Name => "Make.Saved_Gcc_Switches");
172 package Saved_Binder_Switches is new Table.Table (
173 Table_Component_Type => String_Access,
174 Table_Index_Type => Integer,
175 Table_Low_Bound => 1,
177 Table_Increment => 100,
178 Table_Name => "Make.Saved_Binder_Switches");
180 package Saved_Linker_Switches is new Table.Table
181 (Table_Component_Type => String_Access,
182 Table_Index_Type => Integer,
183 Table_Low_Bound => 1,
185 Table_Increment => 100,
186 Table_Name => "Make.Saved_Linker_Switches");
188 package Saved_Make_Switches is new Table.Table
189 (Table_Component_Type => String_Access,
190 Table_Index_Type => Integer,
191 Table_Low_Bound => 1,
193 Table_Increment => 100,
194 Table_Name => "Make.Saved_Make_Switches");
196 Saved_Maximum_Processes : Natural := 0;
197 Saved_WC_Encoding_Method : WC_Encoding_Method := WC_Encoding_Method'First;
198 Saved_WC_Encoding_Method_Set : Boolean := False;
200 type Arg_List_Ref is access Argument_List;
201 The_Saved_Gcc_Switches : Arg_List_Ref;
203 Project_File_Name : String_Access := null;
204 Current_Verbosity : Prj.Verbosity := Prj.Default;
205 Main_Project : Prj.Project_Id := No_Project;
207 procedure Add_Source_Dir (N : String);
208 -- Call Add_Src_Search_Dir.
209 -- Output one line when in verbose mode.
211 procedure Add_Source_Directories is
212 new Prj.Env.For_All_Source_Dirs (Action => Add_Source_Dir);
214 procedure Add_Object_Dir (N : String);
215 -- Call Add_Lib_Search_Dir.
216 -- Output one line when in verbose mode.
218 procedure Add_Object_Directories is
219 new Prj.Env.For_All_Object_Dirs (Action => Add_Object_Dir);
221 type Bad_Compilation_Info is record
222 File : File_Name_Type;
223 Unit : Unit_Name_Type;
226 -- File is the name of the file for which a compilation failed.
227 -- Unit is for gnatdist use in order to easily get the unit name
228 -- of a file when its name is krunched or declared in gnat.adc.
229 -- Found is False if the compilation failed because the file could
232 package Bad_Compilation is new Table.Table (
233 Table_Component_Type => Bad_Compilation_Info,
234 Table_Index_Type => Natural,
235 Table_Low_Bound => 1,
237 Table_Increment => 100,
238 Table_Name => "Make.Bad_Compilation");
239 -- Full name of all the source files for which compilation fails.
241 type Special_Argument is record
242 File : String_Access;
243 Args : Argument_List_Access;
245 -- File is the name of the file for which a special set of compilation
246 -- arguments (Args) is required.
248 package Special_Args is new Table.Table (
249 Table_Component_Type => Special_Argument,
250 Table_Index_Type => Natural,
251 Table_Low_Bound => 1,
253 Table_Increment => 100,
254 Table_Name => "Make.Special_Args");
255 -- Compilation arguments of all the source files for which an entry has
256 -- been found in the project file.
258 Original_Ada_Include_Path : constant String_Access :=
259 Getenv ("ADA_INCLUDE_PATH");
260 Original_Ada_Objects_Path : constant String_Access :=
261 Getenv ("ADA_OBJECTS_PATH");
262 Current_Ada_Include_Path : String_Access := null;
263 Current_Ada_Objects_Path : String_Access := null;
265 Max_Line_Length : constant := 127;
266 -- Maximum number of characters per line, when displaying a path
268 Do_Compile_Step : Boolean := True;
269 Do_Bind_Step : Boolean := True;
270 Do_Link_Step : Boolean := True;
271 -- Flags to indicate what step should be executed.
272 -- Can be set to False with the switches -c, -b and -l.
273 -- These flags are reset to True for each invokation of procedure Gnatmake.
275 ----------------------
276 -- Marking Routines --
277 ----------------------
279 procedure Mark (Source_File : File_Name_Type);
280 -- Mark Source_File. Marking is used to signal that Source_File has
281 -- already been inserted in the Q.
283 function Is_Marked (Source_File : File_Name_Type) return Boolean;
284 -- Returns True if Source_File was previously marked.
286 procedure Unmark (Source_File : File_Name_Type);
287 -- Unmarks Source_File.
293 procedure List_Depend;
294 -- Prints to standard output the list of object dependencies. This list
295 -- can be used directly in a Makefile. A call to Compile_Sources must
296 -- precede the call to List_Depend. Also because this routine uses the
297 -- ALI files that were originally loaded and scanned by Compile_Sources,
298 -- no additional ALI files should be scanned between the two calls (i.e.
299 -- between the call to Compile_Sources and List_Depend.)
301 procedure Inform (N : Name_Id := No_Name; Msg : String);
302 -- Prints out the program name followed by a colon, N and S.
304 procedure List_Bad_Compilations;
305 -- Prints out the list of all files for which the compilation failed.
307 procedure Verbose_Msg
310 N2 : Name_Id := No_Name;
312 Prefix : String := " -> ");
313 -- If the verbose flag (Verbose_Mode) is set then print Prefix to standard
314 -- output followed by N1 and S1. If N2 /= No_Name then N2 is then printed
315 -- after S1. S2 is printed last. Both N1 and N2 are printed in quotation
318 -----------------------
319 -- Gnatmake Routines --
320 -----------------------
322 subtype Lib_Mark_Type is Byte;
324 Ada_Lib_Dir : constant Lib_Mark_Type := 1;
325 GNAT_Lib_Dir : constant Lib_Mark_Type := 2;
327 -- Note that the notion of GNAT lib dir is no longer used. The code
328 -- related to it has not been removed to give an idea on how to use
329 -- the directory prefix marking mechanism.
331 -- An Ada library directory is a directory containing ali and object
332 -- files but no source files for the bodies (the specs can be in the
333 -- same or some other directory). These directories are specified
334 -- in the Gnatmake command line with the switch "-Adir" (to specify the
335 -- spec location -Idir cab be used). Gnatmake skips the missing sources
336 -- whose ali are in Ada library directories. For an explanation of why
337 -- Gnatmake behaves that way, see the spec of Make.Compile_Sources.
338 -- The directory lookup penalty is incurred every single time this
339 -- routine is called.
341 function Is_External_Assignment (Argv : String) return Boolean;
342 -- Verify that an external assignment switch is syntactically correct.
345 -- -X"name=other value"
346 -- Assumptions: 'First = 1, Argv (1 .. 2) = "-X"
347 -- When this function returns True, the external assignment has
348 -- been entered by a call to Prj.Ext.Add, so that in a project
349 -- file, External ("name") will return "value".
351 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean;
352 -- Get directory prefix of this file and get lib mark stored in name
353 -- table for this directory. Then check if an Ada lib mark has been set.
355 procedure Mark_Dir_Path
356 (Path : String_Access;
357 Mark : Lib_Mark_Type);
358 -- Invoke Mark_Directory on each directory of the path.
360 procedure Mark_Directory
362 Mark : Lib_Mark_Type);
363 -- Store Dir in name table and set lib mark as name info to identify
366 function Object_File_Name (Source : String) return String;
367 -- Returns the object file name suitable for switch -o.
369 procedure Set_Ada_Paths
370 (For_Project : Prj.Project_Id;
371 Including_Libraries : Boolean);
372 -- Set, if necessary, env. variables ADA_INCLUDE_PATH and
375 -- Note: this will modify these environment variables only
376 -- for the current gnatmake process and all of its children
377 -- (invocations of the compiler, the binder and the linker).
378 -- The caller process ADA_INCLUDE_PATH and ADA_OBJECTS_PATH are
382 (Source_File : Name_Id;
383 Source_File_Name : String;
384 Naming : Naming_Data;
385 In_Package : Package_Id;
387 return Variable_Value;
388 -- Return the switches for the source file in the specified package
389 -- of a project file. If the Source_File ends with a standard GNAT
390 -- extension (".ads" or ".adb"), try first the full name, then the
391 -- name without the extension. If there is no switches for either
392 -- names, try the default switches for Ada. If all failed, return
393 -- No_Variable_Value.
395 procedure Test_If_Relative_Path (Switch : String_Access);
396 -- Test if Switch is a relative search path switch.
397 -- Fail if it is. This subprogram is only called
398 -- when using project files.
400 procedure Set_Library_For
401 (Project : Project_Id;
402 There_Are_Libraries : in out Boolean);
403 -- If Project is a library project, add the correct
404 -- -L and -l switches to the linker invocation.
406 procedure Set_Libraries is
407 new For_Every_Project_Imported (Boolean, Set_Library_For);
408 -- Add the -L and -l switches to the linker for all
409 -- of the library projects.
411 ----------------------------------------------------
412 -- Compiler, Binder & Linker Data and Subprograms --
413 ----------------------------------------------------
415 Gcc : String_Access := Program_Name ("gcc");
416 Gnatbind : String_Access := Program_Name ("gnatbind");
417 Gnatlink : String_Access := Program_Name ("gnatlink");
418 -- Default compiler, binder, linker programs
420 Saved_Gcc : String_Access := null;
421 Saved_Gnatbind : String_Access := null;
422 Saved_Gnatlink : String_Access := null;
423 -- Given by the command line. Will be used, if non null.
425 Gcc_Path : String_Access :=
426 GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
427 Gnatbind_Path : String_Access :=
428 GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
429 Gnatlink_Path : String_Access :=
430 GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
431 -- Path for compiler, binder, linker programs, defaulted now for gnatdist.
432 -- Changed later if overridden on command line.
434 Comp_Flag : constant String_Access := new String'("-c");
435 Output_Flag : constant String_Access := new String'("-o");
436 Ada_Flag_1 : constant String_Access := new String'("-x");
437 Ada_Flag_2 : constant String_Access := new String'("ada");
438 No_gnat_adc : constant String_Access := new String'("-gnatA");
439 GNAT_Flag : constant String_Access := new String'("-gnatpg");
440 Do_Not_Check_Flag : constant String_Access := new String'("-x");
442 Object_Suffix : constant String := Get_Object_Suffix.all;
443 Executable_Suffix : constant String := Get_Executable_Suffix.all;
445 Display_Executed_Programs : Boolean := True;
446 -- Set to True if name of commands should be output on stderr.
448 Output_File_Name_Seen : Boolean := False;
449 -- Set to True after having scanned the file_name for
450 -- switch "-o file_name"
452 File_Name_Seen : Boolean := False;
453 -- Set to true after having seen at least one file name.
454 -- Used in Scan_Make_Arg only, but must be a global variable.
456 type Make_Program_Type is (None, Compiler, Binder, Linker);
458 Program_Args : Make_Program_Type := None;
459 -- Used to indicate if we are scanning gcc, gnatbind, or gnatbl
460 -- options within the gnatmake command line.
461 -- Used in Scan_Make_Arg only, but must be a global variable.
463 procedure Add_Switches
464 (The_Package : Package_Id;
466 Program : Make_Program_Type);
469 Program : Make_Program_Type;
470 Append_Switch : Boolean := True;
471 And_Save : Boolean := True);
474 Program : Make_Program_Type;
475 Append_Switch : Boolean := True;
476 And_Save : Boolean := True);
477 -- Make invokes one of three programs (the compiler, the binder or the
478 -- linker). For the sake of convenience, some program specific switches
479 -- can be passed directly on the gnatmake commande line. This procedure
480 -- records these switches so that gnamake can pass them to the right
481 -- program. S is the switch to be added at the end of the command line
482 -- for Program if Append_Switch is True. If Append_Switch is False S is
483 -- added at the beginning of the command line.
486 (Lib_File : File_Name_Type;
488 O_File : out File_Name_Type;
489 O_Stamp : out Time_Stamp_Type);
490 -- Determines whether the library file Lib_File is up-to-date or not. The
491 -- full name (with path information) of the object file corresponding to
492 -- Lib_File is returned in O_File. Its time stamp is saved in O_Stamp.
493 -- ALI is the ALI_Id corresponding to Lib_File. If Lib_File in not
494 -- up-to-date, then the corresponding source file needs to be recompiled.
495 -- In this case ALI = No_ALI_Id.
497 procedure Check_Linker_Options
498 (E_Stamp : Time_Stamp_Type;
499 O_File : out File_Name_Type;
500 O_Stamp : out Time_Stamp_Type);
501 -- Checks all linker options for linker files that are newer
502 -- than E_Stamp. If such objects are found, the youngest object
503 -- is returned in O_File and its stamp in O_Stamp.
505 -- If no obsolete linker files were found, the first missing
506 -- linker file is returned in O_File and O_Stamp is empty.
507 -- Otherwise O_File is No_File.
509 procedure Display (Program : String; Args : Argument_List);
510 -- Displays Program followed by the arguments in Args if variable
511 -- Display_Executed_Programs is set. The lower bound of Args must be 1.
517 procedure Add_Object_Dir (N : String) is
519 Add_Lib_Search_Dir (N);
521 if Opt.Verbose_Mode then
522 Write_Str ("Adding object directory """);
533 procedure Add_Source_Dir (N : String) is
535 Add_Src_Search_Dir (N);
537 if Opt.Verbose_Mode then
538 Write_Str ("Adding source directory """);
551 Program : Make_Program_Type;
552 Append_Switch : Boolean := True;
553 And_Save : Boolean := True)
556 with package T is new Table.Table (<>);
557 function Generic_Position return Integer;
558 -- Generic procedure that adds S at the end or beginning of T depending
559 -- of the value of the boolean Append_Switch.
561 ----------------------
562 -- Generic_Position --
563 ----------------------
565 function Generic_Position return Integer is
569 if Append_Switch then
570 return Integer (T.Last);
572 for J in reverse T.Table_Index_Type'Succ (T.First) .. T.Last loop
573 T.Table (J) := T.Table (T.Table_Index_Type'Pred (J));
576 return Integer (T.First);
578 end Generic_Position;
580 function Gcc_Switches_Pos is new Generic_Position (Gcc_Switches);
581 function Binder_Switches_Pos is new Generic_Position (Binder_Switches);
582 function Linker_Switches_Pos is new Generic_Position (Linker_Switches);
584 function Saved_Gcc_Switches_Pos is new
585 Generic_Position (Saved_Gcc_Switches);
587 function Saved_Binder_Switches_Pos is new
588 Generic_Position (Saved_Binder_Switches);
590 function Saved_Linker_Switches_Pos is new
591 Generic_Position (Saved_Linker_Switches);
593 -- Start of processing for Add_Switch
599 Saved_Gcc_Switches.Table (Saved_Gcc_Switches_Pos) := S;
602 Saved_Binder_Switches.Table (Saved_Binder_Switches_Pos) := S;
605 Saved_Linker_Switches.Table (Saved_Linker_Switches_Pos) := S;
614 Gcc_Switches.Table (Gcc_Switches_Pos) := S;
617 Binder_Switches.Table (Binder_Switches_Pos) := S;
620 Linker_Switches.Table (Linker_Switches_Pos) := S;
630 Program : Make_Program_Type;
631 Append_Switch : Boolean := True;
632 And_Save : Boolean := True)
635 Add_Switch (S => new String'(S),
637 Append_Switch => Append_Switch,
638 And_Save => And_Save);
645 procedure Add_Switches
646 (The_Package : Package_Id;
648 Program : Make_Program_Type)
650 Switches : Variable_Value;
651 Switch_List : String_List_Id;
652 Element : String_Element;
655 if File_Name'Length > 0 then
656 Name_Len := File_Name'Length;
657 Name_Buffer (1 .. Name_Len) := File_Name;
660 (Source_File => Name_Find,
661 Source_File_Name => File_Name,
662 Naming => Projects.Table (Main_Project).Naming,
663 In_Package => The_Package,
665 Program = Binder or else Program = Linker);
667 case Switches.Kind is
672 Program_Args := Program;
674 Switch_List := Switches.Values;
676 while Switch_List /= Nil_String loop
677 Element := String_Elements.Table (Switch_List);
678 String_To_Name_Buffer (Element.Value);
681 if Opt.Verbose_Mode then
682 Write_Str (" Adding ");
683 Write_Line (Name_Buffer (1 .. Name_Len));
687 (Name_Buffer (1 .. Name_Len),
691 Switch_List := Element.Next;
695 Program_Args := Program;
696 String_To_Name_Buffer (Switches.Value);
699 if Opt.Verbose_Mode then
700 Write_Str (" Adding ");
701 Write_Line (Name_Buffer (1 .. Name_Len));
705 (Name_Buffer (1 .. Name_Len), And_Save => False);
715 procedure Bind (ALI_File : File_Name_Type; Args : Argument_List) is
716 Bind_Args : Argument_List (1 .. Args'Last + 2);
721 pragma Assert (Args'First = 1);
723 -- Optimize the simple case where the gnatbind command line looks like
724 -- gnatbind -aO. -I- file.ali --into-> gnatbind file.adb
727 and then Args (Args'First).all = "-aO" & Normalized_CWD
728 and then Args (Args'Last).all = "-I-"
729 and then ALI_File = Strip_Directory (ALI_File)
731 Bind_Last := Args'First - 1;
734 Bind_Last := Args'Last;
735 Bind_Args (Args'Range) := Args;
738 -- It is completely pointless to re-check source file time stamps.
739 -- This has been done already by gnatmake
741 Bind_Last := Bind_Last + 1;
742 Bind_Args (Bind_Last) := Do_Not_Check_Flag;
744 Get_Name_String (ALI_File);
746 Bind_Last := Bind_Last + 1;
747 Bind_Args (Bind_Last) := new String'(Name_Buffer (1 .. Name_Len));
749 Display (Gnatbind.all, Bind_Args (Args'First .. Bind_Last));
751 if Gnatbind_Path = null then
752 Osint.Fail ("error, unable to locate " & Gnatbind.all);
756 (Gnatbind_Path.all, Bind_Args (Args'First .. Bind_Last), Success);
768 (Lib_File : File_Name_Type;
770 O_File : out File_Name_Type;
771 O_Stamp : out Time_Stamp_Type)
773 function First_New_Spec (A : ALI_Id) return File_Name_Type;
774 -- Looks in the with table entries of A and returns the spec file name
775 -- of the first withed unit (subprogram) for which no spec existed when
776 -- A was generated but for which there exists one now, implying that A
777 -- is now obsolete. If no such unit is found No_File is returned.
778 -- Otherwise the spec file name of the unit is returned.
780 -- **WARNING** in the event of Uname format modifications, one *MUST*
781 -- make sure this function is also updated.
783 -- Note: This function should really be in ali.adb and use Uname
784 -- services, but this causes the whole compiler to be dragged along
785 -- for gnatbind and gnatmake.
791 function First_New_Spec (A : ALI_Id) return File_Name_Type is
792 Spec_File_Name : File_Name_Type := No_File;
794 function New_Spec (Uname : Unit_Name_Type) return Boolean;
795 -- Uname is the name of the spec or body of some ada unit.
796 -- This function returns True if the Uname is the name of a body
797 -- which has a spec not mentioned inali file A. If True is returned
798 -- Spec_File_Name above is set to the name of this spec file.
804 function New_Spec (Uname : Unit_Name_Type) return Boolean is
805 Spec_Name : Unit_Name_Type;
806 File_Name : File_Name_Type;
809 -- Test whether Uname is the name of a body unit (ie ends with %b)
811 Get_Name_String (Uname);
813 Assert (Name_Len > 2 and then Name_Buffer (Name_Len - 1) = '%');
815 if Name_Buffer (Name_Len) /= 'b' then
819 -- Convert unit name into spec name
821 -- ??? this code seems dubious in presence of pragma
822 -- Source_File_Name since there is no more direct relationship
823 -- between unit name and file name.
825 -- ??? Further, what about alternative subunit naming
827 Name_Buffer (Name_Len) := 's';
828 Spec_Name := Name_Find;
829 File_Name := Get_File_Name (Spec_Name, Subunit => False);
831 -- Look if File_Name is mentioned in A's sdep list.
832 -- If not look if the file exists. If it does return True.
835 ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep
837 if Sdep.Table (D).Sfile = File_Name then
842 if Full_Source_Name (File_Name) /= No_File then
843 Spec_File_Name := File_Name;
850 -- Start of processing for First_New_Spec
854 ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit
856 exit U_Chk when Units.Table (U).Utype = Is_Body_Only
857 and then New_Spec (Units.Table (U).Uname);
859 for W in Units.Table (U).First_With
861 Units.Table (U).Last_With
864 Withs.Table (W).Afile /= No_File
865 and then New_Spec (Withs.Table (W).Uname);
869 return Spec_File_Name;
872 ---------------------------------
873 -- Data declarations for Check --
874 ---------------------------------
876 Full_Lib_File : File_Name_Type;
877 -- Full name of current library file
879 Full_Obj_File : File_Name_Type;
880 -- Full name of the object file corresponding to Lib_File.
882 Lib_Stamp : Time_Stamp_Type;
883 -- Time stamp of the current ada library file.
885 Obj_Stamp : Time_Stamp_Type;
886 -- Time stamp of the current object file.
888 Modified_Source : File_Name_Type;
889 -- The first source in Lib_File whose current time stamp differs
890 -- from that stored in Lib_File.
892 New_Spec : File_Name_Type;
893 -- If Lib_File contains in its W (with) section a body (for a
894 -- subprogram) for which there exists a spec and the spec did not
895 -- appear in the Sdep section of Lib_File, New_Spec contains the file
896 -- name of this new spec.
898 Source_Name : Name_Id;
899 Text : Text_Buffer_Ptr;
901 Prev_Switch : Character;
902 -- First character of previous switch processed
904 Arg : Arg_Id := Arg_Id'First;
905 -- Current index in Args.Table for a given unit (init to stop warning)
907 Switch_Found : Boolean;
908 -- True if a given switch has been found
911 -- Number of compiler arguments processed
913 Special_Arg : Argument_List_Access;
914 -- Special arguments if any of a given compilation file
916 -- Start of processing for Check
919 pragma Assert (Lib_File /= No_File);
921 Text := Read_Library_Info (Lib_File);
922 Full_Lib_File := Full_Library_Info_Name;
923 Full_Obj_File := Full_Object_File_Name;
924 Lib_Stamp := Current_Library_File_Stamp;
925 Obj_Stamp := Current_Object_File_Stamp;
927 if Full_Lib_File = No_File then
928 Verbose_Msg (Lib_File, "being checked ...", Prefix => " ");
930 Verbose_Msg (Full_Lib_File, "being checked ...", Prefix => " ");
934 O_File := Full_Obj_File;
935 O_Stamp := Obj_Stamp;
938 if Full_Lib_File = No_File then
939 Verbose_Msg (Lib_File, "missing.");
941 elsif Obj_Stamp (Obj_Stamp'First) = ' ' then
942 Verbose_Msg (Full_Obj_File, "missing.");
946 (Full_Lib_File, "(" & String (Lib_Stamp) & ") newer than",
947 Full_Obj_File, "(" & String (Obj_Stamp) & ")");
951 ALI := Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
954 if ALI = No_ALI_Id then
955 Verbose_Msg (Full_Lib_File, "incorrectly formatted ALI file");
958 elsif ALIs.Table (ALI).Ver (1 .. ALIs.Table (ALI).Ver_Len) /=
961 Verbose_Msg (Full_Lib_File, "compiled with old GNAT version");
966 -- Don't take Ali file into account if it was generated without
969 if Opt.Operating_Mode /= Opt.Check_Semantics
970 and then ALIs.Table (ALI).No_Object
972 Verbose_Msg (Full_Lib_File, "has no corresponding object");
977 -- Check for matching compiler switches if needed
979 if Opt.Check_Switches then
980 Prev_Switch := ASCII.Nul;
983 Get_Name_String (ALIs.Table (ALI).Sfile);
985 for J in 1 .. Special_Args.Last loop
986 if Special_Args.Table (J).File.all =
987 Name_Buffer (1 .. Name_Len)
989 Special_Arg := Special_Args.Table (J).Args;
994 if Main_Project /= No_Project then
998 if Special_Arg = null then
999 for J in Gcc_Switches.First .. Gcc_Switches.Last loop
1001 -- Skip non switches, -I and -o switches
1003 if (Gcc_Switches.Table (J) (1) = '-'
1005 Gcc_Switches.Table (J) (1) = Switch_Character)
1006 and then Gcc_Switches.Table (J) (2) /= 'o'
1007 and then Gcc_Switches.Table (J) (2) /= 'I'
1009 Num_Args := Num_Args + 1;
1011 -- Comparing switches is delicate because gcc reorders
1012 -- a number of switches, according to lang-specs.h, but
1013 -- gnatmake doesn't have the sufficient knowledge to
1014 -- perform the same reordering. Instead, we ignore orders
1015 -- between different "first letter" switches, but keep
1016 -- orders between same switches, e.g -O -O2 is different
1017 -- than -O2 -O, but -g -O is equivalent to -O -g.
1019 if Gcc_Switches.Table (J) (2) /= Prev_Switch then
1020 Prev_Switch := Gcc_Switches.Table (J) (2);
1022 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg;
1025 Switch_Found := False;
1028 Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1030 if Gcc_Switches.Table (J).all = Args.Table (K).all then
1032 Switch_Found := True;
1037 if not Switch_Found then
1038 if Opt.Verbose_Mode then
1039 Verbose_Msg (ALIs.Table (ALI).Sfile,
1049 -- Special_Arg is non-null
1052 for J in Special_Arg'Range loop
1054 -- Skip non switches, -I and -o switches
1056 if (Special_Arg (J) (1) = '-'
1057 or else Special_Arg (J) (1) = Switch_Character)
1058 and then Special_Arg (J) (2) /= 'o'
1059 and then Special_Arg (J) (2) /= 'I'
1061 Num_Args := Num_Args + 1;
1063 if Special_Arg (J) (2) /= Prev_Switch then
1064 Prev_Switch := Special_Arg (J) (2);
1066 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg;
1069 Switch_Found := False;
1072 Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1074 if Special_Arg (J).all = Args.Table (K).all then
1076 Switch_Found := True;
1081 if not Switch_Found then
1082 if Opt.Verbose_Mode then
1083 Verbose_Msg (ALIs.Table (ALI).Sfile,
1095 Integer (Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg -
1096 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg + 1)
1098 if Opt.Verbose_Mode then
1099 Verbose_Msg (ALIs.Table (ALI).Sfile,
1100 "different number of switches");
1108 -- Get the source files and their time stamps. Note that some
1109 -- sources may be missing if ALI is out-of-date.
1111 Set_Source_Table (ALI);
1113 Modified_Source := Time_Stamp_Mismatch (ALI);
1115 if Modified_Source /= No_File then
1118 if Opt.Verbose_Mode then
1119 Source_Name := Full_Source_Name (Modified_Source);
1121 if Source_Name /= No_File then
1122 Verbose_Msg (Source_Name, "time stamp mismatch");
1124 Verbose_Msg (Modified_Source, "missing");
1129 New_Spec := First_New_Spec (ALI);
1131 if New_Spec /= No_File then
1134 if Opt.Verbose_Mode then
1135 Source_Name := Full_Source_Name (New_Spec);
1137 if Source_Name /= No_File then
1138 Verbose_Msg (Source_Name, "new spec");
1140 Verbose_Msg (New_Spec, "old spec missing");
1148 --------------------------
1149 -- Check_Linker_Options --
1150 --------------------------
1152 procedure Check_Linker_Options
1153 (E_Stamp : Time_Stamp_Type;
1154 O_File : out File_Name_Type;
1155 O_Stamp : out Time_Stamp_Type)
1157 procedure Check_File (File : File_Name_Type);
1158 -- Update O_File and O_Stamp if the given file is younger than E_Stamp
1159 -- and O_Stamp, or if O_File is No_File and File does not exist.
1161 function Get_Library_File (Name : String) return File_Name_Type;
1162 -- Return the full file name including path of a library based
1163 -- on the name specified with the -l linker option, using the
1164 -- Ada object path. Return No_File if no such file can be found.
1166 type Char_Array is array (Natural) of Character;
1167 type Char_Array_Access is access constant Char_Array;
1169 Template : Char_Array_Access;
1170 pragma Import (C, Template, "__gnat_library_template");
1176 procedure Check_File (File : File_Name_Type) is
1177 Stamp : Time_Stamp_Type;
1178 Name : File_Name_Type := File;
1181 Get_Name_String (Name);
1183 -- Remove any trailing NUL characters
1185 while Name_Len >= Name_Buffer'First
1186 and then Name_Buffer (Name_Len) = NUL
1188 Name_Len := Name_Len - 1;
1191 if Name_Len <= 0 then
1194 elsif Name_Buffer (1) = Get_Switch_Character
1195 or else Name_Buffer (1) = '-'
1197 -- Do not check if File is a switch other than "-l"
1199 if Name_Buffer (2) /= 'l' then
1203 -- The argument is a library switch, get actual name. It
1204 -- is necessary to make a copy of the relevant part of
1205 -- Name_Buffer as Get_Library_Name uses Name_Buffer as well.
1208 Base_Name : constant String := Name_Buffer (3 .. Name_Len);
1211 Name := Get_Library_File (Base_Name);
1214 if Name = No_File then
1219 Stamp := File_Stamp (Name);
1221 -- Find the youngest object file that is younger than the
1222 -- executable. If no such file exist, record the first object
1223 -- file that is not found.
1225 if (O_Stamp < Stamp and then E_Stamp < Stamp)
1226 or else (O_File = No_File and then Stamp (Stamp'First) = ' ')
1231 -- Strip the trailing NUL if present
1233 Get_Name_String (O_File);
1235 if Name_Buffer (Name_Len) = NUL then
1236 Name_Len := Name_Len - 1;
1237 O_File := Name_Find;
1242 ----------------------
1243 -- Get_Library_Name --
1244 ----------------------
1246 -- See comments in a-adaint.c about template syntax
1248 function Get_Library_File (Name : String) return File_Name_Type is
1249 File : File_Name_Type := No_File;
1254 for Ptr in Template'Range loop
1255 case Template (Ptr) is
1257 Add_Str_To_Name_Buffer (Name);
1260 File := Full_Lib_File_Name (Name_Find);
1261 exit when File /= No_File;
1268 Add_Char_To_Name_Buffer (Template (Ptr));
1272 -- The for loop exited because the end of the template
1273 -- was reached. File contains the last possible file name
1276 if File = No_File and then Name_Len > 0 then
1277 File := Full_Lib_File_Name (Name_Find);
1281 end Get_Library_File;
1283 -- Start of processing for Check_Linker_Options
1287 O_Stamp := (others => ' ');
1289 -- Process linker options from the ALI files.
1291 for Opt in 1 .. Linker_Options.Last loop
1292 Check_File (Linker_Options.Table (Opt).Name);
1295 -- Process options given on the command line.
1297 for Opt in Linker_Switches.First .. Linker_Switches.Last loop
1299 -- Check if the previous Opt has one of the two switches
1300 -- that take an extra parameter. (See GCC manual.)
1302 if Opt = Linker_Switches.First
1303 or else (Linker_Switches.Table (Opt - 1).all /= "-u"
1305 Linker_Switches.Table (Opt - 1).all /= "-Xlinker")
1308 Add_Str_To_Name_Buffer (Linker_Switches.Table (Opt).all);
1309 Check_File (Name_Find);
1313 end Check_Linker_Options;
1315 ---------------------
1316 -- Compile_Sources --
1317 ---------------------
1319 procedure Compile_Sources
1320 (Main_Source : File_Name_Type;
1321 Args : Argument_List;
1322 First_Compiled_File : out Name_Id;
1323 Most_Recent_Obj_File : out Name_Id;
1324 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
1325 Main_Unit : out Boolean;
1326 Compilation_Failures : out Natural;
1327 Check_Readonly_Files : Boolean := False;
1328 Do_Not_Execute : Boolean := False;
1329 Force_Compilations : Boolean := False;
1330 Keep_Going : Boolean := False;
1331 In_Place_Mode : Boolean := False;
1332 Initialize_ALI_Data : Boolean := True;
1333 Max_Process : Positive := 1)
1338 Args : Argument_List)
1340 -- Compiles S using Args. If S is a GNAT predefined source
1341 -- "-gnatpg" is added to Args. Non blocking call. L corresponds to the
1342 -- expected library file name. Process_Id of the process spawned to
1343 -- execute the compile.
1345 type Compilation_Data is record
1347 Full_Source_File : File_Name_Type;
1348 Lib_File : File_Name_Type;
1349 Source_Unit : Unit_Name_Type;
1352 Running_Compile : array (1 .. Max_Process) of Compilation_Data;
1353 -- Used to save information about outstanding compilations.
1355 Outstanding_Compiles : Natural := 0;
1356 -- Current number of outstanding compiles
1358 Source_Unit : Unit_Name_Type;
1359 -- Current source unit
1361 Source_File : File_Name_Type;
1362 -- Current source file
1364 Full_Source_File : File_Name_Type;
1365 -- Full name of the current source file
1367 Lib_File : File_Name_Type;
1368 -- Current library file
1370 Full_Lib_File : File_Name_Type;
1371 -- Full name of the current library file
1373 Obj_File : File_Name_Type;
1374 -- Full name of the object file corresponding to Lib_File.
1376 Obj_Stamp : Time_Stamp_Type;
1377 -- Time stamp of the current object file.
1379 Sfile : File_Name_Type;
1380 -- Contains the source file of the units withed by Source_File
1383 -- ALI Id of the current ALI file
1385 Compilation_OK : Boolean;
1386 Need_To_Compile : Boolean;
1389 Text : Text_Buffer_Ptr;
1391 Data : Prj.Project_Data;
1393 Arg_Index : Natural;
1394 -- Index in Special_Args.Table of a given compilation file
1396 Need_To_Check_Standard_Library : Boolean := Check_Readonly_Files;
1398 procedure Add_Process
1400 Sfile : File_Name_Type;
1401 Afile : File_Name_Type;
1402 Uname : Unit_Name_Type);
1403 -- Adds process Pid to the current list of outstanding compilation
1404 -- processes and record the full name of the source file Sfile that
1405 -- we are compiling, the name of its library file Afile and the
1406 -- name of its unit Uname.
1408 procedure Await_Compile
1409 (Sfile : out File_Name_Type;
1410 Afile : out File_Name_Type;
1411 Uname : out Unit_Name_Type;
1413 -- Awaits that an outstanding compilation process terminates. When
1414 -- it does set Sfile to the name of the source file that was compiled
1415 -- Afile to the name of its library file and Uname to the name of its
1416 -- unit. Note that this time stamp can be used to check whether the
1417 -- compilation did generate an object file. OK is set to True if the
1418 -- compilation succeeded. Note that Sfile, Afile and Uname could be
1419 -- resp. No_File, No_File and No_Name if there were no compilations
1422 procedure Collect_Arguments_And_Compile;
1423 -- Collect arguments from project file (if any) and compile
1425 package Good_ALI is new Table.Table (
1426 Table_Component_Type => ALI_Id,
1427 Table_Index_Type => Natural,
1428 Table_Low_Bound => 1,
1429 Table_Initial => 50,
1430 Table_Increment => 100,
1431 Table_Name => "Make.Good_ALI");
1432 -- Contains the set of valid ALI files that have not yet been scanned.
1434 procedure Record_Good_ALI (A : ALI_Id);
1435 -- Records in the previous set the Id of an ALI file.
1437 function Good_ALI_Present return Boolean;
1438 -- Returns True if any ALI file was recorded in the previous set.
1440 function Get_Next_Good_ALI return ALI_Id;
1441 -- Returns the next good ALI_Id record;
1443 procedure Record_Failure
1444 (File : File_Name_Type;
1445 Unit : Unit_Name_Type;
1446 Found : Boolean := True);
1447 -- Records in the previous table that the compilation for File failed.
1448 -- If Found is False then the compilation of File failed because we
1449 -- could not find it. Records also Unit when possible.
1451 function Bad_Compilation_Count return Natural;
1452 -- Returns the number of compilation failures.
1454 procedure Debug_Msg (S : String; N : Name_Id);
1455 -- If Debug.Debug_Flag_W is set outputs string S followed by name N.
1457 function Configuration_Pragmas_Switch
1458 (For_Project : Project_Id)
1459 return Argument_List;
1460 -- Return an argument list of one element, if there is a configuration
1461 -- pragmas file to be specified for For_Project,
1462 -- otherwise return an empty argument list.
1468 procedure Add_Process
1470 Sfile : File_Name_Type;
1471 Afile : File_Name_Type;
1472 Uname : Unit_Name_Type)
1474 OC1 : constant Positive := Outstanding_Compiles + 1;
1477 pragma Assert (OC1 <= Max_Process);
1478 pragma Assert (Pid /= Invalid_Pid);
1480 Running_Compile (OC1).Pid := Pid;
1481 Running_Compile (OC1).Full_Source_File := Sfile;
1482 Running_Compile (OC1).Lib_File := Afile;
1483 Running_Compile (OC1).Source_Unit := Uname;
1485 Outstanding_Compiles := OC1;
1488 --------------------
1492 procedure Await_Compile
1493 (Sfile : out File_Name_Type;
1494 Afile : out File_Name_Type;
1495 Uname : out File_Name_Type;
1501 pragma Assert (Outstanding_Compiles > 0);
1508 Wait_Process (Pid, OK);
1510 if Pid = Invalid_Pid then
1514 for J in Running_Compile'First .. Outstanding_Compiles loop
1515 if Pid = Running_Compile (J).Pid then
1516 Sfile := Running_Compile (J).Full_Source_File;
1517 Afile := Running_Compile (J).Lib_File;
1518 Uname := Running_Compile (J).Source_Unit;
1520 -- To actually remove this Pid and related info from
1521 -- Running_Compile replace its entry with the last valid
1522 -- entry in Running_Compile.
1524 if J = Outstanding_Compiles then
1528 Running_Compile (J) :=
1529 Running_Compile (Outstanding_Compiles);
1532 Outstanding_Compiles := Outstanding_Compiles - 1;
1537 raise Program_Error;
1540 ---------------------------
1541 -- Bad_Compilation_Count --
1542 ---------------------------
1544 function Bad_Compilation_Count return Natural is
1546 return Bad_Compilation.Last - Bad_Compilation.First + 1;
1547 end Bad_Compilation_Count;
1549 -----------------------------------
1550 -- Collect_Arguments_And_Compile --
1551 -----------------------------------
1553 procedure Collect_Arguments_And_Compile is
1555 -- If no project file is used, then just call Compile with
1556 -- the specified Args.
1558 if Main_Project = No_Project then
1559 Pid := Compile (Full_Source_File, Lib_File, Args);
1561 -- A project file was used
1564 -- First check if the current source is an immediate
1565 -- source of a project file.
1567 if Opt.Verbose_Mode then
1569 Write_Line ("Establishing Project context.");
1573 Source_File_Name : constant String :=
1574 Name_Buffer (1 .. Name_Len);
1575 Current_Project : Prj.Project_Id;
1576 Path_Name : File_Name_Type := Source_File;
1577 Compiler_Package : Prj.Package_Id;
1578 Switches : Prj.Variable_Value;
1579 Object_File : String_Access;
1582 if Opt.Verbose_Mode then
1583 Write_Str ("Checking if the Project File exists for """);
1584 Write_Str (Source_File_Name);
1590 (Source_File_Name => Source_File_Name,
1591 Project => Current_Project,
1594 if Current_Project = No_Project then
1596 -- The current source is not an immediate source of any
1597 -- project file. Call Compile with the specified Args plus
1598 -- the saved gcc switches.
1600 if Opt.Verbose_Mode then
1601 Write_Str ("No Project File.");
1608 Args & The_Saved_Gcc_Switches.all);
1610 -- We now know the project of the current source
1613 -- Set ADA_INCLUDE_PATH and ADA_OBJECTS_PATH if the project
1616 -- Note: this will modify these environment variables only
1617 -- for the current gnatmake process and all of its children
1618 -- (invocations of the compiler, the binder and the linker).
1620 -- The caller's ADA_INCLUDE_PATH and ADA_OBJECTS_PATH are
1623 Set_Ada_Paths (Current_Project, True);
1625 Data := Projects.Table (Current_Project);
1627 -- Check if it is a library project that needs to be
1628 -- processed, only if it is not the main project.
1630 if MLib.Tgt.Libraries_Are_Supported
1631 and then Current_Project /= Main_Project
1632 and then Data.Library
1633 and then not Data.Flag1
1635 -- Add to the Q all sources of the project that have
1638 Insert_Project_Sources
1639 (The_Project => Current_Project, Into_Q => True);
1641 -- Now mark the project as processed
1644 Projects.Table (Current_Project).Flag1 := True;
1647 Get_Name_String (Data.Object_Directory);
1649 if Name_Buffer (Name_Len) = '/'
1650 or else Name_Buffer (Name_Len) = Directory_Separator
1654 (Name_Buffer (1 .. Name_Len) &
1655 Object_File_Name (Source_File_Name));
1660 (Name_Buffer (1 .. Name_Len) &
1661 Directory_Separator &
1662 Object_File_Name (Source_File_Name));
1665 if Opt.Verbose_Mode then
1666 Write_Str ("Project file is """);
1667 Write_Str (Get_Name_String (Data.Name));
1672 -- We know look for package Compiler
1673 -- and get the switches from this package.
1675 if Opt.Verbose_Mode then
1676 Write_Str ("Checking package Compiler.");
1682 (Name => Name_Compiler,
1683 In_Packages => Data.Decl.Packages);
1685 if Compiler_Package /= No_Package then
1687 if Opt.Verbose_Mode then
1688 Write_Str ("Getting the switches.");
1692 -- If package Gnatmake.Compiler exists, we get
1693 -- the specific switches for the current source,
1694 -- or the global switches, if any.
1696 Switches := Switches_Of
1697 (Source_File => Source_File,
1698 Source_File_Name => Source_File_Name,
1700 Projects.Table (Current_Project).Naming,
1701 In_Package => Compiler_Package,
1702 Allow_ALI => False);
1706 case Switches.Kind is
1708 -- We have a list of switches. We add to Args
1709 -- these switches, plus the saved gcc switches.
1714 Current : String_List_Id := Switches.Values;
1715 Element : String_Element;
1716 Number : Natural := 0;
1719 while Current /= Nil_String loop
1720 Element := String_Elements.Table (Current);
1721 Number := Number + 1;
1722 Current := Element.Next;
1726 New_Args : Argument_List (1 .. Number);
1729 Current := Switches.Values;
1731 for Index in New_Args'Range loop
1732 Element := String_Elements.Table (Current);
1733 String_To_Name_Buffer (Element.Value);
1735 new String' (Name_Buffer (1 .. Name_Len));
1736 Test_If_Relative_Path (New_Args (Index));
1737 Current := Element.Next;
1743 Args & Output_Flag & Object_File &
1744 Configuration_Pragmas_Switch
1746 New_Args & The_Saved_Gcc_Switches.all);
1750 -- We have a single switch. We add to Args
1751 -- this switch, plus the saved gcc switches.
1755 String_To_Name_Buffer (Switches.Value);
1757 New_Args : constant Argument_List :=
1759 (Name_Buffer (1 .. Name_Len)));
1762 Test_If_Relative_Path (New_Args (1));
1770 Configuration_Pragmas_Switch (Current_Project) &
1771 The_Saved_Gcc_Switches.all);
1774 -- We have no switches from Gnatmake.Compiler.
1775 -- We add to Args the saved gcc switches.
1778 if Opt.Verbose_Mode then
1779 Write_Str ("There are no switches.");
1786 Args & Output_Flag & Object_File &
1787 Configuration_Pragmas_Switch (Current_Project) &
1788 The_Saved_Gcc_Switches.all);
1793 end Collect_Arguments_And_Compile;
1799 function Compile (S : Name_Id; L : Name_Id; Args : Argument_List)
1802 Comp_Args : Argument_List (Args'First .. Args'Last + 7);
1803 Comp_Next : Integer := Args'First;
1804 Comp_Last : Integer;
1806 function Ada_File_Name (Name : Name_Id) return Boolean;
1807 -- Returns True if Name is the name of an ada source file
1808 -- (i.e. suffix is .ads or .adb)
1814 function Ada_File_Name (Name : Name_Id) return Boolean is
1816 Get_Name_String (Name);
1819 and then Name_Buffer (Name_Len - 3 .. Name_Len - 1) = ".ad"
1820 and then (Name_Buffer (Name_Len) = 'b'
1822 Name_Buffer (Name_Len) = 's');
1825 -- Start of processing for Compile
1828 Comp_Args (Comp_Next) := Comp_Flag;
1829 Comp_Next := Comp_Next + 1;
1831 -- Optimize the simple case where the gcc command line looks like
1832 -- gcc -c -I. ... -I- file.adb --into-> gcc -c ... file.adb
1834 if Args (Args'First).all = "-I" & Normalized_CWD
1835 and then Args (Args'Last).all = "-I-"
1836 and then S = Strip_Directory (S)
1838 Comp_Last := Comp_Next + Args'Length - 3;
1839 Comp_Args (Comp_Next .. Comp_Last) :=
1840 Args (Args'First + 1 .. Args'Last - 1);
1843 Comp_Last := Comp_Next + Args'Length - 1;
1844 Comp_Args (Comp_Next .. Comp_Last) := Args;
1847 -- Set -gnatpg for predefined files (for this purpose the renamings
1848 -- such as Text_IO do not count as predefined). Note that we strip
1849 -- the directory name from the source file name becase the call to
1850 -- Fname.Is_Predefined_File_Name cannot deal with directory prefixes.
1853 Fname : constant File_Name_Type := Strip_Directory (S);
1856 if Is_Predefined_File_Name (Fname, False) then
1857 if Check_Readonly_Files then
1858 Comp_Last := Comp_Last + 1;
1859 Comp_Args (Comp_Last) := GNAT_Flag;
1863 ("not allowed to compile """ &
1864 Get_Name_String (Fname) &
1865 """; use -a switch.");
1870 -- Now check if the file name has one of the suffixes familiar to
1871 -- the gcc driver. If this is not the case then add the ada flag
1874 if not Ada_File_Name (S) then
1875 Comp_Last := Comp_Last + 1;
1876 Comp_Args (Comp_Last) := Ada_Flag_1;
1877 Comp_Last := Comp_Last + 1;
1878 Comp_Args (Comp_Last) := Ada_Flag_2;
1881 if L /= Strip_Directory (L) then
1883 -- Build -o argument.
1885 Get_Name_String (L);
1887 for J in reverse 1 .. Name_Len loop
1888 if Name_Buffer (J) = '.' then
1889 Name_Len := J + Object_Suffix'Length - 1;
1890 Name_Buffer (J .. Name_Len) := Object_Suffix;
1895 Comp_Last := Comp_Last + 1;
1896 Comp_Args (Comp_Last) := Output_Flag;
1897 Comp_Last := Comp_Last + 1;
1898 Comp_Args (Comp_Last) := new String'(Name_Buffer (1 .. Name_Len));
1901 Get_Name_String (S);
1903 Comp_Last := Comp_Last + 1;
1904 Comp_Args (Comp_Last) := new String'(Name_Buffer (1 .. Name_Len));
1906 Display (Gcc.all, Comp_Args (Args'First .. Comp_Last));
1908 if Gcc_Path = null then
1909 Osint.Fail ("error, unable to locate " & Gcc.all);
1913 GNAT.OS_Lib.Non_Blocking_Spawn
1914 (Gcc_Path.all, Comp_Args (Args'First .. Comp_Last));
1917 ----------------------------------
1918 -- Configuration_Pragmas_Switch --
1919 ----------------------------------
1921 function Configuration_Pragmas_Switch
1922 (For_Project : Project_Id)
1923 return Argument_List
1926 Prj.Env.Create_Config_Pragmas_File (For_Project, Main_Project);
1928 if Projects.Table (For_Project).Config_File_Name /= No_Name then
1930 (1 => new String'("-gnatec" &
1932 (Projects.Table (For_Project).Config_File_Name)));
1935 return (1 .. 0 => null);
1937 end Configuration_Pragmas_Switch;
1943 procedure Debug_Msg (S : String; N : Name_Id) is
1945 if Debug.Debug_Flag_W then
1946 Write_Str (" ... ");
1954 -----------------------
1955 -- Get_Next_Good_ALI --
1956 -----------------------
1958 function Get_Next_Good_ALI return ALI_Id is
1962 pragma Assert (Good_ALI_Present);
1963 ALI := Good_ALI.Table (Good_ALI.Last);
1964 Good_ALI.Decrement_Last;
1966 end Get_Next_Good_ALI;
1968 ----------------------
1969 -- Good_ALI_Present --
1970 ----------------------
1972 function Good_ALI_Present return Boolean is
1974 return Good_ALI.First <= Good_ALI.Last;
1975 end Good_ALI_Present;
1977 --------------------
1978 -- Record_Failure --
1979 --------------------
1981 procedure Record_Failure
1982 (File : File_Name_Type;
1983 Unit : Unit_Name_Type;
1984 Found : Boolean := True)
1987 Bad_Compilation.Increment_Last;
1988 Bad_Compilation.Table (Bad_Compilation.Last) := (File, Unit, Found);
1991 ---------------------
1992 -- Record_Good_ALI --
1993 ---------------------
1995 procedure Record_Good_ALI (A : ALI_Id) is
1997 Good_ALI.Increment_Last;
1998 Good_ALI.Table (Good_ALI.Last) := A;
1999 end Record_Good_ALI;
2001 -- Start of processing for Compile_Sources
2004 pragma Assert (Args'First = 1);
2006 -- Package and Queue initializations.
2009 Bad_Compilation.Init;
2010 Output.Set_Standard_Error;
2013 if Initialize_ALI_Data then
2015 Initialize_ALI_Source;
2018 -- The following two flags affect the behavior of ALI.Set_Source_Table.
2019 -- We set Opt.Check_Source_Files to True to ensure that source file
2020 -- time stamps are checked, and we set Opt.All_Sources to False to
2021 -- avoid checking the presence of the source files listed in the
2022 -- source dependency section of an ali file (which would be a mistake
2023 -- since the ali file may be obsolete).
2025 Opt.Check_Source_Files := True;
2026 Opt.All_Sources := False;
2028 -- If the main source is marked, there is nothing to compile.
2029 -- This can happen when we have several main subprograms.
2030 -- For the first main, we always insert in the Q.
2032 if not Is_Marked (Main_Source) then
2033 Insert_Q (Main_Source);
2037 First_Compiled_File := No_File;
2038 Most_Recent_Obj_File := No_File;
2041 -- Keep looping until there is no more work to do (the Q is empty)
2042 -- and all the outstanding compilations have terminated
2044 Make_Loop : while not Empty_Q or else Outstanding_Compiles > 0 loop
2046 -- If the user does not want to keep going in case of errors then
2047 -- wait for the remaining outstanding compiles and then exit.
2049 if Bad_Compilation_Count > 0 and then not Keep_Going then
2050 while Outstanding_Compiles > 0 loop
2052 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
2054 if not Compilation_OK then
2055 Record_Failure (Full_Source_File, Source_Unit);
2062 -- PHASE 1: Check if there is more work that we can do (ie the Q
2063 -- is non empty). If there is, do it only if we have not yet used
2064 -- up all the available processes.
2066 if not Empty_Q and then Outstanding_Compiles < Max_Process then
2067 Extract_From_Q (Source_File, Source_Unit);
2068 Full_Source_File := Osint.Full_Source_Name (Source_File);
2069 Lib_File := Osint.Lib_File_Name (Source_File);
2070 Full_Lib_File := Osint.Full_Lib_File_Name (Lib_File);
2072 -- If the library file is an Ada library skip it
2074 if Full_Lib_File /= No_File
2075 and then In_Ada_Lib_Dir (Full_Lib_File)
2077 Verbose_Msg (Lib_File, "is in an Ada library", Prefix => " ");
2079 -- If the library file is a read-only library skip it
2081 elsif Full_Lib_File /= No_File
2082 and then not Check_Readonly_Files
2083 and then Is_Readonly_Library (Full_Lib_File)
2086 (Lib_File, "is a read-only library", Prefix => " ");
2088 -- The source file that we are checking cannot be located
2090 elsif Full_Source_File = No_File then
2091 Record_Failure (Source_File, Source_Unit, False);
2093 -- Source and library files can be located but are internal
2096 elsif not Check_Readonly_Files
2097 and then Full_Lib_File /= No_File
2098 and then Is_Internal_File_Name (Source_File)
2101 if Force_Compilations then
2103 ("not allowed to compile """ &
2104 Get_Name_String (Source_File) &
2105 """; use -a switch.");
2109 (Lib_File, "is an internal library", Prefix => " ");
2111 -- The source file that we are checking can be located
2114 -- Don't waste any time if we have to recompile anyway
2116 Obj_Stamp := Empty_Time_Stamp;
2117 Need_To_Compile := Force_Compilations;
2119 if not Force_Compilations then
2120 Check (Lib_File, ALI, Obj_File, Obj_Stamp);
2121 Need_To_Compile := (ALI = No_ALI_Id);
2124 if not Need_To_Compile then
2126 -- The ALI file is up-to-date. Record its Id.
2128 Record_Good_ALI (ALI);
2130 -- Record the time stamp of the most recent object file
2131 -- as long as no (re)compilations are needed.
2133 if First_Compiled_File = No_File
2134 and then (Most_Recent_Obj_File = No_File
2135 or else Obj_Stamp > Most_Recent_Obj_Stamp)
2137 Most_Recent_Obj_File := Obj_File;
2138 Most_Recent_Obj_Stamp := Obj_Stamp;
2142 -- Is this the first file we have to compile?
2144 if First_Compiled_File = No_File then
2145 First_Compiled_File := Full_Source_File;
2146 Most_Recent_Obj_File := No_File;
2148 if Do_Not_Execute then
2153 if In_Place_Mode then
2155 -- If the library file was not found, then save the
2156 -- library file near the source file.
2158 if Full_Lib_File = No_File then
2159 Get_Name_String (Full_Source_File);
2161 for J in reverse 1 .. Name_Len loop
2162 if Name_Buffer (J) = '.' then
2163 Name_Buffer (J + 1 .. J + 3) := "ali";
2169 Lib_File := Name_Find;
2171 -- If the library file was found, then save the
2172 -- library file in the same place.
2175 Lib_File := Full_Lib_File;
2180 -- Check for special compilation flags
2183 Get_Name_String (Source_File);
2185 -- Start the compilation and record it. We can do this
2186 -- because there is at least one free process.
2188 Collect_Arguments_And_Compile;
2190 -- Make sure we could successfully start the compilation
2192 if Pid = Invalid_Pid then
2193 Record_Failure (Full_Source_File, Source_Unit);
2196 (Pid, Full_Source_File, Lib_File, Source_Unit);
2202 -- PHASE 2: Now check if we should wait for a compilation to
2203 -- finish. This is the case if all the available processes are
2204 -- busy compiling sources or there is nothing else to do
2205 -- (that is the Q is empty and there are no good ALIs to process).
2207 if Outstanding_Compiles = Max_Process
2209 and then not Good_ALI_Present
2210 and then Outstanding_Compiles > 0)
2213 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
2215 if not Compilation_OK then
2216 Record_Failure (Full_Source_File, Source_Unit);
2219 -- Re-read the updated library file
2221 Text := Read_Library_Info (Lib_File);
2223 -- If no ALI file was generated by this compilation nothing
2224 -- more to do, otherwise scan the ali file and record it.
2225 -- If the scan fails, a previous ali file is inconsistent with
2226 -- the unit just compiled.
2228 if Text /= null then
2230 Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
2232 if ALI = No_ALI_Id then
2234 (Lib_File, "incompatible ALI file, please recompile");
2235 Record_Failure (Full_Source_File, Source_Unit);
2238 Record_Good_ALI (ALI);
2241 -- If we could not read the ALI file that was just generated
2242 -- then there could be a problem reading either the ALI or the
2243 -- corresponding object file (if Opt.Check_Object_Consistency
2244 -- is set Read_Library_Info checks that the time stamp of the
2245 -- object file is more recent than that of the ALI). For an
2246 -- example of problems caught by this test see [6625-009].
2251 "WARNING: ALI or object file not found after compile");
2252 Record_Failure (Full_Source_File, Source_Unit);
2257 exit Make_Loop when Unique_Compile;
2259 -- PHASE 3: Check if we recorded good ALI files. If yes process
2260 -- them now in the order in which they have been recorded. There
2261 -- are two occasions in which we record good ali files. The first is
2262 -- in phase 1 when, after scanning an existing ALI file we realise
2263 -- it is up-to-date, the second instance is after a successful
2266 while Good_ALI_Present loop
2267 ALI := Get_Next_Good_ALI;
2269 -- If we are processing the library file corresponding to the
2270 -- main source file check if this source can be a main unit.
2272 if ALIs.Table (ALI).Sfile = Main_Source then
2273 Main_Unit := ALIs.Table (ALI).Main_Program /= None;
2276 -- The following adds the standard library (s-stalib) to the
2277 -- list of files to be handled by gnatmake: this file and any
2278 -- files it depends on are always included in every bind,
2279 -- except in No_Run_Time mode, even if they are not
2280 -- in the explicit dependency list.
2282 -- However, to avoid annoying output about s-stalib.ali being
2283 -- read only, when "-v" is used, we add the standard library
2284 -- only when "-a" is used.
2286 if Need_To_Check_Standard_Library then
2287 Need_To_Check_Standard_Library := False;
2289 if not ALIs.Table (ALI).No_Run_Time then
2294 Name_Len := Standard_Library_Package_Body_Name'Length;
2295 Name_Buffer (1 .. Name_Len) :=
2296 Standard_Library_Package_Body_Name;
2297 Sfile := Name_Enter;
2299 if not Is_Marked (Sfile) then
2307 -- Now insert in the Q the unmarked source files (i.e. those
2308 -- which have neever been inserted in the Q and hence never
2312 ALIs.Table (ALI).First_Unit .. ALIs.Table (ALI).Last_Unit
2315 Units.Table (J).First_With .. Units.Table (J).Last_With
2317 Sfile := Withs.Table (K).Sfile;
2319 if Sfile = No_File then
2320 Debug_Msg ("Skipping generic:", Withs.Table (K).Uname);
2322 elsif Is_Marked (Sfile) then
2323 Debug_Msg ("Skipping marked file:", Sfile);
2325 elsif not Check_Readonly_Files
2326 and then Is_Internal_File_Name (Sfile)
2328 Debug_Msg ("Skipping internal file:", Sfile);
2331 Insert_Q (Sfile, Withs.Table (K).Uname);
2338 if Opt.Display_Compilation_Progress then
2339 Write_Str ("completed ");
2340 Write_Int (Int (Q_Front));
2341 Write_Str (" out of ");
2342 Write_Int (Int (Q.Last));
2344 Write_Int (Int ((Q_Front * 100) / (Q.Last - Q.First)));
2345 Write_Str ("%)...");
2350 Compilation_Failures := Bad_Compilation_Count;
2352 -- Compilation is finished
2354 -- Delete any temporary configuration pragma file
2356 if Main_Project /= No_Project then
2361 for Project in 1 .. Projects.Last loop
2362 if Projects.Table (Project).Config_File_Temp then
2363 if Opt.Verbose_Mode then
2364 Write_Str ("Deleting temp configuration file """);
2365 Write_Str (Get_Name_String
2366 (Projects.Table (Project).Config_File_Name));
2371 (Name => Get_Name_String
2372 (Projects.Table (Project).Config_File_Name),
2373 Success => Success);
2375 -- Make sure that we don't have a config file for this
2376 -- project, in case when there are several mains.
2377 -- In this case, we will recreate another config file:
2378 -- we cannot reuse the one that we just deleted!
2380 Projects.Table (Project).Config_Checked := False;
2381 Projects.Table (Project).Config_File_Name := No_Name;
2382 Projects.Table (Project).Config_File_Temp := False;
2387 end Compile_Sources;
2393 procedure Display (Program : String; Args : Argument_List) is
2395 pragma Assert (Args'First = 1);
2397 if Display_Executed_Programs then
2398 Write_Str (Program);
2400 for J in Args'Range loop
2402 Write_Str (Args (J).all);
2409 ----------------------
2410 -- Display_Commands --
2411 ----------------------
2413 procedure Display_Commands (Display : Boolean := True) is
2415 Display_Executed_Programs := Display;
2416 end Display_Commands;
2422 function Empty_Q return Boolean is
2424 if Debug.Debug_Flag_P then
2425 Write_Str (" Q := [");
2427 for J in Q_Front .. Q.Last - 1 loop
2429 Write_Name (Q.Table (J).File);
2438 return Q_Front >= Q.Last;
2441 ---------------------
2442 -- Extract_Failure --
2443 ---------------------
2445 procedure Extract_Failure
2446 (File : out File_Name_Type;
2447 Unit : out Unit_Name_Type;
2448 Found : out Boolean)
2451 File := Bad_Compilation.Table (Bad_Compilation.Last).File;
2452 Unit := Bad_Compilation.Table (Bad_Compilation.Last).Unit;
2453 Found := Bad_Compilation.Table (Bad_Compilation.Last).Found;
2454 Bad_Compilation.Decrement_Last;
2455 end Extract_Failure;
2457 --------------------
2458 -- Extract_From_Q --
2459 --------------------
2461 procedure Extract_From_Q
2462 (Source_File : out File_Name_Type;
2463 Source_Unit : out Unit_Name_Type)
2465 File : constant File_Name_Type := Q.Table (Q_Front).File;
2466 Unit : constant Unit_Name_Type := Q.Table (Q_Front).Unit;
2469 if Debug.Debug_Flag_Q then
2470 Write_Str (" Q := Q - [ ");
2476 Q_Front := Q_Front + 1;
2477 Source_File := File;
2478 Source_Unit := Unit;
2485 procedure Gnatmake is
2486 Main_Source_File : File_Name_Type;
2487 -- The source file containing the main compilation unit
2489 Compilation_Failures : Natural;
2491 Is_Main_Unit : Boolean;
2492 -- Set to True by Compile_Sources if the Main_Source_File can be a
2495 Main_ALI_File : File_Name_Type;
2496 -- The ali file corresponding to Main_Source_File
2498 Executable : File_Name_Type := No_File;
2499 -- The file name of an executable
2501 Non_Std_Executable : Boolean := False;
2502 -- Non_Std_Executable is set to True when there is a possibility
2503 -- that the linker will not choose the correct executable file name.
2505 Executable_Obsolete : Boolean := False;
2506 -- Executable_Obsolete is set to True for the first obsolete main
2507 -- and is never reset to False. Any subsequent main will always
2508 -- be rebuild (if we rebuild mains), even in the case when it is not
2509 -- really necessary, because it is too hard to decide.
2512 Do_Compile_Step := True;
2513 Do_Bind_Step := True;
2514 Do_Link_Step := True;
2518 if Hostparm.Java_VM then
2519 Gcc := new String'("jgnat");
2520 Gnatbind := new String'("jgnatbind");
2521 Gnatlink := new String '("jgnatlink");
2523 -- Do not check for an object file (".o") when compiling to
2524 -- Java bytecode since ".class" files are generated instead.
2526 Opt.Check_Object_Consistency := False;
2529 if Opt.Verbose_Mode then
2531 Write_Str ("GNATMAKE ");
2532 Write_Str (Gnatvsn.Gnat_Version_String);
2533 Write_Str (" Copyright 1995-2001 Free Software Foundation, Inc.");
2537 -- If no mains have been specified on the command line,
2538 -- and we are using a project file, we either find the main(s)
2539 -- in the attribute Main of the main project, or we put all
2540 -- the sources of the project file as mains.
2542 if Main_Project /= No_Project and then Osint.Number_Of_Files = 0 then
2544 Name_Buffer (1 .. 4) := "main";
2547 Main_Id : constant Name_Id := Name_Find;
2549 Mains : constant Prj.Variable_Value :=
2551 (Variable_Name => Main_Id,
2553 Projects.Table (Main_Project).Decl.Attributes);
2555 Value : String_List_Id := Mains.Values;
2558 -- The attribute Main is an empty list or not specified,
2559 -- or else gnatmake was invoked with the switch "-u".
2561 if Value = Prj.Nil_String or else Unique_Compile then
2563 -- First make sure that the binder and the linker
2564 -- will not be invoked.
2566 Do_Bind_Step := False;
2567 Do_Link_Step := False;
2569 -- Put all the sources in the queue
2571 Insert_Project_Sources
2572 (The_Project => Main_Project, Into_Q => False);
2575 -- The attribute Main is not an empty list.
2576 -- Put all the main subprograms in the list as if there were
2577 -- specified on the command line.
2579 while Value /= Prj.Nil_String loop
2580 String_To_Name_Buffer (String_Elements.Table (Value).Value);
2581 Osint.Add_File (Name_Buffer (1 .. Name_Len));
2582 Value := String_Elements.Table (Value).Next;
2590 -- Output usage information if no files. Note that this can happen
2591 -- in the case of a project file that contains only subunits.
2593 if Osint.Number_Of_Files = 0 then
2595 Exit_Program (E_Fatal);
2599 -- If -l was specified behave as if -n was specified
2601 if Opt.List_Dependencies then
2602 Opt.Do_Not_Execute := True;
2605 -- Note that Osint.Next_Main_Source will always return the (possibly
2606 -- abbreviated file) without any directory information.
2608 Main_Source_File := Next_Main_Source;
2610 if Project_File_Name = null then
2611 Add_Switch ("-I-", Compiler, And_Save => True);
2612 Add_Switch ("-I-", Binder, And_Save => True);
2614 if Opt.Look_In_Primary_Dir then
2618 Normalize_Directory_Name
2619 (Get_Primary_Src_Search_Directory.all).all,
2620 Compiler, Append_Switch => False,
2623 Add_Switch ("-aO" & Normalized_CWD,
2625 Append_Switch => False,
2631 -- If the user wants a program without a main subprogram, add the
2632 -- appropriate switch to the binder.
2634 if Opt.No_Main_Subprogram then
2635 Add_Switch ("-z", Binder, And_Save => True);
2638 if Main_Project /= No_Project then
2641 (Get_Name_String (Projects.Table (Main_Project).Object_Directory));
2643 -- Find the file name of the main unit
2646 Main_Source_File_Name : constant String :=
2647 Get_Name_String (Main_Source_File);
2648 Main_Unit_File_Name : constant String :=
2649 Prj.Env.File_Name_Of_Library_Unit_Body
2650 (Name => Main_Source_File_Name,
2651 Project => Main_Project);
2653 The_Packages : constant Package_Id :=
2654 Projects.Table (Main_Project).Decl.Packages;
2656 Gnatmake : constant Prj.Package_Id :=
2658 (Name => Name_Builder,
2659 In_Packages => The_Packages);
2661 Binder_Package : constant Prj.Package_Id :=
2663 (Name => Name_Binder,
2664 In_Packages => The_Packages);
2666 Linker_Package : constant Prj.Package_Id :=
2668 (Name => Name_Linker,
2669 In_Packages => The_Packages);
2672 -- We fail if we cannot find the main source file
2673 -- as an immediate source of the main project file.
2675 if Main_Unit_File_Name = "" then
2676 Fail ('"' & Main_Source_File_Name &
2677 """ is not a unit of project " &
2678 Project_File_Name.all & ".");
2680 -- Remove any directory information from the main
2681 -- source file name.
2684 Pos : Natural := Main_Unit_File_Name'Last;
2688 exit when Pos < Main_Unit_File_Name'First or else
2689 Main_Unit_File_Name (Pos) = Directory_Separator;
2693 Name_Len := Main_Unit_File_Name'Last - Pos;
2695 Name_Buffer (1 .. Name_Len) :=
2697 (Pos + 1 .. Main_Unit_File_Name'Last);
2699 Main_Source_File := Name_Find;
2701 -- We only output the main source file if there is only one
2703 if Opt.Verbose_Mode and then Osint.Number_Of_Files = 1 then
2704 Write_Str ("Main source file: """);
2705 Write_Str (Main_Unit_File_Name
2706 (Pos + 1 .. Main_Unit_File_Name'Last));
2712 -- If there is a package gnatmake in the main project file, add
2713 -- the switches from it. We also add the switches from packages
2714 -- gnatbind and gnatlink, if any.
2716 if Gnatmake /= No_Package then
2718 -- If there is only one main, we attempt to get the gnatmake
2719 -- switches for this main (if any). If there are no specific
2720 -- switch for this particular main, get the general gnatmake
2721 -- switches (if any).
2723 if Osint.Number_Of_Files = 1 then
2724 if Opt.Verbose_Mode then
2725 Write_Str ("Adding gnatmake switches for """);
2726 Write_Str (Main_Unit_File_Name);
2731 (File_Name => Main_Unit_File_Name,
2732 The_Package => Gnatmake,
2736 -- If there are several mains, we always get the general
2737 -- gnatmake switches (if any).
2739 -- Note: As there is never a source with name " ",
2740 -- we are guaranteed to always get the gneneral switches.
2744 The_Package => Gnatmake,
2750 if Binder_Package /= No_Package then
2752 -- If there is only one main, we attempt to get the gnatbind
2753 -- switches for this main (if any). If there are no specific
2754 -- switch for this particular main, get the general gnatbind
2755 -- switches (if any).
2757 if Osint.Number_Of_Files = 1 then
2758 if Opt.Verbose_Mode then
2759 Write_Str ("Adding binder switches for """);
2760 Write_Str (Main_Unit_File_Name);
2765 (File_Name => Main_Unit_File_Name,
2766 The_Package => Binder_Package,
2770 -- If there are several mains, we always get the general
2771 -- gnatbind switches (if any).
2773 -- Note: As there is never a source with name " ",
2774 -- we are guaranteed to always get the gneneral switches.
2778 The_Package => Binder_Package,
2784 if Linker_Package /= No_Package then
2786 -- If there is only one main, we attempt to get the
2787 -- gnatlink switches for this main (if any). If there are
2788 -- no specific switch for this particular main, we get the
2789 -- general gnatlink switches (if any).
2791 if Osint.Number_Of_Files = 1 then
2792 if Opt.Verbose_Mode then
2793 Write_Str ("Adding linker switches for""");
2794 Write_Str (Main_Unit_File_Name);
2799 (File_Name => Main_Unit_File_Name,
2800 The_Package => Linker_Package,
2804 -- If there are several mains, we always get the general
2805 -- gnatlink switches (if any).
2807 -- Note: As there is never a source with name " ",
2808 -- we are guaranteed to always get the general switches.
2812 The_Package => Linker_Package,
2819 Display_Commands (not Opt.Quiet_Output);
2821 -- We now put in the Binder_Switches and Linker_Switches tables,
2822 -- the binder and linker switches of the command line that have been
2823 -- put in the Saved_ tables. If a project file was used, then the
2824 -- command line switches will follow the project file switches.
2826 for J in 1 .. Saved_Binder_Switches.Last loop
2828 (Saved_Binder_Switches.Table (J),
2833 for J in 1 .. Saved_Linker_Switches.Last loop
2835 (Saved_Linker_Switches.Table (J),
2840 -- If no project file is used, we just put the gcc switches
2841 -- from the command line in the Gcc_Switches table.
2843 if Main_Project = No_Project then
2844 for J in 1 .. Saved_Gcc_Switches.Last loop
2846 (Saved_Gcc_Switches.Table (J),
2852 -- And we put the command line gcc switches in the variable
2853 -- The_Saved_Gcc_Switches. They are going to be used later
2854 -- in procedure Compile_Sources.
2856 The_Saved_Gcc_Switches :=
2857 new Argument_List (1 .. Saved_Gcc_Switches.Last + 1);
2859 for J in 1 .. Saved_Gcc_Switches.Last loop
2860 The_Saved_Gcc_Switches (J) := Saved_Gcc_Switches.Table (J);
2861 Test_If_Relative_Path (The_Saved_Gcc_Switches (J));
2864 -- We never use gnat.adc when a project file is used
2866 The_Saved_Gcc_Switches (The_Saved_Gcc_Switches'Last) :=
2869 for J in 1 .. Gcc_Switches.Last loop
2870 Test_If_Relative_Path (Gcc_Switches.Table (J));
2873 for J in 1 .. Binder_Switches.Last loop
2874 Test_If_Relative_Path (Binder_Switches.Table (J));
2877 for J in 1 .. Linker_Switches.Last loop
2878 Test_If_Relative_Path (Linker_Switches.Table (J));
2883 -- If there was a --GCC, --GNATBIND or --GNATLINK switch on
2884 -- the command line, then we have to use it, even if there was
2885 -- another switch in the project file.
2887 if Saved_Gcc /= null then
2891 if Saved_Gnatbind /= null then
2892 Gnatbind := Saved_Gnatbind;
2895 if Saved_Gnatlink /= null then
2896 Gnatlink := Saved_Gnatlink;
2899 Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
2900 Gnatbind_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
2901 Gnatlink_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
2903 -- If we have specified -j switch both from the project file
2904 -- and on the command line, the one from the command line takes
2907 if Saved_Maximum_Processes = 0 then
2908 Saved_Maximum_Processes := Opt.Maximum_Processes;
2911 -- If either -c, -b or -l has been specified, we will not necessarily
2912 -- execute all steps.
2914 if Compile_Only or else Bind_Only or else Link_Only then
2915 Do_Compile_Step := Do_Compile_Step and Compile_Only;
2916 Do_Bind_Step := Do_Bind_Step and Bind_Only;
2917 Do_Link_Step := Do_Link_Step and Link_Only;
2919 -- If -c has been specified, but not -b, ignore any potential -l
2921 if Do_Compile_Step and then not Do_Bind_Step then
2922 Do_Link_Step := False;
2926 -- Here is where the make process is started
2928 -- We do the same process for each main
2930 Multiple_Main_Loop : for N_File in 1 .. Osint.Number_Of_Files loop
2932 if Do_Compile_Step then
2933 Recursive_Compilation_Step : declare
2934 Args : Argument_List (1 .. Gcc_Switches.Last);
2936 First_Compiled_File : Name_Id;
2938 Youngest_Obj_File : Name_Id;
2939 Youngest_Obj_Stamp : Time_Stamp_Type;
2941 Executable_Stamp : Time_Stamp_Type;
2942 -- Executable is the final executable program.
2945 Executable := No_File;
2946 Non_Std_Executable := False;
2948 for J in 1 .. Gcc_Switches.Last loop
2949 Args (J) := Gcc_Switches.Table (J);
2952 -- Look inside the linker switches to see if the name
2953 -- of the final executable program was specified.
2956 J in reverse Linker_Switches.First .. Linker_Switches.Last
2958 if Linker_Switches.Table (J).all = Output_Flag.all then
2959 pragma Assert (J < Linker_Switches.Last);
2961 -- We cannot specify a single executable for several
2962 -- main subprograms!
2964 if Osint.Number_Of_Files > 1 then
2966 ("cannot specify a single executable " &
2967 "for several mains");
2970 Name_Len := Linker_Switches.Table (J + 1)'Length;
2971 Name_Buffer (1 .. Name_Len) :=
2972 Linker_Switches.Table (J + 1).all;
2974 -- If target has an executable suffix and it has not been
2975 -- specified then it is added here.
2977 if Executable_Suffix'Length /= 0
2978 and then Linker_Switches.Table (J + 1)
2979 (Name_Len - Executable_Suffix'Length + 1
2980 .. Name_Len) /= Executable_Suffix
2982 Name_Buffer (Name_Len + 1 ..
2983 Name_Len + Executable_Suffix'Length) :=
2985 Name_Len := Name_Len + Executable_Suffix'Length;
2988 Executable := Name_Enter;
2990 Verbose_Msg (Executable, "final executable");
2994 -- If the name of the final executable program was not
2995 -- specified then construct it from the main input file.
2997 if Executable = No_File then
2998 if Main_Project = No_Project then
3000 Executable_Name (Strip_Suffix (Main_Source_File));
3003 -- If we are using a project file, we attempt to
3004 -- remove the body (or spec) termination of the main
3005 -- subprogram. We find it the the naming scheme of the
3006 -- project file. This will avoid to generate an
3007 -- executable "main.2" for a main subprogram
3008 -- "main.2.ada", when the body termination is ".2.ada".
3011 Body_Append : constant String :=
3015 Naming.Current_Impl_Suffix);
3017 Spec_Append : constant String :=
3021 Naming.Current_Spec_Suffix);
3024 Get_Name_String (Main_Source_File);
3026 if Name_Len > Body_Append'Length
3027 and then Name_Buffer
3028 (Name_Len - Body_Append'Length + 1 .. Name_Len) =
3031 -- We have found the body termination. We remove it
3032 -- add the executable termination, if any.
3034 Name_Len := Name_Len - Body_Append'Length;
3035 Executable := Executable_Name (Name_Find);
3037 elsif Name_Len > Spec_Append'Length
3040 (Name_Len - Spec_Append'Length + 1 .. Name_Len) =
3043 -- We have found the spec termination. We remove
3044 -- it, add the executable termination, if any.
3046 Name_Len := Name_Len - Spec_Append'Length;
3047 Executable := Executable_Name (Name_Find);
3051 Executable_Name (Strip_Suffix (Main_Source_File));
3058 if Main_Project /= No_Project then
3060 Exec_File_Name : constant String :=
3061 Get_Name_String (Executable);
3064 if not Is_Absolute_Path (Exec_File_Name) then
3065 for Index in Exec_File_Name'Range loop
3066 if Exec_File_Name (Index) = Directory_Separator then
3067 Fail ("relative executable (""" &
3069 """) with directory part not allowed " &
3070 "when using project files");
3074 Get_Name_String (Projects.Table
3075 (Main_Project).Exec_Directory);
3078 Name_Buffer (Name_Len) /= Directory_Separator
3080 Name_Len := Name_Len + 1;
3081 Name_Buffer (Name_Len) := Directory_Separator;
3084 Name_Buffer (Name_Len + 1 ..
3085 Name_Len + Exec_File_Name'Length) :=
3087 Name_Len := Name_Len + Exec_File_Name'Length;
3088 Executable := Name_Find;
3089 Non_Std_Executable := True;
3095 -- Now we invoke Compile_Sources for the current main
3098 (Main_Source => Main_Source_File,
3100 First_Compiled_File => First_Compiled_File,
3101 Most_Recent_Obj_File => Youngest_Obj_File,
3102 Most_Recent_Obj_Stamp => Youngest_Obj_Stamp,
3103 Main_Unit => Is_Main_Unit,
3104 Compilation_Failures => Compilation_Failures,
3105 Check_Readonly_Files => Opt.Check_Readonly_Files,
3106 Do_Not_Execute => Opt.Do_Not_Execute,
3107 Force_Compilations => Opt.Force_Compilations,
3108 In_Place_Mode => Opt.In_Place_Mode,
3109 Keep_Going => Opt.Keep_Going,
3110 Initialize_ALI_Data => True,
3111 Max_Process => Saved_Maximum_Processes);
3113 if Opt.Verbose_Mode then
3114 Write_Str ("End of compilation");
3118 if Compilation_Failures /= 0 then
3119 List_Bad_Compilations;
3120 raise Compilation_Failed;
3123 -- Regenerate libraries, if any and if object files
3124 -- have been regenerated
3126 if Main_Project /= No_Project
3127 and then MLib.Tgt.Libraries_Are_Supported
3130 for Proj in Projects.First .. Projects.Last loop
3132 if Proj /= Main_Project
3133 and then Projects.Table (Proj).Flag1
3135 MLib.Prj.Build_Library (For_Project => Proj);
3142 if Opt.List_Dependencies then
3143 if First_Compiled_File /= No_File then
3145 (First_Compiled_File,
3146 "must be recompiled. Can't generate dependence list.");
3151 elsif First_Compiled_File = No_File
3152 and then not Do_Bind_Step
3153 and then not Opt.Quiet_Output
3154 and then Osint.Number_Of_Files = 1
3156 if Unique_Compile then
3157 Inform (Msg => "object up to date.");
3159 Inform (Msg => "objects up to date.");
3162 elsif Opt.Do_Not_Execute
3163 and then First_Compiled_File /= No_File
3165 Write_Name (First_Compiled_File);
3169 -- Stop after compile step if any of:
3171 -- 1) -n (Do_Not_Execute) specified
3173 -- 2) -l (List_Dependencies) specified (also sets
3174 -- Do_Not_Execute above, so this is probably superfluous).
3176 -- 3) -c (Compile_Only) specified, but not -b (Bind_Only)
3178 -- 4) Made unit cannot be a main unit
3180 if (Opt.Do_Not_Execute
3181 or Opt.List_Dependencies
3183 or not Is_Main_Unit)
3184 and then not No_Main_Subprogram
3186 if Osint.Number_Of_Files = 1 then
3194 -- If the objects were up-to-date check if the executable file
3195 -- is also up-to-date. For now always bind and link on the JVM
3196 -- since there is currently no simple way to check the
3197 -- up-to-date status of objects
3199 if not Hostparm.Java_VM
3200 and then First_Compiled_File = No_File
3202 Executable_Stamp := File_Stamp (Executable);
3204 -- Once Executable_Obsolete is set to True, it is never
3205 -- reset to False, because it is too hard to accurately
3206 -- decide if a subsequent main need to be rebuilt or not.
3208 Executable_Obsolete :=
3210 or else Youngest_Obj_Stamp > Executable_Stamp;
3212 if not Executable_Obsolete then
3214 -- If no Ada object files obsolete the executable, check
3215 -- for younger or missing linker files.
3217 Check_Linker_Options
3220 Youngest_Obj_Stamp);
3222 Executable_Obsolete := Youngest_Obj_File /= No_File;
3225 -- Return if the executable is up to date
3226 -- and otherwise motivate the relink/rebind.
3228 if not Executable_Obsolete then
3229 if not Opt.Quiet_Output then
3230 Inform (Executable, "up to date.");
3233 if Osint.Number_Of_Files = 1 then
3241 if Executable_Stamp (1) = ' ' then
3242 Verbose_Msg (Executable, "missing.", Prefix => " ");
3244 elsif Youngest_Obj_Stamp (1) = ' ' then
3250 elsif Youngest_Obj_Stamp > Executable_Stamp then
3253 "(" & String (Youngest_Obj_Stamp) & ") newer than",
3255 "(" & String (Executable_Stamp) & ")");
3259 (Executable, "needs to be rebuild.",
3264 end Recursive_Compilation_Step;
3267 -- If we are here, it means that we need to rebuilt the current
3268 -- main. So we set Executable_Obsolete to True to make sure that
3269 -- the subsequent mains will be rebuilt.
3271 Executable_Obsolete := True;
3273 Main_ALI_In_Place_Mode_Step :
3275 ALI_File : File_Name_Type;
3276 Src_File : File_Name_Type;
3279 Src_File := Strip_Directory (Main_Source_File);
3280 ALI_File := Lib_File_Name (Src_File);
3281 Main_ALI_File := Full_Lib_File_Name (ALI_File);
3283 -- When In_Place_Mode, the library file can be located in the
3284 -- Main_Source_File directory which may not be present in the
3285 -- library path. In this case, use the corresponding library file
3288 if Main_ALI_File = No_File and then Opt.In_Place_Mode then
3289 Get_Name_String (Get_Directory (Full_Source_Name (Src_File)));
3290 Get_Name_String_And_Append (ALI_File);
3291 Main_ALI_File := Name_Find;
3292 Main_ALI_File := Full_Lib_File_Name (Main_ALI_File);
3295 if Main_ALI_File = No_File then
3296 Fail ("could not find the main ALI file");
3299 end Main_ALI_In_Place_Mode_Step;
3301 if Do_Bind_Step then
3303 Args : Argument_List
3304 (Binder_Switches.First .. Binder_Switches.Last);
3307 -- Get all the binder switches
3309 for J in Binder_Switches.First .. Binder_Switches.Last loop
3310 Args (J) := Binder_Switches.Table (J);
3313 if Main_Project /= No_Project then
3315 -- Put all the source directories in ADA_INCLUDE_PATH,
3316 -- and all the object directories in ADA_OBJECTS_PATH
3318 Set_Ada_Paths (Main_Project, False);
3321 Bind (Main_ALI_File, Args);
3325 if Do_Link_Step then
3328 There_Are_Libraries : Boolean := False;
3329 Linker_Switches_Last : constant Integer := Linker_Switches.Last;
3332 if Main_Project /= No_Project then
3334 if MLib.Tgt.Libraries_Are_Supported then
3335 Set_Libraries (Main_Project, There_Are_Libraries);
3338 if There_Are_Libraries then
3340 -- Add -L<lib_dir> -lgnarl -lgnat -Wl,-rpath,<lib_dir>
3342 Linker_Switches.Increment_Last;
3343 Linker_Switches.Table (Linker_Switches.Last) :=
3344 new String'("-L" & MLib.Utl.Lib_Directory);
3345 Linker_Switches.Increment_Last;
3346 Linker_Switches.Table (Linker_Switches.Last) :=
3347 new String'("-lgnarl");
3348 Linker_Switches.Increment_Last;
3349 Linker_Switches.Table (Linker_Switches.Last) :=
3350 new String'("-lgnat");
3353 Option : constant String_Access :=
3354 MLib.Tgt.Linker_Library_Path_Option
3355 (MLib.Utl.Lib_Directory);
3358 if Option /= null then
3359 Linker_Switches.Increment_Last;
3360 Linker_Switches.Table (Linker_Switches.Last) :=
3366 -- Put the object directories in ADA_OBJECTS_PATH
3368 Set_Ada_Paths (Main_Project, False);
3372 Args : Argument_List
3373 (Linker_Switches.First .. Linker_Switches.Last + 2);
3375 Last_Arg : Integer := Linker_Switches.First - 1;
3376 Skip : Boolean := False;
3379 -- Get all the linker switches
3381 for J in Linker_Switches.First .. Linker_Switches.Last loop
3385 elsif Non_Std_Executable
3386 and then Linker_Switches.Table (J).all = "-o"
3391 Last_Arg := Last_Arg + 1;
3392 Args (Last_Arg) := Linker_Switches.Table (J);
3397 -- And invoke the linker
3399 if Non_Std_Executable then
3400 Last_Arg := Last_Arg + 1;
3401 Args (Last_Arg) := new String'("-o");
3402 Last_Arg := Last_Arg + 1;
3404 new String'(Get_Name_String (Executable));
3405 Link (Main_ALI_File, Args (Args'First .. Last_Arg));
3410 Args (Args'First .. Last_Arg));
3415 Linker_Switches.Set_Last (Linker_Switches_Last);
3419 -- We go to here when we skip the bind and link steps.
3423 -- We go to the next main, if we did not process the last one
3425 if N_File < Osint.Number_Of_Files then
3426 Main_Source_File := Next_Main_Source;
3428 if Main_Project /= No_Project then
3430 -- Find the file name of the main unit
3433 Main_Source_File_Name : constant String :=
3434 Get_Name_String (Main_Source_File);
3436 Main_Unit_File_Name : constant String :=
3438 File_Name_Of_Library_Unit_Body
3439 (Name => Main_Source_File_Name,
3440 Project => Main_Project);
3443 -- We fail if we cannot find the main source file
3444 -- as an immediate source of the main project file.
3446 if Main_Unit_File_Name = "" then
3447 Fail ('"' & Main_Source_File_Name &
3448 """ is not a unit of project " &
3449 Project_File_Name.all & ".");
3452 -- Remove any directory information from the main
3453 -- source file name.
3456 Pos : Natural := Main_Unit_File_Name'Last;
3460 exit when Pos < Main_Unit_File_Name'First
3462 Main_Unit_File_Name (Pos) = Directory_Separator;
3466 Name_Len := Main_Unit_File_Name'Last - Pos;
3468 Name_Buffer (1 .. Name_Len) :=
3470 (Pos + 1 .. Main_Unit_File_Name'Last);
3472 Main_Source_File := Name_Find;
3478 end loop Multiple_Main_Loop;
3480 Exit_Program (E_Success);
3484 Osint.Fail ("*** bind failed.");
3486 when Compilation_Failed =>
3487 Exit_Program (E_Fatal);
3490 Osint.Fail ("*** link failed.");
3493 Write_Line (Exception_Information (X));
3494 Osint.Fail ("INTERNAL ERROR. Please report.");
3498 --------------------
3499 -- In_Ada_Lib_Dir --
3500 --------------------
3502 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean is
3503 D : constant Name_Id := Get_Directory (File);
3504 B : constant Byte := Get_Name_Table_Byte (D);
3507 return (B and Ada_Lib_Dir) /= 0;
3514 procedure Inform (N : Name_Id := No_Name; Msg : String) is
3516 Osint.Write_Program_Name;
3520 if N /= No_Name then
3536 First_Q_Initialization := False;
3538 Q.Set_Last (Q.First);
3545 procedure Initialize is
3546 Next_Arg : Positive;
3549 -- Override default initialization of Check_Object_Consistency
3550 -- since this is normally False for GNATBIND, but is True for
3551 -- GNATMAKE since we do not need to check source consistency
3552 -- again once GNATMAKE has looked at the sources to check.
3554 Opt.Check_Object_Consistency := True;
3556 -- Package initializations. The order of calls is important here.
3558 Output.Set_Standard_Error;
3559 Osint.Initialize (Osint.Make);
3562 Binder_Switches.Init;
3563 Linker_Switches.Init;
3573 Scan_Args : while Next_Arg <= Argument_Count loop
3574 Scan_Make_Arg (Argument (Next_Arg), And_Save => True);
3575 Next_Arg := Next_Arg + 1;
3578 if Usage_Requested then
3582 -- Test for trailing -o switch
3584 if Opt.Output_File_Name_Present
3585 and then not Output_File_Name_Seen
3587 Fail ("output file name missing after -o");
3590 if Project_File_Name /= null then
3592 -- A project file was specified by a -P switch
3594 if Opt.Verbose_Mode then
3596 Write_Str ("Parsing Project File """);
3597 Write_Str (Project_File_Name.all);
3602 -- Avoid looking in the current directory for ALI files
3604 -- Opt.Look_In_Primary_Dir := False;
3606 -- Set the project parsing verbosity to whatever was specified
3607 -- by a possible -vP switch.
3609 Prj.Pars.Set_Verbosity (To => Current_Verbosity);
3611 -- Parse the project file.
3612 -- If there is an error, Main_Project will still be No_Project.
3615 (Project => Main_Project,
3616 Project_File_Name => Project_File_Name.all);
3618 if Main_Project = No_Project then
3619 Fail ("""" & Project_File_Name.all &
3620 """ processing failed");
3623 if Opt.Verbose_Mode then
3625 Write_Str ("Parsing of Project File """);
3626 Write_Str (Project_File_Name.all);
3627 Write_Str (""" is finished.");
3631 -- We add the source directories and the object directories
3632 -- to the search paths.
3634 Add_Source_Directories (Main_Project);
3635 Add_Object_Directories (Main_Project);
3639 Osint.Add_Default_Search_Dirs;
3641 -- Mark the GNAT libraries if needed.
3643 -- Source file lookups should be cached for efficiency.
3644 -- Source files are not supposed to change.
3646 Osint.Source_File_Data (Cache => True);
3648 -- Read gnat.adc file to initialize Fname.UF
3650 Fname.UF.Initialize;
3653 Fname.SF.Read_Source_File_Name_Pragmas;
3656 when Err : SFN_Scan.Syntax_Error_In_GNAT_ADC =>
3657 Osint.Fail (Exception_Message (Err));
3661 -----------------------------------
3662 -- Insert_Project_Sources_Into_Q --
3663 -----------------------------------
3665 procedure Insert_Project_Sources
3666 (The_Project : Project_Id;
3669 Unit : Com.Unit_Data;
3673 -- For all the sources in the project files,
3675 for Id in Com.Units.First .. Com.Units.Last loop
3676 Unit := Com.Units.Table (Id);
3679 -- If there is a source for the body,
3681 if Unit.File_Names (Com.Body_Part).Name /= No_Name then
3683 -- And it is a source of the specified project
3685 if Unit.File_Names (Com.Body_Part).Project = The_Project then
3687 -- If we don't have a spec, we cannot consider the source
3688 -- if it is a subunit
3690 if Unit.File_Names (Com.Specification).Name = No_Name then
3692 Src_Ind : Source_File_Index;
3695 Src_Ind := Sinput.L.Load_Source_File
3696 (Unit.File_Names (Com.Body_Part).Name);
3698 -- If it is a subunit, discard it
3700 if Sinput.L.Source_File_Is_Subunit (Src_Ind) then
3704 Sfile := Unit.File_Names (Com.Body_Part).Name;
3709 Sfile := Unit.File_Names (Com.Body_Part).Name;
3713 elsif Unit.File_Names (Com.Specification).Name /= No_Name
3714 and then Unit.File_Names (Com.Specification).Project = The_Project
3716 -- If there is no source for the body, but there is a source
3717 -- for the spec, then we take this one.
3719 Sfile := Unit.File_Names (Com.Specification).Name;
3722 -- If Into_Q is True, we insert into the Q
3726 -- For the first source inserted into the Q, we need
3727 -- to initialize the Q, but not for the subsequent sources.
3729 if First_Q_Initialization then
3733 -- And of course, we only insert in the Q if the source
3736 if Sfile /= No_Name and then not Is_Marked (Sfile) then
3741 elsif Sfile /= No_Name then
3743 -- If Into_Q is False, we add the source as it it were
3744 -- specified on the command line.
3746 Osint.Add_File (Get_Name_String (Sfile));
3749 end Insert_Project_Sources;
3756 (Source_File : File_Name_Type;
3757 Source_Unit : Unit_Name_Type := No_Name)
3760 if Debug.Debug_Flag_Q then
3761 Write_Str (" Q := Q + [ ");
3762 Write_Name (Source_File);
3767 Q.Table (Q.Last).File := Source_File;
3768 Q.Table (Q.Last).Unit := Source_Unit;
3772 ----------------------------
3773 -- Is_External_Assignment --
3774 ----------------------------
3776 function Is_External_Assignment (Argv : String) return Boolean is
3777 Start : Positive := 3;
3778 Finish : Natural := Argv'Last;
3779 Equal_Pos : Natural;
3782 if Argv'Last < 5 then
3785 elsif Argv (3) = '"' then
3786 if Argv (Argv'Last) /= '"' or else Argv'Last < 7 then
3790 Finish := Argv'Last - 1;
3796 while Equal_Pos <= Finish and then Argv (Equal_Pos) /= '=' loop
3797 Equal_Pos := Equal_Pos + 1;
3800 if Equal_Pos = Start
3801 or else Equal_Pos >= Finish
3807 (External_Name => Argv (Start .. Equal_Pos - 1),
3808 Value => Argv (Equal_Pos + 1 .. Finish));
3811 end Is_External_Assignment;
3817 function Is_Marked (Source_File : File_Name_Type) return Boolean is
3819 return Get_Name_Table_Byte (Source_File) /= 0;
3826 procedure Link (ALI_File : File_Name_Type; Args : Argument_List) is
3827 Link_Args : Argument_List (Args'First .. Args'Last + 1);
3831 Link_Args (Args'Range) := Args;
3833 Get_Name_String (ALI_File);
3834 Link_Args (Args'Last + 1) := new String'(Name_Buffer (1 .. Name_Len));
3836 Display (Gnatlink.all, Link_Args);
3838 if Gnatlink_Path = null then
3839 Osint.Fail ("error, unable to locate " & Gnatlink.all);
3842 GNAT.OS_Lib.Spawn (Gnatlink_Path.all, Link_Args, Success);
3849 ---------------------------
3850 -- List_Bad_Compilations --
3851 ---------------------------
3853 procedure List_Bad_Compilations is
3855 for J in Bad_Compilation.First .. Bad_Compilation.Last loop
3856 if Bad_Compilation.Table (J).File = No_File then
3858 elsif not Bad_Compilation.Table (J).Found then
3859 Inform (Bad_Compilation.Table (J).File, "not found");
3861 Inform (Bad_Compilation.Table (J).File, "compilation error");
3864 end List_Bad_Compilations;
3870 procedure List_Depend is
3877 Line_Size : constant := 77;
3880 Set_Standard_Output;
3882 for A in ALIs.First .. ALIs.Last loop
3883 Lib_Name := ALIs.Table (A).Afile;
3885 -- We have to provide the full library file name in In_Place_Mode
3887 if Opt.In_Place_Mode then
3888 Lib_Name := Full_Lib_File_Name (Lib_Name);
3891 Obj_Name := Object_File_Name (Lib_Name);
3892 Write_Name (Obj_Name);
3895 Get_Name_String (Obj_Name);
3897 Line_Pos := Len + 2;
3899 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
3900 Src_Name := Sdep.Table (D).Sfile;
3902 if Is_Internal_File_Name (Src_Name)
3903 and then not Check_Readonly_Files
3907 if not Opt.Quiet_Output then
3908 Src_Name := Full_Source_Name (Src_Name);
3911 Get_Name_String (Src_Name);
3914 if Line_Pos + Len + 1 > Line_Size then
3920 Line_Pos := Line_Pos + Len + 1;
3923 Write_Name (Src_Name);
3937 procedure Mark (Source_File : File_Name_Type) is
3939 Set_Name_Table_Byte (Source_File, 1);
3946 procedure Mark_Dir_Path
3947 (Path : String_Access;
3948 Mark : Lib_Mark_Type)
3950 Dir : String_Access;
3953 if Path /= null then
3954 Osint.Get_Next_Dir_In_Path_Init (Path);
3957 Dir := Osint.Get_Next_Dir_In_Path (Path);
3958 exit when Dir = null;
3959 Mark_Directory (Dir.all, Mark);
3964 --------------------
3965 -- Mark_Directory --
3966 --------------------
3968 procedure Mark_Directory
3970 Mark : Lib_Mark_Type)
3976 -- Dir last character is supposed to be a directory separator.
3978 Name_Len := Dir'Length;
3979 Name_Buffer (1 .. Name_Len) := Dir;
3981 if not Is_Directory_Separator (Name_Buffer (Name_Len)) then
3982 Name_Len := Name_Len + 1;
3983 Name_Buffer (Name_Len) := Directory_Separator;
3986 -- Add flags to the already existing flags
3989 B := Get_Name_Table_Byte (N);
3990 Set_Name_Table_Byte (N, B or Mark);
3993 ----------------------
3994 -- Object_File_Name --
3995 ----------------------
3997 function Object_File_Name (Source : String) return String is
3998 Pos : Natural := Source'Last;
4001 while Pos >= Source'First and then
4002 Source (Pos) /= '.' loop
4006 if Pos >= Source'First then
4010 return Source (Source'First .. Pos) & Object_Suffix;
4011 end Object_File_Name;
4017 procedure Scan_Make_Arg (Argv : String; And_Save : Boolean) is
4019 pragma Assert (Argv'First = 1);
4021 if Argv'Length = 0 then
4025 -- If the previous switch has set the Output_File_Name_Present
4026 -- flag (that is we have seen a -o), then the next argument is
4027 -- the name of the output executable.
4029 if Opt.Output_File_Name_Present and then not Output_File_Name_Seen then
4030 Output_File_Name_Seen := True;
4032 if Argv (1) = Switch_Character or else Argv (1) = '-' then
4033 Fail ("output file name missing after -o");
4035 Add_Switch ("-o", Linker, And_Save => And_Save);
4037 -- Automatically add the executable suffix if it has not been
4038 -- specified explicitly.
4040 if Executable_Suffix'Length /= 0
4041 and then Argv (Argv'Last - Executable_Suffix'Length + 1
4042 .. Argv'Last) /= Executable_Suffix
4045 (Argv & Executable_Suffix,
4047 And_Save => And_Save);
4049 Add_Switch (Argv, Linker, And_Save => And_Save);
4053 -- Then check if we are dealing with a -cargs, -bargs or -largs
4055 elsif (Argv (1) = Switch_Character or else Argv (1) = '-')
4056 and then (Argv (2 .. Argv'Last) = "cargs"
4057 or else Argv (2 .. Argv'Last) = "bargs"
4058 or else Argv (2 .. Argv'Last) = "largs")
4060 if not File_Name_Seen then
4061 Fail ("-cargs, -bargs, -largs ",
4062 "must appear after unit or file name");
4066 when 'c' => Program_Args := Compiler;
4067 when 'b' => Program_Args := Binder;
4068 when 'l' => Program_Args := Linker;
4071 raise Program_Error;
4074 -- A special test is needed for the -o switch within a -largs
4075 -- since that is another way to specify the name of the final
4078 elsif Program_Args = Linker
4079 and then (Argv (1) = Switch_Character or else Argv (1) = '-')
4080 and then Argv (2 .. Argv'Last) = "o"
4082 Fail ("switch -o not allowed within a -largs. Use -o directly.");
4084 -- Check to see if we are reading switches after a -cargs,
4085 -- -bargs or -largs switch. If yes save it.
4087 elsif Program_Args /= None then
4089 -- Check to see if we are reading -I switches in order
4090 -- to take into account in the src & lib search directories.
4092 if Argv'Length > 2 and then Argv (1 .. 2) = "-I" then
4093 if Argv (3 .. Argv'Last) = "-" then
4094 Opt.Look_In_Primary_Dir := False;
4096 elsif Program_Args = Compiler then
4097 if Argv (3 .. Argv'Last) /= "-" then
4098 Add_Src_Search_Dir (Argv (3 .. Argv'Last));
4102 elsif Program_Args = Binder then
4103 Add_Lib_Search_Dir (Argv (3 .. Argv'Last));
4108 Add_Switch (Argv, Program_Args, And_Save => And_Save);
4110 -- Handle non-default compiler, binder, linker
4112 elsif Argv'Length > 2 and then Argv (1 .. 2) = "--" then
4114 and then Argv (1 .. 6) = "--GCC="
4117 Program_Args : Argument_List_Access :=
4118 Argument_String_To_List
4119 (Argv (7 .. Argv'Last));
4123 Saved_Gcc := new String'(Program_Args.all (1).all);
4125 Gcc := new String'(Program_Args.all (1).all);
4128 for J in 2 .. Program_Args.all'Last loop
4130 (Program_Args.all (J).all,
4132 And_Save => And_Save);
4136 elsif Argv'Length > 11
4137 and then Argv (1 .. 11) = "--GNATBIND="
4140 Program_Args : Argument_List_Access :=
4141 Argument_String_To_List
4142 (Argv (12 .. Argv'Last));
4146 Saved_Gnatbind := new String'(Program_Args.all (1).all);
4148 Gnatbind := new String'(Program_Args.all (1).all);
4151 for J in 2 .. Program_Args.all'Last loop
4153 (Program_Args.all (J).all, Binder, And_Save => And_Save);
4157 elsif Argv'Length > 11
4158 and then Argv (1 .. 11) = "--GNATLINK="
4161 Program_Args : Argument_List_Access :=
4162 Argument_String_To_List
4163 (Argv (12 .. Argv'Last));
4166 Saved_Gnatlink := new String'(Program_Args.all (1).all);
4168 Gnatlink := new String'(Program_Args.all (1).all);
4171 for J in 2 .. Program_Args.all'Last loop
4172 Add_Switch (Program_Args.all (J).all, Linker);
4177 Fail ("unknown switch: ", Argv);
4180 -- If we have seen a regular switch process it
4182 elsif Argv (1) = Switch_Character or else Argv (1) = '-' then
4184 if Argv'Length = 1 then
4185 Fail ("switch character cannot be followed by a blank");
4189 elsif Argv (2 .. Argv'Last) = "I-" then
4190 Opt.Look_In_Primary_Dir := False;
4192 -- Forbid -?- or -??- where ? is any character
4194 elsif (Argv'Length = 3 and then Argv (3) = '-')
4195 or else (Argv'Length = 4 and then Argv (4) = '-')
4197 Fail ("trailing ""-"" at the end of ", Argv, " forbidden.");
4201 elsif Argv (2) = 'I' then
4202 Add_Src_Search_Dir (Argv (3 .. Argv'Last));
4203 Add_Lib_Search_Dir (Argv (3 .. Argv'Last));
4204 Add_Switch (Argv, Compiler, And_Save => And_Save);
4205 Add_Switch ("-aO" & Argv (3 .. Argv'Last),
4207 And_Save => And_Save);
4209 -- No need to pass any source dir to the binder
4210 -- since gnatmake call it with the -x flag
4211 -- (ie do not check source time stamp)
4213 -- -aIdir (to gcc this is like a -I switch)
4215 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aI" then
4216 Add_Src_Search_Dir (Argv (4 .. Argv'Last));
4217 Add_Switch ("-I" & Argv (4 .. Argv'Last),
4219 And_Save => And_Save);
4223 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aO" then
4224 Add_Lib_Search_Dir (Argv (4 .. Argv'Last));
4225 Add_Switch (Argv, Binder, And_Save => And_Save);
4227 -- -aLdir (to gnatbind this is like a -aO switch)
4229 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aL" then
4230 Mark_Directory (Argv (4 .. Argv'Last), Ada_Lib_Dir);
4231 Add_Lib_Search_Dir (Argv (4 .. Argv'Last));
4232 Add_Switch ("-aO" & Argv (4 .. Argv'Last),
4234 And_Save => And_Save);
4236 -- -Adir (to gnatbind this is like a -aO switch, to gcc like a -I)
4238 elsif Argv (2) = 'A' then
4239 Mark_Directory (Argv (3 .. Argv'Last), Ada_Lib_Dir);
4240 Add_Src_Search_Dir (Argv (3 .. Argv'Last));
4241 Add_Lib_Search_Dir (Argv (3 .. Argv'Last));
4242 Add_Switch ("-I" & Argv (3 .. Argv'Last),
4244 And_Save => And_Save);
4245 Add_Switch ("-aO" & Argv (3 .. Argv'Last),
4247 And_Save => And_Save);
4251 elsif Argv (2) = 'L' then
4252 Add_Switch (Argv, Linker, And_Save => And_Save);
4254 -- For -gxxxxx,-pg : give the switch to both the compiler and the
4255 -- linker (except for -gnatxxx which is only for the compiler)
4258 (Argv (2) = 'g' and then (Argv'Last < 5
4259 or else Argv (2 .. 5) /= "gnat"))
4260 or else Argv (2 .. Argv'Last) = "pg"
4262 Add_Switch (Argv, Compiler, And_Save => And_Save);
4263 Add_Switch (Argv, Linker, And_Save => And_Save);
4267 elsif Argv (2) = 'd'
4268 and then Argv'Last = 2
4270 Opt.Display_Compilation_Progress := True;
4272 -- -j (need to save the result)
4274 elsif Argv (2) = 'j' then
4275 Scan_Make_Switches (Argv);
4278 Saved_Maximum_Processes := Maximum_Processes;
4283 elsif Argv (2) = 'm'
4284 and then Argv'Last = 2
4286 Opt.Minimal_Recompilation := True;
4290 elsif Argv (2) = 'u'
4291 and then Argv'Last = 2
4293 Unique_Compile := True;
4294 Opt.Compile_Only := True;
4295 Do_Bind_Step := False;
4296 Do_Link_Step := False;
4298 -- -Pprj (only once, and only on the command line)
4301 and then Argv (2) = 'P'
4303 if Project_File_Name /= null then
4304 Fail ("cannot have several project files specified");
4306 elsif not And_Save then
4308 -- It could be a tool other than gnatmake (i.e, gnatdist)
4309 -- or a -P switch inside a project file.
4312 ("either the tool is not ""project-aware"" or " &
4313 "a project file is specified inside a project file");
4316 Project_File_Name := new String' (Argv (3 .. Argv'Last));
4321 -- Since no object file is created, don't check object
4324 elsif Argv (2) = 'S'
4325 and then Argv'Last = 2
4327 Opt.Check_Object_Consistency := False;
4328 Add_Switch (Argv, Compiler, And_Save => And_Save);
4330 -- -vPx (verbosity of the parsing of the project files)
4333 and then Argv (2 .. 3) = "vP"
4334 and then Argv (4) in '0' .. '2'
4339 Current_Verbosity := Prj.Default;
4341 Current_Verbosity := Prj.Medium;
4343 Current_Verbosity := Prj.High;
4349 -- -Wx (need to save the result)
4351 elsif Argv (2) = 'W' then
4352 Scan_Make_Switches (Argv);
4355 Saved_WC_Encoding_Method := Wide_Character_Encoding_Method;
4356 Saved_WC_Encoding_Method_Set := True;
4359 -- -Xext=val (External assignment)
4361 elsif Argv (2) = 'X'
4362 and then Is_External_Assignment (Argv)
4364 -- Is_External_Assignment has side effects
4365 -- when it returns True;
4369 -- If -gnath is present, then generate the usage information
4370 -- right now for the compiler, and do not pass this option
4371 -- on to the compiler calls.
4373 elsif Argv = "-gnath" then
4376 -- If -gnatc is specified, make sure the bind step and the link
4377 -- step are not executed.
4379 elsif Argv'Length >= 6 and then Argv (2 .. 6) = "gnatc" then
4381 -- If -gnatc is specified, make sure the bind step and the link
4382 -- step are not executed.
4384 Add_Switch (Argv, Compiler, And_Save => And_Save);
4385 Opt.Operating_Mode := Opt.Check_Semantics;
4386 Opt.Check_Object_Consistency := False;
4387 Opt.Compile_Only := True;
4388 Do_Bind_Step := False;
4389 Do_Link_Step := False;
4391 elsif Argv (2 .. Argv'Last) = "nostdlib" then
4393 -- Don't pass -nostdlib to gnatlink, it will disable
4394 -- linking with all standard library files.
4396 Opt.No_Stdlib := True;
4397 Add_Switch (Argv, Binder, And_Save => And_Save);
4399 elsif Argv (2 .. Argv'Last) = "nostdinc" then
4401 -- Pass -nostdinv to the Compiler and to gnatbind
4403 Opt.No_Stdinc := True;
4404 Add_Switch (Argv, Compiler, And_Save => And_Save);
4405 Add_Switch (Argv, Binder, And_Save => And_Save);
4407 -- By default all switches with more than one character
4408 -- or one character switches which are not in 'a' .. 'z'
4409 -- (except 'M') are passed to the compiler, unless we are dealing
4410 -- with a debug switch (starts with 'd')
4412 elsif Argv (2) /= 'd'
4413 and then Argv (2 .. Argv'Last) /= "M"
4414 and then (Argv'Length > 2 or else Argv (2) not in 'a' .. 'z')
4416 Add_Switch (Argv, Compiler, And_Save => And_Save);
4418 -- All other options are handled by Scan_Make_Switches
4421 Scan_Make_Switches (Argv);
4424 -- If not a switch it must be a file name
4427 File_Name_Seen := True;
4428 Set_Main_File_Name (Argv);
4436 procedure Set_Ada_Paths
4437 (For_Project : Prj.Project_Id;
4438 Including_Libraries : Boolean)
4440 New_Ada_Include_Path : constant String_Access :=
4441 Prj.Env.Ada_Include_Path (For_Project);
4443 New_Ada_Objects_Path : constant String_Access :=
4444 Prj.Env.Ada_Objects_Path
4445 (For_Project, Including_Libraries);
4448 -- If ADA_INCLUDE_PATH needs to be changed (we are not using the same
4449 -- project file), set the new ADA_INCLUDE_PATH
4451 if New_Ada_Include_Path /= Current_Ada_Include_Path then
4452 Current_Ada_Include_Path := New_Ada_Include_Path;
4454 if Original_Ada_Include_Path'Length = 0 then
4455 Setenv ("ADA_INCLUDE_PATH",
4456 New_Ada_Include_Path.all);
4459 -- If there existed an ADA_INCLUDE_PATH at the invocation of
4460 -- gnatmake, concatenate new ADA_INCLUDE_PATH with the original.
4462 Setenv ("ADA_INCLUDE_PATH",
4463 Original_Ada_Include_Path.all &
4465 New_Ada_Include_Path.all);
4468 if Opt.Verbose_Mode then
4470 Include_Path : constant String_Access :=
4471 Getenv ("ADA_INCLUDE_PATH");
4474 -- Display the new ADA_INCLUDE_PATH
4476 Write_Str ("ADA_INCLUDE_PATH = """);
4478 (S => Include_Path.all,
4479 Max_Length => Max_Line_Length,
4480 Separator => Path_Separator);
4487 -- If ADA_OBJECTS_PATH needs to be changed (we are not using the same
4488 -- project file), set the new ADA_OBJECTS_PATH
4490 if New_Ada_Objects_Path /= Current_Ada_Objects_Path then
4491 Current_Ada_Objects_Path := New_Ada_Objects_Path;
4493 if Original_Ada_Objects_Path'Length = 0 then
4494 Setenv ("ADA_OBJECTS_PATH",
4495 New_Ada_Objects_Path.all);
4498 -- If there existed an ADA_OBJECTS_PATH at the invocation of
4499 -- gnatmake, concatenate new ADA_OBJECTS_PATH with the original.
4501 Setenv ("ADA_OBJECTS_PATH",
4502 Original_Ada_Objects_Path.all &
4504 New_Ada_Objects_Path.all);
4507 if Opt.Verbose_Mode then
4509 Objects_Path : constant String_Access :=
4510 Getenv ("ADA_OBJECTS_PATH");
4513 -- Display the new ADA_OBJECTS_PATH
4515 Write_Str ("ADA_OBJECTS_PATH = """);
4517 (S => Objects_Path.all,
4518 Max_Length => Max_Line_Length,
4519 Separator => Path_Separator);
4528 ---------------------
4529 -- Set_Library_For --
4530 ---------------------
4532 procedure Set_Library_For
4533 (Project : Project_Id;
4534 There_Are_Libraries : in out Boolean)
4537 -- Case of library project
4539 if Projects.Table (Project).Library then
4540 There_Are_Libraries := True;
4542 -- Add the -L switch
4544 Linker_Switches.Increment_Last;
4545 Linker_Switches.Table (Linker_Switches.Last) :=
4548 (Projects.Table (Project).Library_Dir));
4550 -- Add the -l switch
4552 Linker_Switches.Increment_Last;
4553 Linker_Switches.Table (Linker_Switches.Last) :=
4556 (Projects.Table (Project).Library_Name));
4558 -- Add the Wl,-rpath switch if library non static
4560 if Projects.Table (Project).Library_Kind /= Static then
4562 Option : constant String_Access :=
4563 MLib.Tgt.Linker_Library_Path_Option
4565 (Projects.Table (Project).Library_Dir));
4568 if Option /= null then
4569 Linker_Switches.Increment_Last;
4570 Linker_Switches.Table (Linker_Switches.Last) :=
4579 end Set_Library_For;
4585 function Switches_Of
4586 (Source_File : Name_Id;
4587 Source_File_Name : String;
4588 Naming : Naming_Data;
4589 In_Package : Package_Id;
4590 Allow_ALI : Boolean)
4591 return Variable_Value
4593 Switches : Variable_Value;
4595 Defaults : constant Array_Element_Id :=
4597 (Name => Name_Default_Switches,
4599 Packages.Table (In_Package).Decl.Arrays);
4601 Switches_Array : constant Array_Element_Id :=
4603 (Name => Name_Switches,
4605 Packages.Table (In_Package).Decl.Arrays);
4610 (Index => Source_File,
4611 In_Array => Switches_Array);
4613 if Switches = Nil_Variable_Value then
4615 Name : String (1 .. Source_File_Name'Length + 3);
4616 Last : Positive := Source_File_Name'Length;
4617 Spec_Suffix : constant String :=
4618 Get_Name_String (Naming.Current_Spec_Suffix);
4619 Impl_Suffix : constant String :=
4620 Get_Name_String (Naming.Current_Impl_Suffix);
4621 Truncated : Boolean := False;
4624 Name (1 .. Last) := Source_File_Name;
4626 if Last > Impl_Suffix'Length
4627 and then Name (Last - Impl_Suffix'Length + 1 .. Last) =
4631 Last := Last - Impl_Suffix'Length;
4635 and then Last > Spec_Suffix'Length
4636 and then Name (Last - Spec_Suffix'Length + 1 .. Last) =
4640 Last := Last - Spec_Suffix'Length;
4645 Name_Buffer (1 .. Name_Len) := Name (1 .. Last);
4648 (Index => Name_Find,
4649 In_Array => Switches_Array);
4651 if Switches = Nil_Variable_Value then
4652 Last := Source_File_Name'Length;
4654 while Name (Last) /= '.' loop
4658 Name (Last + 1 .. Last + 3) := "ali";
4659 Name_Len := Last + 3;
4660 Name_Buffer (1 .. Name_Len) := Name (1 .. Name_Len);
4663 (Index => Name_Find,
4664 In_Array => Switches_Array);
4670 if Switches = Nil_Variable_Value then
4671 Switches := Prj.Util.Value_Of
4672 (Index => Name_Ada, In_Array => Defaults);
4678 ---------------------------
4679 -- Test_If_Relative_Path --
4680 ---------------------------
4682 procedure Test_If_Relative_Path (Switch : String_Access) is
4684 if Switch /= null then
4687 Sw : String (1 .. Switch'Length);
4693 if Sw (1) = '-' then
4695 and then (Sw (2) = 'A'
4696 or else Sw (2) = 'I'
4697 or else Sw (2) = 'L')
4705 elsif Sw'Length >= 4
4706 and then (Sw (2 .. 3) = "aL"
4707 or else Sw (2 .. 3) = "aO"
4708 or else Sw (2 .. 3) = "aI")
4716 if not Is_Absolute_Path (Sw (Start .. Sw'Last)) then
4717 Fail ("relative search path switches (""" &
4718 Sw & """) are not allowed when using project files");
4723 end Test_If_Relative_Path;
4729 procedure Unmark (Source_File : File_Name_Type) is
4731 Set_Name_Table_Byte (Source_File, 0);
4738 procedure Verbose_Msg
4741 N2 : Name_Id := No_Name;
4743 Prefix : String := " -> ")
4746 if not Opt.Verbose_Mode then
4756 if N2 /= No_Name then