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