1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005, Free Software Foundation, Inc. --
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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
28 with ALI
.Util
; use ALI
.Util
;
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
;
38 with Makeutl
; use Makeutl
;
40 with MLib
.Tgt
; use MLib
.Tgt
;
42 with Namet
; use Namet
;
44 with Osint
.M
; use Osint
.M
;
45 with Osint
; use Osint
;
46 with Output
; use Output
;
54 with Snames
; use Snames
;
55 with Switch
; use Switch
;
56 with Switch
.M
; use Switch
.M
;
60 with Ada
.Exceptions
; use Ada
.Exceptions
;
61 with Ada
.Command_Line
; use Ada
.Command_Line
;
63 with GNAT
.Directory_Operations
; use GNAT
.Directory_Operations
;
64 with GNAT
.Case_Util
; use GNAT
.Case_Util
;
71 -- Make control characters visible
73 Standard_Library_Package_Body_Name
: constant String := "s-stalib.adb";
74 -- Every program depends on this package, that must then be checked,
75 -- especially when -f and -a are used.
77 type Sigint_Handler
is access procedure;
79 procedure Install_Int_Handler
(Handler
: Sigint_Handler
);
80 pragma Import
(C
, Install_Int_Handler
, "__gnat_install_int_handler");
81 -- Called by Gnatmake to install the SIGINT handler below
83 procedure Sigint_Intercepted
;
84 -- Called when the program is interrupted by Ctrl-C to delete the
85 -- temporary mapping files and configuration pragmas files.
87 -------------------------
88 -- Note on terminology --
89 -------------------------
91 -- In this program, we use the phrase "termination" of a file name to
92 -- refer to the suffix that appears after the unit name portion. Very
93 -- often this is simply the extension, but in some cases, the sequence
94 -- may be more complex, for example in main.1.ada, the termination in
95 -- this name is ".1.ada" and in main_.ada the termination is "_.ada".
97 -------------------------------------
98 -- Queue (Q) Manipulation Routines --
99 -------------------------------------
101 -- The Q is used in Compile_Sources below. Its implementation uses the
102 -- GNAT generic package Table (basically an extensible array). Q_Front
103 -- points to the first valid element in the Q, whereas Q.First is the first
104 -- element ever enqueued, while Q.Last - 1 is the last element in the Q.
106 -- +---+--------------+---+---+---+-----------+---+--------
107 -- Q | | ........ | | | | ....... | |
108 -- +---+--------------+---+---+---+-----------+---+--------
110 -- Q.First Q_Front Q.Last - 1
112 -- The elements comprised between Q.First and Q_Front - 1 are the
113 -- elements that have been enqueued and then dequeued, while the
114 -- elements between Q_Front and Q.Last - 1 are the elements currently
115 -- in the Q. When the Q is initialized Q_Front = Q.First = Q.Last.
116 -- After Compile_Sources has terminated its execution, Q_Front = Q.Last
117 -- and the elements contained between Q.Front and Q.Last-1 are those that
118 -- were explored and thus marked by Compile_Sources. Whenever the Q is
119 -- reinitialized, the elements between Q.First and Q.Last - 1 are unmarked.
122 -- Must be called to (re)initialize the Q
125 (Source_File
: File_Name_Type
;
126 Source_Unit
: Unit_Name_Type
:= No_Name
;
128 -- Inserts Source_File at the end of Q. Provide Source_Unit when possible
129 -- for external use (gnatdist). Provide index for multi-unit sources.
131 function Empty_Q
return Boolean;
132 -- Returns True if Q is empty
134 procedure Extract_From_Q
135 (Source_File
: out File_Name_Type
;
136 Source_Unit
: out Unit_Name_Type
;
137 Source_Index
: out Int
);
138 -- Extracts the first element from the Q
140 procedure Insert_Project_Sources
141 (The_Project
: Project_Id
;
142 All_Projects
: Boolean;
144 -- If Into_Q is True, insert all sources of the project file(s) that are
145 -- not already marked into the Q. If Into_Q is False, call Osint.Add_File
146 -- for the first source, then insert all other sources that are not already
147 -- marked into the Q. If All_Projects is True, all sources of all projects
148 -- are concerned; otherwise, only sources of The_Project are concerned,
149 -- including, if The_Project is an extending project, sources inherited
150 -- from projects being extended.
152 First_Q_Initialization
: Boolean := True;
153 -- Will be set to false after Init_Q has been called once
156 -- Points to the first valid element in the Q
158 Unique_Compile
: Boolean := False;
159 -- Set to True if -u or -U or a project file with no main is used
161 Unique_Compile_All_Projects
: Boolean := False;
162 -- Set to True if -U is used
164 RTS_Specified
: String_Access
:= null;
165 -- Used to detect multiple --RTS= switches
167 type Q_Record
is record
168 File
: File_Name_Type
;
169 Unit
: Unit_Name_Type
;
172 -- File is the name of the file to compile. Unit is for gnatdist
173 -- use in order to easily get the unit name of a file to compile
174 -- when its name is krunched or declared in gnat.adc. Index, when not 0,
175 -- is the index of the unit in a multi-unit source.
177 package Q
is new Table
.Table
(
178 Table_Component_Type
=> Q_Record
,
179 Table_Index_Type
=> Natural,
180 Table_Low_Bound
=> 0,
181 Table_Initial
=> 4000,
182 Table_Increment
=> 100,
183 Table_Name
=> "Make.Q");
184 -- This is the actual Q
186 -- The following instantiations and variables are necessary to save what
187 -- is found on the command line, in case there is a project file specified.
189 package Saved_Gcc_Switches
is new Table
.Table
(
190 Table_Component_Type
=> String_Access
,
191 Table_Index_Type
=> Integer,
192 Table_Low_Bound
=> 1,
194 Table_Increment
=> 100,
195 Table_Name
=> "Make.Saved_Gcc_Switches");
197 package Saved_Binder_Switches
is new Table
.Table
(
198 Table_Component_Type
=> String_Access
,
199 Table_Index_Type
=> Integer,
200 Table_Low_Bound
=> 1,
202 Table_Increment
=> 100,
203 Table_Name
=> "Make.Saved_Binder_Switches");
205 package Saved_Linker_Switches
is new Table
.Table
206 (Table_Component_Type
=> String_Access
,
207 Table_Index_Type
=> Integer,
208 Table_Low_Bound
=> 1,
210 Table_Increment
=> 100,
211 Table_Name
=> "Make.Saved_Linker_Switches");
213 package Switches_To_Check
is new Table
.Table
(
214 Table_Component_Type
=> String_Access
,
215 Table_Index_Type
=> Integer,
216 Table_Low_Bound
=> 1,
218 Table_Increment
=> 100,
219 Table_Name
=> "Make.Switches_To_Check");
221 package Library_Paths
is new Table
.Table
(
222 Table_Component_Type
=> String_Access
,
223 Table_Index_Type
=> Integer,
224 Table_Low_Bound
=> 1,
226 Table_Increment
=> 100,
227 Table_Name
=> "Make.Library_Paths");
229 package Failed_Links
is new Table
.Table
(
230 Table_Component_Type
=> File_Name_Type
,
231 Table_Index_Type
=> Integer,
232 Table_Low_Bound
=> 1,
234 Table_Increment
=> 100,
235 Table_Name
=> "Make.Failed_Links");
237 package Successful_Links
is new Table
.Table
(
238 Table_Component_Type
=> File_Name_Type
,
239 Table_Index_Type
=> Integer,
240 Table_Low_Bound
=> 1,
242 Table_Increment
=> 100,
243 Table_Name
=> "Make.Successful_Links");
245 package Library_Projs
is new Table
.Table
(
246 Table_Component_Type
=> Project_Id
,
247 Table_Index_Type
=> Integer,
248 Table_Low_Bound
=> 1,
250 Table_Increment
=> 100,
251 Table_Name
=> "Make.Library_Projs");
253 -- Two variables to keep the last binder and linker switch index in tables
254 -- Binder_Switches and Linker_Switches, before adding switches from the
255 -- project file (if any) and switches from the command line (if any).
257 Last_Binder_Switch
: Integer := 0;
258 Last_Linker_Switch
: Integer := 0;
260 Normalized_Switches
: Argument_List_Access
:= new Argument_List
(1 .. 10);
261 Last_Norm_Switch
: Natural := 0;
263 Saved_Maximum_Processes
: Natural := 0;
265 type Arg_List_Ref
is access Argument_List
;
266 The_Saved_Gcc_Switches
: Arg_List_Ref
;
268 Project_File_Name
: String_Access
:= null;
269 -- The path name of the main project file, if any
271 Project_File_Name_Present
: Boolean := False;
272 -- True when -P is used with a space between -P and the project file name
274 Current_Verbosity
: Prj
.Verbosity
:= Prj
.Default
;
275 -- Verbosity to parse the project files
277 Project_Tree
: constant Project_Tree_Ref
:= new Project_Tree_Data
;
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. Avoid
284 -- calling Change_Dir if the current working directory is already this
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_Library_Search_Dir
307 On_Command_Line : Boolean);
308 -- Call Add_Lib_Search_Dir with an absolute directory path. If Path is a
309 -- relative path, when On_Command_Line is True, it is relative to the
310 -- current working directory; when On_Command_Line is False, it is relative
311 -- to the project directory of the main project.
313 procedure Add_Source_Search_Dir
315 On_Command_Line : Boolean);
316 -- Call Add_Src_Search_Dir with an absolute directory path. If Path is a
317 -- relative path, when On_Command_Line is True, it is relative to the
318 -- current working directory; when On_Command_Line is False, it is relative
319 -- to the project directory of the main project.
321 procedure Add_Source_Dir (N : String);
322 -- Call Add_Src_Search_Dir (output one line when in verbose mode)
324 procedure Add_Source_Directories is
325 new Prj.Env.For_All_Source_Dirs (Action => Add_Source_Dir);
327 procedure Add_Object_Dir (N : String);
328 -- Call Add_Lib_Search_Dir (output one line when in verbose mode)
330 procedure Add_Object_Directories is
331 new Prj.Env.For_All_Object_Dirs (Action => Add_Object_Dir);
333 procedure Change_To_Object_Directory (Project : Project_Id);
334 -- Change to the object directory of project Project, if this is not
335 -- already the current working directory.
337 type Bad_Compilation_Info is record
338 File : File_Name_Type;
339 Unit : Unit_Name_Type;
342 -- File is the name of the file for which a compilation failed. Unit is for
343 -- gnatdist use in order to easily get the unit name of a file when its
344 -- name is krunched or declared in gnat.adc. Found is False if the
345 -- compilation failed because the file could not be found.
347 package Bad_Compilation is new Table.Table (
348 Table_Component_Type => Bad_Compilation_Info,
349 Table_Index_Type => Natural,
350 Table_Low_Bound => 1,
352 Table_Increment => 100,
353 Table_Name => "Make.Bad_Compilation");
354 -- Full name of all the source files for which compilation fails
356 Do_Compile_Step : Boolean := True;
357 Do_Bind_Step : Boolean := True;
358 Do_Link_Step : Boolean := True;
359 -- Flags to indicate what step should be executed.
360 -- Can be set to False with the switches -c, -b and -l.
361 -- These flags are reset to True for each invokation of procedure Gnatmake.
363 Shared_String : aliased String := "-shared";
364 Force_Elab_Flags_String : aliased String := "-F";
366 No_Shared_Switch : aliased Argument_List := (1 .. 0 => null);
367 Shared_Switch : aliased Argument_List := (1 => Shared_String'Access);
368 Bind_Shared : Argument_List_Access := No_Shared_Switch'Access;
369 -- Switch to added in front of gnatbind switches. By default no switch is
370 -- added. Switch "-shared" is added if there is a non-static Library
373 Shared_Libgcc : aliased String := "-shared-libgcc";
375 No_Shared_Libgcc_Switch : aliased Argument_List := (1 .. 0 => null);
376 Shared_Libgcc_Switch : aliased Argument_List :=
377 (1 => Shared_Libgcc'Access);
378 Link_With_Shared_Libgcc : Argument_List_Access :=
379 No_Shared_Libgcc_Switch'Access;
381 procedure Make_Failed (S1 : String; S2 : String := ""; S3 : String := "");
382 -- Delete all temp files created by Gnatmake and call Osint.Fail,
383 -- with the parameter S1, S2 and S3 (see osint.ads).
384 -- This is called from the Prj hierarchy and the MLib hierarchy.
386 --------------------------
387 -- Obsolete Executables --
388 --------------------------
390 Executable_Obsolete : Boolean := False;
391 -- Executable_Obsolete is initially set to False for each executable,
392 -- and is set to True whenever one of the source of the executable is
393 -- compiled, or has already been compiled for another executable.
395 Max_Header : constant := 200;
396 -- This needs a proper comment, it used to say "arbitrary"
397 -- that's not an adequate comment ???
399 type Header_Num is range 1 .. Max_Header;
400 -- Header_Num for the hash table Obsoleted below
402 function Hash (F : Name_Id) return Header_Num;
403 -- Hash function for the hash table Obsoleted below
405 package Obsoleted is new System.HTable.Simple_HTable
406 (Header_Num => Header_Num,
412 -- A hash table to keep all files that have been compiled, to detect
413 -- if an executable is up to date or not.
415 procedure Enter_Into_Obsoleted (F : Name_Id);
416 -- Enter a file name, without directory information, into the hash table
419 function Is_In_Obsoleted (F : Name_Id) return Boolean;
420 -- Check if a file name, without directory information, has already been
421 -- entered into the hash table Obsoleted.
423 type Dependency is record
425 Depends_On : Name_Id;
427 -- Components of table Dependencies below
429 package Dependencies is new Table.Table (
430 Table_Component_Type => Dependency,
431 Table_Index_Type => Integer,
432 Table_Low_Bound => 1,
434 Table_Increment => 100,
435 Table_Name => "Make.Dependencies");
436 -- A table to keep dependencies, to be able to decide if an executable
439 procedure Add_Dependency (S : Name_Id; On : Name_Id);
440 -- Add one entry in table Dependencies
442 ----------------------------
443 -- Arguments and Switches --
444 ----------------------------
446 Arguments : Argument_List_Access;
447 -- Used to gather the arguments for invocation of the compiler
449 Last_Argument : Natural := 0;
450 -- Last index of arguments in Arguments above
452 Arguments_Collected : Boolean := False;
453 -- Set to True when the arguments for the next invocation of the compiler
454 -- have been collected.
456 Arguments_Project : Project_Id;
457 -- Project id, if any, of the source to be compiled
459 Arguments_Path_Name : File_Name_Type;
460 -- Full path of the source to be compiled, when Arguments_Project is not
463 Dummy_Switch : constant String_Access := new String'("- ");
464 -- Used to initialized Prev_Switch in procedure Check
466 procedure Add_Arguments
(Args
: Argument_List
);
467 -- Add arguments to global variable Arguments, increasing its size
468 -- if necessary and adjusting Last_Argument.
470 function Configuration_Pragmas_Switch
471 (For_Project
: Project_Id
) return Argument_List
;
472 -- Return an argument list of one element, if there is a configuration
473 -- pragmas file to be specified for For_Project,
474 -- otherwise return an empty argument list.
480 procedure List_Depend
;
481 -- Prints to standard output the list of object dependencies. This list
482 -- can be used directly in a Makefile. A call to Compile_Sources must
483 -- precede the call to List_Depend. Also because this routine uses the
484 -- ALI files that were originally loaded and scanned by Compile_Sources,
485 -- no additional ALI files should be scanned between the two calls (i.e.
486 -- between the call to Compile_Sources and List_Depend.)
488 procedure Inform
(N
: Name_Id
:= No_Name
; Msg
: String);
489 -- Prints out the program name followed by a colon, N and S
491 procedure List_Bad_Compilations
;
492 -- Prints out the list of all files for which the compilation failed
494 procedure Verbose_Msg
497 N2
: Name_Id
:= No_Name
;
499 Prefix
: String := " -> ";
500 Minimum_Verbosity
: Verbosity_Level_Type
:= Opt
.Low
);
501 -- If the verbose flag (Verbose_Mode) is set and the verbosity level is
502 -- at least equal to Minimum_Verbosity, then print Prefix to standard
503 -- output followed by N1 and S1. If N2 /= No_Name then N2 is printed after
504 -- S1. S2 is printed last. Both N1 and N2 are printed in quotation marks.
506 Usage_Needed
: Boolean := True;
507 -- Flag used to make sure Makeusg is call at most once
510 -- Call Makeusg, if Usage_Needed is True.
511 -- Set Usage_Needed to False.
513 procedure Debug_Msg
(S
: String; N
: Name_Id
);
514 -- If Debug.Debug_Flag_W is set outputs string S followed by name N
516 procedure Recursive_Compute_Depth
517 (Project
: Project_Id
;
519 -- Compute depth of Project and of the projects it depends on
521 procedure Compute_All_Imported_Projects
(Project
: Project_Id
);
522 -- Compute, the list of the projects imported directly or indirectly by
525 -----------------------
526 -- Gnatmake Routines --
527 -----------------------
529 Gnatmake_Called
: Boolean := False;
530 -- Set to True when procedure Gnatmake is called.
531 -- Attempt to delete temporary files is made only when Gnatmake_Called
534 subtype Lib_Mark_Type
is Byte
;
535 -- Used in Mark_Directory
537 Ada_Lib_Dir
: constant Lib_Mark_Type
:= 1;
538 -- Used to mark a directory as a GNAT lib dir
540 -- Note that the notion of GNAT lib dir is no longer used. The code related
541 -- to it has not been removed to give an idea on how to use the directory
542 -- prefix marking mechanism.
544 -- An Ada library directory is a directory containing ali and object files
545 -- but no source files for the bodies (the specs can be in the same or some
546 -- other directory). These directories are specified in the Gnatmake
547 -- command line with the switch "-Adir" (to specify the spec location -Idir
548 -- cab be used). Gnatmake skips the missing sources whose ali are in Ada
549 -- library directories. For an explanation of why Gnatmake behaves that
550 -- way, see the spec of Make.Compile_Sources. The directory lookup penalty
551 -- is incurred every single time this routine is called.
553 procedure Check_Steps
;
554 -- Check what steps (Compile, Bind, Link) must be executed.
555 -- Set the step flags accordingly.
557 function In_Ada_Lib_Dir
(File
: File_Name_Type
) return Boolean;
558 -- Get directory prefix of this file and get lib mark stored in name
559 -- table for this directory. Then check if an Ada lib mark has been set.
561 procedure Mark_Directory
563 Mark
: Lib_Mark_Type
;
564 On_Command_Line
: Boolean);
565 -- Store the absolute path from Dir in name table and set lib mark as name
566 -- info to identify Ada libraries.
568 -- If Dir is a relative path, when On_Command_Line is True, it is relative
569 -- to the current working directory; when On_Command_Line is False, it is
570 -- relative to the project directory of the main project.
572 Output_Is_Object
: Boolean := True;
573 -- Set to False when using a switch -S for the compiler
575 procedure Check_For_S_Switch
;
576 -- Set Output_Is_Object to False when the -S switch is used for the
580 (Source_File
: Name_Id
;
581 Source_File_Name
: String;
583 Naming
: Naming_Data
;
584 In_Package
: Package_Id
;
585 Allow_ALI
: Boolean) return Variable_Value
;
586 -- Return the switches for the source file in the specified package of a
587 -- project file. If the Source_File ends with a standard GNAT extension
588 -- (".ads" or ".adb"), try first the full name, then the name without the
589 -- extension, then, if Allow_ALI is True, the name with the extension
590 -- ".ali". If there is no switches for either names, try the default
591 -- switches for Ada. If all failed, return No_Variable_Value.
593 function Is_In_Object_Directory
594 (Source_File
: File_Name_Type
;
595 Full_Lib_File
: File_Name_Type
) return Boolean;
596 -- Check if, when using a project file, the ALI file is in the project
597 -- directory of the ultimate extending project. If it is not, we ignore
598 -- the fact that this ALI file is read-only.
600 ----------------------------------------------------
601 -- Compiler, Binder & Linker Data and Subprograms --
602 ----------------------------------------------------
604 Gcc
: String_Access
:= Program_Name
("gcc");
605 Gnatbind
: String_Access
:= Program_Name
("gnatbind");
606 Gnatlink
: String_Access
:= Program_Name
("gnatlink");
607 -- Default compiler, binder, linker programs
609 Saved_Gcc
: String_Access
:= null;
610 Saved_Gnatbind
: String_Access
:= null;
611 Saved_Gnatlink
: String_Access
:= null;
612 -- Given by the command line. Will be used, if non null
614 Gcc_Path
: String_Access
:=
615 GNAT
.OS_Lib
.Locate_Exec_On_Path
(Gcc
.all);
616 Gnatbind_Path
: String_Access
:=
617 GNAT
.OS_Lib
.Locate_Exec_On_Path
(Gnatbind
.all);
618 Gnatlink_Path
: String_Access
:=
619 GNAT
.OS_Lib
.Locate_Exec_On_Path
(Gnatlink
.all);
620 -- Path for compiler, binder, linker programs, defaulted now for gnatdist.
621 -- Changed later if overridden on command line.
623 Comp_Flag
: constant String_Access
:= new String'("-c");
624 Output_Flag : constant String_Access := new String'("-o");
625 Ada_Flag_1
: constant String_Access
:= new String'("-x");
626 Ada_Flag_2 : constant String_Access := new String'("ada");
627 No_gnat_adc
: constant String_Access
:= new String'("-gnatA");
628 GNAT_Flag : constant String_Access := new String'("-gnatpg");
629 Do_Not_Check_Flag
: constant String_Access
:= new String'("-x");
631 Object_Suffix : constant String := Get_Target_Object_Suffix.all;
632 Executable_Suffix : constant String := Get_Target_Executable_Suffix.all;
634 Syntax_Only : Boolean := False;
635 -- Set to True when compiling with -gnats
637 Display_Executed_Programs : Boolean := True;
638 -- Set to True if name of commands should be output on stderr
640 Output_File_Name_Seen : Boolean := False;
641 -- Set to True after having scanned the file_name for
642 -- switch "-o file_name"
644 Object_Directory_Seen : Boolean := False;
645 -- Set to True after having scanned the object directory for
646 -- switch "-D obj_dir".
648 Object_Directory_Path : String_Access := null;
649 -- The path name of the object directory, set with switch -D
651 type Make_Program_Type is (None, Compiler, Binder, Linker);
653 Program_Args : Make_Program_Type := None;
654 -- Used to indicate if we are scanning gnatmake, gcc, gnatbind, or gnatbind
655 -- options within the gnatmake command line. Used in Scan_Make_Arg only,
656 -- but must be global since value preserved from one call to another.
658 Temporary_Config_File : Boolean := False;
659 -- Set to True when there is a temporary config file used for a project
660 -- file, to avoid displaying the -gnatec switch for a temporary file.
662 procedure Add_Switches
663 (The_Package : Package_Id;
666 Program : Make_Program_Type);
669 Program : Make_Program_Type;
670 Append_Switch : Boolean := True;
671 And_Save : Boolean := True);
674 Program : Make_Program_Type;
675 Append_Switch : Boolean := True;
676 And_Save : Boolean := True);
677 -- Make invokes one of three programs (the compiler, the binder or the
678 -- linker). For the sake of convenience, some program specific switches
679 -- can be passed directly on the gnatmake commande line. This procedure
680 -- records these switches so that gnamake can pass them to the right
681 -- program. S is the switch to be added at the end of the command line
682 -- for Program if Append_Switch is True. If Append_Switch is False S is
683 -- added at the beginning of the command line.
686 (Source_File : File_Name_Type;
688 The_Args : Argument_List;
689 Lib_File : File_Name_Type;
692 O_File : out File_Name_Type;
693 O_Stamp : out Time_Stamp_Type);
694 -- Determines whether the library file Lib_File is up-to-date or not. The
695 -- full name (with path information) of the object file corresponding to
696 -- Lib_File is returned in O_File. Its time stamp is saved in O_Stamp.
697 -- ALI is the ALI_Id corresponding to Lib_File. If Lib_File in not
698 -- up-to-date, then the corresponding source file needs to be recompiled.
699 -- In this case ALI = No_ALI_Id.
701 procedure Check_Linker_Options
702 (E_Stamp : Time_Stamp_Type;
703 O_File : out File_Name_Type;
704 O_Stamp : out Time_Stamp_Type);
705 -- Checks all linker options for linker files that are newer
706 -- than E_Stamp. If such objects are found, the youngest object
707 -- is returned in O_File and its stamp in O_Stamp.
709 -- If no obsolete linker files were found, the first missing
710 -- linker file is returned in O_File and O_Stamp is empty.
711 -- Otherwise O_File is No_File.
713 procedure Collect_Arguments
714 (Source_File : File_Name_Type;
716 Args : Argument_List);
717 -- Collect all arguments for a source to be compiled, including those
718 -- that come from a project file.
720 procedure Display (Program : String; Args : Argument_List);
721 -- Displays Program followed by the arguments in Args if variable
722 -- Display_Executed_Programs is set. The lower bound of Args must be 1.
728 type Temp_File_Names is
729 array (Project_Id range <>, Positive range <>) of Name_Id;
731 type Temp_Files_Ptr is access Temp_File_Names;
733 type Indices is array (Project_Id range <>) of Natural;
735 type Indices_Ptr is access Indices;
737 type Free_File_Indices is array
738 (Project_Id range <>, Positive range <>) of Positive;
740 type Free_Indices_Ptr is access Free_File_Indices;
742 The_Mapping_File_Names : Temp_Files_Ptr;
743 -- For each project, the name ids of the temporary mapping files used
745 Last_Mapping_File_Names : Indices_Ptr;
746 -- For each project, the index of the last mapping file created
748 The_Free_Mapping_File_Indices : Free_Indices_Ptr;
749 -- For each project, the indices in The_Mapping_File_Names of the mapping
750 -- file names that can be reused for subsequent compilations.
752 Last_Free_Indices : Indices_Ptr;
753 -- For each project, the number of mapping files that can be reused
755 Gnatmake_Mapping_File : String_Access := null;
756 -- The path name of a mapping file specified by switch -C=
758 procedure Delete_Mapping_Files;
759 -- Delete all temporary mapping files
761 procedure Init_Mapping_File
762 (Project : Project_Id;
763 File_Index : in out Natural);
764 -- Create a new temporary mapping file, and fill it with the project file
765 -- mappings, when using project file(s). The out parameter File_Index is
766 -- the index to the name of the file in the array The_Mapping_File_Names.
768 procedure Delete_Temp_Config_Files;
769 -- Delete all temporary config files
771 procedure Delete_All_Temp_Files;
772 -- Delete all temp files (config files, mapping files, path files)
778 procedure Add_Arguments (Args : Argument_List) is
780 if Arguments = null then
781 Arguments := new Argument_List (1 .. Args'Length + 10);
784 while Last_Argument + Args'Length > Arguments'Last loop
786 New_Arguments : constant Argument_List_Access :=
787 new Argument_List (1 .. Arguments'Last * 2);
789 New_Arguments (1 .. Last_Argument) :=
790 Arguments (1 .. Last_Argument);
791 Arguments := New_Arguments;
796 Arguments (Last_Argument + 1 .. Last_Argument + Args'Length) := Args;
797 Last_Argument := Last_Argument + Args'Length;
804 procedure Add_Dependency (S : Name_Id; On : Name_Id) is
806 Dependencies.Increment_Last;
807 Dependencies.Table (Dependencies.Last) := (S, On);
810 ----------------------------
811 -- Add_Library_Search_Dir --
812 ----------------------------
814 procedure Add_Library_Search_Dir
816 On_Command_Line : Boolean)
819 if On_Command_Line then
821 (Normalize_Pathname (Path));
825 (Project_Tree.Projects.Table (Main_Project).Directory);
828 (Path, Name_Buffer (1 .. Name_Len)));
830 end Add_Library_Search_Dir;
836 procedure Add_Object_Dir (N : String) is
838 Add_Lib_Search_Dir (N);
841 Write_Str ("Adding object directory """);
852 procedure Add_Source_Dir (N : String) is
854 Add_Src_Search_Dir (N);
857 Write_Str ("Adding source directory """);
864 ---------------------------
865 -- Add_Source_Search_Dir --
866 ---------------------------
868 procedure Add_Source_Search_Dir
870 On_Command_Line : Boolean)
873 if On_Command_Line then
875 (Normalize_Pathname (Path));
879 (Project_Tree.Projects.Table (Main_Project).Directory);
882 (Path, Name_Buffer (1 .. Name_Len)));
884 end Add_Source_Search_Dir;
892 Program : Make_Program_Type;
893 Append_Switch : Boolean := True;
894 And_Save : Boolean := True)
897 with package T is new Table.Table (<>);
898 procedure Generic_Position (New_Position : out Integer);
899 -- Generic procedure that chooses a position for S in T at the
900 -- beginning or the end, depending on the boolean Append_Switch.
901 -- Calling this procedure may expand the table.
903 ----------------------
904 -- Generic_Position --
905 ----------------------
907 procedure Generic_Position (New_Position : out Integer) is
911 if Append_Switch then
912 New_Position := Integer (T.Last);
914 for J in reverse T.Table_Index_Type'Succ (T.First) .. T.Last loop
915 T.Table (J) := T.Table (T.Table_Index_Type'Pred (J));
918 New_Position := Integer (T.First);
920 end Generic_Position;
922 procedure Gcc_Switches_Pos is new Generic_Position (Gcc_Switches);
923 procedure Binder_Switches_Pos is new Generic_Position (Binder_Switches);
924 procedure Linker_Switches_Pos is new Generic_Position (Linker_Switches);
926 procedure Saved_Gcc_Switches_Pos is new
927 Generic_Position (Saved_Gcc_Switches);
929 procedure Saved_Binder_Switches_Pos is new
930 Generic_Position (Saved_Binder_Switches);
932 procedure Saved_Linker_Switches_Pos is new
933 Generic_Position (Saved_Linker_Switches);
935 New_Position : Integer;
937 -- Start of processing for Add_Switch
943 Saved_Gcc_Switches_Pos (New_Position);
944 Saved_Gcc_Switches.Table (New_Position) := S;
947 Saved_Binder_Switches_Pos (New_Position);
948 Saved_Binder_Switches.Table (New_Position) := S;
951 Saved_Linker_Switches_Pos (New_Position);
952 Saved_Linker_Switches.Table (New_Position) := S;
961 Gcc_Switches_Pos (New_Position);
962 Gcc_Switches.Table (New_Position) := S;
965 Binder_Switches_Pos (New_Position);
966 Binder_Switches.Table (New_Position) := S;
969 Linker_Switches_Pos (New_Position);
970 Linker_Switches.Table (New_Position) := S;
980 Program : Make_Program_Type;
981 Append_Switch : Boolean := True;
982 And_Save : Boolean := True)
985 Add_Switch (S => new String'(S
),
987 Append_Switch
=> Append_Switch
,
988 And_Save
=> And_Save
);
995 procedure Add_Switches
996 (The_Package
: Package_Id
;
999 Program
: Make_Program_Type
)
1001 Switches
: Variable_Value
;
1002 Switch_List
: String_List_Id
;
1003 Element
: String_Element
;
1006 if File_Name
'Length > 0 then
1007 Name_Len
:= File_Name
'Length;
1008 Name_Buffer
(1 .. Name_Len
) := File_Name
;
1011 (Source_File
=> Name_Find
,
1012 Source_File_Name
=> File_Name
,
1013 Source_Index
=> Index
,
1014 Naming
=> Project_Tree
.Projects
.Table
1015 (Main_Project
).Naming
,
1016 In_Package
=> The_Package
,
1018 Program
= Binder
or else Program
= Linker
);
1020 case Switches
.Kind
is
1025 Program_Args
:= Program
;
1027 Switch_List
:= Switches
.Values
;
1029 while Switch_List
/= Nil_String
loop
1031 Project_Tree
.String_Elements
.Table
(Switch_List
);
1032 Get_Name_String
(Element
.Value
);
1034 if Name_Len
> 0 then
1036 Argv
: constant String := Name_Buffer
(1 .. Name_Len
);
1037 -- We need a copy, because Name_Buffer may be modified
1040 if Verbose_Mode
then
1041 Write_Str
(" Adding ");
1045 Scan_Make_Arg
(Argv
, And_Save
=> False);
1049 Switch_List
:= Element
.Next
;
1053 Program_Args
:= Program
;
1054 Get_Name_String
(Switches
.Value
);
1056 if Name_Len
> 0 then
1058 Argv
: constant String := Name_Buffer
(1 .. Name_Len
);
1059 -- We need a copy, because Name_Buffer may be modified
1062 if Verbose_Mode
then
1063 Write_Str
(" Adding ");
1067 Scan_Make_Arg
(Argv
, And_Save
=> False);
1078 procedure Bind
(ALI_File
: File_Name_Type
; Args
: Argument_List
) is
1079 Bind_Args
: Argument_List
(1 .. Args
'Last + 2);
1080 Bind_Last
: Integer;
1084 pragma Assert
(Args
'First = 1);
1086 -- Optimize the simple case where the gnatbind command line looks like
1087 -- gnatbind -aO. -I- file.ali --into-> gnatbind file.adb
1090 and then Args
(Args
'First).all = "-aO" & Normalized_CWD
1091 and then Args
(Args
'Last).all = "-I-"
1092 and then ALI_File
= Strip_Directory
(ALI_File
)
1094 Bind_Last
:= Args
'First - 1;
1097 Bind_Last
:= Args
'Last;
1098 Bind_Args
(Args
'Range) := Args
;
1101 -- It is completely pointless to re-check source file time stamps. This
1102 -- has been done already by gnatmake
1104 Bind_Last
:= Bind_Last
+ 1;
1105 Bind_Args
(Bind_Last
) := Do_Not_Check_Flag
;
1107 Get_Name_String
(ALI_File
);
1109 Bind_Last
:= Bind_Last
+ 1;
1110 Bind_Args
(Bind_Last
) := new String'(Name_Buffer (1 .. Name_Len));
1112 GNAT.OS_Lib.Normalize_Arguments (Bind_Args (Args'First .. Bind_Last));
1114 Display (Gnatbind.all, Bind_Args (Args'First .. Bind_Last));
1116 if Gnatbind_Path = null then
1117 Make_Failed ("error, unable to locate ", Gnatbind.all);
1121 (Gnatbind_Path.all, Bind_Args (Args'First .. Bind_Last), Success);
1128 --------------------------------
1129 -- Change_To_Object_Directory --
1130 --------------------------------
1132 procedure Change_To_Object_Directory (Project : Project_Id) is
1133 Actual_Project : Project_Id;
1136 -- For sources outside of any project, compilation occurs in the object
1137 -- directory of the main project, otherwise we use the project given.
1139 if Project = No_Project then
1140 Actual_Project := Main_Project;
1142 Actual_Project := Project;
1145 -- Nothing to do if the current working directory is already the correct
1146 -- object directory.
1148 if Project_Object_Directory /= Actual_Project then
1149 Project_Object_Directory := Actual_Project;
1151 -- Set the working directory to the object directory of the actual
1156 (Project_Tree.Projects.Table
1157 (Actual_Project).Object_Directory));
1162 -- Fail if unable to change to the object directory
1164 when Directory_Error =>
1165 Make_Failed ("unable to change to object directory """ &
1167 (Project_Tree.Projects.Table
1168 (Actual_Project).Object_Directory) &
1170 Get_Name_String (Project_Tree.Projects.Table
1171 (Actual_Project).Display_Name));
1172 end Change_To_Object_Directory;
1179 (Source_File : File_Name_Type;
1181 The_Args : Argument_List;
1182 Lib_File : File_Name_Type;
1183 Read_Only : Boolean;
1185 O_File : out File_Name_Type;
1186 O_Stamp : out Time_Stamp_Type)
1188 function First_New_Spec (A : ALI_Id) return File_Name_Type;
1189 -- Looks in the with table entries of A and returns the spec file name
1190 -- of the first withed unit (subprogram) for which no spec existed when
1191 -- A was generated but for which there exists one now, implying that A
1192 -- is now obsolete. If no such unit is found No_File is returned.
1193 -- Otherwise the spec file name of the unit is returned.
1195 -- **WARNING** in the event of Uname format modifications, one *MUST*
1196 -- make sure this function is also updated.
1198 -- Note: This function should really be in ali.adb and use Uname
1199 -- services, but this causes the whole compiler to be dragged along
1200 -- for gnatbind and gnatmake.
1202 --------------------
1203 -- First_New_Spec --
1204 --------------------
1206 function First_New_Spec (A : ALI_Id) return File_Name_Type is
1207 Spec_File_Name : File_Name_Type := No_File;
1209 function New_Spec (Uname : Unit_Name_Type) return Boolean;
1210 -- Uname is the name of the spec or body of some ada unit. This
1211 -- function returns True if the Uname is the name of a body which has
1212 -- a spec not mentioned inali file A. If True is returned
1213 -- Spec_File_Name above is set to the name of this spec file.
1219 function New_Spec (Uname : Unit_Name_Type) return Boolean is
1220 Spec_Name : Unit_Name_Type;
1221 File_Name : File_Name_Type;
1224 -- Test whether Uname is the name of a body unit (ie ends with %b)
1226 Get_Name_String (Uname);
1228 Assert (Name_Len > 2 and then Name_Buffer (Name_Len - 1) = '%');
1230 if Name_Buffer (Name_Len) /= 'b
' then
1234 -- Convert unit name into spec name
1236 -- ??? this code seems dubious in presence of pragma
1237 -- Source_File_Name since there is no more direct relationship
1238 -- between unit name and file name.
1240 -- ??? Further, what about alternative subunit naming
1242 Name_Buffer (Name_Len) := 's
';
1243 Spec_Name := Name_Find;
1244 File_Name := Get_File_Name (Spec_Name, Subunit => False);
1246 -- Look if File_Name is mentioned in A's sdep list.
1247 -- If not look if the file exists. If it does return True.
1250 ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep
1252 if Sdep.Table (D).Sfile = File_Name then
1257 if Full_Source_Name (File_Name) /= No_File then
1258 Spec_File_Name := File_Name;
1265 -- Start of processing for First_New_Spec
1269 ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit
1271 exit U_Chk when Units.Table (U).Utype = Is_Body_Only
1272 and then New_Spec (Units.Table (U).Uname);
1274 for W in Units.Table (U).First_With
1276 Units.Table (U).Last_With
1279 Withs.Table (W).Afile /= No_File
1280 and then New_Spec (Withs.Table (W).Uname);
1284 return Spec_File_Name;
1287 ---------------------------------
1288 -- Data declarations for Check --
1289 ---------------------------------
1291 Full_Lib_File : File_Name_Type;
1292 -- Full name of current library file
1294 Full_Obj_File : File_Name_Type;
1295 -- Full name of the object file corresponding to Lib_File
1297 Lib_Stamp : Time_Stamp_Type;
1298 -- Time stamp of the current ada library file
1300 Obj_Stamp : Time_Stamp_Type;
1301 -- Time stamp of the current object file
1303 Modified_Source : File_Name_Type;
1304 -- The first source in Lib_File whose current time stamp differs
1305 -- from that stored in Lib_File.
1307 New_Spec : File_Name_Type;
1308 -- If Lib_File contains in its W (with) section a body (for a
1309 -- subprogram) for which there exists a spec and the spec did not
1310 -- appear in the Sdep section of Lib_File, New_Spec contains the file
1311 -- name of this new spec.
1313 Source_Name : Name_Id;
1314 Text : Text_Buffer_Ptr;
1316 Prev_Switch : String_Access;
1317 -- Previous switch processed
1319 Arg : Arg_Id := Arg_Id'First;
1320 -- Current index in Args.Table for a given unit (init to stop warning)
1322 Switch_Found : Boolean;
1323 -- True if a given switch has been found
1325 -- Start of processing for Check
1328 pragma Assert (Lib_File /= No_File);
1330 -- If ALI file is read-only, temporarily set Check_Object_Consistency to
1331 -- False. We don't care if the object file is not there (presumably a
1332 -- library will be used for linking.)
1336 Saved_Check_Object_Consistency : constant Boolean :=
1337 Check_Object_Consistency;
1339 Check_Object_Consistency := False;
1340 Text := Read_Library_Info (Lib_File);
1341 Check_Object_Consistency := Saved_Check_Object_Consistency;
1345 Text := Read_Library_Info (Lib_File);
1348 Full_Lib_File := Full_Library_Info_Name;
1349 Full_Obj_File := Full_Object_File_Name;
1350 Lib_Stamp := Current_Library_File_Stamp;
1351 Obj_Stamp := Current_Object_File_Stamp;
1353 if Full_Lib_File = No_File then
1356 "being checked ...",
1358 Minimum_Verbosity => Opt.Medium);
1362 "being checked ...",
1364 Minimum_Verbosity => Opt.Medium);
1368 O_File := Full_Obj_File;
1369 O_Stamp := Obj_Stamp;
1372 if Full_Lib_File = No_File then
1373 Verbose_Msg (Lib_File, "missing.");
1375 elsif Obj_Stamp (Obj_Stamp'First) = ' ' then
1376 Verbose_Msg (Full_Obj_File, "missing.");
1380 (Full_Lib_File, "(" & String (Lib_Stamp) & ") newer than",
1381 Full_Obj_File, "(" & String (Obj_Stamp) & ")");
1385 ALI := Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
1388 if ALI = No_ALI_Id then
1389 Verbose_Msg (Full_Lib_File, "incorrectly formatted ALI file");
1392 elsif ALIs.Table (ALI).Ver (1 .. ALIs.Table (ALI).Ver_Len) /=
1393 Verbose_Library_Version
1395 Verbose_Msg (Full_Lib_File, "compiled with old GNAT version");
1400 -- Don't take Ali file into account if it was generated with
1403 if ALIs.Table (ALI).Compile_Errors then
1404 Verbose_Msg (Full_Lib_File, "had errors, must be recompiled");
1409 -- Don't take Ali file into account if it was generated without
1412 if Operating_Mode /= Check_Semantics
1413 and then ALIs.Table (ALI).No_Object
1415 Verbose_Msg (Full_Lib_File, "has no corresponding object");
1420 -- Check for matching compiler switches if needed
1422 if Check_Switches then
1424 -- First, collect all the switches
1426 Collect_Arguments (Source_File, Source_Index, The_Args);
1428 Prev_Switch := Dummy_Switch;
1430 Get_Name_String (ALIs.Table (ALI).Sfile);
1432 Switches_To_Check.Set_Last (0);
1434 for J in 1 .. Last_Argument loop
1436 -- Skip non switches -c, -I and -o switches
1438 if Arguments (J) (1) = '-'
1439 and then Arguments (J) (2) /= 'c
'
1440 and then Arguments (J) (2) /= 'o
'
1441 and then Arguments (J) (2) /= 'I
'
1443 Normalize_Compiler_Switches
1445 Normalized_Switches,
1448 for K in 1 .. Last_Norm_Switch loop
1449 Switches_To_Check.Increment_Last;
1450 Switches_To_Check.Table (Switches_To_Check.Last) :=
1451 Normalized_Switches (K);
1456 for J in 1 .. Switches_To_Check.Last loop
1458 -- Comparing switches is delicate because gcc reorders a number
1459 -- of switches, according to lang-specs.h, but gnatmake doesn't
1460 -- have the sufficient knowledge to perform the same
1461 -- reordering. Instead, we ignore orders between different
1462 -- "first letter" switches, but keep orders between same
1463 -- switches, e.g -O -O2 is different than -O2 -O, but -g -O is
1464 -- equivalent to -O -g.
1466 if Switches_To_Check.Table (J) (2) /= Prev_Switch (2) or else
1467 (Prev_Switch'Length >= 6 and then
1468 Prev_Switch (2 .. 5) = "gnat" and then
1469 Switches_To_Check.Table (J)'Length >= 6 and then
1470 Switches_To_Check.Table (J) (2 .. 5) = "gnat" and then
1471 Prev_Switch (6) /= Switches_To_Check.Table (J) (6))
1473 Prev_Switch := Switches_To_Check.Table (J);
1475 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg;
1478 Switch_Found := False;
1481 Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1484 Switches_To_Check.Table (J).all = Args.Table (K).all
1487 Switch_Found := True;
1492 if not Switch_Found then
1493 if Verbose_Mode then
1494 Verbose_Msg (ALIs.Table (ALI).Sfile,
1495 "switch mismatch """ &
1496 Switches_To_Check.Table (J).all & '"');
1504 if Switches_To_Check.Last /=
1505 Integer (Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg -
1506 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg + 1)
1508 if Verbose_Mode then
1509 Verbose_Msg (ALIs.Table (ALI).Sfile,
1510 "different number
of switches
");
1512 for K in Units.Table (ALIs.Table (ALI).First_Unit).First_Arg
1513 .. Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1515 Write_Str (Args.Table (K).all);
1521 for J in 1 .. Switches_To_Check.Last loop
1522 Write_Str (Switches_To_Check.Table (J).all);
1534 -- Get the source files and their message digests. Note that some
1535 -- sources may be missing if ALI is out-of-date.
1537 Set_Source_Table (ALI);
1539 Modified_Source := Time_Stamp_Mismatch (ALI, Read_Only);
1541 if Modified_Source /= No_File then
1544 if Verbose_Mode then
1545 Source_Name := Full_Source_Name (Modified_Source);
1547 if Source_Name /= No_File then
1548 Verbose_Msg (Source_Name, "time stamp mismatch
");
1550 Verbose_Msg (Modified_Source, "missing
");
1555 New_Spec := First_New_Spec (ALI);
1557 if New_Spec /= No_File then
1560 if Verbose_Mode then
1561 Source_Name := Full_Source_Name (New_Spec);
1563 if Source_Name /= No_File then
1564 Verbose_Msg (Source_Name, "new spec
");
1566 Verbose_Msg (New_Spec, "old spec missing
");
1574 ------------------------
1575 -- Check_For_S_Switch --
1576 ------------------------
1578 procedure Check_For_S_Switch is
1580 -- By default, we generate an object file
1582 Output_Is_Object := True;
1584 for Arg in 1 .. Last_Argument loop
1585 if Arguments (Arg).all = "-S
" then
1586 Output_Is_Object := False;
1588 elsif Arguments (Arg).all = "-c
" then
1589 Output_Is_Object := True;
1592 end Check_For_S_Switch;
1594 --------------------------
1595 -- Check_Linker_Options --
1596 --------------------------
1598 procedure Check_Linker_Options
1599 (E_Stamp : Time_Stamp_Type;
1600 O_File : out File_Name_Type;
1601 O_Stamp : out Time_Stamp_Type)
1603 procedure Check_File (File : File_Name_Type);
1604 -- Update O_File and O_Stamp if the given file is younger than E_Stamp
1605 -- and O_Stamp, or if O_File is No_File and File does not exist.
1607 function Get_Library_File (Name : String) return File_Name_Type;
1608 -- Return the full file name including path of a library based
1609 -- on the name specified with the -l linker option, using the
1610 -- Ada object path. Return No_File if no such file can be found.
1612 type Char_Array is array (Natural) of Character;
1613 type Char_Array_Access is access constant Char_Array;
1615 Template : Char_Array_Access;
1616 pragma Import (C, Template, "__gnat_library_template
");
1622 procedure Check_File (File : File_Name_Type) is
1623 Stamp : Time_Stamp_Type;
1624 Name : File_Name_Type := File;
1627 Get_Name_String (Name);
1629 -- Remove any trailing NUL characters
1631 while Name_Len >= Name_Buffer'First
1632 and then Name_Buffer (Name_Len) = NUL
1634 Name_Len := Name_Len - 1;
1637 if Name_Len = 0 then
1640 elsif Name_Buffer (1) = '-' then
1642 -- Do not check if File is a switch other than "-l
"
1644 if Name_Buffer (2) /= 'l' then
1648 -- The argument is a library switch, get actual name. It
1649 -- is necessary to make a copy of the relevant part of
1650 -- Name_Buffer as Get_Library_Name uses Name_Buffer as well.
1653 Base_Name : constant String := Name_Buffer (3 .. Name_Len);
1656 Name := Get_Library_File (Base_Name);
1659 if Name = No_File then
1664 Stamp := File_Stamp (Name);
1666 -- Find the youngest object file that is younger than the
1667 -- executable. If no such file exist, record the first object
1668 -- file that is not found.
1670 if (O_Stamp < Stamp and then E_Stamp < Stamp)
1671 or else (O_File = No_File and then Stamp (Stamp'First) = ' ')
1676 -- Strip the trailing NUL if present
1678 Get_Name_String (O_File);
1680 if Name_Buffer (Name_Len) = NUL then
1681 Name_Len := Name_Len - 1;
1682 O_File := Name_Find;
1687 ----------------------
1688 -- Get_Library_Name --
1689 ----------------------
1691 -- See comments in a-adaint.c about template syntax
1693 function Get_Library_File (Name : String) return File_Name_Type is
1694 File : File_Name_Type := No_File;
1699 for Ptr in Template'Range loop
1700 case Template (Ptr) is
1702 Add_Str_To_Name_Buffer (Name);
1705 File := Full_Lib_File_Name (Name_Find);
1706 exit when File /= No_File;
1713 Add_Char_To_Name_Buffer (Template (Ptr));
1717 -- The for loop exited because the end of the template
1718 -- was reached. File contains the last possible file name
1721 if File = No_File and then Name_Len > 0 then
1722 File := Full_Lib_File_Name (Name_Find);
1726 end Get_Library_File;
1728 -- Start of processing for Check_Linker_Options
1732 O_Stamp := (others => ' ');
1734 -- Process linker options from the ALI files
1736 for Opt in 1 .. Linker_Options.Last loop
1737 Check_File (Linker_Options.Table (Opt).Name);
1740 -- Process options given on the command line
1742 for Opt in Linker_Switches.First .. Linker_Switches.Last loop
1744 -- Check if the previous Opt has one of the two switches
1745 -- that take an extra parameter. (See GCC manual.)
1747 if Opt = Linker_Switches.First
1748 or else (Linker_Switches.Table (Opt - 1).all /= "-u
"
1750 Linker_Switches.Table (Opt - 1).all /= "-Xlinker
"
1752 Linker_Switches.Table (Opt - 1).all /= "-L
")
1755 Add_Str_To_Name_Buffer (Linker_Switches.Table (Opt).all);
1756 Check_File (Name_Find);
1760 end Check_Linker_Options;
1766 procedure Check_Steps is
1768 -- If either -c, -b or -l has been specified, we will not necessarily
1769 -- execute all steps.
1772 Do_Compile_Step := Do_Compile_Step and Compile_Only;
1773 Do_Bind_Step := Do_Bind_Step and Bind_Only;
1774 Do_Link_Step := Do_Link_Step and Link_Only;
1776 -- If -c has been specified, but not -b, ignore any potential -l
1778 if Do_Compile_Step and then not Do_Bind_Step then
1779 Do_Link_Step := False;
1784 -----------------------
1785 -- Collect_Arguments --
1786 -----------------------
1788 procedure Collect_Arguments
1789 (Source_File : File_Name_Type;
1791 Args : Argument_List)
1794 Arguments_Collected := True;
1795 Arguments_Project := No_Project;
1797 Add_Arguments (Args);
1799 if Main_Project /= No_Project then
1801 Source_File_Name : constant String :=
1802 Get_Name_String (Source_File);
1803 Compiler_Package : Prj.Package_Id;
1804 Switches : Prj.Variable_Value;
1805 Data : Project_Data;
1810 (Source_File_Name => Source_File_Name,
1811 Project => Arguments_Project,
1812 Path => Arguments_Path_Name,
1813 In_Tree => Project_Tree);
1815 -- If the source is not a source of a project file, check if
1818 if Arguments_Project = No_Project then
1819 if not External_Unit_Compilation_Allowed then
1820 Make_Failed ("external source
(", Source_File_Name,
1821 ") is not part
of any project
; cannot be
" &
1822 "compiled without gnatmake switch
-x
");
1825 -- If it is allowed, simply add the saved gcc switches
1827 Add_Arguments (The_Saved_Gcc_Switches.all);
1830 -- We get the project directory for the relative path
1831 -- switches and arguments.
1833 Data := Project_Tree.Projects.Table (Arguments_Project);
1835 -- If the source is in an extended project, we go to
1836 -- the ultimate extending project.
1838 while Data.Extended_By /= No_Project loop
1839 Arguments_Project := Data.Extended_By;
1841 Project_Tree.Projects.Table (Arguments_Project);
1844 -- If building a dynamic or relocatable library, compile with
1845 -- PIC option, if it exists.
1847 if Data.Library and then Data.Library_Kind /= Static then
1849 PIC : constant String := MLib.Tgt.PIC_Option;
1853 Add_Arguments ((1 => new String'(PIC)));
1858 if Data.Dir_Path = null then
1860 new String'(Get_Name_String (Data.Display_Directory));
1861 Project_Tree.Projects.Table (Arguments_Project) :=
1865 -- We now look for package Compiler
1866 -- and get the switches from this package.
1870 (Name => Name_Compiler,
1871 In_Packages => Data.Decl.Packages,
1872 In_Tree => Project_Tree);
1874 if Compiler_Package /= No_Package then
1876 -- If package Gnatmake.Compiler exists, we get
1877 -- the specific switches for the current source,
1878 -- or the global switches, if any.
1880 Switches := Switches_Of
1881 (Source_File => Source_File,
1882 Source_File_Name => Source_File_Name,
1883 Source_Index => Source_Index,
1884 Naming => Data.Naming,
1885 In_Package => Compiler_Package,
1886 Allow_ALI => False);
1890 case Switches.Kind is
1892 -- We have a list of switches. We add these switches,
1893 -- plus the saved gcc switches.
1898 Current : String_List_Id := Switches.Values;
1899 Element : String_Element;
1900 Number : Natural := 0;
1903 while Current /= Nil_String loop
1904 Element := Project_Tree.String_Elements.
1906 Number := Number + 1;
1907 Current := Element.Next;
1911 New_Args : Argument_List (1 .. Number);
1912 Last_New : Natural := 0;
1915 Current := Switches.Values;
1917 for Index in New_Args'Range loop
1918 Element := Project_Tree.String_Elements.
1920 Get_Name_String (Element.Value);
1922 if Name_Len > 0 then
1923 Last_New := Last_New + 1;
1924 New_Args (Last_New) :=
1925 new String'(Name_Buffer (1 .. Name_Len));
1926 Test_If_Relative_Path
1927 (New_Args (Last_New),
1928 Parent => Data.Dir_Path);
1931 Current := Element.Next;
1935 (Configuration_Pragmas_Switch
1936 (Arguments_Project) &
1937 New_Args (1 .. Last_New) &
1938 The_Saved_Gcc_Switches.all);
1942 -- We have a single switch. We add this switch,
1943 -- plus the saved gcc switches.
1946 Get_Name_String (Switches.Value);
1949 New_Args : Argument_List :=
1951 (Name_Buffer (1 .. Name_Len)));
1954 Test_If_Relative_Path
1955 (New_Args (1), Parent => Data.Dir_Path);
1957 (Configuration_Pragmas_Switch (Arguments_Project) &
1958 New_Args & The_Saved_Gcc_Switches.all);
1961 -- We have no switches from Gnatmake.Compiler.
1962 -- We add the saved gcc switches.
1966 (Configuration_Pragmas_Switch (Arguments_Project) &
1967 The_Saved_Gcc_Switches.all);
1973 -- Set Output_Is_Object, depending if there is a -S switch.
1974 -- If the bind step is not performed, and there is a -S switch,
1975 -- then we will not check for a valid object file.
1978 end Collect_Arguments;
1980 ---------------------
1981 -- Compile_Sources --
1982 ---------------------
1984 procedure Compile_Sources
1985 (Main_Source : File_Name_Type;
1986 Args : Argument_List;
1987 First_Compiled_File : out Name_Id;
1988 Most_Recent_Obj_File : out Name_Id;
1989 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
1990 Main_Unit : out Boolean;
1991 Compilation_Failures : out Natural;
1992 Main_Index : Int := 0;
1993 Check_Readonly_Files : Boolean := False;
1994 Do_Not_Execute : Boolean := False;
1995 Force_Compilations : Boolean := False;
1996 Keep_Going : Boolean := False;
1997 In_Place_Mode : Boolean := False;
1998 Initialize_ALI_Data : Boolean := True;
1999 Max_Process : Positive := 1)
2001 No_Mapping_File : constant Natural := 0;
2003 type Compilation_Data is record
2005 Full_Source_File : File_Name_Type;
2006 Lib_File : File_Name_Type;
2007 Source_Unit : Unit_Name_Type;
2008 Mapping_File : Natural := No_Mapping_File;
2009 Project : Project_Id := No_Project;
2010 Syntax_Only : Boolean := False;
2011 Output_Is_Object : Boolean := True;
2014 Running_Compile : array (1 .. Max_Process) of Compilation_Data;
2015 -- Used to save information about outstanding compilations
2017 Outstanding_Compiles : Natural := 0;
2018 -- Current number of outstanding compiles
2020 Source_Unit : Unit_Name_Type;
2021 -- Current source unit
2023 Source_File : File_Name_Type;
2024 -- Current source file
2026 Full_Source_File : File_Name_Type;
2027 -- Full name of the current source file
2029 Lib_File : File_Name_Type;
2030 -- Current library file
2032 Full_Lib_File : File_Name_Type;
2033 -- Full name of the current library file
2035 Obj_File : File_Name_Type;
2036 -- Full name of the object file corresponding to Lib_File
2038 Obj_Stamp : Time_Stamp_Type;
2039 -- Time stamp of the current object file
2041 Sfile : File_Name_Type;
2042 -- Contains the source file of the units withed by Source_File
2045 -- ALI Id of the current ALI file
2047 -- Comment following declarations ???
2049 Read_Only : Boolean := False;
2051 Compilation_OK : Boolean;
2052 Need_To_Compile : Boolean;
2055 Text : Text_Buffer_Ptr;
2057 Mfile : Natural := No_Mapping_File;
2059 Need_To_Check_Standard_Library : Boolean :=
2060 Check_Readonly_Files
2061 and not Unique_Compile;
2063 Mapping_File_Arg : String_Access;
2065 Process_Created : Boolean := False;
2067 procedure Add_Process
2069 Sfile : File_Name_Type;
2070 Afile : File_Name_Type;
2071 Uname : Unit_Name_Type;
2072 Mfile : Natural := No_Mapping_File);
2073 -- Adds process Pid to the current list of outstanding compilation
2074 -- processes and record the full name of the source file Sfile that
2075 -- we are compiling, the name of its library file Afile and the
2076 -- name of its unit Uname. If Mfile is not equal to No_Mapping_File,
2077 -- it is the index of the mapping file used during compilation in the
2078 -- array The_Mapping_File_Names.
2080 procedure Await_Compile
2081 (Sfile : out File_Name_Type;
2082 Afile : out File_Name_Type;
2083 Uname : out Unit_Name_Type;
2085 -- Awaits that an outstanding compilation process terminates. When
2086 -- it does set Sfile to the name of the source file that was compiled
2087 -- Afile to the name of its library file and Uname to the name of its
2088 -- unit. Note that this time stamp can be used to check whether the
2089 -- compilation did generate an object file. OK is set to True if the
2090 -- compilation succeeded. Note that Sfile, Afile and Uname could be
2091 -- resp. No_File, No_File and No_Name if there were no compilations
2094 function Bad_Compilation_Count return Natural;
2095 -- Returns the number of compilation failures
2097 procedure Check_Standard_Library;
2098 -- Check if s-stalib.adb needs to be compiled
2100 procedure Collect_Arguments_And_Compile
2101 (Source_File : File_Name_Type; Source_Index : Int);
2102 -- Collect arguments from project file (if any) and compile
2108 Args : Argument_List) return Process_Id;
2109 -- Compiles S using Args. If S is a GNAT predefined source
2110 -- "-gnatpg
" is added to Args. Non blocking call. L corresponds to the
2111 -- expected library file name. Process_Id of the process spawned to
2112 -- execute the compile.
2114 package Good_ALI is new Table.Table (
2115 Table_Component_Type => ALI_Id,
2116 Table_Index_Type => Natural,
2117 Table_Low_Bound => 1,
2118 Table_Initial => 50,
2119 Table_Increment => 100,
2120 Table_Name => "Make
.Good_ALI
");
2121 -- Contains the set of valid ALI files that have not yet been scanned
2123 function Good_ALI_Present return Boolean;
2124 -- Returns True if any ALI file was recorded in the previous set
2126 procedure Get_Mapping_File (Project : Project_Id);
2127 -- Get a mapping file name. If there is one to be reused, reuse it.
2128 -- Otherwise, create a new mapping file.
2130 function Get_Next_Good_ALI return ALI_Id;
2131 -- Returns the next good ALI_Id record
2133 procedure Record_Failure
2134 (File : File_Name_Type;
2135 Unit : Unit_Name_Type;
2136 Found : Boolean := True);
2137 -- Records in the previous table that the compilation for File failed.
2138 -- If Found is False then the compilation of File failed because we
2139 -- could not find it. Records also Unit when possible.
2141 procedure Record_Good_ALI (A : ALI_Id);
2142 -- Records in the previous set the Id of an ALI file
2148 procedure Add_Process
2150 Sfile : File_Name_Type;
2151 Afile : File_Name_Type;
2152 Uname : Unit_Name_Type;
2153 Mfile : Natural := No_Mapping_File)
2155 OC1 : constant Positive := Outstanding_Compiles + 1;
2158 pragma Assert (OC1 <= Max_Process);
2159 pragma Assert (Pid /= Invalid_Pid);
2161 Running_Compile (OC1).Pid := Pid;
2162 Running_Compile (OC1).Full_Source_File := Sfile;
2163 Running_Compile (OC1).Lib_File := Afile;
2164 Running_Compile (OC1).Source_Unit := Uname;
2165 Running_Compile (OC1).Mapping_File := Mfile;
2166 Running_Compile (OC1).Project := Arguments_Project;
2167 Running_Compile (OC1).Syntax_Only := Syntax_Only;
2168 Running_Compile (OC1).Output_Is_Object := Output_Is_Object;
2170 Outstanding_Compiles := OC1;
2173 --------------------
2177 procedure Await_Compile
2178 (Sfile : out File_Name_Type;
2179 Afile : out File_Name_Type;
2180 Uname : out File_Name_Type;
2184 Project : Project_Id;
2187 pragma Assert (Outstanding_Compiles > 0);
2194 -- The loop here is a work-around for a problem on VMS; in some
2195 -- circumstances (shared library and several executables, for
2196 -- example), there are child processes other than compilation
2197 -- processes that are received. Until this problem is resolved,
2198 -- we will ignore such processes.
2201 Wait_Process (Pid, OK);
2203 if Pid = Invalid_Pid then
2207 for J in Running_Compile'First .. Outstanding_Compiles loop
2208 if Pid = Running_Compile (J).Pid then
2209 Sfile := Running_Compile (J).Full_Source_File;
2210 Afile := Running_Compile (J).Lib_File;
2211 Uname := Running_Compile (J).Source_Unit;
2212 Syntax_Only := Running_Compile (J).Syntax_Only;
2213 Output_Is_Object := Running_Compile (J).Output_Is_Object;
2214 Project := Running_Compile (J).Project;
2216 -- If a mapping file was used by this compilation,
2217 -- get its file name for reuse by a subsequent compilation
2219 if Running_Compile (J).Mapping_File /= No_Mapping_File then
2220 Last_Free_Indices (Project) :=
2221 Last_Free_Indices (Project) + 1;
2222 The_Free_Mapping_File_Indices
2223 (Project, Last_Free_Indices (Project)) :=
2224 Running_Compile (J).Mapping_File;
2227 -- To actually remove this Pid and related info from
2228 -- Running_Compile replace its entry with the last valid
2229 -- entry in Running_Compile.
2231 if J = Outstanding_Compiles then
2235 Running_Compile (J) :=
2236 Running_Compile (Outstanding_Compiles);
2239 Outstanding_Compiles := Outstanding_Compiles - 1;
2244 -- This child process was not one of our compilation processes;
2245 -- just ignore it for now.
2247 -- raise Program_Error;
2251 ---------------------------
2252 -- Bad_Compilation_Count --
2253 ---------------------------
2255 function Bad_Compilation_Count return Natural is
2257 return Bad_Compilation.Last - Bad_Compilation.First + 1;
2258 end Bad_Compilation_Count;
2260 ----------------------------
2261 -- Check_Standard_Library --
2262 ----------------------------
2264 procedure Check_Standard_Library is
2266 Need_To_Check_Standard_Library := False;
2268 if not Targparm.Suppress_Standard_Library_On_Target then
2271 Add_It : Boolean := True;
2274 Name_Len := Standard_Library_Package_Body_Name'Length;
2275 Name_Buffer (1 .. Name_Len) :=
2276 Standard_Library_Package_Body_Name;
2277 Sfile := Name_Enter;
2279 -- If we have a special runtime, we add the standard
2280 -- library only if we can find it.
2284 Find_File (Sfile, Osint.Source) /= No_File;
2288 if Is_Marked (Sfile) then
2289 if Is_In_Obsoleted (Sfile) then
2290 Executable_Obsolete := True;
2294 Insert_Q (Sfile, Index => 0);
2295 Mark (Sfile, Index => 0);
2300 end Check_Standard_Library;
2302 -----------------------------------
2303 -- Collect_Arguments_And_Compile --
2304 -----------------------------------
2306 procedure Collect_Arguments_And_Compile
2307 (Source_File : File_Name_Type; Source_Index : Int)
2310 -- Process_Created will be set True if an attempt is made to compile
2311 -- the source, that is if it is not in an externally built project.
2313 Process_Created := False;
2315 -- If arguments not yet collected (in Check), collect them now
2317 if not Arguments_Collected then
2318 Collect_Arguments (Source_File, Source_Index, Args);
2321 -- If we use mapping file (-P or -C switches), then get one
2323 if Create_Mapping_File then
2324 Get_Mapping_File (Arguments_Project);
2327 -- If the source is part of a project file, we set the ADA_*_PATHs,
2328 -- check for an eventual library project, and use the full path.
2330 if Arguments_Project /= No_Project then
2331 if not Project_Tree.Projects.Table
2332 (Arguments_Project).Externally_Built
2334 Prj.Env.Set_Ada_Paths
2335 (Arguments_Project, Project_Tree, True);
2337 if not Unique_Compile
2338 and then MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None
2341 The_Data : Project_Data :=
2342 Project_Tree.Projects.Table
2343 (Arguments_Project);
2345 Prj : Project_Id := Arguments_Project;
2348 while The_Data.Extended_By /= No_Project loop
2349 Prj := The_Data.Extended_By;
2350 The_Data := Project_Tree.Projects.Table (Prj);
2354 and then not The_Data.Need_To_Build_Lib
2356 -- Add to the Q all sources of the project that
2357 -- have not been marked
2359 Insert_Project_Sources
2360 (The_Project => Prj,
2361 All_Projects => False,
2364 -- Now mark the project as processed
2366 Project_Tree.Projects.Table
2367 (Prj).Need_To_Build_Lib := True;
2372 -- Change to the object directory of the project file,
2375 Change_To_Object_Directory (Arguments_Project);
2377 Pid := Compile (Arguments_Path_Name, Lib_File, Source_Index,
2378 Arguments (1 .. Last_Argument));
2379 Process_Created := True;
2383 -- If this is a source outside of any project file, make sure it
2384 -- will be compiled in object directory of the main project file.
2386 if Main_Project /= No_Project then
2387 Change_To_Object_Directory (Arguments_Project);
2390 Pid := Compile (Full_Source_File, Lib_File, Source_Index,
2391 Arguments (1 .. Last_Argument));
2392 Process_Created := True;
2394 end Collect_Arguments_And_Compile;
2404 Args : Argument_List) return Process_Id
2406 Comp_Args : Argument_List (Args'First .. Args'Last + 9);
2407 Comp_Next : Integer := Args'First;
2408 Comp_Last : Integer;
2409 Arg_Index : Integer;
2411 function Ada_File_Name (Name : Name_Id) return Boolean;
2412 -- Returns True if Name is the name of an ada source file
2413 -- (i.e. suffix is .ads or .adb)
2419 function Ada_File_Name (Name : Name_Id) return Boolean is
2421 Get_Name_String (Name);
2424 and then Name_Buffer (Name_Len - 3 .. Name_Len - 1) = ".ad
"
2425 and then (Name_Buffer (Name_Len) = 'b'
2427 Name_Buffer (Name_Len) = 's');
2430 -- Start of processing for Compile
2433 Enter_Into_Obsoleted (S);
2435 -- By default, Syntax_Only is False
2437 Syntax_Only := False;
2439 for J in Args'Range loop
2440 if Args (J).all = "-gnats
" then
2442 -- If we compile with -gnats, the bind step and the link step
2443 -- are inhibited. Also, we set Syntax_Only to True, so that
2444 -- we don't fail when we don't find the ALI file, after
2447 Do_Bind_Step := False;
2448 Do_Link_Step := False;
2449 Syntax_Only := True;
2451 elsif Args (J).all = "-gnatc
" then
2453 -- If we compile with -gnatc, the bind step and the link step
2454 -- are inhibited. We set Syntax_Only to False for the case when
2455 -- -gnats was previously specified.
2457 Do_Bind_Step := False;
2458 Do_Link_Step := False;
2459 Syntax_Only := False;
2463 Comp_Args (Comp_Next) := Comp_Flag;
2464 Comp_Next := Comp_Next + 1;
2466 -- Optimize the simple case where the gcc command line looks like
2467 -- gcc -c -I. ... -I- file.adb --into-> gcc -c ... file.adb
2469 if Args (Args'First).all = "-I
" & Normalized_CWD
2470 and then Args (Args'Last).all = "-I
-"
2471 and then S = Strip_Directory (S)
2473 Comp_Last := Comp_Next + Args'Length - 3;
2474 Arg_Index := Args'First + 1;
2477 Comp_Last := Comp_Next + Args'Length - 1;
2478 Arg_Index := Args'First;
2481 -- Make a deep copy of the arguments, because Normalize_Arguments
2482 -- may deallocate some arguments.
2484 for J in Comp_Next .. Comp_Last loop
2485 Comp_Args (J) := new String'(Args (Arg_Index).all);
2486 Arg_Index := Arg_Index + 1;
2489 -- Set -gnatpg for predefined files (for this purpose the renamings
2490 -- such as Text_IO do not count as predefined). Note that we strip
2491 -- the directory name from the source file name becase the call to
2492 -- Fname.Is_Predefined_File_Name cannot deal with directory prefixes.
2495 Fname : constant File_Name_Type := Strip_Directory (S);
2498 if Is_Predefined_File_Name (Fname, False) then
2499 if Check_Readonly_Files then
2500 Comp_Last := Comp_Last + 1;
2501 Comp_Args (Comp_Last) := GNAT_Flag;
2505 ("not allowed to compile
""" &
2506 Get_Name_String (Fname) &
2507 """; use -a switch
, or compile file
with " &
2508 """-gnatg
"" switch
");
2513 -- Now check if the file name has one of the suffixes familiar to
2514 -- the gcc driver. If this is not the case then add the ada flag
2517 if not Ada_File_Name (S) and then not Targparm.AAMP_On_Target then
2518 Comp_Last := Comp_Last + 1;
2519 Comp_Args (Comp_Last) := Ada_Flag_1;
2520 Comp_Last := Comp_Last + 1;
2521 Comp_Args (Comp_Last) := Ada_Flag_2;
2524 if Source_Index /= 0 then
2526 Num : constant String := Source_Index'Img;
2528 Comp_Last := Comp_Last + 1;
2529 Comp_Args (Comp_Last) :=
2530 new String'("-gnateI
" & Num (Num'First + 1 .. Num'Last));
2534 if Source_Index /= 0 or else
2535 L /= Strip_Directory (L) or else
2536 Object_Directory_Path /= null
2538 -- Build -o argument
2540 Get_Name_String (L);
2542 for J in reverse 1 .. Name_Len loop
2543 if Name_Buffer (J) = '.' then
2544 Name_Len := J + Object_Suffix'Length - 1;
2545 Name_Buffer (J .. Name_Len) := Object_Suffix;
2550 Comp_Last := Comp_Last + 1;
2551 Comp_Args (Comp_Last) := Output_Flag;
2552 Comp_Last := Comp_Last + 1;
2554 -- If an object directory was specified, prepend the object file
2555 -- name with this object directory.
2557 if Object_Directory_Path /= null then
2558 Comp_Args (Comp_Last) :=
2559 new String'(Object_Directory_Path.all &
2560 Name_Buffer (1 .. Name_Len));
2563 Comp_Args (Comp_Last) :=
2564 new String'(Name_Buffer (1 .. Name_Len));
2568 if Create_Mapping_File then
2569 Comp_Last := Comp_Last + 1;
2570 Comp_Args (Comp_Last) := Mapping_File_Arg;
2573 Get_Name_String (S);
2575 Comp_Last := Comp_Last + 1;
2576 Comp_Args (Comp_Last) := new String'(Name_Buffer (1 .. Name_Len));
2578 GNAT.OS_Lib.Normalize_Arguments (Comp_Args (Args'First .. Comp_Last));
2580 Comp_Last := Comp_Last + 1;
2581 Comp_Args (Comp_Last) := new String'("-gnatez
");
2583 Display (Gcc.all, Comp_Args (Args'First .. Comp_Last));
2585 if Gcc_Path = null then
2586 Make_Failed ("error
, unable to locate
", Gcc.all);
2590 GNAT.OS_Lib.Non_Blocking_Spawn
2591 (Gcc_Path.all, Comp_Args (Args'First .. Comp_Last));
2594 ----------------------
2595 -- Get_Mapping_File --
2596 ----------------------
2598 procedure Get_Mapping_File (Project : Project_Id) is
2600 -- If there is a mapping file ready to be reused, reuse it
2602 if Last_Free_Indices (Project) > 0 then
2603 Mfile := The_Free_Mapping_File_Indices
2604 (Project, Last_Free_Indices (Project));
2605 Last_Free_Indices (Project) := Last_Free_Indices (Project) - 1;
2607 -- Otherwise, create and initialize a new one
2610 Init_Mapping_File (Project => Project, File_Index => Mfile);
2613 -- Put the name in the mapping file argument for the invocation
2616 Free (Mapping_File_Arg);
2618 new String'("-gnatem
=" &
2620 (The_Mapping_File_Names (Project, Mfile)));
2622 end Get_Mapping_File;
2624 -----------------------
2625 -- Get_Next_Good_ALI --
2626 -----------------------
2628 function Get_Next_Good_ALI return ALI_Id is
2632 pragma Assert (Good_ALI_Present);
2633 ALI := Good_ALI.Table (Good_ALI.Last);
2634 Good_ALI.Decrement_Last;
2636 end Get_Next_Good_ALI;
2638 ----------------------
2639 -- Good_ALI_Present --
2640 ----------------------
2642 function Good_ALI_Present return Boolean is
2644 return Good_ALI.First <= Good_ALI.Last;
2645 end Good_ALI_Present;
2647 --------------------
2648 -- Record_Failure --
2649 --------------------
2651 procedure Record_Failure
2652 (File : File_Name_Type;
2653 Unit : Unit_Name_Type;
2654 Found : Boolean := True)
2657 Bad_Compilation.Increment_Last;
2658 Bad_Compilation.Table (Bad_Compilation.Last) := (File, Unit, Found);
2661 ---------------------
2662 -- Record_Good_ALI --
2663 ---------------------
2665 procedure Record_Good_ALI (A : ALI_Id) is
2667 Good_ALI.Increment_Last;
2668 Good_ALI.Table (Good_ALI.Last) := A;
2669 end Record_Good_ALI;
2671 -- Start of processing for Compile_Sources
2674 pragma Assert (Args'First = 1);
2676 -- Package and Queue initializations
2679 Output.Set_Standard_Error;
2681 if First_Q_Initialization then
2685 if Initialize_ALI_Data then
2687 Initialize_ALI_Source;
2690 -- The following two flags affect the behavior of ALI.Set_Source_Table.
2691 -- We set Check_Source_Files to True to ensure that source file
2692 -- time stamps are checked, and we set All_Sources to False to
2693 -- avoid checking the presence of the source files listed in the
2694 -- source dependency section of an ali file (which would be a mistake
2695 -- since the ali file may be obsolete).
2697 Check_Source_Files := True;
2698 All_Sources := False;
2700 -- Only insert in the Q if it is not already done, to avoid simultaneous
2701 -- compilations if -jnnn is used.
2703 if not Is_Marked (Main_Source, Main_Index) then
2704 Insert_Q (Main_Source, Index => Main_Index);
2705 Mark (Main_Source, Main_Index);
2708 First_Compiled_File := No_File;
2709 Most_Recent_Obj_File := No_File;
2710 Most_Recent_Obj_Stamp := Empty_Time_Stamp;
2713 -- Keep looping until there is no more work to do (the Q is empty)
2714 -- and all the outstanding compilations have terminated
2716 Make_Loop : while not Empty_Q or else Outstanding_Compiles > 0 loop
2718 -- If the user does not want to keep going in case of errors then
2719 -- wait for the remaining outstanding compiles and then exit.
2721 if Bad_Compilation_Count > 0 and then not Keep_Going then
2722 while Outstanding_Compiles > 0 loop
2724 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
2726 if not Compilation_OK then
2727 Record_Failure (Full_Source_File, Source_Unit);
2734 -- PHASE 1: Check if there is more work that we can do (ie the Q
2735 -- is non empty). If there is, do it only if we have not yet used
2736 -- up all the available processes.
2738 if not Empty_Q and then Outstanding_Compiles < Max_Process then
2741 -- Index of the current unit in the current source file
2744 Extract_From_Q (Source_File, Source_Unit, Source_Index);
2745 Full_Source_File := Osint.Full_Source_Name (Source_File);
2746 Lib_File := Osint.Lib_File_Name
2747 (Source_File, Source_Index);
2748 Full_Lib_File := Osint.Full_Lib_File_Name (Lib_File);
2750 -- If this source has already been compiled, the executable is
2753 if Is_In_Obsoleted (Source_File) then
2754 Executable_Obsolete := True;
2757 -- If the library file is an Ada library skip it
2759 if Full_Lib_File /= No_File
2760 and then In_Ada_Lib_Dir (Full_Lib_File)
2764 "is in an Ada library
",
2766 Minimum_Verbosity => Opt.High);
2768 -- If the library file is a read-only library skip it, but
2769 -- only if, when using project files, this library file is
2770 -- in the right object directory (a read-only ALI file
2771 -- in the object directory of a project being extended
2772 -- should not be skipped).
2774 elsif Full_Lib_File /= No_File
2775 and then not Check_Readonly_Files
2776 and then Is_Readonly_Library (Full_Lib_File)
2777 and then Is_In_Object_Directory (Source_File, Full_Lib_File)
2781 "is a read
-only library
",
2783 Minimum_Verbosity => Opt.High);
2785 -- The source file that we are checking cannot be located
2787 elsif Full_Source_File = No_File then
2788 Record_Failure (Source_File, Source_Unit, False);
2790 -- Source and library files can be located but are internal
2793 elsif not Check_Readonly_Files
2794 and then Full_Lib_File /= No_File
2795 and then Is_Internal_File_Name (Source_File)
2797 if Force_Compilations then
2799 ("not allowed to compile
""" &
2800 Get_Name_String (Source_File) &
2801 """; use -a switch
, or compile file
with " &
2802 """-gnatg
"" switch
");
2807 "is an internal library
",
2809 Minimum_Verbosity => Opt.High);
2811 -- The source file that we are checking can be located
2814 Arguments_Collected := False;
2816 -- Don't waste any time if we have to recompile anyway
2818 Obj_Stamp := Empty_Time_Stamp;
2819 Need_To_Compile := Force_Compilations;
2821 if not Force_Compilations then
2823 Full_Lib_File /= No_File
2824 and then not Check_Readonly_Files
2825 and then Is_Readonly_Library (Full_Lib_File);
2826 Check (Source_File, Source_Index, Args, Lib_File,
2827 Read_Only, ALI, Obj_File, Obj_Stamp);
2828 Need_To_Compile := (ALI = No_ALI_Id);
2831 if not Need_To_Compile then
2833 -- The ALI file is up-to-date. Record its Id
2835 Record_Good_ALI (ALI);
2837 -- Record the time stamp of the most recent object file
2838 -- as long as no (re)compilations are needed.
2840 if First_Compiled_File = No_File
2841 and then (Most_Recent_Obj_File = No_File
2842 or else Obj_Stamp > Most_Recent_Obj_Stamp)
2844 Most_Recent_Obj_File := Obj_File;
2845 Most_Recent_Obj_Stamp := Obj_Stamp;
2849 -- Do nothing if project of source is externally built
2851 if not Arguments_Collected then
2852 Collect_Arguments (Source_File, Source_Index, Args);
2855 if Arguments_Project = No_Project
2856 or else not Project_Tree.Projects.Table
2857 (Arguments_Project).Externally_Built
2859 -- Is this the first file we have to compile?
2861 if First_Compiled_File = No_File then
2862 First_Compiled_File := Full_Source_File;
2863 Most_Recent_Obj_File := No_File;
2865 if Do_Not_Execute then
2870 if In_Place_Mode then
2872 -- If the library file was not found, then save
2873 -- the library file near the source file.
2875 if Full_Lib_File = No_File then
2876 Lib_File := Osint.Lib_File_Name
2877 (Full_Source_File, Source_Index);
2879 -- If the library file was found, then save the
2880 -- library file in the same place.
2883 Lib_File := Full_Lib_File;
2888 -- Start the compilation and record it. We can do
2889 -- this because there is at least one free process.
2891 Collect_Arguments_And_Compile
2892 (Source_File, Source_Index);
2894 -- Make sure we could successfully start
2897 if Process_Created then
2898 if Pid = Invalid_Pid then
2899 Record_Failure (Full_Source_File, Source_Unit);
2915 -- PHASE 2: Now check if we should wait for a compilation to
2916 -- finish. This is the case if all the available processes are
2917 -- busy compiling sources or there is nothing else to do
2918 -- (that is the Q is empty and there are no good ALIs to process).
2920 if Outstanding_Compiles = Max_Process
2922 and then not Good_ALI_Present
2923 and then Outstanding_Compiles > 0)
2926 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
2928 if not Compilation_OK then
2929 Record_Failure (Full_Source_File, Source_Unit);
2932 if Compilation_OK or else Keep_Going then
2934 -- Re-read the updated library file
2937 Saved_Object_Consistency : constant Boolean :=
2938 Check_Object_Consistency;
2941 -- If compilation was not OK, or if output is not an
2942 -- object file and we don't do the bind step, don't check
2943 -- for object consistency.
2945 Check_Object_Consistency :=
2946 Check_Object_Consistency
2948 and (Output_Is_Object or Do_Bind_Step);
2949 Text := Read_Library_Info (Lib_File);
2951 -- Restore Check_Object_Consistency to its initial value
2953 Check_Object_Consistency := Saved_Object_Consistency;
2956 -- If an ALI file was generated by this compilation, scan
2957 -- the ALI file and record it.
2958 -- If the scan fails, a previous ali file is inconsistent with
2959 -- the unit just compiled.
2961 if Text /= null then
2963 Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
2965 if ALI = No_ALI_Id then
2967 -- Record a failure only if not already done
2969 if Compilation_OK then
2972 "incompatible ALI file
, please recompile
");
2973 Record_Failure (Full_Source_File, Source_Unit);
2977 Record_Good_ALI (ALI);
2980 -- If we could not read the ALI file that was just generated
2981 -- then there could be a problem reading either the ALI or the
2982 -- corresponding object file (if Check_Object_Consistency
2983 -- is set Read_Library_Info checks that the time stamp of the
2984 -- object file is more recent than that of the ALI). For an
2985 -- example of problems caught by this test see [6625-009].
2986 -- However, we record a failure only if not already done.
2989 if Compilation_OK and not Syntax_Only then
2992 "WARNING
: ALI
or object file
not found after compile
");
2993 Record_Failure (Full_Source_File, Source_Unit);
2999 -- PHASE 3: Check if we recorded good ALI files. If yes process
3000 -- them now in the order in which they have been recorded. There
3001 -- are two occasions in which we record good ali files. The first is
3002 -- in phase 1 when, after scanning an existing ALI file we realize
3003 -- it is up-to-date, the second instance is after a successful
3006 while Good_ALI_Present loop
3007 ALI := Get_Next_Good_ALI;
3010 Source_Index : Int := Unit_Index_Of (ALIs.Table (ALI).Afile);
3013 -- If we are processing the library file corresponding to the
3014 -- main source file check if this source can be a main unit.
3016 if ALIs.Table (ALI).Sfile = Main_Source and then
3017 Source_Index = Main_Index
3019 Main_Unit := ALIs.Table (ALI).Main_Program /= None;
3022 -- The following adds the standard library (s-stalib) to the
3023 -- list of files to be handled by gnatmake: this file and any
3024 -- files it depends on are always included in every bind,
3025 -- even if they are not in the explicit dependency list.
3026 -- Of course, it is not added if Suppress_Standard_Library
3029 -- However, to avoid annoying output about s-stalib.ali being
3030 -- read only, when "-v
" is used, we add the standard library
3031 -- only when "-a
" is used.
3033 if Need_To_Check_Standard_Library then
3034 Check_Standard_Library;
3037 -- Now insert in the Q the unmarked source files (i.e. those
3038 -- which have never been inserted in the Q and hence never
3039 -- considered). Only do that if Unique_Compile is False.
3041 if not Unique_Compile then
3043 ALIs.Table (ALI).First_Unit .. ALIs.Table (ALI).Last_Unit
3046 Units.Table (J).First_With .. Units.Table (J).Last_With
3048 Sfile := Withs.Table (K).Sfile;
3049 Add_Dependency (ALIs.Table (ALI).Sfile, Sfile);
3051 if Is_In_Obsoleted (Sfile) then
3052 Executable_Obsolete := True;
3055 if Sfile = No_File then
3057 ("Skipping
generic:", Withs.Table (K).Uname);
3061 Unit_Index_Of (Withs.Table (K).Afile);
3063 if Is_Marked (Sfile, Source_Index) then
3064 Debug_Msg ("Skipping marked file
:", Sfile);
3066 elsif not Check_Readonly_Files
3067 and then Is_Internal_File_Name (Sfile)
3069 Debug_Msg ("Skipping internal file
:", Sfile);
3073 (Sfile, Withs.Table (K).Uname, Source_Index);
3074 Mark (Sfile, Source_Index);
3083 if Display_Compilation_Progress then
3084 Write_Str ("completed
");
3085 Write_Int (Int (Q_Front));
3086 Write_Str (" out of ");
3087 Write_Int (Int (Q.Last));
3089 Write_Int (Int ((Q_Front * 100) / (Q.Last - Q.First)));
3090 Write_Str ("%)...");
3095 Compilation_Failures := Bad_Compilation_Count;
3097 -- Compilation is finished
3099 -- Delete any temporary configuration pragma file
3101 Delete_Temp_Config_Files;
3103 end Compile_Sources;
3105 -----------------------------------
3106 -- Compute_All_Imported_Projects --
3107 -----------------------------------
3109 procedure Compute_All_Imported_Projects (Project : Project_Id) is
3110 procedure Add_To_List (Prj : Project_Id);
3111 -- Add a project to the list All_Imported_Projects of project Project
3113 procedure Recursive_Add_Imported (Project : Project_Id);
3114 -- Recursively add the projects imported by project Project, but not
3115 -- those that are extended.
3121 procedure Add_To_List (Prj : Project_Id) is
3122 Element : constant Project_Element :=
3123 (Prj, Project_Tree.Projects.Table (Project).All_Imported_Projects);
3124 List : Project_List;
3126 Project_List_Table.Increment_Last (Project_Tree.Project_Lists);
3127 List := Project_List_Table.Last (Project_Tree.Project_Lists);
3128 Project_Tree.Project_Lists.Table (List) := Element;
3129 Project_Tree.Projects.Table (Project).All_Imported_Projects := List;
3132 ----------------------------
3133 -- Recursive_Add_Imported --
3134 ----------------------------
3136 procedure Recursive_Add_Imported (Project : Project_Id) is
3137 List : Project_List;
3138 Element : Project_Element;
3142 if Project /= No_Project then
3144 -- For all the imported projects
3146 List := Project_Tree.Projects.Table (Project).Imported_Projects;
3147 while List /= Empty_Project_List loop
3148 Element := Project_Tree.Project_Lists.Table (List);
3149 Prj := Element.Project;
3151 -- Get the ultimate extending project
3154 Project_Tree.Projects.Table (Prj).Extended_By /= No_Project
3156 Prj := Project_Tree.Projects.Table (Prj).Extended_By;
3159 -- If project has not yet been visited, add to list and recurse
3161 if not Project_Tree.Projects.Table (Prj).Seen then
3162 Project_Tree.Projects.Table (Prj).Seen := True;
3164 Recursive_Add_Imported (Prj);
3167 List := Element.Next;
3170 -- Recurse on projects being imported, if any
3172 Recursive_Add_Imported
3173 (Project_Tree.Projects.Table (Project).Extends);
3175 end Recursive_Add_Imported;
3178 -- Reset the Seen flag for all projects
3180 for Index in 1 .. Project_Table.Last (Project_Tree.Projects) loop
3181 Project_Tree.Projects.Table (Index).Seen := False;
3184 -- Make sure the list is empty
3186 Project_Tree.Projects.Table (Project).All_Imported_Projects :=
3189 -- Add to the list all projects imported directly or indirectly
3191 Recursive_Add_Imported (Project);
3192 end Compute_All_Imported_Projects;
3194 ----------------------------------
3195 -- Configuration_Pragmas_Switch --
3196 ----------------------------------
3198 function Configuration_Pragmas_Switch
3199 (For_Project : Project_Id) return Argument_List
3201 The_Packages : Package_Id;
3202 Gnatmake : Package_Id;
3203 Compiler : Package_Id;
3205 Global_Attribute : Variable_Value := Nil_Variable_Value;
3206 Local_Attribute : Variable_Value := Nil_Variable_Value;
3208 Global_Attribute_Present : Boolean := False;
3209 Local_Attribute_Present : Boolean := False;
3211 Result : Argument_List (1 .. 3);
3212 Last : Natural := 0;
3214 function Absolute_Path
3216 Project : Project_Id) return String;
3217 -- Returns an absolute path for a configuration pragmas file
3223 function Absolute_Path
3225 Project : Project_Id) return String
3228 Get_Name_String (Path);
3231 Path_Name : constant String := Name_Buffer (1 .. Name_Len);
3234 if Is_Absolute_Path (Path_Name) then
3239 Parent_Directory : constant String :=
3241 (Project_Tree.Projects.Table
3242 (Project).Directory);
3245 if Parent_Directory (Parent_Directory'Last) =
3248 return Parent_Directory & Path_Name;
3251 return Parent_Directory & Directory_Separator & Path_Name;
3258 -- Start of processing for Configuration_Pragmas_Switch
3261 Prj.Env.Create_Config_Pragmas_File
3262 (For_Project, Main_Project, Project_Tree);
3264 if Project_Tree.Projects.Table
3265 (For_Project).Config_File_Name /= No_Name
3267 Temporary_Config_File :=
3268 Project_Tree.Projects.Table (For_Project).Config_File_Temp;
3274 (Project_Tree.Projects.Table
3275 (For_Project).Config_File_Name));
3278 Temporary_Config_File := False;
3281 -- Check for attribute Builder'Global_Configuration_Pragmas
3283 The_Packages := Project_Tree.Projects.Table
3284 (Main_Project).Decl.Packages;
3287 (Name => Name_Builder,
3288 In_Packages => The_Packages,
3289 In_Tree => Project_Tree);
3291 if Gnatmake /= No_Package then
3292 Global_Attribute := Prj.Util.Value_Of
3293 (Variable_Name => Name_Global_Configuration_Pragmas,
3294 In_Variables => Project_Tree.Packages.Table
3295 (Gnatmake).Decl.Attributes,
3296 In_Tree => Project_Tree);
3297 Global_Attribute_Present :=
3298 Global_Attribute /= Nil_Variable_Value
3299 and then Get_Name_String (Global_Attribute.Value) /= "";
3301 if Global_Attribute_Present then
3303 Path : constant String :=
3305 (Global_Attribute.Value, Global_Attribute.Project);
3307 if not Is_Regular_File (Path) then
3309 ("cannot find configuration pragmas file
", Path);
3313 Result (Last) := new String'("-gnatec
=" & Path);
3318 -- Check for attribute Compiler'Local_Configuration_Pragmas
3321 Project_Tree.Projects.Table (For_Project).Decl.Packages;
3324 (Name => Name_Compiler,
3325 In_Packages => The_Packages,
3326 In_Tree => Project_Tree);
3328 if Compiler /= No_Package then
3329 Local_Attribute := Prj.Util.Value_Of
3330 (Variable_Name => Name_Local_Configuration_Pragmas,
3331 In_Variables => Project_Tree.Packages.Table
3332 (Compiler).Decl.Attributes,
3333 In_Tree => Project_Tree);
3334 Local_Attribute_Present :=
3335 Local_Attribute /= Nil_Variable_Value
3336 and then Get_Name_String (Local_Attribute.Value) /= "";
3338 if Local_Attribute_Present then
3340 Path : constant String :=
3342 (Local_Attribute.Value, Local_Attribute.Project);
3344 if not Is_Regular_File (Path) then
3346 ("cannot find configuration pragmas file
", Path);
3350 Result (Last) := new String'("-gnatec
=" & Path);
3355 return Result (1 .. Last);
3356 end Configuration_Pragmas_Switch;
3362 procedure Debug_Msg (S : String; N : Name_Id) is
3364 if Debug.Debug_Flag_W then
3365 Write_Str (" ... ");
3373 ---------------------------
3374 -- Delete_All_Temp_Files --
3375 ---------------------------
3377 procedure Delete_All_Temp_Files is
3379 if Gnatmake_Called and not Debug.Debug_Flag_N then
3380 Delete_Mapping_Files;
3381 Delete_Temp_Config_Files;
3382 Prj.Env.Delete_All_Path_Files (Project_Tree);
3384 end Delete_All_Temp_Files;
3386 --------------------------
3387 -- Delete_Mapping_Files --
3388 --------------------------
3390 procedure Delete_Mapping_Files is
3393 if not Debug.Debug_Flag_N then
3394 if The_Mapping_File_Names /= null then
3395 for Project in The_Mapping_File_Names'Range (1) loop
3396 for Index in 1 .. Last_Mapping_File_Names (Project) loop
3398 (Name => Get_Name_String
3399 (The_Mapping_File_Names (Project, Index)),
3400 Success => Success);
3405 end Delete_Mapping_Files;
3407 ------------------------------
3408 -- Delete_Temp_Config_Files --
3409 ------------------------------
3411 procedure Delete_Temp_Config_Files is
3414 if (not Debug.Debug_Flag_N) and Main_Project /= No_Project then
3415 for Project in Project_Table.First ..
3416 Project_Table.Last (Project_Tree.Projects)
3419 Project_Tree.Projects.Table (Project).Config_File_Temp
3421 if Verbose_Mode then
3422 Write_Str ("Deleting temp configuration file
""");
3423 Write_Str (Get_Name_String
3424 (Project_Tree.Projects.Table
3425 (Project).Config_File_Name));
3430 (Name => Get_Name_String
3431 (Project_Tree.Projects.Table
3432 (Project).Config_File_Name),
3433 Success => Success);
3435 -- Make sure that we don't have a config file for this
3436 -- project, in case when there are several mains.
3437 -- In this case, we will recreate another config file:
3438 -- we cannot reuse the one that we just deleted!
3440 Project_Tree.Projects.Table (Project).
3441 Config_Checked := False;
3442 Project_Tree.Projects.Table (Project).
3443 Config_File_Name := No_Name;
3444 Project_Tree.Projects.Table (Project).
3445 Config_File_Temp := False;
3449 end Delete_Temp_Config_Files;
3455 procedure Display (Program : String; Args : Argument_List) is
3457 pragma Assert (Args'First = 1);
3459 if Display_Executed_Programs then
3460 Write_Str (Program);
3462 for J in Args'Range loop
3464 -- Never display -gnatez
3466 if Args (J).all /= "-gnatez
" then
3468 -- Do not display the mapping file argument automatically
3469 -- created when using a project file.
3471 if Main_Project = No_Project
3472 or else Debug.Debug_Flag_N
3473 or else Args (J)'Length < 8
3475 Args (J) (Args (J)'First .. Args (J)'First + 6) /= "-gnatem
"
3477 -- When -dn is not specified, do not display the config
3478 -- pragmas switch (-gnatec) for the temporary file created
3479 -- by the project manager (always the first -gnatec switch).
3480 -- Reset Temporary_Config_File to False so that the eventual
3481 -- other -gnatec switches will be displayed.
3483 if (not Debug.Debug_Flag_N)
3484 and then Temporary_Config_File
3485 and then Args (J)'Length > 7
3486 and then Args (J) (Args (J)'First .. Args (J)'First + 6)
3489 Temporary_Config_File := False;
3491 -- Do not display the -F=mapping_file switch for
3492 -- gnatbind, if -dn is not specified.
3494 elsif Debug.Debug_Flag_N
3495 or else Args (J)'Length < 4
3497 Args (J) (Args (J)'First .. Args (J)'First + 2) /= "-F
="
3500 Write_Str (Args (J).all);
3510 ----------------------
3511 -- Display_Commands --
3512 ----------------------
3514 procedure Display_Commands (Display : Boolean := True) is
3516 Display_Executed_Programs := Display;
3517 end Display_Commands;
3523 function Empty_Q return Boolean is
3525 if Debug.Debug_Flag_P then
3526 Write_Str (" Q
:= [");
3528 for J in Q_Front .. Q.Last - 1 loop
3530 Write_Name (Q.Table (J).File);
3539 return Q_Front >= Q.Last;
3542 --------------------------
3543 -- Enter_Into_Obsoleted --
3544 --------------------------
3546 procedure Enter_Into_Obsoleted (F : Name_Id) is
3547 Name : constant String := Get_Name_String (F);
3548 First : Natural := Name'Last;
3552 while First > Name'First
3553 and then Name (First - 1) /= Directory_Separator
3554 and then Name (First - 1) /= '/'
3559 if First /= Name'First then
3561 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
3565 Debug_Msg ("New entry in Obsoleted table
:", F2);
3566 Obsoleted.Set (F2, True);
3567 end Enter_Into_Obsoleted;
3569 ---------------------
3570 -- Extract_Failure --
3571 ---------------------
3573 procedure Extract_Failure
3574 (File : out File_Name_Type;
3575 Unit : out Unit_Name_Type;
3576 Found : out Boolean)
3579 File := Bad_Compilation.Table (Bad_Compilation.Last).File;
3580 Unit := Bad_Compilation.Table (Bad_Compilation.Last).Unit;
3581 Found := Bad_Compilation.Table (Bad_Compilation.Last).Found;
3582 Bad_Compilation.Decrement_Last;
3583 end Extract_Failure;
3585 --------------------
3586 -- Extract_From_Q --
3587 --------------------
3589 procedure Extract_From_Q
3590 (Source_File : out File_Name_Type;
3591 Source_Unit : out Unit_Name_Type;
3592 Source_Index : out Int)
3594 File : constant File_Name_Type := Q.Table (Q_Front).File;
3595 Unit : constant Unit_Name_Type := Q.Table (Q_Front).Unit;
3596 Index : constant Int := Q.Table (Q_Front).Index;
3599 if Debug.Debug_Flag_Q then
3600 Write_Str (" Q
:= Q
- [ ");
3612 Q_Front := Q_Front + 1;
3613 Source_File := File;
3614 Source_Unit := Unit;
3615 Source_Index := Index;
3622 procedure Gnatmake is
3623 Main_Source_File : File_Name_Type;
3624 -- The source file containing the main compilation unit
3626 Compilation_Failures : Natural;
3628 Total_Compilation_Failures : Natural := 0;
3630 Is_Main_Unit : Boolean;
3631 -- Set to True by Compile_Sources if the Main_Source_File can be a
3634 Main_ALI_File : File_Name_Type;
3635 -- The ali file corresponding to Main_Source_File
3637 Executable : File_Name_Type := No_File;
3638 -- The file name of an executable
3640 Non_Std_Executable : Boolean := False;
3641 -- Non_Std_Executable is set to True when there is a possibility
3642 -- that the linker will not choose the correct executable file name.
3644 Current_Work_Dir : constant String_Access :=
3645 new String'(Get_Current_Dir);
3646 -- The current working directory, used to modify some relative path
3647 -- switches on the command line when a project file is used.
3649 Current_Main_Index : Int := 0;
3650 -- If not zero, the index of the current main unit in its source file
3652 There_Are_Stand_Alone_Libraries : Boolean := False;
3653 -- Set to True when there are Stand-Alone Libraries, so that gnatbind
3654 -- is invoked with the -F switch to force checking of elaboration flags.
3656 Mapping_Path : Name_Id := No_Name;
3657 -- The path name of the mapping file
3661 procedure Check_Mains;
3662 -- Check that the main subprograms do exist and that they all
3663 -- belong to the same project file.
3665 procedure Create_Binder_Mapping_File
3666 (Args : in out Argument_List; Last_Arg : in out Natural);
3667 -- Create a binder mapping file and add the necessary switch
3673 procedure Check_Mains is
3674 Real_Main_Project : Project_Id := No_Project;
3675 -- The project of the first main
3677 Proj : Project_Id := No_Project;
3678 -- The project of the current main
3680 Data : Project_Data;
3682 Real_Path : String_Access;
3691 Main : constant String := Mains.Next_Main;
3692 -- The name specified on the command line may include
3693 -- directory information.
3695 File_Name : constant String := Base_Name (Main);
3696 -- The simple file name of the current main main
3699 exit when Main = "";
3701 -- Get the project of the current main
3703 Proj := Prj.Env.Project_Of
3704 (File_Name, Main_Project, Project_Tree);
3706 -- Fail if the current main is not a source of a
3709 if Proj = No_Project then
3712 """ is not a source
of any project
");
3715 -- If there is directory information, check that
3716 -- the source exists and, if it does, that the path
3717 -- is the actual path of a source of a project.
3719 if Main /= File_Name then
3721 Project_Tree.Projects.Table (Main_Project);
3727 (Data.Naming.Ada_Body_Suffix),
3729 if Real_Path = null then
3734 (Data.Naming.Ada_Spec_Suffix),
3738 if Real_Path = null then
3740 Locate_Regular_File (Main, "");
3743 -- Fail if the file cannot be found
3745 if Real_Path = null then
3747 ("file
""" & Main & """ does
not exist
");
3751 Project_Path : constant String :=
3752 Prj.Env.File_Name_Of_Library_Unit_Body
3754 Project => Main_Project,
3755 In_Tree => Project_Tree,
3756 Main_Project_Only => False,
3758 Normed_Path : constant String :=
3761 Case_Sensitive => False);
3762 Proj_Path : constant String :=
3765 Case_Sensitive => False);
3770 -- Fail if it is not the correct path
3772 if Normed_Path /= Proj_Path then
3773 if Verbose_Mode then
3774 Write_Str (Normed_Path);
3776 Write_Line (Proj_Path);
3781 """ is not a source
of any project
");
3786 if not Unique_Compile then
3788 -- Record the project, if it is the first main
3790 if Real_Main_Project = No_Project then
3791 Real_Main_Project := Proj;
3793 elsif Proj /= Real_Main_Project then
3795 -- Fail, as the current main is not a source
3796 -- of the same project as the first main.
3800 """ is not a source
of project
" &
3802 (Project_Tree.Projects.Table
3803 (Real_Main_Project).Name));
3808 -- If -u and -U are not used, we may have mains that
3809 -- are sources of a project that is not the one
3810 -- specified with switch -P.
3812 if not Unique_Compile then
3813 Main_Project := Real_Main_Project;
3819 --------------------------------
3820 -- Create_Binder_Mapping_File --
3821 --------------------------------
3823 procedure Create_Binder_Mapping_File
3824 (Args : in out Argument_List; Last_Arg : in out Natural)
3826 Mapping_FD : File_Descriptor := Invalid_FD;
3827 -- A File Descriptor for an eventual mapping file
3829 ALI_Unit : Name_Id := No_Name;
3830 -- The unit name of an ALI file
3832 ALI_Name : Name_Id := No_Name;
3833 -- The file name of the ALI file
3835 ALI_Project : Project_Id := No_Project;
3836 -- The project of the ALI file
3839 OK : Boolean := True;
3842 -- For call to Close
3845 Tempdir.Create_Temp_File (Mapping_FD, Mapping_Path);
3847 if Mapping_FD /= Invalid_FD then
3849 -- Traverse all units
3851 for J in Unit_Table.First ..
3852 Unit_Table.Last (Project_Tree.Units)
3855 Unit : constant Unit_Data :=
3856 Project_Tree.Units.Table (J);
3858 if Unit.Name /= No_Name then
3860 -- If there is a body, put it in the mapping
3862 if Unit.File_Names (Body_Part).Name /= No_Name
3863 and then Unit.File_Names (Body_Part).Project
3866 Get_Name_String (Unit.Name);
3868 (Name_Len + 1 .. Name_Len + 2) := "%b
";
3869 Name_Len := Name_Len + 2;
3870 ALI_Unit := Name_Find;
3873 (Unit.File_Names (Body_Part).Name);
3875 Unit.File_Names (Body_Part).Project;
3877 -- Otherwise, if there is a spec, put it
3880 elsif Unit.File_Names (Specification).Name
3882 and then Unit.File_Names
3883 (Specification).Project
3886 Get_Name_String (Unit.Name);
3888 (Name_Len + 1 .. Name_Len + 2) := "%s
";
3889 Name_Len := Name_Len + 2;
3890 ALI_Unit := Name_Find;
3891 ALI_Name := Lib_File_Name
3892 (Unit.File_Names (Specification).Name);
3894 Unit.File_Names (Specification).Project;
3897 ALI_Name := No_Name;
3900 -- If we have something to put in the mapping
3901 -- then we do it now. However, if the project
3902 -- is extended, we don't put anything in the
3903 -- mapping file, because we do not know where
3904 -- the ALI file is: it might be in the ext-
3905 -- ended project obj dir as well as in the
3906 -- extending project obj dir.
3908 if ALI_Name /= No_Name
3910 Project_Tree.Projects.Table
3911 (ALI_Project).Extended_By = No_Project
3913 Project_Tree.Projects.Table
3914 (ALI_Project).Extends = No_Project
3916 -- First line is the unit name
3918 Get_Name_String (ALI_Unit);
3919 Name_Len := Name_Len + 1;
3920 Name_Buffer (Name_Len) := ASCII.LF;
3924 Name_Buffer (1)'Address,
3926 OK := Bytes = Name_Len;
3930 -- Second line it the ALI file name
3932 Get_Name_String (ALI_Name);
3933 Name_Len := Name_Len + 1;
3934 Name_Buffer (Name_Len) := ASCII.LF;
3938 Name_Buffer (1)'Address,
3940 OK := Bytes = Name_Len;
3944 -- Third line it the ALI path name, concatenation
3945 -- of either the library directory or the object
3946 -- directory with the ALI file name.
3949 ALI : constant String :=
3950 Get_Name_String (ALI_Name);
3951 PD : Project_Data renames
3952 Project_Tree.Projects.Table (ALI_Project);
3955 -- For library projects, use the library directory,
3956 -- for other projects, use the object directory.
3959 Get_Name_String (PD.Library_Dir);
3961 Get_Name_String (PD.Object_Directory);
3964 if Name_Buffer (Name_Len) /=
3967 Name_Len := Name_Len + 1;
3968 Name_Buffer (Name_Len) :=
3969 Directory_Separator;
3974 Name_Len + ALI'Length) := ALI;
3976 Name_Len + ALI'Length + 1;
3977 Name_Buffer (Name_Len) := ASCII.LF;
3981 Name_Buffer (1)'Address,
3983 OK := Bytes = Name_Len;
3986 -- If OK is False, it means we were unable
3987 -- to write a line. No point in continuing
3988 -- with the other units.
3996 Close (Mapping_FD, Status);
3998 OK := OK and Status;
4000 -- If the creation of the mapping file was successful,
4001 -- we add the switch to the arguments of gnatbind.
4004 Last_Arg := Last_Arg + 1;
4006 new String'("-F
=" & Get_Name_String (Mapping_Path));
4009 end Create_Binder_Mapping_File;
4011 -- Start of processing for Gnatmake
4013 -- This body is very long, should be broken down ???
4016 Gnatmake_Called := True;
4018 Install_Int_Handler (Sigint_Intercepted'Access);
4020 Do_Compile_Step := True;
4021 Do_Bind_Step := True;
4022 Do_Link_Step := True;
4028 Bind_Shared := No_Shared_Switch'Access;
4029 Link_With_Shared_Libgcc := No_Shared_Libgcc_Switch'Access;
4031 Failed_Links.Set_Last (0);
4032 Successful_Links.Set_Last (0);
4034 if Hostparm.Java_VM then
4035 Gcc := new String'("jgnat
");
4036 Gnatbind := new String'("jgnatbind
");
4037 Gnatlink := new String'("jgnatlink
");
4039 -- Do not check for an object file (".o
") when compiling to
4040 -- Java bytecode since ".class
" files are generated instead.
4042 Check_Object_Consistency := False;
4045 -- Special case when switch -B was specified
4047 if Build_Bind_And_Link_Full_Project then
4049 -- When switch -B is specified, there must be a project file
4051 if Main_Project = No_Project then
4052 Make_Failed ("-B cannot be used without a project file
");
4054 -- No main program may be specified on the command line
4056 elsif Osint.Number_Of_Files /= 0 then
4057 Make_Failed ("-B cannot be used
with a main specified on
" &
4058 "the command line
");
4060 -- And the project file cannot be a library project file
4062 elsif Project_Tree.Projects.Table (Main_Project).Library then
4063 Make_Failed ("-B cannot be used
for a library project file
");
4066 Insert_Project_Sources
4067 (The_Project => Main_Project,
4068 All_Projects => Unique_Compile_All_Projects,
4071 -- If there are no sources to compile, we fail
4073 if Osint.Number_Of_Files = 0 then
4074 Make_Failed ("no sources to compile
");
4077 -- Specify -n for gnatbind and add the ALI files of all the
4078 -- sources, except the one which is a fake main subprogram:
4079 -- this is the one for the binder generated file and it will be
4080 -- transmitted to gnatlink. These sources are those that are
4083 Add_Switch ("-n
", Binder, And_Save => True);
4085 for J in Q.First .. Q.Last - 1 loop
4088 (Lib_File_Name (Q.Table (J).File)),
4089 Binder, And_Save => True);
4093 elsif Main_Index /= 0 and then Osint.Number_Of_Files > 1 then
4094 Make_Failed ("cannot specify several mains
with a multi
-unit index
");
4096 elsif Main_Project /= No_Project then
4098 -- If the main project file is a library project file, main(s)
4099 -- cannot be specified on the command line.
4101 if Osint.Number_Of_Files /= 0 then
4102 if Project_Tree.Projects.Table (Main_Project).Library
4103 and then not Unique_Compile
4104 and then ((not Make_Steps) or else Bind_Only or else Link_Only)
4106 Make_Failed ("cannot specify a main program
" &
4107 "on the command line
for a library project file
");
4110 -- Check that each main on the command line is a source of a
4111 -- project file and, if there are several mains, each of them
4112 -- is a source of the same project file.
4117 -- If no mains have been specified on the command line,
4118 -- and we are using a project file, we either find the main(s)
4119 -- in the attribute Main of the main project, or we put all
4120 -- the sources of the project file as mains.
4123 if Main_Index /= 0 then
4124 Make_Failed ("cannot specify a multi
-unit index but no main
" &
4125 "on the command line
");
4129 Value : String_List_Id :=
4130 Project_Tree.Projects.Table (Main_Project).Mains;
4133 -- The attribute Main is an empty list or not specified,
4134 -- or else gnatmake was invoked with the switch "-u
".
4136 if Value = Prj.Nil_String or else Unique_Compile then
4138 if (not Make_Steps) or else Compile_Only
4139 or else not Project_Tree.Projects.Table
4140 (Main_Project).Library
4142 -- First make sure that the binder and the linker
4143 -- will not be invoked.
4145 Do_Bind_Step := False;
4146 Do_Link_Step := False;
4148 -- Put all the sources in the queue
4150 Insert_Project_Sources
4151 (The_Project => Main_Project,
4152 All_Projects => Unique_Compile_All_Projects,
4155 -- If no sources to compile, then there is nothing to do
4157 if Osint.Number_Of_Files = 0 then
4158 if not Debug.Debug_Flag_N then
4159 Delete_Mapping_Files;
4160 Prj.Env.Delete_All_Path_Files (Project_Tree);
4163 if not Quiet_Output then
4164 Osint.Write_Program_Name;
4165 Write_Line (": no sources to compile
");
4168 Exit_Program (E_Success);
4173 -- The attribute Main is not an empty list.
4174 -- Put all the main subprograms in the list as if there
4175 -- were specified on the command line. However, if attribute
4176 -- Languages includes a language other than Ada, only
4177 -- include the Ada mains; if there is no Ada main, compile
4178 -- all the sources of the project.
4181 Data : constant Project_Data :=
4182 Project_Tree.Projects.Table (Main_Project);
4184 Languages : constant Variable_Value :=
4187 Data.Decl.Attributes,
4190 Current : String_List_Id;
4191 Element : String_Element;
4193 Foreign_Language : Boolean := False;
4194 At_Least_One_Main : Boolean := False;
4197 -- First, determine if there is a foreign language in
4198 -- attribute Languages.
4200 if not Languages.Default then
4201 Current := Languages.Values;
4204 while Current /= Nil_String loop
4205 Element := Project_Tree.String_Elements.
4207 Get_Name_String (Element.Value);
4208 To_Lower (Name_Buffer (1 .. Name_Len));
4210 if Name_Buffer (1 .. Name_Len) /= "ada
" then
4211 Foreign_Language := True;
4212 exit Look_For_Foreign;
4215 Current := Element.Next;
4216 end loop Look_For_Foreign;
4219 -- Then, find all mains, or if there is a foreign
4220 -- language, all the Ada mains.
4222 while Value /= Prj.Nil_String loop
4224 (Project_Tree.String_Elements.Table
4227 -- To know if a main is an Ada main, get its project.
4228 -- It should be the project specified on the command
4231 if (not Foreign_Language) or else
4233 (Name_Buffer (1 .. Name_Len),
4238 At_Least_One_Main := True;
4241 (Project_Tree.String_Elements.Table
4244 Project_Tree.String_Elements.Table
4248 Value := Project_Tree.String_Elements.Table
4252 -- If we did not get any main, it means that all mains
4253 -- in attribute Mains are in a foreign language and -B
4254 -- was not specified to gnatmake; so, we fail.
4256 if not At_Least_One_Main then
4258 ("no Ada mains
; use -B to build foreign main
");
4267 if Verbose_Mode then
4269 Write_Str ("GNATMAKE
");
4270 Write_Str (Gnatvsn.Gnat_Version_String);
4272 Write_Str ("Copyright
1995-2004 Free Software Foundation
, Inc
.");
4276 if Main_Project /= No_Project
4277 and then Project_Tree.Projects.Table
4278 (Main_Project).Externally_Built
4281 ("nothing to
do for a main project that
is externally built
");
4284 if Osint.Number_Of_Files = 0 then
4285 if Main_Project /= No_Project
4286 and then Project_Tree.Projects.Table (Main_Project).Library
4289 and then not Project_Tree.Projects.Table
4290 (Main_Project).Standalone_Library
4292 Make_Failed ("only stand
-alone libraries may be bound
");
4295 -- Add the default search directories to be able to find libgnat
4297 Osint.Add_Default_Search_Dirs;
4299 -- And bind and or link the library
4301 MLib.Prj.Build_Library
4302 (For_Project => Main_Project,
4303 In_Tree => Project_Tree,
4304 Gnatbind => Gnatbind.all,
4305 Gnatbind_Path => Gnatbind_Path,
4307 Gcc_Path => Gcc_Path,
4310 Exit_Program (E_Success);
4313 -- Output usage information if no files to compile
4316 Exit_Program (E_Fatal);
4320 -- If -M was specified, behave as if -n was specified
4322 if List_Dependencies then
4323 Do_Not_Execute := True;
4326 -- Note that Osint.Next_Main_Source will always return the (possibly
4327 -- abbreviated file) without any directory information.
4329 Main_Source_File := Next_Main_Source;
4331 if Current_File_Index /= No_Index then
4332 Main_Index := Current_File_Index;
4335 Add_Switch ("-I
-", Binder, And_Save => True);
4336 Add_Switch ("-I
-", Compiler, And_Save => True);
4338 if Main_Project = No_Project then
4339 if Look_In_Primary_Dir then
4343 Normalize_Directory_Name
4344 (Get_Primary_Src_Search_Directory.all).all,
4345 Compiler, Append_Switch => False,
4348 Add_Switch ("-aO
" & Normalized_CWD,
4350 Append_Switch => False,
4355 -- If we use a project file, we have already checked that a main
4356 -- specified on the command line with directory information has the
4357 -- path name corresponding to a correct source in the project tree.
4358 -- So, we don't need the directory information to be taken into
4359 -- account by Find_File, and in fact it may lead to take the wrong
4360 -- sources for other compilation units, when there are extending
4363 Look_In_Primary_Dir := False;
4366 -- If the user wants a program without a main subprogram, add the
4367 -- appropriate switch to the binder.
4369 if No_Main_Subprogram then
4370 Add_Switch ("-z
", Binder, And_Save => True);
4373 if Main_Project /= No_Project then
4375 if Project_Tree.Projects.Table
4376 (Main_Project).Object_Directory /= No_Name
4378 -- Change current directory to object directory of main project
4380 Project_Object_Directory := No_Project;
4381 Change_To_Object_Directory (Main_Project);
4384 -- Source file lookups should be cached for efficiency.
4385 -- Source files are not supposed to change.
4387 Osint.Source_File_Data (Cache => True);
4389 -- Find the file name of the (first) main unit
4392 Main_Source_File_Name : constant String :=
4393 Get_Name_String (Main_Source_File);
4394 Main_Unit_File_Name : constant String :=
4395 Prj.Env.File_Name_Of_Library_Unit_Body
4396 (Name => Main_Source_File_Name,
4397 Project => Main_Project,
4398 In_Tree => Project_Tree,
4399 Main_Project_Only =>
4400 not Unique_Compile);
4402 The_Packages : constant Package_Id :=
4403 Project_Tree.Projects.Table (Main_Project).Decl.Packages;
4405 Builder_Package : constant Prj.Package_Id :=
4407 (Name => Name_Builder,
4408 In_Packages => The_Packages,
4409 In_Tree => Project_Tree);
4411 Binder_Package : constant Prj.Package_Id :=
4413 (Name => Name_Binder,
4414 In_Packages => The_Packages,
4415 In_Tree => Project_Tree);
4417 Linker_Package : constant Prj.Package_Id :=
4419 (Name => Name_Linker,
4420 In_Packages => The_Packages,
4421 In_Tree => Project_Tree);
4424 -- We fail if we cannot find the main source file
4426 if Main_Unit_File_Name = "" then
4427 Make_Failed ('"' & Main_Source_File_Name,
4428 """ is not a unit of project ",
4429 Project_File_Name.all & ".");
4431 -- Remove any directory information from the main
4432 -- source file name.
4435 Pos : Natural := Main_Unit_File_Name'Last;
4439 exit when Pos < Main_Unit_File_Name'First or else
4440 Main_Unit_File_Name (Pos) = Directory_Separator;
4444 Name_Len := Main_Unit_File_Name'Last - Pos;
4446 Name_Buffer (1 .. Name_Len) :=
4448 (Pos + 1 .. Main_Unit_File_Name'Last);
4450 Main_Source_File := Name_Find;
4452 -- We only output the main source file if there is only one
4454 if Verbose_Mode and then Osint.Number_Of_Files = 1 then
4455 Write_Str ("Main source file: """);
4456 Write_Str (Main_Unit_File_Name
4457 (Pos + 1 .. Main_Unit_File_Name'Last));
4463 -- If there is a package Builder in the main project file, add
4464 -- the switches from it.
4466 if Builder_Package /= No_Package then
4468 -- If there is only one main, we attempt to get the gnatmake
4469 -- switches for this main (if any). If there are no specific
4470 -- switch for this particular main, get the general gnatmake
4471 -- switches (if any).
4473 if Osint.Number_Of_Files = 1 then
4474 if Verbose_Mode then
4475 Write_Str ("Adding gnatmake switches for """);
4476 Write_Str (Main_Unit_File_Name);
4481 (File_Name => Main_Unit_File_Name,
4482 Index => Main_Index,
4483 The_Package => Builder_Package,
4487 -- If there are several mains, we always get the general
4488 -- gnatmake switches (if any).
4490 -- Warn the user, if necessary, so that he is not surprized
4491 -- that specific switches are not taken into account.
4494 Defaults : constant Variable_Value :=
4498 Attribute_Or_Array_Name => Name_Default_Switches,
4499 In_Package => Builder_Package,
4500 In_Tree => Project_Tree);
4502 Switches : constant Array_Element_Id :=
4504 (Name => Name_Switches,
4506 Project_Tree.Packages.Table
4507 (Builder_Package).Decl.Arrays,
4508 In_Tree => Project_Tree);
4511 if Defaults /= Nil_Variable_Value then
4512 if (not Quiet_Output)
4513 and then Switches /= No_Array_Element
4516 ("Warning: using Builder'Default_Switches" &
4517 "(""Ada""), as there are several mains");
4520 -- As there is never a source with name " ", we are
4521 -- guaranteed to always get the general switches.
4526 The_Package => Builder_Package,
4529 elsif (not Quiet_Output)
4530 and then Switches /= No_Array_Element
4533 ("Warning: using no switches from package Builder," &
4534 " as there are several mains");
4540 Osint.Add_Default_Search_Dirs;
4542 -- Record the current last switch index for table Binder_Switches
4543 -- and Linker_Switches, so that these tables may be reset before
4544 -- for each main, before adding swiches from the project file
4545 -- and from the command line.
4547 Last_Binder_Switch := Binder_Switches.Last;
4548 Last_Linker_Switch := Linker_Switches.Last;
4552 -- Add binder switches from the project file for the first main
4554 if Do_Bind_Step and Binder_Package /= No_Package then
4555 if Verbose_Mode then
4556 Write_Str ("Adding binder switches for """);
4557 Write_Str (Main_Unit_File_Name);
4562 (File_Name => Main_Unit_File_Name,
4563 Index => Main_Index,
4564 The_Package => Binder_Package,
4568 -- Add linker switches from the project file for the first main
4570 if Do_Link_Step and Linker_Package /= No_Package then
4571 if Verbose_Mode then
4572 Write_Str ("Adding linker switches for""");
4573 Write_Str (Main_Unit_File_Name);
4578 (File_Name => Main_Unit_File_Name,
4579 Index => Main_Index,
4580 The_Package => Linker_Package,
4586 -- Get the target parameters, which are only needed for a couple of
4587 -- cases in gnatmake. Protect against an exception, such as the case
4588 -- of system.ads missing from the library, and fail gracefully.
4591 Targparm.Get_Target_Parameters;
4594 when Unrecoverable_Error =>
4595 Make_Failed ("*** make failed.");
4598 Display_Commands (not Quiet_Output);
4602 if Main_Project /= No_Project then
4604 -- For all library project, if the library file does not exist
4605 -- put all the project sources in the queue, and flag the project
4606 -- so that the library is generated.
4608 if not Unique_Compile
4609 and then MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None
4611 for Proj in Project_Table.First ..
4612 Project_Table.Last (Project_Tree.Projects)
4614 if Project_Tree.Projects.Table (Proj).Library then
4615 Project_Tree.Projects.Table
4616 (Proj).Need_To_Build_Lib :=
4617 (not MLib.Tgt.Library_Exists_For (Proj, Project_Tree))
4618 and then (not Project_Tree.Projects.Table
4619 (Proj).Externally_Built);
4621 if Project_Tree.Projects.Table
4622 (Proj).Need_To_Build_Lib
4624 -- If there is no object directory, then it will be
4625 -- impossible to build the library. So fail immediately.
4627 if Project_Tree.Projects.Table
4628 (Proj).Object_Directory = No_Name
4631 ("no object files to build library for project """,
4633 (Project_Tree.Projects.Table (Proj).Name),
4635 Project_Tree.Projects.Table
4636 (Proj).Need_To_Build_Lib := False;
4639 if Verbose_Mode then
4641 ("Library file does not exist for project """);
4644 (Project_Tree.Projects.Table
4649 Insert_Project_Sources
4650 (The_Project => Proj,
4651 All_Projects => False,
4659 -- If a relative path output file has been specified, we add
4660 -- the exec directory.
4662 for J in reverse 1 .. Saved_Linker_Switches.Last - 1 loop
4663 if Saved_Linker_Switches.Table (J).all = Output_Flag.all then
4665 Exec_File_Name : constant String :=
4666 Saved_Linker_Switches.Table (J + 1).all;
4669 if not Is_Absolute_Path (Exec_File_Name) then
4671 (Project_Tree.Projects.Table
4672 (Main_Project).Exec_Directory);
4674 if Name_Buffer (Name_Len) /= Directory_Separator then
4675 Name_Len := Name_Len + 1;
4676 Name_Buffer (Name_Len) := Directory_Separator;
4679 Name_Buffer (Name_Len + 1 ..
4680 Name_Len + Exec_File_Name'Length) :=
4682 Name_Len := Name_Len + Exec_File_Name'Length;
4683 Saved_Linker_Switches.Table (J + 1) :=
4684 new String'(Name_Buffer
(1 .. Name_Len
));
4692 -- If we are using a project file, for relative paths we add the
4693 -- current working directory for any relative path on the command
4694 -- line and the project directory, for any relative path in the
4698 Dir_Path
: constant String_Access
:=
4699 new String'(Get_Name_String
4700 (Project_Tree.Projects.Table
4701 (Main_Project).Directory));
4703 for J in 1 .. Binder_Switches.Last loop
4704 Test_If_Relative_Path
4705 (Binder_Switches.Table (J),
4706 Parent => Dir_Path, Including_L_Switch => False);
4709 for J in 1 .. Saved_Binder_Switches.Last loop
4710 Test_If_Relative_Path
4711 (Saved_Binder_Switches.Table (J),
4712 Parent => Current_Work_Dir, Including_L_Switch => False);
4715 for J in 1 .. Linker_Switches.Last loop
4716 Test_If_Relative_Path
4717 (Linker_Switches.Table (J), Parent => Dir_Path);
4720 for J in 1 .. Saved_Linker_Switches.Last loop
4721 Test_If_Relative_Path
4722 (Saved_Linker_Switches.Table (J), Parent => Current_Work_Dir);
4725 for J in 1 .. Gcc_Switches.Last loop
4726 Test_If_Relative_Path
4727 (Gcc_Switches.Table (J), Parent => Dir_Path);
4730 for J in 1 .. Saved_Gcc_Switches.Last loop
4731 Test_If_Relative_Path
4732 (Saved_Gcc_Switches.Table (J), Parent => Current_Work_Dir);
4737 -- We now put in the Binder_Switches and Linker_Switches tables, the
4738 -- binder and linker switches of the command line that have been put in
4739 -- the Saved_ tables. If a project file was used, then the command line
4740 -- switches will follow the project file switches.
4742 for J in 1 .. Saved_Binder_Switches.Last loop
4744 (Saved_Binder_Switches.Table (J),
4749 for J in 1 .. Saved_Linker_Switches.Last loop
4751 (Saved_Linker_Switches.Table (J),
4756 -- If no project file is used, we just put the gcc switches
4757 -- from the command line in the Gcc_Switches table.
4759 if Main_Project = No_Project then
4760 for J in 1 .. Saved_Gcc_Switches.Last loop
4762 (Saved_Gcc_Switches.Table (J),
4768 -- And we put the command line gcc switches in the variable
4769 -- The_Saved_Gcc_Switches. They are going to be used later
4770 -- in procedure Compile_Sources.
4772 The_Saved_Gcc_Switches :=
4773 new Argument_List (1 .. Saved_Gcc_Switches.Last + 1);
4775 for J in 1 .. Saved_Gcc_Switches.Last loop
4776 The_Saved_Gcc_Switches (J) := Saved_Gcc_Switches.Table (J);
4779 -- We never use gnat.adc when a project file is used
4781 The_Saved_Gcc_Switches (The_Saved_Gcc_Switches'Last) :=
4786 -- If there was a --GCC, --GNATBIND or --GNATLINK switch on
4787 -- the command line, then we have to use it, even if there was
4788 -- another switch in the project file.
4790 if Saved_Gcc /= null then
4794 if Saved_Gnatbind /= null then
4795 Gnatbind := Saved_Gnatbind;
4798 if Saved_Gnatlink /= null then
4799 Gnatlink := Saved_Gnatlink;
4802 Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
4803 Gnatbind_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
4804 Gnatlink_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
4806 -- If we have specified -j switch both from the project file
4807 -- and on the command line, the one from the command line takes
4810 if Saved_Maximum_Processes = 0 then
4811 Saved_Maximum_Processes := Maximum_Processes;
4814 -- Allocate as many temporary mapping file names as the maximum
4815 -- number of compilation processed, for each possible project.
4817 The_Mapping_File_Names :=
4819 (No_Project .. Project_Table.Last (Project_Tree.Projects),
4820 1 .. Saved_Maximum_Processes);
4821 Last_Mapping_File_Names :=
4823 (No_Project
.. Project_Table
.Last
(Project_Tree
.Projects
)
4826 The_Free_Mapping_File_Indices
:=
4827 new Free_File_Indices
4828 (No_Project
.. Project_Table
.Last
(Project_Tree
.Projects
),
4829 1 .. Saved_Maximum_Processes
);
4830 Last_Free_Indices
:=
4831 new Indices
'(No_Project .. Project_Table.Last
4832 (Project_Tree.Projects) => 0);
4834 Bad_Compilation.Init;
4836 Current_Main_Index := Main_Index;
4838 -- Here is where the make process is started
4840 -- We do the same process for each main
4842 Multiple_Main_Loop : for N_File in 1 .. Osint.Number_Of_Files loop
4844 -- First, find the executable name and path
4846 Executable := No_File;
4847 Executable_Obsolete := False;
4848 Non_Std_Executable := False;
4850 -- Look inside the linker switches to see if the name
4851 -- of the final executable program was specified.
4854 J in reverse Linker_Switches.First .. Linker_Switches.Last
4856 if Linker_Switches.Table (J).all = Output_Flag.all then
4857 pragma Assert (J < Linker_Switches.Last);
4859 -- We cannot specify a single executable for several
4860 -- main subprograms!
4862 if Osint.Number_Of_Files > 1 then
4864 ("cannot specify a single executable " &
4865 "for several mains");
4868 Name_Len := Linker_Switches.Table (J + 1)'Length;
4869 Name_Buffer (1 .. Name_Len) :=
4870 Linker_Switches.Table (J + 1).all;
4871 Executable := Name_Enter;
4873 Verbose_Msg (Executable, "final executable");
4877 -- If the name of the final executable program was not
4878 -- specified then construct it from the main input file.
4880 if Executable = No_File then
4881 if Main_Project = No_Project then
4883 Executable_Name (Strip_Suffix (Main_Source_File));
4886 -- If we are using a project file, we attempt to
4887 -- remove the body (or spec) termination of the main
4888 -- subprogram. We find it the the naming scheme of the
4889 -- project file. This will avoid to generate an
4890 -- executable "main.2" for a main subprogram
4891 -- "main.2.ada", when the body termination is ".2.ada".
4894 Prj.Util.Executable_Of
4895 (Main_Project, Project_Tree, Main_Source_File, Main_Index);
4899 if Main_Project /= No_Project then
4901 Exec_File_Name : constant String :=
4902 Get_Name_String (Executable);
4905 if not Is_Absolute_Path (Exec_File_Name) then
4907 Get_Name_String (Project_Tree.Projects.Table
4908 (Main_Project).Exec_Directory);
4911 Name_Buffer (Name_Len) /= Directory_Separator
4913 Name_Len := Name_Len + 1;
4914 Name_Buffer (Name_Len) := Directory_Separator;
4917 Name_Buffer (Name_Len + 1 ..
4918 Name_Len + Exec_File_Name'Length) :=
4921 Name_Len := Name_Len + Exec_File_Name'Length;
4922 Executable := Name_Find;
4925 Non_Std_Executable := True;
4929 if Do_Compile_Step then
4930 Recursive_Compilation_Step : declare
4931 Args : Argument_List (1 .. Gcc_Switches.Last);
4933 First_Compiled_File : Name_Id;
4934 Youngest_Obj_File : Name_Id;
4935 Youngest_Obj_Stamp : Time_Stamp_Type;
4937 Executable_Stamp : Time_Stamp_Type;
4938 -- Executable is the final executable program
4940 Library_Rebuilt : Boolean := False;
4943 for J in 1 .. Gcc_Switches.Last loop
4944 Args (J) := Gcc_Switches.Table (J);
4947 -- Now we invoke Compile_Sources for the current main
4950 (Main_Source => Main_Source_File,
4952 First_Compiled_File => First_Compiled_File,
4953 Most_Recent_Obj_File => Youngest_Obj_File,
4954 Most_Recent_Obj_Stamp => Youngest_Obj_Stamp,
4955 Main_Unit => Is_Main_Unit,
4956 Main_Index => Current_Main_Index,
4957 Compilation_Failures => Compilation_Failures,
4958 Check_Readonly_Files => Check_Readonly_Files,
4959 Do_Not_Execute => Do_Not_Execute,
4960 Force_Compilations => Force_Compilations,
4961 In_Place_Mode => In_Place_Mode,
4962 Keep_Going => Keep_Going,
4963 Initialize_ALI_Data => True,
4964 Max_Process => Saved_Maximum_Processes);
4966 if Verbose_Mode then
4967 Write_Str ("End of compilation");
4971 -- Make sure the queue will be reinitialized for the next round
4973 First_Q_Initialization := True;
4975 Total_Compilation_Failures :=
4976 Total_Compilation_Failures + Compilation_Failures;
4978 if Total_Compilation_Failures /= 0 then
4982 List_Bad_Compilations;
4983 raise Compilation_Failed;
4987 -- Regenerate libraries, if any, and if object files
4988 -- have been regenerated.
4990 if Main_Project /= No_Project
4991 and then MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None
4992 and then (Do_Bind_Step
4993 or Unique_Compile_All_Projects
4994 or not Compile_Only)
4995 and then (Do_Link_Step or N_File = Osint.Number_Of_Files)
5003 procedure Add_To_Library_Projs (Proj : Project_Id);
5004 -- Add project Project to table Library_Projs
5005 -- in decreasing depth order.
5007 --------------------------
5008 -- Add_To_Library_Projs --
5009 --------------------------
5011 procedure Add_To_Library_Projs (Proj : Project_Id) is
5015 Library_Projs.Increment_Last;
5016 Depth := Project_Tree.Projects.Table (Proj).Depth;
5018 -- Put the projects in decreasing depth order,
5019 -- so that if libA depends on libB, libB is first
5022 Current := Library_Projs.Last;
5023 while Current > 1 loop
5024 Prj := Library_Projs.Table (Current - 1);
5025 exit when Project_Tree.Projects.Table
5026 (Prj).Depth >= Depth;
5027 Library_Projs.Table (Current) := Prj;
5028 Current := Current - 1;
5031 Library_Projs.Table (Current) := Proj;
5032 end Add_To_Library_Projs;
5034 -- Start of processing for ??? (should name declare block
5035 -- or probably better, break this out as a nested proc.
5038 -- Put in Library_Projs table all library project
5039 -- file ids when the library need to be rebuilt.
5041 for Proj1 in Project_Table.First ..
5042 Project_Table.Last (Project_Tree.Projects)
5044 if Project_Tree.Projects.Table
5045 (Proj1).Standalone_Library
5047 There_Are_Stand_Alone_Libraries := True;
5050 if Project_Tree.Projects.Table (Proj1).Library then
5051 MLib.Prj.Check_Library (Proj1, Project_Tree);
5054 if Project_Tree.Projects.Table
5055 (Proj1).Need_To_Build_Lib
5057 Add_To_Library_Projs (Proj1);
5061 -- Check if importing libraries should be regenerated
5062 -- because at least an imported library will be
5063 -- regenerated or is more recent.
5065 for Proj1 in Project_Table.First ..
5066 Project_Table.Last (Project_Tree.Projects)
5068 if Project_Tree.Projects.Table (Proj1).Library
5069 and then not Project_Tree.Projects.Table
5070 (Proj1).Need_To_Build_Lib
5071 and then not Project_Tree.Projects.Table
5072 (Proj1).Externally_Built
5075 List : Project_List;
5076 Element : Project_Element;
5078 Rebuild : Boolean := False;
5080 Lib_Timestamp1 : constant Time_Stamp_Type :=
5081 Project_Tree.Projects.Table
5082 (Proj1). Library_TS;
5085 List := Project_Tree.Projects.Table (Proj1).
5086 All_Imported_Projects;
5087 while List /= Empty_Project_List loop
5089 Project_Tree.Project_Lists.Table (List);
5090 Proj2 := Element.Project;
5093 Project_Tree.Projects.Table (Proj2).Library
5095 if Project_Tree.Projects.Table (Proj2).
5099 Project_Tree.Projects.Table
5107 List := Element.Next;
5111 Project_Tree.Projects.Table
5112 (Proj1).Need_To_Build_Lib := True;
5113 Add_To_Library_Projs (Proj1);
5119 -- Reset the flags Need_To_Build_Lib for the next main,
5120 -- to avoid rebuilding libraries uselessly.
5122 for Proj1 in Project_Table.First ..
5123 Project_Table.Last (Project_Tree.Projects)
5125 Project_Tree.Projects.Table
5126 (Proj1).Need_To_Build_Lib := False;
5130 -- Build the libraries, if any need to be built
5132 for J in 1 .. Library_Projs.Last loop
5133 Library_Rebuilt := True;
5134 MLib.Prj.Build_Library
5135 (For_Project => Library_Projs.Table (J),
5136 In_Tree => Project_Tree,
5137 Gnatbind => Gnatbind.all,
5138 Gnatbind_Path => Gnatbind_Path,
5140 Gcc_Path => Gcc_Path);
5144 if List_Dependencies then
5145 if First_Compiled_File /= No_File then
5147 (First_Compiled_File,
5148 "must be recompiled. Can't generate dependence list.");
5153 elsif First_Compiled_File = No_File
5154 and then not Do_Bind_Step
5155 and then not Quiet_Output
5156 and then not Library_Rebuilt
5157 and then Osint.Number_Of_Files = 1
5159 Inform (Msg => "objects up to date.");
5161 elsif Do_Not_Execute
5162 and then First_Compiled_File /= No_File
5164 Write_Name (First_Compiled_File);
5168 -- Stop after compile step if any of:
5170 -- 1) -n (Do_Not_Execute) specified
5172 -- 2) -M (List_Dependencies) specified (also sets
5173 -- Do_Not_Execute above, so this is probably superfluous).
5175 -- 3) -c (Compile_Only) specified, but not -b (Bind_Only)
5177 -- 4) Made unit cannot be a main unit
5180 or List_Dependencies
5182 or not Is_Main_Unit)
5183 and then not No_Main_Subprogram
5184 and then not Build_Bind_And_Link_Full_Project
5186 if Osint.Number_Of_Files = 1 then
5187 exit Multiple_Main_Loop;
5194 -- If the objects were up-to-date check if the executable file
5195 -- is also up-to-date. For now always bind and link on the JVM
5196 -- since there is currently no simple way to check the
5197 -- up-to-date status of objects
5199 if not Hostparm.Java_VM
5200 and then First_Compiled_File = No_File
5202 Executable_Stamp := File_Stamp (Executable);
5204 if not Executable_Obsolete then
5205 Executable_Obsolete :=
5206 Youngest_Obj_Stamp > Executable_Stamp;
5209 if not Executable_Obsolete then
5210 for Index in reverse 1 .. Dependencies.Last loop
5212 (Dependencies.Table (Index).Depends_On)
5214 Enter_Into_Obsoleted
5215 (Dependencies.Table (Index).This);
5219 Executable_Obsolete := Is_In_Obsoleted (Main_Source_File);
5223 if not Executable_Obsolete then
5225 -- If no Ada object files obsolete the executable, check
5226 -- for younger or missing linker files.
5228 Check_Linker_Options
5231 Youngest_Obj_Stamp);
5233 Executable_Obsolete := Youngest_Obj_File /= No_File;
5236 -- Return if the executable is up to date
5237 -- and otherwise motivate the relink/rebind.
5239 if not Executable_Obsolete then
5240 if not Quiet_Output then
5241 Inform (Executable, "up to date.");
5244 if Osint.Number_Of_Files = 1 then
5245 exit Multiple_Main_Loop;
5252 if Executable_Stamp (1) = ' ' then
5253 Verbose_Msg (Executable, "missing.", Prefix => " ");
5255 elsif Youngest_Obj_Stamp (1) = ' ' then
5261 elsif Youngest_Obj_Stamp > Executable_Stamp then
5264 "(" & String (Youngest_Obj_Stamp) & ") newer than",
5266 "(" & String (Executable_Stamp) & ")");
5270 (Executable, "needs to be rebuild.",
5275 end Recursive_Compilation_Step;
5278 -- For binding and linking, we need to be in the object directory of
5279 -- the main project.
5281 if Main_Project /= No_Project then
5282 Change_To_Object_Directory (Main_Project);
5285 -- If we are here, it means that we need to rebuilt the current
5286 -- main. So we set Executable_Obsolete to True to make sure that
5287 -- the subsequent mains will be rebuilt.
5289 Main_ALI_In_Place_Mode_Step : declare
5290 ALI_File : File_Name_Type;
5291 Src_File : File_Name_Type;
5294 Src_File := Strip_Directory (Main_Source_File);
5295 ALI_File := Lib_File_Name (Src_File, Current_Main_Index);
5296 Main_ALI_File := Full_Lib_File_Name (ALI_File);
5298 -- When In_Place_Mode, the library file can be located in the
5299 -- Main_Source_File directory which may not be present in the
5300 -- library path. In this case, use the corresponding library file
5303 if Main_ALI_File = No_File and then In_Place_Mode then
5304 Get_Name_String (Get_Directory (Full_Source_Name (Src_File)));
5305 Get_Name_String_And_Append (ALI_File);
5306 Main_ALI_File := Name_Find;
5307 Main_ALI_File := Full_Lib_File_Name (Main_ALI_File);
5310 if Main_ALI_File = No_File then
5311 Make_Failed ("could not find the main ALI file");
5313 end Main_ALI_In_Place_Mode_Step;
5315 if Do_Bind_Step then
5317 Args : Argument_List
5318 (Binder_Switches.First .. Binder_Switches.Last + 2);
5319 -- The arguments for the invocation of gnatbind
5321 Last_Arg : Natural := Binder_Switches.Last;
5322 -- Index of the last argument in Args
5324 Shared_Libs : Boolean := False;
5325 -- Set to True when there are shared library project files or
5326 -- when gnatbind is invoked with -shared.
5329 -- Check if there are shared libraries, so that gnatbind is
5330 -- called with -shared. Check also if gnatbind is called with
5331 -- -shared, so that gnatlink is called with -shared-libgcc
5332 -- for GCC version 3 and above, ensuring that the shared
5333 -- version of libgcc will be used.
5335 if Main_Project /= No_Project
5336 and then MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None
5338 for Proj in Project_Table.First ..
5339 Project_Table.Last (Project_Tree.Projects)
5341 if Project_Tree.Projects.Table (Proj).Library
5342 and then Project_Tree.Projects.Table
5343 (Proj).Library_Kind /= Static
5345 Shared_Libs := True;
5346 Bind_Shared := Shared_Switch'Access;
5352 -- Check now for switch -shared
5354 if not Shared_Libs then
5355 for J in Binder_Switches.First .. Last_Arg loop
5356 if Binder_Switches.Table (J).all = "-shared" then
5357 Shared_Libs := True;
5363 -- If there are shared libraries, invoke gnatlink with
5364 -- -shared-libgcc if GCC version is 3 or more.
5366 if Shared_Libs and then GCC_Version >= 3 then
5367 Link_With_Shared_Libgcc := Shared_Libgcc_Switch'Access;
5370 -- Get all the binder switches
5372 for J in Binder_Switches.First .. Last_Arg loop
5373 Args (J) := Binder_Switches.Table (J);
5376 if There_Are_Stand_Alone_Libraries then
5377 Last_Arg := Last_Arg + 1;
5378 Args (Last_Arg) := Force_Elab_Flags_String'Access;
5381 if Main_Project /= No_Project then
5383 -- Put all the source directories in ADA_INCLUDE_PATH,
5384 -- and all the object directories in ADA_OBJECTS_PATH
5386 Prj.Env.Set_Ada_Paths (Main_Project, Project_Tree, False);
5388 -- If switch -C was specified, create a binder mapping file
5390 if Create_Mapping_File then
5391 Create_Binder_Mapping_File (Args, Last_Arg);
5397 Bind (Main_ALI_File,
5398 Bind_Shared.all & Args (Args'First .. Last_Arg));
5403 -- If -dn was not specified, delete the temporary mapping
5404 -- file, if one was created.
5406 if not Debug.Debug_Flag_N
5407 and then Mapping_Path /= No_Name
5409 Delete_File (Get_Name_String (Mapping_Path), Discard);
5412 -- And reraise the exception
5417 -- If -dn was not specified, delete the temporary mapping file,
5418 -- if one was created.
5420 if not Debug.Debug_Flag_N and then Mapping_Path /= No_Name then
5421 Delete_File (Get_Name_String (Mapping_Path), Discard);
5426 if Do_Link_Step then
5428 There_Are_Libraries : Boolean := False;
5429 Linker_Switches_Last : constant Integer := Linker_Switches.Last;
5430 Path_Option : constant String_Access :=
5431 MLib.Linker_Library_Path_Option;
5437 if not Run_Path_Option then
5438 Linker_Switches.Increment_Last;
5439 Linker_Switches.Table (Linker_Switches.Last) :=
5443 if Main_Project
/= No_Project
then
5444 Library_Paths
.Set_Last
(0);
5447 if MLib
.Tgt
.Support_For_Libraries
/= MLib
.Tgt
.None
then
5448 -- Check for library projects
5450 for Proj1
in Project_Table
.First
..
5451 Project_Table
.Last
(Project_Tree
.Projects
)
5453 if Proj1
/= Main_Project
5455 Project_Tree
.Projects
.Table
(Proj1
).Library
5457 -- Add this project to table Library_Projs
5459 There_Are_Libraries
:= True;
5461 Project_Tree
.Projects
.Table
(Proj1
).Depth
;
5462 Library_Projs
.Increment_Last
;
5463 Current
:= Library_Projs
.Last
;
5465 -- Any project with a greater depth should be
5466 -- after this project in the list.
5468 while Current
> 1 loop
5469 Proj2
:= Library_Projs
.Table
(Current
- 1);
5470 exit when Project_Tree
.Projects
.Table
5471 (Proj2
).Depth
<= Depth
;
5472 Library_Projs
.Table
(Current
) := Proj2
;
5473 Current
:= Current
- 1;
5476 Library_Projs
.Table
(Current
) := Proj1
;
5478 -- If it is not a static library and path option
5479 -- is set, add it to the Library_Paths table.
5481 if Project_Tree
.Projects
.Table
5482 (Proj1
).Library_Kind
/= Static
5483 and then Path_Option
/= null
5485 Library_Paths
.Increment_Last
;
5486 Library_Paths
.Table
(Library_Paths
.Last
) :=
5489 (Project_Tree.Projects.Table
5490 (Proj1).Library_Dir));
5495 for Index in 1 .. Library_Projs.Last loop
5496 -- Add the -L switch
5498 Linker_Switches.Increment_Last;
5499 Linker_Switches.Table (Linker_Switches.Last) :=
5502 (Project_Tree
.Projects
.Table
5503 (Library_Projs
.Table
(Index
)).
5506 -- Add the -l switch
5508 Linker_Switches
.Increment_Last
;
5509 Linker_Switches
.Table
(Linker_Switches
.Last
) :=
5512 (Project_Tree.Projects.Table
5513 (Library_Projs.Table (Index)).
5518 if There_Are_Libraries then
5520 -- If Path_Option is not null, create the switch
5521 -- ("-Wl,-rpath," or equivalent) with all the non static
5522 -- library dirs plus the standard GNAT library dir.
5523 -- We do that only if Run_Path_Option is True
5524 -- (not disabled by -R switch).
5526 if Run_Path_Option and Path_Option /= null then
5528 Option : String_Access;
5529 Length : Natural := Path_Option'Length;
5534 Library_Paths.First .. Library_Paths.Last
5536 -- Add the length of the library dir plus one
5537 -- for the directory separator.
5541 Library_Paths.Table (Index)'Length + 1;
5544 -- Finally, add the length of the standard GNAT
5547 Length := Length + MLib.Utl.Lib_Directory'Length;
5548 Option := new String (1 .. Length);
5549 Option (1 .. Path_Option'Length) := Path_Option.all;
5550 Current := Path_Option'Length;
5552 -- Put each library dir followed by a dir separator
5555 Library_Paths.First .. Library_Paths.Last
5560 Library_Paths.Table (Index)'Length) :=
5561 Library_Paths.Table (Index).all;
5564 Library_Paths.Table (Index)'Length + 1;
5565 Option (Current) := Path_Separator;
5568 -- Finally put the standard GNAT library dir
5572 Current + MLib.Utl.Lib_Directory'Length) :=
5573 MLib.Utl.Lib_Directory;
5575 -- And add the switch to the linker switches
5577 Linker_Switches.Increment_Last;
5578 Linker_Switches.Table (Linker_Switches.Last) :=
5585 -- Put the object directories in ADA_OBJECTS_PATH
5587 Prj.Env.Set_Ada_Paths (Main_Project, Project_Tree, False);
5589 -- Check for attributes Linker'Linker_Options in projects
5590 -- other than the main project
5593 Linker_Options : constant String_List :=
5594 Linker_Options_Switches
5595 (Main_Project, Project_Tree);
5597 for Option in Linker_Options'Range loop
5598 Linker_Switches.Increment_Last;
5599 Linker_Switches.Table (Linker_Switches.Last) :=
5600 Linker_Options (Option);
5606 Args : Argument_List
5607 (Linker_Switches.First .. Linker_Switches.Last + 2);
5609 Last_Arg : Integer := Linker_Switches.First - 1;
5610 Skip : Boolean := False;
5613 -- Get all the linker switches
5615 for J in Linker_Switches.First .. Linker_Switches.Last loop
5619 elsif Non_Std_Executable
5620 and then Linker_Switches.Table (J).all = "-o"
5625 Last_Arg := Last_Arg + 1;
5626 Args (Last_Arg) := Linker_Switches.Table (J);
5630 -- If need be, add the -o switch
5632 if Non_Std_Executable then
5633 Last_Arg := Last_Arg + 1;
5634 Args (Last_Arg) := new String'("-o");
5635 Last_Arg
:= Last_Arg
+ 1;
5637 new String'(Get_Name_String (Executable));
5640 -- And invoke the linker
5643 Link (Main_ALI_File,
5644 Link_With_Shared_Libgcc.all &
5645 Args (Args'First .. Last_Arg));
5646 Successful_Links.Increment_Last;
5647 Successful_Links.Table (Successful_Links.Last) :=
5652 if Osint.Number_Of_Files = 1 or not Keep_Going then
5656 Write_Line ("*** link failed");
5657 Failed_Links.Increment_Last;
5658 Failed_Links.Table (Failed_Links.Last) :=
5664 Linker_Switches.Set_Last (Linker_Switches_Last);
5668 -- We go to here when we skip the bind and link steps
5672 -- We go to the next main, if we did not process the last one
5674 if N_File < Osint.Number_Of_Files then
5675 Main_Source_File := Next_Main_Source;
5677 if Current_File_Index /= No_Index then
5678 Main_Index := Current_File_Index;
5681 if Main_Project /= No_Project then
5683 -- Find the file name of the main unit
5686 Main_Source_File_Name : constant String :=
5687 Get_Name_String (Main_Source_File);
5689 Main_Unit_File_Name : constant String :=
5691 File_Name_Of_Library_Unit_Body
5692 (Name => Main_Source_File_Name,
5693 Project => Main_Project,
5694 In_Tree => Project_Tree,
5695 Main_Project_Only =>
5696 not Unique_Compile);
5698 The_Packages : constant Package_Id :=
5699 Project_Tree.Projects.Table
5700 (Main_Project).Decl.Packages;
5702 Binder_Package : constant Prj.Package_Id :=
5704 (Name => Name_Binder,
5705 In_Packages => The_Packages,
5706 In_Tree => Project_Tree);
5708 Linker_Package : constant Prj.Package_Id :=
5710 (Name => Name_Linker,
5711 In_Packages => The_Packages,
5712 In_Tree => Project_Tree);
5715 -- We fail if we cannot find the main source file
5716 -- as an immediate source of the main project file.
5718 if Main_Unit_File_Name = "" then
5719 Make_Failed ('"' & Main_Source_File_Name,
5720 """ is not a unit
of project
",
5721 Project_File_Name.all & ".");
5724 -- Remove any directory information from the main
5725 -- source file name.
5728 Pos : Natural := Main_Unit_File_Name'Last;
5732 exit when Pos < Main_Unit_File_Name'First
5734 Main_Unit_File_Name (Pos) = Directory_Separator;
5738 Name_Len := Main_Unit_File_Name'Last - Pos;
5740 Name_Buffer (1 .. Name_Len) :=
5742 (Pos + 1 .. Main_Unit_File_Name'Last);
5744 Main_Source_File := Name_Find;
5748 -- We now deal with the binder and linker switches.
5749 -- If no project file is used, there is nothing to do
5750 -- because the binder and linker switches are the same
5753 -- Reset the tables Binder_Switches and Linker_Switches
5755 Binder_Switches.Set_Last (Last_Binder_Switch);
5756 Linker_Switches.Set_Last (Last_Linker_Switch);
5758 -- Add binder switches from the project file for this main,
5761 if Do_Bind_Step and Binder_Package /= No_Package then
5762 if Verbose_Mode then
5763 Write_Str ("Adding binder switches
for """);
5764 Write_Str (Main_Unit_File_Name);
5769 (File_Name => Main_Unit_File_Name,
5770 Index => Main_Index,
5771 The_Package => Binder_Package,
5775 -- Add linker switches from the project file for this main,
5778 if Do_Link_Step and Linker_Package /= No_Package then
5779 if Verbose_Mode then
5780 Write_Str ("Adding linker switches
for""");
5781 Write_Str (Main_Unit_File_Name);
5786 (File_Name => Main_Unit_File_Name,
5787 Index => Main_Index,
5788 The_Package => Linker_Package,
5792 -- As we are using a project file, for relative paths we add
5793 -- the current working directory for any relative path on
5794 -- the command line and the project directory, for any
5795 -- relative path in the project file.
5798 Dir_Path : constant String_Access :=
5799 new String'(Get_Name_String
5800 (Project_Tree.Projects.Table
5801 (Main_Project).Directory));
5804 J in Last_Binder_Switch + 1 .. Binder_Switches.Last
5806 Test_If_Relative_Path
5807 (Binder_Switches.Table (J),
5808 Parent => Dir_Path, Including_L_Switch => False);
5812 J in Last_Linker_Switch + 1 .. Linker_Switches.Last
5814 Test_If_Relative_Path
5815 (Linker_Switches.Table (J), Parent => Dir_Path);
5819 -- We now put in the Binder_Switches and Linker_Switches
5820 -- tables, the binder and linker switches of the command
5821 -- line that have been put in the Saved_ tables.
5822 -- These switches will follow the project file switches.
5824 for J in 1 .. Saved_Binder_Switches.Last loop
5826 (Saved_Binder_Switches.Table (J),
5831 for J in 1 .. Saved_Linker_Switches.Last loop
5833 (Saved_Linker_Switches.Table (J),
5841 -- Remove all marks to be sure to check sources for all executables,
5842 -- as the switches may be different and -s may be in use.
5845 end loop Multiple_Main_Loop;
5847 if Failed_Links.Last > 0 then
5848 for Index in 1 .. Successful_Links.Last loop
5849 Write_Str ("Linking
of """);
5850 Write_Str (Get_Name_String (Successful_Links.Table (Index)));
5851 Write_Line (""" succeeded
.");
5854 for Index in 1 .. Failed_Links.Last loop
5855 Write_Str ("Linking
of """);
5856 Write_Str (Get_Name_String (Failed_Links.Table (Index)));
5857 Write_Line (""" failed
.");
5860 if Total_Compilation_Failures = 0 then
5861 raise Compilation_Failed;
5865 if Total_Compilation_Failures /= 0 then
5866 List_Bad_Compilations;
5867 raise Compilation_Failed;
5870 -- Delete the temporary mapping file that was created if we are
5871 -- using project files.
5873 if not Debug.Debug_Flag_N then
5874 Delete_Mapping_Files;
5875 Prj.Env.Delete_All_Path_Files (Project_Tree);
5878 Exit_Program (E_Success);
5882 Make_Failed ("*** bind failed
.");
5884 when Compilation_Failed =>
5885 if not Debug.Debug_Flag_N then
5886 Delete_Mapping_Files;
5887 Prj.Env.Delete_All_Path_Files (Project_Tree);
5890 Exit_Program (E_Fatal);
5893 Make_Failed ("*** link failed
.");
5896 Write_Line (Exception_Information (X));
5897 Make_Failed ("INTERNAL ERROR
. Please report
.");
5904 function Hash (F : Name_Id) return Header_Num is
5906 return Header_Num (1 + F mod Max_Header);
5909 --------------------
5910 -- In_Ada_Lib_Dir --
5911 --------------------
5913 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean is
5914 D : constant Name_Id := Get_Directory (File);
5915 B : constant Byte := Get_Name_Table_Byte (D);
5917 return (B and Ada_Lib_Dir) /= 0;
5924 procedure Inform (N : Name_Id := No_Name; Msg : String) is
5926 Osint.Write_Program_Name;
5930 if N /= No_Name then
5940 -----------------------
5941 -- Init_Mapping_File --
5942 -----------------------
5944 procedure Init_Mapping_File
5945 (Project : Project_Id;
5946 File_Index : in out Natural)
5948 FD : File_Descriptor;
5951 -- For call to Close
5954 -- Increase the index of the last mapping file for this project
5956 Last_Mapping_File_Names (Project) :=
5957 Last_Mapping_File_Names (Project) + 1;
5959 -- If there is a project file, call Create_Mapping_File with
5962 if Project /= No_Project then
5963 Prj.Env.Create_Mapping_File
5964 (Project, Project_Tree,
5965 The_Mapping_File_Names
5966 (Project, Last_Mapping_File_Names (Project)));
5968 -- Otherwise, just create an empty file
5971 Tempdir.Create_Temp_File
5973 The_Mapping_File_Names
5974 (No_Project, Last_Mapping_File_Names (No_Project)));
5975 if FD = Invalid_FD then
5976 Make_Failed ("disk full
");
5982 Make_Failed ("disk full
");
5986 -- And return the index of the newly created file
5988 File_Index := Last_Mapping_File_Names (Project);
5989 end Init_Mapping_File;
5997 First_Q_Initialization := False;
5999 Q.Set_Last (Q.First);
6006 procedure Initialize is
6008 -- Override default initialization of Check_Object_Consistency
6009 -- since this is normally False for GNATBIND, but is True for
6010 -- GNATMAKE since we do not need to check source consistency
6011 -- again once GNATMAKE has looked at the sources to check.
6013 Check_Object_Consistency := True;
6015 -- Package initializations. The order of calls is important here
6017 Output.Set_Standard_Error;
6020 Binder_Switches.Init;
6021 Linker_Switches.Init;
6028 Prj.Initialize (Project_Tree);
6032 RTS_Specified := null;
6036 -- Add the directory where gnatmake is invoked in front of the
6037 -- path, if gnatmake is invoked with directory information.
6038 -- Only do this if the platform is not VMS, where the notion of path
6039 -- does not really exist.
6043 Command : constant String := Command_Name;
6046 for Index in reverse Command'Range loop
6047 if Command (Index) = Directory_Separator then
6049 Absolute_Dir : constant String :=
6051 (Command (Command'First .. Index));
6053 PATH : constant String :=
6056 Getenv ("PATH
").all;
6059 Setenv ("PATH
", PATH);
6068 -- Scan the switches and arguments
6070 Scan_Args : for Next_Arg in 1 .. Argument_Count loop
6071 Scan_Make_Arg (Argument (Next_Arg), And_Save => True);
6074 if Usage_Requested then
6078 -- Test for trailing -P switch
6080 if Project_File_Name_Present and then Project_File_Name = null then
6081 Make_Failed ("project file name missing after
-P
");
6083 -- Test for trailing -o switch
6085 elsif Output_File_Name_Present
6086 and then not Output_File_Name_Seen
6088 Make_Failed ("output file name missing after
-o
");
6090 -- Test for trailing -D switch
6092 elsif Object_Directory_Present
6093 and then not Object_Directory_Seen then
6094 Make_Failed ("object directory missing after
-D
");
6097 -- Test for simultaneity of -i and -D
6099 if Object_Directory_Path /= null and then In_Place_Mode then
6100 Make_Failed ("-i
and -D cannot be used simutaneously
");
6103 -- Deal with -C= switch
6105 if Gnatmake_Mapping_File /= null then
6106 -- First, check compatibility with other switches
6108 if Project_File_Name /= null then
6109 Make_Failed ("-C
= switch
is not compatible
with -P switch
");
6111 elsif Saved_Maximum_Processes > 1 then
6112 Make_Failed ("-C
= switch
is not compatible
with -jnnn switch
");
6115 Fmap.Initialize (Gnatmake_Mapping_File.all);
6117 ("-gnatem
=" & Gnatmake_Mapping_File.all,
6122 if Project_File_Name /= null then
6124 -- A project file was specified by a -P switch
6126 if Verbose_Mode then
6128 Write_Str ("Parsing Project File
""");
6129 Write_Str (Project_File_Name.all);
6134 -- Avoid looking in the current directory for ALI files
6136 -- Look_In_Primary_Dir := False;
6138 -- Set the project parsing verbosity to whatever was specified
6139 -- by a possible -vP switch.
6141 Prj.Pars.Set_Verbosity (To => Current_Verbosity);
6143 -- Parse the project file.
6144 -- If there is an error, Main_Project will still be No_Project.
6147 (Project => Main_Project,
6148 In_Tree => Project_Tree,
6149 Project_File_Name => Project_File_Name.all,
6150 Packages_To_Check => Packages_To_Check_By_Gnatmake);
6152 if Main_Project = No_Project then
6153 Make_Failed ("""", Project_File_Name.all, """ processing failed
");
6156 if Verbose_Mode then
6158 Write_Str ("Parsing
of Project File
""");
6159 Write_Str (Project_File_Name.all);
6160 Write_Str (""" is finished
.");
6164 -- We add the source directories and the object directories
6165 -- to the search paths.
6167 Add_Source_Directories (Main_Project, Project_Tree);
6168 Add_Object_Directories (Main_Project, Project_Tree);
6170 -- Compute depth of each project
6172 for Proj in Project_Table.First ..
6173 Project_Table.Last (Project_Tree.Projects)
6175 Project_Tree.Projects.Table (Proj).Seen := False;
6176 Project_Tree.Projects.Table (Proj).Depth := 0;
6179 Recursive_Compute_Depth
6180 (Main_Project, Depth => 1);
6182 -- For each project compute the list of the projects it imports
6183 -- directly or indirectly.
6185 for Proj in Project_Table.First ..
6186 Project_Table.Last (Project_Tree.Projects)
6188 Compute_All_Imported_Projects (Proj);
6193 Osint.Add_Default_Search_Dirs;
6195 -- Source file lookups should be cached for efficiency.
6196 -- Source files are not supposed to change. However, we do that now
6197 -- only if no project file is used; if a project file is used, we
6198 -- do it just after changing the directory to the object directory.
6200 Osint.Source_File_Data (Cache => True);
6202 -- Read gnat.adc file to initialize Fname.UF
6204 Fname.UF.Initialize;
6207 Fname.SF.Read_Source_File_Name_Pragmas;
6210 when Err : SFN_Scan.Syntax_Error_In_GNAT_ADC =>
6211 Make_Failed (Exception_Message (Err));
6215 -- Make sure no project object directory is recorded
6217 Project_Object_Directory := No_Project;
6221 ----------------------------
6222 -- Insert_Project_Sources --
6223 ----------------------------
6225 procedure Insert_Project_Sources
6226 (The_Project : Project_Id;
6227 All_Projects : Boolean;
6230 Put_In_Q : Boolean := Into_Q;
6234 Extending : constant Boolean :=
6235 Project_Tree.Projects.Table
6236 (The_Project).Extends /= No_Project;
6238 function Check_Project (P : Project_Id) return Boolean;
6239 -- Returns True if P is The_Project or a project extended by
6246 function Check_Project (P : Project_Id) return Boolean is
6248 if All_Projects or P = The_Project then
6250 elsif Extending then
6252 Data : Project_Data :=
6253 Project_Tree.Projects.Table (The_Project);
6257 if P = Data.Extends then
6261 Data := Project_Tree.Projects.Table (Data.Extends);
6262 exit when Data.Extends = No_Project;
6270 -- Start of processing for Insert_Project_Sources
6273 -- For all the sources in the project files,
6275 for Id in Unit_Table.First ..
6276 Unit_Table.Last (Project_Tree.Units)
6278 Unit := Project_Tree.Units.Table (Id);
6281 -- If there is a source for the body, and the body has not been
6284 if Unit.File_Names (Body_Part).Name /= No_Name
6285 and then Unit.File_Names (Body_Part).Path /= Slash
6287 -- And it is a source for the specified project
6289 if Check_Project (Unit.File_Names (Body_Part).Project) then
6291 -- If we don't have a spec, we cannot consider the source
6292 -- if it is a subunit
6294 if Unit.File_Names (Specification).Name = No_Name then
6296 Src_Ind : Source_File_Index;
6298 -- Here we are cheating a little bit: we don't want to
6299 -- use Sinput.L, because it depends on the GNAT tree
6300 -- (Atree, Sinfo, ...). So, we pretend that it is
6301 -- a project file, and we use Sinput.P.
6302 -- Source_File_Is_Subunit is just scanning through
6303 -- the file until it finds one of the reserved words
6304 -- separate, procedure, function, generic or package.
6305 -- Fortunately, these Ada reserved words are also
6306 -- reserved for project files.
6309 Src_Ind := Sinput.P.Load_Project_File
6311 (Unit.File_Names (Body_Part).Path));
6313 -- If it is a subunit, discard it
6315 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
6319 Sfile := Unit.File_Names (Body_Part).Name;
6324 Sfile := Unit.File_Names (Body_Part).Name;
6328 elsif Unit.File_Names (Specification).Name /= No_Name
6329 and then Unit.File_Names (Specification).Path /= Slash
6330 and then Check_Project (Unit.File_Names (Specification).Project)
6332 -- If there is no source for the body, but there is a source
6333 -- for the spec which has not been locally removed, then we take
6336 Sfile := Unit.File_Names (Specification).Name;
6339 -- If Put_In_Q is True, we insert into the Q
6343 -- For the first source inserted into the Q, we need
6344 -- to initialize the Q, but not for the subsequent sources.
6346 if First_Q_Initialization then
6350 -- And of course, we only insert in the Q if the source
6353 if Sfile /= No_Name and then not Is_Marked (Sfile) then
6354 if Verbose_Mode then
6355 Write_Str ("Adding
""");
6356 Write_Str (Get_Name_String (Sfile));
6357 Write_Line (""" to the queue
");
6364 elsif Sfile /= No_Name then
6366 -- If Put_In_Q is False, we add the source as it it were
6367 -- specified on the command line, and we set Put_In_Q to True,
6368 -- so that the following sources will be put directly in the
6369 -- queue. This will allow parallel compilation processes if -jx
6372 if Verbose_Mode then
6373 Write_Str ("Adding
""");
6374 Write_Str (Get_Name_String (Sfile));
6375 Write_Line (""" as
if on the command line
");
6378 Osint.Add_File (Get_Name_String (Sfile));
6381 -- As we may look into the Q later, ensure the Q has been
6382 -- initialized to avoid errors.
6384 if First_Q_Initialization then
6389 end Insert_Project_Sources;
6396 (Source_File : File_Name_Type;
6397 Source_Unit : Unit_Name_Type := No_Name;
6401 if Debug.Debug_Flag_Q then
6402 Write_Str (" Q
:= Q
+ [ ");
6403 Write_Name (Source_File);
6415 (File => Source_File,
6416 Unit => Source_Unit,
6421 ---------------------
6422 -- Is_In_Obsoleted --
6423 ---------------------
6425 function Is_In_Obsoleted (F : Name_Id) return Boolean is
6432 Name : constant String := Get_Name_String (F);
6433 First : Natural := Name'Last;
6437 while First > Name'First
6438 and then Name (First - 1) /= Directory_Separator
6439 and then Name (First - 1) /= '/'
6444 if First /= Name'First then
6446 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
6450 return Obsoleted.Get (F2);
6453 end Is_In_Obsoleted;
6455 ----------------------------
6456 -- Is_In_Object_Directory --
6457 ----------------------------
6459 function Is_In_Object_Directory
6460 (Source_File : File_Name_Type;
6461 Full_Lib_File : File_Name_Type) return Boolean
6464 -- There is something to check only when using project files.
6465 -- Otherwise, this function returns True (last line of the function).
6467 if Main_Project /= No_Project then
6469 Source_File_Name : constant String :=
6470 Get_Name_String (Source_File);
6471 Saved_Verbosity : constant Verbosity := Current_Verbosity;
6472 Project : Project_Id := No_Project;
6473 Path_Name : Name_Id := No_Name;
6474 Data : Project_Data;
6477 -- Call Get_Reference to know the ultimate extending project of
6478 -- the source. Call it with verbosity default to avoid verbose
6481 Current_Verbosity := Default;
6484 (Source_File_Name => Source_File_Name,
6486 In_Tree => Project_Tree,
6488 Current_Verbosity := Saved_Verbosity;
6490 -- If this source is in a project, check that the ALI file is
6491 -- in its object directory. If it is not, return False, so that
6492 -- the ALI file will not be skipped.
6494 -- If the source is not in an extending project, we fall back to
6495 -- the general case and return True at the end of the function.
6497 if Project /= No_Project
6498 and then Project_Tree.Projects.Table
6499 (Project).Extends /= No_Project
6501 Data := Project_Tree.Projects.Table (Project);
6504 Object_Directory : constant String :=
6507 (Data.Object_Directory));
6509 Olast : Natural := Object_Directory'Last;
6511 Lib_File_Directory : constant String :=
6512 Normalize_Pathname (Dir_Name
6513 (Get_Name_String (Full_Lib_File)));
6515 Llast : Natural := Lib_File_Directory'Last;
6518 -- For directories, Normalize_Pathname may or may not put
6519 -- a directory separator at the end, depending on its input.
6520 -- Remove any last directory separator before comparaison.
6521 -- Returns True only if the two directories are the same.
6523 if Object_Directory (Olast) = Directory_Separator then
6527 if Lib_File_Directory (Llast) = Directory_Separator then
6531 return Object_Directory (Object_Directory'First .. Olast) =
6532 Lib_File_Directory (Lib_File_Directory'First .. Llast);
6538 -- When the source is not in a project file, always return True
6541 end Is_In_Object_Directory;
6547 procedure Link (ALI_File : File_Name_Type; Args : Argument_List) is
6548 Link_Args : Argument_List (1 .. Args'Length + 1);
6552 Get_Name_String (ALI_File);
6553 Link_Args (1) := new String'(Name_Buffer (1 .. Name_Len));
6555 Link_Args (2 .. Args'Length + 1) := Args;
6557 GNAT.OS_Lib.Normalize_Arguments (Link_Args);
6559 Display (Gnatlink.all, Link_Args);
6561 if Gnatlink_Path = null then
6562 Make_Failed ("error
, unable to locate
", Gnatlink.all);
6565 GNAT.OS_Lib.Spawn (Gnatlink_Path.all, Link_Args, Success);
6572 ---------------------------
6573 -- List_Bad_Compilations --
6574 ---------------------------
6576 procedure List_Bad_Compilations is
6578 for J in Bad_Compilation.First .. Bad_Compilation.Last loop
6579 if Bad_Compilation.Table (J).File = No_File then
6581 elsif not Bad_Compilation.Table (J).Found then
6582 Inform (Bad_Compilation.Table (J).File, "not found
");
6584 Inform (Bad_Compilation.Table (J).File, "compilation error
");
6587 end List_Bad_Compilations;
6593 procedure List_Depend is
6600 Line_Size : constant := 77;
6603 Set_Standard_Output;
6605 for A in ALIs.First .. ALIs.Last loop
6606 Lib_Name := ALIs.Table (A).Afile;
6608 -- We have to provide the full library file name in In_Place_Mode
6610 if In_Place_Mode then
6611 Lib_Name := Full_Lib_File_Name (Lib_Name);
6614 Obj_Name := Object_File_Name (Lib_Name);
6615 Write_Name (Obj_Name);
6618 Get_Name_String (Obj_Name);
6620 Line_Pos := Len + 2;
6622 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
6623 Src_Name := Sdep.Table (D).Sfile;
6625 if Is_Internal_File_Name (Src_Name)
6626 and then not Check_Readonly_Files
6630 if not Quiet_Output then
6631 Src_Name := Full_Source_Name (Src_Name);
6634 Get_Name_String (Src_Name);
6637 if Line_Pos + Len + 1 > Line_Size then
6643 Line_Pos
:= Line_Pos
+ Len
+ 1;
6646 Write_Name
(Src_Name
);
6660 procedure Make_Failed
(S1
: String; S2
: String := ""; S3
: String := "") is
6662 Delete_All_Temp_Files
;
6663 Osint
.Fail
(S1
, S2
, S3
);
6666 --------------------
6667 -- Mark_Directory --
6668 --------------------
6670 procedure Mark_Directory
6672 Mark
: Lib_Mark_Type
;
6673 On_Command_Line
: Boolean)
6679 if On_Command_Line
then
6681 Real_Path
: constant String :=
6682 Normalize_Pathname
(Dir
);
6685 if Real_Path
'Length = 0 then
6686 Name_Len
:= Dir
'Length;
6687 Name_Buffer
(1 .. Name_Len
) := Dir
;
6690 Name_Len
:= Real_Path
'Length;
6691 Name_Buffer
(1 .. Name_Len
) := Real_Path
;
6697 Real_Path
: constant String :=
6701 (Project_Tree
.Projects
.Table
(Main_Project
).Directory
));
6704 if Real_Path
'Length = 0 then
6705 Name_Len
:= Dir
'Length;
6706 Name_Buffer
(1 .. Name_Len
) := Dir
;
6709 Name_Len
:= Real_Path
'Length;
6710 Name_Buffer
(1 .. Name_Len
) := Real_Path
;
6715 -- Last character is supposed to be a directory separator
6717 if not Is_Directory_Separator
(Name_Buffer
(Name_Len
)) then
6718 Name_Len
:= Name_Len
+ 1;
6719 Name_Buffer
(Name_Len
) := Directory_Separator
;
6722 -- Add flags to the already existing flags
6725 B
:= Get_Name_Table_Byte
(N
);
6726 Set_Name_Table_Byte
(N
, B
or Mark
);
6729 -----------------------------
6730 -- Recursive_Compute_Depth --
6731 -----------------------------
6733 procedure Recursive_Compute_Depth
6734 (Project
: Project_Id
;
6737 List
: Project_List
;
6741 -- Nothing to do if there is no project or if the project has already
6742 -- been seen or if the depth is large enough.
6744 if Project
= No_Project
6745 or else Project_Tree
.Projects
.Table
(Project
).Seen
6746 or else Project_Tree
.Projects
.Table
(Project
).Depth
>= Depth
6751 Project_Tree
.Projects
.Table
(Project
).Depth
:= Depth
;
6753 -- Mark the project as Seen to avoid endless loop caused by limited
6756 Project_Tree
.Projects
.Table
(Project
).Seen
:= True;
6758 List
:= Project_Tree
.Projects
.Table
(Project
).Imported_Projects
;
6760 -- Visit each imported project
6762 while List
/= Empty_Project_List
loop
6763 Proj
:= Project_Tree
.Project_Lists
.Table
(List
).Project
;
6764 List
:= Project_Tree
.Project_Lists
.Table
(List
).Next
;
6765 Recursive_Compute_Depth
6767 Depth
=> Depth
+ 1);
6770 -- Visit a project being extended, if any
6772 Recursive_Compute_Depth
6773 (Project
=> Project_Tree
.Projects
.Table
(Project
).Extends
,
6774 Depth
=> Depth
+ 1);
6776 -- Reset the Seen flag, as we leave this project
6778 Project_Tree
.Projects
.Table
(Project
).Seen
:= False;
6779 end Recursive_Compute_Depth
;
6781 -----------------------
6782 -- Sigint_Intercpted --
6783 -----------------------
6785 procedure Sigint_Intercepted
is
6787 Write_Line
("*** Interrupted ***");
6788 Delete_All_Temp_Files
;
6790 end Sigint_Intercepted
;
6796 procedure Scan_Make_Arg
(Argv
: String; And_Save
: Boolean) is
6798 pragma Assert
(Argv
'First = 1);
6800 if Argv
'Length = 0 then
6804 -- If the previous switch has set the Project_File_Name_Present
6805 -- flag (that is we have seen a -P alone), then the next argument is
6806 -- the name of the project file.
6808 if Project_File_Name_Present
and then Project_File_Name
= null then
6809 if Argv
(1) = '-' then
6810 Make_Failed
("project file name missing after -P");
6813 Project_File_Name_Present
:= False;
6814 Project_File_Name
:= new String'(Argv);
6817 -- If the previous switch has set the Output_File_Name_Present
6818 -- flag (that is we have seen a -o), then the next argument is
6819 -- the name of the output executable.
6821 elsif Output_File_Name_Present
6822 and then not Output_File_Name_Seen
6824 Output_File_Name_Seen := True;
6826 if Argv (1) = '-' then
6827 Make_Failed ("output file name missing after -o");
6830 Add_Switch ("-o", Linker, And_Save => And_Save);
6832 -- Automatically add the executable suffix if it has not been
6833 -- specified explicitly.
6836 Canonical_Argv : String := Argv;
6838 -- Get the file name in canonical case to accept as is
6839 -- names ending with ".EXE" on VMS and Windows.
6841 Canonical_Case_File_Name (Canonical_Argv);
6843 if Executable_Suffix'Length /= 0
6844 and then (Canonical_Argv'Length <= Executable_Suffix'Length
6845 or else Canonical_Argv
6846 (Canonical_Argv'Last -
6847 Executable_Suffix'Length + 1
6848 .. Canonical_Argv'Last)
6849 /= Executable_Suffix)
6852 (Argv & Executable_Suffix,
6854 And_Save => And_Save);
6856 Add_Switch (Argv, Linker, And_Save => And_Save);
6861 -- If the previous switch has set the Object_Directory_Present flag
6862 -- (that is we have seen a -D), then the next argument is
6863 -- the path name of the object directory..
6865 elsif Object_Directory_Present
6866 and then not Object_Directory_Seen
6868 Object_Directory_Seen := True;
6870 if Argv (1) = '-' then
6871 Make_Failed ("object directory path name missing after -D");
6873 elsif not Is_Directory (Argv) then
6874 Make_Failed ("cannot find object directory """, Argv, """");
6877 Add_Lib_Search_Dir (Argv);
6879 -- Specify the object directory to the binder
6881 Add_Switch ("-aO" & Argv, Binder, And_Save => And_Save);
6883 -- Record the object directory. Make sure it ends with a directory
6886 if Argv (Argv'Last) = Directory_Separator then
6887 Object_Directory_Path := new String'(Argv
);
6890 Object_Directory_Path
:=
6891 new String'(Argv & Directory_Separator);
6895 -- Then check if we are dealing with -cargs/-bargs/-largs/-margs
6897 elsif Argv = "-bargs"
6906 when 'c
' => Program_Args := Compiler;
6907 when 'b
' => Program_Args := Binder;
6908 when 'l
' => Program_Args := Linker;
6909 when 'm
' => Program_Args := None;
6912 raise Program_Error;
6915 -- A special test is needed for the -o switch within a -largs
6916 -- since that is another way to specify the name of the final
6919 elsif Program_Args = Linker
6920 and then Argv = "-o"
6922 Make_Failed ("switch -o not allowed within a -largs. " &
6923 "Use -o directly.");
6925 -- Check to see if we are reading switches after a -cargs,
6926 -- -bargs or -largs switch. If yes save it.
6928 elsif Program_Args /= None then
6930 -- Check to see if we are reading -I switches in order
6931 -- to take into account in the src & lib search directories.
6933 if Argv'Length > 2 and then Argv (1 .. 2) = "-I" then
6934 if Argv (3 .. Argv'Last) = "-" then
6935 Look_In_Primary_Dir := False;
6937 elsif Program_Args = Compiler then
6938 if Argv (3 .. Argv'Last) /= "-" then
6939 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
6942 elsif Program_Args = Binder then
6943 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
6947 Add_Switch (Argv, Program_Args, And_Save => And_Save);
6949 -- Handle non-default compiler, binder, linker, and handle --RTS switch
6951 elsif Argv'Length > 2 and then Argv (1 .. 2) = "--" then
6953 and then Argv (1 .. 6) = "--GCC="
6956 Program_Args : constant Argument_List_Access :=
6957 Argument_String_To_List
6958 (Argv (7 .. Argv'Last));
6962 Saved_Gcc := new String'(Program_Args
.all (1).all);
6964 Gcc
:= new String'(Program_Args.all (1).all);
6967 for J in 2 .. Program_Args.all'Last loop
6969 (Program_Args.all (J).all,
6971 And_Save => And_Save);
6975 elsif Argv'Length > 11
6976 and then Argv (1 .. 11) = "--GNATBIND="
6979 Program_Args : constant Argument_List_Access :=
6980 Argument_String_To_List
6981 (Argv (12 .. Argv'Last));
6985 Saved_Gnatbind := new String'(Program_Args
.all (1).all);
6987 Gnatbind
:= new String'(Program_Args.all (1).all);
6990 for J in 2 .. Program_Args.all'Last loop
6992 (Program_Args.all (J).all, Binder, And_Save => And_Save);
6996 elsif Argv'Length > 11
6997 and then Argv (1 .. 11) = "--GNATLINK="
7000 Program_Args : constant Argument_List_Access :=
7001 Argument_String_To_List
7002 (Argv (12 .. Argv'Last));
7005 Saved_Gnatlink := new String'(Program_Args
.all (1).all);
7007 Gnatlink
:= new String'(Program_Args.all (1).all);
7010 for J in 2 .. Program_Args.all'Last loop
7011 Add_Switch (Program_Args.all (J).all, Linker);
7015 elsif Argv'Length >= 5 and then
7016 Argv (1 .. 5) = "--RTS"
7018 Add_Switch (Argv, Compiler, And_Save => And_Save);
7019 Add_Switch (Argv, Binder, And_Save => And_Save);
7021 if Argv'Length <= 6 or else Argv (6) /= '=' then
7022 Make_Failed ("missing path for --RTS");
7025 -- Check that this is the first time we see this switch or
7026 -- if it is not the first time, the same path is specified.
7028 if RTS_Specified = null then
7029 RTS_Specified := new String'(Argv
(7 .. Argv
'Last));
7031 elsif RTS_Specified
.all /= Argv
(7 .. Argv
'Last) then
7032 Make_Failed
("--RTS cannot be specified multiple times");
7035 -- Valid --RTS switch
7042 Src_Path_Name
: constant String_Ptr
:=
7044 (Argv
(7 .. Argv
'Last), Include
);
7046 Lib_Path_Name
: constant String_Ptr
:=
7048 (Argv
(7 .. Argv
'Last), Objects
);
7051 if Src_Path_Name
/= null and then
7052 Lib_Path_Name
/= null
7054 -- Set the RTS_*_Path_Name variables, so that the correct
7055 -- directories will be set when
7056 -- Osint.Add_Default_Search_Dirs will be called later.
7058 RTS_Src_Path_Name
:= Src_Path_Name
;
7059 RTS_Lib_Path_Name
:= Lib_Path_Name
;
7061 elsif Src_Path_Name
= null
7062 and Lib_Path_Name
= null then
7063 Make_Failed
("RTS path not valid: missing " &
7064 "adainclude and adalib directories");
7066 elsif Src_Path_Name
= null then
7067 Make_Failed
("RTS path not valid: missing adainclude " &
7070 elsif Lib_Path_Name
= null then
7071 Make_Failed
("RTS path not valid: missing adalib " &
7078 Make_Failed
("unknown switch: ", Argv
);
7081 -- If we have seen a regular switch process it
7083 elsif Argv
(1) = '-' then
7085 if Argv
'Length = 1 then
7086 Make_Failed
("switch character cannot be followed by a blank");
7090 elsif Argv
(2 .. Argv
'Last) = "I-" then
7091 Look_In_Primary_Dir
:= False;
7093 -- Forbid -?- or -??- where ? is any character
7095 elsif (Argv
'Length = 3 and then Argv
(3) = '-')
7096 or else (Argv
'Length = 4 and then Argv
(4) = '-')
7098 Make_Failed
("trailing ""-"" at the end of ", Argv
, " forbidden.");
7102 elsif Argv
(2) = 'I' then
7103 Add_Source_Search_Dir
(Argv
(3 .. Argv
'Last), And_Save
);
7104 Add_Library_Search_Dir
(Argv
(3 .. Argv
'Last), And_Save
);
7105 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
7106 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
7108 -- -aIdir (to gcc this is like a -I switch)
7110 elsif Argv
'Length >= 3 and then Argv
(2 .. 3) = "aI" then
7111 Add_Source_Search_Dir
(Argv
(4 .. Argv
'Last), And_Save
);
7112 Add_Switch
("-I" & Argv
(4 .. Argv
'Last),
7114 And_Save
=> And_Save
);
7115 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
7119 elsif Argv
'Length >= 3 and then Argv
(2 .. 3) = "aO" then
7120 Add_Library_Search_Dir
(Argv
(4 .. Argv
'Last), And_Save
);
7121 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
7123 -- -aLdir (to gnatbind this is like a -aO switch)
7125 elsif Argv
'Length >= 3 and then Argv
(2 .. 3) = "aL" then
7126 Mark_Directory
(Argv
(4 .. Argv
'Last), Ada_Lib_Dir
, And_Save
);
7127 Add_Library_Search_Dir
(Argv
(4 .. Argv
'Last), And_Save
);
7128 Add_Switch
("-aO" & Argv
(4 .. Argv
'Last),
7130 And_Save
=> And_Save
);
7132 -- -Adir (to gnatbind this is like a -aO switch, to gcc like a -I)
7134 elsif Argv
(2) = 'A' then
7135 Mark_Directory
(Argv
(3 .. Argv
'Last), Ada_Lib_Dir
, And_Save
);
7136 Add_Source_Search_Dir
(Argv
(3 .. Argv
'Last), And_Save
);
7137 Add_Library_Search_Dir
(Argv
(3 .. Argv
'Last), And_Save
);
7138 Add_Switch
("-I" & Argv
(3 .. Argv
'Last),
7140 And_Save
=> And_Save
);
7141 Add_Switch
("-aO" & Argv
(3 .. Argv
'Last),
7143 And_Save
=> And_Save
);
7147 elsif Argv
(2) = 'L' then
7148 Add_Switch
(Argv
, Linker
, And_Save
=> And_Save
);
7150 -- For -gxxxxx, -pg, -mxxx, -fxxx: give the switch to both the
7151 -- compiler and the linker (except for -gnatxxx which is only for
7152 -- the compiler). Some of the -mxxx (for example -m64) and -fxxx
7153 -- (for example -ftest-coverage for gcov) need to be used when
7154 -- compiling the binder generated files, and using all these gcc
7155 -- switches for the binder generated files should not be a problem.
7158 (Argv
(2) = 'g' and then (Argv
'Last < 5
7159 or else Argv
(2 .. 5) /= "gnat"))
7160 or else Argv
(2 .. Argv
'Last) = "pg"
7161 or else (Argv
(2) = 'm' and then Argv
'Last > 2)
7162 or else (Argv
(2) = 'f' and then Argv
'Last > 2)
7164 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
7165 Add_Switch
(Argv
, Linker
, And_Save
=> And_Save
);
7167 -- -C=<mapping file>
7169 elsif Argv
'Last > 2 and then Argv
(2) = 'C' then
7171 if Argv
(3) /= '=' or else Argv
'Last <= 3 then
7172 Make_Failed
("illegal switch ", Argv
);
7175 Gnatmake_Mapping_File
:= new String'(Argv (4 .. Argv'Last));
7180 elsif Argv'Last = 2 and then Argv (2) = 'D
' then
7181 if Project_File_Name /= null then
7182 Make_Failed ("-D cannot be used in conjunction with a " &
7186 Scan_Make_Switches (Argv);
7191 elsif Argv (2) = 'd
'
7192 and then Argv'Last = 2
7194 Display_Compilation_Progress := True;
7198 elsif Argv'Last = 2 and then Argv (2) = 'i
' then
7199 if Project_File_Name /= null then
7200 Make_Failed ("-i cannot be used in conjunction with a " &
7204 Scan_Make_Switches (Argv);
7207 -- -j (need to save the result)
7209 elsif Argv (2) = 'j
' then
7210 Scan_Make_Switches (Argv);
7213 Saved_Maximum_Processes := Maximum_Processes;
7218 elsif Argv (2) = 'm
'
7219 and then Argv'Last = 2
7221 Minimal_Recompilation := True;
7225 elsif Argv (2) = 'u
'
7226 and then Argv'Last = 2
7228 Unique_Compile := True;
7229 Compile_Only := True;
7230 Do_Bind_Step := False;
7231 Do_Link_Step := False;
7235 elsif Argv (2) = 'U
'
7236 and then Argv'Last = 2
7238 Unique_Compile_All_Projects := True;
7239 Unique_Compile := True;
7240 Compile_Only := True;
7241 Do_Bind_Step := False;
7242 Do_Link_Step := False;
7244 -- -Pprj or -P prj (only once, and only on the command line)
7246 elsif Argv (2) = 'P
' then
7247 if Project_File_Name /= null then
7248 Make_Failed ("cannot have several project files specified");
7250 elsif Object_Directory_Path /= null then
7251 Make_Failed ("-D cannot be used in conjunction with a " &
7254 elsif In_Place_Mode then
7255 Make_Failed ("-i cannot be used in conjunction with a " &
7258 elsif not And_Save then
7260 -- It could be a tool other than gnatmake (i.e, gnatdist)
7261 -- or a -P switch inside a project file.
7264 ("either the tool is not ""project-aware"" or " &
7265 "a project file is specified inside a project file");
7267 elsif Argv'Last = 2 then
7269 -- -P is used alone: the project file name is the next option
7271 Project_File_Name_Present := True;
7274 Project_File_Name := new String'(Argv
(3 .. Argv
'Last));
7277 -- -vPx (verbosity of the parsing of the project files)
7280 and then Argv
(2 .. 3) = "vP"
7281 and then Argv
(4) in '0' .. '2'
7286 Current_Verbosity
:= Prj
.Default
;
7288 Current_Verbosity
:= Prj
.Medium
;
7290 Current_Verbosity
:= Prj
.High
;
7296 -- -Xext=val (External assignment)
7298 elsif Argv
(2) = 'X'
7299 and then Is_External_Assignment
(Argv
)
7301 -- Is_External_Assignment has side effects
7302 -- when it returns True;
7306 -- If -gnath is present, then generate the usage information
7307 -- right now and do not pass this option on to the compiler calls.
7309 elsif Argv
= "-gnath" then
7312 -- If -gnatc is specified, make sure the bind step and the link
7313 -- step are not executed.
7315 elsif Argv
'Length >= 6 and then Argv
(2 .. 6) = "gnatc" then
7317 -- If -gnatc is specified, make sure the bind step and the link
7318 -- step are not executed.
7320 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
7321 Operating_Mode
:= Check_Semantics
;
7322 Check_Object_Consistency
:= False;
7323 Compile_Only
:= True;
7324 Do_Bind_Step
:= False;
7325 Do_Link_Step
:= False;
7327 elsif Argv
(2 .. Argv
'Last) = "nostdlib" then
7329 -- Don't pass -nostdlib to gnatlink, it will disable
7330 -- linking with all standard library files.
7334 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
7335 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
7337 elsif Argv
(2 .. Argv
'Last) = "nostdinc" then
7339 -- Pass -nostdinc to the Compiler and to gnatbind
7342 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
7343 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
7345 -- By default all switches with more than one character
7346 -- or one character switches which are not in 'a' .. 'z'
7347 -- (except 'C', 'F', 'M' and 'B') are passed to the compiler,
7348 -- unless we are dealing with a debug switch (starts with 'd')
7349 -- or an extended gnatmake switch (starts with 'e').
7351 elsif Argv
(2) /= 'd'
7352 and then Argv
(2) /= 'e'
7353 and then Argv
(2 .. Argv
'Last) /= "C"
7354 and then Argv
(2 .. Argv
'Last) /= "F"
7355 and then Argv
(2 .. Argv
'Last) /= "M"
7356 and then Argv
(2 .. Argv
'Last) /= "B"
7357 and then Argv
(2 .. Argv
'Last) /= "vl"
7358 and then Argv
(2 .. Argv
'Last) /= "vm"
7359 and then Argv
(2 .. Argv
'Last) /= "vh"
7360 and then (Argv
'Length > 2 or else Argv
(2) not in 'a' .. 'z')
7362 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
7364 -- All other options are handled by Scan_Make_Switches
7367 Scan_Make_Switches
(Argv
);
7370 -- If not a switch it must be a file name
7374 Mains
.Add_Main
(Argv
);
7382 function Switches_Of
7383 (Source_File
: Name_Id
;
7384 Source_File_Name
: String;
7386 Naming
: Naming_Data
;
7387 In_Package
: Package_Id
;
7388 Allow_ALI
: Boolean) return Variable_Value
7390 Switches
: Variable_Value
;
7392 Defaults
: constant Array_Element_Id
:=
7394 (Name
=> Name_Default_Switches
,
7396 Project_Tree
.Packages
.Table
7397 (In_Package
).Decl
.Arrays
,
7398 In_Tree
=> Project_Tree
);
7400 Switches_Array
: constant Array_Element_Id
:=
7402 (Name
=> Name_Switches
,
7404 Project_Tree
.Packages
.Table
7405 (In_Package
).Decl
.Arrays
,
7406 In_Tree
=> Project_Tree
);
7411 (Index
=> Source_File
,
7412 Src_Index
=> Source_Index
,
7413 In_Array
=> Switches_Array
,
7414 In_Tree
=> Project_Tree
);
7416 if Switches
= Nil_Variable_Value
then
7418 Name
: String (1 .. Source_File_Name
'Length + 3);
7419 Last
: Positive := Source_File_Name
'Length;
7420 Spec_Suffix
: constant String :=
7421 Get_Name_String
(Naming
.Ada_Spec_Suffix
);
7422 Body_Suffix
: constant String :=
7423 Get_Name_String
(Naming
.Ada_Body_Suffix
);
7424 Truncated
: Boolean := False;
7427 Name
(1 .. Last
) := Source_File_Name
;
7429 if Last
> Body_Suffix
'Length
7430 and then Name
(Last
- Body_Suffix
'Length + 1 .. Last
) =
7434 Last
:= Last
- Body_Suffix
'Length;
7438 and then Last
> Spec_Suffix
'Length
7439 and then Name
(Last
- Spec_Suffix
'Length + 1 .. Last
) =
7443 Last
:= Last
- Spec_Suffix
'Length;
7448 Name_Buffer
(1 .. Name_Len
) := Name
(1 .. Last
);
7451 (Index
=> Name_Find
,
7453 In_Array
=> Switches_Array
,
7454 In_Tree
=> Project_Tree
);
7456 if Switches
= Nil_Variable_Value
7459 Last
:= Source_File_Name
'Length;
7461 while Name
(Last
) /= '.' loop
7465 Name
(Last
+ 1 .. Last
+ 3) := "ali";
7466 Name_Len
:= Last
+ 3;
7467 Name_Buffer
(1 .. Name_Len
) := Name
(1 .. Name_Len
);
7470 (Index
=> Name_Find
,
7472 In_Array
=> Switches_Array
,
7473 In_Tree
=> Project_Tree
);
7479 if Switches
= Nil_Variable_Value
then
7484 In_Array
=> Defaults
,
7485 In_Tree
=> Project_Tree
);
7497 if Usage_Needed
then
7498 Usage_Needed
:= False;
7507 procedure Verbose_Msg
7510 N2
: Name_Id
:= No_Name
;
7512 Prefix
: String := " -> ";
7513 Minimum_Verbosity
: Verbosity_Level_Type
:= Opt
.Low
)
7516 if (not Verbose_Mode
) or else (Minimum_Verbosity
> Verbosity_Level
) then
7526 if N2
/= No_Name
then
7537 -- Make sure that in case of failure, the temp files will be deleted
7539 Prj
.Com
.Fail
:= Make_Failed
'Access;
7540 MLib
.Fail
:= Make_Failed
'Access;
7541 Makeutl
.Do_Fail
:= Make_Failed
'Access;