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