* gnu/regexp/CharIndexedReader.java: Removed.
[official-gcc.git] / gcc / ada / make.adb
bloba4b2a41ff9fdc1df6e8391f34c62486b3782ef2c
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- M A K E --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2004 Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 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. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
27 with ALI; use ALI;
28 with ALI.Util; use ALI.Util;
29 with Csets;
30 with Debug;
31 with Fmap;
32 with Fname; use Fname;
33 with Fname.SF; use Fname.SF;
34 with Fname.UF; use Fname.UF;
35 with Gnatvsn; use Gnatvsn;
36 with Hostparm; use Hostparm;
37 with Makeusg;
38 with Makeutl; use Makeutl;
39 with MLib.Prj;
40 with MLib.Tgt; use MLib.Tgt;
41 with MLib.Utl;
42 with Namet; use Namet;
43 with Opt; use Opt;
44 with Osint.M; use Osint.M;
45 with Osint; use Osint;
46 with Gnatvsn;
47 with Output; use Output;
48 with Prj; use Prj;
49 with Prj.Com;
50 with Prj.Env;
51 with Prj.Pars;
52 with Prj.Util;
53 with SFN_Scan;
54 with Sinput.P;
55 with Snames; use Snames;
56 with Switch; use Switch;
57 with Switch.M; use Switch.M;
58 with Targparm;
59 with Tempdir;
61 with Ada.Exceptions; use Ada.Exceptions;
62 with Ada.Command_Line; use Ada.Command_Line;
64 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
65 with GNAT.Case_Util; use GNAT.Case_Util;
67 with System.HTable;
69 package body Make is
71 use ASCII;
72 -- Make control characters visible
74 Standard_Library_Package_Body_Name : constant String := "s-stalib.adb";
75 -- Every program depends on this package, that must then be checked,
76 -- especially when -f and -a are used.
78 type Sigint_Handler is access procedure;
80 procedure Install_Int_Handler (Handler : Sigint_Handler);
81 pragma Import (C, Install_Int_Handler, "__gnat_install_int_handler");
82 -- Called by Gnatmake to install the SIGINT handler below
84 procedure Sigint_Intercepted;
85 -- Called when the program is interrupted by Ctrl-C to delete the
86 -- temporary mapping files and configuration pragmas files.
88 -------------------------
89 -- Note on terminology --
90 -------------------------
92 -- In this program, we use the phrase "termination" of a file name to
93 -- refer to the suffix that appears after the unit name portion. Very
94 -- often this is simply the extension, but in some cases, the sequence
95 -- may be more complex, for example in main.1.ada, the termination in
96 -- this name is ".1.ada" and in main_.ada the termination is "_.ada".
98 -------------------------------------
99 -- Queue (Q) Manipulation Routines --
100 -------------------------------------
102 -- The Q is used in Compile_Sources below. Its implementation uses the
103 -- GNAT generic package Table (basically an extensible array). Q_Front
104 -- points to the first valid element in the Q, whereas Q.First is the first
105 -- element ever enqueued, while Q.Last - 1 is the last element in the Q.
107 -- +---+--------------+---+---+---+-----------+---+--------
108 -- Q | | ........ | | | | ....... | |
109 -- +---+--------------+---+---+---+-----------+---+--------
110 -- ^ ^ ^
111 -- Q.First Q_Front Q.Last - 1
113 -- The elements comprised between Q.First and Q_Front - 1 are the
114 -- elements that have been enqueued and then dequeued, while the
115 -- elements between Q_Front and Q.Last - 1 are the elements currently
116 -- in the Q. When the Q is initialized Q_Front = Q.First = Q.Last.
117 -- After Compile_Sources has terminated its execution, Q_Front = Q.Last
118 -- and the elements contained between Q.Front and Q.Last-1 are those that
119 -- were explored and thus marked by Compile_Sources. Whenever the Q is
120 -- reinitialized, the elements between Q.First and Q.Last - 1 are unmarked.
122 procedure Init_Q;
123 -- Must be called to (re)initialize the Q.
125 procedure Insert_Q
126 (Source_File : File_Name_Type;
127 Source_Unit : Unit_Name_Type := No_Name;
128 Index : Int := 0);
129 -- Inserts Source_File at the end of Q. Provide Source_Unit when possible
130 -- for external use (gnatdist). Provide index for multi-unit sources.
132 function Empty_Q return Boolean;
133 -- Returns True if Q is empty.
135 procedure Extract_From_Q
136 (Source_File : out File_Name_Type;
137 Source_Unit : out Unit_Name_Type;
138 Source_Index : out Int);
139 -- Extracts the first element from the Q.
141 procedure Insert_Project_Sources
142 (The_Project : Project_Id;
143 All_Projects : Boolean;
144 Into_Q : Boolean);
145 -- If Into_Q is True, insert all sources of the project file(s) that are
146 -- not already marked into the Q. If Into_Q is False, call Osint.Add_File
147 -- for the first source, then insert all other sources that are not already
148 -- marked into the Q. If All_Projects is True, all sources of all projects
149 -- are concerned; otherwise, only sources of The_Project are concerned,
150 -- including, if The_Project is an extending project, sources inherited
151 -- from projects being extended.
153 First_Q_Initialization : Boolean := True;
154 -- Will be set to false after Init_Q has been called once.
156 Q_Front : Natural;
157 -- Points to the first valid element in the Q.
159 Unique_Compile : Boolean := False;
160 -- Set to True if -u or -U or a project file with no main is used
162 Unique_Compile_All_Projects : Boolean := False;
163 -- Set to True if -U is used
165 RTS_Specified : String_Access := null;
166 -- Used to detect multiple --RTS= switches
168 type Q_Record is record
169 File : File_Name_Type;
170 Unit : Unit_Name_Type;
171 Index : Int;
172 end record;
173 -- File is the name of the file to compile. Unit is for gnatdist
174 -- use in order to easily get the unit name of a file to compile
175 -- when its name is krunched or declared in gnat.adc. Index, when not 0,
176 -- is the index of the unit in a multi-unit source.
178 package Q is new Table.Table (
179 Table_Component_Type => Q_Record,
180 Table_Index_Type => Natural,
181 Table_Low_Bound => 0,
182 Table_Initial => 4000,
183 Table_Increment => 100,
184 Table_Name => "Make.Q");
185 -- This is the actual Q.
187 -- The following instantiations and variables are necessary to save what
188 -- is found on the command line, in case there is a project file specified.
190 package Saved_Gcc_Switches is new Table.Table (
191 Table_Component_Type => String_Access,
192 Table_Index_Type => Integer,
193 Table_Low_Bound => 1,
194 Table_Initial => 20,
195 Table_Increment => 100,
196 Table_Name => "Make.Saved_Gcc_Switches");
198 package Saved_Binder_Switches is new Table.Table (
199 Table_Component_Type => String_Access,
200 Table_Index_Type => Integer,
201 Table_Low_Bound => 1,
202 Table_Initial => 20,
203 Table_Increment => 100,
204 Table_Name => "Make.Saved_Binder_Switches");
206 package Saved_Linker_Switches is new Table.Table
207 (Table_Component_Type => String_Access,
208 Table_Index_Type => Integer,
209 Table_Low_Bound => 1,
210 Table_Initial => 20,
211 Table_Increment => 100,
212 Table_Name => "Make.Saved_Linker_Switches");
214 package Switches_To_Check is new Table.Table (
215 Table_Component_Type => String_Access,
216 Table_Index_Type => Integer,
217 Table_Low_Bound => 1,
218 Table_Initial => 20,
219 Table_Increment => 100,
220 Table_Name => "Make.Switches_To_Check");
222 package Library_Paths is new Table.Table (
223 Table_Component_Type => String_Access,
224 Table_Index_Type => Integer,
225 Table_Low_Bound => 1,
226 Table_Initial => 20,
227 Table_Increment => 100,
228 Table_Name => "Make.Library_Paths");
230 package Failed_Links is new Table.Table (
231 Table_Component_Type => File_Name_Type,
232 Table_Index_Type => Integer,
233 Table_Low_Bound => 1,
234 Table_Initial => 10,
235 Table_Increment => 100,
236 Table_Name => "Make.Failed_Links");
238 package Successful_Links is new Table.Table (
239 Table_Component_Type => File_Name_Type,
240 Table_Index_Type => Integer,
241 Table_Low_Bound => 1,
242 Table_Initial => 10,
243 Table_Increment => 100,
244 Table_Name => "Make.Successful_Links");
246 package Library_Projs is new Table.Table (
247 Table_Component_Type => Project_Id,
248 Table_Index_Type => Integer,
249 Table_Low_Bound => 1,
250 Table_Initial => 10,
251 Table_Increment => 100,
252 Table_Name => "Make.Library_Projs");
254 -- Two variables to keep the last binder and linker switch index
255 -- in tables Binder_Switches and Linker_Switches, before adding
256 -- switches from the project file (if any) and switches from the
257 -- command line (if any).
259 Last_Binder_Switch : Integer := 0;
260 Last_Linker_Switch : Integer := 0;
262 Normalized_Switches : Argument_List_Access := new Argument_List (1 .. 10);
263 Last_Norm_Switch : Natural := 0;
265 Saved_Maximum_Processes : Natural := 0;
267 type Arg_List_Ref is access Argument_List;
268 The_Saved_Gcc_Switches : Arg_List_Ref;
270 Project_File_Name : String_Access := null;
271 -- The path name of the main project file, if any
273 Project_File_Name_Present : Boolean := False;
274 -- True when -P is used with a space between -P and the project file name
276 Current_Verbosity : Prj.Verbosity := Prj.Default;
277 -- Verbosity to parse the project files
279 Main_Project : Prj.Project_Id := No_Project;
280 -- The project id of the main project file, if any
282 Project_Object_Directory : Project_Id := No_Project;
283 -- The object directory of the project for the last compilation.
284 -- Avoid calling Change_Dir if the current working directory is already
285 -- this directory
287 -- Packages of project files where unknown attributes are errors.
289 Naming_String : aliased String := "naming";
290 Builder_String : aliased String := "builder";
291 Compiler_String : aliased String := "compiler";
292 Binder_String : aliased String := "binder";
293 Linker_String : aliased String := "linker";
295 Gnatmake_Packages : aliased String_List :=
296 (Naming_String 'Access,
297 Builder_String 'Access,
298 Compiler_String 'Access,
299 Binder_String 'Access,
300 Linker_String 'Access);
302 Packages_To_Check_By_Gnatmake : constant String_List_Access :=
303 Gnatmake_Packages'Access;
305 procedure Add_Source_Dir (N : String);
306 -- Call Add_Src_Search_Dir.
307 -- Output one line when in verbose mode.
309 procedure Add_Source_Directories is
310 new Prj.Env.For_All_Source_Dirs (Action => Add_Source_Dir);
312 procedure Add_Object_Dir (N : String);
313 -- Call Add_Lib_Search_Dir.
314 -- Output one line when in verbose mode.
316 procedure Add_Object_Directories is
317 new Prj.Env.For_All_Object_Dirs (Action => Add_Object_Dir);
319 procedure Change_To_Object_Directory (Project : Project_Id);
320 -- Change to the object directory of project Project, if this is not
321 -- already the current working directory.
323 type Bad_Compilation_Info is record
324 File : File_Name_Type;
325 Unit : Unit_Name_Type;
326 Found : Boolean;
327 end record;
328 -- File is the name of the file for which a compilation failed.
329 -- Unit is for gnatdist use in order to easily get the unit name
330 -- of a file when its name is krunched or declared in gnat.adc.
331 -- Found is False if the compilation failed because the file could
332 -- not be found.
334 package Bad_Compilation is new Table.Table (
335 Table_Component_Type => Bad_Compilation_Info,
336 Table_Index_Type => Natural,
337 Table_Low_Bound => 1,
338 Table_Initial => 20,
339 Table_Increment => 100,
340 Table_Name => "Make.Bad_Compilation");
341 -- Full name of all the source files for which compilation fails.
343 Do_Compile_Step : Boolean := True;
344 Do_Bind_Step : Boolean := True;
345 Do_Link_Step : Boolean := True;
346 -- Flags to indicate what step should be executed.
347 -- Can be set to False with the switches -c, -b and -l.
348 -- These flags are reset to True for each invokation of procedure Gnatmake.
350 Shared_String : aliased String := "-shared";
351 Force_Elab_Flags_String : aliased String := "-F";
353 No_Shared_Switch : aliased Argument_List := (1 .. 0 => null);
354 Shared_Switch : aliased Argument_List := (1 => Shared_String'Access);
355 Bind_Shared : Argument_List_Access := No_Shared_Switch'Access;
356 -- Switch to added in front of gnatbind switches. By default no switch is
357 -- added. Switch "-shared" is added if there is a non-static Library
358 -- Project File.
360 Bind_Shared_Known : Boolean := False;
361 -- Set to True after the first time Bind_Shared is computed
363 Shared_Libgcc : aliased String := "-shared-libgcc";
365 No_Shared_Libgcc_Switch : aliased Argument_List := (1 .. 0 => null);
366 Shared_Libgcc_Switch : aliased Argument_List :=
367 (1 => Shared_Libgcc'Access);
368 Link_With_Shared_Libgcc : Argument_List_Access :=
369 No_Shared_Libgcc_Switch'Access;
371 procedure Make_Failed (S1 : String; S2 : String := ""; S3 : String := "");
372 -- Delete all temp files created by Gnatmake and call Osint.Fail,
373 -- with the parameter S1, S2 and S3 (see osint.ads).
374 -- This is called from the Prj hierarchy and the MLib hierarchy.
376 --------------------------
377 -- Obsolete Executables --
378 --------------------------
380 Executable_Obsolete : Boolean := False;
381 -- Executable_Obsolete is initially set to False for each executable,
382 -- and is set to True whenever one of the source of the executable is
383 -- compiled, or has already been compiled for another executable.
385 Max_Header : constant := 200;
386 -- This needs a proper comment, it used to say "arbitrary"
387 -- that's not an adequate comment ???
389 type Header_Num is range 1 .. Max_Header;
390 -- Header_Num for the hash table Obsoleted below
392 function Hash (F : Name_Id) return Header_Num;
393 -- Hash function for the hash table Obsoleted below
395 package Obsoleted is new System.HTable.Simple_HTable
396 (Header_Num => Header_Num,
397 Element => Boolean,
398 No_Element => False,
399 Key => Name_Id,
400 Hash => Hash,
401 Equal => "=");
402 -- A hash table to keep all files that have been compiled, to detect
403 -- if an executable is up to date or not.
405 procedure Enter_Into_Obsoleted (F : Name_Id);
406 -- Enter a file name, without directory information, into the has table
407 -- Obsoleted.
409 function Is_In_Obsoleted (F : Name_Id) return Boolean;
410 -- Check if a file name, without directory information, has already been
411 -- entered into the hash table Obsoleted.
413 type Dependency is record
414 This : Name_Id;
415 Depends_On : Name_Id;
416 end record;
417 -- Components of table Dependencies below.
419 package Dependencies is new Table.Table (
420 Table_Component_Type => Dependency,
421 Table_Index_Type => Integer,
422 Table_Low_Bound => 1,
423 Table_Initial => 20,
424 Table_Increment => 100,
425 Table_Name => "Make.Dependencies");
426 -- A table to keep dependencies, to be able to decide if an executable
427 -- is obsolete.
429 procedure Add_Dependency (S : Name_Id; On : Name_Id);
430 -- Add one entry in table Dependencies
432 ----------------------------
433 -- Arguments and Switches --
434 ----------------------------
436 Arguments : Argument_List_Access;
437 -- Used to gather the arguments for invocation of the compiler
439 Last_Argument : Natural := 0;
440 -- Last index of arguments in Arguments above
442 Arguments_Collected : Boolean := False;
443 -- Set to True when the arguments for the next invocation of the compiler
444 -- have been collected.
446 Arguments_Project : Project_Id;
447 -- Project id, if any, of the source to be compiled
449 Arguments_Path_Name : File_Name_Type;
450 -- Full path of the source to be compiled, when Arguments_Project is not
451 -- No_Project.
453 Dummy_Switch : constant String_Access := new String'("- ");
454 -- Used to initialized Prev_Switch in procedure Check
456 procedure Add_Arguments (Args : Argument_List);
457 -- Add arguments to global variable Arguments, increasing its size
458 -- if necessary and adjusting Last_Argument.
460 function Configuration_Pragmas_Switch
461 (For_Project : Project_Id) return Argument_List;
462 -- Return an argument list of one element, if there is a configuration
463 -- pragmas file to be specified for For_Project,
464 -- otherwise return an empty argument list.
466 -------------------
467 -- Misc Routines --
468 -------------------
470 procedure List_Depend;
471 -- Prints to standard output the list of object dependencies. This list
472 -- can be used directly in a Makefile. A call to Compile_Sources must
473 -- precede the call to List_Depend. Also because this routine uses the
474 -- ALI files that were originally loaded and scanned by Compile_Sources,
475 -- no additional ALI files should be scanned between the two calls (i.e.
476 -- between the call to Compile_Sources and List_Depend.)
478 procedure Inform (N : Name_Id := No_Name; Msg : String);
479 -- Prints out the program name followed by a colon, N and S.
481 procedure List_Bad_Compilations;
482 -- Prints out the list of all files for which the compilation failed.
484 procedure Verbose_Msg
485 (N1 : Name_Id;
486 S1 : String;
487 N2 : Name_Id := No_Name;
488 S2 : String := "";
489 Prefix : String := " -> ");
490 -- If the verbose flag (Verbose_Mode) is set then print Prefix to standard
491 -- output followed by N1 and S1. If N2 /= No_Name then N2 is then printed
492 -- after S1. S2 is printed last. Both N1 and N2 are printed in quotation
493 -- marks.
495 Usage_Needed : Boolean := True;
496 -- Flag used to make sure Makeusg is call at most once
498 procedure Usage;
499 -- Call Makeusg, if Usage_Needed is True.
500 -- Set Usage_Needed to False.
502 procedure Debug_Msg (S : String; N : Name_Id);
503 -- If Debug.Debug_Flag_W is set outputs string S followed by name N.
505 type Project_Array is array (Positive range <>) of Project_Id;
506 No_Projects : constant Project_Array := (1 .. 0 => No_Project);
508 procedure Recursive_Compute_Depth
509 (Project : Project_Id;
510 Visited : Project_Array;
511 Depth : Natural);
512 -- Compute depth of Project and of the projects it depends on
514 -----------------------
515 -- Gnatmake Routines --
516 -----------------------
518 Gnatmake_Called : Boolean := False;
519 -- Set to True when procedure Gnatmake is called.
520 -- Attempt to delete temporary files is made only when Gnatmake_Called
521 -- is True.
523 subtype Lib_Mark_Type is Byte;
524 -- Used in Mark_Directory
526 Ada_Lib_Dir : constant Lib_Mark_Type := 1;
527 -- Used to mark a directory as a GNAT lib dir
529 -- Note that the notion of GNAT lib dir is no longer used. The code
530 -- related to it has not been removed to give an idea on how to use
531 -- the directory prefix marking mechanism.
533 -- An Ada library directory is a directory containing ali and object
534 -- files but no source files for the bodies (the specs can be in the
535 -- same or some other directory). These directories are specified
536 -- in the Gnatmake command line with the switch "-Adir" (to specify the
537 -- spec location -Idir cab be used). Gnatmake skips the missing sources
538 -- whose ali are in Ada library directories. For an explanation of why
539 -- Gnatmake behaves that way, see the spec of Make.Compile_Sources.
540 -- The directory lookup penalty is incurred every single time this
541 -- routine is called.
543 procedure Check_Steps;
544 -- Check what steps (Compile, Bind, Link) must be executed.
545 -- Set the step flags accordingly.
547 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean;
548 -- Get directory prefix of this file and get lib mark stored in name
549 -- table for this directory. Then check if an Ada lib mark has been set.
551 procedure Mark_Directory
552 (Dir : String;
553 Mark : Lib_Mark_Type);
554 -- Store Dir in name table and set lib mark as name info to identify
555 -- Ada libraries.
557 Output_Is_Object : Boolean := True;
558 -- Set to False when using a switch -S for the compiler
560 procedure Check_For_S_Switch;
561 -- Set Output_Is_Object to False when the -S switch is used for the
562 -- compiler.
564 function Switches_Of
565 (Source_File : Name_Id;
566 Source_File_Name : String;
567 Source_Index : Int;
568 Naming : Naming_Data;
569 In_Package : Package_Id;
570 Allow_ALI : Boolean) return Variable_Value;
571 -- Return the switches for the source file in the specified package
572 -- of a project file. If the Source_File ends with a standard GNAT
573 -- extension (".ads" or ".adb"), try first the full name, then the
574 -- name without the extension, then, if Allow_ALI is True, the name with
575 -- the extension ".ali". If there is no switches for either names, try the
576 -- default switches for Ada. If all failed, return No_Variable_Value.
578 function Is_In_Object_Directory
579 (Source_File : File_Name_Type;
580 Full_Lib_File : File_Name_Type) return Boolean;
581 -- Check if, when using a project file, the ALI file is in the project
582 -- directory of the ultimate extending project. If it is not, we ignore
583 -- the fact that this ALI file is read-only.
585 ----------------------------------------------------
586 -- Compiler, Binder & Linker Data and Subprograms --
587 ----------------------------------------------------
589 Gcc : String_Access := Program_Name ("gcc");
590 Gnatbind : String_Access := Program_Name ("gnatbind");
591 Gnatlink : String_Access := Program_Name ("gnatlink");
592 -- Default compiler, binder, linker programs
594 Saved_Gcc : String_Access := null;
595 Saved_Gnatbind : String_Access := null;
596 Saved_Gnatlink : String_Access := null;
597 -- Given by the command line. Will be used, if non null.
599 Gcc_Path : String_Access :=
600 GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
601 Gnatbind_Path : String_Access :=
602 GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
603 Gnatlink_Path : String_Access :=
604 GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
605 -- Path for compiler, binder, linker programs, defaulted now for gnatdist.
606 -- Changed later if overridden on command line.
608 Comp_Flag : constant String_Access := new String'("-c");
609 Output_Flag : constant String_Access := new String'("-o");
610 Ada_Flag_1 : constant String_Access := new String'("-x");
611 Ada_Flag_2 : constant String_Access := new String'("ada");
612 No_gnat_adc : constant String_Access := new String'("-gnatA");
613 GNAT_Flag : constant String_Access := new String'("-gnatpg");
614 Do_Not_Check_Flag : constant String_Access := new String'("-x");
616 Object_Suffix : constant String := Get_Object_Suffix.all;
617 Executable_Suffix : constant String := Get_Executable_Suffix.all;
619 Syntax_Only : Boolean := False;
620 -- Set to True when compiling with -gnats
622 Display_Executed_Programs : Boolean := True;
623 -- Set to True if name of commands should be output on stderr.
625 Output_File_Name_Seen : Boolean := False;
626 -- Set to True after having scanned the file_name for
627 -- switch "-o file_name"
629 Object_Directory_Seen : Boolean := False;
630 -- Set to True after having scanned the object directory for
631 -- switch "-D obj_dir".
633 Object_Directory_Path : String_Access := null;
634 -- The path name of the object directory, set with switch -D.
636 type Make_Program_Type is (None, Compiler, Binder, Linker);
638 Program_Args : Make_Program_Type := None;
639 -- Used to indicate if we are scanning gnatmake, gcc, gnatbind, or gnatbind
640 -- options within the gnatmake command line.
641 -- Used in Scan_Make_Arg only, but must be a global variable.
643 Temporary_Config_File : Boolean := False;
644 -- Set to True when there is a temporary config file used for a project
645 -- file, to avoid displaying the -gnatec switch for a temporary file.
647 procedure Add_Switches
648 (The_Package : Package_Id;
649 File_Name : String;
650 Index : Int;
651 Program : Make_Program_Type);
652 procedure Add_Switch
653 (S : String_Access;
654 Program : Make_Program_Type;
655 Append_Switch : Boolean := True;
656 And_Save : Boolean := True);
657 procedure Add_Switch
658 (S : String;
659 Program : Make_Program_Type;
660 Append_Switch : Boolean := True;
661 And_Save : Boolean := True);
662 -- Make invokes one of three programs (the compiler, the binder or the
663 -- linker). For the sake of convenience, some program specific switches
664 -- can be passed directly on the gnatmake commande line. This procedure
665 -- records these switches so that gnamake can pass them to the right
666 -- program. S is the switch to be added at the end of the command line
667 -- for Program if Append_Switch is True. If Append_Switch is False S is
668 -- added at the beginning of the command line.
670 procedure Check
671 (Source_File : File_Name_Type;
672 Source_Index : Int;
673 The_Args : Argument_List;
674 Lib_File : File_Name_Type;
675 Read_Only : Boolean;
676 ALI : out ALI_Id;
677 O_File : out File_Name_Type;
678 O_Stamp : out Time_Stamp_Type);
679 -- Determines whether the library file Lib_File is up-to-date or not. The
680 -- full name (with path information) of the object file corresponding to
681 -- Lib_File is returned in O_File. Its time stamp is saved in O_Stamp.
682 -- ALI is the ALI_Id corresponding to Lib_File. If Lib_File in not
683 -- up-to-date, then the corresponding source file needs to be recompiled.
684 -- In this case ALI = No_ALI_Id.
686 procedure Check_Linker_Options
687 (E_Stamp : Time_Stamp_Type;
688 O_File : out File_Name_Type;
689 O_Stamp : out Time_Stamp_Type);
690 -- Checks all linker options for linker files that are newer
691 -- than E_Stamp. If such objects are found, the youngest object
692 -- is returned in O_File and its stamp in O_Stamp.
694 -- If no obsolete linker files were found, the first missing
695 -- linker file is returned in O_File and O_Stamp is empty.
696 -- Otherwise O_File is No_File.
698 procedure Collect_Arguments
699 (Source_File : File_Name_Type;
700 Source_Index : Int;
701 Args : Argument_List);
702 -- Collect all arguments for a source to be compiled, including those
703 -- that come from a project file.
705 procedure Display (Program : String; Args : Argument_List);
706 -- Displays Program followed by the arguments in Args if variable
707 -- Display_Executed_Programs is set. The lower bound of Args must be 1.
709 -----------------
710 -- Mapping files
711 -----------------
713 type Temp_File_Names is
714 array (Project_Id range <>, Positive range <>) of Name_Id;
716 type Temp_Files_Ptr is access Temp_File_Names;
718 type Indices is array (Project_Id range <>) of Natural;
720 type Indices_Ptr is access Indices;
722 type Free_File_Indices is array
723 (Project_Id range <>, Positive range <>) of Positive;
725 type Free_Indices_Ptr is access Free_File_Indices;
727 The_Mapping_File_Names : Temp_Files_Ptr;
728 -- For each project, the name ids of the temporary mapping files used
730 Last_Mapping_File_Names : Indices_Ptr;
731 -- For each project, the index of the last mapping file created
733 The_Free_Mapping_File_Indices : Free_Indices_Ptr;
734 -- For each project, the indices in The_Mapping_File_Names of the mapping
735 -- file names that can be reused for subsequent compilations.
737 Last_Free_Indices : Indices_Ptr;
738 -- For each project, the number of mapping files that can be reused
740 Gnatmake_Mapping_File : String_Access := null;
741 -- The path name of a mapping file specified by switch -C=
743 procedure Delete_Mapping_Files;
744 -- Delete all temporary mapping files
746 procedure Init_Mapping_File
747 (Project : Project_Id;
748 File_Index : in out Natural);
749 -- Create a new temporary mapping file, and fill it with the project file
750 -- mappings, when using project file(s). The out parameter File_Index is
751 -- the index to the name of the file in the array The_Mapping_File_Names.
753 procedure Delete_Temp_Config_Files;
754 -- Delete all temporary config files
756 procedure Delete_All_Temp_Files;
757 -- Delete all temp files (config files, mapping files, path files)
759 -------------------
760 -- Add_Arguments --
761 -------------------
763 procedure Add_Arguments (Args : Argument_List) is
764 begin
765 if Arguments = null then
766 Arguments := new Argument_List (1 .. Args'Length + 10);
768 else
769 while Last_Argument + Args'Length > Arguments'Last loop
770 declare
771 New_Arguments : constant Argument_List_Access :=
772 new Argument_List (1 .. Arguments'Last * 2);
773 begin
774 New_Arguments (1 .. Last_Argument) :=
775 Arguments (1 .. Last_Argument);
776 Arguments := New_Arguments;
777 end;
778 end loop;
779 end if;
781 Arguments (Last_Argument + 1 .. Last_Argument + Args'Length) := Args;
782 Last_Argument := Last_Argument + Args'Length;
783 end Add_Arguments;
785 --------------------
786 -- Add_Dependency --
787 --------------------
789 procedure Add_Dependency (S : Name_Id; On : Name_Id) is
790 begin
791 Dependencies.Increment_Last;
792 Dependencies.Table (Dependencies.Last) := (S, On);
793 end Add_Dependency;
795 --------------------
796 -- Add_Object_Dir --
797 --------------------
799 procedure Add_Object_Dir (N : String) is
800 begin
801 Add_Lib_Search_Dir (N);
803 if Verbose_Mode then
804 Write_Str ("Adding object directory """);
805 Write_Str (N);
806 Write_Str (""".");
807 Write_Eol;
808 end if;
809 end Add_Object_Dir;
811 --------------------
812 -- Add_Source_Dir --
813 --------------------
815 procedure Add_Source_Dir (N : String) is
816 begin
817 Add_Src_Search_Dir (N);
819 if Verbose_Mode then
820 Write_Str ("Adding source directory """);
821 Write_Str (N);
822 Write_Str (""".");
823 Write_Eol;
824 end if;
825 end Add_Source_Dir;
827 ----------------
828 -- Add_Switch --
829 ----------------
831 procedure Add_Switch
832 (S : String_Access;
833 Program : Make_Program_Type;
834 Append_Switch : Boolean := True;
835 And_Save : Boolean := True)
837 generic
838 with package T is new Table.Table (<>);
839 procedure Generic_Position (New_Position : out Integer);
840 -- Generic procedure that chooses a position for S in T at the
841 -- beginning or the end, depending on the boolean Append_Switch.
842 -- Calling this procedure may expand the table.
844 ----------------------
845 -- Generic_Position --
846 ----------------------
848 procedure Generic_Position (New_Position : out Integer) is
849 begin
850 T.Increment_Last;
852 if Append_Switch then
853 New_Position := Integer (T.Last);
854 else
855 for J in reverse T.Table_Index_Type'Succ (T.First) .. T.Last loop
856 T.Table (J) := T.Table (T.Table_Index_Type'Pred (J));
857 end loop;
859 New_Position := Integer (T.First);
860 end if;
861 end Generic_Position;
863 procedure Gcc_Switches_Pos is new Generic_Position (Gcc_Switches);
864 procedure Binder_Switches_Pos is new Generic_Position (Binder_Switches);
865 procedure Linker_Switches_Pos is new Generic_Position (Linker_Switches);
867 procedure Saved_Gcc_Switches_Pos is new
868 Generic_Position (Saved_Gcc_Switches);
870 procedure Saved_Binder_Switches_Pos is new
871 Generic_Position (Saved_Binder_Switches);
873 procedure Saved_Linker_Switches_Pos is new
874 Generic_Position (Saved_Linker_Switches);
876 New_Position : Integer;
878 -- Start of processing for Add_Switch
880 begin
881 if And_Save then
882 case Program is
883 when Compiler =>
884 Saved_Gcc_Switches_Pos (New_Position);
885 Saved_Gcc_Switches.Table (New_Position) := S;
887 when Binder =>
888 Saved_Binder_Switches_Pos (New_Position);
889 Saved_Binder_Switches.Table (New_Position) := S;
891 when Linker =>
892 Saved_Linker_Switches_Pos (New_Position);
893 Saved_Linker_Switches.Table (New_Position) := S;
895 when None =>
896 raise Program_Error;
897 end case;
899 else
900 case Program is
901 when Compiler =>
902 Gcc_Switches_Pos (New_Position);
903 Gcc_Switches.Table (New_Position) := S;
905 when Binder =>
906 Binder_Switches_Pos (New_Position);
907 Binder_Switches.Table (New_Position) := S;
909 when Linker =>
910 Linker_Switches_Pos (New_Position);
911 Linker_Switches.Table (New_Position) := S;
913 when None =>
914 raise Program_Error;
915 end case;
916 end if;
917 end Add_Switch;
919 procedure Add_Switch
920 (S : String;
921 Program : Make_Program_Type;
922 Append_Switch : Boolean := True;
923 And_Save : Boolean := True)
925 begin
926 Add_Switch (S => new String'(S),
927 Program => Program,
928 Append_Switch => Append_Switch,
929 And_Save => And_Save);
930 end Add_Switch;
932 ------------------
933 -- Add_Switches --
934 ------------------
936 procedure Add_Switches
937 (The_Package : Package_Id;
938 File_Name : String;
939 Index : Int;
940 Program : Make_Program_Type)
942 Switches : Variable_Value;
943 Switch_List : String_List_Id;
944 Element : String_Element;
946 begin
947 if File_Name'Length > 0 then
948 Name_Len := File_Name'Length;
949 Name_Buffer (1 .. Name_Len) := File_Name;
950 Switches :=
951 Switches_Of
952 (Source_File => Name_Find,
953 Source_File_Name => File_Name,
954 Source_Index => Index,
955 Naming => Projects.Table (Main_Project).Naming,
956 In_Package => The_Package,
957 Allow_ALI =>
958 Program = Binder or else Program = Linker);
960 case Switches.Kind is
961 when Undefined =>
962 null;
964 when List =>
965 Program_Args := Program;
967 Switch_List := Switches.Values;
969 while Switch_List /= Nil_String loop
970 Element := String_Elements.Table (Switch_List);
971 Get_Name_String (Element.Value);
973 if Name_Len > 0 then
974 declare
975 Argv : constant String := Name_Buffer (1 .. Name_Len);
976 -- We need a copy, because Name_Buffer may be
977 -- modified.
979 begin
980 if Verbose_Mode then
981 Write_Str (" Adding ");
982 Write_Line (Argv);
983 end if;
985 Scan_Make_Arg (Argv, And_Save => False);
986 end;
987 end if;
989 Switch_List := Element.Next;
990 end loop;
992 when Single =>
993 Program_Args := Program;
994 Get_Name_String (Switches.Value);
996 if Name_Len > 0 then
997 declare
998 Argv : constant String := Name_Buffer (1 .. Name_Len);
999 -- We need a copy, because Name_Buffer may be modified
1001 begin
1002 if Verbose_Mode then
1003 Write_Str (" Adding ");
1004 Write_Line (Argv);
1005 end if;
1007 Scan_Make_Arg (Argv, And_Save => False);
1008 end;
1009 end if;
1010 end case;
1011 end if;
1012 end Add_Switches;
1014 ----------
1015 -- Bind --
1016 ----------
1018 procedure Bind (ALI_File : File_Name_Type; Args : Argument_List) is
1019 Bind_Args : Argument_List (1 .. Args'Last + 2);
1020 Bind_Last : Integer;
1021 Success : Boolean;
1023 begin
1024 pragma Assert (Args'First = 1);
1026 -- Optimize the simple case where the gnatbind command line looks like
1027 -- gnatbind -aO. -I- file.ali --into-> gnatbind file.adb
1029 if Args'Length = 2
1030 and then Args (Args'First).all = "-aO" & Normalized_CWD
1031 and then Args (Args'Last).all = "-I-"
1032 and then ALI_File = Strip_Directory (ALI_File)
1033 then
1034 Bind_Last := Args'First - 1;
1036 else
1037 Bind_Last := Args'Last;
1038 Bind_Args (Args'Range) := Args;
1039 end if;
1041 -- It is completely pointless to re-check source file time stamps.
1042 -- This has been done already by gnatmake
1044 Bind_Last := Bind_Last + 1;
1045 Bind_Args (Bind_Last) := Do_Not_Check_Flag;
1047 Get_Name_String (ALI_File);
1049 Bind_Last := Bind_Last + 1;
1050 Bind_Args (Bind_Last) := new String'(Name_Buffer (1 .. Name_Len));
1052 GNAT.OS_Lib.Normalize_Arguments (Bind_Args (Args'First .. Bind_Last));
1054 Display (Gnatbind.all, Bind_Args (Args'First .. Bind_Last));
1056 if Gnatbind_Path = null then
1057 Make_Failed ("error, unable to locate ", Gnatbind.all);
1058 end if;
1060 GNAT.OS_Lib.Spawn
1061 (Gnatbind_Path.all, Bind_Args (Args'First .. Bind_Last), Success);
1063 if not Success then
1064 raise Bind_Failed;
1065 end if;
1066 end Bind;
1068 --------------------------------
1069 -- Change_To_Object_Directory --
1070 --------------------------------
1072 procedure Change_To_Object_Directory (Project : Project_Id) is
1073 begin
1074 -- Nothing to do if the current working directory is alresdy the one
1075 -- we want.
1077 if Project_Object_Directory /= Project then
1078 Project_Object_Directory := Project;
1080 -- If in a real project, set the working directory to the object
1081 -- directory of the project.
1083 if Project /= No_Project then
1084 Change_Dir
1085 (Get_Name_String (Projects.Table (Project).Object_Directory));
1087 -- Otherwise, for sources outside of any project, set the working
1088 -- directory to the object directory of the main project.
1090 elsif Main_Project /= No_Project then
1091 Change_Dir
1092 (Get_Name_String
1093 (Projects.Table (Main_Project).Object_Directory));
1094 end if;
1095 end if;
1096 end Change_To_Object_Directory;
1098 -----------
1099 -- Check --
1100 -----------
1102 procedure Check
1103 (Source_File : File_Name_Type;
1104 Source_Index : Int;
1105 The_Args : Argument_List;
1106 Lib_File : File_Name_Type;
1107 Read_Only : Boolean;
1108 ALI : out ALI_Id;
1109 O_File : out File_Name_Type;
1110 O_Stamp : out Time_Stamp_Type)
1112 function First_New_Spec (A : ALI_Id) return File_Name_Type;
1113 -- Looks in the with table entries of A and returns the spec file name
1114 -- of the first withed unit (subprogram) for which no spec existed when
1115 -- A was generated but for which there exists one now, implying that A
1116 -- is now obsolete. If no such unit is found No_File is returned.
1117 -- Otherwise the spec file name of the unit is returned.
1119 -- **WARNING** in the event of Uname format modifications, one *MUST*
1120 -- make sure this function is also updated.
1122 -- Note: This function should really be in ali.adb and use Uname
1123 -- services, but this causes the whole compiler to be dragged along
1124 -- for gnatbind and gnatmake.
1126 --------------------
1127 -- First_New_Spec --
1128 --------------------
1130 function First_New_Spec (A : ALI_Id) return File_Name_Type is
1131 Spec_File_Name : File_Name_Type := No_File;
1133 function New_Spec (Uname : Unit_Name_Type) return Boolean;
1134 -- Uname is the name of the spec or body of some ada unit.
1135 -- This function returns True if the Uname is the name of a body
1136 -- which has a spec not mentioned inali file A. If True is returned
1137 -- Spec_File_Name above is set to the name of this spec file.
1139 --------------
1140 -- New_Spec --
1141 --------------
1143 function New_Spec (Uname : Unit_Name_Type) return Boolean is
1144 Spec_Name : Unit_Name_Type;
1145 File_Name : File_Name_Type;
1147 begin
1148 -- Test whether Uname is the name of a body unit (ie ends with %b)
1150 Get_Name_String (Uname);
1151 pragma
1152 Assert (Name_Len > 2 and then Name_Buffer (Name_Len - 1) = '%');
1154 if Name_Buffer (Name_Len) /= 'b' then
1155 return False;
1156 end if;
1158 -- Convert unit name into spec name
1160 -- ??? this code seems dubious in presence of pragma
1161 -- Source_File_Name since there is no more direct relationship
1162 -- between unit name and file name.
1164 -- ??? Further, what about alternative subunit naming
1166 Name_Buffer (Name_Len) := 's';
1167 Spec_Name := Name_Find;
1168 File_Name := Get_File_Name (Spec_Name, Subunit => False);
1170 -- Look if File_Name is mentioned in A's sdep list.
1171 -- If not look if the file exists. If it does return True.
1173 for D in
1174 ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep
1175 loop
1176 if Sdep.Table (D).Sfile = File_Name then
1177 return False;
1178 end if;
1179 end loop;
1181 if Full_Source_Name (File_Name) /= No_File then
1182 Spec_File_Name := File_Name;
1183 return True;
1184 end if;
1186 return False;
1187 end New_Spec;
1189 -- Start of processing for First_New_Spec
1191 begin
1192 U_Chk : for U in
1193 ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit
1194 loop
1195 exit U_Chk when Units.Table (U).Utype = Is_Body_Only
1196 and then New_Spec (Units.Table (U).Uname);
1198 for W in Units.Table (U).First_With
1200 Units.Table (U).Last_With
1201 loop
1202 exit U_Chk when
1203 Withs.Table (W).Afile /= No_File
1204 and then New_Spec (Withs.Table (W).Uname);
1205 end loop;
1206 end loop U_Chk;
1208 return Spec_File_Name;
1209 end First_New_Spec;
1211 ---------------------------------
1212 -- Data declarations for Check --
1213 ---------------------------------
1215 Full_Lib_File : File_Name_Type;
1216 -- Full name of current library file
1218 Full_Obj_File : File_Name_Type;
1219 -- Full name of the object file corresponding to Lib_File.
1221 Lib_Stamp : Time_Stamp_Type;
1222 -- Time stamp of the current ada library file.
1224 Obj_Stamp : Time_Stamp_Type;
1225 -- Time stamp of the current object file.
1227 Modified_Source : File_Name_Type;
1228 -- The first source in Lib_File whose current time stamp differs
1229 -- from that stored in Lib_File.
1231 New_Spec : File_Name_Type;
1232 -- If Lib_File contains in its W (with) section a body (for a
1233 -- subprogram) for which there exists a spec and the spec did not
1234 -- appear in the Sdep section of Lib_File, New_Spec contains the file
1235 -- name of this new spec.
1237 Source_Name : Name_Id;
1238 Text : Text_Buffer_Ptr;
1240 Prev_Switch : String_Access;
1241 -- Previous switch processed
1243 Arg : Arg_Id := Arg_Id'First;
1244 -- Current index in Args.Table for a given unit (init to stop warning)
1246 Switch_Found : Boolean;
1247 -- True if a given switch has been found
1249 -- Start of processing for Check
1251 begin
1252 pragma Assert (Lib_File /= No_File);
1254 -- If the ALI file is read-only, set temporarily
1255 -- Check_Object_Consistency to False: we don't care if the object file
1256 -- is not there; presumably, a library will be used for linking.
1258 if Read_Only then
1259 declare
1260 Saved_Check_Object_Consistency : constant Boolean :=
1261 Check_Object_Consistency;
1262 begin
1263 Check_Object_Consistency := False;
1264 Text := Read_Library_Info (Lib_File);
1265 Check_Object_Consistency := Saved_Check_Object_Consistency;
1266 end;
1268 else
1269 Text := Read_Library_Info (Lib_File);
1270 end if;
1272 Full_Lib_File := Full_Library_Info_Name;
1273 Full_Obj_File := Full_Object_File_Name;
1274 Lib_Stamp := Current_Library_File_Stamp;
1275 Obj_Stamp := Current_Object_File_Stamp;
1277 if Full_Lib_File = No_File then
1278 Verbose_Msg (Lib_File, "being checked ...", Prefix => " ");
1279 else
1280 Verbose_Msg (Full_Lib_File, "being checked ...", Prefix => " ");
1281 end if;
1283 ALI := No_ALI_Id;
1284 O_File := Full_Obj_File;
1285 O_Stamp := Obj_Stamp;
1287 if Text = null then
1288 if Full_Lib_File = No_File then
1289 Verbose_Msg (Lib_File, "missing.");
1291 elsif Obj_Stamp (Obj_Stamp'First) = ' ' then
1292 Verbose_Msg (Full_Obj_File, "missing.");
1294 else
1295 Verbose_Msg
1296 (Full_Lib_File, "(" & String (Lib_Stamp) & ") newer than",
1297 Full_Obj_File, "(" & String (Obj_Stamp) & ")");
1298 end if;
1300 else
1301 ALI := Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
1302 Free (Text);
1304 if ALI = No_ALI_Id then
1305 Verbose_Msg (Full_Lib_File, "incorrectly formatted ALI file");
1306 return;
1308 elsif ALIs.Table (ALI).Ver (1 .. ALIs.Table (ALI).Ver_Len) /=
1309 Verbose_Library_Version
1310 then
1311 Verbose_Msg (Full_Lib_File, "compiled with old GNAT version");
1312 ALI := No_ALI_Id;
1313 return;
1314 end if;
1316 -- Don't take Ali file into account if it was generated with
1317 -- errors.
1319 if ALIs.Table (ALI).Compile_Errors then
1320 Verbose_Msg (Full_Lib_File, "had errors, must be recompiled");
1321 ALI := No_ALI_Id;
1322 return;
1323 end if;
1325 -- Don't take Ali file into account if it was generated without
1326 -- object.
1328 if Operating_Mode /= Check_Semantics
1329 and then ALIs.Table (ALI).No_Object
1330 then
1331 Verbose_Msg (Full_Lib_File, "has no corresponding object");
1332 ALI := No_ALI_Id;
1333 return;
1334 end if;
1336 -- Check for matching compiler switches if needed
1338 if Check_Switches then
1340 -- First, collect all the switches
1342 Collect_Arguments (Source_File, Source_Index, The_Args);
1344 Prev_Switch := Dummy_Switch;
1346 Get_Name_String (ALIs.Table (ALI).Sfile);
1348 Switches_To_Check.Set_Last (0);
1350 for J in 1 .. Last_Argument loop
1352 -- Skip non switches -c, -I and -o switches
1354 if Arguments (J) (1) = '-'
1355 and then Arguments (J) (2) /= 'c'
1356 and then Arguments (J) (2) /= 'o'
1357 and then Arguments (J) (2) /= 'I'
1358 then
1359 Normalize_Compiler_Switches
1360 (Arguments (J).all,
1361 Normalized_Switches,
1362 Last_Norm_Switch);
1364 for K in 1 .. Last_Norm_Switch loop
1365 Switches_To_Check.Increment_Last;
1366 Switches_To_Check.Table (Switches_To_Check.Last) :=
1367 Normalized_Switches (K);
1368 end loop;
1369 end if;
1370 end loop;
1372 for J in 1 .. Switches_To_Check.Last loop
1374 -- Comparing switches is delicate because gcc reorders
1375 -- a number of switches, according to lang-specs.h, but
1376 -- gnatmake doesn't have the sufficient knowledge to
1377 -- perform the same reordering. Instead, we ignore orders
1378 -- between different "first letter" switches, but keep
1379 -- orders between same switches, e.g -O -O2 is different
1380 -- than -O2 -O, but -g -O is equivalent to -O -g.
1382 if Switches_To_Check.Table (J) (2) /= Prev_Switch (2) or else
1383 (Prev_Switch'Length >= 6 and then
1384 Prev_Switch (2 .. 5) = "gnat" and then
1385 Switches_To_Check.Table (J)'Length >= 6 and then
1386 Switches_To_Check.Table (J) (2 .. 5) = "gnat" and then
1387 Prev_Switch (6) /= Switches_To_Check.Table (J) (6))
1388 then
1389 Prev_Switch := Switches_To_Check.Table (J);
1390 Arg :=
1391 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg;
1392 end if;
1394 Switch_Found := False;
1396 for K in Arg ..
1397 Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1398 loop
1400 Switches_To_Check.Table (J).all = Args.Table (K).all
1401 then
1402 Arg := K + 1;
1403 Switch_Found := True;
1404 exit;
1405 end if;
1406 end loop;
1408 if not Switch_Found then
1409 if Verbose_Mode then
1410 Verbose_Msg (ALIs.Table (ALI).Sfile,
1411 "switch mismatch """ &
1412 Switches_To_Check.Table (J).all & '"');
1413 end if;
1415 ALI := No_ALI_Id;
1416 return;
1417 end if;
1418 end loop;
1420 if Switches_To_Check.Last /=
1421 Integer (Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg -
1422 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg + 1)
1423 then
1424 if Verbose_Mode then
1425 Verbose_Msg (ALIs.Table (ALI).Sfile,
1426 "different number of switches");
1428 for K in Units.Table (ALIs.Table (ALI).First_Unit).First_Arg
1429 .. Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1430 loop
1431 Write_Str (Args.Table (K).all);
1432 Write_Char (' ');
1433 end loop;
1435 Write_Eol;
1437 for J in 1 .. Switches_To_Check.Last loop
1438 Write_Str (Switches_To_Check.Table (J).all);
1439 Write_Char (' ');
1440 end loop;
1442 Write_Eol;
1443 end if;
1445 ALI := No_ALI_Id;
1446 return;
1447 end if;
1448 end if;
1450 -- Get the source files and their message digests. Note that some
1451 -- sources may be missing if ALI is out-of-date.
1453 Set_Source_Table (ALI);
1455 Modified_Source := Time_Stamp_Mismatch (ALI, Read_Only);
1457 if Modified_Source /= No_File then
1458 ALI := No_ALI_Id;
1460 if Verbose_Mode then
1461 Source_Name := Full_Source_Name (Modified_Source);
1463 if Source_Name /= No_File then
1464 Verbose_Msg (Source_Name, "time stamp mismatch");
1465 else
1466 Verbose_Msg (Modified_Source, "missing");
1467 end if;
1468 end if;
1470 else
1471 New_Spec := First_New_Spec (ALI);
1473 if New_Spec /= No_File then
1474 ALI := No_ALI_Id;
1476 if Verbose_Mode then
1477 Source_Name := Full_Source_Name (New_Spec);
1479 if Source_Name /= No_File then
1480 Verbose_Msg (Source_Name, "new spec");
1481 else
1482 Verbose_Msg (New_Spec, "old spec missing");
1483 end if;
1484 end if;
1485 end if;
1486 end if;
1487 end if;
1488 end Check;
1490 ------------------------
1491 -- Check_For_S_Switch --
1492 ------------------------
1494 procedure Check_For_S_Switch is
1495 begin
1496 -- By default, we generate an object file
1498 Output_Is_Object := True;
1500 for Arg in 1 .. Last_Argument loop
1501 if Arguments (Arg).all = "-S" then
1502 Output_Is_Object := False;
1504 elsif Arguments (Arg).all = "-c" then
1505 Output_Is_Object := True;
1506 end if;
1507 end loop;
1508 end Check_For_S_Switch;
1510 --------------------------
1511 -- Check_Linker_Options --
1512 --------------------------
1514 procedure Check_Linker_Options
1515 (E_Stamp : Time_Stamp_Type;
1516 O_File : out File_Name_Type;
1517 O_Stamp : out Time_Stamp_Type)
1519 procedure Check_File (File : File_Name_Type);
1520 -- Update O_File and O_Stamp if the given file is younger than E_Stamp
1521 -- and O_Stamp, or if O_File is No_File and File does not exist.
1523 function Get_Library_File (Name : String) return File_Name_Type;
1524 -- Return the full file name including path of a library based
1525 -- on the name specified with the -l linker option, using the
1526 -- Ada object path. Return No_File if no such file can be found.
1528 type Char_Array is array (Natural) of Character;
1529 type Char_Array_Access is access constant Char_Array;
1531 Template : Char_Array_Access;
1532 pragma Import (C, Template, "__gnat_library_template");
1534 ----------------
1535 -- Check_File --
1536 ----------------
1538 procedure Check_File (File : File_Name_Type) is
1539 Stamp : Time_Stamp_Type;
1540 Name : File_Name_Type := File;
1542 begin
1543 Get_Name_String (Name);
1545 -- Remove any trailing NUL characters
1547 while Name_Len >= Name_Buffer'First
1548 and then Name_Buffer (Name_Len) = NUL
1549 loop
1550 Name_Len := Name_Len - 1;
1551 end loop;
1553 if Name_Len <= 0 then
1554 return;
1556 elsif Name_Buffer (1) = '-' then
1558 -- Do not check if File is a switch other than "-l"
1560 if Name_Buffer (2) /= 'l' then
1561 return;
1562 end if;
1564 -- The argument is a library switch, get actual name. It
1565 -- is necessary to make a copy of the relevant part of
1566 -- Name_Buffer as Get_Library_Name uses Name_Buffer as well.
1568 declare
1569 Base_Name : constant String := Name_Buffer (3 .. Name_Len);
1571 begin
1572 Name := Get_Library_File (Base_Name);
1573 end;
1575 if Name = No_File then
1576 return;
1577 end if;
1578 end if;
1580 Stamp := File_Stamp (Name);
1582 -- Find the youngest object file that is younger than the
1583 -- executable. If no such file exist, record the first object
1584 -- file that is not found.
1586 if (O_Stamp < Stamp and then E_Stamp < Stamp)
1587 or else (O_File = No_File and then Stamp (Stamp'First) = ' ')
1588 then
1589 O_Stamp := Stamp;
1590 O_File := Name;
1592 -- Strip the trailing NUL if present
1594 Get_Name_String (O_File);
1596 if Name_Buffer (Name_Len) = NUL then
1597 Name_Len := Name_Len - 1;
1598 O_File := Name_Find;
1599 end if;
1600 end if;
1601 end Check_File;
1603 ----------------------
1604 -- Get_Library_Name --
1605 ----------------------
1607 -- See comments in a-adaint.c about template syntax
1609 function Get_Library_File (Name : String) return File_Name_Type is
1610 File : File_Name_Type := No_File;
1612 begin
1613 Name_Len := 0;
1615 for Ptr in Template'Range loop
1616 case Template (Ptr) is
1617 when '*' =>
1618 Add_Str_To_Name_Buffer (Name);
1620 when ';' =>
1621 File := Full_Lib_File_Name (Name_Find);
1622 exit when File /= No_File;
1623 Name_Len := 0;
1625 when NUL =>
1626 exit;
1628 when others =>
1629 Add_Char_To_Name_Buffer (Template (Ptr));
1630 end case;
1631 end loop;
1633 -- The for loop exited because the end of the template
1634 -- was reached. File contains the last possible file name
1635 -- for the library.
1637 if File = No_File and then Name_Len > 0 then
1638 File := Full_Lib_File_Name (Name_Find);
1639 end if;
1641 return File;
1642 end Get_Library_File;
1644 -- Start of processing for Check_Linker_Options
1646 begin
1647 O_File := No_File;
1648 O_Stamp := (others => ' ');
1650 -- Process linker options from the ALI files.
1652 for Opt in 1 .. Linker_Options.Last loop
1653 Check_File (Linker_Options.Table (Opt).Name);
1654 end loop;
1656 -- Process options given on the command line.
1658 for Opt in Linker_Switches.First .. Linker_Switches.Last loop
1660 -- Check if the previous Opt has one of the two switches
1661 -- that take an extra parameter. (See GCC manual.)
1663 if Opt = Linker_Switches.First
1664 or else (Linker_Switches.Table (Opt - 1).all /= "-u"
1665 and then
1666 Linker_Switches.Table (Opt - 1).all /= "-Xlinker"
1667 and then
1668 Linker_Switches.Table (Opt - 1).all /= "-L")
1669 then
1670 Name_Len := 0;
1671 Add_Str_To_Name_Buffer (Linker_Switches.Table (Opt).all);
1672 Check_File (Name_Find);
1673 end if;
1674 end loop;
1676 end Check_Linker_Options;
1678 -----------------
1679 -- Check_Steps --
1680 -----------------
1682 procedure Check_Steps is
1683 begin
1684 -- If either -c, -b or -l has been specified, we will not necessarily
1685 -- execute all steps.
1687 if Make_Steps then
1688 Do_Compile_Step := Do_Compile_Step and Compile_Only;
1689 Do_Bind_Step := Do_Bind_Step and Bind_Only;
1690 Do_Link_Step := Do_Link_Step and Link_Only;
1692 -- If -c has been specified, but not -b, ignore any potential -l
1694 if Do_Compile_Step and then not Do_Bind_Step then
1695 Do_Link_Step := False;
1696 end if;
1697 end if;
1698 end Check_Steps;
1700 -----------------------
1701 -- Collect_Arguments --
1702 -----------------------
1704 procedure Collect_Arguments
1705 (Source_File : File_Name_Type;
1706 Source_Index : Int;
1707 Args : Argument_List)
1709 begin
1710 Arguments_Collected := True;
1711 Arguments_Project := No_Project;
1712 Last_Argument := 0;
1713 Add_Arguments (Args);
1715 if Main_Project /= No_Project then
1716 declare
1717 Source_File_Name : constant String :=
1718 Get_Name_String (Source_File);
1719 Compiler_Package : Prj.Package_Id;
1720 Switches : Prj.Variable_Value;
1721 Data : Project_Data;
1723 begin
1724 Prj.Env.
1725 Get_Reference
1726 (Source_File_Name => Source_File_Name,
1727 Project => Arguments_Project,
1728 Path => Arguments_Path_Name);
1730 -- If the source is not a source of a project file, check if
1731 -- this is allowed.
1733 if Arguments_Project = No_Project then
1734 if not External_Unit_Compilation_Allowed then
1735 Make_Failed ("external source, not part of any projects, " &
1736 "cannot be compiled (", Source_File_Name, ")");
1737 end if;
1739 -- If it is allowed, simply add the saved gcc switches
1741 Add_Arguments (The_Saved_Gcc_Switches.all);
1743 else
1744 -- We get the project directory for the relative path
1745 -- switches and arguments.
1747 Data := Projects.Table (Arguments_Project);
1749 -- If the source is in an extended project, we go to
1750 -- the ultimate extending project.
1752 while Data.Extended_By /= No_Project loop
1753 Arguments_Project := Data.Extended_By;
1754 Data := Projects.Table (Arguments_Project);
1755 end loop;
1757 -- If building a dynamic or relocatable library, compile with
1758 -- PIC option, if it exists.
1760 if Data.Library and then Data.Library_Kind /= Static then
1761 declare
1762 PIC : constant String := MLib.Tgt.PIC_Option;
1764 begin
1765 if PIC /= "" then
1766 Add_Arguments ((1 => new String'(PIC)));
1767 end if;
1768 end;
1769 end if;
1771 if Data.Dir_Path = null then
1772 Data.Dir_Path :=
1773 new String'(Get_Name_String (Data.Display_Directory));
1774 Projects.Table (Arguments_Project) := Data;
1775 end if;
1777 -- We now look for package Compiler
1778 -- and get the switches from this package.
1780 Compiler_Package :=
1781 Prj.Util.Value_Of
1782 (Name => Name_Compiler,
1783 In_Packages => Data.Decl.Packages);
1785 if Compiler_Package /= No_Package then
1787 -- If package Gnatmake.Compiler exists, we get
1788 -- the specific switches for the current source,
1789 -- or the global switches, if any.
1791 Switches := Switches_Of
1792 (Source_File => Source_File,
1793 Source_File_Name => Source_File_Name,
1794 Source_Index => Source_Index,
1795 Naming => Data.Naming,
1796 In_Package => Compiler_Package,
1797 Allow_ALI => False);
1799 end if;
1801 case Switches.Kind is
1803 -- We have a list of switches. We add these switches,
1804 -- plus the saved gcc switches.
1806 when List =>
1808 declare
1809 Current : String_List_Id := Switches.Values;
1810 Element : String_Element;
1811 Number : Natural := 0;
1813 begin
1814 while Current /= Nil_String loop
1815 Element := String_Elements.Table (Current);
1816 Number := Number + 1;
1817 Current := Element.Next;
1818 end loop;
1820 declare
1821 New_Args : Argument_List (1 .. Number);
1823 begin
1824 Current := Switches.Values;
1826 for Index in New_Args'Range loop
1827 Element := String_Elements.Table (Current);
1828 Get_Name_String (Element.Value);
1829 New_Args (Index) :=
1830 new String'(Name_Buffer (1 .. Name_Len));
1831 Test_If_Relative_Path
1832 (New_Args (Index), Parent => Data.Dir_Path);
1833 Current := Element.Next;
1834 end loop;
1836 Add_Arguments
1837 (Configuration_Pragmas_Switch
1838 (Arguments_Project) &
1839 New_Args & The_Saved_Gcc_Switches.all);
1840 end;
1841 end;
1843 -- We have a single switch. We add this switch,
1844 -- plus the saved gcc switches.
1846 when Single =>
1847 Get_Name_String (Switches.Value);
1849 declare
1850 New_Args : Argument_List :=
1851 (1 => new String'
1852 (Name_Buffer (1 .. Name_Len)));
1854 begin
1855 Test_If_Relative_Path
1856 (New_Args (1), Parent => Data.Dir_Path);
1857 Add_Arguments
1858 (Configuration_Pragmas_Switch (Arguments_Project) &
1859 New_Args & The_Saved_Gcc_Switches.all);
1860 end;
1862 -- We have no switches from Gnatmake.Compiler.
1863 -- We add the saved gcc switches.
1865 when Undefined =>
1866 Add_Arguments
1867 (Configuration_Pragmas_Switch (Arguments_Project) &
1868 The_Saved_Gcc_Switches.all);
1869 end case;
1870 end if;
1871 end;
1872 end if;
1874 -- Set Output_Is_Object, depending if there is a -S switch.
1875 -- If the bind step is not performed, and there is a -S switch,
1876 -- then we will not check for a valid object file.
1878 Check_For_S_Switch;
1879 end Collect_Arguments;
1881 ---------------------
1882 -- Compile_Sources --
1883 ---------------------
1885 procedure Compile_Sources
1886 (Main_Source : File_Name_Type;
1887 Args : Argument_List;
1888 First_Compiled_File : out Name_Id;
1889 Most_Recent_Obj_File : out Name_Id;
1890 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
1891 Main_Unit : out Boolean;
1892 Compilation_Failures : out Natural;
1893 Main_Index : Int := 0;
1894 Check_Readonly_Files : Boolean := False;
1895 Do_Not_Execute : Boolean := False;
1896 Force_Compilations : Boolean := False;
1897 Keep_Going : Boolean := False;
1898 In_Place_Mode : Boolean := False;
1899 Initialize_ALI_Data : Boolean := True;
1900 Max_Process : Positive := 1)
1902 No_Mapping_File : constant Natural := 0;
1904 type Compilation_Data is record
1905 Pid : Process_Id;
1906 Full_Source_File : File_Name_Type;
1907 Lib_File : File_Name_Type;
1908 Source_Unit : Unit_Name_Type;
1909 Mapping_File : Natural := No_Mapping_File;
1910 Project : Project_Id := No_Project;
1911 Syntax_Only : Boolean := False;
1912 Output_Is_Object : Boolean := True;
1913 end record;
1915 Running_Compile : array (1 .. Max_Process) of Compilation_Data;
1916 -- Used to save information about outstanding compilations.
1918 Outstanding_Compiles : Natural := 0;
1919 -- Current number of outstanding compiles
1921 Source_Unit : Unit_Name_Type;
1922 -- Current source unit
1924 Source_File : File_Name_Type;
1925 -- Current source file
1927 Full_Source_File : File_Name_Type;
1928 -- Full name of the current source file
1930 Lib_File : File_Name_Type;
1931 -- Current library file
1933 Full_Lib_File : File_Name_Type;
1934 -- Full name of the current library file
1936 Obj_File : File_Name_Type;
1937 -- Full name of the object file corresponding to Lib_File.
1939 Obj_Stamp : Time_Stamp_Type;
1940 -- Time stamp of the current object file.
1942 Sfile : File_Name_Type;
1943 -- Contains the source file of the units withed by Source_File
1945 ALI : ALI_Id;
1946 -- ALI Id of the current ALI file
1948 Read_Only : Boolean := False;
1950 Compilation_OK : Boolean;
1951 Need_To_Compile : Boolean;
1953 Pid : Process_Id;
1954 Text : Text_Buffer_Ptr;
1956 Mfile : Natural := No_Mapping_File;
1958 Need_To_Check_Standard_Library : Boolean :=
1959 Check_Readonly_Files and not Unique_Compile;
1961 Mapping_File_Arg : String_Access;
1963 procedure Add_Process
1964 (Pid : Process_Id;
1965 Sfile : File_Name_Type;
1966 Afile : File_Name_Type;
1967 Uname : Unit_Name_Type;
1968 Mfile : Natural := No_Mapping_File);
1969 -- Adds process Pid to the current list of outstanding compilation
1970 -- processes and record the full name of the source file Sfile that
1971 -- we are compiling, the name of its library file Afile and the
1972 -- name of its unit Uname. If Mfile is not equal to No_Mapping_File,
1973 -- it is the index of the mapping file used during compilation in the
1974 -- array The_Mapping_File_Names.
1976 procedure Await_Compile
1977 (Sfile : out File_Name_Type;
1978 Afile : out File_Name_Type;
1979 Uname : out Unit_Name_Type;
1980 OK : out Boolean);
1981 -- Awaits that an outstanding compilation process terminates. When
1982 -- it does set Sfile to the name of the source file that was compiled
1983 -- Afile to the name of its library file and Uname to the name of its
1984 -- unit. Note that this time stamp can be used to check whether the
1985 -- compilation did generate an object file. OK is set to True if the
1986 -- compilation succeeded. Note that Sfile, Afile and Uname could be
1987 -- resp. No_File, No_File and No_Name if there were no compilations
1988 -- to wait for.
1990 function Bad_Compilation_Count return Natural;
1991 -- Returns the number of compilation failures.
1993 procedure Collect_Arguments_And_Compile
1994 (Source_File : File_Name_Type; Source_Index : Int);
1995 -- Collect arguments from project file (if any) and compile
1997 function Compile
1998 (S : Name_Id;
1999 L : Name_Id;
2000 Source_Index : Int;
2001 Args : Argument_List) return Process_Id;
2002 -- Compiles S using Args. If S is a GNAT predefined source
2003 -- "-gnatpg" is added to Args. Non blocking call. L corresponds to the
2004 -- expected library file name. Process_Id of the process spawned to
2005 -- execute the compile.
2007 package Good_ALI is new Table.Table (
2008 Table_Component_Type => ALI_Id,
2009 Table_Index_Type => Natural,
2010 Table_Low_Bound => 1,
2011 Table_Initial => 50,
2012 Table_Increment => 100,
2013 Table_Name => "Make.Good_ALI");
2014 -- Contains the set of valid ALI files that have not yet been scanned.
2016 function Good_ALI_Present return Boolean;
2017 -- Returns True if any ALI file was recorded in the previous set.
2019 procedure Get_Mapping_File (Project : Project_Id);
2020 -- Get a mapping file name. If there is one to be reused, reuse it.
2021 -- Otherwise, create a new mapping file.
2023 function Get_Next_Good_ALI return ALI_Id;
2024 -- Returns the next good ALI_Id record;
2026 procedure Record_Failure
2027 (File : File_Name_Type;
2028 Unit : Unit_Name_Type;
2029 Found : Boolean := True);
2030 -- Records in the previous table that the compilation for File failed.
2031 -- If Found is False then the compilation of File failed because we
2032 -- could not find it. Records also Unit when possible.
2034 procedure Record_Good_ALI (A : ALI_Id);
2035 -- Records in the previous set the Id of an ALI file.
2037 -----------------
2038 -- Add_Process --
2039 -----------------
2041 procedure Add_Process
2042 (Pid : Process_Id;
2043 Sfile : File_Name_Type;
2044 Afile : File_Name_Type;
2045 Uname : Unit_Name_Type;
2046 Mfile : Natural := No_Mapping_File)
2048 OC1 : constant Positive := Outstanding_Compiles + 1;
2050 begin
2051 pragma Assert (OC1 <= Max_Process);
2052 pragma Assert (Pid /= Invalid_Pid);
2054 Running_Compile (OC1).Pid := Pid;
2055 Running_Compile (OC1).Full_Source_File := Sfile;
2056 Running_Compile (OC1).Lib_File := Afile;
2057 Running_Compile (OC1).Source_Unit := Uname;
2058 Running_Compile (OC1).Mapping_File := Mfile;
2059 Running_Compile (OC1).Project := Arguments_Project;
2060 Running_Compile (OC1).Syntax_Only := Syntax_Only;
2061 Running_Compile (OC1).Output_Is_Object := Output_Is_Object;
2063 Outstanding_Compiles := OC1;
2064 end Add_Process;
2066 --------------------
2067 -- Await_Compile --
2068 -------------------
2070 procedure Await_Compile
2071 (Sfile : out File_Name_Type;
2072 Afile : out File_Name_Type;
2073 Uname : out File_Name_Type;
2074 OK : out Boolean)
2076 Pid : Process_Id;
2077 Project : Project_Id;
2079 begin
2080 pragma Assert (Outstanding_Compiles > 0);
2082 Sfile := No_File;
2083 Afile := No_File;
2084 Uname := No_Name;
2085 OK := False;
2087 -- The loop here is a work-around for a problem on VMS; in some
2088 -- circumstances (shared library and several executables, for
2089 -- example), there are child processes other than compilation
2090 -- processes that are received. Until this problem is resolved,
2091 -- we will ignore such processes.
2093 loop
2094 Wait_Process (Pid, OK);
2096 if Pid = Invalid_Pid then
2097 return;
2098 end if;
2100 for J in Running_Compile'First .. Outstanding_Compiles loop
2101 if Pid = Running_Compile (J).Pid then
2102 Sfile := Running_Compile (J).Full_Source_File;
2103 Afile := Running_Compile (J).Lib_File;
2104 Uname := Running_Compile (J).Source_Unit;
2105 Syntax_Only := Running_Compile (J).Syntax_Only;
2106 Output_Is_Object := Running_Compile (J).Output_Is_Object;
2107 Project := Running_Compile (J).Project;
2109 -- If a mapping file was used by this compilation,
2110 -- get its file name for reuse by a subsequent compilation
2112 if Running_Compile (J).Mapping_File /= No_Mapping_File then
2113 Last_Free_Indices (Project) :=
2114 Last_Free_Indices (Project) + 1;
2115 The_Free_Mapping_File_Indices
2116 (Project, Last_Free_Indices (Project)) :=
2117 Running_Compile (J).Mapping_File;
2118 end if;
2120 -- To actually remove this Pid and related info from
2121 -- Running_Compile replace its entry with the last valid
2122 -- entry in Running_Compile.
2124 if J = Outstanding_Compiles then
2125 null;
2127 else
2128 Running_Compile (J) :=
2129 Running_Compile (Outstanding_Compiles);
2130 end if;
2132 Outstanding_Compiles := Outstanding_Compiles - 1;
2133 return;
2134 end if;
2135 end loop;
2137 -- This child process was not one of our compilation processes;
2138 -- just ignore it for now.
2140 -- raise Program_Error;
2141 end loop;
2142 end Await_Compile;
2144 ---------------------------
2145 -- Bad_Compilation_Count --
2146 ---------------------------
2148 function Bad_Compilation_Count return Natural is
2149 begin
2150 return Bad_Compilation.Last - Bad_Compilation.First + 1;
2151 end Bad_Compilation_Count;
2153 -----------------------------------
2154 -- Collect_Arguments_And_Compile --
2155 -----------------------------------
2157 procedure Collect_Arguments_And_Compile
2158 (Source_File : File_Name_Type; Source_Index : Int)
2160 begin
2162 -- If arguments have not yet been collected (in Check), collect them
2163 -- now.
2165 if not Arguments_Collected then
2166 Collect_Arguments (Source_File, Source_Index, Args);
2167 end if;
2169 -- If we use mapping file (-P or -C switches), then get one
2171 if Create_Mapping_File then
2172 Get_Mapping_File (Arguments_Project);
2173 end if;
2175 -- If the source is part of a project file, we set the ADA_*_PATHs,
2176 -- check for an eventual library project, and use the full path.
2178 if Arguments_Project /= No_Project then
2179 Prj.Env.Set_Ada_Paths (Arguments_Project, True);
2181 if MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None then
2182 declare
2183 The_Data : Project_Data :=
2184 Projects.Table (Arguments_Project);
2185 Prj : Project_Id := Arguments_Project;
2187 begin
2188 while The_Data.Extended_By /= No_Project loop
2189 Prj := The_Data.Extended_By;
2190 The_Data := Projects.Table (Prj);
2191 end loop;
2193 if The_Data.Library and then not The_Data.Flag1 then
2194 -- Add to the Q all sources of the project that
2195 -- have not been marked
2197 Insert_Project_Sources
2198 (The_Project => Prj,
2199 All_Projects => False,
2200 Into_Q => True);
2202 -- Now mark the project as processed
2204 Projects.Table (Prj).Flag1 := True;
2205 end if;
2206 end;
2207 end if;
2209 -- Change to the object directory of the project file,
2210 -- if necessary.
2212 Change_To_Object_Directory (Arguments_Project);
2214 Pid := Compile (Arguments_Path_Name, Lib_File, Source_Index,
2215 Arguments (1 .. Last_Argument));
2217 else
2218 -- If this is a source outside of any project file, make sure
2219 -- it will be compiled in the object directory of the main project
2220 -- file.
2222 if Main_Project /= No_Project then
2223 Change_To_Object_Directory (Arguments_Project);
2224 end if;
2226 Pid := Compile (Full_Source_File, Lib_File, Source_Index,
2227 Arguments (1 .. Last_Argument));
2228 end if;
2229 end Collect_Arguments_And_Compile;
2231 -------------
2232 -- Compile --
2233 -------------
2235 function Compile
2236 (S : Name_Id;
2237 L : Name_Id;
2238 Source_Index : Int;
2239 Args : Argument_List) return Process_Id
2241 Comp_Args : Argument_List (Args'First .. Args'Last + 8);
2242 Comp_Next : Integer := Args'First;
2243 Comp_Last : Integer;
2245 function Ada_File_Name (Name : Name_Id) return Boolean;
2246 -- Returns True if Name is the name of an ada source file
2247 -- (i.e. suffix is .ads or .adb)
2249 -------------------
2250 -- Ada_File_Name --
2251 -------------------
2253 function Ada_File_Name (Name : Name_Id) return Boolean is
2254 begin
2255 Get_Name_String (Name);
2256 return
2257 Name_Len > 4
2258 and then Name_Buffer (Name_Len - 3 .. Name_Len - 1) = ".ad"
2259 and then (Name_Buffer (Name_Len) = 'b'
2260 or else
2261 Name_Buffer (Name_Len) = 's');
2262 end Ada_File_Name;
2264 -- Start of processing for Compile
2266 begin
2267 Enter_Into_Obsoleted (S);
2269 -- By default, Syntax_Only is False
2271 Syntax_Only := False;
2273 for J in Args'Range loop
2274 if Args (J).all = "-gnats" then
2276 -- If we compile with -gnats, the bind step and the link step
2277 -- are inhibited. Also, we set Syntax_Only to True, so that
2278 -- we don't fail when we don't find the ALI file, after
2279 -- compilation.
2281 Do_Bind_Step := False;
2282 Do_Link_Step := False;
2283 Syntax_Only := True;
2285 elsif Args (J).all = "-gnatc" then
2287 -- If we compile with -gnatc, the bind step and the link step
2288 -- are inhibited. We set Syntax_Only to False for the case when
2289 -- -gnats was previously specified.
2291 Do_Bind_Step := False;
2292 Do_Link_Step := False;
2293 Syntax_Only := False;
2294 end if;
2295 end loop;
2297 Comp_Args (Comp_Next) := Comp_Flag;
2298 Comp_Next := Comp_Next + 1;
2300 -- Optimize the simple case where the gcc command line looks like
2301 -- gcc -c -I. ... -I- file.adb --into-> gcc -c ... file.adb
2303 if Args (Args'First).all = "-I" & Normalized_CWD
2304 and then Args (Args'Last).all = "-I-"
2305 and then S = Strip_Directory (S)
2306 then
2307 Comp_Last := Comp_Next + Args'Length - 3;
2308 Comp_Args (Comp_Next .. Comp_Last) :=
2309 Args (Args'First + 1 .. Args'Last - 1);
2311 else
2312 Comp_Last := Comp_Next + Args'Length - 1;
2313 Comp_Args (Comp_Next .. Comp_Last) := Args;
2314 end if;
2316 -- Set -gnatpg for predefined files (for this purpose the renamings
2317 -- such as Text_IO do not count as predefined). Note that we strip
2318 -- the directory name from the source file name becase the call to
2319 -- Fname.Is_Predefined_File_Name cannot deal with directory prefixes.
2321 declare
2322 Fname : constant File_Name_Type := Strip_Directory (S);
2324 begin
2325 if Is_Predefined_File_Name (Fname, False) then
2326 if Check_Readonly_Files then
2327 Comp_Last := Comp_Last + 1;
2328 Comp_Args (Comp_Last) := GNAT_Flag;
2330 else
2331 Make_Failed
2332 ("not allowed to compile """ &
2333 Get_Name_String (Fname) &
2334 """; use -a switch, or compile file with " &
2335 """-gnatg"" switch");
2336 end if;
2337 end if;
2338 end;
2340 -- Now check if the file name has one of the suffixes familiar to
2341 -- the gcc driver. If this is not the case then add the ada flag
2342 -- "-x ada".
2344 if not Ada_File_Name (S) and then not Targparm.AAMP_On_Target then
2345 Comp_Last := Comp_Last + 1;
2346 Comp_Args (Comp_Last) := Ada_Flag_1;
2347 Comp_Last := Comp_Last + 1;
2348 Comp_Args (Comp_Last) := Ada_Flag_2;
2349 end if;
2351 if Source_Index /= 0 then
2352 declare
2353 Num : constant String := Source_Index'Img;
2354 begin
2355 Comp_Last := Comp_Last + 1;
2356 Comp_Args (Comp_Last) :=
2357 new String'("-gnateI" & Num (Num'First + 1 .. Num'Last));
2358 end;
2359 end if;
2361 if Source_Index /= 0 or else
2362 L /= Strip_Directory (L) or else
2363 Object_Directory_Path /= null
2364 then
2366 -- Build -o argument.
2368 Get_Name_String (L);
2370 for J in reverse 1 .. Name_Len loop
2371 if Name_Buffer (J) = '.' then
2372 Name_Len := J + Object_Suffix'Length - 1;
2373 Name_Buffer (J .. Name_Len) := Object_Suffix;
2374 exit;
2375 end if;
2376 end loop;
2378 Comp_Last := Comp_Last + 1;
2379 Comp_Args (Comp_Last) := Output_Flag;
2380 Comp_Last := Comp_Last + 1;
2382 -- If an object directory was specified, prepend the object file
2383 -- name with this object directory.
2385 if Object_Directory_Path /= null then
2386 Comp_Args (Comp_Last) :=
2387 new String'(Object_Directory_Path.all &
2388 Name_Buffer (1 .. Name_Len));
2390 else
2391 Comp_Args (Comp_Last) :=
2392 new String'(Name_Buffer (1 .. Name_Len));
2393 end if;
2394 end if;
2396 if Create_Mapping_File then
2397 Comp_Last := Comp_Last + 1;
2398 Comp_Args (Comp_Last) := Mapping_File_Arg;
2399 end if;
2401 Get_Name_String (S);
2403 Comp_Last := Comp_Last + 1;
2404 Comp_Args (Comp_Last) := new String'(Name_Buffer (1 .. Name_Len));
2406 GNAT.OS_Lib.Normalize_Arguments (Comp_Args (Args'First .. Comp_Last));
2408 Display (Gcc.all, Comp_Args (Args'First .. Comp_Last));
2410 if Gcc_Path = null then
2411 Make_Failed ("error, unable to locate ", Gcc.all);
2412 end if;
2414 return
2415 GNAT.OS_Lib.Non_Blocking_Spawn
2416 (Gcc_Path.all, Comp_Args (Args'First .. Comp_Last));
2417 end Compile;
2419 ----------------------
2420 -- Get_Mapping_File --
2421 ----------------------
2423 procedure Get_Mapping_File (Project : Project_Id) is
2424 begin
2425 -- If there is a mapping file ready to be reused, reuse it
2427 if Last_Free_Indices (Project) > 0 then
2428 Mfile := The_Free_Mapping_File_Indices
2429 (Project, Last_Free_Indices (Project));
2430 Last_Free_Indices (Project) := Last_Free_Indices (Project) - 1;
2432 -- Otherwise, create and initialize a new one
2434 else
2435 Init_Mapping_File (Project => Project, File_Index => Mfile);
2436 end if;
2438 -- Put the name in the mapping file argument for the invocation
2439 -- of the compiler.
2441 Free (Mapping_File_Arg);
2442 Mapping_File_Arg :=
2443 new String'("-gnatem=" &
2444 Get_Name_String
2445 (The_Mapping_File_Names (Project, Mfile)));
2447 end Get_Mapping_File;
2449 -----------------------
2450 -- Get_Next_Good_ALI --
2451 -----------------------
2453 function Get_Next_Good_ALI return ALI_Id is
2454 ALI : ALI_Id;
2456 begin
2457 pragma Assert (Good_ALI_Present);
2458 ALI := Good_ALI.Table (Good_ALI.Last);
2459 Good_ALI.Decrement_Last;
2460 return ALI;
2461 end Get_Next_Good_ALI;
2463 ----------------------
2464 -- Good_ALI_Present --
2465 ----------------------
2467 function Good_ALI_Present return Boolean is
2468 begin
2469 return Good_ALI.First <= Good_ALI.Last;
2470 end Good_ALI_Present;
2472 --------------------
2473 -- Record_Failure --
2474 --------------------
2476 procedure Record_Failure
2477 (File : File_Name_Type;
2478 Unit : Unit_Name_Type;
2479 Found : Boolean := True)
2481 begin
2482 Bad_Compilation.Increment_Last;
2483 Bad_Compilation.Table (Bad_Compilation.Last) := (File, Unit, Found);
2484 end Record_Failure;
2486 ---------------------
2487 -- Record_Good_ALI --
2488 ---------------------
2490 procedure Record_Good_ALI (A : ALI_Id) is
2491 begin
2492 Good_ALI.Increment_Last;
2493 Good_ALI.Table (Good_ALI.Last) := A;
2494 end Record_Good_ALI;
2496 -- Start of processing for Compile_Sources
2498 begin
2499 pragma Assert (Args'First = 1);
2501 -- Package and Queue initializations.
2503 Good_ALI.Init;
2504 Output.Set_Standard_Error;
2506 if First_Q_Initialization then
2507 Init_Q;
2508 end if;
2510 if Initialize_ALI_Data then
2511 Initialize_ALI;
2512 Initialize_ALI_Source;
2513 end if;
2515 -- The following two flags affect the behavior of ALI.Set_Source_Table.
2516 -- We set Check_Source_Files to True to ensure that source file
2517 -- time stamps are checked, and we set All_Sources to False to
2518 -- avoid checking the presence of the source files listed in the
2519 -- source dependency section of an ali file (which would be a mistake
2520 -- since the ali file may be obsolete).
2522 Check_Source_Files := True;
2523 All_Sources := False;
2525 -- Only insert in the Q if it is not already done, to avoid simultaneous
2526 -- compilations if -jnnn is used.
2528 if not Is_Marked (Main_Source, Main_Index) then
2529 Insert_Q (Main_Source, Index => Main_Index);
2530 Mark (Main_Source, Main_Index);
2531 end if;
2533 First_Compiled_File := No_File;
2534 Most_Recent_Obj_File := No_File;
2535 Most_Recent_Obj_Stamp := Empty_Time_Stamp;
2536 Main_Unit := False;
2538 -- Keep looping until there is no more work to do (the Q is empty)
2539 -- and all the outstanding compilations have terminated
2541 Make_Loop : while not Empty_Q or else Outstanding_Compiles > 0 loop
2543 -- If the user does not want to keep going in case of errors then
2544 -- wait for the remaining outstanding compiles and then exit.
2546 if Bad_Compilation_Count > 0 and then not Keep_Going then
2547 while Outstanding_Compiles > 0 loop
2548 Await_Compile
2549 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
2551 if not Compilation_OK then
2552 Record_Failure (Full_Source_File, Source_Unit);
2553 end if;
2554 end loop;
2556 exit Make_Loop;
2557 end if;
2559 -- PHASE 1: Check if there is more work that we can do (ie the Q
2560 -- is non empty). If there is, do it only if we have not yet used
2561 -- up all the available processes.
2563 if not Empty_Q and then Outstanding_Compiles < Max_Process then
2564 declare
2565 Source_Index : Int;
2566 -- Index of the current unit in the current source file
2568 begin
2569 Extract_From_Q (Source_File, Source_Unit, Source_Index);
2570 Full_Source_File := Osint.Full_Source_Name (Source_File);
2571 Lib_File := Osint.Lib_File_Name
2572 (Source_File, Source_Index);
2573 Full_Lib_File := Osint.Full_Lib_File_Name (Lib_File);
2575 -- If this source has already been compiled, the executable is
2576 -- obsolete.
2578 if Is_In_Obsoleted (Source_File) then
2579 Executable_Obsolete := True;
2580 end if;
2582 -- If the library file is an Ada library skip it
2584 if Full_Lib_File /= No_File
2585 and then In_Ada_Lib_Dir (Full_Lib_File)
2586 then
2587 Verbose_Msg
2588 (Lib_File, "is in an Ada library", Prefix => " ");
2590 -- If the library file is a read-only library skip it, but
2591 -- only if, when using project files, this library file is
2592 -- in the right object directory (a read-only ALI file
2593 -- in the object directory of a project being extended
2594 -- should not be skipped).
2596 elsif Full_Lib_File /= No_File
2597 and then not Check_Readonly_Files
2598 and then Is_Readonly_Library (Full_Lib_File)
2599 and then Is_In_Object_Directory (Source_File, Full_Lib_File)
2600 then
2601 Verbose_Msg
2602 (Lib_File, "is a read-only library", Prefix => " ");
2604 -- The source file that we are checking cannot be located
2606 elsif Full_Source_File = No_File then
2607 Record_Failure (Source_File, Source_Unit, False);
2609 -- Source and library files can be located but are internal
2610 -- files
2612 elsif not Check_Readonly_Files
2613 and then Full_Lib_File /= No_File
2614 and then Is_Internal_File_Name (Source_File)
2615 then
2616 if Force_Compilations then
2617 Fail
2618 ("not allowed to compile """ &
2619 Get_Name_String (Source_File) &
2620 """; use -a switch, or compile file with " &
2621 """-gnatg"" switch");
2622 end if;
2624 Verbose_Msg
2625 (Lib_File, "is an internal library", Prefix => " ");
2627 -- The source file that we are checking can be located
2629 else
2630 Arguments_Collected := False;
2632 -- Don't waste any time if we have to recompile anyway
2634 Obj_Stamp := Empty_Time_Stamp;
2635 Need_To_Compile := Force_Compilations;
2637 if not Force_Compilations then
2638 Read_Only :=
2639 Full_Lib_File /= No_File
2640 and then not Check_Readonly_Files
2641 and then Is_Readonly_Library (Full_Lib_File);
2642 Check (Source_File, Source_Index, Args, Lib_File,
2643 Read_Only, ALI, Obj_File, Obj_Stamp);
2644 Need_To_Compile := (ALI = No_ALI_Id);
2645 end if;
2647 if not Need_To_Compile then
2649 -- The ALI file is up-to-date. Record its Id.
2651 Record_Good_ALI (ALI);
2653 -- Record the time stamp of the most recent object file
2654 -- as long as no (re)compilations are needed.
2656 if First_Compiled_File = No_File
2657 and then (Most_Recent_Obj_File = No_File
2658 or else Obj_Stamp > Most_Recent_Obj_Stamp)
2659 then
2660 Most_Recent_Obj_File := Obj_File;
2661 Most_Recent_Obj_Stamp := Obj_Stamp;
2662 end if;
2664 else
2665 -- Is this the first file we have to compile?
2667 if First_Compiled_File = No_File then
2668 First_Compiled_File := Full_Source_File;
2669 Most_Recent_Obj_File := No_File;
2671 if Do_Not_Execute then
2672 exit Make_Loop;
2673 end if;
2674 end if;
2676 if In_Place_Mode then
2678 -- If the library file was not found, then save the
2679 -- library file near the source file.
2681 if Full_Lib_File = No_File then
2682 Lib_File := Osint.Lib_File_Name
2683 (Full_Source_File, Source_Index);
2685 -- If the library file was found, then save the
2686 -- library file in the same place.
2688 else
2689 Lib_File := Full_Lib_File;
2690 end if;
2692 end if;
2694 -- Start the compilation and record it. We can do this
2695 -- because there is at least one free process.
2697 Collect_Arguments_And_Compile (Source_File, Source_Index);
2699 -- Make sure we could successfully start the compilation
2701 if Pid = Invalid_Pid then
2702 Record_Failure (Full_Source_File, Source_Unit);
2703 else
2704 Add_Process
2705 (Pid,
2706 Full_Source_File,
2707 Lib_File,
2708 Source_Unit,
2709 Mfile);
2710 end if;
2711 end if;
2712 end if;
2713 end;
2714 end if;
2716 -- PHASE 2: Now check if we should wait for a compilation to
2717 -- finish. This is the case if all the available processes are
2718 -- busy compiling sources or there is nothing else to do
2719 -- (that is the Q is empty and there are no good ALIs to process).
2721 if Outstanding_Compiles = Max_Process
2722 or else (Empty_Q
2723 and then not Good_ALI_Present
2724 and then Outstanding_Compiles > 0)
2725 then
2726 Await_Compile
2727 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
2729 if not Compilation_OK then
2730 Record_Failure (Full_Source_File, Source_Unit);
2731 end if;
2733 if Compilation_OK or else Keep_Going then
2735 -- Re-read the updated library file
2737 declare
2738 Saved_Object_Consistency : constant Boolean :=
2739 Check_Object_Consistency;
2741 begin
2742 -- If compilation was not OK, or if output is not an
2743 -- object file and we don't do the bind step, don't check
2744 -- for object consistency.
2746 Check_Object_Consistency :=
2747 Check_Object_Consistency
2748 and Compilation_OK
2749 and (Output_Is_Object or Do_Bind_Step);
2750 Text := Read_Library_Info (Lib_File);
2752 -- Restore Check_Object_Consistency to its initial value
2754 Check_Object_Consistency := Saved_Object_Consistency;
2755 end;
2757 -- If an ALI file was generated by this compilation, scan
2758 -- the ALI file and record it.
2759 -- If the scan fails, a previous ali file is inconsistent with
2760 -- the unit just compiled.
2762 if Text /= null then
2763 ALI :=
2764 Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
2766 if ALI = No_ALI_Id then
2768 -- Record a failure only if not already done
2770 if Compilation_OK then
2771 Inform
2772 (Lib_File,
2773 "incompatible ALI file, please recompile");
2774 Record_Failure (Full_Source_File, Source_Unit);
2775 end if;
2776 else
2777 Free (Text);
2778 Record_Good_ALI (ALI);
2779 end if;
2781 -- If we could not read the ALI file that was just generated
2782 -- then there could be a problem reading either the ALI or the
2783 -- corresponding object file (if Check_Object_Consistency
2784 -- is set Read_Library_Info checks that the time stamp of the
2785 -- object file is more recent than that of the ALI). For an
2786 -- example of problems caught by this test see [6625-009].
2787 -- However, we record a failure only if not already done.
2789 else
2790 if Compilation_OK and not Syntax_Only then
2791 Inform
2792 (Lib_File,
2793 "WARNING: ALI or object file not found after compile");
2794 Record_Failure (Full_Source_File, Source_Unit);
2795 end if;
2796 end if;
2797 end if;
2798 end if;
2800 -- PHASE 3: Check if we recorded good ALI files. If yes process
2801 -- them now in the order in which they have been recorded. There
2802 -- are two occasions in which we record good ali files. The first is
2803 -- in phase 1 when, after scanning an existing ALI file we realize
2804 -- it is up-to-date, the second instance is after a successful
2805 -- compilation.
2807 while Good_ALI_Present loop
2808 ALI := Get_Next_Good_ALI;
2810 declare
2811 Source_Index : Int := Unit_Index_Of (ALIs.Table (ALI).Afile);
2813 begin
2814 -- If we are processing the library file corresponding to the
2815 -- main source file check if this source can be a main unit.
2817 if ALIs.Table (ALI).Sfile = Main_Source and then
2818 Source_Index = Main_Index
2819 then
2820 Main_Unit := ALIs.Table (ALI).Main_Program /= None;
2821 end if;
2823 -- The following adds the standard library (s-stalib) to the
2824 -- list of files to be handled by gnatmake: this file and any
2825 -- files it depends on are always included in every bind,
2826 -- even if they are not in the explicit dependency list.
2827 -- Of course, it is not added if Suppress_Standard_Library
2828 -- is True.
2830 -- However, to avoid annoying output about s-stalib.ali being
2831 -- read only, when "-v" is used, we add the standard library
2832 -- only when "-a" is used.
2834 if Need_To_Check_Standard_Library then
2835 Need_To_Check_Standard_Library := False;
2837 if not Targparm.Suppress_Standard_Library_On_Target then
2838 declare
2839 Sfile : Name_Id;
2840 Add_It : Boolean := True;
2842 begin
2843 Name_Len := Standard_Library_Package_Body_Name'Length;
2844 Name_Buffer (1 .. Name_Len) :=
2845 Standard_Library_Package_Body_Name;
2846 Sfile := Name_Enter;
2848 -- If we have a special runtime, we add the standard
2849 -- library only if we can find it.
2851 if RTS_Switch then
2852 Add_It :=
2853 Find_File (Sfile, Osint.Source) /= No_File;
2854 end if;
2856 if Add_It then
2857 if Is_Marked (Sfile) then
2858 if Is_In_Obsoleted (Sfile) then
2859 Executable_Obsolete := True;
2860 end if;
2862 else
2863 Insert_Q (Sfile, Index => 0);
2864 Mark (Sfile, Index => 0);
2865 end if;
2866 end if;
2867 end;
2868 end if;
2869 end if;
2871 -- Now insert in the Q the unmarked source files (i.e. those
2872 -- which have never been inserted in the Q and hence never
2873 -- considered). Only do that if Unique_Compile is False.
2875 if not Unique_Compile then
2876 for J in
2877 ALIs.Table (ALI).First_Unit .. ALIs.Table (ALI).Last_Unit
2878 loop
2879 for K in
2880 Units.Table (J).First_With .. Units.Table (J).Last_With
2881 loop
2882 Sfile := Withs.Table (K).Sfile;
2883 Add_Dependency (ALIs.Table (ALI).Sfile, Sfile);
2885 if Is_In_Obsoleted (Sfile) then
2886 Executable_Obsolete := True;
2887 end if;
2889 if Sfile = No_File then
2890 Debug_Msg
2891 ("Skipping generic:", Withs.Table (K).Uname);
2893 else
2894 Source_Index :=
2895 Unit_Index_Of (Withs.Table (K).Afile);
2897 if Is_Marked (Sfile, Source_Index) then
2898 Debug_Msg ("Skipping marked file:", Sfile);
2900 elsif not Check_Readonly_Files
2901 and then Is_Internal_File_Name (Sfile)
2902 then
2903 Debug_Msg ("Skipping internal file:", Sfile);
2905 else
2906 Insert_Q
2907 (Sfile, Withs.Table (K).Uname, Source_Index);
2908 Mark (Sfile, Source_Index);
2909 end if;
2910 end if;
2911 end loop;
2912 end loop;
2913 end if;
2914 end;
2915 end loop;
2917 if Display_Compilation_Progress then
2918 Write_Str ("completed ");
2919 Write_Int (Int (Q_Front));
2920 Write_Str (" out of ");
2921 Write_Int (Int (Q.Last));
2922 Write_Str (" (");
2923 Write_Int (Int ((Q_Front * 100) / (Q.Last - Q.First)));
2924 Write_Str ("%)...");
2925 Write_Eol;
2926 end if;
2927 end loop Make_Loop;
2929 Compilation_Failures := Bad_Compilation_Count;
2931 -- Compilation is finished
2933 -- Delete any temporary configuration pragma file
2935 Delete_Temp_Config_Files;
2937 end Compile_Sources;
2939 ----------------------------------
2940 -- Configuration_Pragmas_Switch --
2941 ----------------------------------
2943 function Configuration_Pragmas_Switch
2944 (For_Project : Project_Id) return Argument_List
2946 The_Packages : Package_Id;
2947 Gnatmake : Package_Id;
2948 Compiler : Package_Id;
2950 Global_Attribute : Variable_Value := Nil_Variable_Value;
2951 Local_Attribute : Variable_Value := Nil_Variable_Value;
2953 Global_Attribute_Present : Boolean := False;
2954 Local_Attribute_Present : Boolean := False;
2956 Result : Argument_List (1 .. 3);
2957 Last : Natural := 0;
2959 function Absolute_Path
2960 (Path : Name_Id;
2961 Project : Project_Id) return String;
2962 -- Returns an absolute path for a configuration pragmas file.
2964 -------------------
2965 -- Absolute_Path --
2966 -------------------
2968 function Absolute_Path
2969 (Path : Name_Id;
2970 Project : Project_Id) return String
2972 begin
2973 Get_Name_String (Path);
2975 declare
2976 Path_Name : constant String := Name_Buffer (1 .. Name_Len);
2978 begin
2979 if Is_Absolute_Path (Path_Name) then
2980 return Path_Name;
2982 else
2983 declare
2984 Parent_Directory : constant String :=
2985 Get_Name_String (Projects.Table (Project).Directory);
2987 begin
2988 if Parent_Directory (Parent_Directory'Last) =
2989 Directory_Separator
2990 then
2991 return Parent_Directory & Path_Name;
2993 else
2994 return Parent_Directory & Directory_Separator & Path_Name;
2995 end if;
2996 end;
2997 end if;
2998 end;
2999 end Absolute_Path;
3001 -- Start of processing for Configuration_Pragmas_Switch
3003 begin
3004 Prj.Env.Create_Config_Pragmas_File (For_Project, Main_Project);
3006 if Projects.Table (For_Project).Config_File_Name /= No_Name then
3007 Temporary_Config_File :=
3008 Projects.Table (For_Project).Config_File_Temp;
3009 Last := 1;
3010 Result (1) :=
3011 new String'
3012 ("-gnatec=" &
3013 Get_Name_String
3014 (Projects.Table (For_Project).Config_File_Name));
3016 else
3017 Temporary_Config_File := False;
3018 end if;
3020 -- Check for attribute Builder'Global_Configuration_Pragmas
3022 The_Packages := Projects.Table (Main_Project).Decl.Packages;
3023 Gnatmake :=
3024 Prj.Util.Value_Of
3025 (Name => Name_Builder,
3026 In_Packages => The_Packages);
3028 if Gnatmake /= No_Package then
3029 Global_Attribute := Prj.Util.Value_Of
3030 (Variable_Name => Name_Global_Configuration_Pragmas,
3031 In_Variables => Packages.Table (Gnatmake).Decl.Attributes);
3032 Global_Attribute_Present :=
3033 Global_Attribute /= Nil_Variable_Value
3034 and then Get_Name_String (Global_Attribute.Value) /= "";
3036 if Global_Attribute_Present then
3037 declare
3038 Path : constant String :=
3039 Absolute_Path
3040 (Global_Attribute.Value, Global_Attribute.Project);
3041 begin
3042 if not Is_Regular_File (Path) then
3043 Make_Failed
3044 ("cannot find configuration pragmas file ", Path);
3045 end if;
3047 Last := Last + 1;
3048 Result (Last) := new String'("-gnatec=" & Path);
3049 end;
3050 end if;
3051 end if;
3053 -- Check for attribute Compiler'Local_Configuration_Pragmas
3055 The_Packages := Projects.Table (For_Project).Decl.Packages;
3056 Compiler :=
3057 Prj.Util.Value_Of
3058 (Name => Name_Compiler,
3059 In_Packages => The_Packages);
3061 if Compiler /= No_Package then
3062 Local_Attribute := Prj.Util.Value_Of
3063 (Variable_Name => Name_Local_Configuration_Pragmas,
3064 In_Variables => Packages.Table (Compiler).Decl.Attributes);
3065 Local_Attribute_Present :=
3066 Local_Attribute /= Nil_Variable_Value
3067 and then Get_Name_String (Local_Attribute.Value) /= "";
3069 if Local_Attribute_Present then
3070 declare
3071 Path : constant String :=
3072 Absolute_Path
3073 (Local_Attribute.Value, Local_Attribute.Project);
3074 begin
3075 if not Is_Regular_File (Path) then
3076 Make_Failed
3077 ("cannot find configuration pragmas file ", Path);
3078 end if;
3080 Last := Last + 1;
3081 Result (Last) := new String'("-gnatec=" & Path);
3082 end;
3083 end if;
3084 end if;
3086 return Result (1 .. Last);
3087 end Configuration_Pragmas_Switch;
3089 ---------------
3090 -- Debug_Msg --
3091 ---------------
3093 procedure Debug_Msg (S : String; N : Name_Id) is
3094 begin
3095 if Debug.Debug_Flag_W then
3096 Write_Str (" ... ");
3097 Write_Str (S);
3098 Write_Str (" ");
3099 Write_Name (N);
3100 Write_Eol;
3101 end if;
3102 end Debug_Msg;
3104 ---------------------------
3105 -- Delete_All_Temp_Files --
3106 ---------------------------
3108 procedure Delete_All_Temp_Files is
3109 begin
3110 if Gnatmake_Called and not Debug.Debug_Flag_N then
3111 Delete_Mapping_Files;
3112 Delete_Temp_Config_Files;
3113 Prj.Env.Delete_All_Path_Files;
3114 end if;
3115 end Delete_All_Temp_Files;
3117 --------------------------
3118 -- Delete_Mapping_Files --
3119 --------------------------
3121 procedure Delete_Mapping_Files is
3122 Success : Boolean;
3123 begin
3124 if not Debug.Debug_Flag_N then
3125 if The_Mapping_File_Names /= null then
3126 for Project in The_Mapping_File_Names'Range (1) loop
3127 for Index in 1 .. Last_Mapping_File_Names (Project) loop
3128 Delete_File
3129 (Name => Get_Name_String
3130 (The_Mapping_File_Names (Project, Index)),
3131 Success => Success);
3132 end loop;
3133 end loop;
3134 end if;
3135 end if;
3136 end Delete_Mapping_Files;
3138 ------------------------------
3139 -- Delete_Temp_Config_Files --
3140 ------------------------------
3142 procedure Delete_Temp_Config_Files is
3143 Success : Boolean;
3144 begin
3145 if (not Debug.Debug_Flag_N) and Main_Project /= No_Project then
3146 for Project in 1 .. Projects.Last loop
3147 if Projects.Table (Project).Config_File_Temp then
3148 if Verbose_Mode then
3149 Write_Str ("Deleting temp configuration file """);
3150 Write_Str (Get_Name_String
3151 (Projects.Table (Project).Config_File_Name));
3152 Write_Line ("""");
3153 end if;
3155 Delete_File
3156 (Name => Get_Name_String
3157 (Projects.Table (Project).Config_File_Name),
3158 Success => Success);
3160 -- Make sure that we don't have a config file for this
3161 -- project, in case when there are several mains.
3162 -- In this case, we will recreate another config file:
3163 -- we cannot reuse the one that we just deleted!
3165 Projects.Table (Project).Config_Checked := False;
3166 Projects.Table (Project).Config_File_Name := No_Name;
3167 Projects.Table (Project).Config_File_Temp := False;
3168 end if;
3169 end loop;
3170 end if;
3171 end Delete_Temp_Config_Files;
3173 -------------
3174 -- Display --
3175 -------------
3177 procedure Display (Program : String; Args : Argument_List) is
3178 begin
3179 pragma Assert (Args'First = 1);
3181 if Display_Executed_Programs then
3182 Write_Str (Program);
3184 for J in Args'Range loop
3186 -- Do not display the mapping file argument automatically
3187 -- created when using a project file.
3189 if Main_Project = No_Project
3190 or else Debug.Debug_Flag_N
3191 or else Args (J)'Length < 8
3192 or else
3193 Args (J)(Args (J)'First .. Args (J)'First + 6) /= "-gnatem"
3194 then
3195 -- When -dn is not specified, do not display the config
3196 -- pragmas switch (-gnatec) for the temporary file created
3197 -- by the project manager (always the first -gnatec switch).
3198 -- Reset Temporary_Config_File to False so that the eventual
3199 -- other -gnatec switches will be displayed.
3201 if (not Debug.Debug_Flag_N)
3202 and then Temporary_Config_File
3203 and then Args (J)'Length > 7
3204 and then Args (J)(Args (J)'First .. Args (J)'First + 6)
3205 = "-gnatec"
3206 then
3207 Temporary_Config_File := False;
3209 -- Do not display the -F=mapping_file switch for gnatbind,
3210 -- if -dn is not specified.
3212 elsif Debug.Debug_Flag_N
3213 or else Args (J)'Length < 4
3214 or else Args (J)(Args (J)'First .. Args (J)'First + 2) /=
3215 "-F="
3216 then
3217 Write_Str (" ");
3218 Write_Str (Args (J).all);
3219 end if;
3220 end if;
3221 end loop;
3223 Write_Eol;
3224 end if;
3225 end Display;
3227 ----------------------
3228 -- Display_Commands --
3229 ----------------------
3231 procedure Display_Commands (Display : Boolean := True) is
3232 begin
3233 Display_Executed_Programs := Display;
3234 end Display_Commands;
3236 -------------
3237 -- Empty_Q --
3238 -------------
3240 function Empty_Q return Boolean is
3241 begin
3242 if Debug.Debug_Flag_P then
3243 Write_Str (" Q := [");
3245 for J in Q_Front .. Q.Last - 1 loop
3246 Write_Str (" ");
3247 Write_Name (Q.Table (J).File);
3248 Write_Eol;
3249 Write_Str (" ");
3250 end loop;
3252 Write_Str ("]");
3253 Write_Eol;
3254 end if;
3256 return Q_Front >= Q.Last;
3257 end Empty_Q;
3259 --------------------------
3260 -- Enter_Into_Obsoleted --
3261 --------------------------
3263 procedure Enter_Into_Obsoleted (F : Name_Id) is
3264 Name : constant String := Get_Name_String (F);
3265 First : Natural := Name'Last;
3266 F2 : Name_Id := F;
3268 begin
3269 while First > Name'First
3270 and then Name (First - 1) /= Directory_Separator
3271 and then Name (First - 1) /= '/'
3272 loop
3273 First := First - 1;
3274 end loop;
3276 if First /= Name'First then
3277 Name_Len := 0;
3278 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
3279 F2 := Name_Find;
3280 end if;
3282 Debug_Msg ("New entry in Obsoleted table:", F2);
3283 Obsoleted.Set (F2, True);
3284 end Enter_Into_Obsoleted;
3286 ---------------------
3287 -- Extract_Failure --
3288 ---------------------
3290 procedure Extract_Failure
3291 (File : out File_Name_Type;
3292 Unit : out Unit_Name_Type;
3293 Found : out Boolean)
3295 begin
3296 File := Bad_Compilation.Table (Bad_Compilation.Last).File;
3297 Unit := Bad_Compilation.Table (Bad_Compilation.Last).Unit;
3298 Found := Bad_Compilation.Table (Bad_Compilation.Last).Found;
3299 Bad_Compilation.Decrement_Last;
3300 end Extract_Failure;
3302 --------------------
3303 -- Extract_From_Q --
3304 --------------------
3306 procedure Extract_From_Q
3307 (Source_File : out File_Name_Type;
3308 Source_Unit : out Unit_Name_Type;
3309 Source_Index : out Int)
3311 File : constant File_Name_Type := Q.Table (Q_Front).File;
3312 Unit : constant Unit_Name_Type := Q.Table (Q_Front).Unit;
3313 Index : constant Int := Q.Table (Q_Front).Index;
3315 begin
3316 if Debug.Debug_Flag_Q then
3317 Write_Str (" Q := Q - [ ");
3318 Write_Name (File);
3320 if Index /= 0 then
3321 Write_Str (", ");
3322 Write_Int (Index);
3323 end if;
3325 Write_Str (" ]");
3326 Write_Eol;
3327 end if;
3329 Q_Front := Q_Front + 1;
3330 Source_File := File;
3331 Source_Unit := Unit;
3332 Source_Index := Index;
3333 end Extract_From_Q;
3335 --------------
3336 -- Gnatmake --
3337 --------------
3339 procedure Gnatmake is
3340 Main_Source_File : File_Name_Type;
3341 -- The source file containing the main compilation unit
3343 Compilation_Failures : Natural;
3345 Total_Compilation_Failures : Natural := 0;
3347 Is_Main_Unit : Boolean;
3348 -- Set to True by Compile_Sources if the Main_Source_File can be a
3349 -- main unit.
3351 Main_ALI_File : File_Name_Type;
3352 -- The ali file corresponding to Main_Source_File
3354 Executable : File_Name_Type := No_File;
3355 -- The file name of an executable
3357 Non_Std_Executable : Boolean := False;
3358 -- Non_Std_Executable is set to True when there is a possibility
3359 -- that the linker will not choose the correct executable file name.
3361 Current_Work_Dir : constant String_Access :=
3362 new String'(Get_Current_Dir);
3363 -- The current working directory, used to modify some relative path
3364 -- switches on the command line when a project file is used.
3366 Current_Main_Index : Int := 0;
3367 -- If not zero, the index of the current main unit in its source file
3369 There_Are_Stand_Alone_Libraries : Boolean := False;
3370 -- Set to True when there are Stand-Alone Libraries, so that gnatbind
3371 -- is invoked with the -F switch to force checking of elaboration flags.
3373 begin
3374 Gnatmake_Called := True;
3376 Install_Int_Handler (Sigint_Intercepted'Access);
3378 Do_Compile_Step := True;
3379 Do_Bind_Step := True;
3380 Do_Link_Step := True;
3382 Obsoleted.Reset;
3384 Make.Initialize;
3386 Bind_Shared := No_Shared_Switch'Access;
3387 Link_With_Shared_Libgcc := No_Shared_Libgcc_Switch'Access;
3388 Bind_Shared_Known := False;
3390 Failed_Links.Set_Last (0);
3391 Successful_Links.Set_Last (0);
3393 if Hostparm.Java_VM then
3394 Gcc := new String'("jgnat");
3395 Gnatbind := new String'("jgnatbind");
3396 Gnatlink := new String'("jgnatlink");
3398 -- Do not check for an object file (".o") when compiling to
3399 -- Java bytecode since ".class" files are generated instead.
3401 Check_Object_Consistency := False;
3402 end if;
3404 -- Special case when switch -B was specified
3406 if Build_Bind_And_Link_Full_Project then
3408 -- When switch -B is specified, there must be a project file
3410 if Main_Project = No_Project then
3411 Make_Failed ("-B cannot be used without a project file");
3413 -- No main program may be specified on the command line
3415 elsif Osint.Number_Of_Files /= 0 then
3416 Make_Failed ("-B cannot be used with a main specified on " &
3417 "the command line");
3419 -- And the project file cannot be a library project file
3421 elsif Projects.Table (Main_Project).Library then
3422 Make_Failed ("-B cannot be used for a library project file");
3424 else
3425 Insert_Project_Sources
3426 (The_Project => Main_Project,
3427 All_Projects => Unique_Compile_All_Projects,
3428 Into_Q => False);
3430 -- If there are no sources to compile, we fail
3432 if Osint.Number_Of_Files = 0 then
3433 Make_Failed ("no sources to compile");
3434 end if;
3436 -- Specify -n for gnatbind and add the ALI files of all the
3437 -- sources, except the one which is a fake main subprogram:
3438 -- this is the one for the binder generated file and it will be
3439 -- transmitted to gnatlink. These sources are those that are
3440 -- in the queue.
3442 Add_Switch ("-n", Binder, And_Save => True);
3444 for J in Q.First .. Q.Last - 1 loop
3445 Add_Switch
3446 (Get_Name_String
3447 (Lib_File_Name (Q.Table (J).File)),
3448 Binder, And_Save => True);
3449 end loop;
3450 end if;
3452 elsif Main_Index /= 0 and then Osint.Number_Of_Files > 1 then
3453 Make_Failed ("cannot specify several mains with a multi-unit index");
3455 elsif Main_Project /= No_Project then
3457 -- If the main project file is a library project file, main(s)
3458 -- cannot be specified on the command line.
3460 if Osint.Number_Of_Files /= 0 then
3461 if Projects.Table (Main_Project).Library
3462 and then not Unique_Compile
3463 and then ((not Make_Steps) or else Bind_Only or else Link_Only)
3464 then
3465 Make_Failed ("cannot specify a main program " &
3466 "on the command line for a library project file");
3468 else
3469 -- Check that each main on the command line is a source of a
3470 -- project file and, if there are several mains, each of them
3471 -- is a source of the same project file.
3473 Mains.Reset;
3475 declare
3476 Real_Main_Project : Project_Id := No_Project;
3477 -- The project of the first main
3479 Proj : Project_Id := No_Project;
3480 -- The project of the current main
3482 begin
3483 -- Check each main
3485 loop
3486 declare
3487 Main : constant String := Mains.Next_Main;
3488 -- The name specified on the command line may include
3489 -- directory information.
3491 File_Name : constant String := Base_Name (Main);
3492 -- The simple file name of the current main main
3494 begin
3495 exit when Main = "";
3497 -- Get the project of the current main
3499 Proj := Prj.Env.Project_Of (File_Name, Main_Project);
3501 -- Fail if the current main is not a source of a
3502 -- project.
3504 if Proj = No_Project then
3505 Make_Failed
3506 ("""" & Main &
3507 """ is not a source of any project");
3509 else
3510 -- If there is directory information, check that
3511 -- the source exists and, if it does, that the path
3512 -- is the actual path of a source of a project.
3514 if Main /= File_Name then
3515 declare
3516 Data : constant Project_Data :=
3517 Projects.Table (Main_Project);
3519 Project_Path : constant String :=
3520 Prj.Env.File_Name_Of_Library_Unit_Body
3521 (Name => File_Name,
3522 Project => Main_Project,
3523 Main_Project_Only => False,
3524 Full_Path => True);
3525 Real_Path : String_Access :=
3526 Locate_Regular_File
3527 (Main &
3528 Get_Name_String
3529 (Data.Naming.Current_Body_Suffix),
3530 "");
3531 begin
3532 if Real_Path = null then
3533 Real_Path :=
3534 Locate_Regular_File
3535 (Main &
3536 Get_Name_String
3537 (Data.Naming.Current_Spec_Suffix),
3538 "");
3539 end if;
3541 if Real_Path = null then
3542 Real_Path :=
3543 Locate_Regular_File (Main, "");
3544 end if;
3546 -- Fail if the file cannot be found
3548 if Real_Path = null then
3549 Make_Failed
3550 ("file """ & Main & """ does not exist");
3551 end if;
3553 declare
3554 Normed_Path : constant String :=
3555 Normalize_Pathname
3556 (Real_Path.all,
3557 Case_Sensitive => False);
3558 Proj_Path : constant String :=
3559 Normalize_Pathname
3560 (Project_Path,
3561 Case_Sensitive => False);
3563 begin
3564 Free (Real_Path);
3566 -- Fail if it is not the correct path
3568 if Normed_Path /= Proj_Path then
3569 if Verbose_Mode then
3570 Write_Str (Normed_Path);
3571 Write_Str (" /= ");
3572 Write_Line (Proj_Path);
3573 end if;
3575 Make_Failed
3576 ("""" & Main &
3577 """ is not a source of any project");
3578 end if;
3579 end;
3580 end;
3581 end if;
3583 if not Unique_Compile then
3585 -- Record the project, if it is the first main
3587 if Real_Main_Project = No_Project then
3588 Real_Main_Project := Proj;
3590 elsif Proj /= Real_Main_Project then
3592 -- Fail, as the current main is not a source
3593 -- of the same project as the first main.
3595 Make_Failed
3596 ("""" & Main &
3597 """ is not a source of project " &
3598 Get_Name_String
3599 (Projects.Table
3600 (Real_Main_Project).Name));
3601 end if;
3602 end if;
3603 end if;
3605 -- If -u and -U are not used, we may have mains that
3606 -- are sources of a project that is not the one
3607 -- specified with switch -P.
3609 if not Unique_Compile then
3610 Main_Project := Real_Main_Project;
3611 end if;
3612 end;
3613 end loop;
3614 end;
3615 end if;
3617 -- If no mains have been specified on the command line,
3618 -- and we are using a project file, we either find the main(s)
3619 -- in the attribute Main of the main project, or we put all
3620 -- the sources of the project file as mains.
3622 else
3623 if Main_Index /= 0 then
3624 Make_Failed ("cannot specify a multi-unit index but no main " &
3625 "on the command line");
3626 end if;
3628 declare
3629 Value : String_List_Id := Projects.Table (Main_Project).Mains;
3631 begin
3632 -- The attribute Main is an empty list or not specified,
3633 -- or else gnatmake was invoked with the switch "-u".
3635 if Value = Prj.Nil_String or else Unique_Compile then
3637 if (not Make_Steps) or else Compile_Only
3638 or else not Projects.Table (Main_Project).Library
3639 then
3640 -- First make sure that the binder and the linker
3641 -- will not be invoked.
3643 Do_Bind_Step := False;
3644 Do_Link_Step := False;
3646 -- Put all the sources in the queue
3648 Insert_Project_Sources
3649 (The_Project => Main_Project,
3650 All_Projects => Unique_Compile_All_Projects,
3651 Into_Q => False);
3653 -- If there are no sources to compile, we fail
3655 if Osint.Number_Of_Files = 0 then
3656 Make_Failed ("no sources to compile");
3657 end if;
3658 end if;
3660 else
3661 -- The attribute Main is not an empty list.
3662 -- Put all the main subprograms in the list as if there
3663 -- were specified on the command line. However, if attribute
3664 -- Languages includes a language other than Ada, only
3665 -- include the Ada mains; if there is no Ada main, compile
3666 -- all the sources of the project.
3668 declare
3669 Data : constant Project_Data :=
3670 Projects.Table (Main_Project);
3672 Languages : constant Variable_Value :=
3673 Prj.Util.Value_Of
3674 (Name_Languages, Data.Decl.Attributes);
3676 Current : String_List_Id;
3677 Element : String_Element;
3679 Foreign_Language : Boolean := False;
3680 At_Least_One_Main : Boolean := False;
3682 begin
3683 -- First, determine if there is a foreign language in
3684 -- attribute Languages.
3686 if not Languages.Default then
3687 Current := Languages.Values;
3689 Look_For_Foreign :
3690 while Current /= Nil_String loop
3691 Element := String_Elements.Table (Current);
3692 Get_Name_String (Element.Value);
3693 To_Lower (Name_Buffer (1 .. Name_Len));
3695 if Name_Buffer (1 .. Name_Len) /= "ada" then
3696 Foreign_Language := True;
3697 exit Look_For_Foreign;
3698 end if;
3700 Current := Element.Next;
3701 end loop Look_For_Foreign;
3702 end if;
3704 -- Then, find all mains, or if there is a foreign
3705 -- language, all the Ada mains.
3707 while Value /= Prj.Nil_String loop
3708 Get_Name_String (String_Elements.Table (Value).Value);
3710 -- To know if a main is an Ada main, get its project.
3711 -- It should be the project specified on the command
3712 -- line.
3714 if (not Foreign_Language) or else
3715 Prj.Env.Project_Of
3716 (Name_Buffer (1 .. Name_Len), Main_Project) =
3717 Main_Project
3718 then
3719 At_Least_One_Main := True;
3720 Osint.Add_File
3721 (Get_Name_String
3722 (String_Elements.Table (Value).Value),
3723 Index => String_Elements.Table (Value).Index);
3724 end if;
3726 Value := String_Elements.Table (Value).Next;
3727 end loop;
3729 -- If we did not get any main, it means that all mains
3730 -- in attribute Mains are in a foreign language and -B
3731 -- was not specified to gnatmake; so, we fail.
3733 if not At_Least_One_Main then
3734 Make_Failed
3735 ("no Ada mains; use -B to build foreign main");
3736 end if;
3737 end;
3739 end if;
3740 end;
3741 end if;
3742 end if;
3744 if Verbose_Mode then
3745 Write_Eol;
3746 Write_Str ("GNATMAKE ");
3747 Write_Str (Gnatvsn.Gnat_Version_String);
3748 Write_Str (" Copyright 1995-2004 Free Software Foundation, Inc.");
3749 Write_Eol;
3750 end if;
3752 if Osint.Number_Of_Files = 0 then
3753 if Main_Project /= No_Project
3754 and then Projects.Table (Main_Project).Library
3755 then
3756 if Do_Bind_Step
3757 and then not Projects.Table (Main_Project).Standalone_Library
3758 then
3759 Make_Failed ("only stand-alone libraries may be bound");
3760 end if;
3762 -- Add the default search directories to be able to find libgnat
3764 Osint.Add_Default_Search_Dirs;
3766 -- And bind and or link the library
3768 MLib.Prj.Build_Library
3769 (For_Project => Main_Project,
3770 Gnatbind => Gnatbind.all,
3771 Gnatbind_Path => Gnatbind_Path,
3772 Gcc => Gcc.all,
3773 Gcc_Path => Gcc_Path,
3774 Bind => Bind_Only,
3775 Link => Link_Only);
3776 Exit_Program (E_Success);
3778 else
3779 -- Output usage information if no files to compile
3781 Usage;
3782 Exit_Program (E_Fatal);
3783 end if;
3784 end if;
3786 -- If -M was specified, behave as if -n was specified
3788 if List_Dependencies then
3789 Do_Not_Execute := True;
3790 end if;
3792 -- Note that Osint.Next_Main_Source will always return the (possibly
3793 -- abbreviated file) without any directory information.
3795 Main_Source_File := Next_Main_Source;
3797 if Current_File_Index /= No_Index then
3798 Main_Index := Current_File_Index;
3799 end if;
3801 Add_Switch ("-I-", Binder, And_Save => True);
3802 Add_Switch ("-I-", Compiler, And_Save => True);
3804 if Main_Project = No_Project then
3805 if Look_In_Primary_Dir then
3807 Add_Switch
3808 ("-I" &
3809 Normalize_Directory_Name
3810 (Get_Primary_Src_Search_Directory.all).all,
3811 Compiler, Append_Switch => False,
3812 And_Save => False);
3814 Add_Switch ("-aO" & Normalized_CWD,
3815 Binder,
3816 Append_Switch => False,
3817 And_Save => False);
3818 end if;
3820 else
3821 -- If we use a project file, we have already checked that a main
3822 -- specified on the command line with directory information has the
3823 -- path name corresponding to a correct source in the project tree.
3824 -- So, we don't need the directory information to be taken into
3825 -- account by Find_File, and in fact it may lead to take the wrong
3826 -- sources for other compilation units, when there are extending
3827 -- projects.
3829 Look_In_Primary_Dir := False;
3830 end if;
3832 -- If the user wants a program without a main subprogram, add the
3833 -- appropriate switch to the binder.
3835 if No_Main_Subprogram then
3836 Add_Switch ("-z", Binder, And_Save => True);
3837 end if;
3839 if Main_Project /= No_Project then
3841 if Projects.Table (Main_Project).Object_Directory = No_Name then
3842 Make_Failed ("no sources to compile");
3843 end if;
3845 -- Change the current directory to the object directory of the main
3846 -- project.
3848 begin
3849 Project_Object_Directory := No_Project;
3850 Change_To_Object_Directory (Main_Project);
3852 exception
3853 when Directory_Error =>
3855 -- This should never happen. But, if it does, display the
3856 -- content of the parent directory of the obj dir.
3858 declare
3859 Parent : constant Dir_Name_Str :=
3860 Dir_Name
3861 (Get_Name_String
3862 (Projects.Table (Main_Project).Object_Directory));
3863 Dir : Dir_Type;
3864 Str : String (1 .. 200);
3865 Last : Natural;
3867 begin
3868 Write_Str ("Contents of directory """);
3869 Write_Str (Parent);
3870 Write_Line (""":");
3872 Open (Dir, Parent);
3874 loop
3875 Read (Dir, Str, Last);
3876 exit when Last = 0;
3877 Write_Str (" ");
3878 Write_Line (Str (1 .. Last));
3879 end loop;
3881 Close (Dir);
3883 exception
3884 when X : others =>
3885 Write_Line ("(unexpected exception)");
3886 Write_Line (Exception_Information (X));
3888 if Is_Open (Dir) then
3889 Close (Dir);
3890 end if;
3891 end;
3893 Make_Failed ("unable to change working directory to """,
3894 Get_Name_String
3895 (Projects.Table (Main_Project).Object_Directory),
3896 """");
3897 end;
3899 -- Source file lookups should be cached for efficiency.
3900 -- Source files are not supposed to change.
3902 Osint.Source_File_Data (Cache => True);
3904 -- Find the file name of the (first) main unit
3906 declare
3907 Main_Source_File_Name : constant String :=
3908 Get_Name_String (Main_Source_File);
3909 Main_Unit_File_Name : constant String :=
3910 Prj.Env.File_Name_Of_Library_Unit_Body
3911 (Name => Main_Source_File_Name,
3912 Project => Main_Project,
3913 Main_Project_Only =>
3914 not Unique_Compile);
3916 The_Packages : constant Package_Id :=
3917 Projects.Table (Main_Project).Decl.Packages;
3919 Builder_Package : constant Prj.Package_Id :=
3920 Prj.Util.Value_Of
3921 (Name => Name_Builder,
3922 In_Packages => The_Packages);
3924 Binder_Package : constant Prj.Package_Id :=
3925 Prj.Util.Value_Of
3926 (Name => Name_Binder,
3927 In_Packages => The_Packages);
3929 Linker_Package : constant Prj.Package_Id :=
3930 Prj.Util.Value_Of
3931 (Name => Name_Linker,
3932 In_Packages => The_Packages);
3934 begin
3935 -- We fail if we cannot find the main source file
3937 if Main_Unit_File_Name = "" then
3938 Make_Failed ('"' & Main_Source_File_Name,
3939 """ is not a unit of project ",
3940 Project_File_Name.all & ".");
3941 else
3942 -- Remove any directory information from the main
3943 -- source file name.
3945 declare
3946 Pos : Natural := Main_Unit_File_Name'Last;
3948 begin
3949 loop
3950 exit when Pos < Main_Unit_File_Name'First or else
3951 Main_Unit_File_Name (Pos) = Directory_Separator;
3952 Pos := Pos - 1;
3953 end loop;
3955 Name_Len := Main_Unit_File_Name'Last - Pos;
3957 Name_Buffer (1 .. Name_Len) :=
3958 Main_Unit_File_Name
3959 (Pos + 1 .. Main_Unit_File_Name'Last);
3961 Main_Source_File := Name_Find;
3963 -- We only output the main source file if there is only one
3965 if Verbose_Mode and then Osint.Number_Of_Files = 1 then
3966 Write_Str ("Main source file: """);
3967 Write_Str (Main_Unit_File_Name
3968 (Pos + 1 .. Main_Unit_File_Name'Last));
3969 Write_Line (""".");
3970 end if;
3971 end;
3972 end if;
3974 -- If there is a package Builder in the main project file, add
3975 -- the switches from it.
3977 if Builder_Package /= No_Package then
3979 -- If there is only one main, we attempt to get the gnatmake
3980 -- switches for this main (if any). If there are no specific
3981 -- switch for this particular main, get the general gnatmake
3982 -- switches (if any).
3984 if Osint.Number_Of_Files = 1 then
3985 if Verbose_Mode then
3986 Write_Str ("Adding gnatmake switches for """);
3987 Write_Str (Main_Unit_File_Name);
3988 Write_Line (""".");
3989 end if;
3991 Add_Switches
3992 (File_Name => Main_Unit_File_Name,
3993 Index => Main_Index,
3994 The_Package => Builder_Package,
3995 Program => None);
3997 else
3998 -- If there are several mains, we always get the general
3999 -- gnatmake switches (if any).
4001 -- Warn the user, if necessary, so that he is not surprized
4002 -- that specific switches are not taken into account.
4004 declare
4005 Defaults : constant Variable_Value :=
4006 Prj.Util.Value_Of
4007 (Name => Name_Ada,
4008 Index => 0,
4009 Attribute_Or_Array_Name => Name_Default_Switches,
4010 In_Package => Builder_Package);
4012 Switches : constant Array_Element_Id :=
4013 Prj.Util.Value_Of
4014 (Name => Name_Switches,
4015 In_Arrays =>
4016 Packages.Table (Builder_Package).Decl.Arrays);
4018 begin
4019 if Defaults /= Nil_Variable_Value then
4020 if (not Quiet_Output)
4021 and then Switches /= No_Array_Element
4022 then
4023 Write_Line
4024 ("Warning: using Builder'Default_Switches" &
4025 "(""Ada""), as there are several mains");
4026 end if;
4028 -- As there is never a source with name " ", we are
4029 -- guaranteed to always get the general switches.
4031 Add_Switches
4032 (File_Name => " ",
4033 Index => 0,
4034 The_Package => Builder_Package,
4035 Program => None);
4037 elsif (not Quiet_Output)
4038 and then Switches /= No_Array_Element
4039 then
4040 Write_Line
4041 ("Warning: using no switches from package Builder," &
4042 " as there are several mains");
4043 end if;
4044 end;
4045 end if;
4046 end if;
4048 Osint.Add_Default_Search_Dirs;
4050 -- Record the current last switch index for table Binder_Switches
4051 -- and Linker_Switches, so that these tables may be reset before
4052 -- for each main, before adding swiches from the project file
4053 -- and from the command line.
4055 Last_Binder_Switch := Binder_Switches.Last;
4056 Last_Linker_Switch := Linker_Switches.Last;
4058 Check_Steps;
4060 -- Add binder switches from the project file for the first main
4062 if Do_Bind_Step and Binder_Package /= No_Package then
4063 if Verbose_Mode then
4064 Write_Str ("Adding binder switches for """);
4065 Write_Str (Main_Unit_File_Name);
4066 Write_Line (""".");
4067 end if;
4069 Add_Switches
4070 (File_Name => Main_Unit_File_Name,
4071 Index => Main_Index,
4072 The_Package => Binder_Package,
4073 Program => Binder);
4074 end if;
4076 -- Add linker switches from the project file for the first main
4078 if Do_Link_Step and Linker_Package /= No_Package then
4079 if Verbose_Mode then
4080 Write_Str ("Adding linker switches for""");
4081 Write_Str (Main_Unit_File_Name);
4082 Write_Line (""".");
4083 end if;
4085 Add_Switches
4086 (File_Name => Main_Unit_File_Name,
4087 Index => Main_Index,
4088 The_Package => Linker_Package,
4089 Program => Linker);
4090 end if;
4091 end;
4092 end if;
4094 -- Get the target parameters, which are only needed for a couple of
4095 -- cases in gnatmake. Protect against an exception, such as the case
4096 -- of system.ads missing from the library, and fail gracefully.
4098 begin
4099 Targparm.Get_Target_Parameters;
4101 exception
4102 when Unrecoverable_Error =>
4103 Make_Failed ("*** make failed.");
4104 end;
4106 Display_Commands (not Quiet_Output);
4108 Check_Steps;
4110 if Main_Project /= No_Project then
4112 -- For all library project, if the library file does not exist
4113 -- put all the project sources in the queue, and flag the project
4114 -- so that the library is generated.
4116 if MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None then
4117 for Proj in Projects.First .. Projects.Last loop
4118 if Projects.Table (Proj).Library then
4119 Projects.Table (Proj).Flag1 :=
4120 not MLib.Tgt.Library_Exists_For (Proj);
4122 if Projects.Table (Proj).Flag1 then
4123 if Verbose_Mode then
4124 Write_Str
4125 ("Library file does not exist for project """);
4126 Write_Str
4127 (Get_Name_String (Projects.Table (Proj).Name));
4128 Write_Line ("""");
4129 end if;
4131 Insert_Project_Sources
4132 (The_Project => Proj,
4133 All_Projects => False,
4134 Into_Q => True);
4135 end if;
4136 end if;
4137 end loop;
4138 end if;
4140 -- If a relative path output file has been specified, we add
4141 -- the exec directory.
4143 for J in reverse 1 .. Saved_Linker_Switches.Last - 1 loop
4144 if Saved_Linker_Switches.Table (J).all = Output_Flag.all then
4145 declare
4146 Exec_File_Name : constant String :=
4147 Saved_Linker_Switches.Table (J + 1).all;
4149 begin
4150 if not Is_Absolute_Path (Exec_File_Name) then
4151 for Index in Exec_File_Name'Range loop
4152 if Exec_File_Name (Index) = Directory_Separator then
4153 Make_Failed ("relative executable (""",
4154 Exec_File_Name,
4155 """) with directory part not " &
4156 "allowed when using project files");
4157 end if;
4158 end loop;
4160 Get_Name_String (Projects.Table
4161 (Main_Project).Exec_Directory);
4163 if Name_Buffer (Name_Len) /= Directory_Separator then
4164 Name_Len := Name_Len + 1;
4165 Name_Buffer (Name_Len) := Directory_Separator;
4166 end if;
4168 Name_Buffer (Name_Len + 1 ..
4169 Name_Len + Exec_File_Name'Length) :=
4170 Exec_File_Name;
4171 Name_Len := Name_Len + Exec_File_Name'Length;
4172 Saved_Linker_Switches.Table (J + 1) :=
4173 new String'(Name_Buffer (1 .. Name_Len));
4174 end if;
4175 end;
4177 exit;
4178 end if;
4179 end loop;
4181 -- If we are using a project file, for relative paths we add the
4182 -- current working directory for any relative path on the command
4183 -- line and the project directory, for any relative path in the
4184 -- project file.
4186 declare
4187 Dir_Path : constant String_Access :=
4188 new String'(Get_Name_String
4189 (Projects.Table (Main_Project).Directory));
4190 begin
4191 for J in 1 .. Binder_Switches.Last loop
4192 Test_If_Relative_Path
4193 (Binder_Switches.Table (J),
4194 Parent => Dir_Path, Including_L_Switch => False);
4195 end loop;
4197 for J in 1 .. Saved_Binder_Switches.Last loop
4198 Test_If_Relative_Path
4199 (Saved_Binder_Switches.Table (J),
4200 Parent => Current_Work_Dir, Including_L_Switch => False);
4201 end loop;
4203 for J in 1 .. Linker_Switches.Last loop
4204 Test_If_Relative_Path
4205 (Linker_Switches.Table (J), Parent => Dir_Path);
4206 end loop;
4208 for J in 1 .. Saved_Linker_Switches.Last loop
4209 Test_If_Relative_Path
4210 (Saved_Linker_Switches.Table (J), Parent => Current_Work_Dir);
4211 end loop;
4213 for J in 1 .. Gcc_Switches.Last loop
4214 Test_If_Relative_Path
4215 (Gcc_Switches.Table (J), Parent => Dir_Path);
4216 end loop;
4218 for J in 1 .. Saved_Gcc_Switches.Last loop
4219 Test_If_Relative_Path
4220 (Saved_Gcc_Switches.Table (J), Parent => Current_Work_Dir);
4221 end loop;
4222 end;
4223 end if;
4225 -- We now put in the Binder_Switches and Linker_Switches tables,
4226 -- the binder and linker switches of the command line that have been
4227 -- put in the Saved_ tables. If a project file was used, then the
4228 -- command line switches will follow the project file switches.
4230 for J in 1 .. Saved_Binder_Switches.Last loop
4231 Add_Switch
4232 (Saved_Binder_Switches.Table (J),
4233 Binder,
4234 And_Save => False);
4235 end loop;
4237 for J in 1 .. Saved_Linker_Switches.Last loop
4238 Add_Switch
4239 (Saved_Linker_Switches.Table (J),
4240 Linker,
4241 And_Save => False);
4242 end loop;
4244 -- If no project file is used, we just put the gcc switches
4245 -- from the command line in the Gcc_Switches table.
4247 if Main_Project = No_Project then
4248 for J in 1 .. Saved_Gcc_Switches.Last loop
4249 Add_Switch
4250 (Saved_Gcc_Switches.Table (J),
4251 Compiler,
4252 And_Save => False);
4253 end loop;
4255 else
4256 -- And we put the command line gcc switches in the variable
4257 -- The_Saved_Gcc_Switches. They are going to be used later
4258 -- in procedure Compile_Sources.
4260 The_Saved_Gcc_Switches :=
4261 new Argument_List (1 .. Saved_Gcc_Switches.Last + 1);
4263 for J in 1 .. Saved_Gcc_Switches.Last loop
4264 The_Saved_Gcc_Switches (J) := Saved_Gcc_Switches.Table (J);
4265 end loop;
4267 -- We never use gnat.adc when a project file is used
4269 The_Saved_Gcc_Switches (The_Saved_Gcc_Switches'Last) :=
4270 No_gnat_adc;
4272 end if;
4274 -- If there was a --GCC, --GNATBIND or --GNATLINK switch on
4275 -- the command line, then we have to use it, even if there was
4276 -- another switch in the project file.
4278 if Saved_Gcc /= null then
4279 Gcc := Saved_Gcc;
4280 end if;
4282 if Saved_Gnatbind /= null then
4283 Gnatbind := Saved_Gnatbind;
4284 end if;
4286 if Saved_Gnatlink /= null then
4287 Gnatlink := Saved_Gnatlink;
4288 end if;
4290 Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
4291 Gnatbind_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
4292 Gnatlink_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
4294 -- If we have specified -j switch both from the project file
4295 -- and on the command line, the one from the command line takes
4296 -- precedence.
4298 if Saved_Maximum_Processes = 0 then
4299 Saved_Maximum_Processes := Maximum_Processes;
4300 end if;
4302 -- Allocate as many temporary mapping file names as the maximum
4303 -- number of compilation processed, for each possible project.
4305 The_Mapping_File_Names :=
4306 new Temp_File_Names
4307 (No_Project .. Projects.Last, 1 .. Saved_Maximum_Processes);
4308 Last_Mapping_File_Names :=
4309 new Indices'(No_Project .. Projects.Last => 0);
4311 The_Free_Mapping_File_Indices :=
4312 new Free_File_Indices
4313 (No_Project .. Projects.Last, 1 .. Saved_Maximum_Processes);
4314 Last_Free_Indices :=
4315 new Indices'(No_Project .. Projects.Last => 0);
4317 Bad_Compilation.Init;
4319 Current_Main_Index := Main_Index;
4321 -- Here is where the make process is started
4323 -- We do the same process for each main
4325 Multiple_Main_Loop : for N_File in 1 .. Osint.Number_Of_Files loop
4327 -- First, find the executable name and path
4329 Executable := No_File;
4330 Executable_Obsolete := False;
4331 Non_Std_Executable := False;
4333 -- Look inside the linker switches to see if the name
4334 -- of the final executable program was specified.
4337 J in reverse Linker_Switches.First .. Linker_Switches.Last
4338 loop
4339 if Linker_Switches.Table (J).all = Output_Flag.all then
4340 pragma Assert (J < Linker_Switches.Last);
4342 -- We cannot specify a single executable for several
4343 -- main subprograms!
4345 if Osint.Number_Of_Files > 1 then
4346 Fail
4347 ("cannot specify a single executable " &
4348 "for several mains");
4349 end if;
4351 Name_Len := Linker_Switches.Table (J + 1)'Length;
4352 Name_Buffer (1 .. Name_Len) :=
4353 Linker_Switches.Table (J + 1).all;
4354 Executable := Name_Enter;
4356 Verbose_Msg (Executable, "final executable");
4357 end if;
4358 end loop;
4360 -- If the name of the final executable program was not
4361 -- specified then construct it from the main input file.
4363 if Executable = No_File then
4364 if Main_Project = No_Project then
4365 Executable :=
4366 Executable_Name (Strip_Suffix (Main_Source_File));
4368 else
4369 -- If we are using a project file, we attempt to
4370 -- remove the body (or spec) termination of the main
4371 -- subprogram. We find it the the naming scheme of the
4372 -- project file. This will avoid to generate an
4373 -- executable "main.2" for a main subprogram
4374 -- "main.2.ada", when the body termination is ".2.ada".
4376 Executable := Prj.Util.Executable_Of
4377 (Main_Project, Main_Source_File, Main_Index);
4378 end if;
4379 end if;
4381 if Main_Project /= No_Project then
4382 declare
4383 Exec_File_Name : constant String :=
4384 Get_Name_String (Executable);
4386 begin
4387 if not Is_Absolute_Path (Exec_File_Name) then
4388 for Index in Exec_File_Name'Range loop
4389 if Exec_File_Name (Index) = Directory_Separator then
4390 Make_Failed ("relative executable (""",
4391 Exec_File_Name,
4392 """) with directory part not " &
4393 "allowed when using project files");
4394 end if;
4395 end loop;
4397 Get_Name_String (Projects.Table
4398 (Main_Project).Exec_Directory);
4401 Name_Buffer (Name_Len) /= Directory_Separator
4402 then
4403 Name_Len := Name_Len + 1;
4404 Name_Buffer (Name_Len) := Directory_Separator;
4405 end if;
4407 Name_Buffer (Name_Len + 1 ..
4408 Name_Len + Exec_File_Name'Length) :=
4409 Exec_File_Name;
4410 Name_Len := Name_Len + Exec_File_Name'Length;
4411 Executable := Name_Find;
4412 Non_Std_Executable := True;
4413 end if;
4414 end;
4416 end if;
4418 if Do_Compile_Step then
4419 Recursive_Compilation_Step : declare
4420 Args : Argument_List (1 .. Gcc_Switches.Last);
4422 First_Compiled_File : Name_Id;
4423 Youngest_Obj_File : Name_Id;
4424 Youngest_Obj_Stamp : Time_Stamp_Type;
4426 Executable_Stamp : Time_Stamp_Type;
4427 -- Executable is the final executable program.
4429 Library_Rebuilt : Boolean := False;
4431 begin
4432 for J in 1 .. Gcc_Switches.Last loop
4433 Args (J) := Gcc_Switches.Table (J);
4434 end loop;
4436 -- Now we invoke Compile_Sources for the current main
4438 Compile_Sources
4439 (Main_Source => Main_Source_File,
4440 Args => Args,
4441 First_Compiled_File => First_Compiled_File,
4442 Most_Recent_Obj_File => Youngest_Obj_File,
4443 Most_Recent_Obj_Stamp => Youngest_Obj_Stamp,
4444 Main_Unit => Is_Main_Unit,
4445 Main_Index => Current_Main_Index,
4446 Compilation_Failures => Compilation_Failures,
4447 Check_Readonly_Files => Check_Readonly_Files,
4448 Do_Not_Execute => Do_Not_Execute,
4449 Force_Compilations => Force_Compilations,
4450 In_Place_Mode => In_Place_Mode,
4451 Keep_Going => Keep_Going,
4452 Initialize_ALI_Data => True,
4453 Max_Process => Saved_Maximum_Processes);
4455 if Verbose_Mode then
4456 Write_Str ("End of compilation");
4457 Write_Eol;
4458 end if;
4460 -- Make sure the queue will be reinitialized for the next round
4462 First_Q_Initialization := True;
4464 Total_Compilation_Failures :=
4465 Total_Compilation_Failures + Compilation_Failures;
4467 if Total_Compilation_Failures /= 0 then
4468 if Keep_Going then
4469 goto Next_Main;
4471 else
4472 List_Bad_Compilations;
4473 raise Compilation_Failed;
4474 end if;
4475 end if;
4477 -- Regenerate libraries, if any, and if object files
4478 -- have been regenerated.
4480 if Main_Project /= No_Project
4481 and then MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None
4482 and then (Do_Bind_Step or Unique_Compile_All_Projects
4483 or not Compile_Only)
4484 and then (Do_Link_Step or N_File = Osint.Number_Of_Files)
4485 then
4486 Library_Projs.Init;
4488 declare
4489 Proj2 : Project_Id;
4490 Depth : Natural;
4491 Current : Natural;
4493 begin
4494 -- Put in Library_Projs table all library project
4495 -- file ids when the library need to be rebuilt.
4497 for Proj1 in Projects.First .. Projects.Last loop
4499 if Projects.Table (Proj1).Standalone_Library then
4500 There_Are_Stand_Alone_Libraries := True;
4501 end if;
4503 if Projects.Table (Proj1).Library
4504 and then not Projects.Table (Proj1).Flag1
4505 then
4506 MLib.Prj.Check_Library (Proj1);
4507 end if;
4509 if Projects.Table (Proj1).Flag1 then
4510 Library_Projs.Increment_Last;
4511 Current := Library_Projs.Last;
4512 Depth := Projects.Table (Proj1).Depth;
4514 -- Put the projects in decreasing depth order,
4515 -- so that if libA depends on libB, libB is first
4516 -- in order.
4518 while Current > 1 loop
4519 Proj2 := Library_Projs.Table (Current - 1);
4520 exit when Projects.Table (Proj2).Depth >= Depth;
4521 Library_Projs.Table (Current) := Proj2;
4522 Current := Current - 1;
4523 end loop;
4525 Library_Projs.Table (Current) := Proj1;
4526 Projects.Table (Proj1).Flag1 := False;
4527 end if;
4528 end loop;
4529 end;
4531 -- Build the libraries, if any need to be built
4533 for J in 1 .. Library_Projs.Last loop
4534 Library_Rebuilt := True;
4535 MLib.Prj.Build_Library
4536 (For_Project => Library_Projs.Table (J),
4537 Gnatbind => Gnatbind.all,
4538 Gnatbind_Path => Gnatbind_Path,
4539 Gcc => Gcc.all,
4540 Gcc_Path => Gcc_Path);
4541 end loop;
4542 end if;
4544 if List_Dependencies then
4545 if First_Compiled_File /= No_File then
4546 Inform
4547 (First_Compiled_File,
4548 "must be recompiled. Can't generate dependence list.");
4549 else
4550 List_Depend;
4551 end if;
4553 elsif First_Compiled_File = No_File
4554 and then not Do_Bind_Step
4555 and then not Quiet_Output
4556 and then not Library_Rebuilt
4557 and then Osint.Number_Of_Files = 1
4558 then
4559 Inform (Msg => "objects up to date.");
4561 elsif Do_Not_Execute
4562 and then First_Compiled_File /= No_File
4563 then
4564 Write_Name (First_Compiled_File);
4565 Write_Eol;
4566 end if;
4568 -- Stop after compile step if any of:
4570 -- 1) -n (Do_Not_Execute) specified
4572 -- 2) -M (List_Dependencies) specified (also sets
4573 -- Do_Not_Execute above, so this is probably superfluous).
4575 -- 3) -c (Compile_Only) specified, but not -b (Bind_Only)
4577 -- 4) Made unit cannot be a main unit
4579 if (Do_Not_Execute
4580 or List_Dependencies
4581 or not Do_Bind_Step
4582 or not Is_Main_Unit)
4583 and then not No_Main_Subprogram
4584 and then not Build_Bind_And_Link_Full_Project
4585 then
4586 if Osint.Number_Of_Files = 1 then
4587 exit Multiple_Main_Loop;
4589 else
4590 goto Next_Main;
4591 end if;
4592 end if;
4594 -- If the objects were up-to-date check if the executable file
4595 -- is also up-to-date. For now always bind and link on the JVM
4596 -- since there is currently no simple way to check the
4597 -- up-to-date status of objects
4599 if not Hostparm.Java_VM
4600 and then First_Compiled_File = No_File
4601 then
4602 Executable_Stamp := File_Stamp (Executable);
4604 if not Executable_Obsolete then
4605 Executable_Obsolete :=
4606 Youngest_Obj_Stamp > Executable_Stamp;
4607 end if;
4609 if not Executable_Obsolete then
4610 for Index in reverse 1 .. Dependencies.Last loop
4611 if Is_In_Obsoleted
4612 (Dependencies.Table (Index).Depends_On)
4613 then
4614 Enter_Into_Obsoleted
4615 (Dependencies.Table (Index).This);
4616 end if;
4617 end loop;
4619 Executable_Obsolete := Is_In_Obsoleted (Main_Source_File);
4620 Dependencies.Init;
4621 end if;
4623 if not Executable_Obsolete then
4625 -- If no Ada object files obsolete the executable, check
4626 -- for younger or missing linker files.
4628 Check_Linker_Options
4629 (Executable_Stamp,
4630 Youngest_Obj_File,
4631 Youngest_Obj_Stamp);
4633 Executable_Obsolete := Youngest_Obj_File /= No_File;
4634 end if;
4636 -- Return if the executable is up to date
4637 -- and otherwise motivate the relink/rebind.
4639 if not Executable_Obsolete then
4640 if not Quiet_Output then
4641 Inform (Executable, "up to date.");
4642 end if;
4644 if Osint.Number_Of_Files = 1 then
4645 exit Multiple_Main_Loop;
4647 else
4648 goto Next_Main;
4649 end if;
4650 end if;
4652 if Executable_Stamp (1) = ' ' then
4653 Verbose_Msg (Executable, "missing.", Prefix => " ");
4655 elsif Youngest_Obj_Stamp (1) = ' ' then
4656 Verbose_Msg
4657 (Youngest_Obj_File,
4658 "missing.",
4659 Prefix => " ");
4661 elsif Youngest_Obj_Stamp > Executable_Stamp then
4662 Verbose_Msg
4663 (Youngest_Obj_File,
4664 "(" & String (Youngest_Obj_Stamp) & ") newer than",
4665 Executable,
4666 "(" & String (Executable_Stamp) & ")");
4668 else
4669 Verbose_Msg
4670 (Executable, "needs to be rebuild.",
4671 Prefix => " ");
4673 end if;
4674 end if;
4675 end Recursive_Compilation_Step;
4676 end if;
4678 -- For binding and linking, we need to be in the object directory of
4679 -- the main project.
4681 if Main_Project /= No_Project then
4682 Change_To_Object_Directory (Main_Project);
4683 end if;
4685 -- If we are here, it means that we need to rebuilt the current
4686 -- main. So we set Executable_Obsolete to True to make sure that
4687 -- the subsequent mains will be rebuilt.
4689 Main_ALI_In_Place_Mode_Step : declare
4690 ALI_File : File_Name_Type;
4691 Src_File : File_Name_Type;
4693 begin
4694 Src_File := Strip_Directory (Main_Source_File);
4695 ALI_File := Lib_File_Name (Src_File, Current_Main_Index);
4696 Main_ALI_File := Full_Lib_File_Name (ALI_File);
4698 -- When In_Place_Mode, the library file can be located in the
4699 -- Main_Source_File directory which may not be present in the
4700 -- library path. In this case, use the corresponding library file
4701 -- name.
4703 if Main_ALI_File = No_File and then In_Place_Mode then
4704 Get_Name_String (Get_Directory (Full_Source_Name (Src_File)));
4705 Get_Name_String_And_Append (ALI_File);
4706 Main_ALI_File := Name_Find;
4707 Main_ALI_File := Full_Lib_File_Name (Main_ALI_File);
4708 end if;
4710 if Main_ALI_File = No_File then
4711 Make_Failed ("could not find the main ALI file");
4712 end if;
4713 end Main_ALI_In_Place_Mode_Step;
4715 if Do_Bind_Step then
4716 Bind_Step : declare
4717 Args : Argument_List
4718 (Binder_Switches.First .. Binder_Switches.Last + 2);
4719 -- The arguments for the invocation of gnatbind
4721 Last_Arg : Natural := Binder_Switches.Last;
4722 -- Index of the last argument in Args
4724 Mapping_FD : File_Descriptor := Invalid_FD;
4725 -- A File Descriptor for an eventual mapping file
4727 Mapping_Path : Name_Id := No_Name;
4728 -- The path name of the mapping file
4730 ALI_Unit : Name_Id := No_Name;
4731 -- The unit name of an ALI file
4733 ALI_Name : Name_Id := No_Name;
4734 -- The file name of the ALI file
4736 ALI_Project : Project_Id := No_Project;
4737 -- The project of the ALI file
4739 Bytes : Integer;
4740 OK : Boolean := True;
4742 Status : Boolean;
4743 -- For call to Close
4745 begin
4746 -- If it is the first time the bind step is performed,
4747 -- check if there are shared libraries, so that gnatbind is
4748 -- called with -shared.
4750 if not Bind_Shared_Known then
4751 if Main_Project /= No_Project
4752 and then MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None
4753 then
4754 for Proj in Projects.First .. Projects.Last loop
4755 if Projects.Table (Proj).Library and then
4756 Projects.Table (Proj).Library_Kind /= Static
4757 then
4758 Bind_Shared := Shared_Switch'Access;
4760 if GCC_Version >= 3 then
4761 Link_With_Shared_Libgcc :=
4762 Shared_Libgcc_Switch'Access;
4763 end if;
4765 exit;
4766 end if;
4767 end loop;
4768 end if;
4770 Bind_Shared_Known := True;
4771 end if;
4773 -- Get all the binder switches
4775 for J in Binder_Switches.First .. Last_Arg loop
4776 Args (J) := Binder_Switches.Table (J);
4777 end loop;
4779 if There_Are_Stand_Alone_Libraries then
4780 Last_Arg := Last_Arg + 1;
4781 Args (Last_Arg) := Force_Elab_Flags_String'Access;
4782 end if;
4784 if Main_Project /= No_Project then
4786 -- Put all the source directories in ADA_INCLUDE_PATH,
4787 -- and all the object directories in ADA_OBJECTS_PATH
4789 Prj.Env.Set_Ada_Paths (Main_Project, False);
4791 -- If switch -C was specified, create a binder mapping file
4793 if Create_Mapping_File then
4794 Tempdir.Create_Temp_File (Mapping_FD, Mapping_Path);
4796 if Mapping_FD /= Invalid_FD then
4798 -- Traverse all units
4800 for J in Prj.Com.Units.First .. Prj.Com.Units.Last loop
4801 declare
4802 Unit : constant Prj.Com.Unit_Data :=
4803 Prj.Com.Units.Table (J);
4804 use Prj.Com;
4806 begin
4807 if Unit.Name /= No_Name then
4809 -- If there is a body, put it in the mapping
4811 if Unit.File_Names (Body_Part).Name /= No_Name
4812 and then Unit.File_Names (Body_Part).Project
4813 /= No_Project
4814 then
4815 Get_Name_String (Unit.Name);
4816 Name_Buffer
4817 (Name_Len + 1 .. Name_Len + 2) := "%b";
4818 Name_Len := Name_Len + 2;
4819 ALI_Unit := Name_Find;
4820 ALI_Name :=
4821 Lib_File_Name
4822 (Unit.File_Names (Body_Part).Name);
4823 ALI_Project :=
4824 Unit.File_Names (Body_Part).Project;
4826 -- Otherwise, if there is a spec, put it
4827 -- in the mapping.
4829 elsif Unit.File_Names (Specification).Name
4830 /= No_Name
4831 and then Unit.File_Names
4832 (Specification).Project
4833 /= No_Project
4834 then
4835 Get_Name_String (Unit.Name);
4836 Name_Buffer
4837 (Name_Len + 1 .. Name_Len + 2) := "%s";
4838 Name_Len := Name_Len + 2;
4839 ALI_Unit := Name_Find;
4840 ALI_Name := Lib_File_Name
4841 (Unit.File_Names (Specification).Name);
4842 ALI_Project :=
4843 Unit.File_Names (Specification).Project;
4845 else
4846 ALI_Name := No_Name;
4847 end if;
4849 -- If we have something to put in the mapping
4850 -- then we do it now. However, if the project
4851 -- is extended, we don't put anything in the
4852 -- mapping file, because we do not know where
4853 -- the ALI file is: it might be in the ext-
4854 -- ended project obj dir as well as in the
4855 -- extending project obj dir.
4857 if ALI_Name /= No_Name
4858 and then Projects.Table
4859 (ALI_Project).Extended_By
4860 = No_Project
4861 and then Projects.Table
4862 (ALI_Project).Extends
4863 = No_Project
4864 then
4865 -- First line is the unit name
4867 Get_Name_String (ALI_Unit);
4868 Name_Len := Name_Len + 1;
4869 Name_Buffer (Name_Len) := ASCII.LF;
4870 Bytes :=
4871 Write
4872 (Mapping_FD,
4873 Name_Buffer (1)'Address,
4874 Name_Len);
4875 OK := Bytes = Name_Len;
4877 if OK then
4879 -- Second line it the ALI file name
4881 Get_Name_String (ALI_Name);
4882 Name_Len := Name_Len + 1;
4883 Name_Buffer (Name_Len) := ASCII.LF;
4884 Bytes :=
4885 Write
4886 (Mapping_FD,
4887 Name_Buffer (1)'Address,
4888 Name_Len);
4889 OK := Bytes = Name_Len;
4890 end if;
4892 if OK then
4894 -- Third line it the ALI path name,
4895 -- concatenation of the project
4896 -- directory with the ALI file name.
4898 declare
4899 ALI : constant String :=
4900 Get_Name_String (ALI_Name);
4901 begin
4902 Get_Name_String
4903 (Projects.Table (ALI_Project).
4904 Object_Directory);
4906 if Name_Buffer (Name_Len) /=
4907 Directory_Separator
4908 then
4909 Name_Len := Name_Len + 1;
4910 Name_Buffer (Name_Len) :=
4911 Directory_Separator;
4912 end if;
4914 Name_Buffer
4915 (Name_Len + 1 ..
4916 Name_Len + ALI'Length) := ALI;
4917 Name_Len :=
4918 Name_Len + ALI'Length + 1;
4919 Name_Buffer (Name_Len) := ASCII.LF;
4920 Bytes :=
4921 Write
4922 (Mapping_FD,
4923 Name_Buffer (1)'Address,
4924 Name_Len);
4925 OK := Bytes = Name_Len;
4926 end;
4927 end if;
4929 -- If OK is False, it means we were unable
4930 -- to write a line. No point in continuing
4931 -- with the other units.
4933 exit when not OK;
4934 end if;
4935 end if;
4936 end;
4937 end loop;
4939 Close (Mapping_FD, Status);
4941 OK := OK and Status;
4943 -- If the creation of the mapping file was successful,
4944 -- we add the switch to the arguments of gnatbind.
4946 if OK then
4947 Last_Arg := Last_Arg + 1;
4948 Args (Last_Arg) := new String'
4949 ("-F=" & Get_Name_String (Mapping_Path));
4950 end if;
4951 end if;
4952 end if;
4954 end if;
4956 begin
4957 Bind (Main_ALI_File,
4958 Bind_Shared.all & Args (Args'First .. Last_Arg));
4960 exception
4961 when others =>
4963 -- If -dn was not specified, delete the temporary mapping
4964 -- file, if one was created.
4966 if not Debug.Debug_Flag_N
4967 and then Mapping_Path /= No_Name
4968 then
4969 Delete_File (Get_Name_String (Mapping_Path), OK);
4970 end if;
4972 -- And reraise the exception
4974 raise;
4975 end;
4977 -- If -dn was not specified, delete the temporary mapping file,
4978 -- if one was created.
4980 if not Debug.Debug_Flag_N and then Mapping_Path /= No_Name then
4981 Delete_File (Get_Name_String (Mapping_Path), OK);
4982 end if;
4983 end Bind_Step;
4984 end if;
4986 if Do_Link_Step then
4987 Link_Step : declare
4988 There_Are_Libraries : Boolean := False;
4989 Linker_Switches_Last : constant Integer := Linker_Switches.Last;
4990 Path_Option : constant String_Access :=
4991 MLib.Linker_Library_Path_Option;
4992 Current : Natural;
4993 Proj2 : Project_Id;
4994 Depth : Natural;
4996 begin
4997 if not Run_Path_Option then
4998 Linker_Switches.Increment_Last;
4999 Linker_Switches.Table (Linker_Switches.Last) :=
5000 new String'("-R");
5001 end if;
5003 if Main_Project /= No_Project then
5004 Library_Paths.Set_Last (0);
5005 Library_Projs.Init;
5007 if MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None then
5008 -- Check for library projects
5010 for Proj1 in 1 .. Projects.Last loop
5011 if Proj1 /= Main_Project
5012 and then Projects.Table (Proj1).Library
5013 then
5014 -- Add this project to table Library_Projs
5016 There_Are_Libraries := True;
5017 Depth := Projects.Table (Proj1).Depth;
5018 Library_Projs.Increment_Last;
5019 Current := Library_Projs.Last;
5021 -- Any project with a greater depth should be
5022 -- after this project in the list.
5024 while Current > 1 loop
5025 Proj2 := Library_Projs.Table (Current - 1);
5026 exit when Projects.Table (Proj2).Depth <= Depth;
5027 Library_Projs.Table (Current) := Proj2;
5028 Current := Current - 1;
5029 end loop;
5031 Library_Projs.Table (Current) := Proj1;
5033 -- If it is not a static library and path option
5034 -- is set, add it to the Library_Paths table.
5036 if Projects.Table (Proj1).Library_Kind /= Static
5037 and then Path_Option /= null
5038 then
5039 Library_Paths.Increment_Last;
5040 Library_Paths.Table (Library_Paths.Last) :=
5041 new String'
5042 (Get_Name_String
5043 (Projects.Table (Proj1).Library_Dir));
5044 end if;
5045 end if;
5046 end loop;
5048 for Index in 1 .. Library_Projs.Last loop
5049 -- Add the -L switch
5051 Linker_Switches.Increment_Last;
5052 Linker_Switches.Table (Linker_Switches.Last) :=
5053 new String'("-L" &
5054 Get_Name_String
5055 (Projects.Table
5056 (Library_Projs.Table (Index)).
5057 Library_Dir));
5059 -- Add the -l switch
5061 Linker_Switches.Increment_Last;
5062 Linker_Switches.Table (Linker_Switches.Last) :=
5063 new String'("-l" &
5064 Get_Name_String
5065 (Projects.Table
5066 (Library_Projs.Table (Index)).
5067 Library_Name));
5068 end loop;
5069 end if;
5071 if There_Are_Libraries then
5073 -- If Path_Option is not null, create the switch
5074 -- ("-Wl,-rpath," or equivalent) with all the non static
5075 -- library dirs plus the standard GNAT library dir.
5076 -- We do that only if Run_Path_Option is True
5077 -- (not disabled by -R switch).
5079 if Run_Path_Option and Path_Option /= null then
5080 declare
5081 Option : String_Access;
5082 Length : Natural := Path_Option'Length;
5083 Current : Natural;
5085 begin
5086 for Index in
5087 Library_Paths.First .. Library_Paths.Last
5088 loop
5089 -- Add the length of the library dir plus one
5090 -- for the directory separator.
5092 Length :=
5093 Length +
5094 Library_Paths.Table (Index)'Length + 1;
5095 end loop;
5097 -- Finally, add the length of the standard GNAT
5098 -- library dir.
5100 Length := Length + MLib.Utl.Lib_Directory'Length;
5101 Option := new String (1 .. Length);
5102 Option (1 .. Path_Option'Length) := Path_Option.all;
5103 Current := Path_Option'Length;
5105 -- Put each library dir followed by a dir separator
5107 for Index in
5108 Library_Paths.First .. Library_Paths.Last
5109 loop
5110 Option
5111 (Current + 1 ..
5112 Current +
5113 Library_Paths.Table (Index)'Length) :=
5114 Library_Paths.Table (Index).all;
5115 Current :=
5116 Current +
5117 Library_Paths.Table (Index)'Length + 1;
5118 Option (Current) := Path_Separator;
5119 end loop;
5121 -- Finally put the standard GNAT library dir
5123 Option
5124 (Current + 1 ..
5125 Current + MLib.Utl.Lib_Directory'Length) :=
5126 MLib.Utl.Lib_Directory;
5128 -- And add the switch to the linker switches
5130 Linker_Switches.Increment_Last;
5131 Linker_Switches.Table (Linker_Switches.Last) :=
5132 Option;
5133 end;
5134 end if;
5136 end if;
5138 -- Put the object directories in ADA_OBJECTS_PATH
5140 Prj.Env.Set_Ada_Paths (Main_Project, False);
5142 -- Check for attributes Linker'Linker_Options in projects
5143 -- other than the main project
5145 declare
5146 Linker_Options : constant String_List :=
5147 Linker_Options_Switches (Main_Project);
5149 begin
5150 for Option in Linker_Options'Range loop
5151 Linker_Switches.Increment_Last;
5152 Linker_Switches.Table (Linker_Switches.Last) :=
5153 Linker_Options (Option);
5154 end loop;
5155 end;
5156 end if;
5158 declare
5159 Args : Argument_List
5160 (Linker_Switches.First .. Linker_Switches.Last + 2);
5162 Last_Arg : Integer := Linker_Switches.First - 1;
5163 Skip : Boolean := False;
5165 begin
5166 -- Get all the linker switches
5168 for J in Linker_Switches.First .. Linker_Switches.Last loop
5169 if Skip then
5170 Skip := False;
5172 elsif Non_Std_Executable
5173 and then Linker_Switches.Table (J).all = "-o"
5174 then
5175 Skip := True;
5177 else
5178 Last_Arg := Last_Arg + 1;
5179 Args (Last_Arg) := Linker_Switches.Table (J);
5180 end if;
5181 end loop;
5183 -- If need be, add the -o switch
5185 if Non_Std_Executable then
5186 Last_Arg := Last_Arg + 1;
5187 Args (Last_Arg) := new String'("-o");
5188 Last_Arg := Last_Arg + 1;
5189 Args (Last_Arg) :=
5190 new String'(Get_Name_String (Executable));
5191 end if;
5193 -- And invoke the linker
5195 begin
5196 Link (Main_ALI_File,
5197 Link_With_Shared_Libgcc.all &
5198 Args (Args'First .. Last_Arg));
5199 Successful_Links.Increment_Last;
5200 Successful_Links.Table (Successful_Links.Last) :=
5201 Main_ALI_File;
5203 exception
5204 when Link_Failed =>
5205 if Osint.Number_Of_Files = 1 or not Keep_Going then
5206 raise;
5208 else
5209 Write_Line ("*** link failed");
5210 Failed_Links.Increment_Last;
5211 Failed_Links.Table (Failed_Links.Last) :=
5212 Main_ALI_File;
5213 end if;
5214 end;
5215 end;
5217 Linker_Switches.Set_Last (Linker_Switches_Last);
5218 end Link_Step;
5219 end if;
5221 -- We go to here when we skip the bind and link steps.
5223 <<Next_Main>>
5225 -- We go to the next main, if we did not process the last one
5227 if N_File < Osint.Number_Of_Files then
5228 Main_Source_File := Next_Main_Source;
5230 if Current_File_Index /= No_Index then
5231 Main_Index := Current_File_Index;
5232 end if;
5234 if Main_Project /= No_Project then
5236 -- Find the file name of the main unit
5238 declare
5239 Main_Source_File_Name : constant String :=
5240 Get_Name_String (Main_Source_File);
5242 Main_Unit_File_Name : constant String :=
5243 Prj.Env.
5244 File_Name_Of_Library_Unit_Body
5245 (Name => Main_Source_File_Name,
5246 Project => Main_Project,
5247 Main_Project_Only =>
5248 not Unique_Compile);
5250 The_Packages : constant Package_Id :=
5251 Projects.Table (Main_Project).Decl.Packages;
5253 Binder_Package : constant Prj.Package_Id :=
5254 Prj.Util.Value_Of
5255 (Name => Name_Binder,
5256 In_Packages => The_Packages);
5258 Linker_Package : constant Prj.Package_Id :=
5259 Prj.Util.Value_Of
5260 (Name => Name_Linker,
5261 In_Packages => The_Packages);
5263 begin
5264 -- We fail if we cannot find the main source file
5265 -- as an immediate source of the main project file.
5267 if Main_Unit_File_Name = "" then
5268 Make_Failed ('"' & Main_Source_File_Name,
5269 """ is not a unit of project ",
5270 Project_File_Name.all & ".");
5272 else
5273 -- Remove any directory information from the main
5274 -- source file name.
5276 declare
5277 Pos : Natural := Main_Unit_File_Name'Last;
5279 begin
5280 loop
5281 exit when Pos < Main_Unit_File_Name'First
5282 or else
5283 Main_Unit_File_Name (Pos) = Directory_Separator;
5284 Pos := Pos - 1;
5285 end loop;
5287 Name_Len := Main_Unit_File_Name'Last - Pos;
5289 Name_Buffer (1 .. Name_Len) :=
5290 Main_Unit_File_Name
5291 (Pos + 1 .. Main_Unit_File_Name'Last);
5293 Main_Source_File := Name_Find;
5294 end;
5295 end if;
5297 -- We now deal with the binder and linker switches.
5298 -- If no project file is used, there is nothing to do
5299 -- because the binder and linker switches are the same
5300 -- for all mains.
5302 -- Reset the tables Binder_Switches and Linker_Switches
5304 Binder_Switches.Set_Last (Last_Binder_Switch);
5305 Linker_Switches.Set_Last (Last_Linker_Switch);
5307 -- Add binder switches from the project file for this main,
5308 -- if any.
5310 if Do_Bind_Step and Binder_Package /= No_Package then
5311 if Verbose_Mode then
5312 Write_Str ("Adding binder switches for """);
5313 Write_Str (Main_Unit_File_Name);
5314 Write_Line (""".");
5315 end if;
5317 Add_Switches
5318 (File_Name => Main_Unit_File_Name,
5319 Index => Main_Index,
5320 The_Package => Binder_Package,
5321 Program => Binder);
5322 end if;
5324 -- Add linker switches from the project file for this main,
5325 -- if any.
5327 if Do_Link_Step and Linker_Package /= No_Package then
5328 if Verbose_Mode then
5329 Write_Str ("Adding linker switches for""");
5330 Write_Str (Main_Unit_File_Name);
5331 Write_Line (""".");
5332 end if;
5334 Add_Switches
5335 (File_Name => Main_Unit_File_Name,
5336 Index => Main_Index,
5337 The_Package => Linker_Package,
5338 Program => Linker);
5339 end if;
5341 -- As we are using a project file, for relative paths we add
5342 -- the current working directory for any relative path on
5343 -- the command line and the project directory, for any
5344 -- relative path in the project file.
5346 declare
5347 Dir_Path : constant String_Access :=
5348 new String'(Get_Name_String
5349 (Projects.Table (Main_Project).Directory));
5350 begin
5352 J in Last_Binder_Switch + 1 .. Binder_Switches.Last
5353 loop
5354 Test_If_Relative_Path
5355 (Binder_Switches.Table (J),
5356 Parent => Dir_Path, Including_L_Switch => False);
5357 end loop;
5360 J in Last_Linker_Switch + 1 .. Linker_Switches.Last
5361 loop
5362 Test_If_Relative_Path
5363 (Linker_Switches.Table (J), Parent => Dir_Path);
5364 end loop;
5365 end;
5367 -- We now put in the Binder_Switches and Linker_Switches
5368 -- tables, the binder and linker switches of the command
5369 -- line that have been put in the Saved_ tables.
5370 -- These switches will follow the project file switches.
5372 for J in 1 .. Saved_Binder_Switches.Last loop
5373 Add_Switch
5374 (Saved_Binder_Switches.Table (J),
5375 Binder,
5376 And_Save => False);
5377 end loop;
5379 for J in 1 .. Saved_Linker_Switches.Last loop
5380 Add_Switch
5381 (Saved_Linker_Switches.Table (J),
5382 Linker,
5383 And_Save => False);
5384 end loop;
5385 end;
5386 end if;
5387 end if;
5389 -- Remove all marks to be sure to check sources for all executables,
5390 -- as the switches may be different and -s may be in use.
5392 Delete_All_Marks;
5393 end loop Multiple_Main_Loop;
5395 if Failed_Links.Last > 0 then
5396 for Index in 1 .. Successful_Links.Last loop
5397 Write_Str ("Linking of """);
5398 Write_Str (Get_Name_String (Successful_Links.Table (Index)));
5399 Write_Line (""" succeeded.");
5400 end loop;
5402 for Index in 1 .. Failed_Links.Last loop
5403 Write_Str ("Linking of """);
5404 Write_Str (Get_Name_String (Failed_Links.Table (Index)));
5405 Write_Line (""" failed.");
5406 end loop;
5408 if Total_Compilation_Failures = 0 then
5409 raise Compilation_Failed;
5410 end if;
5411 end if;
5413 if Total_Compilation_Failures /= 0 then
5414 List_Bad_Compilations;
5415 raise Compilation_Failed;
5416 end if;
5418 -- Delete the temporary mapping file that was created if we are
5419 -- using project files.
5421 if not Debug.Debug_Flag_N then
5422 Delete_Mapping_Files;
5423 Prj.Env.Delete_All_Path_Files;
5424 end if;
5426 Exit_Program (E_Success);
5428 exception
5429 when Bind_Failed =>
5430 Make_Failed ("*** bind failed.");
5432 when Compilation_Failed =>
5433 if not Debug.Debug_Flag_N then
5434 Delete_Mapping_Files;
5435 Prj.Env.Delete_All_Path_Files;
5436 end if;
5438 Exit_Program (E_Fatal);
5440 when Link_Failed =>
5441 Make_Failed ("*** link failed.");
5443 when X : others =>
5444 Write_Line (Exception_Information (X));
5445 Make_Failed ("INTERNAL ERROR. Please report.");
5447 end Gnatmake;
5449 ----------
5450 -- Hash --
5451 ----------
5453 function Hash (F : Name_Id) return Header_Num is
5454 begin
5455 return Header_Num (1 + F mod Max_Header);
5456 end Hash;
5458 --------------------
5459 -- In_Ada_Lib_Dir --
5460 --------------------
5462 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean is
5463 D : constant Name_Id := Get_Directory (File);
5464 B : constant Byte := Get_Name_Table_Byte (D);
5466 begin
5467 return (B and Ada_Lib_Dir) /= 0;
5468 end In_Ada_Lib_Dir;
5470 ------------
5471 -- Inform --
5472 ------------
5474 procedure Inform (N : Name_Id := No_Name; Msg : String) is
5475 begin
5476 Osint.Write_Program_Name;
5478 Write_Str (": ");
5480 if N /= No_Name then
5481 Write_Str ("""");
5482 Write_Name (N);
5483 Write_Str (""" ");
5484 end if;
5486 Write_Str (Msg);
5487 Write_Eol;
5488 end Inform;
5490 -----------------------
5491 -- Init_Mapping_File --
5492 -----------------------
5494 procedure Init_Mapping_File
5495 (Project : Project_Id;
5496 File_Index : in out Natural)
5498 FD : File_Descriptor;
5500 Status : Boolean;
5501 -- For call to Close
5503 begin
5504 -- Increase the index of the last mapping file for this project
5506 Last_Mapping_File_Names (Project) :=
5507 Last_Mapping_File_Names (Project) + 1;
5509 -- If there is a project file, call Create_Mapping_File with
5510 -- the project id.
5512 if Project /= No_Project then
5513 Prj.Env.Create_Mapping_File
5514 (Project,
5515 The_Mapping_File_Names
5516 (Project, Last_Mapping_File_Names (Project)));
5518 -- Otherwise, just create an empty file
5520 else
5521 Tempdir.Create_Temp_File
5522 (FD,
5523 The_Mapping_File_Names
5524 (No_Project, Last_Mapping_File_Names (No_Project)));
5525 if FD = Invalid_FD then
5526 Make_Failed ("disk full");
5527 end if;
5529 Close (FD, Status);
5531 if not Status then
5532 Make_Failed ("disk full");
5533 end if;
5534 end if;
5536 -- And return the index of the newly created file
5538 File_Index := Last_Mapping_File_Names (Project);
5539 end Init_Mapping_File;
5541 ------------
5542 -- Init_Q --
5543 ------------
5545 procedure Init_Q is
5546 begin
5547 First_Q_Initialization := False;
5548 Q_Front := Q.First;
5549 Q.Set_Last (Q.First);
5550 end Init_Q;
5552 ----------------
5553 -- Initialize --
5554 ----------------
5556 procedure Initialize is
5557 Next_Arg : Positive;
5559 begin
5560 -- Override default initialization of Check_Object_Consistency
5561 -- since this is normally False for GNATBIND, but is True for
5562 -- GNATMAKE since we do not need to check source consistency
5563 -- again once GNATMAKE has looked at the sources to check.
5565 Check_Object_Consistency := True;
5567 -- Package initializations. The order of calls is important here.
5569 Output.Set_Standard_Error;
5571 Gcc_Switches.Init;
5572 Binder_Switches.Init;
5573 Linker_Switches.Init;
5575 Csets.Initialize;
5576 Namet.Initialize;
5578 Snames.Initialize;
5580 Prj.Initialize;
5582 Dependencies.Init;
5584 RTS_Specified := null;
5586 Mains.Delete;
5588 Next_Arg := 1;
5589 Scan_Args : while Next_Arg <= Argument_Count loop
5590 Scan_Make_Arg (Argument (Next_Arg), And_Save => True);
5591 Next_Arg := Next_Arg + 1;
5592 end loop Scan_Args;
5594 if Usage_Requested then
5595 Usage;
5596 end if;
5598 -- Test for trailing -P switch
5600 if Project_File_Name_Present and then Project_File_Name = null then
5601 Make_Failed ("project file name missing after -P");
5603 -- Test for trailing -o switch
5605 elsif Output_File_Name_Present
5606 and then not Output_File_Name_Seen
5607 then
5608 Make_Failed ("output file name missing after -o");
5610 -- Test for trailing -D switch
5612 elsif Object_Directory_Present
5613 and then not Object_Directory_Seen then
5614 Make_Failed ("object directory missing after -D");
5615 end if;
5617 -- Test for simultaneity of -i and -D
5619 if Object_Directory_Path /= null and then In_Place_Mode then
5620 Make_Failed ("-i and -D cannot be used simutaneously");
5621 end if;
5623 -- Deal with -C= switch
5625 if Gnatmake_Mapping_File /= null then
5626 -- First, check compatibility with other switches
5628 if Project_File_Name /= null then
5629 Make_Failed ("-C= switch is not compatible with -P switch");
5631 elsif Saved_Maximum_Processes > 1 then
5632 Make_Failed ("-C= switch is not compatible with -jnnn switch");
5633 end if;
5635 Fmap.Initialize (Gnatmake_Mapping_File.all);
5636 Add_Switch
5637 ("-gnatem=" & Gnatmake_Mapping_File.all,
5638 Compiler,
5639 And_Save => True);
5640 end if;
5642 if Project_File_Name /= null then
5644 -- A project file was specified by a -P switch
5646 if Verbose_Mode then
5647 Write_Eol;
5648 Write_Str ("Parsing Project File """);
5649 Write_Str (Project_File_Name.all);
5650 Write_Str (""".");
5651 Write_Eol;
5652 end if;
5654 -- Avoid looking in the current directory for ALI files
5656 -- Look_In_Primary_Dir := False;
5658 -- Set the project parsing verbosity to whatever was specified
5659 -- by a possible -vP switch.
5661 Prj.Pars.Set_Verbosity (To => Current_Verbosity);
5663 -- Parse the project file.
5664 -- If there is an error, Main_Project will still be No_Project.
5666 Prj.Pars.Parse
5667 (Project => Main_Project,
5668 Project_File_Name => Project_File_Name.all,
5669 Packages_To_Check => Packages_To_Check_By_Gnatmake);
5671 if Main_Project = No_Project then
5672 Make_Failed ("""", Project_File_Name.all, """ processing failed");
5673 end if;
5675 if Verbose_Mode then
5676 Write_Eol;
5677 Write_Str ("Parsing of Project File """);
5678 Write_Str (Project_File_Name.all);
5679 Write_Str (""" is finished.");
5680 Write_Eol;
5681 end if;
5683 -- We add the source directories and the object directories
5684 -- to the search paths.
5686 Add_Source_Directories (Main_Project);
5687 Add_Object_Directories (Main_Project);
5689 -- Compute depth of each project
5691 Recursive_Compute_Depth
5692 (Main_Project, Visited => No_Projects, Depth => 0);
5694 else
5696 Osint.Add_Default_Search_Dirs;
5698 -- Source file lookups should be cached for efficiency.
5699 -- Source files are not supposed to change. However, we do that now
5700 -- only if no project file is used; if a project file is used, we
5701 -- do it just after changing the directory to the object directory.
5703 Osint.Source_File_Data (Cache => True);
5705 -- Read gnat.adc file to initialize Fname.UF
5707 Fname.UF.Initialize;
5709 begin
5710 Fname.SF.Read_Source_File_Name_Pragmas;
5712 exception
5713 when Err : SFN_Scan.Syntax_Error_In_GNAT_ADC =>
5714 Make_Failed (Exception_Message (Err));
5715 end;
5716 end if;
5718 -- Make sure no project object directory is recorded
5720 Project_Object_Directory := No_Project;
5722 end Initialize;
5724 ----------------------------
5725 -- Insert_Project_Sources --
5726 ----------------------------
5728 procedure Insert_Project_Sources
5729 (The_Project : Project_Id;
5730 All_Projects : Boolean;
5731 Into_Q : Boolean)
5733 Put_In_Q : Boolean := Into_Q;
5734 Unit : Com.Unit_Data;
5735 Sfile : Name_Id;
5737 Extending : constant Boolean :=
5738 Projects.Table (The_Project).Extends /= No_Project;
5740 function Check_Project (P : Project_Id) return Boolean;
5741 -- Returns True if P is The_Project or a project extended by
5742 -- The_Project.
5744 -------------------
5745 -- Check_Project --
5746 -------------------
5748 function Check_Project (P : Project_Id) return Boolean is
5749 begin
5750 if All_Projects or P = The_Project then
5751 return True;
5752 elsif Extending then
5753 declare
5754 Data : Project_Data := Projects.Table (The_Project);
5756 begin
5757 loop
5758 if P = Data.Extends then
5759 return True;
5760 end if;
5762 Data := Projects.Table (Data.Extends);
5763 exit when Data.Extends = No_Project;
5764 end loop;
5765 end;
5766 end if;
5768 return False;
5769 end Check_Project;
5771 -- Start of processing of Insert_Project_Sources
5773 begin
5774 -- For all the sources in the project files,
5776 for Id in Com.Units.First .. Com.Units.Last loop
5777 Unit := Com.Units.Table (Id);
5778 Sfile := No_Name;
5780 -- If there is a source for the body, and the body has not been
5781 -- locally removed,
5783 if Unit.File_Names (Com.Body_Part).Name /= No_Name
5784 and then Unit.File_Names (Com.Body_Part).Path /= Slash
5785 then
5787 -- And it is a source for the specified project
5789 if Check_Project (Unit.File_Names (Com.Body_Part).Project) then
5791 -- If we don't have a spec, we cannot consider the source
5792 -- if it is a subunit
5794 if Unit.File_Names (Com.Specification).Name = No_Name then
5795 declare
5796 Src_Ind : Source_File_Index;
5798 -- Here we are cheating a little bit: we don't want to
5799 -- use Sinput.L, because it depends on the GNAT tree
5800 -- (Atree, Sinfo, ...). So, we pretend that it is
5801 -- a project file, and we use Sinput.P.
5802 -- Source_File_Is_Subunit is just scanning through
5803 -- the file until it finds one of the reserved words
5804 -- separate, procedure, function, generic or package.
5805 -- Fortunately, these Ada reserved words are also
5806 -- reserved for project files.
5808 begin
5809 Src_Ind := Sinput.P.Load_Project_File
5810 (Get_Name_String
5811 (Unit.File_Names (Com.Body_Part).Path));
5813 -- If it is a subunit, discard it
5815 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
5816 Sfile := No_Name;
5818 else
5819 Sfile := Unit.File_Names (Com.Body_Part).Name;
5820 end if;
5821 end;
5823 else
5824 Sfile := Unit.File_Names (Com.Body_Part).Name;
5825 end if;
5826 end if;
5828 elsif Unit.File_Names (Com.Specification).Name /= No_Name
5829 and then Unit.File_Names (Com.Specification).Path /= Slash
5830 and then Check_Project (Unit.File_Names (Com.Specification).Project)
5831 then
5832 -- If there is no source for the body, but there is a source
5833 -- for the spec which has not been locally removed, then we take
5834 -- this one.
5836 Sfile := Unit.File_Names (Com.Specification).Name;
5837 end if;
5839 -- If Put_In_Q is True, we insert into the Q
5841 if Put_In_Q then
5843 -- For the first source inserted into the Q, we need
5844 -- to initialize the Q, but not for the subsequent sources.
5846 if First_Q_Initialization then
5847 Init_Q;
5848 end if;
5850 -- And of course, we only insert in the Q if the source
5851 -- is not marked.
5853 if Sfile /= No_Name and then not Is_Marked (Sfile) then
5854 if Verbose_Mode then
5855 Write_Str ("Adding """);
5856 Write_Str (Get_Name_String (Sfile));
5857 Write_Line (""" to the queue");
5858 end if;
5860 Insert_Q (Sfile);
5861 Mark (Sfile);
5862 end if;
5864 elsif Sfile /= No_Name then
5866 -- If Put_In_Q is False, we add the source as it it were
5867 -- specified on the command line, and we set Put_In_Q to True,
5868 -- so that the following sources will be put directly in the
5869 -- queue. This will allow parallel compilation processes if -jx
5870 -- switch is used.
5872 if Verbose_Mode then
5873 Write_Str ("Adding """);
5874 Write_Str (Get_Name_String (Sfile));
5875 Write_Line (""" as if on the command line");
5876 end if;
5878 Osint.Add_File (Get_Name_String (Sfile));
5879 Put_In_Q := True;
5880 end if;
5881 end loop;
5882 end Insert_Project_Sources;
5884 --------------
5885 -- Insert_Q --
5886 --------------
5888 procedure Insert_Q
5889 (Source_File : File_Name_Type;
5890 Source_Unit : Unit_Name_Type := No_Name;
5891 Index : Int := 0)
5893 begin
5894 if Debug.Debug_Flag_Q then
5895 Write_Str (" Q := Q + [ ");
5896 Write_Name (Source_File);
5898 if Index /= 0 then
5899 Write_Str (", ");
5900 Write_Int (Index);
5901 end if;
5903 Write_Str (" ] ");
5904 Write_Eol;
5905 end if;
5907 Q.Table (Q.Last) :=
5908 (File => Source_File,
5909 Unit => Source_Unit,
5910 Index => Index);
5911 Q.Increment_Last;
5912 end Insert_Q;
5914 ---------------------
5915 -- Is_In_Obsoleted --
5916 ---------------------
5918 function Is_In_Obsoleted (F : Name_Id) return Boolean is
5919 begin
5920 if F = No_File then
5921 return False;
5923 else
5924 declare
5925 Name : constant String := Get_Name_String (F);
5926 First : Natural := Name'Last;
5927 F2 : Name_Id := F;
5929 begin
5930 while First > Name'First
5931 and then Name (First - 1) /= Directory_Separator
5932 and then Name (First - 1) /= '/'
5933 loop
5934 First := First - 1;
5935 end loop;
5937 if First /= Name'First then
5938 Name_Len := 0;
5939 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
5940 F2 := Name_Find;
5941 end if;
5943 return Obsoleted.Get (F2);
5944 end;
5945 end if;
5946 end Is_In_Obsoleted;
5948 ----------------------------
5949 -- Is_In_Object_Directory --
5950 ----------------------------
5952 function Is_In_Object_Directory
5953 (Source_File : File_Name_Type;
5954 Full_Lib_File : File_Name_Type) return Boolean
5956 begin
5957 -- There is something to check only when using project files.
5958 -- Otherwise, this function returns True (last line of the function).
5960 if Main_Project /= No_Project then
5961 declare
5962 Source_File_Name : constant String :=
5963 Get_Name_String (Source_File);
5964 Saved_Verbosity : constant Verbosity := Prj.Com.Current_Verbosity;
5965 Project : Project_Id := No_Project;
5966 Path_Name : Name_Id := No_Name;
5967 Data : Project_Data;
5969 begin
5970 -- Call Get_Reference to know the ultimate extending project of
5971 -- the source. Call it with verbosity default to avoid verbose
5972 -- messages.
5974 Prj.Com.Current_Verbosity := Default;
5975 Prj.Env.
5976 Get_Reference
5977 (Source_File_Name => Source_File_Name,
5978 Project => Project,
5979 Path => Path_Name);
5980 Prj.Com.Current_Verbosity := Saved_Verbosity;
5982 -- If this source is in a project, check that the ALI file is
5983 -- in its object directory. If it is not, return False, so that
5984 -- the ALI file will not be skipped.
5986 -- If the source is not in an extending project, we fall back to
5987 -- the general case and return True at the end of the function.
5989 if Project /= No_Project
5990 and then Projects.Table (Project).Extends /= No_Project
5991 then
5992 Data := Projects.Table (Project);
5994 declare
5995 Object_Directory : constant String :=
5996 Normalize_Pathname
5997 (Get_Name_String
5998 (Data.Object_Directory));
6000 Olast : Natural := Object_Directory'Last;
6002 Lib_File_Directory : constant String :=
6003 Normalize_Pathname (Dir_Name
6004 (Get_Name_String (Full_Lib_File)));
6006 Llast : Natural := Lib_File_Directory'Last;
6008 begin
6009 -- For directories, Normalize_Pathname may or may not put
6010 -- a directory separator at the end, depending on its input.
6011 -- Remove any last directory separator before comparaison.
6012 -- Returns True only if the two directories are the same.
6014 if Object_Directory (Olast) = Directory_Separator then
6015 Olast := Olast - 1;
6016 end if;
6018 if Lib_File_Directory (Llast) = Directory_Separator then
6019 Llast := Llast - 1;
6020 end if;
6022 return Object_Directory (Object_Directory'First .. Olast) =
6023 Lib_File_Directory (Lib_File_Directory'First .. Llast);
6024 end;
6025 end if;
6026 end;
6027 end if;
6029 -- When the source is not in a project file, always return True
6031 return True;
6032 end Is_In_Object_Directory;
6034 ----------
6035 -- Link --
6036 ----------
6038 procedure Link (ALI_File : File_Name_Type; Args : Argument_List) is
6039 Link_Args : Argument_List (1 .. Args'Length + 1);
6040 Success : Boolean;
6042 begin
6043 Get_Name_String (ALI_File);
6044 Link_Args (1) := new String'(Name_Buffer (1 .. Name_Len));
6046 Link_Args (2 .. Args'Length + 1) := Args;
6048 GNAT.OS_Lib.Normalize_Arguments (Link_Args);
6050 Display (Gnatlink.all, Link_Args);
6052 if Gnatlink_Path = null then
6053 Make_Failed ("error, unable to locate ", Gnatlink.all);
6054 end if;
6056 GNAT.OS_Lib.Spawn (Gnatlink_Path.all, Link_Args, Success);
6058 if not Success then
6059 raise Link_Failed;
6060 end if;
6061 end Link;
6063 ---------------------------
6064 -- List_Bad_Compilations --
6065 ---------------------------
6067 procedure List_Bad_Compilations is
6068 begin
6069 for J in Bad_Compilation.First .. Bad_Compilation.Last loop
6070 if Bad_Compilation.Table (J).File = No_File then
6071 null;
6072 elsif not Bad_Compilation.Table (J).Found then
6073 Inform (Bad_Compilation.Table (J).File, "not found");
6074 else
6075 Inform (Bad_Compilation.Table (J).File, "compilation error");
6076 end if;
6077 end loop;
6078 end List_Bad_Compilations;
6080 -----------------
6081 -- List_Depend --
6082 -----------------
6084 procedure List_Depend is
6085 Lib_Name : Name_Id;
6086 Obj_Name : Name_Id;
6087 Src_Name : Name_Id;
6089 Len : Natural;
6090 Line_Pos : Natural;
6091 Line_Size : constant := 77;
6093 begin
6094 Set_Standard_Output;
6096 for A in ALIs.First .. ALIs.Last loop
6097 Lib_Name := ALIs.Table (A).Afile;
6099 -- We have to provide the full library file name in In_Place_Mode
6101 if In_Place_Mode then
6102 Lib_Name := Full_Lib_File_Name (Lib_Name);
6103 end if;
6105 Obj_Name := Object_File_Name (Lib_Name);
6106 Write_Name (Obj_Name);
6107 Write_Str (" :");
6109 Get_Name_String (Obj_Name);
6110 Len := Name_Len;
6111 Line_Pos := Len + 2;
6113 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
6114 Src_Name := Sdep.Table (D).Sfile;
6116 if Is_Internal_File_Name (Src_Name)
6117 and then not Check_Readonly_Files
6118 then
6119 null;
6120 else
6121 if not Quiet_Output then
6122 Src_Name := Full_Source_Name (Src_Name);
6123 end if;
6125 Get_Name_String (Src_Name);
6126 Len := Name_Len;
6128 if Line_Pos + Len + 1 > Line_Size then
6129 Write_Str (" \");
6130 Write_Eol;
6131 Line_Pos := 0;
6132 end if;
6134 Line_Pos := Line_Pos + Len + 1;
6136 Write_Str (" ");
6137 Write_Name (Src_Name);
6138 end if;
6139 end loop;
6141 Write_Eol;
6142 end loop;
6144 Set_Standard_Error;
6145 end List_Depend;
6147 -----------------
6148 -- Make_Failed --
6149 -----------------
6151 procedure Make_Failed (S1 : String; S2 : String := ""; S3 : String := "") is
6152 begin
6153 Delete_All_Temp_Files;
6154 Osint.Fail (S1, S2, S3);
6155 end Make_Failed;
6157 --------------------
6158 -- Mark_Directory --
6159 --------------------
6161 procedure Mark_Directory
6162 (Dir : String;
6163 Mark : Lib_Mark_Type)
6165 N : Name_Id;
6166 B : Byte;
6168 begin
6169 -- Dir last character is supposed to be a directory separator.
6171 Name_Len := Dir'Length;
6172 Name_Buffer (1 .. Name_Len) := Dir;
6174 if not Is_Directory_Separator (Name_Buffer (Name_Len)) then
6175 Name_Len := Name_Len + 1;
6176 Name_Buffer (Name_Len) := Directory_Separator;
6177 end if;
6179 -- Add flags to the already existing flags
6181 N := Name_Find;
6182 B := Get_Name_Table_Byte (N);
6183 Set_Name_Table_Byte (N, B or Mark);
6184 end Mark_Directory;
6186 -----------------------------
6187 -- Recursive_Compute_Depth --
6188 -----------------------------
6190 procedure Recursive_Compute_Depth
6191 (Project : Project_Id;
6192 Visited : Project_Array;
6193 Depth : Natural)
6195 List : Project_List;
6196 Proj : Project_Id;
6197 OK : Boolean;
6198 New_Visited : constant Project_Array := Visited & Project;
6200 begin
6201 -- Nothing to do if there is no project
6203 if Project = No_Project then
6204 return;
6205 end if;
6207 -- If current depth of project is lower than Depth, adjust it
6209 if Projects.Table (Project).Depth < Depth then
6210 Projects.Table (Project).Depth := Depth;
6211 end if;
6213 List := Projects.Table (Project).Imported_Projects;
6215 -- Visit each imported project
6217 while List /= Empty_Project_List loop
6218 Proj := Project_Lists.Table (List).Project;
6219 List := Project_Lists.Table (List).Next;
6221 OK := True;
6223 -- To avoid endless loops due to cycles with limited widts,
6224 -- do not revisit a project that is already in the chain of imports
6225 -- that brought us here.
6227 for J in Visited'Range loop
6228 if Visited (J) = Proj then
6229 OK := False;
6230 exit;
6231 end if;
6232 end loop;
6234 if OK then
6235 Recursive_Compute_Depth
6236 (Project => Proj,
6237 Visited => New_Visited,
6238 Depth => Depth + 1);
6239 end if;
6240 end loop;
6242 -- Visit a project being extended, if any
6244 Recursive_Compute_Depth
6245 (Project => Projects.Table (Project).Extends,
6246 Visited => New_Visited,
6247 Depth => Depth + 1);
6248 end Recursive_Compute_Depth;
6250 -----------------------
6251 -- Sigint_Intercpted --
6252 -----------------------
6254 procedure Sigint_Intercepted is
6255 begin
6256 Write_Line ("*** Interrupted ***");
6257 Delete_All_Temp_Files;
6258 OS_Exit (1);
6259 end Sigint_Intercepted;
6261 -------------------
6262 -- Scan_Make_Arg --
6263 -------------------
6265 procedure Scan_Make_Arg (Argv : String; And_Save : Boolean) is
6266 begin
6267 pragma Assert (Argv'First = 1);
6269 if Argv'Length = 0 then
6270 return;
6271 end if;
6273 -- If the previous switch has set the Project_File_Name_Present
6274 -- flag (that is we have seen a -P alone), then the next argument is
6275 -- the name of the project file.
6277 if Project_File_Name_Present and then Project_File_Name = null then
6278 if Argv (1) = '-' then
6279 Make_Failed ("project file name missing after -P");
6281 else
6282 Project_File_Name_Present := False;
6283 Project_File_Name := new String'(Argv);
6284 end if;
6286 -- If the previous switch has set the Output_File_Name_Present
6287 -- flag (that is we have seen a -o), then the next argument is
6288 -- the name of the output executable.
6290 elsif Output_File_Name_Present
6291 and then not Output_File_Name_Seen
6292 then
6293 Output_File_Name_Seen := True;
6295 if Argv (1) = '-' then
6296 Make_Failed ("output file name missing after -o");
6298 else
6299 Add_Switch ("-o", Linker, And_Save => And_Save);
6301 -- Automatically add the executable suffix if it has not been
6302 -- specified explicitly.
6304 declare
6305 Canonical_Argv : String := Argv;
6306 begin
6307 -- Get the file name in canonical case to accept as is
6308 -- names ending with ".EXE" on VMS and Windows.
6310 Canonical_Case_File_Name (Canonical_Argv);
6312 if Executable_Suffix'Length /= 0
6313 and then (Canonical_Argv'Length <= Executable_Suffix'Length
6314 or else Canonical_Argv
6315 (Canonical_Argv'Last -
6316 Executable_Suffix'Length + 1
6317 .. Canonical_Argv'Last)
6318 /= Executable_Suffix)
6319 then
6320 Add_Switch
6321 (Argv & Executable_Suffix,
6322 Linker,
6323 And_Save => And_Save);
6324 else
6325 Add_Switch (Argv, Linker, And_Save => And_Save);
6326 end if;
6327 end;
6328 end if;
6330 -- If the previous switch has set the Object_Directory_Present flag
6331 -- (that is we have seen a -D), then the next argument is
6332 -- the path name of the object directory..
6334 elsif Object_Directory_Present
6335 and then not Object_Directory_Seen
6336 then
6337 Object_Directory_Seen := True;
6339 if Argv (1) = '-' then
6340 Make_Failed ("object directory path name missing after -D");
6342 elsif not Is_Directory (Argv) then
6343 Make_Failed ("cannot find object directory """, Argv, """");
6345 else
6346 Add_Lib_Search_Dir (Argv);
6348 -- Specify the object directory to the binder
6350 Add_Switch ("-aO" & Argv, Binder, And_Save => And_Save);
6352 -- Record the object directory. Make sure it ends with a directory
6353 -- separator.
6355 if Argv (Argv'Last) = Directory_Separator then
6356 Object_Directory_Path := new String'(Argv);
6358 else
6359 Object_Directory_Path :=
6360 new String'(Argv & Directory_Separator);
6361 end if;
6362 end if;
6364 -- Then check if we are dealing with -cargs/-bargs/-largs/-margs
6366 elsif Argv = "-bargs"
6367 or else
6368 Argv = "-cargs"
6369 or else
6370 Argv = "-largs"
6371 or else
6372 Argv = "-margs"
6373 then
6374 case Argv (2) is
6375 when 'c' => Program_Args := Compiler;
6376 when 'b' => Program_Args := Binder;
6377 when 'l' => Program_Args := Linker;
6378 when 'm' => Program_Args := None;
6380 when others =>
6381 raise Program_Error;
6382 end case;
6384 -- A special test is needed for the -o switch within a -largs
6385 -- since that is another way to specify the name of the final
6386 -- executable.
6388 elsif Program_Args = Linker
6389 and then Argv = "-o"
6390 then
6391 Make_Failed ("switch -o not allowed within a -largs. " &
6392 "Use -o directly.");
6394 -- Check to see if we are reading switches after a -cargs,
6395 -- -bargs or -largs switch. If yes save it.
6397 elsif Program_Args /= None then
6399 -- Check to see if we are reading -I switches in order
6400 -- to take into account in the src & lib search directories.
6402 if Argv'Length > 2 and then Argv (1 .. 2) = "-I" then
6403 if Argv (3 .. Argv'Last) = "-" then
6404 Look_In_Primary_Dir := False;
6406 elsif Program_Args = Compiler then
6407 if Argv (3 .. Argv'Last) /= "-" then
6408 Add_Src_Search_Dir (Argv (3 .. Argv'Last));
6409 end if;
6411 elsif Program_Args = Binder then
6412 Add_Lib_Search_Dir (Argv (3 .. Argv'Last));
6413 end if;
6414 end if;
6416 Add_Switch (Argv, Program_Args, And_Save => And_Save);
6418 -- Handle non-default compiler, binder, linker, and handle --RTS switch
6420 elsif Argv'Length > 2 and then Argv (1 .. 2) = "--" then
6421 if Argv'Length > 6
6422 and then Argv (1 .. 6) = "--GCC="
6423 then
6424 declare
6425 Program_Args : constant Argument_List_Access :=
6426 Argument_String_To_List
6427 (Argv (7 .. Argv'Last));
6429 begin
6430 if And_Save then
6431 Saved_Gcc := new String'(Program_Args.all (1).all);
6432 else
6433 Gcc := new String'(Program_Args.all (1).all);
6434 end if;
6436 for J in 2 .. Program_Args.all'Last loop
6437 Add_Switch
6438 (Program_Args.all (J).all,
6439 Compiler,
6440 And_Save => And_Save);
6441 end loop;
6442 end;
6444 elsif Argv'Length > 11
6445 and then Argv (1 .. 11) = "--GNATBIND="
6446 then
6447 declare
6448 Program_Args : constant Argument_List_Access :=
6449 Argument_String_To_List
6450 (Argv (12 .. Argv'Last));
6452 begin
6453 if And_Save then
6454 Saved_Gnatbind := new String'(Program_Args.all (1).all);
6455 else
6456 Gnatbind := new String'(Program_Args.all (1).all);
6457 end if;
6459 for J in 2 .. Program_Args.all'Last loop
6460 Add_Switch
6461 (Program_Args.all (J).all, Binder, And_Save => And_Save);
6462 end loop;
6463 end;
6465 elsif Argv'Length > 11
6466 and then Argv (1 .. 11) = "--GNATLINK="
6467 then
6468 declare
6469 Program_Args : constant Argument_List_Access :=
6470 Argument_String_To_List
6471 (Argv (12 .. Argv'Last));
6472 begin
6473 if And_Save then
6474 Saved_Gnatlink := new String'(Program_Args.all (1).all);
6475 else
6476 Gnatlink := new String'(Program_Args.all (1).all);
6477 end if;
6479 for J in 2 .. Program_Args.all'Last loop
6480 Add_Switch (Program_Args.all (J).all, Linker);
6481 end loop;
6482 end;
6484 elsif Argv'Length >= 5 and then
6485 Argv (1 .. 5) = "--RTS"
6486 then
6487 Add_Switch (Argv, Compiler, And_Save => And_Save);
6488 Add_Switch (Argv, Binder, And_Save => And_Save);
6490 if Argv'Length <= 6 or else Argv (6) /= '=' then
6491 Make_Failed ("missing path for --RTS");
6493 else
6494 -- Check that this is the first time we see this switch or
6495 -- if it is not the first time, the same path is specified.
6497 if RTS_Specified = null then
6498 RTS_Specified := new String'(Argv (7 .. Argv'Last));
6500 elsif RTS_Specified.all /= Argv (7 .. Argv'Last) then
6501 Make_Failed ("--RTS cannot be specified multiple times");
6502 end if;
6504 -- Valid --RTS switch
6506 No_Stdinc := True;
6507 No_Stdlib := True;
6508 RTS_Switch := True;
6510 declare
6511 Src_Path_Name : constant String_Ptr :=
6512 Get_RTS_Search_Dir
6513 (Argv (7 .. Argv'Last), Include);
6515 Lib_Path_Name : constant String_Ptr :=
6516 Get_RTS_Search_Dir
6517 (Argv (7 .. Argv'Last), Objects);
6519 begin
6520 if Src_Path_Name /= null and then
6521 Lib_Path_Name /= null
6522 then
6523 -- Set the RTS_*_Path_Name variables, so that the correct
6524 -- directories will be set when
6525 -- Osint.Add_Default_Search_Dirs will be called later.
6527 RTS_Src_Path_Name := Src_Path_Name;
6528 RTS_Lib_Path_Name := Lib_Path_Name;
6530 elsif Src_Path_Name = null
6531 and Lib_Path_Name = null then
6532 Make_Failed ("RTS path not valid: missing " &
6533 "adainclude and adalib directories");
6535 elsif Src_Path_Name = null then
6536 Make_Failed ("RTS path not valid: missing adainclude " &
6537 "directory");
6539 elsif Lib_Path_Name = null then
6540 Make_Failed ("RTS path not valid: missing adalib " &
6541 "directory");
6542 end if;
6543 end;
6544 end if;
6546 else
6547 Make_Failed ("unknown switch: ", Argv);
6548 end if;
6550 -- If we have seen a regular switch process it
6552 elsif Argv (1) = '-' then
6554 if Argv'Length = 1 then
6555 Make_Failed ("switch character cannot be followed by a blank");
6557 -- -I-
6559 elsif Argv (2 .. Argv'Last) = "I-" then
6560 Look_In_Primary_Dir := False;
6562 -- Forbid -?- or -??- where ? is any character
6564 elsif (Argv'Length = 3 and then Argv (3) = '-')
6565 or else (Argv'Length = 4 and then Argv (4) = '-')
6566 then
6567 Make_Failed ("trailing ""-"" at the end of ", Argv, " forbidden.");
6569 -- -Idir
6571 elsif Argv (2) = 'I' then
6572 Add_Src_Search_Dir (Argv (3 .. Argv'Last));
6573 Add_Lib_Search_Dir (Argv (3 .. Argv'Last));
6574 Add_Switch (Argv, Compiler, And_Save => And_Save);
6575 Add_Switch (Argv, Binder, And_Save => And_Save);
6577 -- -aIdir (to gcc this is like a -I switch)
6579 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aI" then
6580 Add_Src_Search_Dir (Argv (4 .. Argv'Last));
6581 Add_Switch ("-I" & Argv (4 .. Argv'Last),
6582 Compiler,
6583 And_Save => And_Save);
6584 Add_Switch (Argv, Binder, And_Save => And_Save);
6586 -- -aOdir
6588 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aO" then
6589 Add_Lib_Search_Dir (Argv (4 .. Argv'Last));
6590 Add_Switch (Argv, Binder, And_Save => And_Save);
6592 -- -aLdir (to gnatbind this is like a -aO switch)
6594 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aL" then
6595 Mark_Directory (Argv (4 .. Argv'Last), Ada_Lib_Dir);
6596 Add_Lib_Search_Dir (Argv (4 .. Argv'Last));
6597 Add_Switch ("-aO" & Argv (4 .. Argv'Last),
6598 Binder,
6599 And_Save => And_Save);
6601 -- -Adir (to gnatbind this is like a -aO switch, to gcc like a -I)
6603 elsif Argv (2) = 'A' then
6604 Mark_Directory (Argv (3 .. Argv'Last), Ada_Lib_Dir);
6605 Add_Src_Search_Dir (Argv (3 .. Argv'Last));
6606 Add_Lib_Search_Dir (Argv (3 .. Argv'Last));
6607 Add_Switch ("-I" & Argv (3 .. Argv'Last),
6608 Compiler,
6609 And_Save => And_Save);
6610 Add_Switch ("-aO" & Argv (3 .. Argv'Last),
6611 Binder,
6612 And_Save => And_Save);
6614 -- -Ldir
6616 elsif Argv (2) = 'L' then
6617 Add_Switch (Argv, Linker, And_Save => And_Save);
6619 -- For -gxxxxx, -pg, -mxxx, -fxxx: give the switch to both the
6620 -- compiler and the linker (except for -gnatxxx which is only for
6621 -- the compiler). Some of the -mxxx (for example -m64) and -fxxx
6622 -- (for example -ftest-coverage for gcov) need to be used when
6623 -- compiling the binder generated files, and using all these gcc
6624 -- switches for the binder generated files should not be a problem.
6626 elsif
6627 (Argv (2) = 'g' and then (Argv'Last < 5
6628 or else Argv (2 .. 5) /= "gnat"))
6629 or else Argv (2 .. Argv'Last) = "pg"
6630 or else (Argv (2) = 'm' and then Argv'Last > 2)
6631 or else (Argv (2) = 'f' and then Argv'Last > 2)
6632 then
6633 Add_Switch (Argv, Compiler, And_Save => And_Save);
6634 Add_Switch (Argv, Linker, And_Save => And_Save);
6636 -- -C=<mapping file>
6638 elsif Argv'Last > 2 and then Argv (2) = 'C' then
6639 if And_Save then
6640 if Argv (3) /= '=' or else Argv'Last <= 3 then
6641 Make_Failed ("illegal switch ", Argv);
6642 end if;
6644 Gnatmake_Mapping_File := new String'(Argv (4 .. Argv'Last));
6645 end if;
6647 -- -D
6649 elsif Argv'Last = 2 and then Argv (2) = 'D' then
6650 if Project_File_Name /= null then
6651 Make_Failed ("-D cannot be used in conjunction with a " &
6652 "project file");
6654 else
6655 Scan_Make_Switches (Argv);
6656 end if;
6658 -- -d
6660 elsif Argv (2) = 'd'
6661 and then Argv'Last = 2
6662 then
6663 Display_Compilation_Progress := True;
6665 -- -i
6667 elsif Argv'Last = 2 and then Argv (2) = 'i' then
6668 if Project_File_Name /= null then
6669 Make_Failed ("-i cannot be used in conjunction with a " &
6670 "project file");
6672 else
6673 Scan_Make_Switches (Argv);
6674 end if;
6676 -- -j (need to save the result)
6678 elsif Argv (2) = 'j' then
6679 Scan_Make_Switches (Argv);
6681 if And_Save then
6682 Saved_Maximum_Processes := Maximum_Processes;
6683 end if;
6685 -- -m
6687 elsif Argv (2) = 'm'
6688 and then Argv'Last = 2
6689 then
6690 Minimal_Recompilation := True;
6692 -- -u
6694 elsif Argv (2) = 'u'
6695 and then Argv'Last = 2
6696 then
6697 Unique_Compile := True;
6698 Compile_Only := True;
6699 Do_Bind_Step := False;
6700 Do_Link_Step := False;
6702 -- -U
6704 elsif Argv (2) = 'U'
6705 and then Argv'Last = 2
6706 then
6707 Unique_Compile_All_Projects := True;
6708 Unique_Compile := True;
6709 Compile_Only := True;
6710 Do_Bind_Step := False;
6711 Do_Link_Step := False;
6713 -- -Pprj or -P prj (only once, and only on the command line)
6715 elsif Argv (2) = 'P' then
6716 if Project_File_Name /= null then
6717 Make_Failed ("cannot have several project files specified");
6719 elsif Object_Directory_Path /= null then
6720 Make_Failed ("-D cannot be used in conjunction with a " &
6721 "project file");
6723 elsif In_Place_Mode then
6724 Make_Failed ("-i cannot be used in conjunction with a " &
6725 "project file");
6727 elsif not And_Save then
6729 -- It could be a tool other than gnatmake (i.e, gnatdist)
6730 -- or a -P switch inside a project file.
6732 Fail
6733 ("either the tool is not ""project-aware"" or " &
6734 "a project file is specified inside a project file");
6736 elsif Argv'Last = 2 then
6738 -- -P is used alone: the project file name is the next option
6740 Project_File_Name_Present := True;
6742 else
6743 Project_File_Name := new String'(Argv (3 .. Argv'Last));
6744 end if;
6746 -- -vPx (verbosity of the parsing of the project files)
6748 elsif Argv'Last = 4
6749 and then Argv (2 .. 3) = "vP"
6750 and then Argv (4) in '0' .. '2'
6751 then
6752 if And_Save then
6753 case Argv (4) is
6754 when '0' =>
6755 Current_Verbosity := Prj.Default;
6756 when '1' =>
6757 Current_Verbosity := Prj.Medium;
6758 when '2' =>
6759 Current_Verbosity := Prj.High;
6760 when others =>
6761 null;
6762 end case;
6763 end if;
6765 -- -Xext=val (External assignment)
6767 elsif Argv (2) = 'X'
6768 and then Is_External_Assignment (Argv)
6769 then
6770 -- Is_External_Assignment has side effects
6771 -- when it returns True;
6773 null;
6775 -- If -gnath is present, then generate the usage information
6776 -- right now and do not pass this option on to the compiler calls.
6778 elsif Argv = "-gnath" then
6779 Usage;
6781 -- If -gnatc is specified, make sure the bind step and the link
6782 -- step are not executed.
6784 elsif Argv'Length >= 6 and then Argv (2 .. 6) = "gnatc" then
6786 -- If -gnatc is specified, make sure the bind step and the link
6787 -- step are not executed.
6789 Add_Switch (Argv, Compiler, And_Save => And_Save);
6790 Operating_Mode := Check_Semantics;
6791 Check_Object_Consistency := False;
6792 Compile_Only := True;
6793 Do_Bind_Step := False;
6794 Do_Link_Step := False;
6796 elsif Argv (2 .. Argv'Last) = "nostdlib" then
6798 -- Don't pass -nostdlib to gnatlink, it will disable
6799 -- linking with all standard library files.
6801 No_Stdlib := True;
6803 Add_Switch (Argv, Compiler, And_Save => And_Save);
6804 Add_Switch (Argv, Binder, And_Save => And_Save);
6806 elsif Argv (2 .. Argv'Last) = "nostdinc" then
6808 -- Pass -nostdinc to the Compiler and to gnatbind
6810 No_Stdinc := True;
6811 Add_Switch (Argv, Compiler, And_Save => And_Save);
6812 Add_Switch (Argv, Binder, And_Save => And_Save);
6814 -- By default all switches with more than one character
6815 -- or one character switches which are not in 'a' .. 'z'
6816 -- (except 'C', 'F', 'M' and 'B') are passed to the compiler,
6817 -- unless we are dealing with a debug switch (starts with 'd')
6818 -- or an extended gnatmake switch (starts with 'e').
6820 elsif Argv (2) /= 'd'
6821 and then Argv (2) /= 'e'
6822 and then Argv (2 .. Argv'Last) /= "C"
6823 and then Argv (2 .. Argv'Last) /= "F"
6824 and then Argv (2 .. Argv'Last) /= "M"
6825 and then Argv (2 .. Argv'Last) /= "B"
6826 and then (Argv'Length > 2 or else Argv (2) not in 'a' .. 'z')
6827 then
6828 Add_Switch (Argv, Compiler, And_Save => And_Save);
6830 -- All other options are handled by Scan_Make_Switches
6832 else
6833 Scan_Make_Switches (Argv);
6834 end if;
6836 -- If not a switch it must be a file name
6838 else
6839 Add_File (Argv);
6840 Mains.Add_Main (Argv);
6841 end if;
6842 end Scan_Make_Arg;
6844 -----------------
6845 -- Switches_Of --
6846 -----------------
6848 function Switches_Of
6849 (Source_File : Name_Id;
6850 Source_File_Name : String;
6851 Source_Index : Int;
6852 Naming : Naming_Data;
6853 In_Package : Package_Id;
6854 Allow_ALI : Boolean) return Variable_Value
6856 Switches : Variable_Value;
6858 Defaults : constant Array_Element_Id :=
6859 Prj.Util.Value_Of
6860 (Name => Name_Default_Switches,
6861 In_Arrays =>
6862 Packages.Table (In_Package).Decl.Arrays);
6864 Switches_Array : constant Array_Element_Id :=
6865 Prj.Util.Value_Of
6866 (Name => Name_Switches,
6867 In_Arrays =>
6868 Packages.Table (In_Package).Decl.Arrays);
6870 begin
6871 Switches :=
6872 Prj.Util.Value_Of
6873 (Index => Source_File,
6874 Src_Index => Source_Index,
6875 In_Array => Switches_Array);
6877 if Switches = Nil_Variable_Value then
6878 declare
6879 Name : String (1 .. Source_File_Name'Length + 3);
6880 Last : Positive := Source_File_Name'Length;
6881 Spec_Suffix : constant String :=
6882 Get_Name_String (Naming.Current_Spec_Suffix);
6883 Body_Suffix : constant String :=
6884 Get_Name_String (Naming.Current_Body_Suffix);
6885 Truncated : Boolean := False;
6887 begin
6888 Name (1 .. Last) := Source_File_Name;
6890 if Last > Body_Suffix'Length
6891 and then Name (Last - Body_Suffix'Length + 1 .. Last) =
6892 Body_Suffix
6893 then
6894 Truncated := True;
6895 Last := Last - Body_Suffix'Length;
6896 end if;
6898 if not Truncated
6899 and then Last > Spec_Suffix'Length
6900 and then Name (Last - Spec_Suffix'Length + 1 .. Last) =
6901 Spec_Suffix
6902 then
6903 Truncated := True;
6904 Last := Last - Spec_Suffix'Length;
6905 end if;
6907 if Truncated then
6908 Name_Len := Last;
6909 Name_Buffer (1 .. Name_Len) := Name (1 .. Last);
6910 Switches :=
6911 Prj.Util.Value_Of
6912 (Index => Name_Find,
6913 Src_Index => 0,
6914 In_Array => Switches_Array);
6916 if Switches = Nil_Variable_Value
6917 and then Allow_ALI
6918 then
6919 Last := Source_File_Name'Length;
6921 while Name (Last) /= '.' loop
6922 Last := Last - 1;
6923 end loop;
6925 Name (Last + 1 .. Last + 3) := "ali";
6926 Name_Len := Last + 3;
6927 Name_Buffer (1 .. Name_Len) := Name (1 .. Name_Len);
6928 Switches :=
6929 Prj.Util.Value_Of
6930 (Index => Name_Find,
6931 Src_Index => 0,
6932 In_Array => Switches_Array);
6933 end if;
6934 end if;
6935 end;
6936 end if;
6938 if Switches = Nil_Variable_Value then
6939 Switches :=
6940 Prj.Util.Value_Of
6941 (Index => Name_Ada,
6942 Src_Index => 0,
6943 In_Array => Defaults);
6944 end if;
6946 return Switches;
6947 end Switches_Of;
6949 -----------
6950 -- Usage --
6951 -----------
6953 procedure Usage is
6954 begin
6955 if Usage_Needed then
6956 Usage_Needed := False;
6957 Makeusg;
6958 end if;
6959 end Usage;
6961 -----------------
6962 -- Verbose_Msg --
6963 -----------------
6965 procedure Verbose_Msg
6966 (N1 : Name_Id;
6967 S1 : String;
6968 N2 : Name_Id := No_Name;
6969 S2 : String := "";
6970 Prefix : String := " -> ")
6972 begin
6973 if not Verbose_Mode then
6974 return;
6975 end if;
6977 Write_Str (Prefix);
6978 Write_Str ("""");
6979 Write_Name (N1);
6980 Write_Str (""" ");
6981 Write_Str (S1);
6983 if N2 /= No_Name then
6984 Write_Str (" """);
6985 Write_Name (N2);
6986 Write_Str (""" ");
6987 end if;
6989 Write_Str (S2);
6990 Write_Eol;
6991 end Verbose_Msg;
6993 begin
6994 -- Make sure that in case of failure, the temp files will be deleted
6996 Prj.Com.Fail := Make_Failed'Access;
6997 MLib.Fail := Make_Failed'Access;
6998 Makeutl.Do_Fail := Make_Failed'Access;
6999 end Make;