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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, 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
254 -- in tables Binder_Switches and Linker_Switches, before adding
255 -- switches from the project file (if any) and switches from the
256 -- command line (if any).
258 Last_Binder_Switch
: Integer := 0;
259 Last_Linker_Switch
: Integer := 0;
261 Normalized_Switches
: Argument_List_Access
:= new Argument_List
(1 .. 10);
262 Last_Norm_Switch
: Natural := 0;
264 Saved_Maximum_Processes
: Natural := 0;
266 type Arg_List_Ref
is access Argument_List
;
267 The_Saved_Gcc_Switches
: Arg_List_Ref
;
269 Project_File_Name
: String_Access
:= null;
270 -- The path name of the main project file, if any
272 Project_File_Name_Present
: Boolean := False;
273 -- True when -P is used with a space between -P and the project file name
275 Current_Verbosity
: Prj
.Verbosity
:= Prj
.Default
;
276 -- Verbosity to parse the project files
278 Main_Project
: Prj
.Project_Id
:= No_Project
;
279 -- The project id of the main project file, if any
281 Project_Object_Directory
: Project_Id
:= No_Project
;
282 -- The object directory of the project for the last compilation.
283 -- Avoid calling Change_Dir if the current working directory is already
286 -- Packages of project files where unknown attributes are errors
288 Naming_String
: aliased String := "naming";
289 Builder_String
: aliased String := "builder";
290 Compiler_String
: aliased String := "compiler";
291 Binder_String
: aliased String := "binder";
292 Linker_String
: aliased String := "linker";
294 Gnatmake_Packages
: aliased String_List
:=
295 (Naming_String
'Access,
296 Builder_String 'Access,
297 Compiler_String
'Access,
298 Binder_String 'Access,
299 Linker_String
'Access);
301 Packages_To_Check_By_Gnatmake : constant String_List_Access :=
302 Gnatmake_Packages'Access;
304 procedure Add_Source_Dir (N : String);
305 -- Call Add_Src_Search_Dir.
306 -- Output one line when in verbose mode.
308 procedure Add_Source_Directories is
309 new Prj.Env.For_All_Source_Dirs (Action => Add_Source_Dir);
311 procedure Add_Object_Dir (N : String);
312 -- Call Add_Lib_Search_Dir.
313 -- Output one line when in verbose mode.
315 procedure Add_Object_Directories is
316 new Prj.Env.For_All_Object_Dirs (Action => Add_Object_Dir);
318 procedure Change_To_Object_Directory (Project : Project_Id);
319 -- Change to the object directory of project Project, if this is not
320 -- already the current working directory.
322 type Bad_Compilation_Info is record
323 File : File_Name_Type;
324 Unit : Unit_Name_Type;
327 -- File is the name of the file for which a compilation failed.
328 -- Unit is for gnatdist use in order to easily get the unit name
329 -- of a file when its name is krunched or declared in gnat.adc.
330 -- Found is False if the compilation failed because the file could
333 package Bad_Compilation is new Table.Table (
334 Table_Component_Type => Bad_Compilation_Info,
335 Table_Index_Type => Natural,
336 Table_Low_Bound => 1,
338 Table_Increment => 100,
339 Table_Name => "Make.Bad_Compilation");
340 -- Full name of all the source files for which compilation fails
342 Do_Compile_Step : Boolean := True;
343 Do_Bind_Step : Boolean := True;
344 Do_Link_Step : Boolean := True;
345 -- Flags to indicate what step should be executed.
346 -- Can be set to False with the switches -c, -b and -l.
347 -- These flags are reset to True for each invokation of procedure Gnatmake.
349 Shared_String : aliased String := "-shared";
350 Force_Elab_Flags_String : aliased String := "-F";
352 No_Shared_Switch : aliased Argument_List := (1 .. 0 => null);
353 Shared_Switch : aliased Argument_List := (1 => Shared_String'Access);
354 Bind_Shared : Argument_List_Access := No_Shared_Switch'Access;
355 -- Switch to added in front of gnatbind switches. By default no switch is
356 -- added. Switch "-shared" is added if there is a non-static Library
359 Shared_Libgcc : aliased String := "-shared-libgcc";
361 No_Shared_Libgcc_Switch : aliased Argument_List := (1 .. 0 => null);
362 Shared_Libgcc_Switch : aliased Argument_List :=
363 (1 => Shared_Libgcc'Access);
364 Link_With_Shared_Libgcc : Argument_List_Access :=
365 No_Shared_Libgcc_Switch'Access;
367 procedure Make_Failed (S1 : String; S2 : String := ""; S3 : String := "");
368 -- Delete all temp files created by Gnatmake and call Osint.Fail,
369 -- with the parameter S1, S2 and S3 (see osint.ads).
370 -- This is called from the Prj hierarchy and the MLib hierarchy.
372 --------------------------
373 -- Obsolete Executables --
374 --------------------------
376 Executable_Obsolete : Boolean := False;
377 -- Executable_Obsolete is initially set to False for each executable,
378 -- and is set to True whenever one of the source of the executable is
379 -- compiled, or has already been compiled for another executable.
381 Max_Header : constant := 200;
382 -- This needs a proper comment, it used to say "arbitrary"
383 -- that's not an adequate comment ???
385 type Header_Num is range 1 .. Max_Header;
386 -- Header_Num for the hash table Obsoleted below
388 function Hash (F : Name_Id) return Header_Num;
389 -- Hash function for the hash table Obsoleted below
391 package Obsoleted is new System.HTable.Simple_HTable
392 (Header_Num => Header_Num,
398 -- A hash table to keep all files that have been compiled, to detect
399 -- if an executable is up to date or not.
401 procedure Enter_Into_Obsoleted (F : Name_Id);
402 -- Enter a file name, without directory information, into the has table
405 function Is_In_Obsoleted (F : Name_Id) return Boolean;
406 -- Check if a file name, without directory information, has already been
407 -- entered into the hash table Obsoleted.
409 type Dependency is record
411 Depends_On : Name_Id;
413 -- Components of table Dependencies below
415 package Dependencies is new Table.Table (
416 Table_Component_Type => Dependency,
417 Table_Index_Type => Integer,
418 Table_Low_Bound => 1,
420 Table_Increment => 100,
421 Table_Name => "Make.Dependencies");
422 -- A table to keep dependencies, to be able to decide if an executable
425 procedure Add_Dependency (S : Name_Id; On : Name_Id);
426 -- Add one entry in table Dependencies
428 ----------------------------
429 -- Arguments and Switches --
430 ----------------------------
432 Arguments : Argument_List_Access;
433 -- Used to gather the arguments for invocation of the compiler
435 Last_Argument : Natural := 0;
436 -- Last index of arguments in Arguments above
438 Arguments_Collected : Boolean := False;
439 -- Set to True when the arguments for the next invocation of the compiler
440 -- have been collected.
442 Arguments_Project : Project_Id;
443 -- Project id, if any, of the source to be compiled
445 Arguments_Path_Name : File_Name_Type;
446 -- Full path of the source to be compiled, when Arguments_Project is not
449 Dummy_Switch : constant String_Access := new String'("- ");
450 -- Used to initialized Prev_Switch in procedure Check
452 procedure Add_Arguments
(Args
: Argument_List
);
453 -- Add arguments to global variable Arguments, increasing its size
454 -- if necessary and adjusting Last_Argument.
456 function Configuration_Pragmas_Switch
457 (For_Project
: Project_Id
) return Argument_List
;
458 -- Return an argument list of one element, if there is a configuration
459 -- pragmas file to be specified for For_Project,
460 -- otherwise return an empty argument list.
466 procedure List_Depend
;
467 -- Prints to standard output the list of object dependencies. This list
468 -- can be used directly in a Makefile. A call to Compile_Sources must
469 -- precede the call to List_Depend. Also because this routine uses the
470 -- ALI files that were originally loaded and scanned by Compile_Sources,
471 -- no additional ALI files should be scanned between the two calls (i.e.
472 -- between the call to Compile_Sources and List_Depend.)
474 procedure Inform
(N
: Name_Id
:= No_Name
; Msg
: String);
475 -- Prints out the program name followed by a colon, N and S
477 procedure List_Bad_Compilations
;
478 -- Prints out the list of all files for which the compilation failed
480 procedure Verbose_Msg
483 N2
: Name_Id
:= No_Name
;
485 Prefix
: String := " -> ");
486 -- If the verbose flag (Verbose_Mode) is set then print Prefix to standard
487 -- output followed by N1 and S1. If N2 /= No_Name then N2 is printed after
488 -- S1. S2 is printed last. Both N1 and N2 are printed in quotation marks.
490 Usage_Needed
: Boolean := True;
491 -- Flag used to make sure Makeusg is call at most once
494 -- Call Makeusg, if Usage_Needed is True.
495 -- Set Usage_Needed to False.
497 procedure Debug_Msg
(S
: String; N
: Name_Id
);
498 -- If Debug.Debug_Flag_W is set outputs string S followed by name N
500 procedure Recursive_Compute_Depth
501 (Project
: Project_Id
;
503 -- Compute depth of Project and of the projects it depends on
505 -----------------------
506 -- Gnatmake Routines --
507 -----------------------
509 Gnatmake_Called
: Boolean := False;
510 -- Set to True when procedure Gnatmake is called.
511 -- Attempt to delete temporary files is made only when Gnatmake_Called
514 subtype Lib_Mark_Type
is Byte
;
515 -- Used in Mark_Directory
517 Ada_Lib_Dir
: constant Lib_Mark_Type
:= 1;
518 -- Used to mark a directory as a GNAT lib dir
520 -- Note that the notion of GNAT lib dir is no longer used. The code
521 -- related to it has not been removed to give an idea on how to use
522 -- the directory prefix marking mechanism.
524 -- An Ada library directory is a directory containing ali and object
525 -- files but no source files for the bodies (the specs can be in the
526 -- same or some other directory). These directories are specified
527 -- in the Gnatmake command line with the switch "-Adir" (to specify the
528 -- spec location -Idir cab be used). Gnatmake skips the missing sources
529 -- whose ali are in Ada library directories. For an explanation of why
530 -- Gnatmake behaves that way, see the spec of Make.Compile_Sources.
531 -- The directory lookup penalty is incurred every single time this
532 -- routine is called.
534 procedure Check_Steps
;
535 -- Check what steps (Compile, Bind, Link) must be executed.
536 -- Set the step flags accordingly.
538 function In_Ada_Lib_Dir
(File
: File_Name_Type
) return Boolean;
539 -- Get directory prefix of this file and get lib mark stored in name
540 -- table for this directory. Then check if an Ada lib mark has been set.
542 procedure Mark_Directory
544 Mark
: Lib_Mark_Type
);
545 -- Store Dir in name table and set lib mark as name info to identify
548 Output_Is_Object
: Boolean := True;
549 -- Set to False when using a switch -S for the compiler
551 procedure Check_For_S_Switch
;
552 -- Set Output_Is_Object to False when the -S switch is used for the
556 (Source_File
: Name_Id
;
557 Source_File_Name
: String;
559 Naming
: Naming_Data
;
560 In_Package
: Package_Id
;
561 Allow_ALI
: Boolean) return Variable_Value
;
562 -- Return the switches for the source file in the specified package
563 -- of a project file. If the Source_File ends with a standard GNAT
564 -- extension (".ads" or ".adb"), try first the full name, then the
565 -- name without the extension, then, if Allow_ALI is True, the name with
566 -- the extension ".ali". If there is no switches for either names, try the
567 -- default switches for Ada. If all failed, return No_Variable_Value.
569 function Is_In_Object_Directory
570 (Source_File
: File_Name_Type
;
571 Full_Lib_File
: File_Name_Type
) return Boolean;
572 -- Check if, when using a project file, the ALI file is in the project
573 -- directory of the ultimate extending project. If it is not, we ignore
574 -- the fact that this ALI file is read-only.
576 ----------------------------------------------------
577 -- Compiler, Binder & Linker Data and Subprograms --
578 ----------------------------------------------------
580 Gcc
: String_Access
:= Program_Name
("gcc");
581 Gnatbind
: String_Access
:= Program_Name
("gnatbind");
582 Gnatlink
: String_Access
:= Program_Name
("gnatlink");
583 -- Default compiler, binder, linker programs
585 Saved_Gcc
: String_Access
:= null;
586 Saved_Gnatbind
: String_Access
:= null;
587 Saved_Gnatlink
: String_Access
:= null;
588 -- Given by the command line. Will be used, if non null
590 Gcc_Path
: String_Access
:=
591 GNAT
.OS_Lib
.Locate_Exec_On_Path
(Gcc
.all);
592 Gnatbind_Path
: String_Access
:=
593 GNAT
.OS_Lib
.Locate_Exec_On_Path
(Gnatbind
.all);
594 Gnatlink_Path
: String_Access
:=
595 GNAT
.OS_Lib
.Locate_Exec_On_Path
(Gnatlink
.all);
596 -- Path for compiler, binder, linker programs, defaulted now for gnatdist.
597 -- Changed later if overridden on command line.
599 Comp_Flag
: constant String_Access
:= new String'("-c");
600 Output_Flag : constant String_Access := new String'("-o");
601 Ada_Flag_1
: constant String_Access
:= new String'("-x");
602 Ada_Flag_2 : constant String_Access := new String'("ada");
603 No_gnat_adc
: constant String_Access
:= new String'("-gnatA");
604 GNAT_Flag : constant String_Access := new String'("-gnatpg");
605 Do_Not_Check_Flag
: constant String_Access
:= new String'("-x");
607 Object_Suffix : constant String := Get_Object_Suffix.all;
608 Executable_Suffix : constant String := Get_Executable_Suffix.all;
610 Syntax_Only : Boolean := False;
611 -- Set to True when compiling with -gnats
613 Display_Executed_Programs : Boolean := True;
614 -- Set to True if name of commands should be output on stderr
616 Output_File_Name_Seen : Boolean := False;
617 -- Set to True after having scanned the file_name for
618 -- switch "-o file_name"
620 Object_Directory_Seen : Boolean := False;
621 -- Set to True after having scanned the object directory for
622 -- switch "-D obj_dir".
624 Object_Directory_Path : String_Access := null;
625 -- The path name of the object directory, set with switch -D
627 type Make_Program_Type is (None, Compiler, Binder, Linker);
629 Program_Args : Make_Program_Type := None;
630 -- Used to indicate if we are scanning gnatmake, gcc, gnatbind, or gnatbind
631 -- options within the gnatmake command line. Used in Scan_Make_Arg only,
632 -- but must be global since value preserved from one call to another.
634 Temporary_Config_File : Boolean := False;
635 -- Set to True when there is a temporary config file used for a project
636 -- file, to avoid displaying the -gnatec switch for a temporary file.
638 procedure Add_Switches
639 (The_Package : Package_Id;
642 Program : Make_Program_Type);
645 Program : Make_Program_Type;
646 Append_Switch : Boolean := True;
647 And_Save : Boolean := True);
650 Program : Make_Program_Type;
651 Append_Switch : Boolean := True;
652 And_Save : Boolean := True);
653 -- Make invokes one of three programs (the compiler, the binder or the
654 -- linker). For the sake of convenience, some program specific switches
655 -- can be passed directly on the gnatmake commande line. This procedure
656 -- records these switches so that gnamake can pass them to the right
657 -- program. S is the switch to be added at the end of the command line
658 -- for Program if Append_Switch is True. If Append_Switch is False S is
659 -- added at the beginning of the command line.
662 (Source_File : File_Name_Type;
664 The_Args : Argument_List;
665 Lib_File : File_Name_Type;
668 O_File : out File_Name_Type;
669 O_Stamp : out Time_Stamp_Type);
670 -- Determines whether the library file Lib_File is up-to-date or not. The
671 -- full name (with path information) of the object file corresponding to
672 -- Lib_File is returned in O_File. Its time stamp is saved in O_Stamp.
673 -- ALI is the ALI_Id corresponding to Lib_File. If Lib_File in not
674 -- up-to-date, then the corresponding source file needs to be recompiled.
675 -- In this case ALI = No_ALI_Id.
677 procedure Check_Linker_Options
678 (E_Stamp : Time_Stamp_Type;
679 O_File : out File_Name_Type;
680 O_Stamp : out Time_Stamp_Type);
681 -- Checks all linker options for linker files that are newer
682 -- than E_Stamp. If such objects are found, the youngest object
683 -- is returned in O_File and its stamp in O_Stamp.
685 -- If no obsolete linker files were found, the first missing
686 -- linker file is returned in O_File and O_Stamp is empty.
687 -- Otherwise O_File is No_File.
689 procedure Collect_Arguments
690 (Source_File : File_Name_Type;
692 Args : Argument_List);
693 -- Collect all arguments for a source to be compiled, including those
694 -- that come from a project file.
696 procedure Display (Program : String; Args : Argument_List);
697 -- Displays Program followed by the arguments in Args if variable
698 -- Display_Executed_Programs is set. The lower bound of Args must be 1.
704 type Temp_File_Names is
705 array (Project_Id range <>, Positive range <>) of Name_Id;
707 type Temp_Files_Ptr is access Temp_File_Names;
709 type Indices is array (Project_Id range <>) of Natural;
711 type Indices_Ptr is access Indices;
713 type Free_File_Indices is array
714 (Project_Id range <>, Positive range <>) of Positive;
716 type Free_Indices_Ptr is access Free_File_Indices;
718 The_Mapping_File_Names : Temp_Files_Ptr;
719 -- For each project, the name ids of the temporary mapping files used
721 Last_Mapping_File_Names : Indices_Ptr;
722 -- For each project, the index of the last mapping file created
724 The_Free_Mapping_File_Indices : Free_Indices_Ptr;
725 -- For each project, the indices in The_Mapping_File_Names of the mapping
726 -- file names that can be reused for subsequent compilations.
728 Last_Free_Indices : Indices_Ptr;
729 -- For each project, the number of mapping files that can be reused
731 Gnatmake_Mapping_File : String_Access := null;
732 -- The path name of a mapping file specified by switch -C=
734 procedure Delete_Mapping_Files;
735 -- Delete all temporary mapping files
737 procedure Init_Mapping_File
738 (Project : Project_Id;
739 File_Index : in out Natural);
740 -- Create a new temporary mapping file, and fill it with the project file
741 -- mappings, when using project file(s). The out parameter File_Index is
742 -- the index to the name of the file in the array The_Mapping_File_Names.
744 procedure Delete_Temp_Config_Files;
745 -- Delete all temporary config files
747 procedure Delete_All_Temp_Files;
748 -- Delete all temp files (config files, mapping files, path files)
754 procedure Add_Arguments (Args : Argument_List) is
756 if Arguments = null then
757 Arguments := new Argument_List (1 .. Args'Length + 10);
760 while Last_Argument + Args'Length > Arguments'Last loop
762 New_Arguments : constant Argument_List_Access :=
763 new Argument_List (1 .. Arguments'Last * 2);
765 New_Arguments (1 .. Last_Argument) :=
766 Arguments (1 .. Last_Argument);
767 Arguments := New_Arguments;
772 Arguments (Last_Argument + 1 .. Last_Argument + Args'Length) := Args;
773 Last_Argument := Last_Argument + Args'Length;
780 procedure Add_Dependency (S : Name_Id; On : Name_Id) is
782 Dependencies.Increment_Last;
783 Dependencies.Table (Dependencies.Last) := (S, On);
790 procedure Add_Object_Dir (N : String) is
792 Add_Lib_Search_Dir (N);
795 Write_Str ("Adding object directory """);
806 procedure Add_Source_Dir (N : String) is
808 Add_Src_Search_Dir (N);
811 Write_Str ("Adding source directory """);
824 Program : Make_Program_Type;
825 Append_Switch : Boolean := True;
826 And_Save : Boolean := True)
829 with package T is new Table.Table (<>);
830 procedure Generic_Position (New_Position : out Integer);
831 -- Generic procedure that chooses a position for S in T at the
832 -- beginning or the end, depending on the boolean Append_Switch.
833 -- Calling this procedure may expand the table.
835 ----------------------
836 -- Generic_Position --
837 ----------------------
839 procedure Generic_Position (New_Position : out Integer) is
843 if Append_Switch then
844 New_Position := Integer (T.Last);
846 for J in reverse T.Table_Index_Type'Succ (T.First) .. T.Last loop
847 T.Table (J) := T.Table (T.Table_Index_Type'Pred (J));
850 New_Position := Integer (T.First);
852 end Generic_Position;
854 procedure Gcc_Switches_Pos is new Generic_Position (Gcc_Switches);
855 procedure Binder_Switches_Pos is new Generic_Position (Binder_Switches);
856 procedure Linker_Switches_Pos is new Generic_Position (Linker_Switches);
858 procedure Saved_Gcc_Switches_Pos is new
859 Generic_Position (Saved_Gcc_Switches);
861 procedure Saved_Binder_Switches_Pos is new
862 Generic_Position (Saved_Binder_Switches);
864 procedure Saved_Linker_Switches_Pos is new
865 Generic_Position (Saved_Linker_Switches);
867 New_Position : Integer;
869 -- Start of processing for Add_Switch
875 Saved_Gcc_Switches_Pos (New_Position);
876 Saved_Gcc_Switches.Table (New_Position) := S;
879 Saved_Binder_Switches_Pos (New_Position);
880 Saved_Binder_Switches.Table (New_Position) := S;
883 Saved_Linker_Switches_Pos (New_Position);
884 Saved_Linker_Switches.Table (New_Position) := S;
893 Gcc_Switches_Pos (New_Position);
894 Gcc_Switches.Table (New_Position) := S;
897 Binder_Switches_Pos (New_Position);
898 Binder_Switches.Table (New_Position) := S;
901 Linker_Switches_Pos (New_Position);
902 Linker_Switches.Table (New_Position) := S;
912 Program : Make_Program_Type;
913 Append_Switch : Boolean := True;
914 And_Save : Boolean := True)
917 Add_Switch (S => new String'(S
),
919 Append_Switch
=> Append_Switch
,
920 And_Save
=> And_Save
);
927 procedure Add_Switches
928 (The_Package
: Package_Id
;
931 Program
: Make_Program_Type
)
933 Switches
: Variable_Value
;
934 Switch_List
: String_List_Id
;
935 Element
: String_Element
;
938 if File_Name
'Length > 0 then
939 Name_Len
:= File_Name
'Length;
940 Name_Buffer
(1 .. Name_Len
) := File_Name
;
943 (Source_File
=> Name_Find
,
944 Source_File_Name
=> File_Name
,
945 Source_Index
=> Index
,
946 Naming
=> Projects
.Table
(Main_Project
).Naming
,
947 In_Package
=> The_Package
,
949 Program
= Binder
or else Program
= Linker
);
951 case Switches
.Kind
is
956 Program_Args
:= Program
;
958 Switch_List
:= Switches
.Values
;
960 while Switch_List
/= Nil_String
loop
961 Element
:= String_Elements
.Table
(Switch_List
);
962 Get_Name_String
(Element
.Value
);
966 Argv
: constant String := Name_Buffer
(1 .. Name_Len
);
967 -- We need a copy, because Name_Buffer may be
972 Write_Str
(" Adding ");
976 Scan_Make_Arg
(Argv
, And_Save
=> False);
980 Switch_List
:= Element
.Next
;
984 Program_Args
:= Program
;
985 Get_Name_String
(Switches
.Value
);
989 Argv
: constant String := Name_Buffer
(1 .. Name_Len
);
990 -- We need a copy, because Name_Buffer may be modified
994 Write_Str
(" Adding ");
998 Scan_Make_Arg
(Argv
, And_Save
=> False);
1009 procedure Bind
(ALI_File
: File_Name_Type
; Args
: Argument_List
) is
1010 Bind_Args
: Argument_List
(1 .. Args
'Last + 2);
1011 Bind_Last
: Integer;
1015 pragma Assert
(Args
'First = 1);
1017 -- Optimize the simple case where the gnatbind command line looks like
1018 -- gnatbind -aO. -I- file.ali --into-> gnatbind file.adb
1021 and then Args
(Args
'First).all = "-aO" & Normalized_CWD
1022 and then Args
(Args
'Last).all = "-I-"
1023 and then ALI_File
= Strip_Directory
(ALI_File
)
1025 Bind_Last
:= Args
'First - 1;
1028 Bind_Last
:= Args
'Last;
1029 Bind_Args
(Args
'Range) := Args
;
1032 -- It is completely pointless to re-check source file time stamps.
1033 -- This has been done already by gnatmake
1035 Bind_Last
:= Bind_Last
+ 1;
1036 Bind_Args
(Bind_Last
) := Do_Not_Check_Flag
;
1038 Get_Name_String
(ALI_File
);
1040 Bind_Last
:= Bind_Last
+ 1;
1041 Bind_Args
(Bind_Last
) := new String'(Name_Buffer (1 .. Name_Len));
1043 GNAT.OS_Lib.Normalize_Arguments (Bind_Args (Args'First .. Bind_Last));
1045 Display (Gnatbind.all, Bind_Args (Args'First .. Bind_Last));
1047 if Gnatbind_Path = null then
1048 Make_Failed ("error, unable to locate ", Gnatbind.all);
1052 (Gnatbind_Path.all, Bind_Args (Args'First .. Bind_Last), Success);
1059 --------------------------------
1060 -- Change_To_Object_Directory --
1061 --------------------------------
1063 procedure Change_To_Object_Directory (Project : Project_Id) is
1065 -- Nothing to do if the current working directory is alresdy the one
1068 if Project_Object_Directory /= Project then
1069 Project_Object_Directory := Project;
1071 -- If in a real project, set the working directory to the object
1072 -- directory of the project.
1074 if Project /= No_Project then
1076 (Get_Name_String (Projects.Table (Project).Object_Directory));
1078 -- Otherwise, for sources outside of any project, set the working
1079 -- directory to the object directory of the main project.
1081 elsif Main_Project /= No_Project then
1084 (Projects.Table (Main_Project).Object_Directory));
1087 end Change_To_Object_Directory;
1094 (Source_File : File_Name_Type;
1096 The_Args : Argument_List;
1097 Lib_File : File_Name_Type;
1098 Read_Only : Boolean;
1100 O_File : out File_Name_Type;
1101 O_Stamp : out Time_Stamp_Type)
1103 function First_New_Spec (A : ALI_Id) return File_Name_Type;
1104 -- Looks in the with table entries of A and returns the spec file name
1105 -- of the first withed unit (subprogram) for which no spec existed when
1106 -- A was generated but for which there exists one now, implying that A
1107 -- is now obsolete. If no such unit is found No_File is returned.
1108 -- Otherwise the spec file name of the unit is returned.
1110 -- **WARNING** in the event of Uname format modifications, one *MUST*
1111 -- make sure this function is also updated.
1113 -- Note: This function should really be in ali.adb and use Uname
1114 -- services, but this causes the whole compiler to be dragged along
1115 -- for gnatbind and gnatmake.
1117 --------------------
1118 -- First_New_Spec --
1119 --------------------
1121 function First_New_Spec (A : ALI_Id) return File_Name_Type is
1122 Spec_File_Name : File_Name_Type := No_File;
1124 function New_Spec (Uname : Unit_Name_Type) return Boolean;
1125 -- Uname is the name of the spec or body of some ada unit.
1126 -- This function returns True if the Uname is the name of a body
1127 -- which has a spec not mentioned inali file A. If True is returned
1128 -- Spec_File_Name above is set to the name of this spec file.
1134 function New_Spec (Uname : Unit_Name_Type) return Boolean is
1135 Spec_Name : Unit_Name_Type;
1136 File_Name : File_Name_Type;
1139 -- Test whether Uname is the name of a body unit (ie ends with %b)
1141 Get_Name_String (Uname);
1143 Assert (Name_Len > 2 and then Name_Buffer (Name_Len - 1) = '%');
1145 if Name_Buffer (Name_Len) /= 'b
' then
1149 -- Convert unit name into spec name
1151 -- ??? this code seems dubious in presence of pragma
1152 -- Source_File_Name since there is no more direct relationship
1153 -- between unit name and file name.
1155 -- ??? Further, what about alternative subunit naming
1157 Name_Buffer (Name_Len) := 's
';
1158 Spec_Name := Name_Find;
1159 File_Name := Get_File_Name (Spec_Name, Subunit => False);
1161 -- Look if File_Name is mentioned in A's sdep list.
1162 -- If not look if the file exists. If it does return True.
1165 ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep
1167 if Sdep.Table (D).Sfile = File_Name then
1172 if Full_Source_Name (File_Name) /= No_File then
1173 Spec_File_Name := File_Name;
1180 -- Start of processing for First_New_Spec
1184 ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit
1186 exit U_Chk when Units.Table (U).Utype = Is_Body_Only
1187 and then New_Spec (Units.Table (U).Uname);
1189 for W in Units.Table (U).First_With
1191 Units.Table (U).Last_With
1194 Withs.Table (W).Afile /= No_File
1195 and then New_Spec (Withs.Table (W).Uname);
1199 return Spec_File_Name;
1202 ---------------------------------
1203 -- Data declarations for Check --
1204 ---------------------------------
1206 Full_Lib_File : File_Name_Type;
1207 -- Full name of current library file
1209 Full_Obj_File : File_Name_Type;
1210 -- Full name of the object file corresponding to Lib_File
1212 Lib_Stamp : Time_Stamp_Type;
1213 -- Time stamp of the current ada library file
1215 Obj_Stamp : Time_Stamp_Type;
1216 -- Time stamp of the current object file
1218 Modified_Source : File_Name_Type;
1219 -- The first source in Lib_File whose current time stamp differs
1220 -- from that stored in Lib_File.
1222 New_Spec : File_Name_Type;
1223 -- If Lib_File contains in its W (with) section a body (for a
1224 -- subprogram) for which there exists a spec and the spec did not
1225 -- appear in the Sdep section of Lib_File, New_Spec contains the file
1226 -- name of this new spec.
1228 Source_Name : Name_Id;
1229 Text : Text_Buffer_Ptr;
1231 Prev_Switch : String_Access;
1232 -- Previous switch processed
1234 Arg : Arg_Id := Arg_Id'First;
1235 -- Current index in Args.Table for a given unit (init to stop warning)
1237 Switch_Found : Boolean;
1238 -- True if a given switch has been found
1240 -- Start of processing for Check
1243 pragma Assert (Lib_File /= No_File);
1245 -- If the ALI file is read-only, set temporarily
1246 -- Check_Object_Consistency to False: we don't care if the object file
1247 -- is not there; presumably, a library will be used for linking.
1251 Saved_Check_Object_Consistency : constant Boolean :=
1252 Check_Object_Consistency;
1254 Check_Object_Consistency := False;
1255 Text := Read_Library_Info (Lib_File);
1256 Check_Object_Consistency := Saved_Check_Object_Consistency;
1260 Text := Read_Library_Info (Lib_File);
1263 Full_Lib_File := Full_Library_Info_Name;
1264 Full_Obj_File := Full_Object_File_Name;
1265 Lib_Stamp := Current_Library_File_Stamp;
1266 Obj_Stamp := Current_Object_File_Stamp;
1268 if Full_Lib_File = No_File then
1269 Verbose_Msg (Lib_File, "being checked ...", Prefix => " ");
1271 Verbose_Msg (Full_Lib_File, "being checked ...", Prefix => " ");
1275 O_File := Full_Obj_File;
1276 O_Stamp := Obj_Stamp;
1279 if Full_Lib_File = No_File then
1280 Verbose_Msg (Lib_File, "missing.");
1282 elsif Obj_Stamp (Obj_Stamp'First) = ' ' then
1283 Verbose_Msg (Full_Obj_File, "missing.");
1287 (Full_Lib_File, "(" & String (Lib_Stamp) & ") newer than",
1288 Full_Obj_File, "(" & String (Obj_Stamp) & ")");
1292 ALI := Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
1295 if ALI = No_ALI_Id then
1296 Verbose_Msg (Full_Lib_File, "incorrectly formatted ALI file");
1299 elsif ALIs.Table (ALI).Ver (1 .. ALIs.Table (ALI).Ver_Len) /=
1300 Verbose_Library_Version
1302 Verbose_Msg (Full_Lib_File, "compiled with old GNAT version");
1307 -- Don't take Ali file into account if it was generated with
1310 if ALIs.Table (ALI).Compile_Errors then
1311 Verbose_Msg (Full_Lib_File, "had errors, must be recompiled");
1316 -- Don't take Ali file into account if it was generated without
1319 if Operating_Mode /= Check_Semantics
1320 and then ALIs.Table (ALI).No_Object
1322 Verbose_Msg (Full_Lib_File, "has no corresponding object");
1327 -- Check for matching compiler switches if needed
1329 if Check_Switches then
1331 -- First, collect all the switches
1333 Collect_Arguments (Source_File, Source_Index, The_Args);
1335 Prev_Switch := Dummy_Switch;
1337 Get_Name_String (ALIs.Table (ALI).Sfile);
1339 Switches_To_Check.Set_Last (0);
1341 for J in 1 .. Last_Argument loop
1343 -- Skip non switches -c, -I and -o switches
1345 if Arguments (J) (1) = '-'
1346 and then Arguments (J) (2) /= 'c
'
1347 and then Arguments (J) (2) /= 'o
'
1348 and then Arguments (J) (2) /= 'I
'
1350 Normalize_Compiler_Switches
1352 Normalized_Switches,
1355 for K in 1 .. Last_Norm_Switch loop
1356 Switches_To_Check.Increment_Last;
1357 Switches_To_Check.Table (Switches_To_Check.Last) :=
1358 Normalized_Switches (K);
1363 for J in 1 .. Switches_To_Check.Last loop
1365 -- Comparing switches is delicate because gcc reorders
1366 -- a number of switches, according to lang-specs.h, but
1367 -- gnatmake doesn't have the sufficient knowledge to
1368 -- perform the same reordering. Instead, we ignore orders
1369 -- between different "first letter" switches, but keep
1370 -- orders between same switches, e.g -O -O2 is different
1371 -- than -O2 -O, but -g -O is equivalent to -O -g.
1373 if Switches_To_Check.Table (J) (2) /= Prev_Switch (2) or else
1374 (Prev_Switch'Length >= 6 and then
1375 Prev_Switch (2 .. 5) = "gnat" and then
1376 Switches_To_Check.Table (J)'Length >= 6 and then
1377 Switches_To_Check.Table (J) (2 .. 5) = "gnat" and then
1378 Prev_Switch (6) /= Switches_To_Check.Table (J) (6))
1380 Prev_Switch := Switches_To_Check.Table (J);
1382 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg;
1385 Switch_Found := False;
1388 Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1391 Switches_To_Check.Table (J).all = Args.Table (K).all
1394 Switch_Found := True;
1399 if not Switch_Found then
1400 if Verbose_Mode then
1401 Verbose_Msg (ALIs.Table (ALI).Sfile,
1402 "switch mismatch """ &
1403 Switches_To_Check.Table (J).all & '"');
1411 if Switches_To_Check.Last /=
1412 Integer (Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg -
1413 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg + 1)
1415 if Verbose_Mode then
1416 Verbose_Msg (ALIs.Table (ALI).Sfile,
1417 "different number
of switches
");
1419 for K in Units.Table (ALIs.Table (ALI).First_Unit).First_Arg
1420 .. Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1422 Write_Str (Args.Table (K).all);
1428 for J in 1 .. Switches_To_Check.Last loop
1429 Write_Str (Switches_To_Check.Table (J).all);
1441 -- Get the source files and their message digests. Note that some
1442 -- sources may be missing if ALI is out-of-date.
1444 Set_Source_Table (ALI);
1446 Modified_Source := Time_Stamp_Mismatch (ALI, Read_Only);
1448 if Modified_Source /= No_File then
1451 if Verbose_Mode then
1452 Source_Name := Full_Source_Name (Modified_Source);
1454 if Source_Name /= No_File then
1455 Verbose_Msg (Source_Name, "time stamp mismatch
");
1457 Verbose_Msg (Modified_Source, "missing
");
1462 New_Spec := First_New_Spec (ALI);
1464 if New_Spec /= No_File then
1467 if Verbose_Mode then
1468 Source_Name := Full_Source_Name (New_Spec);
1470 if Source_Name /= No_File then
1471 Verbose_Msg (Source_Name, "new spec
");
1473 Verbose_Msg (New_Spec, "old spec missing
");
1481 ------------------------
1482 -- Check_For_S_Switch --
1483 ------------------------
1485 procedure Check_For_S_Switch is
1487 -- By default, we generate an object file
1489 Output_Is_Object := True;
1491 for Arg in 1 .. Last_Argument loop
1492 if Arguments (Arg).all = "-S
" then
1493 Output_Is_Object := False;
1495 elsif Arguments (Arg).all = "-c
" then
1496 Output_Is_Object := True;
1499 end Check_For_S_Switch;
1501 --------------------------
1502 -- Check_Linker_Options --
1503 --------------------------
1505 procedure Check_Linker_Options
1506 (E_Stamp : Time_Stamp_Type;
1507 O_File : out File_Name_Type;
1508 O_Stamp : out Time_Stamp_Type)
1510 procedure Check_File (File : File_Name_Type);
1511 -- Update O_File and O_Stamp if the given file is younger than E_Stamp
1512 -- and O_Stamp, or if O_File is No_File and File does not exist.
1514 function Get_Library_File (Name : String) return File_Name_Type;
1515 -- Return the full file name including path of a library based
1516 -- on the name specified with the -l linker option, using the
1517 -- Ada object path. Return No_File if no such file can be found.
1519 type Char_Array is array (Natural) of Character;
1520 type Char_Array_Access is access constant Char_Array;
1522 Template : Char_Array_Access;
1523 pragma Import (C, Template, "__gnat_library_template
");
1529 procedure Check_File (File : File_Name_Type) is
1530 Stamp : Time_Stamp_Type;
1531 Name : File_Name_Type := File;
1534 Get_Name_String (Name);
1536 -- Remove any trailing NUL characters
1538 while Name_Len >= Name_Buffer'First
1539 and then Name_Buffer (Name_Len) = NUL
1541 Name_Len := Name_Len - 1;
1544 if Name_Len <= 0 then
1547 elsif Name_Buffer (1) = '-' then
1549 -- Do not check if File is a switch other than "-l
"
1551 if Name_Buffer (2) /= 'l' then
1555 -- The argument is a library switch, get actual name. It
1556 -- is necessary to make a copy of the relevant part of
1557 -- Name_Buffer as Get_Library_Name uses Name_Buffer as well.
1560 Base_Name : constant String := Name_Buffer (3 .. Name_Len);
1563 Name := Get_Library_File (Base_Name);
1566 if Name = No_File then
1571 Stamp := File_Stamp (Name);
1573 -- Find the youngest object file that is younger than the
1574 -- executable. If no such file exist, record the first object
1575 -- file that is not found.
1577 if (O_Stamp < Stamp and then E_Stamp < Stamp)
1578 or else (O_File = No_File and then Stamp (Stamp'First) = ' ')
1583 -- Strip the trailing NUL if present
1585 Get_Name_String (O_File);
1587 if Name_Buffer (Name_Len) = NUL then
1588 Name_Len := Name_Len - 1;
1589 O_File := Name_Find;
1594 ----------------------
1595 -- Get_Library_Name --
1596 ----------------------
1598 -- See comments in a-adaint.c about template syntax
1600 function Get_Library_File (Name : String) return File_Name_Type is
1601 File : File_Name_Type := No_File;
1606 for Ptr in Template'Range loop
1607 case Template (Ptr) is
1609 Add_Str_To_Name_Buffer (Name);
1612 File := Full_Lib_File_Name (Name_Find);
1613 exit when File /= No_File;
1620 Add_Char_To_Name_Buffer (Template (Ptr));
1624 -- The for loop exited because the end of the template
1625 -- was reached. File contains the last possible file name
1628 if File = No_File and then Name_Len > 0 then
1629 File := Full_Lib_File_Name (Name_Find);
1633 end Get_Library_File;
1635 -- Start of processing for Check_Linker_Options
1639 O_Stamp := (others => ' ');
1641 -- Process linker options from the ALI files
1643 for Opt in 1 .. Linker_Options.Last loop
1644 Check_File (Linker_Options.Table (Opt).Name);
1647 -- Process options given on the command line
1649 for Opt in Linker_Switches.First .. Linker_Switches.Last loop
1651 -- Check if the previous Opt has one of the two switches
1652 -- that take an extra parameter. (See GCC manual.)
1654 if Opt = Linker_Switches.First
1655 or else (Linker_Switches.Table (Opt - 1).all /= "-u
"
1657 Linker_Switches.Table (Opt - 1).all /= "-Xlinker
"
1659 Linker_Switches.Table (Opt - 1).all /= "-L
")
1662 Add_Str_To_Name_Buffer (Linker_Switches.Table (Opt).all);
1663 Check_File (Name_Find);
1667 end Check_Linker_Options;
1673 procedure Check_Steps is
1675 -- If either -c, -b or -l has been specified, we will not necessarily
1676 -- execute all steps.
1679 Do_Compile_Step := Do_Compile_Step and Compile_Only;
1680 Do_Bind_Step := Do_Bind_Step and Bind_Only;
1681 Do_Link_Step := Do_Link_Step and Link_Only;
1683 -- If -c has been specified, but not -b, ignore any potential -l
1685 if Do_Compile_Step and then not Do_Bind_Step then
1686 Do_Link_Step := False;
1691 -----------------------
1692 -- Collect_Arguments --
1693 -----------------------
1695 procedure Collect_Arguments
1696 (Source_File : File_Name_Type;
1698 Args : Argument_List)
1701 Arguments_Collected := True;
1702 Arguments_Project := No_Project;
1704 Add_Arguments (Args);
1706 if Main_Project /= No_Project then
1708 Source_File_Name : constant String :=
1709 Get_Name_String (Source_File);
1710 Compiler_Package : Prj.Package_Id;
1711 Switches : Prj.Variable_Value;
1712 Data : Project_Data;
1717 (Source_File_Name => Source_File_Name,
1718 Project => Arguments_Project,
1719 Path => Arguments_Path_Name);
1721 -- If the source is not a source of a project file, check if
1724 if Arguments_Project = No_Project then
1725 if not External_Unit_Compilation_Allowed then
1726 Make_Failed ("external source
(", Source_File_Name,
1727 ") is not part
of any project
; cannot be
" &
1728 "compiled without gnatmake switch
-x
");
1731 -- If it is allowed, simply add the saved gcc switches
1733 Add_Arguments (The_Saved_Gcc_Switches.all);
1736 -- We get the project directory for the relative path
1737 -- switches and arguments.
1739 Data := Projects.Table (Arguments_Project);
1741 -- If the source is in an extended project, we go to
1742 -- the ultimate extending project.
1744 while Data.Extended_By /= No_Project loop
1745 Arguments_Project := Data.Extended_By;
1746 Data := Projects.Table (Arguments_Project);
1749 -- If building a dynamic or relocatable library, compile with
1750 -- PIC option, if it exists.
1752 if Data.Library and then Data.Library_Kind /= Static then
1754 PIC : constant String := MLib.Tgt.PIC_Option;
1758 Add_Arguments ((1 => new String'(PIC)));
1763 if Data.Dir_Path = null then
1765 new String'(Get_Name_String (Data.Display_Directory));
1766 Projects.Table (Arguments_Project) := Data;
1769 -- We now look for package Compiler
1770 -- and get the switches from this package.
1774 (Name => Name_Compiler,
1775 In_Packages => Data.Decl.Packages);
1777 if Compiler_Package /= No_Package then
1779 -- If package Gnatmake.Compiler exists, we get
1780 -- the specific switches for the current source,
1781 -- or the global switches, if any.
1783 Switches := Switches_Of
1784 (Source_File => Source_File,
1785 Source_File_Name => Source_File_Name,
1786 Source_Index => Source_Index,
1787 Naming => Data.Naming,
1788 In_Package => Compiler_Package,
1789 Allow_ALI => False);
1793 case Switches.Kind is
1795 -- We have a list of switches. We add these switches,
1796 -- plus the saved gcc switches.
1801 Current : String_List_Id := Switches.Values;
1802 Element : String_Element;
1803 Number : Natural := 0;
1806 while Current /= Nil_String loop
1807 Element := String_Elements.Table (Current);
1808 Number := Number + 1;
1809 Current := Element.Next;
1813 New_Args : Argument_List (1 .. Number);
1816 Current := Switches.Values;
1818 for Index in New_Args'Range loop
1819 Element := String_Elements.Table (Current);
1820 Get_Name_String (Element.Value);
1822 new String'(Name_Buffer (1 .. Name_Len));
1823 Test_If_Relative_Path
1824 (New_Args (Index), Parent => Data.Dir_Path);
1825 Current := Element.Next;
1829 (Configuration_Pragmas_Switch
1830 (Arguments_Project) &
1831 New_Args & The_Saved_Gcc_Switches.all);
1835 -- We have a single switch. We add this switch,
1836 -- plus the saved gcc switches.
1839 Get_Name_String (Switches.Value);
1842 New_Args : Argument_List :=
1844 (Name_Buffer (1 .. Name_Len)));
1847 Test_If_Relative_Path
1848 (New_Args (1), Parent => Data.Dir_Path);
1850 (Configuration_Pragmas_Switch (Arguments_Project) &
1851 New_Args & The_Saved_Gcc_Switches.all);
1854 -- We have no switches from Gnatmake.Compiler.
1855 -- We add the saved gcc switches.
1859 (Configuration_Pragmas_Switch (Arguments_Project) &
1860 The_Saved_Gcc_Switches.all);
1866 -- Set Output_Is_Object, depending if there is a -S switch.
1867 -- If the bind step is not performed, and there is a -S switch,
1868 -- then we will not check for a valid object file.
1871 end Collect_Arguments;
1873 ---------------------
1874 -- Compile_Sources --
1875 ---------------------
1877 procedure Compile_Sources
1878 (Main_Source : File_Name_Type;
1879 Args : Argument_List;
1880 First_Compiled_File : out Name_Id;
1881 Most_Recent_Obj_File : out Name_Id;
1882 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
1883 Main_Unit : out Boolean;
1884 Compilation_Failures : out Natural;
1885 Main_Index : Int := 0;
1886 Check_Readonly_Files : Boolean := False;
1887 Do_Not_Execute : Boolean := False;
1888 Force_Compilations : Boolean := False;
1889 Keep_Going : Boolean := False;
1890 In_Place_Mode : Boolean := False;
1891 Initialize_ALI_Data : Boolean := True;
1892 Max_Process : Positive := 1)
1894 No_Mapping_File : constant Natural := 0;
1896 type Compilation_Data is record
1898 Full_Source_File : File_Name_Type;
1899 Lib_File : File_Name_Type;
1900 Source_Unit : Unit_Name_Type;
1901 Mapping_File : Natural := No_Mapping_File;
1902 Project : Project_Id := No_Project;
1903 Syntax_Only : Boolean := False;
1904 Output_Is_Object : Boolean := True;
1907 Running_Compile : array (1 .. Max_Process) of Compilation_Data;
1908 -- Used to save information about outstanding compilations
1910 Outstanding_Compiles : Natural := 0;
1911 -- Current number of outstanding compiles
1913 Source_Unit : Unit_Name_Type;
1914 -- Current source unit
1916 Source_File : File_Name_Type;
1917 -- Current source file
1919 Full_Source_File : File_Name_Type;
1920 -- Full name of the current source file
1922 Lib_File : File_Name_Type;
1923 -- Current library file
1925 Full_Lib_File : File_Name_Type;
1926 -- Full name of the current library file
1928 Obj_File : File_Name_Type;
1929 -- Full name of the object file corresponding to Lib_File
1931 Obj_Stamp : Time_Stamp_Type;
1932 -- Time stamp of the current object file
1934 Sfile : File_Name_Type;
1935 -- Contains the source file of the units withed by Source_File
1938 -- ALI Id of the current ALI file
1940 -- Comment following declarations ???
1942 Read_Only : Boolean := False;
1944 Compilation_OK : Boolean;
1945 Need_To_Compile : Boolean;
1948 Text : Text_Buffer_Ptr;
1950 Mfile : Natural := No_Mapping_File;
1952 Need_To_Check_Standard_Library : Boolean :=
1953 Check_Readonly_Files
1954 and not Unique_Compile;
1956 Mapping_File_Arg : String_Access;
1958 Process_Created : Boolean := False;
1960 procedure Add_Process
1962 Sfile : File_Name_Type;
1963 Afile : File_Name_Type;
1964 Uname : Unit_Name_Type;
1965 Mfile : Natural := No_Mapping_File);
1966 -- Adds process Pid to the current list of outstanding compilation
1967 -- processes and record the full name of the source file Sfile that
1968 -- we are compiling, the name of its library file Afile and the
1969 -- name of its unit Uname. If Mfile is not equal to No_Mapping_File,
1970 -- it is the index of the mapping file used during compilation in the
1971 -- array The_Mapping_File_Names.
1973 procedure Await_Compile
1974 (Sfile : out File_Name_Type;
1975 Afile : out File_Name_Type;
1976 Uname : out Unit_Name_Type;
1978 -- Awaits that an outstanding compilation process terminates. When
1979 -- it does set Sfile to the name of the source file that was compiled
1980 -- Afile to the name of its library file and Uname to the name of its
1981 -- unit. Note that this time stamp can be used to check whether the
1982 -- compilation did generate an object file. OK is set to True if the
1983 -- compilation succeeded. Note that Sfile, Afile and Uname could be
1984 -- resp. No_File, No_File and No_Name if there were no compilations
1987 function Bad_Compilation_Count return Natural;
1988 -- Returns the number of compilation failures
1990 procedure Check_Standard_Library;
1991 -- Check if s-stalib.adb needs to be compiled
1993 procedure Collect_Arguments_And_Compile
1994 (Source_File : File_Name_Type; Source_Index : Int);
1995 -- Collect arguments from project file (if any) and compile
2001 Args : Argument_List) return Process_Id;
2002 -- Compiles S using Args. If S is a GNAT predefined source
2003 -- "-gnatpg
" is added to Args. Non blocking call. L corresponds to the
2004 -- expected library file name. Process_Id of the process spawned to
2005 -- execute the compile.
2007 package Good_ALI is new Table.Table (
2008 Table_Component_Type => ALI_Id,
2009 Table_Index_Type => Natural,
2010 Table_Low_Bound => 1,
2011 Table_Initial => 50,
2012 Table_Increment => 100,
2013 Table_Name => "Make
.Good_ALI
");
2014 -- Contains the set of valid ALI files that have not yet been scanned
2016 function Good_ALI_Present return Boolean;
2017 -- Returns True if any ALI file was recorded in the previous set
2019 procedure Get_Mapping_File (Project : Project_Id);
2020 -- Get a mapping file name. If there is one to be reused, reuse it.
2021 -- Otherwise, create a new mapping file.
2023 function Get_Next_Good_ALI return ALI_Id;
2024 -- Returns the next good ALI_Id record
2026 procedure Record_Failure
2027 (File : File_Name_Type;
2028 Unit : Unit_Name_Type;
2029 Found : Boolean := True);
2030 -- Records in the previous table that the compilation for File failed.
2031 -- If Found is False then the compilation of File failed because we
2032 -- could not find it. Records also Unit when possible.
2034 procedure Record_Good_ALI (A : ALI_Id);
2035 -- Records in the previous set the Id of an ALI file
2041 procedure Add_Process
2043 Sfile : File_Name_Type;
2044 Afile : File_Name_Type;
2045 Uname : Unit_Name_Type;
2046 Mfile : Natural := No_Mapping_File)
2048 OC1 : constant Positive := Outstanding_Compiles + 1;
2051 pragma Assert (OC1 <= Max_Process);
2052 pragma Assert (Pid /= Invalid_Pid);
2054 Running_Compile (OC1).Pid := Pid;
2055 Running_Compile (OC1).Full_Source_File := Sfile;
2056 Running_Compile (OC1).Lib_File := Afile;
2057 Running_Compile (OC1).Source_Unit := Uname;
2058 Running_Compile (OC1).Mapping_File := Mfile;
2059 Running_Compile (OC1).Project := Arguments_Project;
2060 Running_Compile (OC1).Syntax_Only := Syntax_Only;
2061 Running_Compile (OC1).Output_Is_Object := Output_Is_Object;
2063 Outstanding_Compiles := OC1;
2066 --------------------
2070 procedure Await_Compile
2071 (Sfile : out File_Name_Type;
2072 Afile : out File_Name_Type;
2073 Uname : out File_Name_Type;
2077 Project : Project_Id;
2080 pragma Assert (Outstanding_Compiles > 0);
2087 -- The loop here is a work-around for a problem on VMS; in some
2088 -- circumstances (shared library and several executables, for
2089 -- example), there are child processes other than compilation
2090 -- processes that are received. Until this problem is resolved,
2091 -- we will ignore such processes.
2094 Wait_Process (Pid, OK);
2096 if Pid = Invalid_Pid then
2100 for J in Running_Compile'First .. Outstanding_Compiles loop
2101 if Pid = Running_Compile (J).Pid then
2102 Sfile := Running_Compile (J).Full_Source_File;
2103 Afile := Running_Compile (J).Lib_File;
2104 Uname := Running_Compile (J).Source_Unit;
2105 Syntax_Only := Running_Compile (J).Syntax_Only;
2106 Output_Is_Object := Running_Compile (J).Output_Is_Object;
2107 Project := Running_Compile (J).Project;
2109 -- If a mapping file was used by this compilation,
2110 -- get its file name for reuse by a subsequent compilation
2112 if Running_Compile (J).Mapping_File /= No_Mapping_File then
2113 Last_Free_Indices (Project) :=
2114 Last_Free_Indices (Project) + 1;
2115 The_Free_Mapping_File_Indices
2116 (Project, Last_Free_Indices (Project)) :=
2117 Running_Compile (J).Mapping_File;
2120 -- To actually remove this Pid and related info from
2121 -- Running_Compile replace its entry with the last valid
2122 -- entry in Running_Compile.
2124 if J = Outstanding_Compiles then
2128 Running_Compile (J) :=
2129 Running_Compile (Outstanding_Compiles);
2132 Outstanding_Compiles := Outstanding_Compiles - 1;
2137 -- This child process was not one of our compilation processes;
2138 -- just ignore it for now.
2140 -- raise Program_Error;
2144 ---------------------------
2145 -- Bad_Compilation_Count --
2146 ---------------------------
2148 function Bad_Compilation_Count return Natural is
2150 return Bad_Compilation.Last - Bad_Compilation.First + 1;
2151 end Bad_Compilation_Count;
2153 ----------------------------
2154 -- Check_Standard_Library --
2155 ----------------------------
2157 procedure Check_Standard_Library is
2159 Need_To_Check_Standard_Library := False;
2161 if not Targparm.Suppress_Standard_Library_On_Target then
2164 Add_It : Boolean := True;
2167 Name_Len := Standard_Library_Package_Body_Name'Length;
2168 Name_Buffer (1 .. Name_Len) :=
2169 Standard_Library_Package_Body_Name;
2170 Sfile := Name_Enter;
2172 -- If we have a special runtime, we add the standard
2173 -- library only if we can find it.
2177 Find_File (Sfile, Osint.Source) /= No_File;
2181 if Is_Marked (Sfile) then
2182 if Is_In_Obsoleted (Sfile) then
2183 Executable_Obsolete := True;
2187 Insert_Q (Sfile, Index => 0);
2188 Mark (Sfile, Index => 0);
2193 end Check_Standard_Library;
2195 -----------------------------------
2196 -- Collect_Arguments_And_Compile --
2197 -----------------------------------
2199 procedure Collect_Arguments_And_Compile
2200 (Source_File : File_Name_Type; Source_Index : Int)
2203 -- Process_Created will be set True if an attempt is made to compile
2204 -- the source, that is if it is not in an externally built project.
2206 Process_Created := False;
2208 -- If arguments not yet collected (in Check), collect them now
2210 if not Arguments_Collected then
2211 Collect_Arguments (Source_File, Source_Index, Args);
2214 -- If we use mapping file (-P or -C switches), then get one
2216 if Create_Mapping_File then
2217 Get_Mapping_File (Arguments_Project);
2220 -- If the source is part of a project file, we set the ADA_*_PATHs,
2221 -- check for an eventual library project, and use the full path.
2223 if Arguments_Project /= No_Project then
2224 if not Projects.Table (Arguments_Project).Externally_Built then
2225 Prj.Env.Set_Ada_Paths (Arguments_Project, True);
2227 if not Unique_Compile
2228 and then MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None
2231 The_Data : Project_Data :=
2232 Projects.Table (Arguments_Project);
2234 Prj : Project_Id := Arguments_Project;
2237 while The_Data.Extended_By /= No_Project loop
2238 Prj := The_Data.Extended_By;
2239 The_Data := Projects.Table (Prj);
2243 and then not The_Data.Need_To_Build_Lib
2245 -- Add to the Q all sources of the project that
2246 -- have not been marked
2248 Insert_Project_Sources
2249 (The_Project => Prj,
2250 All_Projects => False,
2253 -- Now mark the project as processed
2255 Projects.Table (Prj).Need_To_Build_Lib := True;
2260 -- Change to the object directory of the project file,
2263 Change_To_Object_Directory (Arguments_Project);
2265 Pid := Compile (Arguments_Path_Name, Lib_File, Source_Index,
2266 Arguments (1 .. Last_Argument));
2267 Process_Created := True;
2271 -- If this is a source outside of any project file, make sure it
2272 -- will be compiled in object directory of the main project file.
2274 if Main_Project /= No_Project then
2275 Change_To_Object_Directory (Arguments_Project);
2278 Pid := Compile (Full_Source_File, Lib_File, Source_Index,
2279 Arguments (1 .. Last_Argument));
2280 Process_Created := True;
2282 end Collect_Arguments_And_Compile;
2292 Args : Argument_List) return Process_Id
2294 Comp_Args : Argument_List (Args'First .. Args'Last + 9);
2295 Comp_Next : Integer := Args'First;
2296 Comp_Last : Integer;
2298 function Ada_File_Name (Name : Name_Id) return Boolean;
2299 -- Returns True if Name is the name of an ada source file
2300 -- (i.e. suffix is .ads or .adb)
2306 function Ada_File_Name (Name : Name_Id) return Boolean is
2308 Get_Name_String (Name);
2311 and then Name_Buffer (Name_Len - 3 .. Name_Len - 1) = ".ad
"
2312 and then (Name_Buffer (Name_Len) = 'b'
2314 Name_Buffer (Name_Len) = 's');
2317 -- Start of processing for Compile
2320 Enter_Into_Obsoleted (S);
2322 -- By default, Syntax_Only is False
2324 Syntax_Only := False;
2326 for J in Args'Range loop
2327 if Args (J).all = "-gnats
" then
2329 -- If we compile with -gnats, the bind step and the link step
2330 -- are inhibited. Also, we set Syntax_Only to True, so that
2331 -- we don't fail when we don't find the ALI file, after
2334 Do_Bind_Step := False;
2335 Do_Link_Step := False;
2336 Syntax_Only := True;
2338 elsif Args (J).all = "-gnatc
" then
2340 -- If we compile with -gnatc, the bind step and the link step
2341 -- are inhibited. We set Syntax_Only to False for the case when
2342 -- -gnats was previously specified.
2344 Do_Bind_Step := False;
2345 Do_Link_Step := False;
2346 Syntax_Only := False;
2350 Comp_Args (Comp_Next) := Comp_Flag;
2351 Comp_Next := Comp_Next + 1;
2353 -- Optimize the simple case where the gcc command line looks like
2354 -- gcc -c -I. ... -I- file.adb --into-> gcc -c ... file.adb
2356 if Args (Args'First).all = "-I
" & Normalized_CWD
2357 and then Args (Args'Last).all = "-I
-"
2358 and then S = Strip_Directory (S)
2360 Comp_Last := Comp_Next + Args'Length - 3;
2361 Comp_Args (Comp_Next .. Comp_Last) :=
2362 Args (Args'First + 1 .. Args'Last - 1);
2365 Comp_Last := Comp_Next + Args'Length - 1;
2366 Comp_Args (Comp_Next .. Comp_Last) := Args;
2369 -- Set -gnatpg for predefined files (for this purpose the renamings
2370 -- such as Text_IO do not count as predefined). Note that we strip
2371 -- the directory name from the source file name becase the call to
2372 -- Fname.Is_Predefined_File_Name cannot deal with directory prefixes.
2375 Fname : constant File_Name_Type := Strip_Directory (S);
2378 if Is_Predefined_File_Name (Fname, False) then
2379 if Check_Readonly_Files then
2380 Comp_Last := Comp_Last + 1;
2381 Comp_Args (Comp_Last) := GNAT_Flag;
2385 ("not allowed to compile
""" &
2386 Get_Name_String (Fname) &
2387 """; use -a switch
, or compile file
with " &
2388 """-gnatg
"" switch
");
2393 -- Now check if the file name has one of the suffixes familiar to
2394 -- the gcc driver. If this is not the case then add the ada flag
2397 if not Ada_File_Name (S) and then not Targparm.AAMP_On_Target then
2398 Comp_Last := Comp_Last + 1;
2399 Comp_Args (Comp_Last) := Ada_Flag_1;
2400 Comp_Last := Comp_Last + 1;
2401 Comp_Args (Comp_Last) := Ada_Flag_2;
2404 if Source_Index /= 0 then
2406 Num : constant String := Source_Index'Img;
2408 Comp_Last := Comp_Last + 1;
2409 Comp_Args (Comp_Last) :=
2410 new String'("-gnateI
" & Num (Num'First + 1 .. Num'Last));
2414 if Source_Index /= 0 or else
2415 L /= Strip_Directory (L) or else
2416 Object_Directory_Path /= null
2418 -- Build -o argument
2420 Get_Name_String (L);
2422 for J in reverse 1 .. Name_Len loop
2423 if Name_Buffer (J) = '.' then
2424 Name_Len := J + Object_Suffix'Length - 1;
2425 Name_Buffer (J .. Name_Len) := Object_Suffix;
2430 Comp_Last := Comp_Last + 1;
2431 Comp_Args (Comp_Last) := Output_Flag;
2432 Comp_Last := Comp_Last + 1;
2434 -- If an object directory was specified, prepend the object file
2435 -- name with this object directory.
2437 if Object_Directory_Path /= null then
2438 Comp_Args (Comp_Last) :=
2439 new String'(Object_Directory_Path.all &
2440 Name_Buffer (1 .. Name_Len));
2443 Comp_Args (Comp_Last) :=
2444 new String'(Name_Buffer (1 .. Name_Len));
2448 if Create_Mapping_File then
2449 Comp_Last := Comp_Last + 1;
2450 Comp_Args (Comp_Last) := Mapping_File_Arg;
2453 Get_Name_String (S);
2455 Comp_Last := Comp_Last + 1;
2456 Comp_Args (Comp_Last) := new String'(Name_Buffer (1 .. Name_Len));
2458 GNAT.OS_Lib.Normalize_Arguments (Comp_Args (Args'First .. Comp_Last));
2460 Comp_Last := Comp_Last + 1;
2461 Comp_Args (Comp_Last) := new String'("-gnatez
");
2463 Display (Gcc.all, Comp_Args (Args'First .. Comp_Last));
2465 if Gcc_Path = null then
2466 Make_Failed ("error
, unable to locate
", Gcc.all);
2470 GNAT.OS_Lib.Non_Blocking_Spawn
2471 (Gcc_Path.all, Comp_Args (Args'First .. Comp_Last));
2474 ----------------------
2475 -- Get_Mapping_File --
2476 ----------------------
2478 procedure Get_Mapping_File (Project : Project_Id) is
2480 -- If there is a mapping file ready to be reused, reuse it
2482 if Last_Free_Indices (Project) > 0 then
2483 Mfile := The_Free_Mapping_File_Indices
2484 (Project, Last_Free_Indices (Project));
2485 Last_Free_Indices (Project) := Last_Free_Indices (Project) - 1;
2487 -- Otherwise, create and initialize a new one
2490 Init_Mapping_File (Project => Project, File_Index => Mfile);
2493 -- Put the name in the mapping file argument for the invocation
2496 Free (Mapping_File_Arg);
2498 new String'("-gnatem
=" &
2500 (The_Mapping_File_Names (Project, Mfile)));
2502 end Get_Mapping_File;
2504 -----------------------
2505 -- Get_Next_Good_ALI --
2506 -----------------------
2508 function Get_Next_Good_ALI return ALI_Id is
2512 pragma Assert (Good_ALI_Present);
2513 ALI := Good_ALI.Table (Good_ALI.Last);
2514 Good_ALI.Decrement_Last;
2516 end Get_Next_Good_ALI;
2518 ----------------------
2519 -- Good_ALI_Present --
2520 ----------------------
2522 function Good_ALI_Present return Boolean is
2524 return Good_ALI.First <= Good_ALI.Last;
2525 end Good_ALI_Present;
2527 --------------------
2528 -- Record_Failure --
2529 --------------------
2531 procedure Record_Failure
2532 (File : File_Name_Type;
2533 Unit : Unit_Name_Type;
2534 Found : Boolean := True)
2537 Bad_Compilation.Increment_Last;
2538 Bad_Compilation.Table (Bad_Compilation.Last) := (File, Unit, Found);
2541 ---------------------
2542 -- Record_Good_ALI --
2543 ---------------------
2545 procedure Record_Good_ALI (A : ALI_Id) is
2547 Good_ALI.Increment_Last;
2548 Good_ALI.Table (Good_ALI.Last) := A;
2549 end Record_Good_ALI;
2551 -- Start of processing for Compile_Sources
2554 pragma Assert (Args'First = 1);
2556 -- Package and Queue initializations
2559 Output.Set_Standard_Error;
2561 if First_Q_Initialization then
2565 if Initialize_ALI_Data then
2567 Initialize_ALI_Source;
2570 -- The following two flags affect the behavior of ALI.Set_Source_Table.
2571 -- We set Check_Source_Files to True to ensure that source file
2572 -- time stamps are checked, and we set All_Sources to False to
2573 -- avoid checking the presence of the source files listed in the
2574 -- source dependency section of an ali file (which would be a mistake
2575 -- since the ali file may be obsolete).
2577 Check_Source_Files := True;
2578 All_Sources := False;
2580 -- Only insert in the Q if it is not already done, to avoid simultaneous
2581 -- compilations if -jnnn is used.
2583 if not Is_Marked (Main_Source, Main_Index) then
2584 Insert_Q (Main_Source, Index => Main_Index);
2585 Mark (Main_Source, Main_Index);
2588 First_Compiled_File := No_File;
2589 Most_Recent_Obj_File := No_File;
2590 Most_Recent_Obj_Stamp := Empty_Time_Stamp;
2593 -- Keep looping until there is no more work to do (the Q is empty)
2594 -- and all the outstanding compilations have terminated
2596 Make_Loop : while not Empty_Q or else Outstanding_Compiles > 0 loop
2598 -- If the user does not want to keep going in case of errors then
2599 -- wait for the remaining outstanding compiles and then exit.
2601 if Bad_Compilation_Count > 0 and then not Keep_Going then
2602 while Outstanding_Compiles > 0 loop
2604 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
2606 if not Compilation_OK then
2607 Record_Failure (Full_Source_File, Source_Unit);
2614 -- PHASE 1: Check if there is more work that we can do (ie the Q
2615 -- is non empty). If there is, do it only if we have not yet used
2616 -- up all the available processes.
2618 if not Empty_Q and then Outstanding_Compiles < Max_Process then
2621 -- Index of the current unit in the current source file
2624 Extract_From_Q (Source_File, Source_Unit, Source_Index);
2625 Full_Source_File := Osint.Full_Source_Name (Source_File);
2626 Lib_File := Osint.Lib_File_Name
2627 (Source_File, Source_Index);
2628 Full_Lib_File := Osint.Full_Lib_File_Name (Lib_File);
2630 -- If this source has already been compiled, the executable is
2633 if Is_In_Obsoleted (Source_File) then
2634 Executable_Obsolete := True;
2637 -- If the library file is an Ada library skip it
2639 if Full_Lib_File /= No_File
2640 and then In_Ada_Lib_Dir (Full_Lib_File)
2643 (Lib_File, "is in an Ada library
", Prefix => " ");
2645 -- If the library file is a read-only library skip it, but
2646 -- only if, when using project files, this library file is
2647 -- in the right object directory (a read-only ALI file
2648 -- in the object directory of a project being extended
2649 -- should not be skipped).
2651 elsif Full_Lib_File /= No_File
2652 and then not Check_Readonly_Files
2653 and then Is_Readonly_Library (Full_Lib_File)
2654 and then Is_In_Object_Directory (Source_File, Full_Lib_File)
2657 (Lib_File, "is a read
-only library
", Prefix => " ");
2659 -- The source file that we are checking cannot be located
2661 elsif Full_Source_File = No_File then
2662 Record_Failure (Source_File, Source_Unit, False);
2664 -- Source and library files can be located but are internal
2667 elsif not Check_Readonly_Files
2668 and then Full_Lib_File /= No_File
2669 and then Is_Internal_File_Name (Source_File)
2671 if Force_Compilations then
2673 ("not allowed to compile
""" &
2674 Get_Name_String (Source_File) &
2675 """; use -a switch
, or compile file
with " &
2676 """-gnatg
"" switch
");
2680 (Lib_File, "is an internal library
", Prefix => " ");
2682 -- The source file that we are checking can be located
2685 Arguments_Collected := False;
2687 -- Don't waste any time if we have to recompile anyway
2689 Obj_Stamp := Empty_Time_Stamp;
2690 Need_To_Compile := Force_Compilations;
2692 if not Force_Compilations then
2694 Full_Lib_File /= No_File
2695 and then not Check_Readonly_Files
2696 and then Is_Readonly_Library (Full_Lib_File);
2697 Check (Source_File, Source_Index, Args, Lib_File,
2698 Read_Only, ALI, Obj_File, Obj_Stamp);
2699 Need_To_Compile := (ALI = No_ALI_Id);
2702 if not Need_To_Compile then
2704 -- The ALI file is up-to-date. Record its Id
2706 Record_Good_ALI (ALI);
2708 -- Record the time stamp of the most recent object file
2709 -- as long as no (re)compilations are needed.
2711 if First_Compiled_File = No_File
2712 and then (Most_Recent_Obj_File = No_File
2713 or else Obj_Stamp > Most_Recent_Obj_Stamp)
2715 Most_Recent_Obj_File := Obj_File;
2716 Most_Recent_Obj_Stamp := Obj_Stamp;
2720 -- Is this the first file we have to compile?
2722 if First_Compiled_File = No_File then
2723 First_Compiled_File := Full_Source_File;
2724 Most_Recent_Obj_File := No_File;
2726 if Do_Not_Execute then
2731 if In_Place_Mode then
2733 -- If the library file was not found, then save the
2734 -- library file near the source file.
2736 if Full_Lib_File = No_File then
2737 Lib_File := Osint.Lib_File_Name
2738 (Full_Source_File, Source_Index);
2740 -- If the library file was found, then save the
2741 -- library file in the same place.
2744 Lib_File := Full_Lib_File;
2749 -- Start the compilation and record it. We can do this
2750 -- because there is at least one free process.
2752 Collect_Arguments_And_Compile (Source_File, Source_Index);
2754 -- Make sure we could successfully start the compilation
2756 if Process_Created then
2757 if Pid = Invalid_Pid then
2758 Record_Failure (Full_Source_File, Source_Unit);
2773 -- PHASE 2: Now check if we should wait for a compilation to
2774 -- finish. This is the case if all the available processes are
2775 -- busy compiling sources or there is nothing else to do
2776 -- (that is the Q is empty and there are no good ALIs to process).
2778 if Outstanding_Compiles = Max_Process
2780 and then not Good_ALI_Present
2781 and then Outstanding_Compiles > 0)
2784 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
2786 if not Compilation_OK then
2787 Record_Failure (Full_Source_File, Source_Unit);
2790 if Compilation_OK or else Keep_Going then
2792 -- Re-read the updated library file
2795 Saved_Object_Consistency : constant Boolean :=
2796 Check_Object_Consistency;
2799 -- If compilation was not OK, or if output is not an
2800 -- object file and we don't do the bind step, don't check
2801 -- for object consistency.
2803 Check_Object_Consistency :=
2804 Check_Object_Consistency
2806 and (Output_Is_Object or Do_Bind_Step);
2807 Text := Read_Library_Info (Lib_File);
2809 -- Restore Check_Object_Consistency to its initial value
2811 Check_Object_Consistency := Saved_Object_Consistency;
2814 -- If an ALI file was generated by this compilation, scan
2815 -- the ALI file and record it.
2816 -- If the scan fails, a previous ali file is inconsistent with
2817 -- the unit just compiled.
2819 if Text /= null then
2821 Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
2823 if ALI = No_ALI_Id then
2825 -- Record a failure only if not already done
2827 if Compilation_OK then
2830 "incompatible ALI file
, please recompile
");
2831 Record_Failure (Full_Source_File, Source_Unit);
2835 Record_Good_ALI (ALI);
2838 -- If we could not read the ALI file that was just generated
2839 -- then there could be a problem reading either the ALI or the
2840 -- corresponding object file (if Check_Object_Consistency
2841 -- is set Read_Library_Info checks that the time stamp of the
2842 -- object file is more recent than that of the ALI). For an
2843 -- example of problems caught by this test see [6625-009].
2844 -- However, we record a failure only if not already done.
2847 if Compilation_OK and not Syntax_Only then
2850 "WARNING
: ALI
or object file
not found after compile
");
2851 Record_Failure (Full_Source_File, Source_Unit);
2857 -- PHASE 3: Check if we recorded good ALI files. If yes process
2858 -- them now in the order in which they have been recorded. There
2859 -- are two occasions in which we record good ali files. The first is
2860 -- in phase 1 when, after scanning an existing ALI file we realize
2861 -- it is up-to-date, the second instance is after a successful
2864 while Good_ALI_Present loop
2865 ALI := Get_Next_Good_ALI;
2868 Source_Index : Int := Unit_Index_Of (ALIs.Table (ALI).Afile);
2871 -- If we are processing the library file corresponding to the
2872 -- main source file check if this source can be a main unit.
2874 if ALIs.Table (ALI).Sfile = Main_Source and then
2875 Source_Index = Main_Index
2877 Main_Unit := ALIs.Table (ALI).Main_Program /= None;
2880 -- The following adds the standard library (s-stalib) to the
2881 -- list of files to be handled by gnatmake: this file and any
2882 -- files it depends on are always included in every bind,
2883 -- even if they are not in the explicit dependency list.
2884 -- Of course, it is not added if Suppress_Standard_Library
2887 -- However, to avoid annoying output about s-stalib.ali being
2888 -- read only, when "-v
" is used, we add the standard library
2889 -- only when "-a
" is used.
2891 if Need_To_Check_Standard_Library then
2892 Check_Standard_Library;
2895 -- Now insert in the Q the unmarked source files (i.e. those
2896 -- which have never been inserted in the Q and hence never
2897 -- considered). Only do that if Unique_Compile is False.
2899 if not Unique_Compile then
2901 ALIs.Table (ALI).First_Unit .. ALIs.Table (ALI).Last_Unit
2904 Units.Table (J).First_With .. Units.Table (J).Last_With
2906 Sfile := Withs.Table (K).Sfile;
2907 Add_Dependency (ALIs.Table (ALI).Sfile, Sfile);
2909 if Is_In_Obsoleted (Sfile) then
2910 Executable_Obsolete := True;
2913 if Sfile = No_File then
2915 ("Skipping
generic:", Withs.Table (K).Uname);
2919 Unit_Index_Of (Withs.Table (K).Afile);
2921 if Is_Marked (Sfile, Source_Index) then
2922 Debug_Msg ("Skipping marked file
:", Sfile);
2924 elsif not Check_Readonly_Files
2925 and then Is_Internal_File_Name (Sfile)
2927 Debug_Msg ("Skipping internal file
:", Sfile);
2931 (Sfile, Withs.Table (K).Uname, Source_Index);
2932 Mark (Sfile, Source_Index);
2941 if Display_Compilation_Progress then
2942 Write_Str ("completed
");
2943 Write_Int (Int (Q_Front));
2944 Write_Str (" out of ");
2945 Write_Int (Int (Q.Last));
2947 Write_Int (Int ((Q_Front * 100) / (Q.Last - Q.First)));
2948 Write_Str ("%)...");
2953 Compilation_Failures := Bad_Compilation_Count;
2955 -- Compilation is finished
2957 -- Delete any temporary configuration pragma file
2959 Delete_Temp_Config_Files;
2961 end Compile_Sources;
2963 ----------------------------------
2964 -- Configuration_Pragmas_Switch --
2965 ----------------------------------
2967 function Configuration_Pragmas_Switch
2968 (For_Project : Project_Id) return Argument_List
2970 The_Packages : Package_Id;
2971 Gnatmake : Package_Id;
2972 Compiler : Package_Id;
2974 Global_Attribute : Variable_Value := Nil_Variable_Value;
2975 Local_Attribute : Variable_Value := Nil_Variable_Value;
2977 Global_Attribute_Present : Boolean := False;
2978 Local_Attribute_Present : Boolean := False;
2980 Result : Argument_List (1 .. 3);
2981 Last : Natural := 0;
2983 function Absolute_Path
2985 Project : Project_Id) return String;
2986 -- Returns an absolute path for a configuration pragmas file
2992 function Absolute_Path
2994 Project : Project_Id) return String
2997 Get_Name_String (Path);
3000 Path_Name : constant String := Name_Buffer (1 .. Name_Len);
3003 if Is_Absolute_Path (Path_Name) then
3008 Parent_Directory : constant String :=
3009 Get_Name_String (Projects.Table (Project).Directory);
3012 if Parent_Directory (Parent_Directory'Last) =
3015 return Parent_Directory & Path_Name;
3018 return Parent_Directory & Directory_Separator & Path_Name;
3025 -- Start of processing for Configuration_Pragmas_Switch
3028 Prj.Env.Create_Config_Pragmas_File (For_Project, Main_Project);
3030 if Projects.Table (For_Project).Config_File_Name /= No_Name then
3031 Temporary_Config_File :=
3032 Projects.Table (For_Project).Config_File_Temp;
3038 (Projects.Table (For_Project).Config_File_Name));
3041 Temporary_Config_File := False;
3044 -- Check for attribute Builder'Global_Configuration_Pragmas
3046 The_Packages := Projects.Table (Main_Project).Decl.Packages;
3049 (Name => Name_Builder,
3050 In_Packages => The_Packages);
3052 if Gnatmake /= No_Package then
3053 Global_Attribute := Prj.Util.Value_Of
3054 (Variable_Name => Name_Global_Configuration_Pragmas,
3055 In_Variables => Packages.Table (Gnatmake).Decl.Attributes);
3056 Global_Attribute_Present :=
3057 Global_Attribute /= Nil_Variable_Value
3058 and then Get_Name_String (Global_Attribute.Value) /= "";
3060 if Global_Attribute_Present then
3062 Path : constant String :=
3064 (Global_Attribute.Value, Global_Attribute.Project);
3066 if not Is_Regular_File (Path) then
3068 ("cannot find configuration pragmas file
", Path);
3072 Result (Last) := new String'("-gnatec
=" & Path);
3077 -- Check for attribute Compiler'Local_Configuration_Pragmas
3079 The_Packages := Projects.Table (For_Project).Decl.Packages;
3082 (Name => Name_Compiler,
3083 In_Packages => The_Packages);
3085 if Compiler /= No_Package then
3086 Local_Attribute := Prj.Util.Value_Of
3087 (Variable_Name => Name_Local_Configuration_Pragmas,
3088 In_Variables => Packages.Table (Compiler).Decl.Attributes);
3089 Local_Attribute_Present :=
3090 Local_Attribute /= Nil_Variable_Value
3091 and then Get_Name_String (Local_Attribute.Value) /= "";
3093 if Local_Attribute_Present then
3095 Path : constant String :=
3097 (Local_Attribute.Value, Local_Attribute.Project);
3099 if not Is_Regular_File (Path) then
3101 ("cannot find configuration pragmas file
", Path);
3105 Result (Last) := new String'("-gnatec
=" & Path);
3110 return Result (1 .. Last);
3111 end Configuration_Pragmas_Switch;
3117 procedure Debug_Msg (S : String; N : Name_Id) is
3119 if Debug.Debug_Flag_W then
3120 Write_Str (" ... ");
3128 ---------------------------
3129 -- Delete_All_Temp_Files --
3130 ---------------------------
3132 procedure Delete_All_Temp_Files is
3134 if Gnatmake_Called and not Debug.Debug_Flag_N then
3135 Delete_Mapping_Files;
3136 Delete_Temp_Config_Files;
3137 Prj.Env.Delete_All_Path_Files;
3139 end Delete_All_Temp_Files;
3141 --------------------------
3142 -- Delete_Mapping_Files --
3143 --------------------------
3145 procedure Delete_Mapping_Files is
3148 if not Debug.Debug_Flag_N then
3149 if The_Mapping_File_Names /= null then
3150 for Project in The_Mapping_File_Names'Range (1) loop
3151 for Index in 1 .. Last_Mapping_File_Names (Project) loop
3153 (Name => Get_Name_String
3154 (The_Mapping_File_Names (Project, Index)),
3155 Success => Success);
3160 end Delete_Mapping_Files;
3162 ------------------------------
3163 -- Delete_Temp_Config_Files --
3164 ------------------------------
3166 procedure Delete_Temp_Config_Files is
3169 if (not Debug.Debug_Flag_N) and Main_Project /= No_Project then
3170 for Project in 1 .. Projects.Last loop
3171 if Projects.Table (Project).Config_File_Temp then
3172 if Verbose_Mode then
3173 Write_Str ("Deleting temp configuration file
""");
3174 Write_Str (Get_Name_String
3175 (Projects.Table (Project).Config_File_Name));
3180 (Name => Get_Name_String
3181 (Projects.Table (Project).Config_File_Name),
3182 Success => Success);
3184 -- Make sure that we don't have a config file for this
3185 -- project, in case when there are several mains.
3186 -- In this case, we will recreate another config file:
3187 -- we cannot reuse the one that we just deleted!
3189 Projects.Table (Project).Config_Checked := False;
3190 Projects.Table (Project).Config_File_Name := No_Name;
3191 Projects.Table (Project).Config_File_Temp := False;
3195 end Delete_Temp_Config_Files;
3201 procedure Display (Program : String; Args : Argument_List) is
3203 pragma Assert (Args'First = 1);
3205 if Display_Executed_Programs then
3206 Write_Str (Program);
3208 for J in Args'Range loop
3210 -- Never display -gnatez
3212 if Args (J).all /= "-gnatez
" then
3214 -- Do not display the mapping file argument automatically
3215 -- created when using a project file.
3217 if Main_Project = No_Project
3218 or else Debug.Debug_Flag_N
3219 or else Args (J)'Length < 8
3221 Args (J) (Args (J)'First .. Args (J)'First + 6) /= "-gnatem
"
3223 -- When -dn is not specified, do not display the config
3224 -- pragmas switch (-gnatec) for the temporary file created
3225 -- by the project manager (always the first -gnatec switch).
3226 -- Reset Temporary_Config_File to False so that the eventual
3227 -- other -gnatec switches will be displayed.
3229 if (not Debug.Debug_Flag_N)
3230 and then Temporary_Config_File
3231 and then Args (J)'Length > 7
3232 and then Args (J) (Args (J)'First .. Args (J)'First + 6)
3235 Temporary_Config_File := False;
3237 -- Do not display the -F=mapping_file switch for
3238 -- gnatbind, if -dn is not specified.
3240 elsif Debug.Debug_Flag_N
3241 or else Args (J)'Length < 4
3243 Args (J) (Args (J)'First .. Args (J)'First + 2) /= "-F
="
3246 Write_Str (Args (J).all);
3256 ----------------------
3257 -- Display_Commands --
3258 ----------------------
3260 procedure Display_Commands (Display : Boolean := True) is
3262 Display_Executed_Programs := Display;
3263 end Display_Commands;
3269 function Empty_Q return Boolean is
3271 if Debug.Debug_Flag_P then
3272 Write_Str (" Q
:= [");
3274 for J in Q_Front .. Q.Last - 1 loop
3276 Write_Name (Q.Table (J).File);
3285 return Q_Front >= Q.Last;
3288 --------------------------
3289 -- Enter_Into_Obsoleted --
3290 --------------------------
3292 procedure Enter_Into_Obsoleted (F : Name_Id) is
3293 Name : constant String := Get_Name_String (F);
3294 First : Natural := Name'Last;
3298 while First > Name'First
3299 and then Name (First - 1) /= Directory_Separator
3300 and then Name (First - 1) /= '/'
3305 if First /= Name'First then
3307 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
3311 Debug_Msg ("New entry in Obsoleted table
:", F2);
3312 Obsoleted.Set (F2, True);
3313 end Enter_Into_Obsoleted;
3315 ---------------------
3316 -- Extract_Failure --
3317 ---------------------
3319 procedure Extract_Failure
3320 (File : out File_Name_Type;
3321 Unit : out Unit_Name_Type;
3322 Found : out Boolean)
3325 File := Bad_Compilation.Table (Bad_Compilation.Last).File;
3326 Unit := Bad_Compilation.Table (Bad_Compilation.Last).Unit;
3327 Found := Bad_Compilation.Table (Bad_Compilation.Last).Found;
3328 Bad_Compilation.Decrement_Last;
3329 end Extract_Failure;
3331 --------------------
3332 -- Extract_From_Q --
3333 --------------------
3335 procedure Extract_From_Q
3336 (Source_File : out File_Name_Type;
3337 Source_Unit : out Unit_Name_Type;
3338 Source_Index : out Int)
3340 File : constant File_Name_Type := Q.Table (Q_Front).File;
3341 Unit : constant Unit_Name_Type := Q.Table (Q_Front).Unit;
3342 Index : constant Int := Q.Table (Q_Front).Index;
3345 if Debug.Debug_Flag_Q then
3346 Write_Str (" Q
:= Q
- [ ");
3358 Q_Front := Q_Front + 1;
3359 Source_File := File;
3360 Source_Unit := Unit;
3361 Source_Index := Index;
3368 procedure Gnatmake is
3369 Main_Source_File : File_Name_Type;
3370 -- The source file containing the main compilation unit
3372 Compilation_Failures : Natural;
3374 Total_Compilation_Failures : Natural := 0;
3376 Is_Main_Unit : Boolean;
3377 -- Set to True by Compile_Sources if the Main_Source_File can be a
3380 Main_ALI_File : File_Name_Type;
3381 -- The ali file corresponding to Main_Source_File
3383 Executable : File_Name_Type := No_File;
3384 -- The file name of an executable
3386 Non_Std_Executable : Boolean := False;
3387 -- Non_Std_Executable is set to True when there is a possibility
3388 -- that the linker will not choose the correct executable file name.
3390 Current_Work_Dir : constant String_Access :=
3391 new String'(Get_Current_Dir);
3392 -- The current working directory, used to modify some relative path
3393 -- switches on the command line when a project file is used.
3395 Current_Main_Index : Int := 0;
3396 -- If not zero, the index of the current main unit in its source file
3398 There_Are_Stand_Alone_Libraries : Boolean := False;
3399 -- Set to True when there are Stand-Alone Libraries, so that gnatbind
3400 -- is invoked with the -F switch to force checking of elaboration flags.
3402 Mapping_Path : Name_Id := No_Name;
3403 -- The path name of the mapping file
3407 procedure Check_Mains;
3408 -- Check that the main subprograms do exist and that they all
3409 -- belong to the same project file.
3411 procedure Create_Binder_Mapping_File
3412 (Args : in out Argument_List; Last_Arg : in out Natural);
3413 -- Create a binder mapping file and add the necessary switch
3419 procedure Check_Mains is
3420 Real_Main_Project : Project_Id := No_Project;
3421 -- The project of the first main
3423 Proj : Project_Id := No_Project;
3424 -- The project of the current main
3426 Data : Project_Data;
3428 Real_Path : String_Access;
3437 Main : constant String := Mains.Next_Main;
3438 -- The name specified on the command line may include
3439 -- directory information.
3441 File_Name : constant String := Base_Name (Main);
3442 -- The simple file name of the current main main
3445 exit when Main = "";
3447 -- Get the project of the current main
3449 Proj := Prj.Env.Project_Of (File_Name, Main_Project);
3451 -- Fail if the current main is not a source of a
3454 if Proj = No_Project then
3457 """ is not a source
of any project
");
3460 -- If there is directory information, check that
3461 -- the source exists and, if it does, that the path
3462 -- is the actual path of a source of a project.
3464 if Main /= File_Name then
3465 Data := Projects.Table (Main_Project);
3471 (Data.Naming.Ada_Body_Suffix),
3473 if Real_Path = null then
3478 (Data.Naming.Ada_Spec_Suffix),
3482 if Real_Path = null then
3484 Locate_Regular_File (Main, "");
3487 -- Fail if the file cannot be found
3489 if Real_Path = null then
3491 ("file
""" & Main & """ does
not exist
");
3495 Project_Path : constant String :=
3496 Prj.Env.File_Name_Of_Library_Unit_Body
3498 Project => Main_Project,
3499 Main_Project_Only => False,
3501 Normed_Path : constant String :=
3504 Case_Sensitive => False);
3505 Proj_Path : constant String :=
3508 Case_Sensitive => False);
3513 -- Fail if it is not the correct path
3515 if Normed_Path /= Proj_Path then
3516 if Verbose_Mode then
3517 Write_Str (Normed_Path);
3519 Write_Line (Proj_Path);
3524 """ is not a source
of any project
");
3529 if not Unique_Compile then
3531 -- Record the project, if it is the first main
3533 if Real_Main_Project = No_Project then
3534 Real_Main_Project := Proj;
3536 elsif Proj /= Real_Main_Project then
3538 -- Fail, as the current main is not a source
3539 -- of the same project as the first main.
3543 """ is not a source
of project
" &
3546 (Real_Main_Project).Name));
3551 -- If -u and -U are not used, we may have mains that
3552 -- are sources of a project that is not the one
3553 -- specified with switch -P.
3555 if not Unique_Compile then
3556 Main_Project := Real_Main_Project;
3562 --------------------------------
3563 -- Create_Binder_Mapping_File --
3564 --------------------------------
3566 procedure Create_Binder_Mapping_File
3567 (Args : in out Argument_List; Last_Arg : in out Natural)
3569 Mapping_FD : File_Descriptor := Invalid_FD;
3570 -- A File Descriptor for an eventual mapping file
3572 ALI_Unit : Name_Id := No_Name;
3573 -- The unit name of an ALI file
3575 ALI_Name : Name_Id := No_Name;
3576 -- The file name of the ALI file
3578 ALI_Project : Project_Id := No_Project;
3579 -- The project of the ALI file
3582 OK : Boolean := True;
3585 -- For call to Close
3588 Tempdir.Create_Temp_File (Mapping_FD, Mapping_Path);
3590 if Mapping_FD /= Invalid_FD then
3592 -- Traverse all units
3594 for J in Prj.Com.Units.First .. Prj.Com.Units.Last loop
3596 Unit : constant Prj.Com.Unit_Data :=
3597 Prj.Com.Units.Table (J);
3601 if Unit.Name /= No_Name then
3603 -- If there is a body, put it in the mapping
3605 if Unit.File_Names (Body_Part).Name /= No_Name
3606 and then Unit.File_Names (Body_Part).Project
3609 Get_Name_String (Unit.Name);
3611 (Name_Len + 1 .. Name_Len + 2) := "%b
";
3612 Name_Len := Name_Len + 2;
3613 ALI_Unit := Name_Find;
3616 (Unit.File_Names (Body_Part).Name);
3618 Unit.File_Names (Body_Part).Project;
3620 -- Otherwise, if there is a spec, put it
3623 elsif Unit.File_Names (Specification).Name
3625 and then Unit.File_Names
3626 (Specification).Project
3629 Get_Name_String (Unit.Name);
3631 (Name_Len + 1 .. Name_Len + 2) := "%s
";
3632 Name_Len := Name_Len + 2;
3633 ALI_Unit := Name_Find;
3634 ALI_Name := Lib_File_Name
3635 (Unit.File_Names (Specification).Name);
3637 Unit.File_Names (Specification).Project;
3640 ALI_Name := No_Name;
3643 -- If we have something to put in the mapping
3644 -- then we do it now. However, if the project
3645 -- is extended, we don't put anything in the
3646 -- mapping file, because we do not know where
3647 -- the ALI file is: it might be in the ext-
3648 -- ended project obj dir as well as in the
3649 -- extending project obj dir.
3651 if ALI_Name /= No_Name
3653 Projects.Table (ALI_Project).Extended_By = No_Project
3655 Projects.Table (ALI_Project).Extends = No_Project
3657 -- First line is the unit name
3659 Get_Name_String (ALI_Unit);
3660 Name_Len := Name_Len + 1;
3661 Name_Buffer (Name_Len) := ASCII.LF;
3665 Name_Buffer (1)'Address,
3667 OK := Bytes = Name_Len;
3671 -- Second line it the ALI file name
3673 Get_Name_String (ALI_Name);
3674 Name_Len := Name_Len + 1;
3675 Name_Buffer (Name_Len) := ASCII.LF;
3679 Name_Buffer (1)'Address,
3681 OK := Bytes = Name_Len;
3685 -- Third line it the ALI path name,
3686 -- concatenation of the project
3687 -- directory with the ALI file name.
3690 ALI : constant String :=
3691 Get_Name_String (ALI_Name);
3694 (Projects.Table (ALI_Project).
3697 if Name_Buffer (Name_Len) /=
3700 Name_Len := Name_Len + 1;
3701 Name_Buffer (Name_Len) :=
3702 Directory_Separator;
3707 Name_Len + ALI'Length) := ALI;
3709 Name_Len + ALI'Length + 1;
3710 Name_Buffer (Name_Len) := ASCII.LF;
3714 Name_Buffer (1)'Address,
3716 OK := Bytes = Name_Len;
3719 -- If OK is False, it means we were unable
3720 -- to write a line. No point in continuing
3721 -- with the other units.
3729 Close (Mapping_FD, Status);
3731 OK := OK and Status;
3733 -- If the creation of the mapping file was successful,
3734 -- we add the switch to the arguments of gnatbind.
3737 Last_Arg := Last_Arg + 1;
3739 new String'("-F
=" & Get_Name_String (Mapping_Path));
3742 end Create_Binder_Mapping_File;
3744 -- Start of processing for Gnatmake
3746 -- This body is very long, should be broken down ???
3749 Gnatmake_Called := True;
3751 Install_Int_Handler (Sigint_Intercepted'Access);
3753 Do_Compile_Step := True;
3754 Do_Bind_Step := True;
3755 Do_Link_Step := True;
3761 Bind_Shared := No_Shared_Switch'Access;
3762 Link_With_Shared_Libgcc := No_Shared_Libgcc_Switch'Access;
3764 Failed_Links.Set_Last (0);
3765 Successful_Links.Set_Last (0);
3767 if Hostparm.Java_VM then
3768 Gcc := new String'("jgnat
");
3769 Gnatbind := new String'("jgnatbind
");
3770 Gnatlink := new String'("jgnatlink
");
3772 -- Do not check for an object file (".o
") when compiling to
3773 -- Java bytecode since ".class
" files are generated instead.
3775 Check_Object_Consistency := False;
3778 -- Special case when switch -B was specified
3780 if Build_Bind_And_Link_Full_Project then
3782 -- When switch -B is specified, there must be a project file
3784 if Main_Project = No_Project then
3785 Make_Failed ("-B cannot be used without a project file
");
3787 -- No main program may be specified on the command line
3789 elsif Osint.Number_Of_Files /= 0 then
3790 Make_Failed ("-B cannot be used
with a main specified on
" &
3791 "the command line
");
3793 -- And the project file cannot be a library project file
3795 elsif Projects.Table (Main_Project).Library then
3796 Make_Failed ("-B cannot be used
for a library project file
");
3799 Insert_Project_Sources
3800 (The_Project => Main_Project,
3801 All_Projects => Unique_Compile_All_Projects,
3804 -- If there are no sources to compile, we fail
3806 if Osint.Number_Of_Files = 0 then
3807 Make_Failed ("no sources to compile
");
3810 -- Specify -n for gnatbind and add the ALI files of all the
3811 -- sources, except the one which is a fake main subprogram:
3812 -- this is the one for the binder generated file and it will be
3813 -- transmitted to gnatlink. These sources are those that are
3816 Add_Switch ("-n
", Binder, And_Save => True);
3818 for J in Q.First .. Q.Last - 1 loop
3821 (Lib_File_Name (Q.Table (J).File)),
3822 Binder, And_Save => True);
3826 elsif Main_Index /= 0 and then Osint.Number_Of_Files > 1 then
3827 Make_Failed ("cannot specify several mains
with a multi
-unit index
");
3829 elsif Main_Project /= No_Project then
3831 -- If the main project file is a library project file, main(s)
3832 -- cannot be specified on the command line.
3834 if Osint.Number_Of_Files /= 0 then
3835 if Projects.Table (Main_Project).Library
3836 and then not Unique_Compile
3837 and then ((not Make_Steps) or else Bind_Only or else Link_Only)
3839 Make_Failed ("cannot specify a main program
" &
3840 "on the command line
for a library project file
");
3843 -- Check that each main on the command line is a source of a
3844 -- project file and, if there are several mains, each of them
3845 -- is a source of the same project file.
3850 -- If no mains have been specified on the command line,
3851 -- and we are using a project file, we either find the main(s)
3852 -- in the attribute Main of the main project, or we put all
3853 -- the sources of the project file as mains.
3856 if Main_Index /= 0 then
3857 Make_Failed ("cannot specify a multi
-unit index but no main
" &
3858 "on the command line
");
3862 Value : String_List_Id := Projects.Table (Main_Project).Mains;
3865 -- The attribute Main is an empty list or not specified,
3866 -- or else gnatmake was invoked with the switch "-u
".
3868 if Value = Prj.Nil_String or else Unique_Compile then
3870 if (not Make_Steps) or else Compile_Only
3871 or else not Projects.Table (Main_Project).Library
3873 -- First make sure that the binder and the linker
3874 -- will not be invoked.
3876 Do_Bind_Step := False;
3877 Do_Link_Step := False;
3879 -- Put all the sources in the queue
3881 Insert_Project_Sources
3882 (The_Project => Main_Project,
3883 All_Projects => Unique_Compile_All_Projects,
3886 -- If there are no sources to compile, we fail
3888 if Osint.Number_Of_Files = 0 then
3889 Make_Failed ("no sources to compile
");
3894 -- The attribute Main is not an empty list.
3895 -- Put all the main subprograms in the list as if there
3896 -- were specified on the command line. However, if attribute
3897 -- Languages includes a language other than Ada, only
3898 -- include the Ada mains; if there is no Ada main, compile
3899 -- all the sources of the project.
3902 Data : constant Project_Data :=
3903 Projects.Table (Main_Project);
3905 Languages : constant Variable_Value :=
3907 (Name_Languages, Data.Decl.Attributes);
3909 Current : String_List_Id;
3910 Element : String_Element;
3912 Foreign_Language : Boolean := False;
3913 At_Least_One_Main : Boolean := False;
3916 -- First, determine if there is a foreign language in
3917 -- attribute Languages.
3919 if not Languages.Default then
3920 Current := Languages.Values;
3923 while Current /= Nil_String loop
3924 Element := String_Elements.Table (Current);
3925 Get_Name_String (Element.Value);
3926 To_Lower (Name_Buffer (1 .. Name_Len));
3928 if Name_Buffer (1 .. Name_Len) /= "ada
" then
3929 Foreign_Language := True;
3930 exit Look_For_Foreign;
3933 Current := Element.Next;
3934 end loop Look_For_Foreign;
3937 -- Then, find all mains, or if there is a foreign
3938 -- language, all the Ada mains.
3940 while Value /= Prj.Nil_String loop
3941 Get_Name_String (String_Elements.Table (Value).Value);
3943 -- To know if a main is an Ada main, get its project.
3944 -- It should be the project specified on the command
3947 if (not Foreign_Language) or else
3949 (Name_Buffer (1 .. Name_Len), Main_Project) =
3952 At_Least_One_Main := True;
3955 (String_Elements.Table (Value).Value),
3956 Index => String_Elements.Table (Value).Index);
3959 Value := String_Elements.Table (Value).Next;
3962 -- If we did not get any main, it means that all mains
3963 -- in attribute Mains are in a foreign language and -B
3964 -- was not specified to gnatmake; so, we fail.
3966 if not At_Least_One_Main then
3968 ("no Ada mains
; use -B to build foreign main
");
3977 if Verbose_Mode then
3979 Write_Str ("GNATMAKE
");
3980 Write_Str (Gnatvsn.Gnat_Version_String);
3982 Write_Str ("Copyright
1995-2004 Free Software Foundation
, Inc
.");
3986 if Main_Project /= No_Project
3987 and then Projects.Table (Main_Project).Externally_Built
3990 ("nothing to
do for a main project that
is externally built
");
3993 if Osint.Number_Of_Files = 0 then
3994 if Main_Project /= No_Project
3995 and then Projects.Table (Main_Project).Library
3998 and then not Projects.Table (Main_Project).Standalone_Library
4000 Make_Failed ("only stand
-alone libraries may be bound
");
4003 -- Add the default search directories to be able to find libgnat
4005 Osint.Add_Default_Search_Dirs;
4007 -- And bind and or link the library
4009 MLib.Prj.Build_Library
4010 (For_Project => Main_Project,
4011 Gnatbind => Gnatbind.all,
4012 Gnatbind_Path => Gnatbind_Path,
4014 Gcc_Path => Gcc_Path,
4017 Exit_Program (E_Success);
4020 -- Output usage information if no files to compile
4023 Exit_Program (E_Fatal);
4027 -- If -M was specified, behave as if -n was specified
4029 if List_Dependencies then
4030 Do_Not_Execute := True;
4033 -- Note that Osint.Next_Main_Source will always return the (possibly
4034 -- abbreviated file) without any directory information.
4036 Main_Source_File := Next_Main_Source;
4038 if Current_File_Index /= No_Index then
4039 Main_Index := Current_File_Index;
4042 Add_Switch ("-I
-", Binder, And_Save => True);
4043 Add_Switch ("-I
-", Compiler, And_Save => True);
4045 if Main_Project = No_Project then
4046 if Look_In_Primary_Dir then
4050 Normalize_Directory_Name
4051 (Get_Primary_Src_Search_Directory.all).all,
4052 Compiler, Append_Switch => False,
4055 Add_Switch ("-aO
" & Normalized_CWD,
4057 Append_Switch => False,
4062 -- If we use a project file, we have already checked that a main
4063 -- specified on the command line with directory information has the
4064 -- path name corresponding to a correct source in the project tree.
4065 -- So, we don't need the directory information to be taken into
4066 -- account by Find_File, and in fact it may lead to take the wrong
4067 -- sources for other compilation units, when there are extending
4070 Look_In_Primary_Dir := False;
4073 -- If the user wants a program without a main subprogram, add the
4074 -- appropriate switch to the binder.
4076 if No_Main_Subprogram then
4077 Add_Switch ("-z
", Binder, And_Save => True);
4080 if Main_Project /= No_Project then
4082 if Projects.Table (Main_Project).Object_Directory /= No_Name then
4084 -- Change the current directory to the object directory of
4085 -- the main project.
4088 Project_Object_Directory := No_Project;
4089 Change_To_Object_Directory (Main_Project);
4092 when Directory_Error =>
4094 -- This should never happen. But, if it does, display the
4095 -- content of the parent directory of the obj dir.
4098 Parent : constant Dir_Name_Str :=
4102 (Main_Project).Object_Directory));
4105 Str : String (1 .. 200);
4109 Write_Str ("Contents
of directory
""");
4116 Read (Dir, Str, Last);
4119 Write_Line (Str (1 .. Last));
4126 Write_Line ("(unexpected
exception)");
4127 Write_Line (Exception_Information (X));
4129 if Is_Open (Dir) then
4135 ("unable to change working directory to
""",
4137 (Projects.Table (Main_Project).Object_Directory),
4142 -- Source file lookups should be cached for efficiency.
4143 -- Source files are not supposed to change.
4145 Osint.Source_File_Data (Cache => True);
4147 -- Find the file name of the (first) main unit
4150 Main_Source_File_Name : constant String :=
4151 Get_Name_String (Main_Source_File);
4152 Main_Unit_File_Name : constant String :=
4153 Prj.Env.File_Name_Of_Library_Unit_Body
4154 (Name => Main_Source_File_Name,
4155 Project => Main_Project,
4156 Main_Project_Only =>
4157 not Unique_Compile);
4159 The_Packages : constant Package_Id :=
4160 Projects.Table (Main_Project).Decl.Packages;
4162 Builder_Package : constant Prj.Package_Id :=
4164 (Name => Name_Builder,
4165 In_Packages => The_Packages);
4167 Binder_Package : constant Prj.Package_Id :=
4169 (Name => Name_Binder,
4170 In_Packages => The_Packages);
4172 Linker_Package : constant Prj.Package_Id :=
4174 (Name => Name_Linker,
4175 In_Packages => The_Packages);
4178 -- We fail if we cannot find the main source file
4180 if Main_Unit_File_Name = "" then
4181 Make_Failed ('"' & Main_Source_File_Name,
4182 """ is not a unit of project ",
4183 Project_File_Name.all & ".");
4185 -- Remove any directory information from the main
4186 -- source file name.
4189 Pos : Natural := Main_Unit_File_Name'Last;
4193 exit when Pos < Main_Unit_File_Name'First or else
4194 Main_Unit_File_Name (Pos) = Directory_Separator;
4198 Name_Len := Main_Unit_File_Name'Last - Pos;
4200 Name_Buffer (1 .. Name_Len) :=
4202 (Pos + 1 .. Main_Unit_File_Name'Last);
4204 Main_Source_File := Name_Find;
4206 -- We only output the main source file if there is only one
4208 if Verbose_Mode and then Osint.Number_Of_Files = 1 then
4209 Write_Str ("Main source file: """);
4210 Write_Str (Main_Unit_File_Name
4211 (Pos + 1 .. Main_Unit_File_Name'Last));
4217 -- If there is a package Builder in the main project file, add
4218 -- the switches from it.
4220 if Builder_Package /= No_Package then
4222 -- If there is only one main, we attempt to get the gnatmake
4223 -- switches for this main (if any). If there are no specific
4224 -- switch for this particular main, get the general gnatmake
4225 -- switches (if any).
4227 if Osint.Number_Of_Files = 1 then
4228 if Verbose_Mode then
4229 Write_Str ("Adding gnatmake switches for """);
4230 Write_Str (Main_Unit_File_Name);
4235 (File_Name => Main_Unit_File_Name,
4236 Index => Main_Index,
4237 The_Package => Builder_Package,
4241 -- If there are several mains, we always get the general
4242 -- gnatmake switches (if any).
4244 -- Warn the user, if necessary, so that he is not surprized
4245 -- that specific switches are not taken into account.
4248 Defaults : constant Variable_Value :=
4252 Attribute_Or_Array_Name => Name_Default_Switches,
4253 In_Package => Builder_Package);
4255 Switches : constant Array_Element_Id :=
4257 (Name => Name_Switches,
4259 Packages.Table (Builder_Package).Decl.Arrays);
4262 if Defaults /= Nil_Variable_Value then
4263 if (not Quiet_Output)
4264 and then Switches /= No_Array_Element
4267 ("Warning: using Builder'Default_Switches" &
4268 "(""Ada""), as there are several mains");
4271 -- As there is never a source with name " ", we are
4272 -- guaranteed to always get the general switches.
4277 The_Package => Builder_Package,
4280 elsif (not Quiet_Output)
4281 and then Switches /= No_Array_Element
4284 ("Warning: using no switches from package Builder," &
4285 " as there are several mains");
4291 Osint.Add_Default_Search_Dirs;
4293 -- Record the current last switch index for table Binder_Switches
4294 -- and Linker_Switches, so that these tables may be reset before
4295 -- for each main, before adding swiches from the project file
4296 -- and from the command line.
4298 Last_Binder_Switch := Binder_Switches.Last;
4299 Last_Linker_Switch := Linker_Switches.Last;
4303 -- Add binder switches from the project file for the first main
4305 if Do_Bind_Step and Binder_Package /= No_Package then
4306 if Verbose_Mode then
4307 Write_Str ("Adding binder switches for """);
4308 Write_Str (Main_Unit_File_Name);
4313 (File_Name => Main_Unit_File_Name,
4314 Index => Main_Index,
4315 The_Package => Binder_Package,
4319 -- Add linker switches from the project file for the first main
4321 if Do_Link_Step and Linker_Package /= No_Package then
4322 if Verbose_Mode then
4323 Write_Str ("Adding linker switches for""");
4324 Write_Str (Main_Unit_File_Name);
4329 (File_Name => Main_Unit_File_Name,
4330 Index => Main_Index,
4331 The_Package => Linker_Package,
4337 -- Get the target parameters, which are only needed for a couple of
4338 -- cases in gnatmake. Protect against an exception, such as the case
4339 -- of system.ads missing from the library, and fail gracefully.
4342 Targparm.Get_Target_Parameters;
4345 when Unrecoverable_Error =>
4346 Make_Failed ("*** make failed.");
4349 Display_Commands (not Quiet_Output);
4353 if Main_Project /= No_Project then
4355 -- For all library project, if the library file does not exist
4356 -- put all the project sources in the queue, and flag the project
4357 -- so that the library is generated.
4359 if not Unique_Compile
4360 and then MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None
4362 for Proj in Projects.First .. Projects.Last loop
4363 if Projects.Table (Proj).Library then
4364 Projects.Table (Proj).Need_To_Build_Lib :=
4365 (not MLib.Tgt.Library_Exists_For (Proj))
4366 and then (not Projects.Table (Proj).Externally_Built);
4368 if Projects.Table (Proj).Need_To_Build_Lib then
4370 -- If there is no object directory, then it will be
4371 -- impossible to build the library. So fail immediately.
4373 if Projects.Table (Proj).Object_Directory = No_Name then
4375 ("no object files to build library for project """,
4376 Get_Name_String (Projects.Table (Proj).Name),
4378 Projects.Table (Proj).Need_To_Build_Lib := False;
4381 if Verbose_Mode then
4383 ("Library file does not exist for project """);
4385 (Get_Name_String (Projects.Table (Proj).Name));
4389 Insert_Project_Sources
4390 (The_Project => Proj,
4391 All_Projects => False,
4399 -- If a relative path output file has been specified, we add
4400 -- the exec directory.
4402 for J in reverse 1 .. Saved_Linker_Switches.Last - 1 loop
4403 if Saved_Linker_Switches.Table (J).all = Output_Flag.all then
4405 Exec_File_Name : constant String :=
4406 Saved_Linker_Switches.Table (J + 1).all;
4409 if not Is_Absolute_Path (Exec_File_Name) then
4410 for Index in Exec_File_Name'Range loop
4411 if Exec_File_Name (Index) = Directory_Separator then
4412 Make_Failed ("relative executable (""",
4414 """) with directory part not " &
4415 "allowed when using project files");
4419 Get_Name_String (Projects.Table
4420 (Main_Project).Exec_Directory);
4422 if Name_Buffer (Name_Len) /= Directory_Separator then
4423 Name_Len := Name_Len + 1;
4424 Name_Buffer (Name_Len) := Directory_Separator;
4427 Name_Buffer (Name_Len + 1 ..
4428 Name_Len + Exec_File_Name'Length) :=
4430 Name_Len := Name_Len + Exec_File_Name'Length;
4431 Saved_Linker_Switches.Table (J + 1) :=
4432 new String'(Name_Buffer
(1 .. Name_Len
));
4440 -- If we are using a project file, for relative paths we add the
4441 -- current working directory for any relative path on the command
4442 -- line and the project directory, for any relative path in the
4446 Dir_Path
: constant String_Access
:=
4447 new String'(Get_Name_String
4448 (Projects.Table (Main_Project).Directory));
4450 for J in 1 .. Binder_Switches.Last loop
4451 Test_If_Relative_Path
4452 (Binder_Switches.Table (J),
4453 Parent => Dir_Path, Including_L_Switch => False);
4456 for J in 1 .. Saved_Binder_Switches.Last loop
4457 Test_If_Relative_Path
4458 (Saved_Binder_Switches.Table (J),
4459 Parent => Current_Work_Dir, Including_L_Switch => False);
4462 for J in 1 .. Linker_Switches.Last loop
4463 Test_If_Relative_Path
4464 (Linker_Switches.Table (J), Parent => Dir_Path);
4467 for J in 1 .. Saved_Linker_Switches.Last loop
4468 Test_If_Relative_Path
4469 (Saved_Linker_Switches.Table (J), Parent => Current_Work_Dir);
4472 for J in 1 .. Gcc_Switches.Last loop
4473 Test_If_Relative_Path
4474 (Gcc_Switches.Table (J), Parent => Dir_Path);
4477 for J in 1 .. Saved_Gcc_Switches.Last loop
4478 Test_If_Relative_Path
4479 (Saved_Gcc_Switches.Table (J), Parent => Current_Work_Dir);
4484 -- We now put in the Binder_Switches and Linker_Switches tables,
4485 -- the binder and linker switches of the command line that have been
4486 -- put in the Saved_ tables. If a project file was used, then the
4487 -- command line switches will follow the project file switches.
4489 for J in 1 .. Saved_Binder_Switches.Last loop
4491 (Saved_Binder_Switches.Table (J),
4496 for J in 1 .. Saved_Linker_Switches.Last loop
4498 (Saved_Linker_Switches.Table (J),
4503 -- If no project file is used, we just put the gcc switches
4504 -- from the command line in the Gcc_Switches table.
4506 if Main_Project = No_Project then
4507 for J in 1 .. Saved_Gcc_Switches.Last loop
4509 (Saved_Gcc_Switches.Table (J),
4515 -- And we put the command line gcc switches in the variable
4516 -- The_Saved_Gcc_Switches. They are going to be used later
4517 -- in procedure Compile_Sources.
4519 The_Saved_Gcc_Switches :=
4520 new Argument_List (1 .. Saved_Gcc_Switches.Last + 1);
4522 for J in 1 .. Saved_Gcc_Switches.Last loop
4523 The_Saved_Gcc_Switches (J) := Saved_Gcc_Switches.Table (J);
4526 -- We never use gnat.adc when a project file is used
4528 The_Saved_Gcc_Switches (The_Saved_Gcc_Switches'Last) :=
4533 -- If there was a --GCC, --GNATBIND or --GNATLINK switch on
4534 -- the command line, then we have to use it, even if there was
4535 -- another switch in the project file.
4537 if Saved_Gcc /= null then
4541 if Saved_Gnatbind /= null then
4542 Gnatbind := Saved_Gnatbind;
4545 if Saved_Gnatlink /= null then
4546 Gnatlink := Saved_Gnatlink;
4549 Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
4550 Gnatbind_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
4551 Gnatlink_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
4553 -- If we have specified -j switch both from the project file
4554 -- and on the command line, the one from the command line takes
4557 if Saved_Maximum_Processes = 0 then
4558 Saved_Maximum_Processes := Maximum_Processes;
4561 -- Allocate as many temporary mapping file names as the maximum
4562 -- number of compilation processed, for each possible project.
4564 The_Mapping_File_Names :=
4566 (No_Project .. Projects.Last, 1 .. Saved_Maximum_Processes);
4567 Last_Mapping_File_Names :=
4568 new Indices'(No_Project
.. Projects
.Last
=> 0);
4570 The_Free_Mapping_File_Indices
:=
4571 new Free_File_Indices
4572 (No_Project
.. Projects
.Last
, 1 .. Saved_Maximum_Processes
);
4573 Last_Free_Indices
:=
4574 new Indices
'(No_Project .. Projects.Last => 0);
4576 Bad_Compilation.Init;
4578 Current_Main_Index := Main_Index;
4580 -- Here is where the make process is started
4582 -- We do the same process for each main
4584 Multiple_Main_Loop : for N_File in 1 .. Osint.Number_Of_Files loop
4586 -- First, find the executable name and path
4588 Executable := No_File;
4589 Executable_Obsolete := False;
4590 Non_Std_Executable := False;
4592 -- Look inside the linker switches to see if the name
4593 -- of the final executable program was specified.
4596 J in reverse Linker_Switches.First .. Linker_Switches.Last
4598 if Linker_Switches.Table (J).all = Output_Flag.all then
4599 pragma Assert (J < Linker_Switches.Last);
4601 -- We cannot specify a single executable for several
4602 -- main subprograms!
4604 if Osint.Number_Of_Files > 1 then
4606 ("cannot specify a single executable " &
4607 "for several mains");
4610 Name_Len := Linker_Switches.Table (J + 1)'Length;
4611 Name_Buffer (1 .. Name_Len) :=
4612 Linker_Switches.Table (J + 1).all;
4613 Executable := Name_Enter;
4615 Verbose_Msg (Executable, "final executable");
4619 -- If the name of the final executable program was not
4620 -- specified then construct it from the main input file.
4622 if Executable = No_File then
4623 if Main_Project = No_Project then
4625 Executable_Name (Strip_Suffix (Main_Source_File));
4628 -- If we are using a project file, we attempt to
4629 -- remove the body (or spec) termination of the main
4630 -- subprogram. We find it the the naming scheme of the
4631 -- project file. This will avoid to generate an
4632 -- executable "main.2" for a main subprogram
4633 -- "main.2.ada", when the body termination is ".2.ada".
4635 Executable := Prj.Util.Executable_Of
4636 (Main_Project, Main_Source_File, Main_Index);
4640 if Main_Project /= No_Project then
4642 Exec_File_Name : constant String :=
4643 Get_Name_String (Executable);
4646 if not Is_Absolute_Path (Exec_File_Name) then
4647 for Index in Exec_File_Name'Range loop
4648 if Exec_File_Name (Index) = Directory_Separator then
4649 Make_Failed ("relative executable (""",
4651 """) with directory part not " &
4652 "allowed when using project files");
4656 Get_Name_String (Projects.Table
4657 (Main_Project).Exec_Directory);
4660 Name_Buffer (Name_Len) /= Directory_Separator
4662 Name_Len := Name_Len + 1;
4663 Name_Buffer (Name_Len) := Directory_Separator;
4666 Name_Buffer (Name_Len + 1 ..
4667 Name_Len + Exec_File_Name'Length) :=
4670 Name_Len := Name_Len + Exec_File_Name'Length;
4671 Executable := Name_Find;
4672 Non_Std_Executable := True;
4677 if Do_Compile_Step then
4678 Recursive_Compilation_Step : declare
4679 Args : Argument_List (1 .. Gcc_Switches.Last);
4681 First_Compiled_File : Name_Id;
4682 Youngest_Obj_File : Name_Id;
4683 Youngest_Obj_Stamp : Time_Stamp_Type;
4685 Executable_Stamp : Time_Stamp_Type;
4686 -- Executable is the final executable program
4688 Library_Rebuilt : Boolean := False;
4691 for J in 1 .. Gcc_Switches.Last loop
4692 Args (J) := Gcc_Switches.Table (J);
4695 -- Now we invoke Compile_Sources for the current main
4698 (Main_Source => Main_Source_File,
4700 First_Compiled_File => First_Compiled_File,
4701 Most_Recent_Obj_File => Youngest_Obj_File,
4702 Most_Recent_Obj_Stamp => Youngest_Obj_Stamp,
4703 Main_Unit => Is_Main_Unit,
4704 Main_Index => Current_Main_Index,
4705 Compilation_Failures => Compilation_Failures,
4706 Check_Readonly_Files => Check_Readonly_Files,
4707 Do_Not_Execute => Do_Not_Execute,
4708 Force_Compilations => Force_Compilations,
4709 In_Place_Mode => In_Place_Mode,
4710 Keep_Going => Keep_Going,
4711 Initialize_ALI_Data => True,
4712 Max_Process => Saved_Maximum_Processes);
4714 if Verbose_Mode then
4715 Write_Str ("End of compilation");
4719 -- Make sure the queue will be reinitialized for the next round
4721 First_Q_Initialization := True;
4723 Total_Compilation_Failures :=
4724 Total_Compilation_Failures + Compilation_Failures;
4726 if Total_Compilation_Failures /= 0 then
4730 List_Bad_Compilations;
4731 raise Compilation_Failed;
4735 -- Regenerate libraries, if any, and if object files
4736 -- have been regenerated.
4738 if Main_Project /= No_Project
4739 and then MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None
4740 and then (Do_Bind_Step or Unique_Compile_All_Projects
4741 or not Compile_Only)
4742 and then (Do_Link_Step or N_File = Osint.Number_Of_Files)
4752 -- Put in Library_Projs table all library project
4753 -- file ids when the library need to be rebuilt.
4755 for Proj1 in Projects.First .. Projects.Last loop
4757 if Projects.Table (Proj1).Standalone_Library then
4758 There_Are_Stand_Alone_Libraries := True;
4761 if Projects.Table (Proj1).Library
4762 and then not Projects.Table (Proj1).Need_To_Build_Lib
4763 and then not Projects.Table (Proj1).Externally_Built
4765 MLib.Prj.Check_Library (Proj1);
4768 if Projects.Table (Proj1).Need_To_Build_Lib then
4769 Library_Projs.Increment_Last;
4770 Current := Library_Projs.Last;
4771 Depth := Projects.Table (Proj1).Depth;
4773 -- Put the projects in decreasing depth order,
4774 -- so that if libA depends on libB, libB is first
4777 while Current > 1 loop
4778 Proj2 := Library_Projs.Table (Current - 1);
4779 exit when Projects.Table (Proj2).Depth >= Depth;
4780 Library_Projs.Table (Current) := Proj2;
4781 Current := Current - 1;
4784 Library_Projs.Table (Current) := Proj1;
4785 Projects.Table (Proj1).Need_To_Build_Lib := False;
4790 -- Build the libraries, if any need to be built
4792 for J in 1 .. Library_Projs.Last loop
4793 Library_Rebuilt := True;
4794 MLib.Prj.Build_Library
4795 (For_Project => Library_Projs.Table (J),
4796 Gnatbind => Gnatbind.all,
4797 Gnatbind_Path => Gnatbind_Path,
4799 Gcc_Path => Gcc_Path);
4803 if List_Dependencies then
4804 if First_Compiled_File /= No_File then
4806 (First_Compiled_File,
4807 "must be recompiled. Can't generate dependence list.");
4812 elsif First_Compiled_File = No_File
4813 and then not Do_Bind_Step
4814 and then not Quiet_Output
4815 and then not Library_Rebuilt
4816 and then Osint.Number_Of_Files = 1
4818 Inform (Msg => "objects up to date.");
4820 elsif Do_Not_Execute
4821 and then First_Compiled_File /= No_File
4823 Write_Name (First_Compiled_File);
4827 -- Stop after compile step if any of:
4829 -- 1) -n (Do_Not_Execute) specified
4831 -- 2) -M (List_Dependencies) specified (also sets
4832 -- Do_Not_Execute above, so this is probably superfluous).
4834 -- 3) -c (Compile_Only) specified, but not -b (Bind_Only)
4836 -- 4) Made unit cannot be a main unit
4839 or List_Dependencies
4841 or not Is_Main_Unit)
4842 and then not No_Main_Subprogram
4843 and then not Build_Bind_And_Link_Full_Project
4845 if Osint.Number_Of_Files = 1 then
4846 exit Multiple_Main_Loop;
4853 -- If the objects were up-to-date check if the executable file
4854 -- is also up-to-date. For now always bind and link on the JVM
4855 -- since there is currently no simple way to check the
4856 -- up-to-date status of objects
4858 if not Hostparm.Java_VM
4859 and then First_Compiled_File = No_File
4861 Executable_Stamp := File_Stamp (Executable);
4863 if not Executable_Obsolete then
4864 Executable_Obsolete :=
4865 Youngest_Obj_Stamp > Executable_Stamp;
4868 if not Executable_Obsolete then
4869 for Index in reverse 1 .. Dependencies.Last loop
4871 (Dependencies.Table (Index).Depends_On)
4873 Enter_Into_Obsoleted
4874 (Dependencies.Table (Index).This);
4878 Executable_Obsolete := Is_In_Obsoleted (Main_Source_File);
4882 if not Executable_Obsolete then
4884 -- If no Ada object files obsolete the executable, check
4885 -- for younger or missing linker files.
4887 Check_Linker_Options
4890 Youngest_Obj_Stamp);
4892 Executable_Obsolete := Youngest_Obj_File /= No_File;
4895 -- Return if the executable is up to date
4896 -- and otherwise motivate the relink/rebind.
4898 if not Executable_Obsolete then
4899 if not Quiet_Output then
4900 Inform (Executable, "up to date.");
4903 if Osint.Number_Of_Files = 1 then
4904 exit Multiple_Main_Loop;
4911 if Executable_Stamp (1) = ' ' then
4912 Verbose_Msg (Executable, "missing.", Prefix => " ");
4914 elsif Youngest_Obj_Stamp (1) = ' ' then
4920 elsif Youngest_Obj_Stamp > Executable_Stamp then
4923 "(" & String (Youngest_Obj_Stamp) & ") newer than",
4925 "(" & String (Executable_Stamp) & ")");
4929 (Executable, "needs to be rebuild.",
4934 end Recursive_Compilation_Step;
4937 -- For binding and linking, we need to be in the object directory of
4938 -- the main project.
4940 if Main_Project /= No_Project then
4941 Change_To_Object_Directory (Main_Project);
4944 -- If we are here, it means that we need to rebuilt the current
4945 -- main. So we set Executable_Obsolete to True to make sure that
4946 -- the subsequent mains will be rebuilt.
4948 Main_ALI_In_Place_Mode_Step : declare
4949 ALI_File : File_Name_Type;
4950 Src_File : File_Name_Type;
4953 Src_File := Strip_Directory (Main_Source_File);
4954 ALI_File := Lib_File_Name (Src_File, Current_Main_Index);
4955 Main_ALI_File := Full_Lib_File_Name (ALI_File);
4957 -- When In_Place_Mode, the library file can be located in the
4958 -- Main_Source_File directory which may not be present in the
4959 -- library path. In this case, use the corresponding library file
4962 if Main_ALI_File = No_File and then In_Place_Mode then
4963 Get_Name_String (Get_Directory (Full_Source_Name (Src_File)));
4964 Get_Name_String_And_Append (ALI_File);
4965 Main_ALI_File := Name_Find;
4966 Main_ALI_File := Full_Lib_File_Name (Main_ALI_File);
4969 if Main_ALI_File = No_File then
4970 Make_Failed ("could not find the main ALI file");
4972 end Main_ALI_In_Place_Mode_Step;
4974 if Do_Bind_Step then
4976 Args : Argument_List
4977 (Binder_Switches.First .. Binder_Switches.Last + 2);
4978 -- The arguments for the invocation of gnatbind
4980 Last_Arg : Natural := Binder_Switches.Last;
4981 -- Index of the last argument in Args
4983 Shared_Libs : Boolean := False;
4984 -- Set to True when there are shared library project files or
4985 -- when gnatbind is invoked with -shared.
4988 -- Check if there are shared libraries, so that gnatbind is
4989 -- called with -shared. Check also if gnatbind is called with
4990 -- -shared, so that gnatlink is called with -shared-libgcc
4991 -- for GCC version 3 and above, ensuring that the shared
4992 -- version of libgcc will be used.
4994 if Main_Project /= No_Project
4995 and then MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None
4997 for Proj in Projects.First .. Projects.Last loop
4998 if Projects.Table (Proj).Library and then
4999 Projects.Table (Proj).Library_Kind /= Static
5001 Shared_Libs := True;
5002 Bind_Shared := Shared_Switch'Access;
5008 -- Check now for switch -shared
5010 if not Shared_Libs then
5011 for J in Binder_Switches.First .. Last_Arg loop
5012 if Binder_Switches.Table (J).all = "-shared" then
5013 Shared_Libs := True;
5019 -- If there are shared libraries, invoke gnatlink with
5020 -- -shared-libgcc if GCC version is 3 or more.
5022 if Shared_Libs and then GCC_Version >= 3 then
5023 Link_With_Shared_Libgcc := Shared_Libgcc_Switch'Access;
5026 -- Get all the binder switches
5028 for J in Binder_Switches.First .. Last_Arg loop
5029 Args (J) := Binder_Switches.Table (J);
5032 if There_Are_Stand_Alone_Libraries then
5033 Last_Arg := Last_Arg + 1;
5034 Args (Last_Arg) := Force_Elab_Flags_String'Access;
5037 if Main_Project /= No_Project then
5039 -- Put all the source directories in ADA_INCLUDE_PATH,
5040 -- and all the object directories in ADA_OBJECTS_PATH
5042 Prj.Env.Set_Ada_Paths (Main_Project, False);
5044 -- If switch -C was specified, create a binder mapping file
5046 if Create_Mapping_File then
5047 Create_Binder_Mapping_File (Args, Last_Arg);
5053 Bind (Main_ALI_File,
5054 Bind_Shared.all & Args (Args'First .. Last_Arg));
5059 -- If -dn was not specified, delete the temporary mapping
5060 -- file, if one was created.
5062 if not Debug.Debug_Flag_N
5063 and then Mapping_Path /= No_Name
5065 Delete_File (Get_Name_String (Mapping_Path), Discard);
5068 -- And reraise the exception
5073 -- If -dn was not specified, delete the temporary mapping file,
5074 -- if one was created.
5076 if not Debug.Debug_Flag_N and then Mapping_Path /= No_Name then
5077 Delete_File (Get_Name_String (Mapping_Path), Discard);
5082 if Do_Link_Step then
5084 There_Are_Libraries : Boolean := False;
5085 Linker_Switches_Last : constant Integer := Linker_Switches.Last;
5086 Path_Option : constant String_Access :=
5087 MLib.Linker_Library_Path_Option;
5093 if not Run_Path_Option then
5094 Linker_Switches.Increment_Last;
5095 Linker_Switches.Table (Linker_Switches.Last) :=
5099 if Main_Project
/= No_Project
then
5100 Library_Paths
.Set_Last
(0);
5103 if MLib
.Tgt
.Support_For_Libraries
/= MLib
.Tgt
.None
then
5104 -- Check for library projects
5106 for Proj1
in 1 .. Projects
.Last
loop
5107 if Proj1
/= Main_Project
5108 and then Projects
.Table
(Proj1
).Library
5110 -- Add this project to table Library_Projs
5112 There_Are_Libraries
:= True;
5113 Depth
:= Projects
.Table
(Proj1
).Depth
;
5114 Library_Projs
.Increment_Last
;
5115 Current
:= Library_Projs
.Last
;
5117 -- Any project with a greater depth should be
5118 -- after this project in the list.
5120 while Current
> 1 loop
5121 Proj2
:= Library_Projs
.Table
(Current
- 1);
5122 exit when Projects
.Table
(Proj2
).Depth
<= Depth
;
5123 Library_Projs
.Table
(Current
) := Proj2
;
5124 Current
:= Current
- 1;
5127 Library_Projs
.Table
(Current
) := Proj1
;
5129 -- If it is not a static library and path option
5130 -- is set, add it to the Library_Paths table.
5132 if Projects
.Table
(Proj1
).Library_Kind
/= Static
5133 and then Path_Option
/= null
5135 Library_Paths
.Increment_Last
;
5136 Library_Paths
.Table
(Library_Paths
.Last
) :=
5139 (Projects.Table (Proj1).Library_Dir));
5144 for Index in 1 .. Library_Projs.Last loop
5145 -- Add the -L switch
5147 Linker_Switches.Increment_Last;
5148 Linker_Switches.Table (Linker_Switches.Last) :=
5152 (Library_Projs
.Table
(Index
)).
5155 -- Add the -l switch
5157 Linker_Switches
.Increment_Last
;
5158 Linker_Switches
.Table
(Linker_Switches
.Last
) :=
5162 (Library_Projs.Table (Index)).
5167 if There_Are_Libraries then
5169 -- If Path_Option is not null, create the switch
5170 -- ("-Wl,-rpath," or equivalent) with all the non static
5171 -- library dirs plus the standard GNAT library dir.
5172 -- We do that only if Run_Path_Option is True
5173 -- (not disabled by -R switch).
5175 if Run_Path_Option and Path_Option /= null then
5177 Option : String_Access;
5178 Length : Natural := Path_Option'Length;
5183 Library_Paths.First .. Library_Paths.Last
5185 -- Add the length of the library dir plus one
5186 -- for the directory separator.
5190 Library_Paths.Table (Index)'Length + 1;
5193 -- Finally, add the length of the standard GNAT
5196 Length := Length + MLib.Utl.Lib_Directory'Length;
5197 Option := new String (1 .. Length);
5198 Option (1 .. Path_Option'Length) := Path_Option.all;
5199 Current := Path_Option'Length;
5201 -- Put each library dir followed by a dir separator
5204 Library_Paths.First .. Library_Paths.Last
5209 Library_Paths.Table (Index)'Length) :=
5210 Library_Paths.Table (Index).all;
5213 Library_Paths.Table (Index)'Length + 1;
5214 Option (Current) := Path_Separator;
5217 -- Finally put the standard GNAT library dir
5221 Current + MLib.Utl.Lib_Directory'Length) :=
5222 MLib.Utl.Lib_Directory;
5224 -- And add the switch to the linker switches
5226 Linker_Switches.Increment_Last;
5227 Linker_Switches.Table (Linker_Switches.Last) :=
5234 -- Put the object directories in ADA_OBJECTS_PATH
5236 Prj.Env.Set_Ada_Paths (Main_Project, False);
5238 -- Check for attributes Linker'Linker_Options in projects
5239 -- other than the main project
5242 Linker_Options : constant String_List :=
5243 Linker_Options_Switches (Main_Project);
5246 for Option in Linker_Options'Range loop
5247 Linker_Switches.Increment_Last;
5248 Linker_Switches.Table (Linker_Switches.Last) :=
5249 Linker_Options (Option);
5255 Args : Argument_List
5256 (Linker_Switches.First .. Linker_Switches.Last + 2);
5258 Last_Arg : Integer := Linker_Switches.First - 1;
5259 Skip : Boolean := False;
5262 -- Get all the linker switches
5264 for J in Linker_Switches.First .. Linker_Switches.Last loop
5268 elsif Non_Std_Executable
5269 and then Linker_Switches.Table (J).all = "-o"
5274 Last_Arg := Last_Arg + 1;
5275 Args (Last_Arg) := Linker_Switches.Table (J);
5279 -- If need be, add the -o switch
5281 if Non_Std_Executable then
5282 Last_Arg := Last_Arg + 1;
5283 Args (Last_Arg) := new String'("-o");
5284 Last_Arg
:= Last_Arg
+ 1;
5286 new String'(Get_Name_String (Executable));
5289 -- And invoke the linker
5292 Link (Main_ALI_File,
5293 Link_With_Shared_Libgcc.all &
5294 Args (Args'First .. Last_Arg));
5295 Successful_Links.Increment_Last;
5296 Successful_Links.Table (Successful_Links.Last) :=
5301 if Osint.Number_Of_Files = 1 or not Keep_Going then
5305 Write_Line ("*** link failed");
5306 Failed_Links.Increment_Last;
5307 Failed_Links.Table (Failed_Links.Last) :=
5313 Linker_Switches.Set_Last (Linker_Switches_Last);
5317 -- We go to here when we skip the bind and link steps
5321 -- We go to the next main, if we did not process the last one
5323 if N_File < Osint.Number_Of_Files then
5324 Main_Source_File := Next_Main_Source;
5326 if Current_File_Index /= No_Index then
5327 Main_Index := Current_File_Index;
5330 if Main_Project /= No_Project then
5332 -- Find the file name of the main unit
5335 Main_Source_File_Name : constant String :=
5336 Get_Name_String (Main_Source_File);
5338 Main_Unit_File_Name : constant String :=
5340 File_Name_Of_Library_Unit_Body
5341 (Name => Main_Source_File_Name,
5342 Project => Main_Project,
5343 Main_Project_Only =>
5344 not Unique_Compile);
5346 The_Packages : constant Package_Id :=
5347 Projects.Table (Main_Project).Decl.Packages;
5349 Binder_Package : constant Prj.Package_Id :=
5351 (Name => Name_Binder,
5352 In_Packages => The_Packages);
5354 Linker_Package : constant Prj.Package_Id :=
5356 (Name => Name_Linker,
5357 In_Packages => The_Packages);
5360 -- We fail if we cannot find the main source file
5361 -- as an immediate source of the main project file.
5363 if Main_Unit_File_Name = "" then
5364 Make_Failed ('"' & Main_Source_File_Name,
5365 """ is not a unit
of project
",
5366 Project_File_Name.all & ".");
5369 -- Remove any directory information from the main
5370 -- source file name.
5373 Pos : Natural := Main_Unit_File_Name'Last;
5377 exit when Pos < Main_Unit_File_Name'First
5379 Main_Unit_File_Name (Pos) = Directory_Separator;
5383 Name_Len := Main_Unit_File_Name'Last - Pos;
5385 Name_Buffer (1 .. Name_Len) :=
5387 (Pos + 1 .. Main_Unit_File_Name'Last);
5389 Main_Source_File := Name_Find;
5393 -- We now deal with the binder and linker switches.
5394 -- If no project file is used, there is nothing to do
5395 -- because the binder and linker switches are the same
5398 -- Reset the tables Binder_Switches and Linker_Switches
5400 Binder_Switches.Set_Last (Last_Binder_Switch);
5401 Linker_Switches.Set_Last (Last_Linker_Switch);
5403 -- Add binder switches from the project file for this main,
5406 if Do_Bind_Step and Binder_Package /= No_Package then
5407 if Verbose_Mode then
5408 Write_Str ("Adding binder switches
for """);
5409 Write_Str (Main_Unit_File_Name);
5414 (File_Name => Main_Unit_File_Name,
5415 Index => Main_Index,
5416 The_Package => Binder_Package,
5420 -- Add linker switches from the project file for this main,
5423 if Do_Link_Step and Linker_Package /= No_Package then
5424 if Verbose_Mode then
5425 Write_Str ("Adding linker switches
for""");
5426 Write_Str (Main_Unit_File_Name);
5431 (File_Name => Main_Unit_File_Name,
5432 Index => Main_Index,
5433 The_Package => Linker_Package,
5437 -- As we are using a project file, for relative paths we add
5438 -- the current working directory for any relative path on
5439 -- the command line and the project directory, for any
5440 -- relative path in the project file.
5443 Dir_Path : constant String_Access :=
5444 new String'(Get_Name_String
5445 (Projects.Table (Main_Project).Directory));
5448 J in Last_Binder_Switch + 1 .. Binder_Switches.Last
5450 Test_If_Relative_Path
5451 (Binder_Switches.Table (J),
5452 Parent => Dir_Path, Including_L_Switch => False);
5456 J in Last_Linker_Switch + 1 .. Linker_Switches.Last
5458 Test_If_Relative_Path
5459 (Linker_Switches.Table (J), Parent => Dir_Path);
5463 -- We now put in the Binder_Switches and Linker_Switches
5464 -- tables, the binder and linker switches of the command
5465 -- line that have been put in the Saved_ tables.
5466 -- These switches will follow the project file switches.
5468 for J in 1 .. Saved_Binder_Switches.Last loop
5470 (Saved_Binder_Switches.Table (J),
5475 for J in 1 .. Saved_Linker_Switches.Last loop
5477 (Saved_Linker_Switches.Table (J),
5485 -- Remove all marks to be sure to check sources for all executables,
5486 -- as the switches may be different and -s may be in use.
5489 end loop Multiple_Main_Loop;
5491 if Failed_Links.Last > 0 then
5492 for Index in 1 .. Successful_Links.Last loop
5493 Write_Str ("Linking
of """);
5494 Write_Str (Get_Name_String (Successful_Links.Table (Index)));
5495 Write_Line (""" succeeded
.");
5498 for Index in 1 .. Failed_Links.Last loop
5499 Write_Str ("Linking
of """);
5500 Write_Str (Get_Name_String (Failed_Links.Table (Index)));
5501 Write_Line (""" failed
.");
5504 if Total_Compilation_Failures = 0 then
5505 raise Compilation_Failed;
5509 if Total_Compilation_Failures /= 0 then
5510 List_Bad_Compilations;
5511 raise Compilation_Failed;
5514 -- Delete the temporary mapping file that was created if we are
5515 -- using project files.
5517 if not Debug.Debug_Flag_N then
5518 Delete_Mapping_Files;
5519 Prj.Env.Delete_All_Path_Files;
5522 Exit_Program (E_Success);
5526 Make_Failed ("*** bind failed
.");
5528 when Compilation_Failed =>
5529 if not Debug.Debug_Flag_N then
5530 Delete_Mapping_Files;
5531 Prj.Env.Delete_All_Path_Files;
5534 Exit_Program (E_Fatal);
5537 Make_Failed ("*** link failed
.");
5540 Write_Line (Exception_Information (X));
5541 Make_Failed ("INTERNAL ERROR
. Please report
.");
5548 function Hash (F : Name_Id) return Header_Num is
5550 return Header_Num (1 + F mod Max_Header);
5553 --------------------
5554 -- In_Ada_Lib_Dir --
5555 --------------------
5557 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean is
5558 D : constant Name_Id := Get_Directory (File);
5559 B : constant Byte := Get_Name_Table_Byte (D);
5561 return (B and Ada_Lib_Dir) /= 0;
5568 procedure Inform (N : Name_Id := No_Name; Msg : String) is
5570 Osint.Write_Program_Name;
5574 if N /= No_Name then
5584 -----------------------
5585 -- Init_Mapping_File --
5586 -----------------------
5588 procedure Init_Mapping_File
5589 (Project : Project_Id;
5590 File_Index : in out Natural)
5592 FD : File_Descriptor;
5595 -- For call to Close
5598 -- Increase the index of the last mapping file for this project
5600 Last_Mapping_File_Names (Project) :=
5601 Last_Mapping_File_Names (Project) + 1;
5603 -- If there is a project file, call Create_Mapping_File with
5606 if Project /= No_Project then
5607 Prj.Env.Create_Mapping_File
5609 The_Mapping_File_Names
5610 (Project, Last_Mapping_File_Names (Project)));
5612 -- Otherwise, just create an empty file
5615 Tempdir.Create_Temp_File
5617 The_Mapping_File_Names
5618 (No_Project, Last_Mapping_File_Names (No_Project)));
5619 if FD = Invalid_FD then
5620 Make_Failed ("disk full
");
5626 Make_Failed ("disk full
");
5630 -- And return the index of the newly created file
5632 File_Index := Last_Mapping_File_Names (Project);
5633 end Init_Mapping_File;
5641 First_Q_Initialization := False;
5643 Q.Set_Last (Q.First);
5650 procedure Initialize is
5652 -- Override default initialization of Check_Object_Consistency
5653 -- since this is normally False for GNATBIND, but is True for
5654 -- GNATMAKE since we do not need to check source consistency
5655 -- again once GNATMAKE has looked at the sources to check.
5657 Check_Object_Consistency := True;
5659 -- Package initializations. The order of calls is important here
5661 Output.Set_Standard_Error;
5664 Binder_Switches.Init;
5665 Linker_Switches.Init;
5676 RTS_Specified := null;
5680 -- Add the directory where gnatmake is invoked in front of the
5681 -- path, if gnatmake is invoked with directory information.
5682 -- Only do this if the platform is not VMS, where the notion of path
5683 -- does not really exist.
5687 Command : constant String := Command_Name;
5690 for Index in reverse Command'Range loop
5691 if Command (Index) = Directory_Separator then
5693 Absolute_Dir : constant String :=
5695 (Command (Command'First .. Index));
5697 PATH : constant String :=
5700 Getenv ("PATH
").all;
5703 Setenv ("PATH
", PATH);
5712 -- Scan the switches and arguments
5714 Scan_Args : for Next_Arg in 1 .. Argument_Count loop
5715 Scan_Make_Arg (Argument (Next_Arg), And_Save => True);
5718 if Usage_Requested then
5722 -- Test for trailing -P switch
5724 if Project_File_Name_Present and then Project_File_Name = null then
5725 Make_Failed ("project file name missing after
-P
");
5727 -- Test for trailing -o switch
5729 elsif Output_File_Name_Present
5730 and then not Output_File_Name_Seen
5732 Make_Failed ("output file name missing after
-o
");
5734 -- Test for trailing -D switch
5736 elsif Object_Directory_Present
5737 and then not Object_Directory_Seen then
5738 Make_Failed ("object directory missing after
-D
");
5741 -- Test for simultaneity of -i and -D
5743 if Object_Directory_Path /= null and then In_Place_Mode then
5744 Make_Failed ("-i
and -D cannot be used simutaneously
");
5747 -- Deal with -C= switch
5749 if Gnatmake_Mapping_File /= null then
5750 -- First, check compatibility with other switches
5752 if Project_File_Name /= null then
5753 Make_Failed ("-C
= switch
is not compatible
with -P switch
");
5755 elsif Saved_Maximum_Processes > 1 then
5756 Make_Failed ("-C
= switch
is not compatible
with -jnnn switch
");
5759 Fmap.Initialize (Gnatmake_Mapping_File.all);
5761 ("-gnatem
=" & Gnatmake_Mapping_File.all,
5766 if Project_File_Name /= null then
5768 -- A project file was specified by a -P switch
5770 if Verbose_Mode then
5772 Write_Str ("Parsing Project File
""");
5773 Write_Str (Project_File_Name.all);
5778 -- Avoid looking in the current directory for ALI files
5780 -- Look_In_Primary_Dir := False;
5782 -- Set the project parsing verbosity to whatever was specified
5783 -- by a possible -vP switch.
5785 Prj.Pars.Set_Verbosity (To => Current_Verbosity);
5787 -- Parse the project file.
5788 -- If there is an error, Main_Project will still be No_Project.
5791 (Project => Main_Project,
5792 Project_File_Name => Project_File_Name.all,
5793 Packages_To_Check => Packages_To_Check_By_Gnatmake);
5795 if Main_Project = No_Project then
5796 Make_Failed ("""", Project_File_Name.all, """ processing failed
");
5799 if Verbose_Mode then
5801 Write_Str ("Parsing
of Project File
""");
5802 Write_Str (Project_File_Name.all);
5803 Write_Str (""" is finished
.");
5807 -- We add the source directories and the object directories
5808 -- to the search paths.
5810 Add_Source_Directories (Main_Project);
5811 Add_Object_Directories (Main_Project);
5813 -- Compute depth of each project
5815 for Proj in 1 .. Projects.Last loop
5816 Projects.Table (Proj).Seen := False;
5817 Projects.Table (Proj).Depth := 0;
5820 Recursive_Compute_Depth
5821 (Main_Project, Depth => 1);
5825 Osint.Add_Default_Search_Dirs;
5827 -- Source file lookups should be cached for efficiency.
5828 -- Source files are not supposed to change. However, we do that now
5829 -- only if no project file is used; if a project file is used, we
5830 -- do it just after changing the directory to the object directory.
5832 Osint.Source_File_Data (Cache => True);
5834 -- Read gnat.adc file to initialize Fname.UF
5836 Fname.UF.Initialize;
5839 Fname.SF.Read_Source_File_Name_Pragmas;
5842 when Err : SFN_Scan.Syntax_Error_In_GNAT_ADC =>
5843 Make_Failed (Exception_Message (Err));
5847 -- Make sure no project object directory is recorded
5849 Project_Object_Directory := No_Project;
5853 ----------------------------
5854 -- Insert_Project_Sources --
5855 ----------------------------
5857 procedure Insert_Project_Sources
5858 (The_Project : Project_Id;
5859 All_Projects : Boolean;
5862 Put_In_Q : Boolean := Into_Q;
5863 Unit : Com.Unit_Data;
5866 Extending : constant Boolean :=
5867 Projects.Table (The_Project).Extends /= No_Project;
5869 function Check_Project (P : Project_Id) return Boolean;
5870 -- Returns True if P is The_Project or a project extended by
5877 function Check_Project (P : Project_Id) return Boolean is
5879 if All_Projects or P = The_Project then
5881 elsif Extending then
5883 Data : Project_Data := Projects.Table (The_Project);
5887 if P = Data.Extends then
5891 Data := Projects.Table (Data.Extends);
5892 exit when Data.Extends = No_Project;
5900 -- Start of processing of Insert_Project_Sources
5903 -- For all the sources in the project files,
5905 for Id in Com.Units.First .. Com.Units.Last loop
5906 Unit := Com.Units.Table (Id);
5909 -- If there is a source for the body, and the body has not been
5912 if Unit.File_Names (Com.Body_Part).Name /= No_Name
5913 and then Unit.File_Names (Com.Body_Part).Path /= Slash
5916 -- And it is a source for the specified project
5918 if Check_Project (Unit.File_Names (Com.Body_Part).Project) then
5920 -- If we don't have a spec, we cannot consider the source
5921 -- if it is a subunit
5923 if Unit.File_Names (Com.Specification).Name = No_Name then
5925 Src_Ind : Source_File_Index;
5927 -- Here we are cheating a little bit: we don't want to
5928 -- use Sinput.L, because it depends on the GNAT tree
5929 -- (Atree, Sinfo, ...). So, we pretend that it is
5930 -- a project file, and we use Sinput.P.
5931 -- Source_File_Is_Subunit is just scanning through
5932 -- the file until it finds one of the reserved words
5933 -- separate, procedure, function, generic or package.
5934 -- Fortunately, these Ada reserved words are also
5935 -- reserved for project files.
5938 Src_Ind := Sinput.P.Load_Project_File
5940 (Unit.File_Names (Com.Body_Part).Path));
5942 -- If it is a subunit, discard it
5944 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
5948 Sfile := Unit.File_Names (Com.Body_Part).Name;
5953 Sfile := Unit.File_Names (Com.Body_Part).Name;
5957 elsif Unit.File_Names (Com.Specification).Name /= No_Name
5958 and then Unit.File_Names (Com.Specification).Path /= Slash
5959 and then Check_Project (Unit.File_Names (Com.Specification).Project)
5961 -- If there is no source for the body, but there is a source
5962 -- for the spec which has not been locally removed, then we take
5965 Sfile := Unit.File_Names (Com.Specification).Name;
5968 -- If Put_In_Q is True, we insert into the Q
5972 -- For the first source inserted into the Q, we need
5973 -- to initialize the Q, but not for the subsequent sources.
5975 if First_Q_Initialization then
5979 -- And of course, we only insert in the Q if the source
5982 if Sfile /= No_Name and then not Is_Marked (Sfile) then
5983 if Verbose_Mode then
5984 Write_Str ("Adding
""");
5985 Write_Str (Get_Name_String (Sfile));
5986 Write_Line (""" to the queue
");
5993 elsif Sfile /= No_Name then
5995 -- If Put_In_Q is False, we add the source as it it were
5996 -- specified on the command line, and we set Put_In_Q to True,
5997 -- so that the following sources will be put directly in the
5998 -- queue. This will allow parallel compilation processes if -jx
6001 if Verbose_Mode then
6002 Write_Str ("Adding
""");
6003 Write_Str (Get_Name_String (Sfile));
6004 Write_Line (""" as
if on the command line
");
6007 Osint.Add_File (Get_Name_String (Sfile));
6011 end Insert_Project_Sources;
6018 (Source_File : File_Name_Type;
6019 Source_Unit : Unit_Name_Type := No_Name;
6023 if Debug.Debug_Flag_Q then
6024 Write_Str (" Q
:= Q
+ [ ");
6025 Write_Name (Source_File);
6037 (File => Source_File,
6038 Unit => Source_Unit,
6043 ---------------------
6044 -- Is_In_Obsoleted --
6045 ---------------------
6047 function Is_In_Obsoleted (F : Name_Id) return Boolean is
6054 Name : constant String := Get_Name_String (F);
6055 First : Natural := Name'Last;
6059 while First > Name'First
6060 and then Name (First - 1) /= Directory_Separator
6061 and then Name (First - 1) /= '/'
6066 if First /= Name'First then
6068 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
6072 return Obsoleted.Get (F2);
6075 end Is_In_Obsoleted;
6077 ----------------------------
6078 -- Is_In_Object_Directory --
6079 ----------------------------
6081 function Is_In_Object_Directory
6082 (Source_File : File_Name_Type;
6083 Full_Lib_File : File_Name_Type) return Boolean
6086 -- There is something to check only when using project files.
6087 -- Otherwise, this function returns True (last line of the function).
6089 if Main_Project /= No_Project then
6091 Source_File_Name : constant String :=
6092 Get_Name_String (Source_File);
6093 Saved_Verbosity : constant Verbosity := Prj.Com.Current_Verbosity;
6094 Project : Project_Id := No_Project;
6095 Path_Name : Name_Id := No_Name;
6096 Data : Project_Data;
6099 -- Call Get_Reference to know the ultimate extending project of
6100 -- the source. Call it with verbosity default to avoid verbose
6103 Prj.Com.Current_Verbosity := Default;
6106 (Source_File_Name => Source_File_Name,
6109 Prj.Com.Current_Verbosity := Saved_Verbosity;
6111 -- If this source is in a project, check that the ALI file is
6112 -- in its object directory. If it is not, return False, so that
6113 -- the ALI file will not be skipped.
6115 -- If the source is not in an extending project, we fall back to
6116 -- the general case and return True at the end of the function.
6118 if Project /= No_Project
6119 and then Projects.Table (Project).Extends /= No_Project
6121 Data := Projects.Table (Project);
6124 Object_Directory : constant String :=
6127 (Data.Object_Directory));
6129 Olast : Natural := Object_Directory'Last;
6131 Lib_File_Directory : constant String :=
6132 Normalize_Pathname (Dir_Name
6133 (Get_Name_String (Full_Lib_File)));
6135 Llast : Natural := Lib_File_Directory'Last;
6138 -- For directories, Normalize_Pathname may or may not put
6139 -- a directory separator at the end, depending on its input.
6140 -- Remove any last directory separator before comparaison.
6141 -- Returns True only if the two directories are the same.
6143 if Object_Directory (Olast) = Directory_Separator then
6147 if Lib_File_Directory (Llast) = Directory_Separator then
6151 return Object_Directory (Object_Directory'First .. Olast) =
6152 Lib_File_Directory (Lib_File_Directory'First .. Llast);
6158 -- When the source is not in a project file, always return True
6161 end Is_In_Object_Directory;
6167 procedure Link (ALI_File : File_Name_Type; Args : Argument_List) is
6168 Link_Args : Argument_List (1 .. Args'Length + 1);
6172 Get_Name_String (ALI_File);
6173 Link_Args (1) := new String'(Name_Buffer (1 .. Name_Len));
6175 Link_Args (2 .. Args'Length + 1) := Args;
6177 GNAT.OS_Lib.Normalize_Arguments (Link_Args);
6179 Display (Gnatlink.all, Link_Args);
6181 if Gnatlink_Path = null then
6182 Make_Failed ("error
, unable to locate
", Gnatlink.all);
6185 GNAT.OS_Lib.Spawn (Gnatlink_Path.all, Link_Args, Success);
6192 ---------------------------
6193 -- List_Bad_Compilations --
6194 ---------------------------
6196 procedure List_Bad_Compilations is
6198 for J in Bad_Compilation.First .. Bad_Compilation.Last loop
6199 if Bad_Compilation.Table (J).File = No_File then
6201 elsif not Bad_Compilation.Table (J).Found then
6202 Inform (Bad_Compilation.Table (J).File, "not found
");
6204 Inform (Bad_Compilation.Table (J).File, "compilation error
");
6207 end List_Bad_Compilations;
6213 procedure List_Depend is
6220 Line_Size : constant := 77;
6223 Set_Standard_Output;
6225 for A in ALIs.First .. ALIs.Last loop
6226 Lib_Name := ALIs.Table (A).Afile;
6228 -- We have to provide the full library file name in In_Place_Mode
6230 if In_Place_Mode then
6231 Lib_Name := Full_Lib_File_Name (Lib_Name);
6234 Obj_Name := Object_File_Name (Lib_Name);
6235 Write_Name (Obj_Name);
6238 Get_Name_String (Obj_Name);
6240 Line_Pos := Len + 2;
6242 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
6243 Src_Name := Sdep.Table (D).Sfile;
6245 if Is_Internal_File_Name (Src_Name)
6246 and then not Check_Readonly_Files
6250 if not Quiet_Output then
6251 Src_Name := Full_Source_Name (Src_Name);
6254 Get_Name_String (Src_Name);
6257 if Line_Pos + Len + 1 > Line_Size then
6263 Line_Pos
:= Line_Pos
+ Len
+ 1;
6266 Write_Name
(Src_Name
);
6280 procedure Make_Failed
(S1
: String; S2
: String := ""; S3
: String := "") is
6282 Delete_All_Temp_Files
;
6283 Osint
.Fail
(S1
, S2
, S3
);
6286 --------------------
6287 -- Mark_Directory --
6288 --------------------
6290 procedure Mark_Directory
6292 Mark
: Lib_Mark_Type
)
6298 -- Dir last character is supposed to be a directory separator
6300 Name_Len
:= Dir
'Length;
6301 Name_Buffer
(1 .. Name_Len
) := Dir
;
6303 if not Is_Directory_Separator
(Name_Buffer
(Name_Len
)) then
6304 Name_Len
:= Name_Len
+ 1;
6305 Name_Buffer
(Name_Len
) := Directory_Separator
;
6308 -- Add flags to the already existing flags
6311 B
:= Get_Name_Table_Byte
(N
);
6312 Set_Name_Table_Byte
(N
, B
or Mark
);
6315 -----------------------------
6316 -- Recursive_Compute_Depth --
6317 -----------------------------
6319 procedure Recursive_Compute_Depth
6320 (Project
: Project_Id
;
6323 List
: Project_List
;
6327 -- Nothing to do if there is no project or if the project has already
6328 -- been seen or if the depth is large enough.
6330 if Project
= No_Project
6331 or else Projects
.Table
(Project
).Seen
6332 or else Projects
.Table
(Project
).Depth
>= Depth
6337 Projects
.Table
(Project
).Depth
:= Depth
;
6339 -- Mark the project as Seen to avoid endless loop caused by limited
6342 Projects
.Table
(Project
).Seen
:= True;
6344 List
:= Projects
.Table
(Project
).Imported_Projects
;
6346 -- Visit each imported project
6348 while List
/= Empty_Project_List
loop
6349 Proj
:= Project_Lists
.Table
(List
).Project
;
6350 List
:= Project_Lists
.Table
(List
).Next
;
6351 Recursive_Compute_Depth
6353 Depth
=> Depth
+ 1);
6356 -- Visit a project being extended, if any
6358 Recursive_Compute_Depth
6359 (Project
=> Projects
.Table
(Project
).Extends
,
6360 Depth
=> Depth
+ 1);
6362 -- Reset the Seen flag, as we leave this project
6364 Projects
.Table
(Project
).Seen
:= False;
6365 end Recursive_Compute_Depth
;
6367 -----------------------
6368 -- Sigint_Intercpted --
6369 -----------------------
6371 procedure Sigint_Intercepted
is
6373 Write_Line
("*** Interrupted ***");
6374 Delete_All_Temp_Files
;
6376 end Sigint_Intercepted
;
6382 procedure Scan_Make_Arg
(Argv
: String; And_Save
: Boolean) is
6384 pragma Assert
(Argv
'First = 1);
6386 if Argv
'Length = 0 then
6390 -- If the previous switch has set the Project_File_Name_Present
6391 -- flag (that is we have seen a -P alone), then the next argument is
6392 -- the name of the project file.
6394 if Project_File_Name_Present
and then Project_File_Name
= null then
6395 if Argv
(1) = '-' then
6396 Make_Failed
("project file name missing after -P");
6399 Project_File_Name_Present
:= False;
6400 Project_File_Name
:= new String'(Argv);
6403 -- If the previous switch has set the Output_File_Name_Present
6404 -- flag (that is we have seen a -o), then the next argument is
6405 -- the name of the output executable.
6407 elsif Output_File_Name_Present
6408 and then not Output_File_Name_Seen
6410 Output_File_Name_Seen := True;
6412 if Argv (1) = '-' then
6413 Make_Failed ("output file name missing after -o");
6416 Add_Switch ("-o", Linker, And_Save => And_Save);
6418 -- Automatically add the executable suffix if it has not been
6419 -- specified explicitly.
6422 Canonical_Argv : String := Argv;
6424 -- Get the file name in canonical case to accept as is
6425 -- names ending with ".EXE" on VMS and Windows.
6427 Canonical_Case_File_Name (Canonical_Argv);
6429 if Executable_Suffix'Length /= 0
6430 and then (Canonical_Argv'Length <= Executable_Suffix'Length
6431 or else Canonical_Argv
6432 (Canonical_Argv'Last -
6433 Executable_Suffix'Length + 1
6434 .. Canonical_Argv'Last)
6435 /= Executable_Suffix)
6438 (Argv & Executable_Suffix,
6440 And_Save => And_Save);
6442 Add_Switch (Argv, Linker, And_Save => And_Save);
6447 -- If the previous switch has set the Object_Directory_Present flag
6448 -- (that is we have seen a -D), then the next argument is
6449 -- the path name of the object directory..
6451 elsif Object_Directory_Present
6452 and then not Object_Directory_Seen
6454 Object_Directory_Seen := True;
6456 if Argv (1) = '-' then
6457 Make_Failed ("object directory path name missing after -D");
6459 elsif not Is_Directory (Argv) then
6460 Make_Failed ("cannot find object directory """, Argv, """");
6463 Add_Lib_Search_Dir (Argv);
6465 -- Specify the object directory to the binder
6467 Add_Switch ("-aO" & Argv, Binder, And_Save => And_Save);
6469 -- Record the object directory. Make sure it ends with a directory
6472 if Argv (Argv'Last) = Directory_Separator then
6473 Object_Directory_Path := new String'(Argv
);
6476 Object_Directory_Path
:=
6477 new String'(Argv & Directory_Separator);
6481 -- Then check if we are dealing with -cargs/-bargs/-largs/-margs
6483 elsif Argv = "-bargs"
6492 when 'c
' => Program_Args := Compiler;
6493 when 'b
' => Program_Args := Binder;
6494 when 'l
' => Program_Args := Linker;
6495 when 'm
' => Program_Args := None;
6498 raise Program_Error;
6501 -- A special test is needed for the -o switch within a -largs
6502 -- since that is another way to specify the name of the final
6505 elsif Program_Args = Linker
6506 and then Argv = "-o"
6508 Make_Failed ("switch -o not allowed within a -largs. " &
6509 "Use -o directly.");
6511 -- Check to see if we are reading switches after a -cargs,
6512 -- -bargs or -largs switch. If yes save it.
6514 elsif Program_Args /= None then
6516 -- Check to see if we are reading -I switches in order
6517 -- to take into account in the src & lib search directories.
6519 if Argv'Length > 2 and then Argv (1 .. 2) = "-I" then
6520 if Argv (3 .. Argv'Last) = "-" then
6521 Look_In_Primary_Dir := False;
6523 elsif Program_Args = Compiler then
6524 if Argv (3 .. Argv'Last) /= "-" then
6525 Add_Src_Search_Dir (Argv (3 .. Argv'Last));
6528 elsif Program_Args = Binder then
6529 Add_Lib_Search_Dir (Argv (3 .. Argv'Last));
6533 Add_Switch (Argv, Program_Args, And_Save => And_Save);
6535 -- Handle non-default compiler, binder, linker, and handle --RTS switch
6537 elsif Argv'Length > 2 and then Argv (1 .. 2) = "--" then
6539 and then Argv (1 .. 6) = "--GCC="
6542 Program_Args : constant Argument_List_Access :=
6543 Argument_String_To_List
6544 (Argv (7 .. Argv'Last));
6548 Saved_Gcc := new String'(Program_Args
.all (1).all);
6550 Gcc
:= new String'(Program_Args.all (1).all);
6553 for J in 2 .. Program_Args.all'Last loop
6555 (Program_Args.all (J).all,
6557 And_Save => And_Save);
6561 elsif Argv'Length > 11
6562 and then Argv (1 .. 11) = "--GNATBIND="
6565 Program_Args : constant Argument_List_Access :=
6566 Argument_String_To_List
6567 (Argv (12 .. Argv'Last));
6571 Saved_Gnatbind := new String'(Program_Args
.all (1).all);
6573 Gnatbind
:= new String'(Program_Args.all (1).all);
6576 for J in 2 .. Program_Args.all'Last loop
6578 (Program_Args.all (J).all, Binder, And_Save => And_Save);
6582 elsif Argv'Length > 11
6583 and then Argv (1 .. 11) = "--GNATLINK="
6586 Program_Args : constant Argument_List_Access :=
6587 Argument_String_To_List
6588 (Argv (12 .. Argv'Last));
6591 Saved_Gnatlink := new String'(Program_Args
.all (1).all);
6593 Gnatlink
:= new String'(Program_Args.all (1).all);
6596 for J in 2 .. Program_Args.all'Last loop
6597 Add_Switch (Program_Args.all (J).all, Linker);
6601 elsif Argv'Length >= 5 and then
6602 Argv (1 .. 5) = "--RTS"
6604 Add_Switch (Argv, Compiler, And_Save => And_Save);
6605 Add_Switch (Argv, Binder, And_Save => And_Save);
6607 if Argv'Length <= 6 or else Argv (6) /= '=' then
6608 Make_Failed ("missing path for --RTS");
6611 -- Check that this is the first time we see this switch or
6612 -- if it is not the first time, the same path is specified.
6614 if RTS_Specified = null then
6615 RTS_Specified := new String'(Argv
(7 .. Argv
'Last));
6617 elsif RTS_Specified
.all /= Argv
(7 .. Argv
'Last) then
6618 Make_Failed
("--RTS cannot be specified multiple times");
6621 -- Valid --RTS switch
6628 Src_Path_Name
: constant String_Ptr
:=
6630 (Argv
(7 .. Argv
'Last), Include
);
6632 Lib_Path_Name
: constant String_Ptr
:=
6634 (Argv
(7 .. Argv
'Last), Objects
);
6637 if Src_Path_Name
/= null and then
6638 Lib_Path_Name
/= null
6640 -- Set the RTS_*_Path_Name variables, so that the correct
6641 -- directories will be set when
6642 -- Osint.Add_Default_Search_Dirs will be called later.
6644 RTS_Src_Path_Name
:= Src_Path_Name
;
6645 RTS_Lib_Path_Name
:= Lib_Path_Name
;
6647 elsif Src_Path_Name
= null
6648 and Lib_Path_Name
= null then
6649 Make_Failed
("RTS path not valid: missing " &
6650 "adainclude and adalib directories");
6652 elsif Src_Path_Name
= null then
6653 Make_Failed
("RTS path not valid: missing adainclude " &
6656 elsif Lib_Path_Name
= null then
6657 Make_Failed
("RTS path not valid: missing adalib " &
6664 Make_Failed
("unknown switch: ", Argv
);
6667 -- If we have seen a regular switch process it
6669 elsif Argv
(1) = '-' then
6671 if Argv
'Length = 1 then
6672 Make_Failed
("switch character cannot be followed by a blank");
6676 elsif Argv
(2 .. Argv
'Last) = "I-" then
6677 Look_In_Primary_Dir
:= False;
6679 -- Forbid -?- or -??- where ? is any character
6681 elsif (Argv
'Length = 3 and then Argv
(3) = '-')
6682 or else (Argv
'Length = 4 and then Argv
(4) = '-')
6684 Make_Failed
("trailing ""-"" at the end of ", Argv
, " forbidden.");
6688 elsif Argv
(2) = 'I' then
6689 Add_Src_Search_Dir
(Argv
(3 .. Argv
'Last));
6690 Add_Lib_Search_Dir
(Argv
(3 .. Argv
'Last));
6691 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
6692 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
6694 -- -aIdir (to gcc this is like a -I switch)
6696 elsif Argv
'Length >= 3 and then Argv
(2 .. 3) = "aI" then
6697 Add_Src_Search_Dir
(Argv
(4 .. Argv
'Last));
6698 Add_Switch
("-I" & Argv
(4 .. Argv
'Last),
6700 And_Save
=> And_Save
);
6701 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
6705 elsif Argv
'Length >= 3 and then Argv
(2 .. 3) = "aO" then
6706 Add_Lib_Search_Dir
(Argv
(4 .. Argv
'Last));
6707 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
6709 -- -aLdir (to gnatbind this is like a -aO switch)
6711 elsif Argv
'Length >= 3 and then Argv
(2 .. 3) = "aL" then
6712 Mark_Directory
(Argv
(4 .. Argv
'Last), Ada_Lib_Dir
);
6713 Add_Lib_Search_Dir
(Argv
(4 .. Argv
'Last));
6714 Add_Switch
("-aO" & Argv
(4 .. Argv
'Last),
6716 And_Save
=> And_Save
);
6718 -- -Adir (to gnatbind this is like a -aO switch, to gcc like a -I)
6720 elsif Argv
(2) = 'A' then
6721 Mark_Directory
(Argv
(3 .. Argv
'Last), Ada_Lib_Dir
);
6722 Add_Src_Search_Dir
(Argv
(3 .. Argv
'Last));
6723 Add_Lib_Search_Dir
(Argv
(3 .. Argv
'Last));
6724 Add_Switch
("-I" & Argv
(3 .. Argv
'Last),
6726 And_Save
=> And_Save
);
6727 Add_Switch
("-aO" & Argv
(3 .. Argv
'Last),
6729 And_Save
=> And_Save
);
6733 elsif Argv
(2) = 'L' then
6734 Add_Switch
(Argv
, Linker
, And_Save
=> And_Save
);
6736 -- For -gxxxxx, -pg, -mxxx, -fxxx: give the switch to both the
6737 -- compiler and the linker (except for -gnatxxx which is only for
6738 -- the compiler). Some of the -mxxx (for example -m64) and -fxxx
6739 -- (for example -ftest-coverage for gcov) need to be used when
6740 -- compiling the binder generated files, and using all these gcc
6741 -- switches for the binder generated files should not be a problem.
6744 (Argv
(2) = 'g' and then (Argv
'Last < 5
6745 or else Argv
(2 .. 5) /= "gnat"))
6746 or else Argv
(2 .. Argv
'Last) = "pg"
6747 or else (Argv
(2) = 'm' and then Argv
'Last > 2)
6748 or else (Argv
(2) = 'f' and then Argv
'Last > 2)
6750 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
6751 Add_Switch
(Argv
, Linker
, And_Save
=> And_Save
);
6753 -- -C=<mapping file>
6755 elsif Argv
'Last > 2 and then Argv
(2) = 'C' then
6757 if Argv
(3) /= '=' or else Argv
'Last <= 3 then
6758 Make_Failed
("illegal switch ", Argv
);
6761 Gnatmake_Mapping_File
:= new String'(Argv (4 .. Argv'Last));
6766 elsif Argv'Last = 2 and then Argv (2) = 'D
' then
6767 if Project_File_Name /= null then
6768 Make_Failed ("-D cannot be used in conjunction with a " &
6772 Scan_Make_Switches (Argv);
6777 elsif Argv (2) = 'd
'
6778 and then Argv'Last = 2
6780 Display_Compilation_Progress := True;
6784 elsif Argv'Last = 2 and then Argv (2) = 'i
' then
6785 if Project_File_Name /= null then
6786 Make_Failed ("-i cannot be used in conjunction with a " &
6790 Scan_Make_Switches (Argv);
6793 -- -j (need to save the result)
6795 elsif Argv (2) = 'j
' then
6796 Scan_Make_Switches (Argv);
6799 Saved_Maximum_Processes := Maximum_Processes;
6804 elsif Argv (2) = 'm
'
6805 and then Argv'Last = 2
6807 Minimal_Recompilation := True;
6811 elsif Argv (2) = 'u
'
6812 and then Argv'Last = 2
6814 Unique_Compile := True;
6815 Compile_Only := True;
6816 Do_Bind_Step := False;
6817 Do_Link_Step := False;
6821 elsif Argv (2) = 'U
'
6822 and then Argv'Last = 2
6824 Unique_Compile_All_Projects := True;
6825 Unique_Compile := True;
6826 Compile_Only := True;
6827 Do_Bind_Step := False;
6828 Do_Link_Step := False;
6830 -- -Pprj or -P prj (only once, and only on the command line)
6832 elsif Argv (2) = 'P
' then
6833 if Project_File_Name /= null then
6834 Make_Failed ("cannot have several project files specified");
6836 elsif Object_Directory_Path /= null then
6837 Make_Failed ("-D cannot be used in conjunction with a " &
6840 elsif In_Place_Mode then
6841 Make_Failed ("-i cannot be used in conjunction with a " &
6844 elsif not And_Save then
6846 -- It could be a tool other than gnatmake (i.e, gnatdist)
6847 -- or a -P switch inside a project file.
6850 ("either the tool is not ""project-aware"" or " &
6851 "a project file is specified inside a project file");
6853 elsif Argv'Last = 2 then
6855 -- -P is used alone: the project file name is the next option
6857 Project_File_Name_Present := True;
6860 Project_File_Name := new String'(Argv
(3 .. Argv
'Last));
6863 -- -vPx (verbosity of the parsing of the project files)
6866 and then Argv
(2 .. 3) = "vP"
6867 and then Argv
(4) in '0' .. '2'
6872 Current_Verbosity
:= Prj
.Default
;
6874 Current_Verbosity
:= Prj
.Medium
;
6876 Current_Verbosity
:= Prj
.High
;
6882 -- -Xext=val (External assignment)
6884 elsif Argv
(2) = 'X'
6885 and then Is_External_Assignment
(Argv
)
6887 -- Is_External_Assignment has side effects
6888 -- when it returns True;
6892 -- If -gnath is present, then generate the usage information
6893 -- right now and do not pass this option on to the compiler calls.
6895 elsif Argv
= "-gnath" then
6898 -- If -gnatc is specified, make sure the bind step and the link
6899 -- step are not executed.
6901 elsif Argv
'Length >= 6 and then Argv
(2 .. 6) = "gnatc" then
6903 -- If -gnatc is specified, make sure the bind step and the link
6904 -- step are not executed.
6906 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
6907 Operating_Mode
:= Check_Semantics
;
6908 Check_Object_Consistency
:= False;
6909 Compile_Only
:= True;
6910 Do_Bind_Step
:= False;
6911 Do_Link_Step
:= False;
6913 elsif Argv
(2 .. Argv
'Last) = "nostdlib" then
6915 -- Don't pass -nostdlib to gnatlink, it will disable
6916 -- linking with all standard library files.
6920 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
6921 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
6923 elsif Argv
(2 .. Argv
'Last) = "nostdinc" then
6925 -- Pass -nostdinc to the Compiler and to gnatbind
6928 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
6929 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
6931 -- By default all switches with more than one character
6932 -- or one character switches which are not in 'a' .. 'z'
6933 -- (except 'C', 'F', 'M' and 'B') are passed to the compiler,
6934 -- unless we are dealing with a debug switch (starts with 'd')
6935 -- or an extended gnatmake switch (starts with 'e').
6937 elsif Argv
(2) /= 'd'
6938 and then Argv
(2) /= 'e'
6939 and then Argv
(2 .. Argv
'Last) /= "C"
6940 and then Argv
(2 .. Argv
'Last) /= "F"
6941 and then Argv
(2 .. Argv
'Last) /= "M"
6942 and then Argv
(2 .. Argv
'Last) /= "B"
6943 and then (Argv
'Length > 2 or else Argv
(2) not in 'a' .. 'z')
6945 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
6947 -- All other options are handled by Scan_Make_Switches
6950 Scan_Make_Switches
(Argv
);
6953 -- If not a switch it must be a file name
6957 Mains
.Add_Main
(Argv
);
6965 function Switches_Of
6966 (Source_File
: Name_Id
;
6967 Source_File_Name
: String;
6969 Naming
: Naming_Data
;
6970 In_Package
: Package_Id
;
6971 Allow_ALI
: Boolean) return Variable_Value
6973 Switches
: Variable_Value
;
6975 Defaults
: constant Array_Element_Id
:=
6977 (Name
=> Name_Default_Switches
,
6979 Packages
.Table
(In_Package
).Decl
.Arrays
);
6981 Switches_Array
: constant Array_Element_Id
:=
6983 (Name
=> Name_Switches
,
6985 Packages
.Table
(In_Package
).Decl
.Arrays
);
6990 (Index
=> Source_File
,
6991 Src_Index
=> Source_Index
,
6992 In_Array
=> Switches_Array
);
6994 if Switches
= Nil_Variable_Value
then
6996 Name
: String (1 .. Source_File_Name
'Length + 3);
6997 Last
: Positive := Source_File_Name
'Length;
6998 Spec_Suffix
: constant String :=
6999 Get_Name_String
(Naming
.Ada_Spec_Suffix
);
7000 Body_Suffix
: constant String :=
7001 Get_Name_String
(Naming
.Ada_Body_Suffix
);
7002 Truncated
: Boolean := False;
7005 Name
(1 .. Last
) := Source_File_Name
;
7007 if Last
> Body_Suffix
'Length
7008 and then Name
(Last
- Body_Suffix
'Length + 1 .. Last
) =
7012 Last
:= Last
- Body_Suffix
'Length;
7016 and then Last
> Spec_Suffix
'Length
7017 and then Name
(Last
- Spec_Suffix
'Length + 1 .. Last
) =
7021 Last
:= Last
- Spec_Suffix
'Length;
7026 Name_Buffer
(1 .. Name_Len
) := Name
(1 .. Last
);
7029 (Index
=> Name_Find
,
7031 In_Array
=> Switches_Array
);
7033 if Switches
= Nil_Variable_Value
7036 Last
:= Source_File_Name
'Length;
7038 while Name
(Last
) /= '.' loop
7042 Name
(Last
+ 1 .. Last
+ 3) := "ali";
7043 Name_Len
:= Last
+ 3;
7044 Name_Buffer
(1 .. Name_Len
) := Name
(1 .. Name_Len
);
7047 (Index
=> Name_Find
,
7049 In_Array
=> Switches_Array
);
7055 if Switches
= Nil_Variable_Value
then
7060 In_Array
=> Defaults
);
7072 if Usage_Needed
then
7073 Usage_Needed
:= False;
7082 procedure Verbose_Msg
7085 N2
: Name_Id
:= No_Name
;
7087 Prefix
: String := " -> ")
7090 if not Verbose_Mode
then
7100 if N2
/= No_Name
then
7111 -- Make sure that in case of failure, the temp files will be deleted
7113 Prj
.Com
.Fail
:= Make_Failed
'Access;
7114 MLib
.Fail
:= Make_Failed
'Access;
7115 Makeutl
.Do_Fail
:= Make_Failed
'Access;