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