1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
27 with ALI.Util; use ALI.Util;
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;
38 with Makeutl; use Makeutl;
41 with MLib.Tgt; use MLib.Tgt;
43 with Namet; use Namet;
45 with Osint.M; use Osint.M;
46 with Osint; use Osint;
47 with Output; use Output;
55 with Snames; use Snames;
56 with Switch; use Switch;
57 with Switch.M; use Switch.M;
58 with Targparm; use Targparm;
61 with Types; use Types;
63 with Ada.Exceptions; use Ada.Exceptions;
64 with Ada.Command_Line; use Ada.Command_Line;
66 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
67 with GNAT.Dynamic_HTables; use GNAT.Dynamic_HTables;
68 with GNAT.Case_Util; use GNAT.Case_Util;
69 with GNAT.OS_Lib; use GNAT.OS_Lib;
76 -- Make control characters visible
78 Standard_Library_Package_Body_Name : constant String := "s-stalib.adb";
79 -- Every program depends on this package, that must then be checked,
80 -- especially when -f and -a are used.
82 procedure Kill (Pid : Process_Id; Sig_Num : Integer; Close : Integer);
83 pragma Import (C, Kill, "__gnat_kill");
84 -- Called by Sigint_Intercepted to kill all spawned compilation processes
86 type Sigint_Handler is access procedure;
87 pragma Convention (C, Sigint_Handler);
89 procedure Install_Int_Handler (Handler : Sigint_Handler);
90 pragma Import (C, Install_Int_Handler, "__gnat_install_int_handler");
91 -- Called by Gnatmake to install the SIGINT handler below
93 procedure Sigint_Intercepted;
94 pragma Convention (C, Sigint_Intercepted);
95 -- Called when the program is interrupted by Ctrl-C to delete the
96 -- temporary mapping files and configuration pragmas files.
98 No_Mapping_File : constant Natural := 0;
100 type Compilation_Data is record
102 Full_Source_File : File_Name_Type;
103 Lib_File : File_Name_Type;
104 Source_Unit : Unit_Name_Type;
105 Mapping_File : Natural := No_Mapping_File;
106 Project : Project_Id := No_Project;
107 Syntax_Only : Boolean := False;
108 Output_Is_Object : Boolean := True;
110 -- Data recorded for each compilation process spawned
112 type Comp_Data_Arr is array (Positive range <>) of Compilation_Data;
113 type Comp_Data_Ptr is access Comp_Data_Arr;
114 Running_Compile : Comp_Data_Ptr;
115 -- Used to save information about outstanding compilations
117 Outstanding_Compiles : Natural := 0;
118 -- Current number of outstanding compiles
120 -------------------------
121 -- Note on terminology --
122 -------------------------
124 -- In this program, we use the phrase "termination" of a file name to refer
125 -- to the suffix that appears after the unit name portion. Very often this
126 -- is simply the extension, but in some cases, the sequence may be more
127 -- complex, for example in main.1.ada, the termination in this name is
128 -- ".1.ada" and in main_.ada the termination is "_.ada".
130 -------------------------------------
131 -- Queue (Q) Manipulation Routines --
132 -------------------------------------
134 -- The Q is used in Compile_Sources below. Its implementation uses the GNAT
135 -- generic package Table (basically an extensible array). Q_Front points to
136 -- the first valid element in the Q, whereas Q.First is the first element
137 -- ever enqueued, while Q.Last - 1 is the last element in the Q.
139 -- +---+--------------+---+---+---+-----------+---+--------
140 -- Q | | ........ | | | | ....... | |
141 -- +---+--------------+---+---+---+-----------+---+--------
143 -- Q.First Q_Front Q.Last - 1
145 -- The elements comprised between Q.First and Q_Front - 1 are the elements
146 -- that have been enqueued and then dequeued, while the elements between
147 -- Q_Front and Q.Last - 1 are the elements currently in the Q. When the Q
148 -- is initialized Q_Front = Q.First = Q.Last. After Compile_Sources has
149 -- terminated its execution, Q_Front = Q.Last and the elements contained
150 -- between Q.Front and Q.Last-1 are those that were explored and thus
151 -- marked by Compile_Sources. Whenever the Q is reinitialized, the elements
152 -- between Q.First and Q.Last - 1 are unmarked.
155 -- Must be called to (re)initialize the Q
158 (Source_File : File_Name_Type;
159 Source_Unit : Unit_Name_Type := No_Unit_Name;
161 -- Inserts Source_File at the end of Q. Provide Source_Unit when possible
162 -- for external use (gnatdist). Provide index for multi-unit sources.
164 function Empty_Q return Boolean;
165 -- Returns True if Q is empty
167 procedure Extract_From_Q
168 (Source_File : out File_Name_Type;
169 Source_Unit : out Unit_Name_Type;
170 Source_Index : out Int);
171 -- Extracts the first element from the Q
173 procedure Insert_Project_Sources
174 (The_Project : Project_Id;
175 All_Projects : Boolean;
177 -- If Into_Q is True, insert all sources of the project file(s) that are
178 -- not already marked into the Q. If Into_Q is False, call Osint.Add_File
179 -- for the first source, then insert all other sources that are not already
180 -- marked into the Q. If All_Projects is True, all sources of all projects
181 -- are concerned; otherwise, only sources of The_Project are concerned,
182 -- including, if The_Project is an extending project, sources inherited
183 -- from projects being extended.
185 First_Q_Initialization : Boolean := True;
186 -- Will be set to false after Init_Q has been called once
189 -- Points to the first valid element in the Q
191 Unique_Compile : Boolean := False;
192 -- Set to True if -u or -U or a project file with no main is used
194 Unique_Compile_All_Projects : Boolean := False;
195 -- Set to True if -U is used
197 RTS_Specified : String_Access := null;
198 -- Used to detect multiple --RTS= switches
200 type Q_Record is record
201 File : File_Name_Type;
202 Unit : Unit_Name_Type;
205 -- File is the name of the file to compile. Unit is for gnatdist
206 -- use in order to easily get the unit name of a file to compile
207 -- when its name is krunched or declared in gnat.adc. Index, when not 0,
208 -- is the index of the unit in a multi-unit source.
210 package Q is new Table.Table (
211 Table_Component_Type => Q_Record,
212 Table_Index_Type => Natural,
213 Table_Low_Bound => 0,
214 Table_Initial => 4000,
215 Table_Increment => 100,
216 Table_Name => "Make.Q");
217 -- This is the actual Q
219 -- The 3 following packages are used to store gcc, gnatbind and gnatlink
220 -- switches found in the project files.
222 package Gcc_Switches is new Table.Table (
223 Table_Component_Type => String_Access,
224 Table_Index_Type => Integer,
225 Table_Low_Bound => 1,
227 Table_Increment => 100,
228 Table_Name => "Make.Gcc_Switches");
230 package Binder_Switches is new Table.Table (
231 Table_Component_Type => String_Access,
232 Table_Index_Type => Integer,
233 Table_Low_Bound => 1,
235 Table_Increment => 100,
236 Table_Name => "Make.Binder_Switches");
238 package Linker_Switches is new Table.Table (
239 Table_Component_Type => String_Access,
240 Table_Index_Type => Integer,
241 Table_Low_Bound => 1,
243 Table_Increment => 100,
244 Table_Name => "Make.Linker_Switches");
246 -- The following instantiations and variables are necessary to save what
247 -- is found on the command line, in case there is a project file specified.
249 package Saved_Gcc_Switches is new Table.Table (
250 Table_Component_Type => String_Access,
251 Table_Index_Type => Integer,
252 Table_Low_Bound => 1,
254 Table_Increment => 100,
255 Table_Name => "Make.Saved_Gcc_Switches");
257 package Saved_Binder_Switches is new Table.Table (
258 Table_Component_Type => String_Access,
259 Table_Index_Type => Integer,
260 Table_Low_Bound => 1,
262 Table_Increment => 100,
263 Table_Name => "Make.Saved_Binder_Switches");
265 package Saved_Linker_Switches is new Table.Table
266 (Table_Component_Type => String_Access,
267 Table_Index_Type => Integer,
268 Table_Low_Bound => 1,
270 Table_Increment => 100,
271 Table_Name => "Make.Saved_Linker_Switches");
273 package Switches_To_Check is new Table.Table (
274 Table_Component_Type => String_Access,
275 Table_Index_Type => Integer,
276 Table_Low_Bound => 1,
278 Table_Increment => 100,
279 Table_Name => "Make.Switches_To_Check");
281 package Library_Paths is new Table.Table (
282 Table_Component_Type => String_Access,
283 Table_Index_Type => Integer,
284 Table_Low_Bound => 1,
286 Table_Increment => 100,
287 Table_Name => "Make.Library_Paths");
289 package Failed_Links is new Table.Table (
290 Table_Component_Type => File_Name_Type,
291 Table_Index_Type => Integer,
292 Table_Low_Bound => 1,
294 Table_Increment => 100,
295 Table_Name => "Make.Failed_Links");
297 package Successful_Links is new Table.Table (
298 Table_Component_Type => File_Name_Type,
299 Table_Index_Type => Integer,
300 Table_Low_Bound => 1,
302 Table_Increment => 100,
303 Table_Name => "Make.Successful_Links");
305 package Library_Projs is new Table.Table (
306 Table_Component_Type => Project_Id,
307 Table_Index_Type => Integer,
308 Table_Low_Bound => 1,
310 Table_Increment => 100,
311 Table_Name => "Make.Library_Projs");
313 -- Two variables to keep the last binder and linker switch index in tables
314 -- Binder_Switches and Linker_Switches, before adding switches from the
315 -- project file (if any) and switches from the command line (if any).
317 Last_Binder_Switch : Integer := 0;
318 Last_Linker_Switch : Integer := 0;
320 Normalized_Switches : Argument_List_Access := new Argument_List (1 .. 10);
321 Last_Norm_Switch : Natural := 0;
323 Saved_Maximum_Processes : Natural := 0;
325 Gnatmake_Switch_Found : Boolean;
326 -- Set by Scan_Make_Arg. True when the switch is a gnatmake switch.
327 -- Tested by Add_Switches when switches in package Builder must all be
328 -- gnatmake switches.
330 Switch_May_Be_Passed_To_The_Compiler : Boolean;
331 -- Set by Add_Switches and Switches_Of. True when unrecognized switches
332 -- are passed to the Ada compiler.
334 type Arg_List_Ref is access Argument_List;
335 The_Saved_Gcc_Switches : Arg_List_Ref;
337 Project_File_Name : String_Access := null;
338 -- The path name of the main project file, if any
340 Project_File_Name_Present : Boolean := False;
341 -- True when -P is used with a space between -P and the project file name
343 Current_Verbosity : Prj.Verbosity := Prj.Default;
344 -- Verbosity to parse the project files
346 Project_Tree : constant Project_Tree_Ref := new Project_Tree_Data;
348 Main_Project : Prj.Project_Id := No_Project;
349 -- The project id of the main project file, if any
351 Project_Of_Current_Object_Directory : Project_Id := No_Project;
352 -- The object directory of the project for the last compilation. Avoid
353 -- calling Change_Dir if the current working directory is already this
356 -- Packages of project files where unknown attributes are errors
358 Naming_String : aliased String := "naming";
359 Builder_String : aliased String := "builder";
360 Compiler_String : aliased String := "compiler";
361 Binder_String : aliased String := "binder";
362 Linker_String : aliased String := "linker";
364 Gnatmake_Packages : aliased String_List :=
365 (Naming_String 'Access,
366 Builder_String 'Access,
367 Compiler_String 'Access,
368 Binder_String 'Access,
369 Linker_String 'Access);
371 Packages_To_Check_By_Gnatmake : constant String_List_Access :=
372 Gnatmake_Packages'Access;
374 procedure Add_Library_Search_Dir
376 On_Command_Line : Boolean);
377 -- Call Add_Lib_Search_Dir with an absolute directory path. If Path is
378 -- relative path, when On_Command_Line is True, it is relative to the
379 -- current working directory. When On_Command_Line is False, it is relative
380 -- to the project directory of the main project.
382 procedure Add_Source_Search_Dir
384 On_Command_Line : Boolean);
385 -- Call Add_Src_Search_Dir with an absolute directory path. If Path is a
386 -- relative path, when On_Command_Line is True, it is relative to the
387 -- current working directory. When On_Command_Line is False, it is relative
388 -- to the project directory of the main project.
390 procedure Add_Source_Dir (N : String);
391 -- Call Add_Src_Search_Dir (output one line when in verbose mode)
393 procedure Add_Source_Directories is
394 new Prj.Env.For_All_Source_Dirs (Action => Add_Source_Dir);
396 procedure Add_Object_Dir (N : String);
397 -- Call Add_Lib_Search_Dir (output one line when in verbose mode)
399 procedure Add_Object_Directories is
400 new Prj.Env.For_All_Object_Dirs (Action => Add_Object_Dir);
402 procedure Change_To_Object_Directory (Project : Project_Id);
403 -- Change to the object directory of project Project, if this is not
404 -- already the current working directory.
406 type Bad_Compilation_Info is record
407 File : File_Name_Type;
408 Unit : Unit_Name_Type;
411 -- File is the name of the file for which a compilation failed. Unit is for
412 -- gnatdist use in order to easily get the unit name of a file when its
413 -- name is krunched or declared in gnat.adc. Found is False if the
414 -- compilation failed because the file could not be found.
416 package Bad_Compilation is new Table.Table (
417 Table_Component_Type => Bad_Compilation_Info,
418 Table_Index_Type => Natural,
419 Table_Low_Bound => 1,
421 Table_Increment => 100,
422 Table_Name => "Make.Bad_Compilation");
423 -- Full name of all the source files for which compilation fails
425 Do_Compile_Step : Boolean := True;
426 Do_Bind_Step : Boolean := True;
427 Do_Link_Step : Boolean := True;
428 -- Flags to indicate what step should be executed. Can be set to False
429 -- with the switches -c, -b and -l. These flags are reset to True for
430 -- each invocation of procedure Gnatmake.
432 Shared_String : aliased String := "-shared";
433 Force_Elab_Flags_String : aliased String := "-F";
435 No_Shared_Switch : aliased Argument_List := (1 .. 0 => null);
436 Shared_Switch : aliased Argument_List := (1 => Shared_String'Access);
437 Bind_Shared : Argument_List_Access := No_Shared_Switch'Access;
438 -- Switch to added in front of gnatbind switches. By default no switch is
439 -- added. Switch "-shared" is added if there is a non-static Library
442 Shared_Libgcc : aliased String := "-shared-libgcc";
444 No_Shared_Libgcc_Switch : aliased Argument_List := (1 .. 0 => null);
445 Shared_Libgcc_Switch : aliased Argument_List :=
446 (1 => Shared_Libgcc'Access);
447 Link_With_Shared_Libgcc : Argument_List_Access :=
448 No_Shared_Libgcc_Switch'Access;
450 procedure Make_Failed (S : String);
451 -- Delete all temp files created by Gnatmake and call Osint.Fail, with the
452 -- parameter S (see osint.ads). This is called from the Prj hierarchy and
453 -- the MLib hierarchy.
455 --------------------------
456 -- Obsolete Executables --
457 --------------------------
459 Executable_Obsolete : Boolean := False;
460 -- Executable_Obsolete is initially set to False for each executable,
461 -- and is set to True whenever one of the source of the executable is
462 -- compiled, or has already been compiled for another executable.
464 Max_Header : constant := 200;
465 -- This needs a proper comment, it used to say "arbitrary"
466 -- that's not an adequate comment ???
468 type Header_Num is range 1 .. Max_Header;
469 -- Header_Num for the hash table Obsoleted below
471 function Hash (F : File_Name_Type) return Header_Num;
472 -- Hash function for the hash table Obsoleted below
474 package Obsoleted is new System.HTable.Simple_HTable
475 (Header_Num => Header_Num,
478 Key => File_Name_Type,
481 -- A hash table to keep all files that have been compiled, to detect
482 -- if an executable is up to date or not.
484 procedure Enter_Into_Obsoleted (F : File_Name_Type);
485 -- Enter a file name, without directory information, into the hash table
488 function Is_In_Obsoleted (F : File_Name_Type) return Boolean;
489 -- Check if a file name, without directory information, has already been
490 -- entered into the hash table Obsoleted.
492 type Dependency is record
493 This : File_Name_Type;
494 Depends_On : File_Name_Type;
496 -- Components of table Dependencies below
498 package Dependencies is new Table.Table (
499 Table_Component_Type => Dependency,
500 Table_Index_Type => Integer,
501 Table_Low_Bound => 1,
503 Table_Increment => 100,
504 Table_Name => "Make.Dependencies");
505 -- A table to keep dependencies, to be able to decide if an executable
506 -- is obsolete. More explanation needed ???
508 -- procedure Add_Dependency (S : File_Name_Type; On : File_Name_Type);
509 -- -- Add one entry in table Dependencies
511 ----------------------------
512 -- Arguments and Switches --
513 ----------------------------
515 Arguments : Argument_List_Access;
516 -- Used to gather the arguments for invocation of the compiler
518 Last_Argument : Natural := 0;
519 -- Last index of arguments in Arguments above
521 Arguments_Collected : Boolean := False;
522 -- Set to True when the arguments for the next invocation of the compiler
523 -- have been collected.
525 Arguments_Project : Project_Id;
526 -- Project id, if any, of the source to be compiled
528 Arguments_Path_Name : Path_Name_Type;
529 -- Full path of the source to be compiled, when Arguments_Project is not
532 Dummy_Switch : constant String_Access := new String'("- ");
533 -- Used to initialized Prev_Switch in procedure Check
535 procedure Add_Arguments (Args : Argument_List);
536 -- Add arguments to global variable Arguments, increasing its size
537 -- if necessary and adjusting Last_Argument.
539 function Configuration_Pragmas_Switch
540 (For_Project : Project_Id) return Argument_List;
541 -- Return an argument list of one element, if there is a configuration
542 -- pragmas file to be specified for For_Project,
543 -- otherwise return an empty argument list.
549 procedure List_Depend;
550 -- Prints to standard output the list of object dependencies. This list
551 -- can be used directly in a Makefile. A call to Compile_Sources must
552 -- precede the call to List_Depend. Also because this routine uses the
553 -- ALI files that were originally loaded and scanned by Compile_Sources,
554 -- no additional ALI files should be scanned between the two calls (i.e.
555 -- between the call to Compile_Sources and List_Depend.)
557 procedure List_Bad_Compilations;
558 -- Prints out the list of all files for which the compilation failed
560 procedure Verbose_Msg
563 N2 : Name_Id := No_Name;
565 Prefix : String := " -> ";
566 Minimum_Verbosity : Verbosity_Level_Type := Opt.Low);
567 procedure Verbose_Msg
568 (N1 : File_Name_Type;
570 N2 : File_Name_Type := No_File;
572 Prefix : String := " -> ";
573 Minimum_Verbosity : Verbosity_Level_Type := Opt.Low);
574 -- If the verbose flag (Verbose_Mode) is set and the verbosity level is
575 -- at least equal to Minimum_Verbosity, then print Prefix to standard
576 -- output followed by N1 and S1. If N2 /= No_Name then N2 is printed after
577 -- S1. S2 is printed last. Both N1 and N2 are printed in quotation marks.
579 Usage_Needed : Boolean := True;
580 -- Flag used to make sure Makeusg is call at most once
583 -- Call Makeusg, if Usage_Needed is True.
584 -- Set Usage_Needed to False.
586 procedure Debug_Msg (S : String; N : Name_Id);
587 procedure Debug_Msg (S : String; N : File_Name_Type);
588 procedure Debug_Msg (S : String; N : Unit_Name_Type);
589 -- If Debug.Debug_Flag_W is set outputs string S followed by name N
591 procedure Recursive_Compute_Depth (Project : Project_Id);
592 -- Compute depth of Project and of the projects it depends on
594 -----------------------
595 -- Gnatmake Routines --
596 -----------------------
598 subtype Lib_Mark_Type is Byte;
599 -- Used in Mark_Directory
601 Ada_Lib_Dir : constant Lib_Mark_Type := 1;
602 -- Used to mark a directory as a GNAT lib dir
604 -- Note that the notion of GNAT lib dir is no longer used. The code related
605 -- to it has not been removed to give an idea on how to use the directory
606 -- prefix marking mechanism.
608 -- An Ada library directory is a directory containing ali and object files
609 -- but no source files for the bodies (the specs can be in the same or some
610 -- other directory). These directories are specified in the Gnatmake
611 -- command line with the switch "-Adir" (to specify the spec location -Idir
612 -- cab be used). Gnatmake skips the missing sources whose ali are in Ada
613 -- library directories. For an explanation of why Gnatmake behaves that
614 -- way, see the spec of Make.Compile_Sources. The directory lookup penalty
615 -- is incurred every single time this routine is called.
617 procedure Check_Steps;
618 -- Check what steps (Compile, Bind, Link) must be executed.
619 -- Set the step flags accordingly.
621 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean;
622 -- Get directory prefix of this file and get lib mark stored in name
623 -- table for this directory. Then check if an Ada lib mark has been set.
625 procedure Mark_Directory
627 Mark : Lib_Mark_Type;
628 On_Command_Line : Boolean);
629 -- Store the absolute path from Dir in name table and set lib mark as name
630 -- info to identify Ada libraries.
632 -- If Dir is a relative path, when On_Command_Line is True, it is relative
633 -- to the current working directory; when On_Command_Line is False, it is
634 -- relative to the project directory of the main project.
636 Output_Is_Object : Boolean := True;
637 -- Set to False when using a switch -S for the compiler
639 procedure Check_For_S_Switch;
640 -- Set Output_Is_Object to False when the -S switch is used for the
644 (Source_File : File_Name_Type;
645 Source_File_Name : String;
647 Naming : Naming_Data;
648 In_Package : Package_Id;
649 Allow_ALI : Boolean) return Variable_Value;
650 -- Return the switches for the source file in the specified package of a
651 -- project file. If the Source_File ends with a standard GNAT extension
652 -- (".ads" or ".adb"), try first the full name, then the name without the
653 -- extension, then, if Allow_ALI is True, the name with the extension
654 -- ".ali". If there is no switches for either names, try first Switches
655 -- (others) then the default switches for Ada. If all failed, return
656 -- No_Variable_Value.
658 function Is_In_Object_Directory
659 (Source_File : File_Name_Type;
660 Full_Lib_File : File_Name_Type) return Boolean;
661 -- Check if, when using a project file, the ALI file is in the project
662 -- directory of the ultimate extending project. If it is not, we ignore
663 -- the fact that this ALI file is read-only.
665 ----------------------------------------------------
666 -- Compiler, Binder & Linker Data and Subprograms --
667 ----------------------------------------------------
669 Gcc : String_Access := Program_Name ("gcc", "gnatmake");
670 Gnatbind : String_Access := Program_Name ("gnatbind", "gnatmake");
671 Gnatlink : String_Access := Program_Name ("gnatlink", "gnatmake");
672 -- Default compiler, binder, linker programs
674 Saved_Gcc : String_Access := null;
675 Saved_Gnatbind : String_Access := null;
676 Saved_Gnatlink : String_Access := null;
677 -- Given by the command line. Will be used, if non null
679 Gcc_Path : String_Access :=
680 GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
681 Gnatbind_Path : String_Access :=
682 GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
683 Gnatlink_Path : String_Access :=
684 GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
685 -- Path for compiler, binder, linker programs, defaulted now for gnatdist.
686 -- Changed later if overridden on command line.
688 Comp_Flag : constant String_Access := new String'("-c");
689 Output_Flag : constant String_Access := new String'("-o");
690 Ada_Flag_1 : constant String_Access := new String'("-x");
691 Ada_Flag_2 : constant String_Access := new String'("ada");
692 No_gnat_adc : constant String_Access := new String'("-gnatA");
693 GNAT_Flag : constant String_Access := new String'("-gnatpg");
694 Do_Not_Check_Flag : constant String_Access := new String'("-x");
696 Object_Suffix : constant String := Get_Target_Object_Suffix.all;
698 Syntax_Only : Boolean := False;
699 -- Set to True when compiling with -gnats
701 Display_Executed_Programs : Boolean := True;
702 -- Set to True if name of commands should be output on stderr (or on stdout
703 -- if the Commands_To_Stdout flag was set by use of the -eS switch).
705 Output_File_Name_Seen : Boolean := False;
706 -- Set to True after having scanned the file_name for
707 -- switch "-o file_name"
709 Object_Directory_Seen : Boolean := False;
710 -- Set to True after having scanned the object directory for
711 -- switch "-D obj_dir".
713 Object_Directory_Path : String_Access := null;
714 -- The path name of the object directory, set with switch -D
716 type Make_Program_Type is (None, Compiler, Binder, Linker);
718 Program_Args : Make_Program_Type := None;
719 -- Used to indicate if we are scanning gnatmake, gcc, gnatbind, or gnatbind
720 -- options within the gnatmake command line. Used in Scan_Make_Arg only,
721 -- but must be global since value preserved from one call to another.
723 Temporary_Config_File : Boolean := False;
724 -- Set to True when there is a temporary config file used for a project
725 -- file, to avoid displaying the -gnatec switch for a temporary file.
727 procedure Add_Switches
728 (The_Package : Package_Id;
731 Program : Make_Program_Type;
732 Unknown_Switches_To_The_Compiler : Boolean := True);
735 Program : Make_Program_Type;
736 Append_Switch : Boolean := True;
737 And_Save : Boolean := True);
740 Program : Make_Program_Type;
741 Append_Switch : Boolean := True;
742 And_Save : Boolean := True);
743 -- Make invokes one of three programs (the compiler, the binder or the
744 -- linker). For the sake of convenience, some program specific switches
745 -- can be passed directly on the gnatmake command line. This procedure
746 -- records these switches so that gnatmake can pass them to the right
747 -- program. S is the switch to be added at the end of the command line
748 -- for Program if Append_Switch is True. If Append_Switch is False S is
749 -- added at the beginning of the command line.
752 (Source_File : File_Name_Type;
754 Is_Main_Source : Boolean;
755 The_Args : Argument_List;
756 Lib_File : File_Name_Type;
759 O_File : out File_Name_Type;
760 O_Stamp : out Time_Stamp_Type);
761 -- Determines whether the library file Lib_File is up-to-date or not. The
762 -- full name (with path information) of the object file corresponding to
763 -- Lib_File is returned in O_File. Its time stamp is saved in O_Stamp.
764 -- ALI is the ALI_Id corresponding to Lib_File. If Lib_File in not
765 -- up-to-date, then the corresponding source file needs to be recompiled.
766 -- In this case ALI = No_ALI_Id.
768 procedure Check_Linker_Options
769 (E_Stamp : Time_Stamp_Type;
770 O_File : out File_Name_Type;
771 O_Stamp : out Time_Stamp_Type);
772 -- Checks all linker options for linker files that are newer
773 -- than E_Stamp. If such objects are found, the youngest object
774 -- is returned in O_File and its stamp in O_Stamp.
776 -- If no obsolete linker files were found, the first missing
777 -- linker file is returned in O_File and O_Stamp is empty.
778 -- Otherwise O_File is No_File.
780 procedure Collect_Arguments
781 (Source_File : File_Name_Type;
783 Is_Main_Source : Boolean;
784 Args : Argument_List);
785 -- Collect all arguments for a source to be compiled, including those
786 -- that come from a project file.
788 procedure Display (Program : String; Args : Argument_List);
789 -- Displays Program followed by the arguments in Args if variable
790 -- Display_Executed_Programs is set. The lower bound of Args must be 1.
792 procedure Report_Compilation_Failed;
793 -- Delete all temporary files and fail graciously
799 type Temp_Path_Names is array (Positive range <>) of Path_Name_Type;
800 type Temp_Path_Ptr is access Temp_Path_Names;
802 type Free_File_Indices is array (Positive range <>) of Positive;
803 type Free_Indices_Ptr is access Free_File_Indices;
805 type Project_Compilation_Data is record
806 Mapping_File_Names : Temp_Path_Ptr;
807 -- The name ids of the temporary mapping files used. This is indexed
808 -- on the maximum number of compilation processes we will be spawning
811 Last_Mapping_File_Names : Natural;
812 -- Index of the last mapping file created for this project
814 Free_Mapping_File_Indices : Free_Indices_Ptr;
815 -- Indices in Mapping_File_Names of the mapping file names that can be
816 -- reused for subsequent compilations.
818 Last_Free_Indices : Natural;
819 -- Number of mapping files that can be reused
821 -- Information necessary when compiling a project
823 type Project_Compilation_Access is access Project_Compilation_Data;
825 package Project_Compilation_Htable is new Simple_HTable
826 (Header_Num => Prj.Header_Num,
827 Element => Project_Compilation_Access,
833 Project_Compilation : Project_Compilation_Htable.Instance;
835 Gnatmake_Mapping_File : String_Access := null;
836 -- The path name of a mapping file specified by switch -C=
838 procedure Delete_Mapping_Files;
839 -- Delete all temporary mapping files. Called only in Delete_All_Temp_Files
840 -- which ensures that Debug_Flag_N is False.
842 procedure Init_Mapping_File
843 (Project : Project_Id;
844 Data : in out Project_Compilation_Data;
845 File_Index : in out Natural);
846 -- Create a new temporary mapping file, and fill it with the project file
847 -- mappings, when using project file(s). The out parameter File_Index is
848 -- the index to the name of the file in the array The_Mapping_File_Names.
850 procedure Delete_Temp_Config_Files;
851 -- Delete all temporary config files. Must not be called if Debug_Flag_N
854 procedure Delete_All_Temp_Files;
855 -- Delete all temp files (config files, mapping files, path files), unless
856 -- Debug_Flag_N is True (in which case all temp files are left for user
859 -------------------------------------------------
860 -- Subprogram declarations moved from the spec --
861 -------------------------------------------------
863 procedure Bind (ALI_File : File_Name_Type; Args : Argument_List);
864 -- Binds ALI_File. Args are the arguments to pass to the binder.
865 -- Args must have a lower bound of 1.
867 procedure Display_Commands (Display : Boolean := True);
868 -- The default behavior of Make commands (Compile_Sources, Bind, Link)
869 -- is to display them on stderr. This behavior can be changed repeatedly
870 -- by invoking this procedure.
872 -- If a compilation, bind or link failed one of the following 3 exceptions
873 -- is raised. These need to be handled by the calling routines.
875 procedure Compile_Sources
876 (Main_Source : File_Name_Type;
877 Args : Argument_List;
878 First_Compiled_File : out File_Name_Type;
879 Most_Recent_Obj_File : out File_Name_Type;
880 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
881 Main_Unit : out Boolean;
882 Compilation_Failures : out Natural;
883 Main_Index : Int := 0;
884 Check_Readonly_Files : Boolean := False;
885 Do_Not_Execute : Boolean := False;
886 Force_Compilations : Boolean := False;
887 Keep_Going : Boolean := False;
888 In_Place_Mode : Boolean := False;
889 Initialize_ALI_Data : Boolean := True;
890 Max_Process : Positive := 1);
891 -- Compile_Sources will recursively compile all the sources needed by
892 -- Main_Source. Before calling this routine make sure Namet has been
893 -- initialized. This routine can be called repeatedly with different
894 -- Main_Source file as long as all the source (-I flags), library
895 -- (-B flags) and ada library (-A flags) search paths between calls are
896 -- *exactly* the same. The default directory must also be the same.
898 -- Args contains the arguments to use during the compilations.
899 -- The lower bound of Args must be 1.
901 -- First_Compiled_File is set to the name of the first file that is
902 -- compiled or that needs to be compiled. This is set to No_Name if no
903 -- compilations were needed.
905 -- Most_Recent_Obj_File is set to the full name of the most recent
906 -- object file found when no compilations are needed, that is when
907 -- First_Compiled_File is set to No_Name. When First_Compiled_File
908 -- is set then Most_Recent_Obj_File is set to No_Name.
910 -- Most_Recent_Obj_Stamp is the time stamp of Most_Recent_Obj_File.
912 -- Main_Unit is set to True if Main_Source can be a main unit.
913 -- If Do_Not_Execute is False and First_Compiled_File /= No_Name
914 -- the value of Main_Unit is always False.
915 -- Is this used any more??? It is certainly not used by gnatmake???
917 -- Compilation_Failures is a count of compilation failures. This count
918 -- is used to extract compilation failure reports with Extract_Failure.
920 -- Main_Index, when not zero, is the index of the main unit in source
921 -- file Main_Source which is a multi-unit source.
922 -- Zero indicates that Main_Source is a single unit source file.
924 -- Check_Readonly_Files set it to True to compile source files
925 -- which library files are read-only. When compiling GNAT predefined
926 -- files the "-gnatg" flag is used.
928 -- Do_Not_Execute set it to True to find out the first source that
929 -- needs to be recompiled, but without recompiling it. This file is
930 -- saved in First_Compiled_File.
932 -- Force_Compilations forces all compilations no matter what but
933 -- recompiles read-only files only if Check_Readonly_Files
936 -- Keep_Going when True keep compiling even in the presence of
937 -- compilation errors.
939 -- In_Place_Mode when True save library/object files in their object
940 -- directory if they already exist; otherwise, in the source directory.
942 -- Initialize_ALI_Data set it to True when you want to initialize ALI
943 -- data-structures. This is what you should do most of the time.
944 -- (especially the first time around when you call this routine).
945 -- This parameter is set to False to preserve previously recorded
948 -- Max_Process is the maximum number of processes that should be spawned
949 -- to carry out compilations.
951 -- Flags in Package Opt Affecting Compile_Sources
952 -- -----------------------------------------------
954 -- Check_Object_Consistency set it to False to omit all consistency
955 -- checks between an .ali file and its corresponding object file.
956 -- When this flag is set to true, every time an .ali is read,
957 -- package Osint checks that the corresponding object file
958 -- exists and is more recent than the .ali.
960 -- Use of Name Table Info
961 -- ----------------------
963 -- All file names manipulated by Compile_Sources are entered into the
964 -- Names table. The Byte field of a source file is used to mark it.
966 -- Calling Compile_Sources Several Times
967 -- -------------------------------------
969 -- Upon return from Compile_Sources all the ALI data structures are left
970 -- intact for further browsing. HOWEVER upon entry to this routine ALI
971 -- data structures are re-initialized if parameter Initialize_ALI_Data
972 -- above is set to true. Typically this is what you want the first time
973 -- you call Compile_Sources. You should not load an ali file, call this
974 -- routine with flag Initialize_ALI_Data set to True and then expect
975 -- that ALI information to be around after the call. Note that the first
976 -- time you call Compile_Sources you better set Initialize_ALI_Data to
977 -- True unless you have called Initialize_ALI yourself.
979 -- Compile_Sources ALGORITHM : Compile_Sources (Main_Source)
980 -- -------------------------
982 -- 1. Insert Main_Source in a Queue (Q) and mark it.
984 -- 2. Let unit.adb be the file at the head of the Q. If unit.adb is
985 -- missing but its corresponding ali file is in an Ada library directory
986 -- (see below) then, remove unit.adb from the Q and goto step 4.
987 -- Otherwise, look at the files under the D (dependency) section of
988 -- unit.ali. If unit.ali does not exist or some of the time stamps do
989 -- not match, (re)compile unit.adb.
991 -- An Ada library directory is a directory containing Ada specs, ali
992 -- and object files but no source files for the bodies. An Ada library
993 -- directory is communicated to gnatmake by means of some switch so that
994 -- gnatmake can skip the sources whole ali are in that directory.
995 -- There are two reasons for skipping the sources in this case. Firstly,
996 -- Ada libraries typically come without full sources but binding and
997 -- linking against those libraries is still possible. Secondly, it would
998 -- be very wasteful for gnatmake to systematically check the consistency
999 -- of every external Ada library used in a program. The binder is
1000 -- already in charge of catching any potential inconsistencies.
1002 -- 3. Look into the W section of unit.ali and insert into the Q all
1003 -- unmarked source files. Mark all files newly inserted in the Q.
1004 -- Specifically, assuming that the W section looks like
1006 -- W types%s types.adb types.ali
1007 -- W unchecked_deallocation%s
1008 -- W xref_tab%s xref_tab.adb xref_tab.ali
1010 -- Then xref_tab.adb and types.adb are inserted in the Q if they are not
1012 -- Note that there is no file listed under W unchecked_deallocation%s
1013 -- so no generic body should ever be explicitly compiled (unless the
1014 -- Main_Source at the start was a generic body).
1016 -- 4. Repeat steps 2 and 3 above until the Q is empty
1018 -- Note that the above algorithm works because the units withed in
1019 -- subunits are transitively included in the W section (with section) of
1020 -- the main unit. Likewise the withed units in a generic body needed
1021 -- during a compilation are also transitively included in the W section
1022 -- of the originally compiled file.
1024 procedure Initialize;
1025 -- Performs default and package initialization. Therefore,
1026 -- Compile_Sources can be called by an external unit.
1029 (ALI_File : File_Name_Type;
1030 Args : Argument_List;
1031 Success : out Boolean);
1032 -- Links ALI_File. Args are the arguments to pass to the linker.
1033 -- Args must have a lower bound of 1. Success indicates if the link
1034 -- succeeded or not.
1036 procedure Scan_Make_Arg (Argv : String; And_Save : Boolean);
1037 -- Scan make arguments. Argv is a single argument to be processed
1043 procedure Add_Arguments (Args : Argument_List) is
1045 if Arguments = null then
1046 Arguments := new Argument_List (1 .. Args'Length + 10);
1049 while Last_Argument + Args'Length > Arguments'Last loop
1051 New_Arguments : constant Argument_List_Access :=
1052 new Argument_List (1 .. Arguments'Last * 2);
1054 New_Arguments (1 .. Last_Argument) :=
1055 Arguments (1 .. Last_Argument);
1056 Arguments := New_Arguments;
1061 Arguments (Last_Argument + 1 .. Last_Argument + Args'Length) := Args;
1062 Last_Argument := Last_Argument + Args'Length;
1065 -- --------------------
1066 -- -- Add_Dependency --
1067 -- --------------------
1069 -- procedure Add_Dependency (S : File_Name_Type; On : File_Name_Type) is
1071 -- Dependencies.Increment_Last;
1072 -- Dependencies.Table (Dependencies.Last) := (S, On);
1073 -- end Add_Dependency;
1075 ----------------------------
1076 -- Add_Library_Search_Dir --
1077 ----------------------------
1079 procedure Add_Library_Search_Dir
1081 On_Command_Line : Boolean)
1084 if On_Command_Line then
1085 Add_Lib_Search_Dir (Normalize_Pathname (Path));
1088 Get_Name_String (Main_Project.Directory.Display_Name);
1090 (Normalize_Pathname (Path, Name_Buffer (1 .. Name_Len)));
1092 end Add_Library_Search_Dir;
1094 --------------------
1095 -- Add_Object_Dir --
1096 --------------------
1098 procedure Add_Object_Dir (N : String) is
1100 Add_Lib_Search_Dir (N);
1102 if Verbose_Mode then
1103 Write_Str ("Adding object directory """);
1110 --------------------
1111 -- Add_Source_Dir --
1112 --------------------
1114 procedure Add_Source_Dir (N : String) is
1116 Add_Src_Search_Dir (N);
1118 if Verbose_Mode then
1119 Write_Str ("Adding source directory """);
1126 ---------------------------
1127 -- Add_Source_Search_Dir --
1128 ---------------------------
1130 procedure Add_Source_Search_Dir
1132 On_Command_Line : Boolean)
1135 if On_Command_Line then
1136 Add_Src_Search_Dir (Normalize_Pathname (Path));
1139 Get_Name_String (Main_Project.Directory.Display_Name);
1141 (Normalize_Pathname (Path, Name_Buffer (1 .. Name_Len)));
1143 end Add_Source_Search_Dir;
1149 procedure Add_Switch
1151 Program : Make_Program_Type;
1152 Append_Switch : Boolean := True;
1153 And_Save : Boolean := True)
1156 with package T is new Table.Table (<>);
1157 procedure Generic_Position (New_Position : out Integer);
1158 -- Generic procedure that chooses a position for S in T at the
1159 -- beginning or the end, depending on the boolean Append_Switch.
1160 -- Calling this procedure may expand the table.
1162 ----------------------
1163 -- Generic_Position --
1164 ----------------------
1166 procedure Generic_Position (New_Position : out Integer) is
1170 if Append_Switch then
1171 New_Position := Integer (T.Last);
1173 for J in reverse T.Table_Index_Type'Succ (T.First) .. T.Last loop
1174 T.Table (J) := T.Table (T.Table_Index_Type'Pred (J));
1177 New_Position := Integer (T.First);
1179 end Generic_Position;
1181 procedure Gcc_Switches_Pos is new Generic_Position (Gcc_Switches);
1182 procedure Binder_Switches_Pos is new Generic_Position (Binder_Switches);
1183 procedure Linker_Switches_Pos is new Generic_Position (Linker_Switches);
1185 procedure Saved_Gcc_Switches_Pos is new
1186 Generic_Position (Saved_Gcc_Switches);
1188 procedure Saved_Binder_Switches_Pos is new
1189 Generic_Position (Saved_Binder_Switches);
1191 procedure Saved_Linker_Switches_Pos is new
1192 Generic_Position (Saved_Linker_Switches);
1194 New_Position : Integer;
1196 -- Start of processing for Add_Switch
1202 Saved_Gcc_Switches_Pos (New_Position);
1203 Saved_Gcc_Switches.Table (New_Position) := S;
1206 Saved_Binder_Switches_Pos (New_Position);
1207 Saved_Binder_Switches.Table (New_Position) := S;
1210 Saved_Linker_Switches_Pos (New_Position);
1211 Saved_Linker_Switches.Table (New_Position) := S;
1214 raise Program_Error;
1220 Gcc_Switches_Pos (New_Position);
1221 Gcc_Switches.Table (New_Position) := S;
1224 Binder_Switches_Pos (New_Position);
1225 Binder_Switches.Table (New_Position) := S;
1228 Linker_Switches_Pos (New_Position);
1229 Linker_Switches.Table (New_Position) := S;
1232 raise Program_Error;
1237 procedure Add_Switch
1239 Program : Make_Program_Type;
1240 Append_Switch : Boolean := True;
1241 And_Save : Boolean := True)
1244 Add_Switch (S => new String'(S),
1246 Append_Switch => Append_Switch,
1247 And_Save => And_Save);
1254 procedure Add_Switches
1255 (The_Package : Package_Id;
1258 Program : Make_Program_Type;
1259 Unknown_Switches_To_The_Compiler : Boolean := True)
1261 Switches : Variable_Value;
1262 Switch_List : String_List_Id;
1263 Element : String_Element;
1266 Switch_May_Be_Passed_To_The_Compiler :=
1267 Unknown_Switches_To_The_Compiler;
1269 if File_Name'Length > 0 then
1271 Add_Str_To_Name_Buffer (File_Name);
1274 (Source_File => Name_Find,
1275 Source_File_Name => File_Name,
1276 Source_Index => Index,
1277 Naming => Main_Project.Naming,
1278 In_Package => The_Package,
1279 Allow_ALI => Program = Binder or else Program = Linker);
1281 if Switches.Kind = List then
1282 Program_Args := Program;
1284 Switch_List := Switches.Values;
1285 while Switch_List /= Nil_String loop
1286 Element := Project_Tree.String_Elements.Table (Switch_List);
1287 Get_Name_String (Element.Value);
1289 if Name_Len > 0 then
1291 Argv : constant String := Name_Buffer (1 .. Name_Len);
1292 -- We need a copy, because Name_Buffer may be modified
1295 if Verbose_Mode then
1296 Write_Str (" Adding ");
1300 Scan_Make_Arg (Argv, And_Save => False);
1302 if not Gnatmake_Switch_Found
1303 and then not Switch_May_Be_Passed_To_The_Compiler
1307 """ is not a gnatmake switch. Consider moving " &
1308 "it to Global_Compilation_Switches.",
1311 Make_Failed ("*** illegal switch """ & Argv & """");
1316 Switch_List := Element.Next;
1326 procedure Bind (ALI_File : File_Name_Type; Args : Argument_List) is
1327 Bind_Args : Argument_List (1 .. Args'Last + 2);
1328 Bind_Last : Integer;
1332 pragma Assert (Args'First = 1);
1334 -- Optimize the simple case where the gnatbind command line looks like
1335 -- gnatbind -aO. -I- file.ali --into-> gnatbind file.adb
1338 and then Args (Args'First).all = "-aO" & Normalized_CWD
1339 and then Args (Args'Last).all = "-I-"
1340 and then ALI_File = Strip_Directory (ALI_File)
1342 Bind_Last := Args'First - 1;
1345 Bind_Last := Args'Last;
1346 Bind_Args (Args'Range) := Args;
1349 -- It is completely pointless to re-check source file time stamps. This
1350 -- has been done already by gnatmake
1352 Bind_Last := Bind_Last + 1;
1353 Bind_Args (Bind_Last) := Do_Not_Check_Flag;
1355 Get_Name_String (ALI_File);
1357 Bind_Last := Bind_Last + 1;
1358 Bind_Args (Bind_Last) := new String'(Name_Buffer (1 .. Name_Len));
1360 GNAT.OS_Lib.Normalize_Arguments (Bind_Args (Args'First .. Bind_Last));
1362 Display (Gnatbind.all, Bind_Args (Args'First .. Bind_Last));
1364 if Gnatbind_Path = null then
1365 Make_Failed ("error, unable to locate " & Gnatbind.all);
1369 (Gnatbind_Path.all, Bind_Args (Args'First .. Bind_Last), Success);
1372 Make_Failed ("*** bind failed.");
1376 --------------------------------
1377 -- Change_To_Object_Directory --
1378 --------------------------------
1380 procedure Change_To_Object_Directory (Project : Project_Id) is
1381 Actual_Project : Project_Id;
1382 Object_Directory : Path_Name_Type;
1385 -- For sources outside of any project, compilation occurs in the object
1386 -- directory of the main project, otherwise we use the project given.
1388 if Project = No_Project then
1389 Actual_Project := Main_Project;
1391 Actual_Project := Project;
1394 -- Nothing to do if the current working directory is already the correct
1395 -- object directory.
1397 if Project_Of_Current_Object_Directory /= Actual_Project then
1398 Project_Of_Current_Object_Directory := Actual_Project;
1399 Object_Directory := Actual_Project.Object_Directory.Name;
1401 -- Set the working directory to the object directory of the actual
1404 if Verbose_Mode then
1405 Write_Str ("Changing to object directory of """);
1406 Write_Name (Actual_Project.Display_Name);
1407 Write_Str (""": """);
1408 Write_Name (Object_Directory);
1412 Change_Dir (Get_Name_String (Object_Directory));
1416 -- Fail if unable to change to the object directory
1418 when Directory_Error =>
1419 Make_Failed ("unable to change to object directory """ &
1421 (Actual_Project.Object_Directory.Name) &
1423 Get_Name_String (Actual_Project.Display_Name));
1424 end Change_To_Object_Directory;
1431 (Source_File : File_Name_Type;
1433 Is_Main_Source : Boolean;
1434 The_Args : Argument_List;
1435 Lib_File : File_Name_Type;
1436 Read_Only : Boolean;
1438 O_File : out File_Name_Type;
1439 O_Stamp : out Time_Stamp_Type)
1441 function File_Not_A_Source_Of
1443 Sfile : File_Name_Type) return Boolean;
1445 function First_New_Spec (A : ALI_Id) return File_Name_Type;
1446 -- Looks in the with table entries of A and returns the spec file name
1447 -- of the first withed unit (subprogram) for which no spec existed when
1448 -- A was generated but for which there exists one now, implying that A
1449 -- is now obsolete. If no such unit is found No_File is returned.
1450 -- Otherwise the spec file name of the unit is returned.
1452 -- **WARNING** in the event of Uname format modifications, one *MUST*
1453 -- make sure this function is also updated.
1455 -- Note: This function should really be in ali.adb and use Uname
1456 -- services, but this causes the whole compiler to be dragged along
1457 -- for gnatbind and gnatmake.
1459 --------------------------
1460 -- File_Not_A_Source_Of --
1461 --------------------------
1463 function File_Not_A_Source_Of
1465 Sfile : File_Name_Type) return Boolean
1467 UID : Prj.Unit_Index;
1471 UID := Units_Htable.Get (Project_Tree.Units_HT, Uname);
1473 if UID /= Prj.No_Unit_Index then
1474 U_Data := Project_Tree.Units.Table (UID);
1476 if U_Data.File_Names (Body_Part).Name /= Sfile
1477 and then U_Data.File_Names (Specification).Name /= Sfile
1479 Verbose_Msg (Uname, "sources do not include ", Name_Id (Sfile));
1485 end File_Not_A_Source_Of;
1487 --------------------
1488 -- First_New_Spec --
1489 --------------------
1491 function First_New_Spec (A : ALI_Id) return File_Name_Type is
1492 Spec_File_Name : File_Name_Type := No_File;
1494 function New_Spec (Uname : Unit_Name_Type) return Boolean;
1495 -- Uname is the name of the spec or body of some ada unit. This
1496 -- function returns True if the Uname is the name of a body which has
1497 -- a spec not mentioned in ALI file A. If True is returned
1498 -- Spec_File_Name above is set to the name of this spec file.
1504 function New_Spec (Uname : Unit_Name_Type) return Boolean is
1505 Spec_Name : Unit_Name_Type;
1506 File_Name : File_Name_Type;
1509 -- Test whether Uname is the name of a body unit (i.e. ends
1512 Get_Name_String (Uname);
1514 Assert (Name_Len > 2 and then Name_Buffer (Name_Len - 1) = '%');
1516 if Name_Buffer (Name_Len) /= 'b' then
1520 -- Convert unit name into spec name
1522 -- ??? this code seems dubious in presence of pragma
1523 -- Source_File_Name since there is no more direct relationship
1524 -- between unit name and file name.
1526 -- ??? Further, what about alternative subunit naming
1528 Name_Buffer (Name_Len) := 's';
1529 Spec_Name := Name_Find;
1530 File_Name := Get_File_Name (Spec_Name, Subunit => False);
1532 -- Look if File_Name is mentioned in A's sdep list.
1533 -- If not look if the file exists. If it does return True.
1536 ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep
1538 if Sdep.Table (D).Sfile = File_Name then
1543 if Full_Source_Name (File_Name) /= No_File then
1544 Spec_File_Name := File_Name;
1551 -- Start of processing for First_New_Spec
1555 ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit
1557 exit U_Chk when Units.Table (U).Utype = Is_Body_Only
1558 and then New_Spec (Units.Table (U).Uname);
1560 for W in Units.Table (U).First_With
1562 Units.Table (U).Last_With
1565 Withs.Table (W).Afile /= No_File
1566 and then New_Spec (Withs.Table (W).Uname);
1570 return Spec_File_Name;
1573 ---------------------------------
1574 -- Data declarations for Check --
1575 ---------------------------------
1577 Full_Lib_File : File_Name_Type;
1578 -- Full name of current library file
1580 Full_Obj_File : File_Name_Type;
1581 -- Full name of the object file corresponding to Lib_File
1583 Lib_Stamp : Time_Stamp_Type;
1584 -- Time stamp of the current ada library file
1586 Obj_Stamp : Time_Stamp_Type;
1587 -- Time stamp of the current object file
1589 Modified_Source : File_Name_Type;
1590 -- The first source in Lib_File whose current time stamp differs
1591 -- from that stored in Lib_File.
1593 New_Spec : File_Name_Type;
1594 -- If Lib_File contains in its W (with) section a body (for a
1595 -- subprogram) for which there exists a spec and the spec did not
1596 -- appear in the Sdep section of Lib_File, New_Spec contains the file
1597 -- name of this new spec.
1599 Source_Name : File_Name_Type;
1600 Text : Text_Buffer_Ptr;
1602 Prev_Switch : String_Access;
1603 -- Previous switch processed
1605 Arg : Arg_Id := Arg_Id'First;
1606 -- Current index in Args.Table for a given unit (init to stop warning)
1608 Switch_Found : Boolean;
1609 -- True if a given switch has been found
1611 ALI_Project : Project_Id;
1612 -- If the ALI file is in the object directory of a project, this is
1615 -- Start of processing for Check
1618 pragma Assert (Lib_File /= No_File);
1620 -- If ALI file is read-only, temporarily set Check_Object_Consistency to
1621 -- False. We don't care if the object file is not there (presumably a
1622 -- library will be used for linking.)
1626 Saved_Check_Object_Consistency : constant Boolean :=
1627 Check_Object_Consistency;
1629 Check_Object_Consistency := False;
1630 Text := Read_Library_Info (Lib_File);
1631 Check_Object_Consistency := Saved_Check_Object_Consistency;
1635 Text := Read_Library_Info (Lib_File);
1638 Full_Lib_File := Full_Library_Info_Name;
1639 Full_Obj_File := Full_Object_File_Name;
1640 Lib_Stamp := Current_Library_File_Stamp;
1641 Obj_Stamp := Current_Object_File_Stamp;
1643 if Full_Lib_File = No_File then
1646 "being checked ...",
1648 Minimum_Verbosity => Opt.Medium);
1652 "being checked ...",
1654 Minimum_Verbosity => Opt.Medium);
1658 O_File := Full_Obj_File;
1659 O_Stamp := Obj_Stamp;
1662 if Full_Lib_File = No_File then
1663 Verbose_Msg (Lib_File, "missing.");
1665 elsif Obj_Stamp (Obj_Stamp'First) = ' ' then
1666 Verbose_Msg (Full_Obj_File, "missing.");
1670 (Full_Lib_File, "(" & String (Lib_Stamp) & ") newer than",
1671 Full_Obj_File, "(" & String (Obj_Stamp) & ")");
1675 ALI := Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
1678 if ALI = No_ALI_Id then
1679 Verbose_Msg (Full_Lib_File, "incorrectly formatted ALI file");
1682 elsif ALIs.Table (ALI).Ver (1 .. ALIs.Table (ALI).Ver_Len) /=
1683 Verbose_Library_Version
1685 Verbose_Msg (Full_Lib_File, "compiled with old GNAT version");
1690 -- Don't take Ali file into account if it was generated with
1693 if ALIs.Table (ALI).Compile_Errors then
1694 Verbose_Msg (Full_Lib_File, "had errors, must be recompiled");
1699 -- Don't take Ali file into account if it was generated without
1702 if Operating_Mode /= Check_Semantics
1703 and then ALIs.Table (ALI).No_Object
1705 Verbose_Msg (Full_Lib_File, "has no corresponding object");
1710 -- Check for matching compiler switches if needed
1712 if Check_Switches then
1714 -- First, collect all the switches
1717 (Source_File, Source_Index, Is_Main_Source, The_Args);
1719 Prev_Switch := Dummy_Switch;
1721 Get_Name_String (ALIs.Table (ALI).Sfile);
1723 Switches_To_Check.Set_Last (0);
1725 for J in 1 .. Last_Argument loop
1727 -- Skip non switches -c, -I and -o switches
1729 if Arguments (J) (1) = '-'
1730 and then Arguments (J) (2) /= 'c'
1731 and then Arguments (J) (2) /= 'o'
1732 and then Arguments (J) (2) /= 'I'
1734 Normalize_Compiler_Switches
1736 Normalized_Switches,
1739 for K in 1 .. Last_Norm_Switch loop
1740 Switches_To_Check.Increment_Last;
1741 Switches_To_Check.Table (Switches_To_Check.Last) :=
1742 Normalized_Switches (K);
1747 for J in 1 .. Switches_To_Check.Last loop
1749 -- Comparing switches is delicate because gcc reorders a number
1750 -- of switches, according to lang-specs.h, but gnatmake doesn't
1751 -- have sufficient knowledge to perform the same reordering.
1752 -- Instead, we ignore orders between different "first letter"
1753 -- switches, but keep orders between same switches, e.g -O -O2
1754 -- is different than -O2 -O, but -g -O is equivalent to -O -g.
1756 if Switches_To_Check.Table (J) (2) /= Prev_Switch (2) or else
1757 (Prev_Switch'Length >= 6 and then
1758 Prev_Switch (2 .. 5) = "gnat" and then
1759 Switches_To_Check.Table (J)'Length >= 6 and then
1760 Switches_To_Check.Table (J) (2 .. 5) = "gnat" and then
1761 Prev_Switch (6) /= Switches_To_Check.Table (J) (6))
1763 Prev_Switch := Switches_To_Check.Table (J);
1765 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg;
1768 Switch_Found := False;
1771 Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1774 Switches_To_Check.Table (J).all = Args.Table (K).all
1777 Switch_Found := True;
1782 if not Switch_Found then
1783 if Verbose_Mode then
1784 Verbose_Msg (ALIs.Table (ALI).Sfile,
1785 "switch mismatch """ &
1786 Switches_To_Check.Table (J).all & '"');
1794 if Switches_To_Check.Last /=
1795 Integer (Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg -
1796 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg + 1)
1798 if Verbose_Mode then
1799 Verbose_Msg (ALIs.Table (ALI).Sfile,
1800 "different number of switches");
1802 for K in Units.Table (ALIs.Table (ALI).First_Unit).First_Arg
1803 .. Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1805 Write_Str (Args.Table (K).all);
1811 for J in 1 .. Switches_To_Check.Last loop
1812 Write_Str (Switches_To_Check.Table (J).all);
1824 -- Get the source files and their message digests. Note that some
1825 -- sources may be missing if ALI is out-of-date.
1827 Set_Source_Table (ALI);
1829 Modified_Source := Time_Stamp_Mismatch (ALI, Read_Only);
1831 if Modified_Source /= No_File then
1834 if Verbose_Mode then
1835 Source_Name := Full_Source_Name (Modified_Source);
1837 if Source_Name /= No_File then
1838 Verbose_Msg (Source_Name, "time stamp mismatch");
1840 Verbose_Msg (Modified_Source, "missing");
1845 New_Spec := First_New_Spec (ALI);
1847 if New_Spec /= No_File then
1850 if Verbose_Mode then
1851 Source_Name := Full_Source_Name (New_Spec);
1853 if Source_Name /= No_File then
1854 Verbose_Msg (Source_Name, "new spec");
1856 Verbose_Msg (New_Spec, "old spec missing");
1860 elsif not Read_Only and then Main_Project /= No_Project then
1862 -- Check if a file name does not correspond to the mapping of
1863 -- units to file names.
1868 Unit_Name : Name_Id;
1872 for U in ALIs.Table (ALI).First_Unit ..
1873 ALIs.Table (ALI).Last_Unit
1875 -- Check if the file name is one of the source of the
1878 Get_Name_String (Units.Table (U).Uname);
1879 Name_Len := Name_Len - 2;
1880 Unit_Name := Name_Find;
1882 if File_Not_A_Source_Of
1883 (Unit_Name, Units.Table (U).Sfile)
1889 -- Do the same check for each of the withed units
1892 for W in Units.Table (U).First_With
1894 Units.Table (U).Last_With
1896 WR := Withs.Table (W);
1898 if WR.Sfile /= No_File then
1899 Get_Name_String (WR.Uname);
1900 Name_Len := Name_Len - 2;
1901 Unit_Name := Name_Find;
1903 if File_Not_A_Source_Of (Unit_Name, WR.Sfile) then
1911 -- Check also the subunits
1914 for D in ALIs.Table (ALI).First_Sdep ..
1915 ALIs.Table (ALI).Last_Sdep
1917 SD := Sdep.Table (D);
1918 Unit_Name := SD.Subunit_Name;
1920 if Unit_Name /= No_Name then
1921 if File_Not_A_Source_Of (Unit_Name, SD.Sfile) then
1929 -- Check that the ALI file is in the correct object directory.
1930 -- If it is in the object directory of a project that is
1931 -- extended and it depends on a source that is in one of its
1932 -- extending projects, then the ALI file is not in the correct
1933 -- object directory.
1935 -- First, find the project of this ALI file. As there may be
1936 -- several projects with the same object directory, we first
1937 -- need to find the project of the source.
1939 ALI_Project := No_Project;
1942 Udata : Prj.Unit_Data;
1945 for U in 1 .. Unit_Table.Last (Project_Tree.Units) loop
1946 Udata := Project_Tree.Units.Table (U);
1948 if Udata.File_Names (Body_Part).Name = Source_File then
1949 ALI_Project := Udata.File_Names (Body_Part).Project;
1953 Udata.File_Names (Specification).Name = Source_File
1956 Udata.File_Names (Specification).Project;
1962 if ALI_Project = No_Project then
1967 Obj_Dir : Path_Name_Type;
1968 Res_Obj_Dir : constant String :=
1971 (Get_Name_String (Full_Lib_File)),
1972 Resolve_Links => True,
1973 Case_Sensitive => False);
1977 Add_Str_To_Name_Buffer (Res_Obj_Dir);
1979 if Name_Len > 1 and then
1980 (Name_Buffer (Name_Len) = '/'
1982 Name_Buffer (Name_Len) = Directory_Separator)
1984 Name_Len := Name_Len - 1;
1987 Obj_Dir := Name_Find;
1989 while ALI_Project /= No_Project
1990 and then Obj_Dir /= ALI_Project.Object_Directory.Name
1992 ALI_Project := ALI_Project.Extended_By;
1996 if ALI_Project = No_Project then
2000 (Lib_File, " wrong object directory");
2004 -- If the ALI project is not extended, then it must be in
2005 -- the correct object directory.
2007 if ALI_Project.Extended_By = No_Project then
2011 -- Count the extending projects
2019 Proj := ALI_Project;
2021 Proj := Proj.Extended_By;
2022 exit when Proj = No_Project;
2023 Num_Ext := Num_Ext + 1;
2026 -- Make a list of the extending projects
2029 Projects : array (1 .. Num_Ext) of Project_Id;
2031 OK : Boolean := True;
2034 Proj := ALI_Project;
2035 for J in Projects'Range loop
2036 Proj := Proj.Extended_By;
2037 Projects (J) := Proj;
2040 -- Now check if any of the dependant sources are in
2041 -- any of these extending projects.
2044 for D in ALIs.Table (ALI).First_Sdep ..
2045 ALIs.Table (ALI).Last_Sdep
2047 Dep := Sdep.Table (D);
2053 UID in 1 .. Unit_Table.Last (Project_Tree.Units)
2055 if Project_Tree.Units.Table (UID).
2056 File_Names (Body_Part).Name = Dep.Sfile
2058 Proj := Project_Tree.Units.Table (UID).
2059 File_Names (Body_Part).Project;
2061 elsif Project_Tree.Units.Table (UID).
2062 File_Names (Specification).Name = Dep.Sfile
2064 Proj := Project_Tree.Units.Table (UID).
2065 File_Names (Specification).Project;
2068 -- If a source is in a project, check if it is one
2071 if Proj /= No_Project then
2072 for J in Projects'Range loop
2073 if Proj = Projects (J) then
2084 -- If one of the dependent sources is in one project of
2085 -- the list, then we must recompile.
2089 Verbose_Msg (Lib_File, " wrong object directory");
2098 ------------------------
2099 -- Check_For_S_Switch --
2100 ------------------------
2102 procedure Check_For_S_Switch is
2104 -- By default, we generate an object file
2106 Output_Is_Object := True;
2108 for Arg in 1 .. Last_Argument loop
2109 if Arguments (Arg).all = "-S" then
2110 Output_Is_Object := False;
2112 elsif Arguments (Arg).all = "-c" then
2113 Output_Is_Object := True;
2116 end Check_For_S_Switch;
2118 --------------------------
2119 -- Check_Linker_Options --
2120 --------------------------
2122 procedure Check_Linker_Options
2123 (E_Stamp : Time_Stamp_Type;
2124 O_File : out File_Name_Type;
2125 O_Stamp : out Time_Stamp_Type)
2127 procedure Check_File (File : File_Name_Type);
2128 -- Update O_File and O_Stamp if the given file is younger than E_Stamp
2129 -- and O_Stamp, or if O_File is No_File and File does not exist.
2131 function Get_Library_File (Name : String) return File_Name_Type;
2132 -- Return the full file name including path of a library based
2133 -- on the name specified with the -l linker option, using the
2134 -- Ada object path. Return No_File if no such file can be found.
2136 type Char_Array is array (Natural) of Character;
2137 type Char_Array_Access is access constant Char_Array;
2139 Template : Char_Array_Access;
2140 pragma Import (C, Template, "__gnat_library_template");
2146 procedure Check_File (File : File_Name_Type) is
2147 Stamp : Time_Stamp_Type;
2148 Name : File_Name_Type := File;
2151 Get_Name_String (Name);
2153 -- Remove any trailing NUL characters
2155 while Name_Len >= Name_Buffer'First
2156 and then Name_Buffer (Name_Len) = NUL
2158 Name_Len := Name_Len - 1;
2161 if Name_Len = 0 then
2164 elsif Name_Buffer (1) = '-' then
2166 -- Do not check if File is a switch other than "-l"
2168 if Name_Buffer (2) /= 'l' then
2172 -- The argument is a library switch, get actual name. It
2173 -- is necessary to make a copy of the relevant part of
2174 -- Name_Buffer as Get_Library_Name uses Name_Buffer as well.
2177 Base_Name : constant String := Name_Buffer (3 .. Name_Len);
2180 Name := Get_Library_File (Base_Name);
2183 if Name = No_File then
2188 Stamp := File_Stamp (Name);
2190 -- Find the youngest object file that is younger than the
2191 -- executable. If no such file exist, record the first object
2192 -- file that is not found.
2194 if (O_Stamp < Stamp and then E_Stamp < Stamp)
2195 or else (O_File = No_File and then Stamp (Stamp'First) = ' ')
2200 -- Strip the trailing NUL if present
2202 Get_Name_String (O_File);
2204 if Name_Buffer (Name_Len) = NUL then
2205 Name_Len := Name_Len - 1;
2206 O_File := Name_Find;
2211 ----------------------
2212 -- Get_Library_Name --
2213 ----------------------
2215 -- See comments in a-adaint.c about template syntax
2217 function Get_Library_File (Name : String) return File_Name_Type is
2218 File : File_Name_Type := No_File;
2223 for Ptr in Template'Range loop
2224 case Template (Ptr) is
2226 Add_Str_To_Name_Buffer (Name);
2229 File := Full_Lib_File_Name (Name_Find);
2230 exit when File /= No_File;
2237 Add_Char_To_Name_Buffer (Template (Ptr));
2241 -- The for loop exited because the end of the template
2242 -- was reached. File contains the last possible file name
2245 if File = No_File and then Name_Len > 0 then
2246 File := Full_Lib_File_Name (Name_Find);
2250 end Get_Library_File;
2252 -- Start of processing for Check_Linker_Options
2256 O_Stamp := (others => ' ');
2258 -- Process linker options from the ALI files
2260 for Opt in 1 .. Linker_Options.Last loop
2261 Check_File (File_Name_Type (Linker_Options.Table (Opt).Name));
2264 -- Process options given on the command line
2266 for Opt in Linker_Switches.First .. Linker_Switches.Last loop
2268 -- Check if the previous Opt has one of the two switches
2269 -- that take an extra parameter. (See GCC manual.)
2271 if Opt = Linker_Switches.First
2272 or else (Linker_Switches.Table (Opt - 1).all /= "-u"
2274 Linker_Switches.Table (Opt - 1).all /= "-Xlinker"
2276 Linker_Switches.Table (Opt - 1).all /= "-L")
2279 Add_Str_To_Name_Buffer (Linker_Switches.Table (Opt).all);
2280 Check_File (Name_Find);
2284 end Check_Linker_Options;
2290 procedure Check_Steps is
2292 -- If either -c, -b or -l has been specified, we will not necessarily
2293 -- execute all steps.
2296 Do_Compile_Step := Do_Compile_Step and Compile_Only;
2297 Do_Bind_Step := Do_Bind_Step and Bind_Only;
2298 Do_Link_Step := Do_Link_Step and Link_Only;
2300 -- If -c has been specified, but not -b, ignore any potential -l
2302 if Do_Compile_Step and then not Do_Bind_Step then
2303 Do_Link_Step := False;
2308 -----------------------
2309 -- Collect_Arguments --
2310 -----------------------
2312 procedure Collect_Arguments
2313 (Source_File : File_Name_Type;
2315 Is_Main_Source : Boolean;
2316 Args : Argument_List)
2319 Arguments_Collected := True;
2320 Arguments_Project := No_Project;
2322 Add_Arguments (Args);
2324 if Main_Project /= No_Project then
2326 Source_File_Name : constant String :=
2327 Get_Name_String (Source_File);
2328 Compiler_Package : Prj.Package_Id;
2329 Switches : Prj.Variable_Value;
2334 (Source_File_Name => Source_File_Name,
2335 Project => Arguments_Project,
2336 Path => Arguments_Path_Name,
2337 In_Tree => Project_Tree);
2339 -- If the source is not a source of a project file, add the
2340 -- recorded arguments. Check will be done later if the source
2341 -- need to be compiled that the switch -x has been used.
2343 if Arguments_Project = No_Project then
2344 Add_Arguments (The_Saved_Gcc_Switches.all);
2346 elsif not Arguments_Project.Externally_Built then
2347 -- We get the project directory for the relative path
2348 -- switches and arguments.
2350 Arguments_Project := Ultimate_Extending_Project_Of
2351 (Arguments_Project);
2353 -- If building a dynamic or relocatable library, compile with
2354 -- PIC option, if it exists.
2356 if Arguments_Project.Library
2357 and then Arguments_Project.Library_Kind /= Static
2360 PIC : constant String := MLib.Tgt.PIC_Option;
2364 Add_Arguments ((1 => new String'(PIC)));
2369 -- We now look for package Compiler and get the switches from
2374 (Name => Name_Compiler,
2375 In_Packages => Arguments_Project.Decl.Packages,
2376 In_Tree => Project_Tree);
2378 if Compiler_Package /= No_Package then
2380 -- If package Gnatmake.Compiler exists, we get the specific
2381 -- switches for the current source, or the global switches,
2386 (Source_File => Source_File,
2387 Source_File_Name => Source_File_Name,
2388 Source_Index => Source_Index,
2389 Naming => Arguments_Project.Naming,
2390 In_Package => Compiler_Package,
2391 Allow_ALI => False);
2395 case Switches.Kind is
2397 -- We have a list of switches. We add these switches,
2398 -- plus the saved gcc switches.
2403 Current : String_List_Id := Switches.Values;
2404 Element : String_Element;
2405 Number : Natural := 0;
2408 while Current /= Nil_String loop
2409 Element := Project_Tree.String_Elements.
2411 Number := Number + 1;
2412 Current := Element.Next;
2416 New_Args : Argument_List (1 .. Number);
2417 Last_New : Natural := 0;
2418 Dir_Path : constant String := Get_Name_String
2419 (Arguments_Project.Directory.Name);
2422 Current := Switches.Values;
2424 for Index in New_Args'Range loop
2425 Element := Project_Tree.String_Elements.
2427 Get_Name_String (Element.Value);
2429 if Name_Len > 0 then
2430 Last_New := Last_New + 1;
2431 New_Args (Last_New) :=
2432 new String'(Name_Buffer (1 .. Name_Len));
2433 Test_If_Relative_Path
2434 (New_Args (Last_New),
2436 Including_Non_Switch => False);
2439 Current := Element.Next;
2443 (Configuration_Pragmas_Switch
2444 (Arguments_Project) &
2445 New_Args (1 .. Last_New) &
2446 The_Saved_Gcc_Switches.all);
2450 -- We have a single switch. We add this switch,
2451 -- plus the saved gcc switches.
2454 Get_Name_String (Switches.Value);
2457 New_Args : Argument_List :=
2459 (Name_Buffer (1 .. Name_Len)));
2460 Dir_Path : constant String :=
2462 (Arguments_Project.Directory.Name);
2465 Test_If_Relative_Path
2468 Including_Non_Switch => False);
2470 (Configuration_Pragmas_Switch (Arguments_Project) &
2471 New_Args & The_Saved_Gcc_Switches.all);
2474 -- We have no switches from Gnatmake.Compiler.
2475 -- We add the saved gcc switches.
2479 (Configuration_Pragmas_Switch (Arguments_Project) &
2480 The_Saved_Gcc_Switches.all);
2486 -- For VMS, when compiling the main source, add switch
2487 -- -mdebug-main=_ada_ so that the executable can be debugged
2488 -- by the standard VMS debugger.
2490 if not No_Main_Subprogram
2491 and then Targparm.OpenVMS_On_Target
2492 and then Is_Main_Source
2494 -- First, check if compilation will be invoked with -g
2496 for J in 1 .. Last_Argument loop
2497 if Arguments (J)'Length >= 2
2498 and then Arguments (J) (1 .. 2) = "-g"
2499 and then (Arguments (J)'Length < 5
2500 or else Arguments (J) (1 .. 5) /= "-gnat")
2503 ((1 => new String'("-mdebug-main=_ada_")));
2509 -- Set Output_Is_Object, depending if there is a -S switch.
2510 -- If the bind step is not performed, and there is a -S switch,
2511 -- then we will not check for a valid object file.
2514 end Collect_Arguments;
2516 ---------------------
2517 -- Compile_Sources --
2518 ---------------------
2520 procedure Compile_Sources
2521 (Main_Source : File_Name_Type;
2522 Args : Argument_List;
2523 First_Compiled_File : out File_Name_Type;
2524 Most_Recent_Obj_File : out File_Name_Type;
2525 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
2526 Main_Unit : out Boolean;
2527 Compilation_Failures : out Natural;
2528 Main_Index : Int := 0;
2529 Check_Readonly_Files : Boolean := False;
2530 Do_Not_Execute : Boolean := False;
2531 Force_Compilations : Boolean := False;
2532 Keep_Going : Boolean := False;
2533 In_Place_Mode : Boolean := False;
2534 Initialize_ALI_Data : Boolean := True;
2535 Max_Process : Positive := 1)
2537 Source_Unit : Unit_Name_Type;
2538 -- Current source unit
2540 Source_File : File_Name_Type;
2541 -- Current source file
2543 Full_Source_File : File_Name_Type;
2544 -- Full name of the current source file
2546 Lib_File : File_Name_Type;
2547 -- Current library file
2549 Full_Lib_File : File_Name_Type;
2550 -- Full name of the current library file
2552 Obj_File : File_Name_Type;
2553 -- Full name of the object file corresponding to Lib_File
2555 Obj_Stamp : Time_Stamp_Type;
2556 -- Time stamp of the current object file
2558 Sfile : File_Name_Type;
2559 -- Contains the source file of the units withed by Source_File
2561 Uname : Unit_Name_Type;
2562 -- Contains the unit name of the units withed by Source_File
2565 -- ALI Id of the current ALI file
2567 -- Comment following declarations ???
2569 Read_Only : Boolean := False;
2571 Compilation_OK : Boolean;
2572 Need_To_Compile : Boolean;
2575 Text : Text_Buffer_Ptr;
2577 Mfile : Natural := No_Mapping_File;
2579 Need_To_Check_Standard_Library : Boolean :=
2580 Check_Readonly_Files
2581 and not Unique_Compile;
2583 Mapping_File_Arg : String_Access;
2585 Process_Created : Boolean := False;
2587 procedure Add_Process
2589 Sfile : File_Name_Type;
2590 Afile : File_Name_Type;
2591 Uname : Unit_Name_Type;
2592 Mfile : Natural := No_Mapping_File);
2593 -- Adds process Pid to the current list of outstanding compilation
2594 -- processes and record the full name of the source file Sfile that
2595 -- we are compiling, the name of its library file Afile and the
2596 -- name of its unit Uname. If Mfile is not equal to No_Mapping_File,
2597 -- it is the index of the mapping file used during compilation in the
2598 -- array The_Mapping_File_Names.
2600 procedure Await_Compile
2601 (Sfile : out File_Name_Type;
2602 Afile : out File_Name_Type;
2603 Uname : out Unit_Name_Type;
2605 -- Awaits that an outstanding compilation process terminates. When
2606 -- it does set Sfile to the name of the source file that was compiled
2607 -- Afile to the name of its library file and Uname to the name of its
2608 -- unit. Note that this time stamp can be used to check whether the
2609 -- compilation did generate an object file. OK is set to True if the
2610 -- compilation succeeded. Note that Sfile, Afile and Uname could be
2611 -- resp. No_File, No_File and No_Name if there were no compilations
2614 function Bad_Compilation_Count return Natural;
2615 -- Returns the number of compilation failures
2617 procedure Check_Standard_Library;
2618 -- Check if s-stalib.adb needs to be compiled
2620 procedure Collect_Arguments_And_Compile
2621 (Source_File : File_Name_Type;
2622 Source_Index : Int);
2623 -- Collect arguments from project file (if any) and compile
2626 (S : File_Name_Type;
2629 Args : Argument_List) return Process_Id;
2630 -- Compiles S using Args. If S is a GNAT predefined source "-gnatpg" is
2631 -- added to Args. Non blocking call. L corresponds to the expected
2632 -- library file name. Process_Id of the process spawned to execute the
2635 package Good_ALI is new Table.Table (
2636 Table_Component_Type => ALI_Id,
2637 Table_Index_Type => Natural,
2638 Table_Low_Bound => 1,
2639 Table_Initial => 50,
2640 Table_Increment => 100,
2641 Table_Name => "Make.Good_ALI");
2642 -- Contains the set of valid ALI files that have not yet been scanned
2644 function Good_ALI_Present return Boolean;
2645 -- Returns True if any ALI file was recorded in the previous set
2647 procedure Get_Mapping_File (Project : Project_Id);
2648 -- Get a mapping file name. If there is one to be reused, reuse it.
2649 -- Otherwise, create a new mapping file.
2651 function Get_Next_Good_ALI return ALI_Id;
2652 -- Returns the next good ALI_Id record
2654 procedure Record_Failure
2655 (File : File_Name_Type;
2656 Unit : Unit_Name_Type;
2657 Found : Boolean := True);
2658 -- Records in the previous table that the compilation for File failed.
2659 -- If Found is False then the compilation of File failed because we
2660 -- could not find it. Records also Unit when possible.
2662 procedure Record_Good_ALI (A : ALI_Id);
2663 -- Records in the previous set the Id of an ALI file
2669 procedure Add_Process
2671 Sfile : File_Name_Type;
2672 Afile : File_Name_Type;
2673 Uname : Unit_Name_Type;
2674 Mfile : Natural := No_Mapping_File)
2676 OC1 : constant Positive := Outstanding_Compiles + 1;
2679 pragma Assert (OC1 <= Max_Process);
2680 pragma Assert (Pid /= Invalid_Pid);
2682 Running_Compile (OC1).Pid := Pid;
2683 Running_Compile (OC1).Full_Source_File := Sfile;
2684 Running_Compile (OC1).Lib_File := Afile;
2685 Running_Compile (OC1).Source_Unit := Uname;
2686 Running_Compile (OC1).Mapping_File := Mfile;
2687 Running_Compile (OC1).Project := Arguments_Project;
2688 Running_Compile (OC1).Syntax_Only := Syntax_Only;
2689 Running_Compile (OC1).Output_Is_Object := Output_Is_Object;
2691 Outstanding_Compiles := OC1;
2694 --------------------
2698 procedure Await_Compile
2699 (Sfile : out File_Name_Type;
2700 Afile : out File_Name_Type;
2701 Uname : out Unit_Name_Type;
2705 Project : Project_Id;
2706 Data : Project_Compilation_Access;
2709 pragma Assert (Outstanding_Compiles > 0);
2713 Uname := No_Unit_Name;
2716 -- The loop here is a work-around for a problem on VMS; in some
2717 -- circumstances (shared library and several executables, for
2718 -- example), there are child processes other than compilation
2719 -- processes that are received. Until this problem is resolved,
2720 -- we will ignore such processes.
2723 Wait_Process (Pid, OK);
2725 if Pid = Invalid_Pid then
2729 for J in Running_Compile'First .. Outstanding_Compiles loop
2730 if Pid = Running_Compile (J).Pid then
2731 Sfile := Running_Compile (J).Full_Source_File;
2732 Afile := Running_Compile (J).Lib_File;
2733 Uname := Running_Compile (J).Source_Unit;
2734 Syntax_Only := Running_Compile (J).Syntax_Only;
2735 Output_Is_Object := Running_Compile (J).Output_Is_Object;
2736 Project := Running_Compile (J).Project;
2738 -- If a mapping file was used by this compilation,
2739 -- get its file name for reuse by a subsequent compilation
2741 if Running_Compile (J).Mapping_File /= No_Mapping_File then
2742 Data := Project_Compilation_Htable.Get
2743 (Project_Compilation, Project);
2744 Data.Last_Free_Indices := Data.Last_Free_Indices + 1;
2745 Data.Free_Mapping_File_Indices (Data.Last_Free_Indices) :=
2746 Running_Compile (J).Mapping_File;
2749 -- To actually remove this Pid and related info from
2750 -- Running_Compile replace its entry with the last valid
2751 -- entry in Running_Compile.
2753 if J = Outstanding_Compiles then
2757 Running_Compile (J) :=
2758 Running_Compile (Outstanding_Compiles);
2761 Outstanding_Compiles := Outstanding_Compiles - 1;
2766 -- This child process was not one of our compilation processes;
2767 -- just ignore it for now.
2769 -- raise Program_Error;
2773 ---------------------------
2774 -- Bad_Compilation_Count --
2775 ---------------------------
2777 function Bad_Compilation_Count return Natural is
2779 return Bad_Compilation.Last - Bad_Compilation.First + 1;
2780 end Bad_Compilation_Count;
2782 ----------------------------
2783 -- Check_Standard_Library --
2784 ----------------------------
2786 procedure Check_Standard_Library is
2788 Need_To_Check_Standard_Library := False;
2790 if not Targparm.Suppress_Standard_Library_On_Target then
2792 Sfile : File_Name_Type;
2793 Add_It : Boolean := True;
2797 Add_Str_To_Name_Buffer (Standard_Library_Package_Body_Name);
2798 Sfile := Name_Enter;
2800 -- If we have a special runtime, we add the standard
2801 -- library only if we can find it.
2805 Find_File (Sfile, Osint.Source) /= No_File;
2809 if Is_Marked (Sfile) then
2810 if Is_In_Obsoleted (Sfile) then
2811 Executable_Obsolete := True;
2815 Insert_Q (Sfile, Index => 0);
2816 Mark (Sfile, Index => 0);
2821 end Check_Standard_Library;
2823 -----------------------------------
2824 -- Collect_Arguments_And_Compile --
2825 -----------------------------------
2827 procedure Collect_Arguments_And_Compile
2828 (Source_File : File_Name_Type;
2832 -- Process_Created will be set True if an attempt is made to compile
2833 -- the source, that is if it is not in an externally built project.
2835 Process_Created := False;
2837 -- If arguments not yet collected (in Check), collect them now
2839 if not Arguments_Collected then
2841 (Source_File, Source_Index, Source_File = Main_Source, Args);
2844 -- If we use mapping file (-P or -C switches), then get one
2846 if Create_Mapping_File then
2847 Get_Mapping_File (Arguments_Project);
2850 -- If the source is part of a project file, we set the ADA_*_PATHs,
2851 -- check for an eventual library project, and use the full path.
2853 if Arguments_Project /= No_Project then
2854 if not Arguments_Project.Externally_Built then
2855 Prj.Env.Set_Ada_Paths
2858 Including_Libraries => True);
2860 if not Unique_Compile
2861 and then MLib.Tgt.Support_For_Libraries /= Prj.None
2864 Prj : constant Project_Id :=
2865 Ultimate_Extending_Project_Of (Arguments_Project);
2869 and then not Prj.Externally_Built
2870 and then not Prj.Need_To_Build_Lib
2872 -- Add to the Q all sources of the project that have
2875 Insert_Project_Sources
2876 (The_Project => Prj,
2877 All_Projects => False,
2880 -- Now mark the project as processed
2882 Prj.Need_To_Build_Lib := True;
2887 -- Change to object directory of the project file, if necessary
2889 Change_To_Object_Directory (Arguments_Project);
2893 (File_Name_Type (Arguments_Path_Name),
2896 Arguments (1 .. Last_Argument));
2897 Process_Created := True;
2901 -- If this is a source outside of any project file, make sure it
2902 -- will be compiled in object directory of the main project file.
2904 if Main_Project /= No_Project then
2905 Change_To_Object_Directory (Arguments_Project);
2908 Pid := Compile (Full_Source_File, Lib_File, Source_Index,
2909 Arguments (1 .. Last_Argument));
2910 Process_Created := True;
2912 end Collect_Arguments_And_Compile;
2919 (S : File_Name_Type;
2922 Args : Argument_List) return Process_Id
2924 Comp_Args : Argument_List (Args'First .. Args'Last + 10);
2925 Comp_Next : Integer := Args'First;
2926 Comp_Last : Integer;
2927 Arg_Index : Integer;
2929 function Ada_File_Name (Name : File_Name_Type) return Boolean;
2930 -- Returns True if Name is the name of an ada source file
2931 -- (i.e. suffix is .ads or .adb)
2937 function Ada_File_Name (Name : File_Name_Type) return Boolean is
2939 Get_Name_String (Name);
2942 and then Name_Buffer (Name_Len - 3 .. Name_Len - 1) = ".ad"
2943 and then (Name_Buffer (Name_Len) = 'b'
2945 Name_Buffer (Name_Len) = 's');
2948 -- Start of processing for Compile
2951 Enter_Into_Obsoleted (S);
2953 -- By default, Syntax_Only is False
2955 Syntax_Only := False;
2957 for J in Args'Range loop
2958 if Args (J).all = "-gnats" then
2960 -- If we compile with -gnats, the bind step and the link step
2961 -- are inhibited. Also, we set Syntax_Only to True, so that
2962 -- we don't fail when we don't find the ALI file, after
2965 Do_Bind_Step := False;
2966 Do_Link_Step := False;
2967 Syntax_Only := True;
2969 elsif Args (J).all = "-gnatc" then
2971 -- If we compile with -gnatc, the bind step and the link step
2972 -- are inhibited. We set Syntax_Only to False for the case when
2973 -- -gnats was previously specified.
2975 Do_Bind_Step := False;
2976 Do_Link_Step := False;
2977 Syntax_Only := False;
2981 Comp_Args (Comp_Next) := new String'("-gnatea");
2982 Comp_Next := Comp_Next + 1;
2984 Comp_Args (Comp_Next) := Comp_Flag;
2985 Comp_Next := Comp_Next + 1;
2987 -- Optimize the simple case where the gcc command line looks like
2988 -- gcc -c -I. ... -I- file.adb --into-> gcc -c ... file.adb
2990 if Args (Args'First).all = "-I" & Normalized_CWD
2991 and then Args (Args'Last).all = "-I-"
2992 and then S = Strip_Directory (S)
2994 Comp_Last := Comp_Next + Args'Length - 3;
2995 Arg_Index := Args'First + 1;
2998 Comp_Last := Comp_Next + Args'Length - 1;
2999 Arg_Index := Args'First;
3002 -- Make a deep copy of the arguments, because Normalize_Arguments
3003 -- may deallocate some arguments.
3005 for J in Comp_Next .. Comp_Last loop
3006 Comp_Args (J) := new String'(Args (Arg_Index).all);
3007 Arg_Index := Arg_Index + 1;
3010 -- Set -gnatpg for predefined files (for this purpose the renamings
3011 -- such as Text_IO do not count as predefined). Note that we strip
3012 -- the directory name from the source file name because the call to
3013 -- Fname.Is_Predefined_File_Name cannot deal with directory prefixes.
3016 Fname : constant File_Name_Type := Strip_Directory (S);
3019 if Is_Predefined_File_Name (Fname, False) then
3020 if Check_Readonly_Files then
3021 Comp_Args (Comp_Args'First + 2 .. Comp_Last + 1) :=
3022 Comp_Args (Comp_Args'First + 1 .. Comp_Last);
3023 Comp_Last := Comp_Last + 1;
3024 Comp_Args (Comp_Args'First + 1) := GNAT_Flag;
3028 ("not allowed to compile """ &
3029 Get_Name_String (Fname) &
3030 """; use -a switch, or compile file with " &
3031 """-gnatg"" switch");
3036 -- Now check if the file name has one of the suffixes familiar to
3037 -- the gcc driver. If this is not the case then add the ada flag
3040 if not Ada_File_Name (S) and then not Targparm.AAMP_On_Target then
3041 Comp_Last := Comp_Last + 1;
3042 Comp_Args (Comp_Last) := Ada_Flag_1;
3043 Comp_Last := Comp_Last + 1;
3044 Comp_Args (Comp_Last) := Ada_Flag_2;
3047 if Source_Index /= 0 then
3049 Num : constant String := Source_Index'Img;
3051 Comp_Last := Comp_Last + 1;
3052 Comp_Args (Comp_Last) :=
3053 new String'("-gnateI" & Num (Num'First + 1 .. Num'Last));
3057 if Source_Index /= 0
3058 or else L /= Strip_Directory (L)
3059 or else Object_Directory_Path /= null
3061 -- Build -o argument
3063 Get_Name_String (L);
3065 for J in reverse 1 .. Name_Len loop
3066 if Name_Buffer (J) = '.' then
3067 Name_Len := J + Object_Suffix'Length - 1;
3068 Name_Buffer (J .. Name_Len) := Object_Suffix;
3073 Comp_Last := Comp_Last + 1;
3074 Comp_Args (Comp_Last) := Output_Flag;
3075 Comp_Last := Comp_Last + 1;
3077 -- If an object directory was specified, prepend the object file
3078 -- name with this object directory.
3080 if Object_Directory_Path /= null then
3081 Comp_Args (Comp_Last) :=
3082 new String'(Object_Directory_Path.all &
3083 Name_Buffer (1 .. Name_Len));
3086 Comp_Args (Comp_Last) :=
3087 new String'(Name_Buffer (1 .. Name_Len));
3091 if Create_Mapping_File then
3092 Comp_Last := Comp_Last + 1;
3093 Comp_Args (Comp_Last) := Mapping_File_Arg;
3096 Get_Name_String (S);
3098 Comp_Last := Comp_Last + 1;
3099 Comp_Args (Comp_Last) := new String'(Name_Buffer (1 .. Name_Len));
3101 GNAT.OS_Lib.Normalize_Arguments (Comp_Args (Args'First .. Comp_Last));
3103 Comp_Last := Comp_Last + 1;
3104 Comp_Args (Comp_Last) := new String'("-gnatez");
3106 Display (Gcc.all, Comp_Args (Args'First .. Comp_Last));
3108 if Gcc_Path = null then
3109 Make_Failed ("error, unable to locate " & Gcc.all);
3113 GNAT.OS_Lib.Non_Blocking_Spawn
3114 (Gcc_Path.all, Comp_Args (Args'First .. Comp_Last));
3117 ----------------------
3118 -- Get_Mapping_File --
3119 ----------------------
3121 procedure Get_Mapping_File (Project : Project_Id) is
3122 Data : Project_Compilation_Access;
3125 Data := Project_Compilation_Htable.Get (Project_Compilation, Project);
3127 -- If there is a mapping file ready to be reused, reuse it
3129 if Data.Last_Free_Indices > 0 then
3130 Mfile := Data.Free_Mapping_File_Indices (Data.Last_Free_Indices);
3131 Data.Last_Free_Indices := Data.Last_Free_Indices - 1;
3133 -- Otherwise, create and initialize a new one
3137 (Project => Project, Data => Data.all, File_Index => Mfile);
3140 -- Put the name in the mapping file argument for the invocation
3143 Free (Mapping_File_Arg);
3145 new String'("-gnatem=" &
3146 Get_Name_String (Data.Mapping_File_Names (Mfile)));
3147 end Get_Mapping_File;
3149 -----------------------
3150 -- Get_Next_Good_ALI --
3151 -----------------------
3153 function Get_Next_Good_ALI return ALI_Id is
3157 pragma Assert (Good_ALI_Present);
3158 ALI := Good_ALI.Table (Good_ALI.Last);
3159 Good_ALI.Decrement_Last;
3161 end Get_Next_Good_ALI;
3163 ----------------------
3164 -- Good_ALI_Present --
3165 ----------------------
3167 function Good_ALI_Present return Boolean is
3169 return Good_ALI.First <= Good_ALI.Last;
3170 end Good_ALI_Present;
3172 --------------------
3173 -- Record_Failure --
3174 --------------------
3176 procedure Record_Failure
3177 (File : File_Name_Type;
3178 Unit : Unit_Name_Type;
3179 Found : Boolean := True)
3182 Bad_Compilation.Increment_Last;
3183 Bad_Compilation.Table (Bad_Compilation.Last) := (File, Unit, Found);
3186 ---------------------
3187 -- Record_Good_ALI --
3188 ---------------------
3190 procedure Record_Good_ALI (A : ALI_Id) is
3192 Good_ALI.Increment_Last;
3193 Good_ALI.Table (Good_ALI.Last) := A;
3194 end Record_Good_ALI;
3196 -- Start of processing for Compile_Sources
3199 pragma Assert (Args'First = 1);
3201 Outstanding_Compiles := 0;
3202 Running_Compile := new Comp_Data_Arr (1 .. Max_Process);
3204 -- Package and Queue initializations
3208 if First_Q_Initialization then
3212 if Initialize_ALI_Data then
3214 Initialize_ALI_Source;
3217 -- The following two flags affect the behavior of ALI.Set_Source_Table.
3218 -- We set Check_Source_Files to True to ensure that source file
3219 -- time stamps are checked, and we set All_Sources to False to
3220 -- avoid checking the presence of the source files listed in the
3221 -- source dependency section of an ali file (which would be a mistake
3222 -- since the ali file may be obsolete).
3224 Check_Source_Files := True;
3225 All_Sources := False;
3227 -- Only insert in the Q if it is not already done, to avoid simultaneous
3228 -- compilations if -jnnn is used.
3230 if not Is_Marked (Main_Source, Main_Index) then
3231 Insert_Q (Main_Source, Index => Main_Index);
3232 Mark (Main_Source, Main_Index);
3235 First_Compiled_File := No_File;
3236 Most_Recent_Obj_File := No_File;
3237 Most_Recent_Obj_Stamp := Empty_Time_Stamp;
3240 -- Keep looping until there is no more work to do (the Q is empty)
3241 -- and all the outstanding compilations have terminated
3243 Make_Loop : while not Empty_Q or else Outstanding_Compiles > 0 loop
3245 -- If the user does not want to keep going in case of errors then
3246 -- wait for the remaining outstanding compiles and then exit.
3248 if Bad_Compilation_Count > 0 and then not Keep_Going then
3249 while Outstanding_Compiles > 0 loop
3251 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
3253 if not Compilation_OK then
3254 Record_Failure (Full_Source_File, Source_Unit);
3261 -- PHASE 1: Check if there is more work that we can do (i.e. the Q
3262 -- is non empty). If there is, do it only if we have not yet used
3263 -- up all the available processes.
3265 if not Empty_Q and then Outstanding_Compiles < Max_Process then
3268 -- Index of the current unit in the current source file
3271 Extract_From_Q (Source_File, Source_Unit, Source_Index);
3272 Full_Source_File := Osint.Full_Source_Name (Source_File);
3273 Lib_File := Osint.Lib_File_Name
3274 (Source_File, Source_Index);
3275 Full_Lib_File := Osint.Full_Lib_File_Name (Lib_File);
3277 -- If this source has already been compiled, the executable is
3280 if Is_In_Obsoleted (Source_File) then
3281 Executable_Obsolete := True;
3284 -- If the library file is an Ada library skip it
3286 if Full_Lib_File /= No_File
3287 and then In_Ada_Lib_Dir (Full_Lib_File)
3291 "is in an Ada library",
3293 Minimum_Verbosity => Opt.High);
3295 -- If the library file is a read-only library skip it, but
3296 -- only if, when using project files, this library file is
3297 -- in the right object directory (a read-only ALI file
3298 -- in the object directory of a project being extended
3299 -- should not be skipped).
3301 elsif Full_Lib_File /= No_File
3302 and then not Check_Readonly_Files
3303 and then Is_Readonly_Library (Full_Lib_File)
3304 and then Is_In_Object_Directory (Source_File, Full_Lib_File)
3308 "is a read-only library",
3310 Minimum_Verbosity => Opt.High);
3312 -- The source file that we are checking cannot be located
3314 elsif Full_Source_File = No_File then
3315 Record_Failure (Source_File, Source_Unit, False);
3317 -- Source and library files can be located but are internal
3320 elsif not Check_Readonly_Files
3321 and then Full_Lib_File /= No_File
3322 and then Is_Internal_File_Name (Source_File, False)
3324 if Force_Compilations then
3326 ("not allowed to compile """ &
3327 Get_Name_String (Source_File) &
3328 """; use -a switch, or compile file with " &
3329 """-gnatg"" switch");
3334 "is an internal library",
3336 Minimum_Verbosity => Opt.High);
3338 -- The source file that we are checking can be located
3341 Arguments_Collected := False;
3343 Collect_Arguments (Source_File, Source_Index,
3344 Source_File = Main_Source, Args);
3346 -- Do nothing if project of source is externally built
3348 if Arguments_Project = No_Project
3349 or else not Arguments_Project.Externally_Built
3351 -- Don't waste any time if we have to recompile anyway
3353 Obj_Stamp := Empty_Time_Stamp;
3354 Need_To_Compile := Force_Compilations;
3356 if not Force_Compilations then
3358 Full_Lib_File /= No_File
3359 and then not Check_Readonly_Files
3360 and then Is_Readonly_Library (Full_Lib_File);
3361 Check (Source_File, Source_Index,
3362 Source_File = Main_Source, Args, Lib_File,
3363 Read_Only, ALI, Obj_File, Obj_Stamp);
3364 Need_To_Compile := (ALI = No_ALI_Id);
3367 if not Need_To_Compile then
3368 -- The ALI file is up-to-date. Record its Id
3370 Record_Good_ALI (ALI);
3372 -- Record the time stamp of the most recent object
3373 -- file as long as no (re)compilations are needed.
3375 if First_Compiled_File = No_File
3376 and then (Most_Recent_Obj_File = No_File
3377 or else Obj_Stamp > Most_Recent_Obj_Stamp)
3379 Most_Recent_Obj_File := Obj_File;
3380 Most_Recent_Obj_Stamp := Obj_Stamp;
3384 -- Check that switch -x has been used if a source
3385 -- outside of project files need to be compiled.
3387 if Main_Project /= No_Project
3388 and then Arguments_Project = No_Project
3389 and then not External_Unit_Compilation_Allowed
3391 Make_Failed ("external source ("
3392 & Get_Name_String (Source_File)
3393 & ") is not part of any project;"
3394 & " cannot be compiled without"
3395 & " gnatmake switch -x");
3398 -- Is this the first file we have to compile?
3400 if First_Compiled_File = No_File then
3401 First_Compiled_File := Full_Source_File;
3402 Most_Recent_Obj_File := No_File;
3404 if Do_Not_Execute then
3409 if In_Place_Mode then
3411 -- If the library file was not found, then save
3412 -- the library file near the source file.
3414 if Full_Lib_File = No_File then
3415 Lib_File := Osint.Lib_File_Name
3416 (Full_Source_File, Source_Index);
3418 -- If the library file was found, then save the
3419 -- library file in the same place.
3422 Lib_File := Full_Lib_File;
3427 -- Start the compilation and record it. We can do
3428 -- this because there is at least one free process.
3430 Collect_Arguments_And_Compile
3431 (Source_File, Source_Index);
3433 -- Make sure we could successfully start
3436 if Process_Created then
3437 if Pid = Invalid_Pid then
3438 Record_Failure (Full_Source_File, Source_Unit);
3454 -- PHASE 2: Now check if we should wait for a compilation to
3455 -- finish. This is the case if all the available processes are
3456 -- busy compiling sources or there is nothing else to do
3457 -- (that is the Q is empty and there are no good ALIs to process).
3459 if Outstanding_Compiles = Max_Process
3461 and then not Good_ALI_Present
3462 and then Outstanding_Compiles > 0)
3465 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
3467 if not Compilation_OK then
3468 Record_Failure (Full_Source_File, Source_Unit);
3471 if Compilation_OK or else Keep_Going then
3473 -- Re-read the updated library file
3476 Saved_Object_Consistency : constant Boolean :=
3477 Check_Object_Consistency;
3480 -- If compilation was not OK, or if output is not an
3481 -- object file and we don't do the bind step, don't check
3482 -- for object consistency.
3484 Check_Object_Consistency :=
3485 Check_Object_Consistency
3487 and (Output_Is_Object or Do_Bind_Step);
3488 Text := Read_Library_Info (Lib_File);
3490 -- Restore Check_Object_Consistency to its initial value
3492 Check_Object_Consistency := Saved_Object_Consistency;
3495 -- If an ALI file was generated by this compilation, scan
3496 -- the ALI file and record it.
3498 -- If the scan fails, a previous ali file is inconsistent with
3499 -- the unit just compiled.
3501 if Text /= null then
3503 Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
3505 if ALI = No_ALI_Id then
3507 -- Record a failure only if not already done
3509 if Compilation_OK then
3512 "incompatible ALI file, please recompile");
3513 Record_Failure (Full_Source_File, Source_Unit);
3517 Record_Good_ALI (ALI);
3520 -- If we could not read the ALI file that was just generated
3521 -- then there could be a problem reading either the ALI or the
3522 -- corresponding object file (if Check_Object_Consistency is
3523 -- set Read_Library_Info checks that the time stamp of the
3524 -- object file is more recent than that of the ALI). However,
3525 -- we record a failure only if not already done.
3528 if Compilation_OK and not Syntax_Only then
3531 "WARNING: ALI or object file not found after compile");
3532 Record_Failure (Full_Source_File, Source_Unit);
3538 -- PHASE 3: Check if we recorded good ALI files. If yes process
3539 -- them now in the order in which they have been recorded. There
3540 -- are two occasions in which we record good ali files. The first is
3541 -- in phase 1 when, after scanning an existing ALI file we realize
3542 -- it is up-to-date, the second instance is after a successful
3545 while Good_ALI_Present loop
3546 ALI := Get_Next_Good_ALI;
3549 Source_Index : Int := Unit_Index_Of (ALIs.Table (ALI).Afile);
3552 -- If we are processing the library file corresponding to the
3553 -- main source file check if this source can be a main unit.
3555 if ALIs.Table (ALI).Sfile = Main_Source and then
3556 Source_Index = Main_Index
3558 Main_Unit := ALIs.Table (ALI).Main_Program /= None;
3561 -- The following adds the standard library (s-stalib) to the
3562 -- list of files to be handled by gnatmake: this file and any
3563 -- files it depends on are always included in every bind,
3564 -- even if they are not in the explicit dependency list.
3565 -- Of course, it is not added if Suppress_Standard_Library
3568 -- However, to avoid annoying output about s-stalib.ali being
3569 -- read only, when "-v" is used, we add the standard library
3570 -- only when "-a" is used.
3572 if Need_To_Check_Standard_Library then
3573 Check_Standard_Library;
3576 -- Now insert in the Q the unmarked source files (i.e. those
3577 -- which have never been inserted in the Q and hence never
3578 -- considered). Only do that if Unique_Compile is False.
3580 if not Unique_Compile then
3582 ALIs.Table (ALI).First_Unit .. ALIs.Table (ALI).Last_Unit
3585 Units.Table (J).First_With .. Units.Table (J).Last_With
3587 Sfile := Withs.Table (K).Sfile;
3588 Uname := Withs.Table (K).Uname;
3590 -- If project files are used, find the proper source
3591 -- to compile, in case Sfile is the spec, but there
3594 if Main_Project /= No_Project then
3596 Unit_Name : Name_Id;
3597 Uid : Prj.Unit_Index;
3601 Get_Name_String (Uname);
3602 Name_Len := Name_Len - 2;
3603 Unit_Name := Name_Find;
3606 (Project_Tree.Units_HT, Unit_Name);
3608 if Uid /= Prj.No_Unit_Index then
3609 Udata := Project_Tree.Units.Table (Uid);
3612 Udata.File_Names (Body_Part).Name /=
3615 Udata.File_Names (Body_Part).Path.Name /=
3618 Sfile := Udata.File_Names (Body_Part).Name;
3620 Udata.File_Names (Body_Part).Index;
3623 Udata.File_Names (Specification).Name /=
3627 (Specification).Path.Name /= Slash
3630 Udata.File_Names (Specification).Name;
3632 Udata.File_Names (Specification).Index;
3638 Dependencies.Append ((ALIs.Table (ALI).Sfile, Sfile));
3640 if Is_In_Obsoleted (Sfile) then
3641 Executable_Obsolete := True;
3644 if Sfile = No_File then
3646 ("Skipping generic:", Withs.Table (K).Uname);
3650 Unit_Index_Of (Withs.Table (K).Afile);
3652 if Is_Marked (Sfile, Source_Index) then
3653 Debug_Msg ("Skipping marked file:", Sfile);
3655 elsif not Check_Readonly_Files
3656 and then Is_Internal_File_Name (Sfile, False)
3658 Debug_Msg ("Skipping internal file:", Sfile);
3662 (Sfile, Withs.Table (K).Uname, Source_Index);
3663 Mark (Sfile, Source_Index);
3672 if Display_Compilation_Progress then
3673 Write_Str ("completed ");
3674 Write_Int (Int (Q_Front));
3675 Write_Str (" out of ");
3676 Write_Int (Int (Q.Last));
3678 Write_Int (Int ((Q_Front * 100) / (Q.Last - Q.First)));
3679 Write_Str ("%)...");
3684 Compilation_Failures := Bad_Compilation_Count;
3686 -- Compilation is finished
3688 -- Delete any temporary configuration pragma file
3690 if not Debug.Debug_Flag_N then
3691 Delete_Temp_Config_Files;
3693 end Compile_Sources;
3695 ----------------------------------
3696 -- Configuration_Pragmas_Switch --
3697 ----------------------------------
3699 function Configuration_Pragmas_Switch
3700 (For_Project : Project_Id) return Argument_List
3702 The_Packages : Package_Id;
3703 Gnatmake : Package_Id;
3704 Compiler : Package_Id;
3706 Global_Attribute : Variable_Value := Nil_Variable_Value;
3707 Local_Attribute : Variable_Value := Nil_Variable_Value;
3709 Global_Attribute_Present : Boolean := False;
3710 Local_Attribute_Present : Boolean := False;
3712 Result : Argument_List (1 .. 3);
3713 Last : Natural := 0;
3715 function Absolute_Path
3716 (Path : Path_Name_Type;
3717 Project : Project_Id) return String;
3718 -- Returns an absolute path for a configuration pragmas file
3724 function Absolute_Path
3725 (Path : Path_Name_Type;
3726 Project : Project_Id) return String
3729 Get_Name_String (Path);
3732 Path_Name : constant String := Name_Buffer (1 .. Name_Len);
3735 if Is_Absolute_Path (Path_Name) then
3740 Parent_Directory : constant String :=
3741 Get_Name_String (Project.Directory.Display_Name);
3744 if Parent_Directory (Parent_Directory'Last) =
3747 return Parent_Directory & Path_Name;
3750 return Parent_Directory & Directory_Separator & Path_Name;
3757 -- Start of processing for Configuration_Pragmas_Switch
3760 Prj.Env.Create_Config_Pragmas_File
3761 (For_Project, Main_Project, Project_Tree);
3763 if For_Project.Config_File_Name /= No_Path then
3764 Temporary_Config_File := For_Project.Config_File_Temp;
3768 ("-gnatec=" & Get_Name_String (For_Project.Config_File_Name));
3771 Temporary_Config_File := False;
3774 -- Check for attribute Builder'Global_Configuration_Pragmas
3776 The_Packages := Main_Project.Decl.Packages;
3779 (Name => Name_Builder,
3780 In_Packages => The_Packages,
3781 In_Tree => Project_Tree);
3783 if Gnatmake /= No_Package then
3784 Global_Attribute := Prj.Util.Value_Of
3785 (Variable_Name => Name_Global_Configuration_Pragmas,
3786 In_Variables => Project_Tree.Packages.Table
3787 (Gnatmake).Decl.Attributes,
3788 In_Tree => Project_Tree);
3789 Global_Attribute_Present :=
3790 Global_Attribute /= Nil_Variable_Value
3791 and then Get_Name_String (Global_Attribute.Value) /= "";
3793 if Global_Attribute_Present then
3795 Path : constant String :=
3797 (Path_Name_Type (Global_Attribute.Value),
3798 Global_Attribute.Project);
3800 if not Is_Regular_File (Path) then
3801 if Debug.Debug_Flag_F then
3803 ("cannot find configuration pragmas file "
3804 & File_Name (Path));
3807 ("cannot find configuration pragmas file " & Path);
3812 Result (Last) := new String'("-gnatec=" & Path);
3817 -- Check for attribute Compiler'Local_Configuration_Pragmas
3819 The_Packages := For_Project.Decl.Packages;
3822 (Name => Name_Compiler,
3823 In_Packages => The_Packages,
3824 In_Tree => Project_Tree);
3826 if Compiler /= No_Package then
3827 Local_Attribute := Prj.Util.Value_Of
3828 (Variable_Name => Name_Local_Configuration_Pragmas,
3829 In_Variables => Project_Tree.Packages.Table
3830 (Compiler).Decl.Attributes,
3831 In_Tree => Project_Tree);
3832 Local_Attribute_Present :=
3833 Local_Attribute /= Nil_Variable_Value
3834 and then Get_Name_String (Local_Attribute.Value) /= "";
3836 if Local_Attribute_Present then
3838 Path : constant String :=
3840 (Path_Name_Type (Local_Attribute.Value),
3841 Local_Attribute.Project);
3843 if not Is_Regular_File (Path) then
3844 if Debug.Debug_Flag_F then
3846 ("cannot find configuration pragmas file "
3847 & File_Name (Path));
3851 ("cannot find configuration pragmas file " & Path);
3856 Result (Last) := new String'("-gnatec=" & Path);
3861 return Result (1 .. Last);
3862 end Configuration_Pragmas_Switch;
3868 procedure Debug_Msg (S : String; N : Name_Id) is
3870 if Debug.Debug_Flag_W then
3871 Write_Str (" ... ");
3879 procedure Debug_Msg (S : String; N : File_Name_Type) is
3881 Debug_Msg (S, Name_Id (N));
3884 procedure Debug_Msg (S : String; N : Unit_Name_Type) is
3886 Debug_Msg (S, Name_Id (N));
3889 ---------------------------
3890 -- Delete_All_Temp_Files --
3891 ---------------------------
3893 procedure Delete_All_Temp_Files is
3895 if not Debug.Debug_Flag_N then
3896 Delete_Mapping_Files;
3897 Delete_Temp_Config_Files;
3898 Prj.Env.Delete_All_Path_Files (Project_Tree);
3900 end Delete_All_Temp_Files;
3902 --------------------------
3903 -- Delete_Mapping_Files --
3904 --------------------------
3906 procedure Delete_Mapping_Files is
3908 pragma Warnings (Off, Success);
3910 Proj : Project_List;
3911 Data : Project_Compilation_Access;
3914 -- The caller is responsible for ensuring that Debug_Flag_N is False
3916 pragma Assert (not Debug.Debug_Flag_N);
3918 Proj := Project_Tree.Projects;
3919 while Proj /= null loop
3920 Data := Project_Compilation_Htable.Get
3921 (Project_Compilation, Proj.Project);
3923 if Data /= null and then Data.Mapping_File_Names /= null then
3924 for Index in 1 .. Data.Last_Mapping_File_Names loop
3926 (Name => Get_Name_String (Data.Mapping_File_Names (Index)),
3927 Success => Success);
3933 end Delete_Mapping_Files;
3935 ------------------------------
3936 -- Delete_Temp_Config_Files --
3937 ------------------------------
3939 procedure Delete_Temp_Config_Files is
3941 Proj : Project_List;
3942 pragma Warnings (Off, Success);
3945 -- The caller is responsible for ensuring that Debug_Flag_N is False
3947 pragma Assert (not Debug.Debug_Flag_N);
3949 if Main_Project /= No_Project then
3950 Proj := Project_Tree.Projects;
3951 while Proj /= null loop
3952 if Proj.Project.Config_File_Temp then
3953 if Verbose_Mode then
3954 Write_Str ("Deleting temp configuration file """);
3955 Write_Str (Get_Name_String (Proj.Project.Config_File_Name));
3960 (Name => Get_Name_String (Proj.Project.Config_File_Name),
3961 Success => Success);
3963 -- Make sure that we don't have a config file for this project,
3964 -- in case there are several mains. In this case, we will
3965 -- recreate another config file: we cannot reuse the one that
3968 Proj.Project.Config_Checked := False;
3969 Proj.Project.Config_File_Name := No_Path;
3970 Proj.Project.Config_File_Temp := False;
3975 end Delete_Temp_Config_Files;
3981 procedure Display (Program : String; Args : Argument_List) is
3983 pragma Assert (Args'First = 1);
3985 if Display_Executed_Programs then
3986 Write_Str (Program);
3988 for J in Args'Range loop
3990 -- Never display -gnatea nor -gnatez
3992 if Args (J).all /= "-gnatea"
3994 Args (J).all /= "-gnatez"
3996 -- Do not display the mapping file argument automatically
3997 -- created when using a project file.
3999 if Main_Project = No_Project
4000 or else Debug.Debug_Flag_N
4001 or else Args (J)'Length < 8
4003 Args (J) (Args (J)'First .. Args (J)'First + 6) /= "-gnatem"
4005 -- When -dn is not specified, do not display the config
4006 -- pragmas switch (-gnatec) for the temporary file created
4007 -- by the project manager (always the first -gnatec switch).
4008 -- Reset Temporary_Config_File to False so that the eventual
4009 -- other -gnatec switches will be displayed.
4011 if (not Debug.Debug_Flag_N)
4012 and then Temporary_Config_File
4013 and then Args (J)'Length > 7
4014 and then Args (J) (Args (J)'First .. Args (J)'First + 6)
4017 Temporary_Config_File := False;
4019 -- Do not display the -F=mapping_file switch for
4020 -- gnatbind, if -dn is not specified.
4022 elsif Debug.Debug_Flag_N
4023 or else Args (J)'Length < 4
4025 Args (J) (Args (J)'First .. Args (J)'First + 2) /= "-F="
4029 -- If -df is used, only display file names, not path
4032 if Debug.Debug_Flag_F then
4034 Equal_Pos : Natural;
4036 Equal_Pos := Args (J)'First - 1;
4037 for K in Args (J)'Range loop
4038 if Args (J) (K) = '=' then
4045 (Args (J) (Equal_Pos + 1 .. Args (J)'Last))
4048 (Args (J) (Args (J)'First .. Equal_Pos));
4052 (Equal_Pos + 1 .. Args (J)'Last)));
4055 Write_Str (Args (J).all);
4060 Write_Str (Args (J).all);
4071 ----------------------
4072 -- Display_Commands --
4073 ----------------------
4075 procedure Display_Commands (Display : Boolean := True) is
4077 Display_Executed_Programs := Display;
4078 end Display_Commands;
4084 function Empty_Q return Boolean is
4086 if Debug.Debug_Flag_P then
4087 Write_Str (" Q := [");
4089 for J in Q_Front .. Q.Last - 1 loop
4091 Write_Name (Q.Table (J).File);
4100 return Q_Front >= Q.Last;
4103 --------------------------
4104 -- Enter_Into_Obsoleted --
4105 --------------------------
4107 procedure Enter_Into_Obsoleted (F : File_Name_Type) is
4108 Name : constant String := Get_Name_String (F);
4110 F2 : File_Name_Type;
4114 while First > Name'First
4115 and then Name (First - 1) /= Directory_Separator
4116 and then Name (First - 1) /= '/'
4121 if First /= Name'First then
4123 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
4130 Debug_Msg ("New entry in Obsoleted table:", F2);
4131 Obsoleted.Set (F2, True);
4132 end Enter_Into_Obsoleted;
4134 --------------------
4135 -- Extract_From_Q --
4136 --------------------
4138 procedure Extract_From_Q
4139 (Source_File : out File_Name_Type;
4140 Source_Unit : out Unit_Name_Type;
4141 Source_Index : out Int)
4143 File : constant File_Name_Type := Q.Table (Q_Front).File;
4144 Unit : constant Unit_Name_Type := Q.Table (Q_Front).Unit;
4145 Index : constant Int := Q.Table (Q_Front).Index;
4148 if Debug.Debug_Flag_Q then
4149 Write_Str (" Q := Q - [ ");
4161 Q_Front := Q_Front + 1;
4162 Source_File := File;
4163 Source_Unit := Unit;
4164 Source_Index := Index;
4171 procedure Gnatmake is
4172 Main_Source_File : File_Name_Type;
4173 -- The source file containing the main compilation unit
4175 Compilation_Failures : Natural;
4177 Total_Compilation_Failures : Natural := 0;
4179 Is_Main_Unit : Boolean;
4180 -- Set to True by Compile_Sources if the Main_Source_File can be a
4183 Main_ALI_File : File_Name_Type;
4184 -- The ali file corresponding to Main_Source_File
4186 Executable : File_Name_Type := No_File;
4187 -- The file name of an executable
4189 Non_Std_Executable : Boolean := False;
4190 -- Non_Std_Executable is set to True when there is a possibility
4191 -- that the linker will not choose the correct executable file name.
4193 Current_Work_Dir : constant String_Access :=
4194 new String'(Get_Current_Dir);
4195 -- The current working directory, used to modify some relative path
4196 -- switches on the command line when a project file is used.
4198 Current_Main_Index : Int := 0;
4199 -- If not zero, the index of the current main unit in its source file
4201 Stand_Alone_Libraries : Boolean := False;
4202 -- Set to True when there are Stand-Alone Libraries, so that gnatbind
4203 -- is invoked with the -F switch to force checking of elaboration flags.
4205 Mapping_Path : Path_Name_Type := No_Path;
4206 -- The path name of the mapping file
4209 pragma Warnings (Off, Discard);
4211 procedure Check_Mains;
4212 -- Check that the main subprograms do exist and that they all
4213 -- belong to the same project file.
4215 procedure Create_Binder_Mapping_File
4216 (Args : in out Argument_List; Last_Arg : in out Natural);
4217 -- Create a binder mapping file and add the necessary switch
4223 procedure Check_Mains is
4224 Real_Main_Project : Project_Id := No_Project;
4225 -- The project of the first main
4227 Proj : Project_Id := No_Project;
4228 -- The project of the current main
4230 Real_Path : String_Access;
4239 Main : constant String := Mains.Next_Main;
4240 -- The name specified on the command line may include
4241 -- directory information.
4243 File_Name : constant String := Base_Name (Main);
4244 -- The simple file name of the current main
4247 exit when Main = "";
4249 -- Get the project of the current main
4251 Proj := Prj.Env.Project_Of
4252 (File_Name, Main_Project, Project_Tree);
4254 -- Fail if the current main is not a source of a
4257 if Proj = No_Project then
4259 ("""" & Main & """ is not a source of any project");
4262 -- If there is directory information, check that
4263 -- the source exists and, if it does, that the path
4264 -- is the actual path of a source of a project.
4266 if Main /= File_Name then
4271 (Project_Tree, "ada", Main_Project.Naming),
4273 if Real_Path = null then
4278 (Project_Tree, "ada", Main_Project.Naming),
4282 if Real_Path = null then
4283 Real_Path := Locate_Regular_File (Main, "");
4286 -- Fail if the file cannot be found
4288 if Real_Path = null then
4289 Make_Failed ("file """ & Main & """ does not exist");
4293 Project_Path : constant String :=
4294 Prj.Env.File_Name_Of_Library_Unit_Body
4296 Project => Main_Project,
4297 In_Tree => Project_Tree,
4298 Main_Project_Only => False,
4300 Normed_Path : constant String :=
4303 Case_Sensitive => False);
4304 Proj_Path : constant String :=
4307 Case_Sensitive => False);
4312 -- Fail if it is not the correct path
4314 if Normed_Path /= Proj_Path then
4315 if Verbose_Mode then
4317 Write_Str (Normed_Path);
4319 Write_Line (Proj_Path);
4324 """ is not a source of any project");
4329 if not Unique_Compile then
4331 -- Record the project, if it is the first main
4333 if Real_Main_Project = No_Project then
4334 Real_Main_Project := Proj;
4336 elsif Proj /= Real_Main_Project then
4338 -- Fail, as the current main is not a source
4339 -- of the same project as the first main.
4343 """ is not a source of project " &
4344 Get_Name_String (Real_Main_Project.Name));
4349 -- If -u and -U are not used, we may have mains that
4350 -- are sources of a project that is not the one
4351 -- specified with switch -P.
4353 if not Unique_Compile then
4354 Main_Project := Real_Main_Project;
4360 --------------------------------
4361 -- Create_Binder_Mapping_File --
4362 --------------------------------
4364 procedure Create_Binder_Mapping_File
4365 (Args : in out Argument_List; Last_Arg : in out Natural)
4367 Mapping_FD : File_Descriptor := Invalid_FD;
4368 -- A File Descriptor for an eventual mapping file
4370 ALI_Unit : Unit_Name_Type := No_Unit_Name;
4371 -- The unit name of an ALI file
4373 ALI_Name : File_Name_Type := No_File;
4374 -- The file name of the ALI file
4376 ALI_Project : Project_Id := No_Project;
4377 -- The project of the ALI file
4380 OK : Boolean := True;
4383 -- For call to Close
4386 Tempdir.Create_Temp_File (Mapping_FD, Mapping_Path);
4387 Record_Temp_File (Mapping_Path);
4389 if Mapping_FD /= Invalid_FD then
4391 -- Traverse all units
4393 for J in Unit_Table.First ..
4394 Unit_Table.Last (Project_Tree.Units)
4397 Unit : constant Unit_Data := Project_Tree.Units.Table (J);
4399 if Unit.Name /= No_Name then
4401 -- If there is a body, put it in the mapping
4403 if Unit.File_Names (Body_Part).Name /= No_File
4404 and then Unit.File_Names (Body_Part).Project /=
4407 Get_Name_String (Unit.Name);
4408 Add_Str_To_Name_Buffer ("%b");
4409 ALI_Unit := Name_Find;
4412 (Unit.File_Names (Body_Part).Display_Name);
4413 ALI_Project := Unit.File_Names (Body_Part).Project;
4415 -- Otherwise, if there is a spec, put it in the
4418 elsif Unit.File_Names (Specification).Name /= No_File
4419 and then Unit.File_Names (Specification).Project /=
4422 Get_Name_String (Unit.Name);
4423 Add_Str_To_Name_Buffer ("%s");
4424 ALI_Unit := Name_Find;
4427 (Unit.File_Names (Specification).Display_Name);
4428 ALI_Project := Unit.File_Names (Specification).Project;
4431 ALI_Name := No_File;
4434 -- If we have something to put in the mapping then do it
4435 -- now. However, if the project is extended, we don't put
4436 -- anything in the mapping file, because we do not know
4437 -- where the ALI file is: it might be in the extended
4438 -- project obj dir as well as in the extending project
4441 if ALI_Name /= No_File
4442 and then ALI_Project.Extended_By = No_Project
4443 and then ALI_Project.Extends = No_Project
4445 -- First check if the ALI file exists. If it does not,
4446 -- do not put the unit in the mapping file.
4449 ALI : constant String := Get_Name_String (ALI_Name);
4452 -- For library projects, use the library directory,
4453 -- for other projects, use the object directory.
4455 if ALI_Project.Library then
4456 Get_Name_String (ALI_Project.Library_Dir.Name);
4459 (ALI_Project.Object_Directory.Name);
4462 if Name_Buffer (Name_Len) /=
4465 Add_Char_To_Name_Buffer (Directory_Separator);
4468 Add_Str_To_Name_Buffer (ALI);
4469 Add_Char_To_Name_Buffer (ASCII.LF);
4472 ALI_Path_Name : constant String :=
4473 Name_Buffer (1 .. Name_Len);
4477 (ALI_Path_Name (1 .. ALI_Path_Name'Last - 1))
4480 -- First line is the unit name
4482 Get_Name_String (ALI_Unit);
4483 Add_Char_To_Name_Buffer (ASCII.LF);
4487 Name_Buffer (1)'Address,
4489 OK := Bytes = Name_Len;
4493 -- Second line it the ALI file name
4495 Get_Name_String (ALI_Name);
4496 Add_Char_To_Name_Buffer (ASCII.LF);
4500 Name_Buffer (1)'Address,
4502 OK := Bytes = Name_Len;
4506 -- Third line it the ALI path name
4511 ALI_Path_Name (1)'Address,
4512 ALI_Path_Name'Length);
4513 OK := Bytes = ALI_Path_Name'Length;
4515 -- If OK is False, it means we were unable
4516 -- to write a line. No point in continuing
4517 -- with the other units.
4528 Close (Mapping_FD, Status);
4530 OK := OK and Status;
4532 -- If the creation of the mapping file was successful,
4533 -- we add the switch to the arguments of gnatbind.
4536 Last_Arg := Last_Arg + 1;
4538 new String'("-F=" & Get_Name_String (Mapping_Path));
4541 end Create_Binder_Mapping_File;
4543 -- Start of processing for Gnatmake
4545 -- This body is very long, should be broken down ???
4548 Install_Int_Handler (Sigint_Intercepted'Access);
4550 Do_Compile_Step := True;
4551 Do_Bind_Step := True;
4552 Do_Link_Step := True;
4558 Bind_Shared := No_Shared_Switch'Access;
4559 Link_With_Shared_Libgcc := No_Shared_Libgcc_Switch'Access;
4561 Failed_Links.Set_Last (0);
4562 Successful_Links.Set_Last (0);
4564 -- Special case when switch -B was specified
4566 if Build_Bind_And_Link_Full_Project then
4568 -- When switch -B is specified, there must be a project file
4570 if Main_Project = No_Project then
4571 Make_Failed ("-B cannot be used without a project file");
4573 -- No main program may be specified on the command line
4575 elsif Osint.Number_Of_Files /= 0 then
4576 Make_Failed ("-B cannot be used with a main specified on " &
4577 "the command line");
4579 -- And the project file cannot be a library project file
4581 elsif Main_Project.Library then
4582 Make_Failed ("-B cannot be used for a library project file");
4585 No_Main_Subprogram := True;
4586 Insert_Project_Sources
4587 (The_Project => Main_Project,
4588 All_Projects => Unique_Compile_All_Projects,
4591 -- If there are no sources to compile, we fail
4593 if Osint.Number_Of_Files = 0 then
4594 Make_Failed ("no sources to compile");
4597 -- Specify -n for gnatbind and add the ALI files of all the
4598 -- sources, except the one which is a fake main subprogram:
4599 -- this is the one for the binder generated file and it will be
4600 -- transmitted to gnatlink. These sources are those that are
4603 Add_Switch ("-n", Binder, And_Save => True);
4605 for J in Q.First .. Q.Last - 1 loop
4608 (Lib_File_Name (Q.Table (J).File)),
4609 Binder, And_Save => True);
4613 elsif Main_Index /= 0 and then Osint.Number_Of_Files > 1 then
4614 Make_Failed ("cannot specify several mains with a multi-unit index");
4616 elsif Main_Project /= No_Project then
4618 -- If the main project file is a library project file, main(s)
4619 -- cannot be specified on the command line.
4621 if Osint.Number_Of_Files /= 0 then
4622 if Main_Project.Library
4623 and then not Unique_Compile
4624 and then ((not Make_Steps) or else Bind_Only or else Link_Only)
4626 Make_Failed ("cannot specify a main program " &
4627 "on the command line for a library project file");
4630 -- Check that each main on the command line is a source of a
4631 -- project file and, if there are several mains, each of them
4632 -- is a source of the same project file.
4637 -- If no mains have been specified on the command line,
4638 -- and we are using a project file, we either find the main(s)
4639 -- in the attribute Main of the main project, or we put all
4640 -- the sources of the project file as mains.
4643 if Main_Index /= 0 then
4644 Make_Failed ("cannot specify a multi-unit index but no main " &
4645 "on the command line");
4649 Value : String_List_Id := Main_Project.Mains;
4652 -- The attribute Main is an empty list or not specified,
4653 -- or else gnatmake was invoked with the switch "-u".
4655 if Value = Prj.Nil_String or else Unique_Compile then
4657 if (not Make_Steps) or else Compile_Only
4658 or else not Main_Project.Library
4660 -- First make sure that the binder and the linker
4661 -- will not be invoked.
4663 Do_Bind_Step := False;
4664 Do_Link_Step := False;
4666 -- Put all the sources in the queue
4668 No_Main_Subprogram := True;
4669 Insert_Project_Sources
4670 (The_Project => Main_Project,
4671 All_Projects => Unique_Compile_All_Projects,
4674 -- If no sources to compile, then there is nothing to do
4676 if Osint.Number_Of_Files = 0 then
4677 if not Quiet_Output then
4678 Osint.Write_Program_Name;
4679 Write_Line (": no sources to compile");
4682 Delete_All_Temp_Files;
4683 Exit_Program (E_Success);
4688 -- The attribute Main is not an empty list.
4689 -- Put all the main subprograms in the list as if there
4690 -- were specified on the command line. However, if attribute
4691 -- Languages includes a language other than Ada, only
4692 -- include the Ada mains; if there is no Ada main, compile
4693 -- all the sources of the project.
4696 Languages : constant Variable_Value :=
4699 Main_Project.Decl.Attributes,
4702 Current : String_List_Id;
4703 Element : String_Element;
4705 Foreign_Language : Boolean := False;
4706 At_Least_One_Main : Boolean := False;
4709 -- First, determine if there is a foreign language in
4710 -- attribute Languages.
4712 if not Languages.Default then
4713 Current := Languages.Values;
4716 while Current /= Nil_String loop
4717 Element := Project_Tree.String_Elements.
4719 Get_Name_String (Element.Value);
4720 To_Lower (Name_Buffer (1 .. Name_Len));
4722 if Name_Buffer (1 .. Name_Len) /= "ada" then
4723 Foreign_Language := True;
4724 exit Look_For_Foreign;
4727 Current := Element.Next;
4728 end loop Look_For_Foreign;
4731 -- Then, find all mains, or if there is a foreign
4732 -- language, all the Ada mains.
4734 while Value /= Prj.Nil_String loop
4736 (Project_Tree.String_Elements.Table (Value).Value);
4738 -- To know if a main is an Ada main, get its project.
4739 -- It should be the project specified on the command
4742 if (not Foreign_Language) or else
4744 (Name_Buffer (1 .. Name_Len),
4749 At_Least_One_Main := True;
4752 (Project_Tree.String_Elements.Table
4755 Project_Tree.String_Elements.Table
4759 Value := Project_Tree.String_Elements.Table
4763 -- If we did not get any main, it means that all mains
4764 -- in attribute Mains are in a foreign language and -B
4765 -- was not specified to gnatmake; so, we fail.
4767 if not At_Least_One_Main then
4769 ("no Ada mains, use -B to build foreign main");
4778 if Verbose_Mode then
4780 Display_Version ("GNATMAKE", "1995");
4783 if Main_Project /= No_Project
4784 and then Main_Project.Externally_Built
4787 ("nothing to do for a main project that is externally built");
4790 if Osint.Number_Of_Files = 0 then
4791 if Main_Project /= No_Project
4792 and then Main_Project.Library
4795 and then not Main_Project.Standalone_Library
4797 Make_Failed ("only stand-alone libraries may be bound");
4800 -- Add the default search directories to be able to find libgnat
4802 Osint.Add_Default_Search_Dirs;
4804 -- Get the target parameters, so that the correct binder generated
4805 -- files are generated if OpenVMS is the target.
4808 Targparm.Get_Target_Parameters;
4811 when Unrecoverable_Error =>
4812 Make_Failed ("*** make failed.");
4815 -- And bind and or link the library
4817 MLib.Prj.Build_Library
4818 (For_Project => Main_Project,
4819 In_Tree => Project_Tree,
4820 Gnatbind => Gnatbind.all,
4821 Gnatbind_Path => Gnatbind_Path,
4823 Gcc_Path => Gcc_Path,
4827 Delete_All_Temp_Files;
4828 Exit_Program (E_Success);
4831 -- Output usage information if no files to compile
4834 Exit_Program (E_Fatal);
4838 -- If -M was specified, behave as if -n was specified
4840 if List_Dependencies then
4841 Do_Not_Execute := True;
4844 -- Note that Osint.M.Next_Main_Source will always return the (possibly
4845 -- abbreviated file) without any directory information.
4847 Main_Source_File := Next_Main_Source;
4849 if Current_File_Index /= No_Index then
4850 Main_Index := Current_File_Index;
4853 Add_Switch ("-I-", Compiler, And_Save => True);
4855 if Main_Project = No_Project then
4856 if Look_In_Primary_Dir then
4860 Normalize_Directory_Name
4861 (Get_Primary_Src_Search_Directory.all).all,
4862 Compiler, Append_Switch => False,
4868 -- If we use a project file, we have already checked that a main
4869 -- specified on the command line with directory information has the
4870 -- path name corresponding to a correct source in the project tree.
4871 -- So, we don't need the directory information to be taken into
4872 -- account by Find_File, and in fact it may lead to take the wrong
4873 -- sources for other compilation units, when there are extending
4876 Look_In_Primary_Dir := False;
4877 Add_Switch ("-I-", Binder, And_Save => True);
4880 -- If the user wants a program without a main subprogram, add the
4881 -- appropriate switch to the binder.
4883 if No_Main_Subprogram then
4884 Add_Switch ("-z", Binder, And_Save => True);
4887 if Main_Project /= No_Project then
4889 if Main_Project.Object_Directory /= No_Path_Information then
4890 -- Change current directory to object directory of main project
4892 Project_Of_Current_Object_Directory := No_Project;
4893 Change_To_Object_Directory (Main_Project);
4896 -- Source file lookups should be cached for efficiency.
4897 -- Source files are not supposed to change.
4899 Osint.Source_File_Data (Cache => True);
4901 -- Find the file name of the (first) main unit
4904 Main_Source_File_Name : constant String :=
4905 Get_Name_String (Main_Source_File);
4906 Main_Unit_File_Name : constant String :=
4907 Prj.Env.File_Name_Of_Library_Unit_Body
4908 (Name => Main_Source_File_Name,
4909 Project => Main_Project,
4910 In_Tree => Project_Tree,
4911 Main_Project_Only =>
4912 not Unique_Compile);
4914 The_Packages : constant Package_Id :=
4915 Main_Project.Decl.Packages;
4917 Builder_Package : constant Prj.Package_Id :=
4919 (Name => Name_Builder,
4920 In_Packages => The_Packages,
4921 In_Tree => Project_Tree);
4923 Binder_Package : constant Prj.Package_Id :=
4925 (Name => Name_Binder,
4926 In_Packages => The_Packages,
4927 In_Tree => Project_Tree);
4929 Linker_Package : constant Prj.Package_Id :=
4931 (Name => Name_Linker,
4932 In_Packages => The_Packages,
4933 In_Tree => Project_Tree);
4935 Default_Switches_Array : Array_Id;
4937 Global_Compilation_Array : Array_Element_Id;
4938 Global_Compilation_Elem : Array_Element;
4939 Global_Compilation_Switches : Variable_Value;
4942 -- We fail if we cannot find the main source file
4944 if Main_Unit_File_Name = "" then
4945 Make_Failed ('"' & Main_Source_File_Name
4946 & """ is not a unit of project "
4947 & Project_File_Name.all & ".");
4949 -- Remove any directory information from the main
4950 -- source file name.
4953 Pos : Natural := Main_Unit_File_Name'Last;
4957 exit when Pos < Main_Unit_File_Name'First or else
4958 Main_Unit_File_Name (Pos) = Directory_Separator;
4962 Name_Len := Main_Unit_File_Name'Last - Pos;
4964 Name_Buffer (1 .. Name_Len) :=
4966 (Pos + 1 .. Main_Unit_File_Name'Last);
4968 Main_Source_File := Name_Find;
4970 -- We only output the main source file if there is only one
4972 if Verbose_Mode and then Osint.Number_Of_Files = 1 then
4973 Write_Str ("Main source file: """);
4974 Write_Str (Main_Unit_File_Name
4975 (Pos + 1 .. Main_Unit_File_Name'Last));
4981 -- If there is a package Builder in the main project file, add
4982 -- the switches from it.
4984 if Builder_Package /= No_Package then
4986 Global_Compilation_Array := Prj.Util.Value_Of
4987 (Name => Name_Global_Compilation_Switches,
4988 In_Arrays => Project_Tree.Packages.Table
4989 (Builder_Package).Decl.Arrays,
4990 In_Tree => Project_Tree);
4992 Default_Switches_Array :=
4993 Project_Tree.Packages.Table
4994 (Builder_Package).Decl.Arrays;
4996 while Default_Switches_Array /= No_Array and then
4997 Project_Tree.Arrays.Table (Default_Switches_Array).Name /=
4998 Name_Default_Switches
5000 Default_Switches_Array :=
5001 Project_Tree.Arrays.Table (Default_Switches_Array).Next;
5004 if Global_Compilation_Array /= No_Array_Element and then
5005 Default_Switches_Array /= No_Array
5008 ("Default_Switches forbidden in presence of " &
5009 "Global_Compilation_Switches. Use Switches instead.",
5010 Project_Tree.Arrays.Table
5011 (Default_Switches_Array).Location);
5014 ("*** illegal combination of Builder attributes");
5017 -- If there is only one main, we attempt to get the gnatmake
5018 -- switches for this main (if any). If there are no specific
5019 -- switch for this particular main, get the general gnatmake
5020 -- switches (if any).
5022 if Osint.Number_Of_Files = 1 then
5023 if Verbose_Mode then
5024 Write_Str ("Adding gnatmake switches for """);
5025 Write_Str (Main_Unit_File_Name);
5030 (File_Name => Main_Unit_File_Name,
5031 Index => Main_Index,
5032 The_Package => Builder_Package,
5034 Unknown_Switches_To_The_Compiler =>
5035 Global_Compilation_Array = No_Array_Element);
5038 -- If there are several mains, we always get the general
5039 -- gnatmake switches (if any).
5041 -- Warn the user, if necessary, so that he is not surprised
5042 -- that specific switches are not taken into account.
5045 Defaults : constant Variable_Value :=
5049 Attribute_Or_Array_Name =>
5050 Name_Default_Switches,
5053 In_Tree => Project_Tree);
5055 Switches : constant Array_Element_Id :=
5057 (Name => Name_Switches,
5059 Project_Tree.Packages.Table
5060 (Builder_Package).Decl.Arrays,
5061 In_Tree => Project_Tree);
5063 Other_Switches : constant Variable_Value :=
5065 (Name => All_Other_Names,
5067 Attribute_Or_Array_Name
5069 In_Package => Builder_Package,
5070 In_Tree => Project_Tree);
5073 if Other_Switches /= Nil_Variable_Value then
5075 and then Switches /= No_Array_Element
5076 and then Project_Tree.Array_Elements.Table
5077 (Switches).Next /= No_Array_Element
5080 ("Warning: using Builder'Switches(others), "
5081 & "as there are several mains");
5087 The_Package => Builder_Package,
5089 Unknown_Switches_To_The_Compiler => False);
5091 elsif Defaults /= Nil_Variable_Value then
5093 and then Switches /= No_Array_Element
5096 ("Warning: using Builder'Default_Switches"
5097 & "(""Ada""), as there are several mains");
5103 The_Package => Builder_Package,
5106 elsif not Quiet_Output
5107 and then Switches /= No_Array_Element
5110 ("Warning: using no switches from package "
5111 & "Builder, as there are several mains");
5116 -- Take into account attribute Global_Compilation_Switches
5121 List : String_List_Id;
5122 Elem : String_Element;
5125 while Global_Compilation_Array /= No_Array_Element loop
5126 Global_Compilation_Elem :=
5127 Project_Tree.Array_Elements.Table
5128 (Global_Compilation_Array);
5130 Get_Name_String (Global_Compilation_Elem.Index);
5131 To_Lower (Name_Buffer (1 .. Name_Len));
5134 if Index = Name_Ada then
5135 Global_Compilation_Switches :=
5136 Global_Compilation_Elem.Value;
5138 if Global_Compilation_Switches /= Nil_Variable_Value
5139 and then not Global_Compilation_Switches.Default
5141 -- We have found attribute
5142 -- Global_Compilation_Switches ("Ada"): put the
5143 -- switches in the appropriate table.
5145 List := Global_Compilation_Switches.Values;
5147 while List /= Nil_String loop
5149 Project_Tree.String_Elements.Table (List);
5151 if Elem.Value /= No_Name then
5153 (Get_Name_String (Elem.Value),
5165 Global_Compilation_Array := Global_Compilation_Elem.Next;
5170 Osint.Add_Default_Search_Dirs;
5172 -- Record the current last switch index for table Binder_Switches
5173 -- and Linker_Switches, so that these tables may be reset before
5174 -- for each main, before adding switches from the project file
5175 -- and from the command line.
5177 Last_Binder_Switch := Binder_Switches.Last;
5178 Last_Linker_Switch := Linker_Switches.Last;
5182 -- Add binder switches from the project file for the first main
5184 if Do_Bind_Step and Binder_Package /= No_Package then
5185 if Verbose_Mode then
5186 Write_Str ("Adding binder switches for """);
5187 Write_Str (Main_Unit_File_Name);
5192 (File_Name => Main_Unit_File_Name,
5193 Index => Main_Index,
5194 The_Package => Binder_Package,
5198 -- Add linker switches from the project file for the first main
5200 if Do_Link_Step and Linker_Package /= No_Package then
5201 if Verbose_Mode then
5202 Write_Str ("Adding linker switches for""");
5203 Write_Str (Main_Unit_File_Name);
5208 (File_Name => Main_Unit_File_Name,
5209 Index => Main_Index,
5210 The_Package => Linker_Package,
5216 -- Get the target parameters, which are only needed for a couple of
5217 -- cases in gnatmake. Protect against an exception, such as the case
5218 -- of system.ads missing from the library, and fail gracefully.
5221 Targparm.Get_Target_Parameters;
5223 when Unrecoverable_Error =>
5224 Make_Failed ("*** make failed.");
5227 -- Special processing for VM targets
5229 if Targparm.VM_Target /= No_VM then
5231 -- Set proper processing commands
5233 case Targparm.VM_Target is
5234 when Targparm.JVM_Target =>
5236 -- Do not check for an object file (".o") when compiling to
5237 -- JVM machine since ".class" files are generated instead.
5239 Check_Object_Consistency := False;
5240 Gcc := new String'("jvm-gnatcompile");
5242 when Targparm.CLI_Target =>
5243 Gcc := new String'("dotnet-gnatcompile");
5245 when Targparm.No_VM =>
5246 raise Program_Error;
5250 Display_Commands (not Quiet_Output);
5254 if Main_Project /= No_Project then
5256 -- For all library project, if the library file does not exist, put
5257 -- all the project sources in the queue, and flag the project so that
5258 -- the library is generated.
5260 if not Unique_Compile
5261 and then MLib.Tgt.Support_For_Libraries /= Prj.None
5264 Proj : Project_List;
5267 Proj := Project_Tree.Projects;
5268 while Proj /= null loop
5269 if Proj.Project.Library then
5270 Proj.Project.Need_To_Build_Lib :=
5271 not MLib.Tgt.Library_Exists_For
5272 (Proj.Project, Project_Tree)
5273 and then not Proj.Project.Externally_Built;
5275 if Proj.Project.Need_To_Build_Lib then
5277 -- If there is no object directory, then it will be
5278 -- impossible to build the library. So fail
5282 Proj.Project.Object_Directory = No_Path_Information
5285 ("no object files to build library for project """
5286 & Get_Name_String (Proj.Project.Name)
5288 Proj.Project.Need_To_Build_Lib := False;
5291 if Verbose_Mode then
5293 ("Library file does not exist for project """);
5294 Write_Str (Get_Name_String (Proj.Project.Name));
5298 Insert_Project_Sources
5299 (The_Project => Proj.Project,
5300 All_Projects => False,
5311 -- If a relative path output file has been specified, we add
5312 -- the exec directory.
5314 for J in reverse 1 .. Saved_Linker_Switches.Last - 1 loop
5315 if Saved_Linker_Switches.Table (J).all = Output_Flag.all then
5317 Exec_File_Name : constant String :=
5318 Saved_Linker_Switches.Table (J + 1).all;
5321 if not Is_Absolute_Path (Exec_File_Name) then
5322 Get_Name_String (Main_Project.Exec_Directory.Name);
5324 if Name_Buffer (Name_Len) /= Directory_Separator then
5325 Add_Char_To_Name_Buffer (Directory_Separator);
5328 Add_Str_To_Name_Buffer (Exec_File_Name);
5329 Saved_Linker_Switches.Table (J + 1) :=
5330 new String'(Name_Buffer (1 .. Name_Len));
5338 -- If we are using a project file, for relative paths we add the
5339 -- current working directory for any relative path on the command
5340 -- line and the project directory, for any relative path in the
5344 Dir_Path : constant String :=
5345 Get_Name_String (Main_Project.Directory.Name);
5347 for J in 1 .. Binder_Switches.Last loop
5348 Test_If_Relative_Path
5349 (Binder_Switches.Table (J),
5350 Parent => Dir_Path, Including_L_Switch => False);
5353 for J in 1 .. Saved_Binder_Switches.Last loop
5354 Test_If_Relative_Path
5355 (Saved_Binder_Switches.Table (J),
5356 Parent => Current_Work_Dir.all, Including_L_Switch => False);
5359 for J in 1 .. Linker_Switches.Last loop
5360 Test_If_Relative_Path
5361 (Linker_Switches.Table (J), Parent => Dir_Path);
5364 for J in 1 .. Saved_Linker_Switches.Last loop
5365 Test_If_Relative_Path
5366 (Saved_Linker_Switches.Table (J),
5367 Parent => Current_Work_Dir.all);
5370 for J in 1 .. Gcc_Switches.Last loop
5371 Test_If_Relative_Path
5372 (Gcc_Switches.Table (J),
5374 Including_Non_Switch => False);
5377 for J in 1 .. Saved_Gcc_Switches.Last loop
5378 Test_If_Relative_Path
5379 (Saved_Gcc_Switches.Table (J),
5380 Parent => Current_Work_Dir.all,
5381 Including_Non_Switch => False);
5386 -- We now put in the Binder_Switches and Linker_Switches tables, the
5387 -- binder and linker switches of the command line that have been put in
5388 -- the Saved_ tables. If a project file was used, then the command line
5389 -- switches will follow the project file switches.
5391 for J in 1 .. Saved_Binder_Switches.Last loop
5393 (Saved_Binder_Switches.Table (J),
5398 for J in 1 .. Saved_Linker_Switches.Last loop
5400 (Saved_Linker_Switches.Table (J),
5405 -- If no project file is used, we just put the gcc switches
5406 -- from the command line in the Gcc_Switches table.
5408 if Main_Project = No_Project then
5409 for J in 1 .. Saved_Gcc_Switches.Last loop
5411 (Saved_Gcc_Switches.Table (J), Compiler, And_Save => False);
5415 -- If there is a project, put the command line gcc switches in the
5416 -- variable The_Saved_Gcc_Switches. They are going to be used later
5417 -- in procedure Compile_Sources.
5419 The_Saved_Gcc_Switches :=
5420 new Argument_List (1 .. Saved_Gcc_Switches.Last + 1);
5422 for J in 1 .. Saved_Gcc_Switches.Last loop
5423 The_Saved_Gcc_Switches (J) := Saved_Gcc_Switches.Table (J);
5426 -- We never use gnat.adc when a project file is used
5428 The_Saved_Gcc_Switches (The_Saved_Gcc_Switches'Last) := No_gnat_adc;
5431 -- If there was a --GCC, --GNATBIND or --GNATLINK switch on
5432 -- the command line, then we have to use it, even if there was
5433 -- another switch in the project file.
5435 if Saved_Gcc /= null then
5439 if Saved_Gnatbind /= null then
5440 Gnatbind := Saved_Gnatbind;
5443 if Saved_Gnatlink /= null then
5444 Gnatlink := Saved_Gnatlink;
5447 Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
5448 Gnatbind_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
5449 Gnatlink_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
5451 -- If we have specified -j switch both from the project file
5452 -- and on the command line, the one from the command line takes
5455 if Saved_Maximum_Processes = 0 then
5456 Saved_Maximum_Processes := Maximum_Processes;
5459 -- Allocate as many temporary mapping file names as the maximum number
5460 -- of compilations processed, for each possible project.
5463 Data : Project_Compilation_Access;
5464 Proj : Project_List := Project_Tree.Projects;
5466 while Proj /= null loop
5467 Data := new Project_Compilation_Data'
5468 (Mapping_File_Names => new Temp_Path_Names
5469 (1 .. Saved_Maximum_Processes),
5470 Last_Mapping_File_Names => 0,
5471 Free_Mapping_File_Indices => new Free_File_Indices
5472 (1 .. Saved_Maximum_Processes),
5473 Last_Free_Indices => 0);
5475 Project_Compilation_Htable.Set
5476 (Project_Compilation, Proj.Project, Data);
5480 Data := new Project_Compilation_Data'
5481 (Mapping_File_Names => new Temp_Path_Names
5482 (1 .. Saved_Maximum_Processes),
5483 Last_Mapping_File_Names => 0,
5484 Free_Mapping_File_Indices => new Free_File_Indices
5485 (1 .. Saved_Maximum_Processes),
5486 Last_Free_Indices => 0);
5488 Project_Compilation_Htable.Set
5489 (Project_Compilation, No_Project, Data);
5492 Bad_Compilation.Init;
5494 -- If project files are used, create the mapping of all the sources, so
5495 -- that the correct paths will be found. Otherwise, if there is a file
5496 -- which is not a source with the same name in a source directory this
5497 -- file may be incorrectly found.
5499 if Main_Project /= No_Project then
5500 Prj.Env.Create_Mapping (Project_Tree);
5503 Current_Main_Index := Main_Index;
5505 -- Here is where the make process is started
5507 -- We do the same process for each main
5509 Multiple_Main_Loop : for N_File in 1 .. Osint.Number_Of_Files loop
5511 -- First, find the executable name and path
5513 Executable := No_File;
5514 Executable_Obsolete := False;
5515 Non_Std_Executable :=
5516 Targparm.Executable_Extension_On_Target /= No_Name;
5518 -- Look inside the linker switches to see if the name of the final
5519 -- executable program was specified.
5521 for J in reverse Linker_Switches.First .. Linker_Switches.Last loop
5522 if Linker_Switches.Table (J).all = Output_Flag.all then
5523 pragma Assert (J < Linker_Switches.Last);
5525 -- We cannot specify a single executable for several main
5528 if Osint.Number_Of_Files > 1 then
5530 ("cannot specify a single executable for several mains");
5534 Add_Str_To_Name_Buffer (Linker_Switches.Table (J + 1).all);
5535 Executable := Name_Enter;
5537 Verbose_Msg (Executable, "final executable");
5541 -- If the name of the final executable program was not specified then
5542 -- construct it from the main input file.
5544 if Executable = No_File then
5545 if Main_Project = No_Project then
5546 Executable := Executable_Name (Strip_Suffix (Main_Source_File));
5549 -- If we are using a project file, we attempt to remove the
5550 -- body (or spec) termination of the main subprogram. We find
5551 -- it the naming scheme of the project file. This avoids
5552 -- generating an executable "main.2" for a main subprogram
5553 -- "main.2.ada", when the body termination is ".2.ada".
5556 Prj.Util.Executable_Of
5557 (Main_Project, Project_Tree, Main_Source_File, Main_Index);
5561 if Main_Project /= No_Project
5562 and then Main_Project.Exec_Directory /= No_Path_Information
5565 Exec_File_Name : constant String :=
5566 Get_Name_String (Executable);
5569 if not Is_Absolute_Path (Exec_File_Name) then
5570 Get_Name_String (Main_Project.Exec_Directory.Display_Name);
5572 if Name_Buffer (Name_Len) /= Directory_Separator then
5573 Add_Char_To_Name_Buffer (Directory_Separator);
5576 Add_Str_To_Name_Buffer (Exec_File_Name);
5577 Executable := Name_Find;
5580 Non_Std_Executable := True;
5584 if Do_Compile_Step then
5585 Recursive_Compilation_Step : declare
5586 Args : Argument_List (1 .. Gcc_Switches.Last);
5588 First_Compiled_File : File_Name_Type;
5589 Youngest_Obj_File : File_Name_Type;
5590 Youngest_Obj_Stamp : Time_Stamp_Type;
5592 Executable_Stamp : Time_Stamp_Type;
5593 -- Executable is the final executable program
5594 -- ??? comment seems unrelated to declaration
5596 Library_Rebuilt : Boolean := False;
5599 for J in 1 .. Gcc_Switches.Last loop
5600 Args (J) := Gcc_Switches.Table (J);
5603 -- Now we invoke Compile_Sources for the current main
5606 (Main_Source => Main_Source_File,
5608 First_Compiled_File => First_Compiled_File,
5609 Most_Recent_Obj_File => Youngest_Obj_File,
5610 Most_Recent_Obj_Stamp => Youngest_Obj_Stamp,
5611 Main_Unit => Is_Main_Unit,
5612 Main_Index => Current_Main_Index,
5613 Compilation_Failures => Compilation_Failures,
5614 Check_Readonly_Files => Check_Readonly_Files,
5615 Do_Not_Execute => Do_Not_Execute,
5616 Force_Compilations => Force_Compilations,
5617 In_Place_Mode => In_Place_Mode,
5618 Keep_Going => Keep_Going,
5619 Initialize_ALI_Data => True,
5620 Max_Process => Saved_Maximum_Processes);
5622 if Verbose_Mode then
5623 Write_Str ("End of compilation");
5627 -- Make sure the queue will be reinitialized for the next round
5629 First_Q_Initialization := True;
5631 Total_Compilation_Failures :=
5632 Total_Compilation_Failures + Compilation_Failures;
5634 if Total_Compilation_Failures /= 0 then
5639 List_Bad_Compilations;
5640 Report_Compilation_Failed;
5644 -- Regenerate libraries, if there are any and if object files
5645 -- have been regenerated.
5647 if Main_Project /= No_Project
5648 and then MLib.Tgt.Support_For_Libraries /= Prj.None
5649 and then (Do_Bind_Step
5650 or Unique_Compile_All_Projects
5651 or not Compile_Only)
5652 and then (Do_Link_Step or N_File = Osint.Number_Of_Files)
5659 Proj1 : Project_List;
5661 procedure Add_To_Library_Projs (Proj : Project_Id);
5662 -- Add project Project to table Library_Projs in
5663 -- decreasing depth order.
5665 --------------------------
5666 -- Add_To_Library_Projs --
5667 --------------------------
5669 procedure Add_To_Library_Projs (Proj : Project_Id) is
5673 Library_Projs.Increment_Last;
5674 Depth := Proj.Depth;
5676 -- Put the projects in decreasing depth order, so that
5677 -- if libA depends on libB, libB is first in order.
5679 Current := Library_Projs.Last;
5680 while Current > 1 loop
5681 Prj := Library_Projs.Table (Current - 1);
5682 exit when Prj.Depth >= Depth;
5683 Library_Projs.Table (Current) := Prj;
5684 Current := Current - 1;
5687 Library_Projs.Table (Current) := Proj;
5688 end Add_To_Library_Projs;
5690 -- Start of processing for ??? (should name declare block
5691 -- or probably better, break this out as a nested proc).
5694 -- Put in Library_Projs table all library project file
5695 -- ids when the library need to be rebuilt.
5697 Proj1 := Project_Tree.Projects;
5698 while Proj1 /= null loop
5699 if Proj1.Project.Standalone_Library then
5700 Stand_Alone_Libraries := True;
5703 if Proj1.Project.Library then
5704 MLib.Prj.Check_Library
5705 (Proj1.Project, Project_Tree);
5708 if Proj1.Project.Need_To_Build_Lib then
5709 Add_To_Library_Projs (Proj1.Project);
5712 Proj1 := Proj1.Next;
5715 -- Check if importing libraries should be regenerated
5716 -- because at least an imported library will be
5717 -- regenerated or is more recent.
5719 Proj1 := Project_Tree.Projects;
5720 while Proj1 /= null loop
5721 if Proj1.Project.Library
5722 and then Proj1.Project.Library_Kind /= Static
5723 and then not Proj1.Project.Need_To_Build_Lib
5724 and then not Proj1.Project.Externally_Built
5727 List : Project_List;
5729 Rebuild : Boolean := False;
5731 Lib_Timestamp1 : constant Time_Stamp_Type :=
5732 Proj1.Project.Library_TS;
5735 List := Proj1.Project.All_Imported_Projects;
5736 while List /= null loop
5737 Proj2 := List.Project;
5739 if Proj2.Library then
5740 if Proj2.Need_To_Build_Lib
5742 (Lib_Timestamp1 < Proj2.Library_TS)
5753 Proj1.Project.Need_To_Build_Lib := True;
5754 Add_To_Library_Projs (Proj1.Project);
5759 Proj1 := Proj1.Next;
5762 -- Reset the flags Need_To_Build_Lib for the next main,
5763 -- to avoid rebuilding libraries uselessly.
5765 Proj1 := Project_Tree.Projects;
5766 while Proj1 /= null loop
5767 Proj1.Project.Need_To_Build_Lib := False;
5768 Proj1 := Proj1.Next;
5772 -- Build the libraries, if any need to be built
5774 for J in 1 .. Library_Projs.Last loop
5775 Library_Rebuilt := True;
5777 -- If a library is rebuilt, then executables are obsolete
5779 Executable_Obsolete := True;
5781 MLib.Prj.Build_Library
5782 (For_Project => Library_Projs.Table (J),
5783 In_Tree => Project_Tree,
5784 Gnatbind => Gnatbind.all,
5785 Gnatbind_Path => Gnatbind_Path,
5787 Gcc_Path => Gcc_Path);
5791 if List_Dependencies then
5792 if First_Compiled_File /= No_File then
5794 (First_Compiled_File,
5795 "must be recompiled. Can't generate dependence list.");
5800 elsif First_Compiled_File = No_File
5801 and then not Do_Bind_Step
5802 and then not Quiet_Output
5803 and then not Library_Rebuilt
5804 and then Osint.Number_Of_Files = 1
5806 Inform (Msg => "objects up to date.");
5808 elsif Do_Not_Execute
5809 and then First_Compiled_File /= No_File
5811 Write_Name (First_Compiled_File);
5815 -- Stop after compile step if any of:
5817 -- 1) -n (Do_Not_Execute) specified
5819 -- 2) -M (List_Dependencies) specified (also sets
5820 -- Do_Not_Execute above, so this is probably superfluous).
5822 -- 3) -c (Compile_Only) specified, but not -b (Bind_Only)
5824 -- 4) Made unit cannot be a main unit
5827 or List_Dependencies
5829 or not Is_Main_Unit)
5830 and then not No_Main_Subprogram
5831 and then not Build_Bind_And_Link_Full_Project)
5832 or else Unique_Compile
5834 if Osint.Number_Of_Files = 1 then
5835 exit Multiple_Main_Loop;
5842 -- If the objects were up-to-date check if the executable file
5843 -- is also up-to-date. For now always bind and link on the JVM
5844 -- since there is currently no simple way to check whether
5845 -- objects are up-to-date.
5847 if Targparm.VM_Target /= JVM_Target
5848 and then First_Compiled_File = No_File
5850 Executable_Stamp := File_Stamp (Executable);
5852 if not Executable_Obsolete then
5853 Executable_Obsolete :=
5854 Youngest_Obj_Stamp > Executable_Stamp;
5857 if not Executable_Obsolete then
5858 for Index in reverse 1 .. Dependencies.Last loop
5860 (Dependencies.Table (Index).Depends_On)
5862 Enter_Into_Obsoleted
5863 (Dependencies.Table (Index).This);
5867 Executable_Obsolete := Is_In_Obsoleted (Main_Source_File);
5871 if not Executable_Obsolete then
5873 -- If no Ada object files obsolete the executable, check
5874 -- for younger or missing linker files.
5876 Check_Linker_Options
5879 Youngest_Obj_Stamp);
5881 Executable_Obsolete := Youngest_Obj_File /= No_File;
5884 -- Check if any library file is more recent than the
5885 -- executable: there may be an externally built library
5886 -- file that has been modified.
5888 if (not Executable_Obsolete)
5889 and then Main_Project /= No_Project
5892 Proj1 : Project_List;
5894 Proj1 := Project_Tree.Projects;
5895 while Proj1 /= null loop
5896 if Proj1.Project.Library and then
5897 Proj1.Project.Library_TS > Executable_Stamp
5899 Executable_Obsolete := True;
5900 Youngest_Obj_Stamp := Proj1.Project.Library_TS;
5902 Add_Str_To_Name_Buffer ("library ");
5903 Add_Str_To_Name_Buffer
5904 (Get_Name_String (Proj1.Project.Library_Name));
5905 Youngest_Obj_File := Name_Find;
5909 Proj1 := Proj1.Next;
5914 -- Return if the executable is up to date and otherwise
5915 -- motivate the relink/rebind.
5917 if not Executable_Obsolete then
5918 if not Quiet_Output then
5919 Inform (Executable, "up to date.");
5922 if Osint.Number_Of_Files = 1 then
5923 exit Multiple_Main_Loop;
5930 if Executable_Stamp (1) = ' ' then
5931 if not No_Main_Subprogram then
5932 Verbose_Msg (Executable, "missing.", Prefix => " ");
5935 elsif Youngest_Obj_Stamp (1) = ' ' then
5937 (Youngest_Obj_File, "missing.", Prefix => " ");
5939 elsif Youngest_Obj_Stamp > Executable_Stamp then
5942 "(" & String (Youngest_Obj_Stamp) & ") newer than",
5944 "(" & String (Executable_Stamp) & ")");
5948 (Executable, "needs to be rebuilt", Prefix => " ");
5952 end Recursive_Compilation_Step;
5955 -- For binding and linking, we need to be in the object directory of
5956 -- the main project.
5958 if Main_Project /= No_Project then
5959 Change_To_Object_Directory (Main_Project);
5962 -- If we are here, it means that we need to rebuilt the current main,
5963 -- so we set Executable_Obsolete to True to make sure that subsequent
5964 -- mains will be rebuilt.
5966 Main_ALI_In_Place_Mode_Step : declare
5967 ALI_File : File_Name_Type;
5968 Src_File : File_Name_Type;
5971 Src_File := Strip_Directory (Main_Source_File);
5972 ALI_File := Lib_File_Name (Src_File, Current_Main_Index);
5973 Main_ALI_File := Full_Lib_File_Name (ALI_File);
5975 -- When In_Place_Mode, the library file can be located in the
5976 -- Main_Source_File directory which may not be present in the
5977 -- library path. If it is not present then use the corresponding
5978 -- library file name.
5980 if Main_ALI_File = No_File and then In_Place_Mode then
5981 Get_Name_String (Get_Directory (Full_Source_Name (Src_File)));
5982 Get_Name_String_And_Append (ALI_File);
5983 Main_ALI_File := Name_Find;
5984 Main_ALI_File := Full_Lib_File_Name (Main_ALI_File);
5987 if Main_ALI_File = No_File then
5988 Make_Failed ("could not find the main ALI file");
5990 end Main_ALI_In_Place_Mode_Step;
5992 if Do_Bind_Step then
5994 Args : Argument_List
5995 (Binder_Switches.First .. Binder_Switches.Last + 2);
5996 -- The arguments for the invocation of gnatbind
5998 Last_Arg : Natural := Binder_Switches.Last;
5999 -- Index of the last argument in Args
6001 Shared_Libs : Boolean := False;
6002 -- Set to True when there are shared library project files or
6003 -- when gnatbind is invoked with -shared.
6005 Proj : Project_List;
6008 -- Check if there are shared libraries, so that gnatbind is
6009 -- called with -shared. Check also if gnatbind is called with
6010 -- -shared, so that gnatlink is called with -shared-libgcc
6011 -- ensuring that the shared version of libgcc will be used.
6013 if Main_Project /= No_Project
6014 and then MLib.Tgt.Support_For_Libraries /= Prj.None
6016 Proj := Project_Tree.Projects;
6017 while Proj /= null loop
6018 if Proj.Project.Library
6019 and then Proj.Project.Library_Kind /= Static
6021 Shared_Libs := True;
6022 Bind_Shared := Shared_Switch'Access;
6029 -- Check now for switch -shared
6031 if not Shared_Libs then
6032 for J in Binder_Switches.First .. Last_Arg loop
6033 if Binder_Switches.Table (J).all = "-shared" then
6034 Shared_Libs := True;
6040 -- If shared libraries present, invoke gnatlink with
6044 Link_With_Shared_Libgcc := Shared_Libgcc_Switch'Access;
6047 -- Get all the binder switches
6049 for J in Binder_Switches.First .. Last_Arg loop
6050 Args (J) := Binder_Switches.Table (J);
6053 if Stand_Alone_Libraries then
6054 Last_Arg := Last_Arg + 1;
6055 Args (Last_Arg) := Force_Elab_Flags_String'Access;
6058 if Main_Project /= No_Project then
6060 -- Put all the source directories in ADA_INCLUDE_PATH,
6061 -- and all the object directories in ADA_OBJECTS_PATH.
6063 Prj.Env.Set_Ada_Paths (Main_Project, Project_Tree, True);
6065 -- If switch -C was specified, create a binder mapping file
6067 if Create_Mapping_File then
6068 Create_Binder_Mapping_File (Args, Last_Arg);
6074 Bind (Main_ALI_File,
6075 Bind_Shared.all & Args (Args'First .. Last_Arg));
6080 -- If -dn was not specified, delete the temporary mapping
6081 -- file, if one was created.
6083 if not Debug.Debug_Flag_N
6084 and then Mapping_Path /= No_Path
6086 Delete_File (Get_Name_String (Mapping_Path), Discard);
6089 -- And reraise the exception
6094 -- If -dn was not specified, delete the temporary mapping file,
6095 -- if one was created.
6097 if not Debug.Debug_Flag_N and then Mapping_Path /= No_Path then
6098 Delete_File (Get_Name_String (Mapping_Path), Discard);
6103 if Do_Link_Step then
6105 Linker_Switches_Last : constant Integer := Linker_Switches.Last;
6106 Path_Option : constant String_Access :=
6107 MLib.Linker_Library_Path_Option;
6108 Libraries_Present : Boolean := False;
6112 Proj1 : Project_List;
6115 if not Run_Path_Option then
6116 Linker_Switches.Increment_Last;
6117 Linker_Switches.Table (Linker_Switches.Last) :=
6121 if Main_Project /= No_Project then
6122 Library_Paths.Set_Last (0);
6125 if MLib.Tgt.Support_For_Libraries /= Prj.None then
6127 -- Check for library projects
6129 Proj1 := Project_Tree.Projects;
6130 while Proj1 /= null loop
6131 if Proj1.Project /= Main_Project
6132 and then Proj1.Project.Library
6134 -- Add this project to table Library_Projs
6136 Libraries_Present := True;
6137 Depth := Proj1.Project.Depth;
6138 Library_Projs.Increment_Last;
6139 Current := Library_Projs.Last;
6141 -- Any project with a greater depth should be
6142 -- after this project in the list.
6144 while Current > 1 loop
6145 Proj2 := Library_Projs.Table (Current - 1);
6146 exit when Proj2.Depth <= Depth;
6147 Library_Projs.Table (Current) := Proj2;
6148 Current := Current - 1;
6151 Library_Projs.Table (Current) := Proj1.Project;
6153 -- If it is not a static library and path option
6154 -- is set, add it to the Library_Paths table.
6156 if Proj1.Project.Library_Kind /= Static
6157 and then Path_Option /= null
6159 Library_Paths.Increment_Last;
6160 Library_Paths.Table (Library_Paths.Last) :=
6163 (Proj1.Project.Library_Dir.Display_Name));
6167 Proj1 := Proj1.Next;
6170 for Index in 1 .. Library_Projs.Last loop
6172 -- Add the -L switch
6174 Linker_Switches.Increment_Last;
6175 Linker_Switches.Table (Linker_Switches.Last) :=
6178 (Library_Projs.Table (Index).
6179 Library_Dir.Display_Name));
6181 -- Add the -l switch
6183 Linker_Switches.Increment_Last;
6184 Linker_Switches.Table (Linker_Switches.Last) :=
6187 (Library_Projs.Table (Index).
6192 if Libraries_Present then
6194 -- If Path_Option is not null, create the switch
6195 -- ("-Wl,-rpath," or equivalent) with all the non static
6196 -- library dirs plus the standard GNAT library dir.
6197 -- We do that only if Run_Path_Option is True
6198 -- (not disabled by -R switch).
6200 if Run_Path_Option and Path_Option /= null then
6202 Option : String_Access;
6203 Length : Natural := Path_Option'Length;
6207 if MLib.Separate_Run_Path_Options then
6209 -- We are going to create one switch of the form
6210 -- "-Wl,-rpath,dir_N" for each directory to
6213 -- One switch for each library directory
6216 Library_Paths.First .. Library_Paths.Last
6218 Linker_Switches.Increment_Last;
6219 Linker_Switches.Table
6220 (Linker_Switches.Last) := new String'
6222 Library_Paths.Table (Index).all);
6225 -- One switch for the standard GNAT library dir
6227 Linker_Switches.Increment_Last;
6228 Linker_Switches.Table
6229 (Linker_Switches.Last) := new String'
6230 (Path_Option.all & MLib.Utl.Lib_Directory);
6233 -- We are going to create one switch of the form
6234 -- "-Wl,-rpath,dir_1:dir_2:dir_3"
6237 Library_Paths.First .. Library_Paths.Last
6239 -- Add the length of the library dir plus one
6240 -- for the directory separator.
6244 Library_Paths.Table (Index)'Length + 1;
6247 -- Finally, add the length of the standard GNAT
6250 Length := Length + MLib.Utl.Lib_Directory'Length;
6251 Option := new String (1 .. Length);
6252 Option (1 .. Path_Option'Length) :=
6254 Current := Path_Option'Length;
6256 -- Put each library dir followed by a dir
6260 Library_Paths.First .. Library_Paths.Last
6265 Library_Paths.Table (Index)'Length) :=
6266 Library_Paths.Table (Index).all;
6269 Library_Paths.Table (Index)'Length + 1;
6270 Option (Current) := Path_Separator;
6273 -- Finally put the standard GNAT library dir
6277 Current + MLib.Utl.Lib_Directory'Length) :=
6278 MLib.Utl.Lib_Directory;
6280 -- And add the switch to the linker switches
6282 Linker_Switches.Increment_Last;
6283 Linker_Switches.Table (Linker_Switches.Last) :=
6291 -- Put the object directories in ADA_OBJECTS_PATH
6293 Prj.Env.Set_Ada_Paths (Main_Project, Project_Tree, False);
6295 -- Check for attributes Linker'Linker_Options in projects
6296 -- other than the main project
6299 Linker_Options : constant String_List :=
6300 Linker_Options_Switches
6301 (Main_Project, Project_Tree);
6303 for Option in Linker_Options'Range loop
6304 Linker_Switches.Increment_Last;
6305 Linker_Switches.Table (Linker_Switches.Last) :=
6306 Linker_Options (Option);
6312 Args : Argument_List
6313 (Linker_Switches.First .. Linker_Switches.Last + 2);
6315 Last_Arg : Integer := Linker_Switches.First - 1;
6316 Skip : Boolean := False;
6319 -- Get all the linker switches
6321 for J in Linker_Switches.First .. Linker_Switches.Last loop
6325 elsif Non_Std_Executable
6326 and then Linker_Switches.Table (J).all = "-o"
6330 -- Here we capture and duplicate the linker argument. We
6331 -- need to do the duplication since the arguments will
6332 -- get normalized. Not doing so will result in calling
6333 -- normalized two times for the same set of arguments if
6334 -- gnatmake is passed multiple mains. This can result in
6335 -- the wrong argument being passed to the linker.
6338 Last_Arg := Last_Arg + 1;
6340 new String'(Linker_Switches.Table (J).all);
6344 -- If need be, add the -o switch
6346 if Non_Std_Executable then
6347 Last_Arg := Last_Arg + 1;
6348 Args (Last_Arg) := new String'("-o");
6349 Last_Arg := Last_Arg + 1;
6351 new String'(Get_Name_String (Executable));
6354 -- And invoke the linker
6357 Success : Boolean := False;
6359 Link (Main_ALI_File,
6360 Link_With_Shared_Libgcc.all &
6361 Args (Args'First .. Last_Arg),
6365 Successful_Links.Increment_Last;
6366 Successful_Links.Table (Successful_Links.Last) :=
6369 elsif Osint.Number_Of_Files = 1 or not Keep_Going then
6370 Make_Failed ("*** link failed.");
6374 Write_Line ("*** link failed");
6376 if Commands_To_Stdout then
6377 Set_Standard_Output;
6380 Failed_Links.Increment_Last;
6381 Failed_Links.Table (Failed_Links.Last) :=
6387 Linker_Switches.Set_Last (Linker_Switches_Last);
6391 -- We go to here when we skip the bind and link steps
6395 -- We go to the next main, if we did not process the last one
6397 if N_File < Osint.Number_Of_Files then
6398 Main_Source_File := Next_Main_Source;
6400 if Current_File_Index /= No_Index then
6401 Main_Index := Current_File_Index;
6404 if Main_Project /= No_Project then
6406 -- Find the file name of the main unit
6409 Main_Source_File_Name : constant String :=
6410 Get_Name_String (Main_Source_File);
6412 Main_Unit_File_Name : constant String :=
6414 File_Name_Of_Library_Unit_Body
6415 (Name => Main_Source_File_Name,
6416 Project => Main_Project,
6417 In_Tree => Project_Tree,
6418 Main_Project_Only =>
6419 not Unique_Compile);
6421 The_Packages : constant Package_Id :=
6422 Main_Project.Decl.Packages;
6424 Binder_Package : constant Prj.Package_Id :=
6426 (Name => Name_Binder,
6427 In_Packages => The_Packages,
6428 In_Tree => Project_Tree);
6430 Linker_Package : constant Prj.Package_Id :=
6432 (Name => Name_Linker,
6433 In_Packages => The_Packages,
6434 In_Tree => Project_Tree);
6437 -- We fail if we cannot find the main source file
6438 -- as an immediate source of the main project file.
6440 if Main_Unit_File_Name = "" then
6441 Make_Failed ('"' & Main_Source_File_Name
6442 & """ is not a unit of project "
6443 & Project_File_Name.all & ".");
6446 -- Remove any directory information from the main
6447 -- source file name.
6450 Pos : Natural := Main_Unit_File_Name'Last;
6454 exit when Pos < Main_Unit_File_Name'First
6456 Main_Unit_File_Name (Pos) = Directory_Separator;
6460 Name_Len := Main_Unit_File_Name'Last - Pos;
6462 Name_Buffer (1 .. Name_Len) :=
6464 (Pos + 1 .. Main_Unit_File_Name'Last);
6466 Main_Source_File := Name_Find;
6470 -- We now deal with the binder and linker switches.
6471 -- If no project file is used, there is nothing to do
6472 -- because the binder and linker switches are the same
6475 -- Reset the tables Binder_Switches and Linker_Switches
6477 Binder_Switches.Set_Last (Last_Binder_Switch);
6478 Linker_Switches.Set_Last (Last_Linker_Switch);
6480 -- Add binder switches from the project file for this main,
6483 if Do_Bind_Step and Binder_Package /= No_Package then
6484 if Verbose_Mode then
6485 Write_Str ("Adding binder switches for """);
6486 Write_Str (Main_Unit_File_Name);
6491 (File_Name => Main_Unit_File_Name,
6492 Index => Main_Index,
6493 The_Package => Binder_Package,
6497 -- Add linker switches from the project file for this main,
6500 if Do_Link_Step and Linker_Package /= No_Package then
6501 if Verbose_Mode then
6502 Write_Str ("Adding linker switches for""");
6503 Write_Str (Main_Unit_File_Name);
6508 (File_Name => Main_Unit_File_Name,
6509 Index => Main_Index,
6510 The_Package => Linker_Package,
6514 -- As we are using a project file, for relative paths we add
6515 -- the current working directory for any relative path on
6516 -- the command line and the project directory, for any
6517 -- relative path in the project file.
6520 Dir_Path : constant String :=
6522 (Main_Project.Directory.Name);
6526 J in Last_Binder_Switch + 1 .. Binder_Switches.Last
6528 Test_If_Relative_Path
6529 (Binder_Switches.Table (J),
6530 Parent => Dir_Path, Including_L_Switch => False);
6534 J in Last_Linker_Switch + 1 .. Linker_Switches.Last
6536 Test_If_Relative_Path
6537 (Linker_Switches.Table (J), Parent => Dir_Path);
6541 -- We now put in the Binder_Switches and Linker_Switches
6542 -- tables, the binder and linker switches of the command
6543 -- line that have been put in the Saved_ tables.
6544 -- These switches will follow the project file switches.
6546 for J in 1 .. Saved_Binder_Switches.Last loop
6548 (Saved_Binder_Switches.Table (J),
6553 for J in 1 .. Saved_Linker_Switches.Last loop
6555 (Saved_Linker_Switches.Table (J),
6563 -- Remove all marks to be sure to check sources for all executables,
6564 -- as the switches may be different and -s may be in use.
6567 end loop Multiple_Main_Loop;
6569 if Failed_Links.Last > 0 then
6570 for Index in 1 .. Successful_Links.Last loop
6571 Write_Str ("Linking of """);
6572 Write_Str (Get_Name_String (Successful_Links.Table (Index)));
6573 Write_Line (""" succeeded.");
6578 for Index in 1 .. Failed_Links.Last loop
6579 Write_Str ("Linking of """);
6580 Write_Str (Get_Name_String (Failed_Links.Table (Index)));
6581 Write_Line (""" failed.");
6584 if Commands_To_Stdout then
6585 Set_Standard_Output;
6588 if Total_Compilation_Failures = 0 then
6589 Report_Compilation_Failed;
6593 if Total_Compilation_Failures /= 0 then
6594 List_Bad_Compilations;
6595 Report_Compilation_Failed;
6598 -- Delete the temporary mapping file that was created if we are
6599 -- using project files.
6601 Delete_All_Temp_Files;
6606 Write_Line (Exception_Information (X));
6607 Make_Failed ("INTERNAL ERROR. Please report.");
6614 function Hash (F : File_Name_Type) return Header_Num is
6616 return Header_Num (1 + F mod Max_Header);
6619 --------------------
6620 -- In_Ada_Lib_Dir --
6621 --------------------
6623 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean is
6624 D : constant File_Name_Type := Get_Directory (File);
6625 B : constant Byte := Get_Name_Table_Byte (D);
6627 return (B and Ada_Lib_Dir) /= 0;
6630 -----------------------
6631 -- Init_Mapping_File --
6632 -----------------------
6634 procedure Init_Mapping_File
6635 (Project : Project_Id;
6636 Data : in out Project_Compilation_Data;
6637 File_Index : in out Natural)
6639 FD : File_Descriptor;
6641 -- For call to Close
6644 -- Increase the index of the last mapping file for this project
6646 Data.Last_Mapping_File_Names := Data.Last_Mapping_File_Names + 1;
6648 -- If there is a project file, call Create_Mapping_File with
6651 if Project /= No_Project then
6652 Prj.Env.Create_Mapping_File
6654 In_Tree => Project_Tree,
6655 Language => No_Name,
6656 Name => Data.Mapping_File_Names
6657 (Data.Last_Mapping_File_Names));
6659 -- Otherwise, just create an empty file
6662 Tempdir.Create_Temp_File
6664 Data.Mapping_File_Names (Data.Last_Mapping_File_Names));
6666 if FD = Invalid_FD then
6667 Make_Failed ("disk full");
6671 (Data.Mapping_File_Names (Data.Last_Mapping_File_Names));
6677 Make_Failed ("disk full");
6681 -- And return the index of the newly created file
6683 File_Index := Data.Last_Mapping_File_Names;
6684 end Init_Mapping_File;
6692 First_Q_Initialization := False;
6694 Q.Set_Last (Q.First);
6701 procedure Initialize is
6703 procedure Check_Version_And_Help is
6704 new Check_Version_And_Help_G (Makeusg);
6706 -- Start of processing for Initialize
6709 Prj.Set_Mode (Ada_Only);
6711 -- Override default initialization of Check_Object_Consistency since
6712 -- this is normally False for GNATBIND, but is True for GNATMAKE since
6713 -- we do not need to check source consistency again once GNATMAKE has
6714 -- looked at the sources to check.
6716 Check_Object_Consistency := True;
6718 -- Package initializations. The order of calls is important here
6720 Output.Set_Standard_Error;
6723 Binder_Switches.Init;
6724 Linker_Switches.Init;
6731 Prj.Initialize (Project_Tree);
6735 RTS_Specified := null;
6739 -- Add the directory where gnatmake is invoked in front of the
6740 -- path, if gnatmake is invoked from a bin directory or with directory
6741 -- information. Only do this if the platform is not VMS, where the
6742 -- notion of path does not really exist.
6746 Prefix : constant String := Executable_Prefix_Path;
6747 Command : constant String := Command_Name;
6750 if Prefix'Length > 0 then
6752 PATH : constant String :=
6753 Prefix & Directory_Separator & "bin" &
6755 Getenv ("PATH").all;
6757 Setenv ("PATH", PATH);
6761 for Index in reverse Command'Range loop
6762 if Command (Index) = Directory_Separator then
6764 Absolute_Dir : constant String :=
6766 (Command (Command'First .. Index));
6767 PATH : constant String :=
6770 Getenv ("PATH").all;
6772 Setenv ("PATH", PATH);
6782 -- Scan the switches and arguments
6784 -- First, scan to detect --version and/or --help
6786 Check_Version_And_Help ("GNATMAKE", "1995");
6788 -- Scan again the switch and arguments, now that we are sure that they
6789 -- do not include --version or --help.
6791 Scan_Args : for Next_Arg in 1 .. Argument_Count loop
6792 Scan_Make_Arg (Argument (Next_Arg), And_Save => True);
6795 if Commands_To_Stdout then
6796 Set_Standard_Output;
6799 if Usage_Requested then
6803 -- Test for trailing -P switch
6805 if Project_File_Name_Present and then Project_File_Name = null then
6806 Make_Failed ("project file name missing after -P");
6808 -- Test for trailing -o switch
6810 elsif Output_File_Name_Present
6811 and then not Output_File_Name_Seen
6813 Make_Failed ("output file name missing after -o");
6815 -- Test for trailing -D switch
6817 elsif Object_Directory_Present
6818 and then not Object_Directory_Seen then
6819 Make_Failed ("object directory missing after -D");
6822 -- Test for simultaneity of -i and -D
6824 if Object_Directory_Path /= null and then In_Place_Mode then
6825 Make_Failed ("-i and -D cannot be used simultaneously");
6828 -- Deal with -C= switch
6830 if Gnatmake_Mapping_File /= null then
6832 -- First, check compatibility with other switches
6834 if Project_File_Name /= null then
6835 Make_Failed ("-C= switch is not compatible with -P switch");
6837 elsif Saved_Maximum_Processes > 1 then
6838 Make_Failed ("-C= switch is not compatible with -jnnn switch");
6841 Fmap.Initialize (Gnatmake_Mapping_File.all);
6843 ("-gnatem=" & Gnatmake_Mapping_File.all,
6848 if Project_File_Name /= null then
6850 -- A project file was specified by a -P switch
6852 if Verbose_Mode then
6854 Write_Str ("Parsing project file """);
6855 Write_Str (Project_File_Name.all);
6860 -- Avoid looking in the current directory for ALI files
6862 -- Look_In_Primary_Dir := False;
6864 -- Set the project parsing verbosity to whatever was specified
6865 -- by a possible -vP switch.
6867 Prj.Pars.Set_Verbosity (To => Current_Verbosity);
6869 -- Parse the project file.
6870 -- If there is an error, Main_Project will still be No_Project.
6873 (Project => Main_Project,
6874 In_Tree => Project_Tree,
6875 Project_File_Name => Project_File_Name.all,
6876 Packages_To_Check => Packages_To_Check_By_Gnatmake,
6877 Is_Config_File => False);
6879 -- The parsing of project files may have changed the current output
6881 if Commands_To_Stdout then
6882 Set_Standard_Output;
6887 if Main_Project = No_Project then
6889 ("""" & Project_File_Name.all & """ processing failed");
6892 Create_Mapping_File := True;
6894 if Verbose_Mode then
6896 Write_Str ("Parsing of project file """);
6897 Write_Str (Project_File_Name.all);
6898 Write_Str (""" is finished.");
6902 -- We add the source directories and the object directories
6903 -- to the search paths.
6905 Add_Source_Directories (Main_Project, Project_Tree);
6906 Add_Object_Directories (Main_Project);
6908 Recursive_Compute_Depth (Main_Project);
6910 -- For each project compute the list of the projects it imports
6911 -- directly or indirectly.
6914 Proj : Project_List;
6916 Proj := Project_Tree.Projects;
6917 while Proj /= null loop
6918 Compute_All_Imported_Projects (Proj.Project);
6925 Osint.Add_Default_Search_Dirs;
6927 -- Source file lookups should be cached for efficiency. Source files
6928 -- are not supposed to change. However, we do that now only if no
6929 -- project file is used; if a project file is used, we do it just
6930 -- after changing the directory to the object directory.
6932 Osint.Source_File_Data (Cache => True);
6934 -- Read gnat.adc file to initialize Fname.UF
6936 Fname.UF.Initialize;
6939 Fname.SF.Read_Source_File_Name_Pragmas;
6942 when Err : SFN_Scan.Syntax_Error_In_GNAT_ADC =>
6943 Make_Failed (Exception_Message (Err));
6947 -- Make sure no project object directory is recorded
6949 Project_Of_Current_Object_Directory := No_Project;
6953 ----------------------------
6954 -- Insert_Project_Sources --
6955 ----------------------------
6957 procedure Insert_Project_Sources
6958 (The_Project : Project_Id;
6959 All_Projects : Boolean;
6962 Put_In_Q : Boolean := Into_Q;
6964 Sfile : File_Name_Type;
6967 Extending : constant Boolean := The_Project.Extends /= No_Project;
6969 function Check_Project (P : Project_Id) return Boolean;
6970 -- Returns True if P is The_Project or a project extended by The_Project
6976 function Check_Project (P : Project_Id) return Boolean is
6978 if All_Projects or P = The_Project then
6981 elsif Extending then
6986 Proj := The_Project;
6987 while Proj /= null loop
6988 if P = Proj.Extends then
6992 Proj := Proj.Extends;
7000 -- Start of processing for Insert_Project_Sources
7003 -- For all the sources in the project files,
7005 for Id in Unit_Table.First ..
7006 Unit_Table.Last (Project_Tree.Units)
7008 Unit := Project_Tree.Units.Table (Id);
7012 -- If there is a source for the body, and the body has not been
7015 if Unit.File_Names (Body_Part).Name /= No_File
7016 and then Unit.File_Names (Body_Part).Path.Name /= Slash
7018 -- And it is a source for the specified project
7020 if Check_Project (Unit.File_Names (Body_Part).Project) then
7022 -- If we don't have a spec, we cannot consider the source
7023 -- if it is a subunit.
7025 if Unit.File_Names (Specification).Name = No_File then
7027 Src_Ind : Source_File_Index;
7029 -- Here we are cheating a little bit: we don't want to
7030 -- use Sinput.L, because it depends on the GNAT tree
7031 -- (Atree, Sinfo, ...). So, we pretend that it is a
7032 -- project file, and we use Sinput.P.
7034 -- Source_File_Is_Subunit is just scanning through the
7035 -- file until it finds one of the reserved words
7036 -- separate, procedure, function, generic or package.
7037 -- Fortunately, these Ada reserved words are also
7038 -- reserved for project files.
7041 Src_Ind := Sinput.P.Load_Project_File
7043 (Unit.File_Names (Body_Part).Path.Name));
7045 -- If it is a subunit, discard it
7047 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
7051 Sfile := Unit.File_Names (Body_Part).Display_Name;
7052 Index := Unit.File_Names (Body_Part).Index;
7057 Sfile := Unit.File_Names (Body_Part).Display_Name;
7058 Index := Unit.File_Names (Body_Part).Index;
7062 elsif Unit.File_Names (Specification).Name /= No_File
7063 and then Unit.File_Names (Specification).Path.Name /= Slash
7064 and then Check_Project (Unit.File_Names (Specification).Project)
7066 -- If there is no source for the body, but there is a source
7067 -- for the spec which has not been locally removed, then we take
7070 Sfile := Unit.File_Names (Specification).Display_Name;
7071 Index := Unit.File_Names (Specification).Index;
7074 -- If Put_In_Q is True, we insert into the Q
7078 -- For the first source inserted into the Q, we need to initialize
7079 -- the Q, but not for the subsequent sources.
7081 if First_Q_Initialization then
7085 -- And of course, only insert in the Q if the source is not marked
7087 if Sfile /= No_File and then not Is_Marked (Sfile, Index) then
7088 if Verbose_Mode then
7089 Write_Str ("Adding """);
7090 Write_Str (Get_Name_String (Sfile));
7091 Write_Line (""" to the queue");
7094 Insert_Q (Sfile, Index => Index);
7095 Mark (Sfile, Index);
7098 elsif Sfile /= No_File then
7100 -- If Put_In_Q is False, we add the source as if it were specified
7101 -- on the command line, and we set Put_In_Q to True, so that the
7102 -- following sources will be put directly in the queue. This will
7103 -- allow parallel compilation processes if -jx switch is used.
7105 if Verbose_Mode then
7106 Write_Str ("Adding """);
7107 Write_Str (Get_Name_String (Sfile));
7108 Write_Line (""" as if on the command line");
7111 Osint.Add_File (Get_Name_String (Sfile), Index);
7114 -- As we may look into the Q later, ensure the Q has been
7115 -- initialized to avoid errors.
7117 if First_Q_Initialization then
7122 end Insert_Project_Sources;
7129 (Source_File : File_Name_Type;
7130 Source_Unit : Unit_Name_Type := No_Unit_Name;
7134 if Debug.Debug_Flag_Q then
7135 Write_Str (" Q := Q + [ ");
7136 Write_Name (Source_File);
7148 (File => Source_File,
7149 Unit => Source_Unit,
7154 ---------------------
7155 -- Is_In_Obsoleted --
7156 ---------------------
7158 function Is_In_Obsoleted (F : File_Name_Type) return Boolean is
7165 Name : constant String := Get_Name_String (F);
7167 F2 : File_Name_Type;
7171 while First > Name'First
7172 and then Name (First - 1) /= Directory_Separator
7173 and then Name (First - 1) /= '/'
7178 if First /= Name'First then
7180 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
7187 return Obsoleted.Get (F2);
7190 end Is_In_Obsoleted;
7192 ----------------------------
7193 -- Is_In_Object_Directory --
7194 ----------------------------
7196 function Is_In_Object_Directory
7197 (Source_File : File_Name_Type;
7198 Full_Lib_File : File_Name_Type) return Boolean
7201 -- There is something to check only when using project files. Otherwise,
7202 -- this function returns True (last line of the function).
7204 if Main_Project /= No_Project then
7206 Source_File_Name : constant String :=
7207 Get_Name_String (Source_File);
7208 Saved_Verbosity : constant Verbosity := Current_Verbosity;
7209 Project : Project_Id := No_Project;
7211 Path_Name : Path_Name_Type := No_Path;
7212 pragma Warnings (Off, Path_Name);
7215 -- Call Get_Reference to know the ultimate extending project of
7216 -- the source. Call it with verbosity default to avoid verbose
7219 Current_Verbosity := Default;
7220 Prj.Env.Get_Reference
7221 (Source_File_Name => Source_File_Name,
7223 In_Tree => Project_Tree,
7225 Current_Verbosity := Saved_Verbosity;
7227 -- If this source is in a project, check that the ALI file is in
7228 -- its object directory. If it is not, return False, so that the
7229 -- ALI file will not be skipped.
7231 if Project /= No_Project then
7233 Object_Directory : constant String :=
7237 Object_Directory.Display_Name));
7239 Olast : Natural := Object_Directory'Last;
7241 Lib_File_Directory : constant String :=
7242 Normalize_Pathname (Dir_Name
7243 (Get_Name_String (Full_Lib_File)));
7245 Llast : Natural := Lib_File_Directory'Last;
7248 -- For directories, Normalize_Pathname may or may not put
7249 -- a directory separator at the end, depending on its input.
7250 -- Remove any last directory separator before comparison.
7251 -- Returns True only if the two directories are the same.
7253 if Object_Directory (Olast) = Directory_Separator then
7257 if Lib_File_Directory (Llast) = Directory_Separator then
7261 return Object_Directory (Object_Directory'First .. Olast) =
7262 Lib_File_Directory (Lib_File_Directory'First .. Llast);
7268 -- When the source is not in a project file, always return True
7271 end Is_In_Object_Directory;
7278 (ALI_File : File_Name_Type;
7279 Args : Argument_List;
7280 Success : out Boolean)
7282 Link_Args : Argument_List (1 .. Args'Length + 1);
7285 Get_Name_String (ALI_File);
7286 Link_Args (1) := new String'(Name_Buffer (1 .. Name_Len));
7288 Link_Args (2 .. Args'Length + 1) := Args;
7290 GNAT.OS_Lib.Normalize_Arguments (Link_Args);
7292 Display (Gnatlink.all, Link_Args);
7294 if Gnatlink_Path = null then
7295 Make_Failed ("error, unable to locate " & Gnatlink.all);
7298 GNAT.OS_Lib.Spawn (Gnatlink_Path.all, Link_Args, Success);
7301 ---------------------------
7302 -- List_Bad_Compilations --
7303 ---------------------------
7305 procedure List_Bad_Compilations is
7307 for J in Bad_Compilation.First .. Bad_Compilation.Last loop
7308 if Bad_Compilation.Table (J).File = No_File then
7310 elsif not Bad_Compilation.Table (J).Found then
7311 Inform (Bad_Compilation.Table (J).File, "not found");
7313 Inform (Bad_Compilation.Table (J).File, "compilation error");
7316 end List_Bad_Compilations;
7322 procedure List_Depend is
7323 Lib_Name : File_Name_Type;
7324 Obj_Name : File_Name_Type;
7325 Src_Name : File_Name_Type;
7329 Line_Size : constant := 77;
7332 Set_Standard_Output;
7334 for A in ALIs.First .. ALIs.Last loop
7335 Lib_Name := ALIs.Table (A).Afile;
7337 -- We have to provide the full library file name in In_Place_Mode
7339 if In_Place_Mode then
7340 Lib_Name := Full_Lib_File_Name (Lib_Name);
7343 Obj_Name := Object_File_Name (Lib_Name);
7344 Write_Name (Obj_Name);
7347 Get_Name_String (Obj_Name);
7349 Line_Pos := Len + 2;
7351 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
7352 Src_Name := Sdep.Table (D).Sfile;
7354 if Is_Internal_File_Name (Src_Name)
7355 and then not Check_Readonly_Files
7359 if not Quiet_Output then
7360 Src_Name := Full_Source_Name (Src_Name);
7363 Get_Name_String (Src_Name);
7366 if Line_Pos + Len + 1 > Line_Size then
7372 Line_Pos := Line_Pos + Len + 1;
7375 Write_Name (Src_Name);
7382 if not Commands_To_Stdout then
7391 procedure Make_Failed (S : String) is
7393 Delete_All_Temp_Files;
7397 --------------------
7398 -- Mark_Directory --
7399 --------------------
7401 procedure Mark_Directory
7403 Mark : Lib_Mark_Type;
7404 On_Command_Line : Boolean)
7409 function Base_Directory return String;
7410 -- If Dir comes from the command line, empty string (relative paths
7411 -- are resolved with respect to the current directory), else return
7412 -- the main project's directory.
7414 --------------------
7415 -- Base_Directory --
7416 --------------------
7418 function Base_Directory return String is
7420 if On_Command_Line then
7423 return Get_Name_String (Main_Project.Directory.Display_Name);
7427 Real_Path : constant String := Normalize_Pathname (Dir, Base_Directory);
7429 -- Start of processing for Mark_Directory
7434 if Real_Path'Length = 0 then
7435 Add_Str_To_Name_Buffer (Dir);
7438 Add_Str_To_Name_Buffer (Real_Path);
7441 -- Last character is supposed to be a directory separator
7443 if not Is_Directory_Separator (Name_Buffer (Name_Len)) then
7444 Add_Char_To_Name_Buffer (Directory_Separator);
7447 -- Add flags to the already existing flags
7450 B := Get_Name_Table_Byte (N);
7451 Set_Name_Table_Byte (N, B or Mark);
7454 -----------------------------
7455 -- Recursive_Compute_Depth --
7456 -----------------------------
7458 procedure Recursive_Compute_Depth (Project : Project_Id) is
7459 use Project_Boolean_Htable;
7460 Seen : Project_Boolean_Htable.Instance := Project_Boolean_Htable.Nil;
7462 procedure Recurse (Prj : Project_Id; Depth : Natural);
7468 procedure Recurse (Prj : Project_Id; Depth : Natural) is
7469 List : Project_List;
7473 if Prj.Depth >= Depth or else Get (Seen, Prj) then
7477 -- We need a test to avoid infinite recursions with limited withs:
7478 -- If we have A -> B -> A, then when set level of A to n, we try and
7479 -- set level of B to n+1, and then level of A to n + 2, ...
7481 Set (Seen, Prj, True);
7485 -- Visit each imported project
7487 List := Prj.Imported_Projects;
7488 while List /= null loop
7489 Proj := List.Project;
7491 Recurse (Prj => Proj, Depth => Depth + 1);
7494 -- We again allow changing the depth of this project later on if it
7495 -- is in fact imported by a lower-level project.
7497 Set (Seen, Prj, False);
7500 Proj : Project_List;
7502 -- Start of processing for Recursive_Compute_Depth
7505 Proj := Project_Tree.Projects;
7506 while Proj /= null loop
7507 Proj.Project.Depth := 0;
7511 Recurse (Project, Depth => 1);
7513 end Recursive_Compute_Depth;
7515 -------------------------------
7516 -- Report_Compilation_Failed --
7517 -------------------------------
7519 procedure Report_Compilation_Failed is
7521 Delete_All_Temp_Files;
7522 Exit_Program (E_Fatal);
7523 end Report_Compilation_Failed;
7525 ------------------------
7526 -- Sigint_Intercepted --
7527 ------------------------
7529 procedure Sigint_Intercepted is
7530 SIGINT : constant := 2;
7534 Write_Line ("*** Interrupted ***");
7536 -- Send SIGINT to all outstanding compilation processes spawned
7538 for J in 1 .. Outstanding_Compiles loop
7539 Kill (Running_Compile (J).Pid, SIGINT, 1);
7542 Delete_All_Temp_Files;
7544 -- ??? OS_Exit (1) is equivalent to Exit_Program (E_No_Compile),
7545 -- shouldn't that be Exit_Program (E_Abort) instead?
7546 end Sigint_Intercepted;
7552 procedure Scan_Make_Arg (Argv : String; And_Save : Boolean) is
7556 Gnatmake_Switch_Found := True;
7558 pragma Assert (Argv'First = 1);
7560 if Argv'Length = 0 then
7564 -- If the previous switch has set the Project_File_Name_Present flag
7565 -- (that is we have seen a -P alone), then the next argument is the name
7566 -- of the project file.
7568 if Project_File_Name_Present and then Project_File_Name = null then
7569 if Argv (1) = '-' then
7570 Make_Failed ("project file name missing after -P");
7573 Project_File_Name_Present := False;
7574 Project_File_Name := new String'(Argv);
7577 -- If the previous switch has set the Output_File_Name_Present flag
7578 -- (that is we have seen a -o), then the next argument is the name of
7579 -- the output executable.
7581 elsif Output_File_Name_Present
7582 and then not Output_File_Name_Seen
7584 Output_File_Name_Seen := True;
7586 if Argv (1) = '-' then
7587 Make_Failed ("output file name missing after -o");
7590 Add_Switch ("-o", Linker, And_Save => And_Save);
7591 Add_Switch (Executable_Name (Argv), Linker, And_Save => And_Save);
7594 -- If the previous switch has set the Object_Directory_Present flag
7595 -- (that is we have seen a -D), then the next argument is the path name
7596 -- of the object directory..
7598 elsif Object_Directory_Present
7599 and then not Object_Directory_Seen
7601 Object_Directory_Seen := True;
7603 if Argv (1) = '-' then
7604 Make_Failed ("object directory path name missing after -D");
7606 elsif not Is_Directory (Argv) then
7607 Make_Failed ("cannot find object directory """ & Argv & """");
7610 Add_Lib_Search_Dir (Argv);
7612 -- Specify the object directory to the binder
7614 Add_Switch ("-aO" & Argv, Binder, And_Save => And_Save);
7616 -- Record the object directory. Make sure it ends with a directory
7619 if Argv (Argv'Last) = Directory_Separator then
7620 Object_Directory_Path :=
7623 Object_Directory_Path :=
7624 new String'(Argv & Directory_Separator);
7628 -- Then check if we are dealing with -cargs/-bargs/-largs/-margs
7630 elsif Argv = "-bargs"
7639 when 'c' => Program_Args := Compiler;
7640 when 'b' => Program_Args := Binder;
7641 when 'l' => Program_Args := Linker;
7642 when 'm' => Program_Args := None;
7645 raise Program_Error;
7648 -- A special test is needed for the -o switch within a -largs
7649 -- since that is another way to specify the name of the final
7652 elsif Program_Args = Linker
7653 and then Argv = "-o"
7655 Make_Failed ("switch -o not allowed within a -largs. " &
7656 "Use -o directly.");
7658 -- Check to see if we are reading switches after a -cargs,
7659 -- -bargs or -largs switch. If yes save it.
7661 elsif Program_Args /= None then
7663 -- Check to see if we are reading -I switches in order
7664 -- to take into account in the src & lib search directories.
7666 if Argv'Length > 2 and then Argv (1 .. 2) = "-I" then
7667 if Argv (3 .. Argv'Last) = "-" then
7668 Look_In_Primary_Dir := False;
7670 elsif Program_Args = Compiler then
7671 if Argv (3 .. Argv'Last) /= "-" then
7672 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7675 elsif Program_Args = Binder then
7676 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7680 Add_Switch (Argv, Program_Args, And_Save => And_Save);
7682 -- Handle non-default compiler, binder, linker, and handle --RTS switch
7684 elsif Argv'Length > 2 and then Argv (1 .. 2) = "--" then
7686 and then Argv (1 .. 6) = "--GCC="
7689 Program_Args : constant Argument_List_Access :=
7690 Argument_String_To_List
7691 (Argv (7 .. Argv'Last));
7695 Saved_Gcc := new String'(Program_Args.all (1).all);
7697 Gcc := new String'(Program_Args.all (1).all);
7700 for J in 2 .. Program_Args.all'Last loop
7702 (Program_Args.all (J).all,
7704 And_Save => And_Save);
7708 elsif Argv'Length > 11
7709 and then Argv (1 .. 11) = "--GNATBIND="
7712 Program_Args : constant Argument_List_Access :=
7713 Argument_String_To_List
7714 (Argv (12 .. Argv'Last));
7718 Saved_Gnatbind := new String'(Program_Args.all (1).all);
7720 Gnatbind := new String'(Program_Args.all (1).all);
7723 for J in 2 .. Program_Args.all'Last loop
7725 (Program_Args.all (J).all, Binder, And_Save => And_Save);
7729 elsif Argv'Length > 11
7730 and then Argv (1 .. 11) = "--GNATLINK="
7733 Program_Args : constant Argument_List_Access :=
7734 Argument_String_To_List
7735 (Argv (12 .. Argv'Last));
7738 Saved_Gnatlink := new String'(Program_Args.all (1).all);
7740 Gnatlink := new String'(Program_Args.all (1).all);
7743 for J in 2 .. Program_Args.all'Last loop
7744 Add_Switch (Program_Args.all (J).all, Linker);
7748 elsif Argv'Length >= 5 and then
7749 Argv (1 .. 5) = "--RTS"
7751 Add_Switch (Argv, Compiler, And_Save => And_Save);
7752 Add_Switch (Argv, Binder, And_Save => And_Save);
7754 if Argv'Length <= 6 or else Argv (6) /= '=' then
7755 Make_Failed ("missing path for --RTS");
7758 -- Check that this is the first time we see this switch or
7759 -- if it is not the first time, the same path is specified.
7761 if RTS_Specified = null then
7762 RTS_Specified := new String'(Argv (7 .. Argv'Last));
7764 elsif RTS_Specified.all /= Argv (7 .. Argv'Last) then
7765 Make_Failed ("--RTS cannot be specified multiple times");
7768 -- Valid --RTS switch
7775 Src_Path_Name : constant String_Ptr :=
7777 (Argv (7 .. Argv'Last), Include);
7779 Lib_Path_Name : constant String_Ptr :=
7781 (Argv (7 .. Argv'Last), Objects);
7784 if Src_Path_Name /= null
7785 and then Lib_Path_Name /= null
7787 -- Set RTS_*_Path_Name variables, so that correct direct-
7788 -- ories will be set when Osint.Add_Default_Search_Dirs
7791 RTS_Src_Path_Name := Src_Path_Name;
7792 RTS_Lib_Path_Name := Lib_Path_Name;
7794 elsif Src_Path_Name = null
7795 and Lib_Path_Name = null
7797 Make_Failed ("RTS path not valid: missing " &
7798 "adainclude and adalib directories");
7800 elsif Src_Path_Name = null then
7801 Make_Failed ("RTS path not valid: missing adainclude " &
7804 elsif Lib_Path_Name = null then
7805 Make_Failed ("RTS path not valid: missing adalib " &
7811 elsif Argv'Length >= 8 and then
7812 Argv (1 .. 8) = "--param="
7814 Add_Switch (Argv, Compiler, And_Save => And_Save);
7815 Add_Switch (Argv, Linker, And_Save => And_Save);
7818 Scan_Make_Switches (Argv, Success);
7821 -- If we have seen a regular switch process it
7823 elsif Argv (1) = '-' then
7824 if Argv'Length = 1 then
7825 Make_Failed ("switch character cannot be followed by a blank");
7827 -- Incorrect switches that should start with "--"
7829 elsif (Argv'Length > 5 and then Argv (1 .. 5) = "-RTS=")
7830 or else (Argv'Length > 5 and then Argv (1 .. 5) = "-GCC=")
7831 or else (Argv'Length > 8 and then Argv (1 .. 7) = "-param=")
7832 or else (Argv'Length > 10 and then Argv (1 .. 10) = "-GNATLINK=")
7833 or else (Argv'Length > 10 and then Argv (1 .. 10) = "-GNATBIND=")
7835 Make_Failed ("option " & Argv & " should start with '--'");
7839 elsif Argv (2 .. Argv'Last) = "I-" then
7840 Look_In_Primary_Dir := False;
7842 -- Forbid -?- or -??- where ? is any character
7844 elsif (Argv'Length = 3 and then Argv (3) = '-')
7845 or else (Argv'Length = 4 and then Argv (4) = '-')
7848 ("trailing ""-"" at the end of " & Argv & " forbidden.");
7852 elsif Argv (2) = 'I' then
7853 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7854 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7855 Add_Switch (Argv, Compiler, And_Save => And_Save);
7856 Add_Switch (Argv, Binder, And_Save => And_Save);
7858 -- -aIdir (to gcc this is like a -I switch)
7860 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aI" then
7861 Add_Source_Search_Dir (Argv (4 .. Argv'Last), And_Save);
7862 Add_Switch ("-I" & Argv (4 .. Argv'Last),
7864 And_Save => And_Save);
7865 Add_Switch (Argv, Binder, And_Save => And_Save);
7869 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aO" then
7870 Add_Library_Search_Dir (Argv (4 .. Argv'Last), And_Save);
7871 Add_Switch (Argv, Binder, And_Save => And_Save);
7873 -- -aLdir (to gnatbind this is like a -aO switch)
7875 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aL" then
7876 Mark_Directory (Argv (4 .. Argv'Last), Ada_Lib_Dir, And_Save);
7877 Add_Library_Search_Dir (Argv (4 .. Argv'Last), And_Save);
7878 Add_Switch ("-aO" & Argv (4 .. Argv'Last),
7880 And_Save => And_Save);
7884 elsif Argv'Length >= 13 and then Argv (2 .. 13) = "aamp_target=" then
7885 Add_Switch (Argv, Compiler, And_Save => And_Save);
7887 -- Set the aamp_target environment variable so that the binder and
7888 -- linker will use the proper target library. This is consistent
7889 -- with how things work when -aamp_target is passed on the command
7890 -- line to gnaampmake.
7892 Setenv ("aamp_target", Argv (14 .. Argv'Last));
7894 -- -Adir (to gnatbind this is like a -aO switch, to gcc like a -I)
7896 elsif Argv (2) = 'A' then
7897 Mark_Directory (Argv (3 .. Argv'Last), Ada_Lib_Dir, And_Save);
7898 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7899 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7900 Add_Switch ("-I" & Argv (3 .. Argv'Last),
7902 And_Save => And_Save);
7903 Add_Switch ("-aO" & Argv (3 .. Argv'Last),
7905 And_Save => And_Save);
7909 elsif Argv (2) = 'L' then
7910 Add_Switch (Argv, Linker, And_Save => And_Save);
7912 -- For -gxxxxx, -pg, -mxxx, -fxxx: give the switch to both the
7913 -- compiler and the linker (except for -gnatxxx which is only for
7914 -- the compiler). Some of the -mxxx (for example -m64) and -fxxx
7915 -- (for example -ftest-coverage for gcov) need to be used when
7916 -- compiling the binder generated files, and using all these gcc
7917 -- switches for the binder generated files should not be a problem.
7920 (Argv (2) = 'g' and then (Argv'Last < 5
7921 or else Argv (2 .. 5) /= "gnat"))
7922 or else Argv (2 .. Argv'Last) = "pg"
7923 or else (Argv (2) = 'm' and then Argv'Last > 2)
7924 or else (Argv (2) = 'f' and then Argv'Last > 2)
7926 Add_Switch (Argv, Compiler, And_Save => And_Save);
7927 Add_Switch (Argv, Linker, And_Save => And_Save);
7929 -- -C=<mapping file>
7931 elsif Argv'Last > 2 and then Argv (2) = 'C' then
7933 if Argv (3) /= '=' or else Argv'Last <= 3 then
7934 Make_Failed ("illegal switch " & Argv);
7937 Gnatmake_Mapping_File := new String'(Argv (4 .. Argv'Last));
7942 elsif Argv'Last = 2 and then Argv (2) = 'D' then
7943 if Project_File_Name /= null then
7944 Make_Failed ("-D cannot be used in conjunction with a " &
7948 Scan_Make_Switches (Argv, Success);
7953 elsif Argv (2) = 'd'
7954 and then Argv'Last = 2
7956 Display_Compilation_Progress := True;
7960 elsif Argv'Last = 2 and then Argv (2) = 'i' then
7961 if Project_File_Name /= null then
7962 Make_Failed ("-i cannot be used in conjunction with a " &
7965 Scan_Make_Switches (Argv, Success);
7968 -- -j (need to save the result)
7970 elsif Argv (2) = 'j' then
7971 Scan_Make_Switches (Argv, Success);
7974 Saved_Maximum_Processes := Maximum_Processes;
7979 elsif Argv (2) = 'm'
7980 and then Argv'Last = 2
7982 Minimal_Recompilation := True;
7986 elsif Argv (2) = 'u'
7987 and then Argv'Last = 2
7989 Unique_Compile := True;
7990 Compile_Only := True;
7991 Do_Bind_Step := False;
7992 Do_Link_Step := False;
7996 elsif Argv (2) = 'U'
7997 and then Argv'Last = 2
7999 Unique_Compile_All_Projects := True;
8000 Unique_Compile := True;
8001 Compile_Only := True;
8002 Do_Bind_Step := False;
8003 Do_Link_Step := False;
8005 -- -Pprj or -P prj (only once, and only on the command line)
8007 elsif Argv (2) = 'P' then
8008 if Project_File_Name /= null then
8009 Make_Failed ("cannot have several project files specified");
8011 elsif Object_Directory_Path /= null then
8012 Make_Failed ("-D cannot be used in conjunction with a " &
8015 elsif In_Place_Mode then
8016 Make_Failed ("-i cannot be used in conjunction with a " &
8019 elsif not And_Save then
8021 -- It could be a tool other than gnatmake (i.e, gnatdist)
8022 -- or a -P switch inside a project file.
8025 ("either the tool is not ""project-aware"" or " &
8026 "a project file is specified inside a project file");
8028 elsif Argv'Last = 2 then
8030 -- -P is used alone: the project file name is the next option
8032 Project_File_Name_Present := True;
8035 Project_File_Name := new String'(Argv (3 .. Argv'Last));
8038 -- -vPx (verbosity of the parsing of the project files)
8041 and then Argv (2 .. 3) = "vP"
8042 and then Argv (4) in '0' .. '2'
8047 Current_Verbosity := Prj.Default;
8049 Current_Verbosity := Prj.Medium;
8051 Current_Verbosity := Prj.High;
8057 -- -Xext=val (External assignment)
8059 elsif Argv (2) = 'X'
8060 and then Is_External_Assignment (Argv)
8062 -- Is_External_Assignment has side effects
8063 -- when it returns True;
8067 -- If -gnath is present, then generate the usage information
8068 -- right now and do not pass this option on to the compiler calls.
8070 elsif Argv = "-gnath" then
8073 -- If -gnatc is specified, make sure the bind step and the link
8074 -- step are not executed.
8076 elsif Argv'Length >= 6 and then Argv (2 .. 6) = "gnatc" then
8078 -- If -gnatc is specified, make sure the bind step and the link
8079 -- step are not executed.
8081 Add_Switch (Argv, Compiler, And_Save => And_Save);
8082 Operating_Mode := Check_Semantics;
8083 Check_Object_Consistency := False;
8084 Compile_Only := True;
8085 Do_Bind_Step := False;
8086 Do_Link_Step := False;
8088 elsif Argv (2 .. Argv'Last) = "nostdlib" then
8090 -- Don't pass -nostdlib to gnatlink, it will disable
8091 -- linking with all standard library files.
8095 Add_Switch (Argv, Compiler, And_Save => And_Save);
8096 Add_Switch (Argv, Binder, And_Save => And_Save);
8098 elsif Argv (2 .. Argv'Last) = "nostdinc" then
8100 -- Pass -nostdinc to the Compiler and to gnatbind
8103 Add_Switch (Argv, Compiler, And_Save => And_Save);
8104 Add_Switch (Argv, Binder, And_Save => And_Save);
8106 -- All other switches are processed by Scan_Make_Switches. If the
8107 -- call returns with Gnatmake_Switch_Found = False, then the switch
8108 -- is passed to the compiler.
8111 Scan_Make_Switches (Argv, Gnatmake_Switch_Found);
8113 if not Gnatmake_Switch_Found then
8114 Add_Switch (Argv, Compiler, And_Save => And_Save);
8118 -- If not a switch it must be a file name
8122 Mains.Add_Main (Argv);
8130 function Switches_Of
8131 (Source_File : File_Name_Type;
8132 Source_File_Name : String;
8134 Naming : Naming_Data;
8135 In_Package : Package_Id;
8136 Allow_ALI : Boolean) return Variable_Value
8138 Switches : Variable_Value;
8140 Defaults : constant Array_Element_Id :=
8142 (Name => Name_Default_Switches,
8144 Project_Tree.Packages.Table
8145 (In_Package).Decl.Arrays,
8146 In_Tree => Project_Tree);
8148 Switches_Array : constant Array_Element_Id :=
8150 (Name => Name_Switches,
8152 Project_Tree.Packages.Table
8153 (In_Package).Decl.Arrays,
8154 In_Tree => Project_Tree);
8157 -- First, try Switches (<file name>)
8161 (Index => Name_Id (Source_File),
8162 Src_Index => Source_Index,
8163 In_Array => Switches_Array,
8164 In_Tree => Project_Tree);
8166 -- Check also without the suffix
8168 if Switches = Nil_Variable_Value then
8170 Name : String (1 .. Source_File_Name'Length + 3);
8171 Last : Positive := Source_File_Name'Length;
8172 Spec_Suffix : constant String :=
8173 Spec_Suffix_Of (Project_Tree, "ada", Naming);
8174 Body_Suffix : constant String :=
8175 Body_Suffix_Of (Project_Tree, "ada", Naming);
8176 Truncated : Boolean := False;
8179 Name (1 .. Last) := Source_File_Name;
8181 if Last > Body_Suffix'Length
8182 and then Name (Last - Body_Suffix'Length + 1 .. Last) =
8186 Last := Last - Body_Suffix'Length;
8190 and then Last > Spec_Suffix'Length
8191 and then Name (Last - Spec_Suffix'Length + 1 .. Last) =
8195 Last := Last - Spec_Suffix'Length;
8200 Add_Str_To_Name_Buffer (Name (1 .. Last));
8203 (Index => Name_Find,
8205 In_Array => Switches_Array,
8206 In_Tree => Project_Tree);
8208 if Switches = Nil_Variable_Value and then Allow_ALI then
8209 Last := Source_File_Name'Length;
8211 while Name (Last) /= '.' loop
8216 Add_Str_To_Name_Buffer (Name (1 .. Last));
8217 Add_Str_To_Name_Buffer ("ali");
8221 (Index => Name_Find,
8223 In_Array => Switches_Array,
8224 In_Tree => Project_Tree);
8230 -- Next, try Switches ("Ada")
8232 if Switches = Nil_Variable_Value then
8237 In_Array => Switches_Array,
8238 In_Tree => Project_Tree,
8239 Force_Lower_Case_Index => True);
8241 if Switches /= Nil_Variable_Value then
8242 Switch_May_Be_Passed_To_The_Compiler := False;
8246 -- Next, try Switches (others)
8248 if Switches = Nil_Variable_Value then
8251 (Index => All_Other_Names,
8253 In_Array => Switches_Array,
8254 In_Tree => Project_Tree);
8256 if Switches /= Nil_Variable_Value then
8257 Switch_May_Be_Passed_To_The_Compiler := False;
8261 -- And finally, Default_Switches ("Ada")
8263 if Switches = Nil_Variable_Value then
8268 In_Array => Defaults,
8269 In_Tree => Project_Tree);
8281 if Usage_Needed then
8282 Usage_Needed := False;
8291 procedure Verbose_Msg
8294 N2 : Name_Id := No_Name;
8296 Prefix : String := " -> ";
8297 Minimum_Verbosity : Verbosity_Level_Type := Opt.Low)
8300 if (not Verbose_Mode) or else (Minimum_Verbosity > Verbosity_Level) then
8310 if N2 /= No_Name then
8320 procedure Verbose_Msg
8321 (N1 : File_Name_Type;
8323 N2 : File_Name_Type := No_File;
8325 Prefix : String := " -> ";
8326 Minimum_Verbosity : Verbosity_Level_Type := Opt.Low)
8330 (Name_Id (N1), S1, Name_Id (N2), S2, Prefix, Minimum_Verbosity);
8334 -- Make sure that in case of failure, the temp files will be deleted
8336 Prj.Com.Fail := Make_Failed'Access;
8337 MLib.Fail := Make_Failed'Access;
8338 Makeutl.Do_Fail := Make_Failed'Access;