1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
27 with ALI.Util; use ALI.Util;
32 with Fname; use Fname;
33 with Fname.SF; use Fname.SF;
34 with Fname.UF; use Fname.UF;
35 with Gnatvsn; use Gnatvsn;
36 with Hostparm; use Hostparm;
38 with Makeutl; use Makeutl;
41 with MLib.Tgt; use MLib.Tgt;
43 with Namet; use Namet;
45 with Osint.M; use Osint.M;
46 with Osint; use Osint;
47 with Output; use Output;
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;
74 with GNAT.Case_Util; use GNAT.Case_Util;
75 with GNAT.OS_Lib; use GNAT.OS_Lib;
80 -- Make control characters visible
82 Standard_Library_Package_Body_Name : constant String := "s-stalib.adb";
83 -- Every program depends on this package, that must then be checked,
84 -- especially when -f and -a are used.
86 procedure Kill (Pid : Process_Id; Sig_Num : Integer; Close : Integer);
87 pragma Import (C, Kill, "__gnat_kill");
88 -- Called by Sigint_Intercepted to kill all spawned compilation processes
90 type Sigint_Handler is access procedure;
91 pragma Convention (C, Sigint_Handler);
93 procedure Install_Int_Handler (Handler : Sigint_Handler);
94 pragma Import (C, Install_Int_Handler, "__gnat_install_int_handler");
95 -- Called by Gnatmake to install the SIGINT handler below
97 procedure Sigint_Intercepted;
98 pragma Convention (C, Sigint_Intercepted);
99 -- Called when the program is interrupted by Ctrl-C to delete the
100 -- temporary mapping files and configuration pragmas files.
102 No_Mapping_File : constant Natural := 0;
104 type Compilation_Data is record
106 Full_Source_File : File_Name_Type;
107 Lib_File : File_Name_Type;
108 Source_Unit : Unit_Name_Type;
109 Full_Lib_File : File_Name_Type;
110 Lib_File_Attr : aliased File_Attributes;
111 Mapping_File : Natural := No_Mapping_File;
112 Project : Project_Id := No_Project;
114 -- Data recorded for each compilation process spawned
116 No_Compilation_Data : constant Compilation_Data :=
117 (Invalid_Pid, No_File, No_File, No_Unit_Name, No_File, Unknown_Attributes,
118 No_Mapping_File, No_Project);
120 type Comp_Data_Arr is array (Positive range <>) of Compilation_Data;
121 type Comp_Data_Ptr is access Comp_Data_Arr;
122 Running_Compile : Comp_Data_Ptr;
123 -- Used to save information about outstanding compilations
125 Outstanding_Compiles : Natural := 0;
126 -- Current number of outstanding compiles
128 -------------------------
129 -- Note on terminology --
130 -------------------------
132 -- In this program, we use the phrase "termination" of a file name to refer
133 -- to the suffix that appears after the unit name portion. Very often this
134 -- is simply the extension, but in some cases, the sequence may be more
135 -- complex, for example in main.1.ada, the termination in this name is
136 -- ".1.ada" and in main_.ada the termination is "_.ada".
138 -------------------------------------
139 -- Queue (Q) Manipulation Routines --
140 -------------------------------------
142 -- The Q is used in Compile_Sources below. Its implementation uses the GNAT
143 -- generic package Table (basically an extensible array). Q_Front points to
144 -- the first valid element in the Q, whereas Q.First is the first element
145 -- ever enqueued, while Q.Last - 1 is the last element in the Q.
147 -- +---+--------------+---+---+---+-----------+---+--------
148 -- Q | | ........ | | | | ....... | |
149 -- +---+--------------+---+---+---+-----------+---+--------
151 -- Q.First Q_Front Q.Last-1
153 -- The elements comprised between Q.First and Q_Front-1 are the elements
154 -- that have been enqueued and then dequeued, while the elements between
155 -- Q_Front and Q.Last-1 are the elements currently in the Q. When the Q
156 -- is initialized Q_Front = Q.First = Q.Last. After Compile_Sources has
157 -- terminated its execution, Q_Front = Q.Last and the elements contained
158 -- between Q.First and Q.Last-1 are those that were explored and thus
159 -- marked by Compile_Sources. Whenever the Q is reinitialized, the elements
160 -- between Q.First and Q.Last-1 are unmarked.
163 -- Must be called to (re)initialize the Q
166 (Source_File : File_Name_Type;
167 Source_Unit : Unit_Name_Type := No_Unit_Name;
169 -- Inserts Source_File at the end of Q. Provide Source_Unit when possible
170 -- for external use (gnatdist). Provide index for multi-unit sources.
172 function Empty_Q return Boolean;
173 -- Returns True if Q is empty
175 procedure Extract_From_Q
176 (Source_File : out File_Name_Type;
177 Source_Unit : out Unit_Name_Type;
178 Source_Index : out Int);
179 -- Extracts the first element from the Q
181 procedure Insert_Project_Sources
182 (The_Project : Project_Id;
183 All_Projects : Boolean;
185 -- If Into_Q is True, insert all sources of the project file(s) that are
186 -- not already marked into the Q. If Into_Q is False, call Osint.Add_File
187 -- for the first source, then insert all other sources that are not already
188 -- marked into the Q. If All_Projects is True, all sources of all projects
189 -- are concerned; otherwise, only sources of The_Project are concerned,
190 -- including, if The_Project is an extending project, sources inherited
191 -- from projects being extended.
193 First_Q_Initialization : Boolean := True;
194 -- Will be set to false after Init_Q has been called once
197 -- Points to the first valid element in the Q
199 Unique_Compile : Boolean := False;
200 -- Set to True if -u or -U or a project file with no main is used
202 Unique_Compile_All_Projects : Boolean := False;
203 -- Set to True if -U is used
205 RTS_Specified : String_Access := null;
206 -- Used to detect multiple --RTS= switches
208 N_M_Switch : Natural := 0;
209 -- Used to count -mxxx switches that can affect multilib
211 type Q_Record is record
212 File : File_Name_Type;
213 Unit : Unit_Name_Type;
216 -- File is the name of the file to compile. Unit is for gnatdist
217 -- use in order to easily get the unit name of a file to compile
218 -- when its name is krunched or declared in gnat.adc. Index, when not 0,
219 -- is the index of the unit in a multi-unit source.
221 package Q is new Table.Table (
222 Table_Component_Type => Q_Record,
223 Table_Index_Type => Natural,
224 Table_Low_Bound => 0,
225 Table_Initial => 4000,
226 Table_Increment => 100,
227 Table_Name => "Make.Q");
228 -- This is the actual Q
230 -- The 3 following packages are used to store gcc, gnatbind and gnatlink
231 -- switches found in the project files.
233 package Gcc_Switches is new Table.Table (
234 Table_Component_Type => String_Access,
235 Table_Index_Type => Integer,
236 Table_Low_Bound => 1,
238 Table_Increment => 100,
239 Table_Name => "Make.Gcc_Switches");
241 package Binder_Switches is new Table.Table (
242 Table_Component_Type => String_Access,
243 Table_Index_Type => Integer,
244 Table_Low_Bound => 1,
246 Table_Increment => 100,
247 Table_Name => "Make.Binder_Switches");
249 package Linker_Switches is new Table.Table (
250 Table_Component_Type => String_Access,
251 Table_Index_Type => Integer,
252 Table_Low_Bound => 1,
254 Table_Increment => 100,
255 Table_Name => "Make.Linker_Switches");
257 -- The following instantiations and variables are necessary to save what
258 -- is found on the command line, in case there is a project file specified.
260 package Saved_Gcc_Switches is new Table.Table (
261 Table_Component_Type => String_Access,
262 Table_Index_Type => Integer,
263 Table_Low_Bound => 1,
265 Table_Increment => 100,
266 Table_Name => "Make.Saved_Gcc_Switches");
268 package Saved_Binder_Switches is new Table.Table (
269 Table_Component_Type => String_Access,
270 Table_Index_Type => Integer,
271 Table_Low_Bound => 1,
273 Table_Increment => 100,
274 Table_Name => "Make.Saved_Binder_Switches");
276 package Saved_Linker_Switches is new Table.Table
277 (Table_Component_Type => String_Access,
278 Table_Index_Type => Integer,
279 Table_Low_Bound => 1,
281 Table_Increment => 100,
282 Table_Name => "Make.Saved_Linker_Switches");
284 package Switches_To_Check is new Table.Table (
285 Table_Component_Type => String_Access,
286 Table_Index_Type => Integer,
287 Table_Low_Bound => 1,
289 Table_Increment => 100,
290 Table_Name => "Make.Switches_To_Check");
292 package Library_Paths is new Table.Table (
293 Table_Component_Type => String_Access,
294 Table_Index_Type => Integer,
295 Table_Low_Bound => 1,
297 Table_Increment => 100,
298 Table_Name => "Make.Library_Paths");
300 package Failed_Links is new Table.Table (
301 Table_Component_Type => File_Name_Type,
302 Table_Index_Type => Integer,
303 Table_Low_Bound => 1,
305 Table_Increment => 100,
306 Table_Name => "Make.Failed_Links");
308 package Successful_Links is new Table.Table (
309 Table_Component_Type => File_Name_Type,
310 Table_Index_Type => Integer,
311 Table_Low_Bound => 1,
313 Table_Increment => 100,
314 Table_Name => "Make.Successful_Links");
316 package Library_Projs is new Table.Table (
317 Table_Component_Type => Project_Id,
318 Table_Index_Type => Integer,
319 Table_Low_Bound => 1,
321 Table_Increment => 100,
322 Table_Name => "Make.Library_Projs");
324 -- Two variables to keep the last binder and linker switch index in tables
325 -- Binder_Switches and Linker_Switches, before adding switches from the
326 -- project file (if any) and switches from the command line (if any).
328 Last_Binder_Switch : Integer := 0;
329 Last_Linker_Switch : Integer := 0;
331 Normalized_Switches : Argument_List_Access := new Argument_List (1 .. 10);
332 Last_Norm_Switch : Natural := 0;
334 Saved_Maximum_Processes : Natural := 0;
336 Gnatmake_Switch_Found : Boolean;
337 -- Set by Scan_Make_Arg. True when the switch is a gnatmake switch.
338 -- Tested by Add_Switches when switches in package Builder must all be
339 -- gnatmake switches.
341 Switch_May_Be_Passed_To_The_Compiler : Boolean;
342 -- Set by Add_Switches and Switches_Of. True when unrecognized switches
343 -- are passed to the Ada compiler.
345 type Arg_List_Ref is access Argument_List;
346 The_Saved_Gcc_Switches : Arg_List_Ref;
348 Project_File_Name : String_Access := null;
349 -- The path name of the main project file, if any
351 Project_File_Name_Present : Boolean := False;
352 -- True when -P is used with a space between -P and the project file name
354 Current_Verbosity : Prj.Verbosity := Prj.Default;
355 -- Verbosity to parse the project files
357 Main_Project : Prj.Project_Id := No_Project;
358 -- The project id of the main project file, if any
360 Project_Of_Current_Object_Directory : Project_Id := No_Project;
361 -- The object directory of the project for the last compilation. Avoid
362 -- calling Change_Dir if the current working directory is already this
365 -- Packages of project files where unknown attributes are errors
367 Naming_String : aliased String := "naming";
368 Builder_String : aliased String := "builder";
369 Compiler_String : aliased String := "compiler";
370 Binder_String : aliased String := "binder";
371 Linker_String : aliased String := "linker";
373 Gnatmake_Packages : aliased String_List :=
374 (Naming_String 'Access,
375 Builder_String 'Access,
376 Compiler_String 'Access,
377 Binder_String 'Access,
378 Linker_String 'Access);
380 Packages_To_Check_By_Gnatmake : constant String_List_Access :=
381 Gnatmake_Packages'Access;
383 procedure Add_Library_Search_Dir
385 On_Command_Line : Boolean);
386 -- Call Add_Lib_Search_Dir with an absolute directory path. If Path is
387 -- relative path, when On_Command_Line is True, it is relative to the
388 -- current working directory. When On_Command_Line is False, it is relative
389 -- to the project directory of the main project.
391 procedure Add_Source_Search_Dir
393 On_Command_Line : Boolean);
394 -- Call Add_Src_Search_Dir with an absolute directory path. If Path is a
395 -- relative path, when On_Command_Line is True, it is relative to the
396 -- current working directory. When On_Command_Line is False, it is relative
397 -- to the project directory of the main project.
399 procedure Add_Source_Dir (N : String);
400 -- Call Add_Src_Search_Dir (output one line when in verbose mode)
402 procedure Add_Source_Directories is
403 new Prj.Env.For_All_Source_Dirs (Action => Add_Source_Dir);
405 procedure Add_Object_Dir (N : String);
406 -- Call Add_Lib_Search_Dir (output one line when in verbose mode)
408 procedure Add_Object_Directories is
409 new Prj.Env.For_All_Object_Dirs (Action => Add_Object_Dir);
411 procedure Change_To_Object_Directory (Project : Project_Id);
412 -- Change to the object directory of project Project, if this is not
413 -- already the current working directory.
415 type Bad_Compilation_Info is record
416 File : File_Name_Type;
417 Unit : Unit_Name_Type;
420 -- File is the name of the file for which a compilation failed. Unit is for
421 -- gnatdist use in order to easily get the unit name of a file when its
422 -- name is krunched or declared in gnat.adc. Found is False if the
423 -- compilation failed because the file could not be found.
425 package Bad_Compilation is new Table.Table (
426 Table_Component_Type => Bad_Compilation_Info,
427 Table_Index_Type => Natural,
428 Table_Low_Bound => 1,
430 Table_Increment => 100,
431 Table_Name => "Make.Bad_Compilation");
432 -- Full name of all the source files for which compilation fails
434 Do_Compile_Step : Boolean := True;
435 Do_Bind_Step : Boolean := True;
436 Do_Link_Step : Boolean := True;
437 -- Flags to indicate what step should be executed. Can be set to False
438 -- with the switches -c, -b and -l. These flags are reset to True for
439 -- each invocation of procedure Gnatmake.
441 Shared_String : aliased String := "-shared";
442 Force_Elab_Flags_String : aliased String := "-F";
444 No_Shared_Switch : aliased Argument_List := (1 .. 0 => null);
445 Shared_Switch : aliased Argument_List := (1 => Shared_String'Access);
446 Bind_Shared : Argument_List_Access := No_Shared_Switch'Access;
447 -- Switch to added in front of gnatbind switches. By default no switch is
448 -- added. Switch "-shared" is added if there is a non-static Library
451 Shared_Libgcc : aliased String := "-shared-libgcc";
453 No_Shared_Libgcc_Switch : aliased Argument_List := (1 .. 0 => null);
454 Shared_Libgcc_Switch : aliased Argument_List :=
455 (1 => Shared_Libgcc'Access);
456 Link_With_Shared_Libgcc : Argument_List_Access :=
457 No_Shared_Libgcc_Switch'Access;
459 procedure Make_Failed (S : String);
460 -- Delete all temp files created by Gnatmake and call Osint.Fail, with the
461 -- parameter S (see osint.ads). This is called from the Prj hierarchy and
462 -- the MLib hierarchy.
464 --------------------------
465 -- Obsolete Executables --
466 --------------------------
468 Executable_Obsolete : Boolean := False;
469 -- Executable_Obsolete is initially set to False for each executable,
470 -- and is set to True whenever one of the source of the executable is
471 -- compiled, or has already been compiled for another executable.
473 Max_Header : constant := 200;
474 -- This needs a proper comment, it used to say "arbitrary"
475 -- that's not an adequate comment ???
477 type Header_Num is range 1 .. Max_Header;
478 -- Header_Num for the hash table Obsoleted below
480 function Hash (F : File_Name_Type) return Header_Num;
481 -- Hash function for the hash table Obsoleted below
483 package Obsoleted is new System.HTable.Simple_HTable
484 (Header_Num => Header_Num,
487 Key => File_Name_Type,
490 -- A hash table to keep all files that have been compiled, to detect
491 -- if an executable is up to date or not.
493 procedure Enter_Into_Obsoleted (F : File_Name_Type);
494 -- Enter a file name, without directory information, into the hash table
497 function Is_In_Obsoleted (F : File_Name_Type) return Boolean;
498 -- Check if a file name, without directory information, has already been
499 -- entered into the hash table Obsoleted.
501 type Dependency is record
502 This : File_Name_Type;
503 Depends_On : File_Name_Type;
505 -- Components of table Dependencies below
507 package Dependencies is new Table.Table (
508 Table_Component_Type => Dependency,
509 Table_Index_Type => Integer,
510 Table_Low_Bound => 1,
512 Table_Increment => 100,
513 Table_Name => "Make.Dependencies");
514 -- A table to keep dependencies, to be able to decide if an executable
515 -- is obsolete. More explanation needed ???
517 -- procedure Add_Dependency (S : File_Name_Type; On : File_Name_Type);
518 -- -- Add one entry in table Dependencies
520 ----------------------------
521 -- Arguments and Switches --
522 ----------------------------
524 Arguments : Argument_List_Access;
525 -- Used to gather the arguments for invocation of the compiler
527 Last_Argument : Natural := 0;
528 -- Last index of arguments in Arguments above
530 Arguments_Project : Project_Id;
531 -- Project id, if any, of the source to be compiled
533 Arguments_Path_Name : Path_Name_Type;
534 -- Full path of the source to be compiled, when Arguments_Project is not
537 Dummy_Switch : constant String_Access := new String'("- ");
538 -- Used to initialized Prev_Switch in procedure Check
540 procedure Add_Arguments (Args : Argument_List);
541 -- Add arguments to global variable Arguments, increasing its size
542 -- if necessary and adjusting Last_Argument.
544 function Configuration_Pragmas_Switch
545 (For_Project : Project_Id) return Argument_List;
546 -- Return an argument list of one element, if there is a configuration
547 -- pragmas file to be specified for For_Project,
548 -- otherwise return an empty argument list.
554 procedure List_Depend;
555 -- Prints to standard output the list of object dependencies. This list
556 -- can be used directly in a Makefile. A call to Compile_Sources must
557 -- precede the call to List_Depend. Also because this routine uses the
558 -- ALI files that were originally loaded and scanned by Compile_Sources,
559 -- no additional ALI files should be scanned between the two calls (i.e.
560 -- between the call to Compile_Sources and List_Depend.)
562 procedure List_Bad_Compilations;
563 -- Prints out the list of all files for which the compilation failed
565 Usage_Needed : Boolean := True;
566 -- Flag used to make sure Makeusg is call at most once
569 -- Call Makeusg, if Usage_Needed is True.
570 -- Set Usage_Needed to False.
572 procedure Debug_Msg (S : String; N : Name_Id);
573 procedure Debug_Msg (S : String; N : File_Name_Type);
574 procedure Debug_Msg (S : String; N : Unit_Name_Type);
575 -- If Debug.Debug_Flag_W is set outputs string S followed by name N
577 procedure Recursive_Compute_Depth (Project : Project_Id);
578 -- Compute depth of Project and of the projects it depends on
580 -----------------------
581 -- Gnatmake Routines --
582 -----------------------
584 subtype Lib_Mark_Type is Byte;
585 -- Used in Mark_Directory
587 Ada_Lib_Dir : constant Lib_Mark_Type := 1;
588 -- Used to mark a directory as a GNAT lib dir
590 -- Note that the notion of GNAT lib dir is no longer used. The code related
591 -- to it has not been removed to give an idea on how to use the directory
592 -- prefix marking mechanism.
594 -- An Ada library directory is a directory containing ali and object files
595 -- but no source files for the bodies (the specs can be in the same or some
596 -- other directory). These directories are specified in the Gnatmake
597 -- command line with the switch "-Adir" (to specify the spec location -Idir
598 -- cab be used). Gnatmake skips the missing sources whose ali are in Ada
599 -- library directories. For an explanation of why Gnatmake behaves that
600 -- way, see the spec of Make.Compile_Sources. The directory lookup penalty
601 -- is incurred every single time this routine is called.
603 procedure Check_Steps;
604 -- Check what steps (Compile, Bind, Link) must be executed.
605 -- Set the step flags accordingly.
607 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean;
608 -- Get directory prefix of this file and get lib mark stored in name
609 -- table for this directory. Then check if an Ada lib mark has been set.
611 procedure Mark_Directory
613 Mark : Lib_Mark_Type;
614 On_Command_Line : Boolean);
615 -- Store the absolute path from Dir in name table and set lib mark as name
616 -- info to identify Ada libraries.
618 -- If Dir is a relative path, when On_Command_Line is True, it is relative
619 -- to the current working directory; when On_Command_Line is False, it is
620 -- relative to the project directory of the main project.
622 Output_Is_Object : Boolean := True;
623 -- Set to False when using a switch -S for the compiler
625 procedure Check_For_S_Switch;
626 -- Set Output_Is_Object to False when the -S switch is used for the
630 (Source_File : File_Name_Type;
631 Source_File_Name : String;
633 Project : Project_Id;
634 In_Package : Package_Id;
635 Allow_ALI : Boolean) return Variable_Value;
636 -- Return the switches for the source file in the specified package of a
637 -- project file. If the Source_File ends with a standard GNAT extension
638 -- (".ads" or ".adb"), try first the full name, then the name without the
639 -- extension, then, if Allow_ALI is True, the name with the extension
640 -- ".ali". If there is no switches for either names, try first Switches
641 -- (others) then the default switches for Ada. If all failed, return
642 -- No_Variable_Value.
644 function Is_In_Object_Directory
645 (Source_File : File_Name_Type;
646 Full_Lib_File : File_Name_Type) return Boolean;
647 -- Check if, when using a project file, the ALI file is in the project
648 -- directory of the ultimate extending project. If it is not, we ignore
649 -- the fact that this ALI file is read-only.
651 procedure Process_Multilib (Project_Node_Tree : Project_Node_Tree_Ref);
652 -- Add appropriate --RTS argument to handle multilib
654 ----------------------------------------------------
655 -- Compiler, Binder & Linker Data and Subprograms --
656 ----------------------------------------------------
658 Gcc : String_Access := Program_Name ("gcc", "gnatmake");
659 Gnatbind : String_Access := Program_Name ("gnatbind", "gnatmake");
660 Gnatlink : String_Access := Program_Name ("gnatlink", "gnatmake");
661 -- Default compiler, binder, linker programs
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 Comp_Flag : constant String_Access := new String'("-c");
678 Output_Flag : constant String_Access := new String'("-o");
679 Ada_Flag_1 : constant String_Access := new String'("-x");
680 Ada_Flag_2 : constant String_Access := new String'("ada");
681 No_gnat_adc : constant String_Access := new String'("-gnatA");
682 GNAT_Flag : constant String_Access := new String'("-gnatpg");
683 Do_Not_Check_Flag : constant String_Access := new String'("-x");
685 Object_Suffix : constant String := Get_Target_Object_Suffix.all;
687 Syntax_Only : Boolean := False;
688 -- Set to True when compiling with -gnats
690 Display_Executed_Programs : Boolean := True;
691 -- Set to True if name of commands should be output on stderr (or on stdout
692 -- if the Commands_To_Stdout flag was set by use of the -eS switch).
694 Output_File_Name_Seen : Boolean := False;
695 -- Set to True after having scanned the file_name for
696 -- switch "-o file_name"
698 Object_Directory_Seen : Boolean := False;
699 -- Set to True after having scanned the object directory for
700 -- switch "-D obj_dir".
702 Object_Directory_Path : String_Access := null;
703 -- The path name of the object directory, set with switch -D
705 type Make_Program_Type is (None, Compiler, Binder, Linker);
707 Program_Args : Make_Program_Type := None;
708 -- Used to indicate if we are scanning gnatmake, gcc, gnatbind, or gnatbind
709 -- options within the gnatmake command line. Used in Scan_Make_Arg only,
710 -- but must be global since value preserved from one call to another.
712 Temporary_Config_File : Boolean := False;
713 -- Set to True when there is a temporary config file used for a project
714 -- file, to avoid displaying the -gnatec switch for a temporary file.
716 procedure Add_Switches
717 (The_Package : Package_Id;
720 Program : Make_Program_Type;
721 Unknown_Switches_To_The_Compiler : Boolean := True;
722 Project_Node_Tree : Project_Node_Tree_Ref);
725 Program : Make_Program_Type;
726 Append_Switch : Boolean := True;
727 And_Save : Boolean := True);
730 Program : Make_Program_Type;
731 Append_Switch : Boolean := True;
732 And_Save : Boolean := True);
733 -- Make invokes one of three programs (the compiler, the binder or the
734 -- linker). For the sake of convenience, some program specific switches
735 -- can be passed directly on the gnatmake command line. This procedure
736 -- records these switches so that gnatmake can pass them to the right
737 -- program. S is the switch to be added at the end of the command line
738 -- for Program if Append_Switch is True. If Append_Switch is False S is
739 -- added at the beginning of the command line.
742 (Source_File : File_Name_Type;
744 Is_Main_Source : Boolean;
745 The_Args : Argument_List;
746 Lib_File : File_Name_Type;
747 Full_Lib_File : File_Name_Type;
748 Lib_File_Attr : access File_Attributes;
751 O_File : out File_Name_Type;
752 O_Stamp : out Time_Stamp_Type);
753 -- Determines whether the library file Lib_File is up-to-date or not. The
754 -- full name (with path information) of the object file corresponding to
755 -- Lib_File is returned in O_File. Its time stamp is saved in O_Stamp.
756 -- ALI is the ALI_Id corresponding to Lib_File. If Lib_File in not
757 -- up-to-date, then the corresponding source file needs to be recompiled.
758 -- In this case ALI = No_ALI_Id.
759 -- Full_Lib_File must be the result of calling Osint.Full_Lib_File_Name on
760 -- Lib_File. Precomputing it saves system calls. Lib_File_Attr is the
761 -- initialized attributes of that file, which is also used to save on
762 -- system calls (it can safely be initialized to Unknown_Attributes).
764 procedure Check_Linker_Options
765 (E_Stamp : Time_Stamp_Type;
766 O_File : out File_Name_Type;
767 O_Stamp : out Time_Stamp_Type);
768 -- Checks all linker options for linker files that are newer
769 -- than E_Stamp. If such objects are found, the youngest object
770 -- is returned in O_File and its stamp in O_Stamp.
772 -- If no obsolete linker files were found, the first missing
773 -- linker file is returned in O_File and O_Stamp is empty.
774 -- Otherwise O_File is No_File.
776 procedure Collect_Arguments
777 (Source_File : File_Name_Type;
779 Is_Main_Source : Boolean;
780 Args : Argument_List);
781 -- Collect all arguments for a source to be compiled, including those
782 -- that come from a project file.
784 procedure Display (Program : String; Args : Argument_List);
785 -- Displays Program followed by the arguments in Args if variable
786 -- Display_Executed_Programs is set. The lower bound of Args must be 1.
788 procedure Report_Compilation_Failed;
789 -- Delete all temporary files and fail graciously
795 type Temp_Path_Names is array (Positive range <>) of Path_Name_Type;
796 type Temp_Path_Ptr is access Temp_Path_Names;
798 type Free_File_Indices is array (Positive range <>) of Positive;
799 type Free_Indices_Ptr is access Free_File_Indices;
801 type Project_Compilation_Data is record
802 Mapping_File_Names : Temp_Path_Ptr;
803 -- The name ids of the temporary mapping files used. This is indexed
804 -- on the maximum number of compilation processes we will be spawning
807 Last_Mapping_File_Names : Natural;
808 -- Index of the last mapping file created for this project
810 Free_Mapping_File_Indices : Free_Indices_Ptr;
811 -- Indices in Mapping_File_Names of the mapping file names that can be
812 -- reused for subsequent compilations.
814 Last_Free_Indices : Natural;
815 -- Number of mapping files that can be reused
817 -- Information necessary when compiling a project
819 type Project_Compilation_Access is access Project_Compilation_Data;
821 package Project_Compilation_Htable is new Simple_HTable
822 (Header_Num => Prj.Header_Num,
823 Element => Project_Compilation_Access,
829 Project_Compilation : Project_Compilation_Htable.Instance;
831 Gnatmake_Mapping_File : String_Access := null;
832 -- The path name of a mapping file specified by switch -C=
834 procedure Init_Mapping_File
835 (Project : Project_Id;
836 Data : in out Project_Compilation_Data;
837 File_Index : in out Natural);
838 -- Create a new temporary mapping file, and fill it with the project file
839 -- mappings, when using project file(s). The out parameter File_Index is
840 -- the index to the name of the file in the array The_Mapping_File_Names.
842 procedure Delete_Temp_Config_Files;
843 -- Delete all temporary config files. Must not be called if Debug_Flag_N
846 procedure Delete_All_Temp_Files;
847 -- Delete all temp files (config files, mapping files, path files), unless
848 -- Debug_Flag_N is True (in which case all temp files are left for user
851 -------------------------------------------------
852 -- Subprogram declarations moved from the spec --
853 -------------------------------------------------
855 procedure Bind (ALI_File : File_Name_Type; Args : Argument_List);
856 -- Binds ALI_File. Args are the arguments to pass to the binder.
857 -- Args must have a lower bound of 1.
859 procedure Display_Commands (Display : Boolean := True);
860 -- The default behavior of Make commands (Compile_Sources, Bind, Link)
861 -- is to display them on stderr. This behavior can be changed repeatedly
862 -- by invoking this procedure.
864 -- If a compilation, bind or link failed one of the following 3 exceptions
865 -- is raised. These need to be handled by the calling routines.
867 procedure Compile_Sources
868 (Main_Source : File_Name_Type;
869 Args : Argument_List;
870 First_Compiled_File : out File_Name_Type;
871 Most_Recent_Obj_File : out File_Name_Type;
872 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
873 Main_Unit : out Boolean;
874 Compilation_Failures : out Natural;
875 Main_Index : Int := 0;
876 Check_Readonly_Files : Boolean := False;
877 Do_Not_Execute : Boolean := False;
878 Force_Compilations : Boolean := False;
879 Keep_Going : Boolean := False;
880 In_Place_Mode : Boolean := False;
881 Initialize_ALI_Data : Boolean := True;
882 Max_Process : Positive := 1);
883 -- Compile_Sources will recursively compile all the sources needed by
884 -- Main_Source. Before calling this routine make sure Namet has been
885 -- initialized. This routine can be called repeatedly with different
886 -- Main_Source file as long as all the source (-I flags), library
887 -- (-B flags) and ada library (-A flags) search paths between calls are
888 -- *exactly* the same. The default directory must also be the same.
890 -- Args contains the arguments to use during the compilations.
891 -- The lower bound of Args must be 1.
893 -- First_Compiled_File is set to the name of the first file that is
894 -- compiled or that needs to be compiled. This is set to No_Name if no
895 -- compilations were needed.
897 -- Most_Recent_Obj_File is set to the full name of the most recent
898 -- object file found when no compilations are needed, that is when
899 -- First_Compiled_File is set to No_Name. When First_Compiled_File
900 -- is set then Most_Recent_Obj_File is set to No_Name.
902 -- Most_Recent_Obj_Stamp is the time stamp of Most_Recent_Obj_File.
904 -- Main_Unit is set to True if Main_Source can be a main unit.
905 -- If Do_Not_Execute is False and First_Compiled_File /= No_Name
906 -- the value of Main_Unit is always False.
907 -- Is this used any more??? It is certainly not used by gnatmake???
909 -- Compilation_Failures is a count of compilation failures. This count
910 -- is used to extract compilation failure reports with Extract_Failure.
912 -- Main_Index, when not zero, is the index of the main unit in source
913 -- file Main_Source which is a multi-unit source.
914 -- Zero indicates that Main_Source is a single unit source file.
916 -- Check_Readonly_Files set it to True to compile source files
917 -- which library files are read-only. When compiling GNAT predefined
918 -- files the "-gnatg" flag is used.
920 -- Do_Not_Execute set it to True to find out the first source that
921 -- needs to be recompiled, but without recompiling it. This file is
922 -- saved in First_Compiled_File.
924 -- Force_Compilations forces all compilations no matter what but
925 -- recompiles read-only files only if Check_Readonly_Files
928 -- Keep_Going when True keep compiling even in the presence of
929 -- compilation errors.
931 -- In_Place_Mode when True save library/object files in their object
932 -- directory if they already exist; otherwise, in the source directory.
934 -- Initialize_ALI_Data set it to True when you want to initialize ALI
935 -- data-structures. This is what you should do most of the time.
936 -- (especially the first time around when you call this routine).
937 -- This parameter is set to False to preserve previously recorded
940 -- Max_Process is the maximum number of processes that should be spawned
941 -- to carry out compilations.
943 -- Flags in Package Opt Affecting Compile_Sources
944 -- -----------------------------------------------
946 -- Check_Object_Consistency set it to False to omit all consistency
947 -- checks between an .ali file and its corresponding object file.
948 -- When this flag is set to true, every time an .ali is read,
949 -- package Osint checks that the corresponding object file
950 -- exists and is more recent than the .ali.
952 -- Use of Name Table Info
953 -- ----------------------
955 -- All file names manipulated by Compile_Sources are entered into the
956 -- Names table. The Byte field of a source file is used to mark it.
958 -- Calling Compile_Sources Several Times
959 -- -------------------------------------
961 -- Upon return from Compile_Sources all the ALI data structures are left
962 -- intact for further browsing. HOWEVER upon entry to this routine ALI
963 -- data structures are re-initialized if parameter Initialize_ALI_Data
964 -- above is set to true. Typically this is what you want the first time
965 -- you call Compile_Sources. You should not load an ali file, call this
966 -- routine with flag Initialize_ALI_Data set to True and then expect
967 -- that ALI information to be around after the call. Note that the first
968 -- time you call Compile_Sources you better set Initialize_ALI_Data to
969 -- True unless you have called Initialize_ALI yourself.
971 -- Compile_Sources ALGORITHM : Compile_Sources (Main_Source)
972 -- -------------------------
974 -- 1. Insert Main_Source in a Queue (Q) and mark it.
976 -- 2. Let unit.adb be the file at the head of the Q. If unit.adb is
977 -- missing but its corresponding ali file is in an Ada library directory
978 -- (see below) then, remove unit.adb from the Q and goto step 4.
979 -- Otherwise, look at the files under the D (dependency) section of
980 -- unit.ali. If unit.ali does not exist or some of the time stamps do
981 -- not match, (re)compile unit.adb.
983 -- An Ada library directory is a directory containing Ada specs, ali
984 -- and object files but no source files for the bodies. An Ada library
985 -- directory is communicated to gnatmake by means of some switch so that
986 -- gnatmake can skip the sources whole ali are in that directory.
987 -- There are two reasons for skipping the sources in this case. Firstly,
988 -- Ada libraries typically come without full sources but binding and
989 -- linking against those libraries is still possible. Secondly, it would
990 -- be very wasteful for gnatmake to systematically check the consistency
991 -- of every external Ada library used in a program. The binder is
992 -- already in charge of catching any potential inconsistencies.
994 -- 3. Look into the W section of unit.ali and insert into the Q all
995 -- unmarked source files. Mark all files newly inserted in the Q.
996 -- Specifically, assuming that the W section looks like
998 -- W types%s types.adb types.ali
999 -- W unchecked_deallocation%s
1000 -- W xref_tab%s xref_tab.adb xref_tab.ali
1002 -- Then xref_tab.adb and types.adb are inserted in the Q if they are not
1004 -- Note that there is no file listed under W unchecked_deallocation%s
1005 -- so no generic body should ever be explicitly compiled (unless the
1006 -- Main_Source at the start was a generic body).
1008 -- 4. Repeat steps 2 and 3 above until the Q is empty
1010 -- Note that the above algorithm works because the units withed in
1011 -- subunits are transitively included in the W section (with section) of
1012 -- the main unit. Likewise the withed units in a generic body needed
1013 -- during a compilation are also transitively included in the W section
1014 -- of the originally compiled file.
1016 procedure Initialize (Project_Node_Tree : out Project_Node_Tree_Ref);
1017 -- Performs default and package initialization. Therefore,
1018 -- Compile_Sources can be called by an external unit.
1021 (ALI_File : File_Name_Type;
1022 Args : Argument_List;
1023 Success : out Boolean);
1024 -- Links ALI_File. Args are the arguments to pass to the linker.
1025 -- Args must have a lower bound of 1. Success indicates if the link
1026 -- succeeded or not.
1028 procedure Scan_Make_Arg
1029 (Project_Node_Tree : Project_Node_Tree_Ref;
1031 And_Save : Boolean);
1032 -- Scan make arguments. Argv is a single argument to be processed.
1033 -- Project_Node_Tree will be used to initialize external references. It
1034 -- must have been initialized.
1040 procedure Add_Arguments (Args : Argument_List) is
1042 if Arguments = null then
1043 Arguments := new Argument_List (1 .. Args'Length + 10);
1046 while Last_Argument + Args'Length > Arguments'Last loop
1048 New_Arguments : constant Argument_List_Access :=
1049 new Argument_List (1 .. Arguments'Last * 2);
1051 New_Arguments (1 .. Last_Argument) :=
1052 Arguments (1 .. Last_Argument);
1053 Arguments := New_Arguments;
1058 Arguments (Last_Argument + 1 .. Last_Argument + Args'Length) := Args;
1059 Last_Argument := Last_Argument + Args'Length;
1062 -- --------------------
1063 -- -- Add_Dependency --
1064 -- --------------------
1066 -- procedure Add_Dependency (S : File_Name_Type; On : File_Name_Type) is
1068 -- Dependencies.Increment_Last;
1069 -- Dependencies.Table (Dependencies.Last) := (S, On);
1070 -- end Add_Dependency;
1072 ----------------------------
1073 -- Add_Library_Search_Dir --
1074 ----------------------------
1076 procedure Add_Library_Search_Dir
1078 On_Command_Line : Boolean)
1081 if On_Command_Line then
1082 Add_Lib_Search_Dir (Normalize_Pathname (Path));
1085 Get_Name_String (Main_Project.Directory.Display_Name);
1087 (Normalize_Pathname (Path, Name_Buffer (1 .. Name_Len)));
1089 end Add_Library_Search_Dir;
1091 --------------------
1092 -- Add_Object_Dir --
1093 --------------------
1095 procedure Add_Object_Dir (N : String) is
1097 Add_Lib_Search_Dir (N);
1099 if Verbose_Mode then
1100 Write_Str ("Adding object directory """);
1107 --------------------
1108 -- Add_Source_Dir --
1109 --------------------
1111 procedure Add_Source_Dir (N : String) is
1113 Add_Src_Search_Dir (N);
1115 if Verbose_Mode then
1116 Write_Str ("Adding source directory """);
1123 ---------------------------
1124 -- Add_Source_Search_Dir --
1125 ---------------------------
1127 procedure Add_Source_Search_Dir
1129 On_Command_Line : Boolean)
1132 if On_Command_Line then
1133 Add_Src_Search_Dir (Normalize_Pathname (Path));
1136 Get_Name_String (Main_Project.Directory.Display_Name);
1138 (Normalize_Pathname (Path, Name_Buffer (1 .. Name_Len)));
1140 end Add_Source_Search_Dir;
1146 procedure Add_Switch
1148 Program : Make_Program_Type;
1149 Append_Switch : Boolean := True;
1150 And_Save : Boolean := True)
1153 with package T is new Table.Table (<>);
1154 procedure Generic_Position (New_Position : out Integer);
1155 -- Generic procedure that chooses a position for S in T at the
1156 -- beginning or the end, depending on the boolean Append_Switch.
1157 -- Calling this procedure may expand the table.
1159 ----------------------
1160 -- Generic_Position --
1161 ----------------------
1163 procedure Generic_Position (New_Position : out Integer) is
1167 if Append_Switch then
1168 New_Position := Integer (T.Last);
1170 for J in reverse T.Table_Index_Type'Succ (T.First) .. T.Last loop
1171 T.Table (J) := T.Table (T.Table_Index_Type'Pred (J));
1174 New_Position := Integer (T.First);
1176 end Generic_Position;
1178 procedure Gcc_Switches_Pos is new Generic_Position (Gcc_Switches);
1179 procedure Binder_Switches_Pos is new Generic_Position (Binder_Switches);
1180 procedure Linker_Switches_Pos is new Generic_Position (Linker_Switches);
1182 procedure Saved_Gcc_Switches_Pos is new
1183 Generic_Position (Saved_Gcc_Switches);
1185 procedure Saved_Binder_Switches_Pos is new
1186 Generic_Position (Saved_Binder_Switches);
1188 procedure Saved_Linker_Switches_Pos is new
1189 Generic_Position (Saved_Linker_Switches);
1191 New_Position : Integer;
1193 -- Start of processing for Add_Switch
1199 Saved_Gcc_Switches_Pos (New_Position);
1200 Saved_Gcc_Switches.Table (New_Position) := S;
1203 Saved_Binder_Switches_Pos (New_Position);
1204 Saved_Binder_Switches.Table (New_Position) := S;
1207 Saved_Linker_Switches_Pos (New_Position);
1208 Saved_Linker_Switches.Table (New_Position) := S;
1211 raise Program_Error;
1217 Gcc_Switches_Pos (New_Position);
1218 Gcc_Switches.Table (New_Position) := S;
1221 Binder_Switches_Pos (New_Position);
1222 Binder_Switches.Table (New_Position) := S;
1225 Linker_Switches_Pos (New_Position);
1226 Linker_Switches.Table (New_Position) := S;
1229 raise Program_Error;
1234 procedure Add_Switch
1236 Program : Make_Program_Type;
1237 Append_Switch : Boolean := True;
1238 And_Save : Boolean := True)
1241 Add_Switch (S => new String'(S),
1243 Append_Switch => Append_Switch,
1244 And_Save => And_Save);
1251 procedure Add_Switches
1252 (The_Package : Package_Id;
1255 Program : Make_Program_Type;
1256 Unknown_Switches_To_The_Compiler : Boolean := True;
1257 Project_Node_Tree : Project_Node_Tree_Ref)
1259 Switches : Variable_Value;
1260 Switch_List : String_List_Id;
1261 Element : String_Element;
1264 Switch_May_Be_Passed_To_The_Compiler :=
1265 Unknown_Switches_To_The_Compiler;
1267 if File_Name'Length > 0 then
1269 Add_Str_To_Name_Buffer (File_Name);
1272 (Source_File => Name_Find,
1273 Source_File_Name => File_Name,
1274 Source_Index => Index,
1275 Project => Main_Project,
1276 In_Package => The_Package,
1277 Allow_ALI => Program = Binder or else Program = Linker);
1279 if Switches.Kind = List then
1280 Program_Args := Program;
1282 Switch_List := Switches.Values;
1283 while Switch_List /= Nil_String loop
1284 Element := Project_Tree.String_Elements.Table (Switch_List);
1285 Get_Name_String (Element.Value);
1287 if Name_Len > 0 then
1289 Argv : constant String := Name_Buffer (1 .. Name_Len);
1290 -- We need a copy, because Name_Buffer may be modified
1293 if Verbose_Mode then
1294 Write_Str (" Adding ");
1299 (Project_Node_Tree, Argv, And_Save => False);
1301 if not Gnatmake_Switch_Found
1302 and then not Switch_May_Be_Passed_To_The_Compiler
1306 """ is not a gnatmake switch. Consider moving " &
1307 "it to Global_Compilation_Switches.",
1310 Make_Failed ("*** illegal switch """ & Argv & """");
1315 Switch_List := Element.Next;
1325 procedure Bind (ALI_File : File_Name_Type; Args : Argument_List) is
1326 Bind_Args : Argument_List (1 .. Args'Last + 2);
1327 Bind_Last : Integer;
1331 pragma Assert (Args'First = 1);
1333 -- Optimize the simple case where the gnatbind command line looks like
1334 -- gnatbind -aO. -I- file.ali --into-> gnatbind file.adb
1337 and then Args (Args'First).all = "-aO" & Normalized_CWD
1338 and then Args (Args'Last).all = "-I-"
1339 and then ALI_File = Strip_Directory (ALI_File)
1341 Bind_Last := Args'First - 1;
1344 Bind_Last := Args'Last;
1345 Bind_Args (Args'Range) := Args;
1348 -- It is completely pointless to re-check source file time stamps. This
1349 -- has been done already by gnatmake
1351 Bind_Last := Bind_Last + 1;
1352 Bind_Args (Bind_Last) := Do_Not_Check_Flag;
1354 Get_Name_String (ALI_File);
1356 Bind_Last := Bind_Last + 1;
1357 Bind_Args (Bind_Last) := new String'(Name_Buffer (1 .. Name_Len));
1359 GNAT.OS_Lib.Normalize_Arguments (Bind_Args (Args'First .. Bind_Last));
1361 Display (Gnatbind.all, Bind_Args (Args'First .. Bind_Last));
1363 if Gnatbind_Path = null then
1364 Make_Failed ("error, unable to locate " & Gnatbind.all);
1368 (Gnatbind_Path.all, Bind_Args (Args'First .. Bind_Last), Success);
1371 Make_Failed ("*** bind failed.");
1375 --------------------------------
1376 -- Change_To_Object_Directory --
1377 --------------------------------
1379 procedure Change_To_Object_Directory (Project : Project_Id) is
1380 Object_Directory : Path_Name_Type;
1383 pragma Assert (Project /= No_Project);
1385 -- Nothing to do if the current working directory is already the correct
1386 -- object directory.
1388 if Project_Of_Current_Object_Directory /= Project then
1389 Project_Of_Current_Object_Directory := Project;
1390 Object_Directory := Project.Object_Directory.Name;
1392 -- Set the working directory to the object directory of the actual
1395 if Verbose_Mode then
1396 Write_Str ("Changing to object directory of """);
1397 Write_Name (Project.Display_Name);
1398 Write_Str (""": """);
1399 Write_Name (Object_Directory);
1403 Change_Dir (Get_Name_String (Object_Directory));
1407 -- Fail if unable to change to the object directory
1409 when Directory_Error =>
1410 Make_Failed ("unable to change to object directory """ &
1412 (Project.Object_Directory.Name) &
1414 Get_Name_String (Project.Display_Name));
1415 end Change_To_Object_Directory;
1422 (Source_File : File_Name_Type;
1424 Is_Main_Source : Boolean;
1425 The_Args : Argument_List;
1426 Lib_File : File_Name_Type;
1427 Full_Lib_File : File_Name_Type;
1428 Lib_File_Attr : access File_Attributes;
1429 Read_Only : Boolean;
1431 O_File : out File_Name_Type;
1432 O_Stamp : out Time_Stamp_Type)
1434 function First_New_Spec (A : ALI_Id) return File_Name_Type;
1435 -- Looks in the with table entries of A and returns the spec file name
1436 -- of the first withed unit (subprogram) for which no spec existed when
1437 -- A was generated but for which there exists one now, implying that A
1438 -- is now obsolete. If no such unit is found No_File is returned.
1439 -- Otherwise the spec file name of the unit is returned.
1441 -- **WARNING** in the event of Uname format modifications, one *MUST*
1442 -- make sure this function is also updated.
1444 -- Note: This function should really be in ali.adb and use Uname
1445 -- services, but this causes the whole compiler to be dragged along
1446 -- for gnatbind and gnatmake.
1448 --------------------
1449 -- First_New_Spec --
1450 --------------------
1452 function First_New_Spec (A : ALI_Id) return File_Name_Type is
1453 Spec_File_Name : File_Name_Type := No_File;
1455 function New_Spec (Uname : Unit_Name_Type) return Boolean;
1456 -- Uname is the name of the spec or body of some ada unit. This
1457 -- function returns True if the Uname is the name of a body which has
1458 -- a spec not mentioned in ALI file A. If True is returned
1459 -- Spec_File_Name above is set to the name of this spec file.
1465 function New_Spec (Uname : Unit_Name_Type) return Boolean is
1466 Spec_Name : Unit_Name_Type;
1467 File_Name : File_Name_Type;
1470 -- Test whether Uname is the name of a body unit (i.e. ends
1473 Get_Name_String (Uname);
1475 Assert (Name_Len > 2 and then Name_Buffer (Name_Len - 1) = '%');
1477 if Name_Buffer (Name_Len) /= 'b' then
1481 -- Convert unit name into spec name
1483 -- ??? this code seems dubious in presence of pragma
1484 -- Source_File_Name since there is no more direct relationship
1485 -- between unit name and file name.
1487 -- ??? Further, what about alternative subunit naming
1489 Name_Buffer (Name_Len) := 's';
1490 Spec_Name := Name_Find;
1491 File_Name := Get_File_Name (Spec_Name, Subunit => False);
1493 -- Look if File_Name is mentioned in A's sdep list.
1494 -- If not look if the file exists. If it does return True.
1497 ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep
1499 if Sdep.Table (D).Sfile = File_Name then
1504 if Full_Source_Name (File_Name) /= No_File then
1505 Spec_File_Name := File_Name;
1512 -- Start of processing for First_New_Spec
1516 ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit
1518 exit U_Chk when Units.Table (U).Utype = Is_Body_Only
1519 and then New_Spec (Units.Table (U).Uname);
1521 for W in Units.Table (U).First_With
1523 Units.Table (U).Last_With
1526 Withs.Table (W).Afile /= No_File
1527 and then New_Spec (Withs.Table (W).Uname);
1531 return Spec_File_Name;
1534 ---------------------------------
1535 -- Data declarations for Check --
1536 ---------------------------------
1538 Full_Obj_File : File_Name_Type;
1539 -- Full name of the object file corresponding to Lib_File
1541 Lib_Stamp : Time_Stamp_Type;
1542 -- Time stamp of the current ada library file
1544 Obj_Stamp : Time_Stamp_Type;
1545 -- Time stamp of the current object file
1547 Modified_Source : File_Name_Type;
1548 -- The first source in Lib_File whose current time stamp differs
1549 -- from that stored in Lib_File.
1551 New_Spec : File_Name_Type;
1552 -- If Lib_File contains in its W (with) section a body (for a
1553 -- subprogram) for which there exists a spec and the spec did not
1554 -- appear in the Sdep section of Lib_File, New_Spec contains the file
1555 -- name of this new spec.
1557 Source_Name : File_Name_Type;
1558 Text : Text_Buffer_Ptr;
1560 Prev_Switch : String_Access;
1561 -- Previous switch processed
1563 Arg : Arg_Id := Arg_Id'First;
1564 -- Current index in Args.Table for a given unit (init to stop warning)
1566 Switch_Found : Boolean;
1567 -- True if a given switch has been found
1569 ALI_Project : Project_Id;
1570 -- If the ALI file is in the object directory of a project, this is
1573 -- Start of processing for Check
1576 pragma Assert (Lib_File /= No_File);
1578 -- If ALI file is read-only, temporarily set Check_Object_Consistency to
1579 -- False. We don't care if the object file is not there (presumably a
1580 -- library will be used for linking.)
1584 Saved_Check_Object_Consistency : constant Boolean :=
1585 Check_Object_Consistency;
1587 Check_Object_Consistency := False;
1588 Text := Read_Library_Info_From_Full (Full_Lib_File, Lib_File_Attr);
1589 Check_Object_Consistency := Saved_Check_Object_Consistency;
1593 Text := Read_Library_Info_From_Full (Full_Lib_File, Lib_File_Attr);
1596 Full_Obj_File := Full_Object_File_Name;
1597 Lib_Stamp := Current_Library_File_Stamp;
1598 Obj_Stamp := Current_Object_File_Stamp;
1600 if Full_Lib_File = No_File then
1603 "being checked ...",
1605 Minimum_Verbosity => Opt.Medium);
1609 "being checked ...",
1611 Minimum_Verbosity => Opt.Medium);
1615 O_File := Full_Obj_File;
1616 O_Stamp := Obj_Stamp;
1619 if Full_Lib_File = No_File then
1620 Verbose_Msg (Lib_File, "missing.");
1622 elsif Obj_Stamp (Obj_Stamp'First) = ' ' then
1623 Verbose_Msg (Full_Obj_File, "missing.");
1627 (Full_Lib_File, "(" & String (Lib_Stamp) & ") newer than",
1628 Full_Obj_File, "(" & String (Obj_Stamp) & ")");
1632 ALI := Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
1635 if ALI = No_ALI_Id then
1636 Verbose_Msg (Full_Lib_File, "incorrectly formatted ALI file");
1639 elsif ALIs.Table (ALI).Ver (1 .. ALIs.Table (ALI).Ver_Len) /=
1640 Verbose_Library_Version
1642 Verbose_Msg (Full_Lib_File, "compiled with old GNAT version");
1647 -- Don't take Ali file into account if it was generated with
1650 if ALIs.Table (ALI).Compile_Errors then
1651 Verbose_Msg (Full_Lib_File, "had errors, must be recompiled");
1656 -- Don't take Ali file into account if it was generated without
1659 if Operating_Mode /= Check_Semantics
1660 and then ALIs.Table (ALI).No_Object
1662 Verbose_Msg (Full_Lib_File, "has no corresponding object");
1667 -- Check for matching compiler switches if needed
1669 if Check_Switches then
1671 -- First, collect all the switches
1674 (Source_File, Source_Index, Is_Main_Source, The_Args);
1676 Prev_Switch := Dummy_Switch;
1678 Get_Name_String (ALIs.Table (ALI).Sfile);
1680 Switches_To_Check.Set_Last (0);
1682 for J in 1 .. Last_Argument loop
1684 -- Skip non switches -c, -I and -o switches
1686 if Arguments (J) (1) = '-'
1687 and then Arguments (J) (2) /= 'c'
1688 and then Arguments (J) (2) /= 'o'
1689 and then Arguments (J) (2) /= 'I'
1691 Normalize_Compiler_Switches
1693 Normalized_Switches,
1696 for K in 1 .. Last_Norm_Switch loop
1697 Switches_To_Check.Increment_Last;
1698 Switches_To_Check.Table (Switches_To_Check.Last) :=
1699 Normalized_Switches (K);
1704 for J in 1 .. Switches_To_Check.Last loop
1706 -- Comparing switches is delicate because gcc reorders a number
1707 -- of switches, according to lang-specs.h, but gnatmake doesn't
1708 -- have sufficient knowledge to perform the same reordering.
1709 -- Instead, we ignore orders between different "first letter"
1710 -- switches, but keep orders between same switches, e.g -O -O2
1711 -- is different than -O2 -O, but -g -O is equivalent to -O -g.
1713 if Switches_To_Check.Table (J) (2) /= Prev_Switch (2) or else
1714 (Prev_Switch'Length >= 6 and then
1715 Prev_Switch (2 .. 5) = "gnat" and then
1716 Switches_To_Check.Table (J)'Length >= 6 and then
1717 Switches_To_Check.Table (J) (2 .. 5) = "gnat" and then
1718 Prev_Switch (6) /= Switches_To_Check.Table (J) (6))
1720 Prev_Switch := Switches_To_Check.Table (J);
1722 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg;
1725 Switch_Found := False;
1728 Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1731 Switches_To_Check.Table (J).all = Args.Table (K).all
1734 Switch_Found := True;
1739 if not Switch_Found then
1740 if Verbose_Mode then
1741 Verbose_Msg (ALIs.Table (ALI).Sfile,
1742 "switch mismatch """ &
1743 Switches_To_Check.Table (J).all & '"');
1751 if Switches_To_Check.Last /=
1752 Integer (Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg -
1753 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg + 1)
1755 if Verbose_Mode then
1756 Verbose_Msg (ALIs.Table (ALI).Sfile,
1757 "different number of switches");
1759 for K in Units.Table (ALIs.Table (ALI).First_Unit).First_Arg
1760 .. Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1762 Write_Str (Args.Table (K).all);
1768 for J in 1 .. Switches_To_Check.Last loop
1769 Write_Str (Switches_To_Check.Table (J).all);
1781 -- Get the source files and their message digests. Note that some
1782 -- sources may be missing if ALI is out-of-date.
1784 Set_Source_Table (ALI);
1786 Modified_Source := Time_Stamp_Mismatch (ALI, Read_Only);
1788 if Modified_Source /= No_File then
1791 if Verbose_Mode then
1792 Source_Name := Full_Source_Name (Modified_Source);
1794 if Source_Name /= No_File then
1795 Verbose_Msg (Source_Name, "time stamp mismatch");
1797 Verbose_Msg (Modified_Source, "missing");
1802 New_Spec := First_New_Spec (ALI);
1804 if New_Spec /= No_File then
1807 if Verbose_Mode then
1808 Source_Name := Full_Source_Name (New_Spec);
1810 if Source_Name /= No_File then
1811 Verbose_Msg (Source_Name, "new spec");
1813 Verbose_Msg (New_Spec, "old spec missing");
1817 elsif not Read_Only and then Main_Project /= No_Project then
1819 if not Check_Source_Info_In_ALI (ALI) then
1824 -- Check that the ALI file is in the correct object directory.
1825 -- If it is in the object directory of a project that is
1826 -- extended and it depends on a source that is in one of its
1827 -- extending projects, then the ALI file is not in the correct
1828 -- object directory.
1830 -- First, find the project of this ALI file. As there may be
1831 -- several projects with the same object directory, we first
1832 -- need to find the project of the source.
1834 ALI_Project := No_Project;
1837 Udata : Prj.Unit_Index;
1840 Udata := Units_Htable.Get_First (Project_Tree.Units_HT);
1841 while Udata /= No_Unit_Index loop
1842 if Udata.File_Names (Impl) /= null
1843 and then Udata.File_Names (Impl).File = Source_File
1845 ALI_Project := Udata.File_Names (Impl).Project;
1848 elsif Udata.File_Names (Spec) /= null
1849 and then Udata.File_Names (Spec).File = Source_File
1851 ALI_Project := Udata.File_Names (Spec).Project;
1855 Udata := Units_Htable.Get_Next (Project_Tree.Units_HT);
1859 if ALI_Project = No_Project then
1864 Obj_Dir : Path_Name_Type;
1865 Res_Obj_Dir : constant String :=
1868 (Get_Name_String (Full_Lib_File)),
1870 Opt.Follow_Links_For_Dirs,
1871 Case_Sensitive => False);
1875 Add_Str_To_Name_Buffer (Res_Obj_Dir);
1877 if not Is_Directory_Separator (Name_Buffer (Name_Len)) then
1878 Add_Char_To_Name_Buffer (Directory_Separator);
1881 Obj_Dir := Name_Find;
1883 while ALI_Project /= No_Project
1884 and then Obj_Dir /= ALI_Project.Object_Directory.Name
1886 ALI_Project := ALI_Project.Extended_By;
1890 if ALI_Project = No_Project then
1894 (Lib_File, " wrong object directory");
1898 -- If the ALI project is not extended, then it must be in
1899 -- the correct object directory.
1901 if ALI_Project.Extended_By = No_Project then
1905 -- Count the extending projects
1913 Proj := ALI_Project;
1915 Proj := Proj.Extended_By;
1916 exit when Proj = No_Project;
1917 Num_Ext := Num_Ext + 1;
1920 -- Make a list of the extending projects
1923 Projects : array (1 .. Num_Ext) of Project_Id;
1925 OK : Boolean := True;
1929 Proj := ALI_Project;
1930 for J in Projects'Range loop
1931 Proj := Proj.Extended_By;
1932 Projects (J) := Proj;
1935 -- Now check if any of the dependant sources are in
1936 -- any of these extending projects.
1939 for D in ALIs.Table (ALI).First_Sdep ..
1940 ALIs.Table (ALI).Last_Sdep
1942 Dep := Sdep.Table (D);
1943 UID := Units_Htable.Get_First (Project_Tree.Units_HT);
1947 while UID /= null loop
1948 if UID.File_Names (Impl) /= null
1949 and then UID.File_Names (Impl).File = Dep.Sfile
1951 Proj := UID.File_Names (Impl).Project;
1953 elsif UID.File_Names (Spec) /= null
1954 and then UID.File_Names (Spec).File = Dep.Sfile
1956 Proj := UID.File_Names (Spec).Project;
1959 -- If a source is in a project, check if it is one
1962 if Proj /= No_Project then
1963 for J in Projects'Range loop
1964 if Proj = Projects (J) then
1974 Units_Htable.Get_Next (Project_Tree.Units_HT);
1978 -- If one of the dependent sources is in one project of
1979 -- the list, then we must recompile.
1983 Verbose_Msg (Lib_File, " wrong object directory");
1992 ------------------------
1993 -- Check_For_S_Switch --
1994 ------------------------
1996 procedure Check_For_S_Switch is
1998 -- By default, we generate an object file
2000 Output_Is_Object := True;
2002 for Arg in 1 .. Last_Argument loop
2003 if Arguments (Arg).all = "-S" then
2004 Output_Is_Object := False;
2006 elsif Arguments (Arg).all = "-c" then
2007 Output_Is_Object := True;
2010 end Check_For_S_Switch;
2012 --------------------------
2013 -- Check_Linker_Options --
2014 --------------------------
2016 procedure Check_Linker_Options
2017 (E_Stamp : Time_Stamp_Type;
2018 O_File : out File_Name_Type;
2019 O_Stamp : out Time_Stamp_Type)
2021 procedure Check_File (File : File_Name_Type);
2022 -- Update O_File and O_Stamp if the given file is younger than E_Stamp
2023 -- and O_Stamp, or if O_File is No_File and File does not exist.
2025 function Get_Library_File (Name : String) return File_Name_Type;
2026 -- Return the full file name including path of a library based
2027 -- on the name specified with the -l linker option, using the
2028 -- Ada object path. Return No_File if no such file can be found.
2030 type Char_Array is array (Natural) of Character;
2031 type Char_Array_Access is access constant Char_Array;
2033 Template : Char_Array_Access;
2034 pragma Import (C, Template, "__gnat_library_template");
2040 procedure Check_File (File : File_Name_Type) is
2041 Stamp : Time_Stamp_Type;
2042 Name : File_Name_Type := File;
2045 Get_Name_String (Name);
2047 -- Remove any trailing NUL characters
2049 while Name_Len >= Name_Buffer'First
2050 and then Name_Buffer (Name_Len) = NUL
2052 Name_Len := Name_Len - 1;
2055 if Name_Len = 0 then
2058 elsif Name_Buffer (1) = '-' then
2060 -- Do not check if File is a switch other than "-l"
2062 if Name_Buffer (2) /= 'l' then
2066 -- The argument is a library switch, get actual name. It
2067 -- is necessary to make a copy of the relevant part of
2068 -- Name_Buffer as Get_Library_Name uses Name_Buffer as well.
2071 Base_Name : constant String := Name_Buffer (3 .. Name_Len);
2074 Name := Get_Library_File (Base_Name);
2077 if Name = No_File then
2082 Stamp := File_Stamp (Name);
2084 -- Find the youngest object file that is younger than the
2085 -- executable. If no such file exist, record the first object
2086 -- file that is not found.
2088 if (O_Stamp < Stamp and then E_Stamp < Stamp)
2089 or else (O_File = No_File and then Stamp (Stamp'First) = ' ')
2094 -- Strip the trailing NUL if present
2096 Get_Name_String (O_File);
2098 if Name_Buffer (Name_Len) = NUL then
2099 Name_Len := Name_Len - 1;
2100 O_File := Name_Find;
2105 ----------------------
2106 -- Get_Library_Name --
2107 ----------------------
2109 -- See comments in a-adaint.c about template syntax
2111 function Get_Library_File (Name : String) return File_Name_Type is
2112 File : File_Name_Type := No_File;
2117 for Ptr in Template'Range loop
2118 case Template (Ptr) is
2120 Add_Str_To_Name_Buffer (Name);
2123 File := Full_Lib_File_Name (Name_Find);
2124 exit when File /= No_File;
2131 Add_Char_To_Name_Buffer (Template (Ptr));
2135 -- The for loop exited because the end of the template
2136 -- was reached. File contains the last possible file name
2139 if File = No_File and then Name_Len > 0 then
2140 File := Full_Lib_File_Name (Name_Find);
2144 end Get_Library_File;
2146 -- Start of processing for Check_Linker_Options
2150 O_Stamp := (others => ' ');
2152 -- Process linker options from the ALI files
2154 for Opt in 1 .. Linker_Options.Last loop
2155 Check_File (File_Name_Type (Linker_Options.Table (Opt).Name));
2158 -- Process options given on the command line
2160 for Opt in Linker_Switches.First .. Linker_Switches.Last loop
2162 -- Check if the previous Opt has one of the two switches
2163 -- that take an extra parameter. (See GCC manual.)
2165 if Opt = Linker_Switches.First
2166 or else (Linker_Switches.Table (Opt - 1).all /= "-u"
2168 Linker_Switches.Table (Opt - 1).all /= "-Xlinker"
2170 Linker_Switches.Table (Opt - 1).all /= "-L")
2173 Add_Str_To_Name_Buffer (Linker_Switches.Table (Opt).all);
2174 Check_File (Name_Find);
2178 end Check_Linker_Options;
2184 procedure Check_Steps is
2186 -- If either -c, -b or -l has been specified, we will not necessarily
2187 -- execute all steps.
2190 Do_Compile_Step := Do_Compile_Step and Compile_Only;
2191 Do_Bind_Step := Do_Bind_Step and Bind_Only;
2192 Do_Link_Step := Do_Link_Step and Link_Only;
2194 -- If -c has been specified, but not -b, ignore any potential -l
2196 if Do_Compile_Step and then not Do_Bind_Step then
2197 Do_Link_Step := False;
2202 -----------------------
2203 -- Collect_Arguments --
2204 -----------------------
2206 procedure Collect_Arguments
2207 (Source_File : File_Name_Type;
2209 Is_Main_Source : Boolean;
2210 Args : Argument_List)
2213 Arguments_Project := No_Project;
2215 Add_Arguments (Args);
2217 if Main_Project /= No_Project then
2219 Source_File_Name : constant String :=
2220 Get_Name_String (Source_File);
2221 Compiler_Package : Prj.Package_Id;
2222 Switches : Prj.Variable_Value;
2227 (Source_File_Name => Source_File_Name,
2228 Project => Arguments_Project,
2229 Path => Arguments_Path_Name,
2230 In_Tree => Project_Tree);
2232 -- If the source is not a source of a project file, add the
2233 -- recorded arguments. Check will be done later if the source
2234 -- need to be compiled that the switch -x has been used.
2236 if Arguments_Project = No_Project then
2237 Add_Arguments (The_Saved_Gcc_Switches.all);
2239 elsif not Arguments_Project.Externally_Built then
2240 -- We get the project directory for the relative path
2241 -- switches and arguments.
2243 Arguments_Project := Ultimate_Extending_Project_Of
2244 (Arguments_Project);
2246 -- If building a dynamic or relocatable library, compile with
2247 -- PIC option, if it exists.
2249 if Arguments_Project.Library
2250 and then Arguments_Project.Library_Kind /= Static
2253 PIC : constant String := MLib.Tgt.PIC_Option;
2257 Add_Arguments ((1 => new String'(PIC)));
2262 -- We now look for package Compiler and get the switches from
2267 (Name => Name_Compiler,
2268 In_Packages => Arguments_Project.Decl.Packages,
2269 In_Tree => Project_Tree);
2271 if Compiler_Package /= No_Package then
2273 -- If package Gnatmake.Compiler exists, we get the specific
2274 -- switches for the current source, or the global switches,
2279 (Source_File => Source_File,
2280 Source_File_Name => Source_File_Name,
2281 Source_Index => Source_Index,
2282 Project => Arguments_Project,
2283 In_Package => Compiler_Package,
2284 Allow_ALI => False);
2288 case Switches.Kind is
2290 -- We have a list of switches. We add these switches,
2291 -- plus the saved gcc switches.
2296 Current : String_List_Id := Switches.Values;
2297 Element : String_Element;
2298 Number : Natural := 0;
2301 while Current /= Nil_String loop
2302 Element := Project_Tree.String_Elements.
2304 Number := Number + 1;
2305 Current := Element.Next;
2309 New_Args : Argument_List (1 .. Number);
2310 Last_New : Natural := 0;
2311 Dir_Path : constant String := Get_Name_String
2312 (Arguments_Project.Directory.Name);
2315 Current := Switches.Values;
2317 for Index in New_Args'Range loop
2318 Element := Project_Tree.String_Elements.
2320 Get_Name_String (Element.Value);
2322 if Name_Len > 0 then
2323 Last_New := Last_New + 1;
2324 New_Args (Last_New) :=
2325 new String'(Name_Buffer (1 .. Name_Len));
2326 Test_If_Relative_Path
2327 (New_Args (Last_New),
2329 Including_Non_Switch => False);
2332 Current := Element.Next;
2336 (Configuration_Pragmas_Switch
2337 (Arguments_Project) &
2338 New_Args (1 .. Last_New) &
2339 The_Saved_Gcc_Switches.all);
2343 -- We have a single switch. We add this switch,
2344 -- plus the saved gcc switches.
2347 Get_Name_String (Switches.Value);
2350 New_Args : Argument_List :=
2352 (Name_Buffer (1 .. Name_Len)));
2353 Dir_Path : constant String :=
2355 (Arguments_Project.Directory.Name);
2358 Test_If_Relative_Path
2361 Including_Non_Switch => False);
2363 (Configuration_Pragmas_Switch (Arguments_Project) &
2364 New_Args & The_Saved_Gcc_Switches.all);
2367 -- We have no switches from Gnatmake.Compiler.
2368 -- We add the saved gcc switches.
2372 (Configuration_Pragmas_Switch (Arguments_Project) &
2373 The_Saved_Gcc_Switches.all);
2379 -- For VMS, when compiling the main source, add switch
2380 -- -mdebug-main=_ada_ so that the executable can be debugged
2381 -- by the standard VMS debugger.
2383 if not No_Main_Subprogram
2384 and then Targparm.OpenVMS_On_Target
2385 and then Is_Main_Source
2387 -- First, check if compilation will be invoked with -g
2389 for J in 1 .. Last_Argument loop
2390 if Arguments (J)'Length >= 2
2391 and then Arguments (J) (1 .. 2) = "-g"
2392 and then (Arguments (J)'Length < 5
2393 or else Arguments (J) (1 .. 5) /= "-gnat")
2396 ((1 => new String'("-mdebug-main=_ada_")));
2402 -- Set Output_Is_Object, depending if there is a -S switch.
2403 -- If the bind step is not performed, and there is a -S switch,
2404 -- then we will not check for a valid object file.
2407 end Collect_Arguments;
2409 ---------------------
2410 -- Compile_Sources --
2411 ---------------------
2413 procedure Compile_Sources
2414 (Main_Source : File_Name_Type;
2415 Args : Argument_List;
2416 First_Compiled_File : out File_Name_Type;
2417 Most_Recent_Obj_File : out File_Name_Type;
2418 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
2419 Main_Unit : out Boolean;
2420 Compilation_Failures : out Natural;
2421 Main_Index : Int := 0;
2422 Check_Readonly_Files : Boolean := False;
2423 Do_Not_Execute : Boolean := False;
2424 Force_Compilations : Boolean := False;
2425 Keep_Going : Boolean := False;
2426 In_Place_Mode : Boolean := False;
2427 Initialize_ALI_Data : Boolean := True;
2428 Max_Process : Positive := 1)
2430 Mfile : Natural := No_Mapping_File;
2431 Mapping_File_Arg : String_Access;
2432 -- Info on the mapping file
2434 Need_To_Check_Standard_Library : Boolean :=
2435 Check_Readonly_Files
2436 and not Unique_Compile;
2438 procedure Add_Process
2440 Sfile : File_Name_Type;
2441 Afile : File_Name_Type;
2442 Uname : Unit_Name_Type;
2443 Full_Lib_File : File_Name_Type;
2444 Lib_File_Attr : File_Attributes;
2445 Mfile : Natural := No_Mapping_File);
2446 -- Adds process Pid to the current list of outstanding compilation
2447 -- processes and record the full name of the source file Sfile that
2448 -- we are compiling, the name of its library file Afile and the
2449 -- name of its unit Uname. If Mfile is not equal to No_Mapping_File,
2450 -- it is the index of the mapping file used during compilation in the
2451 -- array The_Mapping_File_Names.
2453 procedure Await_Compile
2454 (Data : out Compilation_Data;
2456 -- Awaits that an outstanding compilation process terminates. When
2457 -- it does set Data to the information registered for the corresponding
2458 -- call to Add_Process.
2459 -- Note that this time stamp can be used to check whether the
2460 -- compilation did generate an object file. OK is set to True if the
2461 -- compilation succeeded.
2462 -- Data could be No_Compilation_Data if there was no compilation to wait
2465 function Bad_Compilation_Count return Natural;
2466 -- Returns the number of compilation failures
2468 procedure Check_Standard_Library;
2469 -- Check if s-stalib.adb needs to be compiled
2471 procedure Collect_Arguments_And_Compile
2472 (Full_Source_File : File_Name_Type;
2473 Lib_File : File_Name_Type;
2475 Pid : out Process_Id;
2476 Process_Created : out Boolean);
2477 -- Collect arguments from project file (if any) and compile.
2478 -- If no compilation was attempted, Processed_Created is set to False,
2479 -- and the value of Pid is unknown.
2482 (Project : Project_Id;
2486 Args : Argument_List) return Process_Id;
2487 -- Compiles S using Args. If S is a GNAT predefined source "-gnatpg" is
2488 -- added to Args. Non blocking call. L corresponds to the expected
2489 -- library file name. Process_Id of the process spawned to execute the
2492 package Good_ALI is new Table.Table (
2493 Table_Component_Type => ALI_Id,
2494 Table_Index_Type => Natural,
2495 Table_Low_Bound => 1,
2496 Table_Initial => 50,
2497 Table_Increment => 100,
2498 Table_Name => "Make.Good_ALI");
2499 -- Contains the set of valid ALI files that have not yet been scanned
2501 function Good_ALI_Present return Boolean;
2502 -- Returns True if any ALI file was recorded in the previous set
2504 procedure Get_Mapping_File (Project : Project_Id);
2505 -- Get a mapping file name. If there is one to be reused, reuse it.
2506 -- Otherwise, create a new mapping file.
2508 function Get_Next_Good_ALI return ALI_Id;
2509 -- Returns the next good ALI_Id record
2511 procedure Record_Failure
2512 (File : File_Name_Type;
2513 Unit : Unit_Name_Type;
2514 Found : Boolean := True);
2515 -- Records in the previous table that the compilation for File failed.
2516 -- If Found is False then the compilation of File failed because we
2517 -- could not find it. Records also Unit when possible.
2519 procedure Record_Good_ALI (A : ALI_Id);
2520 -- Records in the previous set the Id of an ALI file
2522 function Must_Exit_Because_Of_Error return Boolean;
2523 -- Return True if there were errors and the user decided to exit in such
2524 -- a case. This waits for any outstanding compilation.
2526 function Start_Compile_If_Possible (Args : Argument_List) return Boolean;
2527 -- Check if there is more work that we can do (i.e. the Queue is non
2528 -- empty). If there is, do it only if we have not yet used up all the
2529 -- available processes.
2530 -- Returns True if we should exit the main loop
2532 procedure Wait_For_Available_Slot;
2533 -- Check if we should wait for a compilation to finish. This is the case
2534 -- if all the available processes are busy compiling sources or there is
2535 -- nothing else to do (that is the Q is empty and there are no good ALIs
2538 procedure Fill_Queue_From_ALI_Files;
2539 -- Check if we recorded good ALI files. If yes process them now in the
2540 -- order in which they have been recorded. There are two occasions in
2541 -- which we record good ali files. The first is in phase 1 when, after
2542 -- scanning an existing ALI file we realize it is up-to-date, the second
2543 -- instance is after a successful compilation.
2549 procedure Add_Process
2551 Sfile : File_Name_Type;
2552 Afile : File_Name_Type;
2553 Uname : Unit_Name_Type;
2554 Full_Lib_File : File_Name_Type;
2555 Lib_File_Attr : File_Attributes;
2556 Mfile : Natural := No_Mapping_File)
2558 OC1 : constant Positive := Outstanding_Compiles + 1;
2561 pragma Assert (OC1 <= Max_Process);
2562 pragma Assert (Pid /= Invalid_Pid);
2564 Running_Compile (OC1) :=
2566 Full_Source_File => Sfile,
2568 Full_Lib_File => Full_Lib_File,
2569 Lib_File_Attr => Lib_File_Attr,
2570 Source_Unit => Uname,
2571 Mapping_File => Mfile,
2572 Project => Arguments_Project);
2574 Outstanding_Compiles := OC1;
2577 --------------------
2581 procedure Await_Compile
2582 (Data : out Compilation_Data;
2586 Project : Project_Id;
2587 Comp_Data : Project_Compilation_Access;
2590 pragma Assert (Outstanding_Compiles > 0);
2592 Data := No_Compilation_Data;
2595 -- The loop here is a work-around for a problem on VMS; in some
2596 -- circumstances (shared library and several executables, for
2597 -- example), there are child processes other than compilation
2598 -- processes that are received. Until this problem is resolved,
2599 -- we will ignore such processes.
2602 Wait_Process (Pid, OK);
2604 if Pid = Invalid_Pid then
2608 for J in Running_Compile'First .. Outstanding_Compiles loop
2609 if Pid = Running_Compile (J).Pid then
2610 Data := Running_Compile (J);
2611 Project := Running_Compile (J).Project;
2613 -- If a mapping file was used by this compilation, get its
2614 -- file name for reuse by a subsequent compilation.
2616 if Running_Compile (J).Mapping_File /= No_Mapping_File then
2617 Comp_Data := Project_Compilation_Htable.Get
2618 (Project_Compilation, Project);
2619 Comp_Data.Last_Free_Indices :=
2620 Comp_Data.Last_Free_Indices + 1;
2621 Comp_Data.Free_Mapping_File_Indices
2622 (Comp_Data.Last_Free_Indices) :=
2623 Running_Compile (J).Mapping_File;
2626 -- To actually remove this Pid and related info from
2627 -- Running_Compile replace its entry with the last valid
2628 -- entry in Running_Compile.
2630 if J = Outstanding_Compiles then
2634 Running_Compile (J) :=
2635 Running_Compile (Outstanding_Compiles);
2638 Outstanding_Compiles := Outstanding_Compiles - 1;
2643 -- This child process was not one of our compilation processes;
2644 -- just ignore it for now.
2646 -- raise Program_Error;
2650 ---------------------------
2651 -- Bad_Compilation_Count --
2652 ---------------------------
2654 function Bad_Compilation_Count return Natural is
2656 return Bad_Compilation.Last - Bad_Compilation.First + 1;
2657 end Bad_Compilation_Count;
2659 ----------------------------
2660 -- Check_Standard_Library --
2661 ----------------------------
2663 procedure Check_Standard_Library is
2665 Need_To_Check_Standard_Library := False;
2667 if not Targparm.Suppress_Standard_Library_On_Target then
2669 Sfile : File_Name_Type;
2670 Add_It : Boolean := True;
2674 Add_Str_To_Name_Buffer (Standard_Library_Package_Body_Name);
2675 Sfile := Name_Enter;
2677 -- If we have a special runtime, we add the standard
2678 -- library only if we can find it.
2682 Find_File (Sfile, Osint.Source) /= No_File;
2686 if Is_Marked (Sfile) then
2687 if Is_In_Obsoleted (Sfile) then
2688 Executable_Obsolete := True;
2692 Insert_Q (Sfile, Index => 0);
2693 Mark (Sfile, Index => 0);
2698 end Check_Standard_Library;
2700 -----------------------------------
2701 -- Collect_Arguments_And_Compile --
2702 -----------------------------------
2704 procedure Collect_Arguments_And_Compile
2705 (Full_Source_File : File_Name_Type;
2706 Lib_File : File_Name_Type;
2708 Pid : out Process_Id;
2709 Process_Created : out Boolean) is
2711 Process_Created := False;
2713 -- If we use mapping file (-P or -C switches), then get one
2715 if Create_Mapping_File then
2716 Get_Mapping_File (Arguments_Project);
2719 -- If the source is part of a project file, we set the ADA_*_PATHs,
2720 -- check for an eventual library project, and use the full path.
2722 if Arguments_Project /= No_Project then
2723 if not Arguments_Project.Externally_Built then
2724 Prj.Env.Set_Ada_Paths
2727 Including_Libraries => True);
2729 if not Unique_Compile
2730 and then MLib.Tgt.Support_For_Libraries /= Prj.None
2733 Prj : constant Project_Id :=
2734 Ultimate_Extending_Project_Of (Arguments_Project);
2738 and then not Prj.Externally_Built
2739 and then not Prj.Need_To_Build_Lib
2741 -- Add to the Q all sources of the project that have
2744 Insert_Project_Sources
2745 (The_Project => Prj,
2746 All_Projects => False,
2749 -- Now mark the project as processed
2751 Prj.Need_To_Build_Lib := True;
2758 (Project => Arguments_Project,
2759 S => File_Name_Type (Arguments_Path_Name),
2761 Source_Index => Source_Index,
2762 Args => Arguments (1 .. Last_Argument));
2763 Process_Created := True;
2767 -- If this is a source outside of any project file, make sure it
2768 -- will be compiled in object directory of the main project file.
2772 (Project => Main_Project,
2773 S => Full_Source_File,
2775 Source_Index => Source_Index,
2776 Args => Arguments (1 .. Last_Argument));
2777 Process_Created := True;
2779 end Collect_Arguments_And_Compile;
2786 (Project : Project_Id;
2790 Args : Argument_List) return Process_Id
2792 Comp_Args : Argument_List (Args'First .. Args'Last + 10);
2793 Comp_Next : Integer := Args'First;
2794 Comp_Last : Integer;
2795 Arg_Index : Integer;
2797 function Ada_File_Name (Name : File_Name_Type) return Boolean;
2798 -- Returns True if Name is the name of an ada source file
2799 -- (i.e. suffix is .ads or .adb)
2805 function Ada_File_Name (Name : File_Name_Type) return Boolean is
2807 Get_Name_String (Name);
2810 and then Name_Buffer (Name_Len - 3 .. Name_Len - 1) = ".ad"
2811 and then (Name_Buffer (Name_Len) = 'b'
2813 Name_Buffer (Name_Len) = 's');
2816 -- Start of processing for Compile
2819 Enter_Into_Obsoleted (S);
2821 -- By default, Syntax_Only is False
2823 Syntax_Only := False;
2825 for J in Args'Range loop
2826 if Args (J).all = "-gnats" then
2828 -- If we compile with -gnats, the bind step and the link step
2829 -- are inhibited. Also, we set Syntax_Only to True, so that
2830 -- we don't fail when we don't find the ALI file, after
2833 Do_Bind_Step := False;
2834 Do_Link_Step := False;
2835 Syntax_Only := True;
2837 elsif Args (J).all = "-gnatc" then
2839 -- If we compile with -gnatc, the bind step and the link step
2840 -- are inhibited. We set Syntax_Only to False for the case when
2841 -- -gnats was previously specified.
2843 Do_Bind_Step := False;
2844 Do_Link_Step := False;
2845 Syntax_Only := False;
2849 Comp_Args (Comp_Next) := new String'("-gnatea");
2850 Comp_Next := Comp_Next + 1;
2852 Comp_Args (Comp_Next) := Comp_Flag;
2853 Comp_Next := Comp_Next + 1;
2855 -- Optimize the simple case where the gcc command line looks like
2856 -- gcc -c -I. ... -I- file.adb
2858 -- gcc -c ... file.adb
2860 if Args (Args'First).all = "-I" & Normalized_CWD
2861 and then Args (Args'Last).all = "-I-"
2862 and then S = Strip_Directory (S)
2864 Comp_Last := Comp_Next + Args'Length - 3;
2865 Arg_Index := Args'First + 1;
2868 Comp_Last := Comp_Next + Args'Length - 1;
2869 Arg_Index := Args'First;
2872 -- Make a deep copy of the arguments, because Normalize_Arguments
2873 -- may deallocate some arguments.
2875 for J in Comp_Next .. Comp_Last loop
2876 Comp_Args (J) := new String'(Args (Arg_Index).all);
2877 Arg_Index := Arg_Index + 1;
2880 -- Set -gnatpg for predefined files (for this purpose the renamings
2881 -- such as Text_IO do not count as predefined). Note that we strip
2882 -- the directory name from the source file name because the call to
2883 -- Fname.Is_Predefined_File_Name cannot deal with directory prefixes.
2886 Fname : constant File_Name_Type := Strip_Directory (S);
2889 if Is_Predefined_File_Name (Fname, False) then
2890 if Check_Readonly_Files then
2891 Comp_Args (Comp_Args'First + 2 .. Comp_Last + 1) :=
2892 Comp_Args (Comp_Args'First + 1 .. Comp_Last);
2893 Comp_Last := Comp_Last + 1;
2894 Comp_Args (Comp_Args'First + 1) := GNAT_Flag;
2898 ("not allowed to compile """ &
2899 Get_Name_String (Fname) &
2900 """; use -a switch, or compile file with " &
2901 """-gnatg"" switch");
2906 -- Now check if the file name has one of the suffixes familiar to
2907 -- the gcc driver. If this is not the case then add the ada flag
2910 if not Ada_File_Name (S) and then not Targparm.AAMP_On_Target then
2911 Comp_Last := Comp_Last + 1;
2912 Comp_Args (Comp_Last) := Ada_Flag_1;
2913 Comp_Last := Comp_Last + 1;
2914 Comp_Args (Comp_Last) := Ada_Flag_2;
2917 if Source_Index /= 0 then
2919 Num : constant String := Source_Index'Img;
2921 Comp_Last := Comp_Last + 1;
2922 Comp_Args (Comp_Last) :=
2923 new String'("-gnateI" & Num (Num'First + 1 .. Num'Last));
2927 if Source_Index /= 0
2928 or else L /= Strip_Directory (L)
2929 or else Object_Directory_Path /= null
2931 -- Build -o argument
2933 Get_Name_String (L);
2935 for J in reverse 1 .. Name_Len loop
2936 if Name_Buffer (J) = '.' then
2937 Name_Len := J + Object_Suffix'Length - 1;
2938 Name_Buffer (J .. Name_Len) := Object_Suffix;
2943 Comp_Last := Comp_Last + 1;
2944 Comp_Args (Comp_Last) := Output_Flag;
2945 Comp_Last := Comp_Last + 1;
2947 -- If an object directory was specified, prepend the object file
2948 -- name with this object directory.
2950 if Object_Directory_Path /= null then
2951 Comp_Args (Comp_Last) :=
2952 new String'(Object_Directory_Path.all &
2953 Name_Buffer (1 .. Name_Len));
2956 Comp_Args (Comp_Last) :=
2957 new String'(Name_Buffer (1 .. Name_Len));
2961 if Create_Mapping_File and then Mapping_File_Arg /= null then
2962 Comp_Last := Comp_Last + 1;
2963 Comp_Args (Comp_Last) := new String'(Mapping_File_Arg.all);
2966 Get_Name_String (S);
2968 Comp_Last := Comp_Last + 1;
2969 Comp_Args (Comp_Last) := new String'(Name_Buffer (1 .. Name_Len));
2971 -- Change to object directory of the project file, if necessary
2973 if Project /= No_Project then
2974 Change_To_Object_Directory (Project);
2977 GNAT.OS_Lib.Normalize_Arguments (Comp_Args (Args'First .. Comp_Last));
2979 Comp_Last := Comp_Last + 1;
2980 Comp_Args (Comp_Last) := new String'("-gnatez");
2982 Display (Gcc.all, Comp_Args (Args'First .. Comp_Last));
2984 if Gcc_Path = null then
2985 Make_Failed ("error, unable to locate " & Gcc.all);
2989 GNAT.OS_Lib.Non_Blocking_Spawn
2990 (Gcc_Path.all, Comp_Args (Args'First .. Comp_Last));
2993 -------------------------------
2994 -- Fill_Queue_From_ALI_Files --
2995 -------------------------------
2997 procedure Fill_Queue_From_ALI_Files is
3000 Sfile : File_Name_Type;
3001 Uname : Unit_Name_Type;
3002 Unit_Name : Name_Id;
3003 Uid : Prj.Unit_Index;
3005 while Good_ALI_Present loop
3006 ALI := Get_Next_Good_ALI;
3007 Source_Index := Unit_Index_Of (ALIs.Table (ALI).Afile);
3009 -- If we are processing the library file corresponding to the
3010 -- main source file check if this source can be a main unit.
3012 if ALIs.Table (ALI).Sfile = Main_Source
3013 and then Source_Index = Main_Index
3015 Main_Unit := ALIs.Table (ALI).Main_Program /= None;
3018 -- The following adds the standard library (s-stalib) to the
3019 -- list of files to be handled by gnatmake: this file and any
3020 -- files it depends on are always included in every bind,
3021 -- even if they are not in the explicit dependency list.
3022 -- Of course, it is not added if Suppress_Standard_Library
3025 -- However, to avoid annoying output about s-stalib.ali being
3026 -- read only, when "-v" is used, we add the standard library
3027 -- only when "-a" is used.
3029 if Need_To_Check_Standard_Library then
3030 Check_Standard_Library;
3033 -- Now insert in the Q the unmarked source files (i.e. those
3034 -- which have never been inserted in the Q and hence never
3035 -- considered). Only do that if Unique_Compile is False.
3037 if not Unique_Compile then
3039 ALIs.Table (ALI).First_Unit .. ALIs.Table (ALI).Last_Unit
3042 Units.Table (J).First_With .. Units.Table (J).Last_With
3044 Sfile := Withs.Table (K).Sfile;
3045 Uname := Withs.Table (K).Uname;
3047 -- If project files are used, find the proper source
3048 -- to compile, in case Sfile is the spec, but there
3051 if Main_Project /= No_Project then
3052 Get_Name_String (Uname);
3053 Name_Len := Name_Len - 2;
3054 Unit_Name := Name_Find;
3056 Units_Htable.Get (Project_Tree.Units_HT, Unit_Name);
3058 if Uid /= Prj.No_Unit_Index then
3059 if Uid.File_Names (Impl) /= null
3060 and then not Uid.File_Names (Impl).Locally_Removed
3062 Sfile := Uid.File_Names (Impl).File;
3063 Source_Index := Uid.File_Names (Impl).Index;
3065 elsif Uid.File_Names (Spec) /= null
3066 and then not Uid.File_Names (Spec).Locally_Removed
3068 Sfile := Uid.File_Names (Spec).File;
3069 Source_Index := Uid.File_Names (Spec).Index;
3074 Dependencies.Append ((ALIs.Table (ALI).Sfile, Sfile));
3076 if Is_In_Obsoleted (Sfile) then
3077 Executable_Obsolete := True;
3080 if Sfile = No_File then
3081 Debug_Msg ("Skipping generic:", Withs.Table (K).Uname);
3084 Source_Index := Unit_Index_Of (Withs.Table (K).Afile);
3086 if Is_Marked (Sfile, Source_Index) then
3087 Debug_Msg ("Skipping marked file:", Sfile);
3089 elsif not Check_Readonly_Files
3090 and then Is_Internal_File_Name (Sfile, False)
3092 Debug_Msg ("Skipping internal file:", Sfile);
3096 (Sfile, Withs.Table (K).Uname, Source_Index);
3097 Mark (Sfile, Source_Index);
3104 end Fill_Queue_From_ALI_Files;
3106 ----------------------
3107 -- Get_Mapping_File --
3108 ----------------------
3110 procedure Get_Mapping_File (Project : Project_Id) is
3111 Data : Project_Compilation_Access;
3114 Data := Project_Compilation_Htable.Get (Project_Compilation, Project);
3116 -- If there is a mapping file ready to be reused, reuse it
3118 if Data.Last_Free_Indices > 0 then
3119 Mfile := Data.Free_Mapping_File_Indices (Data.Last_Free_Indices);
3120 Data.Last_Free_Indices := Data.Last_Free_Indices - 1;
3122 -- Otherwise, create and initialize a new one
3126 (Project => Project, Data => Data.all, File_Index => Mfile);
3129 -- Put the name in the mapping file argument for the invocation
3132 Free (Mapping_File_Arg);
3134 new String'("-gnatem=" &
3135 Get_Name_String (Data.Mapping_File_Names (Mfile)));
3136 end Get_Mapping_File;
3138 -----------------------
3139 -- Get_Next_Good_ALI --
3140 -----------------------
3142 function Get_Next_Good_ALI return ALI_Id is
3146 pragma Assert (Good_ALI_Present);
3147 ALI := Good_ALI.Table (Good_ALI.Last);
3148 Good_ALI.Decrement_Last;
3150 end Get_Next_Good_ALI;
3152 ----------------------
3153 -- Good_ALI_Present --
3154 ----------------------
3156 function Good_ALI_Present return Boolean is
3158 return Good_ALI.First <= Good_ALI.Last;
3159 end Good_ALI_Present;
3161 --------------------------------
3162 -- Must_Exit_Because_Of_Error --
3163 --------------------------------
3165 function Must_Exit_Because_Of_Error return Boolean is
3166 Data : Compilation_Data;
3169 if Bad_Compilation_Count > 0 and then not Keep_Going then
3170 while Outstanding_Compiles > 0 loop
3171 Await_Compile (Data, Success);
3174 Record_Failure (Data.Full_Source_File, Data.Source_Unit);
3182 end Must_Exit_Because_Of_Error;
3184 --------------------
3185 -- Record_Failure --
3186 --------------------
3188 procedure Record_Failure
3189 (File : File_Name_Type;
3190 Unit : Unit_Name_Type;
3191 Found : Boolean := True)
3194 Bad_Compilation.Increment_Last;
3195 Bad_Compilation.Table (Bad_Compilation.Last) := (File, Unit, Found);
3198 ---------------------
3199 -- Record_Good_ALI --
3200 ---------------------
3202 procedure Record_Good_ALI (A : ALI_Id) is
3204 Good_ALI.Increment_Last;
3205 Good_ALI.Table (Good_ALI.Last) := A;
3206 end Record_Good_ALI;
3208 -------------------------------
3209 -- Start_Compile_If_Possible --
3210 -------------------------------
3212 function Start_Compile_If_Possible
3213 (Args : Argument_List) return Boolean
3215 In_Lib_Dir : Boolean;
3216 Need_To_Compile : Boolean;
3218 Process_Created : Boolean;
3220 Source_File : File_Name_Type;
3221 Full_Source_File : File_Name_Type;
3222 Source_File_Attr : aliased File_Attributes;
3223 -- The full name of the source file and its attributes (size, ...)
3225 Source_Unit : Unit_Name_Type;
3227 -- Index of the current unit in the current source file
3229 Lib_File : File_Name_Type;
3230 Full_Lib_File : File_Name_Type;
3231 Lib_File_Attr : aliased File_Attributes;
3232 Read_Only : Boolean := False;
3234 -- The ALI file and its attributes (size, stamp, ...)
3236 Obj_File : File_Name_Type;
3237 Obj_Stamp : Time_Stamp_Type;
3241 if not Empty_Q and then Outstanding_Compiles < Max_Process then
3242 Extract_From_Q (Source_File, Source_Unit, Source_Index);
3244 Osint.Full_Source_Name
3246 Full_File => Full_Source_File,
3247 Attr => Source_File_Attr'Access);
3249 Lib_File := Osint.Lib_File_Name (Source_File, Source_Index);
3250 Osint.Full_Lib_File_Name
3252 Lib_File => Full_Lib_File,
3253 Attr => Lib_File_Attr);
3255 -- If this source has already been compiled, the executable is
3258 if Is_In_Obsoleted (Source_File) then
3259 Executable_Obsolete := True;
3262 In_Lib_Dir := Full_Lib_File /= No_File
3263 and then In_Ada_Lib_Dir (Full_Lib_File);
3265 -- Since the following requires a system call, we precompute it
3268 if not In_Lib_Dir then
3269 if Full_Lib_File /= No_File
3270 and then not Check_Readonly_Files
3272 Get_Name_String (Full_Lib_File);
3273 Name_Buffer (Name_Len + 1) := ASCII.NUL;
3274 Read_Only := not Is_Writable_File
3275 (Name_Buffer'Address, Lib_File_Attr'Access);
3281 -- If the library file is an Ada library skip it
3286 "is in an Ada library",
3288 Minimum_Verbosity => Opt.High);
3290 -- If the library file is a read-only library skip it, but only
3291 -- if, when using project files, this library file is in the
3292 -- right object directory (a read-only ALI file in the object
3293 -- directory of a project being extended must not be skipped).
3296 and then Is_In_Object_Directory (Source_File, Full_Lib_File)
3300 "is a read-only library",
3302 Minimum_Verbosity => Opt.High);
3304 -- The source file that we are checking cannot be located
3306 elsif Full_Source_File = No_File then
3307 Record_Failure (Source_File, Source_Unit, False);
3309 -- Source and library files can be located but are internal
3312 elsif not Check_Readonly_Files
3313 and then Full_Lib_File /= No_File
3314 and then Is_Internal_File_Name (Source_File, False)
3316 if Force_Compilations then
3318 ("not allowed to compile """ &
3319 Get_Name_String (Source_File) &
3320 """; use -a switch, or compile file with " &
3321 """-gnatg"" switch");
3326 "is an internal library",
3328 Minimum_Verbosity => Opt.High);
3330 -- The source file that we are checking can be located
3333 Collect_Arguments (Source_File, Source_Index,
3334 Source_File = Main_Source, Args);
3336 -- Do nothing if project of source is externally built
3338 if Arguments_Project = No_Project
3339 or else not Arguments_Project.Externally_Built
3341 -- Don't waste any time if we have to recompile anyway
3343 Obj_Stamp := Empty_Time_Stamp;
3344 Need_To_Compile := Force_Compilations;
3346 if not Force_Compilations then
3347 Check (Source_File => Source_File,
3348 Source_Index => Source_Index,
3349 Is_Main_Source => Source_File = Main_Source,
3351 Lib_File => Lib_File,
3352 Full_Lib_File => Full_Lib_File,
3353 Lib_File_Attr => Lib_File_Attr'Access,
3354 Read_Only => Read_Only,
3357 O_Stamp => Obj_Stamp);
3358 Need_To_Compile := (ALI = No_ALI_Id);
3361 if not Need_To_Compile then
3362 -- The ALI file is up-to-date. Record its Id
3364 Record_Good_ALI (ALI);
3366 -- Record the time stamp of the most recent object
3367 -- file as long as no (re)compilations are needed.
3369 if First_Compiled_File = No_File
3370 and then (Most_Recent_Obj_File = No_File
3371 or else Obj_Stamp > Most_Recent_Obj_Stamp)
3373 Most_Recent_Obj_File := Obj_File;
3374 Most_Recent_Obj_Stamp := Obj_Stamp;
3378 -- Check that switch -x has been used if a source
3379 -- outside of project files need to be compiled.
3381 if Main_Project /= No_Project
3382 and then Arguments_Project = No_Project
3383 and then not External_Unit_Compilation_Allowed
3385 Make_Failed ("external source ("
3386 & Get_Name_String (Source_File)
3387 & ") is not part of any project;"
3388 & " cannot be compiled without"
3389 & " gnatmake switch -x");
3392 -- Is this the first file we have to compile?
3394 if First_Compiled_File = No_File then
3395 First_Compiled_File := Full_Source_File;
3396 Most_Recent_Obj_File := No_File;
3398 if Do_Not_Execute then
3399 -- Exit the main loop
3405 -- Compute where the ALI file must be generated in
3406 -- In_Place_Mode (this does not require to know the
3407 -- location of the object directory)
3409 if In_Place_Mode then
3410 if Full_Lib_File = No_File then
3411 -- If the library file was not found, then save
3412 -- the library file near the source file.
3414 Lib_File := Osint.Lib_File_Name
3415 (Full_Source_File, Source_Index);
3416 Full_Lib_File := Lib_File;
3419 -- If the library file was found, then save the
3420 -- library file in the same place.
3422 Lib_File := Full_Lib_File;
3426 -- Start the compilation and record it. We can do
3427 -- this because there is at least one free process.
3428 -- This might change the current directory
3430 Collect_Arguments_And_Compile
3431 (Full_Source_File => Full_Source_File,
3432 Lib_File => Lib_File,
3433 Source_Index => Source_Index,
3435 Process_Created => Process_Created);
3437 -- Compute where the ALI file will be generated (for
3438 -- cases that might require to know the current
3439 -- directory). The current directory might be changed
3440 -- when compiling other files so we cannot rely on it
3441 -- being the same to find the resulting ALI file.
3443 if not In_Place_Mode then
3444 -- Compute the expected location of the ALI file. This
3445 -- can be from several places:
3446 -- -i => in place mode. In such a case,
3447 -- Full_Lib_File has already been set above
3448 -- -D => if specified
3449 -- or defaults in current dir
3450 -- We could simply use a call similar to
3451 -- Osint.Full_Lib_File_Name (Lib_File)
3452 -- but that involves system calls and is thus slower
3454 if Object_Directory_Path /= null then
3456 Add_Str_To_Name_Buffer (Object_Directory_Path.all);
3457 Add_Str_To_Name_Buffer (Get_Name_String (Lib_File));
3458 Full_Lib_File := Name_Find;
3460 if Project_Of_Current_Object_Directory /=
3464 (Project_Of_Current_Object_Directory
3465 .Object_Directory.Name);
3466 Add_Str_To_Name_Buffer
3467 (Get_Name_String (Lib_File));
3468 Full_Lib_File := Name_Find;
3470 Full_Lib_File := Lib_File;
3476 Lib_File_Attr := Unknown_Attributes;
3478 -- Make sure we could successfully start
3481 if Process_Created then
3482 if Pid = Invalid_Pid then
3483 Record_Failure (Full_Source_File, Source_Unit);
3487 Sfile => Full_Source_File,
3489 Uname => Source_Unit,
3491 Full_Lib_File => Full_Lib_File,
3492 Lib_File_Attr => Lib_File_Attr);
3500 end Start_Compile_If_Possible;
3502 -----------------------------
3503 -- Wait_For_Available_Slot --
3504 -----------------------------
3506 procedure Wait_For_Available_Slot is
3507 Compilation_OK : Boolean;
3508 Text : Text_Buffer_Ptr;
3510 Data : Compilation_Data;
3513 if Outstanding_Compiles = Max_Process
3515 and then not Good_ALI_Present
3516 and then Outstanding_Compiles > 0)
3518 Await_Compile (Data, Compilation_OK);
3520 if not Compilation_OK then
3521 Record_Failure (Data.Full_Source_File, Data.Source_Unit);
3524 if Compilation_OK or else Keep_Going then
3526 -- Re-read the updated library file
3529 Saved_Object_Consistency : constant Boolean :=
3530 Check_Object_Consistency;
3533 -- If compilation was not OK, or if output is not an object
3534 -- file and we don't do the bind step, don't check for
3535 -- object consistency.
3537 Check_Object_Consistency :=
3538 Check_Object_Consistency
3540 and (Output_Is_Object or Do_Bind_Step);
3542 Text := Read_Library_Info_From_Full
3543 (Data.Full_Lib_File, Data.Lib_File_Attr'Access);
3545 -- Restore Check_Object_Consistency to its initial value
3547 Check_Object_Consistency := Saved_Object_Consistency;
3550 -- If an ALI file was generated by this compilation, scan
3551 -- the ALI file and record it.
3553 -- If the scan fails, a previous ali file is inconsistent with
3554 -- the unit just compiled.
3556 if Text /= null then
3558 (Data.Lib_File, Text, Ignore_ED => False, Err => True);
3560 if ALI = No_ALI_Id then
3562 -- Record a failure only if not already done
3564 if Compilation_OK then
3567 "incompatible ALI file, please recompile");
3569 (Data.Full_Source_File, Data.Source_Unit);
3573 Record_Good_ALI (ALI);
3578 -- If we could not read the ALI file that was just generated
3579 -- then there could be a problem reading either the ALI or the
3580 -- corresponding object file (if Check_Object_Consistency is
3581 -- set Read_Library_Info checks that the time stamp of the
3582 -- object file is more recent than that of the ALI). However,
3583 -- we record a failure only if not already done.
3586 if Compilation_OK and not Syntax_Only then
3589 "WARNING: ALI or object file not found after compile");
3590 Record_Failure (Data.Full_Source_File, Data.Source_Unit);
3595 end Wait_For_Available_Slot;
3597 -- Start of processing for Compile_Sources
3600 pragma Assert (Args'First = 1);
3602 Outstanding_Compiles := 0;
3603 Running_Compile := new Comp_Data_Arr (1 .. Max_Process);
3605 -- Package and Queue initializations
3609 if First_Q_Initialization then
3613 if Initialize_ALI_Data then
3615 Initialize_ALI_Source;
3618 -- The following two flags affect the behavior of ALI.Set_Source_Table.
3619 -- We set Check_Source_Files to True to ensure that source file
3620 -- time stamps are checked, and we set All_Sources to False to
3621 -- avoid checking the presence of the source files listed in the
3622 -- source dependency section of an ali file (which would be a mistake
3623 -- since the ali file may be obsolete).
3625 Check_Source_Files := True;
3626 All_Sources := False;
3628 -- Only insert in the Q if it is not already done, to avoid simultaneous
3629 -- compilations if -jnnn is used.
3631 if not Is_Marked (Main_Source, Main_Index) then
3632 Insert_Q (Main_Source, Index => Main_Index);
3633 Mark (Main_Source, Main_Index);
3636 First_Compiled_File := No_File;
3637 Most_Recent_Obj_File := No_File;
3638 Most_Recent_Obj_Stamp := Empty_Time_Stamp;
3641 -- Keep looping until there is no more work to do (the Q is empty)
3642 -- and all the outstanding compilations have terminated.
3644 Make_Loop : while not Empty_Q or else Outstanding_Compiles > 0 loop
3645 exit Make_Loop when Must_Exit_Because_Of_Error;
3646 exit Make_Loop when Start_Compile_If_Possible (Args);
3648 Wait_For_Available_Slot;
3650 -- ??? Should be done as soon as we add a Good_ALI, wouldn't it avoid
3651 -- the need for a list of good ALI?
3653 Fill_Queue_From_ALI_Files;
3655 if Display_Compilation_Progress then
3656 Write_Str ("completed ");
3657 Write_Int (Int (Q_Front));
3658 Write_Str (" out of ");
3659 Write_Int (Int (Q.Last));
3661 Write_Int (Int ((Q_Front * 100) / (Q.Last - Q.First)));
3662 Write_Str ("%)...");
3667 Compilation_Failures := Bad_Compilation_Count;
3669 -- Compilation is finished
3671 -- Delete any temporary configuration pragma file
3673 if not Debug.Debug_Flag_N then
3674 Delete_Temp_Config_Files;
3676 end Compile_Sources;
3678 ----------------------------------
3679 -- Configuration_Pragmas_Switch --
3680 ----------------------------------
3682 function Configuration_Pragmas_Switch
3683 (For_Project : Project_Id) return Argument_List
3685 The_Packages : Package_Id;
3686 Gnatmake : Package_Id;
3687 Compiler : Package_Id;
3689 Global_Attribute : Variable_Value := Nil_Variable_Value;
3690 Local_Attribute : Variable_Value := Nil_Variable_Value;
3692 Global_Attribute_Present : Boolean := False;
3693 Local_Attribute_Present : Boolean := False;
3695 Result : Argument_List (1 .. 3);
3696 Last : Natural := 0;
3698 function Absolute_Path
3699 (Path : Path_Name_Type;
3700 Project : Project_Id) return String;
3701 -- Returns an absolute path for a configuration pragmas file
3707 function Absolute_Path
3708 (Path : Path_Name_Type;
3709 Project : Project_Id) return String
3712 Get_Name_String (Path);
3715 Path_Name : constant String := Name_Buffer (1 .. Name_Len);
3718 if Is_Absolute_Path (Path_Name) then
3723 Parent_Directory : constant String :=
3724 Get_Name_String (Project.Directory.Display_Name);
3727 if Parent_Directory (Parent_Directory'Last) =
3730 return Parent_Directory & Path_Name;
3733 return Parent_Directory & Directory_Separator & Path_Name;
3740 -- Start of processing for Configuration_Pragmas_Switch
3743 Prj.Env.Create_Config_Pragmas_File
3744 (For_Project, Project_Tree);
3746 if For_Project.Config_File_Name /= No_Path then
3747 Temporary_Config_File := For_Project.Config_File_Temp;
3751 ("-gnatec=" & Get_Name_String (For_Project.Config_File_Name));
3754 Temporary_Config_File := False;
3757 -- Check for attribute Builder'Global_Configuration_Pragmas
3759 The_Packages := Main_Project.Decl.Packages;
3762 (Name => Name_Builder,
3763 In_Packages => The_Packages,
3764 In_Tree => Project_Tree);
3766 if Gnatmake /= No_Package then
3767 Global_Attribute := Prj.Util.Value_Of
3768 (Variable_Name => Name_Global_Configuration_Pragmas,
3769 In_Variables => Project_Tree.Packages.Table
3770 (Gnatmake).Decl.Attributes,
3771 In_Tree => Project_Tree);
3772 Global_Attribute_Present :=
3773 Global_Attribute /= Nil_Variable_Value
3774 and then Get_Name_String (Global_Attribute.Value) /= "";
3776 if Global_Attribute_Present then
3778 Path : constant String :=
3780 (Path_Name_Type (Global_Attribute.Value),
3781 Global_Attribute.Project);
3783 if not Is_Regular_File (Path) then
3784 if Debug.Debug_Flag_F then
3786 ("cannot find configuration pragmas file "
3787 & File_Name (Path));
3790 ("cannot find configuration pragmas file " & Path);
3795 Result (Last) := new String'("-gnatec=" & Path);
3800 -- Check for attribute Compiler'Local_Configuration_Pragmas
3802 The_Packages := For_Project.Decl.Packages;
3805 (Name => Name_Compiler,
3806 In_Packages => The_Packages,
3807 In_Tree => Project_Tree);
3809 if Compiler /= No_Package then
3810 Local_Attribute := Prj.Util.Value_Of
3811 (Variable_Name => Name_Local_Configuration_Pragmas,
3812 In_Variables => Project_Tree.Packages.Table
3813 (Compiler).Decl.Attributes,
3814 In_Tree => Project_Tree);
3815 Local_Attribute_Present :=
3816 Local_Attribute /= Nil_Variable_Value
3817 and then Get_Name_String (Local_Attribute.Value) /= "";
3819 if Local_Attribute_Present then
3821 Path : constant String :=
3823 (Path_Name_Type (Local_Attribute.Value),
3824 Local_Attribute.Project);
3826 if not Is_Regular_File (Path) then
3827 if Debug.Debug_Flag_F then
3829 ("cannot find configuration pragmas file "
3830 & File_Name (Path));
3834 ("cannot find configuration pragmas file " & Path);
3839 Result (Last) := new String'("-gnatec=" & Path);
3844 return Result (1 .. Last);
3845 end Configuration_Pragmas_Switch;
3851 procedure Debug_Msg (S : String; N : Name_Id) is
3853 if Debug.Debug_Flag_W then
3854 Write_Str (" ... ");
3862 procedure Debug_Msg (S : String; N : File_Name_Type) is
3864 Debug_Msg (S, Name_Id (N));
3867 procedure Debug_Msg (S : String; N : Unit_Name_Type) is
3869 Debug_Msg (S, Name_Id (N));
3872 ---------------------------
3873 -- Delete_All_Temp_Files --
3874 ---------------------------
3876 procedure Delete_All_Temp_Files is
3878 if not Debug.Debug_Flag_N then
3879 Delete_Temp_Config_Files;
3880 Prj.Delete_All_Temp_Files (Project_Tree);
3882 end Delete_All_Temp_Files;
3884 ------------------------------
3885 -- Delete_Temp_Config_Files --
3886 ------------------------------
3888 procedure Delete_Temp_Config_Files is
3890 Proj : Project_List;
3891 pragma Warnings (Off, Success);
3894 -- The caller is responsible for ensuring that Debug_Flag_N is False
3896 pragma Assert (not Debug.Debug_Flag_N);
3898 if Main_Project /= No_Project then
3899 Proj := Project_Tree.Projects;
3900 while Proj /= null loop
3901 if Proj.Project.Config_File_Temp then
3902 Delete_Temporary_File
3903 (Project_Tree, Proj.Project.Config_File_Name);
3905 -- Make sure that we don't have a config file for this project,
3906 -- in case there are several mains. In this case, we will
3907 -- recreate another config file: we cannot reuse the one that
3910 Proj.Project.Config_Checked := False;
3911 Proj.Project.Config_File_Name := No_Path;
3912 Proj.Project.Config_File_Temp := False;
3917 end Delete_Temp_Config_Files;
3923 procedure Display (Program : String; Args : Argument_List) is
3925 pragma Assert (Args'First = 1);
3927 if Display_Executed_Programs then
3928 Write_Str (Program);
3930 for J in Args'Range loop
3932 -- Never display -gnatea nor -gnatez
3934 if Args (J).all /= "-gnatea"
3936 Args (J).all /= "-gnatez"
3938 -- Do not display the mapping file argument automatically
3939 -- created when using a project file.
3941 if Main_Project = No_Project
3942 or else Debug.Debug_Flag_N
3943 or else Args (J)'Length < 8
3945 Args (J) (Args (J)'First .. Args (J)'First + 6) /= "-gnatem"
3947 -- When -dn is not specified, do not display the config
3948 -- pragmas switch (-gnatec) for the temporary file created
3949 -- by the project manager (always the first -gnatec switch).
3950 -- Reset Temporary_Config_File to False so that the eventual
3951 -- other -gnatec switches will be displayed.
3953 if (not Debug.Debug_Flag_N)
3954 and then Temporary_Config_File
3955 and then Args (J)'Length > 7
3956 and then Args (J) (Args (J)'First .. Args (J)'First + 6)
3959 Temporary_Config_File := False;
3961 -- Do not display the -F=mapping_file switch for gnatbind
3962 -- if -dn is not specified.
3964 elsif Debug.Debug_Flag_N
3965 or else Args (J)'Length < 4
3967 Args (J) (Args (J)'First .. Args (J)'First + 2) /= "-F="
3971 -- If -df is used, only display file names, not path
3974 if Debug.Debug_Flag_F then
3976 Equal_Pos : Natural;
3978 Equal_Pos := Args (J)'First - 1;
3979 for K in Args (J)'Range loop
3980 if Args (J) (K) = '=' then
3987 (Args (J) (Equal_Pos + 1 .. Args (J)'Last))
3990 (Args (J) (Args (J)'First .. Equal_Pos));
3994 (Equal_Pos + 1 .. Args (J)'Last)));
3997 Write_Str (Args (J).all);
4002 Write_Str (Args (J).all);
4013 ----------------------
4014 -- Display_Commands --
4015 ----------------------
4017 procedure Display_Commands (Display : Boolean := True) is
4019 Display_Executed_Programs := Display;
4020 end Display_Commands;
4026 function Empty_Q return Boolean is
4028 if Debug.Debug_Flag_P then
4029 Write_Str (" Q := [");
4031 for J in Q_Front .. Q.Last - 1 loop
4033 Write_Name (Q.Table (J).File);
4042 return Q_Front >= Q.Last;
4045 --------------------------
4046 -- Enter_Into_Obsoleted --
4047 --------------------------
4049 procedure Enter_Into_Obsoleted (F : File_Name_Type) is
4050 Name : constant String := Get_Name_String (F);
4052 F2 : File_Name_Type;
4056 while First > Name'First
4057 and then Name (First - 1) /= Directory_Separator
4058 and then Name (First - 1) /= '/'
4063 if First /= Name'First then
4065 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
4072 Debug_Msg ("New entry in Obsoleted table:", F2);
4073 Obsoleted.Set (F2, True);
4074 end Enter_Into_Obsoleted;
4076 --------------------
4077 -- Extract_From_Q --
4078 --------------------
4080 procedure Extract_From_Q
4081 (Source_File : out File_Name_Type;
4082 Source_Unit : out Unit_Name_Type;
4083 Source_Index : out Int)
4085 File : constant File_Name_Type := Q.Table (Q_Front).File;
4086 Unit : constant Unit_Name_Type := Q.Table (Q_Front).Unit;
4087 Index : constant Int := Q.Table (Q_Front).Index;
4090 if Debug.Debug_Flag_Q then
4091 Write_Str (" Q := Q - [ ");
4103 Q_Front := Q_Front + 1;
4104 Source_File := File;
4105 Source_Unit := Unit;
4106 Source_Index := Index;
4113 procedure Gnatmake is
4114 Main_Source_File : File_Name_Type;
4115 -- The source file containing the main compilation unit
4117 Compilation_Failures : Natural;
4119 Total_Compilation_Failures : Natural := 0;
4121 Is_Main_Unit : Boolean;
4122 -- Set True by Compile_Sources if Main_Source_File can be a main unit
4124 Main_ALI_File : File_Name_Type;
4125 -- The ali file corresponding to Main_Source_File
4127 Executable : File_Name_Type := No_File;
4128 -- The file name of an executable
4130 Non_Std_Executable : Boolean := False;
4131 -- Non_Std_Executable is set to True when there is a possibility that
4132 -- the linker will not choose the correct executable file name.
4134 Current_Work_Dir : constant String_Access :=
4135 new String'(Get_Current_Dir);
4136 -- The current working directory, used to modify some relative path
4137 -- switches on the command line when a project file is used.
4139 Current_Main_Index : Int := 0;
4140 -- If not zero, the index of the current main unit in its source file
4142 Stand_Alone_Libraries : Boolean := False;
4143 -- Set to True when there are Stand-Alone Libraries, so that gnatbind
4144 -- is invoked with the -F switch to force checking of elaboration flags.
4146 Mapping_Path : Path_Name_Type := No_Path;
4147 -- The path name of the mapping file
4149 Project_Node_Tree : Project_Node_Tree_Ref;
4152 pragma Warnings (Off, Discard);
4154 procedure Check_Mains;
4155 -- Check that the main subprograms do exist and that they all
4156 -- belong to the same project file.
4158 procedure Create_Binder_Mapping_File
4159 (Args : in out Argument_List; Last_Arg : in out Natural);
4160 -- Create a binder mapping file and add the necessary switch
4166 procedure Check_Mains is
4167 Real_Main_Project : Project_Id := No_Project;
4168 -- The project of the first main
4170 Proj : Project_Id := No_Project;
4171 -- The project of the current main
4173 Real_Path : String_Access;
4182 Main : constant String := Mains.Next_Main;
4183 -- The name specified on the command line may include directory
4186 File_Name : constant String := Base_Name (Main);
4187 -- The simple file name of the current main
4189 Lang : Language_Ptr;
4192 exit when Main = "";
4194 -- Get the project of the current main
4196 Proj := Prj.Env.Project_Of
4197 (File_Name, Main_Project, Project_Tree);
4199 -- Fail if the current main is not a source of a project
4201 if Proj = No_Project then
4203 ("""" & Main & """ is not a source of any project");
4206 -- If there is directory information, check that the source
4207 -- exists and, if it does, that the path is the actual path
4208 -- of a source of a project.
4210 if Main /= File_Name then
4211 Lang := Get_Language_From_Name (Main_Project, "ada");
4215 (Main & Get_Name_String
4216 (Lang.Config.Naming_Data.Body_Suffix),
4218 if Real_Path = null then
4221 (Main & Get_Name_String
4222 (Lang.Config.Naming_Data.Spec_Suffix),
4226 if Real_Path = null then
4227 Real_Path := Locate_Regular_File (Main, "");
4230 -- Fail if the file cannot be found
4232 if Real_Path = null then
4233 Make_Failed ("file """ & Main & """ does not exist");
4237 Project_Path : constant String :=
4238 Prj.Env.File_Name_Of_Library_Unit_Body
4240 Project => Main_Project,
4241 In_Tree => Project_Tree,
4242 Main_Project_Only => False,
4244 Normed_Path : constant String :=
4247 Case_Sensitive => False);
4248 Proj_Path : constant String :=
4251 Case_Sensitive => False);
4256 -- Fail if it is not the correct path
4258 if Normed_Path /= Proj_Path then
4259 if Verbose_Mode then
4261 Write_Str (Normed_Path);
4263 Write_Line (Proj_Path);
4268 """ is not a source of any project");
4273 if not Unique_Compile then
4275 -- Record the project, if it is the first main
4277 if Real_Main_Project = No_Project then
4278 Real_Main_Project := Proj;
4280 elsif Proj /= Real_Main_Project then
4282 -- Fail, as the current main is not a source of the
4283 -- same project as the first main.
4287 """ is not a source of project " &
4288 Get_Name_String (Real_Main_Project.Name));
4293 -- If -u and -U are not used, we may have mains that are
4294 -- sources of a project that is not the one specified with
4297 if not Unique_Compile then
4298 Main_Project := Real_Main_Project;
4304 --------------------------------
4305 -- Create_Binder_Mapping_File --
4306 --------------------------------
4308 procedure Create_Binder_Mapping_File
4309 (Args : in out Argument_List; Last_Arg : in out Natural)
4311 Mapping_FD : File_Descriptor := Invalid_FD;
4312 -- A File Descriptor for an eventual mapping file
4314 ALI_Unit : Unit_Name_Type := No_Unit_Name;
4315 -- The unit name of an ALI file
4317 ALI_Name : File_Name_Type := No_File;
4318 -- The file name of the ALI file
4320 ALI_Project : Project_Id := No_Project;
4321 -- The project of the ALI file
4324 OK : Boolean := True;
4328 -- For call to Close
4331 Tempdir.Create_Temp_File (Mapping_FD, Mapping_Path);
4332 Record_Temp_File (Project_Tree, Mapping_Path);
4334 if Mapping_FD /= Invalid_FD then
4336 -- Traverse all units
4338 Unit := Units_Htable.Get_First (Project_Tree.Units_HT);
4340 while Unit /= No_Unit_Index loop
4341 if Unit.Name /= No_Name then
4343 -- If there is a body, put it in the mapping
4345 if Unit.File_Names (Impl) /= No_Source
4346 and then Unit.File_Names (Impl).Project /=
4349 Get_Name_String (Unit.Name);
4350 Add_Str_To_Name_Buffer ("%b");
4351 ALI_Unit := Name_Find;
4354 (Unit.File_Names (Impl).Display_File);
4355 ALI_Project := Unit.File_Names (Impl).Project;
4357 -- Otherwise, if there is a spec, put it in the mapping
4359 elsif Unit.File_Names (Spec) /= No_Source
4360 and then Unit.File_Names (Spec).Project /=
4363 Get_Name_String (Unit.Name);
4364 Add_Str_To_Name_Buffer ("%s");
4365 ALI_Unit := Name_Find;
4368 (Unit.File_Names (Spec).Display_File);
4369 ALI_Project := Unit.File_Names (Spec).Project;
4372 ALI_Name := No_File;
4375 -- If we have something to put in the mapping then do it
4376 -- now. However, if the project is extended, we don't put
4377 -- anything in the mapping file, because we don't know where
4378 -- the ALI file is: it might be in the extended project
4379 -- object directory as well as in the extending project
4380 -- object directory.
4382 if ALI_Name /= No_File
4383 and then ALI_Project.Extended_By = No_Project
4384 and then ALI_Project.Extends = No_Project
4386 -- First check if the ALI file exists. If it does not,
4387 -- do not put the unit in the mapping file.
4390 ALI : constant String := Get_Name_String (ALI_Name);
4393 -- For library projects, use the library directory,
4394 -- for other projects, use the object directory.
4396 if ALI_Project.Library then
4397 Get_Name_String (ALI_Project.Library_Dir.Name);
4400 (ALI_Project.Object_Directory.Name);
4404 Is_Directory_Separator (Name_Buffer (Name_Len))
4406 Add_Char_To_Name_Buffer (Directory_Separator);
4409 Add_Str_To_Name_Buffer (ALI);
4410 Add_Char_To_Name_Buffer (ASCII.LF);
4413 ALI_Path_Name : constant String :=
4414 Name_Buffer (1 .. Name_Len);
4418 (ALI_Path_Name (1 .. ALI_Path_Name'Last - 1))
4420 -- First line is the unit name
4422 Get_Name_String (ALI_Unit);
4423 Add_Char_To_Name_Buffer (ASCII.LF);
4427 Name_Buffer (1)'Address,
4429 OK := Bytes = Name_Len;
4433 -- Second line it the ALI file name
4435 Get_Name_String (ALI_Name);
4436 Add_Char_To_Name_Buffer (ASCII.LF);
4440 Name_Buffer (1)'Address,
4442 OK := (Bytes = Name_Len);
4446 -- Third line it the ALI path name
4451 ALI_Path_Name (1)'Address,
4452 ALI_Path_Name'Length);
4453 OK := (Bytes = ALI_Path_Name'Length);
4455 -- If OK is False, it means we were unable to
4456 -- write a line. No point in continuing with the
4466 Unit := Units_Htable.Get_Next (Project_Tree.Units_HT);
4469 Close (Mapping_FD, Status);
4471 OK := OK and Status;
4473 -- If the creation of the mapping file was successful, we add the
4474 -- switch to the arguments of gnatbind.
4477 Last_Arg := Last_Arg + 1;
4479 new String'("-F=" & Get_Name_String (Mapping_Path));
4482 end Create_Binder_Mapping_File;
4484 -- Start of processing for Gnatmake
4486 -- This body is very long, should be broken down???
4489 Install_Int_Handler (Sigint_Intercepted'Access);
4491 Do_Compile_Step := True;
4492 Do_Bind_Step := True;
4493 Do_Link_Step := True;
4497 Make.Initialize (Project_Node_Tree);
4499 Bind_Shared := No_Shared_Switch'Access;
4500 Link_With_Shared_Libgcc := No_Shared_Libgcc_Switch'Access;
4502 Failed_Links.Set_Last (0);
4503 Successful_Links.Set_Last (0);
4505 -- Special case when switch -B was specified
4507 if Build_Bind_And_Link_Full_Project then
4509 -- When switch -B is specified, there must be a project file
4511 if Main_Project = No_Project then
4512 Make_Failed ("-B cannot be used without a project file");
4514 -- No main program may be specified on the command line
4516 elsif Osint.Number_Of_Files /= 0 then
4517 Make_Failed ("-B cannot be used with a main specified on " &
4518 "the command line");
4520 -- And the project file cannot be a library project file
4522 elsif Main_Project.Library then
4523 Make_Failed ("-B cannot be used for a library project file");
4526 No_Main_Subprogram := True;
4527 Insert_Project_Sources
4528 (The_Project => Main_Project,
4529 All_Projects => Unique_Compile_All_Projects,
4532 -- If there are no sources to compile, we fail
4534 if Osint.Number_Of_Files = 0 then
4535 Make_Failed ("no sources to compile");
4538 -- Specify -n for gnatbind and add the ALI files of all the
4539 -- sources, except the one which is a fake main subprogram: this
4540 -- is the one for the binder generated file and it will be
4541 -- transmitted to gnatlink. These sources are those that are in
4544 Add_Switch ("-n", Binder, And_Save => True);
4546 for J in Q.First .. Q.Last - 1 loop
4549 (Lib_File_Name (Q.Table (J).File)),
4550 Binder, And_Save => True);
4554 elsif Main_Index /= 0 and then Osint.Number_Of_Files > 1 then
4555 Make_Failed ("cannot specify several mains with a multi-unit index");
4557 elsif Main_Project /= No_Project then
4559 -- If the main project file is a library project file, main(s) cannot
4560 -- be specified on the command line.
4562 if Osint.Number_Of_Files /= 0 then
4563 if Main_Project.Library
4564 and then not Unique_Compile
4565 and then ((not Make_Steps) or else Bind_Only or else Link_Only)
4567 Make_Failed ("cannot specify a main program " &
4568 "on the command line for a library project file");
4571 -- Check that each main on the command line is a source of a
4572 -- project file and, if there are several mains, each of them
4573 -- is a source of the same project file.
4578 -- If no mains have been specified on the command line, and we are
4579 -- using a project file, we either find the main(s) in attribute
4580 -- Main of the main project, or we put all the sources of the project
4584 if Main_Index /= 0 then
4585 Make_Failed ("cannot specify a multi-unit index but no main " &
4586 "on the command line");
4590 Value : String_List_Id := Main_Project.Mains;
4593 -- The attribute Main is an empty list or not specified, or
4594 -- else gnatmake was invoked with the switch "-u".
4596 if Value = Prj.Nil_String or else Unique_Compile then
4598 if (not Make_Steps) or else Compile_Only
4599 or else not Main_Project.Library
4601 -- First make sure that the binder and the linker will
4604 Do_Bind_Step := False;
4605 Do_Link_Step := False;
4607 -- Put all the sources in the queue
4609 No_Main_Subprogram := True;
4610 Insert_Project_Sources
4611 (The_Project => Main_Project,
4612 All_Projects => Unique_Compile_All_Projects,
4615 -- If no sources to compile, then there is nothing to do
4617 if Osint.Number_Of_Files = 0 then
4618 if not Quiet_Output then
4619 Osint.Write_Program_Name;
4620 Write_Line (": no sources to compile");
4623 Delete_All_Temp_Files;
4624 Exit_Program (E_Success);
4629 -- The attribute Main is not an empty list.
4630 -- Put all the main subprograms in the list as if they were
4631 -- specified on the command line. However, if attribute
4632 -- Languages includes a language other than Ada, only
4633 -- include the Ada mains; if there is no Ada main, compile
4634 -- all the sources of the project.
4637 Languages : constant Variable_Value :=
4640 Main_Project.Decl.Attributes,
4643 Current : String_List_Id;
4644 Element : String_Element;
4646 Foreign_Language : Boolean := False;
4647 At_Least_One_Main : Boolean := False;
4650 -- First, determine if there is a foreign language in
4651 -- attribute Languages.
4653 if not Languages.Default then
4654 Current := Languages.Values;
4657 while Current /= Nil_String loop
4658 Element := Project_Tree.String_Elements.
4660 Get_Name_String (Element.Value);
4661 To_Lower (Name_Buffer (1 .. Name_Len));
4663 if Name_Buffer (1 .. Name_Len) /= "ada" then
4664 Foreign_Language := True;
4665 exit Look_For_Foreign;
4668 Current := Element.Next;
4669 end loop Look_For_Foreign;
4672 -- Then, find all mains, or if there is a foreign
4673 -- language, all the Ada mains.
4675 while Value /= Prj.Nil_String loop
4677 (Project_Tree.String_Elements.Table (Value).Value);
4679 -- To know if a main is an Ada main, get its project.
4680 -- It should be the project specified on the command
4683 if (not Foreign_Language) or else
4685 (Name_Buffer (1 .. Name_Len),
4690 At_Least_One_Main := True;
4693 (Project_Tree.String_Elements.Table
4696 Project_Tree.String_Elements.Table
4700 Value := Project_Tree.String_Elements.Table
4704 -- If we did not get any main, it means that all mains
4705 -- in attribute Mains are in a foreign language and -B
4706 -- was not specified to gnatmake; so, we fail.
4708 if not At_Least_One_Main then
4710 ("no Ada mains, use -B to build foreign main");
4719 if Verbose_Mode then
4721 Display_Version ("GNATMAKE", "1995");
4724 if Main_Project /= No_Project
4725 and then Main_Project.Externally_Built
4728 ("nothing to do for a main project that is externally built");
4731 if Osint.Number_Of_Files = 0 then
4732 if Main_Project /= No_Project
4733 and then Main_Project.Library
4736 and then not Main_Project.Standalone_Library
4738 Make_Failed ("only stand-alone libraries may be bound");
4741 -- Add the default search directories to be able to find libgnat
4743 Osint.Add_Default_Search_Dirs;
4745 -- Get the target parameters, so that the correct binder generated
4746 -- files are generated if OpenVMS is the target.
4749 Targparm.Get_Target_Parameters;
4752 when Unrecoverable_Error =>
4753 Make_Failed ("*** make failed.");
4756 -- And bind and or link the library
4758 MLib.Prj.Build_Library
4759 (For_Project => Main_Project,
4760 In_Tree => Project_Tree,
4761 Gnatbind => Gnatbind.all,
4762 Gnatbind_Path => Gnatbind_Path,
4764 Gcc_Path => Gcc_Path,
4768 Delete_All_Temp_Files;
4769 Exit_Program (E_Success);
4772 -- Call Get_Target_Parameters to ensure that VM_Target and
4773 -- AAMP_On_Target get set before calling Usage.
4775 Targparm.Get_Target_Parameters;
4777 -- Output usage information if no files to compile
4780 Exit_Program (E_Fatal);
4784 -- If -M was specified, behave as if -n was specified
4786 if List_Dependencies then
4787 Do_Not_Execute := True;
4790 -- Note that Osint.M.Next_Main_Source will always return the (possibly
4791 -- abbreviated file) without any directory information.
4793 Main_Source_File := Next_Main_Source;
4795 if Current_File_Index /= No_Index then
4796 Main_Index := Current_File_Index;
4799 Add_Switch ("-I-", Compiler, And_Save => True);
4801 if Main_Project = No_Project then
4802 if Look_In_Primary_Dir then
4806 Normalize_Directory_Name
4807 (Get_Primary_Src_Search_Directory.all).all,
4808 Compiler, Append_Switch => False,
4814 -- If we use a project file, we have already checked that a main
4815 -- specified on the command line with directory information has the
4816 -- path name corresponding to a correct source in the project tree.
4817 -- So, we don't need the directory information to be taken into
4818 -- account by Find_File, and in fact it may lead to take the wrong
4819 -- sources for other compilation units, when there are extending
4822 Look_In_Primary_Dir := False;
4823 Add_Switch ("-I-", Binder, And_Save => True);
4826 -- If the user wants a program without a main subprogram, add the
4827 -- appropriate switch to the binder.
4829 if No_Main_Subprogram then
4830 Add_Switch ("-z", Binder, And_Save => True);
4833 if Main_Project /= No_Project then
4835 if Main_Project.Object_Directory /= No_Path_Information then
4836 -- Change current directory to object directory of main project
4838 Project_Of_Current_Object_Directory := No_Project;
4839 Change_To_Object_Directory (Main_Project);
4842 -- Source file lookups should be cached for efficiency.
4843 -- Source files are not supposed to change.
4845 Osint.Source_File_Data (Cache => True);
4847 -- Find the file name of the (first) main unit
4850 Main_Source_File_Name : constant String :=
4851 Get_Name_String (Main_Source_File);
4852 Main_Unit_File_Name : constant String :=
4853 Prj.Env.File_Name_Of_Library_Unit_Body
4854 (Name => Main_Source_File_Name,
4855 Project => Main_Project,
4856 In_Tree => Project_Tree,
4857 Main_Project_Only =>
4858 not Unique_Compile);
4860 The_Packages : constant Package_Id :=
4861 Main_Project.Decl.Packages;
4863 Builder_Package : constant Prj.Package_Id :=
4865 (Name => Name_Builder,
4866 In_Packages => The_Packages,
4867 In_Tree => Project_Tree);
4869 Binder_Package : constant Prj.Package_Id :=
4871 (Name => Name_Binder,
4872 In_Packages => The_Packages,
4873 In_Tree => Project_Tree);
4875 Linker_Package : constant Prj.Package_Id :=
4877 (Name => Name_Linker,
4878 In_Packages => The_Packages,
4879 In_Tree => Project_Tree);
4881 Default_Switches_Array : Array_Id;
4883 Global_Compilation_Array : Array_Element_Id;
4884 Global_Compilation_Elem : Array_Element;
4885 Global_Compilation_Switches : Variable_Value;
4888 -- We fail if we cannot find the main source file
4890 if Main_Unit_File_Name = "" then
4891 Make_Failed ('"' & Main_Source_File_Name
4892 & """ is not a unit of project "
4893 & Project_File_Name.all & ".");
4895 -- Remove any directory information from the main source file
4899 Pos : Natural := Main_Unit_File_Name'Last;
4903 exit when Pos < Main_Unit_File_Name'First or else
4904 Main_Unit_File_Name (Pos) = Directory_Separator;
4908 Name_Len := Main_Unit_File_Name'Last - Pos;
4910 Name_Buffer (1 .. Name_Len) :=
4912 (Pos + 1 .. Main_Unit_File_Name'Last);
4914 Main_Source_File := Name_Find;
4916 -- We only output the main source file if there is only one
4918 if Verbose_Mode and then Osint.Number_Of_Files = 1 then
4919 Write_Str ("Main source file: """);
4920 Write_Str (Main_Unit_File_Name
4921 (Pos + 1 .. Main_Unit_File_Name'Last));
4927 -- If there is a package Builder in the main project file, add
4928 -- the switches from it.
4930 if Builder_Package /= No_Package then
4932 Global_Compilation_Array := Prj.Util.Value_Of
4933 (Name => Name_Global_Compilation_Switches,
4934 In_Arrays => Project_Tree.Packages.Table
4935 (Builder_Package).Decl.Arrays,
4936 In_Tree => Project_Tree);
4938 Default_Switches_Array :=
4939 Project_Tree.Packages.Table
4940 (Builder_Package).Decl.Arrays;
4942 while Default_Switches_Array /= No_Array and then
4943 Project_Tree.Arrays.Table (Default_Switches_Array).Name /=
4944 Name_Default_Switches
4946 Default_Switches_Array :=
4947 Project_Tree.Arrays.Table (Default_Switches_Array).Next;
4950 if Global_Compilation_Array /= No_Array_Element and then
4951 Default_Switches_Array /= No_Array
4954 ("Default_Switches forbidden in presence of " &
4955 "Global_Compilation_Switches. Use Switches instead.",
4956 Project_Tree.Arrays.Table
4957 (Default_Switches_Array).Location);
4960 ("*** illegal combination of Builder attributes");
4963 -- If there is only one main, we attempt to get the gnatmake
4964 -- switches for this main (if any). If there are no specific
4965 -- switch for this particular main, get the general gnatmake
4966 -- switches (if any).
4968 if Osint.Number_Of_Files = 1 then
4969 if Verbose_Mode then
4970 Write_Str ("Adding gnatmake switches for """);
4971 Write_Str (Main_Unit_File_Name);
4976 (Project_Node_Tree => Project_Node_Tree,
4977 File_Name => Main_Unit_File_Name,
4978 Index => Main_Index,
4979 The_Package => Builder_Package,
4981 Unknown_Switches_To_The_Compiler =>
4982 Global_Compilation_Array = No_Array_Element);
4985 -- If there are several mains, we always get the general
4986 -- gnatmake switches (if any).
4988 -- Warn the user, if necessary, so that he is not surprised
4989 -- that specific switches are not taken into account.
4992 Defaults : constant Variable_Value :=
4996 Attribute_Or_Array_Name =>
4997 Name_Default_Switches,
5000 In_Tree => Project_Tree);
5002 Switches : constant Array_Element_Id :=
5004 (Name => Name_Switches,
5006 Project_Tree.Packages.Table
5007 (Builder_Package).Decl.Arrays,
5008 In_Tree => Project_Tree);
5010 Other_Switches : constant Variable_Value :=
5012 (Name => All_Other_Names,
5014 Attribute_Or_Array_Name
5016 In_Package => Builder_Package,
5017 In_Tree => Project_Tree);
5020 if Other_Switches /= Nil_Variable_Value then
5022 and then Switches /= No_Array_Element
5023 and then Project_Tree.Array_Elements.Table
5024 (Switches).Next /= No_Array_Element
5027 ("Warning: using Builder'Switches(others), "
5028 & "as there are several mains");
5032 (Project_Node_Tree => Project_Node_Tree,
5035 The_Package => Builder_Package,
5037 Unknown_Switches_To_The_Compiler => False);
5039 elsif Defaults /= Nil_Variable_Value then
5041 and then Switches /= No_Array_Element
5044 ("Warning: using Builder'Default_Switches"
5045 & "(""Ada""), as there are several mains");
5049 (Project_Node_Tree => Project_Node_Tree,
5052 The_Package => Builder_Package,
5055 elsif not Quiet_Output
5056 and then Switches /= No_Array_Element
5059 ("Warning: using no switches from package "
5060 & "Builder, as there are several mains");
5065 -- Take into account attribute Global_Compilation_Switches
5070 List : String_List_Id;
5071 Elem : String_Element;
5074 while Global_Compilation_Array /= No_Array_Element loop
5075 Global_Compilation_Elem :=
5076 Project_Tree.Array_Elements.Table
5077 (Global_Compilation_Array);
5079 Get_Name_String (Global_Compilation_Elem.Index);
5080 To_Lower (Name_Buffer (1 .. Name_Len));
5083 if Index = Name_Ada then
5084 Global_Compilation_Switches :=
5085 Global_Compilation_Elem.Value;
5087 if Global_Compilation_Switches /= Nil_Variable_Value
5088 and then not Global_Compilation_Switches.Default
5090 -- We have found attribute
5091 -- Global_Compilation_Switches ("Ada"): put the
5092 -- switches in the appropriate table.
5094 List := Global_Compilation_Switches.Values;
5096 while List /= Nil_String loop
5098 Project_Tree.String_Elements.Table (List);
5100 if Elem.Value /= No_Name then
5102 (Get_Name_String (Elem.Value),
5114 Global_Compilation_Array := Global_Compilation_Elem.Next;
5119 Osint.Add_Default_Search_Dirs;
5121 -- Record the current last switch index for table Binder_Switches
5122 -- and Linker_Switches, so that these tables may be reset before
5123 -- for each main, before adding switches from the project file
5124 -- and from the command line.
5126 Last_Binder_Switch := Binder_Switches.Last;
5127 Last_Linker_Switch := Linker_Switches.Last;
5131 -- Add binder switches from the project file for the first main
5133 if Do_Bind_Step and then Binder_Package /= No_Package then
5134 if Verbose_Mode then
5135 Write_Str ("Adding binder switches for """);
5136 Write_Str (Main_Unit_File_Name);
5141 (Project_Node_Tree => Project_Node_Tree,
5142 File_Name => Main_Unit_File_Name,
5143 Index => Main_Index,
5144 The_Package => Binder_Package,
5148 -- Add linker switches from the project file for the first main
5150 if Do_Link_Step and then Linker_Package /= No_Package then
5151 if Verbose_Mode then
5152 Write_Str ("Adding linker switches for""");
5153 Write_Str (Main_Unit_File_Name);
5158 (Project_Node_Tree => Project_Node_Tree,
5159 File_Name => Main_Unit_File_Name,
5160 Index => Main_Index,
5161 The_Package => Linker_Package,
5167 -- Get the target parameters, which are only needed for a couple of
5168 -- cases in gnatmake. Protect against an exception, such as the case of
5169 -- system.ads missing from the library, and fail gracefully.
5172 Targparm.Get_Target_Parameters;
5174 when Unrecoverable_Error =>
5175 Make_Failed ("*** make failed.");
5178 -- Special processing for VM targets
5180 if Targparm.VM_Target /= No_VM then
5182 -- Set proper processing commands
5184 case Targparm.VM_Target is
5185 when Targparm.JVM_Target =>
5187 -- Do not check for an object file (".o") when compiling to
5188 -- JVM machine since ".class" files are generated instead.
5190 Check_Object_Consistency := False;
5191 Gcc := new String'("jvm-gnatcompile");
5193 when Targparm.CLI_Target =>
5194 Gcc := new String'("dotnet-gnatcompile");
5196 when Targparm.No_VM =>
5197 raise Program_Error;
5201 Display_Commands (not Quiet_Output);
5205 if Main_Project /= No_Project then
5207 -- For all library project, if the library file does not exist, put
5208 -- all the project sources in the queue, and flag the project so that
5209 -- the library is generated.
5211 if not Unique_Compile
5212 and then MLib.Tgt.Support_For_Libraries /= Prj.None
5215 Proj : Project_List;
5218 Proj := Project_Tree.Projects;
5219 while Proj /= null loop
5220 if Proj.Project.Library then
5221 Proj.Project.Need_To_Build_Lib :=
5222 not MLib.Tgt.Library_Exists_For
5223 (Proj.Project, Project_Tree)
5224 and then not Proj.Project.Externally_Built;
5226 if Proj.Project.Need_To_Build_Lib then
5228 -- If there is no object directory, then it will be
5229 -- impossible to build the library. So fail
5233 Proj.Project.Object_Directory = No_Path_Information
5236 ("no object files to build library for project """
5237 & Get_Name_String (Proj.Project.Name)
5239 Proj.Project.Need_To_Build_Lib := False;
5242 if Verbose_Mode then
5244 ("Library file does not exist for project """);
5245 Write_Str (Get_Name_String (Proj.Project.Name));
5249 Insert_Project_Sources
5250 (The_Project => Proj.Project,
5251 All_Projects => False,
5262 -- If a relative path output file has been specified, we add the
5265 for J in reverse 1 .. Saved_Linker_Switches.Last - 1 loop
5266 if Saved_Linker_Switches.Table (J).all = Output_Flag.all then
5268 Exec_File_Name : constant String :=
5269 Saved_Linker_Switches.Table (J + 1).all;
5272 if not Is_Absolute_Path (Exec_File_Name) then
5273 Get_Name_String (Main_Project.Exec_Directory.Name);
5276 Is_Directory_Separator (Name_Buffer (Name_Len))
5278 Add_Char_To_Name_Buffer (Directory_Separator);
5281 Add_Str_To_Name_Buffer (Exec_File_Name);
5282 Saved_Linker_Switches.Table (J + 1) :=
5283 new String'(Name_Buffer (1 .. Name_Len));
5291 -- If we are using a project file, for relative paths we add the
5292 -- current working directory for any relative path on the command
5293 -- line and the project directory, for any relative path in the
5297 Dir_Path : constant String :=
5298 Get_Name_String (Main_Project.Directory.Name);
5300 for J in 1 .. Binder_Switches.Last loop
5301 Test_If_Relative_Path
5302 (Binder_Switches.Table (J),
5303 Parent => Dir_Path, Including_L_Switch => False);
5306 for J in 1 .. Saved_Binder_Switches.Last loop
5307 Test_If_Relative_Path
5308 (Saved_Binder_Switches.Table (J),
5309 Parent => Current_Work_Dir.all, Including_L_Switch => False);
5312 for J in 1 .. Linker_Switches.Last loop
5313 Test_If_Relative_Path
5314 (Linker_Switches.Table (J), Parent => Dir_Path);
5317 for J in 1 .. Saved_Linker_Switches.Last loop
5318 Test_If_Relative_Path
5319 (Saved_Linker_Switches.Table (J),
5320 Parent => Current_Work_Dir.all);
5323 for J in 1 .. Gcc_Switches.Last loop
5324 Test_If_Relative_Path
5325 (Gcc_Switches.Table (J),
5327 Including_Non_Switch => False);
5330 for J in 1 .. Saved_Gcc_Switches.Last loop
5331 Test_If_Relative_Path
5332 (Saved_Gcc_Switches.Table (J),
5333 Parent => Current_Work_Dir.all,
5334 Including_Non_Switch => False);
5339 -- We now put in the Binder_Switches and Linker_Switches tables, the
5340 -- binder and linker switches of the command line that have been put in
5341 -- the Saved_ tables. If a project file was used, then the command line
5342 -- switches will follow the project file switches.
5344 for J in 1 .. Saved_Binder_Switches.Last loop
5346 (Saved_Binder_Switches.Table (J),
5351 for J in 1 .. Saved_Linker_Switches.Last loop
5353 (Saved_Linker_Switches.Table (J),
5358 -- If no project file is used, we just put the gcc switches
5359 -- from the command line in the Gcc_Switches table.
5361 if Main_Project = No_Project then
5362 for J in 1 .. Saved_Gcc_Switches.Last loop
5364 (Saved_Gcc_Switches.Table (J), Compiler, And_Save => False);
5368 -- If there is a project, put the command line gcc switches in the
5369 -- variable The_Saved_Gcc_Switches. They are going to be used later
5370 -- in procedure Compile_Sources.
5372 The_Saved_Gcc_Switches :=
5373 new Argument_List (1 .. Saved_Gcc_Switches.Last + 1);
5375 for J in 1 .. Saved_Gcc_Switches.Last loop
5376 The_Saved_Gcc_Switches (J) := Saved_Gcc_Switches.Table (J);
5379 -- We never use gnat.adc when a project file is used
5381 The_Saved_Gcc_Switches (The_Saved_Gcc_Switches'Last) := No_gnat_adc;
5384 -- If there was a --GCC, --GNATBIND or --GNATLINK switch on the command
5385 -- line, then we have to use it, even if there was another switch in
5386 -- the project file.
5388 if Saved_Gcc /= null then
5392 if Saved_Gnatbind /= null then
5393 Gnatbind := Saved_Gnatbind;
5396 if Saved_Gnatlink /= null then
5397 Gnatlink := Saved_Gnatlink;
5400 Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
5401 Gnatbind_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
5402 Gnatlink_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
5404 -- If we have specified -j switch both from the project file
5405 -- and on the command line, the one from the command line takes
5408 if Saved_Maximum_Processes = 0 then
5409 Saved_Maximum_Processes := Maximum_Processes;
5412 -- Allocate as many temporary mapping file names as the maximum number
5413 -- of compilations processed, for each possible project.
5416 Data : Project_Compilation_Access;
5417 Proj : Project_List := Project_Tree.Projects;
5419 while Proj /= null loop
5420 Data := new Project_Compilation_Data'
5421 (Mapping_File_Names => new Temp_Path_Names
5422 (1 .. Saved_Maximum_Processes),
5423 Last_Mapping_File_Names => 0,
5424 Free_Mapping_File_Indices => new Free_File_Indices
5425 (1 .. Saved_Maximum_Processes),
5426 Last_Free_Indices => 0);
5428 Project_Compilation_Htable.Set
5429 (Project_Compilation, Proj.Project, Data);
5433 Data := new Project_Compilation_Data'
5434 (Mapping_File_Names => new Temp_Path_Names
5435 (1 .. Saved_Maximum_Processes),
5436 Last_Mapping_File_Names => 0,
5437 Free_Mapping_File_Indices => new Free_File_Indices
5438 (1 .. Saved_Maximum_Processes),
5439 Last_Free_Indices => 0);
5441 Project_Compilation_Htable.Set
5442 (Project_Compilation, No_Project, Data);
5445 Bad_Compilation.Init;
5447 -- If project files are used, create the mapping of all the sources, so
5448 -- that the correct paths will be found. Otherwise, if there is a file
5449 -- which is not a source with the same name in a source directory this
5450 -- file may be incorrectly found.
5452 if Main_Project /= No_Project then
5453 Prj.Env.Create_Mapping (Project_Tree);
5456 Current_Main_Index := Main_Index;
5458 -- Here is where the make process is started
5460 -- We do the same process for each main
5462 Multiple_Main_Loop : for N_File in 1 .. Osint.Number_Of_Files loop
5464 -- First, find the executable name and path
5466 Executable := No_File;
5467 Executable_Obsolete := False;
5468 Non_Std_Executable :=
5469 Targparm.Executable_Extension_On_Target /= No_Name;
5471 -- Look inside the linker switches to see if the name of the final
5472 -- executable program was specified.
5474 for J in reverse Linker_Switches.First .. Linker_Switches.Last loop
5475 if Linker_Switches.Table (J).all = Output_Flag.all then
5476 pragma Assert (J < Linker_Switches.Last);
5478 -- We cannot specify a single executable for several main
5481 if Osint.Number_Of_Files > 1 then
5483 ("cannot specify a single executable for several mains");
5487 Add_Str_To_Name_Buffer (Linker_Switches.Table (J + 1).all);
5488 Executable := Name_Enter;
5490 Verbose_Msg (Executable, "final executable");
5494 -- If the name of the final executable program was not specified then
5495 -- construct it from the main input file.
5497 if Executable = No_File then
5498 if Main_Project = No_Project then
5499 Executable := Executable_Name (Strip_Suffix (Main_Source_File));
5502 -- If we are using a project file, we attempt to remove the
5503 -- body (or spec) termination of the main subprogram. We find
5504 -- it the naming scheme of the project file. This avoids
5505 -- generating an executable "main.2" for a main subprogram
5506 -- "main.2.ada", when the body termination is ".2.ada".
5509 Prj.Util.Executable_Of
5510 (Main_Project, Project_Tree, Main_Source_File, Main_Index);
5514 if Main_Project /= No_Project
5515 and then Main_Project.Exec_Directory /= No_Path_Information
5518 Exec_File_Name : constant String :=
5519 Get_Name_String (Executable);
5522 if not Is_Absolute_Path (Exec_File_Name) then
5523 Get_Name_String (Main_Project.Exec_Directory.Display_Name);
5525 if Name_Buffer (Name_Len) /= Directory_Separator then
5526 Add_Char_To_Name_Buffer (Directory_Separator);
5529 Add_Str_To_Name_Buffer (Exec_File_Name);
5530 Executable := Name_Find;
5533 Non_Std_Executable := True;
5537 if Do_Compile_Step then
5538 Recursive_Compilation_Step : declare
5539 Args : Argument_List (1 .. Gcc_Switches.Last);
5541 First_Compiled_File : File_Name_Type;
5542 Youngest_Obj_File : File_Name_Type;
5543 Youngest_Obj_Stamp : Time_Stamp_Type;
5545 Executable_Stamp : Time_Stamp_Type;
5546 -- Executable is the final executable program
5547 -- ??? comment seems unrelated to declaration
5549 Library_Rebuilt : Boolean := False;
5552 for J in 1 .. Gcc_Switches.Last loop
5553 Args (J) := Gcc_Switches.Table (J);
5556 -- Now we invoke Compile_Sources for the current main
5559 (Main_Source => Main_Source_File,
5561 First_Compiled_File => First_Compiled_File,
5562 Most_Recent_Obj_File => Youngest_Obj_File,
5563 Most_Recent_Obj_Stamp => Youngest_Obj_Stamp,
5564 Main_Unit => Is_Main_Unit,
5565 Main_Index => Current_Main_Index,
5566 Compilation_Failures => Compilation_Failures,
5567 Check_Readonly_Files => Check_Readonly_Files,
5568 Do_Not_Execute => Do_Not_Execute,
5569 Force_Compilations => Force_Compilations,
5570 In_Place_Mode => In_Place_Mode,
5571 Keep_Going => Keep_Going,
5572 Initialize_ALI_Data => True,
5573 Max_Process => Saved_Maximum_Processes);
5575 if Verbose_Mode then
5576 Write_Str ("End of compilation");
5580 -- Make sure the queue will be reinitialized for the next round
5582 First_Q_Initialization := True;
5584 Total_Compilation_Failures :=
5585 Total_Compilation_Failures + Compilation_Failures;
5587 if Total_Compilation_Failures /= 0 then
5592 List_Bad_Compilations;
5593 Report_Compilation_Failed;
5597 -- Regenerate libraries, if there are any and if object files
5598 -- have been regenerated.
5600 if Main_Project /= No_Project
5601 and then MLib.Tgt.Support_For_Libraries /= Prj.None
5602 and then (Do_Bind_Step
5603 or Unique_Compile_All_Projects
5604 or not Compile_Only)
5605 and then (Do_Link_Step or else N_File = Osint.Number_Of_Files)
5612 Proj1 : Project_List;
5614 procedure Add_To_Library_Projs (Proj : Project_Id);
5615 -- Add project Project to table Library_Projs in
5616 -- decreasing depth order.
5618 --------------------------
5619 -- Add_To_Library_Projs --
5620 --------------------------
5622 procedure Add_To_Library_Projs (Proj : Project_Id) is
5626 Library_Projs.Increment_Last;
5627 Depth := Proj.Depth;
5629 -- Put the projects in decreasing depth order, so that
5630 -- if libA depends on libB, libB is first in order.
5632 Current := Library_Projs.Last;
5633 while Current > 1 loop
5634 Prj := Library_Projs.Table (Current - 1);
5635 exit when Prj.Depth >= Depth;
5636 Library_Projs.Table (Current) := Prj;
5637 Current := Current - 1;
5640 Library_Projs.Table (Current) := Proj;
5641 end Add_To_Library_Projs;
5643 -- Start of processing for ??? (should name declare block
5644 -- or probably better, break this out as a nested proc).
5647 -- Put in Library_Projs table all library project file
5648 -- ids when the library need to be rebuilt.
5650 Proj1 := Project_Tree.Projects;
5651 while Proj1 /= null loop
5652 if Proj1.Project.Standalone_Library then
5653 Stand_Alone_Libraries := True;
5656 if Proj1.Project.Library then
5657 MLib.Prj.Check_Library
5658 (Proj1.Project, Project_Tree);
5661 if Proj1.Project.Need_To_Build_Lib then
5662 Add_To_Library_Projs (Proj1.Project);
5665 Proj1 := Proj1.Next;
5668 -- Check if importing libraries should be regenerated
5669 -- because at least an imported library will be
5670 -- regenerated or is more recent.
5672 Proj1 := Project_Tree.Projects;
5673 while Proj1 /= null loop
5674 if Proj1.Project.Library
5675 and then Proj1.Project.Library_Kind /= Static
5676 and then not Proj1.Project.Need_To_Build_Lib
5677 and then not Proj1.Project.Externally_Built
5680 List : Project_List;
5682 Rebuild : Boolean := False;
5684 Lib_Timestamp1 : constant Time_Stamp_Type :=
5685 Proj1.Project.Library_TS;
5688 List := Proj1.Project.All_Imported_Projects;
5689 while List /= null loop
5690 Proj2 := List.Project;
5692 if Proj2.Library then
5693 if Proj2.Need_To_Build_Lib
5695 (Lib_Timestamp1 < Proj2.Library_TS)
5706 Proj1.Project.Need_To_Build_Lib := True;
5707 Add_To_Library_Projs (Proj1.Project);
5712 Proj1 := Proj1.Next;
5715 -- Reset the flags Need_To_Build_Lib for the next main,
5716 -- to avoid rebuilding libraries uselessly.
5718 Proj1 := Project_Tree.Projects;
5719 while Proj1 /= null loop
5720 Proj1.Project.Need_To_Build_Lib := False;
5721 Proj1 := Proj1.Next;
5725 -- Build the libraries, if any need to be built
5727 for J in 1 .. Library_Projs.Last loop
5728 Library_Rebuilt := True;
5730 -- If a library is rebuilt, then executables are obsolete
5732 Executable_Obsolete := True;
5734 MLib.Prj.Build_Library
5735 (For_Project => Library_Projs.Table (J),
5736 In_Tree => Project_Tree,
5737 Gnatbind => Gnatbind.all,
5738 Gnatbind_Path => Gnatbind_Path,
5740 Gcc_Path => Gcc_Path);
5744 if List_Dependencies then
5745 if First_Compiled_File /= No_File then
5747 (First_Compiled_File,
5748 "must be recompiled. Can't generate dependence list.");
5753 elsif First_Compiled_File = No_File
5754 and then not Do_Bind_Step
5755 and then not Quiet_Output
5756 and then not Library_Rebuilt
5757 and then Osint.Number_Of_Files = 1
5759 Inform (Msg => "objects up to date.");
5761 elsif Do_Not_Execute
5762 and then First_Compiled_File /= No_File
5764 Write_Name (First_Compiled_File);
5768 -- Stop after compile step if any of:
5770 -- 1) -n (Do_Not_Execute) specified
5772 -- 2) -M (List_Dependencies) specified (also sets
5773 -- Do_Not_Execute above, so this is probably superfluous).
5775 -- 3) -c (Compile_Only) specified, but not -b (Bind_Only)
5777 -- 4) Made unit cannot be a main unit
5780 or List_Dependencies
5782 or not Is_Main_Unit)
5783 and then not No_Main_Subprogram
5784 and then not Build_Bind_And_Link_Full_Project)
5785 or else Unique_Compile
5787 if Osint.Number_Of_Files = 1 then
5788 exit Multiple_Main_Loop;
5795 -- If the objects were up-to-date check if the executable file
5796 -- is also up-to-date. For now always bind and link on the JVM
5797 -- since there is currently no simple way to check whether
5798 -- objects are up-to-date.
5800 if Targparm.VM_Target /= JVM_Target
5801 and then First_Compiled_File = No_File
5803 Executable_Stamp := File_Stamp (Executable);
5805 if not Executable_Obsolete then
5806 Executable_Obsolete :=
5807 Youngest_Obj_Stamp > Executable_Stamp;
5810 if not Executable_Obsolete then
5811 for Index in reverse 1 .. Dependencies.Last loop
5813 (Dependencies.Table (Index).Depends_On)
5815 Enter_Into_Obsoleted
5816 (Dependencies.Table (Index).This);
5820 Executable_Obsolete := Is_In_Obsoleted (Main_Source_File);
5824 if not Executable_Obsolete then
5826 -- If no Ada object files obsolete the executable, check
5827 -- for younger or missing linker files.
5829 Check_Linker_Options
5832 Youngest_Obj_Stamp);
5834 Executable_Obsolete := Youngest_Obj_File /= No_File;
5837 -- Check if any library file is more recent than the
5838 -- executable: there may be an externally built library
5839 -- file that has been modified.
5841 if not Executable_Obsolete
5842 and then Main_Project /= No_Project
5845 Proj1 : Project_List;
5848 Proj1 := Project_Tree.Projects;
5849 while Proj1 /= null loop
5850 if Proj1.Project.Library
5852 Proj1.Project.Library_TS > Executable_Stamp
5854 Executable_Obsolete := True;
5855 Youngest_Obj_Stamp := Proj1.Project.Library_TS;
5857 Add_Str_To_Name_Buffer ("library ");
5858 Add_Str_To_Name_Buffer
5859 (Get_Name_String (Proj1.Project.Library_Name));
5860 Youngest_Obj_File := Name_Find;
5864 Proj1 := Proj1.Next;
5869 -- Return if the executable is up to date and otherwise
5870 -- motivate the relink/rebind.
5872 if not Executable_Obsolete then
5873 if not Quiet_Output then
5874 Inform (Executable, "up to date.");
5877 if Osint.Number_Of_Files = 1 then
5878 exit Multiple_Main_Loop;
5885 if Executable_Stamp (1) = ' ' then
5886 if not No_Main_Subprogram then
5887 Verbose_Msg (Executable, "missing.", Prefix => " ");
5890 elsif Youngest_Obj_Stamp (1) = ' ' then
5892 (Youngest_Obj_File, "missing.", Prefix => " ");
5894 elsif Youngest_Obj_Stamp > Executable_Stamp then
5897 "(" & String (Youngest_Obj_Stamp) & ") newer than",
5899 "(" & String (Executable_Stamp) & ")");
5903 (Executable, "needs to be rebuilt", Prefix => " ");
5907 end Recursive_Compilation_Step;
5910 -- For binding and linking, we need to be in the object directory of
5911 -- the main project.
5913 if Main_Project /= No_Project then
5914 Change_To_Object_Directory (Main_Project);
5917 -- If we are here, it means that we need to rebuilt the current main,
5918 -- so we set Executable_Obsolete to True to make sure that subsequent
5919 -- mains will be rebuilt.
5921 Main_ALI_In_Place_Mode_Step : declare
5922 ALI_File : File_Name_Type;
5923 Src_File : File_Name_Type;
5926 Src_File := Strip_Directory (Main_Source_File);
5927 ALI_File := Lib_File_Name (Src_File, Current_Main_Index);
5928 Main_ALI_File := Full_Lib_File_Name (ALI_File);
5930 -- When In_Place_Mode, the library file can be located in the
5931 -- Main_Source_File directory which may not be present in the
5932 -- library path. If it is not present then use the corresponding
5933 -- library file name.
5935 if Main_ALI_File = No_File and then In_Place_Mode then
5936 Get_Name_String (Get_Directory (Full_Source_Name (Src_File)));
5937 Get_Name_String_And_Append (ALI_File);
5938 Main_ALI_File := Name_Find;
5939 Main_ALI_File := Full_Lib_File_Name (Main_ALI_File);
5942 if Main_ALI_File = No_File then
5943 Make_Failed ("could not find the main ALI file");
5945 end Main_ALI_In_Place_Mode_Step;
5947 if Do_Bind_Step then
5949 Args : Argument_List
5950 (Binder_Switches.First .. Binder_Switches.Last + 2);
5951 -- The arguments for the invocation of gnatbind
5953 Last_Arg : Natural := Binder_Switches.Last;
5954 -- Index of the last argument in Args
5956 Shared_Libs : Boolean := False;
5957 -- Set to True when there are shared library project files or
5958 -- when gnatbind is invoked with -shared.
5960 Proj : Project_List;
5963 -- Check if there are shared libraries, so that gnatbind is
5964 -- called with -shared. Check also if gnatbind is called with
5965 -- -shared, so that gnatlink is called with -shared-libgcc
5966 -- ensuring that the shared version of libgcc will be used.
5968 if Main_Project /= No_Project
5969 and then MLib.Tgt.Support_For_Libraries /= Prj.None
5971 Proj := Project_Tree.Projects;
5972 while Proj /= null loop
5973 if Proj.Project.Library
5974 and then Proj.Project.Library_Kind /= Static
5976 Shared_Libs := True;
5977 Bind_Shared := Shared_Switch'Access;
5984 -- Check now for switch -shared
5986 if not Shared_Libs then
5987 for J in Binder_Switches.First .. Last_Arg loop
5988 if Binder_Switches.Table (J).all = "-shared" then
5989 Shared_Libs := True;
5995 -- If shared libraries present, invoke gnatlink with
5999 Link_With_Shared_Libgcc := Shared_Libgcc_Switch'Access;
6002 -- Get all the binder switches
6004 for J in Binder_Switches.First .. Last_Arg loop
6005 Args (J) := Binder_Switches.Table (J);
6008 if Stand_Alone_Libraries then
6009 Last_Arg := Last_Arg + 1;
6010 Args (Last_Arg) := Force_Elab_Flags_String'Access;
6013 if Main_Project /= No_Project then
6015 -- Put all the source directories in ADA_INCLUDE_PATH,
6016 -- and all the object directories in ADA_OBJECTS_PATH,
6017 -- except those of library projects.
6019 Prj.Env.Set_Ada_Paths (Main_Project, Project_Tree, False);
6021 -- If switch -C was specified, create a binder mapping file
6023 if Create_Mapping_File then
6024 Create_Binder_Mapping_File (Args, Last_Arg);
6030 Bind (Main_ALI_File,
6031 Bind_Shared.all & Args (Args'First .. Last_Arg));
6036 -- Delete the temporary mapping file, if one was created.
6038 if Mapping_Path /= No_Path then
6039 Delete_Temporary_File (Project_Tree, Mapping_Path);
6042 -- And reraise the exception
6047 -- If -dn was not specified, delete the temporary mapping file,
6048 -- if one was created.
6050 if Mapping_Path /= No_Path then
6051 Delete_Temporary_File (Project_Tree, Mapping_Path);
6056 if Do_Link_Step then
6058 Linker_Switches_Last : constant Integer := Linker_Switches.Last;
6059 Path_Option : constant String_Access :=
6060 MLib.Linker_Library_Path_Option;
6061 Libraries_Present : Boolean := False;
6065 Proj1 : Project_List;
6068 if not Run_Path_Option then
6069 Linker_Switches.Increment_Last;
6070 Linker_Switches.Table (Linker_Switches.Last) :=
6074 if Main_Project /= No_Project then
6075 Library_Paths.Set_Last (0);
6078 if MLib.Tgt.Support_For_Libraries /= Prj.None then
6080 -- Check for library projects
6082 Proj1 := Project_Tree.Projects;
6083 while Proj1 /= null loop
6084 if Proj1.Project /= Main_Project
6085 and then Proj1.Project.Library
6087 -- Add this project to table Library_Projs
6089 Libraries_Present := True;
6090 Depth := Proj1.Project.Depth;
6091 Library_Projs.Increment_Last;
6092 Current := Library_Projs.Last;
6094 -- Any project with a greater depth should be
6095 -- after this project in the list.
6097 while Current > 1 loop
6098 Proj2 := Library_Projs.Table (Current - 1);
6099 exit when Proj2.Depth <= Depth;
6100 Library_Projs.Table (Current) := Proj2;
6101 Current := Current - 1;
6104 Library_Projs.Table (Current) := Proj1.Project;
6106 -- If it is not a static library and path option
6107 -- is set, add it to the Library_Paths table.
6109 if Proj1.Project.Library_Kind /= Static
6110 and then Path_Option /= null
6112 Library_Paths.Increment_Last;
6113 Library_Paths.Table (Library_Paths.Last) :=
6116 (Proj1.Project.Library_Dir.Display_Name));
6120 Proj1 := Proj1.Next;
6123 for Index in 1 .. Library_Projs.Last loop
6125 -- Add the -L switch
6127 Linker_Switches.Increment_Last;
6128 Linker_Switches.Table (Linker_Switches.Last) :=
6131 (Library_Projs.Table (Index).
6132 Library_Dir.Display_Name));
6134 -- Add the -l switch
6136 Linker_Switches.Increment_Last;
6137 Linker_Switches.Table (Linker_Switches.Last) :=
6140 (Library_Projs.Table (Index).
6145 if Libraries_Present then
6147 -- If Path_Option is not null, create the switch
6148 -- ("-Wl,-rpath," or equivalent) with all the non static
6149 -- library dirs plus the standard GNAT library dir.
6150 -- We do that only if Run_Path_Option is True
6151 -- (not disabled by -R switch).
6153 if Run_Path_Option and then Path_Option /= null then
6155 Option : String_Access;
6156 Length : Natural := Path_Option'Length;
6160 if MLib.Separate_Run_Path_Options then
6162 -- We are going to create one switch of the form
6163 -- "-Wl,-rpath,dir_N" for each directory to
6166 -- One switch for each library directory
6169 Library_Paths.First .. Library_Paths.Last
6171 Linker_Switches.Increment_Last;
6172 Linker_Switches.Table
6173 (Linker_Switches.Last) := new String'
6175 Library_Paths.Table (Index).all);
6178 -- One switch for the standard GNAT library dir
6180 Linker_Switches.Increment_Last;
6181 Linker_Switches.Table
6182 (Linker_Switches.Last) := new String'
6183 (Path_Option.all & MLib.Utl.Lib_Directory);
6186 -- We are going to create one switch of the form
6187 -- "-Wl,-rpath,dir_1:dir_2:dir_3"
6190 Library_Paths.First .. Library_Paths.Last
6192 -- Add the length of the library dir plus one
6193 -- for the directory separator.
6197 Library_Paths.Table (Index)'Length + 1;
6200 -- Finally, add the length of the standard GNAT
6203 Length := Length + MLib.Utl.Lib_Directory'Length;
6204 Option := new String (1 .. Length);
6205 Option (1 .. Path_Option'Length) :=
6207 Current := Path_Option'Length;
6209 -- Put each library dir followed by a dir
6213 Library_Paths.First .. Library_Paths.Last
6218 Library_Paths.Table (Index)'Length) :=
6219 Library_Paths.Table (Index).all;
6222 Library_Paths.Table (Index)'Length + 1;
6223 Option (Current) := Path_Separator;
6226 -- Finally put the standard GNAT library dir
6230 Current + MLib.Utl.Lib_Directory'Length) :=
6231 MLib.Utl.Lib_Directory;
6233 -- And add the switch to the linker switches
6235 Linker_Switches.Increment_Last;
6236 Linker_Switches.Table (Linker_Switches.Last) :=
6244 -- Put the object directories in ADA_OBJECTS_PATH
6246 Prj.Env.Set_Ada_Paths (Main_Project, Project_Tree, False);
6248 -- Check for attributes Linker'Linker_Options in projects
6249 -- other than the main project
6252 Linker_Options : constant String_List :=
6253 Linker_Options_Switches
6254 (Main_Project, Project_Tree);
6256 for Option in Linker_Options'Range loop
6257 Linker_Switches.Increment_Last;
6258 Linker_Switches.Table (Linker_Switches.Last) :=
6259 Linker_Options (Option);
6265 Args : Argument_List
6266 (Linker_Switches.First .. Linker_Switches.Last + 2);
6268 Last_Arg : Integer := Linker_Switches.First - 1;
6269 Skip : Boolean := False;
6272 -- Get all the linker switches
6274 for J in Linker_Switches.First .. Linker_Switches.Last loop
6278 elsif Non_Std_Executable
6279 and then Linker_Switches.Table (J).all = "-o"
6283 -- Here we capture and duplicate the linker argument. We
6284 -- need to do the duplication since the arguments will
6285 -- get normalized. Not doing so will result in calling
6286 -- normalized two times for the same set of arguments if
6287 -- gnatmake is passed multiple mains. This can result in
6288 -- the wrong argument being passed to the linker.
6291 Last_Arg := Last_Arg + 1;
6293 new String'(Linker_Switches.Table (J).all);
6297 -- If need be, add the -o switch
6299 if Non_Std_Executable then
6300 Last_Arg := Last_Arg + 1;
6301 Args (Last_Arg) := new String'("-o");
6302 Last_Arg := Last_Arg + 1;
6304 new String'(Get_Name_String (Executable));
6307 -- And invoke the linker
6310 Success : Boolean := False;
6312 Link (Main_ALI_File,
6313 Link_With_Shared_Libgcc.all &
6314 Args (Args'First .. Last_Arg),
6318 Successful_Links.Increment_Last;
6319 Successful_Links.Table (Successful_Links.Last) :=
6322 elsif Osint.Number_Of_Files = 1
6323 or else not Keep_Going
6325 Make_Failed ("*** link failed.");
6329 Write_Line ("*** link failed");
6331 if Commands_To_Stdout then
6332 Set_Standard_Output;
6335 Failed_Links.Increment_Last;
6336 Failed_Links.Table (Failed_Links.Last) :=
6342 Linker_Switches.Set_Last (Linker_Switches_Last);
6346 -- We go to here when we skip the bind and link steps
6350 -- We go to the next main, if we did not process the last one
6352 if N_File < Osint.Number_Of_Files then
6353 Main_Source_File := Next_Main_Source;
6355 if Current_File_Index /= No_Index then
6356 Main_Index := Current_File_Index;
6359 if Main_Project /= No_Project then
6361 -- Find the file name of the main unit
6364 Main_Source_File_Name : constant String :=
6365 Get_Name_String (Main_Source_File);
6367 Main_Unit_File_Name : constant String :=
6369 File_Name_Of_Library_Unit_Body
6370 (Name => Main_Source_File_Name,
6371 Project => Main_Project,
6372 In_Tree => Project_Tree,
6373 Main_Project_Only =>
6374 not Unique_Compile);
6376 The_Packages : constant Package_Id :=
6377 Main_Project.Decl.Packages;
6379 Binder_Package : constant Prj.Package_Id :=
6381 (Name => Name_Binder,
6382 In_Packages => The_Packages,
6383 In_Tree => Project_Tree);
6385 Linker_Package : constant Prj.Package_Id :=
6387 (Name => Name_Linker,
6388 In_Packages => The_Packages,
6389 In_Tree => Project_Tree);
6392 -- We fail if we cannot find the main source file
6393 -- as an immediate source of the main project file.
6395 if Main_Unit_File_Name = "" then
6396 Make_Failed ('"' & Main_Source_File_Name
6397 & """ is not a unit of project "
6398 & Project_File_Name.all & ".");
6401 -- Remove any directory information from the main
6402 -- source file name.
6405 Pos : Natural := Main_Unit_File_Name'Last;
6409 exit when Pos < Main_Unit_File_Name'First
6411 Main_Unit_File_Name (Pos) = Directory_Separator;
6415 Name_Len := Main_Unit_File_Name'Last - Pos;
6417 Name_Buffer (1 .. Name_Len) :=
6419 (Pos + 1 .. Main_Unit_File_Name'Last);
6421 Main_Source_File := Name_Find;
6425 -- We now deal with the binder and linker switches.
6426 -- If no project file is used, there is nothing to do
6427 -- because the binder and linker switches are the same
6430 -- Reset the tables Binder_Switches and Linker_Switches
6432 Binder_Switches.Set_Last (Last_Binder_Switch);
6433 Linker_Switches.Set_Last (Last_Linker_Switch);
6435 -- Add binder switches from the project file for this main,
6438 if Do_Bind_Step and then Binder_Package /= No_Package then
6439 if Verbose_Mode then
6440 Write_Str ("Adding binder switches for """);
6441 Write_Str (Main_Unit_File_Name);
6446 (Project_Node_Tree => Project_Node_Tree,
6447 File_Name => Main_Unit_File_Name,
6448 Index => Main_Index,
6449 The_Package => Binder_Package,
6453 -- Add linker switches from the project file for this main,
6456 if Do_Link_Step and then Linker_Package /= No_Package then
6457 if Verbose_Mode then
6458 Write_Str ("Adding linker switches for""");
6459 Write_Str (Main_Unit_File_Name);
6464 (Project_Node_Tree => Project_Node_Tree,
6465 File_Name => Main_Unit_File_Name,
6466 Index => Main_Index,
6467 The_Package => Linker_Package,
6471 -- As we are using a project file, for relative paths we add
6472 -- the current working directory for any relative path on
6473 -- the command line and the project directory, for any
6474 -- relative path in the project file.
6477 Dir_Path : constant String :=
6479 (Main_Project.Directory.Name);
6483 J in Last_Binder_Switch + 1 .. Binder_Switches.Last
6485 Test_If_Relative_Path
6486 (Binder_Switches.Table (J),
6487 Parent => Dir_Path, Including_L_Switch => False);
6491 J in Last_Linker_Switch + 1 .. Linker_Switches.Last
6493 Test_If_Relative_Path
6494 (Linker_Switches.Table (J), Parent => Dir_Path);
6498 -- We now put in the Binder_Switches and Linker_Switches
6499 -- tables, the binder and linker switches of the command
6500 -- line that have been put in the Saved_ tables.
6501 -- These switches will follow the project file switches.
6503 for J in 1 .. Saved_Binder_Switches.Last loop
6505 (Saved_Binder_Switches.Table (J),
6510 for J in 1 .. Saved_Linker_Switches.Last loop
6512 (Saved_Linker_Switches.Table (J),
6520 -- Remove all marks to be sure to check sources for all executables,
6521 -- as the switches may be different and -s may be in use.
6524 end loop Multiple_Main_Loop;
6526 if Failed_Links.Last > 0 then
6527 for Index in 1 .. Successful_Links.Last loop
6528 Write_Str ("Linking of """);
6529 Write_Str (Get_Name_String (Successful_Links.Table (Index)));
6530 Write_Line (""" succeeded.");
6535 for Index in 1 .. Failed_Links.Last loop
6536 Write_Str ("Linking of """);
6537 Write_Str (Get_Name_String (Failed_Links.Table (Index)));
6538 Write_Line (""" failed.");
6541 if Commands_To_Stdout then
6542 Set_Standard_Output;
6545 if Total_Compilation_Failures = 0 then
6546 Report_Compilation_Failed;
6550 if Total_Compilation_Failures /= 0 then
6551 List_Bad_Compilations;
6552 Report_Compilation_Failed;
6555 -- Delete the temporary mapping file that was created if we are
6556 -- using project files.
6558 Delete_All_Temp_Files;
6563 Write_Line (Exception_Information (X));
6564 Make_Failed ("INTERNAL ERROR. Please report.");
6571 function Hash (F : File_Name_Type) return Header_Num is
6573 return Header_Num (1 + F mod Max_Header);
6576 --------------------
6577 -- In_Ada_Lib_Dir --
6578 --------------------
6580 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean is
6581 D : constant File_Name_Type := Get_Directory (File);
6582 B : constant Byte := Get_Name_Table_Byte (D);
6584 return (B and Ada_Lib_Dir) /= 0;
6587 -----------------------
6588 -- Init_Mapping_File --
6589 -----------------------
6591 procedure Init_Mapping_File
6592 (Project : Project_Id;
6593 Data : in out Project_Compilation_Data;
6594 File_Index : in out Natural)
6596 FD : File_Descriptor;
6598 -- For call to Close
6601 -- Increase the index of the last mapping file for this project
6603 Data.Last_Mapping_File_Names := Data.Last_Mapping_File_Names + 1;
6605 -- If there is a project file, call Create_Mapping_File with
6608 if Project /= No_Project then
6609 Prj.Env.Create_Mapping_File
6611 In_Tree => Project_Tree,
6612 Language => Name_Ada,
6613 Name => Data.Mapping_File_Names
6614 (Data.Last_Mapping_File_Names));
6616 -- Otherwise, just create an empty file
6619 Tempdir.Create_Temp_File
6621 Data.Mapping_File_Names (Data.Last_Mapping_File_Names));
6623 if FD = Invalid_FD then
6624 Make_Failed ("disk full");
6629 Data.Mapping_File_Names (Data.Last_Mapping_File_Names));
6635 Make_Failed ("disk full");
6639 -- And return the index of the newly created file
6641 File_Index := Data.Last_Mapping_File_Names;
6642 end Init_Mapping_File;
6650 First_Q_Initialization := False;
6652 Q.Set_Last (Q.First);
6659 procedure Initialize (Project_Node_Tree : out Project_Node_Tree_Ref) is
6661 procedure Check_Version_And_Help is
6662 new Check_Version_And_Help_G (Makeusg);
6664 -- Start of processing for Initialize
6667 -- Prepare the project's tree, since this is used to hold external
6668 -- references, project path and other attributes that can be impacted by
6669 -- the command line switches
6671 Project_Node_Tree := new Project_Node_Tree_Data;
6672 Prj.Tree.Initialize (Project_Node_Tree);
6674 -- Override default initialization of Check_Object_Consistency since
6675 -- this is normally False for GNATBIND, but is True for GNATMAKE since
6676 -- we do not need to check source consistency again once GNATMAKE has
6677 -- looked at the sources to check.
6679 Check_Object_Consistency := True;
6681 -- Package initializations. The order of calls is important here
6683 Output.Set_Standard_Error;
6686 Binder_Switches.Init;
6687 Linker_Switches.Init;
6694 Prj.Initialize (Project_Tree);
6698 RTS_Specified := null;
6703 -- Add the directory where gnatmake is invoked in front of the path,
6704 -- if gnatmake is invoked from a bin directory or with directory
6705 -- information. Only do this if the platform is not VMS, where the
6706 -- notion of path does not really exist.
6710 Prefix : constant String := Executable_Prefix_Path;
6711 Command : constant String := Command_Name;
6714 if Prefix'Length > 0 then
6716 PATH : constant String :=
6717 Prefix & Directory_Separator & "bin" &
6719 Getenv ("PATH").all;
6721 Setenv ("PATH", PATH);
6725 for Index in reverse Command'Range loop
6726 if Command (Index) = Directory_Separator then
6728 Absolute_Dir : constant String :=
6730 (Command (Command'First .. Index));
6731 PATH : constant String :=
6734 Getenv ("PATH").all;
6736 Setenv ("PATH", PATH);
6746 -- Scan the switches and arguments
6748 -- First, scan to detect --version and/or --help
6750 Check_Version_And_Help ("GNATMAKE", "1995");
6752 -- Scan again the switch and arguments, now that we are sure that they
6753 -- do not include --version or --help.
6755 Scan_Args : for Next_Arg in 1 .. Argument_Count loop
6757 (Project_Node_Tree, Argument (Next_Arg), And_Save => True);
6760 if N_M_Switch > 0 and RTS_Specified = null then
6761 Process_Multilib (Project_Node_Tree);
6764 if Commands_To_Stdout then
6765 Set_Standard_Output;
6768 if Usage_Requested then
6772 -- Test for trailing -P switch
6774 if Project_File_Name_Present and then Project_File_Name = null then
6775 Make_Failed ("project file name missing after -P");
6777 -- Test for trailing -o switch
6779 elsif Output_File_Name_Present
6780 and then not Output_File_Name_Seen
6782 Make_Failed ("output file name missing after -o");
6784 -- Test for trailing -D switch
6786 elsif Object_Directory_Present
6787 and then not Object_Directory_Seen then
6788 Make_Failed ("object directory missing after -D");
6791 -- Test for simultaneity of -i and -D
6793 if Object_Directory_Path /= null and then In_Place_Mode then
6794 Make_Failed ("-i and -D cannot be used simultaneously");
6797 -- Deal with -C= switch
6799 if Gnatmake_Mapping_File /= null then
6801 -- First, check compatibility with other switches
6803 if Project_File_Name /= null then
6804 Make_Failed ("-C= switch is not compatible with -P switch");
6806 elsif Saved_Maximum_Processes > 1 then
6807 Make_Failed ("-C= switch is not compatible with -jnnn switch");
6810 Fmap.Initialize (Gnatmake_Mapping_File.all);
6812 ("-gnatem=" & Gnatmake_Mapping_File.all,
6817 if Project_File_Name /= null then
6819 -- A project file was specified by a -P switch
6821 if Verbose_Mode then
6823 Write_Str ("Parsing project file """);
6824 Write_Str (Project_File_Name.all);
6829 -- Avoid looking in the current directory for ALI files
6831 -- Look_In_Primary_Dir := False;
6833 -- Set the project parsing verbosity to whatever was specified
6834 -- by a possible -vP switch.
6836 Prj.Pars.Set_Verbosity (To => Current_Verbosity);
6838 -- Parse the project file.
6839 -- If there is an error, Main_Project will still be No_Project.
6842 (Project => Main_Project,
6843 In_Tree => Project_Tree,
6844 Project_File_Name => Project_File_Name.all,
6845 Packages_To_Check => Packages_To_Check_By_Gnatmake,
6846 Flags => Gnatmake_Flags,
6847 In_Node_Tree => Project_Node_Tree);
6849 -- The parsing of project files may have changed the current output
6851 if Commands_To_Stdout then
6852 Set_Standard_Output;
6857 if Main_Project = No_Project then
6859 ("""" & Project_File_Name.all & """ processing failed");
6862 Create_Mapping_File := True;
6864 if Verbose_Mode then
6866 Write_Str ("Parsing of project file """);
6867 Write_Str (Project_File_Name.all);
6868 Write_Str (""" is finished.");
6872 -- We add the source directories and the object directories to the
6875 Add_Source_Directories (Main_Project, Project_Tree);
6876 Add_Object_Directories (Main_Project);
6878 Recursive_Compute_Depth (Main_Project);
6880 -- For each project compute the list of the projects it imports
6881 -- directly or indirectly.
6884 Proj : Project_List;
6886 Proj := Project_Tree.Projects;
6887 while Proj /= null loop
6888 Compute_All_Imported_Projects (Proj.Project);
6895 Osint.Add_Default_Search_Dirs;
6897 -- Source file lookups should be cached for efficiency. Source files
6898 -- are not supposed to change. However, we do that now only if no
6899 -- project file is used; if a project file is used, we do it just
6900 -- after changing the directory to the object directory.
6902 Osint.Source_File_Data (Cache => True);
6904 -- Read gnat.adc file to initialize Fname.UF
6906 Fname.UF.Initialize;
6909 Fname.SF.Read_Source_File_Name_Pragmas;
6912 when Err : SFN_Scan.Syntax_Error_In_GNAT_ADC =>
6913 Make_Failed (Exception_Message (Err));
6917 -- Make sure no project object directory is recorded
6919 Project_Of_Current_Object_Directory := No_Project;
6923 ----------------------------
6924 -- Insert_Project_Sources --
6925 ----------------------------
6927 procedure Insert_Project_Sources
6928 (The_Project : Project_Id;
6929 All_Projects : Boolean;
6932 Put_In_Q : Boolean := Into_Q;
6934 Sfile : File_Name_Type;
6937 Extending : constant Boolean := The_Project.Extends /= No_Project;
6939 function Check_Project (P : Project_Id) return Boolean;
6940 -- Returns True if P is The_Project or a project extended by The_Project
6946 function Check_Project (P : Project_Id) return Boolean is
6948 if All_Projects or else P = The_Project then
6951 elsif Extending then
6956 Proj := The_Project;
6957 while Proj /= null loop
6958 if P = Proj.Extends then
6962 Proj := Proj.Extends;
6970 -- Start of processing for Insert_Project_Sources
6973 -- For all the sources in the project files,
6975 Unit := Units_Htable.Get_First (Project_Tree.Units_HT);
6976 while Unit /= null loop
6980 -- If there is a source for the body, and the body has not been
6983 if Unit.File_Names (Impl) /= null
6984 and then not Unit.File_Names (Impl).Locally_Removed
6986 -- And it is a source for the specified project
6988 if Check_Project (Unit.File_Names (Impl).Project) then
6990 -- If we don't have a spec, we cannot consider the source
6991 -- if it is a subunit.
6993 if Unit.File_Names (Spec) = null then
6995 Src_Ind : Source_File_Index;
6997 -- Here we are cheating a little bit: we don't want to
6998 -- use Sinput.L, because it depends on the GNAT tree
6999 -- (Atree, Sinfo, ...). So, we pretend that it is a
7000 -- project file, and we use Sinput.P.
7002 -- Source_File_Is_Subunit is just scanning through the
7003 -- file until it finds one of the reserved words
7004 -- separate, procedure, function, generic or package.
7005 -- Fortunately, these Ada reserved words are also
7006 -- reserved for project files.
7009 Src_Ind := Sinput.P.Load_Project_File
7011 (Unit.File_Names (Impl).Path.Name));
7013 -- If it is a subunit, discard it
7015 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
7019 Sfile := Unit.File_Names (Impl).Display_File;
7020 Index := Unit.File_Names (Impl).Index;
7025 Sfile := Unit.File_Names (Impl).Display_File;
7026 Index := Unit.File_Names (Impl).Index;
7030 elsif Unit.File_Names (Spec) /= null
7031 and then not Unit.File_Names (Spec).Locally_Removed
7032 and then Check_Project (Unit.File_Names (Spec).Project)
7034 -- If there is no source for the body, but there is one for the
7035 -- spec which has not been locally removed, then we take this one.
7037 Sfile := Unit.File_Names (Spec).Display_File;
7038 Index := Unit.File_Names (Spec).Index;
7041 -- If Put_In_Q is True, we insert into the Q
7045 -- For the first source inserted into the Q, we need to initialize
7046 -- the Q, but not for the subsequent sources.
7048 if First_Q_Initialization then
7052 -- And of course, only insert in the Q if the source is not marked
7054 if Sfile /= No_File and then not Is_Marked (Sfile, Index) then
7055 if Verbose_Mode then
7056 Write_Str ("Adding """);
7057 Write_Str (Get_Name_String (Sfile));
7058 Write_Line (""" to the queue");
7061 Insert_Q (Sfile, Index => Index);
7062 Mark (Sfile, Index);
7065 elsif Sfile /= No_File then
7067 -- If Put_In_Q is False, we add the source as if it were specified
7068 -- on the command line, and we set Put_In_Q to True, so that the
7069 -- following sources will be put directly in the queue. This will
7070 -- allow parallel compilation processes if -jx switch is used.
7072 if Verbose_Mode then
7073 Write_Str ("Adding """);
7074 Write_Str (Get_Name_String (Sfile));
7075 Write_Line (""" as if on the command line");
7078 Osint.Add_File (Get_Name_String (Sfile), Index);
7081 -- As we may look into the Q later, ensure the Q has been
7082 -- initialized to avoid errors.
7084 if First_Q_Initialization then
7089 Unit := Units_Htable.Get_Next (Project_Tree.Units_HT);
7091 end Insert_Project_Sources;
7098 (Source_File : File_Name_Type;
7099 Source_Unit : Unit_Name_Type := No_Unit_Name;
7103 if Debug.Debug_Flag_Q then
7104 Write_Str (" Q := Q + [ ");
7105 Write_Name (Source_File);
7117 (File => Source_File,
7118 Unit => Source_Unit,
7123 ---------------------
7124 -- Is_In_Obsoleted --
7125 ---------------------
7127 function Is_In_Obsoleted (F : File_Name_Type) return Boolean is
7134 Name : constant String := Get_Name_String (F);
7136 F2 : File_Name_Type;
7140 while First > Name'First
7141 and then Name (First - 1) /= Directory_Separator
7142 and then Name (First - 1) /= '/'
7147 if First /= Name'First then
7149 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
7156 return Obsoleted.Get (F2);
7159 end Is_In_Obsoleted;
7161 ----------------------------
7162 -- Is_In_Object_Directory --
7163 ----------------------------
7165 function Is_In_Object_Directory
7166 (Source_File : File_Name_Type;
7167 Full_Lib_File : File_Name_Type) return Boolean
7170 -- There is something to check only when using project files. Otherwise,
7171 -- this function returns True (last line of the function).
7173 if Main_Project /= No_Project then
7175 Source_File_Name : constant String :=
7176 Get_Name_String (Source_File);
7177 Saved_Verbosity : constant Verbosity := Current_Verbosity;
7178 Project : Project_Id := No_Project;
7180 Path_Name : Path_Name_Type := No_Path;
7181 pragma Warnings (Off, Path_Name);
7184 -- Call Get_Reference to know the ultimate extending project of
7185 -- the source. Call it with verbosity default to avoid verbose
7188 Current_Verbosity := Default;
7189 Prj.Env.Get_Reference
7190 (Source_File_Name => Source_File_Name,
7192 In_Tree => Project_Tree,
7194 Current_Verbosity := Saved_Verbosity;
7196 -- If this source is in a project, check that the ALI file is in
7197 -- its object directory. If it is not, return False, so that the
7198 -- ALI file will not be skipped.
7200 if Project /= No_Project then
7202 Object_Directory : constant String :=
7206 Object_Directory.Display_Name));
7208 Olast : Natural := Object_Directory'Last;
7210 Lib_File_Directory : constant String :=
7211 Normalize_Pathname (Dir_Name
7212 (Get_Name_String (Full_Lib_File)));
7214 Llast : Natural := Lib_File_Directory'Last;
7217 -- For directories, Normalize_Pathname may or may not put
7218 -- a directory separator at the end, depending on its input.
7219 -- Remove any last directory separator before comparison.
7220 -- Returns True only if the two directories are the same.
7222 if Object_Directory (Olast) = Directory_Separator then
7226 if Lib_File_Directory (Llast) = Directory_Separator then
7230 return Object_Directory (Object_Directory'First .. Olast) =
7231 Lib_File_Directory (Lib_File_Directory'First .. Llast);
7237 -- When the source is not in a project file, always return True
7240 end Is_In_Object_Directory;
7247 (ALI_File : File_Name_Type;
7248 Args : Argument_List;
7249 Success : out Boolean)
7251 Link_Args : Argument_List (1 .. Args'Length + 1);
7254 Get_Name_String (ALI_File);
7255 Link_Args (1) := new String'(Name_Buffer (1 .. Name_Len));
7257 Link_Args (2 .. Args'Length + 1) := Args;
7259 GNAT.OS_Lib.Normalize_Arguments (Link_Args);
7261 Display (Gnatlink.all, Link_Args);
7263 if Gnatlink_Path = null then
7264 Make_Failed ("error, unable to locate " & Gnatlink.all);
7267 GNAT.OS_Lib.Spawn (Gnatlink_Path.all, Link_Args, Success);
7270 ---------------------------
7271 -- List_Bad_Compilations --
7272 ---------------------------
7274 procedure List_Bad_Compilations is
7276 for J in Bad_Compilation.First .. Bad_Compilation.Last loop
7277 if Bad_Compilation.Table (J).File = No_File then
7279 elsif not Bad_Compilation.Table (J).Found then
7280 Inform (Bad_Compilation.Table (J).File, "not found");
7282 Inform (Bad_Compilation.Table (J).File, "compilation error");
7285 end List_Bad_Compilations;
7291 procedure List_Depend is
7292 Lib_Name : File_Name_Type;
7293 Obj_Name : File_Name_Type;
7294 Src_Name : File_Name_Type;
7298 Line_Size : constant := 77;
7301 Set_Standard_Output;
7303 for A in ALIs.First .. ALIs.Last loop
7304 Lib_Name := ALIs.Table (A).Afile;
7306 -- We have to provide the full library file name in In_Place_Mode
7308 if In_Place_Mode then
7309 Lib_Name := Full_Lib_File_Name (Lib_Name);
7312 Obj_Name := Object_File_Name (Lib_Name);
7313 Write_Name (Obj_Name);
7316 Get_Name_String (Obj_Name);
7318 Line_Pos := Len + 2;
7320 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
7321 Src_Name := Sdep.Table (D).Sfile;
7323 if Is_Internal_File_Name (Src_Name)
7324 and then not Check_Readonly_Files
7328 if not Quiet_Output then
7329 Src_Name := Full_Source_Name (Src_Name);
7332 Get_Name_String (Src_Name);
7335 if Line_Pos + Len + 1 > Line_Size then
7341 Line_Pos := Line_Pos + Len + 1;
7344 Write_Name (Src_Name);
7351 if not Commands_To_Stdout then
7360 procedure Make_Failed (S : String) is
7362 Delete_All_Temp_Files;
7366 --------------------
7367 -- Mark_Directory --
7368 --------------------
7370 procedure Mark_Directory
7372 Mark : Lib_Mark_Type;
7373 On_Command_Line : Boolean)
7378 function Base_Directory return String;
7379 -- If Dir comes from the command line, empty string (relative paths are
7380 -- resolved with respect to the current directory), else return the main
7381 -- project's directory.
7383 --------------------
7384 -- Base_Directory --
7385 --------------------
7387 function Base_Directory return String is
7389 if On_Command_Line then
7392 return Get_Name_String (Main_Project.Directory.Display_Name);
7396 Real_Path : constant String := Normalize_Pathname (Dir, Base_Directory);
7398 -- Start of processing for Mark_Directory
7403 if Real_Path'Length = 0 then
7404 Add_Str_To_Name_Buffer (Dir);
7407 Add_Str_To_Name_Buffer (Real_Path);
7410 -- Last character is supposed to be a directory separator
7412 if not Is_Directory_Separator (Name_Buffer (Name_Len)) then
7413 Add_Char_To_Name_Buffer (Directory_Separator);
7416 -- Add flags to the already existing flags
7419 B := Get_Name_Table_Byte (N);
7420 Set_Name_Table_Byte (N, B or Mark);
7423 ----------------------
7424 -- Process_Multilib --
7425 ----------------------
7427 procedure Process_Multilib
7428 (Project_Node_Tree : Project_Node_Tree_Ref)
7430 Output_FD : File_Descriptor;
7431 Output_Name : String_Access;
7432 Arg_Index : Natural := 0;
7433 Success : Boolean := False;
7434 Return_Code : Integer := 0;
7435 Multilib_Gcc_Path : String_Access;
7436 Multilib_Gcc : String_Access;
7437 N_Read : Integer := 0;
7438 Line : String (1 .. 1000);
7439 Args : Argument_List (1 .. N_M_Switch + 1);
7442 pragma Assert (N_M_Switch > 0 and RTS_Specified = null);
7444 -- In case we detected a multilib switch and the user has not
7445 -- manually specified a specific RTS we emulate the following command:
7446 -- gnatmake $FLAGS --RTS=$(gcc -print-multi-directory $FLAGS)
7448 -- First select the flags which might have an impact on multilib
7449 -- processing. Note that this is an heuristic selection and it
7450 -- will need to be maintained over time. The condition has to
7451 -- be kept synchronized with N_M_Switch counting in Scan_Make_Arg.
7453 for Next_Arg in 1 .. Argument_Count loop
7455 Argv : constant String := Argument (Next_Arg);
7458 and then Argv (1) = '-'
7459 and then Argv (2) = 'm'
7460 and then Argv /= "-margs"
7462 -- Ignore -mieee to avoid spawning an extra gcc in this case
7464 and then Argv /= "-mieee"
7466 Arg_Index := Arg_Index + 1;
7467 Args (Arg_Index) := new String'(Argv);
7472 pragma Assert (Arg_Index = N_M_Switch);
7474 Args (Args'Last) := new String'("-print-multi-directory");
7476 -- Call the GCC driver with the collected flags and save its
7477 -- output. Alternate design would be to link in gnatmake the
7478 -- relevant part of the GCC driver.
7480 if Saved_Gcc /= null then
7481 Multilib_Gcc := Saved_Gcc;
7483 Multilib_Gcc := Gcc;
7486 Multilib_Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Multilib_Gcc.all);
7488 Create_Temp_Output_File (Output_FD, Output_Name);
7490 if Output_FD = Invalid_FD then
7495 (Multilib_Gcc_Path.all, Args, Output_FD, Return_Code, False);
7498 if Return_Code /= 0 then
7502 -- Parse the GCC driver output which is a single line, removing CR/LF
7504 Output_FD := Open_Read (Output_Name.all, Binary);
7506 if Output_FD = Invalid_FD then
7510 N_Read := Read (Output_FD, Line (1)'Address, Line'Length);
7512 Delete_File (Output_Name.all, Success);
7514 for J in reverse 1 .. N_Read loop
7515 if Line (J) = ASCII.CR or else Line (J) = ASCII.LF then
7516 N_Read := N_Read - 1;
7522 -- In case the standard RTS is selected do nothing
7524 if N_Read = 0 or else Line (1 .. N_Read) = "." then
7528 -- Otherwise add -margs --RTS=output
7530 Scan_Make_Arg (Project_Node_Tree, "-margs", And_Save => True);
7532 (Project_Node_Tree, "--RTS=" & Line (1 .. N_Read), And_Save => True);
7533 end Process_Multilib;
7535 -----------------------------
7536 -- Recursive_Compute_Depth --
7537 -----------------------------
7539 procedure Recursive_Compute_Depth (Project : Project_Id) is
7540 use Project_Boolean_Htable;
7541 Seen : Project_Boolean_Htable.Instance := Project_Boolean_Htable.Nil;
7543 procedure Recurse (Prj : Project_Id; Depth : Natural);
7544 -- Recursive procedure that does the work, keeping track of the depth
7550 procedure Recurse (Prj : Project_Id; Depth : Natural) is
7551 List : Project_List;
7555 if Prj.Depth >= Depth or else Get (Seen, Prj) then
7559 -- We need a test to avoid infinite recursions with limited withs:
7560 -- If we have A -> B -> A, then when set level of A to n, we try and
7561 -- set level of B to n+1, and then level of A to n + 2, ...
7563 Set (Seen, Prj, True);
7567 -- Visit each imported project
7569 List := Prj.Imported_Projects;
7570 while List /= null loop
7571 Proj := List.Project;
7573 Recurse (Prj => Proj, Depth => Depth + 1);
7576 -- We again allow changing the depth of this project later on if it
7577 -- is in fact imported by a lower-level project.
7579 Set (Seen, Prj, False);
7582 Proj : Project_List;
7584 -- Start of processing for Recursive_Compute_Depth
7587 Proj := Project_Tree.Projects;
7588 while Proj /= null loop
7589 Proj.Project.Depth := 0;
7593 Recurse (Project, Depth => 1);
7595 end Recursive_Compute_Depth;
7597 -------------------------------
7598 -- Report_Compilation_Failed --
7599 -------------------------------
7601 procedure Report_Compilation_Failed is
7603 Delete_All_Temp_Files;
7604 Exit_Program (E_Fatal);
7605 end Report_Compilation_Failed;
7607 ------------------------
7608 -- Sigint_Intercepted --
7609 ------------------------
7611 procedure Sigint_Intercepted is
7612 SIGINT : constant := 2;
7616 Write_Line ("*** Interrupted ***");
7618 -- Send SIGINT to all outstanding compilation processes spawned
7620 for J in 1 .. Outstanding_Compiles loop
7621 Kill (Running_Compile (J).Pid, SIGINT, 1);
7624 Delete_All_Temp_Files;
7626 -- ??? OS_Exit (1) is equivalent to Exit_Program (E_No_Compile),
7627 -- shouldn't that be Exit_Program (E_Abort) instead?
7628 end Sigint_Intercepted;
7634 procedure Scan_Make_Arg
7635 (Project_Node_Tree : Project_Node_Tree_Ref;
7642 Gnatmake_Switch_Found := True;
7644 pragma Assert (Argv'First = 1);
7646 if Argv'Length = 0 then
7650 -- If the previous switch has set the Project_File_Name_Present flag
7651 -- (that is we have seen a -P alone), then the next argument is the name
7652 -- of the project file.
7654 if Project_File_Name_Present and then Project_File_Name = null then
7655 if Argv (1) = '-' then
7656 Make_Failed ("project file name missing after -P");
7659 Project_File_Name_Present := False;
7660 Project_File_Name := new String'(Argv);
7663 -- If the previous switch has set the Output_File_Name_Present flag
7664 -- (that is we have seen a -o), then the next argument is the name of
7665 -- the output executable.
7667 elsif Output_File_Name_Present
7668 and then not Output_File_Name_Seen
7670 Output_File_Name_Seen := True;
7672 if Argv (1) = '-' then
7673 Make_Failed ("output file name missing after -o");
7676 Add_Switch ("-o", Linker, And_Save => And_Save);
7677 Add_Switch (Executable_Name (Argv), Linker, And_Save => And_Save);
7680 -- If the previous switch has set the Object_Directory_Present flag
7681 -- (that is we have seen a -D), then the next argument is the path name
7682 -- of the object directory.
7684 elsif Object_Directory_Present
7685 and then not Object_Directory_Seen
7687 Object_Directory_Seen := True;
7689 if Argv (1) = '-' then
7690 Make_Failed ("object directory path name missing after -D");
7692 elsif not Is_Directory (Argv) then
7693 Make_Failed ("cannot find object directory """ & Argv & """");
7696 -- Record the object directory. Make sure it ends with a directory
7700 Norm : constant String := Normalize_Pathname (Argv);
7702 if Norm (Norm'Last) = Directory_Separator then
7703 Object_Directory_Path := new String'(Norm);
7705 Object_Directory_Path :=
7706 new String'(Norm & Directory_Separator);
7709 Add_Lib_Search_Dir (Norm);
7711 -- Specify the object directory to the binder
7713 Add_Switch ("-aO" & Norm, Binder, And_Save => And_Save);
7718 -- Then check if we are dealing with -cargs/-bargs/-largs/-margs
7720 elsif Argv = "-bargs"
7729 when 'c' => Program_Args := Compiler;
7730 when 'b' => Program_Args := Binder;
7731 when 'l' => Program_Args := Linker;
7732 when 'm' => Program_Args := None;
7735 raise Program_Error;
7738 -- A special test is needed for the -o switch within a -largs since that
7739 -- is another way to specify the name of the final executable.
7741 elsif Program_Args = Linker
7742 and then Argv = "-o"
7744 Make_Failed ("switch -o not allowed within a -largs. " &
7745 "Use -o directly.");
7747 -- Check to see if we are reading switches after a -cargs, -bargs or
7748 -- -largs switch. If so, save it.
7750 elsif Program_Args /= None then
7752 -- Check to see if we are reading -I switches in order
7753 -- to take into account in the src & lib search directories.
7755 if Argv'Length > 2 and then Argv (1 .. 2) = "-I" then
7756 if Argv (3 .. Argv'Last) = "-" then
7757 Look_In_Primary_Dir := False;
7759 elsif Program_Args = Compiler then
7760 if Argv (3 .. Argv'Last) /= "-" then
7761 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7764 elsif Program_Args = Binder then
7765 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7769 Add_Switch (Argv, Program_Args, And_Save => And_Save);
7771 -- Handle non-default compiler, binder, linker, and handle --RTS switch
7773 elsif Argv'Length > 2 and then Argv (1 .. 2) = "--" then
7775 and then Argv (1 .. 6) = "--GCC="
7778 Program_Args : constant Argument_List_Access :=
7779 Argument_String_To_List
7780 (Argv (7 .. Argv'Last));
7784 Saved_Gcc := new String'(Program_Args.all (1).all);
7786 Gcc := new String'(Program_Args.all (1).all);
7789 for J in 2 .. Program_Args.all'Last loop
7791 (Program_Args.all (J).all, Compiler, And_Save => And_Save);
7795 elsif Argv'Length > 11
7796 and then Argv (1 .. 11) = "--GNATBIND="
7799 Program_Args : constant Argument_List_Access :=
7800 Argument_String_To_List
7801 (Argv (12 .. Argv'Last));
7805 Saved_Gnatbind := new String'(Program_Args.all (1).all);
7807 Gnatbind := new String'(Program_Args.all (1).all);
7810 for J in 2 .. Program_Args.all'Last loop
7812 (Program_Args.all (J).all, Binder, And_Save => And_Save);
7816 elsif Argv'Length > 11
7817 and then Argv (1 .. 11) = "--GNATLINK="
7820 Program_Args : constant Argument_List_Access :=
7821 Argument_String_To_List
7822 (Argv (12 .. Argv'Last));
7825 Saved_Gnatlink := new String'(Program_Args.all (1).all);
7827 Gnatlink := new String'(Program_Args.all (1).all);
7830 for J in 2 .. Program_Args.all'Last loop
7831 Add_Switch (Program_Args.all (J).all, Linker);
7835 elsif Argv'Length >= 5 and then
7836 Argv (1 .. 5) = "--RTS"
7838 Add_Switch (Argv, Compiler, And_Save => And_Save);
7839 Add_Switch (Argv, Binder, And_Save => And_Save);
7841 if Argv'Length <= 6 or else Argv (6) /= '=' then
7842 Make_Failed ("missing path for --RTS");
7845 -- Check that this is the first time we see this switch or
7846 -- if it is not the first time, the same path is specified.
7848 if RTS_Specified = null then
7849 RTS_Specified := new String'(Argv (7 .. Argv'Last));
7851 elsif RTS_Specified.all /= Argv (7 .. Argv'Last) then
7852 Make_Failed ("--RTS cannot be specified multiple times");
7855 -- Valid --RTS switch
7862 Src_Path_Name : constant String_Ptr :=
7864 (Argv (7 .. Argv'Last), Include);
7866 Lib_Path_Name : constant String_Ptr :=
7868 (Argv (7 .. Argv'Last), Objects);
7871 if Src_Path_Name /= null
7872 and then Lib_Path_Name /= null
7874 -- Set RTS_*_Path_Name variables, so that correct direct-
7875 -- ories will be set when Osint.Add_Default_Search_Dirs
7878 RTS_Src_Path_Name := Src_Path_Name;
7879 RTS_Lib_Path_Name := Lib_Path_Name;
7881 elsif Src_Path_Name = null
7882 and then Lib_Path_Name = null
7884 Make_Failed ("RTS path not valid: missing " &
7885 "adainclude and adalib directories");
7887 elsif Src_Path_Name = null then
7888 Make_Failed ("RTS path not valid: missing adainclude " &
7891 elsif Lib_Path_Name = null then
7892 Make_Failed ("RTS path not valid: missing adalib " &
7898 elsif Argv'Length >= 8 and then
7899 Argv (1 .. 8) = "--param="
7901 Add_Switch (Argv, Compiler, And_Save => And_Save);
7902 Add_Switch (Argv, Linker, And_Save => And_Save);
7905 Scan_Make_Switches (Project_Node_Tree, Argv, Success);
7908 -- If we have seen a regular switch process it
7910 elsif Argv (1) = '-' then
7911 if Argv'Length = 1 then
7912 Make_Failed ("switch character cannot be followed by a blank");
7914 -- Incorrect switches that should start with "--"
7916 elsif (Argv'Length > 5 and then Argv (1 .. 5) = "-RTS=")
7917 or else (Argv'Length > 5 and then Argv (1 .. 5) = "-GCC=")
7918 or else (Argv'Length > 8 and then Argv (1 .. 7) = "-param=")
7919 or else (Argv'Length > 10 and then Argv (1 .. 10) = "-GNATLINK=")
7920 or else (Argv'Length > 10 and then Argv (1 .. 10) = "-GNATBIND=")
7922 Make_Failed ("option " & Argv & " should start with '--'");
7926 elsif Argv (2 .. Argv'Last) = "I-" then
7927 Look_In_Primary_Dir := False;
7929 -- Forbid -?- or -??- where ? is any character
7931 elsif (Argv'Length = 3 and then Argv (3) = '-')
7932 or else (Argv'Length = 4 and then Argv (4) = '-')
7935 ("trailing ""-"" at the end of " & Argv & " forbidden.");
7939 elsif Argv (2) = 'I' then
7940 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7941 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7942 Add_Switch (Argv, Compiler, And_Save => And_Save);
7943 Add_Switch (Argv, Binder, And_Save => And_Save);
7945 -- -aIdir (to gcc this is like a -I switch)
7947 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aI" then
7948 Add_Source_Search_Dir (Argv (4 .. Argv'Last), And_Save);
7950 ("-I" & Argv (4 .. Argv'Last), Compiler, And_Save => And_Save);
7951 Add_Switch (Argv, Binder, And_Save => And_Save);
7955 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aO" then
7956 Add_Library_Search_Dir (Argv (4 .. Argv'Last), And_Save);
7957 Add_Switch (Argv, Binder, And_Save => And_Save);
7959 -- -aLdir (to gnatbind this is like a -aO switch)
7961 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aL" then
7962 Mark_Directory (Argv (4 .. Argv'Last), Ada_Lib_Dir, And_Save);
7963 Add_Library_Search_Dir (Argv (4 .. Argv'Last), And_Save);
7965 ("-aO" & Argv (4 .. Argv'Last), Binder, And_Save => And_Save);
7969 elsif Argv'Length >= 13 and then Argv (2 .. 13) = "aamp_target=" then
7970 Add_Switch (Argv, Compiler, And_Save => And_Save);
7972 -- Set the aamp_target environment variable so that the binder and
7973 -- linker will use the proper target library. This is consistent
7974 -- with how things work when -aamp_target is passed on the command
7975 -- line to gnaampmake.
7977 Setenv ("aamp_target", Argv (14 .. Argv'Last));
7979 -- -Adir (to gnatbind this is like a -aO switch, to gcc like a -I)
7981 elsif Argv (2) = 'A' then
7982 Mark_Directory (Argv (3 .. Argv'Last), Ada_Lib_Dir, And_Save);
7983 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7984 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7986 ("-I" & Argv (3 .. Argv'Last), Compiler, And_Save => And_Save);
7988 ("-aO" & Argv (3 .. Argv'Last), Binder, And_Save => And_Save);
7992 elsif Argv (2) = 'L' then
7993 Add_Switch (Argv, Linker, And_Save => And_Save);
7995 -- For -gxxxxx, -pg, -mxxx, -fxxx: give the switch to both the
7996 -- compiler and the linker (except for -gnatxxx which is only for the
7997 -- compiler). Some of the -mxxx (for example -m64) and -fxxx (for
7998 -- example -ftest-coverage for gcov) need to be used when compiling
7999 -- the binder generated files, and using all these gcc switches for
8000 -- the binder generated files should not be a problem.
8003 (Argv (2) = 'g' and then (Argv'Last < 5
8004 or else Argv (2 .. 5) /= "gnat"))
8005 or else Argv (2 .. Argv'Last) = "pg"
8006 or else (Argv (2) = 'm' and then Argv'Last > 2)
8007 or else (Argv (2) = 'f' and then Argv'Last > 2)
8009 Add_Switch (Argv, Compiler, And_Save => And_Save);
8010 Add_Switch (Argv, Linker, And_Save => And_Save);
8012 -- The following condition has to be kept synchronized with
8013 -- the Process_Multilib one.
8016 and then Argv /= "-mieee"
8018 N_M_Switch := N_M_Switch + 1;
8021 -- -C=<mapping file>
8023 elsif Argv'Last > 2 and then Argv (2) = 'C' then
8025 if Argv (3) /= '=' or else Argv'Last <= 3 then
8026 Make_Failed ("illegal switch " & Argv);
8029 Gnatmake_Mapping_File := new String'(Argv (4 .. Argv'Last));
8034 elsif Argv'Last = 2 and then Argv (2) = 'D' then
8035 if Project_File_Name /= null then
8037 ("-D cannot be used in conjunction with a project file");
8040 Scan_Make_Switches (Project_Node_Tree, Argv, Success);
8045 elsif Argv (2) = 'd' and then Argv'Last = 2 then
8046 Display_Compilation_Progress := True;
8050 elsif Argv'Last = 2 and then Argv (2) = 'i' then
8051 if Project_File_Name /= null then
8053 ("-i cannot be used in conjunction with a project file");
8055 Scan_Make_Switches (Project_Node_Tree, Argv, Success);
8058 -- -j (need to save the result)
8060 elsif Argv (2) = 'j' then
8061 Scan_Make_Switches (Project_Node_Tree, Argv, Success);
8064 Saved_Maximum_Processes := Maximum_Processes;
8069 elsif Argv (2) = 'm' and then Argv'Last = 2 then
8070 Minimal_Recompilation := True;
8074 elsif Argv (2) = 'u' and then Argv'Last = 2 then
8075 Unique_Compile := True;
8076 Compile_Only := True;
8077 Do_Bind_Step := False;
8078 Do_Link_Step := False;
8082 elsif Argv (2) = 'U'
8083 and then Argv'Last = 2
8085 Unique_Compile_All_Projects := True;
8086 Unique_Compile := True;
8087 Compile_Only := True;
8088 Do_Bind_Step := False;
8089 Do_Link_Step := False;
8091 -- -Pprj or -P prj (only once, and only on the command line)
8093 elsif Argv (2) = 'P' then
8094 if Project_File_Name /= null then
8095 Make_Failed ("cannot have several project files specified");
8097 elsif Object_Directory_Path /= null then
8099 ("-D cannot be used in conjunction with a project file");
8101 elsif In_Place_Mode then
8103 ("-i cannot be used in conjunction with a project file");
8105 elsif not And_Save then
8107 -- It could be a tool other than gnatmake (e.g. gnatdist)
8108 -- or a -P switch inside a project file.
8111 ("either the tool is not ""project-aware"" or " &
8112 "a project file is specified inside a project file");
8114 elsif Argv'Last = 2 then
8116 -- -P is used alone: the project file name is the next option
8118 Project_File_Name_Present := True;
8121 Project_File_Name := new String'(Argv (3 .. Argv'Last));
8124 -- -vPx (verbosity of the parsing of the project files)
8127 and then Argv (2 .. 3) = "vP"
8128 and then Argv (4) in '0' .. '2'
8133 Current_Verbosity := Prj.Default;
8135 Current_Verbosity := Prj.Medium;
8137 Current_Verbosity := Prj.High;
8143 -- -Xext=val (External assignment)
8145 elsif Argv (2) = 'X'
8146 and then Is_External_Assignment (Project_Node_Tree, Argv)
8148 -- Is_External_Assignment has side effects when it returns True
8152 -- If -gnath is present, then generate the usage information right
8153 -- now and do not pass this option on to the compiler calls.
8155 elsif Argv = "-gnath" then
8158 -- If -gnatc is specified, make sure the bind and link steps are not
8161 elsif Argv'Length >= 6 and then Argv (2 .. 6) = "gnatc" then
8163 -- If -gnatc is specified, make sure the bind and link steps are
8166 Add_Switch (Argv, Compiler, And_Save => And_Save);
8167 Operating_Mode := Check_Semantics;
8168 Check_Object_Consistency := False;
8169 Compile_Only := True;
8170 Do_Bind_Step := False;
8171 Do_Link_Step := False;
8173 elsif Argv (2 .. Argv'Last) = "nostdlib" then
8175 -- Don't pass -nostdlib to gnatlink, it will disable
8176 -- linking with all standard library files.
8180 Add_Switch (Argv, Compiler, And_Save => And_Save);
8181 Add_Switch (Argv, Binder, And_Save => And_Save);
8183 elsif Argv (2 .. Argv'Last) = "nostdinc" then
8185 -- Pass -nostdinc to the Compiler and to gnatbind
8188 Add_Switch (Argv, Compiler, And_Save => And_Save);
8189 Add_Switch (Argv, Binder, And_Save => And_Save);
8191 -- All other switches are processed by Scan_Make_Switches. If the
8192 -- call returns with Gnatmake_Switch_Found = False, then the switch
8193 -- is passed to the compiler.
8197 (Project_Node_Tree, Argv, Gnatmake_Switch_Found);
8199 if not Gnatmake_Switch_Found then
8200 Add_Switch (Argv, Compiler, And_Save => And_Save);
8204 -- If not a switch it must be a file name
8208 Mains.Add_Main (Argv);
8216 function Switches_Of
8217 (Source_File : File_Name_Type;
8218 Source_File_Name : String;
8220 Project : Project_Id;
8221 In_Package : Package_Id;
8222 Allow_ALI : Boolean) return Variable_Value
8224 Lang : constant Language_Ptr := Get_Language_From_Name (Project, "ada");
8226 Switches : Variable_Value;
8228 Defaults : constant Array_Element_Id :=
8230 (Name => Name_Default_Switches,
8232 Project_Tree.Packages.Table
8233 (In_Package).Decl.Arrays,
8234 In_Tree => Project_Tree);
8236 Switches_Array : constant Array_Element_Id :=
8238 (Name => Name_Switches,
8240 Project_Tree.Packages.Table
8241 (In_Package).Decl.Arrays,
8242 In_Tree => Project_Tree);
8245 -- First, try Switches (<file name>)
8249 (Index => Name_Id (Source_File),
8250 Src_Index => Source_Index,
8251 In_Array => Switches_Array,
8252 In_Tree => Project_Tree);
8254 -- Check also without the suffix
8256 if Switches = Nil_Variable_Value
8257 and then Lang /= null
8260 Naming : Lang_Naming_Data renames Lang.Config.Naming_Data;
8261 Name : String (1 .. Source_File_Name'Length + 3);
8262 Last : Positive := Source_File_Name'Length;
8263 Spec_Suffix : constant String :=
8264 Get_Name_String (Naming.Spec_Suffix);
8265 Body_Suffix : constant String :=
8266 Get_Name_String (Naming.Body_Suffix);
8267 Truncated : Boolean := False;
8270 Name (1 .. Last) := Source_File_Name;
8272 if Last > Body_Suffix'Length
8273 and then Name (Last - Body_Suffix'Length + 1 .. Last) =
8277 Last := Last - Body_Suffix'Length;
8281 and then Last > Spec_Suffix'Length
8282 and then Name (Last - Spec_Suffix'Length + 1 .. Last) =
8286 Last := Last - Spec_Suffix'Length;
8291 Add_Str_To_Name_Buffer (Name (1 .. Last));
8294 (Index => Name_Find,
8296 In_Array => Switches_Array,
8297 In_Tree => Project_Tree);
8299 if Switches = Nil_Variable_Value and then Allow_ALI then
8300 Last := Source_File_Name'Length;
8302 while Name (Last) /= '.' loop
8307 Add_Str_To_Name_Buffer (Name (1 .. Last));
8308 Add_Str_To_Name_Buffer ("ali");
8312 (Index => Name_Find,
8314 In_Array => Switches_Array,
8315 In_Tree => Project_Tree);
8321 -- Next, try Switches ("Ada")
8323 if Switches = Nil_Variable_Value then
8328 In_Array => Switches_Array,
8329 In_Tree => Project_Tree,
8330 Force_Lower_Case_Index => True);
8332 if Switches /= Nil_Variable_Value then
8333 Switch_May_Be_Passed_To_The_Compiler := False;
8337 -- Next, try Switches (others)
8339 if Switches = Nil_Variable_Value then
8342 (Index => All_Other_Names,
8344 In_Array => Switches_Array,
8345 In_Tree => Project_Tree);
8347 if Switches /= Nil_Variable_Value then
8348 Switch_May_Be_Passed_To_The_Compiler := False;
8352 -- And finally, Default_Switches ("Ada")
8354 if Switches = Nil_Variable_Value then
8359 In_Array => Defaults,
8360 In_Tree => Project_Tree);
8372 if Usage_Needed then
8373 Usage_Needed := False;
8379 -- Make sure that in case of failure, the temp files will be deleted
8381 Prj.Com.Fail := Make_Failed'Access;
8382 MLib.Fail := Make_Failed'Access;
8383 Makeutl.Do_Fail := Make_Failed'Access;