* gimplify.c (find_single_pointer_decl_1): New static function.
[official-gcc.git] / gcc / ada / make.adb
blob7e4c80c65cdee2d918e1fc12aa6fee6fa85d75d6
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- M A K E --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2005 Free Software Foundation, Inc. --
10 -- --
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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
27 with ALI; use ALI;
28 with ALI.Util; use ALI.Util;
29 with Csets;
30 with Debug;
31 with Fmap;
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;
37 with Makeusg;
38 with Makeutl; use Makeutl;
39 with MLib.Prj;
40 with MLib.Tgt; use MLib.Tgt;
41 with MLib.Utl;
42 with Namet; use Namet;
43 with Opt; use Opt;
44 with Osint.M; use Osint.M;
45 with Osint; use Osint;
46 with Output; use Output;
47 with Prj; use Prj;
48 with Prj.Com;
49 with Prj.Env;
50 with Prj.Pars;
51 with Prj.Util;
52 with SFN_Scan;
53 with Sinput.P;
54 with Snames; use Snames;
55 with Switch; use Switch;
56 with Switch.M; use Switch.M;
57 with Targparm;
58 with Tempdir;
60 with Ada.Exceptions; use Ada.Exceptions;
61 with Ada.Command_Line; use Ada.Command_Line;
63 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
64 with GNAT.Case_Util; use GNAT.Case_Util;
66 with System.HTable;
68 package body Make is
70 use ASCII;
71 -- Make control characters visible
73 Standard_Library_Package_Body_Name : constant String := "s-stalib.adb";
74 -- Every program depends on this package, that must then be checked,
75 -- especially when -f and -a are used.
77 type Sigint_Handler is access procedure;
79 procedure Install_Int_Handler (Handler : Sigint_Handler);
80 pragma Import (C, Install_Int_Handler, "__gnat_install_int_handler");
81 -- Called by Gnatmake to install the SIGINT handler below
83 procedure Sigint_Intercepted;
84 -- Called when the program is interrupted by Ctrl-C to delete the
85 -- temporary mapping files and configuration pragmas files.
87 -------------------------
88 -- Note on terminology --
89 -------------------------
91 -- In this program, we use the phrase "termination" of a file name to
92 -- refer to the suffix that appears after the unit name portion. Very
93 -- often this is simply the extension, but in some cases, the sequence
94 -- may be more complex, for example in main.1.ada, the termination in
95 -- this name is ".1.ada" and in main_.ada the termination is "_.ada".
97 -------------------------------------
98 -- Queue (Q) Manipulation Routines --
99 -------------------------------------
101 -- The Q is used in Compile_Sources below. Its implementation uses the
102 -- GNAT generic package Table (basically an extensible array). Q_Front
103 -- points to the first valid element in the Q, whereas Q.First is the first
104 -- element ever enqueued, while Q.Last - 1 is the last element in the Q.
106 -- +---+--------------+---+---+---+-----------+---+--------
107 -- Q | | ........ | | | | ....... | |
108 -- +---+--------------+---+---+---+-----------+---+--------
109 -- ^ ^ ^
110 -- Q.First Q_Front Q.Last - 1
112 -- The elements comprised between Q.First and Q_Front - 1 are the
113 -- elements that have been enqueued and then dequeued, while the
114 -- elements between Q_Front and Q.Last - 1 are the elements currently
115 -- in the Q. When the Q is initialized Q_Front = Q.First = Q.Last.
116 -- After Compile_Sources has terminated its execution, Q_Front = Q.Last
117 -- and the elements contained between Q.Front and Q.Last-1 are those that
118 -- were explored and thus marked by Compile_Sources. Whenever the Q is
119 -- reinitialized, the elements between Q.First and Q.Last - 1 are unmarked.
121 procedure Init_Q;
122 -- Must be called to (re)initialize the Q
124 procedure Insert_Q
125 (Source_File : File_Name_Type;
126 Source_Unit : Unit_Name_Type := No_Name;
127 Index : Int := 0);
128 -- Inserts Source_File at the end of Q. Provide Source_Unit when possible
129 -- for external use (gnatdist). Provide index for multi-unit sources.
131 function Empty_Q return Boolean;
132 -- Returns True if Q is empty
134 procedure Extract_From_Q
135 (Source_File : out File_Name_Type;
136 Source_Unit : out Unit_Name_Type;
137 Source_Index : out Int);
138 -- Extracts the first element from the Q
140 procedure Insert_Project_Sources
141 (The_Project : Project_Id;
142 All_Projects : Boolean;
143 Into_Q : Boolean);
144 -- If Into_Q is True, insert all sources of the project file(s) that are
145 -- not already marked into the Q. If Into_Q is False, call Osint.Add_File
146 -- for the first source, then insert all other sources that are not already
147 -- marked into the Q. If All_Projects is True, all sources of all projects
148 -- are concerned; otherwise, only sources of The_Project are concerned,
149 -- including, if The_Project is an extending project, sources inherited
150 -- from projects being extended.
152 First_Q_Initialization : Boolean := True;
153 -- Will be set to false after Init_Q has been called once
155 Q_Front : Natural;
156 -- Points to the first valid element in the Q
158 Unique_Compile : Boolean := False;
159 -- Set to True if -u or -U or a project file with no main is used
161 Unique_Compile_All_Projects : Boolean := False;
162 -- Set to True if -U is used
164 RTS_Specified : String_Access := null;
165 -- Used to detect multiple --RTS= switches
167 type Q_Record is record
168 File : File_Name_Type;
169 Unit : Unit_Name_Type;
170 Index : Int;
171 end record;
172 -- File is the name of the file to compile. Unit is for gnatdist
173 -- use in order to easily get the unit name of a file to compile
174 -- when its name is krunched or declared in gnat.adc. Index, when not 0,
175 -- is the index of the unit in a multi-unit source.
177 package Q is new Table.Table (
178 Table_Component_Type => Q_Record,
179 Table_Index_Type => Natural,
180 Table_Low_Bound => 0,
181 Table_Initial => 4000,
182 Table_Increment => 100,
183 Table_Name => "Make.Q");
184 -- This is the actual Q
186 -- The following instantiations and variables are necessary to save what
187 -- is found on the command line, in case there is a project file specified.
189 package Saved_Gcc_Switches is new Table.Table (
190 Table_Component_Type => String_Access,
191 Table_Index_Type => Integer,
192 Table_Low_Bound => 1,
193 Table_Initial => 20,
194 Table_Increment => 100,
195 Table_Name => "Make.Saved_Gcc_Switches");
197 package Saved_Binder_Switches is new Table.Table (
198 Table_Component_Type => String_Access,
199 Table_Index_Type => Integer,
200 Table_Low_Bound => 1,
201 Table_Initial => 20,
202 Table_Increment => 100,
203 Table_Name => "Make.Saved_Binder_Switches");
205 package Saved_Linker_Switches is new Table.Table
206 (Table_Component_Type => String_Access,
207 Table_Index_Type => Integer,
208 Table_Low_Bound => 1,
209 Table_Initial => 20,
210 Table_Increment => 100,
211 Table_Name => "Make.Saved_Linker_Switches");
213 package Switches_To_Check is new Table.Table (
214 Table_Component_Type => String_Access,
215 Table_Index_Type => Integer,
216 Table_Low_Bound => 1,
217 Table_Initial => 20,
218 Table_Increment => 100,
219 Table_Name => "Make.Switches_To_Check");
221 package Library_Paths is new Table.Table (
222 Table_Component_Type => String_Access,
223 Table_Index_Type => Integer,
224 Table_Low_Bound => 1,
225 Table_Initial => 20,
226 Table_Increment => 100,
227 Table_Name => "Make.Library_Paths");
229 package Failed_Links is new Table.Table (
230 Table_Component_Type => File_Name_Type,
231 Table_Index_Type => Integer,
232 Table_Low_Bound => 1,
233 Table_Initial => 10,
234 Table_Increment => 100,
235 Table_Name => "Make.Failed_Links");
237 package Successful_Links is new Table.Table (
238 Table_Component_Type => File_Name_Type,
239 Table_Index_Type => Integer,
240 Table_Low_Bound => 1,
241 Table_Initial => 10,
242 Table_Increment => 100,
243 Table_Name => "Make.Successful_Links");
245 package Library_Projs is new Table.Table (
246 Table_Component_Type => Project_Id,
247 Table_Index_Type => Integer,
248 Table_Low_Bound => 1,
249 Table_Initial => 10,
250 Table_Increment => 100,
251 Table_Name => "Make.Library_Projs");
253 -- Two variables to keep the last binder and linker switch index
254 -- in tables Binder_Switches and Linker_Switches, before adding
255 -- switches from the project file (if any) and switches from the
256 -- command line (if any).
258 Last_Binder_Switch : Integer := 0;
259 Last_Linker_Switch : Integer := 0;
261 Normalized_Switches : Argument_List_Access := new Argument_List (1 .. 10);
262 Last_Norm_Switch : Natural := 0;
264 Saved_Maximum_Processes : Natural := 0;
266 type Arg_List_Ref is access Argument_List;
267 The_Saved_Gcc_Switches : Arg_List_Ref;
269 Project_File_Name : String_Access := null;
270 -- The path name of the main project file, if any
272 Project_File_Name_Present : Boolean := False;
273 -- True when -P is used with a space between -P and the project file name
275 Current_Verbosity : Prj.Verbosity := Prj.Default;
276 -- Verbosity to parse the project files
278 Project_Tree : constant Project_Tree_Ref := new Project_Tree_Data;
280 Main_Project : Prj.Project_Id := No_Project;
281 -- The project id of the main project file, if any
283 Project_Object_Directory : Project_Id := No_Project;
284 -- The object directory of the project for the last compilation.
285 -- Avoid calling Change_Dir if the current working directory is already
286 -- this directory
288 -- Packages of project files where unknown attributes are errors
290 Naming_String : aliased String := "naming";
291 Builder_String : aliased String := "builder";
292 Compiler_String : aliased String := "compiler";
293 Binder_String : aliased String := "binder";
294 Linker_String : aliased String := "linker";
296 Gnatmake_Packages : aliased String_List :=
297 (Naming_String 'Access,
298 Builder_String 'Access,
299 Compiler_String 'Access,
300 Binder_String 'Access,
301 Linker_String 'Access);
303 Packages_To_Check_By_Gnatmake : constant String_List_Access :=
304 Gnatmake_Packages'Access;
306 procedure Add_Source_Dir (N : String);
307 -- Call Add_Src_Search_Dir.
308 -- Output one line when in verbose mode.
310 procedure Add_Source_Directories is
311 new Prj.Env.For_All_Source_Dirs (Action => Add_Source_Dir);
313 procedure Add_Object_Dir (N : String);
314 -- Call Add_Lib_Search_Dir.
315 -- Output one line when in verbose mode.
317 procedure Add_Object_Directories is
318 new Prj.Env.For_All_Object_Dirs (Action => Add_Object_Dir);
320 procedure Change_To_Object_Directory (Project : Project_Id);
321 -- Change to the object directory of project Project, if this is not
322 -- already the current working directory.
324 type Bad_Compilation_Info is record
325 File : File_Name_Type;
326 Unit : Unit_Name_Type;
327 Found : Boolean;
328 end record;
329 -- File is the name of the file for which a compilation failed.
330 -- Unit is for gnatdist use in order to easily get the unit name
331 -- of a file when its name is krunched or declared in gnat.adc.
332 -- Found is False if the compilation failed because the file could
333 -- not be found.
335 package Bad_Compilation is new Table.Table (
336 Table_Component_Type => Bad_Compilation_Info,
337 Table_Index_Type => Natural,
338 Table_Low_Bound => 1,
339 Table_Initial => 20,
340 Table_Increment => 100,
341 Table_Name => "Make.Bad_Compilation");
342 -- Full name of all the source files for which compilation fails
344 Do_Compile_Step : Boolean := True;
345 Do_Bind_Step : Boolean := True;
346 Do_Link_Step : Boolean := True;
347 -- Flags to indicate what step should be executed.
348 -- Can be set to False with the switches -c, -b and -l.
349 -- These flags are reset to True for each invokation of procedure Gnatmake.
351 Shared_String : aliased String := "-shared";
352 Force_Elab_Flags_String : aliased String := "-F";
354 No_Shared_Switch : aliased Argument_List := (1 .. 0 => null);
355 Shared_Switch : aliased Argument_List := (1 => Shared_String'Access);
356 Bind_Shared : Argument_List_Access := No_Shared_Switch'Access;
357 -- Switch to added in front of gnatbind switches. By default no switch is
358 -- added. Switch "-shared" is added if there is a non-static Library
359 -- Project File.
361 Shared_Libgcc : aliased String := "-shared-libgcc";
363 No_Shared_Libgcc_Switch : aliased Argument_List := (1 .. 0 => null);
364 Shared_Libgcc_Switch : aliased Argument_List :=
365 (1 => Shared_Libgcc'Access);
366 Link_With_Shared_Libgcc : Argument_List_Access :=
367 No_Shared_Libgcc_Switch'Access;
369 procedure Make_Failed (S1 : String; S2 : String := ""; S3 : String := "");
370 -- Delete all temp files created by Gnatmake and call Osint.Fail,
371 -- with the parameter S1, S2 and S3 (see osint.ads).
372 -- This is called from the Prj hierarchy and the MLib hierarchy.
374 --------------------------
375 -- Obsolete Executables --
376 --------------------------
378 Executable_Obsolete : Boolean := False;
379 -- Executable_Obsolete is initially set to False for each executable,
380 -- and is set to True whenever one of the source of the executable is
381 -- compiled, or has already been compiled for another executable.
383 Max_Header : constant := 200;
384 -- This needs a proper comment, it used to say "arbitrary"
385 -- that's not an adequate comment ???
387 type Header_Num is range 1 .. Max_Header;
388 -- Header_Num for the hash table Obsoleted below
390 function Hash (F : Name_Id) return Header_Num;
391 -- Hash function for the hash table Obsoleted below
393 package Obsoleted is new System.HTable.Simple_HTable
394 (Header_Num => Header_Num,
395 Element => Boolean,
396 No_Element => False,
397 Key => Name_Id,
398 Hash => Hash,
399 Equal => "=");
400 -- A hash table to keep all files that have been compiled, to detect
401 -- if an executable is up to date or not.
403 procedure Enter_Into_Obsoleted (F : Name_Id);
404 -- Enter a file name, without directory information, into the has table
405 -- Obsoleted.
407 function Is_In_Obsoleted (F : Name_Id) return Boolean;
408 -- Check if a file name, without directory information, has already been
409 -- entered into the hash table Obsoleted.
411 type Dependency is record
412 This : Name_Id;
413 Depends_On : Name_Id;
414 end record;
415 -- Components of table Dependencies below
417 package Dependencies is new Table.Table (
418 Table_Component_Type => Dependency,
419 Table_Index_Type => Integer,
420 Table_Low_Bound => 1,
421 Table_Initial => 20,
422 Table_Increment => 100,
423 Table_Name => "Make.Dependencies");
424 -- A table to keep dependencies, to be able to decide if an executable
425 -- is obsolete.
427 procedure Add_Dependency (S : Name_Id; On : Name_Id);
428 -- Add one entry in table Dependencies
430 ----------------------------
431 -- Arguments and Switches --
432 ----------------------------
434 Arguments : Argument_List_Access;
435 -- Used to gather the arguments for invocation of the compiler
437 Last_Argument : Natural := 0;
438 -- Last index of arguments in Arguments above
440 Arguments_Collected : Boolean := False;
441 -- Set to True when the arguments for the next invocation of the compiler
442 -- have been collected.
444 Arguments_Project : Project_Id;
445 -- Project id, if any, of the source to be compiled
447 Arguments_Path_Name : File_Name_Type;
448 -- Full path of the source to be compiled, when Arguments_Project is not
449 -- No_Project.
451 Dummy_Switch : constant String_Access := new String'("- ");
452 -- Used to initialized Prev_Switch in procedure Check
454 procedure Add_Arguments (Args : Argument_List);
455 -- Add arguments to global variable Arguments, increasing its size
456 -- if necessary and adjusting Last_Argument.
458 function Configuration_Pragmas_Switch
459 (For_Project : Project_Id) return Argument_List;
460 -- Return an argument list of one element, if there is a configuration
461 -- pragmas file to be specified for For_Project,
462 -- otherwise return an empty argument list.
464 -------------------
465 -- Misc Routines --
466 -------------------
468 procedure List_Depend;
469 -- Prints to standard output the list of object dependencies. This list
470 -- can be used directly in a Makefile. A call to Compile_Sources must
471 -- precede the call to List_Depend. Also because this routine uses the
472 -- ALI files that were originally loaded and scanned by Compile_Sources,
473 -- no additional ALI files should be scanned between the two calls (i.e.
474 -- between the call to Compile_Sources and List_Depend.)
476 procedure Inform (N : Name_Id := No_Name; Msg : String);
477 -- Prints out the program name followed by a colon, N and S
479 procedure List_Bad_Compilations;
480 -- Prints out the list of all files for which the compilation failed
482 procedure Verbose_Msg
483 (N1 : Name_Id;
484 S1 : String;
485 N2 : Name_Id := No_Name;
486 S2 : String := "";
487 Prefix : String := " -> ");
488 -- If the verbose flag (Verbose_Mode) is set then print Prefix to standard
489 -- output followed by N1 and S1. If N2 /= No_Name then N2 is printed after
490 -- S1. S2 is printed last. Both N1 and N2 are printed in quotation marks.
492 Usage_Needed : Boolean := True;
493 -- Flag used to make sure Makeusg is call at most once
495 procedure Usage;
496 -- Call Makeusg, if Usage_Needed is True.
497 -- Set Usage_Needed to False.
499 procedure Debug_Msg (S : String; N : Name_Id);
500 -- If Debug.Debug_Flag_W is set outputs string S followed by name N
502 procedure Recursive_Compute_Depth
503 (Project : Project_Id;
504 Depth : Natural);
505 -- Compute depth of Project and of the projects it depends on
507 -----------------------
508 -- Gnatmake Routines --
509 -----------------------
511 Gnatmake_Called : Boolean := False;
512 -- Set to True when procedure Gnatmake is called.
513 -- Attempt to delete temporary files is made only when Gnatmake_Called
514 -- is True.
516 subtype Lib_Mark_Type is Byte;
517 -- Used in Mark_Directory
519 Ada_Lib_Dir : constant Lib_Mark_Type := 1;
520 -- Used to mark a directory as a GNAT lib dir
522 -- Note that the notion of GNAT lib dir is no longer used. The code
523 -- related to it has not been removed to give an idea on how to use
524 -- the directory prefix marking mechanism.
526 -- An Ada library directory is a directory containing ali and object
527 -- files but no source files for the bodies (the specs can be in the
528 -- same or some other directory). These directories are specified
529 -- in the Gnatmake command line with the switch "-Adir" (to specify the
530 -- spec location -Idir cab be used). Gnatmake skips the missing sources
531 -- whose ali are in Ada library directories. For an explanation of why
532 -- Gnatmake behaves that way, see the spec of Make.Compile_Sources.
533 -- The directory lookup penalty is incurred every single time this
534 -- routine is called.
536 procedure Check_Steps;
537 -- Check what steps (Compile, Bind, Link) must be executed.
538 -- Set the step flags accordingly.
540 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean;
541 -- Get directory prefix of this file and get lib mark stored in name
542 -- table for this directory. Then check if an Ada lib mark has been set.
544 procedure Mark_Directory
545 (Dir : String;
546 Mark : Lib_Mark_Type);
547 -- Store Dir in name table and set lib mark as name info to identify
548 -- Ada libraries.
550 Output_Is_Object : Boolean := True;
551 -- Set to False when using a switch -S for the compiler
553 procedure Check_For_S_Switch;
554 -- Set Output_Is_Object to False when the -S switch is used for the
555 -- compiler.
557 function Switches_Of
558 (Source_File : Name_Id;
559 Source_File_Name : String;
560 Source_Index : Int;
561 Naming : Naming_Data;
562 In_Package : Package_Id;
563 Allow_ALI : Boolean) return Variable_Value;
564 -- Return the switches for the source file in the specified package
565 -- of a project file. If the Source_File ends with a standard GNAT
566 -- extension (".ads" or ".adb"), try first the full name, then the
567 -- name without the extension, then, if Allow_ALI is True, the name with
568 -- the extension ".ali". If there is no switches for either names, try the
569 -- default switches for Ada. If all failed, return No_Variable_Value.
571 function Is_In_Object_Directory
572 (Source_File : File_Name_Type;
573 Full_Lib_File : File_Name_Type) return Boolean;
574 -- Check if, when using a project file, the ALI file is in the project
575 -- directory of the ultimate extending project. If it is not, we ignore
576 -- the fact that this ALI file is read-only.
578 ----------------------------------------------------
579 -- Compiler, Binder & Linker Data and Subprograms --
580 ----------------------------------------------------
582 Gcc : String_Access := Program_Name ("gcc");
583 Gnatbind : String_Access := Program_Name ("gnatbind");
584 Gnatlink : String_Access := Program_Name ("gnatlink");
585 -- Default compiler, binder, linker programs
587 Saved_Gcc : String_Access := null;
588 Saved_Gnatbind : String_Access := null;
589 Saved_Gnatlink : String_Access := null;
590 -- Given by the command line. Will be used, if non null
592 Gcc_Path : String_Access :=
593 GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
594 Gnatbind_Path : String_Access :=
595 GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
596 Gnatlink_Path : String_Access :=
597 GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
598 -- Path for compiler, binder, linker programs, defaulted now for gnatdist.
599 -- Changed later if overridden on command line.
601 Comp_Flag : constant String_Access := new String'("-c");
602 Output_Flag : constant String_Access := new String'("-o");
603 Ada_Flag_1 : constant String_Access := new String'("-x");
604 Ada_Flag_2 : constant String_Access := new String'("ada");
605 No_gnat_adc : constant String_Access := new String'("-gnatA");
606 GNAT_Flag : constant String_Access := new String'("-gnatpg");
607 Do_Not_Check_Flag : constant String_Access := new String'("-x");
609 Object_Suffix : constant String := Get_Object_Suffix.all;
610 Executable_Suffix : constant String := Get_Executable_Suffix.all;
612 Syntax_Only : Boolean := False;
613 -- Set to True when compiling with -gnats
615 Display_Executed_Programs : Boolean := True;
616 -- Set to True if name of commands should be output on stderr
618 Output_File_Name_Seen : Boolean := False;
619 -- Set to True after having scanned the file_name for
620 -- switch "-o file_name"
622 Object_Directory_Seen : Boolean := False;
623 -- Set to True after having scanned the object directory for
624 -- switch "-D obj_dir".
626 Object_Directory_Path : String_Access := null;
627 -- The path name of the object directory, set with switch -D
629 type Make_Program_Type is (None, Compiler, Binder, Linker);
631 Program_Args : Make_Program_Type := None;
632 -- Used to indicate if we are scanning gnatmake, gcc, gnatbind, or gnatbind
633 -- options within the gnatmake command line. Used in Scan_Make_Arg only,
634 -- but must be global since value preserved from one call to another.
636 Temporary_Config_File : Boolean := False;
637 -- Set to True when there is a temporary config file used for a project
638 -- file, to avoid displaying the -gnatec switch for a temporary file.
640 procedure Add_Switches
641 (The_Package : Package_Id;
642 File_Name : String;
643 Index : Int;
644 Program : Make_Program_Type);
645 procedure Add_Switch
646 (S : String_Access;
647 Program : Make_Program_Type;
648 Append_Switch : Boolean := True;
649 And_Save : Boolean := True);
650 procedure Add_Switch
651 (S : String;
652 Program : Make_Program_Type;
653 Append_Switch : Boolean := True;
654 And_Save : Boolean := True);
655 -- Make invokes one of three programs (the compiler, the binder or the
656 -- linker). For the sake of convenience, some program specific switches
657 -- can be passed directly on the gnatmake commande line. This procedure
658 -- records these switches so that gnamake can pass them to the right
659 -- program. S is the switch to be added at the end of the command line
660 -- for Program if Append_Switch is True. If Append_Switch is False S is
661 -- added at the beginning of the command line.
663 procedure Check
664 (Source_File : File_Name_Type;
665 Source_Index : Int;
666 The_Args : Argument_List;
667 Lib_File : File_Name_Type;
668 Read_Only : Boolean;
669 ALI : out ALI_Id;
670 O_File : out File_Name_Type;
671 O_Stamp : out Time_Stamp_Type);
672 -- Determines whether the library file Lib_File is up-to-date or not. The
673 -- full name (with path information) of the object file corresponding to
674 -- Lib_File is returned in O_File. Its time stamp is saved in O_Stamp.
675 -- ALI is the ALI_Id corresponding to Lib_File. If Lib_File in not
676 -- up-to-date, then the corresponding source file needs to be recompiled.
677 -- In this case ALI = No_ALI_Id.
679 procedure Check_Linker_Options
680 (E_Stamp : Time_Stamp_Type;
681 O_File : out File_Name_Type;
682 O_Stamp : out Time_Stamp_Type);
683 -- Checks all linker options for linker files that are newer
684 -- than E_Stamp. If such objects are found, the youngest object
685 -- is returned in O_File and its stamp in O_Stamp.
687 -- If no obsolete linker files were found, the first missing
688 -- linker file is returned in O_File and O_Stamp is empty.
689 -- Otherwise O_File is No_File.
691 procedure Collect_Arguments
692 (Source_File : File_Name_Type;
693 Source_Index : Int;
694 Args : Argument_List);
695 -- Collect all arguments for a source to be compiled, including those
696 -- that come from a project file.
698 procedure Display (Program : String; Args : Argument_List);
699 -- Displays Program followed by the arguments in Args if variable
700 -- Display_Executed_Programs is set. The lower bound of Args must be 1.
702 -----------------
703 -- Mapping files
704 -----------------
706 type Temp_File_Names is
707 array (Project_Id range <>, Positive range <>) of Name_Id;
709 type Temp_Files_Ptr is access Temp_File_Names;
711 type Indices is array (Project_Id range <>) of Natural;
713 type Indices_Ptr is access Indices;
715 type Free_File_Indices is array
716 (Project_Id range <>, Positive range <>) of Positive;
718 type Free_Indices_Ptr is access Free_File_Indices;
720 The_Mapping_File_Names : Temp_Files_Ptr;
721 -- For each project, the name ids of the temporary mapping files used
723 Last_Mapping_File_Names : Indices_Ptr;
724 -- For each project, the index of the last mapping file created
726 The_Free_Mapping_File_Indices : Free_Indices_Ptr;
727 -- For each project, the indices in The_Mapping_File_Names of the mapping
728 -- file names that can be reused for subsequent compilations.
730 Last_Free_Indices : Indices_Ptr;
731 -- For each project, the number of mapping files that can be reused
733 Gnatmake_Mapping_File : String_Access := null;
734 -- The path name of a mapping file specified by switch -C=
736 procedure Delete_Mapping_Files;
737 -- Delete all temporary mapping files
739 procedure Init_Mapping_File
740 (Project : Project_Id;
741 File_Index : in out Natural);
742 -- Create a new temporary mapping file, and fill it with the project file
743 -- mappings, when using project file(s). The out parameter File_Index is
744 -- the index to the name of the file in the array The_Mapping_File_Names.
746 procedure Delete_Temp_Config_Files;
747 -- Delete all temporary config files
749 procedure Delete_All_Temp_Files;
750 -- Delete all temp files (config files, mapping files, path files)
752 -------------------
753 -- Add_Arguments --
754 -------------------
756 procedure Add_Arguments (Args : Argument_List) is
757 begin
758 if Arguments = null then
759 Arguments := new Argument_List (1 .. Args'Length + 10);
761 else
762 while Last_Argument + Args'Length > Arguments'Last loop
763 declare
764 New_Arguments : constant Argument_List_Access :=
765 new Argument_List (1 .. Arguments'Last * 2);
766 begin
767 New_Arguments (1 .. Last_Argument) :=
768 Arguments (1 .. Last_Argument);
769 Arguments := New_Arguments;
770 end;
771 end loop;
772 end if;
774 Arguments (Last_Argument + 1 .. Last_Argument + Args'Length) := Args;
775 Last_Argument := Last_Argument + Args'Length;
776 end Add_Arguments;
778 --------------------
779 -- Add_Dependency --
780 --------------------
782 procedure Add_Dependency (S : Name_Id; On : Name_Id) is
783 begin
784 Dependencies.Increment_Last;
785 Dependencies.Table (Dependencies.Last) := (S, On);
786 end Add_Dependency;
788 --------------------
789 -- Add_Object_Dir --
790 --------------------
792 procedure Add_Object_Dir (N : String) is
793 begin
794 Add_Lib_Search_Dir (N);
796 if Verbose_Mode then
797 Write_Str ("Adding object directory """);
798 Write_Str (N);
799 Write_Str (""".");
800 Write_Eol;
801 end if;
802 end Add_Object_Dir;
804 --------------------
805 -- Add_Source_Dir --
806 --------------------
808 procedure Add_Source_Dir (N : String) is
809 begin
810 Add_Src_Search_Dir (N);
812 if Verbose_Mode then
813 Write_Str ("Adding source directory """);
814 Write_Str (N);
815 Write_Str (""".");
816 Write_Eol;
817 end if;
818 end Add_Source_Dir;
820 ----------------
821 -- Add_Switch --
822 ----------------
824 procedure Add_Switch
825 (S : String_Access;
826 Program : Make_Program_Type;
827 Append_Switch : Boolean := True;
828 And_Save : Boolean := True)
830 generic
831 with package T is new Table.Table (<>);
832 procedure Generic_Position (New_Position : out Integer);
833 -- Generic procedure that chooses a position for S in T at the
834 -- beginning or the end, depending on the boolean Append_Switch.
835 -- Calling this procedure may expand the table.
837 ----------------------
838 -- Generic_Position --
839 ----------------------
841 procedure Generic_Position (New_Position : out Integer) is
842 begin
843 T.Increment_Last;
845 if Append_Switch then
846 New_Position := Integer (T.Last);
847 else
848 for J in reverse T.Table_Index_Type'Succ (T.First) .. T.Last loop
849 T.Table (J) := T.Table (T.Table_Index_Type'Pred (J));
850 end loop;
852 New_Position := Integer (T.First);
853 end if;
854 end Generic_Position;
856 procedure Gcc_Switches_Pos is new Generic_Position (Gcc_Switches);
857 procedure Binder_Switches_Pos is new Generic_Position (Binder_Switches);
858 procedure Linker_Switches_Pos is new Generic_Position (Linker_Switches);
860 procedure Saved_Gcc_Switches_Pos is new
861 Generic_Position (Saved_Gcc_Switches);
863 procedure Saved_Binder_Switches_Pos is new
864 Generic_Position (Saved_Binder_Switches);
866 procedure Saved_Linker_Switches_Pos is new
867 Generic_Position (Saved_Linker_Switches);
869 New_Position : Integer;
871 -- Start of processing for Add_Switch
873 begin
874 if And_Save then
875 case Program is
876 when Compiler =>
877 Saved_Gcc_Switches_Pos (New_Position);
878 Saved_Gcc_Switches.Table (New_Position) := S;
880 when Binder =>
881 Saved_Binder_Switches_Pos (New_Position);
882 Saved_Binder_Switches.Table (New_Position) := S;
884 when Linker =>
885 Saved_Linker_Switches_Pos (New_Position);
886 Saved_Linker_Switches.Table (New_Position) := S;
888 when None =>
889 raise Program_Error;
890 end case;
892 else
893 case Program is
894 when Compiler =>
895 Gcc_Switches_Pos (New_Position);
896 Gcc_Switches.Table (New_Position) := S;
898 when Binder =>
899 Binder_Switches_Pos (New_Position);
900 Binder_Switches.Table (New_Position) := S;
902 when Linker =>
903 Linker_Switches_Pos (New_Position);
904 Linker_Switches.Table (New_Position) := S;
906 when None =>
907 raise Program_Error;
908 end case;
909 end if;
910 end Add_Switch;
912 procedure Add_Switch
913 (S : String;
914 Program : Make_Program_Type;
915 Append_Switch : Boolean := True;
916 And_Save : Boolean := True)
918 begin
919 Add_Switch (S => new String'(S),
920 Program => Program,
921 Append_Switch => Append_Switch,
922 And_Save => And_Save);
923 end Add_Switch;
925 ------------------
926 -- Add_Switches --
927 ------------------
929 procedure Add_Switches
930 (The_Package : Package_Id;
931 File_Name : String;
932 Index : Int;
933 Program : Make_Program_Type)
935 Switches : Variable_Value;
936 Switch_List : String_List_Id;
937 Element : String_Element;
939 begin
940 if File_Name'Length > 0 then
941 Name_Len := File_Name'Length;
942 Name_Buffer (1 .. Name_Len) := File_Name;
943 Switches :=
944 Switches_Of
945 (Source_File => Name_Find,
946 Source_File_Name => File_Name,
947 Source_Index => Index,
948 Naming => Project_Tree.Projects.Table
949 (Main_Project).Naming,
950 In_Package => The_Package,
951 Allow_ALI =>
952 Program = Binder or else Program = Linker);
954 case Switches.Kind is
955 when Undefined =>
956 null;
958 when List =>
959 Program_Args := Program;
961 Switch_List := Switches.Values;
963 while Switch_List /= Nil_String loop
964 Element :=
965 Project_Tree.String_Elements.Table (Switch_List);
966 Get_Name_String (Element.Value);
968 if Name_Len > 0 then
969 declare
970 Argv : constant String := Name_Buffer (1 .. Name_Len);
971 -- We need a copy, because Name_Buffer may be
972 -- modified.
974 begin
975 if Verbose_Mode then
976 Write_Str (" Adding ");
977 Write_Line (Argv);
978 end if;
980 Scan_Make_Arg (Argv, And_Save => False);
981 end;
982 end if;
984 Switch_List := Element.Next;
985 end loop;
987 when Single =>
988 Program_Args := Program;
989 Get_Name_String (Switches.Value);
991 if Name_Len > 0 then
992 declare
993 Argv : constant String := Name_Buffer (1 .. Name_Len);
994 -- We need a copy, because Name_Buffer may be modified
996 begin
997 if Verbose_Mode then
998 Write_Str (" Adding ");
999 Write_Line (Argv);
1000 end if;
1002 Scan_Make_Arg (Argv, And_Save => False);
1003 end;
1004 end if;
1005 end case;
1006 end if;
1007 end Add_Switches;
1009 ----------
1010 -- Bind --
1011 ----------
1013 procedure Bind (ALI_File : File_Name_Type; Args : Argument_List) is
1014 Bind_Args : Argument_List (1 .. Args'Last + 2);
1015 Bind_Last : Integer;
1016 Success : Boolean;
1018 begin
1019 pragma Assert (Args'First = 1);
1021 -- Optimize the simple case where the gnatbind command line looks like
1022 -- gnatbind -aO. -I- file.ali --into-> gnatbind file.adb
1024 if Args'Length = 2
1025 and then Args (Args'First).all = "-aO" & Normalized_CWD
1026 and then Args (Args'Last).all = "-I-"
1027 and then ALI_File = Strip_Directory (ALI_File)
1028 then
1029 Bind_Last := Args'First - 1;
1031 else
1032 Bind_Last := Args'Last;
1033 Bind_Args (Args'Range) := Args;
1034 end if;
1036 -- It is completely pointless to re-check source file time stamps.
1037 -- This has been done already by gnatmake
1039 Bind_Last := Bind_Last + 1;
1040 Bind_Args (Bind_Last) := Do_Not_Check_Flag;
1042 Get_Name_String (ALI_File);
1044 Bind_Last := Bind_Last + 1;
1045 Bind_Args (Bind_Last) := new String'(Name_Buffer (1 .. Name_Len));
1047 GNAT.OS_Lib.Normalize_Arguments (Bind_Args (Args'First .. Bind_Last));
1049 Display (Gnatbind.all, Bind_Args (Args'First .. Bind_Last));
1051 if Gnatbind_Path = null then
1052 Make_Failed ("error, unable to locate ", Gnatbind.all);
1053 end if;
1055 GNAT.OS_Lib.Spawn
1056 (Gnatbind_Path.all, Bind_Args (Args'First .. Bind_Last), Success);
1058 if not Success then
1059 raise Bind_Failed;
1060 end if;
1061 end Bind;
1063 --------------------------------
1064 -- Change_To_Object_Directory --
1065 --------------------------------
1067 procedure Change_To_Object_Directory (Project : Project_Id) is
1068 Actual_Project : Project_Id;
1070 begin
1071 -- For sources outside of any project, compilation occurs in the object
1072 -- directory of the main project, otherwise we use the project given.
1074 if Project = No_Project then
1075 Actual_Project := Main_Project;
1076 else
1077 Actual_Project := Project;
1078 end if;
1080 -- Nothing to do if the current working directory is already the correct
1081 -- object directory.
1083 if Project_Object_Directory /= Actual_Project then
1084 Project_Object_Directory := Actual_Project;
1086 -- Set the working directory to the object directory of the actual
1087 -- project.
1089 Change_Dir
1090 (Get_Name_String
1091 (Project_Tree.Projects.Table
1092 (Actual_Project).Object_Directory));
1094 end if;
1096 exception
1097 -- Fail if unable to change to the object directory
1099 when Directory_Error =>
1100 Make_Failed ("unable to change to object directory """ &
1101 Get_Name_String
1102 (Project_Tree.Projects.Table
1103 (Actual_Project).Object_Directory) &
1104 """ of project " &
1105 Get_Name_String (Project_Tree.Projects.Table
1106 (Actual_Project).Display_Name));
1107 end Change_To_Object_Directory;
1109 -----------
1110 -- Check --
1111 -----------
1113 procedure Check
1114 (Source_File : File_Name_Type;
1115 Source_Index : Int;
1116 The_Args : Argument_List;
1117 Lib_File : File_Name_Type;
1118 Read_Only : Boolean;
1119 ALI : out ALI_Id;
1120 O_File : out File_Name_Type;
1121 O_Stamp : out Time_Stamp_Type)
1123 function First_New_Spec (A : ALI_Id) return File_Name_Type;
1124 -- Looks in the with table entries of A and returns the spec file name
1125 -- of the first withed unit (subprogram) for which no spec existed when
1126 -- A was generated but for which there exists one now, implying that A
1127 -- is now obsolete. If no such unit is found No_File is returned.
1128 -- Otherwise the spec file name of the unit is returned.
1130 -- **WARNING** in the event of Uname format modifications, one *MUST*
1131 -- make sure this function is also updated.
1133 -- Note: This function should really be in ali.adb and use Uname
1134 -- services, but this causes the whole compiler to be dragged along
1135 -- for gnatbind and gnatmake.
1137 --------------------
1138 -- First_New_Spec --
1139 --------------------
1141 function First_New_Spec (A : ALI_Id) return File_Name_Type is
1142 Spec_File_Name : File_Name_Type := No_File;
1144 function New_Spec (Uname : Unit_Name_Type) return Boolean;
1145 -- Uname is the name of the spec or body of some ada unit.
1146 -- This function returns True if the Uname is the name of a body
1147 -- which has a spec not mentioned inali file A. If True is returned
1148 -- Spec_File_Name above is set to the name of this spec file.
1150 --------------
1151 -- New_Spec --
1152 --------------
1154 function New_Spec (Uname : Unit_Name_Type) return Boolean is
1155 Spec_Name : Unit_Name_Type;
1156 File_Name : File_Name_Type;
1158 begin
1159 -- Test whether Uname is the name of a body unit (ie ends with %b)
1161 Get_Name_String (Uname);
1162 pragma
1163 Assert (Name_Len > 2 and then Name_Buffer (Name_Len - 1) = '%');
1165 if Name_Buffer (Name_Len) /= 'b' then
1166 return False;
1167 end if;
1169 -- Convert unit name into spec name
1171 -- ??? this code seems dubious in presence of pragma
1172 -- Source_File_Name since there is no more direct relationship
1173 -- between unit name and file name.
1175 -- ??? Further, what about alternative subunit naming
1177 Name_Buffer (Name_Len) := 's';
1178 Spec_Name := Name_Find;
1179 File_Name := Get_File_Name (Spec_Name, Subunit => False);
1181 -- Look if File_Name is mentioned in A's sdep list.
1182 -- If not look if the file exists. If it does return True.
1184 for D in
1185 ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep
1186 loop
1187 if Sdep.Table (D).Sfile = File_Name then
1188 return False;
1189 end if;
1190 end loop;
1192 if Full_Source_Name (File_Name) /= No_File then
1193 Spec_File_Name := File_Name;
1194 return True;
1195 end if;
1197 return False;
1198 end New_Spec;
1200 -- Start of processing for First_New_Spec
1202 begin
1203 U_Chk : for U in
1204 ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit
1205 loop
1206 exit U_Chk when Units.Table (U).Utype = Is_Body_Only
1207 and then New_Spec (Units.Table (U).Uname);
1209 for W in Units.Table (U).First_With
1211 Units.Table (U).Last_With
1212 loop
1213 exit U_Chk when
1214 Withs.Table (W).Afile /= No_File
1215 and then New_Spec (Withs.Table (W).Uname);
1216 end loop;
1217 end loop U_Chk;
1219 return Spec_File_Name;
1220 end First_New_Spec;
1222 ---------------------------------
1223 -- Data declarations for Check --
1224 ---------------------------------
1226 Full_Lib_File : File_Name_Type;
1227 -- Full name of current library file
1229 Full_Obj_File : File_Name_Type;
1230 -- Full name of the object file corresponding to Lib_File
1232 Lib_Stamp : Time_Stamp_Type;
1233 -- Time stamp of the current ada library file
1235 Obj_Stamp : Time_Stamp_Type;
1236 -- Time stamp of the current object file
1238 Modified_Source : File_Name_Type;
1239 -- The first source in Lib_File whose current time stamp differs
1240 -- from that stored in Lib_File.
1242 New_Spec : File_Name_Type;
1243 -- If Lib_File contains in its W (with) section a body (for a
1244 -- subprogram) for which there exists a spec and the spec did not
1245 -- appear in the Sdep section of Lib_File, New_Spec contains the file
1246 -- name of this new spec.
1248 Source_Name : Name_Id;
1249 Text : Text_Buffer_Ptr;
1251 Prev_Switch : String_Access;
1252 -- Previous switch processed
1254 Arg : Arg_Id := Arg_Id'First;
1255 -- Current index in Args.Table for a given unit (init to stop warning)
1257 Switch_Found : Boolean;
1258 -- True if a given switch has been found
1260 -- Start of processing for Check
1262 begin
1263 pragma Assert (Lib_File /= No_File);
1265 -- If the ALI file is read-only, set temporarily
1266 -- Check_Object_Consistency to False: we don't care if the object file
1267 -- is not there; presumably, a library will be used for linking.
1269 if Read_Only then
1270 declare
1271 Saved_Check_Object_Consistency : constant Boolean :=
1272 Check_Object_Consistency;
1273 begin
1274 Check_Object_Consistency := False;
1275 Text := Read_Library_Info (Lib_File);
1276 Check_Object_Consistency := Saved_Check_Object_Consistency;
1277 end;
1279 else
1280 Text := Read_Library_Info (Lib_File);
1281 end if;
1283 Full_Lib_File := Full_Library_Info_Name;
1284 Full_Obj_File := Full_Object_File_Name;
1285 Lib_Stamp := Current_Library_File_Stamp;
1286 Obj_Stamp := Current_Object_File_Stamp;
1288 if Full_Lib_File = No_File then
1289 Verbose_Msg (Lib_File, "being checked ...", Prefix => " ");
1290 else
1291 Verbose_Msg (Full_Lib_File, "being checked ...", Prefix => " ");
1292 end if;
1294 ALI := No_ALI_Id;
1295 O_File := Full_Obj_File;
1296 O_Stamp := Obj_Stamp;
1298 if Text = null then
1299 if Full_Lib_File = No_File then
1300 Verbose_Msg (Lib_File, "missing.");
1302 elsif Obj_Stamp (Obj_Stamp'First) = ' ' then
1303 Verbose_Msg (Full_Obj_File, "missing.");
1305 else
1306 Verbose_Msg
1307 (Full_Lib_File, "(" & String (Lib_Stamp) & ") newer than",
1308 Full_Obj_File, "(" & String (Obj_Stamp) & ")");
1309 end if;
1311 else
1312 ALI := Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
1313 Free (Text);
1315 if ALI = No_ALI_Id then
1316 Verbose_Msg (Full_Lib_File, "incorrectly formatted ALI file");
1317 return;
1319 elsif ALIs.Table (ALI).Ver (1 .. ALIs.Table (ALI).Ver_Len) /=
1320 Verbose_Library_Version
1321 then
1322 Verbose_Msg (Full_Lib_File, "compiled with old GNAT version");
1323 ALI := No_ALI_Id;
1324 return;
1325 end if;
1327 -- Don't take Ali file into account if it was generated with
1328 -- errors.
1330 if ALIs.Table (ALI).Compile_Errors then
1331 Verbose_Msg (Full_Lib_File, "had errors, must be recompiled");
1332 ALI := No_ALI_Id;
1333 return;
1334 end if;
1336 -- Don't take Ali file into account if it was generated without
1337 -- object.
1339 if Operating_Mode /= Check_Semantics
1340 and then ALIs.Table (ALI).No_Object
1341 then
1342 Verbose_Msg (Full_Lib_File, "has no corresponding object");
1343 ALI := No_ALI_Id;
1344 return;
1345 end if;
1347 -- Check for matching compiler switches if needed
1349 if Check_Switches then
1351 -- First, collect all the switches
1353 Collect_Arguments (Source_File, Source_Index, The_Args);
1355 Prev_Switch := Dummy_Switch;
1357 Get_Name_String (ALIs.Table (ALI).Sfile);
1359 Switches_To_Check.Set_Last (0);
1361 for J in 1 .. Last_Argument loop
1363 -- Skip non switches -c, -I and -o switches
1365 if Arguments (J) (1) = '-'
1366 and then Arguments (J) (2) /= 'c'
1367 and then Arguments (J) (2) /= 'o'
1368 and then Arguments (J) (2) /= 'I'
1369 then
1370 Normalize_Compiler_Switches
1371 (Arguments (J).all,
1372 Normalized_Switches,
1373 Last_Norm_Switch);
1375 for K in 1 .. Last_Norm_Switch loop
1376 Switches_To_Check.Increment_Last;
1377 Switches_To_Check.Table (Switches_To_Check.Last) :=
1378 Normalized_Switches (K);
1379 end loop;
1380 end if;
1381 end loop;
1383 for J in 1 .. Switches_To_Check.Last loop
1385 -- Comparing switches is delicate because gcc reorders
1386 -- a number of switches, according to lang-specs.h, but
1387 -- gnatmake doesn't have the sufficient knowledge to
1388 -- perform the same reordering. Instead, we ignore orders
1389 -- between different "first letter" switches, but keep
1390 -- orders between same switches, e.g -O -O2 is different
1391 -- than -O2 -O, but -g -O is equivalent to -O -g.
1393 if Switches_To_Check.Table (J) (2) /= Prev_Switch (2) or else
1394 (Prev_Switch'Length >= 6 and then
1395 Prev_Switch (2 .. 5) = "gnat" and then
1396 Switches_To_Check.Table (J)'Length >= 6 and then
1397 Switches_To_Check.Table (J) (2 .. 5) = "gnat" and then
1398 Prev_Switch (6) /= Switches_To_Check.Table (J) (6))
1399 then
1400 Prev_Switch := Switches_To_Check.Table (J);
1401 Arg :=
1402 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg;
1403 end if;
1405 Switch_Found := False;
1407 for K in Arg ..
1408 Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1409 loop
1411 Switches_To_Check.Table (J).all = Args.Table (K).all
1412 then
1413 Arg := K + 1;
1414 Switch_Found := True;
1415 exit;
1416 end if;
1417 end loop;
1419 if not Switch_Found then
1420 if Verbose_Mode then
1421 Verbose_Msg (ALIs.Table (ALI).Sfile,
1422 "switch mismatch """ &
1423 Switches_To_Check.Table (J).all & '"');
1424 end if;
1426 ALI := No_ALI_Id;
1427 return;
1428 end if;
1429 end loop;
1431 if Switches_To_Check.Last /=
1432 Integer (Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg -
1433 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg + 1)
1434 then
1435 if Verbose_Mode then
1436 Verbose_Msg (ALIs.Table (ALI).Sfile,
1437 "different number of switches");
1439 for K in Units.Table (ALIs.Table (ALI).First_Unit).First_Arg
1440 .. Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1441 loop
1442 Write_Str (Args.Table (K).all);
1443 Write_Char (' ');
1444 end loop;
1446 Write_Eol;
1448 for J in 1 .. Switches_To_Check.Last loop
1449 Write_Str (Switches_To_Check.Table (J).all);
1450 Write_Char (' ');
1451 end loop;
1453 Write_Eol;
1454 end if;
1456 ALI := No_ALI_Id;
1457 return;
1458 end if;
1459 end if;
1461 -- Get the source files and their message digests. Note that some
1462 -- sources may be missing if ALI is out-of-date.
1464 Set_Source_Table (ALI);
1466 Modified_Source := Time_Stamp_Mismatch (ALI, Read_Only);
1468 if Modified_Source /= No_File then
1469 ALI := No_ALI_Id;
1471 if Verbose_Mode then
1472 Source_Name := Full_Source_Name (Modified_Source);
1474 if Source_Name /= No_File then
1475 Verbose_Msg (Source_Name, "time stamp mismatch");
1476 else
1477 Verbose_Msg (Modified_Source, "missing");
1478 end if;
1479 end if;
1481 else
1482 New_Spec := First_New_Spec (ALI);
1484 if New_Spec /= No_File then
1485 ALI := No_ALI_Id;
1487 if Verbose_Mode then
1488 Source_Name := Full_Source_Name (New_Spec);
1490 if Source_Name /= No_File then
1491 Verbose_Msg (Source_Name, "new spec");
1492 else
1493 Verbose_Msg (New_Spec, "old spec missing");
1494 end if;
1495 end if;
1496 end if;
1497 end if;
1498 end if;
1499 end Check;
1501 ------------------------
1502 -- Check_For_S_Switch --
1503 ------------------------
1505 procedure Check_For_S_Switch is
1506 begin
1507 -- By default, we generate an object file
1509 Output_Is_Object := True;
1511 for Arg in 1 .. Last_Argument loop
1512 if Arguments (Arg).all = "-S" then
1513 Output_Is_Object := False;
1515 elsif Arguments (Arg).all = "-c" then
1516 Output_Is_Object := True;
1517 end if;
1518 end loop;
1519 end Check_For_S_Switch;
1521 --------------------------
1522 -- Check_Linker_Options --
1523 --------------------------
1525 procedure Check_Linker_Options
1526 (E_Stamp : Time_Stamp_Type;
1527 O_File : out File_Name_Type;
1528 O_Stamp : out Time_Stamp_Type)
1530 procedure Check_File (File : File_Name_Type);
1531 -- Update O_File and O_Stamp if the given file is younger than E_Stamp
1532 -- and O_Stamp, or if O_File is No_File and File does not exist.
1534 function Get_Library_File (Name : String) return File_Name_Type;
1535 -- Return the full file name including path of a library based
1536 -- on the name specified with the -l linker option, using the
1537 -- Ada object path. Return No_File if no such file can be found.
1539 type Char_Array is array (Natural) of Character;
1540 type Char_Array_Access is access constant Char_Array;
1542 Template : Char_Array_Access;
1543 pragma Import (C, Template, "__gnat_library_template");
1545 ----------------
1546 -- Check_File --
1547 ----------------
1549 procedure Check_File (File : File_Name_Type) is
1550 Stamp : Time_Stamp_Type;
1551 Name : File_Name_Type := File;
1553 begin
1554 Get_Name_String (Name);
1556 -- Remove any trailing NUL characters
1558 while Name_Len >= Name_Buffer'First
1559 and then Name_Buffer (Name_Len) = NUL
1560 loop
1561 Name_Len := Name_Len - 1;
1562 end loop;
1564 if Name_Len <= 0 then
1565 return;
1567 elsif Name_Buffer (1) = '-' then
1569 -- Do not check if File is a switch other than "-l"
1571 if Name_Buffer (2) /= 'l' then
1572 return;
1573 end if;
1575 -- The argument is a library switch, get actual name. It
1576 -- is necessary to make a copy of the relevant part of
1577 -- Name_Buffer as Get_Library_Name uses Name_Buffer as well.
1579 declare
1580 Base_Name : constant String := Name_Buffer (3 .. Name_Len);
1582 begin
1583 Name := Get_Library_File (Base_Name);
1584 end;
1586 if Name = No_File then
1587 return;
1588 end if;
1589 end if;
1591 Stamp := File_Stamp (Name);
1593 -- Find the youngest object file that is younger than the
1594 -- executable. If no such file exist, record the first object
1595 -- file that is not found.
1597 if (O_Stamp < Stamp and then E_Stamp < Stamp)
1598 or else (O_File = No_File and then Stamp (Stamp'First) = ' ')
1599 then
1600 O_Stamp := Stamp;
1601 O_File := Name;
1603 -- Strip the trailing NUL if present
1605 Get_Name_String (O_File);
1607 if Name_Buffer (Name_Len) = NUL then
1608 Name_Len := Name_Len - 1;
1609 O_File := Name_Find;
1610 end if;
1611 end if;
1612 end Check_File;
1614 ----------------------
1615 -- Get_Library_Name --
1616 ----------------------
1618 -- See comments in a-adaint.c about template syntax
1620 function Get_Library_File (Name : String) return File_Name_Type is
1621 File : File_Name_Type := No_File;
1623 begin
1624 Name_Len := 0;
1626 for Ptr in Template'Range loop
1627 case Template (Ptr) is
1628 when '*' =>
1629 Add_Str_To_Name_Buffer (Name);
1631 when ';' =>
1632 File := Full_Lib_File_Name (Name_Find);
1633 exit when File /= No_File;
1634 Name_Len := 0;
1636 when NUL =>
1637 exit;
1639 when others =>
1640 Add_Char_To_Name_Buffer (Template (Ptr));
1641 end case;
1642 end loop;
1644 -- The for loop exited because the end of the template
1645 -- was reached. File contains the last possible file name
1646 -- for the library.
1648 if File = No_File and then Name_Len > 0 then
1649 File := Full_Lib_File_Name (Name_Find);
1650 end if;
1652 return File;
1653 end Get_Library_File;
1655 -- Start of processing for Check_Linker_Options
1657 begin
1658 O_File := No_File;
1659 O_Stamp := (others => ' ');
1661 -- Process linker options from the ALI files
1663 for Opt in 1 .. Linker_Options.Last loop
1664 Check_File (Linker_Options.Table (Opt).Name);
1665 end loop;
1667 -- Process options given on the command line
1669 for Opt in Linker_Switches.First .. Linker_Switches.Last loop
1671 -- Check if the previous Opt has one of the two switches
1672 -- that take an extra parameter. (See GCC manual.)
1674 if Opt = Linker_Switches.First
1675 or else (Linker_Switches.Table (Opt - 1).all /= "-u"
1676 and then
1677 Linker_Switches.Table (Opt - 1).all /= "-Xlinker"
1678 and then
1679 Linker_Switches.Table (Opt - 1).all /= "-L")
1680 then
1681 Name_Len := 0;
1682 Add_Str_To_Name_Buffer (Linker_Switches.Table (Opt).all);
1683 Check_File (Name_Find);
1684 end if;
1685 end loop;
1687 end Check_Linker_Options;
1689 -----------------
1690 -- Check_Steps --
1691 -----------------
1693 procedure Check_Steps is
1694 begin
1695 -- If either -c, -b or -l has been specified, we will not necessarily
1696 -- execute all steps.
1698 if Make_Steps then
1699 Do_Compile_Step := Do_Compile_Step and Compile_Only;
1700 Do_Bind_Step := Do_Bind_Step and Bind_Only;
1701 Do_Link_Step := Do_Link_Step and Link_Only;
1703 -- If -c has been specified, but not -b, ignore any potential -l
1705 if Do_Compile_Step and then not Do_Bind_Step then
1706 Do_Link_Step := False;
1707 end if;
1708 end if;
1709 end Check_Steps;
1711 -----------------------
1712 -- Collect_Arguments --
1713 -----------------------
1715 procedure Collect_Arguments
1716 (Source_File : File_Name_Type;
1717 Source_Index : Int;
1718 Args : Argument_List)
1720 begin
1721 Arguments_Collected := True;
1722 Arguments_Project := No_Project;
1723 Last_Argument := 0;
1724 Add_Arguments (Args);
1726 if Main_Project /= No_Project then
1727 declare
1728 Source_File_Name : constant String :=
1729 Get_Name_String (Source_File);
1730 Compiler_Package : Prj.Package_Id;
1731 Switches : Prj.Variable_Value;
1732 Data : Project_Data;
1734 begin
1735 Prj.Env.
1736 Get_Reference
1737 (Source_File_Name => Source_File_Name,
1738 Project => Arguments_Project,
1739 Path => Arguments_Path_Name,
1740 In_Tree => Project_Tree);
1742 -- If the source is not a source of a project file, check if
1743 -- this is allowed.
1745 if Arguments_Project = No_Project then
1746 if not External_Unit_Compilation_Allowed then
1747 Make_Failed ("external source (", Source_File_Name,
1748 ") is not part of any project; cannot be " &
1749 "compiled without gnatmake switch -x");
1750 end if;
1752 -- If it is allowed, simply add the saved gcc switches
1754 Add_Arguments (The_Saved_Gcc_Switches.all);
1756 else
1757 -- We get the project directory for the relative path
1758 -- switches and arguments.
1760 Data := Project_Tree.Projects.Table (Arguments_Project);
1762 -- If the source is in an extended project, we go to
1763 -- the ultimate extending project.
1765 while Data.Extended_By /= No_Project loop
1766 Arguments_Project := Data.Extended_By;
1767 Data :=
1768 Project_Tree.Projects.Table (Arguments_Project);
1769 end loop;
1771 -- If building a dynamic or relocatable library, compile with
1772 -- PIC option, if it exists.
1774 if Data.Library and then Data.Library_Kind /= Static then
1775 declare
1776 PIC : constant String := MLib.Tgt.PIC_Option;
1778 begin
1779 if PIC /= "" then
1780 Add_Arguments ((1 => new String'(PIC)));
1781 end if;
1782 end;
1783 end if;
1785 if Data.Dir_Path = null then
1786 Data.Dir_Path :=
1787 new String'(Get_Name_String (Data.Display_Directory));
1788 Project_Tree.Projects.Table (Arguments_Project) :=
1789 Data;
1790 end if;
1792 -- We now look for package Compiler
1793 -- and get the switches from this package.
1795 Compiler_Package :=
1796 Prj.Util.Value_Of
1797 (Name => Name_Compiler,
1798 In_Packages => Data.Decl.Packages,
1799 In_Tree => Project_Tree);
1801 if Compiler_Package /= No_Package then
1803 -- If package Gnatmake.Compiler exists, we get
1804 -- the specific switches for the current source,
1805 -- or the global switches, if any.
1807 Switches := Switches_Of
1808 (Source_File => Source_File,
1809 Source_File_Name => Source_File_Name,
1810 Source_Index => Source_Index,
1811 Naming => Data.Naming,
1812 In_Package => Compiler_Package,
1813 Allow_ALI => False);
1815 end if;
1817 case Switches.Kind is
1819 -- We have a list of switches. We add these switches,
1820 -- plus the saved gcc switches.
1822 when List =>
1824 declare
1825 Current : String_List_Id := Switches.Values;
1826 Element : String_Element;
1827 Number : Natural := 0;
1829 begin
1830 while Current /= Nil_String loop
1831 Element := Project_Tree.String_Elements.
1832 Table (Current);
1833 Number := Number + 1;
1834 Current := Element.Next;
1835 end loop;
1837 declare
1838 New_Args : Argument_List (1 .. Number);
1839 Last_New : Natural := 0;
1841 begin
1842 Current := Switches.Values;
1844 for Index in New_Args'Range loop
1845 Element := Project_Tree.String_Elements.
1846 Table (Current);
1847 Get_Name_String (Element.Value);
1849 if Name_Len > 0 then
1850 Last_New := Last_New + 1;
1851 New_Args (Last_New) :=
1852 new String'(Name_Buffer (1 .. Name_Len));
1853 Test_If_Relative_Path
1854 (New_Args (Last_New),
1855 Parent => Data.Dir_Path);
1856 end if;
1858 Current := Element.Next;
1859 end loop;
1861 Add_Arguments
1862 (Configuration_Pragmas_Switch
1863 (Arguments_Project) &
1864 New_Args (1 .. Last_New) &
1865 The_Saved_Gcc_Switches.all);
1866 end;
1867 end;
1869 -- We have a single switch. We add this switch,
1870 -- plus the saved gcc switches.
1872 when Single =>
1873 Get_Name_String (Switches.Value);
1875 declare
1876 New_Args : Argument_List :=
1877 (1 => new String'
1878 (Name_Buffer (1 .. Name_Len)));
1880 begin
1881 Test_If_Relative_Path
1882 (New_Args (1), Parent => Data.Dir_Path);
1883 Add_Arguments
1884 (Configuration_Pragmas_Switch (Arguments_Project) &
1885 New_Args & The_Saved_Gcc_Switches.all);
1886 end;
1888 -- We have no switches from Gnatmake.Compiler.
1889 -- We add the saved gcc switches.
1891 when Undefined =>
1892 Add_Arguments
1893 (Configuration_Pragmas_Switch (Arguments_Project) &
1894 The_Saved_Gcc_Switches.all);
1895 end case;
1896 end if;
1897 end;
1898 end if;
1900 -- Set Output_Is_Object, depending if there is a -S switch.
1901 -- If the bind step is not performed, and there is a -S switch,
1902 -- then we will not check for a valid object file.
1904 Check_For_S_Switch;
1905 end Collect_Arguments;
1907 ---------------------
1908 -- Compile_Sources --
1909 ---------------------
1911 procedure Compile_Sources
1912 (Main_Source : File_Name_Type;
1913 Args : Argument_List;
1914 First_Compiled_File : out Name_Id;
1915 Most_Recent_Obj_File : out Name_Id;
1916 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
1917 Main_Unit : out Boolean;
1918 Compilation_Failures : out Natural;
1919 Main_Index : Int := 0;
1920 Check_Readonly_Files : Boolean := False;
1921 Do_Not_Execute : Boolean := False;
1922 Force_Compilations : Boolean := False;
1923 Keep_Going : Boolean := False;
1924 In_Place_Mode : Boolean := False;
1925 Initialize_ALI_Data : Boolean := True;
1926 Max_Process : Positive := 1)
1928 No_Mapping_File : constant Natural := 0;
1930 type Compilation_Data is record
1931 Pid : Process_Id;
1932 Full_Source_File : File_Name_Type;
1933 Lib_File : File_Name_Type;
1934 Source_Unit : Unit_Name_Type;
1935 Mapping_File : Natural := No_Mapping_File;
1936 Project : Project_Id := No_Project;
1937 Syntax_Only : Boolean := False;
1938 Output_Is_Object : Boolean := True;
1939 end record;
1941 Running_Compile : array (1 .. Max_Process) of Compilation_Data;
1942 -- Used to save information about outstanding compilations
1944 Outstanding_Compiles : Natural := 0;
1945 -- Current number of outstanding compiles
1947 Source_Unit : Unit_Name_Type;
1948 -- Current source unit
1950 Source_File : File_Name_Type;
1951 -- Current source file
1953 Full_Source_File : File_Name_Type;
1954 -- Full name of the current source file
1956 Lib_File : File_Name_Type;
1957 -- Current library file
1959 Full_Lib_File : File_Name_Type;
1960 -- Full name of the current library file
1962 Obj_File : File_Name_Type;
1963 -- Full name of the object file corresponding to Lib_File
1965 Obj_Stamp : Time_Stamp_Type;
1966 -- Time stamp of the current object file
1968 Sfile : File_Name_Type;
1969 -- Contains the source file of the units withed by Source_File
1971 ALI : ALI_Id;
1972 -- ALI Id of the current ALI file
1974 -- Comment following declarations ???
1976 Read_Only : Boolean := False;
1978 Compilation_OK : Boolean;
1979 Need_To_Compile : Boolean;
1981 Pid : Process_Id;
1982 Text : Text_Buffer_Ptr;
1984 Mfile : Natural := No_Mapping_File;
1986 Need_To_Check_Standard_Library : Boolean :=
1987 Check_Readonly_Files
1988 and not Unique_Compile;
1990 Mapping_File_Arg : String_Access;
1992 Process_Created : Boolean := False;
1994 procedure Add_Process
1995 (Pid : Process_Id;
1996 Sfile : File_Name_Type;
1997 Afile : File_Name_Type;
1998 Uname : Unit_Name_Type;
1999 Mfile : Natural := No_Mapping_File);
2000 -- Adds process Pid to the current list of outstanding compilation
2001 -- processes and record the full name of the source file Sfile that
2002 -- we are compiling, the name of its library file Afile and the
2003 -- name of its unit Uname. If Mfile is not equal to No_Mapping_File,
2004 -- it is the index of the mapping file used during compilation in the
2005 -- array The_Mapping_File_Names.
2007 procedure Await_Compile
2008 (Sfile : out File_Name_Type;
2009 Afile : out File_Name_Type;
2010 Uname : out Unit_Name_Type;
2011 OK : out Boolean);
2012 -- Awaits that an outstanding compilation process terminates. When
2013 -- it does set Sfile to the name of the source file that was compiled
2014 -- Afile to the name of its library file and Uname to the name of its
2015 -- unit. Note that this time stamp can be used to check whether the
2016 -- compilation did generate an object file. OK is set to True if the
2017 -- compilation succeeded. Note that Sfile, Afile and Uname could be
2018 -- resp. No_File, No_File and No_Name if there were no compilations
2019 -- to wait for.
2021 function Bad_Compilation_Count return Natural;
2022 -- Returns the number of compilation failures
2024 procedure Check_Standard_Library;
2025 -- Check if s-stalib.adb needs to be compiled
2027 procedure Collect_Arguments_And_Compile
2028 (Source_File : File_Name_Type; Source_Index : Int);
2029 -- Collect arguments from project file (if any) and compile
2031 function Compile
2032 (S : Name_Id;
2033 L : Name_Id;
2034 Source_Index : Int;
2035 Args : Argument_List) return Process_Id;
2036 -- Compiles S using Args. If S is a GNAT predefined source
2037 -- "-gnatpg" is added to Args. Non blocking call. L corresponds to the
2038 -- expected library file name. Process_Id of the process spawned to
2039 -- execute the compile.
2041 package Good_ALI is new Table.Table (
2042 Table_Component_Type => ALI_Id,
2043 Table_Index_Type => Natural,
2044 Table_Low_Bound => 1,
2045 Table_Initial => 50,
2046 Table_Increment => 100,
2047 Table_Name => "Make.Good_ALI");
2048 -- Contains the set of valid ALI files that have not yet been scanned
2050 function Good_ALI_Present return Boolean;
2051 -- Returns True if any ALI file was recorded in the previous set
2053 procedure Get_Mapping_File (Project : Project_Id);
2054 -- Get a mapping file name. If there is one to be reused, reuse it.
2055 -- Otherwise, create a new mapping file.
2057 function Get_Next_Good_ALI return ALI_Id;
2058 -- Returns the next good ALI_Id record
2060 procedure Record_Failure
2061 (File : File_Name_Type;
2062 Unit : Unit_Name_Type;
2063 Found : Boolean := True);
2064 -- Records in the previous table that the compilation for File failed.
2065 -- If Found is False then the compilation of File failed because we
2066 -- could not find it. Records also Unit when possible.
2068 procedure Record_Good_ALI (A : ALI_Id);
2069 -- Records in the previous set the Id of an ALI file
2071 -----------------
2072 -- Add_Process --
2073 -----------------
2075 procedure Add_Process
2076 (Pid : Process_Id;
2077 Sfile : File_Name_Type;
2078 Afile : File_Name_Type;
2079 Uname : Unit_Name_Type;
2080 Mfile : Natural := No_Mapping_File)
2082 OC1 : constant Positive := Outstanding_Compiles + 1;
2084 begin
2085 pragma Assert (OC1 <= Max_Process);
2086 pragma Assert (Pid /= Invalid_Pid);
2088 Running_Compile (OC1).Pid := Pid;
2089 Running_Compile (OC1).Full_Source_File := Sfile;
2090 Running_Compile (OC1).Lib_File := Afile;
2091 Running_Compile (OC1).Source_Unit := Uname;
2092 Running_Compile (OC1).Mapping_File := Mfile;
2093 Running_Compile (OC1).Project := Arguments_Project;
2094 Running_Compile (OC1).Syntax_Only := Syntax_Only;
2095 Running_Compile (OC1).Output_Is_Object := Output_Is_Object;
2097 Outstanding_Compiles := OC1;
2098 end Add_Process;
2100 --------------------
2101 -- Await_Compile --
2102 -------------------
2104 procedure Await_Compile
2105 (Sfile : out File_Name_Type;
2106 Afile : out File_Name_Type;
2107 Uname : out File_Name_Type;
2108 OK : out Boolean)
2110 Pid : Process_Id;
2111 Project : Project_Id;
2113 begin
2114 pragma Assert (Outstanding_Compiles > 0);
2116 Sfile := No_File;
2117 Afile := No_File;
2118 Uname := No_Name;
2119 OK := False;
2121 -- The loop here is a work-around for a problem on VMS; in some
2122 -- circumstances (shared library and several executables, for
2123 -- example), there are child processes other than compilation
2124 -- processes that are received. Until this problem is resolved,
2125 -- we will ignore such processes.
2127 loop
2128 Wait_Process (Pid, OK);
2130 if Pid = Invalid_Pid then
2131 return;
2132 end if;
2134 for J in Running_Compile'First .. Outstanding_Compiles loop
2135 if Pid = Running_Compile (J).Pid then
2136 Sfile := Running_Compile (J).Full_Source_File;
2137 Afile := Running_Compile (J).Lib_File;
2138 Uname := Running_Compile (J).Source_Unit;
2139 Syntax_Only := Running_Compile (J).Syntax_Only;
2140 Output_Is_Object := Running_Compile (J).Output_Is_Object;
2141 Project := Running_Compile (J).Project;
2143 -- If a mapping file was used by this compilation,
2144 -- get its file name for reuse by a subsequent compilation
2146 if Running_Compile (J).Mapping_File /= No_Mapping_File then
2147 Last_Free_Indices (Project) :=
2148 Last_Free_Indices (Project) + 1;
2149 The_Free_Mapping_File_Indices
2150 (Project, Last_Free_Indices (Project)) :=
2151 Running_Compile (J).Mapping_File;
2152 end if;
2154 -- To actually remove this Pid and related info from
2155 -- Running_Compile replace its entry with the last valid
2156 -- entry in Running_Compile.
2158 if J = Outstanding_Compiles then
2159 null;
2161 else
2162 Running_Compile (J) :=
2163 Running_Compile (Outstanding_Compiles);
2164 end if;
2166 Outstanding_Compiles := Outstanding_Compiles - 1;
2167 return;
2168 end if;
2169 end loop;
2171 -- This child process was not one of our compilation processes;
2172 -- just ignore it for now.
2174 -- raise Program_Error;
2175 end loop;
2176 end Await_Compile;
2178 ---------------------------
2179 -- Bad_Compilation_Count --
2180 ---------------------------
2182 function Bad_Compilation_Count return Natural is
2183 begin
2184 return Bad_Compilation.Last - Bad_Compilation.First + 1;
2185 end Bad_Compilation_Count;
2187 ----------------------------
2188 -- Check_Standard_Library --
2189 ----------------------------
2191 procedure Check_Standard_Library is
2192 begin
2193 Need_To_Check_Standard_Library := False;
2195 if not Targparm.Suppress_Standard_Library_On_Target then
2196 declare
2197 Sfile : Name_Id;
2198 Add_It : Boolean := True;
2200 begin
2201 Name_Len := Standard_Library_Package_Body_Name'Length;
2202 Name_Buffer (1 .. Name_Len) :=
2203 Standard_Library_Package_Body_Name;
2204 Sfile := Name_Enter;
2206 -- If we have a special runtime, we add the standard
2207 -- library only if we can find it.
2209 if RTS_Switch then
2210 Add_It :=
2211 Find_File (Sfile, Osint.Source) /= No_File;
2212 end if;
2214 if Add_It then
2215 if Is_Marked (Sfile) then
2216 if Is_In_Obsoleted (Sfile) then
2217 Executable_Obsolete := True;
2218 end if;
2220 else
2221 Insert_Q (Sfile, Index => 0);
2222 Mark (Sfile, Index => 0);
2223 end if;
2224 end if;
2225 end;
2226 end if;
2227 end Check_Standard_Library;
2229 -----------------------------------
2230 -- Collect_Arguments_And_Compile --
2231 -----------------------------------
2233 procedure Collect_Arguments_And_Compile
2234 (Source_File : File_Name_Type; Source_Index : Int)
2236 begin
2237 -- Process_Created will be set True if an attempt is made to compile
2238 -- the source, that is if it is not in an externally built project.
2240 Process_Created := False;
2242 -- If arguments not yet collected (in Check), collect them now
2244 if not Arguments_Collected then
2245 Collect_Arguments (Source_File, Source_Index, Args);
2246 end if;
2248 -- If we use mapping file (-P or -C switches), then get one
2250 if Create_Mapping_File then
2251 Get_Mapping_File (Arguments_Project);
2252 end if;
2254 -- If the source is part of a project file, we set the ADA_*_PATHs,
2255 -- check for an eventual library project, and use the full path.
2257 if Arguments_Project /= No_Project then
2258 if not Project_Tree.Projects.Table
2259 (Arguments_Project).Externally_Built
2260 then
2261 Prj.Env.Set_Ada_Paths
2262 (Arguments_Project, Project_Tree, True);
2264 if not Unique_Compile
2265 and then MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None
2266 then
2267 declare
2268 The_Data : Project_Data :=
2269 Project_Tree.Projects.Table
2270 (Arguments_Project);
2272 Prj : Project_Id := Arguments_Project;
2274 begin
2275 while The_Data.Extended_By /= No_Project loop
2276 Prj := The_Data.Extended_By;
2277 The_Data := Project_Tree.Projects.Table (Prj);
2278 end loop;
2280 if The_Data.Library
2281 and then not The_Data.Need_To_Build_Lib
2282 then
2283 -- Add to the Q all sources of the project that
2284 -- have not been marked
2286 Insert_Project_Sources
2287 (The_Project => Prj,
2288 All_Projects => False,
2289 Into_Q => True);
2291 -- Now mark the project as processed
2293 Project_Tree.Projects.Table
2294 (Prj).Need_To_Build_Lib := True;
2295 end if;
2296 end;
2297 end if;
2299 -- Change to the object directory of the project file,
2300 -- if necessary.
2302 Change_To_Object_Directory (Arguments_Project);
2304 Pid := Compile (Arguments_Path_Name, Lib_File, Source_Index,
2305 Arguments (1 .. Last_Argument));
2306 Process_Created := True;
2307 end if;
2309 else
2310 -- If this is a source outside of any project file, make sure it
2311 -- will be compiled in object directory of the main project file.
2313 if Main_Project /= No_Project then
2314 Change_To_Object_Directory (Arguments_Project);
2315 end if;
2317 Pid := Compile (Full_Source_File, Lib_File, Source_Index,
2318 Arguments (1 .. Last_Argument));
2319 Process_Created := True;
2320 end if;
2321 end Collect_Arguments_And_Compile;
2323 -------------
2324 -- Compile --
2325 -------------
2327 function Compile
2328 (S : Name_Id;
2329 L : Name_Id;
2330 Source_Index : Int;
2331 Args : Argument_List) return Process_Id
2333 Comp_Args : Argument_List (Args'First .. Args'Last + 9);
2334 Comp_Next : Integer := Args'First;
2335 Comp_Last : Integer;
2336 Arg_Index : Integer;
2338 function Ada_File_Name (Name : Name_Id) return Boolean;
2339 -- Returns True if Name is the name of an ada source file
2340 -- (i.e. suffix is .ads or .adb)
2342 -------------------
2343 -- Ada_File_Name --
2344 -------------------
2346 function Ada_File_Name (Name : Name_Id) return Boolean is
2347 begin
2348 Get_Name_String (Name);
2349 return
2350 Name_Len > 4
2351 and then Name_Buffer (Name_Len - 3 .. Name_Len - 1) = ".ad"
2352 and then (Name_Buffer (Name_Len) = 'b'
2353 or else
2354 Name_Buffer (Name_Len) = 's');
2355 end Ada_File_Name;
2357 -- Start of processing for Compile
2359 begin
2360 Enter_Into_Obsoleted (S);
2362 -- By default, Syntax_Only is False
2364 Syntax_Only := False;
2366 for J in Args'Range loop
2367 if Args (J).all = "-gnats" then
2369 -- If we compile with -gnats, the bind step and the link step
2370 -- are inhibited. Also, we set Syntax_Only to True, so that
2371 -- we don't fail when we don't find the ALI file, after
2372 -- compilation.
2374 Do_Bind_Step := False;
2375 Do_Link_Step := False;
2376 Syntax_Only := True;
2378 elsif Args (J).all = "-gnatc" then
2380 -- If we compile with -gnatc, the bind step and the link step
2381 -- are inhibited. We set Syntax_Only to False for the case when
2382 -- -gnats was previously specified.
2384 Do_Bind_Step := False;
2385 Do_Link_Step := False;
2386 Syntax_Only := False;
2387 end if;
2388 end loop;
2390 Comp_Args (Comp_Next) := Comp_Flag;
2391 Comp_Next := Comp_Next + 1;
2393 -- Optimize the simple case where the gcc command line looks like
2394 -- gcc -c -I. ... -I- file.adb --into-> gcc -c ... file.adb
2396 if Args (Args'First).all = "-I" & Normalized_CWD
2397 and then Args (Args'Last).all = "-I-"
2398 and then S = Strip_Directory (S)
2399 then
2400 Comp_Last := Comp_Next + Args'Length - 3;
2401 Arg_Index := Args'First + 1;
2403 else
2404 Comp_Last := Comp_Next + Args'Length - 1;
2405 Arg_Index := Args'First;
2406 end if;
2408 -- Make a deep copy of the arguments, because Normalize_Arguments
2409 -- may deallocate some arguments.
2411 for J in Comp_Next .. Comp_Last loop
2412 Comp_Args (J) := new String'(Args (Arg_Index).all);
2413 Arg_Index := Arg_Index + 1;
2414 end loop;
2416 -- Set -gnatpg for predefined files (for this purpose the renamings
2417 -- such as Text_IO do not count as predefined). Note that we strip
2418 -- the directory name from the source file name becase the call to
2419 -- Fname.Is_Predefined_File_Name cannot deal with directory prefixes.
2421 declare
2422 Fname : constant File_Name_Type := Strip_Directory (S);
2424 begin
2425 if Is_Predefined_File_Name (Fname, False) then
2426 if Check_Readonly_Files then
2427 Comp_Last := Comp_Last + 1;
2428 Comp_Args (Comp_Last) := GNAT_Flag;
2430 else
2431 Make_Failed
2432 ("not allowed to compile """ &
2433 Get_Name_String (Fname) &
2434 """; use -a switch, or compile file with " &
2435 """-gnatg"" switch");
2436 end if;
2437 end if;
2438 end;
2440 -- Now check if the file name has one of the suffixes familiar to
2441 -- the gcc driver. If this is not the case then add the ada flag
2442 -- "-x ada".
2444 if not Ada_File_Name (S) and then not Targparm.AAMP_On_Target then
2445 Comp_Last := Comp_Last + 1;
2446 Comp_Args (Comp_Last) := Ada_Flag_1;
2447 Comp_Last := Comp_Last + 1;
2448 Comp_Args (Comp_Last) := Ada_Flag_2;
2449 end if;
2451 if Source_Index /= 0 then
2452 declare
2453 Num : constant String := Source_Index'Img;
2454 begin
2455 Comp_Last := Comp_Last + 1;
2456 Comp_Args (Comp_Last) :=
2457 new String'("-gnateI" & Num (Num'First + 1 .. Num'Last));
2458 end;
2459 end if;
2461 if Source_Index /= 0 or else
2462 L /= Strip_Directory (L) or else
2463 Object_Directory_Path /= null
2464 then
2465 -- Build -o argument
2467 Get_Name_String (L);
2469 for J in reverse 1 .. Name_Len loop
2470 if Name_Buffer (J) = '.' then
2471 Name_Len := J + Object_Suffix'Length - 1;
2472 Name_Buffer (J .. Name_Len) := Object_Suffix;
2473 exit;
2474 end if;
2475 end loop;
2477 Comp_Last := Comp_Last + 1;
2478 Comp_Args (Comp_Last) := Output_Flag;
2479 Comp_Last := Comp_Last + 1;
2481 -- If an object directory was specified, prepend the object file
2482 -- name with this object directory.
2484 if Object_Directory_Path /= null then
2485 Comp_Args (Comp_Last) :=
2486 new String'(Object_Directory_Path.all &
2487 Name_Buffer (1 .. Name_Len));
2489 else
2490 Comp_Args (Comp_Last) :=
2491 new String'(Name_Buffer (1 .. Name_Len));
2492 end if;
2493 end if;
2495 if Create_Mapping_File then
2496 Comp_Last := Comp_Last + 1;
2497 Comp_Args (Comp_Last) := Mapping_File_Arg;
2498 end if;
2500 Get_Name_String (S);
2502 Comp_Last := Comp_Last + 1;
2503 Comp_Args (Comp_Last) := new String'(Name_Buffer (1 .. Name_Len));
2505 GNAT.OS_Lib.Normalize_Arguments (Comp_Args (Args'First .. Comp_Last));
2507 Comp_Last := Comp_Last + 1;
2508 Comp_Args (Comp_Last) := new String'("-gnatez");
2510 Display (Gcc.all, Comp_Args (Args'First .. Comp_Last));
2512 if Gcc_Path = null then
2513 Make_Failed ("error, unable to locate ", Gcc.all);
2514 end if;
2516 return
2517 GNAT.OS_Lib.Non_Blocking_Spawn
2518 (Gcc_Path.all, Comp_Args (Args'First .. Comp_Last));
2519 end Compile;
2521 ----------------------
2522 -- Get_Mapping_File --
2523 ----------------------
2525 procedure Get_Mapping_File (Project : Project_Id) is
2526 begin
2527 -- If there is a mapping file ready to be reused, reuse it
2529 if Last_Free_Indices (Project) > 0 then
2530 Mfile := The_Free_Mapping_File_Indices
2531 (Project, Last_Free_Indices (Project));
2532 Last_Free_Indices (Project) := Last_Free_Indices (Project) - 1;
2534 -- Otherwise, create and initialize a new one
2536 else
2537 Init_Mapping_File (Project => Project, File_Index => Mfile);
2538 end if;
2540 -- Put the name in the mapping file argument for the invocation
2541 -- of the compiler.
2543 Free (Mapping_File_Arg);
2544 Mapping_File_Arg :=
2545 new String'("-gnatem=" &
2546 Get_Name_String
2547 (The_Mapping_File_Names (Project, Mfile)));
2549 end Get_Mapping_File;
2551 -----------------------
2552 -- Get_Next_Good_ALI --
2553 -----------------------
2555 function Get_Next_Good_ALI return ALI_Id is
2556 ALI : ALI_Id;
2558 begin
2559 pragma Assert (Good_ALI_Present);
2560 ALI := Good_ALI.Table (Good_ALI.Last);
2561 Good_ALI.Decrement_Last;
2562 return ALI;
2563 end Get_Next_Good_ALI;
2565 ----------------------
2566 -- Good_ALI_Present --
2567 ----------------------
2569 function Good_ALI_Present return Boolean is
2570 begin
2571 return Good_ALI.First <= Good_ALI.Last;
2572 end Good_ALI_Present;
2574 --------------------
2575 -- Record_Failure --
2576 --------------------
2578 procedure Record_Failure
2579 (File : File_Name_Type;
2580 Unit : Unit_Name_Type;
2581 Found : Boolean := True)
2583 begin
2584 Bad_Compilation.Increment_Last;
2585 Bad_Compilation.Table (Bad_Compilation.Last) := (File, Unit, Found);
2586 end Record_Failure;
2588 ---------------------
2589 -- Record_Good_ALI --
2590 ---------------------
2592 procedure Record_Good_ALI (A : ALI_Id) is
2593 begin
2594 Good_ALI.Increment_Last;
2595 Good_ALI.Table (Good_ALI.Last) := A;
2596 end Record_Good_ALI;
2598 -- Start of processing for Compile_Sources
2600 begin
2601 pragma Assert (Args'First = 1);
2603 -- Package and Queue initializations
2605 Good_ALI.Init;
2606 Output.Set_Standard_Error;
2608 if First_Q_Initialization then
2609 Init_Q;
2610 end if;
2612 if Initialize_ALI_Data then
2613 Initialize_ALI;
2614 Initialize_ALI_Source;
2615 end if;
2617 -- The following two flags affect the behavior of ALI.Set_Source_Table.
2618 -- We set Check_Source_Files to True to ensure that source file
2619 -- time stamps are checked, and we set All_Sources to False to
2620 -- avoid checking the presence of the source files listed in the
2621 -- source dependency section of an ali file (which would be a mistake
2622 -- since the ali file may be obsolete).
2624 Check_Source_Files := True;
2625 All_Sources := False;
2627 -- Only insert in the Q if it is not already done, to avoid simultaneous
2628 -- compilations if -jnnn is used.
2630 if not Is_Marked (Main_Source, Main_Index) then
2631 Insert_Q (Main_Source, Index => Main_Index);
2632 Mark (Main_Source, Main_Index);
2633 end if;
2635 First_Compiled_File := No_File;
2636 Most_Recent_Obj_File := No_File;
2637 Most_Recent_Obj_Stamp := Empty_Time_Stamp;
2638 Main_Unit := False;
2640 -- Keep looping until there is no more work to do (the Q is empty)
2641 -- and all the outstanding compilations have terminated
2643 Make_Loop : while not Empty_Q or else Outstanding_Compiles > 0 loop
2645 -- If the user does not want to keep going in case of errors then
2646 -- wait for the remaining outstanding compiles and then exit.
2648 if Bad_Compilation_Count > 0 and then not Keep_Going then
2649 while Outstanding_Compiles > 0 loop
2650 Await_Compile
2651 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
2653 if not Compilation_OK then
2654 Record_Failure (Full_Source_File, Source_Unit);
2655 end if;
2656 end loop;
2658 exit Make_Loop;
2659 end if;
2661 -- PHASE 1: Check if there is more work that we can do (ie the Q
2662 -- is non empty). If there is, do it only if we have not yet used
2663 -- up all the available processes.
2665 if not Empty_Q and then Outstanding_Compiles < Max_Process then
2666 declare
2667 Source_Index : Int;
2668 -- Index of the current unit in the current source file
2670 begin
2671 Extract_From_Q (Source_File, Source_Unit, Source_Index);
2672 Full_Source_File := Osint.Full_Source_Name (Source_File);
2673 Lib_File := Osint.Lib_File_Name
2674 (Source_File, Source_Index);
2675 Full_Lib_File := Osint.Full_Lib_File_Name (Lib_File);
2677 -- If this source has already been compiled, the executable is
2678 -- obsolete.
2680 if Is_In_Obsoleted (Source_File) then
2681 Executable_Obsolete := True;
2682 end if;
2684 -- If the library file is an Ada library skip it
2686 if Full_Lib_File /= No_File
2687 and then In_Ada_Lib_Dir (Full_Lib_File)
2688 then
2689 Verbose_Msg
2690 (Lib_File, "is in an Ada library", Prefix => " ");
2692 -- If the library file is a read-only library skip it, but
2693 -- only if, when using project files, this library file is
2694 -- in the right object directory (a read-only ALI file
2695 -- in the object directory of a project being extended
2696 -- should not be skipped).
2698 elsif Full_Lib_File /= No_File
2699 and then not Check_Readonly_Files
2700 and then Is_Readonly_Library (Full_Lib_File)
2701 and then Is_In_Object_Directory (Source_File, Full_Lib_File)
2702 then
2703 Verbose_Msg
2704 (Lib_File, "is a read-only library", Prefix => " ");
2706 -- The source file that we are checking cannot be located
2708 elsif Full_Source_File = No_File then
2709 Record_Failure (Source_File, Source_Unit, False);
2711 -- Source and library files can be located but are internal
2712 -- files
2714 elsif not Check_Readonly_Files
2715 and then Full_Lib_File /= No_File
2716 and then Is_Internal_File_Name (Source_File)
2717 then
2718 if Force_Compilations then
2719 Fail
2720 ("not allowed to compile """ &
2721 Get_Name_String (Source_File) &
2722 """; use -a switch, or compile file with " &
2723 """-gnatg"" switch");
2724 end if;
2726 Verbose_Msg
2727 (Lib_File, "is an internal library", Prefix => " ");
2729 -- The source file that we are checking can be located
2731 else
2732 Arguments_Collected := False;
2734 -- Don't waste any time if we have to recompile anyway
2736 Obj_Stamp := Empty_Time_Stamp;
2737 Need_To_Compile := Force_Compilations;
2739 if not Force_Compilations then
2740 Read_Only :=
2741 Full_Lib_File /= No_File
2742 and then not Check_Readonly_Files
2743 and then Is_Readonly_Library (Full_Lib_File);
2744 Check (Source_File, Source_Index, Args, Lib_File,
2745 Read_Only, ALI, Obj_File, Obj_Stamp);
2746 Need_To_Compile := (ALI = No_ALI_Id);
2747 end if;
2749 if not Need_To_Compile then
2751 -- The ALI file is up-to-date. Record its Id
2753 Record_Good_ALI (ALI);
2755 -- Record the time stamp of the most recent object file
2756 -- as long as no (re)compilations are needed.
2758 if First_Compiled_File = No_File
2759 and then (Most_Recent_Obj_File = No_File
2760 or else Obj_Stamp > Most_Recent_Obj_Stamp)
2761 then
2762 Most_Recent_Obj_File := Obj_File;
2763 Most_Recent_Obj_Stamp := Obj_Stamp;
2764 end if;
2766 else
2767 -- Is this the first file we have to compile?
2769 if First_Compiled_File = No_File then
2770 First_Compiled_File := Full_Source_File;
2771 Most_Recent_Obj_File := No_File;
2773 if Do_Not_Execute then
2774 exit Make_Loop;
2775 end if;
2776 end if;
2778 if In_Place_Mode then
2780 -- If the library file was not found, then save the
2781 -- library file near the source file.
2783 if Full_Lib_File = No_File then
2784 Lib_File := Osint.Lib_File_Name
2785 (Full_Source_File, Source_Index);
2787 -- If the library file was found, then save the
2788 -- library file in the same place.
2790 else
2791 Lib_File := Full_Lib_File;
2792 end if;
2794 end if;
2796 -- Start the compilation and record it. We can do this
2797 -- because there is at least one free process.
2799 Collect_Arguments_And_Compile (Source_File, Source_Index);
2801 -- Make sure we could successfully start the compilation
2803 if Process_Created then
2804 if Pid = Invalid_Pid then
2805 Record_Failure (Full_Source_File, Source_Unit);
2806 else
2807 Add_Process
2808 (Pid,
2809 Full_Source_File,
2810 Lib_File,
2811 Source_Unit,
2812 Mfile);
2813 end if;
2814 end if;
2815 end if;
2816 end if;
2817 end;
2818 end if;
2820 -- PHASE 2: Now check if we should wait for a compilation to
2821 -- finish. This is the case if all the available processes are
2822 -- busy compiling sources or there is nothing else to do
2823 -- (that is the Q is empty and there are no good ALIs to process).
2825 if Outstanding_Compiles = Max_Process
2826 or else (Empty_Q
2827 and then not Good_ALI_Present
2828 and then Outstanding_Compiles > 0)
2829 then
2830 Await_Compile
2831 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
2833 if not Compilation_OK then
2834 Record_Failure (Full_Source_File, Source_Unit);
2835 end if;
2837 if Compilation_OK or else Keep_Going then
2839 -- Re-read the updated library file
2841 declare
2842 Saved_Object_Consistency : constant Boolean :=
2843 Check_Object_Consistency;
2845 begin
2846 -- If compilation was not OK, or if output is not an
2847 -- object file and we don't do the bind step, don't check
2848 -- for object consistency.
2850 Check_Object_Consistency :=
2851 Check_Object_Consistency
2852 and Compilation_OK
2853 and (Output_Is_Object or Do_Bind_Step);
2854 Text := Read_Library_Info (Lib_File);
2856 -- Restore Check_Object_Consistency to its initial value
2858 Check_Object_Consistency := Saved_Object_Consistency;
2859 end;
2861 -- If an ALI file was generated by this compilation, scan
2862 -- the ALI file and record it.
2863 -- If the scan fails, a previous ali file is inconsistent with
2864 -- the unit just compiled.
2866 if Text /= null then
2867 ALI :=
2868 Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
2870 if ALI = No_ALI_Id then
2872 -- Record a failure only if not already done
2874 if Compilation_OK then
2875 Inform
2876 (Lib_File,
2877 "incompatible ALI file, please recompile");
2878 Record_Failure (Full_Source_File, Source_Unit);
2879 end if;
2880 else
2881 Free (Text);
2882 Record_Good_ALI (ALI);
2883 end if;
2885 -- If we could not read the ALI file that was just generated
2886 -- then there could be a problem reading either the ALI or the
2887 -- corresponding object file (if Check_Object_Consistency
2888 -- is set Read_Library_Info checks that the time stamp of the
2889 -- object file is more recent than that of the ALI). For an
2890 -- example of problems caught by this test see [6625-009].
2891 -- However, we record a failure only if not already done.
2893 else
2894 if Compilation_OK and not Syntax_Only then
2895 Inform
2896 (Lib_File,
2897 "WARNING: ALI or object file not found after compile");
2898 Record_Failure (Full_Source_File, Source_Unit);
2899 end if;
2900 end if;
2901 end if;
2902 end if;
2904 -- PHASE 3: Check if we recorded good ALI files. If yes process
2905 -- them now in the order in which they have been recorded. There
2906 -- are two occasions in which we record good ali files. The first is
2907 -- in phase 1 when, after scanning an existing ALI file we realize
2908 -- it is up-to-date, the second instance is after a successful
2909 -- compilation.
2911 while Good_ALI_Present loop
2912 ALI := Get_Next_Good_ALI;
2914 declare
2915 Source_Index : Int := Unit_Index_Of (ALIs.Table (ALI).Afile);
2917 begin
2918 -- If we are processing the library file corresponding to the
2919 -- main source file check if this source can be a main unit.
2921 if ALIs.Table (ALI).Sfile = Main_Source and then
2922 Source_Index = Main_Index
2923 then
2924 Main_Unit := ALIs.Table (ALI).Main_Program /= None;
2925 end if;
2927 -- The following adds the standard library (s-stalib) to the
2928 -- list of files to be handled by gnatmake: this file and any
2929 -- files it depends on are always included in every bind,
2930 -- even if they are not in the explicit dependency list.
2931 -- Of course, it is not added if Suppress_Standard_Library
2932 -- is True.
2934 -- However, to avoid annoying output about s-stalib.ali being
2935 -- read only, when "-v" is used, we add the standard library
2936 -- only when "-a" is used.
2938 if Need_To_Check_Standard_Library then
2939 Check_Standard_Library;
2940 end if;
2942 -- Now insert in the Q the unmarked source files (i.e. those
2943 -- which have never been inserted in the Q and hence never
2944 -- considered). Only do that if Unique_Compile is False.
2946 if not Unique_Compile then
2947 for J in
2948 ALIs.Table (ALI).First_Unit .. ALIs.Table (ALI).Last_Unit
2949 loop
2950 for K in
2951 Units.Table (J).First_With .. Units.Table (J).Last_With
2952 loop
2953 Sfile := Withs.Table (K).Sfile;
2954 Add_Dependency (ALIs.Table (ALI).Sfile, Sfile);
2956 if Is_In_Obsoleted (Sfile) then
2957 Executable_Obsolete := True;
2958 end if;
2960 if Sfile = No_File then
2961 Debug_Msg
2962 ("Skipping generic:", Withs.Table (K).Uname);
2964 else
2965 Source_Index :=
2966 Unit_Index_Of (Withs.Table (K).Afile);
2968 if Is_Marked (Sfile, Source_Index) then
2969 Debug_Msg ("Skipping marked file:", Sfile);
2971 elsif not Check_Readonly_Files
2972 and then Is_Internal_File_Name (Sfile)
2973 then
2974 Debug_Msg ("Skipping internal file:", Sfile);
2976 else
2977 Insert_Q
2978 (Sfile, Withs.Table (K).Uname, Source_Index);
2979 Mark (Sfile, Source_Index);
2980 end if;
2981 end if;
2982 end loop;
2983 end loop;
2984 end if;
2985 end;
2986 end loop;
2988 if Display_Compilation_Progress then
2989 Write_Str ("completed ");
2990 Write_Int (Int (Q_Front));
2991 Write_Str (" out of ");
2992 Write_Int (Int (Q.Last));
2993 Write_Str (" (");
2994 Write_Int (Int ((Q_Front * 100) / (Q.Last - Q.First)));
2995 Write_Str ("%)...");
2996 Write_Eol;
2997 end if;
2998 end loop Make_Loop;
3000 Compilation_Failures := Bad_Compilation_Count;
3002 -- Compilation is finished
3004 -- Delete any temporary configuration pragma file
3006 Delete_Temp_Config_Files;
3008 end Compile_Sources;
3010 ----------------------------------
3011 -- Configuration_Pragmas_Switch --
3012 ----------------------------------
3014 function Configuration_Pragmas_Switch
3015 (For_Project : Project_Id) return Argument_List
3017 The_Packages : Package_Id;
3018 Gnatmake : Package_Id;
3019 Compiler : Package_Id;
3021 Global_Attribute : Variable_Value := Nil_Variable_Value;
3022 Local_Attribute : Variable_Value := Nil_Variable_Value;
3024 Global_Attribute_Present : Boolean := False;
3025 Local_Attribute_Present : Boolean := False;
3027 Result : Argument_List (1 .. 3);
3028 Last : Natural := 0;
3030 function Absolute_Path
3031 (Path : Name_Id;
3032 Project : Project_Id) return String;
3033 -- Returns an absolute path for a configuration pragmas file
3035 -------------------
3036 -- Absolute_Path --
3037 -------------------
3039 function Absolute_Path
3040 (Path : Name_Id;
3041 Project : Project_Id) return String
3043 begin
3044 Get_Name_String (Path);
3046 declare
3047 Path_Name : constant String := Name_Buffer (1 .. Name_Len);
3049 begin
3050 if Is_Absolute_Path (Path_Name) then
3051 return Path_Name;
3053 else
3054 declare
3055 Parent_Directory : constant String :=
3056 Get_Name_String
3057 (Project_Tree.Projects.Table
3058 (Project).Directory);
3060 begin
3061 if Parent_Directory (Parent_Directory'Last) =
3062 Directory_Separator
3063 then
3064 return Parent_Directory & Path_Name;
3066 else
3067 return Parent_Directory & Directory_Separator & Path_Name;
3068 end if;
3069 end;
3070 end if;
3071 end;
3072 end Absolute_Path;
3074 -- Start of processing for Configuration_Pragmas_Switch
3076 begin
3077 Prj.Env.Create_Config_Pragmas_File
3078 (For_Project, Main_Project, Project_Tree);
3080 if Project_Tree.Projects.Table
3081 (For_Project).Config_File_Name /= No_Name
3082 then
3083 Temporary_Config_File :=
3084 Project_Tree.Projects.Table (For_Project).Config_File_Temp;
3085 Last := 1;
3086 Result (1) :=
3087 new String'
3088 ("-gnatec=" &
3089 Get_Name_String
3090 (Project_Tree.Projects.Table
3091 (For_Project).Config_File_Name));
3093 else
3094 Temporary_Config_File := False;
3095 end if;
3097 -- Check for attribute Builder'Global_Configuration_Pragmas
3099 The_Packages := Project_Tree.Projects.Table
3100 (Main_Project).Decl.Packages;
3101 Gnatmake :=
3102 Prj.Util.Value_Of
3103 (Name => Name_Builder,
3104 In_Packages => The_Packages,
3105 In_Tree => Project_Tree);
3107 if Gnatmake /= No_Package then
3108 Global_Attribute := Prj.Util.Value_Of
3109 (Variable_Name => Name_Global_Configuration_Pragmas,
3110 In_Variables => Project_Tree.Packages.Table
3111 (Gnatmake).Decl.Attributes,
3112 In_Tree => Project_Tree);
3113 Global_Attribute_Present :=
3114 Global_Attribute /= Nil_Variable_Value
3115 and then Get_Name_String (Global_Attribute.Value) /= "";
3117 if Global_Attribute_Present then
3118 declare
3119 Path : constant String :=
3120 Absolute_Path
3121 (Global_Attribute.Value, Global_Attribute.Project);
3122 begin
3123 if not Is_Regular_File (Path) then
3124 Make_Failed
3125 ("cannot find configuration pragmas file ", Path);
3126 end if;
3128 Last := Last + 1;
3129 Result (Last) := new String'("-gnatec=" & Path);
3130 end;
3131 end if;
3132 end if;
3134 -- Check for attribute Compiler'Local_Configuration_Pragmas
3136 The_Packages :=
3137 Project_Tree.Projects.Table (For_Project).Decl.Packages;
3138 Compiler :=
3139 Prj.Util.Value_Of
3140 (Name => Name_Compiler,
3141 In_Packages => The_Packages,
3142 In_Tree => Project_Tree);
3144 if Compiler /= No_Package then
3145 Local_Attribute := Prj.Util.Value_Of
3146 (Variable_Name => Name_Local_Configuration_Pragmas,
3147 In_Variables => Project_Tree.Packages.Table
3148 (Compiler).Decl.Attributes,
3149 In_Tree => Project_Tree);
3150 Local_Attribute_Present :=
3151 Local_Attribute /= Nil_Variable_Value
3152 and then Get_Name_String (Local_Attribute.Value) /= "";
3154 if Local_Attribute_Present then
3155 declare
3156 Path : constant String :=
3157 Absolute_Path
3158 (Local_Attribute.Value, Local_Attribute.Project);
3159 begin
3160 if not Is_Regular_File (Path) then
3161 Make_Failed
3162 ("cannot find configuration pragmas file ", Path);
3163 end if;
3165 Last := Last + 1;
3166 Result (Last) := new String'("-gnatec=" & Path);
3167 end;
3168 end if;
3169 end if;
3171 return Result (1 .. Last);
3172 end Configuration_Pragmas_Switch;
3174 ---------------
3175 -- Debug_Msg --
3176 ---------------
3178 procedure Debug_Msg (S : String; N : Name_Id) is
3179 begin
3180 if Debug.Debug_Flag_W then
3181 Write_Str (" ... ");
3182 Write_Str (S);
3183 Write_Str (" ");
3184 Write_Name (N);
3185 Write_Eol;
3186 end if;
3187 end Debug_Msg;
3189 ---------------------------
3190 -- Delete_All_Temp_Files --
3191 ---------------------------
3193 procedure Delete_All_Temp_Files is
3194 begin
3195 if Gnatmake_Called and not Debug.Debug_Flag_N then
3196 Delete_Mapping_Files;
3197 Delete_Temp_Config_Files;
3198 Prj.Env.Delete_All_Path_Files (Project_Tree);
3199 end if;
3200 end Delete_All_Temp_Files;
3202 --------------------------
3203 -- Delete_Mapping_Files --
3204 --------------------------
3206 procedure Delete_Mapping_Files is
3207 Success : Boolean;
3208 begin
3209 if not Debug.Debug_Flag_N then
3210 if The_Mapping_File_Names /= null then
3211 for Project in The_Mapping_File_Names'Range (1) loop
3212 for Index in 1 .. Last_Mapping_File_Names (Project) loop
3213 Delete_File
3214 (Name => Get_Name_String
3215 (The_Mapping_File_Names (Project, Index)),
3216 Success => Success);
3217 end loop;
3218 end loop;
3219 end if;
3220 end if;
3221 end Delete_Mapping_Files;
3223 ------------------------------
3224 -- Delete_Temp_Config_Files --
3225 ------------------------------
3227 procedure Delete_Temp_Config_Files is
3228 Success : Boolean;
3229 begin
3230 if (not Debug.Debug_Flag_N) and Main_Project /= No_Project then
3231 for Project in Project_Table.First ..
3232 Project_Table.Last (Project_Tree.Projects)
3233 loop
3235 Project_Tree.Projects.Table (Project).Config_File_Temp
3236 then
3237 if Verbose_Mode then
3238 Write_Str ("Deleting temp configuration file """);
3239 Write_Str (Get_Name_String
3240 (Project_Tree.Projects.Table
3241 (Project).Config_File_Name));
3242 Write_Line ("""");
3243 end if;
3245 Delete_File
3246 (Name => Get_Name_String
3247 (Project_Tree.Projects.Table
3248 (Project).Config_File_Name),
3249 Success => Success);
3251 -- Make sure that we don't have a config file for this
3252 -- project, in case when there are several mains.
3253 -- In this case, we will recreate another config file:
3254 -- we cannot reuse the one that we just deleted!
3256 Project_Tree.Projects.Table (Project).
3257 Config_Checked := False;
3258 Project_Tree.Projects.Table (Project).
3259 Config_File_Name := No_Name;
3260 Project_Tree.Projects.Table (Project).
3261 Config_File_Temp := False;
3262 end if;
3263 end loop;
3264 end if;
3265 end Delete_Temp_Config_Files;
3267 -------------
3268 -- Display --
3269 -------------
3271 procedure Display (Program : String; Args : Argument_List) is
3272 begin
3273 pragma Assert (Args'First = 1);
3275 if Display_Executed_Programs then
3276 Write_Str (Program);
3278 for J in Args'Range loop
3280 -- Never display -gnatez
3282 if Args (J).all /= "-gnatez" then
3284 -- Do not display the mapping file argument automatically
3285 -- created when using a project file.
3287 if Main_Project = No_Project
3288 or else Debug.Debug_Flag_N
3289 or else Args (J)'Length < 8
3290 or else
3291 Args (J) (Args (J)'First .. Args (J)'First + 6) /= "-gnatem"
3292 then
3293 -- When -dn is not specified, do not display the config
3294 -- pragmas switch (-gnatec) for the temporary file created
3295 -- by the project manager (always the first -gnatec switch).
3296 -- Reset Temporary_Config_File to False so that the eventual
3297 -- other -gnatec switches will be displayed.
3299 if (not Debug.Debug_Flag_N)
3300 and then Temporary_Config_File
3301 and then Args (J)'Length > 7
3302 and then Args (J) (Args (J)'First .. Args (J)'First + 6)
3303 = "-gnatec"
3304 then
3305 Temporary_Config_File := False;
3307 -- Do not display the -F=mapping_file switch for
3308 -- gnatbind, if -dn is not specified.
3310 elsif Debug.Debug_Flag_N
3311 or else Args (J)'Length < 4
3312 or else
3313 Args (J) (Args (J)'First .. Args (J)'First + 2) /= "-F="
3314 then
3315 Write_Str (" ");
3316 Write_Str (Args (J).all);
3317 end if;
3318 end if;
3319 end if;
3320 end loop;
3322 Write_Eol;
3323 end if;
3324 end Display;
3326 ----------------------
3327 -- Display_Commands --
3328 ----------------------
3330 procedure Display_Commands (Display : Boolean := True) is
3331 begin
3332 Display_Executed_Programs := Display;
3333 end Display_Commands;
3335 -------------
3336 -- Empty_Q --
3337 -------------
3339 function Empty_Q return Boolean is
3340 begin
3341 if Debug.Debug_Flag_P then
3342 Write_Str (" Q := [");
3344 for J in Q_Front .. Q.Last - 1 loop
3345 Write_Str (" ");
3346 Write_Name (Q.Table (J).File);
3347 Write_Eol;
3348 Write_Str (" ");
3349 end loop;
3351 Write_Str ("]");
3352 Write_Eol;
3353 end if;
3355 return Q_Front >= Q.Last;
3356 end Empty_Q;
3358 --------------------------
3359 -- Enter_Into_Obsoleted --
3360 --------------------------
3362 procedure Enter_Into_Obsoleted (F : Name_Id) is
3363 Name : constant String := Get_Name_String (F);
3364 First : Natural := Name'Last;
3365 F2 : Name_Id := F;
3367 begin
3368 while First > Name'First
3369 and then Name (First - 1) /= Directory_Separator
3370 and then Name (First - 1) /= '/'
3371 loop
3372 First := First - 1;
3373 end loop;
3375 if First /= Name'First then
3376 Name_Len := 0;
3377 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
3378 F2 := Name_Find;
3379 end if;
3381 Debug_Msg ("New entry in Obsoleted table:", F2);
3382 Obsoleted.Set (F2, True);
3383 end Enter_Into_Obsoleted;
3385 ---------------------
3386 -- Extract_Failure --
3387 ---------------------
3389 procedure Extract_Failure
3390 (File : out File_Name_Type;
3391 Unit : out Unit_Name_Type;
3392 Found : out Boolean)
3394 begin
3395 File := Bad_Compilation.Table (Bad_Compilation.Last).File;
3396 Unit := Bad_Compilation.Table (Bad_Compilation.Last).Unit;
3397 Found := Bad_Compilation.Table (Bad_Compilation.Last).Found;
3398 Bad_Compilation.Decrement_Last;
3399 end Extract_Failure;
3401 --------------------
3402 -- Extract_From_Q --
3403 --------------------
3405 procedure Extract_From_Q
3406 (Source_File : out File_Name_Type;
3407 Source_Unit : out Unit_Name_Type;
3408 Source_Index : out Int)
3410 File : constant File_Name_Type := Q.Table (Q_Front).File;
3411 Unit : constant Unit_Name_Type := Q.Table (Q_Front).Unit;
3412 Index : constant Int := Q.Table (Q_Front).Index;
3414 begin
3415 if Debug.Debug_Flag_Q then
3416 Write_Str (" Q := Q - [ ");
3417 Write_Name (File);
3419 if Index /= 0 then
3420 Write_Str (", ");
3421 Write_Int (Index);
3422 end if;
3424 Write_Str (" ]");
3425 Write_Eol;
3426 end if;
3428 Q_Front := Q_Front + 1;
3429 Source_File := File;
3430 Source_Unit := Unit;
3431 Source_Index := Index;
3432 end Extract_From_Q;
3434 --------------
3435 -- Gnatmake --
3436 --------------
3438 procedure Gnatmake is
3439 Main_Source_File : File_Name_Type;
3440 -- The source file containing the main compilation unit
3442 Compilation_Failures : Natural;
3444 Total_Compilation_Failures : Natural := 0;
3446 Is_Main_Unit : Boolean;
3447 -- Set to True by Compile_Sources if the Main_Source_File can be a
3448 -- main unit.
3450 Main_ALI_File : File_Name_Type;
3451 -- The ali file corresponding to Main_Source_File
3453 Executable : File_Name_Type := No_File;
3454 -- The file name of an executable
3456 Non_Std_Executable : Boolean := False;
3457 -- Non_Std_Executable is set to True when there is a possibility
3458 -- that the linker will not choose the correct executable file name.
3460 Current_Work_Dir : constant String_Access :=
3461 new String'(Get_Current_Dir);
3462 -- The current working directory, used to modify some relative path
3463 -- switches on the command line when a project file is used.
3465 Current_Main_Index : Int := 0;
3466 -- If not zero, the index of the current main unit in its source file
3468 There_Are_Stand_Alone_Libraries : Boolean := False;
3469 -- Set to True when there are Stand-Alone Libraries, so that gnatbind
3470 -- is invoked with the -F switch to force checking of elaboration flags.
3472 Mapping_Path : Name_Id := No_Name;
3473 -- The path name of the mapping file
3475 Discard : Boolean;
3477 procedure Check_Mains;
3478 -- Check that the main subprograms do exist and that they all
3479 -- belong to the same project file.
3481 procedure Create_Binder_Mapping_File
3482 (Args : in out Argument_List; Last_Arg : in out Natural);
3483 -- Create a binder mapping file and add the necessary switch
3485 -----------------
3486 -- Check_Mains --
3487 -----------------
3489 procedure Check_Mains is
3490 Real_Main_Project : Project_Id := No_Project;
3491 -- The project of the first main
3493 Proj : Project_Id := No_Project;
3494 -- The project of the current main
3496 Data : Project_Data;
3498 Real_Path : String_Access;
3500 begin
3501 Mains.Reset;
3503 -- Check each main
3505 loop
3506 declare
3507 Main : constant String := Mains.Next_Main;
3508 -- The name specified on the command line may include
3509 -- directory information.
3511 File_Name : constant String := Base_Name (Main);
3512 -- The simple file name of the current main main
3514 begin
3515 exit when Main = "";
3517 -- Get the project of the current main
3519 Proj := Prj.Env.Project_Of
3520 (File_Name, Main_Project, Project_Tree);
3522 -- Fail if the current main is not a source of a
3523 -- project.
3525 if Proj = No_Project then
3526 Make_Failed
3527 ("""" & Main &
3528 """ is not a source of any project");
3530 else
3531 -- If there is directory information, check that
3532 -- the source exists and, if it does, that the path
3533 -- is the actual path of a source of a project.
3535 if Main /= File_Name then
3536 Data :=
3537 Project_Tree.Projects.Table (Main_Project);
3539 Real_Path :=
3540 Locate_Regular_File
3541 (Main &
3542 Get_Name_String
3543 (Data.Naming.Ada_Body_Suffix),
3544 "");
3545 if Real_Path = null then
3546 Real_Path :=
3547 Locate_Regular_File
3548 (Main &
3549 Get_Name_String
3550 (Data.Naming.Ada_Spec_Suffix),
3551 "");
3552 end if;
3554 if Real_Path = null then
3555 Real_Path :=
3556 Locate_Regular_File (Main, "");
3557 end if;
3559 -- Fail if the file cannot be found
3561 if Real_Path = null then
3562 Make_Failed
3563 ("file """ & Main & """ does not exist");
3564 end if;
3566 declare
3567 Project_Path : constant String :=
3568 Prj.Env.File_Name_Of_Library_Unit_Body
3569 (Name => File_Name,
3570 Project => Main_Project,
3571 In_Tree => Project_Tree,
3572 Main_Project_Only => False,
3573 Full_Path => True);
3574 Normed_Path : constant String :=
3575 Normalize_Pathname
3576 (Real_Path.all,
3577 Case_Sensitive => False);
3578 Proj_Path : constant String :=
3579 Normalize_Pathname
3580 (Project_Path,
3581 Case_Sensitive => False);
3583 begin
3584 Free (Real_Path);
3586 -- Fail if it is not the correct path
3588 if Normed_Path /= Proj_Path then
3589 if Verbose_Mode then
3590 Write_Str (Normed_Path);
3591 Write_Str (" /= ");
3592 Write_Line (Proj_Path);
3593 end if;
3595 Make_Failed
3596 ("""" & Main &
3597 """ is not a source of any project");
3598 end if;
3599 end;
3600 end if;
3602 if not Unique_Compile then
3604 -- Record the project, if it is the first main
3606 if Real_Main_Project = No_Project then
3607 Real_Main_Project := Proj;
3609 elsif Proj /= Real_Main_Project then
3611 -- Fail, as the current main is not a source
3612 -- of the same project as the first main.
3614 Make_Failed
3615 ("""" & Main &
3616 """ is not a source of project " &
3617 Get_Name_String
3618 (Project_Tree.Projects.Table
3619 (Real_Main_Project).Name));
3620 end if;
3621 end if;
3622 end if;
3624 -- If -u and -U are not used, we may have mains that
3625 -- are sources of a project that is not the one
3626 -- specified with switch -P.
3628 if not Unique_Compile then
3629 Main_Project := Real_Main_Project;
3630 end if;
3631 end;
3632 end loop;
3633 end Check_Mains;
3635 --------------------------------
3636 -- Create_Binder_Mapping_File --
3637 --------------------------------
3639 procedure Create_Binder_Mapping_File
3640 (Args : in out Argument_List; Last_Arg : in out Natural)
3642 Mapping_FD : File_Descriptor := Invalid_FD;
3643 -- A File Descriptor for an eventual mapping file
3645 ALI_Unit : Name_Id := No_Name;
3646 -- The unit name of an ALI file
3648 ALI_Name : Name_Id := No_Name;
3649 -- The file name of the ALI file
3651 ALI_Project : Project_Id := No_Project;
3652 -- The project of the ALI file
3654 Bytes : Integer;
3655 OK : Boolean := True;
3657 Status : Boolean;
3658 -- For call to Close
3660 begin
3661 Tempdir.Create_Temp_File (Mapping_FD, Mapping_Path);
3663 if Mapping_FD /= Invalid_FD then
3665 -- Traverse all units
3667 for J in Unit_Table.First ..
3668 Unit_Table.Last (Project_Tree.Units)
3669 loop
3670 declare
3671 Unit : constant Unit_Data :=
3672 Project_Tree.Units.Table (J);
3673 begin
3674 if Unit.Name /= No_Name then
3676 -- If there is a body, put it in the mapping
3678 if Unit.File_Names (Body_Part).Name /= No_Name
3679 and then Unit.File_Names (Body_Part).Project
3680 /= No_Project
3681 then
3682 Get_Name_String (Unit.Name);
3683 Name_Buffer
3684 (Name_Len + 1 .. Name_Len + 2) := "%b";
3685 Name_Len := Name_Len + 2;
3686 ALI_Unit := Name_Find;
3687 ALI_Name :=
3688 Lib_File_Name
3689 (Unit.File_Names (Body_Part).Name);
3690 ALI_Project :=
3691 Unit.File_Names (Body_Part).Project;
3693 -- Otherwise, if there is a spec, put it
3694 -- in the mapping.
3696 elsif Unit.File_Names (Specification).Name
3697 /= No_Name
3698 and then Unit.File_Names
3699 (Specification).Project
3700 /= No_Project
3701 then
3702 Get_Name_String (Unit.Name);
3703 Name_Buffer
3704 (Name_Len + 1 .. Name_Len + 2) := "%s";
3705 Name_Len := Name_Len + 2;
3706 ALI_Unit := Name_Find;
3707 ALI_Name := Lib_File_Name
3708 (Unit.File_Names (Specification).Name);
3709 ALI_Project :=
3710 Unit.File_Names (Specification).Project;
3712 else
3713 ALI_Name := No_Name;
3714 end if;
3716 -- If we have something to put in the mapping
3717 -- then we do it now. However, if the project
3718 -- is extended, we don't put anything in the
3719 -- mapping file, because we do not know where
3720 -- the ALI file is: it might be in the ext-
3721 -- ended project obj dir as well as in the
3722 -- extending project obj dir.
3724 if ALI_Name /= No_Name
3725 and then
3726 Project_Tree.Projects.Table
3727 (ALI_Project).Extended_By = No_Project
3728 and then
3729 Project_Tree.Projects.Table
3730 (ALI_Project).Extends = No_Project
3731 then
3732 -- First line is the unit name
3734 Get_Name_String (ALI_Unit);
3735 Name_Len := Name_Len + 1;
3736 Name_Buffer (Name_Len) := ASCII.LF;
3737 Bytes :=
3738 Write
3739 (Mapping_FD,
3740 Name_Buffer (1)'Address,
3741 Name_Len);
3742 OK := Bytes = Name_Len;
3744 exit when not OK;
3746 -- Second line it the ALI file name
3748 Get_Name_String (ALI_Name);
3749 Name_Len := Name_Len + 1;
3750 Name_Buffer (Name_Len) := ASCII.LF;
3751 Bytes :=
3752 Write
3753 (Mapping_FD,
3754 Name_Buffer (1)'Address,
3755 Name_Len);
3756 OK := Bytes = Name_Len;
3758 exit when not OK;
3760 -- Third line it the ALI path name,
3761 -- concatenation of the project
3762 -- directory with the ALI file name.
3764 declare
3765 ALI : constant String :=
3766 Get_Name_String (ALI_Name);
3767 begin
3768 Get_Name_String
3769 (Project_Tree.Projects.Table
3770 (ALI_Project).Object_Directory);
3772 if Name_Buffer (Name_Len) /=
3773 Directory_Separator
3774 then
3775 Name_Len := Name_Len + 1;
3776 Name_Buffer (Name_Len) :=
3777 Directory_Separator;
3778 end if;
3780 Name_Buffer
3781 (Name_Len + 1 ..
3782 Name_Len + ALI'Length) := ALI;
3783 Name_Len :=
3784 Name_Len + ALI'Length + 1;
3785 Name_Buffer (Name_Len) := ASCII.LF;
3786 Bytes :=
3787 Write
3788 (Mapping_FD,
3789 Name_Buffer (1)'Address,
3790 Name_Len);
3791 OK := Bytes = Name_Len;
3792 end;
3794 -- If OK is False, it means we were unable
3795 -- to write a line. No point in continuing
3796 -- with the other units.
3798 exit when not OK;
3799 end if;
3800 end if;
3801 end;
3802 end loop;
3804 Close (Mapping_FD, Status);
3806 OK := OK and Status;
3808 -- If the creation of the mapping file was successful,
3809 -- we add the switch to the arguments of gnatbind.
3811 if OK then
3812 Last_Arg := Last_Arg + 1;
3813 Args (Last_Arg) :=
3814 new String'("-F=" & Get_Name_String (Mapping_Path));
3815 end if;
3816 end if;
3817 end Create_Binder_Mapping_File;
3819 -- Start of processing for Gnatmake
3821 -- This body is very long, should be broken down ???
3823 begin
3824 Gnatmake_Called := True;
3826 Install_Int_Handler (Sigint_Intercepted'Access);
3828 Do_Compile_Step := True;
3829 Do_Bind_Step := True;
3830 Do_Link_Step := True;
3832 Obsoleted.Reset;
3834 Make.Initialize;
3836 Bind_Shared := No_Shared_Switch'Access;
3837 Link_With_Shared_Libgcc := No_Shared_Libgcc_Switch'Access;
3839 Failed_Links.Set_Last (0);
3840 Successful_Links.Set_Last (0);
3842 if Hostparm.Java_VM then
3843 Gcc := new String'("jgnat");
3844 Gnatbind := new String'("jgnatbind");
3845 Gnatlink := new String'("jgnatlink");
3847 -- Do not check for an object file (".o") when compiling to
3848 -- Java bytecode since ".class" files are generated instead.
3850 Check_Object_Consistency := False;
3851 end if;
3853 -- Special case when switch -B was specified
3855 if Build_Bind_And_Link_Full_Project then
3857 -- When switch -B is specified, there must be a project file
3859 if Main_Project = No_Project then
3860 Make_Failed ("-B cannot be used without a project file");
3862 -- No main program may be specified on the command line
3864 elsif Osint.Number_Of_Files /= 0 then
3865 Make_Failed ("-B cannot be used with a main specified on " &
3866 "the command line");
3868 -- And the project file cannot be a library project file
3870 elsif Project_Tree.Projects.Table (Main_Project).Library then
3871 Make_Failed ("-B cannot be used for a library project file");
3873 else
3874 Insert_Project_Sources
3875 (The_Project => Main_Project,
3876 All_Projects => Unique_Compile_All_Projects,
3877 Into_Q => False);
3879 -- If there are no sources to compile, we fail
3881 if Osint.Number_Of_Files = 0 then
3882 Make_Failed ("no sources to compile");
3883 end if;
3885 -- Specify -n for gnatbind and add the ALI files of all the
3886 -- sources, except the one which is a fake main subprogram:
3887 -- this is the one for the binder generated file and it will be
3888 -- transmitted to gnatlink. These sources are those that are
3889 -- in the queue.
3891 Add_Switch ("-n", Binder, And_Save => True);
3893 for J in Q.First .. Q.Last - 1 loop
3894 Add_Switch
3895 (Get_Name_String
3896 (Lib_File_Name (Q.Table (J).File)),
3897 Binder, And_Save => True);
3898 end loop;
3899 end if;
3901 elsif Main_Index /= 0 and then Osint.Number_Of_Files > 1 then
3902 Make_Failed ("cannot specify several mains with a multi-unit index");
3904 elsif Main_Project /= No_Project then
3906 -- If the main project file is a library project file, main(s)
3907 -- cannot be specified on the command line.
3909 if Osint.Number_Of_Files /= 0 then
3910 if Project_Tree.Projects.Table (Main_Project).Library
3911 and then not Unique_Compile
3912 and then ((not Make_Steps) or else Bind_Only or else Link_Only)
3913 then
3914 Make_Failed ("cannot specify a main program " &
3915 "on the command line for a library project file");
3917 else
3918 -- Check that each main on the command line is a source of a
3919 -- project file and, if there are several mains, each of them
3920 -- is a source of the same project file.
3922 Check_Mains;
3923 end if;
3925 -- If no mains have been specified on the command line,
3926 -- and we are using a project file, we either find the main(s)
3927 -- in the attribute Main of the main project, or we put all
3928 -- the sources of the project file as mains.
3930 else
3931 if Main_Index /= 0 then
3932 Make_Failed ("cannot specify a multi-unit index but no main " &
3933 "on the command line");
3934 end if;
3936 declare
3937 Value : String_List_Id :=
3938 Project_Tree.Projects.Table (Main_Project).Mains;
3940 begin
3941 -- The attribute Main is an empty list or not specified,
3942 -- or else gnatmake was invoked with the switch "-u".
3944 if Value = Prj.Nil_String or else Unique_Compile then
3946 if (not Make_Steps) or else Compile_Only
3947 or else not Project_Tree.Projects.Table
3948 (Main_Project).Library
3949 then
3950 -- First make sure that the binder and the linker
3951 -- will not be invoked.
3953 Do_Bind_Step := False;
3954 Do_Link_Step := False;
3956 -- Put all the sources in the queue
3958 Insert_Project_Sources
3959 (The_Project => Main_Project,
3960 All_Projects => Unique_Compile_All_Projects,
3961 Into_Q => False);
3963 -- If no sources to compile, then there is nothing to do
3965 if Osint.Number_Of_Files = 0 then
3966 if not Debug.Debug_Flag_N then
3967 Delete_Mapping_Files;
3968 Prj.Env.Delete_All_Path_Files (Project_Tree);
3969 end if;
3971 if not Quiet_Output then
3972 Osint.Write_Program_Name;
3973 Write_Line (": no sources to compile");
3974 end if;
3976 Exit_Program (E_Success);
3977 end if;
3978 end if;
3980 else
3981 -- The attribute Main is not an empty list.
3982 -- Put all the main subprograms in the list as if there
3983 -- were specified on the command line. However, if attribute
3984 -- Languages includes a language other than Ada, only
3985 -- include the Ada mains; if there is no Ada main, compile
3986 -- all the sources of the project.
3988 declare
3989 Data : constant Project_Data :=
3990 Project_Tree.Projects.Table (Main_Project);
3992 Languages : constant Variable_Value :=
3993 Prj.Util.Value_Of
3994 (Name_Languages,
3995 Data.Decl.Attributes,
3996 Project_Tree);
3998 Current : String_List_Id;
3999 Element : String_Element;
4001 Foreign_Language : Boolean := False;
4002 At_Least_One_Main : Boolean := False;
4004 begin
4005 -- First, determine if there is a foreign language in
4006 -- attribute Languages.
4008 if not Languages.Default then
4009 Current := Languages.Values;
4011 Look_For_Foreign :
4012 while Current /= Nil_String loop
4013 Element := Project_Tree.String_Elements.
4014 Table (Current);
4015 Get_Name_String (Element.Value);
4016 To_Lower (Name_Buffer (1 .. Name_Len));
4018 if Name_Buffer (1 .. Name_Len) /= "ada" then
4019 Foreign_Language := True;
4020 exit Look_For_Foreign;
4021 end if;
4023 Current := Element.Next;
4024 end loop Look_For_Foreign;
4025 end if;
4027 -- Then, find all mains, or if there is a foreign
4028 -- language, all the Ada mains.
4030 while Value /= Prj.Nil_String loop
4031 Get_Name_String
4032 (Project_Tree.String_Elements.Table
4033 (Value).Value);
4035 -- To know if a main is an Ada main, get its project.
4036 -- It should be the project specified on the command
4037 -- line.
4039 if (not Foreign_Language) or else
4040 Prj.Env.Project_Of
4041 (Name_Buffer (1 .. Name_Len),
4042 Main_Project,
4043 Project_Tree) =
4044 Main_Project
4045 then
4046 At_Least_One_Main := True;
4047 Osint.Add_File
4048 (Get_Name_String
4049 (Project_Tree.String_Elements.Table
4050 (Value).Value),
4051 Index =>
4052 Project_Tree.String_Elements.Table
4053 (Value).Index);
4054 end if;
4056 Value := Project_Tree.String_Elements.Table
4057 (Value).Next;
4058 end loop;
4060 -- If we did not get any main, it means that all mains
4061 -- in attribute Mains are in a foreign language and -B
4062 -- was not specified to gnatmake; so, we fail.
4064 if not At_Least_One_Main then
4065 Make_Failed
4066 ("no Ada mains; use -B to build foreign main");
4067 end if;
4068 end;
4070 end if;
4071 end;
4072 end if;
4073 end if;
4075 if Verbose_Mode then
4076 Write_Eol;
4077 Write_Str ("GNATMAKE ");
4078 Write_Str (Gnatvsn.Gnat_Version_String);
4079 Write_Eol;
4080 Write_Str ("Copyright 1995-2004 Free Software Foundation, Inc.");
4081 Write_Eol;
4082 end if;
4084 if Main_Project /= No_Project
4085 and then Project_Tree.Projects.Table
4086 (Main_Project).Externally_Built
4087 then
4088 Make_Failed
4089 ("nothing to do for a main project that is externally built");
4090 end if;
4092 if Osint.Number_Of_Files = 0 then
4093 if Main_Project /= No_Project
4094 and then Project_Tree.Projects.Table (Main_Project).Library
4095 then
4096 if Do_Bind_Step
4097 and then not Project_Tree.Projects.Table
4098 (Main_Project).Standalone_Library
4099 then
4100 Make_Failed ("only stand-alone libraries may be bound");
4101 end if;
4103 -- Add the default search directories to be able to find libgnat
4105 Osint.Add_Default_Search_Dirs;
4107 -- And bind and or link the library
4109 MLib.Prj.Build_Library
4110 (For_Project => Main_Project,
4111 In_Tree => Project_Tree,
4112 Gnatbind => Gnatbind.all,
4113 Gnatbind_Path => Gnatbind_Path,
4114 Gcc => Gcc.all,
4115 Gcc_Path => Gcc_Path,
4116 Bind => Bind_Only,
4117 Link => Link_Only);
4118 Exit_Program (E_Success);
4120 else
4121 -- Output usage information if no files to compile
4123 Usage;
4124 Exit_Program (E_Fatal);
4125 end if;
4126 end if;
4128 -- If -M was specified, behave as if -n was specified
4130 if List_Dependencies then
4131 Do_Not_Execute := True;
4132 end if;
4134 -- Note that Osint.Next_Main_Source will always return the (possibly
4135 -- abbreviated file) without any directory information.
4137 Main_Source_File := Next_Main_Source;
4139 if Current_File_Index /= No_Index then
4140 Main_Index := Current_File_Index;
4141 end if;
4143 Add_Switch ("-I-", Binder, And_Save => True);
4144 Add_Switch ("-I-", Compiler, And_Save => True);
4146 if Main_Project = No_Project then
4147 if Look_In_Primary_Dir then
4149 Add_Switch
4150 ("-I" &
4151 Normalize_Directory_Name
4152 (Get_Primary_Src_Search_Directory.all).all,
4153 Compiler, Append_Switch => False,
4154 And_Save => False);
4156 Add_Switch ("-aO" & Normalized_CWD,
4157 Binder,
4158 Append_Switch => False,
4159 And_Save => False);
4160 end if;
4162 else
4163 -- If we use a project file, we have already checked that a main
4164 -- specified on the command line with directory information has the
4165 -- path name corresponding to a correct source in the project tree.
4166 -- So, we don't need the directory information to be taken into
4167 -- account by Find_File, and in fact it may lead to take the wrong
4168 -- sources for other compilation units, when there are extending
4169 -- projects.
4171 Look_In_Primary_Dir := False;
4172 end if;
4174 -- If the user wants a program without a main subprogram, add the
4175 -- appropriate switch to the binder.
4177 if No_Main_Subprogram then
4178 Add_Switch ("-z", Binder, And_Save => True);
4179 end if;
4181 if Main_Project /= No_Project then
4183 if Project_Tree.Projects.Table
4184 (Main_Project).Object_Directory /= No_Name
4185 then
4186 -- Change current directory to object directory of main project
4188 Project_Object_Directory := No_Project;
4189 Change_To_Object_Directory (Main_Project);
4190 end if;
4192 -- Source file lookups should be cached for efficiency.
4193 -- Source files are not supposed to change.
4195 Osint.Source_File_Data (Cache => True);
4197 -- Find the file name of the (first) main unit
4199 declare
4200 Main_Source_File_Name : constant String :=
4201 Get_Name_String (Main_Source_File);
4202 Main_Unit_File_Name : constant String :=
4203 Prj.Env.File_Name_Of_Library_Unit_Body
4204 (Name => Main_Source_File_Name,
4205 Project => Main_Project,
4206 In_Tree => Project_Tree,
4207 Main_Project_Only =>
4208 not Unique_Compile);
4210 The_Packages : constant Package_Id :=
4211 Project_Tree.Projects.Table (Main_Project).Decl.Packages;
4213 Builder_Package : constant Prj.Package_Id :=
4214 Prj.Util.Value_Of
4215 (Name => Name_Builder,
4216 In_Packages => The_Packages,
4217 In_Tree => Project_Tree);
4219 Binder_Package : constant Prj.Package_Id :=
4220 Prj.Util.Value_Of
4221 (Name => Name_Binder,
4222 In_Packages => The_Packages,
4223 In_Tree => Project_Tree);
4225 Linker_Package : constant Prj.Package_Id :=
4226 Prj.Util.Value_Of
4227 (Name => Name_Linker,
4228 In_Packages => The_Packages,
4229 In_Tree => Project_Tree);
4231 begin
4232 -- We fail if we cannot find the main source file
4234 if Main_Unit_File_Name = "" then
4235 Make_Failed ('"' & Main_Source_File_Name,
4236 """ is not a unit of project ",
4237 Project_File_Name.all & ".");
4238 else
4239 -- Remove any directory information from the main
4240 -- source file name.
4242 declare
4243 Pos : Natural := Main_Unit_File_Name'Last;
4245 begin
4246 loop
4247 exit when Pos < Main_Unit_File_Name'First or else
4248 Main_Unit_File_Name (Pos) = Directory_Separator;
4249 Pos := Pos - 1;
4250 end loop;
4252 Name_Len := Main_Unit_File_Name'Last - Pos;
4254 Name_Buffer (1 .. Name_Len) :=
4255 Main_Unit_File_Name
4256 (Pos + 1 .. Main_Unit_File_Name'Last);
4258 Main_Source_File := Name_Find;
4260 -- We only output the main source file if there is only one
4262 if Verbose_Mode and then Osint.Number_Of_Files = 1 then
4263 Write_Str ("Main source file: """);
4264 Write_Str (Main_Unit_File_Name
4265 (Pos + 1 .. Main_Unit_File_Name'Last));
4266 Write_Line (""".");
4267 end if;
4268 end;
4269 end if;
4271 -- If there is a package Builder in the main project file, add
4272 -- the switches from it.
4274 if Builder_Package /= No_Package then
4276 -- If there is only one main, we attempt to get the gnatmake
4277 -- switches for this main (if any). If there are no specific
4278 -- switch for this particular main, get the general gnatmake
4279 -- switches (if any).
4281 if Osint.Number_Of_Files = 1 then
4282 if Verbose_Mode then
4283 Write_Str ("Adding gnatmake switches for """);
4284 Write_Str (Main_Unit_File_Name);
4285 Write_Line (""".");
4286 end if;
4288 Add_Switches
4289 (File_Name => Main_Unit_File_Name,
4290 Index => Main_Index,
4291 The_Package => Builder_Package,
4292 Program => None);
4294 else
4295 -- If there are several mains, we always get the general
4296 -- gnatmake switches (if any).
4298 -- Warn the user, if necessary, so that he is not surprized
4299 -- that specific switches are not taken into account.
4301 declare
4302 Defaults : constant Variable_Value :=
4303 Prj.Util.Value_Of
4304 (Name => Name_Ada,
4305 Index => 0,
4306 Attribute_Or_Array_Name => Name_Default_Switches,
4307 In_Package => Builder_Package,
4308 In_Tree => Project_Tree);
4310 Switches : constant Array_Element_Id :=
4311 Prj.Util.Value_Of
4312 (Name => Name_Switches,
4313 In_Arrays =>
4314 Project_Tree.Packages.Table
4315 (Builder_Package).Decl.Arrays,
4316 In_Tree => Project_Tree);
4318 begin
4319 if Defaults /= Nil_Variable_Value then
4320 if (not Quiet_Output)
4321 and then Switches /= No_Array_Element
4322 then
4323 Write_Line
4324 ("Warning: using Builder'Default_Switches" &
4325 "(""Ada""), as there are several mains");
4326 end if;
4328 -- As there is never a source with name " ", we are
4329 -- guaranteed to always get the general switches.
4331 Add_Switches
4332 (File_Name => " ",
4333 Index => 0,
4334 The_Package => Builder_Package,
4335 Program => None);
4337 elsif (not Quiet_Output)
4338 and then Switches /= No_Array_Element
4339 then
4340 Write_Line
4341 ("Warning: using no switches from package Builder," &
4342 " as there are several mains");
4343 end if;
4344 end;
4345 end if;
4346 end if;
4348 Osint.Add_Default_Search_Dirs;
4350 -- Record the current last switch index for table Binder_Switches
4351 -- and Linker_Switches, so that these tables may be reset before
4352 -- for each main, before adding swiches from the project file
4353 -- and from the command line.
4355 Last_Binder_Switch := Binder_Switches.Last;
4356 Last_Linker_Switch := Linker_Switches.Last;
4358 Check_Steps;
4360 -- Add binder switches from the project file for the first main
4362 if Do_Bind_Step and Binder_Package /= No_Package then
4363 if Verbose_Mode then
4364 Write_Str ("Adding binder switches for """);
4365 Write_Str (Main_Unit_File_Name);
4366 Write_Line (""".");
4367 end if;
4369 Add_Switches
4370 (File_Name => Main_Unit_File_Name,
4371 Index => Main_Index,
4372 The_Package => Binder_Package,
4373 Program => Binder);
4374 end if;
4376 -- Add linker switches from the project file for the first main
4378 if Do_Link_Step and Linker_Package /= No_Package then
4379 if Verbose_Mode then
4380 Write_Str ("Adding linker switches for""");
4381 Write_Str (Main_Unit_File_Name);
4382 Write_Line (""".");
4383 end if;
4385 Add_Switches
4386 (File_Name => Main_Unit_File_Name,
4387 Index => Main_Index,
4388 The_Package => Linker_Package,
4389 Program => Linker);
4390 end if;
4391 end;
4392 end if;
4394 -- Get the target parameters, which are only needed for a couple of
4395 -- cases in gnatmake. Protect against an exception, such as the case
4396 -- of system.ads missing from the library, and fail gracefully.
4398 begin
4399 Targparm.Get_Target_Parameters;
4401 exception
4402 when Unrecoverable_Error =>
4403 Make_Failed ("*** make failed.");
4404 end;
4406 Display_Commands (not Quiet_Output);
4408 Check_Steps;
4410 if Main_Project /= No_Project then
4412 -- For all library project, if the library file does not exist
4413 -- put all the project sources in the queue, and flag the project
4414 -- so that the library is generated.
4416 if not Unique_Compile
4417 and then MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None
4418 then
4419 for Proj in Project_Table.First ..
4420 Project_Table.Last (Project_Tree.Projects)
4421 loop
4422 if Project_Tree.Projects.Table (Proj).Library then
4423 Project_Tree.Projects.Table
4424 (Proj).Need_To_Build_Lib :=
4425 (not MLib.Tgt.Library_Exists_For (Proj, Project_Tree))
4426 and then (not Project_Tree.Projects.Table
4427 (Proj).Externally_Built);
4429 if Project_Tree.Projects.Table
4430 (Proj).Need_To_Build_Lib
4431 then
4432 -- If there is no object directory, then it will be
4433 -- impossible to build the library. So fail immediately.
4435 if Project_Tree.Projects.Table
4436 (Proj).Object_Directory = No_Name
4437 then
4438 Make_Failed
4439 ("no object files to build library for project """,
4440 Get_Name_String
4441 (Project_Tree.Projects.Table (Proj).Name),
4442 """");
4443 Project_Tree.Projects.Table
4444 (Proj).Need_To_Build_Lib := False;
4446 else
4447 if Verbose_Mode then
4448 Write_Str
4449 ("Library file does not exist for project """);
4450 Write_Str
4451 (Get_Name_String
4452 (Project_Tree.Projects.Table
4453 (Proj).Name));
4454 Write_Line ("""");
4455 end if;
4457 Insert_Project_Sources
4458 (The_Project => Proj,
4459 All_Projects => False,
4460 Into_Q => True);
4461 end if;
4462 end if;
4463 end if;
4464 end loop;
4465 end if;
4467 -- If a relative path output file has been specified, we add
4468 -- the exec directory.
4470 for J in reverse 1 .. Saved_Linker_Switches.Last - 1 loop
4471 if Saved_Linker_Switches.Table (J).all = Output_Flag.all then
4472 declare
4473 Exec_File_Name : constant String :=
4474 Saved_Linker_Switches.Table (J + 1).all;
4476 begin
4477 if not Is_Absolute_Path (Exec_File_Name) then
4478 Get_Name_String
4479 (Project_Tree.Projects.Table
4480 (Main_Project).Exec_Directory);
4482 if Name_Buffer (Name_Len) /= Directory_Separator then
4483 Name_Len := Name_Len + 1;
4484 Name_Buffer (Name_Len) := Directory_Separator;
4485 end if;
4487 Name_Buffer (Name_Len + 1 ..
4488 Name_Len + Exec_File_Name'Length) :=
4489 Exec_File_Name;
4490 Name_Len := Name_Len + Exec_File_Name'Length;
4491 Saved_Linker_Switches.Table (J + 1) :=
4492 new String'(Name_Buffer (1 .. Name_Len));
4493 end if;
4494 end;
4496 exit;
4497 end if;
4498 end loop;
4500 -- If we are using a project file, for relative paths we add the
4501 -- current working directory for any relative path on the command
4502 -- line and the project directory, for any relative path in the
4503 -- project file.
4505 declare
4506 Dir_Path : constant String_Access :=
4507 new String'(Get_Name_String
4508 (Project_Tree.Projects.Table
4509 (Main_Project).Directory));
4510 begin
4511 for J in 1 .. Binder_Switches.Last loop
4512 Test_If_Relative_Path
4513 (Binder_Switches.Table (J),
4514 Parent => Dir_Path, Including_L_Switch => False);
4515 end loop;
4517 for J in 1 .. Saved_Binder_Switches.Last loop
4518 Test_If_Relative_Path
4519 (Saved_Binder_Switches.Table (J),
4520 Parent => Current_Work_Dir, Including_L_Switch => False);
4521 end loop;
4523 for J in 1 .. Linker_Switches.Last loop
4524 Test_If_Relative_Path
4525 (Linker_Switches.Table (J), Parent => Dir_Path);
4526 end loop;
4528 for J in 1 .. Saved_Linker_Switches.Last loop
4529 Test_If_Relative_Path
4530 (Saved_Linker_Switches.Table (J), Parent => Current_Work_Dir);
4531 end loop;
4533 for J in 1 .. Gcc_Switches.Last loop
4534 Test_If_Relative_Path
4535 (Gcc_Switches.Table (J), Parent => Dir_Path);
4536 end loop;
4538 for J in 1 .. Saved_Gcc_Switches.Last loop
4539 Test_If_Relative_Path
4540 (Saved_Gcc_Switches.Table (J), Parent => Current_Work_Dir);
4541 end loop;
4542 end;
4543 end if;
4545 -- We now put in the Binder_Switches and Linker_Switches tables, the
4546 -- binder and linker switches of the command line that have been put in
4547 -- the Saved_ tables. If a project file was used, then the command line
4548 -- switches will follow the project file switches.
4550 for J in 1 .. Saved_Binder_Switches.Last loop
4551 Add_Switch
4552 (Saved_Binder_Switches.Table (J),
4553 Binder,
4554 And_Save => False);
4555 end loop;
4557 for J in 1 .. Saved_Linker_Switches.Last loop
4558 Add_Switch
4559 (Saved_Linker_Switches.Table (J),
4560 Linker,
4561 And_Save => False);
4562 end loop;
4564 -- If no project file is used, we just put the gcc switches
4565 -- from the command line in the Gcc_Switches table.
4567 if Main_Project = No_Project then
4568 for J in 1 .. Saved_Gcc_Switches.Last loop
4569 Add_Switch
4570 (Saved_Gcc_Switches.Table (J),
4571 Compiler,
4572 And_Save => False);
4573 end loop;
4575 else
4576 -- And we put the command line gcc switches in the variable
4577 -- The_Saved_Gcc_Switches. They are going to be used later
4578 -- in procedure Compile_Sources.
4580 The_Saved_Gcc_Switches :=
4581 new Argument_List (1 .. Saved_Gcc_Switches.Last + 1);
4583 for J in 1 .. Saved_Gcc_Switches.Last loop
4584 The_Saved_Gcc_Switches (J) := Saved_Gcc_Switches.Table (J);
4585 end loop;
4587 -- We never use gnat.adc when a project file is used
4589 The_Saved_Gcc_Switches (The_Saved_Gcc_Switches'Last) :=
4590 No_gnat_adc;
4592 end if;
4594 -- If there was a --GCC, --GNATBIND or --GNATLINK switch on
4595 -- the command line, then we have to use it, even if there was
4596 -- another switch in the project file.
4598 if Saved_Gcc /= null then
4599 Gcc := Saved_Gcc;
4600 end if;
4602 if Saved_Gnatbind /= null then
4603 Gnatbind := Saved_Gnatbind;
4604 end if;
4606 if Saved_Gnatlink /= null then
4607 Gnatlink := Saved_Gnatlink;
4608 end if;
4610 Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
4611 Gnatbind_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
4612 Gnatlink_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
4614 -- If we have specified -j switch both from the project file
4615 -- and on the command line, the one from the command line takes
4616 -- precedence.
4618 if Saved_Maximum_Processes = 0 then
4619 Saved_Maximum_Processes := Maximum_Processes;
4620 end if;
4622 -- Allocate as many temporary mapping file names as the maximum
4623 -- number of compilation processed, for each possible project.
4625 The_Mapping_File_Names :=
4626 new Temp_File_Names
4627 (No_Project .. Project_Table.Last (Project_Tree.Projects),
4628 1 .. Saved_Maximum_Processes);
4629 Last_Mapping_File_Names :=
4630 new Indices'
4631 (No_Project .. Project_Table.Last (Project_Tree.Projects)
4632 => 0);
4634 The_Free_Mapping_File_Indices :=
4635 new Free_File_Indices
4636 (No_Project .. Project_Table.Last (Project_Tree.Projects),
4637 1 .. Saved_Maximum_Processes);
4638 Last_Free_Indices :=
4639 new Indices'(No_Project .. Project_Table.Last
4640 (Project_Tree.Projects) => 0);
4642 Bad_Compilation.Init;
4644 Current_Main_Index := Main_Index;
4646 -- Here is where the make process is started
4648 -- We do the same process for each main
4650 Multiple_Main_Loop : for N_File in 1 .. Osint.Number_Of_Files loop
4652 -- First, find the executable name and path
4654 Executable := No_File;
4655 Executable_Obsolete := False;
4656 Non_Std_Executable := False;
4658 -- Look inside the linker switches to see if the name
4659 -- of the final executable program was specified.
4662 J in reverse Linker_Switches.First .. Linker_Switches.Last
4663 loop
4664 if Linker_Switches.Table (J).all = Output_Flag.all then
4665 pragma Assert (J < Linker_Switches.Last);
4667 -- We cannot specify a single executable for several
4668 -- main subprograms!
4670 if Osint.Number_Of_Files > 1 then
4671 Fail
4672 ("cannot specify a single executable " &
4673 "for several mains");
4674 end if;
4676 Name_Len := Linker_Switches.Table (J + 1)'Length;
4677 Name_Buffer (1 .. Name_Len) :=
4678 Linker_Switches.Table (J + 1).all;
4679 Executable := Name_Enter;
4681 Verbose_Msg (Executable, "final executable");
4682 end if;
4683 end loop;
4685 -- If the name of the final executable program was not
4686 -- specified then construct it from the main input file.
4688 if Executable = No_File then
4689 if Main_Project = No_Project then
4690 Executable :=
4691 Executable_Name (Strip_Suffix (Main_Source_File));
4693 else
4694 -- If we are using a project file, we attempt to
4695 -- remove the body (or spec) termination of the main
4696 -- subprogram. We find it the the naming scheme of the
4697 -- project file. This will avoid to generate an
4698 -- executable "main.2" for a main subprogram
4699 -- "main.2.ada", when the body termination is ".2.ada".
4701 Executable :=
4702 Prj.Util.Executable_Of
4703 (Main_Project, Project_Tree, Main_Source_File, Main_Index);
4704 end if;
4705 end if;
4707 if Main_Project /= No_Project then
4708 declare
4709 Exec_File_Name : constant String :=
4710 Get_Name_String (Executable);
4712 begin
4713 if not Is_Absolute_Path (Exec_File_Name) then
4715 Get_Name_String (Project_Tree.Projects.Table
4716 (Main_Project).Exec_Directory);
4719 Name_Buffer (Name_Len) /= Directory_Separator
4720 then
4721 Name_Len := Name_Len + 1;
4722 Name_Buffer (Name_Len) := Directory_Separator;
4723 end if;
4725 Name_Buffer (Name_Len + 1 ..
4726 Name_Len + Exec_File_Name'Length) :=
4727 Exec_File_Name;
4729 Name_Len := Name_Len + Exec_File_Name'Length;
4730 Executable := Name_Find;
4731 end if;
4733 Non_Std_Executable := True;
4734 end;
4735 end if;
4737 if Do_Compile_Step then
4738 Recursive_Compilation_Step : declare
4739 Args : Argument_List (1 .. Gcc_Switches.Last);
4741 First_Compiled_File : Name_Id;
4742 Youngest_Obj_File : Name_Id;
4743 Youngest_Obj_Stamp : Time_Stamp_Type;
4745 Executable_Stamp : Time_Stamp_Type;
4746 -- Executable is the final executable program
4748 Library_Rebuilt : Boolean := False;
4750 begin
4751 for J in 1 .. Gcc_Switches.Last loop
4752 Args (J) := Gcc_Switches.Table (J);
4753 end loop;
4755 -- Now we invoke Compile_Sources for the current main
4757 Compile_Sources
4758 (Main_Source => Main_Source_File,
4759 Args => Args,
4760 First_Compiled_File => First_Compiled_File,
4761 Most_Recent_Obj_File => Youngest_Obj_File,
4762 Most_Recent_Obj_Stamp => Youngest_Obj_Stamp,
4763 Main_Unit => Is_Main_Unit,
4764 Main_Index => Current_Main_Index,
4765 Compilation_Failures => Compilation_Failures,
4766 Check_Readonly_Files => Check_Readonly_Files,
4767 Do_Not_Execute => Do_Not_Execute,
4768 Force_Compilations => Force_Compilations,
4769 In_Place_Mode => In_Place_Mode,
4770 Keep_Going => Keep_Going,
4771 Initialize_ALI_Data => True,
4772 Max_Process => Saved_Maximum_Processes);
4774 if Verbose_Mode then
4775 Write_Str ("End of compilation");
4776 Write_Eol;
4777 end if;
4779 -- Make sure the queue will be reinitialized for the next round
4781 First_Q_Initialization := True;
4783 Total_Compilation_Failures :=
4784 Total_Compilation_Failures + Compilation_Failures;
4786 if Total_Compilation_Failures /= 0 then
4787 if Keep_Going then
4788 goto Next_Main;
4789 else
4790 List_Bad_Compilations;
4791 raise Compilation_Failed;
4792 end if;
4793 end if;
4795 -- Regenerate libraries, if any, and if object files
4796 -- have been regenerated.
4798 if Main_Project /= No_Project
4799 and then MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None
4800 and then (Do_Bind_Step or Unique_Compile_All_Projects
4801 or not Compile_Only)
4802 and then (Do_Link_Step or N_File = Osint.Number_Of_Files)
4803 then
4804 Library_Projs.Init;
4806 declare
4807 Proj2 : Project_Id;
4808 Depth : Natural;
4809 Current : Natural;
4811 begin
4812 -- Put in Library_Projs table all library project
4813 -- file ids when the library need to be rebuilt.
4815 for Proj1 in Project_Table.First ..
4816 Project_Table.Last (Project_Tree.Projects)
4817 loop
4818 if Project_Tree.Projects.Table
4819 (Proj1).Standalone_Library
4820 then
4821 There_Are_Stand_Alone_Libraries := True;
4822 end if;
4824 if Project_Tree.Projects.Table (Proj1).Library
4825 and then not Project_Tree.Projects.Table
4826 (Proj1).Need_To_Build_Lib
4827 and then not Project_Tree.Projects.Table
4828 (Proj1).Externally_Built
4829 then
4830 MLib.Prj.Check_Library (Proj1, Project_Tree);
4831 end if;
4833 if Project_Tree.Projects.Table
4834 (Proj1).Need_To_Build_Lib
4835 then
4836 Library_Projs.Increment_Last;
4837 Current := Library_Projs.Last;
4838 Depth := Project_Tree.Projects.Table
4839 (Proj1).Depth;
4841 -- Put the projects in decreasing depth order,
4842 -- so that if libA depends on libB, libB is first
4843 -- in order.
4845 while Current > 1 loop
4846 Proj2 := Library_Projs.Table (Current - 1);
4847 exit when Project_Tree.Projects.Table
4848 (Proj2).Depth >= Depth;
4849 Library_Projs.Table (Current) := Proj2;
4850 Current := Current - 1;
4851 end loop;
4853 Library_Projs.Table (Current) := Proj1;
4854 Project_Tree.Projects.Table
4855 (Proj1).Need_To_Build_Lib := False;
4856 end if;
4857 end loop;
4858 end;
4860 -- Build the libraries, if any need to be built
4862 for J in 1 .. Library_Projs.Last loop
4863 Library_Rebuilt := True;
4864 MLib.Prj.Build_Library
4865 (For_Project => Library_Projs.Table (J),
4866 In_Tree => Project_Tree,
4867 Gnatbind => Gnatbind.all,
4868 Gnatbind_Path => Gnatbind_Path,
4869 Gcc => Gcc.all,
4870 Gcc_Path => Gcc_Path);
4871 end loop;
4872 end if;
4874 if List_Dependencies then
4875 if First_Compiled_File /= No_File then
4876 Inform
4877 (First_Compiled_File,
4878 "must be recompiled. Can't generate dependence list.");
4879 else
4880 List_Depend;
4881 end if;
4883 elsif First_Compiled_File = No_File
4884 and then not Do_Bind_Step
4885 and then not Quiet_Output
4886 and then not Library_Rebuilt
4887 and then Osint.Number_Of_Files = 1
4888 then
4889 Inform (Msg => "objects up to date.");
4891 elsif Do_Not_Execute
4892 and then First_Compiled_File /= No_File
4893 then
4894 Write_Name (First_Compiled_File);
4895 Write_Eol;
4896 end if;
4898 -- Stop after compile step if any of:
4900 -- 1) -n (Do_Not_Execute) specified
4902 -- 2) -M (List_Dependencies) specified (also sets
4903 -- Do_Not_Execute above, so this is probably superfluous).
4905 -- 3) -c (Compile_Only) specified, but not -b (Bind_Only)
4907 -- 4) Made unit cannot be a main unit
4909 if (Do_Not_Execute
4910 or List_Dependencies
4911 or not Do_Bind_Step
4912 or not Is_Main_Unit)
4913 and then not No_Main_Subprogram
4914 and then not Build_Bind_And_Link_Full_Project
4915 then
4916 if Osint.Number_Of_Files = 1 then
4917 exit Multiple_Main_Loop;
4919 else
4920 goto Next_Main;
4921 end if;
4922 end if;
4924 -- If the objects were up-to-date check if the executable file
4925 -- is also up-to-date. For now always bind and link on the JVM
4926 -- since there is currently no simple way to check the
4927 -- up-to-date status of objects
4929 if not Hostparm.Java_VM
4930 and then First_Compiled_File = No_File
4931 then
4932 Executable_Stamp := File_Stamp (Executable);
4934 if not Executable_Obsolete then
4935 Executable_Obsolete :=
4936 Youngest_Obj_Stamp > Executable_Stamp;
4937 end if;
4939 if not Executable_Obsolete then
4940 for Index in reverse 1 .. Dependencies.Last loop
4941 if Is_In_Obsoleted
4942 (Dependencies.Table (Index).Depends_On)
4943 then
4944 Enter_Into_Obsoleted
4945 (Dependencies.Table (Index).This);
4946 end if;
4947 end loop;
4949 Executable_Obsolete := Is_In_Obsoleted (Main_Source_File);
4950 Dependencies.Init;
4951 end if;
4953 if not Executable_Obsolete then
4955 -- If no Ada object files obsolete the executable, check
4956 -- for younger or missing linker files.
4958 Check_Linker_Options
4959 (Executable_Stamp,
4960 Youngest_Obj_File,
4961 Youngest_Obj_Stamp);
4963 Executable_Obsolete := Youngest_Obj_File /= No_File;
4964 end if;
4966 -- Return if the executable is up to date
4967 -- and otherwise motivate the relink/rebind.
4969 if not Executable_Obsolete then
4970 if not Quiet_Output then
4971 Inform (Executable, "up to date.");
4972 end if;
4974 if Osint.Number_Of_Files = 1 then
4975 exit Multiple_Main_Loop;
4977 else
4978 goto Next_Main;
4979 end if;
4980 end if;
4982 if Executable_Stamp (1) = ' ' then
4983 Verbose_Msg (Executable, "missing.", Prefix => " ");
4985 elsif Youngest_Obj_Stamp (1) = ' ' then
4986 Verbose_Msg
4987 (Youngest_Obj_File,
4988 "missing.",
4989 Prefix => " ");
4991 elsif Youngest_Obj_Stamp > Executable_Stamp then
4992 Verbose_Msg
4993 (Youngest_Obj_File,
4994 "(" & String (Youngest_Obj_Stamp) & ") newer than",
4995 Executable,
4996 "(" & String (Executable_Stamp) & ")");
4998 else
4999 Verbose_Msg
5000 (Executable, "needs to be rebuild.",
5001 Prefix => " ");
5003 end if;
5004 end if;
5005 end Recursive_Compilation_Step;
5006 end if;
5008 -- For binding and linking, we need to be in the object directory of
5009 -- the main project.
5011 if Main_Project /= No_Project then
5012 Change_To_Object_Directory (Main_Project);
5013 end if;
5015 -- If we are here, it means that we need to rebuilt the current
5016 -- main. So we set Executable_Obsolete to True to make sure that
5017 -- the subsequent mains will be rebuilt.
5019 Main_ALI_In_Place_Mode_Step : declare
5020 ALI_File : File_Name_Type;
5021 Src_File : File_Name_Type;
5023 begin
5024 Src_File := Strip_Directory (Main_Source_File);
5025 ALI_File := Lib_File_Name (Src_File, Current_Main_Index);
5026 Main_ALI_File := Full_Lib_File_Name (ALI_File);
5028 -- When In_Place_Mode, the library file can be located in the
5029 -- Main_Source_File directory which may not be present in the
5030 -- library path. In this case, use the corresponding library file
5031 -- name.
5033 if Main_ALI_File = No_File and then In_Place_Mode then
5034 Get_Name_String (Get_Directory (Full_Source_Name (Src_File)));
5035 Get_Name_String_And_Append (ALI_File);
5036 Main_ALI_File := Name_Find;
5037 Main_ALI_File := Full_Lib_File_Name (Main_ALI_File);
5038 end if;
5040 if Main_ALI_File = No_File then
5041 Make_Failed ("could not find the main ALI file");
5042 end if;
5043 end Main_ALI_In_Place_Mode_Step;
5045 if Do_Bind_Step then
5046 Bind_Step : declare
5047 Args : Argument_List
5048 (Binder_Switches.First .. Binder_Switches.Last + 2);
5049 -- The arguments for the invocation of gnatbind
5051 Last_Arg : Natural := Binder_Switches.Last;
5052 -- Index of the last argument in Args
5054 Shared_Libs : Boolean := False;
5055 -- Set to True when there are shared library project files or
5056 -- when gnatbind is invoked with -shared.
5058 begin
5059 -- Check if there are shared libraries, so that gnatbind is
5060 -- called with -shared. Check also if gnatbind is called with
5061 -- -shared, so that gnatlink is called with -shared-libgcc
5062 -- for GCC version 3 and above, ensuring that the shared
5063 -- version of libgcc will be used.
5065 if Main_Project /= No_Project
5066 and then MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None
5067 then
5068 for Proj in Project_Table.First ..
5069 Project_Table.Last (Project_Tree.Projects)
5070 loop
5071 if Project_Tree.Projects.Table (Proj).Library
5072 and then Project_Tree.Projects.Table
5073 (Proj).Library_Kind /= Static
5074 then
5075 Shared_Libs := True;
5076 Bind_Shared := Shared_Switch'Access;
5077 exit;
5078 end if;
5079 end loop;
5080 end if;
5082 -- Check now for switch -shared
5084 if not Shared_Libs then
5085 for J in Binder_Switches.First .. Last_Arg loop
5086 if Binder_Switches.Table (J).all = "-shared" then
5087 Shared_Libs := True;
5088 exit;
5089 end if;
5090 end loop;
5091 end if;
5093 -- If there are shared libraries, invoke gnatlink with
5094 -- -shared-libgcc if GCC version is 3 or more.
5096 if Shared_Libs and then GCC_Version >= 3 then
5097 Link_With_Shared_Libgcc := Shared_Libgcc_Switch'Access;
5098 end if;
5100 -- Get all the binder switches
5102 for J in Binder_Switches.First .. Last_Arg loop
5103 Args (J) := Binder_Switches.Table (J);
5104 end loop;
5106 if There_Are_Stand_Alone_Libraries then
5107 Last_Arg := Last_Arg + 1;
5108 Args (Last_Arg) := Force_Elab_Flags_String'Access;
5109 end if;
5111 if Main_Project /= No_Project then
5113 -- Put all the source directories in ADA_INCLUDE_PATH,
5114 -- and all the object directories in ADA_OBJECTS_PATH
5116 Prj.Env.Set_Ada_Paths (Main_Project, Project_Tree, False);
5118 -- If switch -C was specified, create a binder mapping file
5120 if Create_Mapping_File then
5121 Create_Binder_Mapping_File (Args, Last_Arg);
5122 end if;
5124 end if;
5126 begin
5127 Bind (Main_ALI_File,
5128 Bind_Shared.all & Args (Args'First .. Last_Arg));
5130 exception
5131 when others =>
5133 -- If -dn was not specified, delete the temporary mapping
5134 -- file, if one was created.
5136 if not Debug.Debug_Flag_N
5137 and then Mapping_Path /= No_Name
5138 then
5139 Delete_File (Get_Name_String (Mapping_Path), Discard);
5140 end if;
5142 -- And reraise the exception
5144 raise;
5145 end;
5147 -- If -dn was not specified, delete the temporary mapping file,
5148 -- if one was created.
5150 if not Debug.Debug_Flag_N and then Mapping_Path /= No_Name then
5151 Delete_File (Get_Name_String (Mapping_Path), Discard);
5152 end if;
5153 end Bind_Step;
5154 end if;
5156 if Do_Link_Step then
5157 Link_Step : declare
5158 There_Are_Libraries : Boolean := False;
5159 Linker_Switches_Last : constant Integer := Linker_Switches.Last;
5160 Path_Option : constant String_Access :=
5161 MLib.Linker_Library_Path_Option;
5162 Current : Natural;
5163 Proj2 : Project_Id;
5164 Depth : Natural;
5166 begin
5167 if not Run_Path_Option then
5168 Linker_Switches.Increment_Last;
5169 Linker_Switches.Table (Linker_Switches.Last) :=
5170 new String'("-R");
5171 end if;
5173 if Main_Project /= No_Project then
5174 Library_Paths.Set_Last (0);
5175 Library_Projs.Init;
5177 if MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None then
5178 -- Check for library projects
5180 for Proj1 in Project_Table.First ..
5181 Project_Table.Last (Project_Tree.Projects)
5182 loop
5183 if Proj1 /= Main_Project
5184 and then
5185 Project_Tree.Projects.Table (Proj1).Library
5186 then
5187 -- Add this project to table Library_Projs
5189 There_Are_Libraries := True;
5190 Depth :=
5191 Project_Tree.Projects.Table (Proj1).Depth;
5192 Library_Projs.Increment_Last;
5193 Current := Library_Projs.Last;
5195 -- Any project with a greater depth should be
5196 -- after this project in the list.
5198 while Current > 1 loop
5199 Proj2 := Library_Projs.Table (Current - 1);
5200 exit when Project_Tree.Projects.Table
5201 (Proj2).Depth <= Depth;
5202 Library_Projs.Table (Current) := Proj2;
5203 Current := Current - 1;
5204 end loop;
5206 Library_Projs.Table (Current) := Proj1;
5208 -- If it is not a static library and path option
5209 -- is set, add it to the Library_Paths table.
5211 if Project_Tree.Projects.Table
5212 (Proj1).Library_Kind /= Static
5213 and then Path_Option /= null
5214 then
5215 Library_Paths.Increment_Last;
5216 Library_Paths.Table (Library_Paths.Last) :=
5217 new String'
5218 (Get_Name_String
5219 (Project_Tree.Projects.Table
5220 (Proj1).Library_Dir));
5221 end if;
5222 end if;
5223 end loop;
5225 for Index in 1 .. Library_Projs.Last loop
5226 -- Add the -L switch
5228 Linker_Switches.Increment_Last;
5229 Linker_Switches.Table (Linker_Switches.Last) :=
5230 new String'("-L" &
5231 Get_Name_String
5232 (Project_Tree.Projects.Table
5233 (Library_Projs.Table (Index)).
5234 Library_Dir));
5236 -- Add the -l switch
5238 Linker_Switches.Increment_Last;
5239 Linker_Switches.Table (Linker_Switches.Last) :=
5240 new String'("-l" &
5241 Get_Name_String
5242 (Project_Tree.Projects.Table
5243 (Library_Projs.Table (Index)).
5244 Library_Name));
5245 end loop;
5246 end if;
5248 if There_Are_Libraries then
5250 -- If Path_Option is not null, create the switch
5251 -- ("-Wl,-rpath," or equivalent) with all the non static
5252 -- library dirs plus the standard GNAT library dir.
5253 -- We do that only if Run_Path_Option is True
5254 -- (not disabled by -R switch).
5256 if Run_Path_Option and Path_Option /= null then
5257 declare
5258 Option : String_Access;
5259 Length : Natural := Path_Option'Length;
5260 Current : Natural;
5262 begin
5263 for Index in
5264 Library_Paths.First .. Library_Paths.Last
5265 loop
5266 -- Add the length of the library dir plus one
5267 -- for the directory separator.
5269 Length :=
5270 Length +
5271 Library_Paths.Table (Index)'Length + 1;
5272 end loop;
5274 -- Finally, add the length of the standard GNAT
5275 -- library dir.
5277 Length := Length + MLib.Utl.Lib_Directory'Length;
5278 Option := new String (1 .. Length);
5279 Option (1 .. Path_Option'Length) := Path_Option.all;
5280 Current := Path_Option'Length;
5282 -- Put each library dir followed by a dir separator
5284 for Index in
5285 Library_Paths.First .. Library_Paths.Last
5286 loop
5287 Option
5288 (Current + 1 ..
5289 Current +
5290 Library_Paths.Table (Index)'Length) :=
5291 Library_Paths.Table (Index).all;
5292 Current :=
5293 Current +
5294 Library_Paths.Table (Index)'Length + 1;
5295 Option (Current) := Path_Separator;
5296 end loop;
5298 -- Finally put the standard GNAT library dir
5300 Option
5301 (Current + 1 ..
5302 Current + MLib.Utl.Lib_Directory'Length) :=
5303 MLib.Utl.Lib_Directory;
5305 -- And add the switch to the linker switches
5307 Linker_Switches.Increment_Last;
5308 Linker_Switches.Table (Linker_Switches.Last) :=
5309 Option;
5310 end;
5311 end if;
5313 end if;
5315 -- Put the object directories in ADA_OBJECTS_PATH
5317 Prj.Env.Set_Ada_Paths (Main_Project, Project_Tree, False);
5319 -- Check for attributes Linker'Linker_Options in projects
5320 -- other than the main project
5322 declare
5323 Linker_Options : constant String_List :=
5324 Linker_Options_Switches
5325 (Main_Project, Project_Tree);
5326 begin
5327 for Option in Linker_Options'Range loop
5328 Linker_Switches.Increment_Last;
5329 Linker_Switches.Table (Linker_Switches.Last) :=
5330 Linker_Options (Option);
5331 end loop;
5332 end;
5333 end if;
5335 declare
5336 Args : Argument_List
5337 (Linker_Switches.First .. Linker_Switches.Last + 2);
5339 Last_Arg : Integer := Linker_Switches.First - 1;
5340 Skip : Boolean := False;
5342 begin
5343 -- Get all the linker switches
5345 for J in Linker_Switches.First .. Linker_Switches.Last loop
5346 if Skip then
5347 Skip := False;
5349 elsif Non_Std_Executable
5350 and then Linker_Switches.Table (J).all = "-o"
5351 then
5352 Skip := True;
5354 else
5355 Last_Arg := Last_Arg + 1;
5356 Args (Last_Arg) := Linker_Switches.Table (J);
5357 end if;
5358 end loop;
5360 -- If need be, add the -o switch
5362 if Non_Std_Executable then
5363 Last_Arg := Last_Arg + 1;
5364 Args (Last_Arg) := new String'("-o");
5365 Last_Arg := Last_Arg + 1;
5366 Args (Last_Arg) :=
5367 new String'(Get_Name_String (Executable));
5368 end if;
5370 -- And invoke the linker
5372 begin
5373 Link (Main_ALI_File,
5374 Link_With_Shared_Libgcc.all &
5375 Args (Args'First .. Last_Arg));
5376 Successful_Links.Increment_Last;
5377 Successful_Links.Table (Successful_Links.Last) :=
5378 Main_ALI_File;
5380 exception
5381 when Link_Failed =>
5382 if Osint.Number_Of_Files = 1 or not Keep_Going then
5383 raise;
5385 else
5386 Write_Line ("*** link failed");
5387 Failed_Links.Increment_Last;
5388 Failed_Links.Table (Failed_Links.Last) :=
5389 Main_ALI_File;
5390 end if;
5391 end;
5392 end;
5394 Linker_Switches.Set_Last (Linker_Switches_Last);
5395 end Link_Step;
5396 end if;
5398 -- We go to here when we skip the bind and link steps
5400 <<Next_Main>>
5402 -- We go to the next main, if we did not process the last one
5404 if N_File < Osint.Number_Of_Files then
5405 Main_Source_File := Next_Main_Source;
5407 if Current_File_Index /= No_Index then
5408 Main_Index := Current_File_Index;
5409 end if;
5411 if Main_Project /= No_Project then
5413 -- Find the file name of the main unit
5415 declare
5416 Main_Source_File_Name : constant String :=
5417 Get_Name_String (Main_Source_File);
5419 Main_Unit_File_Name : constant String :=
5420 Prj.Env.
5421 File_Name_Of_Library_Unit_Body
5422 (Name => Main_Source_File_Name,
5423 Project => Main_Project,
5424 In_Tree => Project_Tree,
5425 Main_Project_Only =>
5426 not Unique_Compile);
5428 The_Packages : constant Package_Id :=
5429 Project_Tree.Projects.Table
5430 (Main_Project).Decl.Packages;
5432 Binder_Package : constant Prj.Package_Id :=
5433 Prj.Util.Value_Of
5434 (Name => Name_Binder,
5435 In_Packages => The_Packages,
5436 In_Tree => Project_Tree);
5438 Linker_Package : constant Prj.Package_Id :=
5439 Prj.Util.Value_Of
5440 (Name => Name_Linker,
5441 In_Packages => The_Packages,
5442 In_Tree => Project_Tree);
5444 begin
5445 -- We fail if we cannot find the main source file
5446 -- as an immediate source of the main project file.
5448 if Main_Unit_File_Name = "" then
5449 Make_Failed ('"' & Main_Source_File_Name,
5450 """ is not a unit of project ",
5451 Project_File_Name.all & ".");
5453 else
5454 -- Remove any directory information from the main
5455 -- source file name.
5457 declare
5458 Pos : Natural := Main_Unit_File_Name'Last;
5460 begin
5461 loop
5462 exit when Pos < Main_Unit_File_Name'First
5463 or else
5464 Main_Unit_File_Name (Pos) = Directory_Separator;
5465 Pos := Pos - 1;
5466 end loop;
5468 Name_Len := Main_Unit_File_Name'Last - Pos;
5470 Name_Buffer (1 .. Name_Len) :=
5471 Main_Unit_File_Name
5472 (Pos + 1 .. Main_Unit_File_Name'Last);
5474 Main_Source_File := Name_Find;
5475 end;
5476 end if;
5478 -- We now deal with the binder and linker switches.
5479 -- If no project file is used, there is nothing to do
5480 -- because the binder and linker switches are the same
5481 -- for all mains.
5483 -- Reset the tables Binder_Switches and Linker_Switches
5485 Binder_Switches.Set_Last (Last_Binder_Switch);
5486 Linker_Switches.Set_Last (Last_Linker_Switch);
5488 -- Add binder switches from the project file for this main,
5489 -- if any.
5491 if Do_Bind_Step and Binder_Package /= No_Package then
5492 if Verbose_Mode then
5493 Write_Str ("Adding binder switches for """);
5494 Write_Str (Main_Unit_File_Name);
5495 Write_Line (""".");
5496 end if;
5498 Add_Switches
5499 (File_Name => Main_Unit_File_Name,
5500 Index => Main_Index,
5501 The_Package => Binder_Package,
5502 Program => Binder);
5503 end if;
5505 -- Add linker switches from the project file for this main,
5506 -- if any.
5508 if Do_Link_Step and Linker_Package /= No_Package then
5509 if Verbose_Mode then
5510 Write_Str ("Adding linker switches for""");
5511 Write_Str (Main_Unit_File_Name);
5512 Write_Line (""".");
5513 end if;
5515 Add_Switches
5516 (File_Name => Main_Unit_File_Name,
5517 Index => Main_Index,
5518 The_Package => Linker_Package,
5519 Program => Linker);
5520 end if;
5522 -- As we are using a project file, for relative paths we add
5523 -- the current working directory for any relative path on
5524 -- the command line and the project directory, for any
5525 -- relative path in the project file.
5527 declare
5528 Dir_Path : constant String_Access :=
5529 new String'(Get_Name_String
5530 (Project_Tree.Projects.Table
5531 (Main_Project).Directory));
5532 begin
5534 J in Last_Binder_Switch + 1 .. Binder_Switches.Last
5535 loop
5536 Test_If_Relative_Path
5537 (Binder_Switches.Table (J),
5538 Parent => Dir_Path, Including_L_Switch => False);
5539 end loop;
5542 J in Last_Linker_Switch + 1 .. Linker_Switches.Last
5543 loop
5544 Test_If_Relative_Path
5545 (Linker_Switches.Table (J), Parent => Dir_Path);
5546 end loop;
5547 end;
5549 -- We now put in the Binder_Switches and Linker_Switches
5550 -- tables, the binder and linker switches of the command
5551 -- line that have been put in the Saved_ tables.
5552 -- These switches will follow the project file switches.
5554 for J in 1 .. Saved_Binder_Switches.Last loop
5555 Add_Switch
5556 (Saved_Binder_Switches.Table (J),
5557 Binder,
5558 And_Save => False);
5559 end loop;
5561 for J in 1 .. Saved_Linker_Switches.Last loop
5562 Add_Switch
5563 (Saved_Linker_Switches.Table (J),
5564 Linker,
5565 And_Save => False);
5566 end loop;
5567 end;
5568 end if;
5569 end if;
5571 -- Remove all marks to be sure to check sources for all executables,
5572 -- as the switches may be different and -s may be in use.
5574 Delete_All_Marks;
5575 end loop Multiple_Main_Loop;
5577 if Failed_Links.Last > 0 then
5578 for Index in 1 .. Successful_Links.Last loop
5579 Write_Str ("Linking of """);
5580 Write_Str (Get_Name_String (Successful_Links.Table (Index)));
5581 Write_Line (""" succeeded.");
5582 end loop;
5584 for Index in 1 .. Failed_Links.Last loop
5585 Write_Str ("Linking of """);
5586 Write_Str (Get_Name_String (Failed_Links.Table (Index)));
5587 Write_Line (""" failed.");
5588 end loop;
5590 if Total_Compilation_Failures = 0 then
5591 raise Compilation_Failed;
5592 end if;
5593 end if;
5595 if Total_Compilation_Failures /= 0 then
5596 List_Bad_Compilations;
5597 raise Compilation_Failed;
5598 end if;
5600 -- Delete the temporary mapping file that was created if we are
5601 -- using project files.
5603 if not Debug.Debug_Flag_N then
5604 Delete_Mapping_Files;
5605 Prj.Env.Delete_All_Path_Files (Project_Tree);
5606 end if;
5608 Exit_Program (E_Success);
5610 exception
5611 when Bind_Failed =>
5612 Make_Failed ("*** bind failed.");
5614 when Compilation_Failed =>
5615 if not Debug.Debug_Flag_N then
5616 Delete_Mapping_Files;
5617 Prj.Env.Delete_All_Path_Files (Project_Tree);
5618 end if;
5620 Exit_Program (E_Fatal);
5622 when Link_Failed =>
5623 Make_Failed ("*** link failed.");
5625 when X : others =>
5626 Write_Line (Exception_Information (X));
5627 Make_Failed ("INTERNAL ERROR. Please report.");
5628 end Gnatmake;
5630 ----------
5631 -- Hash --
5632 ----------
5634 function Hash (F : Name_Id) return Header_Num is
5635 begin
5636 return Header_Num (1 + F mod Max_Header);
5637 end Hash;
5639 --------------------
5640 -- In_Ada_Lib_Dir --
5641 --------------------
5643 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean is
5644 D : constant Name_Id := Get_Directory (File);
5645 B : constant Byte := Get_Name_Table_Byte (D);
5646 begin
5647 return (B and Ada_Lib_Dir) /= 0;
5648 end In_Ada_Lib_Dir;
5650 ------------
5651 -- Inform --
5652 ------------
5654 procedure Inform (N : Name_Id := No_Name; Msg : String) is
5655 begin
5656 Osint.Write_Program_Name;
5658 Write_Str (": ");
5660 if N /= No_Name then
5661 Write_Str ("""");
5662 Write_Name (N);
5663 Write_Str (""" ");
5664 end if;
5666 Write_Str (Msg);
5667 Write_Eol;
5668 end Inform;
5670 -----------------------
5671 -- Init_Mapping_File --
5672 -----------------------
5674 procedure Init_Mapping_File
5675 (Project : Project_Id;
5676 File_Index : in out Natural)
5678 FD : File_Descriptor;
5680 Status : Boolean;
5681 -- For call to Close
5683 begin
5684 -- Increase the index of the last mapping file for this project
5686 Last_Mapping_File_Names (Project) :=
5687 Last_Mapping_File_Names (Project) + 1;
5689 -- If there is a project file, call Create_Mapping_File with
5690 -- the project id.
5692 if Project /= No_Project then
5693 Prj.Env.Create_Mapping_File
5694 (Project, Project_Tree,
5695 The_Mapping_File_Names
5696 (Project, Last_Mapping_File_Names (Project)));
5698 -- Otherwise, just create an empty file
5700 else
5701 Tempdir.Create_Temp_File
5702 (FD,
5703 The_Mapping_File_Names
5704 (No_Project, Last_Mapping_File_Names (No_Project)));
5705 if FD = Invalid_FD then
5706 Make_Failed ("disk full");
5707 end if;
5709 Close (FD, Status);
5711 if not Status then
5712 Make_Failed ("disk full");
5713 end if;
5714 end if;
5716 -- And return the index of the newly created file
5718 File_Index := Last_Mapping_File_Names (Project);
5719 end Init_Mapping_File;
5721 ------------
5722 -- Init_Q --
5723 ------------
5725 procedure Init_Q is
5726 begin
5727 First_Q_Initialization := False;
5728 Q_Front := Q.First;
5729 Q.Set_Last (Q.First);
5730 end Init_Q;
5732 ----------------
5733 -- Initialize --
5734 ----------------
5736 procedure Initialize is
5737 begin
5738 -- Override default initialization of Check_Object_Consistency
5739 -- since this is normally False for GNATBIND, but is True for
5740 -- GNATMAKE since we do not need to check source consistency
5741 -- again once GNATMAKE has looked at the sources to check.
5743 Check_Object_Consistency := True;
5745 -- Package initializations. The order of calls is important here
5747 Output.Set_Standard_Error;
5749 Gcc_Switches.Init;
5750 Binder_Switches.Init;
5751 Linker_Switches.Init;
5753 Csets.Initialize;
5754 Namet.Initialize;
5756 Snames.Initialize;
5758 Prj.Initialize (Project_Tree);
5760 Dependencies.Init;
5762 RTS_Specified := null;
5764 Mains.Delete;
5766 -- Add the directory where gnatmake is invoked in front of the
5767 -- path, if gnatmake is invoked with directory information.
5768 -- Only do this if the platform is not VMS, where the notion of path
5769 -- does not really exist.
5771 if not OpenVMS then
5772 declare
5773 Command : constant String := Command_Name;
5775 begin
5776 for Index in reverse Command'Range loop
5777 if Command (Index) = Directory_Separator then
5778 declare
5779 Absolute_Dir : constant String :=
5780 Normalize_Pathname
5781 (Command (Command'First .. Index));
5783 PATH : constant String :=
5784 Absolute_Dir &
5785 Path_Separator &
5786 Getenv ("PATH").all;
5788 begin
5789 Setenv ("PATH", PATH);
5790 end;
5792 exit;
5793 end if;
5794 end loop;
5795 end;
5796 end if;
5798 -- Scan the switches and arguments
5800 Scan_Args : for Next_Arg in 1 .. Argument_Count loop
5801 Scan_Make_Arg (Argument (Next_Arg), And_Save => True);
5802 end loop Scan_Args;
5804 if Usage_Requested then
5805 Usage;
5806 end if;
5808 -- Test for trailing -P switch
5810 if Project_File_Name_Present and then Project_File_Name = null then
5811 Make_Failed ("project file name missing after -P");
5813 -- Test for trailing -o switch
5815 elsif Output_File_Name_Present
5816 and then not Output_File_Name_Seen
5817 then
5818 Make_Failed ("output file name missing after -o");
5820 -- Test for trailing -D switch
5822 elsif Object_Directory_Present
5823 and then not Object_Directory_Seen then
5824 Make_Failed ("object directory missing after -D");
5825 end if;
5827 -- Test for simultaneity of -i and -D
5829 if Object_Directory_Path /= null and then In_Place_Mode then
5830 Make_Failed ("-i and -D cannot be used simutaneously");
5831 end if;
5833 -- Deal with -C= switch
5835 if Gnatmake_Mapping_File /= null then
5836 -- First, check compatibility with other switches
5838 if Project_File_Name /= null then
5839 Make_Failed ("-C= switch is not compatible with -P switch");
5841 elsif Saved_Maximum_Processes > 1 then
5842 Make_Failed ("-C= switch is not compatible with -jnnn switch");
5843 end if;
5845 Fmap.Initialize (Gnatmake_Mapping_File.all);
5846 Add_Switch
5847 ("-gnatem=" & Gnatmake_Mapping_File.all,
5848 Compiler,
5849 And_Save => True);
5850 end if;
5852 if Project_File_Name /= null then
5854 -- A project file was specified by a -P switch
5856 if Verbose_Mode then
5857 Write_Eol;
5858 Write_Str ("Parsing Project File """);
5859 Write_Str (Project_File_Name.all);
5860 Write_Str (""".");
5861 Write_Eol;
5862 end if;
5864 -- Avoid looking in the current directory for ALI files
5866 -- Look_In_Primary_Dir := False;
5868 -- Set the project parsing verbosity to whatever was specified
5869 -- by a possible -vP switch.
5871 Prj.Pars.Set_Verbosity (To => Current_Verbosity);
5873 -- Parse the project file.
5874 -- If there is an error, Main_Project will still be No_Project.
5876 Prj.Pars.Parse
5877 (Project => Main_Project,
5878 In_Tree => Project_Tree,
5879 Project_File_Name => Project_File_Name.all,
5880 Packages_To_Check => Packages_To_Check_By_Gnatmake);
5882 if Main_Project = No_Project then
5883 Make_Failed ("""", Project_File_Name.all, """ processing failed");
5884 end if;
5886 if Verbose_Mode then
5887 Write_Eol;
5888 Write_Str ("Parsing of Project File """);
5889 Write_Str (Project_File_Name.all);
5890 Write_Str (""" is finished.");
5891 Write_Eol;
5892 end if;
5894 -- We add the source directories and the object directories
5895 -- to the search paths.
5897 Add_Source_Directories (Main_Project, Project_Tree);
5898 Add_Object_Directories (Main_Project, Project_Tree);
5900 -- Compute depth of each project
5902 for Proj in Project_Table.First ..
5903 Project_Table.Last (Project_Tree.Projects)
5904 loop
5905 Project_Tree.Projects.Table (Proj).Seen := False;
5906 Project_Tree.Projects.Table (Proj).Depth := 0;
5907 end loop;
5909 Recursive_Compute_Depth
5910 (Main_Project, Depth => 1);
5912 else
5914 Osint.Add_Default_Search_Dirs;
5916 -- Source file lookups should be cached for efficiency.
5917 -- Source files are not supposed to change. However, we do that now
5918 -- only if no project file is used; if a project file is used, we
5919 -- do it just after changing the directory to the object directory.
5921 Osint.Source_File_Data (Cache => True);
5923 -- Read gnat.adc file to initialize Fname.UF
5925 Fname.UF.Initialize;
5927 begin
5928 Fname.SF.Read_Source_File_Name_Pragmas;
5930 exception
5931 when Err : SFN_Scan.Syntax_Error_In_GNAT_ADC =>
5932 Make_Failed (Exception_Message (Err));
5933 end;
5934 end if;
5936 -- Make sure no project object directory is recorded
5938 Project_Object_Directory := No_Project;
5940 end Initialize;
5942 ----------------------------
5943 -- Insert_Project_Sources --
5944 ----------------------------
5946 procedure Insert_Project_Sources
5947 (The_Project : Project_Id;
5948 All_Projects : Boolean;
5949 Into_Q : Boolean)
5951 Put_In_Q : Boolean := Into_Q;
5952 Unit : Unit_Data;
5953 Sfile : Name_Id;
5955 Extending : constant Boolean :=
5956 Project_Tree.Projects.Table
5957 (The_Project).Extends /= No_Project;
5959 function Check_Project (P : Project_Id) return Boolean;
5960 -- Returns True if P is The_Project or a project extended by
5961 -- The_Project.
5963 -------------------
5964 -- Check_Project --
5965 -------------------
5967 function Check_Project (P : Project_Id) return Boolean is
5968 begin
5969 if All_Projects or P = The_Project then
5970 return True;
5971 elsif Extending then
5972 declare
5973 Data : Project_Data :=
5974 Project_Tree.Projects.Table (The_Project);
5976 begin
5977 loop
5978 if P = Data.Extends then
5979 return True;
5980 end if;
5982 Data := Project_Tree.Projects.Table (Data.Extends);
5983 exit when Data.Extends = No_Project;
5984 end loop;
5985 end;
5986 end if;
5988 return False;
5989 end Check_Project;
5991 -- Start of processing for Insert_Project_Sources
5993 begin
5994 -- For all the sources in the project files,
5996 for Id in Unit_Table.First ..
5997 Unit_Table.Last (Project_Tree.Units)
5998 loop
5999 Unit := Project_Tree.Units.Table (Id);
6000 Sfile := No_Name;
6002 -- If there is a source for the body, and the body has not been
6003 -- locally removed,
6005 if Unit.File_Names (Body_Part).Name /= No_Name
6006 and then Unit.File_Names (Body_Part).Path /= Slash
6007 then
6008 -- And it is a source for the specified project
6010 if Check_Project (Unit.File_Names (Body_Part).Project) then
6012 -- If we don't have a spec, we cannot consider the source
6013 -- if it is a subunit
6015 if Unit.File_Names (Specification).Name = No_Name then
6016 declare
6017 Src_Ind : Source_File_Index;
6019 -- Here we are cheating a little bit: we don't want to
6020 -- use Sinput.L, because it depends on the GNAT tree
6021 -- (Atree, Sinfo, ...). So, we pretend that it is
6022 -- a project file, and we use Sinput.P.
6023 -- Source_File_Is_Subunit is just scanning through
6024 -- the file until it finds one of the reserved words
6025 -- separate, procedure, function, generic or package.
6026 -- Fortunately, these Ada reserved words are also
6027 -- reserved for project files.
6029 begin
6030 Src_Ind := Sinput.P.Load_Project_File
6031 (Get_Name_String
6032 (Unit.File_Names (Body_Part).Path));
6034 -- If it is a subunit, discard it
6036 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
6037 Sfile := No_Name;
6039 else
6040 Sfile := Unit.File_Names (Body_Part).Name;
6041 end if;
6042 end;
6044 else
6045 Sfile := Unit.File_Names (Body_Part).Name;
6046 end if;
6047 end if;
6049 elsif Unit.File_Names (Specification).Name /= No_Name
6050 and then Unit.File_Names (Specification).Path /= Slash
6051 and then Check_Project (Unit.File_Names (Specification).Project)
6052 then
6053 -- If there is no source for the body, but there is a source
6054 -- for the spec which has not been locally removed, then we take
6055 -- this one.
6057 Sfile := Unit.File_Names (Specification).Name;
6058 end if;
6060 -- If Put_In_Q is True, we insert into the Q
6062 if Put_In_Q then
6064 -- For the first source inserted into the Q, we need
6065 -- to initialize the Q, but not for the subsequent sources.
6067 if First_Q_Initialization then
6068 Init_Q;
6069 end if;
6071 -- And of course, we only insert in the Q if the source
6072 -- is not marked.
6074 if Sfile /= No_Name and then not Is_Marked (Sfile) then
6075 if Verbose_Mode then
6076 Write_Str ("Adding """);
6077 Write_Str (Get_Name_String (Sfile));
6078 Write_Line (""" to the queue");
6079 end if;
6081 Insert_Q (Sfile);
6082 Mark (Sfile);
6083 end if;
6085 elsif Sfile /= No_Name then
6087 -- If Put_In_Q is False, we add the source as it it were
6088 -- specified on the command line, and we set Put_In_Q to True,
6089 -- so that the following sources will be put directly in the
6090 -- queue. This will allow parallel compilation processes if -jx
6091 -- switch is used.
6093 if Verbose_Mode then
6094 Write_Str ("Adding """);
6095 Write_Str (Get_Name_String (Sfile));
6096 Write_Line (""" as if on the command line");
6097 end if;
6099 Osint.Add_File (Get_Name_String (Sfile));
6100 Put_In_Q := True;
6102 -- As we may look into the Q later, ensure the Q has been
6103 -- initialized to avoid errors.
6105 if First_Q_Initialization then
6106 Init_Q;
6107 end if;
6108 end if;
6109 end loop;
6110 end Insert_Project_Sources;
6112 --------------
6113 -- Insert_Q --
6114 --------------
6116 procedure Insert_Q
6117 (Source_File : File_Name_Type;
6118 Source_Unit : Unit_Name_Type := No_Name;
6119 Index : Int := 0)
6121 begin
6122 if Debug.Debug_Flag_Q then
6123 Write_Str (" Q := Q + [ ");
6124 Write_Name (Source_File);
6126 if Index /= 0 then
6127 Write_Str (", ");
6128 Write_Int (Index);
6129 end if;
6131 Write_Str (" ] ");
6132 Write_Eol;
6133 end if;
6135 Q.Table (Q.Last) :=
6136 (File => Source_File,
6137 Unit => Source_Unit,
6138 Index => Index);
6139 Q.Increment_Last;
6140 end Insert_Q;
6142 ---------------------
6143 -- Is_In_Obsoleted --
6144 ---------------------
6146 function Is_In_Obsoleted (F : Name_Id) return Boolean is
6147 begin
6148 if F = No_File then
6149 return False;
6151 else
6152 declare
6153 Name : constant String := Get_Name_String (F);
6154 First : Natural := Name'Last;
6155 F2 : Name_Id := F;
6157 begin
6158 while First > Name'First
6159 and then Name (First - 1) /= Directory_Separator
6160 and then Name (First - 1) /= '/'
6161 loop
6162 First := First - 1;
6163 end loop;
6165 if First /= Name'First then
6166 Name_Len := 0;
6167 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
6168 F2 := Name_Find;
6169 end if;
6171 return Obsoleted.Get (F2);
6172 end;
6173 end if;
6174 end Is_In_Obsoleted;
6176 ----------------------------
6177 -- Is_In_Object_Directory --
6178 ----------------------------
6180 function Is_In_Object_Directory
6181 (Source_File : File_Name_Type;
6182 Full_Lib_File : File_Name_Type) return Boolean
6184 begin
6185 -- There is something to check only when using project files.
6186 -- Otherwise, this function returns True (last line of the function).
6188 if Main_Project /= No_Project then
6189 declare
6190 Source_File_Name : constant String :=
6191 Get_Name_String (Source_File);
6192 Saved_Verbosity : constant Verbosity := Current_Verbosity;
6193 Project : Project_Id := No_Project;
6194 Path_Name : Name_Id := No_Name;
6195 Data : Project_Data;
6197 begin
6198 -- Call Get_Reference to know the ultimate extending project of
6199 -- the source. Call it with verbosity default to avoid verbose
6200 -- messages.
6202 Current_Verbosity := Default;
6203 Prj.Env.
6204 Get_Reference
6205 (Source_File_Name => Source_File_Name,
6206 Project => Project,
6207 In_Tree => Project_Tree,
6208 Path => Path_Name);
6209 Current_Verbosity := Saved_Verbosity;
6211 -- If this source is in a project, check that the ALI file is
6212 -- in its object directory. If it is not, return False, so that
6213 -- the ALI file will not be skipped.
6215 -- If the source is not in an extending project, we fall back to
6216 -- the general case and return True at the end of the function.
6218 if Project /= No_Project
6219 and then Project_Tree.Projects.Table
6220 (Project).Extends /= No_Project
6221 then
6222 Data := Project_Tree.Projects.Table (Project);
6224 declare
6225 Object_Directory : constant String :=
6226 Normalize_Pathname
6227 (Get_Name_String
6228 (Data.Object_Directory));
6230 Olast : Natural := Object_Directory'Last;
6232 Lib_File_Directory : constant String :=
6233 Normalize_Pathname (Dir_Name
6234 (Get_Name_String (Full_Lib_File)));
6236 Llast : Natural := Lib_File_Directory'Last;
6238 begin
6239 -- For directories, Normalize_Pathname may or may not put
6240 -- a directory separator at the end, depending on its input.
6241 -- Remove any last directory separator before comparaison.
6242 -- Returns True only if the two directories are the same.
6244 if Object_Directory (Olast) = Directory_Separator then
6245 Olast := Olast - 1;
6246 end if;
6248 if Lib_File_Directory (Llast) = Directory_Separator then
6249 Llast := Llast - 1;
6250 end if;
6252 return Object_Directory (Object_Directory'First .. Olast) =
6253 Lib_File_Directory (Lib_File_Directory'First .. Llast);
6254 end;
6255 end if;
6256 end;
6257 end if;
6259 -- When the source is not in a project file, always return True
6261 return True;
6262 end Is_In_Object_Directory;
6264 ----------
6265 -- Link --
6266 ----------
6268 procedure Link (ALI_File : File_Name_Type; Args : Argument_List) is
6269 Link_Args : Argument_List (1 .. Args'Length + 1);
6270 Success : Boolean;
6272 begin
6273 Get_Name_String (ALI_File);
6274 Link_Args (1) := new String'(Name_Buffer (1 .. Name_Len));
6276 Link_Args (2 .. Args'Length + 1) := Args;
6278 GNAT.OS_Lib.Normalize_Arguments (Link_Args);
6280 Display (Gnatlink.all, Link_Args);
6282 if Gnatlink_Path = null then
6283 Make_Failed ("error, unable to locate ", Gnatlink.all);
6284 end if;
6286 GNAT.OS_Lib.Spawn (Gnatlink_Path.all, Link_Args, Success);
6288 if not Success then
6289 raise Link_Failed;
6290 end if;
6291 end Link;
6293 ---------------------------
6294 -- List_Bad_Compilations --
6295 ---------------------------
6297 procedure List_Bad_Compilations is
6298 begin
6299 for J in Bad_Compilation.First .. Bad_Compilation.Last loop
6300 if Bad_Compilation.Table (J).File = No_File then
6301 null;
6302 elsif not Bad_Compilation.Table (J).Found then
6303 Inform (Bad_Compilation.Table (J).File, "not found");
6304 else
6305 Inform (Bad_Compilation.Table (J).File, "compilation error");
6306 end if;
6307 end loop;
6308 end List_Bad_Compilations;
6310 -----------------
6311 -- List_Depend --
6312 -----------------
6314 procedure List_Depend is
6315 Lib_Name : Name_Id;
6316 Obj_Name : Name_Id;
6317 Src_Name : Name_Id;
6319 Len : Natural;
6320 Line_Pos : Natural;
6321 Line_Size : constant := 77;
6323 begin
6324 Set_Standard_Output;
6326 for A in ALIs.First .. ALIs.Last loop
6327 Lib_Name := ALIs.Table (A).Afile;
6329 -- We have to provide the full library file name in In_Place_Mode
6331 if In_Place_Mode then
6332 Lib_Name := Full_Lib_File_Name (Lib_Name);
6333 end if;
6335 Obj_Name := Object_File_Name (Lib_Name);
6336 Write_Name (Obj_Name);
6337 Write_Str (" :");
6339 Get_Name_String (Obj_Name);
6340 Len := Name_Len;
6341 Line_Pos := Len + 2;
6343 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
6344 Src_Name := Sdep.Table (D).Sfile;
6346 if Is_Internal_File_Name (Src_Name)
6347 and then not Check_Readonly_Files
6348 then
6349 null;
6350 else
6351 if not Quiet_Output then
6352 Src_Name := Full_Source_Name (Src_Name);
6353 end if;
6355 Get_Name_String (Src_Name);
6356 Len := Name_Len;
6358 if Line_Pos + Len + 1 > Line_Size then
6359 Write_Str (" \");
6360 Write_Eol;
6361 Line_Pos := 0;
6362 end if;
6364 Line_Pos := Line_Pos + Len + 1;
6366 Write_Str (" ");
6367 Write_Name (Src_Name);
6368 end if;
6369 end loop;
6371 Write_Eol;
6372 end loop;
6374 Set_Standard_Error;
6375 end List_Depend;
6377 -----------------
6378 -- Make_Failed --
6379 -----------------
6381 procedure Make_Failed (S1 : String; S2 : String := ""; S3 : String := "") is
6382 begin
6383 Delete_All_Temp_Files;
6384 Osint.Fail (S1, S2, S3);
6385 end Make_Failed;
6387 --------------------
6388 -- Mark_Directory --
6389 --------------------
6391 procedure Mark_Directory
6392 (Dir : String;
6393 Mark : Lib_Mark_Type)
6395 N : Name_Id;
6396 B : Byte;
6398 begin
6399 -- Dir last character is supposed to be a directory separator
6401 Name_Len := Dir'Length;
6402 Name_Buffer (1 .. Name_Len) := Dir;
6404 if not Is_Directory_Separator (Name_Buffer (Name_Len)) then
6405 Name_Len := Name_Len + 1;
6406 Name_Buffer (Name_Len) := Directory_Separator;
6407 end if;
6409 -- Add flags to the already existing flags
6411 N := Name_Find;
6412 B := Get_Name_Table_Byte (N);
6413 Set_Name_Table_Byte (N, B or Mark);
6414 end Mark_Directory;
6416 -----------------------------
6417 -- Recursive_Compute_Depth --
6418 -----------------------------
6420 procedure Recursive_Compute_Depth
6421 (Project : Project_Id;
6422 Depth : Natural)
6424 List : Project_List;
6425 Proj : Project_Id;
6427 begin
6428 -- Nothing to do if there is no project or if the project has already
6429 -- been seen or if the depth is large enough.
6431 if Project = No_Project
6432 or else Project_Tree.Projects.Table (Project).Seen
6433 or else Project_Tree.Projects.Table (Project).Depth >= Depth
6434 then
6435 return;
6436 end if;
6438 Project_Tree.Projects.Table (Project).Depth := Depth;
6440 -- Mark the project as Seen to avoid endless loop caused by limited
6441 -- withs.
6443 Project_Tree.Projects.Table (Project).Seen := True;
6445 List := Project_Tree.Projects.Table (Project).Imported_Projects;
6447 -- Visit each imported project
6449 while List /= Empty_Project_List loop
6450 Proj := Project_Tree.Project_Lists.Table (List).Project;
6451 List := Project_Tree.Project_Lists.Table (List).Next;
6452 Recursive_Compute_Depth
6453 (Project => Proj,
6454 Depth => Depth + 1);
6455 end loop;
6457 -- Visit a project being extended, if any
6459 Recursive_Compute_Depth
6460 (Project => Project_Tree.Projects.Table (Project).Extends,
6461 Depth => Depth + 1);
6463 -- Reset the Seen flag, as we leave this project
6465 Project_Tree.Projects.Table (Project).Seen := False;
6466 end Recursive_Compute_Depth;
6468 -----------------------
6469 -- Sigint_Intercpted --
6470 -----------------------
6472 procedure Sigint_Intercepted is
6473 begin
6474 Write_Line ("*** Interrupted ***");
6475 Delete_All_Temp_Files;
6476 OS_Exit (1);
6477 end Sigint_Intercepted;
6479 -------------------
6480 -- Scan_Make_Arg --
6481 -------------------
6483 procedure Scan_Make_Arg (Argv : String; And_Save : Boolean) is
6484 begin
6485 pragma Assert (Argv'First = 1);
6487 if Argv'Length = 0 then
6488 return;
6489 end if;
6491 -- If the previous switch has set the Project_File_Name_Present
6492 -- flag (that is we have seen a -P alone), then the next argument is
6493 -- the name of the project file.
6495 if Project_File_Name_Present and then Project_File_Name = null then
6496 if Argv (1) = '-' then
6497 Make_Failed ("project file name missing after -P");
6499 else
6500 Project_File_Name_Present := False;
6501 Project_File_Name := new String'(Argv);
6502 end if;
6504 -- If the previous switch has set the Output_File_Name_Present
6505 -- flag (that is we have seen a -o), then the next argument is
6506 -- the name of the output executable.
6508 elsif Output_File_Name_Present
6509 and then not Output_File_Name_Seen
6510 then
6511 Output_File_Name_Seen := True;
6513 if Argv (1) = '-' then
6514 Make_Failed ("output file name missing after -o");
6516 else
6517 Add_Switch ("-o", Linker, And_Save => And_Save);
6519 -- Automatically add the executable suffix if it has not been
6520 -- specified explicitly.
6522 declare
6523 Canonical_Argv : String := Argv;
6524 begin
6525 -- Get the file name in canonical case to accept as is
6526 -- names ending with ".EXE" on VMS and Windows.
6528 Canonical_Case_File_Name (Canonical_Argv);
6530 if Executable_Suffix'Length /= 0
6531 and then (Canonical_Argv'Length <= Executable_Suffix'Length
6532 or else Canonical_Argv
6533 (Canonical_Argv'Last -
6534 Executable_Suffix'Length + 1
6535 .. Canonical_Argv'Last)
6536 /= Executable_Suffix)
6537 then
6538 Add_Switch
6539 (Argv & Executable_Suffix,
6540 Linker,
6541 And_Save => And_Save);
6542 else
6543 Add_Switch (Argv, Linker, And_Save => And_Save);
6544 end if;
6545 end;
6546 end if;
6548 -- If the previous switch has set the Object_Directory_Present flag
6549 -- (that is we have seen a -D), then the next argument is
6550 -- the path name of the object directory..
6552 elsif Object_Directory_Present
6553 and then not Object_Directory_Seen
6554 then
6555 Object_Directory_Seen := True;
6557 if Argv (1) = '-' then
6558 Make_Failed ("object directory path name missing after -D");
6560 elsif not Is_Directory (Argv) then
6561 Make_Failed ("cannot find object directory """, Argv, """");
6563 else
6564 Add_Lib_Search_Dir (Argv);
6566 -- Specify the object directory to the binder
6568 Add_Switch ("-aO" & Argv, Binder, And_Save => And_Save);
6570 -- Record the object directory. Make sure it ends with a directory
6571 -- separator.
6573 if Argv (Argv'Last) = Directory_Separator then
6574 Object_Directory_Path := new String'(Argv);
6576 else
6577 Object_Directory_Path :=
6578 new String'(Argv & Directory_Separator);
6579 end if;
6580 end if;
6582 -- Then check if we are dealing with -cargs/-bargs/-largs/-margs
6584 elsif Argv = "-bargs"
6585 or else
6586 Argv = "-cargs"
6587 or else
6588 Argv = "-largs"
6589 or else
6590 Argv = "-margs"
6591 then
6592 case Argv (2) is
6593 when 'c' => Program_Args := Compiler;
6594 when 'b' => Program_Args := Binder;
6595 when 'l' => Program_Args := Linker;
6596 when 'm' => Program_Args := None;
6598 when others =>
6599 raise Program_Error;
6600 end case;
6602 -- A special test is needed for the -o switch within a -largs
6603 -- since that is another way to specify the name of the final
6604 -- executable.
6606 elsif Program_Args = Linker
6607 and then Argv = "-o"
6608 then
6609 Make_Failed ("switch -o not allowed within a -largs. " &
6610 "Use -o directly.");
6612 -- Check to see if we are reading switches after a -cargs,
6613 -- -bargs or -largs switch. If yes save it.
6615 elsif Program_Args /= None then
6617 -- Check to see if we are reading -I switches in order
6618 -- to take into account in the src & lib search directories.
6620 if Argv'Length > 2 and then Argv (1 .. 2) = "-I" then
6621 if Argv (3 .. Argv'Last) = "-" then
6622 Look_In_Primary_Dir := False;
6624 elsif Program_Args = Compiler then
6625 if Argv (3 .. Argv'Last) /= "-" then
6626 Add_Src_Search_Dir (Argv (3 .. Argv'Last));
6627 end if;
6629 elsif Program_Args = Binder then
6630 Add_Lib_Search_Dir (Argv (3 .. Argv'Last));
6631 end if;
6632 end if;
6634 Add_Switch (Argv, Program_Args, And_Save => And_Save);
6636 -- Handle non-default compiler, binder, linker, and handle --RTS switch
6638 elsif Argv'Length > 2 and then Argv (1 .. 2) = "--" then
6639 if Argv'Length > 6
6640 and then Argv (1 .. 6) = "--GCC="
6641 then
6642 declare
6643 Program_Args : constant Argument_List_Access :=
6644 Argument_String_To_List
6645 (Argv (7 .. Argv'Last));
6647 begin
6648 if And_Save then
6649 Saved_Gcc := new String'(Program_Args.all (1).all);
6650 else
6651 Gcc := new String'(Program_Args.all (1).all);
6652 end if;
6654 for J in 2 .. Program_Args.all'Last loop
6655 Add_Switch
6656 (Program_Args.all (J).all,
6657 Compiler,
6658 And_Save => And_Save);
6659 end loop;
6660 end;
6662 elsif Argv'Length > 11
6663 and then Argv (1 .. 11) = "--GNATBIND="
6664 then
6665 declare
6666 Program_Args : constant Argument_List_Access :=
6667 Argument_String_To_List
6668 (Argv (12 .. Argv'Last));
6670 begin
6671 if And_Save then
6672 Saved_Gnatbind := new String'(Program_Args.all (1).all);
6673 else
6674 Gnatbind := new String'(Program_Args.all (1).all);
6675 end if;
6677 for J in 2 .. Program_Args.all'Last loop
6678 Add_Switch
6679 (Program_Args.all (J).all, Binder, And_Save => And_Save);
6680 end loop;
6681 end;
6683 elsif Argv'Length > 11
6684 and then Argv (1 .. 11) = "--GNATLINK="
6685 then
6686 declare
6687 Program_Args : constant Argument_List_Access :=
6688 Argument_String_To_List
6689 (Argv (12 .. Argv'Last));
6690 begin
6691 if And_Save then
6692 Saved_Gnatlink := new String'(Program_Args.all (1).all);
6693 else
6694 Gnatlink := new String'(Program_Args.all (1).all);
6695 end if;
6697 for J in 2 .. Program_Args.all'Last loop
6698 Add_Switch (Program_Args.all (J).all, Linker);
6699 end loop;
6700 end;
6702 elsif Argv'Length >= 5 and then
6703 Argv (1 .. 5) = "--RTS"
6704 then
6705 Add_Switch (Argv, Compiler, And_Save => And_Save);
6706 Add_Switch (Argv, Binder, And_Save => And_Save);
6708 if Argv'Length <= 6 or else Argv (6) /= '=' then
6709 Make_Failed ("missing path for --RTS");
6711 else
6712 -- Check that this is the first time we see this switch or
6713 -- if it is not the first time, the same path is specified.
6715 if RTS_Specified = null then
6716 RTS_Specified := new String'(Argv (7 .. Argv'Last));
6718 elsif RTS_Specified.all /= Argv (7 .. Argv'Last) then
6719 Make_Failed ("--RTS cannot be specified multiple times");
6720 end if;
6722 -- Valid --RTS switch
6724 No_Stdinc := True;
6725 No_Stdlib := True;
6726 RTS_Switch := True;
6728 declare
6729 Src_Path_Name : constant String_Ptr :=
6730 Get_RTS_Search_Dir
6731 (Argv (7 .. Argv'Last), Include);
6733 Lib_Path_Name : constant String_Ptr :=
6734 Get_RTS_Search_Dir
6735 (Argv (7 .. Argv'Last), Objects);
6737 begin
6738 if Src_Path_Name /= null and then
6739 Lib_Path_Name /= null
6740 then
6741 -- Set the RTS_*_Path_Name variables, so that the correct
6742 -- directories will be set when
6743 -- Osint.Add_Default_Search_Dirs will be called later.
6745 RTS_Src_Path_Name := Src_Path_Name;
6746 RTS_Lib_Path_Name := Lib_Path_Name;
6748 elsif Src_Path_Name = null
6749 and Lib_Path_Name = null then
6750 Make_Failed ("RTS path not valid: missing " &
6751 "adainclude and adalib directories");
6753 elsif Src_Path_Name = null then
6754 Make_Failed ("RTS path not valid: missing adainclude " &
6755 "directory");
6757 elsif Lib_Path_Name = null then
6758 Make_Failed ("RTS path not valid: missing adalib " &
6759 "directory");
6760 end if;
6761 end;
6762 end if;
6764 else
6765 Make_Failed ("unknown switch: ", Argv);
6766 end if;
6768 -- If we have seen a regular switch process it
6770 elsif Argv (1) = '-' then
6772 if Argv'Length = 1 then
6773 Make_Failed ("switch character cannot be followed by a blank");
6775 -- -I-
6777 elsif Argv (2 .. Argv'Last) = "I-" then
6778 Look_In_Primary_Dir := False;
6780 -- Forbid -?- or -??- where ? is any character
6782 elsif (Argv'Length = 3 and then Argv (3) = '-')
6783 or else (Argv'Length = 4 and then Argv (4) = '-')
6784 then
6785 Make_Failed ("trailing ""-"" at the end of ", Argv, " forbidden.");
6787 -- -Idir
6789 elsif Argv (2) = 'I' then
6790 Add_Src_Search_Dir (Argv (3 .. Argv'Last));
6791 Add_Lib_Search_Dir (Argv (3 .. Argv'Last));
6792 Add_Switch (Argv, Compiler, And_Save => And_Save);
6793 Add_Switch (Argv, Binder, And_Save => And_Save);
6795 -- -aIdir (to gcc this is like a -I switch)
6797 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aI" then
6798 Add_Src_Search_Dir (Argv (4 .. Argv'Last));
6799 Add_Switch ("-I" & Argv (4 .. Argv'Last),
6800 Compiler,
6801 And_Save => And_Save);
6802 Add_Switch (Argv, Binder, And_Save => And_Save);
6804 -- -aOdir
6806 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aO" then
6807 Add_Lib_Search_Dir (Argv (4 .. Argv'Last));
6808 Add_Switch (Argv, Binder, And_Save => And_Save);
6810 -- -aLdir (to gnatbind this is like a -aO switch)
6812 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aL" then
6813 Mark_Directory (Argv (4 .. Argv'Last), Ada_Lib_Dir);
6814 Add_Lib_Search_Dir (Argv (4 .. Argv'Last));
6815 Add_Switch ("-aO" & Argv (4 .. Argv'Last),
6816 Binder,
6817 And_Save => And_Save);
6819 -- -Adir (to gnatbind this is like a -aO switch, to gcc like a -I)
6821 elsif Argv (2) = 'A' then
6822 Mark_Directory (Argv (3 .. Argv'Last), Ada_Lib_Dir);
6823 Add_Src_Search_Dir (Argv (3 .. Argv'Last));
6824 Add_Lib_Search_Dir (Argv (3 .. Argv'Last));
6825 Add_Switch ("-I" & Argv (3 .. Argv'Last),
6826 Compiler,
6827 And_Save => And_Save);
6828 Add_Switch ("-aO" & Argv (3 .. Argv'Last),
6829 Binder,
6830 And_Save => And_Save);
6832 -- -Ldir
6834 elsif Argv (2) = 'L' then
6835 Add_Switch (Argv, Linker, And_Save => And_Save);
6837 -- For -gxxxxx, -pg, -mxxx, -fxxx: give the switch to both the
6838 -- compiler and the linker (except for -gnatxxx which is only for
6839 -- the compiler). Some of the -mxxx (for example -m64) and -fxxx
6840 -- (for example -ftest-coverage for gcov) need to be used when
6841 -- compiling the binder generated files, and using all these gcc
6842 -- switches for the binder generated files should not be a problem.
6844 elsif
6845 (Argv (2) = 'g' and then (Argv'Last < 5
6846 or else Argv (2 .. 5) /= "gnat"))
6847 or else Argv (2 .. Argv'Last) = "pg"
6848 or else (Argv (2) = 'm' and then Argv'Last > 2)
6849 or else (Argv (2) = 'f' and then Argv'Last > 2)
6850 then
6851 Add_Switch (Argv, Compiler, And_Save => And_Save);
6852 Add_Switch (Argv, Linker, And_Save => And_Save);
6854 -- -C=<mapping file>
6856 elsif Argv'Last > 2 and then Argv (2) = 'C' then
6857 if And_Save then
6858 if Argv (3) /= '=' or else Argv'Last <= 3 then
6859 Make_Failed ("illegal switch ", Argv);
6860 end if;
6862 Gnatmake_Mapping_File := new String'(Argv (4 .. Argv'Last));
6863 end if;
6865 -- -D
6867 elsif Argv'Last = 2 and then Argv (2) = 'D' then
6868 if Project_File_Name /= null then
6869 Make_Failed ("-D cannot be used in conjunction with a " &
6870 "project file");
6872 else
6873 Scan_Make_Switches (Argv);
6874 end if;
6876 -- -d
6878 elsif Argv (2) = 'd'
6879 and then Argv'Last = 2
6880 then
6881 Display_Compilation_Progress := True;
6883 -- -i
6885 elsif Argv'Last = 2 and then Argv (2) = 'i' then
6886 if Project_File_Name /= null then
6887 Make_Failed ("-i cannot be used in conjunction with a " &
6888 "project file");
6890 else
6891 Scan_Make_Switches (Argv);
6892 end if;
6894 -- -j (need to save the result)
6896 elsif Argv (2) = 'j' then
6897 Scan_Make_Switches (Argv);
6899 if And_Save then
6900 Saved_Maximum_Processes := Maximum_Processes;
6901 end if;
6903 -- -m
6905 elsif Argv (2) = 'm'
6906 and then Argv'Last = 2
6907 then
6908 Minimal_Recompilation := True;
6910 -- -u
6912 elsif Argv (2) = 'u'
6913 and then Argv'Last = 2
6914 then
6915 Unique_Compile := True;
6916 Compile_Only := True;
6917 Do_Bind_Step := False;
6918 Do_Link_Step := False;
6920 -- -U
6922 elsif Argv (2) = 'U'
6923 and then Argv'Last = 2
6924 then
6925 Unique_Compile_All_Projects := True;
6926 Unique_Compile := True;
6927 Compile_Only := True;
6928 Do_Bind_Step := False;
6929 Do_Link_Step := False;
6931 -- -Pprj or -P prj (only once, and only on the command line)
6933 elsif Argv (2) = 'P' then
6934 if Project_File_Name /= null then
6935 Make_Failed ("cannot have several project files specified");
6937 elsif Object_Directory_Path /= null then
6938 Make_Failed ("-D cannot be used in conjunction with a " &
6939 "project file");
6941 elsif In_Place_Mode then
6942 Make_Failed ("-i cannot be used in conjunction with a " &
6943 "project file");
6945 elsif not And_Save then
6947 -- It could be a tool other than gnatmake (i.e, gnatdist)
6948 -- or a -P switch inside a project file.
6950 Fail
6951 ("either the tool is not ""project-aware"" or " &
6952 "a project file is specified inside a project file");
6954 elsif Argv'Last = 2 then
6956 -- -P is used alone: the project file name is the next option
6958 Project_File_Name_Present := True;
6960 else
6961 Project_File_Name := new String'(Argv (3 .. Argv'Last));
6962 end if;
6964 -- -vPx (verbosity of the parsing of the project files)
6966 elsif Argv'Last = 4
6967 and then Argv (2 .. 3) = "vP"
6968 and then Argv (4) in '0' .. '2'
6969 then
6970 if And_Save then
6971 case Argv (4) is
6972 when '0' =>
6973 Current_Verbosity := Prj.Default;
6974 when '1' =>
6975 Current_Verbosity := Prj.Medium;
6976 when '2' =>
6977 Current_Verbosity := Prj.High;
6978 when others =>
6979 null;
6980 end case;
6981 end if;
6983 -- -Xext=val (External assignment)
6985 elsif Argv (2) = 'X'
6986 and then Is_External_Assignment (Argv)
6987 then
6988 -- Is_External_Assignment has side effects
6989 -- when it returns True;
6991 null;
6993 -- If -gnath is present, then generate the usage information
6994 -- right now and do not pass this option on to the compiler calls.
6996 elsif Argv = "-gnath" then
6997 Usage;
6999 -- If -gnatc is specified, make sure the bind step and the link
7000 -- step are not executed.
7002 elsif Argv'Length >= 6 and then Argv (2 .. 6) = "gnatc" then
7004 -- If -gnatc is specified, make sure the bind step and the link
7005 -- step are not executed.
7007 Add_Switch (Argv, Compiler, And_Save => And_Save);
7008 Operating_Mode := Check_Semantics;
7009 Check_Object_Consistency := False;
7010 Compile_Only := True;
7011 Do_Bind_Step := False;
7012 Do_Link_Step := False;
7014 elsif Argv (2 .. Argv'Last) = "nostdlib" then
7016 -- Don't pass -nostdlib to gnatlink, it will disable
7017 -- linking with all standard library files.
7019 No_Stdlib := True;
7021 Add_Switch (Argv, Compiler, And_Save => And_Save);
7022 Add_Switch (Argv, Binder, And_Save => And_Save);
7024 elsif Argv (2 .. Argv'Last) = "nostdinc" then
7026 -- Pass -nostdinc to the Compiler and to gnatbind
7028 No_Stdinc := True;
7029 Add_Switch (Argv, Compiler, And_Save => And_Save);
7030 Add_Switch (Argv, Binder, And_Save => And_Save);
7032 -- By default all switches with more than one character
7033 -- or one character switches which are not in 'a' .. 'z'
7034 -- (except 'C', 'F', 'M' and 'B') are passed to the compiler,
7035 -- unless we are dealing with a debug switch (starts with 'd')
7036 -- or an extended gnatmake switch (starts with 'e').
7038 elsif Argv (2) /= 'd'
7039 and then Argv (2) /= 'e'
7040 and then Argv (2 .. Argv'Last) /= "C"
7041 and then Argv (2 .. Argv'Last) /= "F"
7042 and then Argv (2 .. Argv'Last) /= "M"
7043 and then Argv (2 .. Argv'Last) /= "B"
7044 and then (Argv'Length > 2 or else Argv (2) not in 'a' .. 'z')
7045 then
7046 Add_Switch (Argv, Compiler, And_Save => And_Save);
7048 -- All other options are handled by Scan_Make_Switches
7050 else
7051 Scan_Make_Switches (Argv);
7052 end if;
7054 -- If not a switch it must be a file name
7056 else
7057 Add_File (Argv);
7058 Mains.Add_Main (Argv);
7059 end if;
7060 end Scan_Make_Arg;
7062 -----------------
7063 -- Switches_Of --
7064 -----------------
7066 function Switches_Of
7067 (Source_File : Name_Id;
7068 Source_File_Name : String;
7069 Source_Index : Int;
7070 Naming : Naming_Data;
7071 In_Package : Package_Id;
7072 Allow_ALI : Boolean) return Variable_Value
7074 Switches : Variable_Value;
7076 Defaults : constant Array_Element_Id :=
7077 Prj.Util.Value_Of
7078 (Name => Name_Default_Switches,
7079 In_Arrays =>
7080 Project_Tree.Packages.Table
7081 (In_Package).Decl.Arrays,
7082 In_Tree => Project_Tree);
7084 Switches_Array : constant Array_Element_Id :=
7085 Prj.Util.Value_Of
7086 (Name => Name_Switches,
7087 In_Arrays =>
7088 Project_Tree.Packages.Table
7089 (In_Package).Decl.Arrays,
7090 In_Tree => Project_Tree);
7092 begin
7093 Switches :=
7094 Prj.Util.Value_Of
7095 (Index => Source_File,
7096 Src_Index => Source_Index,
7097 In_Array => Switches_Array,
7098 In_Tree => Project_Tree);
7100 if Switches = Nil_Variable_Value then
7101 declare
7102 Name : String (1 .. Source_File_Name'Length + 3);
7103 Last : Positive := Source_File_Name'Length;
7104 Spec_Suffix : constant String :=
7105 Get_Name_String (Naming.Ada_Spec_Suffix);
7106 Body_Suffix : constant String :=
7107 Get_Name_String (Naming.Ada_Body_Suffix);
7108 Truncated : Boolean := False;
7110 begin
7111 Name (1 .. Last) := Source_File_Name;
7113 if Last > Body_Suffix'Length
7114 and then Name (Last - Body_Suffix'Length + 1 .. Last) =
7115 Body_Suffix
7116 then
7117 Truncated := True;
7118 Last := Last - Body_Suffix'Length;
7119 end if;
7121 if not Truncated
7122 and then Last > Spec_Suffix'Length
7123 and then Name (Last - Spec_Suffix'Length + 1 .. Last) =
7124 Spec_Suffix
7125 then
7126 Truncated := True;
7127 Last := Last - Spec_Suffix'Length;
7128 end if;
7130 if Truncated then
7131 Name_Len := Last;
7132 Name_Buffer (1 .. Name_Len) := Name (1 .. Last);
7133 Switches :=
7134 Prj.Util.Value_Of
7135 (Index => Name_Find,
7136 Src_Index => 0,
7137 In_Array => Switches_Array,
7138 In_Tree => Project_Tree);
7140 if Switches = Nil_Variable_Value
7141 and then Allow_ALI
7142 then
7143 Last := Source_File_Name'Length;
7145 while Name (Last) /= '.' loop
7146 Last := Last - 1;
7147 end loop;
7149 Name (Last + 1 .. Last + 3) := "ali";
7150 Name_Len := Last + 3;
7151 Name_Buffer (1 .. Name_Len) := Name (1 .. Name_Len);
7152 Switches :=
7153 Prj.Util.Value_Of
7154 (Index => Name_Find,
7155 Src_Index => 0,
7156 In_Array => Switches_Array,
7157 In_Tree => Project_Tree);
7158 end if;
7159 end if;
7160 end;
7161 end if;
7163 if Switches = Nil_Variable_Value then
7164 Switches :=
7165 Prj.Util.Value_Of
7166 (Index => Name_Ada,
7167 Src_Index => 0,
7168 In_Array => Defaults,
7169 In_Tree => Project_Tree);
7170 end if;
7172 return Switches;
7173 end Switches_Of;
7175 -----------
7176 -- Usage --
7177 -----------
7179 procedure Usage is
7180 begin
7181 if Usage_Needed then
7182 Usage_Needed := False;
7183 Makeusg;
7184 end if;
7185 end Usage;
7187 -----------------
7188 -- Verbose_Msg --
7189 -----------------
7191 procedure Verbose_Msg
7192 (N1 : Name_Id;
7193 S1 : String;
7194 N2 : Name_Id := No_Name;
7195 S2 : String := "";
7196 Prefix : String := " -> ")
7198 begin
7199 if not Verbose_Mode then
7200 return;
7201 end if;
7203 Write_Str (Prefix);
7204 Write_Str ("""");
7205 Write_Name (N1);
7206 Write_Str (""" ");
7207 Write_Str (S1);
7209 if N2 /= No_Name then
7210 Write_Str (" """);
7211 Write_Name (N2);
7212 Write_Str (""" ");
7213 end if;
7215 Write_Str (S2);
7216 Write_Eol;
7217 end Verbose_Msg;
7219 begin
7220 -- Make sure that in case of failure, the temp files will be deleted
7222 Prj.Com.Fail := Make_Failed'Access;
7223 MLib.Fail := Make_Failed'Access;
7224 Makeutl.Do_Fail := Make_Failed'Access;
7225 end Make;