1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
27 with ALI.Util; use ALI.Util;
32 with Fname; use Fname;
33 with Fname.SF; use Fname.SF;
34 with Fname.UF; use Fname.UF;
35 with Gnatvsn; use Gnatvsn;
36 with Hostparm; use Hostparm;
38 with Makeutl; use Makeutl;
41 with MLib.Tgt; use MLib.Tgt;
43 with Namet; use Namet;
45 with Osint.M; use Osint.M;
46 with Osint; use Osint;
47 with Output; use Output;
52 with Prj.Tree; use Prj.Tree;
56 with Snames; use Snames;
58 pragma Warnings (Off);
62 with Switch; use Switch;
63 with Switch.M; use Switch.M;
64 with Targparm; use Targparm;
67 with Types; use Types;
69 with Ada.Exceptions; use Ada.Exceptions;
70 with Ada.Command_Line; use Ada.Command_Line;
72 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
73 with GNAT.Dynamic_HTables; use GNAT.Dynamic_HTables;
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 Must_Compile : Boolean := False;
206 -- True if gnatmake is invoked with -f -u and one or several mains on the
209 Main_On_Command_Line : Boolean := False;
210 -- True if gnatmake is invoked with one or several mains on the command
213 RTS_Specified : String_Access := null;
214 -- Used to detect multiple --RTS= switches
216 N_M_Switch : Natural := 0;
217 -- Used to count -mxxx switches that can affect multilib
219 type Q_Record is record
220 File : File_Name_Type;
221 Unit : Unit_Name_Type;
224 -- File is the name of the file to compile. Unit is for gnatdist
225 -- use in order to easily get the unit name of a file to compile
226 -- when its name is krunched or declared in gnat.adc. Index, when not 0,
227 -- is the index of the unit in a multi-unit source.
229 package Q is new Table.Table (
230 Table_Component_Type => Q_Record,
231 Table_Index_Type => Natural,
232 Table_Low_Bound => 0,
233 Table_Initial => 4000,
234 Table_Increment => 100,
235 Table_Name => "Make.Q");
236 -- This is the actual Q
238 -- The 3 following packages are used to store gcc, gnatbind and gnatlink
239 -- switches found in the project files.
241 package Gcc_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.Gcc_Switches");
249 package Binder_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.Binder_Switches");
257 package Linker_Switches is new Table.Table (
258 Table_Component_Type => String_Access,
259 Table_Index_Type => Integer,
260 Table_Low_Bound => 1,
262 Table_Increment => 100,
263 Table_Name => "Make.Linker_Switches");
265 -- The following instantiations and variables are necessary to save what
266 -- is found on the command line, in case there is a project file specified.
268 package Saved_Gcc_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_Gcc_Switches");
276 package Saved_Binder_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_Binder_Switches");
284 package Saved_Linker_Switches 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.Saved_Linker_Switches");
292 package Switches_To_Check 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.Switches_To_Check");
300 package Library_Paths is new Table.Table (
301 Table_Component_Type => String_Access,
302 Table_Index_Type => Integer,
303 Table_Low_Bound => 1,
305 Table_Increment => 100,
306 Table_Name => "Make.Library_Paths");
308 package Failed_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.Failed_Links");
316 package Successful_Links is new Table.Table (
317 Table_Component_Type => File_Name_Type,
318 Table_Index_Type => Integer,
319 Table_Low_Bound => 1,
321 Table_Increment => 100,
322 Table_Name => "Make.Successful_Links");
324 package Library_Projs is new Table.Table (
325 Table_Component_Type => Project_Id,
326 Table_Index_Type => Integer,
327 Table_Low_Bound => 1,
329 Table_Increment => 100,
330 Table_Name => "Make.Library_Projs");
332 -- Two variables to keep the last binder and linker switch index in tables
333 -- Binder_Switches and Linker_Switches, before adding switches from the
334 -- project file (if any) and switches from the command line (if any).
336 Last_Binder_Switch : Integer := 0;
337 Last_Linker_Switch : Integer := 0;
339 Normalized_Switches : Argument_List_Access := new Argument_List (1 .. 10);
340 Last_Norm_Switch : Natural := 0;
342 Saved_Maximum_Processes : Natural := 0;
344 Gnatmake_Switch_Found : Boolean;
345 -- Set by Scan_Make_Arg. True when the switch is a gnatmake switch.
346 -- Tested by Add_Switches when switches in package Builder must all be
347 -- gnatmake switches.
349 Switch_May_Be_Passed_To_The_Compiler : Boolean;
350 -- Set by Add_Switches and Switches_Of. True when unrecognized switches
351 -- are passed to the Ada compiler.
353 type Arg_List_Ref is access Argument_List;
354 The_Saved_Gcc_Switches : Arg_List_Ref;
356 Project_File_Name : String_Access := null;
357 -- The path name of the main project file, if any
359 Project_File_Name_Present : Boolean := False;
360 -- True when -P is used with a space between -P and the project file name
362 Current_Verbosity : Prj.Verbosity := Prj.Default;
363 -- Verbosity to parse the project files
365 Main_Project : Prj.Project_Id := No_Project;
366 -- The project id of the main project file, if any
368 Project_Of_Current_Object_Directory : Project_Id := No_Project;
369 -- The object directory of the project for the last compilation. Avoid
370 -- calling Change_Dir if the current working directory is already this
373 -- Packages of project files where unknown attributes are errors
375 Naming_String : aliased String := "naming";
376 Builder_String : aliased String := "builder";
377 Compiler_String : aliased String := "compiler";
378 Binder_String : aliased String := "binder";
379 Linker_String : aliased String := "linker";
381 Gnatmake_Packages : aliased String_List :=
382 (Naming_String 'Access,
383 Builder_String 'Access,
384 Compiler_String 'Access,
385 Binder_String 'Access,
386 Linker_String 'Access);
388 Packages_To_Check_By_Gnatmake : constant String_List_Access :=
389 Gnatmake_Packages'Access;
391 procedure Add_Library_Search_Dir
393 On_Command_Line : Boolean);
394 -- Call Add_Lib_Search_Dir with an absolute directory path. If Path is
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_Search_Dir
401 On_Command_Line : Boolean);
402 -- Call Add_Src_Search_Dir with an absolute directory path. If Path is a
403 -- relative path, when On_Command_Line is True, it is relative to the
404 -- current working directory. When On_Command_Line is False, it is relative
405 -- to the project directory of the main project.
407 procedure Add_Source_Dir (N : String);
408 -- Call Add_Src_Search_Dir (output one line when in verbose mode)
410 procedure Add_Source_Directories is
411 new Prj.Env.For_All_Source_Dirs (Action => Add_Source_Dir);
413 procedure Add_Object_Dir (N : String);
414 -- Call Add_Lib_Search_Dir (output one line when in verbose mode)
416 procedure Add_Object_Directories is
417 new Prj.Env.For_All_Object_Dirs (Action => Add_Object_Dir);
419 procedure Change_To_Object_Directory (Project : Project_Id);
420 -- Change to the object directory of project Project, if this is not
421 -- already the current working directory.
423 type Bad_Compilation_Info is record
424 File : File_Name_Type;
425 Unit : Unit_Name_Type;
428 -- File is the name of the file for which a compilation failed. Unit is for
429 -- gnatdist use in order to easily get the unit name of a file when its
430 -- name is krunched or declared in gnat.adc. Found is False if the
431 -- compilation failed because the file could not be found.
433 package Bad_Compilation is new Table.Table (
434 Table_Component_Type => Bad_Compilation_Info,
435 Table_Index_Type => Natural,
436 Table_Low_Bound => 1,
438 Table_Increment => 100,
439 Table_Name => "Make.Bad_Compilation");
440 -- Full name of all the source files for which compilation fails
442 Do_Compile_Step : Boolean := True;
443 Do_Bind_Step : Boolean := True;
444 Do_Link_Step : Boolean := True;
445 -- Flags to indicate what step should be executed. Can be set to False
446 -- with the switches -c, -b and -l. These flags are reset to True for
447 -- each invocation of procedure Gnatmake.
449 Shared_String : aliased String := "-shared";
450 Force_Elab_Flags_String : aliased String := "-F";
452 No_Shared_Switch : aliased Argument_List := (1 .. 0 => null);
453 Shared_Switch : aliased Argument_List := (1 => Shared_String'Access);
454 Bind_Shared : Argument_List_Access := No_Shared_Switch'Access;
455 -- Switch to added in front of gnatbind switches. By default no switch is
456 -- added. Switch "-shared" is added if there is a non-static Library
459 Shared_Libgcc : aliased String := "-shared-libgcc";
461 No_Shared_Libgcc_Switch : aliased Argument_List := (1 .. 0 => null);
462 Shared_Libgcc_Switch : aliased Argument_List :=
463 (1 => Shared_Libgcc'Access);
464 Link_With_Shared_Libgcc : Argument_List_Access :=
465 No_Shared_Libgcc_Switch'Access;
467 procedure Make_Failed (S : String);
468 -- Delete all temp files created by Gnatmake and call Osint.Fail, with the
469 -- parameter S (see osint.ads). This is called from the Prj hierarchy and
470 -- the MLib hierarchy.
472 --------------------------
473 -- Obsolete Executables --
474 --------------------------
476 Executable_Obsolete : Boolean := False;
477 -- Executable_Obsolete is initially set to False for each executable,
478 -- and is set to True whenever one of the source of the executable is
479 -- compiled, or has already been compiled for another executable.
481 Max_Header : constant := 200;
482 -- This needs a proper comment, it used to say "arbitrary"
483 -- that's not an adequate comment ???
485 type Header_Num is range 1 .. Max_Header;
486 -- Header_Num for the hash table Obsoleted below
488 function Hash (F : File_Name_Type) return Header_Num;
489 -- Hash function for the hash table Obsoleted below
491 package Obsoleted is new System.HTable.Simple_HTable
492 (Header_Num => Header_Num,
495 Key => File_Name_Type,
498 -- A hash table to keep all files that have been compiled, to detect
499 -- if an executable is up to date or not.
501 procedure Enter_Into_Obsoleted (F : File_Name_Type);
502 -- Enter a file name, without directory information, into the hash table
505 function Is_In_Obsoleted (F : File_Name_Type) return Boolean;
506 -- Check if a file name, without directory information, has already been
507 -- entered into the hash table Obsoleted.
509 type Dependency is record
510 This : File_Name_Type;
511 Depends_On : File_Name_Type;
513 -- Components of table Dependencies below
515 package Dependencies is new Table.Table (
516 Table_Component_Type => Dependency,
517 Table_Index_Type => Integer,
518 Table_Low_Bound => 1,
520 Table_Increment => 100,
521 Table_Name => "Make.Dependencies");
522 -- A table to keep dependencies, to be able to decide if an executable
523 -- is obsolete. More explanation needed ???
525 -- procedure Add_Dependency (S : File_Name_Type; On : File_Name_Type);
526 -- -- Add one entry in table Dependencies
528 ----------------------------
529 -- Arguments and Switches --
530 ----------------------------
532 Arguments : Argument_List_Access;
533 -- Used to gather the arguments for invocation of the compiler
535 Last_Argument : Natural := 0;
536 -- Last index of arguments in Arguments above
538 Arguments_Project : Project_Id;
539 -- Project id, if any, of the source to be compiled
541 Arguments_Path_Name : Path_Name_Type;
542 -- Full path of the source to be compiled, when Arguments_Project is not
545 Dummy_Switch : constant String_Access := new String'("- ");
546 -- Used to initialized Prev_Switch in procedure Check
548 procedure Add_Arguments (Args : Argument_List);
549 -- Add arguments to global variable Arguments, increasing its size
550 -- if necessary and adjusting Last_Argument.
552 function Configuration_Pragmas_Switch
553 (For_Project : Project_Id) return Argument_List;
554 -- Return an argument list of one element, if there is a configuration
555 -- pragmas file to be specified for For_Project,
556 -- otherwise return an empty argument list.
562 procedure List_Depend;
563 -- Prints to standard output the list of object dependencies. This list
564 -- can be used directly in a Makefile. A call to Compile_Sources must
565 -- precede the call to List_Depend. Also because this routine uses the
566 -- ALI files that were originally loaded and scanned by Compile_Sources,
567 -- no additional ALI files should be scanned between the two calls (i.e.
568 -- between the call to Compile_Sources and List_Depend.)
570 procedure List_Bad_Compilations;
571 -- Prints out the list of all files for which the compilation failed
573 Usage_Needed : Boolean := True;
574 -- Flag used to make sure Makeusg is call at most once
577 -- Call Makeusg, if Usage_Needed is True.
578 -- Set Usage_Needed to False.
580 procedure Debug_Msg (S : String; N : Name_Id);
581 procedure Debug_Msg (S : String; N : File_Name_Type);
582 procedure Debug_Msg (S : String; N : Unit_Name_Type);
583 -- If Debug.Debug_Flag_W is set outputs string S followed by name N
585 procedure Recursive_Compute_Depth (Project : Project_Id);
586 -- Compute depth of Project and of the projects it depends on
588 -----------------------
589 -- Gnatmake Routines --
590 -----------------------
592 subtype Lib_Mark_Type is Byte;
593 -- Used in Mark_Directory
595 Ada_Lib_Dir : constant Lib_Mark_Type := 1;
596 -- Used to mark a directory as a GNAT lib dir
598 -- Note that the notion of GNAT lib dir is no longer used. The code related
599 -- to it has not been removed to give an idea on how to use the directory
600 -- prefix marking mechanism.
602 -- An Ada library directory is a directory containing ali and object files
603 -- but no source files for the bodies (the specs can be in the same or some
604 -- other directory). These directories are specified in the Gnatmake
605 -- command line with the switch "-Adir" (to specify the spec location -Idir
606 -- cab be used). Gnatmake skips the missing sources whose ali are in Ada
607 -- library directories. For an explanation of why Gnatmake behaves that
608 -- way, see the spec of Make.Compile_Sources. The directory lookup penalty
609 -- is incurred every single time this routine is called.
611 procedure Check_Steps;
612 -- Check what steps (Compile, Bind, Link) must be executed.
613 -- Set the step flags accordingly.
615 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean;
616 -- Get directory prefix of this file and get lib mark stored in name
617 -- table for this directory. Then check if an Ada lib mark has been set.
619 procedure Mark_Directory
621 Mark : Lib_Mark_Type;
622 On_Command_Line : Boolean);
623 -- Store the absolute path from Dir in name table and set lib mark as name
624 -- info to identify Ada libraries.
626 -- If Dir is a relative path, when On_Command_Line is True, it is relative
627 -- to the current working directory; when On_Command_Line is False, it is
628 -- relative to the project directory of the main project.
630 Output_Is_Object : Boolean := True;
631 -- Set to False when using a switch -S for the compiler
633 procedure Check_For_S_Switch;
634 -- Set Output_Is_Object to False when the -S switch is used for the
638 (Source_File : File_Name_Type;
639 Source_File_Name : String;
641 Project : Project_Id;
642 In_Package : Package_Id;
643 Allow_ALI : Boolean) return Variable_Value;
644 -- Return the switches for the source file in the specified package of a
645 -- project file. If the Source_File ends with a standard GNAT extension
646 -- (".ads" or ".adb"), try first the full name, then the name without the
647 -- extension, then, if Allow_ALI is True, the name with the extension
648 -- ".ali". If there is no switches for either names, try first Switches
649 -- (others) then the default switches for Ada. If all failed, return
650 -- No_Variable_Value.
652 function Is_In_Object_Directory
653 (Source_File : File_Name_Type;
654 Full_Lib_File : File_Name_Type) return Boolean;
655 -- Check if, when using a project file, the ALI file is in the project
656 -- directory of the ultimate extending project. If it is not, we ignore
657 -- the fact that this ALI file is read-only.
659 procedure Process_Multilib (Project_Node_Tree : Project_Node_Tree_Ref);
660 -- Add appropriate --RTS argument to handle multilib
662 ----------------------------------------------------
663 -- Compiler, Binder & Linker Data and Subprograms --
664 ----------------------------------------------------
666 Gcc : String_Access := Program_Name ("gcc", "gnatmake");
667 Gnatbind : String_Access := Program_Name ("gnatbind", "gnatmake");
668 Gnatlink : String_Access := Program_Name ("gnatlink", "gnatmake");
669 -- Default compiler, binder, linker programs
671 Saved_Gcc : String_Access := null;
672 Saved_Gnatbind : String_Access := null;
673 Saved_Gnatlink : String_Access := null;
674 -- Given by the command line. Will be used, if non null
676 Gcc_Path : String_Access :=
677 GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
678 Gnatbind_Path : String_Access :=
679 GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
680 Gnatlink_Path : String_Access :=
681 GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
682 -- Path for compiler, binder, linker programs, defaulted now for gnatdist.
683 -- Changed later if overridden on command line.
685 Comp_Flag : constant String_Access := new String'("-c");
686 Output_Flag : constant String_Access := new String'("-o");
687 Ada_Flag_1 : constant String_Access := new String'("-x");
688 Ada_Flag_2 : constant String_Access := new String'("ada");
689 No_gnat_adc : constant String_Access := new String'("-gnatA");
690 GNAT_Flag : constant String_Access := new String'("-gnatpg");
691 Do_Not_Check_Flag : constant String_Access := new String'("-x");
693 Object_Suffix : constant String := Get_Target_Object_Suffix.all;
695 Syntax_Only : Boolean := False;
696 -- Set to True when compiling with -gnats
698 Display_Executed_Programs : Boolean := True;
699 -- Set to True if name of commands should be output on stderr (or on stdout
700 -- if the Commands_To_Stdout flag was set by use of the -eS switch).
702 Output_File_Name_Seen : Boolean := False;
703 -- Set to True after having scanned the file_name for
704 -- switch "-o file_name"
706 Object_Directory_Seen : Boolean := False;
707 -- Set to True after having scanned the object directory for
708 -- switch "-D obj_dir".
710 Object_Directory_Path : String_Access := null;
711 -- The path name of the object directory, set with switch -D
713 type Make_Program_Type is (None, Compiler, Binder, Linker);
715 Program_Args : Make_Program_Type := None;
716 -- Used to indicate if we are scanning gnatmake, gcc, gnatbind, or gnatbind
717 -- options within the gnatmake command line. Used in Scan_Make_Arg only,
718 -- but must be global since value preserved from one call to another.
720 Temporary_Config_File : Boolean := False;
721 -- Set to True when there is a temporary config file used for a project
722 -- file, to avoid displaying the -gnatec switch for a temporary file.
724 procedure Add_Switches
725 (The_Package : Package_Id;
728 Program : Make_Program_Type;
729 Unknown_Switches_To_The_Compiler : Boolean := True;
730 Project_Node_Tree : Project_Node_Tree_Ref);
733 Program : Make_Program_Type;
734 Append_Switch : Boolean := True;
735 And_Save : Boolean := True);
738 Program : Make_Program_Type;
739 Append_Switch : Boolean := True;
740 And_Save : Boolean := True);
741 -- Make invokes one of three programs (the compiler, the binder or the
742 -- linker). For the sake of convenience, some program specific switches
743 -- can be passed directly on the gnatmake command line. This procedure
744 -- records these switches so that gnatmake can pass them to the right
745 -- program. S is the switch to be added at the end of the command line
746 -- for Program if Append_Switch is True. If Append_Switch is False S is
747 -- added at the beginning of the command line.
750 (Source_File : File_Name_Type;
752 Is_Main_Source : Boolean;
753 The_Args : Argument_List;
754 Lib_File : File_Name_Type;
755 Full_Lib_File : File_Name_Type;
756 Lib_File_Attr : access File_Attributes;
759 O_File : out File_Name_Type;
760 O_Stamp : out Time_Stamp_Type);
761 -- Determines whether the library file Lib_File is up-to-date or not. The
762 -- full name (with path information) of the object file corresponding to
763 -- Lib_File is returned in O_File. Its time stamp is saved in O_Stamp.
764 -- ALI is the ALI_Id corresponding to Lib_File. If Lib_File in not
765 -- up-to-date, then the corresponding source file needs to be recompiled.
766 -- In this case ALI = No_ALI_Id.
767 -- Full_Lib_File must be the result of calling Osint.Full_Lib_File_Name on
768 -- Lib_File. Precomputing it saves system calls. Lib_File_Attr is the
769 -- initialized attributes of that file, which is also used to save on
770 -- system calls (it can safely be initialized to Unknown_Attributes).
772 procedure Check_Linker_Options
773 (E_Stamp : Time_Stamp_Type;
774 O_File : out File_Name_Type;
775 O_Stamp : out Time_Stamp_Type);
776 -- Checks all linker options for linker files that are newer
777 -- than E_Stamp. If such objects are found, the youngest object
778 -- is returned in O_File and its stamp in O_Stamp.
780 -- If no obsolete linker files were found, the first missing
781 -- linker file is returned in O_File and O_Stamp is empty.
782 -- Otherwise O_File is No_File.
784 procedure Collect_Arguments
785 (Source_File : File_Name_Type;
787 Is_Main_Source : Boolean;
788 Args : Argument_List);
789 -- Collect all arguments for a source to be compiled, including those
790 -- that come from a project file.
792 procedure Display (Program : String; Args : Argument_List);
793 -- Displays Program followed by the arguments in Args if variable
794 -- Display_Executed_Programs is set. The lower bound of Args must be 1.
796 procedure Report_Compilation_Failed;
797 -- Delete all temporary files and fail graciously
803 type Temp_Path_Names is array (Positive range <>) of Path_Name_Type;
804 type Temp_Path_Ptr is access Temp_Path_Names;
806 type Free_File_Indices is array (Positive range <>) of Positive;
807 type Free_Indices_Ptr is access Free_File_Indices;
809 type Project_Compilation_Data is record
810 Mapping_File_Names : Temp_Path_Ptr;
811 -- The name ids of the temporary mapping files used. This is indexed
812 -- on the maximum number of compilation processes we will be spawning
815 Last_Mapping_File_Names : Natural;
816 -- Index of the last mapping file created for this project
818 Free_Mapping_File_Indices : Free_Indices_Ptr;
819 -- Indices in Mapping_File_Names of the mapping file names that can be
820 -- reused for subsequent compilations.
822 Last_Free_Indices : Natural;
823 -- Number of mapping files that can be reused
825 -- Information necessary when compiling a project
827 type Project_Compilation_Access is access Project_Compilation_Data;
829 package Project_Compilation_Htable is new Simple_HTable
830 (Header_Num => Prj.Header_Num,
831 Element => Project_Compilation_Access,
837 Project_Compilation : Project_Compilation_Htable.Instance;
839 Gnatmake_Mapping_File : String_Access := null;
840 -- The path name of a mapping file specified by switch -C=
842 procedure Init_Mapping_File
843 (Project : Project_Id;
844 Data : in out Project_Compilation_Data;
845 File_Index : in out Natural);
846 -- Create a new temporary mapping file, and fill it with the project file
847 -- mappings, when using project file(s). The out parameter File_Index is
848 -- the index to the name of the file in the array The_Mapping_File_Names.
850 procedure Delete_Temp_Config_Files;
851 -- Delete all temporary config files. Must not be called if Debug_Flag_N
854 procedure Delete_All_Temp_Files;
855 -- Delete all temp files (config files, mapping files, path files), unless
856 -- Debug_Flag_N is True (in which case all temp files are left for user
859 -------------------------------------------------
860 -- Subprogram declarations moved from the spec --
861 -------------------------------------------------
863 procedure Bind (ALI_File : File_Name_Type; Args : Argument_List);
864 -- Binds ALI_File. Args are the arguments to pass to the binder.
865 -- Args must have a lower bound of 1.
867 procedure Display_Commands (Display : Boolean := True);
868 -- The default behavior of Make commands (Compile_Sources, Bind, Link)
869 -- is to display them on stderr. This behavior can be changed repeatedly
870 -- by invoking this procedure.
872 -- If a compilation, bind or link failed one of the following 3 exceptions
873 -- is raised. These need to be handled by the calling routines.
875 procedure Compile_Sources
876 (Main_Source : File_Name_Type;
877 Args : Argument_List;
878 First_Compiled_File : out File_Name_Type;
879 Most_Recent_Obj_File : out File_Name_Type;
880 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
881 Main_Unit : out Boolean;
882 Compilation_Failures : out Natural;
883 Main_Index : Int := 0;
884 Check_Readonly_Files : Boolean := False;
885 Do_Not_Execute : Boolean := False;
886 Force_Compilations : Boolean := False;
887 Keep_Going : Boolean := False;
888 In_Place_Mode : Boolean := False;
889 Initialize_ALI_Data : Boolean := True;
890 Max_Process : Positive := 1);
891 -- Compile_Sources will recursively compile all the sources needed by
892 -- Main_Source. Before calling this routine make sure Namet has been
893 -- initialized. This routine can be called repeatedly with different
894 -- Main_Source file as long as all the source (-I flags), library
895 -- (-B flags) and ada library (-A flags) search paths between calls are
896 -- *exactly* the same. The default directory must also be the same.
898 -- Args contains the arguments to use during the compilations.
899 -- The lower bound of Args must be 1.
901 -- First_Compiled_File is set to the name of the first file that is
902 -- compiled or that needs to be compiled. This is set to No_Name if no
903 -- compilations were needed.
905 -- Most_Recent_Obj_File is set to the full name of the most recent
906 -- object file found when no compilations are needed, that is when
907 -- First_Compiled_File is set to No_Name. When First_Compiled_File
908 -- is set then Most_Recent_Obj_File is set to No_Name.
910 -- Most_Recent_Obj_Stamp is the time stamp of Most_Recent_Obj_File.
912 -- Main_Unit is set to True if Main_Source can be a main unit.
913 -- If Do_Not_Execute is False and First_Compiled_File /= No_Name
914 -- the value of Main_Unit is always False.
915 -- Is this used any more??? It is certainly not used by gnatmake???
917 -- Compilation_Failures is a count of compilation failures. This count
918 -- is used to extract compilation failure reports with Extract_Failure.
920 -- Main_Index, when not zero, is the index of the main unit in source
921 -- file Main_Source which is a multi-unit source.
922 -- Zero indicates that Main_Source is a single unit source file.
924 -- Check_Readonly_Files set it to True to compile source files
925 -- which library files are read-only. When compiling GNAT predefined
926 -- files the "-gnatg" flag is used.
928 -- Do_Not_Execute set it to True to find out the first source that
929 -- needs to be recompiled, but without recompiling it. This file is
930 -- saved in First_Compiled_File.
932 -- Force_Compilations forces all compilations no matter what but
933 -- recompiles read-only files only if Check_Readonly_Files
936 -- Keep_Going when True keep compiling even in the presence of
937 -- compilation errors.
939 -- In_Place_Mode when True save library/object files in their object
940 -- directory if they already exist; otherwise, in the source directory.
942 -- Initialize_ALI_Data set it to True when you want to initialize ALI
943 -- data-structures. This is what you should do most of the time.
944 -- (especially the first time around when you call this routine).
945 -- This parameter is set to False to preserve previously recorded
948 -- Max_Process is the maximum number of processes that should be spawned
949 -- to carry out compilations.
951 -- Flags in Package Opt Affecting Compile_Sources
952 -- -----------------------------------------------
954 -- Check_Object_Consistency set it to False to omit all consistency
955 -- checks between an .ali file and its corresponding object file.
956 -- When this flag is set to true, every time an .ali is read,
957 -- package Osint checks that the corresponding object file
958 -- exists and is more recent than the .ali.
960 -- Use of Name Table Info
961 -- ----------------------
963 -- All file names manipulated by Compile_Sources are entered into the
964 -- Names table. The Byte field of a source file is used to mark it.
966 -- Calling Compile_Sources Several Times
967 -- -------------------------------------
969 -- Upon return from Compile_Sources all the ALI data structures are left
970 -- intact for further browsing. HOWEVER upon entry to this routine ALI
971 -- data structures are re-initialized if parameter Initialize_ALI_Data
972 -- above is set to true. Typically this is what you want the first time
973 -- you call Compile_Sources. You should not load an ali file, call this
974 -- routine with flag Initialize_ALI_Data set to True and then expect
975 -- that ALI information to be around after the call. Note that the first
976 -- time you call Compile_Sources you better set Initialize_ALI_Data to
977 -- True unless you have called Initialize_ALI yourself.
979 -- Compile_Sources ALGORITHM : Compile_Sources (Main_Source)
980 -- -------------------------
982 -- 1. Insert Main_Source in a Queue (Q) and mark it.
984 -- 2. Let unit.adb be the file at the head of the Q. If unit.adb is
985 -- missing but its corresponding ali file is in an Ada library directory
986 -- (see below) then, remove unit.adb from the Q and goto step 4.
987 -- Otherwise, look at the files under the D (dependency) section of
988 -- unit.ali. If unit.ali does not exist or some of the time stamps do
989 -- not match, (re)compile unit.adb.
991 -- An Ada library directory is a directory containing Ada specs, ali
992 -- and object files but no source files for the bodies. An Ada library
993 -- directory is communicated to gnatmake by means of some switch so that
994 -- gnatmake can skip the sources whole ali are in that directory.
995 -- There are two reasons for skipping the sources in this case. Firstly,
996 -- Ada libraries typically come without full sources but binding and
997 -- linking against those libraries is still possible. Secondly, it would
998 -- be very wasteful for gnatmake to systematically check the consistency
999 -- of every external Ada library used in a program. The binder is
1000 -- already in charge of catching any potential inconsistencies.
1002 -- 3. Look into the W section of unit.ali and insert into the Q all
1003 -- unmarked source files. Mark all files newly inserted in the Q.
1004 -- Specifically, assuming that the W section looks like
1006 -- W types%s types.adb types.ali
1007 -- W unchecked_deallocation%s
1008 -- W xref_tab%s xref_tab.adb xref_tab.ali
1010 -- Then xref_tab.adb and types.adb are inserted in the Q if they are not
1012 -- Note that there is no file listed under W unchecked_deallocation%s
1013 -- so no generic body should ever be explicitly compiled (unless the
1014 -- Main_Source at the start was a generic body).
1016 -- 4. Repeat steps 2 and 3 above until the Q is empty
1018 -- Note that the above algorithm works because the units withed in
1019 -- subunits are transitively included in the W section (with section) of
1020 -- the main unit. Likewise the withed units in a generic body needed
1021 -- during a compilation are also transitively included in the W section
1022 -- of the originally compiled file.
1024 procedure Initialize (Project_Node_Tree : out Project_Node_Tree_Ref);
1025 -- Performs default and package initialization. Therefore,
1026 -- Compile_Sources can be called by an external unit.
1029 (ALI_File : File_Name_Type;
1030 Args : Argument_List;
1031 Success : out Boolean);
1032 -- Links ALI_File. Args are the arguments to pass to the linker.
1033 -- Args must have a lower bound of 1. Success indicates if the link
1034 -- succeeded or not.
1036 procedure Scan_Make_Arg
1037 (Project_Node_Tree : Project_Node_Tree_Ref;
1039 And_Save : Boolean);
1040 -- Scan make arguments. Argv is a single argument to be processed.
1041 -- Project_Node_Tree will be used to initialize external references. It
1042 -- must have been initialized.
1048 procedure Add_Arguments (Args : Argument_List) is
1050 if Arguments = null then
1051 Arguments := new Argument_List (1 .. Args'Length + 10);
1054 while Last_Argument + Args'Length > Arguments'Last loop
1056 New_Arguments : constant Argument_List_Access :=
1057 new Argument_List (1 .. Arguments'Last * 2);
1059 New_Arguments (1 .. Last_Argument) :=
1060 Arguments (1 .. Last_Argument);
1061 Arguments := New_Arguments;
1066 Arguments (Last_Argument + 1 .. Last_Argument + Args'Length) := Args;
1067 Last_Argument := Last_Argument + Args'Length;
1070 -- --------------------
1071 -- -- Add_Dependency --
1072 -- --------------------
1074 -- procedure Add_Dependency (S : File_Name_Type; On : File_Name_Type) is
1076 -- Dependencies.Increment_Last;
1077 -- Dependencies.Table (Dependencies.Last) := (S, On);
1078 -- end Add_Dependency;
1080 ----------------------------
1081 -- Add_Library_Search_Dir --
1082 ----------------------------
1084 procedure Add_Library_Search_Dir
1086 On_Command_Line : Boolean)
1089 if On_Command_Line then
1090 Add_Lib_Search_Dir (Normalize_Pathname (Path));
1093 Get_Name_String (Main_Project.Directory.Display_Name);
1095 (Normalize_Pathname (Path, Name_Buffer (1 .. Name_Len)));
1097 end Add_Library_Search_Dir;
1099 --------------------
1100 -- Add_Object_Dir --
1101 --------------------
1103 procedure Add_Object_Dir (N : String) is
1105 Add_Lib_Search_Dir (N);
1107 if Verbose_Mode then
1108 Write_Str ("Adding object directory """);
1115 --------------------
1116 -- Add_Source_Dir --
1117 --------------------
1119 procedure Add_Source_Dir (N : String) is
1121 Add_Src_Search_Dir (N);
1123 if Verbose_Mode then
1124 Write_Str ("Adding source directory """);
1131 ---------------------------
1132 -- Add_Source_Search_Dir --
1133 ---------------------------
1135 procedure Add_Source_Search_Dir
1137 On_Command_Line : Boolean)
1140 if On_Command_Line then
1141 Add_Src_Search_Dir (Normalize_Pathname (Path));
1144 Get_Name_String (Main_Project.Directory.Display_Name);
1146 (Normalize_Pathname (Path, Name_Buffer (1 .. Name_Len)));
1148 end Add_Source_Search_Dir;
1154 procedure Add_Switch
1156 Program : Make_Program_Type;
1157 Append_Switch : Boolean := True;
1158 And_Save : Boolean := True)
1161 with package T is new Table.Table (<>);
1162 procedure Generic_Position (New_Position : out Integer);
1163 -- Generic procedure that chooses a position for S in T at the
1164 -- beginning or the end, depending on the boolean Append_Switch.
1165 -- Calling this procedure may expand the table.
1167 ----------------------
1168 -- Generic_Position --
1169 ----------------------
1171 procedure Generic_Position (New_Position : out Integer) is
1175 if Append_Switch then
1176 New_Position := Integer (T.Last);
1178 for J in reverse T.Table_Index_Type'Succ (T.First) .. T.Last loop
1179 T.Table (J) := T.Table (T.Table_Index_Type'Pred (J));
1182 New_Position := Integer (T.First);
1184 end Generic_Position;
1186 procedure Gcc_Switches_Pos is new Generic_Position (Gcc_Switches);
1187 procedure Binder_Switches_Pos is new Generic_Position (Binder_Switches);
1188 procedure Linker_Switches_Pos is new Generic_Position (Linker_Switches);
1190 procedure Saved_Gcc_Switches_Pos is new
1191 Generic_Position (Saved_Gcc_Switches);
1193 procedure Saved_Binder_Switches_Pos is new
1194 Generic_Position (Saved_Binder_Switches);
1196 procedure Saved_Linker_Switches_Pos is new
1197 Generic_Position (Saved_Linker_Switches);
1199 New_Position : Integer;
1201 -- Start of processing for Add_Switch
1207 Saved_Gcc_Switches_Pos (New_Position);
1208 Saved_Gcc_Switches.Table (New_Position) := S;
1211 Saved_Binder_Switches_Pos (New_Position);
1212 Saved_Binder_Switches.Table (New_Position) := S;
1215 Saved_Linker_Switches_Pos (New_Position);
1216 Saved_Linker_Switches.Table (New_Position) := S;
1219 raise Program_Error;
1225 Gcc_Switches_Pos (New_Position);
1226 Gcc_Switches.Table (New_Position) := S;
1229 Binder_Switches_Pos (New_Position);
1230 Binder_Switches.Table (New_Position) := S;
1233 Linker_Switches_Pos (New_Position);
1234 Linker_Switches.Table (New_Position) := S;
1237 raise Program_Error;
1242 procedure Add_Switch
1244 Program : Make_Program_Type;
1245 Append_Switch : Boolean := True;
1246 And_Save : Boolean := True)
1249 Add_Switch (S => new String'(S),
1251 Append_Switch => Append_Switch,
1252 And_Save => And_Save);
1259 procedure Add_Switches
1260 (The_Package : Package_Id;
1263 Program : Make_Program_Type;
1264 Unknown_Switches_To_The_Compiler : Boolean := True;
1265 Project_Node_Tree : Project_Node_Tree_Ref)
1267 Switches : Variable_Value;
1268 Switch_List : String_List_Id;
1269 Element : String_Element;
1272 Switch_May_Be_Passed_To_The_Compiler :=
1273 Unknown_Switches_To_The_Compiler;
1275 if File_Name'Length > 0 then
1277 Add_Str_To_Name_Buffer (File_Name);
1280 (Source_File => Name_Find,
1281 Source_File_Name => File_Name,
1282 Source_Index => Index,
1283 Project => Main_Project,
1284 In_Package => The_Package,
1285 Allow_ALI => Program = Binder or else Program = Linker);
1287 if Switches.Kind = List then
1288 Program_Args := Program;
1290 Switch_List := Switches.Values;
1291 while Switch_List /= Nil_String loop
1292 Element := Project_Tree.String_Elements.Table (Switch_List);
1293 Get_Name_String (Element.Value);
1295 if Name_Len > 0 then
1297 Argv : constant String := Name_Buffer (1 .. Name_Len);
1298 -- We need a copy, because Name_Buffer may be modified
1301 if Verbose_Mode then
1302 Write_Str (" Adding ");
1307 (Project_Node_Tree, Argv, And_Save => False);
1309 if not Gnatmake_Switch_Found
1310 and then not Switch_May_Be_Passed_To_The_Compiler
1314 """ is not a gnatmake switch. Consider moving " &
1315 "it to Global_Compilation_Switches.",
1318 Make_Failed ("*** illegal switch """ & Argv & """");
1323 Switch_List := Element.Next;
1333 procedure Bind (ALI_File : File_Name_Type; Args : Argument_List) is
1334 Bind_Args : Argument_List (1 .. Args'Last + 2);
1335 Bind_Last : Integer;
1339 pragma Assert (Args'First = 1);
1341 -- Optimize the simple case where the gnatbind command line looks like
1342 -- gnatbind -aO. -I- file.ali --into-> gnatbind file.adb
1345 and then Args (Args'First).all = "-aO" & Normalized_CWD
1346 and then Args (Args'Last).all = "-I-"
1347 and then ALI_File = Strip_Directory (ALI_File)
1349 Bind_Last := Args'First - 1;
1352 Bind_Last := Args'Last;
1353 Bind_Args (Args'Range) := Args;
1356 -- It is completely pointless to re-check source file time stamps. This
1357 -- has been done already by gnatmake
1359 Bind_Last := Bind_Last + 1;
1360 Bind_Args (Bind_Last) := Do_Not_Check_Flag;
1362 Get_Name_String (ALI_File);
1364 Bind_Last := Bind_Last + 1;
1365 Bind_Args (Bind_Last) := new String'(Name_Buffer (1 .. Name_Len));
1367 GNAT.OS_Lib.Normalize_Arguments (Bind_Args (Args'First .. Bind_Last));
1369 Display (Gnatbind.all, Bind_Args (Args'First .. Bind_Last));
1371 if Gnatbind_Path = null then
1372 Make_Failed ("error, unable to locate " & Gnatbind.all);
1376 (Gnatbind_Path.all, Bind_Args (Args'First .. Bind_Last), Success);
1379 Make_Failed ("*** bind failed.");
1383 --------------------------------
1384 -- Change_To_Object_Directory --
1385 --------------------------------
1387 procedure Change_To_Object_Directory (Project : Project_Id) is
1388 Object_Directory : Path_Name_Type;
1391 pragma Assert (Project /= No_Project);
1393 -- Nothing to do if the current working directory is already the correct
1394 -- object directory.
1396 if Project_Of_Current_Object_Directory /= Project then
1397 Project_Of_Current_Object_Directory := Project;
1398 Object_Directory := Project.Object_Directory.Name;
1400 -- Set the working directory to the object directory of the actual
1403 if Verbose_Mode then
1404 Write_Str ("Changing to object directory of """);
1405 Write_Name (Project.Display_Name);
1406 Write_Str (""": """);
1407 Write_Name (Object_Directory);
1411 Change_Dir (Get_Name_String (Object_Directory));
1415 -- Fail if unable to change to the object directory
1417 when Directory_Error =>
1418 Make_Failed ("unable to change to object directory """ &
1420 (Project.Object_Directory.Name) &
1422 Get_Name_String (Project.Display_Name));
1423 end Change_To_Object_Directory;
1430 (Source_File : File_Name_Type;
1432 Is_Main_Source : Boolean;
1433 The_Args : Argument_List;
1434 Lib_File : File_Name_Type;
1435 Full_Lib_File : File_Name_Type;
1436 Lib_File_Attr : access File_Attributes;
1437 Read_Only : Boolean;
1439 O_File : out File_Name_Type;
1440 O_Stamp : out Time_Stamp_Type)
1442 function First_New_Spec (A : ALI_Id) return File_Name_Type;
1443 -- Looks in the with table entries of A and returns the spec file name
1444 -- of the first withed unit (subprogram) for which no spec existed when
1445 -- A was generated but for which there exists one now, implying that A
1446 -- is now obsolete. If no such unit is found No_File is returned.
1447 -- Otherwise the spec file name of the unit is returned.
1449 -- **WARNING** in the event of Uname format modifications, one *MUST*
1450 -- make sure this function is also updated.
1452 -- Note: This function should really be in ali.adb and use Uname
1453 -- services, but this causes the whole compiler to be dragged along
1454 -- for gnatbind and gnatmake.
1456 --------------------
1457 -- First_New_Spec --
1458 --------------------
1460 function First_New_Spec (A : ALI_Id) return File_Name_Type is
1461 Spec_File_Name : File_Name_Type := No_File;
1463 function New_Spec (Uname : Unit_Name_Type) return Boolean;
1464 -- Uname is the name of the spec or body of some ada unit. This
1465 -- function returns True if the Uname is the name of a body which has
1466 -- a spec not mentioned in ALI file A. If True is returned
1467 -- Spec_File_Name above is set to the name of this spec file.
1473 function New_Spec (Uname : Unit_Name_Type) return Boolean is
1474 Spec_Name : Unit_Name_Type;
1475 File_Name : File_Name_Type;
1478 -- Test whether Uname is the name of a body unit (i.e. ends
1481 Get_Name_String (Uname);
1483 Assert (Name_Len > 2 and then Name_Buffer (Name_Len - 1) = '%');
1485 if Name_Buffer (Name_Len) /= 'b' then
1489 -- Convert unit name into spec name
1491 -- ??? this code seems dubious in presence of pragma
1492 -- Source_File_Name since there is no more direct relationship
1493 -- between unit name and file name.
1495 -- ??? Further, what about alternative subunit naming
1497 Name_Buffer (Name_Len) := 's';
1498 Spec_Name := Name_Find;
1499 File_Name := Get_File_Name (Spec_Name, Subunit => False);
1501 -- Look if File_Name is mentioned in A's sdep list.
1502 -- If not look if the file exists. If it does return True.
1505 ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep
1507 if Sdep.Table (D).Sfile = File_Name then
1512 if Full_Source_Name (File_Name) /= No_File then
1513 Spec_File_Name := File_Name;
1520 -- Start of processing for First_New_Spec
1524 ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit
1526 exit U_Chk when Units.Table (U).Utype = Is_Body_Only
1527 and then New_Spec (Units.Table (U).Uname);
1529 for W in Units.Table (U).First_With
1531 Units.Table (U).Last_With
1534 Withs.Table (W).Afile /= No_File
1535 and then New_Spec (Withs.Table (W).Uname);
1539 return Spec_File_Name;
1542 ---------------------------------
1543 -- Data declarations for Check --
1544 ---------------------------------
1546 Full_Obj_File : File_Name_Type;
1547 -- Full name of the object file corresponding to Lib_File
1549 Lib_Stamp : Time_Stamp_Type;
1550 -- Time stamp of the current ada library file
1552 Obj_Stamp : Time_Stamp_Type;
1553 -- Time stamp of the current object file
1555 Modified_Source : File_Name_Type;
1556 -- The first source in Lib_File whose current time stamp differs
1557 -- from that stored in Lib_File.
1559 New_Spec : File_Name_Type;
1560 -- If Lib_File contains in its W (with) section a body (for a
1561 -- subprogram) for which there exists a spec and the spec did not
1562 -- appear in the Sdep section of Lib_File, New_Spec contains the file
1563 -- name of this new spec.
1565 Source_Name : File_Name_Type;
1566 Text : Text_Buffer_Ptr;
1568 Prev_Switch : String_Access;
1569 -- Previous switch processed
1571 Arg : Arg_Id := Arg_Id'First;
1572 -- Current index in Args.Table for a given unit (init to stop warning)
1574 Switch_Found : Boolean;
1575 -- True if a given switch has been found
1577 ALI_Project : Project_Id;
1578 -- If the ALI file is in the object directory of a project, this is
1581 -- Start of processing for Check
1584 pragma Assert (Lib_File /= No_File);
1586 -- If ALI file is read-only, temporarily set Check_Object_Consistency to
1587 -- False. We don't care if the object file is not there (presumably a
1588 -- library will be used for linking.)
1592 Saved_Check_Object_Consistency : constant Boolean :=
1593 Check_Object_Consistency;
1595 Check_Object_Consistency := False;
1596 Text := Read_Library_Info_From_Full (Full_Lib_File, Lib_File_Attr);
1597 Check_Object_Consistency := Saved_Check_Object_Consistency;
1601 Text := Read_Library_Info_From_Full (Full_Lib_File, Lib_File_Attr);
1604 Full_Obj_File := Full_Object_File_Name;
1605 Lib_Stamp := Current_Library_File_Stamp;
1606 Obj_Stamp := Current_Object_File_Stamp;
1608 if Full_Lib_File = No_File then
1611 "being checked ...",
1613 Minimum_Verbosity => Opt.Medium);
1617 "being checked ...",
1619 Minimum_Verbosity => Opt.Medium);
1623 O_File := Full_Obj_File;
1624 O_Stamp := Obj_Stamp;
1627 if Full_Lib_File = No_File then
1628 Verbose_Msg (Lib_File, "missing.");
1630 elsif Obj_Stamp (Obj_Stamp'First) = ' ' then
1631 Verbose_Msg (Full_Obj_File, "missing.");
1635 (Full_Lib_File, "(" & String (Lib_Stamp) & ") newer than",
1636 Full_Obj_File, "(" & String (Obj_Stamp) & ")");
1640 ALI := Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
1643 if ALI = No_ALI_Id then
1644 Verbose_Msg (Full_Lib_File, "incorrectly formatted ALI file");
1647 elsif ALIs.Table (ALI).Ver (1 .. ALIs.Table (ALI).Ver_Len) /=
1648 Verbose_Library_Version
1650 Verbose_Msg (Full_Lib_File, "compiled with old GNAT version");
1655 -- Don't take Ali file into account if it was generated with
1658 if ALIs.Table (ALI).Compile_Errors then
1659 Verbose_Msg (Full_Lib_File, "had errors, must be recompiled");
1664 -- Don't take Ali file into account if it was generated without
1667 if Operating_Mode /= Check_Semantics
1668 and then ALIs.Table (ALI).No_Object
1670 Verbose_Msg (Full_Lib_File, "has no corresponding object");
1675 -- Check for matching compiler switches if needed
1677 if Check_Switches then
1679 -- First, collect all the switches
1682 (Source_File, Source_Index, Is_Main_Source, The_Args);
1684 Prev_Switch := Dummy_Switch;
1686 Get_Name_String (ALIs.Table (ALI).Sfile);
1688 Switches_To_Check.Set_Last (0);
1690 for J in 1 .. Last_Argument loop
1692 -- Skip non switches -c, -I and -o switches
1694 if Arguments (J) (1) = '-'
1695 and then Arguments (J) (2) /= 'c'
1696 and then Arguments (J) (2) /= 'o'
1697 and then Arguments (J) (2) /= 'I'
1699 Normalize_Compiler_Switches
1701 Normalized_Switches,
1704 for K in 1 .. Last_Norm_Switch loop
1705 Switches_To_Check.Increment_Last;
1706 Switches_To_Check.Table (Switches_To_Check.Last) :=
1707 Normalized_Switches (K);
1712 for J in 1 .. Switches_To_Check.Last loop
1714 -- Comparing switches is delicate because gcc reorders a number
1715 -- of switches, according to lang-specs.h, but gnatmake doesn't
1716 -- have sufficient knowledge to perform the same reordering.
1717 -- Instead, we ignore orders between different "first letter"
1718 -- switches, but keep orders between same switches, e.g -O -O2
1719 -- is different than -O2 -O, but -g -O is equivalent to -O -g.
1721 if Switches_To_Check.Table (J) (2) /= Prev_Switch (2) or else
1722 (Prev_Switch'Length >= 6 and then
1723 Prev_Switch (2 .. 5) = "gnat" and then
1724 Switches_To_Check.Table (J)'Length >= 6 and then
1725 Switches_To_Check.Table (J) (2 .. 5) = "gnat" and then
1726 Prev_Switch (6) /= Switches_To_Check.Table (J) (6))
1728 Prev_Switch := Switches_To_Check.Table (J);
1730 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg;
1733 Switch_Found := False;
1736 Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1739 Switches_To_Check.Table (J).all = Args.Table (K).all
1742 Switch_Found := True;
1747 if not Switch_Found then
1748 if Verbose_Mode then
1749 Verbose_Msg (ALIs.Table (ALI).Sfile,
1750 "switch mismatch """ &
1751 Switches_To_Check.Table (J).all & '"');
1759 if Switches_To_Check.Last /=
1760 Integer (Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg -
1761 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg + 1)
1763 if Verbose_Mode then
1764 Verbose_Msg (ALIs.Table (ALI).Sfile,
1765 "different number of switches");
1767 for K in Units.Table (ALIs.Table (ALI).First_Unit).First_Arg
1768 .. Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1770 Write_Str (Args.Table (K).all);
1776 for J in 1 .. Switches_To_Check.Last loop
1777 Write_Str (Switches_To_Check.Table (J).all);
1789 -- Get the source files and their message digests. Note that some
1790 -- sources may be missing if ALI is out-of-date.
1792 Set_Source_Table (ALI);
1794 Modified_Source := Time_Stamp_Mismatch (ALI, Read_Only);
1796 -- To avoid using too much memory when switch -m is used, free the
1797 -- memory allocated for the source file when computing the checksum.
1799 if Minimal_Recompilation then
1800 Sinput.P.Clear_Source_File_Table;
1803 if Modified_Source /= No_File then
1806 if Verbose_Mode then
1807 Source_Name := Full_Source_Name (Modified_Source);
1809 if Source_Name /= No_File then
1810 Verbose_Msg (Source_Name, "time stamp mismatch");
1812 Verbose_Msg (Modified_Source, "missing");
1817 New_Spec := First_New_Spec (ALI);
1819 if New_Spec /= No_File then
1822 if Verbose_Mode then
1823 Source_Name := Full_Source_Name (New_Spec);
1825 if Source_Name /= No_File then
1826 Verbose_Msg (Source_Name, "new spec");
1828 Verbose_Msg (New_Spec, "old spec missing");
1832 elsif not Read_Only and then Main_Project /= No_Project then
1834 if not Check_Source_Info_In_ALI (ALI) then
1839 -- Check that the ALI file is in the correct object directory.
1840 -- If it is in the object directory of a project that is
1841 -- extended and it depends on a source that is in one of its
1842 -- extending projects, then the ALI file is not in the correct
1843 -- object directory.
1845 -- First, find the project of this ALI file. As there may be
1846 -- several projects with the same object directory, we first
1847 -- need to find the project of the source.
1849 ALI_Project := No_Project;
1852 Udata : Prj.Unit_Index;
1855 Udata := Units_Htable.Get_First (Project_Tree.Units_HT);
1856 while Udata /= No_Unit_Index loop
1857 if Udata.File_Names (Impl) /= null
1858 and then Udata.File_Names (Impl).File = Source_File
1860 ALI_Project := Udata.File_Names (Impl).Project;
1863 elsif Udata.File_Names (Spec) /= null
1864 and then Udata.File_Names (Spec).File = Source_File
1866 ALI_Project := Udata.File_Names (Spec).Project;
1870 Udata := Units_Htable.Get_Next (Project_Tree.Units_HT);
1874 if ALI_Project = No_Project then
1879 Obj_Dir : Path_Name_Type;
1880 Res_Obj_Dir : constant String :=
1883 (Get_Name_String (Full_Lib_File)),
1885 Opt.Follow_Links_For_Dirs,
1886 Case_Sensitive => False);
1890 Add_Str_To_Name_Buffer (Res_Obj_Dir);
1892 if not Is_Directory_Separator (Name_Buffer (Name_Len)) then
1893 Add_Char_To_Name_Buffer (Directory_Separator);
1896 Obj_Dir := Name_Find;
1898 while ALI_Project /= No_Project
1899 and then Obj_Dir /= ALI_Project.Object_Directory.Name
1901 ALI_Project := ALI_Project.Extended_By;
1905 if ALI_Project = No_Project then
1909 (Lib_File, " wrong object directory");
1913 -- If the ALI project is not extended, then it must be in
1914 -- the correct object directory.
1916 if ALI_Project.Extended_By = No_Project then
1920 -- Count the extending projects
1928 Proj := ALI_Project;
1930 Proj := Proj.Extended_By;
1931 exit when Proj = No_Project;
1932 Num_Ext := Num_Ext + 1;
1935 -- Make a list of the extending projects
1938 Projects : array (1 .. Num_Ext) of Project_Id;
1940 OK : Boolean := True;
1944 Proj := ALI_Project;
1945 for J in Projects'Range loop
1946 Proj := Proj.Extended_By;
1947 Projects (J) := Proj;
1950 -- Now check if any of the dependant sources are in
1951 -- any of these extending projects.
1954 for D in ALIs.Table (ALI).First_Sdep ..
1955 ALIs.Table (ALI).Last_Sdep
1957 Dep := Sdep.Table (D);
1958 UID := Units_Htable.Get_First (Project_Tree.Units_HT);
1962 while UID /= null loop
1963 if UID.File_Names (Impl) /= null
1964 and then UID.File_Names (Impl).File = Dep.Sfile
1966 Proj := UID.File_Names (Impl).Project;
1968 elsif UID.File_Names (Spec) /= null
1969 and then UID.File_Names (Spec).File = Dep.Sfile
1971 Proj := UID.File_Names (Spec).Project;
1974 -- If a source is in a project, check if it is one
1977 if Proj /= No_Project then
1978 for J in Projects'Range loop
1979 if Proj = Projects (J) then
1989 Units_Htable.Get_Next (Project_Tree.Units_HT);
1993 -- If one of the dependent sources is in one project of
1994 -- the list, then we must recompile.
1998 Verbose_Msg (Lib_File, " wrong object directory");
2007 ------------------------
2008 -- Check_For_S_Switch --
2009 ------------------------
2011 procedure Check_For_S_Switch is
2013 -- By default, we generate an object file
2015 Output_Is_Object := True;
2017 for Arg in 1 .. Last_Argument loop
2018 if Arguments (Arg).all = "-S" then
2019 Output_Is_Object := False;
2021 elsif Arguments (Arg).all = "-c" then
2022 Output_Is_Object := True;
2025 end Check_For_S_Switch;
2027 --------------------------
2028 -- Check_Linker_Options --
2029 --------------------------
2031 procedure Check_Linker_Options
2032 (E_Stamp : Time_Stamp_Type;
2033 O_File : out File_Name_Type;
2034 O_Stamp : out Time_Stamp_Type)
2036 procedure Check_File (File : File_Name_Type);
2037 -- Update O_File and O_Stamp if the given file is younger than E_Stamp
2038 -- and O_Stamp, or if O_File is No_File and File does not exist.
2040 function Get_Library_File (Name : String) return File_Name_Type;
2041 -- Return the full file name including path of a library based
2042 -- on the name specified with the -l linker option, using the
2043 -- Ada object path. Return No_File if no such file can be found.
2045 type Char_Array is array (Natural) of Character;
2046 type Char_Array_Access is access constant Char_Array;
2048 Template : Char_Array_Access;
2049 pragma Import (C, Template, "__gnat_library_template");
2055 procedure Check_File (File : File_Name_Type) is
2056 Stamp : Time_Stamp_Type;
2057 Name : File_Name_Type := File;
2060 Get_Name_String (Name);
2062 -- Remove any trailing NUL characters
2064 while Name_Len >= Name_Buffer'First
2065 and then Name_Buffer (Name_Len) = NUL
2067 Name_Len := Name_Len - 1;
2070 if Name_Len = 0 then
2073 elsif Name_Buffer (1) = '-' then
2075 -- Do not check if File is a switch other than "-l"
2077 if Name_Buffer (2) /= 'l' then
2081 -- The argument is a library switch, get actual name. It
2082 -- is necessary to make a copy of the relevant part of
2083 -- Name_Buffer as Get_Library_Name uses Name_Buffer as well.
2086 Base_Name : constant String := Name_Buffer (3 .. Name_Len);
2089 Name := Get_Library_File (Base_Name);
2092 if Name = No_File then
2097 Stamp := File_Stamp (Name);
2099 -- Find the youngest object file that is younger than the
2100 -- executable. If no such file exist, record the first object
2101 -- file that is not found.
2103 if (O_Stamp < Stamp and then E_Stamp < Stamp)
2104 or else (O_File = No_File and then Stamp (Stamp'First) = ' ')
2109 -- Strip the trailing NUL if present
2111 Get_Name_String (O_File);
2113 if Name_Buffer (Name_Len) = NUL then
2114 Name_Len := Name_Len - 1;
2115 O_File := Name_Find;
2120 ----------------------
2121 -- Get_Library_Name --
2122 ----------------------
2124 -- See comments in a-adaint.c about template syntax
2126 function Get_Library_File (Name : String) return File_Name_Type is
2127 File : File_Name_Type := No_File;
2132 for Ptr in Template'Range loop
2133 case Template (Ptr) is
2135 Add_Str_To_Name_Buffer (Name);
2138 File := Full_Lib_File_Name (Name_Find);
2139 exit when File /= No_File;
2146 Add_Char_To_Name_Buffer (Template (Ptr));
2150 -- The for loop exited because the end of the template
2151 -- was reached. File contains the last possible file name
2154 if File = No_File and then Name_Len > 0 then
2155 File := Full_Lib_File_Name (Name_Find);
2159 end Get_Library_File;
2161 -- Start of processing for Check_Linker_Options
2165 O_Stamp := (others => ' ');
2167 -- Process linker options from the ALI files
2169 for Opt in 1 .. Linker_Options.Last loop
2170 Check_File (File_Name_Type (Linker_Options.Table (Opt).Name));
2173 -- Process options given on the command line
2175 for Opt in Linker_Switches.First .. Linker_Switches.Last loop
2177 -- Check if the previous Opt has one of the two switches
2178 -- that take an extra parameter. (See GCC manual.)
2180 if Opt = Linker_Switches.First
2181 or else (Linker_Switches.Table (Opt - 1).all /= "-u"
2183 Linker_Switches.Table (Opt - 1).all /= "-Xlinker"
2185 Linker_Switches.Table (Opt - 1).all /= "-L")
2188 Add_Str_To_Name_Buffer (Linker_Switches.Table (Opt).all);
2189 Check_File (Name_Find);
2193 end Check_Linker_Options;
2199 procedure Check_Steps is
2201 -- If either -c, -b or -l has been specified, we will not necessarily
2202 -- execute all steps.
2205 Do_Compile_Step := Do_Compile_Step and Compile_Only;
2206 Do_Bind_Step := Do_Bind_Step and Bind_Only;
2207 Do_Link_Step := Do_Link_Step and Link_Only;
2209 -- If -c has been specified, but not -b, ignore any potential -l
2211 if Do_Compile_Step and then not Do_Bind_Step then
2212 Do_Link_Step := False;
2217 -----------------------
2218 -- Collect_Arguments --
2219 -----------------------
2221 procedure Collect_Arguments
2222 (Source_File : File_Name_Type;
2224 Is_Main_Source : Boolean;
2225 Args : Argument_List)
2228 Arguments_Project := No_Project;
2230 Add_Arguments (Args);
2232 if Main_Project /= No_Project then
2234 Source_File_Name : constant String :=
2235 Get_Name_String (Source_File);
2236 Compiler_Package : Prj.Package_Id;
2237 Switches : Prj.Variable_Value;
2242 (Source_File_Name => Source_File_Name,
2243 Project => Arguments_Project,
2244 Path => Arguments_Path_Name,
2245 In_Tree => Project_Tree);
2247 -- If the source is not a source of a project file, add the
2248 -- recorded arguments. Check will be done later if the source
2249 -- need to be compiled that the switch -x has been used.
2251 if Arguments_Project = No_Project then
2252 Add_Arguments (The_Saved_Gcc_Switches.all);
2254 elsif not Arguments_Project.Externally_Built
2255 or else Must_Compile
2257 -- We get the project directory for the relative path
2258 -- switches and arguments.
2260 Arguments_Project :=
2261 Ultimate_Extending_Project_Of (Arguments_Project);
2263 -- If building a dynamic or relocatable library, compile with
2264 -- PIC option, if it exists.
2266 if Arguments_Project.Library
2267 and then Arguments_Project.Library_Kind /= Static
2270 PIC : constant String := MLib.Tgt.PIC_Option;
2273 Add_Arguments ((1 => new String'(PIC)));
2278 -- We now look for package Compiler and get the switches from
2283 (Name => Name_Compiler,
2284 In_Packages => Arguments_Project.Decl.Packages,
2285 In_Tree => Project_Tree);
2287 if Compiler_Package /= No_Package then
2289 -- If package Gnatmake.Compiler exists, we get the specific
2290 -- switches for the current source, or the global switches,
2295 (Source_File => Source_File,
2296 Source_File_Name => Source_File_Name,
2297 Source_Index => Source_Index,
2298 Project => Arguments_Project,
2299 In_Package => Compiler_Package,
2300 Allow_ALI => False);
2304 case Switches.Kind is
2306 -- We have a list of switches. We add these switches,
2307 -- plus the saved gcc switches.
2312 Current : String_List_Id := Switches.Values;
2313 Element : String_Element;
2314 Number : Natural := 0;
2317 while Current /= Nil_String loop
2318 Element := Project_Tree.String_Elements.
2320 Number := Number + 1;
2321 Current := Element.Next;
2325 New_Args : Argument_List (1 .. Number);
2326 Last_New : Natural := 0;
2327 Dir_Path : constant String := Get_Name_String
2328 (Arguments_Project.Directory.Name);
2331 Current := Switches.Values;
2333 for Index in New_Args'Range loop
2334 Element := Project_Tree.String_Elements.
2336 Get_Name_String (Element.Value);
2338 if Name_Len > 0 then
2339 Last_New := Last_New + 1;
2340 New_Args (Last_New) :=
2341 new String'(Name_Buffer (1 .. Name_Len));
2342 Test_If_Relative_Path
2343 (New_Args (Last_New),
2345 Including_Non_Switch => False);
2348 Current := Element.Next;
2352 (Configuration_Pragmas_Switch
2353 (Arguments_Project) &
2354 New_Args (1 .. Last_New) &
2355 The_Saved_Gcc_Switches.all);
2359 -- We have a single switch. We add this switch,
2360 -- plus the saved gcc switches.
2363 Get_Name_String (Switches.Value);
2366 New_Args : Argument_List :=
2368 (Name_Buffer (1 .. Name_Len)));
2369 Dir_Path : constant String :=
2371 (Arguments_Project.Directory.Name);
2374 Test_If_Relative_Path
2377 Including_Non_Switch => False);
2379 (Configuration_Pragmas_Switch (Arguments_Project) &
2380 New_Args & The_Saved_Gcc_Switches.all);
2383 -- We have no switches from Gnatmake.Compiler.
2384 -- We add the saved gcc switches.
2388 (Configuration_Pragmas_Switch (Arguments_Project) &
2389 The_Saved_Gcc_Switches.all);
2395 -- For VMS, when compiling the main source, add switch
2396 -- -mdebug-main=_ada_ so that the executable can be debugged
2397 -- by the standard VMS debugger.
2399 if not No_Main_Subprogram
2400 and then Targparm.OpenVMS_On_Target
2401 and then Is_Main_Source
2403 -- First, check if compilation will be invoked with -g
2405 for J in 1 .. Last_Argument loop
2406 if Arguments (J)'Length >= 2
2407 and then Arguments (J) (1 .. 2) = "-g"
2408 and then (Arguments (J)'Length < 5
2409 or else Arguments (J) (1 .. 5) /= "-gnat")
2412 ((1 => new String'("-mdebug-main=_ada_")));
2418 -- Set Output_Is_Object, depending if there is a -S switch.
2419 -- If the bind step is not performed, and there is a -S switch,
2420 -- then we will not check for a valid object file.
2423 end Collect_Arguments;
2425 ---------------------
2426 -- Compile_Sources --
2427 ---------------------
2429 procedure Compile_Sources
2430 (Main_Source : File_Name_Type;
2431 Args : Argument_List;
2432 First_Compiled_File : out File_Name_Type;
2433 Most_Recent_Obj_File : out File_Name_Type;
2434 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
2435 Main_Unit : out Boolean;
2436 Compilation_Failures : out Natural;
2437 Main_Index : Int := 0;
2438 Check_Readonly_Files : Boolean := False;
2439 Do_Not_Execute : Boolean := False;
2440 Force_Compilations : Boolean := False;
2441 Keep_Going : Boolean := False;
2442 In_Place_Mode : Boolean := False;
2443 Initialize_ALI_Data : Boolean := True;
2444 Max_Process : Positive := 1)
2446 Mfile : Natural := No_Mapping_File;
2447 Mapping_File_Arg : String_Access;
2448 -- Info on the mapping file
2450 Need_To_Check_Standard_Library : Boolean :=
2451 Check_Readonly_Files
2452 and not Unique_Compile;
2454 procedure Add_Process
2456 Sfile : File_Name_Type;
2457 Afile : File_Name_Type;
2458 Uname : Unit_Name_Type;
2459 Full_Lib_File : File_Name_Type;
2460 Lib_File_Attr : File_Attributes;
2461 Mfile : Natural := No_Mapping_File);
2462 -- Adds process Pid to the current list of outstanding compilation
2463 -- processes and record the full name of the source file Sfile that
2464 -- we are compiling, the name of its library file Afile and the
2465 -- name of its unit Uname. If Mfile is not equal to No_Mapping_File,
2466 -- it is the index of the mapping file used during compilation in the
2467 -- array The_Mapping_File_Names.
2469 procedure Await_Compile
2470 (Data : out Compilation_Data;
2472 -- Awaits that an outstanding compilation process terminates. When it
2473 -- does set Data to the information registered for the corresponding
2474 -- call to Add_Process. Note that this time stamp can be used to check
2475 -- whether the compilation did generate an object file. OK is set to
2476 -- True if the compilation succeeded. Data could be No_Compilation_Data
2477 -- if there was no compilation to wait for.
2479 function Bad_Compilation_Count return Natural;
2480 -- Returns the number of compilation failures
2482 procedure Check_Standard_Library;
2483 -- Check if s-stalib.adb needs to be compiled
2485 procedure Collect_Arguments_And_Compile
2486 (Full_Source_File : File_Name_Type;
2487 Lib_File : File_Name_Type;
2489 Pid : out Process_Id;
2490 Process_Created : out Boolean);
2491 -- Collect arguments from project file (if any) and compile. If no
2492 -- compilation was attempted, Processed_Created is set to False, and the
2493 -- value of Pid is unknown.
2496 (Project : Project_Id;
2500 Args : Argument_List) return Process_Id;
2501 -- Compiles S using Args. If S is a GNAT predefined source "-gnatpg" is
2502 -- added to Args. Non blocking call. L corresponds to the expected
2503 -- library file name. Process_Id of the process spawned to execute the
2506 package Good_ALI is new Table.Table (
2507 Table_Component_Type => ALI_Id,
2508 Table_Index_Type => Natural,
2509 Table_Low_Bound => 1,
2510 Table_Initial => 50,
2511 Table_Increment => 100,
2512 Table_Name => "Make.Good_ALI");
2513 -- Contains the set of valid ALI files that have not yet been scanned
2515 function Good_ALI_Present return Boolean;
2516 -- Returns True if any ALI file was recorded in the previous set
2518 procedure Get_Mapping_File (Project : Project_Id);
2519 -- Get a mapping file name. If there is one to be reused, reuse it.
2520 -- Otherwise, create a new mapping file.
2522 function Get_Next_Good_ALI return ALI_Id;
2523 -- Returns the next good ALI_Id record
2525 procedure Record_Failure
2526 (File : File_Name_Type;
2527 Unit : Unit_Name_Type;
2528 Found : Boolean := True);
2529 -- Records in the previous table that the compilation for File failed.
2530 -- If Found is False then the compilation of File failed because we
2531 -- could not find it. Records also Unit when possible.
2533 procedure Record_Good_ALI (A : ALI_Id);
2534 -- Records in the previous set the Id of an ALI file
2536 function Must_Exit_Because_Of_Error return Boolean;
2537 -- Return True if there were errors and the user decided to exit in such
2538 -- a case. This waits for any outstanding compilation.
2540 function Start_Compile_If_Possible (Args : Argument_List) return Boolean;
2541 -- Check if there is more work that we can do (i.e. the Queue is non
2542 -- empty). If there is, do it only if we have not yet used up all the
2543 -- available processes.
2544 -- Returns True if we should exit the main loop
2546 procedure Wait_For_Available_Slot;
2547 -- Check if we should wait for a compilation to finish. This is the case
2548 -- if all the available processes are busy compiling sources or there is
2549 -- nothing else to do (that is the Q is empty and there are no good ALIs
2552 procedure Fill_Queue_From_ALI_Files;
2553 -- Check if we recorded good ALI files. If yes process them now in the
2554 -- order in which they have been recorded. There are two occasions in
2555 -- which we record good ali files. The first is in phase 1 when, after
2556 -- scanning an existing ALI file we realize it is up-to-date, the second
2557 -- instance is after a successful compilation.
2563 procedure Add_Process
2565 Sfile : File_Name_Type;
2566 Afile : File_Name_Type;
2567 Uname : Unit_Name_Type;
2568 Full_Lib_File : File_Name_Type;
2569 Lib_File_Attr : File_Attributes;
2570 Mfile : Natural := No_Mapping_File)
2572 OC1 : constant Positive := Outstanding_Compiles + 1;
2575 pragma Assert (OC1 <= Max_Process);
2576 pragma Assert (Pid /= Invalid_Pid);
2578 Running_Compile (OC1) :=
2580 Full_Source_File => Sfile,
2582 Full_Lib_File => Full_Lib_File,
2583 Lib_File_Attr => Lib_File_Attr,
2584 Source_Unit => Uname,
2585 Mapping_File => Mfile,
2586 Project => Arguments_Project);
2588 Outstanding_Compiles := OC1;
2591 --------------------
2595 procedure Await_Compile
2596 (Data : out Compilation_Data;
2600 Project : Project_Id;
2601 Comp_Data : Project_Compilation_Access;
2604 pragma Assert (Outstanding_Compiles > 0);
2606 Data := No_Compilation_Data;
2609 -- The loop here is a work-around for a problem on VMS; in some
2610 -- circumstances (shared library and several executables, for
2611 -- example), there are child processes other than compilation
2612 -- processes that are received. Until this problem is resolved,
2613 -- we will ignore such processes.
2616 Wait_Process (Pid, OK);
2618 if Pid = Invalid_Pid then
2622 for J in Running_Compile'First .. Outstanding_Compiles loop
2623 if Pid = Running_Compile (J).Pid then
2624 Data := Running_Compile (J);
2625 Project := Running_Compile (J).Project;
2627 -- If a mapping file was used by this compilation, get its
2628 -- file name for reuse by a subsequent compilation.
2630 if Running_Compile (J).Mapping_File /= No_Mapping_File then
2632 Project_Compilation_Htable.Get
2633 (Project_Compilation, Project);
2634 Comp_Data.Last_Free_Indices :=
2635 Comp_Data.Last_Free_Indices + 1;
2636 Comp_Data.Free_Mapping_File_Indices
2637 (Comp_Data.Last_Free_Indices) :=
2638 Running_Compile (J).Mapping_File;
2641 -- To actually remove this Pid and related info from
2642 -- Running_Compile replace its entry with the last valid
2643 -- entry in Running_Compile.
2645 if J = Outstanding_Compiles then
2648 Running_Compile (J) :=
2649 Running_Compile (Outstanding_Compiles);
2652 Outstanding_Compiles := Outstanding_Compiles - 1;
2657 -- This child process was not one of our compilation processes;
2658 -- just ignore it for now.
2660 -- Why is this commented out code sitting here???
2662 -- raise Program_Error;
2666 ---------------------------
2667 -- Bad_Compilation_Count --
2668 ---------------------------
2670 function Bad_Compilation_Count return Natural is
2672 return Bad_Compilation.Last - Bad_Compilation.First + 1;
2673 end Bad_Compilation_Count;
2675 ----------------------------
2676 -- Check_Standard_Library --
2677 ----------------------------
2679 procedure Check_Standard_Library is
2681 Need_To_Check_Standard_Library := False;
2683 if not Targparm.Suppress_Standard_Library_On_Target then
2685 Sfile : File_Name_Type;
2686 Add_It : Boolean := True;
2690 Add_Str_To_Name_Buffer (Standard_Library_Package_Body_Name);
2691 Sfile := Name_Enter;
2693 -- If we have a special runtime, we add the standard
2694 -- library only if we can find it.
2697 Add_It := Full_Source_Name (Sfile) /= No_File;
2701 if Is_Marked (Sfile) then
2702 if Is_In_Obsoleted (Sfile) then
2703 Executable_Obsolete := True;
2707 Insert_Q (Sfile, Index => 0);
2708 Mark (Sfile, Index => 0);
2713 end Check_Standard_Library;
2715 -----------------------------------
2716 -- Collect_Arguments_And_Compile --
2717 -----------------------------------
2719 procedure Collect_Arguments_And_Compile
2720 (Full_Source_File : File_Name_Type;
2721 Lib_File : File_Name_Type;
2723 Pid : out Process_Id;
2724 Process_Created : out Boolean) is
2726 Process_Created := False;
2728 -- If we use mapping file (-P or -C switches), then get one
2730 if Create_Mapping_File then
2731 Get_Mapping_File (Arguments_Project);
2734 -- If the source is part of a project file, we set the ADA_*_PATHs,
2735 -- check for an eventual library project, and use the full path.
2737 if Arguments_Project /= No_Project then
2738 if not Arguments_Project.Externally_Built
2739 or else Must_Compile
2741 Prj.Env.Set_Ada_Paths
2744 Including_Libraries => True,
2745 Include_Path => Use_Include_Path_File);
2747 if not Unique_Compile
2748 and then MLib.Tgt.Support_For_Libraries /= Prj.None
2751 Prj : constant Project_Id :=
2752 Ultimate_Extending_Project_Of (Arguments_Project);
2756 and then (not Prj.Externally_Built or else Must_Compile)
2757 and then not Prj.Need_To_Build_Lib
2759 -- Add to the Q all sources of the project that have
2762 Insert_Project_Sources
2763 (The_Project => Prj,
2764 All_Projects => False,
2767 -- Now mark the project as processed
2769 Prj.Need_To_Build_Lib := True;
2776 (Project => Arguments_Project,
2777 S => File_Name_Type (Arguments_Path_Name),
2779 Source_Index => Source_Index,
2780 Args => Arguments (1 .. Last_Argument));
2781 Process_Created := True;
2785 -- If this is a source outside of any project file, make sure it
2786 -- will be compiled in object directory of the main project file.
2790 (Project => Main_Project,
2791 S => Full_Source_File,
2793 Source_Index => Source_Index,
2794 Args => Arguments (1 .. Last_Argument));
2795 Process_Created := True;
2797 end Collect_Arguments_And_Compile;
2804 (Project : Project_Id;
2808 Args : Argument_List) return Process_Id
2810 Comp_Args : Argument_List (Args'First .. Args'Last + 10);
2811 Comp_Next : Integer := Args'First;
2812 Comp_Last : Integer;
2813 Arg_Index : Integer;
2815 function Ada_File_Name (Name : File_Name_Type) return Boolean;
2816 -- Returns True if Name is the name of an ada source file
2817 -- (i.e. suffix is .ads or .adb)
2823 function Ada_File_Name (Name : File_Name_Type) return Boolean is
2825 Get_Name_String (Name);
2828 and then Name_Buffer (Name_Len - 3 .. Name_Len - 1) = ".ad"
2829 and then (Name_Buffer (Name_Len) = 'b'
2831 Name_Buffer (Name_Len) = 's');
2834 -- Start of processing for Compile
2837 Enter_Into_Obsoleted (S);
2839 -- By default, Syntax_Only is False
2841 Syntax_Only := False;
2843 for J in Args'Range loop
2844 if Args (J).all = "-gnats" then
2846 -- If we compile with -gnats, the bind step and the link step
2847 -- are inhibited. Also, we set Syntax_Only to True, so that
2848 -- we don't fail when we don't find the ALI file, after
2851 Do_Bind_Step := False;
2852 Do_Link_Step := False;
2853 Syntax_Only := True;
2855 elsif Args (J).all = "-gnatc" then
2857 -- If we compile with -gnatc, the bind step and the link step
2858 -- are inhibited. We set Syntax_Only to False for the case when
2859 -- -gnats was previously specified.
2861 Do_Bind_Step := False;
2862 Do_Link_Step := False;
2863 Syntax_Only := False;
2867 Comp_Args (Comp_Next) := new String'("-gnatea");
2868 Comp_Next := Comp_Next + 1;
2870 Comp_Args (Comp_Next) := Comp_Flag;
2871 Comp_Next := Comp_Next + 1;
2873 -- Optimize the simple case where the gcc command line looks like
2874 -- gcc -c -I. ... -I- file.adb
2876 -- gcc -c ... file.adb
2878 if Args (Args'First).all = "-I" & Normalized_CWD
2879 and then Args (Args'Last).all = "-I-"
2880 and then S = Strip_Directory (S)
2882 Comp_Last := Comp_Next + Args'Length - 3;
2883 Arg_Index := Args'First + 1;
2886 Comp_Last := Comp_Next + Args'Length - 1;
2887 Arg_Index := Args'First;
2890 -- Make a deep copy of the arguments, because Normalize_Arguments
2891 -- may deallocate some arguments.
2893 for J in Comp_Next .. Comp_Last loop
2894 Comp_Args (J) := new String'(Args (Arg_Index).all);
2895 Arg_Index := Arg_Index + 1;
2898 -- Set -gnatpg for predefined files (for this purpose the renamings
2899 -- such as Text_IO do not count as predefined). Note that we strip
2900 -- the directory name from the source file name because the call to
2901 -- Fname.Is_Predefined_File_Name cannot deal with directory prefixes.
2904 Fname : constant File_Name_Type := Strip_Directory (S);
2907 if Is_Predefined_File_Name (Fname, False) then
2908 if Check_Readonly_Files then
2909 Comp_Args (Comp_Args'First + 2 .. Comp_Last + 1) :=
2910 Comp_Args (Comp_Args'First + 1 .. Comp_Last);
2911 Comp_Last := Comp_Last + 1;
2912 Comp_Args (Comp_Args'First + 1) := GNAT_Flag;
2916 ("not allowed to compile """ &
2917 Get_Name_String (Fname) &
2918 """; use -a switch, or compile file with " &
2919 """-gnatg"" switch");
2924 -- Now check if the file name has one of the suffixes familiar to
2925 -- the gcc driver. If this is not the case then add the ada flag
2928 if not Ada_File_Name (S) and then not Targparm.AAMP_On_Target then
2929 Comp_Last := Comp_Last + 1;
2930 Comp_Args (Comp_Last) := Ada_Flag_1;
2931 Comp_Last := Comp_Last + 1;
2932 Comp_Args (Comp_Last) := Ada_Flag_2;
2935 if Source_Index /= 0 then
2937 Num : constant String := Source_Index'Img;
2939 Comp_Last := Comp_Last + 1;
2940 Comp_Args (Comp_Last) :=
2941 new String'("-gnateI" & Num (Num'First + 1 .. Num'Last));
2945 if Source_Index /= 0
2946 or else L /= Strip_Directory (L)
2947 or else Object_Directory_Path /= null
2949 -- Build -o argument
2951 Get_Name_String (L);
2953 for J in reverse 1 .. Name_Len loop
2954 if Name_Buffer (J) = '.' then
2955 Name_Len := J + Object_Suffix'Length - 1;
2956 Name_Buffer (J .. Name_Len) := Object_Suffix;
2961 Comp_Last := Comp_Last + 1;
2962 Comp_Args (Comp_Last) := Output_Flag;
2963 Comp_Last := Comp_Last + 1;
2965 -- If an object directory was specified, prepend the object file
2966 -- name with this object directory.
2968 if Object_Directory_Path /= null then
2969 Comp_Args (Comp_Last) :=
2970 new String'(Object_Directory_Path.all &
2971 Name_Buffer (1 .. Name_Len));
2974 Comp_Args (Comp_Last) :=
2975 new String'(Name_Buffer (1 .. Name_Len));
2979 if Create_Mapping_File and then Mapping_File_Arg /= null then
2980 Comp_Last := Comp_Last + 1;
2981 Comp_Args (Comp_Last) := new String'(Mapping_File_Arg.all);
2984 Get_Name_String (S);
2986 Comp_Last := Comp_Last + 1;
2987 Comp_Args (Comp_Last) := new String'(Name_Buffer (1 .. Name_Len));
2989 -- Change to object directory of the project file, if necessary
2991 if Project /= No_Project then
2992 Change_To_Object_Directory (Project);
2995 GNAT.OS_Lib.Normalize_Arguments (Comp_Args (Args'First .. Comp_Last));
2997 Comp_Last := Comp_Last + 1;
2998 Comp_Args (Comp_Last) := new String'("-gnatez");
3000 Display (Gcc.all, Comp_Args (Args'First .. Comp_Last));
3002 if Gcc_Path = null then
3003 Make_Failed ("error, unable to locate " & Gcc.all);
3007 GNAT.OS_Lib.Non_Blocking_Spawn
3008 (Gcc_Path.all, Comp_Args (Args'First .. Comp_Last));
3011 -------------------------------
3012 -- Fill_Queue_From_ALI_Files --
3013 -------------------------------
3015 procedure Fill_Queue_From_ALI_Files is
3018 Sfile : File_Name_Type;
3019 Uname : Unit_Name_Type;
3020 Unit_Name : Name_Id;
3021 Uid : Prj.Unit_Index;
3024 while Good_ALI_Present loop
3025 ALI := Get_Next_Good_ALI;
3026 Source_Index := Unit_Index_Of (ALIs.Table (ALI).Afile);
3028 -- If we are processing the library file corresponding to the
3029 -- main source file check if this source can be a main unit.
3031 if ALIs.Table (ALI).Sfile = Main_Source
3032 and then Source_Index = Main_Index
3034 Main_Unit := ALIs.Table (ALI).Main_Program /= None;
3037 -- The following adds the standard library (s-stalib) to the list
3038 -- of files to be handled by gnatmake: this file and any files it
3039 -- depends on are always included in every bind, even if they are
3040 -- not in the explicit dependency list. Of course, it is not added
3041 -- if Suppress_Standard_Library is True.
3043 -- However, to avoid annoying output about s-stalib.ali being read
3044 -- only, when "-v" is used, we add the standard library only when
3047 if Need_To_Check_Standard_Library then
3048 Check_Standard_Library;
3051 -- Now insert in the Q the unmarked source files (i.e. those which
3052 -- have never been inserted in the Q and hence never considered).
3053 -- Only do that if Unique_Compile is False.
3055 if not Unique_Compile then
3057 ALIs.Table (ALI).First_Unit .. ALIs.Table (ALI).Last_Unit
3060 Units.Table (J).First_With .. Units.Table (J).Last_With
3062 Sfile := Withs.Table (K).Sfile;
3063 Uname := Withs.Table (K).Uname;
3065 -- If project files are used, find the proper source to
3066 -- compile in case Sfile is the spec but there is a body.
3068 if Main_Project /= No_Project then
3069 Get_Name_String (Uname);
3070 Name_Len := Name_Len - 2;
3071 Unit_Name := Name_Find;
3073 Units_Htable.Get (Project_Tree.Units_HT, Unit_Name);
3075 if Uid /= Prj.No_Unit_Index then
3076 if Uid.File_Names (Impl) /= null
3077 and then not Uid.File_Names (Impl).Locally_Removed
3079 Sfile := Uid.File_Names (Impl).File;
3080 Source_Index := Uid.File_Names (Impl).Index;
3082 elsif Uid.File_Names (Spec) /= null
3083 and then not Uid.File_Names (Spec).Locally_Removed
3085 Sfile := Uid.File_Names (Spec).File;
3086 Source_Index := Uid.File_Names (Spec).Index;
3091 Dependencies.Append ((ALIs.Table (ALI).Sfile, Sfile));
3093 if Is_In_Obsoleted (Sfile) then
3094 Executable_Obsolete := True;
3097 if Sfile = No_File then
3098 Debug_Msg ("Skipping generic:", Withs.Table (K).Uname);
3101 Source_Index := Unit_Index_Of (Withs.Table (K).Afile);
3103 if Is_Marked (Sfile, Source_Index) then
3104 Debug_Msg ("Skipping marked file:", Sfile);
3106 elsif not Check_Readonly_Files
3107 and then Is_Internal_File_Name (Sfile, False)
3109 Debug_Msg ("Skipping internal file:", Sfile);
3113 (Sfile, Withs.Table (K).Uname, Source_Index);
3114 Mark (Sfile, Source_Index);
3121 end Fill_Queue_From_ALI_Files;
3123 ----------------------
3124 -- Get_Mapping_File --
3125 ----------------------
3127 procedure Get_Mapping_File (Project : Project_Id) is
3128 Data : Project_Compilation_Access;
3131 Data := Project_Compilation_Htable.Get (Project_Compilation, Project);
3133 -- If there is a mapping file ready to be reused, reuse it
3135 if Data.Last_Free_Indices > 0 then
3136 Mfile := Data.Free_Mapping_File_Indices (Data.Last_Free_Indices);
3137 Data.Last_Free_Indices := Data.Last_Free_Indices - 1;
3139 -- Otherwise, create and initialize a new one
3143 (Project => Project, Data => Data.all, File_Index => Mfile);
3146 -- Put the name in the mapping file argument for the invocation
3149 Free (Mapping_File_Arg);
3151 new String'("-gnatem=" &
3152 Get_Name_String (Data.Mapping_File_Names (Mfile)));
3153 end Get_Mapping_File;
3155 -----------------------
3156 -- Get_Next_Good_ALI --
3157 -----------------------
3159 function Get_Next_Good_ALI return ALI_Id is
3163 pragma Assert (Good_ALI_Present);
3164 ALI := Good_ALI.Table (Good_ALI.Last);
3165 Good_ALI.Decrement_Last;
3167 end Get_Next_Good_ALI;
3169 ----------------------
3170 -- Good_ALI_Present --
3171 ----------------------
3173 function Good_ALI_Present return Boolean is
3175 return Good_ALI.First <= Good_ALI.Last;
3176 end Good_ALI_Present;
3178 --------------------------------
3179 -- Must_Exit_Because_Of_Error --
3180 --------------------------------
3182 function Must_Exit_Because_Of_Error return Boolean is
3183 Data : Compilation_Data;
3187 if Bad_Compilation_Count > 0 and then not Keep_Going then
3188 while Outstanding_Compiles > 0 loop
3189 Await_Compile (Data, Success);
3192 Record_Failure (Data.Full_Source_File, Data.Source_Unit);
3200 end Must_Exit_Because_Of_Error;
3202 --------------------
3203 -- Record_Failure --
3204 --------------------
3206 procedure Record_Failure
3207 (File : File_Name_Type;
3208 Unit : Unit_Name_Type;
3209 Found : Boolean := True)
3212 Bad_Compilation.Increment_Last;
3213 Bad_Compilation.Table (Bad_Compilation.Last) := (File, Unit, Found);
3216 ---------------------
3217 -- Record_Good_ALI --
3218 ---------------------
3220 procedure Record_Good_ALI (A : ALI_Id) is
3222 Good_ALI.Increment_Last;
3223 Good_ALI.Table (Good_ALI.Last) := A;
3224 end Record_Good_ALI;
3226 -------------------------------
3227 -- Start_Compile_If_Possible --
3228 -------------------------------
3230 function Start_Compile_If_Possible
3231 (Args : Argument_List) return Boolean
3233 In_Lib_Dir : Boolean;
3234 Need_To_Compile : Boolean;
3236 Process_Created : Boolean;
3238 Source_File : File_Name_Type;
3239 Full_Source_File : File_Name_Type;
3240 Source_File_Attr : aliased File_Attributes;
3241 -- The full name of the source file and its attributes (size, ...)
3243 Source_Unit : Unit_Name_Type;
3245 -- Index of the current unit in the current source file
3247 Lib_File : File_Name_Type;
3248 Full_Lib_File : File_Name_Type;
3249 Lib_File_Attr : aliased File_Attributes;
3250 Read_Only : Boolean := False;
3252 -- The ALI file and its attributes (size, stamp, ...)
3254 Obj_File : File_Name_Type;
3255 Obj_Stamp : Time_Stamp_Type;
3259 if not Empty_Q and then Outstanding_Compiles < Max_Process then
3260 Extract_From_Q (Source_File, Source_Unit, Source_Index);
3262 Osint.Full_Source_Name
3264 Full_File => Full_Source_File,
3265 Attr => Source_File_Attr'Access);
3267 Lib_File := Osint.Lib_File_Name (Source_File, Source_Index);
3269 -- ??? This call could be avoided when using projects, since we
3270 -- know where the ALI file is supposed to be. That would avoid
3271 -- searches in the object directories, including in the runtime
3272 -- dir. However, that would require getting access to the
3275 Osint.Full_Lib_File_Name
3277 Lib_File => Full_Lib_File,
3278 Attr => Lib_File_Attr);
3280 -- If source has already been compiled, executable is obsolete
3282 if Is_In_Obsoleted (Source_File) then
3283 Executable_Obsolete := True;
3286 In_Lib_Dir := not Check_Readonly_Files
3287 and then Full_Lib_File /= No_File
3288 and then In_Ada_Lib_Dir (Full_Lib_File);
3290 -- Since the following requires a system call, we precompute it
3293 if not In_Lib_Dir then
3294 if Full_Lib_File /= No_File
3295 and then not Check_Readonly_Files
3297 Get_Name_String (Full_Lib_File);
3298 Name_Buffer (Name_Len + 1) := ASCII.NUL;
3299 Read_Only := not Is_Writable_File
3300 (Name_Buffer'Address, Lib_File_Attr'Access);
3306 -- If the library file is an Ada library skip it
3311 "is in an Ada library",
3313 Minimum_Verbosity => Opt.High);
3315 -- If the library file is a read-only library skip it, but only
3316 -- if, when using project files, this library file is in the
3317 -- right object directory (a read-only ALI file in the object
3318 -- directory of a project being extended must not be skipped).
3321 and then Is_In_Object_Directory (Source_File, Full_Lib_File)
3325 "is a read-only library",
3327 Minimum_Verbosity => Opt.High);
3329 -- The source file that we are checking cannot be located
3331 elsif Full_Source_File = No_File then
3332 Record_Failure (Source_File, Source_Unit, False);
3334 -- Source and library files can be located but are internal
3337 elsif not Check_Readonly_Files
3338 and then Full_Lib_File /= No_File
3339 and then Is_Internal_File_Name (Source_File, False)
3341 if Force_Compilations then
3343 ("not allowed to compile """ &
3344 Get_Name_String (Source_File) &
3345 """; use -a switch, or compile file with " &
3346 """-gnatg"" switch");
3351 "is an internal library",
3353 Minimum_Verbosity => Opt.High);
3355 -- The source file that we are checking can be located
3358 Collect_Arguments (Source_File, Source_Index,
3359 Source_File = Main_Source, Args);
3361 -- Do nothing if project of source is externally built
3363 if Arguments_Project = No_Project
3364 or else not Arguments_Project.Externally_Built
3365 or else Must_Compile
3367 -- Don't waste any time if we have to recompile anyway
3369 Obj_Stamp := Empty_Time_Stamp;
3370 Need_To_Compile := Force_Compilations;
3372 if not Force_Compilations then
3373 Check (Source_File => Source_File,
3374 Source_Index => Source_Index,
3375 Is_Main_Source => Source_File = Main_Source,
3377 Lib_File => Lib_File,
3378 Full_Lib_File => Full_Lib_File,
3379 Lib_File_Attr => Lib_File_Attr'Access,
3380 Read_Only => Read_Only,
3383 O_Stamp => Obj_Stamp);
3384 Need_To_Compile := (ALI = No_ALI_Id);
3387 if not Need_To_Compile then
3389 -- The ALI file is up-to-date; record its Id
3391 Record_Good_ALI (ALI);
3393 -- Record the time stamp of the most recent object
3394 -- file as long as no (re)compilations are needed.
3396 if First_Compiled_File = No_File
3397 and then (Most_Recent_Obj_File = No_File
3398 or else Obj_Stamp > Most_Recent_Obj_Stamp)
3400 Most_Recent_Obj_File := Obj_File;
3401 Most_Recent_Obj_Stamp := Obj_Stamp;
3405 -- Check that switch -x has been used if a source outside
3406 -- of project files need to be compiled.
3408 if Main_Project /= No_Project
3409 and then Arguments_Project = No_Project
3410 and then not External_Unit_Compilation_Allowed
3412 Make_Failed ("external source ("
3413 & Get_Name_String (Source_File)
3414 & ") is not part of any project;"
3415 & " cannot be compiled without"
3416 & " gnatmake switch -x");
3419 -- Is this the first file we have to compile?
3421 if First_Compiled_File = No_File then
3422 First_Compiled_File := Full_Source_File;
3423 Most_Recent_Obj_File := No_File;
3425 if Do_Not_Execute then
3427 -- Exit the main loop
3433 -- Compute where the ALI file must be generated in
3434 -- In_Place_Mode (this does not require to know the
3435 -- location of the object directory).
3437 if In_Place_Mode then
3438 if Full_Lib_File = No_File then
3440 -- If the library file was not found, then save
3441 -- the library file near the source file.
3445 (Full_Source_File, Source_Index);
3446 Full_Lib_File := Lib_File;
3449 -- If the library file was found, then save the
3450 -- library file in the same place.
3452 Lib_File := Full_Lib_File;
3456 -- Start the compilation and record it. We can do this
3457 -- because there is at least one free process. This might
3458 -- change the current directory.
3460 Collect_Arguments_And_Compile
3461 (Full_Source_File => Full_Source_File,
3462 Lib_File => Lib_File,
3463 Source_Index => Source_Index,
3465 Process_Created => Process_Created);
3467 -- Compute where the ALI file will be generated (for
3468 -- cases that might require to know the current
3469 -- directory). The current directory might be changed
3470 -- when compiling other files so we cannot rely on it
3471 -- being the same to find the resulting ALI file.
3473 if not In_Place_Mode then
3475 -- Compute the expected location of the ALI file. This
3476 -- can be from several places:
3477 -- -i => in place mode. In such a case,
3478 -- Full_Lib_File has already been set above
3479 -- -D => if specified
3480 -- or defaults in current dir
3481 -- We could simply use a call similar to
3482 -- Osint.Full_Lib_File_Name (Lib_File)
3483 -- but that involves system calls and is thus slower
3485 if Object_Directory_Path /= null then
3487 Add_Str_To_Name_Buffer (Object_Directory_Path.all);
3488 Add_Str_To_Name_Buffer (Get_Name_String (Lib_File));
3489 Full_Lib_File := Name_Find;
3492 if Project_Of_Current_Object_Directory /=
3496 (Project_Of_Current_Object_Directory
3497 .Object_Directory.Name);
3498 Add_Str_To_Name_Buffer
3499 (Get_Name_String (Lib_File));
3500 Full_Lib_File := Name_Find;
3503 Full_Lib_File := Lib_File;
3509 Lib_File_Attr := Unknown_Attributes;
3511 -- Make sure we could successfully start the compilation
3513 if Process_Created then
3514 if Pid = Invalid_Pid then
3515 Record_Failure (Full_Source_File, Source_Unit);
3519 Sfile => Full_Source_File,
3521 Uname => Source_Unit,
3523 Full_Lib_File => Full_Lib_File,
3524 Lib_File_Attr => Lib_File_Attr);
3532 end Start_Compile_If_Possible;
3534 -----------------------------
3535 -- Wait_For_Available_Slot --
3536 -----------------------------
3538 procedure Wait_For_Available_Slot is
3539 Compilation_OK : Boolean;
3540 Text : Text_Buffer_Ptr;
3542 Data : Compilation_Data;
3545 if Outstanding_Compiles = Max_Process
3547 and then not Good_ALI_Present
3548 and then Outstanding_Compiles > 0)
3550 Await_Compile (Data, Compilation_OK);
3552 if not Compilation_OK then
3553 Record_Failure (Data.Full_Source_File, Data.Source_Unit);
3556 if Compilation_OK or else Keep_Going then
3558 -- Re-read the updated library file
3561 Saved_Object_Consistency : constant Boolean :=
3562 Check_Object_Consistency;
3565 -- If compilation was not OK, or if output is not an object
3566 -- file and we don't do the bind step, don't check for
3567 -- object consistency.
3569 Check_Object_Consistency :=
3570 Check_Object_Consistency
3572 and (Output_Is_Object or Do_Bind_Step);
3575 Read_Library_Info_From_Full
3576 (Data.Full_Lib_File, Data.Lib_File_Attr'Access);
3578 -- Restore Check_Object_Consistency to its initial value
3580 Check_Object_Consistency := Saved_Object_Consistency;
3583 -- If an ALI file was generated by this compilation, scan the
3584 -- ALI file and record it.
3586 -- If the scan fails, a previous ali file is inconsistent with
3587 -- the unit just compiled.
3589 if Text /= null then
3592 (Data.Lib_File, Text, Ignore_ED => False, Err => True);
3594 if ALI = No_ALI_Id then
3596 -- Record a failure only if not already done
3598 if Compilation_OK then
3601 "incompatible ALI file, please recompile");
3603 (Data.Full_Source_File, Data.Source_Unit);
3607 Record_Good_ALI (ALI);
3612 -- If we could not read the ALI file that was just generated
3613 -- then there could be a problem reading either the ALI or the
3614 -- corresponding object file (if Check_Object_Consistency is
3615 -- set Read_Library_Info checks that the time stamp of the
3616 -- object file is more recent than that of the ALI). However,
3617 -- we record a failure only if not already done.
3620 if Compilation_OK and not Syntax_Only then
3623 "WARNING: ALI or object file not found after compile");
3624 Record_Failure (Data.Full_Source_File, Data.Source_Unit);
3629 end Wait_For_Available_Slot;
3631 -- Start of processing for Compile_Sources
3634 pragma Assert (Args'First = 1);
3636 Outstanding_Compiles := 0;
3637 Running_Compile := new Comp_Data_Arr (1 .. Max_Process);
3639 -- Package and Queue initializations
3643 if First_Q_Initialization then
3647 if Initialize_ALI_Data then
3649 Initialize_ALI_Source;
3652 -- The following two flags affect the behavior of ALI.Set_Source_Table.
3653 -- We set Check_Source_Files to True to ensure that source file time
3654 -- stamps are checked, and we set All_Sources to False to avoid checking
3655 -- the presence of the source files listed in the source dependency
3656 -- section of an ali file (which would be a mistake since the ali file
3657 -- may be obsolete).
3659 Check_Source_Files := True;
3660 All_Sources := False;
3662 -- Only insert in the Q if it is not already done, to avoid simultaneous
3663 -- compilations if -jnnn is used.
3665 if not Is_Marked (Main_Source, Main_Index) then
3666 Insert_Q (Main_Source, Index => Main_Index);
3667 Mark (Main_Source, Main_Index);
3670 First_Compiled_File := No_File;
3671 Most_Recent_Obj_File := No_File;
3672 Most_Recent_Obj_Stamp := Empty_Time_Stamp;
3675 -- Keep looping until there is no more work to do (the Q is empty)
3676 -- and all the outstanding compilations have terminated.
3678 Make_Loop : while not Empty_Q or else Outstanding_Compiles > 0 loop
3679 exit Make_Loop when Must_Exit_Because_Of_Error;
3680 exit Make_Loop when Start_Compile_If_Possible (Args);
3682 Wait_For_Available_Slot;
3684 -- ??? Should be done as soon as we add a Good_ALI, wouldn't it avoid
3685 -- the need for a list of good ALI?
3687 Fill_Queue_From_ALI_Files;
3689 if Display_Compilation_Progress then
3690 Write_Str ("completed ");
3691 Write_Int (Int (Q_Front));
3692 Write_Str (" out of ");
3693 Write_Int (Int (Q.Last));
3695 Write_Int (Int ((Q_Front * 100) / (Q.Last - Q.First)));
3696 Write_Str ("%)...");
3701 Compilation_Failures := Bad_Compilation_Count;
3703 -- Compilation is finished
3705 -- Delete any temporary configuration pragma file
3707 if not Debug.Debug_Flag_N then
3708 Delete_Temp_Config_Files;
3710 end Compile_Sources;
3712 ----------------------------------
3713 -- Configuration_Pragmas_Switch --
3714 ----------------------------------
3716 function Configuration_Pragmas_Switch
3717 (For_Project : Project_Id) return Argument_List
3719 The_Packages : Package_Id;
3720 Gnatmake : Package_Id;
3721 Compiler : Package_Id;
3723 Global_Attribute : Variable_Value := Nil_Variable_Value;
3724 Local_Attribute : Variable_Value := Nil_Variable_Value;
3726 Global_Attribute_Present : Boolean := False;
3727 Local_Attribute_Present : Boolean := False;
3729 Result : Argument_List (1 .. 3);
3730 Last : Natural := 0;
3732 function Absolute_Path
3733 (Path : Path_Name_Type;
3734 Project : Project_Id) return String;
3735 -- Returns an absolute path for a configuration pragmas file
3741 function Absolute_Path
3742 (Path : Path_Name_Type;
3743 Project : Project_Id) return String
3746 Get_Name_String (Path);
3749 Path_Name : constant String := Name_Buffer (1 .. Name_Len);
3752 if Is_Absolute_Path (Path_Name) then
3757 Parent_Directory : constant String :=
3758 Get_Name_String (Project.Directory.Display_Name);
3761 if Parent_Directory (Parent_Directory'Last) =
3764 return Parent_Directory & Path_Name;
3767 return Parent_Directory & Directory_Separator & Path_Name;
3774 -- Start of processing for Configuration_Pragmas_Switch
3777 Prj.Env.Create_Config_Pragmas_File
3778 (For_Project, Project_Tree);
3780 if For_Project.Config_File_Name /= No_Path then
3781 Temporary_Config_File := For_Project.Config_File_Temp;
3785 ("-gnatec=" & Get_Name_String (For_Project.Config_File_Name));
3788 Temporary_Config_File := False;
3791 -- Check for attribute Builder'Global_Configuration_Pragmas
3793 The_Packages := Main_Project.Decl.Packages;
3796 (Name => Name_Builder,
3797 In_Packages => The_Packages,
3798 In_Tree => Project_Tree);
3800 if Gnatmake /= No_Package then
3801 Global_Attribute := Prj.Util.Value_Of
3802 (Variable_Name => Name_Global_Configuration_Pragmas,
3803 In_Variables => Project_Tree.Packages.Table
3804 (Gnatmake).Decl.Attributes,
3805 In_Tree => Project_Tree);
3806 Global_Attribute_Present :=
3807 Global_Attribute /= Nil_Variable_Value
3808 and then Get_Name_String (Global_Attribute.Value) /= "";
3810 if Global_Attribute_Present then
3812 Path : constant String :=
3814 (Path_Name_Type (Global_Attribute.Value),
3815 Global_Attribute.Project);
3817 if not Is_Regular_File (Path) then
3818 if Debug.Debug_Flag_F then
3820 ("cannot find configuration pragmas file "
3821 & File_Name (Path));
3824 ("cannot find configuration pragmas file " & Path);
3829 Result (Last) := new String'("-gnatec=" & Path);
3834 -- Check for attribute Compiler'Local_Configuration_Pragmas
3836 The_Packages := For_Project.Decl.Packages;
3839 (Name => Name_Compiler,
3840 In_Packages => The_Packages,
3841 In_Tree => Project_Tree);
3843 if Compiler /= No_Package then
3844 Local_Attribute := Prj.Util.Value_Of
3845 (Variable_Name => Name_Local_Configuration_Pragmas,
3846 In_Variables => Project_Tree.Packages.Table
3847 (Compiler).Decl.Attributes,
3848 In_Tree => Project_Tree);
3849 Local_Attribute_Present :=
3850 Local_Attribute /= Nil_Variable_Value
3851 and then Get_Name_String (Local_Attribute.Value) /= "";
3853 if Local_Attribute_Present then
3855 Path : constant String :=
3857 (Path_Name_Type (Local_Attribute.Value),
3858 Local_Attribute.Project);
3860 if not Is_Regular_File (Path) then
3861 if Debug.Debug_Flag_F then
3863 ("cannot find configuration pragmas file "
3864 & File_Name (Path));
3868 ("cannot find configuration pragmas file " & Path);
3873 Result (Last) := new String'("-gnatec=" & Path);
3878 return Result (1 .. Last);
3879 end Configuration_Pragmas_Switch;
3885 procedure Debug_Msg (S : String; N : Name_Id) is
3887 if Debug.Debug_Flag_W then
3888 Write_Str (" ... ");
3896 procedure Debug_Msg (S : String; N : File_Name_Type) is
3898 Debug_Msg (S, Name_Id (N));
3901 procedure Debug_Msg (S : String; N : Unit_Name_Type) is
3903 Debug_Msg (S, Name_Id (N));
3906 ---------------------------
3907 -- Delete_All_Temp_Files --
3908 ---------------------------
3910 procedure Delete_All_Temp_Files is
3912 if not Debug.Debug_Flag_N then
3913 Delete_Temp_Config_Files;
3914 Prj.Delete_All_Temp_Files (Project_Tree);
3916 end Delete_All_Temp_Files;
3918 ------------------------------
3919 -- Delete_Temp_Config_Files --
3920 ------------------------------
3922 procedure Delete_Temp_Config_Files is
3924 Proj : Project_List;
3925 pragma Warnings (Off, Success);
3928 -- The caller is responsible for ensuring that Debug_Flag_N is False
3930 pragma Assert (not Debug.Debug_Flag_N);
3932 if Main_Project /= No_Project then
3933 Proj := Project_Tree.Projects;
3934 while Proj /= null loop
3935 if Proj.Project.Config_File_Temp then
3936 Delete_Temporary_File
3937 (Project_Tree, Proj.Project.Config_File_Name);
3939 -- Make sure that we don't have a config file for this project,
3940 -- in case there are several mains. In this case, we will
3941 -- recreate another config file: we cannot reuse the one that
3944 Proj.Project.Config_Checked := False;
3945 Proj.Project.Config_File_Name := No_Path;
3946 Proj.Project.Config_File_Temp := False;
3951 end Delete_Temp_Config_Files;
3957 procedure Display (Program : String; Args : Argument_List) is
3959 pragma Assert (Args'First = 1);
3961 if Display_Executed_Programs then
3962 Write_Str (Program);
3964 for J in Args'Range loop
3966 -- Never display -gnatea nor -gnatez
3968 if Args (J).all /= "-gnatea"
3970 Args (J).all /= "-gnatez"
3972 -- Do not display the mapping file argument automatically
3973 -- created when using a project file.
3975 if Main_Project = No_Project
3976 or else Debug.Debug_Flag_N
3977 or else Args (J)'Length < 8
3979 Args (J) (Args (J)'First .. Args (J)'First + 6) /= "-gnatem"
3981 -- When -dn is not specified, do not display the config
3982 -- pragmas switch (-gnatec) for the temporary file created
3983 -- by the project manager (always the first -gnatec switch).
3984 -- Reset Temporary_Config_File to False so that the eventual
3985 -- other -gnatec switches will be displayed.
3987 if (not Debug.Debug_Flag_N)
3988 and then Temporary_Config_File
3989 and then Args (J)'Length > 7
3990 and then Args (J) (Args (J)'First .. Args (J)'First + 6)
3993 Temporary_Config_File := False;
3995 -- Do not display the -F=mapping_file switch for gnatbind
3996 -- if -dn is not specified.
3998 elsif Debug.Debug_Flag_N
3999 or else Args (J)'Length < 4
4001 Args (J) (Args (J)'First .. Args (J)'First + 2) /= "-F="
4005 -- If -df is used, only display file names, not path
4008 if Debug.Debug_Flag_F then
4010 Equal_Pos : Natural;
4012 Equal_Pos := Args (J)'First - 1;
4013 for K in Args (J)'Range loop
4014 if Args (J) (K) = '=' then
4021 (Args (J) (Equal_Pos + 1 .. Args (J)'Last))
4024 (Args (J) (Args (J)'First .. Equal_Pos));
4028 (Equal_Pos + 1 .. Args (J)'Last)));
4031 Write_Str (Args (J).all);
4036 Write_Str (Args (J).all);
4047 ----------------------
4048 -- Display_Commands --
4049 ----------------------
4051 procedure Display_Commands (Display : Boolean := True) is
4053 Display_Executed_Programs := Display;
4054 end Display_Commands;
4060 function Empty_Q return Boolean is
4062 if Debug.Debug_Flag_P then
4063 Write_Str (" Q := [");
4065 for J in Q_Front .. Q.Last - 1 loop
4067 Write_Name (Q.Table (J).File);
4076 return Q_Front >= Q.Last;
4079 --------------------------
4080 -- Enter_Into_Obsoleted --
4081 --------------------------
4083 procedure Enter_Into_Obsoleted (F : File_Name_Type) is
4084 Name : constant String := Get_Name_String (F);
4086 F2 : File_Name_Type;
4090 while First > Name'First
4091 and then Name (First - 1) /= Directory_Separator
4092 and then Name (First - 1) /= '/'
4097 if First /= Name'First then
4099 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
4106 Debug_Msg ("New entry in Obsoleted table:", F2);
4107 Obsoleted.Set (F2, True);
4108 end Enter_Into_Obsoleted;
4110 --------------------
4111 -- Extract_From_Q --
4112 --------------------
4114 procedure Extract_From_Q
4115 (Source_File : out File_Name_Type;
4116 Source_Unit : out Unit_Name_Type;
4117 Source_Index : out Int)
4119 File : constant File_Name_Type := Q.Table (Q_Front).File;
4120 Unit : constant Unit_Name_Type := Q.Table (Q_Front).Unit;
4121 Index : constant Int := Q.Table (Q_Front).Index;
4124 if Debug.Debug_Flag_Q then
4125 Write_Str (" Q := Q - [ ");
4137 Q_Front := Q_Front + 1;
4138 Source_File := File;
4139 Source_Unit := Unit;
4140 Source_Index := Index;
4147 procedure Gnatmake is
4148 Main_Source_File : File_Name_Type;
4149 -- The source file containing the main compilation unit
4151 Compilation_Failures : Natural;
4153 Total_Compilation_Failures : Natural := 0;
4155 Is_Main_Unit : Boolean;
4156 -- Set True by Compile_Sources if Main_Source_File can be a main unit
4158 Main_ALI_File : File_Name_Type;
4159 -- The ali file corresponding to Main_Source_File
4161 Executable : File_Name_Type := No_File;
4162 -- The file name of an executable
4164 Non_Std_Executable : Boolean := False;
4165 -- Non_Std_Executable is set to True when there is a possibility that
4166 -- the linker will not choose the correct executable file name.
4168 Current_Work_Dir : constant String_Access :=
4169 new String'(Get_Current_Dir);
4170 -- The current working directory, used to modify some relative path
4171 -- switches on the command line when a project file is used.
4173 Current_Main_Index : Int := 0;
4174 -- If not zero, the index of the current main unit in its source file
4176 Stand_Alone_Libraries : Boolean := False;
4177 -- Set to True when there are Stand-Alone Libraries, so that gnatbind
4178 -- is invoked with the -F switch to force checking of elaboration flags.
4180 Mapping_Path : Path_Name_Type := No_Path;
4181 -- The path name of the mapping file
4183 Project_Node_Tree : Project_Node_Tree_Ref;
4186 pragma Warnings (Off, Discard);
4188 procedure Check_Mains;
4189 -- Check that the main subprograms do exist and that they all
4190 -- belong to the same project file.
4192 procedure Create_Binder_Mapping_File
4193 (Args : in out Argument_List; Last_Arg : in out Natural);
4194 -- Create a binder mapping file and add the necessary switch
4200 procedure Check_Mains is
4201 Real_Main_Project : Project_Id := No_Project;
4202 -- The project of the first main
4204 Proj : Project_Id := No_Project;
4205 -- The project of the current main
4207 Real_Path : String_Access;
4216 Main : constant String := Mains.Next_Main;
4217 -- The name specified on the command line may include directory
4220 File_Name : constant String := Base_Name (Main);
4221 -- The simple file name of the current main
4223 Lang : Language_Ptr;
4226 exit when Main = "";
4228 -- Get the project of the current main
4230 Proj := Prj.Env.Project_Of
4231 (File_Name, Main_Project, Project_Tree);
4233 -- Fail if the current main is not a source of a project
4235 if Proj = No_Project then
4237 ("""" & Main & """ is not a source of any project");
4240 -- If there is directory information, check that the source
4241 -- exists and, if it does, that the path is the actual path
4242 -- of a source of a project.
4244 if Main /= File_Name then
4245 Lang := Get_Language_From_Name (Main_Project, "ada");
4249 (Main & Get_Name_String
4250 (Lang.Config.Naming_Data.Body_Suffix),
4252 if Real_Path = null then
4255 (Main & Get_Name_String
4256 (Lang.Config.Naming_Data.Spec_Suffix),
4260 if Real_Path = null then
4261 Real_Path := Locate_Regular_File (Main, "");
4264 -- Fail if the file cannot be found
4266 if Real_Path = null then
4267 Make_Failed ("file """ & Main & """ does not exist");
4271 Project_Path : constant String :=
4272 Prj.Env.File_Name_Of_Library_Unit_Body
4274 Project => Main_Project,
4275 In_Tree => Project_Tree,
4276 Main_Project_Only => False,
4278 Normed_Path : constant String :=
4281 Case_Sensitive => False);
4282 Proj_Path : constant String :=
4285 Case_Sensitive => False);
4290 -- Fail if it is not the correct path
4292 if Normed_Path /= Proj_Path then
4293 if Verbose_Mode then
4295 Write_Str (Normed_Path);
4297 Write_Line (Proj_Path);
4302 """ is not a source of any project");
4307 if not Unique_Compile then
4309 -- Record the project, if it is the first main
4311 if Real_Main_Project = No_Project then
4312 Real_Main_Project := Proj;
4314 elsif Proj /= Real_Main_Project then
4316 -- Fail, as the current main is not a source of the
4317 -- same project as the first main.
4321 """ is not a source of project " &
4322 Get_Name_String (Real_Main_Project.Name));
4327 -- If -u and -U are not used, we may have mains that are
4328 -- sources of a project that is not the one specified with
4331 if not Unique_Compile then
4332 Main_Project := Real_Main_Project;
4338 --------------------------------
4339 -- Create_Binder_Mapping_File --
4340 --------------------------------
4342 procedure Create_Binder_Mapping_File
4343 (Args : in out Argument_List; Last_Arg : in out Natural)
4345 Mapping_FD : File_Descriptor := Invalid_FD;
4346 -- A File Descriptor for an eventual mapping file
4348 ALI_Unit : Unit_Name_Type := No_Unit_Name;
4349 -- The unit name of an ALI file
4351 ALI_Name : File_Name_Type := No_File;
4352 -- The file name of the ALI file
4354 ALI_Project : Project_Id := No_Project;
4355 -- The project of the ALI file
4358 OK : Boolean := True;
4362 -- For call to Close
4365 Tempdir.Create_Temp_File (Mapping_FD, Mapping_Path);
4366 Record_Temp_File (Project_Tree, Mapping_Path);
4368 if Mapping_FD /= Invalid_FD then
4370 -- Traverse all units
4372 Unit := Units_Htable.Get_First (Project_Tree.Units_HT);
4374 while Unit /= No_Unit_Index loop
4375 if Unit.Name /= No_Name then
4377 -- If there is a body, put it in the mapping
4379 if Unit.File_Names (Impl) /= No_Source
4380 and then Unit.File_Names (Impl).Project /=
4383 Get_Name_String (Unit.Name);
4384 Add_Str_To_Name_Buffer ("%b");
4385 ALI_Unit := Name_Find;
4388 (Unit.File_Names (Impl).Display_File);
4389 ALI_Project := Unit.File_Names (Impl).Project;
4391 -- Otherwise, if there is a spec, put it in the mapping
4393 elsif Unit.File_Names (Spec) /= No_Source
4394 and then Unit.File_Names (Spec).Project /= No_Project
4396 Get_Name_String (Unit.Name);
4397 Add_Str_To_Name_Buffer ("%s");
4398 ALI_Unit := Name_Find;
4401 (Unit.File_Names (Spec).Display_File);
4402 ALI_Project := Unit.File_Names (Spec).Project;
4405 ALI_Name := No_File;
4408 -- If we have something to put in the mapping then do it
4409 -- now. However, if the project is extended, we don't put
4410 -- anything in the mapping file, because we don't know where
4411 -- the ALI file is: it might be in the extended project
4412 -- object directory as well as in the extending project
4413 -- object directory.
4415 if ALI_Name /= No_File
4416 and then ALI_Project.Extended_By = No_Project
4417 and then ALI_Project.Extends = No_Project
4419 -- First check if the ALI file exists. If it does not,
4420 -- do not put the unit in the mapping file.
4423 ALI : constant String := Get_Name_String (ALI_Name);
4426 -- For library projects, use the library directory,
4427 -- for other projects, use the object directory.
4429 if ALI_Project.Library then
4430 Get_Name_String (ALI_Project.Library_Dir.Name);
4433 (ALI_Project.Object_Directory.Name);
4437 Is_Directory_Separator (Name_Buffer (Name_Len))
4439 Add_Char_To_Name_Buffer (Directory_Separator);
4442 Add_Str_To_Name_Buffer (ALI);
4443 Add_Char_To_Name_Buffer (ASCII.LF);
4446 ALI_Path_Name : constant String :=
4447 Name_Buffer (1 .. Name_Len);
4451 (ALI_Path_Name (1 .. ALI_Path_Name'Last - 1))
4453 -- First line is the unit name
4455 Get_Name_String (ALI_Unit);
4456 Add_Char_To_Name_Buffer (ASCII.LF);
4460 Name_Buffer (1)'Address,
4462 OK := Bytes = Name_Len;
4466 -- Second line it the ALI file name
4468 Get_Name_String (ALI_Name);
4469 Add_Char_To_Name_Buffer (ASCII.LF);
4473 Name_Buffer (1)'Address,
4475 OK := (Bytes = Name_Len);
4479 -- Third line it the ALI path name
4484 ALI_Path_Name (1)'Address,
4485 ALI_Path_Name'Length);
4486 OK := (Bytes = ALI_Path_Name'Length);
4488 -- If OK is False, it means we were unable to
4489 -- write a line. No point in continuing with the
4499 Unit := Units_Htable.Get_Next (Project_Tree.Units_HT);
4502 Close (Mapping_FD, Status);
4504 OK := OK and Status;
4506 -- If the creation of the mapping file was successful, we add the
4507 -- switch to the arguments of gnatbind.
4510 Last_Arg := Last_Arg + 1;
4512 new String'("-F=" & Get_Name_String (Mapping_Path));
4515 end Create_Binder_Mapping_File;
4517 -- Start of processing for Gnatmake
4519 -- This body is very long, should be broken down???
4522 Install_Int_Handler (Sigint_Intercepted'Access);
4524 Do_Compile_Step := True;
4525 Do_Bind_Step := True;
4526 Do_Link_Step := True;
4530 Make.Initialize (Project_Node_Tree);
4532 Bind_Shared := No_Shared_Switch'Access;
4533 Link_With_Shared_Libgcc := No_Shared_Libgcc_Switch'Access;
4535 Failed_Links.Set_Last (0);
4536 Successful_Links.Set_Last (0);
4538 -- Special case when switch -B was specified
4540 if Build_Bind_And_Link_Full_Project then
4542 -- When switch -B is specified, there must be a project file
4544 if Main_Project = No_Project then
4545 Make_Failed ("-B cannot be used without a project file");
4547 -- No main program may be specified on the command line
4549 elsif Osint.Number_Of_Files /= 0 then
4550 Make_Failed ("-B cannot be used with a main specified on " &
4551 "the command line");
4553 -- And the project file cannot be a library project file
4555 elsif Main_Project.Library then
4556 Make_Failed ("-B cannot be used for a library project file");
4559 No_Main_Subprogram := True;
4560 Insert_Project_Sources
4561 (The_Project => Main_Project,
4562 All_Projects => Unique_Compile_All_Projects,
4565 -- If there are no sources to compile, we fail
4567 if Osint.Number_Of_Files = 0 then
4568 Make_Failed ("no sources to compile");
4571 -- Specify -n for gnatbind and add the ALI files of all the
4572 -- sources, except the one which is a fake main subprogram: this
4573 -- is the one for the binder generated file and it will be
4574 -- transmitted to gnatlink. These sources are those that are in
4577 Add_Switch ("-n", Binder, And_Save => True);
4579 for J in Q.First .. Q.Last - 1 loop
4582 (Lib_File_Name (Q.Table (J).File)),
4583 Binder, And_Save => True);
4587 elsif Main_Index /= 0 and then Osint.Number_Of_Files > 1 then
4588 Make_Failed ("cannot specify several mains with a multi-unit index");
4590 elsif Main_Project /= No_Project then
4592 -- If the main project file is a library project file, main(s) cannot
4593 -- be specified on the command line.
4595 if Osint.Number_Of_Files /= 0 then
4596 if Main_Project.Library
4597 and then not Unique_Compile
4598 and then ((not Make_Steps) or else Bind_Only or else Link_Only)
4600 Make_Failed ("cannot specify a main program " &
4601 "on the command line for a library project file");
4604 -- Check that each main on the command line is a source of a
4605 -- project file and, if there are several mains, each of them
4606 -- is a source of the same project file.
4611 -- If no mains have been specified on the command line, and we are
4612 -- using a project file, we either find the main(s) in attribute Main
4613 -- of the main project, or we put all the sources of the project file
4617 if Main_Index /= 0 then
4618 Make_Failed ("cannot specify a multi-unit index but no main " &
4619 "on the command line");
4623 Value : String_List_Id := Main_Project.Mains;
4626 -- The attribute Main is an empty list or not specified, or
4627 -- else gnatmake was invoked with the switch "-u".
4629 if Value = Prj.Nil_String or else Unique_Compile then
4631 if (not Make_Steps) or else Compile_Only
4632 or else not Main_Project.Library
4634 -- First make sure that the binder and the linker will
4637 Do_Bind_Step := False;
4638 Do_Link_Step := False;
4640 -- Put all the sources in the queue
4642 No_Main_Subprogram := True;
4643 Insert_Project_Sources
4644 (The_Project => Main_Project,
4645 All_Projects => Unique_Compile_All_Projects,
4648 -- If no sources to compile, then there is nothing to do
4650 if Osint.Number_Of_Files = 0 then
4651 if not Quiet_Output then
4652 Osint.Write_Program_Name;
4653 Write_Line (": no sources to compile");
4656 Delete_All_Temp_Files;
4657 Exit_Program (E_Success);
4662 -- The attribute Main is not an empty list. Put all the main
4663 -- subprograms in the list as if they were specified on the
4664 -- command line. However, if attribute Languages includes a
4665 -- language other than Ada, only include the Ada mains; if
4666 -- there is no Ada main, compile all sources of the project.
4669 Languages : constant Variable_Value :=
4672 Main_Project.Decl.Attributes,
4675 Current : String_List_Id;
4676 Element : String_Element;
4678 Foreign_Language : Boolean := False;
4679 At_Least_One_Main : Boolean := False;
4682 -- First, determine if there is a foreign language in
4683 -- attribute Languages.
4685 if not Languages.Default then
4686 Current := Languages.Values;
4688 while Current /= Nil_String loop
4689 Element := Project_Tree.String_Elements.
4691 Get_Name_String (Element.Value);
4692 To_Lower (Name_Buffer (1 .. Name_Len));
4694 if Name_Buffer (1 .. Name_Len) /= "ada" then
4695 Foreign_Language := True;
4696 exit Look_For_Foreign;
4699 Current := Element.Next;
4700 end loop Look_For_Foreign;
4703 -- Then, find all mains, or if there is a foreign
4704 -- language, all the Ada mains.
4706 while Value /= Prj.Nil_String loop
4708 (Project_Tree.String_Elements.Table (Value).Value);
4710 -- To know if a main is an Ada main, get its project.
4711 -- It should be the project specified on the command
4714 if (not Foreign_Language) or else
4716 (Name_Buffer (1 .. Name_Len),
4721 At_Least_One_Main := True;
4724 (Project_Tree.String_Elements.Table
4727 Project_Tree.String_Elements.Table
4731 Value := Project_Tree.String_Elements.Table
4735 -- If we did not get any main, it means that all mains
4736 -- in attribute Mains are in a foreign language and -B
4737 -- was not specified to gnatmake; so, we fail.
4739 if not At_Least_One_Main then
4741 ("no Ada mains, use -B to build foreign main");
4750 if Verbose_Mode then
4752 Display_Version ("GNATMAKE", "1995");
4755 if Osint.Number_Of_Files = 0 then
4756 if Main_Project /= No_Project
4757 and then Main_Project.Library
4760 and then not Main_Project.Standalone_Library
4762 Make_Failed ("only stand-alone libraries may be bound");
4765 -- Add the default search directories to be able to find libgnat
4767 Osint.Add_Default_Search_Dirs;
4769 -- Get the target parameters, so that the correct binder generated
4770 -- files are generated if OpenVMS is the target.
4773 Targparm.Get_Target_Parameters;
4776 when Unrecoverable_Error =>
4777 Make_Failed ("*** make failed.");
4780 -- And bind and or link the library
4782 MLib.Prj.Build_Library
4783 (For_Project => Main_Project,
4784 In_Tree => Project_Tree,
4785 Gnatbind => Gnatbind.all,
4786 Gnatbind_Path => Gnatbind_Path,
4788 Gcc_Path => Gcc_Path,
4792 Delete_All_Temp_Files;
4793 Exit_Program (E_Success);
4796 -- Call Get_Target_Parameters to ensure that VM_Target and
4797 -- AAMP_On_Target get set before calling Usage.
4799 Targparm.Get_Target_Parameters;
4801 -- Output usage information if no files to compile
4804 Exit_Program (E_Fatal);
4808 -- If -M was specified, behave as if -n was specified
4810 if List_Dependencies then
4811 Do_Not_Execute := True;
4814 -- Note that Osint.M.Next_Main_Source will always return the (possibly
4815 -- abbreviated file) without any directory information.
4817 Main_Source_File := Next_Main_Source;
4819 if Current_File_Index /= No_Index then
4820 Main_Index := Current_File_Index;
4823 Add_Switch ("-I-", Compiler, And_Save => True);
4825 if Main_Project = No_Project then
4826 if Look_In_Primary_Dir then
4830 Normalize_Directory_Name
4831 (Get_Primary_Src_Search_Directory.all).all,
4832 Compiler, Append_Switch => False,
4838 -- If we use a project file, we have already checked that a main
4839 -- specified on the command line with directory information has the
4840 -- path name corresponding to a correct source in the project tree.
4841 -- So, we don't need the directory information to be taken into
4842 -- account by Find_File, and in fact it may lead to take the wrong
4843 -- sources for other compilation units, when there are extending
4846 Look_In_Primary_Dir := False;
4847 Add_Switch ("-I-", Binder, And_Save => True);
4850 -- If the user wants a program without a main subprogram, add the
4851 -- appropriate switch to the binder.
4853 if No_Main_Subprogram then
4854 Add_Switch ("-z", Binder, And_Save => True);
4857 if Main_Project /= No_Project then
4859 if Main_Project.Object_Directory /= No_Path_Information then
4860 -- Change current directory to object directory of main project
4862 Project_Of_Current_Object_Directory := No_Project;
4863 Change_To_Object_Directory (Main_Project);
4866 -- Source file lookups should be cached for efficiency.
4867 -- Source files are not supposed to change.
4869 Osint.Source_File_Data (Cache => True);
4871 -- Find the file name of the (first) main unit
4874 Main_Source_File_Name : constant String :=
4875 Get_Name_String (Main_Source_File);
4876 Main_Unit_File_Name : constant String :=
4877 Prj.Env.File_Name_Of_Library_Unit_Body
4878 (Name => Main_Source_File_Name,
4879 Project => Main_Project,
4880 In_Tree => Project_Tree,
4881 Main_Project_Only =>
4882 not Unique_Compile);
4884 The_Packages : constant Package_Id :=
4885 Main_Project.Decl.Packages;
4887 Builder_Package : constant Prj.Package_Id :=
4889 (Name => Name_Builder,
4890 In_Packages => The_Packages,
4891 In_Tree => Project_Tree);
4893 Binder_Package : constant Prj.Package_Id :=
4895 (Name => Name_Binder,
4896 In_Packages => The_Packages,
4897 In_Tree => Project_Tree);
4899 Linker_Package : constant Prj.Package_Id :=
4901 (Name => Name_Linker,
4902 In_Packages => The_Packages,
4903 In_Tree => Project_Tree);
4905 Default_Switches_Array : Array_Id;
4907 Global_Compilation_Array : Array_Element_Id;
4908 Global_Compilation_Elem : Array_Element;
4909 Global_Compilation_Switches : Variable_Value;
4912 -- We fail if we cannot find the main source file
4914 if Main_Unit_File_Name = "" then
4915 Make_Failed ('"' & Main_Source_File_Name
4916 & """ is not a unit of project "
4917 & Project_File_Name.all & ".");
4919 -- Remove any directory information from the main source file
4923 Pos : Natural := Main_Unit_File_Name'Last;
4927 exit when Pos < Main_Unit_File_Name'First or else
4928 Main_Unit_File_Name (Pos) = Directory_Separator;
4932 Name_Len := Main_Unit_File_Name'Last - Pos;
4934 Name_Buffer (1 .. Name_Len) :=
4936 (Pos + 1 .. Main_Unit_File_Name'Last);
4938 Main_Source_File := Name_Find;
4940 -- We only output the main source file if there is only one
4942 if Verbose_Mode and then Osint.Number_Of_Files = 1 then
4943 Write_Str ("Main source file: """);
4944 Write_Str (Main_Unit_File_Name
4945 (Pos + 1 .. Main_Unit_File_Name'Last));
4951 -- If there is a package Builder in the main project file, add
4952 -- the switches from it.
4954 if Builder_Package /= No_Package then
4956 Global_Compilation_Array := Prj.Util.Value_Of
4957 (Name => Name_Global_Compilation_Switches,
4958 In_Arrays => Project_Tree.Packages.Table
4959 (Builder_Package).Decl.Arrays,
4960 In_Tree => Project_Tree);
4962 Default_Switches_Array :=
4963 Project_Tree.Packages.Table
4964 (Builder_Package).Decl.Arrays;
4966 while Default_Switches_Array /= No_Array and then
4967 Project_Tree.Arrays.Table (Default_Switches_Array).Name /=
4968 Name_Default_Switches
4970 Default_Switches_Array :=
4971 Project_Tree.Arrays.Table (Default_Switches_Array).Next;
4974 if Global_Compilation_Array /= No_Array_Element and then
4975 Default_Switches_Array /= No_Array
4978 ("Default_Switches forbidden in presence of " &
4979 "Global_Compilation_Switches. Use Switches instead.",
4980 Project_Tree.Arrays.Table
4981 (Default_Switches_Array).Location);
4984 ("*** illegal combination of Builder attributes");
4987 -- If there is only one main, we attempt to get the gnatmake
4988 -- switches for this main (if any). If there are no specific
4989 -- switch for this particular main, get the general gnatmake
4990 -- switches (if any).
4992 if Osint.Number_Of_Files = 1 then
4993 if Verbose_Mode then
4994 Write_Str ("Adding gnatmake switches for """);
4995 Write_Str (Main_Unit_File_Name);
5000 (Project_Node_Tree => Project_Node_Tree,
5001 File_Name => Main_Unit_File_Name,
5002 Index => Main_Index,
5003 The_Package => Builder_Package,
5005 Unknown_Switches_To_The_Compiler =>
5006 Global_Compilation_Array = No_Array_Element);
5009 -- If there are several mains, we always get the general
5010 -- gnatmake switches (if any).
5012 -- Warn the user, if necessary, so that he is not surprised
5013 -- that specific switches are not taken into account.
5016 Defaults : constant Variable_Value :=
5020 Attribute_Or_Array_Name =>
5021 Name_Default_Switches,
5024 In_Tree => Project_Tree);
5026 Switches : constant Array_Element_Id :=
5028 (Name => Name_Switches,
5030 Project_Tree.Packages.Table
5031 (Builder_Package).Decl.Arrays,
5032 In_Tree => Project_Tree);
5034 Other_Switches : constant Variable_Value :=
5036 (Name => All_Other_Names,
5038 Attribute_Or_Array_Name
5040 In_Package => Builder_Package,
5041 In_Tree => Project_Tree);
5044 if Other_Switches /= Nil_Variable_Value then
5046 and then Switches /= No_Array_Element
5047 and then Project_Tree.Array_Elements.Table
5048 (Switches).Next /= No_Array_Element
5051 ("Warning: using Builder'Switches(others), "
5052 & "as there are several mains");
5056 (Project_Node_Tree => Project_Node_Tree,
5059 The_Package => Builder_Package,
5061 Unknown_Switches_To_The_Compiler => False);
5063 elsif Defaults /= Nil_Variable_Value then
5065 and then Switches /= No_Array_Element
5068 ("Warning: using Builder'Default_Switches"
5069 & "(""Ada""), as there are several mains");
5073 (Project_Node_Tree => Project_Node_Tree,
5076 The_Package => Builder_Package,
5079 elsif not Quiet_Output
5080 and then Switches /= No_Array_Element
5083 ("Warning: using no switches from package "
5084 & "Builder, as there are several mains");
5089 -- Take into account attribute Global_Compilation_Switches
5094 List : String_List_Id;
5095 Elem : String_Element;
5098 while Global_Compilation_Array /= No_Array_Element loop
5099 Global_Compilation_Elem :=
5100 Project_Tree.Array_Elements.Table
5101 (Global_Compilation_Array);
5103 Get_Name_String (Global_Compilation_Elem.Index);
5104 To_Lower (Name_Buffer (1 .. Name_Len));
5107 if Index = Name_Ada then
5108 Global_Compilation_Switches :=
5109 Global_Compilation_Elem.Value;
5111 if Global_Compilation_Switches /= Nil_Variable_Value
5112 and then not Global_Compilation_Switches.Default
5114 -- We have found attribute
5115 -- Global_Compilation_Switches ("Ada"): put the
5116 -- switches in the appropriate table.
5118 List := Global_Compilation_Switches.Values;
5120 while List /= Nil_String loop
5122 Project_Tree.String_Elements.Table (List);
5124 if Elem.Value /= No_Name then
5126 (Get_Name_String (Elem.Value),
5138 Global_Compilation_Array := Global_Compilation_Elem.Next;
5143 Osint.Add_Default_Search_Dirs;
5145 -- Record the current last switch index for table Binder_Switches
5146 -- and Linker_Switches, so that these tables may be reset before
5147 -- for each main, before adding switches from the project file
5148 -- and from the command line.
5150 Last_Binder_Switch := Binder_Switches.Last;
5151 Last_Linker_Switch := Linker_Switches.Last;
5155 -- Add binder switches from the project file for the first main
5157 if Do_Bind_Step and then Binder_Package /= No_Package then
5158 if Verbose_Mode then
5159 Write_Str ("Adding binder switches for """);
5160 Write_Str (Main_Unit_File_Name);
5165 (Project_Node_Tree => Project_Node_Tree,
5166 File_Name => Main_Unit_File_Name,
5167 Index => Main_Index,
5168 The_Package => Binder_Package,
5172 -- Add linker switches from the project file for the first main
5174 if Do_Link_Step and then Linker_Package /= No_Package then
5175 if Verbose_Mode then
5176 Write_Str ("Adding linker switches for""");
5177 Write_Str (Main_Unit_File_Name);
5182 (Project_Node_Tree => Project_Node_Tree,
5183 File_Name => Main_Unit_File_Name,
5184 Index => Main_Index,
5185 The_Package => Linker_Package,
5191 -- The combination of -f -u and one or several mains on the command line
5194 if Force_Compilations
5195 and then Unique_Compile
5196 and then not Unique_Compile_All_Projects
5197 and then Main_On_Command_Line
5199 Check_Readonly_Files := True;
5200 Must_Compile := True;
5203 if Main_Project /= No_Project
5204 and then not Must_Compile
5205 and then Main_Project.Externally_Built
5208 ("nothing to do for a main project that is externally built");
5211 -- Get the target parameters, which are only needed for a couple of
5212 -- cases in gnatmake. Protect against an exception, such as the case of
5213 -- system.ads missing from the library, and fail gracefully.
5216 Targparm.Get_Target_Parameters;
5218 when Unrecoverable_Error =>
5219 Make_Failed ("*** make failed.");
5222 -- Special processing for VM targets
5224 if Targparm.VM_Target /= No_VM then
5226 -- Set proper processing commands
5228 case Targparm.VM_Target is
5229 when Targparm.JVM_Target =>
5231 -- Do not check for an object file (".o") when compiling to
5232 -- JVM machine since ".class" files are generated instead.
5234 Check_Object_Consistency := False;
5235 Gcc := new String'("jvm-gnatcompile");
5237 when Targparm.CLI_Target =>
5238 Gcc := new String'("dotnet-gnatcompile");
5240 when Targparm.No_VM =>
5241 raise Program_Error;
5245 Display_Commands (not Quiet_Output);
5249 if Main_Project /= No_Project then
5251 -- For all library project, if the library file does not exist, put
5252 -- all the project sources in the queue, and flag the project so that
5253 -- the library is generated.
5255 if not Unique_Compile
5256 and then MLib.Tgt.Support_For_Libraries /= Prj.None
5259 Proj : Project_List;
5262 Proj := Project_Tree.Projects;
5263 while Proj /= null loop
5264 if Proj.Project.Library then
5265 Proj.Project.Need_To_Build_Lib :=
5266 not MLib.Tgt.Library_Exists_For
5267 (Proj.Project, Project_Tree)
5268 and then not Proj.Project.Externally_Built;
5270 if Proj.Project.Need_To_Build_Lib then
5272 -- If there is no object directory, then it will be
5273 -- impossible to build the library. So fail
5277 Proj.Project.Object_Directory = No_Path_Information
5280 ("no object files to build library for project """
5281 & Get_Name_String (Proj.Project.Name)
5283 Proj.Project.Need_To_Build_Lib := False;
5286 if Verbose_Mode then
5288 ("Library file does not exist for project """);
5289 Write_Str (Get_Name_String (Proj.Project.Name));
5293 Insert_Project_Sources
5294 (The_Project => Proj.Project,
5295 All_Projects => False,
5306 -- If a relative path output file has been specified, we add the
5309 for J in reverse 1 .. Saved_Linker_Switches.Last - 1 loop
5310 if Saved_Linker_Switches.Table (J).all = Output_Flag.all then
5312 Exec_File_Name : constant String :=
5313 Saved_Linker_Switches.Table (J + 1).all;
5316 if not Is_Absolute_Path (Exec_File_Name) then
5317 Get_Name_String (Main_Project.Exec_Directory.Name);
5320 Is_Directory_Separator (Name_Buffer (Name_Len))
5322 Add_Char_To_Name_Buffer (Directory_Separator);
5325 Add_Str_To_Name_Buffer (Exec_File_Name);
5326 Saved_Linker_Switches.Table (J + 1) :=
5327 new String'(Name_Buffer (1 .. Name_Len));
5335 -- If we are using a project file, for relative paths we add the
5336 -- current working directory for any relative path on the command
5337 -- line and the project directory, for any relative path in the
5341 Dir_Path : constant String :=
5342 Get_Name_String (Main_Project.Directory.Name);
5344 for J in 1 .. Binder_Switches.Last loop
5345 Test_If_Relative_Path
5346 (Binder_Switches.Table (J),
5347 Parent => Dir_Path, Including_L_Switch => False);
5350 for J in 1 .. Saved_Binder_Switches.Last loop
5351 Test_If_Relative_Path
5352 (Saved_Binder_Switches.Table (J),
5353 Parent => Current_Work_Dir.all, Including_L_Switch => False);
5356 for J in 1 .. Linker_Switches.Last loop
5357 Test_If_Relative_Path
5358 (Linker_Switches.Table (J), Parent => Dir_Path);
5361 for J in 1 .. Saved_Linker_Switches.Last loop
5362 Test_If_Relative_Path
5363 (Saved_Linker_Switches.Table (J),
5364 Parent => Current_Work_Dir.all);
5367 for J in 1 .. Gcc_Switches.Last loop
5368 Test_If_Relative_Path
5369 (Gcc_Switches.Table (J),
5371 Including_Non_Switch => False);
5374 for J in 1 .. Saved_Gcc_Switches.Last loop
5375 Test_If_Relative_Path
5376 (Saved_Gcc_Switches.Table (J),
5377 Parent => Current_Work_Dir.all,
5378 Including_Non_Switch => False);
5383 -- We now put in the Binder_Switches and Linker_Switches tables, the
5384 -- binder and linker switches of the command line that have been put in
5385 -- the Saved_ tables. If a project file was used, then the command line
5386 -- switches will follow the project file switches.
5388 for J in 1 .. Saved_Binder_Switches.Last loop
5390 (Saved_Binder_Switches.Table (J),
5395 for J in 1 .. Saved_Linker_Switches.Last loop
5397 (Saved_Linker_Switches.Table (J),
5402 -- If no project file is used, we just put the gcc switches
5403 -- from the command line in the Gcc_Switches table.
5405 if Main_Project = No_Project then
5406 for J in 1 .. Saved_Gcc_Switches.Last loop
5408 (Saved_Gcc_Switches.Table (J), Compiler, And_Save => False);
5412 -- If there is a project, put the command line gcc switches in the
5413 -- variable The_Saved_Gcc_Switches. They are going to be used later
5414 -- in procedure Compile_Sources.
5416 The_Saved_Gcc_Switches :=
5417 new Argument_List (1 .. Saved_Gcc_Switches.Last + 1);
5419 for J in 1 .. Saved_Gcc_Switches.Last loop
5420 The_Saved_Gcc_Switches (J) := Saved_Gcc_Switches.Table (J);
5423 -- We never use gnat.adc when a project file is used
5425 The_Saved_Gcc_Switches (The_Saved_Gcc_Switches'Last) := No_gnat_adc;
5428 -- If there was a --GCC, --GNATBIND or --GNATLINK switch on the command
5429 -- line, then we have to use it, even if there was another switch in
5430 -- the project file.
5432 if Saved_Gcc /= null then
5436 if Saved_Gnatbind /= null then
5437 Gnatbind := Saved_Gnatbind;
5440 if Saved_Gnatlink /= null then
5441 Gnatlink := Saved_Gnatlink;
5444 Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
5445 Gnatbind_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
5446 Gnatlink_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
5448 -- If we have specified -j switch both from the project file
5449 -- and on the command line, the one from the command line takes
5452 if Saved_Maximum_Processes = 0 then
5453 Saved_Maximum_Processes := Maximum_Processes;
5456 -- Allocate as many temporary mapping file names as the maximum number
5457 -- of compilations processed, for each possible project.
5460 Data : Project_Compilation_Access;
5461 Proj : Project_List := Project_Tree.Projects;
5463 while Proj /= null loop
5464 Data := new Project_Compilation_Data'
5465 (Mapping_File_Names => new Temp_Path_Names
5466 (1 .. Saved_Maximum_Processes),
5467 Last_Mapping_File_Names => 0,
5468 Free_Mapping_File_Indices => new Free_File_Indices
5469 (1 .. Saved_Maximum_Processes),
5470 Last_Free_Indices => 0);
5472 Project_Compilation_Htable.Set
5473 (Project_Compilation, Proj.Project, Data);
5477 Data := new Project_Compilation_Data'
5478 (Mapping_File_Names => new Temp_Path_Names
5479 (1 .. Saved_Maximum_Processes),
5480 Last_Mapping_File_Names => 0,
5481 Free_Mapping_File_Indices => new Free_File_Indices
5482 (1 .. Saved_Maximum_Processes),
5483 Last_Free_Indices => 0);
5485 Project_Compilation_Htable.Set
5486 (Project_Compilation, No_Project, Data);
5489 Bad_Compilation.Init;
5491 -- If project files are used, create the mapping of all the sources, so
5492 -- that the correct paths will be found. Otherwise, if there is a file
5493 -- which is not a source with the same name in a source directory this
5494 -- file may be incorrectly found.
5496 if Main_Project /= No_Project then
5497 Prj.Env.Create_Mapping (Project_Tree);
5500 Current_Main_Index := Main_Index;
5502 -- Here is where the make process is started
5504 -- We do the same process for each main
5506 Multiple_Main_Loop : for N_File in 1 .. Osint.Number_Of_Files loop
5508 -- First, find the executable name and path
5510 Executable := No_File;
5511 Executable_Obsolete := False;
5512 Non_Std_Executable :=
5513 Targparm.Executable_Extension_On_Target /= No_Name;
5515 -- Look inside the linker switches to see if the name of the final
5516 -- executable program was specified.
5518 for J in reverse Linker_Switches.First .. Linker_Switches.Last loop
5519 if Linker_Switches.Table (J).all = Output_Flag.all then
5520 pragma Assert (J < Linker_Switches.Last);
5522 -- We cannot specify a single executable for several main
5525 if Osint.Number_Of_Files > 1 then
5527 ("cannot specify a single executable for several mains");
5531 Add_Str_To_Name_Buffer (Linker_Switches.Table (J + 1).all);
5532 Executable := Name_Enter;
5534 Verbose_Msg (Executable, "final executable");
5538 -- If the name of the final executable program was not specified then
5539 -- construct it from the main input file.
5541 if Executable = No_File then
5542 if Main_Project = No_Project then
5543 Executable := Executable_Name (Strip_Suffix (Main_Source_File));
5546 -- If we are using a project file, we attempt to remove the
5547 -- body (or spec) termination of the main subprogram. We find
5548 -- it the naming scheme of the project file. This avoids
5549 -- generating an executable "main.2" for a main subprogram
5550 -- "main.2.ada", when the body termination is ".2.ada".
5553 Prj.Util.Executable_Of
5554 (Main_Project, Project_Tree, Main_Source_File, Main_Index);
5558 if Main_Project /= No_Project
5559 and then Main_Project.Exec_Directory /= No_Path_Information
5562 Exec_File_Name : constant String :=
5563 Get_Name_String (Executable);
5566 if not Is_Absolute_Path (Exec_File_Name) then
5567 Get_Name_String (Main_Project.Exec_Directory.Display_Name);
5569 if Name_Buffer (Name_Len) /= Directory_Separator then
5570 Add_Char_To_Name_Buffer (Directory_Separator);
5573 Add_Str_To_Name_Buffer (Exec_File_Name);
5574 Executable := Name_Find;
5577 Non_Std_Executable := True;
5581 if Do_Compile_Step then
5582 Recursive_Compilation_Step : declare
5583 Args : Argument_List (1 .. Gcc_Switches.Last);
5585 First_Compiled_File : File_Name_Type;
5586 Youngest_Obj_File : File_Name_Type;
5587 Youngest_Obj_Stamp : Time_Stamp_Type;
5589 Executable_Stamp : Time_Stamp_Type;
5590 -- Executable is the final executable program
5591 -- ??? comment seems unrelated to declaration
5593 Library_Rebuilt : Boolean := False;
5596 for J in 1 .. Gcc_Switches.Last loop
5597 Args (J) := Gcc_Switches.Table (J);
5600 -- Now we invoke Compile_Sources for the current main
5603 (Main_Source => Main_Source_File,
5605 First_Compiled_File => First_Compiled_File,
5606 Most_Recent_Obj_File => Youngest_Obj_File,
5607 Most_Recent_Obj_Stamp => Youngest_Obj_Stamp,
5608 Main_Unit => Is_Main_Unit,
5609 Main_Index => Current_Main_Index,
5610 Compilation_Failures => Compilation_Failures,
5611 Check_Readonly_Files => Check_Readonly_Files,
5612 Do_Not_Execute => Do_Not_Execute,
5613 Force_Compilations => Force_Compilations,
5614 In_Place_Mode => In_Place_Mode,
5615 Keep_Going => Keep_Going,
5616 Initialize_ALI_Data => True,
5617 Max_Process => Saved_Maximum_Processes);
5619 if Verbose_Mode then
5620 Write_Str ("End of compilation");
5624 -- Make sure the queue will be reinitialized for the next round
5626 First_Q_Initialization := True;
5628 Total_Compilation_Failures :=
5629 Total_Compilation_Failures + Compilation_Failures;
5631 if Total_Compilation_Failures /= 0 then
5636 List_Bad_Compilations;
5637 Report_Compilation_Failed;
5641 -- Regenerate libraries, if there are any and if object files
5642 -- have been regenerated.
5644 if Main_Project /= No_Project
5645 and then MLib.Tgt.Support_For_Libraries /= Prj.None
5646 and then (Do_Bind_Step
5647 or Unique_Compile_All_Projects
5648 or not Compile_Only)
5649 and then (Do_Link_Step or else N_File = Osint.Number_Of_Files)
5656 Proj1 : Project_List;
5658 procedure Add_To_Library_Projs (Proj : Project_Id);
5659 -- Add project Project to table Library_Projs in
5660 -- decreasing depth order.
5662 --------------------------
5663 -- Add_To_Library_Projs --
5664 --------------------------
5666 procedure Add_To_Library_Projs (Proj : Project_Id) is
5670 Library_Projs.Increment_Last;
5671 Depth := Proj.Depth;
5673 -- Put the projects in decreasing depth order, so that
5674 -- if libA depends on libB, libB is first in order.
5676 Current := Library_Projs.Last;
5677 while Current > 1 loop
5678 Prj := Library_Projs.Table (Current - 1);
5679 exit when Prj.Depth >= Depth;
5680 Library_Projs.Table (Current) := Prj;
5681 Current := Current - 1;
5684 Library_Projs.Table (Current) := Proj;
5685 end Add_To_Library_Projs;
5687 -- Start of processing for ??? (should name declare block
5688 -- or probably better, break this out as a nested proc).
5691 -- Put in Library_Projs table all library project file
5692 -- ids when the library need to be rebuilt.
5694 Proj1 := Project_Tree.Projects;
5695 while Proj1 /= null loop
5696 if Proj1.Project.Standalone_Library then
5697 Stand_Alone_Libraries := True;
5700 if Proj1.Project.Library then
5701 MLib.Prj.Check_Library
5702 (Proj1.Project, Project_Tree);
5705 if Proj1.Project.Need_To_Build_Lib then
5706 Add_To_Library_Projs (Proj1.Project);
5709 Proj1 := Proj1.Next;
5712 -- Check if importing libraries should be regenerated
5713 -- because at least an imported library will be
5714 -- regenerated or is more recent.
5716 Proj1 := Project_Tree.Projects;
5717 while Proj1 /= null loop
5718 if Proj1.Project.Library
5719 and then Proj1.Project.Library_Kind /= Static
5720 and then not Proj1.Project.Need_To_Build_Lib
5721 and then not Proj1.Project.Externally_Built
5724 List : Project_List;
5726 Rebuild : Boolean := False;
5728 Lib_Timestamp1 : constant Time_Stamp_Type :=
5729 Proj1.Project.Library_TS;
5732 List := Proj1.Project.All_Imported_Projects;
5733 while List /= null loop
5734 Proj2 := List.Project;
5736 if Proj2.Library then
5737 if Proj2.Need_To_Build_Lib
5739 (Lib_Timestamp1 < Proj2.Library_TS)
5750 Proj1.Project.Need_To_Build_Lib := True;
5751 Add_To_Library_Projs (Proj1.Project);
5756 Proj1 := Proj1.Next;
5759 -- Reset the flags Need_To_Build_Lib for the next main,
5760 -- to avoid rebuilding libraries uselessly.
5762 Proj1 := Project_Tree.Projects;
5763 while Proj1 /= null loop
5764 Proj1.Project.Need_To_Build_Lib := False;
5765 Proj1 := Proj1.Next;
5769 -- Build the libraries, if any need to be built
5771 for J in 1 .. Library_Projs.Last loop
5772 Library_Rebuilt := True;
5774 -- If a library is rebuilt, then executables are obsolete
5776 Executable_Obsolete := True;
5778 MLib.Prj.Build_Library
5779 (For_Project => Library_Projs.Table (J),
5780 In_Tree => Project_Tree,
5781 Gnatbind => Gnatbind.all,
5782 Gnatbind_Path => Gnatbind_Path,
5784 Gcc_Path => Gcc_Path);
5788 if List_Dependencies then
5789 if First_Compiled_File /= No_File then
5791 (First_Compiled_File,
5792 "must be recompiled. Can't generate dependence list.");
5797 elsif First_Compiled_File = No_File
5798 and then not Do_Bind_Step
5799 and then not Quiet_Output
5800 and then not Library_Rebuilt
5801 and then Osint.Number_Of_Files = 1
5803 Inform (Msg => "objects up to date.");
5805 elsif Do_Not_Execute
5806 and then First_Compiled_File /= No_File
5808 Write_Name (First_Compiled_File);
5812 -- Stop after compile step if any of:
5814 -- 1) -n (Do_Not_Execute) specified
5816 -- 2) -M (List_Dependencies) specified (also sets
5817 -- Do_Not_Execute above, so this is probably superfluous).
5819 -- 3) -c (Compile_Only) specified, but not -b (Bind_Only)
5821 -- 4) Made unit cannot be a main unit
5824 or List_Dependencies
5826 or not Is_Main_Unit)
5827 and then not No_Main_Subprogram
5828 and then not Build_Bind_And_Link_Full_Project)
5829 or else Unique_Compile
5831 if Osint.Number_Of_Files = 1 then
5832 exit Multiple_Main_Loop;
5839 -- If the objects were up-to-date check if the executable file
5840 -- is also up-to-date. For now always bind and link on the JVM
5841 -- since there is currently no simple way to check whether
5842 -- objects are up-to-date.
5844 if Targparm.VM_Target /= JVM_Target
5845 and then First_Compiled_File = No_File
5847 Executable_Stamp := File_Stamp (Executable);
5849 if not Executable_Obsolete then
5850 Executable_Obsolete :=
5851 Youngest_Obj_Stamp > Executable_Stamp;
5854 if not Executable_Obsolete then
5855 for Index in reverse 1 .. Dependencies.Last loop
5857 (Dependencies.Table (Index).Depends_On)
5859 Enter_Into_Obsoleted
5860 (Dependencies.Table (Index).This);
5864 Executable_Obsolete := Is_In_Obsoleted (Main_Source_File);
5868 if not Executable_Obsolete then
5870 -- If no Ada object files obsolete the executable, check
5871 -- for younger or missing linker files.
5873 Check_Linker_Options
5876 Youngest_Obj_Stamp);
5878 Executable_Obsolete := Youngest_Obj_File /= No_File;
5881 -- Check if any library file is more recent than the
5882 -- executable: there may be an externally built library
5883 -- file that has been modified.
5885 if not Executable_Obsolete
5886 and then Main_Project /= No_Project
5889 Proj1 : Project_List;
5892 Proj1 := Project_Tree.Projects;
5893 while Proj1 /= null loop
5894 if Proj1.Project.Library
5896 Proj1.Project.Library_TS > Executable_Stamp
5898 Executable_Obsolete := True;
5899 Youngest_Obj_Stamp := Proj1.Project.Library_TS;
5901 Add_Str_To_Name_Buffer ("library ");
5902 Add_Str_To_Name_Buffer
5903 (Get_Name_String (Proj1.Project.Library_Name));
5904 Youngest_Obj_File := Name_Find;
5908 Proj1 := Proj1.Next;
5913 -- Return if the executable is up to date and otherwise
5914 -- motivate the relink/rebind.
5916 if not Executable_Obsolete then
5917 if not Quiet_Output then
5918 Inform (Executable, "up to date.");
5921 if Osint.Number_Of_Files = 1 then
5922 exit Multiple_Main_Loop;
5929 if Executable_Stamp (1) = ' ' then
5930 if not No_Main_Subprogram then
5931 Verbose_Msg (Executable, "missing.", Prefix => " ");
5934 elsif Youngest_Obj_Stamp (1) = ' ' then
5936 (Youngest_Obj_File, "missing.", Prefix => " ");
5938 elsif Youngest_Obj_Stamp > Executable_Stamp then
5941 "(" & String (Youngest_Obj_Stamp) & ") newer than",
5943 "(" & String (Executable_Stamp) & ")");
5947 (Executable, "needs to be rebuilt", Prefix => " ");
5951 end Recursive_Compilation_Step;
5954 -- For binding and linking, we need to be in the object directory of
5955 -- the main project.
5957 if Main_Project /= No_Project then
5958 Change_To_Object_Directory (Main_Project);
5961 -- If we are here, it means that we need to rebuilt the current main,
5962 -- so we set Executable_Obsolete to True to make sure that subsequent
5963 -- mains will be rebuilt.
5965 Main_ALI_In_Place_Mode_Step : declare
5966 ALI_File : File_Name_Type;
5967 Src_File : File_Name_Type;
5970 Src_File := Strip_Directory (Main_Source_File);
5971 ALI_File := Lib_File_Name (Src_File, Current_Main_Index);
5972 Main_ALI_File := Full_Lib_File_Name (ALI_File);
5974 -- When In_Place_Mode, the library file can be located in the
5975 -- Main_Source_File directory which may not be present in the
5976 -- library path. If it is not present then use the corresponding
5977 -- library file name.
5979 if Main_ALI_File = No_File and then In_Place_Mode then
5980 Get_Name_String (Get_Directory (Full_Source_Name (Src_File)));
5981 Get_Name_String_And_Append (ALI_File);
5982 Main_ALI_File := Name_Find;
5983 Main_ALI_File := Full_Lib_File_Name (Main_ALI_File);
5986 if Main_ALI_File = No_File then
5987 Make_Failed ("could not find the main ALI file");
5989 end Main_ALI_In_Place_Mode_Step;
5991 if Do_Bind_Step then
5993 Args : Argument_List
5994 (Binder_Switches.First .. Binder_Switches.Last + 2);
5995 -- The arguments for the invocation of gnatbind
5997 Last_Arg : Natural := Binder_Switches.Last;
5998 -- Index of the last argument in Args
6000 Shared_Libs : Boolean := False;
6001 -- Set to True when there are shared library project files or
6002 -- when gnatbind is invoked with -shared.
6004 Proj : Project_List;
6007 -- Check if there are shared libraries, so that gnatbind is
6008 -- called with -shared. Check also if gnatbind is called with
6009 -- -shared, so that gnatlink is called with -shared-libgcc
6010 -- ensuring that the shared version of libgcc will be used.
6012 if Main_Project /= No_Project
6013 and then MLib.Tgt.Support_For_Libraries /= Prj.None
6015 Proj := Project_Tree.Projects;
6016 while Proj /= null loop
6017 if Proj.Project.Library
6018 and then Proj.Project.Library_Kind /= Static
6020 Shared_Libs := True;
6021 Bind_Shared := Shared_Switch'Access;
6028 -- Check now for switch -shared
6030 if not Shared_Libs then
6031 for J in Binder_Switches.First .. Last_Arg loop
6032 if Binder_Switches.Table (J).all = "-shared" then
6033 Shared_Libs := True;
6039 -- If shared libraries present, invoke gnatlink with
6043 Link_With_Shared_Libgcc := Shared_Libgcc_Switch'Access;
6046 -- Get all the binder switches
6048 for J in Binder_Switches.First .. Last_Arg loop
6049 Args (J) := Binder_Switches.Table (J);
6052 if Stand_Alone_Libraries then
6053 Last_Arg := Last_Arg + 1;
6054 Args (Last_Arg) := Force_Elab_Flags_String'Access;
6057 if Main_Project /= No_Project then
6059 -- Put all the source directories in ADA_INCLUDE_PATH,
6060 -- and all the object directories in ADA_OBJECTS_PATH,
6061 -- except those of library projects.
6063 Prj.Env.Set_Ada_Paths
6064 (Main_Project, Project_Tree, Use_Include_Path_File);
6066 -- If switch -C was specified, create a binder mapping file
6068 if Create_Mapping_File then
6069 Create_Binder_Mapping_File (Args, Last_Arg);
6075 Bind (Main_ALI_File,
6076 Bind_Shared.all & Args (Args'First .. Last_Arg));
6081 -- Delete the temporary mapping file, if one was created.
6083 if Mapping_Path /= No_Path then
6084 Delete_Temporary_File (Project_Tree, Mapping_Path);
6087 -- And reraise the exception
6092 -- If -dn was not specified, delete the temporary mapping file,
6093 -- if one was created.
6095 if Mapping_Path /= No_Path then
6096 Delete_Temporary_File (Project_Tree, Mapping_Path);
6101 if Do_Link_Step then
6103 Linker_Switches_Last : constant Integer := Linker_Switches.Last;
6104 Path_Option : constant String_Access :=
6105 MLib.Linker_Library_Path_Option;
6106 Libraries_Present : Boolean := False;
6110 Proj1 : Project_List;
6113 if not Run_Path_Option then
6114 Linker_Switches.Increment_Last;
6115 Linker_Switches.Table (Linker_Switches.Last) :=
6119 if Main_Project /= No_Project then
6120 Library_Paths.Set_Last (0);
6123 if MLib.Tgt.Support_For_Libraries /= Prj.None then
6125 -- Check for library projects
6127 Proj1 := Project_Tree.Projects;
6128 while Proj1 /= null loop
6129 if Proj1.Project /= Main_Project
6130 and then Proj1.Project.Library
6132 -- Add this project to table Library_Projs
6134 Libraries_Present := True;
6135 Depth := Proj1.Project.Depth;
6136 Library_Projs.Increment_Last;
6137 Current := Library_Projs.Last;
6139 -- Any project with a greater depth should be
6140 -- after this project in the list.
6142 while Current > 1 loop
6143 Proj2 := Library_Projs.Table (Current - 1);
6144 exit when Proj2.Depth <= Depth;
6145 Library_Projs.Table (Current) := Proj2;
6146 Current := Current - 1;
6149 Library_Projs.Table (Current) := Proj1.Project;
6151 -- If it is not a static library and path option
6152 -- is set, add it to the Library_Paths table.
6154 if Proj1.Project.Library_Kind /= Static
6155 and then Path_Option /= null
6157 Library_Paths.Increment_Last;
6158 Library_Paths.Table (Library_Paths.Last) :=
6161 (Proj1.Project.Library_Dir.Display_Name));
6165 Proj1 := Proj1.Next;
6168 for Index in 1 .. Library_Projs.Last loop
6170 -- Add the -L switch
6172 Linker_Switches.Increment_Last;
6173 Linker_Switches.Table (Linker_Switches.Last) :=
6176 (Library_Projs.Table (Index).
6177 Library_Dir.Display_Name));
6179 -- Add the -l switch
6181 Linker_Switches.Increment_Last;
6182 Linker_Switches.Table (Linker_Switches.Last) :=
6185 (Library_Projs.Table (Index).
6190 if Libraries_Present then
6192 -- If Path_Option is not null, create the switch
6193 -- ("-Wl,-rpath," or equivalent) with all the non static
6194 -- library dirs plus the standard GNAT library dir.
6195 -- We do that only if Run_Path_Option is True
6196 -- (not disabled by -R switch).
6198 if Run_Path_Option and then Path_Option /= null then
6200 Option : String_Access;
6201 Length : Natural := Path_Option'Length;
6205 if MLib.Separate_Run_Path_Options then
6207 -- We are going to create one switch of the form
6208 -- "-Wl,-rpath,dir_N" for each directory to
6211 -- One switch for each library directory
6214 Library_Paths.First .. Library_Paths.Last
6216 Linker_Switches.Increment_Last;
6217 Linker_Switches.Table
6218 (Linker_Switches.Last) := new String'
6220 Library_Paths.Table (Index).all);
6223 -- One switch for the standard GNAT library dir
6225 Linker_Switches.Increment_Last;
6226 Linker_Switches.Table
6227 (Linker_Switches.Last) := new String'
6228 (Path_Option.all & MLib.Utl.Lib_Directory);
6231 -- We are going to create one switch of the form
6232 -- "-Wl,-rpath,dir_1:dir_2:dir_3"
6235 Library_Paths.First .. Library_Paths.Last
6237 -- Add the length of the library dir plus one
6238 -- for the directory separator.
6242 Library_Paths.Table (Index)'Length + 1;
6245 -- Finally, add the length of the standard GNAT
6248 Length := Length + MLib.Utl.Lib_Directory'Length;
6249 Option := new String (1 .. Length);
6250 Option (1 .. Path_Option'Length) :=
6252 Current := Path_Option'Length;
6254 -- Put each library dir followed by a dir
6258 Library_Paths.First .. Library_Paths.Last
6263 Library_Paths.Table (Index)'Length) :=
6264 Library_Paths.Table (Index).all;
6267 Library_Paths.Table (Index)'Length + 1;
6268 Option (Current) := Path_Separator;
6271 -- Finally put the standard GNAT library dir
6275 Current + MLib.Utl.Lib_Directory'Length) :=
6276 MLib.Utl.Lib_Directory;
6278 -- And add the switch to the linker switches
6280 Linker_Switches.Increment_Last;
6281 Linker_Switches.Table (Linker_Switches.Last) :=
6289 -- Put the object directories in ADA_OBJECTS_PATH
6291 Prj.Env.Set_Ada_Paths
6294 Including_Libraries => False,
6295 Include_Path => False);
6297 -- Check for attributes Linker'Linker_Options in projects
6298 -- other than the main project
6301 Linker_Options : constant String_List :=
6302 Linker_Options_Switches
6303 (Main_Project, Project_Tree);
6305 for Option in Linker_Options'Range loop
6306 Linker_Switches.Increment_Last;
6307 Linker_Switches.Table (Linker_Switches.Last) :=
6308 Linker_Options (Option);
6314 Args : Argument_List
6315 (Linker_Switches.First .. Linker_Switches.Last + 2);
6317 Last_Arg : Integer := Linker_Switches.First - 1;
6318 Skip : Boolean := False;
6321 -- Get all the linker switches
6323 for J in Linker_Switches.First .. Linker_Switches.Last loop
6327 elsif Non_Std_Executable
6328 and then Linker_Switches.Table (J).all = "-o"
6332 -- Here we capture and duplicate the linker argument. We
6333 -- need to do the duplication since the arguments will
6334 -- get normalized. Not doing so will result in calling
6335 -- normalized two times for the same set of arguments if
6336 -- gnatmake is passed multiple mains. This can result in
6337 -- the wrong argument being passed to the linker.
6340 Last_Arg := Last_Arg + 1;
6342 new String'(Linker_Switches.Table (J).all);
6346 -- If need be, add the -o switch
6348 if Non_Std_Executable then
6349 Last_Arg := Last_Arg + 1;
6350 Args (Last_Arg) := new String'("-o");
6351 Last_Arg := Last_Arg + 1;
6353 new String'(Get_Name_String (Executable));
6356 -- And invoke the linker
6359 Success : Boolean := False;
6361 Link (Main_ALI_File,
6362 Link_With_Shared_Libgcc.all &
6363 Args (Args'First .. Last_Arg),
6367 Successful_Links.Increment_Last;
6368 Successful_Links.Table (Successful_Links.Last) :=
6371 elsif Osint.Number_Of_Files = 1
6372 or else not Keep_Going
6374 Make_Failed ("*** link failed.");
6378 Write_Line ("*** link failed");
6380 if Commands_To_Stdout then
6381 Set_Standard_Output;
6384 Failed_Links.Increment_Last;
6385 Failed_Links.Table (Failed_Links.Last) :=
6391 Linker_Switches.Set_Last (Linker_Switches_Last);
6395 -- We go to here when we skip the bind and link steps
6399 -- We go to the next main, if we did not process the last one
6401 if N_File < Osint.Number_Of_Files then
6402 Main_Source_File := Next_Main_Source;
6404 if Current_File_Index /= No_Index then
6405 Main_Index := Current_File_Index;
6408 if Main_Project /= No_Project then
6410 -- Find the file name of the main unit
6413 Main_Source_File_Name : constant String :=
6414 Get_Name_String (Main_Source_File);
6416 Main_Unit_File_Name : constant String :=
6418 File_Name_Of_Library_Unit_Body
6419 (Name => Main_Source_File_Name,
6420 Project => Main_Project,
6421 In_Tree => Project_Tree,
6422 Main_Project_Only =>
6423 not Unique_Compile);
6425 The_Packages : constant Package_Id :=
6426 Main_Project.Decl.Packages;
6428 Binder_Package : constant Prj.Package_Id :=
6430 (Name => Name_Binder,
6431 In_Packages => The_Packages,
6432 In_Tree => Project_Tree);
6434 Linker_Package : constant Prj.Package_Id :=
6436 (Name => Name_Linker,
6437 In_Packages => The_Packages,
6438 In_Tree => Project_Tree);
6441 -- We fail if we cannot find the main source file
6442 -- as an immediate source of the main project file.
6444 if Main_Unit_File_Name = "" then
6445 Make_Failed ('"' & Main_Source_File_Name
6446 & """ is not a unit of project "
6447 & Project_File_Name.all & ".");
6450 -- Remove any directory information from the main
6451 -- source file name.
6454 Pos : Natural := Main_Unit_File_Name'Last;
6458 exit when Pos < Main_Unit_File_Name'First
6460 Main_Unit_File_Name (Pos) = Directory_Separator;
6464 Name_Len := Main_Unit_File_Name'Last - Pos;
6466 Name_Buffer (1 .. Name_Len) :=
6468 (Pos + 1 .. Main_Unit_File_Name'Last);
6470 Main_Source_File := Name_Find;
6474 -- We now deal with the binder and linker switches.
6475 -- If no project file is used, there is nothing to do
6476 -- because the binder and linker switches are the same
6479 -- Reset the tables Binder_Switches and Linker_Switches
6481 Binder_Switches.Set_Last (Last_Binder_Switch);
6482 Linker_Switches.Set_Last (Last_Linker_Switch);
6484 -- Add binder switches from the project file for this main,
6487 if Do_Bind_Step and then Binder_Package /= No_Package then
6488 if Verbose_Mode then
6489 Write_Str ("Adding binder switches for """);
6490 Write_Str (Main_Unit_File_Name);
6495 (Project_Node_Tree => Project_Node_Tree,
6496 File_Name => Main_Unit_File_Name,
6497 Index => Main_Index,
6498 The_Package => Binder_Package,
6502 -- Add linker switches from the project file for this main,
6505 if Do_Link_Step and then Linker_Package /= No_Package then
6506 if Verbose_Mode then
6507 Write_Str ("Adding linker switches for""");
6508 Write_Str (Main_Unit_File_Name);
6513 (Project_Node_Tree => Project_Node_Tree,
6514 File_Name => Main_Unit_File_Name,
6515 Index => Main_Index,
6516 The_Package => Linker_Package,
6520 -- As we are using a project file, for relative paths we add
6521 -- the current working directory for any relative path on
6522 -- the command line and the project directory, for any
6523 -- relative path in the project file.
6526 Dir_Path : constant String :=
6528 (Main_Project.Directory.Name);
6532 J in Last_Binder_Switch + 1 .. Binder_Switches.Last
6534 Test_If_Relative_Path
6535 (Binder_Switches.Table (J),
6536 Parent => Dir_Path, Including_L_Switch => False);
6540 J in Last_Linker_Switch + 1 .. Linker_Switches.Last
6542 Test_If_Relative_Path
6543 (Linker_Switches.Table (J), Parent => Dir_Path);
6547 -- We now put in the Binder_Switches and Linker_Switches
6548 -- tables, the binder and linker switches of the command
6549 -- line that have been put in the Saved_ tables.
6550 -- These switches will follow the project file switches.
6552 for J in 1 .. Saved_Binder_Switches.Last loop
6554 (Saved_Binder_Switches.Table (J),
6559 for J in 1 .. Saved_Linker_Switches.Last loop
6561 (Saved_Linker_Switches.Table (J),
6569 -- Remove all marks to be sure to check sources for all executables,
6570 -- as the switches may be different and -s may be in use.
6573 end loop Multiple_Main_Loop;
6575 if Failed_Links.Last > 0 then
6576 for Index in 1 .. Successful_Links.Last loop
6577 Write_Str ("Linking of """);
6578 Write_Str (Get_Name_String (Successful_Links.Table (Index)));
6579 Write_Line (""" succeeded.");
6584 for Index in 1 .. Failed_Links.Last loop
6585 Write_Str ("Linking of """);
6586 Write_Str (Get_Name_String (Failed_Links.Table (Index)));
6587 Write_Line (""" failed.");
6590 if Commands_To_Stdout then
6591 Set_Standard_Output;
6594 if Total_Compilation_Failures = 0 then
6595 Report_Compilation_Failed;
6599 if Total_Compilation_Failures /= 0 then
6600 List_Bad_Compilations;
6601 Report_Compilation_Failed;
6604 -- Delete the temporary mapping file that was created if we are
6605 -- using project files.
6607 Delete_All_Temp_Files;
6612 Write_Line (Exception_Information (X));
6613 Make_Failed ("INTERNAL ERROR. Please report.");
6620 function Hash (F : File_Name_Type) return Header_Num is
6622 return Header_Num (1 + F mod Max_Header);
6625 --------------------
6626 -- In_Ada_Lib_Dir --
6627 --------------------
6629 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean is
6630 D : constant File_Name_Type := Get_Directory (File);
6631 B : constant Byte := Get_Name_Table_Byte (D);
6633 return (B and Ada_Lib_Dir) /= 0;
6636 -----------------------
6637 -- Init_Mapping_File --
6638 -----------------------
6640 procedure Init_Mapping_File
6641 (Project : Project_Id;
6642 Data : in out Project_Compilation_Data;
6643 File_Index : in out Natural)
6645 FD : File_Descriptor;
6647 -- For call to Close
6650 -- Increase the index of the last mapping file for this project
6652 Data.Last_Mapping_File_Names := Data.Last_Mapping_File_Names + 1;
6654 -- If there is a project file, call Create_Mapping_File with
6657 if Project /= No_Project then
6658 Prj.Env.Create_Mapping_File
6660 In_Tree => Project_Tree,
6661 Language => Name_Ada,
6662 Name => Data.Mapping_File_Names
6663 (Data.Last_Mapping_File_Names));
6665 -- Otherwise, just create an empty file
6668 Tempdir.Create_Temp_File
6670 Data.Mapping_File_Names (Data.Last_Mapping_File_Names));
6672 if FD = Invalid_FD then
6673 Make_Failed ("disk full");
6678 Data.Mapping_File_Names (Data.Last_Mapping_File_Names));
6684 Make_Failed ("disk full");
6688 -- And return the index of the newly created file
6690 File_Index := Data.Last_Mapping_File_Names;
6691 end Init_Mapping_File;
6699 First_Q_Initialization := False;
6701 Q.Set_Last (Q.First);
6708 procedure Initialize (Project_Node_Tree : out Project_Node_Tree_Ref) is
6710 procedure Check_Version_And_Help is
6711 new Check_Version_And_Help_G (Makeusg);
6713 -- Start of processing for Initialize
6716 -- Prepare the project's tree, since this is used to hold external
6717 -- references, project path and other attributes that can be impacted by
6718 -- the command line switches
6720 Project_Node_Tree := new Project_Node_Tree_Data;
6721 Prj.Tree.Initialize (Project_Node_Tree);
6723 -- Override default initialization of Check_Object_Consistency since
6724 -- this is normally False for GNATBIND, but is True for GNATMAKE since
6725 -- we do not need to check source consistency again once GNATMAKE has
6726 -- looked at the sources to check.
6728 Check_Object_Consistency := True;
6730 -- Package initializations. The order of calls is important here
6732 Output.Set_Standard_Error;
6735 Binder_Switches.Init;
6736 Linker_Switches.Init;
6743 Prj.Initialize (Project_Tree);
6747 RTS_Specified := null;
6752 -- Add the directory where gnatmake is invoked in front of the path,
6753 -- if gnatmake is invoked from a bin directory or with directory
6754 -- information. Only do this if the platform is not VMS, where the
6755 -- notion of path does not really exist.
6759 Prefix : constant String := Executable_Prefix_Path;
6760 Command : constant String := Command_Name;
6763 if Prefix'Length > 0 then
6765 PATH : constant String :=
6766 Prefix & Directory_Separator & "bin" &
6768 Getenv ("PATH").all;
6770 Setenv ("PATH", PATH);
6774 for Index in reverse Command'Range loop
6775 if Command (Index) = Directory_Separator then
6777 Absolute_Dir : constant String :=
6779 (Command (Command'First .. Index));
6780 PATH : constant String :=
6783 Getenv ("PATH").all;
6785 Setenv ("PATH", PATH);
6795 -- Scan the switches and arguments
6797 -- First, scan to detect --version and/or --help
6799 Check_Version_And_Help ("GNATMAKE", "1995");
6801 -- Scan again the switch and arguments, now that we are sure that they
6802 -- do not include --version or --help.
6804 Scan_Args : for Next_Arg in 1 .. Argument_Count loop
6806 (Project_Node_Tree, Argument (Next_Arg), And_Save => True);
6809 if N_M_Switch > 0 and RTS_Specified = null then
6810 Process_Multilib (Project_Node_Tree);
6813 if Commands_To_Stdout then
6814 Set_Standard_Output;
6817 if Usage_Requested then
6821 -- Test for trailing -P switch
6823 if Project_File_Name_Present and then Project_File_Name = null then
6824 Make_Failed ("project file name missing after -P");
6826 -- Test for trailing -o switch
6828 elsif Output_File_Name_Present
6829 and then not Output_File_Name_Seen
6831 Make_Failed ("output file name missing after -o");
6833 -- Test for trailing -D switch
6835 elsif Object_Directory_Present
6836 and then not Object_Directory_Seen then
6837 Make_Failed ("object directory missing after -D");
6840 -- Test for simultaneity of -i and -D
6842 if Object_Directory_Path /= null and then In_Place_Mode then
6843 Make_Failed ("-i and -D cannot be used simultaneously");
6846 -- Deal with -C= switch
6848 if Gnatmake_Mapping_File /= null then
6850 -- First, check compatibility with other switches
6852 if Project_File_Name /= null then
6853 Make_Failed ("-C= switch is not compatible with -P switch");
6855 elsif Saved_Maximum_Processes > 1 then
6856 Make_Failed ("-C= switch is not compatible with -jnnn switch");
6859 Fmap.Initialize (Gnatmake_Mapping_File.all);
6861 ("-gnatem=" & Gnatmake_Mapping_File.all,
6866 if Project_File_Name /= null then
6868 -- A project file was specified by a -P switch
6870 if Verbose_Mode then
6872 Write_Str ("Parsing project file """);
6873 Write_Str (Project_File_Name.all);
6878 -- Avoid looking in the current directory for ALI files
6880 -- Look_In_Primary_Dir := False;
6882 -- Set the project parsing verbosity to whatever was specified
6883 -- by a possible -vP switch.
6885 Prj.Pars.Set_Verbosity (To => Current_Verbosity);
6887 -- Parse the project file.
6888 -- If there is an error, Main_Project will still be No_Project.
6891 (Project => Main_Project,
6892 In_Tree => Project_Tree,
6893 Project_File_Name => Project_File_Name.all,
6894 Packages_To_Check => Packages_To_Check_By_Gnatmake,
6895 Flags => Gnatmake_Flags,
6896 In_Node_Tree => Project_Node_Tree);
6898 -- The parsing of project files may have changed the current output
6900 if Commands_To_Stdout then
6901 Set_Standard_Output;
6906 if Main_Project = No_Project then
6908 ("""" & Project_File_Name.all & """ processing failed");
6911 Create_Mapping_File := True;
6913 if Verbose_Mode then
6915 Write_Str ("Parsing of project file """);
6916 Write_Str (Project_File_Name.all);
6917 Write_Str (""" is finished.");
6921 -- We add the source directories and the object directories to the
6923 -- ??? Why do we need these search directories, we already know the
6924 -- locations from parsing the project, except for the runtime which
6925 -- has its own directories anyway
6927 Add_Source_Directories (Main_Project, Project_Tree);
6928 Add_Object_Directories (Main_Project);
6930 Recursive_Compute_Depth (Main_Project);
6931 Compute_All_Imported_Projects (Project_Tree);
6935 Osint.Add_Default_Search_Dirs;
6937 -- Source file lookups should be cached for efficiency. Source files
6938 -- are not supposed to change. However, we do that now only if no
6939 -- project file is used; if a project file is used, we do it just
6940 -- after changing the directory to the object directory.
6942 Osint.Source_File_Data (Cache => True);
6944 -- Read gnat.adc file to initialize Fname.UF
6946 Fname.UF.Initialize;
6949 Fname.SF.Read_Source_File_Name_Pragmas;
6952 when Err : SFN_Scan.Syntax_Error_In_GNAT_ADC =>
6953 Make_Failed (Exception_Message (Err));
6957 -- Make sure no project object directory is recorded
6959 Project_Of_Current_Object_Directory := No_Project;
6963 ----------------------------
6964 -- Insert_Project_Sources --
6965 ----------------------------
6967 procedure Insert_Project_Sources
6968 (The_Project : Project_Id;
6969 All_Projects : Boolean;
6972 Put_In_Q : Boolean := Into_Q;
6974 Sfile : File_Name_Type;
6977 Extending : constant Boolean := The_Project.Extends /= No_Project;
6979 function Check_Project (P : Project_Id) return Boolean;
6980 -- Returns True if P is The_Project or a project extended by The_Project
6986 function Check_Project (P : Project_Id) return Boolean is
6988 if All_Projects or else P = The_Project then
6991 elsif Extending then
6996 Proj := The_Project;
6997 while Proj /= null loop
6998 if P = Proj.Extends then
7002 Proj := Proj.Extends;
7010 -- Start of processing for Insert_Project_Sources
7013 -- For all the sources in the project files,
7015 Unit := Units_Htable.Get_First (Project_Tree.Units_HT);
7016 while Unit /= null loop
7020 -- If there is a source for the body, and the body has not been
7023 if Unit.File_Names (Impl) /= null
7024 and then not Unit.File_Names (Impl).Locally_Removed
7026 -- And it is a source for the specified project
7028 if Check_Project (Unit.File_Names (Impl).Project) then
7030 -- If we don't have a spec, we cannot consider the source
7031 -- if it is a subunit.
7033 if Unit.File_Names (Spec) = null then
7035 Src_Ind : Source_File_Index;
7037 -- Here we are cheating a little bit: we don't want to
7038 -- use Sinput.L, because it depends on the GNAT tree
7039 -- (Atree, Sinfo, ...). So, we pretend that it is a
7040 -- project file, and we use Sinput.P.
7042 -- Source_File_Is_Subunit is just scanning through the
7043 -- file until it finds one of the reserved words
7044 -- separate, procedure, function, generic or package.
7045 -- Fortunately, these Ada reserved words are also
7046 -- reserved for project files.
7049 Src_Ind := Sinput.P.Load_Project_File
7051 (Unit.File_Names (Impl).Path.Name));
7053 -- If it is a subunit, discard it
7055 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
7059 Sfile := Unit.File_Names (Impl).Display_File;
7060 Index := Unit.File_Names (Impl).Index;
7065 Sfile := Unit.File_Names (Impl).Display_File;
7066 Index := Unit.File_Names (Impl).Index;
7070 elsif Unit.File_Names (Spec) /= null
7071 and then not Unit.File_Names (Spec).Locally_Removed
7072 and then Check_Project (Unit.File_Names (Spec).Project)
7074 -- If there is no source for the body, but there is one for the
7075 -- spec which has not been locally removed, then we take this one.
7077 Sfile := Unit.File_Names (Spec).Display_File;
7078 Index := Unit.File_Names (Spec).Index;
7081 -- If Put_In_Q is True, we insert into the Q
7085 -- For the first source inserted into the Q, we need to initialize
7086 -- the Q, but not for the subsequent sources.
7088 if First_Q_Initialization then
7092 -- And of course, only insert in the Q if the source is not marked
7094 if Sfile /= No_File and then not Is_Marked (Sfile, Index) then
7095 if Verbose_Mode then
7096 Write_Str ("Adding """);
7097 Write_Str (Get_Name_String (Sfile));
7098 Write_Line (""" to the queue");
7101 Insert_Q (Sfile, Index => Index);
7102 Mark (Sfile, Index);
7105 elsif Sfile /= No_File then
7107 -- If Put_In_Q is False, we add the source as if it were specified
7108 -- on the command line, and we set Put_In_Q to True, so that the
7109 -- following sources will be put directly in the queue. This will
7110 -- allow parallel compilation processes if -jx switch is used.
7112 if Verbose_Mode then
7113 Write_Str ("Adding """);
7114 Write_Str (Get_Name_String (Sfile));
7115 Write_Line (""" as if on the command line");
7118 Osint.Add_File (Get_Name_String (Sfile), Index);
7121 -- As we may look into the Q later, ensure the Q has been
7122 -- initialized to avoid errors.
7124 if First_Q_Initialization then
7129 Unit := Units_Htable.Get_Next (Project_Tree.Units_HT);
7131 end Insert_Project_Sources;
7138 (Source_File : File_Name_Type;
7139 Source_Unit : Unit_Name_Type := No_Unit_Name;
7143 if Debug.Debug_Flag_Q then
7144 Write_Str (" Q := Q + [ ");
7145 Write_Name (Source_File);
7157 (File => Source_File,
7158 Unit => Source_Unit,
7163 ---------------------
7164 -- Is_In_Obsoleted --
7165 ---------------------
7167 function Is_In_Obsoleted (F : File_Name_Type) return Boolean is
7174 Name : constant String := Get_Name_String (F);
7176 F2 : File_Name_Type;
7180 while First > Name'First
7181 and then Name (First - 1) /= Directory_Separator
7182 and then Name (First - 1) /= '/'
7187 if First /= Name'First then
7189 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
7196 return Obsoleted.Get (F2);
7199 end Is_In_Obsoleted;
7201 ----------------------------
7202 -- Is_In_Object_Directory --
7203 ----------------------------
7205 function Is_In_Object_Directory
7206 (Source_File : File_Name_Type;
7207 Full_Lib_File : File_Name_Type) return Boolean
7210 -- There is something to check only when using project files. Otherwise,
7211 -- this function returns True (last line of the function).
7213 if Main_Project /= No_Project then
7215 Source_File_Name : constant String :=
7216 Get_Name_String (Source_File);
7217 Saved_Verbosity : constant Verbosity := Current_Verbosity;
7218 Project : Project_Id := No_Project;
7220 Path_Name : Path_Name_Type := No_Path;
7221 pragma Warnings (Off, Path_Name);
7224 -- Call Get_Reference to know the ultimate extending project of
7225 -- the source. Call it with verbosity default to avoid verbose
7228 Current_Verbosity := Default;
7229 Prj.Env.Get_Reference
7230 (Source_File_Name => Source_File_Name,
7232 In_Tree => Project_Tree,
7234 Current_Verbosity := Saved_Verbosity;
7236 -- If this source is in a project, check that the ALI file is in
7237 -- its object directory. If it is not, return False, so that the
7238 -- ALI file will not be skipped.
7240 if Project /= No_Project then
7242 Object_Directory : constant String :=
7246 Object_Directory.Display_Name));
7248 Olast : Natural := Object_Directory'Last;
7250 Lib_File_Directory : constant String :=
7251 Normalize_Pathname (Dir_Name
7252 (Get_Name_String (Full_Lib_File)));
7254 Llast : Natural := Lib_File_Directory'Last;
7257 -- For directories, Normalize_Pathname may or may not put
7258 -- a directory separator at the end, depending on its input.
7259 -- Remove any last directory separator before comparison.
7260 -- Returns True only if the two directories are the same.
7262 if Object_Directory (Olast) = Directory_Separator then
7266 if Lib_File_Directory (Llast) = Directory_Separator then
7270 return Object_Directory (Object_Directory'First .. Olast) =
7271 Lib_File_Directory (Lib_File_Directory'First .. Llast);
7277 -- When the source is not in a project file, always return True
7280 end Is_In_Object_Directory;
7287 (ALI_File : File_Name_Type;
7288 Args : Argument_List;
7289 Success : out Boolean)
7291 Link_Args : Argument_List (1 .. Args'Length + 1);
7294 Get_Name_String (ALI_File);
7295 Link_Args (1) := new String'(Name_Buffer (1 .. Name_Len));
7297 Link_Args (2 .. Args'Length + 1) := Args;
7299 GNAT.OS_Lib.Normalize_Arguments (Link_Args);
7301 Display (Gnatlink.all, Link_Args);
7303 if Gnatlink_Path = null then
7304 Make_Failed ("error, unable to locate " & Gnatlink.all);
7307 GNAT.OS_Lib.Spawn (Gnatlink_Path.all, Link_Args, Success);
7310 ---------------------------
7311 -- List_Bad_Compilations --
7312 ---------------------------
7314 procedure List_Bad_Compilations is
7316 for J in Bad_Compilation.First .. Bad_Compilation.Last loop
7317 if Bad_Compilation.Table (J).File = No_File then
7319 elsif not Bad_Compilation.Table (J).Found then
7320 Inform (Bad_Compilation.Table (J).File, "not found");
7322 Inform (Bad_Compilation.Table (J).File, "compilation error");
7325 end List_Bad_Compilations;
7331 procedure List_Depend is
7332 Lib_Name : File_Name_Type;
7333 Obj_Name : File_Name_Type;
7334 Src_Name : File_Name_Type;
7338 Line_Size : constant := 77;
7341 Set_Standard_Output;
7343 for A in ALIs.First .. ALIs.Last loop
7344 Lib_Name := ALIs.Table (A).Afile;
7346 -- We have to provide the full library file name in In_Place_Mode
7348 if In_Place_Mode then
7349 Lib_Name := Full_Lib_File_Name (Lib_Name);
7352 Obj_Name := Object_File_Name (Lib_Name);
7353 Write_Name (Obj_Name);
7356 Get_Name_String (Obj_Name);
7358 Line_Pos := Len + 2;
7360 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
7361 Src_Name := Sdep.Table (D).Sfile;
7363 if Is_Internal_File_Name (Src_Name)
7364 and then not Check_Readonly_Files
7368 if not Quiet_Output then
7369 Src_Name := Full_Source_Name (Src_Name);
7372 Get_Name_String (Src_Name);
7375 if Line_Pos + Len + 1 > Line_Size then
7381 Line_Pos := Line_Pos + Len + 1;
7384 Write_Name (Src_Name);
7391 if not Commands_To_Stdout then
7400 procedure Make_Failed (S : String) is
7402 Delete_All_Temp_Files;
7406 --------------------
7407 -- Mark_Directory --
7408 --------------------
7410 procedure Mark_Directory
7412 Mark : Lib_Mark_Type;
7413 On_Command_Line : Boolean)
7418 function Base_Directory return String;
7419 -- If Dir comes from the command line, empty string (relative paths are
7420 -- resolved with respect to the current directory), else return the main
7421 -- project's directory.
7423 --------------------
7424 -- Base_Directory --
7425 --------------------
7427 function Base_Directory return String is
7429 if On_Command_Line then
7432 return Get_Name_String (Main_Project.Directory.Display_Name);
7436 Real_Path : constant String := Normalize_Pathname (Dir, Base_Directory);
7438 -- Start of processing for Mark_Directory
7443 if Real_Path'Length = 0 then
7444 Add_Str_To_Name_Buffer (Dir);
7447 Add_Str_To_Name_Buffer (Real_Path);
7450 -- Last character is supposed to be a directory separator
7452 if not Is_Directory_Separator (Name_Buffer (Name_Len)) then
7453 Add_Char_To_Name_Buffer (Directory_Separator);
7456 -- Add flags to the already existing flags
7459 B := Get_Name_Table_Byte (N);
7460 Set_Name_Table_Byte (N, B or Mark);
7463 ----------------------
7464 -- Process_Multilib --
7465 ----------------------
7467 procedure Process_Multilib
7468 (Project_Node_Tree : Project_Node_Tree_Ref)
7470 Output_FD : File_Descriptor;
7471 Output_Name : String_Access;
7472 Arg_Index : Natural := 0;
7473 Success : Boolean := False;
7474 Return_Code : Integer := 0;
7475 Multilib_Gcc_Path : String_Access;
7476 Multilib_Gcc : String_Access;
7477 N_Read : Integer := 0;
7478 Line : String (1 .. 1000);
7479 Args : Argument_List (1 .. N_M_Switch + 1);
7482 pragma Assert (N_M_Switch > 0 and RTS_Specified = null);
7484 -- In case we detected a multilib switch and the user has not
7485 -- manually specified a specific RTS we emulate the following command:
7486 -- gnatmake $FLAGS --RTS=$(gcc -print-multi-directory $FLAGS)
7488 -- First select the flags which might have an impact on multilib
7489 -- processing. Note that this is an heuristic selection and it
7490 -- will need to be maintained over time. The condition has to
7491 -- be kept synchronized with N_M_Switch counting in Scan_Make_Arg.
7493 for Next_Arg in 1 .. Argument_Count loop
7495 Argv : constant String := Argument (Next_Arg);
7498 and then Argv (1) = '-'
7499 and then Argv (2) = 'm'
7500 and then Argv /= "-margs"
7502 -- Ignore -mieee to avoid spawning an extra gcc in this case
7504 and then Argv /= "-mieee"
7506 Arg_Index := Arg_Index + 1;
7507 Args (Arg_Index) := new String'(Argv);
7512 pragma Assert (Arg_Index = N_M_Switch);
7514 Args (Args'Last) := new String'("-print-multi-directory");
7516 -- Call the GCC driver with the collected flags and save its
7517 -- output. Alternate design would be to link in gnatmake the
7518 -- relevant part of the GCC driver.
7520 if Saved_Gcc /= null then
7521 Multilib_Gcc := Saved_Gcc;
7523 Multilib_Gcc := Gcc;
7526 Multilib_Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Multilib_Gcc.all);
7528 Create_Temp_Output_File (Output_FD, Output_Name);
7530 if Output_FD = Invalid_FD then
7535 (Multilib_Gcc_Path.all, Args, Output_FD, Return_Code, False);
7538 if Return_Code /= 0 then
7542 -- Parse the GCC driver output which is a single line, removing CR/LF
7544 Output_FD := Open_Read (Output_Name.all, Binary);
7546 if Output_FD = Invalid_FD then
7550 N_Read := Read (Output_FD, Line (1)'Address, Line'Length);
7552 Delete_File (Output_Name.all, Success);
7554 for J in reverse 1 .. N_Read loop
7555 if Line (J) = ASCII.CR or else Line (J) = ASCII.LF then
7556 N_Read := N_Read - 1;
7562 -- In case the standard RTS is selected do nothing
7564 if N_Read = 0 or else Line (1 .. N_Read) = "." then
7568 -- Otherwise add -margs --RTS=output
7570 Scan_Make_Arg (Project_Node_Tree, "-margs", And_Save => True);
7572 (Project_Node_Tree, "--RTS=" & Line (1 .. N_Read), And_Save => True);
7573 end Process_Multilib;
7575 -----------------------------
7576 -- Recursive_Compute_Depth --
7577 -----------------------------
7579 procedure Recursive_Compute_Depth (Project : Project_Id) is
7580 use Project_Boolean_Htable;
7581 Seen : Project_Boolean_Htable.Instance := Project_Boolean_Htable.Nil;
7583 procedure Recurse (Prj : Project_Id; Depth : Natural);
7584 -- Recursive procedure that does the work, keeping track of the depth
7590 procedure Recurse (Prj : Project_Id; Depth : Natural) is
7591 List : Project_List;
7595 if Prj.Depth >= Depth or else Get (Seen, Prj) then
7599 -- We need a test to avoid infinite recursions with limited withs:
7600 -- If we have A -> B -> A, then when set level of A to n, we try and
7601 -- set level of B to n+1, and then level of A to n + 2, ...
7603 Set (Seen, Prj, True);
7607 -- Visit each imported project
7609 List := Prj.Imported_Projects;
7610 while List /= null loop
7611 Proj := List.Project;
7613 Recurse (Prj => Proj, Depth => Depth + 1);
7616 -- We again allow changing the depth of this project later on if it
7617 -- is in fact imported by a lower-level project.
7619 Set (Seen, Prj, False);
7622 Proj : Project_List;
7624 -- Start of processing for Recursive_Compute_Depth
7627 Proj := Project_Tree.Projects;
7628 while Proj /= null loop
7629 Proj.Project.Depth := 0;
7633 Recurse (Project, Depth => 1);
7635 end Recursive_Compute_Depth;
7637 -------------------------------
7638 -- Report_Compilation_Failed --
7639 -------------------------------
7641 procedure Report_Compilation_Failed is
7643 Delete_All_Temp_Files;
7644 Exit_Program (E_Fatal);
7645 end Report_Compilation_Failed;
7647 ------------------------
7648 -- Sigint_Intercepted --
7649 ------------------------
7651 procedure Sigint_Intercepted is
7652 SIGINT : constant := 2;
7656 Write_Line ("*** Interrupted ***");
7658 -- Send SIGINT to all outstanding compilation processes spawned
7660 for J in 1 .. Outstanding_Compiles loop
7661 Kill (Running_Compile (J).Pid, SIGINT, 1);
7664 Delete_All_Temp_Files;
7666 -- ??? OS_Exit (1) is equivalent to Exit_Program (E_No_Compile),
7667 -- shouldn't that be Exit_Program (E_Abort) instead?
7668 end Sigint_Intercepted;
7674 procedure Scan_Make_Arg
7675 (Project_Node_Tree : Project_Node_Tree_Ref;
7682 Gnatmake_Switch_Found := True;
7684 pragma Assert (Argv'First = 1);
7686 if Argv'Length = 0 then
7690 -- If the previous switch has set the Project_File_Name_Present flag
7691 -- (that is we have seen a -P alone), then the next argument is the name
7692 -- of the project file.
7694 if Project_File_Name_Present and then Project_File_Name = null then
7695 if Argv (1) = '-' then
7696 Make_Failed ("project file name missing after -P");
7699 Project_File_Name_Present := False;
7700 Project_File_Name := new String'(Argv);
7703 -- If the previous switch has set the Output_File_Name_Present flag
7704 -- (that is we have seen a -o), then the next argument is the name of
7705 -- the output executable.
7707 elsif Output_File_Name_Present
7708 and then not Output_File_Name_Seen
7710 Output_File_Name_Seen := True;
7712 if Argv (1) = '-' then
7713 Make_Failed ("output file name missing after -o");
7716 Add_Switch ("-o", Linker, And_Save => And_Save);
7717 Add_Switch (Executable_Name (Argv), Linker, And_Save => And_Save);
7720 -- If the previous switch has set the Object_Directory_Present flag
7721 -- (that is we have seen a -D), then the next argument is the path name
7722 -- of the object directory.
7724 elsif Object_Directory_Present
7725 and then not Object_Directory_Seen
7727 Object_Directory_Seen := True;
7729 if Argv (1) = '-' then
7730 Make_Failed ("object directory path name missing after -D");
7732 elsif not Is_Directory (Argv) then
7733 Make_Failed ("cannot find object directory """ & Argv & """");
7736 -- Record the object directory. Make sure it ends with a directory
7740 Norm : constant String := Normalize_Pathname (Argv);
7743 if Norm (Norm'Last) = Directory_Separator then
7744 Object_Directory_Path := new String'(Norm);
7746 Object_Directory_Path :=
7747 new String'(Norm & Directory_Separator);
7750 Add_Lib_Search_Dir (Norm);
7752 -- Specify the object directory to the binder
7754 Add_Switch ("-aO" & Norm, Binder, And_Save => And_Save);
7759 -- Then check if we are dealing with -cargs/-bargs/-largs/-margs
7761 elsif Argv = "-bargs"
7770 when 'c' => Program_Args := Compiler;
7771 when 'b' => Program_Args := Binder;
7772 when 'l' => Program_Args := Linker;
7773 when 'm' => Program_Args := None;
7776 raise Program_Error;
7779 -- A special test is needed for the -o switch within a -largs since that
7780 -- is another way to specify the name of the final executable.
7782 elsif Program_Args = Linker
7783 and then Argv = "-o"
7785 Make_Failed ("switch -o not allowed within a -largs. " &
7786 "Use -o directly.");
7788 -- Check to see if we are reading switches after a -cargs, -bargs or
7789 -- -largs switch. If so, save it.
7791 elsif Program_Args /= None then
7793 -- Check to see if we are reading -I switches in order
7794 -- to take into account in the src & lib search directories.
7796 if Argv'Length > 2 and then Argv (1 .. 2) = "-I" then
7797 if Argv (3 .. Argv'Last) = "-" then
7798 Look_In_Primary_Dir := False;
7800 elsif Program_Args = Compiler then
7801 if Argv (3 .. Argv'Last) /= "-" then
7802 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7805 elsif Program_Args = Binder then
7806 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7810 Add_Switch (Argv, Program_Args, And_Save => And_Save);
7812 -- Handle non-default compiler, binder, linker, and handle --RTS switch
7814 elsif Argv'Length > 2 and then Argv (1 .. 2) = "--" then
7816 and then Argv (1 .. 6) = "--GCC="
7819 Program_Args : constant Argument_List_Access :=
7820 Argument_String_To_List
7821 (Argv (7 .. Argv'Last));
7825 Saved_Gcc := new String'(Program_Args.all (1).all);
7827 Gcc := new String'(Program_Args.all (1).all);
7830 for J in 2 .. Program_Args.all'Last loop
7832 (Program_Args.all (J).all, Compiler, And_Save => And_Save);
7836 elsif Argv'Length > 11
7837 and then Argv (1 .. 11) = "--GNATBIND="
7840 Program_Args : constant Argument_List_Access :=
7841 Argument_String_To_List
7842 (Argv (12 .. Argv'Last));
7846 Saved_Gnatbind := new String'(Program_Args.all (1).all);
7848 Gnatbind := new String'(Program_Args.all (1).all);
7851 for J in 2 .. Program_Args.all'Last loop
7853 (Program_Args.all (J).all, Binder, And_Save => And_Save);
7857 elsif Argv'Length > 11
7858 and then Argv (1 .. 11) = "--GNATLINK="
7861 Program_Args : constant Argument_List_Access :=
7862 Argument_String_To_List
7863 (Argv (12 .. Argv'Last));
7866 Saved_Gnatlink := new String'(Program_Args.all (1).all);
7868 Gnatlink := new String'(Program_Args.all (1).all);
7871 for J in 2 .. Program_Args.all'Last loop
7872 Add_Switch (Program_Args.all (J).all, Linker);
7876 elsif Argv'Length >= 5 and then
7877 Argv (1 .. 5) = "--RTS"
7879 Add_Switch (Argv, Compiler, And_Save => And_Save);
7880 Add_Switch (Argv, Binder, And_Save => And_Save);
7882 if Argv'Length <= 6 or else Argv (6) /= '=' then
7883 Make_Failed ("missing path for --RTS");
7886 -- Check that this is the first time we see this switch or
7887 -- if it is not the first time, the same path is specified.
7889 if RTS_Specified = null then
7890 RTS_Specified := new String'(Argv (7 .. Argv'Last));
7892 elsif RTS_Specified.all /= Argv (7 .. Argv'Last) then
7893 Make_Failed ("--RTS cannot be specified multiple times");
7896 -- Valid --RTS switch
7903 Src_Path_Name : constant String_Ptr :=
7905 (Argv (7 .. Argv'Last), Include);
7907 Lib_Path_Name : constant String_Ptr :=
7909 (Argv (7 .. Argv'Last), Objects);
7912 if Src_Path_Name /= null
7913 and then Lib_Path_Name /= null
7915 -- Set RTS_*_Path_Name variables, so that correct direct-
7916 -- ories will be set when Osint.Add_Default_Search_Dirs
7919 RTS_Src_Path_Name := Src_Path_Name;
7920 RTS_Lib_Path_Name := Lib_Path_Name;
7922 elsif Src_Path_Name = null
7923 and then Lib_Path_Name = null
7925 Make_Failed ("RTS path not valid: missing " &
7926 "adainclude and adalib directories");
7928 elsif Src_Path_Name = null then
7929 Make_Failed ("RTS path not valid: missing adainclude " &
7932 elsif Lib_Path_Name = null then
7933 Make_Failed ("RTS path not valid: missing adalib " &
7939 elsif Argv'Length >= 8 and then
7940 Argv (1 .. 8) = "--param="
7942 Add_Switch (Argv, Compiler, And_Save => And_Save);
7943 Add_Switch (Argv, Linker, And_Save => And_Save);
7946 Scan_Make_Switches (Project_Node_Tree, Argv, Success);
7949 -- If we have seen a regular switch process it
7951 elsif Argv (1) = '-' then
7952 if Argv'Length = 1 then
7953 Make_Failed ("switch character cannot be followed by a blank");
7955 -- Incorrect switches that should start with "--"
7957 elsif (Argv'Length > 5 and then Argv (1 .. 5) = "-RTS=")
7958 or else (Argv'Length > 5 and then Argv (1 .. 5) = "-GCC=")
7959 or else (Argv'Length > 8 and then Argv (1 .. 7) = "-param=")
7960 or else (Argv'Length > 10 and then Argv (1 .. 10) = "-GNATLINK=")
7961 or else (Argv'Length > 10 and then Argv (1 .. 10) = "-GNATBIND=")
7963 Make_Failed ("option " & Argv & " should start with '--'");
7967 elsif Argv (2 .. Argv'Last) = "I-" then
7968 Look_In_Primary_Dir := False;
7970 -- Forbid -?- or -??- where ? is any character
7972 elsif (Argv'Length = 3 and then Argv (3) = '-')
7973 or else (Argv'Length = 4 and then Argv (4) = '-')
7976 ("trailing ""-"" at the end of " & Argv & " forbidden.");
7980 elsif Argv (2) = 'I' then
7981 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7982 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7983 Add_Switch (Argv, Compiler, And_Save => And_Save);
7984 Add_Switch (Argv, Binder, And_Save => And_Save);
7986 -- -aIdir (to gcc this is like a -I switch)
7988 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aI" then
7989 Add_Source_Search_Dir (Argv (4 .. Argv'Last), And_Save);
7991 ("-I" & Argv (4 .. Argv'Last), Compiler, And_Save => And_Save);
7992 Add_Switch (Argv, Binder, And_Save => And_Save);
7996 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aO" then
7997 Add_Library_Search_Dir (Argv (4 .. Argv'Last), And_Save);
7998 Add_Switch (Argv, Binder, And_Save => And_Save);
8000 -- -aLdir (to gnatbind this is like a -aO switch)
8002 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aL" then
8003 Mark_Directory (Argv (4 .. Argv'Last), Ada_Lib_Dir, And_Save);
8004 Add_Library_Search_Dir (Argv (4 .. Argv'Last), And_Save);
8006 ("-aO" & Argv (4 .. Argv'Last), Binder, And_Save => And_Save);
8010 elsif Argv'Length >= 13 and then Argv (2 .. 13) = "aamp_target=" then
8011 Add_Switch (Argv, Compiler, And_Save => And_Save);
8013 -- Set the aamp_target environment variable so that the binder and
8014 -- linker will use the proper target library. This is consistent
8015 -- with how things work when -aamp_target is passed on the command
8016 -- line to gnaampmake.
8018 Setenv ("aamp_target", Argv (14 .. Argv'Last));
8020 -- -Adir (to gnatbind this is like a -aO switch, to gcc like a -I)
8022 elsif Argv (2) = 'A' then
8023 Mark_Directory (Argv (3 .. Argv'Last), Ada_Lib_Dir, And_Save);
8024 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
8025 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
8027 ("-I" & Argv (3 .. Argv'Last), Compiler, And_Save => And_Save);
8029 ("-aO" & Argv (3 .. Argv'Last), Binder, And_Save => And_Save);
8033 elsif Argv (2) = 'L' then
8034 Add_Switch (Argv, Linker, And_Save => And_Save);
8036 -- For -gxxxxx, -pg, -mxxx, -fxxx: give the switch to both the
8037 -- compiler and the linker (except for -gnatxxx which is only for the
8038 -- compiler). Some of the -mxxx (for example -m64) and -fxxx (for
8039 -- example -ftest-coverage for gcov) need to be used when compiling
8040 -- the binder generated files, and using all these gcc switches for
8041 -- the binder generated files should not be a problem.
8044 (Argv (2) = 'g' and then (Argv'Last < 5
8045 or else Argv (2 .. 5) /= "gnat"))
8046 or else Argv (2 .. Argv'Last) = "pg"
8047 or else (Argv (2) = 'm' and then Argv'Last > 2)
8048 or else (Argv (2) = 'f' and then Argv'Last > 2)
8050 Add_Switch (Argv, Compiler, And_Save => And_Save);
8051 Add_Switch (Argv, Linker, And_Save => And_Save);
8053 -- The following condition has to be kept synchronized with
8054 -- the Process_Multilib one.
8057 and then Argv /= "-mieee"
8059 N_M_Switch := N_M_Switch + 1;
8062 -- -C=<mapping file>
8064 elsif Argv'Last > 2 and then Argv (2) = 'C' then
8066 if Argv (3) /= '=' or else Argv'Last <= 3 then
8067 Make_Failed ("illegal switch " & Argv);
8070 Gnatmake_Mapping_File := new String'(Argv (4 .. Argv'Last));
8075 elsif Argv'Last = 2 and then Argv (2) = 'D' then
8076 if Project_File_Name /= null then
8078 ("-D cannot be used in conjunction with a project file");
8081 Scan_Make_Switches (Project_Node_Tree, Argv, Success);
8086 elsif Argv (2) = 'd' and then Argv'Last = 2 then
8087 Display_Compilation_Progress := True;
8091 elsif Argv'Last = 2 and then Argv (2) = 'i' then
8092 if Project_File_Name /= null then
8094 ("-i cannot be used in conjunction with a project file");
8096 Scan_Make_Switches (Project_Node_Tree, Argv, Success);
8099 -- -j (need to save the result)
8101 elsif Argv (2) = 'j' then
8102 Scan_Make_Switches (Project_Node_Tree, Argv, Success);
8105 Saved_Maximum_Processes := Maximum_Processes;
8110 elsif Argv (2) = 'm' and then Argv'Last = 2 then
8111 Minimal_Recompilation := True;
8115 elsif Argv (2) = 'u' and then Argv'Last = 2 then
8116 Unique_Compile := True;
8117 Compile_Only := True;
8118 Do_Bind_Step := False;
8119 Do_Link_Step := False;
8123 elsif Argv (2) = 'U'
8124 and then Argv'Last = 2
8126 Unique_Compile_All_Projects := True;
8127 Unique_Compile := True;
8128 Compile_Only := True;
8129 Do_Bind_Step := False;
8130 Do_Link_Step := False;
8132 -- -Pprj or -P prj (only once, and only on the command line)
8134 elsif Argv (2) = 'P' then
8135 if Project_File_Name /= null then
8136 Make_Failed ("cannot have several project files specified");
8138 elsif Object_Directory_Path /= null then
8140 ("-D cannot be used in conjunction with a project file");
8142 elsif In_Place_Mode then
8144 ("-i cannot be used in conjunction with a project file");
8146 elsif not And_Save then
8148 -- It could be a tool other than gnatmake (e.g. gnatdist)
8149 -- or a -P switch inside a project file.
8152 ("either the tool is not ""project-aware"" or " &
8153 "a project file is specified inside a project file");
8155 elsif Argv'Last = 2 then
8157 -- -P is used alone: the project file name is the next option
8159 Project_File_Name_Present := True;
8162 Project_File_Name := new String'(Argv (3 .. Argv'Last));
8165 -- -vPx (verbosity of the parsing of the project files)
8168 and then Argv (2 .. 3) = "vP"
8169 and then Argv (4) in '0' .. '2'
8174 Current_Verbosity := Prj.Default;
8176 Current_Verbosity := Prj.Medium;
8178 Current_Verbosity := Prj.High;
8184 -- -Xext=val (External assignment)
8186 elsif Argv (2) = 'X'
8187 and then Is_External_Assignment (Project_Node_Tree, Argv)
8189 -- Is_External_Assignment has side effects when it returns True
8193 -- If -gnath is present, then generate the usage information right
8194 -- now and do not pass this option on to the compiler calls.
8196 elsif Argv = "-gnath" then
8199 -- If -gnatc is specified, make sure the bind and link steps are not
8202 elsif Argv'Length >= 6 and then Argv (2 .. 6) = "gnatc" then
8204 -- If -gnatc is specified, make sure the bind and link steps are
8207 Add_Switch (Argv, Compiler, And_Save => And_Save);
8208 Operating_Mode := Check_Semantics;
8209 Check_Object_Consistency := False;
8210 Compile_Only := True;
8211 Do_Bind_Step := False;
8212 Do_Link_Step := False;
8214 elsif Argv (2 .. Argv'Last) = "nostdlib" then
8216 -- Don't pass -nostdlib to gnatlink, it will disable
8217 -- linking with all standard library files.
8221 Add_Switch (Argv, Compiler, And_Save => And_Save);
8222 Add_Switch (Argv, Binder, And_Save => And_Save);
8224 elsif Argv (2 .. Argv'Last) = "nostdinc" then
8226 -- Pass -nostdinc to the Compiler and to gnatbind
8229 Add_Switch (Argv, Compiler, And_Save => And_Save);
8230 Add_Switch (Argv, Binder, And_Save => And_Save);
8232 -- All other switches are processed by Scan_Make_Switches. If the
8233 -- call returns with Gnatmake_Switch_Found = False, then the switch
8234 -- is passed to the compiler.
8238 (Project_Node_Tree, Argv, Gnatmake_Switch_Found);
8240 if not Gnatmake_Switch_Found then
8241 Add_Switch (Argv, Compiler, And_Save => And_Save);
8245 -- If not a switch it must be a file name
8249 Main_On_Command_Line := True;
8253 Mains.Add_Main (Argv);
8261 function Switches_Of
8262 (Source_File : File_Name_Type;
8263 Source_File_Name : String;
8265 Project : Project_Id;
8266 In_Package : Package_Id;
8267 Allow_ALI : Boolean) return Variable_Value
8269 Lang : constant Language_Ptr := Get_Language_From_Name (Project, "ada");
8271 Switches : Variable_Value;
8273 Defaults : constant Array_Element_Id :=
8275 (Name => Name_Default_Switches,
8277 Project_Tree.Packages.Table
8278 (In_Package).Decl.Arrays,
8279 In_Tree => Project_Tree);
8281 Switches_Array : constant Array_Element_Id :=
8283 (Name => Name_Switches,
8285 Project_Tree.Packages.Table
8286 (In_Package).Decl.Arrays,
8287 In_Tree => Project_Tree);
8290 -- First, try Switches (<file name>)
8294 (Index => Name_Id (Source_File),
8295 Src_Index => Source_Index,
8296 In_Array => Switches_Array,
8297 In_Tree => Project_Tree);
8299 -- Check also without the suffix
8301 if Switches = Nil_Variable_Value
8302 and then Lang /= null
8305 Naming : Lang_Naming_Data renames Lang.Config.Naming_Data;
8306 Name : String (1 .. Source_File_Name'Length + 3);
8307 Last : Positive := Source_File_Name'Length;
8308 Spec_Suffix : constant String :=
8309 Get_Name_String (Naming.Spec_Suffix);
8310 Body_Suffix : constant String :=
8311 Get_Name_String (Naming.Body_Suffix);
8312 Truncated : Boolean := False;
8315 Name (1 .. Last) := Source_File_Name;
8317 if Last > Body_Suffix'Length
8318 and then Name (Last - Body_Suffix'Length + 1 .. Last) =
8322 Last := Last - Body_Suffix'Length;
8326 and then Last > Spec_Suffix'Length
8327 and then Name (Last - Spec_Suffix'Length + 1 .. Last) =
8331 Last := Last - Spec_Suffix'Length;
8336 Add_Str_To_Name_Buffer (Name (1 .. Last));
8339 (Index => Name_Find,
8341 In_Array => Switches_Array,
8342 In_Tree => Project_Tree);
8344 if Switches = Nil_Variable_Value and then Allow_ALI then
8345 Last := Source_File_Name'Length;
8347 while Name (Last) /= '.' loop
8352 Add_Str_To_Name_Buffer (Name (1 .. Last));
8353 Add_Str_To_Name_Buffer ("ali");
8357 (Index => Name_Find,
8359 In_Array => Switches_Array,
8360 In_Tree => Project_Tree);
8366 -- Next, try Switches ("Ada")
8368 if Switches = Nil_Variable_Value then
8373 In_Array => Switches_Array,
8374 In_Tree => Project_Tree,
8375 Force_Lower_Case_Index => True);
8377 if Switches /= Nil_Variable_Value then
8378 Switch_May_Be_Passed_To_The_Compiler := False;
8382 -- Next, try Switches (others)
8384 if Switches = Nil_Variable_Value then
8387 (Index => All_Other_Names,
8389 In_Array => Switches_Array,
8390 In_Tree => Project_Tree);
8392 if Switches /= Nil_Variable_Value then
8393 Switch_May_Be_Passed_To_The_Compiler := False;
8397 -- And finally, Default_Switches ("Ada")
8399 if Switches = Nil_Variable_Value then
8404 In_Array => Defaults,
8405 In_Tree => Project_Tree);
8417 if Usage_Needed then
8418 Usage_Needed := False;
8424 -- Make sure that in case of failure, the temp files will be deleted
8426 Prj.Com.Fail := Make_Failed'Access;
8427 MLib.Fail := Make_Failed'Access;
8428 Makeutl.Do_Fail := Make_Failed'Access;