Merge from the pain train
[official-gcc.git] / gcc / ada / make.adb
blobe799e05d8da28065a3d0c5aafde995d475347d1f
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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, 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 Main_Project : Prj.Project_Id := No_Project;
279 -- The project id of the main project file, if any
281 Project_Object_Directory : Project_Id := No_Project;
282 -- The object directory of the project for the last compilation.
283 -- Avoid calling Change_Dir if the current working directory is already
284 -- this directory
286 -- Packages of project files where unknown attributes are errors
288 Naming_String : aliased String := "naming";
289 Builder_String : aliased String := "builder";
290 Compiler_String : aliased String := "compiler";
291 Binder_String : aliased String := "binder";
292 Linker_String : aliased String := "linker";
294 Gnatmake_Packages : aliased String_List :=
295 (Naming_String 'Access,
296 Builder_String 'Access,
297 Compiler_String 'Access,
298 Binder_String 'Access,
299 Linker_String 'Access);
301 Packages_To_Check_By_Gnatmake : constant String_List_Access :=
302 Gnatmake_Packages'Access;
304 procedure Add_Source_Dir (N : String);
305 -- Call Add_Src_Search_Dir.
306 -- Output one line when in verbose mode.
308 procedure Add_Source_Directories is
309 new Prj.Env.For_All_Source_Dirs (Action => Add_Source_Dir);
311 procedure Add_Object_Dir (N : String);
312 -- Call Add_Lib_Search_Dir.
313 -- Output one line when in verbose mode.
315 procedure Add_Object_Directories is
316 new Prj.Env.For_All_Object_Dirs (Action => Add_Object_Dir);
318 procedure Change_To_Object_Directory (Project : Project_Id);
319 -- Change to the object directory of project Project, if this is not
320 -- already the current working directory.
322 type Bad_Compilation_Info is record
323 File : File_Name_Type;
324 Unit : Unit_Name_Type;
325 Found : Boolean;
326 end record;
327 -- File is the name of the file for which a compilation failed.
328 -- Unit is for gnatdist use in order to easily get the unit name
329 -- of a file when its name is krunched or declared in gnat.adc.
330 -- Found is False if the compilation failed because the file could
331 -- not be found.
333 package Bad_Compilation is new Table.Table (
334 Table_Component_Type => Bad_Compilation_Info,
335 Table_Index_Type => Natural,
336 Table_Low_Bound => 1,
337 Table_Initial => 20,
338 Table_Increment => 100,
339 Table_Name => "Make.Bad_Compilation");
340 -- Full name of all the source files for which compilation fails
342 Do_Compile_Step : Boolean := True;
343 Do_Bind_Step : Boolean := True;
344 Do_Link_Step : Boolean := True;
345 -- Flags to indicate what step should be executed.
346 -- Can be set to False with the switches -c, -b and -l.
347 -- These flags are reset to True for each invokation of procedure Gnatmake.
349 Shared_String : aliased String := "-shared";
350 Force_Elab_Flags_String : aliased String := "-F";
352 No_Shared_Switch : aliased Argument_List := (1 .. 0 => null);
353 Shared_Switch : aliased Argument_List := (1 => Shared_String'Access);
354 Bind_Shared : Argument_List_Access := No_Shared_Switch'Access;
355 -- Switch to added in front of gnatbind switches. By default no switch is
356 -- added. Switch "-shared" is added if there is a non-static Library
357 -- Project File.
359 Shared_Libgcc : aliased String := "-shared-libgcc";
361 No_Shared_Libgcc_Switch : aliased Argument_List := (1 .. 0 => null);
362 Shared_Libgcc_Switch : aliased Argument_List :=
363 (1 => Shared_Libgcc'Access);
364 Link_With_Shared_Libgcc : Argument_List_Access :=
365 No_Shared_Libgcc_Switch'Access;
367 procedure Make_Failed (S1 : String; S2 : String := ""; S3 : String := "");
368 -- Delete all temp files created by Gnatmake and call Osint.Fail,
369 -- with the parameter S1, S2 and S3 (see osint.ads).
370 -- This is called from the Prj hierarchy and the MLib hierarchy.
372 --------------------------
373 -- Obsolete Executables --
374 --------------------------
376 Executable_Obsolete : Boolean := False;
377 -- Executable_Obsolete is initially set to False for each executable,
378 -- and is set to True whenever one of the source of the executable is
379 -- compiled, or has already been compiled for another executable.
381 Max_Header : constant := 200;
382 -- This needs a proper comment, it used to say "arbitrary"
383 -- that's not an adequate comment ???
385 type Header_Num is range 1 .. Max_Header;
386 -- Header_Num for the hash table Obsoleted below
388 function Hash (F : Name_Id) return Header_Num;
389 -- Hash function for the hash table Obsoleted below
391 package Obsoleted is new System.HTable.Simple_HTable
392 (Header_Num => Header_Num,
393 Element => Boolean,
394 No_Element => False,
395 Key => Name_Id,
396 Hash => Hash,
397 Equal => "=");
398 -- A hash table to keep all files that have been compiled, to detect
399 -- if an executable is up to date or not.
401 procedure Enter_Into_Obsoleted (F : Name_Id);
402 -- Enter a file name, without directory information, into the has table
403 -- Obsoleted.
405 function Is_In_Obsoleted (F : Name_Id) return Boolean;
406 -- Check if a file name, without directory information, has already been
407 -- entered into the hash table Obsoleted.
409 type Dependency is record
410 This : Name_Id;
411 Depends_On : Name_Id;
412 end record;
413 -- Components of table Dependencies below
415 package Dependencies is new Table.Table (
416 Table_Component_Type => Dependency,
417 Table_Index_Type => Integer,
418 Table_Low_Bound => 1,
419 Table_Initial => 20,
420 Table_Increment => 100,
421 Table_Name => "Make.Dependencies");
422 -- A table to keep dependencies, to be able to decide if an executable
423 -- is obsolete.
425 procedure Add_Dependency (S : Name_Id; On : Name_Id);
426 -- Add one entry in table Dependencies
428 ----------------------------
429 -- Arguments and Switches --
430 ----------------------------
432 Arguments : Argument_List_Access;
433 -- Used to gather the arguments for invocation of the compiler
435 Last_Argument : Natural := 0;
436 -- Last index of arguments in Arguments above
438 Arguments_Collected : Boolean := False;
439 -- Set to True when the arguments for the next invocation of the compiler
440 -- have been collected.
442 Arguments_Project : Project_Id;
443 -- Project id, if any, of the source to be compiled
445 Arguments_Path_Name : File_Name_Type;
446 -- Full path of the source to be compiled, when Arguments_Project is not
447 -- No_Project.
449 Dummy_Switch : constant String_Access := new String'("- ");
450 -- Used to initialized Prev_Switch in procedure Check
452 procedure Add_Arguments (Args : Argument_List);
453 -- Add arguments to global variable Arguments, increasing its size
454 -- if necessary and adjusting Last_Argument.
456 function Configuration_Pragmas_Switch
457 (For_Project : Project_Id) return Argument_List;
458 -- Return an argument list of one element, if there is a configuration
459 -- pragmas file to be specified for For_Project,
460 -- otherwise return an empty argument list.
462 -------------------
463 -- Misc Routines --
464 -------------------
466 procedure List_Depend;
467 -- Prints to standard output the list of object dependencies. This list
468 -- can be used directly in a Makefile. A call to Compile_Sources must
469 -- precede the call to List_Depend. Also because this routine uses the
470 -- ALI files that were originally loaded and scanned by Compile_Sources,
471 -- no additional ALI files should be scanned between the two calls (i.e.
472 -- between the call to Compile_Sources and List_Depend.)
474 procedure Inform (N : Name_Id := No_Name; Msg : String);
475 -- Prints out the program name followed by a colon, N and S
477 procedure List_Bad_Compilations;
478 -- Prints out the list of all files for which the compilation failed
480 procedure Verbose_Msg
481 (N1 : Name_Id;
482 S1 : String;
483 N2 : Name_Id := No_Name;
484 S2 : String := "";
485 Prefix : String := " -> ");
486 -- If the verbose flag (Verbose_Mode) is set then print Prefix to standard
487 -- output followed by N1 and S1. If N2 /= No_Name then N2 is printed after
488 -- S1. S2 is printed last. Both N1 and N2 are printed in quotation marks.
490 Usage_Needed : Boolean := True;
491 -- Flag used to make sure Makeusg is call at most once
493 procedure Usage;
494 -- Call Makeusg, if Usage_Needed is True.
495 -- Set Usage_Needed to False.
497 procedure Debug_Msg (S : String; N : Name_Id);
498 -- If Debug.Debug_Flag_W is set outputs string S followed by name N
500 procedure Recursive_Compute_Depth
501 (Project : Project_Id;
502 Depth : Natural);
503 -- Compute depth of Project and of the projects it depends on
505 -----------------------
506 -- Gnatmake Routines --
507 -----------------------
509 Gnatmake_Called : Boolean := False;
510 -- Set to True when procedure Gnatmake is called.
511 -- Attempt to delete temporary files is made only when Gnatmake_Called
512 -- is True.
514 subtype Lib_Mark_Type is Byte;
515 -- Used in Mark_Directory
517 Ada_Lib_Dir : constant Lib_Mark_Type := 1;
518 -- Used to mark a directory as a GNAT lib dir
520 -- Note that the notion of GNAT lib dir is no longer used. The code
521 -- related to it has not been removed to give an idea on how to use
522 -- the directory prefix marking mechanism.
524 -- An Ada library directory is a directory containing ali and object
525 -- files but no source files for the bodies (the specs can be in the
526 -- same or some other directory). These directories are specified
527 -- in the Gnatmake command line with the switch "-Adir" (to specify the
528 -- spec location -Idir cab be used). Gnatmake skips the missing sources
529 -- whose ali are in Ada library directories. For an explanation of why
530 -- Gnatmake behaves that way, see the spec of Make.Compile_Sources.
531 -- The directory lookup penalty is incurred every single time this
532 -- routine is called.
534 procedure Check_Steps;
535 -- Check what steps (Compile, Bind, Link) must be executed.
536 -- Set the step flags accordingly.
538 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean;
539 -- Get directory prefix of this file and get lib mark stored in name
540 -- table for this directory. Then check if an Ada lib mark has been set.
542 procedure Mark_Directory
543 (Dir : String;
544 Mark : Lib_Mark_Type);
545 -- Store Dir in name table and set lib mark as name info to identify
546 -- Ada libraries.
548 Output_Is_Object : Boolean := True;
549 -- Set to False when using a switch -S for the compiler
551 procedure Check_For_S_Switch;
552 -- Set Output_Is_Object to False when the -S switch is used for the
553 -- compiler.
555 function Switches_Of
556 (Source_File : Name_Id;
557 Source_File_Name : String;
558 Source_Index : Int;
559 Naming : Naming_Data;
560 In_Package : Package_Id;
561 Allow_ALI : Boolean) return Variable_Value;
562 -- Return the switches for the source file in the specified package
563 -- of a project file. If the Source_File ends with a standard GNAT
564 -- extension (".ads" or ".adb"), try first the full name, then the
565 -- name without the extension, then, if Allow_ALI is True, the name with
566 -- the extension ".ali". If there is no switches for either names, try the
567 -- default switches for Ada. If all failed, return No_Variable_Value.
569 function Is_In_Object_Directory
570 (Source_File : File_Name_Type;
571 Full_Lib_File : File_Name_Type) return Boolean;
572 -- Check if, when using a project file, the ALI file is in the project
573 -- directory of the ultimate extending project. If it is not, we ignore
574 -- the fact that this ALI file is read-only.
576 ----------------------------------------------------
577 -- Compiler, Binder & Linker Data and Subprograms --
578 ----------------------------------------------------
580 Gcc : String_Access := Program_Name ("gcc");
581 Gnatbind : String_Access := Program_Name ("gnatbind");
582 Gnatlink : String_Access := Program_Name ("gnatlink");
583 -- Default compiler, binder, linker programs
585 Saved_Gcc : String_Access := null;
586 Saved_Gnatbind : String_Access := null;
587 Saved_Gnatlink : String_Access := null;
588 -- Given by the command line. Will be used, if non null
590 Gcc_Path : String_Access :=
591 GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
592 Gnatbind_Path : String_Access :=
593 GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
594 Gnatlink_Path : String_Access :=
595 GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
596 -- Path for compiler, binder, linker programs, defaulted now for gnatdist.
597 -- Changed later if overridden on command line.
599 Comp_Flag : constant String_Access := new String'("-c");
600 Output_Flag : constant String_Access := new String'("-o");
601 Ada_Flag_1 : constant String_Access := new String'("-x");
602 Ada_Flag_2 : constant String_Access := new String'("ada");
603 No_gnat_adc : constant String_Access := new String'("-gnatA");
604 GNAT_Flag : constant String_Access := new String'("-gnatpg");
605 Do_Not_Check_Flag : constant String_Access := new String'("-x");
607 Object_Suffix : constant String := Get_Object_Suffix.all;
608 Executable_Suffix : constant String := Get_Executable_Suffix.all;
610 Syntax_Only : Boolean := False;
611 -- Set to True when compiling with -gnats
613 Display_Executed_Programs : Boolean := True;
614 -- Set to True if name of commands should be output on stderr
616 Output_File_Name_Seen : Boolean := False;
617 -- Set to True after having scanned the file_name for
618 -- switch "-o file_name"
620 Object_Directory_Seen : Boolean := False;
621 -- Set to True after having scanned the object directory for
622 -- switch "-D obj_dir".
624 Object_Directory_Path : String_Access := null;
625 -- The path name of the object directory, set with switch -D
627 type Make_Program_Type is (None, Compiler, Binder, Linker);
629 Program_Args : Make_Program_Type := None;
630 -- Used to indicate if we are scanning gnatmake, gcc, gnatbind, or gnatbind
631 -- options within the gnatmake command line. Used in Scan_Make_Arg only,
632 -- but must be global since value preserved from one call to another.
634 Temporary_Config_File : Boolean := False;
635 -- Set to True when there is a temporary config file used for a project
636 -- file, to avoid displaying the -gnatec switch for a temporary file.
638 procedure Add_Switches
639 (The_Package : Package_Id;
640 File_Name : String;
641 Index : Int;
642 Program : Make_Program_Type);
643 procedure Add_Switch
644 (S : String_Access;
645 Program : Make_Program_Type;
646 Append_Switch : Boolean := True;
647 And_Save : Boolean := True);
648 procedure Add_Switch
649 (S : String;
650 Program : Make_Program_Type;
651 Append_Switch : Boolean := True;
652 And_Save : Boolean := True);
653 -- Make invokes one of three programs (the compiler, the binder or the
654 -- linker). For the sake of convenience, some program specific switches
655 -- can be passed directly on the gnatmake commande line. This procedure
656 -- records these switches so that gnamake can pass them to the right
657 -- program. S is the switch to be added at the end of the command line
658 -- for Program if Append_Switch is True. If Append_Switch is False S is
659 -- added at the beginning of the command line.
661 procedure Check
662 (Source_File : File_Name_Type;
663 Source_Index : Int;
664 The_Args : Argument_List;
665 Lib_File : File_Name_Type;
666 Read_Only : Boolean;
667 ALI : out ALI_Id;
668 O_File : out File_Name_Type;
669 O_Stamp : out Time_Stamp_Type);
670 -- Determines whether the library file Lib_File is up-to-date or not. The
671 -- full name (with path information) of the object file corresponding to
672 -- Lib_File is returned in O_File. Its time stamp is saved in O_Stamp.
673 -- ALI is the ALI_Id corresponding to Lib_File. If Lib_File in not
674 -- up-to-date, then the corresponding source file needs to be recompiled.
675 -- In this case ALI = No_ALI_Id.
677 procedure Check_Linker_Options
678 (E_Stamp : Time_Stamp_Type;
679 O_File : out File_Name_Type;
680 O_Stamp : out Time_Stamp_Type);
681 -- Checks all linker options for linker files that are newer
682 -- than E_Stamp. If such objects are found, the youngest object
683 -- is returned in O_File and its stamp in O_Stamp.
685 -- If no obsolete linker files were found, the first missing
686 -- linker file is returned in O_File and O_Stamp is empty.
687 -- Otherwise O_File is No_File.
689 procedure Collect_Arguments
690 (Source_File : File_Name_Type;
691 Source_Index : Int;
692 Args : Argument_List);
693 -- Collect all arguments for a source to be compiled, including those
694 -- that come from a project file.
696 procedure Display (Program : String; Args : Argument_List);
697 -- Displays Program followed by the arguments in Args if variable
698 -- Display_Executed_Programs is set. The lower bound of Args must be 1.
700 -----------------
701 -- Mapping files
702 -----------------
704 type Temp_File_Names is
705 array (Project_Id range <>, Positive range <>) of Name_Id;
707 type Temp_Files_Ptr is access Temp_File_Names;
709 type Indices is array (Project_Id range <>) of Natural;
711 type Indices_Ptr is access Indices;
713 type Free_File_Indices is array
714 (Project_Id range <>, Positive range <>) of Positive;
716 type Free_Indices_Ptr is access Free_File_Indices;
718 The_Mapping_File_Names : Temp_Files_Ptr;
719 -- For each project, the name ids of the temporary mapping files used
721 Last_Mapping_File_Names : Indices_Ptr;
722 -- For each project, the index of the last mapping file created
724 The_Free_Mapping_File_Indices : Free_Indices_Ptr;
725 -- For each project, the indices in The_Mapping_File_Names of the mapping
726 -- file names that can be reused for subsequent compilations.
728 Last_Free_Indices : Indices_Ptr;
729 -- For each project, the number of mapping files that can be reused
731 Gnatmake_Mapping_File : String_Access := null;
732 -- The path name of a mapping file specified by switch -C=
734 procedure Delete_Mapping_Files;
735 -- Delete all temporary mapping files
737 procedure Init_Mapping_File
738 (Project : Project_Id;
739 File_Index : in out Natural);
740 -- Create a new temporary mapping file, and fill it with the project file
741 -- mappings, when using project file(s). The out parameter File_Index is
742 -- the index to the name of the file in the array The_Mapping_File_Names.
744 procedure Delete_Temp_Config_Files;
745 -- Delete all temporary config files
747 procedure Delete_All_Temp_Files;
748 -- Delete all temp files (config files, mapping files, path files)
750 -------------------
751 -- Add_Arguments --
752 -------------------
754 procedure Add_Arguments (Args : Argument_List) is
755 begin
756 if Arguments = null then
757 Arguments := new Argument_List (1 .. Args'Length + 10);
759 else
760 while Last_Argument + Args'Length > Arguments'Last loop
761 declare
762 New_Arguments : constant Argument_List_Access :=
763 new Argument_List (1 .. Arguments'Last * 2);
764 begin
765 New_Arguments (1 .. Last_Argument) :=
766 Arguments (1 .. Last_Argument);
767 Arguments := New_Arguments;
768 end;
769 end loop;
770 end if;
772 Arguments (Last_Argument + 1 .. Last_Argument + Args'Length) := Args;
773 Last_Argument := Last_Argument + Args'Length;
774 end Add_Arguments;
776 --------------------
777 -- Add_Dependency --
778 --------------------
780 procedure Add_Dependency (S : Name_Id; On : Name_Id) is
781 begin
782 Dependencies.Increment_Last;
783 Dependencies.Table (Dependencies.Last) := (S, On);
784 end Add_Dependency;
786 --------------------
787 -- Add_Object_Dir --
788 --------------------
790 procedure Add_Object_Dir (N : String) is
791 begin
792 Add_Lib_Search_Dir (N);
794 if Verbose_Mode then
795 Write_Str ("Adding object directory """);
796 Write_Str (N);
797 Write_Str (""".");
798 Write_Eol;
799 end if;
800 end Add_Object_Dir;
802 --------------------
803 -- Add_Source_Dir --
804 --------------------
806 procedure Add_Source_Dir (N : String) is
807 begin
808 Add_Src_Search_Dir (N);
810 if Verbose_Mode then
811 Write_Str ("Adding source directory """);
812 Write_Str (N);
813 Write_Str (""".");
814 Write_Eol;
815 end if;
816 end Add_Source_Dir;
818 ----------------
819 -- Add_Switch --
820 ----------------
822 procedure Add_Switch
823 (S : String_Access;
824 Program : Make_Program_Type;
825 Append_Switch : Boolean := True;
826 And_Save : Boolean := True)
828 generic
829 with package T is new Table.Table (<>);
830 procedure Generic_Position (New_Position : out Integer);
831 -- Generic procedure that chooses a position for S in T at the
832 -- beginning or the end, depending on the boolean Append_Switch.
833 -- Calling this procedure may expand the table.
835 ----------------------
836 -- Generic_Position --
837 ----------------------
839 procedure Generic_Position (New_Position : out Integer) is
840 begin
841 T.Increment_Last;
843 if Append_Switch then
844 New_Position := Integer (T.Last);
845 else
846 for J in reverse T.Table_Index_Type'Succ (T.First) .. T.Last loop
847 T.Table (J) := T.Table (T.Table_Index_Type'Pred (J));
848 end loop;
850 New_Position := Integer (T.First);
851 end if;
852 end Generic_Position;
854 procedure Gcc_Switches_Pos is new Generic_Position (Gcc_Switches);
855 procedure Binder_Switches_Pos is new Generic_Position (Binder_Switches);
856 procedure Linker_Switches_Pos is new Generic_Position (Linker_Switches);
858 procedure Saved_Gcc_Switches_Pos is new
859 Generic_Position (Saved_Gcc_Switches);
861 procedure Saved_Binder_Switches_Pos is new
862 Generic_Position (Saved_Binder_Switches);
864 procedure Saved_Linker_Switches_Pos is new
865 Generic_Position (Saved_Linker_Switches);
867 New_Position : Integer;
869 -- Start of processing for Add_Switch
871 begin
872 if And_Save then
873 case Program is
874 when Compiler =>
875 Saved_Gcc_Switches_Pos (New_Position);
876 Saved_Gcc_Switches.Table (New_Position) := S;
878 when Binder =>
879 Saved_Binder_Switches_Pos (New_Position);
880 Saved_Binder_Switches.Table (New_Position) := S;
882 when Linker =>
883 Saved_Linker_Switches_Pos (New_Position);
884 Saved_Linker_Switches.Table (New_Position) := S;
886 when None =>
887 raise Program_Error;
888 end case;
890 else
891 case Program is
892 when Compiler =>
893 Gcc_Switches_Pos (New_Position);
894 Gcc_Switches.Table (New_Position) := S;
896 when Binder =>
897 Binder_Switches_Pos (New_Position);
898 Binder_Switches.Table (New_Position) := S;
900 when Linker =>
901 Linker_Switches_Pos (New_Position);
902 Linker_Switches.Table (New_Position) := S;
904 when None =>
905 raise Program_Error;
906 end case;
907 end if;
908 end Add_Switch;
910 procedure Add_Switch
911 (S : String;
912 Program : Make_Program_Type;
913 Append_Switch : Boolean := True;
914 And_Save : Boolean := True)
916 begin
917 Add_Switch (S => new String'(S),
918 Program => Program,
919 Append_Switch => Append_Switch,
920 And_Save => And_Save);
921 end Add_Switch;
923 ------------------
924 -- Add_Switches --
925 ------------------
927 procedure Add_Switches
928 (The_Package : Package_Id;
929 File_Name : String;
930 Index : Int;
931 Program : Make_Program_Type)
933 Switches : Variable_Value;
934 Switch_List : String_List_Id;
935 Element : String_Element;
937 begin
938 if File_Name'Length > 0 then
939 Name_Len := File_Name'Length;
940 Name_Buffer (1 .. Name_Len) := File_Name;
941 Switches :=
942 Switches_Of
943 (Source_File => Name_Find,
944 Source_File_Name => File_Name,
945 Source_Index => Index,
946 Naming => Projects.Table (Main_Project).Naming,
947 In_Package => The_Package,
948 Allow_ALI =>
949 Program = Binder or else Program = Linker);
951 case Switches.Kind is
952 when Undefined =>
953 null;
955 when List =>
956 Program_Args := Program;
958 Switch_List := Switches.Values;
960 while Switch_List /= Nil_String loop
961 Element := String_Elements.Table (Switch_List);
962 Get_Name_String (Element.Value);
964 if Name_Len > 0 then
965 declare
966 Argv : constant String := Name_Buffer (1 .. Name_Len);
967 -- We need a copy, because Name_Buffer may be
968 -- modified.
970 begin
971 if Verbose_Mode then
972 Write_Str (" Adding ");
973 Write_Line (Argv);
974 end if;
976 Scan_Make_Arg (Argv, And_Save => False);
977 end;
978 end if;
980 Switch_List := Element.Next;
981 end loop;
983 when Single =>
984 Program_Args := Program;
985 Get_Name_String (Switches.Value);
987 if Name_Len > 0 then
988 declare
989 Argv : constant String := Name_Buffer (1 .. Name_Len);
990 -- We need a copy, because Name_Buffer may be modified
992 begin
993 if Verbose_Mode then
994 Write_Str (" Adding ");
995 Write_Line (Argv);
996 end if;
998 Scan_Make_Arg (Argv, And_Save => False);
999 end;
1000 end if;
1001 end case;
1002 end if;
1003 end Add_Switches;
1005 ----------
1006 -- Bind --
1007 ----------
1009 procedure Bind (ALI_File : File_Name_Type; Args : Argument_List) is
1010 Bind_Args : Argument_List (1 .. Args'Last + 2);
1011 Bind_Last : Integer;
1012 Success : Boolean;
1014 begin
1015 pragma Assert (Args'First = 1);
1017 -- Optimize the simple case where the gnatbind command line looks like
1018 -- gnatbind -aO. -I- file.ali --into-> gnatbind file.adb
1020 if Args'Length = 2
1021 and then Args (Args'First).all = "-aO" & Normalized_CWD
1022 and then Args (Args'Last).all = "-I-"
1023 and then ALI_File = Strip_Directory (ALI_File)
1024 then
1025 Bind_Last := Args'First - 1;
1027 else
1028 Bind_Last := Args'Last;
1029 Bind_Args (Args'Range) := Args;
1030 end if;
1032 -- It is completely pointless to re-check source file time stamps.
1033 -- This has been done already by gnatmake
1035 Bind_Last := Bind_Last + 1;
1036 Bind_Args (Bind_Last) := Do_Not_Check_Flag;
1038 Get_Name_String (ALI_File);
1040 Bind_Last := Bind_Last + 1;
1041 Bind_Args (Bind_Last) := new String'(Name_Buffer (1 .. Name_Len));
1043 GNAT.OS_Lib.Normalize_Arguments (Bind_Args (Args'First .. Bind_Last));
1045 Display (Gnatbind.all, Bind_Args (Args'First .. Bind_Last));
1047 if Gnatbind_Path = null then
1048 Make_Failed ("error, unable to locate ", Gnatbind.all);
1049 end if;
1051 GNAT.OS_Lib.Spawn
1052 (Gnatbind_Path.all, Bind_Args (Args'First .. Bind_Last), Success);
1054 if not Success then
1055 raise Bind_Failed;
1056 end if;
1057 end Bind;
1059 --------------------------------
1060 -- Change_To_Object_Directory --
1061 --------------------------------
1063 procedure Change_To_Object_Directory (Project : Project_Id) is
1064 begin
1065 -- Nothing to do if the current working directory is alresdy the one
1066 -- we want.
1068 if Project_Object_Directory /= Project then
1069 Project_Object_Directory := Project;
1071 -- If in a real project, set the working directory to the object
1072 -- directory of the project.
1074 if Project /= No_Project then
1075 Change_Dir
1076 (Get_Name_String (Projects.Table (Project).Object_Directory));
1078 -- Otherwise, for sources outside of any project, set the working
1079 -- directory to the object directory of the main project.
1081 elsif Main_Project /= No_Project then
1082 Change_Dir
1083 (Get_Name_String
1084 (Projects.Table (Main_Project).Object_Directory));
1085 end if;
1086 end if;
1087 end Change_To_Object_Directory;
1089 -----------
1090 -- Check --
1091 -----------
1093 procedure Check
1094 (Source_File : File_Name_Type;
1095 Source_Index : Int;
1096 The_Args : Argument_List;
1097 Lib_File : File_Name_Type;
1098 Read_Only : Boolean;
1099 ALI : out ALI_Id;
1100 O_File : out File_Name_Type;
1101 O_Stamp : out Time_Stamp_Type)
1103 function First_New_Spec (A : ALI_Id) return File_Name_Type;
1104 -- Looks in the with table entries of A and returns the spec file name
1105 -- of the first withed unit (subprogram) for which no spec existed when
1106 -- A was generated but for which there exists one now, implying that A
1107 -- is now obsolete. If no such unit is found No_File is returned.
1108 -- Otherwise the spec file name of the unit is returned.
1110 -- **WARNING** in the event of Uname format modifications, one *MUST*
1111 -- make sure this function is also updated.
1113 -- Note: This function should really be in ali.adb and use Uname
1114 -- services, but this causes the whole compiler to be dragged along
1115 -- for gnatbind and gnatmake.
1117 --------------------
1118 -- First_New_Spec --
1119 --------------------
1121 function First_New_Spec (A : ALI_Id) return File_Name_Type is
1122 Spec_File_Name : File_Name_Type := No_File;
1124 function New_Spec (Uname : Unit_Name_Type) return Boolean;
1125 -- Uname is the name of the spec or body of some ada unit.
1126 -- This function returns True if the Uname is the name of a body
1127 -- which has a spec not mentioned inali file A. If True is returned
1128 -- Spec_File_Name above is set to the name of this spec file.
1130 --------------
1131 -- New_Spec --
1132 --------------
1134 function New_Spec (Uname : Unit_Name_Type) return Boolean is
1135 Spec_Name : Unit_Name_Type;
1136 File_Name : File_Name_Type;
1138 begin
1139 -- Test whether Uname is the name of a body unit (ie ends with %b)
1141 Get_Name_String (Uname);
1142 pragma
1143 Assert (Name_Len > 2 and then Name_Buffer (Name_Len - 1) = '%');
1145 if Name_Buffer (Name_Len) /= 'b' then
1146 return False;
1147 end if;
1149 -- Convert unit name into spec name
1151 -- ??? this code seems dubious in presence of pragma
1152 -- Source_File_Name since there is no more direct relationship
1153 -- between unit name and file name.
1155 -- ??? Further, what about alternative subunit naming
1157 Name_Buffer (Name_Len) := 's';
1158 Spec_Name := Name_Find;
1159 File_Name := Get_File_Name (Spec_Name, Subunit => False);
1161 -- Look if File_Name is mentioned in A's sdep list.
1162 -- If not look if the file exists. If it does return True.
1164 for D in
1165 ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep
1166 loop
1167 if Sdep.Table (D).Sfile = File_Name then
1168 return False;
1169 end if;
1170 end loop;
1172 if Full_Source_Name (File_Name) /= No_File then
1173 Spec_File_Name := File_Name;
1174 return True;
1175 end if;
1177 return False;
1178 end New_Spec;
1180 -- Start of processing for First_New_Spec
1182 begin
1183 U_Chk : for U in
1184 ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit
1185 loop
1186 exit U_Chk when Units.Table (U).Utype = Is_Body_Only
1187 and then New_Spec (Units.Table (U).Uname);
1189 for W in Units.Table (U).First_With
1191 Units.Table (U).Last_With
1192 loop
1193 exit U_Chk when
1194 Withs.Table (W).Afile /= No_File
1195 and then New_Spec (Withs.Table (W).Uname);
1196 end loop;
1197 end loop U_Chk;
1199 return Spec_File_Name;
1200 end First_New_Spec;
1202 ---------------------------------
1203 -- Data declarations for Check --
1204 ---------------------------------
1206 Full_Lib_File : File_Name_Type;
1207 -- Full name of current library file
1209 Full_Obj_File : File_Name_Type;
1210 -- Full name of the object file corresponding to Lib_File
1212 Lib_Stamp : Time_Stamp_Type;
1213 -- Time stamp of the current ada library file
1215 Obj_Stamp : Time_Stamp_Type;
1216 -- Time stamp of the current object file
1218 Modified_Source : File_Name_Type;
1219 -- The first source in Lib_File whose current time stamp differs
1220 -- from that stored in Lib_File.
1222 New_Spec : File_Name_Type;
1223 -- If Lib_File contains in its W (with) section a body (for a
1224 -- subprogram) for which there exists a spec and the spec did not
1225 -- appear in the Sdep section of Lib_File, New_Spec contains the file
1226 -- name of this new spec.
1228 Source_Name : Name_Id;
1229 Text : Text_Buffer_Ptr;
1231 Prev_Switch : String_Access;
1232 -- Previous switch processed
1234 Arg : Arg_Id := Arg_Id'First;
1235 -- Current index in Args.Table for a given unit (init to stop warning)
1237 Switch_Found : Boolean;
1238 -- True if a given switch has been found
1240 -- Start of processing for Check
1242 begin
1243 pragma Assert (Lib_File /= No_File);
1245 -- If the ALI file is read-only, set temporarily
1246 -- Check_Object_Consistency to False: we don't care if the object file
1247 -- is not there; presumably, a library will be used for linking.
1249 if Read_Only then
1250 declare
1251 Saved_Check_Object_Consistency : constant Boolean :=
1252 Check_Object_Consistency;
1253 begin
1254 Check_Object_Consistency := False;
1255 Text := Read_Library_Info (Lib_File);
1256 Check_Object_Consistency := Saved_Check_Object_Consistency;
1257 end;
1259 else
1260 Text := Read_Library_Info (Lib_File);
1261 end if;
1263 Full_Lib_File := Full_Library_Info_Name;
1264 Full_Obj_File := Full_Object_File_Name;
1265 Lib_Stamp := Current_Library_File_Stamp;
1266 Obj_Stamp := Current_Object_File_Stamp;
1268 if Full_Lib_File = No_File then
1269 Verbose_Msg (Lib_File, "being checked ...", Prefix => " ");
1270 else
1271 Verbose_Msg (Full_Lib_File, "being checked ...", Prefix => " ");
1272 end if;
1274 ALI := No_ALI_Id;
1275 O_File := Full_Obj_File;
1276 O_Stamp := Obj_Stamp;
1278 if Text = null then
1279 if Full_Lib_File = No_File then
1280 Verbose_Msg (Lib_File, "missing.");
1282 elsif Obj_Stamp (Obj_Stamp'First) = ' ' then
1283 Verbose_Msg (Full_Obj_File, "missing.");
1285 else
1286 Verbose_Msg
1287 (Full_Lib_File, "(" & String (Lib_Stamp) & ") newer than",
1288 Full_Obj_File, "(" & String (Obj_Stamp) & ")");
1289 end if;
1291 else
1292 ALI := Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
1293 Free (Text);
1295 if ALI = No_ALI_Id then
1296 Verbose_Msg (Full_Lib_File, "incorrectly formatted ALI file");
1297 return;
1299 elsif ALIs.Table (ALI).Ver (1 .. ALIs.Table (ALI).Ver_Len) /=
1300 Verbose_Library_Version
1301 then
1302 Verbose_Msg (Full_Lib_File, "compiled with old GNAT version");
1303 ALI := No_ALI_Id;
1304 return;
1305 end if;
1307 -- Don't take Ali file into account if it was generated with
1308 -- errors.
1310 if ALIs.Table (ALI).Compile_Errors then
1311 Verbose_Msg (Full_Lib_File, "had errors, must be recompiled");
1312 ALI := No_ALI_Id;
1313 return;
1314 end if;
1316 -- Don't take Ali file into account if it was generated without
1317 -- object.
1319 if Operating_Mode /= Check_Semantics
1320 and then ALIs.Table (ALI).No_Object
1321 then
1322 Verbose_Msg (Full_Lib_File, "has no corresponding object");
1323 ALI := No_ALI_Id;
1324 return;
1325 end if;
1327 -- Check for matching compiler switches if needed
1329 if Check_Switches then
1331 -- First, collect all the switches
1333 Collect_Arguments (Source_File, Source_Index, The_Args);
1335 Prev_Switch := Dummy_Switch;
1337 Get_Name_String (ALIs.Table (ALI).Sfile);
1339 Switches_To_Check.Set_Last (0);
1341 for J in 1 .. Last_Argument loop
1343 -- Skip non switches -c, -I and -o switches
1345 if Arguments (J) (1) = '-'
1346 and then Arguments (J) (2) /= 'c'
1347 and then Arguments (J) (2) /= 'o'
1348 and then Arguments (J) (2) /= 'I'
1349 then
1350 Normalize_Compiler_Switches
1351 (Arguments (J).all,
1352 Normalized_Switches,
1353 Last_Norm_Switch);
1355 for K in 1 .. Last_Norm_Switch loop
1356 Switches_To_Check.Increment_Last;
1357 Switches_To_Check.Table (Switches_To_Check.Last) :=
1358 Normalized_Switches (K);
1359 end loop;
1360 end if;
1361 end loop;
1363 for J in 1 .. Switches_To_Check.Last loop
1365 -- Comparing switches is delicate because gcc reorders
1366 -- a number of switches, according to lang-specs.h, but
1367 -- gnatmake doesn't have the sufficient knowledge to
1368 -- perform the same reordering. Instead, we ignore orders
1369 -- between different "first letter" switches, but keep
1370 -- orders between same switches, e.g -O -O2 is different
1371 -- than -O2 -O, but -g -O is equivalent to -O -g.
1373 if Switches_To_Check.Table (J) (2) /= Prev_Switch (2) or else
1374 (Prev_Switch'Length >= 6 and then
1375 Prev_Switch (2 .. 5) = "gnat" and then
1376 Switches_To_Check.Table (J)'Length >= 6 and then
1377 Switches_To_Check.Table (J) (2 .. 5) = "gnat" and then
1378 Prev_Switch (6) /= Switches_To_Check.Table (J) (6))
1379 then
1380 Prev_Switch := Switches_To_Check.Table (J);
1381 Arg :=
1382 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg;
1383 end if;
1385 Switch_Found := False;
1387 for K in Arg ..
1388 Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1389 loop
1391 Switches_To_Check.Table (J).all = Args.Table (K).all
1392 then
1393 Arg := K + 1;
1394 Switch_Found := True;
1395 exit;
1396 end if;
1397 end loop;
1399 if not Switch_Found then
1400 if Verbose_Mode then
1401 Verbose_Msg (ALIs.Table (ALI).Sfile,
1402 "switch mismatch """ &
1403 Switches_To_Check.Table (J).all & '"');
1404 end if;
1406 ALI := No_ALI_Id;
1407 return;
1408 end if;
1409 end loop;
1411 if Switches_To_Check.Last /=
1412 Integer (Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg -
1413 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg + 1)
1414 then
1415 if Verbose_Mode then
1416 Verbose_Msg (ALIs.Table (ALI).Sfile,
1417 "different number of switches");
1419 for K in Units.Table (ALIs.Table (ALI).First_Unit).First_Arg
1420 .. Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1421 loop
1422 Write_Str (Args.Table (K).all);
1423 Write_Char (' ');
1424 end loop;
1426 Write_Eol;
1428 for J in 1 .. Switches_To_Check.Last loop
1429 Write_Str (Switches_To_Check.Table (J).all);
1430 Write_Char (' ');
1431 end loop;
1433 Write_Eol;
1434 end if;
1436 ALI := No_ALI_Id;
1437 return;
1438 end if;
1439 end if;
1441 -- Get the source files and their message digests. Note that some
1442 -- sources may be missing if ALI is out-of-date.
1444 Set_Source_Table (ALI);
1446 Modified_Source := Time_Stamp_Mismatch (ALI, Read_Only);
1448 if Modified_Source /= No_File then
1449 ALI := No_ALI_Id;
1451 if Verbose_Mode then
1452 Source_Name := Full_Source_Name (Modified_Source);
1454 if Source_Name /= No_File then
1455 Verbose_Msg (Source_Name, "time stamp mismatch");
1456 else
1457 Verbose_Msg (Modified_Source, "missing");
1458 end if;
1459 end if;
1461 else
1462 New_Spec := First_New_Spec (ALI);
1464 if New_Spec /= No_File then
1465 ALI := No_ALI_Id;
1467 if Verbose_Mode then
1468 Source_Name := Full_Source_Name (New_Spec);
1470 if Source_Name /= No_File then
1471 Verbose_Msg (Source_Name, "new spec");
1472 else
1473 Verbose_Msg (New_Spec, "old spec missing");
1474 end if;
1475 end if;
1476 end if;
1477 end if;
1478 end if;
1479 end Check;
1481 ------------------------
1482 -- Check_For_S_Switch --
1483 ------------------------
1485 procedure Check_For_S_Switch is
1486 begin
1487 -- By default, we generate an object file
1489 Output_Is_Object := True;
1491 for Arg in 1 .. Last_Argument loop
1492 if Arguments (Arg).all = "-S" then
1493 Output_Is_Object := False;
1495 elsif Arguments (Arg).all = "-c" then
1496 Output_Is_Object := True;
1497 end if;
1498 end loop;
1499 end Check_For_S_Switch;
1501 --------------------------
1502 -- Check_Linker_Options --
1503 --------------------------
1505 procedure Check_Linker_Options
1506 (E_Stamp : Time_Stamp_Type;
1507 O_File : out File_Name_Type;
1508 O_Stamp : out Time_Stamp_Type)
1510 procedure Check_File (File : File_Name_Type);
1511 -- Update O_File and O_Stamp if the given file is younger than E_Stamp
1512 -- and O_Stamp, or if O_File is No_File and File does not exist.
1514 function Get_Library_File (Name : String) return File_Name_Type;
1515 -- Return the full file name including path of a library based
1516 -- on the name specified with the -l linker option, using the
1517 -- Ada object path. Return No_File if no such file can be found.
1519 type Char_Array is array (Natural) of Character;
1520 type Char_Array_Access is access constant Char_Array;
1522 Template : Char_Array_Access;
1523 pragma Import (C, Template, "__gnat_library_template");
1525 ----------------
1526 -- Check_File --
1527 ----------------
1529 procedure Check_File (File : File_Name_Type) is
1530 Stamp : Time_Stamp_Type;
1531 Name : File_Name_Type := File;
1533 begin
1534 Get_Name_String (Name);
1536 -- Remove any trailing NUL characters
1538 while Name_Len >= Name_Buffer'First
1539 and then Name_Buffer (Name_Len) = NUL
1540 loop
1541 Name_Len := Name_Len - 1;
1542 end loop;
1544 if Name_Len <= 0 then
1545 return;
1547 elsif Name_Buffer (1) = '-' then
1549 -- Do not check if File is a switch other than "-l"
1551 if Name_Buffer (2) /= 'l' then
1552 return;
1553 end if;
1555 -- The argument is a library switch, get actual name. It
1556 -- is necessary to make a copy of the relevant part of
1557 -- Name_Buffer as Get_Library_Name uses Name_Buffer as well.
1559 declare
1560 Base_Name : constant String := Name_Buffer (3 .. Name_Len);
1562 begin
1563 Name := Get_Library_File (Base_Name);
1564 end;
1566 if Name = No_File then
1567 return;
1568 end if;
1569 end if;
1571 Stamp := File_Stamp (Name);
1573 -- Find the youngest object file that is younger than the
1574 -- executable. If no such file exist, record the first object
1575 -- file that is not found.
1577 if (O_Stamp < Stamp and then E_Stamp < Stamp)
1578 or else (O_File = No_File and then Stamp (Stamp'First) = ' ')
1579 then
1580 O_Stamp := Stamp;
1581 O_File := Name;
1583 -- Strip the trailing NUL if present
1585 Get_Name_String (O_File);
1587 if Name_Buffer (Name_Len) = NUL then
1588 Name_Len := Name_Len - 1;
1589 O_File := Name_Find;
1590 end if;
1591 end if;
1592 end Check_File;
1594 ----------------------
1595 -- Get_Library_Name --
1596 ----------------------
1598 -- See comments in a-adaint.c about template syntax
1600 function Get_Library_File (Name : String) return File_Name_Type is
1601 File : File_Name_Type := No_File;
1603 begin
1604 Name_Len := 0;
1606 for Ptr in Template'Range loop
1607 case Template (Ptr) is
1608 when '*' =>
1609 Add_Str_To_Name_Buffer (Name);
1611 when ';' =>
1612 File := Full_Lib_File_Name (Name_Find);
1613 exit when File /= No_File;
1614 Name_Len := 0;
1616 when NUL =>
1617 exit;
1619 when others =>
1620 Add_Char_To_Name_Buffer (Template (Ptr));
1621 end case;
1622 end loop;
1624 -- The for loop exited because the end of the template
1625 -- was reached. File contains the last possible file name
1626 -- for the library.
1628 if File = No_File and then Name_Len > 0 then
1629 File := Full_Lib_File_Name (Name_Find);
1630 end if;
1632 return File;
1633 end Get_Library_File;
1635 -- Start of processing for Check_Linker_Options
1637 begin
1638 O_File := No_File;
1639 O_Stamp := (others => ' ');
1641 -- Process linker options from the ALI files
1643 for Opt in 1 .. Linker_Options.Last loop
1644 Check_File (Linker_Options.Table (Opt).Name);
1645 end loop;
1647 -- Process options given on the command line
1649 for Opt in Linker_Switches.First .. Linker_Switches.Last loop
1651 -- Check if the previous Opt has one of the two switches
1652 -- that take an extra parameter. (See GCC manual.)
1654 if Opt = Linker_Switches.First
1655 or else (Linker_Switches.Table (Opt - 1).all /= "-u"
1656 and then
1657 Linker_Switches.Table (Opt - 1).all /= "-Xlinker"
1658 and then
1659 Linker_Switches.Table (Opt - 1).all /= "-L")
1660 then
1661 Name_Len := 0;
1662 Add_Str_To_Name_Buffer (Linker_Switches.Table (Opt).all);
1663 Check_File (Name_Find);
1664 end if;
1665 end loop;
1667 end Check_Linker_Options;
1669 -----------------
1670 -- Check_Steps --
1671 -----------------
1673 procedure Check_Steps is
1674 begin
1675 -- If either -c, -b or -l has been specified, we will not necessarily
1676 -- execute all steps.
1678 if Make_Steps then
1679 Do_Compile_Step := Do_Compile_Step and Compile_Only;
1680 Do_Bind_Step := Do_Bind_Step and Bind_Only;
1681 Do_Link_Step := Do_Link_Step and Link_Only;
1683 -- If -c has been specified, but not -b, ignore any potential -l
1685 if Do_Compile_Step and then not Do_Bind_Step then
1686 Do_Link_Step := False;
1687 end if;
1688 end if;
1689 end Check_Steps;
1691 -----------------------
1692 -- Collect_Arguments --
1693 -----------------------
1695 procedure Collect_Arguments
1696 (Source_File : File_Name_Type;
1697 Source_Index : Int;
1698 Args : Argument_List)
1700 begin
1701 Arguments_Collected := True;
1702 Arguments_Project := No_Project;
1703 Last_Argument := 0;
1704 Add_Arguments (Args);
1706 if Main_Project /= No_Project then
1707 declare
1708 Source_File_Name : constant String :=
1709 Get_Name_String (Source_File);
1710 Compiler_Package : Prj.Package_Id;
1711 Switches : Prj.Variable_Value;
1712 Data : Project_Data;
1714 begin
1715 Prj.Env.
1716 Get_Reference
1717 (Source_File_Name => Source_File_Name,
1718 Project => Arguments_Project,
1719 Path => Arguments_Path_Name);
1721 -- If the source is not a source of a project file, check if
1722 -- this is allowed.
1724 if Arguments_Project = No_Project then
1725 if not External_Unit_Compilation_Allowed then
1726 Make_Failed ("external source (", Source_File_Name,
1727 ") is not part of any project; cannot be " &
1728 "compiled without gnatmake switch -x");
1729 end if;
1731 -- If it is allowed, simply add the saved gcc switches
1733 Add_Arguments (The_Saved_Gcc_Switches.all);
1735 else
1736 -- We get the project directory for the relative path
1737 -- switches and arguments.
1739 Data := Projects.Table (Arguments_Project);
1741 -- If the source is in an extended project, we go to
1742 -- the ultimate extending project.
1744 while Data.Extended_By /= No_Project loop
1745 Arguments_Project := Data.Extended_By;
1746 Data := Projects.Table (Arguments_Project);
1747 end loop;
1749 -- If building a dynamic or relocatable library, compile with
1750 -- PIC option, if it exists.
1752 if Data.Library and then Data.Library_Kind /= Static then
1753 declare
1754 PIC : constant String := MLib.Tgt.PIC_Option;
1756 begin
1757 if PIC /= "" then
1758 Add_Arguments ((1 => new String'(PIC)));
1759 end if;
1760 end;
1761 end if;
1763 if Data.Dir_Path = null then
1764 Data.Dir_Path :=
1765 new String'(Get_Name_String (Data.Display_Directory));
1766 Projects.Table (Arguments_Project) := Data;
1767 end if;
1769 -- We now look for package Compiler
1770 -- and get the switches from this package.
1772 Compiler_Package :=
1773 Prj.Util.Value_Of
1774 (Name => Name_Compiler,
1775 In_Packages => Data.Decl.Packages);
1777 if Compiler_Package /= No_Package then
1779 -- If package Gnatmake.Compiler exists, we get
1780 -- the specific switches for the current source,
1781 -- or the global switches, if any.
1783 Switches := Switches_Of
1784 (Source_File => Source_File,
1785 Source_File_Name => Source_File_Name,
1786 Source_Index => Source_Index,
1787 Naming => Data.Naming,
1788 In_Package => Compiler_Package,
1789 Allow_ALI => False);
1791 end if;
1793 case Switches.Kind is
1795 -- We have a list of switches. We add these switches,
1796 -- plus the saved gcc switches.
1798 when List =>
1800 declare
1801 Current : String_List_Id := Switches.Values;
1802 Element : String_Element;
1803 Number : Natural := 0;
1805 begin
1806 while Current /= Nil_String loop
1807 Element := String_Elements.Table (Current);
1808 Number := Number + 1;
1809 Current := Element.Next;
1810 end loop;
1812 declare
1813 New_Args : Argument_List (1 .. Number);
1815 begin
1816 Current := Switches.Values;
1818 for Index in New_Args'Range loop
1819 Element := String_Elements.Table (Current);
1820 Get_Name_String (Element.Value);
1821 New_Args (Index) :=
1822 new String'(Name_Buffer (1 .. Name_Len));
1823 Test_If_Relative_Path
1824 (New_Args (Index), Parent => Data.Dir_Path);
1825 Current := Element.Next;
1826 end loop;
1828 Add_Arguments
1829 (Configuration_Pragmas_Switch
1830 (Arguments_Project) &
1831 New_Args & The_Saved_Gcc_Switches.all);
1832 end;
1833 end;
1835 -- We have a single switch. We add this switch,
1836 -- plus the saved gcc switches.
1838 when Single =>
1839 Get_Name_String (Switches.Value);
1841 declare
1842 New_Args : Argument_List :=
1843 (1 => new String'
1844 (Name_Buffer (1 .. Name_Len)));
1846 begin
1847 Test_If_Relative_Path
1848 (New_Args (1), Parent => Data.Dir_Path);
1849 Add_Arguments
1850 (Configuration_Pragmas_Switch (Arguments_Project) &
1851 New_Args & The_Saved_Gcc_Switches.all);
1852 end;
1854 -- We have no switches from Gnatmake.Compiler.
1855 -- We add the saved gcc switches.
1857 when Undefined =>
1858 Add_Arguments
1859 (Configuration_Pragmas_Switch (Arguments_Project) &
1860 The_Saved_Gcc_Switches.all);
1861 end case;
1862 end if;
1863 end;
1864 end if;
1866 -- Set Output_Is_Object, depending if there is a -S switch.
1867 -- If the bind step is not performed, and there is a -S switch,
1868 -- then we will not check for a valid object file.
1870 Check_For_S_Switch;
1871 end Collect_Arguments;
1873 ---------------------
1874 -- Compile_Sources --
1875 ---------------------
1877 procedure Compile_Sources
1878 (Main_Source : File_Name_Type;
1879 Args : Argument_List;
1880 First_Compiled_File : out Name_Id;
1881 Most_Recent_Obj_File : out Name_Id;
1882 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
1883 Main_Unit : out Boolean;
1884 Compilation_Failures : out Natural;
1885 Main_Index : Int := 0;
1886 Check_Readonly_Files : Boolean := False;
1887 Do_Not_Execute : Boolean := False;
1888 Force_Compilations : Boolean := False;
1889 Keep_Going : Boolean := False;
1890 In_Place_Mode : Boolean := False;
1891 Initialize_ALI_Data : Boolean := True;
1892 Max_Process : Positive := 1)
1894 No_Mapping_File : constant Natural := 0;
1896 type Compilation_Data is record
1897 Pid : Process_Id;
1898 Full_Source_File : File_Name_Type;
1899 Lib_File : File_Name_Type;
1900 Source_Unit : Unit_Name_Type;
1901 Mapping_File : Natural := No_Mapping_File;
1902 Project : Project_Id := No_Project;
1903 Syntax_Only : Boolean := False;
1904 Output_Is_Object : Boolean := True;
1905 end record;
1907 Running_Compile : array (1 .. Max_Process) of Compilation_Data;
1908 -- Used to save information about outstanding compilations
1910 Outstanding_Compiles : Natural := 0;
1911 -- Current number of outstanding compiles
1913 Source_Unit : Unit_Name_Type;
1914 -- Current source unit
1916 Source_File : File_Name_Type;
1917 -- Current source file
1919 Full_Source_File : File_Name_Type;
1920 -- Full name of the current source file
1922 Lib_File : File_Name_Type;
1923 -- Current library file
1925 Full_Lib_File : File_Name_Type;
1926 -- Full name of the current library file
1928 Obj_File : File_Name_Type;
1929 -- Full name of the object file corresponding to Lib_File
1931 Obj_Stamp : Time_Stamp_Type;
1932 -- Time stamp of the current object file
1934 Sfile : File_Name_Type;
1935 -- Contains the source file of the units withed by Source_File
1937 ALI : ALI_Id;
1938 -- ALI Id of the current ALI file
1940 -- Comment following declarations ???
1942 Read_Only : Boolean := False;
1944 Compilation_OK : Boolean;
1945 Need_To_Compile : Boolean;
1947 Pid : Process_Id;
1948 Text : Text_Buffer_Ptr;
1950 Mfile : Natural := No_Mapping_File;
1952 Need_To_Check_Standard_Library : Boolean :=
1953 Check_Readonly_Files
1954 and not Unique_Compile;
1956 Mapping_File_Arg : String_Access;
1958 Process_Created : Boolean := False;
1960 procedure Add_Process
1961 (Pid : Process_Id;
1962 Sfile : File_Name_Type;
1963 Afile : File_Name_Type;
1964 Uname : Unit_Name_Type;
1965 Mfile : Natural := No_Mapping_File);
1966 -- Adds process Pid to the current list of outstanding compilation
1967 -- processes and record the full name of the source file Sfile that
1968 -- we are compiling, the name of its library file Afile and the
1969 -- name of its unit Uname. If Mfile is not equal to No_Mapping_File,
1970 -- it is the index of the mapping file used during compilation in the
1971 -- array The_Mapping_File_Names.
1973 procedure Await_Compile
1974 (Sfile : out File_Name_Type;
1975 Afile : out File_Name_Type;
1976 Uname : out Unit_Name_Type;
1977 OK : out Boolean);
1978 -- Awaits that an outstanding compilation process terminates. When
1979 -- it does set Sfile to the name of the source file that was compiled
1980 -- Afile to the name of its library file and Uname to the name of its
1981 -- unit. Note that this time stamp can be used to check whether the
1982 -- compilation did generate an object file. OK is set to True if the
1983 -- compilation succeeded. Note that Sfile, Afile and Uname could be
1984 -- resp. No_File, No_File and No_Name if there were no compilations
1985 -- to wait for.
1987 function Bad_Compilation_Count return Natural;
1988 -- Returns the number of compilation failures
1990 procedure Check_Standard_Library;
1991 -- Check if s-stalib.adb needs to be compiled
1993 procedure Collect_Arguments_And_Compile
1994 (Source_File : File_Name_Type; Source_Index : Int);
1995 -- Collect arguments from project file (if any) and compile
1997 function Compile
1998 (S : Name_Id;
1999 L : Name_Id;
2000 Source_Index : Int;
2001 Args : Argument_List) return Process_Id;
2002 -- Compiles S using Args. If S is a GNAT predefined source
2003 -- "-gnatpg" is added to Args. Non blocking call. L corresponds to the
2004 -- expected library file name. Process_Id of the process spawned to
2005 -- execute the compile.
2007 package Good_ALI is new Table.Table (
2008 Table_Component_Type => ALI_Id,
2009 Table_Index_Type => Natural,
2010 Table_Low_Bound => 1,
2011 Table_Initial => 50,
2012 Table_Increment => 100,
2013 Table_Name => "Make.Good_ALI");
2014 -- Contains the set of valid ALI files that have not yet been scanned
2016 function Good_ALI_Present return Boolean;
2017 -- Returns True if any ALI file was recorded in the previous set
2019 procedure Get_Mapping_File (Project : Project_Id);
2020 -- Get a mapping file name. If there is one to be reused, reuse it.
2021 -- Otherwise, create a new mapping file.
2023 function Get_Next_Good_ALI return ALI_Id;
2024 -- Returns the next good ALI_Id record
2026 procedure Record_Failure
2027 (File : File_Name_Type;
2028 Unit : Unit_Name_Type;
2029 Found : Boolean := True);
2030 -- Records in the previous table that the compilation for File failed.
2031 -- If Found is False then the compilation of File failed because we
2032 -- could not find it. Records also Unit when possible.
2034 procedure Record_Good_ALI (A : ALI_Id);
2035 -- Records in the previous set the Id of an ALI file
2037 -----------------
2038 -- Add_Process --
2039 -----------------
2041 procedure Add_Process
2042 (Pid : Process_Id;
2043 Sfile : File_Name_Type;
2044 Afile : File_Name_Type;
2045 Uname : Unit_Name_Type;
2046 Mfile : Natural := No_Mapping_File)
2048 OC1 : constant Positive := Outstanding_Compiles + 1;
2050 begin
2051 pragma Assert (OC1 <= Max_Process);
2052 pragma Assert (Pid /= Invalid_Pid);
2054 Running_Compile (OC1).Pid := Pid;
2055 Running_Compile (OC1).Full_Source_File := Sfile;
2056 Running_Compile (OC1).Lib_File := Afile;
2057 Running_Compile (OC1).Source_Unit := Uname;
2058 Running_Compile (OC1).Mapping_File := Mfile;
2059 Running_Compile (OC1).Project := Arguments_Project;
2060 Running_Compile (OC1).Syntax_Only := Syntax_Only;
2061 Running_Compile (OC1).Output_Is_Object := Output_Is_Object;
2063 Outstanding_Compiles := OC1;
2064 end Add_Process;
2066 --------------------
2067 -- Await_Compile --
2068 -------------------
2070 procedure Await_Compile
2071 (Sfile : out File_Name_Type;
2072 Afile : out File_Name_Type;
2073 Uname : out File_Name_Type;
2074 OK : out Boolean)
2076 Pid : Process_Id;
2077 Project : Project_Id;
2079 begin
2080 pragma Assert (Outstanding_Compiles > 0);
2082 Sfile := No_File;
2083 Afile := No_File;
2084 Uname := No_Name;
2085 OK := False;
2087 -- The loop here is a work-around for a problem on VMS; in some
2088 -- circumstances (shared library and several executables, for
2089 -- example), there are child processes other than compilation
2090 -- processes that are received. Until this problem is resolved,
2091 -- we will ignore such processes.
2093 loop
2094 Wait_Process (Pid, OK);
2096 if Pid = Invalid_Pid then
2097 return;
2098 end if;
2100 for J in Running_Compile'First .. Outstanding_Compiles loop
2101 if Pid = Running_Compile (J).Pid then
2102 Sfile := Running_Compile (J).Full_Source_File;
2103 Afile := Running_Compile (J).Lib_File;
2104 Uname := Running_Compile (J).Source_Unit;
2105 Syntax_Only := Running_Compile (J).Syntax_Only;
2106 Output_Is_Object := Running_Compile (J).Output_Is_Object;
2107 Project := Running_Compile (J).Project;
2109 -- If a mapping file was used by this compilation,
2110 -- get its file name for reuse by a subsequent compilation
2112 if Running_Compile (J).Mapping_File /= No_Mapping_File then
2113 Last_Free_Indices (Project) :=
2114 Last_Free_Indices (Project) + 1;
2115 The_Free_Mapping_File_Indices
2116 (Project, Last_Free_Indices (Project)) :=
2117 Running_Compile (J).Mapping_File;
2118 end if;
2120 -- To actually remove this Pid and related info from
2121 -- Running_Compile replace its entry with the last valid
2122 -- entry in Running_Compile.
2124 if J = Outstanding_Compiles then
2125 null;
2127 else
2128 Running_Compile (J) :=
2129 Running_Compile (Outstanding_Compiles);
2130 end if;
2132 Outstanding_Compiles := Outstanding_Compiles - 1;
2133 return;
2134 end if;
2135 end loop;
2137 -- This child process was not one of our compilation processes;
2138 -- just ignore it for now.
2140 -- raise Program_Error;
2141 end loop;
2142 end Await_Compile;
2144 ---------------------------
2145 -- Bad_Compilation_Count --
2146 ---------------------------
2148 function Bad_Compilation_Count return Natural is
2149 begin
2150 return Bad_Compilation.Last - Bad_Compilation.First + 1;
2151 end Bad_Compilation_Count;
2153 ----------------------------
2154 -- Check_Standard_Library --
2155 ----------------------------
2157 procedure Check_Standard_Library is
2158 begin
2159 Need_To_Check_Standard_Library := False;
2161 if not Targparm.Suppress_Standard_Library_On_Target then
2162 declare
2163 Sfile : Name_Id;
2164 Add_It : Boolean := True;
2166 begin
2167 Name_Len := Standard_Library_Package_Body_Name'Length;
2168 Name_Buffer (1 .. Name_Len) :=
2169 Standard_Library_Package_Body_Name;
2170 Sfile := Name_Enter;
2172 -- If we have a special runtime, we add the standard
2173 -- library only if we can find it.
2175 if RTS_Switch then
2176 Add_It :=
2177 Find_File (Sfile, Osint.Source) /= No_File;
2178 end if;
2180 if Add_It then
2181 if Is_Marked (Sfile) then
2182 if Is_In_Obsoleted (Sfile) then
2183 Executable_Obsolete := True;
2184 end if;
2186 else
2187 Insert_Q (Sfile, Index => 0);
2188 Mark (Sfile, Index => 0);
2189 end if;
2190 end if;
2191 end;
2192 end if;
2193 end Check_Standard_Library;
2195 -----------------------------------
2196 -- Collect_Arguments_And_Compile --
2197 -----------------------------------
2199 procedure Collect_Arguments_And_Compile
2200 (Source_File : File_Name_Type; Source_Index : Int)
2202 begin
2203 -- Process_Created will be set True if an attempt is made to compile
2204 -- the source, that is if it is not in an externally built project.
2206 Process_Created := False;
2208 -- If arguments not yet collected (in Check), collect them now
2210 if not Arguments_Collected then
2211 Collect_Arguments (Source_File, Source_Index, Args);
2212 end if;
2214 -- If we use mapping file (-P or -C switches), then get one
2216 if Create_Mapping_File then
2217 Get_Mapping_File (Arguments_Project);
2218 end if;
2220 -- If the source is part of a project file, we set the ADA_*_PATHs,
2221 -- check for an eventual library project, and use the full path.
2223 if Arguments_Project /= No_Project then
2224 if not Projects.Table (Arguments_Project).Externally_Built then
2225 Prj.Env.Set_Ada_Paths (Arguments_Project, True);
2227 if not Unique_Compile
2228 and then MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None
2229 then
2230 declare
2231 The_Data : Project_Data :=
2232 Projects.Table (Arguments_Project);
2234 Prj : Project_Id := Arguments_Project;
2236 begin
2237 while The_Data.Extended_By /= No_Project loop
2238 Prj := The_Data.Extended_By;
2239 The_Data := Projects.Table (Prj);
2240 end loop;
2242 if The_Data.Library
2243 and then not The_Data.Need_To_Build_Lib
2244 then
2245 -- Add to the Q all sources of the project that
2246 -- have not been marked
2248 Insert_Project_Sources
2249 (The_Project => Prj,
2250 All_Projects => False,
2251 Into_Q => True);
2253 -- Now mark the project as processed
2255 Projects.Table (Prj).Need_To_Build_Lib := True;
2256 end if;
2257 end;
2258 end if;
2260 -- Change to the object directory of the project file,
2261 -- if necessary.
2263 Change_To_Object_Directory (Arguments_Project);
2265 Pid := Compile (Arguments_Path_Name, Lib_File, Source_Index,
2266 Arguments (1 .. Last_Argument));
2267 Process_Created := True;
2268 end if;
2270 else
2271 -- If this is a source outside of any project file, make sure it
2272 -- will be compiled in object directory of the main project file.
2274 if Main_Project /= No_Project then
2275 Change_To_Object_Directory (Arguments_Project);
2276 end if;
2278 Pid := Compile (Full_Source_File, Lib_File, Source_Index,
2279 Arguments (1 .. Last_Argument));
2280 Process_Created := True;
2281 end if;
2282 end Collect_Arguments_And_Compile;
2284 -------------
2285 -- Compile --
2286 -------------
2288 function Compile
2289 (S : Name_Id;
2290 L : Name_Id;
2291 Source_Index : Int;
2292 Args : Argument_List) return Process_Id
2294 Comp_Args : Argument_List (Args'First .. Args'Last + 9);
2295 Comp_Next : Integer := Args'First;
2296 Comp_Last : Integer;
2298 function Ada_File_Name (Name : Name_Id) return Boolean;
2299 -- Returns True if Name is the name of an ada source file
2300 -- (i.e. suffix is .ads or .adb)
2302 -------------------
2303 -- Ada_File_Name --
2304 -------------------
2306 function Ada_File_Name (Name : Name_Id) return Boolean is
2307 begin
2308 Get_Name_String (Name);
2309 return
2310 Name_Len > 4
2311 and then Name_Buffer (Name_Len - 3 .. Name_Len - 1) = ".ad"
2312 and then (Name_Buffer (Name_Len) = 'b'
2313 or else
2314 Name_Buffer (Name_Len) = 's');
2315 end Ada_File_Name;
2317 -- Start of processing for Compile
2319 begin
2320 Enter_Into_Obsoleted (S);
2322 -- By default, Syntax_Only is False
2324 Syntax_Only := False;
2326 for J in Args'Range loop
2327 if Args (J).all = "-gnats" then
2329 -- If we compile with -gnats, the bind step and the link step
2330 -- are inhibited. Also, we set Syntax_Only to True, so that
2331 -- we don't fail when we don't find the ALI file, after
2332 -- compilation.
2334 Do_Bind_Step := False;
2335 Do_Link_Step := False;
2336 Syntax_Only := True;
2338 elsif Args (J).all = "-gnatc" then
2340 -- If we compile with -gnatc, the bind step and the link step
2341 -- are inhibited. We set Syntax_Only to False for the case when
2342 -- -gnats was previously specified.
2344 Do_Bind_Step := False;
2345 Do_Link_Step := False;
2346 Syntax_Only := False;
2347 end if;
2348 end loop;
2350 Comp_Args (Comp_Next) := Comp_Flag;
2351 Comp_Next := Comp_Next + 1;
2353 -- Optimize the simple case where the gcc command line looks like
2354 -- gcc -c -I. ... -I- file.adb --into-> gcc -c ... file.adb
2356 if Args (Args'First).all = "-I" & Normalized_CWD
2357 and then Args (Args'Last).all = "-I-"
2358 and then S = Strip_Directory (S)
2359 then
2360 Comp_Last := Comp_Next + Args'Length - 3;
2361 Comp_Args (Comp_Next .. Comp_Last) :=
2362 Args (Args'First + 1 .. Args'Last - 1);
2364 else
2365 Comp_Last := Comp_Next + Args'Length - 1;
2366 Comp_Args (Comp_Next .. Comp_Last) := Args;
2367 end if;
2369 -- Set -gnatpg for predefined files (for this purpose the renamings
2370 -- such as Text_IO do not count as predefined). Note that we strip
2371 -- the directory name from the source file name becase the call to
2372 -- Fname.Is_Predefined_File_Name cannot deal with directory prefixes.
2374 declare
2375 Fname : constant File_Name_Type := Strip_Directory (S);
2377 begin
2378 if Is_Predefined_File_Name (Fname, False) then
2379 if Check_Readonly_Files then
2380 Comp_Last := Comp_Last + 1;
2381 Comp_Args (Comp_Last) := GNAT_Flag;
2383 else
2384 Make_Failed
2385 ("not allowed to compile """ &
2386 Get_Name_String (Fname) &
2387 """; use -a switch, or compile file with " &
2388 """-gnatg"" switch");
2389 end if;
2390 end if;
2391 end;
2393 -- Now check if the file name has one of the suffixes familiar to
2394 -- the gcc driver. If this is not the case then add the ada flag
2395 -- "-x ada".
2397 if not Ada_File_Name (S) and then not Targparm.AAMP_On_Target then
2398 Comp_Last := Comp_Last + 1;
2399 Comp_Args (Comp_Last) := Ada_Flag_1;
2400 Comp_Last := Comp_Last + 1;
2401 Comp_Args (Comp_Last) := Ada_Flag_2;
2402 end if;
2404 if Source_Index /= 0 then
2405 declare
2406 Num : constant String := Source_Index'Img;
2407 begin
2408 Comp_Last := Comp_Last + 1;
2409 Comp_Args (Comp_Last) :=
2410 new String'("-gnateI" & Num (Num'First + 1 .. Num'Last));
2411 end;
2412 end if;
2414 if Source_Index /= 0 or else
2415 L /= Strip_Directory (L) or else
2416 Object_Directory_Path /= null
2417 then
2418 -- Build -o argument
2420 Get_Name_String (L);
2422 for J in reverse 1 .. Name_Len loop
2423 if Name_Buffer (J) = '.' then
2424 Name_Len := J + Object_Suffix'Length - 1;
2425 Name_Buffer (J .. Name_Len) := Object_Suffix;
2426 exit;
2427 end if;
2428 end loop;
2430 Comp_Last := Comp_Last + 1;
2431 Comp_Args (Comp_Last) := Output_Flag;
2432 Comp_Last := Comp_Last + 1;
2434 -- If an object directory was specified, prepend the object file
2435 -- name with this object directory.
2437 if Object_Directory_Path /= null then
2438 Comp_Args (Comp_Last) :=
2439 new String'(Object_Directory_Path.all &
2440 Name_Buffer (1 .. Name_Len));
2442 else
2443 Comp_Args (Comp_Last) :=
2444 new String'(Name_Buffer (1 .. Name_Len));
2445 end if;
2446 end if;
2448 if Create_Mapping_File then
2449 Comp_Last := Comp_Last + 1;
2450 Comp_Args (Comp_Last) := Mapping_File_Arg;
2451 end if;
2453 Get_Name_String (S);
2455 Comp_Last := Comp_Last + 1;
2456 Comp_Args (Comp_Last) := new String'(Name_Buffer (1 .. Name_Len));
2458 GNAT.OS_Lib.Normalize_Arguments (Comp_Args (Args'First .. Comp_Last));
2460 Comp_Last := Comp_Last + 1;
2461 Comp_Args (Comp_Last) := new String'("-gnatez");
2463 Display (Gcc.all, Comp_Args (Args'First .. Comp_Last));
2465 if Gcc_Path = null then
2466 Make_Failed ("error, unable to locate ", Gcc.all);
2467 end if;
2469 return
2470 GNAT.OS_Lib.Non_Blocking_Spawn
2471 (Gcc_Path.all, Comp_Args (Args'First .. Comp_Last));
2472 end Compile;
2474 ----------------------
2475 -- Get_Mapping_File --
2476 ----------------------
2478 procedure Get_Mapping_File (Project : Project_Id) is
2479 begin
2480 -- If there is a mapping file ready to be reused, reuse it
2482 if Last_Free_Indices (Project) > 0 then
2483 Mfile := The_Free_Mapping_File_Indices
2484 (Project, Last_Free_Indices (Project));
2485 Last_Free_Indices (Project) := Last_Free_Indices (Project) - 1;
2487 -- Otherwise, create and initialize a new one
2489 else
2490 Init_Mapping_File (Project => Project, File_Index => Mfile);
2491 end if;
2493 -- Put the name in the mapping file argument for the invocation
2494 -- of the compiler.
2496 Free (Mapping_File_Arg);
2497 Mapping_File_Arg :=
2498 new String'("-gnatem=" &
2499 Get_Name_String
2500 (The_Mapping_File_Names (Project, Mfile)));
2502 end Get_Mapping_File;
2504 -----------------------
2505 -- Get_Next_Good_ALI --
2506 -----------------------
2508 function Get_Next_Good_ALI return ALI_Id is
2509 ALI : ALI_Id;
2511 begin
2512 pragma Assert (Good_ALI_Present);
2513 ALI := Good_ALI.Table (Good_ALI.Last);
2514 Good_ALI.Decrement_Last;
2515 return ALI;
2516 end Get_Next_Good_ALI;
2518 ----------------------
2519 -- Good_ALI_Present --
2520 ----------------------
2522 function Good_ALI_Present return Boolean is
2523 begin
2524 return Good_ALI.First <= Good_ALI.Last;
2525 end Good_ALI_Present;
2527 --------------------
2528 -- Record_Failure --
2529 --------------------
2531 procedure Record_Failure
2532 (File : File_Name_Type;
2533 Unit : Unit_Name_Type;
2534 Found : Boolean := True)
2536 begin
2537 Bad_Compilation.Increment_Last;
2538 Bad_Compilation.Table (Bad_Compilation.Last) := (File, Unit, Found);
2539 end Record_Failure;
2541 ---------------------
2542 -- Record_Good_ALI --
2543 ---------------------
2545 procedure Record_Good_ALI (A : ALI_Id) is
2546 begin
2547 Good_ALI.Increment_Last;
2548 Good_ALI.Table (Good_ALI.Last) := A;
2549 end Record_Good_ALI;
2551 -- Start of processing for Compile_Sources
2553 begin
2554 pragma Assert (Args'First = 1);
2556 -- Package and Queue initializations
2558 Good_ALI.Init;
2559 Output.Set_Standard_Error;
2561 if First_Q_Initialization then
2562 Init_Q;
2563 end if;
2565 if Initialize_ALI_Data then
2566 Initialize_ALI;
2567 Initialize_ALI_Source;
2568 end if;
2570 -- The following two flags affect the behavior of ALI.Set_Source_Table.
2571 -- We set Check_Source_Files to True to ensure that source file
2572 -- time stamps are checked, and we set All_Sources to False to
2573 -- avoid checking the presence of the source files listed in the
2574 -- source dependency section of an ali file (which would be a mistake
2575 -- since the ali file may be obsolete).
2577 Check_Source_Files := True;
2578 All_Sources := False;
2580 -- Only insert in the Q if it is not already done, to avoid simultaneous
2581 -- compilations if -jnnn is used.
2583 if not Is_Marked (Main_Source, Main_Index) then
2584 Insert_Q (Main_Source, Index => Main_Index);
2585 Mark (Main_Source, Main_Index);
2586 end if;
2588 First_Compiled_File := No_File;
2589 Most_Recent_Obj_File := No_File;
2590 Most_Recent_Obj_Stamp := Empty_Time_Stamp;
2591 Main_Unit := False;
2593 -- Keep looping until there is no more work to do (the Q is empty)
2594 -- and all the outstanding compilations have terminated
2596 Make_Loop : while not Empty_Q or else Outstanding_Compiles > 0 loop
2598 -- If the user does not want to keep going in case of errors then
2599 -- wait for the remaining outstanding compiles and then exit.
2601 if Bad_Compilation_Count > 0 and then not Keep_Going then
2602 while Outstanding_Compiles > 0 loop
2603 Await_Compile
2604 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
2606 if not Compilation_OK then
2607 Record_Failure (Full_Source_File, Source_Unit);
2608 end if;
2609 end loop;
2611 exit Make_Loop;
2612 end if;
2614 -- PHASE 1: Check if there is more work that we can do (ie the Q
2615 -- is non empty). If there is, do it only if we have not yet used
2616 -- up all the available processes.
2618 if not Empty_Q and then Outstanding_Compiles < Max_Process then
2619 declare
2620 Source_Index : Int;
2621 -- Index of the current unit in the current source file
2623 begin
2624 Extract_From_Q (Source_File, Source_Unit, Source_Index);
2625 Full_Source_File := Osint.Full_Source_Name (Source_File);
2626 Lib_File := Osint.Lib_File_Name
2627 (Source_File, Source_Index);
2628 Full_Lib_File := Osint.Full_Lib_File_Name (Lib_File);
2630 -- If this source has already been compiled, the executable is
2631 -- obsolete.
2633 if Is_In_Obsoleted (Source_File) then
2634 Executable_Obsolete := True;
2635 end if;
2637 -- If the library file is an Ada library skip it
2639 if Full_Lib_File /= No_File
2640 and then In_Ada_Lib_Dir (Full_Lib_File)
2641 then
2642 Verbose_Msg
2643 (Lib_File, "is in an Ada library", Prefix => " ");
2645 -- If the library file is a read-only library skip it, but
2646 -- only if, when using project files, this library file is
2647 -- in the right object directory (a read-only ALI file
2648 -- in the object directory of a project being extended
2649 -- should not be skipped).
2651 elsif Full_Lib_File /= No_File
2652 and then not Check_Readonly_Files
2653 and then Is_Readonly_Library (Full_Lib_File)
2654 and then Is_In_Object_Directory (Source_File, Full_Lib_File)
2655 then
2656 Verbose_Msg
2657 (Lib_File, "is a read-only library", Prefix => " ");
2659 -- The source file that we are checking cannot be located
2661 elsif Full_Source_File = No_File then
2662 Record_Failure (Source_File, Source_Unit, False);
2664 -- Source and library files can be located but are internal
2665 -- files
2667 elsif not Check_Readonly_Files
2668 and then Full_Lib_File /= No_File
2669 and then Is_Internal_File_Name (Source_File)
2670 then
2671 if Force_Compilations then
2672 Fail
2673 ("not allowed to compile """ &
2674 Get_Name_String (Source_File) &
2675 """; use -a switch, or compile file with " &
2676 """-gnatg"" switch");
2677 end if;
2679 Verbose_Msg
2680 (Lib_File, "is an internal library", Prefix => " ");
2682 -- The source file that we are checking can be located
2684 else
2685 Arguments_Collected := False;
2687 -- Don't waste any time if we have to recompile anyway
2689 Obj_Stamp := Empty_Time_Stamp;
2690 Need_To_Compile := Force_Compilations;
2692 if not Force_Compilations then
2693 Read_Only :=
2694 Full_Lib_File /= No_File
2695 and then not Check_Readonly_Files
2696 and then Is_Readonly_Library (Full_Lib_File);
2697 Check (Source_File, Source_Index, Args, Lib_File,
2698 Read_Only, ALI, Obj_File, Obj_Stamp);
2699 Need_To_Compile := (ALI = No_ALI_Id);
2700 end if;
2702 if not Need_To_Compile then
2704 -- The ALI file is up-to-date. Record its Id
2706 Record_Good_ALI (ALI);
2708 -- Record the time stamp of the most recent object file
2709 -- as long as no (re)compilations are needed.
2711 if First_Compiled_File = No_File
2712 and then (Most_Recent_Obj_File = No_File
2713 or else Obj_Stamp > Most_Recent_Obj_Stamp)
2714 then
2715 Most_Recent_Obj_File := Obj_File;
2716 Most_Recent_Obj_Stamp := Obj_Stamp;
2717 end if;
2719 else
2720 -- Is this the first file we have to compile?
2722 if First_Compiled_File = No_File then
2723 First_Compiled_File := Full_Source_File;
2724 Most_Recent_Obj_File := No_File;
2726 if Do_Not_Execute then
2727 exit Make_Loop;
2728 end if;
2729 end if;
2731 if In_Place_Mode then
2733 -- If the library file was not found, then save the
2734 -- library file near the source file.
2736 if Full_Lib_File = No_File then
2737 Lib_File := Osint.Lib_File_Name
2738 (Full_Source_File, Source_Index);
2740 -- If the library file was found, then save the
2741 -- library file in the same place.
2743 else
2744 Lib_File := Full_Lib_File;
2745 end if;
2747 end if;
2749 -- Start the compilation and record it. We can do this
2750 -- because there is at least one free process.
2752 Collect_Arguments_And_Compile (Source_File, Source_Index);
2754 -- Make sure we could successfully start the compilation
2756 if Process_Created then
2757 if Pid = Invalid_Pid then
2758 Record_Failure (Full_Source_File, Source_Unit);
2759 else
2760 Add_Process
2761 (Pid,
2762 Full_Source_File,
2763 Lib_File,
2764 Source_Unit,
2765 Mfile);
2766 end if;
2767 end if;
2768 end if;
2769 end if;
2770 end;
2771 end if;
2773 -- PHASE 2: Now check if we should wait for a compilation to
2774 -- finish. This is the case if all the available processes are
2775 -- busy compiling sources or there is nothing else to do
2776 -- (that is the Q is empty and there are no good ALIs to process).
2778 if Outstanding_Compiles = Max_Process
2779 or else (Empty_Q
2780 and then not Good_ALI_Present
2781 and then Outstanding_Compiles > 0)
2782 then
2783 Await_Compile
2784 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
2786 if not Compilation_OK then
2787 Record_Failure (Full_Source_File, Source_Unit);
2788 end if;
2790 if Compilation_OK or else Keep_Going then
2792 -- Re-read the updated library file
2794 declare
2795 Saved_Object_Consistency : constant Boolean :=
2796 Check_Object_Consistency;
2798 begin
2799 -- If compilation was not OK, or if output is not an
2800 -- object file and we don't do the bind step, don't check
2801 -- for object consistency.
2803 Check_Object_Consistency :=
2804 Check_Object_Consistency
2805 and Compilation_OK
2806 and (Output_Is_Object or Do_Bind_Step);
2807 Text := Read_Library_Info (Lib_File);
2809 -- Restore Check_Object_Consistency to its initial value
2811 Check_Object_Consistency := Saved_Object_Consistency;
2812 end;
2814 -- If an ALI file was generated by this compilation, scan
2815 -- the ALI file and record it.
2816 -- If the scan fails, a previous ali file is inconsistent with
2817 -- the unit just compiled.
2819 if Text /= null then
2820 ALI :=
2821 Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
2823 if ALI = No_ALI_Id then
2825 -- Record a failure only if not already done
2827 if Compilation_OK then
2828 Inform
2829 (Lib_File,
2830 "incompatible ALI file, please recompile");
2831 Record_Failure (Full_Source_File, Source_Unit);
2832 end if;
2833 else
2834 Free (Text);
2835 Record_Good_ALI (ALI);
2836 end if;
2838 -- If we could not read the ALI file that was just generated
2839 -- then there could be a problem reading either the ALI or the
2840 -- corresponding object file (if Check_Object_Consistency
2841 -- is set Read_Library_Info checks that the time stamp of the
2842 -- object file is more recent than that of the ALI). For an
2843 -- example of problems caught by this test see [6625-009].
2844 -- However, we record a failure only if not already done.
2846 else
2847 if Compilation_OK and not Syntax_Only then
2848 Inform
2849 (Lib_File,
2850 "WARNING: ALI or object file not found after compile");
2851 Record_Failure (Full_Source_File, Source_Unit);
2852 end if;
2853 end if;
2854 end if;
2855 end if;
2857 -- PHASE 3: Check if we recorded good ALI files. If yes process
2858 -- them now in the order in which they have been recorded. There
2859 -- are two occasions in which we record good ali files. The first is
2860 -- in phase 1 when, after scanning an existing ALI file we realize
2861 -- it is up-to-date, the second instance is after a successful
2862 -- compilation.
2864 while Good_ALI_Present loop
2865 ALI := Get_Next_Good_ALI;
2867 declare
2868 Source_Index : Int := Unit_Index_Of (ALIs.Table (ALI).Afile);
2870 begin
2871 -- If we are processing the library file corresponding to the
2872 -- main source file check if this source can be a main unit.
2874 if ALIs.Table (ALI).Sfile = Main_Source and then
2875 Source_Index = Main_Index
2876 then
2877 Main_Unit := ALIs.Table (ALI).Main_Program /= None;
2878 end if;
2880 -- The following adds the standard library (s-stalib) to the
2881 -- list of files to be handled by gnatmake: this file and any
2882 -- files it depends on are always included in every bind,
2883 -- even if they are not in the explicit dependency list.
2884 -- Of course, it is not added if Suppress_Standard_Library
2885 -- is True.
2887 -- However, to avoid annoying output about s-stalib.ali being
2888 -- read only, when "-v" is used, we add the standard library
2889 -- only when "-a" is used.
2891 if Need_To_Check_Standard_Library then
2892 Check_Standard_Library;
2893 end if;
2895 -- Now insert in the Q the unmarked source files (i.e. those
2896 -- which have never been inserted in the Q and hence never
2897 -- considered). Only do that if Unique_Compile is False.
2899 if not Unique_Compile then
2900 for J in
2901 ALIs.Table (ALI).First_Unit .. ALIs.Table (ALI).Last_Unit
2902 loop
2903 for K in
2904 Units.Table (J).First_With .. Units.Table (J).Last_With
2905 loop
2906 Sfile := Withs.Table (K).Sfile;
2907 Add_Dependency (ALIs.Table (ALI).Sfile, Sfile);
2909 if Is_In_Obsoleted (Sfile) then
2910 Executable_Obsolete := True;
2911 end if;
2913 if Sfile = No_File then
2914 Debug_Msg
2915 ("Skipping generic:", Withs.Table (K).Uname);
2917 else
2918 Source_Index :=
2919 Unit_Index_Of (Withs.Table (K).Afile);
2921 if Is_Marked (Sfile, Source_Index) then
2922 Debug_Msg ("Skipping marked file:", Sfile);
2924 elsif not Check_Readonly_Files
2925 and then Is_Internal_File_Name (Sfile)
2926 then
2927 Debug_Msg ("Skipping internal file:", Sfile);
2929 else
2930 Insert_Q
2931 (Sfile, Withs.Table (K).Uname, Source_Index);
2932 Mark (Sfile, Source_Index);
2933 end if;
2934 end if;
2935 end loop;
2936 end loop;
2937 end if;
2938 end;
2939 end loop;
2941 if Display_Compilation_Progress then
2942 Write_Str ("completed ");
2943 Write_Int (Int (Q_Front));
2944 Write_Str (" out of ");
2945 Write_Int (Int (Q.Last));
2946 Write_Str (" (");
2947 Write_Int (Int ((Q_Front * 100) / (Q.Last - Q.First)));
2948 Write_Str ("%)...");
2949 Write_Eol;
2950 end if;
2951 end loop Make_Loop;
2953 Compilation_Failures := Bad_Compilation_Count;
2955 -- Compilation is finished
2957 -- Delete any temporary configuration pragma file
2959 Delete_Temp_Config_Files;
2961 end Compile_Sources;
2963 ----------------------------------
2964 -- Configuration_Pragmas_Switch --
2965 ----------------------------------
2967 function Configuration_Pragmas_Switch
2968 (For_Project : Project_Id) return Argument_List
2970 The_Packages : Package_Id;
2971 Gnatmake : Package_Id;
2972 Compiler : Package_Id;
2974 Global_Attribute : Variable_Value := Nil_Variable_Value;
2975 Local_Attribute : Variable_Value := Nil_Variable_Value;
2977 Global_Attribute_Present : Boolean := False;
2978 Local_Attribute_Present : Boolean := False;
2980 Result : Argument_List (1 .. 3);
2981 Last : Natural := 0;
2983 function Absolute_Path
2984 (Path : Name_Id;
2985 Project : Project_Id) return String;
2986 -- Returns an absolute path for a configuration pragmas file
2988 -------------------
2989 -- Absolute_Path --
2990 -------------------
2992 function Absolute_Path
2993 (Path : Name_Id;
2994 Project : Project_Id) return String
2996 begin
2997 Get_Name_String (Path);
2999 declare
3000 Path_Name : constant String := Name_Buffer (1 .. Name_Len);
3002 begin
3003 if Is_Absolute_Path (Path_Name) then
3004 return Path_Name;
3006 else
3007 declare
3008 Parent_Directory : constant String :=
3009 Get_Name_String (Projects.Table (Project).Directory);
3011 begin
3012 if Parent_Directory (Parent_Directory'Last) =
3013 Directory_Separator
3014 then
3015 return Parent_Directory & Path_Name;
3017 else
3018 return Parent_Directory & Directory_Separator & Path_Name;
3019 end if;
3020 end;
3021 end if;
3022 end;
3023 end Absolute_Path;
3025 -- Start of processing for Configuration_Pragmas_Switch
3027 begin
3028 Prj.Env.Create_Config_Pragmas_File (For_Project, Main_Project);
3030 if Projects.Table (For_Project).Config_File_Name /= No_Name then
3031 Temporary_Config_File :=
3032 Projects.Table (For_Project).Config_File_Temp;
3033 Last := 1;
3034 Result (1) :=
3035 new String'
3036 ("-gnatec=" &
3037 Get_Name_String
3038 (Projects.Table (For_Project).Config_File_Name));
3040 else
3041 Temporary_Config_File := False;
3042 end if;
3044 -- Check for attribute Builder'Global_Configuration_Pragmas
3046 The_Packages := Projects.Table (Main_Project).Decl.Packages;
3047 Gnatmake :=
3048 Prj.Util.Value_Of
3049 (Name => Name_Builder,
3050 In_Packages => The_Packages);
3052 if Gnatmake /= No_Package then
3053 Global_Attribute := Prj.Util.Value_Of
3054 (Variable_Name => Name_Global_Configuration_Pragmas,
3055 In_Variables => Packages.Table (Gnatmake).Decl.Attributes);
3056 Global_Attribute_Present :=
3057 Global_Attribute /= Nil_Variable_Value
3058 and then Get_Name_String (Global_Attribute.Value) /= "";
3060 if Global_Attribute_Present then
3061 declare
3062 Path : constant String :=
3063 Absolute_Path
3064 (Global_Attribute.Value, Global_Attribute.Project);
3065 begin
3066 if not Is_Regular_File (Path) then
3067 Make_Failed
3068 ("cannot find configuration pragmas file ", Path);
3069 end if;
3071 Last := Last + 1;
3072 Result (Last) := new String'("-gnatec=" & Path);
3073 end;
3074 end if;
3075 end if;
3077 -- Check for attribute Compiler'Local_Configuration_Pragmas
3079 The_Packages := Projects.Table (For_Project).Decl.Packages;
3080 Compiler :=
3081 Prj.Util.Value_Of
3082 (Name => Name_Compiler,
3083 In_Packages => The_Packages);
3085 if Compiler /= No_Package then
3086 Local_Attribute := Prj.Util.Value_Of
3087 (Variable_Name => Name_Local_Configuration_Pragmas,
3088 In_Variables => Packages.Table (Compiler).Decl.Attributes);
3089 Local_Attribute_Present :=
3090 Local_Attribute /= Nil_Variable_Value
3091 and then Get_Name_String (Local_Attribute.Value) /= "";
3093 if Local_Attribute_Present then
3094 declare
3095 Path : constant String :=
3096 Absolute_Path
3097 (Local_Attribute.Value, Local_Attribute.Project);
3098 begin
3099 if not Is_Regular_File (Path) then
3100 Make_Failed
3101 ("cannot find configuration pragmas file ", Path);
3102 end if;
3104 Last := Last + 1;
3105 Result (Last) := new String'("-gnatec=" & Path);
3106 end;
3107 end if;
3108 end if;
3110 return Result (1 .. Last);
3111 end Configuration_Pragmas_Switch;
3113 ---------------
3114 -- Debug_Msg --
3115 ---------------
3117 procedure Debug_Msg (S : String; N : Name_Id) is
3118 begin
3119 if Debug.Debug_Flag_W then
3120 Write_Str (" ... ");
3121 Write_Str (S);
3122 Write_Str (" ");
3123 Write_Name (N);
3124 Write_Eol;
3125 end if;
3126 end Debug_Msg;
3128 ---------------------------
3129 -- Delete_All_Temp_Files --
3130 ---------------------------
3132 procedure Delete_All_Temp_Files is
3133 begin
3134 if Gnatmake_Called and not Debug.Debug_Flag_N then
3135 Delete_Mapping_Files;
3136 Delete_Temp_Config_Files;
3137 Prj.Env.Delete_All_Path_Files;
3138 end if;
3139 end Delete_All_Temp_Files;
3141 --------------------------
3142 -- Delete_Mapping_Files --
3143 --------------------------
3145 procedure Delete_Mapping_Files is
3146 Success : Boolean;
3147 begin
3148 if not Debug.Debug_Flag_N then
3149 if The_Mapping_File_Names /= null then
3150 for Project in The_Mapping_File_Names'Range (1) loop
3151 for Index in 1 .. Last_Mapping_File_Names (Project) loop
3152 Delete_File
3153 (Name => Get_Name_String
3154 (The_Mapping_File_Names (Project, Index)),
3155 Success => Success);
3156 end loop;
3157 end loop;
3158 end if;
3159 end if;
3160 end Delete_Mapping_Files;
3162 ------------------------------
3163 -- Delete_Temp_Config_Files --
3164 ------------------------------
3166 procedure Delete_Temp_Config_Files is
3167 Success : Boolean;
3168 begin
3169 if (not Debug.Debug_Flag_N) and Main_Project /= No_Project then
3170 for Project in 1 .. Projects.Last loop
3171 if Projects.Table (Project).Config_File_Temp then
3172 if Verbose_Mode then
3173 Write_Str ("Deleting temp configuration file """);
3174 Write_Str (Get_Name_String
3175 (Projects.Table (Project).Config_File_Name));
3176 Write_Line ("""");
3177 end if;
3179 Delete_File
3180 (Name => Get_Name_String
3181 (Projects.Table (Project).Config_File_Name),
3182 Success => Success);
3184 -- Make sure that we don't have a config file for this
3185 -- project, in case when there are several mains.
3186 -- In this case, we will recreate another config file:
3187 -- we cannot reuse the one that we just deleted!
3189 Projects.Table (Project).Config_Checked := False;
3190 Projects.Table (Project).Config_File_Name := No_Name;
3191 Projects.Table (Project).Config_File_Temp := False;
3192 end if;
3193 end loop;
3194 end if;
3195 end Delete_Temp_Config_Files;
3197 -------------
3198 -- Display --
3199 -------------
3201 procedure Display (Program : String; Args : Argument_List) is
3202 begin
3203 pragma Assert (Args'First = 1);
3205 if Display_Executed_Programs then
3206 Write_Str (Program);
3208 for J in Args'Range loop
3210 -- Never display -gnatez
3212 if Args (J).all /= "-gnatez" then
3214 -- Do not display the mapping file argument automatically
3215 -- created when using a project file.
3217 if Main_Project = No_Project
3218 or else Debug.Debug_Flag_N
3219 or else Args (J)'Length < 8
3220 or else
3221 Args (J) (Args (J)'First .. Args (J)'First + 6) /= "-gnatem"
3222 then
3223 -- When -dn is not specified, do not display the config
3224 -- pragmas switch (-gnatec) for the temporary file created
3225 -- by the project manager (always the first -gnatec switch).
3226 -- Reset Temporary_Config_File to False so that the eventual
3227 -- other -gnatec switches will be displayed.
3229 if (not Debug.Debug_Flag_N)
3230 and then Temporary_Config_File
3231 and then Args (J)'Length > 7
3232 and then Args (J) (Args (J)'First .. Args (J)'First + 6)
3233 = "-gnatec"
3234 then
3235 Temporary_Config_File := False;
3237 -- Do not display the -F=mapping_file switch for
3238 -- gnatbind, if -dn is not specified.
3240 elsif Debug.Debug_Flag_N
3241 or else Args (J)'Length < 4
3242 or else
3243 Args (J) (Args (J)'First .. Args (J)'First + 2) /= "-F="
3244 then
3245 Write_Str (" ");
3246 Write_Str (Args (J).all);
3247 end if;
3248 end if;
3249 end if;
3250 end loop;
3252 Write_Eol;
3253 end if;
3254 end Display;
3256 ----------------------
3257 -- Display_Commands --
3258 ----------------------
3260 procedure Display_Commands (Display : Boolean := True) is
3261 begin
3262 Display_Executed_Programs := Display;
3263 end Display_Commands;
3265 -------------
3266 -- Empty_Q --
3267 -------------
3269 function Empty_Q return Boolean is
3270 begin
3271 if Debug.Debug_Flag_P then
3272 Write_Str (" Q := [");
3274 for J in Q_Front .. Q.Last - 1 loop
3275 Write_Str (" ");
3276 Write_Name (Q.Table (J).File);
3277 Write_Eol;
3278 Write_Str (" ");
3279 end loop;
3281 Write_Str ("]");
3282 Write_Eol;
3283 end if;
3285 return Q_Front >= Q.Last;
3286 end Empty_Q;
3288 --------------------------
3289 -- Enter_Into_Obsoleted --
3290 --------------------------
3292 procedure Enter_Into_Obsoleted (F : Name_Id) is
3293 Name : constant String := Get_Name_String (F);
3294 First : Natural := Name'Last;
3295 F2 : Name_Id := F;
3297 begin
3298 while First > Name'First
3299 and then Name (First - 1) /= Directory_Separator
3300 and then Name (First - 1) /= '/'
3301 loop
3302 First := First - 1;
3303 end loop;
3305 if First /= Name'First then
3306 Name_Len := 0;
3307 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
3308 F2 := Name_Find;
3309 end if;
3311 Debug_Msg ("New entry in Obsoleted table:", F2);
3312 Obsoleted.Set (F2, True);
3313 end Enter_Into_Obsoleted;
3315 ---------------------
3316 -- Extract_Failure --
3317 ---------------------
3319 procedure Extract_Failure
3320 (File : out File_Name_Type;
3321 Unit : out Unit_Name_Type;
3322 Found : out Boolean)
3324 begin
3325 File := Bad_Compilation.Table (Bad_Compilation.Last).File;
3326 Unit := Bad_Compilation.Table (Bad_Compilation.Last).Unit;
3327 Found := Bad_Compilation.Table (Bad_Compilation.Last).Found;
3328 Bad_Compilation.Decrement_Last;
3329 end Extract_Failure;
3331 --------------------
3332 -- Extract_From_Q --
3333 --------------------
3335 procedure Extract_From_Q
3336 (Source_File : out File_Name_Type;
3337 Source_Unit : out Unit_Name_Type;
3338 Source_Index : out Int)
3340 File : constant File_Name_Type := Q.Table (Q_Front).File;
3341 Unit : constant Unit_Name_Type := Q.Table (Q_Front).Unit;
3342 Index : constant Int := Q.Table (Q_Front).Index;
3344 begin
3345 if Debug.Debug_Flag_Q then
3346 Write_Str (" Q := Q - [ ");
3347 Write_Name (File);
3349 if Index /= 0 then
3350 Write_Str (", ");
3351 Write_Int (Index);
3352 end if;
3354 Write_Str (" ]");
3355 Write_Eol;
3356 end if;
3358 Q_Front := Q_Front + 1;
3359 Source_File := File;
3360 Source_Unit := Unit;
3361 Source_Index := Index;
3362 end Extract_From_Q;
3364 --------------
3365 -- Gnatmake --
3366 --------------
3368 procedure Gnatmake is
3369 Main_Source_File : File_Name_Type;
3370 -- The source file containing the main compilation unit
3372 Compilation_Failures : Natural;
3374 Total_Compilation_Failures : Natural := 0;
3376 Is_Main_Unit : Boolean;
3377 -- Set to True by Compile_Sources if the Main_Source_File can be a
3378 -- main unit.
3380 Main_ALI_File : File_Name_Type;
3381 -- The ali file corresponding to Main_Source_File
3383 Executable : File_Name_Type := No_File;
3384 -- The file name of an executable
3386 Non_Std_Executable : Boolean := False;
3387 -- Non_Std_Executable is set to True when there is a possibility
3388 -- that the linker will not choose the correct executable file name.
3390 Current_Work_Dir : constant String_Access :=
3391 new String'(Get_Current_Dir);
3392 -- The current working directory, used to modify some relative path
3393 -- switches on the command line when a project file is used.
3395 Current_Main_Index : Int := 0;
3396 -- If not zero, the index of the current main unit in its source file
3398 There_Are_Stand_Alone_Libraries : Boolean := False;
3399 -- Set to True when there are Stand-Alone Libraries, so that gnatbind
3400 -- is invoked with the -F switch to force checking of elaboration flags.
3402 Mapping_Path : Name_Id := No_Name;
3403 -- The path name of the mapping file
3405 Discard : Boolean;
3407 procedure Check_Mains;
3408 -- Check that the main subprograms do exist and that they all
3409 -- belong to the same project file.
3411 procedure Create_Binder_Mapping_File
3412 (Args : in out Argument_List; Last_Arg : in out Natural);
3413 -- Create a binder mapping file and add the necessary switch
3415 -----------------
3416 -- Check_Mains --
3417 -----------------
3419 procedure Check_Mains is
3420 Real_Main_Project : Project_Id := No_Project;
3421 -- The project of the first main
3423 Proj : Project_Id := No_Project;
3424 -- The project of the current main
3426 Data : Project_Data;
3428 Real_Path : String_Access;
3430 begin
3431 Mains.Reset;
3433 -- Check each main
3435 loop
3436 declare
3437 Main : constant String := Mains.Next_Main;
3438 -- The name specified on the command line may include
3439 -- directory information.
3441 File_Name : constant String := Base_Name (Main);
3442 -- The simple file name of the current main main
3444 begin
3445 exit when Main = "";
3447 -- Get the project of the current main
3449 Proj := Prj.Env.Project_Of (File_Name, Main_Project);
3451 -- Fail if the current main is not a source of a
3452 -- project.
3454 if Proj = No_Project then
3455 Make_Failed
3456 ("""" & Main &
3457 """ is not a source of any project");
3459 else
3460 -- If there is directory information, check that
3461 -- the source exists and, if it does, that the path
3462 -- is the actual path of a source of a project.
3464 if Main /= File_Name then
3465 Data := Projects.Table (Main_Project);
3467 Real_Path :=
3468 Locate_Regular_File
3469 (Main &
3470 Get_Name_String
3471 (Data.Naming.Ada_Body_Suffix),
3472 "");
3473 if Real_Path = null then
3474 Real_Path :=
3475 Locate_Regular_File
3476 (Main &
3477 Get_Name_String
3478 (Data.Naming.Ada_Spec_Suffix),
3479 "");
3480 end if;
3482 if Real_Path = null then
3483 Real_Path :=
3484 Locate_Regular_File (Main, "");
3485 end if;
3487 -- Fail if the file cannot be found
3489 if Real_Path = null then
3490 Make_Failed
3491 ("file """ & Main & """ does not exist");
3492 end if;
3494 declare
3495 Project_Path : constant String :=
3496 Prj.Env.File_Name_Of_Library_Unit_Body
3497 (Name => File_Name,
3498 Project => Main_Project,
3499 Main_Project_Only => False,
3500 Full_Path => True);
3501 Normed_Path : constant String :=
3502 Normalize_Pathname
3503 (Real_Path.all,
3504 Case_Sensitive => False);
3505 Proj_Path : constant String :=
3506 Normalize_Pathname
3507 (Project_Path,
3508 Case_Sensitive => False);
3510 begin
3511 Free (Real_Path);
3513 -- Fail if it is not the correct path
3515 if Normed_Path /= Proj_Path then
3516 if Verbose_Mode then
3517 Write_Str (Normed_Path);
3518 Write_Str (" /= ");
3519 Write_Line (Proj_Path);
3520 end if;
3522 Make_Failed
3523 ("""" & Main &
3524 """ is not a source of any project");
3525 end if;
3526 end;
3527 end if;
3529 if not Unique_Compile then
3531 -- Record the project, if it is the first main
3533 if Real_Main_Project = No_Project then
3534 Real_Main_Project := Proj;
3536 elsif Proj /= Real_Main_Project then
3538 -- Fail, as the current main is not a source
3539 -- of the same project as the first main.
3541 Make_Failed
3542 ("""" & Main &
3543 """ is not a source of project " &
3544 Get_Name_String
3545 (Projects.Table
3546 (Real_Main_Project).Name));
3547 end if;
3548 end if;
3549 end if;
3551 -- If -u and -U are not used, we may have mains that
3552 -- are sources of a project that is not the one
3553 -- specified with switch -P.
3555 if not Unique_Compile then
3556 Main_Project := Real_Main_Project;
3557 end if;
3558 end;
3559 end loop;
3560 end Check_Mains;
3562 --------------------------------
3563 -- Create_Binder_Mapping_File --
3564 --------------------------------
3566 procedure Create_Binder_Mapping_File
3567 (Args : in out Argument_List; Last_Arg : in out Natural)
3569 Mapping_FD : File_Descriptor := Invalid_FD;
3570 -- A File Descriptor for an eventual mapping file
3572 ALI_Unit : Name_Id := No_Name;
3573 -- The unit name of an ALI file
3575 ALI_Name : Name_Id := No_Name;
3576 -- The file name of the ALI file
3578 ALI_Project : Project_Id := No_Project;
3579 -- The project of the ALI file
3581 Bytes : Integer;
3582 OK : Boolean := True;
3584 Status : Boolean;
3585 -- For call to Close
3587 begin
3588 Tempdir.Create_Temp_File (Mapping_FD, Mapping_Path);
3590 if Mapping_FD /= Invalid_FD then
3592 -- Traverse all units
3594 for J in Prj.Com.Units.First .. Prj.Com.Units.Last loop
3595 declare
3596 Unit : constant Prj.Com.Unit_Data :=
3597 Prj.Com.Units.Table (J);
3598 use Prj.Com;
3600 begin
3601 if Unit.Name /= No_Name then
3603 -- If there is a body, put it in the mapping
3605 if Unit.File_Names (Body_Part).Name /= No_Name
3606 and then Unit.File_Names (Body_Part).Project
3607 /= No_Project
3608 then
3609 Get_Name_String (Unit.Name);
3610 Name_Buffer
3611 (Name_Len + 1 .. Name_Len + 2) := "%b";
3612 Name_Len := Name_Len + 2;
3613 ALI_Unit := Name_Find;
3614 ALI_Name :=
3615 Lib_File_Name
3616 (Unit.File_Names (Body_Part).Name);
3617 ALI_Project :=
3618 Unit.File_Names (Body_Part).Project;
3620 -- Otherwise, if there is a spec, put it
3621 -- in the mapping.
3623 elsif Unit.File_Names (Specification).Name
3624 /= No_Name
3625 and then Unit.File_Names
3626 (Specification).Project
3627 /= No_Project
3628 then
3629 Get_Name_String (Unit.Name);
3630 Name_Buffer
3631 (Name_Len + 1 .. Name_Len + 2) := "%s";
3632 Name_Len := Name_Len + 2;
3633 ALI_Unit := Name_Find;
3634 ALI_Name := Lib_File_Name
3635 (Unit.File_Names (Specification).Name);
3636 ALI_Project :=
3637 Unit.File_Names (Specification).Project;
3639 else
3640 ALI_Name := No_Name;
3641 end if;
3643 -- If we have something to put in the mapping
3644 -- then we do it now. However, if the project
3645 -- is extended, we don't put anything in the
3646 -- mapping file, because we do not know where
3647 -- the ALI file is: it might be in the ext-
3648 -- ended project obj dir as well as in the
3649 -- extending project obj dir.
3651 if ALI_Name /= No_Name
3652 and then
3653 Projects.Table (ALI_Project).Extended_By = No_Project
3654 and then
3655 Projects.Table (ALI_Project).Extends = No_Project
3656 then
3657 -- First line is the unit name
3659 Get_Name_String (ALI_Unit);
3660 Name_Len := Name_Len + 1;
3661 Name_Buffer (Name_Len) := ASCII.LF;
3662 Bytes :=
3663 Write
3664 (Mapping_FD,
3665 Name_Buffer (1)'Address,
3666 Name_Len);
3667 OK := Bytes = Name_Len;
3669 exit when not OK;
3671 -- Second line it the ALI file name
3673 Get_Name_String (ALI_Name);
3674 Name_Len := Name_Len + 1;
3675 Name_Buffer (Name_Len) := ASCII.LF;
3676 Bytes :=
3677 Write
3678 (Mapping_FD,
3679 Name_Buffer (1)'Address,
3680 Name_Len);
3681 OK := Bytes = Name_Len;
3683 exit when not OK;
3685 -- Third line it the ALI path name,
3686 -- concatenation of the project
3687 -- directory with the ALI file name.
3689 declare
3690 ALI : constant String :=
3691 Get_Name_String (ALI_Name);
3692 begin
3693 Get_Name_String
3694 (Projects.Table (ALI_Project).
3695 Object_Directory);
3697 if Name_Buffer (Name_Len) /=
3698 Directory_Separator
3699 then
3700 Name_Len := Name_Len + 1;
3701 Name_Buffer (Name_Len) :=
3702 Directory_Separator;
3703 end if;
3705 Name_Buffer
3706 (Name_Len + 1 ..
3707 Name_Len + ALI'Length) := ALI;
3708 Name_Len :=
3709 Name_Len + ALI'Length + 1;
3710 Name_Buffer (Name_Len) := ASCII.LF;
3711 Bytes :=
3712 Write
3713 (Mapping_FD,
3714 Name_Buffer (1)'Address,
3715 Name_Len);
3716 OK := Bytes = Name_Len;
3717 end;
3719 -- If OK is False, it means we were unable
3720 -- to write a line. No point in continuing
3721 -- with the other units.
3723 exit when not OK;
3724 end if;
3725 end if;
3726 end;
3727 end loop;
3729 Close (Mapping_FD, Status);
3731 OK := OK and Status;
3733 -- If the creation of the mapping file was successful,
3734 -- we add the switch to the arguments of gnatbind.
3736 if OK then
3737 Last_Arg := Last_Arg + 1;
3738 Args (Last_Arg) :=
3739 new String'("-F=" & Get_Name_String (Mapping_Path));
3740 end if;
3741 end if;
3742 end Create_Binder_Mapping_File;
3744 -- Start of processing for Gnatmake
3746 -- This body is very long, should be broken down ???
3748 begin
3749 Gnatmake_Called := True;
3751 Install_Int_Handler (Sigint_Intercepted'Access);
3753 Do_Compile_Step := True;
3754 Do_Bind_Step := True;
3755 Do_Link_Step := True;
3757 Obsoleted.Reset;
3759 Make.Initialize;
3761 Bind_Shared := No_Shared_Switch'Access;
3762 Link_With_Shared_Libgcc := No_Shared_Libgcc_Switch'Access;
3764 Failed_Links.Set_Last (0);
3765 Successful_Links.Set_Last (0);
3767 if Hostparm.Java_VM then
3768 Gcc := new String'("jgnat");
3769 Gnatbind := new String'("jgnatbind");
3770 Gnatlink := new String'("jgnatlink");
3772 -- Do not check for an object file (".o") when compiling to
3773 -- Java bytecode since ".class" files are generated instead.
3775 Check_Object_Consistency := False;
3776 end if;
3778 -- Special case when switch -B was specified
3780 if Build_Bind_And_Link_Full_Project then
3782 -- When switch -B is specified, there must be a project file
3784 if Main_Project = No_Project then
3785 Make_Failed ("-B cannot be used without a project file");
3787 -- No main program may be specified on the command line
3789 elsif Osint.Number_Of_Files /= 0 then
3790 Make_Failed ("-B cannot be used with a main specified on " &
3791 "the command line");
3793 -- And the project file cannot be a library project file
3795 elsif Projects.Table (Main_Project).Library then
3796 Make_Failed ("-B cannot be used for a library project file");
3798 else
3799 Insert_Project_Sources
3800 (The_Project => Main_Project,
3801 All_Projects => Unique_Compile_All_Projects,
3802 Into_Q => False);
3804 -- If there are no sources to compile, we fail
3806 if Osint.Number_Of_Files = 0 then
3807 Make_Failed ("no sources to compile");
3808 end if;
3810 -- Specify -n for gnatbind and add the ALI files of all the
3811 -- sources, except the one which is a fake main subprogram:
3812 -- this is the one for the binder generated file and it will be
3813 -- transmitted to gnatlink. These sources are those that are
3814 -- in the queue.
3816 Add_Switch ("-n", Binder, And_Save => True);
3818 for J in Q.First .. Q.Last - 1 loop
3819 Add_Switch
3820 (Get_Name_String
3821 (Lib_File_Name (Q.Table (J).File)),
3822 Binder, And_Save => True);
3823 end loop;
3824 end if;
3826 elsif Main_Index /= 0 and then Osint.Number_Of_Files > 1 then
3827 Make_Failed ("cannot specify several mains with a multi-unit index");
3829 elsif Main_Project /= No_Project then
3831 -- If the main project file is a library project file, main(s)
3832 -- cannot be specified on the command line.
3834 if Osint.Number_Of_Files /= 0 then
3835 if Projects.Table (Main_Project).Library
3836 and then not Unique_Compile
3837 and then ((not Make_Steps) or else Bind_Only or else Link_Only)
3838 then
3839 Make_Failed ("cannot specify a main program " &
3840 "on the command line for a library project file");
3842 else
3843 -- Check that each main on the command line is a source of a
3844 -- project file and, if there are several mains, each of them
3845 -- is a source of the same project file.
3847 Check_Mains;
3848 end if;
3850 -- If no mains have been specified on the command line,
3851 -- and we are using a project file, we either find the main(s)
3852 -- in the attribute Main of the main project, or we put all
3853 -- the sources of the project file as mains.
3855 else
3856 if Main_Index /= 0 then
3857 Make_Failed ("cannot specify a multi-unit index but no main " &
3858 "on the command line");
3859 end if;
3861 declare
3862 Value : String_List_Id := Projects.Table (Main_Project).Mains;
3864 begin
3865 -- The attribute Main is an empty list or not specified,
3866 -- or else gnatmake was invoked with the switch "-u".
3868 if Value = Prj.Nil_String or else Unique_Compile then
3870 if (not Make_Steps) or else Compile_Only
3871 or else not Projects.Table (Main_Project).Library
3872 then
3873 -- First make sure that the binder and the linker
3874 -- will not be invoked.
3876 Do_Bind_Step := False;
3877 Do_Link_Step := False;
3879 -- Put all the sources in the queue
3881 Insert_Project_Sources
3882 (The_Project => Main_Project,
3883 All_Projects => Unique_Compile_All_Projects,
3884 Into_Q => False);
3886 -- If there are no sources to compile, we fail
3888 if Osint.Number_Of_Files = 0 then
3889 Make_Failed ("no sources to compile");
3890 end if;
3891 end if;
3893 else
3894 -- The attribute Main is not an empty list.
3895 -- Put all the main subprograms in the list as if there
3896 -- were specified on the command line. However, if attribute
3897 -- Languages includes a language other than Ada, only
3898 -- include the Ada mains; if there is no Ada main, compile
3899 -- all the sources of the project.
3901 declare
3902 Data : constant Project_Data :=
3903 Projects.Table (Main_Project);
3905 Languages : constant Variable_Value :=
3906 Prj.Util.Value_Of
3907 (Name_Languages, Data.Decl.Attributes);
3909 Current : String_List_Id;
3910 Element : String_Element;
3912 Foreign_Language : Boolean := False;
3913 At_Least_One_Main : Boolean := False;
3915 begin
3916 -- First, determine if there is a foreign language in
3917 -- attribute Languages.
3919 if not Languages.Default then
3920 Current := Languages.Values;
3922 Look_For_Foreign :
3923 while Current /= Nil_String loop
3924 Element := String_Elements.Table (Current);
3925 Get_Name_String (Element.Value);
3926 To_Lower (Name_Buffer (1 .. Name_Len));
3928 if Name_Buffer (1 .. Name_Len) /= "ada" then
3929 Foreign_Language := True;
3930 exit Look_For_Foreign;
3931 end if;
3933 Current := Element.Next;
3934 end loop Look_For_Foreign;
3935 end if;
3937 -- Then, find all mains, or if there is a foreign
3938 -- language, all the Ada mains.
3940 while Value /= Prj.Nil_String loop
3941 Get_Name_String (String_Elements.Table (Value).Value);
3943 -- To know if a main is an Ada main, get its project.
3944 -- It should be the project specified on the command
3945 -- line.
3947 if (not Foreign_Language) or else
3948 Prj.Env.Project_Of
3949 (Name_Buffer (1 .. Name_Len), Main_Project) =
3950 Main_Project
3951 then
3952 At_Least_One_Main := True;
3953 Osint.Add_File
3954 (Get_Name_String
3955 (String_Elements.Table (Value).Value),
3956 Index => String_Elements.Table (Value).Index);
3957 end if;
3959 Value := String_Elements.Table (Value).Next;
3960 end loop;
3962 -- If we did not get any main, it means that all mains
3963 -- in attribute Mains are in a foreign language and -B
3964 -- was not specified to gnatmake; so, we fail.
3966 if not At_Least_One_Main then
3967 Make_Failed
3968 ("no Ada mains; use -B to build foreign main");
3969 end if;
3970 end;
3972 end if;
3973 end;
3974 end if;
3975 end if;
3977 if Verbose_Mode then
3978 Write_Eol;
3979 Write_Str ("GNATMAKE ");
3980 Write_Str (Gnatvsn.Gnat_Version_String);
3981 Write_Eol;
3982 Write_Str ("Copyright 1995-2004 Free Software Foundation, Inc.");
3983 Write_Eol;
3984 end if;
3986 if Main_Project /= No_Project
3987 and then Projects.Table (Main_Project).Externally_Built
3988 then
3989 Make_Failed
3990 ("nothing to do for a main project that is externally built");
3991 end if;
3993 if Osint.Number_Of_Files = 0 then
3994 if Main_Project /= No_Project
3995 and then Projects.Table (Main_Project).Library
3996 then
3997 if Do_Bind_Step
3998 and then not Projects.Table (Main_Project).Standalone_Library
3999 then
4000 Make_Failed ("only stand-alone libraries may be bound");
4001 end if;
4003 -- Add the default search directories to be able to find libgnat
4005 Osint.Add_Default_Search_Dirs;
4007 -- And bind and or link the library
4009 MLib.Prj.Build_Library
4010 (For_Project => Main_Project,
4011 Gnatbind => Gnatbind.all,
4012 Gnatbind_Path => Gnatbind_Path,
4013 Gcc => Gcc.all,
4014 Gcc_Path => Gcc_Path,
4015 Bind => Bind_Only,
4016 Link => Link_Only);
4017 Exit_Program (E_Success);
4019 else
4020 -- Output usage information if no files to compile
4022 Usage;
4023 Exit_Program (E_Fatal);
4024 end if;
4025 end if;
4027 -- If -M was specified, behave as if -n was specified
4029 if List_Dependencies then
4030 Do_Not_Execute := True;
4031 end if;
4033 -- Note that Osint.Next_Main_Source will always return the (possibly
4034 -- abbreviated file) without any directory information.
4036 Main_Source_File := Next_Main_Source;
4038 if Current_File_Index /= No_Index then
4039 Main_Index := Current_File_Index;
4040 end if;
4042 Add_Switch ("-I-", Binder, And_Save => True);
4043 Add_Switch ("-I-", Compiler, And_Save => True);
4045 if Main_Project = No_Project then
4046 if Look_In_Primary_Dir then
4048 Add_Switch
4049 ("-I" &
4050 Normalize_Directory_Name
4051 (Get_Primary_Src_Search_Directory.all).all,
4052 Compiler, Append_Switch => False,
4053 And_Save => False);
4055 Add_Switch ("-aO" & Normalized_CWD,
4056 Binder,
4057 Append_Switch => False,
4058 And_Save => False);
4059 end if;
4061 else
4062 -- If we use a project file, we have already checked that a main
4063 -- specified on the command line with directory information has the
4064 -- path name corresponding to a correct source in the project tree.
4065 -- So, we don't need the directory information to be taken into
4066 -- account by Find_File, and in fact it may lead to take the wrong
4067 -- sources for other compilation units, when there are extending
4068 -- projects.
4070 Look_In_Primary_Dir := False;
4071 end if;
4073 -- If the user wants a program without a main subprogram, add the
4074 -- appropriate switch to the binder.
4076 if No_Main_Subprogram then
4077 Add_Switch ("-z", Binder, And_Save => True);
4078 end if;
4080 if Main_Project /= No_Project then
4082 if Projects.Table (Main_Project).Object_Directory /= No_Name then
4084 -- Change the current directory to the object directory of
4085 -- the main project.
4087 begin
4088 Project_Object_Directory := No_Project;
4089 Change_To_Object_Directory (Main_Project);
4091 exception
4092 when Directory_Error =>
4094 -- This should never happen. But, if it does, display the
4095 -- content of the parent directory of the obj dir.
4097 declare
4098 Parent : constant Dir_Name_Str :=
4099 Dir_Name
4100 (Get_Name_String
4101 (Projects.Table
4102 (Main_Project).Object_Directory));
4104 Dir : Dir_Type;
4105 Str : String (1 .. 200);
4106 Last : Natural;
4108 begin
4109 Write_Str ("Contents of directory """);
4110 Write_Str (Parent);
4111 Write_Line (""":");
4113 Open (Dir, Parent);
4115 loop
4116 Read (Dir, Str, Last);
4117 exit when Last = 0;
4118 Write_Str (" ");
4119 Write_Line (Str (1 .. Last));
4120 end loop;
4122 Close (Dir);
4124 exception
4125 when X : others =>
4126 Write_Line ("(unexpected exception)");
4127 Write_Line (Exception_Information (X));
4129 if Is_Open (Dir) then
4130 Close (Dir);
4131 end if;
4132 end;
4134 Make_Failed
4135 ("unable to change working directory to """,
4136 Get_Name_String
4137 (Projects.Table (Main_Project).Object_Directory),
4138 """");
4139 end;
4140 end if;
4142 -- Source file lookups should be cached for efficiency.
4143 -- Source files are not supposed to change.
4145 Osint.Source_File_Data (Cache => True);
4147 -- Find the file name of the (first) main unit
4149 declare
4150 Main_Source_File_Name : constant String :=
4151 Get_Name_String (Main_Source_File);
4152 Main_Unit_File_Name : constant String :=
4153 Prj.Env.File_Name_Of_Library_Unit_Body
4154 (Name => Main_Source_File_Name,
4155 Project => Main_Project,
4156 Main_Project_Only =>
4157 not Unique_Compile);
4159 The_Packages : constant Package_Id :=
4160 Projects.Table (Main_Project).Decl.Packages;
4162 Builder_Package : constant Prj.Package_Id :=
4163 Prj.Util.Value_Of
4164 (Name => Name_Builder,
4165 In_Packages => The_Packages);
4167 Binder_Package : constant Prj.Package_Id :=
4168 Prj.Util.Value_Of
4169 (Name => Name_Binder,
4170 In_Packages => The_Packages);
4172 Linker_Package : constant Prj.Package_Id :=
4173 Prj.Util.Value_Of
4174 (Name => Name_Linker,
4175 In_Packages => The_Packages);
4177 begin
4178 -- We fail if we cannot find the main source file
4180 if Main_Unit_File_Name = "" then
4181 Make_Failed ('"' & Main_Source_File_Name,
4182 """ is not a unit of project ",
4183 Project_File_Name.all & ".");
4184 else
4185 -- Remove any directory information from the main
4186 -- source file name.
4188 declare
4189 Pos : Natural := Main_Unit_File_Name'Last;
4191 begin
4192 loop
4193 exit when Pos < Main_Unit_File_Name'First or else
4194 Main_Unit_File_Name (Pos) = Directory_Separator;
4195 Pos := Pos - 1;
4196 end loop;
4198 Name_Len := Main_Unit_File_Name'Last - Pos;
4200 Name_Buffer (1 .. Name_Len) :=
4201 Main_Unit_File_Name
4202 (Pos + 1 .. Main_Unit_File_Name'Last);
4204 Main_Source_File := Name_Find;
4206 -- We only output the main source file if there is only one
4208 if Verbose_Mode and then Osint.Number_Of_Files = 1 then
4209 Write_Str ("Main source file: """);
4210 Write_Str (Main_Unit_File_Name
4211 (Pos + 1 .. Main_Unit_File_Name'Last));
4212 Write_Line (""".");
4213 end if;
4214 end;
4215 end if;
4217 -- If there is a package Builder in the main project file, add
4218 -- the switches from it.
4220 if Builder_Package /= No_Package then
4222 -- If there is only one main, we attempt to get the gnatmake
4223 -- switches for this main (if any). If there are no specific
4224 -- switch for this particular main, get the general gnatmake
4225 -- switches (if any).
4227 if Osint.Number_Of_Files = 1 then
4228 if Verbose_Mode then
4229 Write_Str ("Adding gnatmake switches for """);
4230 Write_Str (Main_Unit_File_Name);
4231 Write_Line (""".");
4232 end if;
4234 Add_Switches
4235 (File_Name => Main_Unit_File_Name,
4236 Index => Main_Index,
4237 The_Package => Builder_Package,
4238 Program => None);
4240 else
4241 -- If there are several mains, we always get the general
4242 -- gnatmake switches (if any).
4244 -- Warn the user, if necessary, so that he is not surprized
4245 -- that specific switches are not taken into account.
4247 declare
4248 Defaults : constant Variable_Value :=
4249 Prj.Util.Value_Of
4250 (Name => Name_Ada,
4251 Index => 0,
4252 Attribute_Or_Array_Name => Name_Default_Switches,
4253 In_Package => Builder_Package);
4255 Switches : constant Array_Element_Id :=
4256 Prj.Util.Value_Of
4257 (Name => Name_Switches,
4258 In_Arrays =>
4259 Packages.Table (Builder_Package).Decl.Arrays);
4261 begin
4262 if Defaults /= Nil_Variable_Value then
4263 if (not Quiet_Output)
4264 and then Switches /= No_Array_Element
4265 then
4266 Write_Line
4267 ("Warning: using Builder'Default_Switches" &
4268 "(""Ada""), as there are several mains");
4269 end if;
4271 -- As there is never a source with name " ", we are
4272 -- guaranteed to always get the general switches.
4274 Add_Switches
4275 (File_Name => " ",
4276 Index => 0,
4277 The_Package => Builder_Package,
4278 Program => None);
4280 elsif (not Quiet_Output)
4281 and then Switches /= No_Array_Element
4282 then
4283 Write_Line
4284 ("Warning: using no switches from package Builder," &
4285 " as there are several mains");
4286 end if;
4287 end;
4288 end if;
4289 end if;
4291 Osint.Add_Default_Search_Dirs;
4293 -- Record the current last switch index for table Binder_Switches
4294 -- and Linker_Switches, so that these tables may be reset before
4295 -- for each main, before adding swiches from the project file
4296 -- and from the command line.
4298 Last_Binder_Switch := Binder_Switches.Last;
4299 Last_Linker_Switch := Linker_Switches.Last;
4301 Check_Steps;
4303 -- Add binder switches from the project file for the first main
4305 if Do_Bind_Step and Binder_Package /= No_Package then
4306 if Verbose_Mode then
4307 Write_Str ("Adding binder switches for """);
4308 Write_Str (Main_Unit_File_Name);
4309 Write_Line (""".");
4310 end if;
4312 Add_Switches
4313 (File_Name => Main_Unit_File_Name,
4314 Index => Main_Index,
4315 The_Package => Binder_Package,
4316 Program => Binder);
4317 end if;
4319 -- Add linker switches from the project file for the first main
4321 if Do_Link_Step and Linker_Package /= No_Package then
4322 if Verbose_Mode then
4323 Write_Str ("Adding linker switches for""");
4324 Write_Str (Main_Unit_File_Name);
4325 Write_Line (""".");
4326 end if;
4328 Add_Switches
4329 (File_Name => Main_Unit_File_Name,
4330 Index => Main_Index,
4331 The_Package => Linker_Package,
4332 Program => Linker);
4333 end if;
4334 end;
4335 end if;
4337 -- Get the target parameters, which are only needed for a couple of
4338 -- cases in gnatmake. Protect against an exception, such as the case
4339 -- of system.ads missing from the library, and fail gracefully.
4341 begin
4342 Targparm.Get_Target_Parameters;
4344 exception
4345 when Unrecoverable_Error =>
4346 Make_Failed ("*** make failed.");
4347 end;
4349 Display_Commands (not Quiet_Output);
4351 Check_Steps;
4353 if Main_Project /= No_Project then
4355 -- For all library project, if the library file does not exist
4356 -- put all the project sources in the queue, and flag the project
4357 -- so that the library is generated.
4359 if not Unique_Compile
4360 and then MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None
4361 then
4362 for Proj in Projects.First .. Projects.Last loop
4363 if Projects.Table (Proj).Library then
4364 Projects.Table (Proj).Need_To_Build_Lib :=
4365 (not MLib.Tgt.Library_Exists_For (Proj))
4366 and then (not Projects.Table (Proj).Externally_Built);
4368 if Projects.Table (Proj).Need_To_Build_Lib then
4370 -- If there is no object directory, then it will be
4371 -- impossible to build the library. So fail immediately.
4373 if Projects.Table (Proj).Object_Directory = No_Name then
4374 Make_Failed
4375 ("no object files to build library for project """,
4376 Get_Name_String (Projects.Table (Proj).Name),
4377 """");
4378 Projects.Table (Proj).Need_To_Build_Lib := False;
4380 else
4381 if Verbose_Mode then
4382 Write_Str
4383 ("Library file does not exist for project """);
4384 Write_Str
4385 (Get_Name_String (Projects.Table (Proj).Name));
4386 Write_Line ("""");
4387 end if;
4389 Insert_Project_Sources
4390 (The_Project => Proj,
4391 All_Projects => False,
4392 Into_Q => True);
4393 end if;
4394 end if;
4395 end if;
4396 end loop;
4397 end if;
4399 -- If a relative path output file has been specified, we add
4400 -- the exec directory.
4402 for J in reverse 1 .. Saved_Linker_Switches.Last - 1 loop
4403 if Saved_Linker_Switches.Table (J).all = Output_Flag.all then
4404 declare
4405 Exec_File_Name : constant String :=
4406 Saved_Linker_Switches.Table (J + 1).all;
4408 begin
4409 if not Is_Absolute_Path (Exec_File_Name) then
4410 for Index in Exec_File_Name'Range loop
4411 if Exec_File_Name (Index) = Directory_Separator then
4412 Make_Failed ("relative executable (""",
4413 Exec_File_Name,
4414 """) with directory part not " &
4415 "allowed when using project files");
4416 end if;
4417 end loop;
4419 Get_Name_String (Projects.Table
4420 (Main_Project).Exec_Directory);
4422 if Name_Buffer (Name_Len) /= Directory_Separator then
4423 Name_Len := Name_Len + 1;
4424 Name_Buffer (Name_Len) := Directory_Separator;
4425 end if;
4427 Name_Buffer (Name_Len + 1 ..
4428 Name_Len + Exec_File_Name'Length) :=
4429 Exec_File_Name;
4430 Name_Len := Name_Len + Exec_File_Name'Length;
4431 Saved_Linker_Switches.Table (J + 1) :=
4432 new String'(Name_Buffer (1 .. Name_Len));
4433 end if;
4434 end;
4436 exit;
4437 end if;
4438 end loop;
4440 -- If we are using a project file, for relative paths we add the
4441 -- current working directory for any relative path on the command
4442 -- line and the project directory, for any relative path in the
4443 -- project file.
4445 declare
4446 Dir_Path : constant String_Access :=
4447 new String'(Get_Name_String
4448 (Projects.Table (Main_Project).Directory));
4449 begin
4450 for J in 1 .. Binder_Switches.Last loop
4451 Test_If_Relative_Path
4452 (Binder_Switches.Table (J),
4453 Parent => Dir_Path, Including_L_Switch => False);
4454 end loop;
4456 for J in 1 .. Saved_Binder_Switches.Last loop
4457 Test_If_Relative_Path
4458 (Saved_Binder_Switches.Table (J),
4459 Parent => Current_Work_Dir, Including_L_Switch => False);
4460 end loop;
4462 for J in 1 .. Linker_Switches.Last loop
4463 Test_If_Relative_Path
4464 (Linker_Switches.Table (J), Parent => Dir_Path);
4465 end loop;
4467 for J in 1 .. Saved_Linker_Switches.Last loop
4468 Test_If_Relative_Path
4469 (Saved_Linker_Switches.Table (J), Parent => Current_Work_Dir);
4470 end loop;
4472 for J in 1 .. Gcc_Switches.Last loop
4473 Test_If_Relative_Path
4474 (Gcc_Switches.Table (J), Parent => Dir_Path);
4475 end loop;
4477 for J in 1 .. Saved_Gcc_Switches.Last loop
4478 Test_If_Relative_Path
4479 (Saved_Gcc_Switches.Table (J), Parent => Current_Work_Dir);
4480 end loop;
4481 end;
4482 end if;
4484 -- We now put in the Binder_Switches and Linker_Switches tables,
4485 -- the binder and linker switches of the command line that have been
4486 -- put in the Saved_ tables. If a project file was used, then the
4487 -- command line switches will follow the project file switches.
4489 for J in 1 .. Saved_Binder_Switches.Last loop
4490 Add_Switch
4491 (Saved_Binder_Switches.Table (J),
4492 Binder,
4493 And_Save => False);
4494 end loop;
4496 for J in 1 .. Saved_Linker_Switches.Last loop
4497 Add_Switch
4498 (Saved_Linker_Switches.Table (J),
4499 Linker,
4500 And_Save => False);
4501 end loop;
4503 -- If no project file is used, we just put the gcc switches
4504 -- from the command line in the Gcc_Switches table.
4506 if Main_Project = No_Project then
4507 for J in 1 .. Saved_Gcc_Switches.Last loop
4508 Add_Switch
4509 (Saved_Gcc_Switches.Table (J),
4510 Compiler,
4511 And_Save => False);
4512 end loop;
4514 else
4515 -- And we put the command line gcc switches in the variable
4516 -- The_Saved_Gcc_Switches. They are going to be used later
4517 -- in procedure Compile_Sources.
4519 The_Saved_Gcc_Switches :=
4520 new Argument_List (1 .. Saved_Gcc_Switches.Last + 1);
4522 for J in 1 .. Saved_Gcc_Switches.Last loop
4523 The_Saved_Gcc_Switches (J) := Saved_Gcc_Switches.Table (J);
4524 end loop;
4526 -- We never use gnat.adc when a project file is used
4528 The_Saved_Gcc_Switches (The_Saved_Gcc_Switches'Last) :=
4529 No_gnat_adc;
4531 end if;
4533 -- If there was a --GCC, --GNATBIND or --GNATLINK switch on
4534 -- the command line, then we have to use it, even if there was
4535 -- another switch in the project file.
4537 if Saved_Gcc /= null then
4538 Gcc := Saved_Gcc;
4539 end if;
4541 if Saved_Gnatbind /= null then
4542 Gnatbind := Saved_Gnatbind;
4543 end if;
4545 if Saved_Gnatlink /= null then
4546 Gnatlink := Saved_Gnatlink;
4547 end if;
4549 Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
4550 Gnatbind_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
4551 Gnatlink_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
4553 -- If we have specified -j switch both from the project file
4554 -- and on the command line, the one from the command line takes
4555 -- precedence.
4557 if Saved_Maximum_Processes = 0 then
4558 Saved_Maximum_Processes := Maximum_Processes;
4559 end if;
4561 -- Allocate as many temporary mapping file names as the maximum
4562 -- number of compilation processed, for each possible project.
4564 The_Mapping_File_Names :=
4565 new Temp_File_Names
4566 (No_Project .. Projects.Last, 1 .. Saved_Maximum_Processes);
4567 Last_Mapping_File_Names :=
4568 new Indices'(No_Project .. Projects.Last => 0);
4570 The_Free_Mapping_File_Indices :=
4571 new Free_File_Indices
4572 (No_Project .. Projects.Last, 1 .. Saved_Maximum_Processes);
4573 Last_Free_Indices :=
4574 new Indices'(No_Project .. Projects.Last => 0);
4576 Bad_Compilation.Init;
4578 Current_Main_Index := Main_Index;
4580 -- Here is where the make process is started
4582 -- We do the same process for each main
4584 Multiple_Main_Loop : for N_File in 1 .. Osint.Number_Of_Files loop
4586 -- First, find the executable name and path
4588 Executable := No_File;
4589 Executable_Obsolete := False;
4590 Non_Std_Executable := False;
4592 -- Look inside the linker switches to see if the name
4593 -- of the final executable program was specified.
4596 J in reverse Linker_Switches.First .. Linker_Switches.Last
4597 loop
4598 if Linker_Switches.Table (J).all = Output_Flag.all then
4599 pragma Assert (J < Linker_Switches.Last);
4601 -- We cannot specify a single executable for several
4602 -- main subprograms!
4604 if Osint.Number_Of_Files > 1 then
4605 Fail
4606 ("cannot specify a single executable " &
4607 "for several mains");
4608 end if;
4610 Name_Len := Linker_Switches.Table (J + 1)'Length;
4611 Name_Buffer (1 .. Name_Len) :=
4612 Linker_Switches.Table (J + 1).all;
4613 Executable := Name_Enter;
4615 Verbose_Msg (Executable, "final executable");
4616 end if;
4617 end loop;
4619 -- If the name of the final executable program was not
4620 -- specified then construct it from the main input file.
4622 if Executable = No_File then
4623 if Main_Project = No_Project then
4624 Executable :=
4625 Executable_Name (Strip_Suffix (Main_Source_File));
4627 else
4628 -- If we are using a project file, we attempt to
4629 -- remove the body (or spec) termination of the main
4630 -- subprogram. We find it the the naming scheme of the
4631 -- project file. This will avoid to generate an
4632 -- executable "main.2" for a main subprogram
4633 -- "main.2.ada", when the body termination is ".2.ada".
4635 Executable := Prj.Util.Executable_Of
4636 (Main_Project, Main_Source_File, Main_Index);
4637 end if;
4638 end if;
4640 if Main_Project /= No_Project then
4641 declare
4642 Exec_File_Name : constant String :=
4643 Get_Name_String (Executable);
4645 begin
4646 if not Is_Absolute_Path (Exec_File_Name) then
4647 for Index in Exec_File_Name'Range loop
4648 if Exec_File_Name (Index) = Directory_Separator then
4649 Make_Failed ("relative executable (""",
4650 Exec_File_Name,
4651 """) with directory part not " &
4652 "allowed when using project files");
4653 end if;
4654 end loop;
4656 Get_Name_String (Projects.Table
4657 (Main_Project).Exec_Directory);
4660 Name_Buffer (Name_Len) /= Directory_Separator
4661 then
4662 Name_Len := Name_Len + 1;
4663 Name_Buffer (Name_Len) := Directory_Separator;
4664 end if;
4666 Name_Buffer (Name_Len + 1 ..
4667 Name_Len + Exec_File_Name'Length) :=
4668 Exec_File_Name;
4670 Name_Len := Name_Len + Exec_File_Name'Length;
4671 Executable := Name_Find;
4672 Non_Std_Executable := True;
4673 end if;
4674 end;
4675 end if;
4677 if Do_Compile_Step then
4678 Recursive_Compilation_Step : declare
4679 Args : Argument_List (1 .. Gcc_Switches.Last);
4681 First_Compiled_File : Name_Id;
4682 Youngest_Obj_File : Name_Id;
4683 Youngest_Obj_Stamp : Time_Stamp_Type;
4685 Executable_Stamp : Time_Stamp_Type;
4686 -- Executable is the final executable program
4688 Library_Rebuilt : Boolean := False;
4690 begin
4691 for J in 1 .. Gcc_Switches.Last loop
4692 Args (J) := Gcc_Switches.Table (J);
4693 end loop;
4695 -- Now we invoke Compile_Sources for the current main
4697 Compile_Sources
4698 (Main_Source => Main_Source_File,
4699 Args => Args,
4700 First_Compiled_File => First_Compiled_File,
4701 Most_Recent_Obj_File => Youngest_Obj_File,
4702 Most_Recent_Obj_Stamp => Youngest_Obj_Stamp,
4703 Main_Unit => Is_Main_Unit,
4704 Main_Index => Current_Main_Index,
4705 Compilation_Failures => Compilation_Failures,
4706 Check_Readonly_Files => Check_Readonly_Files,
4707 Do_Not_Execute => Do_Not_Execute,
4708 Force_Compilations => Force_Compilations,
4709 In_Place_Mode => In_Place_Mode,
4710 Keep_Going => Keep_Going,
4711 Initialize_ALI_Data => True,
4712 Max_Process => Saved_Maximum_Processes);
4714 if Verbose_Mode then
4715 Write_Str ("End of compilation");
4716 Write_Eol;
4717 end if;
4719 -- Make sure the queue will be reinitialized for the next round
4721 First_Q_Initialization := True;
4723 Total_Compilation_Failures :=
4724 Total_Compilation_Failures + Compilation_Failures;
4726 if Total_Compilation_Failures /= 0 then
4727 if Keep_Going then
4728 goto Next_Main;
4729 else
4730 List_Bad_Compilations;
4731 raise Compilation_Failed;
4732 end if;
4733 end if;
4735 -- Regenerate libraries, if any, and if object files
4736 -- have been regenerated.
4738 if Main_Project /= No_Project
4739 and then MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None
4740 and then (Do_Bind_Step or Unique_Compile_All_Projects
4741 or not Compile_Only)
4742 and then (Do_Link_Step or N_File = Osint.Number_Of_Files)
4743 then
4744 Library_Projs.Init;
4746 declare
4747 Proj2 : Project_Id;
4748 Depth : Natural;
4749 Current : Natural;
4751 begin
4752 -- Put in Library_Projs table all library project
4753 -- file ids when the library need to be rebuilt.
4755 for Proj1 in Projects.First .. Projects.Last loop
4757 if Projects.Table (Proj1).Standalone_Library then
4758 There_Are_Stand_Alone_Libraries := True;
4759 end if;
4761 if Projects.Table (Proj1).Library
4762 and then not Projects.Table (Proj1).Need_To_Build_Lib
4763 and then not Projects.Table (Proj1).Externally_Built
4764 then
4765 MLib.Prj.Check_Library (Proj1);
4766 end if;
4768 if Projects.Table (Proj1).Need_To_Build_Lib then
4769 Library_Projs.Increment_Last;
4770 Current := Library_Projs.Last;
4771 Depth := Projects.Table (Proj1).Depth;
4773 -- Put the projects in decreasing depth order,
4774 -- so that if libA depends on libB, libB is first
4775 -- in order.
4777 while Current > 1 loop
4778 Proj2 := Library_Projs.Table (Current - 1);
4779 exit when Projects.Table (Proj2).Depth >= Depth;
4780 Library_Projs.Table (Current) := Proj2;
4781 Current := Current - 1;
4782 end loop;
4784 Library_Projs.Table (Current) := Proj1;
4785 Projects.Table (Proj1).Need_To_Build_Lib := False;
4786 end if;
4787 end loop;
4788 end;
4790 -- Build the libraries, if any need to be built
4792 for J in 1 .. Library_Projs.Last loop
4793 Library_Rebuilt := True;
4794 MLib.Prj.Build_Library
4795 (For_Project => Library_Projs.Table (J),
4796 Gnatbind => Gnatbind.all,
4797 Gnatbind_Path => Gnatbind_Path,
4798 Gcc => Gcc.all,
4799 Gcc_Path => Gcc_Path);
4800 end loop;
4801 end if;
4803 if List_Dependencies then
4804 if First_Compiled_File /= No_File then
4805 Inform
4806 (First_Compiled_File,
4807 "must be recompiled. Can't generate dependence list.");
4808 else
4809 List_Depend;
4810 end if;
4812 elsif First_Compiled_File = No_File
4813 and then not Do_Bind_Step
4814 and then not Quiet_Output
4815 and then not Library_Rebuilt
4816 and then Osint.Number_Of_Files = 1
4817 then
4818 Inform (Msg => "objects up to date.");
4820 elsif Do_Not_Execute
4821 and then First_Compiled_File /= No_File
4822 then
4823 Write_Name (First_Compiled_File);
4824 Write_Eol;
4825 end if;
4827 -- Stop after compile step if any of:
4829 -- 1) -n (Do_Not_Execute) specified
4831 -- 2) -M (List_Dependencies) specified (also sets
4832 -- Do_Not_Execute above, so this is probably superfluous).
4834 -- 3) -c (Compile_Only) specified, but not -b (Bind_Only)
4836 -- 4) Made unit cannot be a main unit
4838 if (Do_Not_Execute
4839 or List_Dependencies
4840 or not Do_Bind_Step
4841 or not Is_Main_Unit)
4842 and then not No_Main_Subprogram
4843 and then not Build_Bind_And_Link_Full_Project
4844 then
4845 if Osint.Number_Of_Files = 1 then
4846 exit Multiple_Main_Loop;
4848 else
4849 goto Next_Main;
4850 end if;
4851 end if;
4853 -- If the objects were up-to-date check if the executable file
4854 -- is also up-to-date. For now always bind and link on the JVM
4855 -- since there is currently no simple way to check the
4856 -- up-to-date status of objects
4858 if not Hostparm.Java_VM
4859 and then First_Compiled_File = No_File
4860 then
4861 Executable_Stamp := File_Stamp (Executable);
4863 if not Executable_Obsolete then
4864 Executable_Obsolete :=
4865 Youngest_Obj_Stamp > Executable_Stamp;
4866 end if;
4868 if not Executable_Obsolete then
4869 for Index in reverse 1 .. Dependencies.Last loop
4870 if Is_In_Obsoleted
4871 (Dependencies.Table (Index).Depends_On)
4872 then
4873 Enter_Into_Obsoleted
4874 (Dependencies.Table (Index).This);
4875 end if;
4876 end loop;
4878 Executable_Obsolete := Is_In_Obsoleted (Main_Source_File);
4879 Dependencies.Init;
4880 end if;
4882 if not Executable_Obsolete then
4884 -- If no Ada object files obsolete the executable, check
4885 -- for younger or missing linker files.
4887 Check_Linker_Options
4888 (Executable_Stamp,
4889 Youngest_Obj_File,
4890 Youngest_Obj_Stamp);
4892 Executable_Obsolete := Youngest_Obj_File /= No_File;
4893 end if;
4895 -- Return if the executable is up to date
4896 -- and otherwise motivate the relink/rebind.
4898 if not Executable_Obsolete then
4899 if not Quiet_Output then
4900 Inform (Executable, "up to date.");
4901 end if;
4903 if Osint.Number_Of_Files = 1 then
4904 exit Multiple_Main_Loop;
4906 else
4907 goto Next_Main;
4908 end if;
4909 end if;
4911 if Executable_Stamp (1) = ' ' then
4912 Verbose_Msg (Executable, "missing.", Prefix => " ");
4914 elsif Youngest_Obj_Stamp (1) = ' ' then
4915 Verbose_Msg
4916 (Youngest_Obj_File,
4917 "missing.",
4918 Prefix => " ");
4920 elsif Youngest_Obj_Stamp > Executable_Stamp then
4921 Verbose_Msg
4922 (Youngest_Obj_File,
4923 "(" & String (Youngest_Obj_Stamp) & ") newer than",
4924 Executable,
4925 "(" & String (Executable_Stamp) & ")");
4927 else
4928 Verbose_Msg
4929 (Executable, "needs to be rebuild.",
4930 Prefix => " ");
4932 end if;
4933 end if;
4934 end Recursive_Compilation_Step;
4935 end if;
4937 -- For binding and linking, we need to be in the object directory of
4938 -- the main project.
4940 if Main_Project /= No_Project then
4941 Change_To_Object_Directory (Main_Project);
4942 end if;
4944 -- If we are here, it means that we need to rebuilt the current
4945 -- main. So we set Executable_Obsolete to True to make sure that
4946 -- the subsequent mains will be rebuilt.
4948 Main_ALI_In_Place_Mode_Step : declare
4949 ALI_File : File_Name_Type;
4950 Src_File : File_Name_Type;
4952 begin
4953 Src_File := Strip_Directory (Main_Source_File);
4954 ALI_File := Lib_File_Name (Src_File, Current_Main_Index);
4955 Main_ALI_File := Full_Lib_File_Name (ALI_File);
4957 -- When In_Place_Mode, the library file can be located in the
4958 -- Main_Source_File directory which may not be present in the
4959 -- library path. In this case, use the corresponding library file
4960 -- name.
4962 if Main_ALI_File = No_File and then In_Place_Mode then
4963 Get_Name_String (Get_Directory (Full_Source_Name (Src_File)));
4964 Get_Name_String_And_Append (ALI_File);
4965 Main_ALI_File := Name_Find;
4966 Main_ALI_File := Full_Lib_File_Name (Main_ALI_File);
4967 end if;
4969 if Main_ALI_File = No_File then
4970 Make_Failed ("could not find the main ALI file");
4971 end if;
4972 end Main_ALI_In_Place_Mode_Step;
4974 if Do_Bind_Step then
4975 Bind_Step : declare
4976 Args : Argument_List
4977 (Binder_Switches.First .. Binder_Switches.Last + 2);
4978 -- The arguments for the invocation of gnatbind
4980 Last_Arg : Natural := Binder_Switches.Last;
4981 -- Index of the last argument in Args
4983 Shared_Libs : Boolean := False;
4984 -- Set to True when there are shared library project files or
4985 -- when gnatbind is invoked with -shared.
4987 begin
4988 -- Check if there are shared libraries, so that gnatbind is
4989 -- called with -shared. Check also if gnatbind is called with
4990 -- -shared, so that gnatlink is called with -shared-libgcc
4991 -- for GCC version 3 and above, ensuring that the shared
4992 -- version of libgcc will be used.
4994 if Main_Project /= No_Project
4995 and then MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None
4996 then
4997 for Proj in Projects.First .. Projects.Last loop
4998 if Projects.Table (Proj).Library and then
4999 Projects.Table (Proj).Library_Kind /= Static
5000 then
5001 Shared_Libs := True;
5002 Bind_Shared := Shared_Switch'Access;
5003 exit;
5004 end if;
5005 end loop;
5006 end if;
5008 -- Check now for switch -shared
5010 if not Shared_Libs then
5011 for J in Binder_Switches.First .. Last_Arg loop
5012 if Binder_Switches.Table (J).all = "-shared" then
5013 Shared_Libs := True;
5014 exit;
5015 end if;
5016 end loop;
5017 end if;
5019 -- If there are shared libraries, invoke gnatlink with
5020 -- -shared-libgcc if GCC version is 3 or more.
5022 if Shared_Libs and then GCC_Version >= 3 then
5023 Link_With_Shared_Libgcc := Shared_Libgcc_Switch'Access;
5024 end if;
5026 -- Get all the binder switches
5028 for J in Binder_Switches.First .. Last_Arg loop
5029 Args (J) := Binder_Switches.Table (J);
5030 end loop;
5032 if There_Are_Stand_Alone_Libraries then
5033 Last_Arg := Last_Arg + 1;
5034 Args (Last_Arg) := Force_Elab_Flags_String'Access;
5035 end if;
5037 if Main_Project /= No_Project then
5039 -- Put all the source directories in ADA_INCLUDE_PATH,
5040 -- and all the object directories in ADA_OBJECTS_PATH
5042 Prj.Env.Set_Ada_Paths (Main_Project, False);
5044 -- If switch -C was specified, create a binder mapping file
5046 if Create_Mapping_File then
5047 Create_Binder_Mapping_File (Args, Last_Arg);
5048 end if;
5050 end if;
5052 begin
5053 Bind (Main_ALI_File,
5054 Bind_Shared.all & Args (Args'First .. Last_Arg));
5056 exception
5057 when others =>
5059 -- If -dn was not specified, delete the temporary mapping
5060 -- file, if one was created.
5062 if not Debug.Debug_Flag_N
5063 and then Mapping_Path /= No_Name
5064 then
5065 Delete_File (Get_Name_String (Mapping_Path), Discard);
5066 end if;
5068 -- And reraise the exception
5070 raise;
5071 end;
5073 -- If -dn was not specified, delete the temporary mapping file,
5074 -- if one was created.
5076 if not Debug.Debug_Flag_N and then Mapping_Path /= No_Name then
5077 Delete_File (Get_Name_String (Mapping_Path), Discard);
5078 end if;
5079 end Bind_Step;
5080 end if;
5082 if Do_Link_Step then
5083 Link_Step : declare
5084 There_Are_Libraries : Boolean := False;
5085 Linker_Switches_Last : constant Integer := Linker_Switches.Last;
5086 Path_Option : constant String_Access :=
5087 MLib.Linker_Library_Path_Option;
5088 Current : Natural;
5089 Proj2 : Project_Id;
5090 Depth : Natural;
5092 begin
5093 if not Run_Path_Option then
5094 Linker_Switches.Increment_Last;
5095 Linker_Switches.Table (Linker_Switches.Last) :=
5096 new String'("-R");
5097 end if;
5099 if Main_Project /= No_Project then
5100 Library_Paths.Set_Last (0);
5101 Library_Projs.Init;
5103 if MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None then
5104 -- Check for library projects
5106 for Proj1 in 1 .. Projects.Last loop
5107 if Proj1 /= Main_Project
5108 and then Projects.Table (Proj1).Library
5109 then
5110 -- Add this project to table Library_Projs
5112 There_Are_Libraries := True;
5113 Depth := Projects.Table (Proj1).Depth;
5114 Library_Projs.Increment_Last;
5115 Current := Library_Projs.Last;
5117 -- Any project with a greater depth should be
5118 -- after this project in the list.
5120 while Current > 1 loop
5121 Proj2 := Library_Projs.Table (Current - 1);
5122 exit when Projects.Table (Proj2).Depth <= Depth;
5123 Library_Projs.Table (Current) := Proj2;
5124 Current := Current - 1;
5125 end loop;
5127 Library_Projs.Table (Current) := Proj1;
5129 -- If it is not a static library and path option
5130 -- is set, add it to the Library_Paths table.
5132 if Projects.Table (Proj1).Library_Kind /= Static
5133 and then Path_Option /= null
5134 then
5135 Library_Paths.Increment_Last;
5136 Library_Paths.Table (Library_Paths.Last) :=
5137 new String'
5138 (Get_Name_String
5139 (Projects.Table (Proj1).Library_Dir));
5140 end if;
5141 end if;
5142 end loop;
5144 for Index in 1 .. Library_Projs.Last loop
5145 -- Add the -L switch
5147 Linker_Switches.Increment_Last;
5148 Linker_Switches.Table (Linker_Switches.Last) :=
5149 new String'("-L" &
5150 Get_Name_String
5151 (Projects.Table
5152 (Library_Projs.Table (Index)).
5153 Library_Dir));
5155 -- Add the -l switch
5157 Linker_Switches.Increment_Last;
5158 Linker_Switches.Table (Linker_Switches.Last) :=
5159 new String'("-l" &
5160 Get_Name_String
5161 (Projects.Table
5162 (Library_Projs.Table (Index)).
5163 Library_Name));
5164 end loop;
5165 end if;
5167 if There_Are_Libraries then
5169 -- If Path_Option is not null, create the switch
5170 -- ("-Wl,-rpath," or equivalent) with all the non static
5171 -- library dirs plus the standard GNAT library dir.
5172 -- We do that only if Run_Path_Option is True
5173 -- (not disabled by -R switch).
5175 if Run_Path_Option and Path_Option /= null then
5176 declare
5177 Option : String_Access;
5178 Length : Natural := Path_Option'Length;
5179 Current : Natural;
5181 begin
5182 for Index in
5183 Library_Paths.First .. Library_Paths.Last
5184 loop
5185 -- Add the length of the library dir plus one
5186 -- for the directory separator.
5188 Length :=
5189 Length +
5190 Library_Paths.Table (Index)'Length + 1;
5191 end loop;
5193 -- Finally, add the length of the standard GNAT
5194 -- library dir.
5196 Length := Length + MLib.Utl.Lib_Directory'Length;
5197 Option := new String (1 .. Length);
5198 Option (1 .. Path_Option'Length) := Path_Option.all;
5199 Current := Path_Option'Length;
5201 -- Put each library dir followed by a dir separator
5203 for Index in
5204 Library_Paths.First .. Library_Paths.Last
5205 loop
5206 Option
5207 (Current + 1 ..
5208 Current +
5209 Library_Paths.Table (Index)'Length) :=
5210 Library_Paths.Table (Index).all;
5211 Current :=
5212 Current +
5213 Library_Paths.Table (Index)'Length + 1;
5214 Option (Current) := Path_Separator;
5215 end loop;
5217 -- Finally put the standard GNAT library dir
5219 Option
5220 (Current + 1 ..
5221 Current + MLib.Utl.Lib_Directory'Length) :=
5222 MLib.Utl.Lib_Directory;
5224 -- And add the switch to the linker switches
5226 Linker_Switches.Increment_Last;
5227 Linker_Switches.Table (Linker_Switches.Last) :=
5228 Option;
5229 end;
5230 end if;
5232 end if;
5234 -- Put the object directories in ADA_OBJECTS_PATH
5236 Prj.Env.Set_Ada_Paths (Main_Project, False);
5238 -- Check for attributes Linker'Linker_Options in projects
5239 -- other than the main project
5241 declare
5242 Linker_Options : constant String_List :=
5243 Linker_Options_Switches (Main_Project);
5245 begin
5246 for Option in Linker_Options'Range loop
5247 Linker_Switches.Increment_Last;
5248 Linker_Switches.Table (Linker_Switches.Last) :=
5249 Linker_Options (Option);
5250 end loop;
5251 end;
5252 end if;
5254 declare
5255 Args : Argument_List
5256 (Linker_Switches.First .. Linker_Switches.Last + 2);
5258 Last_Arg : Integer := Linker_Switches.First - 1;
5259 Skip : Boolean := False;
5261 begin
5262 -- Get all the linker switches
5264 for J in Linker_Switches.First .. Linker_Switches.Last loop
5265 if Skip then
5266 Skip := False;
5268 elsif Non_Std_Executable
5269 and then Linker_Switches.Table (J).all = "-o"
5270 then
5271 Skip := True;
5273 else
5274 Last_Arg := Last_Arg + 1;
5275 Args (Last_Arg) := Linker_Switches.Table (J);
5276 end if;
5277 end loop;
5279 -- If need be, add the -o switch
5281 if Non_Std_Executable then
5282 Last_Arg := Last_Arg + 1;
5283 Args (Last_Arg) := new String'("-o");
5284 Last_Arg := Last_Arg + 1;
5285 Args (Last_Arg) :=
5286 new String'(Get_Name_String (Executable));
5287 end if;
5289 -- And invoke the linker
5291 begin
5292 Link (Main_ALI_File,
5293 Link_With_Shared_Libgcc.all &
5294 Args (Args'First .. Last_Arg));
5295 Successful_Links.Increment_Last;
5296 Successful_Links.Table (Successful_Links.Last) :=
5297 Main_ALI_File;
5299 exception
5300 when Link_Failed =>
5301 if Osint.Number_Of_Files = 1 or not Keep_Going then
5302 raise;
5304 else
5305 Write_Line ("*** link failed");
5306 Failed_Links.Increment_Last;
5307 Failed_Links.Table (Failed_Links.Last) :=
5308 Main_ALI_File;
5309 end if;
5310 end;
5311 end;
5313 Linker_Switches.Set_Last (Linker_Switches_Last);
5314 end Link_Step;
5315 end if;
5317 -- We go to here when we skip the bind and link steps
5319 <<Next_Main>>
5321 -- We go to the next main, if we did not process the last one
5323 if N_File < Osint.Number_Of_Files then
5324 Main_Source_File := Next_Main_Source;
5326 if Current_File_Index /= No_Index then
5327 Main_Index := Current_File_Index;
5328 end if;
5330 if Main_Project /= No_Project then
5332 -- Find the file name of the main unit
5334 declare
5335 Main_Source_File_Name : constant String :=
5336 Get_Name_String (Main_Source_File);
5338 Main_Unit_File_Name : constant String :=
5339 Prj.Env.
5340 File_Name_Of_Library_Unit_Body
5341 (Name => Main_Source_File_Name,
5342 Project => Main_Project,
5343 Main_Project_Only =>
5344 not Unique_Compile);
5346 The_Packages : constant Package_Id :=
5347 Projects.Table (Main_Project).Decl.Packages;
5349 Binder_Package : constant Prj.Package_Id :=
5350 Prj.Util.Value_Of
5351 (Name => Name_Binder,
5352 In_Packages => The_Packages);
5354 Linker_Package : constant Prj.Package_Id :=
5355 Prj.Util.Value_Of
5356 (Name => Name_Linker,
5357 In_Packages => The_Packages);
5359 begin
5360 -- We fail if we cannot find the main source file
5361 -- as an immediate source of the main project file.
5363 if Main_Unit_File_Name = "" then
5364 Make_Failed ('"' & Main_Source_File_Name,
5365 """ is not a unit of project ",
5366 Project_File_Name.all & ".");
5368 else
5369 -- Remove any directory information from the main
5370 -- source file name.
5372 declare
5373 Pos : Natural := Main_Unit_File_Name'Last;
5375 begin
5376 loop
5377 exit when Pos < Main_Unit_File_Name'First
5378 or else
5379 Main_Unit_File_Name (Pos) = Directory_Separator;
5380 Pos := Pos - 1;
5381 end loop;
5383 Name_Len := Main_Unit_File_Name'Last - Pos;
5385 Name_Buffer (1 .. Name_Len) :=
5386 Main_Unit_File_Name
5387 (Pos + 1 .. Main_Unit_File_Name'Last);
5389 Main_Source_File := Name_Find;
5390 end;
5391 end if;
5393 -- We now deal with the binder and linker switches.
5394 -- If no project file is used, there is nothing to do
5395 -- because the binder and linker switches are the same
5396 -- for all mains.
5398 -- Reset the tables Binder_Switches and Linker_Switches
5400 Binder_Switches.Set_Last (Last_Binder_Switch);
5401 Linker_Switches.Set_Last (Last_Linker_Switch);
5403 -- Add binder switches from the project file for this main,
5404 -- if any.
5406 if Do_Bind_Step and Binder_Package /= No_Package then
5407 if Verbose_Mode then
5408 Write_Str ("Adding binder switches for """);
5409 Write_Str (Main_Unit_File_Name);
5410 Write_Line (""".");
5411 end if;
5413 Add_Switches
5414 (File_Name => Main_Unit_File_Name,
5415 Index => Main_Index,
5416 The_Package => Binder_Package,
5417 Program => Binder);
5418 end if;
5420 -- Add linker switches from the project file for this main,
5421 -- if any.
5423 if Do_Link_Step and Linker_Package /= No_Package then
5424 if Verbose_Mode then
5425 Write_Str ("Adding linker switches for""");
5426 Write_Str (Main_Unit_File_Name);
5427 Write_Line (""".");
5428 end if;
5430 Add_Switches
5431 (File_Name => Main_Unit_File_Name,
5432 Index => Main_Index,
5433 The_Package => Linker_Package,
5434 Program => Linker);
5435 end if;
5437 -- As we are using a project file, for relative paths we add
5438 -- the current working directory for any relative path on
5439 -- the command line and the project directory, for any
5440 -- relative path in the project file.
5442 declare
5443 Dir_Path : constant String_Access :=
5444 new String'(Get_Name_String
5445 (Projects.Table (Main_Project).Directory));
5446 begin
5448 J in Last_Binder_Switch + 1 .. Binder_Switches.Last
5449 loop
5450 Test_If_Relative_Path
5451 (Binder_Switches.Table (J),
5452 Parent => Dir_Path, Including_L_Switch => False);
5453 end loop;
5456 J in Last_Linker_Switch + 1 .. Linker_Switches.Last
5457 loop
5458 Test_If_Relative_Path
5459 (Linker_Switches.Table (J), Parent => Dir_Path);
5460 end loop;
5461 end;
5463 -- We now put in the Binder_Switches and Linker_Switches
5464 -- tables, the binder and linker switches of the command
5465 -- line that have been put in the Saved_ tables.
5466 -- These switches will follow the project file switches.
5468 for J in 1 .. Saved_Binder_Switches.Last loop
5469 Add_Switch
5470 (Saved_Binder_Switches.Table (J),
5471 Binder,
5472 And_Save => False);
5473 end loop;
5475 for J in 1 .. Saved_Linker_Switches.Last loop
5476 Add_Switch
5477 (Saved_Linker_Switches.Table (J),
5478 Linker,
5479 And_Save => False);
5480 end loop;
5481 end;
5482 end if;
5483 end if;
5485 -- Remove all marks to be sure to check sources for all executables,
5486 -- as the switches may be different and -s may be in use.
5488 Delete_All_Marks;
5489 end loop Multiple_Main_Loop;
5491 if Failed_Links.Last > 0 then
5492 for Index in 1 .. Successful_Links.Last loop
5493 Write_Str ("Linking of """);
5494 Write_Str (Get_Name_String (Successful_Links.Table (Index)));
5495 Write_Line (""" succeeded.");
5496 end loop;
5498 for Index in 1 .. Failed_Links.Last loop
5499 Write_Str ("Linking of """);
5500 Write_Str (Get_Name_String (Failed_Links.Table (Index)));
5501 Write_Line (""" failed.");
5502 end loop;
5504 if Total_Compilation_Failures = 0 then
5505 raise Compilation_Failed;
5506 end if;
5507 end if;
5509 if Total_Compilation_Failures /= 0 then
5510 List_Bad_Compilations;
5511 raise Compilation_Failed;
5512 end if;
5514 -- Delete the temporary mapping file that was created if we are
5515 -- using project files.
5517 if not Debug.Debug_Flag_N then
5518 Delete_Mapping_Files;
5519 Prj.Env.Delete_All_Path_Files;
5520 end if;
5522 Exit_Program (E_Success);
5524 exception
5525 when Bind_Failed =>
5526 Make_Failed ("*** bind failed.");
5528 when Compilation_Failed =>
5529 if not Debug.Debug_Flag_N then
5530 Delete_Mapping_Files;
5531 Prj.Env.Delete_All_Path_Files;
5532 end if;
5534 Exit_Program (E_Fatal);
5536 when Link_Failed =>
5537 Make_Failed ("*** link failed.");
5539 when X : others =>
5540 Write_Line (Exception_Information (X));
5541 Make_Failed ("INTERNAL ERROR. Please report.");
5542 end Gnatmake;
5544 ----------
5545 -- Hash --
5546 ----------
5548 function Hash (F : Name_Id) return Header_Num is
5549 begin
5550 return Header_Num (1 + F mod Max_Header);
5551 end Hash;
5553 --------------------
5554 -- In_Ada_Lib_Dir --
5555 --------------------
5557 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean is
5558 D : constant Name_Id := Get_Directory (File);
5559 B : constant Byte := Get_Name_Table_Byte (D);
5560 begin
5561 return (B and Ada_Lib_Dir) /= 0;
5562 end In_Ada_Lib_Dir;
5564 ------------
5565 -- Inform --
5566 ------------
5568 procedure Inform (N : Name_Id := No_Name; Msg : String) is
5569 begin
5570 Osint.Write_Program_Name;
5572 Write_Str (": ");
5574 if N /= No_Name then
5575 Write_Str ("""");
5576 Write_Name (N);
5577 Write_Str (""" ");
5578 end if;
5580 Write_Str (Msg);
5581 Write_Eol;
5582 end Inform;
5584 -----------------------
5585 -- Init_Mapping_File --
5586 -----------------------
5588 procedure Init_Mapping_File
5589 (Project : Project_Id;
5590 File_Index : in out Natural)
5592 FD : File_Descriptor;
5594 Status : Boolean;
5595 -- For call to Close
5597 begin
5598 -- Increase the index of the last mapping file for this project
5600 Last_Mapping_File_Names (Project) :=
5601 Last_Mapping_File_Names (Project) + 1;
5603 -- If there is a project file, call Create_Mapping_File with
5604 -- the project id.
5606 if Project /= No_Project then
5607 Prj.Env.Create_Mapping_File
5608 (Project,
5609 The_Mapping_File_Names
5610 (Project, Last_Mapping_File_Names (Project)));
5612 -- Otherwise, just create an empty file
5614 else
5615 Tempdir.Create_Temp_File
5616 (FD,
5617 The_Mapping_File_Names
5618 (No_Project, Last_Mapping_File_Names (No_Project)));
5619 if FD = Invalid_FD then
5620 Make_Failed ("disk full");
5621 end if;
5623 Close (FD, Status);
5625 if not Status then
5626 Make_Failed ("disk full");
5627 end if;
5628 end if;
5630 -- And return the index of the newly created file
5632 File_Index := Last_Mapping_File_Names (Project);
5633 end Init_Mapping_File;
5635 ------------
5636 -- Init_Q --
5637 ------------
5639 procedure Init_Q is
5640 begin
5641 First_Q_Initialization := False;
5642 Q_Front := Q.First;
5643 Q.Set_Last (Q.First);
5644 end Init_Q;
5646 ----------------
5647 -- Initialize --
5648 ----------------
5650 procedure Initialize is
5651 begin
5652 -- Override default initialization of Check_Object_Consistency
5653 -- since this is normally False for GNATBIND, but is True for
5654 -- GNATMAKE since we do not need to check source consistency
5655 -- again once GNATMAKE has looked at the sources to check.
5657 Check_Object_Consistency := True;
5659 -- Package initializations. The order of calls is important here
5661 Output.Set_Standard_Error;
5663 Gcc_Switches.Init;
5664 Binder_Switches.Init;
5665 Linker_Switches.Init;
5667 Csets.Initialize;
5668 Namet.Initialize;
5670 Snames.Initialize;
5672 Prj.Initialize;
5674 Dependencies.Init;
5676 RTS_Specified := null;
5678 Mains.Delete;
5680 -- Add the directory where gnatmake is invoked in front of the
5681 -- path, if gnatmake is invoked with directory information.
5682 -- Only do this if the platform is not VMS, where the notion of path
5683 -- does not really exist.
5685 if not OpenVMS then
5686 declare
5687 Command : constant String := Command_Name;
5689 begin
5690 for Index in reverse Command'Range loop
5691 if Command (Index) = Directory_Separator then
5692 declare
5693 Absolute_Dir : constant String :=
5694 Normalize_Pathname
5695 (Command (Command'First .. Index));
5697 PATH : constant String :=
5698 Absolute_Dir &
5699 Path_Separator &
5700 Getenv ("PATH").all;
5702 begin
5703 Setenv ("PATH", PATH);
5704 end;
5706 exit;
5707 end if;
5708 end loop;
5709 end;
5710 end if;
5712 -- Scan the switches and arguments
5714 Scan_Args : for Next_Arg in 1 .. Argument_Count loop
5715 Scan_Make_Arg (Argument (Next_Arg), And_Save => True);
5716 end loop Scan_Args;
5718 if Usage_Requested then
5719 Usage;
5720 end if;
5722 -- Test for trailing -P switch
5724 if Project_File_Name_Present and then Project_File_Name = null then
5725 Make_Failed ("project file name missing after -P");
5727 -- Test for trailing -o switch
5729 elsif Output_File_Name_Present
5730 and then not Output_File_Name_Seen
5731 then
5732 Make_Failed ("output file name missing after -o");
5734 -- Test for trailing -D switch
5736 elsif Object_Directory_Present
5737 and then not Object_Directory_Seen then
5738 Make_Failed ("object directory missing after -D");
5739 end if;
5741 -- Test for simultaneity of -i and -D
5743 if Object_Directory_Path /= null and then In_Place_Mode then
5744 Make_Failed ("-i and -D cannot be used simutaneously");
5745 end if;
5747 -- Deal with -C= switch
5749 if Gnatmake_Mapping_File /= null then
5750 -- First, check compatibility with other switches
5752 if Project_File_Name /= null then
5753 Make_Failed ("-C= switch is not compatible with -P switch");
5755 elsif Saved_Maximum_Processes > 1 then
5756 Make_Failed ("-C= switch is not compatible with -jnnn switch");
5757 end if;
5759 Fmap.Initialize (Gnatmake_Mapping_File.all);
5760 Add_Switch
5761 ("-gnatem=" & Gnatmake_Mapping_File.all,
5762 Compiler,
5763 And_Save => True);
5764 end if;
5766 if Project_File_Name /= null then
5768 -- A project file was specified by a -P switch
5770 if Verbose_Mode then
5771 Write_Eol;
5772 Write_Str ("Parsing Project File """);
5773 Write_Str (Project_File_Name.all);
5774 Write_Str (""".");
5775 Write_Eol;
5776 end if;
5778 -- Avoid looking in the current directory for ALI files
5780 -- Look_In_Primary_Dir := False;
5782 -- Set the project parsing verbosity to whatever was specified
5783 -- by a possible -vP switch.
5785 Prj.Pars.Set_Verbosity (To => Current_Verbosity);
5787 -- Parse the project file.
5788 -- If there is an error, Main_Project will still be No_Project.
5790 Prj.Pars.Parse
5791 (Project => Main_Project,
5792 Project_File_Name => Project_File_Name.all,
5793 Packages_To_Check => Packages_To_Check_By_Gnatmake);
5795 if Main_Project = No_Project then
5796 Make_Failed ("""", Project_File_Name.all, """ processing failed");
5797 end if;
5799 if Verbose_Mode then
5800 Write_Eol;
5801 Write_Str ("Parsing of Project File """);
5802 Write_Str (Project_File_Name.all);
5803 Write_Str (""" is finished.");
5804 Write_Eol;
5805 end if;
5807 -- We add the source directories and the object directories
5808 -- to the search paths.
5810 Add_Source_Directories (Main_Project);
5811 Add_Object_Directories (Main_Project);
5813 -- Compute depth of each project
5815 for Proj in 1 .. Projects.Last loop
5816 Projects.Table (Proj).Seen := False;
5817 Projects.Table (Proj).Depth := 0;
5818 end loop;
5820 Recursive_Compute_Depth
5821 (Main_Project, Depth => 1);
5823 else
5825 Osint.Add_Default_Search_Dirs;
5827 -- Source file lookups should be cached for efficiency.
5828 -- Source files are not supposed to change. However, we do that now
5829 -- only if no project file is used; if a project file is used, we
5830 -- do it just after changing the directory to the object directory.
5832 Osint.Source_File_Data (Cache => True);
5834 -- Read gnat.adc file to initialize Fname.UF
5836 Fname.UF.Initialize;
5838 begin
5839 Fname.SF.Read_Source_File_Name_Pragmas;
5841 exception
5842 when Err : SFN_Scan.Syntax_Error_In_GNAT_ADC =>
5843 Make_Failed (Exception_Message (Err));
5844 end;
5845 end if;
5847 -- Make sure no project object directory is recorded
5849 Project_Object_Directory := No_Project;
5851 end Initialize;
5853 ----------------------------
5854 -- Insert_Project_Sources --
5855 ----------------------------
5857 procedure Insert_Project_Sources
5858 (The_Project : Project_Id;
5859 All_Projects : Boolean;
5860 Into_Q : Boolean)
5862 Put_In_Q : Boolean := Into_Q;
5863 Unit : Com.Unit_Data;
5864 Sfile : Name_Id;
5866 Extending : constant Boolean :=
5867 Projects.Table (The_Project).Extends /= No_Project;
5869 function Check_Project (P : Project_Id) return Boolean;
5870 -- Returns True if P is The_Project or a project extended by
5871 -- The_Project.
5873 -------------------
5874 -- Check_Project --
5875 -------------------
5877 function Check_Project (P : Project_Id) return Boolean is
5878 begin
5879 if All_Projects or P = The_Project then
5880 return True;
5881 elsif Extending then
5882 declare
5883 Data : Project_Data := Projects.Table (The_Project);
5885 begin
5886 loop
5887 if P = Data.Extends then
5888 return True;
5889 end if;
5891 Data := Projects.Table (Data.Extends);
5892 exit when Data.Extends = No_Project;
5893 end loop;
5894 end;
5895 end if;
5897 return False;
5898 end Check_Project;
5900 -- Start of processing of Insert_Project_Sources
5902 begin
5903 -- For all the sources in the project files,
5905 for Id in Com.Units.First .. Com.Units.Last loop
5906 Unit := Com.Units.Table (Id);
5907 Sfile := No_Name;
5909 -- If there is a source for the body, and the body has not been
5910 -- locally removed,
5912 if Unit.File_Names (Com.Body_Part).Name /= No_Name
5913 and then Unit.File_Names (Com.Body_Part).Path /= Slash
5914 then
5916 -- And it is a source for the specified project
5918 if Check_Project (Unit.File_Names (Com.Body_Part).Project) then
5920 -- If we don't have a spec, we cannot consider the source
5921 -- if it is a subunit
5923 if Unit.File_Names (Com.Specification).Name = No_Name then
5924 declare
5925 Src_Ind : Source_File_Index;
5927 -- Here we are cheating a little bit: we don't want to
5928 -- use Sinput.L, because it depends on the GNAT tree
5929 -- (Atree, Sinfo, ...). So, we pretend that it is
5930 -- a project file, and we use Sinput.P.
5931 -- Source_File_Is_Subunit is just scanning through
5932 -- the file until it finds one of the reserved words
5933 -- separate, procedure, function, generic or package.
5934 -- Fortunately, these Ada reserved words are also
5935 -- reserved for project files.
5937 begin
5938 Src_Ind := Sinput.P.Load_Project_File
5939 (Get_Name_String
5940 (Unit.File_Names (Com.Body_Part).Path));
5942 -- If it is a subunit, discard it
5944 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
5945 Sfile := No_Name;
5947 else
5948 Sfile := Unit.File_Names (Com.Body_Part).Name;
5949 end if;
5950 end;
5952 else
5953 Sfile := Unit.File_Names (Com.Body_Part).Name;
5954 end if;
5955 end if;
5957 elsif Unit.File_Names (Com.Specification).Name /= No_Name
5958 and then Unit.File_Names (Com.Specification).Path /= Slash
5959 and then Check_Project (Unit.File_Names (Com.Specification).Project)
5960 then
5961 -- If there is no source for the body, but there is a source
5962 -- for the spec which has not been locally removed, then we take
5963 -- this one.
5965 Sfile := Unit.File_Names (Com.Specification).Name;
5966 end if;
5968 -- If Put_In_Q is True, we insert into the Q
5970 if Put_In_Q then
5972 -- For the first source inserted into the Q, we need
5973 -- to initialize the Q, but not for the subsequent sources.
5975 if First_Q_Initialization then
5976 Init_Q;
5977 end if;
5979 -- And of course, we only insert in the Q if the source
5980 -- is not marked.
5982 if Sfile /= No_Name and then not Is_Marked (Sfile) then
5983 if Verbose_Mode then
5984 Write_Str ("Adding """);
5985 Write_Str (Get_Name_String (Sfile));
5986 Write_Line (""" to the queue");
5987 end if;
5989 Insert_Q (Sfile);
5990 Mark (Sfile);
5991 end if;
5993 elsif Sfile /= No_Name then
5995 -- If Put_In_Q is False, we add the source as it it were
5996 -- specified on the command line, and we set Put_In_Q to True,
5997 -- so that the following sources will be put directly in the
5998 -- queue. This will allow parallel compilation processes if -jx
5999 -- switch is used.
6001 if Verbose_Mode then
6002 Write_Str ("Adding """);
6003 Write_Str (Get_Name_String (Sfile));
6004 Write_Line (""" as if on the command line");
6005 end if;
6007 Osint.Add_File (Get_Name_String (Sfile));
6008 Put_In_Q := True;
6009 end if;
6010 end loop;
6011 end Insert_Project_Sources;
6013 --------------
6014 -- Insert_Q --
6015 --------------
6017 procedure Insert_Q
6018 (Source_File : File_Name_Type;
6019 Source_Unit : Unit_Name_Type := No_Name;
6020 Index : Int := 0)
6022 begin
6023 if Debug.Debug_Flag_Q then
6024 Write_Str (" Q := Q + [ ");
6025 Write_Name (Source_File);
6027 if Index /= 0 then
6028 Write_Str (", ");
6029 Write_Int (Index);
6030 end if;
6032 Write_Str (" ] ");
6033 Write_Eol;
6034 end if;
6036 Q.Table (Q.Last) :=
6037 (File => Source_File,
6038 Unit => Source_Unit,
6039 Index => Index);
6040 Q.Increment_Last;
6041 end Insert_Q;
6043 ---------------------
6044 -- Is_In_Obsoleted --
6045 ---------------------
6047 function Is_In_Obsoleted (F : Name_Id) return Boolean is
6048 begin
6049 if F = No_File then
6050 return False;
6052 else
6053 declare
6054 Name : constant String := Get_Name_String (F);
6055 First : Natural := Name'Last;
6056 F2 : Name_Id := F;
6058 begin
6059 while First > Name'First
6060 and then Name (First - 1) /= Directory_Separator
6061 and then Name (First - 1) /= '/'
6062 loop
6063 First := First - 1;
6064 end loop;
6066 if First /= Name'First then
6067 Name_Len := 0;
6068 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
6069 F2 := Name_Find;
6070 end if;
6072 return Obsoleted.Get (F2);
6073 end;
6074 end if;
6075 end Is_In_Obsoleted;
6077 ----------------------------
6078 -- Is_In_Object_Directory --
6079 ----------------------------
6081 function Is_In_Object_Directory
6082 (Source_File : File_Name_Type;
6083 Full_Lib_File : File_Name_Type) return Boolean
6085 begin
6086 -- There is something to check only when using project files.
6087 -- Otherwise, this function returns True (last line of the function).
6089 if Main_Project /= No_Project then
6090 declare
6091 Source_File_Name : constant String :=
6092 Get_Name_String (Source_File);
6093 Saved_Verbosity : constant Verbosity := Prj.Com.Current_Verbosity;
6094 Project : Project_Id := No_Project;
6095 Path_Name : Name_Id := No_Name;
6096 Data : Project_Data;
6098 begin
6099 -- Call Get_Reference to know the ultimate extending project of
6100 -- the source. Call it with verbosity default to avoid verbose
6101 -- messages.
6103 Prj.Com.Current_Verbosity := Default;
6104 Prj.Env.
6105 Get_Reference
6106 (Source_File_Name => Source_File_Name,
6107 Project => Project,
6108 Path => Path_Name);
6109 Prj.Com.Current_Verbosity := Saved_Verbosity;
6111 -- If this source is in a project, check that the ALI file is
6112 -- in its object directory. If it is not, return False, so that
6113 -- the ALI file will not be skipped.
6115 -- If the source is not in an extending project, we fall back to
6116 -- the general case and return True at the end of the function.
6118 if Project /= No_Project
6119 and then Projects.Table (Project).Extends /= No_Project
6120 then
6121 Data := Projects.Table (Project);
6123 declare
6124 Object_Directory : constant String :=
6125 Normalize_Pathname
6126 (Get_Name_String
6127 (Data.Object_Directory));
6129 Olast : Natural := Object_Directory'Last;
6131 Lib_File_Directory : constant String :=
6132 Normalize_Pathname (Dir_Name
6133 (Get_Name_String (Full_Lib_File)));
6135 Llast : Natural := Lib_File_Directory'Last;
6137 begin
6138 -- For directories, Normalize_Pathname may or may not put
6139 -- a directory separator at the end, depending on its input.
6140 -- Remove any last directory separator before comparaison.
6141 -- Returns True only if the two directories are the same.
6143 if Object_Directory (Olast) = Directory_Separator then
6144 Olast := Olast - 1;
6145 end if;
6147 if Lib_File_Directory (Llast) = Directory_Separator then
6148 Llast := Llast - 1;
6149 end if;
6151 return Object_Directory (Object_Directory'First .. Olast) =
6152 Lib_File_Directory (Lib_File_Directory'First .. Llast);
6153 end;
6154 end if;
6155 end;
6156 end if;
6158 -- When the source is not in a project file, always return True
6160 return True;
6161 end Is_In_Object_Directory;
6163 ----------
6164 -- Link --
6165 ----------
6167 procedure Link (ALI_File : File_Name_Type; Args : Argument_List) is
6168 Link_Args : Argument_List (1 .. Args'Length + 1);
6169 Success : Boolean;
6171 begin
6172 Get_Name_String (ALI_File);
6173 Link_Args (1) := new String'(Name_Buffer (1 .. Name_Len));
6175 Link_Args (2 .. Args'Length + 1) := Args;
6177 GNAT.OS_Lib.Normalize_Arguments (Link_Args);
6179 Display (Gnatlink.all, Link_Args);
6181 if Gnatlink_Path = null then
6182 Make_Failed ("error, unable to locate ", Gnatlink.all);
6183 end if;
6185 GNAT.OS_Lib.Spawn (Gnatlink_Path.all, Link_Args, Success);
6187 if not Success then
6188 raise Link_Failed;
6189 end if;
6190 end Link;
6192 ---------------------------
6193 -- List_Bad_Compilations --
6194 ---------------------------
6196 procedure List_Bad_Compilations is
6197 begin
6198 for J in Bad_Compilation.First .. Bad_Compilation.Last loop
6199 if Bad_Compilation.Table (J).File = No_File then
6200 null;
6201 elsif not Bad_Compilation.Table (J).Found then
6202 Inform (Bad_Compilation.Table (J).File, "not found");
6203 else
6204 Inform (Bad_Compilation.Table (J).File, "compilation error");
6205 end if;
6206 end loop;
6207 end List_Bad_Compilations;
6209 -----------------
6210 -- List_Depend --
6211 -----------------
6213 procedure List_Depend is
6214 Lib_Name : Name_Id;
6215 Obj_Name : Name_Id;
6216 Src_Name : Name_Id;
6218 Len : Natural;
6219 Line_Pos : Natural;
6220 Line_Size : constant := 77;
6222 begin
6223 Set_Standard_Output;
6225 for A in ALIs.First .. ALIs.Last loop
6226 Lib_Name := ALIs.Table (A).Afile;
6228 -- We have to provide the full library file name in In_Place_Mode
6230 if In_Place_Mode then
6231 Lib_Name := Full_Lib_File_Name (Lib_Name);
6232 end if;
6234 Obj_Name := Object_File_Name (Lib_Name);
6235 Write_Name (Obj_Name);
6236 Write_Str (" :");
6238 Get_Name_String (Obj_Name);
6239 Len := Name_Len;
6240 Line_Pos := Len + 2;
6242 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
6243 Src_Name := Sdep.Table (D).Sfile;
6245 if Is_Internal_File_Name (Src_Name)
6246 and then not Check_Readonly_Files
6247 then
6248 null;
6249 else
6250 if not Quiet_Output then
6251 Src_Name := Full_Source_Name (Src_Name);
6252 end if;
6254 Get_Name_String (Src_Name);
6255 Len := Name_Len;
6257 if Line_Pos + Len + 1 > Line_Size then
6258 Write_Str (" \");
6259 Write_Eol;
6260 Line_Pos := 0;
6261 end if;
6263 Line_Pos := Line_Pos + Len + 1;
6265 Write_Str (" ");
6266 Write_Name (Src_Name);
6267 end if;
6268 end loop;
6270 Write_Eol;
6271 end loop;
6273 Set_Standard_Error;
6274 end List_Depend;
6276 -----------------
6277 -- Make_Failed --
6278 -----------------
6280 procedure Make_Failed (S1 : String; S2 : String := ""; S3 : String := "") is
6281 begin
6282 Delete_All_Temp_Files;
6283 Osint.Fail (S1, S2, S3);
6284 end Make_Failed;
6286 --------------------
6287 -- Mark_Directory --
6288 --------------------
6290 procedure Mark_Directory
6291 (Dir : String;
6292 Mark : Lib_Mark_Type)
6294 N : Name_Id;
6295 B : Byte;
6297 begin
6298 -- Dir last character is supposed to be a directory separator
6300 Name_Len := Dir'Length;
6301 Name_Buffer (1 .. Name_Len) := Dir;
6303 if not Is_Directory_Separator (Name_Buffer (Name_Len)) then
6304 Name_Len := Name_Len + 1;
6305 Name_Buffer (Name_Len) := Directory_Separator;
6306 end if;
6308 -- Add flags to the already existing flags
6310 N := Name_Find;
6311 B := Get_Name_Table_Byte (N);
6312 Set_Name_Table_Byte (N, B or Mark);
6313 end Mark_Directory;
6315 -----------------------------
6316 -- Recursive_Compute_Depth --
6317 -----------------------------
6319 procedure Recursive_Compute_Depth
6320 (Project : Project_Id;
6321 Depth : Natural)
6323 List : Project_List;
6324 Proj : Project_Id;
6326 begin
6327 -- Nothing to do if there is no project or if the project has already
6328 -- been seen or if the depth is large enough.
6330 if Project = No_Project
6331 or else Projects.Table (Project).Seen
6332 or else Projects.Table (Project).Depth >= Depth
6333 then
6334 return;
6335 end if;
6337 Projects.Table (Project).Depth := Depth;
6339 -- Mark the project as Seen to avoid endless loop caused by limited
6340 -- withs.
6342 Projects.Table (Project).Seen := True;
6344 List := Projects.Table (Project).Imported_Projects;
6346 -- Visit each imported project
6348 while List /= Empty_Project_List loop
6349 Proj := Project_Lists.Table (List).Project;
6350 List := Project_Lists.Table (List).Next;
6351 Recursive_Compute_Depth
6352 (Project => Proj,
6353 Depth => Depth + 1);
6354 end loop;
6356 -- Visit a project being extended, if any
6358 Recursive_Compute_Depth
6359 (Project => Projects.Table (Project).Extends,
6360 Depth => Depth + 1);
6362 -- Reset the Seen flag, as we leave this project
6364 Projects.Table (Project).Seen := False;
6365 end Recursive_Compute_Depth;
6367 -----------------------
6368 -- Sigint_Intercpted --
6369 -----------------------
6371 procedure Sigint_Intercepted is
6372 begin
6373 Write_Line ("*** Interrupted ***");
6374 Delete_All_Temp_Files;
6375 OS_Exit (1);
6376 end Sigint_Intercepted;
6378 -------------------
6379 -- Scan_Make_Arg --
6380 -------------------
6382 procedure Scan_Make_Arg (Argv : String; And_Save : Boolean) is
6383 begin
6384 pragma Assert (Argv'First = 1);
6386 if Argv'Length = 0 then
6387 return;
6388 end if;
6390 -- If the previous switch has set the Project_File_Name_Present
6391 -- flag (that is we have seen a -P alone), then the next argument is
6392 -- the name of the project file.
6394 if Project_File_Name_Present and then Project_File_Name = null then
6395 if Argv (1) = '-' then
6396 Make_Failed ("project file name missing after -P");
6398 else
6399 Project_File_Name_Present := False;
6400 Project_File_Name := new String'(Argv);
6401 end if;
6403 -- If the previous switch has set the Output_File_Name_Present
6404 -- flag (that is we have seen a -o), then the next argument is
6405 -- the name of the output executable.
6407 elsif Output_File_Name_Present
6408 and then not Output_File_Name_Seen
6409 then
6410 Output_File_Name_Seen := True;
6412 if Argv (1) = '-' then
6413 Make_Failed ("output file name missing after -o");
6415 else
6416 Add_Switch ("-o", Linker, And_Save => And_Save);
6418 -- Automatically add the executable suffix if it has not been
6419 -- specified explicitly.
6421 declare
6422 Canonical_Argv : String := Argv;
6423 begin
6424 -- Get the file name in canonical case to accept as is
6425 -- names ending with ".EXE" on VMS and Windows.
6427 Canonical_Case_File_Name (Canonical_Argv);
6429 if Executable_Suffix'Length /= 0
6430 and then (Canonical_Argv'Length <= Executable_Suffix'Length
6431 or else Canonical_Argv
6432 (Canonical_Argv'Last -
6433 Executable_Suffix'Length + 1
6434 .. Canonical_Argv'Last)
6435 /= Executable_Suffix)
6436 then
6437 Add_Switch
6438 (Argv & Executable_Suffix,
6439 Linker,
6440 And_Save => And_Save);
6441 else
6442 Add_Switch (Argv, Linker, And_Save => And_Save);
6443 end if;
6444 end;
6445 end if;
6447 -- If the previous switch has set the Object_Directory_Present flag
6448 -- (that is we have seen a -D), then the next argument is
6449 -- the path name of the object directory..
6451 elsif Object_Directory_Present
6452 and then not Object_Directory_Seen
6453 then
6454 Object_Directory_Seen := True;
6456 if Argv (1) = '-' then
6457 Make_Failed ("object directory path name missing after -D");
6459 elsif not Is_Directory (Argv) then
6460 Make_Failed ("cannot find object directory """, Argv, """");
6462 else
6463 Add_Lib_Search_Dir (Argv);
6465 -- Specify the object directory to the binder
6467 Add_Switch ("-aO" & Argv, Binder, And_Save => And_Save);
6469 -- Record the object directory. Make sure it ends with a directory
6470 -- separator.
6472 if Argv (Argv'Last) = Directory_Separator then
6473 Object_Directory_Path := new String'(Argv);
6475 else
6476 Object_Directory_Path :=
6477 new String'(Argv & Directory_Separator);
6478 end if;
6479 end if;
6481 -- Then check if we are dealing with -cargs/-bargs/-largs/-margs
6483 elsif Argv = "-bargs"
6484 or else
6485 Argv = "-cargs"
6486 or else
6487 Argv = "-largs"
6488 or else
6489 Argv = "-margs"
6490 then
6491 case Argv (2) is
6492 when 'c' => Program_Args := Compiler;
6493 when 'b' => Program_Args := Binder;
6494 when 'l' => Program_Args := Linker;
6495 when 'm' => Program_Args := None;
6497 when others =>
6498 raise Program_Error;
6499 end case;
6501 -- A special test is needed for the -o switch within a -largs
6502 -- since that is another way to specify the name of the final
6503 -- executable.
6505 elsif Program_Args = Linker
6506 and then Argv = "-o"
6507 then
6508 Make_Failed ("switch -o not allowed within a -largs. " &
6509 "Use -o directly.");
6511 -- Check to see if we are reading switches after a -cargs,
6512 -- -bargs or -largs switch. If yes save it.
6514 elsif Program_Args /= None then
6516 -- Check to see if we are reading -I switches in order
6517 -- to take into account in the src & lib search directories.
6519 if Argv'Length > 2 and then Argv (1 .. 2) = "-I" then
6520 if Argv (3 .. Argv'Last) = "-" then
6521 Look_In_Primary_Dir := False;
6523 elsif Program_Args = Compiler then
6524 if Argv (3 .. Argv'Last) /= "-" then
6525 Add_Src_Search_Dir (Argv (3 .. Argv'Last));
6526 end if;
6528 elsif Program_Args = Binder then
6529 Add_Lib_Search_Dir (Argv (3 .. Argv'Last));
6530 end if;
6531 end if;
6533 Add_Switch (Argv, Program_Args, And_Save => And_Save);
6535 -- Handle non-default compiler, binder, linker, and handle --RTS switch
6537 elsif Argv'Length > 2 and then Argv (1 .. 2) = "--" then
6538 if Argv'Length > 6
6539 and then Argv (1 .. 6) = "--GCC="
6540 then
6541 declare
6542 Program_Args : constant Argument_List_Access :=
6543 Argument_String_To_List
6544 (Argv (7 .. Argv'Last));
6546 begin
6547 if And_Save then
6548 Saved_Gcc := new String'(Program_Args.all (1).all);
6549 else
6550 Gcc := new String'(Program_Args.all (1).all);
6551 end if;
6553 for J in 2 .. Program_Args.all'Last loop
6554 Add_Switch
6555 (Program_Args.all (J).all,
6556 Compiler,
6557 And_Save => And_Save);
6558 end loop;
6559 end;
6561 elsif Argv'Length > 11
6562 and then Argv (1 .. 11) = "--GNATBIND="
6563 then
6564 declare
6565 Program_Args : constant Argument_List_Access :=
6566 Argument_String_To_List
6567 (Argv (12 .. Argv'Last));
6569 begin
6570 if And_Save then
6571 Saved_Gnatbind := new String'(Program_Args.all (1).all);
6572 else
6573 Gnatbind := new String'(Program_Args.all (1).all);
6574 end if;
6576 for J in 2 .. Program_Args.all'Last loop
6577 Add_Switch
6578 (Program_Args.all (J).all, Binder, And_Save => And_Save);
6579 end loop;
6580 end;
6582 elsif Argv'Length > 11
6583 and then Argv (1 .. 11) = "--GNATLINK="
6584 then
6585 declare
6586 Program_Args : constant Argument_List_Access :=
6587 Argument_String_To_List
6588 (Argv (12 .. Argv'Last));
6589 begin
6590 if And_Save then
6591 Saved_Gnatlink := new String'(Program_Args.all (1).all);
6592 else
6593 Gnatlink := new String'(Program_Args.all (1).all);
6594 end if;
6596 for J in 2 .. Program_Args.all'Last loop
6597 Add_Switch (Program_Args.all (J).all, Linker);
6598 end loop;
6599 end;
6601 elsif Argv'Length >= 5 and then
6602 Argv (1 .. 5) = "--RTS"
6603 then
6604 Add_Switch (Argv, Compiler, And_Save => And_Save);
6605 Add_Switch (Argv, Binder, And_Save => And_Save);
6607 if Argv'Length <= 6 or else Argv (6) /= '=' then
6608 Make_Failed ("missing path for --RTS");
6610 else
6611 -- Check that this is the first time we see this switch or
6612 -- if it is not the first time, the same path is specified.
6614 if RTS_Specified = null then
6615 RTS_Specified := new String'(Argv (7 .. Argv'Last));
6617 elsif RTS_Specified.all /= Argv (7 .. Argv'Last) then
6618 Make_Failed ("--RTS cannot be specified multiple times");
6619 end if;
6621 -- Valid --RTS switch
6623 No_Stdinc := True;
6624 No_Stdlib := True;
6625 RTS_Switch := True;
6627 declare
6628 Src_Path_Name : constant String_Ptr :=
6629 Get_RTS_Search_Dir
6630 (Argv (7 .. Argv'Last), Include);
6632 Lib_Path_Name : constant String_Ptr :=
6633 Get_RTS_Search_Dir
6634 (Argv (7 .. Argv'Last), Objects);
6636 begin
6637 if Src_Path_Name /= null and then
6638 Lib_Path_Name /= null
6639 then
6640 -- Set the RTS_*_Path_Name variables, so that the correct
6641 -- directories will be set when
6642 -- Osint.Add_Default_Search_Dirs will be called later.
6644 RTS_Src_Path_Name := Src_Path_Name;
6645 RTS_Lib_Path_Name := Lib_Path_Name;
6647 elsif Src_Path_Name = null
6648 and Lib_Path_Name = null then
6649 Make_Failed ("RTS path not valid: missing " &
6650 "adainclude and adalib directories");
6652 elsif Src_Path_Name = null then
6653 Make_Failed ("RTS path not valid: missing adainclude " &
6654 "directory");
6656 elsif Lib_Path_Name = null then
6657 Make_Failed ("RTS path not valid: missing adalib " &
6658 "directory");
6659 end if;
6660 end;
6661 end if;
6663 else
6664 Make_Failed ("unknown switch: ", Argv);
6665 end if;
6667 -- If we have seen a regular switch process it
6669 elsif Argv (1) = '-' then
6671 if Argv'Length = 1 then
6672 Make_Failed ("switch character cannot be followed by a blank");
6674 -- -I-
6676 elsif Argv (2 .. Argv'Last) = "I-" then
6677 Look_In_Primary_Dir := False;
6679 -- Forbid -?- or -??- where ? is any character
6681 elsif (Argv'Length = 3 and then Argv (3) = '-')
6682 or else (Argv'Length = 4 and then Argv (4) = '-')
6683 then
6684 Make_Failed ("trailing ""-"" at the end of ", Argv, " forbidden.");
6686 -- -Idir
6688 elsif Argv (2) = 'I' then
6689 Add_Src_Search_Dir (Argv (3 .. Argv'Last));
6690 Add_Lib_Search_Dir (Argv (3 .. Argv'Last));
6691 Add_Switch (Argv, Compiler, And_Save => And_Save);
6692 Add_Switch (Argv, Binder, And_Save => And_Save);
6694 -- -aIdir (to gcc this is like a -I switch)
6696 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aI" then
6697 Add_Src_Search_Dir (Argv (4 .. Argv'Last));
6698 Add_Switch ("-I" & Argv (4 .. Argv'Last),
6699 Compiler,
6700 And_Save => And_Save);
6701 Add_Switch (Argv, Binder, And_Save => And_Save);
6703 -- -aOdir
6705 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aO" then
6706 Add_Lib_Search_Dir (Argv (4 .. Argv'Last));
6707 Add_Switch (Argv, Binder, And_Save => And_Save);
6709 -- -aLdir (to gnatbind this is like a -aO switch)
6711 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aL" then
6712 Mark_Directory (Argv (4 .. Argv'Last), Ada_Lib_Dir);
6713 Add_Lib_Search_Dir (Argv (4 .. Argv'Last));
6714 Add_Switch ("-aO" & Argv (4 .. Argv'Last),
6715 Binder,
6716 And_Save => And_Save);
6718 -- -Adir (to gnatbind this is like a -aO switch, to gcc like a -I)
6720 elsif Argv (2) = 'A' then
6721 Mark_Directory (Argv (3 .. Argv'Last), Ada_Lib_Dir);
6722 Add_Src_Search_Dir (Argv (3 .. Argv'Last));
6723 Add_Lib_Search_Dir (Argv (3 .. Argv'Last));
6724 Add_Switch ("-I" & Argv (3 .. Argv'Last),
6725 Compiler,
6726 And_Save => And_Save);
6727 Add_Switch ("-aO" & Argv (3 .. Argv'Last),
6728 Binder,
6729 And_Save => And_Save);
6731 -- -Ldir
6733 elsif Argv (2) = 'L' then
6734 Add_Switch (Argv, Linker, And_Save => And_Save);
6736 -- For -gxxxxx, -pg, -mxxx, -fxxx: give the switch to both the
6737 -- compiler and the linker (except for -gnatxxx which is only for
6738 -- the compiler). Some of the -mxxx (for example -m64) and -fxxx
6739 -- (for example -ftest-coverage for gcov) need to be used when
6740 -- compiling the binder generated files, and using all these gcc
6741 -- switches for the binder generated files should not be a problem.
6743 elsif
6744 (Argv (2) = 'g' and then (Argv'Last < 5
6745 or else Argv (2 .. 5) /= "gnat"))
6746 or else Argv (2 .. Argv'Last) = "pg"
6747 or else (Argv (2) = 'm' and then Argv'Last > 2)
6748 or else (Argv (2) = 'f' and then Argv'Last > 2)
6749 then
6750 Add_Switch (Argv, Compiler, And_Save => And_Save);
6751 Add_Switch (Argv, Linker, And_Save => And_Save);
6753 -- -C=<mapping file>
6755 elsif Argv'Last > 2 and then Argv (2) = 'C' then
6756 if And_Save then
6757 if Argv (3) /= '=' or else Argv'Last <= 3 then
6758 Make_Failed ("illegal switch ", Argv);
6759 end if;
6761 Gnatmake_Mapping_File := new String'(Argv (4 .. Argv'Last));
6762 end if;
6764 -- -D
6766 elsif Argv'Last = 2 and then Argv (2) = 'D' then
6767 if Project_File_Name /= null then
6768 Make_Failed ("-D cannot be used in conjunction with a " &
6769 "project file");
6771 else
6772 Scan_Make_Switches (Argv);
6773 end if;
6775 -- -d
6777 elsif Argv (2) = 'd'
6778 and then Argv'Last = 2
6779 then
6780 Display_Compilation_Progress := True;
6782 -- -i
6784 elsif Argv'Last = 2 and then Argv (2) = 'i' then
6785 if Project_File_Name /= null then
6786 Make_Failed ("-i cannot be used in conjunction with a " &
6787 "project file");
6789 else
6790 Scan_Make_Switches (Argv);
6791 end if;
6793 -- -j (need to save the result)
6795 elsif Argv (2) = 'j' then
6796 Scan_Make_Switches (Argv);
6798 if And_Save then
6799 Saved_Maximum_Processes := Maximum_Processes;
6800 end if;
6802 -- -m
6804 elsif Argv (2) = 'm'
6805 and then Argv'Last = 2
6806 then
6807 Minimal_Recompilation := True;
6809 -- -u
6811 elsif Argv (2) = 'u'
6812 and then Argv'Last = 2
6813 then
6814 Unique_Compile := True;
6815 Compile_Only := True;
6816 Do_Bind_Step := False;
6817 Do_Link_Step := False;
6819 -- -U
6821 elsif Argv (2) = 'U'
6822 and then Argv'Last = 2
6823 then
6824 Unique_Compile_All_Projects := True;
6825 Unique_Compile := True;
6826 Compile_Only := True;
6827 Do_Bind_Step := False;
6828 Do_Link_Step := False;
6830 -- -Pprj or -P prj (only once, and only on the command line)
6832 elsif Argv (2) = 'P' then
6833 if Project_File_Name /= null then
6834 Make_Failed ("cannot have several project files specified");
6836 elsif Object_Directory_Path /= null then
6837 Make_Failed ("-D cannot be used in conjunction with a " &
6838 "project file");
6840 elsif In_Place_Mode then
6841 Make_Failed ("-i cannot be used in conjunction with a " &
6842 "project file");
6844 elsif not And_Save then
6846 -- It could be a tool other than gnatmake (i.e, gnatdist)
6847 -- or a -P switch inside a project file.
6849 Fail
6850 ("either the tool is not ""project-aware"" or " &
6851 "a project file is specified inside a project file");
6853 elsif Argv'Last = 2 then
6855 -- -P is used alone: the project file name is the next option
6857 Project_File_Name_Present := True;
6859 else
6860 Project_File_Name := new String'(Argv (3 .. Argv'Last));
6861 end if;
6863 -- -vPx (verbosity of the parsing of the project files)
6865 elsif Argv'Last = 4
6866 and then Argv (2 .. 3) = "vP"
6867 and then Argv (4) in '0' .. '2'
6868 then
6869 if And_Save then
6870 case Argv (4) is
6871 when '0' =>
6872 Current_Verbosity := Prj.Default;
6873 when '1' =>
6874 Current_Verbosity := Prj.Medium;
6875 when '2' =>
6876 Current_Verbosity := Prj.High;
6877 when others =>
6878 null;
6879 end case;
6880 end if;
6882 -- -Xext=val (External assignment)
6884 elsif Argv (2) = 'X'
6885 and then Is_External_Assignment (Argv)
6886 then
6887 -- Is_External_Assignment has side effects
6888 -- when it returns True;
6890 null;
6892 -- If -gnath is present, then generate the usage information
6893 -- right now and do not pass this option on to the compiler calls.
6895 elsif Argv = "-gnath" then
6896 Usage;
6898 -- If -gnatc is specified, make sure the bind step and the link
6899 -- step are not executed.
6901 elsif Argv'Length >= 6 and then Argv (2 .. 6) = "gnatc" then
6903 -- If -gnatc is specified, make sure the bind step and the link
6904 -- step are not executed.
6906 Add_Switch (Argv, Compiler, And_Save => And_Save);
6907 Operating_Mode := Check_Semantics;
6908 Check_Object_Consistency := False;
6909 Compile_Only := True;
6910 Do_Bind_Step := False;
6911 Do_Link_Step := False;
6913 elsif Argv (2 .. Argv'Last) = "nostdlib" then
6915 -- Don't pass -nostdlib to gnatlink, it will disable
6916 -- linking with all standard library files.
6918 No_Stdlib := True;
6920 Add_Switch (Argv, Compiler, And_Save => And_Save);
6921 Add_Switch (Argv, Binder, And_Save => And_Save);
6923 elsif Argv (2 .. Argv'Last) = "nostdinc" then
6925 -- Pass -nostdinc to the Compiler and to gnatbind
6927 No_Stdinc := True;
6928 Add_Switch (Argv, Compiler, And_Save => And_Save);
6929 Add_Switch (Argv, Binder, And_Save => And_Save);
6931 -- By default all switches with more than one character
6932 -- or one character switches which are not in 'a' .. 'z'
6933 -- (except 'C', 'F', 'M' and 'B') are passed to the compiler,
6934 -- unless we are dealing with a debug switch (starts with 'd')
6935 -- or an extended gnatmake switch (starts with 'e').
6937 elsif Argv (2) /= 'd'
6938 and then Argv (2) /= 'e'
6939 and then Argv (2 .. Argv'Last) /= "C"
6940 and then Argv (2 .. Argv'Last) /= "F"
6941 and then Argv (2 .. Argv'Last) /= "M"
6942 and then Argv (2 .. Argv'Last) /= "B"
6943 and then (Argv'Length > 2 or else Argv (2) not in 'a' .. 'z')
6944 then
6945 Add_Switch (Argv, Compiler, And_Save => And_Save);
6947 -- All other options are handled by Scan_Make_Switches
6949 else
6950 Scan_Make_Switches (Argv);
6951 end if;
6953 -- If not a switch it must be a file name
6955 else
6956 Add_File (Argv);
6957 Mains.Add_Main (Argv);
6958 end if;
6959 end Scan_Make_Arg;
6961 -----------------
6962 -- Switches_Of --
6963 -----------------
6965 function Switches_Of
6966 (Source_File : Name_Id;
6967 Source_File_Name : String;
6968 Source_Index : Int;
6969 Naming : Naming_Data;
6970 In_Package : Package_Id;
6971 Allow_ALI : Boolean) return Variable_Value
6973 Switches : Variable_Value;
6975 Defaults : constant Array_Element_Id :=
6976 Prj.Util.Value_Of
6977 (Name => Name_Default_Switches,
6978 In_Arrays =>
6979 Packages.Table (In_Package).Decl.Arrays);
6981 Switches_Array : constant Array_Element_Id :=
6982 Prj.Util.Value_Of
6983 (Name => Name_Switches,
6984 In_Arrays =>
6985 Packages.Table (In_Package).Decl.Arrays);
6987 begin
6988 Switches :=
6989 Prj.Util.Value_Of
6990 (Index => Source_File,
6991 Src_Index => Source_Index,
6992 In_Array => Switches_Array);
6994 if Switches = Nil_Variable_Value then
6995 declare
6996 Name : String (1 .. Source_File_Name'Length + 3);
6997 Last : Positive := Source_File_Name'Length;
6998 Spec_Suffix : constant String :=
6999 Get_Name_String (Naming.Ada_Spec_Suffix);
7000 Body_Suffix : constant String :=
7001 Get_Name_String (Naming.Ada_Body_Suffix);
7002 Truncated : Boolean := False;
7004 begin
7005 Name (1 .. Last) := Source_File_Name;
7007 if Last > Body_Suffix'Length
7008 and then Name (Last - Body_Suffix'Length + 1 .. Last) =
7009 Body_Suffix
7010 then
7011 Truncated := True;
7012 Last := Last - Body_Suffix'Length;
7013 end if;
7015 if not Truncated
7016 and then Last > Spec_Suffix'Length
7017 and then Name (Last - Spec_Suffix'Length + 1 .. Last) =
7018 Spec_Suffix
7019 then
7020 Truncated := True;
7021 Last := Last - Spec_Suffix'Length;
7022 end if;
7024 if Truncated then
7025 Name_Len := Last;
7026 Name_Buffer (1 .. Name_Len) := Name (1 .. Last);
7027 Switches :=
7028 Prj.Util.Value_Of
7029 (Index => Name_Find,
7030 Src_Index => 0,
7031 In_Array => Switches_Array);
7033 if Switches = Nil_Variable_Value
7034 and then Allow_ALI
7035 then
7036 Last := Source_File_Name'Length;
7038 while Name (Last) /= '.' loop
7039 Last := Last - 1;
7040 end loop;
7042 Name (Last + 1 .. Last + 3) := "ali";
7043 Name_Len := Last + 3;
7044 Name_Buffer (1 .. Name_Len) := Name (1 .. Name_Len);
7045 Switches :=
7046 Prj.Util.Value_Of
7047 (Index => Name_Find,
7048 Src_Index => 0,
7049 In_Array => Switches_Array);
7050 end if;
7051 end if;
7052 end;
7053 end if;
7055 if Switches = Nil_Variable_Value then
7056 Switches :=
7057 Prj.Util.Value_Of
7058 (Index => Name_Ada,
7059 Src_Index => 0,
7060 In_Array => Defaults);
7061 end if;
7063 return Switches;
7064 end Switches_Of;
7066 -----------
7067 -- Usage --
7068 -----------
7070 procedure Usage is
7071 begin
7072 if Usage_Needed then
7073 Usage_Needed := False;
7074 Makeusg;
7075 end if;
7076 end Usage;
7078 -----------------
7079 -- Verbose_Msg --
7080 -----------------
7082 procedure Verbose_Msg
7083 (N1 : Name_Id;
7084 S1 : String;
7085 N2 : Name_Id := No_Name;
7086 S2 : String := "";
7087 Prefix : String := " -> ")
7089 begin
7090 if not Verbose_Mode then
7091 return;
7092 end if;
7094 Write_Str (Prefix);
7095 Write_Str ("""");
7096 Write_Name (N1);
7097 Write_Str (""" ");
7098 Write_Str (S1);
7100 if N2 /= No_Name then
7101 Write_Str (" """);
7102 Write_Name (N2);
7103 Write_Str (""" ");
7104 end if;
7106 Write_Str (S2);
7107 Write_Eol;
7108 end Verbose_Msg;
7110 begin
7111 -- Make sure that in case of failure, the temp files will be deleted
7113 Prj.Com.Fail := Make_Failed'Access;
7114 MLib.Fail := Make_Failed'Access;
7115 Makeutl.Do_Fail := Make_Failed'Access;
7116 end Make;