re PR ada/4720 (GNAT programs do not support --help and --version)
[gcc.git] / gcc / ada / make.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- M A K E --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
26
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; use Targparm;
58 with Table;
59 with Tempdir;
60 with Types; use Types;
61
62 with Ada.Exceptions; use Ada.Exceptions;
63 with Ada.Command_Line; use Ada.Command_Line;
64
65 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
66 with GNAT.Case_Util; use GNAT.Case_Util;
67 with GNAT.OS_Lib; use GNAT.OS_Lib;
68
69 with System.HTable;
70
71 package body Make is
72
73 use ASCII;
74 -- Make control characters visible
75
76 Standard_Library_Package_Body_Name : constant String := "s-stalib.adb";
77 -- Every program depends on this package, that must then be checked,
78 -- especially when -f and -a are used.
79
80 type Sigint_Handler is access procedure;
81
82 procedure Install_Int_Handler (Handler : Sigint_Handler);
83 pragma Import (C, Install_Int_Handler, "__gnat_install_int_handler");
84 -- Called by Gnatmake to install the SIGINT handler below
85
86 procedure Sigint_Intercepted;
87 -- Called when the program is interrupted by Ctrl-C to delete the
88 -- temporary mapping files and configuration pragmas files.
89
90 -------------------------
91 -- Note on terminology --
92 -------------------------
93
94 -- In this program, we use the phrase "termination" of a file name to refer
95 -- to the suffix that appears after the unit name portion. Very often this
96 -- is simply the extension, but in some cases, the sequence may be more
97 -- complex, for example in main.1.ada, the termination in this name is
98 -- ".1.ada" and in main_.ada the termination is "_.ada".
99
100 -------------------------------------
101 -- Queue (Q) Manipulation Routines --
102 -------------------------------------
103
104 -- The Q is used in Compile_Sources below. Its implementation uses the GNAT
105 -- generic package Table (basically an extensible array). Q_Front points to
106 -- the first valid element in the Q, whereas Q.First is the first element
107 -- ever enqueued, while Q.Last - 1 is the last element in the Q.
108 --
109 -- +---+--------------+---+---+---+-----------+---+--------
110 -- Q | | ........ | | | | ....... | |
111 -- +---+--------------+---+---+---+-----------+---+--------
112 -- ^ ^ ^
113 -- Q.First Q_Front Q.Last - 1
114 --
115 -- The elements comprised between Q.First and Q_Front - 1 are the elements
116 -- that have been enqueued and then dequeued, while the elements between
117 -- Q_Front and Q.Last - 1 are the elements currently in the Q. When the Q
118 -- is initialized Q_Front = Q.First = Q.Last. After Compile_Sources has
119 -- terminated its execution, Q_Front = Q.Last and the elements contained
120 -- between Q.Front and Q.Last-1 are those that were explored and thus
121 -- marked by Compile_Sources. Whenever the Q is reinitialized, the elements
122 -- between Q.First and Q.Last - 1 are unmarked.
123
124 procedure Init_Q;
125 -- Must be called to (re)initialize the Q
126
127 procedure Insert_Q
128 (Source_File : File_Name_Type;
129 Source_Unit : Unit_Name_Type := No_Unit_Name;
130 Index : Int := 0);
131 -- Inserts Source_File at the end of Q. Provide Source_Unit when possible
132 -- for external use (gnatdist). Provide index for multi-unit sources.
133
134 function Empty_Q return Boolean;
135 -- Returns True if Q is empty
136
137 procedure Extract_From_Q
138 (Source_File : out File_Name_Type;
139 Source_Unit : out Unit_Name_Type;
140 Source_Index : out Int);
141 -- Extracts the first element from the Q
142
143 procedure Insert_Project_Sources
144 (The_Project : Project_Id;
145 All_Projects : Boolean;
146 Into_Q : Boolean);
147 -- If Into_Q is True, insert all sources of the project file(s) that are
148 -- not already marked into the Q. If Into_Q is False, call Osint.Add_File
149 -- for the first source, then insert all other sources that are not already
150 -- marked into the Q. If All_Projects is True, all sources of all projects
151 -- are concerned; otherwise, only sources of The_Project are concerned,
152 -- including, if The_Project is an extending project, sources inherited
153 -- from projects being extended.
154
155 First_Q_Initialization : Boolean := True;
156 -- Will be set to false after Init_Q has been called once
157
158 Q_Front : Natural;
159 -- Points to the first valid element in the Q
160
161 Unique_Compile : Boolean := False;
162 -- Set to True if -u or -U or a project file with no main is used
163
164 Unique_Compile_All_Projects : Boolean := False;
165 -- Set to True if -U is used
166
167 RTS_Specified : String_Access := null;
168 -- Used to detect multiple --RTS= switches
169
170 type Q_Record is record
171 File : File_Name_Type;
172 Unit : Unit_Name_Type;
173 Index : Int;
174 end record;
175 -- File is the name of the file to compile. Unit is for gnatdist
176 -- use in order to easily get the unit name of a file to compile
177 -- when its name is krunched or declared in gnat.adc. Index, when not 0,
178 -- is the index of the unit in a multi-unit source.
179
180 package Q is new Table.Table (
181 Table_Component_Type => Q_Record,
182 Table_Index_Type => Natural,
183 Table_Low_Bound => 0,
184 Table_Initial => 4000,
185 Table_Increment => 100,
186 Table_Name => "Make.Q");
187 -- This is the actual Q
188
189 -- The 3 following packages are used to store gcc, gnatbind and gnatlink
190 -- switches found in the project files.
191
192 package Gcc_Switches is new Table.Table (
193 Table_Component_Type => String_Access,
194 Table_Index_Type => Integer,
195 Table_Low_Bound => 1,
196 Table_Initial => 20,
197 Table_Increment => 100,
198 Table_Name => "Make.Gcc_Switches");
199
200 package Binder_Switches is new Table.Table (
201 Table_Component_Type => String_Access,
202 Table_Index_Type => Integer,
203 Table_Low_Bound => 1,
204 Table_Initial => 20,
205 Table_Increment => 100,
206 Table_Name => "Make.Binder_Switches");
207
208 package Linker_Switches is new Table.Table (
209 Table_Component_Type => String_Access,
210 Table_Index_Type => Integer,
211 Table_Low_Bound => 1,
212 Table_Initial => 20,
213 Table_Increment => 100,
214 Table_Name => "Make.Linker_Switches");
215
216 -- The following instantiations and variables are necessary to save what
217 -- is found on the command line, in case there is a project file specified.
218
219 package Saved_Gcc_Switches is new Table.Table (
220 Table_Component_Type => String_Access,
221 Table_Index_Type => Integer,
222 Table_Low_Bound => 1,
223 Table_Initial => 20,
224 Table_Increment => 100,
225 Table_Name => "Make.Saved_Gcc_Switches");
226
227 package Saved_Binder_Switches is new Table.Table (
228 Table_Component_Type => String_Access,
229 Table_Index_Type => Integer,
230 Table_Low_Bound => 1,
231 Table_Initial => 20,
232 Table_Increment => 100,
233 Table_Name => "Make.Saved_Binder_Switches");
234
235 package Saved_Linker_Switches is new Table.Table
236 (Table_Component_Type => String_Access,
237 Table_Index_Type => Integer,
238 Table_Low_Bound => 1,
239 Table_Initial => 20,
240 Table_Increment => 100,
241 Table_Name => "Make.Saved_Linker_Switches");
242
243 package Switches_To_Check is new Table.Table (
244 Table_Component_Type => String_Access,
245 Table_Index_Type => Integer,
246 Table_Low_Bound => 1,
247 Table_Initial => 20,
248 Table_Increment => 100,
249 Table_Name => "Make.Switches_To_Check");
250
251 package Library_Paths is new Table.Table (
252 Table_Component_Type => String_Access,
253 Table_Index_Type => Integer,
254 Table_Low_Bound => 1,
255 Table_Initial => 20,
256 Table_Increment => 100,
257 Table_Name => "Make.Library_Paths");
258
259 package Failed_Links is new Table.Table (
260 Table_Component_Type => File_Name_Type,
261 Table_Index_Type => Integer,
262 Table_Low_Bound => 1,
263 Table_Initial => 10,
264 Table_Increment => 100,
265 Table_Name => "Make.Failed_Links");
266
267 package Successful_Links is new Table.Table (
268 Table_Component_Type => File_Name_Type,
269 Table_Index_Type => Integer,
270 Table_Low_Bound => 1,
271 Table_Initial => 10,
272 Table_Increment => 100,
273 Table_Name => "Make.Successful_Links");
274
275 package Library_Projs is new Table.Table (
276 Table_Component_Type => Project_Id,
277 Table_Index_Type => Integer,
278 Table_Low_Bound => 1,
279 Table_Initial => 10,
280 Table_Increment => 100,
281 Table_Name => "Make.Library_Projs");
282
283 -- Two variables to keep the last binder and linker switch index in tables
284 -- Binder_Switches and Linker_Switches, before adding switches from the
285 -- project file (if any) and switches from the command line (if any).
286
287 Last_Binder_Switch : Integer := 0;
288 Last_Linker_Switch : Integer := 0;
289
290 Normalized_Switches : Argument_List_Access := new Argument_List (1 .. 10);
291 Last_Norm_Switch : Natural := 0;
292
293 Saved_Maximum_Processes : Natural := 0;
294
295 type Arg_List_Ref is access Argument_List;
296 The_Saved_Gcc_Switches : Arg_List_Ref;
297
298 Project_File_Name : String_Access := null;
299 -- The path name of the main project file, if any
300
301 Project_File_Name_Present : Boolean := False;
302 -- True when -P is used with a space between -P and the project file name
303
304 Current_Verbosity : Prj.Verbosity := Prj.Default;
305 -- Verbosity to parse the project files
306
307 Project_Tree : constant Project_Tree_Ref := new Project_Tree_Data;
308
309 Main_Project : Prj.Project_Id := No_Project;
310 -- The project id of the main project file, if any
311
312 Project_Of_Current_Object_Directory : Project_Id := No_Project;
313 -- The object directory of the project for the last compilation. Avoid
314 -- calling Change_Dir if the current working directory is already this
315 -- directory
316
317 -- Packages of project files where unknown attributes are errors
318
319 Naming_String : aliased String := "naming";
320 Builder_String : aliased String := "builder";
321 Compiler_String : aliased String := "compiler";
322 Binder_String : aliased String := "binder";
323 Linker_String : aliased String := "linker";
324
325 Gnatmake_Packages : aliased String_List :=
326 (Naming_String 'Access,
327 Builder_String 'Access,
328 Compiler_String 'Access,
329 Binder_String 'Access,
330 Linker_String 'Access);
331
332 Packages_To_Check_By_Gnatmake : constant String_List_Access :=
333 Gnatmake_Packages'Access;
334
335 procedure Add_Library_Search_Dir
336 (Path : String;
337 On_Command_Line : Boolean);
338 -- Call Add_Lib_Search_Dir with an absolute directory path. If Path is
339 -- relative path, when On_Command_Line is True, it is relative to the
340 -- current working directory. When On_Command_Line is False, it is relative
341 -- to the project directory of the main project.
342
343 procedure Add_Source_Search_Dir
344 (Path : String;
345 On_Command_Line : Boolean);
346 -- Call Add_Src_Search_Dir with an absolute directory path. If Path is a
347 -- relative path, when On_Command_Line is True, it is relative to the
348 -- current working directory. When On_Command_Line is False, it is relative
349 -- to the project directory of the main project.
350
351 procedure Add_Source_Dir (N : String);
352 -- Call Add_Src_Search_Dir (output one line when in verbose mode)
353
354 procedure Add_Source_Directories is
355 new Prj.Env.For_All_Source_Dirs (Action => Add_Source_Dir);
356
357 procedure Add_Object_Dir (N : String);
358 -- Call Add_Lib_Search_Dir (output one line when in verbose mode)
359
360 procedure Add_Object_Directories is
361 new Prj.Env.For_All_Object_Dirs (Action => Add_Object_Dir);
362
363 procedure Change_To_Object_Directory (Project : Project_Id);
364 -- Change to the object directory of project Project, if this is not
365 -- already the current working directory.
366
367 type Bad_Compilation_Info is record
368 File : File_Name_Type;
369 Unit : Unit_Name_Type;
370 Found : Boolean;
371 end record;
372 -- File is the name of the file for which a compilation failed. Unit is for
373 -- gnatdist use in order to easily get the unit name of a file when its
374 -- name is krunched or declared in gnat.adc. Found is False if the
375 -- compilation failed because the file could not be found.
376
377 package Bad_Compilation is new Table.Table (
378 Table_Component_Type => Bad_Compilation_Info,
379 Table_Index_Type => Natural,
380 Table_Low_Bound => 1,
381 Table_Initial => 20,
382 Table_Increment => 100,
383 Table_Name => "Make.Bad_Compilation");
384 -- Full name of all the source files for which compilation fails
385
386 Do_Compile_Step : Boolean := True;
387 Do_Bind_Step : Boolean := True;
388 Do_Link_Step : Boolean := True;
389 -- Flags to indicate what step should be executed. Can be set to False
390 -- with the switches -c, -b and -l. These flags are reset to True for
391 -- each invokation of procedure Gnatmake.
392
393 Shared_String : aliased String := "-shared";
394 Force_Elab_Flags_String : aliased String := "-F";
395
396 No_Shared_Switch : aliased Argument_List := (1 .. 0 => null);
397 Shared_Switch : aliased Argument_List := (1 => Shared_String'Access);
398 Bind_Shared : Argument_List_Access := No_Shared_Switch'Access;
399 -- Switch to added in front of gnatbind switches. By default no switch is
400 -- added. Switch "-shared" is added if there is a non-static Library
401 -- Project File.
402
403 Shared_Libgcc : aliased String := "-shared-libgcc";
404
405 No_Shared_Libgcc_Switch : aliased Argument_List := (1 .. 0 => null);
406 Shared_Libgcc_Switch : aliased Argument_List :=
407 (1 => Shared_Libgcc'Access);
408 Link_With_Shared_Libgcc : Argument_List_Access :=
409 No_Shared_Libgcc_Switch'Access;
410
411 procedure Make_Failed (S1 : String; S2 : String := ""; S3 : String := "");
412 -- Delete all temp files created by Gnatmake and call Osint.Fail,
413 -- with the parameter S1, S2 and S3 (see osint.ads).
414 -- This is called from the Prj hierarchy and the MLib hierarchy.
415
416 --------------------------
417 -- Obsolete Executables --
418 --------------------------
419
420 Executable_Obsolete : Boolean := False;
421 -- Executable_Obsolete is initially set to False for each executable,
422 -- and is set to True whenever one of the source of the executable is
423 -- compiled, or has already been compiled for another executable.
424
425 Max_Header : constant := 200;
426 -- This needs a proper comment, it used to say "arbitrary"
427 -- that's not an adequate comment ???
428
429 type Header_Num is range 1 .. Max_Header;
430 -- Header_Num for the hash table Obsoleted below
431
432 function Hash (F : File_Name_Type) return Header_Num;
433 -- Hash function for the hash table Obsoleted below
434
435 package Obsoleted is new System.HTable.Simple_HTable
436 (Header_Num => Header_Num,
437 Element => Boolean,
438 No_Element => False,
439 Key => File_Name_Type,
440 Hash => Hash,
441 Equal => "=");
442 -- A hash table to keep all files that have been compiled, to detect
443 -- if an executable is up to date or not.
444
445 procedure Enter_Into_Obsoleted (F : File_Name_Type);
446 -- Enter a file name, without directory information, into the hash table
447 -- Obsoleted.
448
449 function Is_In_Obsoleted (F : File_Name_Type) return Boolean;
450 -- Check if a file name, without directory information, has already been
451 -- entered into the hash table Obsoleted.
452
453 type Dependency is record
454 This : File_Name_Type;
455 Depends_On : File_Name_Type;
456 end record;
457 -- Components of table Dependencies below
458
459 package Dependencies is new Table.Table (
460 Table_Component_Type => Dependency,
461 Table_Index_Type => Integer,
462 Table_Low_Bound => 1,
463 Table_Initial => 20,
464 Table_Increment => 100,
465 Table_Name => "Make.Dependencies");
466 -- A table to keep dependencies, to be able to decide if an executable
467 -- is obsolete. More explanation needed ???
468
469 -- procedure Add_Dependency (S : File_Name_Type; On : File_Name_Type);
470 -- -- Add one entry in table Dependencies
471
472 ----------------------------
473 -- Arguments and Switches --
474 ----------------------------
475
476 Arguments : Argument_List_Access;
477 -- Used to gather the arguments for invocation of the compiler
478
479 Last_Argument : Natural := 0;
480 -- Last index of arguments in Arguments above
481
482 Arguments_Collected : Boolean := False;
483 -- Set to True when the arguments for the next invocation of the compiler
484 -- have been collected.
485
486 Arguments_Project : Project_Id;
487 -- Project id, if any, of the source to be compiled
488
489 Arguments_Path_Name : Path_Name_Type;
490 -- Full path of the source to be compiled, when Arguments_Project is not
491 -- No_Project.
492
493 Dummy_Switch : constant String_Access := new String'("- ");
494 -- Used to initialized Prev_Switch in procedure Check
495
496 procedure Add_Arguments (Args : Argument_List);
497 -- Add arguments to global variable Arguments, increasing its size
498 -- if necessary and adjusting Last_Argument.
499
500 function Configuration_Pragmas_Switch
501 (For_Project : Project_Id) return Argument_List;
502 -- Return an argument list of one element, if there is a configuration
503 -- pragmas file to be specified for For_Project,
504 -- otherwise return an empty argument list.
505
506 -------------------
507 -- Misc Routines --
508 -------------------
509
510 procedure List_Depend;
511 -- Prints to standard output the list of object dependencies. This list
512 -- can be used directly in a Makefile. A call to Compile_Sources must
513 -- precede the call to List_Depend. Also because this routine uses the
514 -- ALI files that were originally loaded and scanned by Compile_Sources,
515 -- no additional ALI files should be scanned between the two calls (i.e.
516 -- between the call to Compile_Sources and List_Depend.)
517
518 procedure List_Bad_Compilations;
519 -- Prints out the list of all files for which the compilation failed
520
521 procedure Verbose_Msg
522 (N1 : Name_Id;
523 S1 : String;
524 N2 : Name_Id := No_Name;
525 S2 : String := "";
526 Prefix : String := " -> ";
527 Minimum_Verbosity : Verbosity_Level_Type := Opt.Low);
528 procedure Verbose_Msg
529 (N1 : File_Name_Type;
530 S1 : String;
531 N2 : File_Name_Type := No_File;
532 S2 : String := "";
533 Prefix : String := " -> ";
534 Minimum_Verbosity : Verbosity_Level_Type := Opt.Low);
535 -- If the verbose flag (Verbose_Mode) is set and the verbosity level is
536 -- at least equal to Minimum_Verbosity, then print Prefix to standard
537 -- output followed by N1 and S1. If N2 /= No_Name then N2 is printed after
538 -- S1. S2 is printed last. Both N1 and N2 are printed in quotation marks.
539
540 Usage_Needed : Boolean := True;
541 -- Flag used to make sure Makeusg is call at most once
542
543 procedure Usage;
544 -- Call Makeusg, if Usage_Needed is True.
545 -- Set Usage_Needed to False.
546
547 procedure Debug_Msg (S : String; N : Name_Id);
548 procedure Debug_Msg (S : String; N : File_Name_Type);
549 procedure Debug_Msg (S : String; N : Unit_Name_Type);
550 -- If Debug.Debug_Flag_W is set outputs string S followed by name N
551
552 procedure Recursive_Compute_Depth
553 (Project : Project_Id;
554 Depth : Natural);
555 -- Compute depth of Project and of the projects it depends on
556
557 procedure Compute_All_Imported_Projects (Project : Project_Id);
558 -- Compute, the list of the projects imported directly or indirectly by
559 -- project Project.
560
561 -----------------------
562 -- Gnatmake Routines --
563 -----------------------
564
565 Gnatmake_Called : Boolean := False;
566 -- Set to True when procedure Gnatmake is called.
567 -- Attempt to delete temporary files is made only when Gnatmake_Called
568 -- is True.
569
570 subtype Lib_Mark_Type is Byte;
571 -- Used in Mark_Directory
572
573 Ada_Lib_Dir : constant Lib_Mark_Type := 1;
574 -- Used to mark a directory as a GNAT lib dir
575
576 -- Note that the notion of GNAT lib dir is no longer used. The code related
577 -- to it has not been removed to give an idea on how to use the directory
578 -- prefix marking mechanism.
579
580 -- An Ada library directory is a directory containing ali and object files
581 -- but no source files for the bodies (the specs can be in the same or some
582 -- other directory). These directories are specified in the Gnatmake
583 -- command line with the switch "-Adir" (to specify the spec location -Idir
584 -- cab be used). Gnatmake skips the missing sources whose ali are in Ada
585 -- library directories. For an explanation of why Gnatmake behaves that
586 -- way, see the spec of Make.Compile_Sources. The directory lookup penalty
587 -- is incurred every single time this routine is called.
588
589 procedure Check_Steps;
590 -- Check what steps (Compile, Bind, Link) must be executed.
591 -- Set the step flags accordingly.
592
593 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean;
594 -- Get directory prefix of this file and get lib mark stored in name
595 -- table for this directory. Then check if an Ada lib mark has been set.
596
597 procedure Mark_Directory
598 (Dir : String;
599 Mark : Lib_Mark_Type;
600 On_Command_Line : Boolean);
601 -- Store the absolute path from Dir in name table and set lib mark as name
602 -- info to identify Ada libraries.
603 --
604 -- If Dir is a relative path, when On_Command_Line is True, it is relative
605 -- to the current working directory; when On_Command_Line is False, it is
606 -- relative to the project directory of the main project.
607
608 Output_Is_Object : Boolean := True;
609 -- Set to False when using a switch -S for the compiler
610
611 procedure Check_For_S_Switch;
612 -- Set Output_Is_Object to False when the -S switch is used for the
613 -- compiler.
614
615 function Switches_Of
616 (Source_File : File_Name_Type;
617 Source_File_Name : String;
618 Source_Index : Int;
619 Naming : Naming_Data;
620 In_Package : Package_Id;
621 Allow_ALI : Boolean) return Variable_Value;
622 -- Return the switches for the source file in the specified package of a
623 -- project file. If the Source_File ends with a standard GNAT extension
624 -- (".ads" or ".adb"), try first the full name, then the name without the
625 -- extension, then, if Allow_ALI is True, the name with the extension
626 -- ".ali". If there is no switches for either names, try the default
627 -- switches for Ada. If all failed, return No_Variable_Value.
628
629 function Is_In_Object_Directory
630 (Source_File : File_Name_Type;
631 Full_Lib_File : File_Name_Type) return Boolean;
632 -- Check if, when using a project file, the ALI file is in the project
633 -- directory of the ultimate extending project. If it is not, we ignore
634 -- the fact that this ALI file is read-only.
635
636 ----------------------------------------------------
637 -- Compiler, Binder & Linker Data and Subprograms --
638 ----------------------------------------------------
639
640 Gcc : String_Access := Program_Name ("gcc");
641 Gnatbind : String_Access := Program_Name ("gnatbind");
642 Gnatlink : String_Access := Program_Name ("gnatlink");
643 -- Default compiler, binder, linker programs
644
645 Saved_Gcc : String_Access := null;
646 Saved_Gnatbind : String_Access := null;
647 Saved_Gnatlink : String_Access := null;
648 -- Given by the command line. Will be used, if non null
649
650 Gcc_Path : String_Access :=
651 GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
652 Gnatbind_Path : String_Access :=
653 GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
654 Gnatlink_Path : String_Access :=
655 GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
656 -- Path for compiler, binder, linker programs, defaulted now for gnatdist.
657 -- Changed later if overridden on command line.
658
659 Comp_Flag : constant String_Access := new String'("-c");
660 Output_Flag : constant String_Access := new String'("-o");
661 Ada_Flag_1 : constant String_Access := new String'("-x");
662 Ada_Flag_2 : constant String_Access := new String'("ada");
663 No_gnat_adc : constant String_Access := new String'("-gnatA");
664 GNAT_Flag : constant String_Access := new String'("-gnatpg");
665 Do_Not_Check_Flag : constant String_Access := new String'("-x");
666
667 Object_Suffix : constant String := Get_Target_Object_Suffix.all;
668
669 Syntax_Only : Boolean := False;
670 -- Set to True when compiling with -gnats
671
672 Display_Executed_Programs : Boolean := True;
673 -- Set to True if name of commands should be output on stderr (or on stdout
674 -- if the Commands_To_Stdout flag was set by use of the -S switch).
675
676 Output_File_Name_Seen : Boolean := False;
677 -- Set to True after having scanned the file_name for
678 -- switch "-o file_name"
679
680 Object_Directory_Seen : Boolean := False;
681 -- Set to True after having scanned the object directory for
682 -- switch "-D obj_dir".
683
684 Object_Directory_Path : String_Access := null;
685 -- The path name of the object directory, set with switch -D
686
687 type Make_Program_Type is (None, Compiler, Binder, Linker);
688
689 Program_Args : Make_Program_Type := None;
690 -- Used to indicate if we are scanning gnatmake, gcc, gnatbind, or gnatbind
691 -- options within the gnatmake command line. Used in Scan_Make_Arg only,
692 -- but must be global since value preserved from one call to another.
693
694 Temporary_Config_File : Boolean := False;
695 -- Set to True when there is a temporary config file used for a project
696 -- file, to avoid displaying the -gnatec switch for a temporary file.
697
698 procedure Add_Switches
699 (The_Package : Package_Id;
700 File_Name : String;
701 Index : Int;
702 Program : Make_Program_Type);
703 procedure Add_Switch
704 (S : String_Access;
705 Program : Make_Program_Type;
706 Append_Switch : Boolean := True;
707 And_Save : Boolean := True);
708 procedure Add_Switch
709 (S : String;
710 Program : Make_Program_Type;
711 Append_Switch : Boolean := True;
712 And_Save : Boolean := True);
713 -- Make invokes one of three programs (the compiler, the binder or the
714 -- linker). For the sake of convenience, some program specific switches
715 -- can be passed directly on the gnatmake commande line. This procedure
716 -- records these switches so that gnamake can pass them to the right
717 -- program. S is the switch to be added at the end of the command line
718 -- for Program if Append_Switch is True. If Append_Switch is False S is
719 -- added at the beginning of the command line.
720
721 procedure Check
722 (Source_File : File_Name_Type;
723 Source_Index : Int;
724 The_Args : Argument_List;
725 Lib_File : File_Name_Type;
726 Read_Only : Boolean;
727 ALI : out ALI_Id;
728 O_File : out File_Name_Type;
729 O_Stamp : out Time_Stamp_Type);
730 -- Determines whether the library file Lib_File is up-to-date or not. The
731 -- full name (with path information) of the object file corresponding to
732 -- Lib_File is returned in O_File. Its time stamp is saved in O_Stamp.
733 -- ALI is the ALI_Id corresponding to Lib_File. If Lib_File in not
734 -- up-to-date, then the corresponding source file needs to be recompiled.
735 -- In this case ALI = No_ALI_Id.
736
737 procedure Check_Linker_Options
738 (E_Stamp : Time_Stamp_Type;
739 O_File : out File_Name_Type;
740 O_Stamp : out Time_Stamp_Type);
741 -- Checks all linker options for linker files that are newer
742 -- than E_Stamp. If such objects are found, the youngest object
743 -- is returned in O_File and its stamp in O_Stamp.
744 --
745 -- If no obsolete linker files were found, the first missing
746 -- linker file is returned in O_File and O_Stamp is empty.
747 -- Otherwise O_File is No_File.
748
749 procedure Collect_Arguments
750 (Source_File : File_Name_Type;
751 Source_Index : Int;
752 Args : Argument_List);
753 -- Collect all arguments for a source to be compiled, including those
754 -- that come from a project file.
755
756 procedure Display (Program : String; Args : Argument_List);
757 -- Displays Program followed by the arguments in Args if variable
758 -- Display_Executed_Programs is set. The lower bound of Args must be 1.
759
760 procedure Report_Compilation_Failed;
761 -- Delete all temporary files and fail graciously
762
763 -----------------
764 -- Mapping files
765 -----------------
766
767 type Temp_Path_Names is
768 array (Project_Id range <>, Positive range <>) of Path_Name_Type;
769
770 type Temp_Path_Ptr is access Temp_Path_Names;
771
772 type Indices is array (Project_Id range <>) of Natural;
773
774 type Indices_Ptr is access Indices;
775
776 type Free_File_Indices is array
777 (Project_Id range <>, Positive range <>) of Positive;
778
779 type Free_Indices_Ptr is access Free_File_Indices;
780
781 The_Mapping_File_Names : Temp_Path_Ptr;
782 -- For each project, the name ids of the temporary mapping files used
783
784 Last_Mapping_File_Names : Indices_Ptr;
785 -- For each project, the index of the last mapping file created
786
787 The_Free_Mapping_File_Indices : Free_Indices_Ptr;
788 -- For each project, the indices in The_Mapping_File_Names of the mapping
789 -- file names that can be reused for subsequent compilations.
790
791 Last_Free_Indices : Indices_Ptr;
792 -- For each project, the number of mapping files that can be reused
793
794 Gnatmake_Mapping_File : String_Access := null;
795 -- The path name of a mapping file specified by switch -C=
796
797 procedure Delete_Mapping_Files;
798 -- Delete all temporary mapping files
799
800 procedure Init_Mapping_File
801 (Project : Project_Id;
802 File_Index : in out Natural);
803 -- Create a new temporary mapping file, and fill it with the project file
804 -- mappings, when using project file(s). The out parameter File_Index is
805 -- the index to the name of the file in the array The_Mapping_File_Names.
806
807 procedure Delete_Temp_Config_Files;
808 -- Delete all temporary config files
809
810 procedure Delete_All_Temp_Files;
811 -- Delete all temp files (config files, mapping files, path files)
812
813 -------------------------------------------------
814 -- Subprogram declarations moved from the spec --
815 -------------------------------------------------
816
817 procedure Bind (ALI_File : File_Name_Type; Args : Argument_List);
818 -- Binds ALI_File. Args are the arguments to pass to the binder.
819 -- Args must have a lower bound of 1.
820
821 procedure Display_Commands (Display : Boolean := True);
822 -- The default behavior of Make commands (Compile_Sources, Bind, Link)
823 -- is to display them on stderr. This behavior can be changed repeatedly
824 -- by invoking this procedure.
825
826 -- If a compilation, bind or link failed one of the following 3 exceptions
827 -- is raised. These need to be handled by the calling routines.
828
829 procedure Compile_Sources
830 (Main_Source : File_Name_Type;
831 Args : Argument_List;
832 First_Compiled_File : out File_Name_Type;
833 Most_Recent_Obj_File : out File_Name_Type;
834 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
835 Main_Unit : out Boolean;
836 Compilation_Failures : out Natural;
837 Main_Index : Int := 0;
838 Check_Readonly_Files : Boolean := False;
839 Do_Not_Execute : Boolean := False;
840 Force_Compilations : Boolean := False;
841 Keep_Going : Boolean := False;
842 In_Place_Mode : Boolean := False;
843 Initialize_ALI_Data : Boolean := True;
844 Max_Process : Positive := 1);
845 -- Compile_Sources will recursively compile all the sources needed by
846 -- Main_Source. Before calling this routine make sure Namet has been
847 -- initialized. This routine can be called repeatedly with different
848 -- Main_Source file as long as all the source (-I flags), library
849 -- (-B flags) and ada library (-A flags) search paths between calls are
850 -- *exactly* the same. The default directory must also be the same.
851 --
852 -- Args contains the arguments to use during the compilations.
853 -- The lower bound of Args must be 1.
854 --
855 -- First_Compiled_File is set to the name of the first file that is
856 -- compiled or that needs to be compiled. This is set to No_Name if no
857 -- compilations were needed.
858 --
859 -- Most_Recent_Obj_File is set to the full name of the most recent
860 -- object file found when no compilations are needed, that is when
861 -- First_Compiled_File is set to No_Name. When First_Compiled_File
862 -- is set then Most_Recent_Obj_File is set to No_Name.
863 --
864 -- Most_Recent_Obj_Stamp is the time stamp of Most_Recent_Obj_File.
865 --
866 -- Main_Unit is set to True if Main_Source can be a main unit.
867 -- If Do_Not_Execute is False and First_Compiled_File /= No_Name
868 -- the value of Main_Unit is always False.
869 -- Is this used any more??? It is certainly not used by gnatmake???
870 --
871 -- Compilation_Failures is a count of compilation failures. This count
872 -- is used to extract compilation failure reports with Extract_Failure.
873 --
874 -- Main_Index, when not zero, is the index of the main unit in source
875 -- file Main_Source which is a multi-unit source.
876 -- Zero indicates that Main_Source is a single unit source file.
877 --
878 -- Check_Readonly_Files set it to True to compile source files
879 -- which library files are read-only. When compiling GNAT predefined
880 -- files the "-gnatg" flag is used.
881 --
882 -- Do_Not_Execute set it to True to find out the first source that
883 -- needs to be recompiled, but without recompiling it. This file is
884 -- saved in First_Compiled_File.
885 --
886 -- Force_Compilations forces all compilations no matter what but
887 -- recompiles read-only files only if Check_Readonly_Files
888 -- is set.
889 --
890 -- Keep_Going when True keep compiling even in the presence of
891 -- compilation errors.
892 --
893 -- In_Place_Mode when True save library/object files in their object
894 -- directory if they already exist; otherwise, in the source directory.
895 --
896 -- Initialize_ALI_Data set it to True when you want to initialize ALI
897 -- data-structures. This is what you should do most of the time.
898 -- (especially the first time around when you call this routine).
899 -- This parameter is set to False to preserve previously recorded
900 -- ALI file data.
901 --
902 -- Max_Process is the maximum number of processes that should be spawned
903 -- to carry out compilations.
904 --
905 -- Flags in Package Opt Affecting Compile_Sources
906 -- -----------------------------------------------
907 --
908 -- Check_Object_Consistency set it to False to omit all consistency
909 -- checks between an .ali file and its corresponding object file.
910 -- When this flag is set to true, every time an .ali is read,
911 -- package Osint checks that the corresponding object file
912 -- exists and is more recent than the .ali.
913 --
914 -- Use of Name Table Info
915 -- ----------------------
916 --
917 -- All file names manipulated by Compile_Sources are entered into the
918 -- Names table. The Byte field of a source file is used to mark it.
919 --
920 -- Calling Compile_Sources Several Times
921 -- -------------------------------------
922 --
923 -- Upon return from Compile_Sources all the ALI data structures are left
924 -- intact for further browsing. HOWEVER upon entry to this routine ALI
925 -- data structures are re-initialized if parameter Initialize_ALI_Data
926 -- above is set to true. Typically this is what you want the first time
927 -- you call Compile_Sources. You should not load an ali file, call this
928 -- routine with flag Initialize_ALI_Data set to True and then expect
929 -- that ALI information to be around after the call. Note that the first
930 -- time you call Compile_Sources you better set Initialize_ALI_Data to
931 -- True unless you have called Initialize_ALI yourself.
932 --
933 -- Compile_Sources ALGORITHM : Compile_Sources (Main_Source)
934 -- -------------------------
935 --
936 -- 1. Insert Main_Source in a Queue (Q) and mark it.
937 --
938 -- 2. Let unit.adb be the file at the head of the Q. If unit.adb is
939 -- missing but its corresponding ali file is in an Ada library directory
940 -- (see below) then, remove unit.adb from the Q and goto step 4.
941 -- Otherwise, look at the files under the D (dependency) section of
942 -- unit.ali. If unit.ali does not exist or some of the time stamps do
943 -- not match, (re)compile unit.adb.
944 --
945 -- An Ada library directory is a directory containing Ada specs, ali
946 -- and object files but no source files for the bodies. An Ada library
947 -- directory is communicated to gnatmake by means of some switch so that
948 -- gnatmake can skip the sources whole ali are in that directory.
949 -- There are two reasons for skipping the sources in this case. Firstly,
950 -- Ada libraries typically come without full sources but binding and
951 -- linking against those libraries is still possible. Secondly, it would
952 -- be very wasteful for gnatmake to systematically check the consistency
953 -- of every external Ada library used in a program. The binder is
954 -- already in charge of catching any potential inconsistencies.
955 --
956 -- 3. Look into the W section of unit.ali and insert into the Q all
957 -- unmarked source files. Mark all files newly inserted in the Q.
958 -- Specifically, assuming that the W section looks like
959 --
960 -- W types%s types.adb types.ali
961 -- W unchecked_deallocation%s
962 -- W xref_tab%s xref_tab.adb xref_tab.ali
963 --
964 -- Then xref_tab.adb and types.adb are inserted in the Q if they are not
965 -- already marked.
966 -- Note that there is no file listed under W unchecked_deallocation%s
967 -- so no generic body should ever be explicitly compiled (unless the
968 -- Main_Source at the start was a generic body).
969 --
970 -- 4. Repeat steps 2 and 3 above until the Q is empty
971 --
972 -- Note that the above algorithm works because the units withed in
973 -- subunits are transitively included in the W section (with section) of
974 -- the main unit. Likewise the withed units in a generic body needed
975 -- during a compilation are also transitively included in the W section
976 -- of the originally compiled file.
977
978 procedure Initialize;
979 -- Performs default and package initialization. Therefore,
980 -- Compile_Sources can be called by an external unit.
981
982 procedure Link
983 (ALI_File : File_Name_Type;
984 Args : Argument_List;
985 Success : out Boolean);
986 -- Links ALI_File. Args are the arguments to pass to the linker.
987 -- Args must have a lower bound of 1. Success indicates if the link
988 -- succeeded or not.
989
990 procedure Scan_Make_Arg (Argv : String; And_Save : Boolean);
991 -- Scan make arguments. Argv is a single argument to be processed
992
993 -------------------
994 -- Add_Arguments --
995 -------------------
996
997 procedure Add_Arguments (Args : Argument_List) is
998 begin
999 if Arguments = null then
1000 Arguments := new Argument_List (1 .. Args'Length + 10);
1001
1002 else
1003 while Last_Argument + Args'Length > Arguments'Last loop
1004 declare
1005 New_Arguments : constant Argument_List_Access :=
1006 new Argument_List (1 .. Arguments'Last * 2);
1007 begin
1008 New_Arguments (1 .. Last_Argument) :=
1009 Arguments (1 .. Last_Argument);
1010 Arguments := New_Arguments;
1011 end;
1012 end loop;
1013 end if;
1014
1015 Arguments (Last_Argument + 1 .. Last_Argument + Args'Length) := Args;
1016 Last_Argument := Last_Argument + Args'Length;
1017 end Add_Arguments;
1018
1019 -- --------------------
1020 -- -- Add_Dependency --
1021 -- --------------------
1022 --
1023 -- procedure Add_Dependency (S : File_Name_Type; On : File_Name_Type) is
1024 -- begin
1025 -- Dependencies.Increment_Last;
1026 -- Dependencies.Table (Dependencies.Last) := (S, On);
1027 -- end Add_Dependency;
1028
1029 ----------------------------
1030 -- Add_Library_Search_Dir --
1031 ----------------------------
1032
1033 procedure Add_Library_Search_Dir
1034 (Path : String;
1035 On_Command_Line : Boolean)
1036 is
1037 begin
1038 if On_Command_Line then
1039 Add_Lib_Search_Dir (Normalize_Pathname (Path));
1040
1041 else
1042 Get_Name_String
1043 (Project_Tree.Projects.Table (Main_Project).Display_Directory);
1044 Add_Lib_Search_Dir
1045 (Normalize_Pathname (Path, Name_Buffer (1 .. Name_Len)));
1046 end if;
1047 end Add_Library_Search_Dir;
1048
1049 --------------------
1050 -- Add_Object_Dir --
1051 --------------------
1052
1053 procedure Add_Object_Dir (N : String) is
1054 begin
1055 Add_Lib_Search_Dir (N);
1056
1057 if Verbose_Mode then
1058 Write_Str ("Adding object directory """);
1059 Write_Str (N);
1060 Write_Str (""".");
1061 Write_Eol;
1062 end if;
1063 end Add_Object_Dir;
1064
1065 --------------------
1066 -- Add_Source_Dir --
1067 --------------------
1068
1069 procedure Add_Source_Dir (N : String) is
1070 begin
1071 Add_Src_Search_Dir (N);
1072
1073 if Verbose_Mode then
1074 Write_Str ("Adding source directory """);
1075 Write_Str (N);
1076 Write_Str (""".");
1077 Write_Eol;
1078 end if;
1079 end Add_Source_Dir;
1080
1081 ---------------------------
1082 -- Add_Source_Search_Dir --
1083 ---------------------------
1084
1085 procedure Add_Source_Search_Dir
1086 (Path : String;
1087 On_Command_Line : Boolean)
1088 is
1089 begin
1090 if On_Command_Line then
1091 Add_Src_Search_Dir (Normalize_Pathname (Path));
1092
1093 else
1094 Get_Name_String
1095 (Project_Tree.Projects.Table (Main_Project).Display_Directory);
1096 Add_Src_Search_Dir
1097 (Normalize_Pathname (Path, Name_Buffer (1 .. Name_Len)));
1098 end if;
1099 end Add_Source_Search_Dir;
1100
1101 ----------------
1102 -- Add_Switch --
1103 ----------------
1104
1105 procedure Add_Switch
1106 (S : String_Access;
1107 Program : Make_Program_Type;
1108 Append_Switch : Boolean := True;
1109 And_Save : Boolean := True)
1110 is
1111 generic
1112 with package T is new Table.Table (<>);
1113 procedure Generic_Position (New_Position : out Integer);
1114 -- Generic procedure that chooses a position for S in T at the
1115 -- beginning or the end, depending on the boolean Append_Switch.
1116 -- Calling this procedure may expand the table.
1117
1118 ----------------------
1119 -- Generic_Position --
1120 ----------------------
1121
1122 procedure Generic_Position (New_Position : out Integer) is
1123 begin
1124 T.Increment_Last;
1125
1126 if Append_Switch then
1127 New_Position := Integer (T.Last);
1128 else
1129 for J in reverse T.Table_Index_Type'Succ (T.First) .. T.Last loop
1130 T.Table (J) := T.Table (T.Table_Index_Type'Pred (J));
1131 end loop;
1132
1133 New_Position := Integer (T.First);
1134 end if;
1135 end Generic_Position;
1136
1137 procedure Gcc_Switches_Pos is new Generic_Position (Gcc_Switches);
1138 procedure Binder_Switches_Pos is new Generic_Position (Binder_Switches);
1139 procedure Linker_Switches_Pos is new Generic_Position (Linker_Switches);
1140
1141 procedure Saved_Gcc_Switches_Pos is new
1142 Generic_Position (Saved_Gcc_Switches);
1143
1144 procedure Saved_Binder_Switches_Pos is new
1145 Generic_Position (Saved_Binder_Switches);
1146
1147 procedure Saved_Linker_Switches_Pos is new
1148 Generic_Position (Saved_Linker_Switches);
1149
1150 New_Position : Integer;
1151
1152 -- Start of processing for Add_Switch
1153
1154 begin
1155 if And_Save then
1156 case Program is
1157 when Compiler =>
1158 Saved_Gcc_Switches_Pos (New_Position);
1159 Saved_Gcc_Switches.Table (New_Position) := S;
1160
1161 when Binder =>
1162 Saved_Binder_Switches_Pos (New_Position);
1163 Saved_Binder_Switches.Table (New_Position) := S;
1164
1165 when Linker =>
1166 Saved_Linker_Switches_Pos (New_Position);
1167 Saved_Linker_Switches.Table (New_Position) := S;
1168
1169 when None =>
1170 raise Program_Error;
1171 end case;
1172
1173 else
1174 case Program is
1175 when Compiler =>
1176 Gcc_Switches_Pos (New_Position);
1177 Gcc_Switches.Table (New_Position) := S;
1178
1179 when Binder =>
1180 Binder_Switches_Pos (New_Position);
1181 Binder_Switches.Table (New_Position) := S;
1182
1183 when Linker =>
1184 Linker_Switches_Pos (New_Position);
1185 Linker_Switches.Table (New_Position) := S;
1186
1187 when None =>
1188 raise Program_Error;
1189 end case;
1190 end if;
1191 end Add_Switch;
1192
1193 procedure Add_Switch
1194 (S : String;
1195 Program : Make_Program_Type;
1196 Append_Switch : Boolean := True;
1197 And_Save : Boolean := True)
1198 is
1199 begin
1200 Add_Switch (S => new String'(S),
1201 Program => Program,
1202 Append_Switch => Append_Switch,
1203 And_Save => And_Save);
1204 end Add_Switch;
1205
1206 ------------------
1207 -- Add_Switches --
1208 ------------------
1209
1210 procedure Add_Switches
1211 (The_Package : Package_Id;
1212 File_Name : String;
1213 Index : Int;
1214 Program : Make_Program_Type)
1215 is
1216 Switches : Variable_Value;
1217 Switch_List : String_List_Id;
1218 Element : String_Element;
1219
1220 begin
1221 if File_Name'Length > 0 then
1222 Name_Len := File_Name'Length;
1223 Name_Buffer (1 .. Name_Len) := File_Name;
1224 Switches :=
1225 Switches_Of
1226 (Source_File => Name_Find,
1227 Source_File_Name => File_Name,
1228 Source_Index => Index,
1229 Naming => Project_Tree.Projects.Table
1230 (Main_Project).Naming,
1231 In_Package => The_Package,
1232 Allow_ALI =>
1233 Program = Binder or else Program = Linker);
1234
1235 case Switches.Kind is
1236 when Undefined =>
1237 null;
1238
1239 when List =>
1240 Program_Args := Program;
1241
1242 Switch_List := Switches.Values;
1243
1244 while Switch_List /= Nil_String loop
1245 Element := Project_Tree.String_Elements.Table (Switch_List);
1246 Get_Name_String (Element.Value);
1247
1248 if Name_Len > 0 then
1249 declare
1250 Argv : constant String := Name_Buffer (1 .. Name_Len);
1251 -- We need a copy, because Name_Buffer may be modified
1252
1253 begin
1254 if Verbose_Mode then
1255 Write_Str (" Adding ");
1256 Write_Line (Argv);
1257 end if;
1258
1259 Scan_Make_Arg (Argv, And_Save => False);
1260 end;
1261 end if;
1262
1263 Switch_List := Element.Next;
1264 end loop;
1265
1266 when Single =>
1267 Program_Args := Program;
1268 Get_Name_String (Switches.Value);
1269
1270 if Name_Len > 0 then
1271 declare
1272 Argv : constant String := Name_Buffer (1 .. Name_Len);
1273 -- We need a copy, because Name_Buffer may be modified
1274
1275 begin
1276 if Verbose_Mode then
1277 Write_Str (" Adding ");
1278 Write_Line (Argv);
1279 end if;
1280
1281 Scan_Make_Arg (Argv, And_Save => False);
1282 end;
1283 end if;
1284 end case;
1285 end if;
1286 end Add_Switches;
1287
1288 ----------
1289 -- Bind --
1290 ----------
1291
1292 procedure Bind (ALI_File : File_Name_Type; Args : Argument_List) is
1293 Bind_Args : Argument_List (1 .. Args'Last + 2);
1294 Bind_Last : Integer;
1295 Success : Boolean;
1296
1297 begin
1298 pragma Assert (Args'First = 1);
1299
1300 -- Optimize the simple case where the gnatbind command line looks like
1301 -- gnatbind -aO. -I- file.ali --into-> gnatbind file.adb
1302
1303 if Args'Length = 2
1304 and then Args (Args'First).all = "-aO" & Normalized_CWD
1305 and then Args (Args'Last).all = "-I-"
1306 and then ALI_File = Strip_Directory (ALI_File)
1307 then
1308 Bind_Last := Args'First - 1;
1309
1310 else
1311 Bind_Last := Args'Last;
1312 Bind_Args (Args'Range) := Args;
1313 end if;
1314
1315 -- It is completely pointless to re-check source file time stamps. This
1316 -- has been done already by gnatmake
1317
1318 Bind_Last := Bind_Last + 1;
1319 Bind_Args (Bind_Last) := Do_Not_Check_Flag;
1320
1321 Get_Name_String (ALI_File);
1322
1323 Bind_Last := Bind_Last + 1;
1324 Bind_Args (Bind_Last) := new String'(Name_Buffer (1 .. Name_Len));
1325
1326 GNAT.OS_Lib.Normalize_Arguments (Bind_Args (Args'First .. Bind_Last));
1327
1328 Display (Gnatbind.all, Bind_Args (Args'First .. Bind_Last));
1329
1330 if Gnatbind_Path = null then
1331 Make_Failed ("error, unable to locate ", Gnatbind.all);
1332 end if;
1333
1334 GNAT.OS_Lib.Spawn
1335 (Gnatbind_Path.all, Bind_Args (Args'First .. Bind_Last), Success);
1336
1337 if not Success then
1338 Make_Failed ("*** bind failed.");
1339 end if;
1340 end Bind;
1341
1342 --------------------------------
1343 -- Change_To_Object_Directory --
1344 --------------------------------
1345
1346 procedure Change_To_Object_Directory (Project : Project_Id) is
1347 Actual_Project : Project_Id;
1348 Object_Directory : Path_Name_Type;
1349
1350 begin
1351 -- For sources outside of any project, compilation occurs in the object
1352 -- directory of the main project, otherwise we use the project given.
1353
1354 if Project = No_Project then
1355 Actual_Project := Main_Project;
1356 else
1357 Actual_Project := Project;
1358 end if;
1359
1360 -- Nothing to do if the current working directory is already the correct
1361 -- object directory.
1362
1363 if Project_Of_Current_Object_Directory /= Actual_Project then
1364 Project_Of_Current_Object_Directory := Actual_Project;
1365 Object_Directory :=
1366 Project_Tree.Projects.Table (Actual_Project).Object_Directory;
1367
1368 -- Set the working directory to the object directory of the actual
1369 -- project.
1370
1371 if Verbose_Mode then
1372 Write_Str ("Changing to object directory of """);
1373 Write_Name
1374 (Project_Tree.Projects.Table (Actual_Project).Display_Name);
1375 Write_Str (""": """);
1376 Write_Name (Object_Directory);
1377 Write_Line ("""");
1378 end if;
1379
1380 Change_Dir (Get_Name_String (Object_Directory));
1381 end if;
1382
1383 exception
1384 -- Fail if unable to change to the object directory
1385
1386 when Directory_Error =>
1387 Make_Failed ("unable to change to object directory """ &
1388 Get_Name_String
1389 (Project_Tree.Projects.Table
1390 (Actual_Project).Object_Directory) &
1391 """ of project " &
1392 Get_Name_String (Project_Tree.Projects.Table
1393 (Actual_Project).Display_Name));
1394 end Change_To_Object_Directory;
1395
1396 -----------
1397 -- Check --
1398 -----------
1399
1400 procedure Check
1401 (Source_File : File_Name_Type;
1402 Source_Index : Int;
1403 The_Args : Argument_List;
1404 Lib_File : File_Name_Type;
1405 Read_Only : Boolean;
1406 ALI : out ALI_Id;
1407 O_File : out File_Name_Type;
1408 O_Stamp : out Time_Stamp_Type)
1409 is
1410 function First_New_Spec (A : ALI_Id) return File_Name_Type;
1411 -- Looks in the with table entries of A and returns the spec file name
1412 -- of the first withed unit (subprogram) for which no spec existed when
1413 -- A was generated but for which there exists one now, implying that A
1414 -- is now obsolete. If no such unit is found No_File is returned.
1415 -- Otherwise the spec file name of the unit is returned.
1416 --
1417 -- **WARNING** in the event of Uname format modifications, one *MUST*
1418 -- make sure this function is also updated.
1419 --
1420 -- Note: This function should really be in ali.adb and use Uname
1421 -- services, but this causes the whole compiler to be dragged along
1422 -- for gnatbind and gnatmake.
1423
1424 --------------------
1425 -- First_New_Spec --
1426 --------------------
1427
1428 function First_New_Spec (A : ALI_Id) return File_Name_Type is
1429 Spec_File_Name : File_Name_Type := No_File;
1430
1431 function New_Spec (Uname : Unit_Name_Type) return Boolean;
1432 -- Uname is the name of the spec or body of some ada unit. This
1433 -- function returns True if the Uname is the name of a body which has
1434 -- a spec not mentioned in ALI file A. If True is returned
1435 -- Spec_File_Name above is set to the name of this spec file.
1436
1437 --------------
1438 -- New_Spec --
1439 --------------
1440
1441 function New_Spec (Uname : Unit_Name_Type) return Boolean is
1442 Spec_Name : Unit_Name_Type;
1443 File_Name : File_Name_Type;
1444
1445 begin
1446 -- Test whether Uname is the name of a body unit (ie ends with %b)
1447
1448 Get_Name_String (Uname);
1449 pragma
1450 Assert (Name_Len > 2 and then Name_Buffer (Name_Len - 1) = '%');
1451
1452 if Name_Buffer (Name_Len) /= 'b' then
1453 return False;
1454 end if;
1455
1456 -- Convert unit name into spec name
1457
1458 -- ??? this code seems dubious in presence of pragma
1459 -- Source_File_Name since there is no more direct relationship
1460 -- between unit name and file name.
1461
1462 -- ??? Further, what about alternative subunit naming
1463
1464 Name_Buffer (Name_Len) := 's';
1465 Spec_Name := Name_Find;
1466 File_Name := Get_File_Name (Spec_Name, Subunit => False);
1467
1468 -- Look if File_Name is mentioned in A's sdep list.
1469 -- If not look if the file exists. If it does return True.
1470
1471 for D in
1472 ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep
1473 loop
1474 if Sdep.Table (D).Sfile = File_Name then
1475 return False;
1476 end if;
1477 end loop;
1478
1479 if Full_Source_Name (File_Name) /= No_File then
1480 Spec_File_Name := File_Name;
1481 return True;
1482 end if;
1483
1484 return False;
1485 end New_Spec;
1486
1487 -- Start of processing for First_New_Spec
1488
1489 begin
1490 U_Chk : for U in
1491 ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit
1492 loop
1493 exit U_Chk when Units.Table (U).Utype = Is_Body_Only
1494 and then New_Spec (Units.Table (U).Uname);
1495
1496 for W in Units.Table (U).First_With
1497 ..
1498 Units.Table (U).Last_With
1499 loop
1500 exit U_Chk when
1501 Withs.Table (W).Afile /= No_File
1502 and then New_Spec (Withs.Table (W).Uname);
1503 end loop;
1504 end loop U_Chk;
1505
1506 return Spec_File_Name;
1507 end First_New_Spec;
1508
1509 ---------------------------------
1510 -- Data declarations for Check --
1511 ---------------------------------
1512
1513 Full_Lib_File : File_Name_Type;
1514 -- Full name of current library file
1515
1516 Full_Obj_File : File_Name_Type;
1517 -- Full name of the object file corresponding to Lib_File
1518
1519 Lib_Stamp : Time_Stamp_Type;
1520 -- Time stamp of the current ada library file
1521
1522 Obj_Stamp : Time_Stamp_Type;
1523 -- Time stamp of the current object file
1524
1525 Modified_Source : File_Name_Type;
1526 -- The first source in Lib_File whose current time stamp differs
1527 -- from that stored in Lib_File.
1528
1529 New_Spec : File_Name_Type;
1530 -- If Lib_File contains in its W (with) section a body (for a
1531 -- subprogram) for which there exists a spec and the spec did not
1532 -- appear in the Sdep section of Lib_File, New_Spec contains the file
1533 -- name of this new spec.
1534
1535 Source_Name : File_Name_Type;
1536 Text : Text_Buffer_Ptr;
1537
1538 Prev_Switch : String_Access;
1539 -- Previous switch processed
1540
1541 Arg : Arg_Id := Arg_Id'First;
1542 -- Current index in Args.Table for a given unit (init to stop warning)
1543
1544 Switch_Found : Boolean;
1545 -- True if a given switch has been found
1546
1547 ALI_Project : Project_Id;
1548 -- If the ALI file is in the object directory of a project, this is
1549 -- the project id.
1550
1551 -- Start of processing for Check
1552
1553 begin
1554 pragma Assert (Lib_File /= No_File);
1555
1556 -- If ALI file is read-only, temporarily set Check_Object_Consistency to
1557 -- False. We don't care if the object file is not there (presumably a
1558 -- library will be used for linking.)
1559
1560 if Read_Only then
1561 declare
1562 Saved_Check_Object_Consistency : constant Boolean :=
1563 Check_Object_Consistency;
1564 begin
1565 Check_Object_Consistency := False;
1566 Text := Read_Library_Info (Lib_File);
1567 Check_Object_Consistency := Saved_Check_Object_Consistency;
1568 end;
1569
1570 else
1571 Text := Read_Library_Info (Lib_File);
1572 end if;
1573
1574 Full_Lib_File := Full_Library_Info_Name;
1575 Full_Obj_File := Full_Object_File_Name;
1576 Lib_Stamp := Current_Library_File_Stamp;
1577 Obj_Stamp := Current_Object_File_Stamp;
1578
1579 if Full_Lib_File = No_File then
1580 Verbose_Msg
1581 (Lib_File,
1582 "being checked ...",
1583 Prefix => " ",
1584 Minimum_Verbosity => Opt.Medium);
1585 else
1586 Verbose_Msg
1587 (Full_Lib_File,
1588 "being checked ...",
1589 Prefix => " ",
1590 Minimum_Verbosity => Opt.Medium);
1591 end if;
1592
1593 ALI := No_ALI_Id;
1594 O_File := Full_Obj_File;
1595 O_Stamp := Obj_Stamp;
1596
1597 if Text = null then
1598 if Full_Lib_File = No_File then
1599 Verbose_Msg (Lib_File, "missing.");
1600
1601 elsif Obj_Stamp (Obj_Stamp'First) = ' ' then
1602 Verbose_Msg (Full_Obj_File, "missing.");
1603
1604 else
1605 Verbose_Msg
1606 (Full_Lib_File, "(" & String (Lib_Stamp) & ") newer than",
1607 Full_Obj_File, "(" & String (Obj_Stamp) & ")");
1608 end if;
1609
1610 else
1611 ALI := Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
1612 Free (Text);
1613
1614 if ALI = No_ALI_Id then
1615 Verbose_Msg (Full_Lib_File, "incorrectly formatted ALI file");
1616 return;
1617
1618 elsif ALIs.Table (ALI).Ver (1 .. ALIs.Table (ALI).Ver_Len) /=
1619 Verbose_Library_Version
1620 then
1621 Verbose_Msg (Full_Lib_File, "compiled with old GNAT version");
1622 ALI := No_ALI_Id;
1623 return;
1624 end if;
1625
1626 -- Don't take Ali file into account if it was generated with
1627 -- errors.
1628
1629 if ALIs.Table (ALI).Compile_Errors then
1630 Verbose_Msg (Full_Lib_File, "had errors, must be recompiled");
1631 ALI := No_ALI_Id;
1632 return;
1633 end if;
1634
1635 -- Don't take Ali file into account if it was generated without
1636 -- object.
1637
1638 if Operating_Mode /= Check_Semantics
1639 and then ALIs.Table (ALI).No_Object
1640 then
1641 Verbose_Msg (Full_Lib_File, "has no corresponding object");
1642 ALI := No_ALI_Id;
1643 return;
1644 end if;
1645
1646 -- Check for matching compiler switches if needed
1647
1648 if Check_Switches then
1649
1650 -- First, collect all the switches
1651
1652 Collect_Arguments (Source_File, Source_Index, The_Args);
1653
1654 Prev_Switch := Dummy_Switch;
1655
1656 Get_Name_String (ALIs.Table (ALI).Sfile);
1657
1658 Switches_To_Check.Set_Last (0);
1659
1660 for J in 1 .. Last_Argument loop
1661
1662 -- Skip non switches -c, -I and -o switches
1663
1664 if Arguments (J) (1) = '-'
1665 and then Arguments (J) (2) /= 'c'
1666 and then Arguments (J) (2) /= 'o'
1667 and then Arguments (J) (2) /= 'I'
1668 then
1669 Normalize_Compiler_Switches
1670 (Arguments (J).all,
1671 Normalized_Switches,
1672 Last_Norm_Switch);
1673
1674 for K in 1 .. Last_Norm_Switch loop
1675 Switches_To_Check.Increment_Last;
1676 Switches_To_Check.Table (Switches_To_Check.Last) :=
1677 Normalized_Switches (K);
1678 end loop;
1679 end if;
1680 end loop;
1681
1682 for J in 1 .. Switches_To_Check.Last loop
1683
1684 -- Comparing switches is delicate because gcc reorders a number
1685 -- of switches, according to lang-specs.h, but gnatmake doesn't
1686 -- have sufficient knowledge to perform the same reordering.
1687 -- Instead, we ignore orders between different "first letter"
1688 -- switches, but keep orders between same switches, e.g -O -O2
1689 -- is different than -O2 -O, but -g -O is equivalent to -O -g.
1690
1691 if Switches_To_Check.Table (J) (2) /= Prev_Switch (2) or else
1692 (Prev_Switch'Length >= 6 and then
1693 Prev_Switch (2 .. 5) = "gnat" and then
1694 Switches_To_Check.Table (J)'Length >= 6 and then
1695 Switches_To_Check.Table (J) (2 .. 5) = "gnat" and then
1696 Prev_Switch (6) /= Switches_To_Check.Table (J) (6))
1697 then
1698 Prev_Switch := Switches_To_Check.Table (J);
1699 Arg :=
1700 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg;
1701 end if;
1702
1703 Switch_Found := False;
1704
1705 for K in Arg ..
1706 Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1707 loop
1708 if
1709 Switches_To_Check.Table (J).all = Args.Table (K).all
1710 then
1711 Arg := K + 1;
1712 Switch_Found := True;
1713 exit;
1714 end if;
1715 end loop;
1716
1717 if not Switch_Found then
1718 if Verbose_Mode then
1719 Verbose_Msg (ALIs.Table (ALI).Sfile,
1720 "switch mismatch """ &
1721 Switches_To_Check.Table (J).all & '"');
1722 end if;
1723
1724 ALI := No_ALI_Id;
1725 return;
1726 end if;
1727 end loop;
1728
1729 if Switches_To_Check.Last /=
1730 Integer (Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg -
1731 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg + 1)
1732 then
1733 if Verbose_Mode then
1734 Verbose_Msg (ALIs.Table (ALI).Sfile,
1735 "different number of switches");
1736
1737 for K in Units.Table (ALIs.Table (ALI).First_Unit).First_Arg
1738 .. Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1739 loop
1740 Write_Str (Args.Table (K).all);
1741 Write_Char (' ');
1742 end loop;
1743
1744 Write_Eol;
1745
1746 for J in 1 .. Switches_To_Check.Last loop
1747 Write_Str (Switches_To_Check.Table (J).all);
1748 Write_Char (' ');
1749 end loop;
1750
1751 Write_Eol;
1752 end if;
1753
1754 ALI := No_ALI_Id;
1755 return;
1756 end if;
1757 end if;
1758
1759 -- Get the source files and their message digests. Note that some
1760 -- sources may be missing if ALI is out-of-date.
1761
1762 Set_Source_Table (ALI);
1763
1764 Modified_Source := Time_Stamp_Mismatch (ALI, Read_Only);
1765
1766 if Modified_Source /= No_File then
1767 ALI := No_ALI_Id;
1768
1769 if Verbose_Mode then
1770 Source_Name := Full_Source_Name (Modified_Source);
1771
1772 if Source_Name /= No_File then
1773 Verbose_Msg (Source_Name, "time stamp mismatch");
1774 else
1775 Verbose_Msg (Modified_Source, "missing");
1776 end if;
1777 end if;
1778
1779 else
1780 New_Spec := First_New_Spec (ALI);
1781
1782 if New_Spec /= No_File then
1783 ALI := No_ALI_Id;
1784
1785 if Verbose_Mode then
1786 Source_Name := Full_Source_Name (New_Spec);
1787
1788 if Source_Name /= No_File then
1789 Verbose_Msg (Source_Name, "new spec");
1790 else
1791 Verbose_Msg (New_Spec, "old spec missing");
1792 end if;
1793 end if;
1794
1795 elsif Main_Project /= No_Project then
1796
1797 -- Check if a file name does not correspond to the mapping of
1798 -- units to file names.
1799
1800 declare
1801 WR : With_Record;
1802 Unit_Name : Name_Id;
1803 UID : Prj.Unit_Index;
1804 U_Data : Unit_Data;
1805
1806 begin
1807 U_Chk :
1808 for U in ALIs.Table (ALI).First_Unit ..
1809 ALIs.Table (ALI).Last_Unit
1810 loop
1811 W_Check :
1812 for W in Units.Table (U).First_With
1813 ..
1814 Units.Table (U).Last_With
1815 loop
1816 WR := Withs.Table (W);
1817
1818 if WR.Sfile /= No_File then
1819 Get_Name_String (WR.Uname);
1820 Name_Len := Name_Len - 2;
1821 Unit_Name := Name_Find;
1822
1823 UID := Units_Htable.Get
1824 (Project_Tree.Units_HT, Unit_Name);
1825
1826 if UID /= Prj.No_Unit_Index then
1827 U_Data := Project_Tree.Units.Table (UID);
1828
1829 if U_Data.File_Names (Body_Part).Name /= WR.Sfile
1830 and then
1831 U_Data.File_Names (Specification).Name /=
1832 WR.Sfile
1833 then
1834 ALI := No_ALI_Id;
1835
1836 Verbose_Msg
1837 (Unit_Name, " sources does not include ",
1838 Name_Id (WR.Sfile));
1839
1840 return;
1841 end if;
1842 end if;
1843 end if;
1844 end loop W_Check;
1845 end loop U_Chk;
1846 end;
1847
1848 -- Check that the ALI file is in the correct object directory.
1849 -- If it is in the object directory of a project that is
1850 -- extended and it depends on a source that is in one of its
1851 -- extending projects, then the ALI file is not in the correct
1852 -- object directory.
1853
1854 -- First, find the project of this ALI file. As there may be
1855 -- several projects with the same object directory, we first
1856 -- need to find the project of the source.
1857
1858 ALI_Project := No_Project;
1859
1860 declare
1861 Udata : Prj.Unit_Data;
1862
1863 begin
1864 for U in 1 .. Unit_Table.Last (Project_Tree.Units) loop
1865 Udata := Project_Tree.Units.Table (U);
1866
1867 if Udata.File_Names (Body_Part).Name = Source_File then
1868 ALI_Project := Udata.File_Names (Body_Part).Project;
1869 exit;
1870
1871 elsif
1872 Udata.File_Names (Specification).Name = Source_File
1873 then
1874 ALI_Project :=
1875 Udata.File_Names (Specification).Project;
1876 exit;
1877 end if;
1878 end loop;
1879 end;
1880
1881 if ALI_Project = No_Project then
1882 return;
1883 end if;
1884
1885 declare
1886 Obj_Dir : Path_Name_Type;
1887 Res_Obj_Dir : constant String :=
1888 Normalize_Pathname
1889 (Dir_Name
1890 (Get_Name_String (Full_Lib_File)),
1891 Resolve_Links => True,
1892 Case_Sensitive => False);
1893
1894 begin
1895 Name_Len := 0;
1896 Add_Str_To_Name_Buffer (Res_Obj_Dir);
1897
1898 if Name_Len > 1 and then
1899 (Name_Buffer (Name_Len) = '/' or else
1900 Name_Buffer (Name_Len) = Directory_Separator)
1901 then
1902 Name_Len := Name_Len - 1;
1903 end if;
1904
1905 Obj_Dir := Name_Find;
1906
1907 while ALI_Project /= No_Project and then
1908 Obj_Dir /=
1909 Project_Tree.Projects.Table
1910 (ALI_Project).Object_Directory
1911 loop
1912 ALI_Project :=
1913 Project_Tree.Projects.Table (ALI_Project).Extended_By;
1914 end loop;
1915 end;
1916
1917 if ALI_Project = No_Project then
1918 ALI := No_ALI_Id;
1919
1920 Verbose_Msg
1921 (Lib_File, " wrong object directory");
1922 return;
1923 end if;
1924
1925 -- If the ALI project is not extended, then it must be in
1926 -- the correct object directory.
1927
1928 if Project_Tree.Projects.Table (ALI_Project).Extended_By =
1929 No_Project
1930 then
1931 return;
1932 end if;
1933
1934 -- Count the extending projects
1935
1936 declare
1937 Num_Ext : Natural;
1938 Proj : Project_Id;
1939
1940 begin
1941 Num_Ext := 0;
1942 Proj := ALI_Project;
1943 loop
1944 Proj := Project_Tree.Projects.Table (Proj).Extended_By;
1945 exit when Proj = No_Project;
1946 Num_Ext := Num_Ext + 1;
1947 end loop;
1948
1949 -- Make a list of the extending projects
1950
1951 declare
1952 Projects : array (1 .. Num_Ext) of Project_Id;
1953 Dep : Sdep_Record;
1954 OK : Boolean := True;
1955
1956 begin
1957 Proj := ALI_Project;
1958 for J in Projects'Range loop
1959 Proj := Project_Tree.Projects.Table (Proj).Extended_By;
1960 Projects (J) := Proj;
1961 end loop;
1962
1963 -- Now check if any of the dependant sources are in
1964 -- any of these extending projects.
1965
1966 D_Chk :
1967 for D in ALIs.Table (ALI).First_Sdep ..
1968 ALIs.Table (ALI).Last_Sdep
1969 loop
1970 Dep := Sdep.Table (D);
1971
1972 Proj := No_Project;
1973
1974 Unit_Loop :
1975 for
1976 UID in 1 .. Unit_Table.Last (Project_Tree.Units)
1977 loop
1978 if Project_Tree.Units.Table (UID).
1979 File_Names (Body_Part).Name = Dep.Sfile
1980 then
1981 Proj := Project_Tree.Units.Table (UID).
1982 File_Names (Body_Part).Project;
1983
1984 elsif Project_Tree.Units.Table (UID).
1985 File_Names (Specification).Name = Dep.Sfile
1986 then
1987 Proj := Project_Tree.Units.Table (UID).
1988 File_Names (Specification).Project;
1989 end if;
1990
1991 -- If a source is in a project, check if it is one
1992 -- in the list.
1993
1994 if Proj /= No_Project then
1995 for J in Projects'Range loop
1996 if Proj = Projects (J) then
1997 OK := False;
1998 exit D_Chk;
1999 end if;
2000 end loop;
2001
2002 exit Unit_Loop;
2003 end if;
2004 end loop Unit_Loop;
2005 end loop D_Chk;
2006
2007 -- If one of the dependent sources is in one project of
2008 -- the list, then we must recompile.
2009
2010 if not OK then
2011 ALI := No_ALI_Id;
2012 Verbose_Msg (Lib_File, " wrong object directory");
2013 end if;
2014 end;
2015 end;
2016 end if;
2017 end if;
2018 end if;
2019 end Check;
2020
2021 ------------------------
2022 -- Check_For_S_Switch --
2023 ------------------------
2024
2025 procedure Check_For_S_Switch is
2026 begin
2027 -- By default, we generate an object file
2028
2029 Output_Is_Object := True;
2030
2031 for Arg in 1 .. Last_Argument loop
2032 if Arguments (Arg).all = "-S" then
2033 Output_Is_Object := False;
2034
2035 elsif Arguments (Arg).all = "-c" then
2036 Output_Is_Object := True;
2037 end if;
2038 end loop;
2039 end Check_For_S_Switch;
2040
2041 --------------------------
2042 -- Check_Linker_Options --
2043 --------------------------
2044
2045 procedure Check_Linker_Options
2046 (E_Stamp : Time_Stamp_Type;
2047 O_File : out File_Name_Type;
2048 O_Stamp : out Time_Stamp_Type)
2049 is
2050 procedure Check_File (File : File_Name_Type);
2051 -- Update O_File and O_Stamp if the given file is younger than E_Stamp
2052 -- and O_Stamp, or if O_File is No_File and File does not exist.
2053
2054 function Get_Library_File (Name : String) return File_Name_Type;
2055 -- Return the full file name including path of a library based
2056 -- on the name specified with the -l linker option, using the
2057 -- Ada object path. Return No_File if no such file can be found.
2058
2059 type Char_Array is array (Natural) of Character;
2060 type Char_Array_Access is access constant Char_Array;
2061
2062 Template : Char_Array_Access;
2063 pragma Import (C, Template, "__gnat_library_template");
2064
2065 ----------------
2066 -- Check_File --
2067 ----------------
2068
2069 procedure Check_File (File : File_Name_Type) is
2070 Stamp : Time_Stamp_Type;
2071 Name : File_Name_Type := File;
2072
2073 begin
2074 Get_Name_String (Name);
2075
2076 -- Remove any trailing NUL characters
2077
2078 while Name_Len >= Name_Buffer'First
2079 and then Name_Buffer (Name_Len) = NUL
2080 loop
2081 Name_Len := Name_Len - 1;
2082 end loop;
2083
2084 if Name_Len = 0 then
2085 return;
2086
2087 elsif Name_Buffer (1) = '-' then
2088
2089 -- Do not check if File is a switch other than "-l"
2090
2091 if Name_Buffer (2) /= 'l' then
2092 return;
2093 end if;
2094
2095 -- The argument is a library switch, get actual name. It
2096 -- is necessary to make a copy of the relevant part of
2097 -- Name_Buffer as Get_Library_Name uses Name_Buffer as well.
2098
2099 declare
2100 Base_Name : constant String := Name_Buffer (3 .. Name_Len);
2101
2102 begin
2103 Name := Get_Library_File (Base_Name);
2104 end;
2105
2106 if Name = No_File then
2107 return;
2108 end if;
2109 end if;
2110
2111 Stamp := File_Stamp (Name);
2112
2113 -- Find the youngest object file that is younger than the
2114 -- executable. If no such file exist, record the first object
2115 -- file that is not found.
2116
2117 if (O_Stamp < Stamp and then E_Stamp < Stamp)
2118 or else (O_File = No_File and then Stamp (Stamp'First) = ' ')
2119 then
2120 O_Stamp := Stamp;
2121 O_File := Name;
2122
2123 -- Strip the trailing NUL if present
2124
2125 Get_Name_String (O_File);
2126
2127 if Name_Buffer (Name_Len) = NUL then
2128 Name_Len := Name_Len - 1;
2129 O_File := Name_Find;
2130 end if;
2131 end if;
2132 end Check_File;
2133
2134 ----------------------
2135 -- Get_Library_Name --
2136 ----------------------
2137
2138 -- See comments in a-adaint.c about template syntax
2139
2140 function Get_Library_File (Name : String) return File_Name_Type is
2141 File : File_Name_Type := No_File;
2142
2143 begin
2144 Name_Len := 0;
2145
2146 for Ptr in Template'Range loop
2147 case Template (Ptr) is
2148 when '*' =>
2149 Add_Str_To_Name_Buffer (Name);
2150
2151 when ';' =>
2152 File := Full_Lib_File_Name (Name_Find);
2153 exit when File /= No_File;
2154 Name_Len := 0;
2155
2156 when NUL =>
2157 exit;
2158
2159 when others =>
2160 Add_Char_To_Name_Buffer (Template (Ptr));
2161 end case;
2162 end loop;
2163
2164 -- The for loop exited because the end of the template
2165 -- was reached. File contains the last possible file name
2166 -- for the library.
2167
2168 if File = No_File and then Name_Len > 0 then
2169 File := Full_Lib_File_Name (Name_Find);
2170 end if;
2171
2172 return File;
2173 end Get_Library_File;
2174
2175 -- Start of processing for Check_Linker_Options
2176
2177 begin
2178 O_File := No_File;
2179 O_Stamp := (others => ' ');
2180
2181 -- Process linker options from the ALI files
2182
2183 for Opt in 1 .. Linker_Options.Last loop
2184 Check_File (File_Name_Type (Linker_Options.Table (Opt).Name));
2185 end loop;
2186
2187 -- Process options given on the command line
2188
2189 for Opt in Linker_Switches.First .. Linker_Switches.Last loop
2190
2191 -- Check if the previous Opt has one of the two switches
2192 -- that take an extra parameter. (See GCC manual.)
2193
2194 if Opt = Linker_Switches.First
2195 or else (Linker_Switches.Table (Opt - 1).all /= "-u"
2196 and then
2197 Linker_Switches.Table (Opt - 1).all /= "-Xlinker"
2198 and then
2199 Linker_Switches.Table (Opt - 1).all /= "-L")
2200 then
2201 Name_Len := 0;
2202 Add_Str_To_Name_Buffer (Linker_Switches.Table (Opt).all);
2203 Check_File (Name_Find);
2204 end if;
2205 end loop;
2206
2207 end Check_Linker_Options;
2208
2209 -----------------
2210 -- Check_Steps --
2211 -----------------
2212
2213 procedure Check_Steps is
2214 begin
2215 -- If either -c, -b or -l has been specified, we will not necessarily
2216 -- execute all steps.
2217
2218 if Make_Steps then
2219 Do_Compile_Step := Do_Compile_Step and Compile_Only;
2220 Do_Bind_Step := Do_Bind_Step and Bind_Only;
2221 Do_Link_Step := Do_Link_Step and Link_Only;
2222
2223 -- If -c has been specified, but not -b, ignore any potential -l
2224
2225 if Do_Compile_Step and then not Do_Bind_Step then
2226 Do_Link_Step := False;
2227 end if;
2228 end if;
2229 end Check_Steps;
2230
2231 -----------------------
2232 -- Collect_Arguments --
2233 -----------------------
2234
2235 procedure Collect_Arguments
2236 (Source_File : File_Name_Type;
2237 Source_Index : Int;
2238 Args : Argument_List)
2239 is
2240 begin
2241 Arguments_Collected := True;
2242 Arguments_Project := No_Project;
2243 Last_Argument := 0;
2244 Add_Arguments (Args);
2245
2246 if Main_Project /= No_Project then
2247 declare
2248 Source_File_Name : constant String :=
2249 Get_Name_String (Source_File);
2250 Compiler_Package : Prj.Package_Id;
2251 Switches : Prj.Variable_Value;
2252 Data : Project_Data;
2253
2254 begin
2255 Prj.Env.
2256 Get_Reference
2257 (Source_File_Name => Source_File_Name,
2258 Project => Arguments_Project,
2259 Path => Arguments_Path_Name,
2260 In_Tree => Project_Tree);
2261
2262 -- If the source is not a source of a project file, add the
2263 -- recorded arguments. Check will be done later if the source
2264 -- need to be compiled that the switch -x has been used.
2265
2266 if Arguments_Project = No_Project then
2267 Add_Arguments (The_Saved_Gcc_Switches.all);
2268
2269 elsif not Project_Tree.Projects.Table
2270 (Arguments_Project).Externally_Built
2271 then
2272 -- We get the project directory for the relative path
2273 -- switches and arguments.
2274
2275 Data := Project_Tree.Projects.Table (Arguments_Project);
2276
2277 -- If the source is in an extended project, we go to
2278 -- the ultimate extending project.
2279
2280 while Data.Extended_By /= No_Project loop
2281 Arguments_Project := Data.Extended_By;
2282 Data := Project_Tree.Projects.Table (Arguments_Project);
2283 end loop;
2284
2285 -- If building a dynamic or relocatable library, compile with
2286 -- PIC option, if it exists.
2287
2288 if Data.Library and then Data.Library_Kind /= Static then
2289 declare
2290 PIC : constant String := MLib.Tgt.PIC_Option;
2291
2292 begin
2293 if PIC /= "" then
2294 Add_Arguments ((1 => new String'(PIC)));
2295 end if;
2296 end;
2297 end if;
2298
2299 if Data.Dir_Path = null then
2300 Data.Dir_Path :=
2301 new String'(Get_Name_String (Data.Display_Directory));
2302 Project_Tree.Projects.Table (Arguments_Project) :=
2303 Data;
2304 end if;
2305
2306 -- We now look for package Compiler and get the switches from
2307 -- this package.
2308
2309 Compiler_Package :=
2310 Prj.Util.Value_Of
2311 (Name => Name_Compiler,
2312 In_Packages => Data.Decl.Packages,
2313 In_Tree => Project_Tree);
2314
2315 if Compiler_Package /= No_Package then
2316
2317 -- If package Gnatmake.Compiler exists, we get the specific
2318 -- switches for the current source, or the global switches,
2319 -- if any.
2320
2321 Switches :=
2322 Switches_Of
2323 (Source_File => Source_File,
2324 Source_File_Name => Source_File_Name,
2325 Source_Index => Source_Index,
2326 Naming => Data.Naming,
2327 In_Package => Compiler_Package,
2328 Allow_ALI => False);
2329
2330 end if;
2331
2332 case Switches.Kind is
2333
2334 -- We have a list of switches. We add these switches,
2335 -- plus the saved gcc switches.
2336
2337 when List =>
2338
2339 declare
2340 Current : String_List_Id := Switches.Values;
2341 Element : String_Element;
2342 Number : Natural := 0;
2343
2344 begin
2345 while Current /= Nil_String loop
2346 Element := Project_Tree.String_Elements.
2347 Table (Current);
2348 Number := Number + 1;
2349 Current := Element.Next;
2350 end loop;
2351
2352 declare
2353 New_Args : Argument_List (1 .. Number);
2354 Last_New : Natural := 0;
2355
2356 begin
2357 Current := Switches.Values;
2358
2359 for Index in New_Args'Range loop
2360 Element := Project_Tree.String_Elements.
2361 Table (Current);
2362 Get_Name_String (Element.Value);
2363
2364 if Name_Len > 0 then
2365 Last_New := Last_New + 1;
2366 New_Args (Last_New) :=
2367 new String'(Name_Buffer (1 .. Name_Len));
2368 Test_If_Relative_Path
2369 (New_Args (Last_New),
2370 Parent => Data.Dir_Path,
2371 Including_Non_Switch => False);
2372 end if;
2373
2374 Current := Element.Next;
2375 end loop;
2376
2377 Add_Arguments
2378 (Configuration_Pragmas_Switch
2379 (Arguments_Project) &
2380 New_Args (1 .. Last_New) &
2381 The_Saved_Gcc_Switches.all);
2382 end;
2383 end;
2384
2385 -- We have a single switch. We add this switch,
2386 -- plus the saved gcc switches.
2387
2388 when Single =>
2389 Get_Name_String (Switches.Value);
2390
2391 declare
2392 New_Args : Argument_List :=
2393 (1 => new String'
2394 (Name_Buffer (1 .. Name_Len)));
2395
2396 begin
2397 Test_If_Relative_Path
2398 (New_Args (1),
2399 Parent => Data.Dir_Path,
2400 Including_Non_Switch => False);
2401 Add_Arguments
2402 (Configuration_Pragmas_Switch (Arguments_Project) &
2403 New_Args & The_Saved_Gcc_Switches.all);
2404 end;
2405
2406 -- We have no switches from Gnatmake.Compiler.
2407 -- We add the saved gcc switches.
2408
2409 when Undefined =>
2410 Add_Arguments
2411 (Configuration_Pragmas_Switch (Arguments_Project) &
2412 The_Saved_Gcc_Switches.all);
2413 end case;
2414 end if;
2415 end;
2416 end if;
2417
2418 -- Set Output_Is_Object, depending if there is a -S switch.
2419 -- If the bind step is not performed, and there is a -S switch,
2420 -- then we will not check for a valid object file.
2421
2422 Check_For_S_Switch;
2423 end Collect_Arguments;
2424
2425 ---------------------
2426 -- Compile_Sources --
2427 ---------------------
2428
2429 procedure Compile_Sources
2430 (Main_Source : File_Name_Type;
2431 Args : Argument_List;
2432 First_Compiled_File : out File_Name_Type;
2433 Most_Recent_Obj_File : out File_Name_Type;
2434 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
2435 Main_Unit : out Boolean;
2436 Compilation_Failures : out Natural;
2437 Main_Index : Int := 0;
2438 Check_Readonly_Files : Boolean := False;
2439 Do_Not_Execute : Boolean := False;
2440 Force_Compilations : Boolean := False;
2441 Keep_Going : Boolean := False;
2442 In_Place_Mode : Boolean := False;
2443 Initialize_ALI_Data : Boolean := True;
2444 Max_Process : Positive := 1)
2445 is
2446 No_Mapping_File : constant Natural := 0;
2447
2448 type Compilation_Data is record
2449 Pid : Process_Id;
2450 Full_Source_File : File_Name_Type;
2451 Lib_File : File_Name_Type;
2452 Source_Unit : Unit_Name_Type;
2453 Mapping_File : Natural := No_Mapping_File;
2454 Project : Project_Id := No_Project;
2455 Syntax_Only : Boolean := False;
2456 Output_Is_Object : Boolean := True;
2457 end record;
2458
2459 Running_Compile : array (1 .. Max_Process) of Compilation_Data;
2460 -- Used to save information about outstanding compilations
2461
2462 Outstanding_Compiles : Natural := 0;
2463 -- Current number of outstanding compiles
2464
2465 Source_Unit : Unit_Name_Type;
2466 -- Current source unit
2467
2468 Source_File : File_Name_Type;
2469 -- Current source file
2470
2471 Full_Source_File : File_Name_Type;
2472 -- Full name of the current source file
2473
2474 Lib_File : File_Name_Type;
2475 -- Current library file
2476
2477 Full_Lib_File : File_Name_Type;
2478 -- Full name of the current library file
2479
2480 Obj_File : File_Name_Type;
2481 -- Full name of the object file corresponding to Lib_File
2482
2483 Obj_Stamp : Time_Stamp_Type;
2484 -- Time stamp of the current object file
2485
2486 Sfile : File_Name_Type;
2487 -- Contains the source file of the units withed by Source_File
2488
2489 Uname : Unit_Name_Type;
2490 -- Contains the unit name of the units withed by Source_File
2491
2492 ALI : ALI_Id;
2493 -- ALI Id of the current ALI file
2494
2495 -- Comment following declarations ???
2496
2497 Read_Only : Boolean := False;
2498
2499 Compilation_OK : Boolean;
2500 Need_To_Compile : Boolean;
2501
2502 Pid : Process_Id;
2503 Text : Text_Buffer_Ptr;
2504
2505 Mfile : Natural := No_Mapping_File;
2506
2507 Need_To_Check_Standard_Library : Boolean :=
2508 Check_Readonly_Files
2509 and not Unique_Compile;
2510
2511 Mapping_File_Arg : String_Access;
2512
2513 Process_Created : Boolean := False;
2514
2515 procedure Add_Process
2516 (Pid : Process_Id;
2517 Sfile : File_Name_Type;
2518 Afile : File_Name_Type;
2519 Uname : Unit_Name_Type;
2520 Mfile : Natural := No_Mapping_File);
2521 -- Adds process Pid to the current list of outstanding compilation
2522 -- processes and record the full name of the source file Sfile that
2523 -- we are compiling, the name of its library file Afile and the
2524 -- name of its unit Uname. If Mfile is not equal to No_Mapping_File,
2525 -- it is the index of the mapping file used during compilation in the
2526 -- array The_Mapping_File_Names.
2527
2528 procedure Await_Compile
2529 (Sfile : out File_Name_Type;
2530 Afile : out File_Name_Type;
2531 Uname : out Unit_Name_Type;
2532 OK : out Boolean);
2533 -- Awaits that an outstanding compilation process terminates. When
2534 -- it does set Sfile to the name of the source file that was compiled
2535 -- Afile to the name of its library file and Uname to the name of its
2536 -- unit. Note that this time stamp can be used to check whether the
2537 -- compilation did generate an object file. OK is set to True if the
2538 -- compilation succeeded. Note that Sfile, Afile and Uname could be
2539 -- resp. No_File, No_File and No_Name if there were no compilations
2540 -- to wait for.
2541
2542 function Bad_Compilation_Count return Natural;
2543 -- Returns the number of compilation failures
2544
2545 procedure Check_Standard_Library;
2546 -- Check if s-stalib.adb needs to be compiled
2547
2548 procedure Collect_Arguments_And_Compile
2549 (Source_File : File_Name_Type;
2550 Source_Index : Int);
2551 -- Collect arguments from project file (if any) and compile
2552
2553 function Compile
2554 (S : File_Name_Type;
2555 L : File_Name_Type;
2556 Source_Index : Int;
2557 Args : Argument_List) return Process_Id;
2558 -- Compiles S using Args. If S is a GNAT predefined source "-gnatpg" is
2559 -- added to Args. Non blocking call. L corresponds to the expected
2560 -- library file name. Process_Id of the process spawned to execute the
2561 -- compilation.
2562
2563 package Good_ALI is new Table.Table (
2564 Table_Component_Type => ALI_Id,
2565 Table_Index_Type => Natural,
2566 Table_Low_Bound => 1,
2567 Table_Initial => 50,
2568 Table_Increment => 100,
2569 Table_Name => "Make.Good_ALI");
2570 -- Contains the set of valid ALI files that have not yet been scanned
2571
2572 function Good_ALI_Present return Boolean;
2573 -- Returns True if any ALI file was recorded in the previous set
2574
2575 procedure Get_Mapping_File (Project : Project_Id);
2576 -- Get a mapping file name. If there is one to be reused, reuse it.
2577 -- Otherwise, create a new mapping file.
2578
2579 function Get_Next_Good_ALI return ALI_Id;
2580 -- Returns the next good ALI_Id record
2581
2582 procedure Record_Failure
2583 (File : File_Name_Type;
2584 Unit : Unit_Name_Type;
2585 Found : Boolean := True);
2586 -- Records in the previous table that the compilation for File failed.
2587 -- If Found is False then the compilation of File failed because we
2588 -- could not find it. Records also Unit when possible.
2589
2590 procedure Record_Good_ALI (A : ALI_Id);
2591 -- Records in the previous set the Id of an ALI file
2592
2593 -----------------
2594 -- Add_Process --
2595 -----------------
2596
2597 procedure Add_Process
2598 (Pid : Process_Id;
2599 Sfile : File_Name_Type;
2600 Afile : File_Name_Type;
2601 Uname : Unit_Name_Type;
2602 Mfile : Natural := No_Mapping_File)
2603 is
2604 OC1 : constant Positive := Outstanding_Compiles + 1;
2605
2606 begin
2607 pragma Assert (OC1 <= Max_Process);
2608 pragma Assert (Pid /= Invalid_Pid);
2609
2610 Running_Compile (OC1).Pid := Pid;
2611 Running_Compile (OC1).Full_Source_File := Sfile;
2612 Running_Compile (OC1).Lib_File := Afile;
2613 Running_Compile (OC1).Source_Unit := Uname;
2614 Running_Compile (OC1).Mapping_File := Mfile;
2615 Running_Compile (OC1).Project := Arguments_Project;
2616 Running_Compile (OC1).Syntax_Only := Syntax_Only;
2617 Running_Compile (OC1).Output_Is_Object := Output_Is_Object;
2618
2619 Outstanding_Compiles := OC1;
2620 end Add_Process;
2621
2622 --------------------
2623 -- Await_Compile --
2624 -------------------
2625
2626 procedure Await_Compile
2627 (Sfile : out File_Name_Type;
2628 Afile : out File_Name_Type;
2629 Uname : out Unit_Name_Type;
2630 OK : out Boolean)
2631 is
2632 Pid : Process_Id;
2633 Project : Project_Id;
2634
2635 begin
2636 pragma Assert (Outstanding_Compiles > 0);
2637
2638 Sfile := No_File;
2639 Afile := No_File;
2640 Uname := No_Unit_Name;
2641 OK := False;
2642
2643 -- The loop here is a work-around for a problem on VMS; in some
2644 -- circumstances (shared library and several executables, for
2645 -- example), there are child processes other than compilation
2646 -- processes that are received. Until this problem is resolved,
2647 -- we will ignore such processes.
2648
2649 loop
2650 Wait_Process (Pid, OK);
2651
2652 if Pid = Invalid_Pid then
2653 return;
2654 end if;
2655
2656 for J in Running_Compile'First .. Outstanding_Compiles loop
2657 if Pid = Running_Compile (J).Pid then
2658 Sfile := Running_Compile (J).Full_Source_File;
2659 Afile := Running_Compile (J).Lib_File;
2660 Uname := Running_Compile (J).Source_Unit;
2661 Syntax_Only := Running_Compile (J).Syntax_Only;
2662 Output_Is_Object := Running_Compile (J).Output_Is_Object;
2663 Project := Running_Compile (J).Project;
2664
2665 -- If a mapping file was used by this compilation,
2666 -- get its file name for reuse by a subsequent compilation
2667
2668 if Running_Compile (J).Mapping_File /= No_Mapping_File then
2669 Last_Free_Indices (Project) :=
2670 Last_Free_Indices (Project) + 1;
2671 The_Free_Mapping_File_Indices
2672 (Project, Last_Free_Indices (Project)) :=
2673 Running_Compile (J).Mapping_File;
2674 end if;
2675
2676 -- To actually remove this Pid and related info from
2677 -- Running_Compile replace its entry with the last valid
2678 -- entry in Running_Compile.
2679
2680 if J = Outstanding_Compiles then
2681 null;
2682
2683 else
2684 Running_Compile (J) :=
2685 Running_Compile (Outstanding_Compiles);
2686 end if;
2687
2688 Outstanding_Compiles := Outstanding_Compiles - 1;
2689 return;
2690 end if;
2691 end loop;
2692
2693 -- This child process was not one of our compilation processes;
2694 -- just ignore it for now.
2695
2696 -- raise Program_Error;
2697 end loop;
2698 end Await_Compile;
2699
2700 ---------------------------
2701 -- Bad_Compilation_Count --
2702 ---------------------------
2703
2704 function Bad_Compilation_Count return Natural is
2705 begin
2706 return Bad_Compilation.Last - Bad_Compilation.First + 1;
2707 end Bad_Compilation_Count;
2708
2709 ----------------------------
2710 -- Check_Standard_Library --
2711 ----------------------------
2712
2713 procedure Check_Standard_Library is
2714 begin
2715 Need_To_Check_Standard_Library := False;
2716
2717 if not Targparm.Suppress_Standard_Library_On_Target then
2718 declare
2719 Sfile : File_Name_Type;
2720 Add_It : Boolean := True;
2721
2722 begin
2723 Name_Len := Standard_Library_Package_Body_Name'Length;
2724 Name_Buffer (1 .. Name_Len) :=
2725 Standard_Library_Package_Body_Name;
2726 Sfile := Name_Enter;
2727
2728 -- If we have a special runtime, we add the standard
2729 -- library only if we can find it.
2730
2731 if RTS_Switch then
2732 Add_It :=
2733 Find_File (Sfile, Osint.Source) /= No_File;
2734 end if;
2735
2736 if Add_It then
2737 if Is_Marked (Sfile) then
2738 if Is_In_Obsoleted (Sfile) then
2739 Executable_Obsolete := True;
2740 end if;
2741
2742 else
2743 Insert_Q (Sfile, Index => 0);
2744 Mark (Sfile, Index => 0);
2745 end if;
2746 end if;
2747 end;
2748 end if;
2749 end Check_Standard_Library;
2750
2751 -----------------------------------
2752 -- Collect_Arguments_And_Compile --
2753 -----------------------------------
2754
2755 procedure Collect_Arguments_And_Compile
2756 (Source_File : File_Name_Type;
2757 Source_Index : Int)
2758 is
2759 begin
2760 -- Process_Created will be set True if an attempt is made to compile
2761 -- the source, that is if it is not in an externally built project.
2762
2763 Process_Created := False;
2764
2765 -- If arguments not yet collected (in Check), collect them now
2766
2767 if not Arguments_Collected then
2768 Collect_Arguments (Source_File, Source_Index, Args);
2769 end if;
2770
2771 -- For VMS, when compiling the main source, add switch
2772 -- -mdebug-main=_ada_ so that the executable can be debugged
2773 -- by the standard VMS debugger.
2774
2775 if not No_Main_Subprogram
2776 and then Targparm.OpenVMS_On_Target
2777 and then Source_File = Main_Source
2778 then
2779 -- First, check if compilation will be invoked with -g
2780
2781 for J in 1 .. Last_Argument loop
2782 if Arguments (J)'Length >= 2
2783 and then Arguments (J) (1 .. 2) = "-g"
2784 and then (Arguments (J)'Length < 5
2785 or else Arguments (J) (1 .. 5) /= "-gnat")
2786 then
2787 Add_Arguments
2788 ((1 => new String'("-mdebug-main=_ada_")));
2789 exit;
2790 end if;
2791 end loop;
2792 end if;
2793
2794 -- If we use mapping file (-P or -C switches), then get one
2795
2796 if Create_Mapping_File then
2797 Get_Mapping_File (Arguments_Project);
2798 end if;
2799
2800 -- If the source is part of a project file, we set the ADA_*_PATHs,
2801 -- check for an eventual library project, and use the full path.
2802
2803 if Arguments_Project /= No_Project then
2804 if not Project_Tree.Projects.Table
2805 (Arguments_Project).Externally_Built
2806 then
2807 Prj.Env.Set_Ada_Paths (Arguments_Project, Project_Tree, True);
2808
2809 if not Unique_Compile
2810 and then MLib.Tgt.Support_For_Libraries /= Prj.None
2811 then
2812 declare
2813 The_Data : Project_Data :=
2814 Project_Tree.Projects.Table
2815 (Arguments_Project);
2816
2817 Prj : Project_Id := Arguments_Project;
2818
2819 begin
2820 while The_Data.Extended_By /= No_Project loop
2821 Prj := The_Data.Extended_By;
2822 The_Data := Project_Tree.Projects.Table (Prj);
2823 end loop;
2824
2825 if The_Data.Library
2826 and then not The_Data.Need_To_Build_Lib
2827 then
2828 -- Add to the Q all sources of the project that
2829 -- have not been marked
2830
2831 Insert_Project_Sources
2832 (The_Project => Prj,
2833 All_Projects => False,
2834 Into_Q => True);
2835
2836 -- Now mark the project as processed
2837
2838 Project_Tree.Projects.Table
2839 (Prj).Need_To_Build_Lib := True;
2840 end if;
2841 end;
2842 end if;
2843
2844 -- Change to the object directory of the project file,
2845 -- if necessary.
2846
2847 Change_To_Object_Directory (Arguments_Project);
2848
2849 Pid :=
2850 Compile
2851 (File_Name_Type (Arguments_Path_Name),
2852 Lib_File,
2853 Source_Index,
2854 Arguments (1 .. Last_Argument));
2855 Process_Created := True;
2856 end if;
2857
2858 else
2859 -- If this is a source outside of any project file, make sure it
2860 -- will be compiled in object directory of the main project file.
2861
2862 if Main_Project /= No_Project then
2863 Change_To_Object_Directory (Arguments_Project);
2864 end if;
2865
2866 Pid := Compile (Full_Source_File, Lib_File, Source_Index,
2867 Arguments (1 .. Last_Argument));
2868 Process_Created := True;
2869 end if;
2870 end Collect_Arguments_And_Compile;
2871
2872 -------------
2873 -- Compile --
2874 -------------
2875
2876 function Compile
2877 (S : File_Name_Type;
2878 L : File_Name_Type;
2879 Source_Index : Int;
2880 Args : Argument_List) return Process_Id
2881 is
2882 Comp_Args : Argument_List (Args'First .. Args'Last + 9);
2883 Comp_Next : Integer := Args'First;
2884 Comp_Last : Integer;
2885 Arg_Index : Integer;
2886
2887 function Ada_File_Name (Name : File_Name_Type) return Boolean;
2888 -- Returns True if Name is the name of an ada source file
2889 -- (i.e. suffix is .ads or .adb)
2890
2891 -------------------
2892 -- Ada_File_Name --
2893 -------------------
2894
2895 function Ada_File_Name (Name : File_Name_Type) return Boolean is
2896 begin
2897 Get_Name_String (Name);
2898 return
2899 Name_Len > 4
2900 and then Name_Buffer (Name_Len - 3 .. Name_Len - 1) = ".ad"
2901 and then (Name_Buffer (Name_Len) = 'b'
2902 or else
2903 Name_Buffer (Name_Len) = 's');
2904 end Ada_File_Name;
2905
2906 -- Start of processing for Compile
2907
2908 begin
2909 Enter_Into_Obsoleted (S);
2910
2911 -- By default, Syntax_Only is False
2912
2913 Syntax_Only := False;
2914
2915 for J in Args'Range loop
2916 if Args (J).all = "-gnats" then
2917
2918 -- If we compile with -gnats, the bind step and the link step
2919 -- are inhibited. Also, we set Syntax_Only to True, so that
2920 -- we don't fail when we don't find the ALI file, after
2921 -- compilation.
2922
2923 Do_Bind_Step := False;
2924 Do_Link_Step := False;
2925 Syntax_Only := True;
2926
2927 elsif Args (J).all = "-gnatc" then
2928
2929 -- If we compile with -gnatc, the bind step and the link step
2930 -- are inhibited. We set Syntax_Only to False for the case when
2931 -- -gnats was previously specified.
2932
2933 Do_Bind_Step := False;
2934 Do_Link_Step := False;
2935 Syntax_Only := False;
2936 end if;
2937 end loop;
2938
2939 Comp_Args (Comp_Next) := Comp_Flag;
2940 Comp_Next := Comp_Next + 1;
2941
2942 -- Optimize the simple case where the gcc command line looks like
2943 -- gcc -c -I. ... -I- file.adb --into-> gcc -c ... file.adb
2944
2945 if Args (Args'First).all = "-I" & Normalized_CWD
2946 and then Args (Args'Last).all = "-I-"
2947 and then S = Strip_Directory (S)
2948 then
2949 Comp_Last := Comp_Next + Args'Length - 3;
2950 Arg_Index := Args'First + 1;
2951
2952 else
2953 Comp_Last := Comp_Next + Args'Length - 1;
2954 Arg_Index := Args'First;
2955 end if;
2956
2957 -- Make a deep copy of the arguments, because Normalize_Arguments
2958 -- may deallocate some arguments.
2959
2960 for J in Comp_Next .. Comp_Last loop
2961 Comp_Args (J) := new String'(Args (Arg_Index).all);
2962 Arg_Index := Arg_Index + 1;
2963 end loop;
2964
2965 -- Set -gnatpg for predefined files (for this purpose the renamings
2966 -- such as Text_IO do not count as predefined). Note that we strip
2967 -- the directory name from the source file name becase the call to
2968 -- Fname.Is_Predefined_File_Name cannot deal with directory prefixes.
2969
2970 declare
2971 Fname : constant File_Name_Type := Strip_Directory (S);
2972
2973 begin
2974 if Is_Predefined_File_Name (Fname, False) then
2975 if Check_Readonly_Files then
2976 Comp_Args (Comp_Args'First + 2 .. Comp_Last + 1) :=
2977 Comp_Args (Comp_Args'First + 1 .. Comp_Last);
2978 Comp_Last := Comp_Last + 1;
2979 Comp_Args (Comp_Args'First + 1) := GNAT_Flag;
2980
2981 else
2982 Make_Failed
2983 ("not allowed to compile """ &
2984 Get_Name_String (Fname) &
2985 """; use -a switch, or compile file with " &
2986 """-gnatg"" switch");
2987 end if;
2988 end if;
2989 end;
2990
2991 -- Now check if the file name has one of the suffixes familiar to
2992 -- the gcc driver. If this is not the case then add the ada flag
2993 -- "-x ada".
2994
2995 if not Ada_File_Name (S) and then not Targparm.AAMP_On_Target then
2996 Comp_Last := Comp_Last + 1;
2997 Comp_Args (Comp_Last) := Ada_Flag_1;
2998 Comp_Last := Comp_Last + 1;
2999 Comp_Args (Comp_Last) := Ada_Flag_2;
3000 end if;
3001
3002 if Source_Index /= 0 then
3003 declare
3004 Num : constant String := Source_Index'Img;
3005 begin
3006 Comp_Last := Comp_Last + 1;
3007 Comp_Args (Comp_Last) :=
3008 new String'("-gnateI" & Num (Num'First + 1 .. Num'Last));
3009 end;
3010 end if;
3011
3012 if Source_Index /= 0
3013 or else L /= Strip_Directory (L)
3014 or else Object_Directory_Path /= null
3015 then
3016 -- Build -o argument
3017
3018 Get_Name_String (L);
3019
3020 for J in reverse 1 .. Name_Len loop
3021 if Name_Buffer (J) = '.' then
3022 Name_Len := J + Object_Suffix'Length - 1;
3023 Name_Buffer (J .. Name_Len) := Object_Suffix;
3024 exit;
3025 end if;
3026 end loop;
3027
3028 Comp_Last := Comp_Last + 1;
3029 Comp_Args (Comp_Last) := Output_Flag;
3030 Comp_Last := Comp_Last + 1;
3031
3032 -- If an object directory was specified, prepend the object file
3033 -- name with this object directory.
3034
3035 if Object_Directory_Path /= null then
3036 Comp_Args (Comp_Last) :=
3037 new String'(Object_Directory_Path.all &
3038 Name_Buffer (1 .. Name_Len));
3039
3040 else
3041 Comp_Args (Comp_Last) :=
3042 new String'(Name_Buffer (1 .. Name_Len));
3043 end if;
3044 end if;
3045
3046 if Create_Mapping_File then
3047 Comp_Last := Comp_Last + 1;
3048 Comp_Args (Comp_Last) := Mapping_File_Arg;
3049 end if;
3050
3051 Get_Name_String (S);
3052
3053 Comp_Last := Comp_Last + 1;
3054 Comp_Args (Comp_Last) := new String'(Name_Buffer (1 .. Name_Len));
3055
3056 GNAT.OS_Lib.Normalize_Arguments (Comp_Args (Args'First .. Comp_Last));
3057
3058 Comp_Last := Comp_Last + 1;
3059 Comp_Args (Comp_Last) := new String'("-gnatez");
3060
3061 Display (Gcc.all, Comp_Args (Args'First .. Comp_Last));
3062
3063 if Gcc_Path = null then
3064 Make_Failed ("error, unable to locate ", Gcc.all);
3065 end if;
3066
3067 return
3068 GNAT.OS_Lib.Non_Blocking_Spawn
3069 (Gcc_Path.all, Comp_Args (Args'First .. Comp_Last));
3070 end Compile;
3071
3072 ----------------------
3073 -- Get_Mapping_File --
3074 ----------------------
3075
3076 procedure Get_Mapping_File (Project : Project_Id) is
3077 begin
3078 -- If there is a mapping file ready to be reused, reuse it
3079
3080 if Last_Free_Indices (Project) > 0 then
3081 Mfile := The_Free_Mapping_File_Indices
3082 (Project, Last_Free_Indices (Project));
3083 Last_Free_Indices (Project) := Last_Free_Indices (Project) - 1;
3084
3085 -- Otherwise, create and initialize a new one
3086
3087 else
3088 Init_Mapping_File (Project => Project, File_Index => Mfile);
3089 end if;
3090
3091 -- Put the name in the mapping file argument for the invocation
3092 -- of the compiler.
3093
3094 Free (Mapping_File_Arg);
3095 Mapping_File_Arg :=
3096 new String'("-gnatem=" &
3097 Get_Name_String
3098 (The_Mapping_File_Names (Project, Mfile)));
3099
3100 end Get_Mapping_File;
3101
3102 -----------------------
3103 -- Get_Next_Good_ALI --
3104 -----------------------
3105
3106 function Get_Next_Good_ALI return ALI_Id is
3107 ALI : ALI_Id;
3108
3109 begin
3110 pragma Assert (Good_ALI_Present);
3111 ALI := Good_ALI.Table (Good_ALI.Last);
3112 Good_ALI.Decrement_Last;
3113 return ALI;
3114 end Get_Next_Good_ALI;
3115
3116 ----------------------
3117 -- Good_ALI_Present --
3118 ----------------------
3119
3120 function Good_ALI_Present return Boolean is
3121 begin
3122 return Good_ALI.First <= Good_ALI.Last;
3123 end Good_ALI_Present;
3124
3125 --------------------
3126 -- Record_Failure --
3127 --------------------
3128
3129 procedure Record_Failure
3130 (File : File_Name_Type;
3131 Unit : Unit_Name_Type;
3132 Found : Boolean := True)
3133 is
3134 begin
3135 Bad_Compilation.Increment_Last;
3136 Bad_Compilation.Table (Bad_Compilation.Last) := (File, Unit, Found);
3137 end Record_Failure;
3138
3139 ---------------------
3140 -- Record_Good_ALI --
3141 ---------------------
3142
3143 procedure Record_Good_ALI (A : ALI_Id) is
3144 begin
3145 Good_ALI.Increment_Last;
3146 Good_ALI.Table (Good_ALI.Last) := A;
3147 end Record_Good_ALI;
3148
3149 -- Start of processing for Compile_Sources
3150
3151 begin
3152 pragma Assert (Args'First = 1);
3153
3154 -- Package and Queue initializations
3155
3156 Good_ALI.Init;
3157
3158 if First_Q_Initialization then
3159 Init_Q;
3160 end if;
3161
3162 if Initialize_ALI_Data then
3163 Initialize_ALI;
3164 Initialize_ALI_Source;
3165 end if;
3166
3167 -- The following two flags affect the behavior of ALI.Set_Source_Table.
3168 -- We set Check_Source_Files to True to ensure that source file
3169 -- time stamps are checked, and we set All_Sources to False to
3170 -- avoid checking the presence of the source files listed in the
3171 -- source dependency section of an ali file (which would be a mistake
3172 -- since the ali file may be obsolete).
3173
3174 Check_Source_Files := True;
3175 All_Sources := False;
3176
3177 -- Only insert in the Q if it is not already done, to avoid simultaneous
3178 -- compilations if -jnnn is used.
3179
3180 if not Is_Marked (Main_Source, Main_Index) then
3181 Insert_Q (Main_Source, Index => Main_Index);
3182 Mark (Main_Source, Main_Index);
3183 end if;
3184
3185 First_Compiled_File := No_File;
3186 Most_Recent_Obj_File := No_File;
3187 Most_Recent_Obj_Stamp := Empty_Time_Stamp;
3188 Main_Unit := False;
3189
3190 -- Keep looping until there is no more work to do (the Q is empty)
3191 -- and all the outstanding compilations have terminated
3192
3193 Make_Loop : while not Empty_Q or else Outstanding_Compiles > 0 loop
3194
3195 -- If the user does not want to keep going in case of errors then
3196 -- wait for the remaining outstanding compiles and then exit.
3197
3198 if Bad_Compilation_Count > 0 and then not Keep_Going then
3199 while Outstanding_Compiles > 0 loop
3200 Await_Compile
3201 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
3202
3203 if not Compilation_OK then
3204 Record_Failure (Full_Source_File, Source_Unit);
3205 end if;
3206 end loop;
3207
3208 exit Make_Loop;
3209 end if;
3210
3211 -- PHASE 1: Check if there is more work that we can do (ie the Q
3212 -- is non empty). If there is, do it only if we have not yet used
3213 -- up all the available processes.
3214
3215 if not Empty_Q and then Outstanding_Compiles < Max_Process then
3216 declare
3217 Source_Index : Int;
3218 -- Index of the current unit in the current source file
3219
3220 begin
3221 Extract_From_Q (Source_File, Source_Unit, Source_Index);
3222 Full_Source_File := Osint.Full_Source_Name (Source_File);
3223 Lib_File := Osint.Lib_File_Name
3224 (Source_File, Source_Index);
3225 Full_Lib_File := Osint.Full_Lib_File_Name (Lib_File);
3226
3227 -- If this source has already been compiled, the executable is
3228 -- obsolete.
3229
3230 if Is_In_Obsoleted (Source_File) then
3231 Executable_Obsolete := True;
3232 end if;
3233
3234 -- If the library file is an Ada library skip it
3235
3236 if Full_Lib_File /= No_File
3237 and then In_Ada_Lib_Dir (Full_Lib_File)
3238 then
3239 Verbose_Msg
3240 (Lib_File,
3241 "is in an Ada library",
3242 Prefix => " ",
3243 Minimum_Verbosity => Opt.High);
3244
3245 -- If the library file is a read-only library skip it, but
3246 -- only if, when using project files, this library file is
3247 -- in the right object directory (a read-only ALI file
3248 -- in the object directory of a project being extended
3249 -- should not be skipped).
3250
3251 elsif Full_Lib_File /= No_File
3252 and then not Check_Readonly_Files
3253 and then Is_Readonly_Library (Full_Lib_File)
3254 and then Is_In_Object_Directory (Source_File, Full_Lib_File)
3255 then
3256 Verbose_Msg
3257 (Lib_File,
3258 "is a read-only library",
3259 Prefix => " ",
3260 Minimum_Verbosity => Opt.High);
3261
3262 -- The source file that we are checking cannot be located
3263
3264 elsif Full_Source_File = No_File then
3265 Record_Failure (Source_File, Source_Unit, False);
3266
3267 -- Source and library files can be located but are internal
3268 -- files
3269
3270 elsif not Check_Readonly_Files
3271 and then Full_Lib_File /= No_File
3272 and then Is_Internal_File_Name (Source_File, False)
3273 then
3274 if Force_Compilations then
3275 Fail
3276 ("not allowed to compile """ &
3277 Get_Name_String (Source_File) &
3278 """; use -a switch, or compile file with " &
3279 """-gnatg"" switch");
3280 end if;
3281
3282 Verbose_Msg
3283 (Lib_File,
3284 "is an internal library",
3285 Prefix => " ",
3286 Minimum_Verbosity => Opt.High);
3287
3288 -- The source file that we are checking can be located
3289
3290 else
3291 Arguments_Collected := False;
3292
3293 -- Do nothing if project of source is externally built
3294
3295 Collect_Arguments (Source_File, Source_Index, Args);
3296
3297 if Arguments_Project = No_Project
3298 or else not Project_Tree.Projects.Table
3299 (Arguments_Project).Externally_Built
3300 then
3301 -- Don't waste any time if we have to recompile anyway
3302
3303 Obj_Stamp := Empty_Time_Stamp;
3304 Need_To_Compile := Force_Compilations;
3305
3306 if not Force_Compilations then
3307 Read_Only :=
3308 Full_Lib_File /= No_File
3309 and then not Check_Readonly_Files
3310 and then Is_Readonly_Library (Full_Lib_File);
3311 Check (Source_File, Source_Index, Args, Lib_File,
3312 Read_Only, ALI, Obj_File, Obj_Stamp);
3313 Need_To_Compile := (ALI = No_ALI_Id);
3314 end if;
3315
3316 if not Need_To_Compile then
3317 -- The ALI file is up-to-date. Record its Id
3318
3319 Record_Good_ALI (ALI);
3320
3321 -- Record the time stamp of the most recent object
3322 -- file as long as no (re)compilations are needed.
3323
3324 if First_Compiled_File = No_File
3325 and then (Most_Recent_Obj_File = No_File
3326 or else Obj_Stamp > Most_Recent_Obj_Stamp)
3327 then
3328 Most_Recent_Obj_File := Obj_File;
3329 Most_Recent_Obj_Stamp := Obj_Stamp;
3330 end if;
3331
3332 else
3333 -- Check that switch -x has been used if a source
3334 -- outside of project files need to be compiled.
3335
3336 if Main_Project /= No_Project
3337 and then Arguments_Project = No_Project
3338 and then not External_Unit_Compilation_Allowed
3339 then
3340 Make_Failed ("external source (",
3341 Get_Name_String (Source_File),
3342 ") is not part of any project;"
3343 & " cannot be compiled without" &
3344 " gnatmake switch -x");
3345 end if;
3346
3347 -- Is this the first file we have to compile?
3348
3349 if First_Compiled_File = No_File then
3350 First_Compiled_File := Full_Source_File;
3351 Most_Recent_Obj_File := No_File;
3352
3353 if Do_Not_Execute then
3354 exit Make_Loop;
3355 end if;
3356 end if;
3357
3358 if In_Place_Mode then
3359
3360 -- If the library file was not found, then save
3361 -- the library file near the source file.
3362
3363 if Full_Lib_File = No_File then
3364 Lib_File := Osint.Lib_File_Name
3365 (Full_Source_File, Source_Index);
3366
3367 -- If the library file was found, then save the
3368 -- library file in the same place.
3369
3370 else
3371 Lib_File := Full_Lib_File;
3372 end if;
3373
3374 end if;
3375
3376 -- Start the compilation and record it. We can do
3377 -- this because there is at least one free process.
3378
3379 Collect_Arguments_And_Compile
3380 (Source_File, Source_Index);
3381
3382 -- Make sure we could successfully start
3383 -- the Compilation.
3384
3385 if Process_Created then
3386 if Pid = Invalid_Pid then
3387 Record_Failure (Full_Source_File, Source_Unit);
3388 else
3389 Add_Process
3390 (Pid,
3391 Full_Source_File,
3392 Lib_File,
3393 Source_Unit,
3394 Mfile);
3395 end if;
3396 end if;
3397 end if;
3398 end if;
3399 end if;
3400 end;
3401 end if;
3402
3403 -- PHASE 2: Now check if we should wait for a compilation to
3404 -- finish. This is the case if all the available processes are
3405 -- busy compiling sources or there is nothing else to do
3406 -- (that is the Q is empty and there are no good ALIs to process).
3407
3408 if Outstanding_Compiles = Max_Process
3409 or else (Empty_Q
3410 and then not Good_ALI_Present
3411 and then Outstanding_Compiles > 0)
3412 then
3413 Await_Compile
3414 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
3415
3416 if not Compilation_OK then
3417 Record_Failure (Full_Source_File, Source_Unit);
3418 end if;
3419
3420 if Compilation_OK or else Keep_Going then
3421
3422 -- Re-read the updated library file
3423
3424 declare
3425 Saved_Object_Consistency : constant Boolean :=
3426 Check_Object_Consistency;
3427
3428 begin
3429 -- If compilation was not OK, or if output is not an
3430 -- object file and we don't do the bind step, don't check
3431 -- for object consistency.
3432
3433 Check_Object_Consistency :=
3434 Check_Object_Consistency
3435 and Compilation_OK
3436 and (Output_Is_Object or Do_Bind_Step);
3437 Text := Read_Library_Info (Lib_File);
3438
3439 -- Restore Check_Object_Consistency to its initial value
3440
3441 Check_Object_Consistency := Saved_Object_Consistency;
3442 end;
3443
3444 -- If an ALI file was generated by this compilation, scan
3445 -- the ALI file and record it.
3446 -- If the scan fails, a previous ali file is inconsistent with
3447 -- the unit just compiled.
3448
3449 if Text /= null then
3450 ALI :=
3451 Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
3452
3453 if ALI = No_ALI_Id then
3454
3455 -- Record a failure only if not already done
3456
3457 if Compilation_OK then
3458 Inform
3459 (Lib_File,
3460 "incompatible ALI file, please recompile");
3461 Record_Failure (Full_Source_File, Source_Unit);
3462 end if;
3463 else
3464 Free (Text);
3465 Record_Good_ALI (ALI);
3466 end if;
3467
3468 -- If we could not read the ALI file that was just generated
3469 -- then there could be a problem reading either the ALI or the
3470 -- corresponding object file (if Check_Object_Consistency
3471 -- is set Read_Library_Info checks that the time stamp of the
3472 -- object file is more recent than that of the ALI). For an
3473 -- example of problems caught by this test see [6625-009].
3474 -- However, we record a failure only if not already done.
3475
3476 else
3477 if Compilation_OK and not Syntax_Only then
3478 Inform
3479 (Lib_File,
3480 "WARNING: ALI or object file not found after compile");
3481 Record_Failure (Full_Source_File, Source_Unit);
3482 end if;
3483 end if;
3484 end if;
3485 end if;
3486
3487 -- PHASE 3: Check if we recorded good ALI files. If yes process
3488 -- them now in the order in which they have been recorded. There
3489 -- are two occasions in which we record good ali files. The first is
3490 -- in phase 1 when, after scanning an existing ALI file we realize
3491 -- it is up-to-date, the second instance is after a successful
3492 -- compilation.
3493
3494 while Good_ALI_Present loop
3495 ALI := Get_Next_Good_ALI;
3496
3497 declare
3498 Source_Index : Int := Unit_Index_Of (ALIs.Table (ALI).Afile);
3499
3500 begin
3501 -- If we are processing the library file corresponding to the
3502 -- main source file check if this source can be a main unit.
3503
3504 if ALIs.Table (ALI).Sfile = Main_Source and then
3505 Source_Index = Main_Index
3506 then
3507 Main_Unit := ALIs.Table (ALI).Main_Program /= None;
3508 end if;
3509
3510 -- The following adds the standard library (s-stalib) to the
3511 -- list of files to be handled by gnatmake: this file and any
3512 -- files it depends on are always included in every bind,
3513 -- even if they are not in the explicit dependency list.
3514 -- Of course, it is not added if Suppress_Standard_Library
3515 -- is True.
3516
3517 -- However, to avoid annoying output about s-stalib.ali being
3518 -- read only, when "-v" is used, we add the standard library
3519 -- only when "-a" is used.
3520
3521 if Need_To_Check_Standard_Library then
3522 Check_Standard_Library;
3523 end if;
3524
3525 -- Now insert in the Q the unmarked source files (i.e. those
3526 -- which have never been inserted in the Q and hence never
3527 -- considered). Only do that if Unique_Compile is False.
3528
3529 if not Unique_Compile then
3530 for J in
3531 ALIs.Table (ALI).First_Unit .. ALIs.Table (ALI).Last_Unit
3532 loop
3533 for K in
3534 Units.Table (J).First_With .. Units.Table (J).Last_With
3535 loop
3536 Sfile := Withs.Table (K).Sfile;
3537 Uname := Withs.Table (K).Uname;
3538
3539 -- If project files are used, find the proper source
3540 -- to compile, in case Sfile is the spec, but there
3541 -- is a body.
3542
3543 if Main_Project /= No_Project then
3544 declare
3545 Unit_Name : Name_Id;
3546 Uid : Prj.Unit_Index;
3547 Udata : Unit_Data;
3548
3549 begin
3550 Get_Name_String (Uname);
3551 Name_Len := Name_Len - 2;
3552 Unit_Name := Name_Find;
3553 Uid :=
3554 Units_Htable.Get
3555 (Project_Tree.Units_HT, Unit_Name);
3556
3557 if Uid /= Prj.No_Unit_Index then
3558 Udata := Project_Tree.Units.Table (Uid);
3559
3560 if
3561 Udata.File_Names (Body_Part).Name /=
3562 No_File
3563 and then
3564 Udata.File_Names (Body_Part).Path /= Slash
3565 then
3566 Sfile := Udata.File_Names (Body_Part).Name;
3567 Source_Index :=
3568 Udata.File_Names (Body_Part).Index;
3569
3570 elsif
3571 Udata.File_Names (Specification).Name /=
3572 No_File
3573 and then
3574 Udata.File_Names (Specification).Path /=
3575 Slash
3576 then
3577 Sfile :=
3578 Udata.File_Names (Specification).Name;
3579 Source_Index :=
3580 Udata.File_Names (Specification).Index;
3581 end if;
3582 end if;
3583 end;
3584 end if;
3585
3586 Dependencies.Append ((ALIs.Table (ALI).Sfile, Sfile));
3587
3588 if Is_In_Obsoleted (Sfile) then
3589 Executable_Obsolete := True;
3590 end if;
3591
3592 if Sfile = No_File then
3593 Debug_Msg
3594 ("Skipping generic:", Withs.Table (K).Uname);
3595
3596 else
3597 Source_Index :=
3598 Unit_Index_Of (Withs.Table (K).Afile);
3599
3600 if Is_Marked (Sfile, Source_Index) then
3601 Debug_Msg ("Skipping marked file:", Sfile);
3602
3603 elsif not Check_Readonly_Files
3604 and then Is_Internal_File_Name (Sfile, False)
3605 then
3606 Debug_Msg ("Skipping internal file:", Sfile);
3607
3608 else
3609 Insert_Q
3610 (Sfile, Withs.Table (K).Uname, Source_Index);
3611 Mark (Sfile, Source_Index);
3612 end if;
3613 end if;
3614 end loop;
3615 end loop;
3616 end if;
3617 end;
3618 end loop;
3619
3620 if Display_Compilation_Progress then
3621 Write_Str ("completed ");
3622 Write_Int (Int (Q_Front));
3623 Write_Str (" out of ");
3624 Write_Int (Int (Q.Last));
3625 Write_Str (" (");
3626 Write_Int (Int ((Q_Front * 100) / (Q.Last - Q.First)));
3627 Write_Str ("%)...");
3628 Write_Eol;
3629 end if;
3630 end loop Make_Loop;
3631
3632 Compilation_Failures := Bad_Compilation_Count;
3633
3634 -- Compilation is finished
3635
3636 -- Delete any temporary configuration pragma file
3637
3638 Delete_Temp_Config_Files;
3639
3640 end Compile_Sources;
3641
3642 -----------------------------------
3643 -- Compute_All_Imported_Projects --
3644 -----------------------------------
3645
3646 procedure Compute_All_Imported_Projects (Project : Project_Id) is
3647 procedure Add_To_List (Prj : Project_Id);
3648 -- Add a project to the list All_Imported_Projects of project Project
3649
3650 procedure Recursive_Add_Imported (Project : Project_Id);
3651 -- Recursively add the projects imported by project Project, but not
3652 -- those that are extended.
3653
3654 -----------------
3655 -- Add_To_List --
3656 -----------------
3657
3658 procedure Add_To_List (Prj : Project_Id) is
3659 Element : constant Project_Element :=
3660 (Prj, Project_Tree.Projects.Table (Project).All_Imported_Projects);
3661 List : Project_List;
3662 begin
3663 Project_List_Table.Increment_Last (Project_Tree.Project_Lists);
3664 List := Project_List_Table.Last (Project_Tree.Project_Lists);
3665 Project_Tree.Project_Lists.Table (List) := Element;
3666 Project_Tree.Projects.Table (Project).All_Imported_Projects := List;
3667 end Add_To_List;
3668
3669 ----------------------------
3670 -- Recursive_Add_Imported --
3671 ----------------------------
3672
3673 procedure Recursive_Add_Imported (Project : Project_Id) is
3674 List : Project_List;
3675 Element : Project_Element;
3676 Prj : Project_Id;
3677
3678 begin
3679 if Project /= No_Project then
3680
3681 -- For all the imported projects
3682
3683 List := Project_Tree.Projects.Table (Project).Imported_Projects;
3684 while List /= Empty_Project_List loop
3685 Element := Project_Tree.Project_Lists.Table (List);
3686 Prj := Element.Project;
3687
3688 -- Get the ultimate extending project
3689
3690 while
3691 Project_Tree.Projects.Table (Prj).Extended_By /= No_Project
3692 loop
3693 Prj := Project_Tree.Projects.Table (Prj).Extended_By;
3694 end loop;
3695
3696 -- If project has not yet been visited, add to list and recurse
3697
3698 if not Project_Tree.Projects.Table (Prj).Seen then
3699 Project_Tree.Projects.Table (Prj).Seen := True;
3700 Add_To_List (Prj);
3701 Recursive_Add_Imported (Prj);
3702 end if;
3703
3704 List := Element.Next;
3705 end loop;
3706
3707 -- Recurse on projects being imported, if any
3708
3709 Recursive_Add_Imported
3710 (Project_Tree.Projects.Table (Project).Extends);
3711 end if;
3712 end Recursive_Add_Imported;
3713
3714 begin
3715 -- Reset the Seen flag for all projects
3716
3717 for Index in 1 .. Project_Table.Last (Project_Tree.Projects) loop
3718 Project_Tree.Projects.Table (Index).Seen := False;
3719 end loop;
3720
3721 -- Make sure the list is empty
3722
3723 Project_Tree.Projects.Table (Project).All_Imported_Projects :=
3724 Empty_Project_List;
3725
3726 -- Add to the list all projects imported directly or indirectly
3727
3728 Recursive_Add_Imported (Project);
3729 end Compute_All_Imported_Projects;
3730
3731 ----------------------------------
3732 -- Configuration_Pragmas_Switch --
3733 ----------------------------------
3734
3735 function Configuration_Pragmas_Switch
3736 (For_Project : Project_Id) return Argument_List
3737 is
3738 The_Packages : Package_Id;
3739 Gnatmake : Package_Id;
3740 Compiler : Package_Id;
3741
3742 Global_Attribute : Variable_Value := Nil_Variable_Value;
3743 Local_Attribute : Variable_Value := Nil_Variable_Value;
3744
3745 Global_Attribute_Present : Boolean := False;
3746 Local_Attribute_Present : Boolean := False;
3747
3748 Result : Argument_List (1 .. 3);
3749 Last : Natural := 0;
3750
3751 function Absolute_Path
3752 (Path : Path_Name_Type;
3753 Project : Project_Id) return String;
3754 -- Returns an absolute path for a configuration pragmas file
3755
3756 -------------------
3757 -- Absolute_Path --
3758 -------------------
3759
3760 function Absolute_Path
3761 (Path : Path_Name_Type;
3762 Project : Project_Id) return String
3763 is
3764 begin
3765 Get_Name_String (Path);
3766
3767 declare
3768 Path_Name : constant String := Name_Buffer (1 .. Name_Len);
3769
3770 begin
3771 if Is_Absolute_Path (Path_Name) then
3772 return Path_Name;
3773
3774 else
3775 declare
3776 Parent_Directory : constant String :=
3777 Get_Name_String
3778 (Project_Tree.Projects.Table
3779 (Project).Display_Directory);
3780
3781 begin
3782 if Parent_Directory (Parent_Directory'Last) =
3783 Directory_Separator
3784 then
3785 return Parent_Directory & Path_Name;
3786
3787 else
3788 return Parent_Directory & Directory_Separator & Path_Name;
3789 end if;
3790 end;
3791 end if;
3792 end;
3793 end Absolute_Path;
3794
3795 -- Start of processing for Configuration_Pragmas_Switch
3796
3797 begin
3798 Prj.Env.Create_Config_Pragmas_File
3799 (For_Project, Main_Project, Project_Tree);
3800
3801 if Project_Tree.Projects.Table
3802 (For_Project).Config_File_Name /= No_Path
3803 then
3804 Temporary_Config_File :=
3805 Project_Tree.Projects.Table (For_Project).Config_File_Temp;
3806 Last := 1;
3807 Result (1) :=
3808 new String'
3809 ("-gnatec=" &
3810 Get_Name_String
3811 (Project_Tree.Projects.Table
3812 (For_Project).Config_File_Name));
3813
3814 else
3815 Temporary_Config_File := False;
3816 end if;
3817
3818 -- Check for attribute Builder'Global_Configuration_Pragmas
3819
3820 The_Packages := Project_Tree.Projects.Table
3821 (Main_Project).Decl.Packages;
3822 Gnatmake :=
3823 Prj.Util.Value_Of
3824 (Name => Name_Builder,
3825 In_Packages => The_Packages,
3826 In_Tree => Project_Tree);
3827
3828 if Gnatmake /= No_Package then
3829 Global_Attribute := Prj.Util.Value_Of
3830 (Variable_Name => Name_Global_Configuration_Pragmas,
3831 In_Variables => Project_Tree.Packages.Table
3832 (Gnatmake).Decl.Attributes,
3833 In_Tree => Project_Tree);
3834 Global_Attribute_Present :=
3835 Global_Attribute /= Nil_Variable_Value
3836 and then Get_Name_String (Global_Attribute.Value) /= "";
3837
3838 if Global_Attribute_Present then
3839 declare
3840 Path : constant String :=
3841 Absolute_Path
3842 (Path_Name_Type (Global_Attribute.Value),
3843 Global_Attribute.Project);
3844 begin
3845 if not Is_Regular_File (Path) then
3846 Make_Failed
3847 ("cannot find configuration pragmas file ", Path);
3848 end if;
3849
3850 Last := Last + 1;
3851 Result (Last) := new String'("-gnatec=" & Path);
3852 end;
3853 end if;
3854 end if;
3855
3856 -- Check for attribute Compiler'Local_Configuration_Pragmas
3857
3858 The_Packages :=
3859 Project_Tree.Projects.Table (For_Project).Decl.Packages;
3860 Compiler :=
3861 Prj.Util.Value_Of
3862 (Name => Name_Compiler,
3863 In_Packages => The_Packages,
3864 In_Tree => Project_Tree);
3865
3866 if Compiler /= No_Package then
3867 Local_Attribute := Prj.Util.Value_Of
3868 (Variable_Name => Name_Local_Configuration_Pragmas,
3869 In_Variables => Project_Tree.Packages.Table
3870 (Compiler).Decl.Attributes,
3871 In_Tree => Project_Tree);
3872 Local_Attribute_Present :=
3873 Local_Attribute /= Nil_Variable_Value
3874 and then Get_Name_String (Local_Attribute.Value) /= "";
3875
3876 if Local_Attribute_Present then
3877 declare
3878 Path : constant String :=
3879 Absolute_Path
3880 (Path_Name_Type (Local_Attribute.Value),
3881 Local_Attribute.Project);
3882 begin
3883 if not Is_Regular_File (Path) then
3884 Make_Failed
3885 ("cannot find configuration pragmas file ", Path);
3886 end if;
3887
3888 Last := Last + 1;
3889 Result (Last) := new String'("-gnatec=" & Path);
3890 end;
3891 end if;
3892 end if;
3893
3894 return Result (1 .. Last);
3895 end Configuration_Pragmas_Switch;
3896
3897 ---------------
3898 -- Debug_Msg --
3899 ---------------
3900
3901 procedure Debug_Msg (S : String; N : Name_Id) is
3902 begin
3903 if Debug.Debug_Flag_W then
3904 Write_Str (" ... ");
3905 Write_Str (S);
3906 Write_Str (" ");
3907 Write_Name (N);
3908 Write_Eol;
3909 end if;
3910 end Debug_Msg;
3911
3912 procedure Debug_Msg (S : String; N : File_Name_Type) is
3913 begin
3914 Debug_Msg (S, Name_Id (N));
3915 end Debug_Msg;
3916
3917 procedure Debug_Msg (S : String; N : Unit_Name_Type) is
3918 begin
3919 Debug_Msg (S, Name_Id (N));
3920 end Debug_Msg;
3921
3922 ---------------------------
3923 -- Delete_All_Temp_Files --
3924 ---------------------------
3925
3926 procedure Delete_All_Temp_Files is
3927 begin
3928 if Gnatmake_Called and not Debug.Debug_Flag_N then
3929 Delete_Mapping_Files;
3930 Delete_Temp_Config_Files;
3931 Prj.Env.Delete_All_Path_Files (Project_Tree);
3932 end if;
3933 end Delete_All_Temp_Files;
3934
3935 --------------------------
3936 -- Delete_Mapping_Files --
3937 --------------------------
3938
3939 procedure Delete_Mapping_Files is
3940 Success : Boolean;
3941 begin
3942 if not Debug.Debug_Flag_N then
3943 if The_Mapping_File_Names /= null then
3944 for Project in The_Mapping_File_Names'Range (1) loop
3945 for Index in 1 .. Last_Mapping_File_Names (Project) loop
3946 Delete_File
3947 (Name => Get_Name_String
3948 (The_Mapping_File_Names (Project, Index)),
3949 Success => Success);
3950 end loop;
3951 end loop;
3952 end if;
3953 end if;
3954 end Delete_Mapping_Files;
3955
3956 ------------------------------
3957 -- Delete_Temp_Config_Files --
3958 ------------------------------
3959
3960 procedure Delete_Temp_Config_Files is
3961 Success : Boolean;
3962 begin
3963 if (not Debug.Debug_Flag_N) and Main_Project /= No_Project then
3964 for Project in Project_Table.First ..
3965 Project_Table.Last (Project_Tree.Projects)
3966 loop
3967 if
3968 Project_Tree.Projects.Table (Project).Config_File_Temp
3969 then
3970 if Verbose_Mode then
3971 Write_Str ("Deleting temp configuration file """);
3972 Write_Str (Get_Name_String
3973 (Project_Tree.Projects.Table
3974 (Project).Config_File_Name));
3975 Write_Line ("""");
3976 end if;
3977
3978 Delete_File
3979 (Name => Get_Name_String
3980 (Project_Tree.Projects.Table
3981 (Project).Config_File_Name),
3982 Success => Success);
3983
3984 -- Make sure that we don't have a config file for this
3985 -- project, in case when there are several mains.
3986 -- In this case, we will recreate another config file:
3987 -- we cannot reuse the one that we just deleted!
3988
3989 Project_Tree.Projects.Table (Project).
3990 Config_Checked := False;
3991 Project_Tree.Projects.Table (Project).
3992 Config_File_Name := No_Path;
3993 Project_Tree.Projects.Table (Project).
3994 Config_File_Temp := False;
3995 end if;
3996 end loop;
3997 end if;
3998 end Delete_Temp_Config_Files;
3999
4000 -------------
4001 -- Display --
4002 -------------
4003
4004 procedure Display (Program : String; Args : Argument_List) is
4005 begin
4006 pragma Assert (Args'First = 1);
4007
4008 if Display_Executed_Programs then
4009 Write_Str (Program);
4010
4011 for J in Args'Range loop
4012
4013 -- Never display -gnatez
4014
4015 if Args (J).all /= "-gnatez" then
4016
4017 -- Do not display the mapping file argument automatically
4018 -- created when using a project file.
4019
4020 if Main_Project = No_Project
4021 or else Debug.Debug_Flag_N
4022 or else Args (J)'Length < 8
4023 or else
4024 Args (J) (Args (J)'First .. Args (J)'First + 6) /= "-gnatem"
4025 then
4026 -- When -dn is not specified, do not display the config
4027 -- pragmas switch (-gnatec) for the temporary file created
4028 -- by the project manager (always the first -gnatec switch).
4029 -- Reset Temporary_Config_File to False so that the eventual
4030 -- other -gnatec switches will be displayed.
4031
4032 if (not Debug.Debug_Flag_N)
4033 and then Temporary_Config_File
4034 and then Args (J)'Length > 7
4035 and then Args (J) (Args (J)'First .. Args (J)'First + 6)
4036 = "-gnatec"
4037 then
4038 Temporary_Config_File := False;
4039
4040 -- Do not display the -F=mapping_file switch for
4041 -- gnatbind, if -dn is not specified.
4042
4043 elsif Debug.Debug_Flag_N
4044 or else Args (J)'Length < 4
4045 or else
4046 Args (J) (Args (J)'First .. Args (J)'First + 2) /= "-F="
4047 then
4048 Write_Str (" ");
4049 Write_Str (Args (J).all);
4050 end if;
4051 end if;
4052 end if;
4053 end loop;
4054
4055 Write_Eol;
4056 end if;
4057 end Display;
4058
4059 ----------------------
4060 -- Display_Commands --
4061 ----------------------
4062
4063 procedure Display_Commands (Display : Boolean := True) is
4064 begin
4065 Display_Executed_Programs := Display;
4066 end Display_Commands;
4067
4068 -------------
4069 -- Empty_Q --
4070 -------------
4071
4072 function Empty_Q return Boolean is
4073 begin
4074 if Debug.Debug_Flag_P then
4075 Write_Str (" Q := [");
4076
4077 for J in Q_Front .. Q.Last - 1 loop
4078 Write_Str (" ");
4079 Write_Name (Q.Table (J).File);
4080 Write_Eol;
4081 Write_Str (" ");
4082 end loop;
4083
4084 Write_Str ("]");
4085 Write_Eol;
4086 end if;
4087
4088 return Q_Front >= Q.Last;
4089 end Empty_Q;
4090
4091 --------------------------
4092 -- Enter_Into_Obsoleted --
4093 --------------------------
4094
4095 procedure Enter_Into_Obsoleted (F : File_Name_Type) is
4096 Name : constant String := Get_Name_String (F);
4097 First : Natural;
4098 F2 : File_Name_Type;
4099
4100 begin
4101 First := Name'Last;
4102 while First > Name'First
4103 and then Name (First - 1) /= Directory_Separator
4104 and then Name (First - 1) /= '/'
4105 loop
4106 First := First - 1;
4107 end loop;
4108
4109 if First /= Name'First then
4110 Name_Len := 0;
4111 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
4112 F2 := Name_Find;
4113
4114 else
4115 F2 := F;
4116 end if;
4117
4118 Debug_Msg ("New entry in Obsoleted table:", F2);
4119 Obsoleted.Set (F2, True);
4120 end Enter_Into_Obsoleted;
4121
4122 --------------------
4123 -- Extract_From_Q --
4124 --------------------
4125
4126 procedure Extract_From_Q
4127 (Source_File : out File_Name_Type;
4128 Source_Unit : out Unit_Name_Type;
4129 Source_Index : out Int)
4130 is
4131 File : constant File_Name_Type := Q.Table (Q_Front).File;
4132 Unit : constant Unit_Name_Type := Q.Table (Q_Front).Unit;
4133 Index : constant Int := Q.Table (Q_Front).Index;
4134
4135 begin
4136 if Debug.Debug_Flag_Q then
4137 Write_Str (" Q := Q - [ ");
4138 Write_Name (File);
4139
4140 if Index /= 0 then
4141 Write_Str (", ");
4142 Write_Int (Index);
4143 end if;
4144
4145 Write_Str (" ]");
4146 Write_Eol;
4147 end if;
4148
4149 Q_Front := Q_Front + 1;
4150 Source_File := File;
4151 Source_Unit := Unit;
4152 Source_Index := Index;
4153 end Extract_From_Q;
4154
4155 --------------
4156 -- Gnatmake --
4157 --------------
4158
4159 procedure Gnatmake is
4160 Main_Source_File : File_Name_Type;
4161 -- The source file containing the main compilation unit
4162
4163 Compilation_Failures : Natural;
4164
4165 Total_Compilation_Failures : Natural := 0;
4166
4167 Is_Main_Unit : Boolean;
4168 -- Set to True by Compile_Sources if the Main_Source_File can be a
4169 -- main unit.
4170
4171 Main_ALI_File : File_Name_Type;
4172 -- The ali file corresponding to Main_Source_File
4173
4174 Executable : File_Name_Type := No_File;
4175 -- The file name of an executable
4176
4177 Non_Std_Executable : Boolean := False;
4178 -- Non_Std_Executable is set to True when there is a possibility
4179 -- that the linker will not choose the correct executable file name.
4180
4181 Current_Work_Dir : constant String_Access :=
4182 new String'(Get_Current_Dir);
4183 -- The current working directory, used to modify some relative path
4184 -- switches on the command line when a project file is used.
4185
4186 Current_Main_Index : Int := 0;
4187 -- If not zero, the index of the current main unit in its source file
4188
4189 There_Are_Stand_Alone_Libraries : Boolean := False;
4190 -- Set to True when there are Stand-Alone Libraries, so that gnatbind
4191 -- is invoked with the -F switch to force checking of elaboration flags.
4192
4193 Mapping_Path : Path_Name_Type := No_Path;
4194 -- The path name of the mapping file
4195
4196 Discard : Boolean;
4197
4198 procedure Check_Mains;
4199 -- Check that the main subprograms do exist and that they all
4200 -- belong to the same project file.
4201
4202 procedure Create_Binder_Mapping_File
4203 (Args : in out Argument_List; Last_Arg : in out Natural);
4204 -- Create a binder mapping file and add the necessary switch
4205
4206 -----------------
4207 -- Check_Mains --
4208 -----------------
4209
4210 procedure Check_Mains is
4211 Real_Main_Project : Project_Id := No_Project;
4212 -- The project of the first main
4213
4214 Proj : Project_Id := No_Project;
4215 -- The project of the current main
4216
4217 Data : Project_Data;
4218
4219 Real_Path : String_Access;
4220
4221 begin
4222 Mains.Reset;
4223
4224 -- Check each main
4225
4226 loop
4227 declare
4228 Main : constant String := Mains.Next_Main;
4229 -- The name specified on the command line may include
4230 -- directory information.
4231
4232 File_Name : constant String := Base_Name (Main);
4233 -- The simple file name of the current main main
4234
4235 begin
4236 exit when Main = "";
4237
4238 -- Get the project of the current main
4239
4240 Proj := Prj.Env.Project_Of
4241 (File_Name, Main_Project, Project_Tree);
4242
4243 -- Fail if the current main is not a source of a
4244 -- project.
4245
4246 if Proj = No_Project then
4247 Make_Failed
4248 ("""" & Main &
4249 """ is not a source of any project");
4250
4251 else
4252 -- If there is directory information, check that
4253 -- the source exists and, if it does, that the path
4254 -- is the actual path of a source of a project.
4255
4256 if Main /= File_Name then
4257 Data :=
4258 Project_Tree.Projects.Table (Main_Project);
4259
4260 Real_Path :=
4261 Locate_Regular_File
4262 (Main &
4263 Body_Suffix_Of (Project_Tree, "ada", Data.Naming),
4264 "");
4265 if Real_Path = null then
4266 Real_Path :=
4267 Locate_Regular_File
4268 (Main &
4269 Spec_Suffix_Of (Project_Tree, "ada", Data.Naming),
4270 "");
4271 end if;
4272
4273 if Real_Path = null then
4274 Real_Path :=
4275 Locate_Regular_File (Main, "");
4276 end if;
4277
4278 -- Fail if the file cannot be found
4279
4280 if Real_Path = null then
4281 Make_Failed
4282 ("file """ & Main & """ does not exist");
4283 end if;
4284
4285 declare
4286 Project_Path : constant String :=
4287 Prj.Env.File_Name_Of_Library_Unit_Body
4288 (Name => File_Name,
4289 Project => Main_Project,
4290 In_Tree => Project_Tree,
4291 Main_Project_Only => False,
4292 Full_Path => True);
4293 Normed_Path : constant String :=
4294 Normalize_Pathname
4295 (Real_Path.all,
4296 Case_Sensitive => False);
4297 Proj_Path : constant String :=
4298 Normalize_Pathname
4299 (Project_Path,
4300 Case_Sensitive => False);
4301
4302 begin
4303 Free (Real_Path);
4304
4305 -- Fail if it is not the correct path
4306
4307 if Normed_Path /= Proj_Path then
4308 if Verbose_Mode then
4309 Set_Standard_Error;
4310 Write_Str (Normed_Path);
4311 Write_Str (" /= ");
4312 Write_Line (Proj_Path);
4313 end if;
4314
4315 Make_Failed
4316 ("""" & Main &
4317 """ is not a source of any project");
4318 end if;
4319 end;
4320 end if;
4321
4322 if not Unique_Compile then
4323
4324 -- Record the project, if it is the first main
4325
4326 if Real_Main_Project = No_Project then
4327 Real_Main_Project := Proj;
4328
4329 elsif Proj /= Real_Main_Project then
4330
4331 -- Fail, as the current main is not a source
4332 -- of the same project as the first main.
4333
4334 Make_Failed
4335 ("""" & Main &
4336 """ is not a source of project " &
4337 Get_Name_String
4338 (Project_Tree.Projects.Table
4339 (Real_Main_Project).Name));
4340 end if;
4341 end if;
4342 end if;
4343
4344 -- If -u and -U are not used, we may have mains that
4345 -- are sources of a project that is not the one
4346 -- specified with switch -P.
4347
4348 if not Unique_Compile then
4349 Main_Project := Real_Main_Project;
4350 end if;
4351 end;
4352 end loop;
4353 end Check_Mains;
4354
4355 --------------------------------
4356 -- Create_Binder_Mapping_File --
4357 --------------------------------
4358
4359 procedure Create_Binder_Mapping_File
4360 (Args : in out Argument_List; Last_Arg : in out Natural)
4361 is
4362 Mapping_FD : File_Descriptor := Invalid_FD;
4363 -- A File Descriptor for an eventual mapping file
4364
4365 ALI_Unit : Unit_Name_Type := No_Unit_Name;
4366 -- The unit name of an ALI file
4367
4368 ALI_Name : File_Name_Type := No_File;
4369 -- The file name of the ALI file
4370
4371 ALI_Project : Project_Id := No_Project;
4372 -- The project of the ALI file
4373
4374 Bytes : Integer;
4375 OK : Boolean := True;
4376
4377 Status : Boolean;
4378 -- For call to Close
4379
4380 begin
4381 Tempdir.Create_Temp_File (Mapping_FD, Mapping_Path);
4382 Record_Temp_File (Mapping_Path);
4383
4384 if Mapping_FD /= Invalid_FD then
4385
4386 -- Traverse all units
4387
4388 for J in Unit_Table.First ..
4389 Unit_Table.Last (Project_Tree.Units)
4390 loop
4391 declare
4392 Unit : constant Unit_Data := Project_Tree.Units.Table (J);
4393 begin
4394 if Unit.Name /= No_Name then
4395
4396 -- If there is a body, put it in the mapping
4397
4398 if Unit.File_Names (Body_Part).Name /= No_File
4399 and then Unit.File_Names (Body_Part).Project /=
4400 No_Project
4401 then
4402 Get_Name_String (Unit.Name);
4403 Name_Buffer (Name_Len + 1 .. Name_Len + 2) := "%b";
4404 Name_Len := Name_Len + 2;
4405 ALI_Unit := Name_Find;
4406 ALI_Name :=
4407 Lib_File_Name
4408 (Unit.File_Names (Body_Part).Display_Name);
4409 ALI_Project :=
4410 Unit.File_Names (Body_Part).Project;
4411
4412 -- Otherwise, if there is a spec, put it
4413 -- in the mapping.
4414
4415 elsif Unit.File_Names (Specification).Name /= No_File
4416 and then Unit.File_Names (Specification).Project /=
4417 No_Project
4418 then
4419 Get_Name_String (Unit.Name);
4420 Name_Buffer (Name_Len + 1 .. Name_Len + 2) := "%s";
4421 Name_Len := Name_Len + 2;
4422 ALI_Unit := Name_Find;
4423 ALI_Name :=
4424 Lib_File_Name
4425 (Unit.File_Names (Specification).Display_Name);
4426 ALI_Project :=
4427 Unit.File_Names (Specification).Project;
4428
4429 else
4430 ALI_Name := No_File;
4431 end if;
4432
4433 -- If we have something to put in the mapping
4434 -- then we do it now. However, if the project
4435 -- is extended, we don't put anything in the
4436 -- mapping file, because we do not know where
4437 -- the ALI file is: it might be in the ext-
4438 -- ended project obj dir as well as in the
4439 -- extending project obj dir.
4440
4441 if ALI_Name /= No_File
4442 and then
4443 Project_Tree.Projects.Table
4444 (ALI_Project).Extended_By = No_Project
4445 and then
4446 Project_Tree.Projects.Table
4447 (ALI_Project).Extends = No_Project
4448 then
4449 -- First check if the ALI file exists. If it does not,
4450 -- do not put the unit in the mapping file.
4451
4452 declare
4453 ALI : constant String :=
4454 Get_Name_String (ALI_Name);
4455 PD : Project_Data renames
4456 Project_Tree.Projects.Table (ALI_Project);
4457
4458 begin
4459 -- For library projects, use the library directory,
4460 -- for other projects, use the object directory.
4461
4462 if PD.Library then
4463 Get_Name_String (PD.Library_Dir);
4464 else
4465 Get_Name_String (PD.Object_Directory);
4466 end if;
4467
4468 if Name_Buffer (Name_Len) /=
4469 Directory_Separator
4470 then
4471 Name_Len := Name_Len + 1;
4472 Name_Buffer (Name_Len) :=
4473 Directory_Separator;
4474 end if;
4475
4476 Name_Buffer
4477 (Name_Len + 1 ..
4478 Name_Len + ALI'Length) := ALI;
4479 Name_Len :=
4480 Name_Len + ALI'Length + 1;
4481 Name_Buffer (Name_Len) := ASCII.LF;
4482
4483 declare
4484 ALI_Path_Name : constant String :=
4485 Name_Buffer (1 .. Name_Len);
4486
4487 begin
4488 if Is_Regular_File
4489 (ALI_Path_Name (1 .. ALI_Path_Name'Last - 1))
4490 then
4491
4492 -- First line is the unit name
4493
4494 Get_Name_String (ALI_Unit);
4495 Name_Len := Name_Len + 1;
4496 Name_Buffer (Name_Len) := ASCII.LF;
4497 Bytes :=
4498 Write
4499 (Mapping_FD,
4500 Name_Buffer (1)'Address,
4501 Name_Len);
4502 OK := Bytes = Name_Len;
4503
4504 exit when not OK;
4505
4506 -- Second line it the ALI file name
4507
4508 Get_Name_String (ALI_Name);
4509 Name_Len := Name_Len + 1;
4510 Name_Buffer (Name_Len) := ASCII.LF;
4511 Bytes :=
4512 Write
4513 (Mapping_FD,
4514 Name_Buffer (1)'Address,
4515 Name_Len);
4516 OK := Bytes = Name_Len;
4517
4518 exit when not OK;
4519
4520 -- Third line it the ALI path name
4521
4522 Bytes :=
4523 Write
4524 (Mapping_FD,
4525 ALI_Path_Name (1)'Address,
4526 ALI_Path_Name'Length);
4527 OK := Bytes = ALI_Path_Name'Length;
4528
4529 -- If OK is False, it means we were unable
4530 -- to write a line. No point in continuing
4531 -- with the other units.
4532
4533 exit when not OK;
4534 end if;
4535 end;
4536 end;
4537 end if;
4538 end if;
4539 end;
4540 end loop;
4541
4542 Close (Mapping_FD, Status);
4543
4544 OK := OK and Status;
4545
4546 -- If the creation of the mapping file was successful,
4547 -- we add the switch to the arguments of gnatbind.
4548
4549 if OK then
4550 Last_Arg := Last_Arg + 1;
4551 Args (Last_Arg) :=
4552 new String'("-F=" & Get_Name_String (Mapping_Path));
4553 end if;
4554 end if;
4555 end Create_Binder_Mapping_File;
4556
4557 -- Start of processing for Gnatmake
4558
4559 -- This body is very long, should be broken down ???
4560
4561 begin
4562 Gnatmake_Called := True;
4563
4564 Install_Int_Handler (Sigint_Intercepted'Access);
4565
4566 Do_Compile_Step := True;
4567 Do_Bind_Step := True;
4568 Do_Link_Step := True;
4569
4570 Obsoleted.Reset;
4571
4572 Make.Initialize;
4573
4574 Bind_Shared := No_Shared_Switch'Access;
4575 Link_With_Shared_Libgcc := No_Shared_Libgcc_Switch'Access;
4576
4577 Failed_Links.Set_Last (0);
4578 Successful_Links.Set_Last (0);
4579
4580 -- Special case when switch -B was specified
4581
4582 if Build_Bind_And_Link_Full_Project then
4583
4584 -- When switch -B is specified, there must be a project file
4585
4586 if Main_Project = No_Project then
4587 Make_Failed ("-B cannot be used without a project file");
4588
4589 -- No main program may be specified on the command line
4590
4591 elsif Osint.Number_Of_Files /= 0 then
4592 Make_Failed ("-B cannot be used with a main specified on " &
4593 "the command line");
4594
4595 -- And the project file cannot be a library project file
4596
4597 elsif Project_Tree.Projects.Table (Main_Project).Library then
4598 Make_Failed ("-B cannot be used for a library project file");
4599
4600 else
4601 No_Main_Subprogram := True;
4602 Insert_Project_Sources
4603 (The_Project => Main_Project,
4604 All_Projects => Unique_Compile_All_Projects,
4605 Into_Q => False);
4606
4607 -- If there are no sources to compile, we fail
4608
4609 if Osint.Number_Of_Files = 0 then
4610 Make_Failed ("no sources to compile");
4611 end if;
4612
4613 -- Specify -n for gnatbind and add the ALI files of all the
4614 -- sources, except the one which is a fake main subprogram:
4615 -- this is the one for the binder generated file and it will be
4616 -- transmitted to gnatlink. These sources are those that are
4617 -- in the queue.
4618
4619 Add_Switch ("-n", Binder, And_Save => True);
4620
4621 for J in Q.First .. Q.Last - 1 loop
4622 Add_Switch
4623 (Get_Name_String
4624 (Lib_File_Name (Q.Table (J).File)),
4625 Binder, And_Save => True);
4626 end loop;
4627 end if;
4628
4629 elsif Main_Index /= 0 and then Osint.Number_Of_Files > 1 then
4630 Make_Failed ("cannot specify several mains with a multi-unit index");
4631
4632 elsif Main_Project /= No_Project then
4633
4634 -- If the main project file is a library project file, main(s)
4635 -- cannot be specified on the command line.
4636
4637 if Osint.Number_Of_Files /= 0 then
4638 if Project_Tree.Projects.Table (Main_Project).Library
4639 and then not Unique_Compile
4640 and then ((not Make_Steps) or else Bind_Only or else Link_Only)
4641 then
4642 Make_Failed ("cannot specify a main program " &
4643 "on the command line for a library project file");
4644
4645 else
4646 -- Check that each main on the command line is a source of a
4647 -- project file and, if there are several mains, each of them
4648 -- is a source of the same project file.
4649
4650 Check_Mains;
4651 end if;
4652
4653 -- If no mains have been specified on the command line,
4654 -- and we are using a project file, we either find the main(s)
4655 -- in the attribute Main of the main project, or we put all
4656 -- the sources of the project file as mains.
4657
4658 else
4659 if Main_Index /= 0 then
4660 Make_Failed ("cannot specify a multi-unit index but no main " &
4661 "on the command line");
4662 end if;
4663
4664 declare
4665 Value : String_List_Id :=
4666 Project_Tree.Projects.Table (Main_Project).Mains;
4667
4668 begin
4669 -- The attribute Main is an empty list or not specified,
4670 -- or else gnatmake was invoked with the switch "-u".
4671
4672 if Value = Prj.Nil_String or else Unique_Compile then
4673
4674 if (not Make_Steps) or else Compile_Only
4675 or else not Project_Tree.Projects.Table
4676 (Main_Project).Library
4677 then
4678 -- First make sure that the binder and the linker
4679 -- will not be invoked.
4680
4681 Do_Bind_Step := False;
4682 Do_Link_Step := False;
4683
4684 -- Put all the sources in the queue
4685
4686 No_Main_Subprogram := True;
4687 Insert_Project_Sources
4688 (The_Project => Main_Project,
4689 All_Projects => Unique_Compile_All_Projects,
4690 Into_Q => False);
4691
4692 -- If no sources to compile, then there is nothing to do
4693
4694 if Osint.Number_Of_Files = 0 then
4695 if not Debug.Debug_Flag_N then
4696 Delete_Mapping_Files;
4697 Prj.Env.Delete_All_Path_Files (Project_Tree);
4698 end if;
4699
4700 if not Quiet_Output then
4701 Osint.Write_Program_Name;
4702 Write_Line (": no sources to compile");
4703 end if;
4704
4705 Exit_Program (E_Success);
4706 end if;
4707 end if;
4708
4709 else
4710 -- The attribute Main is not an empty list.
4711 -- Put all the main subprograms in the list as if there
4712 -- were specified on the command line. However, if attribute
4713 -- Languages includes a language other than Ada, only
4714 -- include the Ada mains; if there is no Ada main, compile
4715 -- all the sources of the project.
4716
4717 declare
4718 Data : constant Project_Data :=
4719 Project_Tree.Projects.Table (Main_Project);
4720
4721 Languages : constant Variable_Value :=
4722 Prj.Util.Value_Of
4723 (Name_Languages,
4724 Data.Decl.Attributes,
4725 Project_Tree);
4726
4727 Current : String_List_Id;
4728 Element : String_Element;
4729
4730 Foreign_Language : Boolean := False;
4731 At_Least_One_Main : Boolean := False;
4732
4733 begin
4734 -- First, determine if there is a foreign language in
4735 -- attribute Languages.
4736
4737 if not Languages.Default then
4738 Current := Languages.Values;
4739
4740 Look_For_Foreign :
4741 while Current /= Nil_String loop
4742 Element := Project_Tree.String_Elements.
4743 Table (Current);
4744 Get_Name_String (Element.Value);
4745 To_Lower (Name_Buffer (1 .. Name_Len));
4746
4747 if Name_Buffer (1 .. Name_Len) /= "ada" then
4748 Foreign_Language := True;
4749 exit Look_For_Foreign;
4750 end if;
4751
4752 Current := Element.Next;
4753 end loop Look_For_Foreign;
4754 end if;
4755
4756 -- Then, find all mains, or if there is a foreign
4757 -- language, all the Ada mains.
4758
4759 while Value /= Prj.Nil_String loop
4760 Get_Name_String
4761 (Project_Tree.String_Elements.Table
4762 (Value).Value);
4763
4764 -- To know if a main is an Ada main, get its project.
4765 -- It should be the project specified on the command
4766 -- line.
4767
4768 if (not Foreign_Language) or else
4769 Prj.Env.Project_Of
4770 (Name_Buffer (1 .. Name_Len),
4771 Main_Project,
4772 Project_Tree) =
4773 Main_Project
4774 then
4775 At_Least_One_Main := True;
4776 Osint.Add_File
4777 (Get_Name_String
4778 (Project_Tree.String_Elements.Table
4779 (Value).Value),
4780 Index =>
4781 Project_Tree.String_Elements.Table
4782 (Value).Index);
4783 end if;
4784
4785 Value := Project_Tree.String_Elements.Table
4786 (Value).Next;
4787 end loop;
4788
4789 -- If we did not get any main, it means that all mains
4790 -- in attribute Mains are in a foreign language and -B
4791 -- was not specified to gnatmake; so, we fail.
4792
4793 if not At_Least_One_Main then
4794 Make_Failed
4795 ("no Ada mains; use -B to build foreign main");
4796 end if;
4797 end;
4798
4799 end if;
4800 end;
4801 end if;
4802 end if;
4803
4804 if Verbose_Mode then
4805 Write_Eol;
4806 Display_Version ("GNATMAKE ", "1995");
4807 end if;
4808
4809 if Main_Project /= No_Project
4810 and then Project_Tree.Projects.Table
4811 (Main_Project).Externally_Built
4812 then
4813 Make_Failed
4814 ("nothing to do for a main project that is externally built");
4815 end if;
4816
4817 if Osint.Number_Of_Files = 0 then
4818 if Main_Project /= No_Project
4819 and then Project_Tree.Projects.Table (Main_Project).Library
4820 then
4821 if Do_Bind_Step
4822 and then not Project_Tree.Projects.Table
4823 (Main_Project).Standalone_Library
4824 then
4825 Make_Failed ("only stand-alone libraries may be bound");
4826 end if;
4827
4828 -- Add the default search directories to be able to find libgnat
4829
4830 Osint.Add_Default_Search_Dirs;
4831
4832 -- Get the target parameters, so that the correct binder generated
4833 -- files are generated if OpenVMS is the target.
4834
4835 begin
4836 Targparm.Get_Target_Parameters;
4837
4838 exception
4839 when Unrecoverable_Error =>
4840 Make_Failed ("*** make failed.");
4841 end;
4842
4843 -- And bind and or link the library
4844
4845 MLib.Prj.Build_Library
4846 (For_Project => Main_Project,
4847 In_Tree => Project_Tree,
4848 Gnatbind => Gnatbind.all,
4849 Gnatbind_Path => Gnatbind_Path,
4850 Gcc => Gcc.all,
4851 Gcc_Path => Gcc_Path,
4852 Bind => Bind_Only,
4853 Link => Link_Only);
4854 Exit_Program (E_Success);
4855
4856 else
4857 -- Output usage information if no files to compile
4858
4859 Usage;
4860 Exit_Program (E_Fatal);
4861 end if;
4862 end if;
4863
4864 -- If -M was specified, behave as if -n was specified
4865
4866 if List_Dependencies then
4867 Do_Not_Execute := True;
4868 end if;
4869
4870 -- Note that Osint.M.Next_Main_Source will always return the (possibly
4871 -- abbreviated file) without any directory information.
4872
4873 Main_Source_File := Next_Main_Source;
4874
4875 if Current_File_Index /= No_Index then
4876 Main_Index := Current_File_Index;
4877 end if;
4878
4879 Add_Switch ("-I-", Compiler, And_Save => True);
4880
4881 if Main_Project = No_Project then
4882 if Look_In_Primary_Dir then
4883
4884 Add_Switch
4885 ("-I" &
4886 Normalize_Directory_Name
4887 (Get_Primary_Src_Search_Directory.all).all,
4888 Compiler, Append_Switch => False,
4889 And_Save => False);
4890
4891 end if;
4892
4893 else
4894 -- If we use a project file, we have already checked that a main
4895 -- specified on the command line with directory information has the
4896 -- path name corresponding to a correct source in the project tree.
4897 -- So, we don't need the directory information to be taken into
4898 -- account by Find_File, and in fact it may lead to take the wrong
4899 -- sources for other compilation units, when there are extending
4900 -- projects.
4901
4902 Look_In_Primary_Dir := False;
4903 Add_Switch ("-I-", Binder, And_Save => True);
4904 end if;
4905
4906 -- If the user wants a program without a main subprogram, add the
4907 -- appropriate switch to the binder.
4908
4909 if No_Main_Subprogram then
4910 Add_Switch ("-z", Binder, And_Save => True);
4911 end if;
4912
4913 if Main_Project /= No_Project then
4914
4915 if Project_Tree.Projects.Table
4916 (Main_Project).Object_Directory /= No_Path
4917 then
4918 -- Change current directory to object directory of main project
4919
4920 Project_Of_Current_Object_Directory := No_Project;
4921 Change_To_Object_Directory (Main_Project);
4922 end if;
4923
4924 -- Source file lookups should be cached for efficiency.
4925 -- Source files are not supposed to change.
4926
4927 Osint.Source_File_Data (Cache => True);
4928
4929 -- Find the file name of the (first) main unit
4930
4931 declare
4932 Main_Source_File_Name : constant String :=
4933 Get_Name_String (Main_Source_File);
4934 Main_Unit_File_Name : constant String :=
4935 Prj.Env.File_Name_Of_Library_Unit_Body
4936 (Name => Main_Source_File_Name,
4937 Project => Main_Project,
4938 In_Tree => Project_Tree,
4939 Main_Project_Only =>
4940 not Unique_Compile);
4941
4942 The_Packages : constant Package_Id :=
4943 Project_Tree.Projects.Table
4944 (Main_Project).Decl.Packages;
4945
4946 Builder_Package : constant Prj.Package_Id :=
4947 Prj.Util.Value_Of
4948 (Name => Name_Builder,
4949 In_Packages => The_Packages,
4950 In_Tree => Project_Tree);
4951
4952 Binder_Package : constant Prj.Package_Id :=
4953 Prj.Util.Value_Of
4954 (Name => Name_Binder,
4955 In_Packages => The_Packages,
4956 In_Tree => Project_Tree);
4957
4958 Linker_Package : constant Prj.Package_Id :=
4959 Prj.Util.Value_Of
4960 (Name => Name_Linker,
4961 In_Packages => The_Packages,
4962 In_Tree => Project_Tree);
4963
4964 begin
4965 -- We fail if we cannot find the main source file
4966
4967 if Main_Unit_File_Name = "" then
4968 Make_Failed ('"' & Main_Source_File_Name,
4969 """ is not a unit of project ",
4970 Project_File_Name.all & ".");
4971 else
4972 -- Remove any directory information from the main
4973 -- source file name.
4974
4975 declare
4976 Pos : Natural := Main_Unit_File_Name'Last;
4977
4978 begin
4979 loop
4980 exit when Pos < Main_Unit_File_Name'First or else
4981 Main_Unit_File_Name (Pos) = Directory_Separator;
4982 Pos := Pos - 1;
4983 end loop;
4984
4985 Name_Len := Main_Unit_File_Name'Last - Pos;
4986
4987 Name_Buffer (1 .. Name_Len) :=
4988 Main_Unit_File_Name
4989 (Pos + 1 .. Main_Unit_File_Name'Last);
4990
4991 Main_Source_File := Name_Find;
4992
4993 -- We only output the main source file if there is only one
4994
4995 if Verbose_Mode and then Osint.Number_Of_Files = 1 then
4996 Write_Str ("Main source file: """);
4997 Write_Str (Main_Unit_File_Name
4998 (Pos + 1 .. Main_Unit_File_Name'Last));
4999 Write_Line (""".");
5000 end if;
5001 end;
5002 end if;
5003
5004 -- If there is a package Builder in the main project file, add
5005 -- the switches from it.
5006
5007 if Builder_Package /= No_Package then
5008
5009 -- If there is only one main, we attempt to get the gnatmake
5010 -- switches for this main (if any). If there are no specific
5011 -- switch for this particular main, get the general gnatmake
5012 -- switches (if any).
5013
5014 if Osint.Number_Of_Files = 1 then
5015 if Verbose_Mode then
5016 Write_Str ("Adding gnatmake switches for """);
5017 Write_Str (Main_Unit_File_Name);
5018 Write_Line (""".");
5019 end if;
5020
5021 Add_Switches
5022 (File_Name => Main_Unit_File_Name,
5023 Index => Main_Index,
5024 The_Package => Builder_Package,
5025 Program => None);
5026
5027 else
5028 -- If there are several mains, we always get the general
5029 -- gnatmake switches (if any).
5030
5031 -- Warn the user, if necessary, so that he is not surprized
5032 -- that specific switches are not taken into account.
5033
5034 declare
5035 Defaults : constant Variable_Value :=
5036 Prj.Util.Value_Of
5037 (Name => Name_Ada,
5038 Index => 0,
5039 Attribute_Or_Array_Name => Name_Default_Switches,
5040 In_Package => Builder_Package,
5041 In_Tree => Project_Tree);
5042
5043 Switches : constant Array_Element_Id :=
5044 Prj.Util.Value_Of
5045 (Name => Name_Switches,
5046 In_Arrays =>
5047 Project_Tree.Packages.Table
5048 (Builder_Package).Decl.Arrays,
5049 In_Tree => Project_Tree);
5050
5051 begin
5052 if Defaults /= Nil_Variable_Value then
5053 if (not Quiet_Output)
5054 and then Switches /= No_Array_Element
5055 then
5056 Write_Line
5057 ("Warning: using Builder'Default_Switches" &
5058 "(""Ada""), as there are several mains");
5059 end if;
5060
5061 -- As there is never a source with name " ", we are
5062 -- guaranteed to always get the general switches.
5063
5064 Add_Switches
5065 (File_Name => " ",
5066 Index => 0,
5067 The_Package => Builder_Package,
5068 Program => None);
5069
5070 elsif (not Quiet_Output)
5071 and then Switches /= No_Array_Element
5072 then
5073 Write_Line
5074 ("Warning: using no switches from package Builder," &
5075 " as there are several mains");
5076 end if;
5077 end;
5078 end if;
5079 end if;
5080
5081 Osint.Add_Default_Search_Dirs;
5082
5083 -- Record the current last switch index for table Binder_Switches
5084 -- and Linker_Switches, so that these tables may be reset before
5085 -- for each main, before adding swiches from the project file
5086 -- and from the command line.
5087
5088 Last_Binder_Switch := Binder_Switches.Last;
5089 Last_Linker_Switch := Linker_Switches.Last;
5090
5091 Check_Steps;
5092
5093 -- Add binder switches from the project file for the first main
5094
5095 if Do_Bind_Step and Binder_Package /= No_Package then
5096 if Verbose_Mode then
5097 Write_Str ("Adding binder switches for """);
5098 Write_Str (Main_Unit_File_Name);
5099 Write_Line (""".");
5100 end if;
5101
5102 Add_Switches
5103 (File_Name => Main_Unit_File_Name,
5104 Index => Main_Index,
5105 The_Package => Binder_Package,
5106 Program => Binder);
5107 end if;
5108
5109 -- Add linker switches from the project file for the first main
5110
5111 if Do_Link_Step and Linker_Package /= No_Package then
5112 if Verbose_Mode then
5113 Write_Str ("Adding linker switches for""");
5114 Write_Str (Main_Unit_File_Name);
5115 Write_Line (""".");
5116 end if;
5117
5118 Add_Switches
5119 (File_Name => Main_Unit_File_Name,
5120 Index => Main_Index,
5121 The_Package => Linker_Package,
5122 Program => Linker);
5123 end if;
5124 end;
5125 end if;
5126
5127 -- Get the target parameters, which are only needed for a couple of
5128 -- cases in gnatmake. Protect against an exception, such as the case
5129 -- of system.ads missing from the library, and fail gracefully.
5130
5131 begin
5132 Targparm.Get_Target_Parameters;
5133
5134 exception
5135 when Unrecoverable_Error =>
5136 Make_Failed ("*** make failed.");
5137 end;
5138
5139 -- Special processing for VM targets
5140
5141 if Targparm.VM_Target /= No_VM then
5142
5143 -- Do not check for an object file (".o") when compiling to VM
5144 -- machine since ".class" files are generated instead.
5145
5146 Check_Object_Consistency := False;
5147
5148 -- Set proper processing commands
5149
5150 case Targparm.VM_Target is
5151 when Targparm.JVM_Target =>
5152 Gcc := new String'("jgnat");
5153 Gnatbind := new String'("jgnatbind");
5154 Gnatlink := new String'("jgnatlink");
5155
5156 when Targparm.CLI_Target =>
5157 Gcc := new String'("dotnet-gnatcompile");
5158
5159 when Targparm.No_VM =>
5160 raise Program_Error;
5161 end case;
5162 end if;
5163
5164 Display_Commands (not Quiet_Output);
5165
5166 Check_Steps;
5167
5168 if Main_Project /= No_Project then
5169
5170 -- For all library project, if the library file does not exist
5171 -- put all the project sources in the queue, and flag the project
5172 -- so that the library is generated.
5173
5174 if not Unique_Compile
5175 and then MLib.Tgt.Support_For_Libraries /= Prj.None
5176 then
5177 for Proj in Project_Table.First ..
5178 Project_Table.Last (Project_Tree.Projects)
5179 loop
5180 if Project_Tree.Projects.Table (Proj).Library then
5181 Project_Tree.Projects.Table
5182 (Proj).Need_To_Build_Lib :=
5183 (not MLib.Tgt.Library_Exists_For (Proj, Project_Tree))
5184 and then (not Project_Tree.Projects.Table
5185 (Proj).Externally_Built);
5186
5187 if Project_Tree.Projects.Table (Proj).Need_To_Build_Lib then
5188
5189 -- If there is no object directory, then it will be
5190 -- impossible to build the library. So fail immediately.
5191
5192 if Project_Tree.Projects.Table (Proj).Object_Directory =
5193 No_Path
5194 then
5195 Make_Failed
5196 ("no object files to build library for project """,
5197 Get_Name_String
5198 (Project_Tree.Projects.Table (Proj).Name),
5199 """");
5200 Project_Tree.Projects.Table
5201 (Proj).Need_To_Build_Lib := False;
5202
5203 else
5204 if Verbose_Mode then
5205 Write_Str
5206 ("Library file does not exist for project """);
5207 Write_Str
5208 (Get_Name_String
5209 (Project_Tree.Projects.Table
5210 (Proj).Name));
5211 Write_Line ("""");
5212 end if;
5213
5214 Insert_Project_Sources
5215 (The_Project => Proj,
5216 All_Projects => False,
5217 Into_Q => True);
5218 end if;
5219 end if;
5220 end if;
5221 end loop;
5222 end if;
5223
5224 -- If a relative path output file has been specified, we add
5225 -- the exec directory.
5226
5227 for J in reverse 1 .. Saved_Linker_Switches.Last - 1 loop
5228 if Saved_Linker_Switches.Table (J).all = Output_Flag.all then
5229 declare
5230 Exec_File_Name : constant String :=
5231 Saved_Linker_Switches.Table (J + 1).all;
5232
5233 begin
5234 if not Is_Absolute_Path (Exec_File_Name) then
5235 Get_Name_String
5236 (Project_Tree.Projects.Table
5237 (Main_Project).Exec_Directory);
5238
5239 if Name_Buffer (Name_Len) /= Directory_Separator then
5240 Name_Len := Name_Len + 1;
5241 Name_Buffer (Name_Len) := Directory_Separator;
5242 end if;
5243
5244 Name_Buffer (Name_Len + 1 ..
5245 Name_Len + Exec_File_Name'Length) :=
5246 Exec_File_Name;
5247 Name_Len := Name_Len + Exec_File_Name'Length;
5248 Saved_Linker_Switches.Table (J + 1) :=
5249 new String'(Name_Buffer (1 .. Name_Len));
5250 end if;
5251 end;
5252
5253 exit;
5254 end if;
5255 end loop;
5256
5257 -- If we are using a project file, for relative paths we add the
5258 -- current working directory for any relative path on the command
5259 -- line and the project directory, for any relative path in the
5260 -- project file.
5261
5262 declare
5263 Dir_Path : constant String_Access :=
5264 new String'(Get_Name_String
5265 (Project_Tree.Projects.Table
5266 (Main_Project).Directory));
5267 begin
5268 for J in 1 .. Binder_Switches.Last loop
5269 Test_If_Relative_Path
5270 (Binder_Switches.Table (J),
5271 Parent => Dir_Path, Including_L_Switch => False);
5272 end loop;
5273
5274 for J in 1 .. Saved_Binder_Switches.Last loop
5275 Test_If_Relative_Path
5276 (Saved_Binder_Switches.Table (J),
5277 Parent => Current_Work_Dir, Including_L_Switch => False);
5278 end loop;
5279
5280 for J in 1 .. Linker_Switches.Last loop
5281 Test_If_Relative_Path
5282 (Linker_Switches.Table (J), Parent => Dir_Path);
5283 end loop;
5284
5285 for J in 1 .. Saved_Linker_Switches.Last loop
5286 Test_If_Relative_Path
5287 (Saved_Linker_Switches.Table (J), Parent => Current_Work_Dir);
5288 end loop;
5289
5290 for J in 1 .. Gcc_Switches.Last loop
5291 Test_If_Relative_Path
5292 (Gcc_Switches.Table (J),
5293 Parent => Dir_Path,
5294 Including_Non_Switch => False);
5295 end loop;
5296
5297 for J in 1 .. Saved_Gcc_Switches.Last loop
5298 Test_If_Relative_Path
5299 (Saved_Gcc_Switches.Table (J),
5300 Parent => Current_Work_Dir,
5301 Including_Non_Switch => False);
5302 end loop;
5303 end;
5304 end if;
5305
5306 -- We now put in the Binder_Switches and Linker_Switches tables, the
5307 -- binder and linker switches of the command line that have been put in
5308 -- the Saved_ tables. If a project file was used, then the command line
5309 -- switches will follow the project file switches.
5310
5311 for J in 1 .. Saved_Binder_Switches.Last loop
5312 Add_Switch
5313 (Saved_Binder_Switches.Table (J),
5314 Binder,
5315 And_Save => False);
5316 end loop;
5317
5318 for J in 1 .. Saved_Linker_Switches.Last loop
5319 Add_Switch
5320 (Saved_Linker_Switches.Table (J),
5321 Linker,
5322 And_Save => False);
5323 end loop;
5324
5325 -- If no project file is used, we just put the gcc switches
5326 -- from the command line in the Gcc_Switches table.
5327
5328 if Main_Project = No_Project then
5329 for J in 1 .. Saved_Gcc_Switches.Last loop
5330 Add_Switch
5331 (Saved_Gcc_Switches.Table (J),
5332 Compiler,
5333 And_Save => False);
5334 end loop;
5335
5336 else
5337 -- And we put the command line gcc switches in the variable
5338 -- The_Saved_Gcc_Switches. They are going to be used later
5339 -- in procedure Compile_Sources.
5340
5341 The_Saved_Gcc_Switches :=
5342 new Argument_List (1 .. Saved_Gcc_Switches.Last + 1);
5343
5344 for J in 1 .. Saved_Gcc_Switches.Last loop
5345 The_Saved_Gcc_Switches (J) := Saved_Gcc_Switches.Table (J);
5346 end loop;
5347
5348 -- We never use gnat.adc when a project file is used
5349
5350 The_Saved_Gcc_Switches (The_Saved_Gcc_Switches'Last) :=
5351 No_gnat_adc;
5352
5353 end if;
5354
5355 -- If there was a --GCC, --GNATBIND or --GNATLINK switch on
5356 -- the command line, then we have to use it, even if there was
5357 -- another switch in the project file.
5358
5359 if Saved_Gcc /= null then
5360 Gcc := Saved_Gcc;
5361 end if;
5362
5363 if Saved_Gnatbind /= null then
5364 Gnatbind := Saved_Gnatbind;
5365 end if;
5366
5367 if Saved_Gnatlink /= null then
5368 Gnatlink := Saved_Gnatlink;
5369 end if;
5370
5371 Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
5372 Gnatbind_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
5373 Gnatlink_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
5374
5375 -- If we have specified -j switch both from the project file
5376 -- and on the command line, the one from the command line takes
5377 -- precedence.
5378
5379 if Saved_Maximum_Processes = 0 then
5380 Saved_Maximum_Processes := Maximum_Processes;
5381 end if;
5382
5383 -- Allocate as many temporary mapping file names as the maximum
5384 -- number of compilation processed, for each possible project.
5385
5386 The_Mapping_File_Names :=
5387 new Temp_Path_Names
5388 (No_Project .. Project_Table.Last (Project_Tree.Projects),
5389 1 .. Saved_Maximum_Processes);
5390 Last_Mapping_File_Names :=
5391 new Indices'
5392 (No_Project .. Project_Table.Last (Project_Tree.Projects)
5393 => 0);
5394
5395 The_Free_Mapping_File_Indices :=
5396 new Free_File_Indices
5397 (No_Project .. Project_Table.Last (Project_Tree.Projects),
5398 1 .. Saved_Maximum_Processes);
5399 Last_Free_Indices :=
5400 new Indices'(No_Project .. Project_Table.Last
5401 (Project_Tree.Projects) => 0);
5402
5403 Bad_Compilation.Init;
5404
5405 Current_Main_Index := Main_Index;
5406
5407 -- Here is where the make process is started
5408
5409 -- We do the same process for each main
5410
5411 Multiple_Main_Loop : for N_File in 1 .. Osint.Number_Of_Files loop
5412
5413 -- First, find the executable name and path
5414
5415 Executable := No_File;
5416 Executable_Obsolete := False;
5417 Non_Std_Executable :=
5418 Targparm.Executable_Extension_On_Target /= No_Name;
5419
5420 -- Look inside the linker switches to see if the name
5421 -- of the final executable program was specified.
5422
5423 for
5424 J in reverse Linker_Switches.First .. Linker_Switches.Last
5425 loop
5426 if Linker_Switches.Table (J).all = Output_Flag.all then
5427 pragma Assert (J < Linker_Switches.Last);
5428
5429 -- We cannot specify a single executable for several
5430 -- main subprograms!
5431
5432 if Osint.Number_Of_Files > 1 then
5433 Fail
5434 ("cannot specify a single executable " &
5435 "for several mains");
5436 end if;
5437
5438 Name_Len := Linker_Switches.Table (J + 1)'Length;
5439 Name_Buffer (1 .. Name_Len) :=
5440 Linker_Switches.Table (J + 1).all;
5441 Executable := Name_Enter;
5442
5443 Verbose_Msg (Executable, "final executable");
5444 end if;
5445 end loop;
5446
5447 -- If the name of the final executable program was not
5448 -- specified then construct it from the main input file.
5449
5450 if Executable = No_File then
5451 if Main_Project = No_Project then
5452 Executable :=
5453 Executable_Name (Strip_Suffix (Main_Source_File));
5454
5455 else
5456 -- If we are using a project file, we attempt to
5457 -- remove the body (or spec) termination of the main
5458 -- subprogram. We find it the the naming scheme of the
5459 -- project file. This will avoid to generate an
5460 -- executable "main.2" for a main subprogram
5461 -- "main.2.ada", when the body termination is ".2.ada".
5462
5463 Executable :=
5464 Prj.Util.Executable_Of
5465 (Main_Project, Project_Tree, Main_Source_File, Main_Index);
5466 end if;
5467 end if;
5468
5469 if Main_Project /= No_Project then
5470 declare
5471 Exec_File_Name : constant String :=
5472 Get_Name_String (Executable);
5473
5474 begin
5475 if not Is_Absolute_Path (Exec_File_Name) then
5476
5477 Get_Name_String (Project_Tree.Projects.Table
5478 (Main_Project).Display_Exec_Dir);
5479
5480 if
5481 Name_Buffer (Name_Len) /= Directory_Separator
5482 then
5483 Name_Len := Name_Len + 1;
5484 Name_Buffer (Name_Len) := Directory_Separator;
5485 end if;
5486
5487 Name_Buffer (Name_Len + 1 ..
5488 Name_Len + Exec_File_Name'Length) :=
5489 Exec_File_Name;
5490
5491 Name_Len := Name_Len + Exec_File_Name'Length;
5492 Executable := Name_Find;
5493 end if;
5494
5495 Non_Std_Executable := True;
5496 end;
5497 end if;
5498
5499 if Do_Compile_Step then
5500 Recursive_Compilation_Step : declare
5501 Args : Argument_List (1 .. Gcc_Switches.Last);
5502
5503 First_Compiled_File : File_Name_Type;
5504 Youngest_Obj_File : File_Name_Type;
5505 Youngest_Obj_Stamp : Time_Stamp_Type;
5506
5507 Executable_Stamp : Time_Stamp_Type;
5508 -- Executable is the final executable program
5509
5510 Library_Rebuilt : Boolean := False;
5511
5512 begin
5513 for J in 1 .. Gcc_Switches.Last loop
5514 Args (J) := Gcc_Switches.Table (J);
5515 end loop;
5516
5517 -- Now we invoke Compile_Sources for the current main
5518
5519 Compile_Sources
5520 (Main_Source => Main_Source_File,
5521 Args => Args,
5522 First_Compiled_File => First_Compiled_File,
5523 Most_Recent_Obj_File => Youngest_Obj_File,
5524 Most_Recent_Obj_Stamp => Youngest_Obj_Stamp,
5525 Main_Unit => Is_Main_Unit,
5526 Main_Index => Current_Main_Index,
5527 Compilation_Failures => Compilation_Failures,
5528 Check_Readonly_Files => Check_Readonly_Files,
5529 Do_Not_Execute => Do_Not_Execute,
5530 Force_Compilations => Force_Compilations,
5531 In_Place_Mode => In_Place_Mode,
5532 Keep_Going => Keep_Going,
5533 Initialize_ALI_Data => True,
5534 Max_Process => Saved_Maximum_Processes);
5535
5536 if Verbose_Mode then
5537 Write_Str ("End of compilation");
5538 Write_Eol;
5539 end if;
5540
5541 -- Make sure the queue will be reinitialized for the next round
5542
5543 First_Q_Initialization := True;
5544
5545 Total_Compilation_Failures :=
5546 Total_Compilation_Failures + Compilation_Failures;
5547
5548 if Total_Compilation_Failures /= 0 then
5549 if Keep_Going then
5550 goto Next_Main;
5551 else
5552 List_Bad_Compilations;
5553 Report_Compilation_Failed;
5554 end if;
5555 end if;
5556
5557 -- Regenerate libraries, if any, and if object files
5558 -- have been regenerated.
5559
5560 if Main_Project /= No_Project
5561 and then MLib.Tgt.Support_For_Libraries /= Prj.None
5562 and then (Do_Bind_Step
5563 or Unique_Compile_All_Projects
5564 or not Compile_Only)
5565 and then (Do_Link_Step or N_File = Osint.Number_Of_Files)
5566 then
5567 Library_Projs.Init;
5568
5569 declare
5570 Depth : Natural;
5571 Current : Natural;
5572
5573 procedure Add_To_Library_Projs (Proj : Project_Id);
5574 -- Add project Project to table Library_Projs
5575 -- in decreasing depth order.
5576
5577 --------------------------
5578 -- Add_To_Library_Projs --
5579 --------------------------
5580
5581 procedure Add_To_Library_Projs (Proj : Project_Id) is
5582 Prj : Project_Id;
5583
5584 begin
5585 Library_Projs.Increment_Last;
5586 Depth := Project_Tree.Projects.Table (Proj).Depth;
5587
5588 -- Put the projects in decreasing depth order,
5589 -- so that if libA depends on libB, libB is first
5590 -- in order.
5591
5592 Current := Library_Projs.Last;
5593 while Current > 1 loop
5594 Prj := Library_Projs.Table (Current - 1);
5595 exit when Project_Tree.Projects.Table
5596 (Prj).Depth >= Depth;
5597 Library_Projs.Table (Current) := Prj;
5598 Current := Current - 1;
5599 end loop;
5600
5601 Library_Projs.Table (Current) := Proj;
5602 end Add_To_Library_Projs;
5603
5604 -- Start of processing for ??? (should name declare block
5605 -- or probably better, break this out as a nested proc.
5606
5607 begin
5608 -- Put in Library_Projs table all library project
5609 -- file ids when the library need to be rebuilt.
5610
5611 for Proj1 in Project_Table.First ..
5612 Project_Table.Last (Project_Tree.Projects)
5613 loop
5614 if Project_Tree.Projects.Table
5615 (Proj1).Standalone_Library
5616 then
5617 There_Are_Stand_Alone_Libraries := True;
5618 end if;
5619
5620 if Project_Tree.Projects.Table (Proj1).Library then
5621 MLib.Prj.Check_Library (Proj1, Project_Tree);
5622 end if;
5623
5624 if Project_Tree.Projects.Table
5625 (Proj1).Need_To_Build_Lib
5626 then
5627 Add_To_Library_Projs (Proj1);
5628 end if;
5629 end loop;
5630
5631 -- Check if importing libraries should be regenerated
5632 -- because at least an imported library will be
5633 -- regenerated or is more recent.
5634
5635 for Proj1 in Project_Table.First ..
5636 Project_Table.Last (Project_Tree.Projects)
5637 loop
5638 if Project_Tree.Projects.Table (Proj1).Library
5639 and then
5640 Project_Tree.Projects.Table (Proj1).Library_Kind /=
5641 Static
5642 and then not Project_Tree.Projects.Table
5643 (Proj1).Need_To_Build_Lib
5644 and then not Project_Tree.Projects.Table
5645 (Proj1).Externally_Built
5646 then
5647 declare
5648 List : Project_List;
5649 Element : Project_Element;
5650 Proj2 : Project_Id;
5651 Rebuild : Boolean := False;
5652
5653 Lib_Timestamp1 : constant Time_Stamp_Type :=
5654 Project_Tree.Projects.Table
5655 (Proj1).Library_TS;
5656
5657 begin
5658 List := Project_Tree.Projects.Table (Proj1).
5659 All_Imported_Projects;
5660 while List /= Empty_Project_List loop
5661 Element :=
5662 Project_Tree.Project_Lists.Table (List);
5663 Proj2 := Element.Project;
5664
5665 if
5666 Project_Tree.Projects.Table (Proj2).Library
5667 then
5668 if Project_Tree.Projects.Table (Proj2).
5669 Need_To_Build_Lib
5670 or else
5671 (Lib_Timestamp1 <
5672 Project_Tree.Projects.Table
5673 (Proj2).Library_TS)
5674 then
5675 Rebuild := True;
5676 exit;
5677 end if;
5678 end if;
5679
5680 List := Element.Next;
5681 end loop;
5682
5683 if Rebuild then
5684 Project_Tree.Projects.Table
5685 (Proj1).Need_To_Build_Lib := True;
5686 Add_To_Library_Projs (Proj1);
5687 end if;
5688 end;
5689 end if;
5690 end loop;
5691
5692 -- Reset the flags Need_To_Build_Lib for the next main,
5693 -- to avoid rebuilding libraries uselessly.
5694
5695 for Proj1 in Project_Table.First ..
5696 Project_Table.Last (Project_Tree.Projects)
5697 loop
5698 Project_Tree.Projects.Table
5699 (Proj1).Need_To_Build_Lib := False;
5700 end loop;
5701 end;
5702
5703 -- Build the libraries, if any need to be built
5704
5705 for J in 1 .. Library_Projs.Last loop
5706 Library_Rebuilt := True;
5707
5708 -- If a library is rebuilt, then executables are obsolete
5709
5710 Executable_Obsolete := True;
5711
5712 MLib.Prj.Build_Library
5713 (For_Project => Library_Projs.Table (J),
5714 In_Tree => Project_Tree,
5715 Gnatbind => Gnatbind.all,
5716 Gnatbind_Path => Gnatbind_Path,
5717 Gcc => Gcc.all,
5718 Gcc_Path => Gcc_Path);
5719 end loop;
5720 end if;
5721
5722 if List_Dependencies then
5723 if First_Compiled_File /= No_File then
5724 Inform
5725 (First_Compiled_File,
5726 "must be recompiled. Can't generate dependence list.");
5727 else
5728 List_Depend;
5729 end if;
5730
5731 elsif First_Compiled_File = No_File
5732 and then not Do_Bind_Step
5733 and then not Quiet_Output
5734 and then not Library_Rebuilt
5735 and then Osint.Number_Of_Files = 1
5736 then
5737 Inform (Msg => "objects up to date.");
5738
5739 elsif Do_Not_Execute
5740 and then First_Compiled_File /= No_File
5741 then
5742 Write_Name (First_Compiled_File);
5743 Write_Eol;
5744 end if;
5745
5746 -- Stop after compile step if any of:
5747
5748 -- 1) -n (Do_Not_Execute) specified
5749
5750 -- 2) -M (List_Dependencies) specified (also sets
5751 -- Do_Not_Execute above, so this is probably superfluous).
5752
5753 -- 3) -c (Compile_Only) specified, but not -b (Bind_Only)
5754
5755 -- 4) Made unit cannot be a main unit
5756
5757 if ((Do_Not_Execute
5758 or List_Dependencies
5759 or not Do_Bind_Step
5760 or not Is_Main_Unit)
5761 and then not No_Main_Subprogram
5762 and then not Build_Bind_And_Link_Full_Project)
5763 or else Unique_Compile
5764 then
5765 if Osint.Number_Of_Files = 1 then
5766 exit Multiple_Main_Loop;
5767
5768 else
5769 goto Next_Main;
5770 end if;
5771 end if;
5772
5773 -- If the objects were up-to-date check if the executable file
5774 -- is also up-to-date. For now always bind and link on the JVM
5775 -- since there is currently no simple way to check the
5776 -- up-to-date status of objects
5777
5778 if Targparm.VM_Target = No_VM
5779 and then First_Compiled_File = No_File
5780 then
5781 Executable_Stamp := File_Stamp (Executable);
5782
5783 if not Executable_Obsolete then
5784 Executable_Obsolete :=
5785 Youngest_Obj_Stamp > Executable_Stamp;
5786 end if;
5787
5788 if not Executable_Obsolete then
5789 for Index in reverse 1 .. Dependencies.Last loop
5790 if Is_In_Obsoleted
5791 (Dependencies.Table (Index).Depends_On)
5792 then
5793 Enter_Into_Obsoleted
5794 (Dependencies.Table (Index).This);
5795 end if;
5796 end loop;
5797
5798 Executable_Obsolete := Is_In_Obsoleted (Main_Source_File);
5799 Dependencies.Init;
5800 end if;
5801
5802 if not Executable_Obsolete then
5803
5804 -- If no Ada object files obsolete the executable, check
5805 -- for younger or missing linker files.
5806
5807 Check_Linker_Options
5808 (Executable_Stamp,
5809 Youngest_Obj_File,
5810 Youngest_Obj_Stamp);
5811
5812 Executable_Obsolete := Youngest_Obj_File /= No_File;
5813 end if;
5814
5815 -- Return if the executable is up to date
5816 -- and otherwise motivate the relink/rebind.
5817
5818 if not Executable_Obsolete then
5819 if not Quiet_Output then
5820 Inform (Executable, "up to date.");
5821 end if;
5822
5823 if Osint.Number_Of_Files = 1 then
5824 exit Multiple_Main_Loop;
5825
5826 else
5827 goto Next_Main;
5828 end if;
5829 end if;
5830
5831 if Executable_Stamp (1) = ' ' then
5832 if not No_Main_Subprogram then
5833 Verbose_Msg (Executable, "missing.", Prefix => " ");
5834 end if;
5835
5836 elsif Youngest_Obj_Stamp (1) = ' ' then
5837 Verbose_Msg
5838 (Youngest_Obj_File, "missing.", Prefix => " ");
5839
5840 elsif Youngest_Obj_Stamp > Executable_Stamp then
5841 Verbose_Msg
5842 (Youngest_Obj_File,
5843 "(" & String (Youngest_Obj_Stamp) & ") newer than",
5844 Executable,
5845 "(" & String (Executable_Stamp) & ")");
5846
5847 else
5848 Verbose_Msg
5849 (Executable, "needs to be rebuilt", Prefix => " ");
5850
5851 end if;
5852 end if;
5853 end Recursive_Compilation_Step;
5854 end if;
5855
5856 -- For binding and linking, we need to be in the object directory of
5857 -- the main project.
5858
5859 if Main_Project /= No_Project then
5860 Change_To_Object_Directory (Main_Project);
5861 end if;
5862
5863 -- If we are here, it means that we need to rebuilt the current
5864 -- main. So we set Executable_Obsolete to True to make sure that
5865 -- the subsequent mains will be rebuilt.
5866
5867 Main_ALI_In_Place_Mode_Step : declare
5868 ALI_File : File_Name_Type;
5869 Src_File : File_Name_Type;
5870
5871 begin
5872 Src_File := Strip_Directory (Main_Source_File);
5873 ALI_File := Lib_File_Name (Src_File, Current_Main_Index);
5874 Main_ALI_File := Full_Lib_File_Name (ALI_File);
5875
5876 -- When In_Place_Mode, the library file can be located in the
5877 -- Main_Source_File directory which may not be present in the
5878 -- library path. In this case, use the corresponding library file
5879 -- name.
5880
5881 if Main_ALI_File = No_File and then In_Place_Mode then
5882 Get_Name_String (Get_Directory (Full_Source_Name (Src_File)));
5883 Get_Name_String_And_Append (ALI_File);
5884 Main_ALI_File := Name_Find;
5885 Main_ALI_File := Full_Lib_File_Name (Main_ALI_File);
5886 end if;
5887
5888 if Main_ALI_File = No_File then
5889 Make_Failed ("could not find the main ALI file");
5890 end if;
5891 end Main_ALI_In_Place_Mode_Step;
5892
5893 if Do_Bind_Step then
5894 Bind_Step : declare
5895 Args : Argument_List
5896 (Binder_Switches.First .. Binder_Switches.Last + 2);
5897 -- The arguments for the invocation of gnatbind
5898
5899 Last_Arg : Natural := Binder_Switches.Last;
5900 -- Index of the last argument in Args
5901
5902 Shared_Libs : Boolean := False;
5903 -- Set to True when there are shared library project files or
5904 -- when gnatbind is invoked with -shared.
5905
5906 begin
5907 -- Check if there are shared libraries, so that gnatbind is
5908 -- called with -shared. Check also if gnatbind is called with
5909 -- -shared, so that gnatlink is called with -shared-libgcc
5910 -- ensuring that the shared version of libgcc will be used.
5911
5912 if Main_Project /= No_Project
5913 and then MLib.Tgt.Support_For_Libraries /= Prj.None
5914 then
5915 for Proj in Project_Table.First ..
5916 Project_Table.Last (Project_Tree.Projects)
5917 loop
5918 if Project_Tree.Projects.Table (Proj).Library
5919 and then Project_Tree.Projects.Table
5920 (Proj).Library_Kind /= Static
5921 then
5922 Shared_Libs := True;
5923 Bind_Shared := Shared_Switch'Access;
5924 exit;
5925 end if;
5926 end loop;
5927 end if;
5928
5929 -- Check now for switch -shared
5930
5931 if not Shared_Libs then
5932 for J in Binder_Switches.First .. Last_Arg loop
5933 if Binder_Switches.Table (J).all = "-shared" then
5934 Shared_Libs := True;
5935 exit;
5936 end if;
5937 end loop;
5938 end if;
5939
5940 -- If there are shared libraries, invoke gnatlink with
5941 -- -shared-libgcc.
5942
5943 if Shared_Libs then
5944 Link_With_Shared_Libgcc := Shared_Libgcc_Switch'Access;
5945 end if;
5946
5947 -- Get all the binder switches
5948
5949 for J in Binder_Switches.First .. Last_Arg loop
5950 Args (J) := Binder_Switches.Table (J);
5951 end loop;
5952
5953 if There_Are_Stand_Alone_Libraries then
5954 Last_Arg := Last_Arg + 1;
5955 Args (Last_Arg) := Force_Elab_Flags_String'Access;
5956 end if;
5957
5958 if Main_Project /= No_Project then
5959
5960 -- Put all the source directories in ADA_INCLUDE_PATH,
5961 -- and all the object directories in ADA_OBJECTS_PATH
5962
5963 Prj.Env.Set_Ada_Paths (Main_Project, Project_Tree, False);
5964
5965 -- If switch -C was specified, create a binder mapping file
5966
5967 if Create_Mapping_File then
5968 Create_Binder_Mapping_File (Args, Last_Arg);
5969 end if;
5970
5971 end if;
5972
5973 begin
5974 Bind (Main_ALI_File,
5975 Bind_Shared.all & Args (Args'First .. Last_Arg));
5976
5977 exception
5978 when others =>
5979
5980 -- If -dn was not specified, delete the temporary mapping
5981 -- file, if one was created.
5982
5983 if not Debug.Debug_Flag_N
5984 and then Mapping_Path /= No_Path
5985 then
5986 Delete_File (Get_Name_String (Mapping_Path), Discard);
5987 end if;
5988
5989 -- And reraise the exception
5990
5991 raise;
5992 end;
5993
5994 -- If -dn was not specified, delete the temporary mapping file,
5995 -- if one was created.
5996
5997 if not Debug.Debug_Flag_N and then Mapping_Path /= No_Path then
5998 Delete_File (Get_Name_String (Mapping_Path), Discard);
5999 end if;
6000 end Bind_Step;
6001 end if;
6002
6003 if Do_Link_Step then
6004 Link_Step : declare
6005 Linker_Switches_Last : constant Integer := Linker_Switches.Last;
6006 Path_Option : constant String_Access :=
6007 MLib.Linker_Library_Path_Option;
6008 There_Are_Libraries : Boolean := False;
6009 Current : Natural;
6010 Proj2 : Project_Id;
6011 Depth : Natural;
6012
6013 begin
6014 if not Run_Path_Option then
6015 Linker_Switches.Increment_Last;
6016 Linker_Switches.Table (Linker_Switches.Last) :=
6017 new String'("-R");
6018 end if;
6019
6020 if Main_Project /= No_Project then
6021 Library_Paths.Set_Last (0);
6022 Library_Projs.Init;
6023
6024 if MLib.Tgt.Support_For_Libraries /= Prj.None then
6025 -- Check for library projects
6026
6027 for Proj1 in Project_Table.First ..
6028 Project_Table.Last (Project_Tree.Projects)
6029 loop
6030 if Proj1 /= Main_Project
6031 and then
6032 Project_Tree.Projects.Table (Proj1).Library
6033 then
6034 -- Add this project to table Library_Projs
6035
6036 There_Are_Libraries := True;
6037 Depth := Project_Tree.Projects.Table (Proj1).Depth;
6038 Library_Projs.Increment_Last;
6039 Current := Library_Projs.Last;
6040
6041 -- Any project with a greater depth should be
6042 -- after this project in the list.
6043
6044 while Current > 1 loop
6045 Proj2 := Library_Projs.Table (Current - 1);
6046 exit when Project_Tree.Projects.Table
6047 (Proj2).Depth <= Depth;
6048 Library_Projs.Table (Current) := Proj2;
6049 Current := Current - 1;
6050 end loop;
6051
6052 Library_Projs.Table (Current) := Proj1;
6053
6054 -- If it is not a static library and path option
6055 -- is set, add it to the Library_Paths table.
6056
6057 if Project_Tree.Projects.Table
6058 (Proj1).Library_Kind /= Static
6059 and then Path_Option /= null
6060 then
6061 Library_Paths.Increment_Last;
6062 Library_Paths.Table (Library_Paths.Last) :=
6063 new String'
6064 (Get_Name_String
6065 (Project_Tree.Projects.Table
6066 (Proj1).Display_Library_Dir));
6067 end if;
6068 end if;
6069 end loop;
6070
6071 for Index in 1 .. Library_Projs.Last loop
6072 -- Add the -L switch
6073
6074 Linker_Switches.Increment_Last;
6075 Linker_Switches.Table (Linker_Switches.Last) :=
6076 new String'("-L" &
6077 Get_Name_String
6078 (Project_Tree.Projects.Table
6079 (Library_Projs.Table (Index)).
6080 Display_Library_Dir));
6081
6082 -- Add the -l switch
6083
6084 Linker_Switches.Increment_Last;
6085 Linker_Switches.Table (Linker_Switches.Last) :=
6086 new String'("-l" &
6087 Get_Name_String
6088 (Project_Tree.Projects.Table
6089 (Library_Projs.Table (Index)).
6090 Library_Name));
6091 end loop;
6092 end if;
6093
6094 if There_Are_Libraries then
6095
6096 -- If Path_Option is not null, create the switch
6097 -- ("-Wl,-rpath," or equivalent) with all the non static
6098 -- library dirs plus the standard GNAT library dir.
6099 -- We do that only if Run_Path_Option is True
6100 -- (not disabled by -R switch).
6101
6102 if Run_Path_Option and Path_Option /= null then
6103 declare
6104 Option : String_Access;
6105 Length : Natural := Path_Option'Length;
6106 Current : Natural;
6107
6108 begin
6109 for Index in
6110 Library_Paths.First .. Library_Paths.Last
6111 loop
6112 -- Add the length of the library dir plus one
6113 -- for the directory separator.
6114
6115 Length :=
6116 Length +
6117 Library_Paths.Table (Index)'Length + 1;
6118 end loop;
6119
6120 -- Finally, add the length of the standard GNAT
6121 -- library dir.
6122
6123 Length := Length + MLib.Utl.Lib_Directory'Length;
6124 Option := new String (1 .. Length);
6125 Option (1 .. Path_Option'Length) := Path_Option.all;
6126 Current := Path_Option'Length;
6127
6128 -- Put each library dir followed by a dir separator
6129
6130 for Index in
6131 Library_Paths.First .. Library_Paths.Last
6132 loop
6133 Option
6134 (Current + 1 ..
6135 Current +
6136 Library_Paths.Table (Index)'Length) :=
6137 Library_Paths.Table (Index).all;
6138 Current :=
6139 Current +
6140 Library_Paths.Table (Index)'Length + 1;
6141 Option (Current) := Path_Separator;
6142 end loop;
6143
6144 -- Finally put the standard GNAT library dir
6145
6146 Option
6147 (Current + 1 ..
6148 Current + MLib.Utl.Lib_Directory'Length) :=
6149 MLib.Utl.Lib_Directory;
6150
6151 -- And add the switch to the linker switches
6152
6153 Linker_Switches.Increment_Last;
6154 Linker_Switches.Table (Linker_Switches.Last) :=
6155 Option;
6156 end;
6157 end if;
6158
6159 end if;
6160
6161 -- Put the object directories in ADA_OBJECTS_PATH
6162
6163 Prj.Env.Set_Ada_Paths (Main_Project, Project_Tree, False);
6164
6165 -- Check for attributes Linker'Linker_Options in projects
6166 -- other than the main project
6167
6168 declare
6169 Linker_Options : constant String_List :=
6170 Linker_Options_Switches
6171 (Main_Project, Project_Tree);
6172 begin
6173 for Option in Linker_Options'Range loop
6174 Linker_Switches.Increment_Last;
6175 Linker_Switches.Table (Linker_Switches.Last) :=
6176 Linker_Options (Option);
6177 end loop;
6178 end;
6179 end if;
6180
6181 declare
6182 Args : Argument_List
6183 (Linker_Switches.First .. Linker_Switches.Last + 2);
6184
6185 Last_Arg : Integer := Linker_Switches.First - 1;
6186 Skip : Boolean := False;
6187
6188 begin
6189 -- Get all the linker switches
6190
6191 for J in Linker_Switches.First .. Linker_Switches.Last loop
6192 if Skip then
6193 Skip := False;
6194
6195 elsif Non_Std_Executable
6196 and then Linker_Switches.Table (J).all = "-o"
6197 then
6198 Skip := True;
6199
6200 else
6201 Last_Arg := Last_Arg + 1;
6202 Args (Last_Arg) := Linker_Switches.Table (J);
6203 end if;
6204 end loop;
6205
6206 -- If need be, add the -o switch
6207
6208 if Non_Std_Executable then
6209 Last_Arg := Last_Arg + 1;
6210 Args (Last_Arg) := new String'("-o");
6211 Last_Arg := Last_Arg + 1;
6212 Args (Last_Arg) :=
6213 new String'(Get_Name_String (Executable));
6214 end if;
6215
6216 -- And invoke the linker
6217
6218 declare
6219 Success : Boolean := False;
6220 begin
6221 Link (Main_ALI_File,
6222 Link_With_Shared_Libgcc.all &
6223 Args (Args'First .. Last_Arg),
6224 Success);
6225
6226 if Success then
6227 Successful_Links.Increment_Last;
6228 Successful_Links.Table (Successful_Links.Last) :=
6229 Main_ALI_File;
6230
6231 elsif Osint.Number_Of_Files = 1 or not Keep_Going then
6232 Make_Failed ("*** link failed.");
6233
6234 else
6235 Set_Standard_Error;
6236 Write_Line ("*** link failed");
6237
6238 if Commands_To_Stdout then
6239 Set_Standard_Output;
6240 end if;
6241
6242 Failed_Links.Increment_Last;
6243 Failed_Links.Table (Failed_Links.Last) :=
6244 Main_ALI_File;
6245 end if;
6246 end;
6247 end;
6248
6249 Linker_Switches.Set_Last (Linker_Switches_Last);
6250 end Link_Step;
6251 end if;
6252
6253 -- We go to here when we skip the bind and link steps
6254
6255 <<Next_Main>>
6256
6257 -- We go to the next main, if we did not process the last one
6258
6259 if N_File < Osint.Number_Of_Files then
6260 Main_Source_File := Next_Main_Source;
6261
6262 if Current_File_Index /= No_Index then
6263 Main_Index := Current_File_Index;
6264 end if;
6265
6266 if Main_Project /= No_Project then
6267
6268 -- Find the file name of the main unit
6269
6270 declare
6271 Main_Source_File_Name : constant String :=
6272 Get_Name_String (Main_Source_File);
6273
6274 Main_Unit_File_Name : constant String :=
6275 Prj.Env.
6276 File_Name_Of_Library_Unit_Body
6277 (Name => Main_Source_File_Name,
6278 Project => Main_Project,
6279 In_Tree => Project_Tree,
6280 Main_Project_Only =>
6281 not Unique_Compile);
6282
6283 The_Packages : constant Package_Id :=
6284 Project_Tree.Projects.Table
6285 (Main_Project).Decl.Packages;
6286
6287 Binder_Package : constant Prj.Package_Id :=
6288 Prj.Util.Value_Of
6289 (Name => Name_Binder,
6290 In_Packages => The_Packages,
6291 In_Tree => Project_Tree);
6292
6293 Linker_Package : constant Prj.Package_Id :=
6294 Prj.Util.Value_Of
6295 (Name => Name_Linker,
6296 In_Packages => The_Packages,
6297 In_Tree => Project_Tree);
6298
6299 begin
6300 -- We fail if we cannot find the main source file
6301 -- as an immediate source of the main project file.
6302
6303 if Main_Unit_File_Name = "" then
6304 Make_Failed ('"' & Main_Source_File_Name,
6305 """ is not a unit of project ",
6306 Project_File_Name.all & ".");
6307
6308 else
6309 -- Remove any directory information from the main
6310 -- source file name.
6311
6312 declare
6313 Pos : Natural := Main_Unit_File_Name'Last;
6314
6315 begin
6316 loop
6317 exit when Pos < Main_Unit_File_Name'First
6318 or else
6319 Main_Unit_File_Name (Pos) = Directory_Separator;
6320 Pos := Pos - 1;
6321 end loop;
6322
6323 Name_Len := Main_Unit_File_Name'Last - Pos;
6324
6325 Name_Buffer (1 .. Name_Len) :=
6326 Main_Unit_File_Name
6327 (Pos + 1 .. Main_Unit_File_Name'Last);
6328
6329 Main_Source_File := Name_Find;
6330 end;
6331 end if;
6332
6333 -- We now deal with the binder and linker switches.
6334 -- If no project file is used, there is nothing to do
6335 -- because the binder and linker switches are the same
6336 -- for all mains.
6337
6338 -- Reset the tables Binder_Switches and Linker_Switches
6339
6340 Binder_Switches.Set_Last (Last_Binder_Switch);
6341 Linker_Switches.Set_Last (Last_Linker_Switch);
6342
6343 -- Add binder switches from the project file for this main,
6344 -- if any.
6345
6346 if Do_Bind_Step and Binder_Package /= No_Package then
6347 if Verbose_Mode then
6348 Write_Str ("Adding binder switches for """);
6349 Write_Str (Main_Unit_File_Name);
6350 Write_Line (""".");
6351 end if;
6352
6353 Add_Switches
6354 (File_Name => Main_Unit_File_Name,
6355 Index => Main_Index,
6356 The_Package => Binder_Package,
6357 Program => Binder);
6358 end if;
6359
6360 -- Add linker switches from the project file for this main,
6361 -- if any.
6362
6363 if Do_Link_Step and Linker_Package /= No_Package then
6364 if Verbose_Mode then
6365 Write_Str ("Adding linker switches for""");
6366 Write_Str (Main_Unit_File_Name);
6367 Write_Line (""".");
6368 end if;
6369
6370 Add_Switches
6371 (File_Name => Main_Unit_File_Name,
6372 Index => Main_Index,
6373 The_Package => Linker_Package,
6374 Program => Linker);
6375 end if;
6376
6377 -- As we are using a project file, for relative paths we add
6378 -- the current working directory for any relative path on
6379 -- the command line and the project directory, for any
6380 -- relative path in the project file.
6381
6382 declare
6383 Dir_Path : constant String_Access :=
6384 new String'(Get_Name_String
6385 (Project_Tree.Projects.Table
6386 (Main_Project).Directory));
6387 begin
6388 for
6389 J in Last_Binder_Switch + 1 .. Binder_Switches.Last
6390 loop
6391 Test_If_Relative_Path
6392 (Binder_Switches.Table (J),
6393 Parent => Dir_Path, Including_L_Switch => False);
6394 end loop;
6395
6396 for
6397 J in Last_Linker_Switch + 1 .. Linker_Switches.Last
6398 loop
6399 Test_If_Relative_Path
6400 (Linker_Switches.Table (J), Parent => Dir_Path);
6401 end loop;
6402 end;
6403
6404 -- We now put in the Binder_Switches and Linker_Switches
6405 -- tables, the binder and linker switches of the command
6406 -- line that have been put in the Saved_ tables.
6407 -- These switches will follow the project file switches.
6408
6409 for J in 1 .. Saved_Binder_Switches.Last loop
6410 Add_Switch
6411 (Saved_Binder_Switches.Table (J),
6412 Binder,
6413 And_Save => False);
6414 end loop;
6415
6416 for J in 1 .. Saved_Linker_Switches.Last loop
6417 Add_Switch
6418 (Saved_Linker_Switches.Table (J),
6419 Linker,
6420 And_Save => False);
6421 end loop;
6422 end;
6423 end if;
6424 end if;
6425
6426 -- Remove all marks to be sure to check sources for all executables,
6427 -- as the switches may be different and -s may be in use.
6428
6429 Delete_All_Marks;
6430 end loop Multiple_Main_Loop;
6431
6432 if Failed_Links.Last > 0 then
6433 for Index in 1 .. Successful_Links.Last loop
6434 Write_Str ("Linking of """);
6435 Write_Str (Get_Name_String (Successful_Links.Table (Index)));
6436 Write_Line (""" succeeded.");
6437 end loop;
6438
6439 Set_Standard_Error;
6440
6441 for Index in 1 .. Failed_Links.Last loop
6442 Write_Str ("Linking of """);
6443 Write_Str (Get_Name_String (Failed_Links.Table (Index)));
6444 Write_Line (""" failed.");
6445 end loop;
6446
6447 if Commands_To_Stdout then
6448 Set_Standard_Output;
6449 end if;
6450
6451 if Total_Compilation_Failures = 0 then
6452 Report_Compilation_Failed;
6453 end if;
6454 end if;
6455
6456 if Total_Compilation_Failures /= 0 then
6457 List_Bad_Compilations;
6458 Report_Compilation_Failed;
6459 end if;
6460
6461 -- Delete the temporary mapping file that was created if we are
6462 -- using project files.
6463
6464 if not Debug.Debug_Flag_N then
6465 Delete_Mapping_Files;
6466 Prj.Env.Delete_All_Path_Files (Project_Tree);
6467 end if;
6468
6469 exception
6470 when X : others =>
6471 Set_Standard_Error;
6472 Write_Line (Exception_Information (X));
6473 Make_Failed ("INTERNAL ERROR. Please report.");
6474 end Gnatmake;
6475
6476 ----------
6477 -- Hash --
6478 ----------
6479
6480 function Hash (F : File_Name_Type) return Header_Num is
6481 begin
6482 return Header_Num (1 + F mod Max_Header);
6483 end Hash;
6484
6485 --------------------
6486 -- In_Ada_Lib_Dir --
6487 --------------------
6488
6489 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean is
6490 D : constant File_Name_Type := Get_Directory (File);
6491 B : constant Byte := Get_Name_Table_Byte (D);
6492 begin
6493 return (B and Ada_Lib_Dir) /= 0;
6494 end In_Ada_Lib_Dir;
6495
6496 -----------------------
6497 -- Init_Mapping_File --
6498 -----------------------
6499
6500 procedure Init_Mapping_File
6501 (Project : Project_Id;
6502 File_Index : in out Natural)
6503 is
6504 FD : File_Descriptor;
6505 Status : Boolean;
6506 -- For call to Close
6507
6508 begin
6509 -- Increase the index of the last mapping file for this project
6510
6511 Last_Mapping_File_Names (Project) :=
6512 Last_Mapping_File_Names (Project) + 1;
6513
6514 -- If there is a project file, call Create_Mapping_File with
6515 -- the project id.
6516
6517 if Project /= No_Project then
6518 Prj.Env.Create_Mapping_File
6519 (Project, Project_Tree,
6520 The_Mapping_File_Names
6521 (Project, Last_Mapping_File_Names (Project)));
6522
6523 -- Otherwise, just create an empty file
6524
6525 else
6526 Tempdir.Create_Temp_File
6527 (FD,
6528 The_Mapping_File_Names
6529 (No_Project, Last_Mapping_File_Names (No_Project)));
6530
6531 if FD = Invalid_FD then
6532 Make_Failed ("disk full");
6533
6534 else
6535 Record_Temp_File
6536 (The_Mapping_File_Names
6537 (No_Project, Last_Mapping_File_Names (No_Project)));
6538 end if;
6539
6540 Close (FD, Status);
6541
6542 if not Status then
6543 Make_Failed ("disk full");
6544 end if;
6545 end if;
6546
6547 -- And return the index of the newly created file
6548
6549 File_Index := Last_Mapping_File_Names (Project);
6550 end Init_Mapping_File;
6551
6552 ------------
6553 -- Init_Q --
6554 ------------
6555
6556 procedure Init_Q is
6557 begin
6558 First_Q_Initialization := False;
6559 Q_Front := Q.First;
6560 Q.Set_Last (Q.First);
6561 end Init_Q;
6562
6563 ----------------
6564 -- Initialize --
6565 ----------------
6566
6567 procedure Initialize is
6568 begin
6569 Prj.Set_Mode (Ada_Only);
6570
6571 -- Override default initialization of Check_Object_Consistency
6572 -- since this is normally False for GNATBIND, but is True for
6573 -- GNATMAKE since we do not need to check source consistency
6574 -- again once GNATMAKE has looked at the sources to check.
6575
6576 Check_Object_Consistency := True;
6577
6578 -- Package initializations. The order of calls is important here
6579
6580 Output.Set_Standard_Error;
6581
6582 Gcc_Switches.Init;
6583 Binder_Switches.Init;
6584 Linker_Switches.Init;
6585
6586 Csets.Initialize;
6587 Namet.Initialize;
6588
6589 Snames.Initialize;
6590
6591 Prj.Initialize (Project_Tree);
6592
6593 Dependencies.Init;
6594
6595 RTS_Specified := null;
6596
6597 Mains.Delete;
6598
6599 -- Add the directory where gnatmake is invoked in front of the
6600 -- path, if gnatmake is invoked from a bin directory or with directory
6601 -- information. Only do this if the platform is not VMS, where the
6602 -- notion of path does not really exist.
6603
6604 if not OpenVMS then
6605 declare
6606 Prefix : constant String := Executable_Prefix_Path;
6607 Command : constant String := Command_Name;
6608
6609 begin
6610 if Prefix'Length > 0 then
6611 declare
6612 PATH : constant String :=
6613 Prefix & Directory_Separator & "bin" &
6614 Path_Separator &
6615 Getenv ("PATH").all;
6616 begin
6617 Setenv ("PATH", PATH);
6618 end;
6619
6620 else
6621 for Index in reverse Command'Range loop
6622 if Command (Index) = Directory_Separator then
6623 declare
6624 Absolute_Dir : constant String :=
6625 Normalize_Pathname
6626 (Command (Command'First .. Index));
6627 PATH : constant String :=
6628 Absolute_Dir &
6629 Path_Separator &
6630 Getenv ("PATH").all;
6631 begin
6632 Setenv ("PATH", PATH);
6633 end;
6634
6635 exit;
6636 end if;
6637 end loop;
6638 end if;
6639 end;
6640 end if;
6641
6642 -- Scan the switches and arguments
6643
6644 -- First, scan to detect --version and/or --help
6645
6646 Check_Version_And_Help ("GNATMAKE", "1995", Makeusg'Access);
6647
6648 -- Scan again the switch and arguments, now that we are sure that
6649 -- they do not include --version or --help.
6650
6651 Scan_Args : for Next_Arg in 1 .. Argument_Count loop
6652 Scan_Make_Arg (Argument (Next_Arg), And_Save => True);
6653 end loop Scan_Args;
6654
6655 if Commands_To_Stdout then
6656 Set_Standard_Output;
6657 end if;
6658
6659 if Usage_Requested then
6660 Usage;
6661 end if;
6662
6663 -- Test for trailing -P switch
6664
6665 if Project_File_Name_Present and then Project_File_Name = null then
6666 Make_Failed ("project file name missing after -P");
6667
6668 -- Test for trailing -o switch
6669
6670 elsif Output_File_Name_Present
6671 and then not Output_File_Name_Seen
6672 then
6673 Make_Failed ("output file name missing after -o");
6674
6675 -- Test for trailing -D switch
6676
6677 elsif Object_Directory_Present
6678 and then not Object_Directory_Seen then
6679 Make_Failed ("object directory missing after -D");
6680 end if;
6681
6682 -- Test for simultaneity of -i and -D
6683
6684 if Object_Directory_Path /= null and then In_Place_Mode then
6685 Make_Failed ("-i and -D cannot be used simutaneously");
6686 end if;
6687
6688 -- Deal with -C= switch
6689
6690 if Gnatmake_Mapping_File /= null then
6691 -- First, check compatibility with other switches
6692
6693 if Project_File_Name /= null then
6694 Make_Failed ("-C= switch is not compatible with -P switch");
6695
6696 elsif Saved_Maximum_Processes > 1 then
6697 Make_Failed ("-C= switch is not compatible with -jnnn switch");
6698 end if;
6699
6700 Fmap.Initialize (Gnatmake_Mapping_File.all);
6701 Add_Switch
6702 ("-gnatem=" & Gnatmake_Mapping_File.all,
6703 Compiler,
6704 And_Save => True);
6705 end if;
6706
6707 if Project_File_Name /= null then
6708
6709 -- A project file was specified by a -P switch
6710
6711 if Verbose_Mode then
6712 Write_Eol;
6713 Write_Str ("Parsing project file """);
6714 Write_Str (Project_File_Name.all);
6715 Write_Str (""".");
6716 Write_Eol;
6717 end if;
6718
6719 -- Avoid looking in the current directory for ALI files
6720
6721 -- Look_In_Primary_Dir := False;
6722
6723 -- Set the project parsing verbosity to whatever was specified
6724 -- by a possible -vP switch.
6725
6726 Prj.Pars.Set_Verbosity (To => Current_Verbosity);
6727
6728 -- Parse the project file.
6729 -- If there is an error, Main_Project will still be No_Project.
6730
6731 Prj.Pars.Parse
6732 (Project => Main_Project,
6733 In_Tree => Project_Tree,
6734 Project_File_Name => Project_File_Name.all,
6735 Packages_To_Check => Packages_To_Check_By_Gnatmake);
6736
6737 if Main_Project = No_Project then
6738 Make_Failed ("""", Project_File_Name.all, """ processing failed");
6739 end if;
6740
6741 Create_Mapping_File := True;
6742
6743 if Verbose_Mode then
6744 Write_Eol;
6745 Write_Str ("Parsing of project file """);
6746 Write_Str (Project_File_Name.all);
6747 Write_Str (""" is finished.");
6748 Write_Eol;
6749 end if;
6750
6751 -- We add the source directories and the object directories
6752 -- to the search paths.
6753
6754 Add_Source_Directories (Main_Project, Project_Tree);
6755 Add_Object_Directories (Main_Project, Project_Tree);
6756
6757 -- Compute depth of each project
6758
6759 for Proj in Project_Table.First ..
6760 Project_Table.Last (Project_Tree.Projects)
6761 loop
6762 Project_Tree.Projects.Table (Proj).Seen := False;
6763 Project_Tree.Projects.Table (Proj).Depth := 0;
6764 end loop;
6765
6766 Recursive_Compute_Depth (Main_Project, Depth => 1);
6767
6768 -- For each project compute the list of the projects it imports
6769 -- directly or indirectly.
6770
6771 for Proj in Project_Table.First ..
6772 Project_Table.Last (Project_Tree.Projects)
6773 loop
6774 Compute_All_Imported_Projects (Proj);
6775 end loop;
6776
6777 else
6778
6779 Osint.Add_Default_Search_Dirs;
6780
6781 -- Source file lookups should be cached for efficiency. Source files
6782 -- are not supposed to change. However, we do that now only if no
6783 -- project file is used; if a project file is used, we do it just
6784 -- after changing the directory to the object directory.
6785
6786 Osint.Source_File_Data (Cache => True);
6787
6788 -- Read gnat.adc file to initialize Fname.UF
6789
6790 Fname.UF.Initialize;
6791
6792 begin
6793 Fname.SF.Read_Source_File_Name_Pragmas;
6794
6795 exception
6796 when Err : SFN_Scan.Syntax_Error_In_GNAT_ADC =>
6797 Make_Failed (Exception_Message (Err));
6798 end;
6799 end if;
6800
6801 -- Make sure no project object directory is recorded
6802
6803 Project_Of_Current_Object_Directory := No_Project;
6804
6805 end Initialize;
6806
6807 ----------------------------
6808 -- Insert_Project_Sources --
6809 ----------------------------
6810
6811 procedure Insert_Project_Sources
6812 (The_Project : Project_Id;
6813 All_Projects : Boolean;
6814 Into_Q : Boolean)
6815 is
6816 Put_In_Q : Boolean := Into_Q;
6817 Unit : Unit_Data;
6818 Sfile : File_Name_Type;
6819
6820 Extending : constant Boolean :=
6821 Project_Tree.Projects.Table
6822 (The_Project).Extends /= No_Project;
6823
6824 function Check_Project (P : Project_Id) return Boolean;
6825 -- Returns True if P is The_Project or a project extended by The_Project
6826
6827 -------------------
6828 -- Check_Project --
6829 -------------------
6830
6831 function Check_Project (P : Project_Id) return Boolean is
6832 begin
6833 if All_Projects or P = The_Project then
6834 return True;
6835
6836 elsif Extending then
6837 declare
6838 Data : Project_Data :=
6839 Project_Tree.Projects.Table (The_Project);
6840
6841 begin
6842 loop
6843 if P = Data.Extends then
6844 return True;
6845 end if;
6846
6847 Data := Project_Tree.Projects.Table (Data.Extends);
6848 exit when Data.Extends = No_Project;
6849 end loop;
6850 end;
6851 end if;
6852
6853 return False;
6854 end Check_Project;
6855
6856 -- Start of processing for Insert_Project_Sources
6857
6858 begin
6859 -- For all the sources in the project files,
6860
6861 for Id in Unit_Table.First ..
6862 Unit_Table.Last (Project_Tree.Units)
6863 loop
6864 Unit := Project_Tree.Units.Table (Id);
6865 Sfile := No_File;
6866
6867 -- If there is a source for the body, and the body has not been
6868 -- locally removed,
6869
6870 if Unit.File_Names (Body_Part).Name /= No_File
6871 and then Unit.File_Names (Body_Part).Path /= Slash
6872 then
6873 -- And it is a source for the specified project
6874
6875 if Check_Project (Unit.File_Names (Body_Part).Project) then
6876
6877 -- If we don't have a spec, we cannot consider the source
6878 -- if it is a subunit
6879
6880 if Unit.File_Names (Specification).Name = No_File then
6881 declare
6882 Src_Ind : Source_File_Index;
6883
6884 -- Here we are cheating a little bit: we don't want to
6885 -- use Sinput.L, because it depends on the GNAT tree
6886 -- (Atree, Sinfo, ...). So, we pretend that it is a
6887 -- project file, and we use Sinput.P.
6888
6889 -- Source_File_Is_Subunit is just scanning through the
6890 -- file until it finds one of the reserved words
6891 -- separate, procedure, function, generic or package.
6892 -- Fortunately, these Ada reserved words are also
6893 -- reserved for project files.
6894
6895 begin
6896 Src_Ind := Sinput.P.Load_Project_File
6897 (Get_Name_String
6898 (Unit.File_Names (Body_Part).Path));
6899
6900 -- If it is a subunit, discard it
6901
6902 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
6903 Sfile := No_File;
6904 else
6905 Sfile := Unit.File_Names (Body_Part).Display_Name;
6906 end if;
6907 end;
6908
6909 else
6910 Sfile := Unit.File_Names (Body_Part).Display_Name;
6911 end if;
6912 end if;
6913
6914 elsif Unit.File_Names (Specification).Name /= No_File
6915 and then Unit.File_Names (Specification).Path /= Slash
6916 and then Check_Project (Unit.File_Names (Specification).Project)
6917 then
6918 -- If there is no source for the body, but there is a source
6919 -- for the spec which has not been locally removed, then we take
6920 -- this one.
6921
6922 Sfile := Unit.File_Names (Specification).Display_Name;
6923 end if;
6924
6925 -- If Put_In_Q is True, we insert into the Q
6926
6927 if Put_In_Q then
6928
6929 -- For the first source inserted into the Q, we need to initialize
6930 -- the Q, but not for the subsequent sources.
6931
6932 if First_Q_Initialization then
6933 Init_Q;
6934 end if;
6935
6936 -- And of course, we only insert in the Q if the source is not
6937 -- marked.
6938
6939 if Sfile /= No_File and then not Is_Marked (Sfile) then
6940 if Verbose_Mode then
6941 Write_Str ("Adding """);
6942 Write_Str (Get_Name_String (Sfile));
6943 Write_Line (""" to the queue");
6944 end if;
6945
6946 Insert_Q (Sfile);
6947 Mark (Sfile);
6948 end if;
6949
6950 elsif Sfile /= No_File then
6951
6952 -- If Put_In_Q is False, we add the source as it it were specified
6953 -- on the command line, and we set Put_In_Q to True, so that the
6954 -- following sources will be put directly in the queue. This will
6955 -- allow parallel compilation processes if -jx switch is used.
6956
6957 if Verbose_Mode then
6958 Write_Str ("Adding """);
6959 Write_Str (Get_Name_String (Sfile));
6960 Write_Line (""" as if on the command line");
6961 end if;
6962
6963 Osint.Add_File (Get_Name_String (Sfile));
6964 Put_In_Q := True;
6965
6966 -- As we may look into the Q later, ensure the Q has been
6967 -- initialized to avoid errors.
6968
6969 if First_Q_Initialization then
6970 Init_Q;
6971 end if;
6972 end if;
6973 end loop;
6974 end Insert_Project_Sources;
6975
6976 --------------
6977 -- Insert_Q --
6978 --------------
6979
6980 procedure Insert_Q
6981 (Source_File : File_Name_Type;
6982 Source_Unit : Unit_Name_Type := No_Unit_Name;
6983 Index : Int := 0)
6984 is
6985 begin
6986 if Debug.Debug_Flag_Q then
6987 Write_Str (" Q := Q + [ ");
6988 Write_Name (Source_File);
6989
6990 if Index /= 0 then
6991 Write_Str (", ");
6992 Write_Int (Index);
6993 end if;
6994
6995 Write_Str (" ] ");
6996 Write_Eol;
6997 end if;
6998
6999 Q.Table (Q.Last) :=
7000 (File => Source_File,
7001 Unit => Source_Unit,
7002 Index => Index);
7003 Q.Increment_Last;
7004 end Insert_Q;
7005
7006 ---------------------
7007 -- Is_In_Obsoleted --
7008 ---------------------
7009
7010 function Is_In_Obsoleted (F : File_Name_Type) return Boolean is
7011 begin
7012 if F = No_File then
7013 return False;
7014
7015 else
7016 declare
7017 Name : constant String := Get_Name_String (F);
7018 First : Natural;
7019 F2 : File_Name_Type;
7020
7021 begin
7022 First := Name'Last;
7023 while First > Name'First
7024 and then Name (First - 1) /= Directory_Separator
7025 and then Name (First - 1) /= '/'
7026 loop
7027 First := First - 1;
7028 end loop;
7029
7030 if First /= Name'First then
7031 Name_Len := 0;
7032 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
7033 F2 := Name_Find;
7034
7035 else
7036 F2 := F;
7037 end if;
7038
7039 return Obsoleted.Get (F2);
7040 end;
7041 end if;
7042 end Is_In_Obsoleted;
7043
7044 ----------------------------
7045 -- Is_In_Object_Directory --
7046 ----------------------------
7047
7048 function Is_In_Object_Directory
7049 (Source_File : File_Name_Type;
7050 Full_Lib_File : File_Name_Type) return Boolean
7051 is
7052 begin
7053 -- There is something to check only when using project files.
7054 -- Otherwise, this function returns True (last line of the function).
7055
7056 if Main_Project /= No_Project then
7057 declare
7058 Source_File_Name : constant String :=
7059 Get_Name_String (Source_File);
7060 Saved_Verbosity : constant Verbosity := Current_Verbosity;
7061 Project : Project_Id := No_Project;
7062 Path_Name : Path_Name_Type := No_Path;
7063 Data : Project_Data;
7064
7065 begin
7066 -- Call Get_Reference to know the ultimate extending project of
7067 -- the source. Call it with verbosity default to avoid verbose
7068 -- messages.
7069
7070 Current_Verbosity := Default;
7071 Prj.Env.Get_Reference
7072 (Source_File_Name => Source_File_Name,
7073 Project => Project,
7074 In_Tree => Project_Tree,
7075 Path => Path_Name);
7076 Current_Verbosity := Saved_Verbosity;
7077
7078 -- If this source is in a project, check that the ALI file is
7079 -- in its object directory. If it is not, return False, so that
7080 -- the ALI file will not be skipped.
7081
7082 if Project /= No_Project then
7083 Data := Project_Tree.Projects.Table (Project);
7084
7085 declare
7086 Object_Directory : constant String :=
7087 Normalize_Pathname
7088 (Get_Name_String
7089 (Data.Display_Object_Dir));
7090
7091 Olast : Natural := Object_Directory'Last;
7092
7093 Lib_File_Directory : constant String :=
7094 Normalize_Pathname (Dir_Name
7095 (Get_Name_String (Full_Lib_File)));
7096
7097 Llast : Natural := Lib_File_Directory'Last;
7098
7099 begin
7100 -- For directories, Normalize_Pathname may or may not put
7101 -- a directory separator at the end, depending on its input.
7102 -- Remove any last directory separator before comparaison.
7103 -- Returns True only if the two directories are the same.
7104
7105 if Object_Directory (Olast) = Directory_Separator then
7106 Olast := Olast - 1;
7107 end if;
7108
7109 if Lib_File_Directory (Llast) = Directory_Separator then
7110 Llast := Llast - 1;
7111 end if;
7112
7113 return Object_Directory (Object_Directory'First .. Olast) =
7114 Lib_File_Directory (Lib_File_Directory'First .. Llast);
7115 end;
7116 end if;
7117 end;
7118 end if;
7119
7120 -- When the source is not in a project file, always return True
7121
7122 return True;
7123 end Is_In_Object_Directory;
7124
7125 ----------
7126 -- Link --
7127 ----------
7128
7129 procedure Link
7130 (ALI_File : File_Name_Type;
7131 Args : Argument_List;
7132 Success : out Boolean)
7133 is
7134 Link_Args : Argument_List (1 .. Args'Length + 1);
7135
7136 begin
7137 Get_Name_String (ALI_File);
7138 Link_Args (1) := new String'(Name_Buffer (1 .. Name_Len));
7139
7140 Link_Args (2 .. Args'Length + 1) := Args;
7141
7142 GNAT.OS_Lib.Normalize_Arguments (Link_Args);
7143
7144 Display (Gnatlink.all, Link_Args);
7145
7146 if Gnatlink_Path = null then
7147 Make_Failed ("error, unable to locate ", Gnatlink.all);
7148 end if;
7149
7150 GNAT.OS_Lib.Spawn (Gnatlink_Path.all, Link_Args, Success);
7151 end Link;
7152
7153 ---------------------------
7154 -- List_Bad_Compilations --
7155 ---------------------------
7156
7157 procedure List_Bad_Compilations is
7158 begin
7159 for J in Bad_Compilation.First .. Bad_Compilation.Last loop
7160 if Bad_Compilation.Table (J).File = No_File then
7161 null;
7162 elsif not Bad_Compilation.Table (J).Found then
7163 Inform (Bad_Compilation.Table (J).File, "not found");
7164 else
7165 Inform (Bad_Compilation.Table (J).File, "compilation error");
7166 end if;
7167 end loop;
7168 end List_Bad_Compilations;
7169
7170 -----------------
7171 -- List_Depend --
7172 -----------------
7173
7174 procedure List_Depend is
7175 Lib_Name : File_Name_Type;
7176 Obj_Name : File_Name_Type;
7177 Src_Name : File_Name_Type;
7178
7179 Len : Natural;
7180 Line_Pos : Natural;
7181 Line_Size : constant := 77;
7182
7183 begin
7184 Set_Standard_Output;
7185
7186 for A in ALIs.First .. ALIs.Last loop
7187 Lib_Name := ALIs.Table (A).Afile;
7188
7189 -- We have to provide the full library file name in In_Place_Mode
7190
7191 if In_Place_Mode then
7192 Lib_Name := Full_Lib_File_Name (Lib_Name);
7193 end if;
7194
7195 Obj_Name := Object_File_Name (Lib_Name);
7196 Write_Name (Obj_Name);
7197 Write_Str (" :");
7198
7199 Get_Name_String (Obj_Name);
7200 Len := Name_Len;
7201 Line_Pos := Len + 2;
7202
7203 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
7204 Src_Name := Sdep.Table (D).Sfile;
7205
7206 if Is_Internal_File_Name (Src_Name)
7207 and then not Check_Readonly_Files
7208 then
7209 null;
7210 else
7211 if not Quiet_Output then
7212 Src_Name := Full_Source_Name (Src_Name);
7213 end if;
7214
7215 Get_Name_String (Src_Name);
7216 Len := Name_Len;
7217
7218 if Line_Pos + Len + 1 > Line_Size then
7219 Write_Str (" \");
7220 Write_Eol;
7221 Line_Pos := 0;
7222 end if;
7223
7224 Line_Pos := Line_Pos + Len + 1;
7225
7226 Write_Str (" ");
7227 Write_Name (Src_Name);
7228 end if;
7229 end loop;
7230
7231 Write_Eol;
7232 end loop;
7233
7234 if not Commands_To_Stdout then
7235 Set_Standard_Error;
7236 end if;
7237 end List_Depend;
7238
7239 -----------------
7240 -- Make_Failed --
7241 -----------------
7242
7243 procedure Make_Failed (S1 : String; S2 : String := ""; S3 : String := "") is
7244 begin
7245 Delete_All_Temp_Files;
7246 Osint.Fail (S1, S2, S3);
7247 end Make_Failed;
7248
7249 --------------------
7250 -- Mark_Directory --
7251 --------------------
7252
7253 procedure Mark_Directory
7254 (Dir : String;
7255 Mark : Lib_Mark_Type;
7256 On_Command_Line : Boolean)
7257 is
7258 N : Name_Id;
7259 B : Byte;
7260
7261 begin
7262 if On_Command_Line then
7263 declare
7264 Real_Path : constant String := Normalize_Pathname (Dir);
7265
7266 begin
7267 if Real_Path'Length = 0 then
7268 Name_Len := Dir'Length;
7269 Name_Buffer (1 .. Name_Len) := Dir;
7270
7271 else
7272 Name_Len := Real_Path'Length;
7273 Name_Buffer (1 .. Name_Len) := Real_Path;
7274 end if;
7275 end;
7276
7277 else
7278 declare
7279 Real_Path : constant String :=
7280 Normalize_Pathname
7281 (Dir,
7282 Get_Name_String
7283 (Project_Tree.Projects.Table
7284 (Main_Project).Display_Directory));
7285
7286 begin
7287 if Real_Path'Length = 0 then
7288 Name_Len := Dir'Length;
7289 Name_Buffer (1 .. Name_Len) := Dir;
7290
7291 else
7292 Name_Len := Real_Path'Length;
7293 Name_Buffer (1 .. Name_Len) := Real_Path;
7294 end if;
7295 end;
7296 end if;
7297
7298 -- Last character is supposed to be a directory separator
7299
7300 if not Is_Directory_Separator (Name_Buffer (Name_Len)) then
7301 Name_Len := Name_Len + 1;
7302 Name_Buffer (Name_Len) := Directory_Separator;
7303 end if;
7304
7305 -- Add flags to the already existing flags
7306
7307 N := Name_Find;
7308 B := Get_Name_Table_Byte (N);
7309 Set_Name_Table_Byte (N, B or Mark);
7310 end Mark_Directory;
7311
7312 -----------------------------
7313 -- Recursive_Compute_Depth --
7314 -----------------------------
7315
7316 procedure Recursive_Compute_Depth
7317 (Project : Project_Id;
7318 Depth : Natural)
7319 is
7320 List : Project_List;
7321 Proj : Project_Id;
7322
7323 begin
7324 -- Nothing to do if there is no project or if the project has already
7325 -- been seen or if the depth is large enough.
7326
7327 if Project = No_Project
7328 or else Project_Tree.Projects.Table (Project).Seen
7329 or else Project_Tree.Projects.Table (Project).Depth >= Depth
7330 then
7331 return;
7332 end if;
7333
7334 Project_Tree.Projects.Table (Project).Depth := Depth;
7335
7336 -- Mark project as Seen to avoid endless loop caused by limited withs
7337
7338 Project_Tree.Projects.Table (Project).Seen := True;
7339
7340 List := Project_Tree.Projects.Table (Project).Imported_Projects;
7341
7342 -- Visit each imported project
7343
7344 while List /= Empty_Project_List loop
7345 Proj := Project_Tree.Project_Lists.Table (List).Project;
7346 List := Project_Tree.Project_Lists.Table (List).Next;
7347 Recursive_Compute_Depth
7348 (Project => Proj,
7349 Depth => Depth + 1);
7350 end loop;
7351
7352 -- Visit a project being extended, if any
7353
7354 Recursive_Compute_Depth
7355 (Project => Project_Tree.Projects.Table (Project).Extends,
7356 Depth => Depth + 1);
7357
7358 -- Reset the Seen flag, as we leave this project
7359
7360 Project_Tree.Projects.Table (Project).Seen := False;
7361 end Recursive_Compute_Depth;
7362
7363 -------------------------------
7364 -- Report_Compilation_Failed --
7365 -------------------------------
7366
7367 procedure Report_Compilation_Failed is
7368 begin
7369 if not Debug.Debug_Flag_N then
7370 Delete_Mapping_Files;
7371 Prj.Env.Delete_All_Path_Files (Project_Tree);
7372 end if;
7373
7374 Exit_Program (E_Fatal);
7375 end Report_Compilation_Failed;
7376
7377 ------------------------
7378 -- Sigint_Intercepted --
7379 ------------------------
7380
7381 procedure Sigint_Intercepted is
7382 begin
7383 Set_Standard_Error;
7384 Write_Line ("*** Interrupted ***");
7385 Delete_All_Temp_Files;
7386 OS_Exit (1);
7387 end Sigint_Intercepted;
7388
7389 -------------------
7390 -- Scan_Make_Arg --
7391 -------------------
7392
7393 procedure Scan_Make_Arg (Argv : String; And_Save : Boolean) is
7394 Success : Boolean;
7395
7396 begin
7397 pragma Assert (Argv'First = 1);
7398
7399 if Argv'Length = 0 then
7400 return;
7401 end if;
7402
7403 -- If the previous switch has set the Project_File_Name_Present flag
7404 -- (that is we have seen a -P alone), then the next argument is the name
7405 -- of the project file.
7406
7407 if Project_File_Name_Present and then Project_File_Name = null then
7408 if Argv (1) = '-' then
7409 Make_Failed ("project file name missing after -P");
7410
7411 else
7412 Project_File_Name_Present := False;
7413 Project_File_Name := new String'(Argv);
7414 end if;
7415
7416 -- If the previous switch has set the Output_File_Name_Present flag
7417 -- (that is we have seen a -o), then the next argument is the name of
7418 -- the output executable.
7419
7420 elsif Output_File_Name_Present
7421 and then not Output_File_Name_Seen
7422 then
7423 Output_File_Name_Seen := True;
7424
7425 if Argv (1) = '-' then
7426 Make_Failed ("output file name missing after -o");
7427
7428 else
7429 Add_Switch ("-o", Linker, And_Save => And_Save);
7430 Add_Switch (Executable_Name (Argv), Linker, And_Save => And_Save);
7431 end if;
7432
7433 -- If the previous switch has set the Object_Directory_Present flag
7434 -- (that is we have seen a -D), then the next argument is the path name
7435 -- of the object directory..
7436
7437 elsif Object_Directory_Present
7438 and then not Object_Directory_Seen
7439 then
7440 Object_Directory_Seen := True;
7441
7442 if Argv (1) = '-' then
7443 Make_Failed ("object directory path name missing after -D");
7444
7445 elsif not Is_Directory (Argv) then
7446 Make_Failed ("cannot find object directory """, Argv, """");
7447
7448 else
7449 Add_Lib_Search_Dir (Argv);
7450
7451 -- Specify the object directory to the binder
7452
7453 Add_Switch ("-aO" & Argv, Binder, And_Save => And_Save);
7454
7455 -- Record the object directory. Make sure it ends with a directory
7456 -- separator.
7457
7458 if Argv (Argv'Last) = Directory_Separator then
7459 Object_Directory_Path :=
7460 new String'(Argv);
7461 else
7462 Object_Directory_Path :=
7463 new String'(Argv & Directory_Separator);
7464 end if;
7465 end if;
7466
7467 -- Then check if we are dealing with -cargs/-bargs/-largs/-margs
7468
7469 elsif Argv = "-bargs"
7470 or else
7471 Argv = "-cargs"
7472 or else
7473 Argv = "-largs"
7474 or else
7475 Argv = "-margs"
7476 then
7477 case Argv (2) is
7478 when 'c' => Program_Args := Compiler;
7479 when 'b' => Program_Args := Binder;
7480 when 'l' => Program_Args := Linker;
7481 when 'm' => Program_Args := None;
7482
7483 when others =>
7484 raise Program_Error;
7485 end case;
7486
7487 -- A special test is needed for the -o switch within a -largs
7488 -- since that is another way to specify the name of the final
7489 -- executable.
7490
7491 elsif Program_Args = Linker
7492 and then Argv = "-o"
7493 then
7494 Make_Failed ("switch -o not allowed within a -largs. " &
7495 "Use -o directly.");
7496
7497 -- Check to see if we are reading switches after a -cargs,
7498 -- -bargs or -largs switch. If yes save it.
7499
7500 elsif Program_Args /= None then
7501
7502 -- Check to see if we are reading -I switches in order
7503 -- to take into account in the src & lib search directories.
7504
7505 if Argv'Length > 2 and then Argv (1 .. 2) = "-I" then
7506 if Argv (3 .. Argv'Last) = "-" then
7507 Look_In_Primary_Dir := False;
7508
7509 elsif Program_Args = Compiler then
7510 if Argv (3 .. Argv'Last) /= "-" then
7511 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7512 end if;
7513
7514 elsif Program_Args = Binder then
7515 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7516 end if;
7517 end if;
7518
7519 Add_Switch (Argv, Program_Args, And_Save => And_Save);
7520
7521 -- Handle non-default compiler, binder, linker, and handle --RTS switch
7522
7523 elsif Argv'Length > 2 and then Argv (1 .. 2) = "--" then
7524 if Argv'Length > 6
7525 and then Argv (1 .. 6) = "--GCC="
7526 then
7527 declare
7528 Program_Args : constant Argument_List_Access :=
7529 Argument_String_To_List
7530 (Argv (7 .. Argv'Last));
7531
7532 begin
7533 if And_Save then
7534 Saved_Gcc := new String'(Program_Args.all (1).all);
7535 else
7536 Gcc := new String'(Program_Args.all (1).all);
7537 end if;
7538
7539 for J in 2 .. Program_Args.all'Last loop
7540 Add_Switch
7541 (Program_Args.all (J).all,
7542 Compiler,
7543 And_Save => And_Save);
7544 end loop;
7545 end;
7546
7547 elsif Argv'Length > 11
7548 and then Argv (1 .. 11) = "--GNATBIND="
7549 then
7550 declare
7551 Program_Args : constant Argument_List_Access :=
7552 Argument_String_To_List
7553 (Argv (12 .. Argv'Last));
7554
7555 begin
7556 if And_Save then
7557 Saved_Gnatbind := new String'(Program_Args.all (1).all);
7558 else
7559 Gnatbind := new String'(Program_Args.all (1).all);
7560 end if;
7561
7562 for J in 2 .. Program_Args.all'Last loop
7563 Add_Switch
7564 (Program_Args.all (J).all, Binder, And_Save => And_Save);
7565 end loop;
7566 end;
7567
7568 elsif Argv'Length > 11
7569 and then Argv (1 .. 11) = "--GNATLINK="
7570 then
7571 declare
7572 Program_Args : constant Argument_List_Access :=
7573 Argument_String_To_List
7574 (Argv (12 .. Argv'Last));
7575 begin
7576 if And_Save then
7577 Saved_Gnatlink := new String'(Program_Args.all (1).all);
7578 else
7579 Gnatlink := new String'(Program_Args.all (1).all);
7580 end if;
7581
7582 for J in 2 .. Program_Args.all'Last loop
7583 Add_Switch (Program_Args.all (J).all, Linker);
7584 end loop;
7585 end;
7586
7587 elsif Argv'Length >= 5 and then
7588 Argv (1 .. 5) = "--RTS"
7589 then
7590 Add_Switch (Argv, Compiler, And_Save => And_Save);
7591 Add_Switch (Argv, Binder, And_Save => And_Save);
7592
7593 if Argv'Length <= 6 or else Argv (6) /= '=' then
7594 Make_Failed ("missing path for --RTS");
7595
7596 else
7597 -- Check that this is the first time we see this switch or
7598 -- if it is not the first time, the same path is specified.
7599
7600 if RTS_Specified = null then
7601 RTS_Specified := new String'(Argv (7 .. Argv'Last));
7602
7603 elsif RTS_Specified.all /= Argv (7 .. Argv'Last) then
7604 Make_Failed ("--RTS cannot be specified multiple times");
7605 end if;
7606
7607 -- Valid --RTS switch
7608
7609 No_Stdinc := True;
7610 No_Stdlib := True;
7611 RTS_Switch := True;
7612
7613 declare
7614 Src_Path_Name : constant String_Ptr :=
7615 Get_RTS_Search_Dir
7616 (Argv (7 .. Argv'Last), Include);
7617
7618 Lib_Path_Name : constant String_Ptr :=
7619 Get_RTS_Search_Dir
7620 (Argv (7 .. Argv'Last), Objects);
7621
7622 begin
7623 if Src_Path_Name /= null
7624 and then Lib_Path_Name /= null
7625 then
7626 -- Set RTS_*_Path_Name variables, so that correct direct-
7627 -- ories will be set when Osint.Add_Default_Search_Dirs
7628 -- is called later.
7629
7630 RTS_Src_Path_Name := Src_Path_Name;
7631 RTS_Lib_Path_Name := Lib_Path_Name;
7632
7633 elsif Src_Path_Name = null
7634 and Lib_Path_Name = null
7635 then
7636 Make_Failed ("RTS path not valid: missing " &
7637 "adainclude and adalib directories");
7638
7639 elsif Src_Path_Name = null then
7640 Make_Failed ("RTS path not valid: missing adainclude " &
7641 "directory");
7642
7643 elsif Lib_Path_Name = null then
7644 Make_Failed ("RTS path not valid: missing adalib " &
7645 "directory");
7646 end if;
7647 end;
7648 end if;
7649
7650 else
7651 Scan_Make_Switches (Argv, Success);
7652 end if;
7653
7654 -- If we have seen a regular switch process it
7655
7656 elsif Argv (1) = '-' then
7657
7658 if Argv'Length = 1 then
7659 Make_Failed ("switch character cannot be followed by a blank");
7660
7661 -- Incorrect switches that should start with "--"
7662
7663 elsif (Argv'Length > 5 and then Argv (1 .. 5) = "-RTS=")
7664 or else (Argv'Length > 5 and then Argv (1 .. 5) = "-GCC=")
7665 or else (Argv'Length > 10 and then Argv (1 .. 10) = "-GNATLINK=")
7666 or else (Argv'Length > 10 and then Argv (1 .. 10) = "-GNATBIND=")
7667 then
7668 Make_Failed ("option ", Argv, " should start with '--'");
7669
7670 -- -I-
7671
7672 elsif Argv (2 .. Argv'Last) = "I-" then
7673 Look_In_Primary_Dir := False;
7674
7675 -- Forbid -?- or -??- where ? is any character
7676
7677 elsif (Argv'Length = 3 and then Argv (3) = '-')
7678 or else (Argv'Length = 4 and then Argv (4) = '-')
7679 then
7680 Make_Failed ("trailing ""-"" at the end of ", Argv, " forbidden.");
7681
7682 -- -Idir
7683
7684 elsif Argv (2) = 'I' then
7685 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7686 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7687 Add_Switch (Argv, Compiler, And_Save => And_Save);
7688 Add_Switch (Argv, Binder, And_Save => And_Save);
7689
7690 -- -aIdir (to gcc this is like a -I switch)
7691
7692 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aI" then
7693 Add_Source_Search_Dir (Argv (4 .. Argv'Last), And_Save);
7694 Add_Switch ("-I" & Argv (4 .. Argv'Last),
7695 Compiler,
7696 And_Save => And_Save);
7697 Add_Switch (Argv, Binder, And_Save => And_Save);
7698
7699 -- -aOdir
7700
7701 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aO" then
7702 Add_Library_Search_Dir (Argv (4 .. Argv'Last), And_Save);
7703 Add_Switch (Argv, Binder, And_Save => And_Save);
7704
7705 -- -aLdir (to gnatbind this is like a -aO switch)
7706
7707 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aL" then
7708 Mark_Directory (Argv (4 .. Argv'Last), Ada_Lib_Dir, And_Save);
7709 Add_Library_Search_Dir (Argv (4 .. Argv'Last), And_Save);
7710 Add_Switch ("-aO" & Argv (4 .. Argv'Last),
7711 Binder,
7712 And_Save => And_Save);
7713
7714 -- -Adir (to gnatbind this is like a -aO switch, to gcc like a -I)
7715
7716 elsif Argv (2) = 'A' then
7717 Mark_Directory (Argv (3 .. Argv'Last), Ada_Lib_Dir, And_Save);
7718 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7719 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7720 Add_Switch ("-I" & Argv (3 .. Argv'Last),
7721 Compiler,
7722 And_Save => And_Save);
7723 Add_Switch ("-aO" & Argv (3 .. Argv'Last),
7724 Binder,
7725 And_Save => And_Save);
7726
7727 -- -Ldir
7728
7729 elsif Argv (2) = 'L' then
7730 Add_Switch (Argv, Linker, And_Save => And_Save);
7731
7732 -- For -gxxxxx, -pg, -mxxx, -fxxx: give the switch to both the
7733 -- compiler and the linker (except for -gnatxxx which is only for
7734 -- the compiler). Some of the -mxxx (for example -m64) and -fxxx
7735 -- (for example -ftest-coverage for gcov) need to be used when
7736 -- compiling the binder generated files, and using all these gcc
7737 -- switches for the binder generated files should not be a problem.
7738
7739 elsif
7740 (Argv (2) = 'g' and then (Argv'Last < 5
7741 or else Argv (2 .. 5) /= "gnat"))
7742 or else Argv (2 .. Argv'Last) = "pg"
7743 or else (Argv (2) = 'm' and then Argv'Last > 2)
7744 or else (Argv (2) = 'f' and then Argv'Last > 2)
7745 then
7746 Add_Switch (Argv, Compiler, And_Save => And_Save);
7747 Add_Switch (Argv, Linker, And_Save => And_Save);
7748
7749 -- -C=<mapping file>
7750
7751 elsif Argv'Last > 2 and then Argv (2) = 'C' then
7752 if And_Save then
7753 if Argv (3) /= '=' or else Argv'Last <= 3 then
7754 Make_Failed ("illegal switch ", Argv);
7755 end if;
7756
7757 Gnatmake_Mapping_File := new String'(Argv (4 .. Argv'Last));
7758 end if;
7759
7760 -- -D
7761
7762 elsif Argv'Last = 2 and then Argv (2) = 'D' then
7763 if Project_File_Name /= null then
7764 Make_Failed ("-D cannot be used in conjunction with a " &
7765 "project file");
7766
7767 else
7768 Scan_Make_Switches (Argv, Success);
7769 end if;
7770
7771 -- -d
7772
7773 elsif Argv (2) = 'd'
7774 and then Argv'Last = 2
7775 then
7776 Display_Compilation_Progress := True;
7777
7778 -- -i
7779
7780 elsif Argv'Last = 2 and then Argv (2) = 'i' then
7781 if Project_File_Name /= null then
7782 Make_Failed ("-i cannot be used in conjunction with a " &
7783 "project file");
7784
7785 else
7786 Scan_Make_Switches (Argv, Success);
7787 end if;
7788
7789 -- -j (need to save the result)
7790
7791 elsif Argv (2) = 'j' then
7792 Scan_Make_Switches (Argv, Success);
7793
7794 if And_Save then
7795 Saved_Maximum_Processes := Maximum_Processes;
7796 end if;
7797
7798 -- -m
7799
7800 elsif Argv (2) = 'm'
7801 and then Argv'Last = 2
7802 then
7803 Minimal_Recompilation := True;
7804
7805 -- -u
7806
7807 elsif Argv (2) = 'u'
7808 and then Argv'Last = 2
7809 then
7810 Unique_Compile := True;
7811 Compile_Only := True;
7812 Do_Bind_Step := False;
7813 Do_Link_Step := False;
7814
7815 -- -U
7816
7817 elsif Argv (2) = 'U'
7818 and then Argv'Last = 2
7819 then
7820 Unique_Compile_All_Projects := True;
7821 Unique_Compile := True;
7822 Compile_Only := True;
7823 Do_Bind_Step := False;
7824 Do_Link_Step := False;
7825
7826 -- -Pprj or -P prj (only once, and only on the command line)
7827
7828 elsif Argv (2) = 'P' then
7829 if Project_File_Name /= null then
7830 Make_Failed ("cannot have several project files specified");
7831
7832 elsif Object_Directory_Path /= null then
7833 Make_Failed ("-D cannot be used in conjunction with a " &
7834 "project file");
7835
7836 elsif In_Place_Mode then
7837 Make_Failed ("-i cannot be used in conjunction with a " &
7838 "project file");
7839
7840 elsif not And_Save then
7841
7842 -- It could be a tool other than gnatmake (i.e, gnatdist)
7843 -- or a -P switch inside a project file.
7844
7845 Fail
7846 ("either the tool is not ""project-aware"" or " &
7847 "a project file is specified inside a project file");
7848
7849 elsif Argv'Last = 2 then
7850
7851 -- -P is used alone: the project file name is the next option
7852
7853 Project_File_Name_Present := True;
7854
7855 else
7856 Project_File_Name := new String'(Argv (3 .. Argv'Last));
7857 end if;
7858
7859 -- -vPx (verbosity of the parsing of the project files)
7860
7861 elsif Argv'Last = 4
7862 and then Argv (2 .. 3) = "vP"
7863 and then Argv (4) in '0' .. '2'
7864 then
7865 if And_Save then
7866 case Argv (4) is
7867 when '0' =>
7868 Current_Verbosity := Prj.Default;
7869 when '1' =>
7870 Current_Verbosity := Prj.Medium;
7871 when '2' =>
7872 Current_Verbosity := Prj.High;
7873 when others =>
7874 null;
7875 end case;
7876 end if;
7877
7878 -- -Xext=val (External assignment)
7879
7880 elsif Argv (2) = 'X'
7881 and then Is_External_Assignment (Argv)
7882 then
7883 -- Is_External_Assignment has side effects
7884 -- when it returns True;
7885
7886 null;
7887
7888 -- If -gnath is present, then generate the usage information
7889 -- right now and do not pass this option on to the compiler calls.
7890
7891 elsif Argv = "-gnath" then
7892 Usage;
7893
7894 -- If -gnatc is specified, make sure the bind step and the link
7895 -- step are not executed.
7896
7897 elsif Argv'Length >= 6 and then Argv (2 .. 6) = "gnatc" then
7898
7899 -- If -gnatc is specified, make sure the bind step and the link
7900 -- step are not executed.
7901
7902 Add_Switch (Argv, Compiler, And_Save => And_Save);
7903 Operating_Mode := Check_Semantics;
7904 Check_Object_Consistency := False;
7905 Compile_Only := True;
7906 Do_Bind_Step := False;
7907 Do_Link_Step := False;
7908
7909 elsif Argv (2 .. Argv'Last) = "nostdlib" then
7910
7911 -- Don't pass -nostdlib to gnatlink, it will disable
7912 -- linking with all standard library files.
7913
7914 No_Stdlib := True;
7915
7916 Add_Switch (Argv, Compiler, And_Save => And_Save);
7917 Add_Switch (Argv, Binder, And_Save => And_Save);
7918
7919 elsif Argv (2 .. Argv'Last) = "nostdinc" then
7920
7921 -- Pass -nostdinc to the Compiler and to gnatbind
7922
7923 No_Stdinc := True;
7924 Add_Switch (Argv, Compiler, And_Save => And_Save);
7925 Add_Switch (Argv, Binder, And_Save => And_Save);
7926
7927 -- All other switches are processed by Scan_Make_Switches.
7928 -- If the call returns with Success = False, then the switch is
7929 -- passed to the compiler.
7930
7931 else
7932 Scan_Make_Switches (Argv, Success);
7933
7934 if not Success then
7935 Add_Switch (Argv, Compiler, And_Save => And_Save);
7936 end if;
7937 end if;
7938
7939 -- If not a switch it must be a file name
7940
7941 else
7942 Add_File (Argv);
7943 Mains.Add_Main (Argv);
7944 end if;
7945 end Scan_Make_Arg;
7946
7947 -----------------
7948 -- Switches_Of --
7949 -----------------
7950
7951 function Switches_Of
7952 (Source_File : File_Name_Type;
7953 Source_File_Name : String;
7954 Source_Index : Int;
7955 Naming : Naming_Data;
7956 In_Package : Package_Id;
7957 Allow_ALI : Boolean) return Variable_Value
7958 is
7959 Switches : Variable_Value;
7960
7961 Defaults : constant Array_Element_Id :=
7962 Prj.Util.Value_Of
7963 (Name => Name_Default_Switches,
7964 In_Arrays =>
7965 Project_Tree.Packages.Table
7966 (In_Package).Decl.Arrays,
7967 In_Tree => Project_Tree);
7968
7969 Switches_Array : constant Array_Element_Id :=
7970 Prj.Util.Value_Of
7971 (Name => Name_Switches,
7972 In_Arrays =>
7973 Project_Tree.Packages.Table
7974 (In_Package).Decl.Arrays,
7975 In_Tree => Project_Tree);
7976
7977 begin
7978 Switches :=
7979 Prj.Util.Value_Of
7980 (Index => Name_Id (Source_File),
7981 Src_Index => Source_Index,
7982 In_Array => Switches_Array,
7983 In_Tree => Project_Tree);
7984
7985 if Switches = Nil_Variable_Value then
7986 declare
7987 Name : String (1 .. Source_File_Name'Length + 3);
7988 Last : Positive := Source_File_Name'Length;
7989 Spec_Suffix : constant String :=
7990 Spec_Suffix_Of (Project_Tree, "ada", Naming);
7991 Body_Suffix : constant String :=
7992 Body_Suffix_Of (Project_Tree, "ada", Naming);
7993 Truncated : Boolean := False;
7994
7995 begin
7996 Name (1 .. Last) := Source_File_Name;
7997
7998 if Last > Body_Suffix'Length
7999 and then Name (Last - Body_Suffix'Length + 1 .. Last) =
8000 Body_Suffix
8001 then
8002 Truncated := True;
8003 Last := Last - Body_Suffix'Length;
8004 end if;
8005
8006 if not Truncated
8007 and then Last > Spec_Suffix'Length
8008 and then Name (Last - Spec_Suffix'Length + 1 .. Last) =
8009 Spec_Suffix
8010 then
8011 Truncated := True;
8012 Last := Last - Spec_Suffix'Length;
8013 end if;
8014
8015 if Truncated then
8016 Name_Len := Last;
8017 Name_Buffer (1 .. Name_Len) := Name (1 .. Last);
8018 Switches :=
8019 Prj.Util.Value_Of
8020 (Index => Name_Find,
8021 Src_Index => 0,
8022 In_Array => Switches_Array,
8023 In_Tree => Project_Tree);
8024
8025 if Switches = Nil_Variable_Value
8026 and then Allow_ALI
8027 then
8028 Last := Source_File_Name'Length;
8029
8030 while Name (Last) /= '.' loop
8031 Last := Last - 1;
8032 end loop;
8033
8034 Name (Last + 1 .. Last + 3) := "ali";
8035 Name_Len := Last + 3;
8036 Name_Buffer (1 .. Name_Len) := Name (1 .. Name_Len);
8037 Switches :=
8038 Prj.Util.Value_Of
8039 (Index => Name_Find,
8040 Src_Index => 0,
8041 In_Array => Switches_Array,
8042 In_Tree => Project_Tree);
8043 end if;
8044 end if;
8045 end;
8046 end if;
8047
8048 if Switches = Nil_Variable_Value then
8049 Switches :=
8050 Prj.Util.Value_Of
8051 (Index => Name_Ada,
8052 Src_Index => 0,
8053 In_Array => Defaults,
8054 In_Tree => Project_Tree);
8055 end if;
8056
8057 return Switches;
8058 end Switches_Of;
8059
8060 -----------
8061 -- Usage --
8062 -----------
8063
8064 procedure Usage is
8065 begin
8066 if Usage_Needed then
8067 Usage_Needed := False;
8068 Makeusg;
8069 end if;
8070 end Usage;
8071
8072 -----------------
8073 -- Verbose_Msg --
8074 -----------------
8075
8076 procedure Verbose_Msg
8077 (N1 : Name_Id;
8078 S1 : String;
8079 N2 : Name_Id := No_Name;
8080 S2 : String := "";
8081 Prefix : String := " -> ";
8082 Minimum_Verbosity : Verbosity_Level_Type := Opt.Low)
8083 is
8084 begin
8085 if (not Verbose_Mode) or else (Minimum_Verbosity > Verbosity_Level) then
8086 return;
8087 end if;
8088
8089 Write_Str (Prefix);
8090 Write_Str ("""");
8091 Write_Name (N1);
8092 Write_Str (""" ");
8093 Write_Str (S1);
8094
8095 if N2 /= No_Name then
8096 Write_Str (" """);
8097 Write_Name (N2);
8098 Write_Str (""" ");
8099 end if;
8100
8101 Write_Str (S2);
8102 Write_Eol;
8103 end Verbose_Msg;
8104
8105 procedure Verbose_Msg
8106 (N1 : File_Name_Type;
8107 S1 : String;
8108 N2 : File_Name_Type := No_File;
8109 S2 : String := "";
8110 Prefix : String := " -> ";
8111 Minimum_Verbosity : Verbosity_Level_Type := Opt.Low)
8112 is
8113 begin
8114 Verbose_Msg
8115 (Name_Id (N1), S1, Name_Id (N2), S2, Prefix, Minimum_Verbosity);
8116 end Verbose_Msg;
8117
8118 begin
8119 -- Make sure that in case of failure, the temp files will be deleted
8120
8121 Prj.Com.Fail := Make_Failed'Access;
8122 MLib.Fail := Make_Failed'Access;
8123 Makeutl.Do_Fail := Make_Failed'Access;
8124 end Make;