1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, 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 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
27 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
;
41 with MLib
.Tgt
; use MLib
.Tgt
;
43 with Namet
; use Namet
;
45 with Osint
.M
; use Osint
.M
;
46 with Osint
; use Osint
;
47 with Output
; use Output
;
52 with Prj
.Tree
; use Prj
.Tree
;
56 with Snames
; use Snames
;
58 pragma Warnings
(Off
);
62 with Switch
; use Switch
;
63 with Switch
.M
; use Switch
.M
;
64 with Targparm
; use Targparm
;
67 with Types
; use Types
;
69 with Ada
.Exceptions
; use Ada
.Exceptions
;
70 with Ada
.Command_Line
; use Ada
.Command_Line
;
72 with GNAT
.Directory_Operations
; use GNAT
.Directory_Operations
;
73 with GNAT
.Dynamic_HTables
; use GNAT
.Dynamic_HTables
;
74 with GNAT
.Case_Util
; use GNAT
.Case_Util
;
75 with GNAT
.OS_Lib
; use GNAT
.OS_Lib
;
80 -- Make control characters visible
82 Standard_Library_Package_Body_Name
: constant String := "s-stalib.adb";
83 -- Every program depends on this package, that must then be checked,
84 -- especially when -f and -a are used.
86 procedure Kill
(Pid
: Process_Id
; Sig_Num
: Integer; Close
: Integer);
87 pragma Import
(C
, Kill
, "__gnat_kill");
88 -- Called by Sigint_Intercepted to kill all spawned compilation processes
90 type Sigint_Handler
is access procedure;
91 pragma Convention
(C
, Sigint_Handler
);
93 procedure Install_Int_Handler
(Handler
: Sigint_Handler
);
94 pragma Import
(C
, Install_Int_Handler
, "__gnat_install_int_handler");
95 -- Called by Gnatmake to install the SIGINT handler below
97 procedure Sigint_Intercepted
;
98 pragma Convention
(C
, Sigint_Intercepted
);
99 -- Called when the program is interrupted by Ctrl-C to delete the
100 -- temporary mapping files and configuration pragmas files.
102 No_Mapping_File
: constant Natural := 0;
104 type Compilation_Data
is record
106 Full_Source_File
: File_Name_Type
;
107 Lib_File
: File_Name_Type
;
108 Source_Unit
: Unit_Name_Type
;
109 Mapping_File
: Natural := No_Mapping_File
;
110 Project
: Project_Id
:= No_Project
;
111 Syntax_Only
: Boolean := False;
112 Output_Is_Object
: Boolean := True;
114 -- Data recorded for each compilation process spawned
116 type Comp_Data_Arr
is array (Positive range <>) of Compilation_Data
;
117 type Comp_Data_Ptr
is access Comp_Data_Arr
;
118 Running_Compile
: Comp_Data_Ptr
;
119 -- Used to save information about outstanding compilations
121 Outstanding_Compiles
: Natural := 0;
122 -- Current number of outstanding compiles
124 -------------------------
125 -- Note on terminology --
126 -------------------------
128 -- In this program, we use the phrase "termination" of a file name to refer
129 -- to the suffix that appears after the unit name portion. Very often this
130 -- is simply the extension, but in some cases, the sequence may be more
131 -- complex, for example in main.1.ada, the termination in this name is
132 -- ".1.ada" and in main_.ada the termination is "_.ada".
134 -------------------------------------
135 -- Queue (Q) Manipulation Routines --
136 -------------------------------------
138 -- The Q is used in Compile_Sources below. Its implementation uses the GNAT
139 -- generic package Table (basically an extensible array). Q_Front points to
140 -- the first valid element in the Q, whereas Q.First is the first element
141 -- ever enqueued, while Q.Last - 1 is the last element in the Q.
143 -- +---+--------------+---+---+---+-----------+---+--------
144 -- Q | | ........ | | | | ....... | |
145 -- +---+--------------+---+---+---+-----------+---+--------
147 -- Q.First Q_Front Q.Last-1
149 -- The elements comprised between Q.First and Q_Front-1 are the elements
150 -- that have been enqueued and then dequeued, while the elements between
151 -- Q_Front and Q.Last-1 are the elements currently in the Q. When the Q
152 -- is initialized Q_Front = Q.First = Q.Last. After Compile_Sources has
153 -- terminated its execution, Q_Front = Q.Last and the elements contained
154 -- between Q.First and Q.Last-1 are those that were explored and thus
155 -- marked by Compile_Sources. Whenever the Q is reinitialized, the elements
156 -- between Q.First and Q.Last-1 are unmarked.
159 -- Must be called to (re)initialize the Q
162 (Source_File
: File_Name_Type
;
163 Source_Unit
: Unit_Name_Type
:= No_Unit_Name
;
165 -- Inserts Source_File at the end of Q. Provide Source_Unit when possible
166 -- for external use (gnatdist). Provide index for multi-unit sources.
168 function Empty_Q
return Boolean;
169 -- Returns True if Q is empty
171 procedure Extract_From_Q
172 (Source_File
: out File_Name_Type
;
173 Source_Unit
: out Unit_Name_Type
;
174 Source_Index
: out Int
);
175 -- Extracts the first element from the Q
177 procedure Insert_Project_Sources
178 (The_Project
: Project_Id
;
179 All_Projects
: Boolean;
181 -- If Into_Q is True, insert all sources of the project file(s) that are
182 -- not already marked into the Q. If Into_Q is False, call Osint.Add_File
183 -- for the first source, then insert all other sources that are not already
184 -- marked into the Q. If All_Projects is True, all sources of all projects
185 -- are concerned; otherwise, only sources of The_Project are concerned,
186 -- including, if The_Project is an extending project, sources inherited
187 -- from projects being extended.
189 First_Q_Initialization
: Boolean := True;
190 -- Will be set to false after Init_Q has been called once
193 -- Points to the first valid element in the Q
195 Unique_Compile
: Boolean := False;
196 -- Set to True if -u or -U or a project file with no main is used
198 Unique_Compile_All_Projects
: Boolean := False;
199 -- Set to True if -U is used
201 RTS_Specified
: String_Access
:= null;
202 -- Used to detect multiple --RTS= switches
204 N_M_Switch
: Natural := 0;
205 -- Used to count -mxxx switches that can affect multilib
207 type Q_Record
is record
208 File
: File_Name_Type
;
209 Unit
: Unit_Name_Type
;
212 -- File is the name of the file to compile. Unit is for gnatdist
213 -- use in order to easily get the unit name of a file to compile
214 -- when its name is krunched or declared in gnat.adc. Index, when not 0,
215 -- is the index of the unit in a multi-unit source.
217 package Q
is new Table
.Table
(
218 Table_Component_Type
=> Q_Record
,
219 Table_Index_Type
=> Natural,
220 Table_Low_Bound
=> 0,
221 Table_Initial
=> 4000,
222 Table_Increment
=> 100,
223 Table_Name
=> "Make.Q");
224 -- This is the actual Q
226 -- The 3 following packages are used to store gcc, gnatbind and gnatlink
227 -- switches found in the project files.
229 package Gcc_Switches
is new Table
.Table
(
230 Table_Component_Type
=> String_Access
,
231 Table_Index_Type
=> Integer,
232 Table_Low_Bound
=> 1,
234 Table_Increment
=> 100,
235 Table_Name
=> "Make.Gcc_Switches");
237 package Binder_Switches
is new Table
.Table
(
238 Table_Component_Type
=> String_Access
,
239 Table_Index_Type
=> Integer,
240 Table_Low_Bound
=> 1,
242 Table_Increment
=> 100,
243 Table_Name
=> "Make.Binder_Switches");
245 package Linker_Switches
is new Table
.Table
(
246 Table_Component_Type
=> String_Access
,
247 Table_Index_Type
=> Integer,
248 Table_Low_Bound
=> 1,
250 Table_Increment
=> 100,
251 Table_Name
=> "Make.Linker_Switches");
253 -- The following instantiations and variables are necessary to save what
254 -- is found on the command line, in case there is a project file specified.
256 package Saved_Gcc_Switches
is new Table
.Table
(
257 Table_Component_Type
=> String_Access
,
258 Table_Index_Type
=> Integer,
259 Table_Low_Bound
=> 1,
261 Table_Increment
=> 100,
262 Table_Name
=> "Make.Saved_Gcc_Switches");
264 package Saved_Binder_Switches
is new Table
.Table
(
265 Table_Component_Type
=> String_Access
,
266 Table_Index_Type
=> Integer,
267 Table_Low_Bound
=> 1,
269 Table_Increment
=> 100,
270 Table_Name
=> "Make.Saved_Binder_Switches");
272 package Saved_Linker_Switches
is new Table
.Table
273 (Table_Component_Type
=> String_Access
,
274 Table_Index_Type
=> Integer,
275 Table_Low_Bound
=> 1,
277 Table_Increment
=> 100,
278 Table_Name
=> "Make.Saved_Linker_Switches");
280 package Switches_To_Check
is new Table
.Table
(
281 Table_Component_Type
=> String_Access
,
282 Table_Index_Type
=> Integer,
283 Table_Low_Bound
=> 1,
285 Table_Increment
=> 100,
286 Table_Name
=> "Make.Switches_To_Check");
288 package Library_Paths
is new Table
.Table
(
289 Table_Component_Type
=> String_Access
,
290 Table_Index_Type
=> Integer,
291 Table_Low_Bound
=> 1,
293 Table_Increment
=> 100,
294 Table_Name
=> "Make.Library_Paths");
296 package Failed_Links
is new Table
.Table
(
297 Table_Component_Type
=> File_Name_Type
,
298 Table_Index_Type
=> Integer,
299 Table_Low_Bound
=> 1,
301 Table_Increment
=> 100,
302 Table_Name
=> "Make.Failed_Links");
304 package Successful_Links
is new Table
.Table
(
305 Table_Component_Type
=> File_Name_Type
,
306 Table_Index_Type
=> Integer,
307 Table_Low_Bound
=> 1,
309 Table_Increment
=> 100,
310 Table_Name
=> "Make.Successful_Links");
312 package Library_Projs
is new Table
.Table
(
313 Table_Component_Type
=> Project_Id
,
314 Table_Index_Type
=> Integer,
315 Table_Low_Bound
=> 1,
317 Table_Increment
=> 100,
318 Table_Name
=> "Make.Library_Projs");
320 -- Two variables to keep the last binder and linker switch index in tables
321 -- Binder_Switches and Linker_Switches, before adding switches from the
322 -- project file (if any) and switches from the command line (if any).
324 Last_Binder_Switch
: Integer := 0;
325 Last_Linker_Switch
: Integer := 0;
327 Normalized_Switches
: Argument_List_Access
:= new Argument_List
(1 .. 10);
328 Last_Norm_Switch
: Natural := 0;
330 Saved_Maximum_Processes
: Natural := 0;
332 Gnatmake_Switch_Found
: Boolean;
333 -- Set by Scan_Make_Arg. True when the switch is a gnatmake switch.
334 -- Tested by Add_Switches when switches in package Builder must all be
335 -- gnatmake switches.
337 Switch_May_Be_Passed_To_The_Compiler
: Boolean;
338 -- Set by Add_Switches and Switches_Of. True when unrecognized switches
339 -- are passed to the Ada compiler.
341 type Arg_List_Ref
is access Argument_List
;
342 The_Saved_Gcc_Switches
: Arg_List_Ref
;
344 Project_File_Name
: String_Access
:= null;
345 -- The path name of the main project file, if any
347 Project_File_Name_Present
: Boolean := False;
348 -- True when -P is used with a space between -P and the project file name
350 Current_Verbosity
: Prj
.Verbosity
:= Prj
.Default
;
351 -- Verbosity to parse the project files
353 Main_Project
: Prj
.Project_Id
:= No_Project
;
354 -- The project id of the main project file, if any
356 Project_Of_Current_Object_Directory
: Project_Id
:= No_Project
;
357 -- The object directory of the project for the last compilation. Avoid
358 -- calling Change_Dir if the current working directory is already this
361 -- Packages of project files where unknown attributes are errors
363 Naming_String
: aliased String := "naming";
364 Builder_String
: aliased String := "builder";
365 Compiler_String
: aliased String := "compiler";
366 Binder_String
: aliased String := "binder";
367 Linker_String
: aliased String := "linker";
369 Gnatmake_Packages
: aliased String_List
:=
370 (Naming_String
'Access,
371 Builder_String 'Access,
372 Compiler_String
'Access,
373 Binder_String 'Access,
374 Linker_String
'Access);
376 Packages_To_Check_By_Gnatmake : constant String_List_Access :=
377 Gnatmake_Packages'Access;
379 procedure Add_Library_Search_Dir
381 On_Command_Line : Boolean);
382 -- Call Add_Lib_Search_Dir with an absolute directory path. If Path is
383 -- relative path, when On_Command_Line is True, it is relative to the
384 -- current working directory. When On_Command_Line is False, it is relative
385 -- to the project directory of the main project.
387 procedure Add_Source_Search_Dir
389 On_Command_Line : Boolean);
390 -- Call Add_Src_Search_Dir with an absolute directory path. If Path is a
391 -- relative path, when On_Command_Line is True, it is relative to the
392 -- current working directory. When On_Command_Line is False, it is relative
393 -- to the project directory of the main project.
395 procedure Add_Source_Dir (N : String);
396 -- Call Add_Src_Search_Dir (output one line when in verbose mode)
398 procedure Add_Source_Directories is
399 new Prj.Env.For_All_Source_Dirs (Action => Add_Source_Dir);
401 procedure Add_Object_Dir (N : String);
402 -- Call Add_Lib_Search_Dir (output one line when in verbose mode)
404 procedure Add_Object_Directories is
405 new Prj.Env.For_All_Object_Dirs (Action => Add_Object_Dir);
407 procedure Change_To_Object_Directory (Project : Project_Id);
408 -- Change to the object directory of project Project, if this is not
409 -- already the current working directory.
411 type Bad_Compilation_Info is record
412 File : File_Name_Type;
413 Unit : Unit_Name_Type;
416 -- File is the name of the file for which a compilation failed. Unit is for
417 -- gnatdist use in order to easily get the unit name of a file when its
418 -- name is krunched or declared in gnat.adc. Found is False if the
419 -- compilation failed because the file could not be found.
421 package Bad_Compilation is new Table.Table (
422 Table_Component_Type => Bad_Compilation_Info,
423 Table_Index_Type => Natural,
424 Table_Low_Bound => 1,
426 Table_Increment => 100,
427 Table_Name => "Make.Bad_Compilation");
428 -- Full name of all the source files for which compilation fails
430 Do_Compile_Step : Boolean := True;
431 Do_Bind_Step : Boolean := True;
432 Do_Link_Step : Boolean := True;
433 -- Flags to indicate what step should be executed. Can be set to False
434 -- with the switches -c, -b and -l. These flags are reset to True for
435 -- each invocation of procedure Gnatmake.
437 Shared_String : aliased String := "-shared";
438 Force_Elab_Flags_String : aliased String := "-F";
440 No_Shared_Switch : aliased Argument_List := (1 .. 0 => null);
441 Shared_Switch : aliased Argument_List := (1 => Shared_String'Access);
442 Bind_Shared : Argument_List_Access := No_Shared_Switch'Access;
443 -- Switch to added in front of gnatbind switches. By default no switch is
444 -- added. Switch "-shared" is added if there is a non-static Library
447 Shared_Libgcc : aliased String := "-shared-libgcc";
449 No_Shared_Libgcc_Switch : aliased Argument_List := (1 .. 0 => null);
450 Shared_Libgcc_Switch : aliased Argument_List :=
451 (1 => Shared_Libgcc'Access);
452 Link_With_Shared_Libgcc : Argument_List_Access :=
453 No_Shared_Libgcc_Switch'Access;
455 procedure Make_Failed (S : String);
456 -- Delete all temp files created by Gnatmake and call Osint.Fail, with the
457 -- parameter S (see osint.ads). This is called from the Prj hierarchy and
458 -- the MLib hierarchy.
460 --------------------------
461 -- Obsolete Executables --
462 --------------------------
464 Executable_Obsolete : Boolean := False;
465 -- Executable_Obsolete is initially set to False for each executable,
466 -- and is set to True whenever one of the source of the executable is
467 -- compiled, or has already been compiled for another executable.
469 Max_Header : constant := 200;
470 -- This needs a proper comment, it used to say "arbitrary"
471 -- that's not an adequate comment ???
473 type Header_Num is range 1 .. Max_Header;
474 -- Header_Num for the hash table Obsoleted below
476 function Hash (F : File_Name_Type) return Header_Num;
477 -- Hash function for the hash table Obsoleted below
479 package Obsoleted is new System.HTable.Simple_HTable
480 (Header_Num => Header_Num,
483 Key => File_Name_Type,
486 -- A hash table to keep all files that have been compiled, to detect
487 -- if an executable is up to date or not.
489 procedure Enter_Into_Obsoleted (F : File_Name_Type);
490 -- Enter a file name, without directory information, into the hash table
493 function Is_In_Obsoleted (F : File_Name_Type) return Boolean;
494 -- Check if a file name, without directory information, has already been
495 -- entered into the hash table Obsoleted.
497 type Dependency is record
498 This : File_Name_Type;
499 Depends_On : File_Name_Type;
501 -- Components of table Dependencies below
503 package Dependencies is new Table.Table (
504 Table_Component_Type => Dependency,
505 Table_Index_Type => Integer,
506 Table_Low_Bound => 1,
508 Table_Increment => 100,
509 Table_Name => "Make.Dependencies");
510 -- A table to keep dependencies, to be able to decide if an executable
511 -- is obsolete. More explanation needed ???
513 -- procedure Add_Dependency (S : File_Name_Type; On : File_Name_Type);
514 -- -- Add one entry in table Dependencies
516 ----------------------------
517 -- Arguments and Switches --
518 ----------------------------
520 Arguments : Argument_List_Access;
521 -- Used to gather the arguments for invocation of the compiler
523 Last_Argument : Natural := 0;
524 -- Last index of arguments in Arguments above
526 Arguments_Project : Project_Id;
527 -- Project id, if any, of the source to be compiled
529 Arguments_Path_Name : Path_Name_Type;
530 -- Full path of the source to be compiled, when Arguments_Project is not
533 Dummy_Switch : constant String_Access := new String'("- ");
534 -- Used to initialized Prev_Switch in procedure Check
536 procedure Add_Arguments
(Args
: Argument_List
);
537 -- Add arguments to global variable Arguments, increasing its size
538 -- if necessary and adjusting Last_Argument.
540 function Configuration_Pragmas_Switch
541 (For_Project
: Project_Id
) return Argument_List
;
542 -- Return an argument list of one element, if there is a configuration
543 -- pragmas file to be specified for For_Project,
544 -- otherwise return an empty argument list.
550 procedure List_Depend
;
551 -- Prints to standard output the list of object dependencies. This list
552 -- can be used directly in a Makefile. A call to Compile_Sources must
553 -- precede the call to List_Depend. Also because this routine uses the
554 -- ALI files that were originally loaded and scanned by Compile_Sources,
555 -- no additional ALI files should be scanned between the two calls (i.e.
556 -- between the call to Compile_Sources and List_Depend.)
558 procedure List_Bad_Compilations
;
559 -- Prints out the list of all files for which the compilation failed
561 Usage_Needed
: Boolean := True;
562 -- Flag used to make sure Makeusg is call at most once
565 -- Call Makeusg, if Usage_Needed is True.
566 -- Set Usage_Needed to False.
568 procedure Debug_Msg
(S
: String; N
: Name_Id
);
569 procedure Debug_Msg
(S
: String; N
: File_Name_Type
);
570 procedure Debug_Msg
(S
: String; N
: Unit_Name_Type
);
571 -- If Debug.Debug_Flag_W is set outputs string S followed by name N
573 procedure Recursive_Compute_Depth
(Project
: Project_Id
);
574 -- Compute depth of Project and of the projects it depends on
576 -----------------------
577 -- Gnatmake Routines --
578 -----------------------
580 subtype Lib_Mark_Type
is Byte
;
581 -- Used in Mark_Directory
583 Ada_Lib_Dir
: constant Lib_Mark_Type
:= 1;
584 -- Used to mark a directory as a GNAT lib dir
586 -- Note that the notion of GNAT lib dir is no longer used. The code related
587 -- to it has not been removed to give an idea on how to use the directory
588 -- prefix marking mechanism.
590 -- An Ada library directory is a directory containing ali and object files
591 -- but no source files for the bodies (the specs can be in the same or some
592 -- other directory). These directories are specified in the Gnatmake
593 -- command line with the switch "-Adir" (to specify the spec location -Idir
594 -- cab be used). Gnatmake skips the missing sources whose ali are in Ada
595 -- library directories. For an explanation of why Gnatmake behaves that
596 -- way, see the spec of Make.Compile_Sources. The directory lookup penalty
597 -- is incurred every single time this routine is called.
599 procedure Check_Steps
;
600 -- Check what steps (Compile, Bind, Link) must be executed.
601 -- Set the step flags accordingly.
603 function In_Ada_Lib_Dir
(File
: File_Name_Type
) return Boolean;
604 -- Get directory prefix of this file and get lib mark stored in name
605 -- table for this directory. Then check if an Ada lib mark has been set.
607 procedure Mark_Directory
609 Mark
: Lib_Mark_Type
;
610 On_Command_Line
: Boolean);
611 -- Store the absolute path from Dir in name table and set lib mark as name
612 -- info to identify Ada libraries.
614 -- If Dir is a relative path, when On_Command_Line is True, it is relative
615 -- to the current working directory; when On_Command_Line is False, it is
616 -- relative to the project directory of the main project.
618 Output_Is_Object
: Boolean := True;
619 -- Set to False when using a switch -S for the compiler
621 procedure Check_For_S_Switch
;
622 -- Set Output_Is_Object to False when the -S switch is used for the
626 (Source_File
: File_Name_Type
;
627 Source_File_Name
: String;
629 Project
: Project_Id
;
630 In_Package
: Package_Id
;
631 Allow_ALI
: Boolean) return Variable_Value
;
632 -- Return the switches for the source file in the specified package of a
633 -- project file. If the Source_File ends with a standard GNAT extension
634 -- (".ads" or ".adb"), try first the full name, then the name without the
635 -- extension, then, if Allow_ALI is True, the name with the extension
636 -- ".ali". If there is no switches for either names, try first Switches
637 -- (others) then the default switches for Ada. If all failed, return
638 -- No_Variable_Value.
640 function Is_In_Object_Directory
641 (Source_File
: File_Name_Type
;
642 Full_Lib_File
: File_Name_Type
) return Boolean;
643 -- Check if, when using a project file, the ALI file is in the project
644 -- directory of the ultimate extending project. If it is not, we ignore
645 -- the fact that this ALI file is read-only.
647 procedure Process_Multilib
(Project_Node_Tree
: Project_Node_Tree_Ref
);
648 -- Add appropriate --RTS argument to handle multilib
650 ----------------------------------------------------
651 -- Compiler, Binder & Linker Data and Subprograms --
652 ----------------------------------------------------
654 Gcc
: String_Access
:= Program_Name
("gcc", "gnatmake");
655 Gnatbind
: String_Access
:= Program_Name
("gnatbind", "gnatmake");
656 Gnatlink
: String_Access
:= Program_Name
("gnatlink", "gnatmake");
657 -- Default compiler, binder, linker programs
659 Saved_Gcc
: String_Access
:= null;
660 Saved_Gnatbind
: String_Access
:= null;
661 Saved_Gnatlink
: String_Access
:= null;
662 -- Given by the command line. Will be used, if non null
664 Gcc_Path
: String_Access
:=
665 GNAT
.OS_Lib
.Locate_Exec_On_Path
(Gcc
.all);
666 Gnatbind_Path
: String_Access
:=
667 GNAT
.OS_Lib
.Locate_Exec_On_Path
(Gnatbind
.all);
668 Gnatlink_Path
: String_Access
:=
669 GNAT
.OS_Lib
.Locate_Exec_On_Path
(Gnatlink
.all);
670 -- Path for compiler, binder, linker programs, defaulted now for gnatdist.
671 -- Changed later if overridden on command line.
673 Comp_Flag
: constant String_Access
:= new String'("-c");
674 Output_Flag : constant String_Access := new String'("-o");
675 Ada_Flag_1
: constant String_Access
:= new String'("-x");
676 Ada_Flag_2 : constant String_Access := new String'("ada");
677 No_gnat_adc
: constant String_Access
:= new String'("-gnatA");
678 GNAT_Flag : constant String_Access := new String'("-gnatpg");
679 Do_Not_Check_Flag
: constant String_Access
:= new String'("-x");
681 Object_Suffix : constant String := Get_Target_Object_Suffix.all;
683 Syntax_Only : Boolean := False;
684 -- Set to True when compiling with -gnats
686 Display_Executed_Programs : Boolean := True;
687 -- Set to True if name of commands should be output on stderr (or on stdout
688 -- if the Commands_To_Stdout flag was set by use of the -eS switch).
690 Output_File_Name_Seen : Boolean := False;
691 -- Set to True after having scanned the file_name for
692 -- switch "-o file_name"
694 Object_Directory_Seen : Boolean := False;
695 -- Set to True after having scanned the object directory for
696 -- switch "-D obj_dir".
698 Object_Directory_Path : String_Access := null;
699 -- The path name of the object directory, set with switch -D
701 type Make_Program_Type is (None, Compiler, Binder, Linker);
703 Program_Args : Make_Program_Type := None;
704 -- Used to indicate if we are scanning gnatmake, gcc, gnatbind, or gnatbind
705 -- options within the gnatmake command line. Used in Scan_Make_Arg only,
706 -- but must be global since value preserved from one call to another.
708 Temporary_Config_File : Boolean := False;
709 -- Set to True when there is a temporary config file used for a project
710 -- file, to avoid displaying the -gnatec switch for a temporary file.
712 procedure Add_Switches
713 (The_Package : Package_Id;
716 Program : Make_Program_Type;
717 Unknown_Switches_To_The_Compiler : Boolean := True;
718 Project_Node_Tree : Project_Node_Tree_Ref);
721 Program : Make_Program_Type;
722 Append_Switch : Boolean := True;
723 And_Save : Boolean := True);
726 Program : Make_Program_Type;
727 Append_Switch : Boolean := True;
728 And_Save : Boolean := True);
729 -- Make invokes one of three programs (the compiler, the binder or the
730 -- linker). For the sake of convenience, some program specific switches
731 -- can be passed directly on the gnatmake command line. This procedure
732 -- records these switches so that gnatmake can pass them to the right
733 -- program. S is the switch to be added at the end of the command line
734 -- for Program if Append_Switch is True. If Append_Switch is False S is
735 -- added at the beginning of the command line.
738 (Source_File : File_Name_Type;
740 Is_Main_Source : Boolean;
741 The_Args : Argument_List;
742 Lib_File : File_Name_Type;
745 O_File : out File_Name_Type;
746 O_Stamp : out Time_Stamp_Type);
747 -- Determines whether the library file Lib_File is up-to-date or not. The
748 -- full name (with path information) of the object file corresponding to
749 -- Lib_File is returned in O_File. Its time stamp is saved in O_Stamp.
750 -- ALI is the ALI_Id corresponding to Lib_File. If Lib_File in not
751 -- up-to-date, then the corresponding source file needs to be recompiled.
752 -- In this case ALI = No_ALI_Id.
754 procedure Check_Linker_Options
755 (E_Stamp : Time_Stamp_Type;
756 O_File : out File_Name_Type;
757 O_Stamp : out Time_Stamp_Type);
758 -- Checks all linker options for linker files that are newer
759 -- than E_Stamp. If such objects are found, the youngest object
760 -- is returned in O_File and its stamp in O_Stamp.
762 -- If no obsolete linker files were found, the first missing
763 -- linker file is returned in O_File and O_Stamp is empty.
764 -- Otherwise O_File is No_File.
766 procedure Collect_Arguments
767 (Source_File : File_Name_Type;
769 Is_Main_Source : Boolean;
770 Args : Argument_List);
771 -- Collect all arguments for a source to be compiled, including those
772 -- that come from a project file.
774 procedure Display (Program : String; Args : Argument_List);
775 -- Displays Program followed by the arguments in Args if variable
776 -- Display_Executed_Programs is set. The lower bound of Args must be 1.
778 procedure Report_Compilation_Failed;
779 -- Delete all temporary files and fail graciously
785 type Temp_Path_Names is array (Positive range <>) of Path_Name_Type;
786 type Temp_Path_Ptr is access Temp_Path_Names;
788 type Free_File_Indices is array (Positive range <>) of Positive;
789 type Free_Indices_Ptr is access Free_File_Indices;
791 type Project_Compilation_Data is record
792 Mapping_File_Names : Temp_Path_Ptr;
793 -- The name ids of the temporary mapping files used. This is indexed
794 -- on the maximum number of compilation processes we will be spawning
797 Last_Mapping_File_Names : Natural;
798 -- Index of the last mapping file created for this project
800 Free_Mapping_File_Indices : Free_Indices_Ptr;
801 -- Indices in Mapping_File_Names of the mapping file names that can be
802 -- reused for subsequent compilations.
804 Last_Free_Indices : Natural;
805 -- Number of mapping files that can be reused
807 -- Information necessary when compiling a project
809 type Project_Compilation_Access is access Project_Compilation_Data;
811 package Project_Compilation_Htable is new Simple_HTable
812 (Header_Num => Prj.Header_Num,
813 Element => Project_Compilation_Access,
819 Project_Compilation : Project_Compilation_Htable.Instance;
821 Gnatmake_Mapping_File : String_Access := null;
822 -- The path name of a mapping file specified by switch -C=
824 procedure Init_Mapping_File
825 (Project : Project_Id;
826 Data : in out Project_Compilation_Data;
827 File_Index : in out Natural);
828 -- Create a new temporary mapping file, and fill it with the project file
829 -- mappings, when using project file(s). The out parameter File_Index is
830 -- the index to the name of the file in the array The_Mapping_File_Names.
832 procedure Delete_Temp_Config_Files;
833 -- Delete all temporary config files. Must not be called if Debug_Flag_N
836 procedure Delete_All_Temp_Files;
837 -- Delete all temp files (config files, mapping files, path files), unless
838 -- Debug_Flag_N is True (in which case all temp files are left for user
841 -------------------------------------------------
842 -- Subprogram declarations moved from the spec --
843 -------------------------------------------------
845 procedure Bind (ALI_File : File_Name_Type; Args : Argument_List);
846 -- Binds ALI_File. Args are the arguments to pass to the binder.
847 -- Args must have a lower bound of 1.
849 procedure Display_Commands (Display : Boolean := True);
850 -- The default behavior of Make commands (Compile_Sources, Bind, Link)
851 -- is to display them on stderr. This behavior can be changed repeatedly
852 -- by invoking this procedure.
854 -- If a compilation, bind or link failed one of the following 3 exceptions
855 -- is raised. These need to be handled by the calling routines.
857 procedure Compile_Sources
858 (Main_Source : File_Name_Type;
859 Args : Argument_List;
860 First_Compiled_File : out File_Name_Type;
861 Most_Recent_Obj_File : out File_Name_Type;
862 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
863 Main_Unit : out Boolean;
864 Compilation_Failures : out Natural;
865 Main_Index : Int := 0;
866 Check_Readonly_Files : Boolean := False;
867 Do_Not_Execute : Boolean := False;
868 Force_Compilations : Boolean := False;
869 Keep_Going : Boolean := False;
870 In_Place_Mode : Boolean := False;
871 Initialize_ALI_Data : Boolean := True;
872 Max_Process : Positive := 1);
873 -- Compile_Sources will recursively compile all the sources needed by
874 -- Main_Source. Before calling this routine make sure Namet has been
875 -- initialized. This routine can be called repeatedly with different
876 -- Main_Source file as long as all the source (-I flags), library
877 -- (-B flags) and ada library (-A flags) search paths between calls are
878 -- *exactly* the same. The default directory must also be the same.
880 -- Args contains the arguments to use during the compilations.
881 -- The lower bound of Args must be 1.
883 -- First_Compiled_File is set to the name of the first file that is
884 -- compiled or that needs to be compiled. This is set to No_Name if no
885 -- compilations were needed.
887 -- Most_Recent_Obj_File is set to the full name of the most recent
888 -- object file found when no compilations are needed, that is when
889 -- First_Compiled_File is set to No_Name. When First_Compiled_File
890 -- is set then Most_Recent_Obj_File is set to No_Name.
892 -- Most_Recent_Obj_Stamp is the time stamp of Most_Recent_Obj_File.
894 -- Main_Unit is set to True if Main_Source can be a main unit.
895 -- If Do_Not_Execute is False and First_Compiled_File /= No_Name
896 -- the value of Main_Unit is always False.
897 -- Is this used any more??? It is certainly not used by gnatmake???
899 -- Compilation_Failures is a count of compilation failures. This count
900 -- is used to extract compilation failure reports with Extract_Failure.
902 -- Main_Index, when not zero, is the index of the main unit in source
903 -- file Main_Source which is a multi-unit source.
904 -- Zero indicates that Main_Source is a single unit source file.
906 -- Check_Readonly_Files set it to True to compile source files
907 -- which library files are read-only. When compiling GNAT predefined
908 -- files the "-gnatg" flag is used.
910 -- Do_Not_Execute set it to True to find out the first source that
911 -- needs to be recompiled, but without recompiling it. This file is
912 -- saved in First_Compiled_File.
914 -- Force_Compilations forces all compilations no matter what but
915 -- recompiles read-only files only if Check_Readonly_Files
918 -- Keep_Going when True keep compiling even in the presence of
919 -- compilation errors.
921 -- In_Place_Mode when True save library/object files in their object
922 -- directory if they already exist; otherwise, in the source directory.
924 -- Initialize_ALI_Data set it to True when you want to initialize ALI
925 -- data-structures. This is what you should do most of the time.
926 -- (especially the first time around when you call this routine).
927 -- This parameter is set to False to preserve previously recorded
930 -- Max_Process is the maximum number of processes that should be spawned
931 -- to carry out compilations.
933 -- Flags in Package Opt Affecting Compile_Sources
934 -- -----------------------------------------------
936 -- Check_Object_Consistency set it to False to omit all consistency
937 -- checks between an .ali file and its corresponding object file.
938 -- When this flag is set to true, every time an .ali is read,
939 -- package Osint checks that the corresponding object file
940 -- exists and is more recent than the .ali.
942 -- Use of Name Table Info
943 -- ----------------------
945 -- All file names manipulated by Compile_Sources are entered into the
946 -- Names table. The Byte field of a source file is used to mark it.
948 -- Calling Compile_Sources Several Times
949 -- -------------------------------------
951 -- Upon return from Compile_Sources all the ALI data structures are left
952 -- intact for further browsing. HOWEVER upon entry to this routine ALI
953 -- data structures are re-initialized if parameter Initialize_ALI_Data
954 -- above is set to true. Typically this is what you want the first time
955 -- you call Compile_Sources. You should not load an ali file, call this
956 -- routine with flag Initialize_ALI_Data set to True and then expect
957 -- that ALI information to be around after the call. Note that the first
958 -- time you call Compile_Sources you better set Initialize_ALI_Data to
959 -- True unless you have called Initialize_ALI yourself.
961 -- Compile_Sources ALGORITHM : Compile_Sources (Main_Source)
962 -- -------------------------
964 -- 1. Insert Main_Source in a Queue (Q) and mark it.
966 -- 2. Let unit.adb be the file at the head of the Q. If unit.adb is
967 -- missing but its corresponding ali file is in an Ada library directory
968 -- (see below) then, remove unit.adb from the Q and goto step 4.
969 -- Otherwise, look at the files under the D (dependency) section of
970 -- unit.ali. If unit.ali does not exist or some of the time stamps do
971 -- not match, (re)compile unit.adb.
973 -- An Ada library directory is a directory containing Ada specs, ali
974 -- and object files but no source files for the bodies. An Ada library
975 -- directory is communicated to gnatmake by means of some switch so that
976 -- gnatmake can skip the sources whole ali are in that directory.
977 -- There are two reasons for skipping the sources in this case. Firstly,
978 -- Ada libraries typically come without full sources but binding and
979 -- linking against those libraries is still possible. Secondly, it would
980 -- be very wasteful for gnatmake to systematically check the consistency
981 -- of every external Ada library used in a program. The binder is
982 -- already in charge of catching any potential inconsistencies.
984 -- 3. Look into the W section of unit.ali and insert into the Q all
985 -- unmarked source files. Mark all files newly inserted in the Q.
986 -- Specifically, assuming that the W section looks like
988 -- W types%s types.adb types.ali
989 -- W unchecked_deallocation%s
990 -- W xref_tab%s xref_tab.adb xref_tab.ali
992 -- Then xref_tab.adb and types.adb are inserted in the Q if they are not
994 -- Note that there is no file listed under W unchecked_deallocation%s
995 -- so no generic body should ever be explicitly compiled (unless the
996 -- Main_Source at the start was a generic body).
998 -- 4. Repeat steps 2 and 3 above until the Q is empty
1000 -- Note that the above algorithm works because the units withed in
1001 -- subunits are transitively included in the W section (with section) of
1002 -- the main unit. Likewise the withed units in a generic body needed
1003 -- during a compilation are also transitively included in the W section
1004 -- of the originally compiled file.
1006 procedure Initialize (Project_Node_Tree : out Project_Node_Tree_Ref);
1007 -- Performs default and package initialization. Therefore,
1008 -- Compile_Sources can be called by an external unit.
1011 (ALI_File : File_Name_Type;
1012 Args : Argument_List;
1013 Success : out Boolean);
1014 -- Links ALI_File. Args are the arguments to pass to the linker.
1015 -- Args must have a lower bound of 1. Success indicates if the link
1016 -- succeeded or not.
1018 procedure Scan_Make_Arg
1019 (Project_Node_Tree : Project_Node_Tree_Ref;
1021 And_Save : Boolean);
1022 -- Scan make arguments. Argv is a single argument to be processed.
1023 -- Project_Node_Tree will be used to initialize external references. It
1024 -- must have been initialized.
1030 procedure Add_Arguments (Args : Argument_List) is
1032 if Arguments = null then
1033 Arguments := new Argument_List (1 .. Args'Length + 10);
1036 while Last_Argument + Args'Length > Arguments'Last loop
1038 New_Arguments : constant Argument_List_Access :=
1039 new Argument_List (1 .. Arguments'Last * 2);
1041 New_Arguments (1 .. Last_Argument) :=
1042 Arguments (1 .. Last_Argument);
1043 Arguments := New_Arguments;
1048 Arguments (Last_Argument + 1 .. Last_Argument + Args'Length) := Args;
1049 Last_Argument := Last_Argument + Args'Length;
1052 -- --------------------
1053 -- -- Add_Dependency --
1054 -- --------------------
1056 -- procedure Add_Dependency (S : File_Name_Type; On : File_Name_Type) is
1058 -- Dependencies.Increment_Last;
1059 -- Dependencies.Table (Dependencies.Last) := (S, On);
1060 -- end Add_Dependency;
1062 ----------------------------
1063 -- Add_Library_Search_Dir --
1064 ----------------------------
1066 procedure Add_Library_Search_Dir
1068 On_Command_Line : Boolean)
1071 if On_Command_Line then
1072 Add_Lib_Search_Dir (Normalize_Pathname (Path));
1075 Get_Name_String (Main_Project.Directory.Display_Name);
1077 (Normalize_Pathname (Path, Name_Buffer (1 .. Name_Len)));
1079 end Add_Library_Search_Dir;
1081 --------------------
1082 -- Add_Object_Dir --
1083 --------------------
1085 procedure Add_Object_Dir (N : String) is
1087 Add_Lib_Search_Dir (N);
1089 if Verbose_Mode then
1090 Write_Str ("Adding object directory """);
1097 --------------------
1098 -- Add_Source_Dir --
1099 --------------------
1101 procedure Add_Source_Dir (N : String) is
1103 Add_Src_Search_Dir (N);
1105 if Verbose_Mode then
1106 Write_Str ("Adding source directory """);
1113 ---------------------------
1114 -- Add_Source_Search_Dir --
1115 ---------------------------
1117 procedure Add_Source_Search_Dir
1119 On_Command_Line : Boolean)
1122 if On_Command_Line then
1123 Add_Src_Search_Dir (Normalize_Pathname (Path));
1126 Get_Name_String (Main_Project.Directory.Display_Name);
1128 (Normalize_Pathname (Path, Name_Buffer (1 .. Name_Len)));
1130 end Add_Source_Search_Dir;
1136 procedure Add_Switch
1138 Program : Make_Program_Type;
1139 Append_Switch : Boolean := True;
1140 And_Save : Boolean := True)
1143 with package T is new Table.Table (<>);
1144 procedure Generic_Position (New_Position : out Integer);
1145 -- Generic procedure that chooses a position for S in T at the
1146 -- beginning or the end, depending on the boolean Append_Switch.
1147 -- Calling this procedure may expand the table.
1149 ----------------------
1150 -- Generic_Position --
1151 ----------------------
1153 procedure Generic_Position (New_Position : out Integer) is
1157 if Append_Switch then
1158 New_Position := Integer (T.Last);
1160 for J in reverse T.Table_Index_Type'Succ (T.First) .. T.Last loop
1161 T.Table (J) := T.Table (T.Table_Index_Type'Pred (J));
1164 New_Position := Integer (T.First);
1166 end Generic_Position;
1168 procedure Gcc_Switches_Pos is new Generic_Position (Gcc_Switches);
1169 procedure Binder_Switches_Pos is new Generic_Position (Binder_Switches);
1170 procedure Linker_Switches_Pos is new Generic_Position (Linker_Switches);
1172 procedure Saved_Gcc_Switches_Pos is new
1173 Generic_Position (Saved_Gcc_Switches);
1175 procedure Saved_Binder_Switches_Pos is new
1176 Generic_Position (Saved_Binder_Switches);
1178 procedure Saved_Linker_Switches_Pos is new
1179 Generic_Position (Saved_Linker_Switches);
1181 New_Position : Integer;
1183 -- Start of processing for Add_Switch
1189 Saved_Gcc_Switches_Pos (New_Position);
1190 Saved_Gcc_Switches.Table (New_Position) := S;
1193 Saved_Binder_Switches_Pos (New_Position);
1194 Saved_Binder_Switches.Table (New_Position) := S;
1197 Saved_Linker_Switches_Pos (New_Position);
1198 Saved_Linker_Switches.Table (New_Position) := S;
1201 raise Program_Error;
1207 Gcc_Switches_Pos (New_Position);
1208 Gcc_Switches.Table (New_Position) := S;
1211 Binder_Switches_Pos (New_Position);
1212 Binder_Switches.Table (New_Position) := S;
1215 Linker_Switches_Pos (New_Position);
1216 Linker_Switches.Table (New_Position) := S;
1219 raise Program_Error;
1224 procedure Add_Switch
1226 Program : Make_Program_Type;
1227 Append_Switch : Boolean := True;
1228 And_Save : Boolean := True)
1231 Add_Switch (S => new String'(S
),
1233 Append_Switch
=> Append_Switch
,
1234 And_Save
=> And_Save
);
1241 procedure Add_Switches
1242 (The_Package
: Package_Id
;
1245 Program
: Make_Program_Type
;
1246 Unknown_Switches_To_The_Compiler
: Boolean := True;
1247 Project_Node_Tree
: Project_Node_Tree_Ref
)
1249 Switches
: Variable_Value
;
1250 Switch_List
: String_List_Id
;
1251 Element
: String_Element
;
1254 Switch_May_Be_Passed_To_The_Compiler
:=
1255 Unknown_Switches_To_The_Compiler
;
1257 if File_Name
'Length > 0 then
1259 Add_Str_To_Name_Buffer
(File_Name
);
1262 (Source_File
=> Name_Find
,
1263 Source_File_Name
=> File_Name
,
1264 Source_Index
=> Index
,
1265 Project
=> Main_Project
,
1266 In_Package
=> The_Package
,
1267 Allow_ALI
=> Program
= Binder
or else Program
= Linker
);
1269 if Switches
.Kind
= List
then
1270 Program_Args
:= Program
;
1272 Switch_List
:= Switches
.Values
;
1273 while Switch_List
/= Nil_String
loop
1274 Element
:= Project_Tree
.String_Elements
.Table
(Switch_List
);
1275 Get_Name_String
(Element
.Value
);
1277 if Name_Len
> 0 then
1279 Argv
: constant String := Name_Buffer
(1 .. Name_Len
);
1280 -- We need a copy, because Name_Buffer may be modified
1283 if Verbose_Mode
then
1284 Write_Str
(" Adding ");
1289 (Project_Node_Tree
, Argv
, And_Save
=> False);
1291 if not Gnatmake_Switch_Found
1292 and then not Switch_May_Be_Passed_To_The_Compiler
1296 """ is not a gnatmake switch. Consider moving " &
1297 "it to Global_Compilation_Switches.",
1300 Make_Failed
("*** illegal switch """ & Argv
& """");
1305 Switch_List
:= Element
.Next
;
1315 procedure Bind
(ALI_File
: File_Name_Type
; Args
: Argument_List
) is
1316 Bind_Args
: Argument_List
(1 .. Args
'Last + 2);
1317 Bind_Last
: Integer;
1321 pragma Assert
(Args
'First = 1);
1323 -- Optimize the simple case where the gnatbind command line looks like
1324 -- gnatbind -aO. -I- file.ali --into-> gnatbind file.adb
1327 and then Args
(Args
'First).all = "-aO" & Normalized_CWD
1328 and then Args
(Args
'Last).all = "-I-"
1329 and then ALI_File
= Strip_Directory
(ALI_File
)
1331 Bind_Last
:= Args
'First - 1;
1334 Bind_Last
:= Args
'Last;
1335 Bind_Args
(Args
'Range) := Args
;
1338 -- It is completely pointless to re-check source file time stamps. This
1339 -- has been done already by gnatmake
1341 Bind_Last
:= Bind_Last
+ 1;
1342 Bind_Args
(Bind_Last
) := Do_Not_Check_Flag
;
1344 Get_Name_String
(ALI_File
);
1346 Bind_Last
:= Bind_Last
+ 1;
1347 Bind_Args
(Bind_Last
) := new String'(Name_Buffer (1 .. Name_Len));
1349 GNAT.OS_Lib.Normalize_Arguments (Bind_Args (Args'First .. Bind_Last));
1351 Display (Gnatbind.all, Bind_Args (Args'First .. Bind_Last));
1353 if Gnatbind_Path = null then
1354 Make_Failed ("error, unable to locate " & Gnatbind.all);
1358 (Gnatbind_Path.all, Bind_Args (Args'First .. Bind_Last), Success);
1361 Make_Failed ("*** bind failed.");
1365 --------------------------------
1366 -- Change_To_Object_Directory --
1367 --------------------------------
1369 procedure Change_To_Object_Directory (Project : Project_Id) is
1370 Object_Directory : Path_Name_Type;
1373 pragma Assert (Project /= No_Project);
1375 -- Nothing to do if the current working directory is already the correct
1376 -- object directory.
1378 if Project_Of_Current_Object_Directory /= Project then
1379 Project_Of_Current_Object_Directory := Project;
1380 Object_Directory := Project.Object_Directory.Name;
1382 -- Set the working directory to the object directory of the actual
1385 if Verbose_Mode then
1386 Write_Str ("Changing to object directory of """);
1387 Write_Name (Project.Display_Name);
1388 Write_Str (""": """);
1389 Write_Name (Object_Directory);
1393 Change_Dir (Get_Name_String (Object_Directory));
1397 -- Fail if unable to change to the object directory
1399 when Directory_Error =>
1400 Make_Failed ("unable to change to object directory """ &
1402 (Project.Object_Directory.Name) &
1404 Get_Name_String (Project.Display_Name));
1405 end Change_To_Object_Directory;
1412 (Source_File : File_Name_Type;
1414 Is_Main_Source : Boolean;
1415 The_Args : Argument_List;
1416 Lib_File : File_Name_Type;
1417 Read_Only : Boolean;
1419 O_File : out File_Name_Type;
1420 O_Stamp : out Time_Stamp_Type)
1422 function First_New_Spec (A : ALI_Id) return File_Name_Type;
1423 -- Looks in the with table entries of A and returns the spec file name
1424 -- of the first withed unit (subprogram) for which no spec existed when
1425 -- A was generated but for which there exists one now, implying that A
1426 -- is now obsolete. If no such unit is found No_File is returned.
1427 -- Otherwise the spec file name of the unit is returned.
1429 -- **WARNING** in the event of Uname format modifications, one *MUST*
1430 -- make sure this function is also updated.
1432 -- Note: This function should really be in ali.adb and use Uname
1433 -- services, but this causes the whole compiler to be dragged along
1434 -- for gnatbind and gnatmake.
1436 --------------------
1437 -- First_New_Spec --
1438 --------------------
1440 function First_New_Spec (A : ALI_Id) return File_Name_Type is
1441 Spec_File_Name : File_Name_Type := No_File;
1443 function New_Spec (Uname : Unit_Name_Type) return Boolean;
1444 -- Uname is the name of the spec or body of some ada unit. This
1445 -- function returns True if the Uname is the name of a body which has
1446 -- a spec not mentioned in ALI file A. If True is returned
1447 -- Spec_File_Name above is set to the name of this spec file.
1453 function New_Spec (Uname : Unit_Name_Type) return Boolean is
1454 Spec_Name : Unit_Name_Type;
1455 File_Name : File_Name_Type;
1458 -- Test whether Uname is the name of a body unit (i.e. ends
1461 Get_Name_String (Uname);
1463 Assert (Name_Len > 2 and then Name_Buffer (Name_Len - 1) = '%');
1465 if Name_Buffer (Name_Len) /= 'b
' then
1469 -- Convert unit name into spec name
1471 -- ??? this code seems dubious in presence of pragma
1472 -- Source_File_Name since there is no more direct relationship
1473 -- between unit name and file name.
1475 -- ??? Further, what about alternative subunit naming
1477 Name_Buffer (Name_Len) := 's
';
1478 Spec_Name := Name_Find;
1479 File_Name := Get_File_Name (Spec_Name, Subunit => False);
1481 -- Look if File_Name is mentioned in A's sdep list.
1482 -- If not look if the file exists. If it does return True.
1485 ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep
1487 if Sdep.Table (D).Sfile = File_Name then
1492 if Full_Source_Name (File_Name) /= No_File then
1493 Spec_File_Name := File_Name;
1500 -- Start of processing for First_New_Spec
1504 ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit
1506 exit U_Chk when Units.Table (U).Utype = Is_Body_Only
1507 and then New_Spec (Units.Table (U).Uname);
1509 for W in Units.Table (U).First_With
1511 Units.Table (U).Last_With
1514 Withs.Table (W).Afile /= No_File
1515 and then New_Spec (Withs.Table (W).Uname);
1519 return Spec_File_Name;
1522 ---------------------------------
1523 -- Data declarations for Check --
1524 ---------------------------------
1526 Full_Lib_File : File_Name_Type;
1527 -- Full name of current library file
1529 Full_Obj_File : File_Name_Type;
1530 -- Full name of the object file corresponding to Lib_File
1532 Lib_Stamp : Time_Stamp_Type;
1533 -- Time stamp of the current ada library file
1535 Obj_Stamp : Time_Stamp_Type;
1536 -- Time stamp of the current object file
1538 Modified_Source : File_Name_Type;
1539 -- The first source in Lib_File whose current time stamp differs
1540 -- from that stored in Lib_File.
1542 New_Spec : File_Name_Type;
1543 -- If Lib_File contains in its W (with) section a body (for a
1544 -- subprogram) for which there exists a spec and the spec did not
1545 -- appear in the Sdep section of Lib_File, New_Spec contains the file
1546 -- name of this new spec.
1548 Source_Name : File_Name_Type;
1549 Text : Text_Buffer_Ptr;
1551 Prev_Switch : String_Access;
1552 -- Previous switch processed
1554 Arg : Arg_Id := Arg_Id'First;
1555 -- Current index in Args.Table for a given unit (init to stop warning)
1557 Switch_Found : Boolean;
1558 -- True if a given switch has been found
1560 ALI_Project : Project_Id;
1561 -- If the ALI file is in the object directory of a project, this is
1564 -- Start of processing for Check
1567 pragma Assert (Lib_File /= No_File);
1569 -- If ALI file is read-only, temporarily set Check_Object_Consistency to
1570 -- False. We don't care if the object file is not there (presumably a
1571 -- library will be used for linking.)
1575 Saved_Check_Object_Consistency : constant Boolean :=
1576 Check_Object_Consistency;
1578 Check_Object_Consistency := False;
1579 Text := Read_Library_Info (Lib_File);
1580 Check_Object_Consistency := Saved_Check_Object_Consistency;
1584 Text := Read_Library_Info (Lib_File);
1587 Full_Lib_File := Full_Library_Info_Name;
1588 Full_Obj_File := Full_Object_File_Name;
1589 Lib_Stamp := Current_Library_File_Stamp;
1590 Obj_Stamp := Current_Object_File_Stamp;
1592 if Full_Lib_File = No_File then
1595 "being checked ...",
1597 Minimum_Verbosity => Opt.Medium);
1601 "being checked ...",
1603 Minimum_Verbosity => Opt.Medium);
1607 O_File := Full_Obj_File;
1608 O_Stamp := Obj_Stamp;
1611 if Full_Lib_File = No_File then
1612 Verbose_Msg (Lib_File, "missing.");
1614 elsif Obj_Stamp (Obj_Stamp'First) = ' ' then
1615 Verbose_Msg (Full_Obj_File, "missing.");
1619 (Full_Lib_File, "(" & String (Lib_Stamp) & ") newer than",
1620 Full_Obj_File, "(" & String (Obj_Stamp) & ")");
1624 ALI := Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
1627 if ALI = No_ALI_Id then
1628 Verbose_Msg (Full_Lib_File, "incorrectly formatted ALI file");
1631 elsif ALIs.Table (ALI).Ver (1 .. ALIs.Table (ALI).Ver_Len) /=
1632 Verbose_Library_Version
1634 Verbose_Msg (Full_Lib_File, "compiled with old GNAT version");
1639 -- Don't take Ali file into account if it was generated with
1642 if ALIs.Table (ALI).Compile_Errors then
1643 Verbose_Msg (Full_Lib_File, "had errors, must be recompiled");
1648 -- Don't take Ali file into account if it was generated without
1651 if Operating_Mode /= Check_Semantics
1652 and then ALIs.Table (ALI).No_Object
1654 Verbose_Msg (Full_Lib_File, "has no corresponding object");
1659 -- Check for matching compiler switches if needed
1661 if Check_Switches then
1663 -- First, collect all the switches
1666 (Source_File, Source_Index, Is_Main_Source, The_Args);
1668 Prev_Switch := Dummy_Switch;
1670 Get_Name_String (ALIs.Table (ALI).Sfile);
1672 Switches_To_Check.Set_Last (0);
1674 for J in 1 .. Last_Argument loop
1676 -- Skip non switches -c, -I and -o switches
1678 if Arguments (J) (1) = '-'
1679 and then Arguments (J) (2) /= 'c
'
1680 and then Arguments (J) (2) /= 'o
'
1681 and then Arguments (J) (2) /= 'I
'
1683 Normalize_Compiler_Switches
1685 Normalized_Switches,
1688 for K in 1 .. Last_Norm_Switch loop
1689 Switches_To_Check.Increment_Last;
1690 Switches_To_Check.Table (Switches_To_Check.Last) :=
1691 Normalized_Switches (K);
1696 for J in 1 .. Switches_To_Check.Last loop
1698 -- Comparing switches is delicate because gcc reorders a number
1699 -- of switches, according to lang-specs.h, but gnatmake doesn't
1700 -- have sufficient knowledge to perform the same reordering.
1701 -- Instead, we ignore orders between different "first letter"
1702 -- switches, but keep orders between same switches, e.g -O -O2
1703 -- is different than -O2 -O, but -g -O is equivalent to -O -g.
1705 if Switches_To_Check.Table (J) (2) /= Prev_Switch (2) or else
1706 (Prev_Switch'Length >= 6 and then
1707 Prev_Switch (2 .. 5) = "gnat" and then
1708 Switches_To_Check.Table (J)'Length >= 6 and then
1709 Switches_To_Check.Table (J) (2 .. 5) = "gnat" and then
1710 Prev_Switch (6) /= Switches_To_Check.Table (J) (6))
1712 Prev_Switch := Switches_To_Check.Table (J);
1714 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg;
1717 Switch_Found := False;
1720 Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1723 Switches_To_Check.Table (J).all = Args.Table (K).all
1726 Switch_Found := True;
1731 if not Switch_Found then
1732 if Verbose_Mode then
1733 Verbose_Msg (ALIs.Table (ALI).Sfile,
1734 "switch mismatch """ &
1735 Switches_To_Check.Table (J).all & '"');
1743 if Switches_To_Check.Last /=
1744 Integer (Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg -
1745 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg + 1)
1747 if Verbose_Mode then
1748 Verbose_Msg (ALIs.Table (ALI).Sfile,
1749 "different number
of switches
");
1751 for K in Units.Table (ALIs.Table (ALI).First_Unit).First_Arg
1752 .. Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1754 Write_Str (Args.Table (K).all);
1760 for J in 1 .. Switches_To_Check.Last loop
1761 Write_Str (Switches_To_Check.Table (J).all);
1773 -- Get the source files and their message digests. Note that some
1774 -- sources may be missing if ALI is out-of-date.
1776 Set_Source_Table (ALI);
1778 Modified_Source := Time_Stamp_Mismatch (ALI, Read_Only);
1780 if Modified_Source /= No_File then
1783 if Verbose_Mode then
1784 Source_Name := Full_Source_Name (Modified_Source);
1786 if Source_Name /= No_File then
1787 Verbose_Msg (Source_Name, "time stamp mismatch
");
1789 Verbose_Msg (Modified_Source, "missing
");
1794 New_Spec := First_New_Spec (ALI);
1796 if New_Spec /= No_File then
1799 if Verbose_Mode then
1800 Source_Name := Full_Source_Name (New_Spec);
1802 if Source_Name /= No_File then
1803 Verbose_Msg (Source_Name, "new spec
");
1805 Verbose_Msg (New_Spec, "old spec missing
");
1809 elsif not Read_Only and then Main_Project /= No_Project then
1811 if not Check_Source_Info_In_ALI (ALI) then
1816 -- Check that the ALI file is in the correct object directory.
1817 -- If it is in the object directory of a project that is
1818 -- extended and it depends on a source that is in one of its
1819 -- extending projects, then the ALI file is not in the correct
1820 -- object directory.
1822 -- First, find the project of this ALI file. As there may be
1823 -- several projects with the same object directory, we first
1824 -- need to find the project of the source.
1826 ALI_Project := No_Project;
1829 Udata : Prj.Unit_Index;
1832 Udata := Units_Htable.Get_First (Project_Tree.Units_HT);
1833 while Udata /= No_Unit_Index loop
1834 if Udata.File_Names (Impl) /= null
1835 and then Udata.File_Names (Impl).File = Source_File
1837 ALI_Project := Udata.File_Names (Impl).Project;
1840 elsif Udata.File_Names (Spec) /= null
1841 and then Udata.File_Names (Spec).File = Source_File
1843 ALI_Project := Udata.File_Names (Spec).Project;
1847 Udata := Units_Htable.Get_Next (Project_Tree.Units_HT);
1851 if ALI_Project = No_Project then
1856 Obj_Dir : Path_Name_Type;
1857 Res_Obj_Dir : constant String :=
1860 (Get_Name_String (Full_Lib_File)),
1861 Resolve_Links => True,
1862 Case_Sensitive => False);
1866 Add_Str_To_Name_Buffer (Res_Obj_Dir);
1868 if not Is_Directory_Separator (Name_Buffer (Name_Len)) then
1869 Add_Char_To_Name_Buffer (Directory_Separator);
1872 Obj_Dir := Name_Find;
1874 while ALI_Project /= No_Project
1875 and then Obj_Dir /= ALI_Project.Object_Directory.Name
1877 ALI_Project := ALI_Project.Extended_By;
1881 if ALI_Project = No_Project then
1885 (Lib_File, " wrong object directory
");
1889 -- If the ALI project is not extended, then it must be in
1890 -- the correct object directory.
1892 if ALI_Project.Extended_By = No_Project then
1896 -- Count the extending projects
1904 Proj := ALI_Project;
1906 Proj := Proj.Extended_By;
1907 exit when Proj = No_Project;
1908 Num_Ext := Num_Ext + 1;
1911 -- Make a list of the extending projects
1914 Projects : array (1 .. Num_Ext) of Project_Id;
1916 OK : Boolean := True;
1920 Proj := ALI_Project;
1921 for J in Projects'Range loop
1922 Proj := Proj.Extended_By;
1923 Projects (J) := Proj;
1926 -- Now check if any of the dependant sources are in
1927 -- any of these extending projects.
1930 for D in ALIs.Table (ALI).First_Sdep ..
1931 ALIs.Table (ALI).Last_Sdep
1933 Dep := Sdep.Table (D);
1934 UID := Units_Htable.Get_First (Project_Tree.Units_HT);
1938 while UID /= null loop
1939 if UID.File_Names (Impl) /= null
1940 and then UID.File_Names (Impl).File = Dep.Sfile
1942 Proj := UID.File_Names (Impl).Project;
1944 elsif UID.File_Names (Spec) /= null
1945 and then UID.File_Names (Spec).File = Dep.Sfile
1947 Proj := UID.File_Names (Spec).Project;
1950 -- If a source is in a project, check if it is one
1953 if Proj /= No_Project then
1954 for J in Projects'Range loop
1955 if Proj = Projects (J) then
1965 Units_Htable.Get_Next (Project_Tree.Units_HT);
1969 -- If one of the dependent sources is in one project of
1970 -- the list, then we must recompile.
1974 Verbose_Msg (Lib_File, " wrong object directory
");
1983 ------------------------
1984 -- Check_For_S_Switch --
1985 ------------------------
1987 procedure Check_For_S_Switch is
1989 -- By default, we generate an object file
1991 Output_Is_Object := True;
1993 for Arg in 1 .. Last_Argument loop
1994 if Arguments (Arg).all = "-S
" then
1995 Output_Is_Object := False;
1997 elsif Arguments (Arg).all = "-c
" then
1998 Output_Is_Object := True;
2001 end Check_For_S_Switch;
2003 --------------------------
2004 -- Check_Linker_Options --
2005 --------------------------
2007 procedure Check_Linker_Options
2008 (E_Stamp : Time_Stamp_Type;
2009 O_File : out File_Name_Type;
2010 O_Stamp : out Time_Stamp_Type)
2012 procedure Check_File (File : File_Name_Type);
2013 -- Update O_File and O_Stamp if the given file is younger than E_Stamp
2014 -- and O_Stamp, or if O_File is No_File and File does not exist.
2016 function Get_Library_File (Name : String) return File_Name_Type;
2017 -- Return the full file name including path of a library based
2018 -- on the name specified with the -l linker option, using the
2019 -- Ada object path. Return No_File if no such file can be found.
2021 type Char_Array is array (Natural) of Character;
2022 type Char_Array_Access is access constant Char_Array;
2024 Template : Char_Array_Access;
2025 pragma Import (C, Template, "__gnat_library_template
");
2031 procedure Check_File (File : File_Name_Type) is
2032 Stamp : Time_Stamp_Type;
2033 Name : File_Name_Type := File;
2036 Get_Name_String (Name);
2038 -- Remove any trailing NUL characters
2040 while Name_Len >= Name_Buffer'First
2041 and then Name_Buffer (Name_Len) = NUL
2043 Name_Len := Name_Len - 1;
2046 if Name_Len = 0 then
2049 elsif Name_Buffer (1) = '-' then
2051 -- Do not check if File is a switch other than "-l
"
2053 if Name_Buffer (2) /= 'l' then
2057 -- The argument is a library switch, get actual name. It
2058 -- is necessary to make a copy of the relevant part of
2059 -- Name_Buffer as Get_Library_Name uses Name_Buffer as well.
2062 Base_Name : constant String := Name_Buffer (3 .. Name_Len);
2065 Name := Get_Library_File (Base_Name);
2068 if Name = No_File then
2073 Stamp := File_Stamp (Name);
2075 -- Find the youngest object file that is younger than the
2076 -- executable. If no such file exist, record the first object
2077 -- file that is not found.
2079 if (O_Stamp < Stamp and then E_Stamp < Stamp)
2080 or else (O_File = No_File and then Stamp (Stamp'First) = ' ')
2085 -- Strip the trailing NUL if present
2087 Get_Name_String (O_File);
2089 if Name_Buffer (Name_Len) = NUL then
2090 Name_Len := Name_Len - 1;
2091 O_File := Name_Find;
2096 ----------------------
2097 -- Get_Library_Name --
2098 ----------------------
2100 -- See comments in a-adaint.c about template syntax
2102 function Get_Library_File (Name : String) return File_Name_Type is
2103 File : File_Name_Type := No_File;
2108 for Ptr in Template'Range loop
2109 case Template (Ptr) is
2111 Add_Str_To_Name_Buffer (Name);
2114 File := Full_Lib_File_Name (Name_Find);
2115 exit when File /= No_File;
2122 Add_Char_To_Name_Buffer (Template (Ptr));
2126 -- The for loop exited because the end of the template
2127 -- was reached. File contains the last possible file name
2130 if File = No_File and then Name_Len > 0 then
2131 File := Full_Lib_File_Name (Name_Find);
2135 end Get_Library_File;
2137 -- Start of processing for Check_Linker_Options
2141 O_Stamp := (others => ' ');
2143 -- Process linker options from the ALI files
2145 for Opt in 1 .. Linker_Options.Last loop
2146 Check_File (File_Name_Type (Linker_Options.Table (Opt).Name));
2149 -- Process options given on the command line
2151 for Opt in Linker_Switches.First .. Linker_Switches.Last loop
2153 -- Check if the previous Opt has one of the two switches
2154 -- that take an extra parameter. (See GCC manual.)
2156 if Opt = Linker_Switches.First
2157 or else (Linker_Switches.Table (Opt - 1).all /= "-u
"
2159 Linker_Switches.Table (Opt - 1).all /= "-Xlinker
"
2161 Linker_Switches.Table (Opt - 1).all /= "-L
")
2164 Add_Str_To_Name_Buffer (Linker_Switches.Table (Opt).all);
2165 Check_File (Name_Find);
2169 end Check_Linker_Options;
2175 procedure Check_Steps is
2177 -- If either -c, -b or -l has been specified, we will not necessarily
2178 -- execute all steps.
2181 Do_Compile_Step := Do_Compile_Step and Compile_Only;
2182 Do_Bind_Step := Do_Bind_Step and Bind_Only;
2183 Do_Link_Step := Do_Link_Step and Link_Only;
2185 -- If -c has been specified, but not -b, ignore any potential -l
2187 if Do_Compile_Step and then not Do_Bind_Step then
2188 Do_Link_Step := False;
2193 -----------------------
2194 -- Collect_Arguments --
2195 -----------------------
2197 procedure Collect_Arguments
2198 (Source_File : File_Name_Type;
2200 Is_Main_Source : Boolean;
2201 Args : Argument_List)
2204 Arguments_Project := No_Project;
2206 Add_Arguments (Args);
2208 if Main_Project /= No_Project then
2210 Source_File_Name : constant String :=
2211 Get_Name_String (Source_File);
2212 Compiler_Package : Prj.Package_Id;
2213 Switches : Prj.Variable_Value;
2218 (Source_File_Name => Source_File_Name,
2219 Project => Arguments_Project,
2220 Path => Arguments_Path_Name,
2221 In_Tree => Project_Tree);
2223 -- If the source is not a source of a project file, add the
2224 -- recorded arguments. Check will be done later if the source
2225 -- need to be compiled that the switch -x has been used.
2227 if Arguments_Project = No_Project then
2228 Add_Arguments (The_Saved_Gcc_Switches.all);
2230 elsif not Arguments_Project.Externally_Built then
2231 -- We get the project directory for the relative path
2232 -- switches and arguments.
2234 Arguments_Project := Ultimate_Extending_Project_Of
2235 (Arguments_Project);
2237 -- If building a dynamic or relocatable library, compile with
2238 -- PIC option, if it exists.
2240 if Arguments_Project.Library
2241 and then Arguments_Project.Library_Kind /= Static
2244 PIC : constant String := MLib.Tgt.PIC_Option;
2248 Add_Arguments ((1 => new String'(PIC)));
2253 -- We now look for package Compiler and get the switches from
2258 (Name => Name_Compiler,
2259 In_Packages => Arguments_Project.Decl.Packages,
2260 In_Tree => Project_Tree);
2262 if Compiler_Package /= No_Package then
2264 -- If package Gnatmake.Compiler exists, we get the specific
2265 -- switches for the current source, or the global switches,
2270 (Source_File => Source_File,
2271 Source_File_Name => Source_File_Name,
2272 Source_Index => Source_Index,
2273 Project => Arguments_Project,
2274 In_Package => Compiler_Package,
2275 Allow_ALI => False);
2279 case Switches.Kind is
2281 -- We have a list of switches. We add these switches,
2282 -- plus the saved gcc switches.
2287 Current : String_List_Id := Switches.Values;
2288 Element : String_Element;
2289 Number : Natural := 0;
2292 while Current /= Nil_String loop
2293 Element := Project_Tree.String_Elements.
2295 Number := Number + 1;
2296 Current := Element.Next;
2300 New_Args : Argument_List (1 .. Number);
2301 Last_New : Natural := 0;
2302 Dir_Path : constant String := Get_Name_String
2303 (Arguments_Project.Directory.Name);
2306 Current := Switches.Values;
2308 for Index in New_Args'Range loop
2309 Element := Project_Tree.String_Elements.
2311 Get_Name_String (Element.Value);
2313 if Name_Len > 0 then
2314 Last_New := Last_New + 1;
2315 New_Args (Last_New) :=
2316 new String'(Name_Buffer (1 .. Name_Len));
2317 Test_If_Relative_Path
2318 (New_Args (Last_New),
2320 Including_Non_Switch => False);
2323 Current := Element.Next;
2327 (Configuration_Pragmas_Switch
2328 (Arguments_Project) &
2329 New_Args (1 .. Last_New) &
2330 The_Saved_Gcc_Switches.all);
2334 -- We have a single switch. We add this switch,
2335 -- plus the saved gcc switches.
2338 Get_Name_String (Switches.Value);
2341 New_Args : Argument_List :=
2343 (Name_Buffer (1 .. Name_Len)));
2344 Dir_Path : constant String :=
2346 (Arguments_Project.Directory.Name);
2349 Test_If_Relative_Path
2352 Including_Non_Switch => False);
2354 (Configuration_Pragmas_Switch (Arguments_Project) &
2355 New_Args & The_Saved_Gcc_Switches.all);
2358 -- We have no switches from Gnatmake.Compiler.
2359 -- We add the saved gcc switches.
2363 (Configuration_Pragmas_Switch (Arguments_Project) &
2364 The_Saved_Gcc_Switches.all);
2370 -- For VMS, when compiling the main source, add switch
2371 -- -mdebug-main=_ada_ so that the executable can be debugged
2372 -- by the standard VMS debugger.
2374 if not No_Main_Subprogram
2375 and then Targparm.OpenVMS_On_Target
2376 and then Is_Main_Source
2378 -- First, check if compilation will be invoked with -g
2380 for J in 1 .. Last_Argument loop
2381 if Arguments (J)'Length >= 2
2382 and then Arguments (J) (1 .. 2) = "-g
"
2383 and then (Arguments (J)'Length < 5
2384 or else Arguments (J) (1 .. 5) /= "-gnat
")
2387 ((1 => new String'("-mdebug
-main
=_ada_
")));
2393 -- Set Output_Is_Object, depending if there is a -S switch.
2394 -- If the bind step is not performed, and there is a -S switch,
2395 -- then we will not check for a valid object file.
2398 end Collect_Arguments;
2400 ---------------------
2401 -- Compile_Sources --
2402 ---------------------
2404 procedure Compile_Sources
2405 (Main_Source : File_Name_Type;
2406 Args : Argument_List;
2407 First_Compiled_File : out File_Name_Type;
2408 Most_Recent_Obj_File : out File_Name_Type;
2409 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
2410 Main_Unit : out Boolean;
2411 Compilation_Failures : out Natural;
2412 Main_Index : Int := 0;
2413 Check_Readonly_Files : Boolean := False;
2414 Do_Not_Execute : Boolean := False;
2415 Force_Compilations : Boolean := False;
2416 Keep_Going : Boolean := False;
2417 In_Place_Mode : Boolean := False;
2418 Initialize_ALI_Data : Boolean := True;
2419 Max_Process : Positive := 1)
2421 Source_Unit : Unit_Name_Type;
2422 -- Current source unit
2424 Source_File : File_Name_Type;
2425 -- Current source file
2427 Full_Source_File : File_Name_Type;
2428 -- Full name of the current source file
2430 Lib_File : File_Name_Type;
2431 -- Current library file
2433 Full_Lib_File : File_Name_Type;
2434 -- Full name of the current library file
2436 Obj_File : File_Name_Type;
2437 -- Full name of the object file corresponding to Lib_File
2439 Obj_Stamp : Time_Stamp_Type;
2440 -- Time stamp of the current object file
2442 Sfile : File_Name_Type;
2443 -- Contains the source file of the units withed by Source_File
2445 Uname : Unit_Name_Type;
2446 -- Contains the unit name of the units withed by Source_File
2449 -- ALI Id of the current ALI file
2451 -- Comment following declarations ???
2453 Read_Only : Boolean := False;
2455 Compilation_OK : Boolean;
2456 Need_To_Compile : Boolean;
2459 Text : Text_Buffer_Ptr;
2461 Mfile : Natural := No_Mapping_File;
2463 Need_To_Check_Standard_Library : Boolean :=
2464 Check_Readonly_Files
2465 and not Unique_Compile;
2467 Mapping_File_Arg : String_Access;
2469 Process_Created : Boolean := False;
2471 procedure Add_Process
2473 Sfile : File_Name_Type;
2474 Afile : File_Name_Type;
2475 Uname : Unit_Name_Type;
2476 Mfile : Natural := No_Mapping_File);
2477 -- Adds process Pid to the current list of outstanding compilation
2478 -- processes and record the full name of the source file Sfile that
2479 -- we are compiling, the name of its library file Afile and the
2480 -- name of its unit Uname. If Mfile is not equal to No_Mapping_File,
2481 -- it is the index of the mapping file used during compilation in the
2482 -- array The_Mapping_File_Names.
2484 procedure Await_Compile
2485 (Sfile : out File_Name_Type;
2486 Afile : out File_Name_Type;
2487 Uname : out Unit_Name_Type;
2489 -- Awaits that an outstanding compilation process terminates. When
2490 -- it does set Sfile to the name of the source file that was compiled
2491 -- Afile to the name of its library file and Uname to the name of its
2492 -- unit. Note that this time stamp can be used to check whether the
2493 -- compilation did generate an object file. OK is set to True if the
2494 -- compilation succeeded. Note that Sfile, Afile and Uname could be
2495 -- resp. No_File, No_File and No_Name if there were no compilations
2498 function Bad_Compilation_Count return Natural;
2499 -- Returns the number of compilation failures
2501 procedure Check_Standard_Library;
2502 -- Check if s-stalib.adb needs to be compiled
2504 procedure Collect_Arguments_And_Compile (Source_Index : Int);
2505 -- Collect arguments from project file (if any) and compile
2508 (Project : Project_Id;
2512 Args : Argument_List) return Process_Id;
2513 -- Compiles S using Args. If S is a GNAT predefined source "-gnatpg
" is
2514 -- added to Args. Non blocking call. L corresponds to the expected
2515 -- library file name. Process_Id of the process spawned to execute the
2518 package Good_ALI is new Table.Table (
2519 Table_Component_Type => ALI_Id,
2520 Table_Index_Type => Natural,
2521 Table_Low_Bound => 1,
2522 Table_Initial => 50,
2523 Table_Increment => 100,
2524 Table_Name => "Make
.Good_ALI
");
2525 -- Contains the set of valid ALI files that have not yet been scanned
2527 function Good_ALI_Present return Boolean;
2528 -- Returns True if any ALI file was recorded in the previous set
2530 procedure Get_Mapping_File (Project : Project_Id);
2531 -- Get a mapping file name. If there is one to be reused, reuse it.
2532 -- Otherwise, create a new mapping file.
2534 function Get_Next_Good_ALI return ALI_Id;
2535 -- Returns the next good ALI_Id record
2537 procedure Record_Failure
2538 (File : File_Name_Type;
2539 Unit : Unit_Name_Type;
2540 Found : Boolean := True);
2541 -- Records in the previous table that the compilation for File failed.
2542 -- If Found is False then the compilation of File failed because we
2543 -- could not find it. Records also Unit when possible.
2545 procedure Record_Good_ALI (A : ALI_Id);
2546 -- Records in the previous set the Id of an ALI file
2552 procedure Add_Process
2554 Sfile : File_Name_Type;
2555 Afile : File_Name_Type;
2556 Uname : Unit_Name_Type;
2557 Mfile : Natural := No_Mapping_File)
2559 OC1 : constant Positive := Outstanding_Compiles + 1;
2562 pragma Assert (OC1 <= Max_Process);
2563 pragma Assert (Pid /= Invalid_Pid);
2565 Running_Compile (OC1).Pid := Pid;
2566 Running_Compile (OC1).Full_Source_File := Sfile;
2567 Running_Compile (OC1).Lib_File := Afile;
2568 Running_Compile (OC1).Source_Unit := Uname;
2569 Running_Compile (OC1).Mapping_File := Mfile;
2570 Running_Compile (OC1).Project := Arguments_Project;
2571 Running_Compile (OC1).Syntax_Only := Syntax_Only;
2572 Running_Compile (OC1).Output_Is_Object := Output_Is_Object;
2574 Outstanding_Compiles := OC1;
2577 --------------------
2581 procedure Await_Compile
2582 (Sfile : out File_Name_Type;
2583 Afile : out File_Name_Type;
2584 Uname : out Unit_Name_Type;
2588 Project : Project_Id;
2589 Data : Project_Compilation_Access;
2592 pragma Assert (Outstanding_Compiles > 0);
2596 Uname := No_Unit_Name;
2599 -- The loop here is a work-around for a problem on VMS; in some
2600 -- circumstances (shared library and several executables, for
2601 -- example), there are child processes other than compilation
2602 -- processes that are received. Until this problem is resolved,
2603 -- we will ignore such processes.
2606 Wait_Process (Pid, OK);
2608 if Pid = Invalid_Pid then
2612 for J in Running_Compile'First .. Outstanding_Compiles loop
2613 if Pid = Running_Compile (J).Pid then
2614 Sfile := Running_Compile (J).Full_Source_File;
2615 Afile := Running_Compile (J).Lib_File;
2616 Uname := Running_Compile (J).Source_Unit;
2617 Syntax_Only := Running_Compile (J).Syntax_Only;
2618 Output_Is_Object := Running_Compile (J).Output_Is_Object;
2619 Project := Running_Compile (J).Project;
2621 -- If a mapping file was used by this compilation,
2622 -- get its file name for reuse by a subsequent compilation
2624 if Running_Compile (J).Mapping_File /= No_Mapping_File then
2625 Data := Project_Compilation_Htable.Get
2626 (Project_Compilation, Project);
2627 Data.Last_Free_Indices := Data.Last_Free_Indices + 1;
2628 Data.Free_Mapping_File_Indices (Data.Last_Free_Indices) :=
2629 Running_Compile (J).Mapping_File;
2632 -- To actually remove this Pid and related info from
2633 -- Running_Compile replace its entry with the last valid
2634 -- entry in Running_Compile.
2636 if J = Outstanding_Compiles then
2640 Running_Compile (J) :=
2641 Running_Compile (Outstanding_Compiles);
2644 Outstanding_Compiles := Outstanding_Compiles - 1;
2649 -- This child process was not one of our compilation processes;
2650 -- just ignore it for now.
2652 -- raise Program_Error;
2656 ---------------------------
2657 -- Bad_Compilation_Count --
2658 ---------------------------
2660 function Bad_Compilation_Count return Natural is
2662 return Bad_Compilation.Last - Bad_Compilation.First + 1;
2663 end Bad_Compilation_Count;
2665 ----------------------------
2666 -- Check_Standard_Library --
2667 ----------------------------
2669 procedure Check_Standard_Library is
2671 Need_To_Check_Standard_Library := False;
2673 if not Targparm.Suppress_Standard_Library_On_Target then
2675 Sfile : File_Name_Type;
2676 Add_It : Boolean := True;
2680 Add_Str_To_Name_Buffer (Standard_Library_Package_Body_Name);
2681 Sfile := Name_Enter;
2683 -- If we have a special runtime, we add the standard
2684 -- library only if we can find it.
2688 Find_File (Sfile, Osint.Source) /= No_File;
2692 if Is_Marked (Sfile) then
2693 if Is_In_Obsoleted (Sfile) then
2694 Executable_Obsolete := True;
2698 Insert_Q (Sfile, Index => 0);
2699 Mark (Sfile, Index => 0);
2704 end Check_Standard_Library;
2706 -----------------------------------
2707 -- Collect_Arguments_And_Compile --
2708 -----------------------------------
2710 procedure Collect_Arguments_And_Compile (Source_Index : Int) is
2712 -- Process_Created will be set True if an attempt is made to compile
2713 -- the source, that is if it is not in an externally built project.
2715 Process_Created := False;
2717 -- If we use mapping file (-P or -C switches), then get one
2719 if Create_Mapping_File then
2720 Get_Mapping_File (Arguments_Project);
2723 -- If the source is part of a project file, we set the ADA_*_PATHs,
2724 -- check for an eventual library project, and use the full path.
2726 if Arguments_Project /= No_Project then
2727 if not Arguments_Project.Externally_Built then
2728 Prj.Env.Set_Ada_Paths
2731 Including_Libraries => True);
2733 if not Unique_Compile
2734 and then MLib.Tgt.Support_For_Libraries /= Prj.None
2737 Prj : constant Project_Id :=
2738 Ultimate_Extending_Project_Of (Arguments_Project);
2742 and then not Prj.Externally_Built
2743 and then not Prj.Need_To_Build_Lib
2745 -- Add to the Q all sources of the project that have
2748 Insert_Project_Sources
2749 (The_Project => Prj,
2750 All_Projects => False,
2753 -- Now mark the project as processed
2755 Prj.Need_To_Build_Lib := True;
2763 File_Name_Type (Arguments_Path_Name),
2766 Arguments (1 .. Last_Argument));
2767 Process_Created := True;
2771 -- If this is a source outside of any project file, make sure it
2772 -- will be compiled in object directory of the main project file.
2780 Arguments (1 .. Last_Argument));
2781 Process_Created := True;
2783 end Collect_Arguments_And_Compile;
2790 (Project : Project_Id;
2794 Args : Argument_List) return Process_Id
2796 Comp_Args : Argument_List (Args'First .. Args'Last + 10);
2797 Comp_Next : Integer := Args'First;
2798 Comp_Last : Integer;
2799 Arg_Index : Integer;
2801 function Ada_File_Name (Name : File_Name_Type) return Boolean;
2802 -- Returns True if Name is the name of an ada source file
2803 -- (i.e. suffix is .ads or .adb)
2809 function Ada_File_Name (Name : File_Name_Type) return Boolean is
2811 Get_Name_String (Name);
2814 and then Name_Buffer (Name_Len - 3 .. Name_Len - 1) = ".ad
"
2815 and then (Name_Buffer (Name_Len) = 'b'
2817 Name_Buffer (Name_Len) = 's');
2820 -- Start of processing for Compile
2823 Enter_Into_Obsoleted (S);
2825 -- By default, Syntax_Only is False
2827 Syntax_Only := False;
2829 for J in Args'Range loop
2830 if Args (J).all = "-gnats
" then
2832 -- If we compile with -gnats, the bind step and the link step
2833 -- are inhibited. Also, we set Syntax_Only to True, so that
2834 -- we don't fail when we don't find the ALI file, after
2837 Do_Bind_Step := False;
2838 Do_Link_Step := False;
2839 Syntax_Only := True;
2841 elsif Args (J).all = "-gnatc
" then
2843 -- If we compile with -gnatc, the bind step and the link step
2844 -- are inhibited. We set Syntax_Only to False for the case when
2845 -- -gnats was previously specified.
2847 Do_Bind_Step := False;
2848 Do_Link_Step := False;
2849 Syntax_Only := False;
2853 Comp_Args (Comp_Next) := new String'("-gnatea
");
2854 Comp_Next := Comp_Next + 1;
2856 Comp_Args (Comp_Next) := Comp_Flag;
2857 Comp_Next := Comp_Next + 1;
2859 -- Optimize the simple case where the gcc command line looks like
2860 -- gcc -c -I. ... -I- file.adb
2862 -- gcc -c ... file.adb
2864 if Args (Args'First).all = "-I
" & Normalized_CWD
2865 and then Args (Args'Last).all = "-I
-"
2866 and then S = Strip_Directory (S)
2868 Comp_Last := Comp_Next + Args'Length - 3;
2869 Arg_Index := Args'First + 1;
2872 Comp_Last := Comp_Next + Args'Length - 1;
2873 Arg_Index := Args'First;
2876 -- Make a deep copy of the arguments, because Normalize_Arguments
2877 -- may deallocate some arguments.
2879 for J in Comp_Next .. Comp_Last loop
2880 Comp_Args (J) := new String'(Args (Arg_Index).all);
2881 Arg_Index := Arg_Index + 1;
2884 -- Set -gnatpg for predefined files (for this purpose the renamings
2885 -- such as Text_IO do not count as predefined). Note that we strip
2886 -- the directory name from the source file name because the call to
2887 -- Fname.Is_Predefined_File_Name cannot deal with directory prefixes.
2890 Fname : constant File_Name_Type := Strip_Directory (S);
2893 if Is_Predefined_File_Name (Fname, False) then
2894 if Check_Readonly_Files then
2895 Comp_Args (Comp_Args'First + 2 .. Comp_Last + 1) :=
2896 Comp_Args (Comp_Args'First + 1 .. Comp_Last);
2897 Comp_Last := Comp_Last + 1;
2898 Comp_Args (Comp_Args'First + 1) := GNAT_Flag;
2902 ("not allowed to compile
""" &
2903 Get_Name_String (Fname) &
2904 """; use -a switch
, or compile file
with " &
2905 """-gnatg
"" switch
");
2910 -- Now check if the file name has one of the suffixes familiar to
2911 -- the gcc driver. If this is not the case then add the ada flag
2914 if not Ada_File_Name (S) and then not Targparm.AAMP_On_Target then
2915 Comp_Last := Comp_Last + 1;
2916 Comp_Args (Comp_Last) := Ada_Flag_1;
2917 Comp_Last := Comp_Last + 1;
2918 Comp_Args (Comp_Last) := Ada_Flag_2;
2921 if Source_Index /= 0 then
2923 Num : constant String := Source_Index'Img;
2925 Comp_Last := Comp_Last + 1;
2926 Comp_Args (Comp_Last) :=
2927 new String'("-gnateI
" & Num (Num'First + 1 .. Num'Last));
2931 if Source_Index /= 0
2932 or else L /= Strip_Directory (L)
2933 or else Object_Directory_Path /= null
2935 -- Build -o argument
2937 Get_Name_String (L);
2939 for J in reverse 1 .. Name_Len loop
2940 if Name_Buffer (J) = '.' then
2941 Name_Len := J + Object_Suffix'Length - 1;
2942 Name_Buffer (J .. Name_Len) := Object_Suffix;
2947 Comp_Last := Comp_Last + 1;
2948 Comp_Args (Comp_Last) := Output_Flag;
2949 Comp_Last := Comp_Last + 1;
2951 -- If an object directory was specified, prepend the object file
2952 -- name with this object directory.
2954 if Object_Directory_Path /= null then
2955 Comp_Args (Comp_Last) :=
2956 new String'(Object_Directory_Path.all &
2957 Name_Buffer (1 .. Name_Len));
2960 Comp_Args (Comp_Last) :=
2961 new String'(Name_Buffer (1 .. Name_Len));
2965 if Create_Mapping_File and then Mapping_File_Arg /= null then
2966 Comp_Last := Comp_Last + 1;
2967 Comp_Args (Comp_Last) := new String'(Mapping_File_Arg.all);
2970 Get_Name_String (S);
2972 Comp_Last := Comp_Last + 1;
2973 Comp_Args (Comp_Last) := new String'(Name_Buffer (1 .. Name_Len));
2975 -- Change to object directory of the project file, if necessary
2977 if Project /= No_Project then
2978 Change_To_Object_Directory (Project);
2981 GNAT.OS_Lib.Normalize_Arguments (Comp_Args (Args'First .. Comp_Last));
2983 Comp_Last := Comp_Last + 1;
2984 Comp_Args (Comp_Last) := new String'("-gnatez
");
2986 Display (Gcc.all, Comp_Args (Args'First .. Comp_Last));
2988 if Gcc_Path = null then
2989 Make_Failed ("error
, unable to locate
" & Gcc.all);
2993 GNAT.OS_Lib.Non_Blocking_Spawn
2994 (Gcc_Path.all, Comp_Args (Args'First .. Comp_Last));
2997 ----------------------
2998 -- Get_Mapping_File --
2999 ----------------------
3001 procedure Get_Mapping_File (Project : Project_Id) is
3002 Data : Project_Compilation_Access;
3005 Data := Project_Compilation_Htable.Get (Project_Compilation, Project);
3007 -- If there is a mapping file ready to be reused, reuse it
3009 if Data.Last_Free_Indices > 0 then
3010 Mfile := Data.Free_Mapping_File_Indices (Data.Last_Free_Indices);
3011 Data.Last_Free_Indices := Data.Last_Free_Indices - 1;
3013 -- Otherwise, create and initialize a new one
3017 (Project => Project, Data => Data.all, File_Index => Mfile);
3020 -- Put the name in the mapping file argument for the invocation
3023 Free (Mapping_File_Arg);
3025 new String'("-gnatem
=" &
3026 Get_Name_String (Data.Mapping_File_Names (Mfile)));
3027 end Get_Mapping_File;
3029 -----------------------
3030 -- Get_Next_Good_ALI --
3031 -----------------------
3033 function Get_Next_Good_ALI return ALI_Id is
3037 pragma Assert (Good_ALI_Present);
3038 ALI := Good_ALI.Table (Good_ALI.Last);
3039 Good_ALI.Decrement_Last;
3041 end Get_Next_Good_ALI;
3043 ----------------------
3044 -- Good_ALI_Present --
3045 ----------------------
3047 function Good_ALI_Present return Boolean is
3049 return Good_ALI.First <= Good_ALI.Last;
3050 end Good_ALI_Present;
3052 --------------------
3053 -- Record_Failure --
3054 --------------------
3056 procedure Record_Failure
3057 (File : File_Name_Type;
3058 Unit : Unit_Name_Type;
3059 Found : Boolean := True)
3062 Bad_Compilation.Increment_Last;
3063 Bad_Compilation.Table (Bad_Compilation.Last) := (File, Unit, Found);
3066 ---------------------
3067 -- Record_Good_ALI --
3068 ---------------------
3070 procedure Record_Good_ALI (A : ALI_Id) is
3072 Good_ALI.Increment_Last;
3073 Good_ALI.Table (Good_ALI.Last) := A;
3074 end Record_Good_ALI;
3076 -- Start of processing for Compile_Sources
3079 pragma Assert (Args'First = 1);
3081 Outstanding_Compiles := 0;
3082 Running_Compile := new Comp_Data_Arr (1 .. Max_Process);
3084 -- Package and Queue initializations
3088 if First_Q_Initialization then
3092 if Initialize_ALI_Data then
3094 Initialize_ALI_Source;
3097 -- The following two flags affect the behavior of ALI.Set_Source_Table.
3098 -- We set Check_Source_Files to True to ensure that source file
3099 -- time stamps are checked, and we set All_Sources to False to
3100 -- avoid checking the presence of the source files listed in the
3101 -- source dependency section of an ali file (which would be a mistake
3102 -- since the ali file may be obsolete).
3104 Check_Source_Files := True;
3105 All_Sources := False;
3107 -- Only insert in the Q if it is not already done, to avoid simultaneous
3108 -- compilations if -jnnn is used.
3110 if not Is_Marked (Main_Source, Main_Index) then
3111 Insert_Q (Main_Source, Index => Main_Index);
3112 Mark (Main_Source, Main_Index);
3115 First_Compiled_File := No_File;
3116 Most_Recent_Obj_File := No_File;
3117 Most_Recent_Obj_Stamp := Empty_Time_Stamp;
3120 -- Keep looping until there is no more work to do (the Q is empty)
3121 -- and all the outstanding compilations have terminated
3123 Make_Loop : while not Empty_Q or else Outstanding_Compiles > 0 loop
3125 -- If the user does not want to keep going in case of errors then
3126 -- wait for the remaining outstanding compiles and then exit.
3128 if Bad_Compilation_Count > 0 and then not Keep_Going then
3129 while Outstanding_Compiles > 0 loop
3131 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
3133 if not Compilation_OK then
3134 Record_Failure (Full_Source_File, Source_Unit);
3141 -- PHASE 1: Check if there is more work that we can do (i.e. the Q
3142 -- is non empty). If there is, do it only if we have not yet used
3143 -- up all the available processes.
3145 if not Empty_Q and then Outstanding_Compiles < Max_Process then
3148 -- Index of the current unit in the current source file
3151 Extract_From_Q (Source_File, Source_Unit, Source_Index);
3152 Full_Source_File := Osint.Full_Source_Name (Source_File);
3153 Lib_File := Osint.Lib_File_Name
3154 (Source_File, Source_Index);
3155 Full_Lib_File := Osint.Full_Lib_File_Name (Lib_File);
3157 -- If this source has already been compiled, the executable is
3160 if Is_In_Obsoleted (Source_File) then
3161 Executable_Obsolete := True;
3164 -- If the library file is an Ada library skip it
3166 if Full_Lib_File /= No_File
3167 and then In_Ada_Lib_Dir (Full_Lib_File)
3171 "is in an Ada library
",
3173 Minimum_Verbosity => Opt.High);
3175 -- If the library file is a read-only library skip it, but
3176 -- only if, when using project files, this library file is
3177 -- in the right object directory (a read-only ALI file
3178 -- in the object directory of a project being extended
3179 -- should not be skipped).
3181 elsif Full_Lib_File /= No_File
3182 and then not Check_Readonly_Files
3183 and then Is_Readonly_Library (Full_Lib_File)
3184 and then Is_In_Object_Directory (Source_File, Full_Lib_File)
3188 "is a read
-only library
",
3190 Minimum_Verbosity => Opt.High);
3192 -- The source file that we are checking cannot be located
3194 elsif Full_Source_File = No_File then
3195 Record_Failure (Source_File, Source_Unit, False);
3197 -- Source and library files can be located but are internal
3200 elsif not Check_Readonly_Files
3201 and then Full_Lib_File /= No_File
3202 and then Is_Internal_File_Name (Source_File, False)
3204 if Force_Compilations then
3206 ("not allowed to compile
""" &
3207 Get_Name_String (Source_File) &
3208 """; use -a switch
, or compile file
with " &
3209 """-gnatg
"" switch
");
3214 "is an internal library
",
3216 Minimum_Verbosity => Opt.High);
3218 -- The source file that we are checking can be located
3221 Collect_Arguments (Source_File, Source_Index,
3222 Source_File = Main_Source, Args);
3224 -- Do nothing if project of source is externally built
3226 if Arguments_Project = No_Project
3227 or else not Arguments_Project.Externally_Built
3229 -- Don't waste any time if we have to recompile anyway
3231 Obj_Stamp := Empty_Time_Stamp;
3232 Need_To_Compile := Force_Compilations;
3234 if not Force_Compilations then
3236 Full_Lib_File /= No_File
3237 and then not Check_Readonly_Files
3238 and then Is_Readonly_Library (Full_Lib_File);
3239 Check (Source_File, Source_Index,
3240 Source_File = Main_Source, Args, Lib_File,
3241 Read_Only, ALI, Obj_File, Obj_Stamp);
3242 Need_To_Compile := (ALI = No_ALI_Id);
3245 if not Need_To_Compile then
3246 -- The ALI file is up-to-date. Record its Id
3248 Record_Good_ALI (ALI);
3250 -- Record the time stamp of the most recent object
3251 -- file as long as no (re)compilations are needed.
3253 if First_Compiled_File = No_File
3254 and then (Most_Recent_Obj_File = No_File
3255 or else Obj_Stamp > Most_Recent_Obj_Stamp)
3257 Most_Recent_Obj_File := Obj_File;
3258 Most_Recent_Obj_Stamp := Obj_Stamp;
3262 -- Check that switch -x has been used if a source
3263 -- outside of project files need to be compiled.
3265 if Main_Project /= No_Project
3266 and then Arguments_Project = No_Project
3267 and then not External_Unit_Compilation_Allowed
3269 Make_Failed ("external source
("
3270 & Get_Name_String (Source_File)
3271 & ") is not part
of any project
;"
3272 & " cannot be compiled without
"
3273 & " gnatmake switch
-x
");
3276 -- Is this the first file we have to compile?
3278 if First_Compiled_File = No_File then
3279 First_Compiled_File := Full_Source_File;
3280 Most_Recent_Obj_File := No_File;
3282 if Do_Not_Execute then
3287 if In_Place_Mode then
3289 -- If the library file was not found, then save
3290 -- the library file near the source file.
3292 if Full_Lib_File = No_File then
3293 Lib_File := Osint.Lib_File_Name
3294 (Full_Source_File, Source_Index);
3296 -- If the library file was found, then save the
3297 -- library file in the same place.
3300 Lib_File := Full_Lib_File;
3305 -- Start the compilation and record it. We can do
3306 -- this because there is at least one free process.
3308 Collect_Arguments_And_Compile (Source_Index);
3310 -- Make sure we could successfully start
3313 if Process_Created then
3314 if Pid = Invalid_Pid then
3315 Record_Failure (Full_Source_File, Source_Unit);
3331 -- PHASE 2: Now check if we should wait for a compilation to
3332 -- finish. This is the case if all the available processes are
3333 -- busy compiling sources or there is nothing else to do
3334 -- (that is the Q is empty and there are no good ALIs to process).
3336 if Outstanding_Compiles = Max_Process
3338 and then not Good_ALI_Present
3339 and then Outstanding_Compiles > 0)
3342 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
3344 if not Compilation_OK then
3345 Record_Failure (Full_Source_File, Source_Unit);
3348 if Compilation_OK or else Keep_Going then
3350 -- Re-read the updated library file
3353 Saved_Object_Consistency : constant Boolean :=
3354 Check_Object_Consistency;
3357 -- If compilation was not OK, or if output is not an
3358 -- object file and we don't do the bind step, don't check
3359 -- for object consistency.
3361 Check_Object_Consistency :=
3362 Check_Object_Consistency
3364 and (Output_Is_Object or Do_Bind_Step);
3365 Text := Read_Library_Info (Lib_File);
3367 -- Restore Check_Object_Consistency to its initial value
3369 Check_Object_Consistency := Saved_Object_Consistency;
3372 -- If an ALI file was generated by this compilation, scan
3373 -- the ALI file and record it.
3375 -- If the scan fails, a previous ali file is inconsistent with
3376 -- the unit just compiled.
3378 if Text /= null then
3380 Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
3382 if ALI = No_ALI_Id then
3384 -- Record a failure only if not already done
3386 if Compilation_OK then
3389 "incompatible ALI file
, please recompile
");
3390 Record_Failure (Full_Source_File, Source_Unit);
3394 Record_Good_ALI (ALI);
3397 -- If we could not read the ALI file that was just generated
3398 -- then there could be a problem reading either the ALI or the
3399 -- corresponding object file (if Check_Object_Consistency is
3400 -- set Read_Library_Info checks that the time stamp of the
3401 -- object file is more recent than that of the ALI). However,
3402 -- we record a failure only if not already done.
3405 if Compilation_OK and not Syntax_Only then
3408 "WARNING
: ALI
or object file
not found after compile
");
3409 Record_Failure (Full_Source_File, Source_Unit);
3415 -- PHASE 3: Check if we recorded good ALI files. If yes process
3416 -- them now in the order in which they have been recorded. There
3417 -- are two occasions in which we record good ali files. The first is
3418 -- in phase 1 when, after scanning an existing ALI file we realize
3419 -- it is up-to-date, the second instance is after a successful
3422 while Good_ALI_Present loop
3423 ALI := Get_Next_Good_ALI;
3426 Source_Index : Int := Unit_Index_Of (ALIs.Table (ALI).Afile);
3429 -- If we are processing the library file corresponding to the
3430 -- main source file check if this source can be a main unit.
3432 if ALIs.Table (ALI).Sfile = Main_Source and then
3433 Source_Index = Main_Index
3435 Main_Unit := ALIs.Table (ALI).Main_Program /= None;
3438 -- The following adds the standard library (s-stalib) to the
3439 -- list of files to be handled by gnatmake: this file and any
3440 -- files it depends on are always included in every bind,
3441 -- even if they are not in the explicit dependency list.
3442 -- Of course, it is not added if Suppress_Standard_Library
3445 -- However, to avoid annoying output about s-stalib.ali being
3446 -- read only, when "-v
" is used, we add the standard library
3447 -- only when "-a
" is used.
3449 if Need_To_Check_Standard_Library then
3450 Check_Standard_Library;
3453 -- Now insert in the Q the unmarked source files (i.e. those
3454 -- which have never been inserted in the Q and hence never
3455 -- considered). Only do that if Unique_Compile is False.
3457 if not Unique_Compile then
3459 ALIs.Table (ALI).First_Unit .. ALIs.Table (ALI).Last_Unit
3462 Units.Table (J).First_With .. Units.Table (J).Last_With
3464 Sfile := Withs.Table (K).Sfile;
3465 Uname := Withs.Table (K).Uname;
3467 -- If project files are used, find the proper source
3468 -- to compile, in case Sfile is the spec, but there
3471 if Main_Project /= No_Project then
3473 Unit_Name : Name_Id;
3474 Uid : Prj.Unit_Index;
3477 Get_Name_String (Uname);
3478 Name_Len := Name_Len - 2;
3479 Unit_Name := Name_Find;
3482 (Project_Tree.Units_HT, Unit_Name);
3484 if Uid /= Prj.No_Unit_Index then
3485 if Uid.File_Names (Impl) /= null
3487 not Uid.File_Names (Impl).Locally_Removed
3489 Sfile := Uid.File_Names (Impl).File;
3491 Uid.File_Names (Impl).Index;
3493 elsif Uid.File_Names (Spec) /= null
3495 not Uid.File_Names (Spec).Locally_Removed
3497 Sfile := Uid.File_Names (Spec).File;
3499 Uid.File_Names (Spec).Index;
3505 Dependencies.Append ((ALIs.Table (ALI).Sfile, Sfile));
3507 if Is_In_Obsoleted (Sfile) then
3508 Executable_Obsolete := True;
3511 if Sfile = No_File then
3513 ("Skipping
generic:", Withs.Table (K).Uname);
3517 Unit_Index_Of (Withs.Table (K).Afile);
3519 if Is_Marked (Sfile, Source_Index) then
3520 Debug_Msg ("Skipping marked file
:", Sfile);
3522 elsif not Check_Readonly_Files
3523 and then Is_Internal_File_Name (Sfile, False)
3525 Debug_Msg ("Skipping internal file
:", Sfile);
3529 (Sfile, Withs.Table (K).Uname, Source_Index);
3530 Mark (Sfile, Source_Index);
3539 if Display_Compilation_Progress then
3540 Write_Str ("completed
");
3541 Write_Int (Int (Q_Front));
3542 Write_Str (" out of ");
3543 Write_Int (Int (Q.Last));
3545 Write_Int (Int ((Q_Front * 100) / (Q.Last - Q.First)));
3546 Write_Str ("%)...");
3551 Compilation_Failures := Bad_Compilation_Count;
3553 -- Compilation is finished
3555 -- Delete any temporary configuration pragma file
3557 if not Debug.Debug_Flag_N then
3558 Delete_Temp_Config_Files;
3560 end Compile_Sources;
3562 ----------------------------------
3563 -- Configuration_Pragmas_Switch --
3564 ----------------------------------
3566 function Configuration_Pragmas_Switch
3567 (For_Project : Project_Id) return Argument_List
3569 The_Packages : Package_Id;
3570 Gnatmake : Package_Id;
3571 Compiler : Package_Id;
3573 Global_Attribute : Variable_Value := Nil_Variable_Value;
3574 Local_Attribute : Variable_Value := Nil_Variable_Value;
3576 Global_Attribute_Present : Boolean := False;
3577 Local_Attribute_Present : Boolean := False;
3579 Result : Argument_List (1 .. 3);
3580 Last : Natural := 0;
3582 function Absolute_Path
3583 (Path : Path_Name_Type;
3584 Project : Project_Id) return String;
3585 -- Returns an absolute path for a configuration pragmas file
3591 function Absolute_Path
3592 (Path : Path_Name_Type;
3593 Project : Project_Id) return String
3596 Get_Name_String (Path);
3599 Path_Name : constant String := Name_Buffer (1 .. Name_Len);
3602 if Is_Absolute_Path (Path_Name) then
3607 Parent_Directory : constant String :=
3608 Get_Name_String (Project.Directory.Display_Name);
3611 if Parent_Directory (Parent_Directory'Last) =
3614 return Parent_Directory & Path_Name;
3617 return Parent_Directory & Directory_Separator & Path_Name;
3624 -- Start of processing for Configuration_Pragmas_Switch
3627 Prj.Env.Create_Config_Pragmas_File
3628 (For_Project, Project_Tree);
3630 if For_Project.Config_File_Name /= No_Path then
3631 Temporary_Config_File := For_Project.Config_File_Temp;
3635 ("-gnatec
=" & Get_Name_String (For_Project.Config_File_Name));
3638 Temporary_Config_File := False;
3641 -- Check for attribute Builder'Global_Configuration_Pragmas
3643 The_Packages := Main_Project.Decl.Packages;
3646 (Name => Name_Builder,
3647 In_Packages => The_Packages,
3648 In_Tree => Project_Tree);
3650 if Gnatmake /= No_Package then
3651 Global_Attribute := Prj.Util.Value_Of
3652 (Variable_Name => Name_Global_Configuration_Pragmas,
3653 In_Variables => Project_Tree.Packages.Table
3654 (Gnatmake).Decl.Attributes,
3655 In_Tree => Project_Tree);
3656 Global_Attribute_Present :=
3657 Global_Attribute /= Nil_Variable_Value
3658 and then Get_Name_String (Global_Attribute.Value) /= "";
3660 if Global_Attribute_Present then
3662 Path : constant String :=
3664 (Path_Name_Type (Global_Attribute.Value),
3665 Global_Attribute.Project);
3667 if not Is_Regular_File (Path) then
3668 if Debug.Debug_Flag_F then
3670 ("cannot find configuration pragmas file
"
3671 & File_Name (Path));
3674 ("cannot find configuration pragmas file
" & Path);
3679 Result (Last) := new String'("-gnatec
=" & Path);
3684 -- Check for attribute Compiler'Local_Configuration_Pragmas
3686 The_Packages := For_Project.Decl.Packages;
3689 (Name => Name_Compiler,
3690 In_Packages => The_Packages,
3691 In_Tree => Project_Tree);
3693 if Compiler /= No_Package then
3694 Local_Attribute := Prj.Util.Value_Of
3695 (Variable_Name => Name_Local_Configuration_Pragmas,
3696 In_Variables => Project_Tree.Packages.Table
3697 (Compiler).Decl.Attributes,
3698 In_Tree => Project_Tree);
3699 Local_Attribute_Present :=
3700 Local_Attribute /= Nil_Variable_Value
3701 and then Get_Name_String (Local_Attribute.Value) /= "";
3703 if Local_Attribute_Present then
3705 Path : constant String :=
3707 (Path_Name_Type (Local_Attribute.Value),
3708 Local_Attribute.Project);
3710 if not Is_Regular_File (Path) then
3711 if Debug.Debug_Flag_F then
3713 ("cannot find configuration pragmas file
"
3714 & File_Name (Path));
3718 ("cannot find configuration pragmas file
" & Path);
3723 Result (Last) := new String'("-gnatec
=" & Path);
3728 return Result (1 .. Last);
3729 end Configuration_Pragmas_Switch;
3735 procedure Debug_Msg (S : String; N : Name_Id) is
3737 if Debug.Debug_Flag_W then
3738 Write_Str (" ... ");
3746 procedure Debug_Msg (S : String; N : File_Name_Type) is
3748 Debug_Msg (S, Name_Id (N));
3751 procedure Debug_Msg (S : String; N : Unit_Name_Type) is
3753 Debug_Msg (S, Name_Id (N));
3756 ---------------------------
3757 -- Delete_All_Temp_Files --
3758 ---------------------------
3760 procedure Delete_All_Temp_Files is
3762 if not Debug.Debug_Flag_N then
3763 Delete_Temp_Config_Files;
3764 Prj.Delete_All_Temp_Files (Project_Tree);
3766 end Delete_All_Temp_Files;
3768 ------------------------------
3769 -- Delete_Temp_Config_Files --
3770 ------------------------------
3772 procedure Delete_Temp_Config_Files is
3774 Proj : Project_List;
3775 pragma Warnings (Off, Success);
3778 -- The caller is responsible for ensuring that Debug_Flag_N is False
3780 pragma Assert (not Debug.Debug_Flag_N);
3782 if Main_Project /= No_Project then
3783 Proj := Project_Tree.Projects;
3784 while Proj /= null loop
3785 if Proj.Project.Config_File_Temp then
3786 Delete_Temporary_File
3787 (Project_Tree, Proj.Project.Config_File_Name);
3789 -- Make sure that we don't have a config file for this project,
3790 -- in case there are several mains. In this case, we will
3791 -- recreate another config file: we cannot reuse the one that
3794 Proj.Project.Config_Checked := False;
3795 Proj.Project.Config_File_Name := No_Path;
3796 Proj.Project.Config_File_Temp := False;
3801 end Delete_Temp_Config_Files;
3807 procedure Display (Program : String; Args : Argument_List) is
3809 pragma Assert (Args'First = 1);
3811 if Display_Executed_Programs then
3812 Write_Str (Program);
3814 for J in Args'Range loop
3816 -- Never display -gnatea nor -gnatez
3818 if Args (J).all /= "-gnatea
"
3820 Args (J).all /= "-gnatez
"
3822 -- Do not display the mapping file argument automatically
3823 -- created when using a project file.
3825 if Main_Project = No_Project
3826 or else Debug.Debug_Flag_N
3827 or else Args (J)'Length < 8
3829 Args (J) (Args (J)'First .. Args (J)'First + 6) /= "-gnatem
"
3831 -- When -dn is not specified, do not display the config
3832 -- pragmas switch (-gnatec) for the temporary file created
3833 -- by the project manager (always the first -gnatec switch).
3834 -- Reset Temporary_Config_File to False so that the eventual
3835 -- other -gnatec switches will be displayed.
3837 if (not Debug.Debug_Flag_N)
3838 and then Temporary_Config_File
3839 and then Args (J)'Length > 7
3840 and then Args (J) (Args (J)'First .. Args (J)'First + 6)
3843 Temporary_Config_File := False;
3845 -- Do not display the -F=mapping_file switch for
3846 -- gnatbind, if -dn is not specified.
3848 elsif Debug.Debug_Flag_N
3849 or else Args (J)'Length < 4
3851 Args (J) (Args (J)'First .. Args (J)'First + 2) /= "-F
="
3855 -- If -df is used, only display file names, not path
3858 if Debug.Debug_Flag_F then
3860 Equal_Pos : Natural;
3862 Equal_Pos := Args (J)'First - 1;
3863 for K in Args (J)'Range loop
3864 if Args (J) (K) = '=' then
3871 (Args (J) (Equal_Pos + 1 .. Args (J)'Last))
3874 (Args (J) (Args (J)'First .. Equal_Pos));
3878 (Equal_Pos + 1 .. Args (J)'Last)));
3881 Write_Str (Args (J).all);
3886 Write_Str (Args (J).all);
3897 ----------------------
3898 -- Display_Commands --
3899 ----------------------
3901 procedure Display_Commands (Display : Boolean := True) is
3903 Display_Executed_Programs := Display;
3904 end Display_Commands;
3910 function Empty_Q return Boolean is
3912 if Debug.Debug_Flag_P then
3913 Write_Str (" Q
:= [");
3915 for J in Q_Front .. Q.Last - 1 loop
3917 Write_Name (Q.Table (J).File);
3926 return Q_Front >= Q.Last;
3929 --------------------------
3930 -- Enter_Into_Obsoleted --
3931 --------------------------
3933 procedure Enter_Into_Obsoleted (F : File_Name_Type) is
3934 Name : constant String := Get_Name_String (F);
3936 F2 : File_Name_Type;
3940 while First > Name'First
3941 and then Name (First - 1) /= Directory_Separator
3942 and then Name (First - 1) /= '/'
3947 if First /= Name'First then
3949 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
3956 Debug_Msg ("New entry in Obsoleted table
:", F2);
3957 Obsoleted.Set (F2, True);
3958 end Enter_Into_Obsoleted;
3960 --------------------
3961 -- Extract_From_Q --
3962 --------------------
3964 procedure Extract_From_Q
3965 (Source_File : out File_Name_Type;
3966 Source_Unit : out Unit_Name_Type;
3967 Source_Index : out Int)
3969 File : constant File_Name_Type := Q.Table (Q_Front).File;
3970 Unit : constant Unit_Name_Type := Q.Table (Q_Front).Unit;
3971 Index : constant Int := Q.Table (Q_Front).Index;
3974 if Debug.Debug_Flag_Q then
3975 Write_Str (" Q
:= Q
- [ ");
3987 Q_Front := Q_Front + 1;
3988 Source_File := File;
3989 Source_Unit := Unit;
3990 Source_Index := Index;
3997 procedure Gnatmake is
3998 Main_Source_File : File_Name_Type;
3999 -- The source file containing the main compilation unit
4001 Compilation_Failures : Natural;
4003 Total_Compilation_Failures : Natural := 0;
4005 Is_Main_Unit : Boolean;
4006 -- Set to True by Compile_Sources if the Main_Source_File can be a
4009 Main_ALI_File : File_Name_Type;
4010 -- The ali file corresponding to Main_Source_File
4012 Executable : File_Name_Type := No_File;
4013 -- The file name of an executable
4015 Non_Std_Executable : Boolean := False;
4016 -- Non_Std_Executable is set to True when there is a possibility
4017 -- that the linker will not choose the correct executable file name.
4019 Current_Work_Dir : constant String_Access :=
4020 new String'(Get_Current_Dir);
4021 -- The current working directory, used to modify some relative path
4022 -- switches on the command line when a project file is used.
4024 Current_Main_Index : Int := 0;
4025 -- If not zero, the index of the current main unit in its source file
4027 Stand_Alone_Libraries : Boolean := False;
4028 -- Set to True when there are Stand-Alone Libraries, so that gnatbind
4029 -- is invoked with the -F switch to force checking of elaboration flags.
4031 Mapping_Path : Path_Name_Type := No_Path;
4032 -- The path name of the mapping file
4034 Project_Node_Tree : Project_Node_Tree_Ref;
4037 pragma Warnings (Off, Discard);
4039 procedure Check_Mains;
4040 -- Check that the main subprograms do exist and that they all
4041 -- belong to the same project file.
4043 procedure Create_Binder_Mapping_File
4044 (Args : in out Argument_List; Last_Arg : in out Natural);
4045 -- Create a binder mapping file and add the necessary switch
4051 procedure Check_Mains is
4052 Real_Main_Project : Project_Id := No_Project;
4053 -- The project of the first main
4055 Proj : Project_Id := No_Project;
4056 -- The project of the current main
4058 Real_Path : String_Access;
4067 Main : constant String := Mains.Next_Main;
4068 -- The name specified on the command line may include
4069 -- directory information.
4071 File_Name : constant String := Base_Name (Main);
4072 -- The simple file name of the current main
4074 Lang : Language_Ptr;
4077 exit when Main = "";
4079 -- Get the project of the current main
4081 Proj := Prj.Env.Project_Of
4082 (File_Name, Main_Project, Project_Tree);
4084 -- Fail if the current main is not a source of a
4087 if Proj = No_Project then
4089 ("""" & Main & """ is not a source
of any project
");
4092 -- If there is directory information, check that
4093 -- the source exists and, if it does, that the path
4094 -- is the actual path of a source of a project.
4096 if Main /= File_Name then
4097 Lang := Get_Language_From_Name (Main_Project, "ada
");
4101 (Main & Get_Name_String
4102 (Lang.Config.Naming_Data.Body_Suffix),
4104 if Real_Path = null then
4107 (Main & Get_Name_String
4108 (Lang.Config.Naming_Data.Spec_Suffix),
4112 if Real_Path = null then
4113 Real_Path := Locate_Regular_File (Main, "");
4116 -- Fail if the file cannot be found
4118 if Real_Path = null then
4119 Make_Failed ("file
""" & Main & """ does
not exist
");
4123 Project_Path : constant String :=
4124 Prj.Env.File_Name_Of_Library_Unit_Body
4126 Project => Main_Project,
4127 In_Tree => Project_Tree,
4128 Main_Project_Only => False,
4130 Normed_Path : constant String :=
4133 Case_Sensitive => False);
4134 Proj_Path : constant String :=
4137 Case_Sensitive => False);
4142 -- Fail if it is not the correct path
4144 if Normed_Path /= Proj_Path then
4145 if Verbose_Mode then
4147 Write_Str (Normed_Path);
4149 Write_Line (Proj_Path);
4154 """ is not a source
of any project
");
4159 if not Unique_Compile then
4161 -- Record the project, if it is the first main
4163 if Real_Main_Project = No_Project then
4164 Real_Main_Project := Proj;
4166 elsif Proj /= Real_Main_Project then
4168 -- Fail, as the current main is not a source
4169 -- of the same project as the first main.
4173 """ is not a source
of project
" &
4174 Get_Name_String (Real_Main_Project.Name));
4179 -- If -u and -U are not used, we may have mains that
4180 -- are sources of a project that is not the one
4181 -- specified with switch -P.
4183 if not Unique_Compile then
4184 Main_Project := Real_Main_Project;
4190 --------------------------------
4191 -- Create_Binder_Mapping_File --
4192 --------------------------------
4194 procedure Create_Binder_Mapping_File
4195 (Args : in out Argument_List; Last_Arg : in out Natural)
4197 Mapping_FD : File_Descriptor := Invalid_FD;
4198 -- A File Descriptor for an eventual mapping file
4200 ALI_Unit : Unit_Name_Type := No_Unit_Name;
4201 -- The unit name of an ALI file
4203 ALI_Name : File_Name_Type := No_File;
4204 -- The file name of the ALI file
4206 ALI_Project : Project_Id := No_Project;
4207 -- The project of the ALI file
4210 OK : Boolean := True;
4214 -- For call to Close
4217 Tempdir.Create_Temp_File (Mapping_FD, Mapping_Path);
4218 Record_Temp_File (Project_Tree, Mapping_Path);
4220 if Mapping_FD /= Invalid_FD then
4222 -- Traverse all units
4224 Unit := Units_Htable.Get_First (Project_Tree.Units_HT);
4226 while Unit /= No_Unit_Index loop
4227 if Unit.Name /= No_Name then
4229 -- If there is a body, put it in the mapping
4231 if Unit.File_Names (Impl) /= No_Source
4232 and then Unit.File_Names (Impl).Project /=
4235 Get_Name_String (Unit.Name);
4236 Add_Str_To_Name_Buffer ("%b
");
4237 ALI_Unit := Name_Find;
4240 (Unit.File_Names (Impl).Display_File);
4241 ALI_Project := Unit.File_Names (Impl).Project;
4243 -- Otherwise, if there is a spec, put it in the
4246 elsif Unit.File_Names (Spec) /= No_Source
4247 and then Unit.File_Names (Spec).Project /=
4250 Get_Name_String (Unit.Name);
4251 Add_Str_To_Name_Buffer ("%s
");
4252 ALI_Unit := Name_Find;
4255 (Unit.File_Names (Spec).Display_File);
4256 ALI_Project := Unit.File_Names (Spec).Project;
4259 ALI_Name := No_File;
4262 -- If we have something to put in the mapping then do it
4263 -- now. However, if the project is extended, we don't put
4264 -- anything in the mapping file, because we don't know where
4265 -- the ALI file is: it might be in the extended project obj
4266 -- dir as well as in the extending project obj dir.
4268 if ALI_Name /= No_File
4269 and then ALI_Project.Extended_By = No_Project
4270 and then ALI_Project.Extends = No_Project
4272 -- First check if the ALI file exists. If it does not,
4273 -- do not put the unit in the mapping file.
4276 ALI : constant String := Get_Name_String (ALI_Name);
4279 -- For library projects, use the library directory,
4280 -- for other projects, use the object directory.
4282 if ALI_Project.Library then
4283 Get_Name_String (ALI_Project.Library_Dir.Name);
4286 (ALI_Project.Object_Directory.Name);
4290 Is_Directory_Separator (Name_Buffer (Name_Len))
4292 Add_Char_To_Name_Buffer (Directory_Separator);
4295 Add_Str_To_Name_Buffer (ALI);
4296 Add_Char_To_Name_Buffer (ASCII.LF);
4299 ALI_Path_Name : constant String :=
4300 Name_Buffer (1 .. Name_Len);
4304 (ALI_Path_Name (1 .. ALI_Path_Name'Last - 1))
4306 -- First line is the unit name
4308 Get_Name_String (ALI_Unit);
4309 Add_Char_To_Name_Buffer (ASCII.LF);
4313 Name_Buffer (1)'Address,
4315 OK := Bytes = Name_Len;
4319 -- Second line it the ALI file name
4321 Get_Name_String (ALI_Name);
4322 Add_Char_To_Name_Buffer (ASCII.LF);
4326 Name_Buffer (1)'Address,
4328 OK := (Bytes = Name_Len);
4332 -- Third line it the ALI path name
4337 ALI_Path_Name (1)'Address,
4338 ALI_Path_Name'Length);
4339 OK := (Bytes = ALI_Path_Name'Length);
4341 -- If OK is False, it means we were unable to
4342 -- write a line. No point in continuing with the
4352 Unit := Units_Htable.Get_Next (Project_Tree.Units_HT);
4355 Close (Mapping_FD, Status);
4357 OK := OK and Status;
4359 -- If the creation of the mapping file was successful,
4360 -- we add the switch to the arguments of gnatbind.
4363 Last_Arg := Last_Arg + 1;
4365 new String'("-F
=" & Get_Name_String (Mapping_Path));
4368 end Create_Binder_Mapping_File;
4370 -- Start of processing for Gnatmake
4372 -- This body is very long, should be broken down ???
4375 Install_Int_Handler (Sigint_Intercepted'Access);
4377 Do_Compile_Step := True;
4378 Do_Bind_Step := True;
4379 Do_Link_Step := True;
4383 Make.Initialize (Project_Node_Tree);
4385 Bind_Shared := No_Shared_Switch'Access;
4386 Link_With_Shared_Libgcc := No_Shared_Libgcc_Switch'Access;
4388 Failed_Links.Set_Last (0);
4389 Successful_Links.Set_Last (0);
4391 -- Special case when switch -B was specified
4393 if Build_Bind_And_Link_Full_Project then
4395 -- When switch -B is specified, there must be a project file
4397 if Main_Project = No_Project then
4398 Make_Failed ("-B cannot be used without a project file
");
4400 -- No main program may be specified on the command line
4402 elsif Osint.Number_Of_Files /= 0 then
4403 Make_Failed ("-B cannot be used
with a main specified on
" &
4404 "the command line
");
4406 -- And the project file cannot be a library project file
4408 elsif Main_Project.Library then
4409 Make_Failed ("-B cannot be used
for a library project file
");
4412 No_Main_Subprogram := True;
4413 Insert_Project_Sources
4414 (The_Project => Main_Project,
4415 All_Projects => Unique_Compile_All_Projects,
4418 -- If there are no sources to compile, we fail
4420 if Osint.Number_Of_Files = 0 then
4421 Make_Failed ("no sources to compile
");
4424 -- Specify -n for gnatbind and add the ALI files of all the
4425 -- sources, except the one which is a fake main subprogram:
4426 -- this is the one for the binder generated file and it will be
4427 -- transmitted to gnatlink. These sources are those that are
4430 Add_Switch ("-n
", Binder, And_Save => True);
4432 for J in Q.First .. Q.Last - 1 loop
4435 (Lib_File_Name (Q.Table (J).File)),
4436 Binder, And_Save => True);
4440 elsif Main_Index /= 0 and then Osint.Number_Of_Files > 1 then
4441 Make_Failed ("cannot specify several mains
with a multi
-unit index
");
4443 elsif Main_Project /= No_Project then
4445 -- If the main project file is a library project file, main(s)
4446 -- cannot be specified on the command line.
4448 if Osint.Number_Of_Files /= 0 then
4449 if Main_Project.Library
4450 and then not Unique_Compile
4451 and then ((not Make_Steps) or else Bind_Only or else Link_Only)
4453 Make_Failed ("cannot specify a main program
" &
4454 "on the command line
for a library project file
");
4457 -- Check that each main on the command line is a source of a
4458 -- project file and, if there are several mains, each of them
4459 -- is a source of the same project file.
4464 -- If no mains have been specified on the command line,
4465 -- and we are using a project file, we either find the main(s)
4466 -- in the attribute Main of the main project, or we put all
4467 -- the sources of the project file as mains.
4470 if Main_Index /= 0 then
4471 Make_Failed ("cannot specify a multi
-unit index but no main
" &
4472 "on the command line
");
4476 Value : String_List_Id := Main_Project.Mains;
4479 -- The attribute Main is an empty list or not specified,
4480 -- or else gnatmake was invoked with the switch "-u
".
4482 if Value = Prj.Nil_String or else Unique_Compile then
4484 if (not Make_Steps) or else Compile_Only
4485 or else not Main_Project.Library
4487 -- First make sure that the binder and the linker
4488 -- will not be invoked.
4490 Do_Bind_Step := False;
4491 Do_Link_Step := False;
4493 -- Put all the sources in the queue
4495 No_Main_Subprogram := True;
4496 Insert_Project_Sources
4497 (The_Project => Main_Project,
4498 All_Projects => Unique_Compile_All_Projects,
4501 -- If no sources to compile, then there is nothing to do
4503 if Osint.Number_Of_Files = 0 then
4504 if not Quiet_Output then
4505 Osint.Write_Program_Name;
4506 Write_Line (": no sources to compile
");
4509 Delete_All_Temp_Files;
4510 Exit_Program (E_Success);
4515 -- The attribute Main is not an empty list.
4516 -- Put all the main subprograms in the list as if there
4517 -- were specified on the command line. However, if attribute
4518 -- Languages includes a language other than Ada, only
4519 -- include the Ada mains; if there is no Ada main, compile
4520 -- all the sources of the project.
4523 Languages : constant Variable_Value :=
4526 Main_Project.Decl.Attributes,
4529 Current : String_List_Id;
4530 Element : String_Element;
4532 Foreign_Language : Boolean := False;
4533 At_Least_One_Main : Boolean := False;
4536 -- First, determine if there is a foreign language in
4537 -- attribute Languages.
4539 if not Languages.Default then
4540 Current := Languages.Values;
4543 while Current /= Nil_String loop
4544 Element := Project_Tree.String_Elements.
4546 Get_Name_String (Element.Value);
4547 To_Lower (Name_Buffer (1 .. Name_Len));
4549 if Name_Buffer (1 .. Name_Len) /= "ada
" then
4550 Foreign_Language := True;
4551 exit Look_For_Foreign;
4554 Current := Element.Next;
4555 end loop Look_For_Foreign;
4558 -- Then, find all mains, or if there is a foreign
4559 -- language, all the Ada mains.
4561 while Value /= Prj.Nil_String loop
4563 (Project_Tree.String_Elements.Table (Value).Value);
4565 -- To know if a main is an Ada main, get its project.
4566 -- It should be the project specified on the command
4569 if (not Foreign_Language) or else
4571 (Name_Buffer (1 .. Name_Len),
4576 At_Least_One_Main := True;
4579 (Project_Tree.String_Elements.Table
4582 Project_Tree.String_Elements.Table
4586 Value := Project_Tree.String_Elements.Table
4590 -- If we did not get any main, it means that all mains
4591 -- in attribute Mains are in a foreign language and -B
4592 -- was not specified to gnatmake; so, we fail.
4594 if not At_Least_One_Main then
4596 ("no Ada mains
, use -B to build foreign main
");
4605 if Verbose_Mode then
4607 Display_Version ("GNATMAKE
", "1995");
4610 if Main_Project /= No_Project
4611 and then Main_Project.Externally_Built
4614 ("nothing to
do for a main project that
is externally built
");
4617 if Osint.Number_Of_Files = 0 then
4618 if Main_Project /= No_Project
4619 and then Main_Project.Library
4622 and then not Main_Project.Standalone_Library
4624 Make_Failed ("only stand
-alone libraries may be bound
");
4627 -- Add the default search directories to be able to find libgnat
4629 Osint.Add_Default_Search_Dirs;
4631 -- Get the target parameters, so that the correct binder generated
4632 -- files are generated if OpenVMS is the target.
4635 Targparm.Get_Target_Parameters;
4638 when Unrecoverable_Error =>
4639 Make_Failed ("*** make failed
.");
4642 -- And bind and or link the library
4644 MLib.Prj.Build_Library
4645 (For_Project => Main_Project,
4646 In_Tree => Project_Tree,
4647 Gnatbind => Gnatbind.all,
4648 Gnatbind_Path => Gnatbind_Path,
4650 Gcc_Path => Gcc_Path,
4654 Delete_All_Temp_Files;
4655 Exit_Program (E_Success);
4658 -- Call Get_Target_Parameters to ensure that VM_Target and
4659 -- AAMP_On_Target get set before calling Usage.
4661 Targparm.Get_Target_Parameters;
4663 -- Output usage information if no files to compile
4666 Exit_Program (E_Fatal);
4670 -- If -M was specified, behave as if -n was specified
4672 if List_Dependencies then
4673 Do_Not_Execute := True;
4676 -- Note that Osint.M.Next_Main_Source will always return the (possibly
4677 -- abbreviated file) without any directory information.
4679 Main_Source_File := Next_Main_Source;
4681 if Current_File_Index /= No_Index then
4682 Main_Index := Current_File_Index;
4685 Add_Switch ("-I
-", Compiler, And_Save => True);
4687 if Main_Project = No_Project then
4688 if Look_In_Primary_Dir then
4692 Normalize_Directory_Name
4693 (Get_Primary_Src_Search_Directory.all).all,
4694 Compiler, Append_Switch => False,
4700 -- If we use a project file, we have already checked that a main
4701 -- specified on the command line with directory information has the
4702 -- path name corresponding to a correct source in the project tree.
4703 -- So, we don't need the directory information to be taken into
4704 -- account by Find_File, and in fact it may lead to take the wrong
4705 -- sources for other compilation units, when there are extending
4708 Look_In_Primary_Dir := False;
4709 Add_Switch ("-I
-", Binder, And_Save => True);
4712 -- If the user wants a program without a main subprogram, add the
4713 -- appropriate switch to the binder.
4715 if No_Main_Subprogram then
4716 Add_Switch ("-z
", Binder, And_Save => True);
4719 if Main_Project /= No_Project then
4721 if Main_Project.Object_Directory /= No_Path_Information then
4722 -- Change current directory to object directory of main project
4724 Project_Of_Current_Object_Directory := No_Project;
4725 Change_To_Object_Directory (Main_Project);
4728 -- Source file lookups should be cached for efficiency.
4729 -- Source files are not supposed to change.
4731 Osint.Source_File_Data (Cache => True);
4733 -- Find the file name of the (first) main unit
4736 Main_Source_File_Name : constant String :=
4737 Get_Name_String (Main_Source_File);
4738 Main_Unit_File_Name : constant String :=
4739 Prj.Env.File_Name_Of_Library_Unit_Body
4740 (Name => Main_Source_File_Name,
4741 Project => Main_Project,
4742 In_Tree => Project_Tree,
4743 Main_Project_Only =>
4744 not Unique_Compile);
4746 The_Packages : constant Package_Id :=
4747 Main_Project.Decl.Packages;
4749 Builder_Package : constant Prj.Package_Id :=
4751 (Name => Name_Builder,
4752 In_Packages => The_Packages,
4753 In_Tree => Project_Tree);
4755 Binder_Package : constant Prj.Package_Id :=
4757 (Name => Name_Binder,
4758 In_Packages => The_Packages,
4759 In_Tree => Project_Tree);
4761 Linker_Package : constant Prj.Package_Id :=
4763 (Name => Name_Linker,
4764 In_Packages => The_Packages,
4765 In_Tree => Project_Tree);
4767 Default_Switches_Array : Array_Id;
4769 Global_Compilation_Array : Array_Element_Id;
4770 Global_Compilation_Elem : Array_Element;
4771 Global_Compilation_Switches : Variable_Value;
4774 -- We fail if we cannot find the main source file
4776 if Main_Unit_File_Name = "" then
4777 Make_Failed ('"' & Main_Source_File_Name
4778 & """ is not a unit of project "
4779 & Project_File_Name.all & ".");
4781 -- Remove any directory information from the main
4782 -- source file name.
4785 Pos : Natural := Main_Unit_File_Name'Last;
4789 exit when Pos < Main_Unit_File_Name'First or else
4790 Main_Unit_File_Name (Pos) = Directory_Separator;
4794 Name_Len := Main_Unit_File_Name'Last - Pos;
4796 Name_Buffer (1 .. Name_Len) :=
4798 (Pos + 1 .. Main_Unit_File_Name'Last);
4800 Main_Source_File := Name_Find;
4802 -- We only output the main source file if there is only one
4804 if Verbose_Mode and then Osint.Number_Of_Files = 1 then
4805 Write_Str ("Main source file: """);
4806 Write_Str (Main_Unit_File_Name
4807 (Pos + 1 .. Main_Unit_File_Name'Last));
4813 -- If there is a package Builder in the main project file, add
4814 -- the switches from it.
4816 if Builder_Package /= No_Package then
4818 Global_Compilation_Array := Prj.Util.Value_Of
4819 (Name => Name_Global_Compilation_Switches,
4820 In_Arrays => Project_Tree.Packages.Table
4821 (Builder_Package).Decl.Arrays,
4822 In_Tree => Project_Tree);
4824 Default_Switches_Array :=
4825 Project_Tree.Packages.Table
4826 (Builder_Package).Decl.Arrays;
4828 while Default_Switches_Array /= No_Array and then
4829 Project_Tree.Arrays.Table (Default_Switches_Array).Name /=
4830 Name_Default_Switches
4832 Default_Switches_Array :=
4833 Project_Tree.Arrays.Table (Default_Switches_Array).Next;
4836 if Global_Compilation_Array /= No_Array_Element and then
4837 Default_Switches_Array /= No_Array
4840 ("Default_Switches forbidden in presence of " &
4841 "Global_Compilation_Switches. Use Switches instead.",
4842 Project_Tree.Arrays.Table
4843 (Default_Switches_Array).Location);
4846 ("*** illegal combination of Builder attributes");
4849 -- If there is only one main, we attempt to get the gnatmake
4850 -- switches for this main (if any). If there are no specific
4851 -- switch for this particular main, get the general gnatmake
4852 -- switches (if any).
4854 if Osint.Number_Of_Files = 1 then
4855 if Verbose_Mode then
4856 Write_Str ("Adding gnatmake switches for """);
4857 Write_Str (Main_Unit_File_Name);
4862 (Project_Node_Tree => Project_Node_Tree,
4863 File_Name => Main_Unit_File_Name,
4864 Index => Main_Index,
4865 The_Package => Builder_Package,
4867 Unknown_Switches_To_The_Compiler =>
4868 Global_Compilation_Array = No_Array_Element);
4871 -- If there are several mains, we always get the general
4872 -- gnatmake switches (if any).
4874 -- Warn the user, if necessary, so that he is not surprised
4875 -- that specific switches are not taken into account.
4878 Defaults : constant Variable_Value :=
4882 Attribute_Or_Array_Name =>
4883 Name_Default_Switches,
4886 In_Tree => Project_Tree);
4888 Switches : constant Array_Element_Id :=
4890 (Name => Name_Switches,
4892 Project_Tree.Packages.Table
4893 (Builder_Package).Decl.Arrays,
4894 In_Tree => Project_Tree);
4896 Other_Switches : constant Variable_Value :=
4898 (Name => All_Other_Names,
4900 Attribute_Or_Array_Name
4902 In_Package => Builder_Package,
4903 In_Tree => Project_Tree);
4906 if Other_Switches /= Nil_Variable_Value then
4908 and then Switches /= No_Array_Element
4909 and then Project_Tree.Array_Elements.Table
4910 (Switches).Next /= No_Array_Element
4913 ("Warning: using Builder'Switches(others), "
4914 & "as there are several mains");
4918 (Project_Node_Tree => Project_Node_Tree,
4921 The_Package => Builder_Package,
4923 Unknown_Switches_To_The_Compiler => False);
4925 elsif Defaults /= Nil_Variable_Value then
4927 and then Switches /= No_Array_Element
4930 ("Warning: using Builder'Default_Switches"
4931 & "(""Ada""), as there are several mains");
4935 (Project_Node_Tree => Project_Node_Tree,
4938 The_Package => Builder_Package,
4941 elsif not Quiet_Output
4942 and then Switches /= No_Array_Element
4945 ("Warning: using no switches from package "
4946 & "Builder, as there are several mains");
4951 -- Take into account attribute Global_Compilation_Switches
4956 List : String_List_Id;
4957 Elem : String_Element;
4960 while Global_Compilation_Array /= No_Array_Element loop
4961 Global_Compilation_Elem :=
4962 Project_Tree.Array_Elements.Table
4963 (Global_Compilation_Array);
4965 Get_Name_String (Global_Compilation_Elem.Index);
4966 To_Lower (Name_Buffer (1 .. Name_Len));
4969 if Index = Name_Ada then
4970 Global_Compilation_Switches :=
4971 Global_Compilation_Elem.Value;
4973 if Global_Compilation_Switches /= Nil_Variable_Value
4974 and then not Global_Compilation_Switches.Default
4976 -- We have found attribute
4977 -- Global_Compilation_Switches ("Ada"): put the
4978 -- switches in the appropriate table.
4980 List := Global_Compilation_Switches.Values;
4982 while List /= Nil_String loop
4984 Project_Tree.String_Elements.Table (List);
4986 if Elem.Value /= No_Name then
4988 (Get_Name_String (Elem.Value),
5000 Global_Compilation_Array := Global_Compilation_Elem.Next;
5005 Osint.Add_Default_Search_Dirs;
5007 -- Record the current last switch index for table Binder_Switches
5008 -- and Linker_Switches, so that these tables may be reset before
5009 -- for each main, before adding switches from the project file
5010 -- and from the command line.
5012 Last_Binder_Switch := Binder_Switches.Last;
5013 Last_Linker_Switch := Linker_Switches.Last;
5017 -- Add binder switches from the project file for the first main
5019 if Do_Bind_Step and then Binder_Package /= No_Package then
5020 if Verbose_Mode then
5021 Write_Str ("Adding binder switches for """);
5022 Write_Str (Main_Unit_File_Name);
5027 (Project_Node_Tree => Project_Node_Tree,
5028 File_Name => Main_Unit_File_Name,
5029 Index => Main_Index,
5030 The_Package => Binder_Package,
5034 -- Add linker switches from the project file for the first main
5036 if Do_Link_Step and then Linker_Package /= No_Package then
5037 if Verbose_Mode then
5038 Write_Str ("Adding linker switches for""");
5039 Write_Str (Main_Unit_File_Name);
5044 (Project_Node_Tree => Project_Node_Tree,
5045 File_Name => Main_Unit_File_Name,
5046 Index => Main_Index,
5047 The_Package => Linker_Package,
5053 -- Get the target parameters, which are only needed for a couple of
5054 -- cases in gnatmake. Protect against an exception, such as the case
5055 -- of system.ads missing from the library, and fail gracefully.
5058 Targparm.Get_Target_Parameters;
5060 when Unrecoverable_Error =>
5061 Make_Failed ("*** make failed.");
5064 -- Special processing for VM targets
5066 if Targparm.VM_Target /= No_VM then
5068 -- Set proper processing commands
5070 case Targparm.VM_Target is
5071 when Targparm.JVM_Target =>
5073 -- Do not check for an object file (".o") when compiling to
5074 -- JVM machine since ".class" files are generated instead.
5076 Check_Object_Consistency := False;
5077 Gcc := new String'("jvm-gnatcompile");
5079 when Targparm
.CLI_Target
=>
5080 Gcc
:= new String'("dotnet-gnatcompile");
5082 when Targparm.No_VM =>
5083 raise Program_Error;
5087 Display_Commands (not Quiet_Output);
5091 if Main_Project /= No_Project then
5093 -- For all library project, if the library file does not exist, put
5094 -- all the project sources in the queue, and flag the project so that
5095 -- the library is generated.
5097 if not Unique_Compile
5098 and then MLib.Tgt.Support_For_Libraries /= Prj.None
5101 Proj : Project_List;
5104 Proj := Project_Tree.Projects;
5105 while Proj /= null loop
5106 if Proj.Project.Library then
5107 Proj.Project.Need_To_Build_Lib :=
5108 not MLib.Tgt.Library_Exists_For
5109 (Proj.Project, Project_Tree)
5110 and then not Proj.Project.Externally_Built;
5112 if Proj.Project.Need_To_Build_Lib then
5114 -- If there is no object directory, then it will be
5115 -- impossible to build the library. So fail
5119 Proj.Project.Object_Directory = No_Path_Information
5122 ("no object files to build library for project """
5123 & Get_Name_String (Proj.Project.Name)
5125 Proj.Project.Need_To_Build_Lib := False;
5128 if Verbose_Mode then
5130 ("Library file does not exist for project """);
5131 Write_Str (Get_Name_String (Proj.Project.Name));
5135 Insert_Project_Sources
5136 (The_Project => Proj.Project,
5137 All_Projects => False,
5148 -- If a relative path output file has been specified, we add
5149 -- the exec directory.
5151 for J in reverse 1 .. Saved_Linker_Switches.Last - 1 loop
5152 if Saved_Linker_Switches.Table (J).all = Output_Flag.all then
5154 Exec_File_Name : constant String :=
5155 Saved_Linker_Switches.Table (J + 1).all;
5158 if not Is_Absolute_Path (Exec_File_Name) then
5159 Get_Name_String (Main_Project.Exec_Directory.Name);
5162 Is_Directory_Separator (Name_Buffer (Name_Len))
5164 Add_Char_To_Name_Buffer (Directory_Separator);
5167 Add_Str_To_Name_Buffer (Exec_File_Name);
5168 Saved_Linker_Switches.Table (J + 1) :=
5169 new String'(Name_Buffer
(1 .. Name_Len
));
5177 -- If we are using a project file, for relative paths we add the
5178 -- current working directory for any relative path on the command
5179 -- line and the project directory, for any relative path in the
5183 Dir_Path
: constant String :=
5184 Get_Name_String
(Main_Project
.Directory
.Name
);
5186 for J
in 1 .. Binder_Switches
.Last
loop
5187 Test_If_Relative_Path
5188 (Binder_Switches
.Table
(J
),
5189 Parent
=> Dir_Path
, Including_L_Switch
=> False);
5192 for J
in 1 .. Saved_Binder_Switches
.Last
loop
5193 Test_If_Relative_Path
5194 (Saved_Binder_Switches
.Table
(J
),
5195 Parent
=> Current_Work_Dir
.all, Including_L_Switch
=> False);
5198 for J
in 1 .. Linker_Switches
.Last
loop
5199 Test_If_Relative_Path
5200 (Linker_Switches
.Table
(J
), Parent
=> Dir_Path
);
5203 for J
in 1 .. Saved_Linker_Switches
.Last
loop
5204 Test_If_Relative_Path
5205 (Saved_Linker_Switches
.Table
(J
),
5206 Parent
=> Current_Work_Dir
.all);
5209 for J
in 1 .. Gcc_Switches
.Last
loop
5210 Test_If_Relative_Path
5211 (Gcc_Switches
.Table
(J
),
5213 Including_Non_Switch
=> False);
5216 for J
in 1 .. Saved_Gcc_Switches
.Last
loop
5217 Test_If_Relative_Path
5218 (Saved_Gcc_Switches
.Table
(J
),
5219 Parent
=> Current_Work_Dir
.all,
5220 Including_Non_Switch
=> False);
5225 -- We now put in the Binder_Switches and Linker_Switches tables, the
5226 -- binder and linker switches of the command line that have been put in
5227 -- the Saved_ tables. If a project file was used, then the command line
5228 -- switches will follow the project file switches.
5230 for J
in 1 .. Saved_Binder_Switches
.Last
loop
5232 (Saved_Binder_Switches
.Table
(J
),
5237 for J
in 1 .. Saved_Linker_Switches
.Last
loop
5239 (Saved_Linker_Switches
.Table
(J
),
5244 -- If no project file is used, we just put the gcc switches
5245 -- from the command line in the Gcc_Switches table.
5247 if Main_Project
= No_Project
then
5248 for J
in 1 .. Saved_Gcc_Switches
.Last
loop
5250 (Saved_Gcc_Switches
.Table
(J
), Compiler
, And_Save
=> False);
5254 -- If there is a project, put the command line gcc switches in the
5255 -- variable The_Saved_Gcc_Switches. They are going to be used later
5256 -- in procedure Compile_Sources.
5258 The_Saved_Gcc_Switches
:=
5259 new Argument_List
(1 .. Saved_Gcc_Switches
.Last
+ 1);
5261 for J
in 1 .. Saved_Gcc_Switches
.Last
loop
5262 The_Saved_Gcc_Switches
(J
) := Saved_Gcc_Switches
.Table
(J
);
5265 -- We never use gnat.adc when a project file is used
5267 The_Saved_Gcc_Switches
(The_Saved_Gcc_Switches
'Last) := No_gnat_adc
;
5270 -- If there was a --GCC, --GNATBIND or --GNATLINK switch on
5271 -- the command line, then we have to use it, even if there was
5272 -- another switch in the project file.
5274 if Saved_Gcc
/= null then
5278 if Saved_Gnatbind
/= null then
5279 Gnatbind
:= Saved_Gnatbind
;
5282 if Saved_Gnatlink
/= null then
5283 Gnatlink
:= Saved_Gnatlink
;
5286 Gcc_Path
:= GNAT
.OS_Lib
.Locate_Exec_On_Path
(Gcc
.all);
5287 Gnatbind_Path
:= GNAT
.OS_Lib
.Locate_Exec_On_Path
(Gnatbind
.all);
5288 Gnatlink_Path
:= GNAT
.OS_Lib
.Locate_Exec_On_Path
(Gnatlink
.all);
5290 -- If we have specified -j switch both from the project file
5291 -- and on the command line, the one from the command line takes
5294 if Saved_Maximum_Processes
= 0 then
5295 Saved_Maximum_Processes
:= Maximum_Processes
;
5298 -- Allocate as many temporary mapping file names as the maximum number
5299 -- of compilations processed, for each possible project.
5302 Data
: Project_Compilation_Access
;
5303 Proj
: Project_List
:= Project_Tree
.Projects
;
5305 while Proj
/= null loop
5306 Data
:= new Project_Compilation_Data
'
5307 (Mapping_File_Names => new Temp_Path_Names
5308 (1 .. Saved_Maximum_Processes),
5309 Last_Mapping_File_Names => 0,
5310 Free_Mapping_File_Indices => new Free_File_Indices
5311 (1 .. Saved_Maximum_Processes),
5312 Last_Free_Indices => 0);
5314 Project_Compilation_Htable.Set
5315 (Project_Compilation, Proj.Project, Data);
5319 Data := new Project_Compilation_Data'
5320 (Mapping_File_Names
=> new Temp_Path_Names
5321 (1 .. Saved_Maximum_Processes
),
5322 Last_Mapping_File_Names
=> 0,
5323 Free_Mapping_File_Indices
=> new Free_File_Indices
5324 (1 .. Saved_Maximum_Processes
),
5325 Last_Free_Indices
=> 0);
5327 Project_Compilation_Htable
.Set
5328 (Project_Compilation
, No_Project
, Data
);
5331 Bad_Compilation
.Init
;
5333 -- If project files are used, create the mapping of all the sources, so
5334 -- that the correct paths will be found. Otherwise, if there is a file
5335 -- which is not a source with the same name in a source directory this
5336 -- file may be incorrectly found.
5338 if Main_Project
/= No_Project
then
5339 Prj
.Env
.Create_Mapping
(Project_Tree
);
5342 Current_Main_Index
:= Main_Index
;
5344 -- Here is where the make process is started
5346 -- We do the same process for each main
5348 Multiple_Main_Loop
: for N_File
in 1 .. Osint
.Number_Of_Files
loop
5350 -- First, find the executable name and path
5352 Executable
:= No_File
;
5353 Executable_Obsolete
:= False;
5354 Non_Std_Executable
:=
5355 Targparm
.Executable_Extension_On_Target
/= No_Name
;
5357 -- Look inside the linker switches to see if the name of the final
5358 -- executable program was specified.
5360 for J
in reverse Linker_Switches
.First
.. Linker_Switches
.Last
loop
5361 if Linker_Switches
.Table
(J
).all = Output_Flag
.all then
5362 pragma Assert
(J
< Linker_Switches
.Last
);
5364 -- We cannot specify a single executable for several main
5367 if Osint
.Number_Of_Files
> 1 then
5369 ("cannot specify a single executable for several mains");
5373 Add_Str_To_Name_Buffer
(Linker_Switches
.Table
(J
+ 1).all);
5374 Executable
:= Name_Enter
;
5376 Verbose_Msg
(Executable
, "final executable");
5380 -- If the name of the final executable program was not specified then
5381 -- construct it from the main input file.
5383 if Executable
= No_File
then
5384 if Main_Project
= No_Project
then
5385 Executable
:= Executable_Name
(Strip_Suffix
(Main_Source_File
));
5388 -- If we are using a project file, we attempt to remove the
5389 -- body (or spec) termination of the main subprogram. We find
5390 -- it the naming scheme of the project file. This avoids
5391 -- generating an executable "main.2" for a main subprogram
5392 -- "main.2.ada", when the body termination is ".2.ada".
5395 Prj
.Util
.Executable_Of
5396 (Main_Project
, Project_Tree
, Main_Source_File
, Main_Index
);
5400 if Main_Project
/= No_Project
5401 and then Main_Project
.Exec_Directory
/= No_Path_Information
5404 Exec_File_Name
: constant String :=
5405 Get_Name_String
(Executable
);
5408 if not Is_Absolute_Path
(Exec_File_Name
) then
5409 Get_Name_String
(Main_Project
.Exec_Directory
.Display_Name
);
5411 if Name_Buffer
(Name_Len
) /= Directory_Separator
then
5412 Add_Char_To_Name_Buffer
(Directory_Separator
);
5415 Add_Str_To_Name_Buffer
(Exec_File_Name
);
5416 Executable
:= Name_Find
;
5419 Non_Std_Executable
:= True;
5423 if Do_Compile_Step
then
5424 Recursive_Compilation_Step
: declare
5425 Args
: Argument_List
(1 .. Gcc_Switches
.Last
);
5427 First_Compiled_File
: File_Name_Type
;
5428 Youngest_Obj_File
: File_Name_Type
;
5429 Youngest_Obj_Stamp
: Time_Stamp_Type
;
5431 Executable_Stamp
: Time_Stamp_Type
;
5432 -- Executable is the final executable program
5433 -- ??? comment seems unrelated to declaration
5435 Library_Rebuilt
: Boolean := False;
5438 for J
in 1 .. Gcc_Switches
.Last
loop
5439 Args
(J
) := Gcc_Switches
.Table
(J
);
5442 -- Now we invoke Compile_Sources for the current main
5445 (Main_Source
=> Main_Source_File
,
5447 First_Compiled_File
=> First_Compiled_File
,
5448 Most_Recent_Obj_File
=> Youngest_Obj_File
,
5449 Most_Recent_Obj_Stamp
=> Youngest_Obj_Stamp
,
5450 Main_Unit
=> Is_Main_Unit
,
5451 Main_Index
=> Current_Main_Index
,
5452 Compilation_Failures
=> Compilation_Failures
,
5453 Check_Readonly_Files
=> Check_Readonly_Files
,
5454 Do_Not_Execute
=> Do_Not_Execute
,
5455 Force_Compilations
=> Force_Compilations
,
5456 In_Place_Mode
=> In_Place_Mode
,
5457 Keep_Going
=> Keep_Going
,
5458 Initialize_ALI_Data
=> True,
5459 Max_Process
=> Saved_Maximum_Processes
);
5461 if Verbose_Mode
then
5462 Write_Str
("End of compilation");
5466 -- Make sure the queue will be reinitialized for the next round
5468 First_Q_Initialization
:= True;
5470 Total_Compilation_Failures
:=
5471 Total_Compilation_Failures
+ Compilation_Failures
;
5473 if Total_Compilation_Failures
/= 0 then
5478 List_Bad_Compilations
;
5479 Report_Compilation_Failed
;
5483 -- Regenerate libraries, if there are any and if object files
5484 -- have been regenerated.
5486 if Main_Project
/= No_Project
5487 and then MLib
.Tgt
.Support_For_Libraries
/= Prj
.None
5488 and then (Do_Bind_Step
5489 or Unique_Compile_All_Projects
5490 or not Compile_Only
)
5491 and then (Do_Link_Step
or else N_File
= Osint
.Number_Of_Files
)
5498 Proj1
: Project_List
;
5500 procedure Add_To_Library_Projs
(Proj
: Project_Id
);
5501 -- Add project Project to table Library_Projs in
5502 -- decreasing depth order.
5504 --------------------------
5505 -- Add_To_Library_Projs --
5506 --------------------------
5508 procedure Add_To_Library_Projs
(Proj
: Project_Id
) is
5512 Library_Projs
.Increment_Last
;
5513 Depth
:= Proj
.Depth
;
5515 -- Put the projects in decreasing depth order, so that
5516 -- if libA depends on libB, libB is first in order.
5518 Current
:= Library_Projs
.Last
;
5519 while Current
> 1 loop
5520 Prj
:= Library_Projs
.Table
(Current
- 1);
5521 exit when Prj
.Depth
>= Depth
;
5522 Library_Projs
.Table
(Current
) := Prj
;
5523 Current
:= Current
- 1;
5526 Library_Projs
.Table
(Current
) := Proj
;
5527 end Add_To_Library_Projs
;
5529 -- Start of processing for ??? (should name declare block
5530 -- or probably better, break this out as a nested proc).
5533 -- Put in Library_Projs table all library project file
5534 -- ids when the library need to be rebuilt.
5536 Proj1
:= Project_Tree
.Projects
;
5537 while Proj1
/= null loop
5538 if Proj1
.Project
.Standalone_Library
then
5539 Stand_Alone_Libraries
:= True;
5542 if Proj1
.Project
.Library
then
5543 MLib
.Prj
.Check_Library
5544 (Proj1
.Project
, Project_Tree
);
5547 if Proj1
.Project
.Need_To_Build_Lib
then
5548 Add_To_Library_Projs
(Proj1
.Project
);
5551 Proj1
:= Proj1
.Next
;
5554 -- Check if importing libraries should be regenerated
5555 -- because at least an imported library will be
5556 -- regenerated or is more recent.
5558 Proj1
:= Project_Tree
.Projects
;
5559 while Proj1
/= null loop
5560 if Proj1
.Project
.Library
5561 and then Proj1
.Project
.Library_Kind
/= Static
5562 and then not Proj1
.Project
.Need_To_Build_Lib
5563 and then not Proj1
.Project
.Externally_Built
5566 List
: Project_List
;
5568 Rebuild
: Boolean := False;
5570 Lib_Timestamp1
: constant Time_Stamp_Type
:=
5571 Proj1
.Project
.Library_TS
;
5574 List
:= Proj1
.Project
.All_Imported_Projects
;
5575 while List
/= null loop
5576 Proj2
:= List
.Project
;
5578 if Proj2
.Library
then
5579 if Proj2
.Need_To_Build_Lib
5581 (Lib_Timestamp1
< Proj2
.Library_TS
)
5592 Proj1
.Project
.Need_To_Build_Lib
:= True;
5593 Add_To_Library_Projs
(Proj1
.Project
);
5598 Proj1
:= Proj1
.Next
;
5601 -- Reset the flags Need_To_Build_Lib for the next main,
5602 -- to avoid rebuilding libraries uselessly.
5604 Proj1
:= Project_Tree
.Projects
;
5605 while Proj1
/= null loop
5606 Proj1
.Project
.Need_To_Build_Lib
:= False;
5607 Proj1
:= Proj1
.Next
;
5611 -- Build the libraries, if any need to be built
5613 for J
in 1 .. Library_Projs
.Last
loop
5614 Library_Rebuilt
:= True;
5616 -- If a library is rebuilt, then executables are obsolete
5618 Executable_Obsolete
:= True;
5620 MLib
.Prj
.Build_Library
5621 (For_Project
=> Library_Projs
.Table
(J
),
5622 In_Tree
=> Project_Tree
,
5623 Gnatbind
=> Gnatbind
.all,
5624 Gnatbind_Path
=> Gnatbind_Path
,
5626 Gcc_Path
=> Gcc_Path
);
5630 if List_Dependencies
then
5631 if First_Compiled_File
/= No_File
then
5633 (First_Compiled_File
,
5634 "must be recompiled. Can't generate dependence list.");
5639 elsif First_Compiled_File
= No_File
5640 and then not Do_Bind_Step
5641 and then not Quiet_Output
5642 and then not Library_Rebuilt
5643 and then Osint
.Number_Of_Files
= 1
5645 Inform
(Msg
=> "objects up to date.");
5647 elsif Do_Not_Execute
5648 and then First_Compiled_File
/= No_File
5650 Write_Name
(First_Compiled_File
);
5654 -- Stop after compile step if any of:
5656 -- 1) -n (Do_Not_Execute) specified
5658 -- 2) -M (List_Dependencies) specified (also sets
5659 -- Do_Not_Execute above, so this is probably superfluous).
5661 -- 3) -c (Compile_Only) specified, but not -b (Bind_Only)
5663 -- 4) Made unit cannot be a main unit
5666 or List_Dependencies
5668 or not Is_Main_Unit
)
5669 and then not No_Main_Subprogram
5670 and then not Build_Bind_And_Link_Full_Project
)
5671 or else Unique_Compile
5673 if Osint
.Number_Of_Files
= 1 then
5674 exit Multiple_Main_Loop
;
5681 -- If the objects were up-to-date check if the executable file
5682 -- is also up-to-date. For now always bind and link on the JVM
5683 -- since there is currently no simple way to check whether
5684 -- objects are up-to-date.
5686 if Targparm
.VM_Target
/= JVM_Target
5687 and then First_Compiled_File
= No_File
5689 Executable_Stamp
:= File_Stamp
(Executable
);
5691 if not Executable_Obsolete
then
5692 Executable_Obsolete
:=
5693 Youngest_Obj_Stamp
> Executable_Stamp
;
5696 if not Executable_Obsolete
then
5697 for Index
in reverse 1 .. Dependencies
.Last
loop
5699 (Dependencies
.Table
(Index
).Depends_On
)
5701 Enter_Into_Obsoleted
5702 (Dependencies
.Table
(Index
).This
);
5706 Executable_Obsolete
:= Is_In_Obsoleted
(Main_Source_File
);
5710 if not Executable_Obsolete
then
5712 -- If no Ada object files obsolete the executable, check
5713 -- for younger or missing linker files.
5715 Check_Linker_Options
5718 Youngest_Obj_Stamp
);
5720 Executable_Obsolete
:= Youngest_Obj_File
/= No_File
;
5723 -- Check if any library file is more recent than the
5724 -- executable: there may be an externally built library
5725 -- file that has been modified.
5727 if not Executable_Obsolete
5728 and then Main_Project
/= No_Project
5731 Proj1
: Project_List
;
5734 Proj1
:= Project_Tree
.Projects
;
5735 while Proj1
/= null loop
5736 if Proj1
.Project
.Library
5738 Proj1
.Project
.Library_TS
> Executable_Stamp
5740 Executable_Obsolete
:= True;
5741 Youngest_Obj_Stamp
:= Proj1
.Project
.Library_TS
;
5743 Add_Str_To_Name_Buffer
("library ");
5744 Add_Str_To_Name_Buffer
5745 (Get_Name_String
(Proj1
.Project
.Library_Name
));
5746 Youngest_Obj_File
:= Name_Find
;
5750 Proj1
:= Proj1
.Next
;
5755 -- Return if the executable is up to date and otherwise
5756 -- motivate the relink/rebind.
5758 if not Executable_Obsolete
then
5759 if not Quiet_Output
then
5760 Inform
(Executable
, "up to date.");
5763 if Osint
.Number_Of_Files
= 1 then
5764 exit Multiple_Main_Loop
;
5771 if Executable_Stamp
(1) = ' ' then
5772 if not No_Main_Subprogram
then
5773 Verbose_Msg
(Executable
, "missing.", Prefix
=> " ");
5776 elsif Youngest_Obj_Stamp
(1) = ' ' then
5778 (Youngest_Obj_File
, "missing.", Prefix
=> " ");
5780 elsif Youngest_Obj_Stamp
> Executable_Stamp
then
5783 "(" & String (Youngest_Obj_Stamp
) & ") newer than",
5785 "(" & String (Executable_Stamp
) & ")");
5789 (Executable
, "needs to be rebuilt", Prefix
=> " ");
5793 end Recursive_Compilation_Step
;
5796 -- For binding and linking, we need to be in the object directory of
5797 -- the main project.
5799 if Main_Project
/= No_Project
then
5800 Change_To_Object_Directory
(Main_Project
);
5803 -- If we are here, it means that we need to rebuilt the current main,
5804 -- so we set Executable_Obsolete to True to make sure that subsequent
5805 -- mains will be rebuilt.
5807 Main_ALI_In_Place_Mode_Step
: declare
5808 ALI_File
: File_Name_Type
;
5809 Src_File
: File_Name_Type
;
5812 Src_File
:= Strip_Directory
(Main_Source_File
);
5813 ALI_File
:= Lib_File_Name
(Src_File
, Current_Main_Index
);
5814 Main_ALI_File
:= Full_Lib_File_Name
(ALI_File
);
5816 -- When In_Place_Mode, the library file can be located in the
5817 -- Main_Source_File directory which may not be present in the
5818 -- library path. If it is not present then use the corresponding
5819 -- library file name.
5821 if Main_ALI_File
= No_File
and then In_Place_Mode
then
5822 Get_Name_String
(Get_Directory
(Full_Source_Name
(Src_File
)));
5823 Get_Name_String_And_Append
(ALI_File
);
5824 Main_ALI_File
:= Name_Find
;
5825 Main_ALI_File
:= Full_Lib_File_Name
(Main_ALI_File
);
5828 if Main_ALI_File
= No_File
then
5829 Make_Failed
("could not find the main ALI file");
5831 end Main_ALI_In_Place_Mode_Step
;
5833 if Do_Bind_Step
then
5835 Args
: Argument_List
5836 (Binder_Switches
.First
.. Binder_Switches
.Last
+ 2);
5837 -- The arguments for the invocation of gnatbind
5839 Last_Arg
: Natural := Binder_Switches
.Last
;
5840 -- Index of the last argument in Args
5842 Shared_Libs
: Boolean := False;
5843 -- Set to True when there are shared library project files or
5844 -- when gnatbind is invoked with -shared.
5846 Proj
: Project_List
;
5849 -- Check if there are shared libraries, so that gnatbind is
5850 -- called with -shared. Check also if gnatbind is called with
5851 -- -shared, so that gnatlink is called with -shared-libgcc
5852 -- ensuring that the shared version of libgcc will be used.
5854 if Main_Project
/= No_Project
5855 and then MLib
.Tgt
.Support_For_Libraries
/= Prj
.None
5857 Proj
:= Project_Tree
.Projects
;
5858 while Proj
/= null loop
5859 if Proj
.Project
.Library
5860 and then Proj
.Project
.Library_Kind
/= Static
5862 Shared_Libs
:= True;
5863 Bind_Shared
:= Shared_Switch
'Access;
5870 -- Check now for switch -shared
5872 if not Shared_Libs
then
5873 for J
in Binder_Switches
.First
.. Last_Arg
loop
5874 if Binder_Switches
.Table
(J
).all = "-shared" then
5875 Shared_Libs
:= True;
5881 -- If shared libraries present, invoke gnatlink with
5885 Link_With_Shared_Libgcc
:= Shared_Libgcc_Switch
'Access;
5888 -- Get all the binder switches
5890 for J
in Binder_Switches
.First
.. Last_Arg
loop
5891 Args
(J
) := Binder_Switches
.Table
(J
);
5894 if Stand_Alone_Libraries
then
5895 Last_Arg
:= Last_Arg
+ 1;
5896 Args
(Last_Arg
) := Force_Elab_Flags_String
'Access;
5899 if Main_Project
/= No_Project
then
5901 -- Put all the source directories in ADA_INCLUDE_PATH,
5902 -- and all the object directories in ADA_OBJECTS_PATH,
5903 -- except those of library projects.
5905 Prj
.Env
.Set_Ada_Paths
(Main_Project
, Project_Tree
, False);
5907 -- If switch -C was specified, create a binder mapping file
5909 if Create_Mapping_File
then
5910 Create_Binder_Mapping_File
(Args
, Last_Arg
);
5916 Bind
(Main_ALI_File
,
5917 Bind_Shared
.all & Args
(Args
'First .. Last_Arg
));
5922 -- Delete the temporary mapping file, if one was created.
5924 if Mapping_Path
/= No_Path
then
5925 Delete_Temporary_File
(Project_Tree
, Mapping_Path
);
5928 -- And reraise the exception
5933 -- If -dn was not specified, delete the temporary mapping file,
5934 -- if one was created.
5936 if Mapping_Path
/= No_Path
then
5937 Delete_Temporary_File
(Project_Tree
, Mapping_Path
);
5942 if Do_Link_Step
then
5944 Linker_Switches_Last
: constant Integer := Linker_Switches
.Last
;
5945 Path_Option
: constant String_Access
:=
5946 MLib
.Linker_Library_Path_Option
;
5947 Libraries_Present
: Boolean := False;
5951 Proj1
: Project_List
;
5954 if not Run_Path_Option
then
5955 Linker_Switches
.Increment_Last
;
5956 Linker_Switches
.Table
(Linker_Switches
.Last
) :=
5960 if Main_Project /= No_Project then
5961 Library_Paths.Set_Last (0);
5964 if MLib.Tgt.Support_For_Libraries /= Prj.None then
5966 -- Check for library projects
5968 Proj1 := Project_Tree.Projects;
5969 while Proj1 /= null loop
5970 if Proj1.Project /= Main_Project
5971 and then Proj1.Project.Library
5973 -- Add this project to table Library_Projs
5975 Libraries_Present := True;
5976 Depth := Proj1.Project.Depth;
5977 Library_Projs.Increment_Last;
5978 Current := Library_Projs.Last;
5980 -- Any project with a greater depth should be
5981 -- after this project in the list.
5983 while Current > 1 loop
5984 Proj2 := Library_Projs.Table (Current - 1);
5985 exit when Proj2.Depth <= Depth;
5986 Library_Projs.Table (Current) := Proj2;
5987 Current := Current - 1;
5990 Library_Projs.Table (Current) := Proj1.Project;
5992 -- If it is not a static library and path option
5993 -- is set, add it to the Library_Paths table.
5995 if Proj1.Project.Library_Kind /= Static
5996 and then Path_Option /= null
5998 Library_Paths.Increment_Last;
5999 Library_Paths.Table (Library_Paths.Last) :=
6002 (Proj1
.Project
.Library_Dir
.Display_Name
));
6006 Proj1
:= Proj1
.Next
;
6009 for Index
in 1 .. Library_Projs
.Last
loop
6011 -- Add the -L switch
6013 Linker_Switches
.Increment_Last
;
6014 Linker_Switches
.Table
(Linker_Switches
.Last
) :=
6017 (Library_Projs.Table (Index).
6018 Library_Dir.Display_Name));
6020 -- Add the -l switch
6022 Linker_Switches.Increment_Last;
6023 Linker_Switches.Table (Linker_Switches.Last) :=
6026 (Library_Projs
.Table
(Index
).
6031 if Libraries_Present
then
6033 -- If Path_Option is not null, create the switch
6034 -- ("-Wl,-rpath," or equivalent) with all the non static
6035 -- library dirs plus the standard GNAT library dir.
6036 -- We do that only if Run_Path_Option is True
6037 -- (not disabled by -R switch).
6039 if Run_Path_Option
and then Path_Option
/= null then
6041 Option
: String_Access
;
6042 Length
: Natural := Path_Option
'Length;
6046 if MLib
.Separate_Run_Path_Options
then
6048 -- We are going to create one switch of the form
6049 -- "-Wl,-rpath,dir_N" for each directory to
6052 -- One switch for each library directory
6055 Library_Paths
.First
.. Library_Paths
.Last
6057 Linker_Switches
.Increment_Last
;
6058 Linker_Switches
.Table
6059 (Linker_Switches
.Last
) := new String'
6061 Library_Paths.Table (Index).all);
6064 -- One switch for the standard GNAT library dir
6066 Linker_Switches.Increment_Last;
6067 Linker_Switches.Table
6068 (Linker_Switches.Last) := new String'
6069 (Path_Option
.all & MLib
.Utl
.Lib_Directory
);
6072 -- We are going to create one switch of the form
6073 -- "-Wl,-rpath,dir_1:dir_2:dir_3"
6076 Library_Paths
.First
.. Library_Paths
.Last
6078 -- Add the length of the library dir plus one
6079 -- for the directory separator.
6083 Library_Paths
.Table
(Index
)'Length + 1;
6086 -- Finally, add the length of the standard GNAT
6089 Length
:= Length
+ MLib
.Utl
.Lib_Directory
'Length;
6090 Option
:= new String (1 .. Length
);
6091 Option
(1 .. Path_Option
'Length) :=
6093 Current
:= Path_Option
'Length;
6095 -- Put each library dir followed by a dir
6099 Library_Paths
.First
.. Library_Paths
.Last
6104 Library_Paths
.Table
(Index
)'Length) :=
6105 Library_Paths
.Table
(Index
).all;
6108 Library_Paths
.Table
(Index
)'Length + 1;
6109 Option
(Current
) := Path_Separator
;
6112 -- Finally put the standard GNAT library dir
6116 Current
+ MLib
.Utl
.Lib_Directory
'Length) :=
6117 MLib
.Utl
.Lib_Directory
;
6119 -- And add the switch to the linker switches
6121 Linker_Switches
.Increment_Last
;
6122 Linker_Switches
.Table
(Linker_Switches
.Last
) :=
6130 -- Put the object directories in ADA_OBJECTS_PATH
6132 Prj
.Env
.Set_Ada_Paths
(Main_Project
, Project_Tree
, False);
6134 -- Check for attributes Linker'Linker_Options in projects
6135 -- other than the main project
6138 Linker_Options
: constant String_List
:=
6139 Linker_Options_Switches
6140 (Main_Project
, Project_Tree
);
6142 for Option
in Linker_Options
'Range loop
6143 Linker_Switches
.Increment_Last
;
6144 Linker_Switches
.Table
(Linker_Switches
.Last
) :=
6145 Linker_Options
(Option
);
6151 Args
: Argument_List
6152 (Linker_Switches
.First
.. Linker_Switches
.Last
+ 2);
6154 Last_Arg
: Integer := Linker_Switches
.First
- 1;
6155 Skip
: Boolean := False;
6158 -- Get all the linker switches
6160 for J
in Linker_Switches
.First
.. Linker_Switches
.Last
loop
6164 elsif Non_Std_Executable
6165 and then Linker_Switches
.Table
(J
).all = "-o"
6169 -- Here we capture and duplicate the linker argument. We
6170 -- need to do the duplication since the arguments will
6171 -- get normalized. Not doing so will result in calling
6172 -- normalized two times for the same set of arguments if
6173 -- gnatmake is passed multiple mains. This can result in
6174 -- the wrong argument being passed to the linker.
6177 Last_Arg
:= Last_Arg
+ 1;
6179 new String'(Linker_Switches.Table (J).all);
6183 -- If need be, add the -o switch
6185 if Non_Std_Executable then
6186 Last_Arg := Last_Arg + 1;
6187 Args (Last_Arg) := new String'("-o");
6188 Last_Arg
:= Last_Arg
+ 1;
6190 new String'(Get_Name_String (Executable));
6193 -- And invoke the linker
6196 Success : Boolean := False;
6198 Link (Main_ALI_File,
6199 Link_With_Shared_Libgcc.all &
6200 Args (Args'First .. Last_Arg),
6204 Successful_Links.Increment_Last;
6205 Successful_Links.Table (Successful_Links.Last) :=
6208 elsif Osint.Number_Of_Files = 1
6209 or else not Keep_Going
6211 Make_Failed ("*** link failed.");
6215 Write_Line ("*** link failed");
6217 if Commands_To_Stdout then
6218 Set_Standard_Output;
6221 Failed_Links.Increment_Last;
6222 Failed_Links.Table (Failed_Links.Last) :=
6228 Linker_Switches.Set_Last (Linker_Switches_Last);
6232 -- We go to here when we skip the bind and link steps
6236 -- We go to the next main, if we did not process the last one
6238 if N_File < Osint.Number_Of_Files then
6239 Main_Source_File := Next_Main_Source;
6241 if Current_File_Index /= No_Index then
6242 Main_Index := Current_File_Index;
6245 if Main_Project /= No_Project then
6247 -- Find the file name of the main unit
6250 Main_Source_File_Name : constant String :=
6251 Get_Name_String (Main_Source_File);
6253 Main_Unit_File_Name : constant String :=
6255 File_Name_Of_Library_Unit_Body
6256 (Name => Main_Source_File_Name,
6257 Project => Main_Project,
6258 In_Tree => Project_Tree,
6259 Main_Project_Only =>
6260 not Unique_Compile);
6262 The_Packages : constant Package_Id :=
6263 Main_Project.Decl.Packages;
6265 Binder_Package : constant Prj.Package_Id :=
6267 (Name => Name_Binder,
6268 In_Packages => The_Packages,
6269 In_Tree => Project_Tree);
6271 Linker_Package : constant Prj.Package_Id :=
6273 (Name => Name_Linker,
6274 In_Packages => The_Packages,
6275 In_Tree => Project_Tree);
6278 -- We fail if we cannot find the main source file
6279 -- as an immediate source of the main project file.
6281 if Main_Unit_File_Name = "" then
6282 Make_Failed ('"' & Main_Source_File_Name
6283 & """ is not a unit
of project
"
6284 & Project_File_Name.all & ".");
6287 -- Remove any directory information from the main
6288 -- source file name.
6291 Pos : Natural := Main_Unit_File_Name'Last;
6295 exit when Pos < Main_Unit_File_Name'First
6297 Main_Unit_File_Name (Pos) = Directory_Separator;
6301 Name_Len := Main_Unit_File_Name'Last - Pos;
6303 Name_Buffer (1 .. Name_Len) :=
6305 (Pos + 1 .. Main_Unit_File_Name'Last);
6307 Main_Source_File := Name_Find;
6311 -- We now deal with the binder and linker switches.
6312 -- If no project file is used, there is nothing to do
6313 -- because the binder and linker switches are the same
6316 -- Reset the tables Binder_Switches and Linker_Switches
6318 Binder_Switches.Set_Last (Last_Binder_Switch);
6319 Linker_Switches.Set_Last (Last_Linker_Switch);
6321 -- Add binder switches from the project file for this main,
6324 if Do_Bind_Step and then Binder_Package /= No_Package then
6325 if Verbose_Mode then
6326 Write_Str ("Adding binder switches
for """);
6327 Write_Str (Main_Unit_File_Name);
6332 (Project_Node_Tree => Project_Node_Tree,
6333 File_Name => Main_Unit_File_Name,
6334 Index => Main_Index,
6335 The_Package => Binder_Package,
6339 -- Add linker switches from the project file for this main,
6342 if Do_Link_Step and then Linker_Package /= No_Package then
6343 if Verbose_Mode then
6344 Write_Str ("Adding linker switches
for""");
6345 Write_Str (Main_Unit_File_Name);
6350 (Project_Node_Tree => Project_Node_Tree,
6351 File_Name => Main_Unit_File_Name,
6352 Index => Main_Index,
6353 The_Package => Linker_Package,
6357 -- As we are using a project file, for relative paths we add
6358 -- the current working directory for any relative path on
6359 -- the command line and the project directory, for any
6360 -- relative path in the project file.
6363 Dir_Path : constant String :=
6365 (Main_Project.Directory.Name);
6369 J in Last_Binder_Switch + 1 .. Binder_Switches.Last
6371 Test_If_Relative_Path
6372 (Binder_Switches.Table (J),
6373 Parent => Dir_Path, Including_L_Switch => False);
6377 J in Last_Linker_Switch + 1 .. Linker_Switches.Last
6379 Test_If_Relative_Path
6380 (Linker_Switches.Table (J), Parent => Dir_Path);
6384 -- We now put in the Binder_Switches and Linker_Switches
6385 -- tables, the binder and linker switches of the command
6386 -- line that have been put in the Saved_ tables.
6387 -- These switches will follow the project file switches.
6389 for J in 1 .. Saved_Binder_Switches.Last loop
6391 (Saved_Binder_Switches.Table (J),
6396 for J in 1 .. Saved_Linker_Switches.Last loop
6398 (Saved_Linker_Switches.Table (J),
6406 -- Remove all marks to be sure to check sources for all executables,
6407 -- as the switches may be different and -s may be in use.
6410 end loop Multiple_Main_Loop;
6412 if Failed_Links.Last > 0 then
6413 for Index in 1 .. Successful_Links.Last loop
6414 Write_Str ("Linking
of """);
6415 Write_Str (Get_Name_String (Successful_Links.Table (Index)));
6416 Write_Line (""" succeeded
.");
6421 for Index in 1 .. Failed_Links.Last loop
6422 Write_Str ("Linking
of """);
6423 Write_Str (Get_Name_String (Failed_Links.Table (Index)));
6424 Write_Line (""" failed
.");
6427 if Commands_To_Stdout then
6428 Set_Standard_Output;
6431 if Total_Compilation_Failures = 0 then
6432 Report_Compilation_Failed;
6436 if Total_Compilation_Failures /= 0 then
6437 List_Bad_Compilations;
6438 Report_Compilation_Failed;
6441 -- Delete the temporary mapping file that was created if we are
6442 -- using project files.
6444 Delete_All_Temp_Files;
6449 Write_Line (Exception_Information (X));
6450 Make_Failed ("INTERNAL ERROR
. Please report
.");
6457 function Hash (F : File_Name_Type) return Header_Num is
6459 return Header_Num (1 + F mod Max_Header);
6462 --------------------
6463 -- In_Ada_Lib_Dir --
6464 --------------------
6466 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean is
6467 D : constant File_Name_Type := Get_Directory (File);
6468 B : constant Byte := Get_Name_Table_Byte (D);
6470 return (B and Ada_Lib_Dir) /= 0;
6473 -----------------------
6474 -- Init_Mapping_File --
6475 -----------------------
6477 procedure Init_Mapping_File
6478 (Project : Project_Id;
6479 Data : in out Project_Compilation_Data;
6480 File_Index : in out Natural)
6482 FD : File_Descriptor;
6484 -- For call to Close
6487 -- Increase the index of the last mapping file for this project
6489 Data.Last_Mapping_File_Names := Data.Last_Mapping_File_Names + 1;
6491 -- If there is a project file, call Create_Mapping_File with
6494 if Project /= No_Project then
6495 Prj.Env.Create_Mapping_File
6497 In_Tree => Project_Tree,
6498 Language => Name_Ada,
6499 Name => Data.Mapping_File_Names
6500 (Data.Last_Mapping_File_Names));
6502 -- Otherwise, just create an empty file
6505 Tempdir.Create_Temp_File
6507 Data.Mapping_File_Names (Data.Last_Mapping_File_Names));
6509 if FD = Invalid_FD then
6510 Make_Failed ("disk full
");
6515 Data.Mapping_File_Names (Data.Last_Mapping_File_Names));
6521 Make_Failed ("disk full
");
6525 -- And return the index of the newly created file
6527 File_Index := Data.Last_Mapping_File_Names;
6528 end Init_Mapping_File;
6536 First_Q_Initialization := False;
6538 Q.Set_Last (Q.First);
6545 procedure Initialize (Project_Node_Tree : out Project_Node_Tree_Ref) is
6547 procedure Check_Version_And_Help is
6548 new Check_Version_And_Help_G (Makeusg);
6550 -- Start of processing for Initialize
6553 -- Prepare the project's tree, since this is used to hold external
6554 -- references, project path and other attributes that can be impacted by
6555 -- the command line switches
6557 Project_Node_Tree := new Project_Node_Tree_Data;
6558 Prj.Tree.Initialize (Project_Node_Tree);
6560 -- Override default initialization of Check_Object_Consistency since
6561 -- this is normally False for GNATBIND, but is True for GNATMAKE since
6562 -- we do not need to check source consistency again once GNATMAKE has
6563 -- looked at the sources to check.
6565 Check_Object_Consistency := True;
6567 -- Package initializations. The order of calls is important here
6569 Output.Set_Standard_Error;
6572 Binder_Switches.Init;
6573 Linker_Switches.Init;
6580 Prj.Initialize (Project_Tree);
6584 RTS_Specified := null;
6589 -- Add the directory where gnatmake is invoked in front of the
6590 -- path, if gnatmake is invoked from a bin directory or with directory
6591 -- information. Only do this if the platform is not VMS, where the
6592 -- notion of path does not really exist.
6596 Prefix : constant String := Executable_Prefix_Path;
6597 Command : constant String := Command_Name;
6600 if Prefix'Length > 0 then
6602 PATH : constant String :=
6603 Prefix & Directory_Separator & "bin
" &
6605 Getenv ("PATH
").all;
6607 Setenv ("PATH
", PATH);
6611 for Index in reverse Command'Range loop
6612 if Command (Index) = Directory_Separator then
6614 Absolute_Dir : constant String :=
6616 (Command (Command'First .. Index));
6617 PATH : constant String :=
6620 Getenv ("PATH
").all;
6622 Setenv ("PATH
", PATH);
6632 -- Scan the switches and arguments
6634 -- First, scan to detect --version and/or --help
6636 Check_Version_And_Help ("GNATMAKE
", "1995");
6638 -- Scan again the switch and arguments, now that we are sure that they
6639 -- do not include --version or --help.
6641 Scan_Args : for Next_Arg in 1 .. Argument_Count loop
6643 (Project_Node_Tree, Argument (Next_Arg), And_Save => True);
6646 if N_M_Switch > 0 and RTS_Specified = null then
6647 Process_Multilib (Project_Node_Tree);
6650 if Commands_To_Stdout then
6651 Set_Standard_Output;
6654 if Usage_Requested then
6658 -- Test for trailing -P switch
6660 if Project_File_Name_Present and then Project_File_Name = null then
6661 Make_Failed ("project file name missing after
-P
");
6663 -- Test for trailing -o switch
6665 elsif Output_File_Name_Present
6666 and then not Output_File_Name_Seen
6668 Make_Failed ("output file name missing after
-o
");
6670 -- Test for trailing -D switch
6672 elsif Object_Directory_Present
6673 and then not Object_Directory_Seen then
6674 Make_Failed ("object directory missing after
-D
");
6677 -- Test for simultaneity of -i and -D
6679 if Object_Directory_Path /= null and then In_Place_Mode then
6680 Make_Failed ("-i
and -D cannot be used simultaneously
");
6683 -- Deal with -C= switch
6685 if Gnatmake_Mapping_File /= null then
6687 -- First, check compatibility with other switches
6689 if Project_File_Name /= null then
6690 Make_Failed ("-C
= switch
is not compatible
with -P switch
");
6692 elsif Saved_Maximum_Processes > 1 then
6693 Make_Failed ("-C
= switch
is not compatible
with -jnnn switch
");
6696 Fmap.Initialize (Gnatmake_Mapping_File.all);
6698 ("-gnatem
=" & Gnatmake_Mapping_File.all,
6703 if Project_File_Name /= null then
6705 -- A project file was specified by a -P switch
6707 if Verbose_Mode then
6709 Write_Str ("Parsing project file
""");
6710 Write_Str (Project_File_Name.all);
6715 -- Avoid looking in the current directory for ALI files
6717 -- Look_In_Primary_Dir := False;
6719 -- Set the project parsing verbosity to whatever was specified
6720 -- by a possible -vP switch.
6722 Prj.Pars.Set_Verbosity (To => Current_Verbosity);
6724 -- Parse the project file.
6725 -- If there is an error, Main_Project will still be No_Project.
6728 (Project => Main_Project,
6729 In_Tree => Project_Tree,
6730 Project_File_Name => Project_File_Name.all,
6731 Packages_To_Check => Packages_To_Check_By_Gnatmake,
6732 Flags => Gnatmake_Flags,
6733 In_Node_Tree => Project_Node_Tree);
6735 -- The parsing of project files may have changed the current output
6737 if Commands_To_Stdout then
6738 Set_Standard_Output;
6743 if Main_Project = No_Project then
6745 ("""" & Project_File_Name.all & """ processing failed
");
6748 Create_Mapping_File := True;
6750 if Verbose_Mode then
6752 Write_Str ("Parsing
of project file
""");
6753 Write_Str (Project_File_Name.all);
6754 Write_Str (""" is finished
.");
6758 -- We add the source directories and the object directories
6759 -- to the search paths.
6761 Add_Source_Directories (Main_Project, Project_Tree);
6762 Add_Object_Directories (Main_Project);
6764 Recursive_Compute_Depth (Main_Project);
6766 -- For each project compute the list of the projects it imports
6767 -- directly or indirectly.
6770 Proj : Project_List;
6772 Proj := Project_Tree.Projects;
6773 while Proj /= null loop
6774 Compute_All_Imported_Projects (Proj.Project);
6781 Osint.Add_Default_Search_Dirs;
6783 -- Source file lookups should be cached for efficiency. Source files
6784 -- are not supposed to change. However, we do that now only if no
6785 -- project file is used; if a project file is used, we do it just
6786 -- after changing the directory to the object directory.
6788 Osint.Source_File_Data (Cache => True);
6790 -- Read gnat.adc file to initialize Fname.UF
6792 Fname.UF.Initialize;
6795 Fname.SF.Read_Source_File_Name_Pragmas;
6798 when Err : SFN_Scan.Syntax_Error_In_GNAT_ADC =>
6799 Make_Failed (Exception_Message (Err));
6803 -- Make sure no project object directory is recorded
6805 Project_Of_Current_Object_Directory := No_Project;
6809 ----------------------------
6810 -- Insert_Project_Sources --
6811 ----------------------------
6813 procedure Insert_Project_Sources
6814 (The_Project : Project_Id;
6815 All_Projects : Boolean;
6818 Put_In_Q : Boolean := Into_Q;
6820 Sfile : File_Name_Type;
6823 Extending : constant Boolean := The_Project.Extends /= No_Project;
6825 function Check_Project (P : Project_Id) return Boolean;
6826 -- Returns True if P is The_Project or a project extended by The_Project
6832 function Check_Project (P : Project_Id) return Boolean is
6834 if All_Projects or else P = The_Project then
6837 elsif Extending then
6842 Proj := The_Project;
6843 while Proj /= null loop
6844 if P = Proj.Extends then
6848 Proj := Proj.Extends;
6856 -- Start of processing for Insert_Project_Sources
6859 -- For all the sources in the project files,
6861 Unit := Units_Htable.Get_First (Project_Tree.Units_HT);
6862 while Unit /= null loop
6866 -- If there is a source for the body, and the body has not been
6869 if Unit.File_Names (Impl) /= null
6870 and then not Unit.File_Names (Impl).Locally_Removed
6872 -- And it is a source for the specified project
6874 if Check_Project (Unit.File_Names (Impl).Project) then
6876 -- If we don't have a spec, we cannot consider the source
6877 -- if it is a subunit.
6879 if Unit.File_Names (Spec) = null then
6881 Src_Ind : Source_File_Index;
6883 -- Here we are cheating a little bit: we don't want to
6884 -- use Sinput.L, because it depends on the GNAT tree
6885 -- (Atree, Sinfo, ...). So, we pretend that it is a
6886 -- project file, and we use Sinput.P.
6888 -- Source_File_Is_Subunit is just scanning through the
6889 -- file until it finds one of the reserved words
6890 -- separate, procedure, function, generic or package.
6891 -- Fortunately, these Ada reserved words are also
6892 -- reserved for project files.
6895 Src_Ind := Sinput.P.Load_Project_File
6897 (Unit.File_Names (Impl).Path.Name));
6899 -- If it is a subunit, discard it
6901 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
6905 Sfile := Unit.File_Names (Impl).Display_File;
6906 Index := Unit.File_Names (Impl).Index;
6911 Sfile := Unit.File_Names (Impl).Display_File;
6912 Index := Unit.File_Names (Impl).Index;
6916 elsif Unit.File_Names (Spec) /= null
6917 and then not Unit.File_Names (Spec).Locally_Removed
6918 and then Check_Project (Unit.File_Names (Spec).Project)
6920 -- If there is no source for the body, but there is a source
6921 -- for the spec which has not been locally removed, then we take
6924 Sfile := Unit.File_Names (Spec).Display_File;
6925 Index := Unit.File_Names (Spec).Index;
6928 -- If Put_In_Q is True, we insert into the Q
6932 -- For the first source inserted into the Q, we need to initialize
6933 -- the Q, but not for the subsequent sources.
6935 if First_Q_Initialization then
6939 -- And of course, only insert in the Q if the source is not marked
6941 if Sfile /= No_File and then not Is_Marked (Sfile, Index) then
6942 if Verbose_Mode then
6943 Write_Str ("Adding
""");
6944 Write_Str (Get_Name_String (Sfile));
6945 Write_Line (""" to the queue
");
6948 Insert_Q (Sfile, Index => Index);
6949 Mark (Sfile, Index);
6952 elsif Sfile /= No_File then
6954 -- If Put_In_Q is False, we add the source as if it were specified
6955 -- on the command line, and we set Put_In_Q to True, so that the
6956 -- following sources will be put directly in the queue. This will
6957 -- allow parallel compilation processes if -jx switch is used.
6959 if Verbose_Mode then
6960 Write_Str ("Adding
""");
6961 Write_Str (Get_Name_String (Sfile));
6962 Write_Line (""" as
if on the command line
");
6965 Osint.Add_File (Get_Name_String (Sfile), Index);
6968 -- As we may look into the Q later, ensure the Q has been
6969 -- initialized to avoid errors.
6971 if First_Q_Initialization then
6976 Unit := Units_Htable.Get_Next (Project_Tree.Units_HT);
6978 end Insert_Project_Sources;
6985 (Source_File : File_Name_Type;
6986 Source_Unit : Unit_Name_Type := No_Unit_Name;
6990 if Debug.Debug_Flag_Q then
6991 Write_Str (" Q
:= Q
+ [ ");
6992 Write_Name (Source_File);
7004 (File => Source_File,
7005 Unit => Source_Unit,
7010 ---------------------
7011 -- Is_In_Obsoleted --
7012 ---------------------
7014 function Is_In_Obsoleted (F : File_Name_Type) return Boolean is
7021 Name : constant String := Get_Name_String (F);
7023 F2 : File_Name_Type;
7027 while First > Name'First
7028 and then Name (First - 1) /= Directory_Separator
7029 and then Name (First - 1) /= '/'
7034 if First /= Name'First then
7036 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
7043 return Obsoleted.Get (F2);
7046 end Is_In_Obsoleted;
7048 ----------------------------
7049 -- Is_In_Object_Directory --
7050 ----------------------------
7052 function Is_In_Object_Directory
7053 (Source_File : File_Name_Type;
7054 Full_Lib_File : File_Name_Type) return Boolean
7057 -- There is something to check only when using project files. Otherwise,
7058 -- this function returns True (last line of the function).
7060 if Main_Project /= No_Project then
7062 Source_File_Name : constant String :=
7063 Get_Name_String (Source_File);
7064 Saved_Verbosity : constant Verbosity := Current_Verbosity;
7065 Project : Project_Id := No_Project;
7067 Path_Name : Path_Name_Type := No_Path;
7068 pragma Warnings (Off, Path_Name);
7071 -- Call Get_Reference to know the ultimate extending project of
7072 -- the source. Call it with verbosity default to avoid verbose
7075 Current_Verbosity := Default;
7076 Prj.Env.Get_Reference
7077 (Source_File_Name => Source_File_Name,
7079 In_Tree => Project_Tree,
7081 Current_Verbosity := Saved_Verbosity;
7083 -- If this source is in a project, check that the ALI file is in
7084 -- its object directory. If it is not, return False, so that the
7085 -- ALI file will not be skipped.
7087 if Project /= No_Project then
7089 Object_Directory : constant String :=
7093 Object_Directory.Display_Name));
7095 Olast : Natural := Object_Directory'Last;
7097 Lib_File_Directory : constant String :=
7098 Normalize_Pathname (Dir_Name
7099 (Get_Name_String (Full_Lib_File)));
7101 Llast : Natural := Lib_File_Directory'Last;
7104 -- For directories, Normalize_Pathname may or may not put
7105 -- a directory separator at the end, depending on its input.
7106 -- Remove any last directory separator before comparison.
7107 -- Returns True only if the two directories are the same.
7109 if Object_Directory (Olast) = Directory_Separator then
7113 if Lib_File_Directory (Llast) = Directory_Separator then
7117 return Object_Directory (Object_Directory'First .. Olast) =
7118 Lib_File_Directory (Lib_File_Directory'First .. Llast);
7124 -- When the source is not in a project file, always return True
7127 end Is_In_Object_Directory;
7134 (ALI_File : File_Name_Type;
7135 Args : Argument_List;
7136 Success : out Boolean)
7138 Link_Args : Argument_List (1 .. Args'Length + 1);
7141 Get_Name_String (ALI_File);
7142 Link_Args (1) := new String'(Name_Buffer (1 .. Name_Len));
7144 Link_Args (2 .. Args'Length + 1) := Args;
7146 GNAT.OS_Lib.Normalize_Arguments (Link_Args);
7148 Display (Gnatlink.all, Link_Args);
7150 if Gnatlink_Path = null then
7151 Make_Failed ("error
, unable to locate
" & Gnatlink.all);
7154 GNAT.OS_Lib.Spawn (Gnatlink_Path.all, Link_Args, Success);
7157 ---------------------------
7158 -- List_Bad_Compilations --
7159 ---------------------------
7161 procedure List_Bad_Compilations is
7163 for J in Bad_Compilation.First .. Bad_Compilation.Last loop
7164 if Bad_Compilation.Table (J).File = No_File then
7166 elsif not Bad_Compilation.Table (J).Found then
7167 Inform (Bad_Compilation.Table (J).File, "not found
");
7169 Inform (Bad_Compilation.Table (J).File, "compilation error
");
7172 end List_Bad_Compilations;
7178 procedure List_Depend is
7179 Lib_Name : File_Name_Type;
7180 Obj_Name : File_Name_Type;
7181 Src_Name : File_Name_Type;
7185 Line_Size : constant := 77;
7188 Set_Standard_Output;
7190 for A in ALIs.First .. ALIs.Last loop
7191 Lib_Name := ALIs.Table (A).Afile;
7193 -- We have to provide the full library file name in In_Place_Mode
7195 if In_Place_Mode then
7196 Lib_Name := Full_Lib_File_Name (Lib_Name);
7199 Obj_Name := Object_File_Name (Lib_Name);
7200 Write_Name (Obj_Name);
7203 Get_Name_String (Obj_Name);
7205 Line_Pos := Len + 2;
7207 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
7208 Src_Name := Sdep.Table (D).Sfile;
7210 if Is_Internal_File_Name (Src_Name)
7211 and then not Check_Readonly_Files
7215 if not Quiet_Output then
7216 Src_Name := Full_Source_Name (Src_Name);
7219 Get_Name_String (Src_Name);
7222 if Line_Pos + Len + 1 > Line_Size then
7228 Line_Pos
:= Line_Pos
+ Len
+ 1;
7231 Write_Name
(Src_Name
);
7238 if not Commands_To_Stdout
then
7247 procedure Make_Failed
(S
: String) is
7249 Delete_All_Temp_Files
;
7253 --------------------
7254 -- Mark_Directory --
7255 --------------------
7257 procedure Mark_Directory
7259 Mark
: Lib_Mark_Type
;
7260 On_Command_Line
: Boolean)
7265 function Base_Directory
return String;
7266 -- If Dir comes from the command line, empty string (relative paths
7267 -- are resolved with respect to the current directory), else return
7268 -- the main project's directory.
7270 --------------------
7271 -- Base_Directory --
7272 --------------------
7274 function Base_Directory
return String is
7276 if On_Command_Line
then
7279 return Get_Name_String
(Main_Project
.Directory
.Display_Name
);
7283 Real_Path
: constant String := Normalize_Pathname
(Dir
, Base_Directory
);
7285 -- Start of processing for Mark_Directory
7290 if Real_Path
'Length = 0 then
7291 Add_Str_To_Name_Buffer
(Dir
);
7294 Add_Str_To_Name_Buffer
(Real_Path
);
7297 -- Last character is supposed to be a directory separator
7299 if not Is_Directory_Separator
(Name_Buffer
(Name_Len
)) then
7300 Add_Char_To_Name_Buffer
(Directory_Separator
);
7303 -- Add flags to the already existing flags
7306 B
:= Get_Name_Table_Byte
(N
);
7307 Set_Name_Table_Byte
(N
, B
or Mark
);
7310 ----------------------
7311 -- Process_Multilib --
7312 ----------------------
7314 procedure Process_Multilib
7315 (Project_Node_Tree
: Project_Node_Tree_Ref
)
7317 Output_FD
: File_Descriptor
;
7318 Output_Name
: String_Access
;
7319 Arg_Index
: Natural := 0;
7320 Success
: Boolean := False;
7321 Return_Code
: Integer := 0;
7322 Multilib_Gcc_Path
: String_Access
;
7323 Multilib_Gcc
: String_Access
;
7324 N_Read
: Integer := 0;
7325 Line
: String (1 .. 1000);
7326 Args
: Argument_List
(1 .. N_M_Switch
+ 1);
7329 pragma Assert
(N_M_Switch
> 0 and RTS_Specified
= null);
7331 -- In case we detected a multilib switch and the user has not
7332 -- manually specified a specific RTS we emulate the following command:
7333 -- gnatmake $FLAGS --RTS=$(gcc -print-multi-directory $FLAGS)
7335 -- First select the flags which might have an impact on multilib
7336 -- processing. Note that this is an heuristic selection and it
7337 -- will need to be maintained over time. The condition has to
7338 -- be kept synchronized with N_M_Switch counting in Scan_Make_Arg.
7340 for Next_Arg
in 1 .. Argument_Count
loop
7342 Argv
: constant String := Argument
(Next_Arg
);
7345 and then Argv
(1) = '-'
7346 and then Argv
(2) = 'm'
7347 and then Argv
/= "-margs"
7349 -- Ignore -mieee to avoid spawning an extra gcc in this case
7351 and then Argv
/= "-mieee"
7353 Arg_Index
:= Arg_Index
+ 1;
7354 Args
(Arg_Index
) := new String'(Argv);
7359 pragma Assert (Arg_Index = N_M_Switch);
7361 Args (Args'Last) := new String'("-print-multi-directory");
7363 -- Call the GCC driver with the collected flags and save its
7364 -- output. Alternate design would be to link in gnatmake the
7365 -- relevant part of the GCC driver.
7367 if Saved_Gcc
/= null then
7368 Multilib_Gcc
:= Saved_Gcc
;
7370 Multilib_Gcc
:= Gcc
;
7373 Multilib_Gcc_Path
:= GNAT
.OS_Lib
.Locate_Exec_On_Path
(Multilib_Gcc
.all);
7375 Create_Temp_File
(Output_FD
, Output_Name
);
7377 if Output_FD
= Invalid_FD
then
7382 (Multilib_Gcc_Path
.all, Args
, Output_FD
, Return_Code
, False);
7385 if Return_Code
/= 0 then
7389 -- Parse the GCC driver output which is a single line, removing CR/LF
7391 Output_FD
:= Open_Read
(Output_Name
.all, Binary
);
7393 if Output_FD
= Invalid_FD
then
7397 N_Read
:= Read
(Output_FD
, Line
(1)'Address, Line
'Length);
7399 Delete_File
(Output_Name
.all, Success
);
7401 for J
in reverse 1 .. N_Read
loop
7402 if Line
(J
) = ASCII
.CR
or else Line
(J
) = ASCII
.LF
then
7403 N_Read
:= N_Read
- 1;
7409 -- In case the standard RTS is selected do nothing
7411 if N_Read
= 0 or else Line
(1 .. N_Read
) = "." then
7415 -- Otherwise add -margs --RTS=output
7417 Scan_Make_Arg
(Project_Node_Tree
, "-margs", And_Save
=> True);
7419 (Project_Node_Tree
, "--RTS=" & Line
(1 .. N_Read
), And_Save
=> True);
7420 end Process_Multilib
;
7422 -----------------------------
7423 -- Recursive_Compute_Depth --
7424 -----------------------------
7426 procedure Recursive_Compute_Depth
(Project
: Project_Id
) is
7427 use Project_Boolean_Htable
;
7428 Seen
: Project_Boolean_Htable
.Instance
:= Project_Boolean_Htable
.Nil
;
7430 procedure Recurse
(Prj
: Project_Id
; Depth
: Natural);
7431 -- Recursive procedure that does the work, keeping track of the depth
7437 procedure Recurse
(Prj
: Project_Id
; Depth
: Natural) is
7438 List
: Project_List
;
7442 if Prj
.Depth
>= Depth
or else Get
(Seen
, Prj
) then
7446 -- We need a test to avoid infinite recursions with limited withs:
7447 -- If we have A -> B -> A, then when set level of A to n, we try and
7448 -- set level of B to n+1, and then level of A to n + 2, ...
7450 Set
(Seen
, Prj
, True);
7454 -- Visit each imported project
7456 List
:= Prj
.Imported_Projects
;
7457 while List
/= null loop
7458 Proj
:= List
.Project
;
7460 Recurse
(Prj
=> Proj
, Depth
=> Depth
+ 1);
7463 -- We again allow changing the depth of this project later on if it
7464 -- is in fact imported by a lower-level project.
7466 Set
(Seen
, Prj
, False);
7469 Proj
: Project_List
;
7471 -- Start of processing for Recursive_Compute_Depth
7474 Proj
:= Project_Tree
.Projects
;
7475 while Proj
/= null loop
7476 Proj
.Project
.Depth
:= 0;
7480 Recurse
(Project
, Depth
=> 1);
7482 end Recursive_Compute_Depth
;
7484 -------------------------------
7485 -- Report_Compilation_Failed --
7486 -------------------------------
7488 procedure Report_Compilation_Failed
is
7490 Delete_All_Temp_Files
;
7491 Exit_Program
(E_Fatal
);
7492 end Report_Compilation_Failed
;
7494 ------------------------
7495 -- Sigint_Intercepted --
7496 ------------------------
7498 procedure Sigint_Intercepted
is
7499 SIGINT
: constant := 2;
7503 Write_Line
("*** Interrupted ***");
7505 -- Send SIGINT to all outstanding compilation processes spawned
7507 for J
in 1 .. Outstanding_Compiles
loop
7508 Kill
(Running_Compile
(J
).Pid
, SIGINT
, 1);
7511 Delete_All_Temp_Files
;
7513 -- ??? OS_Exit (1) is equivalent to Exit_Program (E_No_Compile),
7514 -- shouldn't that be Exit_Program (E_Abort) instead?
7515 end Sigint_Intercepted
;
7521 procedure Scan_Make_Arg
7522 (Project_Node_Tree
: Project_Node_Tree_Ref
;
7529 Gnatmake_Switch_Found
:= True;
7531 pragma Assert
(Argv
'First = 1);
7533 if Argv
'Length = 0 then
7537 -- If the previous switch has set the Project_File_Name_Present flag
7538 -- (that is we have seen a -P alone), then the next argument is the name
7539 -- of the project file.
7541 if Project_File_Name_Present
and then Project_File_Name
= null then
7542 if Argv
(1) = '-' then
7543 Make_Failed
("project file name missing after -P");
7546 Project_File_Name_Present
:= False;
7547 Project_File_Name
:= new String'(Argv);
7550 -- If the previous switch has set the Output_File_Name_Present flag
7551 -- (that is we have seen a -o), then the next argument is the name of
7552 -- the output executable.
7554 elsif Output_File_Name_Present
7555 and then not Output_File_Name_Seen
7557 Output_File_Name_Seen := True;
7559 if Argv (1) = '-' then
7560 Make_Failed ("output file name missing after -o");
7563 Add_Switch ("-o", Linker, And_Save => And_Save);
7564 Add_Switch (Executable_Name (Argv), Linker, And_Save => And_Save);
7567 -- If the previous switch has set the Object_Directory_Present flag
7568 -- (that is we have seen a -D), then the next argument is the path name
7569 -- of the object directory..
7571 elsif Object_Directory_Present
7572 and then not Object_Directory_Seen
7574 Object_Directory_Seen := True;
7576 if Argv (1) = '-' then
7577 Make_Failed ("object directory path name missing after -D");
7579 elsif not Is_Directory (Argv) then
7580 Make_Failed ("cannot find object directory """ & Argv & """");
7583 Add_Lib_Search_Dir (Argv);
7585 -- Specify the object directory to the binder
7587 Add_Switch ("-aO" & Argv, Binder, And_Save => And_Save);
7589 -- Record the object directory. Make sure it ends with a directory
7592 if Argv (Argv'Last) = Directory_Separator then
7593 Object_Directory_Path := new String'(Argv
);
7595 Object_Directory_Path
:=
7596 new String'(Argv & Directory_Separator);
7600 -- Then check if we are dealing with -cargs/-bargs/-largs/-margs
7602 elsif Argv = "-bargs"
7611 when 'c
' => Program_Args := Compiler;
7612 when 'b
' => Program_Args := Binder;
7613 when 'l
' => Program_Args := Linker;
7614 when 'm
' => Program_Args := None;
7617 raise Program_Error;
7620 -- A special test is needed for the -o switch within a -largs
7621 -- since that is another way to specify the name of the final
7624 elsif Program_Args = Linker
7625 and then Argv = "-o"
7627 Make_Failed ("switch -o not allowed within a -largs. " &
7628 "Use -o directly.");
7630 -- Check to see if we are reading switches after a -cargs,
7631 -- -bargs or -largs switch. If yes save it.
7633 elsif Program_Args /= None then
7635 -- Check to see if we are reading -I switches in order
7636 -- to take into account in the src & lib search directories.
7638 if Argv'Length > 2 and then Argv (1 .. 2) = "-I" then
7639 if Argv (3 .. Argv'Last) = "-" then
7640 Look_In_Primary_Dir := False;
7642 elsif Program_Args = Compiler then
7643 if Argv (3 .. Argv'Last) /= "-" then
7644 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7647 elsif Program_Args = Binder then
7648 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7652 Add_Switch (Argv, Program_Args, And_Save => And_Save);
7654 -- Handle non-default compiler, binder, linker, and handle --RTS switch
7656 elsif Argv'Length > 2 and then Argv (1 .. 2) = "--" then
7658 and then Argv (1 .. 6) = "--GCC="
7661 Program_Args : constant Argument_List_Access :=
7662 Argument_String_To_List
7663 (Argv (7 .. Argv'Last));
7667 Saved_Gcc := new String'(Program_Args
.all (1).all);
7669 Gcc
:= new String'(Program_Args.all (1).all);
7672 for J in 2 .. Program_Args.all'Last loop
7674 (Program_Args.all (J).all,
7676 And_Save => And_Save);
7680 elsif Argv'Length > 11
7681 and then Argv (1 .. 11) = "--GNATBIND="
7684 Program_Args : constant Argument_List_Access :=
7685 Argument_String_To_List
7686 (Argv (12 .. Argv'Last));
7690 Saved_Gnatbind := new String'(Program_Args
.all (1).all);
7692 Gnatbind
:= new String'(Program_Args.all (1).all);
7695 for J in 2 .. Program_Args.all'Last loop
7697 (Program_Args.all (J).all, Binder, And_Save => And_Save);
7701 elsif Argv'Length > 11
7702 and then Argv (1 .. 11) = "--GNATLINK="
7705 Program_Args : constant Argument_List_Access :=
7706 Argument_String_To_List
7707 (Argv (12 .. Argv'Last));
7710 Saved_Gnatlink := new String'(Program_Args
.all (1).all);
7712 Gnatlink
:= new String'(Program_Args.all (1).all);
7715 for J in 2 .. Program_Args.all'Last loop
7716 Add_Switch (Program_Args.all (J).all, Linker);
7720 elsif Argv'Length >= 5 and then
7721 Argv (1 .. 5) = "--RTS"
7723 Add_Switch (Argv, Compiler, And_Save => And_Save);
7724 Add_Switch (Argv, Binder, And_Save => And_Save);
7726 if Argv'Length <= 6 or else Argv (6) /= '=' then
7727 Make_Failed ("missing path for --RTS");
7730 -- Check that this is the first time we see this switch or
7731 -- if it is not the first time, the same path is specified.
7733 if RTS_Specified = null then
7734 RTS_Specified := new String'(Argv
(7 .. Argv
'Last));
7736 elsif RTS_Specified
.all /= Argv
(7 .. Argv
'Last) then
7737 Make_Failed
("--RTS cannot be specified multiple times");
7740 -- Valid --RTS switch
7747 Src_Path_Name
: constant String_Ptr
:=
7749 (Argv
(7 .. Argv
'Last), Include
);
7751 Lib_Path_Name
: constant String_Ptr
:=
7753 (Argv
(7 .. Argv
'Last), Objects
);
7756 if Src_Path_Name
/= null
7757 and then Lib_Path_Name
/= null
7759 -- Set RTS_*_Path_Name variables, so that correct direct-
7760 -- ories will be set when Osint.Add_Default_Search_Dirs
7763 RTS_Src_Path_Name
:= Src_Path_Name
;
7764 RTS_Lib_Path_Name
:= Lib_Path_Name
;
7766 elsif Src_Path_Name
= null
7767 and then Lib_Path_Name
= null
7769 Make_Failed
("RTS path not valid: missing " &
7770 "adainclude and adalib directories");
7772 elsif Src_Path_Name
= null then
7773 Make_Failed
("RTS path not valid: missing adainclude " &
7776 elsif Lib_Path_Name
= null then
7777 Make_Failed
("RTS path not valid: missing adalib " &
7783 elsif Argv
'Length >= 8 and then
7784 Argv
(1 .. 8) = "--param="
7786 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
7787 Add_Switch
(Argv
, Linker
, And_Save
=> And_Save
);
7790 Scan_Make_Switches
(Project_Node_Tree
, Argv
, Success
);
7793 -- If we have seen a regular switch process it
7795 elsif Argv
(1) = '-' then
7796 if Argv
'Length = 1 then
7797 Make_Failed
("switch character cannot be followed by a blank");
7799 -- Incorrect switches that should start with "--"
7801 elsif (Argv
'Length > 5 and then Argv
(1 .. 5) = "-RTS=")
7802 or else (Argv
'Length > 5 and then Argv
(1 .. 5) = "-GCC=")
7803 or else (Argv
'Length > 8 and then Argv
(1 .. 7) = "-param=")
7804 or else (Argv
'Length > 10 and then Argv
(1 .. 10) = "-GNATLINK=")
7805 or else (Argv
'Length > 10 and then Argv
(1 .. 10) = "-GNATBIND=")
7807 Make_Failed
("option " & Argv
& " should start with '--'");
7811 elsif Argv
(2 .. Argv
'Last) = "I-" then
7812 Look_In_Primary_Dir
:= False;
7814 -- Forbid -?- or -??- where ? is any character
7816 elsif (Argv
'Length = 3 and then Argv
(3) = '-')
7817 or else (Argv
'Length = 4 and then Argv
(4) = '-')
7820 ("trailing ""-"" at the end of " & Argv
& " forbidden.");
7824 elsif Argv
(2) = 'I' then
7825 Add_Source_Search_Dir
(Argv
(3 .. Argv
'Last), And_Save
);
7826 Add_Library_Search_Dir
(Argv
(3 .. Argv
'Last), And_Save
);
7827 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
7828 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
7830 -- -aIdir (to gcc this is like a -I switch)
7832 elsif Argv
'Length >= 3 and then Argv
(2 .. 3) = "aI" then
7833 Add_Source_Search_Dir
(Argv
(4 .. Argv
'Last), And_Save
);
7834 Add_Switch
("-I" & Argv
(4 .. Argv
'Last),
7836 And_Save
=> And_Save
);
7837 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
7841 elsif Argv
'Length >= 3 and then Argv
(2 .. 3) = "aO" then
7842 Add_Library_Search_Dir
(Argv
(4 .. Argv
'Last), And_Save
);
7843 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
7845 -- -aLdir (to gnatbind this is like a -aO switch)
7847 elsif Argv
'Length >= 3 and then Argv
(2 .. 3) = "aL" then
7848 Mark_Directory
(Argv
(4 .. Argv
'Last), Ada_Lib_Dir
, And_Save
);
7849 Add_Library_Search_Dir
(Argv
(4 .. Argv
'Last), And_Save
);
7850 Add_Switch
("-aO" & Argv
(4 .. Argv
'Last),
7852 And_Save
=> And_Save
);
7856 elsif Argv
'Length >= 13 and then Argv
(2 .. 13) = "aamp_target=" then
7857 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
7859 -- Set the aamp_target environment variable so that the binder and
7860 -- linker will use the proper target library. This is consistent
7861 -- with how things work when -aamp_target is passed on the command
7862 -- line to gnaampmake.
7864 Setenv
("aamp_target", Argv
(14 .. Argv
'Last));
7866 -- -Adir (to gnatbind this is like a -aO switch, to gcc like a -I)
7868 elsif Argv
(2) = 'A' then
7869 Mark_Directory
(Argv
(3 .. Argv
'Last), Ada_Lib_Dir
, And_Save
);
7870 Add_Source_Search_Dir
(Argv
(3 .. Argv
'Last), And_Save
);
7871 Add_Library_Search_Dir
(Argv
(3 .. Argv
'Last), And_Save
);
7872 Add_Switch
("-I" & Argv
(3 .. Argv
'Last),
7874 And_Save
=> And_Save
);
7875 Add_Switch
("-aO" & Argv
(3 .. Argv
'Last),
7877 And_Save
=> And_Save
);
7881 elsif Argv
(2) = 'L' then
7882 Add_Switch
(Argv
, Linker
, And_Save
=> And_Save
);
7884 -- For -gxxxxx, -pg, -mxxx, -fxxx: give the switch to both the
7885 -- compiler and the linker (except for -gnatxxx which is only for
7886 -- the compiler). Some of the -mxxx (for example -m64) and -fxxx
7887 -- (for example -ftest-coverage for gcov) need to be used when
7888 -- compiling the binder generated files, and using all these gcc
7889 -- switches for the binder generated files should not be a problem.
7892 (Argv
(2) = 'g' and then (Argv
'Last < 5
7893 or else Argv
(2 .. 5) /= "gnat"))
7894 or else Argv
(2 .. Argv
'Last) = "pg"
7895 or else (Argv
(2) = 'm' and then Argv
'Last > 2)
7896 or else (Argv
(2) = 'f' and then Argv
'Last > 2)
7898 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
7899 Add_Switch
(Argv
, Linker
, And_Save
=> And_Save
);
7901 -- The following condition has to be kept synchronized with
7902 -- the Process_Multilib one.
7905 and then Argv
/= "-mieee"
7907 N_M_Switch
:= N_M_Switch
+ 1;
7910 -- -C=<mapping file>
7912 elsif Argv
'Last > 2 and then Argv
(2) = 'C' then
7914 if Argv
(3) /= '=' or else Argv
'Last <= 3 then
7915 Make_Failed
("illegal switch " & Argv
);
7918 Gnatmake_Mapping_File
:= new String'(Argv (4 .. Argv'Last));
7923 elsif Argv'Last = 2 and then Argv (2) = 'D
' then
7924 if Project_File_Name /= null then
7925 Make_Failed ("-D cannot be used in conjunction with a " &
7929 Scan_Make_Switches (Project_Node_Tree, Argv, Success);
7934 elsif Argv (2) = 'd
'
7935 and then Argv'Last = 2
7937 Display_Compilation_Progress := True;
7941 elsif Argv'Last = 2 and then Argv (2) = 'i
' then
7942 if Project_File_Name /= null then
7943 Make_Failed ("-i cannot be used in conjunction with a " &
7946 Scan_Make_Switches (Project_Node_Tree, Argv, Success);
7949 -- -j (need to save the result)
7951 elsif Argv (2) = 'j
' then
7952 Scan_Make_Switches (Project_Node_Tree, Argv, Success);
7955 Saved_Maximum_Processes := Maximum_Processes;
7960 elsif Argv (2) = 'm
'
7961 and then Argv'Last = 2
7963 Minimal_Recompilation := True;
7967 elsif Argv (2) = 'u
'
7968 and then Argv'Last = 2
7970 Unique_Compile := True;
7971 Compile_Only := True;
7972 Do_Bind_Step := False;
7973 Do_Link_Step := False;
7977 elsif Argv (2) = 'U
'
7978 and then Argv'Last = 2
7980 Unique_Compile_All_Projects := True;
7981 Unique_Compile := True;
7982 Compile_Only := True;
7983 Do_Bind_Step := False;
7984 Do_Link_Step := False;
7986 -- -Pprj or -P prj (only once, and only on the command line)
7988 elsif Argv (2) = 'P
' then
7989 if Project_File_Name /= null then
7990 Make_Failed ("cannot have several project files specified");
7992 elsif Object_Directory_Path /= null then
7993 Make_Failed ("-D cannot be used in conjunction with a " &
7996 elsif In_Place_Mode then
7997 Make_Failed ("-i cannot be used in conjunction with a " &
8000 elsif not And_Save then
8002 -- It could be a tool other than gnatmake (i.e, gnatdist)
8003 -- or a -P switch inside a project file.
8006 ("either the tool is not ""project-aware"" or " &
8007 "a project file is specified inside a project file");
8009 elsif Argv'Last = 2 then
8011 -- -P is used alone: the project file name is the next option
8013 Project_File_Name_Present := True;
8016 Project_File_Name := new String'(Argv
(3 .. Argv
'Last));
8019 -- -vPx (verbosity of the parsing of the project files)
8022 and then Argv
(2 .. 3) = "vP"
8023 and then Argv
(4) in '0' .. '2'
8028 Current_Verbosity
:= Prj
.Default
;
8030 Current_Verbosity
:= Prj
.Medium
;
8032 Current_Verbosity
:= Prj
.High
;
8038 -- -Xext=val (External assignment)
8040 elsif Argv
(2) = 'X'
8041 and then Is_External_Assignment
(Project_Node_Tree
, Argv
)
8043 -- Is_External_Assignment has side effects
8044 -- when it returns True;
8048 -- If -gnath is present, then generate the usage information
8049 -- right now and do not pass this option on to the compiler calls.
8051 elsif Argv
= "-gnath" then
8054 -- If -gnatc is specified, make sure the bind step and the link
8055 -- step are not executed.
8057 elsif Argv
'Length >= 6 and then Argv
(2 .. 6) = "gnatc" then
8059 -- If -gnatc is specified, make sure the bind step and the link
8060 -- step are not executed.
8062 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
8063 Operating_Mode
:= Check_Semantics
;
8064 Check_Object_Consistency
:= False;
8065 Compile_Only
:= True;
8066 Do_Bind_Step
:= False;
8067 Do_Link_Step
:= False;
8069 elsif Argv
(2 .. Argv
'Last) = "nostdlib" then
8071 -- Don't pass -nostdlib to gnatlink, it will disable
8072 -- linking with all standard library files.
8076 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
8077 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
8079 elsif Argv
(2 .. Argv
'Last) = "nostdinc" then
8081 -- Pass -nostdinc to the Compiler and to gnatbind
8084 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
8085 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
8087 -- All other switches are processed by Scan_Make_Switches. If the
8088 -- call returns with Gnatmake_Switch_Found = False, then the switch
8089 -- is passed to the compiler.
8093 (Project_Node_Tree
, Argv
, Gnatmake_Switch_Found
);
8095 if not Gnatmake_Switch_Found
then
8096 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
8100 -- If not a switch it must be a file name
8104 Mains
.Add_Main
(Argv
);
8112 function Switches_Of
8113 (Source_File
: File_Name_Type
;
8114 Source_File_Name
: String;
8116 Project
: Project_Id
;
8117 In_Package
: Package_Id
;
8118 Allow_ALI
: Boolean) return Variable_Value
8120 Lang
: constant Language_Ptr
:= Get_Language_From_Name
(Project
, "ada");
8122 Switches
: Variable_Value
;
8124 Defaults
: constant Array_Element_Id
:=
8126 (Name
=> Name_Default_Switches
,
8128 Project_Tree
.Packages
.Table
8129 (In_Package
).Decl
.Arrays
,
8130 In_Tree
=> Project_Tree
);
8132 Switches_Array
: constant Array_Element_Id
:=
8134 (Name
=> Name_Switches
,
8136 Project_Tree
.Packages
.Table
8137 (In_Package
).Decl
.Arrays
,
8138 In_Tree
=> Project_Tree
);
8141 -- First, try Switches (<file name>)
8145 (Index
=> Name_Id
(Source_File
),
8146 Src_Index
=> Source_Index
,
8147 In_Array
=> Switches_Array
,
8148 In_Tree
=> Project_Tree
);
8150 -- Check also without the suffix
8152 if Switches
= Nil_Variable_Value
8153 and then Lang
/= null
8156 Naming
: Lang_Naming_Data
renames Lang
.Config
.Naming_Data
;
8157 Name
: String (1 .. Source_File_Name
'Length + 3);
8158 Last
: Positive := Source_File_Name
'Length;
8159 Spec_Suffix
: constant String :=
8160 Get_Name_String
(Naming
.Spec_Suffix
);
8161 Body_Suffix
: constant String :=
8162 Get_Name_String
(Naming
.Body_Suffix
);
8163 Truncated
: Boolean := False;
8166 Name
(1 .. Last
) := Source_File_Name
;
8168 if Last
> Body_Suffix
'Length
8169 and then Name
(Last
- Body_Suffix
'Length + 1 .. Last
) =
8173 Last
:= Last
- Body_Suffix
'Length;
8177 and then Last
> Spec_Suffix
'Length
8178 and then Name
(Last
- Spec_Suffix
'Length + 1 .. Last
) =
8182 Last
:= Last
- Spec_Suffix
'Length;
8187 Add_Str_To_Name_Buffer
(Name
(1 .. Last
));
8190 (Index
=> Name_Find
,
8192 In_Array
=> Switches_Array
,
8193 In_Tree
=> Project_Tree
);
8195 if Switches
= Nil_Variable_Value
and then Allow_ALI
then
8196 Last
:= Source_File_Name
'Length;
8198 while Name
(Last
) /= '.' loop
8203 Add_Str_To_Name_Buffer
(Name
(1 .. Last
));
8204 Add_Str_To_Name_Buffer
("ali");
8208 (Index
=> Name_Find
,
8210 In_Array
=> Switches_Array
,
8211 In_Tree
=> Project_Tree
);
8217 -- Next, try Switches ("Ada")
8219 if Switches
= Nil_Variable_Value
then
8224 In_Array
=> Switches_Array
,
8225 In_Tree
=> Project_Tree
,
8226 Force_Lower_Case_Index
=> True);
8228 if Switches
/= Nil_Variable_Value
then
8229 Switch_May_Be_Passed_To_The_Compiler
:= False;
8233 -- Next, try Switches (others)
8235 if Switches
= Nil_Variable_Value
then
8238 (Index
=> All_Other_Names
,
8240 In_Array
=> Switches_Array
,
8241 In_Tree
=> Project_Tree
);
8243 if Switches
/= Nil_Variable_Value
then
8244 Switch_May_Be_Passed_To_The_Compiler
:= False;
8248 -- And finally, Default_Switches ("Ada")
8250 if Switches
= Nil_Variable_Value
then
8255 In_Array
=> Defaults
,
8256 In_Tree
=> Project_Tree
);
8268 if Usage_Needed
then
8269 Usage_Needed
:= False;
8275 -- Make sure that in case of failure, the temp files will be deleted
8277 Prj
.Com
.Fail
:= Make_Failed
'Access;
8278 MLib
.Fail
:= Make_Failed
'Access;
8279 Makeutl
.Do_Fail
:= Make_Failed
'Access;