1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, 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;
31 with Fname; use Fname;
32 with Fname.SF; use Fname.SF;
33 with Fname.UF; use Fname.UF;
34 with Gnatvsn; use Gnatvsn;
35 with Hostparm; use Hostparm;
37 with Makeutl; use Makeutl;
39 with MLib.Tgt; use MLib.Tgt;
41 with Namet; use Namet;
43 with Osint.M; use Osint.M;
44 with Osint; use Osint;
45 with Output; use Output;
53 with Snames; use Snames;
54 with Switch; use Switch;
55 with Switch.M; use Switch.M;
56 with Targparm; use Targparm;
59 with Types; use Types;
61 with Ada.Exceptions; use Ada.Exceptions;
62 with Ada.Command_Line; use Ada.Command_Line;
64 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
65 with GNAT.Case_Util; use GNAT.Case_Util;
66 with GNAT.OS_Lib; use GNAT.OS_Lib;
73 -- Make control characters visible
75 Standard_Library_Package_Body_Name : constant String := "s-stalib.adb";
76 -- Every program depends on this package, that must then be checked,
77 -- especially when -f and -a are used.
79 procedure Kill (Pid : Process_Id; Sig_Num : Integer; Close : Integer);
80 pragma Import (C, Kill, "__gnat_kill");
81 -- Called by Sigint_Intercepted to kill all spawned compilation processes
83 type Sigint_Handler is access procedure;
85 procedure Install_Int_Handler (Handler : Sigint_Handler);
86 pragma Import (C, Install_Int_Handler, "__gnat_install_int_handler");
87 -- Called by Gnatmake to install the SIGINT handler below
89 procedure Sigint_Intercepted;
90 -- Called when the program is interrupted by Ctrl-C to delete the
91 -- temporary mapping files and configuration pragmas files.
93 No_Mapping_File : constant Natural := 0;
95 type Compilation_Data is record
97 Full_Source_File : File_Name_Type;
98 Lib_File : File_Name_Type;
99 Source_Unit : Unit_Name_Type;
100 Mapping_File : Natural := No_Mapping_File;
101 Project : Project_Id := No_Project;
102 Syntax_Only : Boolean := False;
103 Output_Is_Object : Boolean := True;
105 -- Data recorded for each compilation process spawned
107 type Comp_Data_Arr is array (Positive range <>) of Compilation_Data;
108 type Comp_Data_Ptr is access Comp_Data_Arr;
109 Running_Compile : Comp_Data_Ptr;
110 -- Used to save information about outstanding compilations
112 Outstanding_Compiles : Natural := 0;
113 -- Current number of outstanding compiles
115 -------------------------
116 -- Note on terminology --
117 -------------------------
119 -- In this program, we use the phrase "termination" of a file name to refer
120 -- to the suffix that appears after the unit name portion. Very often this
121 -- is simply the extension, but in some cases, the sequence may be more
122 -- complex, for example in main.1.ada, the termination in this name is
123 -- ".1.ada" and in main_.ada the termination is "_.ada".
125 -------------------------------------
126 -- Queue (Q) Manipulation Routines --
127 -------------------------------------
129 -- The Q is used in Compile_Sources below. Its implementation uses the GNAT
130 -- generic package Table (basically an extensible array). Q_Front points to
131 -- the first valid element in the Q, whereas Q.First is the first element
132 -- ever enqueued, while Q.Last - 1 is the last element in the Q.
134 -- +---+--------------+---+---+---+-----------+---+--------
135 -- Q | | ........ | | | | ....... | |
136 -- +---+--------------+---+---+---+-----------+---+--------
138 -- Q.First Q_Front Q.Last - 1
140 -- The elements comprised between Q.First and Q_Front - 1 are the elements
141 -- that have been enqueued and then dequeued, while the elements between
142 -- Q_Front and Q.Last - 1 are the elements currently in the Q. When the Q
143 -- is initialized Q_Front = Q.First = Q.Last. After Compile_Sources has
144 -- terminated its execution, Q_Front = Q.Last and the elements contained
145 -- between Q.Front and Q.Last-1 are those that were explored and thus
146 -- marked by Compile_Sources. Whenever the Q is reinitialized, the elements
147 -- between Q.First and Q.Last - 1 are unmarked.
150 -- Must be called to (re)initialize the Q
153 (Source_File : File_Name_Type;
154 Source_Unit : Unit_Name_Type := No_Unit_Name;
156 -- Inserts Source_File at the end of Q. Provide Source_Unit when possible
157 -- for external use (gnatdist). Provide index for multi-unit sources.
159 function Empty_Q return Boolean;
160 -- Returns True if Q is empty
162 procedure Extract_From_Q
163 (Source_File : out File_Name_Type;
164 Source_Unit : out Unit_Name_Type;
165 Source_Index : out Int);
166 -- Extracts the first element from the Q
168 procedure Insert_Project_Sources
169 (The_Project : Project_Id;
170 All_Projects : Boolean;
172 -- If Into_Q is True, insert all sources of the project file(s) that are
173 -- not already marked into the Q. If Into_Q is False, call Osint.Add_File
174 -- for the first source, then insert all other sources that are not already
175 -- marked into the Q. If All_Projects is True, all sources of all projects
176 -- are concerned; otherwise, only sources of The_Project are concerned,
177 -- including, if The_Project is an extending project, sources inherited
178 -- from projects being extended.
180 First_Q_Initialization : Boolean := True;
181 -- Will be set to false after Init_Q has been called once
184 -- Points to the first valid element in the Q
186 Unique_Compile : Boolean := False;
187 -- Set to True if -u or -U or a project file with no main is used
189 Unique_Compile_All_Projects : Boolean := False;
190 -- Set to True if -U is used
192 RTS_Specified : String_Access := null;
193 -- Used to detect multiple --RTS= switches
195 type Q_Record is record
196 File : File_Name_Type;
197 Unit : Unit_Name_Type;
200 -- File is the name of the file to compile. Unit is for gnatdist
201 -- use in order to easily get the unit name of a file to compile
202 -- when its name is krunched or declared in gnat.adc. Index, when not 0,
203 -- is the index of the unit in a multi-unit source.
205 package Q is new Table.Table (
206 Table_Component_Type => Q_Record,
207 Table_Index_Type => Natural,
208 Table_Low_Bound => 0,
209 Table_Initial => 4000,
210 Table_Increment => 100,
211 Table_Name => "Make.Q");
212 -- This is the actual Q
214 -- The 3 following packages are used to store gcc, gnatbind and gnatlink
215 -- switches found in the project files.
217 package Gcc_Switches is new Table.Table (
218 Table_Component_Type => String_Access,
219 Table_Index_Type => Integer,
220 Table_Low_Bound => 1,
222 Table_Increment => 100,
223 Table_Name => "Make.Gcc_Switches");
225 package Binder_Switches is new Table.Table (
226 Table_Component_Type => String_Access,
227 Table_Index_Type => Integer,
228 Table_Low_Bound => 1,
230 Table_Increment => 100,
231 Table_Name => "Make.Binder_Switches");
233 package Linker_Switches is new Table.Table (
234 Table_Component_Type => String_Access,
235 Table_Index_Type => Integer,
236 Table_Low_Bound => 1,
238 Table_Increment => 100,
239 Table_Name => "Make.Linker_Switches");
241 -- The following instantiations and variables are necessary to save what
242 -- is found on the command line, in case there is a project file specified.
244 package Saved_Gcc_Switches is new Table.Table (
245 Table_Component_Type => String_Access,
246 Table_Index_Type => Integer,
247 Table_Low_Bound => 1,
249 Table_Increment => 100,
250 Table_Name => "Make.Saved_Gcc_Switches");
252 package Saved_Binder_Switches is new Table.Table (
253 Table_Component_Type => String_Access,
254 Table_Index_Type => Integer,
255 Table_Low_Bound => 1,
257 Table_Increment => 100,
258 Table_Name => "Make.Saved_Binder_Switches");
260 package Saved_Linker_Switches is new Table.Table
261 (Table_Component_Type => String_Access,
262 Table_Index_Type => Integer,
263 Table_Low_Bound => 1,
265 Table_Increment => 100,
266 Table_Name => "Make.Saved_Linker_Switches");
268 package Switches_To_Check is new Table.Table (
269 Table_Component_Type => String_Access,
270 Table_Index_Type => Integer,
271 Table_Low_Bound => 1,
273 Table_Increment => 100,
274 Table_Name => "Make.Switches_To_Check");
276 package Library_Paths is new Table.Table (
277 Table_Component_Type => String_Access,
278 Table_Index_Type => Integer,
279 Table_Low_Bound => 1,
281 Table_Increment => 100,
282 Table_Name => "Make.Library_Paths");
284 package Failed_Links is new Table.Table (
285 Table_Component_Type => File_Name_Type,
286 Table_Index_Type => Integer,
287 Table_Low_Bound => 1,
289 Table_Increment => 100,
290 Table_Name => "Make.Failed_Links");
292 package Successful_Links is new Table.Table (
293 Table_Component_Type => File_Name_Type,
294 Table_Index_Type => Integer,
295 Table_Low_Bound => 1,
297 Table_Increment => 100,
298 Table_Name => "Make.Successful_Links");
300 package Library_Projs is new Table.Table (
301 Table_Component_Type => Project_Id,
302 Table_Index_Type => Integer,
303 Table_Low_Bound => 1,
305 Table_Increment => 100,
306 Table_Name => "Make.Library_Projs");
308 -- Two variables to keep the last binder and linker switch index in tables
309 -- Binder_Switches and Linker_Switches, before adding switches from the
310 -- project file (if any) and switches from the command line (if any).
312 Last_Binder_Switch : Integer := 0;
313 Last_Linker_Switch : Integer := 0;
315 Normalized_Switches : Argument_List_Access := new Argument_List (1 .. 10);
316 Last_Norm_Switch : Natural := 0;
318 Saved_Maximum_Processes : Natural := 0;
320 type Arg_List_Ref is access Argument_List;
321 The_Saved_Gcc_Switches : Arg_List_Ref;
323 Project_File_Name : String_Access := null;
324 -- The path name of the main project file, if any
326 Project_File_Name_Present : Boolean := False;
327 -- True when -P is used with a space between -P and the project file name
329 Current_Verbosity : Prj.Verbosity := Prj.Default;
330 -- Verbosity to parse the project files
332 Project_Tree : constant Project_Tree_Ref := new Project_Tree_Data;
334 Main_Project : Prj.Project_Id := No_Project;
335 -- The project id of the main project file, if any
337 Project_Of_Current_Object_Directory : Project_Id := No_Project;
338 -- The object directory of the project for the last compilation. Avoid
339 -- calling Change_Dir if the current working directory is already this
342 -- Packages of project files where unknown attributes are errors
344 Naming_String : aliased String := "naming";
345 Builder_String : aliased String := "builder";
346 Compiler_String : aliased String := "compiler";
347 Binder_String : aliased String := "binder";
348 Linker_String : aliased String := "linker";
350 Gnatmake_Packages : aliased String_List :=
351 (Naming_String 'Access,
352 Builder_String 'Access,
353 Compiler_String 'Access,
354 Binder_String 'Access,
355 Linker_String 'Access);
357 Packages_To_Check_By_Gnatmake : constant String_List_Access :=
358 Gnatmake_Packages'Access;
360 procedure Add_Library_Search_Dir
362 On_Command_Line : Boolean);
363 -- Call Add_Lib_Search_Dir with an absolute directory path. If Path is
364 -- relative path, when On_Command_Line is True, it is relative to the
365 -- current working directory. When On_Command_Line is False, it is relative
366 -- to the project directory of the main project.
368 procedure Add_Source_Search_Dir
370 On_Command_Line : Boolean);
371 -- Call Add_Src_Search_Dir with an absolute directory path. If Path is a
372 -- relative path, when On_Command_Line is True, it is relative to the
373 -- current working directory. When On_Command_Line is False, it is relative
374 -- to the project directory of the main project.
376 procedure Add_Source_Dir (N : String);
377 -- Call Add_Src_Search_Dir (output one line when in verbose mode)
379 procedure Add_Source_Directories is
380 new Prj.Env.For_All_Source_Dirs (Action => Add_Source_Dir);
382 procedure Add_Object_Dir (N : String);
383 -- Call Add_Lib_Search_Dir (output one line when in verbose mode)
385 procedure Add_Object_Directories is
386 new Prj.Env.For_All_Object_Dirs (Action => Add_Object_Dir);
388 procedure Change_To_Object_Directory (Project : Project_Id);
389 -- Change to the object directory of project Project, if this is not
390 -- already the current working directory.
392 type Bad_Compilation_Info is record
393 File : File_Name_Type;
394 Unit : Unit_Name_Type;
397 -- File is the name of the file for which a compilation failed. Unit is for
398 -- gnatdist use in order to easily get the unit name of a file when its
399 -- name is krunched or declared in gnat.adc. Found is False if the
400 -- compilation failed because the file could not be found.
402 package Bad_Compilation is new Table.Table (
403 Table_Component_Type => Bad_Compilation_Info,
404 Table_Index_Type => Natural,
405 Table_Low_Bound => 1,
407 Table_Increment => 100,
408 Table_Name => "Make.Bad_Compilation");
409 -- Full name of all the source files for which compilation fails
411 Do_Compile_Step : Boolean := True;
412 Do_Bind_Step : Boolean := True;
413 Do_Link_Step : Boolean := True;
414 -- Flags to indicate what step should be executed. Can be set to False
415 -- with the switches -c, -b and -l. These flags are reset to True for
416 -- each invokation of procedure Gnatmake.
418 Shared_String : aliased String := "-shared";
419 Force_Elab_Flags_String : aliased String := "-F";
421 No_Shared_Switch : aliased Argument_List := (1 .. 0 => null);
422 Shared_Switch : aliased Argument_List := (1 => Shared_String'Access);
423 Bind_Shared : Argument_List_Access := No_Shared_Switch'Access;
424 -- Switch to added in front of gnatbind switches. By default no switch is
425 -- added. Switch "-shared" is added if there is a non-static Library
428 Shared_Libgcc : aliased String := "-shared-libgcc";
430 No_Shared_Libgcc_Switch : aliased Argument_List := (1 .. 0 => null);
431 Shared_Libgcc_Switch : aliased Argument_List :=
432 (1 => Shared_Libgcc'Access);
433 Link_With_Shared_Libgcc : Argument_List_Access :=
434 No_Shared_Libgcc_Switch'Access;
436 procedure Make_Failed (S1 : String; S2 : String := ""; S3 : String := "");
437 -- Delete all temp files created by Gnatmake and call Osint.Fail,
438 -- with the parameter S1, S2 and S3 (see osint.ads).
439 -- This is called from the Prj hierarchy and the MLib hierarchy.
441 --------------------------
442 -- Obsolete Executables --
443 --------------------------
445 Executable_Obsolete : Boolean := False;
446 -- Executable_Obsolete is initially set to False for each executable,
447 -- and is set to True whenever one of the source of the executable is
448 -- compiled, or has already been compiled for another executable.
450 Max_Header : constant := 200;
451 -- This needs a proper comment, it used to say "arbitrary"
452 -- that's not an adequate comment ???
454 type Header_Num is range 1 .. Max_Header;
455 -- Header_Num for the hash table Obsoleted below
457 function Hash (F : File_Name_Type) return Header_Num;
458 -- Hash function for the hash table Obsoleted below
460 package Obsoleted is new System.HTable.Simple_HTable
461 (Header_Num => Header_Num,
464 Key => File_Name_Type,
467 -- A hash table to keep all files that have been compiled, to detect
468 -- if an executable is up to date or not.
470 procedure Enter_Into_Obsoleted (F : File_Name_Type);
471 -- Enter a file name, without directory information, into the hash table
474 function Is_In_Obsoleted (F : File_Name_Type) return Boolean;
475 -- Check if a file name, without directory information, has already been
476 -- entered into the hash table Obsoleted.
478 type Dependency is record
479 This : File_Name_Type;
480 Depends_On : File_Name_Type;
482 -- Components of table Dependencies below
484 package Dependencies is new Table.Table (
485 Table_Component_Type => Dependency,
486 Table_Index_Type => Integer,
487 Table_Low_Bound => 1,
489 Table_Increment => 100,
490 Table_Name => "Make.Dependencies");
491 -- A table to keep dependencies, to be able to decide if an executable
492 -- is obsolete. More explanation needed ???
494 -- procedure Add_Dependency (S : File_Name_Type; On : File_Name_Type);
495 -- -- Add one entry in table Dependencies
497 ----------------------------
498 -- Arguments and Switches --
499 ----------------------------
501 Arguments : Argument_List_Access;
502 -- Used to gather the arguments for invocation of the compiler
504 Last_Argument : Natural := 0;
505 -- Last index of arguments in Arguments above
507 Arguments_Collected : Boolean := False;
508 -- Set to True when the arguments for the next invocation of the compiler
509 -- have been collected.
511 Arguments_Project : Project_Id;
512 -- Project id, if any, of the source to be compiled
514 Arguments_Path_Name : Path_Name_Type;
515 -- Full path of the source to be compiled, when Arguments_Project is not
518 Dummy_Switch : constant String_Access := new String'("- ");
519 -- Used to initialized Prev_Switch in procedure Check
521 procedure Add_Arguments (Args : Argument_List);
522 -- Add arguments to global variable Arguments, increasing its size
523 -- if necessary and adjusting Last_Argument.
525 function Configuration_Pragmas_Switch
526 (For_Project : Project_Id) return Argument_List;
527 -- Return an argument list of one element, if there is a configuration
528 -- pragmas file to be specified for For_Project,
529 -- otherwise return an empty argument list.
535 procedure List_Depend;
536 -- Prints to standard output the list of object dependencies. This list
537 -- can be used directly in a Makefile. A call to Compile_Sources must
538 -- precede the call to List_Depend. Also because this routine uses the
539 -- ALI files that were originally loaded and scanned by Compile_Sources,
540 -- no additional ALI files should be scanned between the two calls (i.e.
541 -- between the call to Compile_Sources and List_Depend.)
543 procedure List_Bad_Compilations;
544 -- Prints out the list of all files for which the compilation failed
546 procedure Verbose_Msg
549 N2 : Name_Id := No_Name;
551 Prefix : String := " -> ";
552 Minimum_Verbosity : Verbosity_Level_Type := Opt.Low);
553 procedure Verbose_Msg
554 (N1 : File_Name_Type;
556 N2 : File_Name_Type := No_File;
558 Prefix : String := " -> ";
559 Minimum_Verbosity : Verbosity_Level_Type := Opt.Low);
560 -- If the verbose flag (Verbose_Mode) is set and the verbosity level is
561 -- at least equal to Minimum_Verbosity, then print Prefix to standard
562 -- output followed by N1 and S1. If N2 /= No_Name then N2 is printed after
563 -- S1. S2 is printed last. Both N1 and N2 are printed in quotation marks.
565 Usage_Needed : Boolean := True;
566 -- Flag used to make sure Makeusg is call at most once
569 -- Call Makeusg, if Usage_Needed is True.
570 -- Set Usage_Needed to False.
572 procedure Debug_Msg (S : String; N : Name_Id);
573 procedure Debug_Msg (S : String; N : File_Name_Type);
574 procedure Debug_Msg (S : String; N : Unit_Name_Type);
575 -- If Debug.Debug_Flag_W is set outputs string S followed by name N
577 procedure Recursive_Compute_Depth
578 (Project : Project_Id;
580 -- Compute depth of Project and of the projects it depends on
582 procedure Compute_All_Imported_Projects (Project : Project_Id);
583 -- Compute, the list of the projects imported directly or indirectly by
586 -----------------------
587 -- Gnatmake Routines --
588 -----------------------
590 Gnatmake_Called : Boolean := False;
591 -- Set to True when procedure Gnatmake is called.
592 -- Attempt to delete temporary files is made only when Gnatmake_Called
595 subtype Lib_Mark_Type is Byte;
596 -- Used in Mark_Directory
598 Ada_Lib_Dir : constant Lib_Mark_Type := 1;
599 -- Used to mark a directory as a GNAT lib dir
601 -- Note that the notion of GNAT lib dir is no longer used. The code related
602 -- to it has not been removed to give an idea on how to use the directory
603 -- prefix marking mechanism.
605 -- An Ada library directory is a directory containing ali and object files
606 -- but no source files for the bodies (the specs can be in the same or some
607 -- other directory). These directories are specified in the Gnatmake
608 -- command line with the switch "-Adir" (to specify the spec location -Idir
609 -- cab be used). Gnatmake skips the missing sources whose ali are in Ada
610 -- library directories. For an explanation of why Gnatmake behaves that
611 -- way, see the spec of Make.Compile_Sources. The directory lookup penalty
612 -- is incurred every single time this routine is called.
614 procedure Check_Steps;
615 -- Check what steps (Compile, Bind, Link) must be executed.
616 -- Set the step flags accordingly.
618 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean;
619 -- Get directory prefix of this file and get lib mark stored in name
620 -- table for this directory. Then check if an Ada lib mark has been set.
622 procedure Mark_Directory
624 Mark : Lib_Mark_Type;
625 On_Command_Line : Boolean);
626 -- Store the absolute path from Dir in name table and set lib mark as name
627 -- info to identify Ada libraries.
629 -- If Dir is a relative path, when On_Command_Line is True, it is relative
630 -- to the current working directory; when On_Command_Line is False, it is
631 -- relative to the project directory of the main project.
633 Output_Is_Object : Boolean := True;
634 -- Set to False when using a switch -S for the compiler
636 procedure Check_For_S_Switch;
637 -- Set Output_Is_Object to False when the -S switch is used for the
641 (Source_File : File_Name_Type;
642 Source_File_Name : String;
644 Naming : Naming_Data;
645 In_Package : Package_Id;
646 Allow_ALI : Boolean) return Variable_Value;
647 -- Return the switches for the source file in the specified package of a
648 -- project file. If the Source_File ends with a standard GNAT extension
649 -- (".ads" or ".adb"), try first the full name, then the name without the
650 -- extension, then, if Allow_ALI is True, the name with the extension
651 -- ".ali". If there is no switches for either names, try the default
652 -- switches for Ada. If all failed, return No_Variable_Value.
654 function Is_In_Object_Directory
655 (Source_File : File_Name_Type;
656 Full_Lib_File : File_Name_Type) return Boolean;
657 -- Check if, when using a project file, the ALI file is in the project
658 -- directory of the ultimate extending project. If it is not, we ignore
659 -- the fact that this ALI file is read-only.
661 ----------------------------------------------------
662 -- Compiler, Binder & Linker Data and Subprograms --
663 ----------------------------------------------------
665 Gcc : String_Access := Program_Name ("gcc");
666 Gnatbind : String_Access := Program_Name ("gnatbind");
667 Gnatlink : String_Access := Program_Name ("gnatlink");
668 -- Default compiler, binder, linker programs
670 Saved_Gcc : String_Access := null;
671 Saved_Gnatbind : String_Access := null;
672 Saved_Gnatlink : String_Access := null;
673 -- Given by the command line. Will be used, if non null
675 Gcc_Path : String_Access :=
676 GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
677 Gnatbind_Path : String_Access :=
678 GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
679 Gnatlink_Path : String_Access :=
680 GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
681 -- Path for compiler, binder, linker programs, defaulted now for gnatdist.
682 -- Changed later if overridden on command line.
684 Comp_Flag : constant String_Access := new String'("-c");
685 Output_Flag : constant String_Access := new String'("-o");
686 Ada_Flag_1 : constant String_Access := new String'("-x");
687 Ada_Flag_2 : constant String_Access := new String'("ada");
688 No_gnat_adc : constant String_Access := new String'("-gnatA");
689 GNAT_Flag : constant String_Access := new String'("-gnatpg");
690 Do_Not_Check_Flag : constant String_Access := new String'("-x");
692 Object_Suffix : constant String := Get_Target_Object_Suffix.all;
694 Syntax_Only : Boolean := False;
695 -- Set to True when compiling with -gnats
697 Display_Executed_Programs : Boolean := True;
698 -- Set to True if name of commands should be output on stderr (or on stdout
699 -- if the Commands_To_Stdout flag was set by use of the -S switch).
701 Output_File_Name_Seen : Boolean := False;
702 -- Set to True after having scanned the file_name for
703 -- switch "-o file_name"
705 Object_Directory_Seen : Boolean := False;
706 -- Set to True after having scanned the object directory for
707 -- switch "-D obj_dir".
709 Object_Directory_Path : String_Access := null;
710 -- The path name of the object directory, set with switch -D
712 type Make_Program_Type is (None, Compiler, Binder, Linker);
714 Program_Args : Make_Program_Type := None;
715 -- Used to indicate if we are scanning gnatmake, gcc, gnatbind, or gnatbind
716 -- options within the gnatmake command line. Used in Scan_Make_Arg only,
717 -- but must be global since value preserved from one call to another.
719 Temporary_Config_File : Boolean := False;
720 -- Set to True when there is a temporary config file used for a project
721 -- file, to avoid displaying the -gnatec switch for a temporary file.
723 procedure Add_Switches
724 (The_Package : Package_Id;
727 Program : Make_Program_Type);
730 Program : Make_Program_Type;
731 Append_Switch : Boolean := True;
732 And_Save : Boolean := True);
735 Program : Make_Program_Type;
736 Append_Switch : Boolean := True;
737 And_Save : Boolean := True);
738 -- Make invokes one of three programs (the compiler, the binder or the
739 -- linker). For the sake of convenience, some program specific switches
740 -- can be passed directly on the gnatmake commande line. This procedure
741 -- records these switches so that gnamake can pass them to the right
742 -- program. S is the switch to be added at the end of the command line
743 -- for Program if Append_Switch is True. If Append_Switch is False S is
744 -- added at the beginning of the command line.
747 (Source_File : File_Name_Type;
749 The_Args : Argument_List;
750 Lib_File : File_Name_Type;
753 O_File : out File_Name_Type;
754 O_Stamp : out Time_Stamp_Type);
755 -- Determines whether the library file Lib_File is up-to-date or not. The
756 -- full name (with path information) of the object file corresponding to
757 -- Lib_File is returned in O_File. Its time stamp is saved in O_Stamp.
758 -- ALI is the ALI_Id corresponding to Lib_File. If Lib_File in not
759 -- up-to-date, then the corresponding source file needs to be recompiled.
760 -- In this case ALI = No_ALI_Id.
762 procedure Check_Linker_Options
763 (E_Stamp : Time_Stamp_Type;
764 O_File : out File_Name_Type;
765 O_Stamp : out Time_Stamp_Type);
766 -- Checks all linker options for linker files that are newer
767 -- than E_Stamp. If such objects are found, the youngest object
768 -- is returned in O_File and its stamp in O_Stamp.
770 -- If no obsolete linker files were found, the first missing
771 -- linker file is returned in O_File and O_Stamp is empty.
772 -- Otherwise O_File is No_File.
774 procedure Collect_Arguments
775 (Source_File : File_Name_Type;
777 Args : Argument_List);
778 -- Collect all arguments for a source to be compiled, including those
779 -- that come from a project file.
781 procedure Display (Program : String; Args : Argument_List);
782 -- Displays Program followed by the arguments in Args if variable
783 -- Display_Executed_Programs is set. The lower bound of Args must be 1.
785 procedure Report_Compilation_Failed;
786 -- Delete all temporary files and fail graciously
792 type Temp_Path_Names is
793 array (Project_Id range <>, Positive range <>) of Path_Name_Type;
795 type Temp_Path_Ptr is access Temp_Path_Names;
797 type Indices is array (Project_Id range <>) of Natural;
799 type Indices_Ptr is access Indices;
801 type Free_File_Indices is array
802 (Project_Id range <>, Positive range <>) of Positive;
804 type Free_Indices_Ptr is access Free_File_Indices;
806 The_Mapping_File_Names : Temp_Path_Ptr;
807 -- For each project, the name ids of the temporary mapping files used
809 Last_Mapping_File_Names : Indices_Ptr;
810 -- For each project, the index of the last mapping file created
812 The_Free_Mapping_File_Indices : Free_Indices_Ptr;
813 -- For each project, the indices in The_Mapping_File_Names of the mapping
814 -- file names that can be reused for subsequent compilations.
816 Last_Free_Indices : Indices_Ptr;
817 -- For each project, the number of mapping files that can be reused
819 Gnatmake_Mapping_File : String_Access := null;
820 -- The path name of a mapping file specified by switch -C=
822 procedure Delete_Mapping_Files;
823 -- Delete all temporary mapping files
825 procedure Init_Mapping_File
826 (Project : Project_Id;
827 File_Index : in out Natural);
828 -- Create a new temporary mapping file, and fill it with the project file
829 -- mappings, when using project file(s). The out parameter File_Index is
830 -- the index to the name of the file in the array The_Mapping_File_Names.
832 procedure Delete_Temp_Config_Files;
833 -- Delete all temporary config files
835 procedure Delete_All_Temp_Files;
836 -- Delete all temp files (config files, mapping files, path files)
838 -------------------------------------------------
839 -- Subprogram declarations moved from the spec --
840 -------------------------------------------------
842 procedure Bind (ALI_File : File_Name_Type; Args : Argument_List);
843 -- Binds ALI_File. Args are the arguments to pass to the binder.
844 -- Args must have a lower bound of 1.
846 procedure Display_Commands (Display : Boolean := True);
847 -- The default behavior of Make commands (Compile_Sources, Bind, Link)
848 -- is to display them on stderr. This behavior can be changed repeatedly
849 -- by invoking this procedure.
851 -- If a compilation, bind or link failed one of the following 3 exceptions
852 -- is raised. These need to be handled by the calling routines.
854 procedure Compile_Sources
855 (Main_Source : File_Name_Type;
856 Args : Argument_List;
857 First_Compiled_File : out File_Name_Type;
858 Most_Recent_Obj_File : out File_Name_Type;
859 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
860 Main_Unit : out Boolean;
861 Compilation_Failures : out Natural;
862 Main_Index : Int := 0;
863 Check_Readonly_Files : Boolean := False;
864 Do_Not_Execute : Boolean := False;
865 Force_Compilations : Boolean := False;
866 Keep_Going : Boolean := False;
867 In_Place_Mode : Boolean := False;
868 Initialize_ALI_Data : Boolean := True;
869 Max_Process : Positive := 1);
870 -- Compile_Sources will recursively compile all the sources needed by
871 -- Main_Source. Before calling this routine make sure Namet has been
872 -- initialized. This routine can be called repeatedly with different
873 -- Main_Source file as long as all the source (-I flags), library
874 -- (-B flags) and ada library (-A flags) search paths between calls are
875 -- *exactly* the same. The default directory must also be the same.
877 -- Args contains the arguments to use during the compilations.
878 -- The lower bound of Args must be 1.
880 -- First_Compiled_File is set to the name of the first file that is
881 -- compiled or that needs to be compiled. This is set to No_Name if no
882 -- compilations were needed.
884 -- Most_Recent_Obj_File is set to the full name of the most recent
885 -- object file found when no compilations are needed, that is when
886 -- First_Compiled_File is set to No_Name. When First_Compiled_File
887 -- is set then Most_Recent_Obj_File is set to No_Name.
889 -- Most_Recent_Obj_Stamp is the time stamp of Most_Recent_Obj_File.
891 -- Main_Unit is set to True if Main_Source can be a main unit.
892 -- If Do_Not_Execute is False and First_Compiled_File /= No_Name
893 -- the value of Main_Unit is always False.
894 -- Is this used any more??? It is certainly not used by gnatmake???
896 -- Compilation_Failures is a count of compilation failures. This count
897 -- is used to extract compilation failure reports with Extract_Failure.
899 -- Main_Index, when not zero, is the index of the main unit in source
900 -- file Main_Source which is a multi-unit source.
901 -- Zero indicates that Main_Source is a single unit source file.
903 -- Check_Readonly_Files set it to True to compile source files
904 -- which library files are read-only. When compiling GNAT predefined
905 -- files the "-gnatg" flag is used.
907 -- Do_Not_Execute set it to True to find out the first source that
908 -- needs to be recompiled, but without recompiling it. This file is
909 -- saved in First_Compiled_File.
911 -- Force_Compilations forces all compilations no matter what but
912 -- recompiles read-only files only if Check_Readonly_Files
915 -- Keep_Going when True keep compiling even in the presence of
916 -- compilation errors.
918 -- In_Place_Mode when True save library/object files in their object
919 -- directory if they already exist; otherwise, in the source directory.
921 -- Initialize_ALI_Data set it to True when you want to initialize ALI
922 -- data-structures. This is what you should do most of the time.
923 -- (especially the first time around when you call this routine).
924 -- This parameter is set to False to preserve previously recorded
927 -- Max_Process is the maximum number of processes that should be spawned
928 -- to carry out compilations.
930 -- Flags in Package Opt Affecting Compile_Sources
931 -- -----------------------------------------------
933 -- Check_Object_Consistency set it to False to omit all consistency
934 -- checks between an .ali file and its corresponding object file.
935 -- When this flag is set to true, every time an .ali is read,
936 -- package Osint checks that the corresponding object file
937 -- exists and is more recent than the .ali.
939 -- Use of Name Table Info
940 -- ----------------------
942 -- All file names manipulated by Compile_Sources are entered into the
943 -- Names table. The Byte field of a source file is used to mark it.
945 -- Calling Compile_Sources Several Times
946 -- -------------------------------------
948 -- Upon return from Compile_Sources all the ALI data structures are left
949 -- intact for further browsing. HOWEVER upon entry to this routine ALI
950 -- data structures are re-initialized if parameter Initialize_ALI_Data
951 -- above is set to true. Typically this is what you want the first time
952 -- you call Compile_Sources. You should not load an ali file, call this
953 -- routine with flag Initialize_ALI_Data set to True and then expect
954 -- that ALI information to be around after the call. Note that the first
955 -- time you call Compile_Sources you better set Initialize_ALI_Data to
956 -- True unless you have called Initialize_ALI yourself.
958 -- Compile_Sources ALGORITHM : Compile_Sources (Main_Source)
959 -- -------------------------
961 -- 1. Insert Main_Source in a Queue (Q) and mark it.
963 -- 2. Let unit.adb be the file at the head of the Q. If unit.adb is
964 -- missing but its corresponding ali file is in an Ada library directory
965 -- (see below) then, remove unit.adb from the Q and goto step 4.
966 -- Otherwise, look at the files under the D (dependency) section of
967 -- unit.ali. If unit.ali does not exist or some of the time stamps do
968 -- not match, (re)compile unit.adb.
970 -- An Ada library directory is a directory containing Ada specs, ali
971 -- and object files but no source files for the bodies. An Ada library
972 -- directory is communicated to gnatmake by means of some switch so that
973 -- gnatmake can skip the sources whole ali are in that directory.
974 -- There are two reasons for skipping the sources in this case. Firstly,
975 -- Ada libraries typically come without full sources but binding and
976 -- linking against those libraries is still possible. Secondly, it would
977 -- be very wasteful for gnatmake to systematically check the consistency
978 -- of every external Ada library used in a program. The binder is
979 -- already in charge of catching any potential inconsistencies.
981 -- 3. Look into the W section of unit.ali and insert into the Q all
982 -- unmarked source files. Mark all files newly inserted in the Q.
983 -- Specifically, assuming that the W section looks like
985 -- W types%s types.adb types.ali
986 -- W unchecked_deallocation%s
987 -- W xref_tab%s xref_tab.adb xref_tab.ali
989 -- Then xref_tab.adb and types.adb are inserted in the Q if they are not
991 -- Note that there is no file listed under W unchecked_deallocation%s
992 -- so no generic body should ever be explicitly compiled (unless the
993 -- Main_Source at the start was a generic body).
995 -- 4. Repeat steps 2 and 3 above until the Q is empty
997 -- Note that the above algorithm works because the units withed in
998 -- subunits are transitively included in the W section (with section) of
999 -- the main unit. Likewise the withed units in a generic body needed
1000 -- during a compilation are also transitively included in the W section
1001 -- of the originally compiled file.
1003 procedure Initialize;
1004 -- Performs default and package initialization. Therefore,
1005 -- Compile_Sources can be called by an external unit.
1008 (ALI_File : File_Name_Type;
1009 Args : Argument_List;
1010 Success : out Boolean);
1011 -- Links ALI_File. Args are the arguments to pass to the linker.
1012 -- Args must have a lower bound of 1. Success indicates if the link
1013 -- succeeded or not.
1015 procedure Scan_Make_Arg (Argv : String; And_Save : Boolean);
1016 -- Scan make arguments. Argv is a single argument to be processed
1022 procedure Add_Arguments (Args : Argument_List) is
1024 if Arguments = null then
1025 Arguments := new Argument_List (1 .. Args'Length + 10);
1028 while Last_Argument + Args'Length > Arguments'Last loop
1030 New_Arguments : constant Argument_List_Access :=
1031 new Argument_List (1 .. Arguments'Last * 2);
1033 New_Arguments (1 .. Last_Argument) :=
1034 Arguments (1 .. Last_Argument);
1035 Arguments := New_Arguments;
1040 Arguments (Last_Argument + 1 .. Last_Argument + Args'Length) := Args;
1041 Last_Argument := Last_Argument + Args'Length;
1044 -- --------------------
1045 -- -- Add_Dependency --
1046 -- --------------------
1048 -- procedure Add_Dependency (S : File_Name_Type; On : File_Name_Type) is
1050 -- Dependencies.Increment_Last;
1051 -- Dependencies.Table (Dependencies.Last) := (S, On);
1052 -- end Add_Dependency;
1054 ----------------------------
1055 -- Add_Library_Search_Dir --
1056 ----------------------------
1058 procedure Add_Library_Search_Dir
1060 On_Command_Line : Boolean)
1063 if On_Command_Line then
1064 Add_Lib_Search_Dir (Normalize_Pathname (Path));
1068 (Project_Tree.Projects.Table (Main_Project).Display_Directory);
1070 (Normalize_Pathname (Path, Name_Buffer (1 .. Name_Len)));
1072 end Add_Library_Search_Dir;
1074 --------------------
1075 -- Add_Object_Dir --
1076 --------------------
1078 procedure Add_Object_Dir (N : String) is
1080 Add_Lib_Search_Dir (N);
1082 if Verbose_Mode then
1083 Write_Str ("Adding object directory """);
1090 --------------------
1091 -- Add_Source_Dir --
1092 --------------------
1094 procedure Add_Source_Dir (N : String) is
1096 Add_Src_Search_Dir (N);
1098 if Verbose_Mode then
1099 Write_Str ("Adding source directory """);
1106 ---------------------------
1107 -- Add_Source_Search_Dir --
1108 ---------------------------
1110 procedure Add_Source_Search_Dir
1112 On_Command_Line : Boolean)
1115 if On_Command_Line then
1116 Add_Src_Search_Dir (Normalize_Pathname (Path));
1120 (Project_Tree.Projects.Table (Main_Project).Display_Directory);
1122 (Normalize_Pathname (Path, Name_Buffer (1 .. Name_Len)));
1124 end Add_Source_Search_Dir;
1130 procedure Add_Switch
1132 Program : Make_Program_Type;
1133 Append_Switch : Boolean := True;
1134 And_Save : Boolean := True)
1137 with package T is new Table.Table (<>);
1138 procedure Generic_Position (New_Position : out Integer);
1139 -- Generic procedure that chooses a position for S in T at the
1140 -- beginning or the end, depending on the boolean Append_Switch.
1141 -- Calling this procedure may expand the table.
1143 ----------------------
1144 -- Generic_Position --
1145 ----------------------
1147 procedure Generic_Position (New_Position : out Integer) is
1151 if Append_Switch then
1152 New_Position := Integer (T.Last);
1154 for J in reverse T.Table_Index_Type'Succ (T.First) .. T.Last loop
1155 T.Table (J) := T.Table (T.Table_Index_Type'Pred (J));
1158 New_Position := Integer (T.First);
1160 end Generic_Position;
1162 procedure Gcc_Switches_Pos is new Generic_Position (Gcc_Switches);
1163 procedure Binder_Switches_Pos is new Generic_Position (Binder_Switches);
1164 procedure Linker_Switches_Pos is new Generic_Position (Linker_Switches);
1166 procedure Saved_Gcc_Switches_Pos is new
1167 Generic_Position (Saved_Gcc_Switches);
1169 procedure Saved_Binder_Switches_Pos is new
1170 Generic_Position (Saved_Binder_Switches);
1172 procedure Saved_Linker_Switches_Pos is new
1173 Generic_Position (Saved_Linker_Switches);
1175 New_Position : Integer;
1177 -- Start of processing for Add_Switch
1183 Saved_Gcc_Switches_Pos (New_Position);
1184 Saved_Gcc_Switches.Table (New_Position) := S;
1187 Saved_Binder_Switches_Pos (New_Position);
1188 Saved_Binder_Switches.Table (New_Position) := S;
1191 Saved_Linker_Switches_Pos (New_Position);
1192 Saved_Linker_Switches.Table (New_Position) := S;
1195 raise Program_Error;
1201 Gcc_Switches_Pos (New_Position);
1202 Gcc_Switches.Table (New_Position) := S;
1205 Binder_Switches_Pos (New_Position);
1206 Binder_Switches.Table (New_Position) := S;
1209 Linker_Switches_Pos (New_Position);
1210 Linker_Switches.Table (New_Position) := S;
1213 raise Program_Error;
1218 procedure Add_Switch
1220 Program : Make_Program_Type;
1221 Append_Switch : Boolean := True;
1222 And_Save : Boolean := True)
1225 Add_Switch (S => new String'(S),
1227 Append_Switch => Append_Switch,
1228 And_Save => And_Save);
1235 procedure Add_Switches
1236 (The_Package : Package_Id;
1239 Program : Make_Program_Type)
1241 Switches : Variable_Value;
1242 Switch_List : String_List_Id;
1243 Element : String_Element;
1246 if File_Name'Length > 0 then
1247 Name_Len := File_Name'Length;
1248 Name_Buffer (1 .. Name_Len) := File_Name;
1251 (Source_File => Name_Find,
1252 Source_File_Name => File_Name,
1253 Source_Index => Index,
1254 Naming => Project_Tree.Projects.Table
1255 (Main_Project).Naming,
1256 In_Package => The_Package,
1258 Program = Binder or else Program = Linker);
1260 case Switches.Kind is
1265 Program_Args := Program;
1267 Switch_List := Switches.Values;
1269 while Switch_List /= Nil_String loop
1270 Element := Project_Tree.String_Elements.Table (Switch_List);
1271 Get_Name_String (Element.Value);
1273 if Name_Len > 0 then
1275 Argv : constant String := Name_Buffer (1 .. Name_Len);
1276 -- We need a copy, because Name_Buffer may be modified
1279 if Verbose_Mode then
1280 Write_Str (" Adding ");
1284 Scan_Make_Arg (Argv, And_Save => False);
1288 Switch_List := Element.Next;
1292 Program_Args := Program;
1293 Get_Name_String (Switches.Value);
1295 if Name_Len > 0 then
1297 Argv : constant String := Name_Buffer (1 .. Name_Len);
1298 -- We need a copy, because Name_Buffer may be modified
1301 if Verbose_Mode then
1302 Write_Str (" Adding ");
1306 Scan_Make_Arg (Argv, And_Save => False);
1317 procedure Bind (ALI_File : File_Name_Type; Args : Argument_List) is
1318 Bind_Args : Argument_List (1 .. Args'Last + 2);
1319 Bind_Last : Integer;
1323 pragma Assert (Args'First = 1);
1325 -- Optimize the simple case where the gnatbind command line looks like
1326 -- gnatbind -aO. -I- file.ali --into-> gnatbind file.adb
1329 and then Args (Args'First).all = "-aO" & Normalized_CWD
1330 and then Args (Args'Last).all = "-I-"
1331 and then ALI_File = Strip_Directory (ALI_File)
1333 Bind_Last := Args'First - 1;
1336 Bind_Last := Args'Last;
1337 Bind_Args (Args'Range) := Args;
1340 -- It is completely pointless to re-check source file time stamps. This
1341 -- has been done already by gnatmake
1343 Bind_Last := Bind_Last + 1;
1344 Bind_Args (Bind_Last) := Do_Not_Check_Flag;
1346 Get_Name_String (ALI_File);
1348 Bind_Last := Bind_Last + 1;
1349 Bind_Args (Bind_Last) := new String'(Name_Buffer (1 .. Name_Len));
1351 GNAT.OS_Lib.Normalize_Arguments (Bind_Args (Args'First .. Bind_Last));
1353 Display (Gnatbind.all, Bind_Args (Args'First .. Bind_Last));
1355 if Gnatbind_Path = null then
1356 Make_Failed ("error, unable to locate ", Gnatbind.all);
1360 (Gnatbind_Path.all, Bind_Args (Args'First .. Bind_Last), Success);
1363 Make_Failed ("*** bind failed.");
1367 --------------------------------
1368 -- Change_To_Object_Directory --
1369 --------------------------------
1371 procedure Change_To_Object_Directory (Project : Project_Id) is
1372 Actual_Project : Project_Id;
1373 Object_Directory : Path_Name_Type;
1376 -- For sources outside of any project, compilation occurs in the object
1377 -- directory of the main project, otherwise we use the project given.
1379 if Project = No_Project then
1380 Actual_Project := Main_Project;
1382 Actual_Project := Project;
1385 -- Nothing to do if the current working directory is already the correct
1386 -- object directory.
1388 if Project_Of_Current_Object_Directory /= Actual_Project then
1389 Project_Of_Current_Object_Directory := Actual_Project;
1391 Project_Tree.Projects.Table (Actual_Project).Object_Directory;
1393 -- Set the working directory to the object directory of the actual
1396 if Verbose_Mode then
1397 Write_Str ("Changing to object directory of """);
1399 (Project_Tree.Projects.Table (Actual_Project).Display_Name);
1400 Write_Str (""": """);
1401 Write_Name (Object_Directory);
1405 Change_Dir (Get_Name_String (Object_Directory));
1409 -- Fail if unable to change to the object directory
1411 when Directory_Error =>
1412 Make_Failed ("unable to change to object directory """ &
1414 (Project_Tree.Projects.Table
1415 (Actual_Project).Object_Directory) &
1417 Get_Name_String (Project_Tree.Projects.Table
1418 (Actual_Project).Display_Name));
1419 end Change_To_Object_Directory;
1426 (Source_File : File_Name_Type;
1428 The_Args : Argument_List;
1429 Lib_File : File_Name_Type;
1430 Read_Only : Boolean;
1432 O_File : out File_Name_Type;
1433 O_Stamp : out Time_Stamp_Type)
1435 function First_New_Spec (A : ALI_Id) return File_Name_Type;
1436 -- Looks in the with table entries of A and returns the spec file name
1437 -- of the first withed unit (subprogram) for which no spec existed when
1438 -- A was generated but for which there exists one now, implying that A
1439 -- is now obsolete. If no such unit is found No_File is returned.
1440 -- Otherwise the spec file name of the unit is returned.
1442 -- **WARNING** in the event of Uname format modifications, one *MUST*
1443 -- make sure this function is also updated.
1445 -- Note: This function should really be in ali.adb and use Uname
1446 -- services, but this causes the whole compiler to be dragged along
1447 -- for gnatbind and gnatmake.
1449 --------------------
1450 -- First_New_Spec --
1451 --------------------
1453 function First_New_Spec (A : ALI_Id) return File_Name_Type is
1454 Spec_File_Name : File_Name_Type := No_File;
1456 function New_Spec (Uname : Unit_Name_Type) return Boolean;
1457 -- Uname is the name of the spec or body of some ada unit. This
1458 -- function returns True if the Uname is the name of a body which has
1459 -- a spec not mentioned in ALI file A. If True is returned
1460 -- Spec_File_Name above is set to the name of this spec file.
1466 function New_Spec (Uname : Unit_Name_Type) return Boolean is
1467 Spec_Name : Unit_Name_Type;
1468 File_Name : File_Name_Type;
1471 -- Test whether Uname is the name of a body unit (ie ends with %b)
1473 Get_Name_String (Uname);
1475 Assert (Name_Len > 2 and then Name_Buffer (Name_Len - 1) = '%');
1477 if Name_Buffer (Name_Len) /= 'b' then
1481 -- Convert unit name into spec name
1483 -- ??? this code seems dubious in presence of pragma
1484 -- Source_File_Name since there is no more direct relationship
1485 -- between unit name and file name.
1487 -- ??? Further, what about alternative subunit naming
1489 Name_Buffer (Name_Len) := 's';
1490 Spec_Name := Name_Find;
1491 File_Name := Get_File_Name (Spec_Name, Subunit => False);
1493 -- Look if File_Name is mentioned in A's sdep list.
1494 -- If not look if the file exists. If it does return True.
1497 ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep
1499 if Sdep.Table (D).Sfile = File_Name then
1504 if Full_Source_Name (File_Name) /= No_File then
1505 Spec_File_Name := File_Name;
1512 -- Start of processing for First_New_Spec
1516 ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit
1518 exit U_Chk when Units.Table (U).Utype = Is_Body_Only
1519 and then New_Spec (Units.Table (U).Uname);
1521 for W in Units.Table (U).First_With
1523 Units.Table (U).Last_With
1526 Withs.Table (W).Afile /= No_File
1527 and then New_Spec (Withs.Table (W).Uname);
1531 return Spec_File_Name;
1534 ---------------------------------
1535 -- Data declarations for Check --
1536 ---------------------------------
1538 Full_Lib_File : File_Name_Type;
1539 -- Full name of current library file
1541 Full_Obj_File : File_Name_Type;
1542 -- Full name of the object file corresponding to Lib_File
1544 Lib_Stamp : Time_Stamp_Type;
1545 -- Time stamp of the current ada library file
1547 Obj_Stamp : Time_Stamp_Type;
1548 -- Time stamp of the current object file
1550 Modified_Source : File_Name_Type;
1551 -- The first source in Lib_File whose current time stamp differs
1552 -- from that stored in Lib_File.
1554 New_Spec : File_Name_Type;
1555 -- If Lib_File contains in its W (with) section a body (for a
1556 -- subprogram) for which there exists a spec and the spec did not
1557 -- appear in the Sdep section of Lib_File, New_Spec contains the file
1558 -- name of this new spec.
1560 Source_Name : File_Name_Type;
1561 Text : Text_Buffer_Ptr;
1563 Prev_Switch : String_Access;
1564 -- Previous switch processed
1566 Arg : Arg_Id := Arg_Id'First;
1567 -- Current index in Args.Table for a given unit (init to stop warning)
1569 Switch_Found : Boolean;
1570 -- True if a given switch has been found
1572 ALI_Project : Project_Id;
1573 -- If the ALI file is in the object directory of a project, this is
1576 -- Start of processing for Check
1579 pragma Assert (Lib_File /= No_File);
1581 -- If ALI file is read-only, temporarily set Check_Object_Consistency to
1582 -- False. We don't care if the object file is not there (presumably a
1583 -- library will be used for linking.)
1587 Saved_Check_Object_Consistency : constant Boolean :=
1588 Check_Object_Consistency;
1590 Check_Object_Consistency := False;
1591 Text := Read_Library_Info (Lib_File);
1592 Check_Object_Consistency := Saved_Check_Object_Consistency;
1596 Text := Read_Library_Info (Lib_File);
1599 Full_Lib_File := Full_Library_Info_Name;
1600 Full_Obj_File := Full_Object_File_Name;
1601 Lib_Stamp := Current_Library_File_Stamp;
1602 Obj_Stamp := Current_Object_File_Stamp;
1604 if Full_Lib_File = No_File then
1607 "being checked ...",
1609 Minimum_Verbosity => Opt.Medium);
1613 "being checked ...",
1615 Minimum_Verbosity => Opt.Medium);
1619 O_File := Full_Obj_File;
1620 O_Stamp := Obj_Stamp;
1623 if Full_Lib_File = No_File then
1624 Verbose_Msg (Lib_File, "missing.");
1626 elsif Obj_Stamp (Obj_Stamp'First) = ' ' then
1627 Verbose_Msg (Full_Obj_File, "missing.");
1631 (Full_Lib_File, "(" & String (Lib_Stamp) & ") newer than",
1632 Full_Obj_File, "(" & String (Obj_Stamp) & ")");
1636 ALI := Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
1639 if ALI = No_ALI_Id then
1640 Verbose_Msg (Full_Lib_File, "incorrectly formatted ALI file");
1643 elsif ALIs.Table (ALI).Ver (1 .. ALIs.Table (ALI).Ver_Len) /=
1644 Verbose_Library_Version
1646 Verbose_Msg (Full_Lib_File, "compiled with old GNAT version");
1651 -- Don't take Ali file into account if it was generated with
1654 if ALIs.Table (ALI).Compile_Errors then
1655 Verbose_Msg (Full_Lib_File, "had errors, must be recompiled");
1660 -- Don't take Ali file into account if it was generated without
1663 if Operating_Mode /= Check_Semantics
1664 and then ALIs.Table (ALI).No_Object
1666 Verbose_Msg (Full_Lib_File, "has no corresponding object");
1671 -- Check for matching compiler switches if needed
1673 if Check_Switches then
1675 -- First, collect all the switches
1677 Collect_Arguments (Source_File, Source_Index, The_Args);
1679 Prev_Switch := Dummy_Switch;
1681 Get_Name_String (ALIs.Table (ALI).Sfile);
1683 Switches_To_Check.Set_Last (0);
1685 for J in 1 .. Last_Argument loop
1687 -- Skip non switches -c, -I and -o switches
1689 if Arguments (J) (1) = '-'
1690 and then Arguments (J) (2) /= 'c'
1691 and then Arguments (J) (2) /= 'o'
1692 and then Arguments (J) (2) /= 'I'
1694 Normalize_Compiler_Switches
1696 Normalized_Switches,
1699 for K in 1 .. Last_Norm_Switch loop
1700 Switches_To_Check.Increment_Last;
1701 Switches_To_Check.Table (Switches_To_Check.Last) :=
1702 Normalized_Switches (K);
1707 for J in 1 .. Switches_To_Check.Last loop
1709 -- Comparing switches is delicate because gcc reorders a number
1710 -- of switches, according to lang-specs.h, but gnatmake doesn't
1711 -- have sufficient knowledge to perform the same reordering.
1712 -- Instead, we ignore orders between different "first letter"
1713 -- switches, but keep orders between same switches, e.g -O -O2
1714 -- is different than -O2 -O, but -g -O is equivalent to -O -g.
1716 if Switches_To_Check.Table (J) (2) /= Prev_Switch (2) or else
1717 (Prev_Switch'Length >= 6 and then
1718 Prev_Switch (2 .. 5) = "gnat" and then
1719 Switches_To_Check.Table (J)'Length >= 6 and then
1720 Switches_To_Check.Table (J) (2 .. 5) = "gnat" and then
1721 Prev_Switch (6) /= Switches_To_Check.Table (J) (6))
1723 Prev_Switch := Switches_To_Check.Table (J);
1725 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg;
1728 Switch_Found := False;
1731 Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1734 Switches_To_Check.Table (J).all = Args.Table (K).all
1737 Switch_Found := True;
1742 if not Switch_Found then
1743 if Verbose_Mode then
1744 Verbose_Msg (ALIs.Table (ALI).Sfile,
1745 "switch mismatch """ &
1746 Switches_To_Check.Table (J).all & '"');
1754 if Switches_To_Check.Last /=
1755 Integer (Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg -
1756 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg + 1)
1758 if Verbose_Mode then
1759 Verbose_Msg (ALIs.Table (ALI).Sfile,
1760 "different number of switches");
1762 for K in Units.Table (ALIs.Table (ALI).First_Unit).First_Arg
1763 .. Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1765 Write_Str (Args.Table (K).all);
1771 for J in 1 .. Switches_To_Check.Last loop
1772 Write_Str (Switches_To_Check.Table (J).all);
1784 -- Get the source files and their message digests. Note that some
1785 -- sources may be missing if ALI is out-of-date.
1787 Set_Source_Table (ALI);
1789 Modified_Source := Time_Stamp_Mismatch (ALI, Read_Only);
1791 if Modified_Source /= No_File then
1794 if Verbose_Mode then
1795 Source_Name := Full_Source_Name (Modified_Source);
1797 if Source_Name /= No_File then
1798 Verbose_Msg (Source_Name, "time stamp mismatch");
1800 Verbose_Msg (Modified_Source, "missing");
1805 New_Spec := First_New_Spec (ALI);
1807 if New_Spec /= No_File then
1810 if Verbose_Mode then
1811 Source_Name := Full_Source_Name (New_Spec);
1813 if Source_Name /= No_File then
1814 Verbose_Msg (Source_Name, "new spec");
1816 Verbose_Msg (New_Spec, "old spec missing");
1820 elsif Main_Project /= No_Project then
1822 -- Check if a file name does not correspond to the mapping of
1823 -- units to file names.
1827 Unit_Name : Name_Id;
1828 UID : Prj.Unit_Index;
1833 for U in ALIs.Table (ALI).First_Unit ..
1834 ALIs.Table (ALI).Last_Unit
1837 for W in Units.Table (U).First_With
1839 Units.Table (U).Last_With
1841 WR := Withs.Table (W);
1843 if WR.Sfile /= No_File then
1844 Get_Name_String (WR.Uname);
1845 Name_Len := Name_Len - 2;
1846 Unit_Name := Name_Find;
1848 UID := Units_Htable.Get
1849 (Project_Tree.Units_HT, Unit_Name);
1851 if UID /= Prj.No_Unit_Index then
1852 U_Data := Project_Tree.Units.Table (UID);
1854 if U_Data.File_Names (Body_Part).Name /= WR.Sfile
1856 U_Data.File_Names (Specification).Name /=
1862 (Unit_Name, " sources does not include ",
1863 Name_Id (WR.Sfile));
1873 -- Check that the ALI file is in the correct object directory.
1874 -- If it is in the object directory of a project that is
1875 -- extended and it depends on a source that is in one of its
1876 -- extending projects, then the ALI file is not in the correct
1877 -- object directory.
1879 -- First, find the project of this ALI file. As there may be
1880 -- several projects with the same object directory, we first
1881 -- need to find the project of the source.
1883 ALI_Project := No_Project;
1886 Udata : Prj.Unit_Data;
1889 for U in 1 .. Unit_Table.Last (Project_Tree.Units) loop
1890 Udata := Project_Tree.Units.Table (U);
1892 if Udata.File_Names (Body_Part).Name = Source_File then
1893 ALI_Project := Udata.File_Names (Body_Part).Project;
1897 Udata.File_Names (Specification).Name = Source_File
1900 Udata.File_Names (Specification).Project;
1906 if ALI_Project = No_Project then
1911 Obj_Dir : Path_Name_Type;
1912 Res_Obj_Dir : constant String :=
1915 (Get_Name_String (Full_Lib_File)),
1916 Resolve_Links => True,
1917 Case_Sensitive => False);
1921 Add_Str_To_Name_Buffer (Res_Obj_Dir);
1923 if Name_Len > 1 and then
1924 (Name_Buffer (Name_Len) = '/' or else
1925 Name_Buffer (Name_Len) = Directory_Separator)
1927 Name_Len := Name_Len - 1;
1930 Obj_Dir := Name_Find;
1932 while ALI_Project /= No_Project and then
1934 Project_Tree.Projects.Table
1935 (ALI_Project).Object_Directory
1938 Project_Tree.Projects.Table (ALI_Project).Extended_By;
1942 if ALI_Project = No_Project then
1946 (Lib_File, " wrong object directory");
1950 -- If the ALI project is not extended, then it must be in
1951 -- the correct object directory.
1953 if Project_Tree.Projects.Table (ALI_Project).Extended_By =
1959 -- Count the extending projects
1967 Proj := ALI_Project;
1969 Proj := Project_Tree.Projects.Table (Proj).Extended_By;
1970 exit when Proj = No_Project;
1971 Num_Ext := Num_Ext + 1;
1974 -- Make a list of the extending projects
1977 Projects : array (1 .. Num_Ext) of Project_Id;
1979 OK : Boolean := True;
1982 Proj := ALI_Project;
1983 for J in Projects'Range loop
1984 Proj := Project_Tree.Projects.Table (Proj).Extended_By;
1985 Projects (J) := Proj;
1988 -- Now check if any of the dependant sources are in
1989 -- any of these extending projects.
1992 for D in ALIs.Table (ALI).First_Sdep ..
1993 ALIs.Table (ALI).Last_Sdep
1995 Dep := Sdep.Table (D);
2001 UID in 1 .. Unit_Table.Last (Project_Tree.Units)
2003 if Project_Tree.Units.Table (UID).
2004 File_Names (Body_Part).Name = Dep.Sfile
2006 Proj := Project_Tree.Units.Table (UID).
2007 File_Names (Body_Part).Project;
2009 elsif Project_Tree.Units.Table (UID).
2010 File_Names (Specification).Name = Dep.Sfile
2012 Proj := Project_Tree.Units.Table (UID).
2013 File_Names (Specification).Project;
2016 -- If a source is in a project, check if it is one
2019 if Proj /= No_Project then
2020 for J in Projects'Range loop
2021 if Proj = Projects (J) then
2032 -- If one of the dependent sources is in one project of
2033 -- the list, then we must recompile.
2037 Verbose_Msg (Lib_File, " wrong object directory");
2046 ------------------------
2047 -- Check_For_S_Switch --
2048 ------------------------
2050 procedure Check_For_S_Switch is
2052 -- By default, we generate an object file
2054 Output_Is_Object := True;
2056 for Arg in 1 .. Last_Argument loop
2057 if Arguments (Arg).all = "-S" then
2058 Output_Is_Object := False;
2060 elsif Arguments (Arg).all = "-c" then
2061 Output_Is_Object := True;
2064 end Check_For_S_Switch;
2066 --------------------------
2067 -- Check_Linker_Options --
2068 --------------------------
2070 procedure Check_Linker_Options
2071 (E_Stamp : Time_Stamp_Type;
2072 O_File : out File_Name_Type;
2073 O_Stamp : out Time_Stamp_Type)
2075 procedure Check_File (File : File_Name_Type);
2076 -- Update O_File and O_Stamp if the given file is younger than E_Stamp
2077 -- and O_Stamp, or if O_File is No_File and File does not exist.
2079 function Get_Library_File (Name : String) return File_Name_Type;
2080 -- Return the full file name including path of a library based
2081 -- on the name specified with the -l linker option, using the
2082 -- Ada object path. Return No_File if no such file can be found.
2084 type Char_Array is array (Natural) of Character;
2085 type Char_Array_Access is access constant Char_Array;
2087 Template : Char_Array_Access;
2088 pragma Import (C, Template, "__gnat_library_template");
2094 procedure Check_File (File : File_Name_Type) is
2095 Stamp : Time_Stamp_Type;
2096 Name : File_Name_Type := File;
2099 Get_Name_String (Name);
2101 -- Remove any trailing NUL characters
2103 while Name_Len >= Name_Buffer'First
2104 and then Name_Buffer (Name_Len) = NUL
2106 Name_Len := Name_Len - 1;
2109 if Name_Len = 0 then
2112 elsif Name_Buffer (1) = '-' then
2114 -- Do not check if File is a switch other than "-l"
2116 if Name_Buffer (2) /= 'l' then
2120 -- The argument is a library switch, get actual name. It
2121 -- is necessary to make a copy of the relevant part of
2122 -- Name_Buffer as Get_Library_Name uses Name_Buffer as well.
2125 Base_Name : constant String := Name_Buffer (3 .. Name_Len);
2128 Name := Get_Library_File (Base_Name);
2131 if Name = No_File then
2136 Stamp := File_Stamp (Name);
2138 -- Find the youngest object file that is younger than the
2139 -- executable. If no such file exist, record the first object
2140 -- file that is not found.
2142 if (O_Stamp < Stamp and then E_Stamp < Stamp)
2143 or else (O_File = No_File and then Stamp (Stamp'First) = ' ')
2148 -- Strip the trailing NUL if present
2150 Get_Name_String (O_File);
2152 if Name_Buffer (Name_Len) = NUL then
2153 Name_Len := Name_Len - 1;
2154 O_File := Name_Find;
2159 ----------------------
2160 -- Get_Library_Name --
2161 ----------------------
2163 -- See comments in a-adaint.c about template syntax
2165 function Get_Library_File (Name : String) return File_Name_Type is
2166 File : File_Name_Type := No_File;
2171 for Ptr in Template'Range loop
2172 case Template (Ptr) is
2174 Add_Str_To_Name_Buffer (Name);
2177 File := Full_Lib_File_Name (Name_Find);
2178 exit when File /= No_File;
2185 Add_Char_To_Name_Buffer (Template (Ptr));
2189 -- The for loop exited because the end of the template
2190 -- was reached. File contains the last possible file name
2193 if File = No_File and then Name_Len > 0 then
2194 File := Full_Lib_File_Name (Name_Find);
2198 end Get_Library_File;
2200 -- Start of processing for Check_Linker_Options
2204 O_Stamp := (others => ' ');
2206 -- Process linker options from the ALI files
2208 for Opt in 1 .. Linker_Options.Last loop
2209 Check_File (File_Name_Type (Linker_Options.Table (Opt).Name));
2212 -- Process options given on the command line
2214 for Opt in Linker_Switches.First .. Linker_Switches.Last loop
2216 -- Check if the previous Opt has one of the two switches
2217 -- that take an extra parameter. (See GCC manual.)
2219 if Opt = Linker_Switches.First
2220 or else (Linker_Switches.Table (Opt - 1).all /= "-u"
2222 Linker_Switches.Table (Opt - 1).all /= "-Xlinker"
2224 Linker_Switches.Table (Opt - 1).all /= "-L")
2227 Add_Str_To_Name_Buffer (Linker_Switches.Table (Opt).all);
2228 Check_File (Name_Find);
2232 end Check_Linker_Options;
2238 procedure Check_Steps is
2240 -- If either -c, -b or -l has been specified, we will not necessarily
2241 -- execute all steps.
2244 Do_Compile_Step := Do_Compile_Step and Compile_Only;
2245 Do_Bind_Step := Do_Bind_Step and Bind_Only;
2246 Do_Link_Step := Do_Link_Step and Link_Only;
2248 -- If -c has been specified, but not -b, ignore any potential -l
2250 if Do_Compile_Step and then not Do_Bind_Step then
2251 Do_Link_Step := False;
2256 -----------------------
2257 -- Collect_Arguments --
2258 -----------------------
2260 procedure Collect_Arguments
2261 (Source_File : File_Name_Type;
2263 Args : Argument_List)
2266 Arguments_Collected := True;
2267 Arguments_Project := No_Project;
2269 Add_Arguments (Args);
2271 if Main_Project /= No_Project then
2273 Source_File_Name : constant String :=
2274 Get_Name_String (Source_File);
2275 Compiler_Package : Prj.Package_Id;
2276 Switches : Prj.Variable_Value;
2277 Data : Project_Data;
2282 (Source_File_Name => Source_File_Name,
2283 Project => Arguments_Project,
2284 Path => Arguments_Path_Name,
2285 In_Tree => Project_Tree);
2287 -- If the source is not a source of a project file, add the
2288 -- recorded arguments. Check will be done later if the source
2289 -- need to be compiled that the switch -x has been used.
2291 if Arguments_Project = No_Project then
2292 Add_Arguments (The_Saved_Gcc_Switches.all);
2294 elsif not Project_Tree.Projects.Table
2295 (Arguments_Project).Externally_Built
2297 -- We get the project directory for the relative path
2298 -- switches and arguments.
2300 Data := Project_Tree.Projects.Table (Arguments_Project);
2302 -- If the source is in an extended project, we go to
2303 -- the ultimate extending project.
2305 while Data.Extended_By /= No_Project loop
2306 Arguments_Project := Data.Extended_By;
2307 Data := Project_Tree.Projects.Table (Arguments_Project);
2310 -- If building a dynamic or relocatable library, compile with
2311 -- PIC option, if it exists.
2313 if Data.Library and then Data.Library_Kind /= Static then
2315 PIC : constant String := MLib.Tgt.PIC_Option;
2319 Add_Arguments ((1 => new String'(PIC)));
2324 if Data.Dir_Path = null then
2326 new String'(Get_Name_String (Data.Display_Directory));
2327 Project_Tree.Projects.Table (Arguments_Project) :=
2331 -- We now look for package Compiler and get the switches from
2336 (Name => Name_Compiler,
2337 In_Packages => Data.Decl.Packages,
2338 In_Tree => Project_Tree);
2340 if Compiler_Package /= No_Package then
2342 -- If package Gnatmake.Compiler exists, we get the specific
2343 -- switches for the current source, or the global switches,
2348 (Source_File => Source_File,
2349 Source_File_Name => Source_File_Name,
2350 Source_Index => Source_Index,
2351 Naming => Data.Naming,
2352 In_Package => Compiler_Package,
2353 Allow_ALI => False);
2357 case Switches.Kind is
2359 -- We have a list of switches. We add these switches,
2360 -- plus the saved gcc switches.
2365 Current : String_List_Id := Switches.Values;
2366 Element : String_Element;
2367 Number : Natural := 0;
2370 while Current /= Nil_String loop
2371 Element := Project_Tree.String_Elements.
2373 Number := Number + 1;
2374 Current := Element.Next;
2378 New_Args : Argument_List (1 .. Number);
2379 Last_New : Natural := 0;
2382 Current := Switches.Values;
2384 for Index in New_Args'Range loop
2385 Element := Project_Tree.String_Elements.
2387 Get_Name_String (Element.Value);
2389 if Name_Len > 0 then
2390 Last_New := Last_New + 1;
2391 New_Args (Last_New) :=
2392 new String'(Name_Buffer (1 .. Name_Len));
2393 Test_If_Relative_Path
2394 (New_Args (Last_New),
2395 Parent => Data.Dir_Path,
2396 Including_Non_Switch => False);
2399 Current := Element.Next;
2403 (Configuration_Pragmas_Switch
2404 (Arguments_Project) &
2405 New_Args (1 .. Last_New) &
2406 The_Saved_Gcc_Switches.all);
2410 -- We have a single switch. We add this switch,
2411 -- plus the saved gcc switches.
2414 Get_Name_String (Switches.Value);
2417 New_Args : Argument_List :=
2419 (Name_Buffer (1 .. Name_Len)));
2422 Test_If_Relative_Path
2424 Parent => Data.Dir_Path,
2425 Including_Non_Switch => False);
2427 (Configuration_Pragmas_Switch (Arguments_Project) &
2428 New_Args & The_Saved_Gcc_Switches.all);
2431 -- We have no switches from Gnatmake.Compiler.
2432 -- We add the saved gcc switches.
2436 (Configuration_Pragmas_Switch (Arguments_Project) &
2437 The_Saved_Gcc_Switches.all);
2443 -- Set Output_Is_Object, depending if there is a -S switch.
2444 -- If the bind step is not performed, and there is a -S switch,
2445 -- then we will not check for a valid object file.
2448 end Collect_Arguments;
2450 ---------------------
2451 -- Compile_Sources --
2452 ---------------------
2454 procedure Compile_Sources
2455 (Main_Source : File_Name_Type;
2456 Args : Argument_List;
2457 First_Compiled_File : out File_Name_Type;
2458 Most_Recent_Obj_File : out File_Name_Type;
2459 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
2460 Main_Unit : out Boolean;
2461 Compilation_Failures : out Natural;
2462 Main_Index : Int := 0;
2463 Check_Readonly_Files : Boolean := False;
2464 Do_Not_Execute : Boolean := False;
2465 Force_Compilations : Boolean := False;
2466 Keep_Going : Boolean := False;
2467 In_Place_Mode : Boolean := False;
2468 Initialize_ALI_Data : Boolean := True;
2469 Max_Process : Positive := 1)
2471 Source_Unit : Unit_Name_Type;
2472 -- Current source unit
2474 Source_File : File_Name_Type;
2475 -- Current source file
2477 Full_Source_File : File_Name_Type;
2478 -- Full name of the current source file
2480 Lib_File : File_Name_Type;
2481 -- Current library file
2483 Full_Lib_File : File_Name_Type;
2484 -- Full name of the current library file
2486 Obj_File : File_Name_Type;
2487 -- Full name of the object file corresponding to Lib_File
2489 Obj_Stamp : Time_Stamp_Type;
2490 -- Time stamp of the current object file
2492 Sfile : File_Name_Type;
2493 -- Contains the source file of the units withed by Source_File
2495 Uname : Unit_Name_Type;
2496 -- Contains the unit name of the units withed by Source_File
2499 -- ALI Id of the current ALI file
2501 -- Comment following declarations ???
2503 Read_Only : Boolean := False;
2505 Compilation_OK : Boolean;
2506 Need_To_Compile : Boolean;
2509 Text : Text_Buffer_Ptr;
2511 Mfile : Natural := No_Mapping_File;
2513 Need_To_Check_Standard_Library : Boolean :=
2514 Check_Readonly_Files
2515 and not Unique_Compile;
2517 Mapping_File_Arg : String_Access;
2519 Process_Created : Boolean := False;
2521 procedure Add_Process
2523 Sfile : File_Name_Type;
2524 Afile : File_Name_Type;
2525 Uname : Unit_Name_Type;
2526 Mfile : Natural := No_Mapping_File);
2527 -- Adds process Pid to the current list of outstanding compilation
2528 -- processes and record the full name of the source file Sfile that
2529 -- we are compiling, the name of its library file Afile and the
2530 -- name of its unit Uname. If Mfile is not equal to No_Mapping_File,
2531 -- it is the index of the mapping file used during compilation in the
2532 -- array The_Mapping_File_Names.
2534 procedure Await_Compile
2535 (Sfile : out File_Name_Type;
2536 Afile : out File_Name_Type;
2537 Uname : out Unit_Name_Type;
2539 -- Awaits that an outstanding compilation process terminates. When
2540 -- it does set Sfile to the name of the source file that was compiled
2541 -- Afile to the name of its library file and Uname to the name of its
2542 -- unit. Note that this time stamp can be used to check whether the
2543 -- compilation did generate an object file. OK is set to True if the
2544 -- compilation succeeded. Note that Sfile, Afile and Uname could be
2545 -- resp. No_File, No_File and No_Name if there were no compilations
2548 function Bad_Compilation_Count return Natural;
2549 -- Returns the number of compilation failures
2551 procedure Check_Standard_Library;
2552 -- Check if s-stalib.adb needs to be compiled
2554 procedure Collect_Arguments_And_Compile
2555 (Source_File : File_Name_Type;
2556 Source_Index : Int);
2557 -- Collect arguments from project file (if any) and compile
2560 (S : File_Name_Type;
2563 Args : Argument_List) return Process_Id;
2564 -- Compiles S using Args. If S is a GNAT predefined source "-gnatpg" is
2565 -- added to Args. Non blocking call. L corresponds to the expected
2566 -- library file name. Process_Id of the process spawned to execute the
2569 package Good_ALI is new Table.Table (
2570 Table_Component_Type => ALI_Id,
2571 Table_Index_Type => Natural,
2572 Table_Low_Bound => 1,
2573 Table_Initial => 50,
2574 Table_Increment => 100,
2575 Table_Name => "Make.Good_ALI");
2576 -- Contains the set of valid ALI files that have not yet been scanned
2578 function Good_ALI_Present return Boolean;
2579 -- Returns True if any ALI file was recorded in the previous set
2581 procedure Get_Mapping_File (Project : Project_Id);
2582 -- Get a mapping file name. If there is one to be reused, reuse it.
2583 -- Otherwise, create a new mapping file.
2585 function Get_Next_Good_ALI return ALI_Id;
2586 -- Returns the next good ALI_Id record
2588 procedure Record_Failure
2589 (File : File_Name_Type;
2590 Unit : Unit_Name_Type;
2591 Found : Boolean := True);
2592 -- Records in the previous table that the compilation for File failed.
2593 -- If Found is False then the compilation of File failed because we
2594 -- could not find it. Records also Unit when possible.
2596 procedure Record_Good_ALI (A : ALI_Id);
2597 -- Records in the previous set the Id of an ALI file
2603 procedure Add_Process
2605 Sfile : File_Name_Type;
2606 Afile : File_Name_Type;
2607 Uname : Unit_Name_Type;
2608 Mfile : Natural := No_Mapping_File)
2610 OC1 : constant Positive := Outstanding_Compiles + 1;
2613 pragma Assert (OC1 <= Max_Process);
2614 pragma Assert (Pid /= Invalid_Pid);
2616 Running_Compile (OC1).Pid := Pid;
2617 Running_Compile (OC1).Full_Source_File := Sfile;
2618 Running_Compile (OC1).Lib_File := Afile;
2619 Running_Compile (OC1).Source_Unit := Uname;
2620 Running_Compile (OC1).Mapping_File := Mfile;
2621 Running_Compile (OC1).Project := Arguments_Project;
2622 Running_Compile (OC1).Syntax_Only := Syntax_Only;
2623 Running_Compile (OC1).Output_Is_Object := Output_Is_Object;
2625 Outstanding_Compiles := OC1;
2628 --------------------
2632 procedure Await_Compile
2633 (Sfile : out File_Name_Type;
2634 Afile : out File_Name_Type;
2635 Uname : out Unit_Name_Type;
2639 Project : Project_Id;
2642 pragma Assert (Outstanding_Compiles > 0);
2646 Uname := No_Unit_Name;
2649 -- The loop here is a work-around for a problem on VMS; in some
2650 -- circumstances (shared library and several executables, for
2651 -- example), there are child processes other than compilation
2652 -- processes that are received. Until this problem is resolved,
2653 -- we will ignore such processes.
2656 Wait_Process (Pid, OK);
2658 if Pid = Invalid_Pid then
2662 for J in Running_Compile'First .. Outstanding_Compiles loop
2663 if Pid = Running_Compile (J).Pid then
2664 Sfile := Running_Compile (J).Full_Source_File;
2665 Afile := Running_Compile (J).Lib_File;
2666 Uname := Running_Compile (J).Source_Unit;
2667 Syntax_Only := Running_Compile (J).Syntax_Only;
2668 Output_Is_Object := Running_Compile (J).Output_Is_Object;
2669 Project := Running_Compile (J).Project;
2671 -- If a mapping file was used by this compilation,
2672 -- get its file name for reuse by a subsequent compilation
2674 if Running_Compile (J).Mapping_File /= No_Mapping_File then
2675 Last_Free_Indices (Project) :=
2676 Last_Free_Indices (Project) + 1;
2677 The_Free_Mapping_File_Indices
2678 (Project, Last_Free_Indices (Project)) :=
2679 Running_Compile (J).Mapping_File;
2682 -- To actually remove this Pid and related info from
2683 -- Running_Compile replace its entry with the last valid
2684 -- entry in Running_Compile.
2686 if J = Outstanding_Compiles then
2690 Running_Compile (J) :=
2691 Running_Compile (Outstanding_Compiles);
2694 Outstanding_Compiles := Outstanding_Compiles - 1;
2699 -- This child process was not one of our compilation processes;
2700 -- just ignore it for now.
2702 -- raise Program_Error;
2706 ---------------------------
2707 -- Bad_Compilation_Count --
2708 ---------------------------
2710 function Bad_Compilation_Count return Natural is
2712 return Bad_Compilation.Last - Bad_Compilation.First + 1;
2713 end Bad_Compilation_Count;
2715 ----------------------------
2716 -- Check_Standard_Library --
2717 ----------------------------
2719 procedure Check_Standard_Library is
2721 Need_To_Check_Standard_Library := False;
2723 if not Targparm.Suppress_Standard_Library_On_Target then
2725 Sfile : File_Name_Type;
2726 Add_It : Boolean := True;
2729 Name_Len := Standard_Library_Package_Body_Name'Length;
2730 Name_Buffer (1 .. Name_Len) :=
2731 Standard_Library_Package_Body_Name;
2732 Sfile := Name_Enter;
2734 -- If we have a special runtime, we add the standard
2735 -- library only if we can find it.
2739 Find_File (Sfile, Osint.Source) /= No_File;
2743 if Is_Marked (Sfile) then
2744 if Is_In_Obsoleted (Sfile) then
2745 Executable_Obsolete := True;
2749 Insert_Q (Sfile, Index => 0);
2750 Mark (Sfile, Index => 0);
2755 end Check_Standard_Library;
2757 -----------------------------------
2758 -- Collect_Arguments_And_Compile --
2759 -----------------------------------
2761 procedure Collect_Arguments_And_Compile
2762 (Source_File : File_Name_Type;
2766 -- Process_Created will be set True if an attempt is made to compile
2767 -- the source, that is if it is not in an externally built project.
2769 Process_Created := False;
2771 -- If arguments not yet collected (in Check), collect them now
2773 if not Arguments_Collected then
2774 Collect_Arguments (Source_File, Source_Index, Args);
2777 -- For VMS, when compiling the main source, add switch
2778 -- -mdebug-main=_ada_ so that the executable can be debugged
2779 -- by the standard VMS debugger.
2781 if not No_Main_Subprogram
2782 and then Targparm.OpenVMS_On_Target
2783 and then Source_File = Main_Source
2785 -- First, check if compilation will be invoked with -g
2787 for J in 1 .. Last_Argument loop
2788 if Arguments (J)'Length >= 2
2789 and then Arguments (J) (1 .. 2) = "-g"
2790 and then (Arguments (J)'Length < 5
2791 or else Arguments (J) (1 .. 5) /= "-gnat")
2794 ((1 => new String'("-mdebug-main=_ada_")));
2800 -- If we use mapping file (-P or -C switches), then get one
2802 if Create_Mapping_File then
2803 Get_Mapping_File (Arguments_Project);
2806 -- If the source is part of a project file, we set the ADA_*_PATHs,
2807 -- check for an eventual library project, and use the full path.
2809 if Arguments_Project /= No_Project then
2810 if not Project_Tree.Projects.Table
2811 (Arguments_Project).Externally_Built
2813 Prj.Env.Set_Ada_Paths (Arguments_Project, Project_Tree, True);
2815 if not Unique_Compile
2816 and then MLib.Tgt.Support_For_Libraries /= Prj.None
2819 The_Data : Project_Data :=
2820 Project_Tree.Projects.Table
2821 (Arguments_Project);
2823 Prj : Project_Id := Arguments_Project;
2826 while The_Data.Extended_By /= No_Project loop
2827 Prj := The_Data.Extended_By;
2828 The_Data := Project_Tree.Projects.Table (Prj);
2832 and then not The_Data.Need_To_Build_Lib
2834 -- Add to the Q all sources of the project that
2835 -- have not been marked
2837 Insert_Project_Sources
2838 (The_Project => Prj,
2839 All_Projects => False,
2842 -- Now mark the project as processed
2844 Project_Tree.Projects.Table
2845 (Prj).Need_To_Build_Lib := True;
2850 -- Change to the object directory of the project file,
2853 Change_To_Object_Directory (Arguments_Project);
2857 (File_Name_Type (Arguments_Path_Name),
2860 Arguments (1 .. Last_Argument));
2861 Process_Created := True;
2865 -- If this is a source outside of any project file, make sure it
2866 -- will be compiled in object directory of the main project file.
2868 if Main_Project /= No_Project then
2869 Change_To_Object_Directory (Arguments_Project);
2872 Pid := Compile (Full_Source_File, Lib_File, Source_Index,
2873 Arguments (1 .. Last_Argument));
2874 Process_Created := True;
2876 end Collect_Arguments_And_Compile;
2883 (S : File_Name_Type;
2886 Args : Argument_List) return Process_Id
2888 Comp_Args : Argument_List (Args'First .. Args'Last + 9);
2889 Comp_Next : Integer := Args'First;
2890 Comp_Last : Integer;
2891 Arg_Index : Integer;
2893 function Ada_File_Name (Name : File_Name_Type) return Boolean;
2894 -- Returns True if Name is the name of an ada source file
2895 -- (i.e. suffix is .ads or .adb)
2901 function Ada_File_Name (Name : File_Name_Type) return Boolean is
2903 Get_Name_String (Name);
2906 and then Name_Buffer (Name_Len - 3 .. Name_Len - 1) = ".ad"
2907 and then (Name_Buffer (Name_Len) = 'b'
2909 Name_Buffer (Name_Len) = 's');
2912 -- Start of processing for Compile
2915 Enter_Into_Obsoleted (S);
2917 -- By default, Syntax_Only is False
2919 Syntax_Only := False;
2921 for J in Args'Range loop
2922 if Args (J).all = "-gnats" then
2924 -- If we compile with -gnats, the bind step and the link step
2925 -- are inhibited. Also, we set Syntax_Only to True, so that
2926 -- we don't fail when we don't find the ALI file, after
2929 Do_Bind_Step := False;
2930 Do_Link_Step := False;
2931 Syntax_Only := True;
2933 elsif Args (J).all = "-gnatc" then
2935 -- If we compile with -gnatc, the bind step and the link step
2936 -- are inhibited. We set Syntax_Only to False for the case when
2937 -- -gnats was previously specified.
2939 Do_Bind_Step := False;
2940 Do_Link_Step := False;
2941 Syntax_Only := False;
2945 Comp_Args (Comp_Next) := Comp_Flag;
2946 Comp_Next := Comp_Next + 1;
2948 -- Optimize the simple case where the gcc command line looks like
2949 -- gcc -c -I. ... -I- file.adb --into-> gcc -c ... file.adb
2951 if Args (Args'First).all = "-I" & Normalized_CWD
2952 and then Args (Args'Last).all = "-I-"
2953 and then S = Strip_Directory (S)
2955 Comp_Last := Comp_Next + Args'Length - 3;
2956 Arg_Index := Args'First + 1;
2959 Comp_Last := Comp_Next + Args'Length - 1;
2960 Arg_Index := Args'First;
2963 -- Make a deep copy of the arguments, because Normalize_Arguments
2964 -- may deallocate some arguments.
2966 for J in Comp_Next .. Comp_Last loop
2967 Comp_Args (J) := new String'(Args (Arg_Index).all);
2968 Arg_Index := Arg_Index + 1;
2971 -- Set -gnatpg for predefined files (for this purpose the renamings
2972 -- such as Text_IO do not count as predefined). Note that we strip
2973 -- the directory name from the source file name becase the call to
2974 -- Fname.Is_Predefined_File_Name cannot deal with directory prefixes.
2977 Fname : constant File_Name_Type := Strip_Directory (S);
2980 if Is_Predefined_File_Name (Fname, False) then
2981 if Check_Readonly_Files then
2982 Comp_Args (Comp_Args'First + 2 .. Comp_Last + 1) :=
2983 Comp_Args (Comp_Args'First + 1 .. Comp_Last);
2984 Comp_Last := Comp_Last + 1;
2985 Comp_Args (Comp_Args'First + 1) := GNAT_Flag;
2989 ("not allowed to compile """ &
2990 Get_Name_String (Fname) &
2991 """; use -a switch, or compile file with " &
2992 """-gnatg"" switch");
2997 -- Now check if the file name has one of the suffixes familiar to
2998 -- the gcc driver. If this is not the case then add the ada flag
3001 if not Ada_File_Name (S) and then not Targparm.AAMP_On_Target then
3002 Comp_Last := Comp_Last + 1;
3003 Comp_Args (Comp_Last) := Ada_Flag_1;
3004 Comp_Last := Comp_Last + 1;
3005 Comp_Args (Comp_Last) := Ada_Flag_2;
3008 if Source_Index /= 0 then
3010 Num : constant String := Source_Index'Img;
3012 Comp_Last := Comp_Last + 1;
3013 Comp_Args (Comp_Last) :=
3014 new String'("-gnateI" & Num (Num'First + 1 .. Num'Last));
3018 if Source_Index /= 0
3019 or else L /= Strip_Directory (L)
3020 or else Object_Directory_Path /= null
3022 -- Build -o argument
3024 Get_Name_String (L);
3026 for J in reverse 1 .. Name_Len loop
3027 if Name_Buffer (J) = '.' then
3028 Name_Len := J + Object_Suffix'Length - 1;
3029 Name_Buffer (J .. Name_Len) := Object_Suffix;
3034 Comp_Last := Comp_Last + 1;
3035 Comp_Args (Comp_Last) := Output_Flag;
3036 Comp_Last := Comp_Last + 1;
3038 -- If an object directory was specified, prepend the object file
3039 -- name with this object directory.
3041 if Object_Directory_Path /= null then
3042 Comp_Args (Comp_Last) :=
3043 new String'(Object_Directory_Path.all &
3044 Name_Buffer (1 .. Name_Len));
3047 Comp_Args (Comp_Last) :=
3048 new String'(Name_Buffer (1 .. Name_Len));
3052 if Create_Mapping_File then
3053 Comp_Last := Comp_Last + 1;
3054 Comp_Args (Comp_Last) := Mapping_File_Arg;
3057 Get_Name_String (S);
3059 Comp_Last := Comp_Last + 1;
3060 Comp_Args (Comp_Last) := new String'(Name_Buffer (1 .. Name_Len));
3062 GNAT.OS_Lib.Normalize_Arguments (Comp_Args (Args'First .. Comp_Last));
3064 Comp_Last := Comp_Last + 1;
3065 Comp_Args (Comp_Last) := new String'("-gnatez");
3067 Display (Gcc.all, Comp_Args (Args'First .. Comp_Last));
3069 if Gcc_Path = null then
3070 Make_Failed ("error, unable to locate ", Gcc.all);
3074 GNAT.OS_Lib.Non_Blocking_Spawn
3075 (Gcc_Path.all, Comp_Args (Args'First .. Comp_Last));
3078 ----------------------
3079 -- Get_Mapping_File --
3080 ----------------------
3082 procedure Get_Mapping_File (Project : Project_Id) is
3084 -- If there is a mapping file ready to be reused, reuse it
3086 if Last_Free_Indices (Project) > 0 then
3087 Mfile := The_Free_Mapping_File_Indices
3088 (Project, Last_Free_Indices (Project));
3089 Last_Free_Indices (Project) := Last_Free_Indices (Project) - 1;
3091 -- Otherwise, create and initialize a new one
3094 Init_Mapping_File (Project => Project, File_Index => Mfile);
3097 -- Put the name in the mapping file argument for the invocation
3100 Free (Mapping_File_Arg);
3102 new String'("-gnatem=" &
3104 (The_Mapping_File_Names (Project, Mfile)));
3106 end Get_Mapping_File;
3108 -----------------------
3109 -- Get_Next_Good_ALI --
3110 -----------------------
3112 function Get_Next_Good_ALI return ALI_Id is
3116 pragma Assert (Good_ALI_Present);
3117 ALI := Good_ALI.Table (Good_ALI.Last);
3118 Good_ALI.Decrement_Last;
3120 end Get_Next_Good_ALI;
3122 ----------------------
3123 -- Good_ALI_Present --
3124 ----------------------
3126 function Good_ALI_Present return Boolean is
3128 return Good_ALI.First <= Good_ALI.Last;
3129 end Good_ALI_Present;
3131 --------------------
3132 -- Record_Failure --
3133 --------------------
3135 procedure Record_Failure
3136 (File : File_Name_Type;
3137 Unit : Unit_Name_Type;
3138 Found : Boolean := True)
3141 Bad_Compilation.Increment_Last;
3142 Bad_Compilation.Table (Bad_Compilation.Last) := (File, Unit, Found);
3145 ---------------------
3146 -- Record_Good_ALI --
3147 ---------------------
3149 procedure Record_Good_ALI (A : ALI_Id) is
3151 Good_ALI.Increment_Last;
3152 Good_ALI.Table (Good_ALI.Last) := A;
3153 end Record_Good_ALI;
3155 -- Start of processing for Compile_Sources
3158 pragma Assert (Args'First = 1);
3160 Outstanding_Compiles := 0;
3161 Running_Compile := new Comp_Data_Arr (1 .. Max_Process);
3163 -- Package and Queue initializations
3167 if First_Q_Initialization then
3171 if Initialize_ALI_Data then
3173 Initialize_ALI_Source;
3176 -- The following two flags affect the behavior of ALI.Set_Source_Table.
3177 -- We set Check_Source_Files to True to ensure that source file
3178 -- time stamps are checked, and we set All_Sources to False to
3179 -- avoid checking the presence of the source files listed in the
3180 -- source dependency section of an ali file (which would be a mistake
3181 -- since the ali file may be obsolete).
3183 Check_Source_Files := True;
3184 All_Sources := False;
3186 -- Only insert in the Q if it is not already done, to avoid simultaneous
3187 -- compilations if -jnnn is used.
3189 if not Is_Marked (Main_Source, Main_Index) then
3190 Insert_Q (Main_Source, Index => Main_Index);
3191 Mark (Main_Source, Main_Index);
3194 First_Compiled_File := No_File;
3195 Most_Recent_Obj_File := No_File;
3196 Most_Recent_Obj_Stamp := Empty_Time_Stamp;
3199 -- Keep looping until there is no more work to do (the Q is empty)
3200 -- and all the outstanding compilations have terminated
3202 Make_Loop : while not Empty_Q or else Outstanding_Compiles > 0 loop
3204 -- If the user does not want to keep going in case of errors then
3205 -- wait for the remaining outstanding compiles and then exit.
3207 if Bad_Compilation_Count > 0 and then not Keep_Going then
3208 while Outstanding_Compiles > 0 loop
3210 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
3212 if not Compilation_OK then
3213 Record_Failure (Full_Source_File, Source_Unit);
3220 -- PHASE 1: Check if there is more work that we can do (ie the Q
3221 -- is non empty). If there is, do it only if we have not yet used
3222 -- up all the available processes.
3224 if not Empty_Q and then Outstanding_Compiles < Max_Process then
3227 -- Index of the current unit in the current source file
3230 Extract_From_Q (Source_File, Source_Unit, Source_Index);
3231 Full_Source_File := Osint.Full_Source_Name (Source_File);
3232 Lib_File := Osint.Lib_File_Name
3233 (Source_File, Source_Index);
3234 Full_Lib_File := Osint.Full_Lib_File_Name (Lib_File);
3236 -- If this source has already been compiled, the executable is
3239 if Is_In_Obsoleted (Source_File) then
3240 Executable_Obsolete := True;
3243 -- If the library file is an Ada library skip it
3245 if Full_Lib_File /= No_File
3246 and then In_Ada_Lib_Dir (Full_Lib_File)
3250 "is in an Ada library",
3252 Minimum_Verbosity => Opt.High);
3254 -- If the library file is a read-only library skip it, but
3255 -- only if, when using project files, this library file is
3256 -- in the right object directory (a read-only ALI file
3257 -- in the object directory of a project being extended
3258 -- should not be skipped).
3260 elsif Full_Lib_File /= No_File
3261 and then not Check_Readonly_Files
3262 and then Is_Readonly_Library (Full_Lib_File)
3263 and then Is_In_Object_Directory (Source_File, Full_Lib_File)
3267 "is a read-only library",
3269 Minimum_Verbosity => Opt.High);
3271 -- The source file that we are checking cannot be located
3273 elsif Full_Source_File = No_File then
3274 Record_Failure (Source_File, Source_Unit, False);
3276 -- Source and library files can be located but are internal
3279 elsif not Check_Readonly_Files
3280 and then Full_Lib_File /= No_File
3281 and then Is_Internal_File_Name (Source_File, False)
3283 if Force_Compilations then
3285 ("not allowed to compile """ &
3286 Get_Name_String (Source_File) &
3287 """; use -a switch, or compile file with " &
3288 """-gnatg"" switch");
3293 "is an internal library",
3295 Minimum_Verbosity => Opt.High);
3297 -- The source file that we are checking can be located
3300 Arguments_Collected := False;
3302 -- Do nothing if project of source is externally built
3304 Collect_Arguments (Source_File, Source_Index, Args);
3306 if Arguments_Project = No_Project
3307 or else not Project_Tree.Projects.Table
3308 (Arguments_Project).Externally_Built
3310 -- Don't waste any time if we have to recompile anyway
3312 Obj_Stamp := Empty_Time_Stamp;
3313 Need_To_Compile := Force_Compilations;
3315 if not Force_Compilations then
3317 Full_Lib_File /= No_File
3318 and then not Check_Readonly_Files
3319 and then Is_Readonly_Library (Full_Lib_File);
3320 Check (Source_File, Source_Index, Args, Lib_File,
3321 Read_Only, ALI, Obj_File, Obj_Stamp);
3322 Need_To_Compile := (ALI = No_ALI_Id);
3325 if not Need_To_Compile then
3326 -- The ALI file is up-to-date. Record its Id
3328 Record_Good_ALI (ALI);
3330 -- Record the time stamp of the most recent object
3331 -- file as long as no (re)compilations are needed.
3333 if First_Compiled_File = No_File
3334 and then (Most_Recent_Obj_File = No_File
3335 or else Obj_Stamp > Most_Recent_Obj_Stamp)
3337 Most_Recent_Obj_File := Obj_File;
3338 Most_Recent_Obj_Stamp := Obj_Stamp;
3342 -- Check that switch -x has been used if a source
3343 -- outside of project files need to be compiled.
3345 if Main_Project /= No_Project
3346 and then Arguments_Project = No_Project
3347 and then not External_Unit_Compilation_Allowed
3349 Make_Failed ("external source (",
3350 Get_Name_String (Source_File),
3351 ") is not part of any project;"
3352 & " cannot be compiled without" &
3353 " gnatmake switch -x");
3356 -- Is this the first file we have to compile?
3358 if First_Compiled_File = No_File then
3359 First_Compiled_File := Full_Source_File;
3360 Most_Recent_Obj_File := No_File;
3362 if Do_Not_Execute then
3367 if In_Place_Mode then
3369 -- If the library file was not found, then save
3370 -- the library file near the source file.
3372 if Full_Lib_File = No_File then
3373 Lib_File := Osint.Lib_File_Name
3374 (Full_Source_File, Source_Index);
3376 -- If the library file was found, then save the
3377 -- library file in the same place.
3380 Lib_File := Full_Lib_File;
3385 -- Start the compilation and record it. We can do
3386 -- this because there is at least one free process.
3388 Collect_Arguments_And_Compile
3389 (Source_File, Source_Index);
3391 -- Make sure we could successfully start
3394 if Process_Created then
3395 if Pid = Invalid_Pid then
3396 Record_Failure (Full_Source_File, Source_Unit);
3412 -- PHASE 2: Now check if we should wait for a compilation to
3413 -- finish. This is the case if all the available processes are
3414 -- busy compiling sources or there is nothing else to do
3415 -- (that is the Q is empty and there are no good ALIs to process).
3417 if Outstanding_Compiles = Max_Process
3419 and then not Good_ALI_Present
3420 and then Outstanding_Compiles > 0)
3423 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
3425 if not Compilation_OK then
3426 Record_Failure (Full_Source_File, Source_Unit);
3429 if Compilation_OK or else Keep_Going then
3431 -- Re-read the updated library file
3434 Saved_Object_Consistency : constant Boolean :=
3435 Check_Object_Consistency;
3438 -- If compilation was not OK, or if output is not an
3439 -- object file and we don't do the bind step, don't check
3440 -- for object consistency.
3442 Check_Object_Consistency :=
3443 Check_Object_Consistency
3445 and (Output_Is_Object or Do_Bind_Step);
3446 Text := Read_Library_Info (Lib_File);
3448 -- Restore Check_Object_Consistency to its initial value
3450 Check_Object_Consistency := Saved_Object_Consistency;
3453 -- If an ALI file was generated by this compilation, scan
3454 -- the ALI file and record it.
3455 -- If the scan fails, a previous ali file is inconsistent with
3456 -- the unit just compiled.
3458 if Text /= null then
3460 Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
3462 if ALI = No_ALI_Id then
3464 -- Record a failure only if not already done
3466 if Compilation_OK then
3469 "incompatible ALI file, please recompile");
3470 Record_Failure (Full_Source_File, Source_Unit);
3474 Record_Good_ALI (ALI);
3477 -- If we could not read the ALI file that was just generated
3478 -- then there could be a problem reading either the ALI or the
3479 -- corresponding object file (if Check_Object_Consistency
3480 -- is set Read_Library_Info checks that the time stamp of the
3481 -- object file is more recent than that of the ALI). For an
3482 -- example of problems caught by this test see [6625-009].
3483 -- However, we record a failure only if not already done.
3486 if Compilation_OK and not Syntax_Only then
3489 "WARNING: ALI or object file not found after compile");
3490 Record_Failure (Full_Source_File, Source_Unit);
3496 -- PHASE 3: Check if we recorded good ALI files. If yes process
3497 -- them now in the order in which they have been recorded. There
3498 -- are two occasions in which we record good ali files. The first is
3499 -- in phase 1 when, after scanning an existing ALI file we realize
3500 -- it is up-to-date, the second instance is after a successful
3503 while Good_ALI_Present loop
3504 ALI := Get_Next_Good_ALI;
3507 Source_Index : Int := Unit_Index_Of (ALIs.Table (ALI).Afile);
3510 -- If we are processing the library file corresponding to the
3511 -- main source file check if this source can be a main unit.
3513 if ALIs.Table (ALI).Sfile = Main_Source and then
3514 Source_Index = Main_Index
3516 Main_Unit := ALIs.Table (ALI).Main_Program /= None;
3519 -- The following adds the standard library (s-stalib) to the
3520 -- list of files to be handled by gnatmake: this file and any
3521 -- files it depends on are always included in every bind,
3522 -- even if they are not in the explicit dependency list.
3523 -- Of course, it is not added if Suppress_Standard_Library
3526 -- However, to avoid annoying output about s-stalib.ali being
3527 -- read only, when "-v" is used, we add the standard library
3528 -- only when "-a" is used.
3530 if Need_To_Check_Standard_Library then
3531 Check_Standard_Library;
3534 -- Now insert in the Q the unmarked source files (i.e. those
3535 -- which have never been inserted in the Q and hence never
3536 -- considered). Only do that if Unique_Compile is False.
3538 if not Unique_Compile then
3540 ALIs.Table (ALI).First_Unit .. ALIs.Table (ALI).Last_Unit
3543 Units.Table (J).First_With .. Units.Table (J).Last_With
3545 Sfile := Withs.Table (K).Sfile;
3546 Uname := Withs.Table (K).Uname;
3548 -- If project files are used, find the proper source
3549 -- to compile, in case Sfile is the spec, but there
3552 if Main_Project /= No_Project then
3554 Unit_Name : Name_Id;
3555 Uid : Prj.Unit_Index;
3559 Get_Name_String (Uname);
3560 Name_Len := Name_Len - 2;
3561 Unit_Name := Name_Find;
3564 (Project_Tree.Units_HT, Unit_Name);
3566 if Uid /= Prj.No_Unit_Index then
3567 Udata := Project_Tree.Units.Table (Uid);
3570 Udata.File_Names (Body_Part).Name /=
3573 Udata.File_Names (Body_Part).Path /= Slash
3575 Sfile := Udata.File_Names (Body_Part).Name;
3577 Udata.File_Names (Body_Part).Index;
3580 Udata.File_Names (Specification).Name /=
3583 Udata.File_Names (Specification).Path /=
3587 Udata.File_Names (Specification).Name;
3589 Udata.File_Names (Specification).Index;
3595 Dependencies.Append ((ALIs.Table (ALI).Sfile, Sfile));
3597 if Is_In_Obsoleted (Sfile) then
3598 Executable_Obsolete := True;
3601 if Sfile = No_File then
3603 ("Skipping generic:", Withs.Table (K).Uname);
3607 Unit_Index_Of (Withs.Table (K).Afile);
3609 if Is_Marked (Sfile, Source_Index) then
3610 Debug_Msg ("Skipping marked file:", Sfile);
3612 elsif not Check_Readonly_Files
3613 and then Is_Internal_File_Name (Sfile, False)
3615 Debug_Msg ("Skipping internal file:", Sfile);
3619 (Sfile, Withs.Table (K).Uname, Source_Index);
3620 Mark (Sfile, Source_Index);
3629 if Display_Compilation_Progress then
3630 Write_Str ("completed ");
3631 Write_Int (Int (Q_Front));
3632 Write_Str (" out of ");
3633 Write_Int (Int (Q.Last));
3635 Write_Int (Int ((Q_Front * 100) / (Q.Last - Q.First)));
3636 Write_Str ("%)...");
3641 Compilation_Failures := Bad_Compilation_Count;
3643 -- Compilation is finished
3645 -- Delete any temporary configuration pragma file
3647 Delete_Temp_Config_Files;
3649 end Compile_Sources;
3651 -----------------------------------
3652 -- Compute_All_Imported_Projects --
3653 -----------------------------------
3655 procedure Compute_All_Imported_Projects (Project : Project_Id) is
3656 procedure Add_To_List (Prj : Project_Id);
3657 -- Add a project to the list All_Imported_Projects of project Project
3659 procedure Recursive_Add_Imported (Project : Project_Id);
3660 -- Recursively add the projects imported by project Project, but not
3661 -- those that are extended.
3667 procedure Add_To_List (Prj : Project_Id) is
3668 Element : constant Project_Element :=
3669 (Prj, Project_Tree.Projects.Table (Project).All_Imported_Projects);
3670 List : Project_List;
3672 Project_List_Table.Increment_Last (Project_Tree.Project_Lists);
3673 List := Project_List_Table.Last (Project_Tree.Project_Lists);
3674 Project_Tree.Project_Lists.Table (List) := Element;
3675 Project_Tree.Projects.Table (Project).All_Imported_Projects := List;
3678 ----------------------------
3679 -- Recursive_Add_Imported --
3680 ----------------------------
3682 procedure Recursive_Add_Imported (Project : Project_Id) is
3683 List : Project_List;
3684 Element : Project_Element;
3688 if Project /= No_Project then
3690 -- For all the imported projects
3692 List := Project_Tree.Projects.Table (Project).Imported_Projects;
3693 while List /= Empty_Project_List loop
3694 Element := Project_Tree.Project_Lists.Table (List);
3695 Prj := Element.Project;
3697 -- Get the ultimate extending project
3700 Project_Tree.Projects.Table (Prj).Extended_By /= No_Project
3702 Prj := Project_Tree.Projects.Table (Prj).Extended_By;
3705 -- If project has not yet been visited, add to list and recurse
3707 if not Project_Tree.Projects.Table (Prj).Seen then
3708 Project_Tree.Projects.Table (Prj).Seen := True;
3710 Recursive_Add_Imported (Prj);
3713 List := Element.Next;
3716 -- Recurse on projects being imported, if any
3718 Recursive_Add_Imported
3719 (Project_Tree.Projects.Table (Project).Extends);
3721 end Recursive_Add_Imported;
3724 -- Reset the Seen flag for all projects
3726 for Index in 1 .. Project_Table.Last (Project_Tree.Projects) loop
3727 Project_Tree.Projects.Table (Index).Seen := False;
3730 -- Make sure the list is empty
3732 Project_Tree.Projects.Table (Project).All_Imported_Projects :=
3735 -- Add to the list all projects imported directly or indirectly
3737 Recursive_Add_Imported (Project);
3738 end Compute_All_Imported_Projects;
3740 ----------------------------------
3741 -- Configuration_Pragmas_Switch --
3742 ----------------------------------
3744 function Configuration_Pragmas_Switch
3745 (For_Project : Project_Id) return Argument_List
3747 The_Packages : Package_Id;
3748 Gnatmake : Package_Id;
3749 Compiler : Package_Id;
3751 Global_Attribute : Variable_Value := Nil_Variable_Value;
3752 Local_Attribute : Variable_Value := Nil_Variable_Value;
3754 Global_Attribute_Present : Boolean := False;
3755 Local_Attribute_Present : Boolean := False;
3757 Result : Argument_List (1 .. 3);
3758 Last : Natural := 0;
3760 function Absolute_Path
3761 (Path : Path_Name_Type;
3762 Project : Project_Id) return String;
3763 -- Returns an absolute path for a configuration pragmas file
3769 function Absolute_Path
3770 (Path : Path_Name_Type;
3771 Project : Project_Id) return String
3774 Get_Name_String (Path);
3777 Path_Name : constant String := Name_Buffer (1 .. Name_Len);
3780 if Is_Absolute_Path (Path_Name) then
3785 Parent_Directory : constant String :=
3787 (Project_Tree.Projects.Table
3788 (Project).Display_Directory);
3791 if Parent_Directory (Parent_Directory'Last) =
3794 return Parent_Directory & Path_Name;
3797 return Parent_Directory & Directory_Separator & Path_Name;
3804 -- Start of processing for Configuration_Pragmas_Switch
3807 Prj.Env.Create_Config_Pragmas_File
3808 (For_Project, Main_Project, Project_Tree);
3810 if Project_Tree.Projects.Table
3811 (For_Project).Config_File_Name /= No_Path
3813 Temporary_Config_File :=
3814 Project_Tree.Projects.Table (For_Project).Config_File_Temp;
3820 (Project_Tree.Projects.Table
3821 (For_Project).Config_File_Name));
3824 Temporary_Config_File := False;
3827 -- Check for attribute Builder'Global_Configuration_Pragmas
3829 The_Packages := Project_Tree.Projects.Table
3830 (Main_Project).Decl.Packages;
3833 (Name => Name_Builder,
3834 In_Packages => The_Packages,
3835 In_Tree => Project_Tree);
3837 if Gnatmake /= No_Package then
3838 Global_Attribute := Prj.Util.Value_Of
3839 (Variable_Name => Name_Global_Configuration_Pragmas,
3840 In_Variables => Project_Tree.Packages.Table
3841 (Gnatmake).Decl.Attributes,
3842 In_Tree => Project_Tree);
3843 Global_Attribute_Present :=
3844 Global_Attribute /= Nil_Variable_Value
3845 and then Get_Name_String (Global_Attribute.Value) /= "";
3847 if Global_Attribute_Present then
3849 Path : constant String :=
3851 (Path_Name_Type (Global_Attribute.Value),
3852 Global_Attribute.Project);
3854 if not Is_Regular_File (Path) then
3856 ("cannot find configuration pragmas file ", Path);
3860 Result (Last) := new String'("-gnatec=" & Path);
3865 -- Check for attribute Compiler'Local_Configuration_Pragmas
3868 Project_Tree.Projects.Table (For_Project).Decl.Packages;
3871 (Name => Name_Compiler,
3872 In_Packages => The_Packages,
3873 In_Tree => Project_Tree);
3875 if Compiler /= No_Package then
3876 Local_Attribute := Prj.Util.Value_Of
3877 (Variable_Name => Name_Local_Configuration_Pragmas,
3878 In_Variables => Project_Tree.Packages.Table
3879 (Compiler).Decl.Attributes,
3880 In_Tree => Project_Tree);
3881 Local_Attribute_Present :=
3882 Local_Attribute /= Nil_Variable_Value
3883 and then Get_Name_String (Local_Attribute.Value) /= "";
3885 if Local_Attribute_Present then
3887 Path : constant String :=
3889 (Path_Name_Type (Local_Attribute.Value),
3890 Local_Attribute.Project);
3892 if not Is_Regular_File (Path) then
3894 ("cannot find configuration pragmas file ", Path);
3898 Result (Last) := new String'("-gnatec=" & Path);
3903 return Result (1 .. Last);
3904 end Configuration_Pragmas_Switch;
3910 procedure Debug_Msg (S : String; N : Name_Id) is
3912 if Debug.Debug_Flag_W then
3913 Write_Str (" ... ");
3921 procedure Debug_Msg (S : String; N : File_Name_Type) is
3923 Debug_Msg (S, Name_Id (N));
3926 procedure Debug_Msg (S : String; N : Unit_Name_Type) is
3928 Debug_Msg (S, Name_Id (N));
3931 ---------------------------
3932 -- Delete_All_Temp_Files --
3933 ---------------------------
3935 procedure Delete_All_Temp_Files is
3937 if Gnatmake_Called and not Debug.Debug_Flag_N then
3938 Delete_Mapping_Files;
3939 Delete_Temp_Config_Files;
3940 Prj.Env.Delete_All_Path_Files (Project_Tree);
3942 end Delete_All_Temp_Files;
3944 --------------------------
3945 -- Delete_Mapping_Files --
3946 --------------------------
3948 procedure Delete_Mapping_Files is
3950 pragma Warnings (Off, Success);
3952 if not Debug.Debug_Flag_N then
3953 if The_Mapping_File_Names /= null then
3954 for Project in The_Mapping_File_Names'Range (1) loop
3955 for Index in 1 .. Last_Mapping_File_Names (Project) loop
3957 (Name => Get_Name_String
3958 (The_Mapping_File_Names (Project, Index)),
3959 Success => Success);
3964 end Delete_Mapping_Files;
3966 ------------------------------
3967 -- Delete_Temp_Config_Files --
3968 ------------------------------
3970 procedure Delete_Temp_Config_Files is
3972 pragma Warnings (Off, Success);
3975 if (not Debug.Debug_Flag_N) and Main_Project /= No_Project then
3976 for Project in Project_Table.First ..
3977 Project_Table.Last (Project_Tree.Projects)
3980 Project_Tree.Projects.Table (Project).Config_File_Temp
3982 if Verbose_Mode then
3983 Write_Str ("Deleting temp configuration file """);
3984 Write_Str (Get_Name_String
3985 (Project_Tree.Projects.Table
3986 (Project).Config_File_Name));
3991 (Name => Get_Name_String
3992 (Project_Tree.Projects.Table
3993 (Project).Config_File_Name),
3994 Success => Success);
3996 -- Make sure that we don't have a config file for this
3997 -- project, in case when there are several mains.
3998 -- In this case, we will recreate another config file:
3999 -- we cannot reuse the one that we just deleted!
4001 Project_Tree.Projects.Table (Project).
4002 Config_Checked := False;
4003 Project_Tree.Projects.Table (Project).
4004 Config_File_Name := No_Path;
4005 Project_Tree.Projects.Table (Project).
4006 Config_File_Temp := False;
4010 end Delete_Temp_Config_Files;
4016 procedure Display (Program : String; Args : Argument_List) is
4018 pragma Assert (Args'First = 1);
4020 if Display_Executed_Programs then
4021 Write_Str (Program);
4023 for J in Args'Range loop
4025 -- Never display -gnatez
4027 if Args (J).all /= "-gnatez" then
4029 -- Do not display the mapping file argument automatically
4030 -- created when using a project file.
4032 if Main_Project = No_Project
4033 or else Debug.Debug_Flag_N
4034 or else Args (J)'Length < 8
4036 Args (J) (Args (J)'First .. Args (J)'First + 6) /= "-gnatem"
4038 -- When -dn is not specified, do not display the config
4039 -- pragmas switch (-gnatec) for the temporary file created
4040 -- by the project manager (always the first -gnatec switch).
4041 -- Reset Temporary_Config_File to False so that the eventual
4042 -- other -gnatec switches will be displayed.
4044 if (not Debug.Debug_Flag_N)
4045 and then Temporary_Config_File
4046 and then Args (J)'Length > 7
4047 and then Args (J) (Args (J)'First .. Args (J)'First + 6)
4050 Temporary_Config_File := False;
4052 -- Do not display the -F=mapping_file switch for
4053 -- gnatbind, if -dn is not specified.
4055 elsif Debug.Debug_Flag_N
4056 or else Args (J)'Length < 4
4058 Args (J) (Args (J)'First .. Args (J)'First + 2) /= "-F="
4061 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 There_Are_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 Data : Project_Data;
4232 Real_Path : String_Access;
4241 Main : constant String := Mains.Next_Main;
4242 -- The name specified on the command line may include
4243 -- directory information.
4245 File_Name : constant String := Base_Name (Main);
4246 -- The simple file name of the current main main
4249 exit when Main = "";
4251 -- Get the project of the current main
4253 Proj := Prj.Env.Project_Of
4254 (File_Name, Main_Project, Project_Tree);
4256 -- Fail if the current main is not a source of a
4259 if Proj = No_Project then
4262 """ is not a source of any project");
4265 -- If there is directory information, check that
4266 -- the source exists and, if it does, that the path
4267 -- is the actual path of a source of a project.
4269 if Main /= File_Name then
4271 Project_Tree.Projects.Table (Main_Project);
4276 Body_Suffix_Of (Project_Tree, "ada", Data.Naming),
4278 if Real_Path = null then
4282 Spec_Suffix_Of (Project_Tree, "ada", Data.Naming),
4286 if Real_Path = null then
4288 Locate_Regular_File (Main, "");
4291 -- Fail if the file cannot be found
4293 if Real_Path = null then
4295 ("file """ & Main & """ does not exist");
4299 Project_Path : constant String :=
4300 Prj.Env.File_Name_Of_Library_Unit_Body
4302 Project => Main_Project,
4303 In_Tree => Project_Tree,
4304 Main_Project_Only => False,
4306 Normed_Path : constant String :=
4309 Case_Sensitive => False);
4310 Proj_Path : constant String :=
4313 Case_Sensitive => False);
4318 -- Fail if it is not the correct path
4320 if Normed_Path /= Proj_Path then
4321 if Verbose_Mode then
4323 Write_Str (Normed_Path);
4325 Write_Line (Proj_Path);
4330 """ is not a source of any project");
4335 if not Unique_Compile then
4337 -- Record the project, if it is the first main
4339 if Real_Main_Project = No_Project then
4340 Real_Main_Project := Proj;
4342 elsif Proj /= Real_Main_Project then
4344 -- Fail, as the current main is not a source
4345 -- of the same project as the first main.
4349 """ is not a source of project " &
4351 (Project_Tree.Projects.Table
4352 (Real_Main_Project).Name));
4357 -- If -u and -U are not used, we may have mains that
4358 -- are sources of a project that is not the one
4359 -- specified with switch -P.
4361 if not Unique_Compile then
4362 Main_Project := Real_Main_Project;
4368 --------------------------------
4369 -- Create_Binder_Mapping_File --
4370 --------------------------------
4372 procedure Create_Binder_Mapping_File
4373 (Args : in out Argument_List; Last_Arg : in out Natural)
4375 Mapping_FD : File_Descriptor := Invalid_FD;
4376 -- A File Descriptor for an eventual mapping file
4378 ALI_Unit : Unit_Name_Type := No_Unit_Name;
4379 -- The unit name of an ALI file
4381 ALI_Name : File_Name_Type := No_File;
4382 -- The file name of the ALI file
4384 ALI_Project : Project_Id := No_Project;
4385 -- The project of the ALI file
4388 OK : Boolean := True;
4391 -- For call to Close
4394 Tempdir.Create_Temp_File (Mapping_FD, Mapping_Path);
4395 Record_Temp_File (Mapping_Path);
4397 if Mapping_FD /= Invalid_FD then
4399 -- Traverse all units
4401 for J in Unit_Table.First ..
4402 Unit_Table.Last (Project_Tree.Units)
4405 Unit : constant Unit_Data := Project_Tree.Units.Table (J);
4407 if Unit.Name /= No_Name then
4409 -- If there is a body, put it in the mapping
4411 if Unit.File_Names (Body_Part).Name /= No_File
4412 and then Unit.File_Names (Body_Part).Project /=
4415 Get_Name_String (Unit.Name);
4416 Name_Buffer (Name_Len + 1 .. Name_Len + 2) := "%b";
4417 Name_Len := Name_Len + 2;
4418 ALI_Unit := Name_Find;
4421 (Unit.File_Names (Body_Part).Display_Name);
4423 Unit.File_Names (Body_Part).Project;
4425 -- Otherwise, if there is a spec, put it
4428 elsif Unit.File_Names (Specification).Name /= No_File
4429 and then Unit.File_Names (Specification).Project /=
4432 Get_Name_String (Unit.Name);
4433 Name_Buffer (Name_Len + 1 .. Name_Len + 2) := "%s";
4434 Name_Len := Name_Len + 2;
4435 ALI_Unit := Name_Find;
4438 (Unit.File_Names (Specification).Display_Name);
4440 Unit.File_Names (Specification).Project;
4443 ALI_Name := No_File;
4446 -- If we have something to put in the mapping
4447 -- then we do it now. However, if the project
4448 -- is extended, we don't put anything in the
4449 -- mapping file, because we do not know where
4450 -- the ALI file is: it might be in the ext-
4451 -- ended project obj dir as well as in the
4452 -- extending project obj dir.
4454 if ALI_Name /= No_File
4456 Project_Tree.Projects.Table
4457 (ALI_Project).Extended_By = No_Project
4459 Project_Tree.Projects.Table
4460 (ALI_Project).Extends = No_Project
4462 -- First check if the ALI file exists. If it does not,
4463 -- do not put the unit in the mapping file.
4466 ALI : constant String :=
4467 Get_Name_String (ALI_Name);
4468 PD : Project_Data renames
4469 Project_Tree.Projects.Table (ALI_Project);
4472 -- For library projects, use the library directory,
4473 -- for other projects, use the object directory.
4476 Get_Name_String (PD.Library_Dir);
4478 Get_Name_String (PD.Object_Directory);
4481 if Name_Buffer (Name_Len) /=
4484 Name_Len := Name_Len + 1;
4485 Name_Buffer (Name_Len) :=
4486 Directory_Separator;
4491 Name_Len + ALI'Length) := ALI;
4493 Name_Len + ALI'Length + 1;
4494 Name_Buffer (Name_Len) := ASCII.LF;
4497 ALI_Path_Name : constant String :=
4498 Name_Buffer (1 .. Name_Len);
4502 (ALI_Path_Name (1 .. ALI_Path_Name'Last - 1))
4505 -- First line is the unit name
4507 Get_Name_String (ALI_Unit);
4508 Name_Len := Name_Len + 1;
4509 Name_Buffer (Name_Len) := ASCII.LF;
4513 Name_Buffer (1)'Address,
4515 OK := Bytes = Name_Len;
4519 -- Second line it the ALI file name
4521 Get_Name_String (ALI_Name);
4522 Name_Len := Name_Len + 1;
4523 Name_Buffer (Name_Len) := ASCII.LF;
4527 Name_Buffer (1)'Address,
4529 OK := Bytes = Name_Len;
4533 -- Third line it the ALI path name
4538 ALI_Path_Name (1)'Address,
4539 ALI_Path_Name'Length);
4540 OK := Bytes = ALI_Path_Name'Length;
4542 -- If OK is False, it means we were unable
4543 -- to write a line. No point in continuing
4544 -- with the other units.
4555 Close (Mapping_FD, Status);
4557 OK := OK and Status;
4559 -- If the creation of the mapping file was successful,
4560 -- we add the switch to the arguments of gnatbind.
4563 Last_Arg := Last_Arg + 1;
4565 new String'("-F=" & Get_Name_String (Mapping_Path));
4568 end Create_Binder_Mapping_File;
4570 -- Start of processing for Gnatmake
4572 -- This body is very long, should be broken down ???
4575 Gnatmake_Called := True;
4577 Install_Int_Handler (Sigint_Intercepted'Access);
4579 Do_Compile_Step := True;
4580 Do_Bind_Step := True;
4581 Do_Link_Step := True;
4587 Bind_Shared := No_Shared_Switch'Access;
4588 Link_With_Shared_Libgcc := No_Shared_Libgcc_Switch'Access;
4590 Failed_Links.Set_Last (0);
4591 Successful_Links.Set_Last (0);
4593 -- Special case when switch -B was specified
4595 if Build_Bind_And_Link_Full_Project then
4597 -- When switch -B is specified, there must be a project file
4599 if Main_Project = No_Project then
4600 Make_Failed ("-B cannot be used without a project file");
4602 -- No main program may be specified on the command line
4604 elsif Osint.Number_Of_Files /= 0 then
4605 Make_Failed ("-B cannot be used with a main specified on " &
4606 "the command line");
4608 -- And the project file cannot be a library project file
4610 elsif Project_Tree.Projects.Table (Main_Project).Library then
4611 Make_Failed ("-B cannot be used for a library project file");
4614 No_Main_Subprogram := True;
4615 Insert_Project_Sources
4616 (The_Project => Main_Project,
4617 All_Projects => Unique_Compile_All_Projects,
4620 -- If there are no sources to compile, we fail
4622 if Osint.Number_Of_Files = 0 then
4623 Make_Failed ("no sources to compile");
4626 -- Specify -n for gnatbind and add the ALI files of all the
4627 -- sources, except the one which is a fake main subprogram:
4628 -- this is the one for the binder generated file and it will be
4629 -- transmitted to gnatlink. These sources are those that are
4632 Add_Switch ("-n", Binder, And_Save => True);
4634 for J in Q.First .. Q.Last - 1 loop
4637 (Lib_File_Name (Q.Table (J).File)),
4638 Binder, And_Save => True);
4642 elsif Main_Index /= 0 and then Osint.Number_Of_Files > 1 then
4643 Make_Failed ("cannot specify several mains with a multi-unit index");
4645 elsif Main_Project /= No_Project then
4647 -- If the main project file is a library project file, main(s)
4648 -- cannot be specified on the command line.
4650 if Osint.Number_Of_Files /= 0 then
4651 if Project_Tree.Projects.Table (Main_Project).Library
4652 and then not Unique_Compile
4653 and then ((not Make_Steps) or else Bind_Only or else Link_Only)
4655 Make_Failed ("cannot specify a main program " &
4656 "on the command line for a library project file");
4659 -- Check that each main on the command line is a source of a
4660 -- project file and, if there are several mains, each of them
4661 -- is a source of the same project file.
4666 -- If no mains have been specified on the command line,
4667 -- and we are using a project file, we either find the main(s)
4668 -- in the attribute Main of the main project, or we put all
4669 -- the sources of the project file as mains.
4672 if Main_Index /= 0 then
4673 Make_Failed ("cannot specify a multi-unit index but no main " &
4674 "on the command line");
4678 Value : String_List_Id :=
4679 Project_Tree.Projects.Table (Main_Project).Mains;
4682 -- The attribute Main is an empty list or not specified,
4683 -- or else gnatmake was invoked with the switch "-u".
4685 if Value = Prj.Nil_String or else Unique_Compile then
4687 if (not Make_Steps) or else Compile_Only
4688 or else not Project_Tree.Projects.Table
4689 (Main_Project).Library
4691 -- First make sure that the binder and the linker
4692 -- will not be invoked.
4694 Do_Bind_Step := False;
4695 Do_Link_Step := False;
4697 -- Put all the sources in the queue
4699 No_Main_Subprogram := True;
4700 Insert_Project_Sources
4701 (The_Project => Main_Project,
4702 All_Projects => Unique_Compile_All_Projects,
4705 -- If no sources to compile, then there is nothing to do
4707 if Osint.Number_Of_Files = 0 then
4708 if not Debug.Debug_Flag_N then
4709 Delete_Mapping_Files;
4710 Prj.Env.Delete_All_Path_Files (Project_Tree);
4713 if not Quiet_Output then
4714 Osint.Write_Program_Name;
4715 Write_Line (": no sources to compile");
4718 Exit_Program (E_Success);
4723 -- The attribute Main is not an empty list.
4724 -- Put all the main subprograms in the list as if there
4725 -- were specified on the command line. However, if attribute
4726 -- Languages includes a language other than Ada, only
4727 -- include the Ada mains; if there is no Ada main, compile
4728 -- all the sources of the project.
4731 Data : constant Project_Data :=
4732 Project_Tree.Projects.Table (Main_Project);
4734 Languages : constant Variable_Value :=
4737 Data.Decl.Attributes,
4740 Current : String_List_Id;
4741 Element : String_Element;
4743 Foreign_Language : Boolean := False;
4744 At_Least_One_Main : Boolean := False;
4747 -- First, determine if there is a foreign language in
4748 -- attribute Languages.
4750 if not Languages.Default then
4751 Current := Languages.Values;
4754 while Current /= Nil_String loop
4755 Element := Project_Tree.String_Elements.
4757 Get_Name_String (Element.Value);
4758 To_Lower (Name_Buffer (1 .. Name_Len));
4760 if Name_Buffer (1 .. Name_Len) /= "ada" then
4761 Foreign_Language := True;
4762 exit Look_For_Foreign;
4765 Current := Element.Next;
4766 end loop Look_For_Foreign;
4769 -- Then, find all mains, or if there is a foreign
4770 -- language, all the Ada mains.
4772 while Value /= Prj.Nil_String loop
4774 (Project_Tree.String_Elements.Table
4777 -- To know if a main is an Ada main, get its project.
4778 -- It should be the project specified on the command
4781 if (not Foreign_Language) or else
4783 (Name_Buffer (1 .. Name_Len),
4788 At_Least_One_Main := True;
4791 (Project_Tree.String_Elements.Table
4794 Project_Tree.String_Elements.Table
4798 Value := Project_Tree.String_Elements.Table
4802 -- If we did not get any main, it means that all mains
4803 -- in attribute Mains are in a foreign language and -B
4804 -- was not specified to gnatmake; so, we fail.
4806 if not At_Least_One_Main then
4808 ("no Ada mains; use -B to build foreign main");
4817 if Verbose_Mode then
4819 Display_Version ("GNATMAKE ", "1995");
4822 if Main_Project /= No_Project
4823 and then Project_Tree.Projects.Table
4824 (Main_Project).Externally_Built
4827 ("nothing to do for a main project that is externally built");
4830 if Osint.Number_Of_Files = 0 then
4831 if Main_Project /= No_Project
4832 and then Project_Tree.Projects.Table (Main_Project).Library
4835 and then not Project_Tree.Projects.Table
4836 (Main_Project).Standalone_Library
4838 Make_Failed ("only stand-alone libraries may be bound");
4841 -- Add the default search directories to be able to find libgnat
4843 Osint.Add_Default_Search_Dirs;
4845 -- Get the target parameters, so that the correct binder generated
4846 -- files are generated if OpenVMS is the target.
4849 Targparm.Get_Target_Parameters;
4852 when Unrecoverable_Error =>
4853 Make_Failed ("*** make failed.");
4856 -- And bind and or link the library
4858 MLib.Prj.Build_Library
4859 (For_Project => Main_Project,
4860 In_Tree => Project_Tree,
4861 Gnatbind => Gnatbind.all,
4862 Gnatbind_Path => Gnatbind_Path,
4864 Gcc_Path => Gcc_Path,
4867 Exit_Program (E_Success);
4870 -- Output usage information if no files to compile
4873 Exit_Program (E_Fatal);
4877 -- If -M was specified, behave as if -n was specified
4879 if List_Dependencies then
4880 Do_Not_Execute := True;
4883 -- Note that Osint.M.Next_Main_Source will always return the (possibly
4884 -- abbreviated file) without any directory information.
4886 Main_Source_File := Next_Main_Source;
4888 if Current_File_Index /= No_Index then
4889 Main_Index := Current_File_Index;
4892 Add_Switch ("-I-", Compiler, And_Save => True);
4894 if Main_Project = No_Project then
4895 if Look_In_Primary_Dir then
4899 Normalize_Directory_Name
4900 (Get_Primary_Src_Search_Directory.all).all,
4901 Compiler, Append_Switch => False,
4907 -- If we use a project file, we have already checked that a main
4908 -- specified on the command line with directory information has the
4909 -- path name corresponding to a correct source in the project tree.
4910 -- So, we don't need the directory information to be taken into
4911 -- account by Find_File, and in fact it may lead to take the wrong
4912 -- sources for other compilation units, when there are extending
4915 Look_In_Primary_Dir := False;
4916 Add_Switch ("-I-", Binder, And_Save => True);
4919 -- If the user wants a program without a main subprogram, add the
4920 -- appropriate switch to the binder.
4922 if No_Main_Subprogram then
4923 Add_Switch ("-z", Binder, And_Save => True);
4926 if Main_Project /= No_Project then
4928 if Project_Tree.Projects.Table
4929 (Main_Project).Object_Directory /= No_Path
4931 -- Change current directory to object directory of main project
4933 Project_Of_Current_Object_Directory := No_Project;
4934 Change_To_Object_Directory (Main_Project);
4937 -- Source file lookups should be cached for efficiency.
4938 -- Source files are not supposed to change.
4940 Osint.Source_File_Data (Cache => True);
4942 -- Find the file name of the (first) main unit
4945 Main_Source_File_Name : constant String :=
4946 Get_Name_String (Main_Source_File);
4947 Main_Unit_File_Name : constant String :=
4948 Prj.Env.File_Name_Of_Library_Unit_Body
4949 (Name => Main_Source_File_Name,
4950 Project => Main_Project,
4951 In_Tree => Project_Tree,
4952 Main_Project_Only =>
4953 not Unique_Compile);
4955 The_Packages : constant Package_Id :=
4956 Project_Tree.Projects.Table
4957 (Main_Project).Decl.Packages;
4959 Builder_Package : constant Prj.Package_Id :=
4961 (Name => Name_Builder,
4962 In_Packages => The_Packages,
4963 In_Tree => Project_Tree);
4965 Binder_Package : constant Prj.Package_Id :=
4967 (Name => Name_Binder,
4968 In_Packages => The_Packages,
4969 In_Tree => Project_Tree);
4971 Linker_Package : constant Prj.Package_Id :=
4973 (Name => Name_Linker,
4974 In_Packages => The_Packages,
4975 In_Tree => Project_Tree);
4978 -- We fail if we cannot find the main source file
4980 if Main_Unit_File_Name = "" then
4981 Make_Failed ('"' & Main_Source_File_Name,
4982 """ is not a unit of project ",
4983 Project_File_Name.all & ".");
4985 -- Remove any directory information from the main
4986 -- source file name.
4989 Pos : Natural := Main_Unit_File_Name'Last;
4993 exit when Pos < Main_Unit_File_Name'First or else
4994 Main_Unit_File_Name (Pos) = Directory_Separator;
4998 Name_Len := Main_Unit_File_Name'Last - Pos;
5000 Name_Buffer (1 .. Name_Len) :=
5002 (Pos + 1 .. Main_Unit_File_Name'Last);
5004 Main_Source_File := Name_Find;
5006 -- We only output the main source file if there is only one
5008 if Verbose_Mode and then Osint.Number_Of_Files = 1 then
5009 Write_Str ("Main source file: """);
5010 Write_Str (Main_Unit_File_Name
5011 (Pos + 1 .. Main_Unit_File_Name'Last));
5017 -- If there is a package Builder in the main project file, add
5018 -- the switches from it.
5020 if Builder_Package /= No_Package then
5022 -- If there is only one main, we attempt to get the gnatmake
5023 -- switches for this main (if any). If there are no specific
5024 -- switch for this particular main, get the general gnatmake
5025 -- switches (if any).
5027 if Osint.Number_Of_Files = 1 then
5028 if Verbose_Mode then
5029 Write_Str ("Adding gnatmake switches for """);
5030 Write_Str (Main_Unit_File_Name);
5035 (File_Name => Main_Unit_File_Name,
5036 Index => Main_Index,
5037 The_Package => Builder_Package,
5041 -- If there are several mains, we always get the general
5042 -- gnatmake switches (if any).
5044 -- Warn the user, if necessary, so that he is not surprized
5045 -- that specific switches are not taken into account.
5048 Defaults : constant Variable_Value :=
5052 Attribute_Or_Array_Name => Name_Default_Switches,
5053 In_Package => Builder_Package,
5054 In_Tree => Project_Tree);
5056 Switches : constant Array_Element_Id :=
5058 (Name => Name_Switches,
5060 Project_Tree.Packages.Table
5061 (Builder_Package).Decl.Arrays,
5062 In_Tree => Project_Tree);
5065 if Defaults /= Nil_Variable_Value then
5066 if (not Quiet_Output)
5067 and then Switches /= No_Array_Element
5070 ("Warning: using Builder'Default_Switches" &
5071 "(""Ada""), as there are several mains");
5074 -- As there is never a source with name " ", we are
5075 -- guaranteed to always get the general switches.
5080 The_Package => Builder_Package,
5083 elsif (not Quiet_Output)
5084 and then Switches /= No_Array_Element
5087 ("Warning: using no switches from package Builder," &
5088 " as there are several mains");
5094 Osint.Add_Default_Search_Dirs;
5096 -- Record the current last switch index for table Binder_Switches
5097 -- and Linker_Switches, so that these tables may be reset before
5098 -- for each main, before adding swiches from the project file
5099 -- and from the command line.
5101 Last_Binder_Switch := Binder_Switches.Last;
5102 Last_Linker_Switch := Linker_Switches.Last;
5106 -- Add binder switches from the project file for the first main
5108 if Do_Bind_Step and Binder_Package /= No_Package then
5109 if Verbose_Mode then
5110 Write_Str ("Adding binder switches for """);
5111 Write_Str (Main_Unit_File_Name);
5116 (File_Name => Main_Unit_File_Name,
5117 Index => Main_Index,
5118 The_Package => Binder_Package,
5122 -- Add linker switches from the project file for the first main
5124 if Do_Link_Step and Linker_Package /= No_Package then
5125 if Verbose_Mode then
5126 Write_Str ("Adding linker switches for""");
5127 Write_Str (Main_Unit_File_Name);
5132 (File_Name => Main_Unit_File_Name,
5133 Index => Main_Index,
5134 The_Package => Linker_Package,
5140 -- Get the target parameters, which are only needed for a couple of
5141 -- cases in gnatmake. Protect against an exception, such as the case
5142 -- of system.ads missing from the library, and fail gracefully.
5145 Targparm.Get_Target_Parameters;
5148 when Unrecoverable_Error =>
5149 Make_Failed ("*** make failed.");
5152 -- Special processing for VM targets
5154 if Targparm.VM_Target /= No_VM then
5156 -- Do not check for an object file (".o") when compiling to VM
5157 -- machine since ".class" files are generated instead.
5159 Check_Object_Consistency := False;
5161 -- Set proper processing commands
5163 case Targparm.VM_Target is
5164 when Targparm.JVM_Target =>
5165 Gcc := new String'("jgnat");
5166 Gnatbind := new String'("jgnatbind");
5167 Gnatlink := new String'("jgnatlink");
5169 when Targparm.CLI_Target =>
5170 Gcc := new String'("dotnet-gnatcompile");
5172 when Targparm.No_VM =>
5173 raise Program_Error;
5177 Display_Commands (not Quiet_Output);
5181 if Main_Project /= No_Project then
5183 -- For all library project, if the library file does not exist
5184 -- put all the project sources in the queue, and flag the project
5185 -- so that the library is generated.
5187 if not Unique_Compile
5188 and then MLib.Tgt.Support_For_Libraries /= Prj.None
5190 for Proj in Project_Table.First ..
5191 Project_Table.Last (Project_Tree.Projects)
5193 if Project_Tree.Projects.Table (Proj).Library then
5194 Project_Tree.Projects.Table
5195 (Proj).Need_To_Build_Lib :=
5196 (not MLib.Tgt.Library_Exists_For (Proj, Project_Tree))
5197 and then (not Project_Tree.Projects.Table
5198 (Proj).Externally_Built);
5200 if Project_Tree.Projects.Table (Proj).Need_To_Build_Lib then
5202 -- If there is no object directory, then it will be
5203 -- impossible to build the library. So fail immediately.
5205 if Project_Tree.Projects.Table (Proj).Object_Directory =
5209 ("no object files to build library for project """,
5211 (Project_Tree.Projects.Table (Proj).Name),
5213 Project_Tree.Projects.Table
5214 (Proj).Need_To_Build_Lib := False;
5217 if Verbose_Mode then
5219 ("Library file does not exist for project """);
5222 (Project_Tree.Projects.Table
5227 Insert_Project_Sources
5228 (The_Project => Proj,
5229 All_Projects => False,
5237 -- If a relative path output file has been specified, we add
5238 -- the exec directory.
5240 for J in reverse 1 .. Saved_Linker_Switches.Last - 1 loop
5241 if Saved_Linker_Switches.Table (J).all = Output_Flag.all then
5243 Exec_File_Name : constant String :=
5244 Saved_Linker_Switches.Table (J + 1).all;
5247 if not Is_Absolute_Path (Exec_File_Name) then
5249 (Project_Tree.Projects.Table
5250 (Main_Project).Exec_Directory);
5252 if Name_Buffer (Name_Len) /= Directory_Separator then
5253 Name_Len := Name_Len + 1;
5254 Name_Buffer (Name_Len) := Directory_Separator;
5257 Name_Buffer (Name_Len + 1 ..
5258 Name_Len + Exec_File_Name'Length) :=
5260 Name_Len := Name_Len + Exec_File_Name'Length;
5261 Saved_Linker_Switches.Table (J + 1) :=
5262 new String'(Name_Buffer (1 .. Name_Len));
5270 -- If we are using a project file, for relative paths we add the
5271 -- current working directory for any relative path on the command
5272 -- line and the project directory, for any relative path in the
5276 Dir_Path : constant String_Access :=
5277 new String'(Get_Name_String
5278 (Project_Tree.Projects.Table
5279 (Main_Project).Directory));
5281 for J in 1 .. Binder_Switches.Last loop
5282 Test_If_Relative_Path
5283 (Binder_Switches.Table (J),
5284 Parent => Dir_Path, Including_L_Switch => False);
5287 for J in 1 .. Saved_Binder_Switches.Last loop
5288 Test_If_Relative_Path
5289 (Saved_Binder_Switches.Table (J),
5290 Parent => Current_Work_Dir, Including_L_Switch => False);
5293 for J in 1 .. Linker_Switches.Last loop
5294 Test_If_Relative_Path
5295 (Linker_Switches.Table (J), Parent => Dir_Path);
5298 for J in 1 .. Saved_Linker_Switches.Last loop
5299 Test_If_Relative_Path
5300 (Saved_Linker_Switches.Table (J), Parent => Current_Work_Dir);
5303 for J in 1 .. Gcc_Switches.Last loop
5304 Test_If_Relative_Path
5305 (Gcc_Switches.Table (J),
5307 Including_Non_Switch => False);
5310 for J in 1 .. Saved_Gcc_Switches.Last loop
5311 Test_If_Relative_Path
5312 (Saved_Gcc_Switches.Table (J),
5313 Parent => Current_Work_Dir,
5314 Including_Non_Switch => False);
5319 -- We now put in the Binder_Switches and Linker_Switches tables, the
5320 -- binder and linker switches of the command line that have been put in
5321 -- the Saved_ tables. If a project file was used, then the command line
5322 -- switches will follow the project file switches.
5324 for J in 1 .. Saved_Binder_Switches.Last loop
5326 (Saved_Binder_Switches.Table (J),
5331 for J in 1 .. Saved_Linker_Switches.Last loop
5333 (Saved_Linker_Switches.Table (J),
5338 -- If no project file is used, we just put the gcc switches
5339 -- from the command line in the Gcc_Switches table.
5341 if Main_Project = No_Project then
5342 for J in 1 .. Saved_Gcc_Switches.Last loop
5344 (Saved_Gcc_Switches.Table (J),
5350 -- And we put the command line gcc switches in the variable
5351 -- The_Saved_Gcc_Switches. They are going to be used later
5352 -- in procedure Compile_Sources.
5354 The_Saved_Gcc_Switches :=
5355 new Argument_List (1 .. Saved_Gcc_Switches.Last + 1);
5357 for J in 1 .. Saved_Gcc_Switches.Last loop
5358 The_Saved_Gcc_Switches (J) := Saved_Gcc_Switches.Table (J);
5361 -- We never use gnat.adc when a project file is used
5363 The_Saved_Gcc_Switches (The_Saved_Gcc_Switches'Last) :=
5368 -- If there was a --GCC, --GNATBIND or --GNATLINK switch on
5369 -- the command line, then we have to use it, even if there was
5370 -- another switch in the project file.
5372 if Saved_Gcc /= null then
5376 if Saved_Gnatbind /= null then
5377 Gnatbind := Saved_Gnatbind;
5380 if Saved_Gnatlink /= null then
5381 Gnatlink := Saved_Gnatlink;
5384 Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
5385 Gnatbind_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
5386 Gnatlink_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
5388 -- If we have specified -j switch both from the project file
5389 -- and on the command line, the one from the command line takes
5392 if Saved_Maximum_Processes = 0 then
5393 Saved_Maximum_Processes := Maximum_Processes;
5396 -- Allocate as many temporary mapping file names as the maximum
5397 -- number of compilation processed, for each possible project.
5399 The_Mapping_File_Names :=
5401 (No_Project .. Project_Table.Last (Project_Tree.Projects),
5402 1 .. Saved_Maximum_Processes);
5403 Last_Mapping_File_Names :=
5405 (No_Project .. Project_Table.Last (Project_Tree.Projects)
5408 The_Free_Mapping_File_Indices :=
5409 new Free_File_Indices
5410 (No_Project .. Project_Table.Last (Project_Tree.Projects),
5411 1 .. Saved_Maximum_Processes);
5412 Last_Free_Indices :=
5413 new Indices'(No_Project .. Project_Table.Last
5414 (Project_Tree.Projects) => 0);
5416 Bad_Compilation.Init;
5418 -- If project files are used, create the mapping of all the sources,
5419 -- so that the correct paths will be found. Otherwise, if there is
5420 -- a file which is not a source with the same name in a source directory
5421 -- this file may be incorrectly found.
5423 if Main_Project /= No_Project then
5424 Prj.Env.Create_Mapping (Project_Tree);
5427 Current_Main_Index := Main_Index;
5429 -- Here is where the make process is started
5431 -- We do the same process for each main
5433 Multiple_Main_Loop : for N_File in 1 .. Osint.Number_Of_Files loop
5435 -- First, find the executable name and path
5437 Executable := No_File;
5438 Executable_Obsolete := False;
5439 Non_Std_Executable :=
5440 Targparm.Executable_Extension_On_Target /= No_Name;
5442 -- Look inside the linker switches to see if the name
5443 -- of the final executable program was specified.
5446 J in reverse Linker_Switches.First .. Linker_Switches.Last
5448 if Linker_Switches.Table (J).all = Output_Flag.all then
5449 pragma Assert (J < Linker_Switches.Last);
5451 -- We cannot specify a single executable for several
5452 -- main subprograms!
5454 if Osint.Number_Of_Files > 1 then
5456 ("cannot specify a single executable " &
5457 "for several mains");
5460 Name_Len := Linker_Switches.Table (J + 1)'Length;
5461 Name_Buffer (1 .. Name_Len) :=
5462 Linker_Switches.Table (J + 1).all;
5463 Executable := Name_Enter;
5465 Verbose_Msg (Executable, "final executable");
5469 -- If the name of the final executable program was not
5470 -- specified then construct it from the main input file.
5472 if Executable = No_File then
5473 if Main_Project = No_Project then
5475 Executable_Name (Strip_Suffix (Main_Source_File));
5478 -- If we are using a project file, we attempt to
5479 -- remove the body (or spec) termination of the main
5480 -- subprogram. We find it the the naming scheme of the
5481 -- project file. This will avoid to generate an
5482 -- executable "main.2" for a main subprogram
5483 -- "main.2.ada", when the body termination is ".2.ada".
5486 Prj.Util.Executable_Of
5487 (Main_Project, Project_Tree, Main_Source_File, Main_Index);
5491 if Main_Project /= No_Project then
5493 Exec_File_Name : constant String :=
5494 Get_Name_String (Executable);
5497 if not Is_Absolute_Path (Exec_File_Name) then
5499 Get_Name_String (Project_Tree.Projects.Table
5500 (Main_Project).Display_Exec_Dir);
5503 Name_Buffer (Name_Len) /= Directory_Separator
5505 Name_Len := Name_Len + 1;
5506 Name_Buffer (Name_Len) := Directory_Separator;
5509 Name_Buffer (Name_Len + 1 ..
5510 Name_Len + Exec_File_Name'Length) :=
5513 Name_Len := Name_Len + Exec_File_Name'Length;
5514 Executable := Name_Find;
5517 Non_Std_Executable := True;
5521 if Do_Compile_Step then
5522 Recursive_Compilation_Step : declare
5523 Args : Argument_List (1 .. Gcc_Switches.Last);
5525 First_Compiled_File : File_Name_Type;
5526 Youngest_Obj_File : File_Name_Type;
5527 Youngest_Obj_Stamp : Time_Stamp_Type;
5529 Executable_Stamp : Time_Stamp_Type;
5530 -- Executable is the final executable program
5532 Library_Rebuilt : Boolean := False;
5535 for J in 1 .. Gcc_Switches.Last loop
5536 Args (J) := Gcc_Switches.Table (J);
5539 -- Now we invoke Compile_Sources for the current main
5542 (Main_Source => Main_Source_File,
5544 First_Compiled_File => First_Compiled_File,
5545 Most_Recent_Obj_File => Youngest_Obj_File,
5546 Most_Recent_Obj_Stamp => Youngest_Obj_Stamp,
5547 Main_Unit => Is_Main_Unit,
5548 Main_Index => Current_Main_Index,
5549 Compilation_Failures => Compilation_Failures,
5550 Check_Readonly_Files => Check_Readonly_Files,
5551 Do_Not_Execute => Do_Not_Execute,
5552 Force_Compilations => Force_Compilations,
5553 In_Place_Mode => In_Place_Mode,
5554 Keep_Going => Keep_Going,
5555 Initialize_ALI_Data => True,
5556 Max_Process => Saved_Maximum_Processes);
5558 if Verbose_Mode then
5559 Write_Str ("End of compilation");
5563 -- Make sure the queue will be reinitialized for the next round
5565 First_Q_Initialization := True;
5567 Total_Compilation_Failures :=
5568 Total_Compilation_Failures + Compilation_Failures;
5570 if Total_Compilation_Failures /= 0 then
5574 List_Bad_Compilations;
5575 Report_Compilation_Failed;
5579 -- Regenerate libraries, if any, and if object files
5580 -- have been regenerated.
5582 if Main_Project /= No_Project
5583 and then MLib.Tgt.Support_For_Libraries /= Prj.None
5584 and then (Do_Bind_Step
5585 or Unique_Compile_All_Projects
5586 or not Compile_Only)
5587 and then (Do_Link_Step or N_File = Osint.Number_Of_Files)
5595 procedure Add_To_Library_Projs (Proj : Project_Id);
5596 -- Add project Project to table Library_Projs
5597 -- in decreasing depth order.
5599 --------------------------
5600 -- Add_To_Library_Projs --
5601 --------------------------
5603 procedure Add_To_Library_Projs (Proj : Project_Id) is
5607 Library_Projs.Increment_Last;
5608 Depth := Project_Tree.Projects.Table (Proj).Depth;
5610 -- Put the projects in decreasing depth order,
5611 -- so that if libA depends on libB, libB is first
5614 Current := Library_Projs.Last;
5615 while Current > 1 loop
5616 Prj := Library_Projs.Table (Current - 1);
5617 exit when Project_Tree.Projects.Table
5618 (Prj).Depth >= Depth;
5619 Library_Projs.Table (Current) := Prj;
5620 Current := Current - 1;
5623 Library_Projs.Table (Current) := Proj;
5624 end Add_To_Library_Projs;
5626 -- Start of processing for ??? (should name declare block
5627 -- or probably better, break this out as a nested proc.
5630 -- Put in Library_Projs table all library project
5631 -- file ids when the library need to be rebuilt.
5633 for Proj1 in Project_Table.First ..
5634 Project_Table.Last (Project_Tree.Projects)
5636 if Project_Tree.Projects.Table
5637 (Proj1).Standalone_Library
5639 There_Are_Stand_Alone_Libraries := True;
5642 if Project_Tree.Projects.Table (Proj1).Library then
5643 MLib.Prj.Check_Library (Proj1, Project_Tree);
5646 if Project_Tree.Projects.Table
5647 (Proj1).Need_To_Build_Lib
5649 Add_To_Library_Projs (Proj1);
5653 -- Check if importing libraries should be regenerated
5654 -- because at least an imported library will be
5655 -- regenerated or is more recent.
5657 for Proj1 in Project_Table.First ..
5658 Project_Table.Last (Project_Tree.Projects)
5660 if Project_Tree.Projects.Table (Proj1).Library
5662 Project_Tree.Projects.Table (Proj1).Library_Kind /=
5664 and then not Project_Tree.Projects.Table
5665 (Proj1).Need_To_Build_Lib
5666 and then not Project_Tree.Projects.Table
5667 (Proj1).Externally_Built
5670 List : Project_List;
5671 Element : Project_Element;
5673 Rebuild : Boolean := False;
5675 Lib_Timestamp1 : constant Time_Stamp_Type :=
5676 Project_Tree.Projects.Table
5680 List := Project_Tree.Projects.Table (Proj1).
5681 All_Imported_Projects;
5682 while List /= Empty_Project_List loop
5684 Project_Tree.Project_Lists.Table (List);
5685 Proj2 := Element.Project;
5688 Project_Tree.Projects.Table (Proj2).Library
5690 if Project_Tree.Projects.Table (Proj2).
5694 Project_Tree.Projects.Table
5702 List := Element.Next;
5706 Project_Tree.Projects.Table
5707 (Proj1).Need_To_Build_Lib := True;
5708 Add_To_Library_Projs (Proj1);
5714 -- Reset the flags Need_To_Build_Lib for the next main,
5715 -- to avoid rebuilding libraries uselessly.
5717 for Proj1 in Project_Table.First ..
5718 Project_Table.Last (Project_Tree.Projects)
5720 Project_Tree.Projects.Table
5721 (Proj1).Need_To_Build_Lib := False;
5725 -- Build the libraries, if any need to be built
5727 for J in 1 .. Library_Projs.Last loop
5728 Library_Rebuilt := True;
5730 -- If a library is rebuilt, then executables are obsolete
5732 Executable_Obsolete := True;
5734 MLib.Prj.Build_Library
5735 (For_Project => Library_Projs.Table (J),
5736 In_Tree => Project_Tree,
5737 Gnatbind => Gnatbind.all,
5738 Gnatbind_Path => Gnatbind_Path,
5740 Gcc_Path => Gcc_Path);
5744 if List_Dependencies then
5745 if First_Compiled_File /= No_File then
5747 (First_Compiled_File,
5748 "must be recompiled. Can't generate dependence list.");
5753 elsif First_Compiled_File = No_File
5754 and then not Do_Bind_Step
5755 and then not Quiet_Output
5756 and then not Library_Rebuilt
5757 and then Osint.Number_Of_Files = 1
5759 Inform (Msg => "objects up to date.");
5761 elsif Do_Not_Execute
5762 and then First_Compiled_File /= No_File
5764 Write_Name (First_Compiled_File);
5768 -- Stop after compile step if any of:
5770 -- 1) -n (Do_Not_Execute) specified
5772 -- 2) -M (List_Dependencies) specified (also sets
5773 -- Do_Not_Execute above, so this is probably superfluous).
5775 -- 3) -c (Compile_Only) specified, but not -b (Bind_Only)
5777 -- 4) Made unit cannot be a main unit
5780 or List_Dependencies
5782 or not Is_Main_Unit)
5783 and then not No_Main_Subprogram
5784 and then not Build_Bind_And_Link_Full_Project)
5785 or else Unique_Compile
5787 if Osint.Number_Of_Files = 1 then
5788 exit Multiple_Main_Loop;
5795 -- If the objects were up-to-date check if the executable file
5796 -- is also up-to-date. For now always bind and link on the JVM
5797 -- since there is currently no simple way to check the
5798 -- up-to-date status of objects
5800 if Targparm.VM_Target = No_VM
5801 and then First_Compiled_File = No_File
5803 Executable_Stamp := File_Stamp (Executable);
5805 if not Executable_Obsolete then
5806 Executable_Obsolete :=
5807 Youngest_Obj_Stamp > Executable_Stamp;
5810 if not Executable_Obsolete then
5811 for Index in reverse 1 .. Dependencies.Last loop
5813 (Dependencies.Table (Index).Depends_On)
5815 Enter_Into_Obsoleted
5816 (Dependencies.Table (Index).This);
5820 Executable_Obsolete := Is_In_Obsoleted (Main_Source_File);
5824 if not Executable_Obsolete then
5826 -- If no Ada object files obsolete the executable, check
5827 -- for younger or missing linker files.
5829 Check_Linker_Options
5832 Youngest_Obj_Stamp);
5834 Executable_Obsolete := Youngest_Obj_File /= No_File;
5837 -- Return if the executable is up to date
5838 -- and otherwise motivate the relink/rebind.
5840 if not Executable_Obsolete then
5841 if not Quiet_Output then
5842 Inform (Executable, "up to date.");
5845 if Osint.Number_Of_Files = 1 then
5846 exit Multiple_Main_Loop;
5853 if Executable_Stamp (1) = ' ' then
5854 if not No_Main_Subprogram then
5855 Verbose_Msg (Executable, "missing.", Prefix => " ");
5858 elsif Youngest_Obj_Stamp (1) = ' ' then
5860 (Youngest_Obj_File, "missing.", Prefix => " ");
5862 elsif Youngest_Obj_Stamp > Executable_Stamp then
5865 "(" & String (Youngest_Obj_Stamp) & ") newer than",
5867 "(" & String (Executable_Stamp) & ")");
5871 (Executable, "needs to be rebuilt", Prefix => " ");
5875 end Recursive_Compilation_Step;
5878 -- For binding and linking, we need to be in the object directory of
5879 -- the main project.
5881 if Main_Project /= No_Project then
5882 Change_To_Object_Directory (Main_Project);
5885 -- If we are here, it means that we need to rebuilt the current
5886 -- main. So we set Executable_Obsolete to True to make sure that
5887 -- the subsequent mains will be rebuilt.
5889 Main_ALI_In_Place_Mode_Step : declare
5890 ALI_File : File_Name_Type;
5891 Src_File : File_Name_Type;
5894 Src_File := Strip_Directory (Main_Source_File);
5895 ALI_File := Lib_File_Name (Src_File, Current_Main_Index);
5896 Main_ALI_File := Full_Lib_File_Name (ALI_File);
5898 -- When In_Place_Mode, the library file can be located in the
5899 -- Main_Source_File directory which may not be present in the
5900 -- library path. In this case, use the corresponding library file
5903 if Main_ALI_File = No_File and then In_Place_Mode then
5904 Get_Name_String (Get_Directory (Full_Source_Name (Src_File)));
5905 Get_Name_String_And_Append (ALI_File);
5906 Main_ALI_File := Name_Find;
5907 Main_ALI_File := Full_Lib_File_Name (Main_ALI_File);
5910 if Main_ALI_File = No_File then
5911 Make_Failed ("could not find the main ALI file");
5913 end Main_ALI_In_Place_Mode_Step;
5915 if Do_Bind_Step then
5917 Args : Argument_List
5918 (Binder_Switches.First .. Binder_Switches.Last + 2);
5919 -- The arguments for the invocation of gnatbind
5921 Last_Arg : Natural := Binder_Switches.Last;
5922 -- Index of the last argument in Args
5924 Shared_Libs : Boolean := False;
5925 -- Set to True when there are shared library project files or
5926 -- when gnatbind is invoked with -shared.
5929 -- Check if there are shared libraries, so that gnatbind is
5930 -- called with -shared. Check also if gnatbind is called with
5931 -- -shared, so that gnatlink is called with -shared-libgcc
5932 -- ensuring that the shared version of libgcc will be used.
5934 if Main_Project /= No_Project
5935 and then MLib.Tgt.Support_For_Libraries /= Prj.None
5937 for Proj in Project_Table.First ..
5938 Project_Table.Last (Project_Tree.Projects)
5940 if Project_Tree.Projects.Table (Proj).Library
5941 and then Project_Tree.Projects.Table
5942 (Proj).Library_Kind /= Static
5944 Shared_Libs := True;
5945 Bind_Shared := Shared_Switch'Access;
5951 -- Check now for switch -shared
5953 if not Shared_Libs then
5954 for J in Binder_Switches.First .. Last_Arg loop
5955 if Binder_Switches.Table (J).all = "-shared" then
5956 Shared_Libs := True;
5962 -- If there are shared libraries, invoke gnatlink with
5966 Link_With_Shared_Libgcc := Shared_Libgcc_Switch'Access;
5969 -- Get all the binder switches
5971 for J in Binder_Switches.First .. Last_Arg loop
5972 Args (J) := Binder_Switches.Table (J);
5975 if There_Are_Stand_Alone_Libraries then
5976 Last_Arg := Last_Arg + 1;
5977 Args (Last_Arg) := Force_Elab_Flags_String'Access;
5980 if Main_Project /= No_Project then
5982 -- Put all the source directories in ADA_INCLUDE_PATH,
5983 -- and all the object directories in ADA_OBJECTS_PATH
5985 Prj.Env.Set_Ada_Paths (Main_Project, Project_Tree, False);
5987 -- If switch -C was specified, create a binder mapping file
5989 if Create_Mapping_File then
5990 Create_Binder_Mapping_File (Args, Last_Arg);
5996 Bind (Main_ALI_File,
5997 Bind_Shared.all & Args (Args'First .. Last_Arg));
6002 -- If -dn was not specified, delete the temporary mapping
6003 -- file, if one was created.
6005 if not Debug.Debug_Flag_N
6006 and then Mapping_Path /= No_Path
6008 Delete_File (Get_Name_String (Mapping_Path), Discard);
6011 -- And reraise the exception
6016 -- If -dn was not specified, delete the temporary mapping file,
6017 -- if one was created.
6019 if not Debug.Debug_Flag_N and then Mapping_Path /= No_Path then
6020 Delete_File (Get_Name_String (Mapping_Path), Discard);
6025 if Do_Link_Step then
6027 Linker_Switches_Last : constant Integer := Linker_Switches.Last;
6028 Path_Option : constant String_Access :=
6029 MLib.Linker_Library_Path_Option;
6030 There_Are_Libraries : Boolean := False;
6036 if not Run_Path_Option then
6037 Linker_Switches.Increment_Last;
6038 Linker_Switches.Table (Linker_Switches.Last) :=
6042 if Main_Project /= No_Project then
6043 Library_Paths.Set_Last (0);
6046 if MLib.Tgt.Support_For_Libraries /= Prj.None then
6047 -- Check for library projects
6049 for Proj1 in Project_Table.First ..
6050 Project_Table.Last (Project_Tree.Projects)
6052 if Proj1 /= Main_Project
6054 Project_Tree.Projects.Table (Proj1).Library
6056 -- Add this project to table Library_Projs
6058 There_Are_Libraries := True;
6059 Depth := Project_Tree.Projects.Table (Proj1).Depth;
6060 Library_Projs.Increment_Last;
6061 Current := Library_Projs.Last;
6063 -- Any project with a greater depth should be
6064 -- after this project in the list.
6066 while Current > 1 loop
6067 Proj2 := Library_Projs.Table (Current - 1);
6068 exit when Project_Tree.Projects.Table
6069 (Proj2).Depth <= Depth;
6070 Library_Projs.Table (Current) := Proj2;
6071 Current := Current - 1;
6074 Library_Projs.Table (Current) := Proj1;
6076 -- If it is not a static library and path option
6077 -- is set, add it to the Library_Paths table.
6079 if Project_Tree.Projects.Table
6080 (Proj1).Library_Kind /= Static
6081 and then Path_Option /= null
6083 Library_Paths.Increment_Last;
6084 Library_Paths.Table (Library_Paths.Last) :=
6087 (Project_Tree.Projects.Table
6088 (Proj1).Display_Library_Dir));
6093 for Index in 1 .. Library_Projs.Last loop
6094 -- Add the -L switch
6096 Linker_Switches.Increment_Last;
6097 Linker_Switches.Table (Linker_Switches.Last) :=
6100 (Project_Tree.Projects.Table
6101 (Library_Projs.Table (Index)).
6102 Display_Library_Dir));
6104 -- Add the -l switch
6106 Linker_Switches.Increment_Last;
6107 Linker_Switches.Table (Linker_Switches.Last) :=
6110 (Project_Tree.Projects.Table
6111 (Library_Projs.Table (Index)).
6116 if There_Are_Libraries then
6118 -- If Path_Option is not null, create the switch
6119 -- ("-Wl,-rpath," or equivalent) with all the non static
6120 -- library dirs plus the standard GNAT library dir.
6121 -- We do that only if Run_Path_Option is True
6122 -- (not disabled by -R switch).
6124 if Run_Path_Option and Path_Option /= null then
6126 Option : String_Access;
6127 Length : Natural := Path_Option'Length;
6132 Library_Paths.First .. Library_Paths.Last
6134 -- Add the length of the library dir plus one
6135 -- for the directory separator.
6139 Library_Paths.Table (Index)'Length + 1;
6142 -- Finally, add the length of the standard GNAT
6145 Length := Length + MLib.Utl.Lib_Directory'Length;
6146 Option := new String (1 .. Length);
6147 Option (1 .. Path_Option'Length) := Path_Option.all;
6148 Current := Path_Option'Length;
6150 -- Put each library dir followed by a dir separator
6153 Library_Paths.First .. Library_Paths.Last
6158 Library_Paths.Table (Index)'Length) :=
6159 Library_Paths.Table (Index).all;
6162 Library_Paths.Table (Index)'Length + 1;
6163 Option (Current) := Path_Separator;
6166 -- Finally put the standard GNAT library dir
6170 Current + MLib.Utl.Lib_Directory'Length) :=
6171 MLib.Utl.Lib_Directory;
6173 -- And add the switch to the linker switches
6175 Linker_Switches.Increment_Last;
6176 Linker_Switches.Table (Linker_Switches.Last) :=
6183 -- Put the object directories in ADA_OBJECTS_PATH
6185 Prj.Env.Set_Ada_Paths (Main_Project, Project_Tree, False);
6187 -- Check for attributes Linker'Linker_Options in projects
6188 -- other than the main project
6191 Linker_Options : constant String_List :=
6192 Linker_Options_Switches
6193 (Main_Project, Project_Tree);
6195 for Option in Linker_Options'Range loop
6196 Linker_Switches.Increment_Last;
6197 Linker_Switches.Table (Linker_Switches.Last) :=
6198 Linker_Options (Option);
6204 Args : Argument_List
6205 (Linker_Switches.First .. Linker_Switches.Last + 2);
6207 Last_Arg : Integer := Linker_Switches.First - 1;
6208 Skip : Boolean := False;
6211 -- Get all the linker switches
6213 for J in Linker_Switches.First .. Linker_Switches.Last loop
6217 elsif Non_Std_Executable
6218 and then Linker_Switches.Table (J).all = "-o"
6223 Last_Arg := Last_Arg + 1;
6224 Args (Last_Arg) := Linker_Switches.Table (J);
6228 -- If need be, add the -o switch
6230 if Non_Std_Executable then
6231 Last_Arg := Last_Arg + 1;
6232 Args (Last_Arg) := new String'("-o");
6233 Last_Arg := Last_Arg + 1;
6235 new String'(Get_Name_String (Executable));
6238 -- And invoke the linker
6241 Success : Boolean := False;
6243 Link (Main_ALI_File,
6244 Link_With_Shared_Libgcc.all &
6245 Args (Args'First .. Last_Arg),
6249 Successful_Links.Increment_Last;
6250 Successful_Links.Table (Successful_Links.Last) :=
6253 elsif Osint.Number_Of_Files = 1 or not Keep_Going then
6254 Make_Failed ("*** link failed.");
6258 Write_Line ("*** link failed");
6260 if Commands_To_Stdout then
6261 Set_Standard_Output;
6264 Failed_Links.Increment_Last;
6265 Failed_Links.Table (Failed_Links.Last) :=
6271 Linker_Switches.Set_Last (Linker_Switches_Last);
6275 -- We go to here when we skip the bind and link steps
6279 -- We go to the next main, if we did not process the last one
6281 if N_File < Osint.Number_Of_Files then
6282 Main_Source_File := Next_Main_Source;
6284 if Current_File_Index /= No_Index then
6285 Main_Index := Current_File_Index;
6288 if Main_Project /= No_Project then
6290 -- Find the file name of the main unit
6293 Main_Source_File_Name : constant String :=
6294 Get_Name_String (Main_Source_File);
6296 Main_Unit_File_Name : constant String :=
6298 File_Name_Of_Library_Unit_Body
6299 (Name => Main_Source_File_Name,
6300 Project => Main_Project,
6301 In_Tree => Project_Tree,
6302 Main_Project_Only =>
6303 not Unique_Compile);
6305 The_Packages : constant Package_Id :=
6306 Project_Tree.Projects.Table
6307 (Main_Project).Decl.Packages;
6309 Binder_Package : constant Prj.Package_Id :=
6311 (Name => Name_Binder,
6312 In_Packages => The_Packages,
6313 In_Tree => Project_Tree);
6315 Linker_Package : constant Prj.Package_Id :=
6317 (Name => Name_Linker,
6318 In_Packages => The_Packages,
6319 In_Tree => Project_Tree);
6322 -- We fail if we cannot find the main source file
6323 -- as an immediate source of the main project file.
6325 if Main_Unit_File_Name = "" then
6326 Make_Failed ('"' & Main_Source_File_Name,
6327 """ is not a unit of project ",
6328 Project_File_Name.all & ".");
6331 -- Remove any directory information from the main
6332 -- source file name.
6335 Pos : Natural := Main_Unit_File_Name'Last;
6339 exit when Pos < Main_Unit_File_Name'First
6341 Main_Unit_File_Name (Pos) = Directory_Separator;
6345 Name_Len := Main_Unit_File_Name'Last - Pos;
6347 Name_Buffer (1 .. Name_Len) :=
6349 (Pos + 1 .. Main_Unit_File_Name'Last);
6351 Main_Source_File := Name_Find;
6355 -- We now deal with the binder and linker switches.
6356 -- If no project file is used, there is nothing to do
6357 -- because the binder and linker switches are the same
6360 -- Reset the tables Binder_Switches and Linker_Switches
6362 Binder_Switches.Set_Last (Last_Binder_Switch);
6363 Linker_Switches.Set_Last (Last_Linker_Switch);
6365 -- Add binder switches from the project file for this main,
6368 if Do_Bind_Step and Binder_Package /= No_Package then
6369 if Verbose_Mode then
6370 Write_Str ("Adding binder switches for """);
6371 Write_Str (Main_Unit_File_Name);
6376 (File_Name => Main_Unit_File_Name,
6377 Index => Main_Index,
6378 The_Package => Binder_Package,
6382 -- Add linker switches from the project file for this main,
6385 if Do_Link_Step and Linker_Package /= No_Package then
6386 if Verbose_Mode then
6387 Write_Str ("Adding linker switches for""");
6388 Write_Str (Main_Unit_File_Name);
6393 (File_Name => Main_Unit_File_Name,
6394 Index => Main_Index,
6395 The_Package => Linker_Package,
6399 -- As we are using a project file, for relative paths we add
6400 -- the current working directory for any relative path on
6401 -- the command line and the project directory, for any
6402 -- relative path in the project file.
6405 Dir_Path : constant String_Access :=
6406 new String'(Get_Name_String
6407 (Project_Tree.Projects.Table
6408 (Main_Project).Directory));
6411 J in Last_Binder_Switch + 1 .. Binder_Switches.Last
6413 Test_If_Relative_Path
6414 (Binder_Switches.Table (J),
6415 Parent => Dir_Path, Including_L_Switch => False);
6419 J in Last_Linker_Switch + 1 .. Linker_Switches.Last
6421 Test_If_Relative_Path
6422 (Linker_Switches.Table (J), Parent => Dir_Path);
6426 -- We now put in the Binder_Switches and Linker_Switches
6427 -- tables, the binder and linker switches of the command
6428 -- line that have been put in the Saved_ tables.
6429 -- These switches will follow the project file switches.
6431 for J in 1 .. Saved_Binder_Switches.Last loop
6433 (Saved_Binder_Switches.Table (J),
6438 for J in 1 .. Saved_Linker_Switches.Last loop
6440 (Saved_Linker_Switches.Table (J),
6448 -- Remove all marks to be sure to check sources for all executables,
6449 -- as the switches may be different and -s may be in use.
6452 end loop Multiple_Main_Loop;
6454 if Failed_Links.Last > 0 then
6455 for Index in 1 .. Successful_Links.Last loop
6456 Write_Str ("Linking of """);
6457 Write_Str (Get_Name_String (Successful_Links.Table (Index)));
6458 Write_Line (""" succeeded.");
6463 for Index in 1 .. Failed_Links.Last loop
6464 Write_Str ("Linking of """);
6465 Write_Str (Get_Name_String (Failed_Links.Table (Index)));
6466 Write_Line (""" failed.");
6469 if Commands_To_Stdout then
6470 Set_Standard_Output;
6473 if Total_Compilation_Failures = 0 then
6474 Report_Compilation_Failed;
6478 if Total_Compilation_Failures /= 0 then
6479 List_Bad_Compilations;
6480 Report_Compilation_Failed;
6483 -- Delete the temporary mapping file that was created if we are
6484 -- using project files.
6486 if not Debug.Debug_Flag_N then
6487 Delete_Mapping_Files;
6488 Prj.Env.Delete_All_Path_Files (Project_Tree);
6494 Write_Line (Exception_Information (X));
6495 Make_Failed ("INTERNAL ERROR. Please report.");
6502 function Hash (F : File_Name_Type) return Header_Num is
6504 return Header_Num (1 + F mod Max_Header);
6507 --------------------
6508 -- In_Ada_Lib_Dir --
6509 --------------------
6511 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean is
6512 D : constant File_Name_Type := Get_Directory (File);
6513 B : constant Byte := Get_Name_Table_Byte (D);
6515 return (B and Ada_Lib_Dir) /= 0;
6518 -----------------------
6519 -- Init_Mapping_File --
6520 -----------------------
6522 procedure Init_Mapping_File
6523 (Project : Project_Id;
6524 File_Index : in out Natural)
6526 FD : File_Descriptor;
6528 -- For call to Close
6531 -- Increase the index of the last mapping file for this project
6533 Last_Mapping_File_Names (Project) :=
6534 Last_Mapping_File_Names (Project) + 1;
6536 -- If there is a project file, call Create_Mapping_File with
6539 if Project /= No_Project then
6540 Prj.Env.Create_Mapping_File
6541 (Project, Project_Tree,
6542 The_Mapping_File_Names
6543 (Project, Last_Mapping_File_Names (Project)));
6545 -- Otherwise, just create an empty file
6548 Tempdir.Create_Temp_File
6550 The_Mapping_File_Names
6551 (No_Project, Last_Mapping_File_Names (No_Project)));
6553 if FD = Invalid_FD then
6554 Make_Failed ("disk full");
6558 (The_Mapping_File_Names
6559 (No_Project, Last_Mapping_File_Names (No_Project)));
6565 Make_Failed ("disk full");
6569 -- And return the index of the newly created file
6571 File_Index := Last_Mapping_File_Names (Project);
6572 end Init_Mapping_File;
6580 First_Q_Initialization := False;
6582 Q.Set_Last (Q.First);
6589 procedure Initialize is
6591 Prj.Set_Mode (Ada_Only);
6593 -- Override default initialization of Check_Object_Consistency
6594 -- since this is normally False for GNATBIND, but is True for
6595 -- GNATMAKE since we do not need to check source consistency
6596 -- again once GNATMAKE has looked at the sources to check.
6598 Check_Object_Consistency := True;
6600 -- Package initializations. The order of calls is important here
6602 Output.Set_Standard_Error;
6605 Binder_Switches.Init;
6606 Linker_Switches.Init;
6613 Prj.Initialize (Project_Tree);
6617 RTS_Specified := null;
6621 -- Add the directory where gnatmake is invoked in front of the
6622 -- path, if gnatmake is invoked from a bin directory or with directory
6623 -- information. Only do this if the platform is not VMS, where the
6624 -- notion of path does not really exist.
6628 Prefix : constant String := Executable_Prefix_Path;
6629 Command : constant String := Command_Name;
6632 if Prefix'Length > 0 then
6634 PATH : constant String :=
6635 Prefix & Directory_Separator & "bin" &
6637 Getenv ("PATH").all;
6639 Setenv ("PATH", PATH);
6643 for Index in reverse Command'Range loop
6644 if Command (Index) = Directory_Separator then
6646 Absolute_Dir : constant String :=
6648 (Command (Command'First .. Index));
6649 PATH : constant String :=
6652 Getenv ("PATH").all;
6654 Setenv ("PATH", PATH);
6664 -- Scan the switches and arguments
6666 -- First, scan to detect --version and/or --help
6668 Check_Version_And_Help ("GNATMAKE", "1995", Makeusg'Access);
6670 -- Scan again the switch and arguments, now that we are sure that
6671 -- they do not include --version or --help.
6673 Scan_Args : for Next_Arg in 1 .. Argument_Count loop
6674 Scan_Make_Arg (Argument (Next_Arg), And_Save => True);
6677 if Commands_To_Stdout then
6678 Set_Standard_Output;
6681 if Usage_Requested then
6685 -- Test for trailing -P switch
6687 if Project_File_Name_Present and then Project_File_Name = null then
6688 Make_Failed ("project file name missing after -P");
6690 -- Test for trailing -o switch
6692 elsif Output_File_Name_Present
6693 and then not Output_File_Name_Seen
6695 Make_Failed ("output file name missing after -o");
6697 -- Test for trailing -D switch
6699 elsif Object_Directory_Present
6700 and then not Object_Directory_Seen then
6701 Make_Failed ("object directory missing after -D");
6704 -- Test for simultaneity of -i and -D
6706 if Object_Directory_Path /= null and then In_Place_Mode then
6707 Make_Failed ("-i and -D cannot be used simutaneously");
6710 -- Deal with -C= switch
6712 if Gnatmake_Mapping_File /= null then
6713 -- First, check compatibility with other switches
6715 if Project_File_Name /= null then
6716 Make_Failed ("-C= switch is not compatible with -P switch");
6718 elsif Saved_Maximum_Processes > 1 then
6719 Make_Failed ("-C= switch is not compatible with -jnnn switch");
6722 Fmap.Initialize (Gnatmake_Mapping_File.all);
6724 ("-gnatem=" & Gnatmake_Mapping_File.all,
6729 if Project_File_Name /= null then
6731 -- A project file was specified by a -P switch
6733 if Verbose_Mode then
6735 Write_Str ("Parsing project file """);
6736 Write_Str (Project_File_Name.all);
6741 -- Avoid looking in the current directory for ALI files
6743 -- Look_In_Primary_Dir := False;
6745 -- Set the project parsing verbosity to whatever was specified
6746 -- by a possible -vP switch.
6748 Prj.Pars.Set_Verbosity (To => Current_Verbosity);
6750 -- Parse the project file.
6751 -- If there is an error, Main_Project will still be No_Project.
6754 (Project => Main_Project,
6755 In_Tree => Project_Tree,
6756 Project_File_Name => Project_File_Name.all,
6757 Packages_To_Check => Packages_To_Check_By_Gnatmake);
6759 if Main_Project = No_Project then
6760 Make_Failed ("""", Project_File_Name.all, """ processing failed");
6763 Create_Mapping_File := True;
6765 if Verbose_Mode then
6767 Write_Str ("Parsing of project file """);
6768 Write_Str (Project_File_Name.all);
6769 Write_Str (""" is finished.");
6773 -- We add the source directories and the object directories
6774 -- to the search paths.
6776 Add_Source_Directories (Main_Project, Project_Tree);
6777 Add_Object_Directories (Main_Project, Project_Tree);
6779 -- Compute depth of each project
6781 for Proj in Project_Table.First ..
6782 Project_Table.Last (Project_Tree.Projects)
6784 Project_Tree.Projects.Table (Proj).Seen := False;
6785 Project_Tree.Projects.Table (Proj).Depth := 0;
6788 Recursive_Compute_Depth (Main_Project, Depth => 1);
6790 -- For each project compute the list of the projects it imports
6791 -- directly or indirectly.
6793 for Proj in Project_Table.First ..
6794 Project_Table.Last (Project_Tree.Projects)
6796 Compute_All_Imported_Projects (Proj);
6801 Osint.Add_Default_Search_Dirs;
6803 -- Source file lookups should be cached for efficiency. Source files
6804 -- are not supposed to change. However, we do that now only if no
6805 -- project file is used; if a project file is used, we do it just
6806 -- after changing the directory to the object directory.
6808 Osint.Source_File_Data (Cache => True);
6810 -- Read gnat.adc file to initialize Fname.UF
6812 Fname.UF.Initialize;
6815 Fname.SF.Read_Source_File_Name_Pragmas;
6818 when Err : SFN_Scan.Syntax_Error_In_GNAT_ADC =>
6819 Make_Failed (Exception_Message (Err));
6823 -- Make sure no project object directory is recorded
6825 Project_Of_Current_Object_Directory := No_Project;
6829 ----------------------------
6830 -- Insert_Project_Sources --
6831 ----------------------------
6833 procedure Insert_Project_Sources
6834 (The_Project : Project_Id;
6835 All_Projects : Boolean;
6838 Put_In_Q : Boolean := Into_Q;
6840 Sfile : File_Name_Type;
6842 Extending : constant Boolean :=
6843 Project_Tree.Projects.Table
6844 (The_Project).Extends /= No_Project;
6846 function Check_Project (P : Project_Id) return Boolean;
6847 -- Returns True if P is The_Project or a project extended by The_Project
6853 function Check_Project (P : Project_Id) return Boolean is
6855 if All_Projects or P = The_Project then
6858 elsif Extending then
6860 Data : Project_Data :=
6861 Project_Tree.Projects.Table (The_Project);
6865 if P = Data.Extends then
6869 Data := Project_Tree.Projects.Table (Data.Extends);
6870 exit when Data.Extends = No_Project;
6878 -- Start of processing for Insert_Project_Sources
6881 -- For all the sources in the project files,
6883 for Id in Unit_Table.First ..
6884 Unit_Table.Last (Project_Tree.Units)
6886 Unit := Project_Tree.Units.Table (Id);
6889 -- If there is a source for the body, and the body has not been
6892 if Unit.File_Names (Body_Part).Name /= No_File
6893 and then Unit.File_Names (Body_Part).Path /= Slash
6895 -- And it is a source for the specified project
6897 if Check_Project (Unit.File_Names (Body_Part).Project) then
6899 -- If we don't have a spec, we cannot consider the source
6900 -- if it is a subunit
6902 if Unit.File_Names (Specification).Name = No_File then
6904 Src_Ind : Source_File_Index;
6906 -- Here we are cheating a little bit: we don't want to
6907 -- use Sinput.L, because it depends on the GNAT tree
6908 -- (Atree, Sinfo, ...). So, we pretend that it is a
6909 -- project file, and we use Sinput.P.
6911 -- Source_File_Is_Subunit is just scanning through the
6912 -- file until it finds one of the reserved words
6913 -- separate, procedure, function, generic or package.
6914 -- Fortunately, these Ada reserved words are also
6915 -- reserved for project files.
6918 Src_Ind := Sinput.P.Load_Project_File
6920 (Unit.File_Names (Body_Part).Path));
6922 -- If it is a subunit, discard it
6924 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
6927 Sfile := Unit.File_Names (Body_Part).Display_Name;
6932 Sfile := Unit.File_Names (Body_Part).Display_Name;
6936 elsif Unit.File_Names (Specification).Name /= No_File
6937 and then Unit.File_Names (Specification).Path /= Slash
6938 and then Check_Project (Unit.File_Names (Specification).Project)
6940 -- If there is no source for the body, but there is a source
6941 -- for the spec which has not been locally removed, then we take
6944 Sfile := Unit.File_Names (Specification).Display_Name;
6947 -- If Put_In_Q is True, we insert into the Q
6951 -- For the first source inserted into the Q, we need to initialize
6952 -- the Q, but not for the subsequent sources.
6954 if First_Q_Initialization then
6958 -- And of course, we only insert in the Q if the source is not
6961 if Sfile /= No_File and then not Is_Marked (Sfile) then
6962 if Verbose_Mode then
6963 Write_Str ("Adding """);
6964 Write_Str (Get_Name_String (Sfile));
6965 Write_Line (""" to the queue");
6972 elsif Sfile /= No_File then
6974 -- If Put_In_Q is False, we add the source as it it were specified
6975 -- on the command line, and we set Put_In_Q to True, so that the
6976 -- following sources will be put directly in the queue. This will
6977 -- allow parallel compilation processes if -jx switch is used.
6979 if Verbose_Mode then
6980 Write_Str ("Adding """);
6981 Write_Str (Get_Name_String (Sfile));
6982 Write_Line (""" as if on the command line");
6985 Osint.Add_File (Get_Name_String (Sfile));
6988 -- As we may look into the Q later, ensure the Q has been
6989 -- initialized to avoid errors.
6991 if First_Q_Initialization then
6996 end Insert_Project_Sources;
7003 (Source_File : File_Name_Type;
7004 Source_Unit : Unit_Name_Type := No_Unit_Name;
7008 if Debug.Debug_Flag_Q then
7009 Write_Str (" Q := Q + [ ");
7010 Write_Name (Source_File);
7022 (File => Source_File,
7023 Unit => Source_Unit,
7028 ---------------------
7029 -- Is_In_Obsoleted --
7030 ---------------------
7032 function Is_In_Obsoleted (F : File_Name_Type) return Boolean is
7039 Name : constant String := Get_Name_String (F);
7041 F2 : File_Name_Type;
7045 while First > Name'First
7046 and then Name (First - 1) /= Directory_Separator
7047 and then Name (First - 1) /= '/'
7052 if First /= Name'First then
7054 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
7061 return Obsoleted.Get (F2);
7064 end Is_In_Obsoleted;
7066 ----------------------------
7067 -- Is_In_Object_Directory --
7068 ----------------------------
7070 function Is_In_Object_Directory
7071 (Source_File : File_Name_Type;
7072 Full_Lib_File : File_Name_Type) return Boolean
7075 -- There is something to check only when using project files.
7076 -- Otherwise, this function returns True (last line of the function).
7078 if Main_Project /= No_Project then
7080 Source_File_Name : constant String :=
7081 Get_Name_String (Source_File);
7082 Saved_Verbosity : constant Verbosity := Current_Verbosity;
7083 Project : Project_Id := No_Project;
7084 Data : Project_Data;
7086 Path_Name : Path_Name_Type := No_Path;
7087 pragma Warnings (Off, Path_Name);
7090 -- Call Get_Reference to know the ultimate extending project of
7091 -- the source. Call it with verbosity default to avoid verbose
7094 Current_Verbosity := Default;
7095 Prj.Env.Get_Reference
7096 (Source_File_Name => Source_File_Name,
7098 In_Tree => Project_Tree,
7100 Current_Verbosity := Saved_Verbosity;
7102 -- If this source is in a project, check that the ALI file is
7103 -- in its object directory. If it is not, return False, so that
7104 -- the ALI file will not be skipped.
7106 if Project /= No_Project then
7107 Data := Project_Tree.Projects.Table (Project);
7110 Object_Directory : constant String :=
7113 (Data.Display_Object_Dir));
7115 Olast : Natural := Object_Directory'Last;
7117 Lib_File_Directory : constant String :=
7118 Normalize_Pathname (Dir_Name
7119 (Get_Name_String (Full_Lib_File)));
7121 Llast : Natural := Lib_File_Directory'Last;
7124 -- For directories, Normalize_Pathname may or may not put
7125 -- a directory separator at the end, depending on its input.
7126 -- Remove any last directory separator before comparaison.
7127 -- Returns True only if the two directories are the same.
7129 if Object_Directory (Olast) = Directory_Separator then
7133 if Lib_File_Directory (Llast) = Directory_Separator then
7137 return Object_Directory (Object_Directory'First .. Olast) =
7138 Lib_File_Directory (Lib_File_Directory'First .. Llast);
7144 -- When the source is not in a project file, always return True
7147 end Is_In_Object_Directory;
7154 (ALI_File : File_Name_Type;
7155 Args : Argument_List;
7156 Success : out Boolean)
7158 Link_Args : Argument_List (1 .. Args'Length + 1);
7161 Get_Name_String (ALI_File);
7162 Link_Args (1) := new String'(Name_Buffer (1 .. Name_Len));
7164 Link_Args (2 .. Args'Length + 1) := Args;
7166 GNAT.OS_Lib.Normalize_Arguments (Link_Args);
7168 Display (Gnatlink.all, Link_Args);
7170 if Gnatlink_Path = null then
7171 Make_Failed ("error, unable to locate ", Gnatlink.all);
7174 GNAT.OS_Lib.Spawn (Gnatlink_Path.all, Link_Args, Success);
7177 ---------------------------
7178 -- List_Bad_Compilations --
7179 ---------------------------
7181 procedure List_Bad_Compilations is
7183 for J in Bad_Compilation.First .. Bad_Compilation.Last loop
7184 if Bad_Compilation.Table (J).File = No_File then
7186 elsif not Bad_Compilation.Table (J).Found then
7187 Inform (Bad_Compilation.Table (J).File, "not found");
7189 Inform (Bad_Compilation.Table (J).File, "compilation error");
7192 end List_Bad_Compilations;
7198 procedure List_Depend is
7199 Lib_Name : File_Name_Type;
7200 Obj_Name : File_Name_Type;
7201 Src_Name : File_Name_Type;
7205 Line_Size : constant := 77;
7208 Set_Standard_Output;
7210 for A in ALIs.First .. ALIs.Last loop
7211 Lib_Name := ALIs.Table (A).Afile;
7213 -- We have to provide the full library file name in In_Place_Mode
7215 if In_Place_Mode then
7216 Lib_Name := Full_Lib_File_Name (Lib_Name);
7219 Obj_Name := Object_File_Name (Lib_Name);
7220 Write_Name (Obj_Name);
7223 Get_Name_String (Obj_Name);
7225 Line_Pos := Len + 2;
7227 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
7228 Src_Name := Sdep.Table (D).Sfile;
7230 if Is_Internal_File_Name (Src_Name)
7231 and then not Check_Readonly_Files
7235 if not Quiet_Output then
7236 Src_Name := Full_Source_Name (Src_Name);
7239 Get_Name_String (Src_Name);
7242 if Line_Pos + Len + 1 > Line_Size then
7248 Line_Pos := Line_Pos + Len + 1;
7251 Write_Name (Src_Name);
7258 if not Commands_To_Stdout then
7267 procedure Make_Failed (S1 : String; S2 : String := ""; S3 : String := "") is
7269 Delete_All_Temp_Files;
7270 Osint.Fail (S1, S2, S3);
7273 --------------------
7274 -- Mark_Directory --
7275 --------------------
7277 procedure Mark_Directory
7279 Mark : Lib_Mark_Type;
7280 On_Command_Line : Boolean)
7286 if On_Command_Line then
7288 Real_Path : constant String := Normalize_Pathname (Dir);
7291 if Real_Path'Length = 0 then
7292 Name_Len := Dir'Length;
7293 Name_Buffer (1 .. Name_Len) := Dir;
7296 Name_Len := Real_Path'Length;
7297 Name_Buffer (1 .. Name_Len) := Real_Path;
7303 Real_Path : constant String :=
7307 (Project_Tree.Projects.Table
7308 (Main_Project).Display_Directory));
7311 if Real_Path'Length = 0 then
7312 Name_Len := Dir'Length;
7313 Name_Buffer (1 .. Name_Len) := Dir;
7316 Name_Len := Real_Path'Length;
7317 Name_Buffer (1 .. Name_Len) := Real_Path;
7322 -- Last character is supposed to be a directory separator
7324 if not Is_Directory_Separator (Name_Buffer (Name_Len)) then
7325 Name_Len := Name_Len + 1;
7326 Name_Buffer (Name_Len) := Directory_Separator;
7329 -- Add flags to the already existing flags
7332 B := Get_Name_Table_Byte (N);
7333 Set_Name_Table_Byte (N, B or Mark);
7336 -----------------------------
7337 -- Recursive_Compute_Depth --
7338 -----------------------------
7340 procedure Recursive_Compute_Depth
7341 (Project : Project_Id;
7344 List : Project_List;
7348 -- Nothing to do if there is no project or if the project has already
7349 -- been seen or if the depth is large enough.
7351 if Project = No_Project
7352 or else Project_Tree.Projects.Table (Project).Seen
7353 or else Project_Tree.Projects.Table (Project).Depth >= Depth
7358 Project_Tree.Projects.Table (Project).Depth := Depth;
7360 -- Mark project as Seen to avoid endless loop caused by limited withs
7362 Project_Tree.Projects.Table (Project).Seen := True;
7364 List := Project_Tree.Projects.Table (Project).Imported_Projects;
7366 -- Visit each imported project
7368 while List /= Empty_Project_List loop
7369 Proj := Project_Tree.Project_Lists.Table (List).Project;
7370 List := Project_Tree.Project_Lists.Table (List).Next;
7371 Recursive_Compute_Depth
7373 Depth => Depth + 1);
7376 -- Visit a project being extended, if any
7378 Recursive_Compute_Depth
7379 (Project => Project_Tree.Projects.Table (Project).Extends,
7380 Depth => Depth + 1);
7382 -- Reset the Seen flag, as we leave this project
7384 Project_Tree.Projects.Table (Project).Seen := False;
7385 end Recursive_Compute_Depth;
7387 -------------------------------
7388 -- Report_Compilation_Failed --
7389 -------------------------------
7391 procedure Report_Compilation_Failed is
7393 if not Debug.Debug_Flag_N then
7394 Delete_Mapping_Files;
7395 Prj.Env.Delete_All_Path_Files (Project_Tree);
7398 Exit_Program (E_Fatal);
7399 end Report_Compilation_Failed;
7401 ------------------------
7402 -- Sigint_Intercepted --
7403 ------------------------
7405 procedure Sigint_Intercepted is
7406 SIGINT : constant := 2;
7409 Write_Line ("*** Interrupted ***");
7410 Delete_All_Temp_Files;
7412 -- Send SIGINT to all oustanding compilation processes spawned
7414 for J in 1 .. Outstanding_Compiles loop
7415 Kill (Running_Compile (J).Pid, SIGINT, 1);
7419 end Sigint_Intercepted;
7425 procedure Scan_Make_Arg (Argv : String; And_Save : Boolean) is
7429 pragma Assert (Argv'First = 1);
7431 if Argv'Length = 0 then
7435 -- If the previous switch has set the Project_File_Name_Present flag
7436 -- (that is we have seen a -P alone), then the next argument is the name
7437 -- of the project file.
7439 if Project_File_Name_Present and then Project_File_Name = null then
7440 if Argv (1) = '-' then
7441 Make_Failed ("project file name missing after -P");
7444 Project_File_Name_Present := False;
7445 Project_File_Name := new String'(Argv);
7448 -- If the previous switch has set the Output_File_Name_Present flag
7449 -- (that is we have seen a -o), then the next argument is the name of
7450 -- the output executable.
7452 elsif Output_File_Name_Present
7453 and then not Output_File_Name_Seen
7455 Output_File_Name_Seen := True;
7457 if Argv (1) = '-' then
7458 Make_Failed ("output file name missing after -o");
7461 Add_Switch ("-o", Linker, And_Save => And_Save);
7462 Add_Switch (Executable_Name (Argv), Linker, And_Save => And_Save);
7465 -- If the previous switch has set the Object_Directory_Present flag
7466 -- (that is we have seen a -D), then the next argument is the path name
7467 -- of the object directory..
7469 elsif Object_Directory_Present
7470 and then not Object_Directory_Seen
7472 Object_Directory_Seen := True;
7474 if Argv (1) = '-' then
7475 Make_Failed ("object directory path name missing after -D");
7477 elsif not Is_Directory (Argv) then
7478 Make_Failed ("cannot find object directory """, Argv, """");
7481 Add_Lib_Search_Dir (Argv);
7483 -- Specify the object directory to the binder
7485 Add_Switch ("-aO" & Argv, Binder, And_Save => And_Save);
7487 -- Record the object directory. Make sure it ends with a directory
7490 if Argv (Argv'Last) = Directory_Separator then
7491 Object_Directory_Path :=
7494 Object_Directory_Path :=
7495 new String'(Argv & Directory_Separator);
7499 -- Then check if we are dealing with -cargs/-bargs/-largs/-margs
7501 elsif Argv = "-bargs"
7510 when 'c' => Program_Args := Compiler;
7511 when 'b' => Program_Args := Binder;
7512 when 'l' => Program_Args := Linker;
7513 when 'm' => Program_Args := None;
7516 raise Program_Error;
7519 -- A special test is needed for the -o switch within a -largs
7520 -- since that is another way to specify the name of the final
7523 elsif Program_Args = Linker
7524 and then Argv = "-o"
7526 Make_Failed ("switch -o not allowed within a -largs. " &
7527 "Use -o directly.");
7529 -- Check to see if we are reading switches after a -cargs,
7530 -- -bargs or -largs switch. If yes save it.
7532 elsif Program_Args /= None then
7534 -- Check to see if we are reading -I switches in order
7535 -- to take into account in the src & lib search directories.
7537 if Argv'Length > 2 and then Argv (1 .. 2) = "-I" then
7538 if Argv (3 .. Argv'Last) = "-" then
7539 Look_In_Primary_Dir := False;
7541 elsif Program_Args = Compiler then
7542 if Argv (3 .. Argv'Last) /= "-" then
7543 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7546 elsif Program_Args = Binder then
7547 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7551 Add_Switch (Argv, Program_Args, And_Save => And_Save);
7553 -- Handle non-default compiler, binder, linker, and handle --RTS switch
7555 elsif Argv'Length > 2 and then Argv (1 .. 2) = "--" then
7557 and then Argv (1 .. 6) = "--GCC="
7560 Program_Args : constant Argument_List_Access :=
7561 Argument_String_To_List
7562 (Argv (7 .. Argv'Last));
7566 Saved_Gcc := new String'(Program_Args.all (1).all);
7568 Gcc := new String'(Program_Args.all (1).all);
7571 for J in 2 .. Program_Args.all'Last loop
7573 (Program_Args.all (J).all,
7575 And_Save => And_Save);
7579 elsif Argv'Length > 11
7580 and then Argv (1 .. 11) = "--GNATBIND="
7583 Program_Args : constant Argument_List_Access :=
7584 Argument_String_To_List
7585 (Argv (12 .. Argv'Last));
7589 Saved_Gnatbind := new String'(Program_Args.all (1).all);
7591 Gnatbind := new String'(Program_Args.all (1).all);
7594 for J in 2 .. Program_Args.all'Last loop
7596 (Program_Args.all (J).all, Binder, And_Save => And_Save);
7600 elsif Argv'Length > 11
7601 and then Argv (1 .. 11) = "--GNATLINK="
7604 Program_Args : constant Argument_List_Access :=
7605 Argument_String_To_List
7606 (Argv (12 .. Argv'Last));
7609 Saved_Gnatlink := new String'(Program_Args.all (1).all);
7611 Gnatlink := new String'(Program_Args.all (1).all);
7614 for J in 2 .. Program_Args.all'Last loop
7615 Add_Switch (Program_Args.all (J).all, Linker);
7619 elsif Argv'Length >= 5 and then
7620 Argv (1 .. 5) = "--RTS"
7622 Add_Switch (Argv, Compiler, And_Save => And_Save);
7623 Add_Switch (Argv, Binder, And_Save => And_Save);
7625 if Argv'Length <= 6 or else Argv (6) /= '=' then
7626 Make_Failed ("missing path for --RTS");
7629 -- Check that this is the first time we see this switch or
7630 -- if it is not the first time, the same path is specified.
7632 if RTS_Specified = null then
7633 RTS_Specified := new String'(Argv (7 .. Argv'Last));
7635 elsif RTS_Specified.all /= Argv (7 .. Argv'Last) then
7636 Make_Failed ("--RTS cannot be specified multiple times");
7639 -- Valid --RTS switch
7646 Src_Path_Name : constant String_Ptr :=
7648 (Argv (7 .. Argv'Last), Include);
7650 Lib_Path_Name : constant String_Ptr :=
7652 (Argv (7 .. Argv'Last), Objects);
7655 if Src_Path_Name /= null
7656 and then Lib_Path_Name /= null
7658 -- Set RTS_*_Path_Name variables, so that correct direct-
7659 -- ories will be set when Osint.Add_Default_Search_Dirs
7662 RTS_Src_Path_Name := Src_Path_Name;
7663 RTS_Lib_Path_Name := Lib_Path_Name;
7665 elsif Src_Path_Name = null
7666 and Lib_Path_Name = null
7668 Make_Failed ("RTS path not valid: missing " &
7669 "adainclude and adalib directories");
7671 elsif Src_Path_Name = null then
7672 Make_Failed ("RTS path not valid: missing adainclude " &
7675 elsif Lib_Path_Name = null then
7676 Make_Failed ("RTS path not valid: missing adalib " &
7683 Scan_Make_Switches (Argv, Success);
7686 -- If we have seen a regular switch process it
7688 elsif Argv (1) = '-' then
7690 if Argv'Length = 1 then
7691 Make_Failed ("switch character cannot be followed by a blank");
7693 -- Incorrect switches that should start with "--"
7695 elsif (Argv'Length > 5 and then Argv (1 .. 5) = "-RTS=")
7696 or else (Argv'Length > 5 and then Argv (1 .. 5) = "-GCC=")
7697 or else (Argv'Length > 10 and then Argv (1 .. 10) = "-GNATLINK=")
7698 or else (Argv'Length > 10 and then Argv (1 .. 10) = "-GNATBIND=")
7700 Make_Failed ("option ", Argv, " should start with '--'");
7704 elsif Argv (2 .. Argv'Last) = "I-" then
7705 Look_In_Primary_Dir := False;
7707 -- Forbid -?- or -??- where ? is any character
7709 elsif (Argv'Length = 3 and then Argv (3) = '-')
7710 or else (Argv'Length = 4 and then Argv (4) = '-')
7712 Make_Failed ("trailing ""-"" at the end of ", Argv, " forbidden.");
7716 elsif Argv (2) = 'I' then
7717 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7718 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7719 Add_Switch (Argv, Compiler, And_Save => And_Save);
7720 Add_Switch (Argv, Binder, And_Save => And_Save);
7722 -- -aIdir (to gcc this is like a -I switch)
7724 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aI" then
7725 Add_Source_Search_Dir (Argv (4 .. Argv'Last), And_Save);
7726 Add_Switch ("-I" & Argv (4 .. Argv'Last),
7728 And_Save => And_Save);
7729 Add_Switch (Argv, Binder, And_Save => And_Save);
7733 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aO" then
7734 Add_Library_Search_Dir (Argv (4 .. Argv'Last), And_Save);
7735 Add_Switch (Argv, Binder, And_Save => And_Save);
7737 -- -aLdir (to gnatbind this is like a -aO switch)
7739 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aL" then
7740 Mark_Directory (Argv (4 .. Argv'Last), Ada_Lib_Dir, And_Save);
7741 Add_Library_Search_Dir (Argv (4 .. Argv'Last), And_Save);
7742 Add_Switch ("-aO" & Argv (4 .. Argv'Last),
7744 And_Save => And_Save);
7746 -- -Adir (to gnatbind this is like a -aO switch, to gcc like a -I)
7748 elsif Argv (2) = 'A' then
7749 Mark_Directory (Argv (3 .. Argv'Last), Ada_Lib_Dir, And_Save);
7750 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7751 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7752 Add_Switch ("-I" & Argv (3 .. Argv'Last),
7754 And_Save => And_Save);
7755 Add_Switch ("-aO" & Argv (3 .. Argv'Last),
7757 And_Save => And_Save);
7761 elsif Argv (2) = 'L' then
7762 Add_Switch (Argv, Linker, And_Save => And_Save);
7764 -- For -gxxxxx, -pg, -mxxx, -fxxx: give the switch to both the
7765 -- compiler and the linker (except for -gnatxxx which is only for
7766 -- the compiler). Some of the -mxxx (for example -m64) and -fxxx
7767 -- (for example -ftest-coverage for gcov) need to be used when
7768 -- compiling the binder generated files, and using all these gcc
7769 -- switches for the binder generated files should not be a problem.
7772 (Argv (2) = 'g' and then (Argv'Last < 5
7773 or else Argv (2 .. 5) /= "gnat"))
7774 or else Argv (2 .. Argv'Last) = "pg"
7775 or else (Argv (2) = 'm' and then Argv'Last > 2)
7776 or else (Argv (2) = 'f' and then Argv'Last > 2)
7778 Add_Switch (Argv, Compiler, And_Save => And_Save);
7779 Add_Switch (Argv, Linker, And_Save => And_Save);
7781 -- -C=<mapping file>
7783 elsif Argv'Last > 2 and then Argv (2) = 'C' then
7785 if Argv (3) /= '=' or else Argv'Last <= 3 then
7786 Make_Failed ("illegal switch ", Argv);
7789 Gnatmake_Mapping_File := new String'(Argv (4 .. Argv'Last));
7794 elsif Argv'Last = 2 and then Argv (2) = 'D' then
7795 if Project_File_Name /= null then
7796 Make_Failed ("-D cannot be used in conjunction with a " &
7800 Scan_Make_Switches (Argv, Success);
7805 elsif Argv (2) = 'd'
7806 and then Argv'Last = 2
7808 Display_Compilation_Progress := True;
7812 elsif Argv'Last = 2 and then Argv (2) = 'i' then
7813 if Project_File_Name /= null then
7814 Make_Failed ("-i cannot be used in conjunction with a " &
7818 Scan_Make_Switches (Argv, Success);
7821 -- -j (need to save the result)
7823 elsif Argv (2) = 'j' then
7824 Scan_Make_Switches (Argv, Success);
7827 Saved_Maximum_Processes := Maximum_Processes;
7832 elsif Argv (2) = 'm'
7833 and then Argv'Last = 2
7835 Minimal_Recompilation := True;
7839 elsif Argv (2) = 'u'
7840 and then Argv'Last = 2
7842 Unique_Compile := True;
7843 Compile_Only := True;
7844 Do_Bind_Step := False;
7845 Do_Link_Step := False;
7849 elsif Argv (2) = 'U'
7850 and then Argv'Last = 2
7852 Unique_Compile_All_Projects := True;
7853 Unique_Compile := True;
7854 Compile_Only := True;
7855 Do_Bind_Step := False;
7856 Do_Link_Step := False;
7858 -- -Pprj or -P prj (only once, and only on the command line)
7860 elsif Argv (2) = 'P' then
7861 if Project_File_Name /= null then
7862 Make_Failed ("cannot have several project files specified");
7864 elsif Object_Directory_Path /= null then
7865 Make_Failed ("-D cannot be used in conjunction with a " &
7868 elsif In_Place_Mode then
7869 Make_Failed ("-i cannot be used in conjunction with a " &
7872 elsif not And_Save then
7874 -- It could be a tool other than gnatmake (i.e, gnatdist)
7875 -- or a -P switch inside a project file.
7878 ("either the tool is not ""project-aware"" or " &
7879 "a project file is specified inside a project file");
7881 elsif Argv'Last = 2 then
7883 -- -P is used alone: the project file name is the next option
7885 Project_File_Name_Present := True;
7888 Project_File_Name := new String'(Argv (3 .. Argv'Last));
7891 -- -vPx (verbosity of the parsing of the project files)
7894 and then Argv (2 .. 3) = "vP"
7895 and then Argv (4) in '0' .. '2'
7900 Current_Verbosity := Prj.Default;
7902 Current_Verbosity := Prj.Medium;
7904 Current_Verbosity := Prj.High;
7910 -- -Xext=val (External assignment)
7912 elsif Argv (2) = 'X'
7913 and then Is_External_Assignment (Argv)
7915 -- Is_External_Assignment has side effects
7916 -- when it returns True;
7920 -- If -gnath is present, then generate the usage information
7921 -- right now and do not pass this option on to the compiler calls.
7923 elsif Argv = "-gnath" then
7926 -- If -gnatc is specified, make sure the bind step and the link
7927 -- step are not executed.
7929 elsif Argv'Length >= 6 and then Argv (2 .. 6) = "gnatc" then
7931 -- If -gnatc is specified, make sure the bind step and the link
7932 -- step are not executed.
7934 Add_Switch (Argv, Compiler, And_Save => And_Save);
7935 Operating_Mode := Check_Semantics;
7936 Check_Object_Consistency := False;
7937 Compile_Only := True;
7938 Do_Bind_Step := False;
7939 Do_Link_Step := False;
7941 elsif Argv (2 .. Argv'Last) = "nostdlib" then
7943 -- Don't pass -nostdlib to gnatlink, it will disable
7944 -- linking with all standard library files.
7948 Add_Switch (Argv, Compiler, And_Save => And_Save);
7949 Add_Switch (Argv, Binder, And_Save => And_Save);
7951 elsif Argv (2 .. Argv'Last) = "nostdinc" then
7953 -- Pass -nostdinc to the Compiler and to gnatbind
7956 Add_Switch (Argv, Compiler, And_Save => And_Save);
7957 Add_Switch (Argv, Binder, And_Save => And_Save);
7959 -- All other switches are processed by Scan_Make_Switches.
7960 -- If the call returns with Success = False, then the switch is
7961 -- passed to the compiler.
7964 Scan_Make_Switches (Argv, Success);
7967 Add_Switch (Argv, Compiler, And_Save => And_Save);
7971 -- If not a switch it must be a file name
7975 Mains.Add_Main (Argv);
7983 function Switches_Of
7984 (Source_File : File_Name_Type;
7985 Source_File_Name : String;
7987 Naming : Naming_Data;
7988 In_Package : Package_Id;
7989 Allow_ALI : Boolean) return Variable_Value
7991 Switches : Variable_Value;
7993 Defaults : constant Array_Element_Id :=
7995 (Name => Name_Default_Switches,
7997 Project_Tree.Packages.Table
7998 (In_Package).Decl.Arrays,
7999 In_Tree => Project_Tree);
8001 Switches_Array : constant Array_Element_Id :=
8003 (Name => Name_Switches,
8005 Project_Tree.Packages.Table
8006 (In_Package).Decl.Arrays,
8007 In_Tree => Project_Tree);
8012 (Index => Name_Id (Source_File),
8013 Src_Index => Source_Index,
8014 In_Array => Switches_Array,
8015 In_Tree => Project_Tree);
8017 if Switches = Nil_Variable_Value then
8019 Name : String (1 .. Source_File_Name'Length + 3);
8020 Last : Positive := Source_File_Name'Length;
8021 Spec_Suffix : constant String :=
8022 Spec_Suffix_Of (Project_Tree, "ada", Naming);
8023 Body_Suffix : constant String :=
8024 Body_Suffix_Of (Project_Tree, "ada", Naming);
8025 Truncated : Boolean := False;
8028 Name (1 .. Last) := Source_File_Name;
8030 if Last > Body_Suffix'Length
8031 and then Name (Last - Body_Suffix'Length + 1 .. Last) =
8035 Last := Last - Body_Suffix'Length;
8039 and then Last > Spec_Suffix'Length
8040 and then Name (Last - Spec_Suffix'Length + 1 .. Last) =
8044 Last := Last - Spec_Suffix'Length;
8049 Name_Buffer (1 .. Name_Len) := Name (1 .. Last);
8052 (Index => Name_Find,
8054 In_Array => Switches_Array,
8055 In_Tree => Project_Tree);
8057 if Switches = Nil_Variable_Value
8060 Last := Source_File_Name'Length;
8062 while Name (Last) /= '.' loop
8066 Name (Last + 1 .. Last + 3) := "ali";
8067 Name_Len := Last + 3;
8068 Name_Buffer (1 .. Name_Len) := Name (1 .. Name_Len);
8071 (Index => Name_Find,
8073 In_Array => Switches_Array,
8074 In_Tree => Project_Tree);
8080 if Switches = Nil_Variable_Value then
8085 In_Array => Defaults,
8086 In_Tree => Project_Tree);
8098 if Usage_Needed then
8099 Usage_Needed := False;
8108 procedure Verbose_Msg
8111 N2 : Name_Id := No_Name;
8113 Prefix : String := " -> ";
8114 Minimum_Verbosity : Verbosity_Level_Type := Opt.Low)
8117 if (not Verbose_Mode) or else (Minimum_Verbosity > Verbosity_Level) then
8127 if N2 /= No_Name then
8137 procedure Verbose_Msg
8138 (N1 : File_Name_Type;
8140 N2 : File_Name_Type := No_File;
8142 Prefix : String := " -> ";
8143 Minimum_Verbosity : Verbosity_Level_Type := Opt.Low)
8147 (Name_Id (N1), S1, Name_Id (N2), S2, Prefix, Minimum_Verbosity);
8151 -- Make sure that in case of failure, the temp files will be deleted
8153 Prj.Com.Fail := Make_Failed'Access;
8154 MLib.Fail := Make_Failed'Access;
8155 Makeutl.Do_Fail := Make_Failed'Access;