1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2002 Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Ada.Exceptions; use Ada.Exceptions;
28 with Ada.Command_Line; use Ada.Command_Line;
30 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
33 with ALI.Util; use ALI.Util;
36 with Fname; use Fname;
37 with Fname.SF; use Fname.SF;
38 with Fname.UF; use Fname.UF;
39 with Gnatvsn; use Gnatvsn;
40 with Hostparm; use Hostparm;
45 with Namet; use Namet;
47 with Osint.M; use Osint.M;
48 with Osint; use Osint;
50 with Output; use Output;
59 with Snames; use Snames;
60 with Stringt; use Stringt;
61 with Switch; use Switch;
62 with Switch.M; use Switch.M;
65 with System.WCh_Con; use System.WCh_Con;
70 -- Make control characters visible
72 Standard_Library_Package_Body_Name : constant String := "s-stalib.adb";
73 -- Every program depends on this package, that must then be checked,
74 -- especially when -f and -a are used.
76 -------------------------
77 -- Note on terminology --
78 -------------------------
80 -- In this program, we use the phrase "termination" of a file name to
81 -- refer to the suffix that appears after the unit name portion. Very
82 -- often this is simply the extension, but in some cases, the sequence
83 -- may be more complex, for example in main.1.ada, the termination in
84 -- this name is ".1.ada" and in main_.ada the termination is "_.ada".
86 -------------------------------------
87 -- Queue (Q) Manipulation Routines --
88 -------------------------------------
90 -- The Q is used in Compile_Sources below. Its implementation uses the
91 -- GNAT generic package Table (basically an extensible array). Q_Front
92 -- points to the first valid element in the Q, whereas Q.First is the first
93 -- element ever enqueued, while Q.Last - 1 is the last element in the Q.
95 -- +---+--------------+---+---+---+-----------+---+--------
96 -- Q | | ........ | | | | ....... | |
97 -- +---+--------------+---+---+---+-----------+---+--------
99 -- Q.First Q_Front Q.Last - 1
101 -- The elements comprised between Q.First and Q_Front - 1 are the
102 -- elements that have been enqueued and then dequeued, while the
103 -- elements between Q_Front and Q.Last - 1 are the elements currently
104 -- in the Q. When the Q is initialized Q_Front = Q.First = Q.Last.
105 -- After Compile_Sources has terminated its execution, Q_Front = Q.Last
106 -- and the elements contained between Q.Front and Q.Last-1 are those that
107 -- were explored and thus marked by Compile_Sources. Whenever the Q is
108 -- reinitialized, the elements between Q.First and Q.Last - 1 are unmarked.
111 -- Must be called to (re)initialize the Q.
114 (Source_File : File_Name_Type;
115 Source_Unit : Unit_Name_Type := No_Name);
116 -- Inserts Source_File at the end of Q. Provide Source_Unit when
117 -- possible for external use (gnatdist).
119 function Empty_Q return Boolean;
120 -- Returns True if Q is empty.
122 procedure Extract_From_Q
123 (Source_File : out File_Name_Type;
124 Source_Unit : out Unit_Name_Type);
125 -- Extracts the first element from the Q.
127 procedure Insert_Project_Sources
128 (The_Project : Project_Id;
130 -- If Into_Q is True, insert all sources of the project file that are not
131 -- already marked into the Q. If Into_Q is False, call Osint.Add_File for
132 -- all sources of the project file.
134 First_Q_Initialization : Boolean := True;
135 -- Will be set to false after Init_Q has been called once.
138 -- Points to the first valid element in the Q.
140 Unique_Compile : Boolean := False;
142 type Q_Record is record
143 File : File_Name_Type;
144 Unit : Unit_Name_Type;
146 -- File is the name of the file to compile. Unit is for gnatdist
147 -- use in order to easily get the unit name of a file to compile
148 -- when its name is krunched or declared in gnat.adc.
150 package Q is new Table.Table (
151 Table_Component_Type => Q_Record,
152 Table_Index_Type => Natural,
153 Table_Low_Bound => 0,
154 Table_Initial => 4000,
155 Table_Increment => 100,
156 Table_Name => "Make.Q");
157 -- This is the actual Q.
159 -- The following instantiations and variables are necessary to save what
160 -- is found on the command line, in case there is a project file specified.
162 package Saved_Gcc_Switches is new Table.Table (
163 Table_Component_Type => String_Access,
164 Table_Index_Type => Integer,
165 Table_Low_Bound => 1,
167 Table_Increment => 100,
168 Table_Name => "Make.Saved_Gcc_Switches");
170 package Saved_Binder_Switches is new Table.Table (
171 Table_Component_Type => String_Access,
172 Table_Index_Type => Integer,
173 Table_Low_Bound => 1,
175 Table_Increment => 100,
176 Table_Name => "Make.Saved_Binder_Switches");
178 package Saved_Linker_Switches is new Table.Table
179 (Table_Component_Type => String_Access,
180 Table_Index_Type => Integer,
181 Table_Low_Bound => 1,
183 Table_Increment => 100,
184 Table_Name => "Make.Saved_Linker_Switches");
186 package Saved_Make_Switches is new Table.Table
187 (Table_Component_Type => String_Access,
188 Table_Index_Type => Integer,
189 Table_Low_Bound => 1,
191 Table_Increment => 100,
192 Table_Name => "Make.Saved_Make_Switches");
194 package Switches_To_Check is new Table.Table (
195 Table_Component_Type => String_Access,
196 Table_Index_Type => Integer,
197 Table_Low_Bound => 1,
199 Table_Increment => 100,
200 Table_Name => "Make.Switches_To_Check");
202 Normalized_Switches : Argument_List_Access := new Argument_List (1 .. 10);
203 Last_Norm_Switch : Natural := 0;
205 Saved_Maximum_Processes : Natural := 0;
206 Saved_WC_Encoding_Method : WC_Encoding_Method := WC_Encoding_Method'First;
207 Saved_WC_Encoding_Method_Set : Boolean := False;
209 type Arg_List_Ref is access Argument_List;
210 The_Saved_Gcc_Switches : Arg_List_Ref;
212 Project_File_Name : String_Access := null;
213 Current_Verbosity : Prj.Verbosity := Prj.Default;
214 Main_Project : Prj.Project_Id := No_Project;
216 procedure Add_Source_Dir (N : String);
217 -- Call Add_Src_Search_Dir.
218 -- Output one line when in verbose mode.
220 procedure Add_Source_Directories is
221 new Prj.Env.For_All_Source_Dirs (Action => Add_Source_Dir);
223 procedure Add_Object_Dir (N : String);
224 -- Call Add_Lib_Search_Dir.
225 -- Output one line when in verbose mode.
227 procedure Add_Object_Directories is
228 new Prj.Env.For_All_Object_Dirs (Action => Add_Object_Dir);
230 type Bad_Compilation_Info is record
231 File : File_Name_Type;
232 Unit : Unit_Name_Type;
235 -- File is the name of the file for which a compilation failed.
236 -- Unit is for gnatdist use in order to easily get the unit name
237 -- of a file when its name is krunched or declared in gnat.adc.
238 -- Found is False if the compilation failed because the file could
241 package Bad_Compilation is new Table.Table (
242 Table_Component_Type => Bad_Compilation_Info,
243 Table_Index_Type => Natural,
244 Table_Low_Bound => 1,
246 Table_Increment => 100,
247 Table_Name => "Make.Bad_Compilation");
248 -- Full name of all the source files for which compilation fails.
250 Original_Ada_Include_Path : constant String_Access :=
251 Getenv ("ADA_INCLUDE_PATH");
252 Original_Ada_Objects_Path : constant String_Access :=
253 Getenv ("ADA_OBJECTS_PATH");
254 Current_Ada_Include_Path : String_Access := null;
255 Current_Ada_Objects_Path : String_Access := null;
257 Max_Line_Length : constant := 127;
258 -- Maximum number of characters per line, when displaying a path
260 Do_Compile_Step : Boolean := True;
261 Do_Bind_Step : Boolean := True;
262 Do_Link_Step : Boolean := True;
263 -- Flags to indicate what step should be executed.
264 -- Can be set to False with the switches -c, -b and -l.
265 -- These flags are reset to True for each invokation of procedure Gnatmake.
267 ----------------------
268 -- Marking Routines --
269 ----------------------
271 procedure Mark (Source_File : File_Name_Type);
272 -- Mark Source_File. Marking is used to signal that Source_File has
273 -- already been inserted in the Q.
275 function Is_Marked (Source_File : File_Name_Type) return Boolean;
276 -- Returns True if Source_File was previously marked.
282 procedure List_Depend;
283 -- Prints to standard output the list of object dependencies. This list
284 -- can be used directly in a Makefile. A call to Compile_Sources must
285 -- precede the call to List_Depend. Also because this routine uses the
286 -- ALI files that were originally loaded and scanned by Compile_Sources,
287 -- no additional ALI files should be scanned between the two calls (i.e.
288 -- between the call to Compile_Sources and List_Depend.)
290 procedure Inform (N : Name_Id := No_Name; Msg : String);
291 -- Prints out the program name followed by a colon, N and S.
293 procedure List_Bad_Compilations;
294 -- Prints out the list of all files for which the compilation failed.
296 procedure Verbose_Msg
299 N2 : Name_Id := No_Name;
301 Prefix : String := " -> ");
302 -- If the verbose flag (Verbose_Mode) is set then print Prefix to standard
303 -- output followed by N1 and S1. If N2 /= No_Name then N2 is then printed
304 -- after S1. S2 is printed last. Both N1 and N2 are printed in quotation
307 Usage_Needed : Boolean := True;
308 -- Flag used to make sure Makeusg is call at most once
311 -- Call Makeusg, if Usage_Needed is True.
312 -- Set Usage_Needed to False.
314 -----------------------
315 -- Gnatmake Routines --
316 -----------------------
318 subtype Lib_Mark_Type is Byte;
319 -- ??? this needs a comment
321 Ada_Lib_Dir : constant Lib_Mark_Type := 1;
322 -- ??? this needs a comment
324 -- Note that the notion of GNAT lib dir is no longer used. The code
325 -- related to it has not been removed to give an idea on how to use
326 -- the directory prefix marking mechanism.
328 -- An Ada library directory is a directory containing ali and object
329 -- files but no source files for the bodies (the specs can be in the
330 -- same or some other directory). These directories are specified
331 -- in the Gnatmake command line with the switch "-Adir" (to specify the
332 -- spec location -Idir cab be used). Gnatmake skips the missing sources
333 -- whose ali are in Ada library directories. For an explanation of why
334 -- Gnatmake behaves that way, see the spec of Make.Compile_Sources.
335 -- The directory lookup penalty is incurred every single time this
336 -- routine is called.
338 function Is_External_Assignment (Argv : String) return Boolean;
339 -- Verify that an external assignment switch is syntactically correct.
342 -- -X"name=other value"
343 -- Assumptions: 'First = 1, Argv (1 .. 2) = "-X"
344 -- When this function returns True, the external assignment has
345 -- been entered by a call to Prj.Ext.Add, so that in a project
346 -- file, External ("name") will return "value".
348 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean;
349 -- Get directory prefix of this file and get lib mark stored in name
350 -- table for this directory. Then check if an Ada lib mark has been set.
352 procedure Mark_Directory
354 Mark : Lib_Mark_Type);
355 -- Store Dir in name table and set lib mark as name info to identify
358 function Object_File_Name (Source : String) return String;
359 -- Returns the object file name suitable for switch -o.
361 procedure Set_Ada_Paths
362 (For_Project : Prj.Project_Id;
363 Including_Libraries : Boolean);
364 -- Set, if necessary, env. variables ADA_INCLUDE_PATH and
367 -- Note: this will modify these environment variables only
368 -- for the current gnatmake process and all of its children
369 -- (invocations of the compiler, the binder and the linker).
370 -- The caller process ADA_INCLUDE_PATH and ADA_OBJECTS_PATH are
374 (Source_File : Name_Id;
375 Source_File_Name : String;
376 Naming : Naming_Data;
377 In_Package : Package_Id;
379 return Variable_Value;
380 -- Return the switches for the source file in the specified package
381 -- of a project file. If the Source_File ends with a standard GNAT
382 -- extension (".ads" or ".adb"), try first the full name, then the
383 -- name without the extension, then, if Allow_ALI is True, the name with
384 -- the extension ".ali". If there is no switches for either names, try the
385 -- default switches for Ada. If all failed, return No_Variable_Value.
387 procedure Test_If_Relative_Path
388 (Switch : in out String_Access;
389 Parent : String_Access);
390 -- Test if Switch is a relative search path switch.
391 -- If it is, fail if Parent is null, otherwise prepend the path with
392 -- Parent. This subprogram is only called when using project files.
394 procedure Set_Library_For
395 (Project : Project_Id;
396 There_Are_Libraries : in out Boolean);
397 -- If Project is a library project, add the correct
398 -- -L and -l switches to the linker invocation.
400 procedure Set_Libraries is
401 new For_Every_Project_Imported (Boolean, Set_Library_For);
402 -- Add the -L and -l switches to the linker for all
403 -- of the library projects.
405 ----------------------------------------------------
406 -- Compiler, Binder & Linker Data and Subprograms --
407 ----------------------------------------------------
409 Gcc : String_Access := Program_Name ("gcc");
410 Gnatbind : String_Access := Program_Name ("gnatbind");
411 Gnatlink : String_Access := Program_Name ("gnatlink");
412 -- Default compiler, binder, linker programs
414 Saved_Gcc : String_Access := null;
415 Saved_Gnatbind : String_Access := null;
416 Saved_Gnatlink : String_Access := null;
417 -- Given by the command line. Will be used, if non null.
419 Gcc_Path : String_Access :=
420 GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
421 Gnatbind_Path : String_Access :=
422 GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
423 Gnatlink_Path : String_Access :=
424 GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
425 -- Path for compiler, binder, linker programs, defaulted now for gnatdist.
426 -- Changed later if overridden on command line.
428 Comp_Flag : constant String_Access := new String'("-c");
429 Output_Flag : constant String_Access := new String'("-o");
430 Ada_Flag_1 : constant String_Access := new String'("-x");
431 Ada_Flag_2 : constant String_Access := new String'("ada");
432 No_gnat_adc : constant String_Access := new String'("-gnatA");
433 GNAT_Flag : constant String_Access := new String'("-gnatpg");
434 Do_Not_Check_Flag : constant String_Access := new String'("-x");
436 Object_Suffix : constant String := Get_Object_Suffix.all;
437 Executable_Suffix : constant String := Get_Executable_Suffix.all;
439 Syntax_Only : Boolean := False;
440 -- Set to True when compiling with -gnats
442 Display_Executed_Programs : Boolean := True;
443 -- Set to True if name of commands should be output on stderr.
445 Output_File_Name_Seen : Boolean := False;
446 -- Set to True after having scanned the file_name for
447 -- switch "-o file_name"
449 type Make_Program_Type is (None, Compiler, Binder, Linker);
451 Program_Args : Make_Program_Type := None;
452 -- Used to indicate if we are scanning gnatmake, gcc, gnatbind, or gnatbind
453 -- options within the gnatmake command line.
454 -- Used in Scan_Make_Arg only, but must be a global variable.
456 procedure Add_Switches
457 (The_Package : Package_Id;
459 Program : Make_Program_Type);
462 Program : Make_Program_Type;
463 Append_Switch : Boolean := True;
464 And_Save : Boolean := True);
467 Program : Make_Program_Type;
468 Append_Switch : Boolean := True;
469 And_Save : Boolean := True);
470 -- Make invokes one of three programs (the compiler, the binder or the
471 -- linker). For the sake of convenience, some program specific switches
472 -- can be passed directly on the gnatmake commande line. This procedure
473 -- records these switches so that gnamake can pass them to the right
474 -- program. S is the switch to be added at the end of the command line
475 -- for Program if Append_Switch is True. If Append_Switch is False S is
476 -- added at the beginning of the command line.
479 (Lib_File : File_Name_Type;
481 O_File : out File_Name_Type;
482 O_Stamp : out Time_Stamp_Type);
483 -- Determines whether the library file Lib_File is up-to-date or not. The
484 -- full name (with path information) of the object file corresponding to
485 -- Lib_File is returned in O_File. Its time stamp is saved in O_Stamp.
486 -- ALI is the ALI_Id corresponding to Lib_File. If Lib_File in not
487 -- up-to-date, then the corresponding source file needs to be recompiled.
488 -- In this case ALI = No_ALI_Id.
490 procedure Check_Linker_Options
491 (E_Stamp : Time_Stamp_Type;
492 O_File : out File_Name_Type;
493 O_Stamp : out Time_Stamp_Type);
494 -- Checks all linker options for linker files that are newer
495 -- than E_Stamp. If such objects are found, the youngest object
496 -- is returned in O_File and its stamp in O_Stamp.
498 -- If no obsolete linker files were found, the first missing
499 -- linker file is returned in O_File and O_Stamp is empty.
500 -- Otherwise O_File is No_File.
502 procedure Display (Program : String; Args : Argument_List);
503 -- Displays Program followed by the arguments in Args if variable
504 -- Display_Executed_Programs is set. The lower bound of Args must be 1.
506 type Temp_File_Names is array (Positive range <>) of Temp_File_Name;
508 type Temp_Files_Ptr is access Temp_File_Names;
510 The_Mapping_File_Names : Temp_Files_Ptr;
511 Last_Mapping_File_Name : Natural := 0;
513 procedure Delete_Mapping_Files;
514 -- Delete all temporary mapping files
516 procedure Init_Mapping_File (File_Name : in out Temp_File_Name);
517 -- Create a new temporary mapping file, and fill it with the project file
518 -- mappings, when using project file(s)
524 procedure Add_Object_Dir (N : String) is
526 Add_Lib_Search_Dir (N);
528 if Opt.Verbose_Mode then
529 Write_Str ("Adding object directory """);
540 procedure Add_Source_Dir (N : String) is
542 Add_Src_Search_Dir (N);
544 if Opt.Verbose_Mode then
545 Write_Str ("Adding source directory """);
558 Program : Make_Program_Type;
559 Append_Switch : Boolean := True;
560 And_Save : Boolean := True)
563 with package T is new Table.Table (<>);
564 procedure Generic_Position (New_Position : out Integer);
565 -- Generic procedure that chooses a position for S in T at the
566 -- beginning or the end, depending on the boolean Append_Switch.
569 ----------------------
570 -- Generic_Position --
571 ----------------------
573 procedure Generic_Position (New_Position : out Integer) is
577 if Append_Switch then
578 New_Position := Integer (T.Last);
580 for J in reverse T.Table_Index_Type'Succ (T.First) .. T.Last loop
581 T.Table (J) := T.Table (T.Table_Index_Type'Pred (J));
584 New_Position := Integer (T.First);
586 end Generic_Position;
588 procedure Gcc_Switches_Pos is new Generic_Position (Gcc_Switches);
589 procedure Binder_Switches_Pos is new Generic_Position (Binder_Switches);
590 procedure Linker_Switches_Pos is new Generic_Position (Linker_Switches);
592 procedure Saved_Gcc_Switches_Pos is new
593 Generic_Position (Saved_Gcc_Switches);
595 procedure Saved_Binder_Switches_Pos is new
596 Generic_Position (Saved_Binder_Switches);
598 procedure Saved_Linker_Switches_Pos is new
599 Generic_Position (Saved_Linker_Switches);
601 New_Position : Integer;
603 -- Start of processing for Add_Switch
609 Saved_Gcc_Switches_Pos (New_Position);
610 Saved_Gcc_Switches.Table (New_Position) := S;
613 Saved_Binder_Switches_Pos (New_Position);
614 Saved_Binder_Switches.Table (New_Position) := S;
617 Saved_Linker_Switches_Pos (New_Position);
618 Saved_Linker_Switches.Table (New_Position) := S;
627 Gcc_Switches_Pos (New_Position);
628 Gcc_Switches.Table (New_Position) := S;
631 Binder_Switches_Pos (New_Position);
632 Binder_Switches.Table (New_Position) := S;
635 Linker_Switches_Pos (New_Position);
636 Linker_Switches.Table (New_Position) := S;
646 Program : Make_Program_Type;
647 Append_Switch : Boolean := True;
648 And_Save : Boolean := True)
651 Add_Switch (S => new String'(S),
653 Append_Switch => Append_Switch,
654 And_Save => And_Save);
661 procedure Add_Switches
662 (The_Package : Package_Id;
664 Program : Make_Program_Type)
666 Switches : Variable_Value;
667 Switch_List : String_List_Id;
668 Element : String_Element;
671 if File_Name'Length > 0 then
672 Name_Len := File_Name'Length;
673 Name_Buffer (1 .. Name_Len) := File_Name;
676 (Source_File => Name_Find,
677 Source_File_Name => File_Name,
678 Naming => Projects.Table (Main_Project).Naming,
679 In_Package => The_Package,
681 Program = Binder or else Program = Linker);
683 case Switches.Kind is
688 Program_Args := Program;
690 Switch_List := Switches.Values;
692 while Switch_List /= Nil_String loop
693 Element := String_Elements.Table (Switch_List);
694 String_To_Name_Buffer (Element.Value);
697 if Opt.Verbose_Mode then
698 Write_Str (" Adding ");
699 Write_Line (Name_Buffer (1 .. Name_Len));
703 (Name_Buffer (1 .. Name_Len),
707 Switch_List := Element.Next;
711 Program_Args := Program;
712 String_To_Name_Buffer (Switches.Value);
715 if Opt.Verbose_Mode then
716 Write_Str (" Adding ");
717 Write_Line (Name_Buffer (1 .. Name_Len));
721 (Name_Buffer (1 .. Name_Len), And_Save => False);
731 procedure Bind (ALI_File : File_Name_Type; Args : Argument_List) is
732 Bind_Args : Argument_List (1 .. Args'Last + 2);
737 pragma Assert (Args'First = 1);
739 -- Optimize the simple case where the gnatbind command line looks like
740 -- gnatbind -aO. -I- file.ali --into-> gnatbind file.adb
743 and then Args (Args'First).all = "-aO" & Normalized_CWD
744 and then Args (Args'Last).all = "-I-"
745 and then ALI_File = Strip_Directory (ALI_File)
747 Bind_Last := Args'First - 1;
750 Bind_Last := Args'Last;
751 Bind_Args (Args'Range) := Args;
754 -- It is completely pointless to re-check source file time stamps.
755 -- This has been done already by gnatmake
757 Bind_Last := Bind_Last + 1;
758 Bind_Args (Bind_Last) := Do_Not_Check_Flag;
760 Get_Name_String (ALI_File);
762 Bind_Last := Bind_Last + 1;
763 Bind_Args (Bind_Last) := new String'(Name_Buffer (1 .. Name_Len));
765 GNAT.OS_Lib.Normalize_Arguments (Bind_Args (Args'First .. Bind_Last));
767 Display (Gnatbind.all, Bind_Args (Args'First .. Bind_Last));
769 if Gnatbind_Path = null then
770 Osint.Fail ("error, unable to locate " & Gnatbind.all);
774 (Gnatbind_Path.all, Bind_Args (Args'First .. Bind_Last), Success);
786 (Lib_File : File_Name_Type;
788 O_File : out File_Name_Type;
789 O_Stamp : out Time_Stamp_Type)
791 function First_New_Spec (A : ALI_Id) return File_Name_Type;
792 -- Looks in the with table entries of A and returns the spec file name
793 -- of the first withed unit (subprogram) for which no spec existed when
794 -- A was generated but for which there exists one now, implying that A
795 -- is now obsolete. If no such unit is found No_File is returned.
796 -- Otherwise the spec file name of the unit is returned.
798 -- **WARNING** in the event of Uname format modifications, one *MUST*
799 -- make sure this function is also updated.
801 -- Note: This function should really be in ali.adb and use Uname
802 -- services, but this causes the whole compiler to be dragged along
803 -- for gnatbind and gnatmake.
809 function First_New_Spec (A : ALI_Id) return File_Name_Type is
810 Spec_File_Name : File_Name_Type := No_File;
812 function New_Spec (Uname : Unit_Name_Type) return Boolean;
813 -- Uname is the name of the spec or body of some ada unit.
814 -- This function returns True if the Uname is the name of a body
815 -- which has a spec not mentioned inali file A. If True is returned
816 -- Spec_File_Name above is set to the name of this spec file.
822 function New_Spec (Uname : Unit_Name_Type) return Boolean is
823 Spec_Name : Unit_Name_Type;
824 File_Name : File_Name_Type;
827 -- Test whether Uname is the name of a body unit (ie ends with %b)
829 Get_Name_String (Uname);
831 Assert (Name_Len > 2 and then Name_Buffer (Name_Len - 1) = '%');
833 if Name_Buffer (Name_Len) /= 'b' then
837 -- Convert unit name into spec name
839 -- ??? this code seems dubious in presence of pragma
840 -- Source_File_Name since there is no more direct relationship
841 -- between unit name and file name.
843 -- ??? Further, what about alternative subunit naming
845 Name_Buffer (Name_Len) := 's';
846 Spec_Name := Name_Find;
847 File_Name := Get_File_Name (Spec_Name, Subunit => False);
849 -- Look if File_Name is mentioned in A's sdep list.
850 -- If not look if the file exists. If it does return True.
853 ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep
855 if Sdep.Table (D).Sfile = File_Name then
860 if Full_Source_Name (File_Name) /= No_File then
861 Spec_File_Name := File_Name;
868 -- Start of processing for First_New_Spec
872 ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit
874 exit U_Chk when Units.Table (U).Utype = Is_Body_Only
875 and then New_Spec (Units.Table (U).Uname);
877 for W in Units.Table (U).First_With
879 Units.Table (U).Last_With
882 Withs.Table (W).Afile /= No_File
883 and then New_Spec (Withs.Table (W).Uname);
887 return Spec_File_Name;
890 ---------------------------------
891 -- Data declarations for Check --
892 ---------------------------------
894 Full_Lib_File : File_Name_Type;
895 -- Full name of current library file
897 Full_Obj_File : File_Name_Type;
898 -- Full name of the object file corresponding to Lib_File.
900 Lib_Stamp : Time_Stamp_Type;
901 -- Time stamp of the current ada library file.
903 Obj_Stamp : Time_Stamp_Type;
904 -- Time stamp of the current object file.
906 Modified_Source : File_Name_Type;
907 -- The first source in Lib_File whose current time stamp differs
908 -- from that stored in Lib_File.
910 New_Spec : File_Name_Type;
911 -- If Lib_File contains in its W (with) section a body (for a
912 -- subprogram) for which there exists a spec and the spec did not
913 -- appear in the Sdep section of Lib_File, New_Spec contains the file
914 -- name of this new spec.
916 Source_Name : Name_Id;
917 Text : Text_Buffer_Ptr;
919 Prev_Switch : Character;
920 -- First character of previous switch processed
922 Arg : Arg_Id := Arg_Id'First;
923 -- Current index in Args.Table for a given unit (init to stop warning)
925 Switch_Found : Boolean;
926 -- True if a given switch has been found
929 -- Number of compiler arguments processed
931 -- Start of processing for Check
934 pragma Assert (Lib_File /= No_File);
936 Text := Read_Library_Info (Lib_File);
937 Full_Lib_File := Full_Library_Info_Name;
938 Full_Obj_File := Full_Object_File_Name;
939 Lib_Stamp := Current_Library_File_Stamp;
940 Obj_Stamp := Current_Object_File_Stamp;
942 if Full_Lib_File = No_File then
943 Verbose_Msg (Lib_File, "being checked ...", Prefix => " ");
945 Verbose_Msg (Full_Lib_File, "being checked ...", Prefix => " ");
949 O_File := Full_Obj_File;
950 O_Stamp := Obj_Stamp;
953 if Full_Lib_File = No_File then
954 Verbose_Msg (Lib_File, "missing.");
956 elsif Obj_Stamp (Obj_Stamp'First) = ' ' then
957 Verbose_Msg (Full_Obj_File, "missing.");
961 (Full_Lib_File, "(" & String (Lib_Stamp) & ") newer than",
962 Full_Obj_File, "(" & String (Obj_Stamp) & ")");
966 ALI := Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
969 if ALI = No_ALI_Id then
970 Verbose_Msg (Full_Lib_File, "incorrectly formatted ALI file");
973 elsif ALIs.Table (ALI).Ver (1 .. ALIs.Table (ALI).Ver_Len) /=
976 Verbose_Msg (Full_Lib_File, "compiled with old GNAT version");
981 -- Don't take Ali file into account if it was generated without
984 if Opt.Operating_Mode /= Opt.Check_Semantics
985 and then ALIs.Table (ALI).No_Object
987 Verbose_Msg (Full_Lib_File, "has no corresponding object");
992 -- Check for matching compiler switches if needed
994 if Opt.Check_Switches then
995 Prev_Switch := ASCII.Nul;
998 Get_Name_String (ALIs.Table (ALI).Sfile);
1000 Switches_To_Check.Set_Last (0);
1002 for J in Gcc_Switches.First .. Gcc_Switches.Last loop
1004 -- Skip non switches, -I and -o switches
1006 if Gcc_Switches.Table (J) (1) = '-'
1007 and then Gcc_Switches.Table (J) (2) /= 'o'
1008 and then Gcc_Switches.Table (J) (2) /= 'I'
1010 Normalize_Compiler_Switches
1011 (Gcc_Switches.Table (J).all,
1012 Normalized_Switches,
1015 for K in 1 .. Last_Norm_Switch loop
1016 Switches_To_Check.Increment_Last;
1017 Switches_To_Check.Table (Switches_To_Check.Last) :=
1018 Normalized_Switches (K);
1023 for J in 1 .. Switches_To_Check.Last loop
1025 -- Comparing switches is delicate because gcc reorders
1026 -- a number of switches, according to lang-specs.h, but
1027 -- gnatmake doesn't have the sufficient knowledge to
1028 -- perform the same reordering. Instead, we ignore orders
1029 -- between different "first letter" switches, but keep
1030 -- orders between same switches, e.g -O -O2 is different
1031 -- than -O2 -O, but -g -O is equivalent to -O -g.
1033 if Switches_To_Check.Table (J) (2) /= Prev_Switch then
1034 Prev_Switch := Switches_To_Check.Table (J) (2);
1036 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg;
1039 Switch_Found := False;
1042 Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1044 Num_Args := Num_Args + 1;
1047 Switches_To_Check.Table (J).all = Args.Table (K).all
1050 Switch_Found := True;
1055 if not Switch_Found then
1056 if Opt.Verbose_Mode then
1057 Verbose_Msg (ALIs.Table (ALI).Sfile,
1067 Integer (Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg -
1068 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg + 1)
1070 if Opt.Verbose_Mode then
1071 Verbose_Msg (ALIs.Table (ALI).Sfile,
1072 "different number of switches");
1080 -- Get the source files and their time stamps. Note that some
1081 -- sources may be missing if ALI is out-of-date.
1083 Set_Source_Table (ALI);
1085 Modified_Source := Time_Stamp_Mismatch (ALI);
1087 if Modified_Source /= No_File then
1090 if Opt.Verbose_Mode then
1091 Source_Name := Full_Source_Name (Modified_Source);
1093 if Source_Name /= No_File then
1094 Verbose_Msg (Source_Name, "time stamp mismatch");
1096 Verbose_Msg (Modified_Source, "missing");
1101 New_Spec := First_New_Spec (ALI);
1103 if New_Spec /= No_File then
1106 if Opt.Verbose_Mode then
1107 Source_Name := Full_Source_Name (New_Spec);
1109 if Source_Name /= No_File then
1110 Verbose_Msg (Source_Name, "new spec");
1112 Verbose_Msg (New_Spec, "old spec missing");
1120 --------------------------
1121 -- Check_Linker_Options --
1122 --------------------------
1124 procedure Check_Linker_Options
1125 (E_Stamp : Time_Stamp_Type;
1126 O_File : out File_Name_Type;
1127 O_Stamp : out Time_Stamp_Type)
1129 procedure Check_File (File : File_Name_Type);
1130 -- Update O_File and O_Stamp if the given file is younger than E_Stamp
1131 -- and O_Stamp, or if O_File is No_File and File does not exist.
1133 function Get_Library_File (Name : String) return File_Name_Type;
1134 -- Return the full file name including path of a library based
1135 -- on the name specified with the -l linker option, using the
1136 -- Ada object path. Return No_File if no such file can be found.
1138 type Char_Array is array (Natural) of Character;
1139 type Char_Array_Access is access constant Char_Array;
1141 Template : Char_Array_Access;
1142 pragma Import (C, Template, "__gnat_library_template");
1148 procedure Check_File (File : File_Name_Type) is
1149 Stamp : Time_Stamp_Type;
1150 Name : File_Name_Type := File;
1153 Get_Name_String (Name);
1155 -- Remove any trailing NUL characters
1157 while Name_Len >= Name_Buffer'First
1158 and then Name_Buffer (Name_Len) = NUL
1160 Name_Len := Name_Len - 1;
1163 if Name_Len <= 0 then
1166 elsif Name_Buffer (1) = '-' then
1168 -- Do not check if File is a switch other than "-l"
1170 if Name_Buffer (2) /= 'l' then
1174 -- The argument is a library switch, get actual name. It
1175 -- is necessary to make a copy of the relevant part of
1176 -- Name_Buffer as Get_Library_Name uses Name_Buffer as well.
1179 Base_Name : constant String := Name_Buffer (3 .. Name_Len);
1182 Name := Get_Library_File (Base_Name);
1185 if Name = No_File then
1190 Stamp := File_Stamp (Name);
1192 -- Find the youngest object file that is younger than the
1193 -- executable. If no such file exist, record the first object
1194 -- file that is not found.
1196 if (O_Stamp < Stamp and then E_Stamp < Stamp)
1197 or else (O_File = No_File and then Stamp (Stamp'First) = ' ')
1202 -- Strip the trailing NUL if present
1204 Get_Name_String (O_File);
1206 if Name_Buffer (Name_Len) = NUL then
1207 Name_Len := Name_Len - 1;
1208 O_File := Name_Find;
1213 ----------------------
1214 -- Get_Library_Name --
1215 ----------------------
1217 -- See comments in a-adaint.c about template syntax
1219 function Get_Library_File (Name : String) return File_Name_Type is
1220 File : File_Name_Type := No_File;
1225 for Ptr in Template'Range loop
1226 case Template (Ptr) is
1228 Add_Str_To_Name_Buffer (Name);
1231 File := Full_Lib_File_Name (Name_Find);
1232 exit when File /= No_File;
1239 Add_Char_To_Name_Buffer (Template (Ptr));
1243 -- The for loop exited because the end of the template
1244 -- was reached. File contains the last possible file name
1247 if File = No_File and then Name_Len > 0 then
1248 File := Full_Lib_File_Name (Name_Find);
1252 end Get_Library_File;
1254 -- Start of processing for Check_Linker_Options
1258 O_Stamp := (others => ' ');
1260 -- Process linker options from the ALI files.
1262 for Opt in 1 .. Linker_Options.Last loop
1263 Check_File (Linker_Options.Table (Opt).Name);
1266 -- Process options given on the command line.
1268 for Opt in Linker_Switches.First .. Linker_Switches.Last loop
1270 -- Check if the previous Opt has one of the two switches
1271 -- that take an extra parameter. (See GCC manual.)
1273 if Opt = Linker_Switches.First
1274 or else (Linker_Switches.Table (Opt - 1).all /= "-u"
1276 Linker_Switches.Table (Opt - 1).all /= "-Xlinker")
1279 Add_Str_To_Name_Buffer (Linker_Switches.Table (Opt).all);
1280 Check_File (Name_Find);
1284 end Check_Linker_Options;
1286 ---------------------
1287 -- Compile_Sources --
1288 ---------------------
1290 procedure Compile_Sources
1291 (Main_Source : File_Name_Type;
1292 Args : Argument_List;
1293 First_Compiled_File : out Name_Id;
1294 Most_Recent_Obj_File : out Name_Id;
1295 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
1296 Main_Unit : out Boolean;
1297 Compilation_Failures : out Natural;
1298 Check_Readonly_Files : Boolean := False;
1299 Do_Not_Execute : Boolean := False;
1300 Force_Compilations : Boolean := False;
1301 Keep_Going : Boolean := False;
1302 In_Place_Mode : Boolean := False;
1303 Initialize_ALI_Data : Boolean := True;
1304 Max_Process : Positive := 1)
1309 Args : Argument_List)
1311 -- Compiles S using Args. If S is a GNAT predefined source
1312 -- "-gnatpg" is added to Args. Non blocking call. L corresponds to the
1313 -- expected library file name. Process_Id of the process spawned to
1314 -- execute the compile.
1316 No_Mapping_File : constant Temp_File_Name := (others => ' ');
1318 type Compilation_Data is record
1320 Full_Source_File : File_Name_Type;
1321 Lib_File : File_Name_Type;
1322 Source_Unit : Unit_Name_Type;
1323 Mapping_File : Temp_File_Name := No_Mapping_File;
1324 Use_Mapping_File : Boolean := False;
1325 Syntax_Only : Boolean := False;
1328 Running_Compile : array (1 .. Max_Process) of Compilation_Data;
1329 -- Used to save information about outstanding compilations.
1331 Outstanding_Compiles : Natural := 0;
1332 -- Current number of outstanding compiles
1334 Source_Unit : Unit_Name_Type;
1335 -- Current source unit
1337 Source_File : File_Name_Type;
1338 -- Current source file
1340 Full_Source_File : File_Name_Type;
1341 -- Full name of the current source file
1343 Lib_File : File_Name_Type;
1344 -- Current library file
1346 Full_Lib_File : File_Name_Type;
1347 -- Full name of the current library file
1349 Obj_File : File_Name_Type;
1350 -- Full name of the object file corresponding to Lib_File.
1352 Obj_Stamp : Time_Stamp_Type;
1353 -- Time stamp of the current object file.
1355 Sfile : File_Name_Type;
1356 -- Contains the source file of the units withed by Source_File
1359 -- ALI Id of the current ALI file
1361 Compilation_OK : Boolean;
1362 Need_To_Compile : Boolean;
1365 Text : Text_Buffer_Ptr;
1367 Mfile : Temp_File_Name := No_Mapping_File;
1369 Data : Prj.Project_Data;
1371 Arg_Index : Natural;
1372 -- Index in Special_Args.Table of a given compilation file
1374 Need_To_Check_Standard_Library : Boolean := Check_Readonly_Files;
1376 Mapping_File_Arg : constant String_Access := new String'
1377 (1 => '-', 2 => 'g', 3 => 'n', 4 => 'a', 5 => 't', 6 => 'e', 7 => 'm',
1378 8 .. 7 + Mfile'Length => ' ');
1380 procedure Add_Process
1382 Sfile : File_Name_Type;
1383 Afile : File_Name_Type;
1384 Uname : Unit_Name_Type;
1385 Mfile : Temp_File_Name := No_Mapping_File;
1386 UMfile : Boolean := False);
1387 -- Adds process Pid to the current list of outstanding compilation
1388 -- processes and record the full name of the source file Sfile that
1389 -- we are compiling, the name of its library file Afile and the
1390 -- name of its unit Uname.
1392 procedure Await_Compile
1393 (Sfile : out File_Name_Type;
1394 Afile : out File_Name_Type;
1395 Uname : out Unit_Name_Type;
1397 -- Awaits that an outstanding compilation process terminates. When
1398 -- it does set Sfile to the name of the source file that was compiled
1399 -- Afile to the name of its library file and Uname to the name of its
1400 -- unit. Note that this time stamp can be used to check whether the
1401 -- compilation did generate an object file. OK is set to True if the
1402 -- compilation succeeded. Note that Sfile, Afile and Uname could be
1403 -- resp. No_File, No_File and No_Name if there were no compilations
1406 procedure Collect_Arguments_And_Compile (Source_File : File_Name_Type);
1407 -- Collect arguments from project file (if any) and compile
1409 package Good_ALI is new Table.Table (
1410 Table_Component_Type => ALI_Id,
1411 Table_Index_Type => Natural,
1412 Table_Low_Bound => 1,
1413 Table_Initial => 50,
1414 Table_Increment => 100,
1415 Table_Name => "Make.Good_ALI");
1416 -- Contains the set of valid ALI files that have not yet been scanned.
1418 procedure Record_Good_ALI (A : ALI_Id);
1419 -- Records in the previous set the Id of an ALI file.
1421 function Good_ALI_Present return Boolean;
1422 -- Returns True if any ALI file was recorded in the previous set.
1424 function Get_Next_Good_ALI return ALI_Id;
1425 -- Returns the next good ALI_Id record;
1427 procedure Record_Failure
1428 (File : File_Name_Type;
1429 Unit : Unit_Name_Type;
1430 Found : Boolean := True);
1431 -- Records in the previous table that the compilation for File failed.
1432 -- If Found is False then the compilation of File failed because we
1433 -- could not find it. Records also Unit when possible.
1435 function Bad_Compilation_Count return Natural;
1436 -- Returns the number of compilation failures.
1438 procedure Debug_Msg (S : String; N : Name_Id);
1439 -- If Debug.Debug_Flag_W is set outputs string S followed by name N.
1441 function Configuration_Pragmas_Switch
1442 (For_Project : Project_Id)
1443 return Argument_List;
1444 -- Return an argument list of one element, if there is a configuration
1445 -- pragmas file to be specified for For_Project,
1446 -- otherwise return an empty argument list.
1448 procedure Get_Mapping_File;
1449 -- Get a mapping file name. If there is one to be reused, reuse it.
1450 -- Otherwise, create a new mapping file.
1456 procedure Add_Process
1458 Sfile : File_Name_Type;
1459 Afile : File_Name_Type;
1460 Uname : Unit_Name_Type;
1461 Mfile : Temp_File_Name := No_Mapping_File;
1462 UMfile : Boolean := False)
1464 OC1 : constant Positive := Outstanding_Compiles + 1;
1467 pragma Assert (OC1 <= Max_Process);
1468 pragma Assert (Pid /= Invalid_Pid);
1470 Running_Compile (OC1).Pid := Pid;
1471 Running_Compile (OC1).Full_Source_File := Sfile;
1472 Running_Compile (OC1).Lib_File := Afile;
1473 Running_Compile (OC1).Source_Unit := Uname;
1474 Running_Compile (OC1).Mapping_File := Mfile;
1475 Running_Compile (OC1).Use_Mapping_File := UMfile;
1476 Running_Compile (OC1).Syntax_Only := Syntax_Only;
1478 Outstanding_Compiles := OC1;
1481 --------------------
1485 procedure Await_Compile
1486 (Sfile : out File_Name_Type;
1487 Afile : out File_Name_Type;
1488 Uname : out File_Name_Type;
1494 pragma Assert (Outstanding_Compiles > 0);
1501 Wait_Process (Pid, OK);
1503 if Pid = Invalid_Pid then
1507 for J in Running_Compile'First .. Outstanding_Compiles loop
1508 if Pid = Running_Compile (J).Pid then
1509 Sfile := Running_Compile (J).Full_Source_File;
1510 Afile := Running_Compile (J).Lib_File;
1511 Uname := Running_Compile (J).Source_Unit;
1512 Syntax_Only := Running_Compile (J).Syntax_Only;
1514 -- If a mapping file was used by this compilation,
1515 -- get its file name for reuse by a subsequent compilation
1517 if Running_Compile (J).Use_Mapping_File then
1518 Last_Mapping_File_Name := Last_Mapping_File_Name + 1;
1519 The_Mapping_File_Names (Last_Mapping_File_Name) :=
1520 Running_Compile (J).Mapping_File;
1523 -- To actually remove this Pid and related info from
1524 -- Running_Compile replace its entry with the last valid
1525 -- entry in Running_Compile.
1527 if J = Outstanding_Compiles then
1531 Running_Compile (J) :=
1532 Running_Compile (Outstanding_Compiles);
1535 Outstanding_Compiles := Outstanding_Compiles - 1;
1540 raise Program_Error;
1543 ---------------------------
1544 -- Bad_Compilation_Count --
1545 ---------------------------
1547 function Bad_Compilation_Count return Natural is
1549 return Bad_Compilation.Last - Bad_Compilation.First + 1;
1550 end Bad_Compilation_Count;
1552 -----------------------------------
1553 -- Collect_Arguments_And_Compile --
1554 -----------------------------------
1556 procedure Collect_Arguments_And_Compile (Source_File : File_Name_Type) is
1559 -- If we use mapping file (-P or -C switches), then get one
1561 if Create_Mapping_File then
1565 -- If no project file is used, then just call Compile with
1566 -- the specified Args.
1568 if Main_Project = No_Project then
1569 Pid := Compile (Full_Source_File, Lib_File, Args);
1571 -- A project file was used
1574 -- First check if the current source is an immediate
1575 -- source of a project file.
1577 if Opt.Verbose_Mode then
1579 Write_Line ("Establishing Project context.");
1583 Source_File_Name : constant String :=
1584 Get_Name_String (Source_File);
1585 Current_Project : Prj.Project_Id;
1586 Path_Name : File_Name_Type := Source_File;
1587 Compiler_Package : Prj.Package_Id;
1588 Switches : Prj.Variable_Value;
1589 Object_File : String_Access;
1592 if Opt.Verbose_Mode then
1593 Write_Str ("Checking if the Project File exists for """);
1594 Write_Str (Source_File_Name);
1600 (Source_File_Name => Source_File_Name,
1601 Project => Current_Project,
1604 if Current_Project = No_Project then
1606 -- The current source is not an immediate source of any
1607 -- project file. Call Compile with the specified Args plus
1608 -- the saved gcc switches.
1610 if Opt.Verbose_Mode then
1611 Write_Str ("No Project File.");
1618 Args & The_Saved_Gcc_Switches.all);
1620 -- We now know the project of the current source
1623 -- Set ADA_INCLUDE_PATH and ADA_OBJECTS_PATH if the project
1626 -- Note: this will modify these environment variables only
1627 -- for the current gnatmake process and all of its children
1628 -- (invocations of the compiler, the binder and the linker).
1630 -- The caller's ADA_INCLUDE_PATH and ADA_OBJECTS_PATH are
1633 Set_Ada_Paths (Current_Project, True);
1635 Data := Projects.Table (Current_Project);
1637 -- Check if it is a library project that needs to be
1638 -- processed, only if it is not the main project.
1640 if MLib.Tgt.Libraries_Are_Supported
1641 and then Current_Project /= Main_Project
1642 and then Data.Library
1643 and then not Data.Flag1
1645 -- Add to the Q all sources of the project that have
1648 Insert_Project_Sources
1649 (The_Project => Current_Project, Into_Q => True);
1651 -- Now mark the project as processed
1654 Projects.Table (Current_Project).Flag1 := True;
1657 Get_Name_String (Data.Object_Directory);
1659 if Name_Buffer (Name_Len) = '/'
1660 or else Name_Buffer (Name_Len) = Directory_Separator
1664 (Name_Buffer (1 .. Name_Len) &
1665 Object_File_Name (Source_File_Name));
1670 (Name_Buffer (1 .. Name_Len) &
1671 Directory_Separator &
1672 Object_File_Name (Source_File_Name));
1675 if Opt.Verbose_Mode then
1676 Write_Str ("Project file is """);
1677 Write_Str (Get_Name_String (Data.Name));
1682 -- We know look for package Compiler
1683 -- and get the switches from this package.
1685 if Opt.Verbose_Mode then
1686 Write_Str ("Checking package Compiler.");
1692 (Name => Name_Compiler,
1693 In_Packages => Data.Decl.Packages);
1695 if Compiler_Package /= No_Package then
1697 if Opt.Verbose_Mode then
1698 Write_Str ("Getting the switches.");
1702 -- If package Gnatmake.Compiler exists, we get
1703 -- the specific switches for the current source,
1704 -- or the global switches, if any.
1706 Switches := Switches_Of
1707 (Source_File => Source_File,
1708 Source_File_Name => Source_File_Name,
1710 Projects.Table (Current_Project).Naming,
1711 In_Package => Compiler_Package,
1712 Allow_ALI => False);
1716 case Switches.Kind is
1718 -- We have a list of switches. We add to Args
1719 -- these switches, plus the saved gcc switches.
1724 Current : String_List_Id := Switches.Values;
1725 Element : String_Element;
1726 Number : Natural := 0;
1729 while Current /= Nil_String loop
1730 Element := String_Elements.Table (Current);
1731 Number := Number + 1;
1732 Current := Element.Next;
1736 New_Args : Argument_List (1 .. Number);
1739 Current := Switches.Values;
1741 for Index in New_Args'Range loop
1742 Element := String_Elements.Table (Current);
1743 String_To_Name_Buffer (Element.Value);
1745 new String' (Name_Buffer (1 .. Name_Len));
1746 Test_If_Relative_Path
1747 (New_Args (Index), Parent => null);
1748 Current := Element.Next;
1754 Args & Output_Flag & Object_File &
1755 Configuration_Pragmas_Switch
1757 New_Args & The_Saved_Gcc_Switches.all);
1761 -- We have a single switch. We add to Args
1762 -- this switch, plus the saved gcc switches.
1765 String_To_Name_Buffer (Switches.Value);
1768 New_Args : Argument_List :=
1770 (Name_Buffer (1 .. Name_Len)));
1773 Test_If_Relative_Path
1774 (New_Args (1), Parent => null);
1782 Configuration_Pragmas_Switch (Current_Project) &
1783 The_Saved_Gcc_Switches.all);
1786 -- We have no switches from Gnatmake.Compiler.
1787 -- We add to Args the saved gcc switches.
1790 if Opt.Verbose_Mode then
1791 Write_Str ("There are no switches.");
1798 Args & Output_Flag & Object_File &
1799 Configuration_Pragmas_Switch (Current_Project) &
1800 The_Saved_Gcc_Switches.all);
1805 end Collect_Arguments_And_Compile;
1811 function Compile (S : Name_Id; L : Name_Id; Args : Argument_List)
1814 Comp_Args : Argument_List (Args'First .. Args'Last + 8);
1815 Comp_Next : Integer := Args'First;
1816 Comp_Last : Integer;
1818 function Ada_File_Name (Name : Name_Id) return Boolean;
1819 -- Returns True if Name is the name of an ada source file
1820 -- (i.e. suffix is .ads or .adb)
1826 function Ada_File_Name (Name : Name_Id) return Boolean is
1828 Get_Name_String (Name);
1831 and then Name_Buffer (Name_Len - 3 .. Name_Len - 1) = ".ad"
1832 and then (Name_Buffer (Name_Len) = 'b'
1834 Name_Buffer (Name_Len) = 's');
1837 -- Start of processing for Compile
1840 -- By default, Syntax_Only is False
1842 Syntax_Only := False;
1844 for J in Args'Range loop
1845 if Args (J).all = "-gnats" then
1847 -- If we compile with -gnats, the bind step and the link step
1848 -- are inhibited. Also, we set Syntax_Only to True, so that
1849 -- we don't fail when we don't find the ALI file, after
1852 Do_Bind_Step := False;
1853 Do_Link_Step := False;
1854 Syntax_Only := True;
1856 elsif Args (J).all = "-gnatc" then
1858 -- If we compile with -gnatc, the bind step and the link step
1859 -- are inhibited. We set Syntax_Only to True for the case when
1860 -- -gnats was previously specified.
1862 Do_Bind_Step := False;
1863 Do_Link_Step := False;
1864 Syntax_Only := False;
1868 Comp_Args (Comp_Next) := Comp_Flag;
1869 Comp_Next := Comp_Next + 1;
1871 -- Optimize the simple case where the gcc command line looks like
1872 -- gcc -c -I. ... -I- file.adb --into-> gcc -c ... file.adb
1874 if Args (Args'First).all = "-I" & Normalized_CWD
1875 and then Args (Args'Last).all = "-I-"
1876 and then S = Strip_Directory (S)
1878 Comp_Last := Comp_Next + Args'Length - 3;
1879 Comp_Args (Comp_Next .. Comp_Last) :=
1880 Args (Args'First + 1 .. Args'Last - 1);
1883 Comp_Last := Comp_Next + Args'Length - 1;
1884 Comp_Args (Comp_Next .. Comp_Last) := Args;
1887 -- Set -gnatpg for predefined files (for this purpose the renamings
1888 -- such as Text_IO do not count as predefined). Note that we strip
1889 -- the directory name from the source file name becase the call to
1890 -- Fname.Is_Predefined_File_Name cannot deal with directory prefixes.
1893 Fname : constant File_Name_Type := Strip_Directory (S);
1896 if Is_Predefined_File_Name (Fname, False) then
1897 if Check_Readonly_Files then
1898 Comp_Last := Comp_Last + 1;
1899 Comp_Args (Comp_Last) := GNAT_Flag;
1903 ("not allowed to compile """ &
1904 Get_Name_String (Fname) &
1905 """; use -a switch.");
1910 -- Now check if the file name has one of the suffixes familiar to
1911 -- the gcc driver. If this is not the case then add the ada flag
1914 if not Ada_File_Name (S) then
1915 Comp_Last := Comp_Last + 1;
1916 Comp_Args (Comp_Last) := Ada_Flag_1;
1917 Comp_Last := Comp_Last + 1;
1918 Comp_Args (Comp_Last) := Ada_Flag_2;
1921 if L /= Strip_Directory (L) then
1923 -- Build -o argument.
1925 Get_Name_String (L);
1927 for J in reverse 1 .. Name_Len loop
1928 if Name_Buffer (J) = '.' then
1929 Name_Len := J + Object_Suffix'Length - 1;
1930 Name_Buffer (J .. Name_Len) := Object_Suffix;
1935 Comp_Last := Comp_Last + 1;
1936 Comp_Args (Comp_Last) := Output_Flag;
1937 Comp_Last := Comp_Last + 1;
1938 Comp_Args (Comp_Last) := new String'(Name_Buffer (1 .. Name_Len));
1941 if Create_Mapping_File then
1942 Comp_Last := Comp_Last + 1;
1943 Comp_Args (Comp_Last) := Mapping_File_Arg;
1946 Get_Name_String (S);
1948 Comp_Last := Comp_Last + 1;
1949 Comp_Args (Comp_Last) := new String'(Name_Buffer (1 .. Name_Len));
1951 GNAT.OS_Lib.Normalize_Arguments (Comp_Args (Args'First .. Comp_Last));
1953 Display (Gcc.all, Comp_Args (Args'First .. Comp_Last));
1955 if Gcc_Path = null then
1956 Osint.Fail ("error, unable to locate " & Gcc.all);
1960 GNAT.OS_Lib.Non_Blocking_Spawn
1961 (Gcc_Path.all, Comp_Args (Args'First .. Comp_Last));
1964 ----------------------------------
1965 -- Configuration_Pragmas_Switch --
1966 ----------------------------------
1968 function Configuration_Pragmas_Switch
1969 (For_Project : Project_Id)
1970 return Argument_List
1973 Prj.Env.Create_Config_Pragmas_File (For_Project, Main_Project);
1975 if Projects.Table (For_Project).Config_File_Name /= No_Name then
1977 (1 => new String'("-gnatec" &
1979 (Projects.Table (For_Project).Config_File_Name)));
1982 return (1 .. 0 => null);
1984 end Configuration_Pragmas_Switch;
1990 procedure Debug_Msg (S : String; N : Name_Id) is
1992 if Debug.Debug_Flag_W then
1993 Write_Str (" ... ");
2001 ----------------------
2002 -- Get_Mapping_File --
2003 ----------------------
2005 procedure Get_Mapping_File is
2007 -- If there is a mapping file ready to be reused, reuse it
2009 if Last_Mapping_File_Name > 0 then
2010 Mfile := The_Mapping_File_Names (Last_Mapping_File_Name);
2011 Last_Mapping_File_Name := Last_Mapping_File_Name - 1;
2013 -- Otherwise, create and initialize a new one
2016 Init_Mapping_File (File_Name => Mfile);
2019 -- Put the name in the mapping file argument for the invocation
2022 Mapping_File_Arg (8 .. Mapping_File_Arg'Last) := Mfile;
2024 end Get_Mapping_File;
2026 -----------------------
2027 -- Get_Next_Good_ALI --
2028 -----------------------
2030 function Get_Next_Good_ALI return ALI_Id is
2034 pragma Assert (Good_ALI_Present);
2035 ALI := Good_ALI.Table (Good_ALI.Last);
2036 Good_ALI.Decrement_Last;
2038 end Get_Next_Good_ALI;
2040 ----------------------
2041 -- Good_ALI_Present --
2042 ----------------------
2044 function Good_ALI_Present return Boolean is
2046 return Good_ALI.First <= Good_ALI.Last;
2047 end Good_ALI_Present;
2049 --------------------
2050 -- Record_Failure --
2051 --------------------
2053 procedure Record_Failure
2054 (File : File_Name_Type;
2055 Unit : Unit_Name_Type;
2056 Found : Boolean := True)
2059 Bad_Compilation.Increment_Last;
2060 Bad_Compilation.Table (Bad_Compilation.Last) := (File, Unit, Found);
2063 ---------------------
2064 -- Record_Good_ALI --
2065 ---------------------
2067 procedure Record_Good_ALI (A : ALI_Id) is
2069 Good_ALI.Increment_Last;
2070 Good_ALI.Table (Good_ALI.Last) := A;
2071 end Record_Good_ALI;
2073 -- Start of processing for Compile_Sources
2076 pragma Assert (Args'First = 1);
2078 -- Package and Queue initializations.
2081 Output.Set_Standard_Error;
2084 if Initialize_ALI_Data then
2086 Initialize_ALI_Source;
2089 -- The following two flags affect the behavior of ALI.Set_Source_Table.
2090 -- We set Opt.Check_Source_Files to True to ensure that source file
2091 -- time stamps are checked, and we set Opt.All_Sources to False to
2092 -- avoid checking the presence of the source files listed in the
2093 -- source dependency section of an ali file (which would be a mistake
2094 -- since the ali file may be obsolete).
2096 Opt.Check_Source_Files := True;
2097 Opt.All_Sources := False;
2099 -- If the main source is marked, there is nothing to compile.
2100 -- This can happen when we have several main subprograms.
2101 -- For the first main, we always insert in the Q.
2103 if not Is_Marked (Main_Source) then
2104 Insert_Q (Main_Source);
2108 First_Compiled_File := No_File;
2109 Most_Recent_Obj_File := No_File;
2112 -- Keep looping until there is no more work to do (the Q is empty)
2113 -- and all the outstanding compilations have terminated
2115 Make_Loop : while not Empty_Q or else Outstanding_Compiles > 0 loop
2117 -- If the user does not want to keep going in case of errors then
2118 -- wait for the remaining outstanding compiles and then exit.
2120 if Bad_Compilation_Count > 0 and then not Keep_Going then
2121 while Outstanding_Compiles > 0 loop
2123 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
2125 if not Compilation_OK then
2126 Record_Failure (Full_Source_File, Source_Unit);
2133 -- PHASE 1: Check if there is more work that we can do (ie the Q
2134 -- is non empty). If there is, do it only if we have not yet used
2135 -- up all the available processes.
2137 if not Empty_Q and then Outstanding_Compiles < Max_Process then
2138 Extract_From_Q (Source_File, Source_Unit);
2139 Full_Source_File := Osint.Full_Source_Name (Source_File);
2140 Lib_File := Osint.Lib_File_Name (Source_File);
2141 Full_Lib_File := Osint.Full_Lib_File_Name (Lib_File);
2143 -- If the library file is an Ada library skip it
2145 if Full_Lib_File /= No_File
2146 and then In_Ada_Lib_Dir (Full_Lib_File)
2148 Verbose_Msg (Lib_File, "is in an Ada library", Prefix => " ");
2150 -- If the library file is a read-only library skip it
2152 elsif Full_Lib_File /= No_File
2153 and then not Check_Readonly_Files
2154 and then Is_Readonly_Library (Full_Lib_File)
2157 (Lib_File, "is a read-only library", Prefix => " ");
2159 -- The source file that we are checking cannot be located
2161 elsif Full_Source_File = No_File then
2162 Record_Failure (Source_File, Source_Unit, False);
2164 -- Source and library files can be located but are internal
2167 elsif not Check_Readonly_Files
2168 and then Full_Lib_File /= No_File
2169 and then Is_Internal_File_Name (Source_File)
2172 if Force_Compilations then
2174 ("not allowed to compile """ &
2175 Get_Name_String (Source_File) &
2176 """; use -a switch.");
2180 (Lib_File, "is an internal library", Prefix => " ");
2182 -- The source file that we are checking can be located
2185 -- Don't waste any time if we have to recompile anyway
2187 Obj_Stamp := Empty_Time_Stamp;
2188 Need_To_Compile := Force_Compilations;
2190 if not Force_Compilations then
2191 Check (Lib_File, ALI, Obj_File, Obj_Stamp);
2192 Need_To_Compile := (ALI = No_ALI_Id);
2195 if not Need_To_Compile then
2197 -- The ALI file is up-to-date. Record its Id.
2199 Record_Good_ALI (ALI);
2201 -- Record the time stamp of the most recent object file
2202 -- as long as no (re)compilations are needed.
2204 if First_Compiled_File = No_File
2205 and then (Most_Recent_Obj_File = No_File
2206 or else Obj_Stamp > Most_Recent_Obj_Stamp)
2208 Most_Recent_Obj_File := Obj_File;
2209 Most_Recent_Obj_Stamp := Obj_Stamp;
2213 -- Is this the first file we have to compile?
2215 if First_Compiled_File = No_File then
2216 First_Compiled_File := Full_Source_File;
2217 Most_Recent_Obj_File := No_File;
2219 if Do_Not_Execute then
2224 if In_Place_Mode then
2226 -- If the library file was not found, then save the
2227 -- library file near the source file.
2229 if Full_Lib_File = No_File then
2230 Get_Name_String (Full_Source_File);
2232 for J in reverse 1 .. Name_Len loop
2233 if Name_Buffer (J) = '.' then
2234 Name_Buffer (J + 1 .. J + 3) := "ali";
2240 Lib_File := Name_Find;
2242 -- If the library file was found, then save the
2243 -- library file in the same place.
2246 Lib_File := Full_Lib_File;
2251 -- Check for special compilation flags
2255 -- Start the compilation and record it. We can do this
2256 -- because there is at least one free process.
2258 Collect_Arguments_And_Compile (Source_File);
2260 -- Make sure we could successfully start the compilation
2262 if Pid = Invalid_Pid then
2263 Record_Failure (Full_Source_File, Source_Unit);
2271 Create_Mapping_File);
2277 -- PHASE 2: Now check if we should wait for a compilation to
2278 -- finish. This is the case if all the available processes are
2279 -- busy compiling sources or there is nothing else to do
2280 -- (that is the Q is empty and there are no good ALIs to process).
2282 if Outstanding_Compiles = Max_Process
2284 and then not Good_ALI_Present
2285 and then Outstanding_Compiles > 0)
2288 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
2290 if not Compilation_OK then
2291 Record_Failure (Full_Source_File, Source_Unit);
2294 if Compilation_OK or else Keep_Going then
2296 -- Re-read the updated library file
2299 Saved_Object_Consistency : constant Boolean :=
2300 Opt.Check_Object_Consistency;
2303 -- If compilation was not OK, don't check object
2306 Opt.Check_Object_Consistency :=
2307 Opt.Check_Object_Consistency and Compilation_OK;
2308 Text := Read_Library_Info (Lib_File);
2310 -- Restore Check_Object_Consistency to its initial value
2312 Opt.Check_Object_Consistency := Saved_Object_Consistency;
2315 -- If no ALI file was generated by this compilation nothing
2316 -- more to do, otherwise scan the ali file and record it.
2317 -- If the scan fails, a previous ali file is inconsistent with
2318 -- the unit just compiled.
2320 if Text /= null then
2322 Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
2324 if ALI = No_ALI_Id then
2326 -- Record a failure only if not already done
2328 if Compilation_OK then
2331 "incompatible ALI file, please recompile");
2332 Record_Failure (Full_Source_File, Source_Unit);
2336 Record_Good_ALI (ALI);
2339 -- If we could not read the ALI file that was just generated
2340 -- then there could be a problem reading either the ALI or the
2341 -- corresponding object file (if Opt.Check_Object_Consistency
2342 -- is set Read_Library_Info checks that the time stamp of the
2343 -- object file is more recent than that of the ALI). For an
2344 -- example of problems caught by this test see [6625-009].
2345 -- However, we record a failure only if not already done.
2348 if Compilation_OK and not Syntax_Only then
2351 "WARNING: ALI or object file not found after compile");
2352 Record_Failure (Full_Source_File, Source_Unit);
2358 exit Make_Loop when Unique_Compile;
2360 -- PHASE 3: Check if we recorded good ALI files. If yes process
2361 -- them now in the order in which they have been recorded. There
2362 -- are two occasions in which we record good ali files. The first is
2363 -- in phase 1 when, after scanning an existing ALI file we realise
2364 -- it is up-to-date, the second instance is after a successful
2367 while Good_ALI_Present loop
2368 ALI := Get_Next_Good_ALI;
2370 -- If we are processing the library file corresponding to the
2371 -- main source file check if this source can be a main unit.
2373 if ALIs.Table (ALI).Sfile = Main_Source then
2374 Main_Unit := ALIs.Table (ALI).Main_Program /= None;
2377 -- The following adds the standard library (s-stalib) to the
2378 -- list of files to be handled by gnatmake: this file and any
2379 -- files it depends on are always included in every bind,
2380 -- except in No_Run_Time mode, even if they are not
2381 -- in the explicit dependency list.
2383 -- However, to avoid annoying output about s-stalib.ali being
2384 -- read only, when "-v" is used, we add the standard library
2385 -- only when "-a" is used.
2387 if Need_To_Check_Standard_Library then
2388 Need_To_Check_Standard_Library := False;
2390 if not ALIs.Table (ALI).No_Run_Time then
2393 Add_It : Boolean := True;
2396 Name_Len := Standard_Library_Package_Body_Name'Length;
2397 Name_Buffer (1 .. Name_Len) :=
2398 Standard_Library_Package_Body_Name;
2399 Sfile := Name_Enter;
2401 -- If we have a special runtime, we add the standard
2402 -- library only if we can find it.
2404 if Opt.RTS_Switch then
2405 Add_It := Find_File (Sfile, Osint.Source) /= No_File;
2408 if Add_It and then not Is_Marked (Sfile) then
2416 -- Now insert in the Q the unmarked source files (i.e. those
2417 -- which have neever been inserted in the Q and hence never
2421 ALIs.Table (ALI).First_Unit .. ALIs.Table (ALI).Last_Unit
2424 Units.Table (J).First_With .. Units.Table (J).Last_With
2426 Sfile := Withs.Table (K).Sfile;
2428 if Sfile = No_File then
2429 Debug_Msg ("Skipping generic:", Withs.Table (K).Uname);
2431 elsif Is_Marked (Sfile) then
2432 Debug_Msg ("Skipping marked file:", Sfile);
2434 elsif not Check_Readonly_Files
2435 and then Is_Internal_File_Name (Sfile)
2437 Debug_Msg ("Skipping internal file:", Sfile);
2440 Insert_Q (Sfile, Withs.Table (K).Uname);
2447 if Opt.Display_Compilation_Progress then
2448 Write_Str ("completed ");
2449 Write_Int (Int (Q_Front));
2450 Write_Str (" out of ");
2451 Write_Int (Int (Q.Last));
2453 Write_Int (Int ((Q_Front * 100) / (Q.Last - Q.First)));
2454 Write_Str ("%)...");
2459 Compilation_Failures := Bad_Compilation_Count;
2461 -- Compilation is finished
2463 -- Delete any temporary configuration pragma file
2465 if Main_Project /= No_Project then
2470 for Project in 1 .. Projects.Last loop
2471 if Projects.Table (Project).Config_File_Temp then
2472 if Opt.Verbose_Mode then
2473 Write_Str ("Deleting temp configuration file """);
2474 Write_Str (Get_Name_String
2475 (Projects.Table (Project).Config_File_Name));
2480 (Name => Get_Name_String
2481 (Projects.Table (Project).Config_File_Name),
2482 Success => Success);
2484 -- Make sure that we don't have a config file for this
2485 -- project, in case when there are several mains.
2486 -- In this case, we will recreate another config file:
2487 -- we cannot reuse the one that we just deleted!
2489 Projects.Table (Project).Config_Checked := False;
2490 Projects.Table (Project).Config_File_Name := No_Name;
2491 Projects.Table (Project).Config_File_Temp := False;
2496 end Compile_Sources;
2498 --------------------------
2499 -- Delete_Mapping_Files --
2500 --------------------------
2502 procedure Delete_Mapping_Files is
2506 for Index in 1 .. Last_Mapping_File_Name loop
2508 (Name => The_Mapping_File_Names (Index), Success => Success);
2510 end Delete_Mapping_Files;
2516 procedure Display (Program : String; Args : Argument_List) is
2518 pragma Assert (Args'First = 1);
2520 if Display_Executed_Programs then
2521 Write_Str (Program);
2523 for J in Args'Range loop
2525 -- Do not display the mapping file argument automatically
2526 -- created when using a project file.
2528 if Main_Project = No_Project
2529 or else Args (J)'Length /= 7 + Temp_File_Name'Length
2530 or else Args (J)'First /= 1
2531 or else Args (J)(1 .. 7) /= "-gnatem"
2534 Write_Str (Args (J).all);
2542 ----------------------
2543 -- Display_Commands --
2544 ----------------------
2546 procedure Display_Commands (Display : Boolean := True) is
2548 Display_Executed_Programs := Display;
2549 end Display_Commands;
2555 function Empty_Q return Boolean is
2557 if Debug.Debug_Flag_P then
2558 Write_Str (" Q := [");
2560 for J in Q_Front .. Q.Last - 1 loop
2562 Write_Name (Q.Table (J).File);
2571 return Q_Front >= Q.Last;
2574 ---------------------
2575 -- Extract_Failure --
2576 ---------------------
2578 procedure Extract_Failure
2579 (File : out File_Name_Type;
2580 Unit : out Unit_Name_Type;
2581 Found : out Boolean)
2584 File := Bad_Compilation.Table (Bad_Compilation.Last).File;
2585 Unit := Bad_Compilation.Table (Bad_Compilation.Last).Unit;
2586 Found := Bad_Compilation.Table (Bad_Compilation.Last).Found;
2587 Bad_Compilation.Decrement_Last;
2588 end Extract_Failure;
2590 --------------------
2591 -- Extract_From_Q --
2592 --------------------
2594 procedure Extract_From_Q
2595 (Source_File : out File_Name_Type;
2596 Source_Unit : out Unit_Name_Type)
2598 File : constant File_Name_Type := Q.Table (Q_Front).File;
2599 Unit : constant Unit_Name_Type := Q.Table (Q_Front).Unit;
2602 if Debug.Debug_Flag_Q then
2603 Write_Str (" Q := Q - [ ");
2609 Q_Front := Q_Front + 1;
2610 Source_File := File;
2611 Source_Unit := Unit;
2618 procedure Gnatmake is
2619 Main_Source_File : File_Name_Type;
2620 -- The source file containing the main compilation unit
2622 Compilation_Failures : Natural;
2624 Total_Compilation_Failures : Natural := 0;
2626 Is_Main_Unit : Boolean;
2627 -- Set to True by Compile_Sources if the Main_Source_File can be a
2630 Main_ALI_File : File_Name_Type;
2631 -- The ali file corresponding to Main_Source_File
2633 Executable : File_Name_Type := No_File;
2634 -- The file name of an executable
2636 Non_Std_Executable : Boolean := False;
2637 -- Non_Std_Executable is set to True when there is a possibility
2638 -- that the linker will not choose the correct executable file name.
2640 Executable_Obsolete : Boolean := False;
2641 -- Executable_Obsolete is set to True for the first obsolete main
2642 -- and is never reset to False. Any subsequent main will always
2643 -- be rebuild (if we rebuild mains), even in the case when it is not
2644 -- really necessary, because it is too hard to decide.
2646 Current_Work_Dir : constant String_Access :=
2647 new String'(Get_Current_Dir);
2648 -- The current working directory, used to modify some relative path
2649 -- switches on the command line when a project file is used.
2652 Do_Compile_Step := True;
2653 Do_Bind_Step := True;
2654 Do_Link_Step := True;
2658 if Hostparm.Java_VM then
2659 Gcc := new String'("jgnat");
2660 Gnatbind := new String'("jgnatbind");
2661 Gnatlink := new String '("jgnatlink");
2663 -- Do not check for an object file (".o") when compiling to
2664 -- Java bytecode since ".class" files are generated instead.
2666 Opt.Check_Object_Consistency := False;
2669 if Opt.Verbose_Mode then
2670 Targparm.Get_Target_Parameters;
2673 Write_Str ("GNATMAKE ");
2675 if Targparm.High_Integrity_Mode_On_Target then
2676 Write_Str ("Pro High Integrity ");
2679 Write_Str (Gnatvsn.Gnat_Version_String);
2680 Write_Str (" Copyright 1995-2002 Free Software Foundation, Inc.");
2684 -- If no mains have been specified on the command line,
2685 -- and we are using a project file, we either find the main(s)
2686 -- in the attribute Main of the main project, or we put all
2687 -- the sources of the project file as mains.
2689 if Main_Project /= No_Project and then Osint.Number_Of_Files = 0 then
2691 Name_Buffer (1 .. 4) := "main";
2694 Main_Id : constant Name_Id := Name_Find;
2696 Mains : constant Prj.Variable_Value :=
2698 (Variable_Name => Main_Id,
2700 Projects.Table (Main_Project).Decl.Attributes);
2702 Value : String_List_Id := Mains.Values;
2705 -- The attribute Main is an empty list or not specified,
2706 -- or else gnatmake was invoked with the switch "-u".
2708 if Value = Prj.Nil_String or else Unique_Compile then
2710 -- First make sure that the binder and the linker
2711 -- will not be invoked.
2713 Do_Bind_Step := False;
2714 Do_Link_Step := False;
2716 -- Set Unique_Compile if it was not already set
2718 Unique_Compile := True;
2720 -- Put all the sources in the queue
2722 Insert_Project_Sources
2723 (The_Project => Main_Project, Into_Q => False);
2726 -- The attribute Main is not an empty list.
2727 -- Put all the main subprograms in the list as if there were
2728 -- specified on the command line.
2730 while Value /= Prj.Nil_String loop
2731 String_To_Name_Buffer (String_Elements.Table (Value).Value);
2732 Osint.Add_File (Name_Buffer (1 .. Name_Len));
2733 Value := String_Elements.Table (Value).Next;
2741 -- Output usage information if no files. Note that this can happen
2742 -- in the case of a project file that contains only subunits.
2744 if Osint.Number_Of_Files = 0 then
2746 Exit_Program (E_Fatal);
2750 -- If -M was specified, behave as if -n was specified
2752 if Opt.List_Dependencies then
2753 Opt.Do_Not_Execute := True;
2756 -- Note that Osint.Next_Main_Source will always return the (possibly
2757 -- abbreviated file) without any directory information.
2759 Main_Source_File := Next_Main_Source;
2761 if Project_File_Name = null then
2762 Add_Switch ("-I-", Compiler, And_Save => True);
2763 Add_Switch ("-I-", Binder, And_Save => True);
2765 if Opt.Look_In_Primary_Dir then
2769 Normalize_Directory_Name
2770 (Get_Primary_Src_Search_Directory.all).all,
2771 Compiler, Append_Switch => False,
2774 Add_Switch ("-aO" & Normalized_CWD,
2776 Append_Switch => False,
2782 -- If the user wants a program without a main subprogram, add the
2783 -- appropriate switch to the binder.
2785 if Opt.No_Main_Subprogram then
2786 Add_Switch ("-z", Binder, And_Save => True);
2789 if Main_Project /= No_Project then
2792 (Get_Name_String (Projects.Table (Main_Project).Object_Directory));
2794 -- Find the file name of the main unit
2797 Main_Source_File_Name : constant String :=
2798 Get_Name_String (Main_Source_File);
2799 Main_Unit_File_Name : constant String :=
2800 Prj.Env.File_Name_Of_Library_Unit_Body
2801 (Name => Main_Source_File_Name,
2802 Project => Main_Project);
2804 The_Packages : constant Package_Id :=
2805 Projects.Table (Main_Project).Decl.Packages;
2807 Gnatmake : constant Prj.Package_Id :=
2809 (Name => Name_Builder,
2810 In_Packages => The_Packages);
2812 Binder_Package : constant Prj.Package_Id :=
2814 (Name => Name_Binder,
2815 In_Packages => The_Packages);
2817 Linker_Package : constant Prj.Package_Id :=
2819 (Name => Name_Linker,
2820 In_Packages => The_Packages);
2823 -- We fail if we cannot find the main source file
2824 -- as an immediate source of the main project file.
2826 if Main_Unit_File_Name = "" then
2827 Fail ('"' & Main_Source_File_Name &
2828 """ is not a unit of project " &
2829 Project_File_Name.all & ".");
2831 -- Remove any directory information from the main
2832 -- source file name.
2835 Pos : Natural := Main_Unit_File_Name'Last;
2839 exit when Pos < Main_Unit_File_Name'First or else
2840 Main_Unit_File_Name (Pos) = Directory_Separator;
2844 Name_Len := Main_Unit_File_Name'Last - Pos;
2846 Name_Buffer (1 .. Name_Len) :=
2848 (Pos + 1 .. Main_Unit_File_Name'Last);
2850 Main_Source_File := Name_Find;
2852 -- We only output the main source file if there is only one
2854 if Opt.Verbose_Mode and then Osint.Number_Of_Files = 1 then
2855 Write_Str ("Main source file: """);
2856 Write_Str (Main_Unit_File_Name
2857 (Pos + 1 .. Main_Unit_File_Name'Last));
2863 -- If there is a package gnatmake in the main project file, add
2864 -- the switches from it. We also add the switches from packages
2865 -- gnatbind and gnatlink, if any.
2867 if Gnatmake /= No_Package then
2869 -- If there is only one main, we attempt to get the gnatmake
2870 -- switches for this main (if any). If there are no specific
2871 -- switch for this particular main, get the general gnatmake
2872 -- switches (if any).
2874 if Osint.Number_Of_Files = 1 then
2875 if Opt.Verbose_Mode then
2876 Write_Str ("Adding gnatmake switches for """);
2877 Write_Str (Main_Unit_File_Name);
2882 (File_Name => Main_Unit_File_Name,
2883 The_Package => Gnatmake,
2887 -- If there are several mains, we always get the general
2888 -- gnatmake switches (if any).
2890 -- Note: As there is never a source with name " ",
2891 -- we are guaranteed to always get the gneneral switches.
2895 The_Package => Gnatmake,
2901 if Binder_Package /= No_Package then
2903 -- If there is only one main, we attempt to get the gnatbind
2904 -- switches for this main (if any). If there are no specific
2905 -- switch for this particular main, get the general gnatbind
2906 -- switches (if any).
2908 if Osint.Number_Of_Files = 1 then
2909 if Opt.Verbose_Mode then
2910 Write_Str ("Adding binder switches for """);
2911 Write_Str (Main_Unit_File_Name);
2916 (File_Name => Main_Unit_File_Name,
2917 The_Package => Binder_Package,
2921 -- If there are several mains, we always get the general
2922 -- gnatbind switches (if any).
2924 -- Note: As there is never a source with name " ",
2925 -- we are guaranteed to always get the gneneral switches.
2929 The_Package => Binder_Package,
2935 if Linker_Package /= No_Package then
2937 -- If there is only one main, we attempt to get the
2938 -- gnatlink switches for this main (if any). If there are
2939 -- no specific switch for this particular main, we get the
2940 -- general gnatlink switches (if any).
2942 if Osint.Number_Of_Files = 1 then
2943 if Opt.Verbose_Mode then
2944 Write_Str ("Adding linker switches for""");
2945 Write_Str (Main_Unit_File_Name);
2950 (File_Name => Main_Unit_File_Name,
2951 The_Package => Linker_Package,
2955 -- If there are several mains, we always get the general
2956 -- gnatlink switches (if any).
2958 -- Note: As there is never a source with name " ",
2959 -- we are guaranteed to always get the general switches.
2963 The_Package => Linker_Package,
2970 Display_Commands (not Opt.Quiet_Output);
2972 -- If we are using a project file, relative paths are forbidden in the
2973 -- project file, but we add the current working directory for any
2974 -- relative path on the command line.
2976 if Main_Project /= No_Project then
2978 for J in 1 .. Binder_Switches.Last loop
2979 Test_If_Relative_Path
2980 (Binder_Switches.Table (J), Parent => null);
2983 for J in 1 .. Saved_Binder_Switches.Last loop
2984 Test_If_Relative_Path
2985 (Saved_Binder_Switches.Table (J), Parent => Current_Work_Dir);
2988 for J in 1 .. Linker_Switches.Last loop
2989 Test_If_Relative_Path
2990 (Linker_Switches.Table (J), Parent => null);
2993 for J in 1 .. Saved_Linker_Switches.Last loop
2994 Test_If_Relative_Path
2995 (Saved_Linker_Switches.Table (J), Parent => Current_Work_Dir);
2998 for J in 1 .. Gcc_Switches.Last loop
2999 Test_If_Relative_Path
3000 (Gcc_Switches.Table (J), Parent => null);
3003 for J in 1 .. Saved_Gcc_Switches.Last loop
3004 Test_If_Relative_Path
3005 (Saved_Gcc_Switches.Table (J), Parent => Current_Work_Dir);
3009 -- We now put in the Binder_Switches and Linker_Switches tables,
3010 -- the binder and linker switches of the command line that have been
3011 -- put in the Saved_ tables. If a project file was used, then the
3012 -- command line switches will follow the project file switches.
3014 for J in 1 .. Saved_Binder_Switches.Last loop
3016 (Saved_Binder_Switches.Table (J),
3021 for J in 1 .. Saved_Linker_Switches.Last loop
3023 (Saved_Linker_Switches.Table (J),
3028 -- If no project file is used, we just put the gcc switches
3029 -- from the command line in the Gcc_Switches table.
3031 if Main_Project = No_Project then
3032 for J in 1 .. Saved_Gcc_Switches.Last loop
3034 (Saved_Gcc_Switches.Table (J),
3040 -- And we put the command line gcc switches in the variable
3041 -- The_Saved_Gcc_Switches. They are going to be used later
3042 -- in procedure Compile_Sources.
3044 The_Saved_Gcc_Switches :=
3045 new Argument_List (1 .. Saved_Gcc_Switches.Last + 1);
3047 for J in 1 .. Saved_Gcc_Switches.Last loop
3048 The_Saved_Gcc_Switches (J) := Saved_Gcc_Switches.Table (J);
3051 -- We never use gnat.adc when a project file is used
3053 The_Saved_Gcc_Switches (The_Saved_Gcc_Switches'Last) :=
3058 -- If there was a --GCC, --GNATBIND or --GNATLINK switch on
3059 -- the command line, then we have to use it, even if there was
3060 -- another switch in the project file.
3062 if Saved_Gcc /= null then
3066 if Saved_Gnatbind /= null then
3067 Gnatbind := Saved_Gnatbind;
3070 if Saved_Gnatlink /= null then
3071 Gnatlink := Saved_Gnatlink;
3074 Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
3075 Gnatbind_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
3076 Gnatlink_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
3078 -- If we have specified -j switch both from the project file
3079 -- and on the command line, the one from the command line takes
3082 if Saved_Maximum_Processes = 0 then
3083 Saved_Maximum_Processes := Opt.Maximum_Processes;
3086 -- Allocate as many temporary mapping file names as the maximum
3087 -- number of compilation processed.
3089 The_Mapping_File_Names :=
3090 new Temp_File_Names (1 .. Saved_Maximum_Processes);
3092 -- If either -c, -b or -l has been specified, we will not necessarily
3093 -- execute all steps.
3095 if Compile_Only or else Bind_Only or else Link_Only then
3096 Do_Compile_Step := Do_Compile_Step and Compile_Only;
3097 Do_Bind_Step := Do_Bind_Step and Bind_Only;
3098 Do_Link_Step := Do_Link_Step and Link_Only;
3100 -- If -c has been specified, but not -b, ignore any potential -l
3102 if Do_Compile_Step and then not Do_Bind_Step then
3103 Do_Link_Step := False;
3107 Bad_Compilation.Init;
3109 -- Here is where the make process is started
3111 -- We do the same process for each main
3113 Multiple_Main_Loop : for N_File in 1 .. Osint.Number_Of_Files loop
3115 if Do_Compile_Step then
3116 Recursive_Compilation_Step : declare
3117 Args : Argument_List (1 .. Gcc_Switches.Last);
3119 First_Compiled_File : Name_Id;
3121 Youngest_Obj_File : Name_Id;
3122 Youngest_Obj_Stamp : Time_Stamp_Type;
3124 Executable_Stamp : Time_Stamp_Type;
3125 -- Executable is the final executable program.
3128 Executable := No_File;
3129 Non_Std_Executable := False;
3131 for J in 1 .. Gcc_Switches.Last loop
3132 Args (J) := Gcc_Switches.Table (J);
3135 -- Look inside the linker switches to see if the name
3136 -- of the final executable program was specified.
3139 J in reverse Linker_Switches.First .. Linker_Switches.Last
3141 if Linker_Switches.Table (J).all = Output_Flag.all then
3142 pragma Assert (J < Linker_Switches.Last);
3144 -- We cannot specify a single executable for several
3145 -- main subprograms!
3147 if Osint.Number_Of_Files > 1 then
3149 ("cannot specify a single executable " &
3150 "for several mains");
3153 Name_Len := Linker_Switches.Table (J + 1)'Length;
3154 Name_Buffer (1 .. Name_Len) :=
3155 Linker_Switches.Table (J + 1).all;
3157 -- If target has an executable suffix and it has not been
3158 -- specified then it is added here.
3160 if Executable_Suffix'Length /= 0
3161 and then Linker_Switches.Table (J + 1)
3162 (Name_Len - Executable_Suffix'Length + 1
3163 .. Name_Len) /= Executable_Suffix
3165 Name_Buffer (Name_Len + 1 ..
3166 Name_Len + Executable_Suffix'Length) :=
3168 Name_Len := Name_Len + Executable_Suffix'Length;
3171 Executable := Name_Enter;
3173 Verbose_Msg (Executable, "final executable");
3177 -- If the name of the final executable program was not
3178 -- specified then construct it from the main input file.
3180 if Executable = No_File then
3181 if Main_Project = No_Project then
3183 Executable_Name (Strip_Suffix (Main_Source_File));
3186 -- If we are using a project file, we attempt to
3187 -- remove the body (or spec) termination of the main
3188 -- subprogram. We find it the the naming scheme of the
3189 -- project file. This will avoid to generate an
3190 -- executable "main.2" for a main subprogram
3191 -- "main.2.ada", when the body termination is ".2.ada".
3194 Body_Append : constant String :=
3198 Naming.Current_Impl_Suffix);
3200 Spec_Append : constant String :=
3204 Naming.Current_Spec_Suffix);
3207 Get_Name_String (Main_Source_File);
3209 if Name_Len > Body_Append'Length
3210 and then Name_Buffer
3211 (Name_Len - Body_Append'Length + 1 .. Name_Len) =
3214 -- We have found the body termination. We remove it
3215 -- add the executable termination, if any.
3217 Name_Len := Name_Len - Body_Append'Length;
3218 Executable := Executable_Name (Name_Find);
3220 elsif Name_Len > Spec_Append'Length
3223 (Name_Len - Spec_Append'Length + 1 .. Name_Len) =
3226 -- We have found the spec termination. We remove
3227 -- it, add the executable termination, if any.
3229 Name_Len := Name_Len - Spec_Append'Length;
3230 Executable := Executable_Name (Name_Find);
3234 Executable_Name (Strip_Suffix (Main_Source_File));
3241 if Main_Project /= No_Project then
3243 Exec_File_Name : constant String :=
3244 Get_Name_String (Executable);
3247 if not Is_Absolute_Path (Exec_File_Name) then
3248 for Index in Exec_File_Name'Range loop
3249 if Exec_File_Name (Index) = Directory_Separator then
3250 Fail ("relative executable (""" &
3252 """) with directory part not allowed " &
3253 "when using project files");
3257 Get_Name_String (Projects.Table
3258 (Main_Project).Exec_Directory);
3261 Name_Buffer (Name_Len) /= Directory_Separator
3263 Name_Len := Name_Len + 1;
3264 Name_Buffer (Name_Len) := Directory_Separator;
3267 Name_Buffer (Name_Len + 1 ..
3268 Name_Len + Exec_File_Name'Length) :=
3270 Name_Len := Name_Len + Exec_File_Name'Length;
3271 Executable := Name_Find;
3272 Non_Std_Executable := True;
3278 -- Now we invoke Compile_Sources for the current main
3281 (Main_Source => Main_Source_File,
3283 First_Compiled_File => First_Compiled_File,
3284 Most_Recent_Obj_File => Youngest_Obj_File,
3285 Most_Recent_Obj_Stamp => Youngest_Obj_Stamp,
3286 Main_Unit => Is_Main_Unit,
3287 Compilation_Failures => Compilation_Failures,
3288 Check_Readonly_Files => Opt.Check_Readonly_Files,
3289 Do_Not_Execute => Opt.Do_Not_Execute,
3290 Force_Compilations => Opt.Force_Compilations,
3291 In_Place_Mode => Opt.In_Place_Mode,
3292 Keep_Going => Opt.Keep_Going,
3293 Initialize_ALI_Data => True,
3294 Max_Process => Saved_Maximum_Processes);
3296 if Opt.Verbose_Mode then
3297 Write_Str ("End of compilation");
3301 Total_Compilation_Failures :=
3302 Total_Compilation_Failures + Compilation_Failures;
3304 if Total_Compilation_Failures /= 0 then
3305 if Opt.Keep_Going then
3309 List_Bad_Compilations;
3310 raise Compilation_Failed;
3314 -- Regenerate libraries, if any and if object files
3315 -- have been regenerated
3317 if Main_Project /= No_Project
3318 and then MLib.Tgt.Libraries_Are_Supported
3321 for Proj in Projects.First .. Projects.Last loop
3323 if Proj /= Main_Project
3324 and then Projects.Table (Proj).Flag1
3326 MLib.Prj.Build_Library (For_Project => Proj);
3333 if Opt.List_Dependencies then
3334 if First_Compiled_File /= No_File then
3336 (First_Compiled_File,
3337 "must be recompiled. Can't generate dependence list.");
3342 elsif First_Compiled_File = No_File
3343 and then not Do_Bind_Step
3344 and then not Opt.Quiet_Output
3345 and then Osint.Number_Of_Files = 1
3347 if Unique_Compile then
3348 Inform (Msg => "object up to date.");
3350 Inform (Msg => "objects up to date.");
3353 elsif Opt.Do_Not_Execute
3354 and then First_Compiled_File /= No_File
3356 Write_Name (First_Compiled_File);
3360 -- Stop after compile step if any of:
3362 -- 1) -n (Do_Not_Execute) specified
3364 -- 2) -M (List_Dependencies) specified (also sets
3365 -- Do_Not_Execute above, so this is probably superfluous).
3367 -- 3) -c (Compile_Only) specified, but not -b (Bind_Only)
3369 -- 4) Made unit cannot be a main unit
3371 if (Opt.Do_Not_Execute
3372 or Opt.List_Dependencies
3374 or not Is_Main_Unit)
3375 and then not No_Main_Subprogram
3377 if Osint.Number_Of_Files = 1 then
3378 exit Multiple_Main_Loop;
3385 -- If the objects were up-to-date check if the executable file
3386 -- is also up-to-date. For now always bind and link on the JVM
3387 -- since there is currently no simple way to check the
3388 -- up-to-date status of objects
3390 if not Hostparm.Java_VM
3391 and then First_Compiled_File = No_File
3393 Executable_Stamp := File_Stamp (Executable);
3395 -- Once Executable_Obsolete is set to True, it is never
3396 -- reset to False, because it is too hard to accurately
3397 -- decide if a subsequent main need to be rebuilt or not.
3399 Executable_Obsolete :=
3401 or else Youngest_Obj_Stamp > Executable_Stamp;
3403 if not Executable_Obsolete then
3405 -- If no Ada object files obsolete the executable, check
3406 -- for younger or missing linker files.
3408 Check_Linker_Options
3411 Youngest_Obj_Stamp);
3413 Executable_Obsolete := Youngest_Obj_File /= No_File;
3416 -- Return if the executable is up to date
3417 -- and otherwise motivate the relink/rebind.
3419 if not Executable_Obsolete then
3420 if not Opt.Quiet_Output then
3421 Inform (Executable, "up to date.");
3424 if Osint.Number_Of_Files = 1 then
3425 exit Multiple_Main_Loop;
3432 if Executable_Stamp (1) = ' ' then
3433 Verbose_Msg (Executable, "missing.", Prefix => " ");
3435 elsif Youngest_Obj_Stamp (1) = ' ' then
3441 elsif Youngest_Obj_Stamp > Executable_Stamp then
3444 "(" & String (Youngest_Obj_Stamp) & ") newer than",
3446 "(" & String (Executable_Stamp) & ")");
3450 (Executable, "needs to be rebuild.",
3455 end Recursive_Compilation_Step;
3458 -- If we are here, it means that we need to rebuilt the current
3459 -- main. So we set Executable_Obsolete to True to make sure that
3460 -- the subsequent mains will be rebuilt.
3462 Executable_Obsolete := True;
3464 Main_ALI_In_Place_Mode_Step :
3466 ALI_File : File_Name_Type;
3467 Src_File : File_Name_Type;
3470 Src_File := Strip_Directory (Main_Source_File);
3471 ALI_File := Lib_File_Name (Src_File);
3472 Main_ALI_File := Full_Lib_File_Name (ALI_File);
3474 -- When In_Place_Mode, the library file can be located in the
3475 -- Main_Source_File directory which may not be present in the
3476 -- library path. In this case, use the corresponding library file
3479 if Main_ALI_File = No_File and then Opt.In_Place_Mode then
3480 Get_Name_String (Get_Directory (Full_Source_Name (Src_File)));
3481 Get_Name_String_And_Append (ALI_File);
3482 Main_ALI_File := Name_Find;
3483 Main_ALI_File := Full_Lib_File_Name (Main_ALI_File);
3486 if Main_ALI_File = No_File then
3487 Fail ("could not find the main ALI file");
3490 end Main_ALI_In_Place_Mode_Step;
3492 if Do_Bind_Step then
3494 Args : Argument_List
3495 (Binder_Switches.First .. Binder_Switches.Last);
3498 -- Get all the binder switches
3500 for J in Binder_Switches.First .. Binder_Switches.Last loop
3501 Args (J) := Binder_Switches.Table (J);
3504 if Main_Project /= No_Project then
3506 -- Put all the source directories in ADA_INCLUDE_PATH,
3507 -- and all the object directories in ADA_OBJECTS_PATH
3509 Set_Ada_Paths (Main_Project, False);
3512 Bind (Main_ALI_File, Args);
3516 if Do_Link_Step then
3519 There_Are_Libraries : Boolean := False;
3520 Linker_Switches_Last : constant Integer := Linker_Switches.Last;
3523 if Main_Project /= No_Project then
3525 if MLib.Tgt.Libraries_Are_Supported then
3526 Set_Libraries (Main_Project, There_Are_Libraries);
3529 if There_Are_Libraries then
3531 -- Add -L<lib_dir> -lgnarl -lgnat -Wl,-rpath,<lib_dir>
3533 Linker_Switches.Increment_Last;
3534 Linker_Switches.Table (Linker_Switches.Last) :=
3535 new String'("-L" & MLib.Utl.Lib_Directory);
3536 Linker_Switches.Increment_Last;
3537 Linker_Switches.Table (Linker_Switches.Last) :=
3538 new String'("-lgnarl");
3539 Linker_Switches.Increment_Last;
3540 Linker_Switches.Table (Linker_Switches.Last) :=
3541 new String'("-lgnat");
3544 Option : constant String_Access :=
3545 MLib.Tgt.Linker_Library_Path_Option
3546 (MLib.Utl.Lib_Directory);
3549 if Option /= null then
3550 Linker_Switches.Increment_Last;
3551 Linker_Switches.Table (Linker_Switches.Last) :=
3557 -- Put the object directories in ADA_OBJECTS_PATH
3559 Set_Ada_Paths (Main_Project, False);
3563 Args : Argument_List
3564 (Linker_Switches.First .. Linker_Switches.Last + 2);
3566 Last_Arg : Integer := Linker_Switches.First - 1;
3567 Skip : Boolean := False;
3570 -- Get all the linker switches
3572 for J in Linker_Switches.First .. Linker_Switches.Last loop
3576 elsif Non_Std_Executable
3577 and then Linker_Switches.Table (J).all = "-o"
3582 Last_Arg := Last_Arg + 1;
3583 Args (Last_Arg) := Linker_Switches.Table (J);
3588 -- And invoke the linker
3590 if Non_Std_Executable then
3591 Last_Arg := Last_Arg + 1;
3592 Args (Last_Arg) := new String'("-o");
3593 Last_Arg := Last_Arg + 1;
3595 new String'(Get_Name_String (Executable));
3596 Link (Main_ALI_File, Args (Args'First .. Last_Arg));
3601 Args (Args'First .. Last_Arg));
3606 Linker_Switches.Set_Last (Linker_Switches_Last);
3610 -- We go to here when we skip the bind and link steps.
3614 -- We go to the next main, if we did not process the last one
3616 if N_File < Osint.Number_Of_Files then
3617 Main_Source_File := Next_Main_Source;
3619 if Main_Project /= No_Project then
3621 -- Find the file name of the main unit
3624 Main_Source_File_Name : constant String :=
3625 Get_Name_String (Main_Source_File);
3627 Main_Unit_File_Name : constant String :=
3629 File_Name_Of_Library_Unit_Body
3630 (Name => Main_Source_File_Name,
3631 Project => Main_Project);
3634 -- We fail if we cannot find the main source file
3635 -- as an immediate source of the main project file.
3637 if Main_Unit_File_Name = "" then
3638 Fail ('"' & Main_Source_File_Name &
3639 """ is not a unit of project " &
3640 Project_File_Name.all & ".");
3643 -- Remove any directory information from the main
3644 -- source file name.
3647 Pos : Natural := Main_Unit_File_Name'Last;
3651 exit when Pos < Main_Unit_File_Name'First
3653 Main_Unit_File_Name (Pos) = Directory_Separator;
3657 Name_Len := Main_Unit_File_Name'Last - Pos;
3659 Name_Buffer (1 .. Name_Len) :=
3661 (Pos + 1 .. Main_Unit_File_Name'Last);
3663 Main_Source_File := Name_Find;
3669 end loop Multiple_Main_Loop;
3671 if Total_Compilation_Failures /= 0 then
3672 List_Bad_Compilations;
3673 raise Compilation_Failed;
3676 -- Delete the temporary mapping file that was created if we are
3677 -- using project files.
3679 Delete_Mapping_Files;
3681 Exit_Program (E_Success);
3685 Delete_Mapping_Files;
3686 Osint.Fail ("*** bind failed.");
3688 when Compilation_Failed =>
3689 Delete_Mapping_Files;
3690 Exit_Program (E_Fatal);
3693 Delete_Mapping_Files;
3694 Osint.Fail ("*** link failed.");
3697 Delete_Mapping_Files;
3698 Write_Line (Exception_Information (X));
3699 Osint.Fail ("INTERNAL ERROR. Please report.");
3703 --------------------
3704 -- In_Ada_Lib_Dir --
3705 --------------------
3707 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean is
3708 D : constant Name_Id := Get_Directory (File);
3709 B : constant Byte := Get_Name_Table_Byte (D);
3712 return (B and Ada_Lib_Dir) /= 0;
3719 procedure Inform (N : Name_Id := No_Name; Msg : String) is
3721 Osint.Write_Program_Name;
3725 if N /= No_Name then
3735 -----------------------
3736 -- Init_Mapping_File --
3737 -----------------------
3739 procedure Init_Mapping_File (File_Name : in out Temp_File_Name) is
3740 FD : File_Descriptor;
3742 if Main_Project /= No_Project then
3743 Prj.Env.Create_Mapping_File (File_Name);
3746 Create_Temp_File (FD, File_Name);
3748 if FD = Invalid_FD then
3754 end Init_Mapping_File;
3762 First_Q_Initialization := False;
3764 Q.Set_Last (Q.First);
3771 procedure Initialize is
3772 Next_Arg : Positive;
3775 -- Override default initialization of Check_Object_Consistency
3776 -- since this is normally False for GNATBIND, but is True for
3777 -- GNATMAKE since we do not need to check source consistency
3778 -- again once GNATMAKE has looked at the sources to check.
3780 Opt.Check_Object_Consistency := True;
3782 -- Package initializations. The order of calls is important here.
3784 Output.Set_Standard_Error;
3787 Binder_Switches.Init;
3788 Linker_Switches.Init;
3798 Scan_Args : while Next_Arg <= Argument_Count loop
3799 Scan_Make_Arg (Argument (Next_Arg), And_Save => True);
3800 Next_Arg := Next_Arg + 1;
3803 if Usage_Requested then
3807 -- Test for trailing -o switch
3809 if Opt.Output_File_Name_Present
3810 and then not Output_File_Name_Seen
3812 Fail ("output file name missing after -o");
3815 if Project_File_Name /= null then
3817 -- A project file was specified by a -P switch
3819 if Opt.Verbose_Mode then
3821 Write_Str ("Parsing Project File """);
3822 Write_Str (Project_File_Name.all);
3827 -- Avoid looking in the current directory for ALI files
3829 -- Opt.Look_In_Primary_Dir := False;
3831 -- Set the project parsing verbosity to whatever was specified
3832 -- by a possible -vP switch.
3834 Prj.Pars.Set_Verbosity (To => Current_Verbosity);
3836 -- Parse the project file.
3837 -- If there is an error, Main_Project will still be No_Project.
3840 (Project => Main_Project,
3841 Project_File_Name => Project_File_Name.all);
3843 if Main_Project = No_Project then
3844 Fail ("""" & Project_File_Name.all &
3845 """ processing failed");
3848 if Opt.Verbose_Mode then
3850 Write_Str ("Parsing of Project File """);
3851 Write_Str (Project_File_Name.all);
3852 Write_Str (""" is finished.");
3856 -- We add the source directories and the object directories
3857 -- to the search paths.
3859 Add_Source_Directories (Main_Project);
3860 Add_Object_Directories (Main_Project);
3864 Osint.Add_Default_Search_Dirs;
3866 -- Mark the GNAT libraries if needed.
3868 -- Source file lookups should be cached for efficiency.
3869 -- Source files are not supposed to change.
3871 Osint.Source_File_Data (Cache => True);
3873 -- Read gnat.adc file to initialize Fname.UF
3875 Fname.UF.Initialize;
3878 Fname.SF.Read_Source_File_Name_Pragmas;
3881 when Err : SFN_Scan.Syntax_Error_In_GNAT_ADC =>
3882 Osint.Fail (Exception_Message (Err));
3886 -----------------------------------
3887 -- Insert_Project_Sources_Into_Q --
3888 -----------------------------------
3890 procedure Insert_Project_Sources
3891 (The_Project : Project_Id;
3894 Unit : Com.Unit_Data;
3898 -- For all the sources in the project files,
3900 for Id in Com.Units.First .. Com.Units.Last loop
3901 Unit := Com.Units.Table (Id);
3904 -- If there is a source for the body,
3906 if Unit.File_Names (Com.Body_Part).Name /= No_Name then
3908 -- And it is a source of the specified project
3910 if Unit.File_Names (Com.Body_Part).Project = The_Project then
3912 -- If we don't have a spec, we cannot consider the source
3913 -- if it is a subunit
3915 if Unit.File_Names (Com.Specification).Name = No_Name then
3917 Src_Ind : Source_File_Index;
3920 Src_Ind := Sinput.L.Load_Source_File
3921 (Unit.File_Names (Com.Body_Part).Name);
3923 -- If it is a subunit, discard it
3925 if Sinput.L.Source_File_Is_Subunit (Src_Ind) then
3929 Sfile := Unit.File_Names (Com.Body_Part).Name;
3934 Sfile := Unit.File_Names (Com.Body_Part).Name;
3938 elsif Unit.File_Names (Com.Specification).Name /= No_Name
3939 and then Unit.File_Names (Com.Specification).Project = The_Project
3941 -- If there is no source for the body, but there is a source
3942 -- for the spec, then we take this one.
3944 Sfile := Unit.File_Names (Com.Specification).Name;
3947 -- If Into_Q is True, we insert into the Q
3951 -- For the first source inserted into the Q, we need
3952 -- to initialize the Q, but not for the subsequent sources.
3954 if First_Q_Initialization then
3958 -- And of course, we only insert in the Q if the source
3961 if Sfile /= No_Name and then not Is_Marked (Sfile) then
3966 elsif Sfile /= No_Name then
3968 -- If Into_Q is False, we add the source as it it were
3969 -- specified on the command line.
3971 Osint.Add_File (Get_Name_String (Sfile));
3974 end Insert_Project_Sources;
3981 (Source_File : File_Name_Type;
3982 Source_Unit : Unit_Name_Type := No_Name)
3985 if Debug.Debug_Flag_Q then
3986 Write_Str (" Q := Q + [ ");
3987 Write_Name (Source_File);
3992 Q.Table (Q.Last).File := Source_File;
3993 Q.Table (Q.Last).Unit := Source_Unit;
3997 ----------------------------
3998 -- Is_External_Assignment --
3999 ----------------------------
4001 function Is_External_Assignment (Argv : String) return Boolean is
4002 Start : Positive := 3;
4003 Finish : Natural := Argv'Last;
4004 Equal_Pos : Natural;
4007 if Argv'Last < 5 then
4010 elsif Argv (3) = '"' then
4011 if Argv (Argv'Last) /= '"' or else Argv'Last < 7 then
4015 Finish := Argv'Last - 1;
4021 while Equal_Pos <= Finish and then Argv (Equal_Pos) /= '=' loop
4022 Equal_Pos := Equal_Pos + 1;
4025 if Equal_Pos = Start
4026 or else Equal_Pos >= Finish
4032 (External_Name => Argv (Start .. Equal_Pos - 1),
4033 Value => Argv (Equal_Pos + 1 .. Finish));
4036 end Is_External_Assignment;
4042 function Is_Marked (Source_File : File_Name_Type) return Boolean is
4044 return Get_Name_Table_Byte (Source_File) /= 0;
4051 procedure Link (ALI_File : File_Name_Type; Args : Argument_List) is
4052 Link_Args : Argument_List (Args'First .. Args'Last + 1);
4056 Link_Args (Args'Range) := Args;
4058 Get_Name_String (ALI_File);
4059 Link_Args (Args'Last + 1) := new String'(Name_Buffer (1 .. Name_Len));
4061 GNAT.OS_Lib.Normalize_Arguments (Link_Args);
4063 Display (Gnatlink.all, Link_Args);
4065 if Gnatlink_Path = null then
4066 Osint.Fail ("error, unable to locate " & Gnatlink.all);
4069 GNAT.OS_Lib.Spawn (Gnatlink_Path.all, Link_Args, Success);
4076 ---------------------------
4077 -- List_Bad_Compilations --
4078 ---------------------------
4080 procedure List_Bad_Compilations is
4082 for J in Bad_Compilation.First .. Bad_Compilation.Last loop
4083 if Bad_Compilation.Table (J).File = No_File then
4085 elsif not Bad_Compilation.Table (J).Found then
4086 Inform (Bad_Compilation.Table (J).File, "not found");
4088 Inform (Bad_Compilation.Table (J).File, "compilation error");
4091 end List_Bad_Compilations;
4097 procedure List_Depend is
4104 Line_Size : constant := 77;
4107 Set_Standard_Output;
4109 for A in ALIs.First .. ALIs.Last loop
4110 Lib_Name := ALIs.Table (A).Afile;
4112 -- We have to provide the full library file name in In_Place_Mode
4114 if Opt.In_Place_Mode then
4115 Lib_Name := Full_Lib_File_Name (Lib_Name);
4118 Obj_Name := Object_File_Name (Lib_Name);
4119 Write_Name (Obj_Name);
4122 Get_Name_String (Obj_Name);
4124 Line_Pos := Len + 2;
4126 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
4127 Src_Name := Sdep.Table (D).Sfile;
4129 if Is_Internal_File_Name (Src_Name)
4130 and then not Check_Readonly_Files
4134 if not Opt.Quiet_Output then
4135 Src_Name := Full_Source_Name (Src_Name);
4138 Get_Name_String (Src_Name);
4141 if Line_Pos + Len + 1 > Line_Size then
4147 Line_Pos := Line_Pos + Len + 1;
4150 Write_Name (Src_Name);
4164 procedure Mark (Source_File : File_Name_Type) is
4166 Set_Name_Table_Byte (Source_File, 1);
4169 --------------------
4170 -- Mark_Directory --
4171 --------------------
4173 procedure Mark_Directory
4175 Mark : Lib_Mark_Type)
4181 -- Dir last character is supposed to be a directory separator.
4183 Name_Len := Dir'Length;
4184 Name_Buffer (1 .. Name_Len) := Dir;
4186 if not Is_Directory_Separator (Name_Buffer (Name_Len)) then
4187 Name_Len := Name_Len + 1;
4188 Name_Buffer (Name_Len) := Directory_Separator;
4191 -- Add flags to the already existing flags
4194 B := Get_Name_Table_Byte (N);
4195 Set_Name_Table_Byte (N, B or Mark);
4198 ----------------------
4199 -- Object_File_Name --
4200 ----------------------
4202 function Object_File_Name (Source : String) return String is
4204 -- If the source name has an extension, then replace it with
4205 -- the object suffix.
4207 for Index in reverse Source'First + 1 .. Source'Last loop
4208 if Source (Index) = '.' then
4209 return Source (Source'First .. Index - 1) & Object_Suffix;
4213 -- If there is no dot, or if it is the first character, just add the
4216 return Source & Object_Suffix;
4217 end Object_File_Name;
4223 procedure Scan_Make_Arg (Argv : String; And_Save : Boolean) is
4225 pragma Assert (Argv'First = 1);
4227 if Argv'Length = 0 then
4231 -- If the previous switch has set the Output_File_Name_Present
4232 -- flag (that is we have seen a -o), then the next argument is
4233 -- the name of the output executable.
4235 if Opt.Output_File_Name_Present and then not Output_File_Name_Seen then
4236 Output_File_Name_Seen := True;
4238 if Argv (1) = '-' then
4239 Fail ("output file name missing after -o");
4242 Add_Switch ("-o", Linker, And_Save => And_Save);
4244 -- Automatically add the executable suffix if it has not been
4245 -- specified explicitly.
4247 if Executable_Suffix'Length /= 0
4248 and then Argv (Argv'Last - Executable_Suffix'Length + 1
4249 .. Argv'Last) /= Executable_Suffix
4252 (Argv & Executable_Suffix,
4254 And_Save => And_Save);
4256 Add_Switch (Argv, Linker, And_Save => And_Save);
4260 -- Then check if we are dealing with -cargs/-bargs/-largs
4262 elsif Argv = "-bargs"
4271 when 'c' => Program_Args := Compiler;
4272 when 'b' => Program_Args := Binder;
4273 when 'l' => Program_Args := Linker;
4274 when 'm' => Program_Args := None;
4277 raise Program_Error;
4280 -- A special test is needed for the -o switch within a -largs
4281 -- since that is another way to specify the name of the final
4284 elsif Program_Args = Linker
4285 and then Argv = "-o"
4287 Fail ("switch -o not allowed within a -largs. Use -o directly.");
4289 -- Check to see if we are reading switches after a -cargs,
4290 -- -bargs or -largs switch. If yes save it.
4292 elsif Program_Args /= None then
4294 -- Check to see if we are reading -I switches in order
4295 -- to take into account in the src & lib search directories.
4297 if Argv'Length > 2 and then Argv (1 .. 2) = "-I" then
4298 if Argv (3 .. Argv'Last) = "-" then
4299 Opt.Look_In_Primary_Dir := False;
4301 elsif Program_Args = Compiler then
4302 if Argv (3 .. Argv'Last) /= "-" then
4303 Add_Src_Search_Dir (Argv (3 .. Argv'Last));
4307 elsif Program_Args = Binder then
4308 Add_Lib_Search_Dir (Argv (3 .. Argv'Last));
4313 Add_Switch (Argv, Program_Args, And_Save => And_Save);
4315 -- Handle non-default compiler, binder, linker, and handle --RTS switch
4317 elsif Argv'Length > 2 and then Argv (1 .. 2) = "--" then
4319 and then Argv (1 .. 6) = "--GCC="
4322 Program_Args : Argument_List_Access :=
4323 Argument_String_To_List
4324 (Argv (7 .. Argv'Last));
4328 Saved_Gcc := new String'(Program_Args.all (1).all);
4330 Gcc := new String'(Program_Args.all (1).all);
4333 for J in 2 .. Program_Args.all'Last loop
4335 (Program_Args.all (J).all,
4337 And_Save => And_Save);
4341 elsif Argv'Length > 11
4342 and then Argv (1 .. 11) = "--GNATBIND="
4345 Program_Args : Argument_List_Access :=
4346 Argument_String_To_List
4347 (Argv (12 .. Argv'Last));
4351 Saved_Gnatbind := new String'(Program_Args.all (1).all);
4353 Gnatbind := new String'(Program_Args.all (1).all);
4356 for J in 2 .. Program_Args.all'Last loop
4358 (Program_Args.all (J).all, Binder, And_Save => And_Save);
4362 elsif Argv'Length > 11
4363 and then Argv (1 .. 11) = "--GNATLINK="
4366 Program_Args : Argument_List_Access :=
4367 Argument_String_To_List
4368 (Argv (12 .. Argv'Last));
4371 Saved_Gnatlink := new String'(Program_Args.all (1).all);
4373 Gnatlink := new String'(Program_Args.all (1).all);
4376 for J in 2 .. Program_Args.all'Last loop
4377 Add_Switch (Program_Args.all (J).all, Linker);
4381 elsif Argv'Length >= 5 and then
4382 Argv (1 .. 5) = "--RTS"
4384 Add_Switch (Argv, Compiler, And_Save => And_Save);
4385 Add_Switch (Argv, Binder, And_Save => And_Save);
4387 if Argv'Length <= 6 or else Argv (6) /= '=' then
4388 Osint.Fail ("missing path for --RTS");
4391 -- Valid --RTS switch
4393 Opt.No_Stdinc := True;
4394 Opt.No_Stdlib := True;
4395 Opt.RTS_Switch := True;
4398 Src_Path_Name : String_Ptr :=
4400 (Argv (7 .. Argv'Last), Include);
4401 Lib_Path_Name : String_Ptr :=
4403 (Argv (7 .. Argv'Last), Objects);
4406 if Src_Path_Name /= null and then
4407 Lib_Path_Name /= null
4409 Add_Search_Dirs (Src_Path_Name, Include);
4410 Add_Search_Dirs (Lib_Path_Name, Objects);
4412 elsif Src_Path_Name = null
4413 and Lib_Path_Name = null then
4414 Osint.Fail ("RTS path not valid: missing " &
4415 "adainclude and adalib directories");
4417 elsif Src_Path_Name = null then
4418 Osint.Fail ("RTS path not valid: missing " &
4419 "adainclude directory");
4421 elsif Lib_Path_Name = null then
4422 Osint.Fail ("RTS path not valid: missing " &
4423 "adalib directory");
4429 Fail ("unknown switch: ", Argv);
4432 -- If we have seen a regular switch process it
4434 elsif Argv (1) = '-' then
4436 if Argv'Length = 1 then
4437 Fail ("switch character cannot be followed by a blank");
4441 elsif Argv (2 .. Argv'Last) = "I-" then
4442 Opt.Look_In_Primary_Dir := False;
4444 -- Forbid -?- or -??- where ? is any character
4446 elsif (Argv'Length = 3 and then Argv (3) = '-')
4447 or else (Argv'Length = 4 and then Argv (4) = '-')
4449 Fail ("trailing ""-"" at the end of ", Argv, " forbidden.");
4453 elsif Argv (2) = 'I' then
4454 Add_Src_Search_Dir (Argv (3 .. Argv'Last));
4455 Add_Lib_Search_Dir (Argv (3 .. Argv'Last));
4456 Add_Switch (Argv, Compiler, And_Save => And_Save);
4457 Add_Switch ("-aO" & Argv (3 .. Argv'Last),
4459 And_Save => And_Save);
4461 -- No need to pass any source dir to the binder
4462 -- since gnatmake call it with the -x flag
4463 -- (ie do not check source time stamp)
4465 -- -aIdir (to gcc this is like a -I switch)
4467 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aI" then
4468 Add_Src_Search_Dir (Argv (4 .. Argv'Last));
4469 Add_Switch ("-I" & Argv (4 .. Argv'Last),
4471 And_Save => And_Save);
4475 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aO" then
4476 Add_Lib_Search_Dir (Argv (4 .. Argv'Last));
4477 Add_Switch (Argv, Binder, And_Save => And_Save);
4479 -- -aLdir (to gnatbind this is like a -aO switch)
4481 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aL" then
4482 Mark_Directory (Argv (4 .. Argv'Last), Ada_Lib_Dir);
4483 Add_Lib_Search_Dir (Argv (4 .. Argv'Last));
4484 Add_Switch ("-aO" & Argv (4 .. Argv'Last),
4486 And_Save => And_Save);
4488 -- -Adir (to gnatbind this is like a -aO switch, to gcc like a -I)
4490 elsif Argv (2) = 'A' then
4491 Mark_Directory (Argv (3 .. Argv'Last), Ada_Lib_Dir);
4492 Add_Src_Search_Dir (Argv (3 .. Argv'Last));
4493 Add_Lib_Search_Dir (Argv (3 .. Argv'Last));
4494 Add_Switch ("-I" & Argv (3 .. Argv'Last),
4496 And_Save => And_Save);
4497 Add_Switch ("-aO" & Argv (3 .. Argv'Last),
4499 And_Save => And_Save);
4503 elsif Argv (2) = 'L' then
4504 Add_Switch (Argv, Linker, And_Save => And_Save);
4506 -- For -gxxxxx,-pg : give the switch to both the compiler and the
4507 -- linker (except for -gnatxxx which is only for the compiler)
4510 (Argv (2) = 'g' and then (Argv'Last < 5
4511 or else Argv (2 .. 5) /= "gnat"))
4512 or else Argv (2 .. Argv'Last) = "pg"
4514 Add_Switch (Argv, Compiler, And_Save => And_Save);
4515 Add_Switch (Argv, Linker, And_Save => And_Save);
4519 elsif Argv (2) = 'd'
4520 and then Argv'Last = 2
4522 Opt.Display_Compilation_Progress := True;
4524 -- -j (need to save the result)
4526 elsif Argv (2) = 'j' then
4527 Scan_Make_Switches (Argv);
4530 Saved_Maximum_Processes := Maximum_Processes;
4535 elsif Argv (2) = 'm'
4536 and then Argv'Last = 2
4538 Opt.Minimal_Recompilation := True;
4542 elsif Argv (2) = 'u'
4543 and then Argv'Last = 2
4545 Unique_Compile := True;
4546 Opt.Compile_Only := True;
4547 Do_Bind_Step := False;
4548 Do_Link_Step := False;
4550 -- -Pprj (only once, and only on the command line)
4553 and then Argv (2) = 'P'
4555 if Project_File_Name /= null then
4556 Fail ("cannot have several project files specified");
4558 elsif not And_Save then
4560 -- It could be a tool other than gnatmake (i.e, gnatdist)
4561 -- or a -P switch inside a project file.
4564 ("either the tool is not ""project-aware"" or " &
4565 "a project file is specified inside a project file");
4568 Project_File_Name := new String' (Argv (3 .. Argv'Last));
4573 -- Since no object file is created, don't check object
4576 elsif Argv (2) = 'S'
4577 and then Argv'Last = 2
4579 Opt.Check_Object_Consistency := False;
4580 Add_Switch (Argv, Compiler, And_Save => And_Save);
4582 -- -vPx (verbosity of the parsing of the project files)
4585 and then Argv (2 .. 3) = "vP"
4586 and then Argv (4) in '0' .. '2'
4591 Current_Verbosity := Prj.Default;
4593 Current_Verbosity := Prj.Medium;
4595 Current_Verbosity := Prj.High;
4601 -- -Wx (need to save the result)
4603 elsif Argv (2) = 'W' then
4604 Scan_Make_Switches (Argv);
4607 Saved_WC_Encoding_Method := Wide_Character_Encoding_Method;
4608 Saved_WC_Encoding_Method_Set := True;
4611 -- -Xext=val (External assignment)
4613 elsif Argv (2) = 'X'
4614 and then Is_External_Assignment (Argv)
4616 -- Is_External_Assignment has side effects
4617 -- when it returns True;
4621 -- If -gnath is present, then generate the usage information
4622 -- right now and do not pass this option on to the compiler calls.
4624 elsif Argv = "-gnath" then
4627 -- If -gnatc is specified, make sure the bind step and the link
4628 -- step are not executed.
4630 elsif Argv'Length >= 6 and then Argv (2 .. 6) = "gnatc" then
4632 -- If -gnatc is specified, make sure the bind step and the link
4633 -- step are not executed.
4635 Add_Switch (Argv, Compiler, And_Save => And_Save);
4636 Opt.Operating_Mode := Opt.Check_Semantics;
4637 Opt.Check_Object_Consistency := False;
4638 Opt.Compile_Only := True;
4639 Do_Bind_Step := False;
4640 Do_Link_Step := False;
4642 elsif Argv (2 .. Argv'Last) = "nostdlib" then
4644 -- Don't pass -nostdlib to gnatlink, it will disable
4645 -- linking with all standard library files.
4647 Opt.No_Stdlib := True;
4648 Add_Switch (Argv, Binder, And_Save => And_Save);
4650 elsif Argv (2 .. Argv'Last) = "nostdinc" then
4652 -- Pass -nostdinv to the Compiler and to gnatbind
4654 Opt.No_Stdinc := True;
4655 Add_Switch (Argv, Compiler, And_Save => And_Save);
4656 Add_Switch (Argv, Binder, And_Save => And_Save);
4658 -- By default all switches with more than one character
4659 -- or one character switches which are not in 'a' .. 'z'
4660 -- (except 'C' and 'M') are passed to the compiler, unless we are
4661 -- dealing with a debug switch (starts with 'd')
4663 elsif Argv (2) /= 'd'
4664 and then Argv (2 .. Argv'Last) /= "M"
4665 and then Argv (2 .. Argv'Last) /= "C"
4666 and then (Argv'Length > 2 or else Argv (2) not in 'a' .. 'z')
4668 Add_Switch (Argv, Compiler, And_Save => And_Save);
4670 -- All other options are handled by Scan_Make_Switches
4673 Scan_Make_Switches (Argv);
4676 -- If not a switch it must be a file name
4687 procedure Set_Ada_Paths
4688 (For_Project : Prj.Project_Id;
4689 Including_Libraries : Boolean)
4691 New_Ada_Include_Path : constant String_Access :=
4692 Prj.Env.Ada_Include_Path (For_Project);
4694 New_Ada_Objects_Path : constant String_Access :=
4695 Prj.Env.Ada_Objects_Path
4696 (For_Project, Including_Libraries);
4699 -- If ADA_INCLUDE_PATH needs to be changed (we are not using the same
4700 -- project file), set the new ADA_INCLUDE_PATH
4702 if New_Ada_Include_Path /= Current_Ada_Include_Path then
4703 Current_Ada_Include_Path := New_Ada_Include_Path;
4705 if Original_Ada_Include_Path'Length = 0 then
4706 Setenv ("ADA_INCLUDE_PATH",
4707 New_Ada_Include_Path.all);
4710 -- If there existed an ADA_INCLUDE_PATH at the invocation of
4711 -- gnatmake, concatenate new ADA_INCLUDE_PATH with the original.
4713 Setenv ("ADA_INCLUDE_PATH",
4714 Original_Ada_Include_Path.all &
4716 New_Ada_Include_Path.all);
4719 if Opt.Verbose_Mode then
4721 Include_Path : constant String_Access :=
4722 Getenv ("ADA_INCLUDE_PATH");
4725 -- Display the new ADA_INCLUDE_PATH
4727 Write_Str ("ADA_INCLUDE_PATH = """);
4729 (S => Include_Path.all,
4730 Max_Length => Max_Line_Length,
4731 Separator => Path_Separator);
4738 -- If ADA_OBJECTS_PATH needs to be changed (we are not using the same
4739 -- project file), set the new ADA_OBJECTS_PATH
4741 if New_Ada_Objects_Path /= Current_Ada_Objects_Path then
4742 Current_Ada_Objects_Path := New_Ada_Objects_Path;
4744 if Original_Ada_Objects_Path'Length = 0 then
4745 Setenv ("ADA_OBJECTS_PATH",
4746 New_Ada_Objects_Path.all);
4749 -- If there existed an ADA_OBJECTS_PATH at the invocation of
4750 -- gnatmake, concatenate new ADA_OBJECTS_PATH with the original.
4752 Setenv ("ADA_OBJECTS_PATH",
4753 Original_Ada_Objects_Path.all &
4755 New_Ada_Objects_Path.all);
4758 if Opt.Verbose_Mode then
4760 Objects_Path : constant String_Access :=
4761 Getenv ("ADA_OBJECTS_PATH");
4764 -- Display the new ADA_OBJECTS_PATH
4766 Write_Str ("ADA_OBJECTS_PATH = """);
4768 (S => Objects_Path.all,
4769 Max_Length => Max_Line_Length,
4770 Separator => Path_Separator);
4779 ---------------------
4780 -- Set_Library_For --
4781 ---------------------
4783 procedure Set_Library_For
4784 (Project : Project_Id;
4785 There_Are_Libraries : in out Boolean)
4788 -- Case of library project
4790 if Projects.Table (Project).Library then
4791 There_Are_Libraries := True;
4793 -- Add the -L switch
4795 Linker_Switches.Increment_Last;
4796 Linker_Switches.Table (Linker_Switches.Last) :=
4799 (Projects.Table (Project).Library_Dir));
4801 -- Add the -l switch
4803 Linker_Switches.Increment_Last;
4804 Linker_Switches.Table (Linker_Switches.Last) :=
4807 (Projects.Table (Project).Library_Name));
4809 -- Add the Wl,-rpath switch if library non static
4811 if Projects.Table (Project).Library_Kind /= Static then
4813 Option : constant String_Access :=
4814 MLib.Tgt.Linker_Library_Path_Option
4816 (Projects.Table (Project).Library_Dir));
4819 if Option /= null then
4820 Linker_Switches.Increment_Last;
4821 Linker_Switches.Table (Linker_Switches.Last) :=
4830 end Set_Library_For;
4836 function Switches_Of
4837 (Source_File : Name_Id;
4838 Source_File_Name : String;
4839 Naming : Naming_Data;
4840 In_Package : Package_Id;
4841 Allow_ALI : Boolean)
4842 return Variable_Value
4844 Switches : Variable_Value;
4846 Defaults : constant Array_Element_Id :=
4848 (Name => Name_Default_Switches,
4850 Packages.Table (In_Package).Decl.Arrays);
4852 Switches_Array : constant Array_Element_Id :=
4854 (Name => Name_Switches,
4856 Packages.Table (In_Package).Decl.Arrays);
4861 (Index => Source_File,
4862 In_Array => Switches_Array);
4864 if Switches = Nil_Variable_Value then
4866 Name : String (1 .. Source_File_Name'Length + 3);
4867 Last : Positive := Source_File_Name'Length;
4868 Spec_Suffix : constant String :=
4869 Get_Name_String (Naming.Current_Spec_Suffix);
4870 Impl_Suffix : constant String :=
4871 Get_Name_String (Naming.Current_Impl_Suffix);
4872 Truncated : Boolean := False;
4875 Name (1 .. Last) := Source_File_Name;
4877 if Last > Impl_Suffix'Length
4878 and then Name (Last - Impl_Suffix'Length + 1 .. Last) =
4882 Last := Last - Impl_Suffix'Length;
4886 and then Last > Spec_Suffix'Length
4887 and then Name (Last - Spec_Suffix'Length + 1 .. Last) =
4891 Last := Last - Spec_Suffix'Length;
4896 Name_Buffer (1 .. Name_Len) := Name (1 .. Last);
4899 (Index => Name_Find,
4900 In_Array => Switches_Array);
4902 if Switches = Nil_Variable_Value
4905 Last := Source_File_Name'Length;
4907 while Name (Last) /= '.' loop
4911 Name (Last + 1 .. Last + 3) := "ali";
4912 Name_Len := Last + 3;
4913 Name_Buffer (1 .. Name_Len) := Name (1 .. Name_Len);
4916 (Index => Name_Find,
4917 In_Array => Switches_Array);
4923 if Switches = Nil_Variable_Value then
4924 Switches := Prj.Util.Value_Of
4925 (Index => Name_Ada, In_Array => Defaults);
4931 ---------------------------
4932 -- Test_If_Relative_Path --
4933 ---------------------------
4935 procedure Test_If_Relative_Path
4936 (Switch : in out String_Access;
4937 Parent : String_Access)
4940 if Switch /= null then
4943 Sw : String (1 .. Switch'Length);
4949 if Sw (1) = '-' then
4951 and then (Sw (2) = 'A'
4952 or else Sw (2) = 'I'
4953 or else Sw (2) = 'L')
4961 elsif Sw'Length >= 4
4962 and then (Sw (2 .. 3) = "aL"
4963 or else Sw (2 .. 3) = "aO"
4964 or else Sw (2 .. 3) = "aI")
4968 elsif Sw'Length >= 7
4969 and then Sw (2 .. 6) = "-RTS="
4976 if not Is_Absolute_Path (Sw (Start .. Sw'Last)) then
4977 if Parent = null then
4978 Fail ("relative search path switches (""" & Sw &
4979 """) are not allowed inside project files");
4984 (Sw (1 .. Start - 1) &
4986 Directory_Separator &
4987 Sw (Start .. Sw'Last));
4993 end Test_If_Relative_Path;
5001 if Usage_Needed then
5002 Usage_Needed := False;
5011 procedure Verbose_Msg
5014 N2 : Name_Id := No_Name;
5016 Prefix : String := " -> ")
5019 if not Opt.Verbose_Mode then
5029 if N2 /= No_Name then