1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2008, 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;
84 pragma Convention (C, Sigint_Handler);
86 procedure Install_Int_Handler (Handler : Sigint_Handler);
87 pragma Import (C, Install_Int_Handler, "__gnat_install_int_handler");
88 -- Called by Gnatmake to install the SIGINT handler below
90 procedure Sigint_Intercepted;
91 pragma Convention (C, Sigint_Intercepted);
92 -- Called when the program is interrupted by Ctrl-C to delete the
93 -- temporary mapping files and configuration pragmas files.
95 No_Mapping_File : constant Natural := 0;
97 type Compilation_Data is record
99 Full_Source_File : File_Name_Type;
100 Lib_File : File_Name_Type;
101 Source_Unit : Unit_Name_Type;
102 Mapping_File : Natural := No_Mapping_File;
103 Project : Project_Id := No_Project;
104 Syntax_Only : Boolean := False;
105 Output_Is_Object : Boolean := True;
107 -- Data recorded for each compilation process spawned
109 type Comp_Data_Arr is array (Positive range <>) of Compilation_Data;
110 type Comp_Data_Ptr is access Comp_Data_Arr;
111 Running_Compile : Comp_Data_Ptr;
112 -- Used to save information about outstanding compilations
114 Outstanding_Compiles : Natural := 0;
115 -- Current number of outstanding compiles
117 -------------------------
118 -- Note on terminology --
119 -------------------------
121 -- In this program, we use the phrase "termination" of a file name to refer
122 -- to the suffix that appears after the unit name portion. Very often this
123 -- is simply the extension, but in some cases, the sequence may be more
124 -- complex, for example in main.1.ada, the termination in this name is
125 -- ".1.ada" and in main_.ada the termination is "_.ada".
127 -------------------------------------
128 -- Queue (Q) Manipulation Routines --
129 -------------------------------------
131 -- The Q is used in Compile_Sources below. Its implementation uses the GNAT
132 -- generic package Table (basically an extensible array). Q_Front points to
133 -- the first valid element in the Q, whereas Q.First is the first element
134 -- ever enqueued, while Q.Last - 1 is the last element in the Q.
136 -- +---+--------------+---+---+---+-----------+---+--------
137 -- Q | | ........ | | | | ....... | |
138 -- +---+--------------+---+---+---+-----------+---+--------
140 -- Q.First Q_Front Q.Last - 1
142 -- The elements comprised between Q.First and Q_Front - 1 are the elements
143 -- that have been enqueued and then dequeued, while the elements between
144 -- Q_Front and Q.Last - 1 are the elements currently in the Q. When the Q
145 -- is initialized Q_Front = Q.First = Q.Last. After Compile_Sources has
146 -- terminated its execution, Q_Front = Q.Last and the elements contained
147 -- between Q.Front and Q.Last-1 are those that were explored and thus
148 -- marked by Compile_Sources. Whenever the Q is reinitialized, the elements
149 -- between Q.First and Q.Last - 1 are unmarked.
152 -- Must be called to (re)initialize the Q
155 (Source_File : File_Name_Type;
156 Source_Unit : Unit_Name_Type := No_Unit_Name;
158 -- Inserts Source_File at the end of Q. Provide Source_Unit when possible
159 -- for external use (gnatdist). Provide index for multi-unit sources.
161 function Empty_Q return Boolean;
162 -- Returns True if Q is empty
164 procedure Extract_From_Q
165 (Source_File : out File_Name_Type;
166 Source_Unit : out Unit_Name_Type;
167 Source_Index : out Int);
168 -- Extracts the first element from the Q
170 procedure Insert_Project_Sources
171 (The_Project : Project_Id;
172 All_Projects : Boolean;
174 -- If Into_Q is True, insert all sources of the project file(s) that are
175 -- not already marked into the Q. If Into_Q is False, call Osint.Add_File
176 -- for the first source, then insert all other sources that are not already
177 -- marked into the Q. If All_Projects is True, all sources of all projects
178 -- are concerned; otherwise, only sources of The_Project are concerned,
179 -- including, if The_Project is an extending project, sources inherited
180 -- from projects being extended.
182 First_Q_Initialization : Boolean := True;
183 -- Will be set to false after Init_Q has been called once
186 -- Points to the first valid element in the Q
188 Unique_Compile : Boolean := False;
189 -- Set to True if -u or -U or a project file with no main is used
191 Unique_Compile_All_Projects : Boolean := False;
192 -- Set to True if -U is used
194 RTS_Specified : String_Access := null;
195 -- Used to detect multiple --RTS= switches
197 type Q_Record is record
198 File : File_Name_Type;
199 Unit : Unit_Name_Type;
202 -- File is the name of the file to compile. Unit is for gnatdist
203 -- use in order to easily get the unit name of a file to compile
204 -- when its name is krunched or declared in gnat.adc. Index, when not 0,
205 -- is the index of the unit in a multi-unit source.
207 package Q is new Table.Table (
208 Table_Component_Type => Q_Record,
209 Table_Index_Type => Natural,
210 Table_Low_Bound => 0,
211 Table_Initial => 4000,
212 Table_Increment => 100,
213 Table_Name => "Make.Q");
214 -- This is the actual Q
216 -- The 3 following packages are used to store gcc, gnatbind and gnatlink
217 -- switches found in the project files.
219 package Gcc_Switches is new Table.Table (
220 Table_Component_Type => String_Access,
221 Table_Index_Type => Integer,
222 Table_Low_Bound => 1,
224 Table_Increment => 100,
225 Table_Name => "Make.Gcc_Switches");
227 package Binder_Switches is new Table.Table (
228 Table_Component_Type => String_Access,
229 Table_Index_Type => Integer,
230 Table_Low_Bound => 1,
232 Table_Increment => 100,
233 Table_Name => "Make.Binder_Switches");
235 package Linker_Switches is new Table.Table (
236 Table_Component_Type => String_Access,
237 Table_Index_Type => Integer,
238 Table_Low_Bound => 1,
240 Table_Increment => 100,
241 Table_Name => "Make.Linker_Switches");
243 -- The following instantiations and variables are necessary to save what
244 -- is found on the command line, in case there is a project file specified.
246 package Saved_Gcc_Switches is new Table.Table (
247 Table_Component_Type => String_Access,
248 Table_Index_Type => Integer,
249 Table_Low_Bound => 1,
251 Table_Increment => 100,
252 Table_Name => "Make.Saved_Gcc_Switches");
254 package Saved_Binder_Switches is new Table.Table (
255 Table_Component_Type => String_Access,
256 Table_Index_Type => Integer,
257 Table_Low_Bound => 1,
259 Table_Increment => 100,
260 Table_Name => "Make.Saved_Binder_Switches");
262 package Saved_Linker_Switches is new Table.Table
263 (Table_Component_Type => String_Access,
264 Table_Index_Type => Integer,
265 Table_Low_Bound => 1,
267 Table_Increment => 100,
268 Table_Name => "Make.Saved_Linker_Switches");
270 package Switches_To_Check is new Table.Table (
271 Table_Component_Type => String_Access,
272 Table_Index_Type => Integer,
273 Table_Low_Bound => 1,
275 Table_Increment => 100,
276 Table_Name => "Make.Switches_To_Check");
278 package Library_Paths is new Table.Table (
279 Table_Component_Type => String_Access,
280 Table_Index_Type => Integer,
281 Table_Low_Bound => 1,
283 Table_Increment => 100,
284 Table_Name => "Make.Library_Paths");
286 package Failed_Links is new Table.Table (
287 Table_Component_Type => File_Name_Type,
288 Table_Index_Type => Integer,
289 Table_Low_Bound => 1,
291 Table_Increment => 100,
292 Table_Name => "Make.Failed_Links");
294 package Successful_Links is new Table.Table (
295 Table_Component_Type => File_Name_Type,
296 Table_Index_Type => Integer,
297 Table_Low_Bound => 1,
299 Table_Increment => 100,
300 Table_Name => "Make.Successful_Links");
302 package Library_Projs is new Table.Table (
303 Table_Component_Type => Project_Id,
304 Table_Index_Type => Integer,
305 Table_Low_Bound => 1,
307 Table_Increment => 100,
308 Table_Name => "Make.Library_Projs");
310 -- Two variables to keep the last binder and linker switch index in tables
311 -- Binder_Switches and Linker_Switches, before adding switches from the
312 -- project file (if any) and switches from the command line (if any).
314 Last_Binder_Switch : Integer := 0;
315 Last_Linker_Switch : Integer := 0;
317 Normalized_Switches : Argument_List_Access := new Argument_List (1 .. 10);
318 Last_Norm_Switch : Natural := 0;
320 Saved_Maximum_Processes : Natural := 0;
322 type Arg_List_Ref is access Argument_List;
323 The_Saved_Gcc_Switches : Arg_List_Ref;
325 Project_File_Name : String_Access := null;
326 -- The path name of the main project file, if any
328 Project_File_Name_Present : Boolean := False;
329 -- True when -P is used with a space between -P and the project file name
331 Current_Verbosity : Prj.Verbosity := Prj.Default;
332 -- Verbosity to parse the project files
334 Project_Tree : constant Project_Tree_Ref := new Project_Tree_Data;
336 Main_Project : Prj.Project_Id := No_Project;
337 -- The project id of the main project file, if any
339 Project_Of_Current_Object_Directory : Project_Id := No_Project;
340 -- The object directory of the project for the last compilation. Avoid
341 -- calling Change_Dir if the current working directory is already this
344 -- Packages of project files where unknown attributes are errors
346 Naming_String : aliased String := "naming";
347 Builder_String : aliased String := "builder";
348 Compiler_String : aliased String := "compiler";
349 Binder_String : aliased String := "binder";
350 Linker_String : aliased String := "linker";
352 Gnatmake_Packages : aliased String_List :=
353 (Naming_String 'Access,
354 Builder_String 'Access,
355 Compiler_String 'Access,
356 Binder_String 'Access,
357 Linker_String 'Access);
359 Packages_To_Check_By_Gnatmake : constant String_List_Access :=
360 Gnatmake_Packages'Access;
362 procedure Add_Library_Search_Dir
364 On_Command_Line : Boolean);
365 -- Call Add_Lib_Search_Dir with an absolute directory path. If Path is
366 -- relative path, when On_Command_Line is True, it is relative to the
367 -- current working directory. When On_Command_Line is False, it is relative
368 -- to the project directory of the main project.
370 procedure Add_Source_Search_Dir
372 On_Command_Line : Boolean);
373 -- Call Add_Src_Search_Dir with an absolute directory path. If Path is a
374 -- relative path, when On_Command_Line is True, it is relative to the
375 -- current working directory. When On_Command_Line is False, it is relative
376 -- to the project directory of the main project.
378 procedure Add_Source_Dir (N : String);
379 -- Call Add_Src_Search_Dir (output one line when in verbose mode)
381 procedure Add_Source_Directories is
382 new Prj.Env.For_All_Source_Dirs (Action => Add_Source_Dir);
384 procedure Add_Object_Dir (N : String);
385 -- Call Add_Lib_Search_Dir (output one line when in verbose mode)
387 procedure Add_Object_Directories is
388 new Prj.Env.For_All_Object_Dirs (Action => Add_Object_Dir);
390 procedure Change_To_Object_Directory (Project : Project_Id);
391 -- Change to the object directory of project Project, if this is not
392 -- already the current working directory.
394 type Bad_Compilation_Info is record
395 File : File_Name_Type;
396 Unit : Unit_Name_Type;
399 -- File is the name of the file for which a compilation failed. Unit is for
400 -- gnatdist use in order to easily get the unit name of a file when its
401 -- name is krunched or declared in gnat.adc. Found is False if the
402 -- compilation failed because the file could not be found.
404 package Bad_Compilation is new Table.Table (
405 Table_Component_Type => Bad_Compilation_Info,
406 Table_Index_Type => Natural,
407 Table_Low_Bound => 1,
409 Table_Increment => 100,
410 Table_Name => "Make.Bad_Compilation");
411 -- Full name of all the source files for which compilation fails
413 Do_Compile_Step : Boolean := True;
414 Do_Bind_Step : Boolean := True;
415 Do_Link_Step : Boolean := True;
416 -- Flags to indicate what step should be executed. Can be set to False
417 -- with the switches -c, -b and -l. These flags are reset to True for
418 -- each invocation of procedure Gnatmake.
420 Shared_String : aliased String := "-shared";
421 Force_Elab_Flags_String : aliased String := "-F";
423 No_Shared_Switch : aliased Argument_List := (1 .. 0 => null);
424 Shared_Switch : aliased Argument_List := (1 => Shared_String'Access);
425 Bind_Shared : Argument_List_Access := No_Shared_Switch'Access;
426 -- Switch to added in front of gnatbind switches. By default no switch is
427 -- added. Switch "-shared" is added if there is a non-static Library
430 Shared_Libgcc : aliased String := "-shared-libgcc";
432 No_Shared_Libgcc_Switch : aliased Argument_List := (1 .. 0 => null);
433 Shared_Libgcc_Switch : aliased Argument_List :=
434 (1 => Shared_Libgcc'Access);
435 Link_With_Shared_Libgcc : Argument_List_Access :=
436 No_Shared_Libgcc_Switch'Access;
438 procedure Make_Failed (S1 : String; S2 : String := ""; S3 : String := "");
439 -- Delete all temp files created by Gnatmake and call Osint.Fail,
440 -- with the parameter S1, S2 and S3 (see osint.ads).
441 -- This is called from the Prj hierarchy and the MLib hierarchy.
443 --------------------------
444 -- Obsolete Executables --
445 --------------------------
447 Executable_Obsolete : Boolean := False;
448 -- Executable_Obsolete is initially set to False for each executable,
449 -- and is set to True whenever one of the source of the executable is
450 -- compiled, or has already been compiled for another executable.
452 Max_Header : constant := 200;
453 -- This needs a proper comment, it used to say "arbitrary"
454 -- that's not an adequate comment ???
456 type Header_Num is range 1 .. Max_Header;
457 -- Header_Num for the hash table Obsoleted below
459 function Hash (F : File_Name_Type) return Header_Num;
460 -- Hash function for the hash table Obsoleted below
462 package Obsoleted is new System.HTable.Simple_HTable
463 (Header_Num => Header_Num,
466 Key => File_Name_Type,
469 -- A hash table to keep all files that have been compiled, to detect
470 -- if an executable is up to date or not.
472 procedure Enter_Into_Obsoleted (F : File_Name_Type);
473 -- Enter a file name, without directory information, into the hash table
476 function Is_In_Obsoleted (F : File_Name_Type) return Boolean;
477 -- Check if a file name, without directory information, has already been
478 -- entered into the hash table Obsoleted.
480 type Dependency is record
481 This : File_Name_Type;
482 Depends_On : File_Name_Type;
484 -- Components of table Dependencies below
486 package Dependencies is new Table.Table (
487 Table_Component_Type => Dependency,
488 Table_Index_Type => Integer,
489 Table_Low_Bound => 1,
491 Table_Increment => 100,
492 Table_Name => "Make.Dependencies");
493 -- A table to keep dependencies, to be able to decide if an executable
494 -- is obsolete. More explanation needed ???
496 -- procedure Add_Dependency (S : File_Name_Type; On : File_Name_Type);
497 -- -- Add one entry in table Dependencies
499 ----------------------------
500 -- Arguments and Switches --
501 ----------------------------
503 Arguments : Argument_List_Access;
504 -- Used to gather the arguments for invocation of the compiler
506 Last_Argument : Natural := 0;
507 -- Last index of arguments in Arguments above
509 Arguments_Collected : Boolean := False;
510 -- Set to True when the arguments for the next invocation of the compiler
511 -- have been collected.
513 Arguments_Project : Project_Id;
514 -- Project id, if any, of the source to be compiled
516 Arguments_Path_Name : Path_Name_Type;
517 -- Full path of the source to be compiled, when Arguments_Project is not
520 Dummy_Switch : constant String_Access := new String'("- ");
521 -- Used to initialized Prev_Switch in procedure Check
523 procedure Add_Arguments (Args : Argument_List);
524 -- Add arguments to global variable Arguments, increasing its size
525 -- if necessary and adjusting Last_Argument.
527 function Configuration_Pragmas_Switch
528 (For_Project : Project_Id) return Argument_List;
529 -- Return an argument list of one element, if there is a configuration
530 -- pragmas file to be specified for For_Project,
531 -- otherwise return an empty argument list.
537 procedure List_Depend;
538 -- Prints to standard output the list of object dependencies. This list
539 -- can be used directly in a Makefile. A call to Compile_Sources must
540 -- precede the call to List_Depend. Also because this routine uses the
541 -- ALI files that were originally loaded and scanned by Compile_Sources,
542 -- no additional ALI files should be scanned between the two calls (i.e.
543 -- between the call to Compile_Sources and List_Depend.)
545 procedure List_Bad_Compilations;
546 -- Prints out the list of all files for which the compilation failed
548 procedure Verbose_Msg
551 N2 : Name_Id := No_Name;
553 Prefix : String := " -> ";
554 Minimum_Verbosity : Verbosity_Level_Type := Opt.Low);
555 procedure Verbose_Msg
556 (N1 : File_Name_Type;
558 N2 : File_Name_Type := No_File;
560 Prefix : String := " -> ";
561 Minimum_Verbosity : Verbosity_Level_Type := Opt.Low);
562 -- If the verbose flag (Verbose_Mode) is set and the verbosity level is
563 -- at least equal to Minimum_Verbosity, then print Prefix to standard
564 -- output followed by N1 and S1. If N2 /= No_Name then N2 is printed after
565 -- S1. S2 is printed last. Both N1 and N2 are printed in quotation marks.
567 Usage_Needed : Boolean := True;
568 -- Flag used to make sure Makeusg is call at most once
571 -- Call Makeusg, if Usage_Needed is True.
572 -- Set Usage_Needed to False.
574 procedure Debug_Msg (S : String; N : Name_Id);
575 procedure Debug_Msg (S : String; N : File_Name_Type);
576 procedure Debug_Msg (S : String; N : Unit_Name_Type);
577 -- If Debug.Debug_Flag_W is set outputs string S followed by name N
579 procedure Recursive_Compute_Depth
580 (Project : Project_Id;
582 -- Compute depth of Project and of the projects it depends on
584 procedure Compute_All_Imported_Projects (Project : Project_Id);
585 -- Compute, the list of the projects imported directly or indirectly by
588 -----------------------
589 -- Gnatmake Routines --
590 -----------------------
592 subtype Lib_Mark_Type is Byte;
593 -- Used in Mark_Directory
595 Ada_Lib_Dir : constant Lib_Mark_Type := 1;
596 -- Used to mark a directory as a GNAT lib dir
598 -- Note that the notion of GNAT lib dir is no longer used. The code related
599 -- to it has not been removed to give an idea on how to use the directory
600 -- prefix marking mechanism.
602 -- An Ada library directory is a directory containing ali and object files
603 -- but no source files for the bodies (the specs can be in the same or some
604 -- other directory). These directories are specified in the Gnatmake
605 -- command line with the switch "-Adir" (to specify the spec location -Idir
606 -- cab be used). Gnatmake skips the missing sources whose ali are in Ada
607 -- library directories. For an explanation of why Gnatmake behaves that
608 -- way, see the spec of Make.Compile_Sources. The directory lookup penalty
609 -- is incurred every single time this routine is called.
611 procedure Check_Steps;
612 -- Check what steps (Compile, Bind, Link) must be executed.
613 -- Set the step flags accordingly.
615 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean;
616 -- Get directory prefix of this file and get lib mark stored in name
617 -- table for this directory. Then check if an Ada lib mark has been set.
619 procedure Mark_Directory
621 Mark : Lib_Mark_Type;
622 On_Command_Line : Boolean);
623 -- Store the absolute path from Dir in name table and set lib mark as name
624 -- info to identify Ada libraries.
626 -- If Dir is a relative path, when On_Command_Line is True, it is relative
627 -- to the current working directory; when On_Command_Line is False, it is
628 -- relative to the project directory of the main project.
630 Output_Is_Object : Boolean := True;
631 -- Set to False when using a switch -S for the compiler
633 procedure Check_For_S_Switch;
634 -- Set Output_Is_Object to False when the -S switch is used for the
638 (Source_File : File_Name_Type;
639 Source_File_Name : String;
641 Naming : Naming_Data;
642 In_Package : Package_Id;
643 Allow_ALI : Boolean) return Variable_Value;
644 -- Return the switches for the source file in the specified package of a
645 -- project file. If the Source_File ends with a standard GNAT extension
646 -- (".ads" or ".adb"), try first the full name, then the name without the
647 -- extension, then, if Allow_ALI is True, the name with the extension
648 -- ".ali". If there is no switches for either names, try the default
649 -- switches for Ada. If all failed, return No_Variable_Value.
651 function Is_In_Object_Directory
652 (Source_File : File_Name_Type;
653 Full_Lib_File : File_Name_Type) return Boolean;
654 -- Check if, when using a project file, the ALI file is in the project
655 -- directory of the ultimate extending project. If it is not, we ignore
656 -- the fact that this ALI file is read-only.
658 ----------------------------------------------------
659 -- Compiler, Binder & Linker Data and Subprograms --
660 ----------------------------------------------------
662 Gcc : String_Access := Program_Name ("gcc");
663 Gnatbind : String_Access := Program_Name ("gnatbind");
664 Gnatlink : String_Access := Program_Name ("gnatlink");
665 -- Default compiler, binder, linker programs
667 Saved_Gcc : String_Access := null;
668 Saved_Gnatbind : String_Access := null;
669 Saved_Gnatlink : String_Access := null;
670 -- Given by the command line. Will be used, if non null
672 Gcc_Path : String_Access :=
673 GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
674 Gnatbind_Path : String_Access :=
675 GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
676 Gnatlink_Path : String_Access :=
677 GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
678 -- Path for compiler, binder, linker programs, defaulted now for gnatdist.
679 -- Changed later if overridden on command line.
681 Comp_Flag : constant String_Access := new String'("-c");
682 Output_Flag : constant String_Access := new String'("-o");
683 Ada_Flag_1 : constant String_Access := new String'("-x");
684 Ada_Flag_2 : constant String_Access := new String'("ada");
685 No_gnat_adc : constant String_Access := new String'("-gnatA");
686 GNAT_Flag : constant String_Access := new String'("-gnatpg");
687 Do_Not_Check_Flag : constant String_Access := new String'("-x");
689 Object_Suffix : constant String := Get_Target_Object_Suffix.all;
691 Syntax_Only : Boolean := False;
692 -- Set to True when compiling with -gnats
694 Display_Executed_Programs : Boolean := True;
695 -- Set to True if name of commands should be output on stderr (or on stdout
696 -- if the Commands_To_Stdout flag was set by use of the -eS switch).
698 Output_File_Name_Seen : Boolean := False;
699 -- Set to True after having scanned the file_name for
700 -- switch "-o file_name"
702 Object_Directory_Seen : Boolean := False;
703 -- Set to True after having scanned the object directory for
704 -- switch "-D obj_dir".
706 Object_Directory_Path : String_Access := null;
707 -- The path name of the object directory, set with switch -D
709 type Make_Program_Type is (None, Compiler, Binder, Linker);
711 Program_Args : Make_Program_Type := None;
712 -- Used to indicate if we are scanning gnatmake, gcc, gnatbind, or gnatbind
713 -- options within the gnatmake command line. Used in Scan_Make_Arg only,
714 -- but must be global since value preserved from one call to another.
716 Temporary_Config_File : Boolean := False;
717 -- Set to True when there is a temporary config file used for a project
718 -- file, to avoid displaying the -gnatec switch for a temporary file.
720 procedure Add_Switches
721 (The_Package : Package_Id;
724 Program : Make_Program_Type);
727 Program : Make_Program_Type;
728 Append_Switch : Boolean := True;
729 And_Save : Boolean := True);
732 Program : Make_Program_Type;
733 Append_Switch : Boolean := True;
734 And_Save : Boolean := True);
735 -- Make invokes one of three programs (the compiler, the binder or the
736 -- linker). For the sake of convenience, some program specific switches
737 -- can be passed directly on the gnatmake command line. This procedure
738 -- records these switches so that gnatmake can pass them to the right
739 -- program. S is the switch to be added at the end of the command line
740 -- for Program if Append_Switch is True. If Append_Switch is False S is
741 -- added at the beginning of the command line.
744 (Source_File : File_Name_Type;
746 Is_Main_Source : Boolean;
747 The_Args : Argument_List;
748 Lib_File : File_Name_Type;
751 O_File : out File_Name_Type;
752 O_Stamp : out Time_Stamp_Type);
753 -- Determines whether the library file Lib_File is up-to-date or not. The
754 -- full name (with path information) of the object file corresponding to
755 -- Lib_File is returned in O_File. Its time stamp is saved in O_Stamp.
756 -- ALI is the ALI_Id corresponding to Lib_File. If Lib_File in not
757 -- up-to-date, then the corresponding source file needs to be recompiled.
758 -- In this case ALI = No_ALI_Id.
760 procedure Check_Linker_Options
761 (E_Stamp : Time_Stamp_Type;
762 O_File : out File_Name_Type;
763 O_Stamp : out Time_Stamp_Type);
764 -- Checks all linker options for linker files that are newer
765 -- than E_Stamp. If such objects are found, the youngest object
766 -- is returned in O_File and its stamp in O_Stamp.
768 -- If no obsolete linker files were found, the first missing
769 -- linker file is returned in O_File and O_Stamp is empty.
770 -- Otherwise O_File is No_File.
772 procedure Collect_Arguments
773 (Source_File : File_Name_Type;
775 Is_Main_Source : Boolean;
776 Args : Argument_List);
777 -- Collect all arguments for a source to be compiled, including those
778 -- that come from a project file.
780 procedure Display (Program : String; Args : Argument_List);
781 -- Displays Program followed by the arguments in Args if variable
782 -- Display_Executed_Programs is set. The lower bound of Args must be 1.
784 procedure Report_Compilation_Failed;
785 -- Delete all temporary files and fail graciously
791 type Temp_Path_Names is
792 array (Project_Id range <>, Positive range <>) of Path_Name_Type;
794 type Temp_Path_Ptr is access Temp_Path_Names;
796 type Indices is array (Project_Id range <>) of Natural;
798 type Indices_Ptr is access Indices;
800 type Free_File_Indices is array
801 (Project_Id range <>, Positive range <>) of Positive;
803 type Free_Indices_Ptr is access Free_File_Indices;
805 The_Mapping_File_Names : Temp_Path_Ptr;
806 -- For each project, the name ids of the temporary mapping files used
808 Last_Mapping_File_Names : Indices_Ptr;
809 -- For each project, the index of the last mapping file created
811 The_Free_Mapping_File_Indices : Free_Indices_Ptr;
812 -- For each project, the indices in The_Mapping_File_Names of the mapping
813 -- file names that can be reused for subsequent compilations.
815 Last_Free_Indices : Indices_Ptr;
816 -- For each project, the number of mapping files that can be reused
818 Gnatmake_Mapping_File : String_Access := null;
819 -- The path name of a mapping file specified by switch -C=
821 procedure Delete_Mapping_Files;
822 -- Delete all temporary mapping files. Called only in Delete_All_Temp_Files
823 -- which ensures that Debug_Flag_N is False.
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. Must not be called if Debug_Flag_N
836 procedure Delete_All_Temp_Files;
837 -- Delete all temp files (config files, mapping files, path files), unless
838 -- Debug_Flag_N is True (in which case all temp files are left for user
841 -------------------------------------------------
842 -- Subprogram declarations moved from the spec --
843 -------------------------------------------------
845 procedure Bind (ALI_File : File_Name_Type; Args : Argument_List);
846 -- Binds ALI_File. Args are the arguments to pass to the binder.
847 -- Args must have a lower bound of 1.
849 procedure Display_Commands (Display : Boolean := True);
850 -- The default behavior of Make commands (Compile_Sources, Bind, Link)
851 -- is to display them on stderr. This behavior can be changed repeatedly
852 -- by invoking this procedure.
854 -- If a compilation, bind or link failed one of the following 3 exceptions
855 -- is raised. These need to be handled by the calling routines.
857 procedure Compile_Sources
858 (Main_Source : File_Name_Type;
859 Args : Argument_List;
860 First_Compiled_File : out File_Name_Type;
861 Most_Recent_Obj_File : out File_Name_Type;
862 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
863 Main_Unit : out Boolean;
864 Compilation_Failures : out Natural;
865 Main_Index : Int := 0;
866 Check_Readonly_Files : Boolean := False;
867 Do_Not_Execute : Boolean := False;
868 Force_Compilations : Boolean := False;
869 Keep_Going : Boolean := False;
870 In_Place_Mode : Boolean := False;
871 Initialize_ALI_Data : Boolean := True;
872 Max_Process : Positive := 1);
873 -- Compile_Sources will recursively compile all the sources needed by
874 -- Main_Source. Before calling this routine make sure Namet has been
875 -- initialized. This routine can be called repeatedly with different
876 -- Main_Source file as long as all the source (-I flags), library
877 -- (-B flags) and ada library (-A flags) search paths between calls are
878 -- *exactly* the same. The default directory must also be the same.
880 -- Args contains the arguments to use during the compilations.
881 -- The lower bound of Args must be 1.
883 -- First_Compiled_File is set to the name of the first file that is
884 -- compiled or that needs to be compiled. This is set to No_Name if no
885 -- compilations were needed.
887 -- Most_Recent_Obj_File is set to the full name of the most recent
888 -- object file found when no compilations are needed, that is when
889 -- First_Compiled_File is set to No_Name. When First_Compiled_File
890 -- is set then Most_Recent_Obj_File is set to No_Name.
892 -- Most_Recent_Obj_Stamp is the time stamp of Most_Recent_Obj_File.
894 -- Main_Unit is set to True if Main_Source can be a main unit.
895 -- If Do_Not_Execute is False and First_Compiled_File /= No_Name
896 -- the value of Main_Unit is always False.
897 -- Is this used any more??? It is certainly not used by gnatmake???
899 -- Compilation_Failures is a count of compilation failures. This count
900 -- is used to extract compilation failure reports with Extract_Failure.
902 -- Main_Index, when not zero, is the index of the main unit in source
903 -- file Main_Source which is a multi-unit source.
904 -- Zero indicates that Main_Source is a single unit source file.
906 -- Check_Readonly_Files set it to True to compile source files
907 -- which library files are read-only. When compiling GNAT predefined
908 -- files the "-gnatg" flag is used.
910 -- Do_Not_Execute set it to True to find out the first source that
911 -- needs to be recompiled, but without recompiling it. This file is
912 -- saved in First_Compiled_File.
914 -- Force_Compilations forces all compilations no matter what but
915 -- recompiles read-only files only if Check_Readonly_Files
918 -- Keep_Going when True keep compiling even in the presence of
919 -- compilation errors.
921 -- In_Place_Mode when True save library/object files in their object
922 -- directory if they already exist; otherwise, in the source directory.
924 -- Initialize_ALI_Data set it to True when you want to initialize ALI
925 -- data-structures. This is what you should do most of the time.
926 -- (especially the first time around when you call this routine).
927 -- This parameter is set to False to preserve previously recorded
930 -- Max_Process is the maximum number of processes that should be spawned
931 -- to carry out compilations.
933 -- Flags in Package Opt Affecting Compile_Sources
934 -- -----------------------------------------------
936 -- Check_Object_Consistency set it to False to omit all consistency
937 -- checks between an .ali file and its corresponding object file.
938 -- When this flag is set to true, every time an .ali is read,
939 -- package Osint checks that the corresponding object file
940 -- exists and is more recent than the .ali.
942 -- Use of Name Table Info
943 -- ----------------------
945 -- All file names manipulated by Compile_Sources are entered into the
946 -- Names table. The Byte field of a source file is used to mark it.
948 -- Calling Compile_Sources Several Times
949 -- -------------------------------------
951 -- Upon return from Compile_Sources all the ALI data structures are left
952 -- intact for further browsing. HOWEVER upon entry to this routine ALI
953 -- data structures are re-initialized if parameter Initialize_ALI_Data
954 -- above is set to true. Typically this is what you want the first time
955 -- you call Compile_Sources. You should not load an ali file, call this
956 -- routine with flag Initialize_ALI_Data set to True and then expect
957 -- that ALI information to be around after the call. Note that the first
958 -- time you call Compile_Sources you better set Initialize_ALI_Data to
959 -- True unless you have called Initialize_ALI yourself.
961 -- Compile_Sources ALGORITHM : Compile_Sources (Main_Source)
962 -- -------------------------
964 -- 1. Insert Main_Source in a Queue (Q) and mark it.
966 -- 2. Let unit.adb be the file at the head of the Q. If unit.adb is
967 -- missing but its corresponding ali file is in an Ada library directory
968 -- (see below) then, remove unit.adb from the Q and goto step 4.
969 -- Otherwise, look at the files under the D (dependency) section of
970 -- unit.ali. If unit.ali does not exist or some of the time stamps do
971 -- not match, (re)compile unit.adb.
973 -- An Ada library directory is a directory containing Ada specs, ali
974 -- and object files but no source files for the bodies. An Ada library
975 -- directory is communicated to gnatmake by means of some switch so that
976 -- gnatmake can skip the sources whole ali are in that directory.
977 -- There are two reasons for skipping the sources in this case. Firstly,
978 -- Ada libraries typically come without full sources but binding and
979 -- linking against those libraries is still possible. Secondly, it would
980 -- be very wasteful for gnatmake to systematically check the consistency
981 -- of every external Ada library used in a program. The binder is
982 -- already in charge of catching any potential inconsistencies.
984 -- 3. Look into the W section of unit.ali and insert into the Q all
985 -- unmarked source files. Mark all files newly inserted in the Q.
986 -- Specifically, assuming that the W section looks like
988 -- W types%s types.adb types.ali
989 -- W unchecked_deallocation%s
990 -- W xref_tab%s xref_tab.adb xref_tab.ali
992 -- Then xref_tab.adb and types.adb are inserted in the Q if they are not
994 -- Note that there is no file listed under W unchecked_deallocation%s
995 -- so no generic body should ever be explicitly compiled (unless the
996 -- Main_Source at the start was a generic body).
998 -- 4. Repeat steps 2 and 3 above until the Q is empty
1000 -- Note that the above algorithm works because the units withed in
1001 -- subunits are transitively included in the W section (with section) of
1002 -- the main unit. Likewise the withed units in a generic body needed
1003 -- during a compilation are also transitively included in the W section
1004 -- of the originally compiled file.
1006 procedure Initialize;
1007 -- Performs default and package initialization. Therefore,
1008 -- Compile_Sources can be called by an external unit.
1011 (ALI_File : File_Name_Type;
1012 Args : Argument_List;
1013 Success : out Boolean);
1014 -- Links ALI_File. Args are the arguments to pass to the linker.
1015 -- Args must have a lower bound of 1. Success indicates if the link
1016 -- succeeded or not.
1018 procedure Scan_Make_Arg (Argv : String; And_Save : Boolean);
1019 -- Scan make arguments. Argv is a single argument to be processed
1025 procedure Add_Arguments (Args : Argument_List) is
1027 if Arguments = null then
1028 Arguments := new Argument_List (1 .. Args'Length + 10);
1031 while Last_Argument + Args'Length > Arguments'Last loop
1033 New_Arguments : constant Argument_List_Access :=
1034 new Argument_List (1 .. Arguments'Last * 2);
1036 New_Arguments (1 .. Last_Argument) :=
1037 Arguments (1 .. Last_Argument);
1038 Arguments := New_Arguments;
1043 Arguments (Last_Argument + 1 .. Last_Argument + Args'Length) := Args;
1044 Last_Argument := Last_Argument + Args'Length;
1047 -- --------------------
1048 -- -- Add_Dependency --
1049 -- --------------------
1051 -- procedure Add_Dependency (S : File_Name_Type; On : File_Name_Type) is
1053 -- Dependencies.Increment_Last;
1054 -- Dependencies.Table (Dependencies.Last) := (S, On);
1055 -- end Add_Dependency;
1057 ----------------------------
1058 -- Add_Library_Search_Dir --
1059 ----------------------------
1061 procedure Add_Library_Search_Dir
1063 On_Command_Line : Boolean)
1066 if On_Command_Line then
1067 Add_Lib_Search_Dir (Normalize_Pathname (Path));
1071 (Project_Tree.Projects.Table (Main_Project).Display_Directory);
1073 (Normalize_Pathname (Path, Name_Buffer (1 .. Name_Len)));
1075 end Add_Library_Search_Dir;
1077 --------------------
1078 -- Add_Object_Dir --
1079 --------------------
1081 procedure Add_Object_Dir (N : String) is
1083 Add_Lib_Search_Dir (N);
1085 if Verbose_Mode then
1086 Write_Str ("Adding object directory """);
1093 --------------------
1094 -- Add_Source_Dir --
1095 --------------------
1097 procedure Add_Source_Dir (N : String) is
1099 Add_Src_Search_Dir (N);
1101 if Verbose_Mode then
1102 Write_Str ("Adding source directory """);
1109 ---------------------------
1110 -- Add_Source_Search_Dir --
1111 ---------------------------
1113 procedure Add_Source_Search_Dir
1115 On_Command_Line : Boolean)
1118 if On_Command_Line then
1119 Add_Src_Search_Dir (Normalize_Pathname (Path));
1123 (Project_Tree.Projects.Table (Main_Project).Display_Directory);
1125 (Normalize_Pathname (Path, Name_Buffer (1 .. Name_Len)));
1127 end Add_Source_Search_Dir;
1133 procedure Add_Switch
1135 Program : Make_Program_Type;
1136 Append_Switch : Boolean := True;
1137 And_Save : Boolean := True)
1140 with package T is new Table.Table (<>);
1141 procedure Generic_Position (New_Position : out Integer);
1142 -- Generic procedure that chooses a position for S in T at the
1143 -- beginning or the end, depending on the boolean Append_Switch.
1144 -- Calling this procedure may expand the table.
1146 ----------------------
1147 -- Generic_Position --
1148 ----------------------
1150 procedure Generic_Position (New_Position : out Integer) is
1154 if Append_Switch then
1155 New_Position := Integer (T.Last);
1157 for J in reverse T.Table_Index_Type'Succ (T.First) .. T.Last loop
1158 T.Table (J) := T.Table (T.Table_Index_Type'Pred (J));
1161 New_Position := Integer (T.First);
1163 end Generic_Position;
1165 procedure Gcc_Switches_Pos is new Generic_Position (Gcc_Switches);
1166 procedure Binder_Switches_Pos is new Generic_Position (Binder_Switches);
1167 procedure Linker_Switches_Pos is new Generic_Position (Linker_Switches);
1169 procedure Saved_Gcc_Switches_Pos is new
1170 Generic_Position (Saved_Gcc_Switches);
1172 procedure Saved_Binder_Switches_Pos is new
1173 Generic_Position (Saved_Binder_Switches);
1175 procedure Saved_Linker_Switches_Pos is new
1176 Generic_Position (Saved_Linker_Switches);
1178 New_Position : Integer;
1180 -- Start of processing for Add_Switch
1186 Saved_Gcc_Switches_Pos (New_Position);
1187 Saved_Gcc_Switches.Table (New_Position) := S;
1190 Saved_Binder_Switches_Pos (New_Position);
1191 Saved_Binder_Switches.Table (New_Position) := S;
1194 Saved_Linker_Switches_Pos (New_Position);
1195 Saved_Linker_Switches.Table (New_Position) := S;
1198 raise Program_Error;
1204 Gcc_Switches_Pos (New_Position);
1205 Gcc_Switches.Table (New_Position) := S;
1208 Binder_Switches_Pos (New_Position);
1209 Binder_Switches.Table (New_Position) := S;
1212 Linker_Switches_Pos (New_Position);
1213 Linker_Switches.Table (New_Position) := S;
1216 raise Program_Error;
1221 procedure Add_Switch
1223 Program : Make_Program_Type;
1224 Append_Switch : Boolean := True;
1225 And_Save : Boolean := True)
1228 Add_Switch (S => new String'(S),
1230 Append_Switch => Append_Switch,
1231 And_Save => And_Save);
1238 procedure Add_Switches
1239 (The_Package : Package_Id;
1242 Program : Make_Program_Type)
1244 Switches : Variable_Value;
1245 Switch_List : String_List_Id;
1246 Element : String_Element;
1249 if File_Name'Length > 0 then
1250 Name_Len := File_Name'Length;
1251 Name_Buffer (1 .. Name_Len) := File_Name;
1254 (Source_File => Name_Find,
1255 Source_File_Name => File_Name,
1256 Source_Index => Index,
1257 Naming => Project_Tree.Projects.Table
1258 (Main_Project).Naming,
1259 In_Package => The_Package,
1261 Program = Binder or else Program = Linker);
1263 case Switches.Kind is
1268 Program_Args := Program;
1270 Switch_List := Switches.Values;
1272 while Switch_List /= Nil_String loop
1273 Element := Project_Tree.String_Elements.Table (Switch_List);
1274 Get_Name_String (Element.Value);
1276 if Name_Len > 0 then
1278 Argv : constant String := Name_Buffer (1 .. Name_Len);
1279 -- We need a copy, because Name_Buffer may be modified
1282 if Verbose_Mode then
1283 Write_Str (" Adding ");
1287 Scan_Make_Arg (Argv, And_Save => False);
1291 Switch_List := Element.Next;
1295 Program_Args := Program;
1296 Get_Name_String (Switches.Value);
1298 if Name_Len > 0 then
1300 Argv : constant String := Name_Buffer (1 .. Name_Len);
1301 -- We need a copy, because Name_Buffer may be modified
1304 if Verbose_Mode then
1305 Write_Str (" Adding ");
1309 Scan_Make_Arg (Argv, And_Save => False);
1320 procedure Bind (ALI_File : File_Name_Type; Args : Argument_List) is
1321 Bind_Args : Argument_List (1 .. Args'Last + 2);
1322 Bind_Last : Integer;
1326 pragma Assert (Args'First = 1);
1328 -- Optimize the simple case where the gnatbind command line looks like
1329 -- gnatbind -aO. -I- file.ali --into-> gnatbind file.adb
1332 and then Args (Args'First).all = "-aO" & Normalized_CWD
1333 and then Args (Args'Last).all = "-I-"
1334 and then ALI_File = Strip_Directory (ALI_File)
1336 Bind_Last := Args'First - 1;
1339 Bind_Last := Args'Last;
1340 Bind_Args (Args'Range) := Args;
1343 -- It is completely pointless to re-check source file time stamps. This
1344 -- has been done already by gnatmake
1346 Bind_Last := Bind_Last + 1;
1347 Bind_Args (Bind_Last) := Do_Not_Check_Flag;
1349 Get_Name_String (ALI_File);
1351 Bind_Last := Bind_Last + 1;
1352 Bind_Args (Bind_Last) := new String'(Name_Buffer (1 .. Name_Len));
1354 GNAT.OS_Lib.Normalize_Arguments (Bind_Args (Args'First .. Bind_Last));
1356 Display (Gnatbind.all, Bind_Args (Args'First .. Bind_Last));
1358 if Gnatbind_Path = null then
1359 Make_Failed ("error, unable to locate ", Gnatbind.all);
1363 (Gnatbind_Path.all, Bind_Args (Args'First .. Bind_Last), Success);
1366 Make_Failed ("*** bind failed.");
1370 --------------------------------
1371 -- Change_To_Object_Directory --
1372 --------------------------------
1374 procedure Change_To_Object_Directory (Project : Project_Id) is
1375 Actual_Project : Project_Id;
1376 Object_Directory : Path_Name_Type;
1379 -- For sources outside of any project, compilation occurs in the object
1380 -- directory of the main project, otherwise we use the project given.
1382 if Project = No_Project then
1383 Actual_Project := Main_Project;
1385 Actual_Project := Project;
1388 -- Nothing to do if the current working directory is already the correct
1389 -- object directory.
1391 if Project_Of_Current_Object_Directory /= Actual_Project then
1392 Project_Of_Current_Object_Directory := Actual_Project;
1394 Project_Tree.Projects.Table (Actual_Project).Object_Directory;
1396 -- Set the working directory to the object directory of the actual
1399 if Verbose_Mode then
1400 Write_Str ("Changing to object directory of """);
1402 (Project_Tree.Projects.Table (Actual_Project).Display_Name);
1403 Write_Str (""": """);
1404 Write_Name (Object_Directory);
1408 Change_Dir (Get_Name_String (Object_Directory));
1412 -- Fail if unable to change to the object directory
1414 when Directory_Error =>
1415 Make_Failed ("unable to change to object directory """ &
1417 (Project_Tree.Projects.Table
1418 (Actual_Project).Object_Directory) &
1420 Get_Name_String (Project_Tree.Projects.Table
1421 (Actual_Project).Display_Name));
1422 end Change_To_Object_Directory;
1429 (Source_File : File_Name_Type;
1431 Is_Main_Source : Boolean;
1432 The_Args : Argument_List;
1433 Lib_File : File_Name_Type;
1434 Read_Only : Boolean;
1436 O_File : out File_Name_Type;
1437 O_Stamp : out Time_Stamp_Type)
1439 function First_New_Spec (A : ALI_Id) return File_Name_Type;
1440 -- Looks in the with table entries of A and returns the spec file name
1441 -- of the first withed unit (subprogram) for which no spec existed when
1442 -- A was generated but for which there exists one now, implying that A
1443 -- is now obsolete. If no such unit is found No_File is returned.
1444 -- Otherwise the spec file name of the unit is returned.
1446 -- **WARNING** in the event of Uname format modifications, one *MUST*
1447 -- make sure this function is also updated.
1449 -- Note: This function should really be in ali.adb and use Uname
1450 -- services, but this causes the whole compiler to be dragged along
1451 -- for gnatbind and gnatmake.
1453 --------------------
1454 -- First_New_Spec --
1455 --------------------
1457 function First_New_Spec (A : ALI_Id) return File_Name_Type is
1458 Spec_File_Name : File_Name_Type := No_File;
1460 function New_Spec (Uname : Unit_Name_Type) return Boolean;
1461 -- Uname is the name of the spec or body of some ada unit. This
1462 -- function returns True if the Uname is the name of a body which has
1463 -- a spec not mentioned in ALI file A. If True is returned
1464 -- Spec_File_Name above is set to the name of this spec file.
1470 function New_Spec (Uname : Unit_Name_Type) return Boolean is
1471 Spec_Name : Unit_Name_Type;
1472 File_Name : File_Name_Type;
1475 -- Test whether Uname is the name of a body unit (i.e. ends
1478 Get_Name_String (Uname);
1480 Assert (Name_Len > 2 and then Name_Buffer (Name_Len - 1) = '%');
1482 if Name_Buffer (Name_Len) /= 'b' then
1486 -- Convert unit name into spec name
1488 -- ??? this code seems dubious in presence of pragma
1489 -- Source_File_Name since there is no more direct relationship
1490 -- between unit name and file name.
1492 -- ??? Further, what about alternative subunit naming
1494 Name_Buffer (Name_Len) := 's';
1495 Spec_Name := Name_Find;
1496 File_Name := Get_File_Name (Spec_Name, Subunit => False);
1498 -- Look if File_Name is mentioned in A's sdep list.
1499 -- If not look if the file exists. If it does return True.
1502 ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep
1504 if Sdep.Table (D).Sfile = File_Name then
1509 if Full_Source_Name (File_Name) /= No_File then
1510 Spec_File_Name := File_Name;
1517 -- Start of processing for First_New_Spec
1521 ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit
1523 exit U_Chk when Units.Table (U).Utype = Is_Body_Only
1524 and then New_Spec (Units.Table (U).Uname);
1526 for W in Units.Table (U).First_With
1528 Units.Table (U).Last_With
1531 Withs.Table (W).Afile /= No_File
1532 and then New_Spec (Withs.Table (W).Uname);
1536 return Spec_File_Name;
1539 ---------------------------------
1540 -- Data declarations for Check --
1541 ---------------------------------
1543 Full_Lib_File : File_Name_Type;
1544 -- Full name of current library file
1546 Full_Obj_File : File_Name_Type;
1547 -- Full name of the object file corresponding to Lib_File
1549 Lib_Stamp : Time_Stamp_Type;
1550 -- Time stamp of the current ada library file
1552 Obj_Stamp : Time_Stamp_Type;
1553 -- Time stamp of the current object file
1555 Modified_Source : File_Name_Type;
1556 -- The first source in Lib_File whose current time stamp differs
1557 -- from that stored in Lib_File.
1559 New_Spec : File_Name_Type;
1560 -- If Lib_File contains in its W (with) section a body (for a
1561 -- subprogram) for which there exists a spec and the spec did not
1562 -- appear in the Sdep section of Lib_File, New_Spec contains the file
1563 -- name of this new spec.
1565 Source_Name : File_Name_Type;
1566 Text : Text_Buffer_Ptr;
1568 Prev_Switch : String_Access;
1569 -- Previous switch processed
1571 Arg : Arg_Id := Arg_Id'First;
1572 -- Current index in Args.Table for a given unit (init to stop warning)
1574 Switch_Found : Boolean;
1575 -- True if a given switch has been found
1577 ALI_Project : Project_Id;
1578 -- If the ALI file is in the object directory of a project, this is
1581 -- Start of processing for Check
1584 pragma Assert (Lib_File /= No_File);
1586 -- If ALI file is read-only, temporarily set Check_Object_Consistency to
1587 -- False. We don't care if the object file is not there (presumably a
1588 -- library will be used for linking.)
1592 Saved_Check_Object_Consistency : constant Boolean :=
1593 Check_Object_Consistency;
1595 Check_Object_Consistency := False;
1596 Text := Read_Library_Info (Lib_File);
1597 Check_Object_Consistency := Saved_Check_Object_Consistency;
1601 Text := Read_Library_Info (Lib_File);
1604 Full_Lib_File := Full_Library_Info_Name;
1605 Full_Obj_File := Full_Object_File_Name;
1606 Lib_Stamp := Current_Library_File_Stamp;
1607 Obj_Stamp := Current_Object_File_Stamp;
1609 if Full_Lib_File = No_File then
1612 "being checked ...",
1614 Minimum_Verbosity => Opt.Medium);
1618 "being checked ...",
1620 Minimum_Verbosity => Opt.Medium);
1624 O_File := Full_Obj_File;
1625 O_Stamp := Obj_Stamp;
1628 if Full_Lib_File = No_File then
1629 Verbose_Msg (Lib_File, "missing.");
1631 elsif Obj_Stamp (Obj_Stamp'First) = ' ' then
1632 Verbose_Msg (Full_Obj_File, "missing.");
1636 (Full_Lib_File, "(" & String (Lib_Stamp) & ") newer than",
1637 Full_Obj_File, "(" & String (Obj_Stamp) & ")");
1641 ALI := Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
1644 if ALI = No_ALI_Id then
1645 Verbose_Msg (Full_Lib_File, "incorrectly formatted ALI file");
1648 elsif ALIs.Table (ALI).Ver (1 .. ALIs.Table (ALI).Ver_Len) /=
1649 Verbose_Library_Version
1651 Verbose_Msg (Full_Lib_File, "compiled with old GNAT version");
1656 -- Don't take Ali file into account if it was generated with
1659 if ALIs.Table (ALI).Compile_Errors then
1660 Verbose_Msg (Full_Lib_File, "had errors, must be recompiled");
1665 -- Don't take Ali file into account if it was generated without
1668 if Operating_Mode /= Check_Semantics
1669 and then ALIs.Table (ALI).No_Object
1671 Verbose_Msg (Full_Lib_File, "has no corresponding object");
1676 -- Check for matching compiler switches if needed
1678 if Check_Switches then
1680 -- First, collect all the switches
1683 (Source_File, Source_Index, Is_Main_Source, The_Args);
1685 Prev_Switch := Dummy_Switch;
1687 Get_Name_String (ALIs.Table (ALI).Sfile);
1689 Switches_To_Check.Set_Last (0);
1691 for J in 1 .. Last_Argument loop
1693 -- Skip non switches -c, -I and -o switches
1695 if Arguments (J) (1) = '-'
1696 and then Arguments (J) (2) /= 'c'
1697 and then Arguments (J) (2) /= 'o'
1698 and then Arguments (J) (2) /= 'I'
1700 Normalize_Compiler_Switches
1702 Normalized_Switches,
1705 for K in 1 .. Last_Norm_Switch loop
1706 Switches_To_Check.Increment_Last;
1707 Switches_To_Check.Table (Switches_To_Check.Last) :=
1708 Normalized_Switches (K);
1713 for J in 1 .. Switches_To_Check.Last loop
1715 -- Comparing switches is delicate because gcc reorders a number
1716 -- of switches, according to lang-specs.h, but gnatmake doesn't
1717 -- have sufficient knowledge to perform the same reordering.
1718 -- Instead, we ignore orders between different "first letter"
1719 -- switches, but keep orders between same switches, e.g -O -O2
1720 -- is different than -O2 -O, but -g -O is equivalent to -O -g.
1722 if Switches_To_Check.Table (J) (2) /= Prev_Switch (2) or else
1723 (Prev_Switch'Length >= 6 and then
1724 Prev_Switch (2 .. 5) = "gnat" and then
1725 Switches_To_Check.Table (J)'Length >= 6 and then
1726 Switches_To_Check.Table (J) (2 .. 5) = "gnat" and then
1727 Prev_Switch (6) /= Switches_To_Check.Table (J) (6))
1729 Prev_Switch := Switches_To_Check.Table (J);
1731 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg;
1734 Switch_Found := False;
1737 Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1740 Switches_To_Check.Table (J).all = Args.Table (K).all
1743 Switch_Found := True;
1748 if not Switch_Found then
1749 if Verbose_Mode then
1750 Verbose_Msg (ALIs.Table (ALI).Sfile,
1751 "switch mismatch """ &
1752 Switches_To_Check.Table (J).all & '"');
1760 if Switches_To_Check.Last /=
1761 Integer (Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg -
1762 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg + 1)
1764 if Verbose_Mode then
1765 Verbose_Msg (ALIs.Table (ALI).Sfile,
1766 "different number of switches");
1768 for K in Units.Table (ALIs.Table (ALI).First_Unit).First_Arg
1769 .. Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1771 Write_Str (Args.Table (K).all);
1777 for J in 1 .. Switches_To_Check.Last loop
1778 Write_Str (Switches_To_Check.Table (J).all);
1790 -- Get the source files and their message digests. Note that some
1791 -- sources may be missing if ALI is out-of-date.
1793 Set_Source_Table (ALI);
1795 Modified_Source := Time_Stamp_Mismatch (ALI, Read_Only);
1797 if Modified_Source /= No_File then
1800 if Verbose_Mode then
1801 Source_Name := Full_Source_Name (Modified_Source);
1803 if Source_Name /= No_File then
1804 Verbose_Msg (Source_Name, "time stamp mismatch");
1806 Verbose_Msg (Modified_Source, "missing");
1811 New_Spec := First_New_Spec (ALI);
1813 if New_Spec /= No_File then
1816 if Verbose_Mode then
1817 Source_Name := Full_Source_Name (New_Spec);
1819 if Source_Name /= No_File then
1820 Verbose_Msg (Source_Name, "new spec");
1822 Verbose_Msg (New_Spec, "old spec missing");
1826 elsif Main_Project /= No_Project then
1828 -- Check if a file name does not correspond to the mapping of
1829 -- units to file names.
1833 Unit_Name : Name_Id;
1834 UID : Prj.Unit_Index;
1839 for U in ALIs.Table (ALI).First_Unit ..
1840 ALIs.Table (ALI).Last_Unit
1843 for W in Units.Table (U).First_With
1845 Units.Table (U).Last_With
1847 WR := Withs.Table (W);
1849 if WR.Sfile /= No_File then
1850 Get_Name_String (WR.Uname);
1851 Name_Len := Name_Len - 2;
1852 Unit_Name := Name_Find;
1854 UID := Units_Htable.Get
1855 (Project_Tree.Units_HT, Unit_Name);
1857 if UID /= Prj.No_Unit_Index then
1858 U_Data := Project_Tree.Units.Table (UID);
1860 if U_Data.File_Names (Body_Part).Name /= WR.Sfile
1862 U_Data.File_Names (Specification).Name /=
1868 (Unit_Name, " sources does not include ",
1869 Name_Id (WR.Sfile));
1879 -- Check that the ALI file is in the correct object directory.
1880 -- If it is in the object directory of a project that is
1881 -- extended and it depends on a source that is in one of its
1882 -- extending projects, then the ALI file is not in the correct
1883 -- object directory.
1885 -- First, find the project of this ALI file. As there may be
1886 -- several projects with the same object directory, we first
1887 -- need to find the project of the source.
1889 ALI_Project := No_Project;
1892 Udata : Prj.Unit_Data;
1895 for U in 1 .. Unit_Table.Last (Project_Tree.Units) loop
1896 Udata := Project_Tree.Units.Table (U);
1898 if Udata.File_Names (Body_Part).Name = Source_File then
1899 ALI_Project := Udata.File_Names (Body_Part).Project;
1903 Udata.File_Names (Specification).Name = Source_File
1906 Udata.File_Names (Specification).Project;
1912 if ALI_Project = No_Project then
1917 Obj_Dir : Path_Name_Type;
1918 Res_Obj_Dir : constant String :=
1921 (Get_Name_String (Full_Lib_File)),
1922 Resolve_Links => True,
1923 Case_Sensitive => False);
1927 Add_Str_To_Name_Buffer (Res_Obj_Dir);
1929 if Name_Len > 1 and then
1930 (Name_Buffer (Name_Len) = '/' or else
1931 Name_Buffer (Name_Len) = Directory_Separator)
1933 Name_Len := Name_Len - 1;
1936 Obj_Dir := Name_Find;
1938 while ALI_Project /= No_Project and then
1940 Project_Tree.Projects.Table
1941 (ALI_Project).Object_Directory
1944 Project_Tree.Projects.Table (ALI_Project).Extended_By;
1948 if ALI_Project = No_Project then
1952 (Lib_File, " wrong object directory");
1956 -- If the ALI project is not extended, then it must be in
1957 -- the correct object directory.
1959 if Project_Tree.Projects.Table (ALI_Project).Extended_By =
1965 -- Count the extending projects
1973 Proj := ALI_Project;
1975 Proj := Project_Tree.Projects.Table (Proj).Extended_By;
1976 exit when Proj = No_Project;
1977 Num_Ext := Num_Ext + 1;
1980 -- Make a list of the extending projects
1983 Projects : array (1 .. Num_Ext) of Project_Id;
1985 OK : Boolean := True;
1988 Proj := ALI_Project;
1989 for J in Projects'Range loop
1990 Proj := Project_Tree.Projects.Table (Proj).Extended_By;
1991 Projects (J) := Proj;
1994 -- Now check if any of the dependant sources are in
1995 -- any of these extending projects.
1998 for D in ALIs.Table (ALI).First_Sdep ..
1999 ALIs.Table (ALI).Last_Sdep
2001 Dep := Sdep.Table (D);
2007 UID in 1 .. Unit_Table.Last (Project_Tree.Units)
2009 if Project_Tree.Units.Table (UID).
2010 File_Names (Body_Part).Name = Dep.Sfile
2012 Proj := Project_Tree.Units.Table (UID).
2013 File_Names (Body_Part).Project;
2015 elsif Project_Tree.Units.Table (UID).
2016 File_Names (Specification).Name = Dep.Sfile
2018 Proj := Project_Tree.Units.Table (UID).
2019 File_Names (Specification).Project;
2022 -- If a source is in a project, check if it is one
2025 if Proj /= No_Project then
2026 for J in Projects'Range loop
2027 if Proj = Projects (J) then
2038 -- If one of the dependent sources is in one project of
2039 -- the list, then we must recompile.
2043 Verbose_Msg (Lib_File, " wrong object directory");
2052 ------------------------
2053 -- Check_For_S_Switch --
2054 ------------------------
2056 procedure Check_For_S_Switch is
2058 -- By default, we generate an object file
2060 Output_Is_Object := True;
2062 for Arg in 1 .. Last_Argument loop
2063 if Arguments (Arg).all = "-S" then
2064 Output_Is_Object := False;
2066 elsif Arguments (Arg).all = "-c" then
2067 Output_Is_Object := True;
2070 end Check_For_S_Switch;
2072 --------------------------
2073 -- Check_Linker_Options --
2074 --------------------------
2076 procedure Check_Linker_Options
2077 (E_Stamp : Time_Stamp_Type;
2078 O_File : out File_Name_Type;
2079 O_Stamp : out Time_Stamp_Type)
2081 procedure Check_File (File : File_Name_Type);
2082 -- Update O_File and O_Stamp if the given file is younger than E_Stamp
2083 -- and O_Stamp, or if O_File is No_File and File does not exist.
2085 function Get_Library_File (Name : String) return File_Name_Type;
2086 -- Return the full file name including path of a library based
2087 -- on the name specified with the -l linker option, using the
2088 -- Ada object path. Return No_File if no such file can be found.
2090 type Char_Array is array (Natural) of Character;
2091 type Char_Array_Access is access constant Char_Array;
2093 Template : Char_Array_Access;
2094 pragma Import (C, Template, "__gnat_library_template");
2100 procedure Check_File (File : File_Name_Type) is
2101 Stamp : Time_Stamp_Type;
2102 Name : File_Name_Type := File;
2105 Get_Name_String (Name);
2107 -- Remove any trailing NUL characters
2109 while Name_Len >= Name_Buffer'First
2110 and then Name_Buffer (Name_Len) = NUL
2112 Name_Len := Name_Len - 1;
2115 if Name_Len = 0 then
2118 elsif Name_Buffer (1) = '-' then
2120 -- Do not check if File is a switch other than "-l"
2122 if Name_Buffer (2) /= 'l' then
2126 -- The argument is a library switch, get actual name. It
2127 -- is necessary to make a copy of the relevant part of
2128 -- Name_Buffer as Get_Library_Name uses Name_Buffer as well.
2131 Base_Name : constant String := Name_Buffer (3 .. Name_Len);
2134 Name := Get_Library_File (Base_Name);
2137 if Name = No_File then
2142 Stamp := File_Stamp (Name);
2144 -- Find the youngest object file that is younger than the
2145 -- executable. If no such file exist, record the first object
2146 -- file that is not found.
2148 if (O_Stamp < Stamp and then E_Stamp < Stamp)
2149 or else (O_File = No_File and then Stamp (Stamp'First) = ' ')
2154 -- Strip the trailing NUL if present
2156 Get_Name_String (O_File);
2158 if Name_Buffer (Name_Len) = NUL then
2159 Name_Len := Name_Len - 1;
2160 O_File := Name_Find;
2165 ----------------------
2166 -- Get_Library_Name --
2167 ----------------------
2169 -- See comments in a-adaint.c about template syntax
2171 function Get_Library_File (Name : String) return File_Name_Type is
2172 File : File_Name_Type := No_File;
2177 for Ptr in Template'Range loop
2178 case Template (Ptr) is
2180 Add_Str_To_Name_Buffer (Name);
2183 File := Full_Lib_File_Name (Name_Find);
2184 exit when File /= No_File;
2191 Add_Char_To_Name_Buffer (Template (Ptr));
2195 -- The for loop exited because the end of the template
2196 -- was reached. File contains the last possible file name
2199 if File = No_File and then Name_Len > 0 then
2200 File := Full_Lib_File_Name (Name_Find);
2204 end Get_Library_File;
2206 -- Start of processing for Check_Linker_Options
2210 O_Stamp := (others => ' ');
2212 -- Process linker options from the ALI files
2214 for Opt in 1 .. Linker_Options.Last loop
2215 Check_File (File_Name_Type (Linker_Options.Table (Opt).Name));
2218 -- Process options given on the command line
2220 for Opt in Linker_Switches.First .. Linker_Switches.Last loop
2222 -- Check if the previous Opt has one of the two switches
2223 -- that take an extra parameter. (See GCC manual.)
2225 if Opt = Linker_Switches.First
2226 or else (Linker_Switches.Table (Opt - 1).all /= "-u"
2228 Linker_Switches.Table (Opt - 1).all /= "-Xlinker"
2230 Linker_Switches.Table (Opt - 1).all /= "-L")
2233 Add_Str_To_Name_Buffer (Linker_Switches.Table (Opt).all);
2234 Check_File (Name_Find);
2238 end Check_Linker_Options;
2244 procedure Check_Steps is
2246 -- If either -c, -b or -l has been specified, we will not necessarily
2247 -- execute all steps.
2250 Do_Compile_Step := Do_Compile_Step and Compile_Only;
2251 Do_Bind_Step := Do_Bind_Step and Bind_Only;
2252 Do_Link_Step := Do_Link_Step and Link_Only;
2254 -- If -c has been specified, but not -b, ignore any potential -l
2256 if Do_Compile_Step and then not Do_Bind_Step then
2257 Do_Link_Step := False;
2262 -----------------------
2263 -- Collect_Arguments --
2264 -----------------------
2266 procedure Collect_Arguments
2267 (Source_File : File_Name_Type;
2269 Is_Main_Source : Boolean;
2270 Args : Argument_List)
2273 Arguments_Collected := True;
2274 Arguments_Project := No_Project;
2276 Add_Arguments (Args);
2278 if Main_Project /= No_Project then
2280 Source_File_Name : constant String :=
2281 Get_Name_String (Source_File);
2282 Compiler_Package : Prj.Package_Id;
2283 Switches : Prj.Variable_Value;
2284 Data : Project_Data;
2289 (Source_File_Name => Source_File_Name,
2290 Project => Arguments_Project,
2291 Path => Arguments_Path_Name,
2292 In_Tree => Project_Tree);
2294 -- If the source is not a source of a project file, add the
2295 -- recorded arguments. Check will be done later if the source
2296 -- need to be compiled that the switch -x has been used.
2298 if Arguments_Project = No_Project then
2299 Add_Arguments (The_Saved_Gcc_Switches.all);
2301 elsif not Project_Tree.Projects.Table
2302 (Arguments_Project).Externally_Built
2304 -- We get the project directory for the relative path
2305 -- switches and arguments.
2307 Data := Project_Tree.Projects.Table (Arguments_Project);
2309 -- If the source is in an extended project, we go to
2310 -- the ultimate extending project.
2312 while Data.Extended_By /= No_Project loop
2313 Arguments_Project := Data.Extended_By;
2314 Data := Project_Tree.Projects.Table (Arguments_Project);
2317 -- If building a dynamic or relocatable library, compile with
2318 -- PIC option, if it exists.
2320 if Data.Library and then Data.Library_Kind /= Static then
2322 PIC : constant String := MLib.Tgt.PIC_Option;
2326 Add_Arguments ((1 => new String'(PIC)));
2331 if Data.Dir_Path = null then
2333 new String'(Get_Name_String (Data.Display_Directory));
2334 Project_Tree.Projects.Table (Arguments_Project) :=
2338 -- We now look for package Compiler and get the switches from
2343 (Name => Name_Compiler,
2344 In_Packages => Data.Decl.Packages,
2345 In_Tree => Project_Tree);
2347 if Compiler_Package /= No_Package then
2349 -- If package Gnatmake.Compiler exists, we get the specific
2350 -- switches for the current source, or the global switches,
2355 (Source_File => Source_File,
2356 Source_File_Name => Source_File_Name,
2357 Source_Index => Source_Index,
2358 Naming => Data.Naming,
2359 In_Package => Compiler_Package,
2360 Allow_ALI => False);
2364 case Switches.Kind is
2366 -- We have a list of switches. We add these switches,
2367 -- plus the saved gcc switches.
2372 Current : String_List_Id := Switches.Values;
2373 Element : String_Element;
2374 Number : Natural := 0;
2377 while Current /= Nil_String loop
2378 Element := Project_Tree.String_Elements.
2380 Number := Number + 1;
2381 Current := Element.Next;
2385 New_Args : Argument_List (1 .. Number);
2386 Last_New : Natural := 0;
2389 Current := Switches.Values;
2391 for Index in New_Args'Range loop
2392 Element := Project_Tree.String_Elements.
2394 Get_Name_String (Element.Value);
2396 if Name_Len > 0 then
2397 Last_New := Last_New + 1;
2398 New_Args (Last_New) :=
2399 new String'(Name_Buffer (1 .. Name_Len));
2400 Test_If_Relative_Path
2401 (New_Args (Last_New),
2402 Parent => Data.Dir_Path,
2403 Including_Non_Switch => False);
2406 Current := Element.Next;
2410 (Configuration_Pragmas_Switch
2411 (Arguments_Project) &
2412 New_Args (1 .. Last_New) &
2413 The_Saved_Gcc_Switches.all);
2417 -- We have a single switch. We add this switch,
2418 -- plus the saved gcc switches.
2421 Get_Name_String (Switches.Value);
2424 New_Args : Argument_List :=
2426 (Name_Buffer (1 .. Name_Len)));
2429 Test_If_Relative_Path
2431 Parent => Data.Dir_Path,
2432 Including_Non_Switch => False);
2434 (Configuration_Pragmas_Switch (Arguments_Project) &
2435 New_Args & The_Saved_Gcc_Switches.all);
2438 -- We have no switches from Gnatmake.Compiler.
2439 -- We add the saved gcc switches.
2443 (Configuration_Pragmas_Switch (Arguments_Project) &
2444 The_Saved_Gcc_Switches.all);
2450 -- For VMS, when compiling the main source, add switch
2451 -- -mdebug-main=_ada_ so that the executable can be debugged
2452 -- by the standard VMS debugger.
2454 if not No_Main_Subprogram
2455 and then Targparm.OpenVMS_On_Target
2456 and then Is_Main_Source
2458 -- First, check if compilation will be invoked with -g
2460 for J in 1 .. Last_Argument loop
2461 if Arguments (J)'Length >= 2
2462 and then Arguments (J) (1 .. 2) = "-g"
2463 and then (Arguments (J)'Length < 5
2464 or else Arguments (J) (1 .. 5) /= "-gnat")
2467 ((1 => new String'("-mdebug-main=_ada_")));
2473 -- Set Output_Is_Object, depending if there is a -S switch.
2474 -- If the bind step is not performed, and there is a -S switch,
2475 -- then we will not check for a valid object file.
2478 end Collect_Arguments;
2480 ---------------------
2481 -- Compile_Sources --
2482 ---------------------
2484 procedure Compile_Sources
2485 (Main_Source : File_Name_Type;
2486 Args : Argument_List;
2487 First_Compiled_File : out File_Name_Type;
2488 Most_Recent_Obj_File : out File_Name_Type;
2489 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
2490 Main_Unit : out Boolean;
2491 Compilation_Failures : out Natural;
2492 Main_Index : Int := 0;
2493 Check_Readonly_Files : Boolean := False;
2494 Do_Not_Execute : Boolean := False;
2495 Force_Compilations : Boolean := False;
2496 Keep_Going : Boolean := False;
2497 In_Place_Mode : Boolean := False;
2498 Initialize_ALI_Data : Boolean := True;
2499 Max_Process : Positive := 1)
2501 Source_Unit : Unit_Name_Type;
2502 -- Current source unit
2504 Source_File : File_Name_Type;
2505 -- Current source file
2507 Full_Source_File : File_Name_Type;
2508 -- Full name of the current source file
2510 Lib_File : File_Name_Type;
2511 -- Current library file
2513 Full_Lib_File : File_Name_Type;
2514 -- Full name of the current library file
2516 Obj_File : File_Name_Type;
2517 -- Full name of the object file corresponding to Lib_File
2519 Obj_Stamp : Time_Stamp_Type;
2520 -- Time stamp of the current object file
2522 Sfile : File_Name_Type;
2523 -- Contains the source file of the units withed by Source_File
2525 Uname : Unit_Name_Type;
2526 -- Contains the unit name of the units withed by Source_File
2529 -- ALI Id of the current ALI file
2531 -- Comment following declarations ???
2533 Read_Only : Boolean := False;
2535 Compilation_OK : Boolean;
2536 Need_To_Compile : Boolean;
2539 Text : Text_Buffer_Ptr;
2541 Mfile : Natural := No_Mapping_File;
2543 Need_To_Check_Standard_Library : Boolean :=
2544 Check_Readonly_Files
2545 and not Unique_Compile;
2547 Mapping_File_Arg : String_Access;
2549 Process_Created : Boolean := False;
2551 procedure Add_Process
2553 Sfile : File_Name_Type;
2554 Afile : File_Name_Type;
2555 Uname : Unit_Name_Type;
2556 Mfile : Natural := No_Mapping_File);
2557 -- Adds process Pid to the current list of outstanding compilation
2558 -- processes and record the full name of the source file Sfile that
2559 -- we are compiling, the name of its library file Afile and the
2560 -- name of its unit Uname. If Mfile is not equal to No_Mapping_File,
2561 -- it is the index of the mapping file used during compilation in the
2562 -- array The_Mapping_File_Names.
2564 procedure Await_Compile
2565 (Sfile : out File_Name_Type;
2566 Afile : out File_Name_Type;
2567 Uname : out Unit_Name_Type;
2569 -- Awaits that an outstanding compilation process terminates. When
2570 -- it does set Sfile to the name of the source file that was compiled
2571 -- Afile to the name of its library file and Uname to the name of its
2572 -- unit. Note that this time stamp can be used to check whether the
2573 -- compilation did generate an object file. OK is set to True if the
2574 -- compilation succeeded. Note that Sfile, Afile and Uname could be
2575 -- resp. No_File, No_File and No_Name if there were no compilations
2578 function Bad_Compilation_Count return Natural;
2579 -- Returns the number of compilation failures
2581 procedure Check_Standard_Library;
2582 -- Check if s-stalib.adb needs to be compiled
2584 procedure Collect_Arguments_And_Compile
2585 (Source_File : File_Name_Type;
2586 Source_Index : Int);
2587 -- Collect arguments from project file (if any) and compile
2590 (S : File_Name_Type;
2593 Args : Argument_List) return Process_Id;
2594 -- Compiles S using Args. If S is a GNAT predefined source "-gnatpg" is
2595 -- added to Args. Non blocking call. L corresponds to the expected
2596 -- library file name. Process_Id of the process spawned to execute the
2599 package Good_ALI is new Table.Table (
2600 Table_Component_Type => ALI_Id,
2601 Table_Index_Type => Natural,
2602 Table_Low_Bound => 1,
2603 Table_Initial => 50,
2604 Table_Increment => 100,
2605 Table_Name => "Make.Good_ALI");
2606 -- Contains the set of valid ALI files that have not yet been scanned
2608 function Good_ALI_Present return Boolean;
2609 -- Returns True if any ALI file was recorded in the previous set
2611 procedure Get_Mapping_File (Project : Project_Id);
2612 -- Get a mapping file name. If there is one to be reused, reuse it.
2613 -- Otherwise, create a new mapping file.
2615 function Get_Next_Good_ALI return ALI_Id;
2616 -- Returns the next good ALI_Id record
2618 procedure Record_Failure
2619 (File : File_Name_Type;
2620 Unit : Unit_Name_Type;
2621 Found : Boolean := True);
2622 -- Records in the previous table that the compilation for File failed.
2623 -- If Found is False then the compilation of File failed because we
2624 -- could not find it. Records also Unit when possible.
2626 procedure Record_Good_ALI (A : ALI_Id);
2627 -- Records in the previous set the Id of an ALI file
2633 procedure Add_Process
2635 Sfile : File_Name_Type;
2636 Afile : File_Name_Type;
2637 Uname : Unit_Name_Type;
2638 Mfile : Natural := No_Mapping_File)
2640 OC1 : constant Positive := Outstanding_Compiles + 1;
2643 pragma Assert (OC1 <= Max_Process);
2644 pragma Assert (Pid /= Invalid_Pid);
2646 Running_Compile (OC1).Pid := Pid;
2647 Running_Compile (OC1).Full_Source_File := Sfile;
2648 Running_Compile (OC1).Lib_File := Afile;
2649 Running_Compile (OC1).Source_Unit := Uname;
2650 Running_Compile (OC1).Mapping_File := Mfile;
2651 Running_Compile (OC1).Project := Arguments_Project;
2652 Running_Compile (OC1).Syntax_Only := Syntax_Only;
2653 Running_Compile (OC1).Output_Is_Object := Output_Is_Object;
2655 Outstanding_Compiles := OC1;
2658 --------------------
2662 procedure Await_Compile
2663 (Sfile : out File_Name_Type;
2664 Afile : out File_Name_Type;
2665 Uname : out Unit_Name_Type;
2669 Project : Project_Id;
2672 pragma Assert (Outstanding_Compiles > 0);
2676 Uname := No_Unit_Name;
2679 -- The loop here is a work-around for a problem on VMS; in some
2680 -- circumstances (shared library and several executables, for
2681 -- example), there are child processes other than compilation
2682 -- processes that are received. Until this problem is resolved,
2683 -- we will ignore such processes.
2686 Wait_Process (Pid, OK);
2688 if Pid = Invalid_Pid then
2692 for J in Running_Compile'First .. Outstanding_Compiles loop
2693 if Pid = Running_Compile (J).Pid then
2694 Sfile := Running_Compile (J).Full_Source_File;
2695 Afile := Running_Compile (J).Lib_File;
2696 Uname := Running_Compile (J).Source_Unit;
2697 Syntax_Only := Running_Compile (J).Syntax_Only;
2698 Output_Is_Object := Running_Compile (J).Output_Is_Object;
2699 Project := Running_Compile (J).Project;
2701 -- If a mapping file was used by this compilation,
2702 -- get its file name for reuse by a subsequent compilation
2704 if Running_Compile (J).Mapping_File /= No_Mapping_File then
2705 Last_Free_Indices (Project) :=
2706 Last_Free_Indices (Project) + 1;
2707 The_Free_Mapping_File_Indices
2708 (Project, Last_Free_Indices (Project)) :=
2709 Running_Compile (J).Mapping_File;
2712 -- To actually remove this Pid and related info from
2713 -- Running_Compile replace its entry with the last valid
2714 -- entry in Running_Compile.
2716 if J = Outstanding_Compiles then
2720 Running_Compile (J) :=
2721 Running_Compile (Outstanding_Compiles);
2724 Outstanding_Compiles := Outstanding_Compiles - 1;
2729 -- This child process was not one of our compilation processes;
2730 -- just ignore it for now.
2732 -- raise Program_Error;
2736 ---------------------------
2737 -- Bad_Compilation_Count --
2738 ---------------------------
2740 function Bad_Compilation_Count return Natural is
2742 return Bad_Compilation.Last - Bad_Compilation.First + 1;
2743 end Bad_Compilation_Count;
2745 ----------------------------
2746 -- Check_Standard_Library --
2747 ----------------------------
2749 procedure Check_Standard_Library is
2751 Need_To_Check_Standard_Library := False;
2753 if not Targparm.Suppress_Standard_Library_On_Target then
2755 Sfile : File_Name_Type;
2756 Add_It : Boolean := True;
2759 Name_Len := Standard_Library_Package_Body_Name'Length;
2760 Name_Buffer (1 .. Name_Len) :=
2761 Standard_Library_Package_Body_Name;
2762 Sfile := Name_Enter;
2764 -- If we have a special runtime, we add the standard
2765 -- library only if we can find it.
2769 Find_File (Sfile, Osint.Source) /= No_File;
2773 if Is_Marked (Sfile) then
2774 if Is_In_Obsoleted (Sfile) then
2775 Executable_Obsolete := True;
2779 Insert_Q (Sfile, Index => 0);
2780 Mark (Sfile, Index => 0);
2785 end Check_Standard_Library;
2787 -----------------------------------
2788 -- Collect_Arguments_And_Compile --
2789 -----------------------------------
2791 procedure Collect_Arguments_And_Compile
2792 (Source_File : File_Name_Type;
2796 -- Process_Created will be set True if an attempt is made to compile
2797 -- the source, that is if it is not in an externally built project.
2799 Process_Created := False;
2801 -- If arguments not yet collected (in Check), collect them now
2803 if not Arguments_Collected then
2805 (Source_File, Source_Index, Source_File = Main_Source, Args);
2808 -- If we use mapping file (-P or -C switches), then get one
2810 if Create_Mapping_File then
2811 Get_Mapping_File (Arguments_Project);
2814 -- If the source is part of a project file, we set the ADA_*_PATHs,
2815 -- check for an eventual library project, and use the full path.
2817 if Arguments_Project /= No_Project then
2818 if not Project_Tree.Projects.Table
2819 (Arguments_Project).Externally_Built
2821 Prj.Env.Set_Ada_Paths (Arguments_Project, Project_Tree, True);
2823 if not Unique_Compile
2824 and then MLib.Tgt.Support_For_Libraries /= Prj.None
2827 The_Data : Project_Data :=
2828 Project_Tree.Projects.Table
2829 (Arguments_Project);
2831 Prj : Project_Id := Arguments_Project;
2834 while The_Data.Extended_By /= No_Project loop
2835 Prj := The_Data.Extended_By;
2836 The_Data := Project_Tree.Projects.Table (Prj);
2840 and then not The_Data.Externally_Built
2841 and then not The_Data.Need_To_Build_Lib
2843 -- Add to the Q all sources of the project that
2844 -- have not been marked
2846 Insert_Project_Sources
2847 (The_Project => Prj,
2848 All_Projects => False,
2851 -- Now mark the project as processed
2853 Project_Tree.Projects.Table
2854 (Prj).Need_To_Build_Lib := True;
2859 -- Change to the object directory of the project file,
2862 Change_To_Object_Directory (Arguments_Project);
2866 (File_Name_Type (Arguments_Path_Name),
2869 Arguments (1 .. Last_Argument));
2870 Process_Created := True;
2874 -- If this is a source outside of any project file, make sure it
2875 -- will be compiled in object directory of the main project file.
2877 if Main_Project /= No_Project then
2878 Change_To_Object_Directory (Arguments_Project);
2881 Pid := Compile (Full_Source_File, Lib_File, Source_Index,
2882 Arguments (1 .. Last_Argument));
2883 Process_Created := True;
2885 end Collect_Arguments_And_Compile;
2892 (S : File_Name_Type;
2895 Args : Argument_List) return Process_Id
2897 Comp_Args : Argument_List (Args'First .. Args'Last + 9);
2898 Comp_Next : Integer := Args'First;
2899 Comp_Last : Integer;
2900 Arg_Index : Integer;
2902 function Ada_File_Name (Name : File_Name_Type) return Boolean;
2903 -- Returns True if Name is the name of an ada source file
2904 -- (i.e. suffix is .ads or .adb)
2910 function Ada_File_Name (Name : File_Name_Type) return Boolean is
2912 Get_Name_String (Name);
2915 and then Name_Buffer (Name_Len - 3 .. Name_Len - 1) = ".ad"
2916 and then (Name_Buffer (Name_Len) = 'b'
2918 Name_Buffer (Name_Len) = 's');
2921 -- Start of processing for Compile
2924 Enter_Into_Obsoleted (S);
2926 -- By default, Syntax_Only is False
2928 Syntax_Only := False;
2930 for J in Args'Range loop
2931 if Args (J).all = "-gnats" then
2933 -- If we compile with -gnats, the bind step and the link step
2934 -- are inhibited. Also, we set Syntax_Only to True, so that
2935 -- we don't fail when we don't find the ALI file, after
2938 Do_Bind_Step := False;
2939 Do_Link_Step := False;
2940 Syntax_Only := True;
2942 elsif Args (J).all = "-gnatc" then
2944 -- If we compile with -gnatc, the bind step and the link step
2945 -- are inhibited. We set Syntax_Only to False for the case when
2946 -- -gnats was previously specified.
2948 Do_Bind_Step := False;
2949 Do_Link_Step := False;
2950 Syntax_Only := False;
2954 Comp_Args (Comp_Next) := Comp_Flag;
2955 Comp_Next := Comp_Next + 1;
2957 -- Optimize the simple case where the gcc command line looks like
2958 -- gcc -c -I. ... -I- file.adb --into-> gcc -c ... file.adb
2960 if Args (Args'First).all = "-I" & Normalized_CWD
2961 and then Args (Args'Last).all = "-I-"
2962 and then S = Strip_Directory (S)
2964 Comp_Last := Comp_Next + Args'Length - 3;
2965 Arg_Index := Args'First + 1;
2968 Comp_Last := Comp_Next + Args'Length - 1;
2969 Arg_Index := Args'First;
2972 -- Make a deep copy of the arguments, because Normalize_Arguments
2973 -- may deallocate some arguments.
2975 for J in Comp_Next .. Comp_Last loop
2976 Comp_Args (J) := new String'(Args (Arg_Index).all);
2977 Arg_Index := Arg_Index + 1;
2980 -- Set -gnatpg for predefined files (for this purpose the renamings
2981 -- such as Text_IO do not count as predefined). Note that we strip
2982 -- the directory name from the source file name because the call to
2983 -- Fname.Is_Predefined_File_Name cannot deal with directory prefixes.
2986 Fname : constant File_Name_Type := Strip_Directory (S);
2989 if Is_Predefined_File_Name (Fname, False) then
2990 if Check_Readonly_Files then
2991 Comp_Args (Comp_Args'First + 2 .. Comp_Last + 1) :=
2992 Comp_Args (Comp_Args'First + 1 .. Comp_Last);
2993 Comp_Last := Comp_Last + 1;
2994 Comp_Args (Comp_Args'First + 1) := GNAT_Flag;
2998 ("not allowed to compile """ &
2999 Get_Name_String (Fname) &
3000 """; use -a switch, or compile file with " &
3001 """-gnatg"" switch");
3006 -- Now check if the file name has one of the suffixes familiar to
3007 -- the gcc driver. If this is not the case then add the ada flag
3010 if not Ada_File_Name (S) and then not Targparm.AAMP_On_Target then
3011 Comp_Last := Comp_Last + 1;
3012 Comp_Args (Comp_Last) := Ada_Flag_1;
3013 Comp_Last := Comp_Last + 1;
3014 Comp_Args (Comp_Last) := Ada_Flag_2;
3017 if Source_Index /= 0 then
3019 Num : constant String := Source_Index'Img;
3021 Comp_Last := Comp_Last + 1;
3022 Comp_Args (Comp_Last) :=
3023 new String'("-gnateI" & Num (Num'First + 1 .. Num'Last));
3027 if Source_Index /= 0
3028 or else L /= Strip_Directory (L)
3029 or else Object_Directory_Path /= null
3031 -- Build -o argument
3033 Get_Name_String (L);
3035 for J in reverse 1 .. Name_Len loop
3036 if Name_Buffer (J) = '.' then
3037 Name_Len := J + Object_Suffix'Length - 1;
3038 Name_Buffer (J .. Name_Len) := Object_Suffix;
3043 Comp_Last := Comp_Last + 1;
3044 Comp_Args (Comp_Last) := Output_Flag;
3045 Comp_Last := Comp_Last + 1;
3047 -- If an object directory was specified, prepend the object file
3048 -- name with this object directory.
3050 if Object_Directory_Path /= null then
3051 Comp_Args (Comp_Last) :=
3052 new String'(Object_Directory_Path.all &
3053 Name_Buffer (1 .. Name_Len));
3056 Comp_Args (Comp_Last) :=
3057 new String'(Name_Buffer (1 .. Name_Len));
3061 if Create_Mapping_File then
3062 Comp_Last := Comp_Last + 1;
3063 Comp_Args (Comp_Last) := Mapping_File_Arg;
3066 Get_Name_String (S);
3068 Comp_Last := Comp_Last + 1;
3069 Comp_Args (Comp_Last) := new String'(Name_Buffer (1 .. Name_Len));
3071 GNAT.OS_Lib.Normalize_Arguments (Comp_Args (Args'First .. Comp_Last));
3073 Comp_Last := Comp_Last + 1;
3074 Comp_Args (Comp_Last) := new String'("-gnatez");
3076 Display (Gcc.all, Comp_Args (Args'First .. Comp_Last));
3078 if Gcc_Path = null then
3079 Make_Failed ("error, unable to locate ", Gcc.all);
3083 GNAT.OS_Lib.Non_Blocking_Spawn
3084 (Gcc_Path.all, Comp_Args (Args'First .. Comp_Last));
3087 ----------------------
3088 -- Get_Mapping_File --
3089 ----------------------
3091 procedure Get_Mapping_File (Project : Project_Id) is
3093 -- If there is a mapping file ready to be reused, reuse it
3095 if Last_Free_Indices (Project) > 0 then
3096 Mfile := The_Free_Mapping_File_Indices
3097 (Project, Last_Free_Indices (Project));
3098 Last_Free_Indices (Project) := Last_Free_Indices (Project) - 1;
3100 -- Otherwise, create and initialize a new one
3103 Init_Mapping_File (Project => Project, File_Index => Mfile);
3106 -- Put the name in the mapping file argument for the invocation
3109 Free (Mapping_File_Arg);
3111 new String'("-gnatem=" &
3113 (The_Mapping_File_Names (Project, Mfile)));
3115 end Get_Mapping_File;
3117 -----------------------
3118 -- Get_Next_Good_ALI --
3119 -----------------------
3121 function Get_Next_Good_ALI return ALI_Id is
3125 pragma Assert (Good_ALI_Present);
3126 ALI := Good_ALI.Table (Good_ALI.Last);
3127 Good_ALI.Decrement_Last;
3129 end Get_Next_Good_ALI;
3131 ----------------------
3132 -- Good_ALI_Present --
3133 ----------------------
3135 function Good_ALI_Present return Boolean is
3137 return Good_ALI.First <= Good_ALI.Last;
3138 end Good_ALI_Present;
3140 --------------------
3141 -- Record_Failure --
3142 --------------------
3144 procedure Record_Failure
3145 (File : File_Name_Type;
3146 Unit : Unit_Name_Type;
3147 Found : Boolean := True)
3150 Bad_Compilation.Increment_Last;
3151 Bad_Compilation.Table (Bad_Compilation.Last) := (File, Unit, Found);
3154 ---------------------
3155 -- Record_Good_ALI --
3156 ---------------------
3158 procedure Record_Good_ALI (A : ALI_Id) is
3160 Good_ALI.Increment_Last;
3161 Good_ALI.Table (Good_ALI.Last) := A;
3162 end Record_Good_ALI;
3164 -- Start of processing for Compile_Sources
3167 pragma Assert (Args'First = 1);
3169 Outstanding_Compiles := 0;
3170 Running_Compile := new Comp_Data_Arr (1 .. Max_Process);
3172 -- Package and Queue initializations
3176 if First_Q_Initialization then
3180 if Initialize_ALI_Data then
3182 Initialize_ALI_Source;
3185 -- The following two flags affect the behavior of ALI.Set_Source_Table.
3186 -- We set Check_Source_Files to True to ensure that source file
3187 -- time stamps are checked, and we set All_Sources to False to
3188 -- avoid checking the presence of the source files listed in the
3189 -- source dependency section of an ali file (which would be a mistake
3190 -- since the ali file may be obsolete).
3192 Check_Source_Files := True;
3193 All_Sources := False;
3195 -- Only insert in the Q if it is not already done, to avoid simultaneous
3196 -- compilations if -jnnn is used.
3198 if not Is_Marked (Main_Source, Main_Index) then
3199 Insert_Q (Main_Source, Index => Main_Index);
3200 Mark (Main_Source, Main_Index);
3203 First_Compiled_File := No_File;
3204 Most_Recent_Obj_File := No_File;
3205 Most_Recent_Obj_Stamp := Empty_Time_Stamp;
3208 -- Keep looping until there is no more work to do (the Q is empty)
3209 -- and all the outstanding compilations have terminated
3211 Make_Loop : while not Empty_Q or else Outstanding_Compiles > 0 loop
3213 -- If the user does not want to keep going in case of errors then
3214 -- wait for the remaining outstanding compiles and then exit.
3216 if Bad_Compilation_Count > 0 and then not Keep_Going then
3217 while Outstanding_Compiles > 0 loop
3219 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
3221 if not Compilation_OK then
3222 Record_Failure (Full_Source_File, Source_Unit);
3229 -- PHASE 1: Check if there is more work that we can do (i.e. the Q
3230 -- is non empty). If there is, do it only if we have not yet used
3231 -- up all the available processes.
3233 if not Empty_Q and then Outstanding_Compiles < Max_Process then
3236 -- Index of the current unit in the current source file
3239 Extract_From_Q (Source_File, Source_Unit, Source_Index);
3240 Full_Source_File := Osint.Full_Source_Name (Source_File);
3241 Lib_File := Osint.Lib_File_Name
3242 (Source_File, Source_Index);
3243 Full_Lib_File := Osint.Full_Lib_File_Name (Lib_File);
3245 -- If this source has already been compiled, the executable is
3248 if Is_In_Obsoleted (Source_File) then
3249 Executable_Obsolete := True;
3252 -- If the library file is an Ada library skip it
3254 if Full_Lib_File /= No_File
3255 and then In_Ada_Lib_Dir (Full_Lib_File)
3259 "is in an Ada library",
3261 Minimum_Verbosity => Opt.High);
3263 -- If the library file is a read-only library skip it, but
3264 -- only if, when using project files, this library file is
3265 -- in the right object directory (a read-only ALI file
3266 -- in the object directory of a project being extended
3267 -- should not be skipped).
3269 elsif Full_Lib_File /= No_File
3270 and then not Check_Readonly_Files
3271 and then Is_Readonly_Library (Full_Lib_File)
3272 and then Is_In_Object_Directory (Source_File, Full_Lib_File)
3276 "is a read-only library",
3278 Minimum_Verbosity => Opt.High);
3280 -- The source file that we are checking cannot be located
3282 elsif Full_Source_File = No_File then
3283 Record_Failure (Source_File, Source_Unit, False);
3285 -- Source and library files can be located but are internal
3288 elsif not Check_Readonly_Files
3289 and then Full_Lib_File /= No_File
3290 and then Is_Internal_File_Name (Source_File, False)
3292 if Force_Compilations then
3294 ("not allowed to compile """ &
3295 Get_Name_String (Source_File) &
3296 """; use -a switch, or compile file with " &
3297 """-gnatg"" switch");
3302 "is an internal library",
3304 Minimum_Verbosity => Opt.High);
3306 -- The source file that we are checking can be located
3309 Arguments_Collected := False;
3311 Collect_Arguments (Source_File, Source_Index,
3312 Source_File = Main_Source, Args);
3314 -- Do nothing if project of source is externally built
3316 if Arguments_Project = No_Project
3317 or else not Project_Tree.Projects.Table
3318 (Arguments_Project).Externally_Built
3320 -- Don't waste any time if we have to recompile anyway
3322 Obj_Stamp := Empty_Time_Stamp;
3323 Need_To_Compile := Force_Compilations;
3325 if not Force_Compilations then
3327 Full_Lib_File /= No_File
3328 and then not Check_Readonly_Files
3329 and then Is_Readonly_Library (Full_Lib_File);
3330 Check (Source_File, Source_Index,
3331 Source_File = Main_Source, Args, Lib_File,
3332 Read_Only, ALI, Obj_File, Obj_Stamp);
3333 Need_To_Compile := (ALI = No_ALI_Id);
3336 if not Need_To_Compile then
3337 -- The ALI file is up-to-date. Record its Id
3339 Record_Good_ALI (ALI);
3341 -- Record the time stamp of the most recent object
3342 -- file as long as no (re)compilations are needed.
3344 if First_Compiled_File = No_File
3345 and then (Most_Recent_Obj_File = No_File
3346 or else Obj_Stamp > Most_Recent_Obj_Stamp)
3348 Most_Recent_Obj_File := Obj_File;
3349 Most_Recent_Obj_Stamp := Obj_Stamp;
3353 -- Check that switch -x has been used if a source
3354 -- outside of project files need to be compiled.
3356 if Main_Project /= No_Project
3357 and then Arguments_Project = No_Project
3358 and then not External_Unit_Compilation_Allowed
3360 Make_Failed ("external source (",
3361 Get_Name_String (Source_File),
3362 ") is not part of any project;"
3363 & " cannot be compiled without" &
3364 " gnatmake switch -x");
3367 -- Is this the first file we have to compile?
3369 if First_Compiled_File = No_File then
3370 First_Compiled_File := Full_Source_File;
3371 Most_Recent_Obj_File := No_File;
3373 if Do_Not_Execute then
3378 if In_Place_Mode then
3380 -- If the library file was not found, then save
3381 -- the library file near the source file.
3383 if Full_Lib_File = No_File then
3384 Lib_File := Osint.Lib_File_Name
3385 (Full_Source_File, Source_Index);
3387 -- If the library file was found, then save the
3388 -- library file in the same place.
3391 Lib_File := Full_Lib_File;
3396 -- Start the compilation and record it. We can do
3397 -- this because there is at least one free process.
3399 Collect_Arguments_And_Compile
3400 (Source_File, Source_Index);
3402 -- Make sure we could successfully start
3405 if Process_Created then
3406 if Pid = Invalid_Pid then
3407 Record_Failure (Full_Source_File, Source_Unit);
3423 -- PHASE 2: Now check if we should wait for a compilation to
3424 -- finish. This is the case if all the available processes are
3425 -- busy compiling sources or there is nothing else to do
3426 -- (that is the Q is empty and there are no good ALIs to process).
3428 if Outstanding_Compiles = Max_Process
3430 and then not Good_ALI_Present
3431 and then Outstanding_Compiles > 0)
3434 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
3436 if not Compilation_OK then
3437 Record_Failure (Full_Source_File, Source_Unit);
3440 if Compilation_OK or else Keep_Going then
3442 -- Re-read the updated library file
3445 Saved_Object_Consistency : constant Boolean :=
3446 Check_Object_Consistency;
3449 -- If compilation was not OK, or if output is not an
3450 -- object file and we don't do the bind step, don't check
3451 -- for object consistency.
3453 Check_Object_Consistency :=
3454 Check_Object_Consistency
3456 and (Output_Is_Object or Do_Bind_Step);
3457 Text := Read_Library_Info (Lib_File);
3459 -- Restore Check_Object_Consistency to its initial value
3461 Check_Object_Consistency := Saved_Object_Consistency;
3464 -- If an ALI file was generated by this compilation, scan
3465 -- the ALI file and record it.
3466 -- If the scan fails, a previous ali file is inconsistent with
3467 -- the unit just compiled.
3469 if Text /= null then
3471 Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
3473 if ALI = No_ALI_Id then
3475 -- Record a failure only if not already done
3477 if Compilation_OK then
3480 "incompatible ALI file, please recompile");
3481 Record_Failure (Full_Source_File, Source_Unit);
3485 Record_Good_ALI (ALI);
3488 -- If we could not read the ALI file that was just generated
3489 -- then there could be a problem reading either the ALI or the
3490 -- corresponding object file (if Check_Object_Consistency is
3491 -- set Read_Library_Info checks that the time stamp of the
3492 -- object file is more recent than that of the ALI). However,
3493 -- we record a failure only if not already done.
3496 if Compilation_OK and not Syntax_Only then
3499 "WARNING: ALI or object file not found after compile");
3500 Record_Failure (Full_Source_File, Source_Unit);
3506 -- PHASE 3: Check if we recorded good ALI files. If yes process
3507 -- them now in the order in which they have been recorded. There
3508 -- are two occasions in which we record good ali files. The first is
3509 -- in phase 1 when, after scanning an existing ALI file we realize
3510 -- it is up-to-date, the second instance is after a successful
3513 while Good_ALI_Present loop
3514 ALI := Get_Next_Good_ALI;
3517 Source_Index : Int := Unit_Index_Of (ALIs.Table (ALI).Afile);
3520 -- If we are processing the library file corresponding to the
3521 -- main source file check if this source can be a main unit.
3523 if ALIs.Table (ALI).Sfile = Main_Source and then
3524 Source_Index = Main_Index
3526 Main_Unit := ALIs.Table (ALI).Main_Program /= None;
3529 -- The following adds the standard library (s-stalib) to the
3530 -- list of files to be handled by gnatmake: this file and any
3531 -- files it depends on are always included in every bind,
3532 -- even if they are not in the explicit dependency list.
3533 -- Of course, it is not added if Suppress_Standard_Library
3536 -- However, to avoid annoying output about s-stalib.ali being
3537 -- read only, when "-v" is used, we add the standard library
3538 -- only when "-a" is used.
3540 if Need_To_Check_Standard_Library then
3541 Check_Standard_Library;
3544 -- Now insert in the Q the unmarked source files (i.e. those
3545 -- which have never been inserted in the Q and hence never
3546 -- considered). Only do that if Unique_Compile is False.
3548 if not Unique_Compile then
3550 ALIs.Table (ALI).First_Unit .. ALIs.Table (ALI).Last_Unit
3553 Units.Table (J).First_With .. Units.Table (J).Last_With
3555 Sfile := Withs.Table (K).Sfile;
3556 Uname := Withs.Table (K).Uname;
3558 -- If project files are used, find the proper source
3559 -- to compile, in case Sfile is the spec, but there
3562 if Main_Project /= No_Project then
3564 Unit_Name : Name_Id;
3565 Uid : Prj.Unit_Index;
3569 Get_Name_String (Uname);
3570 Name_Len := Name_Len - 2;
3571 Unit_Name := Name_Find;
3574 (Project_Tree.Units_HT, Unit_Name);
3576 if Uid /= Prj.No_Unit_Index then
3577 Udata := Project_Tree.Units.Table (Uid);
3580 Udata.File_Names (Body_Part).Name /=
3583 Udata.File_Names (Body_Part).Path /= Slash
3585 Sfile := Udata.File_Names (Body_Part).Name;
3587 Udata.File_Names (Body_Part).Index;
3590 Udata.File_Names (Specification).Name /=
3593 Udata.File_Names (Specification).Path /=
3597 Udata.File_Names (Specification).Name;
3599 Udata.File_Names (Specification).Index;
3605 Dependencies.Append ((ALIs.Table (ALI).Sfile, Sfile));
3607 if Is_In_Obsoleted (Sfile) then
3608 Executable_Obsolete := True;
3611 if Sfile = No_File then
3613 ("Skipping generic:", Withs.Table (K).Uname);
3617 Unit_Index_Of (Withs.Table (K).Afile);
3619 if Is_Marked (Sfile, Source_Index) then
3620 Debug_Msg ("Skipping marked file:", Sfile);
3622 elsif not Check_Readonly_Files
3623 and then Is_Internal_File_Name (Sfile, False)
3625 Debug_Msg ("Skipping internal file:", Sfile);
3629 (Sfile, Withs.Table (K).Uname, Source_Index);
3630 Mark (Sfile, Source_Index);
3639 if Display_Compilation_Progress then
3640 Write_Str ("completed ");
3641 Write_Int (Int (Q_Front));
3642 Write_Str (" out of ");
3643 Write_Int (Int (Q.Last));
3645 Write_Int (Int ((Q_Front * 100) / (Q.Last - Q.First)));
3646 Write_Str ("%)...");
3651 Compilation_Failures := Bad_Compilation_Count;
3653 -- Compilation is finished
3655 -- Delete any temporary configuration pragma file
3657 if not Debug.Debug_Flag_N then
3658 Delete_Temp_Config_Files;
3660 end Compile_Sources;
3662 -----------------------------------
3663 -- Compute_All_Imported_Projects --
3664 -----------------------------------
3666 procedure Compute_All_Imported_Projects (Project : Project_Id) is
3667 procedure Add_To_List (Prj : Project_Id);
3668 -- Add a project to the list All_Imported_Projects of project Project
3670 procedure Recursive_Add_Imported (Project : Project_Id);
3671 -- Recursively add the projects imported by project Project, but not
3672 -- those that are extended.
3678 procedure Add_To_List (Prj : Project_Id) is
3679 Element : constant Project_Element :=
3680 (Prj, Project_Tree.Projects.Table (Project).All_Imported_Projects);
3681 List : Project_List;
3683 Project_List_Table.Increment_Last (Project_Tree.Project_Lists);
3684 List := Project_List_Table.Last (Project_Tree.Project_Lists);
3685 Project_Tree.Project_Lists.Table (List) := Element;
3686 Project_Tree.Projects.Table (Project).All_Imported_Projects := List;
3689 ----------------------------
3690 -- Recursive_Add_Imported --
3691 ----------------------------
3693 procedure Recursive_Add_Imported (Project : Project_Id) is
3694 List : Project_List;
3695 Element : Project_Element;
3699 if Project /= No_Project then
3701 -- For all the imported projects
3703 List := Project_Tree.Projects.Table (Project).Imported_Projects;
3704 while List /= Empty_Project_List loop
3705 Element := Project_Tree.Project_Lists.Table (List);
3706 Prj := Element.Project;
3708 -- Get the ultimate extending project
3711 Project_Tree.Projects.Table (Prj).Extended_By /= No_Project
3713 Prj := Project_Tree.Projects.Table (Prj).Extended_By;
3716 -- If project has not yet been visited, add to list and recurse
3718 if not Project_Tree.Projects.Table (Prj).Seen then
3719 Project_Tree.Projects.Table (Prj).Seen := True;
3721 Recursive_Add_Imported (Prj);
3724 List := Element.Next;
3727 -- Recurse on projects being imported, if any
3729 Recursive_Add_Imported
3730 (Project_Tree.Projects.Table (Project).Extends);
3732 end Recursive_Add_Imported;
3735 -- Reset the Seen flag for all projects
3737 for Index in 1 .. Project_Table.Last (Project_Tree.Projects) loop
3738 Project_Tree.Projects.Table (Index).Seen := False;
3741 -- Make sure the list is empty
3743 Project_Tree.Projects.Table (Project).All_Imported_Projects :=
3746 -- Add to the list all projects imported directly or indirectly
3748 Recursive_Add_Imported (Project);
3749 end Compute_All_Imported_Projects;
3751 ----------------------------------
3752 -- Configuration_Pragmas_Switch --
3753 ----------------------------------
3755 function Configuration_Pragmas_Switch
3756 (For_Project : Project_Id) return Argument_List
3758 The_Packages : Package_Id;
3759 Gnatmake : Package_Id;
3760 Compiler : Package_Id;
3762 Global_Attribute : Variable_Value := Nil_Variable_Value;
3763 Local_Attribute : Variable_Value := Nil_Variable_Value;
3765 Global_Attribute_Present : Boolean := False;
3766 Local_Attribute_Present : Boolean := False;
3768 Result : Argument_List (1 .. 3);
3769 Last : Natural := 0;
3771 function Absolute_Path
3772 (Path : Path_Name_Type;
3773 Project : Project_Id) return String;
3774 -- Returns an absolute path for a configuration pragmas file
3780 function Absolute_Path
3781 (Path : Path_Name_Type;
3782 Project : Project_Id) return String
3785 Get_Name_String (Path);
3788 Path_Name : constant String := Name_Buffer (1 .. Name_Len);
3791 if Is_Absolute_Path (Path_Name) then
3796 Parent_Directory : constant String :=
3798 (Project_Tree.Projects.Table
3799 (Project).Display_Directory);
3802 if Parent_Directory (Parent_Directory'Last) =
3805 return Parent_Directory & Path_Name;
3808 return Parent_Directory & Directory_Separator & Path_Name;
3815 -- Start of processing for Configuration_Pragmas_Switch
3818 Prj.Env.Create_Config_Pragmas_File
3819 (For_Project, Main_Project, Project_Tree);
3821 if Project_Tree.Projects.Table
3822 (For_Project).Config_File_Name /= No_Path
3824 Temporary_Config_File :=
3825 Project_Tree.Projects.Table (For_Project).Config_File_Temp;
3831 (Project_Tree.Projects.Table
3832 (For_Project).Config_File_Name));
3835 Temporary_Config_File := False;
3838 -- Check for attribute Builder'Global_Configuration_Pragmas
3840 The_Packages := Project_Tree.Projects.Table
3841 (Main_Project).Decl.Packages;
3844 (Name => Name_Builder,
3845 In_Packages => The_Packages,
3846 In_Tree => Project_Tree);
3848 if Gnatmake /= No_Package then
3849 Global_Attribute := Prj.Util.Value_Of
3850 (Variable_Name => Name_Global_Configuration_Pragmas,
3851 In_Variables => Project_Tree.Packages.Table
3852 (Gnatmake).Decl.Attributes,
3853 In_Tree => Project_Tree);
3854 Global_Attribute_Present :=
3855 Global_Attribute /= Nil_Variable_Value
3856 and then Get_Name_String (Global_Attribute.Value) /= "";
3858 if Global_Attribute_Present then
3860 Path : constant String :=
3862 (Path_Name_Type (Global_Attribute.Value),
3863 Global_Attribute.Project);
3865 if not Is_Regular_File (Path) then
3866 if Debug.Debug_Flag_F then
3868 ("cannot find configuration pragmas file ",
3872 ("cannot find configuration pragmas file ",
3878 Result (Last) := new String'("-gnatec=" & Path);
3883 -- Check for attribute Compiler'Local_Configuration_Pragmas
3886 Project_Tree.Projects.Table (For_Project).Decl.Packages;
3889 (Name => Name_Compiler,
3890 In_Packages => The_Packages,
3891 In_Tree => Project_Tree);
3893 if Compiler /= No_Package then
3894 Local_Attribute := Prj.Util.Value_Of
3895 (Variable_Name => Name_Local_Configuration_Pragmas,
3896 In_Variables => Project_Tree.Packages.Table
3897 (Compiler).Decl.Attributes,
3898 In_Tree => Project_Tree);
3899 Local_Attribute_Present :=
3900 Local_Attribute /= Nil_Variable_Value
3901 and then Get_Name_String (Local_Attribute.Value) /= "";
3903 if Local_Attribute_Present then
3905 Path : constant String :=
3907 (Path_Name_Type (Local_Attribute.Value),
3908 Local_Attribute.Project);
3910 if not Is_Regular_File (Path) then
3911 if Debug.Debug_Flag_F then
3913 ("cannot find configuration pragmas file ",
3918 ("cannot find configuration pragmas file ", Path);
3923 Result (Last) := new String'("-gnatec=" & Path);
3928 return Result (1 .. Last);
3929 end Configuration_Pragmas_Switch;
3935 procedure Debug_Msg (S : String; N : Name_Id) is
3937 if Debug.Debug_Flag_W then
3938 Write_Str (" ... ");
3946 procedure Debug_Msg (S : String; N : File_Name_Type) is
3948 Debug_Msg (S, Name_Id (N));
3951 procedure Debug_Msg (S : String; N : Unit_Name_Type) is
3953 Debug_Msg (S, Name_Id (N));
3956 ---------------------------
3957 -- Delete_All_Temp_Files --
3958 ---------------------------
3960 procedure Delete_All_Temp_Files is
3962 if not Debug.Debug_Flag_N then
3963 Delete_Mapping_Files;
3964 Delete_Temp_Config_Files;
3965 Prj.Env.Delete_All_Path_Files (Project_Tree);
3967 end Delete_All_Temp_Files;
3969 --------------------------
3970 -- Delete_Mapping_Files --
3971 --------------------------
3973 procedure Delete_Mapping_Files is
3975 pragma Warnings (Off, Success);
3978 -- The caller is responsible for ensuring that Debug_Flag_N is False
3980 pragma Assert (not Debug.Debug_Flag_N);
3982 if The_Mapping_File_Names /= null then
3983 for Project in The_Mapping_File_Names'Range (1) loop
3984 for Index in 1 .. Last_Mapping_File_Names (Project) loop
3986 (Name => Get_Name_String
3987 (The_Mapping_File_Names (Project, Index)),
3988 Success => Success);
3992 end Delete_Mapping_Files;
3994 ------------------------------
3995 -- Delete_Temp_Config_Files --
3996 ------------------------------
3998 procedure Delete_Temp_Config_Files is
4000 pragma Warnings (Off, Success);
4003 -- The caller is responsible for ensuring that Debug_Flag_N is False
4005 pragma Assert (not Debug.Debug_Flag_N);
4007 if Main_Project /= No_Project then
4008 for Project in Project_Table.First ..
4009 Project_Table.Last (Project_Tree.Projects)
4012 Project_Tree.Projects.Table (Project).Config_File_Temp
4014 if Verbose_Mode then
4015 Write_Str ("Deleting temp configuration file """);
4016 Write_Str (Get_Name_String
4017 (Project_Tree.Projects.Table
4018 (Project).Config_File_Name));
4023 (Name => Get_Name_String
4024 (Project_Tree.Projects.Table
4025 (Project).Config_File_Name),
4026 Success => Success);
4028 -- Make sure that we don't have a config file for this project,
4029 -- in case there are several mains. In this case, we will
4030 -- recreate another config file: we cannot reuse the one that
4033 Project_Tree.Projects.Table (Project).
4034 Config_Checked := False;
4035 Project_Tree.Projects.Table (Project).
4036 Config_File_Name := No_Path;
4037 Project_Tree.Projects.Table (Project).
4038 Config_File_Temp := False;
4042 end Delete_Temp_Config_Files;
4048 procedure Display (Program : String; Args : Argument_List) is
4050 pragma Assert (Args'First = 1);
4052 if Display_Executed_Programs then
4053 Write_Str (Program);
4055 for J in Args'Range loop
4057 -- Never display -gnatez
4059 if Args (J).all /= "-gnatez" then
4061 -- Do not display the mapping file argument automatically
4062 -- created when using a project file.
4064 if Main_Project = No_Project
4065 or else Debug.Debug_Flag_N
4066 or else Args (J)'Length < 8
4068 Args (J) (Args (J)'First .. Args (J)'First + 6) /= "-gnatem"
4070 -- When -dn is not specified, do not display the config
4071 -- pragmas switch (-gnatec) for the temporary file created
4072 -- by the project manager (always the first -gnatec switch).
4073 -- Reset Temporary_Config_File to False so that the eventual
4074 -- other -gnatec switches will be displayed.
4076 if (not Debug.Debug_Flag_N)
4077 and then Temporary_Config_File
4078 and then Args (J)'Length > 7
4079 and then Args (J) (Args (J)'First .. Args (J)'First + 6)
4082 Temporary_Config_File := False;
4084 -- Do not display the -F=mapping_file switch for
4085 -- gnatbind, if -dn is not specified.
4087 elsif Debug.Debug_Flag_N
4088 or else Args (J)'Length < 4
4090 Args (J) (Args (J)'First .. Args (J)'First + 2) /= "-F="
4094 -- If -df is used, only display file names, not path
4097 if Debug.Debug_Flag_F then
4099 Equal_Pos : Natural;
4101 Equal_Pos := Args (J)'First - 1;
4102 for K in Args (J)'Range loop
4103 if Args (J) (K) = '=' then
4110 (Args (J) (Equal_Pos + 1 .. Args (J)'Last))
4113 (Args (J) (Args (J)'First .. Equal_Pos));
4117 (Equal_Pos + 1 .. Args (J)'Last)));
4120 Write_Str (Args (J).all);
4125 Write_Str (Args (J).all);
4136 ----------------------
4137 -- Display_Commands --
4138 ----------------------
4140 procedure Display_Commands (Display : Boolean := True) is
4142 Display_Executed_Programs := Display;
4143 end Display_Commands;
4149 function Empty_Q return Boolean is
4151 if Debug.Debug_Flag_P then
4152 Write_Str (" Q := [");
4154 for J in Q_Front .. Q.Last - 1 loop
4156 Write_Name (Q.Table (J).File);
4165 return Q_Front >= Q.Last;
4168 --------------------------
4169 -- Enter_Into_Obsoleted --
4170 --------------------------
4172 procedure Enter_Into_Obsoleted (F : File_Name_Type) is
4173 Name : constant String := Get_Name_String (F);
4175 F2 : File_Name_Type;
4179 while First > Name'First
4180 and then Name (First - 1) /= Directory_Separator
4181 and then Name (First - 1) /= '/'
4186 if First /= Name'First then
4188 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
4195 Debug_Msg ("New entry in Obsoleted table:", F2);
4196 Obsoleted.Set (F2, True);
4197 end Enter_Into_Obsoleted;
4199 --------------------
4200 -- Extract_From_Q --
4201 --------------------
4203 procedure Extract_From_Q
4204 (Source_File : out File_Name_Type;
4205 Source_Unit : out Unit_Name_Type;
4206 Source_Index : out Int)
4208 File : constant File_Name_Type := Q.Table (Q_Front).File;
4209 Unit : constant Unit_Name_Type := Q.Table (Q_Front).Unit;
4210 Index : constant Int := Q.Table (Q_Front).Index;
4213 if Debug.Debug_Flag_Q then
4214 Write_Str (" Q := Q - [ ");
4226 Q_Front := Q_Front + 1;
4227 Source_File := File;
4228 Source_Unit := Unit;
4229 Source_Index := Index;
4236 procedure Gnatmake is
4237 Main_Source_File : File_Name_Type;
4238 -- The source file containing the main compilation unit
4240 Compilation_Failures : Natural;
4242 Total_Compilation_Failures : Natural := 0;
4244 Is_Main_Unit : Boolean;
4245 -- Set to True by Compile_Sources if the Main_Source_File can be a
4248 Main_ALI_File : File_Name_Type;
4249 -- The ali file corresponding to Main_Source_File
4251 Executable : File_Name_Type := No_File;
4252 -- The file name of an executable
4254 Non_Std_Executable : Boolean := False;
4255 -- Non_Std_Executable is set to True when there is a possibility
4256 -- that the linker will not choose the correct executable file name.
4258 Current_Work_Dir : constant String_Access :=
4259 new String'(Get_Current_Dir);
4260 -- The current working directory, used to modify some relative path
4261 -- switches on the command line when a project file is used.
4263 Current_Main_Index : Int := 0;
4264 -- If not zero, the index of the current main unit in its source file
4266 There_Are_Stand_Alone_Libraries : Boolean := False;
4267 -- Set to True when there are Stand-Alone Libraries, so that gnatbind
4268 -- is invoked with the -F switch to force checking of elaboration flags.
4270 Mapping_Path : Path_Name_Type := No_Path;
4271 -- The path name of the mapping file
4274 pragma Warnings (Off, Discard);
4276 procedure Check_Mains;
4277 -- Check that the main subprograms do exist and that they all
4278 -- belong to the same project file.
4280 procedure Create_Binder_Mapping_File
4281 (Args : in out Argument_List; Last_Arg : in out Natural);
4282 -- Create a binder mapping file and add the necessary switch
4288 procedure Check_Mains is
4289 Real_Main_Project : Project_Id := No_Project;
4290 -- The project of the first main
4292 Proj : Project_Id := No_Project;
4293 -- The project of the current main
4295 Data : Project_Data;
4297 Real_Path : String_Access;
4306 Main : constant String := Mains.Next_Main;
4307 -- The name specified on the command line may include
4308 -- directory information.
4310 File_Name : constant String := Base_Name (Main);
4311 -- The simple file name of the current main main
4314 exit when Main = "";
4316 -- Get the project of the current main
4318 Proj := Prj.Env.Project_Of
4319 (File_Name, Main_Project, Project_Tree);
4321 -- Fail if the current main is not a source of a
4324 if Proj = No_Project then
4327 """ is not a source of any project");
4330 -- If there is directory information, check that
4331 -- the source exists and, if it does, that the path
4332 -- is the actual path of a source of a project.
4334 if Main /= File_Name then
4336 Project_Tree.Projects.Table (Main_Project);
4341 Body_Suffix_Of (Project_Tree, "ada", Data.Naming),
4343 if Real_Path = null then
4347 Spec_Suffix_Of (Project_Tree, "ada", Data.Naming),
4351 if Real_Path = null then
4353 Locate_Regular_File (Main, "");
4356 -- Fail if the file cannot be found
4358 if Real_Path = null then
4360 ("file """ & Main & """ does not exist");
4364 Project_Path : constant String :=
4365 Prj.Env.File_Name_Of_Library_Unit_Body
4367 Project => Main_Project,
4368 In_Tree => Project_Tree,
4369 Main_Project_Only => False,
4371 Normed_Path : constant String :=
4374 Case_Sensitive => False);
4375 Proj_Path : constant String :=
4378 Case_Sensitive => False);
4383 -- Fail if it is not the correct path
4385 if Normed_Path /= Proj_Path then
4386 if Verbose_Mode then
4388 Write_Str (Normed_Path);
4390 Write_Line (Proj_Path);
4395 """ is not a source of any project");
4400 if not Unique_Compile then
4402 -- Record the project, if it is the first main
4404 if Real_Main_Project = No_Project then
4405 Real_Main_Project := Proj;
4407 elsif Proj /= Real_Main_Project then
4409 -- Fail, as the current main is not a source
4410 -- of the same project as the first main.
4414 """ is not a source of project " &
4416 (Project_Tree.Projects.Table
4417 (Real_Main_Project).Name));
4422 -- If -u and -U are not used, we may have mains that
4423 -- are sources of a project that is not the one
4424 -- specified with switch -P.
4426 if not Unique_Compile then
4427 Main_Project := Real_Main_Project;
4433 --------------------------------
4434 -- Create_Binder_Mapping_File --
4435 --------------------------------
4437 procedure Create_Binder_Mapping_File
4438 (Args : in out Argument_List; Last_Arg : in out Natural)
4440 Mapping_FD : File_Descriptor := Invalid_FD;
4441 -- A File Descriptor for an eventual mapping file
4443 ALI_Unit : Unit_Name_Type := No_Unit_Name;
4444 -- The unit name of an ALI file
4446 ALI_Name : File_Name_Type := No_File;
4447 -- The file name of the ALI file
4449 ALI_Project : Project_Id := No_Project;
4450 -- The project of the ALI file
4453 OK : Boolean := True;
4456 -- For call to Close
4459 Tempdir.Create_Temp_File (Mapping_FD, Mapping_Path);
4460 Record_Temp_File (Mapping_Path);
4462 if Mapping_FD /= Invalid_FD then
4464 -- Traverse all units
4466 for J in Unit_Table.First ..
4467 Unit_Table.Last (Project_Tree.Units)
4470 Unit : constant Unit_Data := Project_Tree.Units.Table (J);
4472 if Unit.Name /= No_Name then
4474 -- If there is a body, put it in the mapping
4476 if Unit.File_Names (Body_Part).Name /= No_File
4477 and then Unit.File_Names (Body_Part).Project /=
4480 Get_Name_String (Unit.Name);
4481 Name_Buffer (Name_Len + 1 .. Name_Len + 2) := "%b";
4482 Name_Len := Name_Len + 2;
4483 ALI_Unit := Name_Find;
4486 (Unit.File_Names (Body_Part).Display_Name);
4488 Unit.File_Names (Body_Part).Project;
4490 -- Otherwise, if there is a spec, put it
4493 elsif Unit.File_Names (Specification).Name /= No_File
4494 and then Unit.File_Names (Specification).Project /=
4497 Get_Name_String (Unit.Name);
4498 Name_Buffer (Name_Len + 1 .. Name_Len + 2) := "%s";
4499 Name_Len := Name_Len + 2;
4500 ALI_Unit := Name_Find;
4503 (Unit.File_Names (Specification).Display_Name);
4505 Unit.File_Names (Specification).Project;
4508 ALI_Name := No_File;
4511 -- If we have something to put in the mapping
4512 -- then we do it now. However, if the project
4513 -- is extended, we don't put anything in the
4514 -- mapping file, because we do not know where
4515 -- the ALI file is: it might be in the ext-
4516 -- ended project obj dir as well as in the
4517 -- extending project obj dir.
4519 if ALI_Name /= No_File
4521 Project_Tree.Projects.Table
4522 (ALI_Project).Extended_By = No_Project
4524 Project_Tree.Projects.Table
4525 (ALI_Project).Extends = No_Project
4527 -- First check if the ALI file exists. If it does not,
4528 -- do not put the unit in the mapping file.
4531 ALI : constant String :=
4532 Get_Name_String (ALI_Name);
4533 PD : Project_Data renames
4534 Project_Tree.Projects.Table (ALI_Project);
4537 -- For library projects, use the library directory,
4538 -- for other projects, use the object directory.
4541 Get_Name_String (PD.Library_Dir);
4543 Get_Name_String (PD.Object_Directory);
4546 if Name_Buffer (Name_Len) /=
4549 Name_Len := Name_Len + 1;
4550 Name_Buffer (Name_Len) :=
4551 Directory_Separator;
4556 Name_Len + ALI'Length) := ALI;
4558 Name_Len + ALI'Length + 1;
4559 Name_Buffer (Name_Len) := ASCII.LF;
4562 ALI_Path_Name : constant String :=
4563 Name_Buffer (1 .. Name_Len);
4567 (ALI_Path_Name (1 .. ALI_Path_Name'Last - 1))
4570 -- First line is the unit name
4572 Get_Name_String (ALI_Unit);
4573 Name_Len := Name_Len + 1;
4574 Name_Buffer (Name_Len) := ASCII.LF;
4578 Name_Buffer (1)'Address,
4580 OK := Bytes = Name_Len;
4584 -- Second line it the ALI file name
4586 Get_Name_String (ALI_Name);
4587 Name_Len := Name_Len + 1;
4588 Name_Buffer (Name_Len) := ASCII.LF;
4592 Name_Buffer (1)'Address,
4594 OK := Bytes = Name_Len;
4598 -- Third line it the ALI path name
4603 ALI_Path_Name (1)'Address,
4604 ALI_Path_Name'Length);
4605 OK := Bytes = ALI_Path_Name'Length;
4607 -- If OK is False, it means we were unable
4608 -- to write a line. No point in continuing
4609 -- with the other units.
4620 Close (Mapping_FD, Status);
4622 OK := OK and Status;
4624 -- If the creation of the mapping file was successful,
4625 -- we add the switch to the arguments of gnatbind.
4628 Last_Arg := Last_Arg + 1;
4630 new String'("-F=" & Get_Name_String (Mapping_Path));
4633 end Create_Binder_Mapping_File;
4635 -- Start of processing for Gnatmake
4637 -- This body is very long, should be broken down ???
4640 Install_Int_Handler (Sigint_Intercepted'Access);
4642 Do_Compile_Step := True;
4643 Do_Bind_Step := True;
4644 Do_Link_Step := True;
4650 Bind_Shared := No_Shared_Switch'Access;
4651 Link_With_Shared_Libgcc := No_Shared_Libgcc_Switch'Access;
4653 Failed_Links.Set_Last (0);
4654 Successful_Links.Set_Last (0);
4656 -- Special case when switch -B was specified
4658 if Build_Bind_And_Link_Full_Project then
4660 -- When switch -B is specified, there must be a project file
4662 if Main_Project = No_Project then
4663 Make_Failed ("-B cannot be used without a project file");
4665 -- No main program may be specified on the command line
4667 elsif Osint.Number_Of_Files /= 0 then
4668 Make_Failed ("-B cannot be used with a main specified on " &
4669 "the command line");
4671 -- And the project file cannot be a library project file
4673 elsif Project_Tree.Projects.Table (Main_Project).Library then
4674 Make_Failed ("-B cannot be used for a library project file");
4677 No_Main_Subprogram := True;
4678 Insert_Project_Sources
4679 (The_Project => Main_Project,
4680 All_Projects => Unique_Compile_All_Projects,
4683 -- If there are no sources to compile, we fail
4685 if Osint.Number_Of_Files = 0 then
4686 Make_Failed ("no sources to compile");
4689 -- Specify -n for gnatbind and add the ALI files of all the
4690 -- sources, except the one which is a fake main subprogram:
4691 -- this is the one for the binder generated file and it will be
4692 -- transmitted to gnatlink. These sources are those that are
4695 Add_Switch ("-n", Binder, And_Save => True);
4697 for J in Q.First .. Q.Last - 1 loop
4700 (Lib_File_Name (Q.Table (J).File)),
4701 Binder, And_Save => True);
4705 elsif Main_Index /= 0 and then Osint.Number_Of_Files > 1 then
4706 Make_Failed ("cannot specify several mains with a multi-unit index");
4708 elsif Main_Project /= No_Project then
4710 -- If the main project file is a library project file, main(s)
4711 -- cannot be specified on the command line.
4713 if Osint.Number_Of_Files /= 0 then
4714 if Project_Tree.Projects.Table (Main_Project).Library
4715 and then not Unique_Compile
4716 and then ((not Make_Steps) or else Bind_Only or else Link_Only)
4718 Make_Failed ("cannot specify a main program " &
4719 "on the command line for a library project file");
4722 -- Check that each main on the command line is a source of a
4723 -- project file and, if there are several mains, each of them
4724 -- is a source of the same project file.
4729 -- If no mains have been specified on the command line,
4730 -- and we are using a project file, we either find the main(s)
4731 -- in the attribute Main of the main project, or we put all
4732 -- the sources of the project file as mains.
4735 if Main_Index /= 0 then
4736 Make_Failed ("cannot specify a multi-unit index but no main " &
4737 "on the command line");
4741 Value : String_List_Id :=
4742 Project_Tree.Projects.Table (Main_Project).Mains;
4745 -- The attribute Main is an empty list or not specified,
4746 -- or else gnatmake was invoked with the switch "-u".
4748 if Value = Prj.Nil_String or else Unique_Compile then
4750 if (not Make_Steps) or else Compile_Only
4751 or else not Project_Tree.Projects.Table
4752 (Main_Project).Library
4754 -- First make sure that the binder and the linker
4755 -- will not be invoked.
4757 Do_Bind_Step := False;
4758 Do_Link_Step := False;
4760 -- Put all the sources in the queue
4762 No_Main_Subprogram := True;
4763 Insert_Project_Sources
4764 (The_Project => Main_Project,
4765 All_Projects => Unique_Compile_All_Projects,
4768 -- If no sources to compile, then there is nothing to do
4770 if Osint.Number_Of_Files = 0 then
4771 if not Quiet_Output then
4772 Osint.Write_Program_Name;
4773 Write_Line (": no sources to compile");
4776 Delete_All_Temp_Files;
4777 Exit_Program (E_Success);
4782 -- The attribute Main is not an empty list.
4783 -- Put all the main subprograms in the list as if there
4784 -- were specified on the command line. However, if attribute
4785 -- Languages includes a language other than Ada, only
4786 -- include the Ada mains; if there is no Ada main, compile
4787 -- all the sources of the project.
4790 Data : constant Project_Data :=
4791 Project_Tree.Projects.Table (Main_Project);
4793 Languages : constant Variable_Value :=
4796 Data.Decl.Attributes,
4799 Current : String_List_Id;
4800 Element : String_Element;
4802 Foreign_Language : Boolean := False;
4803 At_Least_One_Main : Boolean := False;
4806 -- First, determine if there is a foreign language in
4807 -- attribute Languages.
4809 if not Languages.Default then
4810 Current := Languages.Values;
4813 while Current /= Nil_String loop
4814 Element := Project_Tree.String_Elements.
4816 Get_Name_String (Element.Value);
4817 To_Lower (Name_Buffer (1 .. Name_Len));
4819 if Name_Buffer (1 .. Name_Len) /= "ada" then
4820 Foreign_Language := True;
4821 exit Look_For_Foreign;
4824 Current := Element.Next;
4825 end loop Look_For_Foreign;
4828 -- Then, find all mains, or if there is a foreign
4829 -- language, all the Ada mains.
4831 while Value /= Prj.Nil_String loop
4833 (Project_Tree.String_Elements.Table
4836 -- To know if a main is an Ada main, get its project.
4837 -- It should be the project specified on the command
4840 if (not Foreign_Language) or else
4842 (Name_Buffer (1 .. Name_Len),
4847 At_Least_One_Main := True;
4850 (Project_Tree.String_Elements.Table
4853 Project_Tree.String_Elements.Table
4857 Value := Project_Tree.String_Elements.Table
4861 -- If we did not get any main, it means that all mains
4862 -- in attribute Mains are in a foreign language and -B
4863 -- was not specified to gnatmake; so, we fail.
4865 if not At_Least_One_Main then
4867 ("no Ada mains; use -B to build foreign main");
4876 if Verbose_Mode then
4878 Display_Version ("GNATMAKE ", "1995");
4881 if Main_Project /= No_Project
4882 and then Project_Tree.Projects.Table
4883 (Main_Project).Externally_Built
4886 ("nothing to do for a main project that is externally built");
4889 if Osint.Number_Of_Files = 0 then
4890 if Main_Project /= No_Project
4891 and then Project_Tree.Projects.Table (Main_Project).Library
4894 and then not Project_Tree.Projects.Table
4895 (Main_Project).Standalone_Library
4897 Make_Failed ("only stand-alone libraries may be bound");
4900 -- Add the default search directories to be able to find libgnat
4902 Osint.Add_Default_Search_Dirs;
4904 -- Get the target parameters, so that the correct binder generated
4905 -- files are generated if OpenVMS is the target.
4908 Targparm.Get_Target_Parameters;
4911 when Unrecoverable_Error =>
4912 Make_Failed ("*** make failed.");
4915 -- And bind and or link the library
4917 MLib.Prj.Build_Library
4918 (For_Project => Main_Project,
4919 In_Tree => Project_Tree,
4920 Gnatbind => Gnatbind.all,
4921 Gnatbind_Path => Gnatbind_Path,
4923 Gcc_Path => Gcc_Path,
4927 Delete_All_Temp_Files;
4928 Exit_Program (E_Success);
4931 -- Output usage information if no files to compile
4934 Exit_Program (E_Fatal);
4938 -- If -M was specified, behave as if -n was specified
4940 if List_Dependencies then
4941 Do_Not_Execute := True;
4944 -- Note that Osint.M.Next_Main_Source will always return the (possibly
4945 -- abbreviated file) without any directory information.
4947 Main_Source_File := Next_Main_Source;
4949 if Current_File_Index /= No_Index then
4950 Main_Index := Current_File_Index;
4953 Add_Switch ("-I-", Compiler, And_Save => True);
4955 if Main_Project = No_Project then
4956 if Look_In_Primary_Dir then
4960 Normalize_Directory_Name
4961 (Get_Primary_Src_Search_Directory.all).all,
4962 Compiler, Append_Switch => False,
4968 -- If we use a project file, we have already checked that a main
4969 -- specified on the command line with directory information has the
4970 -- path name corresponding to a correct source in the project tree.
4971 -- So, we don't need the directory information to be taken into
4972 -- account by Find_File, and in fact it may lead to take the wrong
4973 -- sources for other compilation units, when there are extending
4976 Look_In_Primary_Dir := False;
4977 Add_Switch ("-I-", Binder, And_Save => True);
4980 -- If the user wants a program without a main subprogram, add the
4981 -- appropriate switch to the binder.
4983 if No_Main_Subprogram then
4984 Add_Switch ("-z", Binder, And_Save => True);
4987 if Main_Project /= No_Project then
4989 if Project_Tree.Projects.Table
4990 (Main_Project).Object_Directory /= No_Path
4992 -- Change current directory to object directory of main project
4994 Project_Of_Current_Object_Directory := No_Project;
4995 Change_To_Object_Directory (Main_Project);
4998 -- Source file lookups should be cached for efficiency.
4999 -- Source files are not supposed to change.
5001 Osint.Source_File_Data (Cache => True);
5003 -- Find the file name of the (first) main unit
5006 Main_Source_File_Name : constant String :=
5007 Get_Name_String (Main_Source_File);
5008 Main_Unit_File_Name : constant String :=
5009 Prj.Env.File_Name_Of_Library_Unit_Body
5010 (Name => Main_Source_File_Name,
5011 Project => Main_Project,
5012 In_Tree => Project_Tree,
5013 Main_Project_Only =>
5014 not Unique_Compile);
5016 The_Packages : constant Package_Id :=
5017 Project_Tree.Projects.Table
5018 (Main_Project).Decl.Packages;
5020 Builder_Package : constant Prj.Package_Id :=
5022 (Name => Name_Builder,
5023 In_Packages => The_Packages,
5024 In_Tree => Project_Tree);
5026 Binder_Package : constant Prj.Package_Id :=
5028 (Name => Name_Binder,
5029 In_Packages => The_Packages,
5030 In_Tree => Project_Tree);
5032 Linker_Package : constant Prj.Package_Id :=
5034 (Name => Name_Linker,
5035 In_Packages => The_Packages,
5036 In_Tree => Project_Tree);
5039 -- We fail if we cannot find the main source file
5041 if Main_Unit_File_Name = "" then
5042 Make_Failed ('"' & Main_Source_File_Name,
5043 """ is not a unit of project ",
5044 Project_File_Name.all & ".");
5046 -- Remove any directory information from the main
5047 -- source file name.
5050 Pos : Natural := Main_Unit_File_Name'Last;
5054 exit when Pos < Main_Unit_File_Name'First or else
5055 Main_Unit_File_Name (Pos) = Directory_Separator;
5059 Name_Len := Main_Unit_File_Name'Last - Pos;
5061 Name_Buffer (1 .. Name_Len) :=
5063 (Pos + 1 .. Main_Unit_File_Name'Last);
5065 Main_Source_File := Name_Find;
5067 -- We only output the main source file if there is only one
5069 if Verbose_Mode and then Osint.Number_Of_Files = 1 then
5070 Write_Str ("Main source file: """);
5071 Write_Str (Main_Unit_File_Name
5072 (Pos + 1 .. Main_Unit_File_Name'Last));
5078 -- If there is a package Builder in the main project file, add
5079 -- the switches from it.
5081 if Builder_Package /= No_Package then
5083 -- If there is only one main, we attempt to get the gnatmake
5084 -- switches for this main (if any). If there are no specific
5085 -- switch for this particular main, get the general gnatmake
5086 -- switches (if any).
5088 if Osint.Number_Of_Files = 1 then
5089 if Verbose_Mode then
5090 Write_Str ("Adding gnatmake switches for """);
5091 Write_Str (Main_Unit_File_Name);
5096 (File_Name => Main_Unit_File_Name,
5097 Index => Main_Index,
5098 The_Package => Builder_Package,
5102 -- If there are several mains, we always get the general
5103 -- gnatmake switches (if any).
5105 -- Warn the user, if necessary, so that he is not surprised
5106 -- that specific switches are not taken into account.
5109 Defaults : constant Variable_Value :=
5113 Attribute_Or_Array_Name => Name_Default_Switches,
5114 In_Package => Builder_Package,
5115 In_Tree => Project_Tree);
5117 Switches : constant Array_Element_Id :=
5119 (Name => Name_Switches,
5121 Project_Tree.Packages.Table
5122 (Builder_Package).Decl.Arrays,
5123 In_Tree => Project_Tree);
5126 if Defaults /= Nil_Variable_Value then
5127 if (not Quiet_Output)
5128 and then Switches /= No_Array_Element
5131 ("Warning: using Builder'Default_Switches" &
5132 "(""Ada""), as there are several mains");
5135 -- As there is never a source with name " ", we are
5136 -- guaranteed to always get the general switches.
5141 The_Package => Builder_Package,
5144 elsif (not Quiet_Output)
5145 and then Switches /= No_Array_Element
5148 ("Warning: using no switches from package Builder," &
5149 " as there are several mains");
5155 Osint.Add_Default_Search_Dirs;
5157 -- Record the current last switch index for table Binder_Switches
5158 -- and Linker_Switches, so that these tables may be reset before
5159 -- for each main, before adding switches from the project file
5160 -- and from the command line.
5162 Last_Binder_Switch := Binder_Switches.Last;
5163 Last_Linker_Switch := Linker_Switches.Last;
5167 -- Add binder switches from the project file for the first main
5169 if Do_Bind_Step and Binder_Package /= No_Package then
5170 if Verbose_Mode then
5171 Write_Str ("Adding binder switches for """);
5172 Write_Str (Main_Unit_File_Name);
5177 (File_Name => Main_Unit_File_Name,
5178 Index => Main_Index,
5179 The_Package => Binder_Package,
5183 -- Add linker switches from the project file for the first main
5185 if Do_Link_Step and Linker_Package /= No_Package then
5186 if Verbose_Mode then
5187 Write_Str ("Adding linker switches for""");
5188 Write_Str (Main_Unit_File_Name);
5193 (File_Name => Main_Unit_File_Name,
5194 Index => Main_Index,
5195 The_Package => Linker_Package,
5201 -- Get the target parameters, which are only needed for a couple of
5202 -- cases in gnatmake. Protect against an exception, such as the case
5203 -- of system.ads missing from the library, and fail gracefully.
5206 Targparm.Get_Target_Parameters;
5208 when Unrecoverable_Error =>
5209 Make_Failed ("*** make failed.");
5212 -- Special processing for VM targets
5214 if Targparm.VM_Target /= No_VM then
5216 -- Set proper processing commands
5218 case Targparm.VM_Target is
5219 when Targparm.JVM_Target =>
5221 -- Do not check for an object file (".o") when compiling to
5222 -- JVM machine since ".class" files are generated instead.
5224 Check_Object_Consistency := False;
5226 Gcc := new String'("jgnat");
5227 Gnatbind := new String'("jgnatbind");
5228 Gnatlink := new String'("jgnatlink");
5230 when Targparm.CLI_Target =>
5231 Gcc := new String'("dotnet-gnatcompile");
5233 when Targparm.No_VM =>
5234 raise Program_Error;
5238 Display_Commands (not Quiet_Output);
5242 if Main_Project /= No_Project then
5244 -- For all library project, if the library file does not exist, put
5245 -- all the project sources in the queue, and flag the project so that
5246 -- the library is generated.
5248 if not Unique_Compile
5249 and then MLib.Tgt.Support_For_Libraries /= Prj.None
5251 for Proj in Project_Table.First ..
5252 Project_Table.Last (Project_Tree.Projects)
5254 if Project_Tree.Projects.Table (Proj).Library then
5255 Project_Tree.Projects.Table
5256 (Proj).Need_To_Build_Lib :=
5257 (not MLib.Tgt.Library_Exists_For (Proj, Project_Tree))
5258 and then (not Project_Tree.Projects.Table
5259 (Proj).Externally_Built);
5261 if Project_Tree.Projects.Table (Proj).Need_To_Build_Lib then
5263 -- If there is no object directory, then it will be
5264 -- impossible to build the library. So fail immediately.
5266 if Project_Tree.Projects.Table (Proj).Object_Directory =
5270 ("no object files to build library for project """,
5272 (Project_Tree.Projects.Table (Proj).Name),
5274 Project_Tree.Projects.Table
5275 (Proj).Need_To_Build_Lib := False;
5278 if Verbose_Mode then
5280 ("Library file does not exist for project """);
5283 (Project_Tree.Projects.Table
5288 Insert_Project_Sources
5289 (The_Project => Proj,
5290 All_Projects => False,
5298 -- If a relative path output file has been specified, we add
5299 -- the exec directory.
5301 for J in reverse 1 .. Saved_Linker_Switches.Last - 1 loop
5302 if Saved_Linker_Switches.Table (J).all = Output_Flag.all then
5304 Exec_File_Name : constant String :=
5305 Saved_Linker_Switches.Table (J + 1).all;
5308 if not Is_Absolute_Path (Exec_File_Name) then
5310 (Project_Tree.Projects.Table
5311 (Main_Project).Exec_Directory);
5313 if Name_Buffer (Name_Len) /= Directory_Separator then
5314 Name_Len := Name_Len + 1;
5315 Name_Buffer (Name_Len) := Directory_Separator;
5318 Name_Buffer (Name_Len + 1 ..
5319 Name_Len + Exec_File_Name'Length) :=
5321 Name_Len := Name_Len + Exec_File_Name'Length;
5322 Saved_Linker_Switches.Table (J + 1) :=
5323 new String'(Name_Buffer (1 .. Name_Len));
5331 -- If we are using a project file, for relative paths we add the
5332 -- current working directory for any relative path on the command
5333 -- line and the project directory, for any relative path in the
5337 Dir_Path : constant String_Access :=
5338 new String'(Get_Name_String
5339 (Project_Tree.Projects.Table
5340 (Main_Project).Directory));
5342 for J in 1 .. Binder_Switches.Last loop
5343 Test_If_Relative_Path
5344 (Binder_Switches.Table (J),
5345 Parent => Dir_Path, Including_L_Switch => False);
5348 for J in 1 .. Saved_Binder_Switches.Last loop
5349 Test_If_Relative_Path
5350 (Saved_Binder_Switches.Table (J),
5351 Parent => Current_Work_Dir, Including_L_Switch => False);
5354 for J in 1 .. Linker_Switches.Last loop
5355 Test_If_Relative_Path
5356 (Linker_Switches.Table (J), Parent => Dir_Path);
5359 for J in 1 .. Saved_Linker_Switches.Last loop
5360 Test_If_Relative_Path
5361 (Saved_Linker_Switches.Table (J), Parent => Current_Work_Dir);
5364 for J in 1 .. Gcc_Switches.Last loop
5365 Test_If_Relative_Path
5366 (Gcc_Switches.Table (J),
5368 Including_Non_Switch => False);
5371 for J in 1 .. Saved_Gcc_Switches.Last loop
5372 Test_If_Relative_Path
5373 (Saved_Gcc_Switches.Table (J),
5374 Parent => Current_Work_Dir,
5375 Including_Non_Switch => False);
5380 -- We now put in the Binder_Switches and Linker_Switches tables, the
5381 -- binder and linker switches of the command line that have been put in
5382 -- the Saved_ tables. If a project file was used, then the command line
5383 -- switches will follow the project file switches.
5385 for J in 1 .. Saved_Binder_Switches.Last loop
5387 (Saved_Binder_Switches.Table (J),
5392 for J in 1 .. Saved_Linker_Switches.Last loop
5394 (Saved_Linker_Switches.Table (J),
5399 -- If no project file is used, we just put the gcc switches
5400 -- from the command line in the Gcc_Switches table.
5402 if Main_Project = No_Project then
5403 for J in 1 .. Saved_Gcc_Switches.Last loop
5405 (Saved_Gcc_Switches.Table (J),
5411 -- If there is a project, put the command line gcc switches in the
5412 -- variable The_Saved_Gcc_Switches. They are going to be used later
5413 -- in procedure Compile_Sources.
5415 The_Saved_Gcc_Switches :=
5416 new Argument_List (1 .. Saved_Gcc_Switches.Last + 1);
5418 for J in 1 .. Saved_Gcc_Switches.Last loop
5419 The_Saved_Gcc_Switches (J) := Saved_Gcc_Switches.Table (J);
5422 -- We never use gnat.adc when a project file is used
5424 The_Saved_Gcc_Switches (The_Saved_Gcc_Switches'Last) :=
5428 -- If there was a --GCC, --GNATBIND or --GNATLINK switch on
5429 -- the command line, then we have to use it, even if there was
5430 -- another switch in the project file.
5432 if Saved_Gcc /= null then
5436 if Saved_Gnatbind /= null then
5437 Gnatbind := Saved_Gnatbind;
5440 if Saved_Gnatlink /= null then
5441 Gnatlink := Saved_Gnatlink;
5444 Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
5445 Gnatbind_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
5446 Gnatlink_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
5448 -- If we have specified -j switch both from the project file
5449 -- and on the command line, the one from the command line takes
5452 if Saved_Maximum_Processes = 0 then
5453 Saved_Maximum_Processes := Maximum_Processes;
5456 -- Allocate as many temporary mapping file names as the maximum
5457 -- number of compilation processed, for each possible project.
5459 The_Mapping_File_Names :=
5461 (No_Project .. Project_Table.Last (Project_Tree.Projects),
5462 1 .. Saved_Maximum_Processes);
5463 Last_Mapping_File_Names :=
5465 (No_Project .. Project_Table.Last (Project_Tree.Projects)
5468 The_Free_Mapping_File_Indices :=
5469 new Free_File_Indices
5470 (No_Project .. Project_Table.Last (Project_Tree.Projects),
5471 1 .. Saved_Maximum_Processes);
5472 Last_Free_Indices :=
5473 new Indices'(No_Project .. Project_Table.Last
5474 (Project_Tree.Projects) => 0);
5476 Bad_Compilation.Init;
5478 -- If project files are used, create the mapping of all the sources,
5479 -- so that the correct paths will be found. Otherwise, if there is
5480 -- a file which is not a source with the same name in a source directory
5481 -- this file may be incorrectly found.
5483 if Main_Project /= No_Project then
5484 Prj.Env.Create_Mapping (Project_Tree);
5487 Current_Main_Index := Main_Index;
5489 -- Here is where the make process is started
5491 -- We do the same process for each main
5493 Multiple_Main_Loop : for N_File in 1 .. Osint.Number_Of_Files loop
5495 -- First, find the executable name and path
5497 Executable := No_File;
5498 Executable_Obsolete := False;
5499 Non_Std_Executable :=
5500 Targparm.Executable_Extension_On_Target /= No_Name;
5502 -- Look inside the linker switches to see if the name of the final
5503 -- executable program was specified.
5506 J in reverse Linker_Switches.First .. Linker_Switches.Last
5508 if Linker_Switches.Table (J).all = Output_Flag.all then
5509 pragma Assert (J < Linker_Switches.Last);
5511 -- We cannot specify a single executable for several
5512 -- main subprograms!
5514 if Osint.Number_Of_Files > 1 then
5516 ("cannot specify a single executable " &
5517 "for several mains");
5520 Name_Len := Linker_Switches.Table (J + 1)'Length;
5521 Name_Buffer (1 .. Name_Len) :=
5522 Linker_Switches.Table (J + 1).all;
5523 Executable := Name_Enter;
5525 Verbose_Msg (Executable, "final executable");
5529 -- If the name of the final executable program was not specified
5530 -- then construct it from the main input file.
5532 if Executable = No_File then
5533 if Main_Project = No_Project then
5535 Executable_Name (Strip_Suffix (Main_Source_File));
5538 -- If we are using a project file, we attempt to remove the
5539 -- body (or spec) termination of the main subprogram. We find
5540 -- it the naming scheme of the project file. This avoids
5541 -- generating an executable "main.2" for a main subprogram
5542 -- "main.2.ada", when the body termination is ".2.ada".
5545 Prj.Util.Executable_Of
5546 (Main_Project, Project_Tree, Main_Source_File, Main_Index);
5550 if Main_Project /= No_Project then
5552 Exec_File_Name : constant String :=
5553 Get_Name_String (Executable);
5556 if not Is_Absolute_Path (Exec_File_Name) then
5557 Get_Name_String (Project_Tree.Projects.Table
5558 (Main_Project).Display_Exec_Dir);
5560 if Name_Buffer (Name_Len) /= Directory_Separator then
5561 Name_Len := Name_Len + 1;
5562 Name_Buffer (Name_Len) := Directory_Separator;
5565 Name_Buffer (Name_Len + 1 ..
5566 Name_Len + Exec_File_Name'Length) :=
5569 Name_Len := Name_Len + Exec_File_Name'Length;
5570 Executable := Name_Find;
5573 Non_Std_Executable := True;
5577 if Do_Compile_Step then
5578 Recursive_Compilation_Step : declare
5579 Args : Argument_List (1 .. Gcc_Switches.Last);
5581 First_Compiled_File : File_Name_Type;
5582 Youngest_Obj_File : File_Name_Type;
5583 Youngest_Obj_Stamp : Time_Stamp_Type;
5585 Executable_Stamp : Time_Stamp_Type;
5586 -- Executable is the final executable program
5588 Library_Rebuilt : Boolean := False;
5591 for J in 1 .. Gcc_Switches.Last loop
5592 Args (J) := Gcc_Switches.Table (J);
5595 -- Now we invoke Compile_Sources for the current main
5598 (Main_Source => Main_Source_File,
5600 First_Compiled_File => First_Compiled_File,
5601 Most_Recent_Obj_File => Youngest_Obj_File,
5602 Most_Recent_Obj_Stamp => Youngest_Obj_Stamp,
5603 Main_Unit => Is_Main_Unit,
5604 Main_Index => Current_Main_Index,
5605 Compilation_Failures => Compilation_Failures,
5606 Check_Readonly_Files => Check_Readonly_Files,
5607 Do_Not_Execute => Do_Not_Execute,
5608 Force_Compilations => Force_Compilations,
5609 In_Place_Mode => In_Place_Mode,
5610 Keep_Going => Keep_Going,
5611 Initialize_ALI_Data => True,
5612 Max_Process => Saved_Maximum_Processes);
5614 if Verbose_Mode then
5615 Write_Str ("End of compilation");
5619 -- Make sure the queue will be reinitialized for the next round
5621 First_Q_Initialization := True;
5623 Total_Compilation_Failures :=
5624 Total_Compilation_Failures + Compilation_Failures;
5626 if Total_Compilation_Failures /= 0 then
5630 List_Bad_Compilations;
5631 Report_Compilation_Failed;
5635 -- Regenerate libraries, if there are any and if object files
5636 -- have been regenerated.
5638 if Main_Project /= No_Project
5639 and then MLib.Tgt.Support_For_Libraries /= Prj.None
5640 and then (Do_Bind_Step
5641 or Unique_Compile_All_Projects
5642 or not Compile_Only)
5643 and then (Do_Link_Step or N_File = Osint.Number_Of_Files)
5651 procedure Add_To_Library_Projs (Proj : Project_Id);
5652 -- Add project Project to table Library_Projs in
5653 -- decreasing depth order.
5655 --------------------------
5656 -- Add_To_Library_Projs --
5657 --------------------------
5659 procedure Add_To_Library_Projs (Proj : Project_Id) is
5663 Library_Projs.Increment_Last;
5664 Depth := Project_Tree.Projects.Table (Proj).Depth;
5666 -- Put the projects in decreasing depth order, so that
5667 -- if libA depends on libB, libB is first in order.
5669 Current := Library_Projs.Last;
5670 while Current > 1 loop
5671 Prj := Library_Projs.Table (Current - 1);
5672 exit when Project_Tree.Projects.Table
5673 (Prj).Depth >= Depth;
5674 Library_Projs.Table (Current) := Prj;
5675 Current := Current - 1;
5678 Library_Projs.Table (Current) := Proj;
5679 end Add_To_Library_Projs;
5681 -- Start of processing for ??? (should name declare block
5682 -- or probably better, break this out as a nested proc).
5685 -- Put in Library_Projs table all library project
5686 -- file ids when the library need to be rebuilt.
5688 for Proj1 in Project_Table.First ..
5689 Project_Table.Last (Project_Tree.Projects)
5691 if Project_Tree.Projects.Table
5692 (Proj1).Standalone_Library
5694 There_Are_Stand_Alone_Libraries := True;
5697 if Project_Tree.Projects.Table (Proj1).Library then
5698 MLib.Prj.Check_Library (Proj1, Project_Tree);
5701 if Project_Tree.Projects.Table
5702 (Proj1).Need_To_Build_Lib
5704 Add_To_Library_Projs (Proj1);
5708 -- Check if importing libraries should be regenerated
5709 -- because at least an imported library will be
5710 -- regenerated or is more recent.
5712 for Proj1 in Project_Table.First ..
5713 Project_Table.Last (Project_Tree.Projects)
5715 if Project_Tree.Projects.Table (Proj1).Library
5717 Project_Tree.Projects.Table (Proj1).Library_Kind /=
5719 and then not Project_Tree.Projects.Table
5720 (Proj1).Need_To_Build_Lib
5721 and then not Project_Tree.Projects.Table
5722 (Proj1).Externally_Built
5725 List : Project_List;
5726 Element : Project_Element;
5728 Rebuild : Boolean := False;
5730 Lib_Timestamp1 : constant Time_Stamp_Type :=
5731 Project_Tree.Projects.Table
5735 List := Project_Tree.Projects.Table (Proj1).
5736 All_Imported_Projects;
5737 while List /= Empty_Project_List loop
5739 Project_Tree.Project_Lists.Table (List);
5740 Proj2 := Element.Project;
5743 Project_Tree.Projects.Table (Proj2).Library
5745 if Project_Tree.Projects.Table (Proj2).
5749 Project_Tree.Projects.Table
5757 List := Element.Next;
5761 Project_Tree.Projects.Table
5762 (Proj1).Need_To_Build_Lib := True;
5763 Add_To_Library_Projs (Proj1);
5769 -- Reset the flags Need_To_Build_Lib for the next main,
5770 -- to avoid rebuilding libraries uselessly.
5772 for Proj1 in Project_Table.First ..
5773 Project_Table.Last (Project_Tree.Projects)
5775 Project_Tree.Projects.Table
5776 (Proj1).Need_To_Build_Lib := False;
5780 -- Build the libraries, if any need to be built
5782 for J in 1 .. Library_Projs.Last loop
5783 Library_Rebuilt := True;
5785 -- If a library is rebuilt, then executables are obsolete
5787 Executable_Obsolete := True;
5789 MLib.Prj.Build_Library
5790 (For_Project => Library_Projs.Table (J),
5791 In_Tree => Project_Tree,
5792 Gnatbind => Gnatbind.all,
5793 Gnatbind_Path => Gnatbind_Path,
5795 Gcc_Path => Gcc_Path);
5799 if List_Dependencies then
5800 if First_Compiled_File /= No_File then
5802 (First_Compiled_File,
5803 "must be recompiled. Can't generate dependence list.");
5808 elsif First_Compiled_File = No_File
5809 and then not Do_Bind_Step
5810 and then not Quiet_Output
5811 and then not Library_Rebuilt
5812 and then Osint.Number_Of_Files = 1
5814 Inform (Msg => "objects up to date.");
5816 elsif Do_Not_Execute
5817 and then First_Compiled_File /= No_File
5819 Write_Name (First_Compiled_File);
5823 -- Stop after compile step if any of:
5825 -- 1) -n (Do_Not_Execute) specified
5827 -- 2) -M (List_Dependencies) specified (also sets
5828 -- Do_Not_Execute above, so this is probably superfluous).
5830 -- 3) -c (Compile_Only) specified, but not -b (Bind_Only)
5832 -- 4) Made unit cannot be a main unit
5835 or List_Dependencies
5837 or not Is_Main_Unit)
5838 and then not No_Main_Subprogram
5839 and then not Build_Bind_And_Link_Full_Project)
5840 or else Unique_Compile
5842 if Osint.Number_Of_Files = 1 then
5843 exit Multiple_Main_Loop;
5850 -- If the objects were up-to-date check if the executable file
5851 -- is also up-to-date. For now always bind and link on the JVM
5852 -- since there is currently no simple way to check the
5853 -- up-to-date status of objects
5855 if Targparm.VM_Target /= JVM_Target
5856 and then First_Compiled_File = No_File
5858 Executable_Stamp := File_Stamp (Executable);
5860 if not Executable_Obsolete then
5861 Executable_Obsolete :=
5862 Youngest_Obj_Stamp > Executable_Stamp;
5865 if not Executable_Obsolete then
5866 for Index in reverse 1 .. Dependencies.Last loop
5868 (Dependencies.Table (Index).Depends_On)
5870 Enter_Into_Obsoleted
5871 (Dependencies.Table (Index).This);
5875 Executable_Obsolete := Is_In_Obsoleted (Main_Source_File);
5879 if not Executable_Obsolete then
5881 -- If no Ada object files obsolete the executable, check
5882 -- for younger or missing linker files.
5884 Check_Linker_Options
5887 Youngest_Obj_Stamp);
5889 Executable_Obsolete := Youngest_Obj_File /= No_File;
5892 -- Return if the executable is up to date
5893 -- and otherwise motivate the relink/rebind.
5895 if not Executable_Obsolete then
5896 if not Quiet_Output then
5897 Inform (Executable, "up to date.");
5900 if Osint.Number_Of_Files = 1 then
5901 exit Multiple_Main_Loop;
5908 if Executable_Stamp (1) = ' ' then
5909 if not No_Main_Subprogram then
5910 Verbose_Msg (Executable, "missing.", Prefix => " ");
5913 elsif Youngest_Obj_Stamp (1) = ' ' then
5915 (Youngest_Obj_File, "missing.", Prefix => " ");
5917 elsif Youngest_Obj_Stamp > Executable_Stamp then
5920 "(" & String (Youngest_Obj_Stamp) & ") newer than",
5922 "(" & String (Executable_Stamp) & ")");
5926 (Executable, "needs to be rebuilt", Prefix => " ");
5930 end Recursive_Compilation_Step;
5933 -- For binding and linking, we need to be in the object directory of
5934 -- the main project.
5936 if Main_Project /= No_Project then
5937 Change_To_Object_Directory (Main_Project);
5940 -- If we are here, it means that we need to rebuilt the current
5941 -- main. So we set Executable_Obsolete to True to make sure that
5942 -- the subsequent mains will be rebuilt.
5944 Main_ALI_In_Place_Mode_Step : declare
5945 ALI_File : File_Name_Type;
5946 Src_File : File_Name_Type;
5949 Src_File := Strip_Directory (Main_Source_File);
5950 ALI_File := Lib_File_Name (Src_File, Current_Main_Index);
5951 Main_ALI_File := Full_Lib_File_Name (ALI_File);
5953 -- When In_Place_Mode, the library file can be located in the
5954 -- Main_Source_File directory which may not be present in the
5955 -- library path. If it is not present then use the corresponding
5956 -- library file name.
5958 if Main_ALI_File = No_File and then In_Place_Mode then
5959 Get_Name_String (Get_Directory (Full_Source_Name (Src_File)));
5960 Get_Name_String_And_Append (ALI_File);
5961 Main_ALI_File := Name_Find;
5962 Main_ALI_File := Full_Lib_File_Name (Main_ALI_File);
5965 if Main_ALI_File = No_File then
5966 Make_Failed ("could not find the main ALI file");
5968 end Main_ALI_In_Place_Mode_Step;
5970 if Do_Bind_Step then
5972 Args : Argument_List
5973 (Binder_Switches.First .. Binder_Switches.Last + 2);
5974 -- The arguments for the invocation of gnatbind
5976 Last_Arg : Natural := Binder_Switches.Last;
5977 -- Index of the last argument in Args
5979 Shared_Libs : Boolean := False;
5980 -- Set to True when there are shared library project files or
5981 -- when gnatbind is invoked with -shared.
5984 -- Check if there are shared libraries, so that gnatbind is
5985 -- called with -shared. Check also if gnatbind is called with
5986 -- -shared, so that gnatlink is called with -shared-libgcc
5987 -- ensuring that the shared version of libgcc will be used.
5989 if Main_Project /= No_Project
5990 and then MLib.Tgt.Support_For_Libraries /= Prj.None
5992 for Proj in Project_Table.First ..
5993 Project_Table.Last (Project_Tree.Projects)
5995 if Project_Tree.Projects.Table (Proj).Library
5996 and then Project_Tree.Projects.Table
5997 (Proj).Library_Kind /= Static
5999 Shared_Libs := True;
6000 Bind_Shared := Shared_Switch'Access;
6006 -- Check now for switch -shared
6008 if not Shared_Libs then
6009 for J in Binder_Switches.First .. Last_Arg loop
6010 if Binder_Switches.Table (J).all = "-shared" then
6011 Shared_Libs := True;
6017 -- If shared libraries present, invoke gnatlink with
6021 Link_With_Shared_Libgcc := Shared_Libgcc_Switch'Access;
6024 -- Get all the binder switches
6026 for J in Binder_Switches.First .. Last_Arg loop
6027 Args (J) := Binder_Switches.Table (J);
6030 if There_Are_Stand_Alone_Libraries then
6031 Last_Arg := Last_Arg + 1;
6032 Args (Last_Arg) := Force_Elab_Flags_String'Access;
6035 if Main_Project /= No_Project then
6037 -- Put all the source directories in ADA_INCLUDE_PATH,
6038 -- and all the object directories in ADA_OBJECTS_PATH.
6040 Prj.Env.Set_Ada_Paths (Main_Project, Project_Tree, False);
6042 -- If switch -C was specified, create a binder mapping file
6044 if Create_Mapping_File then
6045 Create_Binder_Mapping_File (Args, Last_Arg);
6051 Bind (Main_ALI_File,
6052 Bind_Shared.all & Args (Args'First .. Last_Arg));
6057 -- If -dn was not specified, delete the temporary mapping
6058 -- file, if one was created.
6060 if not Debug.Debug_Flag_N
6061 and then Mapping_Path /= No_Path
6063 Delete_File (Get_Name_String (Mapping_Path), Discard);
6066 -- And reraise the exception
6071 -- If -dn was not specified, delete the temporary mapping file,
6072 -- if one was created.
6074 if not Debug.Debug_Flag_N and then Mapping_Path /= No_Path then
6075 Delete_File (Get_Name_String (Mapping_Path), Discard);
6080 if Do_Link_Step then
6082 Linker_Switches_Last : constant Integer := Linker_Switches.Last;
6083 Path_Option : constant String_Access :=
6084 MLib.Linker_Library_Path_Option;
6085 There_Are_Libraries : Boolean := False;
6091 if not Run_Path_Option then
6092 Linker_Switches.Increment_Last;
6093 Linker_Switches.Table (Linker_Switches.Last) :=
6097 if Main_Project /= No_Project then
6098 Library_Paths.Set_Last (0);
6101 if MLib.Tgt.Support_For_Libraries /= Prj.None then
6103 -- Check for library projects
6105 for Proj1 in Project_Table.First ..
6106 Project_Table.Last (Project_Tree.Projects)
6108 if Proj1 /= Main_Project
6110 Project_Tree.Projects.Table (Proj1).Library
6112 -- Add this project to table Library_Projs
6114 There_Are_Libraries := True;
6115 Depth := Project_Tree.Projects.Table (Proj1).Depth;
6116 Library_Projs.Increment_Last;
6117 Current := Library_Projs.Last;
6119 -- Any project with a greater depth should be
6120 -- after this project in the list.
6122 while Current > 1 loop
6123 Proj2 := Library_Projs.Table (Current - 1);
6124 exit when Project_Tree.Projects.Table
6125 (Proj2).Depth <= Depth;
6126 Library_Projs.Table (Current) := Proj2;
6127 Current := Current - 1;
6130 Library_Projs.Table (Current) := Proj1;
6132 -- If it is not a static library and path option
6133 -- is set, add it to the Library_Paths table.
6135 if Project_Tree.Projects.Table
6136 (Proj1).Library_Kind /= Static
6137 and then Path_Option /= null
6139 Library_Paths.Increment_Last;
6140 Library_Paths.Table (Library_Paths.Last) :=
6143 (Project_Tree.Projects.Table
6144 (Proj1).Display_Library_Dir));
6149 for Index in 1 .. Library_Projs.Last loop
6151 -- Add the -L switch
6153 Linker_Switches.Increment_Last;
6154 Linker_Switches.Table (Linker_Switches.Last) :=
6157 (Project_Tree.Projects.Table
6158 (Library_Projs.Table (Index)).
6159 Display_Library_Dir));
6161 -- Add the -l switch
6163 Linker_Switches.Increment_Last;
6164 Linker_Switches.Table (Linker_Switches.Last) :=
6167 (Project_Tree.Projects.Table
6168 (Library_Projs.Table (Index)).
6173 if There_Are_Libraries then
6175 -- If Path_Option is not null, create the switch
6176 -- ("-Wl,-rpath," or equivalent) with all the non static
6177 -- library dirs plus the standard GNAT library dir.
6178 -- We do that only if Run_Path_Option is True
6179 -- (not disabled by -R switch).
6181 if Run_Path_Option and Path_Option /= null then
6183 Option : String_Access;
6184 Length : Natural := Path_Option'Length;
6189 Library_Paths.First .. Library_Paths.Last
6191 -- Add the length of the library dir plus one
6192 -- for the directory separator.
6196 Library_Paths.Table (Index)'Length + 1;
6199 -- Finally, add the length of the standard GNAT
6202 Length := Length + MLib.Utl.Lib_Directory'Length;
6203 Option := new String (1 .. Length);
6204 Option (1 .. Path_Option'Length) := Path_Option.all;
6205 Current := Path_Option'Length;
6207 -- Put each library dir followed by a dir separator
6210 Library_Paths.First .. Library_Paths.Last
6215 Library_Paths.Table (Index)'Length) :=
6216 Library_Paths.Table (Index).all;
6219 Library_Paths.Table (Index)'Length + 1;
6220 Option (Current) := Path_Separator;
6223 -- Finally put the standard GNAT library dir
6227 Current + MLib.Utl.Lib_Directory'Length) :=
6228 MLib.Utl.Lib_Directory;
6230 -- And add the switch to the linker switches
6232 Linker_Switches.Increment_Last;
6233 Linker_Switches.Table (Linker_Switches.Last) :=
6240 -- Put the object directories in ADA_OBJECTS_PATH
6242 Prj.Env.Set_Ada_Paths (Main_Project, Project_Tree, False);
6244 -- Check for attributes Linker'Linker_Options in projects
6245 -- other than the main project
6248 Linker_Options : constant String_List :=
6249 Linker_Options_Switches
6250 (Main_Project, Project_Tree);
6252 for Option in Linker_Options'Range loop
6253 Linker_Switches.Increment_Last;
6254 Linker_Switches.Table (Linker_Switches.Last) :=
6255 Linker_Options (Option);
6261 Args : Argument_List
6262 (Linker_Switches.First .. Linker_Switches.Last + 2);
6264 Last_Arg : Integer := Linker_Switches.First - 1;
6265 Skip : Boolean := False;
6268 -- Get all the linker switches
6270 for J in Linker_Switches.First .. Linker_Switches.Last loop
6274 elsif Non_Std_Executable
6275 and then Linker_Switches.Table (J).all = "-o"
6280 Last_Arg := Last_Arg + 1;
6281 Args (Last_Arg) := Linker_Switches.Table (J);
6285 -- If need be, add the -o switch
6287 if Non_Std_Executable then
6288 Last_Arg := Last_Arg + 1;
6289 Args (Last_Arg) := new String'("-o");
6290 Last_Arg := Last_Arg + 1;
6292 new String'(Get_Name_String (Executable));
6295 -- And invoke the linker
6298 Success : Boolean := False;
6300 Link (Main_ALI_File,
6301 Link_With_Shared_Libgcc.all &
6302 Args (Args'First .. Last_Arg),
6306 Successful_Links.Increment_Last;
6307 Successful_Links.Table (Successful_Links.Last) :=
6310 elsif Osint.Number_Of_Files = 1 or not Keep_Going then
6311 Make_Failed ("*** link failed.");
6315 Write_Line ("*** link failed");
6317 if Commands_To_Stdout then
6318 Set_Standard_Output;
6321 Failed_Links.Increment_Last;
6322 Failed_Links.Table (Failed_Links.Last) :=
6328 Linker_Switches.Set_Last (Linker_Switches_Last);
6332 -- We go to here when we skip the bind and link steps
6336 -- We go to the next main, if we did not process the last one
6338 if N_File < Osint.Number_Of_Files then
6339 Main_Source_File := Next_Main_Source;
6341 if Current_File_Index /= No_Index then
6342 Main_Index := Current_File_Index;
6345 if Main_Project /= No_Project then
6347 -- Find the file name of the main unit
6350 Main_Source_File_Name : constant String :=
6351 Get_Name_String (Main_Source_File);
6353 Main_Unit_File_Name : constant String :=
6355 File_Name_Of_Library_Unit_Body
6356 (Name => Main_Source_File_Name,
6357 Project => Main_Project,
6358 In_Tree => Project_Tree,
6359 Main_Project_Only =>
6360 not Unique_Compile);
6362 The_Packages : constant Package_Id :=
6363 Project_Tree.Projects.Table
6364 (Main_Project).Decl.Packages;
6366 Binder_Package : constant Prj.Package_Id :=
6368 (Name => Name_Binder,
6369 In_Packages => The_Packages,
6370 In_Tree => Project_Tree);
6372 Linker_Package : constant Prj.Package_Id :=
6374 (Name => Name_Linker,
6375 In_Packages => The_Packages,
6376 In_Tree => Project_Tree);
6379 -- We fail if we cannot find the main source file
6380 -- as an immediate source of the main project file.
6382 if Main_Unit_File_Name = "" then
6383 Make_Failed ('"' & Main_Source_File_Name,
6384 """ is not a unit of project ",
6385 Project_File_Name.all & ".");
6388 -- Remove any directory information from the main
6389 -- source file name.
6392 Pos : Natural := Main_Unit_File_Name'Last;
6396 exit when Pos < Main_Unit_File_Name'First
6398 Main_Unit_File_Name (Pos) = Directory_Separator;
6402 Name_Len := Main_Unit_File_Name'Last - Pos;
6404 Name_Buffer (1 .. Name_Len) :=
6406 (Pos + 1 .. Main_Unit_File_Name'Last);
6408 Main_Source_File := Name_Find;
6412 -- We now deal with the binder and linker switches.
6413 -- If no project file is used, there is nothing to do
6414 -- because the binder and linker switches are the same
6417 -- Reset the tables Binder_Switches and Linker_Switches
6419 Binder_Switches.Set_Last (Last_Binder_Switch);
6420 Linker_Switches.Set_Last (Last_Linker_Switch);
6422 -- Add binder switches from the project file for this main,
6425 if Do_Bind_Step and Binder_Package /= No_Package then
6426 if Verbose_Mode then
6427 Write_Str ("Adding binder switches for """);
6428 Write_Str (Main_Unit_File_Name);
6433 (File_Name => Main_Unit_File_Name,
6434 Index => Main_Index,
6435 The_Package => Binder_Package,
6439 -- Add linker switches from the project file for this main,
6442 if Do_Link_Step and Linker_Package /= No_Package then
6443 if Verbose_Mode then
6444 Write_Str ("Adding linker switches for""");
6445 Write_Str (Main_Unit_File_Name);
6450 (File_Name => Main_Unit_File_Name,
6451 Index => Main_Index,
6452 The_Package => Linker_Package,
6456 -- As we are using a project file, for relative paths we add
6457 -- the current working directory for any relative path on
6458 -- the command line and the project directory, for any
6459 -- relative path in the project file.
6462 Dir_Path : constant String_Access :=
6463 new String'(Get_Name_String
6464 (Project_Tree.Projects.Table
6465 (Main_Project).Directory));
6468 J in Last_Binder_Switch + 1 .. Binder_Switches.Last
6470 Test_If_Relative_Path
6471 (Binder_Switches.Table (J),
6472 Parent => Dir_Path, Including_L_Switch => False);
6476 J in Last_Linker_Switch + 1 .. Linker_Switches.Last
6478 Test_If_Relative_Path
6479 (Linker_Switches.Table (J), Parent => Dir_Path);
6483 -- We now put in the Binder_Switches and Linker_Switches
6484 -- tables, the binder and linker switches of the command
6485 -- line that have been put in the Saved_ tables.
6486 -- These switches will follow the project file switches.
6488 for J in 1 .. Saved_Binder_Switches.Last loop
6490 (Saved_Binder_Switches.Table (J),
6495 for J in 1 .. Saved_Linker_Switches.Last loop
6497 (Saved_Linker_Switches.Table (J),
6505 -- Remove all marks to be sure to check sources for all executables,
6506 -- as the switches may be different and -s may be in use.
6509 end loop Multiple_Main_Loop;
6511 if Failed_Links.Last > 0 then
6512 for Index in 1 .. Successful_Links.Last loop
6513 Write_Str ("Linking of """);
6514 Write_Str (Get_Name_String (Successful_Links.Table (Index)));
6515 Write_Line (""" succeeded.");
6520 for Index in 1 .. Failed_Links.Last loop
6521 Write_Str ("Linking of """);
6522 Write_Str (Get_Name_String (Failed_Links.Table (Index)));
6523 Write_Line (""" failed.");
6526 if Commands_To_Stdout then
6527 Set_Standard_Output;
6530 if Total_Compilation_Failures = 0 then
6531 Report_Compilation_Failed;
6535 if Total_Compilation_Failures /= 0 then
6536 List_Bad_Compilations;
6537 Report_Compilation_Failed;
6540 -- Delete the temporary mapping file that was created if we are
6541 -- using project files.
6543 Delete_All_Temp_Files;
6548 Write_Line (Exception_Information (X));
6549 Make_Failed ("INTERNAL ERROR. Please report.");
6556 function Hash (F : File_Name_Type) return Header_Num is
6558 return Header_Num (1 + F mod Max_Header);
6561 --------------------
6562 -- In_Ada_Lib_Dir --
6563 --------------------
6565 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean is
6566 D : constant File_Name_Type := Get_Directory (File);
6567 B : constant Byte := Get_Name_Table_Byte (D);
6569 return (B and Ada_Lib_Dir) /= 0;
6572 -----------------------
6573 -- Init_Mapping_File --
6574 -----------------------
6576 procedure Init_Mapping_File
6577 (Project : Project_Id;
6578 File_Index : in out Natural)
6580 FD : File_Descriptor;
6582 -- For call to Close
6585 -- Increase the index of the last mapping file for this project
6587 Last_Mapping_File_Names (Project) :=
6588 Last_Mapping_File_Names (Project) + 1;
6590 -- If there is a project file, call Create_Mapping_File with
6593 if Project /= No_Project then
6594 Prj.Env.Create_Mapping_File
6595 (Project, Project_Tree,
6596 The_Mapping_File_Names
6597 (Project, Last_Mapping_File_Names (Project)));
6599 -- Otherwise, just create an empty file
6602 Tempdir.Create_Temp_File
6604 The_Mapping_File_Names
6605 (No_Project, Last_Mapping_File_Names (No_Project)));
6607 if FD = Invalid_FD then
6608 Make_Failed ("disk full");
6612 (The_Mapping_File_Names
6613 (No_Project, Last_Mapping_File_Names (No_Project)));
6619 Make_Failed ("disk full");
6623 -- And return the index of the newly created file
6625 File_Index := Last_Mapping_File_Names (Project);
6626 end Init_Mapping_File;
6634 First_Q_Initialization := False;
6636 Q.Set_Last (Q.First);
6643 procedure Initialize is
6645 procedure Check_Version_And_Help is
6646 new Check_Version_And_Help_G (Makeusg);
6648 -- Start of processing for Initialize
6651 Prj.Set_Mode (Ada_Only);
6653 -- Override default initialization of Check_Object_Consistency since
6654 -- this is normally False for GNATBIND, but is True for GNATMAKE since
6655 -- we do not need to check source consistency again once GNATMAKE has
6656 -- looked at the sources to check.
6658 Check_Object_Consistency := True;
6660 -- Package initializations. The order of calls is important here
6662 Output.Set_Standard_Error;
6665 Binder_Switches.Init;
6666 Linker_Switches.Init;
6673 Prj.Initialize (Project_Tree);
6677 RTS_Specified := null;
6681 -- Add the directory where gnatmake is invoked in front of the
6682 -- path, if gnatmake is invoked from a bin directory or with directory
6683 -- information. Only do this if the platform is not VMS, where the
6684 -- notion of path does not really exist.
6688 Prefix : constant String := Executable_Prefix_Path;
6689 Command : constant String := Command_Name;
6692 if Prefix'Length > 0 then
6694 PATH : constant String :=
6695 Prefix & Directory_Separator & "bin" &
6697 Getenv ("PATH").all;
6699 Setenv ("PATH", PATH);
6703 for Index in reverse Command'Range loop
6704 if Command (Index) = Directory_Separator then
6706 Absolute_Dir : constant String :=
6708 (Command (Command'First .. Index));
6709 PATH : constant String :=
6712 Getenv ("PATH").all;
6714 Setenv ("PATH", PATH);
6724 -- Scan the switches and arguments
6726 -- First, scan to detect --version and/or --help
6728 Check_Version_And_Help ("GNATMAKE", "1995");
6730 -- Scan again the switch and arguments, now that we are sure that they
6731 -- do not include --version or --help.
6733 Scan_Args : for Next_Arg in 1 .. Argument_Count loop
6734 Scan_Make_Arg (Argument (Next_Arg), And_Save => True);
6737 if Commands_To_Stdout then
6738 Set_Standard_Output;
6741 if Usage_Requested then
6745 -- Test for trailing -P switch
6747 if Project_File_Name_Present and then Project_File_Name = null then
6748 Make_Failed ("project file name missing after -P");
6750 -- Test for trailing -o switch
6752 elsif Output_File_Name_Present
6753 and then not Output_File_Name_Seen
6755 Make_Failed ("output file name missing after -o");
6757 -- Test for trailing -D switch
6759 elsif Object_Directory_Present
6760 and then not Object_Directory_Seen then
6761 Make_Failed ("object directory missing after -D");
6764 -- Test for simultaneity of -i and -D
6766 if Object_Directory_Path /= null and then In_Place_Mode then
6767 Make_Failed ("-i and -D cannot be used simultaneously");
6770 -- Deal with -C= switch
6772 if Gnatmake_Mapping_File /= null then
6774 -- First, check compatibility with other switches
6776 if Project_File_Name /= null then
6777 Make_Failed ("-C= switch is not compatible with -P switch");
6779 elsif Saved_Maximum_Processes > 1 then
6780 Make_Failed ("-C= switch is not compatible with -jnnn switch");
6783 Fmap.Initialize (Gnatmake_Mapping_File.all);
6785 ("-gnatem=" & Gnatmake_Mapping_File.all,
6790 if Project_File_Name /= null then
6792 -- A project file was specified by a -P switch
6794 if Verbose_Mode then
6796 Write_Str ("Parsing project file """);
6797 Write_Str (Project_File_Name.all);
6802 -- Avoid looking in the current directory for ALI files
6804 -- Look_In_Primary_Dir := False;
6806 -- Set the project parsing verbosity to whatever was specified
6807 -- by a possible -vP switch.
6809 Prj.Pars.Set_Verbosity (To => Current_Verbosity);
6811 -- Parse the project file.
6812 -- If there is an error, Main_Project will still be No_Project.
6815 (Project => Main_Project,
6816 In_Tree => Project_Tree,
6817 Project_File_Name => Project_File_Name.all,
6818 Packages_To_Check => Packages_To_Check_By_Gnatmake);
6820 -- The parsing of project files may have changed the current output
6822 if Commands_To_Stdout then
6823 Set_Standard_Output;
6828 if Main_Project = No_Project then
6829 Make_Failed ("""", Project_File_Name.all, """ processing failed");
6832 Create_Mapping_File := True;
6834 if Verbose_Mode then
6836 Write_Str ("Parsing of project file """);
6837 Write_Str (Project_File_Name.all);
6838 Write_Str (""" is finished.");
6842 -- We add the source directories and the object directories
6843 -- to the search paths.
6845 Add_Source_Directories (Main_Project, Project_Tree);
6846 Add_Object_Directories (Main_Project, Project_Tree);
6848 -- Compute depth of each project
6850 for Proj in Project_Table.First ..
6851 Project_Table.Last (Project_Tree.Projects)
6853 Project_Tree.Projects.Table (Proj).Seen := False;
6854 Project_Tree.Projects.Table (Proj).Depth := 0;
6857 Recursive_Compute_Depth (Main_Project, Depth => 1);
6859 -- For each project compute the list of the projects it imports
6860 -- directly or indirectly.
6862 for Proj in Project_Table.First ..
6863 Project_Table.Last (Project_Tree.Projects)
6865 Compute_All_Imported_Projects (Proj);
6870 Osint.Add_Default_Search_Dirs;
6872 -- Source file lookups should be cached for efficiency. Source files
6873 -- are not supposed to change. However, we do that now only if no
6874 -- project file is used; if a project file is used, we do it just
6875 -- after changing the directory to the object directory.
6877 Osint.Source_File_Data (Cache => True);
6879 -- Read gnat.adc file to initialize Fname.UF
6881 Fname.UF.Initialize;
6884 Fname.SF.Read_Source_File_Name_Pragmas;
6887 when Err : SFN_Scan.Syntax_Error_In_GNAT_ADC =>
6888 Make_Failed (Exception_Message (Err));
6892 -- Make sure no project object directory is recorded
6894 Project_Of_Current_Object_Directory := No_Project;
6898 ----------------------------
6899 -- Insert_Project_Sources --
6900 ----------------------------
6902 procedure Insert_Project_Sources
6903 (The_Project : Project_Id;
6904 All_Projects : Boolean;
6907 Put_In_Q : Boolean := Into_Q;
6909 Sfile : File_Name_Type;
6912 Extending : constant Boolean :=
6913 Project_Tree.Projects.Table
6914 (The_Project).Extends /= No_Project;
6916 function Check_Project (P : Project_Id) return Boolean;
6917 -- Returns True if P is The_Project or a project extended by The_Project
6923 function Check_Project (P : Project_Id) return Boolean is
6925 if All_Projects or P = The_Project then
6928 elsif Extending then
6930 Data : Project_Data :=
6931 Project_Tree.Projects.Table (The_Project);
6935 if P = Data.Extends then
6939 Data := Project_Tree.Projects.Table (Data.Extends);
6940 exit when Data.Extends = No_Project;
6948 -- Start of processing for Insert_Project_Sources
6951 -- For all the sources in the project files,
6953 for Id in Unit_Table.First ..
6954 Unit_Table.Last (Project_Tree.Units)
6956 Unit := Project_Tree.Units.Table (Id);
6960 -- If there is a source for the body, and the body has not been
6963 if Unit.File_Names (Body_Part).Name /= No_File
6964 and then Unit.File_Names (Body_Part).Path /= Slash
6966 -- And it is a source for the specified project
6968 if Check_Project (Unit.File_Names (Body_Part).Project) then
6970 -- If we don't have a spec, we cannot consider the source
6971 -- if it is a subunit
6973 if Unit.File_Names (Specification).Name = No_File then
6975 Src_Ind : Source_File_Index;
6977 -- Here we are cheating a little bit: we don't want to
6978 -- use Sinput.L, because it depends on the GNAT tree
6979 -- (Atree, Sinfo, ...). So, we pretend that it is a
6980 -- project file, and we use Sinput.P.
6982 -- Source_File_Is_Subunit is just scanning through the
6983 -- file until it finds one of the reserved words
6984 -- separate, procedure, function, generic or package.
6985 -- Fortunately, these Ada reserved words are also
6986 -- reserved for project files.
6989 Src_Ind := Sinput.P.Load_Project_File
6991 (Unit.File_Names (Body_Part).Path));
6993 -- If it is a subunit, discard it
6995 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
6999 Sfile := Unit.File_Names (Body_Part).Display_Name;
7000 Index := Unit.File_Names (Body_Part).Index;
7005 Sfile := Unit.File_Names (Body_Part).Display_Name;
7006 Index := Unit.File_Names (Body_Part).Index;
7010 elsif Unit.File_Names (Specification).Name /= No_File
7011 and then Unit.File_Names (Specification).Path /= Slash
7012 and then Check_Project (Unit.File_Names (Specification).Project)
7014 -- If there is no source for the body, but there is a source
7015 -- for the spec which has not been locally removed, then we take
7018 Sfile := Unit.File_Names (Specification).Display_Name;
7019 Index := Unit.File_Names (Specification).Index;
7022 -- If Put_In_Q is True, we insert into the Q
7026 -- For the first source inserted into the Q, we need to initialize
7027 -- the Q, but not for the subsequent sources.
7029 if First_Q_Initialization then
7033 -- And of course, we only insert in the Q if the source is not
7036 if Sfile /= No_File and then not Is_Marked (Sfile, Index) then
7037 if Verbose_Mode then
7038 Write_Str ("Adding """);
7039 Write_Str (Get_Name_String (Sfile));
7040 Write_Line (""" to the queue");
7043 Insert_Q (Sfile, Index => Index);
7044 Mark (Sfile, Index);
7047 elsif Sfile /= No_File then
7049 -- If Put_In_Q is False, we add the source as it it were specified
7050 -- on the command line, and we set Put_In_Q to True, so that the
7051 -- following sources will be put directly in the queue. This will
7052 -- allow parallel compilation processes if -jx switch is used.
7054 if Verbose_Mode then
7055 Write_Str ("Adding """);
7056 Write_Str (Get_Name_String (Sfile));
7057 Write_Line (""" as if on the command line");
7060 Osint.Add_File (Get_Name_String (Sfile), Index);
7063 -- As we may look into the Q later, ensure the Q has been
7064 -- initialized to avoid errors.
7066 if First_Q_Initialization then
7071 end Insert_Project_Sources;
7078 (Source_File : File_Name_Type;
7079 Source_Unit : Unit_Name_Type := No_Unit_Name;
7083 if Debug.Debug_Flag_Q then
7084 Write_Str (" Q := Q + [ ");
7085 Write_Name (Source_File);
7097 (File => Source_File,
7098 Unit => Source_Unit,
7103 ---------------------
7104 -- Is_In_Obsoleted --
7105 ---------------------
7107 function Is_In_Obsoleted (F : File_Name_Type) return Boolean is
7114 Name : constant String := Get_Name_String (F);
7116 F2 : File_Name_Type;
7120 while First > Name'First
7121 and then Name (First - 1) /= Directory_Separator
7122 and then Name (First - 1) /= '/'
7127 if First /= Name'First then
7129 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
7136 return Obsoleted.Get (F2);
7139 end Is_In_Obsoleted;
7141 ----------------------------
7142 -- Is_In_Object_Directory --
7143 ----------------------------
7145 function Is_In_Object_Directory
7146 (Source_File : File_Name_Type;
7147 Full_Lib_File : File_Name_Type) return Boolean
7150 -- There is something to check only when using project files.
7151 -- Otherwise, this function returns True (last line of the function).
7153 if Main_Project /= No_Project then
7155 Source_File_Name : constant String :=
7156 Get_Name_String (Source_File);
7157 Saved_Verbosity : constant Verbosity := Current_Verbosity;
7158 Project : Project_Id := No_Project;
7159 Data : Project_Data;
7161 Path_Name : Path_Name_Type := No_Path;
7162 pragma Warnings (Off, Path_Name);
7165 -- Call Get_Reference to know the ultimate extending project of
7166 -- the source. Call it with verbosity default to avoid verbose
7169 Current_Verbosity := Default;
7170 Prj.Env.Get_Reference
7171 (Source_File_Name => Source_File_Name,
7173 In_Tree => Project_Tree,
7175 Current_Verbosity := Saved_Verbosity;
7177 -- If this source is in a project, check that the ALI file is
7178 -- in its object directory. If it is not, return False, so that
7179 -- the ALI file will not be skipped.
7181 if Project /= No_Project then
7182 Data := Project_Tree.Projects.Table (Project);
7185 Object_Directory : constant String :=
7188 (Data.Display_Object_Dir));
7190 Olast : Natural := Object_Directory'Last;
7192 Lib_File_Directory : constant String :=
7193 Normalize_Pathname (Dir_Name
7194 (Get_Name_String (Full_Lib_File)));
7196 Llast : Natural := Lib_File_Directory'Last;
7199 -- For directories, Normalize_Pathname may or may not put
7200 -- a directory separator at the end, depending on its input.
7201 -- Remove any last directory separator before comparison.
7202 -- Returns True only if the two directories are the same.
7204 if Object_Directory (Olast) = Directory_Separator then
7208 if Lib_File_Directory (Llast) = Directory_Separator then
7212 return Object_Directory (Object_Directory'First .. Olast) =
7213 Lib_File_Directory (Lib_File_Directory'First .. Llast);
7219 -- When the source is not in a project file, always return True
7222 end Is_In_Object_Directory;
7229 (ALI_File : File_Name_Type;
7230 Args : Argument_List;
7231 Success : out Boolean)
7233 Link_Args : Argument_List (1 .. Args'Length + 1);
7236 Get_Name_String (ALI_File);
7237 Link_Args (1) := new String'(Name_Buffer (1 .. Name_Len));
7239 Link_Args (2 .. Args'Length + 1) := Args;
7241 GNAT.OS_Lib.Normalize_Arguments (Link_Args);
7243 Display (Gnatlink.all, Link_Args);
7245 if Gnatlink_Path = null then
7246 Make_Failed ("error, unable to locate ", Gnatlink.all);
7249 GNAT.OS_Lib.Spawn (Gnatlink_Path.all, Link_Args, Success);
7252 ---------------------------
7253 -- List_Bad_Compilations --
7254 ---------------------------
7256 procedure List_Bad_Compilations is
7258 for J in Bad_Compilation.First .. Bad_Compilation.Last loop
7259 if Bad_Compilation.Table (J).File = No_File then
7261 elsif not Bad_Compilation.Table (J).Found then
7262 Inform (Bad_Compilation.Table (J).File, "not found");
7264 Inform (Bad_Compilation.Table (J).File, "compilation error");
7267 end List_Bad_Compilations;
7273 procedure List_Depend is
7274 Lib_Name : File_Name_Type;
7275 Obj_Name : File_Name_Type;
7276 Src_Name : File_Name_Type;
7280 Line_Size : constant := 77;
7283 Set_Standard_Output;
7285 for A in ALIs.First .. ALIs.Last loop
7286 Lib_Name := ALIs.Table (A).Afile;
7288 -- We have to provide the full library file name in In_Place_Mode
7290 if In_Place_Mode then
7291 Lib_Name := Full_Lib_File_Name (Lib_Name);
7294 Obj_Name := Object_File_Name (Lib_Name);
7295 Write_Name (Obj_Name);
7298 Get_Name_String (Obj_Name);
7300 Line_Pos := Len + 2;
7302 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
7303 Src_Name := Sdep.Table (D).Sfile;
7305 if Is_Internal_File_Name (Src_Name)
7306 and then not Check_Readonly_Files
7310 if not Quiet_Output then
7311 Src_Name := Full_Source_Name (Src_Name);
7314 Get_Name_String (Src_Name);
7317 if Line_Pos + Len + 1 > Line_Size then
7323 Line_Pos := Line_Pos + Len + 1;
7326 Write_Name (Src_Name);
7333 if not Commands_To_Stdout then
7342 procedure Make_Failed (S1 : String; S2 : String := ""; S3 : String := "") is
7344 Delete_All_Temp_Files;
7345 Osint.Fail (S1, S2, S3);
7348 --------------------
7349 -- Mark_Directory --
7350 --------------------
7352 procedure Mark_Directory
7354 Mark : Lib_Mark_Type;
7355 On_Command_Line : Boolean)
7361 if On_Command_Line then
7363 Real_Path : constant String := Normalize_Pathname (Dir);
7366 if Real_Path'Length = 0 then
7367 Name_Len := Dir'Length;
7368 Name_Buffer (1 .. Name_Len) := Dir;
7371 Name_Len := Real_Path'Length;
7372 Name_Buffer (1 .. Name_Len) := Real_Path;
7378 Real_Path : constant String :=
7382 (Project_Tree.Projects.Table
7383 (Main_Project).Display_Directory));
7386 if Real_Path'Length = 0 then
7387 Name_Len := Dir'Length;
7388 Name_Buffer (1 .. Name_Len) := Dir;
7391 Name_Len := Real_Path'Length;
7392 Name_Buffer (1 .. Name_Len) := Real_Path;
7397 -- Last character is supposed to be a directory separator
7399 if not Is_Directory_Separator (Name_Buffer (Name_Len)) then
7400 Name_Len := Name_Len + 1;
7401 Name_Buffer (Name_Len) := Directory_Separator;
7404 -- Add flags to the already existing flags
7407 B := Get_Name_Table_Byte (N);
7408 Set_Name_Table_Byte (N, B or Mark);
7411 -----------------------------
7412 -- Recursive_Compute_Depth --
7413 -----------------------------
7415 procedure Recursive_Compute_Depth
7416 (Project : Project_Id;
7419 List : Project_List;
7423 -- Nothing to do if there is no project or if the project has already
7424 -- been seen or if the depth is large enough.
7426 if Project = No_Project
7427 or else Project_Tree.Projects.Table (Project).Seen
7428 or else Project_Tree.Projects.Table (Project).Depth >= Depth
7433 Project_Tree.Projects.Table (Project).Depth := Depth;
7435 -- Mark project as Seen to avoid endless loop caused by limited withs
7437 Project_Tree.Projects.Table (Project).Seen := True;
7439 List := Project_Tree.Projects.Table (Project).Imported_Projects;
7441 -- Visit each imported project
7443 while List /= Empty_Project_List loop
7444 Proj := Project_Tree.Project_Lists.Table (List).Project;
7445 List := Project_Tree.Project_Lists.Table (List).Next;
7446 Recursive_Compute_Depth
7448 Depth => Depth + 1);
7451 -- Visit a project being extended, if any
7453 Recursive_Compute_Depth
7454 (Project => Project_Tree.Projects.Table (Project).Extends,
7455 Depth => Depth + 1);
7457 -- Reset the Seen flag, as we leave this project
7459 Project_Tree.Projects.Table (Project).Seen := False;
7460 end Recursive_Compute_Depth;
7462 -------------------------------
7463 -- Report_Compilation_Failed --
7464 -------------------------------
7466 procedure Report_Compilation_Failed is
7468 Delete_All_Temp_Files;
7469 Exit_Program (E_Fatal);
7470 end Report_Compilation_Failed;
7472 ------------------------
7473 -- Sigint_Intercepted --
7474 ------------------------
7476 procedure Sigint_Intercepted is
7477 SIGINT : constant := 2;
7480 Write_Line ("*** Interrupted ***");
7482 -- Send SIGINT to all outstanding compilation processes spawned
7484 for J in 1 .. Outstanding_Compiles loop
7485 Kill (Running_Compile (J).Pid, SIGINT, 1);
7488 Delete_All_Temp_Files;
7490 -- ??? OS_Exit (1) is equivalent to Exit_Program (E_No_Compile),
7491 -- shouldn't that be Exit_Program (E_Abort) instead?
7492 end Sigint_Intercepted;
7498 procedure Scan_Make_Arg (Argv : String; And_Save : Boolean) is
7502 pragma Assert (Argv'First = 1);
7504 if Argv'Length = 0 then
7508 -- If the previous switch has set the Project_File_Name_Present flag
7509 -- (that is we have seen a -P alone), then the next argument is the name
7510 -- of the project file.
7512 if Project_File_Name_Present and then Project_File_Name = null then
7513 if Argv (1) = '-' then
7514 Make_Failed ("project file name missing after -P");
7517 Project_File_Name_Present := False;
7518 Project_File_Name := new String'(Argv);
7521 -- If the previous switch has set the Output_File_Name_Present flag
7522 -- (that is we have seen a -o), then the next argument is the name of
7523 -- the output executable.
7525 elsif Output_File_Name_Present
7526 and then not Output_File_Name_Seen
7528 Output_File_Name_Seen := True;
7530 if Argv (1) = '-' then
7531 Make_Failed ("output file name missing after -o");
7534 Add_Switch ("-o", Linker, And_Save => And_Save);
7535 Add_Switch (Executable_Name (Argv), Linker, And_Save => And_Save);
7538 -- If the previous switch has set the Object_Directory_Present flag
7539 -- (that is we have seen a -D), then the next argument is the path name
7540 -- of the object directory..
7542 elsif Object_Directory_Present
7543 and then not Object_Directory_Seen
7545 Object_Directory_Seen := True;
7547 if Argv (1) = '-' then
7548 Make_Failed ("object directory path name missing after -D");
7550 elsif not Is_Directory (Argv) then
7551 Make_Failed ("cannot find object directory """, Argv, """");
7554 Add_Lib_Search_Dir (Argv);
7556 -- Specify the object directory to the binder
7558 Add_Switch ("-aO" & Argv, Binder, And_Save => And_Save);
7560 -- Record the object directory. Make sure it ends with a directory
7563 if Argv (Argv'Last) = Directory_Separator then
7564 Object_Directory_Path :=
7567 Object_Directory_Path :=
7568 new String'(Argv & Directory_Separator);
7572 -- Then check if we are dealing with -cargs/-bargs/-largs/-margs
7574 elsif Argv = "-bargs"
7583 when 'c' => Program_Args := Compiler;
7584 when 'b' => Program_Args := Binder;
7585 when 'l' => Program_Args := Linker;
7586 when 'm' => Program_Args := None;
7589 raise Program_Error;
7592 -- A special test is needed for the -o switch within a -largs
7593 -- since that is another way to specify the name of the final
7596 elsif Program_Args = Linker
7597 and then Argv = "-o"
7599 Make_Failed ("switch -o not allowed within a -largs. " &
7600 "Use -o directly.");
7602 -- Check to see if we are reading switches after a -cargs,
7603 -- -bargs or -largs switch. If yes save it.
7605 elsif Program_Args /= None then
7607 -- Check to see if we are reading -I switches in order
7608 -- to take into account in the src & lib search directories.
7610 if Argv'Length > 2 and then Argv (1 .. 2) = "-I" then
7611 if Argv (3 .. Argv'Last) = "-" then
7612 Look_In_Primary_Dir := False;
7614 elsif Program_Args = Compiler then
7615 if Argv (3 .. Argv'Last) /= "-" then
7616 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7619 elsif Program_Args = Binder then
7620 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7624 Add_Switch (Argv, Program_Args, And_Save => And_Save);
7626 -- Handle non-default compiler, binder, linker, and handle --RTS switch
7628 elsif Argv'Length > 2 and then Argv (1 .. 2) = "--" then
7630 and then Argv (1 .. 6) = "--GCC="
7633 Program_Args : constant Argument_List_Access :=
7634 Argument_String_To_List
7635 (Argv (7 .. Argv'Last));
7639 Saved_Gcc := new String'(Program_Args.all (1).all);
7641 Gcc := new String'(Program_Args.all (1).all);
7644 for J in 2 .. Program_Args.all'Last loop
7646 (Program_Args.all (J).all,
7648 And_Save => And_Save);
7652 elsif Argv'Length > 11
7653 and then Argv (1 .. 11) = "--GNATBIND="
7656 Program_Args : constant Argument_List_Access :=
7657 Argument_String_To_List
7658 (Argv (12 .. Argv'Last));
7662 Saved_Gnatbind := new String'(Program_Args.all (1).all);
7664 Gnatbind := new String'(Program_Args.all (1).all);
7667 for J in 2 .. Program_Args.all'Last loop
7669 (Program_Args.all (J).all, Binder, And_Save => And_Save);
7673 elsif Argv'Length > 11
7674 and then Argv (1 .. 11) = "--GNATLINK="
7677 Program_Args : constant Argument_List_Access :=
7678 Argument_String_To_List
7679 (Argv (12 .. Argv'Last));
7682 Saved_Gnatlink := new String'(Program_Args.all (1).all);
7684 Gnatlink := new String'(Program_Args.all (1).all);
7687 for J in 2 .. Program_Args.all'Last loop
7688 Add_Switch (Program_Args.all (J).all, Linker);
7692 elsif Argv'Length >= 5 and then
7693 Argv (1 .. 5) = "--RTS"
7695 Add_Switch (Argv, Compiler, And_Save => And_Save);
7696 Add_Switch (Argv, Binder, And_Save => And_Save);
7698 if Argv'Length <= 6 or else Argv (6) /= '=' then
7699 Make_Failed ("missing path for --RTS");
7702 -- Check that this is the first time we see this switch or
7703 -- if it is not the first time, the same path is specified.
7705 if RTS_Specified = null then
7706 RTS_Specified := new String'(Argv (7 .. Argv'Last));
7708 elsif RTS_Specified.all /= Argv (7 .. Argv'Last) then
7709 Make_Failed ("--RTS cannot be specified multiple times");
7712 -- Valid --RTS switch
7719 Src_Path_Name : constant String_Ptr :=
7721 (Argv (7 .. Argv'Last), Include);
7723 Lib_Path_Name : constant String_Ptr :=
7725 (Argv (7 .. Argv'Last), Objects);
7728 if Src_Path_Name /= null
7729 and then Lib_Path_Name /= null
7731 -- Set RTS_*_Path_Name variables, so that correct direct-
7732 -- ories will be set when Osint.Add_Default_Search_Dirs
7735 RTS_Src_Path_Name := Src_Path_Name;
7736 RTS_Lib_Path_Name := Lib_Path_Name;
7738 elsif Src_Path_Name = null
7739 and Lib_Path_Name = null
7741 Make_Failed ("RTS path not valid: missing " &
7742 "adainclude and adalib directories");
7744 elsif Src_Path_Name = null then
7745 Make_Failed ("RTS path not valid: missing adainclude " &
7748 elsif Lib_Path_Name = null then
7749 Make_Failed ("RTS path not valid: missing adalib " &
7756 Scan_Make_Switches (Argv, Success);
7759 -- If we have seen a regular switch process it
7761 elsif Argv (1) = '-' then
7762 if Argv'Length = 1 then
7763 Make_Failed ("switch character cannot be followed by a blank");
7765 -- Incorrect switches that should start with "--"
7767 elsif (Argv'Length > 5 and then Argv (1 .. 5) = "-RTS=")
7768 or else (Argv'Length > 5 and then Argv (1 .. 5) = "-GCC=")
7769 or else (Argv'Length > 10 and then Argv (1 .. 10) = "-GNATLINK=")
7770 or else (Argv'Length > 10 and then Argv (1 .. 10) = "-GNATBIND=")
7772 Make_Failed ("option ", Argv, " should start with '--'");
7776 elsif Argv (2 .. Argv'Last) = "I-" then
7777 Look_In_Primary_Dir := False;
7779 -- Forbid -?- or -??- where ? is any character
7781 elsif (Argv'Length = 3 and then Argv (3) = '-')
7782 or else (Argv'Length = 4 and then Argv (4) = '-')
7784 Make_Failed ("trailing ""-"" at the end of ", Argv, " forbidden.");
7788 elsif Argv (2) = 'I' then
7789 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7790 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7791 Add_Switch (Argv, Compiler, And_Save => And_Save);
7792 Add_Switch (Argv, Binder, And_Save => And_Save);
7794 -- -aIdir (to gcc this is like a -I switch)
7796 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aI" then
7797 Add_Source_Search_Dir (Argv (4 .. Argv'Last), And_Save);
7798 Add_Switch ("-I" & Argv (4 .. Argv'Last),
7800 And_Save => And_Save);
7801 Add_Switch (Argv, Binder, And_Save => And_Save);
7805 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aO" then
7806 Add_Library_Search_Dir (Argv (4 .. Argv'Last), And_Save);
7807 Add_Switch (Argv, Binder, And_Save => And_Save);
7809 -- -aLdir (to gnatbind this is like a -aO switch)
7811 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aL" then
7812 Mark_Directory (Argv (4 .. Argv'Last), Ada_Lib_Dir, And_Save);
7813 Add_Library_Search_Dir (Argv (4 .. Argv'Last), And_Save);
7814 Add_Switch ("-aO" & Argv (4 .. Argv'Last),
7816 And_Save => And_Save);
7820 elsif Argv'Length >= 13 and then Argv (2 .. 13) = "aamp_target=" then
7821 Add_Switch (Argv, Compiler, And_Save => And_Save);
7823 -- Set the aamp_target environment variable so that the binder and
7824 -- linker will use the proper target library. This is consistent
7825 -- with how things work when -aamp_target is passed on the command
7826 -- line to gnaampmake.
7828 Setenv ("aamp_target", Argv (14 .. Argv'Last));
7830 -- -Adir (to gnatbind this is like a -aO switch, to gcc like a -I)
7832 elsif Argv (2) = 'A' then
7833 Mark_Directory (Argv (3 .. Argv'Last), Ada_Lib_Dir, And_Save);
7834 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7835 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7836 Add_Switch ("-I" & Argv (3 .. Argv'Last),
7838 And_Save => And_Save);
7839 Add_Switch ("-aO" & Argv (3 .. Argv'Last),
7841 And_Save => And_Save);
7845 elsif Argv (2) = 'L' then
7846 Add_Switch (Argv, Linker, And_Save => And_Save);
7848 -- For -gxxxxx, -pg, -mxxx, -fxxx: give the switch to both the
7849 -- compiler and the linker (except for -gnatxxx which is only for
7850 -- the compiler). Some of the -mxxx (for example -m64) and -fxxx
7851 -- (for example -ftest-coverage for gcov) need to be used when
7852 -- compiling the binder generated files, and using all these gcc
7853 -- switches for the binder generated files should not be a problem.
7856 (Argv (2) = 'g' and then (Argv'Last < 5
7857 or else Argv (2 .. 5) /= "gnat"))
7858 or else Argv (2 .. Argv'Last) = "pg"
7859 or else (Argv (2) = 'm' and then Argv'Last > 2)
7860 or else (Argv (2) = 'f' and then Argv'Last > 2)
7862 Add_Switch (Argv, Compiler, And_Save => And_Save);
7863 Add_Switch (Argv, Linker, And_Save => And_Save);
7865 -- -C=<mapping file>
7867 elsif Argv'Last > 2 and then Argv (2) = 'C' then
7869 if Argv (3) /= '=' or else Argv'Last <= 3 then
7870 Make_Failed ("illegal switch ", Argv);
7873 Gnatmake_Mapping_File := new String'(Argv (4 .. Argv'Last));
7878 elsif Argv'Last = 2 and then Argv (2) = 'D' then
7879 if Project_File_Name /= null then
7880 Make_Failed ("-D cannot be used in conjunction with a " &
7884 Scan_Make_Switches (Argv, Success);
7889 elsif Argv (2) = 'd'
7890 and then Argv'Last = 2
7892 Display_Compilation_Progress := True;
7896 elsif Argv'Last = 2 and then Argv (2) = 'i' then
7897 if Project_File_Name /= null then
7898 Make_Failed ("-i cannot be used in conjunction with a " &
7901 Scan_Make_Switches (Argv, Success);
7904 -- -j (need to save the result)
7906 elsif Argv (2) = 'j' then
7907 Scan_Make_Switches (Argv, Success);
7910 Saved_Maximum_Processes := Maximum_Processes;
7915 elsif Argv (2) = 'm'
7916 and then Argv'Last = 2
7918 Minimal_Recompilation := True;
7922 elsif Argv (2) = 'u'
7923 and then Argv'Last = 2
7925 Unique_Compile := True;
7926 Compile_Only := True;
7927 Do_Bind_Step := False;
7928 Do_Link_Step := False;
7932 elsif Argv (2) = 'U'
7933 and then Argv'Last = 2
7935 Unique_Compile_All_Projects := True;
7936 Unique_Compile := True;
7937 Compile_Only := True;
7938 Do_Bind_Step := False;
7939 Do_Link_Step := False;
7941 -- -Pprj or -P prj (only once, and only on the command line)
7943 elsif Argv (2) = 'P' then
7944 if Project_File_Name /= null then
7945 Make_Failed ("cannot have several project files specified");
7947 elsif Object_Directory_Path /= null then
7948 Make_Failed ("-D cannot be used in conjunction with a " &
7951 elsif In_Place_Mode then
7952 Make_Failed ("-i cannot be used in conjunction with a " &
7955 elsif not And_Save then
7957 -- It could be a tool other than gnatmake (i.e, gnatdist)
7958 -- or a -P switch inside a project file.
7961 ("either the tool is not ""project-aware"" or " &
7962 "a project file is specified inside a project file");
7964 elsif Argv'Last = 2 then
7966 -- -P is used alone: the project file name is the next option
7968 Project_File_Name_Present := True;
7971 Project_File_Name := new String'(Argv (3 .. Argv'Last));
7974 -- -vPx (verbosity of the parsing of the project files)
7977 and then Argv (2 .. 3) = "vP"
7978 and then Argv (4) in '0' .. '2'
7983 Current_Verbosity := Prj.Default;
7985 Current_Verbosity := Prj.Medium;
7987 Current_Verbosity := Prj.High;
7993 -- -Xext=val (External assignment)
7995 elsif Argv (2) = 'X'
7996 and then Is_External_Assignment (Argv)
7998 -- Is_External_Assignment has side effects
7999 -- when it returns True;
8003 -- If -gnath is present, then generate the usage information
8004 -- right now and do not pass this option on to the compiler calls.
8006 elsif Argv = "-gnath" then
8009 -- If -gnatc is specified, make sure the bind step and the link
8010 -- step are not executed.
8012 elsif Argv'Length >= 6 and then Argv (2 .. 6) = "gnatc" then
8014 -- If -gnatc is specified, make sure the bind step and the link
8015 -- step are not executed.
8017 Add_Switch (Argv, Compiler, And_Save => And_Save);
8018 Operating_Mode := Check_Semantics;
8019 Check_Object_Consistency := False;
8020 Compile_Only := True;
8021 Do_Bind_Step := False;
8022 Do_Link_Step := False;
8024 elsif Argv (2 .. Argv'Last) = "nostdlib" then
8026 -- Don't pass -nostdlib to gnatlink, it will disable
8027 -- linking with all standard library files.
8031 Add_Switch (Argv, Compiler, And_Save => And_Save);
8032 Add_Switch (Argv, Binder, And_Save => And_Save);
8034 elsif Argv (2 .. Argv'Last) = "nostdinc" then
8036 -- Pass -nostdinc to the Compiler and to gnatbind
8039 Add_Switch (Argv, Compiler, And_Save => And_Save);
8040 Add_Switch (Argv, Binder, And_Save => And_Save);
8042 -- All other switches are processed by Scan_Make_Switches.
8043 -- If the call returns with Success = False, then the switch is
8044 -- passed to the compiler.
8047 Scan_Make_Switches (Argv, Success);
8050 Add_Switch (Argv, Compiler, And_Save => And_Save);
8054 -- If not a switch it must be a file name
8058 Mains.Add_Main (Argv);
8066 function Switches_Of
8067 (Source_File : File_Name_Type;
8068 Source_File_Name : String;
8070 Naming : Naming_Data;
8071 In_Package : Package_Id;
8072 Allow_ALI : Boolean) return Variable_Value
8074 Switches : Variable_Value;
8076 Defaults : constant Array_Element_Id :=
8078 (Name => Name_Default_Switches,
8080 Project_Tree.Packages.Table
8081 (In_Package).Decl.Arrays,
8082 In_Tree => Project_Tree);
8084 Switches_Array : constant Array_Element_Id :=
8086 (Name => Name_Switches,
8088 Project_Tree.Packages.Table
8089 (In_Package).Decl.Arrays,
8090 In_Tree => Project_Tree);
8095 (Index => Name_Id (Source_File),
8096 Src_Index => Source_Index,
8097 In_Array => Switches_Array,
8098 In_Tree => Project_Tree);
8100 if Switches = Nil_Variable_Value then
8102 Name : String (1 .. Source_File_Name'Length + 3);
8103 Last : Positive := Source_File_Name'Length;
8104 Spec_Suffix : constant String :=
8105 Spec_Suffix_Of (Project_Tree, "ada", Naming);
8106 Body_Suffix : constant String :=
8107 Body_Suffix_Of (Project_Tree, "ada", Naming);
8108 Truncated : Boolean := False;
8111 Name (1 .. Last) := Source_File_Name;
8113 if Last > Body_Suffix'Length
8114 and then Name (Last - Body_Suffix'Length + 1 .. Last) =
8118 Last := Last - Body_Suffix'Length;
8122 and then Last > Spec_Suffix'Length
8123 and then Name (Last - Spec_Suffix'Length + 1 .. Last) =
8127 Last := Last - Spec_Suffix'Length;
8132 Name_Buffer (1 .. Name_Len) := Name (1 .. Last);
8135 (Index => Name_Find,
8137 In_Array => Switches_Array,
8138 In_Tree => Project_Tree);
8140 if Switches = Nil_Variable_Value
8143 Last := Source_File_Name'Length;
8145 while Name (Last) /= '.' loop
8149 Name (Last + 1 .. Last + 3) := "ali";
8150 Name_Len := Last + 3;
8151 Name_Buffer (1 .. Name_Len) := Name (1 .. Name_Len);
8154 (Index => Name_Find,
8156 In_Array => Switches_Array,
8157 In_Tree => Project_Tree);
8163 if Switches = Nil_Variable_Value then
8168 In_Array => Defaults,
8169 In_Tree => Project_Tree);
8181 if Usage_Needed then
8182 Usage_Needed := False;
8191 procedure Verbose_Msg
8194 N2 : Name_Id := No_Name;
8196 Prefix : String := " -> ";
8197 Minimum_Verbosity : Verbosity_Level_Type := Opt.Low)
8200 if (not Verbose_Mode) or else (Minimum_Verbosity > Verbosity_Level) then
8210 if N2 /= No_Name then
8220 procedure Verbose_Msg
8221 (N1 : File_Name_Type;
8223 N2 : File_Name_Type := No_File;
8225 Prefix : String := " -> ";
8226 Minimum_Verbosity : Verbosity_Level_Type := Opt.Low)
8230 (Name_Id (N1), S1, Name_Id (N2), S2, Prefix, Minimum_Verbosity);
8234 -- Make sure that in case of failure, the temp files will be deleted
8236 Prj.Com.Fail := Make_Failed'Access;
8237 MLib.Fail := Make_Failed'Access;
8238 Makeutl.Do_Fail := Make_Failed'Access;