1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
27 with ALI.Util; use ALI.Util;
32 with Fname; use Fname;
33 with Fname.SF; use Fname.SF;
34 with Fname.UF; use Fname.UF;
35 with Gnatvsn; use Gnatvsn;
36 with Hostparm; use Hostparm;
38 with Makeutl; use Makeutl;
41 with MLib.Tgt; use MLib.Tgt;
43 with Namet; use Namet;
45 with Osint.M; use Osint.M;
46 with Osint; use Osint;
47 with Output; use Output;
52 with Prj.Tree; use Prj.Tree;
56 with Snames; use Snames;
58 pragma Warnings (Off);
62 with Switch; use Switch;
63 with Switch.M; use Switch.M;
64 with Targparm; use Targparm;
67 with Types; use Types;
69 with Ada.Exceptions; use Ada.Exceptions;
70 with Ada.Command_Line; use Ada.Command_Line;
72 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
73 with GNAT.Dynamic_HTables; use GNAT.Dynamic_HTables;
75 with GNAT.Case_Util; use GNAT.Case_Util;
76 with GNAT.OS_Lib; use GNAT.OS_Lib;
81 -- Make control characters visible
83 Standard_Library_Package_Body_Name : constant String := "s-stalib.adb";
84 -- Every program depends on this package, that must then be checked,
85 -- especially when -f and -a are used.
87 procedure Kill (Pid : Process_Id; Sig_Num : Integer; Close : Integer);
88 pragma Import (C, Kill, "__gnat_kill");
89 -- Called by Sigint_Intercepted to kill all spawned compilation processes
91 type Sigint_Handler is access procedure;
92 pragma Convention (C, Sigint_Handler);
94 procedure Install_Int_Handler (Handler : Sigint_Handler);
95 pragma Import (C, Install_Int_Handler, "__gnat_install_int_handler");
96 -- Called by Gnatmake to install the SIGINT handler below
98 procedure Sigint_Intercepted;
99 pragma Convention (C, Sigint_Intercepted);
100 -- Called when the program is interrupted by Ctrl-C to delete the
101 -- temporary mapping files and configuration pragmas files.
103 No_Mapping_File : constant Natural := 0;
105 type Compilation_Data is record
107 Full_Source_File : File_Name_Type;
108 Lib_File : File_Name_Type;
109 Source_Unit : Unit_Name_Type;
110 Full_Lib_File : File_Name_Type;
111 Lib_File_Attr : aliased File_Attributes;
112 Mapping_File : Natural := No_Mapping_File;
113 Project : Project_Id := No_Project;
115 -- Data recorded for each compilation process spawned
117 No_Compilation_Data : constant Compilation_Data :=
118 (Invalid_Pid, No_File, No_File, No_Unit_Name, No_File, Unknown_Attributes,
119 No_Mapping_File, No_Project);
121 type Comp_Data_Arr is array (Positive range <>) of Compilation_Data;
122 type Comp_Data_Ptr is access Comp_Data_Arr;
123 Running_Compile : Comp_Data_Ptr;
124 -- Used to save information about outstanding compilations
126 Outstanding_Compiles : Natural := 0;
127 -- Current number of outstanding compiles
129 -------------------------
130 -- Note on terminology --
131 -------------------------
133 -- In this program, we use the phrase "termination" of a file name to refer
134 -- to the suffix that appears after the unit name portion. Very often this
135 -- is simply the extension, but in some cases, the sequence may be more
136 -- complex, for example in main.1.ada, the termination in this name is
137 -- ".1.ada" and in main_.ada the termination is "_.ada".
139 procedure Insert_Project_Sources
140 (The_Project : Project_Id;
141 All_Projects : Boolean;
143 -- If Into_Q is True, insert all sources of the project file(s) that are
144 -- not already marked into the Q. If Into_Q is False, call Osint.Add_File
145 -- for the first source, then insert all other sources that are not already
146 -- marked into the Q. If All_Projects is True, all sources of all projects
147 -- are concerned; otherwise, only sources of The_Project are concerned,
148 -- including, if The_Project is an extending project, sources inherited
149 -- from projects being extended.
151 Unique_Compile : Boolean := False;
152 -- Set to True if -u or -U or a project file with no main is used
154 Unique_Compile_All_Projects : Boolean := False;
155 -- Set to True if -U is used
157 Must_Compile : Boolean := False;
158 -- True if gnatmake is invoked with -f -u and one or several mains on the
161 Main_On_Command_Line : Boolean := False;
162 -- True if gnatmake is invoked with one or several mains on the command
165 RTS_Specified : String_Access := null;
166 -- Used to detect multiple --RTS= switches
168 N_M_Switch : Natural := 0;
169 -- Used to count -mxxx switches that can affect multilib
172 ---------------------------------
173 -- Queue Manipulation Routines --
174 ---------------------------------
176 procedure Initialize (Queue_Per_Obj_Dir : Boolean);
177 -- Initialize the queue
179 function Is_Empty return Boolean;
180 -- Returns True if the queue is empty
182 function Is_Virtually_Empty return Boolean;
183 -- Returns True if the queue is empty or if all object directories are
187 (Source_File_Name : File_Name_Type;
188 Project : Project_Id;
189 Source_Unit : Unit_Name_Type := No_Unit_Name;
191 -- Insert source in the queue
194 (Source_File_Name : out File_Name_Type;
195 Source_Unit : out Unit_Name_Type;
196 Source_Index : out Int);
197 -- Get the first source that can be compiled from the queue. If no
198 -- source may be compiled, return No_File/No_Source.
200 function Size return Natural;
201 -- Return the total size of the queue, including the sources already
204 function Processed return Natural;
205 -- Return the number of source in the queue that have already been
208 procedure Set_Obj_Dir_Busy (Obj_Dir : Path_Name_Type);
209 -- Indicate that this object directory is busy, so that when
210 -- One_Compilation_Per_Obj_Dir is True no other compilation occurs in
211 -- this object directory.
213 procedure Set_Obj_Dir_Free (Obj_Dir : Path_Name_Type);
214 -- Indicate that there is no compilation for this object directory
216 function Element (Rank : Positive) return File_Name_Type;
217 -- Get the file name for element of index Rank in the queue
221 -- The 3 following packages are used to store gcc, gnatbind and gnatlink
222 -- switches found in the project files.
224 package Gcc_Switches is new Table.Table (
225 Table_Component_Type => String_Access,
226 Table_Index_Type => Integer,
227 Table_Low_Bound => 1,
229 Table_Increment => 100,
230 Table_Name => "Make.Gcc_Switches");
232 package Binder_Switches is new Table.Table (
233 Table_Component_Type => String_Access,
234 Table_Index_Type => Integer,
235 Table_Low_Bound => 1,
237 Table_Increment => 100,
238 Table_Name => "Make.Binder_Switches");
240 package Linker_Switches is new Table.Table (
241 Table_Component_Type => String_Access,
242 Table_Index_Type => Integer,
243 Table_Low_Bound => 1,
245 Table_Increment => 100,
246 Table_Name => "Make.Linker_Switches");
248 -- The following instantiations and variables are necessary to save what
249 -- is found on the command line, in case there is a project file specified.
251 package Saved_Gcc_Switches is new Table.Table (
252 Table_Component_Type => String_Access,
253 Table_Index_Type => Integer,
254 Table_Low_Bound => 1,
256 Table_Increment => 100,
257 Table_Name => "Make.Saved_Gcc_Switches");
259 package Saved_Binder_Switches is new Table.Table (
260 Table_Component_Type => String_Access,
261 Table_Index_Type => Integer,
262 Table_Low_Bound => 1,
264 Table_Increment => 100,
265 Table_Name => "Make.Saved_Binder_Switches");
267 package Saved_Linker_Switches is new Table.Table
268 (Table_Component_Type => String_Access,
269 Table_Index_Type => Integer,
270 Table_Low_Bound => 1,
272 Table_Increment => 100,
273 Table_Name => "Make.Saved_Linker_Switches");
275 package Switches_To_Check is new Table.Table (
276 Table_Component_Type => String_Access,
277 Table_Index_Type => Integer,
278 Table_Low_Bound => 1,
280 Table_Increment => 100,
281 Table_Name => "Make.Switches_To_Check");
283 package Library_Paths is new Table.Table (
284 Table_Component_Type => String_Access,
285 Table_Index_Type => Integer,
286 Table_Low_Bound => 1,
288 Table_Increment => 100,
289 Table_Name => "Make.Library_Paths");
291 package Failed_Links is new Table.Table (
292 Table_Component_Type => File_Name_Type,
293 Table_Index_Type => Integer,
294 Table_Low_Bound => 1,
296 Table_Increment => 100,
297 Table_Name => "Make.Failed_Links");
299 package Successful_Links is new Table.Table (
300 Table_Component_Type => File_Name_Type,
301 Table_Index_Type => Integer,
302 Table_Low_Bound => 1,
304 Table_Increment => 100,
305 Table_Name => "Make.Successful_Links");
307 package Library_Projs is new Table.Table (
308 Table_Component_Type => Project_Id,
309 Table_Index_Type => Integer,
310 Table_Low_Bound => 1,
312 Table_Increment => 100,
313 Table_Name => "Make.Library_Projs");
315 -- Two variables to keep the last binder and linker switch index in tables
316 -- Binder_Switches and Linker_Switches, before adding switches from the
317 -- project file (if any) and switches from the command line (if any).
319 Last_Binder_Switch : Integer := 0;
320 Last_Linker_Switch : Integer := 0;
322 Normalized_Switches : Argument_List_Access := new Argument_List (1 .. 10);
323 Last_Norm_Switch : Natural := 0;
325 Saved_Maximum_Processes : Natural := 0;
327 Gnatmake_Switch_Found : Boolean;
328 -- Set by Scan_Make_Arg. True when the switch is a gnatmake switch.
329 -- Tested by Add_Switches when switches in package Builder must all be
330 -- gnatmake switches.
332 Switch_May_Be_Passed_To_The_Compiler : Boolean;
333 -- Set by Add_Switches and Switches_Of. True when unrecognized switches
334 -- are passed to the Ada compiler.
336 type Arg_List_Ref is access Argument_List;
337 The_Saved_Gcc_Switches : Arg_List_Ref;
339 Project_File_Name : String_Access := null;
340 -- The path name of the main project file, if any
342 Project_File_Name_Present : Boolean := False;
343 -- True when -P is used with a space between -P and the project file name
345 Current_Verbosity : Prj.Verbosity := Prj.Default;
346 -- Verbosity to parse the project files
348 Main_Project : Prj.Project_Id := No_Project;
349 -- The project id of the main project file, if any
351 Project_Of_Current_Object_Directory : Project_Id := No_Project;
352 -- The object directory of the project for the last compilation. Avoid
353 -- calling Change_Dir if the current working directory is already this
356 Map_File : String_Access := null;
357 -- Value of switch --create-map-file
359 -- Packages of project files where unknown attributes are errors
361 Naming_String : aliased String := "naming";
362 Builder_String : aliased String := "builder";
363 Compiler_String : aliased String := "compiler";
364 Binder_String : aliased String := "binder";
365 Linker_String : aliased String := "linker";
367 Gnatmake_Packages : aliased String_List :=
368 (Naming_String 'Access,
369 Builder_String 'Access,
370 Compiler_String 'Access,
371 Binder_String 'Access,
372 Linker_String 'Access);
374 Packages_To_Check_By_Gnatmake : constant String_List_Access :=
375 Gnatmake_Packages'Access;
377 procedure Add_Library_Search_Dir
379 On_Command_Line : Boolean);
380 -- Call Add_Lib_Search_Dir with an absolute directory path. If Path is
381 -- relative path, when On_Command_Line is True, it is relative to the
382 -- current working directory. When On_Command_Line is False, it is relative
383 -- to the project directory of the main project.
385 procedure Add_Source_Search_Dir
387 On_Command_Line : Boolean);
388 -- Call Add_Src_Search_Dir with an absolute directory path. If Path is a
389 -- relative path, when On_Command_Line is True, it is relative to the
390 -- current working directory. When On_Command_Line is False, it is relative
391 -- to the project directory of the main project.
393 procedure Add_Source_Dir (N : String);
394 -- Call Add_Src_Search_Dir (output one line when in verbose mode)
396 procedure Add_Source_Directories is
397 new Prj.Env.For_All_Source_Dirs (Action => Add_Source_Dir);
399 procedure Add_Object_Dir (N : String);
400 -- Call Add_Lib_Search_Dir (output one line when in verbose mode)
402 procedure Add_Object_Directories is
403 new Prj.Env.For_All_Object_Dirs (Action => Add_Object_Dir);
405 procedure Change_To_Object_Directory (Project : Project_Id);
406 -- Change to the object directory of project Project, if this is not
407 -- already the current working directory.
409 type Bad_Compilation_Info is record
410 File : File_Name_Type;
411 Unit : Unit_Name_Type;
414 -- File is the name of the file for which a compilation failed. Unit is for
415 -- gnatdist use in order to easily get the unit name of a file when its
416 -- name is krunched or declared in gnat.adc. Found is False if the
417 -- compilation failed because the file could not be found.
419 package Bad_Compilation is new Table.Table (
420 Table_Component_Type => Bad_Compilation_Info,
421 Table_Index_Type => Natural,
422 Table_Low_Bound => 1,
424 Table_Increment => 100,
425 Table_Name => "Make.Bad_Compilation");
426 -- Full name of all the source files for which compilation fails
428 Do_Compile_Step : Boolean := True;
429 Do_Bind_Step : Boolean := True;
430 Do_Link_Step : Boolean := True;
431 -- Flags to indicate what step should be executed. Can be set to False
432 -- with the switches -c, -b and -l. These flags are reset to True for
433 -- each invocation of procedure Gnatmake.
435 Do_Codepeer_Globalize_Step : Boolean := False;
436 -- Flag to indicate whether the CodePeer globalizer should be called
438 Shared_String : aliased String := "-shared";
439 Force_Elab_Flags_String : aliased String := "-F";
441 No_Shared_Switch : aliased Argument_List := (1 .. 0 => null);
442 Shared_Switch : aliased Argument_List := (1 => Shared_String'Access);
443 Bind_Shared : Argument_List_Access := No_Shared_Switch'Access;
444 -- Switch to added in front of gnatbind switches. By default no switch is
445 -- added. Switch "-shared" is added if there is a non-static Library
448 Shared_Libgcc : aliased String := "-shared-libgcc";
450 No_Shared_Libgcc_Switch : aliased Argument_List := (1 .. 0 => null);
451 Shared_Libgcc_Switch : aliased Argument_List :=
452 (1 => Shared_Libgcc'Access);
453 Link_With_Shared_Libgcc : Argument_List_Access :=
454 No_Shared_Libgcc_Switch'Access;
456 procedure Make_Failed (S : String);
457 -- Delete all temp files created by Gnatmake and call Osint.Fail, with the
458 -- parameter S (see osint.ads). This is called from the Prj hierarchy and
459 -- the MLib hierarchy.
461 --------------------------
462 -- Obsolete Executables --
463 --------------------------
465 Executable_Obsolete : Boolean := False;
466 -- Executable_Obsolete is initially set to False for each executable,
467 -- and is set to True whenever one of the source of the executable is
468 -- compiled, or has already been compiled for another executable.
470 Max_Header : constant := 200;
471 -- This needs a proper comment, it used to say "arbitrary"
472 -- that's not an adequate comment ???
474 type Header_Num is range 1 .. Max_Header;
475 -- Header_Num for the hash table Obsoleted below
477 function Hash (F : File_Name_Type) return Header_Num;
478 -- Hash function for the hash table Obsoleted below
480 package Obsoleted is new System.HTable.Simple_HTable
481 (Header_Num => Header_Num,
484 Key => File_Name_Type,
487 -- A hash table to keep all files that have been compiled, to detect
488 -- if an executable is up to date or not.
490 procedure Enter_Into_Obsoleted (F : File_Name_Type);
491 -- Enter a file name, without directory information, into the hash table
494 function Is_In_Obsoleted (F : File_Name_Type) return Boolean;
495 -- Check if a file name, without directory information, has already been
496 -- entered into the hash table Obsoleted.
498 type Dependency is record
499 This : File_Name_Type;
500 Depends_On : File_Name_Type;
502 -- Components of table Dependencies below
504 package Dependencies is new Table.Table (
505 Table_Component_Type => Dependency,
506 Table_Index_Type => Integer,
507 Table_Low_Bound => 1,
509 Table_Increment => 100,
510 Table_Name => "Make.Dependencies");
511 -- A table to keep dependencies, to be able to decide if an executable
512 -- is obsolete. More explanation needed ???
514 -- procedure Add_Dependency (S : File_Name_Type; On : File_Name_Type);
515 -- -- Add one entry in table Dependencies
517 ----------------------------
518 -- Arguments and Switches --
519 ----------------------------
521 Arguments : Argument_List_Access;
522 -- Used to gather the arguments for invocation of the compiler
524 Last_Argument : Natural := 0;
525 -- Last index of arguments in Arguments above
527 Arguments_Project : Project_Id;
528 -- Project id, if any, of the source to be compiled
530 Arguments_Path_Name : Path_Name_Type;
531 -- Full path of the source to be compiled, when Arguments_Project is not
534 Dummy_Switch : constant String_Access := new String'("- ");
535 -- Used to initialized Prev_Switch in procedure Check
537 procedure Add_Arguments (Args : Argument_List);
538 -- Add arguments to global variable Arguments, increasing its size
539 -- if necessary and adjusting Last_Argument.
541 function Configuration_Pragmas_Switch
542 (For_Project : Project_Id) return Argument_List;
543 -- Return an argument list of one element, if there is a configuration
544 -- pragmas file to be specified for For_Project,
545 -- otherwise return an empty argument list.
551 procedure List_Depend;
552 -- Prints to standard output the list of object dependencies. This list
553 -- can be used directly in a Makefile. A call to Compile_Sources must
554 -- precede the call to List_Depend. Also because this routine uses the
555 -- ALI files that were originally loaded and scanned by Compile_Sources,
556 -- no additional ALI files should be scanned between the two calls (i.e.
557 -- between the call to Compile_Sources and List_Depend.)
559 procedure List_Bad_Compilations;
560 -- Prints out the list of all files for which the compilation failed
562 Usage_Needed : Boolean := True;
563 -- Flag used to make sure Makeusg is call at most once
566 -- Call Makeusg, if Usage_Needed is True.
567 -- Set Usage_Needed to False.
569 procedure Debug_Msg (S : String; N : Name_Id);
570 procedure Debug_Msg (S : String; N : File_Name_Type);
571 procedure Debug_Msg (S : String; N : Unit_Name_Type);
572 -- If Debug.Debug_Flag_W is set outputs string S followed by name N
574 procedure Recursive_Compute_Depth (Project : Project_Id);
575 -- Compute depth of Project and of the projects it depends on
577 -----------------------
578 -- Gnatmake Routines --
579 -----------------------
581 subtype Lib_Mark_Type is Byte;
582 -- Used in Mark_Directory
584 Ada_Lib_Dir : constant Lib_Mark_Type := 1;
585 -- Used to mark a directory as a GNAT lib dir
587 -- Note that the notion of GNAT lib dir is no longer used. The code related
588 -- to it has not been removed to give an idea on how to use the directory
589 -- prefix marking mechanism.
591 -- An Ada library directory is a directory containing ali and object files
592 -- but no source files for the bodies (the specs can be in the same or some
593 -- other directory). These directories are specified in the Gnatmake
594 -- command line with the switch "-Adir" (to specify the spec location -Idir
595 -- cab be used). Gnatmake skips the missing sources whose ali are in Ada
596 -- library directories. For an explanation of why Gnatmake behaves that
597 -- way, see the spec of Make.Compile_Sources. The directory lookup penalty
598 -- is incurred every single time this routine is called.
600 procedure Check_Steps;
601 -- Check what steps (Compile, Bind, Link) must be executed.
602 -- Set the step flags accordingly.
604 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean;
605 -- Get directory prefix of this file and get lib mark stored in name
606 -- table for this directory. Then check if an Ada lib mark has been set.
608 procedure Mark_Directory
610 Mark : Lib_Mark_Type;
611 On_Command_Line : Boolean);
612 -- Store the absolute path from Dir in name table and set lib mark as name
613 -- info to identify Ada libraries.
615 -- If Dir is a relative path, when On_Command_Line is True, it is relative
616 -- to the current working directory; when On_Command_Line is False, it is
617 -- relative to the project directory of the main project.
619 Output_Is_Object : Boolean := True;
620 -- Set to False when using a switch -S for the compiler
622 procedure Check_For_S_Switch;
623 -- Set Output_Is_Object to False when the -S switch is used for the
627 (Source_File : File_Name_Type;
628 Source_File_Name : String;
630 Project : Project_Id;
631 In_Package : Package_Id;
632 Allow_ALI : Boolean) return Variable_Value;
633 -- Return the switches for the source file in the specified package of a
634 -- project file. If the Source_File ends with a standard GNAT extension
635 -- (".ads" or ".adb"), try first the full name, then the name without the
636 -- extension, then, if Allow_ALI is True, the name with the extension
637 -- ".ali". If there is no switches for either names, try first Switches
638 -- (others) then the default switches for Ada. If all failed, return
639 -- No_Variable_Value.
641 function Is_In_Object_Directory
642 (Source_File : File_Name_Type;
643 Full_Lib_File : File_Name_Type) return Boolean;
644 -- Check if, when using a project file, the ALI file is in the project
645 -- directory of the ultimate extending project. If it is not, we ignore
646 -- the fact that this ALI file is read-only.
648 procedure Process_Multilib (Project_Node_Tree : Project_Node_Tree_Ref);
649 -- Add appropriate --RTS argument to handle multilib
651 ----------------------------------------------------
652 -- Compiler, Binder & Linker Data and Subprograms --
653 ----------------------------------------------------
655 Gcc : String_Access := Program_Name ("gcc", "gnatmake");
656 Gnatbind : String_Access := Program_Name ("gnatbind", "gnatmake");
657 Gnatlink : String_Access := Program_Name ("gnatlink", "gnatmake");
658 -- Default compiler, binder, linker programs
660 Globalizer : constant String := "codepeer_globalizer";
661 -- CodePeer globalizer executable name
663 Saved_Gcc : String_Access := null;
664 Saved_Gnatbind : String_Access := null;
665 Saved_Gnatlink : String_Access := null;
666 -- Given by the command line. Will be used, if non null
668 Gcc_Path : String_Access :=
669 GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
670 Gnatbind_Path : String_Access :=
671 GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
672 Gnatlink_Path : String_Access :=
673 GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
674 -- Path for compiler, binder, linker programs, defaulted now for gnatdist.
675 -- Changed later if overridden on command line.
677 Globalizer_Path : constant String_Access :=
678 GNAT.OS_Lib.Locate_Exec_On_Path (Globalizer);
679 -- Path for CodePeer globalizer
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;
725 Unknown_Switches_To_The_Compiler : Boolean := True;
726 Project_Node_Tree : Project_Node_Tree_Ref);
729 Program : Make_Program_Type;
730 Append_Switch : Boolean := True;
731 And_Save : Boolean := True);
734 Program : Make_Program_Type;
735 Append_Switch : Boolean := True;
736 And_Save : Boolean := True);
737 -- Make invokes one of three programs (the compiler, the binder or the
738 -- linker). For the sake of convenience, some program specific switches
739 -- can be passed directly on the gnatmake command line. This procedure
740 -- records these switches so that gnatmake can pass them to the right
741 -- program. S is the switch to be added at the end of the command line
742 -- for Program if Append_Switch is True. If Append_Switch is False S is
743 -- added at the beginning of the command line.
746 (Source_File : File_Name_Type;
748 Is_Main_Source : Boolean;
749 The_Args : Argument_List;
750 Lib_File : File_Name_Type;
751 Full_Lib_File : File_Name_Type;
752 Lib_File_Attr : access File_Attributes;
755 O_File : out File_Name_Type;
756 O_Stamp : out Time_Stamp_Type);
757 -- Determines whether the library file Lib_File is up-to-date or not. The
758 -- full name (with path information) of the object file corresponding to
759 -- Lib_File is returned in O_File. Its time stamp is saved in O_Stamp.
760 -- ALI is the ALI_Id corresponding to Lib_File. If Lib_File in not
761 -- up-to-date, then the corresponding source file needs to be recompiled.
762 -- In this case ALI = No_ALI_Id.
763 -- Full_Lib_File must be the result of calling Osint.Full_Lib_File_Name on
764 -- Lib_File. Precomputing it saves system calls. Lib_File_Attr is the
765 -- initialized attributes of that file, which is also used to save on
766 -- system calls (it can safely be initialized to Unknown_Attributes).
768 procedure Check_Linker_Options
769 (E_Stamp : Time_Stamp_Type;
770 O_File : out File_Name_Type;
771 O_Stamp : out Time_Stamp_Type);
772 -- Checks all linker options for linker files that are newer
773 -- than E_Stamp. If such objects are found, the youngest object
774 -- is returned in O_File and its stamp in O_Stamp.
776 -- If no obsolete linker files were found, the first missing
777 -- linker file is returned in O_File and O_Stamp is empty.
778 -- Otherwise O_File is No_File.
780 procedure Collect_Arguments
781 (Source_File : File_Name_Type;
783 Is_Main_Source : Boolean;
784 Args : Argument_List);
785 -- Collect all arguments for a source to be compiled, including those
786 -- that come from a project file.
788 procedure Display (Program : String; Args : Argument_List);
789 -- Displays Program followed by the arguments in Args if variable
790 -- Display_Executed_Programs is set. The lower bound of Args must be 1.
792 procedure Report_Compilation_Failed;
793 -- Delete all temporary files and fail graciously
799 type Temp_Path_Names is array (Positive range <>) of Path_Name_Type;
800 type Temp_Path_Ptr is access Temp_Path_Names;
802 type Free_File_Indexes is array (Positive range <>) of Positive;
803 type Free_Indexes_Ptr is access Free_File_Indexes;
805 type Project_Compilation_Data is record
806 Mapping_File_Names : Temp_Path_Ptr;
807 -- The name ids of the temporary mapping files used. This is indexed
808 -- on the maximum number of compilation processes we will be spawning
811 Last_Mapping_File_Names : Natural;
812 -- Index of the last mapping file created for this project
814 Free_Mapping_File_Indexes : Free_Indexes_Ptr;
815 -- Indexes in Mapping_File_Names of the mapping file names that can be
816 -- reused for subsequent compilations.
818 Last_Free_Indexes : Natural;
819 -- Number of mapping files that can be reused
821 -- Information necessary when compiling a project
823 type Project_Compilation_Access is access Project_Compilation_Data;
825 package Project_Compilation_Htable is new Simple_HTable
826 (Header_Num => Prj.Header_Num,
827 Element => Project_Compilation_Access,
833 Project_Compilation : Project_Compilation_Htable.Instance;
835 Gnatmake_Mapping_File : String_Access := null;
836 -- The path name of a mapping file specified by switch -C=
838 procedure Init_Mapping_File
839 (Project : Project_Id;
840 Data : in out Project_Compilation_Data;
841 File_Index : in out Natural);
842 -- Create a new temporary mapping file, and fill it with the project file
843 -- mappings, when using project file(s). The out parameter File_Index is
844 -- the index to the name of the file in the array The_Mapping_File_Names.
846 procedure Delete_Temp_Config_Files;
847 -- Delete all temporary config files. Must not be called if Debug_Flag_N
850 procedure Delete_All_Temp_Files;
851 -- Delete all temp files (config files, mapping files, path files), unless
852 -- Debug_Flag_N is True (in which case all temp files are left for user
855 -------------------------------------------------
856 -- Subprogram declarations moved from the spec --
857 -------------------------------------------------
859 procedure Bind (ALI_File : File_Name_Type; Args : Argument_List);
860 -- Binds ALI_File. Args are the arguments to pass to the binder.
861 -- Args must have a lower bound of 1.
863 procedure Display_Commands (Display : Boolean := True);
864 -- The default behavior of Make commands (Compile_Sources, Bind, Link)
865 -- is to display them on stderr. This behavior can be changed repeatedly
866 -- by invoking this procedure.
868 -- If a compilation, bind or link failed one of the following 3 exceptions
869 -- is raised. These need to be handled by the calling routines.
871 procedure Compile_Sources
872 (Main_Source : File_Name_Type;
873 Args : Argument_List;
874 First_Compiled_File : out File_Name_Type;
875 Most_Recent_Obj_File : out File_Name_Type;
876 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
877 Main_Unit : out Boolean;
878 Compilation_Failures : out Natural;
879 Main_Index : Int := 0;
880 Check_Readonly_Files : Boolean := False;
881 Do_Not_Execute : Boolean := False;
882 Force_Compilations : Boolean := False;
883 Keep_Going : Boolean := False;
884 In_Place_Mode : Boolean := False;
885 Initialize_ALI_Data : Boolean := True;
886 Max_Process : Positive := 1);
887 -- Compile_Sources will recursively compile all the sources needed by
888 -- Main_Source. Before calling this routine make sure Namet has been
889 -- initialized. This routine can be called repeatedly with different
890 -- Main_Source file as long as all the source (-I flags), library
891 -- (-B flags) and ada library (-A flags) search paths between calls are
892 -- *exactly* the same. The default directory must also be the same.
894 -- Args contains the arguments to use during the compilations.
895 -- The lower bound of Args must be 1.
897 -- First_Compiled_File is set to the name of the first file that is
898 -- compiled or that needs to be compiled. This is set to No_Name if no
899 -- compilations were needed.
901 -- Most_Recent_Obj_File is set to the full name of the most recent
902 -- object file found when no compilations are needed, that is when
903 -- First_Compiled_File is set to No_Name. When First_Compiled_File
904 -- is set then Most_Recent_Obj_File is set to No_Name.
906 -- Most_Recent_Obj_Stamp is the time stamp of Most_Recent_Obj_File.
908 -- Main_Unit is set to True if Main_Source can be a main unit.
909 -- If Do_Not_Execute is False and First_Compiled_File /= No_Name
910 -- the value of Main_Unit is always False.
911 -- Is this used any more??? It is certainly not used by gnatmake???
913 -- Compilation_Failures is a count of compilation failures. This count
914 -- is used to extract compilation failure reports with Extract_Failure.
916 -- Main_Index, when not zero, is the index of the main unit in source
917 -- file Main_Source which is a multi-unit source.
918 -- Zero indicates that Main_Source is a single unit source file.
920 -- Check_Readonly_Files set it to True to compile source files
921 -- which library files are read-only. When compiling GNAT predefined
922 -- files the "-gnatg" flag is used.
924 -- Do_Not_Execute set it to True to find out the first source that
925 -- needs to be recompiled, but without recompiling it. This file is
926 -- saved in First_Compiled_File.
928 -- Force_Compilations forces all compilations no matter what but
929 -- recompiles read-only files only if Check_Readonly_Files
932 -- Keep_Going when True keep compiling even in the presence of
933 -- compilation errors.
935 -- In_Place_Mode when True save library/object files in their object
936 -- directory if they already exist; otherwise, in the source directory.
938 -- Initialize_ALI_Data set it to True when you want to initialize ALI
939 -- data-structures. This is what you should do most of the time.
940 -- (especially the first time around when you call this routine).
941 -- This parameter is set to False to preserve previously recorded
944 -- Max_Process is the maximum number of processes that should be spawned
945 -- to carry out compilations.
947 -- Flags in Package Opt Affecting Compile_Sources
948 -- -----------------------------------------------
950 -- Check_Object_Consistency set it to False to omit all consistency
951 -- checks between an .ali file and its corresponding object file.
952 -- When this flag is set to true, every time an .ali is read,
953 -- package Osint checks that the corresponding object file
954 -- exists and is more recent than the .ali.
956 -- Use of Name Table Info
957 -- ----------------------
959 -- All file names manipulated by Compile_Sources are entered into the
960 -- Names table. The Byte field of a source file is used to mark it.
962 -- Calling Compile_Sources Several Times
963 -- -------------------------------------
965 -- Upon return from Compile_Sources all the ALI data structures are left
966 -- intact for further browsing. HOWEVER upon entry to this routine ALI
967 -- data structures are re-initialized if parameter Initialize_ALI_Data
968 -- above is set to true. Typically this is what you want the first time
969 -- you call Compile_Sources. You should not load an ali file, call this
970 -- routine with flag Initialize_ALI_Data set to True and then expect
971 -- that ALI information to be around after the call. Note that the first
972 -- time you call Compile_Sources you better set Initialize_ALI_Data to
973 -- True unless you have called Initialize_ALI yourself.
975 -- Compile_Sources ALGORITHM : Compile_Sources (Main_Source)
976 -- -------------------------
978 -- 1. Insert Main_Source in a Queue (Q) and mark it.
980 -- 2. Let unit.adb be the file at the head of the Q. If unit.adb is
981 -- missing but its corresponding ali file is in an Ada library directory
982 -- (see below) then, remove unit.adb from the Q and goto step 4.
983 -- Otherwise, look at the files under the D (dependency) section of
984 -- unit.ali. If unit.ali does not exist or some of the time stamps do
985 -- not match, (re)compile unit.adb.
987 -- An Ada library directory is a directory containing Ada specs, ali
988 -- and object files but no source files for the bodies. An Ada library
989 -- directory is communicated to gnatmake by means of some switch so that
990 -- gnatmake can skip the sources whole ali are in that directory.
991 -- There are two reasons for skipping the sources in this case. Firstly,
992 -- Ada libraries typically come without full sources but binding and
993 -- linking against those libraries is still possible. Secondly, it would
994 -- be very wasteful for gnatmake to systematically check the consistency
995 -- of every external Ada library used in a program. The binder is
996 -- already in charge of catching any potential inconsistencies.
998 -- 3. Look into the W section of unit.ali and insert into the Q all
999 -- unmarked source files. Mark all files newly inserted in the Q.
1000 -- Specifically, assuming that the W section looks like
1002 -- W types%s types.adb types.ali
1003 -- W unchecked_deallocation%s
1004 -- W xref_tab%s xref_tab.adb xref_tab.ali
1006 -- Then xref_tab.adb and types.adb are inserted in the Q if they are not
1008 -- Note that there is no file listed under W unchecked_deallocation%s
1009 -- so no generic body should ever be explicitly compiled (unless the
1010 -- Main_Source at the start was a generic body).
1012 -- 4. Repeat steps 2 and 3 above until the Q is empty
1014 -- Note that the above algorithm works because the units withed in
1015 -- subunits are transitively included in the W section (with section) of
1016 -- the main unit. Likewise the withed units in a generic body needed
1017 -- during a compilation are also transitively included in the W section
1018 -- of the originally compiled file.
1020 procedure Globalize (Success : out Boolean);
1021 -- Call the CodePeer globalizer on all the project's object directories,
1022 -- or on the current directory if no projects.
1024 procedure Initialize (Project_Node_Tree : out Project_Node_Tree_Ref);
1025 -- Performs default and package initialization. Therefore,
1026 -- Compile_Sources can be called by an external unit.
1029 (ALI_File : File_Name_Type;
1030 Args : Argument_List;
1031 Success : out Boolean);
1032 -- Links ALI_File. Args are the arguments to pass to the linker.
1033 -- Args must have a lower bound of 1. Success indicates if the link
1034 -- succeeded or not.
1036 procedure Scan_Make_Arg
1037 (Project_Node_Tree : Project_Node_Tree_Ref;
1039 And_Save : Boolean);
1040 -- Scan make arguments. Argv is a single argument to be processed.
1041 -- Project_Node_Tree will be used to initialize external references. It
1042 -- must have been initialized.
1048 procedure Add_Arguments (Args : Argument_List) is
1050 if Arguments = null then
1051 Arguments := new Argument_List (1 .. Args'Length + 10);
1054 while Last_Argument + Args'Length > Arguments'Last loop
1056 New_Arguments : constant Argument_List_Access :=
1057 new Argument_List (1 .. Arguments'Last * 2);
1059 New_Arguments (1 .. Last_Argument) :=
1060 Arguments (1 .. Last_Argument);
1061 Arguments := New_Arguments;
1066 Arguments (Last_Argument + 1 .. Last_Argument + Args'Length) := Args;
1067 Last_Argument := Last_Argument + Args'Length;
1070 -- --------------------
1071 -- -- Add_Dependency --
1072 -- --------------------
1074 -- procedure Add_Dependency (S : File_Name_Type; On : File_Name_Type) is
1076 -- Dependencies.Increment_Last;
1077 -- Dependencies.Table (Dependencies.Last) := (S, On);
1078 -- end Add_Dependency;
1080 ----------------------------
1081 -- Add_Library_Search_Dir --
1082 ----------------------------
1084 procedure Add_Library_Search_Dir
1086 On_Command_Line : Boolean)
1089 if On_Command_Line then
1090 Add_Lib_Search_Dir (Normalize_Pathname (Path));
1093 Get_Name_String (Main_Project.Directory.Display_Name);
1095 (Normalize_Pathname (Path, Name_Buffer (1 .. Name_Len)));
1097 end Add_Library_Search_Dir;
1099 --------------------
1100 -- Add_Object_Dir --
1101 --------------------
1103 procedure Add_Object_Dir (N : String) is
1105 Add_Lib_Search_Dir (N);
1107 if Verbose_Mode then
1108 Write_Str ("Adding object directory """);
1115 --------------------
1116 -- Add_Source_Dir --
1117 --------------------
1119 procedure Add_Source_Dir (N : String) is
1121 Add_Src_Search_Dir (N);
1123 if Verbose_Mode then
1124 Write_Str ("Adding source directory """);
1131 ---------------------------
1132 -- Add_Source_Search_Dir --
1133 ---------------------------
1135 procedure Add_Source_Search_Dir
1137 On_Command_Line : Boolean)
1140 if On_Command_Line then
1141 Add_Src_Search_Dir (Normalize_Pathname (Path));
1144 Get_Name_String (Main_Project.Directory.Display_Name);
1146 (Normalize_Pathname (Path, Name_Buffer (1 .. Name_Len)));
1148 end Add_Source_Search_Dir;
1154 procedure Add_Switch
1156 Program : Make_Program_Type;
1157 Append_Switch : Boolean := True;
1158 And_Save : Boolean := True)
1161 with package T is new Table.Table (<>);
1162 procedure Generic_Position (New_Position : out Integer);
1163 -- Generic procedure that chooses a position for S in T at the
1164 -- beginning or the end, depending on the boolean Append_Switch.
1165 -- Calling this procedure may expand the table.
1167 ----------------------
1168 -- Generic_Position --
1169 ----------------------
1171 procedure Generic_Position (New_Position : out Integer) is
1175 if Append_Switch then
1176 New_Position := Integer (T.Last);
1178 for J in reverse T.Table_Index_Type'Succ (T.First) .. T.Last loop
1179 T.Table (J) := T.Table (T.Table_Index_Type'Pred (J));
1182 New_Position := Integer (T.First);
1184 end Generic_Position;
1186 procedure Gcc_Switches_Pos is new Generic_Position (Gcc_Switches);
1187 procedure Binder_Switches_Pos is new Generic_Position (Binder_Switches);
1188 procedure Linker_Switches_Pos is new Generic_Position (Linker_Switches);
1190 procedure Saved_Gcc_Switches_Pos is new
1191 Generic_Position (Saved_Gcc_Switches);
1193 procedure Saved_Binder_Switches_Pos is new
1194 Generic_Position (Saved_Binder_Switches);
1196 procedure Saved_Linker_Switches_Pos is new
1197 Generic_Position (Saved_Linker_Switches);
1199 New_Position : Integer;
1201 -- Start of processing for Add_Switch
1207 Saved_Gcc_Switches_Pos (New_Position);
1208 Saved_Gcc_Switches.Table (New_Position) := S;
1211 Saved_Binder_Switches_Pos (New_Position);
1212 Saved_Binder_Switches.Table (New_Position) := S;
1215 Saved_Linker_Switches_Pos (New_Position);
1216 Saved_Linker_Switches.Table (New_Position) := S;
1219 raise Program_Error;
1225 Gcc_Switches_Pos (New_Position);
1226 Gcc_Switches.Table (New_Position) := S;
1229 Binder_Switches_Pos (New_Position);
1230 Binder_Switches.Table (New_Position) := S;
1233 Linker_Switches_Pos (New_Position);
1234 Linker_Switches.Table (New_Position) := S;
1237 raise Program_Error;
1242 procedure Add_Switch
1244 Program : Make_Program_Type;
1245 Append_Switch : Boolean := True;
1246 And_Save : Boolean := True)
1249 Add_Switch (S => new String'(S),
1251 Append_Switch => Append_Switch,
1252 And_Save => And_Save);
1259 procedure Add_Switches
1260 (The_Package : Package_Id;
1263 Program : Make_Program_Type;
1264 Unknown_Switches_To_The_Compiler : Boolean := True;
1265 Project_Node_Tree : Project_Node_Tree_Ref)
1267 Switches : Variable_Value;
1268 Switch_List : String_List_Id;
1269 Element : String_Element;
1272 Switch_May_Be_Passed_To_The_Compiler :=
1273 Unknown_Switches_To_The_Compiler;
1275 if File_Name'Length > 0 then
1277 Add_Str_To_Name_Buffer (File_Name);
1280 (Source_File => Name_Find,
1281 Source_File_Name => File_Name,
1282 Source_Index => Index,
1283 Project => Main_Project,
1284 In_Package => The_Package,
1285 Allow_ALI => Program = Binder or else Program = Linker);
1287 if Switches.Kind = List then
1288 Program_Args := Program;
1290 Switch_List := Switches.Values;
1291 while Switch_List /= Nil_String loop
1292 Element := Project_Tree.String_Elements.Table (Switch_List);
1293 Get_Name_String (Element.Value);
1295 if Name_Len > 0 then
1297 Argv : constant String := Name_Buffer (1 .. Name_Len);
1298 -- We need a copy, because Name_Buffer may be modified
1301 if Verbose_Mode then
1302 Write_Str (" Adding ");
1307 (Project_Node_Tree, Argv, And_Save => False);
1309 if not Gnatmake_Switch_Found
1310 and then not Switch_May_Be_Passed_To_The_Compiler
1314 """ is not a gnatmake switch. Consider moving " &
1315 "it to Global_Compilation_Switches.",
1318 Make_Failed ("*** illegal switch """ & Argv & """");
1323 Switch_List := Element.Next;
1333 procedure Bind (ALI_File : File_Name_Type; Args : Argument_List) is
1334 Bind_Args : Argument_List (1 .. Args'Last + 2);
1335 Bind_Last : Integer;
1339 pragma Assert (Args'First = 1);
1341 -- Optimize the simple case where the gnatbind command line looks like
1342 -- gnatbind -aO. -I- file.ali --into-> gnatbind file.adb
1345 and then Args (Args'First).all = "-aO" & Normalized_CWD
1346 and then Args (Args'Last).all = "-I-"
1347 and then ALI_File = Strip_Directory (ALI_File)
1349 Bind_Last := Args'First - 1;
1352 Bind_Last := Args'Last;
1353 Bind_Args (Args'Range) := Args;
1356 -- It is completely pointless to re-check source file time stamps. This
1357 -- has been done already by gnatmake
1359 Bind_Last := Bind_Last + 1;
1360 Bind_Args (Bind_Last) := Do_Not_Check_Flag;
1362 Get_Name_String (ALI_File);
1364 Bind_Last := Bind_Last + 1;
1365 Bind_Args (Bind_Last) := new String'(Name_Buffer (1 .. Name_Len));
1367 GNAT.OS_Lib.Normalize_Arguments (Bind_Args (Args'First .. Bind_Last));
1369 Display (Gnatbind.all, Bind_Args (Args'First .. Bind_Last));
1371 if Gnatbind_Path = null then
1372 Make_Failed ("error, unable to locate " & Gnatbind.all);
1376 (Gnatbind_Path.all, Bind_Args (Args'First .. Bind_Last), Success);
1379 Make_Failed ("*** bind failed.");
1383 --------------------------------
1384 -- Change_To_Object_Directory --
1385 --------------------------------
1387 procedure Change_To_Object_Directory (Project : Project_Id) is
1388 Object_Directory : Path_Name_Type;
1391 pragma Assert (Project /= No_Project);
1393 -- Nothing to do if the current working directory is already the correct
1394 -- object directory.
1396 if Project_Of_Current_Object_Directory /= Project then
1397 Project_Of_Current_Object_Directory := Project;
1398 Object_Directory := Project.Object_Directory.Display_Name;
1400 -- Set the working directory to the object directory of the actual
1403 if Verbose_Mode then
1404 Write_Str ("Changing to object directory of """);
1405 Write_Name (Project.Display_Name);
1406 Write_Str (""": """);
1407 Write_Name (Object_Directory);
1411 Change_Dir (Get_Name_String (Object_Directory));
1415 -- Fail if unable to change to the object directory
1417 when Directory_Error =>
1418 Make_Failed ("unable to change to object directory """ &
1420 (Project.Object_Directory.Display_Name) &
1422 Get_Name_String (Project.Display_Name));
1423 end Change_To_Object_Directory;
1430 (Source_File : File_Name_Type;
1432 Is_Main_Source : Boolean;
1433 The_Args : Argument_List;
1434 Lib_File : File_Name_Type;
1435 Full_Lib_File : File_Name_Type;
1436 Lib_File_Attr : access File_Attributes;
1437 Read_Only : Boolean;
1439 O_File : out File_Name_Type;
1440 O_Stamp : out Time_Stamp_Type)
1442 function First_New_Spec (A : ALI_Id) return File_Name_Type;
1443 -- Looks in the with table entries of A and returns the spec file name
1444 -- of the first withed unit (subprogram) for which no spec existed when
1445 -- A was generated but for which there exists one now, implying that A
1446 -- is now obsolete. If no such unit is found No_File is returned.
1447 -- Otherwise the spec file name of the unit is returned.
1449 -- **WARNING** in the event of Uname format modifications, one *MUST*
1450 -- make sure this function is also updated.
1452 -- Note: This function should really be in ali.adb and use Uname
1453 -- services, but this causes the whole compiler to be dragged along
1454 -- for gnatbind and gnatmake.
1456 --------------------
1457 -- First_New_Spec --
1458 --------------------
1460 function First_New_Spec (A : ALI_Id) return File_Name_Type is
1461 Spec_File_Name : File_Name_Type := No_File;
1463 function New_Spec (Uname : Unit_Name_Type) return Boolean;
1464 -- Uname is the name of the spec or body of some ada unit. This
1465 -- function returns True if the Uname is the name of a body which has
1466 -- a spec not mentioned in ALI file A. If True is returned
1467 -- Spec_File_Name above is set to the name of this spec file.
1473 function New_Spec (Uname : Unit_Name_Type) return Boolean is
1474 Spec_Name : Unit_Name_Type;
1475 File_Name : File_Name_Type;
1478 -- Test whether Uname is the name of a body unit (i.e. ends
1481 Get_Name_String (Uname);
1483 Assert (Name_Len > 2 and then Name_Buffer (Name_Len - 1) = '%');
1485 if Name_Buffer (Name_Len) /= 'b' then
1489 -- Convert unit name into spec name
1491 -- ??? this code seems dubious in presence of pragma
1492 -- Source_File_Name since there is no more direct relationship
1493 -- between unit name and file name.
1495 -- ??? Further, what about alternative subunit naming
1497 Name_Buffer (Name_Len) := 's';
1498 Spec_Name := Name_Find;
1499 File_Name := Get_File_Name (Spec_Name, Subunit => False);
1501 -- Look if File_Name is mentioned in A's sdep list.
1502 -- If not look if the file exists. If it does return True.
1505 ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep
1507 if Sdep.Table (D).Sfile = File_Name then
1512 if Full_Source_Name (File_Name) /= No_File then
1513 Spec_File_Name := File_Name;
1520 -- Start of processing for First_New_Spec
1524 ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit
1526 exit U_Chk when Units.Table (U).Utype = Is_Body_Only
1527 and then New_Spec (Units.Table (U).Uname);
1529 for W in Units.Table (U).First_With
1531 Units.Table (U).Last_With
1534 Withs.Table (W).Afile /= No_File
1535 and then New_Spec (Withs.Table (W).Uname);
1539 return Spec_File_Name;
1542 ---------------------------------
1543 -- Data declarations for Check --
1544 ---------------------------------
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_From_Full (Full_Lib_File, Lib_File_Attr);
1597 Check_Object_Consistency := Saved_Check_Object_Consistency;
1601 Text := Read_Library_Info_From_Full (Full_Lib_File, Lib_File_Attr);
1604 Full_Obj_File := Full_Object_File_Name;
1605 Lib_Stamp := Current_Library_File_Stamp;
1606 Obj_Stamp := Current_Object_File_Stamp;
1608 if Full_Lib_File = No_File then
1611 "being checked ...",
1613 Minimum_Verbosity => Opt.Medium);
1617 "being checked ...",
1619 Minimum_Verbosity => Opt.Medium);
1623 O_File := Full_Obj_File;
1624 O_Stamp := Obj_Stamp;
1627 if Full_Lib_File = No_File then
1628 Verbose_Msg (Lib_File, "missing.");
1630 elsif Obj_Stamp (Obj_Stamp'First) = ' ' then
1631 Verbose_Msg (Full_Obj_File, "missing.");
1635 (Full_Lib_File, "(" & String (Lib_Stamp) & ") newer than",
1636 Full_Obj_File, "(" & String (Obj_Stamp) & ")");
1640 ALI := Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
1643 if ALI = No_ALI_Id then
1644 Verbose_Msg (Full_Lib_File, "incorrectly formatted ALI file");
1647 elsif ALIs.Table (ALI).Ver (1 .. ALIs.Table (ALI).Ver_Len) /=
1648 Verbose_Library_Version
1650 Verbose_Msg (Full_Lib_File, "compiled with old GNAT version");
1655 -- Don't take Ali file into account if it was generated with
1658 if ALIs.Table (ALI).Compile_Errors then
1659 Verbose_Msg (Full_Lib_File, "had errors, must be recompiled");
1664 -- Don't take Ali file into account if it was generated without
1667 if Operating_Mode /= Check_Semantics
1668 and then ALIs.Table (ALI).No_Object
1670 Verbose_Msg (Full_Lib_File, "has no corresponding object");
1675 -- When compiling with -gnatc, don't take ALI file into account if
1676 -- it has not been generated for the current source, for example if
1677 -- it has been generated for the spec, but we are compiling the body.
1679 if Operating_Mode = Check_Semantics then
1681 File_Name : constant String := Get_Name_String (Source_File);
1682 OK : Boolean := False;
1685 for U in ALIs.Table (ALI).First_Unit ..
1686 ALIs.Table (ALI).Last_Unit
1688 OK := Get_Name_String (Units.Table (U).Sfile) = File_Name;
1694 (Full_Lib_File, "not generated for the same source");
1701 -- Check for matching compiler switches if needed
1703 if Check_Switches then
1705 -- First, collect all the switches
1708 (Source_File, Source_Index, Is_Main_Source, The_Args);
1710 Prev_Switch := Dummy_Switch;
1712 Get_Name_String (ALIs.Table (ALI).Sfile);
1714 Switches_To_Check.Set_Last (0);
1716 for J in 1 .. Last_Argument loop
1718 -- Skip non switches -c, -I and -o switches
1720 if Arguments (J) (1) = '-'
1721 and then Arguments (J) (2) /= 'c'
1722 and then Arguments (J) (2) /= 'o'
1723 and then Arguments (J) (2) /= 'I'
1725 Normalize_Compiler_Switches
1727 Normalized_Switches,
1730 for K in 1 .. Last_Norm_Switch loop
1731 Switches_To_Check.Increment_Last;
1732 Switches_To_Check.Table (Switches_To_Check.Last) :=
1733 Normalized_Switches (K);
1738 for J in 1 .. Switches_To_Check.Last loop
1740 -- Comparing switches is delicate because gcc reorders a number
1741 -- of switches, according to lang-specs.h, but gnatmake doesn't
1742 -- have sufficient knowledge to perform the same reordering.
1743 -- Instead, we ignore orders between different "first letter"
1744 -- switches, but keep orders between same switches, e.g -O -O2
1745 -- is different than -O2 -O, but -g -O is equivalent to -O -g.
1747 if Switches_To_Check.Table (J) (2) /= Prev_Switch (2) or else
1748 (Prev_Switch'Length >= 6 and then
1749 Prev_Switch (2 .. 5) = "gnat" and then
1750 Switches_To_Check.Table (J)'Length >= 6 and then
1751 Switches_To_Check.Table (J) (2 .. 5) = "gnat" and then
1752 Prev_Switch (6) /= Switches_To_Check.Table (J) (6))
1754 Prev_Switch := Switches_To_Check.Table (J);
1756 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg;
1759 Switch_Found := False;
1762 Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1765 Switches_To_Check.Table (J).all = Args.Table (K).all
1768 Switch_Found := True;
1773 if not Switch_Found then
1774 if Verbose_Mode then
1775 Verbose_Msg (ALIs.Table (ALI).Sfile,
1776 "switch mismatch """ &
1777 Switches_To_Check.Table (J).all & '"');
1785 if Switches_To_Check.Last /=
1786 Integer (Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg -
1787 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg + 1)
1789 if Verbose_Mode then
1790 Verbose_Msg (ALIs.Table (ALI).Sfile,
1791 "different number of switches");
1793 for K in Units.Table (ALIs.Table (ALI).First_Unit).First_Arg
1794 .. Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1796 Write_Str (Args.Table (K).all);
1802 for J in 1 .. Switches_To_Check.Last loop
1803 Write_Str (Switches_To_Check.Table (J).all);
1815 -- Get the source files and their message digests. Note that some
1816 -- sources may be missing if ALI is out-of-date.
1818 Set_Source_Table (ALI);
1820 Modified_Source := Time_Stamp_Mismatch (ALI, Read_Only);
1822 -- To avoid using too much memory when switch -m is used, free the
1823 -- memory allocated for the source file when computing the checksum.
1825 if Minimal_Recompilation then
1826 Sinput.P.Clear_Source_File_Table;
1829 if Modified_Source /= No_File then
1832 if Verbose_Mode then
1833 Source_Name := Full_Source_Name (Modified_Source);
1835 if Source_Name /= No_File then
1836 Verbose_Msg (Source_Name, "time stamp mismatch");
1838 Verbose_Msg (Modified_Source, "missing");
1843 New_Spec := First_New_Spec (ALI);
1845 if New_Spec /= No_File then
1848 if Verbose_Mode then
1849 Source_Name := Full_Source_Name (New_Spec);
1851 if Source_Name /= No_File then
1852 Verbose_Msg (Source_Name, "new spec");
1854 Verbose_Msg (New_Spec, "old spec missing");
1858 elsif not Read_Only and then Main_Project /= No_Project then
1859 if not Check_Source_Info_In_ALI (ALI, Project_Tree) then
1864 -- Check that the ALI file is in the correct object directory.
1865 -- If it is in the object directory of a project that is
1866 -- extended and it depends on a source that is in one of its
1867 -- extending projects, then the ALI file is not in the correct
1868 -- object directory.
1870 -- First, find the project of this ALI file. As there may be
1871 -- several projects with the same object directory, we first
1872 -- need to find the project of the source.
1874 ALI_Project := No_Project;
1877 Udata : Prj.Unit_Index;
1880 Udata := Units_Htable.Get_First (Project_Tree.Units_HT);
1881 while Udata /= No_Unit_Index loop
1882 if Udata.File_Names (Impl) /= null
1883 and then Udata.File_Names (Impl).File = Source_File
1885 ALI_Project := Udata.File_Names (Impl).Project;
1888 elsif Udata.File_Names (Spec) /= null
1889 and then Udata.File_Names (Spec).File = Source_File
1891 ALI_Project := Udata.File_Names (Spec).Project;
1895 Udata := Units_Htable.Get_Next (Project_Tree.Units_HT);
1899 if ALI_Project = No_Project then
1904 Obj_Dir : Path_Name_Type;
1905 Res_Obj_Dir : constant String :=
1908 (Get_Name_String (Full_Lib_File)),
1910 Opt.Follow_Links_For_Dirs,
1911 Case_Sensitive => False);
1915 Add_Str_To_Name_Buffer (Res_Obj_Dir);
1917 if not Is_Directory_Separator (Name_Buffer (Name_Len)) then
1918 Add_Char_To_Name_Buffer (Directory_Separator);
1921 Obj_Dir := Name_Find;
1923 while ALI_Project /= No_Project
1924 and then Obj_Dir /= ALI_Project.Object_Directory.Name
1926 ALI_Project := ALI_Project.Extended_By;
1930 if ALI_Project = No_Project then
1933 Verbose_Msg (Lib_File, " wrong object directory");
1937 -- If the ALI project is not extended, then it must be in
1938 -- the correct object directory.
1940 if ALI_Project.Extended_By = No_Project then
1944 -- Count the extending projects
1952 Proj := ALI_Project;
1954 Proj := Proj.Extended_By;
1955 exit when Proj = No_Project;
1956 Num_Ext := Num_Ext + 1;
1959 -- Make a list of the extending projects
1962 Projects : array (1 .. Num_Ext) of Project_Id;
1964 OK : Boolean := True;
1968 Proj := ALI_Project;
1969 for J in Projects'Range loop
1970 Proj := Proj.Extended_By;
1971 Projects (J) := Proj;
1974 -- Now check if any of the dependant sources are in
1975 -- any of these extending projects.
1978 for D in ALIs.Table (ALI).First_Sdep ..
1979 ALIs.Table (ALI).Last_Sdep
1981 Dep := Sdep.Table (D);
1982 UID := Units_Htable.Get_First (Project_Tree.Units_HT);
1986 while UID /= null loop
1987 if UID.File_Names (Impl) /= null
1988 and then UID.File_Names (Impl).File = Dep.Sfile
1990 Proj := UID.File_Names (Impl).Project;
1992 elsif UID.File_Names (Spec) /= null
1993 and then UID.File_Names (Spec).File = Dep.Sfile
1995 Proj := UID.File_Names (Spec).Project;
1998 -- If a source is in a project, check if it is one
2001 if Proj /= No_Project then
2002 for J in Projects'Range loop
2003 if Proj = Projects (J) then
2013 Units_Htable.Get_Next (Project_Tree.Units_HT);
2017 -- If one of the dependent sources is in one project of
2018 -- the list, then we must recompile.
2022 Verbose_Msg (Lib_File, " wrong object directory");
2031 ------------------------
2032 -- Check_For_S_Switch --
2033 ------------------------
2035 procedure Check_For_S_Switch is
2037 -- By default, we generate an object file
2039 Output_Is_Object := True;
2041 for Arg in 1 .. Last_Argument loop
2042 if Arguments (Arg).all = "-S" then
2043 Output_Is_Object := False;
2045 elsif Arguments (Arg).all = "-c" then
2046 Output_Is_Object := True;
2049 end Check_For_S_Switch;
2051 --------------------------
2052 -- Check_Linker_Options --
2053 --------------------------
2055 procedure Check_Linker_Options
2056 (E_Stamp : Time_Stamp_Type;
2057 O_File : out File_Name_Type;
2058 O_Stamp : out Time_Stamp_Type)
2060 procedure Check_File (File : File_Name_Type);
2061 -- Update O_File and O_Stamp if the given file is younger than E_Stamp
2062 -- and O_Stamp, or if O_File is No_File and File does not exist.
2064 function Get_Library_File (Name : String) return File_Name_Type;
2065 -- Return the full file name including path of a library based
2066 -- on the name specified with the -l linker option, using the
2067 -- Ada object path. Return No_File if no such file can be found.
2069 type Char_Array is array (Natural) of Character;
2070 type Char_Array_Access is access constant Char_Array;
2072 Template : Char_Array_Access;
2073 pragma Import (C, Template, "__gnat_library_template");
2079 procedure Check_File (File : File_Name_Type) is
2080 Stamp : Time_Stamp_Type;
2081 Name : File_Name_Type := File;
2084 Get_Name_String (Name);
2086 -- Remove any trailing NUL characters
2088 while Name_Len >= Name_Buffer'First
2089 and then Name_Buffer (Name_Len) = NUL
2091 Name_Len := Name_Len - 1;
2094 if Name_Len = 0 then
2097 elsif Name_Buffer (1) = '-' then
2099 -- Do not check if File is a switch other than "-l"
2101 if Name_Buffer (2) /= 'l' then
2105 -- The argument is a library switch, get actual name. It
2106 -- is necessary to make a copy of the relevant part of
2107 -- Name_Buffer as Get_Library_Name uses Name_Buffer as well.
2110 Base_Name : constant String := Name_Buffer (3 .. Name_Len);
2113 Name := Get_Library_File (Base_Name);
2116 if Name = No_File then
2121 Stamp := File_Stamp (Name);
2123 -- Find the youngest object file that is younger than the
2124 -- executable. If no such file exist, record the first object
2125 -- file that is not found.
2127 if (O_Stamp < Stamp and then E_Stamp < Stamp)
2128 or else (O_File = No_File and then Stamp (Stamp'First) = ' ')
2133 -- Strip the trailing NUL if present
2135 Get_Name_String (O_File);
2137 if Name_Buffer (Name_Len) = NUL then
2138 Name_Len := Name_Len - 1;
2139 O_File := Name_Find;
2144 ----------------------
2145 -- Get_Library_Name --
2146 ----------------------
2148 -- See comments in a-adaint.c about template syntax
2150 function Get_Library_File (Name : String) return File_Name_Type is
2151 File : File_Name_Type := No_File;
2156 for Ptr in Template'Range loop
2157 case Template (Ptr) is
2159 Add_Str_To_Name_Buffer (Name);
2162 File := Full_Lib_File_Name (Name_Find);
2163 exit when File /= No_File;
2170 Add_Char_To_Name_Buffer (Template (Ptr));
2174 -- The for loop exited because the end of the template
2175 -- was reached. File contains the last possible file name
2178 if File = No_File and then Name_Len > 0 then
2179 File := Full_Lib_File_Name (Name_Find);
2183 end Get_Library_File;
2185 -- Start of processing for Check_Linker_Options
2189 O_Stamp := (others => ' ');
2191 -- Process linker options from the ALI files
2193 for Opt in 1 .. Linker_Options.Last loop
2194 Check_File (File_Name_Type (Linker_Options.Table (Opt).Name));
2197 -- Process options given on the command line
2199 for Opt in Linker_Switches.First .. Linker_Switches.Last loop
2201 -- Check if the previous Opt has one of the two switches
2202 -- that take an extra parameter. (See GCC manual.)
2204 if Opt = Linker_Switches.First
2205 or else (Linker_Switches.Table (Opt - 1).all /= "-u"
2207 Linker_Switches.Table (Opt - 1).all /= "-Xlinker"
2209 Linker_Switches.Table (Opt - 1).all /= "-L")
2212 Add_Str_To_Name_Buffer (Linker_Switches.Table (Opt).all);
2213 Check_File (Name_Find);
2216 end Check_Linker_Options;
2222 procedure Check_Steps is
2224 -- If either -c, -b or -l has been specified, we will not necessarily
2225 -- execute all steps.
2228 Do_Compile_Step := Do_Compile_Step and Compile_Only;
2229 Do_Bind_Step := Do_Bind_Step and Bind_Only;
2230 Do_Link_Step := Do_Link_Step and Link_Only;
2232 -- If -c has been specified, but not -b, ignore any potential -l
2234 if Do_Compile_Step and then not Do_Bind_Step then
2235 Do_Link_Step := False;
2240 -----------------------
2241 -- Collect_Arguments --
2242 -----------------------
2244 procedure Collect_Arguments
2245 (Source_File : File_Name_Type;
2247 Is_Main_Source : Boolean;
2248 Args : Argument_List)
2251 Arguments_Project := No_Project;
2253 Add_Arguments (Args);
2255 if Main_Project /= No_Project then
2257 Source_File_Name : constant String :=
2258 Get_Name_String (Source_File);
2259 Compiler_Package : Prj.Package_Id;
2260 Switches : Prj.Variable_Value;
2265 (Source_File_Name => Source_File_Name,
2266 Project => Arguments_Project,
2267 Path => Arguments_Path_Name,
2268 In_Tree => Project_Tree);
2270 -- If the source is not a source of a project file, add the
2271 -- recorded arguments. Check will be done later if the source
2272 -- need to be compiled that the switch -x has been used.
2274 if Arguments_Project = No_Project then
2275 Add_Arguments (The_Saved_Gcc_Switches.all);
2277 elsif not Arguments_Project.Externally_Built
2278 or else Must_Compile
2280 -- We get the project directory for the relative path
2281 -- switches and arguments.
2283 Arguments_Project :=
2284 Ultimate_Extending_Project_Of (Arguments_Project);
2286 -- If building a dynamic or relocatable library, compile with
2287 -- PIC option, if it exists.
2289 if Arguments_Project.Library
2290 and then Arguments_Project.Library_Kind /= Static
2293 PIC : constant String := MLib.Tgt.PIC_Option;
2296 Add_Arguments ((1 => new String'(PIC)));
2301 -- We now look for package Compiler and get the switches from
2306 (Name => Name_Compiler,
2307 In_Packages => Arguments_Project.Decl.Packages,
2308 In_Tree => Project_Tree);
2310 if Compiler_Package /= No_Package then
2312 -- If package Gnatmake.Compiler exists, we get the specific
2313 -- switches for the current source, or the global switches,
2318 (Source_File => Source_File,
2319 Source_File_Name => Source_File_Name,
2320 Source_Index => Source_Index,
2321 Project => Arguments_Project,
2322 In_Package => Compiler_Package,
2323 Allow_ALI => False);
2327 case Switches.Kind is
2329 -- We have a list of switches. We add these switches,
2330 -- plus the saved gcc switches.
2335 Current : String_List_Id := Switches.Values;
2336 Element : String_Element;
2337 Number : Natural := 0;
2340 while Current /= Nil_String loop
2341 Element := Project_Tree.String_Elements.
2343 Number := Number + 1;
2344 Current := Element.Next;
2348 New_Args : Argument_List (1 .. Number);
2349 Last_New : Natural := 0;
2350 Dir_Path : constant String := Get_Name_String
2351 (Arguments_Project.Directory.Display_Name);
2354 Current := Switches.Values;
2356 for Index in New_Args'Range loop
2357 Element := Project_Tree.String_Elements.
2359 Get_Name_String (Element.Value);
2361 if Name_Len > 0 then
2362 Last_New := Last_New + 1;
2363 New_Args (Last_New) :=
2364 new String'(Name_Buffer (1 .. Name_Len));
2365 Test_If_Relative_Path
2366 (New_Args (Last_New),
2368 Including_Non_Switch => False);
2371 Current := Element.Next;
2375 (Configuration_Pragmas_Switch
2376 (Arguments_Project) &
2377 New_Args (1 .. Last_New) &
2378 The_Saved_Gcc_Switches.all);
2382 -- We have a single switch. We add this switch,
2383 -- plus the saved gcc switches.
2386 Get_Name_String (Switches.Value);
2389 New_Args : Argument_List :=
2391 (Name_Buffer (1 .. Name_Len)));
2392 Dir_Path : constant String :=
2395 Directory.Display_Name);
2398 Test_If_Relative_Path
2401 Including_Non_Switch => False);
2403 (Configuration_Pragmas_Switch (Arguments_Project) &
2404 New_Args & The_Saved_Gcc_Switches.all);
2407 -- We have no switches from Gnatmake.Compiler.
2408 -- We add the saved gcc switches.
2412 (Configuration_Pragmas_Switch (Arguments_Project) &
2413 The_Saved_Gcc_Switches.all);
2419 -- For VMS, when compiling the main source, add switch
2420 -- -mdebug-main=_ada_ so that the executable can be debugged
2421 -- by the standard VMS debugger.
2423 if not No_Main_Subprogram
2424 and then Targparm.OpenVMS_On_Target
2425 and then Is_Main_Source
2427 -- First, check if compilation will be invoked with -g
2429 for J in 1 .. Last_Argument loop
2430 if Arguments (J)'Length >= 2
2431 and then Arguments (J) (1 .. 2) = "-g"
2432 and then (Arguments (J)'Length < 5
2433 or else Arguments (J) (1 .. 5) /= "-gnat")
2436 ((1 => new String'("-mdebug-main=_ada_")));
2442 -- Set Output_Is_Object, depending if there is a -S switch.
2443 -- If the bind step is not performed, and there is a -S switch,
2444 -- then we will not check for a valid object file.
2447 end Collect_Arguments;
2449 ---------------------
2450 -- Compile_Sources --
2451 ---------------------
2453 procedure Compile_Sources
2454 (Main_Source : File_Name_Type;
2455 Args : Argument_List;
2456 First_Compiled_File : out File_Name_Type;
2457 Most_Recent_Obj_File : out File_Name_Type;
2458 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
2459 Main_Unit : out Boolean;
2460 Compilation_Failures : out Natural;
2461 Main_Index : Int := 0;
2462 Check_Readonly_Files : Boolean := False;
2463 Do_Not_Execute : Boolean := False;
2464 Force_Compilations : Boolean := False;
2465 Keep_Going : Boolean := False;
2466 In_Place_Mode : Boolean := False;
2467 Initialize_ALI_Data : Boolean := True;
2468 Max_Process : Positive := 1)
2470 Mfile : Natural := No_Mapping_File;
2471 Mapping_File_Arg : String_Access;
2472 -- Info on the mapping file
2474 Need_To_Check_Standard_Library : Boolean :=
2475 (Check_Readonly_Files or Must_Compile)
2476 and not Unique_Compile;
2478 procedure Add_Process
2480 Sfile : File_Name_Type;
2481 Afile : File_Name_Type;
2482 Uname : Unit_Name_Type;
2483 Full_Lib_File : File_Name_Type;
2484 Lib_File_Attr : File_Attributes;
2485 Mfile : Natural := No_Mapping_File);
2486 -- Adds process Pid to the current list of outstanding compilation
2487 -- processes and record the full name of the source file Sfile that
2488 -- we are compiling, the name of its library file Afile and the
2489 -- name of its unit Uname. If Mfile is not equal to No_Mapping_File,
2490 -- it is the index of the mapping file used during compilation in the
2491 -- array The_Mapping_File_Names.
2493 procedure Await_Compile
2494 (Data : out Compilation_Data;
2496 -- Awaits that an outstanding compilation process terminates. When it
2497 -- does set Data to the information registered for the corresponding
2498 -- call to Add_Process. Note that this time stamp can be used to check
2499 -- whether the compilation did generate an object file. OK is set to
2500 -- True if the compilation succeeded. Data could be No_Compilation_Data
2501 -- if there was no compilation to wait for.
2503 function Bad_Compilation_Count return Natural;
2504 -- Returns the number of compilation failures
2506 procedure Check_Standard_Library;
2507 -- Check if s-stalib.adb needs to be compiled
2509 procedure Collect_Arguments_And_Compile
2510 (Full_Source_File : File_Name_Type;
2511 Lib_File : File_Name_Type;
2513 Pid : out Process_Id;
2514 Process_Created : out Boolean);
2515 -- Collect arguments from project file (if any) and compile. If no
2516 -- compilation was attempted, Processed_Created is set to False, and the
2517 -- value of Pid is unknown.
2520 (Project : Project_Id;
2524 Args : Argument_List) return Process_Id;
2525 -- Compiles S using Args. If S is a GNAT predefined source "-gnatpg" is
2526 -- added to Args. Non blocking call. L corresponds to the expected
2527 -- library file name. Process_Id of the process spawned to execute the
2530 type ALI_Project is record
2532 Project : Project_Id;
2535 package Good_ALI is new Table.Table (
2536 Table_Component_Type => ALI_Project,
2537 Table_Index_Type => Natural,
2538 Table_Low_Bound => 1,
2539 Table_Initial => 50,
2540 Table_Increment => 100,
2541 Table_Name => "Make.Good_ALI");
2542 -- Contains the set of valid ALI files that have not yet been scanned
2544 function Good_ALI_Present return Boolean;
2545 -- Returns True if any ALI file was recorded in the previous set
2547 procedure Get_Mapping_File (Project : Project_Id);
2548 -- Get a mapping file name. If there is one to be reused, reuse it.
2549 -- Otherwise, create a new mapping file.
2551 function Get_Next_Good_ALI return ALI_Project;
2552 -- Returns the next good ALI_Id record
2554 procedure Record_Failure
2555 (File : File_Name_Type;
2556 Unit : Unit_Name_Type;
2557 Found : Boolean := True);
2558 -- Records in the previous table that the compilation for File failed.
2559 -- If Found is False then the compilation of File failed because we
2560 -- could not find it. Records also Unit when possible.
2562 procedure Record_Good_ALI (A : ALI_Id; Project : Project_Id);
2563 -- Records in the previous set the Id of an ALI file
2565 function Must_Exit_Because_Of_Error return Boolean;
2566 -- Return True if there were errors and the user decided to exit in such
2567 -- a case. This waits for any outstanding compilation.
2569 function Start_Compile_If_Possible (Args : Argument_List) return Boolean;
2570 -- Check if there is more work that we can do (i.e. the Queue is non
2571 -- empty). If there is, do it only if we have not yet used up all the
2572 -- available processes.
2573 -- Returns True if we should exit the main loop
2575 procedure Wait_For_Available_Slot;
2576 -- Check if we should wait for a compilation to finish. This is the case
2577 -- if all the available processes are busy compiling sources or there is
2578 -- nothing else to do (that is the Q is empty and there are no good ALIs
2581 procedure Fill_Queue_From_ALI_Files;
2582 -- Check if we recorded good ALI files. If yes process them now in the
2583 -- order in which they have been recorded. There are two occasions in
2584 -- which we record good ali files. The first is in phase 1 when, after
2585 -- scanning an existing ALI file we realize it is up-to-date, the second
2586 -- instance is after a successful compilation.
2592 procedure Add_Process
2594 Sfile : File_Name_Type;
2595 Afile : File_Name_Type;
2596 Uname : Unit_Name_Type;
2597 Full_Lib_File : File_Name_Type;
2598 Lib_File_Attr : File_Attributes;
2599 Mfile : Natural := No_Mapping_File)
2601 OC1 : constant Positive := Outstanding_Compiles + 1;
2604 pragma Assert (OC1 <= Max_Process);
2605 pragma Assert (Pid /= Invalid_Pid);
2607 Running_Compile (OC1) :=
2609 Full_Source_File => Sfile,
2611 Full_Lib_File => Full_Lib_File,
2612 Lib_File_Attr => Lib_File_Attr,
2613 Source_Unit => Uname,
2614 Mapping_File => Mfile,
2615 Project => Arguments_Project);
2617 Outstanding_Compiles := OC1;
2619 if Arguments_Project /= No_Project then
2620 Queue.Set_Obj_Dir_Busy (Arguments_Project.Object_Directory.Name);
2624 --------------------
2628 procedure Await_Compile
2629 (Data : out Compilation_Data;
2633 Project : Project_Id;
2634 Comp_Data : Project_Compilation_Access;
2637 pragma Assert (Outstanding_Compiles > 0);
2639 Data := No_Compilation_Data;
2642 -- The loop here is a work-around for a problem on VMS; in some
2643 -- circumstances (shared library and several executables, for
2644 -- example), there are child processes other than compilation
2645 -- processes that are received. Until this problem is resolved,
2646 -- we will ignore such processes.
2649 Wait_Process (Pid, OK);
2651 if Pid = Invalid_Pid then
2655 for J in Running_Compile'First .. Outstanding_Compiles loop
2656 if Pid = Running_Compile (J).Pid then
2657 Data := Running_Compile (J);
2658 Project := Running_Compile (J).Project;
2660 if Project /= No_Project then
2661 Queue.Set_Obj_Dir_Free (Project.Object_Directory.Name);
2664 -- If a mapping file was used by this compilation, get its
2665 -- file name for reuse by a subsequent compilation.
2667 if Running_Compile (J).Mapping_File /= No_Mapping_File then
2669 Project_Compilation_Htable.Get
2670 (Project_Compilation, Project);
2671 Comp_Data.Last_Free_Indexes :=
2672 Comp_Data.Last_Free_Indexes + 1;
2673 Comp_Data.Free_Mapping_File_Indexes
2674 (Comp_Data.Last_Free_Indexes) :=
2675 Running_Compile (J).Mapping_File;
2678 -- To actually remove this Pid and related info from
2679 -- Running_Compile replace its entry with the last valid
2680 -- entry in Running_Compile.
2682 if J = Outstanding_Compiles then
2685 Running_Compile (J) :=
2686 Running_Compile (Outstanding_Compiles);
2689 Outstanding_Compiles := Outstanding_Compiles - 1;
2694 -- This child process was not one of our compilation processes;
2695 -- just ignore it for now.
2697 -- Why is this commented out code sitting here???
2699 -- raise Program_Error;
2703 ---------------------------
2704 -- Bad_Compilation_Count --
2705 ---------------------------
2707 function Bad_Compilation_Count return Natural is
2709 return Bad_Compilation.Last - Bad_Compilation.First + 1;
2710 end Bad_Compilation_Count;
2712 ----------------------------
2713 -- Check_Standard_Library --
2714 ----------------------------
2716 procedure Check_Standard_Library is
2718 Need_To_Check_Standard_Library := False;
2720 if not Targparm.Suppress_Standard_Library_On_Target then
2722 Sfile : File_Name_Type;
2723 Add_It : Boolean := True;
2727 Add_Str_To_Name_Buffer (Standard_Library_Package_Body_Name);
2728 Sfile := Name_Enter;
2730 -- If we have a special runtime, we add the standard
2731 -- library only if we can find it.
2734 Add_It := Full_Source_Name (Sfile) /= No_File;
2738 if Is_Marked (Sfile) then
2739 if Is_In_Obsoleted (Sfile) then
2740 Executable_Obsolete := True;
2744 Queue.Insert (Sfile, Project => No_Project, Index => 0);
2745 Mark (Sfile, Index => 0);
2750 end Check_Standard_Library;
2752 -----------------------------------
2753 -- Collect_Arguments_And_Compile --
2754 -----------------------------------
2756 procedure Collect_Arguments_And_Compile
2757 (Full_Source_File : File_Name_Type;
2758 Lib_File : File_Name_Type;
2760 Pid : out Process_Id;
2761 Process_Created : out Boolean) is
2763 Process_Created := False;
2765 -- If we use mapping file (-P or -C switches), then get one
2767 if Create_Mapping_File then
2768 Get_Mapping_File (Arguments_Project);
2771 -- If the source is part of a project file, we set the ADA_*_PATHs,
2772 -- check for an eventual library project, and use the full path.
2774 if Arguments_Project /= No_Project then
2775 if not Arguments_Project.Externally_Built
2776 or else Must_Compile
2778 Prj.Env.Set_Ada_Paths
2781 Including_Libraries => True,
2782 Include_Path => Use_Include_Path_File);
2784 if not Unique_Compile
2785 and then MLib.Tgt.Support_For_Libraries /= Prj.None
2788 Prj : constant Project_Id :=
2789 Ultimate_Extending_Project_Of (Arguments_Project);
2793 and then (not Prj.Externally_Built or else Must_Compile)
2794 and then not Prj.Need_To_Build_Lib
2796 -- Add to the Q all sources of the project that have
2799 Insert_Project_Sources
2800 (The_Project => Prj,
2801 All_Projects => False,
2804 -- Now mark the project as processed
2806 Prj.Need_To_Build_Lib := True;
2813 (Project => Arguments_Project,
2814 S => File_Name_Type (Arguments_Path_Name),
2816 Source_Index => Source_Index,
2817 Args => Arguments (1 .. Last_Argument));
2818 Process_Created := True;
2822 -- If this is a source outside of any project file, make sure it
2823 -- will be compiled in object directory of the main project file.
2827 (Project => Main_Project,
2828 S => Full_Source_File,
2830 Source_Index => Source_Index,
2831 Args => Arguments (1 .. Last_Argument));
2832 Process_Created := True;
2834 end Collect_Arguments_And_Compile;
2841 (Project : Project_Id;
2845 Args : Argument_List) return Process_Id
2847 Comp_Args : Argument_List (Args'First .. Args'Last + 10);
2848 Comp_Next : Integer := Args'First;
2849 Comp_Last : Integer;
2850 Arg_Index : Integer;
2852 function Ada_File_Name (Name : File_Name_Type) return Boolean;
2853 -- Returns True if Name is the name of an ada source file
2854 -- (i.e. suffix is .ads or .adb)
2860 function Ada_File_Name (Name : File_Name_Type) return Boolean is
2862 Get_Name_String (Name);
2865 and then Name_Buffer (Name_Len - 3 .. Name_Len - 1) = ".ad"
2866 and then (Name_Buffer (Name_Len) = 'b'
2868 Name_Buffer (Name_Len) = 's');
2871 -- Start of processing for Compile
2874 Enter_Into_Obsoleted (S);
2876 -- By default, Syntax_Only is False
2878 Syntax_Only := False;
2880 for J in Args'Range loop
2881 if Args (J).all = "-gnats" then
2883 -- If we compile with -gnats, the bind step and the link step
2884 -- are inhibited. Also, we set Syntax_Only to True, so that
2885 -- we don't fail when we don't find the ALI file, after
2888 Do_Bind_Step := False;
2889 Do_Link_Step := False;
2890 Syntax_Only := True;
2892 elsif Args (J).all = "-gnatc" then
2894 -- If we compile with -gnatc, the bind step and the link step
2895 -- are inhibited. We set Syntax_Only to False for the case when
2896 -- -gnats was previously specified.
2898 Do_Bind_Step := False;
2899 Do_Link_Step := False;
2900 Syntax_Only := False;
2902 elsif Args (J).all = "-gnatC"
2903 or else Args (J).all = "-gnatcC"
2905 -- If we compile with -gnatC, enable CodePeer globalize step
2907 Do_Codepeer_Globalize_Step := True;
2911 Comp_Args (Comp_Next) := new String'("-gnatea");
2912 Comp_Next := Comp_Next + 1;
2914 Comp_Args (Comp_Next) := Comp_Flag;
2915 Comp_Next := Comp_Next + 1;
2917 -- Optimize the simple case where the gcc command line looks like
2918 -- gcc -c -I. ... -I- file.adb
2920 -- gcc -c ... file.adb
2922 if Args (Args'First).all = "-I" & Normalized_CWD
2923 and then Args (Args'Last).all = "-I-"
2924 and then S = Strip_Directory (S)
2926 Comp_Last := Comp_Next + Args'Length - 3;
2927 Arg_Index := Args'First + 1;
2930 Comp_Last := Comp_Next + Args'Length - 1;
2931 Arg_Index := Args'First;
2934 -- Make a deep copy of the arguments, because Normalize_Arguments
2935 -- may deallocate some arguments. Also strip target specific -mxxx
2936 -- switches in CodePeer mode.
2940 Last : constant Natural := Comp_Last;
2944 for J in Comp_Next .. Last loop
2946 Str : String renames Args (Arg_Index).all;
2948 if Do_Codepeer_Globalize_Step
2949 and then Str'Length > 2
2950 and then Str (Str'First .. Str'First + 1) = "-m"
2952 Comp_Last := Comp_Last - 1;
2954 Comp_Args (Index) := new String'(Str);
2959 Arg_Index := Arg_Index + 1;
2963 -- Set -gnatpg for predefined files (for this purpose the renamings
2964 -- such as Text_IO do not count as predefined). Note that we strip
2965 -- the directory name from the source file name because the call to
2966 -- Fname.Is_Predefined_File_Name cannot deal with directory prefixes.
2969 Fname : constant File_Name_Type := Strip_Directory (S);
2972 if Is_Predefined_File_Name (Fname, False) then
2973 if Check_Readonly_Files or else Must_Compile then
2974 Comp_Args (Comp_Args'First + 2 .. Comp_Last + 1) :=
2975 Comp_Args (Comp_Args'First + 1 .. Comp_Last);
2976 Comp_Last := Comp_Last + 1;
2977 Comp_Args (Comp_Args'First + 1) := GNAT_Flag;
2981 ("not allowed to compile """ &
2982 Get_Name_String (Fname) &
2983 """; use -a switch, or compile file with " &
2984 """-gnatg"" switch");
2989 -- Now check if the file name has one of the suffixes familiar to
2990 -- the gcc driver. If this is not the case then add the ada flag
2993 if not Ada_File_Name (S) and then not Targparm.AAMP_On_Target then
2994 Comp_Last := Comp_Last + 1;
2995 Comp_Args (Comp_Last) := Ada_Flag_1;
2996 Comp_Last := Comp_Last + 1;
2997 Comp_Args (Comp_Last) := Ada_Flag_2;
3000 if Source_Index /= 0 then
3002 Num : constant String := Source_Index'Img;
3004 Comp_Last := Comp_Last + 1;
3005 Comp_Args (Comp_Last) :=
3006 new String'("-gnateI" & Num (Num'First + 1 .. Num'Last));
3010 if Source_Index /= 0
3011 or else L /= Strip_Directory (L)
3012 or else Object_Directory_Path /= null
3014 -- Build -o argument
3016 Get_Name_String (L);
3018 for J in reverse 1 .. Name_Len loop
3019 if Name_Buffer (J) = '.' then
3020 Name_Len := J + Object_Suffix'Length - 1;
3021 Name_Buffer (J .. Name_Len) := Object_Suffix;
3026 Comp_Last := Comp_Last + 1;
3027 Comp_Args (Comp_Last) := Output_Flag;
3028 Comp_Last := Comp_Last + 1;
3030 -- If an object directory was specified, prepend the object file
3031 -- name with this object directory.
3033 if Object_Directory_Path /= null then
3034 Comp_Args (Comp_Last) :=
3035 new String'(Object_Directory_Path.all &
3036 Name_Buffer (1 .. Name_Len));
3039 Comp_Args (Comp_Last) :=
3040 new String'(Name_Buffer (1 .. Name_Len));
3044 if Create_Mapping_File and then Mapping_File_Arg /= null then
3045 Comp_Last := Comp_Last + 1;
3046 Comp_Args (Comp_Last) := new String'(Mapping_File_Arg.all);
3049 Get_Name_String (S);
3051 Comp_Last := Comp_Last + 1;
3052 Comp_Args (Comp_Last) := new String'(Name_Buffer (1 .. Name_Len));
3054 -- Change to object directory of the project file, if necessary
3056 if Project /= No_Project then
3057 Change_To_Object_Directory (Project);
3060 GNAT.OS_Lib.Normalize_Arguments (Comp_Args (Args'First .. Comp_Last));
3062 Comp_Last := Comp_Last + 1;
3063 Comp_Args (Comp_Last) := new String'("-gnatez");
3065 Display (Gcc.all, Comp_Args (Args'First .. Comp_Last));
3067 if Gcc_Path = null then
3068 Make_Failed ("error, unable to locate " & Gcc.all);
3072 GNAT.OS_Lib.Non_Blocking_Spawn
3073 (Gcc_Path.all, Comp_Args (Args'First .. Comp_Last));
3076 -------------------------------
3077 -- Fill_Queue_From_ALI_Files --
3078 -------------------------------
3080 procedure Fill_Queue_From_ALI_Files is
3081 ALI_P : ALI_Project;
3084 Sfile : File_Name_Type;
3085 Uname : Unit_Name_Type;
3086 Unit_Name : Name_Id;
3087 Uid : Prj.Unit_Index;
3090 while Good_ALI_Present loop
3091 ALI_P := Get_Next_Good_ALI;
3093 Source_Index := Unit_Index_Of (ALIs.Table (ALI_P.ALI).Afile);
3095 -- If we are processing the library file corresponding to the
3096 -- main source file check if this source can be a main unit.
3098 if ALIs.Table (ALI).Sfile = Main_Source
3099 and then Source_Index = Main_Index
3101 Main_Unit := ALIs.Table (ALI).Main_Program /= None;
3104 -- The following adds the standard library (s-stalib) to the list
3105 -- of files to be handled by gnatmake: this file and any files it
3106 -- depends on are always included in every bind, even if they are
3107 -- not in the explicit dependency list. Of course, it is not added
3108 -- if Suppress_Standard_Library is True.
3110 -- However, to avoid annoying output about s-stalib.ali being read
3111 -- only, when "-v" is used, we add the standard library only when
3114 if Need_To_Check_Standard_Library then
3115 Check_Standard_Library;
3118 -- Now insert in the Q the unmarked source files (i.e. those which
3119 -- have never been inserted in the Q and hence never considered).
3120 -- Only do that if Unique_Compile is False.
3122 if not Unique_Compile then
3124 ALIs.Table (ALI).First_Unit .. ALIs.Table (ALI).Last_Unit
3127 Units.Table (J).First_With .. Units.Table (J).Last_With
3129 Sfile := Withs.Table (K).Sfile;
3130 Uname := Withs.Table (K).Uname;
3132 -- If project files are used, find the proper source to
3133 -- compile in case Sfile is the spec but there is a body.
3135 if Main_Project /= No_Project then
3136 Get_Name_String (Uname);
3137 Name_Len := Name_Len - 2;
3138 Unit_Name := Name_Find;
3140 Units_Htable.Get (Project_Tree.Units_HT, Unit_Name);
3142 if Uid /= Prj.No_Unit_Index then
3143 if Uid.File_Names (Impl) /= null
3144 and then not Uid.File_Names (Impl).Locally_Removed
3146 Sfile := Uid.File_Names (Impl).File;
3147 Source_Index := Uid.File_Names (Impl).Index;
3149 elsif Uid.File_Names (Spec) /= null
3150 and then not Uid.File_Names (Spec).Locally_Removed
3152 Sfile := Uid.File_Names (Spec).File;
3153 Source_Index := Uid.File_Names (Spec).Index;
3158 Dependencies.Append ((ALIs.Table (ALI).Sfile, Sfile));
3160 if Is_In_Obsoleted (Sfile) then
3161 Executable_Obsolete := True;
3164 if Sfile = No_File then
3165 Debug_Msg ("Skipping generic:", Withs.Table (K).Uname);
3168 Source_Index := Unit_Index_Of (Withs.Table (K).Afile);
3170 if Is_Marked (Sfile, Source_Index) then
3171 Debug_Msg ("Skipping marked file:", Sfile);
3173 elsif not (Check_Readonly_Files or Must_Compile)
3174 and then Is_Internal_File_Name (Sfile, False)
3176 Debug_Msg ("Skipping internal file:", Sfile);
3182 Withs.Table (K).Uname,
3184 Mark (Sfile, Source_Index);
3191 end Fill_Queue_From_ALI_Files;
3193 ----------------------
3194 -- Get_Mapping_File --
3195 ----------------------
3197 procedure Get_Mapping_File (Project : Project_Id) is
3198 Data : Project_Compilation_Access;
3201 Data := Project_Compilation_Htable.Get (Project_Compilation, Project);
3203 -- If there is a mapping file ready to be reused, reuse it
3205 if Data.Last_Free_Indexes > 0 then
3206 Mfile := Data.Free_Mapping_File_Indexes (Data.Last_Free_Indexes);
3207 Data.Last_Free_Indexes := Data.Last_Free_Indexes - 1;
3209 -- Otherwise, create and initialize a new one
3213 (Project => Project, Data => Data.all, File_Index => Mfile);
3216 -- Put the name in the mapping file argument for the invocation
3219 Free (Mapping_File_Arg);
3221 new String'("-gnatem=" &
3222 Get_Name_String (Data.Mapping_File_Names (Mfile)));
3223 end Get_Mapping_File;
3225 -----------------------
3226 -- Get_Next_Good_ALI --
3227 -----------------------
3229 function Get_Next_Good_ALI return ALI_Project is
3233 pragma Assert (Good_ALI_Present);
3234 ALIP := Good_ALI.Table (Good_ALI.Last);
3235 Good_ALI.Decrement_Last;
3237 end Get_Next_Good_ALI;
3239 ----------------------
3240 -- Good_ALI_Present --
3241 ----------------------
3243 function Good_ALI_Present return Boolean is
3245 return Good_ALI.First <= Good_ALI.Last;
3246 end Good_ALI_Present;
3248 --------------------------------
3249 -- Must_Exit_Because_Of_Error --
3250 --------------------------------
3252 function Must_Exit_Because_Of_Error return Boolean is
3253 Data : Compilation_Data;
3257 if Bad_Compilation_Count > 0 and then not Keep_Going then
3258 while Outstanding_Compiles > 0 loop
3259 Await_Compile (Data, Success);
3262 Record_Failure (Data.Full_Source_File, Data.Source_Unit);
3270 end Must_Exit_Because_Of_Error;
3272 --------------------
3273 -- Record_Failure --
3274 --------------------
3276 procedure Record_Failure
3277 (File : File_Name_Type;
3278 Unit : Unit_Name_Type;
3279 Found : Boolean := True)
3282 Bad_Compilation.Increment_Last;
3283 Bad_Compilation.Table (Bad_Compilation.Last) := (File, Unit, Found);
3286 ---------------------
3287 -- Record_Good_ALI --
3288 ---------------------
3290 procedure Record_Good_ALI (A : ALI_Id; Project : Project_Id) is
3292 Good_ALI.Increment_Last;
3293 Good_ALI.Table (Good_ALI.Last) := (A, Project);
3294 end Record_Good_ALI;
3296 -------------------------------
3297 -- Start_Compile_If_Possible --
3298 -------------------------------
3300 function Start_Compile_If_Possible
3301 (Args : Argument_List) return Boolean
3303 In_Lib_Dir : Boolean;
3304 Need_To_Compile : Boolean;
3306 Process_Created : Boolean;
3308 Source_File : File_Name_Type;
3309 Full_Source_File : File_Name_Type;
3310 Source_File_Attr : aliased File_Attributes;
3311 -- The full name of the source file and its attributes (size, ...)
3313 Source_Unit : Unit_Name_Type;
3315 -- Index of the current unit in the current source file
3317 Lib_File : File_Name_Type;
3318 Full_Lib_File : File_Name_Type;
3319 Lib_File_Attr : aliased File_Attributes;
3320 Read_Only : Boolean := False;
3322 -- The ALI file and its attributes (size, stamp, ...)
3324 Obj_File : File_Name_Type;
3325 Obj_Stamp : Time_Stamp_Type;
3329 if not Queue.Is_Virtually_Empty and then
3330 Outstanding_Compiles < Max_Process
3332 Queue.Extract (Source_File, Source_Unit, Source_Index);
3334 Osint.Full_Source_Name
3336 Full_File => Full_Source_File,
3337 Attr => Source_File_Attr'Access);
3339 Lib_File := Osint.Lib_File_Name (Source_File, Source_Index);
3341 -- ??? This call could be avoided when using projects, since we
3342 -- know where the ALI file is supposed to be. That would avoid
3343 -- searches in the object directories, including in the runtime
3344 -- dir. However, that would require getting access to the
3347 Osint.Full_Lib_File_Name
3349 Lib_File => Full_Lib_File,
3350 Attr => Lib_File_Attr);
3352 -- If source has already been compiled, executable is obsolete
3354 if Is_In_Obsoleted (Source_File) then
3355 Executable_Obsolete := True;
3358 In_Lib_Dir := Full_Lib_File /= No_File
3359 and then In_Ada_Lib_Dir (Full_Lib_File);
3361 -- Since the following requires a system call, we precompute it
3364 if not In_Lib_Dir then
3365 if Full_Lib_File /= No_File
3366 and then not (Check_Readonly_Files or else Must_Compile)
3368 Get_Name_String (Full_Lib_File);
3369 Name_Buffer (Name_Len + 1) := ASCII.NUL;
3370 Read_Only := not Is_Writable_File
3371 (Name_Buffer'Address, Lib_File_Attr'Access);
3377 -- If the library file is an Ada library skip it
3382 "is in an Ada library",
3384 Minimum_Verbosity => Opt.High);
3386 -- If the library file is a read-only library skip it, but only
3387 -- if, when using project files, this library file is in the
3388 -- right object directory (a read-only ALI file in the object
3389 -- directory of a project being extended must not be skipped).
3392 and then Is_In_Object_Directory (Source_File, Full_Lib_File)
3396 "is a read-only library",
3398 Minimum_Verbosity => Opt.High);
3400 -- The source file that we are checking cannot be located
3402 elsif Full_Source_File = No_File then
3403 Record_Failure (Source_File, Source_Unit, False);
3405 -- Source and library files can be located but are internal
3408 elsif not (Check_Readonly_Files or else Must_Compile)
3409 and then Full_Lib_File /= No_File
3410 and then Is_Internal_File_Name (Source_File, False)
3412 if Force_Compilations then
3414 ("not allowed to compile """ &
3415 Get_Name_String (Source_File) &
3416 """; use -a switch, or compile file with " &
3417 """-gnatg"" switch");
3422 "is an internal library",
3424 Minimum_Verbosity => Opt.High);
3426 -- The source file that we are checking can be located
3429 Collect_Arguments (Source_File, Source_Index,
3430 Source_File = Main_Source, Args);
3432 -- Do nothing if project of source is externally built
3434 if Arguments_Project = No_Project
3435 or else not Arguments_Project.Externally_Built
3436 or else Must_Compile
3438 -- Don't waste any time if we have to recompile anyway
3440 Obj_Stamp := Empty_Time_Stamp;
3441 Need_To_Compile := Force_Compilations;
3443 if not Force_Compilations then
3444 Check (Source_File => Source_File,
3445 Source_Index => Source_Index,
3446 Is_Main_Source => Source_File = Main_Source,
3448 Lib_File => Lib_File,
3449 Full_Lib_File => Full_Lib_File,
3450 Lib_File_Attr => Lib_File_Attr'Access,
3451 Read_Only => Read_Only,
3454 O_Stamp => Obj_Stamp);
3455 Need_To_Compile := (ALI = No_ALI_Id);
3458 if not Need_To_Compile then
3460 -- The ALI file is up-to-date; record its Id
3462 Record_Good_ALI (ALI, Arguments_Project);
3464 -- Record the time stamp of the most recent object
3465 -- file as long as no (re)compilations are needed.
3467 if First_Compiled_File = No_File
3468 and then (Most_Recent_Obj_File = No_File
3469 or else Obj_Stamp > Most_Recent_Obj_Stamp)
3471 Most_Recent_Obj_File := Obj_File;
3472 Most_Recent_Obj_Stamp := Obj_Stamp;
3476 -- Check that switch -x has been used if a source outside
3477 -- of project files need to be compiled.
3479 if Main_Project /= No_Project
3480 and then Arguments_Project = No_Project
3481 and then not External_Unit_Compilation_Allowed
3483 Make_Failed ("external source ("
3484 & Get_Name_String (Source_File)
3485 & ") is not part of any project;"
3486 & " cannot be compiled without"
3487 & " gnatmake switch -x");
3490 -- Is this the first file we have to compile?
3492 if First_Compiled_File = No_File then
3493 First_Compiled_File := Full_Source_File;
3494 Most_Recent_Obj_File := No_File;
3496 if Do_Not_Execute then
3498 -- Exit the main loop
3504 -- Compute where the ALI file must be generated in
3505 -- In_Place_Mode (this does not require to know the
3506 -- location of the object directory).
3508 if In_Place_Mode then
3509 if Full_Lib_File = No_File then
3511 -- If the library file was not found, then save
3512 -- the library file near the source file.
3516 (Full_Source_File, Source_Index);
3517 Full_Lib_File := Lib_File;
3520 -- If the library file was found, then save the
3521 -- library file in the same place.
3523 Lib_File := Full_Lib_File;
3527 -- Start the compilation and record it. We can do this
3528 -- because there is at least one free process. This might
3529 -- change the current directory.
3531 Collect_Arguments_And_Compile
3532 (Full_Source_File => Full_Source_File,
3533 Lib_File => Lib_File,
3534 Source_Index => Source_Index,
3536 Process_Created => Process_Created);
3538 -- Compute where the ALI file will be generated (for
3539 -- cases that might require to know the current
3540 -- directory). The current directory might be changed
3541 -- when compiling other files so we cannot rely on it
3542 -- being the same to find the resulting ALI file.
3544 if not In_Place_Mode then
3546 -- Compute the expected location of the ALI file. This
3547 -- can be from several places:
3548 -- -i => in place mode. In such a case,
3549 -- Full_Lib_File has already been set above
3550 -- -D => if specified
3551 -- or defaults in current dir
3552 -- We could simply use a call similar to
3553 -- Osint.Full_Lib_File_Name (Lib_File)
3554 -- but that involves system calls and is thus slower
3556 if Object_Directory_Path /= null then
3558 Add_Str_To_Name_Buffer (Object_Directory_Path.all);
3559 Add_Str_To_Name_Buffer (Get_Name_String (Lib_File));
3560 Full_Lib_File := Name_Find;
3563 if Project_Of_Current_Object_Directory /=
3567 (Project_Of_Current_Object_Directory
3568 .Object_Directory.Display_Name);
3569 Add_Str_To_Name_Buffer
3570 (Get_Name_String (Lib_File));
3571 Full_Lib_File := Name_Find;
3574 Full_Lib_File := Lib_File;
3580 Lib_File_Attr := Unknown_Attributes;
3582 -- Make sure we could successfully start the compilation
3584 if Process_Created then
3585 if Pid = Invalid_Pid then
3586 Record_Failure (Full_Source_File, Source_Unit);
3590 Sfile => Full_Source_File,
3592 Uname => Source_Unit,
3594 Full_Lib_File => Full_Lib_File,
3595 Lib_File_Attr => Lib_File_Attr);
3603 end Start_Compile_If_Possible;
3605 -----------------------------
3606 -- Wait_For_Available_Slot --
3607 -----------------------------
3609 procedure Wait_For_Available_Slot is
3610 Compilation_OK : Boolean;
3611 Text : Text_Buffer_Ptr;
3613 Data : Compilation_Data;
3616 if Outstanding_Compiles = Max_Process
3617 or else (Queue.Is_Virtually_Empty
3618 and then not Good_ALI_Present
3619 and then Outstanding_Compiles > 0)
3621 Await_Compile (Data, Compilation_OK);
3623 if not Compilation_OK then
3624 Record_Failure (Data.Full_Source_File, Data.Source_Unit);
3627 if Compilation_OK or else Keep_Going then
3629 -- Re-read the updated library file
3632 Saved_Object_Consistency : constant Boolean :=
3633 Check_Object_Consistency;
3636 -- If compilation was not OK, or if output is not an object
3637 -- file and we don't do the bind step, don't check for
3638 -- object consistency.
3640 Check_Object_Consistency :=
3641 Check_Object_Consistency
3643 and (Output_Is_Object or Do_Bind_Step);
3646 Read_Library_Info_From_Full
3647 (Data.Full_Lib_File, Data.Lib_File_Attr'Access);
3649 -- Restore Check_Object_Consistency to its initial value
3651 Check_Object_Consistency := Saved_Object_Consistency;
3654 -- If an ALI file was generated by this compilation, scan the
3655 -- ALI file and record it.
3657 -- If the scan fails, a previous ali file is inconsistent with
3658 -- the unit just compiled.
3660 if Text /= null then
3663 (Data.Lib_File, Text, Ignore_ED => False, Err => True);
3665 if ALI = No_ALI_Id then
3667 -- Record a failure only if not already done
3669 if Compilation_OK then
3672 "incompatible ALI file, please recompile");
3674 (Data.Full_Source_File, Data.Source_Unit);
3678 Record_Good_ALI (ALI, Data.Project);
3683 -- If we could not read the ALI file that was just generated
3684 -- then there could be a problem reading either the ALI or the
3685 -- corresponding object file (if Check_Object_Consistency is
3686 -- set Read_Library_Info checks that the time stamp of the
3687 -- object file is more recent than that of the ALI). However,
3688 -- we record a failure only if not already done.
3691 if Compilation_OK and not Syntax_Only then
3694 "WARNING: ALI or object file not found after compile");
3695 Record_Failure (Data.Full_Source_File, Data.Source_Unit);
3700 end Wait_For_Available_Slot;
3702 -- Start of processing for Compile_Sources
3705 pragma Assert (Args'First = 1);
3707 Outstanding_Compiles := 0;
3708 Running_Compile := new Comp_Data_Arr (1 .. Max_Process);
3710 -- Package and Queue initializations
3714 if Initialize_ALI_Data then
3716 Initialize_ALI_Source;
3719 -- The following two flags affect the behavior of ALI.Set_Source_Table.
3720 -- We set Check_Source_Files to True to ensure that source file time
3721 -- stamps are checked, and we set All_Sources to False to avoid checking
3722 -- the presence of the source files listed in the source dependency
3723 -- section of an ali file (which would be a mistake since the ali file
3724 -- may be obsolete).
3726 Check_Source_Files := True;
3727 All_Sources := False;
3729 -- Only insert in the Q if it is not already done, to avoid simultaneous
3730 -- compilations if -jnnn is used.
3732 if not Is_Marked (Main_Source, Main_Index) then
3733 Queue.Insert (Main_Source, Main_Project, Index => Main_Index);
3734 Mark (Main_Source, Main_Index);
3737 First_Compiled_File := No_File;
3738 Most_Recent_Obj_File := No_File;
3739 Most_Recent_Obj_Stamp := Empty_Time_Stamp;
3742 -- Keep looping until there is no more work to do (the Q is empty)
3743 -- and all the outstanding compilations have terminated.
3746 while not Queue.Is_Empty or else Outstanding_Compiles > 0 loop
3747 exit Make_Loop when Must_Exit_Because_Of_Error;
3748 exit Make_Loop when Start_Compile_If_Possible (Args);
3750 Wait_For_Available_Slot;
3752 -- ??? Should be done as soon as we add a Good_ALI, wouldn't it avoid
3753 -- the need for a list of good ALI?
3755 Fill_Queue_From_ALI_Files;
3757 if Display_Compilation_Progress then
3758 Write_Str ("completed ");
3759 Write_Int (Int (Queue.Processed));
3760 Write_Str (" out of ");
3761 Write_Int (Int (Queue.Size));
3763 Write_Int (Int ((Queue.Processed * 100) / Queue.Size));
3764 Write_Str ("%)...");
3769 Compilation_Failures := Bad_Compilation_Count;
3771 -- Compilation is finished
3773 -- Delete any temporary configuration pragma file
3775 if not Debug.Debug_Flag_N then
3776 Delete_Temp_Config_Files;
3778 end Compile_Sources;
3780 ----------------------------------
3781 -- Configuration_Pragmas_Switch --
3782 ----------------------------------
3784 function Configuration_Pragmas_Switch
3785 (For_Project : Project_Id) return Argument_List
3787 The_Packages : Package_Id;
3788 Gnatmake : Package_Id;
3789 Compiler : Package_Id;
3791 Global_Attribute : Variable_Value := Nil_Variable_Value;
3792 Local_Attribute : Variable_Value := Nil_Variable_Value;
3794 Global_Attribute_Present : Boolean := False;
3795 Local_Attribute_Present : Boolean := False;
3797 Result : Argument_List (1 .. 3);
3798 Last : Natural := 0;
3800 function Absolute_Path
3801 (Path : Path_Name_Type;
3802 Project : Project_Id) return String;
3803 -- Returns an absolute path for a configuration pragmas file
3809 function Absolute_Path
3810 (Path : Path_Name_Type;
3811 Project : Project_Id) return String
3814 Get_Name_String (Path);
3817 Path_Name : constant String := Name_Buffer (1 .. Name_Len);
3820 if Is_Absolute_Path (Path_Name) then
3825 Parent_Directory : constant String :=
3826 Get_Name_String (Project.Directory.Display_Name);
3829 return Parent_Directory & Path_Name;
3835 -- Start of processing for Configuration_Pragmas_Switch
3838 Prj.Env.Create_Config_Pragmas_File
3839 (For_Project, Project_Tree);
3841 if For_Project.Config_File_Name /= No_Path then
3842 Temporary_Config_File := For_Project.Config_File_Temp;
3846 ("-gnatec=" & Get_Name_String (For_Project.Config_File_Name));
3849 Temporary_Config_File := False;
3852 -- Check for attribute Builder'Global_Configuration_Pragmas
3854 The_Packages := Main_Project.Decl.Packages;
3857 (Name => Name_Builder,
3858 In_Packages => The_Packages,
3859 In_Tree => Project_Tree);
3861 if Gnatmake /= No_Package then
3862 Global_Attribute := Prj.Util.Value_Of
3863 (Variable_Name => Name_Global_Configuration_Pragmas,
3864 In_Variables => Project_Tree.Packages.Table
3865 (Gnatmake).Decl.Attributes,
3866 In_Tree => Project_Tree);
3867 Global_Attribute_Present :=
3868 Global_Attribute /= Nil_Variable_Value
3869 and then Get_Name_String (Global_Attribute.Value) /= "";
3871 if Global_Attribute_Present then
3873 Path : constant String :=
3875 (Path_Name_Type (Global_Attribute.Value),
3876 Global_Attribute.Project);
3878 if not Is_Regular_File (Path) then
3879 if Debug.Debug_Flag_F then
3881 ("cannot find configuration pragmas file "
3882 & File_Name (Path));
3885 ("cannot find configuration pragmas file " & Path);
3890 Result (Last) := new String'("-gnatec=" & Path);
3895 -- Check for attribute Compiler'Local_Configuration_Pragmas
3897 The_Packages := For_Project.Decl.Packages;
3900 (Name => Name_Compiler,
3901 In_Packages => The_Packages,
3902 In_Tree => Project_Tree);
3904 if Compiler /= No_Package then
3905 Local_Attribute := Prj.Util.Value_Of
3906 (Variable_Name => Name_Local_Configuration_Pragmas,
3907 In_Variables => Project_Tree.Packages.Table
3908 (Compiler).Decl.Attributes,
3909 In_Tree => Project_Tree);
3910 Local_Attribute_Present :=
3911 Local_Attribute /= Nil_Variable_Value
3912 and then Get_Name_String (Local_Attribute.Value) /= "";
3914 if Local_Attribute_Present then
3916 Path : constant String :=
3918 (Path_Name_Type (Local_Attribute.Value),
3919 Local_Attribute.Project);
3921 if not Is_Regular_File (Path) then
3922 if Debug.Debug_Flag_F then
3924 ("cannot find configuration pragmas file "
3925 & File_Name (Path));
3929 ("cannot find configuration pragmas file " & Path);
3934 Result (Last) := new String'("-gnatec=" & Path);
3939 return Result (1 .. Last);
3940 end Configuration_Pragmas_Switch;
3946 procedure Debug_Msg (S : String; N : Name_Id) is
3948 if Debug.Debug_Flag_W then
3949 Write_Str (" ... ");
3957 procedure Debug_Msg (S : String; N : File_Name_Type) is
3959 Debug_Msg (S, Name_Id (N));
3962 procedure Debug_Msg (S : String; N : Unit_Name_Type) is
3964 Debug_Msg (S, Name_Id (N));
3967 ---------------------------
3968 -- Delete_All_Temp_Files --
3969 ---------------------------
3971 procedure Delete_All_Temp_Files is
3973 if not Debug.Debug_Flag_N then
3974 Delete_Temp_Config_Files;
3975 Prj.Delete_All_Temp_Files (Project_Tree);
3977 end Delete_All_Temp_Files;
3979 ------------------------------
3980 -- Delete_Temp_Config_Files --
3981 ------------------------------
3983 procedure Delete_Temp_Config_Files is
3985 Proj : Project_List;
3986 pragma Warnings (Off, Success);
3989 -- The caller is responsible for ensuring that Debug_Flag_N is False
3991 pragma Assert (not Debug.Debug_Flag_N);
3993 if Main_Project /= No_Project then
3994 Proj := Project_Tree.Projects;
3995 while Proj /= null loop
3996 if Proj.Project.Config_File_Temp then
3997 Delete_Temporary_File
3998 (Project_Tree, Proj.Project.Config_File_Name);
4000 -- Make sure that we don't have a config file for this project,
4001 -- in case there are several mains. In this case, we will
4002 -- recreate another config file: we cannot reuse the one that
4005 Proj.Project.Config_Checked := False;
4006 Proj.Project.Config_File_Name := No_Path;
4007 Proj.Project.Config_File_Temp := False;
4012 end Delete_Temp_Config_Files;
4018 procedure Display (Program : String; Args : Argument_List) is
4020 pragma Assert (Args'First = 1);
4022 if Display_Executed_Programs then
4023 Write_Str (Program);
4025 for J in Args'Range loop
4027 -- Never display -gnatea nor -gnatez
4029 if Args (J).all /= "-gnatea"
4031 Args (J).all /= "-gnatez"
4033 -- Do not display the mapping file argument automatically
4034 -- created when using a project file.
4036 if Main_Project = No_Project
4037 or else Debug.Debug_Flag_N
4038 or else Args (J)'Length < 8
4040 Args (J) (Args (J)'First .. Args (J)'First + 6) /= "-gnatem"
4042 -- When -dn is not specified, do not display the config
4043 -- pragmas switch (-gnatec) for the temporary file created
4044 -- by the project manager (always the first -gnatec switch).
4045 -- Reset Temporary_Config_File to False so that the eventual
4046 -- other -gnatec switches will be displayed.
4048 if (not Debug.Debug_Flag_N)
4049 and then Temporary_Config_File
4050 and then Args (J)'Length > 7
4051 and then Args (J) (Args (J)'First .. Args (J)'First + 6)
4054 Temporary_Config_File := False;
4056 -- Do not display the -F=mapping_file switch for gnatbind
4057 -- if -dn is not specified.
4059 elsif Debug.Debug_Flag_N
4060 or else Args (J)'Length < 4
4062 Args (J) (Args (J)'First .. Args (J)'First + 2) /= "-F="
4066 -- If -df is used, only display file names, not path
4069 if Debug.Debug_Flag_F then
4071 Equal_Pos : Natural;
4073 Equal_Pos := Args (J)'First - 1;
4074 for K in Args (J)'Range loop
4075 if Args (J) (K) = '=' then
4082 (Args (J) (Equal_Pos + 1 .. Args (J)'Last))
4085 (Args (J) (Args (J)'First .. Equal_Pos));
4089 (Equal_Pos + 1 .. Args (J)'Last)));
4092 Write_Str (Args (J).all);
4097 Write_Str (Args (J).all);
4108 ----------------------
4109 -- Display_Commands --
4110 ----------------------
4112 procedure Display_Commands (Display : Boolean := True) is
4114 Display_Executed_Programs := Display;
4115 end Display_Commands;
4117 --------------------------
4118 -- Enter_Into_Obsoleted --
4119 --------------------------
4121 procedure Enter_Into_Obsoleted (F : File_Name_Type) is
4122 Name : constant String := Get_Name_String (F);
4124 F2 : File_Name_Type;
4128 while First > Name'First
4129 and then Name (First - 1) /= Directory_Separator
4130 and then Name (First - 1) /= '/'
4135 if First /= Name'First then
4137 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
4144 Debug_Msg ("New entry in Obsoleted table:", F2);
4145 Obsoleted.Set (F2, True);
4146 end Enter_Into_Obsoleted;
4152 procedure Globalize (Success : out Boolean) is
4153 Quiet_Str : aliased String := "-quiet";
4154 Globalizer_Args : constant Argument_List :=
4155 (1 => Quiet_Str'Unchecked_Access);
4156 Previous_Dir : String_Access;
4158 procedure Globalize_Dir (Dir : String);
4159 -- Call CodePeer globalizer on Dir
4165 procedure Globalize_Dir (Dir : String) is
4168 if Previous_Dir = null or else Dir /= Previous_Dir.all then
4169 Free (Previous_Dir);
4170 Previous_Dir := new String'(Dir);
4172 GNAT.OS_Lib.Spawn (Globalizer_Path.all, Globalizer_Args, Result);
4173 Success := Success and Result;
4177 procedure Globalize_Dirs is new
4178 Prj.Env.For_All_Object_Dirs (Globalize_Dir);
4182 Display (Globalizer, Globalizer_Args);
4184 if Globalizer_Path = null then
4185 Make_Failed ("error, unable to locate " & Globalizer);
4188 if Main_Project = No_Project then
4189 GNAT.OS_Lib.Spawn (Globalizer_Path.all, Globalizer_Args, Success);
4191 Globalize_Dirs (Main_Project);
4199 procedure Gnatmake is
4200 Main_Source_File : File_Name_Type;
4201 -- The source file containing the main compilation unit
4203 Compilation_Failures : Natural;
4205 Total_Compilation_Failures : Natural := 0;
4207 Is_Main_Unit : Boolean;
4208 -- Set True by Compile_Sources if Main_Source_File can be a main unit
4210 Main_ALI_File : File_Name_Type;
4211 -- The ali file corresponding to Main_Source_File
4213 Executable : File_Name_Type := No_File;
4214 -- The file name of an executable
4216 Non_Std_Executable : Boolean := False;
4217 -- Non_Std_Executable is set to True when there is a possibility that
4218 -- the linker will not choose the correct executable file name.
4220 Current_Work_Dir : constant String_Access :=
4221 new String'(Get_Current_Dir);
4222 -- The current working directory, used to modify some relative path
4223 -- switches on the command line when a project file is used.
4225 Current_Main_Index : Int := 0;
4226 -- If not zero, the index of the current main unit in its source file
4228 Stand_Alone_Libraries : Boolean := False;
4229 -- Set to True when there are Stand-Alone Libraries, so that gnatbind
4230 -- is invoked with the -F switch to force checking of elaboration flags.
4232 Mapping_Path : Path_Name_Type := No_Path;
4233 -- The path name of the mapping file
4235 Project_Node_Tree : Project_Node_Tree_Ref;
4238 pragma Warnings (Off, Discard);
4240 procedure Check_Mains;
4241 -- Check that the main subprograms do exist and that they all
4242 -- belong to the same project file.
4248 procedure Check_Mains is
4249 Real_Main_Project : Project_Id := No_Project;
4250 -- The project of the first main
4252 Proj : Project_Id := No_Project;
4253 -- The project of the current main
4255 Real_Path : String_Access;
4264 Main : constant String := Mains.Next_Main;
4265 -- The name specified on the command line may include directory
4268 File_Name : constant String := Base_Name (Main);
4269 -- The simple file name of the current main
4271 Lang : Language_Ptr;
4274 exit when Main = "";
4276 -- Get the project of the current main
4278 Proj := Prj.Env.Project_Of
4279 (File_Name, Main_Project, Project_Tree);
4281 -- Fail if the current main is not a source of a project
4283 if Proj = No_Project then
4285 ("""" & Main & """ is not a source of any project");
4288 -- If there is directory information, check that the source
4289 -- exists and, if it does, that the path is the actual path
4290 -- of a source of a project.
4292 if Main /= File_Name then
4293 Lang := Get_Language_From_Name (Main_Project, "ada");
4297 (Main & Get_Name_String
4298 (Lang.Config.Naming_Data.Body_Suffix),
4300 if Real_Path = null then
4303 (Main & Get_Name_String
4304 (Lang.Config.Naming_Data.Spec_Suffix),
4308 if Real_Path = null then
4309 Real_Path := Locate_Regular_File (Main, "");
4312 -- Fail if the file cannot be found
4314 if Real_Path = null then
4315 Make_Failed ("file """ & Main & """ does not exist");
4319 Project_Path : constant String :=
4320 Prj.Env.File_Name_Of_Library_Unit_Body
4322 Project => Main_Project,
4323 In_Tree => Project_Tree,
4324 Main_Project_Only => False,
4326 Normed_Path : constant String :=
4329 Case_Sensitive => False);
4330 Proj_Path : constant String :=
4333 Case_Sensitive => False);
4338 -- Fail if it is not the correct path
4340 if Normed_Path /= Proj_Path then
4341 if Verbose_Mode then
4343 Write_Str (Normed_Path);
4345 Write_Line (Proj_Path);
4350 """ is not a source of any project");
4355 if not Unique_Compile then
4357 -- Record the project, if it is the first main
4359 if Real_Main_Project = No_Project then
4360 Real_Main_Project := Proj;
4362 elsif Proj /= Real_Main_Project then
4364 -- Fail, as the current main is not a source of the
4365 -- same project as the first main.
4369 """ is not a source of project " &
4370 Get_Name_String (Real_Main_Project.Name));
4375 -- If -u and -U are not used, we may have mains that are
4376 -- sources of a project that is not the one specified with
4379 if not Unique_Compile then
4380 Main_Project := Real_Main_Project;
4386 -- Start of processing for Gnatmake
4388 -- This body is very long, should be broken down???
4391 Install_Int_Handler (Sigint_Intercepted'Access);
4393 Do_Compile_Step := True;
4394 Do_Bind_Step := True;
4395 Do_Link_Step := True;
4399 Make.Initialize (Project_Node_Tree);
4401 Bind_Shared := No_Shared_Switch'Access;
4402 Link_With_Shared_Libgcc := No_Shared_Libgcc_Switch'Access;
4404 Failed_Links.Set_Last (0);
4405 Successful_Links.Set_Last (0);
4407 -- Special case when switch -B was specified
4409 if Build_Bind_And_Link_Full_Project then
4411 -- When switch -B is specified, there must be a project file
4413 if Main_Project = No_Project then
4414 Make_Failed ("-B cannot be used without a project file");
4416 -- No main program may be specified on the command line
4418 elsif Osint.Number_Of_Files /= 0 then
4419 Make_Failed ("-B cannot be used with a main specified on " &
4420 "the command line");
4422 -- And the project file cannot be a library project file
4424 elsif Main_Project.Library then
4425 Make_Failed ("-B cannot be used for a library project file");
4428 No_Main_Subprogram := True;
4429 Insert_Project_Sources
4430 (The_Project => Main_Project,
4431 All_Projects => Unique_Compile_All_Projects,
4434 -- If there are no sources to compile, we fail
4436 if Osint.Number_Of_Files = 0 then
4437 Make_Failed ("no sources to compile");
4440 -- Specify -n for gnatbind and add the ALI files of all the
4441 -- sources, except the one which is a fake main subprogram: this
4442 -- is the one for the binder generated file and it will be
4443 -- transmitted to gnatlink. These sources are those that are in
4446 Add_Switch ("-n", Binder, And_Save => True);
4448 for J in 1 .. Queue.Size loop
4451 (Lib_File_Name (Queue.Element (J))),
4452 Binder, And_Save => True);
4456 elsif Main_Index /= 0 and then Osint.Number_Of_Files > 1 then
4457 Make_Failed ("cannot specify several mains with a multi-unit index");
4459 elsif Main_Project /= No_Project then
4461 -- If the main project file is a library project file, main(s) cannot
4462 -- be specified on the command line.
4464 if Osint.Number_Of_Files /= 0 then
4465 if Main_Project.Library
4466 and then not Unique_Compile
4467 and then ((not Make_Steps) or else Bind_Only or else Link_Only)
4469 Make_Failed ("cannot specify a main program " &
4470 "on the command line for a library project file");
4473 -- Check that each main on the command line is a source of a
4474 -- project file and, if there are several mains, each of them
4475 -- is a source of the same project file.
4480 -- If no mains have been specified on the command line, and we are
4481 -- using a project file, we either find the main(s) in attribute Main
4482 -- of the main project, or we put all the sources of the project file
4486 if Main_Index /= 0 then
4487 Make_Failed ("cannot specify a multi-unit index but no main " &
4488 "on the command line");
4492 Value : String_List_Id := Main_Project.Mains;
4495 -- The attribute Main is an empty list or not specified, or
4496 -- else gnatmake was invoked with the switch "-u".
4498 if Value = Prj.Nil_String or else Unique_Compile then
4500 if (not Make_Steps) or else Compile_Only
4501 or else not Main_Project.Library
4503 -- First make sure that the binder and the linker will
4506 Do_Bind_Step := False;
4507 Do_Link_Step := False;
4509 -- Put all the sources in the queue
4511 No_Main_Subprogram := True;
4512 Insert_Project_Sources
4513 (The_Project => Main_Project,
4514 All_Projects => Unique_Compile_All_Projects,
4517 -- If no sources to compile, then there is nothing to do
4519 if Osint.Number_Of_Files = 0 then
4520 if not Quiet_Output then
4521 Osint.Write_Program_Name;
4522 Write_Line (": no sources to compile");
4525 Delete_All_Temp_Files;
4526 Exit_Program (E_Success);
4531 -- The attribute Main is not an empty list. Put all the main
4532 -- subprograms in the list as if they were specified on the
4533 -- command line. However, if attribute Languages includes a
4534 -- language other than Ada, only include the Ada mains; if
4535 -- there is no Ada main, compile all sources of the project.
4538 Languages : constant Variable_Value :=
4541 Main_Project.Decl.Attributes,
4544 Current : String_List_Id;
4545 Element : String_Element;
4547 Foreign_Language : Boolean := False;
4548 At_Least_One_Main : Boolean := False;
4551 -- First, determine if there is a foreign language in
4552 -- attribute Languages.
4554 if not Languages.Default then
4555 Current := Languages.Values;
4557 while Current /= Nil_String loop
4558 Element := Project_Tree.String_Elements.
4560 Get_Name_String (Element.Value);
4561 To_Lower (Name_Buffer (1 .. Name_Len));
4563 if Name_Buffer (1 .. Name_Len) /= "ada" then
4564 Foreign_Language := True;
4565 exit Look_For_Foreign;
4568 Current := Element.Next;
4569 end loop Look_For_Foreign;
4572 -- Then, find all mains, or if there is a foreign
4573 -- language, all the Ada mains.
4575 while Value /= Prj.Nil_String loop
4576 -- To know if a main is an Ada main, get its project.
4577 -- It should be the project specified on the command
4581 (Project_Tree.String_Elements.Table (Value).Value);
4584 Main_Name : constant String :=
4586 (Project_Tree.String_Elements.Table
4588 Proj : constant Project_Id :=
4590 (Main_Name, Main_Project, Project_Tree);
4593 if Proj = Main_Project then
4595 At_Least_One_Main := True;
4598 (Project_Tree.String_Elements.Table
4601 Project_Tree.String_Elements.Table
4604 elsif not Foreign_Language then
4607 """ is not a source of project " &
4608 Get_Name_String (Main_Project.Display_Name));
4612 Value := Project_Tree.String_Elements.Table
4616 -- If we did not get any main, it means that all mains
4617 -- in attribute Mains are in a foreign language and -B
4618 -- was not specified to gnatmake; so, we fail.
4620 if not At_Least_One_Main then
4622 ("no Ada mains, use -B to build foreign main");
4631 if Verbose_Mode then
4633 Display_Version ("GNATMAKE", "1995");
4636 if Osint.Number_Of_Files = 0 then
4637 if Main_Project /= No_Project
4638 and then Main_Project.Library
4641 and then not Main_Project.Standalone_Library
4643 Make_Failed ("only stand-alone libraries may be bound");
4646 -- Add the default search directories to be able to find libgnat
4648 Osint.Add_Default_Search_Dirs;
4650 -- Get the target parameters, so that the correct binder generated
4651 -- files are generated if OpenVMS is the target.
4654 Targparm.Get_Target_Parameters;
4657 when Unrecoverable_Error =>
4658 Make_Failed ("*** make failed.");
4661 -- And bind and or link the library
4663 MLib.Prj.Build_Library
4664 (For_Project => Main_Project,
4665 In_Tree => Project_Tree,
4666 Gnatbind => Gnatbind.all,
4667 Gnatbind_Path => Gnatbind_Path,
4669 Gcc_Path => Gcc_Path,
4673 Delete_All_Temp_Files;
4674 Exit_Program (E_Success);
4677 -- Call Get_Target_Parameters to ensure that VM_Target and
4678 -- AAMP_On_Target get set before calling Usage.
4680 Targparm.Get_Target_Parameters;
4682 -- Output usage information if no files to compile
4685 Exit_Program (E_Fatal);
4689 -- If -M was specified, behave as if -n was specified
4691 if List_Dependencies then
4692 Do_Not_Execute := True;
4695 -- Note that Osint.M.Next_Main_Source will always return the (possibly
4696 -- abbreviated file) without any directory information.
4698 Main_Source_File := Next_Main_Source;
4700 if Current_File_Index /= No_Index then
4701 Main_Index := Current_File_Index;
4704 Add_Switch ("-I-", Compiler, And_Save => True);
4706 if Main_Project = No_Project then
4707 if Look_In_Primary_Dir then
4711 Normalize_Directory_Name
4712 (Get_Primary_Src_Search_Directory.all).all,
4713 Compiler, Append_Switch => False,
4719 -- If we use a project file, we have already checked that a main
4720 -- specified on the command line with directory information has the
4721 -- path name corresponding to a correct source in the project tree.
4722 -- So, we don't need the directory information to be taken into
4723 -- account by Find_File, and in fact it may lead to take the wrong
4724 -- sources for other compilation units, when there are extending
4727 Look_In_Primary_Dir := False;
4728 Add_Switch ("-I-", Binder, And_Save => True);
4731 -- If the user wants a program without a main subprogram, add the
4732 -- appropriate switch to the binder.
4734 if No_Main_Subprogram then
4735 Add_Switch ("-z", Binder, And_Save => True);
4738 if Main_Project /= No_Project then
4740 if Main_Project.Object_Directory /= No_Path_Information then
4741 -- Change current directory to object directory of main project
4743 Project_Of_Current_Object_Directory := No_Project;
4744 Change_To_Object_Directory (Main_Project);
4747 -- Source file lookups should be cached for efficiency.
4748 -- Source files are not supposed to change.
4750 Osint.Source_File_Data (Cache => True);
4752 -- Find the file name of the (first) main unit
4755 Main_Source_File_Name : constant String :=
4756 Get_Name_String (Main_Source_File);
4757 Main_Unit_File_Name : constant String :=
4758 Prj.Env.File_Name_Of_Library_Unit_Body
4759 (Name => Main_Source_File_Name,
4760 Project => Main_Project,
4761 In_Tree => Project_Tree,
4762 Main_Project_Only =>
4763 not Unique_Compile);
4765 The_Packages : constant Package_Id :=
4766 Main_Project.Decl.Packages;
4768 Builder_Package : constant Prj.Package_Id :=
4770 (Name => Name_Builder,
4771 In_Packages => The_Packages,
4772 In_Tree => Project_Tree);
4774 Binder_Package : constant Prj.Package_Id :=
4776 (Name => Name_Binder,
4777 In_Packages => The_Packages,
4778 In_Tree => Project_Tree);
4780 Linker_Package : constant Prj.Package_Id :=
4782 (Name => Name_Linker,
4783 In_Packages => The_Packages,
4784 In_Tree => Project_Tree);
4786 Default_Switches_Array : Array_Id;
4788 Global_Compilation_Array : Array_Element_Id;
4789 Global_Compilation_Elem : Array_Element;
4790 Global_Compilation_Switches : Variable_Value;
4793 -- We fail if we cannot find the main source file
4795 if Main_Unit_File_Name = "" then
4796 Make_Failed ('"' & Main_Source_File_Name
4797 & """ is not a unit of project "
4798 & Project_File_Name.all & ".");
4800 -- Remove any directory information from the main source file
4804 Pos : Natural := Main_Unit_File_Name'Last;
4808 exit when Pos < Main_Unit_File_Name'First or else
4809 Main_Unit_File_Name (Pos) = Directory_Separator;
4813 Name_Len := Main_Unit_File_Name'Last - Pos;
4815 Name_Buffer (1 .. Name_Len) :=
4817 (Pos + 1 .. Main_Unit_File_Name'Last);
4819 Main_Source_File := Name_Find;
4821 -- We only output the main source file if there is only one
4823 if Verbose_Mode and then Osint.Number_Of_Files = 1 then
4824 Write_Str ("Main source file: """);
4825 Write_Str (Main_Unit_File_Name
4826 (Pos + 1 .. Main_Unit_File_Name'Last));
4832 -- If there is a package Builder in the main project file, add
4833 -- the switches from it.
4835 if Builder_Package /= No_Package then
4837 Global_Compilation_Array := Prj.Util.Value_Of
4838 (Name => Name_Global_Compilation_Switches,
4839 In_Arrays => Project_Tree.Packages.Table
4840 (Builder_Package).Decl.Arrays,
4841 In_Tree => Project_Tree);
4843 Default_Switches_Array :=
4844 Project_Tree.Packages.Table
4845 (Builder_Package).Decl.Arrays;
4847 while Default_Switches_Array /= No_Array and then
4848 Project_Tree.Arrays.Table (Default_Switches_Array).Name /=
4849 Name_Default_Switches
4851 Default_Switches_Array :=
4852 Project_Tree.Arrays.Table (Default_Switches_Array).Next;
4855 if Global_Compilation_Array /= No_Array_Element and then
4856 Default_Switches_Array /= No_Array
4859 ("Default_Switches forbidden in presence of " &
4860 "Global_Compilation_Switches. Use Switches instead.",
4861 Project_Tree.Arrays.Table
4862 (Default_Switches_Array).Location);
4865 ("*** illegal combination of Builder attributes");
4868 -- If there is only one main, we attempt to get the gnatmake
4869 -- switches for this main (if any). If there are no specific
4870 -- switch for this particular main, get the general gnatmake
4871 -- switches (if any).
4873 if Osint.Number_Of_Files = 1 then
4874 if Verbose_Mode then
4875 Write_Str ("Adding gnatmake switches for """);
4876 Write_Str (Main_Unit_File_Name);
4881 (Project_Node_Tree => Project_Node_Tree,
4882 File_Name => Main_Unit_File_Name,
4883 Index => Main_Index,
4884 The_Package => Builder_Package,
4886 Unknown_Switches_To_The_Compiler =>
4887 Global_Compilation_Array = No_Array_Element);
4890 -- If there are several mains, we always get the general
4891 -- gnatmake switches (if any).
4893 -- Warn the user, if necessary, so that he is not surprised
4894 -- that specific switches are not taken into account.
4897 Defaults : constant Variable_Value :=
4901 Attribute_Or_Array_Name =>
4902 Name_Default_Switches,
4905 In_Tree => Project_Tree);
4907 Switches : constant Array_Element_Id :=
4909 (Name => Name_Switches,
4911 Project_Tree.Packages.Table
4912 (Builder_Package).Decl.Arrays,
4913 In_Tree => Project_Tree);
4915 Other_Switches : constant Variable_Value :=
4917 (Name => All_Other_Names,
4919 Attribute_Or_Array_Name
4921 In_Package => Builder_Package,
4922 In_Tree => Project_Tree);
4925 if Other_Switches /= Nil_Variable_Value then
4927 and then Switches /= No_Array_Element
4928 and then Project_Tree.Array_Elements.Table
4929 (Switches).Next /= No_Array_Element
4932 ("Warning: using Builder'Switches(others), "
4933 & "as there are several mains");
4937 (Project_Node_Tree => Project_Node_Tree,
4940 The_Package => Builder_Package,
4942 Unknown_Switches_To_The_Compiler => False);
4944 elsif Defaults /= Nil_Variable_Value then
4946 and then Switches /= No_Array_Element
4949 ("Warning: using Builder'Default_Switches"
4950 & "(""Ada""), as there are several mains");
4954 (Project_Node_Tree => Project_Node_Tree,
4957 The_Package => Builder_Package,
4960 elsif not Quiet_Output
4961 and then Switches /= No_Array_Element
4964 ("Warning: using no switches from package "
4965 & "Builder, as there are several mains");
4970 -- Take into account attribute Global_Compilation_Switches
4975 List : String_List_Id;
4976 Elem : String_Element;
4979 while Global_Compilation_Array /= No_Array_Element loop
4980 Global_Compilation_Elem :=
4981 Project_Tree.Array_Elements.Table
4982 (Global_Compilation_Array);
4984 Get_Name_String (Global_Compilation_Elem.Index);
4985 To_Lower (Name_Buffer (1 .. Name_Len));
4988 if Index = Name_Ada then
4989 Global_Compilation_Switches :=
4990 Global_Compilation_Elem.Value;
4992 if Global_Compilation_Switches /= Nil_Variable_Value
4993 and then not Global_Compilation_Switches.Default
4995 -- We have found attribute
4996 -- Global_Compilation_Switches ("Ada"): put the
4997 -- switches in the appropriate table.
4999 List := Global_Compilation_Switches.Values;
5001 while List /= Nil_String loop
5003 Project_Tree.String_Elements.Table (List);
5005 if Elem.Value /= No_Name then
5007 (Get_Name_String (Elem.Value),
5019 Global_Compilation_Array := Global_Compilation_Elem.Next;
5024 Osint.Add_Default_Search_Dirs;
5026 -- Record the current last switch index for table Binder_Switches
5027 -- and Linker_Switches, so that these tables may be reset before
5028 -- for each main, before adding switches from the project file
5029 -- and from the command line.
5031 Last_Binder_Switch := Binder_Switches.Last;
5032 Last_Linker_Switch := Linker_Switches.Last;
5036 -- Add binder switches from the project file for the first main
5038 if Do_Bind_Step and then Binder_Package /= No_Package then
5039 if Verbose_Mode then
5040 Write_Str ("Adding binder switches for """);
5041 Write_Str (Main_Unit_File_Name);
5046 (Project_Node_Tree => Project_Node_Tree,
5047 File_Name => Main_Unit_File_Name,
5048 Index => Main_Index,
5049 The_Package => Binder_Package,
5053 -- Add linker switches from the project file for the first main
5055 if Do_Link_Step and then Linker_Package /= No_Package then
5056 if Verbose_Mode then
5057 Write_Str ("Adding linker switches for""");
5058 Write_Str (Main_Unit_File_Name);
5063 (Project_Node_Tree => Project_Node_Tree,
5064 File_Name => Main_Unit_File_Name,
5065 Index => Main_Index,
5066 The_Package => Linker_Package,
5072 -- The combination of -f -u and one or several mains on the command line
5075 if Force_Compilations
5076 and then Unique_Compile
5077 and then not Unique_Compile_All_Projects
5078 and then Main_On_Command_Line
5080 Must_Compile := True;
5083 if Main_Project /= No_Project
5084 and then not Must_Compile
5085 and then Main_Project.Externally_Built
5088 ("nothing to do for a main project that is externally built");
5091 -- Get the target parameters, which are only needed for a couple of
5092 -- cases in gnatmake. Protect against an exception, such as the case of
5093 -- system.ads missing from the library, and fail gracefully.
5096 Targparm.Get_Target_Parameters;
5098 when Unrecoverable_Error =>
5099 Make_Failed ("*** make failed.");
5102 -- Special processing for VM targets
5104 if Targparm.VM_Target /= No_VM then
5106 -- Set proper processing commands
5108 case Targparm.VM_Target is
5109 when Targparm.JVM_Target =>
5111 -- Do not check for an object file (".o") when compiling to
5112 -- JVM machine since ".class" files are generated instead.
5114 Check_Object_Consistency := False;
5115 Gcc := new String'("jvm-gnatcompile");
5117 when Targparm.CLI_Target =>
5118 Gcc := new String'("dotnet-gnatcompile");
5120 when Targparm.No_VM =>
5121 raise Program_Error;
5125 Display_Commands (not Quiet_Output);
5129 if Main_Project /= No_Project then
5131 -- For all library project, if the library file does not exist, put
5132 -- all the project sources in the queue, and flag the project so that
5133 -- the library is generated.
5135 if not Unique_Compile
5136 and then MLib.Tgt.Support_For_Libraries /= Prj.None
5139 Proj : Project_List;
5142 Proj := Project_Tree.Projects;
5143 while Proj /= null loop
5144 if Proj.Project.Library then
5145 Proj.Project.Need_To_Build_Lib :=
5146 not MLib.Tgt.Library_Exists_For
5147 (Proj.Project, Project_Tree)
5148 and then not Proj.Project.Externally_Built;
5150 if Proj.Project.Need_To_Build_Lib then
5152 -- If there is no object directory, then it will be
5153 -- impossible to build the library. So fail
5157 Proj.Project.Object_Directory = No_Path_Information
5160 ("no object files to build library for project """
5161 & Get_Name_String (Proj.Project.Name)
5163 Proj.Project.Need_To_Build_Lib := False;
5166 if Verbose_Mode then
5168 ("Library file does not exist for project """);
5169 Write_Str (Get_Name_String (Proj.Project.Name));
5173 Insert_Project_Sources
5174 (The_Project => Proj.Project,
5175 All_Projects => False,
5186 -- If a relative path output file has been specified, we add the
5189 for J in reverse 1 .. Saved_Linker_Switches.Last - 1 loop
5190 if Saved_Linker_Switches.Table (J).all = Output_Flag.all then
5192 Exec_File_Name : constant String :=
5193 Saved_Linker_Switches.Table (J + 1).all;
5196 if not Is_Absolute_Path (Exec_File_Name) then
5198 (Main_Project.Exec_Directory.Display_Name);
5199 Add_Str_To_Name_Buffer (Exec_File_Name);
5200 Saved_Linker_Switches.Table (J + 1) :=
5201 new String'(Name_Buffer (1 .. Name_Len));
5209 -- If we are using a project file, for relative paths we add the
5210 -- current working directory for any relative path on the command
5211 -- line and the project directory, for any relative path in the
5215 Dir_Path : constant String :=
5216 Get_Name_String (Main_Project.Directory.Display_Name);
5218 for J in 1 .. Binder_Switches.Last loop
5219 Test_If_Relative_Path
5220 (Binder_Switches.Table (J),
5221 Parent => Dir_Path, Including_L_Switch => False);
5224 for J in 1 .. Saved_Binder_Switches.Last loop
5225 Test_If_Relative_Path
5226 (Saved_Binder_Switches.Table (J),
5227 Parent => Current_Work_Dir.all, Including_L_Switch => False);
5230 for J in 1 .. Linker_Switches.Last loop
5231 Test_If_Relative_Path
5232 (Linker_Switches.Table (J), Parent => Dir_Path);
5235 for J in 1 .. Saved_Linker_Switches.Last loop
5236 Test_If_Relative_Path
5237 (Saved_Linker_Switches.Table (J),
5238 Parent => Current_Work_Dir.all);
5241 for J in 1 .. Gcc_Switches.Last loop
5242 Test_If_Relative_Path
5243 (Gcc_Switches.Table (J),
5245 Including_Non_Switch => False);
5248 for J in 1 .. Saved_Gcc_Switches.Last loop
5249 Test_If_Relative_Path
5250 (Saved_Gcc_Switches.Table (J),
5251 Parent => Current_Work_Dir.all,
5252 Including_Non_Switch => False);
5257 -- We now put in the Binder_Switches and Linker_Switches tables, the
5258 -- binder and linker switches of the command line that have been put in
5259 -- the Saved_ tables. If a project file was used, then the command line
5260 -- switches will follow the project file switches.
5262 for J in 1 .. Saved_Binder_Switches.Last loop
5264 (Saved_Binder_Switches.Table (J),
5269 for J in 1 .. Saved_Linker_Switches.Last loop
5271 (Saved_Linker_Switches.Table (J),
5276 -- If no project file is used, we just put the gcc switches
5277 -- from the command line in the Gcc_Switches table.
5279 if Main_Project = No_Project then
5280 for J in 1 .. Saved_Gcc_Switches.Last loop
5282 (Saved_Gcc_Switches.Table (J), Compiler, And_Save => False);
5286 -- If there is a project, put the command line gcc switches in the
5287 -- variable The_Saved_Gcc_Switches. They are going to be used later
5288 -- in procedure Compile_Sources.
5290 The_Saved_Gcc_Switches :=
5291 new Argument_List (1 .. Saved_Gcc_Switches.Last + 1);
5293 for J in 1 .. Saved_Gcc_Switches.Last loop
5294 The_Saved_Gcc_Switches (J) := Saved_Gcc_Switches.Table (J);
5297 -- We never use gnat.adc when a project file is used
5299 The_Saved_Gcc_Switches (The_Saved_Gcc_Switches'Last) := No_gnat_adc;
5302 -- If there was a --GCC, --GNATBIND or --GNATLINK switch on the command
5303 -- line, then we have to use it, even if there was another switch in
5304 -- the project file.
5306 if Saved_Gcc /= null then
5310 if Saved_Gnatbind /= null then
5311 Gnatbind := Saved_Gnatbind;
5314 if Saved_Gnatlink /= null then
5315 Gnatlink := Saved_Gnatlink;
5318 Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
5319 Gnatbind_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
5320 Gnatlink_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
5322 -- If we have specified -j switch both from the project file
5323 -- and on the command line, the one from the command line takes
5326 if Saved_Maximum_Processes = 0 then
5327 Saved_Maximum_Processes := Maximum_Processes;
5330 if Debug.Debug_Flag_M then
5331 Write_Line ("Maximum number of simultaneous compilations =" &
5332 Saved_Maximum_Processes'Img);
5335 -- Allocate as many temporary mapping file names as the maximum number
5336 -- of compilations processed, for each possible project.
5339 Data : Project_Compilation_Access;
5340 Proj : Project_List := Project_Tree.Projects;
5342 while Proj /= null loop
5343 Data := new Project_Compilation_Data'
5344 (Mapping_File_Names => new Temp_Path_Names
5345 (1 .. Saved_Maximum_Processes),
5346 Last_Mapping_File_Names => 0,
5347 Free_Mapping_File_Indexes => new Free_File_Indexes
5348 (1 .. Saved_Maximum_Processes),
5349 Last_Free_Indexes => 0);
5351 Project_Compilation_Htable.Set
5352 (Project_Compilation, Proj.Project, Data);
5356 Data := new Project_Compilation_Data'
5357 (Mapping_File_Names => new Temp_Path_Names
5358 (1 .. Saved_Maximum_Processes),
5359 Last_Mapping_File_Names => 0,
5360 Free_Mapping_File_Indexes => new Free_File_Indexes
5361 (1 .. Saved_Maximum_Processes),
5362 Last_Free_Indexes => 0);
5364 Project_Compilation_Htable.Set
5365 (Project_Compilation, No_Project, Data);
5368 Bad_Compilation.Init;
5370 -- If project files are used, create the mapping of all the sources, so
5371 -- that the correct paths will be found. Otherwise, if there is a file
5372 -- which is not a source with the same name in a source directory this
5373 -- file may be incorrectly found.
5375 if Main_Project /= No_Project then
5376 Prj.Env.Create_Mapping (Project_Tree);
5379 Current_Main_Index := Main_Index;
5381 -- Here is where the make process is started
5383 -- We do the same process for each main
5385 Multiple_Main_Loop : for N_File in 1 .. Osint.Number_Of_Files loop
5387 -- First, find the executable name and path
5389 Executable := No_File;
5390 Executable_Obsolete := False;
5391 Non_Std_Executable :=
5392 Targparm.Executable_Extension_On_Target /= No_Name;
5394 -- Look inside the linker switches to see if the name of the final
5395 -- executable program was specified.
5397 for J in reverse Linker_Switches.First .. Linker_Switches.Last loop
5398 if Linker_Switches.Table (J).all = Output_Flag.all then
5399 pragma Assert (J < Linker_Switches.Last);
5401 -- We cannot specify a single executable for several main
5404 if Osint.Number_Of_Files > 1 then
5406 ("cannot specify a single executable for several mains");
5410 Add_Str_To_Name_Buffer (Linker_Switches.Table (J + 1).all);
5411 Executable := Name_Enter;
5413 Verbose_Msg (Executable, "final executable");
5417 -- If the name of the final executable program was not specified then
5418 -- construct it from the main input file.
5420 if Executable = No_File then
5421 if Main_Project = No_Project then
5422 Executable := Executable_Name (Strip_Suffix (Main_Source_File));
5425 -- If we are using a project file, we attempt to remove the
5426 -- body (or spec) termination of the main subprogram. We find
5427 -- it the naming scheme of the project file. This avoids
5428 -- generating an executable "main.2" for a main subprogram
5429 -- "main.2.ada", when the body termination is ".2.ada".
5432 Prj.Util.Executable_Of
5433 (Main_Project, Project_Tree, Main_Source_File, Main_Index);
5437 if Main_Project /= No_Project
5438 and then Main_Project.Exec_Directory /= No_Path_Information
5441 Exec_File_Name : constant String :=
5442 Get_Name_String (Executable);
5445 if not Is_Absolute_Path (Exec_File_Name) then
5446 Get_Name_String (Main_Project.Exec_Directory.Display_Name);
5447 Add_Str_To_Name_Buffer (Exec_File_Name);
5448 Executable := Name_Find;
5451 Non_Std_Executable := True;
5455 if Do_Compile_Step then
5456 Recursive_Compilation_Step : declare
5457 Args : Argument_List (1 .. Gcc_Switches.Last);
5459 First_Compiled_File : File_Name_Type;
5460 Youngest_Obj_File : File_Name_Type;
5461 Youngest_Obj_Stamp : Time_Stamp_Type;
5463 Executable_Stamp : Time_Stamp_Type;
5464 -- Executable is the final executable program
5465 -- ??? comment seems unrelated to declaration
5467 Library_Rebuilt : Boolean := False;
5470 for J in 1 .. Gcc_Switches.Last loop
5471 Args (J) := Gcc_Switches.Table (J);
5475 (Main_Project /= No_Project and then
5476 One_Compilation_Per_Obj_Dir);
5478 -- Now we invoke Compile_Sources for the current main
5481 (Main_Source => Main_Source_File,
5483 First_Compiled_File => First_Compiled_File,
5484 Most_Recent_Obj_File => Youngest_Obj_File,
5485 Most_Recent_Obj_Stamp => Youngest_Obj_Stamp,
5486 Main_Unit => Is_Main_Unit,
5487 Main_Index => Current_Main_Index,
5488 Compilation_Failures => Compilation_Failures,
5489 Check_Readonly_Files => Check_Readonly_Files,
5490 Do_Not_Execute => Do_Not_Execute,
5491 Force_Compilations => Force_Compilations,
5492 In_Place_Mode => In_Place_Mode,
5493 Keep_Going => Keep_Going,
5494 Initialize_ALI_Data => True,
5495 Max_Process => Saved_Maximum_Processes);
5497 if Verbose_Mode then
5498 Write_Str ("End of compilation");
5502 Total_Compilation_Failures :=
5503 Total_Compilation_Failures + Compilation_Failures;
5505 if Total_Compilation_Failures /= 0 then
5510 List_Bad_Compilations;
5511 Report_Compilation_Failed;
5515 -- Regenerate libraries, if there are any and if object files
5516 -- have been regenerated.
5518 if Main_Project /= No_Project
5519 and then MLib.Tgt.Support_For_Libraries /= Prj.None
5520 and then (Do_Bind_Step
5521 or Unique_Compile_All_Projects
5522 or not Compile_Only)
5523 and then (Do_Link_Step or else N_File = Osint.Number_Of_Files)
5530 Proj1 : Project_List;
5532 procedure Add_To_Library_Projs (Proj : Project_Id);
5533 -- Add project Project to table Library_Projs in
5534 -- decreasing depth order.
5536 --------------------------
5537 -- Add_To_Library_Projs --
5538 --------------------------
5540 procedure Add_To_Library_Projs (Proj : Project_Id) is
5544 Library_Projs.Increment_Last;
5545 Depth := Proj.Depth;
5547 -- Put the projects in decreasing depth order, so that
5548 -- if libA depends on libB, libB is first in order.
5550 Current := Library_Projs.Last;
5551 while Current > 1 loop
5552 Prj := Library_Projs.Table (Current - 1);
5553 exit when Prj.Depth >= Depth;
5554 Library_Projs.Table (Current) := Prj;
5555 Current := Current - 1;
5558 Library_Projs.Table (Current) := Proj;
5559 end Add_To_Library_Projs;
5561 -- Start of processing for ??? (should name declare block
5562 -- or probably better, break this out as a nested proc).
5565 -- Put in Library_Projs table all library project file
5566 -- ids when the library need to be rebuilt.
5568 Proj1 := Project_Tree.Projects;
5569 while Proj1 /= null loop
5570 if Proj1.Project.Standalone_Library then
5571 Stand_Alone_Libraries := True;
5574 if Proj1.Project.Library then
5575 MLib.Prj.Check_Library
5576 (Proj1.Project, Project_Tree);
5579 if Proj1.Project.Need_To_Build_Lib then
5580 Add_To_Library_Projs (Proj1.Project);
5583 Proj1 := Proj1.Next;
5586 -- Check if importing libraries should be regenerated
5587 -- because at least an imported library will be
5588 -- regenerated or is more recent.
5590 Proj1 := Project_Tree.Projects;
5591 while Proj1 /= null loop
5592 if Proj1.Project.Library
5593 and then Proj1.Project.Library_Kind /= Static
5594 and then not Proj1.Project.Need_To_Build_Lib
5595 and then not Proj1.Project.Externally_Built
5598 List : Project_List;
5600 Rebuild : Boolean := False;
5602 Lib_Timestamp1 : constant Time_Stamp_Type :=
5603 Proj1.Project.Library_TS;
5606 List := Proj1.Project.All_Imported_Projects;
5607 while List /= null loop
5608 Proj2 := List.Project;
5610 if Proj2.Library then
5611 if Proj2.Need_To_Build_Lib
5613 (Lib_Timestamp1 < Proj2.Library_TS)
5624 Proj1.Project.Need_To_Build_Lib := True;
5625 Add_To_Library_Projs (Proj1.Project);
5630 Proj1 := Proj1.Next;
5633 -- Reset the flags Need_To_Build_Lib for the next main,
5634 -- to avoid rebuilding libraries uselessly.
5636 Proj1 := Project_Tree.Projects;
5637 while Proj1 /= null loop
5638 Proj1.Project.Need_To_Build_Lib := False;
5639 Proj1 := Proj1.Next;
5643 -- Build the libraries, if any need to be built
5645 for J in 1 .. Library_Projs.Last loop
5646 Library_Rebuilt := True;
5648 -- If a library is rebuilt, then executables are obsolete
5650 Executable_Obsolete := True;
5652 MLib.Prj.Build_Library
5653 (For_Project => Library_Projs.Table (J),
5654 In_Tree => Project_Tree,
5655 Gnatbind => Gnatbind.all,
5656 Gnatbind_Path => Gnatbind_Path,
5658 Gcc_Path => Gcc_Path);
5662 if List_Dependencies then
5663 if First_Compiled_File /= No_File then
5665 (First_Compiled_File,
5666 "must be recompiled. Can't generate dependence list.");
5671 elsif First_Compiled_File = No_File
5672 and then not Do_Bind_Step
5673 and then not Quiet_Output
5674 and then not Library_Rebuilt
5675 and then Osint.Number_Of_Files = 1
5677 Inform (Msg => "objects up to date.");
5679 elsif Do_Not_Execute
5680 and then First_Compiled_File /= No_File
5682 Write_Name (First_Compiled_File);
5686 -- Stop after compile step if any of:
5688 -- 1) -n (Do_Not_Execute) specified
5690 -- 2) -M (List_Dependencies) specified (also sets
5691 -- Do_Not_Execute above, so this is probably superfluous).
5693 -- 3) -c (Compile_Only) specified, but not -b (Bind_Only)
5695 -- 4) Made unit cannot be a main unit
5698 or List_Dependencies
5700 or not Is_Main_Unit)
5701 and then not No_Main_Subprogram
5702 and then not Build_Bind_And_Link_Full_Project)
5703 or else Unique_Compile
5705 if Osint.Number_Of_Files = 1 then
5706 exit Multiple_Main_Loop;
5713 -- If the objects were up-to-date check if the executable file
5714 -- is also up-to-date. For now always bind and link on the JVM
5715 -- since there is currently no simple way to check whether
5716 -- objects are up-to-date.
5718 if Targparm.VM_Target /= JVM_Target
5719 and then First_Compiled_File = No_File
5721 Executable_Stamp := File_Stamp (Executable);
5723 if not Executable_Obsolete then
5724 Executable_Obsolete :=
5725 Youngest_Obj_Stamp > Executable_Stamp;
5728 if not Executable_Obsolete then
5729 for Index in reverse 1 .. Dependencies.Last loop
5731 (Dependencies.Table (Index).Depends_On)
5733 Enter_Into_Obsoleted
5734 (Dependencies.Table (Index).This);
5738 Executable_Obsolete := Is_In_Obsoleted (Main_Source_File);
5742 if not Executable_Obsolete then
5744 -- If no Ada object files obsolete the executable, check
5745 -- for younger or missing linker files.
5747 Check_Linker_Options
5750 Youngest_Obj_Stamp);
5752 Executable_Obsolete := Youngest_Obj_File /= No_File;
5755 -- Check if any library file is more recent than the
5756 -- executable: there may be an externally built library
5757 -- file that has been modified.
5759 if not Executable_Obsolete
5760 and then Main_Project /= No_Project
5763 Proj1 : Project_List;
5766 Proj1 := Project_Tree.Projects;
5767 while Proj1 /= null loop
5768 if Proj1.Project.Library
5770 Proj1.Project.Library_TS > Executable_Stamp
5772 Executable_Obsolete := True;
5773 Youngest_Obj_Stamp := Proj1.Project.Library_TS;
5775 Add_Str_To_Name_Buffer ("library ");
5776 Add_Str_To_Name_Buffer
5777 (Get_Name_String (Proj1.Project.Library_Name));
5778 Youngest_Obj_File := Name_Find;
5782 Proj1 := Proj1.Next;
5787 -- Return if the executable is up to date and otherwise
5788 -- motivate the relink/rebind.
5790 if not Executable_Obsolete then
5791 if not Quiet_Output then
5792 Inform (Executable, "up to date.");
5795 if Osint.Number_Of_Files = 1 then
5796 exit Multiple_Main_Loop;
5803 if Executable_Stamp (1) = ' ' then
5804 if not No_Main_Subprogram then
5805 Verbose_Msg (Executable, "missing.", Prefix => " ");
5808 elsif Youngest_Obj_Stamp (1) = ' ' then
5810 (Youngest_Obj_File, "missing.", Prefix => " ");
5812 elsif Youngest_Obj_Stamp > Executable_Stamp then
5815 "(" & String (Youngest_Obj_Stamp) & ") newer than",
5817 "(" & String (Executable_Stamp) & ")");
5821 (Executable, "needs to be rebuilt", Prefix => " ");
5825 end Recursive_Compilation_Step;
5828 -- For binding and linking, we need to be in the object directory of
5829 -- the main project.
5831 if Main_Project /= No_Project then
5832 Change_To_Object_Directory (Main_Project);
5835 -- If we are here, it means that we need to rebuilt the current main,
5836 -- so we set Executable_Obsolete to True to make sure that subsequent
5837 -- mains will be rebuilt.
5839 Main_ALI_In_Place_Mode_Step : declare
5840 ALI_File : File_Name_Type;
5841 Src_File : File_Name_Type;
5844 Src_File := Strip_Directory (Main_Source_File);
5845 ALI_File := Lib_File_Name (Src_File, Current_Main_Index);
5846 Main_ALI_File := Full_Lib_File_Name (ALI_File);
5848 -- When In_Place_Mode, the library file can be located in the
5849 -- Main_Source_File directory which may not be present in the
5850 -- library path. If it is not present then use the corresponding
5851 -- library file name.
5853 if Main_ALI_File = No_File and then In_Place_Mode then
5854 Get_Name_String (Get_Directory (Full_Source_Name (Src_File)));
5855 Get_Name_String_And_Append (ALI_File);
5856 Main_ALI_File := Name_Find;
5857 Main_ALI_File := Full_Lib_File_Name (Main_ALI_File);
5860 if Main_ALI_File = No_File then
5861 Make_Failed ("could not find the main ALI file");
5863 end Main_ALI_In_Place_Mode_Step;
5865 if Do_Bind_Step then
5867 Args : Argument_List
5868 (Binder_Switches.First .. Binder_Switches.Last + 2);
5869 -- The arguments for the invocation of gnatbind
5871 Last_Arg : Natural := Binder_Switches.Last;
5872 -- Index of the last argument in Args
5874 Shared_Libs : Boolean := False;
5875 -- Set to True when there are shared library project files or
5876 -- when gnatbind is invoked with -shared.
5878 Proj : Project_List;
5881 -- Check if there are shared libraries, so that gnatbind is
5882 -- called with -shared. Check also if gnatbind is called with
5883 -- -shared, so that gnatlink is called with -shared-libgcc
5884 -- ensuring that the shared version of libgcc will be used.
5886 if Main_Project /= No_Project
5887 and then MLib.Tgt.Support_For_Libraries /= Prj.None
5889 Proj := Project_Tree.Projects;
5890 while Proj /= null loop
5891 if Proj.Project.Library
5892 and then Proj.Project.Library_Kind /= Static
5894 Shared_Libs := True;
5895 Bind_Shared := Shared_Switch'Access;
5902 -- Check now for switch -shared
5904 if not Shared_Libs then
5905 for J in Binder_Switches.First .. Last_Arg loop
5906 if Binder_Switches.Table (J).all = "-shared" then
5907 Shared_Libs := True;
5913 -- If shared libraries present, invoke gnatlink with
5917 Link_With_Shared_Libgcc := Shared_Libgcc_Switch'Access;
5920 -- Get all the binder switches
5922 for J in Binder_Switches.First .. Last_Arg loop
5923 Args (J) := Binder_Switches.Table (J);
5926 if Stand_Alone_Libraries then
5927 Last_Arg := Last_Arg + 1;
5928 Args (Last_Arg) := Force_Elab_Flags_String'Access;
5931 if Main_Project /= No_Project then
5933 -- Put all the source directories in ADA_INCLUDE_PATH,
5934 -- and all the object directories in ADA_OBJECTS_PATH,
5935 -- except those of library projects.
5937 Prj.Env.Set_Ada_Paths
5938 (Main_Project, Project_Tree, Use_Include_Path_File);
5940 -- If switch -C was specified, create a binder mapping file
5942 if Create_Mapping_File then
5943 Mapping_Path := Create_Binder_Mapping_File;
5945 if Mapping_Path /= No_Path then
5946 Last_Arg := Last_Arg + 1;
5948 new String'("-F=" & Get_Name_String (Mapping_Path));
5955 Bind (Main_ALI_File,
5956 Bind_Shared.all & Args (Args'First .. Last_Arg));
5961 -- Delete the temporary mapping file if one was created
5963 if Mapping_Path /= No_Path then
5964 Delete_Temporary_File (Project_Tree, Mapping_Path);
5967 -- And reraise the exception
5972 -- If -dn was not specified, delete the temporary mapping file
5973 -- if one was created.
5975 if Mapping_Path /= No_Path then
5976 Delete_Temporary_File (Project_Tree, Mapping_Path);
5981 if Do_Link_Step then
5983 Linker_Switches_Last : constant Integer := Linker_Switches.Last;
5984 Path_Option : constant String_Access :=
5985 MLib.Linker_Library_Path_Option;
5986 Libraries_Present : Boolean := False;
5990 Proj1 : Project_List;
5993 if not Run_Path_Option then
5994 Linker_Switches.Increment_Last;
5995 Linker_Switches.Table (Linker_Switches.Last) :=
5999 if Main_Project /= No_Project then
6000 Library_Paths.Set_Last (0);
6003 if MLib.Tgt.Support_For_Libraries /= Prj.None then
6005 -- Check for library projects
6007 Proj1 := Project_Tree.Projects;
6008 while Proj1 /= null loop
6009 if Proj1.Project /= Main_Project
6010 and then Proj1.Project.Library
6012 -- Add this project to table Library_Projs
6014 Libraries_Present := True;
6015 Depth := Proj1.Project.Depth;
6016 Library_Projs.Increment_Last;
6017 Current := Library_Projs.Last;
6019 -- Any project with a greater depth should be
6020 -- after this project in the list.
6022 while Current > 1 loop
6023 Proj2 := Library_Projs.Table (Current - 1);
6024 exit when Proj2.Depth <= Depth;
6025 Library_Projs.Table (Current) := Proj2;
6026 Current := Current - 1;
6029 Library_Projs.Table (Current) := Proj1.Project;
6031 -- If it is not a static library and path option
6032 -- is set, add it to the Library_Paths table.
6034 if Proj1.Project.Library_Kind /= Static
6035 and then Path_Option /= null
6037 Library_Paths.Increment_Last;
6038 Library_Paths.Table (Library_Paths.Last) :=
6041 (Proj1.Project.Library_Dir.Display_Name));
6045 Proj1 := Proj1.Next;
6048 for Index in 1 .. Library_Projs.Last loop
6049 if Library_Projs.Table (Index).Library_Kind = Static
6050 and then not Targparm.OpenVMS_On_Target
6052 Linker_Switches.Increment_Last;
6053 Linker_Switches.Table (Linker_Switches.Last) :=
6056 (Library_Projs.Table
6057 (Index).Library_Dir.Display_Name) &
6060 (Library_Projs.Table (Index). Library_Name) &
6062 MLib.Tgt.Archive_Ext);
6065 -- Add the -L switch
6067 Linker_Switches.Increment_Last;
6068 Linker_Switches.Table (Linker_Switches.Last) :=
6071 (Library_Projs.Table (Index).
6072 Library_Dir.Display_Name));
6074 -- Add the -l switch
6076 Linker_Switches.Increment_Last;
6077 Linker_Switches.Table (Linker_Switches.Last) :=
6080 (Library_Projs.Table (Index).
6086 if Libraries_Present then
6088 -- If Path_Option is not null, create the switch
6089 -- ("-Wl,-rpath," or equivalent) with all the non-static
6090 -- library dirs plus the standard GNAT library dir.
6091 -- We do that only if Run_Path_Option is True
6092 -- (not disabled by -R switch).
6094 if Run_Path_Option and then Path_Option /= null then
6096 Option : String_Access;
6097 Length : Natural := Path_Option'Length;
6101 if MLib.Separate_Run_Path_Options then
6103 -- We are going to create one switch of the form
6104 -- "-Wl,-rpath,dir_N" for each directory to
6107 -- One switch for each library directory
6110 Library_Paths.First .. Library_Paths.Last
6112 Linker_Switches.Increment_Last;
6113 Linker_Switches.Table
6114 (Linker_Switches.Last) :=
6117 Library_Paths.Table (Index).all);
6120 -- One switch for the standard GNAT library dir
6122 Linker_Switches.Increment_Last;
6123 Linker_Switches.Table
6124 (Linker_Switches.Last) :=
6126 (Path_Option.all & MLib.Utl.Lib_Directory);
6129 -- We are going to create one switch of the form
6130 -- "-Wl,-rpath,dir_1:dir_2:dir_3"
6133 Library_Paths.First .. Library_Paths.Last
6135 -- Add the length of the library dir plus one
6136 -- for the directory separator.
6140 Library_Paths.Table (Index)'Length + 1;
6143 -- Finally, add the length of the standard GNAT
6146 Length := Length + MLib.Utl.Lib_Directory'Length;
6147 Option := new String (1 .. Length);
6148 Option (1 .. Path_Option'Length) :=
6150 Current := Path_Option'Length;
6152 -- Put each library dir followed by a dir
6156 Library_Paths.First .. Library_Paths.Last
6161 Library_Paths.Table (Index)'Length) :=
6162 Library_Paths.Table (Index).all;
6165 Library_Paths.Table (Index)'Length + 1;
6166 Option (Current) := Path_Separator;
6169 -- Finally put the standard GNAT library dir
6173 Current + MLib.Utl.Lib_Directory'Length) :=
6174 MLib.Utl.Lib_Directory;
6176 -- And add the switch to the linker switches
6178 Linker_Switches.Increment_Last;
6179 Linker_Switches.Table (Linker_Switches.Last) :=
6187 -- Put the object directories in ADA_OBJECTS_PATH
6189 Prj.Env.Set_Ada_Paths
6192 Including_Libraries => False,
6193 Include_Path => False);
6195 -- Check for attributes Linker'Linker_Options in projects
6196 -- other than the main project
6199 Linker_Options : constant String_List :=
6200 Linker_Options_Switches
6201 (Main_Project, Project_Tree);
6203 for Option in Linker_Options'Range loop
6204 Linker_Switches.Increment_Last;
6205 Linker_Switches.Table (Linker_Switches.Last) :=
6206 Linker_Options (Option);
6211 -- Add switch -M to gnatlink if builder switch
6212 -- --create-map-file has been specified.
6214 if Map_File /= null then
6215 Linker_Switches.Increment_Last;
6216 Linker_Switches.Table (Linker_Switches.Last) :=
6217 new String'("-M" & Map_File.all);
6221 Args : Argument_List
6222 (Linker_Switches.First .. Linker_Switches.Last + 2);
6224 Last_Arg : Integer := Linker_Switches.First - 1;
6225 Skip : Boolean := False;
6228 -- Get all the linker switches
6230 for J in Linker_Switches.First .. Linker_Switches.Last loop
6234 elsif Non_Std_Executable
6235 and then Linker_Switches.Table (J).all = "-o"
6239 -- Here we capture and duplicate the linker argument. We
6240 -- need to do the duplication since the arguments will
6241 -- get normalized. Not doing so will result in calling
6242 -- normalized two times for the same set of arguments if
6243 -- gnatmake is passed multiple mains. This can result in
6244 -- the wrong argument being passed to the linker.
6247 Last_Arg := Last_Arg + 1;
6249 new String'(Linker_Switches.Table (J).all);
6253 -- If need be, add the -o switch
6255 if Non_Std_Executable then
6256 Last_Arg := Last_Arg + 1;
6257 Args (Last_Arg) := new String'("-o");
6258 Last_Arg := Last_Arg + 1;
6260 new String'(Get_Name_String (Executable));
6263 -- And invoke the linker
6266 Success : Boolean := False;
6268 Link (Main_ALI_File,
6269 Link_With_Shared_Libgcc.all &
6270 Args (Args'First .. Last_Arg),
6274 Successful_Links.Increment_Last;
6275 Successful_Links.Table (Successful_Links.Last) :=
6278 elsif Osint.Number_Of_Files = 1
6279 or else not Keep_Going
6281 Make_Failed ("*** link failed.");
6285 Write_Line ("*** link failed");
6287 if Commands_To_Stdout then
6288 Set_Standard_Output;
6291 Failed_Links.Increment_Last;
6292 Failed_Links.Table (Failed_Links.Last) :=
6298 Linker_Switches.Set_Last (Linker_Switches_Last);
6302 -- We go to here when we skip the bind and link steps
6306 -- We go to the next main, if we did not process the last one
6308 if N_File < Osint.Number_Of_Files then
6309 Main_Source_File := Next_Main_Source;
6311 if Current_File_Index /= No_Index then
6312 Main_Index := Current_File_Index;
6315 if Main_Project /= No_Project then
6317 -- Find the file name of the main unit
6320 Main_Source_File_Name : constant String :=
6321 Get_Name_String (Main_Source_File);
6323 Main_Unit_File_Name : constant String :=
6325 File_Name_Of_Library_Unit_Body
6326 (Name => Main_Source_File_Name,
6327 Project => Main_Project,
6328 In_Tree => Project_Tree,
6329 Main_Project_Only =>
6330 not Unique_Compile);
6332 The_Packages : constant Package_Id :=
6333 Main_Project.Decl.Packages;
6335 Binder_Package : constant Prj.Package_Id :=
6337 (Name => Name_Binder,
6338 In_Packages => The_Packages,
6339 In_Tree => Project_Tree);
6341 Linker_Package : constant Prj.Package_Id :=
6343 (Name => Name_Linker,
6344 In_Packages => The_Packages,
6345 In_Tree => Project_Tree);
6348 -- We fail if we cannot find the main source file
6349 -- as an immediate source of the main project file.
6351 if Main_Unit_File_Name = "" then
6352 Make_Failed ('"' & Main_Source_File_Name
6353 & """ is not a unit of project "
6354 & Project_File_Name.all & ".");
6357 -- Remove any directory information from the main
6358 -- source file name.
6361 Pos : Natural := Main_Unit_File_Name'Last;
6365 exit when Pos < Main_Unit_File_Name'First
6367 Main_Unit_File_Name (Pos) = Directory_Separator;
6371 Name_Len := Main_Unit_File_Name'Last - Pos;
6373 Name_Buffer (1 .. Name_Len) :=
6375 (Pos + 1 .. Main_Unit_File_Name'Last);
6377 Main_Source_File := Name_Find;
6381 -- We now deal with the binder and linker switches.
6382 -- If no project file is used, there is nothing to do
6383 -- because the binder and linker switches are the same
6386 -- Reset the tables Binder_Switches and Linker_Switches
6388 Binder_Switches.Set_Last (Last_Binder_Switch);
6389 Linker_Switches.Set_Last (Last_Linker_Switch);
6391 -- Add binder switches from the project file for this main,
6394 if Do_Bind_Step and then Binder_Package /= No_Package then
6395 if Verbose_Mode then
6396 Write_Str ("Adding binder switches for """);
6397 Write_Str (Main_Unit_File_Name);
6402 (Project_Node_Tree => Project_Node_Tree,
6403 File_Name => Main_Unit_File_Name,
6404 Index => Main_Index,
6405 The_Package => Binder_Package,
6409 -- Add linker switches from the project file for this main,
6412 if Do_Link_Step and then Linker_Package /= No_Package then
6413 if Verbose_Mode then
6414 Write_Str ("Adding linker switches for""");
6415 Write_Str (Main_Unit_File_Name);
6420 (Project_Node_Tree => Project_Node_Tree,
6421 File_Name => Main_Unit_File_Name,
6422 Index => Main_Index,
6423 The_Package => Linker_Package,
6427 -- As we are using a project file, for relative paths we add
6428 -- the current working directory for any relative path on
6429 -- the command line and the project directory, for any
6430 -- relative path in the project file.
6433 Dir_Path : constant String :=
6435 (Main_Project.Directory.Display_Name);
6439 J in Last_Binder_Switch + 1 .. Binder_Switches.Last
6441 Test_If_Relative_Path
6442 (Binder_Switches.Table (J),
6443 Parent => Dir_Path, Including_L_Switch => False);
6447 J in Last_Linker_Switch + 1 .. Linker_Switches.Last
6449 Test_If_Relative_Path
6450 (Linker_Switches.Table (J), Parent => Dir_Path);
6454 -- We now put in the Binder_Switches and Linker_Switches
6455 -- tables, the binder and linker switches of the command
6456 -- line that have been put in the Saved_ tables.
6457 -- These switches will follow the project file switches.
6459 for J in 1 .. Saved_Binder_Switches.Last loop
6461 (Saved_Binder_Switches.Table (J),
6466 for J in 1 .. Saved_Linker_Switches.Last loop
6468 (Saved_Linker_Switches.Table (J),
6476 -- Remove all marks to be sure to check sources for all executables,
6477 -- as the switches may be different and -s may be in use.
6480 end loop Multiple_Main_Loop;
6482 if Do_Codepeer_Globalize_Step then
6484 Success : Boolean := False;
6486 Globalize (Success);
6490 Write_Str ("*** globalize failed.");
6492 if Commands_To_Stdout then
6493 Set_Standard_Output;
6499 if Failed_Links.Last > 0 then
6500 for Index in 1 .. Successful_Links.Last loop
6501 Write_Str ("Linking of """);
6502 Write_Str (Get_Name_String (Successful_Links.Table (Index)));
6503 Write_Line (""" succeeded.");
6508 for Index in 1 .. Failed_Links.Last loop
6509 Write_Str ("Linking of """);
6510 Write_Str (Get_Name_String (Failed_Links.Table (Index)));
6511 Write_Line (""" failed.");
6514 if Commands_To_Stdout then
6515 Set_Standard_Output;
6518 if Total_Compilation_Failures = 0 then
6519 Report_Compilation_Failed;
6523 if Total_Compilation_Failures /= 0 then
6524 List_Bad_Compilations;
6525 Report_Compilation_Failed;
6528 -- Delete the temporary mapping file that was created if we are
6529 -- using project files.
6531 Delete_All_Temp_Files;
6533 -- Output Namet statistics
6540 Write_Line (Exception_Information (X));
6541 Make_Failed ("INTERNAL ERROR. Please report.");
6548 function Hash (F : File_Name_Type) return Header_Num is
6550 return Header_Num (1 + F mod Max_Header);
6553 --------------------
6554 -- In_Ada_Lib_Dir --
6555 --------------------
6557 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean is
6558 D : constant File_Name_Type := Get_Directory (File);
6559 B : constant Byte := Get_Name_Table_Byte (D);
6561 return (B and Ada_Lib_Dir) /= 0;
6564 -----------------------
6565 -- Init_Mapping_File --
6566 -----------------------
6568 procedure Init_Mapping_File
6569 (Project : Project_Id;
6570 Data : in out Project_Compilation_Data;
6571 File_Index : in out Natural)
6573 FD : File_Descriptor;
6575 -- For call to Close
6578 -- Increase the index of the last mapping file for this project
6580 Data.Last_Mapping_File_Names := Data.Last_Mapping_File_Names + 1;
6582 -- If there is a project file, call Create_Mapping_File with
6585 if Project /= No_Project then
6586 Prj.Env.Create_Mapping_File
6588 In_Tree => Project_Tree,
6589 Language => Name_Ada,
6590 Name => Data.Mapping_File_Names
6591 (Data.Last_Mapping_File_Names));
6593 -- Otherwise, just create an empty file
6596 Tempdir.Create_Temp_File
6598 Data.Mapping_File_Names (Data.Last_Mapping_File_Names));
6600 if FD = Invalid_FD then
6601 Make_Failed ("disk full");
6606 Data.Mapping_File_Names (Data.Last_Mapping_File_Names));
6612 Make_Failed ("disk full");
6616 -- And return the index of the newly created file
6618 File_Index := Data.Last_Mapping_File_Names;
6619 end Init_Mapping_File;
6625 procedure Initialize (Project_Node_Tree : out Project_Node_Tree_Ref) is
6627 procedure Check_Version_And_Help is
6628 new Check_Version_And_Help_G (Makeusg);
6630 -- Start of processing for Initialize
6633 -- Prepare the project's tree, since this is used to hold external
6634 -- references, project path and other attributes that can be impacted by
6635 -- the command line switches
6637 Project_Node_Tree := new Project_Node_Tree_Data;
6638 Prj.Tree.Initialize (Project_Node_Tree);
6640 -- Override default initialization of Check_Object_Consistency since
6641 -- this is normally False for GNATBIND, but is True for GNATMAKE since
6642 -- we do not need to check source consistency again once GNATMAKE has
6643 -- looked at the sources to check.
6645 Check_Object_Consistency := True;
6647 -- Package initializations (the order of calls is important here)
6649 Output.Set_Standard_Error;
6652 Binder_Switches.Init;
6653 Linker_Switches.Init;
6658 Prj.Initialize (Project_Tree);
6662 RTS_Specified := null;
6667 -- Add the directory where gnatmake is invoked in front of the path,
6668 -- if gnatmake is invoked from a bin directory or with directory
6669 -- information. Only do this if the platform is not VMS, where the
6670 -- notion of path does not really exist.
6674 Prefix : constant String := Executable_Prefix_Path;
6675 Command : constant String := Command_Name;
6678 if Prefix'Length > 0 then
6680 PATH : constant String :=
6681 Prefix & Directory_Separator & "bin" &
6683 Getenv ("PATH").all;
6685 Setenv ("PATH", PATH);
6689 for Index in reverse Command'Range loop
6690 if Command (Index) = Directory_Separator then
6692 Absolute_Dir : constant String :=
6694 (Command (Command'First .. Index));
6695 PATH : constant String :=
6698 Getenv ("PATH").all;
6700 Setenv ("PATH", PATH);
6710 -- Scan the switches and arguments
6712 -- First, scan to detect --version and/or --help
6714 Check_Version_And_Help ("GNATMAKE", "1995");
6716 -- Scan again the switch and arguments, now that we are sure that they
6717 -- do not include --version or --help.
6719 Scan_Args : for Next_Arg in 1 .. Argument_Count loop
6721 (Project_Node_Tree, Argument (Next_Arg), And_Save => True);
6724 if N_M_Switch > 0 and RTS_Specified = null then
6725 Process_Multilib (Project_Node_Tree);
6728 if Commands_To_Stdout then
6729 Set_Standard_Output;
6732 if Usage_Requested then
6736 -- Test for trailing -P switch
6738 if Project_File_Name_Present and then Project_File_Name = null then
6739 Make_Failed ("project file name missing after -P");
6741 -- Test for trailing -o switch
6743 elsif Output_File_Name_Present
6744 and then not Output_File_Name_Seen
6746 Make_Failed ("output file name missing after -o");
6748 -- Test for trailing -D switch
6750 elsif Object_Directory_Present
6751 and then not Object_Directory_Seen then
6752 Make_Failed ("object directory missing after -D");
6755 -- Test for simultaneity of -i and -D
6757 if Object_Directory_Path /= null and then In_Place_Mode then
6758 Make_Failed ("-i and -D cannot be used simultaneously");
6761 -- Deal with -C= switch
6763 if Gnatmake_Mapping_File /= null then
6765 -- First, check compatibility with other switches
6767 if Project_File_Name /= null then
6768 Make_Failed ("-C= switch is not compatible with -P switch");
6770 elsif Saved_Maximum_Processes > 1 then
6771 Make_Failed ("-C= switch is not compatible with -jnnn switch");
6774 Fmap.Initialize (Gnatmake_Mapping_File.all);
6776 ("-gnatem=" & Gnatmake_Mapping_File.all,
6781 if Project_File_Name /= null then
6783 -- A project file was specified by a -P switch
6785 if Verbose_Mode then
6787 Write_Str ("Parsing project file """);
6788 Write_Str (Project_File_Name.all);
6793 -- Avoid looking in the current directory for ALI files
6795 -- Look_In_Primary_Dir := False;
6797 -- Set the project parsing verbosity to whatever was specified
6798 -- by a possible -vP switch.
6800 Prj.Pars.Set_Verbosity (To => Current_Verbosity);
6802 -- Parse the project file.
6803 -- If there is an error, Main_Project will still be No_Project.
6806 (Project => Main_Project,
6807 In_Tree => Project_Tree,
6808 Project_File_Name => Project_File_Name.all,
6809 Packages_To_Check => Packages_To_Check_By_Gnatmake,
6810 Flags => Gnatmake_Flags,
6811 In_Node_Tree => Project_Node_Tree);
6813 -- The parsing of project files may have changed the current output
6815 if Commands_To_Stdout then
6816 Set_Standard_Output;
6821 if Main_Project = No_Project then
6823 ("""" & Project_File_Name.all & """ processing failed");
6826 Create_Mapping_File := True;
6828 if Verbose_Mode then
6830 Write_Str ("Parsing of project file """);
6831 Write_Str (Project_File_Name.all);
6832 Write_Str (""" is finished.");
6836 -- We add the source directories and the object directories to the
6838 -- ??? Why do we need these search directories, we already know the
6839 -- locations from parsing the project, except for the runtime which
6840 -- has its own directories anyway
6842 Add_Source_Directories (Main_Project, Project_Tree);
6843 Add_Object_Directories (Main_Project);
6845 Recursive_Compute_Depth (Main_Project);
6846 Compute_All_Imported_Projects (Project_Tree);
6850 Osint.Add_Default_Search_Dirs;
6852 -- Source file lookups should be cached for efficiency. Source files
6853 -- are not supposed to change. However, we do that now only if no
6854 -- project file is used; if a project file is used, we do it just
6855 -- after changing the directory to the object directory.
6857 Osint.Source_File_Data (Cache => True);
6859 -- Read gnat.adc file to initialize Fname.UF
6861 Fname.UF.Initialize;
6864 Fname.SF.Read_Source_File_Name_Pragmas;
6867 when Err : SFN_Scan.Syntax_Error_In_GNAT_ADC =>
6868 Make_Failed (Exception_Message (Err));
6872 -- Make sure no project object directory is recorded
6874 Project_Of_Current_Object_Directory := No_Project;
6878 ----------------------------
6879 -- Insert_Project_Sources --
6880 ----------------------------
6882 procedure Insert_Project_Sources
6883 (The_Project : Project_Id;
6884 All_Projects : Boolean;
6887 Put_In_Q : Boolean := Into_Q;
6889 Sfile : File_Name_Type;
6891 Project : Project_Id;
6893 Extending : constant Boolean := The_Project.Extends /= No_Project;
6895 function Check_Project (P : Project_Id) return Boolean;
6896 -- Returns True if P is The_Project or a project extended by The_Project
6902 function Check_Project (P : Project_Id) return Boolean is
6904 if All_Projects or else P = The_Project then
6907 elsif Extending then
6912 Proj := The_Project;
6913 while Proj /= null loop
6914 if P = Proj.Extends then
6918 Proj := Proj.Extends;
6926 -- Start of processing for Insert_Project_Sources
6929 -- For all the sources in the project files,
6931 Unit := Units_Htable.Get_First (Project_Tree.Units_HT);
6932 while Unit /= null loop
6935 Project := No_Project;
6937 -- If there is a source for the body, and the body has not been
6940 if Unit.File_Names (Impl) /= null
6941 and then not Unit.File_Names (Impl).Locally_Removed
6943 -- And it is a source for the specified project
6945 if Check_Project (Unit.File_Names (Impl).Project) then
6946 Project := Unit.File_Names (Impl).Project;
6948 -- If we don't have a spec, we cannot consider the source
6949 -- if it is a subunit.
6951 if Unit.File_Names (Spec) = null then
6953 Src_Ind : Source_File_Index;
6955 -- Here we are cheating a little bit: we don't want to
6956 -- use Sinput.L, because it depends on the GNAT tree
6957 -- (Atree, Sinfo, ...). So, we pretend that it is a
6958 -- project file, and we use Sinput.P.
6960 -- Source_File_Is_Subunit is just scanning through the
6961 -- file until it finds one of the reserved words
6962 -- separate, procedure, function, generic or package.
6963 -- Fortunately, these Ada reserved words are also
6964 -- reserved for project files.
6967 Src_Ind := Sinput.P.Load_Project_File
6969 (Unit.File_Names (Impl).Path.Display_Name));
6971 -- If it is a subunit, discard it
6973 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
6977 Sfile := Unit.File_Names (Impl).Display_File;
6978 Index := Unit.File_Names (Impl).Index;
6983 Sfile := Unit.File_Names (Impl).Display_File;
6984 Index := Unit.File_Names (Impl).Index;
6988 elsif Unit.File_Names (Spec) /= null
6989 and then not Unit.File_Names (Spec).Locally_Removed
6990 and then Check_Project (Unit.File_Names (Spec).Project)
6992 -- If there is no source for the body, but there is one for the
6993 -- spec which has not been locally removed, then we take this one.
6995 Sfile := Unit.File_Names (Spec).Display_File;
6996 Index := Unit.File_Names (Spec).Index;
6997 Project := Unit.File_Names (Spec).Project;
7000 -- For the first source inserted into the Q, we need to initialize
7001 -- the Q, but not for the subsequent sources.
7004 (Main_Project /= No_Project and then
7005 One_Compilation_Per_Obj_Dir);
7007 -- And of course, only insert in the Q if the source is not marked
7009 if Sfile /= No_File and then not Is_Marked (Sfile, Index) then
7010 if Verbose_Mode then
7011 Write_Str ("Adding """);
7012 Write_Str (Get_Name_String (Sfile));
7013 Write_Line (""" to the queue");
7016 Queue.Insert (Sfile, Project, Index => Index);
7017 Mark (Sfile, Index);
7020 if not Put_In_Q and then Sfile /= No_File then
7022 -- If Put_In_Q is False, we add the source as if it were specified
7023 -- on the command line, and we set Put_In_Q to True, so that the
7024 -- following sources will only be put in the queue. The source is
7025 -- already in the Q, but we need at least one fake main to call
7028 if Verbose_Mode then
7029 Write_Str ("Adding """);
7030 Write_Str (Get_Name_String (Sfile));
7031 Write_Line (""" as if on the command line");
7034 Osint.Add_File (Get_Name_String (Sfile), Index);
7038 Unit := Units_Htable.Get_Next (Project_Tree.Units_HT);
7040 end Insert_Project_Sources;
7042 ---------------------
7043 -- Is_In_Obsoleted --
7044 ---------------------
7046 function Is_In_Obsoleted (F : File_Name_Type) return Boolean is
7053 Name : constant String := Get_Name_String (F);
7055 F2 : File_Name_Type;
7059 while First > Name'First
7060 and then Name (First - 1) /= Directory_Separator
7061 and then Name (First - 1) /= '/'
7066 if First /= Name'First then
7068 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
7075 return Obsoleted.Get (F2);
7078 end Is_In_Obsoleted;
7080 ----------------------------
7081 -- Is_In_Object_Directory --
7082 ----------------------------
7084 function Is_In_Object_Directory
7085 (Source_File : File_Name_Type;
7086 Full_Lib_File : File_Name_Type) return Boolean
7089 -- There is something to check only when using project files. Otherwise,
7090 -- this function returns True (last line of the function).
7092 if Main_Project /= No_Project then
7094 Source_File_Name : constant String :=
7095 Get_Name_String (Source_File);
7096 Saved_Verbosity : constant Verbosity := Current_Verbosity;
7097 Project : Project_Id := No_Project;
7099 Path_Name : Path_Name_Type := No_Path;
7100 pragma Warnings (Off, Path_Name);
7103 -- Call Get_Reference to know the ultimate extending project of
7104 -- the source. Call it with verbosity default to avoid verbose
7107 Current_Verbosity := Default;
7108 Prj.Env.Get_Reference
7109 (Source_File_Name => Source_File_Name,
7111 In_Tree => Project_Tree,
7113 Current_Verbosity := Saved_Verbosity;
7115 -- If this source is in a project, check that the ALI file is in
7116 -- its object directory. If it is not, return False, so that the
7117 -- ALI file will not be skipped.
7119 if Project /= No_Project then
7121 Object_Directory : constant String :=
7125 Object_Directory.Display_Name));
7127 Olast : Natural := Object_Directory'Last;
7129 Lib_File_Directory : constant String :=
7130 Normalize_Pathname (Dir_Name
7131 (Get_Name_String (Full_Lib_File)));
7133 Llast : Natural := Lib_File_Directory'Last;
7136 -- For directories, Normalize_Pathname may or may not put
7137 -- a directory separator at the end, depending on its input.
7138 -- Remove any last directory separator before comparison.
7139 -- Returns True only if the two directories are the same.
7141 if Object_Directory (Olast) = Directory_Separator then
7145 if Lib_File_Directory (Llast) = Directory_Separator then
7149 return Object_Directory (Object_Directory'First .. Olast) =
7150 Lib_File_Directory (Lib_File_Directory'First .. Llast);
7156 -- When the source is not in a project file, always return True
7159 end Is_In_Object_Directory;
7166 (ALI_File : File_Name_Type;
7167 Args : Argument_List;
7168 Success : out Boolean)
7170 Link_Args : Argument_List (1 .. Args'Length + 1);
7173 Get_Name_String (ALI_File);
7174 Link_Args (1) := new String'(Name_Buffer (1 .. Name_Len));
7176 Link_Args (2 .. Args'Length + 1) := Args;
7178 GNAT.OS_Lib.Normalize_Arguments (Link_Args);
7180 Display (Gnatlink.all, Link_Args);
7182 if Gnatlink_Path = null then
7183 Make_Failed ("error, unable to locate " & Gnatlink.all);
7186 GNAT.OS_Lib.Spawn (Gnatlink_Path.all, Link_Args, Success);
7189 ---------------------------
7190 -- List_Bad_Compilations --
7191 ---------------------------
7193 procedure List_Bad_Compilations is
7195 for J in Bad_Compilation.First .. Bad_Compilation.Last loop
7196 if Bad_Compilation.Table (J).File = No_File then
7198 elsif not Bad_Compilation.Table (J).Found then
7199 Inform (Bad_Compilation.Table (J).File, "not found");
7201 Inform (Bad_Compilation.Table (J).File, "compilation error");
7204 end List_Bad_Compilations;
7210 procedure List_Depend is
7211 Lib_Name : File_Name_Type;
7212 Obj_Name : File_Name_Type;
7213 Src_Name : File_Name_Type;
7217 Line_Size : constant := 77;
7220 Set_Standard_Output;
7222 for A in ALIs.First .. ALIs.Last loop
7223 Lib_Name := ALIs.Table (A).Afile;
7225 -- We have to provide the full library file name in In_Place_Mode
7227 if In_Place_Mode then
7228 Lib_Name := Full_Lib_File_Name (Lib_Name);
7231 Obj_Name := Object_File_Name (Lib_Name);
7232 Write_Name (Obj_Name);
7235 Get_Name_String (Obj_Name);
7237 Line_Pos := Len + 2;
7239 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
7240 Src_Name := Sdep.Table (D).Sfile;
7242 if Is_Internal_File_Name (Src_Name)
7243 and then not Check_Readonly_Files
7247 if not Quiet_Output then
7248 Src_Name := Full_Source_Name (Src_Name);
7251 Get_Name_String (Src_Name);
7254 if Line_Pos + Len + 1 > Line_Size then
7260 Line_Pos := Line_Pos + Len + 1;
7263 Write_Name (Src_Name);
7270 if not Commands_To_Stdout then
7279 procedure Make_Failed (S : String) is
7281 Delete_All_Temp_Files;
7285 --------------------
7286 -- Mark_Directory --
7287 --------------------
7289 procedure Mark_Directory
7291 Mark : Lib_Mark_Type;
7292 On_Command_Line : Boolean)
7297 function Base_Directory return String;
7298 -- If Dir comes from the command line, empty string (relative paths are
7299 -- resolved with respect to the current directory), else return the main
7300 -- project's directory.
7302 --------------------
7303 -- Base_Directory --
7304 --------------------
7306 function Base_Directory return String is
7308 if On_Command_Line then
7311 return Get_Name_String (Main_Project.Directory.Display_Name);
7315 Real_Path : constant String := Normalize_Pathname (Dir, Base_Directory);
7317 -- Start of processing for Mark_Directory
7322 if Real_Path'Length = 0 then
7323 Add_Str_To_Name_Buffer (Dir);
7326 Add_Str_To_Name_Buffer (Real_Path);
7329 -- Last character is supposed to be a directory separator
7331 if not Is_Directory_Separator (Name_Buffer (Name_Len)) then
7332 Add_Char_To_Name_Buffer (Directory_Separator);
7335 -- Add flags to the already existing flags
7338 B := Get_Name_Table_Byte (N);
7339 Set_Name_Table_Byte (N, B or Mark);
7342 ----------------------
7343 -- Process_Multilib --
7344 ----------------------
7346 procedure Process_Multilib
7347 (Project_Node_Tree : Project_Node_Tree_Ref)
7349 Output_FD : File_Descriptor;
7350 Output_Name : String_Access;
7351 Arg_Index : Natural := 0;
7352 Success : Boolean := False;
7353 Return_Code : Integer := 0;
7354 Multilib_Gcc_Path : String_Access;
7355 Multilib_Gcc : String_Access;
7356 N_Read : Integer := 0;
7357 Line : String (1 .. 1000);
7358 Args : Argument_List (1 .. N_M_Switch + 1);
7361 pragma Assert (N_M_Switch > 0 and RTS_Specified = null);
7363 -- In case we detected a multilib switch and the user has not
7364 -- manually specified a specific RTS we emulate the following command:
7365 -- gnatmake $FLAGS --RTS=$(gcc -print-multi-directory $FLAGS)
7367 -- First select the flags which might have an impact on multilib
7368 -- processing. Note that this is an heuristic selection and it
7369 -- will need to be maintained over time. The condition has to
7370 -- be kept synchronized with N_M_Switch counting in Scan_Make_Arg.
7372 for Next_Arg in 1 .. Argument_Count loop
7374 Argv : constant String := Argument (Next_Arg);
7377 and then Argv (1) = '-'
7378 and then Argv (2) = 'm'
7379 and then Argv /= "-margs"
7381 -- Ignore -mieee to avoid spawning an extra gcc in this case
7383 and then Argv /= "-mieee"
7385 Arg_Index := Arg_Index + 1;
7386 Args (Arg_Index) := new String'(Argv);
7391 pragma Assert (Arg_Index = N_M_Switch);
7393 Args (Args'Last) := new String'("-print-multi-directory");
7395 -- Call the GCC driver with the collected flags and save its
7396 -- output. Alternate design would be to link in gnatmake the
7397 -- relevant part of the GCC driver.
7399 if Saved_Gcc /= null then
7400 Multilib_Gcc := Saved_Gcc;
7402 Multilib_Gcc := Gcc;
7405 Multilib_Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Multilib_Gcc.all);
7407 Create_Temp_Output_File (Output_FD, Output_Name);
7409 if Output_FD = Invalid_FD then
7414 (Multilib_Gcc_Path.all, Args, Output_FD, Return_Code, False);
7417 if Return_Code /= 0 then
7421 -- Parse the GCC driver output which is a single line, removing CR/LF
7423 Output_FD := Open_Read (Output_Name.all, Binary);
7425 if Output_FD = Invalid_FD then
7429 N_Read := Read (Output_FD, Line (1)'Address, Line'Length);
7431 Delete_File (Output_Name.all, Success);
7433 for J in reverse 1 .. N_Read loop
7434 if Line (J) = ASCII.CR or else Line (J) = ASCII.LF then
7435 N_Read := N_Read - 1;
7441 -- In case the standard RTS is selected do nothing
7443 if N_Read = 0 or else Line (1 .. N_Read) = "." then
7447 -- Otherwise add -margs --RTS=output
7449 Scan_Make_Arg (Project_Node_Tree, "-margs", And_Save => True);
7451 (Project_Node_Tree, "--RTS=" & Line (1 .. N_Read), And_Save => True);
7452 end Process_Multilib;
7458 package body Queue is
7460 type Q_Record is record
7461 File : File_Name_Type;
7462 Unit : Unit_Name_Type;
7464 Project : Project_Id;
7465 Processed : Boolean;
7467 -- File is the name of the file to compile. Unit is for gnatdist use in
7468 -- order to easily get the unit name of a file to compile when its name
7469 -- is krunched or declared in gnat.adc. Index, when not 0, is the index
7470 -- of the unit in a multi-unit source.
7472 package Q is new Table.Table
7473 (Table_Component_Type => Q_Record,
7474 Table_Index_Type => Positive,
7475 Table_Low_Bound => 1,
7476 Table_Initial => 4000,
7477 Table_Increment => 100,
7478 Table_Name => "Make.Queue.Q");
7479 -- This is the actual Q
7481 package Busy_Obj_Dirs is new GNAT.HTable.Simple_HTable
7482 (Header_Num => Prj.Header_Num,
7484 No_Element => False,
7485 Key => Path_Name_Type,
7489 Q_First : Natural := 1;
7490 -- Points to the first valid element in the queue
7492 Q_Processed : Natural := 0;
7493 One_Queue_Per_Obj_Dir : Boolean := False;
7494 Q_Initialized : Boolean := False;
7500 function Element (Rank : Positive) return File_Name_Type is
7502 if Rank <= Q.Last then
7503 return Q.Table (Rank).File;
7513 -- This body needs commenting ???
7516 (Source_File_Name : out File_Name_Type;
7517 Source_Unit : out Unit_Name_Type;
7518 Source_Index : out Int)
7520 Found : Boolean := False;
7523 if One_Queue_Per_Obj_Dir then
7524 for J in Q_First .. Q.Last loop
7525 if not Q.Table (J).Processed
7526 and then (Q.Table (J).Project = No_Project
7529 (Q.Table (J).Project.Object_Directory.Name))
7532 Source_File_Name := Q.Table (J).File;
7533 Source_Unit := Q.Table (J).Unit;
7534 Source_Index := Q.Table (J).Index;
7535 Q.Table (J).Processed := True;
7538 while Q_First <= Q.Last
7539 and then Q.Table (Q_First).Processed
7541 Q_First := Q_First + 1;
7549 elsif Q_First <= Q.Last then
7550 Source_File_Name := Q.Table (Q_First).File;
7551 Source_Unit := Q.Table (Q_First).Unit;
7552 Source_Index := Q.Table (Q_First).Index;
7553 Q.Table (Q_First).Processed := True;
7554 Q_First := Q_First + 1;
7559 Q_Processed := Q_Processed + 1;
7561 Source_File_Name := No_File;
7562 Source_Unit := No_Unit_Name;
7566 if Found and then Debug.Debug_Flag_Q then
7567 Write_Str (" Q := Q - [ ");
7568 Write_Name (Source_File_Name);
7570 if Source_Index /= 0 then
7572 Write_Int (Source_Index);
7578 Write_Str (" Q_First =");
7579 Write_Int (Int (Q_First));
7582 Write_Str (" Q.Last =");
7583 Write_Int (Int (Q.Last));
7592 procedure Initialize (Queue_Per_Obj_Dir : Boolean) is
7594 if not Q_Initialized then
7595 One_Queue_Per_Obj_Dir := Queue_Per_Obj_Dir;
7597 Q_Initialized := True;
7607 -- This body needs commenting ???
7610 (Source_File_Name : File_Name_Type;
7611 Project : Project_Id;
7612 Source_Unit : Unit_Name_Type := No_Unit_Name;
7617 ((File => Source_File_Name,
7619 Unit => Source_Unit,
7621 Processed => False));
7623 if Debug.Debug_Flag_Q then
7624 Write_Str (" Q := Q + [ ");
7625 Write_Name (Source_File_Name);
7635 Write_Str (" Q_First =");
7636 Write_Int (Int (Q_First));
7639 Write_Str (" Q.Last =");
7640 Write_Int (Int (Q.Last));
7649 function Is_Empty return Boolean is
7651 if Debug.Debug_Flag_P then
7652 Write_Str (" Q := [");
7654 for J in Q_First .. Q.Last loop
7655 if not Q.Table (J).Processed then
7657 Write_Name (Q.Table (J).File);
7667 return Q_First > Q.Last;
7670 ------------------------
7671 -- Is_Virtually_Empty --
7672 ------------------------
7674 function Is_Virtually_Empty return Boolean is
7676 if One_Queue_Per_Obj_Dir then
7677 for J in Q_First .. Q.Last loop
7678 if not Q.Table (J).Processed
7680 (Q.Table (J).Project = No_Project
7683 (Q.Table (J).Project.Object_Directory.Name))
7694 end Is_Virtually_Empty;
7700 function Processed return Natural is
7705 ----------------------
7706 -- Set_Obj_Dir_Busy --
7707 ----------------------
7709 procedure Set_Obj_Dir_Busy (Obj_Dir : Path_Name_Type) is
7711 if One_Queue_Per_Obj_Dir then
7712 Busy_Obj_Dirs.Set (Obj_Dir, True);
7714 end Set_Obj_Dir_Busy;
7716 ----------------------
7717 -- Set_Obj_Dir_Free --
7718 ----------------------
7720 procedure Set_Obj_Dir_Free (Obj_Dir : Path_Name_Type) is
7722 if One_Queue_Per_Obj_Dir then
7723 Busy_Obj_Dirs.Set (Obj_Dir, False);
7725 end Set_Obj_Dir_Free;
7731 function Size return Natural is
7738 -----------------------------
7739 -- Recursive_Compute_Depth --
7740 -----------------------------
7742 procedure Recursive_Compute_Depth (Project : Project_Id) is
7743 use Project_Boolean_Htable;
7744 Seen : Project_Boolean_Htable.Instance := Project_Boolean_Htable.Nil;
7746 procedure Recurse (Prj : Project_Id; Depth : Natural);
7747 -- Recursive procedure that does the work, keeping track of the depth
7753 procedure Recurse (Prj : Project_Id; Depth : Natural) is
7754 List : Project_List;
7758 if Prj.Depth >= Depth or else Get (Seen, Prj) then
7762 -- We need a test to avoid infinite recursions with limited withs:
7763 -- If we have A -> B -> A, then when set level of A to n, we try and
7764 -- set level of B to n+1, and then level of A to n + 2, ...
7766 Set (Seen, Prj, True);
7770 -- Visit each imported project
7772 List := Prj.Imported_Projects;
7773 while List /= null loop
7774 Proj := List.Project;
7776 Recurse (Prj => Proj, Depth => Depth + 1);
7779 -- We again allow changing the depth of this project later on if it
7780 -- is in fact imported by a lower-level project.
7782 Set (Seen, Prj, False);
7785 Proj : Project_List;
7787 -- Start of processing for Recursive_Compute_Depth
7790 Proj := Project_Tree.Projects;
7791 while Proj /= null loop
7792 Proj.Project.Depth := 0;
7796 Recurse (Project, Depth => 1);
7798 end Recursive_Compute_Depth;
7800 -------------------------------
7801 -- Report_Compilation_Failed --
7802 -------------------------------
7804 procedure Report_Compilation_Failed is
7806 Delete_All_Temp_Files;
7807 Exit_Program (E_Fatal);
7808 end Report_Compilation_Failed;
7810 ------------------------
7811 -- Sigint_Intercepted --
7812 ------------------------
7814 procedure Sigint_Intercepted is
7815 SIGINT : constant := 2;
7819 Write_Line ("*** Interrupted ***");
7821 -- Send SIGINT to all outstanding compilation processes spawned
7823 for J in 1 .. Outstanding_Compiles loop
7824 Kill (Running_Compile (J).Pid, SIGINT, 1);
7827 Delete_All_Temp_Files;
7829 -- ??? OS_Exit (1) is equivalent to Exit_Program (E_No_Compile),
7830 -- shouldn't that be Exit_Program (E_Abort) instead?
7831 end Sigint_Intercepted;
7837 procedure Scan_Make_Arg
7838 (Project_Node_Tree : Project_Node_Tree_Ref;
7845 Gnatmake_Switch_Found := True;
7847 pragma Assert (Argv'First = 1);
7849 if Argv'Length = 0 then
7853 -- If the previous switch has set the Project_File_Name_Present flag
7854 -- (that is we have seen a -P alone), then the next argument is the name
7855 -- of the project file.
7857 if Project_File_Name_Present and then Project_File_Name = null then
7858 if Argv (1) = '-' then
7859 Make_Failed ("project file name missing after -P");
7862 Project_File_Name_Present := False;
7863 Project_File_Name := new String'(Argv);
7866 -- If the previous switch has set the Output_File_Name_Present flag
7867 -- (that is we have seen a -o), then the next argument is the name of
7868 -- the output executable.
7870 elsif Output_File_Name_Present
7871 and then not Output_File_Name_Seen
7873 Output_File_Name_Seen := True;
7875 if Argv (1) = '-' then
7876 Make_Failed ("output file name missing after -o");
7879 Add_Switch ("-o", Linker, And_Save => And_Save);
7880 Add_Switch (Executable_Name (Argv), Linker, And_Save => And_Save);
7883 -- If the previous switch has set the Object_Directory_Present flag
7884 -- (that is we have seen a -D), then the next argument is the path name
7885 -- of the object directory.
7887 elsif Object_Directory_Present
7888 and then not Object_Directory_Seen
7890 Object_Directory_Seen := True;
7892 if Argv (1) = '-' then
7893 Make_Failed ("object directory path name missing after -D");
7895 elsif not Is_Directory (Argv) then
7896 Make_Failed ("cannot find object directory """ & Argv & """");
7899 -- Record the object directory. Make sure it ends with a directory
7903 Norm : constant String := Normalize_Pathname (Argv);
7906 if Norm (Norm'Last) = Directory_Separator then
7907 Object_Directory_Path := new String'(Norm);
7909 Object_Directory_Path :=
7910 new String'(Norm & Directory_Separator);
7913 Add_Lib_Search_Dir (Norm);
7915 -- Specify the object directory to the binder
7917 Add_Switch ("-aO" & Norm, Binder, And_Save => And_Save);
7922 -- Then check if we are dealing with -cargs/-bargs/-largs/-margs
7924 elsif Argv = "-bargs"
7933 when 'c' => Program_Args := Compiler;
7934 when 'b' => Program_Args := Binder;
7935 when 'l' => Program_Args := Linker;
7936 when 'm' => Program_Args := None;
7939 raise Program_Error;
7942 -- A special test is needed for the -o switch within a -largs since that
7943 -- is another way to specify the name of the final executable.
7945 elsif Program_Args = Linker
7946 and then Argv = "-o"
7948 Make_Failed ("switch -o not allowed within a -largs. " &
7949 "Use -o directly.");
7951 -- Check to see if we are reading switches after a -cargs, -bargs or
7952 -- -largs switch. If so, save it.
7954 elsif Program_Args /= None then
7956 -- Check to see if we are reading -I switches in order
7957 -- to take into account in the src & lib search directories.
7959 if Argv'Length > 2 and then Argv (1 .. 2) = "-I" then
7960 if Argv (3 .. Argv'Last) = "-" then
7961 Look_In_Primary_Dir := False;
7963 elsif Program_Args = Compiler then
7964 if Argv (3 .. Argv'Last) /= "-" then
7965 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7968 elsif Program_Args = Binder then
7969 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7973 Add_Switch (Argv, Program_Args, And_Save => And_Save);
7975 -- Handle non-default compiler, binder, linker, and handle --RTS switch
7977 elsif Argv'Length > 2 and then Argv (1 .. 2) = "--" then
7979 and then Argv (1 .. 6) = "--GCC="
7982 Program_Args : constant Argument_List_Access :=
7983 Argument_String_To_List
7984 (Argv (7 .. Argv'Last));
7988 Saved_Gcc := new String'(Program_Args.all (1).all);
7990 Gcc := new String'(Program_Args.all (1).all);
7993 for J in 2 .. Program_Args.all'Last loop
7995 (Program_Args.all (J).all, Compiler, And_Save => And_Save);
7999 elsif Argv'Length > 11
8000 and then Argv (1 .. 11) = "--GNATBIND="
8003 Program_Args : constant Argument_List_Access :=
8004 Argument_String_To_List
8005 (Argv (12 .. Argv'Last));
8009 Saved_Gnatbind := new String'(Program_Args.all (1).all);
8011 Gnatbind := new String'(Program_Args.all (1).all);
8014 for J in 2 .. Program_Args.all'Last loop
8016 (Program_Args.all (J).all, Binder, And_Save => And_Save);
8020 elsif Argv'Length > 11
8021 and then Argv (1 .. 11) = "--GNATLINK="
8024 Program_Args : constant Argument_List_Access :=
8025 Argument_String_To_List
8026 (Argv (12 .. Argv'Last));
8029 Saved_Gnatlink := new String'(Program_Args.all (1).all);
8031 Gnatlink := new String'(Program_Args.all (1).all);
8034 for J in 2 .. Program_Args.all'Last loop
8035 Add_Switch (Program_Args.all (J).all, Linker);
8039 elsif Argv'Length >= 5 and then
8040 Argv (1 .. 5) = "--RTS"
8042 Add_Switch (Argv, Compiler, And_Save => And_Save);
8043 Add_Switch (Argv, Binder, And_Save => And_Save);
8045 if Argv'Length <= 6 or else Argv (6) /= '=' then
8046 Make_Failed ("missing path for --RTS");
8049 -- Check that this is the first time we see this switch or
8050 -- if it is not the first time, the same path is specified.
8052 if RTS_Specified = null then
8053 RTS_Specified := new String'(Argv (7 .. Argv'Last));
8055 elsif RTS_Specified.all /= Argv (7 .. Argv'Last) then
8056 Make_Failed ("--RTS cannot be specified multiple times");
8059 -- Valid --RTS switch
8066 Src_Path_Name : constant String_Ptr :=
8068 (Argv (7 .. Argv'Last), Include);
8070 Lib_Path_Name : constant String_Ptr :=
8072 (Argv (7 .. Argv'Last), Objects);
8075 if Src_Path_Name /= null
8076 and then Lib_Path_Name /= null
8078 -- Set RTS_*_Path_Name variables, so that correct direct-
8079 -- ories will be set when Osint.Add_Default_Search_Dirs
8082 RTS_Src_Path_Name := Src_Path_Name;
8083 RTS_Lib_Path_Name := Lib_Path_Name;
8085 elsif Src_Path_Name = null
8086 and then Lib_Path_Name = null
8088 Make_Failed ("RTS path not valid: missing " &
8089 "adainclude and adalib directories");
8091 elsif Src_Path_Name = null then
8092 Make_Failed ("RTS path not valid: missing adainclude " &
8095 elsif Lib_Path_Name = null then
8096 Make_Failed ("RTS path not valid: missing adalib " &
8102 elsif Argv'Length > Source_Info_Option'Length and then
8103 Argv (1 .. Source_Info_Option'Length) = Source_Info_Option
8105 Project_Tree.Source_Info_File_Name :=
8106 new String'(Argv (Source_Info_Option'Length + 1 .. Argv'Last));
8108 elsif Argv'Length >= 8 and then
8109 Argv (1 .. 8) = "--param="
8111 Add_Switch (Argv, Compiler, And_Save => And_Save);
8112 Add_Switch (Argv, Linker, And_Save => And_Save);
8114 elsif Argv = Create_Map_File_Switch then
8115 Map_File := new String'("");
8117 elsif Argv'Length > Create_Map_File_Switch'Length + 1
8119 Argv (1 .. Create_Map_File_Switch'Length) = Create_Map_File_Switch
8121 Argv (Create_Map_File_Switch'Length + 1) = '='
8125 (Argv (Create_Map_File_Switch'Length + 2 .. Argv'Last));
8128 Scan_Make_Switches (Project_Node_Tree, Argv, Success);
8131 -- If we have seen a regular switch process it
8133 elsif Argv (1) = '-' then
8134 if Argv'Length = 1 then
8135 Make_Failed ("switch character cannot be followed by a blank");
8137 -- Incorrect switches that should start with "--"
8139 elsif (Argv'Length > 5 and then Argv (1 .. 5) = "-RTS=")
8140 or else (Argv'Length > 5 and then Argv (1 .. 5) = "-GCC=")
8141 or else (Argv'Length > 8 and then Argv (1 .. 7) = "-param=")
8142 or else (Argv'Length > 10 and then Argv (1 .. 10) = "-GNATLINK=")
8143 or else (Argv'Length > 10 and then Argv (1 .. 10) = "-GNATBIND=")
8145 Make_Failed ("option " & Argv & " should start with '--'");
8149 elsif Argv (2 .. Argv'Last) = "I-" then
8150 Look_In_Primary_Dir := False;
8152 -- Forbid -?- or -??- where ? is any character
8154 elsif (Argv'Length = 3 and then Argv (3) = '-')
8155 or else (Argv'Length = 4 and then Argv (4) = '-')
8158 ("trailing ""-"" at the end of " & Argv & " forbidden.");
8162 elsif Argv (2) = 'I' then
8163 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
8164 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
8165 Add_Switch (Argv, Compiler, And_Save => And_Save);
8166 Add_Switch (Argv, Binder, And_Save => And_Save);
8168 -- -aIdir (to gcc this is like a -I switch)
8170 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aI" then
8171 Add_Source_Search_Dir (Argv (4 .. Argv'Last), And_Save);
8173 ("-I" & Argv (4 .. Argv'Last), Compiler, And_Save => And_Save);
8174 Add_Switch (Argv, Binder, And_Save => And_Save);
8178 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aO" then
8179 Add_Library_Search_Dir (Argv (4 .. Argv'Last), And_Save);
8180 Add_Switch (Argv, Binder, And_Save => And_Save);
8182 -- -aLdir (to gnatbind this is like a -aO switch)
8184 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aL" then
8185 Mark_Directory (Argv (4 .. Argv'Last), Ada_Lib_Dir, And_Save);
8186 Add_Library_Search_Dir (Argv (4 .. Argv'Last), And_Save);
8188 ("-aO" & Argv (4 .. Argv'Last), Binder, And_Save => And_Save);
8192 elsif Argv'Length >= 13 and then Argv (2 .. 13) = "aamp_target=" then
8193 Add_Switch (Argv, Compiler, And_Save => And_Save);
8195 -- Set the aamp_target environment variable so that the binder and
8196 -- linker will use the proper target library. This is consistent
8197 -- with how things work when -aamp_target is passed on the command
8198 -- line to gnaampmake.
8200 Setenv ("aamp_target", Argv (14 .. Argv'Last));
8202 -- -Adir (to gnatbind this is like a -aO switch, to gcc like a -I)
8204 elsif Argv (2) = 'A' then
8205 Mark_Directory (Argv (3 .. Argv'Last), Ada_Lib_Dir, And_Save);
8206 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
8207 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
8209 ("-I" & Argv (3 .. Argv'Last), Compiler, And_Save => And_Save);
8211 ("-aO" & Argv (3 .. Argv'Last), Binder, And_Save => And_Save);
8215 elsif Argv (2) = 'L' then
8216 Add_Switch (Argv, Linker, And_Save => And_Save);
8218 -- For -gxxx, -pg, -mxxx, -fxxx, -Oxxx, pass the switch to both the
8219 -- compiler and the linker (except for -gnatxxx which is only for the
8220 -- compiler). Some of the -mxxx (for example -m64) and -fxxx (for
8221 -- example -ftest-coverage for gcov) need to be used when compiling
8222 -- the binder generated files, and using all these gcc switches for
8223 -- them should not be a problem. Pass -Oxxx to the linker for LTO.
8226 (Argv (2) = 'g' and then (Argv'Last < 5
8227 or else Argv (2 .. 5) /= "gnat"))
8228 or else Argv (2 .. Argv'Last) = "pg"
8229 or else (Argv (2) = 'm' and then Argv'Last > 2)
8230 or else (Argv (2) = 'f' and then Argv'Last > 2)
8231 or else Argv (2) = 'O'
8233 Add_Switch (Argv, Compiler, And_Save => And_Save);
8234 Add_Switch (Argv, Linker, And_Save => And_Save);
8236 -- The following condition has to be kept synchronized with
8237 -- the Process_Multilib one.
8240 and then Argv /= "-mieee"
8242 N_M_Switch := N_M_Switch + 1;
8245 -- -C=<mapping file>
8247 elsif Argv'Last > 2 and then Argv (2) = 'C' then
8249 if Argv (3) /= '=' or else Argv'Last <= 3 then
8250 Make_Failed ("illegal switch " & Argv);
8253 Gnatmake_Mapping_File := new String'(Argv (4 .. Argv'Last));
8258 elsif Argv'Last = 2 and then Argv (2) = 'D' then
8259 if Project_File_Name /= null then
8261 ("-D cannot be used in conjunction with a project file");
8264 Scan_Make_Switches (Project_Node_Tree, Argv, Success);
8269 elsif Argv (2) = 'd' and then Argv'Last = 2 then
8270 Display_Compilation_Progress := True;
8274 elsif Argv'Last = 2 and then Argv (2) = 'i' then
8275 if Project_File_Name /= null then
8277 ("-i cannot be used in conjunction with a project file");
8279 Scan_Make_Switches (Project_Node_Tree, Argv, Success);
8282 -- -j (need to save the result)
8284 elsif Argv (2) = 'j' then
8285 Scan_Make_Switches (Project_Node_Tree, Argv, Success);
8288 Saved_Maximum_Processes := Maximum_Processes;
8293 elsif Argv (2) = 'm' and then Argv'Last = 2 then
8294 Minimal_Recompilation := True;
8298 elsif Argv (2) = 'u' and then Argv'Last = 2 then
8299 Unique_Compile := True;
8300 Compile_Only := True;
8301 Do_Bind_Step := False;
8302 Do_Link_Step := False;
8306 elsif Argv (2) = 'U'
8307 and then Argv'Last = 2
8309 Unique_Compile_All_Projects := True;
8310 Unique_Compile := True;
8311 Compile_Only := True;
8312 Do_Bind_Step := False;
8313 Do_Link_Step := False;
8315 -- -Pprj or -P prj (only once, and only on the command line)
8317 elsif Argv (2) = 'P' then
8318 if Project_File_Name /= null then
8319 Make_Failed ("cannot have several project files specified");
8321 elsif Object_Directory_Path /= null then
8323 ("-D cannot be used in conjunction with a project file");
8325 elsif In_Place_Mode then
8327 ("-i cannot be used in conjunction with a project file");
8329 elsif not And_Save then
8331 -- It could be a tool other than gnatmake (e.g. gnatdist)
8332 -- or a -P switch inside a project file.
8335 ("either the tool is not ""project-aware"" or " &
8336 "a project file is specified inside a project file");
8338 elsif Argv'Last = 2 then
8340 -- -P is used alone: the project file name is the next option
8342 Project_File_Name_Present := True;
8345 Project_File_Name := new String'(Argv (3 .. Argv'Last));
8348 -- -vPx (verbosity of the parsing of the project files)
8351 and then Argv (2 .. 3) = "vP"
8352 and then Argv (4) in '0' .. '2'
8357 Current_Verbosity := Prj.Default;
8359 Current_Verbosity := Prj.Medium;
8361 Current_Verbosity := Prj.High;
8367 -- -Xext=val (External assignment)
8369 elsif Argv (2) = 'X'
8370 and then Is_External_Assignment (Project_Node_Tree, Argv)
8372 -- Is_External_Assignment has side effects when it returns True
8376 -- If -gnath is present, then generate the usage information right
8377 -- now and do not pass this option on to the compiler calls.
8379 elsif Argv = "-gnath" then
8382 -- If -gnatc is specified, make sure the bind and link steps are not
8385 elsif Argv'Length >= 6 and then Argv (2 .. 6) = "gnatc" then
8387 -- If -gnatc is specified, make sure the bind and link steps are
8390 Add_Switch (Argv, Compiler, And_Save => And_Save);
8391 Operating_Mode := Check_Semantics;
8392 Check_Object_Consistency := False;
8393 Compile_Only := True;
8394 Do_Bind_Step := False;
8395 Do_Link_Step := False;
8397 elsif Argv (2 .. Argv'Last) = "nostdlib" then
8399 -- Pass -nstdlib to gnatbind and gnatlink
8402 Add_Switch (Argv, Binder, And_Save => And_Save);
8403 Add_Switch (Argv, Linker, And_Save => And_Save);
8405 elsif Argv (2 .. Argv'Last) = "nostdinc" then
8407 -- Pass -nostdinc to the Compiler and to gnatbind
8410 Add_Switch (Argv, Compiler, And_Save => And_Save);
8411 Add_Switch (Argv, Binder, And_Save => And_Save);
8413 -- All other switches are processed by Scan_Make_Switches. If the
8414 -- call returns with Gnatmake_Switch_Found = False, then the switch
8415 -- is passed to the compiler.
8419 (Project_Node_Tree, Argv, Gnatmake_Switch_Found);
8421 if not Gnatmake_Switch_Found then
8422 Add_Switch (Argv, Compiler, And_Save => And_Save);
8426 -- If not a switch it must be a file name
8430 Main_On_Command_Line := True;
8434 Mains.Add_Main (Argv);
8442 function Switches_Of
8443 (Source_File : File_Name_Type;
8444 Source_File_Name : String;
8446 Project : Project_Id;
8447 In_Package : Package_Id;
8448 Allow_ALI : Boolean) return Variable_Value
8450 Lang : constant Language_Ptr := Get_Language_From_Name (Project, "ada");
8452 Switches : Variable_Value;
8454 Defaults : constant Array_Element_Id :=
8456 (Name => Name_Default_Switches,
8458 Project_Tree.Packages.Table
8459 (In_Package).Decl.Arrays,
8460 In_Tree => Project_Tree);
8462 Switches_Array : constant Array_Element_Id :=
8464 (Name => Name_Switches,
8466 Project_Tree.Packages.Table
8467 (In_Package).Decl.Arrays,
8468 In_Tree => Project_Tree);
8471 -- First, try Switches (<file name>)
8475 (Index => Name_Id (Source_File),
8476 Src_Index => Source_Index,
8477 In_Array => Switches_Array,
8478 In_Tree => Project_Tree,
8479 Allow_Wildcards => True);
8481 -- Check also without the suffix
8483 if Switches = Nil_Variable_Value
8484 and then Lang /= null
8487 Naming : Lang_Naming_Data renames Lang.Config.Naming_Data;
8488 Name : String (1 .. Source_File_Name'Length + 3);
8489 Last : Positive := Source_File_Name'Length;
8490 Spec_Suffix : String := Get_Name_String (Naming.Spec_Suffix);
8491 Body_Suffix : String := Get_Name_String (Naming.Body_Suffix);
8492 Truncated : Boolean := False;
8495 Canonical_Case_File_Name (Spec_Suffix);
8496 Canonical_Case_File_Name (Body_Suffix);
8497 Name (1 .. Last) := Source_File_Name;
8499 if Last > Body_Suffix'Length
8500 and then Name (Last - Body_Suffix'Length + 1 .. Last) =
8504 Last := Last - Body_Suffix'Length;
8508 and then Last > Spec_Suffix'Length
8509 and then Name (Last - Spec_Suffix'Length + 1 .. Last) =
8513 Last := Last - Spec_Suffix'Length;
8518 Add_Str_To_Name_Buffer (Name (1 .. Last));
8521 (Index => Name_Find,
8523 In_Array => Switches_Array,
8524 In_Tree => Project_Tree,
8525 Allow_Wildcards => True);
8527 if Switches = Nil_Variable_Value and then Allow_ALI then
8528 Last := Source_File_Name'Length;
8530 while Name (Last) /= '.' loop
8535 Add_Str_To_Name_Buffer (Name (1 .. Last));
8536 Add_Str_To_Name_Buffer ("ali");
8540 (Index => Name_Find,
8542 In_Array => Switches_Array,
8543 In_Tree => Project_Tree);
8549 -- Next, try Switches ("Ada")
8551 if Switches = Nil_Variable_Value then
8556 In_Array => Switches_Array,
8557 In_Tree => Project_Tree,
8558 Force_Lower_Case_Index => True);
8560 if Switches /= Nil_Variable_Value then
8561 Switch_May_Be_Passed_To_The_Compiler := False;
8565 -- Next, try Switches (others)
8567 if Switches = Nil_Variable_Value then
8570 (Index => All_Other_Names,
8572 In_Array => Switches_Array,
8573 In_Tree => Project_Tree);
8575 if Switches /= Nil_Variable_Value then
8576 Switch_May_Be_Passed_To_The_Compiler := False;
8580 -- And finally, Default_Switches ("Ada")
8582 if Switches = Nil_Variable_Value then
8587 In_Array => Defaults,
8588 In_Tree => Project_Tree);
8600 if Usage_Needed then
8601 Usage_Needed := False;
8607 -- Make sure that in case of failure, the temp files will be deleted
8609 Prj.Com.Fail := Make_Failed'Access;
8610 MLib.Fail := Make_Failed'Access;
8611 Makeutl.Do_Fail := Make_Failed'Access;