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