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