1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2016, 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
;
57 with Snames
; use Snames
;
60 pragma Warnings
(Off
);
64 with Switch
; use Switch
;
65 with Switch
.M
; use Switch
.M
;
67 with Targparm
; use Targparm
;
69 with Types
; use Types
;
71 with Ada
.Command_Line
; use Ada
.Command_Line
;
73 with Ada
.Exceptions
; use Ada
.Exceptions
;
75 with GNAT
.Case_Util
; use GNAT
.Case_Util
;
76 with GNAT
.Command_Line
; use GNAT
.Command_Line
;
77 with GNAT
.Directory_Operations
; use GNAT
.Directory_Operations
;
78 with GNAT
.Dynamic_HTables
; use GNAT
.Dynamic_HTables
;
79 with GNAT
.OS_Lib
; use GNAT
.OS_Lib
;
84 -- Make control characters visible
86 Standard_Library_Package_Body_Name
: constant String := "s-stalib.adb";
87 System_Package_Spec_Name
: constant String := "system.ads";
88 -- Every program depends on one of these packages: usually the first one,
89 -- or if Supress_Standard_Library is true on the second one. The dependency
90 -- is not always explicit and considering it is important when -f and -a
93 type Sigint_Handler
is access procedure;
94 pragma Convention
(C
, Sigint_Handler
);
96 procedure Install_Int_Handler
(Handler
: Sigint_Handler
);
97 pragma Import
(C
, Install_Int_Handler
, "__gnat_install_int_handler");
98 -- Called by Gnatmake to install the SIGINT handler below
100 procedure Sigint_Intercepted
;
101 pragma Convention
(C
, Sigint_Intercepted
);
102 -- Called when the program is interrupted by Ctrl-C to delete the
103 -- temporary mapping files and configuration pragmas files.
105 No_Mapping_File
: constant Natural := 0;
107 type Compilation_Data
is record
109 Full_Source_File
: File_Name_Type
;
110 Lib_File
: File_Name_Type
;
111 Source_Unit
: Unit_Name_Type
;
112 Full_Lib_File
: File_Name_Type
;
113 Lib_File_Attr
: aliased File_Attributes
;
114 Mapping_File
: Natural := No_Mapping_File
;
115 Project
: Project_Id
:= No_Project
;
117 -- Data recorded for each compilation process spawned
119 No_Compilation_Data
: constant Compilation_Data
:=
120 (Invalid_Pid
, No_File
, No_File
, No_Unit_Name
, No_File
, Unknown_Attributes
,
121 No_Mapping_File
, No_Project
);
123 type Comp_Data_Arr
is array (Positive range <>) of Compilation_Data
;
124 type Comp_Data_Ptr
is access Comp_Data_Arr
;
125 Running_Compile
: Comp_Data_Ptr
;
126 -- Used to save information about outstanding compilations
128 Outstanding_Compiles
: Natural := 0;
129 -- Current number of outstanding compiles
131 -------------------------
132 -- Note on terminology --
133 -------------------------
135 -- In this program, we use the phrase "termination" of a file name to refer
136 -- to the suffix that appears after the unit name portion. Very often this
137 -- is simply the extension, but in some cases, the sequence may be more
138 -- complex, for example in main.1.ada, the termination in this name is
139 -- ".1.ada" and in main_.ada the termination is "_.ada".
141 procedure Insert_Project_Sources
142 (The_Project
: Project_Id
;
143 All_Projects
: Boolean;
145 -- If Into_Q is True, insert all sources of the project file(s) that are
146 -- not already marked into the Q. If Into_Q is False, call Osint.Add_File
147 -- for the first source, then insert all other sources that are not already
148 -- marked into the Q. If All_Projects is True, all sources of all projects
149 -- are concerned; otherwise, only sources of The_Project are concerned,
150 -- including, if The_Project is an extending project, sources inherited
151 -- from projects being extended.
153 Unique_Compile
: Boolean := False;
154 -- Set to True if -u or -U or a project file with no main is used
156 Unique_Compile_All_Projects
: Boolean := False;
157 -- Set to True if -U is used
159 Must_Compile
: Boolean := False;
160 -- True if gnatmake is invoked with -f -u and one or several mains on the
163 Project_Tree
: constant Project_Tree_Ref
:=
164 new Project_Tree_Data
(Is_Root_Tree
=> True);
167 Main_On_Command_Line
: Boolean := False;
168 -- True if gnatmake is invoked with one or several mains on the command
171 RTS_Specified
: String_Access
:= null;
172 -- Used to detect multiple --RTS= switches
174 N_M_Switch
: Natural := 0;
175 -- Used to count -mxxx switches that can affect multilib
177 -- The 3 following packages are used to store gcc, gnatbind and gnatlink
178 -- switches found in the project files.
180 package Gcc_Switches
is new Table
.Table
(
181 Table_Component_Type
=> String_Access
,
182 Table_Index_Type
=> Integer,
183 Table_Low_Bound
=> 1,
185 Table_Increment
=> 100,
186 Table_Name
=> "Make.Gcc_Switches");
188 package Binder_Switches
is new Table
.Table
(
189 Table_Component_Type
=> String_Access
,
190 Table_Index_Type
=> Integer,
191 Table_Low_Bound
=> 1,
193 Table_Increment
=> 100,
194 Table_Name
=> "Make.Binder_Switches");
196 package Linker_Switches
is new Table
.Table
(
197 Table_Component_Type
=> String_Access
,
198 Table_Index_Type
=> Integer,
199 Table_Low_Bound
=> 1,
201 Table_Increment
=> 100,
202 Table_Name
=> "Make.Linker_Switches");
204 -- The following instantiations and variables are necessary to save what
205 -- is found on the command line, in case there is a project file specified.
207 package Saved_Gcc_Switches
is new Table
.Table
(
208 Table_Component_Type
=> String_Access
,
209 Table_Index_Type
=> Integer,
210 Table_Low_Bound
=> 1,
212 Table_Increment
=> 100,
213 Table_Name
=> "Make.Saved_Gcc_Switches");
215 package Saved_Binder_Switches
is new Table
.Table
(
216 Table_Component_Type
=> String_Access
,
217 Table_Index_Type
=> Integer,
218 Table_Low_Bound
=> 1,
220 Table_Increment
=> 100,
221 Table_Name
=> "Make.Saved_Binder_Switches");
223 package Saved_Linker_Switches
is new Table
.Table
224 (Table_Component_Type
=> String_Access
,
225 Table_Index_Type
=> Integer,
226 Table_Low_Bound
=> 1,
228 Table_Increment
=> 100,
229 Table_Name
=> "Make.Saved_Linker_Switches");
231 package Switches_To_Check
is new Table
.Table
(
232 Table_Component_Type
=> String_Access
,
233 Table_Index_Type
=> Integer,
234 Table_Low_Bound
=> 1,
236 Table_Increment
=> 100,
237 Table_Name
=> "Make.Switches_To_Check");
239 package Library_Paths
is new Table
.Table
(
240 Table_Component_Type
=> String_Access
,
241 Table_Index_Type
=> Integer,
242 Table_Low_Bound
=> 1,
244 Table_Increment
=> 100,
245 Table_Name
=> "Make.Library_Paths");
247 package Failed_Links
is new Table
.Table
(
248 Table_Component_Type
=> File_Name_Type
,
249 Table_Index_Type
=> Integer,
250 Table_Low_Bound
=> 1,
252 Table_Increment
=> 100,
253 Table_Name
=> "Make.Failed_Links");
255 package Successful_Links
is new Table
.Table
(
256 Table_Component_Type
=> File_Name_Type
,
257 Table_Index_Type
=> Integer,
258 Table_Low_Bound
=> 1,
260 Table_Increment
=> 100,
261 Table_Name
=> "Make.Successful_Links");
263 package Library_Projs
is new Table
.Table
(
264 Table_Component_Type
=> Project_Id
,
265 Table_Index_Type
=> Integer,
266 Table_Low_Bound
=> 1,
268 Table_Increment
=> 100,
269 Table_Name
=> "Make.Library_Projs");
271 -- Two variables to keep the last binder and linker switch index in tables
272 -- Binder_Switches and Linker_Switches, before adding switches from the
273 -- project file (if any) and switches from the command line (if any).
275 Last_Binder_Switch
: Integer := 0;
276 Last_Linker_Switch
: Integer := 0;
278 Normalized_Switches
: Argument_List_Access
:= new Argument_List
(1 .. 10);
279 Last_Norm_Switch
: Natural := 0;
281 Saved_Maximum_Processes
: Natural := 0;
283 Gnatmake_Switch_Found
: Boolean;
284 -- Set by Scan_Make_Arg. True when the switch is a gnatmake switch.
285 -- Tested by Add_Switches when switches in package Builder must all be
286 -- gnatmake switches.
288 Switch_May_Be_Passed_To_The_Compiler
: Boolean;
289 -- Set by Add_Switches and Switches_Of. True when unrecognized switches
290 -- are passed to the Ada compiler.
292 type Arg_List_Ref
is access Argument_List
;
293 The_Saved_Gcc_Switches
: Arg_List_Ref
;
295 Project_File_Name
: String_Access
:= null;
296 -- The path name of the main project file, if any
298 Project_File_Name_Present
: Boolean := False;
299 -- True when -P is used with a space between -P and the project file name
301 Current_Verbosity
: Prj
.Verbosity
:= Prj
.Default
;
302 -- Verbosity to parse the project files
304 Main_Project
: Prj
.Project_Id
:= No_Project
;
305 -- The project id of the main project file, if any
307 Project_Of_Current_Object_Directory
: Project_Id
:= No_Project
;
308 -- The object directory of the project for the last compilation. Avoid
309 -- calling Change_Dir if the current working directory is already this
312 Map_File
: String_Access
:= null;
313 -- Value of switch --create-map-file
315 -- Packages of project files where unknown attributes are errors
317 Naming_String
: aliased String := "naming";
318 Builder_String
: aliased String := "builder";
319 Compiler_String
: aliased String := "compiler";
320 Binder_String
: aliased String := "binder";
321 Linker_String
: aliased String := "linker";
323 Gnatmake_Packages
: aliased String_List
:=
324 (Naming_String
'Access,
325 Builder_String 'Access,
326 Compiler_String
'Access,
327 Binder_String 'Access,
328 Linker_String
'Access);
330 Packages_To_Check_By_Gnatmake : constant String_List_Access :=
331 Gnatmake_Packages'Access;
333 procedure Add_Library_Search_Dir
335 On_Command_Line : Boolean);
336 -- Call Add_Lib_Search_Dir with an absolute directory path. If Path is
337 -- relative path, when On_Command_Line is True, it is relative to the
338 -- current working directory. When On_Command_Line is False, it is relative
339 -- to the project directory of the main project.
341 procedure Add_Source_Search_Dir
343 On_Command_Line : Boolean);
344 -- Call Add_Src_Search_Dir with an absolute directory path. If Path is a
345 -- relative path, when On_Command_Line is True, it is relative to the
346 -- current working directory. When On_Command_Line is False, it is relative
347 -- to the project directory of the main project.
349 procedure Add_Source_Dir (N : String);
350 -- Call Add_Src_Search_Dir (output one line when in verbose mode)
352 procedure Add_Source_Directories is
353 new Prj.Env.For_All_Source_Dirs (Action => Add_Source_Dir);
355 procedure Add_Object_Dir (N : String);
356 -- Call Add_Lib_Search_Dir (output one line when in verbose mode)
358 procedure Add_Object_Directories is
359 new Prj.Env.For_All_Object_Dirs (Action => Add_Object_Dir);
361 procedure Change_To_Object_Directory (Project : Project_Id);
362 -- Change to the object directory of project Project, if this is not
363 -- already the current working directory.
365 type Bad_Compilation_Info is record
366 File : File_Name_Type;
367 Unit : Unit_Name_Type;
370 -- File is the name of the file for which a compilation failed. Unit is for
371 -- gnatdist use in order to easily get the unit name of a file when its
372 -- name is krunched or declared in gnat.adc. Found is False if the
373 -- compilation failed because the file could not be found.
375 package Bad_Compilation is new Table.Table (
376 Table_Component_Type => Bad_Compilation_Info,
377 Table_Index_Type => Natural,
378 Table_Low_Bound => 1,
380 Table_Increment => 100,
381 Table_Name => "Make.Bad_Compilation");
382 -- Full name of all the source files for which compilation fails
384 Do_Compile_Step : Boolean := True;
385 Do_Bind_Step : Boolean := True;
386 Do_Link_Step : Boolean := True;
387 -- Flags to indicate what step should be executed. Can be set to False
388 -- with the switches -c, -b and -l. These flags are reset to True for
389 -- each invocation of procedure Gnatmake.
391 Shared_String : aliased String := "-shared";
392 Force_Elab_Flags_String : aliased String := "-F";
393 CodePeer_Mode_String : aliased String := "-P";
395 No_Shared_Switch : aliased Argument_List := (1 .. 0 => null);
396 Shared_Switch : aliased Argument_List := (1 => Shared_String'Access);
397 Bind_Shared : Argument_List_Access := No_Shared_Switch'Access;
398 -- Switch to added in front of gnatbind switches. By default no switch is
399 -- added. Switch "-shared" is added if there is a non-static Library
402 Shared_Libgcc : aliased String := "-shared-libgcc";
404 No_Shared_Libgcc_Switch : aliased Argument_List := (1 .. 0 => null);
405 Shared_Libgcc_Switch : aliased Argument_List :=
406 (1 => Shared_Libgcc'Access);
407 Link_With_Shared_Libgcc : Argument_List_Access :=
408 No_Shared_Libgcc_Switch'Access;
410 procedure Make_Failed (S : String);
411 -- Delete all temp files created by Gnatmake and call Osint.Fail, with the
412 -- parameter S (see osint.ads). This is called from the Prj hierarchy and
413 -- the MLib hierarchy. This subprogram also prints current error messages
414 -- (i.e. finalizes Errutil).
416 --------------------------
417 -- Obsolete Executables --
418 --------------------------
420 Executable_Obsolete : Boolean := False;
421 -- Executable_Obsolete is initially set to False for each executable,
422 -- and is set to True whenever one of the source of the executable is
423 -- compiled, or has already been compiled for another executable.
425 Max_Header : constant := 200;
426 -- This needs a proper comment, it used to say "arbitrary" that's not an
427 -- adequate comment ???
429 type Header_Num is range 1 .. Max_Header;
430 -- Header_Num for the hash table Obsoleted below
432 function Hash (F : File_Name_Type) return Header_Num;
433 -- Hash function for the hash table Obsoleted below
435 package Obsoleted is new System.HTable.Simple_HTable
436 (Header_Num => Header_Num,
439 Key => File_Name_Type,
442 -- A hash table to keep all files that have been compiled, to detect
443 -- if an executable is up to date or not.
445 procedure Enter_Into_Obsoleted (F : File_Name_Type);
446 -- Enter a file name, without directory information, into the hash table
449 function Is_In_Obsoleted (F : File_Name_Type) return Boolean;
450 -- Check if a file name, without directory information, has already been
451 -- entered into the hash table Obsoleted.
453 type Dependency is record
454 This : File_Name_Type;
455 Depends_On : File_Name_Type;
457 -- Components of table Dependencies below
459 package Dependencies is new Table.Table (
460 Table_Component_Type => Dependency,
461 Table_Index_Type => Integer,
462 Table_Low_Bound => 1,
464 Table_Increment => 100,
465 Table_Name => "Make.Dependencies");
466 -- A table to keep dependencies, to be able to decide if an executable
467 -- is obsolete. More explanation needed ???
469 ----------------------------
470 -- Arguments and Switches --
471 ----------------------------
473 Arguments : Argument_List_Access;
474 -- Used to gather the arguments for invocation of the compiler
476 Last_Argument : Natural := 0;
477 -- Last index of arguments in Arguments above
479 Arguments_Project : Project_Id;
480 -- Project id, if any, of the source to be compiled
482 Arguments_Path_Name : Path_Name_Type;
483 -- Full path of the source to be compiled, when Arguments_Project is not
486 Dummy_Switch : constant String_Access := new String'("- ");
487 -- Used to initialized Prev_Switch in procedure Check
489 procedure Add_Arguments
(Args
: Argument_List
);
490 -- Add arguments to global variable Arguments, increasing its size
491 -- if necessary and adjusting Last_Argument.
493 function Configuration_Pragmas_Switch
494 (For_Project
: Project_Id
) return Argument_List
;
495 -- Return an argument list of one element, if there is a configuration
496 -- pragmas file to be specified for For_Project,
497 -- otherwise return an empty argument list.
503 procedure List_Depend
;
504 -- Prints to standard output the list of object dependencies. This list
505 -- can be used directly in a Makefile. A call to Compile_Sources must
506 -- precede the call to List_Depend. Also because this routine uses the
507 -- ALI files that were originally loaded and scanned by Compile_Sources,
508 -- no additional ALI files should be scanned between the two calls (i.e.
509 -- between the call to Compile_Sources and List_Depend.)
511 procedure List_Bad_Compilations
;
512 -- Prints out the list of all files for which the compilation failed
514 Usage_Needed
: Boolean := True;
515 -- Flag used to make sure Makeusg is call at most once
518 -- Call Makeusg, if Usage_Needed is True.
519 -- Set Usage_Needed to False.
521 procedure Debug_Msg
(S
: String; N
: Name_Id
);
522 procedure Debug_Msg
(S
: String; N
: File_Name_Type
);
523 procedure Debug_Msg
(S
: String; N
: Unit_Name_Type
);
524 -- If Debug.Debug_Flag_W is set outputs string S followed by name N
526 procedure Recursive_Compute_Depth
(Project
: Project_Id
);
527 -- Compute depth of Project and of the projects it depends on
529 -----------------------
530 -- Gnatmake Routines --
531 -----------------------
533 subtype Lib_Mark_Type
is Byte
;
534 -- Used in Mark_Directory
536 Ada_Lib_Dir
: constant Lib_Mark_Type
:= 1;
537 -- Used to mark a directory as a GNAT lib dir
539 -- Note that the notion of GNAT lib dir is no longer used. The code related
540 -- to it has not been removed to give an idea on how to use the directory
541 -- prefix marking mechanism.
543 -- An Ada library directory is a directory containing ali and object files
544 -- but no source files for the bodies (the specs can be in the same or some
545 -- other directory). These directories are specified in the Gnatmake
546 -- command line with the switch "-Adir" (to specify the spec location -Idir
547 -- cab be used). Gnatmake skips the missing sources whose ali are in Ada
548 -- library directories. For an explanation of why Gnatmake behaves that
549 -- way, see the spec of Make.Compile_Sources. The directory lookup penalty
550 -- is incurred every single time this routine is called.
552 procedure Check_Steps
;
553 -- Check what steps (Compile, Bind, Link) must be executed.
554 -- Set the step flags accordingly.
556 function In_Ada_Lib_Dir
(File
: File_Name_Type
) return Boolean;
557 -- Get directory prefix of this file and get lib mark stored in name
558 -- table for this directory. Then check if an Ada lib mark has been set.
560 procedure Mark_Directory
562 Mark
: Lib_Mark_Type
;
563 On_Command_Line
: Boolean);
564 -- Store the absolute path from Dir in name table and set lib mark as name
565 -- info to identify Ada libraries.
567 -- If Dir is a relative path, when On_Command_Line is True, it is relative
568 -- to the current working directory; when On_Command_Line is False, it is
569 -- relative to the project directory of the main project.
571 Output_Is_Object
: Boolean := True;
572 -- Set to False when using a switch -S for the compiler
574 procedure Check_For_S_Switch
;
575 -- Set Output_Is_Object to False when the -S switch is used for the
579 (Source_File
: File_Name_Type
;
580 Project
: Project_Id
;
581 In_Package
: Package_Id
;
582 Allow_ALI
: Boolean) return Variable_Value
;
583 -- Return the switches for the source file in the specified package of a
584 -- project file. If the Source_File ends with a standard GNAT extension
585 -- (".ads" or ".adb"), try first the full name, then the name without the
586 -- extension, then, if Allow_ALI is True, the name with the extension
587 -- ".ali". If there is no switches for either names, try first Switches
588 -- (others) then the default switches for Ada. If all failed, return
589 -- No_Variable_Value.
591 function Is_In_Object_Directory
592 (Source_File
: File_Name_Type
;
593 Full_Lib_File
: File_Name_Type
) return Boolean;
594 -- Check if, when using a project file, the ALI file is in the project
595 -- directory of the ultimate extending project. If it is not, we ignore
596 -- the fact that this ALI file is read-only.
598 procedure Process_Multilib
(Env
: in out Prj
.Tree
.Environment
);
599 -- Add appropriate --RTS argument to handle multilib
601 procedure Resolve_Relative_Names_In_Switches
(Current_Work_Dir
: String);
602 -- Resolve all relative paths found in the linker and binder switches,
603 -- when using project files.
605 procedure Queue_Library_Project_Sources
;
606 -- For all library project, if the library file does not exist, put all the
607 -- project sources in the queue, and flag the project so that the library
610 procedure Compute_Switches_For_Main
611 (Main_Source_File
: in out File_Name_Type
;
612 Root_Environment
: in out Prj
.Tree
.Environment
;
613 Compute_Builder
: Boolean;
614 Current_Work_Dir
: String);
615 -- Find compiler, binder and linker switches to use for the given main
617 procedure Compute_Executable
618 (Main_Source_File
: File_Name_Type
;
619 Executable
: out File_Name_Type
;
620 Non_Std_Executable
: out Boolean);
621 -- Parse the linker switches and project file to compute the name of the
622 -- executable to generate.
623 -- ??? What is the meaning of Non_Std_Executable
625 procedure Compilation_Phase
626 (Main_Source_File
: File_Name_Type
;
627 Current_Main_Index
: Int
:= 0;
628 Total_Compilation_Failures
: in out Natural;
629 Stand_Alone_Libraries
: in out Boolean;
630 Executable
: File_Name_Type
:= No_File
;
631 Is_Last_Main
: Boolean;
632 Stop_Compile
: out Boolean);
633 -- Build all source files for a given main file
635 -- Current_Main_Index, if not zero, is the index of the current main unit
636 -- in its source file.
638 -- Stand_Alone_Libraries is set to True when there are Stand-Alone
639 -- Libraries, so that gnatbind is invoked with the -F switch to force
640 -- checking of elaboration flags.
642 -- Stop_Compile is set to true if we should not try to compile any more
645 procedure Binding_Phase
646 (Stand_Alone_Libraries
: Boolean := False;
647 Main_ALI_File
: File_Name_Type
);
648 -- Stand_Alone_Libraries should be set to True when there are Stand-Alone
649 -- Libraries, so that gnatbind is invoked with the -F switch to force
650 -- checking of elaboration flags.
652 procedure Library_Phase
653 (Stand_Alone_Libraries
: in out Boolean;
654 Library_Rebuilt
: in out Boolean);
656 -- Stand_Alone_Libraries is set to True when there are Stand-Alone
657 -- Libraries, so that gnatbind is invoked with the -F switch to force
658 -- checking of elaboration flags.
660 procedure Linking_Phase
661 (Non_Std_Executable
: Boolean := False;
662 Executable
: File_Name_Type
:= No_File
;
663 Main_ALI_File
: File_Name_Type
);
664 -- Perform the link of a single executable. The ali file corresponds
665 -- to Main_ALI_File. Executable is the file name of an executable.
666 -- Non_Std_Executable is set to True when there is a possibility that
667 -- the linker will not choose the correct executable file name.
669 ----------------------------------------------------
670 -- Compiler, Binder & Linker Data and Subprograms --
671 ----------------------------------------------------
673 Gcc
: String_Access
:= Program_Name
("gcc", "gnatmake");
674 Gnatbind
: String_Access
:= Program_Name
("gnatbind", "gnatmake");
675 Gnatlink
: String_Access
:= Program_Name
("gnatlink", "gnatmake");
676 -- Default compiler, binder, linker programs
678 Saved_Gcc
: String_Access
:= null;
679 Saved_Gnatbind
: String_Access
:= null;
680 Saved_Gnatlink
: String_Access
:= null;
681 -- Given by the command line. Will be used, if non null
683 Gcc_Path
: String_Access
:=
684 GNAT
.OS_Lib
.Locate_Exec_On_Path
(Gcc
.all);
685 Gnatbind_Path
: String_Access
:=
686 GNAT
.OS_Lib
.Locate_Exec_On_Path
(Gnatbind
.all);
687 Gnatlink_Path
: String_Access
:=
688 GNAT
.OS_Lib
.Locate_Exec_On_Path
(Gnatlink
.all);
689 -- Path for compiler, binder, linker programs, defaulted now for gnatdist.
690 -- Changed later if overridden on command line.
692 Comp_Flag
: constant String_Access
:= new String'("-c");
693 Output_Flag : constant String_Access := new String'("-o");
694 Ada_Flag_1
: constant String_Access
:= new String'("-x");
695 Ada_Flag_2 : constant String_Access := new String'("ada");
696 AdaSCIL_Flag
: constant String_Access
:= new String'("adascil");
697 No_gnat_adc : constant String_Access := new String'("-gnatA");
698 GNAT_Flag
: constant String_Access
:= new String'("-gnatpg");
699 Do_Not_Check_Flag : constant String_Access := new String'("-x");
701 Object_Suffix
: constant String := Get_Target_Object_Suffix
.all;
703 Syntax_Only
: Boolean := False;
704 -- Set to True when compiling with -gnats
706 Display_Executed_Programs
: Boolean := True;
707 -- Set to True if name of commands should be output on stderr (or on stdout
708 -- if the Commands_To_Stdout flag was set by use of the -eS switch).
710 Output_File_Name_Seen
: Boolean := False;
711 -- Set to True after having scanned the file_name for
712 -- switch "-o file_name"
714 Object_Directory_Seen
: Boolean := False;
715 -- Set to True after having scanned the object directory for
716 -- switch "-D obj_dir".
718 Object_Directory_Path
: String_Access
:= null;
719 -- The path name of the object directory, set with switch -D
721 type Make_Program_Type
is (None
, Compiler
, Binder
, Linker
);
723 Program_Args
: Make_Program_Type
:= None
;
724 -- Used to indicate if we are scanning gnatmake, gcc, gnatbind, or gnatbind
725 -- options within the gnatmake command line. Used in Scan_Make_Arg only,
726 -- but must be global since value preserved from one call to another.
728 Temporary_Config_File
: Boolean := False;
729 -- Set to True when there is a temporary config file used for a project
730 -- file, to avoid displaying the -gnatec switch for a temporary file.
732 procedure Add_Switches
733 (The_Package
: Package_Id
;
735 Program
: Make_Program_Type
;
736 Unknown_Switches_To_The_Compiler
: Boolean := True;
737 Env
: in out Prj
.Tree
.Environment
);
740 Program
: Make_Program_Type
;
741 Append_Switch
: Boolean := True;
742 And_Save
: Boolean := True);
745 Program
: Make_Program_Type
;
746 Append_Switch
: Boolean := True;
747 And_Save
: Boolean := True);
748 -- Make invokes one of three programs (the compiler, the binder or the
749 -- linker). For the sake of convenience, some program specific switches
750 -- can be passed directly on the gnatmake command line. This procedure
751 -- records these switches so that gnatmake can pass them to the right
752 -- program. S is the switch to be added at the end of the command line
753 -- for Program if Append_Switch is True. If Append_Switch is False S is
754 -- added at the beginning of the command line.
757 (Source_File
: File_Name_Type
;
758 Is_Main_Source
: Boolean;
759 The_Args
: Argument_List
;
760 Lib_File
: File_Name_Type
;
761 Full_Lib_File
: File_Name_Type
;
762 Lib_File_Attr
: access File_Attributes
;
765 O_File
: out File_Name_Type
;
766 O_Stamp
: out Time_Stamp_Type
);
767 -- Determines whether the library file Lib_File is up-to-date or not. The
768 -- full name (with path information) of the object file corresponding to
769 -- Lib_File is returned in O_File. Its time stamp is saved in O_Stamp.
770 -- ALI is the ALI_Id corresponding to Lib_File. If Lib_File in not
771 -- up-to-date, then the corresponding source file needs to be recompiled.
772 -- In this case ALI = No_ALI_Id.
773 -- Full_Lib_File must be the result of calling Osint.Full_Lib_File_Name on
774 -- Lib_File. Precomputing it saves system calls. Lib_File_Attr is the
775 -- initialized attributes of that file, which is also used to save on
776 -- system calls (it can safely be initialized to Unknown_Attributes).
778 procedure Check_Linker_Options
779 (E_Stamp
: Time_Stamp_Type
;
780 O_File
: out File_Name_Type
;
781 O_Stamp
: out Time_Stamp_Type
);
782 -- Checks all linker options for linker files that are newer
783 -- than E_Stamp. If such objects are found, the youngest object
784 -- is returned in O_File and its stamp in O_Stamp.
786 -- If no obsolete linker files were found, the first missing
787 -- linker file is returned in O_File and O_Stamp is empty.
788 -- Otherwise O_File is No_File.
790 procedure Collect_Arguments
791 (Source_File
: File_Name_Type
;
792 Is_Main_Source
: Boolean;
793 Args
: Argument_List
);
794 -- Collect all arguments for a source to be compiled, including those
795 -- that come from a project file.
797 procedure Display
(Program
: String; Args
: Argument_List
);
798 -- Displays Program followed by the arguments in Args if variable
799 -- Display_Executed_Programs is set. The lower bound of Args must be 1.
801 procedure Report_Compilation_Failed
;
802 -- Delete all temporary files and fail graciously
808 type Temp_Path_Names
is array (Positive range <>) of Path_Name_Type
;
809 type Temp_Path_Ptr
is access Temp_Path_Names
;
811 type Free_File_Indexes
is array (Positive range <>) of Positive;
812 type Free_Indexes_Ptr
is access Free_File_Indexes
;
814 type Project_Compilation_Data
is record
815 Mapping_File_Names
: Temp_Path_Ptr
;
816 -- The name ids of the temporary mapping files used. This is indexed
817 -- on the maximum number of compilation processes we will be spawning
820 Last_Mapping_File_Names
: Natural;
821 -- Index of the last mapping file created for this project
823 Free_Mapping_File_Indexes
: Free_Indexes_Ptr
;
824 -- Indexes in Mapping_File_Names of the mapping file names that can be
825 -- reused for subsequent compilations.
827 Last_Free_Indexes
: Natural;
828 -- Number of mapping files that can be reused
830 -- Information necessary when compiling a project
832 type Project_Compilation_Access
is access Project_Compilation_Data
;
834 package Project_Compilation_Htable
is new Simple_HTable
835 (Header_Num
=> Prj
.Header_Num
,
836 Element
=> Project_Compilation_Access
,
842 Project_Compilation
: Project_Compilation_Htable
.Instance
;
844 Gnatmake_Mapping_File
: String_Access
:= null;
845 -- The path name of a mapping file specified by switch -C=
847 procedure Init_Mapping_File
848 (Project
: Project_Id
;
849 Data
: in out Project_Compilation_Data
;
850 File_Index
: in out Natural);
851 -- Create a new temporary mapping file, and fill it with the project file
852 -- mappings, when using project file(s). The out parameter File_Index is
853 -- the index to the name of the file in the array The_Mapping_File_Names.
855 -------------------------------------------------
856 -- Subprogram declarations moved from the spec --
857 -------------------------------------------------
859 procedure Bind
(ALI_File
: File_Name_Type
; Args
: Argument_List
);
860 -- Binds ALI_File. Args are the arguments to pass to the binder.
861 -- Args must have a lower bound of 1.
863 procedure Display_Commands
(Display
: Boolean := True);
864 -- The default behavior of Make commands (Compile_Sources, Bind, Link)
865 -- is to display them on stderr. This behavior can be changed repeatedly
866 -- by invoking this procedure.
868 -- If a compilation, bind or link failed one of the following 3 exceptions
869 -- is raised. These need to be handled by the calling routines.
871 procedure Compile_Sources
872 (Main_Source
: File_Name_Type
;
873 Args
: Argument_List
;
874 First_Compiled_File
: out File_Name_Type
;
875 Most_Recent_Obj_File
: out File_Name_Type
;
876 Most_Recent_Obj_Stamp
: out Time_Stamp_Type
;
877 Main_Unit
: out Boolean;
878 Compilation_Failures
: out Natural;
879 Main_Index
: Int
:= 0;
880 Check_Readonly_Files
: Boolean := False;
881 Do_Not_Execute
: Boolean := False;
882 Force_Compilations
: Boolean := False;
883 Keep_Going
: Boolean := False;
884 In_Place_Mode
: Boolean := False;
885 Initialize_ALI_Data
: Boolean := True;
886 Max_Process
: Positive := 1);
887 -- Compile_Sources will recursively compile all the sources needed by
888 -- Main_Source. Before calling this routine make sure Namet has been
889 -- initialized. This routine can be called repeatedly with different
890 -- Main_Source file as long as all the source (-I flags), library
891 -- (-B flags) and ada library (-A flags) search paths between calls are
892 -- *exactly* the same. The default directory must also be the same.
894 -- Args contains the arguments to use during the compilations.
895 -- The lower bound of Args must be 1.
897 -- First_Compiled_File is set to the name of the first file that is
898 -- compiled or that needs to be compiled. This is set to No_Name if no
899 -- compilations were needed.
901 -- Most_Recent_Obj_File is set to the full name of the most recent
902 -- object file found when no compilations are needed, that is when
903 -- First_Compiled_File is set to No_Name. When First_Compiled_File
904 -- is set then Most_Recent_Obj_File is set to No_Name.
906 -- Most_Recent_Obj_Stamp is the time stamp of Most_Recent_Obj_File.
908 -- Main_Unit is set to True if Main_Source can be a main unit.
909 -- If Do_Not_Execute is False and First_Compiled_File /= No_Name
910 -- the value of Main_Unit is always False.
911 -- Is this used any more??? It is certainly not used by gnatmake???
913 -- Compilation_Failures is a count of compilation failures. This count
914 -- is used to extract compilation failure reports with Extract_Failure.
916 -- Main_Index, when not zero, is the index of the main unit in source
917 -- file Main_Source which is a multi-unit source.
918 -- Zero indicates that Main_Source is a single unit source file.
920 -- Check_Readonly_Files set it to True to compile source files
921 -- which library files are read-only. When compiling GNAT predefined
922 -- files the "-gnatg" flag is used.
924 -- Do_Not_Execute set it to True to find out the first source that
925 -- needs to be recompiled, but without recompiling it. This file is
926 -- saved in First_Compiled_File.
928 -- Force_Compilations forces all compilations no matter what but
929 -- recompiles read-only files only if Check_Readonly_Files
932 -- Keep_Going when True keep compiling even in the presence of
933 -- compilation errors.
935 -- In_Place_Mode when True save library/object files in their object
936 -- directory if they already exist; otherwise, in the source directory.
938 -- Initialize_ALI_Data set it to True when you want to initialize ALI
939 -- data-structures. This is what you should do most of the time.
940 -- (especially the first time around when you call this routine).
941 -- This parameter is set to False to preserve previously recorded
944 -- Max_Process is the maximum number of processes that should be spawned
945 -- to carry out compilations.
947 -- Flags in Package Opt Affecting Compile_Sources
948 -- -----------------------------------------------
950 -- Check_Object_Consistency set it to False to omit all consistency
951 -- checks between an .ali file and its corresponding object file.
952 -- When this flag is set to true, every time an .ali is read,
953 -- package Osint checks that the corresponding object file
954 -- exists and is more recent than the .ali.
956 -- Use of Name Table Info
957 -- ----------------------
959 -- All file names manipulated by Compile_Sources are entered into the
960 -- Names table. The Byte field of a source file is used to mark it.
962 -- Calling Compile_Sources Several Times
963 -- -------------------------------------
965 -- Upon return from Compile_Sources all the ALI data structures are left
966 -- intact for further browsing. HOWEVER upon entry to this routine ALI
967 -- data structures are re-initialized if parameter Initialize_ALI_Data
968 -- above is set to true. Typically this is what you want the first time
969 -- you call Compile_Sources. You should not load an ali file, call this
970 -- routine with flag Initialize_ALI_Data set to True and then expect
971 -- that ALI information to be around after the call. Note that the first
972 -- time you call Compile_Sources you better set Initialize_ALI_Data to
973 -- True unless you have called Initialize_ALI yourself.
975 -- Compile_Sources ALGORITHM : Compile_Sources (Main_Source)
976 -- -------------------------
978 -- 1. Insert Main_Source in a Queue (Q) and mark it.
980 -- 2. Let unit.adb be the file at the head of the Q. If unit.adb is
981 -- missing but its corresponding ali file is in an Ada library directory
982 -- (see below) then, remove unit.adb from the Q and goto step 4.
983 -- Otherwise, look at the files under the D (dependency) section of
984 -- unit.ali. If unit.ali does not exist or some of the time stamps do
985 -- not match, (re)compile unit.adb.
987 -- An Ada library directory is a directory containing Ada specs, ali
988 -- and object files but no source files for the bodies. An Ada library
989 -- directory is communicated to gnatmake by means of some switch so that
990 -- gnatmake can skip the sources whole ali are in that directory.
991 -- There are two reasons for skipping the sources in this case. Firstly,
992 -- Ada libraries typically come without full sources but binding and
993 -- linking against those libraries is still possible. Secondly, it would
994 -- be very wasteful for gnatmake to systematically check the consistency
995 -- of every external Ada library used in a program. The binder is
996 -- already in charge of catching any potential inconsistencies.
998 -- 3. Look into the W section of unit.ali and insert into the Q all
999 -- unmarked source files. Mark all files newly inserted in the Q.
1000 -- Specifically, assuming that the W section looks like
1002 -- W types%s types.adb types.ali
1003 -- W unchecked_deallocation%s
1004 -- W xref_tab%s xref_tab.adb xref_tab.ali
1006 -- Then xref_tab.adb and types.adb are inserted in the Q if they are not
1008 -- Note that there is no file listed under W unchecked_deallocation%s
1009 -- so no generic body should ever be explicitly compiled (unless the
1010 -- Main_Source at the start was a generic body).
1012 -- 4. Repeat steps 2 and 3 above until the Q is empty
1014 -- Note that the above algorithm works because the units withed in
1015 -- subunits are transitively included in the W section (with section) of
1016 -- the main unit. Likewise the withed units in a generic body needed
1017 -- during a compilation are also transitively included in the W section
1018 -- of the originally compiled file.
1020 procedure Initialize
1021 (Project_Node_Tree
: out Project_Node_Tree_Ref
;
1022 Env
: out Prj
.Tree
.Environment
);
1023 -- Performs default and package initialization. Therefore,
1024 -- Compile_Sources can be called by an external unit.
1027 (ALI_File
: File_Name_Type
;
1028 Args
: Argument_List
;
1029 Success
: out Boolean);
1030 -- Links ALI_File. Args are the arguments to pass to the linker.
1031 -- Args must have a lower bound of 1. Success indicates if the link
1032 -- succeeded or not.
1034 procedure Scan_Make_Arg
1035 (Env
: in out Prj
.Tree
.Environment
;
1037 And_Save
: Boolean);
1038 -- Scan make arguments. Argv is a single argument to be processed.
1039 -- Project_Node_Tree will be used to initialize external references. It
1040 -- must have been initialized.
1046 procedure Add_Arguments
(Args
: Argument_List
) is
1048 if Arguments
= null then
1049 Arguments
:= new Argument_List
(1 .. Args
'Length + 10);
1052 while Last_Argument
+ Args
'Length > Arguments
'Last loop
1054 New_Arguments
: constant Argument_List_Access
:=
1055 new Argument_List
(1 .. Arguments
'Last * 2);
1057 New_Arguments
(1 .. Last_Argument
) :=
1058 Arguments
(1 .. Last_Argument
);
1059 Arguments
:= New_Arguments
;
1064 Arguments
(Last_Argument
+ 1 .. Last_Argument
+ Args
'Length) := Args
;
1065 Last_Argument
:= Last_Argument
+ Args
'Length;
1068 -- --------------------
1069 -- -- Add_Dependency --
1070 -- --------------------
1072 -- procedure Add_Dependency (S : File_Name_Type; On : File_Name_Type) is
1074 -- Dependencies.Increment_Last;
1075 -- Dependencies.Table (Dependencies.Last) := (S, On);
1076 -- end Add_Dependency;
1078 ----------------------------
1079 -- Add_Library_Search_Dir --
1080 ----------------------------
1082 procedure Add_Library_Search_Dir
1084 On_Command_Line
: Boolean)
1087 if On_Command_Line
then
1088 Add_Lib_Search_Dir
(Normalize_Pathname
(Path
));
1091 Get_Name_String
(Main_Project
.Directory
.Display_Name
);
1093 (Normalize_Pathname
(Path
, Name_Buffer
(1 .. Name_Len
)));
1095 end Add_Library_Search_Dir
;
1097 --------------------
1098 -- Add_Object_Dir --
1099 --------------------
1101 procedure Add_Object_Dir
(N
: String) is
1103 Add_Lib_Search_Dir
(N
);
1105 if Verbose_Mode
then
1106 Write_Str
("Adding object directory """);
1113 --------------------
1114 -- Add_Source_Dir --
1115 --------------------
1117 procedure Add_Source_Dir
(N
: String) is
1119 Add_Src_Search_Dir
(N
);
1121 if Verbose_Mode
then
1122 Write_Str
("Adding source directory """);
1129 ---------------------------
1130 -- Add_Source_Search_Dir --
1131 ---------------------------
1133 procedure Add_Source_Search_Dir
1135 On_Command_Line
: Boolean)
1138 if On_Command_Line
then
1139 Add_Src_Search_Dir
(Normalize_Pathname
(Path
));
1142 Get_Name_String
(Main_Project
.Directory
.Display_Name
);
1144 (Normalize_Pathname
(Path
, Name_Buffer
(1 .. Name_Len
)));
1146 end Add_Source_Search_Dir
;
1152 procedure Add_Switch
1154 Program
: Make_Program_Type
;
1155 Append_Switch
: Boolean := True;
1156 And_Save
: Boolean := True)
1159 with package T
is new Table
.Table
(<>);
1160 procedure Generic_Position
(New_Position
: out Integer);
1161 -- Generic procedure that chooses a position for S in T at the
1162 -- beginning or the end, depending on the boolean Append_Switch.
1163 -- Calling this procedure may expand the table.
1165 ----------------------
1166 -- Generic_Position --
1167 ----------------------
1169 procedure Generic_Position
(New_Position
: out Integer) is
1173 if Append_Switch
then
1174 New_Position
:= Integer (T
.Last
);
1176 for J
in reverse T
.Table_Index_Type
'Succ (T
.First
) .. T
.Last
loop
1177 T
.Table
(J
) := T
.Table
(T
.Table_Index_Type
'Pred (J
));
1180 New_Position
:= Integer (T
.First
);
1182 end Generic_Position
;
1184 procedure Gcc_Switches_Pos
is new Generic_Position
(Gcc_Switches
);
1185 procedure Binder_Switches_Pos
is new Generic_Position
(Binder_Switches
);
1186 procedure Linker_Switches_Pos
is new Generic_Position
(Linker_Switches
);
1188 procedure Saved_Gcc_Switches_Pos
is new
1189 Generic_Position
(Saved_Gcc_Switches
);
1191 procedure Saved_Binder_Switches_Pos
is new
1192 Generic_Position
(Saved_Binder_Switches
);
1194 procedure Saved_Linker_Switches_Pos
is new
1195 Generic_Position
(Saved_Linker_Switches
);
1197 New_Position
: Integer;
1199 -- Start of processing for Add_Switch
1205 Saved_Gcc_Switches_Pos
(New_Position
);
1206 Saved_Gcc_Switches
.Table
(New_Position
) := S
;
1209 Saved_Binder_Switches_Pos
(New_Position
);
1210 Saved_Binder_Switches
.Table
(New_Position
) := S
;
1213 Saved_Linker_Switches_Pos
(New_Position
);
1214 Saved_Linker_Switches
.Table
(New_Position
) := S
;
1217 raise Program_Error
;
1223 Gcc_Switches_Pos
(New_Position
);
1224 Gcc_Switches
.Table
(New_Position
) := S
;
1227 Binder_Switches_Pos
(New_Position
);
1228 Binder_Switches
.Table
(New_Position
) := S
;
1231 Linker_Switches_Pos
(New_Position
);
1232 Linker_Switches
.Table
(New_Position
) := S
;
1235 raise Program_Error
;
1240 procedure Add_Switch
1242 Program
: Make_Program_Type
;
1243 Append_Switch
: Boolean := True;
1244 And_Save
: Boolean := True)
1247 Add_Switch
(S
=> new String'(S),
1249 Append_Switch => Append_Switch,
1250 And_Save => And_Save);
1257 procedure Add_Switches
1258 (The_Package : Package_Id;
1260 Program : Make_Program_Type;
1261 Unknown_Switches_To_The_Compiler : Boolean := True;
1262 Env : in out Prj.Tree.Environment)
1264 Switches : Variable_Value;
1265 Switch_List : String_List_Id;
1266 Element : String_Element;
1269 Switch_May_Be_Passed_To_The_Compiler :=
1270 Unknown_Switches_To_The_Compiler;
1272 if File_Name'Length > 0 then
1274 Add_Str_To_Name_Buffer (File_Name);
1277 (Source_File => Name_Find,
1278 Project => Main_Project,
1279 In_Package => The_Package,
1280 Allow_ALI => Program = Binder or else Program = Linker);
1282 if Switches.Kind = List then
1283 Program_Args := Program;
1285 Switch_List := Switches.Values;
1286 while Switch_List /= Nil_String loop
1288 Project_Tree.Shared.String_Elements.Table (Switch_List);
1289 Get_Name_String (Element.Value);
1291 if Name_Len > 0 then
1293 Argv : constant String := Name_Buffer (1 .. Name_Len);
1294 -- We need a copy, because Name_Buffer may be modified
1297 if Verbose_Mode then
1298 Write_Str (" Adding ");
1302 Scan_Make_Arg (Env, Argv, And_Save => False);
1304 if not Gnatmake_Switch_Found
1305 and then not Switch_May_Be_Passed_To_The_Compiler
1309 """ is not a gnatmake switch
. Consider moving
"
1310 & "it to Global_Compilation_Switches
.",
1312 Make_Failed ("*** illegal switch
""" & Argv & """");
1317 Switch_List := Element.Next;
1327 procedure Bind (ALI_File : File_Name_Type; Args : Argument_List) is
1328 Bind_Args : Argument_List (1 .. Args'Last + 2);
1329 Bind_Last : Integer;
1333 pragma Assert (Args'First = 1);
1335 -- Optimize the simple case where the gnatbind command line looks like
1336 -- gnatbind -aO. -I- file.ali
1338 -- gnatbind file.adb
1341 and then Args (Args'First).all = "-aO
" & Normalized_CWD
1342 and then Args (Args'Last).all = "-I
-"
1343 and then ALI_File = Strip_Directory (ALI_File)
1345 Bind_Last := Args'First - 1;
1348 Bind_Last := Args'Last;
1349 Bind_Args (Args'Range) := Args;
1352 -- It is completely pointless to re-check source file time stamps. This
1353 -- has been done already by gnatmake
1355 Bind_Last := Bind_Last + 1;
1356 Bind_Args (Bind_Last) := Do_Not_Check_Flag;
1358 Get_Name_String (ALI_File);
1360 Bind_Last := Bind_Last + 1;
1361 Bind_Args (Bind_Last) := new String'(Name_Buffer (1 .. Name_Len));
1363 GNAT.OS_Lib.Normalize_Arguments (Bind_Args (Args'First .. Bind_Last));
1365 Display (Gnatbind.all, Bind_Args (Args'First .. Bind_Last));
1367 if Gnatbind_Path = null then
1368 Make_Failed ("error
, unable to locate
" & Gnatbind.all);
1372 (Gnatbind_Path.all, Bind_Args (Args'First .. Bind_Last), Success);
1375 Make_Failed ("*** bind failed
.");
1379 --------------------------------
1380 -- Change_To_Object_Directory --
1381 --------------------------------
1383 procedure Change_To_Object_Directory (Project : Project_Id) is
1384 Object_Directory : Path_Name_Type;
1387 pragma Assert (Project /= No_Project);
1389 -- Nothing to do if the current working directory is already the correct
1390 -- object directory.
1392 if Project_Of_Current_Object_Directory /= Project then
1393 Project_Of_Current_Object_Directory := Project;
1394 Object_Directory := Project.Object_Directory.Display_Name;
1396 -- Set the working directory to the object directory of the actual
1399 if Verbose_Mode then
1400 Write_Str ("Changing to object directory
of """);
1401 Write_Name (Project.Display_Name);
1402 Write_Str (""": """);
1403 Write_Name (Object_Directory);
1407 Change_Dir (Get_Name_String (Object_Directory));
1411 -- Fail if unable to change to the object directory
1413 when Directory_Error =>
1414 Make_Failed ("unable to change to object directory
""" &
1416 (Project.Object_Directory.Display_Name) &
1418 Get_Name_String (Project.Display_Name));
1419 end Change_To_Object_Directory;
1426 (Source_File : File_Name_Type;
1427 Is_Main_Source : Boolean;
1428 The_Args : Argument_List;
1429 Lib_File : File_Name_Type;
1430 Full_Lib_File : File_Name_Type;
1431 Lib_File_Attr : access File_Attributes;
1432 Read_Only : Boolean;
1434 O_File : out File_Name_Type;
1435 O_Stamp : out Time_Stamp_Type)
1437 function First_New_Spec (A : ALI_Id) return File_Name_Type;
1438 -- Looks in the with table entries of A and returns the spec file name
1439 -- of the first withed unit (subprogram) for which no spec existed when
1440 -- A was generated but for which there exists one now, implying that A
1441 -- is now obsolete. If no such unit is found No_File is returned.
1442 -- Otherwise the spec file name of the unit is returned.
1444 -- **WARNING** in the event of Uname format modifications, one *MUST*
1445 -- make sure this function is also updated.
1447 -- Note: This function should really be in ali.adb and use Uname
1448 -- services, but this causes the whole compiler to be dragged along
1449 -- for gnatbind and gnatmake.
1451 --------------------
1452 -- First_New_Spec --
1453 --------------------
1455 function First_New_Spec (A : ALI_Id) return File_Name_Type is
1456 Spec_File_Name : File_Name_Type := No_File;
1458 function New_Spec (Uname : Unit_Name_Type) return Boolean;
1459 -- Uname is the name of the spec or body of some ada unit. This
1460 -- function returns True if the Uname is the name of a body which has
1461 -- a spec not mentioned in ALI file A. If True is returned
1462 -- Spec_File_Name above is set to the name of this spec file.
1468 function New_Spec (Uname : Unit_Name_Type) return Boolean is
1469 Spec_Name : Unit_Name_Type;
1470 File_Name : File_Name_Type;
1473 -- Test whether Uname is the name of a body unit (i.e. ends
1476 Get_Name_String (Uname);
1478 Assert (Name_Len > 2 and then Name_Buffer (Name_Len - 1) = '%');
1480 if Name_Buffer (Name_Len) /= 'b' then
1484 -- Convert unit name into spec name
1486 -- ??? this code seems dubious in presence of pragma
1487 -- Source_File_Name since there is no more direct relationship
1488 -- between unit name and file name.
1490 -- ??? Further, what about alternative subunit naming
1492 Name_Buffer (Name_Len) := 's';
1493 Spec_Name := Name_Find;
1494 File_Name := Get_File_Name (Spec_Name, Subunit => False);
1496 -- Look if File_Name is mentioned in A's sdep list.
1497 -- If not look if the file exists. If it does return True.
1500 ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep
1502 if Sdep.Table (D).Sfile = File_Name then
1507 if Full_Source_Name (File_Name) /= No_File then
1508 Spec_File_Name := File_Name;
1515 -- Start of processing for First_New_Spec
1519 ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit
1521 exit U_Chk when Units.Table (U).Utype = Is_Body_Only
1522 and then New_Spec (Units.Table (U).Uname);
1524 for W in Units.Table (U).First_With
1526 Units.Table (U).Last_With
1529 Withs.Table (W).Afile /= No_File
1530 and then New_Spec (Withs.Table (W).Uname);
1534 return Spec_File_Name;
1537 ---------------------------------
1538 -- Data declarations for Check --
1539 ---------------------------------
1541 Full_Obj_File : File_Name_Type;
1542 -- Full name of the object file corresponding to Lib_File
1544 Lib_Stamp : Time_Stamp_Type;
1545 -- Time stamp of the current ada library file
1547 Obj_Stamp : Time_Stamp_Type;
1548 -- Time stamp of the current object file
1550 Modified_Source : File_Name_Type;
1551 -- The first source in Lib_File whose current time stamp differs from
1552 -- that stored in Lib_File.
1554 New_Spec : File_Name_Type;
1555 -- If Lib_File contains in its W (with) section a body (for a
1556 -- subprogram) for which there exists a spec, and the spec did not
1557 -- appear in the Sdep section of Lib_File, New_Spec contains the file
1558 -- name of this new spec.
1560 Source_Name : File_Name_Type;
1561 Text : Text_Buffer_Ptr;
1564 -- Index of the first argument in Args.Table for a given unit
1567 -- Index of the last argument in Args.Table for a given unit
1569 Arg : Arg_Id := Arg_Id'First;
1570 -- Current index in Args.Table for a given unit (init to stop warning)
1572 Number_Of_Switches : Natural;
1573 -- Number of switches recorded for a given unit
1575 Prev_Switch : String_Access;
1576 -- Previous switch processed
1578 Switch_Found : Boolean;
1579 -- True if a given switch has been found
1581 ALI_Project : Project_Id;
1582 -- If the ALI file is in the object directory of a project, this is
1585 -- Start of processing for Check
1588 pragma Assert (Lib_File /= No_File);
1590 -- If ALI file is read-only, temporarily set Check_Object_Consistency to
1591 -- False. We don't care if the object file is not there (presumably a
1592 -- library will be used for linking.)
1596 Saved_Check_Object_Consistency : constant Boolean :=
1597 Check_Object_Consistency;
1599 Check_Object_Consistency := False;
1600 Text := Read_Library_Info_From_Full (Full_Lib_File, Lib_File_Attr);
1601 Check_Object_Consistency := Saved_Check_Object_Consistency;
1605 Text := Read_Library_Info_From_Full (Full_Lib_File, Lib_File_Attr);
1608 Full_Obj_File := Full_Object_File_Name;
1609 Lib_Stamp := Current_Library_File_Stamp;
1610 Obj_Stamp := Current_Object_File_Stamp;
1612 if Full_Lib_File = No_File then
1615 "being checked
...",
1617 Minimum_Verbosity => Opt.Medium);
1621 "being checked
...",
1623 Minimum_Verbosity => Opt.Medium);
1627 O_File := Full_Obj_File;
1628 O_Stamp := Obj_Stamp;
1631 if Full_Lib_File = No_File then
1632 Verbose_Msg (Lib_File, "missing
.");
1634 elsif Obj_Stamp (Obj_Stamp'First) = ' ' then
1635 Verbose_Msg (Full_Obj_File, "missing
.");
1639 (Full_Lib_File, "(" & String (Lib_Stamp) & ") newer than
",
1640 Full_Obj_File, "(" & String (Obj_Stamp) & ")");
1644 ALI := Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
1647 if ALI = No_ALI_Id then
1648 Verbose_Msg (Full_Lib_File, "incorrectly formatted ALI file
");
1651 elsif ALIs.Table (ALI).Ver (1 .. ALIs.Table (ALI).Ver_Len) /=
1652 Verbose_Library_Version
1654 Verbose_Msg (Full_Lib_File, "compiled
with old GNAT version
");
1659 -- Don't take ALI file into account if it was generated with errors
1661 if ALIs.Table (ALI).Compile_Errors then
1662 Verbose_Msg (Full_Lib_File, "had errors
, must be recompiled
");
1667 -- Don't take ALI file into account if no object was generated
1669 if Operating_Mode /= Check_Semantics
1670 and then ALIs.Table (ALI).No_Object
1672 Verbose_Msg (Full_Lib_File, "has no corresponding object
");
1677 -- When compiling with -gnatc, don't take ALI file into account if
1678 -- it has not been generated for the current source, for example if
1679 -- it has been generated for the spec, but we are compiling the body.
1681 if Operating_Mode = Check_Semantics then
1683 File_Name : String := Get_Name_String (Source_File);
1684 OK : Boolean := False;
1687 -- In the ALI file, the source file names are in canonical case
1689 Canonical_Case_File_Name (File_Name);
1691 for U in ALIs.Table (ALI).First_Unit ..
1692 ALIs.Table (ALI).Last_Unit
1694 OK := Get_Name_String (Units.Table (U).Sfile) = File_Name;
1700 (Full_Lib_File, "not generated
for the same source
");
1707 -- Check for matching compiler switches if needed
1709 if Check_Switches then
1711 -- First, collect all the switches
1713 Collect_Arguments (Source_File, Is_Main_Source, The_Args);
1714 Prev_Switch := Dummy_Switch;
1715 Get_Name_String (ALIs.Table (ALI).Sfile);
1716 Switches_To_Check.Set_Last (0);
1718 for J in 1 .. Last_Argument loop
1720 -- Skip -c, -I and -o switches
1722 if Arguments (J) (1) = '-'
1723 and then Arguments (J) (2) /= 'c'
1724 and then Arguments (J) (2) /= 'o'
1725 and then Arguments (J) (2) /= 'I'
1727 Normalize_Compiler_Switches
1729 Normalized_Switches,
1732 for K in 1 .. Last_Norm_Switch loop
1733 Switches_To_Check.Increment_Last;
1734 Switches_To_Check.Table (Switches_To_Check.Last) :=
1735 Normalized_Switches (K);
1740 First_Arg := Units.Table (ALIs.Table (ALI).First_Unit).First_Arg;
1741 Last_Arg := Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg;
1743 for J in 1 .. Switches_To_Check.Last loop
1745 -- Comparing switches is delicate because gcc reorders a number
1746 -- of switches, according to lang-specs.h, but gnatmake doesn't
1747 -- have sufficient knowledge to perform the same reordering.
1748 -- Instead, we ignore orders between different "first letter
"
1749 -- switches, but keep orders between same switches, e.g -O -O2
1750 -- is different than -O2 -O, but -g -O is equivalent to -O -g.
1752 if Switches_To_Check.Table (J) (2) /= Prev_Switch (2) or else
1753 (Prev_Switch'Length >= 6 and then
1754 Prev_Switch (2 .. 5) = "gnat
" and then
1755 Switches_To_Check.Table (J)'Length >= 6 and then
1756 Switches_To_Check.Table (J) (2 .. 5) = "gnat
" and then
1757 Prev_Switch (6) /= Switches_To_Check.Table (J) (6))
1759 Prev_Switch := Switches_To_Check.Table (J);
1763 Switch_Found := False;
1765 for K in Arg .. Last_Arg loop
1767 Switches_To_Check.Table (J).all = Args.Table (K).all
1770 Switch_Found := True;
1775 if not Switch_Found then
1776 if Verbose_Mode then
1777 Verbose_Msg (ALIs.Table (ALI).Sfile,
1778 "switch mismatch
""" &
1779 Switches_To_Check.Table (J).all & '"');
1787 Number_Of_Switches := Natural (Last_Arg - First_Arg + 1);
1789 -- Do not count the multilib switches reinstated by the compiler
1790 -- according to the lang-specs.h.settings.
1792 for K in First_Arg .. Last_Arg loop
1793 if Args.Table (K).all = "-mrtp" then
1794 Number_Of_Switches := Number_Of_Switches - 1;
1798 if Switches_To_Check.Last /= Number_Of_Switches then
1799 if Verbose_Mode then
1800 Verbose_Msg (ALIs.Table (ALI).Sfile,
1801 "different number of switches");
1803 for K in First_Arg .. Last_Arg loop
1804 Write_Str (Args.Table (K).all);
1810 for J in 1 .. Switches_To_Check.Last loop
1811 Write_Str (Switches_To_Check.Table (J).all);
1823 -- Get the source files and their message digests. Note that some
1824 -- sources may be missing if ALI is out-of-date.
1826 Set_Source_Table (ALI);
1828 Modified_Source := Time_Stamp_Mismatch (ALI, Read_Only);
1830 -- To avoid using too much memory when switch -m is used, free the
1831 -- memory allocated for the source file when computing the checksum.
1833 if Minimal_Recompilation then
1834 Sinput.P.Clear_Source_File_Table;
1837 if Modified_Source /= No_File then
1840 if Verbose_Mode then
1841 Source_Name := Full_Source_Name (Modified_Source);
1843 if Source_Name /= No_File then
1844 Verbose_Msg (Source_Name, "time stamp mismatch");
1846 Verbose_Msg (Modified_Source, "missing");
1851 New_Spec := First_New_Spec (ALI);
1853 if New_Spec /= No_File then
1856 if Verbose_Mode then
1857 Source_Name := Full_Source_Name (New_Spec);
1859 if Source_Name /= No_File then
1860 Verbose_Msg (Source_Name, "new spec");
1862 Verbose_Msg (New_Spec, "old spec missing");
1866 elsif not Read_Only and then Main_Project /= No_Project then
1868 Uname : constant Name_Id :=
1869 Check_Source_Info_In_ALI (ALI, Project_Tree);
1871 Udata : Prj.Unit_Index;
1874 if Uname = No_Name then
1879 -- Check that ALI file is in the correct object directory.
1880 -- If it is in the object directory of a project that is
1881 -- extended and it depends on a source that is in one of
1882 -- its extending projects, then the ALI file is not in the
1883 -- correct object directory.
1885 -- First, find the project of this ALI file. As there may be
1886 -- several projects with the same object directory, we first
1887 -- need to find the project of the source.
1889 ALI_Project := No_Project;
1891 Udata := Units_Htable.Get (Project_Tree.Units_HT, Uname);
1893 if Udata /= No_Unit_Index then
1894 if Udata.File_Names (Impl) /= null
1895 and then Udata.File_Names (Impl).File = Source_File
1897 ALI_Project := Udata.File_Names (Impl).Project;
1899 elsif Udata.File_Names (Spec) /= null
1900 and then Udata.File_Names (Spec).File = Source_File
1902 ALI_Project := Udata.File_Names (Spec).Project;
1907 if ALI_Project = No_Project then
1912 Obj_Dir : Path_Name_Type;
1913 Res_Obj_Dir : constant String :=
1916 (Get_Name_String (Full_Lib_File)),
1918 Opt.Follow_Links_For_Dirs,
1919 Case_Sensitive => False);
1923 Add_Str_To_Name_Buffer (Res_Obj_Dir);
1925 if not Is_Directory_Separator (Name_Buffer (Name_Len)) then
1926 Add_Char_To_Name_Buffer (Directory_Separator);
1929 Obj_Dir := Name_Find;
1931 while ALI_Project /= No_Project
1932 and then Obj_Dir /= ALI_Project.Object_Directory.Name
1934 ALI_Project := ALI_Project.Extended_By;
1938 if ALI_Project = No_Project then
1941 Verbose_Msg (Lib_File, " wrong object directory");
1945 -- If the ALI project is not extended, then it must be in
1946 -- the correct object directory.
1948 if ALI_Project.Extended_By = No_Project then
1952 -- Count the extending projects
1960 Proj := ALI_Project;
1962 Proj := Proj.Extended_By;
1963 exit when Proj = No_Project;
1964 Num_Ext := Num_Ext + 1;
1967 -- Make a list of the extending projects
1970 Projects : array (1 .. Num_Ext) of Project_Id;
1972 OK : Boolean := True;
1976 Proj := ALI_Project;
1977 for J in Projects'Range loop
1978 Proj := Proj.Extended_By;
1979 Projects (J) := Proj;
1982 -- Now check if any of the dependant sources are in any
1983 -- of these extending projects.
1986 for D in ALIs.Table (ALI).First_Sdep ..
1987 ALIs.Table (ALI).Last_Sdep
1989 Dep := Sdep.Table (D);
1990 UID := Units_Htable.Get_First (Project_Tree.Units_HT);
1994 while UID /= null loop
1995 if UID.File_Names (Impl) /= null
1996 and then UID.File_Names (Impl).File = Dep.Sfile
1998 Proj := UID.File_Names (Impl).Project;
2000 elsif UID.File_Names (Spec) /= null
2001 and then UID.File_Names (Spec).File = Dep.Sfile
2003 Proj := UID.File_Names (Spec).Project;
2006 -- If a source is in a project, check if it is one
2009 if Proj /= No_Project then
2010 for J in Projects'Range loop
2011 if Proj = Projects (J) then
2021 Units_Htable.Get_Next (Project_Tree.Units_HT);
2025 -- If one of the dependent sources is in one project of
2026 -- the list, then we must recompile.
2030 Verbose_Msg (Lib_File, " wrong object directory");
2039 ------------------------
2040 -- Check_For_S_Switch --
2041 ------------------------
2043 procedure Check_For_S_Switch is
2045 -- By default, we generate an object file
2047 Output_Is_Object := True;
2049 for Arg in 1 .. Last_Argument loop
2050 if Arguments (Arg).all = "-S" then
2051 Output_Is_Object := False;
2053 elsif Arguments (Arg).all = "-c" then
2054 Output_Is_Object := True;
2057 end Check_For_S_Switch;
2059 --------------------------
2060 -- Check_Linker_Options --
2061 --------------------------
2063 procedure Check_Linker_Options
2064 (E_Stamp : Time_Stamp_Type;
2065 O_File : out File_Name_Type;
2066 O_Stamp : out Time_Stamp_Type)
2068 procedure Check_File (File : File_Name_Type);
2069 -- Update O_File and O_Stamp if the given file is younger than E_Stamp
2070 -- and O_Stamp, or if O_File is No_File and File does not exist.
2072 function Get_Library_File (Name : String) return File_Name_Type;
2073 -- Return the full file name including path of a library based
2074 -- on the name specified with the -l linker option, using the
2075 -- Ada object path. Return No_File if no such file can be found.
2077 type Char_Array is array (Natural) of Character;
2078 type Char_Array_Access is access constant Char_Array;
2080 Template : Char_Array_Access;
2081 pragma Import (C, Template, "__gnat_library_template");
2087 procedure Check_File (File : File_Name_Type) is
2088 Stamp : Time_Stamp_Type;
2089 Name : File_Name_Type := File;
2092 Get_Name_String (Name);
2094 -- Remove any trailing NUL characters
2096 while Name_Len >= Name_Buffer'First
2097 and then Name_Buffer (Name_Len) = NUL
2099 Name_Len := Name_Len - 1;
2102 if Name_Len = 0 then
2105 elsif Name_Buffer (1) = '-' then
2107 -- Do not check if File is a switch other than "-l"
2109 if Name_Buffer (2) /= 'l
' then
2113 -- The argument is a library switch, get actual name. It
2114 -- is necessary to make a copy of the relevant part of
2115 -- Name_Buffer as Get_Library_Name uses Name_Buffer as well.
2118 Base_Name : constant String := Name_Buffer (3 .. Name_Len);
2121 Name := Get_Library_File (Base_Name);
2124 if Name = No_File then
2129 Stamp := File_Stamp (Name);
2131 -- Find the youngest object file that is younger than the
2132 -- executable. If no such file exist, record the first object
2133 -- file that is not found.
2135 if (O_Stamp < Stamp and then E_Stamp < Stamp)
2136 or else (O_File = No_File and then Stamp (Stamp'First) = ' ')
2141 -- Strip the trailing NUL if present
2143 Get_Name_String (O_File);
2145 if Name_Buffer (Name_Len) = NUL then
2146 Name_Len := Name_Len - 1;
2147 O_File := Name_Find;
2152 ----------------------
2153 -- Get_Library_Name --
2154 ----------------------
2156 -- See comments in a-adaint.c about template syntax
2158 function Get_Library_File (Name : String) return File_Name_Type is
2159 File : File_Name_Type := No_File;
2164 for Ptr in Template'Range loop
2165 case Template (Ptr) is
2167 Add_Str_To_Name_Buffer (Name);
2170 File := Full_Lib_File_Name (Name_Find);
2171 exit when File /= No_File;
2178 Add_Char_To_Name_Buffer (Template (Ptr));
2182 -- The for loop exited because the end of the template
2183 -- was reached. File contains the last possible file name
2186 if File = No_File and then Name_Len > 0 then
2187 File := Full_Lib_File_Name (Name_Find);
2191 end Get_Library_File;
2193 -- Start of processing for Check_Linker_Options
2197 O_Stamp := (others => ' ');
2199 -- Process linker options from the ALI files
2201 for Opt in 1 .. Linker_Options.Last loop
2202 Check_File (File_Name_Type (Linker_Options.Table (Opt).Name));
2205 -- Process options given on the command line
2207 for Opt in Linker_Switches.First .. Linker_Switches.Last loop
2209 -- Check if the previous Opt has one of the two switches
2210 -- that take an extra parameter. (See GCC manual.)
2212 if Opt = Linker_Switches.First
2213 or else (Linker_Switches.Table (Opt - 1).all /= "-u"
2215 Linker_Switches.Table (Opt - 1).all /= "-Xlinker"
2217 Linker_Switches.Table (Opt - 1).all /= "-L")
2220 Add_Str_To_Name_Buffer (Linker_Switches.Table (Opt).all);
2221 Check_File (Name_Find);
2224 end Check_Linker_Options;
2230 procedure Check_Steps is
2232 -- If either -c, -b or -l has been specified, we will not necessarily
2233 -- execute all steps.
2236 Do_Compile_Step := Do_Compile_Step and Compile_Only;
2237 Do_Bind_Step := Do_Bind_Step and Bind_Only;
2238 Do_Link_Step := Do_Link_Step and Link_Only;
2240 -- If -c has been specified, but not -b, ignore any potential -l
2242 if Do_Compile_Step and then not Do_Bind_Step then
2243 Do_Link_Step := False;
2248 -----------------------
2249 -- Collect_Arguments --
2250 -----------------------
2252 procedure Collect_Arguments
2253 (Source_File : File_Name_Type;
2254 Is_Main_Source : Boolean;
2255 Args : Argument_List)
2257 pragma Unreferenced (Is_Main_Source);
2260 Arguments_Project := No_Project;
2262 Add_Arguments (Args);
2264 if Main_Project /= No_Project then
2266 Source_File_Name : constant String :=
2267 Get_Name_String (Source_File);
2268 Compiler_Package : Prj.Package_Id;
2269 Switches : Prj.Variable_Value;
2274 (Source_File_Name => Source_File_Name,
2275 Project => Arguments_Project,
2276 Path => Arguments_Path_Name,
2277 In_Tree => Project_Tree);
2279 -- If the source is not a source of a project file, add the
2280 -- recorded arguments. Check will be done later if the source
2281 -- need to be compiled that the switch -x has been used.
2283 if Arguments_Project = No_Project then
2284 Add_Arguments (The_Saved_Gcc_Switches.all);
2286 elsif not Arguments_Project.Externally_Built or else Must_Compile
2288 -- We get the project directory for the relative path
2289 -- switches and arguments.
2291 Arguments_Project :=
2292 Ultimate_Extending_Project_Of (Arguments_Project);
2294 -- If building a dynamic or relocatable library, compile with
2295 -- PIC option, if it exists.
2297 if Arguments_Project.Library
2298 and then Arguments_Project.Library_Kind /= Static
2301 PIC : constant String := MLib.Tgt.PIC_Option;
2304 Add_Arguments ((1 => new String'(PIC
)));
2309 -- We now look for package Compiler and get the switches from
2314 (Name
=> Name_Compiler
,
2315 In_Packages
=> Arguments_Project
.Decl
.Packages
,
2316 Shared
=> Project_Tree
.Shared
);
2318 if Compiler_Package
/= No_Package
then
2320 -- If package Gnatmake.Compiler exists, we get the specific
2321 -- switches for the current source, or the global switches,
2326 (Source_File
=> Source_File
,
2327 Project
=> Arguments_Project
,
2328 In_Package
=> Compiler_Package
,
2329 Allow_ALI
=> False);
2333 case Switches
.Kind
is
2335 -- We have a list of switches. We add these switches,
2336 -- plus the saved gcc switches.
2340 Current
: String_List_Id
:= Switches
.Values
;
2341 Element
: String_Element
;
2342 Number
: Natural := 0;
2345 while Current
/= Nil_String
loop
2346 Element
:= Project_Tree
.Shared
.String_Elements
.
2348 Number
:= Number
+ 1;
2349 Current
:= Element
.Next
;
2353 New_Args
: Argument_List
(1 .. Number
);
2354 Last_New
: Natural := 0;
2355 Dir_Path
: constant String := Get_Name_String
2356 (Arguments_Project
.Directory
.Display_Name
);
2359 Current
:= Switches
.Values
;
2361 for Index
in New_Args
'Range loop
2362 Element
:= Project_Tree
.Shared
.String_Elements
.
2364 Get_Name_String
(Element
.Value
);
2366 if Name_Len
> 0 then
2367 Last_New
:= Last_New
+ 1;
2368 New_Args
(Last_New
) :=
2369 new String'(Name_Buffer (1 .. Name_Len));
2370 Ensure_Absolute_Path
2371 (New_Args (Last_New),
2372 Do_Fail => Make_Failed'Access,
2374 Including_Non_Switch => False);
2377 Current := Element.Next;
2381 (Configuration_Pragmas_Switch (Arguments_Project)
2382 & New_Args (1 .. Last_New)
2383 & The_Saved_Gcc_Switches.all);
2387 -- We have a single switch. We add this switch,
2388 -- plus the saved gcc switches.
2391 Get_Name_String (Switches.Value);
2394 New_Args : Argument_List :=
2396 (Name_Buffer
(1 .. Name_Len
)));
2397 Dir_Path
: constant String :=
2400 Directory
.Display_Name
);
2403 Ensure_Absolute_Path
2405 Do_Fail
=> Make_Failed
'Access,
2407 Including_Non_Switch
=> False);
2409 (Configuration_Pragmas_Switch
(Arguments_Project
) &
2410 New_Args
& The_Saved_Gcc_Switches
.all);
2413 -- We have no switches from Gnatmake.Compiler.
2414 -- We add the saved gcc switches.
2418 (Configuration_Pragmas_Switch
(Arguments_Project
) &
2419 The_Saved_Gcc_Switches
.all);
2425 -- Set Output_Is_Object, depending if there is a -S switch.
2426 -- If the bind step is not performed, and there is a -S switch,
2427 -- then we will not check for a valid object file.
2430 end Collect_Arguments
;
2432 ---------------------
2433 -- Compile_Sources --
2434 ---------------------
2436 procedure Compile_Sources
2437 (Main_Source
: File_Name_Type
;
2438 Args
: Argument_List
;
2439 First_Compiled_File
: out File_Name_Type
;
2440 Most_Recent_Obj_File
: out File_Name_Type
;
2441 Most_Recent_Obj_Stamp
: out Time_Stamp_Type
;
2442 Main_Unit
: out Boolean;
2443 Compilation_Failures
: out Natural;
2444 Main_Index
: Int
:= 0;
2445 Check_Readonly_Files
: Boolean := False;
2446 Do_Not_Execute
: Boolean := False;
2447 Force_Compilations
: Boolean := False;
2448 Keep_Going
: Boolean := False;
2449 In_Place_Mode
: Boolean := False;
2450 Initialize_ALI_Data
: Boolean := True;
2451 Max_Process
: Positive := 1)
2453 Mfile
: Natural := No_Mapping_File
;
2454 Mapping_File_Arg
: String_Access
;
2455 -- Info on the mapping file
2457 Need_To_Check_Standard_Library
: Boolean :=
2458 (Check_Readonly_Files
or Must_Compile
)
2459 and not Unique_Compile
;
2461 procedure Add_Process
2463 Sfile
: File_Name_Type
;
2464 Afile
: File_Name_Type
;
2465 Uname
: Unit_Name_Type
;
2466 Full_Lib_File
: File_Name_Type
;
2467 Lib_File_Attr
: File_Attributes
;
2468 Mfile
: Natural := No_Mapping_File
);
2469 -- Adds process Pid to the current list of outstanding compilation
2470 -- processes and record the full name of the source file Sfile that
2471 -- we are compiling, the name of its library file Afile and the
2472 -- name of its unit Uname. If Mfile is not equal to No_Mapping_File,
2473 -- it is the index of the mapping file used during compilation in the
2474 -- array The_Mapping_File_Names.
2476 procedure Await_Compile
2477 (Data
: out Compilation_Data
;
2479 -- Awaits that an outstanding compilation process terminates. When it
2480 -- does set Data to the information registered for the corresponding
2481 -- call to Add_Process. Note that this time stamp can be used to check
2482 -- whether the compilation did generate an object file. OK is set to
2483 -- True if the compilation succeeded. Data could be No_Compilation_Data
2484 -- if there was no compilation to wait for.
2486 function Bad_Compilation_Count
return Natural;
2487 -- Returns the number of compilation failures
2489 procedure Check_Standard_Library
;
2490 -- Check if s-stalib.adb needs to be compiled
2492 procedure Collect_Arguments_And_Compile
2493 (Full_Source_File
: File_Name_Type
;
2494 Lib_File
: File_Name_Type
;
2496 Pid
: out Process_Id
;
2497 Process_Created
: out Boolean);
2498 -- Collect arguments from project file (if any) and compile. If no
2499 -- compilation was attempted, Processed_Created is set to False, and the
2500 -- value of Pid is unknown.
2503 (Project
: Project_Id
;
2507 Args
: Argument_List
) return Process_Id
;
2508 -- Compiles S using Args. If S is a GNAT predefined source "-gnatpg" is
2509 -- added to Args. Non blocking call. L corresponds to the expected
2510 -- library file name. Process_Id of the process spawned to execute the
2513 type ALI_Project
is record
2515 Project
: Project_Id
;
2518 package Good_ALI
is new Table
.Table
(
2519 Table_Component_Type
=> ALI_Project
,
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_Project
;
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
; Project
: Project_Id
);
2546 -- Records in the previous set the Id of an ALI file
2548 function Must_Exit_Because_Of_Error
return Boolean;
2549 -- Return True if there were errors and the user decided to exit in such
2550 -- a case. This waits for any outstanding compilation.
2552 function Start_Compile_If_Possible
(Args
: Argument_List
) return Boolean;
2553 -- Check if there is more work that we can do (i.e. the Queue is non
2554 -- empty). If there is, do it only if we have not yet used up all the
2555 -- available processes.
2556 -- Returns True if we should exit the main loop
2558 procedure Wait_For_Available_Slot
;
2559 -- Check if we should wait for a compilation to finish. This is the case
2560 -- if all the available processes are busy compiling sources or there is
2561 -- nothing else to do (that is the Q is empty and there are no good ALIs
2564 procedure Fill_Queue_From_ALI_Files
;
2565 -- Check if we recorded good ALI files. If yes process them now in the
2566 -- order in which they have been recorded. There are two occasions in
2567 -- which we record good ali files. The first is in phase 1 when, after
2568 -- scanning an existing ALI file we realize it is up-to-date, the second
2569 -- instance is after a successful compilation.
2575 procedure Add_Process
2577 Sfile
: File_Name_Type
;
2578 Afile
: File_Name_Type
;
2579 Uname
: Unit_Name_Type
;
2580 Full_Lib_File
: File_Name_Type
;
2581 Lib_File_Attr
: File_Attributes
;
2582 Mfile
: Natural := No_Mapping_File
)
2584 OC1
: constant Positive := Outstanding_Compiles
+ 1;
2587 pragma Assert
(OC1
<= Max_Process
);
2588 pragma Assert
(Pid
/= Invalid_Pid
);
2590 Running_Compile
(OC1
) :=
2592 Full_Source_File
=> Sfile
,
2594 Full_Lib_File
=> Full_Lib_File
,
2595 Lib_File_Attr
=> Lib_File_Attr
,
2596 Source_Unit
=> Uname
,
2597 Mapping_File
=> Mfile
,
2598 Project
=> Arguments_Project
);
2600 Outstanding_Compiles
:= OC1
;
2602 if Arguments_Project
/= No_Project
then
2603 Queue
.Set_Obj_Dir_Busy
(Arguments_Project
.Object_Directory
.Name
);
2607 --------------------
2611 procedure Await_Compile
2612 (Data
: out Compilation_Data
;
2616 Project
: Project_Id
;
2617 Comp_Data
: Project_Compilation_Access
;
2620 pragma Assert
(Outstanding_Compiles
> 0);
2622 Data
:= No_Compilation_Data
;
2625 Wait_Process
(Pid
, OK
);
2627 if Pid
= Invalid_Pid
then
2631 -- Look into the running compilation processes for this PID
2633 for J
in Running_Compile
'First .. Outstanding_Compiles
loop
2634 if Pid
= Running_Compile
(J
).Pid
then
2635 Data
:= Running_Compile
(J
);
2636 Project
:= Running_Compile
(J
).Project
;
2638 if Project
/= No_Project
then
2639 Queue
.Set_Obj_Dir_Free
(Project
.Object_Directory
.Name
);
2642 -- If a mapping file was used by this compilation, get its file
2643 -- name for reuse by a subsequent compilation.
2645 if Running_Compile
(J
).Mapping_File
/= No_Mapping_File
then
2647 Project_Compilation_Htable
.Get
2648 (Project_Compilation
, Project
);
2649 Comp_Data
.Last_Free_Indexes
:=
2650 Comp_Data
.Last_Free_Indexes
+ 1;
2651 Comp_Data
.Free_Mapping_File_Indexes
2652 (Comp_Data
.Last_Free_Indexes
) :=
2653 Running_Compile
(J
).Mapping_File
;
2656 -- To actually remove this Pid and related info from
2657 -- Running_Compile replace its entry with the last valid
2658 -- entry in Running_Compile.
2660 if J
= Outstanding_Compiles
then
2663 Running_Compile
(J
) :=
2664 Running_Compile
(Outstanding_Compiles
);
2667 Outstanding_Compiles
:= Outstanding_Compiles
- 1;
2672 -- If the PID was not found, return with OK set to False
2674 if Data
= No_Compilation_Data
then
2679 ---------------------------
2680 -- Bad_Compilation_Count --
2681 ---------------------------
2683 function Bad_Compilation_Count
return Natural is
2685 return Bad_Compilation
.Last
- Bad_Compilation
.First
+ 1;
2686 end Bad_Compilation_Count
;
2688 ----------------------------
2689 -- Check_Standard_Library --
2690 ----------------------------
2692 procedure Check_Standard_Library
is
2694 Need_To_Check_Standard_Library
:= False;
2697 if not Targparm
.Suppress_Standard_Library_On_Target
then
2698 Add_Str_To_Name_Buffer
(Standard_Library_Package_Body_Name
);
2700 Add_Str_To_Name_Buffer
(System_Package_Spec_Name
);
2704 Add_It
: Boolean := True;
2705 Sfile
: File_Name_Type
;
2708 Sfile
:= Name_Enter
;
2710 -- If we have a special runtime, we add the standard library only
2711 -- if we can find it.
2714 Add_It
:= Full_Source_Name
(Sfile
) /= No_File
;
2719 ((Format
=> Format_Gnatmake
,
2721 Unit
=> No_Unit_Name
,
2722 Project
=> No_Project
,
2726 if Is_In_Obsoleted
(Sfile
) then
2727 Executable_Obsolete
:= True;
2732 end Check_Standard_Library
;
2734 -----------------------------------
2735 -- Collect_Arguments_And_Compile --
2736 -----------------------------------
2738 procedure Collect_Arguments_And_Compile
2739 (Full_Source_File
: File_Name_Type
;
2740 Lib_File
: File_Name_Type
;
2742 Pid
: out Process_Id
;
2743 Process_Created
: out Boolean) is
2745 Process_Created
:= False;
2747 -- If we use mapping file (-P or -C switches), then get one
2749 if Create_Mapping_File
then
2750 Get_Mapping_File
(Arguments_Project
);
2753 -- If the source is part of a project file, we set the ADA_*_PATHs,
2754 -- check for an eventual library project, and use the full path.
2756 if Arguments_Project
/= No_Project
then
2757 if not Arguments_Project
.Externally_Built
2758 or else Must_Compile
2760 Prj
.Env
.Set_Ada_Paths
2763 Including_Libraries
=> True,
2764 Include_Path
=> Use_Include_Path_File
);
2766 if not Unique_Compile
2767 and then MLib
.Tgt
.Support_For_Libraries
/= Prj
.None
2770 Prj
: constant Project_Id
:=
2771 Ultimate_Extending_Project_Of
(Arguments_Project
);
2775 and then (not Prj
.Externally_Built
or else Must_Compile
)
2776 and then not Prj
.Need_To_Build_Lib
2778 -- Add to the Q all sources of the project that have
2781 Insert_Project_Sources
2782 (The_Project
=> Prj
,
2783 All_Projects
=> False,
2786 -- Now mark the project as processed
2788 Prj
.Need_To_Build_Lib
:= True;
2795 (Project
=> Arguments_Project
,
2796 S
=> File_Name_Type
(Arguments_Path_Name
),
2798 Source_Index
=> Source_Index
,
2799 Args
=> Arguments
(1 .. Last_Argument
));
2800 Process_Created
:= True;
2804 -- If this is a source outside of any project file, make sure it
2805 -- will be compiled in object directory of the main project file.
2809 (Project
=> Main_Project
,
2810 S
=> Full_Source_File
,
2812 Source_Index
=> Source_Index
,
2813 Args
=> Arguments
(1 .. Last_Argument
));
2814 Process_Created
:= True;
2816 end Collect_Arguments_And_Compile
;
2823 (Project
: Project_Id
;
2827 Args
: Argument_List
) return Process_Id
2829 Comp_Args
: Argument_List
(Args
'First .. Args
'Last + 10);
2830 Comp_Next
: Integer := Args
'First;
2831 Comp_Last
: Integer;
2832 Arg_Index
: Integer;
2834 function Ada_File_Name
(Name
: File_Name_Type
) return Boolean;
2835 -- Returns True if Name is the name of an ada source file
2836 -- (i.e. suffix is .ads or .adb)
2842 function Ada_File_Name
(Name
: File_Name_Type
) return Boolean is
2844 Get_Name_String
(Name
);
2847 and then Name_Buffer
(Name_Len
- 3 .. Name_Len
- 1) = ".ad"
2848 and then (Name_Buffer
(Name_Len
) = 'b'
2850 Name_Buffer
(Name_Len
) = 's');
2853 -- Start of processing for Compile
2856 Enter_Into_Obsoleted
(S
);
2858 -- By default, Syntax_Only is False
2860 Syntax_Only
:= False;
2862 for J
in Args
'Range loop
2863 if Args
(J
).all = "-gnats" then
2865 -- If we compile with -gnats, the bind step and the link step
2866 -- are inhibited. Also, we set Syntax_Only to True, so that
2867 -- we don't fail when we don't find the ALI file, after
2870 Do_Bind_Step
:= False;
2871 Do_Link_Step
:= False;
2872 Syntax_Only
:= True;
2874 elsif Args
(J
).all = "-gnatc" then
2876 -- If we compile with -gnatc, the bind step and the link step
2877 -- are inhibited. We set Syntax_Only to False for the case when
2878 -- -gnats was previously specified.
2880 Do_Bind_Step
:= False;
2881 Do_Link_Step
:= False;
2882 Syntax_Only
:= False;
2886 Comp_Args
(Comp_Next
) := new String'("-gnatea");
2887 Comp_Next := Comp_Next + 1;
2889 Comp_Args (Comp_Next) := Comp_Flag;
2890 Comp_Next := Comp_Next + 1;
2892 -- Optimize the simple case where the gcc command line looks like
2893 -- gcc -c -I. ... -I- file.adb
2895 -- gcc -c ... file.adb
2897 if Args (Args'First).all = "-I" & Normalized_CWD
2898 and then Args (Args'Last).all = "-I-"
2899 and then S = Strip_Directory (S)
2901 Comp_Last := Comp_Next + Args'Length - 3;
2902 Arg_Index := Args'First + 1;
2905 Comp_Last := Comp_Next + Args'Length - 1;
2906 Arg_Index := Args'First;
2909 -- Make a deep copy of the arguments, because Normalize_Arguments
2910 -- may deallocate some arguments. Also strip target specific -mxxx
2911 -- switches in CodePeer mode.
2915 Last : constant Natural := Comp_Last;
2919 for J in Comp_Next .. Last loop
2921 Str : String renames Args (Arg_Index).all;
2924 and then Str'Length > 2
2925 and then Str (Str'First .. Str'First + 1) = "-m"
2927 Comp_Last := Comp_Last - 1;
2929 Comp_Args (Index) := new String'(Str
);
2934 Arg_Index
:= Arg_Index
+ 1;
2938 -- Set -gnatpg for predefined files (for this purpose the renamings
2939 -- such as Text_IO do not count as predefined). Note that we strip
2940 -- the directory name from the source file name because the call to
2941 -- Fname.Is_Predefined_File_Name cannot deal with directory prefixes.
2944 Fname
: constant File_Name_Type
:= Strip_Directory
(S
);
2947 if Is_Predefined_File_Name
2948 (Fname
, Renamings_Included
=> False)
2950 if Check_Readonly_Files
or else Must_Compile
then
2951 Comp_Args
(Comp_Args
'First + 2 .. Comp_Last
+ 1) :=
2952 Comp_Args
(Comp_Args
'First + 1 .. Comp_Last
);
2953 Comp_Last
:= Comp_Last
+ 1;
2954 Comp_Args
(Comp_Args
'First + 1) := GNAT_Flag
;
2958 ("not allowed to compile """ &
2959 Get_Name_String
(Fname
) &
2960 """; use -a switch, or use the compiler directly with "
2961 & "the ""-gnatg"" switch");
2966 -- Now check if the file name has one of the suffixes familiar to
2967 -- the gcc driver. If this is not the case then add the ada flag
2969 -- Append systematically "-x adascil" in CodePeer mode instead, to
2970 -- force the use of gnat1scil instead of gnat1.
2972 if CodePeer_Mode
then
2973 Comp_Last
:= Comp_Last
+ 1;
2974 Comp_Args
(Comp_Last
) := Ada_Flag_1
;
2975 Comp_Last
:= Comp_Last
+ 1;
2976 Comp_Args
(Comp_Last
) := AdaSCIL_Flag
;
2978 elsif not Ada_File_Name
(S
) then
2979 Comp_Last
:= Comp_Last
+ 1;
2980 Comp_Args
(Comp_Last
) := Ada_Flag_1
;
2981 Comp_Last
:= Comp_Last
+ 1;
2982 Comp_Args
(Comp_Last
) := Ada_Flag_2
;
2985 if Source_Index
/= 0 then
2987 Num
: constant String := Source_Index
'Img;
2989 Comp_Last
:= Comp_Last
+ 1;
2990 Comp_Args
(Comp_Last
) :=
2991 new String'("-gnateI" & Num (Num'First + 1 .. Num'Last));
2995 if Source_Index /= 0
2996 or else L /= Strip_Directory (L)
2997 or else Object_Directory_Path /= null
2999 -- Build -o argument
3001 Get_Name_String (L);
3003 for J in reverse 1 .. Name_Len loop
3004 if Name_Buffer (J) = '.' then
3005 Name_Len := J + Object_Suffix'Length - 1;
3006 Name_Buffer (J .. Name_Len) := Object_Suffix;
3011 Comp_Last := Comp_Last + 1;
3012 Comp_Args (Comp_Last) := Output_Flag;
3013 Comp_Last := Comp_Last + 1;
3015 -- If an object directory was specified, prepend the object file
3016 -- name with this object directory.
3018 if Object_Directory_Path /= null then
3019 Comp_Args (Comp_Last) :=
3020 new String'(Object_Directory_Path
.all &
3021 Name_Buffer
(1 .. Name_Len
));
3024 Comp_Args
(Comp_Last
) :=
3025 new String'(Name_Buffer (1 .. Name_Len));
3029 if Create_Mapping_File and then Mapping_File_Arg /= null then
3030 Comp_Last := Comp_Last + 1;
3031 Comp_Args (Comp_Last) := new String'(Mapping_File_Arg
.all);
3034 Get_Name_String
(S
);
3036 Comp_Last
:= Comp_Last
+ 1;
3037 Comp_Args
(Comp_Last
) := new String'(Name_Buffer (1 .. Name_Len));
3039 -- Change to object directory of the project file, if necessary
3041 if Project /= No_Project then
3042 Change_To_Object_Directory (Project);
3045 GNAT.OS_Lib.Normalize_Arguments (Comp_Args (Args'First .. Comp_Last));
3047 Comp_Last := Comp_Last + 1;
3048 Comp_Args (Comp_Last) := new String'("-gnatez");
3050 Display
(Gcc
.all, Comp_Args
(Args
'First .. Comp_Last
));
3052 if Gcc_Path
= null then
3053 Make_Failed
("error, unable to locate " & Gcc
.all);
3057 GNAT
.OS_Lib
.Non_Blocking_Spawn
3058 (Gcc_Path
.all, Comp_Args
(Args
'First .. Comp_Last
));
3061 -------------------------------
3062 -- Fill_Queue_From_ALI_Files --
3063 -------------------------------
3065 procedure Fill_Queue_From_ALI_Files
is
3066 ALI_P
: ALI_Project
;
3069 Sfile
: File_Name_Type
;
3070 Sid
: Prj
.Source_Id
;
3071 Uname
: Unit_Name_Type
;
3072 Unit_Name
: Name_Id
;
3073 Uid
: Prj
.Unit_Index
;
3076 while Good_ALI_Present
loop
3077 ALI_P
:= Get_Next_Good_ALI
;
3079 Source_Index
:= Unit_Index_Of
(ALIs
.Table
(ALI_P
.ALI
).Afile
);
3081 -- If we are processing the library file corresponding to the
3082 -- main source file check if this source can be a main unit.
3084 if ALIs
.Table
(ALI
).Sfile
= Main_Source
3085 and then Source_Index
= Main_Index
3087 Main_Unit
:= ALIs
.Table
(ALI
).Main_Program
/= None
;
3090 -- The following adds the standard library (s-stalib) to the list
3091 -- of files to be handled by gnatmake: this file and any files it
3092 -- depends on are always included in every bind, even if they are
3093 -- not in the explicit dependency list. Of course, it is not added
3094 -- if Suppress_Standard_Library is True.
3096 -- However, to avoid annoying output about s-stalib.ali being read
3097 -- only, when "-v" is used, we add the standard library only when
3100 if Need_To_Check_Standard_Library
then
3101 Check_Standard_Library
;
3104 -- Now insert in the Q the unmarked source files (i.e. those which
3105 -- have never been inserted in the Q and hence never considered).
3106 -- Only do that if Unique_Compile is False.
3108 if not Unique_Compile
then
3110 ALIs
.Table
(ALI
).First_Unit
.. ALIs
.Table
(ALI
).Last_Unit
3113 Units
.Table
(J
).First_With
.. Units
.Table
(J
).Last_With
3115 Sfile
:= Withs
.Table
(K
).Sfile
;
3116 Uname
:= Withs
.Table
(K
).Uname
;
3119 -- If project files are used, find the proper source to
3120 -- compile in case Sfile is the spec but there is a body.
3122 if Main_Project
/= No_Project
then
3123 Get_Name_String
(Uname
);
3124 Name_Len
:= Name_Len
- 2;
3125 Unit_Name
:= Name_Find
;
3127 Units_Htable
.Get
(Project_Tree
.Units_HT
, Unit_Name
);
3129 if Uid
/= Prj
.No_Unit_Index
then
3130 if Uid
.File_Names
(Impl
) /= null
3131 and then not Uid
.File_Names
(Impl
).Locally_Removed
3133 Sfile
:= Uid
.File_Names
(Impl
).File
;
3134 Source_Index
:= Uid
.File_Names
(Impl
).Index
;
3135 Sid
:= Uid
.File_Names
(Impl
);
3137 elsif Uid
.File_Names
(Spec
) /= null
3138 and then not Uid
.File_Names
(Spec
).Locally_Removed
3140 Sfile
:= Uid
.File_Names
(Spec
).File
;
3141 Source_Index
:= Uid
.File_Names
(Spec
).Index
;
3142 Sid
:= Uid
.File_Names
(Spec
);
3147 Dependencies
.Append
((ALIs
.Table
(ALI
).Sfile
, Sfile
));
3149 if Is_In_Obsoleted
(Sfile
) then
3150 Executable_Obsolete
:= True;
3153 if Sfile
= No_File
then
3154 Debug_Msg
("Skipping generic:", Withs
.Table
(K
).Uname
);
3157 Source_Index
:= Unit_Index_Of
(Withs
.Table
(K
).Afile
);
3159 if not (Check_Readonly_Files
or Must_Compile
)
3160 and then Is_Internal_File_Name
(Sfile
, False)
3162 Debug_Msg
("Skipping internal file:", Sfile
);
3166 ((Format
=> Format_Gnatmake
,
3168 Project
=> ALI_P
.Project
,
3169 Unit
=> Withs
.Table
(K
).Uname
,
3170 Index
=> Source_Index
,
3178 end Fill_Queue_From_ALI_Files
;
3180 ----------------------
3181 -- Get_Mapping_File --
3182 ----------------------
3184 procedure Get_Mapping_File
(Project
: Project_Id
) is
3185 Data
: Project_Compilation_Access
;
3188 Data
:= Project_Compilation_Htable
.Get
(Project_Compilation
, Project
);
3190 -- If there is a mapping file ready to be reused, reuse it
3192 if Data
.Last_Free_Indexes
> 0 then
3193 Mfile
:= Data
.Free_Mapping_File_Indexes
(Data
.Last_Free_Indexes
);
3194 Data
.Last_Free_Indexes
:= Data
.Last_Free_Indexes
- 1;
3196 -- Otherwise, create and initialize a new one
3200 (Project
=> Project
, Data
=> Data
.all, File_Index
=> Mfile
);
3203 -- Put the name in the mapping file argument for the invocation
3206 Free
(Mapping_File_Arg
);
3208 new String'("-gnatem=" &
3209 Get_Name_String (Data.Mapping_File_Names (Mfile)));
3210 end Get_Mapping_File;
3212 -----------------------
3213 -- Get_Next_Good_ALI --
3214 -----------------------
3216 function Get_Next_Good_ALI return ALI_Project is
3220 pragma Assert (Good_ALI_Present);
3221 ALIP := Good_ALI.Table (Good_ALI.Last);
3222 Good_ALI.Decrement_Last;
3224 end Get_Next_Good_ALI;
3226 ----------------------
3227 -- Good_ALI_Present --
3228 ----------------------
3230 function Good_ALI_Present return Boolean is
3232 return Good_ALI.First <= Good_ALI.Last;
3233 end Good_ALI_Present;
3235 --------------------------------
3236 -- Must_Exit_Because_Of_Error --
3237 --------------------------------
3239 function Must_Exit_Because_Of_Error return Boolean is
3240 Data : Compilation_Data;
3244 if Bad_Compilation_Count > 0 and then not Keep_Going then
3245 while Outstanding_Compiles > 0 loop
3246 Await_Compile (Data, Success);
3249 Record_Failure (Data.Full_Source_File, Data.Source_Unit);
3257 end Must_Exit_Because_Of_Error;
3259 --------------------
3260 -- Record_Failure --
3261 --------------------
3263 procedure Record_Failure
3264 (File : File_Name_Type;
3265 Unit : Unit_Name_Type;
3266 Found : Boolean := True)
3269 Bad_Compilation.Increment_Last;
3270 Bad_Compilation.Table (Bad_Compilation.Last) := (File, Unit, Found);
3273 ---------------------
3274 -- Record_Good_ALI --
3275 ---------------------
3277 procedure Record_Good_ALI (A : ALI_Id; Project : Project_Id) is
3279 Good_ALI.Increment_Last;
3280 Good_ALI.Table (Good_ALI.Last) := (A, Project);
3281 end Record_Good_ALI;
3283 -------------------------------
3284 -- Start_Compile_If_Possible --
3285 -------------------------------
3287 function Start_Compile_If_Possible
3288 (Args : Argument_List) return Boolean
3290 In_Lib_Dir : Boolean;
3291 Need_To_Compile : Boolean;
3292 Pid : Process_Id := Invalid_Pid;
3293 Process_Created : Boolean;
3295 Source : Queue.Source_Info;
3296 Full_Source_File : File_Name_Type := No_File;
3297 Source_File_Attr : aliased File_Attributes;
3298 -- The full name of the source file and its attributes (size, ...)
3300 Lib_File : File_Name_Type;
3301 Full_Lib_File : File_Name_Type := No_File;
3302 Lib_File_Attr : aliased File_Attributes;
3303 Read_Only : Boolean := False;
3305 -- The ALI file and its attributes (size, stamp, ...)
3307 Obj_File : File_Name_Type;
3308 Obj_Stamp : Time_Stamp_Type;
3314 if not Queue.Is_Virtually_Empty and then
3315 Outstanding_Compiles < Max_Process
3317 Queue.Extract (Found, Source);
3319 -- If it is a source in a project, first look for the ALI file
3320 -- in the object directory. When the project is extending another
3321 -- the ALI file may not be found, but the source does not
3322 -- necessarily need to be compiled, as it may already be up to
3323 -- date in the project being extended. In this case, look for an
3324 -- ALI file in all the object directories, as is done when
3325 -- gnatmake is not invoked with a project file.
3327 if Source.Sid /= No_Source then
3328 Initialize_Source_Record (Source.Sid);
3330 File_Name_Type (Source.Sid.Path.Display_Name);
3331 Lib_File := Source.Sid.Dep_Name;
3332 Full_Lib_File := File_Name_Type (Source.Sid.Dep_Path);
3333 Lib_File_Attr := Unknown_Attributes;
3335 if Full_Lib_File /= No_File then
3337 FLF : constant String :=
3338 Get_Name_String (Full_Lib_File) & ASCII.NUL;
3340 if not Is_Regular_File
3341 (FLF'Address, Lib_File_Attr'Access)
3343 Full_Lib_File := No_File;
3349 if Full_Lib_File = No_File then
3350 Osint.Full_Source_Name
3352 Full_File => Full_Source_File,
3353 Attr => Source_File_Attr'Access);
3355 Lib_File := Osint.Lib_File_Name (Source.File, Source.Index);
3357 Osint.Full_Lib_File_Name
3359 Lib_File => Full_Lib_File,
3360 Attr => Lib_File_Attr);
3363 -- If source has already been compiled, executable is obsolete
3365 if Is_In_Obsoleted (Source.File) then
3366 Executable_Obsolete := True;
3369 In_Lib_Dir := Full_Lib_File /= No_File
3370 and then In_Ada_Lib_Dir (Full_Lib_File);
3372 -- Since the following requires a system call, we precompute it
3375 if not In_Lib_Dir then
3376 if Full_Lib_File /= No_File
3377 and then not (Check_Readonly_Files or else Must_Compile)
3379 Get_Name_String (Full_Lib_File);
3380 Name_Buffer (Name_Len + 1) := ASCII.NUL;
3381 Read_Only := not Is_Writable_File
3382 (Name_Buffer'Address, Lib_File_Attr'Access);
3388 -- If the library file is an Ada library skip it
3393 "is in an Ada library",
3395 Minimum_Verbosity => Opt.High);
3397 -- If the library file is a read-only library skip it, but only
3398 -- if, when using project files, this library file is in the
3399 -- right object directory (a read-only ALI file in the object
3400 -- directory of a project being extended must not be skipped).
3403 and then Is_In_Object_Directory (Source.File, Full_Lib_File)
3407 "is a read-only library",
3409 Minimum_Verbosity => Opt.High);
3411 -- The source file that we are checking cannot be located
3413 elsif Full_Source_File = No_File then
3414 Record_Failure (Source.File, Source.Unit, False);
3416 -- Source and library files can be located but are internal
3419 elsif not (Check_Readonly_Files or else Must_Compile)
3420 and then Full_Lib_File /= No_File
3421 and then Is_Internal_File_Name (Source.File, False)
3423 if Force_Compilations then
3425 ("not allowed to compile """ &
3426 Get_Name_String (Source.File) &
3427 """; use -a switch, or use the compiler directly with "
3428 & "the ""-gnatg"" switch");
3433 "is an internal library",
3435 Minimum_Verbosity => Opt.High);
3437 -- The source file that we are checking can be located
3441 (Source.File, Source.File = Main_Source, Args);
3443 -- Do nothing if project of source is externally built
3445 if Arguments_Project = No_Project
3446 or else not Arguments_Project.Externally_Built
3447 or else Must_Compile
3449 -- Don't waste any time if we have to recompile anyway
3451 Obj_Stamp := Empty_Time_Stamp;
3452 Need_To_Compile := Force_Compilations;
3454 if not Force_Compilations then
3455 Check (Source_File => Source.File,
3456 Is_Main_Source => Source.File = Main_Source,
3458 Lib_File => Lib_File,
3459 Full_Lib_File => Full_Lib_File,
3460 Lib_File_Attr => Lib_File_Attr'Access,
3461 Read_Only => Read_Only,
3464 O_Stamp => Obj_Stamp);
3465 Need_To_Compile := (ALI = No_ALI_Id);
3468 if not Need_To_Compile then
3470 -- The ALI file is up-to-date; record its Id
3472 Record_Good_ALI (ALI, Arguments_Project);
3474 -- Record the time stamp of the most recent object
3475 -- file as long as no (re)compilations are needed.
3477 if First_Compiled_File = No_File
3478 and then (Most_Recent_Obj_File = No_File
3479 or else Obj_Stamp > Most_Recent_Obj_Stamp)
3481 Most_Recent_Obj_File := Obj_File;
3482 Most_Recent_Obj_Stamp := Obj_Stamp;
3486 -- Check that switch -x has been used if a source outside
3487 -- of project files need to be compiled.
3489 if Main_Project /= No_Project
3490 and then Arguments_Project = No_Project
3491 and then not External_Unit_Compilation_Allowed
3493 Make_Failed ("external source ("
3494 & Get_Name_String (Source.File)
3495 & ") is not part of any project;"
3496 & " cannot be compiled without"
3497 & " gnatmake switch -x");
3500 -- Is this the first file we have to compile?
3502 if First_Compiled_File = No_File then
3503 First_Compiled_File := Full_Source_File;
3504 Most_Recent_Obj_File := No_File;
3506 if Do_Not_Execute then
3508 -- Exit the main loop
3514 -- Compute where the ALI file must be generated in
3515 -- In_Place_Mode (this does not require to know the
3516 -- location of the object directory).
3518 if In_Place_Mode then
3519 if Full_Lib_File = No_File then
3521 -- If the library file was not found, then save
3522 -- the library file near the source file.
3526 (Full_Source_File, Source.Index);
3527 Full_Lib_File := Lib_File;
3530 -- If the library file was found, then save the
3531 -- library file in the same place.
3533 Lib_File := Full_Lib_File;
3537 -- Start the compilation and record it. We can do this
3538 -- because there is at least one free process. This might
3539 -- change the current directory.
3541 Collect_Arguments_And_Compile
3542 (Full_Source_File => Full_Source_File,
3543 Lib_File => Lib_File,
3544 Source_Index => Source.Index,
3546 Process_Created => Process_Created);
3548 -- Compute where the ALI file will be generated (for
3549 -- cases that might require to know the current
3550 -- directory). The current directory might be changed
3551 -- when compiling other files so we cannot rely on it
3552 -- being the same to find the resulting ALI file.
3554 if not In_Place_Mode then
3556 -- Compute the expected location of the ALI file. This
3557 -- can be from several places:
3558 -- -i => in place mode. In such a case,
3559 -- Full_Lib_File has already been set above
3560 -- -D => if specified
3561 -- or defaults in current dir
3562 -- We could simply use a call similar to
3563 -- Osint.Full_Lib_File_Name (Lib_File)
3564 -- but that involves system calls and is thus slower
3566 if Object_Directory_Path /= null then
3568 Add_Str_To_Name_Buffer (Object_Directory_Path.all);
3569 Add_Str_To_Name_Buffer (Get_Name_String (Lib_File));
3570 Full_Lib_File := Name_Find;
3573 if Project_Of_Current_Object_Directory /=
3577 (Project_Of_Current_Object_Directory
3578 .Object_Directory.Display_Name);
3579 Add_Str_To_Name_Buffer
3580 (Get_Name_String (Lib_File));
3581 Full_Lib_File := Name_Find;
3584 Full_Lib_File := Lib_File;
3590 Lib_File_Attr := Unknown_Attributes;
3592 -- Make sure we could successfully start the compilation
3594 if Process_Created then
3595 if Pid = Invalid_Pid then
3596 Record_Failure (Full_Source_File, Source.Unit);
3600 Sfile => Full_Source_File,
3602 Uname => Source.Unit,
3604 Full_Lib_File => Full_Lib_File,
3605 Lib_File_Attr => Lib_File_Attr);
3613 end Start_Compile_If_Possible;
3615 -----------------------------
3616 -- Wait_For_Available_Slot --
3617 -----------------------------
3619 procedure Wait_For_Available_Slot is
3620 Compilation_OK : Boolean;
3621 Text : Text_Buffer_Ptr;
3623 Data : Compilation_Data;
3626 if Outstanding_Compiles = Max_Process
3627 or else (Queue.Is_Virtually_Empty
3628 and then not Good_ALI_Present
3629 and then Outstanding_Compiles > 0)
3631 Await_Compile (Data, Compilation_OK);
3633 if not Compilation_OK then
3634 Record_Failure (Data.Full_Source_File, Data.Source_Unit);
3637 if Compilation_OK or else Keep_Going then
3639 -- Re-read the updated library file
3642 Saved_Object_Consistency : constant Boolean :=
3643 Check_Object_Consistency;
3646 -- If compilation was not OK, or if output is not an object
3647 -- file and we don't do the bind step, don't check for
3648 -- object consistency.
3650 Check_Object_Consistency :=
3651 Check_Object_Consistency
3653 and (Output_Is_Object or Do_Bind_Step);
3656 Read_Library_Info_From_Full
3657 (Data.Full_Lib_File, Data.Lib_File_Attr'Access);
3659 -- Restore Check_Object_Consistency to its initial value
3661 Check_Object_Consistency := Saved_Object_Consistency;
3664 -- If an ALI file was generated by this compilation, scan the
3665 -- ALI file and record it.
3667 -- If the scan fails, a previous ali file is inconsistent with
3668 -- the unit just compiled.
3670 if Text /= null then
3673 (Data.Lib_File, Text, Ignore_ED => False, Err => True);
3675 if ALI = No_ALI_Id then
3677 -- Record a failure only if not already done
3679 if Compilation_OK then
3682 "incompatible ALI file, please recompile");
3684 (Data.Full_Source_File, Data.Source_Unit);
3688 Record_Good_ALI (ALI, Data.Project);
3693 -- If we could not read the ALI file that was just generated
3694 -- then there could be a problem reading either the ALI or the
3695 -- corresponding object file (if Check_Object_Consistency is
3696 -- set Read_Library_Info checks that the time stamp of the
3697 -- object file is more recent than that of the ALI). However,
3698 -- we record a failure only if not already done.
3701 if Compilation_OK and not Syntax_Only then
3704 "WARNING: ALI or object file not found after compile");
3706 if not Is_Regular_File
3707 (Get_Name_String (Name_Id (Data.Full_Lib_File)))
3709 Inform (Data.Full_Lib_File, "not found");
3712 Record_Failure (Data.Full_Source_File, Data.Source_Unit);
3717 end Wait_For_Available_Slot;
3719 -- Start of processing for Compile_Sources
3722 pragma Assert (Args'First = 1);
3724 Outstanding_Compiles := 0;
3725 Running_Compile := new Comp_Data_Arr (1 .. Max_Process);
3727 -- Package and Queue initializations
3731 if Initialize_ALI_Data then
3733 Initialize_ALI_Source;
3736 -- The following two flags affect the behavior of ALI.Set_Source_Table.
3737 -- We set Check_Source_Files to True to ensure that source file time
3738 -- stamps are checked, and we set All_Sources to False to avoid checking
3739 -- the presence of the source files listed in the source dependency
3740 -- section of an ali file (which would be a mistake since the ali file
3741 -- may be obsolete).
3743 Check_Source_Files := True;
3744 All_Sources := False;
3747 ((Format => Format_Gnatmake,
3748 File => Main_Source,
3749 Project => Main_Project,
3750 Unit => No_Unit_Name,
3751 Index => Main_Index,
3754 First_Compiled_File := No_File;
3755 Most_Recent_Obj_File := No_File;
3756 Most_Recent_Obj_Stamp := Empty_Time_Stamp;
3759 -- Keep looping until there is no more work to do (the Q is empty)
3760 -- and all the outstanding compilations have terminated.
3763 while not Queue.Is_Empty or else Outstanding_Compiles > 0 loop
3764 exit Make_Loop when Must_Exit_Because_Of_Error;
3765 exit Make_Loop when Start_Compile_If_Possible (Args);
3767 Wait_For_Available_Slot;
3769 -- ??? Should be done as soon as we add a Good_ALI, wouldn't it avoid
3770 -- the need for a list of good ALI?
3772 Fill_Queue_From_ALI_Files;
3774 if Display_Compilation_Progress then
3775 Write_Str ("completed ");
3776 Write_Int (Int (Queue.Processed));
3777 Write_Str (" out of ");
3778 Write_Int (Int (Queue.Size));
3780 Write_Int (Int ((Queue.Processed * 100) / Queue.Size));
3781 Write_Str ("%)...");
3786 Compilation_Failures := Bad_Compilation_Count;
3788 -- Compilation is finished
3790 -- Delete any temporary configuration pragma file
3792 if not Keep_Temporary_Files then
3793 Delete_Temp_Config_Files (Project_Tree);
3795 end Compile_Sources;
3797 ----------------------------------
3798 -- Configuration_Pragmas_Switch --
3799 ----------------------------------
3801 function Configuration_Pragmas_Switch
3802 (For_Project : Project_Id) return Argument_List
3804 The_Packages : Package_Id;
3805 Gnatmake : Package_Id;
3806 Compiler : Package_Id;
3808 Global_Attribute : Variable_Value := Nil_Variable_Value;
3809 Local_Attribute : Variable_Value := Nil_Variable_Value;
3811 Global_Attribute_Present : Boolean := False;
3812 Local_Attribute_Present : Boolean := False;
3814 Result : Argument_List (1 .. 3);
3815 Last : Natural := 0;
3818 Prj.Env.Create_Config_Pragmas_File
3819 (For_Project, Project_Tree);
3821 if For_Project.Config_File_Name /= No_Path then
3822 Temporary_Config_File := For_Project.Config_File_Temp;
3826 ("-gnatec=" & Get_Name_String
(For_Project
.Config_File_Name
));
3829 Temporary_Config_File
:= False;
3832 -- Check for attribute Builder'Global_Configuration_Pragmas
3834 The_Packages
:= Main_Project
.Decl
.Packages
;
3837 (Name
=> Name_Builder
,
3838 In_Packages
=> The_Packages
,
3839 Shared
=> Project_Tree
.Shared
);
3841 if Gnatmake
/= No_Package
then
3842 Global_Attribute
:= Prj
.Util
.Value_Of
3843 (Variable_Name
=> Name_Global_Configuration_Pragmas
,
3844 In_Variables
=> Project_Tree
.Shared
.Packages
.Table
3845 (Gnatmake
).Decl
.Attributes
,
3846 Shared
=> Project_Tree
.Shared
);
3847 Global_Attribute_Present
:=
3848 Global_Attribute
/= Nil_Variable_Value
3849 and then Get_Name_String
(Global_Attribute
.Value
) /= "";
3851 if Global_Attribute_Present
then
3853 Path
: constant String :=
3855 (Path_Name_Type
(Global_Attribute
.Value
),
3856 Global_Attribute
.Project
);
3858 if not Is_Regular_File
(Path
) then
3859 if Debug
.Debug_Flag_F
then
3861 ("cannot find configuration pragmas file "
3862 & File_Name
(Path
));
3865 ("cannot find configuration pragmas file " & Path
);
3870 Result
(Last
) := new String'("-gnatec=" & Path);
3875 -- Check for attribute Compiler'Local_Configuration_Pragmas
3877 The_Packages := For_Project.Decl.Packages;
3880 (Name => Name_Compiler,
3881 In_Packages => The_Packages,
3882 Shared => Project_Tree.Shared);
3884 if Compiler /= No_Package then
3885 Local_Attribute := Prj.Util.Value_Of
3886 (Variable_Name => Name_Local_Configuration_Pragmas,
3887 In_Variables => Project_Tree.Shared.Packages.Table
3888 (Compiler).Decl.Attributes,
3889 Shared => Project_Tree.Shared);
3890 Local_Attribute_Present :=
3891 Local_Attribute /= Nil_Variable_Value
3892 and then Get_Name_String (Local_Attribute.Value) /= "";
3894 if Local_Attribute_Present then
3896 Path : constant String :=
3898 (Path_Name_Type (Local_Attribute.Value),
3899 Local_Attribute.Project);
3901 if not Is_Regular_File (Path) then
3902 if Debug.Debug_Flag_F then
3904 ("cannot find configuration pragmas file "
3905 & File_Name (Path));
3909 ("cannot find configuration pragmas file " & Path);
3914 Result (Last) := new String'("-gnatec=" & Path
);
3919 return Result
(1 .. Last
);
3920 end Configuration_Pragmas_Switch
;
3926 procedure Debug_Msg
(S
: String; N
: Name_Id
) is
3928 if Debug
.Debug_Flag_W
then
3929 Write_Str
(" ... ");
3937 procedure Debug_Msg
(S
: String; N
: File_Name_Type
) is
3939 Debug_Msg
(S
, Name_Id
(N
));
3942 procedure Debug_Msg
(S
: String; N
: Unit_Name_Type
) is
3944 Debug_Msg
(S
, Name_Id
(N
));
3951 procedure Display
(Program
: String; Args
: Argument_List
) is
3953 pragma Assert
(Args
'First = 1);
3955 if Display_Executed_Programs
then
3956 Write_Str
(Program
);
3958 for J
in Args
'Range loop
3960 -- Never display -gnatea nor -gnatez
3962 if Args
(J
).all /= "-gnatea"
3964 Args
(J
).all /= "-gnatez"
3966 -- Do not display the mapping file argument automatically
3967 -- created when using a project file.
3969 if Main_Project
= No_Project
3970 or else Opt
.Keep_Temporary_Files
3971 or else Args
(J
)'Length < 8
3973 Args
(J
) (Args
(J
)'First .. Args
(J
)'First + 6) /= "-gnatem"
3975 -- When -dn is not specified, do not display the config
3976 -- pragmas switch (-gnatec) for the temporary file created
3977 -- by the project manager (always the first -gnatec switch).
3978 -- Reset Temporary_Config_File to False so that the eventual
3979 -- other -gnatec switches will be displayed.
3981 if not Opt
.Keep_Temporary_Files
3982 and then Temporary_Config_File
3983 and then Args
(J
)'Length > 7
3984 and then Args
(J
) (Args
(J
)'First .. Args
(J
)'First + 6) =
3987 Temporary_Config_File
:= False;
3989 -- Do not display the -F=mapping_file switch for gnatbind
3990 -- if -dn is not specified.
3992 elsif Opt
.Keep_Temporary_Files
3993 or else Args
(J
)'Length < 4
3995 Args
(J
) (Args
(J
)'First .. Args
(J
)'First + 2) /= "-F="
3999 -- If -df is used, only display file names, not path
4002 if Debug
.Debug_Flag_F
then
4004 Equal_Pos
: Natural;
4007 Equal_Pos
:= Args
(J
)'First - 1;
4008 for K
in Args
(J
)'Range loop
4009 if Args
(J
) (K
) = '=' then
4016 (Args
(J
) (Equal_Pos
+ 1 .. Args
(J
)'Last))
4019 (Args
(J
) (Args
(J
)'First .. Equal_Pos
));
4023 (Equal_Pos
+ 1 .. Args
(J
)'Last)));
4026 Write_Str
(Args
(J
).all);
4031 Write_Str
(Args
(J
).all);
4042 ----------------------
4043 -- Display_Commands --
4044 ----------------------
4046 procedure Display_Commands
(Display
: Boolean := True) is
4048 Display_Executed_Programs
:= Display
;
4049 end Display_Commands
;
4051 --------------------------
4052 -- Enter_Into_Obsoleted --
4053 --------------------------
4055 procedure Enter_Into_Obsoleted
(F
: File_Name_Type
) is
4056 Name
: constant String := Get_Name_String
(F
);
4058 F2
: File_Name_Type
;
4062 while First
> Name
'First
4063 and then not Is_Directory_Separator
(Name
(First
- 1))
4068 if First
/= Name
'First then
4070 Add_Str_To_Name_Buffer
(Name
(First
.. Name
'Last));
4077 Debug_Msg
("New entry in Obsoleted table:", F2
);
4078 Obsoleted
.Set
(F2
, True);
4079 end Enter_Into_Obsoleted
;
4085 procedure Linking_Phase
4086 (Non_Std_Executable
: Boolean := False;
4087 Executable
: File_Name_Type
:= No_File
;
4088 Main_ALI_File
: File_Name_Type
)
4090 Linker_Switches_Last
: constant Integer := Linker_Switches
.Last
;
4091 Path_Option
: constant String_Access
:=
4092 MLib
.Linker_Library_Path_Option
;
4093 Libraries_Present
: Boolean := False;
4097 Proj1
: Project_List
;
4100 if not Run_Path_Option
then
4101 Linker_Switches
.Increment_Last
;
4102 Linker_Switches
.Table
(Linker_Switches
.Last
) :=
4106 if Main_Project /= No_Project then
4107 Library_Paths.Set_Last (0);
4110 if MLib.Tgt.Support_For_Libraries /= Prj.None then
4112 -- Check for library projects
4114 Proj1 := Project_Tree.Projects;
4115 while Proj1 /= null loop
4116 if Proj1.Project /= Main_Project
4117 and then Proj1.Project.Library
4119 -- Add this project to table Library_Projs
4121 Libraries_Present := True;
4122 Depth := Proj1.Project.Depth;
4123 Library_Projs.Increment_Last;
4124 Current := Library_Projs.Last;
4126 -- Any project with a greater depth should be after this
4127 -- project in the list.
4129 while Current > 1 loop
4130 Proj2 := Library_Projs.Table (Current - 1);
4131 exit when Proj2.Depth <= Depth;
4132 Library_Projs.Table (Current) := Proj2;
4133 Current := Current - 1;
4136 Library_Projs.Table (Current) := Proj1.Project;
4138 -- If it is not a static library and path option is set, add
4139 -- it to the Library_Paths table.
4141 if Proj1.Project.Library_Kind /= Static
4142 and then Proj1.Project.Extended_By = No_Project
4143 and then Path_Option /= null
4145 Library_Paths.Increment_Last;
4146 Library_Paths.Table (Library_Paths.Last) :=
4149 (Proj1
.Project
.Library_Dir
.Display_Name
));
4153 Proj1
:= Proj1
.Next
;
4156 for Index
in 1 .. Library_Projs
.Last
loop
4157 if Library_Projs
.Table
(Index
).Extended_By
= No_Project
then
4158 if Library_Projs
.Table
(Index
).Library_Kind
= Static
then
4159 Linker_Switches
.Increment_Last
;
4160 Linker_Switches
.Table
(Linker_Switches
.Last
) :=
4163 (Library_Projs.Table
4164 (Index).Library_Dir.Display_Name) &
4167 (Library_Projs.Table (Index).Library_Name) &
4169 MLib.Tgt.Archive_Ext);
4172 -- Add the -L switch
4174 Linker_Switches.Increment_Last;
4175 Linker_Switches.Table (Linker_Switches.Last) :=
4177 Get_Name_String
(Library_Projs
.Table
(Index
).
4178 Library_Dir
.Display_Name
));
4180 -- Add the -l switch
4182 Linker_Switches
.Increment_Last
;
4183 Linker_Switches
.Table
(Linker_Switches
.Last
) :=
4186 (Library_Projs.Table (Index).Library_Name));
4192 if Libraries_Present then
4194 -- If Path_Option is not null, create the switch ("-Wl,-rpath,"
4195 -- or equivalent) with all the non-static library dirs plus the
4196 -- standard GNAT library dir. We do that only if Run_Path_Option
4197 -- is True (not disabled by -R switch).
4199 if Run_Path_Option and then Path_Option /= null then
4201 Option : String_Access;
4202 Length : Natural := Path_Option'Length;
4206 if MLib.Separate_Run_Path_Options then
4208 -- We are going to create one switch of the form
4209 -- "-Wl,-rpath,dir_N" for each directory to
4212 -- One switch for each library directory
4215 Library_Paths.First .. Library_Paths.Last
4217 Linker_Switches.Increment_Last;
4218 Linker_Switches.Table (Linker_Switches.Last) :=
4221 Library_Paths
.Table
(Index
).all);
4224 -- One switch for the standard GNAT library dir
4226 Linker_Switches
.Increment_Last
;
4227 Linker_Switches
.Table
(Linker_Switches
.Last
) :=
4228 new String'(Path_Option.all & MLib.Utl.Lib_Directory);
4231 -- We are going to create one switch of the form
4232 -- "-Wl,-rpath,dir_1:dir_2:dir_3"
4234 for Index in Library_Paths.First .. Library_Paths.Last
4236 -- Add the length of the library dir plus one for the
4237 -- directory separator.
4240 Length + Library_Paths.Table (Index)'Length + 1;
4243 -- Finally, add the length of the standard GNAT
4246 Length := Length + MLib.Utl.Lib_Directory'Length;
4247 Option := new String (1 .. Length);
4248 Option (1 .. Path_Option'Length) := Path_Option.all;
4249 Current := Path_Option'Length;
4251 -- Put each library dir followed by a dir
4254 for Index in Library_Paths.First .. Library_Paths.Last
4258 Current + Library_Paths.Table (Index)'Length) :=
4259 Library_Paths.Table (Index).all;
4261 Current + Library_Paths.Table (Index)'Length + 1;
4262 Option (Current) := Path_Separator;
4265 -- Finally put the standard GNAT library dir
4269 Current + MLib.Utl.Lib_Directory'Length) :=
4270 MLib.Utl.Lib_Directory;
4272 -- And add the switch to the linker switches
4274 Linker_Switches.Increment_Last;
4275 Linker_Switches.Table (Linker_Switches.Last) := Option;
4281 -- Put the object directories in ADA_OBJECTS_PATH
4283 Prj.Env.Set_Ada_Paths
4286 Including_Libraries => False,
4287 Include_Path => False);
4289 -- Check for attributes Linker'Linker_Options in projects other than
4293 Linker_Options : constant String_List :=
4294 Linker_Options_Switches
4296 Do_Fail => Make_Failed'Access,
4297 In_Tree => Project_Tree);
4299 for Option in Linker_Options'Range loop
4300 Linker_Switches.Increment_Last;
4301 Linker_Switches.Table (Linker_Switches.Last) :=
4302 Linker_Options (Option);
4307 if CodePeer_Mode then
4308 Linker_Switches.Increment_Last;
4309 Linker_Switches.Table (Linker_Switches.Last) :=
4310 new String'(CodePeer_Mode_String
);
4313 -- Add switch -M to gnatlink if builder switch --create-map-file
4314 -- has been specified.
4316 if Map_File
/= null then
4317 Linker_Switches
.Increment_Last
;
4318 Linker_Switches
.Table
(Linker_Switches
.Last
) :=
4319 new String'("-M" & Map_File.all);
4323 Args : Argument_List
4324 (Linker_Switches.First .. Linker_Switches.Last + 2);
4326 Last_Arg : Integer := Linker_Switches.First - 1;
4327 Skip : Boolean := False;
4330 -- Get all the linker switches
4332 for J in Linker_Switches.First .. Linker_Switches.Last loop
4336 elsif Non_Std_Executable
4337 and then Linker_Switches.Table (J).all = "-o"
4341 -- Here we capture and duplicate the linker argument. We
4342 -- need to do the duplication since the arguments will get
4343 -- normalized. Not doing so will result in calling normalized
4344 -- two times for the same set of arguments if gnatmake is
4345 -- passed multiple mains. This can result in the wrong
4346 -- argument being passed to the linker.
4349 Last_Arg := Last_Arg + 1;
4350 Args (Last_Arg) := new String'(Linker_Switches
.Table
(J
).all);
4354 -- If need be, add the -o switch
4356 if Non_Std_Executable
then
4357 Last_Arg
:= Last_Arg
+ 1;
4358 Args
(Last_Arg
) := new String'("-o");
4359 Last_Arg := Last_Arg + 1;
4360 Args (Last_Arg) := new String'(Get_Name_String
(Executable
));
4363 -- And invoke the linker
4366 Success
: Boolean := False;
4369 -- If gnatmake was invoked with --subdirs and no project file,
4370 -- put the executable in the subdirectory specified.
4372 if Prj
.Subdirs
/= null and then Main_Project
= No_Project
then
4373 Change_Dir
(Object_Directory_Path
.all);
4376 Link
(Main_ALI_File
,
4377 Link_With_Shared_Libgcc
.all &
4378 Args
(Args
'First .. Last_Arg
),
4382 Successful_Links
.Increment_Last
;
4383 Successful_Links
.Table
(Successful_Links
.Last
) := Main_ALI_File
;
4385 elsif Osint
.Number_Of_Files
= 1 or else not Keep_Going
then
4386 Make_Failed
("*** link failed.");
4390 Write_Line
("*** link failed");
4392 if Commands_To_Stdout
then
4393 Set_Standard_Output
;
4396 Failed_Links
.Increment_Last
;
4397 Failed_Links
.Table
(Failed_Links
.Last
) := Main_ALI_File
;
4402 Linker_Switches
.Set_Last
(Linker_Switches_Last
);
4409 procedure Binding_Phase
4410 (Stand_Alone_Libraries
: Boolean := False;
4411 Main_ALI_File
: File_Name_Type
)
4413 Args
: Argument_List
(Binder_Switches
.First
.. Binder_Switches
.Last
+ 2);
4414 -- The arguments for the invocation of gnatbind
4416 Last_Arg
: Natural := Binder_Switches
.Last
;
4417 -- Index of the last argument in Args
4419 Shared_Libs
: Boolean := False;
4420 -- Set to True when there are shared library project files or
4421 -- when gnatbind is invoked with -shared.
4423 Proj
: Project_List
;
4425 Mapping_Path
: Path_Name_Type
:= No_Path
;
4426 -- The path name of the mapping file
4429 -- Check if there are shared libraries, so that gnatbind is called with
4430 -- -shared. Check also if gnatbind is called with -shared, so that
4431 -- gnatlink is called with -shared-libgcc ensuring that the shared
4432 -- version of libgcc will be used.
4434 if Main_Project
/= No_Project
4435 and then MLib
.Tgt
.Support_For_Libraries
/= Prj
.None
4437 Proj
:= Project_Tree
.Projects
;
4438 while Proj
/= null loop
4439 if Proj
.Project
.Library
4440 and then Proj
.Project
.Library_Kind
/= Static
4442 Shared_Libs
:= True;
4443 Bind_Shared
:= Shared_Switch
'Access;
4451 -- Check now for switch -shared
4453 if not Shared_Libs
then
4454 for J
in Binder_Switches
.First
.. Last_Arg
loop
4455 if Binder_Switches
.Table
(J
).all = "-shared" then
4456 Shared_Libs
:= True;
4462 -- If shared libraries present, invoke gnatlink with
4466 Link_With_Shared_Libgcc
:= Shared_Libgcc_Switch
'Access;
4469 -- Get all the binder switches
4471 for J
in Binder_Switches
.First
.. Last_Arg
loop
4472 Args
(J
) := Binder_Switches
.Table
(J
);
4475 if Stand_Alone_Libraries
then
4476 Last_Arg
:= Last_Arg
+ 1;
4477 Args
(Last_Arg
) := Force_Elab_Flags_String
'Access;
4480 if CodePeer_Mode
then
4481 Last_Arg
:= Last_Arg
+ 1;
4482 Args
(Last_Arg
) := CodePeer_Mode_String
'Access;
4485 if Main_Project
/= No_Project
then
4487 -- Put all the source directories in ADA_INCLUDE_PATH, and all the
4488 -- object directories in ADA_OBJECTS_PATH.
4490 Prj
.Env
.Set_Ada_Paths
4491 (Project
=> Main_Project
,
4492 In_Tree
=> Project_Tree
,
4493 Including_Libraries
=> True,
4494 Include_Path
=> Use_Include_Path_File
);
4496 -- If switch -C was specified, create a binder mapping file
4498 if Create_Mapping_File
then
4499 Mapping_Path
:= Create_Binder_Mapping_File
(Project_Tree
);
4501 if Mapping_Path
/= No_Path
then
4502 Last_Arg
:= Last_Arg
+ 1;
4504 new String'("-F=" & Get_Name_String (Mapping_Path));
4509 -- If gnatmake was invoked with --subdirs and no project file, put the
4510 -- binder generated files in the subdirectory specified.
4512 if Main_Project = No_Project and then Prj.Subdirs /= null then
4513 Change_Dir (Object_Directory_Path.all);
4517 Bind (Main_ALI_File,
4518 Bind_Shared.all & Args (Args'First .. Last_Arg));
4523 -- Delete the temporary mapping file if one was created
4525 if Mapping_Path /= No_Path then
4526 Delete_Temporary_File (Project_Tree.Shared, Mapping_Path);
4529 -- And reraise the exception
4534 -- If -dn was not specified, delete the temporary mapping file
4535 -- if one was created.
4537 if Mapping_Path /= No_Path then
4538 Delete_Temporary_File (Project_Tree.Shared, Mapping_Path);
4546 procedure Library_Phase
4547 (Stand_Alone_Libraries : in out Boolean;
4548 Library_Rebuilt : in out Boolean)
4552 Proj1 : Project_List;
4554 procedure Add_To_Library_Projs (Proj : Project_Id);
4555 -- Add project Project to table Library_Projs in decreasing depth order
4557 --------------------------
4558 -- Add_To_Library_Projs --
4559 --------------------------
4561 procedure Add_To_Library_Projs (Proj : Project_Id) is
4565 Library_Projs.Increment_Last;
4566 Depth := Proj.Depth;
4568 -- Put the projects in decreasing depth order, so that
4569 -- if libA depends on libB, libB is first in order.
4571 Current := Library_Projs.Last;
4572 while Current > 1 loop
4573 Prj := Library_Projs.Table (Current - 1);
4574 exit when Prj.Depth >= Depth;
4575 Library_Projs.Table (Current) := Prj;
4576 Current := Current - 1;
4579 Library_Projs.Table (Current) := Proj;
4580 end Add_To_Library_Projs;
4582 -- Start of processing for Library_Phase
4587 -- Put in Library_Projs table all library project file ids when the
4588 -- library need to be rebuilt.
4590 Proj1 := Project_Tree.Projects;
4591 while Proj1 /= null loop
4592 if Proj1.Project.Extended_By = No_Project then
4593 if Proj1.Project.Standalone_Library /= No then
4594 Stand_Alone_Libraries := True;
4597 if Proj1.Project.Library then
4598 MLib.Prj.Check_Library
4599 (Proj1.Project, Project_Tree);
4602 if Proj1.Project.Need_To_Build_Lib then
4603 Add_To_Library_Projs (Proj1.Project);
4607 Proj1 := Proj1.Next;
4610 -- Check if importing libraries should be regenerated
4611 -- because at least an imported library will be
4612 -- regenerated or is more recent.
4614 Proj1 := Project_Tree.Projects;
4615 while Proj1 /= null loop
4616 if Proj1.Project.Library
4617 and then Proj1.Project.Extended_By = No_Project
4618 and then Proj1.Project.Library_Kind /= Static
4619 and then not Proj1.Project.Need_To_Build_Lib
4620 and then not Proj1.Project.Externally_Built
4623 List : Project_List;
4625 Rebuild : Boolean := False;
4627 Lib_Timestamp1 : constant Time_Stamp_Type :=
4628 Proj1.Project.Library_TS;
4631 List := Proj1.Project.All_Imported_Projects;
4632 while List /= null loop
4633 Proj2 := List.Project;
4635 if Proj2.Library then
4636 if Proj2.Need_To_Build_Lib
4638 (Lib_Timestamp1 < Proj2.Library_TS)
4649 Proj1.Project.Need_To_Build_Lib := True;
4650 Add_To_Library_Projs (Proj1.Project);
4655 Proj1 := Proj1.Next;
4658 -- Reset the flags Need_To_Build_Lib for the next main, to avoid
4659 -- rebuilding libraries uselessly.
4661 Proj1 := Project_Tree.Projects;
4662 while Proj1 /= null loop
4663 Proj1.Project.Need_To_Build_Lib := False;
4664 Proj1 := Proj1.Next;
4667 -- Build the libraries, if any need to be built
4669 for J in 1 .. Library_Projs.Last loop
4670 Library_Rebuilt := True;
4672 -- If a library is rebuilt, then executables are obsolete
4674 Executable_Obsolete := True;
4676 MLib.Prj.Build_Library
4677 (For_Project => Library_Projs.Table (J),
4678 In_Tree => Project_Tree,
4679 Gnatbind => Gnatbind.all,
4680 Gnatbind_Path => Gnatbind_Path,
4682 Gcc_Path => Gcc_Path);
4686 -----------------------
4687 -- Compilation_Phase --
4688 -----------------------
4690 procedure Compilation_Phase
4691 (Main_Source_File : File_Name_Type;
4692 Current_Main_Index : Int := 0;
4693 Total_Compilation_Failures : in out Natural;
4694 Stand_Alone_Libraries : in out Boolean;
4695 Executable : File_Name_Type := No_File;
4696 Is_Last_Main : Boolean;
4697 Stop_Compile : out Boolean)
4699 Args : Argument_List (1 .. Gcc_Switches.Last);
4700 First_Compiled_File : File_Name_Type;
4701 Youngest_Obj_File : File_Name_Type;
4702 Youngest_Obj_Stamp : Time_Stamp_Type;
4704 Is_Main_Unit : Boolean;
4705 -- Set True by Compile_Sources if Main_Source_File can be a main unit
4707 Compilation_Failures : Natural;
4709 Executable_Stamp : Time_Stamp_Type;
4711 Library_Rebuilt : Boolean := False;
4714 Stop_Compile := False;
4716 for J in 1 .. Gcc_Switches.Last loop
4717 Args (J) := Gcc_Switches.Table (J);
4720 -- Now we invoke Compile_Sources for the current main
4723 (Main_Source => Main_Source_File,
4725 First_Compiled_File => First_Compiled_File,
4726 Most_Recent_Obj_File => Youngest_Obj_File,
4727 Most_Recent_Obj_Stamp => Youngest_Obj_Stamp,
4728 Main_Unit => Is_Main_Unit,
4729 Main_Index => Current_Main_Index,
4730 Compilation_Failures => Compilation_Failures,
4731 Check_Readonly_Files => Check_Readonly_Files,
4732 Do_Not_Execute => Do_Not_Execute,
4733 Force_Compilations => Force_Compilations,
4734 In_Place_Mode => In_Place_Mode,
4735 Keep_Going => Keep_Going,
4736 Initialize_ALI_Data => True,
4737 Max_Process => Saved_Maximum_Processes);
4739 if Verbose_Mode then
4740 Write_Str ("End of compilation");
4744 Total_Compilation_Failures :=
4745 Total_Compilation_Failures + Compilation_Failures;
4747 if Total_Compilation_Failures /= 0 then
4748 Stop_Compile := True;
4752 -- Regenerate libraries, if there are any and if object files have been
4753 -- regenerated. Note that we skip this in CodePeer mode because we don't
4754 -- need libraries in this case, and more importantly, the object files
4755 -- may not be present.
4757 if Main_Project /= No_Project
4758 and then not CodePeer_Mode
4759 and then MLib.Tgt.Support_For_Libraries /= Prj.None
4760 and then (Do_Bind_Step
4761 or Unique_Compile_All_Projects
4762 or not Compile_Only)
4763 and then (Do_Link_Step or Is_Last_Main)
4766 (Stand_Alone_Libraries => Stand_Alone_Libraries,
4767 Library_Rebuilt => Library_Rebuilt);
4770 if List_Dependencies then
4771 if First_Compiled_File /= No_File then
4773 (First_Compiled_File,
4774 "must be recompiled. Can't generate dependence list.");
4779 elsif First_Compiled_File = No_File
4780 and then not Do_Bind_Step
4781 and then not Quiet_Output
4782 and then not Library_Rebuilt
4783 and then Osint.Number_Of_Files = 1
4785 Inform (Msg => "objects up to date.");
4786 Stop_Compile := True;
4789 elsif Do_Not_Execute and then First_Compiled_File /= No_File then
4790 Write_Name (First_Compiled_File);
4794 -- Stop after compile step if any of:
4796 -- 1) -n (Do_Not_Execute) specified
4798 -- 2) -M (List_Dependencies) specified (also sets
4799 -- Do_Not_Execute above, so this is probably superfluous).
4801 -- 3) -c (Compile_Only) specified, but not -b (Bind_Only)
4803 -- 4) Made unit cannot be a main unit
4806 or List_Dependencies
4808 or not Is_Main_Unit)
4809 and not No_Main_Subprogram
4810 and not Build_Bind_And_Link_Full_Project)
4813 Stop_Compile := True;
4817 -- If the objects were up-to-date check if the executable file is also
4818 -- up-to-date. For now always bind and link in CodePeer mode where there
4819 -- is no executable.
4821 if not CodePeer_Mode
4822 and then First_Compiled_File = No_File
4824 Executable_Stamp := File_Stamp (Executable);
4826 if not Executable_Obsolete then
4827 Executable_Obsolete := Youngest_Obj_Stamp > Executable_Stamp;
4830 if not Executable_Obsolete then
4831 for Index in reverse 1 .. Dependencies.Last loop
4832 if Is_In_Obsoleted (Dependencies.Table (Index).Depends_On) then
4833 Enter_Into_Obsoleted (Dependencies.Table (Index).This);
4837 Executable_Obsolete := Is_In_Obsoleted (Main_Source_File);
4841 if not Executable_Obsolete then
4843 -- If no Ada object files obsolete the executable, check
4844 -- for younger or missing linker files.
4846 Check_Linker_Options
4849 Youngest_Obj_Stamp);
4851 Executable_Obsolete := Youngest_Obj_File /= No_File;
4854 -- Check if any library file is more recent than the
4855 -- executable: there may be an externally built library
4856 -- file that has been modified.
4858 if not Executable_Obsolete and then Main_Project /= No_Project then
4860 Proj1 : Project_List;
4863 Proj1 := Project_Tree.Projects;
4864 while Proj1 /= null loop
4865 if Proj1.Project.Library
4866 and then Proj1.Project.Library_TS > Executable_Stamp
4868 Executable_Obsolete := True;
4869 Youngest_Obj_Stamp := Proj1.Project.Library_TS;
4871 Add_Str_To_Name_Buffer ("library ");
4872 Add_Str_To_Name_Buffer
4873 (Get_Name_String (Proj1.Project.Library_Name));
4874 Youngest_Obj_File := Name_Find;
4878 Proj1 := Proj1.Next;
4883 -- Return if the executable is up to date and otherwise
4884 -- motivate the relink/rebind.
4886 if not Executable_Obsolete then
4887 if not Quiet_Output then
4888 Inform (Executable, "up to date.");
4891 Stop_Compile := True;
4895 if Executable_Stamp (1) = ' ' then
4896 if not No_Main_Subprogram then
4897 Verbose_Msg (Executable, "missing.", Prefix => " ");
4900 elsif Youngest_Obj_Stamp (1) = ' ' then
4902 (Youngest_Obj_File, "missing.", Prefix => " ");
4904 elsif Youngest_Obj_Stamp > Executable_Stamp then
4907 "(" & String (Youngest_Obj_Stamp) & ") newer than",
4909 "(" & String (Executable_Stamp) & ")");
4913 (Executable, "needs to be rebuilt", Prefix => " ");
4917 end Compilation_Phase;
4919 ----------------------------------------
4920 -- Resolve_Relative_Names_In_Switches --
4921 ----------------------------------------
4923 procedure Resolve_Relative_Names_In_Switches (Current_Work_Dir : String) is
4925 -- If a relative path output file has been specified, we add the
4928 for J in reverse 1 .. Saved_Linker_Switches.Last - 1 loop
4929 if Saved_Linker_Switches.Table (J).all = Output_Flag.all then
4931 Exec_File_Name : constant String :=
4932 Saved_Linker_Switches.Table (J + 1).all;
4935 if not Is_Absolute_Path (Exec_File_Name) then
4936 Get_Name_String (Main_Project.Exec_Directory.Display_Name);
4937 Add_Str_To_Name_Buffer (Exec_File_Name);
4938 Saved_Linker_Switches.Table (J + 1) :=
4939 new String'(Name_Buffer
(1 .. Name_Len
));
4947 -- If we are using a project file, for relative paths we add the
4948 -- current working directory for any relative path on the command
4949 -- line and the project directory, for any relative path in the
4953 Dir_Path
: constant String :=
4954 Get_Name_String
(Main_Project
.Directory
.Display_Name
);
4956 for J
in 1 .. Binder_Switches
.Last
loop
4957 Ensure_Absolute_Path
4958 (Binder_Switches
.Table
(J
),
4959 Do_Fail
=> Make_Failed
'Access,
4960 Parent
=> Dir_Path
, For_Gnatbind
=> True);
4963 for J
in 1 .. Saved_Binder_Switches
.Last
loop
4964 Ensure_Absolute_Path
4965 (Saved_Binder_Switches
.Table
(J
),
4966 Do_Fail
=> Make_Failed
'Access,
4967 Parent
=> Current_Work_Dir
,
4968 For_Gnatbind
=> True);
4971 for J
in 1 .. Linker_Switches
.Last
loop
4972 Ensure_Absolute_Path
4973 (Linker_Switches
.Table
(J
),
4975 Do_Fail
=> Make_Failed
'Access);
4978 for J
in 1 .. Saved_Linker_Switches
.Last
loop
4979 Ensure_Absolute_Path
4980 (Saved_Linker_Switches
.Table
(J
),
4981 Do_Fail
=> Make_Failed
'Access,
4982 Parent
=> Current_Work_Dir
);
4985 for J
in 1 .. Gcc_Switches
.Last
loop
4986 Ensure_Absolute_Path
4987 (Gcc_Switches
.Table
(J
),
4988 Do_Fail
=> Make_Failed
'Access,
4990 Including_Non_Switch
=> False);
4993 for J
in 1 .. Saved_Gcc_Switches
.Last
loop
4994 Ensure_Absolute_Path
4995 (Saved_Gcc_Switches
.Table
(J
),
4996 Parent
=> Current_Work_Dir
,
4997 Do_Fail
=> Make_Failed
'Access,
4998 Including_Non_Switch
=> False);
5001 end Resolve_Relative_Names_In_Switches
;
5003 -----------------------------------
5004 -- Queue_Library_Project_Sources --
5005 -----------------------------------
5007 procedure Queue_Library_Project_Sources
is
5009 if not Unique_Compile
5010 and then MLib
.Tgt
.Support_For_Libraries
/= Prj
.None
5013 Proj
: Project_List
;
5016 Proj
:= Project_Tree
.Projects
;
5017 while Proj
/= null loop
5018 if Proj
.Project
.Library
then
5019 Proj
.Project
.Need_To_Build_Lib
:=
5020 not MLib
.Tgt
.Library_Exists_For
5021 (Proj
.Project
, Project_Tree
)
5022 and then not Proj
.Project
.Externally_Built
;
5024 if Proj
.Project
.Need_To_Build_Lib
then
5026 -- If there is no object directory, then it will be
5027 -- impossible to build the library, so fail immediately.
5029 if Proj
.Project
.Object_Directory
= No_Path_Information
5032 ("no object files to build library for"
5034 & Get_Name_String
(Proj
.Project
.Name
)
5036 Proj
.Project
.Need_To_Build_Lib
:= False;
5039 if Verbose_Mode
then
5041 ("Library file does not exist for "
5044 (Get_Name_String
(Proj
.Project
.Name
));
5048 Insert_Project_Sources
5049 (The_Project
=> Proj
.Project
,
5050 All_Projects
=> False,
5060 end Queue_Library_Project_Sources
;
5062 ------------------------
5063 -- Compute_Executable --
5064 ------------------------
5066 procedure Compute_Executable
5067 (Main_Source_File
: File_Name_Type
;
5068 Executable
: out File_Name_Type
;
5069 Non_Std_Executable
: out Boolean)
5072 Executable
:= No_File
;
5073 Non_Std_Executable
:=
5074 Targparm
.Executable_Extension_On_Target
/= No_Name
;
5076 -- Look inside the linker switches to see if the name of the final
5077 -- executable program was specified.
5079 for J
in reverse Linker_Switches
.First
.. Linker_Switches
.Last
loop
5080 if Linker_Switches
.Table
(J
).all = Output_Flag
.all then
5081 pragma Assert
(J
< Linker_Switches
.Last
);
5083 -- We cannot specify a single executable for several main
5086 if Osint
.Number_Of_Files
> 1 then
5087 Fail
("cannot specify a single executable for several mains");
5091 Add_Str_To_Name_Buffer
(Linker_Switches
.Table
(J
+ 1).all);
5092 Executable
:= Name_Enter
;
5094 Verbose_Msg
(Executable
, "final executable");
5098 -- If the name of the final executable program was not specified then
5099 -- construct it from the main input file.
5101 if Executable
= No_File
then
5102 if Main_Project
= No_Project
then
5103 Executable
:= Executable_Name
(Strip_Suffix
(Main_Source_File
));
5106 -- If we are using a project file, we attempt to remove the body
5107 -- (or spec) termination of the main subprogram. We find it the
5108 -- naming scheme of the project file. This avoids generating an
5109 -- executable "main.2" for a main subprogram "main.2.ada", when
5110 -- the body termination is ".2.ada".
5113 Prj
.Util
.Executable_Of
5114 (Main_Project
, Project_Tree
.Shared
,
5115 Main_Source_File
, Main_Index
);
5119 if Main_Project
/= No_Project
5120 and then Main_Project
.Exec_Directory
/= No_Path_Information
5123 Exec_File_Name
: constant String := Get_Name_String
(Executable
);
5125 if not Is_Absolute_Path
(Exec_File_Name
) then
5126 Get_Name_String
(Main_Project
.Exec_Directory
.Display_Name
);
5127 Add_Str_To_Name_Buffer
(Exec_File_Name
);
5128 Executable
:= Name_Find
;
5131 Non_Std_Executable
:= True;
5134 end Compute_Executable
;
5136 -------------------------------
5137 -- Compute_Switches_For_Main --
5138 -------------------------------
5140 procedure Compute_Switches_For_Main
5141 (Main_Source_File
: in out File_Name_Type
;
5142 Root_Environment
: in out Prj
.Tree
.Environment
;
5143 Compute_Builder
: Boolean;
5144 Current_Work_Dir
: String)
5146 function Add_Global_Switches
5149 For_Builder
: Boolean;
5150 Has_Global_Compilation_Switches
: Boolean) return Boolean;
5151 -- Handles builder and global compilation switches, as read from the
5154 -------------------------
5155 -- Add_Global_Switches --
5156 -------------------------
5158 function Add_Global_Switches
5161 For_Builder
: Boolean;
5162 Has_Global_Compilation_Switches
: Boolean) return Boolean
5164 pragma Unreferenced
(For_Lang
);
5168 Program_Args
:= None
;
5169 Switch_May_Be_Passed_To_The_Compiler
:=
5170 not Has_Global_Compilation_Switches
;
5171 Scan_Make_Arg
(Root_Environment
, Switch
, And_Save
=> False);
5173 return Gnatmake_Switch_Found
5174 or else Switch_May_Be_Passed_To_The_Compiler
;
5176 Add_Switch
(Switch
, Compiler
, And_Save
=> False);
5179 end Add_Global_Switches
;
5181 procedure Do_Compute_Builder_Switches
5182 is new Makeutl
.Compute_Builder_Switches
(Add_Global_Switches
);
5184 -- Start of processing for Compute_Switches_For_Main
5187 if Main_Project
/= No_Project
then
5189 Main_Source_File_Name
: constant String :=
5190 Get_Name_String
(Main_Source_File
);
5192 Main_Unit_File_Name
: constant String :=
5193 Prj
.Env
.File_Name_Of_Library_Unit_Body
5194 (Name
=> Main_Source_File_Name
,
5195 Project
=> Main_Project
,
5196 In_Tree
=> Project_Tree
,
5197 Main_Project_Only
=> not Unique_Compile
);
5199 The_Packages
: constant Package_Id
:= Main_Project
.Decl
.Packages
;
5201 Binder_Package
: constant Prj
.Package_Id
:=
5203 (Name
=> Name_Binder
,
5204 In_Packages
=> The_Packages
,
5205 Shared
=> Project_Tree
.Shared
);
5207 Linker_Package
: constant Prj
.Package_Id
:=
5209 (Name
=> Name_Linker
,
5210 In_Packages
=> The_Packages
,
5211 Shared
=> Project_Tree
.Shared
);
5214 -- We fail if we cannot find the main source file
5216 if Main_Unit_File_Name
= "" then
5217 Make_Failed
('"' & Main_Source_File_Name
5218 & """ is not a unit of project "
5219 & Project_File_Name
.all & ".");
5222 -- Remove any directory information from the main source file
5226 Pos
: Natural := Main_Unit_File_Name
'Last;
5230 exit when Pos
< Main_Unit_File_Name
'First
5231 or else Main_Unit_File_Name
(Pos
) = Directory_Separator
;
5235 Name_Len
:= Main_Unit_File_Name
'Last - Pos
;
5237 Name_Buffer
(1 .. Name_Len
) :=
5238 Main_Unit_File_Name
(Pos
+ 1 .. Main_Unit_File_Name
'Last);
5240 Main_Source_File
:= Name_Find
;
5242 -- We only output the main source file if there is only one
5244 if Verbose_Mode
and then Osint
.Number_Of_Files
= 1 then
5245 Write_Str
("Main source file: """);
5246 Write_Str
(Main_Unit_File_Name
5247 (Pos
+ 1 .. Main_Unit_File_Name
'Last));
5252 if Compute_Builder
then
5253 Do_Compute_Builder_Switches
5254 (Project_Tree
=> Project_Tree
,
5255 Env
=> Root_Environment
,
5256 Main_Project
=> Main_Project
,
5257 Only_For_Lang
=> Name_Ada
);
5259 Resolve_Relative_Names_In_Switches
5260 (Current_Work_Dir
=> Current_Work_Dir
);
5262 -- Record current last switch index for tables Binder_Switches
5263 -- and Linker_Switches, so that these tables may be reset
5264 -- before each main, before adding switches from the project
5265 -- file and from the command line.
5267 Last_Binder_Switch
:= Binder_Switches
.Last
;
5268 Last_Linker_Switch
:= Linker_Switches
.Last
;
5271 -- Reset the tables Binder_Switches and Linker_Switches
5273 Binder_Switches
.Set_Last
(Last_Binder_Switch
);
5274 Linker_Switches
.Set_Last
(Last_Linker_Switch
);
5277 -- We now deal with the binder and linker switches. If no project
5278 -- file is used, there is nothing to do because the binder and
5279 -- linker switches are the same for all mains.
5281 -- Add binder switches from the project file for the first main
5283 if Do_Bind_Step
and then Binder_Package
/= No_Package
then
5284 if Verbose_Mode
then
5285 Write_Str
("Adding binder switches for """);
5286 Write_Str
(Main_Unit_File_Name
);
5291 (Env
=> Root_Environment
,
5292 File_Name
=> Main_Unit_File_Name
,
5293 The_Package
=> Binder_Package
,
5297 -- Add linker switches from the project file for the first main
5299 if Do_Link_Step
and then Linker_Package
/= No_Package
then
5300 if Verbose_Mode
then
5301 Write_Str
("Adding linker switches for""");
5302 Write_Str
(Main_Unit_File_Name
);
5307 (Env
=> Root_Environment
,
5308 File_Name
=> Main_Unit_File_Name
,
5309 The_Package
=> Linker_Package
,
5313 -- As we are using a project file, for relative paths we add the
5314 -- current working directory for any relative path on the command
5315 -- line and the project directory, for any relative path in the
5319 Dir_Path
: constant String :=
5320 Get_Name_String
(Main_Project
.Directory
.Display_Name
);
5323 for J
in Last_Binder_Switch
+ 1 .. Binder_Switches
.Last
loop
5324 Ensure_Absolute_Path
5325 (Binder_Switches
.Table
(J
),
5326 Do_Fail
=> Make_Failed
'Access,
5327 Parent
=> Dir_Path
, For_Gnatbind
=> True);
5330 for J
in Last_Linker_Switch
+ 1 .. Linker_Switches
.Last
loop
5331 Ensure_Absolute_Path
5332 (Linker_Switches
.Table
(J
),
5334 Do_Fail
=> Make_Failed
'Access);
5340 if not Compute_Builder
then
5342 -- Reset the tables Binder_Switches and Linker_Switches
5344 Binder_Switches
.Set_Last
(Last_Binder_Switch
);
5345 Linker_Switches
.Set_Last
(Last_Linker_Switch
);
5351 if Compute_Builder
then
5352 Display_Commands
(not Quiet_Output
);
5355 -- We now put in the Binder_Switches and Linker_Switches tables, the
5356 -- binder and linker switches of the command line that have been put in
5357 -- the Saved_ tables. If a project file was used, then the command line
5358 -- switches will follow the project file switches.
5360 for J
in 1 .. Saved_Binder_Switches
.Last
loop
5362 (Saved_Binder_Switches
.Table
(J
),
5367 for J
in 1 .. Saved_Linker_Switches
.Last
loop
5369 (Saved_Linker_Switches
.Table
(J
),
5373 end Compute_Switches_For_Main
;
5379 procedure Gnatmake
is
5380 Main_Source_File
: File_Name_Type
;
5381 -- The source file containing the main compilation unit
5383 Total_Compilation_Failures
: Natural := 0;
5385 Main_ALI_File
: File_Name_Type
;
5386 -- The ali file corresponding to Main_Source_File
5388 Executable
: File_Name_Type
:= No_File
;
5389 -- The file name of an executable
5391 Non_Std_Executable
: Boolean := False;
5392 -- Non_Std_Executable is set to True when there is a possibility that
5393 -- the linker will not choose the correct executable file name.
5395 Current_Work_Dir
: constant String_Access
:=
5396 new String'(Get_Current_Dir);
5397 -- The current working directory, used to modify some relative path
5398 -- switches on the command line when a project file is used.
5400 Current_Main_Index : Int := 0;
5401 -- If not zero, the index of the current main unit in its source file
5403 Is_First_Main : Boolean;
5404 -- Whether we are processing the first main
5406 Stand_Alone_Libraries : Boolean := False;
5407 -- Set to True when there are Stand-Alone Libraries, so that gnatbind
5408 -- is invoked with the -F switch to force checking of elaboration flags.
5410 Project_Node_Tree : Project_Node_Tree_Ref;
5412 Stop_Compile : Boolean;
5415 pragma Warnings (Off, Discard);
5417 procedure Check_Mains;
5418 -- Check that the main subprograms do exist and that they all
5419 -- belong to the same project file.
5425 procedure Check_Mains is
5426 Real_Main_Project : Project_Id := No_Project;
5431 if Mains.Number_Of_Mains (Project_Tree) = 0
5432 and then not Unique_Compile
5434 Mains.Fill_From_Project (Main_Project, Project_Tree);
5437 Mains.Complete_Mains
5438 (Root_Environment.Flags, Main_Project, Project_Tree);
5440 -- If we have multiple mains on the command line, they need not
5441 -- belong to the root project, but they must all belong to the same
5444 if not Unique_Compile then
5447 Info := Mains.Next_Main;
5448 exit when Info = No_Main_Info;
5450 Proj := Ultimate_Extending_Project_Of (Info.Project);
5452 if Real_Main_Project = No_Project then
5453 Real_Main_Project := Proj;
5454 elsif Real_Main_Project /= Proj then
5456 ("""" & Get_Name_String (Info.File) &
5457 """ is not a source of project " &
5458 Get_Name_String (Real_Main_Project.Name));
5462 if Real_Main_Project /= No_Project then
5463 Main_Project := Real_Main_Project;
5466 Debug_Output ("After checking mains, main project is",
5470 -- For all mains on the command line, make sure they were in
5471 -- osint. In particular, if the user has specified a multi-unit
5472 -- source file, the call to Complete_Mains will have expanded
5473 -- the list of mains to all its units, and we must now put them
5474 -- back on the command line.
5475 -- ??? This will not be necessary when gnatmake shares the same
5476 -- queue as gprbuild and processes the file directly on the queue.
5480 Info := Mains.Next_Main;
5481 exit when Info = No_Main_Info;
5483 if Info.Index /= 0 then
5484 Debug_Output ("Add to command line index="
5485 & Info.Index'Img, Name_Id (Info.File));
5486 Osint.Add_File (Get_Name_String (Info.File), Info.Index);
5492 -- Start of processing for Gnatmake
5494 -- This body is very long, should be broken down???
5497 Install_Int_Handler (Sigint_Intercepted'Access);
5499 Do_Compile_Step := True;
5500 Do_Bind_Step := True;
5501 Do_Link_Step := True;
5505 Make.Initialize (Project_Node_Tree, Root_Environment);
5507 Bind_Shared := No_Shared_Switch'Access;
5508 Link_With_Shared_Libgcc := No_Shared_Libgcc_Switch'Access;
5510 Failed_Links.Set_Last (0);
5511 Successful_Links.Set_Last (0);
5513 -- Special case when switch -B was specified
5515 if Build_Bind_And_Link_Full_Project then
5517 -- When switch -B is specified, there must be a project file
5519 if Main_Project = No_Project then
5520 Make_Failed ("-B cannot be used without a project file");
5522 -- No main program may be specified on the command line
5524 elsif Osint.Number_Of_Files /= 0 then
5526 ("-B cannot be used with a main specified on the command line");
5528 -- And the project file cannot be a library project file
5530 elsif Main_Project.Library then
5531 Make_Failed ("-B cannot be used for a library project file");
5534 No_Main_Subprogram := True;
5535 Insert_Project_Sources
5536 (The_Project => Main_Project,
5537 All_Projects => Unique_Compile_All_Projects,
5540 -- If there are no sources to compile, we fail
5542 if Osint.Number_Of_Files = 0 then
5543 Make_Failed ("no sources to compile");
5546 -- Specify -n for gnatbind and add the ALI files of all the
5547 -- sources, except the one which is a fake main subprogram: this
5548 -- is the one for the binder generated file and it will be
5549 -- transmitted to gnatlink. These sources are those that are in
5552 Add_Switch ("-n", Binder, And_Save => True);
5554 for J in 1 .. Queue.Size loop
5556 (Get_Name_String (Lib_File_Name (Queue.Element (J))),
5557 Binder, And_Save => True);
5561 elsif Main_Index /= 0 and then Osint.Number_Of_Files > 1 then
5562 Make_Failed ("cannot specify several mains with a multi-unit index");
5564 elsif Main_Project /= No_Project then
5566 -- If the main project file is a library project file, main(s) cannot
5567 -- be specified on the command line.
5569 if Osint.Number_Of_Files /= 0 then
5570 if Main_Project.Library
5571 and then not Unique_Compile
5572 and then ((not Make_Steps) or else Bind_Only or else Link_Only)
5575 ("cannot specify a main program "
5576 & "on the command line for a library project file");
5579 -- If no mains have been specified on the command line, and we are
5580 -- using a project file, we either find the main(s) in attribute Main
5581 -- of the main project, or we put all the sources of the project file
5585 if Main_Index /= 0 then
5586 Make_Failed ("cannot specify a multi-unit index but no main "
5587 & "on the command line");
5591 Value : String_List_Id := Main_Project.Mains;
5594 -- The attribute Main is an empty list or not specified, or
5595 -- else gnatmake was invoked with the switch "-u".
5597 if Value = Prj.Nil_String or else Unique_Compile then
5600 or not Main_Project.Library
5602 -- First make sure that the binder and the linker will
5605 Do_Bind_Step := False;
5606 Do_Link_Step := False;
5608 -- Put all the sources in the queue
5610 No_Main_Subprogram := True;
5611 Insert_Project_Sources
5612 (The_Project => Main_Project,
5613 All_Projects => Unique_Compile_All_Projects,
5616 -- If no sources to compile, then there is nothing to do
5618 if Osint.Number_Of_Files = 0 then
5619 if not Quiet_Output then
5620 Osint.Write_Program_Name;
5621 Write_Line (": no sources to compile");
5624 Finish_Program (Project_Tree, E_Success);
5629 -- The attribute Main is not an empty list. Put all the main
5630 -- subprograms in the list as if they were specified on the
5631 -- command line. However, if attribute Languages includes a
5632 -- language other than Ada, only include the Ada mains; if
5633 -- there is no Ada main, compile all sources of the project.
5636 Languages : constant Variable_Value :=
5639 Main_Project.Decl.Attributes,
5640 Project_Tree.Shared);
5642 Current : String_List_Id;
5643 Element : String_Element;
5645 Foreign_Language : Boolean := False;
5646 At_Least_One_Main : Boolean := False;
5649 -- First, determine if there is a foreign language in
5650 -- attribute Languages.
5652 if not Languages.Default then
5653 Current := Languages.Values;
5655 while Current /= Nil_String loop
5656 Element := Project_Tree.Shared.String_Elements.
5658 Get_Name_String (Element.Value);
5659 To_Lower (Name_Buffer (1 .. Name_Len));
5661 if Name_Buffer (1 .. Name_Len) /= "ada" then
5662 Foreign_Language := True;
5663 exit Look_For_Foreign;
5666 Current := Element.Next;
5667 end loop Look_For_Foreign;
5670 -- Then, find all mains, or if there is a foreign
5671 -- language, all the Ada mains.
5673 while Value /= Prj.Nil_String loop
5674 -- To know if a main is an Ada main, get its project.
5675 -- It should be the project specified on the command
5679 (Project_Tree.Shared.String_Elements.Table
5683 Main_Name : constant String :=
5685 (Project_Tree.Shared.
5687 Table (Value).Value);
5689 Proj : constant Project_Id :=
5691 (Main_Name, Main_Project, Project_Tree);
5694 if Proj = Main_Project then
5695 At_Least_One_Main := True;
5698 (Project_Tree.Shared.String_Elements.Table
5701 Project_Tree.Shared.String_Elements.Table
5704 elsif not Foreign_Language then
5707 """ is not a source of project " &
5708 Get_Name_String (Main_Project.Display_Name));
5712 Value := Project_Tree.Shared.String_Elements.Table
5716 -- If we did not get any main, it means that all mains
5717 -- in attribute Mains are in a foreign language and -B
5718 -- was not specified to gnatmake; so, we fail.
5720 if not At_Least_One_Main then
5722 ("no Ada mains, use -B to build foreign main");
5730 -- Check that each main on the command line is a source of a
5731 -- project file and, if there are several mains, each of them
5732 -- is a source of the same project file.
5737 if Verbose_Mode then
5739 Display_Version ("GNATMAKE", "1992");
5742 if Osint.Number_Of_Files = 0 then
5743 if Main_Project /= No_Project and then Main_Project.Library then
5744 if Do_Bind_Step and then Main_Project.Standalone_Library = No then
5745 Make_Failed ("only stand-alone libraries may be bound");
5748 -- Add the default search directories to be able to find libgnat
5750 Osint.Add_Default_Search_Dirs;
5752 -- And bind and or link the library
5754 MLib.Prj.Build_Library
5755 (For_Project => Main_Project,
5756 In_Tree => Project_Tree,
5757 Gnatbind => Gnatbind.all,
5758 Gnatbind_Path => Gnatbind_Path,
5760 Gcc_Path => Gcc_Path,
5764 Finish_Program (Project_Tree, E_Success);
5767 -- Call Get_Target_Parameters to ensure that flags are properly
5768 -- set before calling Usage.
5770 Targparm.Get_Target_Parameters;
5772 -- Output usage information if no argument on the command line
5774 if Argument_Count = 0 then
5780 Finish_Program (Project_Tree, E_Success);
5784 -- Get the first executable.
5785 -- ??? This needs to be done early, because Osint.Next_Main_File also
5786 -- initializes the primary search directory, used below to initialize
5787 -- the "-I" parameter
5789 Main_Source_File := Next_Main_Source; -- No directory information
5791 -- If -M was specified, behave as if -n was specified
5793 if List_Dependencies then
5794 Do_Not_Execute := True;
5797 Add_Switch ("-I-", Compiler, And_Save => True);
5799 if Main_Project = No_Project then
5800 if Look_In_Primary_Dir then
5803 Normalize_Directory_Name
5804 (Get_Primary_Src_Search_Directory.all).all,
5806 Append_Switch => False,
5812 -- If we use a project file, we have already checked that a main
5813 -- specified on the command line with directory information has the
5814 -- path name corresponding to a correct source in the project tree.
5815 -- So, we don't need the directory information to be taken into
5816 -- account by Find_File, and in fact it may lead to take the wrong
5817 -- sources for other compilation units, when there are extending
5820 Look_In_Primary_Dir := False;
5823 -- If the user wants a program without a main subprogram, add the
5824 -- appropriate switch to the binder.
5826 if No_Main_Subprogram then
5827 Add_Switch ("-z", Binder, And_Save => True);
5830 if Main_Project /= No_Project then
5832 if Main_Project.Object_Directory /= No_Path_Information then
5834 -- Change current directory to object directory of main project
5836 Project_Of_Current_Object_Directory := No_Project;
5837 Change_To_Object_Directory (Main_Project);
5840 -- Source file lookups should be cached for efficiency. Source files
5841 -- are not supposed to change.
5843 Osint.Source_File_Data (Cache => True);
5845 Queue_Library_Project_Sources;
5848 -- The combination of -f -u and one or several mains on the command line
5851 if Force_Compilations
5852 and then Unique_Compile
5853 and then not Unique_Compile_All_Projects
5854 and then Main_On_Command_Line
5856 Must_Compile := True;
5859 if Main_Project /= No_Project
5860 and then not Must_Compile
5861 and then Main_Project.Externally_Built
5864 ("nothing to do for a main project that is externally built");
5867 -- If no project file is used, we just put the gcc switches
5868 -- from the command line in the Gcc_Switches table.
5870 if Main_Project = No_Project then
5871 for J in 1 .. Saved_Gcc_Switches.Last loop
5873 (Saved_Gcc_Switches.Table (J), Compiler, And_Save => False);
5877 -- If there is a project, put the command line gcc switches in the
5878 -- variable The_Saved_Gcc_Switches. They are going to be used later
5879 -- in procedure Compile_Sources.
5881 The_Saved_Gcc_Switches :=
5882 new Argument_List (1 .. Saved_Gcc_Switches.Last + 1);
5884 for J in 1 .. Saved_Gcc_Switches.Last loop
5885 The_Saved_Gcc_Switches (J) := Saved_Gcc_Switches.Table (J);
5888 -- We never use gnat.adc when a project file is used
5890 The_Saved_Gcc_Switches (The_Saved_Gcc_Switches'Last) := No_gnat_adc;
5893 -- If there was a --GCC, --GNATBIND or --GNATLINK switch on the command
5894 -- line, then we have to use it, even if there was another switch in
5895 -- the project file.
5897 if Saved_Gcc /= null then
5901 if Saved_Gnatbind /= null then
5902 Gnatbind := Saved_Gnatbind;
5905 if Saved_Gnatlink /= null then
5906 Gnatlink := Saved_Gnatlink;
5909 Bad_Compilation.Init;
5911 -- If project files are used, create the mapping of all the sources, so
5912 -- that the correct paths will be found. Otherwise, if there is a file
5913 -- which is not a source with the same name in a source directory this
5914 -- file may be incorrectly found.
5916 if Main_Project /= No_Project then
5917 Prj.Env.Create_Mapping (Project_Tree);
5920 -- Here is where the make process is started
5923 (Main_Project /= No_Project and then One_Compilation_Per_Obj_Dir);
5925 Is_First_Main := True;
5927 Multiple_Main_Loop : for N_File in 1 .. Osint.Number_Of_Files loop
5928 if Current_File_Index /= No_Index then
5929 Main_Index := Current_File_Index;
5932 Current_Main_Index := Main_Index;
5934 if Current_Main_Index = 0
5935 and then Unique_Compile
5936 and then Main_Project /= No_Project
5938 -- If this is a multi-unit source, do not compile it as is (ie
5939 -- without specifying which unit to compile)
5940 -- Insert_Project_Sources has added each of the unit separately.
5943 Source : constant Prj.Source_Id := Find_Source
5944 (In_Tree => Project_Tree,
5945 Project => Main_Project,
5946 Base_Name => Main_Source_File,
5947 Index => Current_Main_Index,
5948 In_Imported_Only => True);
5950 if Source /= No_Source and then Source.Index /= 0 then
5956 Compute_Switches_For_Main
5959 Compute_Builder => Is_First_Main,
5960 Current_Work_Dir => Current_Work_Dir.all);
5962 if Is_First_Main then
5964 -- Put the default source dirs in the source path only now, so
5965 -- that we take the correct ones in the case where --RTS= is
5966 -- specified in the Builder switches.
5968 Osint.Add_Default_Search_Dirs;
5970 -- Get the target parameters, which are only needed for a couple
5971 -- of cases in gnatmake. Protect against an exception, such as the
5972 -- case of system.ads missing from the library, and fail
5976 Targparm.Get_Target_Parameters;
5978 when Unrecoverable_Error =>
5979 Make_Failed ("*** make failed.");
5982 Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
5983 Gnatbind_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
5984 Gnatlink_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
5986 -- If we have specified -j switch both from the project file
5987 -- and on the command line, the one from the command line takes
5990 if Saved_Maximum_Processes = 0 then
5991 Saved_Maximum_Processes := Maximum_Processes;
5994 if Debug.Debug_Flag_M then
5995 Write_Line ("Maximum number of simultaneous compilations =" &
5996 Saved_Maximum_Processes'Img);
5999 -- Allocate as many temporary mapping file names as the maximum
6000 -- number of compilations processed, for each possible project.
6003 Data : Project_Compilation_Access;
6004 Proj : Project_List;
6007 Proj := Project_Tree.Projects;
6008 while Proj /= null loop
6010 new Project_Compilation_Data'
6011 (Mapping_File_Names
=>
6012 new Temp_Path_Names
(1 .. Saved_Maximum_Processes
),
6013 Last_Mapping_File_Names
=> 0,
6014 Free_Mapping_File_Indexes
=>
6015 new Free_File_Indexes
(1 .. Saved_Maximum_Processes
),
6016 Last_Free_Indexes
=> 0);
6018 Project_Compilation_Htable
.Set
6019 (Project_Compilation
, Proj
.Project
, Data
);
6024 new Project_Compilation_Data
'
6025 (Mapping_File_Names =>
6026 new Temp_Path_Names (1 .. Saved_Maximum_Processes),
6027 Last_Mapping_File_Names => 0,
6028 Free_Mapping_File_Indexes =>
6029 new Free_File_Indexes (1 .. Saved_Maximum_Processes),
6030 Last_Free_Indexes => 0);
6032 Project_Compilation_Htable.Set
6033 (Project_Compilation, No_Project, Data);
6036 Is_First_Main := False;
6039 Executable_Obsolete := False;
6042 (Main_Source_File => Main_Source_File,
6043 Executable => Executable,
6044 Non_Std_Executable => Non_Std_Executable);
6046 if Do_Compile_Step then
6048 (Main_Source_File => Main_Source_File,
6049 Current_Main_Index => Current_Main_Index,
6050 Total_Compilation_Failures => Total_Compilation_Failures,
6051 Stand_Alone_Libraries => Stand_Alone_Libraries,
6052 Executable => Executable,
6053 Is_Last_Main => N_File = Osint.Number_Of_Files,
6054 Stop_Compile => Stop_Compile);
6056 if Stop_Compile then
6057 if Total_Compilation_Failures /= 0 then
6062 List_Bad_Compilations;
6063 Report_Compilation_Failed;
6066 elsif Osint.Number_Of_Files = 1 then
6067 exit Multiple_Main_Loop;
6074 -- For binding and linking, we need to be in the object directory of
6075 -- the main project.
6077 if Main_Project /= No_Project then
6078 Change_To_Object_Directory (Main_Project);
6081 -- If we are here, it means that we need to rebuilt the current main,
6082 -- so we set Executable_Obsolete to True to make sure that subsequent
6083 -- mains will be rebuilt.
6085 Main_ALI_In_Place_Mode_Step : declare
6086 ALI_File : File_Name_Type;
6087 Src_File : File_Name_Type;
6090 Src_File := Strip_Directory (Main_Source_File);
6091 ALI_File := Lib_File_Name (Src_File, Current_Main_Index);
6092 Main_ALI_File := Full_Lib_File_Name (ALI_File);
6094 -- When In_Place_Mode, the library file can be located in the
6095 -- Main_Source_File directory which may not be present in the
6096 -- library path. If it is not present then use the corresponding
6097 -- library file name.
6099 if Main_ALI_File = No_File and then In_Place_Mode then
6100 Get_Name_String (Get_Directory (Full_Source_Name (Src_File)));
6101 Get_Name_String_And_Append (ALI_File);
6102 Main_ALI_File := Name_Find;
6103 Main_ALI_File := Full_Lib_File_Name (Main_ALI_File);
6106 if Main_ALI_File = No_File then
6107 Make_Failed ("could not find the main ALI file");
6109 end Main_ALI_In_Place_Mode_Step;
6111 if Do_Bind_Step then
6113 (Stand_Alone_Libraries => Stand_Alone_Libraries,
6114 Main_ALI_File => Main_ALI_File);
6117 if Do_Link_Step then
6119 (Non_Std_Executable => Non_Std_Executable,
6120 Executable => Executable,
6121 Main_ALI_File => Main_ALI_File);
6124 -- We go to here when we skip the bind and link steps
6130 if N_File < Osint.Number_Of_Files then
6131 Main_Source_File := Next_Main_Source; -- No directory information
6133 end loop Multiple_Main_Loop;
6135 if Failed_Links.Last > 0 then
6136 for Index in 1 .. Successful_Links.Last loop
6137 Write_Str ("Linking of """);
6138 Write_Str (Get_Name_String (Successful_Links.Table (Index)));
6139 Write_Line (""" succeeded.");
6144 for Index in 1 .. Failed_Links.Last loop
6145 Write_Str ("Linking of """);
6146 Write_Str (Get_Name_String (Failed_Links.Table (Index)));
6147 Write_Line (""" failed.");
6150 if Commands_To_Stdout then
6151 Set_Standard_Output;
6154 if Total_Compilation_Failures = 0 then
6155 Report_Compilation_Failed;
6159 if Total_Compilation_Failures /= 0 then
6160 List_Bad_Compilations;
6161 Report_Compilation_Failed;
6164 Finish_Program (Project_Tree, E_Success);
6169 Write_Line (Exception_Information (X));
6170 Make_Failed ("INTERNAL ERROR. Please report.");
6177 function Hash (F : File_Name_Type) return Header_Num is
6179 return Header_Num (1 + F mod Max_Header);
6182 --------------------
6183 -- In_Ada_Lib_Dir --
6184 --------------------
6186 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean is
6187 D : constant File_Name_Type := Get_Directory (File);
6188 B : constant Byte := Get_Name_Table_Byte (D);
6190 return (B and Ada_Lib_Dir) /= 0;
6193 -----------------------
6194 -- Init_Mapping_File --
6195 -----------------------
6197 procedure Init_Mapping_File
6198 (Project : Project_Id;
6199 Data : in out Project_Compilation_Data;
6200 File_Index : in out Natural)
6202 FD : File_Descriptor;
6204 -- For call to Close
6207 -- Increase the index of the last mapping file for this project
6209 Data.Last_Mapping_File_Names := Data.Last_Mapping_File_Names + 1;
6211 -- If there is a project file, call Create_Mapping_File with
6214 if Project /= No_Project then
6215 Prj.Env.Create_Mapping_File
6217 In_Tree => Project_Tree,
6218 Language => Name_Ada,
6219 Name => Data.Mapping_File_Names
6220 (Data.Last_Mapping_File_Names));
6222 -- Otherwise, just create an empty file
6225 Tempdir.Create_Temp_File
6226 (FD, Data.Mapping_File_Names (Data.Last_Mapping_File_Names));
6228 if FD = Invalid_FD then
6229 Make_Failed ("disk full");
6232 (Project_Tree.Shared,
6233 Data.Mapping_File_Names (Data.Last_Mapping_File_Names));
6239 Make_Failed ("disk full");
6243 -- And return the index of the newly created file
6245 File_Index := Data.Last_Mapping_File_Names;
6246 end Init_Mapping_File;
6252 procedure Initialize
6253 (Project_Node_Tree : out Project_Node_Tree_Ref;
6254 Env : out Prj.Tree.Environment)
6256 procedure Check_Version_And_Help is
6257 new Check_Version_And_Help_G (Makeusg);
6259 -- Start of processing for Initialize
6262 -- Prepare the project's tree, since this is used to hold external
6263 -- references, project path and other attributes that can be impacted by
6264 -- the command line switches
6266 Prj.Tree.Initialize (Env, Gnatmake_Flags);
6268 Project_Node_Tree := new Project_Node_Tree_Data;
6269 Prj.Tree.Initialize (Project_Node_Tree);
6271 -- Override default initialization of Check_Object_Consistency since
6272 -- this is normally False for GNATBIND, but is True for GNATMAKE since
6273 -- we do not need to check source consistency again once GNATMAKE has
6274 -- looked at the sources to check.
6276 Check_Object_Consistency := True;
6278 -- Package initializations (the order of calls is important here)
6280 Output.Set_Standard_Error;
6283 Binder_Switches.Init;
6284 Linker_Switches.Init;
6290 Prj.Initialize (Project_Tree);
6294 RTS_Specified := null;
6299 -- Add the directory where gnatmake is invoked in front of the path,
6300 -- if gnatmake is invoked from a bin directory or with directory
6304 Prefix : constant String := Executable_Prefix_Path;
6305 Command : constant String := Command_Name;
6308 if Prefix'Length > 0 then
6310 PATH : constant String :=
6311 Prefix & Directory_Separator & "bin" & Path_Separator
6312 & Getenv ("PATH").all;
6314 Setenv ("PATH", PATH);
6318 for Index in reverse Command'Range loop
6319 if Command (Index) = Directory_Separator then
6321 Absolute_Dir : constant String :=
6323 (Command (Command'First .. Index));
6324 PATH : constant String :=
6327 Getenv ("PATH").all;
6329 Setenv ("PATH", PATH);
6338 -- Scan the switches and arguments
6340 -- First, scan to detect --version and/or --help
6342 Check_Version_And_Help ("GNATMAKE", "1995");
6344 -- Scan again the switch and arguments, now that we are sure that they
6345 -- do not include --version or --help.
6347 -- First, check for switch -P and, if found and gprbuild is available,
6348 -- silently invoke gprbuild, with switch --target if not on a native
6352 Arg_Len : Natural := Argument_Count;
6353 Call_Gprbuild : Boolean := False;
6354 Gprbuild : String_Access := null;
6357 Target : String_Access := null;
6363 and then Name_Buffer (Name_Len - 7 .. Name_Len) = "gnatmake"
6365 if Name_Len > 8 then
6366 Target := new String'(Name_Buffer
(1 .. Name_Len
- 9));
6367 Arg_Len
:= Arg_Len
+ 1;
6370 for J
in 1 .. Argument_Count
loop
6372 Arg
: constant String := Argument
(J
);
6375 and then Arg
(Arg
'First .. Arg
'First + 1) = "-P"
6377 Call_Gprbuild
:= True;
6383 if Call_Gprbuild
then
6384 Gprbuild
:= Locate_Exec_On_Path
(Exec_Name
=> "gprbuild");
6386 if Gprbuild
/= null then
6388 Args
: Argument_List
(1 .. Arg_Len
);
6390 if Target
/= null then
6391 Args
(1) := new String'("--target=" & Target.all);
6395 for J in 1 .. Argument_Count loop
6397 Args (Pos) := new String'(Argument
(J
));
6400 Spawn
(Gprbuild
.all, Args
, Success
);
6405 Exit_Program
(E_Success
);
6413 Scan_Args
: for Next_Arg
in 1 .. Argument_Count
loop
6414 Scan_Make_Arg
(Env
, Argument
(Next_Arg
), And_Save
=> True);
6417 if N_M_Switch
> 0 and RTS_Specified
= null then
6418 Process_Multilib
(Env
);
6421 if Commands_To_Stdout
then
6422 Set_Standard_Output
;
6425 if Usage_Requested
then
6429 -- Add the default project search directories now, after the directories
6430 -- that have been specified by switches -aP<dir>.
6432 Prj
.Env
.Initialize_Default_Project_Path
6433 (Env
.Project_Path
, Target_Name
=> Sdefault
.Target_Name
.all);
6435 -- Test for trailing -P switch
6437 if Project_File_Name_Present
and then Project_File_Name
= null then
6438 Make_Failed
("project file name missing after -P");
6440 -- Test for trailing -o switch
6442 elsif Output_File_Name_Present
and then not Output_File_Name_Seen
then
6443 Make_Failed
("output file name missing after -o");
6445 -- Test for trailing -D switch
6447 elsif Object_Directory_Present
and then not Object_Directory_Seen
then
6448 Make_Failed
("object directory missing after -D");
6451 -- Test for simultaneity of -i and -D
6453 if Object_Directory_Path
/= null and then In_Place_Mode
then
6454 Make_Failed
("-i and -D cannot be used simultaneously");
6457 -- If --subdirs= is specified, but not -P, this is equivalent to -D,
6458 -- except that the directory is created if it does not exist.
6460 if Prj
.Subdirs
/= null and then Project_File_Name
= null then
6461 if Object_Directory_Path
/= null then
6462 Make_Failed
("--subdirs and -D cannot be used simultaneously");
6464 elsif In_Place_Mode
then
6465 Make_Failed
("--subdirs and -i cannot be used simultaneously");
6468 if not Is_Directory
(Prj
.Subdirs
.all) then
6470 Ada
.Directories
.Create_Path
(Prj
.Subdirs
.all);
6473 Make_Failed
("unable to create object directory " &
6478 Object_Directory_Present
:= True;
6481 Argv
: constant String (1 .. Prj
.Subdirs
'Length) :=
6484 Scan_Make_Arg
(Env
, Argv
, And_Save
=> False);
6489 -- Deal with -C= switch
6491 if Gnatmake_Mapping_File
/= null then
6493 -- First, check compatibility with other switches
6495 if Project_File_Name
/= null then
6496 Make_Failed
("-C= switch is not compatible with -P switch");
6498 elsif Saved_Maximum_Processes
> 1 then
6499 Make_Failed
("-C= switch is not compatible with -jnnn switch");
6502 Fmap
.Initialize
(Gnatmake_Mapping_File
.all);
6504 ("-gnatem=" & Gnatmake_Mapping_File
.all,
6509 if Project_File_Name
/= null then
6511 -- A project file was specified by a -P switch
6513 if Verbose_Mode
then
6515 Write_Str
("Parsing project file """);
6516 Write_Str
(Project_File_Name
.all);
6521 -- Avoid looking in the current directory for ALI files
6523 -- Look_In_Primary_Dir := False;
6525 -- Set the project parsing verbosity to whatever was specified
6526 -- by a possible -vP switch.
6528 Prj
.Pars
.Set_Verbosity
(To
=> Current_Verbosity
);
6530 -- Parse the project file.
6531 -- If there is an error, Main_Project will still be No_Project.
6534 (Project
=> Main_Project
,
6535 In_Tree
=> Project_Tree
,
6536 Project_File_Name
=> Project_File_Name
.all,
6537 Packages_To_Check
=> Packages_To_Check_By_Gnatmake
,
6539 In_Node_Tree
=> Project_Node_Tree
);
6541 -- The parsing of project files may have changed the current output
6543 if Commands_To_Stdout
then
6544 Set_Standard_Output
;
6549 if Main_Project
= No_Project
then
6551 ("""" & Project_File_Name
.all & """ processing failed");
6554 if Main_Project
.Qualifier
= Aggregate
then
6555 Make_Failed
("aggregate projects are not supported");
6557 elsif Aggregate_Libraries_In
(Project_Tree
) then
6558 Make_Failed
("aggregate library projects are not supported");
6561 Create_Mapping_File
:= True;
6563 if Verbose_Mode
then
6565 Write_Str
("Parsing of project file """);
6566 Write_Str
(Project_File_Name
.all);
6567 Write_Str
(""" is finished.");
6571 -- We add the source directories and the object directories to the
6574 -- ??? Why do we need these search directories, we already know the
6575 -- locations from parsing the project, except for the runtime which
6576 -- has its own directories anyway
6578 Add_Source_Directories
(Main_Project
, Project_Tree
);
6579 Add_Object_Directories
(Main_Project
, Project_Tree
);
6581 Recursive_Compute_Depth
(Main_Project
);
6582 Compute_All_Imported_Projects
(Main_Project
, Project_Tree
);
6586 Osint
.Add_Default_Search_Dirs
;
6588 -- Source file lookups should be cached for efficiency. Source files
6589 -- are not supposed to change. However, we do that now only if no
6590 -- project file is used; if a project file is used, we do it just
6591 -- after changing the directory to the object directory.
6593 Osint
.Source_File_Data
(Cache
=> True);
6595 -- Read gnat.adc file to initialize Fname.UF
6597 Fname
.UF
.Initialize
;
6601 Fname
.SF
.Read_Source_File_Name_Pragmas
;
6604 when Err
: SFN_Scan
.Syntax_Error_In_GNAT_ADC
=>
6605 Make_Failed
(Exception_Message
(Err
));
6610 -- Make sure no project object directory is recorded
6612 Project_Of_Current_Object_Directory
:= No_Project
;
6614 if Debug
.Debug_Flag_N
then
6615 Opt
.Keep_Temporary_Files
:= True;
6619 ----------------------------
6620 -- Insert_Project_Sources --
6621 ----------------------------
6623 procedure Insert_Project_Sources
6624 (The_Project
: Project_Id
;
6625 All_Projects
: Boolean;
6628 Put_In_Q
: Boolean := Into_Q
;
6630 Sfile
: File_Name_Type
;
6631 Sid
: Prj
.Source_Id
;
6633 Project
: Project_Id
;
6636 -- Loop through all the sources in the project files
6638 Unit
:= Units_Htable
.Get_First
(Project_Tree
.Units_HT
);
6639 while Unit
/= null loop
6643 Project
:= No_Project
;
6645 -- If there is a source for the body, and the body has not been
6648 if Unit
.File_Names
(Impl
) /= null
6649 and then not Unit
.File_Names
(Impl
).Locally_Removed
6651 -- And it is a source for the specified project
6655 Is_Extending
(The_Project
, Unit
.File_Names
(Impl
).Project
)
6657 Project
:= Unit
.File_Names
(Impl
).Project
;
6659 -- If we don't have a spec, we cannot consider the source
6660 -- if it is a subunit.
6662 if Unit
.File_Names
(Spec
) = null then
6664 Src_Ind
: Source_File_Index
;
6666 -- Here we are cheating a little bit: we don't want to
6667 -- use Sinput.L, because it depends on the GNAT tree
6668 -- (Atree, Sinfo, ...). So, we pretend that it is a
6669 -- project file, and we use Sinput.P.
6671 -- Source_File_Is_Subunit is just scanning through the
6672 -- file until it finds one of the reserved words
6673 -- separate, procedure, function, generic or package.
6674 -- Fortunately, these Ada reserved words are also
6675 -- reserved for project files.
6678 Src_Ind
:= Sinput
.P
.Load_Project_File
6680 (Unit
.File_Names
(Impl
).Path
.Display_Name
));
6682 -- If it is a subunit, discard it
6684 if Sinput
.P
.Source_File_Is_Subunit
(Src_Ind
) then
6689 Sfile
:= Unit
.File_Names
(Impl
).Display_File
;
6690 Index
:= Unit
.File_Names
(Impl
).Index
;
6691 Sid
:= Unit
.File_Names
(Impl
);
6696 Sfile
:= Unit
.File_Names
(Impl
).Display_File
;
6697 Index
:= Unit
.File_Names
(Impl
).Index
;
6698 Sid
:= Unit
.File_Names
(Impl
);
6702 elsif Unit
.File_Names
(Spec
) /= null
6703 and then not Unit
.File_Names
(Spec
).Locally_Removed
6707 Is_Extending
(The_Project
, Unit
.File_Names
(Spec
).Project
))
6709 -- If there is no source for the body, but there is one for the
6710 -- spec which has not been locally removed, then we take this one.
6712 Sfile
:= Unit
.File_Names
(Spec
).Display_File
;
6713 Index
:= Unit
.File_Names
(Spec
).Index
;
6714 Sid
:= Unit
.File_Names
(Spec
);
6715 Project
:= Unit
.File_Names
(Spec
).Project
;
6718 -- For the first source inserted into the Q, we need to initialize
6719 -- the Q, but not for the subsequent sources.
6722 (Main_Project
/= No_Project
and then
6723 One_Compilation_Per_Obj_Dir
);
6725 if Sfile
/= No_File
then
6727 ((Format
=> Format_Gnatmake
,
6730 Unit
=> No_Unit_Name
,
6735 if not Put_In_Q
and then Sfile
/= No_File
then
6737 -- If Put_In_Q is False, we add the source as if it were specified
6738 -- on the command line, and we set Put_In_Q to True, so that the
6739 -- following sources will only be put in the queue. The source is
6740 -- already in the Q, but we need at least one fake main to call
6743 if Verbose_Mode
then
6744 Write_Str
("Adding """);
6745 Write_Str
(Get_Name_String
(Sfile
));
6746 Write_Line
(""" as if on the command line");
6749 Osint
.Add_File
(Get_Name_String
(Sfile
), Index
);
6753 Unit
:= Units_Htable
.Get_Next
(Project_Tree
.Units_HT
);
6755 end Insert_Project_Sources
;
6757 ---------------------
6758 -- Is_In_Obsoleted --
6759 ---------------------
6761 function Is_In_Obsoleted
(F
: File_Name_Type
) return Boolean is
6768 Name
: constant String := Get_Name_String
(F
);
6770 F2
: File_Name_Type
;
6774 while First
> Name
'First
6775 and then not Is_Directory_Separator
(Name
(First
- 1))
6780 if First
/= Name
'First then
6782 Add_Str_To_Name_Buffer
(Name
(First
.. Name
'Last));
6789 return Obsoleted
.Get
(F2
);
6792 end Is_In_Obsoleted
;
6794 ----------------------------
6795 -- Is_In_Object_Directory --
6796 ----------------------------
6798 function Is_In_Object_Directory
6799 (Source_File
: File_Name_Type
;
6800 Full_Lib_File
: File_Name_Type
) return Boolean
6803 -- There is something to check only when using project files. Otherwise,
6804 -- this function returns True (last line of the function).
6806 if Main_Project
/= No_Project
then
6808 Source_File_Name
: constant String :=
6809 Get_Name_String
(Source_File
);
6810 Saved_Verbosity
: constant Verbosity
:= Current_Verbosity
;
6811 Project
: Project_Id
:= No_Project
;
6813 Path_Name
: Path_Name_Type
:= No_Path
;
6814 pragma Warnings
(Off
, Path_Name
);
6817 -- Call Get_Reference to know the ultimate extending project of
6818 -- the source. Call it with verbosity default to avoid verbose
6821 Current_Verbosity
:= Default
;
6822 Prj
.Env
.Get_Reference
6823 (Source_File_Name
=> Source_File_Name
,
6825 In_Tree
=> Project_Tree
,
6827 Current_Verbosity
:= Saved_Verbosity
;
6829 -- If this source is in a project, check that the ALI file is in
6830 -- its object directory. If it is not, return False, so that the
6831 -- ALI file will not be skipped.
6833 if Project
/= No_Project
then
6835 Object_Directory
: constant String :=
6839 Object_Directory
.Display_Name
));
6841 Olast
: Natural := Object_Directory
'Last;
6843 Lib_File_Directory
: constant String :=
6844 Normalize_Pathname
(Dir_Name
6845 (Get_Name_String
(Full_Lib_File
)));
6847 Llast
: Natural := Lib_File_Directory
'Last;
6850 -- For directories, Normalize_Pathname may or may not put
6851 -- a directory separator at the end, depending on its input.
6852 -- Remove any last directory separator before comparison.
6853 -- Returns True only if the two directories are the same.
6855 if Object_Directory
(Olast
) = Directory_Separator
then
6859 if Lib_File_Directory
(Llast
) = Directory_Separator
then
6863 return Object_Directory
(Object_Directory
'First .. Olast
) =
6864 Lib_File_Directory
(Lib_File_Directory
'First .. Llast
);
6870 -- When the source is not in a project file, always return True
6873 end Is_In_Object_Directory
;
6880 (ALI_File
: File_Name_Type
;
6881 Args
: Argument_List
;
6882 Success
: out Boolean)
6884 Link_Args
: Argument_List
(1 .. Args
'Length + 1);
6887 Get_Name_String
(ALI_File
);
6888 Link_Args
(1) := new String'(Name_Buffer (1 .. Name_Len));
6890 Link_Args (2 .. Args'Length + 1) := Args;
6892 GNAT.OS_Lib.Normalize_Arguments (Link_Args);
6894 Display (Gnatlink.all, Link_Args);
6896 if Gnatlink_Path = null then
6897 Make_Failed ("error, unable to locate " & Gnatlink.all);
6900 GNAT.OS_Lib.Spawn (Gnatlink_Path.all, Link_Args, Success);
6903 ---------------------------
6904 -- List_Bad_Compilations --
6905 ---------------------------
6907 procedure List_Bad_Compilations is
6909 if not No_Exit_Message then
6910 for J in Bad_Compilation.First .. Bad_Compilation.Last loop
6911 if Bad_Compilation.Table (J).File = No_File then
6913 elsif not Bad_Compilation.Table (J).Found then
6914 Inform (Bad_Compilation.Table (J).File, "not found");
6916 Inform (Bad_Compilation.Table (J).File, "compilation error");
6920 end List_Bad_Compilations;
6926 procedure List_Depend is
6927 Lib_Name : File_Name_Type;
6928 Obj_Name : File_Name_Type;
6929 Src_Name : File_Name_Type;
6933 Line_Size : constant := 77;
6936 Set_Standard_Output;
6938 for A in ALIs.First .. ALIs.Last loop
6939 Lib_Name := ALIs.Table (A).Afile;
6941 -- We have to provide the full library file name in In_Place_Mode
6943 if In_Place_Mode then
6944 Lib_Name := Full_Lib_File_Name (Lib_Name);
6947 Obj_Name := Object_File_Name (Lib_Name);
6948 Write_Name (Obj_Name);
6951 Get_Name_String (Obj_Name);
6953 Line_Pos := Len + 2;
6955 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
6956 Src_Name := Sdep.Table (D).Sfile;
6958 if Is_Internal_File_Name (Src_Name)
6959 and then not Check_Readonly_Files
6963 if not Quiet_Output then
6964 Src_Name := Full_Source_Name (Src_Name);
6967 Get_Name_String (Src_Name);
6970 if Line_Pos + Len + 1 > Line_Size then
6976 Line_Pos := Line_Pos + Len + 1;
6979 Write_Name (Src_Name);
6986 if not Commands_To_Stdout then
6995 procedure Make_Failed (S : String) is
6997 Fail_Program (Project_Tree, S);
7000 --------------------
7001 -- Mark_Directory --
7002 --------------------
7004 procedure Mark_Directory
7006 Mark : Lib_Mark_Type;
7007 On_Command_Line : Boolean)
7012 function Base_Directory return String;
7013 -- If Dir comes from the command line, empty string (relative paths are
7014 -- resolved with respect to the current directory), else return the main
7015 -- project's directory.
7017 --------------------
7018 -- Base_Directory --
7019 --------------------
7021 function Base_Directory return String is
7023 if On_Command_Line then
7026 return Get_Name_String (Main_Project.Directory.Display_Name);
7030 Real_Path : constant String := Normalize_Pathname (Dir, Base_Directory);
7032 -- Start of processing for Mark_Directory
7037 if Real_Path'Length = 0 then
7038 Add_Str_To_Name_Buffer (Dir);
7041 Add_Str_To_Name_Buffer (Real_Path);
7044 -- Last character is supposed to be a directory separator
7046 if not Is_Directory_Separator (Name_Buffer (Name_Len)) then
7047 Add_Char_To_Name_Buffer (Directory_Separator);
7050 -- Add flags to the already existing flags
7053 B := Get_Name_Table_Byte (N);
7054 Set_Name_Table_Byte (N, B or Mark);
7057 ----------------------
7058 -- Process_Multilib --
7059 ----------------------
7061 procedure Process_Multilib (Env : in out Prj.Tree.Environment) is
7062 Output_FD : File_Descriptor;
7063 Output_Name : String_Access;
7064 Arg_Index : Natural := 0;
7065 Success : Boolean := False;
7066 Return_Code : Integer := 0;
7067 Multilib_Gcc_Path : String_Access;
7068 Multilib_Gcc : String_Access;
7069 N_Read : Integer := 0;
7070 Line : String (1 .. 1000);
7071 Args : Argument_List (1 .. N_M_Switch + 1);
7074 pragma Assert (N_M_Switch > 0 and RTS_Specified = null);
7076 -- In case we detected a multilib switch and the user has not
7077 -- manually specified a specific RTS we emulate the following command:
7078 -- gnatmake $FLAGS --RTS=$(gcc -print-multi-directory $FLAGS)
7080 -- First select the flags which might have an impact on multilib
7081 -- processing. Note that this is an heuristic selection and it
7082 -- will need to be maintained over time. The condition has to
7083 -- be kept synchronized with N_M_Switch counting in Scan_Make_Arg.
7085 for Next_Arg in 1 .. Argument_Count loop
7087 Argv : constant String := Argument (Next_Arg);
7091 and then Argv (1) = '-'
7092 and then Argv (2) = 'm
'
7093 and then Argv /= "-margs"
7095 -- Ignore -mieee to avoid spawning an extra gcc in this case
7097 and then Argv /= "-mieee"
7099 Arg_Index := Arg_Index + 1;
7100 Args (Arg_Index) := new String'(Argv
);
7105 pragma Assert
(Arg_Index
= N_M_Switch
);
7107 Args
(Args
'Last) := new String'("-print-multi-directory");
7109 -- Call the GCC driver with the collected flags and save its
7110 -- output. Alternate design would be to link in gnatmake the
7111 -- relevant part of the GCC driver.
7113 if Saved_Gcc /= null then
7114 Multilib_Gcc := Saved_Gcc;
7116 Multilib_Gcc := Gcc;
7119 Multilib_Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Multilib_Gcc.all);
7121 Create_Temp_Output_File (Output_FD, Output_Name);
7123 if Output_FD = Invalid_FD then
7128 (Multilib_Gcc_Path.all, Args, Output_FD, Return_Code, False);
7131 if Return_Code /= 0 then
7135 -- Parse the GCC driver output which is a single line, removing CR/LF
7137 Output_FD := Open_Read (Output_Name.all, Binary);
7139 if Output_FD = Invalid_FD then
7143 N_Read := Read (Output_FD, Line (1)'Address, Line'Length);
7145 Delete_File (Output_Name.all, Success);
7147 for J in reverse 1 .. N_Read loop
7148 if Line (J) = ASCII.CR or else Line (J) = ASCII.LF then
7149 N_Read := N_Read - 1;
7155 -- In case the standard RTS is selected do nothing
7157 if N_Read = 0 or else Line (1 .. N_Read) = "." then
7161 -- Otherwise add -margs --RTS=output
7163 Scan_Make_Arg (Env, "-margs", And_Save => True);
7164 Scan_Make_Arg (Env, "--RTS=" & Line (1 .. N_Read), And_Save => True);
7165 end Process_Multilib;
7167 -----------------------------
7168 -- Recursive_Compute_Depth --
7169 -----------------------------
7171 procedure Recursive_Compute_Depth (Project : Project_Id) is
7172 use Project_Boolean_Htable;
7173 Seen : Project_Boolean_Htable.Instance := Project_Boolean_Htable.Nil;
7175 procedure Recurse (Prj : Project_Id; Depth : Natural);
7176 -- Recursive procedure that does the work, keeping track of the depth
7182 procedure Recurse (Prj : Project_Id; Depth : Natural) is
7183 List : Project_List;
7187 if Prj.Depth >= Depth or else Get (Seen, Prj) then
7191 -- We need a test to avoid infinite recursions with limited withs:
7192 -- If we have A -> B -> A, then when set level of A to n, we try and
7193 -- set level of B to n+1, and then level of A to n + 2, ...
7195 Set (Seen, Prj, True);
7199 -- Visit each imported project
7201 List := Prj.Imported_Projects;
7202 while List /= null loop
7203 Proj := List.Project;
7205 Recurse (Prj => Proj, Depth => Depth + 1);
7208 -- We again allow changing the depth of this project later on if it
7209 -- is in fact imported by a lower-level project.
7211 Set (Seen, Prj, False);
7214 Proj : Project_List;
7216 -- Start of processing for Recursive_Compute_Depth
7219 Proj := Project_Tree.Projects;
7220 while Proj /= null loop
7221 Proj.Project.Depth := 0;
7225 Recurse (Project, Depth => 1);
7227 end Recursive_Compute_Depth;
7229 -------------------------------
7230 -- Report_Compilation_Failed --
7231 -------------------------------
7233 procedure Report_Compilation_Failed is
7235 Fail_Program (Project_Tree, "");
7236 end Report_Compilation_Failed;
7238 ------------------------
7239 -- Sigint_Intercepted --
7240 ------------------------
7242 procedure Sigint_Intercepted is
7245 Write_Line ("*** Interrupted ***");
7247 -- Send SIGINT to all outstanding compilation processes spawned
7249 for J in 1 .. Outstanding_Compiles loop
7250 Kill (Running_Compile (J).Pid, Hard_Kill => False);
7253 Finish_Program (Project_Tree, E_No_Compile);
7254 end Sigint_Intercepted;
7260 procedure Scan_Make_Arg
7261 (Env : in out Prj.Tree.Environment;
7268 Gnatmake_Switch_Found := True;
7270 pragma Assert (Argv'First = 1);
7272 if Argv'Length = 0 then
7276 -- If the previous switch has set the Project_File_Name_Present flag
7277 -- (that is we have seen a -P alone), then the next argument is the name
7278 -- of the project file.
7280 if Project_File_Name_Present and then Project_File_Name = null then
7281 if Argv (1) = '-' then
7282 Make_Failed ("project file name missing after -P");
7285 Project_File_Name_Present := False;
7286 Project_File_Name := new String'(Argv
);
7289 -- If the previous switch has set the Output_File_Name_Present flag
7290 -- (that is we have seen a -o), then the next argument is the name of
7291 -- the output executable.
7293 elsif Output_File_Name_Present
7294 and then not Output_File_Name_Seen
7296 Output_File_Name_Seen
:= True;
7298 if Argv
(1) = '-' then
7299 Make_Failed
("output file name missing after -o");
7302 Add_Switch
("-o", Linker
, And_Save
=> And_Save
);
7303 Add_Switch
(Executable_Name
(Argv
), Linker
, And_Save
=> And_Save
);
7306 -- If the previous switch has set the Object_Directory_Present flag
7307 -- (that is we have seen a -D), then the next argument is the path name
7308 -- of the object directory.
7310 elsif Object_Directory_Present
7311 and then not Object_Directory_Seen
7313 Object_Directory_Seen
:= True;
7315 if Argv
(1) = '-' then
7316 Make_Failed
("object directory path name missing after -D");
7318 elsif not Is_Directory
(Argv
) then
7319 Make_Failed
("cannot find object directory """ & Argv
& """");
7322 -- Record the object directory. Make sure it ends with a directory
7326 Norm
: constant String := Normalize_Pathname
(Argv
);
7329 if Norm
(Norm
'Last) = Directory_Separator
then
7330 Object_Directory_Path
:= new String'(Norm);
7332 Object_Directory_Path :=
7333 new String'(Norm
& Directory_Separator
);
7336 Add_Lib_Search_Dir
(Norm
);
7338 -- Specify the object directory to the binder
7340 Add_Switch
("-aO" & Norm
, Binder
, And_Save
=> And_Save
);
7345 -- Then check if we are dealing with -cargs/-bargs/-largs/-margs. These
7346 -- options are taken as is when found in package Compiler, Binder or
7347 -- Linker of the main project file.
7349 elsif (And_Save
or else Program_Args
= None
)
7350 and then (Argv
= "-bargs" or else
7351 Argv
= "-cargs" or else
7352 Argv
= "-largs" or else
7356 when 'c' => Program_Args
:= Compiler
;
7357 when 'b' => Program_Args
:= Binder
;
7358 when 'l' => Program_Args
:= Linker
;
7359 when 'm' => Program_Args
:= None
;
7362 raise Program_Error
;
7365 -- A special test is needed for the -o switch within a -largs since that
7366 -- is another way to specify the name of the final executable.
7368 elsif Program_Args
= Linker
and then Argv
= "-o" then
7370 ("switch -o not allowed within a -largs. Use -o directly.");
7372 -- Check to see if we are reading switches after a -cargs, -bargs or
7373 -- -largs switch. If so, save it.
7375 elsif Program_Args
/= None
then
7377 -- Check to see if we are reading -I switches in order to take into
7378 -- account in the src & lib search directories.
7380 if Argv
'Length > 2 and then Argv
(1 .. 2) = "-I" then
7381 if Argv
(3 .. Argv
'Last) = "-" then
7382 Look_In_Primary_Dir
:= False;
7384 elsif Program_Args
= Compiler
then
7385 if Argv
(3 .. Argv
'Last) /= "-" then
7386 Add_Source_Search_Dir
(Argv
(3 .. Argv
'Last), And_Save
);
7389 elsif Program_Args
= Binder
then
7390 Add_Library_Search_Dir
(Argv
(3 .. Argv
'Last), And_Save
);
7394 Add_Switch
(Argv
, Program_Args
, And_Save
=> And_Save
);
7396 -- Make sure that all significant switches -m on the command line
7400 and then Argv
(1 .. 2) = "-m"
7401 and then Argv
/= "-mieee"
7403 N_M_Switch
:= N_M_Switch
+ 1;
7406 -- Handle non-default compiler, binder, linker, and handle --RTS switch
7408 elsif Argv
'Length > 2 and then Argv
(1 .. 2) = "--" then
7410 and then Argv
(1 .. 6) = "--GCC="
7413 Program_Args
: constant Argument_List_Access
:=
7414 Argument_String_To_List
7415 (Argv
(7 .. Argv
'Last));
7419 Saved_Gcc
:= new String'(Program_Args.all (1).all);
7421 Gcc := new String'(Program_Args
.all (1).all);
7424 for J
in 2 .. Program_Args
.all'Last loop
7426 (Program_Args
.all (J
).all, Compiler
, And_Save
=> And_Save
);
7430 elsif Argv
'Length > 11
7431 and then Argv
(1 .. 11) = "--GNATBIND="
7434 Program_Args
: constant Argument_List_Access
:=
7435 Argument_String_To_List
7436 (Argv
(12 .. Argv
'Last));
7440 Saved_Gnatbind
:= new String'(Program_Args.all (1).all);
7442 Gnatbind := new String'(Program_Args
.all (1).all);
7445 for J
in 2 .. Program_Args
.all'Last loop
7447 (Program_Args
.all (J
).all, Binder
, And_Save
=> And_Save
);
7451 elsif Argv
'Length > 11
7452 and then Argv
(1 .. 11) = "--GNATLINK="
7455 Program_Args
: constant Argument_List_Access
:=
7456 Argument_String_To_List
7457 (Argv
(12 .. Argv
'Last));
7460 Saved_Gnatlink
:= new String'(Program_Args.all (1).all);
7462 Gnatlink := new String'(Program_Args
.all (1).all);
7465 for J
in 2 .. Program_Args
.all'Last loop
7466 Add_Switch
(Program_Args
.all (J
).all, Linker
);
7470 elsif Argv
'Length >= 5 and then
7471 Argv
(1 .. 5) = "--RTS"
7473 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
7474 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
7476 if Argv
'Length <= 6 or else Argv
(6) /= '=' then
7477 Make_Failed
("missing path for --RTS");
7480 -- Check that this is the first time we see this switch or
7481 -- if it is not the first time, the same path is specified.
7483 if RTS_Specified
= null then
7484 RTS_Specified
:= new String'(Argv (7 .. Argv'Last));
7486 elsif RTS_Specified.all /= Argv (7 .. Argv'Last) then
7487 Make_Failed ("--RTS cannot be specified multiple times");
7490 -- Valid --RTS switch
7497 Src_Path_Name : constant String_Ptr :=
7499 (Argv (7 .. Argv'Last), Include);
7501 Lib_Path_Name : constant String_Ptr :=
7503 (Argv (7 .. Argv'Last), Objects);
7506 if Src_Path_Name /= null
7507 and then Lib_Path_Name /= null
7509 -- Set RTS_*_Path_Name variables, so that correct direct-
7510 -- ories will be set when Osint.Add_Default_Search_Dirs
7513 RTS_Src_Path_Name := Src_Path_Name;
7514 RTS_Lib_Path_Name := Lib_Path_Name;
7516 elsif Src_Path_Name = null
7517 and then Lib_Path_Name = null
7520 ("RTS path not valid: missing adainclude and adalib "
7523 elsif Src_Path_Name = null then
7525 ("RTS path not valid: missing adainclude directory");
7527 elsif Lib_Path_Name = null then
7529 ("RTS path not valid: missing adalib directory");
7534 elsif Argv'Length > Source_Info_Option'Length
7535 and then Argv (1 .. Source_Info_Option'Length) = Source_Info_Option
7537 Project_Tree.Source_Info_File_Name :=
7538 new String'(Argv
(Source_Info_Option
'Length + 1 .. Argv
'Last));
7540 elsif Argv
'Length >= 8 and then Argv
(1 .. 8) = "--param=" then
7541 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
7542 Add_Switch
(Argv
, Linker
, And_Save
=> And_Save
);
7544 elsif Argv
= Create_Map_File_Switch
then
7545 Map_File
:= new String'("");
7547 elsif Argv'Length > Create_Map_File_Switch'Length + 1
7549 Argv (1 .. Create_Map_File_Switch'Length) = Create_Map_File_Switch
7551 Argv (Create_Map_File_Switch'Length + 1) = '='
7555 (Argv
(Create_Map_File_Switch
'Length + 2 .. Argv
'Last));
7558 Scan_Make_Switches
(Env
, Argv
, Success
);
7561 -- If we have seen a regular switch process it
7563 elsif Argv
(1) = '-' then
7564 if Argv
'Length = 1 then
7565 Make_Failed
("switch character cannot be followed by a blank");
7567 -- Incorrect switches that should start with "--"
7569 elsif (Argv
'Length > 5 and then Argv
(1 .. 5) = "-RTS=")
7570 or else (Argv
'Length > 5 and then Argv
(1 .. 5) = "-GCC=")
7571 or else (Argv
'Length > 8 and then Argv
(1 .. 7) = "-param=")
7572 or else (Argv
'Length > 10 and then Argv
(1 .. 10) = "-GNATLINK=")
7573 or else (Argv
'Length > 10 and then Argv
(1 .. 10) = "-GNATBIND=")
7575 Make_Failed
("option " & Argv
& " should start with '--'");
7579 elsif Argv
(2 .. Argv
'Last) = "I-" then
7580 Look_In_Primary_Dir
:= False;
7582 -- Forbid -?- or -??- where ? is any character
7584 elsif (Argv
'Length = 3 and then Argv
(3) = '-')
7585 or else (Argv
'Length = 4 and then Argv
(4) = '-')
7588 ("trailing ""-"" at the end of " & Argv
& " forbidden.");
7592 elsif Argv
(2) = 'I' then
7593 Add_Source_Search_Dir
(Argv
(3 .. Argv
'Last), And_Save
);
7594 Add_Library_Search_Dir
(Argv
(3 .. Argv
'Last), And_Save
);
7595 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
7596 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
7598 -- -aIdir (to gcc this is like a -I switch)
7600 elsif Argv
'Length >= 3 and then Argv
(2 .. 3) = "aI" then
7601 Add_Source_Search_Dir
(Argv
(4 .. Argv
'Last), And_Save
);
7603 ("-I" & Argv
(4 .. Argv
'Last), Compiler
, And_Save
=> And_Save
);
7604 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
7608 elsif Argv
'Length >= 3 and then Argv
(2 .. 3) = "aO" then
7609 Add_Library_Search_Dir
(Argv
(4 .. Argv
'Last), And_Save
);
7610 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
7612 -- -aLdir (to gnatbind this is like a -aO switch)
7614 elsif Argv
'Length >= 3 and then Argv
(2 .. 3) = "aL" then
7615 Mark_Directory
(Argv
(4 .. Argv
'Last), Ada_Lib_Dir
, And_Save
);
7616 Add_Library_Search_Dir
(Argv
(4 .. Argv
'Last), And_Save
);
7618 ("-aO" & Argv
(4 .. Argv
'Last), Binder
, And_Save
=> And_Save
);
7622 elsif Argv
'Length >= 13 and then Argv
(2 .. 13) = "aamp_target=" then
7623 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
7625 -- Set the aamp_target environment variable so that the binder and
7626 -- linker will use the proper target library. This is consistent
7627 -- with how things work when -aamp_target is passed on the command
7628 -- line to gnaampmake.
7630 Setenv
("aamp_target", Argv
(14 .. Argv
'Last));
7632 -- -Adir (to gnatbind this is like a -aO switch, to gcc like a -I)
7634 elsif Argv
(2) = 'A' then
7635 Mark_Directory
(Argv
(3 .. Argv
'Last), Ada_Lib_Dir
, And_Save
);
7636 Add_Source_Search_Dir
(Argv
(3 .. Argv
'Last), And_Save
);
7637 Add_Library_Search_Dir
(Argv
(3 .. Argv
'Last), And_Save
);
7639 ("-I" & Argv
(3 .. Argv
'Last), Compiler
, And_Save
=> And_Save
);
7641 ("-aO" & Argv
(3 .. Argv
'Last), Binder
, And_Save
=> And_Save
);
7645 elsif Argv
(2) = 'L' then
7646 Add_Switch
(Argv
, Linker
, And_Save
=> And_Save
);
7648 -- For -gxxx, -pg, -mxxx, -fxxx, -Oxxx, pass the switch to both the
7649 -- compiler and the linker (except for -gnatxxx which is only for the
7650 -- compiler). Some of the -mxxx (for example -m64) and -fxxx (for
7651 -- example -ftest-coverage for gcov) need to be used when compiling
7652 -- the binder generated files, and using all these gcc switches for
7653 -- them should not be a problem. Pass -Oxxx to the linker for LTO.
7656 (Argv
(2) = 'g' and then (Argv
'Last < 5
7657 or else Argv
(2 .. 5) /= "gnat"))
7658 or else Argv
(2 .. Argv
'Last) = "pg"
7659 or else (Argv
(2) = 'm' and then Argv
'Last > 2)
7660 or else (Argv
(2) = 'f' and then Argv
'Last > 2)
7661 or else Argv
(2) = 'O'
7663 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
7664 Add_Switch
(Argv
, Linker
, And_Save
=> And_Save
);
7666 -- The following condition has to be kept synchronized with
7667 -- the Process_Multilib one.
7670 and then Argv
/= "-mieee"
7672 N_M_Switch
:= N_M_Switch
+ 1;
7675 -- -C=<mapping file>
7677 elsif Argv
'Last > 2 and then Argv
(2) = 'C' then
7679 if Argv
(3) /= '=' or else Argv
'Last <= 3 then
7680 Make_Failed
("illegal switch " & Argv
);
7683 Gnatmake_Mapping_File
:= new String'(Argv (4 .. Argv'Last));
7688 elsif Argv'Last = 2 and then Argv (2) = 'D
' then
7689 if Project_File_Name /= null then
7691 ("-D cannot be used in conjunction with a project file");
7694 Scan_Make_Switches (Env, Argv, Success);
7699 elsif Argv (2) = 'd
' and then Argv'Last = 2 then
7700 Display_Compilation_Progress := True;
7704 elsif Argv'Last = 2 and then Argv (2) = 'i
' then
7705 if Project_File_Name /= null then
7707 ("-i cannot be used in conjunction with a project file");
7709 Scan_Make_Switches (Env, Argv, Success);
7712 -- -j (need to save the result)
7714 elsif Argv (2) = 'j
' then
7715 Scan_Make_Switches (Env, Argv, Success);
7718 Saved_Maximum_Processes := Maximum_Processes;
7723 elsif Argv (2) = 'm
' and then Argv'Last = 2 then
7724 Minimal_Recompilation := True;
7728 elsif Argv (2) = 'u
' and then Argv'Last = 2 then
7729 Unique_Compile := True;
7730 Compile_Only := True;
7731 Do_Bind_Step := False;
7732 Do_Link_Step := False;
7736 elsif Argv (2) = 'U
'
7737 and then Argv'Last = 2
7739 Unique_Compile_All_Projects := True;
7740 Unique_Compile := True;
7741 Compile_Only := True;
7742 Do_Bind_Step := False;
7743 Do_Link_Step := False;
7745 -- -Pprj or -P prj (only once, and only on the command line)
7747 elsif Argv (2) = 'P
' then
7748 if Project_File_Name /= null then
7749 Make_Failed ("cannot have several project files specified");
7751 elsif Object_Directory_Path /= null then
7753 ("-D cannot be used in conjunction with a project file");
7755 elsif In_Place_Mode then
7757 ("-i cannot be used in conjunction with a project file");
7759 elsif not And_Save then
7761 -- It could be a tool other than gnatmake (e.g. gnatdist)
7762 -- or a -P switch inside a project file.
7765 ("either the tool is not ""project-aware"" or "
7766 & "a project file is specified inside a project file");
7768 elsif Argv'Last = 2 then
7770 -- -P is used alone: the project file name is the next option
7772 Project_File_Name_Present := True;
7775 Project_File_Name := new String'(Argv
(3 .. Argv
'Last));
7778 -- -vPx (verbosity of the parsing of the project files)
7780 elsif Argv
'Length >= 3 and then Argv
(2 .. 3) = "vP" then
7781 if Argv
'Last /= 4 or else Argv
(4) not in '0' .. '2' then
7783 ("invalid verbosity level " & Argv
(4 .. Argv
'Last));
7788 Current_Verbosity
:= Prj
.Default
;
7790 Current_Verbosity
:= Prj
.Medium
;
7792 Current_Verbosity
:= Prj
.High
;
7798 -- -Xext=val (External assignment)
7800 elsif Argv
(2) = 'X'
7801 and then Is_External_Assignment
(Env
, Argv
)
7803 -- Is_External_Assignment has side effects when it returns True
7807 -- If -gnath is present, then generate the usage information right
7808 -- now and do not pass this option on to the compiler calls.
7810 elsif Argv
= "-gnath" then
7813 -- If -gnatc is specified, make sure the bind and link steps are not
7816 elsif Argv
'Length >= 6 and then Argv
(2 .. 6) = "gnatc" then
7818 -- If -gnatc is specified, make sure the bind and link steps are
7821 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
7822 Operating_Mode
:= Check_Semantics
;
7823 Check_Object_Consistency
:= False;
7825 -- Except in CodePeer mode (set by -gnatcC), where we do want to
7826 -- call bind/link in CodePeer mode (-P switch).
7828 if Argv
'Last >= 7 and then Argv
(7) = 'C' then
7829 CodePeer_Mode
:= True;
7831 Compile_Only
:= True;
7832 Do_Bind_Step
:= False;
7833 Do_Link_Step
:= False;
7836 -- If -gnatA is specified, make sure that gnat.adc is never read
7838 elsif Argv
'Length >= 6 and then Argv
(2 .. 6) = "gnatA" then
7839 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
7840 Opt
.Config_File
:= False;
7842 elsif Argv
(2 .. Argv
'Last) = "nostdlib" then
7844 -- Pass -nstdlib to gnatbind and gnatlink
7847 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
7848 Add_Switch
(Argv
, Linker
, And_Save
=> And_Save
);
7850 elsif Argv
(2 .. Argv
'Last) = "nostdinc" then
7852 -- Pass -nostdinc to the Compiler and to gnatbind
7855 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
7856 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
7858 -- All other switches are processed by Scan_Make_Switches. If the
7859 -- call returns with Gnatmake_Switch_Found = False, then the switch
7860 -- is passed to the compiler.
7863 Scan_Make_Switches
(Env
, Argv
, Gnatmake_Switch_Found
);
7865 if not Gnatmake_Switch_Found
then
7866 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
7870 -- If not a switch it must be a file name
7874 Main_On_Command_Line
:= True;
7878 Mains
.Add_Main
(Argv
);
7886 function Switches_Of
7887 (Source_File
: File_Name_Type
;
7888 Project
: Project_Id
;
7889 In_Package
: Package_Id
;
7890 Allow_ALI
: Boolean) return Variable_Value
7892 Switches
: Variable_Value
;
7893 Is_Default
: Boolean;
7896 Makeutl
.Get_Switches
7897 (Source_File
=> Source_File
,
7898 Source_Lang
=> Name_Ada
,
7899 Source_Prj
=> Project
,
7900 Pkg_Name
=> Project_Tree
.Shared
.Packages
.Table
(In_Package
).Name
,
7901 Project_Tree
=> Project_Tree
,
7903 Is_Default
=> Is_Default
,
7904 Test_Without_Suffix
=> True,
7905 Check_ALI_Suffix
=> Allow_ALI
);
7915 if Usage_Needed
then
7916 Usage_Needed
:= False;
7922 -- Make sure that in case of failure, the temp files will be deleted
7924 Prj
.Com
.Fail
:= Make_Failed
'Access;
7925 MLib
.Fail
:= Make_Failed
'Access;