2004-12-07 Eric Christopher <echristo@redhat.com>
[official-gcc.git] / gcc / ada / make.adb
blob473c73cdfe0f0cb16f41bd2f8b8926ea6ff7f129
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- M A K E --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2004 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
27 with ALI; use ALI;
28 with ALI.Util; use ALI.Util;
29 with Csets;
30 with Debug;
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.Prj;
40 with MLib.Tgt; use MLib.Tgt;
41 with MLib.Utl;
42 with Namet; use Namet;
43 with Opt; use Opt;
44 with Osint.M; use Osint.M;
45 with Osint; use Osint;
46 with Gnatvsn;
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;
59 with Tempdir;
61 with Ada.Exceptions; use Ada.Exceptions;
62 with Ada.Command_Line; use Ada.Command_Line;
64 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
65 with GNAT.Case_Util; use GNAT.Case_Util;
67 with System.HTable;
69 package body Make is
71 use ASCII;
72 -- Make control characters visible
74 Standard_Library_Package_Body_Name : constant String := "s-stalib.adb";
75 -- Every program depends on this package, that must then be checked,
76 -- especially when -f and -a are used.
78 type Sigint_Handler is access procedure;
80 procedure Install_Int_Handler (Handler : Sigint_Handler);
81 pragma Import (C, Install_Int_Handler, "__gnat_install_int_handler");
82 -- Called by Gnatmake to install the SIGINT handler below
84 procedure Sigint_Intercepted;
85 -- Called when the program is interrupted by Ctrl-C to delete the
86 -- temporary mapping files and configuration pragmas files.
88 -------------------------
89 -- Note on terminology --
90 -------------------------
92 -- In this program, we use the phrase "termination" of a file name to
93 -- refer to the suffix that appears after the unit name portion. Very
94 -- often this is simply the extension, but in some cases, the sequence
95 -- may be more complex, for example in main.1.ada, the termination in
96 -- this name is ".1.ada" and in main_.ada the termination is "_.ada".
98 -------------------------------------
99 -- Queue (Q) Manipulation Routines --
100 -------------------------------------
102 -- The Q is used in Compile_Sources below. Its implementation uses the
103 -- GNAT generic package Table (basically an extensible array). Q_Front
104 -- points to the first valid element in the Q, whereas Q.First is the first
105 -- element ever enqueued, while Q.Last - 1 is the last element in the Q.
107 -- +---+--------------+---+---+---+-----------+---+--------
108 -- Q | | ........ | | | | ....... | |
109 -- +---+--------------+---+---+---+-----------+---+--------
110 -- ^ ^ ^
111 -- Q.First Q_Front Q.Last - 1
113 -- The elements comprised between Q.First and Q_Front - 1 are the
114 -- elements that have been enqueued and then dequeued, while the
115 -- elements between Q_Front and Q.Last - 1 are the elements currently
116 -- in the Q. When the Q is initialized Q_Front = Q.First = Q.Last.
117 -- After Compile_Sources has terminated its execution, Q_Front = Q.Last
118 -- and the elements contained between Q.Front and Q.Last-1 are those that
119 -- were explored and thus marked by Compile_Sources. Whenever the Q is
120 -- reinitialized, the elements between Q.First and Q.Last - 1 are unmarked.
122 procedure Init_Q;
123 -- Must be called to (re)initialize the Q.
125 procedure Insert_Q
126 (Source_File : File_Name_Type;
127 Source_Unit : Unit_Name_Type := No_Name;
128 Index : Int := 0);
129 -- Inserts Source_File at the end of Q. Provide Source_Unit when possible
130 -- for external use (gnatdist). Provide index for multi-unit sources.
132 function Empty_Q return Boolean;
133 -- Returns True if Q is empty.
135 procedure Extract_From_Q
136 (Source_File : out File_Name_Type;
137 Source_Unit : out Unit_Name_Type;
138 Source_Index : out Int);
139 -- Extracts the first element from the Q.
141 procedure Insert_Project_Sources
142 (The_Project : Project_Id;
143 All_Projects : Boolean;
144 Into_Q : Boolean);
145 -- If Into_Q is True, insert all sources of the project file(s) that are
146 -- not already marked into the Q. If Into_Q is False, call Osint.Add_File
147 -- for the first source, then insert all other sources that are not already
148 -- marked into the Q. If All_Projects is True, all sources of all projects
149 -- are concerned; otherwise, only sources of The_Project are concerned,
150 -- including, if The_Project is an extending project, sources inherited
151 -- from projects being extended.
153 First_Q_Initialization : Boolean := True;
154 -- Will be set to false after Init_Q has been called once.
156 Q_Front : Natural;
157 -- Points to the first valid element in the Q.
159 Unique_Compile : Boolean := False;
160 -- Set to True if -u or -U or a project file with no main is used
162 Unique_Compile_All_Projects : Boolean := False;
163 -- Set to True if -U is used
165 RTS_Specified : String_Access := null;
166 -- Used to detect multiple --RTS= switches
168 type Q_Record is record
169 File : File_Name_Type;
170 Unit : Unit_Name_Type;
171 Index : Int;
172 end record;
173 -- File is the name of the file to compile. Unit is for gnatdist
174 -- use in order to easily get the unit name of a file to compile
175 -- when its name is krunched or declared in gnat.adc. Index, when not 0,
176 -- is the index of the unit in a multi-unit source.
178 package Q is new Table.Table (
179 Table_Component_Type => Q_Record,
180 Table_Index_Type => Natural,
181 Table_Low_Bound => 0,
182 Table_Initial => 4000,
183 Table_Increment => 100,
184 Table_Name => "Make.Q");
185 -- This is the actual Q.
187 -- The following instantiations and variables are necessary to save what
188 -- is found on the command line, in case there is a project file specified.
190 package Saved_Gcc_Switches is new Table.Table (
191 Table_Component_Type => String_Access,
192 Table_Index_Type => Integer,
193 Table_Low_Bound => 1,
194 Table_Initial => 20,
195 Table_Increment => 100,
196 Table_Name => "Make.Saved_Gcc_Switches");
198 package Saved_Binder_Switches is new Table.Table (
199 Table_Component_Type => String_Access,
200 Table_Index_Type => Integer,
201 Table_Low_Bound => 1,
202 Table_Initial => 20,
203 Table_Increment => 100,
204 Table_Name => "Make.Saved_Binder_Switches");
206 package Saved_Linker_Switches is new Table.Table
207 (Table_Component_Type => String_Access,
208 Table_Index_Type => Integer,
209 Table_Low_Bound => 1,
210 Table_Initial => 20,
211 Table_Increment => 100,
212 Table_Name => "Make.Saved_Linker_Switches");
214 package Switches_To_Check is new Table.Table (
215 Table_Component_Type => String_Access,
216 Table_Index_Type => Integer,
217 Table_Low_Bound => 1,
218 Table_Initial => 20,
219 Table_Increment => 100,
220 Table_Name => "Make.Switches_To_Check");
222 package Library_Paths 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.Library_Paths");
230 package Failed_Links is new Table.Table (
231 Table_Component_Type => File_Name_Type,
232 Table_Index_Type => Integer,
233 Table_Low_Bound => 1,
234 Table_Initial => 10,
235 Table_Increment => 100,
236 Table_Name => "Make.Failed_Links");
238 package Successful_Links is new Table.Table (
239 Table_Component_Type => File_Name_Type,
240 Table_Index_Type => Integer,
241 Table_Low_Bound => 1,
242 Table_Initial => 10,
243 Table_Increment => 100,
244 Table_Name => "Make.Successful_Links");
246 package Library_Projs is new Table.Table (
247 Table_Component_Type => Project_Id,
248 Table_Index_Type => Integer,
249 Table_Low_Bound => 1,
250 Table_Initial => 10,
251 Table_Increment => 100,
252 Table_Name => "Make.Library_Projs");
254 -- Two variables to keep the last binder and linker switch index
255 -- in tables Binder_Switches and Linker_Switches, before adding
256 -- switches from the project file (if any) and switches from the
257 -- command line (if any).
259 Last_Binder_Switch : Integer := 0;
260 Last_Linker_Switch : Integer := 0;
262 Normalized_Switches : Argument_List_Access := new Argument_List (1 .. 10);
263 Last_Norm_Switch : Natural := 0;
265 Saved_Maximum_Processes : Natural := 0;
267 type Arg_List_Ref is access Argument_List;
268 The_Saved_Gcc_Switches : Arg_List_Ref;
270 Project_File_Name : String_Access := null;
271 -- The path name of the main project file, if any
273 Project_File_Name_Present : Boolean := False;
274 -- True when -P is used with a space between -P and the project file name
276 Current_Verbosity : Prj.Verbosity := Prj.Default;
277 -- Verbosity to parse the project files
279 Main_Project : Prj.Project_Id := No_Project;
280 -- The project id of the main project file, if any
282 Project_Object_Directory : Project_Id := No_Project;
283 -- The object directory of the project for the last compilation.
284 -- Avoid calling Change_Dir if the current working directory is already
285 -- this directory
287 -- Packages of project files where unknown attributes are errors.
289 Naming_String : aliased String := "naming";
290 Builder_String : aliased String := "builder";
291 Compiler_String : aliased String := "compiler";
292 Binder_String : aliased String := "binder";
293 Linker_String : aliased String := "linker";
295 Gnatmake_Packages : aliased String_List :=
296 (Naming_String 'Access,
297 Builder_String 'Access,
298 Compiler_String 'Access,
299 Binder_String 'Access,
300 Linker_String 'Access);
302 Packages_To_Check_By_Gnatmake : constant String_List_Access :=
303 Gnatmake_Packages'Access;
305 procedure Add_Source_Dir (N : String);
306 -- Call Add_Src_Search_Dir.
307 -- Output one line when in verbose mode.
309 procedure Add_Source_Directories is
310 new Prj.Env.For_All_Source_Dirs (Action => Add_Source_Dir);
312 procedure Add_Object_Dir (N : String);
313 -- Call Add_Lib_Search_Dir.
314 -- Output one line when in verbose mode.
316 procedure Add_Object_Directories is
317 new Prj.Env.For_All_Object_Dirs (Action => Add_Object_Dir);
319 procedure Change_To_Object_Directory (Project : Project_Id);
320 -- Change to the object directory of project Project, if this is not
321 -- already the current working directory.
323 type Bad_Compilation_Info is record
324 File : File_Name_Type;
325 Unit : Unit_Name_Type;
326 Found : Boolean;
327 end record;
328 -- File is the name of the file for which a compilation failed.
329 -- Unit is for gnatdist use in order to easily get the unit name
330 -- of a file when its name is krunched or declared in gnat.adc.
331 -- Found is False if the compilation failed because the file could
332 -- not be found.
334 package Bad_Compilation is new Table.Table (
335 Table_Component_Type => Bad_Compilation_Info,
336 Table_Index_Type => Natural,
337 Table_Low_Bound => 1,
338 Table_Initial => 20,
339 Table_Increment => 100,
340 Table_Name => "Make.Bad_Compilation");
341 -- Full name of all the source files for which compilation fails.
343 Do_Compile_Step : Boolean := True;
344 Do_Bind_Step : Boolean := True;
345 Do_Link_Step : Boolean := True;
346 -- Flags to indicate what step should be executed.
347 -- Can be set to False with the switches -c, -b and -l.
348 -- These flags are reset to True for each invokation of procedure Gnatmake.
350 Shared_String : aliased String := "-shared";
351 Force_Elab_Flags_String : aliased String := "-F";
353 No_Shared_Switch : aliased Argument_List := (1 .. 0 => null);
354 Shared_Switch : aliased Argument_List := (1 => Shared_String'Access);
355 Bind_Shared : Argument_List_Access := No_Shared_Switch'Access;
356 -- Switch to added in front of gnatbind switches. By default no switch is
357 -- added. Switch "-shared" is added if there is a non-static Library
358 -- Project File.
360 Shared_Libgcc : aliased String := "-shared-libgcc";
362 No_Shared_Libgcc_Switch : aliased Argument_List := (1 .. 0 => null);
363 Shared_Libgcc_Switch : aliased Argument_List :=
364 (1 => Shared_Libgcc'Access);
365 Link_With_Shared_Libgcc : Argument_List_Access :=
366 No_Shared_Libgcc_Switch'Access;
368 procedure Make_Failed (S1 : String; S2 : String := ""; S3 : String := "");
369 -- Delete all temp files created by Gnatmake and call Osint.Fail,
370 -- with the parameter S1, S2 and S3 (see osint.ads).
371 -- This is called from the Prj hierarchy and the MLib hierarchy.
373 --------------------------
374 -- Obsolete Executables --
375 --------------------------
377 Executable_Obsolete : Boolean := False;
378 -- Executable_Obsolete is initially set to False for each executable,
379 -- and is set to True whenever one of the source of the executable is
380 -- compiled, or has already been compiled for another executable.
382 Max_Header : constant := 200;
383 -- This needs a proper comment, it used to say "arbitrary"
384 -- that's not an adequate comment ???
386 type Header_Num is range 1 .. Max_Header;
387 -- Header_Num for the hash table Obsoleted below
389 function Hash (F : Name_Id) return Header_Num;
390 -- Hash function for the hash table Obsoleted below
392 package Obsoleted is new System.HTable.Simple_HTable
393 (Header_Num => Header_Num,
394 Element => Boolean,
395 No_Element => False,
396 Key => Name_Id,
397 Hash => Hash,
398 Equal => "=");
399 -- A hash table to keep all files that have been compiled, to detect
400 -- if an executable is up to date or not.
402 procedure Enter_Into_Obsoleted (F : Name_Id);
403 -- Enter a file name, without directory information, into the has table
404 -- Obsoleted.
406 function Is_In_Obsoleted (F : Name_Id) return Boolean;
407 -- Check if a file name, without directory information, has already been
408 -- entered into the hash table Obsoleted.
410 type Dependency is record
411 This : Name_Id;
412 Depends_On : Name_Id;
413 end record;
414 -- Components of table Dependencies below.
416 package Dependencies is new Table.Table (
417 Table_Component_Type => Dependency,
418 Table_Index_Type => Integer,
419 Table_Low_Bound => 1,
420 Table_Initial => 20,
421 Table_Increment => 100,
422 Table_Name => "Make.Dependencies");
423 -- A table to keep dependencies, to be able to decide if an executable
424 -- is obsolete.
426 procedure Add_Dependency (S : Name_Id; On : Name_Id);
427 -- Add one entry in table Dependencies
429 ----------------------------
430 -- Arguments and Switches --
431 ----------------------------
433 Arguments : Argument_List_Access;
434 -- Used to gather the arguments for invocation of the compiler
436 Last_Argument : Natural := 0;
437 -- Last index of arguments in Arguments above
439 Arguments_Collected : Boolean := False;
440 -- Set to True when the arguments for the next invocation of the compiler
441 -- have been collected.
443 Arguments_Project : Project_Id;
444 -- Project id, if any, of the source to be compiled
446 Arguments_Path_Name : File_Name_Type;
447 -- Full path of the source to be compiled, when Arguments_Project is not
448 -- No_Project.
450 Dummy_Switch : constant String_Access := new String'("- ");
451 -- Used to initialized Prev_Switch in procedure Check
453 procedure Add_Arguments (Args : Argument_List);
454 -- Add arguments to global variable Arguments, increasing its size
455 -- if necessary and adjusting Last_Argument.
457 function Configuration_Pragmas_Switch
458 (For_Project : Project_Id) return Argument_List;
459 -- Return an argument list of one element, if there is a configuration
460 -- pragmas file to be specified for For_Project,
461 -- otherwise return an empty argument list.
463 -------------------
464 -- Misc Routines --
465 -------------------
467 procedure List_Depend;
468 -- Prints to standard output the list of object dependencies. This list
469 -- can be used directly in a Makefile. A call to Compile_Sources must
470 -- precede the call to List_Depend. Also because this routine uses the
471 -- ALI files that were originally loaded and scanned by Compile_Sources,
472 -- no additional ALI files should be scanned between the two calls (i.e.
473 -- between the call to Compile_Sources and List_Depend.)
475 procedure Inform (N : Name_Id := No_Name; Msg : String);
476 -- Prints out the program name followed by a colon, N and S.
478 procedure List_Bad_Compilations;
479 -- Prints out the list of all files for which the compilation failed.
481 procedure Verbose_Msg
482 (N1 : Name_Id;
483 S1 : String;
484 N2 : Name_Id := No_Name;
485 S2 : String := "";
486 Prefix : String := " -> ");
487 -- If the verbose flag (Verbose_Mode) is set then print Prefix to standard
488 -- output followed by N1 and S1. If N2 /= No_Name then N2 is then printed
489 -- after S1. S2 is printed last. Both N1 and N2 are printed in quotation
490 -- marks.
492 Usage_Needed : Boolean := True;
493 -- Flag used to make sure Makeusg is call at most once
495 procedure Usage;
496 -- Call Makeusg, if Usage_Needed is True.
497 -- Set Usage_Needed to False.
499 procedure Debug_Msg (S : String; N : Name_Id);
500 -- If Debug.Debug_Flag_W is set outputs string S followed by name N.
502 procedure Recursive_Compute_Depth
503 (Project : Project_Id;
504 Depth : Natural);
505 -- Compute depth of Project and of the projects it depends on
507 -----------------------
508 -- Gnatmake Routines --
509 -----------------------
511 Gnatmake_Called : Boolean := False;
512 -- Set to True when procedure Gnatmake is called.
513 -- Attempt to delete temporary files is made only when Gnatmake_Called
514 -- is True.
516 subtype Lib_Mark_Type is Byte;
517 -- Used in Mark_Directory
519 Ada_Lib_Dir : constant Lib_Mark_Type := 1;
520 -- Used to mark a directory as a GNAT lib dir
522 -- Note that the notion of GNAT lib dir is no longer used. The code
523 -- related to it has not been removed to give an idea on how to use
524 -- the directory prefix marking mechanism.
526 -- An Ada library directory is a directory containing ali and object
527 -- files but no source files for the bodies (the specs can be in the
528 -- same or some other directory). These directories are specified
529 -- in the Gnatmake command line with the switch "-Adir" (to specify the
530 -- spec location -Idir cab be used). Gnatmake skips the missing sources
531 -- whose ali are in Ada library directories. For an explanation of why
532 -- Gnatmake behaves that way, see the spec of Make.Compile_Sources.
533 -- The directory lookup penalty is incurred every single time this
534 -- routine is called.
536 procedure Check_Steps;
537 -- Check what steps (Compile, Bind, Link) must be executed.
538 -- Set the step flags accordingly.
540 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean;
541 -- Get directory prefix of this file and get lib mark stored in name
542 -- table for this directory. Then check if an Ada lib mark has been set.
544 procedure Mark_Directory
545 (Dir : String;
546 Mark : Lib_Mark_Type);
547 -- Store Dir in name table and set lib mark as name info to identify
548 -- Ada libraries.
550 Output_Is_Object : Boolean := True;
551 -- Set to False when using a switch -S for the compiler
553 procedure Check_For_S_Switch;
554 -- Set Output_Is_Object to False when the -S switch is used for the
555 -- compiler.
557 function Switches_Of
558 (Source_File : Name_Id;
559 Source_File_Name : String;
560 Source_Index : Int;
561 Naming : Naming_Data;
562 In_Package : Package_Id;
563 Allow_ALI : Boolean) return Variable_Value;
564 -- Return the switches for the source file in the specified package
565 -- of a project file. If the Source_File ends with a standard GNAT
566 -- extension (".ads" or ".adb"), try first the full name, then the
567 -- name without the extension, then, if Allow_ALI is True, the name with
568 -- the extension ".ali". If there is no switches for either names, try the
569 -- default switches for Ada. If all failed, return No_Variable_Value.
571 function Is_In_Object_Directory
572 (Source_File : File_Name_Type;
573 Full_Lib_File : File_Name_Type) return Boolean;
574 -- Check if, when using a project file, the ALI file is in the project
575 -- directory of the ultimate extending project. If it is not, we ignore
576 -- the fact that this ALI file is read-only.
578 ----------------------------------------------------
579 -- Compiler, Binder & Linker Data and Subprograms --
580 ----------------------------------------------------
582 Gcc : String_Access := Program_Name ("gcc");
583 Gnatbind : String_Access := Program_Name ("gnatbind");
584 Gnatlink : String_Access := Program_Name ("gnatlink");
585 -- Default compiler, binder, linker programs
587 Saved_Gcc : String_Access := null;
588 Saved_Gnatbind : String_Access := null;
589 Saved_Gnatlink : String_Access := null;
590 -- Given by the command line. Will be used, if non null.
592 Gcc_Path : String_Access :=
593 GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
594 Gnatbind_Path : String_Access :=
595 GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
596 Gnatlink_Path : String_Access :=
597 GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
598 -- Path for compiler, binder, linker programs, defaulted now for gnatdist.
599 -- Changed later if overridden on command line.
601 Comp_Flag : constant String_Access := new String'("-c");
602 Output_Flag : constant String_Access := new String'("-o");
603 Ada_Flag_1 : constant String_Access := new String'("-x");
604 Ada_Flag_2 : constant String_Access := new String'("ada");
605 No_gnat_adc : constant String_Access := new String'("-gnatA");
606 GNAT_Flag : constant String_Access := new String'("-gnatpg");
607 Do_Not_Check_Flag : constant String_Access := new String'("-x");
609 Object_Suffix : constant String := Get_Object_Suffix.all;
610 Executable_Suffix : constant String := Get_Executable_Suffix.all;
612 Syntax_Only : Boolean := False;
613 -- Set to True when compiling with -gnats
615 Display_Executed_Programs : Boolean := True;
616 -- Set to True if name of commands should be output on stderr.
618 Output_File_Name_Seen : Boolean := False;
619 -- Set to True after having scanned the file_name for
620 -- switch "-o file_name"
622 Object_Directory_Seen : Boolean := False;
623 -- Set to True after having scanned the object directory for
624 -- switch "-D obj_dir".
626 Object_Directory_Path : String_Access := null;
627 -- The path name of the object directory, set with switch -D.
629 type Make_Program_Type is (None, Compiler, Binder, Linker);
631 Program_Args : Make_Program_Type := None;
632 -- Used to indicate if we are scanning gnatmake, gcc, gnatbind, or gnatbind
633 -- options within the gnatmake command line.
634 -- Used in Scan_Make_Arg only, but must be a global variable.
636 Temporary_Config_File : Boolean := False;
637 -- Set to True when there is a temporary config file used for a project
638 -- file, to avoid displaying the -gnatec switch for a temporary file.
640 procedure Add_Switches
641 (The_Package : Package_Id;
642 File_Name : String;
643 Index : Int;
644 Program : Make_Program_Type);
645 procedure Add_Switch
646 (S : String_Access;
647 Program : Make_Program_Type;
648 Append_Switch : Boolean := True;
649 And_Save : Boolean := True);
650 procedure Add_Switch
651 (S : String;
652 Program : Make_Program_Type;
653 Append_Switch : Boolean := True;
654 And_Save : Boolean := True);
655 -- Make invokes one of three programs (the compiler, the binder or the
656 -- linker). For the sake of convenience, some program specific switches
657 -- can be passed directly on the gnatmake commande line. This procedure
658 -- records these switches so that gnamake can pass them to the right
659 -- program. S is the switch to be added at the end of the command line
660 -- for Program if Append_Switch is True. If Append_Switch is False S is
661 -- added at the beginning of the command line.
663 procedure Check
664 (Source_File : File_Name_Type;
665 Source_Index : Int;
666 The_Args : Argument_List;
667 Lib_File : File_Name_Type;
668 Read_Only : Boolean;
669 ALI : out ALI_Id;
670 O_File : out File_Name_Type;
671 O_Stamp : out Time_Stamp_Type);
672 -- Determines whether the library file Lib_File is up-to-date or not. The
673 -- full name (with path information) of the object file corresponding to
674 -- Lib_File is returned in O_File. Its time stamp is saved in O_Stamp.
675 -- ALI is the ALI_Id corresponding to Lib_File. If Lib_File in not
676 -- up-to-date, then the corresponding source file needs to be recompiled.
677 -- In this case ALI = No_ALI_Id.
679 procedure Check_Linker_Options
680 (E_Stamp : Time_Stamp_Type;
681 O_File : out File_Name_Type;
682 O_Stamp : out Time_Stamp_Type);
683 -- Checks all linker options for linker files that are newer
684 -- than E_Stamp. If such objects are found, the youngest object
685 -- is returned in O_File and its stamp in O_Stamp.
687 -- If no obsolete linker files were found, the first missing
688 -- linker file is returned in O_File and O_Stamp is empty.
689 -- Otherwise O_File is No_File.
691 procedure Collect_Arguments
692 (Source_File : File_Name_Type;
693 Source_Index : Int;
694 Args : Argument_List);
695 -- Collect all arguments for a source to be compiled, including those
696 -- that come from a project file.
698 procedure Display (Program : String; Args : Argument_List);
699 -- Displays Program followed by the arguments in Args if variable
700 -- Display_Executed_Programs is set. The lower bound of Args must be 1.
702 -----------------
703 -- Mapping files
704 -----------------
706 type Temp_File_Names is
707 array (Project_Id range <>, Positive range <>) of Name_Id;
709 type Temp_Files_Ptr is access Temp_File_Names;
711 type Indices is array (Project_Id range <>) of Natural;
713 type Indices_Ptr is access Indices;
715 type Free_File_Indices is array
716 (Project_Id range <>, Positive range <>) of Positive;
718 type Free_Indices_Ptr is access Free_File_Indices;
720 The_Mapping_File_Names : Temp_Files_Ptr;
721 -- For each project, the name ids of the temporary mapping files used
723 Last_Mapping_File_Names : Indices_Ptr;
724 -- For each project, the index of the last mapping file created
726 The_Free_Mapping_File_Indices : Free_Indices_Ptr;
727 -- For each project, the indices in The_Mapping_File_Names of the mapping
728 -- file names that can be reused for subsequent compilations.
730 Last_Free_Indices : Indices_Ptr;
731 -- For each project, the number of mapping files that can be reused
733 Gnatmake_Mapping_File : String_Access := null;
734 -- The path name of a mapping file specified by switch -C=
736 procedure Delete_Mapping_Files;
737 -- Delete all temporary mapping files
739 procedure Init_Mapping_File
740 (Project : Project_Id;
741 File_Index : in out Natural);
742 -- Create a new temporary mapping file, and fill it with the project file
743 -- mappings, when using project file(s). The out parameter File_Index is
744 -- the index to the name of the file in the array The_Mapping_File_Names.
746 procedure Delete_Temp_Config_Files;
747 -- Delete all temporary config files
749 procedure Delete_All_Temp_Files;
750 -- Delete all temp files (config files, mapping files, path files)
752 -------------------
753 -- Add_Arguments --
754 -------------------
756 procedure Add_Arguments (Args : Argument_List) is
757 begin
758 if Arguments = null then
759 Arguments := new Argument_List (1 .. Args'Length + 10);
761 else
762 while Last_Argument + Args'Length > Arguments'Last loop
763 declare
764 New_Arguments : constant Argument_List_Access :=
765 new Argument_List (1 .. Arguments'Last * 2);
766 begin
767 New_Arguments (1 .. Last_Argument) :=
768 Arguments (1 .. Last_Argument);
769 Arguments := New_Arguments;
770 end;
771 end loop;
772 end if;
774 Arguments (Last_Argument + 1 .. Last_Argument + Args'Length) := Args;
775 Last_Argument := Last_Argument + Args'Length;
776 end Add_Arguments;
778 --------------------
779 -- Add_Dependency --
780 --------------------
782 procedure Add_Dependency (S : Name_Id; On : Name_Id) is
783 begin
784 Dependencies.Increment_Last;
785 Dependencies.Table (Dependencies.Last) := (S, On);
786 end Add_Dependency;
788 --------------------
789 -- Add_Object_Dir --
790 --------------------
792 procedure Add_Object_Dir (N : String) is
793 begin
794 Add_Lib_Search_Dir (N);
796 if Verbose_Mode then
797 Write_Str ("Adding object directory """);
798 Write_Str (N);
799 Write_Str (""".");
800 Write_Eol;
801 end if;
802 end Add_Object_Dir;
804 --------------------
805 -- Add_Source_Dir --
806 --------------------
808 procedure Add_Source_Dir (N : String) is
809 begin
810 Add_Src_Search_Dir (N);
812 if Verbose_Mode then
813 Write_Str ("Adding source directory """);
814 Write_Str (N);
815 Write_Str (""".");
816 Write_Eol;
817 end if;
818 end Add_Source_Dir;
820 ----------------
821 -- Add_Switch --
822 ----------------
824 procedure Add_Switch
825 (S : String_Access;
826 Program : Make_Program_Type;
827 Append_Switch : Boolean := True;
828 And_Save : Boolean := True)
830 generic
831 with package T is new Table.Table (<>);
832 procedure Generic_Position (New_Position : out Integer);
833 -- Generic procedure that chooses a position for S in T at the
834 -- beginning or the end, depending on the boolean Append_Switch.
835 -- Calling this procedure may expand the table.
837 ----------------------
838 -- Generic_Position --
839 ----------------------
841 procedure Generic_Position (New_Position : out Integer) is
842 begin
843 T.Increment_Last;
845 if Append_Switch then
846 New_Position := Integer (T.Last);
847 else
848 for J in reverse T.Table_Index_Type'Succ (T.First) .. T.Last loop
849 T.Table (J) := T.Table (T.Table_Index_Type'Pred (J));
850 end loop;
852 New_Position := Integer (T.First);
853 end if;
854 end Generic_Position;
856 procedure Gcc_Switches_Pos is new Generic_Position (Gcc_Switches);
857 procedure Binder_Switches_Pos is new Generic_Position (Binder_Switches);
858 procedure Linker_Switches_Pos is new Generic_Position (Linker_Switches);
860 procedure Saved_Gcc_Switches_Pos is new
861 Generic_Position (Saved_Gcc_Switches);
863 procedure Saved_Binder_Switches_Pos is new
864 Generic_Position (Saved_Binder_Switches);
866 procedure Saved_Linker_Switches_Pos is new
867 Generic_Position (Saved_Linker_Switches);
869 New_Position : Integer;
871 -- Start of processing for Add_Switch
873 begin
874 if And_Save then
875 case Program is
876 when Compiler =>
877 Saved_Gcc_Switches_Pos (New_Position);
878 Saved_Gcc_Switches.Table (New_Position) := S;
880 when Binder =>
881 Saved_Binder_Switches_Pos (New_Position);
882 Saved_Binder_Switches.Table (New_Position) := S;
884 when Linker =>
885 Saved_Linker_Switches_Pos (New_Position);
886 Saved_Linker_Switches.Table (New_Position) := S;
888 when None =>
889 raise Program_Error;
890 end case;
892 else
893 case Program is
894 when Compiler =>
895 Gcc_Switches_Pos (New_Position);
896 Gcc_Switches.Table (New_Position) := S;
898 when Binder =>
899 Binder_Switches_Pos (New_Position);
900 Binder_Switches.Table (New_Position) := S;
902 when Linker =>
903 Linker_Switches_Pos (New_Position);
904 Linker_Switches.Table (New_Position) := S;
906 when None =>
907 raise Program_Error;
908 end case;
909 end if;
910 end Add_Switch;
912 procedure Add_Switch
913 (S : String;
914 Program : Make_Program_Type;
915 Append_Switch : Boolean := True;
916 And_Save : Boolean := True)
918 begin
919 Add_Switch (S => new String'(S),
920 Program => Program,
921 Append_Switch => Append_Switch,
922 And_Save => And_Save);
923 end Add_Switch;
925 ------------------
926 -- Add_Switches --
927 ------------------
929 procedure Add_Switches
930 (The_Package : Package_Id;
931 File_Name : String;
932 Index : Int;
933 Program : Make_Program_Type)
935 Switches : Variable_Value;
936 Switch_List : String_List_Id;
937 Element : String_Element;
939 begin
940 if File_Name'Length > 0 then
941 Name_Len := File_Name'Length;
942 Name_Buffer (1 .. Name_Len) := File_Name;
943 Switches :=
944 Switches_Of
945 (Source_File => Name_Find,
946 Source_File_Name => File_Name,
947 Source_Index => Index,
948 Naming => Projects.Table (Main_Project).Naming,
949 In_Package => The_Package,
950 Allow_ALI =>
951 Program = Binder or else Program = Linker);
953 case Switches.Kind is
954 when Undefined =>
955 null;
957 when List =>
958 Program_Args := Program;
960 Switch_List := Switches.Values;
962 while Switch_List /= Nil_String loop
963 Element := String_Elements.Table (Switch_List);
964 Get_Name_String (Element.Value);
966 if Name_Len > 0 then
967 declare
968 Argv : constant String := Name_Buffer (1 .. Name_Len);
969 -- We need a copy, because Name_Buffer may be
970 -- modified.
972 begin
973 if Verbose_Mode then
974 Write_Str (" Adding ");
975 Write_Line (Argv);
976 end if;
978 Scan_Make_Arg (Argv, And_Save => False);
979 end;
980 end if;
982 Switch_List := Element.Next;
983 end loop;
985 when Single =>
986 Program_Args := Program;
987 Get_Name_String (Switches.Value);
989 if Name_Len > 0 then
990 declare
991 Argv : constant String := Name_Buffer (1 .. Name_Len);
992 -- We need a copy, because Name_Buffer may be modified
994 begin
995 if Verbose_Mode then
996 Write_Str (" Adding ");
997 Write_Line (Argv);
998 end if;
1000 Scan_Make_Arg (Argv, And_Save => False);
1001 end;
1002 end if;
1003 end case;
1004 end if;
1005 end Add_Switches;
1007 ----------
1008 -- Bind --
1009 ----------
1011 procedure Bind (ALI_File : File_Name_Type; Args : Argument_List) is
1012 Bind_Args : Argument_List (1 .. Args'Last + 2);
1013 Bind_Last : Integer;
1014 Success : Boolean;
1016 begin
1017 pragma Assert (Args'First = 1);
1019 -- Optimize the simple case where the gnatbind command line looks like
1020 -- gnatbind -aO. -I- file.ali --into-> gnatbind file.adb
1022 if Args'Length = 2
1023 and then Args (Args'First).all = "-aO" & Normalized_CWD
1024 and then Args (Args'Last).all = "-I-"
1025 and then ALI_File = Strip_Directory (ALI_File)
1026 then
1027 Bind_Last := Args'First - 1;
1029 else
1030 Bind_Last := Args'Last;
1031 Bind_Args (Args'Range) := Args;
1032 end if;
1034 -- It is completely pointless to re-check source file time stamps.
1035 -- This has been done already by gnatmake
1037 Bind_Last := Bind_Last + 1;
1038 Bind_Args (Bind_Last) := Do_Not_Check_Flag;
1040 Get_Name_String (ALI_File);
1042 Bind_Last := Bind_Last + 1;
1043 Bind_Args (Bind_Last) := new String'(Name_Buffer (1 .. Name_Len));
1045 GNAT.OS_Lib.Normalize_Arguments (Bind_Args (Args'First .. Bind_Last));
1047 Display (Gnatbind.all, Bind_Args (Args'First .. Bind_Last));
1049 if Gnatbind_Path = null then
1050 Make_Failed ("error, unable to locate ", Gnatbind.all);
1051 end if;
1053 GNAT.OS_Lib.Spawn
1054 (Gnatbind_Path.all, Bind_Args (Args'First .. Bind_Last), Success);
1056 if not Success then
1057 raise Bind_Failed;
1058 end if;
1059 end Bind;
1061 --------------------------------
1062 -- Change_To_Object_Directory --
1063 --------------------------------
1065 procedure Change_To_Object_Directory (Project : Project_Id) is
1066 begin
1067 -- Nothing to do if the current working directory is alresdy the one
1068 -- we want.
1070 if Project_Object_Directory /= Project then
1071 Project_Object_Directory := Project;
1073 -- If in a real project, set the working directory to the object
1074 -- directory of the project.
1076 if Project /= No_Project then
1077 Change_Dir
1078 (Get_Name_String (Projects.Table (Project).Object_Directory));
1080 -- Otherwise, for sources outside of any project, set the working
1081 -- directory to the object directory of the main project.
1083 elsif Main_Project /= No_Project then
1084 Change_Dir
1085 (Get_Name_String
1086 (Projects.Table (Main_Project).Object_Directory));
1087 end if;
1088 end if;
1089 end Change_To_Object_Directory;
1091 -----------
1092 -- Check --
1093 -----------
1095 procedure Check
1096 (Source_File : File_Name_Type;
1097 Source_Index : Int;
1098 The_Args : Argument_List;
1099 Lib_File : File_Name_Type;
1100 Read_Only : Boolean;
1101 ALI : out ALI_Id;
1102 O_File : out File_Name_Type;
1103 O_Stamp : out Time_Stamp_Type)
1105 function First_New_Spec (A : ALI_Id) return File_Name_Type;
1106 -- Looks in the with table entries of A and returns the spec file name
1107 -- of the first withed unit (subprogram) for which no spec existed when
1108 -- A was generated but for which there exists one now, implying that A
1109 -- is now obsolete. If no such unit is found No_File is returned.
1110 -- Otherwise the spec file name of the unit is returned.
1112 -- **WARNING** in the event of Uname format modifications, one *MUST*
1113 -- make sure this function is also updated.
1115 -- Note: This function should really be in ali.adb and use Uname
1116 -- services, but this causes the whole compiler to be dragged along
1117 -- for gnatbind and gnatmake.
1119 --------------------
1120 -- First_New_Spec --
1121 --------------------
1123 function First_New_Spec (A : ALI_Id) return File_Name_Type is
1124 Spec_File_Name : File_Name_Type := No_File;
1126 function New_Spec (Uname : Unit_Name_Type) return Boolean;
1127 -- Uname is the name of the spec or body of some ada unit.
1128 -- This function returns True if the Uname is the name of a body
1129 -- which has a spec not mentioned inali file A. If True is returned
1130 -- Spec_File_Name above is set to the name of this spec file.
1132 --------------
1133 -- New_Spec --
1134 --------------
1136 function New_Spec (Uname : Unit_Name_Type) return Boolean is
1137 Spec_Name : Unit_Name_Type;
1138 File_Name : File_Name_Type;
1140 begin
1141 -- Test whether Uname is the name of a body unit (ie ends with %b)
1143 Get_Name_String (Uname);
1144 pragma
1145 Assert (Name_Len > 2 and then Name_Buffer (Name_Len - 1) = '%');
1147 if Name_Buffer (Name_Len) /= 'b' then
1148 return False;
1149 end if;
1151 -- Convert unit name into spec name
1153 -- ??? this code seems dubious in presence of pragma
1154 -- Source_File_Name since there is no more direct relationship
1155 -- between unit name and file name.
1157 -- ??? Further, what about alternative subunit naming
1159 Name_Buffer (Name_Len) := 's';
1160 Spec_Name := Name_Find;
1161 File_Name := Get_File_Name (Spec_Name, Subunit => False);
1163 -- Look if File_Name is mentioned in A's sdep list.
1164 -- If not look if the file exists. If it does return True.
1166 for D in
1167 ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep
1168 loop
1169 if Sdep.Table (D).Sfile = File_Name then
1170 return False;
1171 end if;
1172 end loop;
1174 if Full_Source_Name (File_Name) /= No_File then
1175 Spec_File_Name := File_Name;
1176 return True;
1177 end if;
1179 return False;
1180 end New_Spec;
1182 -- Start of processing for First_New_Spec
1184 begin
1185 U_Chk : for U in
1186 ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit
1187 loop
1188 exit U_Chk when Units.Table (U).Utype = Is_Body_Only
1189 and then New_Spec (Units.Table (U).Uname);
1191 for W in Units.Table (U).First_With
1193 Units.Table (U).Last_With
1194 loop
1195 exit U_Chk when
1196 Withs.Table (W).Afile /= No_File
1197 and then New_Spec (Withs.Table (W).Uname);
1198 end loop;
1199 end loop U_Chk;
1201 return Spec_File_Name;
1202 end First_New_Spec;
1204 ---------------------------------
1205 -- Data declarations for Check --
1206 ---------------------------------
1208 Full_Lib_File : File_Name_Type;
1209 -- Full name of current library file
1211 Full_Obj_File : File_Name_Type;
1212 -- Full name of the object file corresponding to Lib_File.
1214 Lib_Stamp : Time_Stamp_Type;
1215 -- Time stamp of the current ada library file.
1217 Obj_Stamp : Time_Stamp_Type;
1218 -- Time stamp of the current object file.
1220 Modified_Source : File_Name_Type;
1221 -- The first source in Lib_File whose current time stamp differs
1222 -- from that stored in Lib_File.
1224 New_Spec : File_Name_Type;
1225 -- If Lib_File contains in its W (with) section a body (for a
1226 -- subprogram) for which there exists a spec and the spec did not
1227 -- appear in the Sdep section of Lib_File, New_Spec contains the file
1228 -- name of this new spec.
1230 Source_Name : Name_Id;
1231 Text : Text_Buffer_Ptr;
1233 Prev_Switch : String_Access;
1234 -- Previous switch processed
1236 Arg : Arg_Id := Arg_Id'First;
1237 -- Current index in Args.Table for a given unit (init to stop warning)
1239 Switch_Found : Boolean;
1240 -- True if a given switch has been found
1242 -- Start of processing for Check
1244 begin
1245 pragma Assert (Lib_File /= No_File);
1247 -- If the ALI file is read-only, set temporarily
1248 -- Check_Object_Consistency to False: we don't care if the object file
1249 -- is not there; presumably, a library will be used for linking.
1251 if Read_Only then
1252 declare
1253 Saved_Check_Object_Consistency : constant Boolean :=
1254 Check_Object_Consistency;
1255 begin
1256 Check_Object_Consistency := False;
1257 Text := Read_Library_Info (Lib_File);
1258 Check_Object_Consistency := Saved_Check_Object_Consistency;
1259 end;
1261 else
1262 Text := Read_Library_Info (Lib_File);
1263 end if;
1265 Full_Lib_File := Full_Library_Info_Name;
1266 Full_Obj_File := Full_Object_File_Name;
1267 Lib_Stamp := Current_Library_File_Stamp;
1268 Obj_Stamp := Current_Object_File_Stamp;
1270 if Full_Lib_File = No_File then
1271 Verbose_Msg (Lib_File, "being checked ...", Prefix => " ");
1272 else
1273 Verbose_Msg (Full_Lib_File, "being checked ...", Prefix => " ");
1274 end if;
1276 ALI := No_ALI_Id;
1277 O_File := Full_Obj_File;
1278 O_Stamp := Obj_Stamp;
1280 if Text = null then
1281 if Full_Lib_File = No_File then
1282 Verbose_Msg (Lib_File, "missing.");
1284 elsif Obj_Stamp (Obj_Stamp'First) = ' ' then
1285 Verbose_Msg (Full_Obj_File, "missing.");
1287 else
1288 Verbose_Msg
1289 (Full_Lib_File, "(" & String (Lib_Stamp) & ") newer than",
1290 Full_Obj_File, "(" & String (Obj_Stamp) & ")");
1291 end if;
1293 else
1294 ALI := Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
1295 Free (Text);
1297 if ALI = No_ALI_Id then
1298 Verbose_Msg (Full_Lib_File, "incorrectly formatted ALI file");
1299 return;
1301 elsif ALIs.Table (ALI).Ver (1 .. ALIs.Table (ALI).Ver_Len) /=
1302 Verbose_Library_Version
1303 then
1304 Verbose_Msg (Full_Lib_File, "compiled with old GNAT version");
1305 ALI := No_ALI_Id;
1306 return;
1307 end if;
1309 -- Don't take Ali file into account if it was generated with
1310 -- errors.
1312 if ALIs.Table (ALI).Compile_Errors then
1313 Verbose_Msg (Full_Lib_File, "had errors, must be recompiled");
1314 ALI := No_ALI_Id;
1315 return;
1316 end if;
1318 -- Don't take Ali file into account if it was generated without
1319 -- object.
1321 if Operating_Mode /= Check_Semantics
1322 and then ALIs.Table (ALI).No_Object
1323 then
1324 Verbose_Msg (Full_Lib_File, "has no corresponding object");
1325 ALI := No_ALI_Id;
1326 return;
1327 end if;
1329 -- Check for matching compiler switches if needed
1331 if Check_Switches then
1333 -- First, collect all the switches
1335 Collect_Arguments (Source_File, Source_Index, The_Args);
1337 Prev_Switch := Dummy_Switch;
1339 Get_Name_String (ALIs.Table (ALI).Sfile);
1341 Switches_To_Check.Set_Last (0);
1343 for J in 1 .. Last_Argument loop
1345 -- Skip non switches -c, -I and -o switches
1347 if Arguments (J) (1) = '-'
1348 and then Arguments (J) (2) /= 'c'
1349 and then Arguments (J) (2) /= 'o'
1350 and then Arguments (J) (2) /= 'I'
1351 then
1352 Normalize_Compiler_Switches
1353 (Arguments (J).all,
1354 Normalized_Switches,
1355 Last_Norm_Switch);
1357 for K in 1 .. Last_Norm_Switch loop
1358 Switches_To_Check.Increment_Last;
1359 Switches_To_Check.Table (Switches_To_Check.Last) :=
1360 Normalized_Switches (K);
1361 end loop;
1362 end if;
1363 end loop;
1365 for J in 1 .. Switches_To_Check.Last loop
1367 -- Comparing switches is delicate because gcc reorders
1368 -- a number of switches, according to lang-specs.h, but
1369 -- gnatmake doesn't have the sufficient knowledge to
1370 -- perform the same reordering. Instead, we ignore orders
1371 -- between different "first letter" switches, but keep
1372 -- orders between same switches, e.g -O -O2 is different
1373 -- than -O2 -O, but -g -O is equivalent to -O -g.
1375 if Switches_To_Check.Table (J) (2) /= Prev_Switch (2) or else
1376 (Prev_Switch'Length >= 6 and then
1377 Prev_Switch (2 .. 5) = "gnat" and then
1378 Switches_To_Check.Table (J)'Length >= 6 and then
1379 Switches_To_Check.Table (J) (2 .. 5) = "gnat" and then
1380 Prev_Switch (6) /= Switches_To_Check.Table (J) (6))
1381 then
1382 Prev_Switch := Switches_To_Check.Table (J);
1383 Arg :=
1384 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg;
1385 end if;
1387 Switch_Found := False;
1389 for K in Arg ..
1390 Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1391 loop
1393 Switches_To_Check.Table (J).all = Args.Table (K).all
1394 then
1395 Arg := K + 1;
1396 Switch_Found := True;
1397 exit;
1398 end if;
1399 end loop;
1401 if not Switch_Found then
1402 if Verbose_Mode then
1403 Verbose_Msg (ALIs.Table (ALI).Sfile,
1404 "switch mismatch """ &
1405 Switches_To_Check.Table (J).all & '"');
1406 end if;
1408 ALI := No_ALI_Id;
1409 return;
1410 end if;
1411 end loop;
1413 if Switches_To_Check.Last /=
1414 Integer (Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg -
1415 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg + 1)
1416 then
1417 if Verbose_Mode then
1418 Verbose_Msg (ALIs.Table (ALI).Sfile,
1419 "different number of switches");
1421 for K in Units.Table (ALIs.Table (ALI).First_Unit).First_Arg
1422 .. Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1423 loop
1424 Write_Str (Args.Table (K).all);
1425 Write_Char (' ');
1426 end loop;
1428 Write_Eol;
1430 for J in 1 .. Switches_To_Check.Last loop
1431 Write_Str (Switches_To_Check.Table (J).all);
1432 Write_Char (' ');
1433 end loop;
1435 Write_Eol;
1436 end if;
1438 ALI := No_ALI_Id;
1439 return;
1440 end if;
1441 end if;
1443 -- Get the source files and their message digests. Note that some
1444 -- sources may be missing if ALI is out-of-date.
1446 Set_Source_Table (ALI);
1448 Modified_Source := Time_Stamp_Mismatch (ALI, Read_Only);
1450 if Modified_Source /= No_File then
1451 ALI := No_ALI_Id;
1453 if Verbose_Mode then
1454 Source_Name := Full_Source_Name (Modified_Source);
1456 if Source_Name /= No_File then
1457 Verbose_Msg (Source_Name, "time stamp mismatch");
1458 else
1459 Verbose_Msg (Modified_Source, "missing");
1460 end if;
1461 end if;
1463 else
1464 New_Spec := First_New_Spec (ALI);
1466 if New_Spec /= No_File then
1467 ALI := No_ALI_Id;
1469 if Verbose_Mode then
1470 Source_Name := Full_Source_Name (New_Spec);
1472 if Source_Name /= No_File then
1473 Verbose_Msg (Source_Name, "new spec");
1474 else
1475 Verbose_Msg (New_Spec, "old spec missing");
1476 end if;
1477 end if;
1478 end if;
1479 end if;
1480 end if;
1481 end Check;
1483 ------------------------
1484 -- Check_For_S_Switch --
1485 ------------------------
1487 procedure Check_For_S_Switch is
1488 begin
1489 -- By default, we generate an object file
1491 Output_Is_Object := True;
1493 for Arg in 1 .. Last_Argument loop
1494 if Arguments (Arg).all = "-S" then
1495 Output_Is_Object := False;
1497 elsif Arguments (Arg).all = "-c" then
1498 Output_Is_Object := True;
1499 end if;
1500 end loop;
1501 end Check_For_S_Switch;
1503 --------------------------
1504 -- Check_Linker_Options --
1505 --------------------------
1507 procedure Check_Linker_Options
1508 (E_Stamp : Time_Stamp_Type;
1509 O_File : out File_Name_Type;
1510 O_Stamp : out Time_Stamp_Type)
1512 procedure Check_File (File : File_Name_Type);
1513 -- Update O_File and O_Stamp if the given file is younger than E_Stamp
1514 -- and O_Stamp, or if O_File is No_File and File does not exist.
1516 function Get_Library_File (Name : String) return File_Name_Type;
1517 -- Return the full file name including path of a library based
1518 -- on the name specified with the -l linker option, using the
1519 -- Ada object path. Return No_File if no such file can be found.
1521 type Char_Array is array (Natural) of Character;
1522 type Char_Array_Access is access constant Char_Array;
1524 Template : Char_Array_Access;
1525 pragma Import (C, Template, "__gnat_library_template");
1527 ----------------
1528 -- Check_File --
1529 ----------------
1531 procedure Check_File (File : File_Name_Type) is
1532 Stamp : Time_Stamp_Type;
1533 Name : File_Name_Type := File;
1535 begin
1536 Get_Name_String (Name);
1538 -- Remove any trailing NUL characters
1540 while Name_Len >= Name_Buffer'First
1541 and then Name_Buffer (Name_Len) = NUL
1542 loop
1543 Name_Len := Name_Len - 1;
1544 end loop;
1546 if Name_Len <= 0 then
1547 return;
1549 elsif Name_Buffer (1) = '-' then
1551 -- Do not check if File is a switch other than "-l"
1553 if Name_Buffer (2) /= 'l' then
1554 return;
1555 end if;
1557 -- The argument is a library switch, get actual name. It
1558 -- is necessary to make a copy of the relevant part of
1559 -- Name_Buffer as Get_Library_Name uses Name_Buffer as well.
1561 declare
1562 Base_Name : constant String := Name_Buffer (3 .. Name_Len);
1564 begin
1565 Name := Get_Library_File (Base_Name);
1566 end;
1568 if Name = No_File then
1569 return;
1570 end if;
1571 end if;
1573 Stamp := File_Stamp (Name);
1575 -- Find the youngest object file that is younger than the
1576 -- executable. If no such file exist, record the first object
1577 -- file that is not found.
1579 if (O_Stamp < Stamp and then E_Stamp < Stamp)
1580 or else (O_File = No_File and then Stamp (Stamp'First) = ' ')
1581 then
1582 O_Stamp := Stamp;
1583 O_File := Name;
1585 -- Strip the trailing NUL if present
1587 Get_Name_String (O_File);
1589 if Name_Buffer (Name_Len) = NUL then
1590 Name_Len := Name_Len - 1;
1591 O_File := Name_Find;
1592 end if;
1593 end if;
1594 end Check_File;
1596 ----------------------
1597 -- Get_Library_Name --
1598 ----------------------
1600 -- See comments in a-adaint.c about template syntax
1602 function Get_Library_File (Name : String) return File_Name_Type is
1603 File : File_Name_Type := No_File;
1605 begin
1606 Name_Len := 0;
1608 for Ptr in Template'Range loop
1609 case Template (Ptr) is
1610 when '*' =>
1611 Add_Str_To_Name_Buffer (Name);
1613 when ';' =>
1614 File := Full_Lib_File_Name (Name_Find);
1615 exit when File /= No_File;
1616 Name_Len := 0;
1618 when NUL =>
1619 exit;
1621 when others =>
1622 Add_Char_To_Name_Buffer (Template (Ptr));
1623 end case;
1624 end loop;
1626 -- The for loop exited because the end of the template
1627 -- was reached. File contains the last possible file name
1628 -- for the library.
1630 if File = No_File and then Name_Len > 0 then
1631 File := Full_Lib_File_Name (Name_Find);
1632 end if;
1634 return File;
1635 end Get_Library_File;
1637 -- Start of processing for Check_Linker_Options
1639 begin
1640 O_File := No_File;
1641 O_Stamp := (others => ' ');
1643 -- Process linker options from the ALI files.
1645 for Opt in 1 .. Linker_Options.Last loop
1646 Check_File (Linker_Options.Table (Opt).Name);
1647 end loop;
1649 -- Process options given on the command line.
1651 for Opt in Linker_Switches.First .. Linker_Switches.Last loop
1653 -- Check if the previous Opt has one of the two switches
1654 -- that take an extra parameter. (See GCC manual.)
1656 if Opt = Linker_Switches.First
1657 or else (Linker_Switches.Table (Opt - 1).all /= "-u"
1658 and then
1659 Linker_Switches.Table (Opt - 1).all /= "-Xlinker"
1660 and then
1661 Linker_Switches.Table (Opt - 1).all /= "-L")
1662 then
1663 Name_Len := 0;
1664 Add_Str_To_Name_Buffer (Linker_Switches.Table (Opt).all);
1665 Check_File (Name_Find);
1666 end if;
1667 end loop;
1669 end Check_Linker_Options;
1671 -----------------
1672 -- Check_Steps --
1673 -----------------
1675 procedure Check_Steps is
1676 begin
1677 -- If either -c, -b or -l has been specified, we will not necessarily
1678 -- execute all steps.
1680 if Make_Steps then
1681 Do_Compile_Step := Do_Compile_Step and Compile_Only;
1682 Do_Bind_Step := Do_Bind_Step and Bind_Only;
1683 Do_Link_Step := Do_Link_Step and Link_Only;
1685 -- If -c has been specified, but not -b, ignore any potential -l
1687 if Do_Compile_Step and then not Do_Bind_Step then
1688 Do_Link_Step := False;
1689 end if;
1690 end if;
1691 end Check_Steps;
1693 -----------------------
1694 -- Collect_Arguments --
1695 -----------------------
1697 procedure Collect_Arguments
1698 (Source_File : File_Name_Type;
1699 Source_Index : Int;
1700 Args : Argument_List)
1702 begin
1703 Arguments_Collected := True;
1704 Arguments_Project := No_Project;
1705 Last_Argument := 0;
1706 Add_Arguments (Args);
1708 if Main_Project /= No_Project then
1709 declare
1710 Source_File_Name : constant String :=
1711 Get_Name_String (Source_File);
1712 Compiler_Package : Prj.Package_Id;
1713 Switches : Prj.Variable_Value;
1714 Data : Project_Data;
1716 begin
1717 Prj.Env.
1718 Get_Reference
1719 (Source_File_Name => Source_File_Name,
1720 Project => Arguments_Project,
1721 Path => Arguments_Path_Name);
1723 -- If the source is not a source of a project file, check if
1724 -- this is allowed.
1726 if Arguments_Project = No_Project then
1727 if not External_Unit_Compilation_Allowed then
1728 Make_Failed ("external source (", Source_File_Name,
1729 ") is not part of any project; cannot be " &
1730 "compiled without gnatmake switch -x");
1731 end if;
1733 -- If it is allowed, simply add the saved gcc switches
1735 Add_Arguments (The_Saved_Gcc_Switches.all);
1737 else
1738 -- We get the project directory for the relative path
1739 -- switches and arguments.
1741 Data := Projects.Table (Arguments_Project);
1743 -- If the source is in an extended project, we go to
1744 -- the ultimate extending project.
1746 while Data.Extended_By /= No_Project loop
1747 Arguments_Project := Data.Extended_By;
1748 Data := Projects.Table (Arguments_Project);
1749 end loop;
1751 -- If building a dynamic or relocatable library, compile with
1752 -- PIC option, if it exists.
1754 if Data.Library and then Data.Library_Kind /= Static then
1755 declare
1756 PIC : constant String := MLib.Tgt.PIC_Option;
1758 begin
1759 if PIC /= "" then
1760 Add_Arguments ((1 => new String'(PIC)));
1761 end if;
1762 end;
1763 end if;
1765 if Data.Dir_Path = null then
1766 Data.Dir_Path :=
1767 new String'(Get_Name_String (Data.Display_Directory));
1768 Projects.Table (Arguments_Project) := Data;
1769 end if;
1771 -- We now look for package Compiler
1772 -- and get the switches from this package.
1774 Compiler_Package :=
1775 Prj.Util.Value_Of
1776 (Name => Name_Compiler,
1777 In_Packages => Data.Decl.Packages);
1779 if Compiler_Package /= No_Package then
1781 -- If package Gnatmake.Compiler exists, we get
1782 -- the specific switches for the current source,
1783 -- or the global switches, if any.
1785 Switches := Switches_Of
1786 (Source_File => Source_File,
1787 Source_File_Name => Source_File_Name,
1788 Source_Index => Source_Index,
1789 Naming => Data.Naming,
1790 In_Package => Compiler_Package,
1791 Allow_ALI => False);
1793 end if;
1795 case Switches.Kind is
1797 -- We have a list of switches. We add these switches,
1798 -- plus the saved gcc switches.
1800 when List =>
1802 declare
1803 Current : String_List_Id := Switches.Values;
1804 Element : String_Element;
1805 Number : Natural := 0;
1807 begin
1808 while Current /= Nil_String loop
1809 Element := String_Elements.Table (Current);
1810 Number := Number + 1;
1811 Current := Element.Next;
1812 end loop;
1814 declare
1815 New_Args : Argument_List (1 .. Number);
1817 begin
1818 Current := Switches.Values;
1820 for Index in New_Args'Range loop
1821 Element := String_Elements.Table (Current);
1822 Get_Name_String (Element.Value);
1823 New_Args (Index) :=
1824 new String'(Name_Buffer (1 .. Name_Len));
1825 Test_If_Relative_Path
1826 (New_Args (Index), Parent => Data.Dir_Path);
1827 Current := Element.Next;
1828 end loop;
1830 Add_Arguments
1831 (Configuration_Pragmas_Switch
1832 (Arguments_Project) &
1833 New_Args & The_Saved_Gcc_Switches.all);
1834 end;
1835 end;
1837 -- We have a single switch. We add this switch,
1838 -- plus the saved gcc switches.
1840 when Single =>
1841 Get_Name_String (Switches.Value);
1843 declare
1844 New_Args : Argument_List :=
1845 (1 => new String'
1846 (Name_Buffer (1 .. Name_Len)));
1848 begin
1849 Test_If_Relative_Path
1850 (New_Args (1), Parent => Data.Dir_Path);
1851 Add_Arguments
1852 (Configuration_Pragmas_Switch (Arguments_Project) &
1853 New_Args & The_Saved_Gcc_Switches.all);
1854 end;
1856 -- We have no switches from Gnatmake.Compiler.
1857 -- We add the saved gcc switches.
1859 when Undefined =>
1860 Add_Arguments
1861 (Configuration_Pragmas_Switch (Arguments_Project) &
1862 The_Saved_Gcc_Switches.all);
1863 end case;
1864 end if;
1865 end;
1866 end if;
1868 -- Set Output_Is_Object, depending if there is a -S switch.
1869 -- If the bind step is not performed, and there is a -S switch,
1870 -- then we will not check for a valid object file.
1872 Check_For_S_Switch;
1873 end Collect_Arguments;
1875 ---------------------
1876 -- Compile_Sources --
1877 ---------------------
1879 procedure Compile_Sources
1880 (Main_Source : File_Name_Type;
1881 Args : Argument_List;
1882 First_Compiled_File : out Name_Id;
1883 Most_Recent_Obj_File : out Name_Id;
1884 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
1885 Main_Unit : out Boolean;
1886 Compilation_Failures : out Natural;
1887 Main_Index : Int := 0;
1888 Check_Readonly_Files : Boolean := False;
1889 Do_Not_Execute : Boolean := False;
1890 Force_Compilations : Boolean := False;
1891 Keep_Going : Boolean := False;
1892 In_Place_Mode : Boolean := False;
1893 Initialize_ALI_Data : Boolean := True;
1894 Max_Process : Positive := 1)
1896 No_Mapping_File : constant Natural := 0;
1898 type Compilation_Data is record
1899 Pid : Process_Id;
1900 Full_Source_File : File_Name_Type;
1901 Lib_File : File_Name_Type;
1902 Source_Unit : Unit_Name_Type;
1903 Mapping_File : Natural := No_Mapping_File;
1904 Project : Project_Id := No_Project;
1905 Syntax_Only : Boolean := False;
1906 Output_Is_Object : Boolean := True;
1907 end record;
1909 Running_Compile : array (1 .. Max_Process) of Compilation_Data;
1910 -- Used to save information about outstanding compilations.
1912 Outstanding_Compiles : Natural := 0;
1913 -- Current number of outstanding compiles
1915 Source_Unit : Unit_Name_Type;
1916 -- Current source unit
1918 Source_File : File_Name_Type;
1919 -- Current source file
1921 Full_Source_File : File_Name_Type;
1922 -- Full name of the current source file
1924 Lib_File : File_Name_Type;
1925 -- Current library file
1927 Full_Lib_File : File_Name_Type;
1928 -- Full name of the current library file
1930 Obj_File : File_Name_Type;
1931 -- Full name of the object file corresponding to Lib_File.
1933 Obj_Stamp : Time_Stamp_Type;
1934 -- Time stamp of the current object file.
1936 Sfile : File_Name_Type;
1937 -- Contains the source file of the units withed by Source_File
1939 ALI : ALI_Id;
1940 -- ALI Id of the current ALI file
1942 Read_Only : Boolean := False;
1944 Compilation_OK : Boolean;
1945 Need_To_Compile : Boolean;
1947 Pid : Process_Id;
1948 Text : Text_Buffer_Ptr;
1950 Mfile : Natural := No_Mapping_File;
1952 Need_To_Check_Standard_Library : Boolean :=
1953 Check_Readonly_Files and not Unique_Compile;
1955 Mapping_File_Arg : String_Access;
1957 procedure Add_Process
1958 (Pid : Process_Id;
1959 Sfile : File_Name_Type;
1960 Afile : File_Name_Type;
1961 Uname : Unit_Name_Type;
1962 Mfile : Natural := No_Mapping_File);
1963 -- Adds process Pid to the current list of outstanding compilation
1964 -- processes and record the full name of the source file Sfile that
1965 -- we are compiling, the name of its library file Afile and the
1966 -- name of its unit Uname. If Mfile is not equal to No_Mapping_File,
1967 -- it is the index of the mapping file used during compilation in the
1968 -- array The_Mapping_File_Names.
1970 procedure Await_Compile
1971 (Sfile : out File_Name_Type;
1972 Afile : out File_Name_Type;
1973 Uname : out Unit_Name_Type;
1974 OK : out Boolean);
1975 -- Awaits that an outstanding compilation process terminates. When
1976 -- it does set Sfile to the name of the source file that was compiled
1977 -- Afile to the name of its library file and Uname to the name of its
1978 -- unit. Note that this time stamp can be used to check whether the
1979 -- compilation did generate an object file. OK is set to True if the
1980 -- compilation succeeded. Note that Sfile, Afile and Uname could be
1981 -- resp. No_File, No_File and No_Name if there were no compilations
1982 -- to wait for.
1984 function Bad_Compilation_Count return Natural;
1985 -- Returns the number of compilation failures.
1987 procedure Check_Standard_Library;
1988 -- Check if s-stalib.adb needs to be compiled
1990 procedure Collect_Arguments_And_Compile
1991 (Source_File : File_Name_Type; Source_Index : Int);
1992 -- Collect arguments from project file (if any) and compile
1994 function Compile
1995 (S : Name_Id;
1996 L : Name_Id;
1997 Source_Index : Int;
1998 Args : Argument_List) return Process_Id;
1999 -- Compiles S using Args. If S is a GNAT predefined source
2000 -- "-gnatpg" is added to Args. Non blocking call. L corresponds to the
2001 -- expected library file name. Process_Id of the process spawned to
2002 -- execute the compile.
2004 package Good_ALI is new Table.Table (
2005 Table_Component_Type => ALI_Id,
2006 Table_Index_Type => Natural,
2007 Table_Low_Bound => 1,
2008 Table_Initial => 50,
2009 Table_Increment => 100,
2010 Table_Name => "Make.Good_ALI");
2011 -- Contains the set of valid ALI files that have not yet been scanned.
2013 function Good_ALI_Present return Boolean;
2014 -- Returns True if any ALI file was recorded in the previous set.
2016 procedure Get_Mapping_File (Project : Project_Id);
2017 -- Get a mapping file name. If there is one to be reused, reuse it.
2018 -- Otherwise, create a new mapping file.
2020 function Get_Next_Good_ALI return ALI_Id;
2021 -- Returns the next good ALI_Id record;
2023 procedure Record_Failure
2024 (File : File_Name_Type;
2025 Unit : Unit_Name_Type;
2026 Found : Boolean := True);
2027 -- Records in the previous table that the compilation for File failed.
2028 -- If Found is False then the compilation of File failed because we
2029 -- could not find it. Records also Unit when possible.
2031 procedure Record_Good_ALI (A : ALI_Id);
2032 -- Records in the previous set the Id of an ALI file.
2034 -----------------
2035 -- Add_Process --
2036 -----------------
2038 procedure Add_Process
2039 (Pid : Process_Id;
2040 Sfile : File_Name_Type;
2041 Afile : File_Name_Type;
2042 Uname : Unit_Name_Type;
2043 Mfile : Natural := No_Mapping_File)
2045 OC1 : constant Positive := Outstanding_Compiles + 1;
2047 begin
2048 pragma Assert (OC1 <= Max_Process);
2049 pragma Assert (Pid /= Invalid_Pid);
2051 Running_Compile (OC1).Pid := Pid;
2052 Running_Compile (OC1).Full_Source_File := Sfile;
2053 Running_Compile (OC1).Lib_File := Afile;
2054 Running_Compile (OC1).Source_Unit := Uname;
2055 Running_Compile (OC1).Mapping_File := Mfile;
2056 Running_Compile (OC1).Project := Arguments_Project;
2057 Running_Compile (OC1).Syntax_Only := Syntax_Only;
2058 Running_Compile (OC1).Output_Is_Object := Output_Is_Object;
2060 Outstanding_Compiles := OC1;
2061 end Add_Process;
2063 --------------------
2064 -- Await_Compile --
2065 -------------------
2067 procedure Await_Compile
2068 (Sfile : out File_Name_Type;
2069 Afile : out File_Name_Type;
2070 Uname : out File_Name_Type;
2071 OK : out Boolean)
2073 Pid : Process_Id;
2074 Project : Project_Id;
2076 begin
2077 pragma Assert (Outstanding_Compiles > 0);
2079 Sfile := No_File;
2080 Afile := No_File;
2081 Uname := No_Name;
2082 OK := False;
2084 -- The loop here is a work-around for a problem on VMS; in some
2085 -- circumstances (shared library and several executables, for
2086 -- example), there are child processes other than compilation
2087 -- processes that are received. Until this problem is resolved,
2088 -- we will ignore such processes.
2090 loop
2091 Wait_Process (Pid, OK);
2093 if Pid = Invalid_Pid then
2094 return;
2095 end if;
2097 for J in Running_Compile'First .. Outstanding_Compiles loop
2098 if Pid = Running_Compile (J).Pid then
2099 Sfile := Running_Compile (J).Full_Source_File;
2100 Afile := Running_Compile (J).Lib_File;
2101 Uname := Running_Compile (J).Source_Unit;
2102 Syntax_Only := Running_Compile (J).Syntax_Only;
2103 Output_Is_Object := Running_Compile (J).Output_Is_Object;
2104 Project := Running_Compile (J).Project;
2106 -- If a mapping file was used by this compilation,
2107 -- get its file name for reuse by a subsequent compilation
2109 if Running_Compile (J).Mapping_File /= No_Mapping_File then
2110 Last_Free_Indices (Project) :=
2111 Last_Free_Indices (Project) + 1;
2112 The_Free_Mapping_File_Indices
2113 (Project, Last_Free_Indices (Project)) :=
2114 Running_Compile (J).Mapping_File;
2115 end if;
2117 -- To actually remove this Pid and related info from
2118 -- Running_Compile replace its entry with the last valid
2119 -- entry in Running_Compile.
2121 if J = Outstanding_Compiles then
2122 null;
2124 else
2125 Running_Compile (J) :=
2126 Running_Compile (Outstanding_Compiles);
2127 end if;
2129 Outstanding_Compiles := Outstanding_Compiles - 1;
2130 return;
2131 end if;
2132 end loop;
2134 -- This child process was not one of our compilation processes;
2135 -- just ignore it for now.
2137 -- raise Program_Error;
2138 end loop;
2139 end Await_Compile;
2141 ---------------------------
2142 -- Bad_Compilation_Count --
2143 ---------------------------
2145 function Bad_Compilation_Count return Natural is
2146 begin
2147 return Bad_Compilation.Last - Bad_Compilation.First + 1;
2148 end Bad_Compilation_Count;
2150 ----------------------------
2151 -- Check_Standard_Library --
2152 ----------------------------
2154 procedure Check_Standard_Library is
2155 begin
2156 Need_To_Check_Standard_Library := False;
2158 if not Targparm.Suppress_Standard_Library_On_Target then
2159 declare
2160 Sfile : Name_Id;
2161 Add_It : Boolean := True;
2163 begin
2164 Name_Len := Standard_Library_Package_Body_Name'Length;
2165 Name_Buffer (1 .. Name_Len) :=
2166 Standard_Library_Package_Body_Name;
2167 Sfile := Name_Enter;
2169 -- If we have a special runtime, we add the standard
2170 -- library only if we can find it.
2172 if RTS_Switch then
2173 Add_It :=
2174 Find_File (Sfile, Osint.Source) /= No_File;
2175 end if;
2177 if Add_It then
2178 if Is_Marked (Sfile) then
2179 if Is_In_Obsoleted (Sfile) then
2180 Executable_Obsolete := True;
2181 end if;
2183 else
2184 Insert_Q (Sfile, Index => 0);
2185 Mark (Sfile, Index => 0);
2186 end if;
2187 end if;
2188 end;
2189 end if;
2190 end Check_Standard_Library;
2192 -----------------------------------
2193 -- Collect_Arguments_And_Compile --
2194 -----------------------------------
2196 procedure Collect_Arguments_And_Compile
2197 (Source_File : File_Name_Type; Source_Index : Int)
2199 begin
2201 -- If arguments have not yet been collected (in Check), collect them
2202 -- now.
2204 if not Arguments_Collected then
2205 Collect_Arguments (Source_File, Source_Index, Args);
2206 end if;
2208 -- If we use mapping file (-P or -C switches), then get one
2210 if Create_Mapping_File then
2211 Get_Mapping_File (Arguments_Project);
2212 end if;
2214 -- If the source is part of a project file, we set the ADA_*_PATHs,
2215 -- check for an eventual library project, and use the full path.
2217 if Arguments_Project /= No_Project then
2218 Prj.Env.Set_Ada_Paths (Arguments_Project, True);
2220 if MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None then
2221 declare
2222 The_Data : Project_Data :=
2223 Projects.Table (Arguments_Project);
2224 Prj : Project_Id := Arguments_Project;
2226 begin
2227 while The_Data.Extended_By /= No_Project loop
2228 Prj := The_Data.Extended_By;
2229 The_Data := Projects.Table (Prj);
2230 end loop;
2232 if The_Data.Library
2233 and then not The_Data.Need_To_Build_Lib
2234 then
2235 -- Add to the Q all sources of the project that
2236 -- have not been marked
2238 Insert_Project_Sources
2239 (The_Project => Prj,
2240 All_Projects => False,
2241 Into_Q => True);
2243 -- Now mark the project as processed
2245 Projects.Table (Prj).Need_To_Build_Lib := True;
2246 end if;
2247 end;
2248 end if;
2250 -- Change to the object directory of the project file,
2251 -- if necessary.
2253 Change_To_Object_Directory (Arguments_Project);
2255 Pid := Compile (Arguments_Path_Name, Lib_File, Source_Index,
2256 Arguments (1 .. Last_Argument));
2258 else
2259 -- If this is a source outside of any project file, make sure
2260 -- it will be compiled in the object directory of the main project
2261 -- file.
2263 if Main_Project /= No_Project then
2264 Change_To_Object_Directory (Arguments_Project);
2265 end if;
2267 Pid := Compile (Full_Source_File, Lib_File, Source_Index,
2268 Arguments (1 .. Last_Argument));
2269 end if;
2270 end Collect_Arguments_And_Compile;
2272 -------------
2273 -- Compile --
2274 -------------
2276 function Compile
2277 (S : Name_Id;
2278 L : Name_Id;
2279 Source_Index : Int;
2280 Args : Argument_List) return Process_Id
2282 Comp_Args : Argument_List (Args'First .. Args'Last + 9);
2283 Comp_Next : Integer := Args'First;
2284 Comp_Last : Integer;
2286 function Ada_File_Name (Name : Name_Id) return Boolean;
2287 -- Returns True if Name is the name of an ada source file
2288 -- (i.e. suffix is .ads or .adb)
2290 -------------------
2291 -- Ada_File_Name --
2292 -------------------
2294 function Ada_File_Name (Name : Name_Id) return Boolean is
2295 begin
2296 Get_Name_String (Name);
2297 return
2298 Name_Len > 4
2299 and then Name_Buffer (Name_Len - 3 .. Name_Len - 1) = ".ad"
2300 and then (Name_Buffer (Name_Len) = 'b'
2301 or else
2302 Name_Buffer (Name_Len) = 's');
2303 end Ada_File_Name;
2305 -- Start of processing for Compile
2307 begin
2308 Enter_Into_Obsoleted (S);
2310 -- By default, Syntax_Only is False
2312 Syntax_Only := False;
2314 for J in Args'Range loop
2315 if Args (J).all = "-gnats" then
2317 -- If we compile with -gnats, the bind step and the link step
2318 -- are inhibited. Also, we set Syntax_Only to True, so that
2319 -- we don't fail when we don't find the ALI file, after
2320 -- compilation.
2322 Do_Bind_Step := False;
2323 Do_Link_Step := False;
2324 Syntax_Only := True;
2326 elsif Args (J).all = "-gnatc" then
2328 -- If we compile with -gnatc, the bind step and the link step
2329 -- are inhibited. We set Syntax_Only to False for the case when
2330 -- -gnats was previously specified.
2332 Do_Bind_Step := False;
2333 Do_Link_Step := False;
2334 Syntax_Only := False;
2335 end if;
2336 end loop;
2338 Comp_Args (Comp_Next) := Comp_Flag;
2339 Comp_Next := Comp_Next + 1;
2341 -- Optimize the simple case where the gcc command line looks like
2342 -- gcc -c -I. ... -I- file.adb --into-> gcc -c ... file.adb
2344 if Args (Args'First).all = "-I" & Normalized_CWD
2345 and then Args (Args'Last).all = "-I-"
2346 and then S = Strip_Directory (S)
2347 then
2348 Comp_Last := Comp_Next + Args'Length - 3;
2349 Comp_Args (Comp_Next .. Comp_Last) :=
2350 Args (Args'First + 1 .. Args'Last - 1);
2352 else
2353 Comp_Last := Comp_Next + Args'Length - 1;
2354 Comp_Args (Comp_Next .. Comp_Last) := Args;
2355 end if;
2357 -- Set -gnatpg for predefined files (for this purpose the renamings
2358 -- such as Text_IO do not count as predefined). Note that we strip
2359 -- the directory name from the source file name becase the call to
2360 -- Fname.Is_Predefined_File_Name cannot deal with directory prefixes.
2362 declare
2363 Fname : constant File_Name_Type := Strip_Directory (S);
2365 begin
2366 if Is_Predefined_File_Name (Fname, False) then
2367 if Check_Readonly_Files then
2368 Comp_Last := Comp_Last + 1;
2369 Comp_Args (Comp_Last) := GNAT_Flag;
2371 else
2372 Make_Failed
2373 ("not allowed to compile """ &
2374 Get_Name_String (Fname) &
2375 """; use -a switch, or compile file with " &
2376 """-gnatg"" switch");
2377 end if;
2378 end if;
2379 end;
2381 -- Now check if the file name has one of the suffixes familiar to
2382 -- the gcc driver. If this is not the case then add the ada flag
2383 -- "-x ada".
2385 if not Ada_File_Name (S) and then not Targparm.AAMP_On_Target then
2386 Comp_Last := Comp_Last + 1;
2387 Comp_Args (Comp_Last) := Ada_Flag_1;
2388 Comp_Last := Comp_Last + 1;
2389 Comp_Args (Comp_Last) := Ada_Flag_2;
2390 end if;
2392 if Source_Index /= 0 then
2393 declare
2394 Num : constant String := Source_Index'Img;
2395 begin
2396 Comp_Last := Comp_Last + 1;
2397 Comp_Args (Comp_Last) :=
2398 new String'("-gnateI" & Num (Num'First + 1 .. Num'Last));
2399 end;
2400 end if;
2402 if Source_Index /= 0 or else
2403 L /= Strip_Directory (L) or else
2404 Object_Directory_Path /= null
2405 then
2407 -- Build -o argument.
2409 Get_Name_String (L);
2411 for J in reverse 1 .. Name_Len loop
2412 if Name_Buffer (J) = '.' then
2413 Name_Len := J + Object_Suffix'Length - 1;
2414 Name_Buffer (J .. Name_Len) := Object_Suffix;
2415 exit;
2416 end if;
2417 end loop;
2419 Comp_Last := Comp_Last + 1;
2420 Comp_Args (Comp_Last) := Output_Flag;
2421 Comp_Last := Comp_Last + 1;
2423 -- If an object directory was specified, prepend the object file
2424 -- name with this object directory.
2426 if Object_Directory_Path /= null then
2427 Comp_Args (Comp_Last) :=
2428 new String'(Object_Directory_Path.all &
2429 Name_Buffer (1 .. Name_Len));
2431 else
2432 Comp_Args (Comp_Last) :=
2433 new String'(Name_Buffer (1 .. Name_Len));
2434 end if;
2435 end if;
2437 if Create_Mapping_File then
2438 Comp_Last := Comp_Last + 1;
2439 Comp_Args (Comp_Last) := Mapping_File_Arg;
2440 end if;
2442 Get_Name_String (S);
2444 Comp_Last := Comp_Last + 1;
2445 Comp_Args (Comp_Last) := new String'(Name_Buffer (1 .. Name_Len));
2447 GNAT.OS_Lib.Normalize_Arguments (Comp_Args (Args'First .. Comp_Last));
2449 Comp_Last := Comp_Last + 1;
2450 Comp_Args (Comp_Last) := new String'("-gnatez");
2452 Display (Gcc.all, Comp_Args (Args'First .. Comp_Last));
2454 if Gcc_Path = null then
2455 Make_Failed ("error, unable to locate ", Gcc.all);
2456 end if;
2458 return
2459 GNAT.OS_Lib.Non_Blocking_Spawn
2460 (Gcc_Path.all, Comp_Args (Args'First .. Comp_Last));
2461 end Compile;
2463 ----------------------
2464 -- Get_Mapping_File --
2465 ----------------------
2467 procedure Get_Mapping_File (Project : Project_Id) is
2468 begin
2469 -- If there is a mapping file ready to be reused, reuse it
2471 if Last_Free_Indices (Project) > 0 then
2472 Mfile := The_Free_Mapping_File_Indices
2473 (Project, Last_Free_Indices (Project));
2474 Last_Free_Indices (Project) := Last_Free_Indices (Project) - 1;
2476 -- Otherwise, create and initialize a new one
2478 else
2479 Init_Mapping_File (Project => Project, File_Index => Mfile);
2480 end if;
2482 -- Put the name in the mapping file argument for the invocation
2483 -- of the compiler.
2485 Free (Mapping_File_Arg);
2486 Mapping_File_Arg :=
2487 new String'("-gnatem=" &
2488 Get_Name_String
2489 (The_Mapping_File_Names (Project, Mfile)));
2491 end Get_Mapping_File;
2493 -----------------------
2494 -- Get_Next_Good_ALI --
2495 -----------------------
2497 function Get_Next_Good_ALI return ALI_Id is
2498 ALI : ALI_Id;
2500 begin
2501 pragma Assert (Good_ALI_Present);
2502 ALI := Good_ALI.Table (Good_ALI.Last);
2503 Good_ALI.Decrement_Last;
2504 return ALI;
2505 end Get_Next_Good_ALI;
2507 ----------------------
2508 -- Good_ALI_Present --
2509 ----------------------
2511 function Good_ALI_Present return Boolean is
2512 begin
2513 return Good_ALI.First <= Good_ALI.Last;
2514 end Good_ALI_Present;
2516 --------------------
2517 -- Record_Failure --
2518 --------------------
2520 procedure Record_Failure
2521 (File : File_Name_Type;
2522 Unit : Unit_Name_Type;
2523 Found : Boolean := True)
2525 begin
2526 Bad_Compilation.Increment_Last;
2527 Bad_Compilation.Table (Bad_Compilation.Last) := (File, Unit, Found);
2528 end Record_Failure;
2530 ---------------------
2531 -- Record_Good_ALI --
2532 ---------------------
2534 procedure Record_Good_ALI (A : ALI_Id) is
2535 begin
2536 Good_ALI.Increment_Last;
2537 Good_ALI.Table (Good_ALI.Last) := A;
2538 end Record_Good_ALI;
2540 -- Start of processing for Compile_Sources
2542 begin
2543 pragma Assert (Args'First = 1);
2545 -- Package and Queue initializations.
2547 Good_ALI.Init;
2548 Output.Set_Standard_Error;
2550 if First_Q_Initialization then
2551 Init_Q;
2552 end if;
2554 if Initialize_ALI_Data then
2555 Initialize_ALI;
2556 Initialize_ALI_Source;
2557 end if;
2559 -- The following two flags affect the behavior of ALI.Set_Source_Table.
2560 -- We set Check_Source_Files to True to ensure that source file
2561 -- time stamps are checked, and we set All_Sources to False to
2562 -- avoid checking the presence of the source files listed in the
2563 -- source dependency section of an ali file (which would be a mistake
2564 -- since the ali file may be obsolete).
2566 Check_Source_Files := True;
2567 All_Sources := False;
2569 -- Only insert in the Q if it is not already done, to avoid simultaneous
2570 -- compilations if -jnnn is used.
2572 if not Is_Marked (Main_Source, Main_Index) then
2573 Insert_Q (Main_Source, Index => Main_Index);
2574 Mark (Main_Source, Main_Index);
2575 end if;
2577 First_Compiled_File := No_File;
2578 Most_Recent_Obj_File := No_File;
2579 Most_Recent_Obj_Stamp := Empty_Time_Stamp;
2580 Main_Unit := False;
2582 -- Keep looping until there is no more work to do (the Q is empty)
2583 -- and all the outstanding compilations have terminated
2585 Make_Loop : while not Empty_Q or else Outstanding_Compiles > 0 loop
2587 -- If the user does not want to keep going in case of errors then
2588 -- wait for the remaining outstanding compiles and then exit.
2590 if Bad_Compilation_Count > 0 and then not Keep_Going then
2591 while Outstanding_Compiles > 0 loop
2592 Await_Compile
2593 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
2595 if not Compilation_OK then
2596 Record_Failure (Full_Source_File, Source_Unit);
2597 end if;
2598 end loop;
2600 exit Make_Loop;
2601 end if;
2603 -- PHASE 1: Check if there is more work that we can do (ie the Q
2604 -- is non empty). If there is, do it only if we have not yet used
2605 -- up all the available processes.
2607 if not Empty_Q and then Outstanding_Compiles < Max_Process then
2608 declare
2609 Source_Index : Int;
2610 -- Index of the current unit in the current source file
2612 begin
2613 Extract_From_Q (Source_File, Source_Unit, Source_Index);
2614 Full_Source_File := Osint.Full_Source_Name (Source_File);
2615 Lib_File := Osint.Lib_File_Name
2616 (Source_File, Source_Index);
2617 Full_Lib_File := Osint.Full_Lib_File_Name (Lib_File);
2619 -- If this source has already been compiled, the executable is
2620 -- obsolete.
2622 if Is_In_Obsoleted (Source_File) then
2623 Executable_Obsolete := True;
2624 end if;
2626 -- If the library file is an Ada library skip it
2628 if Full_Lib_File /= No_File
2629 and then In_Ada_Lib_Dir (Full_Lib_File)
2630 then
2631 Verbose_Msg
2632 (Lib_File, "is in an Ada library", Prefix => " ");
2634 -- If the library file is a read-only library skip it, but
2635 -- only if, when using project files, this library file is
2636 -- in the right object directory (a read-only ALI file
2637 -- in the object directory of a project being extended
2638 -- should not be skipped).
2640 elsif Full_Lib_File /= No_File
2641 and then not Check_Readonly_Files
2642 and then Is_Readonly_Library (Full_Lib_File)
2643 and then Is_In_Object_Directory (Source_File, Full_Lib_File)
2644 then
2645 Verbose_Msg
2646 (Lib_File, "is a read-only library", Prefix => " ");
2648 -- The source file that we are checking cannot be located
2650 elsif Full_Source_File = No_File then
2651 Record_Failure (Source_File, Source_Unit, False);
2653 -- Source and library files can be located but are internal
2654 -- files
2656 elsif not Check_Readonly_Files
2657 and then Full_Lib_File /= No_File
2658 and then Is_Internal_File_Name (Source_File)
2659 then
2660 if Force_Compilations then
2661 Fail
2662 ("not allowed to compile """ &
2663 Get_Name_String (Source_File) &
2664 """; use -a switch, or compile file with " &
2665 """-gnatg"" switch");
2666 end if;
2668 Verbose_Msg
2669 (Lib_File, "is an internal library", Prefix => " ");
2671 -- The source file that we are checking can be located
2673 else
2674 Arguments_Collected := False;
2676 -- Don't waste any time if we have to recompile anyway
2678 Obj_Stamp := Empty_Time_Stamp;
2679 Need_To_Compile := Force_Compilations;
2681 if not Force_Compilations then
2682 Read_Only :=
2683 Full_Lib_File /= No_File
2684 and then not Check_Readonly_Files
2685 and then Is_Readonly_Library (Full_Lib_File);
2686 Check (Source_File, Source_Index, Args, Lib_File,
2687 Read_Only, ALI, Obj_File, Obj_Stamp);
2688 Need_To_Compile := (ALI = No_ALI_Id);
2689 end if;
2691 if not Need_To_Compile then
2693 -- The ALI file is up-to-date. Record its Id.
2695 Record_Good_ALI (ALI);
2697 -- Record the time stamp of the most recent object file
2698 -- as long as no (re)compilations are needed.
2700 if First_Compiled_File = No_File
2701 and then (Most_Recent_Obj_File = No_File
2702 or else Obj_Stamp > Most_Recent_Obj_Stamp)
2703 then
2704 Most_Recent_Obj_File := Obj_File;
2705 Most_Recent_Obj_Stamp := Obj_Stamp;
2706 end if;
2708 else
2709 -- Is this the first file we have to compile?
2711 if First_Compiled_File = No_File then
2712 First_Compiled_File := Full_Source_File;
2713 Most_Recent_Obj_File := No_File;
2715 if Do_Not_Execute then
2716 exit Make_Loop;
2717 end if;
2718 end if;
2720 if In_Place_Mode then
2722 -- If the library file was not found, then save the
2723 -- library file near the source file.
2725 if Full_Lib_File = No_File then
2726 Lib_File := Osint.Lib_File_Name
2727 (Full_Source_File, Source_Index);
2729 -- If the library file was found, then save the
2730 -- library file in the same place.
2732 else
2733 Lib_File := Full_Lib_File;
2734 end if;
2736 end if;
2738 -- Start the compilation and record it. We can do this
2739 -- because there is at least one free process.
2741 Collect_Arguments_And_Compile (Source_File, Source_Index);
2743 -- Make sure we could successfully start the compilation
2745 if Pid = Invalid_Pid then
2746 Record_Failure (Full_Source_File, Source_Unit);
2747 else
2748 Add_Process
2749 (Pid,
2750 Full_Source_File,
2751 Lib_File,
2752 Source_Unit,
2753 Mfile);
2754 end if;
2755 end if;
2756 end if;
2757 end;
2758 end if;
2760 -- PHASE 2: Now check if we should wait for a compilation to
2761 -- finish. This is the case if all the available processes are
2762 -- busy compiling sources or there is nothing else to do
2763 -- (that is the Q is empty and there are no good ALIs to process).
2765 if Outstanding_Compiles = Max_Process
2766 or else (Empty_Q
2767 and then not Good_ALI_Present
2768 and then Outstanding_Compiles > 0)
2769 then
2770 Await_Compile
2771 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
2773 if not Compilation_OK then
2774 Record_Failure (Full_Source_File, Source_Unit);
2775 end if;
2777 if Compilation_OK or else Keep_Going then
2779 -- Re-read the updated library file
2781 declare
2782 Saved_Object_Consistency : constant Boolean :=
2783 Check_Object_Consistency;
2785 begin
2786 -- If compilation was not OK, or if output is not an
2787 -- object file and we don't do the bind step, don't check
2788 -- for object consistency.
2790 Check_Object_Consistency :=
2791 Check_Object_Consistency
2792 and Compilation_OK
2793 and (Output_Is_Object or Do_Bind_Step);
2794 Text := Read_Library_Info (Lib_File);
2796 -- Restore Check_Object_Consistency to its initial value
2798 Check_Object_Consistency := Saved_Object_Consistency;
2799 end;
2801 -- If an ALI file was generated by this compilation, scan
2802 -- the ALI file and record it.
2803 -- If the scan fails, a previous ali file is inconsistent with
2804 -- the unit just compiled.
2806 if Text /= null then
2807 ALI :=
2808 Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
2810 if ALI = No_ALI_Id then
2812 -- Record a failure only if not already done
2814 if Compilation_OK then
2815 Inform
2816 (Lib_File,
2817 "incompatible ALI file, please recompile");
2818 Record_Failure (Full_Source_File, Source_Unit);
2819 end if;
2820 else
2821 Free (Text);
2822 Record_Good_ALI (ALI);
2823 end if;
2825 -- If we could not read the ALI file that was just generated
2826 -- then there could be a problem reading either the ALI or the
2827 -- corresponding object file (if Check_Object_Consistency
2828 -- is set Read_Library_Info checks that the time stamp of the
2829 -- object file is more recent than that of the ALI). For an
2830 -- example of problems caught by this test see [6625-009].
2831 -- However, we record a failure only if not already done.
2833 else
2834 if Compilation_OK and not Syntax_Only then
2835 Inform
2836 (Lib_File,
2837 "WARNING: ALI or object file not found after compile");
2838 Record_Failure (Full_Source_File, Source_Unit);
2839 end if;
2840 end if;
2841 end if;
2842 end if;
2844 -- PHASE 3: Check if we recorded good ALI files. If yes process
2845 -- them now in the order in which they have been recorded. There
2846 -- are two occasions in which we record good ali files. The first is
2847 -- in phase 1 when, after scanning an existing ALI file we realize
2848 -- it is up-to-date, the second instance is after a successful
2849 -- compilation.
2851 while Good_ALI_Present loop
2852 ALI := Get_Next_Good_ALI;
2854 declare
2855 Source_Index : Int := Unit_Index_Of (ALIs.Table (ALI).Afile);
2857 begin
2858 -- If we are processing the library file corresponding to the
2859 -- main source file check if this source can be a main unit.
2861 if ALIs.Table (ALI).Sfile = Main_Source and then
2862 Source_Index = Main_Index
2863 then
2864 Main_Unit := ALIs.Table (ALI).Main_Program /= None;
2865 end if;
2867 -- The following adds the standard library (s-stalib) to the
2868 -- list of files to be handled by gnatmake: this file and any
2869 -- files it depends on are always included in every bind,
2870 -- even if they are not in the explicit dependency list.
2871 -- Of course, it is not added if Suppress_Standard_Library
2872 -- is True.
2874 -- However, to avoid annoying output about s-stalib.ali being
2875 -- read only, when "-v" is used, we add the standard library
2876 -- only when "-a" is used.
2878 if Need_To_Check_Standard_Library then
2879 Check_Standard_Library;
2880 end if;
2882 -- Now insert in the Q the unmarked source files (i.e. those
2883 -- which have never been inserted in the Q and hence never
2884 -- considered). Only do that if Unique_Compile is False.
2886 if not Unique_Compile then
2887 for J in
2888 ALIs.Table (ALI).First_Unit .. ALIs.Table (ALI).Last_Unit
2889 loop
2890 for K in
2891 Units.Table (J).First_With .. Units.Table (J).Last_With
2892 loop
2893 Sfile := Withs.Table (K).Sfile;
2894 Add_Dependency (ALIs.Table (ALI).Sfile, Sfile);
2896 if Is_In_Obsoleted (Sfile) then
2897 Executable_Obsolete := True;
2898 end if;
2900 if Sfile = No_File then
2901 Debug_Msg
2902 ("Skipping generic:", Withs.Table (K).Uname);
2904 else
2905 Source_Index :=
2906 Unit_Index_Of (Withs.Table (K).Afile);
2908 if Is_Marked (Sfile, Source_Index) then
2909 Debug_Msg ("Skipping marked file:", Sfile);
2911 elsif not Check_Readonly_Files
2912 and then Is_Internal_File_Name (Sfile)
2913 then
2914 Debug_Msg ("Skipping internal file:", Sfile);
2916 else
2917 Insert_Q
2918 (Sfile, Withs.Table (K).Uname, Source_Index);
2919 Mark (Sfile, Source_Index);
2920 end if;
2921 end if;
2922 end loop;
2923 end loop;
2924 end if;
2925 end;
2926 end loop;
2928 if Display_Compilation_Progress then
2929 Write_Str ("completed ");
2930 Write_Int (Int (Q_Front));
2931 Write_Str (" out of ");
2932 Write_Int (Int (Q.Last));
2933 Write_Str (" (");
2934 Write_Int (Int ((Q_Front * 100) / (Q.Last - Q.First)));
2935 Write_Str ("%)...");
2936 Write_Eol;
2937 end if;
2938 end loop Make_Loop;
2940 Compilation_Failures := Bad_Compilation_Count;
2942 -- Compilation is finished
2944 -- Delete any temporary configuration pragma file
2946 Delete_Temp_Config_Files;
2948 end Compile_Sources;
2950 ----------------------------------
2951 -- Configuration_Pragmas_Switch --
2952 ----------------------------------
2954 function Configuration_Pragmas_Switch
2955 (For_Project : Project_Id) return Argument_List
2957 The_Packages : Package_Id;
2958 Gnatmake : Package_Id;
2959 Compiler : Package_Id;
2961 Global_Attribute : Variable_Value := Nil_Variable_Value;
2962 Local_Attribute : Variable_Value := Nil_Variable_Value;
2964 Global_Attribute_Present : Boolean := False;
2965 Local_Attribute_Present : Boolean := False;
2967 Result : Argument_List (1 .. 3);
2968 Last : Natural := 0;
2970 function Absolute_Path
2971 (Path : Name_Id;
2972 Project : Project_Id) return String;
2973 -- Returns an absolute path for a configuration pragmas file.
2975 -------------------
2976 -- Absolute_Path --
2977 -------------------
2979 function Absolute_Path
2980 (Path : Name_Id;
2981 Project : Project_Id) return String
2983 begin
2984 Get_Name_String (Path);
2986 declare
2987 Path_Name : constant String := Name_Buffer (1 .. Name_Len);
2989 begin
2990 if Is_Absolute_Path (Path_Name) then
2991 return Path_Name;
2993 else
2994 declare
2995 Parent_Directory : constant String :=
2996 Get_Name_String (Projects.Table (Project).Directory);
2998 begin
2999 if Parent_Directory (Parent_Directory'Last) =
3000 Directory_Separator
3001 then
3002 return Parent_Directory & Path_Name;
3004 else
3005 return Parent_Directory & Directory_Separator & Path_Name;
3006 end if;
3007 end;
3008 end if;
3009 end;
3010 end Absolute_Path;
3012 -- Start of processing for Configuration_Pragmas_Switch
3014 begin
3015 Prj.Env.Create_Config_Pragmas_File (For_Project, Main_Project);
3017 if Projects.Table (For_Project).Config_File_Name /= No_Name then
3018 Temporary_Config_File :=
3019 Projects.Table (For_Project).Config_File_Temp;
3020 Last := 1;
3021 Result (1) :=
3022 new String'
3023 ("-gnatec=" &
3024 Get_Name_String
3025 (Projects.Table (For_Project).Config_File_Name));
3027 else
3028 Temporary_Config_File := False;
3029 end if;
3031 -- Check for attribute Builder'Global_Configuration_Pragmas
3033 The_Packages := Projects.Table (Main_Project).Decl.Packages;
3034 Gnatmake :=
3035 Prj.Util.Value_Of
3036 (Name => Name_Builder,
3037 In_Packages => The_Packages);
3039 if Gnatmake /= No_Package then
3040 Global_Attribute := Prj.Util.Value_Of
3041 (Variable_Name => Name_Global_Configuration_Pragmas,
3042 In_Variables => Packages.Table (Gnatmake).Decl.Attributes);
3043 Global_Attribute_Present :=
3044 Global_Attribute /= Nil_Variable_Value
3045 and then Get_Name_String (Global_Attribute.Value) /= "";
3047 if Global_Attribute_Present then
3048 declare
3049 Path : constant String :=
3050 Absolute_Path
3051 (Global_Attribute.Value, Global_Attribute.Project);
3052 begin
3053 if not Is_Regular_File (Path) then
3054 Make_Failed
3055 ("cannot find configuration pragmas file ", Path);
3056 end if;
3058 Last := Last + 1;
3059 Result (Last) := new String'("-gnatec=" & Path);
3060 end;
3061 end if;
3062 end if;
3064 -- Check for attribute Compiler'Local_Configuration_Pragmas
3066 The_Packages := Projects.Table (For_Project).Decl.Packages;
3067 Compiler :=
3068 Prj.Util.Value_Of
3069 (Name => Name_Compiler,
3070 In_Packages => The_Packages);
3072 if Compiler /= No_Package then
3073 Local_Attribute := Prj.Util.Value_Of
3074 (Variable_Name => Name_Local_Configuration_Pragmas,
3075 In_Variables => Packages.Table (Compiler).Decl.Attributes);
3076 Local_Attribute_Present :=
3077 Local_Attribute /= Nil_Variable_Value
3078 and then Get_Name_String (Local_Attribute.Value) /= "";
3080 if Local_Attribute_Present then
3081 declare
3082 Path : constant String :=
3083 Absolute_Path
3084 (Local_Attribute.Value, Local_Attribute.Project);
3085 begin
3086 if not Is_Regular_File (Path) then
3087 Make_Failed
3088 ("cannot find configuration pragmas file ", Path);
3089 end if;
3091 Last := Last + 1;
3092 Result (Last) := new String'("-gnatec=" & Path);
3093 end;
3094 end if;
3095 end if;
3097 return Result (1 .. Last);
3098 end Configuration_Pragmas_Switch;
3100 ---------------
3101 -- Debug_Msg --
3102 ---------------
3104 procedure Debug_Msg (S : String; N : Name_Id) is
3105 begin
3106 if Debug.Debug_Flag_W then
3107 Write_Str (" ... ");
3108 Write_Str (S);
3109 Write_Str (" ");
3110 Write_Name (N);
3111 Write_Eol;
3112 end if;
3113 end Debug_Msg;
3115 ---------------------------
3116 -- Delete_All_Temp_Files --
3117 ---------------------------
3119 procedure Delete_All_Temp_Files is
3120 begin
3121 if Gnatmake_Called and not Debug.Debug_Flag_N then
3122 Delete_Mapping_Files;
3123 Delete_Temp_Config_Files;
3124 Prj.Env.Delete_All_Path_Files;
3125 end if;
3126 end Delete_All_Temp_Files;
3128 --------------------------
3129 -- Delete_Mapping_Files --
3130 --------------------------
3132 procedure Delete_Mapping_Files is
3133 Success : Boolean;
3134 begin
3135 if not Debug.Debug_Flag_N then
3136 if The_Mapping_File_Names /= null then
3137 for Project in The_Mapping_File_Names'Range (1) loop
3138 for Index in 1 .. Last_Mapping_File_Names (Project) loop
3139 Delete_File
3140 (Name => Get_Name_String
3141 (The_Mapping_File_Names (Project, Index)),
3142 Success => Success);
3143 end loop;
3144 end loop;
3145 end if;
3146 end if;
3147 end Delete_Mapping_Files;
3149 ------------------------------
3150 -- Delete_Temp_Config_Files --
3151 ------------------------------
3153 procedure Delete_Temp_Config_Files is
3154 Success : Boolean;
3155 begin
3156 if (not Debug.Debug_Flag_N) and Main_Project /= No_Project then
3157 for Project in 1 .. Projects.Last loop
3158 if Projects.Table (Project).Config_File_Temp then
3159 if Verbose_Mode then
3160 Write_Str ("Deleting temp configuration file """);
3161 Write_Str (Get_Name_String
3162 (Projects.Table (Project).Config_File_Name));
3163 Write_Line ("""");
3164 end if;
3166 Delete_File
3167 (Name => Get_Name_String
3168 (Projects.Table (Project).Config_File_Name),
3169 Success => Success);
3171 -- Make sure that we don't have a config file for this
3172 -- project, in case when there are several mains.
3173 -- In this case, we will recreate another config file:
3174 -- we cannot reuse the one that we just deleted!
3176 Projects.Table (Project).Config_Checked := False;
3177 Projects.Table (Project).Config_File_Name := No_Name;
3178 Projects.Table (Project).Config_File_Temp := False;
3179 end if;
3180 end loop;
3181 end if;
3182 end Delete_Temp_Config_Files;
3184 -------------
3185 -- Display --
3186 -------------
3188 procedure Display (Program : String; Args : Argument_List) is
3189 begin
3190 pragma Assert (Args'First = 1);
3192 if Display_Executed_Programs then
3193 Write_Str (Program);
3195 for J in Args'Range loop
3197 -- Never display -gnatez
3199 if Args (J).all /= "-gnatez" then
3201 -- Do not display the mapping file argument automatically
3202 -- created when using a project file.
3204 if Main_Project = No_Project
3205 or else Debug.Debug_Flag_N
3206 or else Args (J)'Length < 8
3207 or else
3208 Args (J) (Args (J)'First .. Args (J)'First + 6) /= "-gnatem"
3209 then
3210 -- When -dn is not specified, do not display the config
3211 -- pragmas switch (-gnatec) for the temporary file created
3212 -- by the project manager (always the first -gnatec switch).
3213 -- Reset Temporary_Config_File to False so that the eventual
3214 -- other -gnatec switches will be displayed.
3216 if (not Debug.Debug_Flag_N)
3217 and then Temporary_Config_File
3218 and then Args (J)'Length > 7
3219 and then Args (J) (Args (J)'First .. Args (J)'First + 6)
3220 = "-gnatec"
3221 then
3222 Temporary_Config_File := False;
3224 -- Do not display the -F=mapping_file switch for
3225 -- gnatbind, if -dn is not specified.
3227 elsif Debug.Debug_Flag_N
3228 or else Args (J)'Length < 4
3229 or else
3230 Args (J) (Args (J)'First .. Args (J)'First + 2) /= "-F="
3231 then
3232 Write_Str (" ");
3233 Write_Str (Args (J).all);
3234 end if;
3235 end if;
3236 end if;
3237 end loop;
3239 Write_Eol;
3240 end if;
3241 end Display;
3243 ----------------------
3244 -- Display_Commands --
3245 ----------------------
3247 procedure Display_Commands (Display : Boolean := True) is
3248 begin
3249 Display_Executed_Programs := Display;
3250 end Display_Commands;
3252 -------------
3253 -- Empty_Q --
3254 -------------
3256 function Empty_Q return Boolean is
3257 begin
3258 if Debug.Debug_Flag_P then
3259 Write_Str (" Q := [");
3261 for J in Q_Front .. Q.Last - 1 loop
3262 Write_Str (" ");
3263 Write_Name (Q.Table (J).File);
3264 Write_Eol;
3265 Write_Str (" ");
3266 end loop;
3268 Write_Str ("]");
3269 Write_Eol;
3270 end if;
3272 return Q_Front >= Q.Last;
3273 end Empty_Q;
3275 --------------------------
3276 -- Enter_Into_Obsoleted --
3277 --------------------------
3279 procedure Enter_Into_Obsoleted (F : Name_Id) is
3280 Name : constant String := Get_Name_String (F);
3281 First : Natural := Name'Last;
3282 F2 : Name_Id := F;
3284 begin
3285 while First > Name'First
3286 and then Name (First - 1) /= Directory_Separator
3287 and then Name (First - 1) /= '/'
3288 loop
3289 First := First - 1;
3290 end loop;
3292 if First /= Name'First then
3293 Name_Len := 0;
3294 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
3295 F2 := Name_Find;
3296 end if;
3298 Debug_Msg ("New entry in Obsoleted table:", F2);
3299 Obsoleted.Set (F2, True);
3300 end Enter_Into_Obsoleted;
3302 ---------------------
3303 -- Extract_Failure --
3304 ---------------------
3306 procedure Extract_Failure
3307 (File : out File_Name_Type;
3308 Unit : out Unit_Name_Type;
3309 Found : out Boolean)
3311 begin
3312 File := Bad_Compilation.Table (Bad_Compilation.Last).File;
3313 Unit := Bad_Compilation.Table (Bad_Compilation.Last).Unit;
3314 Found := Bad_Compilation.Table (Bad_Compilation.Last).Found;
3315 Bad_Compilation.Decrement_Last;
3316 end Extract_Failure;
3318 --------------------
3319 -- Extract_From_Q --
3320 --------------------
3322 procedure Extract_From_Q
3323 (Source_File : out File_Name_Type;
3324 Source_Unit : out Unit_Name_Type;
3325 Source_Index : out Int)
3327 File : constant File_Name_Type := Q.Table (Q_Front).File;
3328 Unit : constant Unit_Name_Type := Q.Table (Q_Front).Unit;
3329 Index : constant Int := Q.Table (Q_Front).Index;
3331 begin
3332 if Debug.Debug_Flag_Q then
3333 Write_Str (" Q := Q - [ ");
3334 Write_Name (File);
3336 if Index /= 0 then
3337 Write_Str (", ");
3338 Write_Int (Index);
3339 end if;
3341 Write_Str (" ]");
3342 Write_Eol;
3343 end if;
3345 Q_Front := Q_Front + 1;
3346 Source_File := File;
3347 Source_Unit := Unit;
3348 Source_Index := Index;
3349 end Extract_From_Q;
3351 --------------
3352 -- Gnatmake --
3353 --------------
3355 procedure Gnatmake is
3356 Main_Source_File : File_Name_Type;
3357 -- The source file containing the main compilation unit
3359 Compilation_Failures : Natural;
3361 Total_Compilation_Failures : Natural := 0;
3363 Is_Main_Unit : Boolean;
3364 -- Set to True by Compile_Sources if the Main_Source_File can be a
3365 -- main unit.
3367 Main_ALI_File : File_Name_Type;
3368 -- The ali file corresponding to Main_Source_File
3370 Executable : File_Name_Type := No_File;
3371 -- The file name of an executable
3373 Non_Std_Executable : Boolean := False;
3374 -- Non_Std_Executable is set to True when there is a possibility
3375 -- that the linker will not choose the correct executable file name.
3377 Current_Work_Dir : constant String_Access :=
3378 new String'(Get_Current_Dir);
3379 -- The current working directory, used to modify some relative path
3380 -- switches on the command line when a project file is used.
3382 Current_Main_Index : Int := 0;
3383 -- If not zero, the index of the current main unit in its source file
3385 There_Are_Stand_Alone_Libraries : Boolean := False;
3386 -- Set to True when there are Stand-Alone Libraries, so that gnatbind
3387 -- is invoked with the -F switch to force checking of elaboration flags.
3389 Mapping_Path : Name_Id := No_Name;
3390 -- The path name of the mapping file
3392 Discard : Boolean;
3394 procedure Check_Mains;
3395 -- Check that the main subprograms do exist and that they all
3396 -- belong to the same project file.
3398 procedure Create_Binder_Mapping_File
3399 (Args : in out Argument_List; Last_Arg : in out Natural);
3400 -- Create a binder mapping file and add the necessary switch
3402 -----------------
3403 -- Check_Mains --
3404 -----------------
3406 procedure Check_Mains is
3407 Real_Main_Project : Project_Id := No_Project;
3408 -- The project of the first main
3410 Proj : Project_Id := No_Project;
3411 -- The project of the current main
3413 Data : Project_Data;
3415 Real_Path : String_Access;
3417 begin
3418 Mains.Reset;
3420 -- Check each main
3422 loop
3423 declare
3424 Main : constant String := Mains.Next_Main;
3425 -- The name specified on the command line may include
3426 -- directory information.
3428 File_Name : constant String := Base_Name (Main);
3429 -- The simple file name of the current main main
3431 begin
3432 exit when Main = "";
3434 -- Get the project of the current main
3436 Proj := Prj.Env.Project_Of (File_Name, Main_Project);
3438 -- Fail if the current main is not a source of a
3439 -- project.
3441 if Proj = No_Project then
3442 Make_Failed
3443 ("""" & Main &
3444 """ is not a source of any project");
3446 else
3447 -- If there is directory information, check that
3448 -- the source exists and, if it does, that the path
3449 -- is the actual path of a source of a project.
3451 if Main /= File_Name then
3452 Data := Projects.Table (Main_Project);
3454 Real_Path :=
3455 Locate_Regular_File
3456 (Main &
3457 Get_Name_String
3458 (Data.Naming.Current_Body_Suffix),
3459 "");
3460 if Real_Path = null then
3461 Real_Path :=
3462 Locate_Regular_File
3463 (Main &
3464 Get_Name_String
3465 (Data.Naming.Current_Spec_Suffix),
3466 "");
3467 end if;
3469 if Real_Path = null then
3470 Real_Path :=
3471 Locate_Regular_File (Main, "");
3472 end if;
3474 -- Fail if the file cannot be found
3476 if Real_Path = null then
3477 Make_Failed
3478 ("file """ & Main & """ does not exist");
3479 end if;
3481 declare
3482 Project_Path : constant String :=
3483 Prj.Env.File_Name_Of_Library_Unit_Body
3484 (Name => File_Name,
3485 Project => Main_Project,
3486 Main_Project_Only => False,
3487 Full_Path => True);
3488 Normed_Path : constant String :=
3489 Normalize_Pathname
3490 (Real_Path.all,
3491 Case_Sensitive => False);
3492 Proj_Path : constant String :=
3493 Normalize_Pathname
3494 (Project_Path,
3495 Case_Sensitive => False);
3497 begin
3498 Free (Real_Path);
3500 -- Fail if it is not the correct path
3502 if Normed_Path /= Proj_Path then
3503 if Verbose_Mode then
3504 Write_Str (Normed_Path);
3505 Write_Str (" /= ");
3506 Write_Line (Proj_Path);
3507 end if;
3509 Make_Failed
3510 ("""" & Main &
3511 """ is not a source of any project");
3512 end if;
3513 end;
3514 end if;
3516 if not Unique_Compile then
3518 -- Record the project, if it is the first main
3520 if Real_Main_Project = No_Project then
3521 Real_Main_Project := Proj;
3523 elsif Proj /= Real_Main_Project then
3525 -- Fail, as the current main is not a source
3526 -- of the same project as the first main.
3528 Make_Failed
3529 ("""" & Main &
3530 """ is not a source of project " &
3531 Get_Name_String
3532 (Projects.Table
3533 (Real_Main_Project).Name));
3534 end if;
3535 end if;
3536 end if;
3538 -- If -u and -U are not used, we may have mains that
3539 -- are sources of a project that is not the one
3540 -- specified with switch -P.
3542 if not Unique_Compile then
3543 Main_Project := Real_Main_Project;
3544 end if;
3545 end;
3546 end loop;
3547 end Check_Mains;
3549 --------------------------------
3550 -- Create_Binder_Mapping_File --
3551 --------------------------------
3553 procedure Create_Binder_Mapping_File
3554 (Args : in out Argument_List; Last_Arg : in out Natural)
3556 Mapping_FD : File_Descriptor := Invalid_FD;
3557 -- A File Descriptor for an eventual mapping file
3559 ALI_Unit : Name_Id := No_Name;
3560 -- The unit name of an ALI file
3562 ALI_Name : Name_Id := No_Name;
3563 -- The file name of the ALI file
3565 ALI_Project : Project_Id := No_Project;
3566 -- The project of the ALI file
3568 Bytes : Integer;
3569 OK : Boolean := True;
3571 Status : Boolean;
3572 -- For call to Close
3574 begin
3575 Tempdir.Create_Temp_File (Mapping_FD, Mapping_Path);
3577 if Mapping_FD /= Invalid_FD then
3579 -- Traverse all units
3581 for J in Prj.Com.Units.First .. Prj.Com.Units.Last loop
3582 declare
3583 Unit : constant Prj.Com.Unit_Data :=
3584 Prj.Com.Units.Table (J);
3585 use Prj.Com;
3587 begin
3588 if Unit.Name /= No_Name then
3590 -- If there is a body, put it in the mapping
3592 if Unit.File_Names (Body_Part).Name /= No_Name
3593 and then Unit.File_Names (Body_Part).Project
3594 /= No_Project
3595 then
3596 Get_Name_String (Unit.Name);
3597 Name_Buffer
3598 (Name_Len + 1 .. Name_Len + 2) := "%b";
3599 Name_Len := Name_Len + 2;
3600 ALI_Unit := Name_Find;
3601 ALI_Name :=
3602 Lib_File_Name
3603 (Unit.File_Names (Body_Part).Name);
3604 ALI_Project :=
3605 Unit.File_Names (Body_Part).Project;
3607 -- Otherwise, if there is a spec, put it
3608 -- in the mapping.
3610 elsif Unit.File_Names (Specification).Name
3611 /= No_Name
3612 and then Unit.File_Names
3613 (Specification).Project
3614 /= No_Project
3615 then
3616 Get_Name_String (Unit.Name);
3617 Name_Buffer
3618 (Name_Len + 1 .. Name_Len + 2) := "%s";
3619 Name_Len := Name_Len + 2;
3620 ALI_Unit := Name_Find;
3621 ALI_Name := Lib_File_Name
3622 (Unit.File_Names (Specification).Name);
3623 ALI_Project :=
3624 Unit.File_Names (Specification).Project;
3626 else
3627 ALI_Name := No_Name;
3628 end if;
3630 -- If we have something to put in the mapping
3631 -- then we do it now. However, if the project
3632 -- is extended, we don't put anything in the
3633 -- mapping file, because we do not know where
3634 -- the ALI file is: it might be in the ext-
3635 -- ended project obj dir as well as in the
3636 -- extending project obj dir.
3638 if ALI_Name /= No_Name
3639 and then
3640 Projects.Table (ALI_Project).Extended_By = No_Project
3641 and then
3642 Projects.Table (ALI_Project).Extends = No_Project
3643 then
3644 -- First line is the unit name
3646 Get_Name_String (ALI_Unit);
3647 Name_Len := Name_Len + 1;
3648 Name_Buffer (Name_Len) := ASCII.LF;
3649 Bytes :=
3650 Write
3651 (Mapping_FD,
3652 Name_Buffer (1)'Address,
3653 Name_Len);
3654 OK := Bytes = Name_Len;
3656 exit when not OK;
3658 -- Second line it the ALI file name
3660 Get_Name_String (ALI_Name);
3661 Name_Len := Name_Len + 1;
3662 Name_Buffer (Name_Len) := ASCII.LF;
3663 Bytes :=
3664 Write
3665 (Mapping_FD,
3666 Name_Buffer (1)'Address,
3667 Name_Len);
3668 OK := Bytes = Name_Len;
3670 exit when not OK;
3672 -- Third line it the ALI path name,
3673 -- concatenation of the project
3674 -- directory with the ALI file name.
3676 declare
3677 ALI : constant String :=
3678 Get_Name_String (ALI_Name);
3679 begin
3680 Get_Name_String
3681 (Projects.Table (ALI_Project).
3682 Object_Directory);
3684 if Name_Buffer (Name_Len) /=
3685 Directory_Separator
3686 then
3687 Name_Len := Name_Len + 1;
3688 Name_Buffer (Name_Len) :=
3689 Directory_Separator;
3690 end if;
3692 Name_Buffer
3693 (Name_Len + 1 ..
3694 Name_Len + ALI'Length) := ALI;
3695 Name_Len :=
3696 Name_Len + ALI'Length + 1;
3697 Name_Buffer (Name_Len) := ASCII.LF;
3698 Bytes :=
3699 Write
3700 (Mapping_FD,
3701 Name_Buffer (1)'Address,
3702 Name_Len);
3703 OK := Bytes = Name_Len;
3704 end;
3706 -- If OK is False, it means we were unable
3707 -- to write a line. No point in continuing
3708 -- with the other units.
3710 exit when not OK;
3711 end if;
3712 end if;
3713 end;
3714 end loop;
3716 Close (Mapping_FD, Status);
3718 OK := OK and Status;
3720 -- If the creation of the mapping file was successful,
3721 -- we add the switch to the arguments of gnatbind.
3723 if OK then
3724 Last_Arg := Last_Arg + 1;
3725 Args (Last_Arg) :=
3726 new String'("-F=" & Get_Name_String (Mapping_Path));
3727 end if;
3728 end if;
3729 end Create_Binder_Mapping_File;
3731 -- Start of processing for Gnatmake
3733 -- This body is very long, should be broken down ???
3735 begin
3736 Gnatmake_Called := True;
3738 Install_Int_Handler (Sigint_Intercepted'Access);
3740 Do_Compile_Step := True;
3741 Do_Bind_Step := True;
3742 Do_Link_Step := True;
3744 Obsoleted.Reset;
3746 Make.Initialize;
3748 Bind_Shared := No_Shared_Switch'Access;
3749 Link_With_Shared_Libgcc := No_Shared_Libgcc_Switch'Access;
3751 Failed_Links.Set_Last (0);
3752 Successful_Links.Set_Last (0);
3754 if Hostparm.Java_VM then
3755 Gcc := new String'("jgnat");
3756 Gnatbind := new String'("jgnatbind");
3757 Gnatlink := new String'("jgnatlink");
3759 -- Do not check for an object file (".o") when compiling to
3760 -- Java bytecode since ".class" files are generated instead.
3762 Check_Object_Consistency := False;
3763 end if;
3765 -- Special case when switch -B was specified
3767 if Build_Bind_And_Link_Full_Project then
3769 -- When switch -B is specified, there must be a project file
3771 if Main_Project = No_Project then
3772 Make_Failed ("-B cannot be used without a project file");
3774 -- No main program may be specified on the command line
3776 elsif Osint.Number_Of_Files /= 0 then
3777 Make_Failed ("-B cannot be used with a main specified on " &
3778 "the command line");
3780 -- And the project file cannot be a library project file
3782 elsif Projects.Table (Main_Project).Library then
3783 Make_Failed ("-B cannot be used for a library project file");
3785 else
3786 Insert_Project_Sources
3787 (The_Project => Main_Project,
3788 All_Projects => Unique_Compile_All_Projects,
3789 Into_Q => False);
3791 -- If there are no sources to compile, we fail
3793 if Osint.Number_Of_Files = 0 then
3794 Make_Failed ("no sources to compile");
3795 end if;
3797 -- Specify -n for gnatbind and add the ALI files of all the
3798 -- sources, except the one which is a fake main subprogram:
3799 -- this is the one for the binder generated file and it will be
3800 -- transmitted to gnatlink. These sources are those that are
3801 -- in the queue.
3803 Add_Switch ("-n", Binder, And_Save => True);
3805 for J in Q.First .. Q.Last - 1 loop
3806 Add_Switch
3807 (Get_Name_String
3808 (Lib_File_Name (Q.Table (J).File)),
3809 Binder, And_Save => True);
3810 end loop;
3811 end if;
3813 elsif Main_Index /= 0 and then Osint.Number_Of_Files > 1 then
3814 Make_Failed ("cannot specify several mains with a multi-unit index");
3816 elsif Main_Project /= No_Project then
3818 -- If the main project file is a library project file, main(s)
3819 -- cannot be specified on the command line.
3821 if Osint.Number_Of_Files /= 0 then
3822 if Projects.Table (Main_Project).Library
3823 and then not Unique_Compile
3824 and then ((not Make_Steps) or else Bind_Only or else Link_Only)
3825 then
3826 Make_Failed ("cannot specify a main program " &
3827 "on the command line for a library project file");
3829 else
3830 -- Check that each main on the command line is a source of a
3831 -- project file and, if there are several mains, each of them
3832 -- is a source of the same project file.
3834 Check_Mains;
3835 end if;
3837 -- If no mains have been specified on the command line,
3838 -- and we are using a project file, we either find the main(s)
3839 -- in the attribute Main of the main project, or we put all
3840 -- the sources of the project file as mains.
3842 else
3843 if Main_Index /= 0 then
3844 Make_Failed ("cannot specify a multi-unit index but no main " &
3845 "on the command line");
3846 end if;
3848 declare
3849 Value : String_List_Id := Projects.Table (Main_Project).Mains;
3851 begin
3852 -- The attribute Main is an empty list or not specified,
3853 -- or else gnatmake was invoked with the switch "-u".
3855 if Value = Prj.Nil_String or else Unique_Compile then
3857 if (not Make_Steps) or else Compile_Only
3858 or else not Projects.Table (Main_Project).Library
3859 then
3860 -- First make sure that the binder and the linker
3861 -- will not be invoked.
3863 Do_Bind_Step := False;
3864 Do_Link_Step := False;
3866 -- Put all the sources in the queue
3868 Insert_Project_Sources
3869 (The_Project => Main_Project,
3870 All_Projects => Unique_Compile_All_Projects,
3871 Into_Q => False);
3873 -- If there are no sources to compile, we fail
3875 if Osint.Number_Of_Files = 0 then
3876 Make_Failed ("no sources to compile");
3877 end if;
3878 end if;
3880 else
3881 -- The attribute Main is not an empty list.
3882 -- Put all the main subprograms in the list as if there
3883 -- were specified on the command line. However, if attribute
3884 -- Languages includes a language other than Ada, only
3885 -- include the Ada mains; if there is no Ada main, compile
3886 -- all the sources of the project.
3888 declare
3889 Data : constant Project_Data :=
3890 Projects.Table (Main_Project);
3892 Languages : constant Variable_Value :=
3893 Prj.Util.Value_Of
3894 (Name_Languages, Data.Decl.Attributes);
3896 Current : String_List_Id;
3897 Element : String_Element;
3899 Foreign_Language : Boolean := False;
3900 At_Least_One_Main : Boolean := False;
3902 begin
3903 -- First, determine if there is a foreign language in
3904 -- attribute Languages.
3906 if not Languages.Default then
3907 Current := Languages.Values;
3909 Look_For_Foreign :
3910 while Current /= Nil_String loop
3911 Element := String_Elements.Table (Current);
3912 Get_Name_String (Element.Value);
3913 To_Lower (Name_Buffer (1 .. Name_Len));
3915 if Name_Buffer (1 .. Name_Len) /= "ada" then
3916 Foreign_Language := True;
3917 exit Look_For_Foreign;
3918 end if;
3920 Current := Element.Next;
3921 end loop Look_For_Foreign;
3922 end if;
3924 -- Then, find all mains, or if there is a foreign
3925 -- language, all the Ada mains.
3927 while Value /= Prj.Nil_String loop
3928 Get_Name_String (String_Elements.Table (Value).Value);
3930 -- To know if a main is an Ada main, get its project.
3931 -- It should be the project specified on the command
3932 -- line.
3934 if (not Foreign_Language) or else
3935 Prj.Env.Project_Of
3936 (Name_Buffer (1 .. Name_Len), Main_Project) =
3937 Main_Project
3938 then
3939 At_Least_One_Main := True;
3940 Osint.Add_File
3941 (Get_Name_String
3942 (String_Elements.Table (Value).Value),
3943 Index => String_Elements.Table (Value).Index);
3944 end if;
3946 Value := String_Elements.Table (Value).Next;
3947 end loop;
3949 -- If we did not get any main, it means that all mains
3950 -- in attribute Mains are in a foreign language and -B
3951 -- was not specified to gnatmake; so, we fail.
3953 if not At_Least_One_Main then
3954 Make_Failed
3955 ("no Ada mains; use -B to build foreign main");
3956 end if;
3957 end;
3959 end if;
3960 end;
3961 end if;
3962 end if;
3964 if Verbose_Mode then
3965 Write_Eol;
3966 Write_Str ("GNATMAKE ");
3967 Write_Str (Gnatvsn.Gnat_Version_String);
3968 Write_Eol;
3969 Write_Str ("Copyright 1995-2004 Free Software Foundation, Inc.");
3970 Write_Eol;
3971 end if;
3973 if Osint.Number_Of_Files = 0 then
3974 if Main_Project /= No_Project
3975 and then Projects.Table (Main_Project).Library
3976 then
3977 if Do_Bind_Step
3978 and then not Projects.Table (Main_Project).Standalone_Library
3979 then
3980 Make_Failed ("only stand-alone libraries may be bound");
3981 end if;
3983 -- Add the default search directories to be able to find libgnat
3985 Osint.Add_Default_Search_Dirs;
3987 -- And bind and or link the library
3989 MLib.Prj.Build_Library
3990 (For_Project => Main_Project,
3991 Gnatbind => Gnatbind.all,
3992 Gnatbind_Path => Gnatbind_Path,
3993 Gcc => Gcc.all,
3994 Gcc_Path => Gcc_Path,
3995 Bind => Bind_Only,
3996 Link => Link_Only);
3997 Exit_Program (E_Success);
3999 else
4000 -- Output usage information if no files to compile
4002 Usage;
4003 Exit_Program (E_Fatal);
4004 end if;
4005 end if;
4007 -- If -M was specified, behave as if -n was specified
4009 if List_Dependencies then
4010 Do_Not_Execute := True;
4011 end if;
4013 -- Note that Osint.Next_Main_Source will always return the (possibly
4014 -- abbreviated file) without any directory information.
4016 Main_Source_File := Next_Main_Source;
4018 if Current_File_Index /= No_Index then
4019 Main_Index := Current_File_Index;
4020 end if;
4022 Add_Switch ("-I-", Binder, And_Save => True);
4023 Add_Switch ("-I-", Compiler, And_Save => True);
4025 if Main_Project = No_Project then
4026 if Look_In_Primary_Dir then
4028 Add_Switch
4029 ("-I" &
4030 Normalize_Directory_Name
4031 (Get_Primary_Src_Search_Directory.all).all,
4032 Compiler, Append_Switch => False,
4033 And_Save => False);
4035 Add_Switch ("-aO" & Normalized_CWD,
4036 Binder,
4037 Append_Switch => False,
4038 And_Save => False);
4039 end if;
4041 else
4042 -- If we use a project file, we have already checked that a main
4043 -- specified on the command line with directory information has the
4044 -- path name corresponding to a correct source in the project tree.
4045 -- So, we don't need the directory information to be taken into
4046 -- account by Find_File, and in fact it may lead to take the wrong
4047 -- sources for other compilation units, when there are extending
4048 -- projects.
4050 Look_In_Primary_Dir := False;
4051 end if;
4053 -- If the user wants a program without a main subprogram, add the
4054 -- appropriate switch to the binder.
4056 if No_Main_Subprogram then
4057 Add_Switch ("-z", Binder, And_Save => True);
4058 end if;
4060 if Main_Project /= No_Project then
4062 if Projects.Table (Main_Project).Object_Directory = No_Name then
4063 Make_Failed ("no sources to compile");
4064 end if;
4066 -- Change the current directory to the object directory of the main
4067 -- project.
4069 begin
4070 Project_Object_Directory := No_Project;
4071 Change_To_Object_Directory (Main_Project);
4073 exception
4074 when Directory_Error =>
4076 -- This should never happen. But, if it does, display the
4077 -- content of the parent directory of the obj dir.
4079 declare
4080 Parent : constant Dir_Name_Str :=
4081 Dir_Name
4082 (Get_Name_String
4083 (Projects.Table (Main_Project).Object_Directory));
4084 Dir : Dir_Type;
4085 Str : String (1 .. 200);
4086 Last : Natural;
4088 begin
4089 Write_Str ("Contents of directory """);
4090 Write_Str (Parent);
4091 Write_Line (""":");
4093 Open (Dir, Parent);
4095 loop
4096 Read (Dir, Str, Last);
4097 exit when Last = 0;
4098 Write_Str (" ");
4099 Write_Line (Str (1 .. Last));
4100 end loop;
4102 Close (Dir);
4104 exception
4105 when X : others =>
4106 Write_Line ("(unexpected exception)");
4107 Write_Line (Exception_Information (X));
4109 if Is_Open (Dir) then
4110 Close (Dir);
4111 end if;
4112 end;
4114 Make_Failed ("unable to change working directory to """,
4115 Get_Name_String
4116 (Projects.Table (Main_Project).Object_Directory),
4117 """");
4118 end;
4120 -- Source file lookups should be cached for efficiency.
4121 -- Source files are not supposed to change.
4123 Osint.Source_File_Data (Cache => True);
4125 -- Find the file name of the (first) main unit
4127 declare
4128 Main_Source_File_Name : constant String :=
4129 Get_Name_String (Main_Source_File);
4130 Main_Unit_File_Name : constant String :=
4131 Prj.Env.File_Name_Of_Library_Unit_Body
4132 (Name => Main_Source_File_Name,
4133 Project => Main_Project,
4134 Main_Project_Only =>
4135 not Unique_Compile);
4137 The_Packages : constant Package_Id :=
4138 Projects.Table (Main_Project).Decl.Packages;
4140 Builder_Package : constant Prj.Package_Id :=
4141 Prj.Util.Value_Of
4142 (Name => Name_Builder,
4143 In_Packages => The_Packages);
4145 Binder_Package : constant Prj.Package_Id :=
4146 Prj.Util.Value_Of
4147 (Name => Name_Binder,
4148 In_Packages => The_Packages);
4150 Linker_Package : constant Prj.Package_Id :=
4151 Prj.Util.Value_Of
4152 (Name => Name_Linker,
4153 In_Packages => The_Packages);
4155 begin
4156 -- We fail if we cannot find the main source file
4158 if Main_Unit_File_Name = "" then
4159 Make_Failed ('"' & Main_Source_File_Name,
4160 """ is not a unit of project ",
4161 Project_File_Name.all & ".");
4162 else
4163 -- Remove any directory information from the main
4164 -- source file name.
4166 declare
4167 Pos : Natural := Main_Unit_File_Name'Last;
4169 begin
4170 loop
4171 exit when Pos < Main_Unit_File_Name'First or else
4172 Main_Unit_File_Name (Pos) = Directory_Separator;
4173 Pos := Pos - 1;
4174 end loop;
4176 Name_Len := Main_Unit_File_Name'Last - Pos;
4178 Name_Buffer (1 .. Name_Len) :=
4179 Main_Unit_File_Name
4180 (Pos + 1 .. Main_Unit_File_Name'Last);
4182 Main_Source_File := Name_Find;
4184 -- We only output the main source file if there is only one
4186 if Verbose_Mode and then Osint.Number_Of_Files = 1 then
4187 Write_Str ("Main source file: """);
4188 Write_Str (Main_Unit_File_Name
4189 (Pos + 1 .. Main_Unit_File_Name'Last));
4190 Write_Line (""".");
4191 end if;
4192 end;
4193 end if;
4195 -- If there is a package Builder in the main project file, add
4196 -- the switches from it.
4198 if Builder_Package /= No_Package then
4200 -- If there is only one main, we attempt to get the gnatmake
4201 -- switches for this main (if any). If there are no specific
4202 -- switch for this particular main, get the general gnatmake
4203 -- switches (if any).
4205 if Osint.Number_Of_Files = 1 then
4206 if Verbose_Mode then
4207 Write_Str ("Adding gnatmake switches for """);
4208 Write_Str (Main_Unit_File_Name);
4209 Write_Line (""".");
4210 end if;
4212 Add_Switches
4213 (File_Name => Main_Unit_File_Name,
4214 Index => Main_Index,
4215 The_Package => Builder_Package,
4216 Program => None);
4218 else
4219 -- If there are several mains, we always get the general
4220 -- gnatmake switches (if any).
4222 -- Warn the user, if necessary, so that he is not surprized
4223 -- that specific switches are not taken into account.
4225 declare
4226 Defaults : constant Variable_Value :=
4227 Prj.Util.Value_Of
4228 (Name => Name_Ada,
4229 Index => 0,
4230 Attribute_Or_Array_Name => Name_Default_Switches,
4231 In_Package => Builder_Package);
4233 Switches : constant Array_Element_Id :=
4234 Prj.Util.Value_Of
4235 (Name => Name_Switches,
4236 In_Arrays =>
4237 Packages.Table (Builder_Package).Decl.Arrays);
4239 begin
4240 if Defaults /= Nil_Variable_Value then
4241 if (not Quiet_Output)
4242 and then Switches /= No_Array_Element
4243 then
4244 Write_Line
4245 ("Warning: using Builder'Default_Switches" &
4246 "(""Ada""), as there are several mains");
4247 end if;
4249 -- As there is never a source with name " ", we are
4250 -- guaranteed to always get the general switches.
4252 Add_Switches
4253 (File_Name => " ",
4254 Index => 0,
4255 The_Package => Builder_Package,
4256 Program => None);
4258 elsif (not Quiet_Output)
4259 and then Switches /= No_Array_Element
4260 then
4261 Write_Line
4262 ("Warning: using no switches from package Builder," &
4263 " as there are several mains");
4264 end if;
4265 end;
4266 end if;
4267 end if;
4269 Osint.Add_Default_Search_Dirs;
4271 -- Record the current last switch index for table Binder_Switches
4272 -- and Linker_Switches, so that these tables may be reset before
4273 -- for each main, before adding swiches from the project file
4274 -- and from the command line.
4276 Last_Binder_Switch := Binder_Switches.Last;
4277 Last_Linker_Switch := Linker_Switches.Last;
4279 Check_Steps;
4281 -- Add binder switches from the project file for the first main
4283 if Do_Bind_Step and Binder_Package /= No_Package then
4284 if Verbose_Mode then
4285 Write_Str ("Adding binder switches for """);
4286 Write_Str (Main_Unit_File_Name);
4287 Write_Line (""".");
4288 end if;
4290 Add_Switches
4291 (File_Name => Main_Unit_File_Name,
4292 Index => Main_Index,
4293 The_Package => Binder_Package,
4294 Program => Binder);
4295 end if;
4297 -- Add linker switches from the project file for the first main
4299 if Do_Link_Step and Linker_Package /= No_Package then
4300 if Verbose_Mode then
4301 Write_Str ("Adding linker switches for""");
4302 Write_Str (Main_Unit_File_Name);
4303 Write_Line (""".");
4304 end if;
4306 Add_Switches
4307 (File_Name => Main_Unit_File_Name,
4308 Index => Main_Index,
4309 The_Package => Linker_Package,
4310 Program => Linker);
4311 end if;
4312 end;
4313 end if;
4315 -- Get the target parameters, which are only needed for a couple of
4316 -- cases in gnatmake. Protect against an exception, such as the case
4317 -- of system.ads missing from the library, and fail gracefully.
4319 begin
4320 Targparm.Get_Target_Parameters;
4322 exception
4323 when Unrecoverable_Error =>
4324 Make_Failed ("*** make failed.");
4325 end;
4327 Display_Commands (not Quiet_Output);
4329 Check_Steps;
4331 if Main_Project /= No_Project then
4333 -- For all library project, if the library file does not exist
4334 -- put all the project sources in the queue, and flag the project
4335 -- so that the library is generated.
4337 if MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None then
4338 for Proj in Projects.First .. Projects.Last loop
4339 if Projects.Table (Proj).Library then
4340 Projects.Table (Proj).Need_To_Build_Lib :=
4341 not MLib.Tgt.Library_Exists_For (Proj);
4343 if Projects.Table (Proj).Need_To_Build_Lib then
4344 -- If there is no object directory, then it will be
4345 -- impossible to build the library. So, we fail
4346 -- immediately.
4348 if Projects.Table (Proj).Object_Directory = No_Name then
4349 Make_Failed
4350 ("no object files to build library for project """,
4351 Get_Name_String (Projects.Table (Proj).Name),
4352 """");
4353 Projects.Table (Proj).Need_To_Build_Lib := False;
4355 else
4356 if Verbose_Mode then
4357 Write_Str
4358 ("Library file does not exist for project """);
4359 Write_Str
4360 (Get_Name_String (Projects.Table (Proj).Name));
4361 Write_Line ("""");
4362 end if;
4364 Insert_Project_Sources
4365 (The_Project => Proj,
4366 All_Projects => False,
4367 Into_Q => True);
4368 end if;
4369 end if;
4370 end if;
4371 end loop;
4372 end if;
4374 -- If a relative path output file has been specified, we add
4375 -- the exec directory.
4377 for J in reverse 1 .. Saved_Linker_Switches.Last - 1 loop
4378 if Saved_Linker_Switches.Table (J).all = Output_Flag.all then
4379 declare
4380 Exec_File_Name : constant String :=
4381 Saved_Linker_Switches.Table (J + 1).all;
4383 begin
4384 if not Is_Absolute_Path (Exec_File_Name) then
4385 for Index in Exec_File_Name'Range loop
4386 if Exec_File_Name (Index) = Directory_Separator then
4387 Make_Failed ("relative executable (""",
4388 Exec_File_Name,
4389 """) with directory part not " &
4390 "allowed when using project files");
4391 end if;
4392 end loop;
4394 Get_Name_String (Projects.Table
4395 (Main_Project).Exec_Directory);
4397 if Name_Buffer (Name_Len) /= Directory_Separator then
4398 Name_Len := Name_Len + 1;
4399 Name_Buffer (Name_Len) := Directory_Separator;
4400 end if;
4402 Name_Buffer (Name_Len + 1 ..
4403 Name_Len + Exec_File_Name'Length) :=
4404 Exec_File_Name;
4405 Name_Len := Name_Len + Exec_File_Name'Length;
4406 Saved_Linker_Switches.Table (J + 1) :=
4407 new String'(Name_Buffer (1 .. Name_Len));
4408 end if;
4409 end;
4411 exit;
4412 end if;
4413 end loop;
4415 -- If we are using a project file, for relative paths we add the
4416 -- current working directory for any relative path on the command
4417 -- line and the project directory, for any relative path in the
4418 -- project file.
4420 declare
4421 Dir_Path : constant String_Access :=
4422 new String'(Get_Name_String
4423 (Projects.Table (Main_Project).Directory));
4424 begin
4425 for J in 1 .. Binder_Switches.Last loop
4426 Test_If_Relative_Path
4427 (Binder_Switches.Table (J),
4428 Parent => Dir_Path, Including_L_Switch => False);
4429 end loop;
4431 for J in 1 .. Saved_Binder_Switches.Last loop
4432 Test_If_Relative_Path
4433 (Saved_Binder_Switches.Table (J),
4434 Parent => Current_Work_Dir, Including_L_Switch => False);
4435 end loop;
4437 for J in 1 .. Linker_Switches.Last loop
4438 Test_If_Relative_Path
4439 (Linker_Switches.Table (J), Parent => Dir_Path);
4440 end loop;
4442 for J in 1 .. Saved_Linker_Switches.Last loop
4443 Test_If_Relative_Path
4444 (Saved_Linker_Switches.Table (J), Parent => Current_Work_Dir);
4445 end loop;
4447 for J in 1 .. Gcc_Switches.Last loop
4448 Test_If_Relative_Path
4449 (Gcc_Switches.Table (J), Parent => Dir_Path);
4450 end loop;
4452 for J in 1 .. Saved_Gcc_Switches.Last loop
4453 Test_If_Relative_Path
4454 (Saved_Gcc_Switches.Table (J), Parent => Current_Work_Dir);
4455 end loop;
4456 end;
4457 end if;
4459 -- We now put in the Binder_Switches and Linker_Switches tables,
4460 -- the binder and linker switches of the command line that have been
4461 -- put in the Saved_ tables. If a project file was used, then the
4462 -- command line switches will follow the project file switches.
4464 for J in 1 .. Saved_Binder_Switches.Last loop
4465 Add_Switch
4466 (Saved_Binder_Switches.Table (J),
4467 Binder,
4468 And_Save => False);
4469 end loop;
4471 for J in 1 .. Saved_Linker_Switches.Last loop
4472 Add_Switch
4473 (Saved_Linker_Switches.Table (J),
4474 Linker,
4475 And_Save => False);
4476 end loop;
4478 -- If no project file is used, we just put the gcc switches
4479 -- from the command line in the Gcc_Switches table.
4481 if Main_Project = No_Project then
4482 for J in 1 .. Saved_Gcc_Switches.Last loop
4483 Add_Switch
4484 (Saved_Gcc_Switches.Table (J),
4485 Compiler,
4486 And_Save => False);
4487 end loop;
4489 else
4490 -- And we put the command line gcc switches in the variable
4491 -- The_Saved_Gcc_Switches. They are going to be used later
4492 -- in procedure Compile_Sources.
4494 The_Saved_Gcc_Switches :=
4495 new Argument_List (1 .. Saved_Gcc_Switches.Last + 1);
4497 for J in 1 .. Saved_Gcc_Switches.Last loop
4498 The_Saved_Gcc_Switches (J) := Saved_Gcc_Switches.Table (J);
4499 end loop;
4501 -- We never use gnat.adc when a project file is used
4503 The_Saved_Gcc_Switches (The_Saved_Gcc_Switches'Last) :=
4504 No_gnat_adc;
4506 end if;
4508 -- If there was a --GCC, --GNATBIND or --GNATLINK switch on
4509 -- the command line, then we have to use it, even if there was
4510 -- another switch in the project file.
4512 if Saved_Gcc /= null then
4513 Gcc := Saved_Gcc;
4514 end if;
4516 if Saved_Gnatbind /= null then
4517 Gnatbind := Saved_Gnatbind;
4518 end if;
4520 if Saved_Gnatlink /= null then
4521 Gnatlink := Saved_Gnatlink;
4522 end if;
4524 Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
4525 Gnatbind_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
4526 Gnatlink_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
4528 -- If we have specified -j switch both from the project file
4529 -- and on the command line, the one from the command line takes
4530 -- precedence.
4532 if Saved_Maximum_Processes = 0 then
4533 Saved_Maximum_Processes := Maximum_Processes;
4534 end if;
4536 -- Allocate as many temporary mapping file names as the maximum
4537 -- number of compilation processed, for each possible project.
4539 The_Mapping_File_Names :=
4540 new Temp_File_Names
4541 (No_Project .. Projects.Last, 1 .. Saved_Maximum_Processes);
4542 Last_Mapping_File_Names :=
4543 new Indices'(No_Project .. Projects.Last => 0);
4545 The_Free_Mapping_File_Indices :=
4546 new Free_File_Indices
4547 (No_Project .. Projects.Last, 1 .. Saved_Maximum_Processes);
4548 Last_Free_Indices :=
4549 new Indices'(No_Project .. Projects.Last => 0);
4551 Bad_Compilation.Init;
4553 Current_Main_Index := Main_Index;
4555 -- Here is where the make process is started
4557 -- We do the same process for each main
4559 Multiple_Main_Loop : for N_File in 1 .. Osint.Number_Of_Files loop
4561 -- First, find the executable name and path
4563 Executable := No_File;
4564 Executable_Obsolete := False;
4565 Non_Std_Executable := False;
4567 -- Look inside the linker switches to see if the name
4568 -- of the final executable program was specified.
4571 J in reverse Linker_Switches.First .. Linker_Switches.Last
4572 loop
4573 if Linker_Switches.Table (J).all = Output_Flag.all then
4574 pragma Assert (J < Linker_Switches.Last);
4576 -- We cannot specify a single executable for several
4577 -- main subprograms!
4579 if Osint.Number_Of_Files > 1 then
4580 Fail
4581 ("cannot specify a single executable " &
4582 "for several mains");
4583 end if;
4585 Name_Len := Linker_Switches.Table (J + 1)'Length;
4586 Name_Buffer (1 .. Name_Len) :=
4587 Linker_Switches.Table (J + 1).all;
4588 Executable := Name_Enter;
4590 Verbose_Msg (Executable, "final executable");
4591 end if;
4592 end loop;
4594 -- If the name of the final executable program was not
4595 -- specified then construct it from the main input file.
4597 if Executable = No_File then
4598 if Main_Project = No_Project then
4599 Executable :=
4600 Executable_Name (Strip_Suffix (Main_Source_File));
4602 else
4603 -- If we are using a project file, we attempt to
4604 -- remove the body (or spec) termination of the main
4605 -- subprogram. We find it the the naming scheme of the
4606 -- project file. This will avoid to generate an
4607 -- executable "main.2" for a main subprogram
4608 -- "main.2.ada", when the body termination is ".2.ada".
4610 Executable := Prj.Util.Executable_Of
4611 (Main_Project, Main_Source_File, Main_Index);
4612 end if;
4613 end if;
4615 if Main_Project /= No_Project then
4616 declare
4617 Exec_File_Name : constant String :=
4618 Get_Name_String (Executable);
4620 begin
4621 if not Is_Absolute_Path (Exec_File_Name) then
4622 for Index in Exec_File_Name'Range loop
4623 if Exec_File_Name (Index) = Directory_Separator then
4624 Make_Failed ("relative executable (""",
4625 Exec_File_Name,
4626 """) with directory part not " &
4627 "allowed when using project files");
4628 end if;
4629 end loop;
4631 Get_Name_String (Projects.Table
4632 (Main_Project).Exec_Directory);
4635 Name_Buffer (Name_Len) /= Directory_Separator
4636 then
4637 Name_Len := Name_Len + 1;
4638 Name_Buffer (Name_Len) := Directory_Separator;
4639 end if;
4641 Name_Buffer (Name_Len + 1 ..
4642 Name_Len + Exec_File_Name'Length) :=
4643 Exec_File_Name;
4644 Name_Len := Name_Len + Exec_File_Name'Length;
4645 Executable := Name_Find;
4646 Non_Std_Executable := True;
4647 end if;
4648 end;
4650 end if;
4652 if Do_Compile_Step then
4653 Recursive_Compilation_Step : declare
4654 Args : Argument_List (1 .. Gcc_Switches.Last);
4656 First_Compiled_File : Name_Id;
4657 Youngest_Obj_File : Name_Id;
4658 Youngest_Obj_Stamp : Time_Stamp_Type;
4660 Executable_Stamp : Time_Stamp_Type;
4661 -- Executable is the final executable program.
4663 Library_Rebuilt : Boolean := False;
4665 begin
4666 for J in 1 .. Gcc_Switches.Last loop
4667 Args (J) := Gcc_Switches.Table (J);
4668 end loop;
4670 -- Now we invoke Compile_Sources for the current main
4672 Compile_Sources
4673 (Main_Source => Main_Source_File,
4674 Args => Args,
4675 First_Compiled_File => First_Compiled_File,
4676 Most_Recent_Obj_File => Youngest_Obj_File,
4677 Most_Recent_Obj_Stamp => Youngest_Obj_Stamp,
4678 Main_Unit => Is_Main_Unit,
4679 Main_Index => Current_Main_Index,
4680 Compilation_Failures => Compilation_Failures,
4681 Check_Readonly_Files => Check_Readonly_Files,
4682 Do_Not_Execute => Do_Not_Execute,
4683 Force_Compilations => Force_Compilations,
4684 In_Place_Mode => In_Place_Mode,
4685 Keep_Going => Keep_Going,
4686 Initialize_ALI_Data => True,
4687 Max_Process => Saved_Maximum_Processes);
4689 if Verbose_Mode then
4690 Write_Str ("End of compilation");
4691 Write_Eol;
4692 end if;
4694 -- Make sure the queue will be reinitialized for the next round
4696 First_Q_Initialization := True;
4698 Total_Compilation_Failures :=
4699 Total_Compilation_Failures + Compilation_Failures;
4701 if Total_Compilation_Failures /= 0 then
4702 if Keep_Going then
4703 goto Next_Main;
4705 else
4706 List_Bad_Compilations;
4707 raise Compilation_Failed;
4708 end if;
4709 end if;
4711 -- Regenerate libraries, if any, and if object files
4712 -- have been regenerated.
4714 if Main_Project /= No_Project
4715 and then MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None
4716 and then (Do_Bind_Step or Unique_Compile_All_Projects
4717 or not Compile_Only)
4718 and then (Do_Link_Step or N_File = Osint.Number_Of_Files)
4719 then
4720 Library_Projs.Init;
4722 declare
4723 Proj2 : Project_Id;
4724 Depth : Natural;
4725 Current : Natural;
4727 begin
4728 -- Put in Library_Projs table all library project
4729 -- file ids when the library need to be rebuilt.
4731 for Proj1 in Projects.First .. Projects.Last loop
4733 if Projects.Table (Proj1).Standalone_Library then
4734 There_Are_Stand_Alone_Libraries := True;
4735 end if;
4737 if Projects.Table (Proj1).Library
4738 and then not Projects.Table (Proj1).Need_To_Build_Lib
4739 then
4740 MLib.Prj.Check_Library (Proj1);
4741 end if;
4743 if Projects.Table (Proj1).Need_To_Build_Lib then
4744 Library_Projs.Increment_Last;
4745 Current := Library_Projs.Last;
4746 Depth := Projects.Table (Proj1).Depth;
4748 -- Put the projects in decreasing depth order,
4749 -- so that if libA depends on libB, libB is first
4750 -- in order.
4752 while Current > 1 loop
4753 Proj2 := Library_Projs.Table (Current - 1);
4754 exit when Projects.Table (Proj2).Depth >= Depth;
4755 Library_Projs.Table (Current) := Proj2;
4756 Current := Current - 1;
4757 end loop;
4759 Library_Projs.Table (Current) := Proj1;
4760 Projects.Table (Proj1).Need_To_Build_Lib := False;
4761 end if;
4762 end loop;
4763 end;
4765 -- Build the libraries, if any need to be built
4767 for J in 1 .. Library_Projs.Last loop
4768 Library_Rebuilt := True;
4769 MLib.Prj.Build_Library
4770 (For_Project => Library_Projs.Table (J),
4771 Gnatbind => Gnatbind.all,
4772 Gnatbind_Path => Gnatbind_Path,
4773 Gcc => Gcc.all,
4774 Gcc_Path => Gcc_Path);
4775 end loop;
4776 end if;
4778 if List_Dependencies then
4779 if First_Compiled_File /= No_File then
4780 Inform
4781 (First_Compiled_File,
4782 "must be recompiled. Can't generate dependence list.");
4783 else
4784 List_Depend;
4785 end if;
4787 elsif First_Compiled_File = No_File
4788 and then not Do_Bind_Step
4789 and then not Quiet_Output
4790 and then not Library_Rebuilt
4791 and then Osint.Number_Of_Files = 1
4792 then
4793 Inform (Msg => "objects up to date.");
4795 elsif Do_Not_Execute
4796 and then First_Compiled_File /= No_File
4797 then
4798 Write_Name (First_Compiled_File);
4799 Write_Eol;
4800 end if;
4802 -- Stop after compile step if any of:
4804 -- 1) -n (Do_Not_Execute) specified
4806 -- 2) -M (List_Dependencies) specified (also sets
4807 -- Do_Not_Execute above, so this is probably superfluous).
4809 -- 3) -c (Compile_Only) specified, but not -b (Bind_Only)
4811 -- 4) Made unit cannot be a main unit
4813 if (Do_Not_Execute
4814 or List_Dependencies
4815 or not Do_Bind_Step
4816 or not Is_Main_Unit)
4817 and then not No_Main_Subprogram
4818 and then not Build_Bind_And_Link_Full_Project
4819 then
4820 if Osint.Number_Of_Files = 1 then
4821 exit Multiple_Main_Loop;
4823 else
4824 goto Next_Main;
4825 end if;
4826 end if;
4828 -- If the objects were up-to-date check if the executable file
4829 -- is also up-to-date. For now always bind and link on the JVM
4830 -- since there is currently no simple way to check the
4831 -- up-to-date status of objects
4833 if not Hostparm.Java_VM
4834 and then First_Compiled_File = No_File
4835 then
4836 Executable_Stamp := File_Stamp (Executable);
4838 if not Executable_Obsolete then
4839 Executable_Obsolete :=
4840 Youngest_Obj_Stamp > Executable_Stamp;
4841 end if;
4843 if not Executable_Obsolete then
4844 for Index in reverse 1 .. Dependencies.Last loop
4845 if Is_In_Obsoleted
4846 (Dependencies.Table (Index).Depends_On)
4847 then
4848 Enter_Into_Obsoleted
4849 (Dependencies.Table (Index).This);
4850 end if;
4851 end loop;
4853 Executable_Obsolete := Is_In_Obsoleted (Main_Source_File);
4854 Dependencies.Init;
4855 end if;
4857 if not Executable_Obsolete then
4859 -- If no Ada object files obsolete the executable, check
4860 -- for younger or missing linker files.
4862 Check_Linker_Options
4863 (Executable_Stamp,
4864 Youngest_Obj_File,
4865 Youngest_Obj_Stamp);
4867 Executable_Obsolete := Youngest_Obj_File /= No_File;
4868 end if;
4870 -- Return if the executable is up to date
4871 -- and otherwise motivate the relink/rebind.
4873 if not Executable_Obsolete then
4874 if not Quiet_Output then
4875 Inform (Executable, "up to date.");
4876 end if;
4878 if Osint.Number_Of_Files = 1 then
4879 exit Multiple_Main_Loop;
4881 else
4882 goto Next_Main;
4883 end if;
4884 end if;
4886 if Executable_Stamp (1) = ' ' then
4887 Verbose_Msg (Executable, "missing.", Prefix => " ");
4889 elsif Youngest_Obj_Stamp (1) = ' ' then
4890 Verbose_Msg
4891 (Youngest_Obj_File,
4892 "missing.",
4893 Prefix => " ");
4895 elsif Youngest_Obj_Stamp > Executable_Stamp then
4896 Verbose_Msg
4897 (Youngest_Obj_File,
4898 "(" & String (Youngest_Obj_Stamp) & ") newer than",
4899 Executable,
4900 "(" & String (Executable_Stamp) & ")");
4902 else
4903 Verbose_Msg
4904 (Executable, "needs to be rebuild.",
4905 Prefix => " ");
4907 end if;
4908 end if;
4909 end Recursive_Compilation_Step;
4910 end if;
4912 -- For binding and linking, we need to be in the object directory of
4913 -- the main project.
4915 if Main_Project /= No_Project then
4916 Change_To_Object_Directory (Main_Project);
4917 end if;
4919 -- If we are here, it means that we need to rebuilt the current
4920 -- main. So we set Executable_Obsolete to True to make sure that
4921 -- the subsequent mains will be rebuilt.
4923 Main_ALI_In_Place_Mode_Step : declare
4924 ALI_File : File_Name_Type;
4925 Src_File : File_Name_Type;
4927 begin
4928 Src_File := Strip_Directory (Main_Source_File);
4929 ALI_File := Lib_File_Name (Src_File, Current_Main_Index);
4930 Main_ALI_File := Full_Lib_File_Name (ALI_File);
4932 -- When In_Place_Mode, the library file can be located in the
4933 -- Main_Source_File directory which may not be present in the
4934 -- library path. In this case, use the corresponding library file
4935 -- name.
4937 if Main_ALI_File = No_File and then In_Place_Mode then
4938 Get_Name_String (Get_Directory (Full_Source_Name (Src_File)));
4939 Get_Name_String_And_Append (ALI_File);
4940 Main_ALI_File := Name_Find;
4941 Main_ALI_File := Full_Lib_File_Name (Main_ALI_File);
4942 end if;
4944 if Main_ALI_File = No_File then
4945 Make_Failed ("could not find the main ALI file");
4946 end if;
4947 end Main_ALI_In_Place_Mode_Step;
4949 if Do_Bind_Step then
4950 Bind_Step : declare
4951 Args : Argument_List
4952 (Binder_Switches.First .. Binder_Switches.Last + 2);
4953 -- The arguments for the invocation of gnatbind
4955 Last_Arg : Natural := Binder_Switches.Last;
4956 -- Index of the last argument in Args
4958 Shared_Libs : Boolean := False;
4959 -- Set to True when there are shared library project files or
4960 -- when gnatbind is invoked with -shared.
4962 begin
4963 -- Check if there are shared libraries, so that gnatbind is
4964 -- called with -shared. Check also if gnatbind is called with
4965 -- -shared, so that gnatlink is called with -shared-libgcc
4966 -- for GCC version 3 and above, ensuring that the shared
4967 -- version of libgcc will be used.
4969 if Main_Project /= No_Project
4970 and then MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None
4971 then
4972 for Proj in Projects.First .. Projects.Last loop
4973 if Projects.Table (Proj).Library and then
4974 Projects.Table (Proj).Library_Kind /= Static
4975 then
4976 Shared_Libs := True;
4977 Bind_Shared := Shared_Switch'Access;
4978 exit;
4979 end if;
4980 end loop;
4981 end if;
4983 -- Check now for switch -shared
4985 if not Shared_Libs then
4986 for J in Binder_Switches.First .. Last_Arg loop
4987 if Binder_Switches.Table (J).all = "-shared" then
4988 Shared_Libs := True;
4989 exit;
4990 end if;
4991 end loop;
4992 end if;
4994 -- If there are shared libraries, invoke gnatlink with
4995 -- -shared-libgcc if GCC version is 3 or more.
4997 if Shared_Libs and then GCC_Version >= 3 then
4998 Link_With_Shared_Libgcc := Shared_Libgcc_Switch'Access;
4999 end if;
5001 -- Get all the binder switches
5003 for J in Binder_Switches.First .. Last_Arg loop
5004 Args (J) := Binder_Switches.Table (J);
5005 end loop;
5007 if There_Are_Stand_Alone_Libraries then
5008 Last_Arg := Last_Arg + 1;
5009 Args (Last_Arg) := Force_Elab_Flags_String'Access;
5010 end if;
5012 if Main_Project /= No_Project then
5014 -- Put all the source directories in ADA_INCLUDE_PATH,
5015 -- and all the object directories in ADA_OBJECTS_PATH
5017 Prj.Env.Set_Ada_Paths (Main_Project, False);
5019 -- If switch -C was specified, create a binder mapping file
5021 if Create_Mapping_File then
5022 Create_Binder_Mapping_File (Args, Last_Arg);
5023 end if;
5025 end if;
5027 begin
5028 Bind (Main_ALI_File,
5029 Bind_Shared.all & Args (Args'First .. Last_Arg));
5031 exception
5032 when others =>
5034 -- If -dn was not specified, delete the temporary mapping
5035 -- file, if one was created.
5037 if not Debug.Debug_Flag_N
5038 and then Mapping_Path /= No_Name
5039 then
5040 Delete_File (Get_Name_String (Mapping_Path), Discard);
5041 end if;
5043 -- And reraise the exception
5045 raise;
5046 end;
5048 -- If -dn was not specified, delete the temporary mapping file,
5049 -- if one was created.
5051 if not Debug.Debug_Flag_N and then Mapping_Path /= No_Name then
5052 Delete_File (Get_Name_String (Mapping_Path), Discard);
5053 end if;
5054 end Bind_Step;
5055 end if;
5057 if Do_Link_Step then
5058 Link_Step : declare
5059 There_Are_Libraries : Boolean := False;
5060 Linker_Switches_Last : constant Integer := Linker_Switches.Last;
5061 Path_Option : constant String_Access :=
5062 MLib.Linker_Library_Path_Option;
5063 Current : Natural;
5064 Proj2 : Project_Id;
5065 Depth : Natural;
5067 begin
5068 if not Run_Path_Option then
5069 Linker_Switches.Increment_Last;
5070 Linker_Switches.Table (Linker_Switches.Last) :=
5071 new String'("-R");
5072 end if;
5074 if Main_Project /= No_Project then
5075 Library_Paths.Set_Last (0);
5076 Library_Projs.Init;
5078 if MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None then
5079 -- Check for library projects
5081 for Proj1 in 1 .. Projects.Last loop
5082 if Proj1 /= Main_Project
5083 and then Projects.Table (Proj1).Library
5084 then
5085 -- Add this project to table Library_Projs
5087 There_Are_Libraries := True;
5088 Depth := Projects.Table (Proj1).Depth;
5089 Library_Projs.Increment_Last;
5090 Current := Library_Projs.Last;
5092 -- Any project with a greater depth should be
5093 -- after this project in the list.
5095 while Current > 1 loop
5096 Proj2 := Library_Projs.Table (Current - 1);
5097 exit when Projects.Table (Proj2).Depth <= Depth;
5098 Library_Projs.Table (Current) := Proj2;
5099 Current := Current - 1;
5100 end loop;
5102 Library_Projs.Table (Current) := Proj1;
5104 -- If it is not a static library and path option
5105 -- is set, add it to the Library_Paths table.
5107 if Projects.Table (Proj1).Library_Kind /= Static
5108 and then Path_Option /= null
5109 then
5110 Library_Paths.Increment_Last;
5111 Library_Paths.Table (Library_Paths.Last) :=
5112 new String'
5113 (Get_Name_String
5114 (Projects.Table (Proj1).Library_Dir));
5115 end if;
5116 end if;
5117 end loop;
5119 for Index in 1 .. Library_Projs.Last loop
5120 -- Add the -L switch
5122 Linker_Switches.Increment_Last;
5123 Linker_Switches.Table (Linker_Switches.Last) :=
5124 new String'("-L" &
5125 Get_Name_String
5126 (Projects.Table
5127 (Library_Projs.Table (Index)).
5128 Library_Dir));
5130 -- Add the -l switch
5132 Linker_Switches.Increment_Last;
5133 Linker_Switches.Table (Linker_Switches.Last) :=
5134 new String'("-l" &
5135 Get_Name_String
5136 (Projects.Table
5137 (Library_Projs.Table (Index)).
5138 Library_Name));
5139 end loop;
5140 end if;
5142 if There_Are_Libraries then
5144 -- If Path_Option is not null, create the switch
5145 -- ("-Wl,-rpath," or equivalent) with all the non static
5146 -- library dirs plus the standard GNAT library dir.
5147 -- We do that only if Run_Path_Option is True
5148 -- (not disabled by -R switch).
5150 if Run_Path_Option and Path_Option /= null then
5151 declare
5152 Option : String_Access;
5153 Length : Natural := Path_Option'Length;
5154 Current : Natural;
5156 begin
5157 for Index in
5158 Library_Paths.First .. Library_Paths.Last
5159 loop
5160 -- Add the length of the library dir plus one
5161 -- for the directory separator.
5163 Length :=
5164 Length +
5165 Library_Paths.Table (Index)'Length + 1;
5166 end loop;
5168 -- Finally, add the length of the standard GNAT
5169 -- library dir.
5171 Length := Length + MLib.Utl.Lib_Directory'Length;
5172 Option := new String (1 .. Length);
5173 Option (1 .. Path_Option'Length) := Path_Option.all;
5174 Current := Path_Option'Length;
5176 -- Put each library dir followed by a dir separator
5178 for Index in
5179 Library_Paths.First .. Library_Paths.Last
5180 loop
5181 Option
5182 (Current + 1 ..
5183 Current +
5184 Library_Paths.Table (Index)'Length) :=
5185 Library_Paths.Table (Index).all;
5186 Current :=
5187 Current +
5188 Library_Paths.Table (Index)'Length + 1;
5189 Option (Current) := Path_Separator;
5190 end loop;
5192 -- Finally put the standard GNAT library dir
5194 Option
5195 (Current + 1 ..
5196 Current + MLib.Utl.Lib_Directory'Length) :=
5197 MLib.Utl.Lib_Directory;
5199 -- And add the switch to the linker switches
5201 Linker_Switches.Increment_Last;
5202 Linker_Switches.Table (Linker_Switches.Last) :=
5203 Option;
5204 end;
5205 end if;
5207 end if;
5209 -- Put the object directories in ADA_OBJECTS_PATH
5211 Prj.Env.Set_Ada_Paths (Main_Project, False);
5213 -- Check for attributes Linker'Linker_Options in projects
5214 -- other than the main project
5216 declare
5217 Linker_Options : constant String_List :=
5218 Linker_Options_Switches (Main_Project);
5220 begin
5221 for Option in Linker_Options'Range loop
5222 Linker_Switches.Increment_Last;
5223 Linker_Switches.Table (Linker_Switches.Last) :=
5224 Linker_Options (Option);
5225 end loop;
5226 end;
5227 end if;
5229 declare
5230 Args : Argument_List
5231 (Linker_Switches.First .. Linker_Switches.Last + 2);
5233 Last_Arg : Integer := Linker_Switches.First - 1;
5234 Skip : Boolean := False;
5236 begin
5237 -- Get all the linker switches
5239 for J in Linker_Switches.First .. Linker_Switches.Last loop
5240 if Skip then
5241 Skip := False;
5243 elsif Non_Std_Executable
5244 and then Linker_Switches.Table (J).all = "-o"
5245 then
5246 Skip := True;
5248 else
5249 Last_Arg := Last_Arg + 1;
5250 Args (Last_Arg) := Linker_Switches.Table (J);
5251 end if;
5252 end loop;
5254 -- If need be, add the -o switch
5256 if Non_Std_Executable then
5257 Last_Arg := Last_Arg + 1;
5258 Args (Last_Arg) := new String'("-o");
5259 Last_Arg := Last_Arg + 1;
5260 Args (Last_Arg) :=
5261 new String'(Get_Name_String (Executable));
5262 end if;
5264 -- And invoke the linker
5266 begin
5267 Link (Main_ALI_File,
5268 Link_With_Shared_Libgcc.all &
5269 Args (Args'First .. Last_Arg));
5270 Successful_Links.Increment_Last;
5271 Successful_Links.Table (Successful_Links.Last) :=
5272 Main_ALI_File;
5274 exception
5275 when Link_Failed =>
5276 if Osint.Number_Of_Files = 1 or not Keep_Going then
5277 raise;
5279 else
5280 Write_Line ("*** link failed");
5281 Failed_Links.Increment_Last;
5282 Failed_Links.Table (Failed_Links.Last) :=
5283 Main_ALI_File;
5284 end if;
5285 end;
5286 end;
5288 Linker_Switches.Set_Last (Linker_Switches_Last);
5289 end Link_Step;
5290 end if;
5292 -- We go to here when we skip the bind and link steps.
5294 <<Next_Main>>
5296 -- We go to the next main, if we did not process the last one
5298 if N_File < Osint.Number_Of_Files then
5299 Main_Source_File := Next_Main_Source;
5301 if Current_File_Index /= No_Index then
5302 Main_Index := Current_File_Index;
5303 end if;
5305 if Main_Project /= No_Project then
5307 -- Find the file name of the main unit
5309 declare
5310 Main_Source_File_Name : constant String :=
5311 Get_Name_String (Main_Source_File);
5313 Main_Unit_File_Name : constant String :=
5314 Prj.Env.
5315 File_Name_Of_Library_Unit_Body
5316 (Name => Main_Source_File_Name,
5317 Project => Main_Project,
5318 Main_Project_Only =>
5319 not Unique_Compile);
5321 The_Packages : constant Package_Id :=
5322 Projects.Table (Main_Project).Decl.Packages;
5324 Binder_Package : constant Prj.Package_Id :=
5325 Prj.Util.Value_Of
5326 (Name => Name_Binder,
5327 In_Packages => The_Packages);
5329 Linker_Package : constant Prj.Package_Id :=
5330 Prj.Util.Value_Of
5331 (Name => Name_Linker,
5332 In_Packages => The_Packages);
5334 begin
5335 -- We fail if we cannot find the main source file
5336 -- as an immediate source of the main project file.
5338 if Main_Unit_File_Name = "" then
5339 Make_Failed ('"' & Main_Source_File_Name,
5340 """ is not a unit of project ",
5341 Project_File_Name.all & ".");
5343 else
5344 -- Remove any directory information from the main
5345 -- source file name.
5347 declare
5348 Pos : Natural := Main_Unit_File_Name'Last;
5350 begin
5351 loop
5352 exit when Pos < Main_Unit_File_Name'First
5353 or else
5354 Main_Unit_File_Name (Pos) = Directory_Separator;
5355 Pos := Pos - 1;
5356 end loop;
5358 Name_Len := Main_Unit_File_Name'Last - Pos;
5360 Name_Buffer (1 .. Name_Len) :=
5361 Main_Unit_File_Name
5362 (Pos + 1 .. Main_Unit_File_Name'Last);
5364 Main_Source_File := Name_Find;
5365 end;
5366 end if;
5368 -- We now deal with the binder and linker switches.
5369 -- If no project file is used, there is nothing to do
5370 -- because the binder and linker switches are the same
5371 -- for all mains.
5373 -- Reset the tables Binder_Switches and Linker_Switches
5375 Binder_Switches.Set_Last (Last_Binder_Switch);
5376 Linker_Switches.Set_Last (Last_Linker_Switch);
5378 -- Add binder switches from the project file for this main,
5379 -- if any.
5381 if Do_Bind_Step and Binder_Package /= No_Package then
5382 if Verbose_Mode then
5383 Write_Str ("Adding binder switches for """);
5384 Write_Str (Main_Unit_File_Name);
5385 Write_Line (""".");
5386 end if;
5388 Add_Switches
5389 (File_Name => Main_Unit_File_Name,
5390 Index => Main_Index,
5391 The_Package => Binder_Package,
5392 Program => Binder);
5393 end if;
5395 -- Add linker switches from the project file for this main,
5396 -- if any.
5398 if Do_Link_Step and Linker_Package /= No_Package then
5399 if Verbose_Mode then
5400 Write_Str ("Adding linker switches for""");
5401 Write_Str (Main_Unit_File_Name);
5402 Write_Line (""".");
5403 end if;
5405 Add_Switches
5406 (File_Name => Main_Unit_File_Name,
5407 Index => Main_Index,
5408 The_Package => Linker_Package,
5409 Program => Linker);
5410 end if;
5412 -- As we are using a project file, for relative paths we add
5413 -- the current working directory for any relative path on
5414 -- the command line and the project directory, for any
5415 -- relative path in the project file.
5417 declare
5418 Dir_Path : constant String_Access :=
5419 new String'(Get_Name_String
5420 (Projects.Table (Main_Project).Directory));
5421 begin
5423 J in Last_Binder_Switch + 1 .. Binder_Switches.Last
5424 loop
5425 Test_If_Relative_Path
5426 (Binder_Switches.Table (J),
5427 Parent => Dir_Path, Including_L_Switch => False);
5428 end loop;
5431 J in Last_Linker_Switch + 1 .. Linker_Switches.Last
5432 loop
5433 Test_If_Relative_Path
5434 (Linker_Switches.Table (J), Parent => Dir_Path);
5435 end loop;
5436 end;
5438 -- We now put in the Binder_Switches and Linker_Switches
5439 -- tables, the binder and linker switches of the command
5440 -- line that have been put in the Saved_ tables.
5441 -- These switches will follow the project file switches.
5443 for J in 1 .. Saved_Binder_Switches.Last loop
5444 Add_Switch
5445 (Saved_Binder_Switches.Table (J),
5446 Binder,
5447 And_Save => False);
5448 end loop;
5450 for J in 1 .. Saved_Linker_Switches.Last loop
5451 Add_Switch
5452 (Saved_Linker_Switches.Table (J),
5453 Linker,
5454 And_Save => False);
5455 end loop;
5456 end;
5457 end if;
5458 end if;
5460 -- Remove all marks to be sure to check sources for all executables,
5461 -- as the switches may be different and -s may be in use.
5463 Delete_All_Marks;
5464 end loop Multiple_Main_Loop;
5466 if Failed_Links.Last > 0 then
5467 for Index in 1 .. Successful_Links.Last loop
5468 Write_Str ("Linking of """);
5469 Write_Str (Get_Name_String (Successful_Links.Table (Index)));
5470 Write_Line (""" succeeded.");
5471 end loop;
5473 for Index in 1 .. Failed_Links.Last loop
5474 Write_Str ("Linking of """);
5475 Write_Str (Get_Name_String (Failed_Links.Table (Index)));
5476 Write_Line (""" failed.");
5477 end loop;
5479 if Total_Compilation_Failures = 0 then
5480 raise Compilation_Failed;
5481 end if;
5482 end if;
5484 if Total_Compilation_Failures /= 0 then
5485 List_Bad_Compilations;
5486 raise Compilation_Failed;
5487 end if;
5489 -- Delete the temporary mapping file that was created if we are
5490 -- using project files.
5492 if not Debug.Debug_Flag_N then
5493 Delete_Mapping_Files;
5494 Prj.Env.Delete_All_Path_Files;
5495 end if;
5497 Exit_Program (E_Success);
5499 exception
5500 when Bind_Failed =>
5501 Make_Failed ("*** bind failed.");
5503 when Compilation_Failed =>
5504 if not Debug.Debug_Flag_N then
5505 Delete_Mapping_Files;
5506 Prj.Env.Delete_All_Path_Files;
5507 end if;
5509 Exit_Program (E_Fatal);
5511 when Link_Failed =>
5512 Make_Failed ("*** link failed.");
5514 when X : others =>
5515 Write_Line (Exception_Information (X));
5516 Make_Failed ("INTERNAL ERROR. Please report.");
5517 end Gnatmake;
5519 ----------
5520 -- Hash --
5521 ----------
5523 function Hash (F : Name_Id) return Header_Num is
5524 begin
5525 return Header_Num (1 + F mod Max_Header);
5526 end Hash;
5528 --------------------
5529 -- In_Ada_Lib_Dir --
5530 --------------------
5532 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean is
5533 D : constant Name_Id := Get_Directory (File);
5534 B : constant Byte := Get_Name_Table_Byte (D);
5535 begin
5536 return (B and Ada_Lib_Dir) /= 0;
5537 end In_Ada_Lib_Dir;
5539 ------------
5540 -- Inform --
5541 ------------
5543 procedure Inform (N : Name_Id := No_Name; Msg : String) is
5544 begin
5545 Osint.Write_Program_Name;
5547 Write_Str (": ");
5549 if N /= No_Name then
5550 Write_Str ("""");
5551 Write_Name (N);
5552 Write_Str (""" ");
5553 end if;
5555 Write_Str (Msg);
5556 Write_Eol;
5557 end Inform;
5559 -----------------------
5560 -- Init_Mapping_File --
5561 -----------------------
5563 procedure Init_Mapping_File
5564 (Project : Project_Id;
5565 File_Index : in out Natural)
5567 FD : File_Descriptor;
5569 Status : Boolean;
5570 -- For call to Close
5572 begin
5573 -- Increase the index of the last mapping file for this project
5575 Last_Mapping_File_Names (Project) :=
5576 Last_Mapping_File_Names (Project) + 1;
5578 -- If there is a project file, call Create_Mapping_File with
5579 -- the project id.
5581 if Project /= No_Project then
5582 Prj.Env.Create_Mapping_File
5583 (Project,
5584 The_Mapping_File_Names
5585 (Project, Last_Mapping_File_Names (Project)));
5587 -- Otherwise, just create an empty file
5589 else
5590 Tempdir.Create_Temp_File
5591 (FD,
5592 The_Mapping_File_Names
5593 (No_Project, Last_Mapping_File_Names (No_Project)));
5594 if FD = Invalid_FD then
5595 Make_Failed ("disk full");
5596 end if;
5598 Close (FD, Status);
5600 if not Status then
5601 Make_Failed ("disk full");
5602 end if;
5603 end if;
5605 -- And return the index of the newly created file
5607 File_Index := Last_Mapping_File_Names (Project);
5608 end Init_Mapping_File;
5610 ------------
5611 -- Init_Q --
5612 ------------
5614 procedure Init_Q is
5615 begin
5616 First_Q_Initialization := False;
5617 Q_Front := Q.First;
5618 Q.Set_Last (Q.First);
5619 end Init_Q;
5621 ----------------
5622 -- Initialize --
5623 ----------------
5625 procedure Initialize is
5626 begin
5627 -- Override default initialization of Check_Object_Consistency
5628 -- since this is normally False for GNATBIND, but is True for
5629 -- GNATMAKE since we do not need to check source consistency
5630 -- again once GNATMAKE has looked at the sources to check.
5632 Check_Object_Consistency := True;
5634 -- Package initializations. The order of calls is important here.
5636 Output.Set_Standard_Error;
5638 Gcc_Switches.Init;
5639 Binder_Switches.Init;
5640 Linker_Switches.Init;
5642 Csets.Initialize;
5643 Namet.Initialize;
5645 Snames.Initialize;
5647 Prj.Initialize;
5649 Dependencies.Init;
5651 RTS_Specified := null;
5653 Mains.Delete;
5655 -- Add the directory where gnatmake is invoked in front of the
5656 -- path, if gnatmake is invoked with directory information.
5657 -- Only do this if the platform is not VMS, where the notion of path
5658 -- does not really exist.
5660 if not OpenVMS then
5661 declare
5662 Command : constant String := Command_Name;
5664 begin
5665 for Index in reverse Command'Range loop
5666 if Command (Index) = Directory_Separator then
5667 declare
5668 Absolute_Dir : constant String :=
5669 Normalize_Pathname
5670 (Command (Command'First .. Index));
5672 PATH : constant String :=
5673 Absolute_Dir &
5674 Path_Separator &
5675 Getenv ("PATH").all;
5677 begin
5678 Setenv ("PATH", PATH);
5679 end;
5681 exit;
5682 end if;
5683 end loop;
5684 end;
5685 end if;
5687 -- Scan the switches and arguments
5689 Scan_Args : for Next_Arg in 1 .. Argument_Count loop
5690 Scan_Make_Arg (Argument (Next_Arg), And_Save => True);
5691 end loop Scan_Args;
5693 if Usage_Requested then
5694 Usage;
5695 end if;
5697 -- Test for trailing -P switch
5699 if Project_File_Name_Present and then Project_File_Name = null then
5700 Make_Failed ("project file name missing after -P");
5702 -- Test for trailing -o switch
5704 elsif Output_File_Name_Present
5705 and then not Output_File_Name_Seen
5706 then
5707 Make_Failed ("output file name missing after -o");
5709 -- Test for trailing -D switch
5711 elsif Object_Directory_Present
5712 and then not Object_Directory_Seen then
5713 Make_Failed ("object directory missing after -D");
5714 end if;
5716 -- Test for simultaneity of -i and -D
5718 if Object_Directory_Path /= null and then In_Place_Mode then
5719 Make_Failed ("-i and -D cannot be used simutaneously");
5720 end if;
5722 -- Deal with -C= switch
5724 if Gnatmake_Mapping_File /= null then
5725 -- First, check compatibility with other switches
5727 if Project_File_Name /= null then
5728 Make_Failed ("-C= switch is not compatible with -P switch");
5730 elsif Saved_Maximum_Processes > 1 then
5731 Make_Failed ("-C= switch is not compatible with -jnnn switch");
5732 end if;
5734 Fmap.Initialize (Gnatmake_Mapping_File.all);
5735 Add_Switch
5736 ("-gnatem=" & Gnatmake_Mapping_File.all,
5737 Compiler,
5738 And_Save => True);
5739 end if;
5741 if Project_File_Name /= null then
5743 -- A project file was specified by a -P switch
5745 if Verbose_Mode then
5746 Write_Eol;
5747 Write_Str ("Parsing Project File """);
5748 Write_Str (Project_File_Name.all);
5749 Write_Str (""".");
5750 Write_Eol;
5751 end if;
5753 -- Avoid looking in the current directory for ALI files
5755 -- Look_In_Primary_Dir := False;
5757 -- Set the project parsing verbosity to whatever was specified
5758 -- by a possible -vP switch.
5760 Prj.Pars.Set_Verbosity (To => Current_Verbosity);
5762 -- Parse the project file.
5763 -- If there is an error, Main_Project will still be No_Project.
5765 Prj.Pars.Parse
5766 (Project => Main_Project,
5767 Project_File_Name => Project_File_Name.all,
5768 Packages_To_Check => Packages_To_Check_By_Gnatmake);
5770 if Main_Project = No_Project then
5771 Make_Failed ("""", Project_File_Name.all, """ processing failed");
5772 end if;
5774 if Verbose_Mode then
5775 Write_Eol;
5776 Write_Str ("Parsing of Project File """);
5777 Write_Str (Project_File_Name.all);
5778 Write_Str (""" is finished.");
5779 Write_Eol;
5780 end if;
5782 -- We add the source directories and the object directories
5783 -- to the search paths.
5785 Add_Source_Directories (Main_Project);
5786 Add_Object_Directories (Main_Project);
5788 -- Compute depth of each project
5790 for Proj in 1 .. Projects.Last loop
5791 Projects.Table (Proj).Seen := False;
5792 Projects.Table (Proj).Depth := 0;
5793 end loop;
5795 Recursive_Compute_Depth
5796 (Main_Project, Depth => 1);
5798 else
5800 Osint.Add_Default_Search_Dirs;
5802 -- Source file lookups should be cached for efficiency.
5803 -- Source files are not supposed to change. However, we do that now
5804 -- only if no project file is used; if a project file is used, we
5805 -- do it just after changing the directory to the object directory.
5807 Osint.Source_File_Data (Cache => True);
5809 -- Read gnat.adc file to initialize Fname.UF
5811 Fname.UF.Initialize;
5813 begin
5814 Fname.SF.Read_Source_File_Name_Pragmas;
5816 exception
5817 when Err : SFN_Scan.Syntax_Error_In_GNAT_ADC =>
5818 Make_Failed (Exception_Message (Err));
5819 end;
5820 end if;
5822 -- Make sure no project object directory is recorded
5824 Project_Object_Directory := No_Project;
5826 end Initialize;
5828 ----------------------------
5829 -- Insert_Project_Sources --
5830 ----------------------------
5832 procedure Insert_Project_Sources
5833 (The_Project : Project_Id;
5834 All_Projects : Boolean;
5835 Into_Q : Boolean)
5837 Put_In_Q : Boolean := Into_Q;
5838 Unit : Com.Unit_Data;
5839 Sfile : Name_Id;
5841 Extending : constant Boolean :=
5842 Projects.Table (The_Project).Extends /= No_Project;
5844 function Check_Project (P : Project_Id) return Boolean;
5845 -- Returns True if P is The_Project or a project extended by
5846 -- The_Project.
5848 -------------------
5849 -- Check_Project --
5850 -------------------
5852 function Check_Project (P : Project_Id) return Boolean is
5853 begin
5854 if All_Projects or P = The_Project then
5855 return True;
5856 elsif Extending then
5857 declare
5858 Data : Project_Data := Projects.Table (The_Project);
5860 begin
5861 loop
5862 if P = Data.Extends then
5863 return True;
5864 end if;
5866 Data := Projects.Table (Data.Extends);
5867 exit when Data.Extends = No_Project;
5868 end loop;
5869 end;
5870 end if;
5872 return False;
5873 end Check_Project;
5875 -- Start of processing of Insert_Project_Sources
5877 begin
5878 -- For all the sources in the project files,
5880 for Id in Com.Units.First .. Com.Units.Last loop
5881 Unit := Com.Units.Table (Id);
5882 Sfile := No_Name;
5884 -- If there is a source for the body, and the body has not been
5885 -- locally removed,
5887 if Unit.File_Names (Com.Body_Part).Name /= No_Name
5888 and then Unit.File_Names (Com.Body_Part).Path /= Slash
5889 then
5891 -- And it is a source for the specified project
5893 if Check_Project (Unit.File_Names (Com.Body_Part).Project) then
5895 -- If we don't have a spec, we cannot consider the source
5896 -- if it is a subunit
5898 if Unit.File_Names (Com.Specification).Name = No_Name then
5899 declare
5900 Src_Ind : Source_File_Index;
5902 -- Here we are cheating a little bit: we don't want to
5903 -- use Sinput.L, because it depends on the GNAT tree
5904 -- (Atree, Sinfo, ...). So, we pretend that it is
5905 -- a project file, and we use Sinput.P.
5906 -- Source_File_Is_Subunit is just scanning through
5907 -- the file until it finds one of the reserved words
5908 -- separate, procedure, function, generic or package.
5909 -- Fortunately, these Ada reserved words are also
5910 -- reserved for project files.
5912 begin
5913 Src_Ind := Sinput.P.Load_Project_File
5914 (Get_Name_String
5915 (Unit.File_Names (Com.Body_Part).Path));
5917 -- If it is a subunit, discard it
5919 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
5920 Sfile := No_Name;
5922 else
5923 Sfile := Unit.File_Names (Com.Body_Part).Name;
5924 end if;
5925 end;
5927 else
5928 Sfile := Unit.File_Names (Com.Body_Part).Name;
5929 end if;
5930 end if;
5932 elsif Unit.File_Names (Com.Specification).Name /= No_Name
5933 and then Unit.File_Names (Com.Specification).Path /= Slash
5934 and then Check_Project (Unit.File_Names (Com.Specification).Project)
5935 then
5936 -- If there is no source for the body, but there is a source
5937 -- for the spec which has not been locally removed, then we take
5938 -- this one.
5940 Sfile := Unit.File_Names (Com.Specification).Name;
5941 end if;
5943 -- If Put_In_Q is True, we insert into the Q
5945 if Put_In_Q then
5947 -- For the first source inserted into the Q, we need
5948 -- to initialize the Q, but not for the subsequent sources.
5950 if First_Q_Initialization then
5951 Init_Q;
5952 end if;
5954 -- And of course, we only insert in the Q if the source
5955 -- is not marked.
5957 if Sfile /= No_Name and then not Is_Marked (Sfile) then
5958 if Verbose_Mode then
5959 Write_Str ("Adding """);
5960 Write_Str (Get_Name_String (Sfile));
5961 Write_Line (""" to the queue");
5962 end if;
5964 Insert_Q (Sfile);
5965 Mark (Sfile);
5966 end if;
5968 elsif Sfile /= No_Name then
5970 -- If Put_In_Q is False, we add the source as it it were
5971 -- specified on the command line, and we set Put_In_Q to True,
5972 -- so that the following sources will be put directly in the
5973 -- queue. This will allow parallel compilation processes if -jx
5974 -- switch is used.
5976 if Verbose_Mode then
5977 Write_Str ("Adding """);
5978 Write_Str (Get_Name_String (Sfile));
5979 Write_Line (""" as if on the command line");
5980 end if;
5982 Osint.Add_File (Get_Name_String (Sfile));
5983 Put_In_Q := True;
5984 end if;
5985 end loop;
5986 end Insert_Project_Sources;
5988 --------------
5989 -- Insert_Q --
5990 --------------
5992 procedure Insert_Q
5993 (Source_File : File_Name_Type;
5994 Source_Unit : Unit_Name_Type := No_Name;
5995 Index : Int := 0)
5997 begin
5998 if Debug.Debug_Flag_Q then
5999 Write_Str (" Q := Q + [ ");
6000 Write_Name (Source_File);
6002 if Index /= 0 then
6003 Write_Str (", ");
6004 Write_Int (Index);
6005 end if;
6007 Write_Str (" ] ");
6008 Write_Eol;
6009 end if;
6011 Q.Table (Q.Last) :=
6012 (File => Source_File,
6013 Unit => Source_Unit,
6014 Index => Index);
6015 Q.Increment_Last;
6016 end Insert_Q;
6018 ---------------------
6019 -- Is_In_Obsoleted --
6020 ---------------------
6022 function Is_In_Obsoleted (F : Name_Id) return Boolean is
6023 begin
6024 if F = No_File then
6025 return False;
6027 else
6028 declare
6029 Name : constant String := Get_Name_String (F);
6030 First : Natural := Name'Last;
6031 F2 : Name_Id := F;
6033 begin
6034 while First > Name'First
6035 and then Name (First - 1) /= Directory_Separator
6036 and then Name (First - 1) /= '/'
6037 loop
6038 First := First - 1;
6039 end loop;
6041 if First /= Name'First then
6042 Name_Len := 0;
6043 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
6044 F2 := Name_Find;
6045 end if;
6047 return Obsoleted.Get (F2);
6048 end;
6049 end if;
6050 end Is_In_Obsoleted;
6052 ----------------------------
6053 -- Is_In_Object_Directory --
6054 ----------------------------
6056 function Is_In_Object_Directory
6057 (Source_File : File_Name_Type;
6058 Full_Lib_File : File_Name_Type) return Boolean
6060 begin
6061 -- There is something to check only when using project files.
6062 -- Otherwise, this function returns True (last line of the function).
6064 if Main_Project /= No_Project then
6065 declare
6066 Source_File_Name : constant String :=
6067 Get_Name_String (Source_File);
6068 Saved_Verbosity : constant Verbosity := Prj.Com.Current_Verbosity;
6069 Project : Project_Id := No_Project;
6070 Path_Name : Name_Id := No_Name;
6071 Data : Project_Data;
6073 begin
6074 -- Call Get_Reference to know the ultimate extending project of
6075 -- the source. Call it with verbosity default to avoid verbose
6076 -- messages.
6078 Prj.Com.Current_Verbosity := Default;
6079 Prj.Env.
6080 Get_Reference
6081 (Source_File_Name => Source_File_Name,
6082 Project => Project,
6083 Path => Path_Name);
6084 Prj.Com.Current_Verbosity := Saved_Verbosity;
6086 -- If this source is in a project, check that the ALI file is
6087 -- in its object directory. If it is not, return False, so that
6088 -- the ALI file will not be skipped.
6090 -- If the source is not in an extending project, we fall back to
6091 -- the general case and return True at the end of the function.
6093 if Project /= No_Project
6094 and then Projects.Table (Project).Extends /= No_Project
6095 then
6096 Data := Projects.Table (Project);
6098 declare
6099 Object_Directory : constant String :=
6100 Normalize_Pathname
6101 (Get_Name_String
6102 (Data.Object_Directory));
6104 Olast : Natural := Object_Directory'Last;
6106 Lib_File_Directory : constant String :=
6107 Normalize_Pathname (Dir_Name
6108 (Get_Name_String (Full_Lib_File)));
6110 Llast : Natural := Lib_File_Directory'Last;
6112 begin
6113 -- For directories, Normalize_Pathname may or may not put
6114 -- a directory separator at the end, depending on its input.
6115 -- Remove any last directory separator before comparaison.
6116 -- Returns True only if the two directories are the same.
6118 if Object_Directory (Olast) = Directory_Separator then
6119 Olast := Olast - 1;
6120 end if;
6122 if Lib_File_Directory (Llast) = Directory_Separator then
6123 Llast := Llast - 1;
6124 end if;
6126 return Object_Directory (Object_Directory'First .. Olast) =
6127 Lib_File_Directory (Lib_File_Directory'First .. Llast);
6128 end;
6129 end if;
6130 end;
6131 end if;
6133 -- When the source is not in a project file, always return True
6135 return True;
6136 end Is_In_Object_Directory;
6138 ----------
6139 -- Link --
6140 ----------
6142 procedure Link (ALI_File : File_Name_Type; Args : Argument_List) is
6143 Link_Args : Argument_List (1 .. Args'Length + 1);
6144 Success : Boolean;
6146 begin
6147 Get_Name_String (ALI_File);
6148 Link_Args (1) := new String'(Name_Buffer (1 .. Name_Len));
6150 Link_Args (2 .. Args'Length + 1) := Args;
6152 GNAT.OS_Lib.Normalize_Arguments (Link_Args);
6154 Display (Gnatlink.all, Link_Args);
6156 if Gnatlink_Path = null then
6157 Make_Failed ("error, unable to locate ", Gnatlink.all);
6158 end if;
6160 GNAT.OS_Lib.Spawn (Gnatlink_Path.all, Link_Args, Success);
6162 if not Success then
6163 raise Link_Failed;
6164 end if;
6165 end Link;
6167 ---------------------------
6168 -- List_Bad_Compilations --
6169 ---------------------------
6171 procedure List_Bad_Compilations is
6172 begin
6173 for J in Bad_Compilation.First .. Bad_Compilation.Last loop
6174 if Bad_Compilation.Table (J).File = No_File then
6175 null;
6176 elsif not Bad_Compilation.Table (J).Found then
6177 Inform (Bad_Compilation.Table (J).File, "not found");
6178 else
6179 Inform (Bad_Compilation.Table (J).File, "compilation error");
6180 end if;
6181 end loop;
6182 end List_Bad_Compilations;
6184 -----------------
6185 -- List_Depend --
6186 -----------------
6188 procedure List_Depend is
6189 Lib_Name : Name_Id;
6190 Obj_Name : Name_Id;
6191 Src_Name : Name_Id;
6193 Len : Natural;
6194 Line_Pos : Natural;
6195 Line_Size : constant := 77;
6197 begin
6198 Set_Standard_Output;
6200 for A in ALIs.First .. ALIs.Last loop
6201 Lib_Name := ALIs.Table (A).Afile;
6203 -- We have to provide the full library file name in In_Place_Mode
6205 if In_Place_Mode then
6206 Lib_Name := Full_Lib_File_Name (Lib_Name);
6207 end if;
6209 Obj_Name := Object_File_Name (Lib_Name);
6210 Write_Name (Obj_Name);
6211 Write_Str (" :");
6213 Get_Name_String (Obj_Name);
6214 Len := Name_Len;
6215 Line_Pos := Len + 2;
6217 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
6218 Src_Name := Sdep.Table (D).Sfile;
6220 if Is_Internal_File_Name (Src_Name)
6221 and then not Check_Readonly_Files
6222 then
6223 null;
6224 else
6225 if not Quiet_Output then
6226 Src_Name := Full_Source_Name (Src_Name);
6227 end if;
6229 Get_Name_String (Src_Name);
6230 Len := Name_Len;
6232 if Line_Pos + Len + 1 > Line_Size then
6233 Write_Str (" \");
6234 Write_Eol;
6235 Line_Pos := 0;
6236 end if;
6238 Line_Pos := Line_Pos + Len + 1;
6240 Write_Str (" ");
6241 Write_Name (Src_Name);
6242 end if;
6243 end loop;
6245 Write_Eol;
6246 end loop;
6248 Set_Standard_Error;
6249 end List_Depend;
6251 -----------------
6252 -- Make_Failed --
6253 -----------------
6255 procedure Make_Failed (S1 : String; S2 : String := ""; S3 : String := "") is
6256 begin
6257 Delete_All_Temp_Files;
6258 Osint.Fail (S1, S2, S3);
6259 end Make_Failed;
6261 --------------------
6262 -- Mark_Directory --
6263 --------------------
6265 procedure Mark_Directory
6266 (Dir : String;
6267 Mark : Lib_Mark_Type)
6269 N : Name_Id;
6270 B : Byte;
6272 begin
6273 -- Dir last character is supposed to be a directory separator.
6275 Name_Len := Dir'Length;
6276 Name_Buffer (1 .. Name_Len) := Dir;
6278 if not Is_Directory_Separator (Name_Buffer (Name_Len)) then
6279 Name_Len := Name_Len + 1;
6280 Name_Buffer (Name_Len) := Directory_Separator;
6281 end if;
6283 -- Add flags to the already existing flags
6285 N := Name_Find;
6286 B := Get_Name_Table_Byte (N);
6287 Set_Name_Table_Byte (N, B or Mark);
6288 end Mark_Directory;
6290 -----------------------------
6291 -- Recursive_Compute_Depth --
6292 -----------------------------
6294 procedure Recursive_Compute_Depth
6295 (Project : Project_Id;
6296 Depth : Natural)
6298 List : Project_List;
6299 Proj : Project_Id;
6301 begin
6302 -- Nothing to do if there is no project or if the project has already
6303 -- been seen or if the depth is large enough.
6305 if Project = No_Project
6306 or else Projects.Table (Project).Seen
6307 or else Projects.Table (Project).Depth >= Depth
6308 then
6309 return;
6310 end if;
6312 Projects.Table (Project).Depth := Depth;
6314 -- Mark the project as Seen to avoid endless loop caused by limited
6315 -- withs.
6317 Projects.Table (Project).Seen := True;
6319 List := Projects.Table (Project).Imported_Projects;
6321 -- Visit each imported project
6323 while List /= Empty_Project_List loop
6324 Proj := Project_Lists.Table (List).Project;
6325 List := Project_Lists.Table (List).Next;
6326 Recursive_Compute_Depth
6327 (Project => Proj,
6328 Depth => Depth + 1);
6329 end loop;
6331 -- Visit a project being extended, if any
6333 Recursive_Compute_Depth
6334 (Project => Projects.Table (Project).Extends,
6335 Depth => Depth + 1);
6337 -- Reset the Seen flag, as we leave this project
6339 Projects.Table (Project).Seen := False;
6340 end Recursive_Compute_Depth;
6342 -----------------------
6343 -- Sigint_Intercpted --
6344 -----------------------
6346 procedure Sigint_Intercepted is
6347 begin
6348 Write_Line ("*** Interrupted ***");
6349 Delete_All_Temp_Files;
6350 OS_Exit (1);
6351 end Sigint_Intercepted;
6353 -------------------
6354 -- Scan_Make_Arg --
6355 -------------------
6357 procedure Scan_Make_Arg (Argv : String; And_Save : Boolean) is
6358 begin
6359 pragma Assert (Argv'First = 1);
6361 if Argv'Length = 0 then
6362 return;
6363 end if;
6365 -- If the previous switch has set the Project_File_Name_Present
6366 -- flag (that is we have seen a -P alone), then the next argument is
6367 -- the name of the project file.
6369 if Project_File_Name_Present and then Project_File_Name = null then
6370 if Argv (1) = '-' then
6371 Make_Failed ("project file name missing after -P");
6373 else
6374 Project_File_Name_Present := False;
6375 Project_File_Name := new String'(Argv);
6376 end if;
6378 -- If the previous switch has set the Output_File_Name_Present
6379 -- flag (that is we have seen a -o), then the next argument is
6380 -- the name of the output executable.
6382 elsif Output_File_Name_Present
6383 and then not Output_File_Name_Seen
6384 then
6385 Output_File_Name_Seen := True;
6387 if Argv (1) = '-' then
6388 Make_Failed ("output file name missing after -o");
6390 else
6391 Add_Switch ("-o", Linker, And_Save => And_Save);
6393 -- Automatically add the executable suffix if it has not been
6394 -- specified explicitly.
6396 declare
6397 Canonical_Argv : String := Argv;
6398 begin
6399 -- Get the file name in canonical case to accept as is
6400 -- names ending with ".EXE" on VMS and Windows.
6402 Canonical_Case_File_Name (Canonical_Argv);
6404 if Executable_Suffix'Length /= 0
6405 and then (Canonical_Argv'Length <= Executable_Suffix'Length
6406 or else Canonical_Argv
6407 (Canonical_Argv'Last -
6408 Executable_Suffix'Length + 1
6409 .. Canonical_Argv'Last)
6410 /= Executable_Suffix)
6411 then
6412 Add_Switch
6413 (Argv & Executable_Suffix,
6414 Linker,
6415 And_Save => And_Save);
6416 else
6417 Add_Switch (Argv, Linker, And_Save => And_Save);
6418 end if;
6419 end;
6420 end if;
6422 -- If the previous switch has set the Object_Directory_Present flag
6423 -- (that is we have seen a -D), then the next argument is
6424 -- the path name of the object directory..
6426 elsif Object_Directory_Present
6427 and then not Object_Directory_Seen
6428 then
6429 Object_Directory_Seen := True;
6431 if Argv (1) = '-' then
6432 Make_Failed ("object directory path name missing after -D");
6434 elsif not Is_Directory (Argv) then
6435 Make_Failed ("cannot find object directory """, Argv, """");
6437 else
6438 Add_Lib_Search_Dir (Argv);
6440 -- Specify the object directory to the binder
6442 Add_Switch ("-aO" & Argv, Binder, And_Save => And_Save);
6444 -- Record the object directory. Make sure it ends with a directory
6445 -- separator.
6447 if Argv (Argv'Last) = Directory_Separator then
6448 Object_Directory_Path := new String'(Argv);
6450 else
6451 Object_Directory_Path :=
6452 new String'(Argv & Directory_Separator);
6453 end if;
6454 end if;
6456 -- Then check if we are dealing with -cargs/-bargs/-largs/-margs
6458 elsif Argv = "-bargs"
6459 or else
6460 Argv = "-cargs"
6461 or else
6462 Argv = "-largs"
6463 or else
6464 Argv = "-margs"
6465 then
6466 case Argv (2) is
6467 when 'c' => Program_Args := Compiler;
6468 when 'b' => Program_Args := Binder;
6469 when 'l' => Program_Args := Linker;
6470 when 'm' => Program_Args := None;
6472 when others =>
6473 raise Program_Error;
6474 end case;
6476 -- A special test is needed for the -o switch within a -largs
6477 -- since that is another way to specify the name of the final
6478 -- executable.
6480 elsif Program_Args = Linker
6481 and then Argv = "-o"
6482 then
6483 Make_Failed ("switch -o not allowed within a -largs. " &
6484 "Use -o directly.");
6486 -- Check to see if we are reading switches after a -cargs,
6487 -- -bargs or -largs switch. If yes save it.
6489 elsif Program_Args /= None then
6491 -- Check to see if we are reading -I switches in order
6492 -- to take into account in the src & lib search directories.
6494 if Argv'Length > 2 and then Argv (1 .. 2) = "-I" then
6495 if Argv (3 .. Argv'Last) = "-" then
6496 Look_In_Primary_Dir := False;
6498 elsif Program_Args = Compiler then
6499 if Argv (3 .. Argv'Last) /= "-" then
6500 Add_Src_Search_Dir (Argv (3 .. Argv'Last));
6501 end if;
6503 elsif Program_Args = Binder then
6504 Add_Lib_Search_Dir (Argv (3 .. Argv'Last));
6505 end if;
6506 end if;
6508 Add_Switch (Argv, Program_Args, And_Save => And_Save);
6510 -- Handle non-default compiler, binder, linker, and handle --RTS switch
6512 elsif Argv'Length > 2 and then Argv (1 .. 2) = "--" then
6513 if Argv'Length > 6
6514 and then Argv (1 .. 6) = "--GCC="
6515 then
6516 declare
6517 Program_Args : constant Argument_List_Access :=
6518 Argument_String_To_List
6519 (Argv (7 .. Argv'Last));
6521 begin
6522 if And_Save then
6523 Saved_Gcc := new String'(Program_Args.all (1).all);
6524 else
6525 Gcc := new String'(Program_Args.all (1).all);
6526 end if;
6528 for J in 2 .. Program_Args.all'Last loop
6529 Add_Switch
6530 (Program_Args.all (J).all,
6531 Compiler,
6532 And_Save => And_Save);
6533 end loop;
6534 end;
6536 elsif Argv'Length > 11
6537 and then Argv (1 .. 11) = "--GNATBIND="
6538 then
6539 declare
6540 Program_Args : constant Argument_List_Access :=
6541 Argument_String_To_List
6542 (Argv (12 .. Argv'Last));
6544 begin
6545 if And_Save then
6546 Saved_Gnatbind := new String'(Program_Args.all (1).all);
6547 else
6548 Gnatbind := new String'(Program_Args.all (1).all);
6549 end if;
6551 for J in 2 .. Program_Args.all'Last loop
6552 Add_Switch
6553 (Program_Args.all (J).all, Binder, And_Save => And_Save);
6554 end loop;
6555 end;
6557 elsif Argv'Length > 11
6558 and then Argv (1 .. 11) = "--GNATLINK="
6559 then
6560 declare
6561 Program_Args : constant Argument_List_Access :=
6562 Argument_String_To_List
6563 (Argv (12 .. Argv'Last));
6564 begin
6565 if And_Save then
6566 Saved_Gnatlink := new String'(Program_Args.all (1).all);
6567 else
6568 Gnatlink := new String'(Program_Args.all (1).all);
6569 end if;
6571 for J in 2 .. Program_Args.all'Last loop
6572 Add_Switch (Program_Args.all (J).all, Linker);
6573 end loop;
6574 end;
6576 elsif Argv'Length >= 5 and then
6577 Argv (1 .. 5) = "--RTS"
6578 then
6579 Add_Switch (Argv, Compiler, And_Save => And_Save);
6580 Add_Switch (Argv, Binder, And_Save => And_Save);
6582 if Argv'Length <= 6 or else Argv (6) /= '=' then
6583 Make_Failed ("missing path for --RTS");
6585 else
6586 -- Check that this is the first time we see this switch or
6587 -- if it is not the first time, the same path is specified.
6589 if RTS_Specified = null then
6590 RTS_Specified := new String'(Argv (7 .. Argv'Last));
6592 elsif RTS_Specified.all /= Argv (7 .. Argv'Last) then
6593 Make_Failed ("--RTS cannot be specified multiple times");
6594 end if;
6596 -- Valid --RTS switch
6598 No_Stdinc := True;
6599 No_Stdlib := True;
6600 RTS_Switch := True;
6602 declare
6603 Src_Path_Name : constant String_Ptr :=
6604 Get_RTS_Search_Dir
6605 (Argv (7 .. Argv'Last), Include);
6607 Lib_Path_Name : constant String_Ptr :=
6608 Get_RTS_Search_Dir
6609 (Argv (7 .. Argv'Last), Objects);
6611 begin
6612 if Src_Path_Name /= null and then
6613 Lib_Path_Name /= null
6614 then
6615 -- Set the RTS_*_Path_Name variables, so that the correct
6616 -- directories will be set when
6617 -- Osint.Add_Default_Search_Dirs will be called later.
6619 RTS_Src_Path_Name := Src_Path_Name;
6620 RTS_Lib_Path_Name := Lib_Path_Name;
6622 elsif Src_Path_Name = null
6623 and Lib_Path_Name = null then
6624 Make_Failed ("RTS path not valid: missing " &
6625 "adainclude and adalib directories");
6627 elsif Src_Path_Name = null then
6628 Make_Failed ("RTS path not valid: missing adainclude " &
6629 "directory");
6631 elsif Lib_Path_Name = null then
6632 Make_Failed ("RTS path not valid: missing adalib " &
6633 "directory");
6634 end if;
6635 end;
6636 end if;
6638 else
6639 Make_Failed ("unknown switch: ", Argv);
6640 end if;
6642 -- If we have seen a regular switch process it
6644 elsif Argv (1) = '-' then
6646 if Argv'Length = 1 then
6647 Make_Failed ("switch character cannot be followed by a blank");
6649 -- -I-
6651 elsif Argv (2 .. Argv'Last) = "I-" then
6652 Look_In_Primary_Dir := False;
6654 -- Forbid -?- or -??- where ? is any character
6656 elsif (Argv'Length = 3 and then Argv (3) = '-')
6657 or else (Argv'Length = 4 and then Argv (4) = '-')
6658 then
6659 Make_Failed ("trailing ""-"" at the end of ", Argv, " forbidden.");
6661 -- -Idir
6663 elsif Argv (2) = 'I' then
6664 Add_Src_Search_Dir (Argv (3 .. Argv'Last));
6665 Add_Lib_Search_Dir (Argv (3 .. Argv'Last));
6666 Add_Switch (Argv, Compiler, And_Save => And_Save);
6667 Add_Switch (Argv, Binder, And_Save => And_Save);
6669 -- -aIdir (to gcc this is like a -I switch)
6671 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aI" then
6672 Add_Src_Search_Dir (Argv (4 .. Argv'Last));
6673 Add_Switch ("-I" & Argv (4 .. Argv'Last),
6674 Compiler,
6675 And_Save => And_Save);
6676 Add_Switch (Argv, Binder, And_Save => And_Save);
6678 -- -aOdir
6680 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aO" then
6681 Add_Lib_Search_Dir (Argv (4 .. Argv'Last));
6682 Add_Switch (Argv, Binder, And_Save => And_Save);
6684 -- -aLdir (to gnatbind this is like a -aO switch)
6686 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aL" then
6687 Mark_Directory (Argv (4 .. Argv'Last), Ada_Lib_Dir);
6688 Add_Lib_Search_Dir (Argv (4 .. Argv'Last));
6689 Add_Switch ("-aO" & Argv (4 .. Argv'Last),
6690 Binder,
6691 And_Save => And_Save);
6693 -- -Adir (to gnatbind this is like a -aO switch, to gcc like a -I)
6695 elsif Argv (2) = 'A' then
6696 Mark_Directory (Argv (3 .. Argv'Last), Ada_Lib_Dir);
6697 Add_Src_Search_Dir (Argv (3 .. Argv'Last));
6698 Add_Lib_Search_Dir (Argv (3 .. Argv'Last));
6699 Add_Switch ("-I" & Argv (3 .. Argv'Last),
6700 Compiler,
6701 And_Save => And_Save);
6702 Add_Switch ("-aO" & Argv (3 .. Argv'Last),
6703 Binder,
6704 And_Save => And_Save);
6706 -- -Ldir
6708 elsif Argv (2) = 'L' then
6709 Add_Switch (Argv, Linker, And_Save => And_Save);
6711 -- For -gxxxxx, -pg, -mxxx, -fxxx: give the switch to both the
6712 -- compiler and the linker (except for -gnatxxx which is only for
6713 -- the compiler). Some of the -mxxx (for example -m64) and -fxxx
6714 -- (for example -ftest-coverage for gcov) need to be used when
6715 -- compiling the binder generated files, and using all these gcc
6716 -- switches for the binder generated files should not be a problem.
6718 elsif
6719 (Argv (2) = 'g' and then (Argv'Last < 5
6720 or else Argv (2 .. 5) /= "gnat"))
6721 or else Argv (2 .. Argv'Last) = "pg"
6722 or else (Argv (2) = 'm' and then Argv'Last > 2)
6723 or else (Argv (2) = 'f' and then Argv'Last > 2)
6724 then
6725 Add_Switch (Argv, Compiler, And_Save => And_Save);
6726 Add_Switch (Argv, Linker, And_Save => And_Save);
6728 -- -C=<mapping file>
6730 elsif Argv'Last > 2 and then Argv (2) = 'C' then
6731 if And_Save then
6732 if Argv (3) /= '=' or else Argv'Last <= 3 then
6733 Make_Failed ("illegal switch ", Argv);
6734 end if;
6736 Gnatmake_Mapping_File := new String'(Argv (4 .. Argv'Last));
6737 end if;
6739 -- -D
6741 elsif Argv'Last = 2 and then Argv (2) = 'D' then
6742 if Project_File_Name /= null then
6743 Make_Failed ("-D cannot be used in conjunction with a " &
6744 "project file");
6746 else
6747 Scan_Make_Switches (Argv);
6748 end if;
6750 -- -d
6752 elsif Argv (2) = 'd'
6753 and then Argv'Last = 2
6754 then
6755 Display_Compilation_Progress := True;
6757 -- -i
6759 elsif Argv'Last = 2 and then Argv (2) = 'i' then
6760 if Project_File_Name /= null then
6761 Make_Failed ("-i cannot be used in conjunction with a " &
6762 "project file");
6764 else
6765 Scan_Make_Switches (Argv);
6766 end if;
6768 -- -j (need to save the result)
6770 elsif Argv (2) = 'j' then
6771 Scan_Make_Switches (Argv);
6773 if And_Save then
6774 Saved_Maximum_Processes := Maximum_Processes;
6775 end if;
6777 -- -m
6779 elsif Argv (2) = 'm'
6780 and then Argv'Last = 2
6781 then
6782 Minimal_Recompilation := True;
6784 -- -u
6786 elsif Argv (2) = 'u'
6787 and then Argv'Last = 2
6788 then
6789 Unique_Compile := True;
6790 Compile_Only := True;
6791 Do_Bind_Step := False;
6792 Do_Link_Step := False;
6794 -- -U
6796 elsif Argv (2) = 'U'
6797 and then Argv'Last = 2
6798 then
6799 Unique_Compile_All_Projects := True;
6800 Unique_Compile := True;
6801 Compile_Only := True;
6802 Do_Bind_Step := False;
6803 Do_Link_Step := False;
6805 -- -Pprj or -P prj (only once, and only on the command line)
6807 elsif Argv (2) = 'P' then
6808 if Project_File_Name /= null then
6809 Make_Failed ("cannot have several project files specified");
6811 elsif Object_Directory_Path /= null then
6812 Make_Failed ("-D cannot be used in conjunction with a " &
6813 "project file");
6815 elsif In_Place_Mode then
6816 Make_Failed ("-i cannot be used in conjunction with a " &
6817 "project file");
6819 elsif not And_Save then
6821 -- It could be a tool other than gnatmake (i.e, gnatdist)
6822 -- or a -P switch inside a project file.
6824 Fail
6825 ("either the tool is not ""project-aware"" or " &
6826 "a project file is specified inside a project file");
6828 elsif Argv'Last = 2 then
6830 -- -P is used alone: the project file name is the next option
6832 Project_File_Name_Present := True;
6834 else
6835 Project_File_Name := new String'(Argv (3 .. Argv'Last));
6836 end if;
6838 -- -vPx (verbosity of the parsing of the project files)
6840 elsif Argv'Last = 4
6841 and then Argv (2 .. 3) = "vP"
6842 and then Argv (4) in '0' .. '2'
6843 then
6844 if And_Save then
6845 case Argv (4) is
6846 when '0' =>
6847 Current_Verbosity := Prj.Default;
6848 when '1' =>
6849 Current_Verbosity := Prj.Medium;
6850 when '2' =>
6851 Current_Verbosity := Prj.High;
6852 when others =>
6853 null;
6854 end case;
6855 end if;
6857 -- -Xext=val (External assignment)
6859 elsif Argv (2) = 'X'
6860 and then Is_External_Assignment (Argv)
6861 then
6862 -- Is_External_Assignment has side effects
6863 -- when it returns True;
6865 null;
6867 -- If -gnath is present, then generate the usage information
6868 -- right now and do not pass this option on to the compiler calls.
6870 elsif Argv = "-gnath" then
6871 Usage;
6873 -- If -gnatc is specified, make sure the bind step and the link
6874 -- step are not executed.
6876 elsif Argv'Length >= 6 and then Argv (2 .. 6) = "gnatc" then
6878 -- If -gnatc is specified, make sure the bind step and the link
6879 -- step are not executed.
6881 Add_Switch (Argv, Compiler, And_Save => And_Save);
6882 Operating_Mode := Check_Semantics;
6883 Check_Object_Consistency := False;
6884 Compile_Only := True;
6885 Do_Bind_Step := False;
6886 Do_Link_Step := False;
6888 elsif Argv (2 .. Argv'Last) = "nostdlib" then
6890 -- Don't pass -nostdlib to gnatlink, it will disable
6891 -- linking with all standard library files.
6893 No_Stdlib := True;
6895 Add_Switch (Argv, Compiler, And_Save => And_Save);
6896 Add_Switch (Argv, Binder, And_Save => And_Save);
6898 elsif Argv (2 .. Argv'Last) = "nostdinc" then
6900 -- Pass -nostdinc to the Compiler and to gnatbind
6902 No_Stdinc := True;
6903 Add_Switch (Argv, Compiler, And_Save => And_Save);
6904 Add_Switch (Argv, Binder, And_Save => And_Save);
6906 -- By default all switches with more than one character
6907 -- or one character switches which are not in 'a' .. 'z'
6908 -- (except 'C', 'F', 'M' and 'B') are passed to the compiler,
6909 -- unless we are dealing with a debug switch (starts with 'd')
6910 -- or an extended gnatmake switch (starts with 'e').
6912 elsif Argv (2) /= 'd'
6913 and then Argv (2) /= 'e'
6914 and then Argv (2 .. Argv'Last) /= "C"
6915 and then Argv (2 .. Argv'Last) /= "F"
6916 and then Argv (2 .. Argv'Last) /= "M"
6917 and then Argv (2 .. Argv'Last) /= "B"
6918 and then (Argv'Length > 2 or else Argv (2) not in 'a' .. 'z')
6919 then
6920 Add_Switch (Argv, Compiler, And_Save => And_Save);
6922 -- All other options are handled by Scan_Make_Switches
6924 else
6925 Scan_Make_Switches (Argv);
6926 end if;
6928 -- If not a switch it must be a file name
6930 else
6931 Add_File (Argv);
6932 Mains.Add_Main (Argv);
6933 end if;
6934 end Scan_Make_Arg;
6936 -----------------
6937 -- Switches_Of --
6938 -----------------
6940 function Switches_Of
6941 (Source_File : Name_Id;
6942 Source_File_Name : String;
6943 Source_Index : Int;
6944 Naming : Naming_Data;
6945 In_Package : Package_Id;
6946 Allow_ALI : Boolean) return Variable_Value
6948 Switches : Variable_Value;
6950 Defaults : constant Array_Element_Id :=
6951 Prj.Util.Value_Of
6952 (Name => Name_Default_Switches,
6953 In_Arrays =>
6954 Packages.Table (In_Package).Decl.Arrays);
6956 Switches_Array : constant Array_Element_Id :=
6957 Prj.Util.Value_Of
6958 (Name => Name_Switches,
6959 In_Arrays =>
6960 Packages.Table (In_Package).Decl.Arrays);
6962 begin
6963 Switches :=
6964 Prj.Util.Value_Of
6965 (Index => Source_File,
6966 Src_Index => Source_Index,
6967 In_Array => Switches_Array);
6969 if Switches = Nil_Variable_Value then
6970 declare
6971 Name : String (1 .. Source_File_Name'Length + 3);
6972 Last : Positive := Source_File_Name'Length;
6973 Spec_Suffix : constant String :=
6974 Get_Name_String (Naming.Current_Spec_Suffix);
6975 Body_Suffix : constant String :=
6976 Get_Name_String (Naming.Current_Body_Suffix);
6977 Truncated : Boolean := False;
6979 begin
6980 Name (1 .. Last) := Source_File_Name;
6982 if Last > Body_Suffix'Length
6983 and then Name (Last - Body_Suffix'Length + 1 .. Last) =
6984 Body_Suffix
6985 then
6986 Truncated := True;
6987 Last := Last - Body_Suffix'Length;
6988 end if;
6990 if not Truncated
6991 and then Last > Spec_Suffix'Length
6992 and then Name (Last - Spec_Suffix'Length + 1 .. Last) =
6993 Spec_Suffix
6994 then
6995 Truncated := True;
6996 Last := Last - Spec_Suffix'Length;
6997 end if;
6999 if Truncated then
7000 Name_Len := Last;
7001 Name_Buffer (1 .. Name_Len) := Name (1 .. Last);
7002 Switches :=
7003 Prj.Util.Value_Of
7004 (Index => Name_Find,
7005 Src_Index => 0,
7006 In_Array => Switches_Array);
7008 if Switches = Nil_Variable_Value
7009 and then Allow_ALI
7010 then
7011 Last := Source_File_Name'Length;
7013 while Name (Last) /= '.' loop
7014 Last := Last - 1;
7015 end loop;
7017 Name (Last + 1 .. Last + 3) := "ali";
7018 Name_Len := Last + 3;
7019 Name_Buffer (1 .. Name_Len) := Name (1 .. Name_Len);
7020 Switches :=
7021 Prj.Util.Value_Of
7022 (Index => Name_Find,
7023 Src_Index => 0,
7024 In_Array => Switches_Array);
7025 end if;
7026 end if;
7027 end;
7028 end if;
7030 if Switches = Nil_Variable_Value then
7031 Switches :=
7032 Prj.Util.Value_Of
7033 (Index => Name_Ada,
7034 Src_Index => 0,
7035 In_Array => Defaults);
7036 end if;
7038 return Switches;
7039 end Switches_Of;
7041 -----------
7042 -- Usage --
7043 -----------
7045 procedure Usage is
7046 begin
7047 if Usage_Needed then
7048 Usage_Needed := False;
7049 Makeusg;
7050 end if;
7051 end Usage;
7053 -----------------
7054 -- Verbose_Msg --
7055 -----------------
7057 procedure Verbose_Msg
7058 (N1 : Name_Id;
7059 S1 : String;
7060 N2 : Name_Id := No_Name;
7061 S2 : String := "";
7062 Prefix : String := " -> ")
7064 begin
7065 if not Verbose_Mode then
7066 return;
7067 end if;
7069 Write_Str (Prefix);
7070 Write_Str ("""");
7071 Write_Name (N1);
7072 Write_Str (""" ");
7073 Write_Str (S1);
7075 if N2 /= No_Name then
7076 Write_Str (" """);
7077 Write_Name (N2);
7078 Write_Str (""" ");
7079 end if;
7081 Write_Str (S2);
7082 Write_Eol;
7083 end Verbose_Msg;
7085 begin
7086 -- Make sure that in case of failure, the temp files will be deleted
7088 Prj.Com.Fail := Make_Failed'Access;
7089 MLib.Fail := Make_Failed'Access;
7090 Makeutl.Do_Fail := Make_Failed'Access;
7091 end Make;