s-crtl.ads, [...]: Fix support for VMS
[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 =>
1870 Opt.Follow_Links_For_Dirs,
1871 Case_Sensitive => False);
1872
1873 begin
1874 Name_Len := 0;
1875 Add_Str_To_Name_Buffer (Res_Obj_Dir);
1876
1877 if not Is_Directory_Separator (Name_Buffer (Name_Len)) then
1878 Add_Char_To_Name_Buffer (Directory_Separator);
1879 end if;
1880
1881 Obj_Dir := Name_Find;
1882
1883 while ALI_Project /= No_Project
1884 and then Obj_Dir /= ALI_Project.Object_Directory.Name
1885 loop
1886 ALI_Project := ALI_Project.Extended_By;
1887 end loop;
1888 end;
1889
1890 if ALI_Project = No_Project then
1891 ALI := No_ALI_Id;
1892
1893 Verbose_Msg
1894 (Lib_File, " wrong object directory");
1895 return;
1896 end if;
1897
1898 -- If the ALI project is not extended, then it must be in
1899 -- the correct object directory.
1900
1901 if ALI_Project.Extended_By = No_Project then
1902 return;
1903 end if;
1904
1905 -- Count the extending projects
1906
1907 declare
1908 Num_Ext : Natural;
1909 Proj : Project_Id;
1910
1911 begin
1912 Num_Ext := 0;
1913 Proj := ALI_Project;
1914 loop
1915 Proj := Proj.Extended_By;
1916 exit when Proj = No_Project;
1917 Num_Ext := Num_Ext + 1;
1918 end loop;
1919
1920 -- Make a list of the extending projects
1921
1922 declare
1923 Projects : array (1 .. Num_Ext) of Project_Id;
1924 Dep : Sdep_Record;
1925 OK : Boolean := True;
1926 UID : Unit_Index;
1927
1928 begin
1929 Proj := ALI_Project;
1930 for J in Projects'Range loop
1931 Proj := Proj.Extended_By;
1932 Projects (J) := Proj;
1933 end loop;
1934
1935 -- Now check if any of the dependant sources are in
1936 -- any of these extending projects.
1937
1938 D_Chk :
1939 for D in ALIs.Table (ALI).First_Sdep ..
1940 ALIs.Table (ALI).Last_Sdep
1941 loop
1942 Dep := Sdep.Table (D);
1943 UID := Units_Htable.Get_First (Project_Tree.Units_HT);
1944 Proj := No_Project;
1945
1946 Unit_Loop :
1947 while UID /= null loop
1948 if UID.File_Names (Impl) /= null
1949 and then UID.File_Names (Impl).File = Dep.Sfile
1950 then
1951 Proj := UID.File_Names (Impl).Project;
1952
1953 elsif UID.File_Names (Spec) /= null
1954 and then UID.File_Names (Spec).File = Dep.Sfile
1955 then
1956 Proj := UID.File_Names (Spec).Project;
1957 end if;
1958
1959 -- If a source is in a project, check if it is one
1960 -- in the list.
1961
1962 if Proj /= No_Project then
1963 for J in Projects'Range loop
1964 if Proj = Projects (J) then
1965 OK := False;
1966 exit D_Chk;
1967 end if;
1968 end loop;
1969
1970 exit Unit_Loop;
1971 end if;
1972
1973 UID :=
1974 Units_Htable.Get_Next (Project_Tree.Units_HT);
1975 end loop Unit_Loop;
1976 end loop D_Chk;
1977
1978 -- If one of the dependent sources is in one project of
1979 -- the list, then we must recompile.
1980
1981 if not OK then
1982 ALI := No_ALI_Id;
1983 Verbose_Msg (Lib_File, " wrong object directory");
1984 end if;
1985 end;
1986 end;
1987 end if;
1988 end if;
1989 end if;
1990 end Check;
1991
1992 ------------------------
1993 -- Check_For_S_Switch --
1994 ------------------------
1995
1996 procedure Check_For_S_Switch is
1997 begin
1998 -- By default, we generate an object file
1999
2000 Output_Is_Object := True;
2001
2002 for Arg in 1 .. Last_Argument loop
2003 if Arguments (Arg).all = "-S" then
2004 Output_Is_Object := False;
2005
2006 elsif Arguments (Arg).all = "-c" then
2007 Output_Is_Object := True;
2008 end if;
2009 end loop;
2010 end Check_For_S_Switch;
2011
2012 --------------------------
2013 -- Check_Linker_Options --
2014 --------------------------
2015
2016 procedure Check_Linker_Options
2017 (E_Stamp : Time_Stamp_Type;
2018 O_File : out File_Name_Type;
2019 O_Stamp : out Time_Stamp_Type)
2020 is
2021 procedure Check_File (File : File_Name_Type);
2022 -- Update O_File and O_Stamp if the given file is younger than E_Stamp
2023 -- and O_Stamp, or if O_File is No_File and File does not exist.
2024
2025 function Get_Library_File (Name : String) return File_Name_Type;
2026 -- Return the full file name including path of a library based
2027 -- on the name specified with the -l linker option, using the
2028 -- Ada object path. Return No_File if no such file can be found.
2029
2030 type Char_Array is array (Natural) of Character;
2031 type Char_Array_Access is access constant Char_Array;
2032
2033 Template : Char_Array_Access;
2034 pragma Import (C, Template, "__gnat_library_template");
2035
2036 ----------------
2037 -- Check_File --
2038 ----------------
2039
2040 procedure Check_File (File : File_Name_Type) is
2041 Stamp : Time_Stamp_Type;
2042 Name : File_Name_Type := File;
2043
2044 begin
2045 Get_Name_String (Name);
2046
2047 -- Remove any trailing NUL characters
2048
2049 while Name_Len >= Name_Buffer'First
2050 and then Name_Buffer (Name_Len) = NUL
2051 loop
2052 Name_Len := Name_Len - 1;
2053 end loop;
2054
2055 if Name_Len = 0 then
2056 return;
2057
2058 elsif Name_Buffer (1) = '-' then
2059
2060 -- Do not check if File is a switch other than "-l"
2061
2062 if Name_Buffer (2) /= 'l' then
2063 return;
2064 end if;
2065
2066 -- The argument is a library switch, get actual name. It
2067 -- is necessary to make a copy of the relevant part of
2068 -- Name_Buffer as Get_Library_Name uses Name_Buffer as well.
2069
2070 declare
2071 Base_Name : constant String := Name_Buffer (3 .. Name_Len);
2072
2073 begin
2074 Name := Get_Library_File (Base_Name);
2075 end;
2076
2077 if Name = No_File then
2078 return;
2079 end if;
2080 end if;
2081
2082 Stamp := File_Stamp (Name);
2083
2084 -- Find the youngest object file that is younger than the
2085 -- executable. If no such file exist, record the first object
2086 -- file that is not found.
2087
2088 if (O_Stamp < Stamp and then E_Stamp < Stamp)
2089 or else (O_File = No_File and then Stamp (Stamp'First) = ' ')
2090 then
2091 O_Stamp := Stamp;
2092 O_File := Name;
2093
2094 -- Strip the trailing NUL if present
2095
2096 Get_Name_String (O_File);
2097
2098 if Name_Buffer (Name_Len) = NUL then
2099 Name_Len := Name_Len - 1;
2100 O_File := Name_Find;
2101 end if;
2102 end if;
2103 end Check_File;
2104
2105 ----------------------
2106 -- Get_Library_Name --
2107 ----------------------
2108
2109 -- See comments in a-adaint.c about template syntax
2110
2111 function Get_Library_File (Name : String) return File_Name_Type is
2112 File : File_Name_Type := No_File;
2113
2114 begin
2115 Name_Len := 0;
2116
2117 for Ptr in Template'Range loop
2118 case Template (Ptr) is
2119 when '*' =>
2120 Add_Str_To_Name_Buffer (Name);
2121
2122 when ';' =>
2123 File := Full_Lib_File_Name (Name_Find);
2124 exit when File /= No_File;
2125 Name_Len := 0;
2126
2127 when NUL =>
2128 exit;
2129
2130 when others =>
2131 Add_Char_To_Name_Buffer (Template (Ptr));
2132 end case;
2133 end loop;
2134
2135 -- The for loop exited because the end of the template
2136 -- was reached. File contains the last possible file name
2137 -- for the library.
2138
2139 if File = No_File and then Name_Len > 0 then
2140 File := Full_Lib_File_Name (Name_Find);
2141 end if;
2142
2143 return File;
2144 end Get_Library_File;
2145
2146 -- Start of processing for Check_Linker_Options
2147
2148 begin
2149 O_File := No_File;
2150 O_Stamp := (others => ' ');
2151
2152 -- Process linker options from the ALI files
2153
2154 for Opt in 1 .. Linker_Options.Last loop
2155 Check_File (File_Name_Type (Linker_Options.Table (Opt).Name));
2156 end loop;
2157
2158 -- Process options given on the command line
2159
2160 for Opt in Linker_Switches.First .. Linker_Switches.Last loop
2161
2162 -- Check if the previous Opt has one of the two switches
2163 -- that take an extra parameter. (See GCC manual.)
2164
2165 if Opt = Linker_Switches.First
2166 or else (Linker_Switches.Table (Opt - 1).all /= "-u"
2167 and then
2168 Linker_Switches.Table (Opt - 1).all /= "-Xlinker"
2169 and then
2170 Linker_Switches.Table (Opt - 1).all /= "-L")
2171 then
2172 Name_Len := 0;
2173 Add_Str_To_Name_Buffer (Linker_Switches.Table (Opt).all);
2174 Check_File (Name_Find);
2175 end if;
2176 end loop;
2177
2178 end Check_Linker_Options;
2179
2180 -----------------
2181 -- Check_Steps --
2182 -----------------
2183
2184 procedure Check_Steps is
2185 begin
2186 -- If either -c, -b or -l has been specified, we will not necessarily
2187 -- execute all steps.
2188
2189 if Make_Steps then
2190 Do_Compile_Step := Do_Compile_Step and Compile_Only;
2191 Do_Bind_Step := Do_Bind_Step and Bind_Only;
2192 Do_Link_Step := Do_Link_Step and Link_Only;
2193
2194 -- If -c has been specified, but not -b, ignore any potential -l
2195
2196 if Do_Compile_Step and then not Do_Bind_Step then
2197 Do_Link_Step := False;
2198 end if;
2199 end if;
2200 end Check_Steps;
2201
2202 -----------------------
2203 -- Collect_Arguments --
2204 -----------------------
2205
2206 procedure Collect_Arguments
2207 (Source_File : File_Name_Type;
2208 Source_Index : Int;
2209 Is_Main_Source : Boolean;
2210 Args : Argument_List)
2211 is
2212 begin
2213 Arguments_Project := No_Project;
2214 Last_Argument := 0;
2215 Add_Arguments (Args);
2216
2217 if Main_Project /= No_Project then
2218 declare
2219 Source_File_Name : constant String :=
2220 Get_Name_String (Source_File);
2221 Compiler_Package : Prj.Package_Id;
2222 Switches : Prj.Variable_Value;
2223
2224 begin
2225 Prj.Env.
2226 Get_Reference
2227 (Source_File_Name => Source_File_Name,
2228 Project => Arguments_Project,
2229 Path => Arguments_Path_Name,
2230 In_Tree => Project_Tree);
2231
2232 -- If the source is not a source of a project file, add the
2233 -- recorded arguments. Check will be done later if the source
2234 -- need to be compiled that the switch -x has been used.
2235
2236 if Arguments_Project = No_Project then
2237 Add_Arguments (The_Saved_Gcc_Switches.all);
2238
2239 elsif not Arguments_Project.Externally_Built then
2240 -- We get the project directory for the relative path
2241 -- switches and arguments.
2242
2243 Arguments_Project := Ultimate_Extending_Project_Of
2244 (Arguments_Project);
2245
2246 -- If building a dynamic or relocatable library, compile with
2247 -- PIC option, if it exists.
2248
2249 if Arguments_Project.Library
2250 and then Arguments_Project.Library_Kind /= Static
2251 then
2252 declare
2253 PIC : constant String := MLib.Tgt.PIC_Option;
2254
2255 begin
2256 if PIC /= "" then
2257 Add_Arguments ((1 => new String'(PIC)));
2258 end if;
2259 end;
2260 end if;
2261
2262 -- We now look for package Compiler and get the switches from
2263 -- this package.
2264
2265 Compiler_Package :=
2266 Prj.Util.Value_Of
2267 (Name => Name_Compiler,
2268 In_Packages => Arguments_Project.Decl.Packages,
2269 In_Tree => Project_Tree);
2270
2271 if Compiler_Package /= No_Package then
2272
2273 -- If package Gnatmake.Compiler exists, we get the specific
2274 -- switches for the current source, or the global switches,
2275 -- if any.
2276
2277 Switches :=
2278 Switches_Of
2279 (Source_File => Source_File,
2280 Source_File_Name => Source_File_Name,
2281 Source_Index => Source_Index,
2282 Project => Arguments_Project,
2283 In_Package => Compiler_Package,
2284 Allow_ALI => False);
2285
2286 end if;
2287
2288 case Switches.Kind is
2289
2290 -- We have a list of switches. We add these switches,
2291 -- plus the saved gcc switches.
2292
2293 when List =>
2294
2295 declare
2296 Current : String_List_Id := Switches.Values;
2297 Element : String_Element;
2298 Number : Natural := 0;
2299
2300 begin
2301 while Current /= Nil_String loop
2302 Element := Project_Tree.String_Elements.
2303 Table (Current);
2304 Number := Number + 1;
2305 Current := Element.Next;
2306 end loop;
2307
2308 declare
2309 New_Args : Argument_List (1 .. Number);
2310 Last_New : Natural := 0;
2311 Dir_Path : constant String := Get_Name_String
2312 (Arguments_Project.Directory.Name);
2313
2314 begin
2315 Current := Switches.Values;
2316
2317 for Index in New_Args'Range loop
2318 Element := Project_Tree.String_Elements.
2319 Table (Current);
2320 Get_Name_String (Element.Value);
2321
2322 if Name_Len > 0 then
2323 Last_New := Last_New + 1;
2324 New_Args (Last_New) :=
2325 new String'(Name_Buffer (1 .. Name_Len));
2326 Test_If_Relative_Path
2327 (New_Args (Last_New),
2328 Parent => Dir_Path,
2329 Including_Non_Switch => False);
2330 end if;
2331
2332 Current := Element.Next;
2333 end loop;
2334
2335 Add_Arguments
2336 (Configuration_Pragmas_Switch
2337 (Arguments_Project) &
2338 New_Args (1 .. Last_New) &
2339 The_Saved_Gcc_Switches.all);
2340 end;
2341 end;
2342
2343 -- We have a single switch. We add this switch,
2344 -- plus the saved gcc switches.
2345
2346 when Single =>
2347 Get_Name_String (Switches.Value);
2348
2349 declare
2350 New_Args : Argument_List :=
2351 (1 => new String'
2352 (Name_Buffer (1 .. Name_Len)));
2353 Dir_Path : constant String :=
2354 Get_Name_String
2355 (Arguments_Project.Directory.Name);
2356
2357 begin
2358 Test_If_Relative_Path
2359 (New_Args (1),
2360 Parent => Dir_Path,
2361 Including_Non_Switch => False);
2362 Add_Arguments
2363 (Configuration_Pragmas_Switch (Arguments_Project) &
2364 New_Args & The_Saved_Gcc_Switches.all);
2365 end;
2366
2367 -- We have no switches from Gnatmake.Compiler.
2368 -- We add the saved gcc switches.
2369
2370 when Undefined =>
2371 Add_Arguments
2372 (Configuration_Pragmas_Switch (Arguments_Project) &
2373 The_Saved_Gcc_Switches.all);
2374 end case;
2375 end if;
2376 end;
2377 end if;
2378
2379 -- For VMS, when compiling the main source, add switch
2380 -- -mdebug-main=_ada_ so that the executable can be debugged
2381 -- by the standard VMS debugger.
2382
2383 if not No_Main_Subprogram
2384 and then Targparm.OpenVMS_On_Target
2385 and then Is_Main_Source
2386 then
2387 -- First, check if compilation will be invoked with -g
2388
2389 for J in 1 .. Last_Argument loop
2390 if Arguments (J)'Length >= 2
2391 and then Arguments (J) (1 .. 2) = "-g"
2392 and then (Arguments (J)'Length < 5
2393 or else Arguments (J) (1 .. 5) /= "-gnat")
2394 then
2395 Add_Arguments
2396 ((1 => new String'("-mdebug-main=_ada_")));
2397 exit;
2398 end if;
2399 end loop;
2400 end if;
2401
2402 -- Set Output_Is_Object, depending if there is a -S switch.
2403 -- If the bind step is not performed, and there is a -S switch,
2404 -- then we will not check for a valid object file.
2405
2406 Check_For_S_Switch;
2407 end Collect_Arguments;
2408
2409 ---------------------
2410 -- Compile_Sources --
2411 ---------------------
2412
2413 procedure Compile_Sources
2414 (Main_Source : File_Name_Type;
2415 Args : Argument_List;
2416 First_Compiled_File : out File_Name_Type;
2417 Most_Recent_Obj_File : out File_Name_Type;
2418 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
2419 Main_Unit : out Boolean;
2420 Compilation_Failures : out Natural;
2421 Main_Index : Int := 0;
2422 Check_Readonly_Files : Boolean := False;
2423 Do_Not_Execute : Boolean := False;
2424 Force_Compilations : Boolean := False;
2425 Keep_Going : Boolean := False;
2426 In_Place_Mode : Boolean := False;
2427 Initialize_ALI_Data : Boolean := True;
2428 Max_Process : Positive := 1)
2429 is
2430 Mfile : Natural := No_Mapping_File;
2431 Mapping_File_Arg : String_Access;
2432 -- Info on the mapping file
2433
2434 Need_To_Check_Standard_Library : Boolean :=
2435 Check_Readonly_Files
2436 and not Unique_Compile;
2437
2438 procedure Add_Process
2439 (Pid : Process_Id;
2440 Sfile : File_Name_Type;
2441 Afile : File_Name_Type;
2442 Uname : Unit_Name_Type;
2443 Full_Lib_File : File_Name_Type;
2444 Lib_File_Attr : File_Attributes;
2445 Mfile : Natural := No_Mapping_File);
2446 -- Adds process Pid to the current list of outstanding compilation
2447 -- processes and record the full name of the source file Sfile that
2448 -- we are compiling, the name of its library file Afile and the
2449 -- name of its unit Uname. If Mfile is not equal to No_Mapping_File,
2450 -- it is the index of the mapping file used during compilation in the
2451 -- array The_Mapping_File_Names.
2452
2453 procedure Await_Compile
2454 (Data : out Compilation_Data;
2455 OK : out Boolean);
2456 -- Awaits that an outstanding compilation process terminates. When it
2457 -- does set Data to the information registered for the corresponding
2458 -- call to Add_Process. Note that this time stamp can be used to check
2459 -- whether the compilation did generate an object file. OK is set to
2460 -- True if the compilation succeeded. Data could be No_Compilation_Data
2461 -- if there was no compilation to wait for.
2462
2463 function Bad_Compilation_Count return Natural;
2464 -- Returns the number of compilation failures
2465
2466 procedure Check_Standard_Library;
2467 -- Check if s-stalib.adb needs to be compiled
2468
2469 procedure Collect_Arguments_And_Compile
2470 (Full_Source_File : File_Name_Type;
2471 Lib_File : File_Name_Type;
2472 Source_Index : Int;
2473 Pid : out Process_Id;
2474 Process_Created : out Boolean);
2475 -- Collect arguments from project file (if any) and compile. If no
2476 -- compilation was attempted, Processed_Created is set to False, and the
2477 -- value of Pid is unknown.
2478
2479 function Compile
2480 (Project : Project_Id;
2481 S : File_Name_Type;
2482 L : File_Name_Type;
2483 Source_Index : Int;
2484 Args : Argument_List) return Process_Id;
2485 -- Compiles S using Args. If S is a GNAT predefined source "-gnatpg" is
2486 -- added to Args. Non blocking call. L corresponds to the expected
2487 -- library file name. Process_Id of the process spawned to execute the
2488 -- compilation.
2489
2490 package Good_ALI is new Table.Table (
2491 Table_Component_Type => ALI_Id,
2492 Table_Index_Type => Natural,
2493 Table_Low_Bound => 1,
2494 Table_Initial => 50,
2495 Table_Increment => 100,
2496 Table_Name => "Make.Good_ALI");
2497 -- Contains the set of valid ALI files that have not yet been scanned
2498
2499 function Good_ALI_Present return Boolean;
2500 -- Returns True if any ALI file was recorded in the previous set
2501
2502 procedure Get_Mapping_File (Project : Project_Id);
2503 -- Get a mapping file name. If there is one to be reused, reuse it.
2504 -- Otherwise, create a new mapping file.
2505
2506 function Get_Next_Good_ALI return ALI_Id;
2507 -- Returns the next good ALI_Id record
2508
2509 procedure Record_Failure
2510 (File : File_Name_Type;
2511 Unit : Unit_Name_Type;
2512 Found : Boolean := True);
2513 -- Records in the previous table that the compilation for File failed.
2514 -- If Found is False then the compilation of File failed because we
2515 -- could not find it. Records also Unit when possible.
2516
2517 procedure Record_Good_ALI (A : ALI_Id);
2518 -- Records in the previous set the Id of an ALI file
2519
2520 function Must_Exit_Because_Of_Error return Boolean;
2521 -- Return True if there were errors and the user decided to exit in such
2522 -- a case. This waits for any outstanding compilation.
2523
2524 function Start_Compile_If_Possible (Args : Argument_List) return Boolean;
2525 -- Check if there is more work that we can do (i.e. the Queue is non
2526 -- empty). If there is, do it only if we have not yet used up all the
2527 -- available processes.
2528 -- Returns True if we should exit the main loop
2529
2530 procedure Wait_For_Available_Slot;
2531 -- Check if we should wait for a compilation to finish. This is the case
2532 -- if all the available processes are busy compiling sources or there is
2533 -- nothing else to do (that is the Q is empty and there are no good ALIs
2534 -- to process).
2535
2536 procedure Fill_Queue_From_ALI_Files;
2537 -- Check if we recorded good ALI files. If yes process them now in the
2538 -- order in which they have been recorded. There are two occasions in
2539 -- which we record good ali files. The first is in phase 1 when, after
2540 -- scanning an existing ALI file we realize it is up-to-date, the second
2541 -- instance is after a successful compilation.
2542
2543 -----------------
2544 -- Add_Process --
2545 -----------------
2546
2547 procedure Add_Process
2548 (Pid : Process_Id;
2549 Sfile : File_Name_Type;
2550 Afile : File_Name_Type;
2551 Uname : Unit_Name_Type;
2552 Full_Lib_File : File_Name_Type;
2553 Lib_File_Attr : File_Attributes;
2554 Mfile : Natural := No_Mapping_File)
2555 is
2556 OC1 : constant Positive := Outstanding_Compiles + 1;
2557
2558 begin
2559 pragma Assert (OC1 <= Max_Process);
2560 pragma Assert (Pid /= Invalid_Pid);
2561
2562 Running_Compile (OC1) :=
2563 (Pid => Pid,
2564 Full_Source_File => Sfile,
2565 Lib_File => Afile,
2566 Full_Lib_File => Full_Lib_File,
2567 Lib_File_Attr => Lib_File_Attr,
2568 Source_Unit => Uname,
2569 Mapping_File => Mfile,
2570 Project => Arguments_Project);
2571
2572 Outstanding_Compiles := OC1;
2573 end Add_Process;
2574
2575 --------------------
2576 -- Await_Compile --
2577 -------------------
2578
2579 procedure Await_Compile
2580 (Data : out Compilation_Data;
2581 OK : out Boolean)
2582 is
2583 Pid : Process_Id;
2584 Project : Project_Id;
2585 Comp_Data : Project_Compilation_Access;
2586
2587 begin
2588 pragma Assert (Outstanding_Compiles > 0);
2589
2590 Data := No_Compilation_Data;
2591 OK := False;
2592
2593 -- The loop here is a work-around for a problem on VMS; in some
2594 -- circumstances (shared library and several executables, for
2595 -- example), there are child processes other than compilation
2596 -- processes that are received. Until this problem is resolved,
2597 -- we will ignore such processes.
2598
2599 loop
2600 Wait_Process (Pid, OK);
2601
2602 if Pid = Invalid_Pid then
2603 return;
2604 end if;
2605
2606 for J in Running_Compile'First .. Outstanding_Compiles loop
2607 if Pid = Running_Compile (J).Pid then
2608 Data := Running_Compile (J);
2609 Project := Running_Compile (J).Project;
2610
2611 -- If a mapping file was used by this compilation, get its
2612 -- file name for reuse by a subsequent compilation.
2613
2614 if Running_Compile (J).Mapping_File /= No_Mapping_File then
2615 Comp_Data :=
2616 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 else
2632 Running_Compile (J) :=
2633 Running_Compile (Outstanding_Compiles);
2634 end if;
2635
2636 Outstanding_Compiles := Outstanding_Compiles - 1;
2637 return;
2638 end if;
2639 end loop;
2640
2641 -- This child process was not one of our compilation processes;
2642 -- just ignore it for now.
2643
2644 -- Why is this commented out code sitting here???
2645
2646 -- raise Program_Error;
2647 end loop;
2648 end Await_Compile;
2649
2650 ---------------------------
2651 -- Bad_Compilation_Count --
2652 ---------------------------
2653
2654 function Bad_Compilation_Count return Natural is
2655 begin
2656 return Bad_Compilation.Last - Bad_Compilation.First + 1;
2657 end Bad_Compilation_Count;
2658
2659 ----------------------------
2660 -- Check_Standard_Library --
2661 ----------------------------
2662
2663 procedure Check_Standard_Library is
2664 begin
2665 Need_To_Check_Standard_Library := False;
2666
2667 if not Targparm.Suppress_Standard_Library_On_Target then
2668 declare
2669 Sfile : File_Name_Type;
2670 Add_It : Boolean := True;
2671
2672 begin
2673 Name_Len := 0;
2674 Add_Str_To_Name_Buffer (Standard_Library_Package_Body_Name);
2675 Sfile := Name_Enter;
2676
2677 -- If we have a special runtime, we add the standard
2678 -- library only if we can find it.
2679
2680 if RTS_Switch then
2681 Add_It :=
2682 Find_File (Sfile, Osint.Source) /= No_File;
2683 end if;
2684
2685 if Add_It then
2686 if Is_Marked (Sfile) then
2687 if Is_In_Obsoleted (Sfile) then
2688 Executable_Obsolete := True;
2689 end if;
2690
2691 else
2692 Insert_Q (Sfile, Index => 0);
2693 Mark (Sfile, Index => 0);
2694 end if;
2695 end if;
2696 end;
2697 end if;
2698 end Check_Standard_Library;
2699
2700 -----------------------------------
2701 -- Collect_Arguments_And_Compile --
2702 -----------------------------------
2703
2704 procedure Collect_Arguments_And_Compile
2705 (Full_Source_File : File_Name_Type;
2706 Lib_File : File_Name_Type;
2707 Source_Index : Int;
2708 Pid : out Process_Id;
2709 Process_Created : out Boolean) is
2710 begin
2711 Process_Created := False;
2712
2713 -- If we use mapping file (-P or -C switches), then get one
2714
2715 if Create_Mapping_File then
2716 Get_Mapping_File (Arguments_Project);
2717 end if;
2718
2719 -- If the source is part of a project file, we set the ADA_*_PATHs,
2720 -- check for an eventual library project, and use the full path.
2721
2722 if Arguments_Project /= No_Project then
2723 if not Arguments_Project.Externally_Built then
2724 Prj.Env.Set_Ada_Paths
2725 (Arguments_Project,
2726 Project_Tree,
2727 Including_Libraries => True);
2728
2729 if not Unique_Compile
2730 and then MLib.Tgt.Support_For_Libraries /= Prj.None
2731 then
2732 declare
2733 Prj : constant Project_Id :=
2734 Ultimate_Extending_Project_Of (Arguments_Project);
2735
2736 begin
2737 if Prj.Library
2738 and then not Prj.Externally_Built
2739 and then not Prj.Need_To_Build_Lib
2740 then
2741 -- Add to the Q all sources of the project that have
2742 -- not been marked.
2743
2744 Insert_Project_Sources
2745 (The_Project => Prj,
2746 All_Projects => False,
2747 Into_Q => True);
2748
2749 -- Now mark the project as processed
2750
2751 Prj.Need_To_Build_Lib := True;
2752 end if;
2753 end;
2754 end if;
2755
2756 Pid :=
2757 Compile
2758 (Project => Arguments_Project,
2759 S => File_Name_Type (Arguments_Path_Name),
2760 L => Lib_File,
2761 Source_Index => Source_Index,
2762 Args => Arguments (1 .. Last_Argument));
2763 Process_Created := True;
2764 end if;
2765
2766 else
2767 -- If this is a source outside of any project file, make sure it
2768 -- will be compiled in object directory of the main project file.
2769
2770 Pid :=
2771 Compile
2772 (Project => Main_Project,
2773 S => Full_Source_File,
2774 L => Lib_File,
2775 Source_Index => Source_Index,
2776 Args => Arguments (1 .. Last_Argument));
2777 Process_Created := True;
2778 end if;
2779 end Collect_Arguments_And_Compile;
2780
2781 -------------
2782 -- Compile --
2783 -------------
2784
2785 function Compile
2786 (Project : Project_Id;
2787 S : File_Name_Type;
2788 L : File_Name_Type;
2789 Source_Index : Int;
2790 Args : Argument_List) return Process_Id
2791 is
2792 Comp_Args : Argument_List (Args'First .. Args'Last + 10);
2793 Comp_Next : Integer := Args'First;
2794 Comp_Last : Integer;
2795 Arg_Index : Integer;
2796
2797 function Ada_File_Name (Name : File_Name_Type) return Boolean;
2798 -- Returns True if Name is the name of an ada source file
2799 -- (i.e. suffix is .ads or .adb)
2800
2801 -------------------
2802 -- Ada_File_Name --
2803 -------------------
2804
2805 function Ada_File_Name (Name : File_Name_Type) return Boolean is
2806 begin
2807 Get_Name_String (Name);
2808 return
2809 Name_Len > 4
2810 and then Name_Buffer (Name_Len - 3 .. Name_Len - 1) = ".ad"
2811 and then (Name_Buffer (Name_Len) = 'b'
2812 or else
2813 Name_Buffer (Name_Len) = 's');
2814 end Ada_File_Name;
2815
2816 -- Start of processing for Compile
2817
2818 begin
2819 Enter_Into_Obsoleted (S);
2820
2821 -- By default, Syntax_Only is False
2822
2823 Syntax_Only := False;
2824
2825 for J in Args'Range loop
2826 if Args (J).all = "-gnats" then
2827
2828 -- If we compile with -gnats, the bind step and the link step
2829 -- are inhibited. Also, we set Syntax_Only to True, so that
2830 -- we don't fail when we don't find the ALI file, after
2831 -- compilation.
2832
2833 Do_Bind_Step := False;
2834 Do_Link_Step := False;
2835 Syntax_Only := True;
2836
2837 elsif Args (J).all = "-gnatc" then
2838
2839 -- If we compile with -gnatc, the bind step and the link step
2840 -- are inhibited. We set Syntax_Only to False for the case when
2841 -- -gnats was previously specified.
2842
2843 Do_Bind_Step := False;
2844 Do_Link_Step := False;
2845 Syntax_Only := False;
2846 end if;
2847 end loop;
2848
2849 Comp_Args (Comp_Next) := new String'("-gnatea");
2850 Comp_Next := Comp_Next + 1;
2851
2852 Comp_Args (Comp_Next) := Comp_Flag;
2853 Comp_Next := Comp_Next + 1;
2854
2855 -- Optimize the simple case where the gcc command line looks like
2856 -- gcc -c -I. ... -I- file.adb
2857 -- into
2858 -- gcc -c ... file.adb
2859
2860 if Args (Args'First).all = "-I" & Normalized_CWD
2861 and then Args (Args'Last).all = "-I-"
2862 and then S = Strip_Directory (S)
2863 then
2864 Comp_Last := Comp_Next + Args'Length - 3;
2865 Arg_Index := Args'First + 1;
2866
2867 else
2868 Comp_Last := Comp_Next + Args'Length - 1;
2869 Arg_Index := Args'First;
2870 end if;
2871
2872 -- Make a deep copy of the arguments, because Normalize_Arguments
2873 -- may deallocate some arguments.
2874
2875 for J in Comp_Next .. Comp_Last loop
2876 Comp_Args (J) := new String'(Args (Arg_Index).all);
2877 Arg_Index := Arg_Index + 1;
2878 end loop;
2879
2880 -- Set -gnatpg for predefined files (for this purpose the renamings
2881 -- such as Text_IO do not count as predefined). Note that we strip
2882 -- the directory name from the source file name because the call to
2883 -- Fname.Is_Predefined_File_Name cannot deal with directory prefixes.
2884
2885 declare
2886 Fname : constant File_Name_Type := Strip_Directory (S);
2887
2888 begin
2889 if Is_Predefined_File_Name (Fname, False) then
2890 if Check_Readonly_Files then
2891 Comp_Args (Comp_Args'First + 2 .. Comp_Last + 1) :=
2892 Comp_Args (Comp_Args'First + 1 .. Comp_Last);
2893 Comp_Last := Comp_Last + 1;
2894 Comp_Args (Comp_Args'First + 1) := GNAT_Flag;
2895
2896 else
2897 Make_Failed
2898 ("not allowed to compile """ &
2899 Get_Name_String (Fname) &
2900 """; use -a switch, or compile file with " &
2901 """-gnatg"" switch");
2902 end if;
2903 end if;
2904 end;
2905
2906 -- Now check if the file name has one of the suffixes familiar to
2907 -- the gcc driver. If this is not the case then add the ada flag
2908 -- "-x ada".
2909
2910 if not Ada_File_Name (S) and then not Targparm.AAMP_On_Target then
2911 Comp_Last := Comp_Last + 1;
2912 Comp_Args (Comp_Last) := Ada_Flag_1;
2913 Comp_Last := Comp_Last + 1;
2914 Comp_Args (Comp_Last) := Ada_Flag_2;
2915 end if;
2916
2917 if Source_Index /= 0 then
2918 declare
2919 Num : constant String := Source_Index'Img;
2920 begin
2921 Comp_Last := Comp_Last + 1;
2922 Comp_Args (Comp_Last) :=
2923 new String'("-gnateI" & Num (Num'First + 1 .. Num'Last));
2924 end;
2925 end if;
2926
2927 if Source_Index /= 0
2928 or else L /= Strip_Directory (L)
2929 or else Object_Directory_Path /= null
2930 then
2931 -- Build -o argument
2932
2933 Get_Name_String (L);
2934
2935 for J in reverse 1 .. Name_Len loop
2936 if Name_Buffer (J) = '.' then
2937 Name_Len := J + Object_Suffix'Length - 1;
2938 Name_Buffer (J .. Name_Len) := Object_Suffix;
2939 exit;
2940 end if;
2941 end loop;
2942
2943 Comp_Last := Comp_Last + 1;
2944 Comp_Args (Comp_Last) := Output_Flag;
2945 Comp_Last := Comp_Last + 1;
2946
2947 -- If an object directory was specified, prepend the object file
2948 -- name with this object directory.
2949
2950 if Object_Directory_Path /= null then
2951 Comp_Args (Comp_Last) :=
2952 new String'(Object_Directory_Path.all &
2953 Name_Buffer (1 .. Name_Len));
2954
2955 else
2956 Comp_Args (Comp_Last) :=
2957 new String'(Name_Buffer (1 .. Name_Len));
2958 end if;
2959 end if;
2960
2961 if Create_Mapping_File and then Mapping_File_Arg /= null then
2962 Comp_Last := Comp_Last + 1;
2963 Comp_Args (Comp_Last) := new String'(Mapping_File_Arg.all);
2964 end if;
2965
2966 Get_Name_String (S);
2967
2968 Comp_Last := Comp_Last + 1;
2969 Comp_Args (Comp_Last) := new String'(Name_Buffer (1 .. Name_Len));
2970
2971 -- Change to object directory of the project file, if necessary
2972
2973 if Project /= No_Project then
2974 Change_To_Object_Directory (Project);
2975 end if;
2976
2977 GNAT.OS_Lib.Normalize_Arguments (Comp_Args (Args'First .. Comp_Last));
2978
2979 Comp_Last := Comp_Last + 1;
2980 Comp_Args (Comp_Last) := new String'("-gnatez");
2981
2982 Display (Gcc.all, Comp_Args (Args'First .. Comp_Last));
2983
2984 if Gcc_Path = null then
2985 Make_Failed ("error, unable to locate " & Gcc.all);
2986 end if;
2987
2988 return
2989 GNAT.OS_Lib.Non_Blocking_Spawn
2990 (Gcc_Path.all, Comp_Args (Args'First .. Comp_Last));
2991 end Compile;
2992
2993 -------------------------------
2994 -- Fill_Queue_From_ALI_Files --
2995 -------------------------------
2996
2997 procedure Fill_Queue_From_ALI_Files is
2998 ALI : ALI_Id;
2999 Source_Index : Int;
3000 Sfile : File_Name_Type;
3001 Uname : Unit_Name_Type;
3002 Unit_Name : Name_Id;
3003 Uid : Prj.Unit_Index;
3004
3005 begin
3006 while Good_ALI_Present loop
3007 ALI := Get_Next_Good_ALI;
3008 Source_Index := Unit_Index_Of (ALIs.Table (ALI).Afile);
3009
3010 -- If we are processing the library file corresponding to the
3011 -- main source file check if this source can be a main unit.
3012
3013 if ALIs.Table (ALI).Sfile = Main_Source
3014 and then Source_Index = Main_Index
3015 then
3016 Main_Unit := ALIs.Table (ALI).Main_Program /= None;
3017 end if;
3018
3019 -- The following adds the standard library (s-stalib) to the list
3020 -- of files to be handled by gnatmake: this file and any files it
3021 -- depends on are always included in every bind, even if they are
3022 -- not in the explicit dependency list. Of course, it is not added
3023 -- if Suppress_Standard_Library is True.
3024
3025 -- However, to avoid annoying output about s-stalib.ali being read
3026 -- only, when "-v" is used, we add the standard library only when
3027 -- "-a" is used.
3028
3029 if Need_To_Check_Standard_Library then
3030 Check_Standard_Library;
3031 end if;
3032
3033 -- Now insert in the Q the unmarked source files (i.e. those which
3034 -- have never been inserted in the Q and hence never considered).
3035 -- Only do that if Unique_Compile is False.
3036
3037 if not Unique_Compile then
3038 for J in
3039 ALIs.Table (ALI).First_Unit .. ALIs.Table (ALI).Last_Unit
3040 loop
3041 for K in
3042 Units.Table (J).First_With .. Units.Table (J).Last_With
3043 loop
3044 Sfile := Withs.Table (K).Sfile;
3045 Uname := Withs.Table (K).Uname;
3046
3047 -- If project files are used, find the proper source to
3048 -- compile in case Sfile is the spec but there 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
3168 begin
3169 if Bad_Compilation_Count > 0 and then not Keep_Going then
3170 while Outstanding_Compiles > 0 loop
3171 Await_Compile (Data, Success);
3172
3173 if not Success then
3174 Record_Failure (Data.Full_Source_File, Data.Source_Unit);
3175 end if;
3176 end loop;
3177
3178 return True;
3179 end if;
3180
3181 return False;
3182 end Must_Exit_Because_Of_Error;
3183
3184 --------------------
3185 -- Record_Failure --
3186 --------------------
3187
3188 procedure Record_Failure
3189 (File : File_Name_Type;
3190 Unit : Unit_Name_Type;
3191 Found : Boolean := True)
3192 is
3193 begin
3194 Bad_Compilation.Increment_Last;
3195 Bad_Compilation.Table (Bad_Compilation.Last) := (File, Unit, Found);
3196 end Record_Failure;
3197
3198 ---------------------
3199 -- Record_Good_ALI --
3200 ---------------------
3201
3202 procedure Record_Good_ALI (A : ALI_Id) is
3203 begin
3204 Good_ALI.Increment_Last;
3205 Good_ALI.Table (Good_ALI.Last) := A;
3206 end Record_Good_ALI;
3207
3208 -------------------------------
3209 -- Start_Compile_If_Possible --
3210 -------------------------------
3211
3212 function Start_Compile_If_Possible
3213 (Args : Argument_List) return Boolean
3214 is
3215 In_Lib_Dir : Boolean;
3216 Need_To_Compile : Boolean;
3217 Pid : Process_Id;
3218 Process_Created : Boolean;
3219
3220 Source_File : File_Name_Type;
3221 Full_Source_File : File_Name_Type;
3222 Source_File_Attr : aliased File_Attributes;
3223 -- The full name of the source file and its attributes (size, ...)
3224
3225 Source_Unit : Unit_Name_Type;
3226 Source_Index : Int;
3227 -- Index of the current unit in the current source file
3228
3229 Lib_File : File_Name_Type;
3230 Full_Lib_File : File_Name_Type;
3231 Lib_File_Attr : aliased File_Attributes;
3232 Read_Only : Boolean := False;
3233 ALI : ALI_Id;
3234 -- The ALI file and its attributes (size, stamp, ...)
3235
3236 Obj_File : File_Name_Type;
3237 Obj_Stamp : Time_Stamp_Type;
3238 -- The object file
3239
3240 begin
3241 if not Empty_Q and then Outstanding_Compiles < Max_Process then
3242 Extract_From_Q (Source_File, Source_Unit, Source_Index);
3243
3244 Osint.Full_Source_Name
3245 (Source_File,
3246 Full_File => Full_Source_File,
3247 Attr => Source_File_Attr'Access);
3248
3249 Lib_File := Osint.Lib_File_Name (Source_File, Source_Index);
3250 Osint.Full_Lib_File_Name
3251 (Lib_File,
3252 Lib_File => Full_Lib_File,
3253 Attr => Lib_File_Attr);
3254
3255 -- If source has already been compiled, executable is 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
3362 -- The ALI file is up-to-date; record its Id
3363
3364 Record_Good_ALI (ALI);
3365
3366 -- Record the time stamp of the most recent object
3367 -- file as long as no (re)compilations are needed.
3368
3369 if First_Compiled_File = No_File
3370 and then (Most_Recent_Obj_File = No_File
3371 or else Obj_Stamp > Most_Recent_Obj_Stamp)
3372 then
3373 Most_Recent_Obj_File := Obj_File;
3374 Most_Recent_Obj_Stamp := Obj_Stamp;
3375 end if;
3376
3377 else
3378 -- Check that switch -x has been used if a source outside
3379 -- of project files need to be compiled.
3380
3381 if Main_Project /= No_Project
3382 and then Arguments_Project = No_Project
3383 and then not External_Unit_Compilation_Allowed
3384 then
3385 Make_Failed ("external source ("
3386 & Get_Name_String (Source_File)
3387 & ") is not part of any project;"
3388 & " cannot be compiled without"
3389 & " gnatmake switch -x");
3390 end if;
3391
3392 -- Is this the first file we have to compile?
3393
3394 if First_Compiled_File = No_File then
3395 First_Compiled_File := Full_Source_File;
3396 Most_Recent_Obj_File := No_File;
3397
3398 if Do_Not_Execute then
3399
3400 -- Exit the main loop
3401
3402 return True;
3403 end if;
3404 end if;
3405
3406 -- Compute where the ALI file must be generated in
3407 -- In_Place_Mode (this does not require to know the
3408 -- location of the object directory).
3409
3410 if In_Place_Mode then
3411 if Full_Lib_File = No_File then
3412
3413 -- If the library file was not found, then save
3414 -- the library file near the source file.
3415
3416 Lib_File :=
3417 Osint.Lib_File_Name
3418 (Full_Source_File, Source_Index);
3419 Full_Lib_File := Lib_File;
3420
3421 else
3422 -- If the library file was found, then save the
3423 -- library file in the same place.
3424
3425 Lib_File := Full_Lib_File;
3426 end if;
3427 end if;
3428
3429 -- Start the compilation and record it. We can do this
3430 -- because there is at least one free process. This
3431 -- might change the current directory.
3432
3433 Collect_Arguments_And_Compile
3434 (Full_Source_File => Full_Source_File,
3435 Lib_File => Lib_File,
3436 Source_Index => Source_Index,
3437 Pid => Pid,
3438 Process_Created => Process_Created);
3439
3440 -- Compute where the ALI file will be generated (for
3441 -- cases that might require to know the current
3442 -- directory). The current directory might be changed
3443 -- when compiling other files so we cannot rely on it
3444 -- being the same to find the resulting ALI file.
3445
3446 if not In_Place_Mode then
3447
3448 -- Compute the expected location of the ALI file. This
3449 -- can be from several places:
3450 -- -i => in place mode. In such a case,
3451 -- Full_Lib_File has already been set above
3452 -- -D => if specified
3453 -- or defaults in current dir
3454 -- We could simply use a call similar to
3455 -- Osint.Full_Lib_File_Name (Lib_File)
3456 -- but that involves system calls and is thus slower
3457
3458 if Object_Directory_Path /= null then
3459 Name_Len := 0;
3460 Add_Str_To_Name_Buffer (Object_Directory_Path.all);
3461 Add_Str_To_Name_Buffer (Get_Name_String (Lib_File));
3462 Full_Lib_File := Name_Find;
3463
3464 else
3465 if Project_Of_Current_Object_Directory /=
3466 No_Project
3467 then
3468 Get_Name_String
3469 (Project_Of_Current_Object_Directory
3470 .Object_Directory.Name);
3471 Add_Str_To_Name_Buffer
3472 (Get_Name_String (Lib_File));
3473 Full_Lib_File := Name_Find;
3474
3475 else
3476 Full_Lib_File := Lib_File;
3477 end if;
3478 end if;
3479
3480 end if;
3481
3482 Lib_File_Attr := Unknown_Attributes;
3483
3484 -- Make sure we could successfully start the compilation
3485
3486 if Process_Created then
3487 if Pid = Invalid_Pid then
3488 Record_Failure (Full_Source_File, Source_Unit);
3489 else
3490 Add_Process
3491 (Pid => Pid,
3492 Sfile => Full_Source_File,
3493 Afile => Lib_File,
3494 Uname => Source_Unit,
3495 Mfile => Mfile,
3496 Full_Lib_File => Full_Lib_File,
3497 Lib_File_Attr => Lib_File_Attr);
3498 end if;
3499 end if;
3500 end if;
3501 end if;
3502 end if;
3503 end if;
3504 return False;
3505 end Start_Compile_If_Possible;
3506
3507 -----------------------------
3508 -- Wait_For_Available_Slot --
3509 -----------------------------
3510
3511 procedure Wait_For_Available_Slot is
3512 Compilation_OK : Boolean;
3513 Text : Text_Buffer_Ptr;
3514 ALI : ALI_Id;
3515 Data : Compilation_Data;
3516
3517 begin
3518 if Outstanding_Compiles = Max_Process
3519 or else (Empty_Q
3520 and then not Good_ALI_Present
3521 and then Outstanding_Compiles > 0)
3522 then
3523 Await_Compile (Data, Compilation_OK);
3524
3525 if not Compilation_OK then
3526 Record_Failure (Data.Full_Source_File, Data.Source_Unit);
3527 end if;
3528
3529 if Compilation_OK or else Keep_Going then
3530
3531 -- Re-read the updated library file
3532
3533 declare
3534 Saved_Object_Consistency : constant Boolean :=
3535 Check_Object_Consistency;
3536
3537 begin
3538 -- If compilation was not OK, or if output is not an object
3539 -- file and we don't do the bind step, don't check for
3540 -- object consistency.
3541
3542 Check_Object_Consistency :=
3543 Check_Object_Consistency
3544 and Compilation_OK
3545 and (Output_Is_Object or Do_Bind_Step);
3546
3547 Text :=
3548 Read_Library_Info_From_Full
3549 (Data.Full_Lib_File, Data.Lib_File_Attr'Access);
3550
3551 -- Restore Check_Object_Consistency to its initial value
3552
3553 Check_Object_Consistency := Saved_Object_Consistency;
3554 end;
3555
3556 -- If an ALI file was generated by this compilation, scan the
3557 -- ALI file and record it.
3558
3559 -- If the scan fails, a previous ali file is inconsistent with
3560 -- the unit just compiled.
3561
3562 if Text /= null then
3563 ALI :=
3564 Scan_ALI
3565 (Data.Lib_File, Text, Ignore_ED => False, Err => True);
3566
3567 if ALI = No_ALI_Id then
3568
3569 -- Record a failure only if not already done
3570
3571 if Compilation_OK then
3572 Inform
3573 (Data.Lib_File,
3574 "incompatible ALI file, please recompile");
3575 Record_Failure
3576 (Data.Full_Source_File, Data.Source_Unit);
3577 end if;
3578
3579 else
3580 Record_Good_ALI (ALI);
3581 end if;
3582
3583 Free (Text);
3584
3585 -- If we could not read the ALI file that was just generated
3586 -- then there could be a problem reading either the ALI or the
3587 -- corresponding object file (if Check_Object_Consistency is
3588 -- set Read_Library_Info checks that the time stamp of the
3589 -- object file is more recent than that of the ALI). However,
3590 -- we record a failure only if not already done.
3591
3592 else
3593 if Compilation_OK and not Syntax_Only then
3594 Inform
3595 (Data.Lib_File,
3596 "WARNING: ALI or object file not found after compile");
3597 Record_Failure (Data.Full_Source_File, Data.Source_Unit);
3598 end if;
3599 end if;
3600 end if;
3601 end if;
3602 end Wait_For_Available_Slot;
3603
3604 -- Start of processing for Compile_Sources
3605
3606 begin
3607 pragma Assert (Args'First = 1);
3608
3609 Outstanding_Compiles := 0;
3610 Running_Compile := new Comp_Data_Arr (1 .. Max_Process);
3611
3612 -- Package and Queue initializations
3613
3614 Good_ALI.Init;
3615
3616 if First_Q_Initialization then
3617 Init_Q;
3618 end if;
3619
3620 if Initialize_ALI_Data then
3621 Initialize_ALI;
3622 Initialize_ALI_Source;
3623 end if;
3624
3625 -- The following two flags affect the behavior of ALI.Set_Source_Table.
3626 -- We set Check_Source_Files to True to ensure that source file time
3627 -- stamps are checked, and we set All_Sources to False to avoid checking
3628 -- the presence of the source files listed in the source dependency
3629 -- section of an ali file (which would be a mistake since the ali file
3630 -- may be obsolete).
3631
3632 Check_Source_Files := True;
3633 All_Sources := False;
3634
3635 -- Only insert in the Q if it is not already done, to avoid simultaneous
3636 -- compilations if -jnnn is used.
3637
3638 if not Is_Marked (Main_Source, Main_Index) then
3639 Insert_Q (Main_Source, Index => Main_Index);
3640 Mark (Main_Source, Main_Index);
3641 end if;
3642
3643 First_Compiled_File := No_File;
3644 Most_Recent_Obj_File := No_File;
3645 Most_Recent_Obj_Stamp := Empty_Time_Stamp;
3646 Main_Unit := False;
3647
3648 -- Keep looping until there is no more work to do (the Q is empty)
3649 -- and all the outstanding compilations have terminated.
3650
3651 Make_Loop : while not Empty_Q or else Outstanding_Compiles > 0 loop
3652 exit Make_Loop when Must_Exit_Because_Of_Error;
3653 exit Make_Loop when Start_Compile_If_Possible (Args);
3654
3655 Wait_For_Available_Slot;
3656
3657 -- ??? Should be done as soon as we add a Good_ALI, wouldn't it avoid
3658 -- the need for a list of good ALI?
3659
3660 Fill_Queue_From_ALI_Files;
3661
3662 if Display_Compilation_Progress then
3663 Write_Str ("completed ");
3664 Write_Int (Int (Q_Front));
3665 Write_Str (" out of ");
3666 Write_Int (Int (Q.Last));
3667 Write_Str (" (");
3668 Write_Int (Int ((Q_Front * 100) / (Q.Last - Q.First)));
3669 Write_Str ("%)...");
3670 Write_Eol;
3671 end if;
3672 end loop Make_Loop;
3673
3674 Compilation_Failures := Bad_Compilation_Count;
3675
3676 -- Compilation is finished
3677
3678 -- Delete any temporary configuration pragma file
3679
3680 if not Debug.Debug_Flag_N then
3681 Delete_Temp_Config_Files;
3682 end if;
3683 end Compile_Sources;
3684
3685 ----------------------------------
3686 -- Configuration_Pragmas_Switch --
3687 ----------------------------------
3688
3689 function Configuration_Pragmas_Switch
3690 (For_Project : Project_Id) return Argument_List
3691 is
3692 The_Packages : Package_Id;
3693 Gnatmake : Package_Id;
3694 Compiler : Package_Id;
3695
3696 Global_Attribute : Variable_Value := Nil_Variable_Value;
3697 Local_Attribute : Variable_Value := Nil_Variable_Value;
3698
3699 Global_Attribute_Present : Boolean := False;
3700 Local_Attribute_Present : Boolean := False;
3701
3702 Result : Argument_List (1 .. 3);
3703 Last : Natural := 0;
3704
3705 function Absolute_Path
3706 (Path : Path_Name_Type;
3707 Project : Project_Id) return String;
3708 -- Returns an absolute path for a configuration pragmas file
3709
3710 -------------------
3711 -- Absolute_Path --
3712 -------------------
3713
3714 function Absolute_Path
3715 (Path : Path_Name_Type;
3716 Project : Project_Id) return String
3717 is
3718 begin
3719 Get_Name_String (Path);
3720
3721 declare
3722 Path_Name : constant String := Name_Buffer (1 .. Name_Len);
3723
3724 begin
3725 if Is_Absolute_Path (Path_Name) then
3726 return Path_Name;
3727
3728 else
3729 declare
3730 Parent_Directory : constant String :=
3731 Get_Name_String (Project.Directory.Display_Name);
3732
3733 begin
3734 if Parent_Directory (Parent_Directory'Last) =
3735 Directory_Separator
3736 then
3737 return Parent_Directory & Path_Name;
3738
3739 else
3740 return Parent_Directory & Directory_Separator & Path_Name;
3741 end if;
3742 end;
3743 end if;
3744 end;
3745 end Absolute_Path;
3746
3747 -- Start of processing for Configuration_Pragmas_Switch
3748
3749 begin
3750 Prj.Env.Create_Config_Pragmas_File
3751 (For_Project, Project_Tree);
3752
3753 if For_Project.Config_File_Name /= No_Path then
3754 Temporary_Config_File := For_Project.Config_File_Temp;
3755 Last := 1;
3756 Result (1) :=
3757 new String'
3758 ("-gnatec=" & Get_Name_String (For_Project.Config_File_Name));
3759
3760 else
3761 Temporary_Config_File := False;
3762 end if;
3763
3764 -- Check for attribute Builder'Global_Configuration_Pragmas
3765
3766 The_Packages := Main_Project.Decl.Packages;
3767 Gnatmake :=
3768 Prj.Util.Value_Of
3769 (Name => Name_Builder,
3770 In_Packages => The_Packages,
3771 In_Tree => Project_Tree);
3772
3773 if Gnatmake /= No_Package then
3774 Global_Attribute := Prj.Util.Value_Of
3775 (Variable_Name => Name_Global_Configuration_Pragmas,
3776 In_Variables => Project_Tree.Packages.Table
3777 (Gnatmake).Decl.Attributes,
3778 In_Tree => Project_Tree);
3779 Global_Attribute_Present :=
3780 Global_Attribute /= Nil_Variable_Value
3781 and then Get_Name_String (Global_Attribute.Value) /= "";
3782
3783 if Global_Attribute_Present then
3784 declare
3785 Path : constant String :=
3786 Absolute_Path
3787 (Path_Name_Type (Global_Attribute.Value),
3788 Global_Attribute.Project);
3789 begin
3790 if not Is_Regular_File (Path) then
3791 if Debug.Debug_Flag_F then
3792 Make_Failed
3793 ("cannot find configuration pragmas file "
3794 & File_Name (Path));
3795 else
3796 Make_Failed
3797 ("cannot find configuration pragmas file " & Path);
3798 end if;
3799 end if;
3800
3801 Last := Last + 1;
3802 Result (Last) := new String'("-gnatec=" & Path);
3803 end;
3804 end if;
3805 end if;
3806
3807 -- Check for attribute Compiler'Local_Configuration_Pragmas
3808
3809 The_Packages := For_Project.Decl.Packages;
3810 Compiler :=
3811 Prj.Util.Value_Of
3812 (Name => Name_Compiler,
3813 In_Packages => The_Packages,
3814 In_Tree => Project_Tree);
3815
3816 if Compiler /= No_Package then
3817 Local_Attribute := Prj.Util.Value_Of
3818 (Variable_Name => Name_Local_Configuration_Pragmas,
3819 In_Variables => Project_Tree.Packages.Table
3820 (Compiler).Decl.Attributes,
3821 In_Tree => Project_Tree);
3822 Local_Attribute_Present :=
3823 Local_Attribute /= Nil_Variable_Value
3824 and then Get_Name_String (Local_Attribute.Value) /= "";
3825
3826 if Local_Attribute_Present then
3827 declare
3828 Path : constant String :=
3829 Absolute_Path
3830 (Path_Name_Type (Local_Attribute.Value),
3831 Local_Attribute.Project);
3832 begin
3833 if not Is_Regular_File (Path) then
3834 if Debug.Debug_Flag_F then
3835 Make_Failed
3836 ("cannot find configuration pragmas file "
3837 & File_Name (Path));
3838
3839 else
3840 Make_Failed
3841 ("cannot find configuration pragmas file " & Path);
3842 end if;
3843 end if;
3844
3845 Last := Last + 1;
3846 Result (Last) := new String'("-gnatec=" & Path);
3847 end;
3848 end if;
3849 end if;
3850
3851 return Result (1 .. Last);
3852 end Configuration_Pragmas_Switch;
3853
3854 ---------------
3855 -- Debug_Msg --
3856 ---------------
3857
3858 procedure Debug_Msg (S : String; N : Name_Id) is
3859 begin
3860 if Debug.Debug_Flag_W then
3861 Write_Str (" ... ");
3862 Write_Str (S);
3863 Write_Str (" ");
3864 Write_Name (N);
3865 Write_Eol;
3866 end if;
3867 end Debug_Msg;
3868
3869 procedure Debug_Msg (S : String; N : File_Name_Type) is
3870 begin
3871 Debug_Msg (S, Name_Id (N));
3872 end Debug_Msg;
3873
3874 procedure Debug_Msg (S : String; N : Unit_Name_Type) is
3875 begin
3876 Debug_Msg (S, Name_Id (N));
3877 end Debug_Msg;
3878
3879 ---------------------------
3880 -- Delete_All_Temp_Files --
3881 ---------------------------
3882
3883 procedure Delete_All_Temp_Files is
3884 begin
3885 if not Debug.Debug_Flag_N then
3886 Delete_Temp_Config_Files;
3887 Prj.Delete_All_Temp_Files (Project_Tree);
3888 end if;
3889 end Delete_All_Temp_Files;
3890
3891 ------------------------------
3892 -- Delete_Temp_Config_Files --
3893 ------------------------------
3894
3895 procedure Delete_Temp_Config_Files is
3896 Success : Boolean;
3897 Proj : Project_List;
3898 pragma Warnings (Off, Success);
3899
3900 begin
3901 -- The caller is responsible for ensuring that Debug_Flag_N is False
3902
3903 pragma Assert (not Debug.Debug_Flag_N);
3904
3905 if Main_Project /= No_Project then
3906 Proj := Project_Tree.Projects;
3907 while Proj /= null loop
3908 if Proj.Project.Config_File_Temp then
3909 Delete_Temporary_File
3910 (Project_Tree, Proj.Project.Config_File_Name);
3911
3912 -- Make sure that we don't have a config file for this project,
3913 -- in case there are several mains. In this case, we will
3914 -- recreate another config file: we cannot reuse the one that
3915 -- we just deleted!
3916
3917 Proj.Project.Config_Checked := False;
3918 Proj.Project.Config_File_Name := No_Path;
3919 Proj.Project.Config_File_Temp := False;
3920 end if;
3921 Proj := Proj.Next;
3922 end loop;
3923 end if;
3924 end Delete_Temp_Config_Files;
3925
3926 -------------
3927 -- Display --
3928 -------------
3929
3930 procedure Display (Program : String; Args : Argument_List) is
3931 begin
3932 pragma Assert (Args'First = 1);
3933
3934 if Display_Executed_Programs then
3935 Write_Str (Program);
3936
3937 for J in Args'Range loop
3938
3939 -- Never display -gnatea nor -gnatez
3940
3941 if Args (J).all /= "-gnatea"
3942 and then
3943 Args (J).all /= "-gnatez"
3944 then
3945 -- Do not display the mapping file argument automatically
3946 -- created when using a project file.
3947
3948 if Main_Project = No_Project
3949 or else Debug.Debug_Flag_N
3950 or else Args (J)'Length < 8
3951 or else
3952 Args (J) (Args (J)'First .. Args (J)'First + 6) /= "-gnatem"
3953 then
3954 -- When -dn is not specified, do not display the config
3955 -- pragmas switch (-gnatec) for the temporary file created
3956 -- by the project manager (always the first -gnatec switch).
3957 -- Reset Temporary_Config_File to False so that the eventual
3958 -- other -gnatec switches will be displayed.
3959
3960 if (not Debug.Debug_Flag_N)
3961 and then Temporary_Config_File
3962 and then Args (J)'Length > 7
3963 and then Args (J) (Args (J)'First .. Args (J)'First + 6)
3964 = "-gnatec"
3965 then
3966 Temporary_Config_File := False;
3967
3968 -- Do not display the -F=mapping_file switch for gnatbind
3969 -- if -dn is not specified.
3970
3971 elsif Debug.Debug_Flag_N
3972 or else Args (J)'Length < 4
3973 or else
3974 Args (J) (Args (J)'First .. Args (J)'First + 2) /= "-F="
3975 then
3976 Write_Str (" ");
3977
3978 -- If -df is used, only display file names, not path
3979 -- names.
3980
3981 if Debug.Debug_Flag_F then
3982 declare
3983 Equal_Pos : Natural;
3984 begin
3985 Equal_Pos := Args (J)'First - 1;
3986 for K in Args (J)'Range loop
3987 if Args (J) (K) = '=' then
3988 Equal_Pos := K;
3989 exit;
3990 end if;
3991 end loop;
3992
3993 if Is_Absolute_Path
3994 (Args (J) (Equal_Pos + 1 .. Args (J)'Last))
3995 then
3996 Write_Str
3997 (Args (J) (Args (J)'First .. Equal_Pos));
3998 Write_Str
3999 (File_Name
4000 (Args (J)
4001 (Equal_Pos + 1 .. Args (J)'Last)));
4002
4003 else
4004 Write_Str (Args (J).all);
4005 end if;
4006 end;
4007
4008 else
4009 Write_Str (Args (J).all);
4010 end if;
4011 end if;
4012 end if;
4013 end if;
4014 end loop;
4015
4016 Write_Eol;
4017 end if;
4018 end Display;
4019
4020 ----------------------
4021 -- Display_Commands --
4022 ----------------------
4023
4024 procedure Display_Commands (Display : Boolean := True) is
4025 begin
4026 Display_Executed_Programs := Display;
4027 end Display_Commands;
4028
4029 -------------
4030 -- Empty_Q --
4031 -------------
4032
4033 function Empty_Q return Boolean is
4034 begin
4035 if Debug.Debug_Flag_P then
4036 Write_Str (" Q := [");
4037
4038 for J in Q_Front .. Q.Last - 1 loop
4039 Write_Str (" ");
4040 Write_Name (Q.Table (J).File);
4041 Write_Eol;
4042 Write_Str (" ");
4043 end loop;
4044
4045 Write_Str ("]");
4046 Write_Eol;
4047 end if;
4048
4049 return Q_Front >= Q.Last;
4050 end Empty_Q;
4051
4052 --------------------------
4053 -- Enter_Into_Obsoleted --
4054 --------------------------
4055
4056 procedure Enter_Into_Obsoleted (F : File_Name_Type) is
4057 Name : constant String := Get_Name_String (F);
4058 First : Natural;
4059 F2 : File_Name_Type;
4060
4061 begin
4062 First := Name'Last;
4063 while First > Name'First
4064 and then Name (First - 1) /= Directory_Separator
4065 and then Name (First - 1) /= '/'
4066 loop
4067 First := First - 1;
4068 end loop;
4069
4070 if First /= Name'First then
4071 Name_Len := 0;
4072 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
4073 F2 := Name_Find;
4074
4075 else
4076 F2 := F;
4077 end if;
4078
4079 Debug_Msg ("New entry in Obsoleted table:", F2);
4080 Obsoleted.Set (F2, True);
4081 end Enter_Into_Obsoleted;
4082
4083 --------------------
4084 -- Extract_From_Q --
4085 --------------------
4086
4087 procedure Extract_From_Q
4088 (Source_File : out File_Name_Type;
4089 Source_Unit : out Unit_Name_Type;
4090 Source_Index : out Int)
4091 is
4092 File : constant File_Name_Type := Q.Table (Q_Front).File;
4093 Unit : constant Unit_Name_Type := Q.Table (Q_Front).Unit;
4094 Index : constant Int := Q.Table (Q_Front).Index;
4095
4096 begin
4097 if Debug.Debug_Flag_Q then
4098 Write_Str (" Q := Q - [ ");
4099 Write_Name (File);
4100
4101 if Index /= 0 then
4102 Write_Str (", ");
4103 Write_Int (Index);
4104 end if;
4105
4106 Write_Str (" ]");
4107 Write_Eol;
4108 end if;
4109
4110 Q_Front := Q_Front + 1;
4111 Source_File := File;
4112 Source_Unit := Unit;
4113 Source_Index := Index;
4114 end Extract_From_Q;
4115
4116 --------------
4117 -- Gnatmake --
4118 --------------
4119
4120 procedure Gnatmake is
4121 Main_Source_File : File_Name_Type;
4122 -- The source file containing the main compilation unit
4123
4124 Compilation_Failures : Natural;
4125
4126 Total_Compilation_Failures : Natural := 0;
4127
4128 Is_Main_Unit : Boolean;
4129 -- Set True by Compile_Sources if Main_Source_File can be a main unit
4130
4131 Main_ALI_File : File_Name_Type;
4132 -- The ali file corresponding to Main_Source_File
4133
4134 Executable : File_Name_Type := No_File;
4135 -- The file name of an executable
4136
4137 Non_Std_Executable : Boolean := False;
4138 -- Non_Std_Executable is set to True when there is a possibility that
4139 -- the linker will not choose the correct executable file name.
4140
4141 Current_Work_Dir : constant String_Access :=
4142 new String'(Get_Current_Dir);
4143 -- The current working directory, used to modify some relative path
4144 -- switches on the command line when a project file is used.
4145
4146 Current_Main_Index : Int := 0;
4147 -- If not zero, the index of the current main unit in its source file
4148
4149 Stand_Alone_Libraries : Boolean := False;
4150 -- Set to True when there are Stand-Alone Libraries, so that gnatbind
4151 -- is invoked with the -F switch to force checking of elaboration flags.
4152
4153 Mapping_Path : Path_Name_Type := No_Path;
4154 -- The path name of the mapping file
4155
4156 Project_Node_Tree : Project_Node_Tree_Ref;
4157
4158 Discard : Boolean;
4159 pragma Warnings (Off, Discard);
4160
4161 procedure Check_Mains;
4162 -- Check that the main subprograms do exist and that they all
4163 -- belong to the same project file.
4164
4165 procedure Create_Binder_Mapping_File
4166 (Args : in out Argument_List; Last_Arg : in out Natural);
4167 -- Create a binder mapping file and add the necessary switch
4168
4169 -----------------
4170 -- Check_Mains --
4171 -----------------
4172
4173 procedure Check_Mains is
4174 Real_Main_Project : Project_Id := No_Project;
4175 -- The project of the first main
4176
4177 Proj : Project_Id := No_Project;
4178 -- The project of the current main
4179
4180 Real_Path : String_Access;
4181
4182 begin
4183 Mains.Reset;
4184
4185 -- Check each main
4186
4187 loop
4188 declare
4189 Main : constant String := Mains.Next_Main;
4190 -- The name specified on the command line may include directory
4191 -- information.
4192
4193 File_Name : constant String := Base_Name (Main);
4194 -- The simple file name of the current main
4195
4196 Lang : Language_Ptr;
4197
4198 begin
4199 exit when Main = "";
4200
4201 -- Get the project of the current main
4202
4203 Proj := Prj.Env.Project_Of
4204 (File_Name, Main_Project, Project_Tree);
4205
4206 -- Fail if the current main is not a source of a project
4207
4208 if Proj = No_Project then
4209 Make_Failed
4210 ("""" & Main & """ is not a source of any project");
4211
4212 else
4213 -- If there is directory information, check that the source
4214 -- exists and, if it does, that the path is the actual path
4215 -- of a source of a project.
4216
4217 if Main /= File_Name then
4218 Lang := Get_Language_From_Name (Main_Project, "ada");
4219
4220 Real_Path :=
4221 Locate_Regular_File
4222 (Main & Get_Name_String
4223 (Lang.Config.Naming_Data.Body_Suffix),
4224 "");
4225 if Real_Path = null then
4226 Real_Path :=
4227 Locate_Regular_File
4228 (Main & Get_Name_String
4229 (Lang.Config.Naming_Data.Spec_Suffix),
4230 "");
4231 end if;
4232
4233 if Real_Path = null then
4234 Real_Path := Locate_Regular_File (Main, "");
4235 end if;
4236
4237 -- Fail if the file cannot be found
4238
4239 if Real_Path = null then
4240 Make_Failed ("file """ & Main & """ does not exist");
4241 end if;
4242
4243 declare
4244 Project_Path : constant String :=
4245 Prj.Env.File_Name_Of_Library_Unit_Body
4246 (Name => File_Name,
4247 Project => Main_Project,
4248 In_Tree => Project_Tree,
4249 Main_Project_Only => False,
4250 Full_Path => True);
4251 Normed_Path : constant String :=
4252 Normalize_Pathname
4253 (Real_Path.all,
4254 Case_Sensitive => False);
4255 Proj_Path : constant String :=
4256 Normalize_Pathname
4257 (Project_Path,
4258 Case_Sensitive => False);
4259
4260 begin
4261 Free (Real_Path);
4262
4263 -- Fail if it is not the correct path
4264
4265 if Normed_Path /= Proj_Path then
4266 if Verbose_Mode then
4267 Set_Standard_Error;
4268 Write_Str (Normed_Path);
4269 Write_Str (" /= ");
4270 Write_Line (Proj_Path);
4271 end if;
4272
4273 Make_Failed
4274 ("""" & Main &
4275 """ is not a source of any project");
4276 end if;
4277 end;
4278 end if;
4279
4280 if not Unique_Compile then
4281
4282 -- Record the project, if it is the first main
4283
4284 if Real_Main_Project = No_Project then
4285 Real_Main_Project := Proj;
4286
4287 elsif Proj /= Real_Main_Project then
4288
4289 -- Fail, as the current main is not a source of the
4290 -- same project as the first main.
4291
4292 Make_Failed
4293 ("""" & Main &
4294 """ is not a source of project " &
4295 Get_Name_String (Real_Main_Project.Name));
4296 end if;
4297 end if;
4298 end if;
4299
4300 -- If -u and -U are not used, we may have mains that are
4301 -- sources of a project that is not the one specified with
4302 -- switch -P.
4303
4304 if not Unique_Compile then
4305 Main_Project := Real_Main_Project;
4306 end if;
4307 end;
4308 end loop;
4309 end Check_Mains;
4310
4311 --------------------------------
4312 -- Create_Binder_Mapping_File --
4313 --------------------------------
4314
4315 procedure Create_Binder_Mapping_File
4316 (Args : in out Argument_List; Last_Arg : in out Natural)
4317 is
4318 Mapping_FD : File_Descriptor := Invalid_FD;
4319 -- A File Descriptor for an eventual mapping file
4320
4321 ALI_Unit : Unit_Name_Type := No_Unit_Name;
4322 -- The unit name of an ALI file
4323
4324 ALI_Name : File_Name_Type := No_File;
4325 -- The file name of the ALI file
4326
4327 ALI_Project : Project_Id := No_Project;
4328 -- The project of the ALI file
4329
4330 Bytes : Integer;
4331 OK : Boolean := True;
4332 Unit : Unit_Index;
4333
4334 Status : Boolean;
4335 -- For call to Close
4336
4337 begin
4338 Tempdir.Create_Temp_File (Mapping_FD, Mapping_Path);
4339 Record_Temp_File (Project_Tree, Mapping_Path);
4340
4341 if Mapping_FD /= Invalid_FD then
4342
4343 -- Traverse all units
4344
4345 Unit := Units_Htable.Get_First (Project_Tree.Units_HT);
4346
4347 while Unit /= No_Unit_Index loop
4348 if Unit.Name /= No_Name then
4349
4350 -- If there is a body, put it in the mapping
4351
4352 if Unit.File_Names (Impl) /= No_Source
4353 and then Unit.File_Names (Impl).Project /=
4354 No_Project
4355 then
4356 Get_Name_String (Unit.Name);
4357 Add_Str_To_Name_Buffer ("%b");
4358 ALI_Unit := Name_Find;
4359 ALI_Name :=
4360 Lib_File_Name
4361 (Unit.File_Names (Impl).Display_File);
4362 ALI_Project := Unit.File_Names (Impl).Project;
4363
4364 -- Otherwise, if there is a spec, put it in the mapping
4365
4366 elsif Unit.File_Names (Spec) /= No_Source
4367 and then Unit.File_Names (Spec).Project /= No_Project
4368 then
4369 Get_Name_String (Unit.Name);
4370 Add_Str_To_Name_Buffer ("%s");
4371 ALI_Unit := Name_Find;
4372 ALI_Name :=
4373 Lib_File_Name
4374 (Unit.File_Names (Spec).Display_File);
4375 ALI_Project := Unit.File_Names (Spec).Project;
4376
4377 else
4378 ALI_Name := No_File;
4379 end if;
4380
4381 -- If we have something to put in the mapping then do it
4382 -- now. However, if the project is extended, we don't put
4383 -- anything in the mapping file, because we don't know where
4384 -- the ALI file is: it might be in the extended project
4385 -- object directory as well as in the extending project
4386 -- object directory.
4387
4388 if ALI_Name /= No_File
4389 and then ALI_Project.Extended_By = No_Project
4390 and then ALI_Project.Extends = No_Project
4391 then
4392 -- First check if the ALI file exists. If it does not,
4393 -- do not put the unit in the mapping file.
4394
4395 declare
4396 ALI : constant String := Get_Name_String (ALI_Name);
4397
4398 begin
4399 -- For library projects, use the library directory,
4400 -- for other projects, use the object directory.
4401
4402 if ALI_Project.Library then
4403 Get_Name_String (ALI_Project.Library_Dir.Name);
4404 else
4405 Get_Name_String
4406 (ALI_Project.Object_Directory.Name);
4407 end if;
4408
4409 if not
4410 Is_Directory_Separator (Name_Buffer (Name_Len))
4411 then
4412 Add_Char_To_Name_Buffer (Directory_Separator);
4413 end if;
4414
4415 Add_Str_To_Name_Buffer (ALI);
4416 Add_Char_To_Name_Buffer (ASCII.LF);
4417
4418 declare
4419 ALI_Path_Name : constant String :=
4420 Name_Buffer (1 .. Name_Len);
4421
4422 begin
4423 if Is_Regular_File
4424 (ALI_Path_Name (1 .. ALI_Path_Name'Last - 1))
4425 then
4426 -- First line is the unit name
4427
4428 Get_Name_String (ALI_Unit);
4429 Add_Char_To_Name_Buffer (ASCII.LF);
4430 Bytes :=
4431 Write
4432 (Mapping_FD,
4433 Name_Buffer (1)'Address,
4434 Name_Len);
4435 OK := Bytes = Name_Len;
4436
4437 exit when not OK;
4438
4439 -- Second line it the ALI file name
4440
4441 Get_Name_String (ALI_Name);
4442 Add_Char_To_Name_Buffer (ASCII.LF);
4443 Bytes :=
4444 Write
4445 (Mapping_FD,
4446 Name_Buffer (1)'Address,
4447 Name_Len);
4448 OK := (Bytes = Name_Len);
4449
4450 exit when not OK;
4451
4452 -- Third line it the ALI path name
4453
4454 Bytes :=
4455 Write
4456 (Mapping_FD,
4457 ALI_Path_Name (1)'Address,
4458 ALI_Path_Name'Length);
4459 OK := (Bytes = ALI_Path_Name'Length);
4460
4461 -- If OK is False, it means we were unable to
4462 -- write a line. No point in continuing with the
4463 -- other units.
4464
4465 exit when not OK;
4466 end if;
4467 end;
4468 end;
4469 end if;
4470 end if;
4471
4472 Unit := Units_Htable.Get_Next (Project_Tree.Units_HT);
4473 end loop;
4474
4475 Close (Mapping_FD, Status);
4476
4477 OK := OK and Status;
4478
4479 -- If the creation of the mapping file was successful, we add the
4480 -- switch to the arguments of gnatbind.
4481
4482 if OK then
4483 Last_Arg := Last_Arg + 1;
4484 Args (Last_Arg) :=
4485 new String'("-F=" & Get_Name_String (Mapping_Path));
4486 end if;
4487 end if;
4488 end Create_Binder_Mapping_File;
4489
4490 -- Start of processing for Gnatmake
4491
4492 -- This body is very long, should be broken down???
4493
4494 begin
4495 Install_Int_Handler (Sigint_Intercepted'Access);
4496
4497 Do_Compile_Step := True;
4498 Do_Bind_Step := True;
4499 Do_Link_Step := True;
4500
4501 Obsoleted.Reset;
4502
4503 Make.Initialize (Project_Node_Tree);
4504
4505 Bind_Shared := No_Shared_Switch'Access;
4506 Link_With_Shared_Libgcc := No_Shared_Libgcc_Switch'Access;
4507
4508 Failed_Links.Set_Last (0);
4509 Successful_Links.Set_Last (0);
4510
4511 -- Special case when switch -B was specified
4512
4513 if Build_Bind_And_Link_Full_Project then
4514
4515 -- When switch -B is specified, there must be a project file
4516
4517 if Main_Project = No_Project then
4518 Make_Failed ("-B cannot be used without a project file");
4519
4520 -- No main program may be specified on the command line
4521
4522 elsif Osint.Number_Of_Files /= 0 then
4523 Make_Failed ("-B cannot be used with a main specified on " &
4524 "the command line");
4525
4526 -- And the project file cannot be a library project file
4527
4528 elsif Main_Project.Library then
4529 Make_Failed ("-B cannot be used for a library project file");
4530
4531 else
4532 No_Main_Subprogram := True;
4533 Insert_Project_Sources
4534 (The_Project => Main_Project,
4535 All_Projects => Unique_Compile_All_Projects,
4536 Into_Q => False);
4537
4538 -- If there are no sources to compile, we fail
4539
4540 if Osint.Number_Of_Files = 0 then
4541 Make_Failed ("no sources to compile");
4542 end if;
4543
4544 -- Specify -n for gnatbind and add the ALI files of all the
4545 -- sources, except the one which is a fake main subprogram: this
4546 -- is the one for the binder generated file and it will be
4547 -- transmitted to gnatlink. These sources are those that are in
4548 -- the queue.
4549
4550 Add_Switch ("-n", Binder, And_Save => True);
4551
4552 for J in Q.First .. Q.Last - 1 loop
4553 Add_Switch
4554 (Get_Name_String
4555 (Lib_File_Name (Q.Table (J).File)),
4556 Binder, And_Save => True);
4557 end loop;
4558 end if;
4559
4560 elsif Main_Index /= 0 and then Osint.Number_Of_Files > 1 then
4561 Make_Failed ("cannot specify several mains with a multi-unit index");
4562
4563 elsif Main_Project /= No_Project then
4564
4565 -- If the main project file is a library project file, main(s) cannot
4566 -- be specified on the command line.
4567
4568 if Osint.Number_Of_Files /= 0 then
4569 if Main_Project.Library
4570 and then not Unique_Compile
4571 and then ((not Make_Steps) or else Bind_Only or else Link_Only)
4572 then
4573 Make_Failed ("cannot specify a main program " &
4574 "on the command line for a library project file");
4575
4576 else
4577 -- Check that each main on the command line is a source of a
4578 -- project file and, if there are several mains, each of them
4579 -- is a source of the same project file.
4580
4581 Check_Mains;
4582 end if;
4583
4584 -- If no mains have been specified on the command line, and we are
4585 -- using a project file, we either find the main(s) in attribute Main
4586 -- of the main project, or we put all the sources of the project file
4587 -- as mains.
4588
4589 else
4590 if Main_Index /= 0 then
4591 Make_Failed ("cannot specify a multi-unit index but no main " &
4592 "on the command line");
4593 end if;
4594
4595 declare
4596 Value : String_List_Id := Main_Project.Mains;
4597
4598 begin
4599 -- The attribute Main is an empty list or not specified, or
4600 -- else gnatmake was invoked with the switch "-u".
4601
4602 if Value = Prj.Nil_String or else Unique_Compile then
4603
4604 if (not Make_Steps) or else Compile_Only
4605 or else not Main_Project.Library
4606 then
4607 -- First make sure that the binder and the linker will
4608 -- not be invoked.
4609
4610 Do_Bind_Step := False;
4611 Do_Link_Step := False;
4612
4613 -- Put all the sources in the queue
4614
4615 No_Main_Subprogram := True;
4616 Insert_Project_Sources
4617 (The_Project => Main_Project,
4618 All_Projects => Unique_Compile_All_Projects,
4619 Into_Q => False);
4620
4621 -- If no sources to compile, then there is nothing to do
4622
4623 if Osint.Number_Of_Files = 0 then
4624 if not Quiet_Output then
4625 Osint.Write_Program_Name;
4626 Write_Line (": no sources to compile");
4627 end if;
4628
4629 Delete_All_Temp_Files;
4630 Exit_Program (E_Success);
4631 end if;
4632 end if;
4633
4634 else
4635 -- The attribute Main is not an empty list. Put all the main
4636 -- subprograms in the list as if they were specified on the
4637 -- command line. However, if attribute Languages includes a
4638 -- language other than Ada, only include the Ada mains; if
4639 -- there is no Ada main, compile all sources of the project.
4640
4641 declare
4642 Languages : constant Variable_Value :=
4643 Prj.Util.Value_Of
4644 (Name_Languages,
4645 Main_Project.Decl.Attributes,
4646 Project_Tree);
4647
4648 Current : String_List_Id;
4649 Element : String_Element;
4650
4651 Foreign_Language : Boolean := False;
4652 At_Least_One_Main : Boolean := False;
4653
4654 begin
4655 -- First, determine if there is a foreign language in
4656 -- attribute Languages.
4657
4658 if not Languages.Default then
4659 Current := Languages.Values;
4660 Look_For_Foreign :
4661 while Current /= Nil_String loop
4662 Element := Project_Tree.String_Elements.
4663 Table (Current);
4664 Get_Name_String (Element.Value);
4665 To_Lower (Name_Buffer (1 .. Name_Len));
4666
4667 if Name_Buffer (1 .. Name_Len) /= "ada" then
4668 Foreign_Language := True;
4669 exit Look_For_Foreign;
4670 end if;
4671
4672 Current := Element.Next;
4673 end loop Look_For_Foreign;
4674 end if;
4675
4676 -- Then, find all mains, or if there is a foreign
4677 -- language, all the Ada mains.
4678
4679 while Value /= Prj.Nil_String loop
4680 Get_Name_String
4681 (Project_Tree.String_Elements.Table (Value).Value);
4682
4683 -- To know if a main is an Ada main, get its project.
4684 -- It should be the project specified on the command
4685 -- line.
4686
4687 if (not Foreign_Language) or else
4688 Prj.Env.Project_Of
4689 (Name_Buffer (1 .. Name_Len),
4690 Main_Project,
4691 Project_Tree) =
4692 Main_Project
4693 then
4694 At_Least_One_Main := True;
4695 Osint.Add_File
4696 (Get_Name_String
4697 (Project_Tree.String_Elements.Table
4698 (Value).Value),
4699 Index =>
4700 Project_Tree.String_Elements.Table
4701 (Value).Index);
4702 end if;
4703
4704 Value := Project_Tree.String_Elements.Table
4705 (Value).Next;
4706 end loop;
4707
4708 -- If we did not get any main, it means that all mains
4709 -- in attribute Mains are in a foreign language and -B
4710 -- was not specified to gnatmake; so, we fail.
4711
4712 if not At_Least_One_Main then
4713 Make_Failed
4714 ("no Ada mains, use -B to build foreign main");
4715 end if;
4716 end;
4717
4718 end if;
4719 end;
4720 end if;
4721 end if;
4722
4723 if Verbose_Mode then
4724 Write_Eol;
4725 Display_Version ("GNATMAKE", "1995");
4726 end if;
4727
4728 if Main_Project /= No_Project
4729 and then Main_Project.Externally_Built
4730 then
4731 Make_Failed
4732 ("nothing to do for a main project that is externally built");
4733 end if;
4734
4735 if Osint.Number_Of_Files = 0 then
4736 if Main_Project /= No_Project
4737 and then Main_Project.Library
4738 then
4739 if Do_Bind_Step
4740 and then not Main_Project.Standalone_Library
4741 then
4742 Make_Failed ("only stand-alone libraries may be bound");
4743 end if;
4744
4745 -- Add the default search directories to be able to find libgnat
4746
4747 Osint.Add_Default_Search_Dirs;
4748
4749 -- Get the target parameters, so that the correct binder generated
4750 -- files are generated if OpenVMS is the target.
4751
4752 begin
4753 Targparm.Get_Target_Parameters;
4754
4755 exception
4756 when Unrecoverable_Error =>
4757 Make_Failed ("*** make failed.");
4758 end;
4759
4760 -- And bind and or link the library
4761
4762 MLib.Prj.Build_Library
4763 (For_Project => Main_Project,
4764 In_Tree => Project_Tree,
4765 Gnatbind => Gnatbind.all,
4766 Gnatbind_Path => Gnatbind_Path,
4767 Gcc => Gcc.all,
4768 Gcc_Path => Gcc_Path,
4769 Bind => Bind_Only,
4770 Link => Link_Only);
4771
4772 Delete_All_Temp_Files;
4773 Exit_Program (E_Success);
4774
4775 else
4776 -- Call Get_Target_Parameters to ensure that VM_Target and
4777 -- AAMP_On_Target get set before calling Usage.
4778
4779 Targparm.Get_Target_Parameters;
4780
4781 -- Output usage information if no files to compile
4782
4783 Usage;
4784 Exit_Program (E_Fatal);
4785 end if;
4786 end if;
4787
4788 -- If -M was specified, behave as if -n was specified
4789
4790 if List_Dependencies then
4791 Do_Not_Execute := True;
4792 end if;
4793
4794 -- Note that Osint.M.Next_Main_Source will always return the (possibly
4795 -- abbreviated file) without any directory information.
4796
4797 Main_Source_File := Next_Main_Source;
4798
4799 if Current_File_Index /= No_Index then
4800 Main_Index := Current_File_Index;
4801 end if;
4802
4803 Add_Switch ("-I-", Compiler, And_Save => True);
4804
4805 if Main_Project = No_Project then
4806 if Look_In_Primary_Dir then
4807
4808 Add_Switch
4809 ("-I" &
4810 Normalize_Directory_Name
4811 (Get_Primary_Src_Search_Directory.all).all,
4812 Compiler, Append_Switch => False,
4813 And_Save => False);
4814
4815 end if;
4816
4817 else
4818 -- If we use a project file, we have already checked that a main
4819 -- specified on the command line with directory information has the
4820 -- path name corresponding to a correct source in the project tree.
4821 -- So, we don't need the directory information to be taken into
4822 -- account by Find_File, and in fact it may lead to take the wrong
4823 -- sources for other compilation units, when there are extending
4824 -- projects.
4825
4826 Look_In_Primary_Dir := False;
4827 Add_Switch ("-I-", Binder, And_Save => True);
4828 end if;
4829
4830 -- If the user wants a program without a main subprogram, add the
4831 -- appropriate switch to the binder.
4832
4833 if No_Main_Subprogram then
4834 Add_Switch ("-z", Binder, And_Save => True);
4835 end if;
4836
4837 if Main_Project /= No_Project then
4838
4839 if Main_Project.Object_Directory /= No_Path_Information then
4840 -- Change current directory to object directory of main project
4841
4842 Project_Of_Current_Object_Directory := No_Project;
4843 Change_To_Object_Directory (Main_Project);
4844 end if;
4845
4846 -- Source file lookups should be cached for efficiency.
4847 -- Source files are not supposed to change.
4848
4849 Osint.Source_File_Data (Cache => True);
4850
4851 -- Find the file name of the (first) main unit
4852
4853 declare
4854 Main_Source_File_Name : constant String :=
4855 Get_Name_String (Main_Source_File);
4856 Main_Unit_File_Name : constant String :=
4857 Prj.Env.File_Name_Of_Library_Unit_Body
4858 (Name => Main_Source_File_Name,
4859 Project => Main_Project,
4860 In_Tree => Project_Tree,
4861 Main_Project_Only =>
4862 not Unique_Compile);
4863
4864 The_Packages : constant Package_Id :=
4865 Main_Project.Decl.Packages;
4866
4867 Builder_Package : constant Prj.Package_Id :=
4868 Prj.Util.Value_Of
4869 (Name => Name_Builder,
4870 In_Packages => The_Packages,
4871 In_Tree => Project_Tree);
4872
4873 Binder_Package : constant Prj.Package_Id :=
4874 Prj.Util.Value_Of
4875 (Name => Name_Binder,
4876 In_Packages => The_Packages,
4877 In_Tree => Project_Tree);
4878
4879 Linker_Package : constant Prj.Package_Id :=
4880 Prj.Util.Value_Of
4881 (Name => Name_Linker,
4882 In_Packages => The_Packages,
4883 In_Tree => Project_Tree);
4884
4885 Default_Switches_Array : Array_Id;
4886
4887 Global_Compilation_Array : Array_Element_Id;
4888 Global_Compilation_Elem : Array_Element;
4889 Global_Compilation_Switches : Variable_Value;
4890
4891 begin
4892 -- We fail if we cannot find the main source file
4893
4894 if Main_Unit_File_Name = "" then
4895 Make_Failed ('"' & Main_Source_File_Name
4896 & """ is not a unit of project "
4897 & Project_File_Name.all & ".");
4898 else
4899 -- Remove any directory information from the main source file
4900 -- file name.
4901
4902 declare
4903 Pos : Natural := Main_Unit_File_Name'Last;
4904
4905 begin
4906 loop
4907 exit when Pos < Main_Unit_File_Name'First or else
4908 Main_Unit_File_Name (Pos) = Directory_Separator;
4909 Pos := Pos - 1;
4910 end loop;
4911
4912 Name_Len := Main_Unit_File_Name'Last - Pos;
4913
4914 Name_Buffer (1 .. Name_Len) :=
4915 Main_Unit_File_Name
4916 (Pos + 1 .. Main_Unit_File_Name'Last);
4917
4918 Main_Source_File := Name_Find;
4919
4920 -- We only output the main source file if there is only one
4921
4922 if Verbose_Mode and then Osint.Number_Of_Files = 1 then
4923 Write_Str ("Main source file: """);
4924 Write_Str (Main_Unit_File_Name
4925 (Pos + 1 .. Main_Unit_File_Name'Last));
4926 Write_Line (""".");
4927 end if;
4928 end;
4929 end if;
4930
4931 -- If there is a package Builder in the main project file, add
4932 -- the switches from it.
4933
4934 if Builder_Package /= No_Package then
4935
4936 Global_Compilation_Array := Prj.Util.Value_Of
4937 (Name => Name_Global_Compilation_Switches,
4938 In_Arrays => Project_Tree.Packages.Table
4939 (Builder_Package).Decl.Arrays,
4940 In_Tree => Project_Tree);
4941
4942 Default_Switches_Array :=
4943 Project_Tree.Packages.Table
4944 (Builder_Package).Decl.Arrays;
4945
4946 while Default_Switches_Array /= No_Array and then
4947 Project_Tree.Arrays.Table (Default_Switches_Array).Name /=
4948 Name_Default_Switches
4949 loop
4950 Default_Switches_Array :=
4951 Project_Tree.Arrays.Table (Default_Switches_Array).Next;
4952 end loop;
4953
4954 if Global_Compilation_Array /= No_Array_Element and then
4955 Default_Switches_Array /= No_Array
4956 then
4957 Errutil.Error_Msg
4958 ("Default_Switches forbidden in presence of " &
4959 "Global_Compilation_Switches. Use Switches instead.",
4960 Project_Tree.Arrays.Table
4961 (Default_Switches_Array).Location);
4962 Errutil.Finalize;
4963 Make_Failed
4964 ("*** illegal combination of Builder attributes");
4965 end if;
4966
4967 -- If there is only one main, we attempt to get the gnatmake
4968 -- switches for this main (if any). If there are no specific
4969 -- switch for this particular main, get the general gnatmake
4970 -- switches (if any).
4971
4972 if Osint.Number_Of_Files = 1 then
4973 if Verbose_Mode then
4974 Write_Str ("Adding gnatmake switches for """);
4975 Write_Str (Main_Unit_File_Name);
4976 Write_Line (""".");
4977 end if;
4978
4979 Add_Switches
4980 (Project_Node_Tree => Project_Node_Tree,
4981 File_Name => Main_Unit_File_Name,
4982 Index => Main_Index,
4983 The_Package => Builder_Package,
4984 Program => None,
4985 Unknown_Switches_To_The_Compiler =>
4986 Global_Compilation_Array = No_Array_Element);
4987
4988 else
4989 -- If there are several mains, we always get the general
4990 -- gnatmake switches (if any).
4991
4992 -- Warn the user, if necessary, so that he is not surprised
4993 -- that specific switches are not taken into account.
4994
4995 declare
4996 Defaults : constant Variable_Value :=
4997 Prj.Util.Value_Of
4998 (Name => Name_Ada,
4999 Index => 0,
5000 Attribute_Or_Array_Name =>
5001 Name_Default_Switches,
5002 In_Package =>
5003 Builder_Package,
5004 In_Tree => Project_Tree);
5005
5006 Switches : constant Array_Element_Id :=
5007 Prj.Util.Value_Of
5008 (Name => Name_Switches,
5009 In_Arrays =>
5010 Project_Tree.Packages.Table
5011 (Builder_Package).Decl.Arrays,
5012 In_Tree => Project_Tree);
5013
5014 Other_Switches : constant Variable_Value :=
5015 Prj.Util.Value_Of
5016 (Name => All_Other_Names,
5017 Index => 0,
5018 Attribute_Or_Array_Name
5019 => Name_Switches,
5020 In_Package => Builder_Package,
5021 In_Tree => Project_Tree);
5022
5023 begin
5024 if Other_Switches /= Nil_Variable_Value then
5025 if not Quiet_Output
5026 and then Switches /= No_Array_Element
5027 and then Project_Tree.Array_Elements.Table
5028 (Switches).Next /= No_Array_Element
5029 then
5030 Write_Line
5031 ("Warning: using Builder'Switches(others), "
5032 & "as there are several mains");
5033 end if;
5034
5035 Add_Switches
5036 (Project_Node_Tree => Project_Node_Tree,
5037 File_Name => " ",
5038 Index => 0,
5039 The_Package => Builder_Package,
5040 Program => None,
5041 Unknown_Switches_To_The_Compiler => False);
5042
5043 elsif Defaults /= Nil_Variable_Value then
5044 if not Quiet_Output
5045 and then Switches /= No_Array_Element
5046 then
5047 Write_Line
5048 ("Warning: using Builder'Default_Switches"
5049 & "(""Ada""), as there are several mains");
5050 end if;
5051
5052 Add_Switches
5053 (Project_Node_Tree => Project_Node_Tree,
5054 File_Name => " ",
5055 Index => 0,
5056 The_Package => Builder_Package,
5057 Program => None);
5058
5059 elsif not Quiet_Output
5060 and then Switches /= No_Array_Element
5061 then
5062 Write_Line
5063 ("Warning: using no switches from package "
5064 & "Builder, as there are several mains");
5065 end if;
5066 end;
5067 end if;
5068
5069 -- Take into account attribute Global_Compilation_Switches
5070 -- ("Ada").
5071
5072 declare
5073 Index : Name_Id;
5074 List : String_List_Id;
5075 Elem : String_Element;
5076
5077 begin
5078 while Global_Compilation_Array /= No_Array_Element loop
5079 Global_Compilation_Elem :=
5080 Project_Tree.Array_Elements.Table
5081 (Global_Compilation_Array);
5082
5083 Get_Name_String (Global_Compilation_Elem.Index);
5084 To_Lower (Name_Buffer (1 .. Name_Len));
5085 Index := Name_Find;
5086
5087 if Index = Name_Ada then
5088 Global_Compilation_Switches :=
5089 Global_Compilation_Elem.Value;
5090
5091 if Global_Compilation_Switches /= Nil_Variable_Value
5092 and then not Global_Compilation_Switches.Default
5093 then
5094 -- We have found attribute
5095 -- Global_Compilation_Switches ("Ada"): put the
5096 -- switches in the appropriate table.
5097
5098 List := Global_Compilation_Switches.Values;
5099
5100 while List /= Nil_String loop
5101 Elem :=
5102 Project_Tree.String_Elements.Table (List);
5103
5104 if Elem.Value /= No_Name then
5105 Add_Switch
5106 (Get_Name_String (Elem.Value),
5107 Compiler,
5108 And_Save => False);
5109 end if;
5110
5111 List := Elem.Next;
5112 end loop;
5113
5114 exit;
5115 end if;
5116 end if;
5117
5118 Global_Compilation_Array := Global_Compilation_Elem.Next;
5119 end loop;
5120 end;
5121 end if;
5122
5123 Osint.Add_Default_Search_Dirs;
5124
5125 -- Record the current last switch index for table Binder_Switches
5126 -- and Linker_Switches, so that these tables may be reset before
5127 -- for each main, before adding switches from the project file
5128 -- and from the command line.
5129
5130 Last_Binder_Switch := Binder_Switches.Last;
5131 Last_Linker_Switch := Linker_Switches.Last;
5132
5133 Check_Steps;
5134
5135 -- Add binder switches from the project file for the first main
5136
5137 if Do_Bind_Step and then Binder_Package /= No_Package then
5138 if Verbose_Mode then
5139 Write_Str ("Adding binder switches for """);
5140 Write_Str (Main_Unit_File_Name);
5141 Write_Line (""".");
5142 end if;
5143
5144 Add_Switches
5145 (Project_Node_Tree => Project_Node_Tree,
5146 File_Name => Main_Unit_File_Name,
5147 Index => Main_Index,
5148 The_Package => Binder_Package,
5149 Program => Binder);
5150 end if;
5151
5152 -- Add linker switches from the project file for the first main
5153
5154 if Do_Link_Step and then Linker_Package /= No_Package then
5155 if Verbose_Mode then
5156 Write_Str ("Adding linker switches for""");
5157 Write_Str (Main_Unit_File_Name);
5158 Write_Line (""".");
5159 end if;
5160
5161 Add_Switches
5162 (Project_Node_Tree => Project_Node_Tree,
5163 File_Name => Main_Unit_File_Name,
5164 Index => Main_Index,
5165 The_Package => Linker_Package,
5166 Program => Linker);
5167 end if;
5168 end;
5169 end if;
5170
5171 -- Get the target parameters, which are only needed for a couple of
5172 -- cases in gnatmake. Protect against an exception, such as the case of
5173 -- system.ads missing from the library, and fail gracefully.
5174
5175 begin
5176 Targparm.Get_Target_Parameters;
5177 exception
5178 when Unrecoverable_Error =>
5179 Make_Failed ("*** make failed.");
5180 end;
5181
5182 -- Special processing for VM targets
5183
5184 if Targparm.VM_Target /= No_VM then
5185
5186 -- Set proper processing commands
5187
5188 case Targparm.VM_Target is
5189 when Targparm.JVM_Target =>
5190
5191 -- Do not check for an object file (".o") when compiling to
5192 -- JVM machine since ".class" files are generated instead.
5193
5194 Check_Object_Consistency := False;
5195 Gcc := new String'("jvm-gnatcompile");
5196
5197 when Targparm.CLI_Target =>
5198 Gcc := new String'("dotnet-gnatcompile");
5199
5200 when Targparm.No_VM =>
5201 raise Program_Error;
5202 end case;
5203 end if;
5204
5205 Display_Commands (not Quiet_Output);
5206
5207 Check_Steps;
5208
5209 if Main_Project /= No_Project then
5210
5211 -- For all library project, if the library file does not exist, put
5212 -- all the project sources in the queue, and flag the project so that
5213 -- the library is generated.
5214
5215 if not Unique_Compile
5216 and then MLib.Tgt.Support_For_Libraries /= Prj.None
5217 then
5218 declare
5219 Proj : Project_List;
5220
5221 begin
5222 Proj := Project_Tree.Projects;
5223 while Proj /= null loop
5224 if Proj.Project.Library then
5225 Proj.Project.Need_To_Build_Lib :=
5226 not MLib.Tgt.Library_Exists_For
5227 (Proj.Project, Project_Tree)
5228 and then not Proj.Project.Externally_Built;
5229
5230 if Proj.Project.Need_To_Build_Lib then
5231
5232 -- If there is no object directory, then it will be
5233 -- impossible to build the library. So fail
5234 -- immediately.
5235
5236 if
5237 Proj.Project.Object_Directory = No_Path_Information
5238 then
5239 Make_Failed
5240 ("no object files to build library for project """
5241 & Get_Name_String (Proj.Project.Name)
5242 & """");
5243 Proj.Project.Need_To_Build_Lib := False;
5244
5245 else
5246 if Verbose_Mode then
5247 Write_Str
5248 ("Library file does not exist for project """);
5249 Write_Str (Get_Name_String (Proj.Project.Name));
5250 Write_Line ("""");
5251 end if;
5252
5253 Insert_Project_Sources
5254 (The_Project => Proj.Project,
5255 All_Projects => False,
5256 Into_Q => True);
5257 end if;
5258 end if;
5259 end if;
5260
5261 Proj := Proj.Next;
5262 end loop;
5263 end;
5264 end if;
5265
5266 -- If a relative path output file has been specified, we add the
5267 -- exec directory.
5268
5269 for J in reverse 1 .. Saved_Linker_Switches.Last - 1 loop
5270 if Saved_Linker_Switches.Table (J).all = Output_Flag.all then
5271 declare
5272 Exec_File_Name : constant String :=
5273 Saved_Linker_Switches.Table (J + 1).all;
5274
5275 begin
5276 if not Is_Absolute_Path (Exec_File_Name) then
5277 Get_Name_String (Main_Project.Exec_Directory.Name);
5278
5279 if not
5280 Is_Directory_Separator (Name_Buffer (Name_Len))
5281 then
5282 Add_Char_To_Name_Buffer (Directory_Separator);
5283 end if;
5284
5285 Add_Str_To_Name_Buffer (Exec_File_Name);
5286 Saved_Linker_Switches.Table (J + 1) :=
5287 new String'(Name_Buffer (1 .. Name_Len));
5288 end if;
5289 end;
5290
5291 exit;
5292 end if;
5293 end loop;
5294
5295 -- If we are using a project file, for relative paths we add the
5296 -- current working directory for any relative path on the command
5297 -- line and the project directory, for any relative path in the
5298 -- project file.
5299
5300 declare
5301 Dir_Path : constant String :=
5302 Get_Name_String (Main_Project.Directory.Name);
5303 begin
5304 for J in 1 .. Binder_Switches.Last loop
5305 Test_If_Relative_Path
5306 (Binder_Switches.Table (J),
5307 Parent => Dir_Path, Including_L_Switch => False);
5308 end loop;
5309
5310 for J in 1 .. Saved_Binder_Switches.Last loop
5311 Test_If_Relative_Path
5312 (Saved_Binder_Switches.Table (J),
5313 Parent => Current_Work_Dir.all, Including_L_Switch => False);
5314 end loop;
5315
5316 for J in 1 .. Linker_Switches.Last loop
5317 Test_If_Relative_Path
5318 (Linker_Switches.Table (J), Parent => Dir_Path);
5319 end loop;
5320
5321 for J in 1 .. Saved_Linker_Switches.Last loop
5322 Test_If_Relative_Path
5323 (Saved_Linker_Switches.Table (J),
5324 Parent => Current_Work_Dir.all);
5325 end loop;
5326
5327 for J in 1 .. Gcc_Switches.Last loop
5328 Test_If_Relative_Path
5329 (Gcc_Switches.Table (J),
5330 Parent => Dir_Path,
5331 Including_Non_Switch => False);
5332 end loop;
5333
5334 for J in 1 .. Saved_Gcc_Switches.Last loop
5335 Test_If_Relative_Path
5336 (Saved_Gcc_Switches.Table (J),
5337 Parent => Current_Work_Dir.all,
5338 Including_Non_Switch => False);
5339 end loop;
5340 end;
5341 end if;
5342
5343 -- We now put in the Binder_Switches and Linker_Switches tables, the
5344 -- binder and linker switches of the command line that have been put in
5345 -- the Saved_ tables. If a project file was used, then the command line
5346 -- switches will follow the project file switches.
5347
5348 for J in 1 .. Saved_Binder_Switches.Last loop
5349 Add_Switch
5350 (Saved_Binder_Switches.Table (J),
5351 Binder,
5352 And_Save => False);
5353 end loop;
5354
5355 for J in 1 .. Saved_Linker_Switches.Last loop
5356 Add_Switch
5357 (Saved_Linker_Switches.Table (J),
5358 Linker,
5359 And_Save => False);
5360 end loop;
5361
5362 -- If no project file is used, we just put the gcc switches
5363 -- from the command line in the Gcc_Switches table.
5364
5365 if Main_Project = No_Project then
5366 for J in 1 .. Saved_Gcc_Switches.Last loop
5367 Add_Switch
5368 (Saved_Gcc_Switches.Table (J), Compiler, And_Save => False);
5369 end loop;
5370
5371 else
5372 -- If there is a project, put the command line gcc switches in the
5373 -- variable The_Saved_Gcc_Switches. They are going to be used later
5374 -- in procedure Compile_Sources.
5375
5376 The_Saved_Gcc_Switches :=
5377 new Argument_List (1 .. Saved_Gcc_Switches.Last + 1);
5378
5379 for J in 1 .. Saved_Gcc_Switches.Last loop
5380 The_Saved_Gcc_Switches (J) := Saved_Gcc_Switches.Table (J);
5381 end loop;
5382
5383 -- We never use gnat.adc when a project file is used
5384
5385 The_Saved_Gcc_Switches (The_Saved_Gcc_Switches'Last) := No_gnat_adc;
5386 end if;
5387
5388 -- If there was a --GCC, --GNATBIND or --GNATLINK switch on the command
5389 -- line, then we have to use it, even if there was another switch in
5390 -- the project file.
5391
5392 if Saved_Gcc /= null then
5393 Gcc := Saved_Gcc;
5394 end if;
5395
5396 if Saved_Gnatbind /= null then
5397 Gnatbind := Saved_Gnatbind;
5398 end if;
5399
5400 if Saved_Gnatlink /= null then
5401 Gnatlink := Saved_Gnatlink;
5402 end if;
5403
5404 Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
5405 Gnatbind_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
5406 Gnatlink_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
5407
5408 -- If we have specified -j switch both from the project file
5409 -- and on the command line, the one from the command line takes
5410 -- precedence.
5411
5412 if Saved_Maximum_Processes = 0 then
5413 Saved_Maximum_Processes := Maximum_Processes;
5414 end if;
5415
5416 -- Allocate as many temporary mapping file names as the maximum number
5417 -- of compilations processed, for each possible project.
5418
5419 declare
5420 Data : Project_Compilation_Access;
5421 Proj : Project_List := Project_Tree.Projects;
5422 begin
5423 while Proj /= null loop
5424 Data := new Project_Compilation_Data'
5425 (Mapping_File_Names => new Temp_Path_Names
5426 (1 .. Saved_Maximum_Processes),
5427 Last_Mapping_File_Names => 0,
5428 Free_Mapping_File_Indices => new Free_File_Indices
5429 (1 .. Saved_Maximum_Processes),
5430 Last_Free_Indices => 0);
5431
5432 Project_Compilation_Htable.Set
5433 (Project_Compilation, Proj.Project, Data);
5434 Proj := Proj.Next;
5435 end loop;
5436
5437 Data := new Project_Compilation_Data'
5438 (Mapping_File_Names => new Temp_Path_Names
5439 (1 .. Saved_Maximum_Processes),
5440 Last_Mapping_File_Names => 0,
5441 Free_Mapping_File_Indices => new Free_File_Indices
5442 (1 .. Saved_Maximum_Processes),
5443 Last_Free_Indices => 0);
5444
5445 Project_Compilation_Htable.Set
5446 (Project_Compilation, No_Project, Data);
5447 end;
5448
5449 Bad_Compilation.Init;
5450
5451 -- If project files are used, create the mapping of all the sources, so
5452 -- that the correct paths will be found. Otherwise, if there is a file
5453 -- which is not a source with the same name in a source directory this
5454 -- file may be incorrectly found.
5455
5456 if Main_Project /= No_Project then
5457 Prj.Env.Create_Mapping (Project_Tree);
5458 end if;
5459
5460 Current_Main_Index := Main_Index;
5461
5462 -- Here is where the make process is started
5463
5464 -- We do the same process for each main
5465
5466 Multiple_Main_Loop : for N_File in 1 .. Osint.Number_Of_Files loop
5467
5468 -- First, find the executable name and path
5469
5470 Executable := No_File;
5471 Executable_Obsolete := False;
5472 Non_Std_Executable :=
5473 Targparm.Executable_Extension_On_Target /= No_Name;
5474
5475 -- Look inside the linker switches to see if the name of the final
5476 -- executable program was specified.
5477
5478 for J in reverse Linker_Switches.First .. Linker_Switches.Last loop
5479 if Linker_Switches.Table (J).all = Output_Flag.all then
5480 pragma Assert (J < Linker_Switches.Last);
5481
5482 -- We cannot specify a single executable for several main
5483 -- subprograms
5484
5485 if Osint.Number_Of_Files > 1 then
5486 Fail
5487 ("cannot specify a single executable for several mains");
5488 end if;
5489
5490 Name_Len := 0;
5491 Add_Str_To_Name_Buffer (Linker_Switches.Table (J + 1).all);
5492 Executable := Name_Enter;
5493
5494 Verbose_Msg (Executable, "final executable");
5495 end if;
5496 end loop;
5497
5498 -- If the name of the final executable program was not specified then
5499 -- construct it from the main input file.
5500
5501 if Executable = No_File then
5502 if Main_Project = No_Project then
5503 Executable := Executable_Name (Strip_Suffix (Main_Source_File));
5504
5505 else
5506 -- If we are using a project file, we attempt to remove the
5507 -- body (or spec) termination of the main subprogram. We find
5508 -- it the naming scheme of the project file. This avoids
5509 -- generating an executable "main.2" for a main subprogram
5510 -- "main.2.ada", when the body termination is ".2.ada".
5511
5512 Executable :=
5513 Prj.Util.Executable_Of
5514 (Main_Project, Project_Tree, Main_Source_File, Main_Index);
5515 end if;
5516 end if;
5517
5518 if Main_Project /= No_Project
5519 and then Main_Project.Exec_Directory /= No_Path_Information
5520 then
5521 declare
5522 Exec_File_Name : constant String :=
5523 Get_Name_String (Executable);
5524
5525 begin
5526 if not Is_Absolute_Path (Exec_File_Name) then
5527 Get_Name_String (Main_Project.Exec_Directory.Display_Name);
5528
5529 if Name_Buffer (Name_Len) /= Directory_Separator then
5530 Add_Char_To_Name_Buffer (Directory_Separator);
5531 end if;
5532
5533 Add_Str_To_Name_Buffer (Exec_File_Name);
5534 Executable := Name_Find;
5535 end if;
5536
5537 Non_Std_Executable := True;
5538 end;
5539 end if;
5540
5541 if Do_Compile_Step then
5542 Recursive_Compilation_Step : declare
5543 Args : Argument_List (1 .. Gcc_Switches.Last);
5544
5545 First_Compiled_File : File_Name_Type;
5546 Youngest_Obj_File : File_Name_Type;
5547 Youngest_Obj_Stamp : Time_Stamp_Type;
5548
5549 Executable_Stamp : Time_Stamp_Type;
5550 -- Executable is the final executable program
5551 -- ??? comment seems unrelated to declaration
5552
5553 Library_Rebuilt : Boolean := False;
5554
5555 begin
5556 for J in 1 .. Gcc_Switches.Last loop
5557 Args (J) := Gcc_Switches.Table (J);
5558 end loop;
5559
5560 -- Now we invoke Compile_Sources for the current main
5561
5562 Compile_Sources
5563 (Main_Source => Main_Source_File,
5564 Args => Args,
5565 First_Compiled_File => First_Compiled_File,
5566 Most_Recent_Obj_File => Youngest_Obj_File,
5567 Most_Recent_Obj_Stamp => Youngest_Obj_Stamp,
5568 Main_Unit => Is_Main_Unit,
5569 Main_Index => Current_Main_Index,
5570 Compilation_Failures => Compilation_Failures,
5571 Check_Readonly_Files => Check_Readonly_Files,
5572 Do_Not_Execute => Do_Not_Execute,
5573 Force_Compilations => Force_Compilations,
5574 In_Place_Mode => In_Place_Mode,
5575 Keep_Going => Keep_Going,
5576 Initialize_ALI_Data => True,
5577 Max_Process => Saved_Maximum_Processes);
5578
5579 if Verbose_Mode then
5580 Write_Str ("End of compilation");
5581 Write_Eol;
5582 end if;
5583
5584 -- Make sure the queue will be reinitialized for the next round
5585
5586 First_Q_Initialization := True;
5587
5588 Total_Compilation_Failures :=
5589 Total_Compilation_Failures + Compilation_Failures;
5590
5591 if Total_Compilation_Failures /= 0 then
5592 if Keep_Going then
5593 goto Next_Main;
5594
5595 else
5596 List_Bad_Compilations;
5597 Report_Compilation_Failed;
5598 end if;
5599 end if;
5600
5601 -- Regenerate libraries, if there are any and if object files
5602 -- have been regenerated.
5603
5604 if Main_Project /= No_Project
5605 and then MLib.Tgt.Support_For_Libraries /= Prj.None
5606 and then (Do_Bind_Step
5607 or Unique_Compile_All_Projects
5608 or not Compile_Only)
5609 and then (Do_Link_Step or else N_File = Osint.Number_Of_Files)
5610 then
5611 Library_Projs.Init;
5612
5613 declare
5614 Depth : Natural;
5615 Current : Natural;
5616 Proj1 : Project_List;
5617
5618 procedure Add_To_Library_Projs (Proj : Project_Id);
5619 -- Add project Project to table Library_Projs in
5620 -- decreasing depth order.
5621
5622 --------------------------
5623 -- Add_To_Library_Projs --
5624 --------------------------
5625
5626 procedure Add_To_Library_Projs (Proj : Project_Id) is
5627 Prj : Project_Id;
5628
5629 begin
5630 Library_Projs.Increment_Last;
5631 Depth := Proj.Depth;
5632
5633 -- Put the projects in decreasing depth order, so that
5634 -- if libA depends on libB, libB is first in order.
5635
5636 Current := Library_Projs.Last;
5637 while Current > 1 loop
5638 Prj := Library_Projs.Table (Current - 1);
5639 exit when Prj.Depth >= Depth;
5640 Library_Projs.Table (Current) := Prj;
5641 Current := Current - 1;
5642 end loop;
5643
5644 Library_Projs.Table (Current) := Proj;
5645 end Add_To_Library_Projs;
5646
5647 -- Start of processing for ??? (should name declare block
5648 -- or probably better, break this out as a nested proc).
5649
5650 begin
5651 -- Put in Library_Projs table all library project file
5652 -- ids when the library need to be rebuilt.
5653
5654 Proj1 := Project_Tree.Projects;
5655 while Proj1 /= null loop
5656 if Proj1.Project.Standalone_Library then
5657 Stand_Alone_Libraries := True;
5658 end if;
5659
5660 if Proj1.Project.Library then
5661 MLib.Prj.Check_Library
5662 (Proj1.Project, Project_Tree);
5663 end if;
5664
5665 if Proj1.Project.Need_To_Build_Lib then
5666 Add_To_Library_Projs (Proj1.Project);
5667 end if;
5668
5669 Proj1 := Proj1.Next;
5670 end loop;
5671
5672 -- Check if importing libraries should be regenerated
5673 -- because at least an imported library will be
5674 -- regenerated or is more recent.
5675
5676 Proj1 := Project_Tree.Projects;
5677 while Proj1 /= null loop
5678 if Proj1.Project.Library
5679 and then Proj1.Project.Library_Kind /= Static
5680 and then not Proj1.Project.Need_To_Build_Lib
5681 and then not Proj1.Project.Externally_Built
5682 then
5683 declare
5684 List : Project_List;
5685 Proj2 : Project_Id;
5686 Rebuild : Boolean := False;
5687
5688 Lib_Timestamp1 : constant Time_Stamp_Type :=
5689 Proj1.Project.Library_TS;
5690
5691 begin
5692 List := Proj1.Project.All_Imported_Projects;
5693 while List /= null loop
5694 Proj2 := List.Project;
5695
5696 if Proj2.Library then
5697 if Proj2.Need_To_Build_Lib
5698 or else
5699 (Lib_Timestamp1 < Proj2.Library_TS)
5700 then
5701 Rebuild := True;
5702 exit;
5703 end if;
5704 end if;
5705
5706 List := List.Next;
5707 end loop;
5708
5709 if Rebuild then
5710 Proj1.Project.Need_To_Build_Lib := True;
5711 Add_To_Library_Projs (Proj1.Project);
5712 end if;
5713 end;
5714 end if;
5715
5716 Proj1 := Proj1.Next;
5717 end loop;
5718
5719 -- Reset the flags Need_To_Build_Lib for the next main,
5720 -- to avoid rebuilding libraries uselessly.
5721
5722 Proj1 := Project_Tree.Projects;
5723 while Proj1 /= null loop
5724 Proj1.Project.Need_To_Build_Lib := False;
5725 Proj1 := Proj1.Next;
5726 end loop;
5727 end;
5728
5729 -- Build the libraries, if any need to be built
5730
5731 for J in 1 .. Library_Projs.Last loop
5732 Library_Rebuilt := True;
5733
5734 -- If a library is rebuilt, then executables are obsolete
5735
5736 Executable_Obsolete := True;
5737
5738 MLib.Prj.Build_Library
5739 (For_Project => Library_Projs.Table (J),
5740 In_Tree => Project_Tree,
5741 Gnatbind => Gnatbind.all,
5742 Gnatbind_Path => Gnatbind_Path,
5743 Gcc => Gcc.all,
5744 Gcc_Path => Gcc_Path);
5745 end loop;
5746 end if;
5747
5748 if List_Dependencies then
5749 if First_Compiled_File /= No_File then
5750 Inform
5751 (First_Compiled_File,
5752 "must be recompiled. Can't generate dependence list.");
5753 else
5754 List_Depend;
5755 end if;
5756
5757 elsif First_Compiled_File = No_File
5758 and then not Do_Bind_Step
5759 and then not Quiet_Output
5760 and then not Library_Rebuilt
5761 and then Osint.Number_Of_Files = 1
5762 then
5763 Inform (Msg => "objects up to date.");
5764
5765 elsif Do_Not_Execute
5766 and then First_Compiled_File /= No_File
5767 then
5768 Write_Name (First_Compiled_File);
5769 Write_Eol;
5770 end if;
5771
5772 -- Stop after compile step if any of:
5773
5774 -- 1) -n (Do_Not_Execute) specified
5775
5776 -- 2) -M (List_Dependencies) specified (also sets
5777 -- Do_Not_Execute above, so this is probably superfluous).
5778
5779 -- 3) -c (Compile_Only) specified, but not -b (Bind_Only)
5780
5781 -- 4) Made unit cannot be a main unit
5782
5783 if ((Do_Not_Execute
5784 or List_Dependencies
5785 or not Do_Bind_Step
5786 or not Is_Main_Unit)
5787 and then not No_Main_Subprogram
5788 and then not Build_Bind_And_Link_Full_Project)
5789 or else Unique_Compile
5790 then
5791 if Osint.Number_Of_Files = 1 then
5792 exit Multiple_Main_Loop;
5793
5794 else
5795 goto Next_Main;
5796 end if;
5797 end if;
5798
5799 -- If the objects were up-to-date check if the executable file
5800 -- is also up-to-date. For now always bind and link on the JVM
5801 -- since there is currently no simple way to check whether
5802 -- objects are up-to-date.
5803
5804 if Targparm.VM_Target /= JVM_Target
5805 and then First_Compiled_File = No_File
5806 then
5807 Executable_Stamp := File_Stamp (Executable);
5808
5809 if not Executable_Obsolete then
5810 Executable_Obsolete :=
5811 Youngest_Obj_Stamp > Executable_Stamp;
5812 end if;
5813
5814 if not Executable_Obsolete then
5815 for Index in reverse 1 .. Dependencies.Last loop
5816 if Is_In_Obsoleted
5817 (Dependencies.Table (Index).Depends_On)
5818 then
5819 Enter_Into_Obsoleted
5820 (Dependencies.Table (Index).This);
5821 end if;
5822 end loop;
5823
5824 Executable_Obsolete := Is_In_Obsoleted (Main_Source_File);
5825 Dependencies.Init;
5826 end if;
5827
5828 if not Executable_Obsolete then
5829
5830 -- If no Ada object files obsolete the executable, check
5831 -- for younger or missing linker files.
5832
5833 Check_Linker_Options
5834 (Executable_Stamp,
5835 Youngest_Obj_File,
5836 Youngest_Obj_Stamp);
5837
5838 Executable_Obsolete := Youngest_Obj_File /= No_File;
5839 end if;
5840
5841 -- Check if any library file is more recent than the
5842 -- executable: there may be an externally built library
5843 -- file that has been modified.
5844
5845 if not Executable_Obsolete
5846 and then Main_Project /= No_Project
5847 then
5848 declare
5849 Proj1 : Project_List;
5850
5851 begin
5852 Proj1 := Project_Tree.Projects;
5853 while Proj1 /= null loop
5854 if Proj1.Project.Library
5855 and then
5856 Proj1.Project.Library_TS > Executable_Stamp
5857 then
5858 Executable_Obsolete := True;
5859 Youngest_Obj_Stamp := Proj1.Project.Library_TS;
5860 Name_Len := 0;
5861 Add_Str_To_Name_Buffer ("library ");
5862 Add_Str_To_Name_Buffer
5863 (Get_Name_String (Proj1.Project.Library_Name));
5864 Youngest_Obj_File := Name_Find;
5865 exit;
5866 end if;
5867
5868 Proj1 := Proj1.Next;
5869 end loop;
5870 end;
5871 end if;
5872
5873 -- Return if the executable is up to date and otherwise
5874 -- motivate the relink/rebind.
5875
5876 if not Executable_Obsolete then
5877 if not Quiet_Output then
5878 Inform (Executable, "up to date.");
5879 end if;
5880
5881 if Osint.Number_Of_Files = 1 then
5882 exit Multiple_Main_Loop;
5883
5884 else
5885 goto Next_Main;
5886 end if;
5887 end if;
5888
5889 if Executable_Stamp (1) = ' ' then
5890 if not No_Main_Subprogram then
5891 Verbose_Msg (Executable, "missing.", Prefix => " ");
5892 end if;
5893
5894 elsif Youngest_Obj_Stamp (1) = ' ' then
5895 Verbose_Msg
5896 (Youngest_Obj_File, "missing.", Prefix => " ");
5897
5898 elsif Youngest_Obj_Stamp > Executable_Stamp then
5899 Verbose_Msg
5900 (Youngest_Obj_File,
5901 "(" & String (Youngest_Obj_Stamp) & ") newer than",
5902 Executable,
5903 "(" & String (Executable_Stamp) & ")");
5904
5905 else
5906 Verbose_Msg
5907 (Executable, "needs to be rebuilt", Prefix => " ");
5908
5909 end if;
5910 end if;
5911 end Recursive_Compilation_Step;
5912 end if;
5913
5914 -- For binding and linking, we need to be in the object directory of
5915 -- the main project.
5916
5917 if Main_Project /= No_Project then
5918 Change_To_Object_Directory (Main_Project);
5919 end if;
5920
5921 -- If we are here, it means that we need to rebuilt the current main,
5922 -- so we set Executable_Obsolete to True to make sure that subsequent
5923 -- mains will be rebuilt.
5924
5925 Main_ALI_In_Place_Mode_Step : declare
5926 ALI_File : File_Name_Type;
5927 Src_File : File_Name_Type;
5928
5929 begin
5930 Src_File := Strip_Directory (Main_Source_File);
5931 ALI_File := Lib_File_Name (Src_File, Current_Main_Index);
5932 Main_ALI_File := Full_Lib_File_Name (ALI_File);
5933
5934 -- When In_Place_Mode, the library file can be located in the
5935 -- Main_Source_File directory which may not be present in the
5936 -- library path. If it is not present then use the corresponding
5937 -- library file name.
5938
5939 if Main_ALI_File = No_File and then In_Place_Mode then
5940 Get_Name_String (Get_Directory (Full_Source_Name (Src_File)));
5941 Get_Name_String_And_Append (ALI_File);
5942 Main_ALI_File := Name_Find;
5943 Main_ALI_File := Full_Lib_File_Name (Main_ALI_File);
5944 end if;
5945
5946 if Main_ALI_File = No_File then
5947 Make_Failed ("could not find the main ALI file");
5948 end if;
5949 end Main_ALI_In_Place_Mode_Step;
5950
5951 if Do_Bind_Step then
5952 Bind_Step : declare
5953 Args : Argument_List
5954 (Binder_Switches.First .. Binder_Switches.Last + 2);
5955 -- The arguments for the invocation of gnatbind
5956
5957 Last_Arg : Natural := Binder_Switches.Last;
5958 -- Index of the last argument in Args
5959
5960 Shared_Libs : Boolean := False;
5961 -- Set to True when there are shared library project files or
5962 -- when gnatbind is invoked with -shared.
5963
5964 Proj : Project_List;
5965
5966 begin
5967 -- Check if there are shared libraries, so that gnatbind is
5968 -- called with -shared. Check also if gnatbind is called with
5969 -- -shared, so that gnatlink is called with -shared-libgcc
5970 -- ensuring that the shared version of libgcc will be used.
5971
5972 if Main_Project /= No_Project
5973 and then MLib.Tgt.Support_For_Libraries /= Prj.None
5974 then
5975 Proj := Project_Tree.Projects;
5976 while Proj /= null loop
5977 if Proj.Project.Library
5978 and then Proj.Project.Library_Kind /= Static
5979 then
5980 Shared_Libs := True;
5981 Bind_Shared := Shared_Switch'Access;
5982 exit;
5983 end if;
5984 Proj := Proj.Next;
5985 end loop;
5986 end if;
5987
5988 -- Check now for switch -shared
5989
5990 if not Shared_Libs then
5991 for J in Binder_Switches.First .. Last_Arg loop
5992 if Binder_Switches.Table (J).all = "-shared" then
5993 Shared_Libs := True;
5994 exit;
5995 end if;
5996 end loop;
5997 end if;
5998
5999 -- If shared libraries present, invoke gnatlink with
6000 -- -shared-libgcc.
6001
6002 if Shared_Libs then
6003 Link_With_Shared_Libgcc := Shared_Libgcc_Switch'Access;
6004 end if;
6005
6006 -- Get all the binder switches
6007
6008 for J in Binder_Switches.First .. Last_Arg loop
6009 Args (J) := Binder_Switches.Table (J);
6010 end loop;
6011
6012 if Stand_Alone_Libraries then
6013 Last_Arg := Last_Arg + 1;
6014 Args (Last_Arg) := Force_Elab_Flags_String'Access;
6015 end if;
6016
6017 if Main_Project /= No_Project then
6018
6019 -- Put all the source directories in ADA_INCLUDE_PATH,
6020 -- and all the object directories in ADA_OBJECTS_PATH,
6021 -- except those of library projects.
6022
6023 Prj.Env.Set_Ada_Paths (Main_Project, Project_Tree, False);
6024
6025 -- If switch -C was specified, create a binder mapping file
6026
6027 if Create_Mapping_File then
6028 Create_Binder_Mapping_File (Args, Last_Arg);
6029 end if;
6030
6031 end if;
6032
6033 begin
6034 Bind (Main_ALI_File,
6035 Bind_Shared.all & Args (Args'First .. Last_Arg));
6036
6037 exception
6038 when others =>
6039
6040 -- Delete the temporary mapping file, if one was created.
6041
6042 if Mapping_Path /= No_Path then
6043 Delete_Temporary_File (Project_Tree, Mapping_Path);
6044 end if;
6045
6046 -- And reraise the exception
6047
6048 raise;
6049 end;
6050
6051 -- If -dn was not specified, delete the temporary mapping file,
6052 -- if one was created.
6053
6054 if Mapping_Path /= No_Path then
6055 Delete_Temporary_File (Project_Tree, Mapping_Path);
6056 end if;
6057 end Bind_Step;
6058 end if;
6059
6060 if Do_Link_Step then
6061 Link_Step : declare
6062 Linker_Switches_Last : constant Integer := Linker_Switches.Last;
6063 Path_Option : constant String_Access :=
6064 MLib.Linker_Library_Path_Option;
6065 Libraries_Present : Boolean := False;
6066 Current : Natural;
6067 Proj2 : Project_Id;
6068 Depth : Natural;
6069 Proj1 : Project_List;
6070
6071 begin
6072 if not Run_Path_Option then
6073 Linker_Switches.Increment_Last;
6074 Linker_Switches.Table (Linker_Switches.Last) :=
6075 new String'("-R");
6076 end if;
6077
6078 if Main_Project /= No_Project then
6079 Library_Paths.Set_Last (0);
6080 Library_Projs.Init;
6081
6082 if MLib.Tgt.Support_For_Libraries /= Prj.None then
6083
6084 -- Check for library projects
6085
6086 Proj1 := Project_Tree.Projects;
6087 while Proj1 /= null loop
6088 if Proj1.Project /= Main_Project
6089 and then Proj1.Project.Library
6090 then
6091 -- Add this project to table Library_Projs
6092
6093 Libraries_Present := True;
6094 Depth := Proj1.Project.Depth;
6095 Library_Projs.Increment_Last;
6096 Current := Library_Projs.Last;
6097
6098 -- Any project with a greater depth should be
6099 -- after this project in the list.
6100
6101 while Current > 1 loop
6102 Proj2 := Library_Projs.Table (Current - 1);
6103 exit when Proj2.Depth <= Depth;
6104 Library_Projs.Table (Current) := Proj2;
6105 Current := Current - 1;
6106 end loop;
6107
6108 Library_Projs.Table (Current) := Proj1.Project;
6109
6110 -- If it is not a static library and path option
6111 -- is set, add it to the Library_Paths table.
6112
6113 if Proj1.Project.Library_Kind /= Static
6114 and then Path_Option /= null
6115 then
6116 Library_Paths.Increment_Last;
6117 Library_Paths.Table (Library_Paths.Last) :=
6118 new String'
6119 (Get_Name_String
6120 (Proj1.Project.Library_Dir.Display_Name));
6121 end if;
6122 end if;
6123
6124 Proj1 := Proj1.Next;
6125 end loop;
6126
6127 for Index in 1 .. Library_Projs.Last loop
6128
6129 -- Add the -L switch
6130
6131 Linker_Switches.Increment_Last;
6132 Linker_Switches.Table (Linker_Switches.Last) :=
6133 new String'("-L" &
6134 Get_Name_String
6135 (Library_Projs.Table (Index).
6136 Library_Dir.Display_Name));
6137
6138 -- Add the -l switch
6139
6140 Linker_Switches.Increment_Last;
6141 Linker_Switches.Table (Linker_Switches.Last) :=
6142 new String'("-l" &
6143 Get_Name_String
6144 (Library_Projs.Table (Index).
6145 Library_Name));
6146 end loop;
6147 end if;
6148
6149 if Libraries_Present then
6150
6151 -- If Path_Option is not null, create the switch
6152 -- ("-Wl,-rpath," or equivalent) with all the non static
6153 -- library dirs plus the standard GNAT library dir.
6154 -- We do that only if Run_Path_Option is True
6155 -- (not disabled by -R switch).
6156
6157 if Run_Path_Option and then Path_Option /= null then
6158 declare
6159 Option : String_Access;
6160 Length : Natural := Path_Option'Length;
6161 Current : Natural;
6162
6163 begin
6164 if MLib.Separate_Run_Path_Options then
6165
6166 -- We are going to create one switch of the form
6167 -- "-Wl,-rpath,dir_N" for each directory to
6168 -- consider.
6169
6170 -- One switch for each library directory
6171
6172 for Index in
6173 Library_Paths.First .. Library_Paths.Last
6174 loop
6175 Linker_Switches.Increment_Last;
6176 Linker_Switches.Table
6177 (Linker_Switches.Last) := new String'
6178 (Path_Option.all &
6179 Library_Paths.Table (Index).all);
6180 end loop;
6181
6182 -- One switch for the standard GNAT library dir
6183
6184 Linker_Switches.Increment_Last;
6185 Linker_Switches.Table
6186 (Linker_Switches.Last) := new String'
6187 (Path_Option.all & MLib.Utl.Lib_Directory);
6188
6189 else
6190 -- We are going to create one switch of the form
6191 -- "-Wl,-rpath,dir_1:dir_2:dir_3"
6192
6193 for Index in
6194 Library_Paths.First .. Library_Paths.Last
6195 loop
6196 -- Add the length of the library dir plus one
6197 -- for the directory separator.
6198
6199 Length :=
6200 Length +
6201 Library_Paths.Table (Index)'Length + 1;
6202 end loop;
6203
6204 -- Finally, add the length of the standard GNAT
6205 -- library dir.
6206
6207 Length := Length + MLib.Utl.Lib_Directory'Length;
6208 Option := new String (1 .. Length);
6209 Option (1 .. Path_Option'Length) :=
6210 Path_Option.all;
6211 Current := Path_Option'Length;
6212
6213 -- Put each library dir followed by a dir
6214 -- separator.
6215
6216 for Index in
6217 Library_Paths.First .. Library_Paths.Last
6218 loop
6219 Option
6220 (Current + 1 ..
6221 Current +
6222 Library_Paths.Table (Index)'Length) :=
6223 Library_Paths.Table (Index).all;
6224 Current :=
6225 Current +
6226 Library_Paths.Table (Index)'Length + 1;
6227 Option (Current) := Path_Separator;
6228 end loop;
6229
6230 -- Finally put the standard GNAT library dir
6231
6232 Option
6233 (Current + 1 ..
6234 Current + MLib.Utl.Lib_Directory'Length) :=
6235 MLib.Utl.Lib_Directory;
6236
6237 -- And add the switch to the linker switches
6238
6239 Linker_Switches.Increment_Last;
6240 Linker_Switches.Table (Linker_Switches.Last) :=
6241 Option;
6242 end if;
6243 end;
6244 end if;
6245
6246 end if;
6247
6248 -- Put the object directories in ADA_OBJECTS_PATH
6249
6250 Prj.Env.Set_Ada_Paths (Main_Project, Project_Tree, False);
6251
6252 -- Check for attributes Linker'Linker_Options in projects
6253 -- other than the main project
6254
6255 declare
6256 Linker_Options : constant String_List :=
6257 Linker_Options_Switches
6258 (Main_Project, Project_Tree);
6259 begin
6260 for Option in Linker_Options'Range loop
6261 Linker_Switches.Increment_Last;
6262 Linker_Switches.Table (Linker_Switches.Last) :=
6263 Linker_Options (Option);
6264 end loop;
6265 end;
6266 end if;
6267
6268 declare
6269 Args : Argument_List
6270 (Linker_Switches.First .. Linker_Switches.Last + 2);
6271
6272 Last_Arg : Integer := Linker_Switches.First - 1;
6273 Skip : Boolean := False;
6274
6275 begin
6276 -- Get all the linker switches
6277
6278 for J in Linker_Switches.First .. Linker_Switches.Last loop
6279 if Skip then
6280 Skip := False;
6281
6282 elsif Non_Std_Executable
6283 and then Linker_Switches.Table (J).all = "-o"
6284 then
6285 Skip := True;
6286
6287 -- Here we capture and duplicate the linker argument. We
6288 -- need to do the duplication since the arguments will
6289 -- get normalized. Not doing so will result in calling
6290 -- normalized two times for the same set of arguments if
6291 -- gnatmake is passed multiple mains. This can result in
6292 -- the wrong argument being passed to the linker.
6293
6294 else
6295 Last_Arg := Last_Arg + 1;
6296 Args (Last_Arg) :=
6297 new String'(Linker_Switches.Table (J).all);
6298 end if;
6299 end loop;
6300
6301 -- If need be, add the -o switch
6302
6303 if Non_Std_Executable then
6304 Last_Arg := Last_Arg + 1;
6305 Args (Last_Arg) := new String'("-o");
6306 Last_Arg := Last_Arg + 1;
6307 Args (Last_Arg) :=
6308 new String'(Get_Name_String (Executable));
6309 end if;
6310
6311 -- And invoke the linker
6312
6313 declare
6314 Success : Boolean := False;
6315 begin
6316 Link (Main_ALI_File,
6317 Link_With_Shared_Libgcc.all &
6318 Args (Args'First .. Last_Arg),
6319 Success);
6320
6321 if Success then
6322 Successful_Links.Increment_Last;
6323 Successful_Links.Table (Successful_Links.Last) :=
6324 Main_ALI_File;
6325
6326 elsif Osint.Number_Of_Files = 1
6327 or else not Keep_Going
6328 then
6329 Make_Failed ("*** link failed.");
6330
6331 else
6332 Set_Standard_Error;
6333 Write_Line ("*** link failed");
6334
6335 if Commands_To_Stdout then
6336 Set_Standard_Output;
6337 end if;
6338
6339 Failed_Links.Increment_Last;
6340 Failed_Links.Table (Failed_Links.Last) :=
6341 Main_ALI_File;
6342 end if;
6343 end;
6344 end;
6345
6346 Linker_Switches.Set_Last (Linker_Switches_Last);
6347 end Link_Step;
6348 end if;
6349
6350 -- We go to here when we skip the bind and link steps
6351
6352 <<Next_Main>>
6353
6354 -- We go to the next main, if we did not process the last one
6355
6356 if N_File < Osint.Number_Of_Files then
6357 Main_Source_File := Next_Main_Source;
6358
6359 if Current_File_Index /= No_Index then
6360 Main_Index := Current_File_Index;
6361 end if;
6362
6363 if Main_Project /= No_Project then
6364
6365 -- Find the file name of the main unit
6366
6367 declare
6368 Main_Source_File_Name : constant String :=
6369 Get_Name_String (Main_Source_File);
6370
6371 Main_Unit_File_Name : constant String :=
6372 Prj.Env.
6373 File_Name_Of_Library_Unit_Body
6374 (Name => Main_Source_File_Name,
6375 Project => Main_Project,
6376 In_Tree => Project_Tree,
6377 Main_Project_Only =>
6378 not Unique_Compile);
6379
6380 The_Packages : constant Package_Id :=
6381 Main_Project.Decl.Packages;
6382
6383 Binder_Package : constant Prj.Package_Id :=
6384 Prj.Util.Value_Of
6385 (Name => Name_Binder,
6386 In_Packages => The_Packages,
6387 In_Tree => Project_Tree);
6388
6389 Linker_Package : constant Prj.Package_Id :=
6390 Prj.Util.Value_Of
6391 (Name => Name_Linker,
6392 In_Packages => The_Packages,
6393 In_Tree => Project_Tree);
6394
6395 begin
6396 -- We fail if we cannot find the main source file
6397 -- as an immediate source of the main project file.
6398
6399 if Main_Unit_File_Name = "" then
6400 Make_Failed ('"' & Main_Source_File_Name
6401 & """ is not a unit of project "
6402 & Project_File_Name.all & ".");
6403
6404 else
6405 -- Remove any directory information from the main
6406 -- source file name.
6407
6408 declare
6409 Pos : Natural := Main_Unit_File_Name'Last;
6410
6411 begin
6412 loop
6413 exit when Pos < Main_Unit_File_Name'First
6414 or else
6415 Main_Unit_File_Name (Pos) = Directory_Separator;
6416 Pos := Pos - 1;
6417 end loop;
6418
6419 Name_Len := Main_Unit_File_Name'Last - Pos;
6420
6421 Name_Buffer (1 .. Name_Len) :=
6422 Main_Unit_File_Name
6423 (Pos + 1 .. Main_Unit_File_Name'Last);
6424
6425 Main_Source_File := Name_Find;
6426 end;
6427 end if;
6428
6429 -- We now deal with the binder and linker switches.
6430 -- If no project file is used, there is nothing to do
6431 -- because the binder and linker switches are the same
6432 -- for all mains.
6433
6434 -- Reset the tables Binder_Switches and Linker_Switches
6435
6436 Binder_Switches.Set_Last (Last_Binder_Switch);
6437 Linker_Switches.Set_Last (Last_Linker_Switch);
6438
6439 -- Add binder switches from the project file for this main,
6440 -- if any.
6441
6442 if Do_Bind_Step and then Binder_Package /= No_Package then
6443 if Verbose_Mode then
6444 Write_Str ("Adding binder switches for """);
6445 Write_Str (Main_Unit_File_Name);
6446 Write_Line (""".");
6447 end if;
6448
6449 Add_Switches
6450 (Project_Node_Tree => Project_Node_Tree,
6451 File_Name => Main_Unit_File_Name,
6452 Index => Main_Index,
6453 The_Package => Binder_Package,
6454 Program => Binder);
6455 end if;
6456
6457 -- Add linker switches from the project file for this main,
6458 -- if any.
6459
6460 if Do_Link_Step and then Linker_Package /= No_Package then
6461 if Verbose_Mode then
6462 Write_Str ("Adding linker switches for""");
6463 Write_Str (Main_Unit_File_Name);
6464 Write_Line (""".");
6465 end if;
6466
6467 Add_Switches
6468 (Project_Node_Tree => Project_Node_Tree,
6469 File_Name => Main_Unit_File_Name,
6470 Index => Main_Index,
6471 The_Package => Linker_Package,
6472 Program => Linker);
6473 end if;
6474
6475 -- As we are using a project file, for relative paths we add
6476 -- the current working directory for any relative path on
6477 -- the command line and the project directory, for any
6478 -- relative path in the project file.
6479
6480 declare
6481 Dir_Path : constant String :=
6482 Get_Name_String
6483 (Main_Project.Directory.Name);
6484
6485 begin
6486 for
6487 J in Last_Binder_Switch + 1 .. Binder_Switches.Last
6488 loop
6489 Test_If_Relative_Path
6490 (Binder_Switches.Table (J),
6491 Parent => Dir_Path, Including_L_Switch => False);
6492 end loop;
6493
6494 for
6495 J in Last_Linker_Switch + 1 .. Linker_Switches.Last
6496 loop
6497 Test_If_Relative_Path
6498 (Linker_Switches.Table (J), Parent => Dir_Path);
6499 end loop;
6500 end;
6501
6502 -- We now put in the Binder_Switches and Linker_Switches
6503 -- tables, the binder and linker switches of the command
6504 -- line that have been put in the Saved_ tables.
6505 -- These switches will follow the project file switches.
6506
6507 for J in 1 .. Saved_Binder_Switches.Last loop
6508 Add_Switch
6509 (Saved_Binder_Switches.Table (J),
6510 Binder,
6511 And_Save => False);
6512 end loop;
6513
6514 for J in 1 .. Saved_Linker_Switches.Last loop
6515 Add_Switch
6516 (Saved_Linker_Switches.Table (J),
6517 Linker,
6518 And_Save => False);
6519 end loop;
6520 end;
6521 end if;
6522 end if;
6523
6524 -- Remove all marks to be sure to check sources for all executables,
6525 -- as the switches may be different and -s may be in use.
6526
6527 Delete_All_Marks;
6528 end loop Multiple_Main_Loop;
6529
6530 if Failed_Links.Last > 0 then
6531 for Index in 1 .. Successful_Links.Last loop
6532 Write_Str ("Linking of """);
6533 Write_Str (Get_Name_String (Successful_Links.Table (Index)));
6534 Write_Line (""" succeeded.");
6535 end loop;
6536
6537 Set_Standard_Error;
6538
6539 for Index in 1 .. Failed_Links.Last loop
6540 Write_Str ("Linking of """);
6541 Write_Str (Get_Name_String (Failed_Links.Table (Index)));
6542 Write_Line (""" failed.");
6543 end loop;
6544
6545 if Commands_To_Stdout then
6546 Set_Standard_Output;
6547 end if;
6548
6549 if Total_Compilation_Failures = 0 then
6550 Report_Compilation_Failed;
6551 end if;
6552 end if;
6553
6554 if Total_Compilation_Failures /= 0 then
6555 List_Bad_Compilations;
6556 Report_Compilation_Failed;
6557 end if;
6558
6559 -- Delete the temporary mapping file that was created if we are
6560 -- using project files.
6561
6562 Delete_All_Temp_Files;
6563
6564 exception
6565 when X : others =>
6566 Set_Standard_Error;
6567 Write_Line (Exception_Information (X));
6568 Make_Failed ("INTERNAL ERROR. Please report.");
6569 end Gnatmake;
6570
6571 ----------
6572 -- Hash --
6573 ----------
6574
6575 function Hash (F : File_Name_Type) return Header_Num is
6576 begin
6577 return Header_Num (1 + F mod Max_Header);
6578 end Hash;
6579
6580 --------------------
6581 -- In_Ada_Lib_Dir --
6582 --------------------
6583
6584 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean is
6585 D : constant File_Name_Type := Get_Directory (File);
6586 B : constant Byte := Get_Name_Table_Byte (D);
6587 begin
6588 return (B and Ada_Lib_Dir) /= 0;
6589 end In_Ada_Lib_Dir;
6590
6591 -----------------------
6592 -- Init_Mapping_File --
6593 -----------------------
6594
6595 procedure Init_Mapping_File
6596 (Project : Project_Id;
6597 Data : in out Project_Compilation_Data;
6598 File_Index : in out Natural)
6599 is
6600 FD : File_Descriptor;
6601 Status : Boolean;
6602 -- For call to Close
6603
6604 begin
6605 -- Increase the index of the last mapping file for this project
6606
6607 Data.Last_Mapping_File_Names := Data.Last_Mapping_File_Names + 1;
6608
6609 -- If there is a project file, call Create_Mapping_File with
6610 -- the project id.
6611
6612 if Project /= No_Project then
6613 Prj.Env.Create_Mapping_File
6614 (Project,
6615 In_Tree => Project_Tree,
6616 Language => Name_Ada,
6617 Name => Data.Mapping_File_Names
6618 (Data.Last_Mapping_File_Names));
6619
6620 -- Otherwise, just create an empty file
6621
6622 else
6623 Tempdir.Create_Temp_File
6624 (FD,
6625 Data.Mapping_File_Names (Data.Last_Mapping_File_Names));
6626
6627 if FD = Invalid_FD then
6628 Make_Failed ("disk full");
6629
6630 else
6631 Record_Temp_File
6632 (Project_Tree,
6633 Data.Mapping_File_Names (Data.Last_Mapping_File_Names));
6634 end if;
6635
6636 Close (FD, Status);
6637
6638 if not Status then
6639 Make_Failed ("disk full");
6640 end if;
6641 end if;
6642
6643 -- And return the index of the newly created file
6644
6645 File_Index := Data.Last_Mapping_File_Names;
6646 end Init_Mapping_File;
6647
6648 ------------
6649 -- Init_Q --
6650 ------------
6651
6652 procedure Init_Q is
6653 begin
6654 First_Q_Initialization := False;
6655 Q_Front := Q.First;
6656 Q.Set_Last (Q.First);
6657 end Init_Q;
6658
6659 ----------------
6660 -- Initialize --
6661 ----------------
6662
6663 procedure Initialize (Project_Node_Tree : out Project_Node_Tree_Ref) is
6664
6665 procedure Check_Version_And_Help is
6666 new Check_Version_And_Help_G (Makeusg);
6667
6668 -- Start of processing for Initialize
6669
6670 begin
6671 -- Prepare the project's tree, since this is used to hold external
6672 -- references, project path and other attributes that can be impacted by
6673 -- the command line switches
6674
6675 Project_Node_Tree := new Project_Node_Tree_Data;
6676 Prj.Tree.Initialize (Project_Node_Tree);
6677
6678 -- Override default initialization of Check_Object_Consistency since
6679 -- this is normally False for GNATBIND, but is True for GNATMAKE since
6680 -- we do not need to check source consistency again once GNATMAKE has
6681 -- looked at the sources to check.
6682
6683 Check_Object_Consistency := True;
6684
6685 -- Package initializations. The order of calls is important here
6686
6687 Output.Set_Standard_Error;
6688
6689 Gcc_Switches.Init;
6690 Binder_Switches.Init;
6691 Linker_Switches.Init;
6692
6693 Csets.Initialize;
6694 Namet.Initialize;
6695
6696 Snames.Initialize;
6697
6698 Prj.Initialize (Project_Tree);
6699
6700 Dependencies.Init;
6701
6702 RTS_Specified := null;
6703 N_M_Switch := 0;
6704
6705 Mains.Delete;
6706
6707 -- Add the directory where gnatmake is invoked in front of the path,
6708 -- if gnatmake is invoked from a bin directory or with directory
6709 -- information. Only do this if the platform is not VMS, where the
6710 -- notion of path does not really exist.
6711
6712 if not OpenVMS then
6713 declare
6714 Prefix : constant String := Executable_Prefix_Path;
6715 Command : constant String := Command_Name;
6716
6717 begin
6718 if Prefix'Length > 0 then
6719 declare
6720 PATH : constant String :=
6721 Prefix & Directory_Separator & "bin" &
6722 Path_Separator &
6723 Getenv ("PATH").all;
6724 begin
6725 Setenv ("PATH", PATH);
6726 end;
6727
6728 else
6729 for Index in reverse Command'Range loop
6730 if Command (Index) = Directory_Separator then
6731 declare
6732 Absolute_Dir : constant String :=
6733 Normalize_Pathname
6734 (Command (Command'First .. Index));
6735 PATH : constant String :=
6736 Absolute_Dir &
6737 Path_Separator &
6738 Getenv ("PATH").all;
6739 begin
6740 Setenv ("PATH", PATH);
6741 end;
6742
6743 exit;
6744 end if;
6745 end loop;
6746 end if;
6747 end;
6748 end if;
6749
6750 -- Scan the switches and arguments
6751
6752 -- First, scan to detect --version and/or --help
6753
6754 Check_Version_And_Help ("GNATMAKE", "1995");
6755
6756 -- Scan again the switch and arguments, now that we are sure that they
6757 -- do not include --version or --help.
6758
6759 Scan_Args : for Next_Arg in 1 .. Argument_Count loop
6760 Scan_Make_Arg
6761 (Project_Node_Tree, Argument (Next_Arg), And_Save => True);
6762 end loop Scan_Args;
6763
6764 if N_M_Switch > 0 and RTS_Specified = null then
6765 Process_Multilib (Project_Node_Tree);
6766 end if;
6767
6768 if Commands_To_Stdout then
6769 Set_Standard_Output;
6770 end if;
6771
6772 if Usage_Requested then
6773 Usage;
6774 end if;
6775
6776 -- Test for trailing -P switch
6777
6778 if Project_File_Name_Present and then Project_File_Name = null then
6779 Make_Failed ("project file name missing after -P");
6780
6781 -- Test for trailing -o switch
6782
6783 elsif Output_File_Name_Present
6784 and then not Output_File_Name_Seen
6785 then
6786 Make_Failed ("output file name missing after -o");
6787
6788 -- Test for trailing -D switch
6789
6790 elsif Object_Directory_Present
6791 and then not Object_Directory_Seen then
6792 Make_Failed ("object directory missing after -D");
6793 end if;
6794
6795 -- Test for simultaneity of -i and -D
6796
6797 if Object_Directory_Path /= null and then In_Place_Mode then
6798 Make_Failed ("-i and -D cannot be used simultaneously");
6799 end if;
6800
6801 -- Deal with -C= switch
6802
6803 if Gnatmake_Mapping_File /= null then
6804
6805 -- First, check compatibility with other switches
6806
6807 if Project_File_Name /= null then
6808 Make_Failed ("-C= switch is not compatible with -P switch");
6809
6810 elsif Saved_Maximum_Processes > 1 then
6811 Make_Failed ("-C= switch is not compatible with -jnnn switch");
6812 end if;
6813
6814 Fmap.Initialize (Gnatmake_Mapping_File.all);
6815 Add_Switch
6816 ("-gnatem=" & Gnatmake_Mapping_File.all,
6817 Compiler,
6818 And_Save => True);
6819 end if;
6820
6821 if Project_File_Name /= null then
6822
6823 -- A project file was specified by a -P switch
6824
6825 if Verbose_Mode then
6826 Write_Eol;
6827 Write_Str ("Parsing project file """);
6828 Write_Str (Project_File_Name.all);
6829 Write_Str (""".");
6830 Write_Eol;
6831 end if;
6832
6833 -- Avoid looking in the current directory for ALI files
6834
6835 -- Look_In_Primary_Dir := False;
6836
6837 -- Set the project parsing verbosity to whatever was specified
6838 -- by a possible -vP switch.
6839
6840 Prj.Pars.Set_Verbosity (To => Current_Verbosity);
6841
6842 -- Parse the project file.
6843 -- If there is an error, Main_Project will still be No_Project.
6844
6845 Prj.Pars.Parse
6846 (Project => Main_Project,
6847 In_Tree => Project_Tree,
6848 Project_File_Name => Project_File_Name.all,
6849 Packages_To_Check => Packages_To_Check_By_Gnatmake,
6850 Flags => Gnatmake_Flags,
6851 In_Node_Tree => Project_Node_Tree);
6852
6853 -- The parsing of project files may have changed the current output
6854
6855 if Commands_To_Stdout then
6856 Set_Standard_Output;
6857 else
6858 Set_Standard_Error;
6859 end if;
6860
6861 if Main_Project = No_Project then
6862 Make_Failed
6863 ("""" & Project_File_Name.all & """ processing failed");
6864 end if;
6865
6866 Create_Mapping_File := True;
6867
6868 if Verbose_Mode then
6869 Write_Eol;
6870 Write_Str ("Parsing of project file """);
6871 Write_Str (Project_File_Name.all);
6872 Write_Str (""" is finished.");
6873 Write_Eol;
6874 end if;
6875
6876 -- We add the source directories and the object directories to the
6877 -- search paths.
6878
6879 Add_Source_Directories (Main_Project, Project_Tree);
6880 Add_Object_Directories (Main_Project);
6881
6882 Recursive_Compute_Depth (Main_Project);
6883
6884 -- For each project compute the list of the projects it imports
6885 -- directly or indirectly.
6886
6887 declare
6888 Proj : Project_List;
6889 begin
6890 Proj := Project_Tree.Projects;
6891 while Proj /= null loop
6892 Compute_All_Imported_Projects (Proj.Project);
6893 Proj := Proj.Next;
6894 end loop;
6895 end;
6896
6897 else
6898
6899 Osint.Add_Default_Search_Dirs;
6900
6901 -- Source file lookups should be cached for efficiency. Source files
6902 -- are not supposed to change. However, we do that now only if no
6903 -- project file is used; if a project file is used, we do it just
6904 -- after changing the directory to the object directory.
6905
6906 Osint.Source_File_Data (Cache => True);
6907
6908 -- Read gnat.adc file to initialize Fname.UF
6909
6910 Fname.UF.Initialize;
6911
6912 begin
6913 Fname.SF.Read_Source_File_Name_Pragmas;
6914
6915 exception
6916 when Err : SFN_Scan.Syntax_Error_In_GNAT_ADC =>
6917 Make_Failed (Exception_Message (Err));
6918 end;
6919 end if;
6920
6921 -- Make sure no project object directory is recorded
6922
6923 Project_Of_Current_Object_Directory := No_Project;
6924
6925 end Initialize;
6926
6927 ----------------------------
6928 -- Insert_Project_Sources --
6929 ----------------------------
6930
6931 procedure Insert_Project_Sources
6932 (The_Project : Project_Id;
6933 All_Projects : Boolean;
6934 Into_Q : Boolean)
6935 is
6936 Put_In_Q : Boolean := Into_Q;
6937 Unit : Unit_Index;
6938 Sfile : File_Name_Type;
6939 Index : Int;
6940
6941 Extending : constant Boolean := The_Project.Extends /= No_Project;
6942
6943 function Check_Project (P : Project_Id) return Boolean;
6944 -- Returns True if P is The_Project or a project extended by The_Project
6945
6946 -------------------
6947 -- Check_Project --
6948 -------------------
6949
6950 function Check_Project (P : Project_Id) return Boolean is
6951 begin
6952 if All_Projects or else P = The_Project then
6953 return True;
6954
6955 elsif Extending then
6956 declare
6957 Proj : Project_Id;
6958
6959 begin
6960 Proj := The_Project;
6961 while Proj /= null loop
6962 if P = Proj.Extends then
6963 return True;
6964 end if;
6965
6966 Proj := Proj.Extends;
6967 end loop;
6968 end;
6969 end if;
6970
6971 return False;
6972 end Check_Project;
6973
6974 -- Start of processing for Insert_Project_Sources
6975
6976 begin
6977 -- For all the sources in the project files,
6978
6979 Unit := Units_Htable.Get_First (Project_Tree.Units_HT);
6980 while Unit /= null loop
6981 Sfile := No_File;
6982 Index := 0;
6983
6984 -- If there is a source for the body, and the body has not been
6985 -- locally removed.
6986
6987 if Unit.File_Names (Impl) /= null
6988 and then not Unit.File_Names (Impl).Locally_Removed
6989 then
6990 -- And it is a source for the specified project
6991
6992 if Check_Project (Unit.File_Names (Impl).Project) then
6993
6994 -- If we don't have a spec, we cannot consider the source
6995 -- if it is a subunit.
6996
6997 if Unit.File_Names (Spec) = null then
6998 declare
6999 Src_Ind : Source_File_Index;
7000
7001 -- Here we are cheating a little bit: we don't want to
7002 -- use Sinput.L, because it depends on the GNAT tree
7003 -- (Atree, Sinfo, ...). So, we pretend that it is a
7004 -- project file, and we use Sinput.P.
7005
7006 -- Source_File_Is_Subunit is just scanning through the
7007 -- file until it finds one of the reserved words
7008 -- separate, procedure, function, generic or package.
7009 -- Fortunately, these Ada reserved words are also
7010 -- reserved for project files.
7011
7012 begin
7013 Src_Ind := Sinput.P.Load_Project_File
7014 (Get_Name_String
7015 (Unit.File_Names (Impl).Path.Name));
7016
7017 -- If it is a subunit, discard it
7018
7019 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
7020 Sfile := No_File;
7021 Index := 0;
7022 else
7023 Sfile := Unit.File_Names (Impl).Display_File;
7024 Index := Unit.File_Names (Impl).Index;
7025 end if;
7026 end;
7027
7028 else
7029 Sfile := Unit.File_Names (Impl).Display_File;
7030 Index := Unit.File_Names (Impl).Index;
7031 end if;
7032 end if;
7033
7034 elsif Unit.File_Names (Spec) /= null
7035 and then not Unit.File_Names (Spec).Locally_Removed
7036 and then Check_Project (Unit.File_Names (Spec).Project)
7037 then
7038 -- If there is no source for the body, but there is one for the
7039 -- spec which has not been locally removed, then we take this one.
7040
7041 Sfile := Unit.File_Names (Spec).Display_File;
7042 Index := Unit.File_Names (Spec).Index;
7043 end if;
7044
7045 -- If Put_In_Q is True, we insert into the Q
7046
7047 if Put_In_Q then
7048
7049 -- For the first source inserted into the Q, we need to initialize
7050 -- the Q, but not for the subsequent sources.
7051
7052 if First_Q_Initialization then
7053 Init_Q;
7054 end if;
7055
7056 -- And of course, only insert in the Q if the source is not marked
7057
7058 if Sfile /= No_File and then not Is_Marked (Sfile, Index) then
7059 if Verbose_Mode then
7060 Write_Str ("Adding """);
7061 Write_Str (Get_Name_String (Sfile));
7062 Write_Line (""" to the queue");
7063 end if;
7064
7065 Insert_Q (Sfile, Index => Index);
7066 Mark (Sfile, Index);
7067 end if;
7068
7069 elsif Sfile /= No_File then
7070
7071 -- If Put_In_Q is False, we add the source as if it were specified
7072 -- on the command line, and we set Put_In_Q to True, so that the
7073 -- following sources will be put directly in the queue. This will
7074 -- allow parallel compilation processes if -jx switch is used.
7075
7076 if Verbose_Mode then
7077 Write_Str ("Adding """);
7078 Write_Str (Get_Name_String (Sfile));
7079 Write_Line (""" as if on the command line");
7080 end if;
7081
7082 Osint.Add_File (Get_Name_String (Sfile), Index);
7083 Put_In_Q := True;
7084
7085 -- As we may look into the Q later, ensure the Q has been
7086 -- initialized to avoid errors.
7087
7088 if First_Q_Initialization then
7089 Init_Q;
7090 end if;
7091 end if;
7092
7093 Unit := Units_Htable.Get_Next (Project_Tree.Units_HT);
7094 end loop;
7095 end Insert_Project_Sources;
7096
7097 --------------
7098 -- Insert_Q --
7099 --------------
7100
7101 procedure Insert_Q
7102 (Source_File : File_Name_Type;
7103 Source_Unit : Unit_Name_Type := No_Unit_Name;
7104 Index : Int := 0)
7105 is
7106 begin
7107 if Debug.Debug_Flag_Q then
7108 Write_Str (" Q := Q + [ ");
7109 Write_Name (Source_File);
7110
7111 if Index /= 0 then
7112 Write_Str (", ");
7113 Write_Int (Index);
7114 end if;
7115
7116 Write_Str (" ] ");
7117 Write_Eol;
7118 end if;
7119
7120 Q.Table (Q.Last) :=
7121 (File => Source_File,
7122 Unit => Source_Unit,
7123 Index => Index);
7124 Q.Increment_Last;
7125 end Insert_Q;
7126
7127 ---------------------
7128 -- Is_In_Obsoleted --
7129 ---------------------
7130
7131 function Is_In_Obsoleted (F : File_Name_Type) return Boolean is
7132 begin
7133 if F = No_File then
7134 return False;
7135
7136 else
7137 declare
7138 Name : constant String := Get_Name_String (F);
7139 First : Natural;
7140 F2 : File_Name_Type;
7141
7142 begin
7143 First := Name'Last;
7144 while First > Name'First
7145 and then Name (First - 1) /= Directory_Separator
7146 and then Name (First - 1) /= '/'
7147 loop
7148 First := First - 1;
7149 end loop;
7150
7151 if First /= Name'First then
7152 Name_Len := 0;
7153 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
7154 F2 := Name_Find;
7155
7156 else
7157 F2 := F;
7158 end if;
7159
7160 return Obsoleted.Get (F2);
7161 end;
7162 end if;
7163 end Is_In_Obsoleted;
7164
7165 ----------------------------
7166 -- Is_In_Object_Directory --
7167 ----------------------------
7168
7169 function Is_In_Object_Directory
7170 (Source_File : File_Name_Type;
7171 Full_Lib_File : File_Name_Type) return Boolean
7172 is
7173 begin
7174 -- There is something to check only when using project files. Otherwise,
7175 -- this function returns True (last line of the function).
7176
7177 if Main_Project /= No_Project then
7178 declare
7179 Source_File_Name : constant String :=
7180 Get_Name_String (Source_File);
7181 Saved_Verbosity : constant Verbosity := Current_Verbosity;
7182 Project : Project_Id := No_Project;
7183
7184 Path_Name : Path_Name_Type := No_Path;
7185 pragma Warnings (Off, Path_Name);
7186
7187 begin
7188 -- Call Get_Reference to know the ultimate extending project of
7189 -- the source. Call it with verbosity default to avoid verbose
7190 -- messages.
7191
7192 Current_Verbosity := Default;
7193 Prj.Env.Get_Reference
7194 (Source_File_Name => Source_File_Name,
7195 Project => Project,
7196 In_Tree => Project_Tree,
7197 Path => Path_Name);
7198 Current_Verbosity := Saved_Verbosity;
7199
7200 -- If this source is in a project, check that the ALI file is in
7201 -- its object directory. If it is not, return False, so that the
7202 -- ALI file will not be skipped.
7203
7204 if Project /= No_Project then
7205 declare
7206 Object_Directory : constant String :=
7207 Normalize_Pathname
7208 (Get_Name_String
7209 (Project.
7210 Object_Directory.Display_Name));
7211
7212 Olast : Natural := Object_Directory'Last;
7213
7214 Lib_File_Directory : constant String :=
7215 Normalize_Pathname (Dir_Name
7216 (Get_Name_String (Full_Lib_File)));
7217
7218 Llast : Natural := Lib_File_Directory'Last;
7219
7220 begin
7221 -- For directories, Normalize_Pathname may or may not put
7222 -- a directory separator at the end, depending on its input.
7223 -- Remove any last directory separator before comparison.
7224 -- Returns True only if the two directories are the same.
7225
7226 if Object_Directory (Olast) = Directory_Separator then
7227 Olast := Olast - 1;
7228 end if;
7229
7230 if Lib_File_Directory (Llast) = Directory_Separator then
7231 Llast := Llast - 1;
7232 end if;
7233
7234 return Object_Directory (Object_Directory'First .. Olast) =
7235 Lib_File_Directory (Lib_File_Directory'First .. Llast);
7236 end;
7237 end if;
7238 end;
7239 end if;
7240
7241 -- When the source is not in a project file, always return True
7242
7243 return True;
7244 end Is_In_Object_Directory;
7245
7246 ----------
7247 -- Link --
7248 ----------
7249
7250 procedure Link
7251 (ALI_File : File_Name_Type;
7252 Args : Argument_List;
7253 Success : out Boolean)
7254 is
7255 Link_Args : Argument_List (1 .. Args'Length + 1);
7256
7257 begin
7258 Get_Name_String (ALI_File);
7259 Link_Args (1) := new String'(Name_Buffer (1 .. Name_Len));
7260
7261 Link_Args (2 .. Args'Length + 1) := Args;
7262
7263 GNAT.OS_Lib.Normalize_Arguments (Link_Args);
7264
7265 Display (Gnatlink.all, Link_Args);
7266
7267 if Gnatlink_Path = null then
7268 Make_Failed ("error, unable to locate " & Gnatlink.all);
7269 end if;
7270
7271 GNAT.OS_Lib.Spawn (Gnatlink_Path.all, Link_Args, Success);
7272 end Link;
7273
7274 ---------------------------
7275 -- List_Bad_Compilations --
7276 ---------------------------
7277
7278 procedure List_Bad_Compilations is
7279 begin
7280 for J in Bad_Compilation.First .. Bad_Compilation.Last loop
7281 if Bad_Compilation.Table (J).File = No_File then
7282 null;
7283 elsif not Bad_Compilation.Table (J).Found then
7284 Inform (Bad_Compilation.Table (J).File, "not found");
7285 else
7286 Inform (Bad_Compilation.Table (J).File, "compilation error");
7287 end if;
7288 end loop;
7289 end List_Bad_Compilations;
7290
7291 -----------------
7292 -- List_Depend --
7293 -----------------
7294
7295 procedure List_Depend is
7296 Lib_Name : File_Name_Type;
7297 Obj_Name : File_Name_Type;
7298 Src_Name : File_Name_Type;
7299
7300 Len : Natural;
7301 Line_Pos : Natural;
7302 Line_Size : constant := 77;
7303
7304 begin
7305 Set_Standard_Output;
7306
7307 for A in ALIs.First .. ALIs.Last loop
7308 Lib_Name := ALIs.Table (A).Afile;
7309
7310 -- We have to provide the full library file name in In_Place_Mode
7311
7312 if In_Place_Mode then
7313 Lib_Name := Full_Lib_File_Name (Lib_Name);
7314 end if;
7315
7316 Obj_Name := Object_File_Name (Lib_Name);
7317 Write_Name (Obj_Name);
7318 Write_Str (" :");
7319
7320 Get_Name_String (Obj_Name);
7321 Len := Name_Len;
7322 Line_Pos := Len + 2;
7323
7324 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
7325 Src_Name := Sdep.Table (D).Sfile;
7326
7327 if Is_Internal_File_Name (Src_Name)
7328 and then not Check_Readonly_Files
7329 then
7330 null;
7331 else
7332 if not Quiet_Output then
7333 Src_Name := Full_Source_Name (Src_Name);
7334 end if;
7335
7336 Get_Name_String (Src_Name);
7337 Len := Name_Len;
7338
7339 if Line_Pos + Len + 1 > Line_Size then
7340 Write_Str (" \");
7341 Write_Eol;
7342 Line_Pos := 0;
7343 end if;
7344
7345 Line_Pos := Line_Pos + Len + 1;
7346
7347 Write_Str (" ");
7348 Write_Name (Src_Name);
7349 end if;
7350 end loop;
7351
7352 Write_Eol;
7353 end loop;
7354
7355 if not Commands_To_Stdout then
7356 Set_Standard_Error;
7357 end if;
7358 end List_Depend;
7359
7360 -----------------
7361 -- Make_Failed --
7362 -----------------
7363
7364 procedure Make_Failed (S : String) is
7365 begin
7366 Delete_All_Temp_Files;
7367 Osint.Fail (S);
7368 end Make_Failed;
7369
7370 --------------------
7371 -- Mark_Directory --
7372 --------------------
7373
7374 procedure Mark_Directory
7375 (Dir : String;
7376 Mark : Lib_Mark_Type;
7377 On_Command_Line : Boolean)
7378 is
7379 N : Name_Id;
7380 B : Byte;
7381
7382 function Base_Directory return String;
7383 -- If Dir comes from the command line, empty string (relative paths are
7384 -- resolved with respect to the current directory), else return the main
7385 -- project's directory.
7386
7387 --------------------
7388 -- Base_Directory --
7389 --------------------
7390
7391 function Base_Directory return String is
7392 begin
7393 if On_Command_Line then
7394 return "";
7395 else
7396 return Get_Name_String (Main_Project.Directory.Display_Name);
7397 end if;
7398 end Base_Directory;
7399
7400 Real_Path : constant String := Normalize_Pathname (Dir, Base_Directory);
7401
7402 -- Start of processing for Mark_Directory
7403
7404 begin
7405 Name_Len := 0;
7406
7407 if Real_Path'Length = 0 then
7408 Add_Str_To_Name_Buffer (Dir);
7409
7410 else
7411 Add_Str_To_Name_Buffer (Real_Path);
7412 end if;
7413
7414 -- Last character is supposed to be a directory separator
7415
7416 if not Is_Directory_Separator (Name_Buffer (Name_Len)) then
7417 Add_Char_To_Name_Buffer (Directory_Separator);
7418 end if;
7419
7420 -- Add flags to the already existing flags
7421
7422 N := Name_Find;
7423 B := Get_Name_Table_Byte (N);
7424 Set_Name_Table_Byte (N, B or Mark);
7425 end Mark_Directory;
7426
7427 ----------------------
7428 -- Process_Multilib --
7429 ----------------------
7430
7431 procedure Process_Multilib
7432 (Project_Node_Tree : Project_Node_Tree_Ref)
7433 is
7434 Output_FD : File_Descriptor;
7435 Output_Name : String_Access;
7436 Arg_Index : Natural := 0;
7437 Success : Boolean := False;
7438 Return_Code : Integer := 0;
7439 Multilib_Gcc_Path : String_Access;
7440 Multilib_Gcc : String_Access;
7441 N_Read : Integer := 0;
7442 Line : String (1 .. 1000);
7443 Args : Argument_List (1 .. N_M_Switch + 1);
7444
7445 begin
7446 pragma Assert (N_M_Switch > 0 and RTS_Specified = null);
7447
7448 -- In case we detected a multilib switch and the user has not
7449 -- manually specified a specific RTS we emulate the following command:
7450 -- gnatmake $FLAGS --RTS=$(gcc -print-multi-directory $FLAGS)
7451
7452 -- First select the flags which might have an impact on multilib
7453 -- processing. Note that this is an heuristic selection and it
7454 -- will need to be maintained over time. The condition has to
7455 -- be kept synchronized with N_M_Switch counting in Scan_Make_Arg.
7456
7457 for Next_Arg in 1 .. Argument_Count loop
7458 declare
7459 Argv : constant String := Argument (Next_Arg);
7460 begin
7461 if Argv'Length > 2
7462 and then Argv (1) = '-'
7463 and then Argv (2) = 'm'
7464 and then Argv /= "-margs"
7465
7466 -- Ignore -mieee to avoid spawning an extra gcc in this case
7467
7468 and then Argv /= "-mieee"
7469 then
7470 Arg_Index := Arg_Index + 1;
7471 Args (Arg_Index) := new String'(Argv);
7472 end if;
7473 end;
7474 end loop;
7475
7476 pragma Assert (Arg_Index = N_M_Switch);
7477
7478 Args (Args'Last) := new String'("-print-multi-directory");
7479
7480 -- Call the GCC driver with the collected flags and save its
7481 -- output. Alternate design would be to link in gnatmake the
7482 -- relevant part of the GCC driver.
7483
7484 if Saved_Gcc /= null then
7485 Multilib_Gcc := Saved_Gcc;
7486 else
7487 Multilib_Gcc := Gcc;
7488 end if;
7489
7490 Multilib_Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Multilib_Gcc.all);
7491
7492 Create_Temp_Output_File (Output_FD, Output_Name);
7493
7494 if Output_FD = Invalid_FD then
7495 return;
7496 end if;
7497
7498 GNAT.OS_Lib.Spawn
7499 (Multilib_Gcc_Path.all, Args, Output_FD, Return_Code, False);
7500 Close (Output_FD);
7501
7502 if Return_Code /= 0 then
7503 return;
7504 end if;
7505
7506 -- Parse the GCC driver output which is a single line, removing CR/LF
7507
7508 Output_FD := Open_Read (Output_Name.all, Binary);
7509
7510 if Output_FD = Invalid_FD then
7511 return;
7512 end if;
7513
7514 N_Read := Read (Output_FD, Line (1)'Address, Line'Length);
7515 Close (Output_FD);
7516 Delete_File (Output_Name.all, Success);
7517
7518 for J in reverse 1 .. N_Read loop
7519 if Line (J) = ASCII.CR or else Line (J) = ASCII.LF then
7520 N_Read := N_Read - 1;
7521 else
7522 exit;
7523 end if;
7524 end loop;
7525
7526 -- In case the standard RTS is selected do nothing
7527
7528 if N_Read = 0 or else Line (1 .. N_Read) = "." then
7529 return;
7530 end if;
7531
7532 -- Otherwise add -margs --RTS=output
7533
7534 Scan_Make_Arg (Project_Node_Tree, "-margs", And_Save => True);
7535 Scan_Make_Arg
7536 (Project_Node_Tree, "--RTS=" & Line (1 .. N_Read), And_Save => True);
7537 end Process_Multilib;
7538
7539 -----------------------------
7540 -- Recursive_Compute_Depth --
7541 -----------------------------
7542
7543 procedure Recursive_Compute_Depth (Project : Project_Id) is
7544 use Project_Boolean_Htable;
7545 Seen : Project_Boolean_Htable.Instance := Project_Boolean_Htable.Nil;
7546
7547 procedure Recurse (Prj : Project_Id; Depth : Natural);
7548 -- Recursive procedure that does the work, keeping track of the depth
7549
7550 -------------
7551 -- Recurse --
7552 -------------
7553
7554 procedure Recurse (Prj : Project_Id; Depth : Natural) is
7555 List : Project_List;
7556 Proj : Project_Id;
7557
7558 begin
7559 if Prj.Depth >= Depth or else Get (Seen, Prj) then
7560 return;
7561 end if;
7562
7563 -- We need a test to avoid infinite recursions with limited withs:
7564 -- If we have A -> B -> A, then when set level of A to n, we try and
7565 -- set level of B to n+1, and then level of A to n + 2, ...
7566
7567 Set (Seen, Prj, True);
7568
7569 Prj.Depth := Depth;
7570
7571 -- Visit each imported project
7572
7573 List := Prj.Imported_Projects;
7574 while List /= null loop
7575 Proj := List.Project;
7576 List := List.Next;
7577 Recurse (Prj => Proj, Depth => Depth + 1);
7578 end loop;
7579
7580 -- We again allow changing the depth of this project later on if it
7581 -- is in fact imported by a lower-level project.
7582
7583 Set (Seen, Prj, False);
7584 end Recurse;
7585
7586 Proj : Project_List;
7587
7588 -- Start of processing for Recursive_Compute_Depth
7589
7590 begin
7591 Proj := Project_Tree.Projects;
7592 while Proj /= null loop
7593 Proj.Project.Depth := 0;
7594 Proj := Proj.Next;
7595 end loop;
7596
7597 Recurse (Project, Depth => 1);
7598 Reset (Seen);
7599 end Recursive_Compute_Depth;
7600
7601 -------------------------------
7602 -- Report_Compilation_Failed --
7603 -------------------------------
7604
7605 procedure Report_Compilation_Failed is
7606 begin
7607 Delete_All_Temp_Files;
7608 Exit_Program (E_Fatal);
7609 end Report_Compilation_Failed;
7610
7611 ------------------------
7612 -- Sigint_Intercepted --
7613 ------------------------
7614
7615 procedure Sigint_Intercepted is
7616 SIGINT : constant := 2;
7617
7618 begin
7619 Set_Standard_Error;
7620 Write_Line ("*** Interrupted ***");
7621
7622 -- Send SIGINT to all outstanding compilation processes spawned
7623
7624 for J in 1 .. Outstanding_Compiles loop
7625 Kill (Running_Compile (J).Pid, SIGINT, 1);
7626 end loop;
7627
7628 Delete_All_Temp_Files;
7629 OS_Exit (1);
7630 -- ??? OS_Exit (1) is equivalent to Exit_Program (E_No_Compile),
7631 -- shouldn't that be Exit_Program (E_Abort) instead?
7632 end Sigint_Intercepted;
7633
7634 -------------------
7635 -- Scan_Make_Arg --
7636 -------------------
7637
7638 procedure Scan_Make_Arg
7639 (Project_Node_Tree : Project_Node_Tree_Ref;
7640 Argv : String;
7641 And_Save : Boolean)
7642 is
7643 Success : Boolean;
7644
7645 begin
7646 Gnatmake_Switch_Found := True;
7647
7648 pragma Assert (Argv'First = 1);
7649
7650 if Argv'Length = 0 then
7651 return;
7652 end if;
7653
7654 -- If the previous switch has set the Project_File_Name_Present flag
7655 -- (that is we have seen a -P alone), then the next argument is the name
7656 -- of the project file.
7657
7658 if Project_File_Name_Present and then Project_File_Name = null then
7659 if Argv (1) = '-' then
7660 Make_Failed ("project file name missing after -P");
7661
7662 else
7663 Project_File_Name_Present := False;
7664 Project_File_Name := new String'(Argv);
7665 end if;
7666
7667 -- If the previous switch has set the Output_File_Name_Present flag
7668 -- (that is we have seen a -o), then the next argument is the name of
7669 -- the output executable.
7670
7671 elsif Output_File_Name_Present
7672 and then not Output_File_Name_Seen
7673 then
7674 Output_File_Name_Seen := True;
7675
7676 if Argv (1) = '-' then
7677 Make_Failed ("output file name missing after -o");
7678
7679 else
7680 Add_Switch ("-o", Linker, And_Save => And_Save);
7681 Add_Switch (Executable_Name (Argv), Linker, And_Save => And_Save);
7682 end if;
7683
7684 -- If the previous switch has set the Object_Directory_Present flag
7685 -- (that is we have seen a -D), then the next argument is the path name
7686 -- of the object directory.
7687
7688 elsif Object_Directory_Present
7689 and then not Object_Directory_Seen
7690 then
7691 Object_Directory_Seen := True;
7692
7693 if Argv (1) = '-' then
7694 Make_Failed ("object directory path name missing after -D");
7695
7696 elsif not Is_Directory (Argv) then
7697 Make_Failed ("cannot find object directory """ & Argv & """");
7698
7699 else
7700 -- Record the object directory. Make sure it ends with a directory
7701 -- separator.
7702
7703 declare
7704 Norm : constant String := Normalize_Pathname (Argv);
7705
7706 begin
7707 if Norm (Norm'Last) = Directory_Separator then
7708 Object_Directory_Path := new String'(Norm);
7709 else
7710 Object_Directory_Path :=
7711 new String'(Norm & Directory_Separator);
7712 end if;
7713
7714 Add_Lib_Search_Dir (Norm);
7715
7716 -- Specify the object directory to the binder
7717
7718 Add_Switch ("-aO" & Norm, Binder, And_Save => And_Save);
7719 end;
7720
7721 end if;
7722
7723 -- Then check if we are dealing with -cargs/-bargs/-largs/-margs
7724
7725 elsif Argv = "-bargs"
7726 or else
7727 Argv = "-cargs"
7728 or else
7729 Argv = "-largs"
7730 or else
7731 Argv = "-margs"
7732 then
7733 case Argv (2) is
7734 when 'c' => Program_Args := Compiler;
7735 when 'b' => Program_Args := Binder;
7736 when 'l' => Program_Args := Linker;
7737 when 'm' => Program_Args := None;
7738
7739 when others =>
7740 raise Program_Error;
7741 end case;
7742
7743 -- A special test is needed for the -o switch within a -largs since that
7744 -- is another way to specify the name of the final executable.
7745
7746 elsif Program_Args = Linker
7747 and then Argv = "-o"
7748 then
7749 Make_Failed ("switch -o not allowed within a -largs. " &
7750 "Use -o directly.");
7751
7752 -- Check to see if we are reading switches after a -cargs, -bargs or
7753 -- -largs switch. If so, save it.
7754
7755 elsif Program_Args /= None then
7756
7757 -- Check to see if we are reading -I switches in order
7758 -- to take into account in the src & lib search directories.
7759
7760 if Argv'Length > 2 and then Argv (1 .. 2) = "-I" then
7761 if Argv (3 .. Argv'Last) = "-" then
7762 Look_In_Primary_Dir := False;
7763
7764 elsif Program_Args = Compiler then
7765 if Argv (3 .. Argv'Last) /= "-" then
7766 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7767 end if;
7768
7769 elsif Program_Args = Binder then
7770 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7771 end if;
7772 end if;
7773
7774 Add_Switch (Argv, Program_Args, And_Save => And_Save);
7775
7776 -- Handle non-default compiler, binder, linker, and handle --RTS switch
7777
7778 elsif Argv'Length > 2 and then Argv (1 .. 2) = "--" then
7779 if Argv'Length > 6
7780 and then Argv (1 .. 6) = "--GCC="
7781 then
7782 declare
7783 Program_Args : constant Argument_List_Access :=
7784 Argument_String_To_List
7785 (Argv (7 .. Argv'Last));
7786
7787 begin
7788 if And_Save then
7789 Saved_Gcc := new String'(Program_Args.all (1).all);
7790 else
7791 Gcc := new String'(Program_Args.all (1).all);
7792 end if;
7793
7794 for J in 2 .. Program_Args.all'Last loop
7795 Add_Switch
7796 (Program_Args.all (J).all, Compiler, And_Save => And_Save);
7797 end loop;
7798 end;
7799
7800 elsif Argv'Length > 11
7801 and then Argv (1 .. 11) = "--GNATBIND="
7802 then
7803 declare
7804 Program_Args : constant Argument_List_Access :=
7805 Argument_String_To_List
7806 (Argv (12 .. Argv'Last));
7807
7808 begin
7809 if And_Save then
7810 Saved_Gnatbind := new String'(Program_Args.all (1).all);
7811 else
7812 Gnatbind := new String'(Program_Args.all (1).all);
7813 end if;
7814
7815 for J in 2 .. Program_Args.all'Last loop
7816 Add_Switch
7817 (Program_Args.all (J).all, Binder, And_Save => And_Save);
7818 end loop;
7819 end;
7820
7821 elsif Argv'Length > 11
7822 and then Argv (1 .. 11) = "--GNATLINK="
7823 then
7824 declare
7825 Program_Args : constant Argument_List_Access :=
7826 Argument_String_To_List
7827 (Argv (12 .. Argv'Last));
7828 begin
7829 if And_Save then
7830 Saved_Gnatlink := new String'(Program_Args.all (1).all);
7831 else
7832 Gnatlink := new String'(Program_Args.all (1).all);
7833 end if;
7834
7835 for J in 2 .. Program_Args.all'Last loop
7836 Add_Switch (Program_Args.all (J).all, Linker);
7837 end loop;
7838 end;
7839
7840 elsif Argv'Length >= 5 and then
7841 Argv (1 .. 5) = "--RTS"
7842 then
7843 Add_Switch (Argv, Compiler, And_Save => And_Save);
7844 Add_Switch (Argv, Binder, And_Save => And_Save);
7845
7846 if Argv'Length <= 6 or else Argv (6) /= '=' then
7847 Make_Failed ("missing path for --RTS");
7848
7849 else
7850 -- Check that this is the first time we see this switch or
7851 -- if it is not the first time, the same path is specified.
7852
7853 if RTS_Specified = null then
7854 RTS_Specified := new String'(Argv (7 .. Argv'Last));
7855
7856 elsif RTS_Specified.all /= Argv (7 .. Argv'Last) then
7857 Make_Failed ("--RTS cannot be specified multiple times");
7858 end if;
7859
7860 -- Valid --RTS switch
7861
7862 No_Stdinc := True;
7863 No_Stdlib := True;
7864 RTS_Switch := True;
7865
7866 declare
7867 Src_Path_Name : constant String_Ptr :=
7868 Get_RTS_Search_Dir
7869 (Argv (7 .. Argv'Last), Include);
7870
7871 Lib_Path_Name : constant String_Ptr :=
7872 Get_RTS_Search_Dir
7873 (Argv (7 .. Argv'Last), Objects);
7874
7875 begin
7876 if Src_Path_Name /= null
7877 and then Lib_Path_Name /= null
7878 then
7879 -- Set RTS_*_Path_Name variables, so that correct direct-
7880 -- ories will be set when Osint.Add_Default_Search_Dirs
7881 -- is called later.
7882
7883 RTS_Src_Path_Name := Src_Path_Name;
7884 RTS_Lib_Path_Name := Lib_Path_Name;
7885
7886 elsif Src_Path_Name = null
7887 and then Lib_Path_Name = null
7888 then
7889 Make_Failed ("RTS path not valid: missing " &
7890 "adainclude and adalib directories");
7891
7892 elsif Src_Path_Name = null then
7893 Make_Failed ("RTS path not valid: missing adainclude " &
7894 "directory");
7895
7896 elsif Lib_Path_Name = null then
7897 Make_Failed ("RTS path not valid: missing adalib " &
7898 "directory");
7899 end if;
7900 end;
7901 end if;
7902
7903 elsif Argv'Length >= 8 and then
7904 Argv (1 .. 8) = "--param="
7905 then
7906 Add_Switch (Argv, Compiler, And_Save => And_Save);
7907 Add_Switch (Argv, Linker, And_Save => And_Save);
7908
7909 else
7910 Scan_Make_Switches (Project_Node_Tree, Argv, Success);
7911 end if;
7912
7913 -- If we have seen a regular switch process it
7914
7915 elsif Argv (1) = '-' then
7916 if Argv'Length = 1 then
7917 Make_Failed ("switch character cannot be followed by a blank");
7918
7919 -- Incorrect switches that should start with "--"
7920
7921 elsif (Argv'Length > 5 and then Argv (1 .. 5) = "-RTS=")
7922 or else (Argv'Length > 5 and then Argv (1 .. 5) = "-GCC=")
7923 or else (Argv'Length > 8 and then Argv (1 .. 7) = "-param=")
7924 or else (Argv'Length > 10 and then Argv (1 .. 10) = "-GNATLINK=")
7925 or else (Argv'Length > 10 and then Argv (1 .. 10) = "-GNATBIND=")
7926 then
7927 Make_Failed ("option " & Argv & " should start with '--'");
7928
7929 -- -I-
7930
7931 elsif Argv (2 .. Argv'Last) = "I-" then
7932 Look_In_Primary_Dir := False;
7933
7934 -- Forbid -?- or -??- where ? is any character
7935
7936 elsif (Argv'Length = 3 and then Argv (3) = '-')
7937 or else (Argv'Length = 4 and then Argv (4) = '-')
7938 then
7939 Make_Failed
7940 ("trailing ""-"" at the end of " & Argv & " forbidden.");
7941
7942 -- -Idir
7943
7944 elsif Argv (2) = 'I' then
7945 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7946 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7947 Add_Switch (Argv, Compiler, And_Save => And_Save);
7948 Add_Switch (Argv, Binder, And_Save => And_Save);
7949
7950 -- -aIdir (to gcc this is like a -I switch)
7951
7952 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aI" then
7953 Add_Source_Search_Dir (Argv (4 .. Argv'Last), And_Save);
7954 Add_Switch
7955 ("-I" & Argv (4 .. Argv'Last), Compiler, And_Save => And_Save);
7956 Add_Switch (Argv, Binder, And_Save => And_Save);
7957
7958 -- -aOdir
7959
7960 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aO" then
7961 Add_Library_Search_Dir (Argv (4 .. Argv'Last), And_Save);
7962 Add_Switch (Argv, Binder, And_Save => And_Save);
7963
7964 -- -aLdir (to gnatbind this is like a -aO switch)
7965
7966 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aL" then
7967 Mark_Directory (Argv (4 .. Argv'Last), Ada_Lib_Dir, And_Save);
7968 Add_Library_Search_Dir (Argv (4 .. Argv'Last), And_Save);
7969 Add_Switch
7970 ("-aO" & Argv (4 .. Argv'Last), Binder, And_Save => And_Save);
7971
7972 -- -aamp_target=...
7973
7974 elsif Argv'Length >= 13 and then Argv (2 .. 13) = "aamp_target=" then
7975 Add_Switch (Argv, Compiler, And_Save => And_Save);
7976
7977 -- Set the aamp_target environment variable so that the binder and
7978 -- linker will use the proper target library. This is consistent
7979 -- with how things work when -aamp_target is passed on the command
7980 -- line to gnaampmake.
7981
7982 Setenv ("aamp_target", Argv (14 .. Argv'Last));
7983
7984 -- -Adir (to gnatbind this is like a -aO switch, to gcc like a -I)
7985
7986 elsif Argv (2) = 'A' then
7987 Mark_Directory (Argv (3 .. Argv'Last), Ada_Lib_Dir, And_Save);
7988 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7989 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7990 Add_Switch
7991 ("-I" & Argv (3 .. Argv'Last), Compiler, And_Save => And_Save);
7992 Add_Switch
7993 ("-aO" & Argv (3 .. Argv'Last), Binder, And_Save => And_Save);
7994
7995 -- -Ldir
7996
7997 elsif Argv (2) = 'L' then
7998 Add_Switch (Argv, Linker, And_Save => And_Save);
7999
8000 -- For -gxxxxx, -pg, -mxxx, -fxxx: give the switch to both the
8001 -- compiler and the linker (except for -gnatxxx which is only for the
8002 -- compiler). Some of the -mxxx (for example -m64) and -fxxx (for
8003 -- example -ftest-coverage for gcov) need to be used when compiling
8004 -- the binder generated files, and using all these gcc switches for
8005 -- the binder generated files should not be a problem.
8006
8007 elsif
8008 (Argv (2) = 'g' and then (Argv'Last < 5
8009 or else Argv (2 .. 5) /= "gnat"))
8010 or else Argv (2 .. Argv'Last) = "pg"
8011 or else (Argv (2) = 'm' and then Argv'Last > 2)
8012 or else (Argv (2) = 'f' and then Argv'Last > 2)
8013 then
8014 Add_Switch (Argv, Compiler, And_Save => And_Save);
8015 Add_Switch (Argv, Linker, And_Save => And_Save);
8016
8017 -- The following condition has to be kept synchronized with
8018 -- the Process_Multilib one.
8019
8020 if Argv (2) = 'm'
8021 and then Argv /= "-mieee"
8022 then
8023 N_M_Switch := N_M_Switch + 1;
8024 end if;
8025
8026 -- -C=<mapping file>
8027
8028 elsif Argv'Last > 2 and then Argv (2) = 'C' then
8029 if And_Save then
8030 if Argv (3) /= '=' or else Argv'Last <= 3 then
8031 Make_Failed ("illegal switch " & Argv);
8032 end if;
8033
8034 Gnatmake_Mapping_File := new String'(Argv (4 .. Argv'Last));
8035 end if;
8036
8037 -- -D
8038
8039 elsif Argv'Last = 2 and then Argv (2) = 'D' then
8040 if Project_File_Name /= null then
8041 Make_Failed
8042 ("-D cannot be used in conjunction with a project file");
8043
8044 else
8045 Scan_Make_Switches (Project_Node_Tree, Argv, Success);
8046 end if;
8047
8048 -- -d
8049
8050 elsif Argv (2) = 'd' and then Argv'Last = 2 then
8051 Display_Compilation_Progress := True;
8052
8053 -- -i
8054
8055 elsif Argv'Last = 2 and then Argv (2) = 'i' then
8056 if Project_File_Name /= null then
8057 Make_Failed
8058 ("-i cannot be used in conjunction with a project file");
8059 else
8060 Scan_Make_Switches (Project_Node_Tree, Argv, Success);
8061 end if;
8062
8063 -- -j (need to save the result)
8064
8065 elsif Argv (2) = 'j' then
8066 Scan_Make_Switches (Project_Node_Tree, Argv, Success);
8067
8068 if And_Save then
8069 Saved_Maximum_Processes := Maximum_Processes;
8070 end if;
8071
8072 -- -m
8073
8074 elsif Argv (2) = 'm' and then Argv'Last = 2 then
8075 Minimal_Recompilation := True;
8076
8077 -- -u
8078
8079 elsif Argv (2) = 'u' and then Argv'Last = 2 then
8080 Unique_Compile := True;
8081 Compile_Only := True;
8082 Do_Bind_Step := False;
8083 Do_Link_Step := False;
8084
8085 -- -U
8086
8087 elsif Argv (2) = 'U'
8088 and then Argv'Last = 2
8089 then
8090 Unique_Compile_All_Projects := True;
8091 Unique_Compile := True;
8092 Compile_Only := True;
8093 Do_Bind_Step := False;
8094 Do_Link_Step := False;
8095
8096 -- -Pprj or -P prj (only once, and only on the command line)
8097
8098 elsif Argv (2) = 'P' then
8099 if Project_File_Name /= null then
8100 Make_Failed ("cannot have several project files specified");
8101
8102 elsif Object_Directory_Path /= null then
8103 Make_Failed
8104 ("-D cannot be used in conjunction with a project file");
8105
8106 elsif In_Place_Mode then
8107 Make_Failed
8108 ("-i cannot be used in conjunction with a project file");
8109
8110 elsif not And_Save then
8111
8112 -- It could be a tool other than gnatmake (e.g. gnatdist)
8113 -- or a -P switch inside a project file.
8114
8115 Fail
8116 ("either the tool is not ""project-aware"" or " &
8117 "a project file is specified inside a project file");
8118
8119 elsif Argv'Last = 2 then
8120
8121 -- -P is used alone: the project file name is the next option
8122
8123 Project_File_Name_Present := True;
8124
8125 else
8126 Project_File_Name := new String'(Argv (3 .. Argv'Last));
8127 end if;
8128
8129 -- -vPx (verbosity of the parsing of the project files)
8130
8131 elsif Argv'Last = 4
8132 and then Argv (2 .. 3) = "vP"
8133 and then Argv (4) in '0' .. '2'
8134 then
8135 if And_Save then
8136 case Argv (4) is
8137 when '0' =>
8138 Current_Verbosity := Prj.Default;
8139 when '1' =>
8140 Current_Verbosity := Prj.Medium;
8141 when '2' =>
8142 Current_Verbosity := Prj.High;
8143 when others =>
8144 null;
8145 end case;
8146 end if;
8147
8148 -- -Xext=val (External assignment)
8149
8150 elsif Argv (2) = 'X'
8151 and then Is_External_Assignment (Project_Node_Tree, Argv)
8152 then
8153 -- Is_External_Assignment has side effects when it returns True
8154
8155 null;
8156
8157 -- If -gnath is present, then generate the usage information right
8158 -- now and do not pass this option on to the compiler calls.
8159
8160 elsif Argv = "-gnath" then
8161 Usage;
8162
8163 -- If -gnatc is specified, make sure the bind and link steps are not
8164 -- executed.
8165
8166 elsif Argv'Length >= 6 and then Argv (2 .. 6) = "gnatc" then
8167
8168 -- If -gnatc is specified, make sure the bind and link steps are
8169 -- not executed.
8170
8171 Add_Switch (Argv, Compiler, And_Save => And_Save);
8172 Operating_Mode := Check_Semantics;
8173 Check_Object_Consistency := False;
8174 Compile_Only := True;
8175 Do_Bind_Step := False;
8176 Do_Link_Step := False;
8177
8178 elsif Argv (2 .. Argv'Last) = "nostdlib" then
8179
8180 -- Don't pass -nostdlib to gnatlink, it will disable
8181 -- linking with all standard library files.
8182
8183 No_Stdlib := True;
8184
8185 Add_Switch (Argv, Compiler, And_Save => And_Save);
8186 Add_Switch (Argv, Binder, And_Save => And_Save);
8187
8188 elsif Argv (2 .. Argv'Last) = "nostdinc" then
8189
8190 -- Pass -nostdinc to the Compiler and to gnatbind
8191
8192 No_Stdinc := True;
8193 Add_Switch (Argv, Compiler, And_Save => And_Save);
8194 Add_Switch (Argv, Binder, And_Save => And_Save);
8195
8196 -- All other switches are processed by Scan_Make_Switches. If the
8197 -- call returns with Gnatmake_Switch_Found = False, then the switch
8198 -- is passed to the compiler.
8199
8200 else
8201 Scan_Make_Switches
8202 (Project_Node_Tree, Argv, Gnatmake_Switch_Found);
8203
8204 if not Gnatmake_Switch_Found then
8205 Add_Switch (Argv, Compiler, And_Save => And_Save);
8206 end if;
8207 end if;
8208
8209 -- If not a switch it must be a file name
8210
8211 else
8212 Add_File (Argv);
8213 Mains.Add_Main (Argv);
8214 end if;
8215 end Scan_Make_Arg;
8216
8217 -----------------
8218 -- Switches_Of --
8219 -----------------
8220
8221 function Switches_Of
8222 (Source_File : File_Name_Type;
8223 Source_File_Name : String;
8224 Source_Index : Int;
8225 Project : Project_Id;
8226 In_Package : Package_Id;
8227 Allow_ALI : Boolean) return Variable_Value
8228 is
8229 Lang : constant Language_Ptr := Get_Language_From_Name (Project, "ada");
8230
8231 Switches : Variable_Value;
8232
8233 Defaults : constant Array_Element_Id :=
8234 Prj.Util.Value_Of
8235 (Name => Name_Default_Switches,
8236 In_Arrays =>
8237 Project_Tree.Packages.Table
8238 (In_Package).Decl.Arrays,
8239 In_Tree => Project_Tree);
8240
8241 Switches_Array : constant Array_Element_Id :=
8242 Prj.Util.Value_Of
8243 (Name => Name_Switches,
8244 In_Arrays =>
8245 Project_Tree.Packages.Table
8246 (In_Package).Decl.Arrays,
8247 In_Tree => Project_Tree);
8248
8249 begin
8250 -- First, try Switches (<file name>)
8251
8252 Switches :=
8253 Prj.Util.Value_Of
8254 (Index => Name_Id (Source_File),
8255 Src_Index => Source_Index,
8256 In_Array => Switches_Array,
8257 In_Tree => Project_Tree);
8258
8259 -- Check also without the suffix
8260
8261 if Switches = Nil_Variable_Value
8262 and then Lang /= null
8263 then
8264 declare
8265 Naming : Lang_Naming_Data renames Lang.Config.Naming_Data;
8266 Name : String (1 .. Source_File_Name'Length + 3);
8267 Last : Positive := Source_File_Name'Length;
8268 Spec_Suffix : constant String :=
8269 Get_Name_String (Naming.Spec_Suffix);
8270 Body_Suffix : constant String :=
8271 Get_Name_String (Naming.Body_Suffix);
8272 Truncated : Boolean := False;
8273
8274 begin
8275 Name (1 .. Last) := Source_File_Name;
8276
8277 if Last > Body_Suffix'Length
8278 and then Name (Last - Body_Suffix'Length + 1 .. Last) =
8279 Body_Suffix
8280 then
8281 Truncated := True;
8282 Last := Last - Body_Suffix'Length;
8283 end if;
8284
8285 if not Truncated
8286 and then Last > Spec_Suffix'Length
8287 and then Name (Last - Spec_Suffix'Length + 1 .. Last) =
8288 Spec_Suffix
8289 then
8290 Truncated := True;
8291 Last := Last - Spec_Suffix'Length;
8292 end if;
8293
8294 if Truncated then
8295 Name_Len := 0;
8296 Add_Str_To_Name_Buffer (Name (1 .. Last));
8297 Switches :=
8298 Prj.Util.Value_Of
8299 (Index => Name_Find,
8300 Src_Index => 0,
8301 In_Array => Switches_Array,
8302 In_Tree => Project_Tree);
8303
8304 if Switches = Nil_Variable_Value and then Allow_ALI then
8305 Last := Source_File_Name'Length;
8306
8307 while Name (Last) /= '.' loop
8308 Last := Last - 1;
8309 end loop;
8310
8311 Name_Len := 0;
8312 Add_Str_To_Name_Buffer (Name (1 .. Last));
8313 Add_Str_To_Name_Buffer ("ali");
8314
8315 Switches :=
8316 Prj.Util.Value_Of
8317 (Index => Name_Find,
8318 Src_Index => 0,
8319 In_Array => Switches_Array,
8320 In_Tree => Project_Tree);
8321 end if;
8322 end if;
8323 end;
8324 end if;
8325
8326 -- Next, try Switches ("Ada")
8327
8328 if Switches = Nil_Variable_Value then
8329 Switches :=
8330 Prj.Util.Value_Of
8331 (Index => Name_Ada,
8332 Src_Index => 0,
8333 In_Array => Switches_Array,
8334 In_Tree => Project_Tree,
8335 Force_Lower_Case_Index => True);
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 -- Next, try Switches (others)
8343
8344 if Switches = Nil_Variable_Value then
8345 Switches :=
8346 Prj.Util.Value_Of
8347 (Index => All_Other_Names,
8348 Src_Index => 0,
8349 In_Array => Switches_Array,
8350 In_Tree => Project_Tree);
8351
8352 if Switches /= Nil_Variable_Value then
8353 Switch_May_Be_Passed_To_The_Compiler := False;
8354 end if;
8355 end if;
8356
8357 -- And finally, Default_Switches ("Ada")
8358
8359 if Switches = Nil_Variable_Value then
8360 Switches :=
8361 Prj.Util.Value_Of
8362 (Index => Name_Ada,
8363 Src_Index => 0,
8364 In_Array => Defaults,
8365 In_Tree => Project_Tree);
8366 end if;
8367
8368 return Switches;
8369 end Switches_Of;
8370
8371 -----------
8372 -- Usage --
8373 -----------
8374
8375 procedure Usage is
8376 begin
8377 if Usage_Needed then
8378 Usage_Needed := False;
8379 Makeusg;
8380 end if;
8381 end Usage;
8382
8383 begin
8384 -- Make sure that in case of failure, the temp files will be deleted
8385
8386 Prj.Com.Fail := Make_Failed'Access;
8387 MLib.Fail := Make_Failed'Access;
8388 Makeutl.Do_Fail := Make_Failed'Access;
8389 end Make;