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
(Fname
, False) then
2948 if Check_Readonly_Files
or else Must_Compile
then
2949 Comp_Args
(Comp_Args
'First + 2 .. Comp_Last
+ 1) :=
2950 Comp_Args
(Comp_Args
'First + 1 .. Comp_Last
);
2951 Comp_Last
:= Comp_Last
+ 1;
2952 Comp_Args
(Comp_Args
'First + 1) := GNAT_Flag
;
2956 ("not allowed to compile """ &
2957 Get_Name_String
(Fname
) &
2958 """; use -a switch, or use the compiler directly with "
2959 & "the ""-gnatg"" switch");
2964 -- Now check if the file name has one of the suffixes familiar to
2965 -- the gcc driver. If this is not the case then add the ada flag
2967 -- Append systematically "-x adascil" in CodePeer mode instead, to
2968 -- force the use of gnat1scil instead of gnat1.
2970 if CodePeer_Mode
then
2971 Comp_Last
:= Comp_Last
+ 1;
2972 Comp_Args
(Comp_Last
) := Ada_Flag_1
;
2973 Comp_Last
:= Comp_Last
+ 1;
2974 Comp_Args
(Comp_Last
) := AdaSCIL_Flag
;
2976 elsif not Ada_File_Name
(S
) then
2977 Comp_Last
:= Comp_Last
+ 1;
2978 Comp_Args
(Comp_Last
) := Ada_Flag_1
;
2979 Comp_Last
:= Comp_Last
+ 1;
2980 Comp_Args
(Comp_Last
) := Ada_Flag_2
;
2983 if Source_Index
/= 0 then
2985 Num
: constant String := Source_Index
'Img;
2987 Comp_Last
:= Comp_Last
+ 1;
2988 Comp_Args
(Comp_Last
) :=
2989 new String'("-gnateI" & Num (Num'First + 1 .. Num'Last));
2993 if Source_Index /= 0
2994 or else L /= Strip_Directory (L)
2995 or else Object_Directory_Path /= null
2997 -- Build -o argument
2999 Get_Name_String (L);
3001 for J in reverse 1 .. Name_Len loop
3002 if Name_Buffer (J) = '.' then
3003 Name_Len := J + Object_Suffix'Length - 1;
3004 Name_Buffer (J .. Name_Len) := Object_Suffix;
3009 Comp_Last := Comp_Last + 1;
3010 Comp_Args (Comp_Last) := Output_Flag;
3011 Comp_Last := Comp_Last + 1;
3013 -- If an object directory was specified, prepend the object file
3014 -- name with this object directory.
3016 if Object_Directory_Path /= null then
3017 Comp_Args (Comp_Last) :=
3018 new String'(Object_Directory_Path
.all &
3019 Name_Buffer
(1 .. Name_Len
));
3022 Comp_Args
(Comp_Last
) :=
3023 new String'(Name_Buffer (1 .. Name_Len));
3027 if Create_Mapping_File and then Mapping_File_Arg /= null then
3028 Comp_Last := Comp_Last + 1;
3029 Comp_Args (Comp_Last) := new String'(Mapping_File_Arg
.all);
3032 Get_Name_String
(S
);
3034 Comp_Last
:= Comp_Last
+ 1;
3035 Comp_Args
(Comp_Last
) := new String'(Name_Buffer (1 .. Name_Len));
3037 -- Change to object directory of the project file, if necessary
3039 if Project /= No_Project then
3040 Change_To_Object_Directory (Project);
3043 GNAT.OS_Lib.Normalize_Arguments (Comp_Args (Args'First .. Comp_Last));
3045 Comp_Last := Comp_Last + 1;
3046 Comp_Args (Comp_Last) := new String'("-gnatez");
3048 Display
(Gcc
.all, Comp_Args
(Args
'First .. Comp_Last
));
3050 if Gcc_Path
= null then
3051 Make_Failed
("error, unable to locate " & Gcc
.all);
3055 GNAT
.OS_Lib
.Non_Blocking_Spawn
3056 (Gcc_Path
.all, Comp_Args
(Args
'First .. Comp_Last
));
3059 -------------------------------
3060 -- Fill_Queue_From_ALI_Files --
3061 -------------------------------
3063 procedure Fill_Queue_From_ALI_Files
is
3064 ALI_P
: ALI_Project
;
3067 Sfile
: File_Name_Type
;
3068 Sid
: Prj
.Source_Id
;
3069 Uname
: Unit_Name_Type
;
3070 Unit_Name
: Name_Id
;
3071 Uid
: Prj
.Unit_Index
;
3074 while Good_ALI_Present
loop
3075 ALI_P
:= Get_Next_Good_ALI
;
3077 Source_Index
:= Unit_Index_Of
(ALIs
.Table
(ALI_P
.ALI
).Afile
);
3079 -- If we are processing the library file corresponding to the
3080 -- main source file check if this source can be a main unit.
3082 if ALIs
.Table
(ALI
).Sfile
= Main_Source
3083 and then Source_Index
= Main_Index
3085 Main_Unit
:= ALIs
.Table
(ALI
).Main_Program
/= None
;
3088 -- The following adds the standard library (s-stalib) to the list
3089 -- of files to be handled by gnatmake: this file and any files it
3090 -- depends on are always included in every bind, even if they are
3091 -- not in the explicit dependency list. Of course, it is not added
3092 -- if Suppress_Standard_Library is True.
3094 -- However, to avoid annoying output about s-stalib.ali being read
3095 -- only, when "-v" is used, we add the standard library only when
3098 if Need_To_Check_Standard_Library
then
3099 Check_Standard_Library
;
3102 -- Now insert in the Q the unmarked source files (i.e. those which
3103 -- have never been inserted in the Q and hence never considered).
3104 -- Only do that if Unique_Compile is False.
3106 if not Unique_Compile
then
3108 ALIs
.Table
(ALI
).First_Unit
.. ALIs
.Table
(ALI
).Last_Unit
3111 Units
.Table
(J
).First_With
.. Units
.Table
(J
).Last_With
3113 Sfile
:= Withs
.Table
(K
).Sfile
;
3114 Uname
:= Withs
.Table
(K
).Uname
;
3117 -- If project files are used, find the proper source to
3118 -- compile in case Sfile is the spec but there is a body.
3120 if Main_Project
/= No_Project
then
3121 Get_Name_String
(Uname
);
3122 Name_Len
:= Name_Len
- 2;
3123 Unit_Name
:= Name_Find
;
3125 Units_Htable
.Get
(Project_Tree
.Units_HT
, Unit_Name
);
3127 if Uid
/= Prj
.No_Unit_Index
then
3128 if Uid
.File_Names
(Impl
) /= null
3129 and then not Uid
.File_Names
(Impl
).Locally_Removed
3131 Sfile
:= Uid
.File_Names
(Impl
).File
;
3132 Source_Index
:= Uid
.File_Names
(Impl
).Index
;
3133 Sid
:= Uid
.File_Names
(Impl
);
3135 elsif Uid
.File_Names
(Spec
) /= null
3136 and then not Uid
.File_Names
(Spec
).Locally_Removed
3138 Sfile
:= Uid
.File_Names
(Spec
).File
;
3139 Source_Index
:= Uid
.File_Names
(Spec
).Index
;
3140 Sid
:= Uid
.File_Names
(Spec
);
3145 Dependencies
.Append
((ALIs
.Table
(ALI
).Sfile
, Sfile
));
3147 if Is_In_Obsoleted
(Sfile
) then
3148 Executable_Obsolete
:= True;
3151 if Sfile
= No_File
then
3152 Debug_Msg
("Skipping generic:", Withs
.Table
(K
).Uname
);
3155 Source_Index
:= Unit_Index_Of
(Withs
.Table
(K
).Afile
);
3157 if not (Check_Readonly_Files
or Must_Compile
)
3158 and then Is_Internal_File_Name
(Sfile
, False)
3160 Debug_Msg
("Skipping internal file:", Sfile
);
3164 ((Format
=> Format_Gnatmake
,
3166 Project
=> ALI_P
.Project
,
3167 Unit
=> Withs
.Table
(K
).Uname
,
3168 Index
=> Source_Index
,
3176 end Fill_Queue_From_ALI_Files
;
3178 ----------------------
3179 -- Get_Mapping_File --
3180 ----------------------
3182 procedure Get_Mapping_File
(Project
: Project_Id
) is
3183 Data
: Project_Compilation_Access
;
3186 Data
:= Project_Compilation_Htable
.Get
(Project_Compilation
, Project
);
3188 -- If there is a mapping file ready to be reused, reuse it
3190 if Data
.Last_Free_Indexes
> 0 then
3191 Mfile
:= Data
.Free_Mapping_File_Indexes
(Data
.Last_Free_Indexes
);
3192 Data
.Last_Free_Indexes
:= Data
.Last_Free_Indexes
- 1;
3194 -- Otherwise, create and initialize a new one
3198 (Project
=> Project
, Data
=> Data
.all, File_Index
=> Mfile
);
3201 -- Put the name in the mapping file argument for the invocation
3204 Free
(Mapping_File_Arg
);
3206 new String'("-gnatem=" &
3207 Get_Name_String (Data.Mapping_File_Names (Mfile)));
3208 end Get_Mapping_File;
3210 -----------------------
3211 -- Get_Next_Good_ALI --
3212 -----------------------
3214 function Get_Next_Good_ALI return ALI_Project is
3218 pragma Assert (Good_ALI_Present);
3219 ALIP := Good_ALI.Table (Good_ALI.Last);
3220 Good_ALI.Decrement_Last;
3222 end Get_Next_Good_ALI;
3224 ----------------------
3225 -- Good_ALI_Present --
3226 ----------------------
3228 function Good_ALI_Present return Boolean is
3230 return Good_ALI.First <= Good_ALI.Last;
3231 end Good_ALI_Present;
3233 --------------------------------
3234 -- Must_Exit_Because_Of_Error --
3235 --------------------------------
3237 function Must_Exit_Because_Of_Error return Boolean is
3238 Data : Compilation_Data;
3242 if Bad_Compilation_Count > 0 and then not Keep_Going then
3243 while Outstanding_Compiles > 0 loop
3244 Await_Compile (Data, Success);
3247 Record_Failure (Data.Full_Source_File, Data.Source_Unit);
3255 end Must_Exit_Because_Of_Error;
3257 --------------------
3258 -- Record_Failure --
3259 --------------------
3261 procedure Record_Failure
3262 (File : File_Name_Type;
3263 Unit : Unit_Name_Type;
3264 Found : Boolean := True)
3267 Bad_Compilation.Increment_Last;
3268 Bad_Compilation.Table (Bad_Compilation.Last) := (File, Unit, Found);
3271 ---------------------
3272 -- Record_Good_ALI --
3273 ---------------------
3275 procedure Record_Good_ALI (A : ALI_Id; Project : Project_Id) is
3277 Good_ALI.Increment_Last;
3278 Good_ALI.Table (Good_ALI.Last) := (A, Project);
3279 end Record_Good_ALI;
3281 -------------------------------
3282 -- Start_Compile_If_Possible --
3283 -------------------------------
3285 function Start_Compile_If_Possible
3286 (Args : Argument_List) return Boolean
3288 In_Lib_Dir : Boolean;
3289 Need_To_Compile : Boolean;
3290 Pid : Process_Id := Invalid_Pid;
3291 Process_Created : Boolean;
3293 Source : Queue.Source_Info;
3294 Full_Source_File : File_Name_Type := No_File;
3295 Source_File_Attr : aliased File_Attributes;
3296 -- The full name of the source file and its attributes (size, ...)
3298 Lib_File : File_Name_Type;
3299 Full_Lib_File : File_Name_Type := No_File;
3300 Lib_File_Attr : aliased File_Attributes;
3301 Read_Only : Boolean := False;
3303 -- The ALI file and its attributes (size, stamp, ...)
3305 Obj_File : File_Name_Type;
3306 Obj_Stamp : Time_Stamp_Type;
3312 if not Queue.Is_Virtually_Empty and then
3313 Outstanding_Compiles < Max_Process
3315 Queue.Extract (Found, Source);
3317 -- If it is a source in a project, first look for the ALI file
3318 -- in the object directory. When the project is extending another
3319 -- the ALI file may not be found, but the source does not
3320 -- necessarily need to be compiled, as it may already be up to
3321 -- date in the project being extended. In this case, look for an
3322 -- ALI file in all the object directories, as is done when
3323 -- gnatmake is not invoked with a project file.
3325 if Source.Sid /= No_Source then
3326 Initialize_Source_Record (Source.Sid);
3328 File_Name_Type (Source.Sid.Path.Display_Name);
3329 Lib_File := Source.Sid.Dep_Name;
3330 Full_Lib_File := File_Name_Type (Source.Sid.Dep_Path);
3331 Lib_File_Attr := Unknown_Attributes;
3333 if Full_Lib_File /= No_File then
3335 FLF : constant String :=
3336 Get_Name_String (Full_Lib_File) & ASCII.NUL;
3338 if not Is_Regular_File
3339 (FLF'Address, Lib_File_Attr'Access)
3341 Full_Lib_File := No_File;
3347 if Full_Lib_File = No_File then
3348 Osint.Full_Source_Name
3350 Full_File => Full_Source_File,
3351 Attr => Source_File_Attr'Access);
3353 Lib_File := Osint.Lib_File_Name (Source.File, Source.Index);
3355 Osint.Full_Lib_File_Name
3357 Lib_File => Full_Lib_File,
3358 Attr => Lib_File_Attr);
3361 -- If source has already been compiled, executable is obsolete
3363 if Is_In_Obsoleted (Source.File) then
3364 Executable_Obsolete := True;
3367 In_Lib_Dir := Full_Lib_File /= No_File
3368 and then In_Ada_Lib_Dir (Full_Lib_File);
3370 -- Since the following requires a system call, we precompute it
3373 if not In_Lib_Dir then
3374 if Full_Lib_File /= No_File
3375 and then not (Check_Readonly_Files or else Must_Compile)
3377 Get_Name_String (Full_Lib_File);
3378 Name_Buffer (Name_Len + 1) := ASCII.NUL;
3379 Read_Only := not Is_Writable_File
3380 (Name_Buffer'Address, Lib_File_Attr'Access);
3386 -- If the library file is an Ada library skip it
3391 "is in an Ada library",
3393 Minimum_Verbosity => Opt.High);
3395 -- If the library file is a read-only library skip it, but only
3396 -- if, when using project files, this library file is in the
3397 -- right object directory (a read-only ALI file in the object
3398 -- directory of a project being extended must not be skipped).
3401 and then Is_In_Object_Directory (Source.File, Full_Lib_File)
3405 "is a read-only library",
3407 Minimum_Verbosity => Opt.High);
3409 -- The source file that we are checking cannot be located
3411 elsif Full_Source_File = No_File then
3412 Record_Failure (Source.File, Source.Unit, False);
3414 -- Source and library files can be located but are internal
3417 elsif not (Check_Readonly_Files or else Must_Compile)
3418 and then Full_Lib_File /= No_File
3419 and then Is_Internal_File_Name (Source.File, False)
3421 if Force_Compilations then
3423 ("not allowed to compile """ &
3424 Get_Name_String (Source.File) &
3425 """; use -a switch, or use the compiler directly with "
3426 & "the ""-gnatg"" switch");
3431 "is an internal library",
3433 Minimum_Verbosity => Opt.High);
3435 -- The source file that we are checking can be located
3439 (Source.File, Source.File = Main_Source, Args);
3441 -- Do nothing if project of source is externally built
3443 if Arguments_Project = No_Project
3444 or else not Arguments_Project.Externally_Built
3445 or else Must_Compile
3447 -- Don't waste any time if we have to recompile anyway
3449 Obj_Stamp := Empty_Time_Stamp;
3450 Need_To_Compile := Force_Compilations;
3452 if not Force_Compilations then
3453 Check (Source_File => Source.File,
3454 Is_Main_Source => Source.File = Main_Source,
3456 Lib_File => Lib_File,
3457 Full_Lib_File => Full_Lib_File,
3458 Lib_File_Attr => Lib_File_Attr'Access,
3459 Read_Only => Read_Only,
3462 O_Stamp => Obj_Stamp);
3463 Need_To_Compile := (ALI = No_ALI_Id);
3466 if not Need_To_Compile then
3468 -- The ALI file is up-to-date; record its Id
3470 Record_Good_ALI (ALI, Arguments_Project);
3472 -- Record the time stamp of the most recent object
3473 -- file as long as no (re)compilations are needed.
3475 if First_Compiled_File = No_File
3476 and then (Most_Recent_Obj_File = No_File
3477 or else Obj_Stamp > Most_Recent_Obj_Stamp)
3479 Most_Recent_Obj_File := Obj_File;
3480 Most_Recent_Obj_Stamp := Obj_Stamp;
3484 -- Check that switch -x has been used if a source outside
3485 -- of project files need to be compiled.
3487 if Main_Project /= No_Project
3488 and then Arguments_Project = No_Project
3489 and then not External_Unit_Compilation_Allowed
3491 Make_Failed ("external source ("
3492 & Get_Name_String (Source.File)
3493 & ") is not part of any project;"
3494 & " cannot be compiled without"
3495 & " gnatmake switch -x");
3498 -- Is this the first file we have to compile?
3500 if First_Compiled_File = No_File then
3501 First_Compiled_File := Full_Source_File;
3502 Most_Recent_Obj_File := No_File;
3504 if Do_Not_Execute then
3506 -- Exit the main loop
3512 -- Compute where the ALI file must be generated in
3513 -- In_Place_Mode (this does not require to know the
3514 -- location of the object directory).
3516 if In_Place_Mode then
3517 if Full_Lib_File = No_File then
3519 -- If the library file was not found, then save
3520 -- the library file near the source file.
3524 (Full_Source_File, Source.Index);
3525 Full_Lib_File := Lib_File;
3528 -- If the library file was found, then save the
3529 -- library file in the same place.
3531 Lib_File := Full_Lib_File;
3535 -- Start the compilation and record it. We can do this
3536 -- because there is at least one free process. This might
3537 -- change the current directory.
3539 Collect_Arguments_And_Compile
3540 (Full_Source_File => Full_Source_File,
3541 Lib_File => Lib_File,
3542 Source_Index => Source.Index,
3544 Process_Created => Process_Created);
3546 -- Compute where the ALI file will be generated (for
3547 -- cases that might require to know the current
3548 -- directory). The current directory might be changed
3549 -- when compiling other files so we cannot rely on it
3550 -- being the same to find the resulting ALI file.
3552 if not In_Place_Mode then
3554 -- Compute the expected location of the ALI file. This
3555 -- can be from several places:
3556 -- -i => in place mode. In such a case,
3557 -- Full_Lib_File has already been set above
3558 -- -D => if specified
3559 -- or defaults in current dir
3560 -- We could simply use a call similar to
3561 -- Osint.Full_Lib_File_Name (Lib_File)
3562 -- but that involves system calls and is thus slower
3564 if Object_Directory_Path /= null then
3566 Add_Str_To_Name_Buffer (Object_Directory_Path.all);
3567 Add_Str_To_Name_Buffer (Get_Name_String (Lib_File));
3568 Full_Lib_File := Name_Find;
3571 if Project_Of_Current_Object_Directory /=
3575 (Project_Of_Current_Object_Directory
3576 .Object_Directory.Display_Name);
3577 Add_Str_To_Name_Buffer
3578 (Get_Name_String (Lib_File));
3579 Full_Lib_File := Name_Find;
3582 Full_Lib_File := Lib_File;
3588 Lib_File_Attr := Unknown_Attributes;
3590 -- Make sure we could successfully start the compilation
3592 if Process_Created then
3593 if Pid = Invalid_Pid then
3594 Record_Failure (Full_Source_File, Source.Unit);
3598 Sfile => Full_Source_File,
3600 Uname => Source.Unit,
3602 Full_Lib_File => Full_Lib_File,
3603 Lib_File_Attr => Lib_File_Attr);
3611 end Start_Compile_If_Possible;
3613 -----------------------------
3614 -- Wait_For_Available_Slot --
3615 -----------------------------
3617 procedure Wait_For_Available_Slot is
3618 Compilation_OK : Boolean;
3619 Text : Text_Buffer_Ptr;
3621 Data : Compilation_Data;
3624 if Outstanding_Compiles = Max_Process
3625 or else (Queue.Is_Virtually_Empty
3626 and then not Good_ALI_Present
3627 and then Outstanding_Compiles > 0)
3629 Await_Compile (Data, Compilation_OK);
3631 if not Compilation_OK then
3632 Record_Failure (Data.Full_Source_File, Data.Source_Unit);
3635 if Compilation_OK or else Keep_Going then
3637 -- Re-read the updated library file
3640 Saved_Object_Consistency : constant Boolean :=
3641 Check_Object_Consistency;
3644 -- If compilation was not OK, or if output is not an object
3645 -- file and we don't do the bind step, don't check for
3646 -- object consistency.
3648 Check_Object_Consistency :=
3649 Check_Object_Consistency
3651 and (Output_Is_Object or Do_Bind_Step);
3654 Read_Library_Info_From_Full
3655 (Data.Full_Lib_File, Data.Lib_File_Attr'Access);
3657 -- Restore Check_Object_Consistency to its initial value
3659 Check_Object_Consistency := Saved_Object_Consistency;
3662 -- If an ALI file was generated by this compilation, scan the
3663 -- ALI file and record it.
3665 -- If the scan fails, a previous ali file is inconsistent with
3666 -- the unit just compiled.
3668 if Text /= null then
3671 (Data.Lib_File, Text, Ignore_ED => False, Err => True);
3673 if ALI = No_ALI_Id then
3675 -- Record a failure only if not already done
3677 if Compilation_OK then
3680 "incompatible ALI file, please recompile");
3682 (Data.Full_Source_File, Data.Source_Unit);
3686 Record_Good_ALI (ALI, Data.Project);
3691 -- If we could not read the ALI file that was just generated
3692 -- then there could be a problem reading either the ALI or the
3693 -- corresponding object file (if Check_Object_Consistency is
3694 -- set Read_Library_Info checks that the time stamp of the
3695 -- object file is more recent than that of the ALI). However,
3696 -- we record a failure only if not already done.
3699 if Compilation_OK and not Syntax_Only then
3702 "WARNING: ALI or object file not found after compile");
3704 if not Is_Regular_File
3705 (Get_Name_String (Name_Id (Data.Full_Lib_File)))
3707 Inform (Data.Full_Lib_File, "not found");
3710 Record_Failure (Data.Full_Source_File, Data.Source_Unit);
3715 end Wait_For_Available_Slot;
3717 -- Start of processing for Compile_Sources
3720 pragma Assert (Args'First = 1);
3722 Outstanding_Compiles := 0;
3723 Running_Compile := new Comp_Data_Arr (1 .. Max_Process);
3725 -- Package and Queue initializations
3729 if Initialize_ALI_Data then
3731 Initialize_ALI_Source;
3734 -- The following two flags affect the behavior of ALI.Set_Source_Table.
3735 -- We set Check_Source_Files to True to ensure that source file time
3736 -- stamps are checked, and we set All_Sources to False to avoid checking
3737 -- the presence of the source files listed in the source dependency
3738 -- section of an ali file (which would be a mistake since the ali file
3739 -- may be obsolete).
3741 Check_Source_Files := True;
3742 All_Sources := False;
3745 ((Format => Format_Gnatmake,
3746 File => Main_Source,
3747 Project => Main_Project,
3748 Unit => No_Unit_Name,
3749 Index => Main_Index,
3752 First_Compiled_File := No_File;
3753 Most_Recent_Obj_File := No_File;
3754 Most_Recent_Obj_Stamp := Empty_Time_Stamp;
3757 -- Keep looping until there is no more work to do (the Q is empty)
3758 -- and all the outstanding compilations have terminated.
3761 while not Queue.Is_Empty or else Outstanding_Compiles > 0 loop
3762 exit Make_Loop when Must_Exit_Because_Of_Error;
3763 exit Make_Loop when Start_Compile_If_Possible (Args);
3765 Wait_For_Available_Slot;
3767 -- ??? Should be done as soon as we add a Good_ALI, wouldn't it avoid
3768 -- the need for a list of good ALI?
3770 Fill_Queue_From_ALI_Files;
3772 if Display_Compilation_Progress then
3773 Write_Str ("completed ");
3774 Write_Int (Int (Queue.Processed));
3775 Write_Str (" out of ");
3776 Write_Int (Int (Queue.Size));
3778 Write_Int (Int ((Queue.Processed * 100) / Queue.Size));
3779 Write_Str ("%)...");
3784 Compilation_Failures := Bad_Compilation_Count;
3786 -- Compilation is finished
3788 -- Delete any temporary configuration pragma file
3790 if not Keep_Temporary_Files then
3791 Delete_Temp_Config_Files (Project_Tree);
3793 end Compile_Sources;
3795 ----------------------------------
3796 -- Configuration_Pragmas_Switch --
3797 ----------------------------------
3799 function Configuration_Pragmas_Switch
3800 (For_Project : Project_Id) return Argument_List
3802 The_Packages : Package_Id;
3803 Gnatmake : Package_Id;
3804 Compiler : Package_Id;
3806 Global_Attribute : Variable_Value := Nil_Variable_Value;
3807 Local_Attribute : Variable_Value := Nil_Variable_Value;
3809 Global_Attribute_Present : Boolean := False;
3810 Local_Attribute_Present : Boolean := False;
3812 Result : Argument_List (1 .. 3);
3813 Last : Natural := 0;
3816 Prj.Env.Create_Config_Pragmas_File
3817 (For_Project, Project_Tree);
3819 if For_Project.Config_File_Name /= No_Path then
3820 Temporary_Config_File := For_Project.Config_File_Temp;
3824 ("-gnatec=" & Get_Name_String
(For_Project
.Config_File_Name
));
3827 Temporary_Config_File
:= False;
3830 -- Check for attribute Builder'Global_Configuration_Pragmas
3832 The_Packages
:= Main_Project
.Decl
.Packages
;
3835 (Name
=> Name_Builder
,
3836 In_Packages
=> The_Packages
,
3837 Shared
=> Project_Tree
.Shared
);
3839 if Gnatmake
/= No_Package
then
3840 Global_Attribute
:= Prj
.Util
.Value_Of
3841 (Variable_Name
=> Name_Global_Configuration_Pragmas
,
3842 In_Variables
=> Project_Tree
.Shared
.Packages
.Table
3843 (Gnatmake
).Decl
.Attributes
,
3844 Shared
=> Project_Tree
.Shared
);
3845 Global_Attribute_Present
:=
3846 Global_Attribute
/= Nil_Variable_Value
3847 and then Get_Name_String
(Global_Attribute
.Value
) /= "";
3849 if Global_Attribute_Present
then
3851 Path
: constant String :=
3853 (Path_Name_Type
(Global_Attribute
.Value
),
3854 Global_Attribute
.Project
);
3856 if not Is_Regular_File
(Path
) then
3857 if Debug
.Debug_Flag_F
then
3859 ("cannot find configuration pragmas file "
3860 & File_Name
(Path
));
3863 ("cannot find configuration pragmas file " & Path
);
3868 Result
(Last
) := new String'("-gnatec=" & Path);
3873 -- Check for attribute Compiler'Local_Configuration_Pragmas
3875 The_Packages := For_Project.Decl.Packages;
3878 (Name => Name_Compiler,
3879 In_Packages => The_Packages,
3880 Shared => Project_Tree.Shared);
3882 if Compiler /= No_Package then
3883 Local_Attribute := Prj.Util.Value_Of
3884 (Variable_Name => Name_Local_Configuration_Pragmas,
3885 In_Variables => Project_Tree.Shared.Packages.Table
3886 (Compiler).Decl.Attributes,
3887 Shared => Project_Tree.Shared);
3888 Local_Attribute_Present :=
3889 Local_Attribute /= Nil_Variable_Value
3890 and then Get_Name_String (Local_Attribute.Value) /= "";
3892 if Local_Attribute_Present then
3894 Path : constant String :=
3896 (Path_Name_Type (Local_Attribute.Value),
3897 Local_Attribute.Project);
3899 if not Is_Regular_File (Path) then
3900 if Debug.Debug_Flag_F then
3902 ("cannot find configuration pragmas file "
3903 & File_Name (Path));
3907 ("cannot find configuration pragmas file " & Path);
3912 Result (Last) := new String'("-gnatec=" & Path
);
3917 return Result
(1 .. Last
);
3918 end Configuration_Pragmas_Switch
;
3924 procedure Debug_Msg
(S
: String; N
: Name_Id
) is
3926 if Debug
.Debug_Flag_W
then
3927 Write_Str
(" ... ");
3935 procedure Debug_Msg
(S
: String; N
: File_Name_Type
) is
3937 Debug_Msg
(S
, Name_Id
(N
));
3940 procedure Debug_Msg
(S
: String; N
: Unit_Name_Type
) is
3942 Debug_Msg
(S
, Name_Id
(N
));
3949 procedure Display
(Program
: String; Args
: Argument_List
) is
3951 pragma Assert
(Args
'First = 1);
3953 if Display_Executed_Programs
then
3954 Write_Str
(Program
);
3956 for J
in Args
'Range loop
3958 -- Never display -gnatea nor -gnatez
3960 if Args
(J
).all /= "-gnatea"
3962 Args
(J
).all /= "-gnatez"
3964 -- Do not display the mapping file argument automatically
3965 -- created when using a project file.
3967 if Main_Project
= No_Project
3968 or else Opt
.Keep_Temporary_Files
3969 or else Args
(J
)'Length < 8
3971 Args
(J
) (Args
(J
)'First .. Args
(J
)'First + 6) /= "-gnatem"
3973 -- When -dn is not specified, do not display the config
3974 -- pragmas switch (-gnatec) for the temporary file created
3975 -- by the project manager (always the first -gnatec switch).
3976 -- Reset Temporary_Config_File to False so that the eventual
3977 -- other -gnatec switches will be displayed.
3979 if not Opt
.Keep_Temporary_Files
3980 and then Temporary_Config_File
3981 and then Args
(J
)'Length > 7
3982 and then Args
(J
) (Args
(J
)'First .. Args
(J
)'First + 6) =
3985 Temporary_Config_File
:= False;
3987 -- Do not display the -F=mapping_file switch for gnatbind
3988 -- if -dn is not specified.
3990 elsif Opt
.Keep_Temporary_Files
3991 or else Args
(J
)'Length < 4
3993 Args
(J
) (Args
(J
)'First .. Args
(J
)'First + 2) /= "-F="
3997 -- If -df is used, only display file names, not path
4000 if Debug
.Debug_Flag_F
then
4002 Equal_Pos
: Natural;
4005 Equal_Pos
:= Args
(J
)'First - 1;
4006 for K
in Args
(J
)'Range loop
4007 if Args
(J
) (K
) = '=' then
4014 (Args
(J
) (Equal_Pos
+ 1 .. Args
(J
)'Last))
4017 (Args
(J
) (Args
(J
)'First .. Equal_Pos
));
4021 (Equal_Pos
+ 1 .. Args
(J
)'Last)));
4024 Write_Str
(Args
(J
).all);
4029 Write_Str
(Args
(J
).all);
4040 ----------------------
4041 -- Display_Commands --
4042 ----------------------
4044 procedure Display_Commands
(Display
: Boolean := True) is
4046 Display_Executed_Programs
:= Display
;
4047 end Display_Commands
;
4049 --------------------------
4050 -- Enter_Into_Obsoleted --
4051 --------------------------
4053 procedure Enter_Into_Obsoleted
(F
: File_Name_Type
) is
4054 Name
: constant String := Get_Name_String
(F
);
4056 F2
: File_Name_Type
;
4060 while First
> Name
'First
4061 and then not Is_Directory_Separator
(Name
(First
- 1))
4066 if First
/= Name
'First then
4068 Add_Str_To_Name_Buffer
(Name
(First
.. Name
'Last));
4075 Debug_Msg
("New entry in Obsoleted table:", F2
);
4076 Obsoleted
.Set
(F2
, True);
4077 end Enter_Into_Obsoleted
;
4083 procedure Linking_Phase
4084 (Non_Std_Executable
: Boolean := False;
4085 Executable
: File_Name_Type
:= No_File
;
4086 Main_ALI_File
: File_Name_Type
)
4088 Linker_Switches_Last
: constant Integer := Linker_Switches
.Last
;
4089 Path_Option
: constant String_Access
:=
4090 MLib
.Linker_Library_Path_Option
;
4091 Libraries_Present
: Boolean := False;
4095 Proj1
: Project_List
;
4098 if not Run_Path_Option
then
4099 Linker_Switches
.Increment_Last
;
4100 Linker_Switches
.Table
(Linker_Switches
.Last
) :=
4104 if Main_Project /= No_Project then
4105 Library_Paths.Set_Last (0);
4108 if MLib.Tgt.Support_For_Libraries /= Prj.None then
4110 -- Check for library projects
4112 Proj1 := Project_Tree.Projects;
4113 while Proj1 /= null loop
4114 if Proj1.Project /= Main_Project
4115 and then Proj1.Project.Library
4117 -- Add this project to table Library_Projs
4119 Libraries_Present := True;
4120 Depth := Proj1.Project.Depth;
4121 Library_Projs.Increment_Last;
4122 Current := Library_Projs.Last;
4124 -- Any project with a greater depth should be after this
4125 -- project in the list.
4127 while Current > 1 loop
4128 Proj2 := Library_Projs.Table (Current - 1);
4129 exit when Proj2.Depth <= Depth;
4130 Library_Projs.Table (Current) := Proj2;
4131 Current := Current - 1;
4134 Library_Projs.Table (Current) := Proj1.Project;
4136 -- If it is not a static library and path option is set, add
4137 -- it to the Library_Paths table.
4139 if Proj1.Project.Library_Kind /= Static
4140 and then Proj1.Project.Extended_By = No_Project
4141 and then Path_Option /= null
4143 Library_Paths.Increment_Last;
4144 Library_Paths.Table (Library_Paths.Last) :=
4147 (Proj1
.Project
.Library_Dir
.Display_Name
));
4151 Proj1
:= Proj1
.Next
;
4154 for Index
in 1 .. Library_Projs
.Last
loop
4155 if Library_Projs
.Table
(Index
).Extended_By
= No_Project
then
4156 if Library_Projs
.Table
(Index
).Library_Kind
= Static
then
4157 Linker_Switches
.Increment_Last
;
4158 Linker_Switches
.Table
(Linker_Switches
.Last
) :=
4161 (Library_Projs.Table
4162 (Index).Library_Dir.Display_Name) &
4165 (Library_Projs.Table (Index).Library_Name) &
4167 MLib.Tgt.Archive_Ext);
4170 -- Add the -L switch
4172 Linker_Switches.Increment_Last;
4173 Linker_Switches.Table (Linker_Switches.Last) :=
4175 Get_Name_String
(Library_Projs
.Table
(Index
).
4176 Library_Dir
.Display_Name
));
4178 -- Add the -l switch
4180 Linker_Switches
.Increment_Last
;
4181 Linker_Switches
.Table
(Linker_Switches
.Last
) :=
4184 (Library_Projs.Table (Index).Library_Name));
4190 if Libraries_Present then
4192 -- If Path_Option is not null, create the switch ("-Wl,-rpath,"
4193 -- or equivalent) with all the non-static library dirs plus the
4194 -- standard GNAT library dir. We do that only if Run_Path_Option
4195 -- is True (not disabled by -R switch).
4197 if Run_Path_Option and then Path_Option /= null then
4199 Option : String_Access;
4200 Length : Natural := Path_Option'Length;
4204 if MLib.Separate_Run_Path_Options then
4206 -- We are going to create one switch of the form
4207 -- "-Wl,-rpath,dir_N" for each directory to
4210 -- One switch for each library directory
4213 Library_Paths.First .. Library_Paths.Last
4215 Linker_Switches.Increment_Last;
4216 Linker_Switches.Table (Linker_Switches.Last) :=
4219 Library_Paths
.Table
(Index
).all);
4222 -- One switch for the standard GNAT library dir
4224 Linker_Switches
.Increment_Last
;
4225 Linker_Switches
.Table
(Linker_Switches
.Last
) :=
4226 new String'(Path_Option.all & MLib.Utl.Lib_Directory);
4229 -- We are going to create one switch of the form
4230 -- "-Wl,-rpath,dir_1:dir_2:dir_3"
4232 for Index in Library_Paths.First .. Library_Paths.Last
4234 -- Add the length of the library dir plus one for the
4235 -- directory separator.
4238 Length + Library_Paths.Table (Index)'Length + 1;
4241 -- Finally, add the length of the standard GNAT
4244 Length := Length + MLib.Utl.Lib_Directory'Length;
4245 Option := new String (1 .. Length);
4246 Option (1 .. Path_Option'Length) := Path_Option.all;
4247 Current := Path_Option'Length;
4249 -- Put each library dir followed by a dir
4252 for Index in Library_Paths.First .. Library_Paths.Last
4256 Current + Library_Paths.Table (Index)'Length) :=
4257 Library_Paths.Table (Index).all;
4259 Current + Library_Paths.Table (Index)'Length + 1;
4260 Option (Current) := Path_Separator;
4263 -- Finally put the standard GNAT library dir
4267 Current + MLib.Utl.Lib_Directory'Length) :=
4268 MLib.Utl.Lib_Directory;
4270 -- And add the switch to the linker switches
4272 Linker_Switches.Increment_Last;
4273 Linker_Switches.Table (Linker_Switches.Last) := Option;
4279 -- Put the object directories in ADA_OBJECTS_PATH
4281 Prj.Env.Set_Ada_Paths
4284 Including_Libraries => False,
4285 Include_Path => False);
4287 -- Check for attributes Linker'Linker_Options in projects other than
4291 Linker_Options : constant String_List :=
4292 Linker_Options_Switches
4294 Do_Fail => Make_Failed'Access,
4295 In_Tree => Project_Tree);
4297 for Option in Linker_Options'Range loop
4298 Linker_Switches.Increment_Last;
4299 Linker_Switches.Table (Linker_Switches.Last) :=
4300 Linker_Options (Option);
4305 if CodePeer_Mode then
4306 Linker_Switches.Increment_Last;
4307 Linker_Switches.Table (Linker_Switches.Last) :=
4308 new String'(CodePeer_Mode_String
);
4311 -- Add switch -M to gnatlink if builder switch --create-map-file
4312 -- has been specified.
4314 if Map_File
/= null then
4315 Linker_Switches
.Increment_Last
;
4316 Linker_Switches
.Table
(Linker_Switches
.Last
) :=
4317 new String'("-M" & Map_File.all);
4321 Args : Argument_List
4322 (Linker_Switches.First .. Linker_Switches.Last + 2);
4324 Last_Arg : Integer := Linker_Switches.First - 1;
4325 Skip : Boolean := False;
4328 -- Get all the linker switches
4330 for J in Linker_Switches.First .. Linker_Switches.Last loop
4334 elsif Non_Std_Executable
4335 and then Linker_Switches.Table (J).all = "-o"
4339 -- Here we capture and duplicate the linker argument. We
4340 -- need to do the duplication since the arguments will get
4341 -- normalized. Not doing so will result in calling normalized
4342 -- two times for the same set of arguments if gnatmake is
4343 -- passed multiple mains. This can result in the wrong
4344 -- argument being passed to the linker.
4347 Last_Arg := Last_Arg + 1;
4348 Args (Last_Arg) := new String'(Linker_Switches
.Table
(J
).all);
4352 -- If need be, add the -o switch
4354 if Non_Std_Executable
then
4355 Last_Arg
:= Last_Arg
+ 1;
4356 Args
(Last_Arg
) := new String'("-o");
4357 Last_Arg := Last_Arg + 1;
4358 Args (Last_Arg) := new String'(Get_Name_String
(Executable
));
4361 -- And invoke the linker
4364 Success
: Boolean := False;
4367 -- If gnatmake was invoked with --subdirs and no project file,
4368 -- put the executable in the subdirectory specified.
4370 if Prj
.Subdirs
/= null and then Main_Project
= No_Project
then
4371 Change_Dir
(Object_Directory_Path
.all);
4374 Link
(Main_ALI_File
,
4375 Link_With_Shared_Libgcc
.all &
4376 Args
(Args
'First .. Last_Arg
),
4380 Successful_Links
.Increment_Last
;
4381 Successful_Links
.Table
(Successful_Links
.Last
) := Main_ALI_File
;
4383 elsif Osint
.Number_Of_Files
= 1 or else not Keep_Going
then
4384 Make_Failed
("*** link failed.");
4388 Write_Line
("*** link failed");
4390 if Commands_To_Stdout
then
4391 Set_Standard_Output
;
4394 Failed_Links
.Increment_Last
;
4395 Failed_Links
.Table
(Failed_Links
.Last
) := Main_ALI_File
;
4400 Linker_Switches
.Set_Last
(Linker_Switches_Last
);
4407 procedure Binding_Phase
4408 (Stand_Alone_Libraries
: Boolean := False;
4409 Main_ALI_File
: File_Name_Type
)
4411 Args
: Argument_List
(Binder_Switches
.First
.. Binder_Switches
.Last
+ 2);
4412 -- The arguments for the invocation of gnatbind
4414 Last_Arg
: Natural := Binder_Switches
.Last
;
4415 -- Index of the last argument in Args
4417 Shared_Libs
: Boolean := False;
4418 -- Set to True when there are shared library project files or
4419 -- when gnatbind is invoked with -shared.
4421 Proj
: Project_List
;
4423 Mapping_Path
: Path_Name_Type
:= No_Path
;
4424 -- The path name of the mapping file
4427 -- Check if there are shared libraries, so that gnatbind is called with
4428 -- -shared. Check also if gnatbind is called with -shared, so that
4429 -- gnatlink is called with -shared-libgcc ensuring that the shared
4430 -- version of libgcc will be used.
4432 if Main_Project
/= No_Project
4433 and then MLib
.Tgt
.Support_For_Libraries
/= Prj
.None
4435 Proj
:= Project_Tree
.Projects
;
4436 while Proj
/= null loop
4437 if Proj
.Project
.Library
4438 and then Proj
.Project
.Library_Kind
/= Static
4440 Shared_Libs
:= True;
4441 Bind_Shared
:= Shared_Switch
'Access;
4449 -- Check now for switch -shared
4451 if not Shared_Libs
then
4452 for J
in Binder_Switches
.First
.. Last_Arg
loop
4453 if Binder_Switches
.Table
(J
).all = "-shared" then
4454 Shared_Libs
:= True;
4460 -- If shared libraries present, invoke gnatlink with
4464 Link_With_Shared_Libgcc
:= Shared_Libgcc_Switch
'Access;
4467 -- Get all the binder switches
4469 for J
in Binder_Switches
.First
.. Last_Arg
loop
4470 Args
(J
) := Binder_Switches
.Table
(J
);
4473 if Stand_Alone_Libraries
then
4474 Last_Arg
:= Last_Arg
+ 1;
4475 Args
(Last_Arg
) := Force_Elab_Flags_String
'Access;
4478 if CodePeer_Mode
then
4479 Last_Arg
:= Last_Arg
+ 1;
4480 Args
(Last_Arg
) := CodePeer_Mode_String
'Access;
4483 if Main_Project
/= No_Project
then
4485 -- Put all the source directories in ADA_INCLUDE_PATH, and all the
4486 -- object directories in ADA_OBJECTS_PATH.
4488 Prj
.Env
.Set_Ada_Paths
4489 (Project
=> Main_Project
,
4490 In_Tree
=> Project_Tree
,
4491 Including_Libraries
=> True,
4492 Include_Path
=> Use_Include_Path_File
);
4494 -- If switch -C was specified, create a binder mapping file
4496 if Create_Mapping_File
then
4497 Mapping_Path
:= Create_Binder_Mapping_File
(Project_Tree
);
4499 if Mapping_Path
/= No_Path
then
4500 Last_Arg
:= Last_Arg
+ 1;
4502 new String'("-F=" & Get_Name_String (Mapping_Path));
4507 -- If gnatmake was invoked with --subdirs and no project file, put the
4508 -- binder generated files in the subdirectory specified.
4510 if Main_Project = No_Project and then Prj.Subdirs /= null then
4511 Change_Dir (Object_Directory_Path.all);
4515 Bind (Main_ALI_File,
4516 Bind_Shared.all & Args (Args'First .. Last_Arg));
4521 -- Delete the temporary mapping file if one was created
4523 if Mapping_Path /= No_Path then
4524 Delete_Temporary_File (Project_Tree.Shared, Mapping_Path);
4527 -- And reraise the exception
4532 -- If -dn was not specified, delete the temporary mapping file
4533 -- if one was created.
4535 if Mapping_Path /= No_Path then
4536 Delete_Temporary_File (Project_Tree.Shared, Mapping_Path);
4544 procedure Library_Phase
4545 (Stand_Alone_Libraries : in out Boolean;
4546 Library_Rebuilt : in out Boolean)
4550 Proj1 : Project_List;
4552 procedure Add_To_Library_Projs (Proj : Project_Id);
4553 -- Add project Project to table Library_Projs in decreasing depth order
4555 --------------------------
4556 -- Add_To_Library_Projs --
4557 --------------------------
4559 procedure Add_To_Library_Projs (Proj : Project_Id) is
4563 Library_Projs.Increment_Last;
4564 Depth := Proj.Depth;
4566 -- Put the projects in decreasing depth order, so that
4567 -- if libA depends on libB, libB is first in order.
4569 Current := Library_Projs.Last;
4570 while Current > 1 loop
4571 Prj := Library_Projs.Table (Current - 1);
4572 exit when Prj.Depth >= Depth;
4573 Library_Projs.Table (Current) := Prj;
4574 Current := Current - 1;
4577 Library_Projs.Table (Current) := Proj;
4578 end Add_To_Library_Projs;
4580 -- Start of processing for Library_Phase
4585 -- Put in Library_Projs table all library project file ids when the
4586 -- library need to be rebuilt.
4588 Proj1 := Project_Tree.Projects;
4589 while Proj1 /= null loop
4590 if Proj1.Project.Extended_By = No_Project then
4591 if Proj1.Project.Standalone_Library /= No then
4592 Stand_Alone_Libraries := True;
4595 if Proj1.Project.Library then
4596 MLib.Prj.Check_Library
4597 (Proj1.Project, Project_Tree);
4600 if Proj1.Project.Need_To_Build_Lib then
4601 Add_To_Library_Projs (Proj1.Project);
4605 Proj1 := Proj1.Next;
4608 -- Check if importing libraries should be regenerated
4609 -- because at least an imported library will be
4610 -- regenerated or is more recent.
4612 Proj1 := Project_Tree.Projects;
4613 while Proj1 /= null loop
4614 if Proj1.Project.Library
4615 and then Proj1.Project.Extended_By = No_Project
4616 and then Proj1.Project.Library_Kind /= Static
4617 and then not Proj1.Project.Need_To_Build_Lib
4618 and then not Proj1.Project.Externally_Built
4621 List : Project_List;
4623 Rebuild : Boolean := False;
4625 Lib_Timestamp1 : constant Time_Stamp_Type :=
4626 Proj1.Project.Library_TS;
4629 List := Proj1.Project.All_Imported_Projects;
4630 while List /= null loop
4631 Proj2 := List.Project;
4633 if Proj2.Library then
4634 if Proj2.Need_To_Build_Lib
4636 (Lib_Timestamp1 < Proj2.Library_TS)
4647 Proj1.Project.Need_To_Build_Lib := True;
4648 Add_To_Library_Projs (Proj1.Project);
4653 Proj1 := Proj1.Next;
4656 -- Reset the flags Need_To_Build_Lib for the next main, to avoid
4657 -- rebuilding libraries uselessly.
4659 Proj1 := Project_Tree.Projects;
4660 while Proj1 /= null loop
4661 Proj1.Project.Need_To_Build_Lib := False;
4662 Proj1 := Proj1.Next;
4665 -- Build the libraries, if any need to be built
4667 for J in 1 .. Library_Projs.Last loop
4668 Library_Rebuilt := True;
4670 -- If a library is rebuilt, then executables are obsolete
4672 Executable_Obsolete := True;
4674 MLib.Prj.Build_Library
4675 (For_Project => Library_Projs.Table (J),
4676 In_Tree => Project_Tree,
4677 Gnatbind => Gnatbind.all,
4678 Gnatbind_Path => Gnatbind_Path,
4680 Gcc_Path => Gcc_Path);
4684 -----------------------
4685 -- Compilation_Phase --
4686 -----------------------
4688 procedure Compilation_Phase
4689 (Main_Source_File : File_Name_Type;
4690 Current_Main_Index : Int := 0;
4691 Total_Compilation_Failures : in out Natural;
4692 Stand_Alone_Libraries : in out Boolean;
4693 Executable : File_Name_Type := No_File;
4694 Is_Last_Main : Boolean;
4695 Stop_Compile : out Boolean)
4697 Args : Argument_List (1 .. Gcc_Switches.Last);
4698 First_Compiled_File : File_Name_Type;
4699 Youngest_Obj_File : File_Name_Type;
4700 Youngest_Obj_Stamp : Time_Stamp_Type;
4702 Is_Main_Unit : Boolean;
4703 -- Set True by Compile_Sources if Main_Source_File can be a main unit
4705 Compilation_Failures : Natural;
4707 Executable_Stamp : Time_Stamp_Type;
4709 Library_Rebuilt : Boolean := False;
4712 Stop_Compile := False;
4714 for J in 1 .. Gcc_Switches.Last loop
4715 Args (J) := Gcc_Switches.Table (J);
4718 -- Now we invoke Compile_Sources for the current main
4721 (Main_Source => Main_Source_File,
4723 First_Compiled_File => First_Compiled_File,
4724 Most_Recent_Obj_File => Youngest_Obj_File,
4725 Most_Recent_Obj_Stamp => Youngest_Obj_Stamp,
4726 Main_Unit => Is_Main_Unit,
4727 Main_Index => Current_Main_Index,
4728 Compilation_Failures => Compilation_Failures,
4729 Check_Readonly_Files => Check_Readonly_Files,
4730 Do_Not_Execute => Do_Not_Execute,
4731 Force_Compilations => Force_Compilations,
4732 In_Place_Mode => In_Place_Mode,
4733 Keep_Going => Keep_Going,
4734 Initialize_ALI_Data => True,
4735 Max_Process => Saved_Maximum_Processes);
4737 if Verbose_Mode then
4738 Write_Str ("End of compilation");
4742 Total_Compilation_Failures :=
4743 Total_Compilation_Failures + Compilation_Failures;
4745 if Total_Compilation_Failures /= 0 then
4746 Stop_Compile := True;
4750 -- Regenerate libraries, if there are any and if object files have been
4751 -- regenerated. Note that we skip this in CodePeer mode because we don't
4752 -- need libraries in this case, and more importantly, the object files
4753 -- may not be present.
4755 if Main_Project /= No_Project
4756 and then not CodePeer_Mode
4757 and then MLib.Tgt.Support_For_Libraries /= Prj.None
4758 and then (Do_Bind_Step
4759 or Unique_Compile_All_Projects
4760 or not Compile_Only)
4761 and then (Do_Link_Step or Is_Last_Main)
4764 (Stand_Alone_Libraries => Stand_Alone_Libraries,
4765 Library_Rebuilt => Library_Rebuilt);
4768 if List_Dependencies then
4769 if First_Compiled_File /= No_File then
4771 (First_Compiled_File,
4772 "must be recompiled. Can't generate dependence list.");
4777 elsif First_Compiled_File = No_File
4778 and then not Do_Bind_Step
4779 and then not Quiet_Output
4780 and then not Library_Rebuilt
4781 and then Osint.Number_Of_Files = 1
4783 Inform (Msg => "objects up to date.");
4784 Stop_Compile := True;
4787 elsif Do_Not_Execute and then First_Compiled_File /= No_File then
4788 Write_Name (First_Compiled_File);
4792 -- Stop after compile step if any of:
4794 -- 1) -n (Do_Not_Execute) specified
4796 -- 2) -M (List_Dependencies) specified (also sets
4797 -- Do_Not_Execute above, so this is probably superfluous).
4799 -- 3) -c (Compile_Only) specified, but not -b (Bind_Only)
4801 -- 4) Made unit cannot be a main unit
4804 or List_Dependencies
4806 or not Is_Main_Unit)
4807 and not No_Main_Subprogram
4808 and not Build_Bind_And_Link_Full_Project)
4811 Stop_Compile := True;
4815 -- If the objects were up-to-date check if the executable file is also
4816 -- up-to-date. For now always bind and link in CodePeer mode where there
4817 -- is no executable.
4819 if not CodePeer_Mode
4820 and then First_Compiled_File = No_File
4822 Executable_Stamp := File_Stamp (Executable);
4824 if not Executable_Obsolete then
4825 Executable_Obsolete := Youngest_Obj_Stamp > Executable_Stamp;
4828 if not Executable_Obsolete then
4829 for Index in reverse 1 .. Dependencies.Last loop
4830 if Is_In_Obsoleted (Dependencies.Table (Index).Depends_On) then
4831 Enter_Into_Obsoleted (Dependencies.Table (Index).This);
4835 Executable_Obsolete := Is_In_Obsoleted (Main_Source_File);
4839 if not Executable_Obsolete then
4841 -- If no Ada object files obsolete the executable, check
4842 -- for younger or missing linker files.
4844 Check_Linker_Options
4847 Youngest_Obj_Stamp);
4849 Executable_Obsolete := Youngest_Obj_File /= No_File;
4852 -- Check if any library file is more recent than the
4853 -- executable: there may be an externally built library
4854 -- file that has been modified.
4856 if not Executable_Obsolete and then Main_Project /= No_Project then
4858 Proj1 : Project_List;
4861 Proj1 := Project_Tree.Projects;
4862 while Proj1 /= null loop
4863 if Proj1.Project.Library
4864 and then Proj1.Project.Library_TS > Executable_Stamp
4866 Executable_Obsolete := True;
4867 Youngest_Obj_Stamp := Proj1.Project.Library_TS;
4869 Add_Str_To_Name_Buffer ("library ");
4870 Add_Str_To_Name_Buffer
4871 (Get_Name_String (Proj1.Project.Library_Name));
4872 Youngest_Obj_File := Name_Find;
4876 Proj1 := Proj1.Next;
4881 -- Return if the executable is up to date and otherwise
4882 -- motivate the relink/rebind.
4884 if not Executable_Obsolete then
4885 if not Quiet_Output then
4886 Inform (Executable, "up to date.");
4889 Stop_Compile := True;
4893 if Executable_Stamp (1) = ' ' then
4894 if not No_Main_Subprogram then
4895 Verbose_Msg (Executable, "missing.", Prefix => " ");
4898 elsif Youngest_Obj_Stamp (1) = ' ' then
4900 (Youngest_Obj_File, "missing.", Prefix => " ");
4902 elsif Youngest_Obj_Stamp > Executable_Stamp then
4905 "(" & String (Youngest_Obj_Stamp) & ") newer than",
4907 "(" & String (Executable_Stamp) & ")");
4911 (Executable, "needs to be rebuilt", Prefix => " ");
4915 end Compilation_Phase;
4917 ----------------------------------------
4918 -- Resolve_Relative_Names_In_Switches --
4919 ----------------------------------------
4921 procedure Resolve_Relative_Names_In_Switches (Current_Work_Dir : String) is
4923 -- If a relative path output file has been specified, we add the
4926 for J in reverse 1 .. Saved_Linker_Switches.Last - 1 loop
4927 if Saved_Linker_Switches.Table (J).all = Output_Flag.all then
4929 Exec_File_Name : constant String :=
4930 Saved_Linker_Switches.Table (J + 1).all;
4933 if not Is_Absolute_Path (Exec_File_Name) then
4934 Get_Name_String (Main_Project.Exec_Directory.Display_Name);
4935 Add_Str_To_Name_Buffer (Exec_File_Name);
4936 Saved_Linker_Switches.Table (J + 1) :=
4937 new String'(Name_Buffer
(1 .. Name_Len
));
4945 -- If we are using a project file, for relative paths we add the
4946 -- current working directory for any relative path on the command
4947 -- line and the project directory, for any relative path in the
4951 Dir_Path
: constant String :=
4952 Get_Name_String
(Main_Project
.Directory
.Display_Name
);
4954 for J
in 1 .. Binder_Switches
.Last
loop
4955 Ensure_Absolute_Path
4956 (Binder_Switches
.Table
(J
),
4957 Do_Fail
=> Make_Failed
'Access,
4958 Parent
=> Dir_Path
, For_Gnatbind
=> True);
4961 for J
in 1 .. Saved_Binder_Switches
.Last
loop
4962 Ensure_Absolute_Path
4963 (Saved_Binder_Switches
.Table
(J
),
4964 Do_Fail
=> Make_Failed
'Access,
4965 Parent
=> Current_Work_Dir
,
4966 For_Gnatbind
=> True);
4969 for J
in 1 .. Linker_Switches
.Last
loop
4970 Ensure_Absolute_Path
4971 (Linker_Switches
.Table
(J
),
4973 Do_Fail
=> Make_Failed
'Access);
4976 for J
in 1 .. Saved_Linker_Switches
.Last
loop
4977 Ensure_Absolute_Path
4978 (Saved_Linker_Switches
.Table
(J
),
4979 Do_Fail
=> Make_Failed
'Access,
4980 Parent
=> Current_Work_Dir
);
4983 for J
in 1 .. Gcc_Switches
.Last
loop
4984 Ensure_Absolute_Path
4985 (Gcc_Switches
.Table
(J
),
4986 Do_Fail
=> Make_Failed
'Access,
4988 Including_Non_Switch
=> False);
4991 for J
in 1 .. Saved_Gcc_Switches
.Last
loop
4992 Ensure_Absolute_Path
4993 (Saved_Gcc_Switches
.Table
(J
),
4994 Parent
=> Current_Work_Dir
,
4995 Do_Fail
=> Make_Failed
'Access,
4996 Including_Non_Switch
=> False);
4999 end Resolve_Relative_Names_In_Switches
;
5001 -----------------------------------
5002 -- Queue_Library_Project_Sources --
5003 -----------------------------------
5005 procedure Queue_Library_Project_Sources
is
5007 if not Unique_Compile
5008 and then MLib
.Tgt
.Support_For_Libraries
/= Prj
.None
5011 Proj
: Project_List
;
5014 Proj
:= Project_Tree
.Projects
;
5015 while Proj
/= null loop
5016 if Proj
.Project
.Library
then
5017 Proj
.Project
.Need_To_Build_Lib
:=
5018 not MLib
.Tgt
.Library_Exists_For
5019 (Proj
.Project
, Project_Tree
)
5020 and then not Proj
.Project
.Externally_Built
;
5022 if Proj
.Project
.Need_To_Build_Lib
then
5024 -- If there is no object directory, then it will be
5025 -- impossible to build the library, so fail immediately.
5027 if Proj
.Project
.Object_Directory
= No_Path_Information
5030 ("no object files to build library for"
5032 & Get_Name_String
(Proj
.Project
.Name
)
5034 Proj
.Project
.Need_To_Build_Lib
:= False;
5037 if Verbose_Mode
then
5039 ("Library file does not exist for "
5042 (Get_Name_String
(Proj
.Project
.Name
));
5046 Insert_Project_Sources
5047 (The_Project
=> Proj
.Project
,
5048 All_Projects
=> False,
5058 end Queue_Library_Project_Sources
;
5060 ------------------------
5061 -- Compute_Executable --
5062 ------------------------
5064 procedure Compute_Executable
5065 (Main_Source_File
: File_Name_Type
;
5066 Executable
: out File_Name_Type
;
5067 Non_Std_Executable
: out Boolean)
5070 Executable
:= No_File
;
5071 Non_Std_Executable
:=
5072 Targparm
.Executable_Extension_On_Target
/= No_Name
;
5074 -- Look inside the linker switches to see if the name of the final
5075 -- executable program was specified.
5077 for J
in reverse Linker_Switches
.First
.. Linker_Switches
.Last
loop
5078 if Linker_Switches
.Table
(J
).all = Output_Flag
.all then
5079 pragma Assert
(J
< Linker_Switches
.Last
);
5081 -- We cannot specify a single executable for several main
5084 if Osint
.Number_Of_Files
> 1 then
5085 Fail
("cannot specify a single executable for several mains");
5089 Add_Str_To_Name_Buffer
(Linker_Switches
.Table
(J
+ 1).all);
5090 Executable
:= Name_Enter
;
5092 Verbose_Msg
(Executable
, "final executable");
5096 -- If the name of the final executable program was not specified then
5097 -- construct it from the main input file.
5099 if Executable
= No_File
then
5100 if Main_Project
= No_Project
then
5101 Executable
:= Executable_Name
(Strip_Suffix
(Main_Source_File
));
5104 -- If we are using a project file, we attempt to remove the body
5105 -- (or spec) termination of the main subprogram. We find it the
5106 -- naming scheme of the project file. This avoids generating an
5107 -- executable "main.2" for a main subprogram "main.2.ada", when
5108 -- the body termination is ".2.ada".
5111 Prj
.Util
.Executable_Of
5112 (Main_Project
, Project_Tree
.Shared
,
5113 Main_Source_File
, Main_Index
);
5117 if Main_Project
/= No_Project
5118 and then Main_Project
.Exec_Directory
/= No_Path_Information
5121 Exec_File_Name
: constant String := Get_Name_String
(Executable
);
5123 if not Is_Absolute_Path
(Exec_File_Name
) then
5124 Get_Name_String
(Main_Project
.Exec_Directory
.Display_Name
);
5125 Add_Str_To_Name_Buffer
(Exec_File_Name
);
5126 Executable
:= Name_Find
;
5129 Non_Std_Executable
:= True;
5132 end Compute_Executable
;
5134 -------------------------------
5135 -- Compute_Switches_For_Main --
5136 -------------------------------
5138 procedure Compute_Switches_For_Main
5139 (Main_Source_File
: in out File_Name_Type
;
5140 Root_Environment
: in out Prj
.Tree
.Environment
;
5141 Compute_Builder
: Boolean;
5142 Current_Work_Dir
: String)
5144 function Add_Global_Switches
5147 For_Builder
: Boolean;
5148 Has_Global_Compilation_Switches
: Boolean) return Boolean;
5149 -- Handles builder and global compilation switches, as read from the
5152 -------------------------
5153 -- Add_Global_Switches --
5154 -------------------------
5156 function Add_Global_Switches
5159 For_Builder
: Boolean;
5160 Has_Global_Compilation_Switches
: Boolean) return Boolean
5162 pragma Unreferenced
(For_Lang
);
5166 Program_Args
:= None
;
5167 Switch_May_Be_Passed_To_The_Compiler
:=
5168 not Has_Global_Compilation_Switches
;
5169 Scan_Make_Arg
(Root_Environment
, Switch
, And_Save
=> False);
5171 return Gnatmake_Switch_Found
5172 or else Switch_May_Be_Passed_To_The_Compiler
;
5174 Add_Switch
(Switch
, Compiler
, And_Save
=> False);
5177 end Add_Global_Switches
;
5179 procedure Do_Compute_Builder_Switches
5180 is new Makeutl
.Compute_Builder_Switches
(Add_Global_Switches
);
5182 -- Start of processing for Compute_Switches_For_Main
5185 if Main_Project
/= No_Project
then
5187 Main_Source_File_Name
: constant String :=
5188 Get_Name_String
(Main_Source_File
);
5190 Main_Unit_File_Name
: constant String :=
5191 Prj
.Env
.File_Name_Of_Library_Unit_Body
5192 (Name
=> Main_Source_File_Name
,
5193 Project
=> Main_Project
,
5194 In_Tree
=> Project_Tree
,
5195 Main_Project_Only
=> not Unique_Compile
);
5197 The_Packages
: constant Package_Id
:= Main_Project
.Decl
.Packages
;
5199 Binder_Package
: constant Prj
.Package_Id
:=
5201 (Name
=> Name_Binder
,
5202 In_Packages
=> The_Packages
,
5203 Shared
=> Project_Tree
.Shared
);
5205 Linker_Package
: constant Prj
.Package_Id
:=
5207 (Name
=> Name_Linker
,
5208 In_Packages
=> The_Packages
,
5209 Shared
=> Project_Tree
.Shared
);
5212 -- We fail if we cannot find the main source file
5214 if Main_Unit_File_Name
= "" then
5215 Make_Failed
('"' & Main_Source_File_Name
5216 & """ is not a unit of project "
5217 & Project_File_Name
.all & ".");
5220 -- Remove any directory information from the main source file
5224 Pos
: Natural := Main_Unit_File_Name
'Last;
5228 exit when Pos
< Main_Unit_File_Name
'First
5229 or else Main_Unit_File_Name
(Pos
) = Directory_Separator
;
5233 Name_Len
:= Main_Unit_File_Name
'Last - Pos
;
5235 Name_Buffer
(1 .. Name_Len
) :=
5236 Main_Unit_File_Name
(Pos
+ 1 .. Main_Unit_File_Name
'Last);
5238 Main_Source_File
:= Name_Find
;
5240 -- We only output the main source file if there is only one
5242 if Verbose_Mode
and then Osint
.Number_Of_Files
= 1 then
5243 Write_Str
("Main source file: """);
5244 Write_Str
(Main_Unit_File_Name
5245 (Pos
+ 1 .. Main_Unit_File_Name
'Last));
5250 if Compute_Builder
then
5251 Do_Compute_Builder_Switches
5252 (Project_Tree
=> Project_Tree
,
5253 Env
=> Root_Environment
,
5254 Main_Project
=> Main_Project
,
5255 Only_For_Lang
=> Name_Ada
);
5257 Resolve_Relative_Names_In_Switches
5258 (Current_Work_Dir
=> Current_Work_Dir
);
5260 -- Record current last switch index for tables Binder_Switches
5261 -- and Linker_Switches, so that these tables may be reset
5262 -- before each main, before adding switches from the project
5263 -- file and from the command line.
5265 Last_Binder_Switch
:= Binder_Switches
.Last
;
5266 Last_Linker_Switch
:= Linker_Switches
.Last
;
5269 -- Reset the tables Binder_Switches and Linker_Switches
5271 Binder_Switches
.Set_Last
(Last_Binder_Switch
);
5272 Linker_Switches
.Set_Last
(Last_Linker_Switch
);
5275 -- We now deal with the binder and linker switches. If no project
5276 -- file is used, there is nothing to do because the binder and
5277 -- linker switches are the same for all mains.
5279 -- Add binder switches from the project file for the first main
5281 if Do_Bind_Step
and then Binder_Package
/= No_Package
then
5282 if Verbose_Mode
then
5283 Write_Str
("Adding binder switches for """);
5284 Write_Str
(Main_Unit_File_Name
);
5289 (Env
=> Root_Environment
,
5290 File_Name
=> Main_Unit_File_Name
,
5291 The_Package
=> Binder_Package
,
5295 -- Add linker switches from the project file for the first main
5297 if Do_Link_Step
and then Linker_Package
/= No_Package
then
5298 if Verbose_Mode
then
5299 Write_Str
("Adding linker switches for""");
5300 Write_Str
(Main_Unit_File_Name
);
5305 (Env
=> Root_Environment
,
5306 File_Name
=> Main_Unit_File_Name
,
5307 The_Package
=> Linker_Package
,
5311 -- As we are using a project file, for relative paths we add the
5312 -- current working directory for any relative path on the command
5313 -- line and the project directory, for any relative path in the
5317 Dir_Path
: constant String :=
5318 Get_Name_String
(Main_Project
.Directory
.Display_Name
);
5321 for J
in Last_Binder_Switch
+ 1 .. Binder_Switches
.Last
loop
5322 Ensure_Absolute_Path
5323 (Binder_Switches
.Table
(J
),
5324 Do_Fail
=> Make_Failed
'Access,
5325 Parent
=> Dir_Path
, For_Gnatbind
=> True);
5328 for J
in Last_Linker_Switch
+ 1 .. Linker_Switches
.Last
loop
5329 Ensure_Absolute_Path
5330 (Linker_Switches
.Table
(J
),
5332 Do_Fail
=> Make_Failed
'Access);
5338 if not Compute_Builder
then
5340 -- Reset the tables Binder_Switches and Linker_Switches
5342 Binder_Switches
.Set_Last
(Last_Binder_Switch
);
5343 Linker_Switches
.Set_Last
(Last_Linker_Switch
);
5349 if Compute_Builder
then
5350 Display_Commands
(not Quiet_Output
);
5353 -- We now put in the Binder_Switches and Linker_Switches tables, the
5354 -- binder and linker switches of the command line that have been put in
5355 -- the Saved_ tables. If a project file was used, then the command line
5356 -- switches will follow the project file switches.
5358 for J
in 1 .. Saved_Binder_Switches
.Last
loop
5360 (Saved_Binder_Switches
.Table
(J
),
5365 for J
in 1 .. Saved_Linker_Switches
.Last
loop
5367 (Saved_Linker_Switches
.Table
(J
),
5371 end Compute_Switches_For_Main
;
5377 procedure Gnatmake
is
5378 Main_Source_File
: File_Name_Type
;
5379 -- The source file containing the main compilation unit
5381 Total_Compilation_Failures
: Natural := 0;
5383 Main_ALI_File
: File_Name_Type
;
5384 -- The ali file corresponding to Main_Source_File
5386 Executable
: File_Name_Type
:= No_File
;
5387 -- The file name of an executable
5389 Non_Std_Executable
: Boolean := False;
5390 -- Non_Std_Executable is set to True when there is a possibility that
5391 -- the linker will not choose the correct executable file name.
5393 Current_Work_Dir
: constant String_Access
:=
5394 new String'(Get_Current_Dir);
5395 -- The current working directory, used to modify some relative path
5396 -- switches on the command line when a project file is used.
5398 Current_Main_Index : Int := 0;
5399 -- If not zero, the index of the current main unit in its source file
5401 Is_First_Main : Boolean;
5402 -- Whether we are processing the first main
5404 Stand_Alone_Libraries : Boolean := False;
5405 -- Set to True when there are Stand-Alone Libraries, so that gnatbind
5406 -- is invoked with the -F switch to force checking of elaboration flags.
5408 Project_Node_Tree : Project_Node_Tree_Ref;
5410 Stop_Compile : Boolean;
5413 pragma Warnings (Off, Discard);
5415 procedure Check_Mains;
5416 -- Check that the main subprograms do exist and that they all
5417 -- belong to the same project file.
5423 procedure Check_Mains is
5424 Real_Main_Project : Project_Id := No_Project;
5429 if Mains.Number_Of_Mains (Project_Tree) = 0
5430 and then not Unique_Compile
5432 Mains.Fill_From_Project (Main_Project, Project_Tree);
5435 Mains.Complete_Mains
5436 (Root_Environment.Flags, Main_Project, Project_Tree);
5438 -- If we have multiple mains on the command line, they need not
5439 -- belong to the root project, but they must all belong to the same
5442 if not Unique_Compile then
5445 Info := Mains.Next_Main;
5446 exit when Info = No_Main_Info;
5448 Proj := Ultimate_Extending_Project_Of (Info.Project);
5450 if Real_Main_Project = No_Project then
5451 Real_Main_Project := Proj;
5452 elsif Real_Main_Project /= Proj then
5454 ("""" & Get_Name_String (Info.File) &
5455 """ is not a source of project " &
5456 Get_Name_String (Real_Main_Project.Name));
5460 if Real_Main_Project /= No_Project then
5461 Main_Project := Real_Main_Project;
5464 Debug_Output ("After checking mains, main project is",
5468 -- For all mains on the command line, make sure they were in
5469 -- osint. In particular, if the user has specified a multi-unit
5470 -- source file, the call to Complete_Mains will have expanded
5471 -- the list of mains to all its units, and we must now put them
5472 -- back on the command line.
5473 -- ??? This will not be necessary when gnatmake shares the same
5474 -- queue as gprbuild and processes the file directly on the queue.
5478 Info := Mains.Next_Main;
5479 exit when Info = No_Main_Info;
5481 if Info.Index /= 0 then
5482 Debug_Output ("Add to command line index="
5483 & Info.Index'Img, Name_Id (Info.File));
5484 Osint.Add_File (Get_Name_String (Info.File), Info.Index);
5490 -- Start of processing for Gnatmake
5492 -- This body is very long, should be broken down???
5495 Install_Int_Handler (Sigint_Intercepted'Access);
5497 Do_Compile_Step := True;
5498 Do_Bind_Step := True;
5499 Do_Link_Step := True;
5503 Make.Initialize (Project_Node_Tree, Root_Environment);
5505 Bind_Shared := No_Shared_Switch'Access;
5506 Link_With_Shared_Libgcc := No_Shared_Libgcc_Switch'Access;
5508 Failed_Links.Set_Last (0);
5509 Successful_Links.Set_Last (0);
5511 -- Special case when switch -B was specified
5513 if Build_Bind_And_Link_Full_Project then
5515 -- When switch -B is specified, there must be a project file
5517 if Main_Project = No_Project then
5518 Make_Failed ("-B cannot be used without a project file");
5520 -- No main program may be specified on the command line
5522 elsif Osint.Number_Of_Files /= 0 then
5524 ("-B cannot be used with a main specified on the command line");
5526 -- And the project file cannot be a library project file
5528 elsif Main_Project.Library then
5529 Make_Failed ("-B cannot be used for a library project file");
5532 No_Main_Subprogram := True;
5533 Insert_Project_Sources
5534 (The_Project => Main_Project,
5535 All_Projects => Unique_Compile_All_Projects,
5538 -- If there are no sources to compile, we fail
5540 if Osint.Number_Of_Files = 0 then
5541 Make_Failed ("no sources to compile");
5544 -- Specify -n for gnatbind and add the ALI files of all the
5545 -- sources, except the one which is a fake main subprogram: this
5546 -- is the one for the binder generated file and it will be
5547 -- transmitted to gnatlink. These sources are those that are in
5550 Add_Switch ("-n", Binder, And_Save => True);
5552 for J in 1 .. Queue.Size loop
5554 (Get_Name_String (Lib_File_Name (Queue.Element (J))),
5555 Binder, And_Save => True);
5559 elsif Main_Index /= 0 and then Osint.Number_Of_Files > 1 then
5560 Make_Failed ("cannot specify several mains with a multi-unit index");
5562 elsif Main_Project /= No_Project then
5564 -- If the main project file is a library project file, main(s) cannot
5565 -- be specified on the command line.
5567 if Osint.Number_Of_Files /= 0 then
5568 if Main_Project.Library
5569 and then not Unique_Compile
5570 and then ((not Make_Steps) or else Bind_Only or else Link_Only)
5573 ("cannot specify a main program "
5574 & "on the command line for a library project file");
5577 -- If no mains have been specified on the command line, and we are
5578 -- using a project file, we either find the main(s) in attribute Main
5579 -- of the main project, or we put all the sources of the project file
5583 if Main_Index /= 0 then
5584 Make_Failed ("cannot specify a multi-unit index but no main "
5585 & "on the command line");
5589 Value : String_List_Id := Main_Project.Mains;
5592 -- The attribute Main is an empty list or not specified, or
5593 -- else gnatmake was invoked with the switch "-u".
5595 if Value = Prj.Nil_String or else Unique_Compile then
5598 or not Main_Project.Library
5600 -- First make sure that the binder and the linker will
5603 Do_Bind_Step := False;
5604 Do_Link_Step := False;
5606 -- Put all the sources in the queue
5608 No_Main_Subprogram := True;
5609 Insert_Project_Sources
5610 (The_Project => Main_Project,
5611 All_Projects => Unique_Compile_All_Projects,
5614 -- If no sources to compile, then there is nothing to do
5616 if Osint.Number_Of_Files = 0 then
5617 if not Quiet_Output then
5618 Osint.Write_Program_Name;
5619 Write_Line (": no sources to compile");
5622 Finish_Program (Project_Tree, E_Success);
5627 -- The attribute Main is not an empty list. Put all the main
5628 -- subprograms in the list as if they were specified on the
5629 -- command line. However, if attribute Languages includes a
5630 -- language other than Ada, only include the Ada mains; if
5631 -- there is no Ada main, compile all sources of the project.
5634 Languages : constant Variable_Value :=
5637 Main_Project.Decl.Attributes,
5638 Project_Tree.Shared);
5640 Current : String_List_Id;
5641 Element : String_Element;
5643 Foreign_Language : Boolean := False;
5644 At_Least_One_Main : Boolean := False;
5647 -- First, determine if there is a foreign language in
5648 -- attribute Languages.
5650 if not Languages.Default then
5651 Current := Languages.Values;
5653 while Current /= Nil_String loop
5654 Element := Project_Tree.Shared.String_Elements.
5656 Get_Name_String (Element.Value);
5657 To_Lower (Name_Buffer (1 .. Name_Len));
5659 if Name_Buffer (1 .. Name_Len) /= "ada" then
5660 Foreign_Language := True;
5661 exit Look_For_Foreign;
5664 Current := Element.Next;
5665 end loop Look_For_Foreign;
5668 -- Then, find all mains, or if there is a foreign
5669 -- language, all the Ada mains.
5671 while Value /= Prj.Nil_String loop
5672 -- To know if a main is an Ada main, get its project.
5673 -- It should be the project specified on the command
5677 (Project_Tree.Shared.String_Elements.Table
5681 Main_Name : constant String :=
5683 (Project_Tree.Shared.
5685 Table (Value).Value);
5687 Proj : constant Project_Id :=
5689 (Main_Name, Main_Project, Project_Tree);
5692 if Proj = Main_Project then
5693 At_Least_One_Main := True;
5696 (Project_Tree.Shared.String_Elements.Table
5699 Project_Tree.Shared.String_Elements.Table
5702 elsif not Foreign_Language then
5705 """ is not a source of project " &
5706 Get_Name_String (Main_Project.Display_Name));
5710 Value := Project_Tree.Shared.String_Elements.Table
5714 -- If we did not get any main, it means that all mains
5715 -- in attribute Mains are in a foreign language and -B
5716 -- was not specified to gnatmake; so, we fail.
5718 if not At_Least_One_Main then
5720 ("no Ada mains, use -B to build foreign main");
5728 -- Check that each main on the command line is a source of a
5729 -- project file and, if there are several mains, each of them
5730 -- is a source of the same project file.
5735 if Verbose_Mode then
5737 Display_Version ("GNATMAKE", "1992");
5740 if Osint.Number_Of_Files = 0 then
5741 if Main_Project /= No_Project and then Main_Project.Library then
5742 if Do_Bind_Step and then Main_Project.Standalone_Library = No then
5743 Make_Failed ("only stand-alone libraries may be bound");
5746 -- Add the default search directories to be able to find libgnat
5748 Osint.Add_Default_Search_Dirs;
5750 -- And bind and or link the library
5752 MLib.Prj.Build_Library
5753 (For_Project => Main_Project,
5754 In_Tree => Project_Tree,
5755 Gnatbind => Gnatbind.all,
5756 Gnatbind_Path => Gnatbind_Path,
5758 Gcc_Path => Gcc_Path,
5762 Finish_Program (Project_Tree, E_Success);
5765 -- Call Get_Target_Parameters to ensure that flags are properly
5766 -- set before calling Usage.
5768 Targparm.Get_Target_Parameters;
5770 -- Output usage information if no argument on the command line
5772 if Argument_Count = 0 then
5778 Finish_Program (Project_Tree, E_Success);
5782 -- Get the first executable.
5783 -- ??? This needs to be done early, because Osint.Next_Main_File also
5784 -- initializes the primary search directory, used below to initialize
5785 -- the "-I" parameter
5787 Main_Source_File := Next_Main_Source; -- No directory information
5789 -- If -M was specified, behave as if -n was specified
5791 if List_Dependencies then
5792 Do_Not_Execute := True;
5795 Add_Switch ("-I-", Compiler, And_Save => True);
5797 if Main_Project = No_Project then
5798 if Look_In_Primary_Dir then
5801 Normalize_Directory_Name
5802 (Get_Primary_Src_Search_Directory.all).all,
5804 Append_Switch => False,
5810 -- If we use a project file, we have already checked that a main
5811 -- specified on the command line with directory information has the
5812 -- path name corresponding to a correct source in the project tree.
5813 -- So, we don't need the directory information to be taken into
5814 -- account by Find_File, and in fact it may lead to take the wrong
5815 -- sources for other compilation units, when there are extending
5818 Look_In_Primary_Dir := False;
5821 -- If the user wants a program without a main subprogram, add the
5822 -- appropriate switch to the binder.
5824 if No_Main_Subprogram then
5825 Add_Switch ("-z", Binder, And_Save => True);
5828 if Main_Project /= No_Project then
5830 if Main_Project.Object_Directory /= No_Path_Information then
5832 -- Change current directory to object directory of main project
5834 Project_Of_Current_Object_Directory := No_Project;
5835 Change_To_Object_Directory (Main_Project);
5838 -- Source file lookups should be cached for efficiency. Source files
5839 -- are not supposed to change.
5841 Osint.Source_File_Data (Cache => True);
5843 Queue_Library_Project_Sources;
5846 -- The combination of -f -u and one or several mains on the command line
5849 if Force_Compilations
5850 and then Unique_Compile
5851 and then not Unique_Compile_All_Projects
5852 and then Main_On_Command_Line
5854 Must_Compile := True;
5857 if Main_Project /= No_Project
5858 and then not Must_Compile
5859 and then Main_Project.Externally_Built
5862 ("nothing to do for a main project that is externally built");
5865 -- If no project file is used, we just put the gcc switches
5866 -- from the command line in the Gcc_Switches table.
5868 if Main_Project = No_Project then
5869 for J in 1 .. Saved_Gcc_Switches.Last loop
5871 (Saved_Gcc_Switches.Table (J), Compiler, And_Save => False);
5875 -- If there is a project, put the command line gcc switches in the
5876 -- variable The_Saved_Gcc_Switches. They are going to be used later
5877 -- in procedure Compile_Sources.
5879 The_Saved_Gcc_Switches :=
5880 new Argument_List (1 .. Saved_Gcc_Switches.Last + 1);
5882 for J in 1 .. Saved_Gcc_Switches.Last loop
5883 The_Saved_Gcc_Switches (J) := Saved_Gcc_Switches.Table (J);
5886 -- We never use gnat.adc when a project file is used
5888 The_Saved_Gcc_Switches (The_Saved_Gcc_Switches'Last) := No_gnat_adc;
5891 -- If there was a --GCC, --GNATBIND or --GNATLINK switch on the command
5892 -- line, then we have to use it, even if there was another switch in
5893 -- the project file.
5895 if Saved_Gcc /= null then
5899 if Saved_Gnatbind /= null then
5900 Gnatbind := Saved_Gnatbind;
5903 if Saved_Gnatlink /= null then
5904 Gnatlink := Saved_Gnatlink;
5907 Bad_Compilation.Init;
5909 -- If project files are used, create the mapping of all the sources, so
5910 -- that the correct paths will be found. Otherwise, if there is a file
5911 -- which is not a source with the same name in a source directory this
5912 -- file may be incorrectly found.
5914 if Main_Project /= No_Project then
5915 Prj.Env.Create_Mapping (Project_Tree);
5918 -- Here is where the make process is started
5921 (Main_Project /= No_Project and then One_Compilation_Per_Obj_Dir);
5923 Is_First_Main := True;
5925 Multiple_Main_Loop : for N_File in 1 .. Osint.Number_Of_Files loop
5926 if Current_File_Index /= No_Index then
5927 Main_Index := Current_File_Index;
5930 Current_Main_Index := Main_Index;
5932 if Current_Main_Index = 0
5933 and then Unique_Compile
5934 and then Main_Project /= No_Project
5936 -- If this is a multi-unit source, do not compile it as is (ie
5937 -- without specifying which unit to compile)
5938 -- Insert_Project_Sources has added each of the unit separately.
5941 Source : constant Prj.Source_Id := Find_Source
5942 (In_Tree => Project_Tree,
5943 Project => Main_Project,
5944 Base_Name => Main_Source_File,
5945 Index => Current_Main_Index,
5946 In_Imported_Only => True);
5948 if Source /= No_Source and then Source.Index /= 0 then
5954 Compute_Switches_For_Main
5957 Compute_Builder => Is_First_Main,
5958 Current_Work_Dir => Current_Work_Dir.all);
5960 if Is_First_Main then
5962 -- Put the default source dirs in the source path only now, so
5963 -- that we take the correct ones in the case where --RTS= is
5964 -- specified in the Builder switches.
5966 Osint.Add_Default_Search_Dirs;
5968 -- Get the target parameters, which are only needed for a couple
5969 -- of cases in gnatmake. Protect against an exception, such as the
5970 -- case of system.ads missing from the library, and fail
5974 Targparm.Get_Target_Parameters;
5976 when Unrecoverable_Error =>
5977 Make_Failed ("*** make failed.");
5980 Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
5981 Gnatbind_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
5982 Gnatlink_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
5984 -- If we have specified -j switch both from the project file
5985 -- and on the command line, the one from the command line takes
5988 if Saved_Maximum_Processes = 0 then
5989 Saved_Maximum_Processes := Maximum_Processes;
5992 if Debug.Debug_Flag_M then
5993 Write_Line ("Maximum number of simultaneous compilations =" &
5994 Saved_Maximum_Processes'Img);
5997 -- Allocate as many temporary mapping file names as the maximum
5998 -- number of compilations processed, for each possible project.
6001 Data : Project_Compilation_Access;
6002 Proj : Project_List;
6005 Proj := Project_Tree.Projects;
6006 while Proj /= null loop
6008 new Project_Compilation_Data'
6009 (Mapping_File_Names
=>
6010 new Temp_Path_Names
(1 .. Saved_Maximum_Processes
),
6011 Last_Mapping_File_Names
=> 0,
6012 Free_Mapping_File_Indexes
=>
6013 new Free_File_Indexes
(1 .. Saved_Maximum_Processes
),
6014 Last_Free_Indexes
=> 0);
6016 Project_Compilation_Htable
.Set
6017 (Project_Compilation
, Proj
.Project
, Data
);
6022 new Project_Compilation_Data
'
6023 (Mapping_File_Names =>
6024 new Temp_Path_Names (1 .. Saved_Maximum_Processes),
6025 Last_Mapping_File_Names => 0,
6026 Free_Mapping_File_Indexes =>
6027 new Free_File_Indexes (1 .. Saved_Maximum_Processes),
6028 Last_Free_Indexes => 0);
6030 Project_Compilation_Htable.Set
6031 (Project_Compilation, No_Project, Data);
6034 Is_First_Main := False;
6037 Executable_Obsolete := False;
6040 (Main_Source_File => Main_Source_File,
6041 Executable => Executable,
6042 Non_Std_Executable => Non_Std_Executable);
6044 if Do_Compile_Step then
6046 (Main_Source_File => Main_Source_File,
6047 Current_Main_Index => Current_Main_Index,
6048 Total_Compilation_Failures => Total_Compilation_Failures,
6049 Stand_Alone_Libraries => Stand_Alone_Libraries,
6050 Executable => Executable,
6051 Is_Last_Main => N_File = Osint.Number_Of_Files,
6052 Stop_Compile => Stop_Compile);
6054 if Stop_Compile then
6055 if Total_Compilation_Failures /= 0 then
6060 List_Bad_Compilations;
6061 Report_Compilation_Failed;
6064 elsif Osint.Number_Of_Files = 1 then
6065 exit Multiple_Main_Loop;
6072 -- For binding and linking, we need to be in the object directory of
6073 -- the main project.
6075 if Main_Project /= No_Project then
6076 Change_To_Object_Directory (Main_Project);
6079 -- If we are here, it means that we need to rebuilt the current main,
6080 -- so we set Executable_Obsolete to True to make sure that subsequent
6081 -- mains will be rebuilt.
6083 Main_ALI_In_Place_Mode_Step : declare
6084 ALI_File : File_Name_Type;
6085 Src_File : File_Name_Type;
6088 Src_File := Strip_Directory (Main_Source_File);
6089 ALI_File := Lib_File_Name (Src_File, Current_Main_Index);
6090 Main_ALI_File := Full_Lib_File_Name (ALI_File);
6092 -- When In_Place_Mode, the library file can be located in the
6093 -- Main_Source_File directory which may not be present in the
6094 -- library path. If it is not present then use the corresponding
6095 -- library file name.
6097 if Main_ALI_File = No_File and then In_Place_Mode then
6098 Get_Name_String (Get_Directory (Full_Source_Name (Src_File)));
6099 Get_Name_String_And_Append (ALI_File);
6100 Main_ALI_File := Name_Find;
6101 Main_ALI_File := Full_Lib_File_Name (Main_ALI_File);
6104 if Main_ALI_File = No_File then
6105 Make_Failed ("could not find the main ALI file");
6107 end Main_ALI_In_Place_Mode_Step;
6109 if Do_Bind_Step then
6111 (Stand_Alone_Libraries => Stand_Alone_Libraries,
6112 Main_ALI_File => Main_ALI_File);
6115 if Do_Link_Step then
6117 (Non_Std_Executable => Non_Std_Executable,
6118 Executable => Executable,
6119 Main_ALI_File => Main_ALI_File);
6122 -- We go to here when we skip the bind and link steps
6128 if N_File < Osint.Number_Of_Files then
6129 Main_Source_File := Next_Main_Source; -- No directory information
6131 end loop Multiple_Main_Loop;
6133 if Failed_Links.Last > 0 then
6134 for Index in 1 .. Successful_Links.Last loop
6135 Write_Str ("Linking of """);
6136 Write_Str (Get_Name_String (Successful_Links.Table (Index)));
6137 Write_Line (""" succeeded.");
6142 for Index in 1 .. Failed_Links.Last loop
6143 Write_Str ("Linking of """);
6144 Write_Str (Get_Name_String (Failed_Links.Table (Index)));
6145 Write_Line (""" failed.");
6148 if Commands_To_Stdout then
6149 Set_Standard_Output;
6152 if Total_Compilation_Failures = 0 then
6153 Report_Compilation_Failed;
6157 if Total_Compilation_Failures /= 0 then
6158 List_Bad_Compilations;
6159 Report_Compilation_Failed;
6162 Finish_Program (Project_Tree, E_Success);
6167 Write_Line (Exception_Information (X));
6168 Make_Failed ("INTERNAL ERROR. Please report.");
6175 function Hash (F : File_Name_Type) return Header_Num is
6177 return Header_Num (1 + F mod Max_Header);
6180 --------------------
6181 -- In_Ada_Lib_Dir --
6182 --------------------
6184 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean is
6185 D : constant File_Name_Type := Get_Directory (File);
6186 B : constant Byte := Get_Name_Table_Byte (D);
6188 return (B and Ada_Lib_Dir) /= 0;
6191 -----------------------
6192 -- Init_Mapping_File --
6193 -----------------------
6195 procedure Init_Mapping_File
6196 (Project : Project_Id;
6197 Data : in out Project_Compilation_Data;
6198 File_Index : in out Natural)
6200 FD : File_Descriptor;
6202 -- For call to Close
6205 -- Increase the index of the last mapping file for this project
6207 Data.Last_Mapping_File_Names := Data.Last_Mapping_File_Names + 1;
6209 -- If there is a project file, call Create_Mapping_File with
6212 if Project /= No_Project then
6213 Prj.Env.Create_Mapping_File
6215 In_Tree => Project_Tree,
6216 Language => Name_Ada,
6217 Name => Data.Mapping_File_Names
6218 (Data.Last_Mapping_File_Names));
6220 -- Otherwise, just create an empty file
6223 Tempdir.Create_Temp_File
6224 (FD, Data.Mapping_File_Names (Data.Last_Mapping_File_Names));
6226 if FD = Invalid_FD then
6227 Make_Failed ("disk full");
6230 (Project_Tree.Shared,
6231 Data.Mapping_File_Names (Data.Last_Mapping_File_Names));
6237 Make_Failed ("disk full");
6241 -- And return the index of the newly created file
6243 File_Index := Data.Last_Mapping_File_Names;
6244 end Init_Mapping_File;
6250 procedure Initialize
6251 (Project_Node_Tree : out Project_Node_Tree_Ref;
6252 Env : out Prj.Tree.Environment)
6254 procedure Check_Version_And_Help is
6255 new Check_Version_And_Help_G (Makeusg);
6257 -- Start of processing for Initialize
6260 -- Prepare the project's tree, since this is used to hold external
6261 -- references, project path and other attributes that can be impacted by
6262 -- the command line switches
6264 Prj.Tree.Initialize (Env, Gnatmake_Flags);
6266 Project_Node_Tree := new Project_Node_Tree_Data;
6267 Prj.Tree.Initialize (Project_Node_Tree);
6269 -- Override default initialization of Check_Object_Consistency since
6270 -- this is normally False for GNATBIND, but is True for GNATMAKE since
6271 -- we do not need to check source consistency again once GNATMAKE has
6272 -- looked at the sources to check.
6274 Check_Object_Consistency := True;
6276 -- Package initializations (the order of calls is important here)
6278 Output.Set_Standard_Error;
6281 Binder_Switches.Init;
6282 Linker_Switches.Init;
6288 Prj.Initialize (Project_Tree);
6292 RTS_Specified := null;
6297 -- Add the directory where gnatmake is invoked in front of the path,
6298 -- if gnatmake is invoked from a bin directory or with directory
6302 Prefix : constant String := Executable_Prefix_Path;
6303 Command : constant String := Command_Name;
6306 if Prefix'Length > 0 then
6308 PATH : constant String :=
6309 Prefix & Directory_Separator & "bin" & Path_Separator
6310 & Getenv ("PATH").all;
6312 Setenv ("PATH", PATH);
6316 for Index in reverse Command'Range loop
6317 if Command (Index) = Directory_Separator then
6319 Absolute_Dir : constant String :=
6321 (Command (Command'First .. Index));
6322 PATH : constant String :=
6325 Getenv ("PATH").all;
6327 Setenv ("PATH", PATH);
6336 -- Scan the switches and arguments
6338 -- First, scan to detect --version and/or --help
6340 Check_Version_And_Help ("GNATMAKE", "1995");
6342 -- Scan again the switch and arguments, now that we are sure that they
6343 -- do not include --version or --help.
6345 -- First, check for switch -P and, if found and gprbuild is available,
6346 -- silently invoke gprbuild, with switch --target if not on a native
6350 Arg_Len : Natural := Argument_Count;
6351 Call_Gprbuild : Boolean := False;
6352 Gprbuild : String_Access := null;
6355 Target : String_Access := null;
6361 and then Name_Buffer (Name_Len - 7 .. Name_Len) = "gnatmake"
6363 if Name_Len > 8 then
6364 Target := new String'(Name_Buffer
(1 .. Name_Len
- 9));
6365 Arg_Len
:= Arg_Len
+ 1;
6368 for J
in 1 .. Argument_Count
loop
6370 Arg
: constant String := Argument
(J
);
6373 and then Arg
(Arg
'First .. Arg
'First + 1) = "-P"
6375 Call_Gprbuild
:= True;
6381 if Call_Gprbuild
then
6382 Gprbuild
:= Locate_Exec_On_Path
(Exec_Name
=> "gprbuild");
6384 if Gprbuild
/= null then
6386 Args
: Argument_List
(1 .. Arg_Len
);
6388 if Target
/= null then
6389 Args
(1) := new String'("--target=" & Target.all);
6393 for J in 1 .. Argument_Count loop
6395 Args (Pos) := new String'(Argument
(J
));
6398 Spawn
(Gprbuild
.all, Args
, Success
);
6403 Exit_Program
(E_Success
);
6411 Scan_Args
: for Next_Arg
in 1 .. Argument_Count
loop
6412 Scan_Make_Arg
(Env
, Argument
(Next_Arg
), And_Save
=> True);
6415 if N_M_Switch
> 0 and RTS_Specified
= null then
6416 Process_Multilib
(Env
);
6419 if Commands_To_Stdout
then
6420 Set_Standard_Output
;
6423 if Usage_Requested
then
6427 -- Add the default project search directories now, after the directories
6428 -- that have been specified by switches -aP<dir>.
6430 Prj
.Env
.Initialize_Default_Project_Path
6431 (Env
.Project_Path
, Target_Name
=> Sdefault
.Target_Name
.all);
6433 -- Test for trailing -P switch
6435 if Project_File_Name_Present
and then Project_File_Name
= null then
6436 Make_Failed
("project file name missing after -P");
6438 -- Test for trailing -o switch
6440 elsif Output_File_Name_Present
and then not Output_File_Name_Seen
then
6441 Make_Failed
("output file name missing after -o");
6443 -- Test for trailing -D switch
6445 elsif Object_Directory_Present
and then not Object_Directory_Seen
then
6446 Make_Failed
("object directory missing after -D");
6449 -- Test for simultaneity of -i and -D
6451 if Object_Directory_Path
/= null and then In_Place_Mode
then
6452 Make_Failed
("-i and -D cannot be used simultaneously");
6455 -- If --subdirs= is specified, but not -P, this is equivalent to -D,
6456 -- except that the directory is created if it does not exist.
6458 if Prj
.Subdirs
/= null and then Project_File_Name
= null then
6459 if Object_Directory_Path
/= null then
6460 Make_Failed
("--subdirs and -D cannot be used simultaneously");
6462 elsif In_Place_Mode
then
6463 Make_Failed
("--subdirs and -i cannot be used simultaneously");
6466 if not Is_Directory
(Prj
.Subdirs
.all) then
6468 Ada
.Directories
.Create_Path
(Prj
.Subdirs
.all);
6471 Make_Failed
("unable to create object directory " &
6476 Object_Directory_Present
:= True;
6479 Argv
: constant String (1 .. Prj
.Subdirs
'Length) :=
6482 Scan_Make_Arg
(Env
, Argv
, And_Save
=> False);
6487 -- Deal with -C= switch
6489 if Gnatmake_Mapping_File
/= null then
6491 -- First, check compatibility with other switches
6493 if Project_File_Name
/= null then
6494 Make_Failed
("-C= switch is not compatible with -P switch");
6496 elsif Saved_Maximum_Processes
> 1 then
6497 Make_Failed
("-C= switch is not compatible with -jnnn switch");
6500 Fmap
.Initialize
(Gnatmake_Mapping_File
.all);
6502 ("-gnatem=" & Gnatmake_Mapping_File
.all,
6507 if Project_File_Name
/= null then
6509 -- A project file was specified by a -P switch
6511 if Verbose_Mode
then
6513 Write_Str
("Parsing project file """);
6514 Write_Str
(Project_File_Name
.all);
6519 -- Avoid looking in the current directory for ALI files
6521 -- Look_In_Primary_Dir := False;
6523 -- Set the project parsing verbosity to whatever was specified
6524 -- by a possible -vP switch.
6526 Prj
.Pars
.Set_Verbosity
(To
=> Current_Verbosity
);
6528 -- Parse the project file.
6529 -- If there is an error, Main_Project will still be No_Project.
6532 (Project
=> Main_Project
,
6533 In_Tree
=> Project_Tree
,
6534 Project_File_Name
=> Project_File_Name
.all,
6535 Packages_To_Check
=> Packages_To_Check_By_Gnatmake
,
6537 In_Node_Tree
=> Project_Node_Tree
);
6539 -- The parsing of project files may have changed the current output
6541 if Commands_To_Stdout
then
6542 Set_Standard_Output
;
6547 if Main_Project
= No_Project
then
6549 ("""" & Project_File_Name
.all & """ processing failed");
6552 if Main_Project
.Qualifier
= Aggregate
then
6553 Make_Failed
("aggregate projects are not supported");
6555 elsif Aggregate_Libraries_In
(Project_Tree
) then
6556 Make_Failed
("aggregate library projects are not supported");
6559 Create_Mapping_File
:= True;
6561 if Verbose_Mode
then
6563 Write_Str
("Parsing of project file """);
6564 Write_Str
(Project_File_Name
.all);
6565 Write_Str
(""" is finished.");
6569 -- We add the source directories and the object directories to the
6572 -- ??? Why do we need these search directories, we already know the
6573 -- locations from parsing the project, except for the runtime which
6574 -- has its own directories anyway
6576 Add_Source_Directories
(Main_Project
, Project_Tree
);
6577 Add_Object_Directories
(Main_Project
, Project_Tree
);
6579 Recursive_Compute_Depth
(Main_Project
);
6580 Compute_All_Imported_Projects
(Main_Project
, Project_Tree
);
6584 Osint
.Add_Default_Search_Dirs
;
6586 -- Source file lookups should be cached for efficiency. Source files
6587 -- are not supposed to change. However, we do that now only if no
6588 -- project file is used; if a project file is used, we do it just
6589 -- after changing the directory to the object directory.
6591 Osint
.Source_File_Data
(Cache
=> True);
6593 -- Read gnat.adc file to initialize Fname.UF
6595 Fname
.UF
.Initialize
;
6599 Fname
.SF
.Read_Source_File_Name_Pragmas
;
6602 when Err
: SFN_Scan
.Syntax_Error_In_GNAT_ADC
=>
6603 Make_Failed
(Exception_Message
(Err
));
6608 -- Make sure no project object directory is recorded
6610 Project_Of_Current_Object_Directory
:= No_Project
;
6612 if Debug
.Debug_Flag_N
then
6613 Opt
.Keep_Temporary_Files
:= True;
6617 ----------------------------
6618 -- Insert_Project_Sources --
6619 ----------------------------
6621 procedure Insert_Project_Sources
6622 (The_Project
: Project_Id
;
6623 All_Projects
: Boolean;
6626 Put_In_Q
: Boolean := Into_Q
;
6628 Sfile
: File_Name_Type
;
6629 Sid
: Prj
.Source_Id
;
6631 Project
: Project_Id
;
6634 -- Loop through all the sources in the project files
6636 Unit
:= Units_Htable
.Get_First
(Project_Tree
.Units_HT
);
6637 while Unit
/= null loop
6641 Project
:= No_Project
;
6643 -- If there is a source for the body, and the body has not been
6646 if Unit
.File_Names
(Impl
) /= null
6647 and then not Unit
.File_Names
(Impl
).Locally_Removed
6649 -- And it is a source for the specified project
6653 Is_Extending
(The_Project
, Unit
.File_Names
(Impl
).Project
)
6655 Project
:= Unit
.File_Names
(Impl
).Project
;
6657 -- If we don't have a spec, we cannot consider the source
6658 -- if it is a subunit.
6660 if Unit
.File_Names
(Spec
) = null then
6662 Src_Ind
: Source_File_Index
;
6664 -- Here we are cheating a little bit: we don't want to
6665 -- use Sinput.L, because it depends on the GNAT tree
6666 -- (Atree, Sinfo, ...). So, we pretend that it is a
6667 -- project file, and we use Sinput.P.
6669 -- Source_File_Is_Subunit is just scanning through the
6670 -- file until it finds one of the reserved words
6671 -- separate, procedure, function, generic or package.
6672 -- Fortunately, these Ada reserved words are also
6673 -- reserved for project files.
6676 Src_Ind
:= Sinput
.P
.Load_Project_File
6678 (Unit
.File_Names
(Impl
).Path
.Display_Name
));
6680 -- If it is a subunit, discard it
6682 if Sinput
.P
.Source_File_Is_Subunit
(Src_Ind
) then
6687 Sfile
:= Unit
.File_Names
(Impl
).Display_File
;
6688 Index
:= Unit
.File_Names
(Impl
).Index
;
6689 Sid
:= Unit
.File_Names
(Impl
);
6694 Sfile
:= Unit
.File_Names
(Impl
).Display_File
;
6695 Index
:= Unit
.File_Names
(Impl
).Index
;
6696 Sid
:= Unit
.File_Names
(Impl
);
6700 elsif Unit
.File_Names
(Spec
) /= null
6701 and then not Unit
.File_Names
(Spec
).Locally_Removed
6705 Is_Extending
(The_Project
, Unit
.File_Names
(Spec
).Project
))
6707 -- If there is no source for the body, but there is one for the
6708 -- spec which has not been locally removed, then we take this one.
6710 Sfile
:= Unit
.File_Names
(Spec
).Display_File
;
6711 Index
:= Unit
.File_Names
(Spec
).Index
;
6712 Sid
:= Unit
.File_Names
(Spec
);
6713 Project
:= Unit
.File_Names
(Spec
).Project
;
6716 -- For the first source inserted into the Q, we need to initialize
6717 -- the Q, but not for the subsequent sources.
6720 (Main_Project
/= No_Project
and then
6721 One_Compilation_Per_Obj_Dir
);
6723 if Sfile
/= No_File
then
6725 ((Format
=> Format_Gnatmake
,
6728 Unit
=> No_Unit_Name
,
6733 if not Put_In_Q
and then Sfile
/= No_File
then
6735 -- If Put_In_Q is False, we add the source as if it were specified
6736 -- on the command line, and we set Put_In_Q to True, so that the
6737 -- following sources will only be put in the queue. The source is
6738 -- already in the Q, but we need at least one fake main to call
6741 if Verbose_Mode
then
6742 Write_Str
("Adding """);
6743 Write_Str
(Get_Name_String
(Sfile
));
6744 Write_Line
(""" as if on the command line");
6747 Osint
.Add_File
(Get_Name_String
(Sfile
), Index
);
6751 Unit
:= Units_Htable
.Get_Next
(Project_Tree
.Units_HT
);
6753 end Insert_Project_Sources
;
6755 ---------------------
6756 -- Is_In_Obsoleted --
6757 ---------------------
6759 function Is_In_Obsoleted
(F
: File_Name_Type
) return Boolean is
6766 Name
: constant String := Get_Name_String
(F
);
6768 F2
: File_Name_Type
;
6772 while First
> Name
'First
6773 and then not Is_Directory_Separator
(Name
(First
- 1))
6778 if First
/= Name
'First then
6780 Add_Str_To_Name_Buffer
(Name
(First
.. Name
'Last));
6787 return Obsoleted
.Get
(F2
);
6790 end Is_In_Obsoleted
;
6792 ----------------------------
6793 -- Is_In_Object_Directory --
6794 ----------------------------
6796 function Is_In_Object_Directory
6797 (Source_File
: File_Name_Type
;
6798 Full_Lib_File
: File_Name_Type
) return Boolean
6801 -- There is something to check only when using project files. Otherwise,
6802 -- this function returns True (last line of the function).
6804 if Main_Project
/= No_Project
then
6806 Source_File_Name
: constant String :=
6807 Get_Name_String
(Source_File
);
6808 Saved_Verbosity
: constant Verbosity
:= Current_Verbosity
;
6809 Project
: Project_Id
:= No_Project
;
6811 Path_Name
: Path_Name_Type
:= No_Path
;
6812 pragma Warnings
(Off
, Path_Name
);
6815 -- Call Get_Reference to know the ultimate extending project of
6816 -- the source. Call it with verbosity default to avoid verbose
6819 Current_Verbosity
:= Default
;
6820 Prj
.Env
.Get_Reference
6821 (Source_File_Name
=> Source_File_Name
,
6823 In_Tree
=> Project_Tree
,
6825 Current_Verbosity
:= Saved_Verbosity
;
6827 -- If this source is in a project, check that the ALI file is in
6828 -- its object directory. If it is not, return False, so that the
6829 -- ALI file will not be skipped.
6831 if Project
/= No_Project
then
6833 Object_Directory
: constant String :=
6837 Object_Directory
.Display_Name
));
6839 Olast
: Natural := Object_Directory
'Last;
6841 Lib_File_Directory
: constant String :=
6842 Normalize_Pathname
(Dir_Name
6843 (Get_Name_String
(Full_Lib_File
)));
6845 Llast
: Natural := Lib_File_Directory
'Last;
6848 -- For directories, Normalize_Pathname may or may not put
6849 -- a directory separator at the end, depending on its input.
6850 -- Remove any last directory separator before comparison.
6851 -- Returns True only if the two directories are the same.
6853 if Object_Directory
(Olast
) = Directory_Separator
then
6857 if Lib_File_Directory
(Llast
) = Directory_Separator
then
6861 return Object_Directory
(Object_Directory
'First .. Olast
) =
6862 Lib_File_Directory
(Lib_File_Directory
'First .. Llast
);
6868 -- When the source is not in a project file, always return True
6871 end Is_In_Object_Directory
;
6878 (ALI_File
: File_Name_Type
;
6879 Args
: Argument_List
;
6880 Success
: out Boolean)
6882 Link_Args
: Argument_List
(1 .. Args
'Length + 1);
6885 Get_Name_String
(ALI_File
);
6886 Link_Args
(1) := new String'(Name_Buffer (1 .. Name_Len));
6888 Link_Args (2 .. Args'Length + 1) := Args;
6890 GNAT.OS_Lib.Normalize_Arguments (Link_Args);
6892 Display (Gnatlink.all, Link_Args);
6894 if Gnatlink_Path = null then
6895 Make_Failed ("error, unable to locate " & Gnatlink.all);
6898 GNAT.OS_Lib.Spawn (Gnatlink_Path.all, Link_Args, Success);
6901 ---------------------------
6902 -- List_Bad_Compilations --
6903 ---------------------------
6905 procedure List_Bad_Compilations is
6907 if not No_Exit_Message then
6908 for J in Bad_Compilation.First .. Bad_Compilation.Last loop
6909 if Bad_Compilation.Table (J).File = No_File then
6911 elsif not Bad_Compilation.Table (J).Found then
6912 Inform (Bad_Compilation.Table (J).File, "not found");
6914 Inform (Bad_Compilation.Table (J).File, "compilation error");
6918 end List_Bad_Compilations;
6924 procedure List_Depend is
6925 Lib_Name : File_Name_Type;
6926 Obj_Name : File_Name_Type;
6927 Src_Name : File_Name_Type;
6931 Line_Size : constant := 77;
6934 Set_Standard_Output;
6936 for A in ALIs.First .. ALIs.Last loop
6937 Lib_Name := ALIs.Table (A).Afile;
6939 -- We have to provide the full library file name in In_Place_Mode
6941 if In_Place_Mode then
6942 Lib_Name := Full_Lib_File_Name (Lib_Name);
6945 Obj_Name := Object_File_Name (Lib_Name);
6946 Write_Name (Obj_Name);
6949 Get_Name_String (Obj_Name);
6951 Line_Pos := Len + 2;
6953 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
6954 Src_Name := Sdep.Table (D).Sfile;
6956 if Is_Internal_File_Name (Src_Name)
6957 and then not Check_Readonly_Files
6961 if not Quiet_Output then
6962 Src_Name := Full_Source_Name (Src_Name);
6965 Get_Name_String (Src_Name);
6968 if Line_Pos + Len + 1 > Line_Size then
6974 Line_Pos := Line_Pos + Len + 1;
6977 Write_Name (Src_Name);
6984 if not Commands_To_Stdout then
6993 procedure Make_Failed (S : String) is
6995 Fail_Program (Project_Tree, S);
6998 --------------------
6999 -- Mark_Directory --
7000 --------------------
7002 procedure Mark_Directory
7004 Mark : Lib_Mark_Type;
7005 On_Command_Line : Boolean)
7010 function Base_Directory return String;
7011 -- If Dir comes from the command line, empty string (relative paths are
7012 -- resolved with respect to the current directory), else return the main
7013 -- project's directory.
7015 --------------------
7016 -- Base_Directory --
7017 --------------------
7019 function Base_Directory return String is
7021 if On_Command_Line then
7024 return Get_Name_String (Main_Project.Directory.Display_Name);
7028 Real_Path : constant String := Normalize_Pathname (Dir, Base_Directory);
7030 -- Start of processing for Mark_Directory
7035 if Real_Path'Length = 0 then
7036 Add_Str_To_Name_Buffer (Dir);
7039 Add_Str_To_Name_Buffer (Real_Path);
7042 -- Last character is supposed to be a directory separator
7044 if not Is_Directory_Separator (Name_Buffer (Name_Len)) then
7045 Add_Char_To_Name_Buffer (Directory_Separator);
7048 -- Add flags to the already existing flags
7051 B := Get_Name_Table_Byte (N);
7052 Set_Name_Table_Byte (N, B or Mark);
7055 ----------------------
7056 -- Process_Multilib --
7057 ----------------------
7059 procedure Process_Multilib (Env : in out Prj.Tree.Environment) is
7060 Output_FD : File_Descriptor;
7061 Output_Name : String_Access;
7062 Arg_Index : Natural := 0;
7063 Success : Boolean := False;
7064 Return_Code : Integer := 0;
7065 Multilib_Gcc_Path : String_Access;
7066 Multilib_Gcc : String_Access;
7067 N_Read : Integer := 0;
7068 Line : String (1 .. 1000);
7069 Args : Argument_List (1 .. N_M_Switch + 1);
7072 pragma Assert (N_M_Switch > 0 and RTS_Specified = null);
7074 -- In case we detected a multilib switch and the user has not
7075 -- manually specified a specific RTS we emulate the following command:
7076 -- gnatmake $FLAGS --RTS=$(gcc -print-multi-directory $FLAGS)
7078 -- First select the flags which might have an impact on multilib
7079 -- processing. Note that this is an heuristic selection and it
7080 -- will need to be maintained over time. The condition has to
7081 -- be kept synchronized with N_M_Switch counting in Scan_Make_Arg.
7083 for Next_Arg in 1 .. Argument_Count loop
7085 Argv : constant String := Argument (Next_Arg);
7089 and then Argv (1) = '-'
7090 and then Argv (2) = 'm
'
7091 and then Argv /= "-margs"
7093 -- Ignore -mieee to avoid spawning an extra gcc in this case
7095 and then Argv /= "-mieee"
7097 Arg_Index := Arg_Index + 1;
7098 Args (Arg_Index) := new String'(Argv
);
7103 pragma Assert
(Arg_Index
= N_M_Switch
);
7105 Args
(Args
'Last) := new String'("-print-multi-directory");
7107 -- Call the GCC driver with the collected flags and save its
7108 -- output. Alternate design would be to link in gnatmake the
7109 -- relevant part of the GCC driver.
7111 if Saved_Gcc /= null then
7112 Multilib_Gcc := Saved_Gcc;
7114 Multilib_Gcc := Gcc;
7117 Multilib_Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Multilib_Gcc.all);
7119 Create_Temp_Output_File (Output_FD, Output_Name);
7121 if Output_FD = Invalid_FD then
7126 (Multilib_Gcc_Path.all, Args, Output_FD, Return_Code, False);
7129 if Return_Code /= 0 then
7133 -- Parse the GCC driver output which is a single line, removing CR/LF
7135 Output_FD := Open_Read (Output_Name.all, Binary);
7137 if Output_FD = Invalid_FD then
7141 N_Read := Read (Output_FD, Line (1)'Address, Line'Length);
7143 Delete_File (Output_Name.all, Success);
7145 for J in reverse 1 .. N_Read loop
7146 if Line (J) = ASCII.CR or else Line (J) = ASCII.LF then
7147 N_Read := N_Read - 1;
7153 -- In case the standard RTS is selected do nothing
7155 if N_Read = 0 or else Line (1 .. N_Read) = "." then
7159 -- Otherwise add -margs --RTS=output
7161 Scan_Make_Arg (Env, "-margs", And_Save => True);
7162 Scan_Make_Arg (Env, "--RTS=" & Line (1 .. N_Read), And_Save => True);
7163 end Process_Multilib;
7165 -----------------------------
7166 -- Recursive_Compute_Depth --
7167 -----------------------------
7169 procedure Recursive_Compute_Depth (Project : Project_Id) is
7170 use Project_Boolean_Htable;
7171 Seen : Project_Boolean_Htable.Instance := Project_Boolean_Htable.Nil;
7173 procedure Recurse (Prj : Project_Id; Depth : Natural);
7174 -- Recursive procedure that does the work, keeping track of the depth
7180 procedure Recurse (Prj : Project_Id; Depth : Natural) is
7181 List : Project_List;
7185 if Prj.Depth >= Depth or else Get (Seen, Prj) then
7189 -- We need a test to avoid infinite recursions with limited withs:
7190 -- If we have A -> B -> A, then when set level of A to n, we try and
7191 -- set level of B to n+1, and then level of A to n + 2, ...
7193 Set (Seen, Prj, True);
7197 -- Visit each imported project
7199 List := Prj.Imported_Projects;
7200 while List /= null loop
7201 Proj := List.Project;
7203 Recurse (Prj => Proj, Depth => Depth + 1);
7206 -- We again allow changing the depth of this project later on if it
7207 -- is in fact imported by a lower-level project.
7209 Set (Seen, Prj, False);
7212 Proj : Project_List;
7214 -- Start of processing for Recursive_Compute_Depth
7217 Proj := Project_Tree.Projects;
7218 while Proj /= null loop
7219 Proj.Project.Depth := 0;
7223 Recurse (Project, Depth => 1);
7225 end Recursive_Compute_Depth;
7227 -------------------------------
7228 -- Report_Compilation_Failed --
7229 -------------------------------
7231 procedure Report_Compilation_Failed is
7233 Fail_Program (Project_Tree, "");
7234 end Report_Compilation_Failed;
7236 ------------------------
7237 -- Sigint_Intercepted --
7238 ------------------------
7240 procedure Sigint_Intercepted is
7243 Write_Line ("*** Interrupted ***");
7245 -- Send SIGINT to all outstanding compilation processes spawned
7247 for J in 1 .. Outstanding_Compiles loop
7248 Kill (Running_Compile (J).Pid, Hard_Kill => False);
7251 Finish_Program (Project_Tree, E_No_Compile);
7252 end Sigint_Intercepted;
7258 procedure Scan_Make_Arg
7259 (Env : in out Prj.Tree.Environment;
7266 Gnatmake_Switch_Found := True;
7268 pragma Assert (Argv'First = 1);
7270 if Argv'Length = 0 then
7274 -- If the previous switch has set the Project_File_Name_Present flag
7275 -- (that is we have seen a -P alone), then the next argument is the name
7276 -- of the project file.
7278 if Project_File_Name_Present and then Project_File_Name = null then
7279 if Argv (1) = '-' then
7280 Make_Failed ("project file name missing after -P");
7283 Project_File_Name_Present := False;
7284 Project_File_Name := new String'(Argv
);
7287 -- If the previous switch has set the Output_File_Name_Present flag
7288 -- (that is we have seen a -o), then the next argument is the name of
7289 -- the output executable.
7291 elsif Output_File_Name_Present
7292 and then not Output_File_Name_Seen
7294 Output_File_Name_Seen
:= True;
7296 if Argv
(1) = '-' then
7297 Make_Failed
("output file name missing after -o");
7300 Add_Switch
("-o", Linker
, And_Save
=> And_Save
);
7301 Add_Switch
(Executable_Name
(Argv
), Linker
, And_Save
=> And_Save
);
7304 -- If the previous switch has set the Object_Directory_Present flag
7305 -- (that is we have seen a -D), then the next argument is the path name
7306 -- of the object directory.
7308 elsif Object_Directory_Present
7309 and then not Object_Directory_Seen
7311 Object_Directory_Seen
:= True;
7313 if Argv
(1) = '-' then
7314 Make_Failed
("object directory path name missing after -D");
7316 elsif not Is_Directory
(Argv
) then
7317 Make_Failed
("cannot find object directory """ & Argv
& """");
7320 -- Record the object directory. Make sure it ends with a directory
7324 Norm
: constant String := Normalize_Pathname
(Argv
);
7327 if Norm
(Norm
'Last) = Directory_Separator
then
7328 Object_Directory_Path
:= new String'(Norm);
7330 Object_Directory_Path :=
7331 new String'(Norm
& Directory_Separator
);
7334 Add_Lib_Search_Dir
(Norm
);
7336 -- Specify the object directory to the binder
7338 Add_Switch
("-aO" & Norm
, Binder
, And_Save
=> And_Save
);
7343 -- Then check if we are dealing with -cargs/-bargs/-largs/-margs. These
7344 -- options are taken as is when found in package Compiler, Binder or
7345 -- Linker of the main project file.
7347 elsif (And_Save
or else Program_Args
= None
)
7348 and then (Argv
= "-bargs" or else
7349 Argv
= "-cargs" or else
7350 Argv
= "-largs" or else
7354 when 'c' => Program_Args
:= Compiler
;
7355 when 'b' => Program_Args
:= Binder
;
7356 when 'l' => Program_Args
:= Linker
;
7357 when 'm' => Program_Args
:= None
;
7360 raise Program_Error
;
7363 -- A special test is needed for the -o switch within a -largs since that
7364 -- is another way to specify the name of the final executable.
7366 elsif Program_Args
= Linker
and then Argv
= "-o" then
7368 ("switch -o not allowed within a -largs. Use -o directly.");
7370 -- Check to see if we are reading switches after a -cargs, -bargs or
7371 -- -largs switch. If so, save it.
7373 elsif Program_Args
/= None
then
7375 -- Check to see if we are reading -I switches in order to take into
7376 -- account in the src & lib search directories.
7378 if Argv
'Length > 2 and then Argv
(1 .. 2) = "-I" then
7379 if Argv
(3 .. Argv
'Last) = "-" then
7380 Look_In_Primary_Dir
:= False;
7382 elsif Program_Args
= Compiler
then
7383 if Argv
(3 .. Argv
'Last) /= "-" then
7384 Add_Source_Search_Dir
(Argv
(3 .. Argv
'Last), And_Save
);
7387 elsif Program_Args
= Binder
then
7388 Add_Library_Search_Dir
(Argv
(3 .. Argv
'Last), And_Save
);
7392 Add_Switch
(Argv
, Program_Args
, And_Save
=> And_Save
);
7394 -- Make sure that all significant switches -m on the command line
7398 and then Argv
(1 .. 2) = "-m"
7399 and then Argv
/= "-mieee"
7401 N_M_Switch
:= N_M_Switch
+ 1;
7404 -- Handle non-default compiler, binder, linker, and handle --RTS switch
7406 elsif Argv
'Length > 2 and then Argv
(1 .. 2) = "--" then
7408 and then Argv
(1 .. 6) = "--GCC="
7411 Program_Args
: constant Argument_List_Access
:=
7412 Argument_String_To_List
7413 (Argv
(7 .. Argv
'Last));
7417 Saved_Gcc
:= new String'(Program_Args.all (1).all);
7419 Gcc := new String'(Program_Args
.all (1).all);
7422 for J
in 2 .. Program_Args
.all'Last loop
7424 (Program_Args
.all (J
).all, Compiler
, And_Save
=> And_Save
);
7428 elsif Argv
'Length > 11
7429 and then Argv
(1 .. 11) = "--GNATBIND="
7432 Program_Args
: constant Argument_List_Access
:=
7433 Argument_String_To_List
7434 (Argv
(12 .. Argv
'Last));
7438 Saved_Gnatbind
:= new String'(Program_Args.all (1).all);
7440 Gnatbind := new String'(Program_Args
.all (1).all);
7443 for J
in 2 .. Program_Args
.all'Last loop
7445 (Program_Args
.all (J
).all, Binder
, And_Save
=> And_Save
);
7449 elsif Argv
'Length > 11
7450 and then Argv
(1 .. 11) = "--GNATLINK="
7453 Program_Args
: constant Argument_List_Access
:=
7454 Argument_String_To_List
7455 (Argv
(12 .. Argv
'Last));
7458 Saved_Gnatlink
:= new String'(Program_Args.all (1).all);
7460 Gnatlink := new String'(Program_Args
.all (1).all);
7463 for J
in 2 .. Program_Args
.all'Last loop
7464 Add_Switch
(Program_Args
.all (J
).all, Linker
);
7468 elsif Argv
'Length >= 5 and then
7469 Argv
(1 .. 5) = "--RTS"
7471 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
7472 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
7474 if Argv
'Length <= 6 or else Argv
(6) /= '=' then
7475 Make_Failed
("missing path for --RTS");
7478 -- Check that this is the first time we see this switch or
7479 -- if it is not the first time, the same path is specified.
7481 if RTS_Specified
= null then
7482 RTS_Specified
:= new String'(Argv (7 .. Argv'Last));
7484 elsif RTS_Specified.all /= Argv (7 .. Argv'Last) then
7485 Make_Failed ("--RTS cannot be specified multiple times");
7488 -- Valid --RTS switch
7495 Src_Path_Name : constant String_Ptr :=
7497 (Argv (7 .. Argv'Last), Include);
7499 Lib_Path_Name : constant String_Ptr :=
7501 (Argv (7 .. Argv'Last), Objects);
7504 if Src_Path_Name /= null
7505 and then Lib_Path_Name /= null
7507 -- Set RTS_*_Path_Name variables, so that correct direct-
7508 -- ories will be set when Osint.Add_Default_Search_Dirs
7511 RTS_Src_Path_Name := Src_Path_Name;
7512 RTS_Lib_Path_Name := Lib_Path_Name;
7514 elsif Src_Path_Name = null
7515 and then Lib_Path_Name = null
7518 ("RTS path not valid: missing adainclude and adalib "
7521 elsif Src_Path_Name = null then
7523 ("RTS path not valid: missing adainclude directory");
7525 elsif Lib_Path_Name = null then
7527 ("RTS path not valid: missing adalib directory");
7532 elsif Argv'Length > Source_Info_Option'Length
7533 and then Argv (1 .. Source_Info_Option'Length) = Source_Info_Option
7535 Project_Tree.Source_Info_File_Name :=
7536 new String'(Argv
(Source_Info_Option
'Length + 1 .. Argv
'Last));
7538 elsif Argv
'Length >= 8 and then Argv
(1 .. 8) = "--param=" then
7539 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
7540 Add_Switch
(Argv
, Linker
, And_Save
=> And_Save
);
7542 elsif Argv
= Create_Map_File_Switch
then
7543 Map_File
:= new String'("");
7545 elsif Argv'Length > Create_Map_File_Switch'Length + 1
7547 Argv (1 .. Create_Map_File_Switch'Length) = Create_Map_File_Switch
7549 Argv (Create_Map_File_Switch'Length + 1) = '='
7553 (Argv
(Create_Map_File_Switch
'Length + 2 .. Argv
'Last));
7556 Scan_Make_Switches
(Env
, Argv
, Success
);
7559 -- If we have seen a regular switch process it
7561 elsif Argv
(1) = '-' then
7562 if Argv
'Length = 1 then
7563 Make_Failed
("switch character cannot be followed by a blank");
7565 -- Incorrect switches that should start with "--"
7567 elsif (Argv
'Length > 5 and then Argv
(1 .. 5) = "-RTS=")
7568 or else (Argv
'Length > 5 and then Argv
(1 .. 5) = "-GCC=")
7569 or else (Argv
'Length > 8 and then Argv
(1 .. 7) = "-param=")
7570 or else (Argv
'Length > 10 and then Argv
(1 .. 10) = "-GNATLINK=")
7571 or else (Argv
'Length > 10 and then Argv
(1 .. 10) = "-GNATBIND=")
7573 Make_Failed
("option " & Argv
& " should start with '--'");
7577 elsif Argv
(2 .. Argv
'Last) = "I-" then
7578 Look_In_Primary_Dir
:= False;
7580 -- Forbid -?- or -??- where ? is any character
7582 elsif (Argv
'Length = 3 and then Argv
(3) = '-')
7583 or else (Argv
'Length = 4 and then Argv
(4) = '-')
7586 ("trailing ""-"" at the end of " & Argv
& " forbidden.");
7590 elsif Argv
(2) = 'I' then
7591 Add_Source_Search_Dir
(Argv
(3 .. Argv
'Last), And_Save
);
7592 Add_Library_Search_Dir
(Argv
(3 .. Argv
'Last), And_Save
);
7593 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
7594 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
7596 -- -aIdir (to gcc this is like a -I switch)
7598 elsif Argv
'Length >= 3 and then Argv
(2 .. 3) = "aI" then
7599 Add_Source_Search_Dir
(Argv
(4 .. Argv
'Last), And_Save
);
7601 ("-I" & Argv
(4 .. Argv
'Last), Compiler
, And_Save
=> And_Save
);
7602 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
7606 elsif Argv
'Length >= 3 and then Argv
(2 .. 3) = "aO" then
7607 Add_Library_Search_Dir
(Argv
(4 .. Argv
'Last), And_Save
);
7608 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
7610 -- -aLdir (to gnatbind this is like a -aO switch)
7612 elsif Argv
'Length >= 3 and then Argv
(2 .. 3) = "aL" then
7613 Mark_Directory
(Argv
(4 .. Argv
'Last), Ada_Lib_Dir
, And_Save
);
7614 Add_Library_Search_Dir
(Argv
(4 .. Argv
'Last), And_Save
);
7616 ("-aO" & Argv
(4 .. Argv
'Last), Binder
, And_Save
=> And_Save
);
7620 elsif Argv
'Length >= 13 and then Argv
(2 .. 13) = "aamp_target=" then
7621 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
7623 -- Set the aamp_target environment variable so that the binder and
7624 -- linker will use the proper target library. This is consistent
7625 -- with how things work when -aamp_target is passed on the command
7626 -- line to gnaampmake.
7628 Setenv
("aamp_target", Argv
(14 .. Argv
'Last));
7630 -- -Adir (to gnatbind this is like a -aO switch, to gcc like a -I)
7632 elsif Argv
(2) = 'A' then
7633 Mark_Directory
(Argv
(3 .. Argv
'Last), Ada_Lib_Dir
, And_Save
);
7634 Add_Source_Search_Dir
(Argv
(3 .. Argv
'Last), And_Save
);
7635 Add_Library_Search_Dir
(Argv
(3 .. Argv
'Last), And_Save
);
7637 ("-I" & Argv
(3 .. Argv
'Last), Compiler
, And_Save
=> And_Save
);
7639 ("-aO" & Argv
(3 .. Argv
'Last), Binder
, And_Save
=> And_Save
);
7643 elsif Argv
(2) = 'L' then
7644 Add_Switch
(Argv
, Linker
, And_Save
=> And_Save
);
7646 -- For -gxxx, -pg, -mxxx, -fxxx, -Oxxx, pass the switch to both the
7647 -- compiler and the linker (except for -gnatxxx which is only for the
7648 -- compiler). Some of the -mxxx (for example -m64) and -fxxx (for
7649 -- example -ftest-coverage for gcov) need to be used when compiling
7650 -- the binder generated files, and using all these gcc switches for
7651 -- them should not be a problem. Pass -Oxxx to the linker for LTO.
7654 (Argv
(2) = 'g' and then (Argv
'Last < 5
7655 or else Argv
(2 .. 5) /= "gnat"))
7656 or else Argv
(2 .. Argv
'Last) = "pg"
7657 or else (Argv
(2) = 'm' and then Argv
'Last > 2)
7658 or else (Argv
(2) = 'f' and then Argv
'Last > 2)
7659 or else Argv
(2) = 'O'
7661 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
7662 Add_Switch
(Argv
, Linker
, And_Save
=> And_Save
);
7664 -- The following condition has to be kept synchronized with
7665 -- the Process_Multilib one.
7668 and then Argv
/= "-mieee"
7670 N_M_Switch
:= N_M_Switch
+ 1;
7673 -- -C=<mapping file>
7675 elsif Argv
'Last > 2 and then Argv
(2) = 'C' then
7677 if Argv
(3) /= '=' or else Argv
'Last <= 3 then
7678 Make_Failed
("illegal switch " & Argv
);
7681 Gnatmake_Mapping_File
:= new String'(Argv (4 .. Argv'Last));
7686 elsif Argv'Last = 2 and then Argv (2) = 'D
' then
7687 if Project_File_Name /= null then
7689 ("-D cannot be used in conjunction with a project file");
7692 Scan_Make_Switches (Env, Argv, Success);
7697 elsif Argv (2) = 'd
' and then Argv'Last = 2 then
7698 Display_Compilation_Progress := True;
7702 elsif Argv'Last = 2 and then Argv (2) = 'i
' then
7703 if Project_File_Name /= null then
7705 ("-i cannot be used in conjunction with a project file");
7707 Scan_Make_Switches (Env, Argv, Success);
7710 -- -j (need to save the result)
7712 elsif Argv (2) = 'j
' then
7713 Scan_Make_Switches (Env, Argv, Success);
7716 Saved_Maximum_Processes := Maximum_Processes;
7721 elsif Argv (2) = 'm
' and then Argv'Last = 2 then
7722 Minimal_Recompilation := True;
7726 elsif Argv (2) = 'u
' and then Argv'Last = 2 then
7727 Unique_Compile := True;
7728 Compile_Only := True;
7729 Do_Bind_Step := False;
7730 Do_Link_Step := False;
7734 elsif Argv (2) = 'U
'
7735 and then Argv'Last = 2
7737 Unique_Compile_All_Projects := True;
7738 Unique_Compile := True;
7739 Compile_Only := True;
7740 Do_Bind_Step := False;
7741 Do_Link_Step := False;
7743 -- -Pprj or -P prj (only once, and only on the command line)
7745 elsif Argv (2) = 'P
' then
7746 if Project_File_Name /= null then
7747 Make_Failed ("cannot have several project files specified");
7749 elsif Object_Directory_Path /= null then
7751 ("-D cannot be used in conjunction with a project file");
7753 elsif In_Place_Mode then
7755 ("-i cannot be used in conjunction with a project file");
7757 elsif not And_Save then
7759 -- It could be a tool other than gnatmake (e.g. gnatdist)
7760 -- or a -P switch inside a project file.
7763 ("either the tool is not ""project-aware"" or "
7764 & "a project file is specified inside a project file");
7766 elsif Argv'Last = 2 then
7768 -- -P is used alone: the project file name is the next option
7770 Project_File_Name_Present := True;
7773 Project_File_Name := new String'(Argv
(3 .. Argv
'Last));
7776 -- -vPx (verbosity of the parsing of the project files)
7778 elsif Argv
'Length >= 3 and then Argv
(2 .. 3) = "vP" then
7779 if Argv
'Last /= 4 or else Argv
(4) not in '0' .. '2' then
7781 ("invalid verbosity level " & Argv
(4 .. Argv
'Last));
7786 Current_Verbosity
:= Prj
.Default
;
7788 Current_Verbosity
:= Prj
.Medium
;
7790 Current_Verbosity
:= Prj
.High
;
7796 -- -Xext=val (External assignment)
7798 elsif Argv
(2) = 'X'
7799 and then Is_External_Assignment
(Env
, Argv
)
7801 -- Is_External_Assignment has side effects when it returns True
7805 -- If -gnath is present, then generate the usage information right
7806 -- now and do not pass this option on to the compiler calls.
7808 elsif Argv
= "-gnath" then
7811 -- If -gnatc is specified, make sure the bind and link steps are not
7814 elsif Argv
'Length >= 6 and then Argv
(2 .. 6) = "gnatc" then
7816 -- If -gnatc is specified, make sure the bind and link steps are
7819 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
7820 Operating_Mode
:= Check_Semantics
;
7821 Check_Object_Consistency
:= False;
7823 -- Except in CodePeer mode (set by -gnatcC), where we do want to
7824 -- call bind/link in CodePeer mode (-P switch).
7826 if Argv
'Last >= 7 and then Argv
(7) = 'C' then
7827 CodePeer_Mode
:= True;
7829 Compile_Only
:= True;
7830 Do_Bind_Step
:= False;
7831 Do_Link_Step
:= False;
7834 -- If -gnatA is specified, make sure that gnat.adc is never read
7836 elsif Argv
'Length >= 6 and then Argv
(2 .. 6) = "gnatA" then
7837 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
7838 Opt
.Config_File
:= False;
7840 elsif Argv
(2 .. Argv
'Last) = "nostdlib" then
7842 -- Pass -nstdlib to gnatbind and gnatlink
7845 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
7846 Add_Switch
(Argv
, Linker
, And_Save
=> And_Save
);
7848 elsif Argv
(2 .. Argv
'Last) = "nostdinc" then
7850 -- Pass -nostdinc to the Compiler and to gnatbind
7853 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
7854 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
7856 -- All other switches are processed by Scan_Make_Switches. If the
7857 -- call returns with Gnatmake_Switch_Found = False, then the switch
7858 -- is passed to the compiler.
7861 Scan_Make_Switches
(Env
, Argv
, Gnatmake_Switch_Found
);
7863 if not Gnatmake_Switch_Found
then
7864 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
7868 -- If not a switch it must be a file name
7872 Main_On_Command_Line
:= True;
7876 Mains
.Add_Main
(Argv
);
7884 function Switches_Of
7885 (Source_File
: File_Name_Type
;
7886 Project
: Project_Id
;
7887 In_Package
: Package_Id
;
7888 Allow_ALI
: Boolean) return Variable_Value
7890 Switches
: Variable_Value
;
7891 Is_Default
: Boolean;
7894 Makeutl
.Get_Switches
7895 (Source_File
=> Source_File
,
7896 Source_Lang
=> Name_Ada
,
7897 Source_Prj
=> Project
,
7898 Pkg_Name
=> Project_Tree
.Shared
.Packages
.Table
(In_Package
).Name
,
7899 Project_Tree
=> Project_Tree
,
7901 Is_Default
=> Is_Default
,
7902 Test_Without_Suffix
=> True,
7903 Check_ALI_Suffix
=> Allow_ALI
);
7913 if Usage_Needed
then
7914 Usage_Needed
:= False;
7920 -- Make sure that in case of failure, the temp files will be deleted
7922 Prj
.Com
.Fail
:= Make_Failed
'Access;
7923 MLib
.Fail
:= Make_Failed
'Access;