1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004 Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
28 with ALI
.Util
; use ALI
.Util
;
32 with Fname
; use Fname
;
33 with Fname
.SF
; use Fname
.SF
;
34 with Fname
.UF
; use Fname
.UF
;
35 with Gnatvsn
; use Gnatvsn
;
36 with Hostparm
; use Hostparm
;
38 with Makeutl
; use Makeutl
;
40 with MLib
.Tgt
; use MLib
.Tgt
;
42 with Namet
; use Namet
;
44 with Osint
.M
; use Osint
.M
;
45 with Osint
; use Osint
;
47 with Output
; use Output
;
55 with Snames
; use Snames
;
56 with Switch
; use Switch
;
57 with Switch
.M
; use Switch
.M
;
61 with Ada
.Exceptions
; use Ada
.Exceptions
;
62 with Ada
.Command_Line
; use Ada
.Command_Line
;
64 with GNAT
.Directory_Operations
; use GNAT
.Directory_Operations
;
65 with GNAT
.Case_Util
; use GNAT
.Case_Util
;
72 -- Make control characters visible
74 Standard_Library_Package_Body_Name
: constant String := "s-stalib.adb";
75 -- Every program depends on this package, that must then be checked,
76 -- especially when -f and -a are used.
78 type Sigint_Handler
is access procedure;
80 procedure Install_Int_Handler
(Handler
: Sigint_Handler
);
81 pragma Import
(C
, Install_Int_Handler
, "__gnat_install_int_handler");
82 -- Called by Gnatmake to install the SIGINT handler below
84 procedure Sigint_Intercepted
;
85 -- Called when the program is interrupted by Ctrl-C to delete the
86 -- temporary mapping files and configuration pragmas files.
88 -------------------------
89 -- Note on terminology --
90 -------------------------
92 -- In this program, we use the phrase "termination" of a file name to
93 -- refer to the suffix that appears after the unit name portion. Very
94 -- often this is simply the extension, but in some cases, the sequence
95 -- may be more complex, for example in main.1.ada, the termination in
96 -- this name is ".1.ada" and in main_.ada the termination is "_.ada".
98 -------------------------------------
99 -- Queue (Q) Manipulation Routines --
100 -------------------------------------
102 -- The Q is used in Compile_Sources below. Its implementation uses the
103 -- GNAT generic package Table (basically an extensible array). Q_Front
104 -- points to the first valid element in the Q, whereas Q.First is the first
105 -- element ever enqueued, while Q.Last - 1 is the last element in the Q.
107 -- +---+--------------+---+---+---+-----------+---+--------
108 -- Q | | ........ | | | | ....... | |
109 -- +---+--------------+---+---+---+-----------+---+--------
111 -- Q.First Q_Front Q.Last - 1
113 -- The elements comprised between Q.First and Q_Front - 1 are the
114 -- elements that have been enqueued and then dequeued, while the
115 -- elements between Q_Front and Q.Last - 1 are the elements currently
116 -- in the Q. When the Q is initialized Q_Front = Q.First = Q.Last.
117 -- After Compile_Sources has terminated its execution, Q_Front = Q.Last
118 -- and the elements contained between Q.Front and Q.Last-1 are those that
119 -- were explored and thus marked by Compile_Sources. Whenever the Q is
120 -- reinitialized, the elements between Q.First and Q.Last - 1 are unmarked.
123 -- Must be called to (re)initialize the Q.
126 (Source_File
: File_Name_Type
;
127 Source_Unit
: Unit_Name_Type
:= No_Name
;
129 -- Inserts Source_File at the end of Q. Provide Source_Unit when possible
130 -- for external use (gnatdist). Provide index for multi-unit sources.
132 function Empty_Q
return Boolean;
133 -- Returns True if Q is empty.
135 procedure Extract_From_Q
136 (Source_File
: out File_Name_Type
;
137 Source_Unit
: out Unit_Name_Type
;
138 Source_Index
: out Int
);
139 -- Extracts the first element from the Q.
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 First_Q_Initialization
: Boolean := True;
154 -- Will be set to false after Init_Q has been called once.
157 -- Points to the first valid element in the Q.
159 Unique_Compile
: Boolean := False;
160 -- Set to True if -u or -U or a project file with no main is used
162 Unique_Compile_All_Projects
: Boolean := False;
163 -- Set to True if -U is used
165 RTS_Specified
: String_Access
:= null;
166 -- Used to detect multiple --RTS= switches
168 type Q_Record
is record
169 File
: File_Name_Type
;
170 Unit
: Unit_Name_Type
;
173 -- File is the name of the file to compile. Unit is for gnatdist
174 -- use in order to easily get the unit name of a file to compile
175 -- when its name is krunched or declared in gnat.adc. Index, when not 0,
176 -- is the index of the unit in a multi-unit source.
178 package Q
is new Table
.Table
(
179 Table_Component_Type
=> Q_Record
,
180 Table_Index_Type
=> Natural,
181 Table_Low_Bound
=> 0,
182 Table_Initial
=> 4000,
183 Table_Increment
=> 100,
184 Table_Name
=> "Make.Q");
185 -- This is the actual Q.
187 -- The following instantiations and variables are necessary to save what
188 -- is found on the command line, in case there is a project file specified.
190 package Saved_Gcc_Switches
is new Table
.Table
(
191 Table_Component_Type
=> String_Access
,
192 Table_Index_Type
=> Integer,
193 Table_Low_Bound
=> 1,
195 Table_Increment
=> 100,
196 Table_Name
=> "Make.Saved_Gcc_Switches");
198 package Saved_Binder_Switches
is new Table
.Table
(
199 Table_Component_Type
=> String_Access
,
200 Table_Index_Type
=> Integer,
201 Table_Low_Bound
=> 1,
203 Table_Increment
=> 100,
204 Table_Name
=> "Make.Saved_Binder_Switches");
206 package Saved_Linker_Switches
is new Table
.Table
207 (Table_Component_Type
=> String_Access
,
208 Table_Index_Type
=> Integer,
209 Table_Low_Bound
=> 1,
211 Table_Increment
=> 100,
212 Table_Name
=> "Make.Saved_Linker_Switches");
214 package Switches_To_Check
is new Table
.Table
(
215 Table_Component_Type
=> String_Access
,
216 Table_Index_Type
=> Integer,
217 Table_Low_Bound
=> 1,
219 Table_Increment
=> 100,
220 Table_Name
=> "Make.Switches_To_Check");
222 package Library_Paths
is new Table
.Table
(
223 Table_Component_Type
=> String_Access
,
224 Table_Index_Type
=> Integer,
225 Table_Low_Bound
=> 1,
227 Table_Increment
=> 100,
228 Table_Name
=> "Make.Library_Paths");
230 package Failed_Links
is new Table
.Table
(
231 Table_Component_Type
=> File_Name_Type
,
232 Table_Index_Type
=> Integer,
233 Table_Low_Bound
=> 1,
235 Table_Increment
=> 100,
236 Table_Name
=> "Make.Failed_Links");
238 package Successful_Links
is new Table
.Table
(
239 Table_Component_Type
=> File_Name_Type
,
240 Table_Index_Type
=> Integer,
241 Table_Low_Bound
=> 1,
243 Table_Increment
=> 100,
244 Table_Name
=> "Make.Successful_Links");
246 package Library_Projs
is new Table
.Table
(
247 Table_Component_Type
=> Project_Id
,
248 Table_Index_Type
=> Integer,
249 Table_Low_Bound
=> 1,
251 Table_Increment
=> 100,
252 Table_Name
=> "Make.Library_Projs");
254 -- Two variables to keep the last binder and linker switch index
255 -- in tables Binder_Switches and Linker_Switches, before adding
256 -- switches from the project file (if any) and switches from the
257 -- command line (if any).
259 Last_Binder_Switch
: Integer := 0;
260 Last_Linker_Switch
: Integer := 0;
262 Normalized_Switches
: Argument_List_Access
:= new Argument_List
(1 .. 10);
263 Last_Norm_Switch
: Natural := 0;
265 Saved_Maximum_Processes
: Natural := 0;
267 type Arg_List_Ref
is access Argument_List
;
268 The_Saved_Gcc_Switches
: Arg_List_Ref
;
270 Project_File_Name
: String_Access
:= null;
271 -- The path name of the main project file, if any
273 Project_File_Name_Present
: Boolean := False;
274 -- True when -P is used with a space between -P and the project file name
276 Current_Verbosity
: Prj
.Verbosity
:= Prj
.Default
;
277 -- Verbosity to parse the project files
279 Main_Project
: Prj
.Project_Id
:= No_Project
;
280 -- The project id of the main project file, if any
282 Project_Object_Directory
: Project_Id
:= No_Project
;
283 -- The object directory of the project for the last compilation.
284 -- Avoid calling Change_Dir if the current working directory is already
287 -- Packages of project files where unknown attributes are errors.
289 Naming_String
: aliased String := "naming";
290 Builder_String
: aliased String := "builder";
291 Compiler_String
: aliased String := "compiler";
292 Binder_String
: aliased String := "binder";
293 Linker_String
: aliased String := "linker";
295 Gnatmake_Packages
: aliased String_List
:=
296 (Naming_String
'Access,
297 Builder_String 'Access,
298 Compiler_String
'Access,
299 Binder_String 'Access,
300 Linker_String
'Access);
302 Packages_To_Check_By_Gnatmake : constant String_List_Access :=
303 Gnatmake_Packages'Access;
305 procedure Add_Source_Dir (N : String);
306 -- Call Add_Src_Search_Dir.
307 -- Output one line when in verbose mode.
309 procedure Add_Source_Directories is
310 new Prj.Env.For_All_Source_Dirs (Action => Add_Source_Dir);
312 procedure Add_Object_Dir (N : String);
313 -- Call Add_Lib_Search_Dir.
314 -- Output one line when in verbose mode.
316 procedure Add_Object_Directories is
317 new Prj.Env.For_All_Object_Dirs (Action => Add_Object_Dir);
319 procedure Change_To_Object_Directory (Project : Project_Id);
320 -- Change to the object directory of project Project, if this is not
321 -- already the current working directory.
323 type Bad_Compilation_Info is record
324 File : File_Name_Type;
325 Unit : Unit_Name_Type;
328 -- File is the name of the file for which a compilation failed.
329 -- Unit is for gnatdist use in order to easily get the unit name
330 -- of a file when its name is krunched or declared in gnat.adc.
331 -- Found is False if the compilation failed because the file could
334 package Bad_Compilation is new Table.Table (
335 Table_Component_Type => Bad_Compilation_Info,
336 Table_Index_Type => Natural,
337 Table_Low_Bound => 1,
339 Table_Increment => 100,
340 Table_Name => "Make.Bad_Compilation");
341 -- Full name of all the source files for which compilation fails.
343 Do_Compile_Step : Boolean := True;
344 Do_Bind_Step : Boolean := True;
345 Do_Link_Step : Boolean := True;
346 -- Flags to indicate what step should be executed.
347 -- Can be set to False with the switches -c, -b and -l.
348 -- These flags are reset to True for each invokation of procedure Gnatmake.
350 Shared_String : aliased String := "-shared";
351 Force_Elab_Flags_String : aliased String := "-F";
353 No_Shared_Switch : aliased Argument_List := (1 .. 0 => null);
354 Shared_Switch : aliased Argument_List := (1 => Shared_String'Access);
355 Bind_Shared : Argument_List_Access := No_Shared_Switch'Access;
356 -- Switch to added in front of gnatbind switches. By default no switch is
357 -- added. Switch "-shared" is added if there is a non-static Library
360 Shared_Libgcc : aliased String := "-shared-libgcc";
362 No_Shared_Libgcc_Switch : aliased Argument_List := (1 .. 0 => null);
363 Shared_Libgcc_Switch : aliased Argument_List :=
364 (1 => Shared_Libgcc'Access);
365 Link_With_Shared_Libgcc : Argument_List_Access :=
366 No_Shared_Libgcc_Switch'Access;
368 procedure Make_Failed (S1 : String; S2 : String := ""; S3 : String := "");
369 -- Delete all temp files created by Gnatmake and call Osint.Fail,
370 -- with the parameter S1, S2 and S3 (see osint.ads).
371 -- This is called from the Prj hierarchy and the MLib hierarchy.
373 --------------------------
374 -- Obsolete Executables --
375 --------------------------
377 Executable_Obsolete : Boolean := False;
378 -- Executable_Obsolete is initially set to False for each executable,
379 -- and is set to True whenever one of the source of the executable is
380 -- compiled, or has already been compiled for another executable.
382 Max_Header : constant := 200;
383 -- This needs a proper comment, it used to say "arbitrary"
384 -- that's not an adequate comment ???
386 type Header_Num is range 1 .. Max_Header;
387 -- Header_Num for the hash table Obsoleted below
389 function Hash (F : Name_Id) return Header_Num;
390 -- Hash function for the hash table Obsoleted below
392 package Obsoleted is new System.HTable.Simple_HTable
393 (Header_Num => Header_Num,
399 -- A hash table to keep all files that have been compiled, to detect
400 -- if an executable is up to date or not.
402 procedure Enter_Into_Obsoleted (F : Name_Id);
403 -- Enter a file name, without directory information, into the has table
406 function Is_In_Obsoleted (F : Name_Id) return Boolean;
407 -- Check if a file name, without directory information, has already been
408 -- entered into the hash table Obsoleted.
410 type Dependency is record
412 Depends_On : Name_Id;
414 -- Components of table Dependencies below.
416 package Dependencies is new Table.Table (
417 Table_Component_Type => Dependency,
418 Table_Index_Type => Integer,
419 Table_Low_Bound => 1,
421 Table_Increment => 100,
422 Table_Name => "Make.Dependencies");
423 -- A table to keep dependencies, to be able to decide if an executable
426 procedure Add_Dependency (S : Name_Id; On : Name_Id);
427 -- Add one entry in table Dependencies
429 ----------------------------
430 -- Arguments and Switches --
431 ----------------------------
433 Arguments : Argument_List_Access;
434 -- Used to gather the arguments for invocation of the compiler
436 Last_Argument : Natural := 0;
437 -- Last index of arguments in Arguments above
439 Arguments_Collected : Boolean := False;
440 -- Set to True when the arguments for the next invocation of the compiler
441 -- have been collected.
443 Arguments_Project : Project_Id;
444 -- Project id, if any, of the source to be compiled
446 Arguments_Path_Name : File_Name_Type;
447 -- Full path of the source to be compiled, when Arguments_Project is not
450 Dummy_Switch : constant String_Access := new String'("- ");
451 -- Used to initialized Prev_Switch in procedure Check
453 procedure Add_Arguments
(Args
: Argument_List
);
454 -- Add arguments to global variable Arguments, increasing its size
455 -- if necessary and adjusting Last_Argument.
457 function Configuration_Pragmas_Switch
458 (For_Project
: Project_Id
) return Argument_List
;
459 -- Return an argument list of one element, if there is a configuration
460 -- pragmas file to be specified for For_Project,
461 -- otherwise return an empty argument list.
467 procedure List_Depend
;
468 -- Prints to standard output the list of object dependencies. This list
469 -- can be used directly in a Makefile. A call to Compile_Sources must
470 -- precede the call to List_Depend. Also because this routine uses the
471 -- ALI files that were originally loaded and scanned by Compile_Sources,
472 -- no additional ALI files should be scanned between the two calls (i.e.
473 -- between the call to Compile_Sources and List_Depend.)
475 procedure Inform
(N
: Name_Id
:= No_Name
; Msg
: String);
476 -- Prints out the program name followed by a colon, N and S.
478 procedure List_Bad_Compilations
;
479 -- Prints out the list of all files for which the compilation failed.
481 procedure Verbose_Msg
484 N2
: Name_Id
:= No_Name
;
486 Prefix
: String := " -> ");
487 -- If the verbose flag (Verbose_Mode) is set then print Prefix to standard
488 -- output followed by N1 and S1. If N2 /= No_Name then N2 is then printed
489 -- after S1. S2 is printed last. Both N1 and N2 are printed in quotation
492 Usage_Needed
: Boolean := True;
493 -- Flag used to make sure Makeusg is call at most once
496 -- Call Makeusg, if Usage_Needed is True.
497 -- Set Usage_Needed to False.
499 procedure Debug_Msg
(S
: String; N
: Name_Id
);
500 -- If Debug.Debug_Flag_W is set outputs string S followed by name N.
502 procedure Recursive_Compute_Depth
503 (Project
: Project_Id
;
505 -- Compute depth of Project and of the projects it depends on
507 -----------------------
508 -- Gnatmake Routines --
509 -----------------------
511 Gnatmake_Called
: Boolean := False;
512 -- Set to True when procedure Gnatmake is called.
513 -- Attempt to delete temporary files is made only when Gnatmake_Called
516 subtype Lib_Mark_Type
is Byte
;
517 -- Used in Mark_Directory
519 Ada_Lib_Dir
: constant Lib_Mark_Type
:= 1;
520 -- Used to mark a directory as a GNAT lib dir
522 -- Note that the notion of GNAT lib dir is no longer used. The code
523 -- related to it has not been removed to give an idea on how to use
524 -- the directory prefix marking mechanism.
526 -- An Ada library directory is a directory containing ali and object
527 -- files but no source files for the bodies (the specs can be in the
528 -- same or some other directory). These directories are specified
529 -- in the Gnatmake command line with the switch "-Adir" (to specify the
530 -- spec location -Idir cab be used). Gnatmake skips the missing sources
531 -- whose ali are in Ada library directories. For an explanation of why
532 -- Gnatmake behaves that way, see the spec of Make.Compile_Sources.
533 -- The directory lookup penalty is incurred every single time this
534 -- routine is called.
536 procedure Check_Steps
;
537 -- Check what steps (Compile, Bind, Link) must be executed.
538 -- Set the step flags accordingly.
540 function In_Ada_Lib_Dir
(File
: File_Name_Type
) return Boolean;
541 -- Get directory prefix of this file and get lib mark stored in name
542 -- table for this directory. Then check if an Ada lib mark has been set.
544 procedure Mark_Directory
546 Mark
: Lib_Mark_Type
);
547 -- Store Dir in name table and set lib mark as name info to identify
550 Output_Is_Object
: Boolean := True;
551 -- Set to False when using a switch -S for the compiler
553 procedure Check_For_S_Switch
;
554 -- Set Output_Is_Object to False when the -S switch is used for the
558 (Source_File
: Name_Id
;
559 Source_File_Name
: String;
561 Naming
: Naming_Data
;
562 In_Package
: Package_Id
;
563 Allow_ALI
: Boolean) return Variable_Value
;
564 -- Return the switches for the source file in the specified package
565 -- of a project file. If the Source_File ends with a standard GNAT
566 -- extension (".ads" or ".adb"), try first the full name, then the
567 -- name without the extension, then, if Allow_ALI is True, the name with
568 -- the extension ".ali". If there is no switches for either names, try the
569 -- default switches for Ada. If all failed, return No_Variable_Value.
571 function Is_In_Object_Directory
572 (Source_File
: File_Name_Type
;
573 Full_Lib_File
: File_Name_Type
) return Boolean;
574 -- Check if, when using a project file, the ALI file is in the project
575 -- directory of the ultimate extending project. If it is not, we ignore
576 -- the fact that this ALI file is read-only.
578 ----------------------------------------------------
579 -- Compiler, Binder & Linker Data and Subprograms --
580 ----------------------------------------------------
582 Gcc
: String_Access
:= Program_Name
("gcc");
583 Gnatbind
: String_Access
:= Program_Name
("gnatbind");
584 Gnatlink
: String_Access
:= Program_Name
("gnatlink");
585 -- Default compiler, binder, linker programs
587 Saved_Gcc
: String_Access
:= null;
588 Saved_Gnatbind
: String_Access
:= null;
589 Saved_Gnatlink
: String_Access
:= null;
590 -- Given by the command line. Will be used, if non null.
592 Gcc_Path
: String_Access
:=
593 GNAT
.OS_Lib
.Locate_Exec_On_Path
(Gcc
.all);
594 Gnatbind_Path
: String_Access
:=
595 GNAT
.OS_Lib
.Locate_Exec_On_Path
(Gnatbind
.all);
596 Gnatlink_Path
: String_Access
:=
597 GNAT
.OS_Lib
.Locate_Exec_On_Path
(Gnatlink
.all);
598 -- Path for compiler, binder, linker programs, defaulted now for gnatdist.
599 -- Changed later if overridden on command line.
601 Comp_Flag
: constant String_Access
:= new String'("-c");
602 Output_Flag : constant String_Access := new String'("-o");
603 Ada_Flag_1
: constant String_Access
:= new String'("-x");
604 Ada_Flag_2 : constant String_Access := new String'("ada");
605 No_gnat_adc
: constant String_Access
:= new String'("-gnatA");
606 GNAT_Flag : constant String_Access := new String'("-gnatpg");
607 Do_Not_Check_Flag
: constant String_Access
:= new String'("-x");
609 Object_Suffix : constant String := Get_Object_Suffix.all;
610 Executable_Suffix : constant String := Get_Executable_Suffix.all;
612 Syntax_Only : Boolean := False;
613 -- Set to True when compiling with -gnats
615 Display_Executed_Programs : Boolean := True;
616 -- Set to True if name of commands should be output on stderr.
618 Output_File_Name_Seen : Boolean := False;
619 -- Set to True after having scanned the file_name for
620 -- switch "-o file_name"
622 Object_Directory_Seen : Boolean := False;
623 -- Set to True after having scanned the object directory for
624 -- switch "-D obj_dir".
626 Object_Directory_Path : String_Access := null;
627 -- The path name of the object directory, set with switch -D.
629 type Make_Program_Type is (None, Compiler, Binder, Linker);
631 Program_Args : Make_Program_Type := None;
632 -- Used to indicate if we are scanning gnatmake, gcc, gnatbind, or gnatbind
633 -- options within the gnatmake command line.
634 -- Used in Scan_Make_Arg only, but must be a global variable.
636 Temporary_Config_File : Boolean := False;
637 -- Set to True when there is a temporary config file used for a project
638 -- file, to avoid displaying the -gnatec switch for a temporary file.
640 procedure Add_Switches
641 (The_Package : Package_Id;
644 Program : Make_Program_Type);
647 Program : Make_Program_Type;
648 Append_Switch : Boolean := True;
649 And_Save : Boolean := True);
652 Program : Make_Program_Type;
653 Append_Switch : Boolean := True;
654 And_Save : Boolean := True);
655 -- Make invokes one of three programs (the compiler, the binder or the
656 -- linker). For the sake of convenience, some program specific switches
657 -- can be passed directly on the gnatmake commande line. This procedure
658 -- records these switches so that gnamake can pass them to the right
659 -- program. S is the switch to be added at the end of the command line
660 -- for Program if Append_Switch is True. If Append_Switch is False S is
661 -- added at the beginning of the command line.
664 (Source_File : File_Name_Type;
666 The_Args : Argument_List;
667 Lib_File : File_Name_Type;
670 O_File : out File_Name_Type;
671 O_Stamp : out Time_Stamp_Type);
672 -- Determines whether the library file Lib_File is up-to-date or not. The
673 -- full name (with path information) of the object file corresponding to
674 -- Lib_File is returned in O_File. Its time stamp is saved in O_Stamp.
675 -- ALI is the ALI_Id corresponding to Lib_File. If Lib_File in not
676 -- up-to-date, then the corresponding source file needs to be recompiled.
677 -- In this case ALI = No_ALI_Id.
679 procedure Check_Linker_Options
680 (E_Stamp : Time_Stamp_Type;
681 O_File : out File_Name_Type;
682 O_Stamp : out Time_Stamp_Type);
683 -- Checks all linker options for linker files that are newer
684 -- than E_Stamp. If such objects are found, the youngest object
685 -- is returned in O_File and its stamp in O_Stamp.
687 -- If no obsolete linker files were found, the first missing
688 -- linker file is returned in O_File and O_Stamp is empty.
689 -- Otherwise O_File is No_File.
691 procedure Collect_Arguments
692 (Source_File : File_Name_Type;
694 Args : Argument_List);
695 -- Collect all arguments for a source to be compiled, including those
696 -- that come from a project file.
698 procedure Display (Program : String; Args : Argument_List);
699 -- Displays Program followed by the arguments in Args if variable
700 -- Display_Executed_Programs is set. The lower bound of Args must be 1.
706 type Temp_File_Names is
707 array (Project_Id range <>, Positive range <>) of Name_Id;
709 type Temp_Files_Ptr is access Temp_File_Names;
711 type Indices is array (Project_Id range <>) of Natural;
713 type Indices_Ptr is access Indices;
715 type Free_File_Indices is array
716 (Project_Id range <>, Positive range <>) of Positive;
718 type Free_Indices_Ptr is access Free_File_Indices;
720 The_Mapping_File_Names : Temp_Files_Ptr;
721 -- For each project, the name ids of the temporary mapping files used
723 Last_Mapping_File_Names : Indices_Ptr;
724 -- For each project, the index of the last mapping file created
726 The_Free_Mapping_File_Indices : Free_Indices_Ptr;
727 -- For each project, the indices in The_Mapping_File_Names of the mapping
728 -- file names that can be reused for subsequent compilations.
730 Last_Free_Indices : Indices_Ptr;
731 -- For each project, the number of mapping files that can be reused
733 Gnatmake_Mapping_File : String_Access := null;
734 -- The path name of a mapping file specified by switch -C=
736 procedure Delete_Mapping_Files;
737 -- Delete all temporary mapping files
739 procedure Init_Mapping_File
740 (Project : Project_Id;
741 File_Index : in out Natural);
742 -- Create a new temporary mapping file, and fill it with the project file
743 -- mappings, when using project file(s). The out parameter File_Index is
744 -- the index to the name of the file in the array The_Mapping_File_Names.
746 procedure Delete_Temp_Config_Files;
747 -- Delete all temporary config files
749 procedure Delete_All_Temp_Files;
750 -- Delete all temp files (config files, mapping files, path files)
756 procedure Add_Arguments (Args : Argument_List) is
758 if Arguments = null then
759 Arguments := new Argument_List (1 .. Args'Length + 10);
762 while Last_Argument + Args'Length > Arguments'Last loop
764 New_Arguments : constant Argument_List_Access :=
765 new Argument_List (1 .. Arguments'Last * 2);
767 New_Arguments (1 .. Last_Argument) :=
768 Arguments (1 .. Last_Argument);
769 Arguments := New_Arguments;
774 Arguments (Last_Argument + 1 .. Last_Argument + Args'Length) := Args;
775 Last_Argument := Last_Argument + Args'Length;
782 procedure Add_Dependency (S : Name_Id; On : Name_Id) is
784 Dependencies.Increment_Last;
785 Dependencies.Table (Dependencies.Last) := (S, On);
792 procedure Add_Object_Dir (N : String) is
794 Add_Lib_Search_Dir (N);
797 Write_Str ("Adding object directory """);
808 procedure Add_Source_Dir (N : String) is
810 Add_Src_Search_Dir (N);
813 Write_Str ("Adding source directory """);
826 Program : Make_Program_Type;
827 Append_Switch : Boolean := True;
828 And_Save : Boolean := True)
831 with package T is new Table.Table (<>);
832 procedure Generic_Position (New_Position : out Integer);
833 -- Generic procedure that chooses a position for S in T at the
834 -- beginning or the end, depending on the boolean Append_Switch.
835 -- Calling this procedure may expand the table.
837 ----------------------
838 -- Generic_Position --
839 ----------------------
841 procedure Generic_Position (New_Position : out Integer) is
845 if Append_Switch then
846 New_Position := Integer (T.Last);
848 for J in reverse T.Table_Index_Type'Succ (T.First) .. T.Last loop
849 T.Table (J) := T.Table (T.Table_Index_Type'Pred (J));
852 New_Position := Integer (T.First);
854 end Generic_Position;
856 procedure Gcc_Switches_Pos is new Generic_Position (Gcc_Switches);
857 procedure Binder_Switches_Pos is new Generic_Position (Binder_Switches);
858 procedure Linker_Switches_Pos is new Generic_Position (Linker_Switches);
860 procedure Saved_Gcc_Switches_Pos is new
861 Generic_Position (Saved_Gcc_Switches);
863 procedure Saved_Binder_Switches_Pos is new
864 Generic_Position (Saved_Binder_Switches);
866 procedure Saved_Linker_Switches_Pos is new
867 Generic_Position (Saved_Linker_Switches);
869 New_Position : Integer;
871 -- Start of processing for Add_Switch
877 Saved_Gcc_Switches_Pos (New_Position);
878 Saved_Gcc_Switches.Table (New_Position) := S;
881 Saved_Binder_Switches_Pos (New_Position);
882 Saved_Binder_Switches.Table (New_Position) := S;
885 Saved_Linker_Switches_Pos (New_Position);
886 Saved_Linker_Switches.Table (New_Position) := S;
895 Gcc_Switches_Pos (New_Position);
896 Gcc_Switches.Table (New_Position) := S;
899 Binder_Switches_Pos (New_Position);
900 Binder_Switches.Table (New_Position) := S;
903 Linker_Switches_Pos (New_Position);
904 Linker_Switches.Table (New_Position) := S;
914 Program : Make_Program_Type;
915 Append_Switch : Boolean := True;
916 And_Save : Boolean := True)
919 Add_Switch (S => new String'(S
),
921 Append_Switch
=> Append_Switch
,
922 And_Save
=> And_Save
);
929 procedure Add_Switches
930 (The_Package
: Package_Id
;
933 Program
: Make_Program_Type
)
935 Switches
: Variable_Value
;
936 Switch_List
: String_List_Id
;
937 Element
: String_Element
;
940 if File_Name
'Length > 0 then
941 Name_Len
:= File_Name
'Length;
942 Name_Buffer
(1 .. Name_Len
) := File_Name
;
945 (Source_File
=> Name_Find
,
946 Source_File_Name
=> File_Name
,
947 Source_Index
=> Index
,
948 Naming
=> Projects
.Table
(Main_Project
).Naming
,
949 In_Package
=> The_Package
,
951 Program
= Binder
or else Program
= Linker
);
953 case Switches
.Kind
is
958 Program_Args
:= Program
;
960 Switch_List
:= Switches
.Values
;
962 while Switch_List
/= Nil_String
loop
963 Element
:= String_Elements
.Table
(Switch_List
);
964 Get_Name_String
(Element
.Value
);
968 Argv
: constant String := Name_Buffer
(1 .. Name_Len
);
969 -- We need a copy, because Name_Buffer may be
974 Write_Str
(" Adding ");
978 Scan_Make_Arg
(Argv
, And_Save
=> False);
982 Switch_List
:= Element
.Next
;
986 Program_Args
:= Program
;
987 Get_Name_String
(Switches
.Value
);
991 Argv
: constant String := Name_Buffer
(1 .. Name_Len
);
992 -- We need a copy, because Name_Buffer may be modified
996 Write_Str
(" Adding ");
1000 Scan_Make_Arg
(Argv
, And_Save
=> False);
1011 procedure Bind
(ALI_File
: File_Name_Type
; Args
: Argument_List
) is
1012 Bind_Args
: Argument_List
(1 .. Args
'Last + 2);
1013 Bind_Last
: Integer;
1017 pragma Assert
(Args
'First = 1);
1019 -- Optimize the simple case where the gnatbind command line looks like
1020 -- gnatbind -aO. -I- file.ali --into-> gnatbind file.adb
1023 and then Args
(Args
'First).all = "-aO" & Normalized_CWD
1024 and then Args
(Args
'Last).all = "-I-"
1025 and then ALI_File
= Strip_Directory
(ALI_File
)
1027 Bind_Last
:= Args
'First - 1;
1030 Bind_Last
:= Args
'Last;
1031 Bind_Args
(Args
'Range) := Args
;
1034 -- It is completely pointless to re-check source file time stamps.
1035 -- This has been done already by gnatmake
1037 Bind_Last
:= Bind_Last
+ 1;
1038 Bind_Args
(Bind_Last
) := Do_Not_Check_Flag
;
1040 Get_Name_String
(ALI_File
);
1042 Bind_Last
:= Bind_Last
+ 1;
1043 Bind_Args
(Bind_Last
) := new String'(Name_Buffer (1 .. Name_Len));
1045 GNAT.OS_Lib.Normalize_Arguments (Bind_Args (Args'First .. Bind_Last));
1047 Display (Gnatbind.all, Bind_Args (Args'First .. Bind_Last));
1049 if Gnatbind_Path = null then
1050 Make_Failed ("error, unable to locate ", Gnatbind.all);
1054 (Gnatbind_Path.all, Bind_Args (Args'First .. Bind_Last), Success);
1061 --------------------------------
1062 -- Change_To_Object_Directory --
1063 --------------------------------
1065 procedure Change_To_Object_Directory (Project : Project_Id) is
1067 -- Nothing to do if the current working directory is alresdy the one
1070 if Project_Object_Directory /= Project then
1071 Project_Object_Directory := Project;
1073 -- If in a real project, set the working directory to the object
1074 -- directory of the project.
1076 if Project /= No_Project then
1078 (Get_Name_String (Projects.Table (Project).Object_Directory));
1080 -- Otherwise, for sources outside of any project, set the working
1081 -- directory to the object directory of the main project.
1083 elsif Main_Project /= No_Project then
1086 (Projects.Table (Main_Project).Object_Directory));
1089 end Change_To_Object_Directory;
1096 (Source_File : File_Name_Type;
1098 The_Args : Argument_List;
1099 Lib_File : File_Name_Type;
1100 Read_Only : Boolean;
1102 O_File : out File_Name_Type;
1103 O_Stamp : out Time_Stamp_Type)
1105 function First_New_Spec (A : ALI_Id) return File_Name_Type;
1106 -- Looks in the with table entries of A and returns the spec file name
1107 -- of the first withed unit (subprogram) for which no spec existed when
1108 -- A was generated but for which there exists one now, implying that A
1109 -- is now obsolete. If no such unit is found No_File is returned.
1110 -- Otherwise the spec file name of the unit is returned.
1112 -- **WARNING** in the event of Uname format modifications, one *MUST*
1113 -- make sure this function is also updated.
1115 -- Note: This function should really be in ali.adb and use Uname
1116 -- services, but this causes the whole compiler to be dragged along
1117 -- for gnatbind and gnatmake.
1119 --------------------
1120 -- First_New_Spec --
1121 --------------------
1123 function First_New_Spec (A : ALI_Id) return File_Name_Type is
1124 Spec_File_Name : File_Name_Type := No_File;
1126 function New_Spec (Uname : Unit_Name_Type) return Boolean;
1127 -- Uname is the name of the spec or body of some ada unit.
1128 -- This function returns True if the Uname is the name of a body
1129 -- which has a spec not mentioned inali file A. If True is returned
1130 -- Spec_File_Name above is set to the name of this spec file.
1136 function New_Spec (Uname : Unit_Name_Type) return Boolean is
1137 Spec_Name : Unit_Name_Type;
1138 File_Name : File_Name_Type;
1141 -- Test whether Uname is the name of a body unit (ie ends with %b)
1143 Get_Name_String (Uname);
1145 Assert (Name_Len > 2 and then Name_Buffer (Name_Len - 1) = '%');
1147 if Name_Buffer (Name_Len) /= 'b
' then
1151 -- Convert unit name into spec name
1153 -- ??? this code seems dubious in presence of pragma
1154 -- Source_File_Name since there is no more direct relationship
1155 -- between unit name and file name.
1157 -- ??? Further, what about alternative subunit naming
1159 Name_Buffer (Name_Len) := 's
';
1160 Spec_Name := Name_Find;
1161 File_Name := Get_File_Name (Spec_Name, Subunit => False);
1163 -- Look if File_Name is mentioned in A's sdep list.
1164 -- If not look if the file exists. If it does return True.
1167 ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep
1169 if Sdep.Table (D).Sfile = File_Name then
1174 if Full_Source_Name (File_Name) /= No_File then
1175 Spec_File_Name := File_Name;
1182 -- Start of processing for First_New_Spec
1186 ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit
1188 exit U_Chk when Units.Table (U).Utype = Is_Body_Only
1189 and then New_Spec (Units.Table (U).Uname);
1191 for W in Units.Table (U).First_With
1193 Units.Table (U).Last_With
1196 Withs.Table (W).Afile /= No_File
1197 and then New_Spec (Withs.Table (W).Uname);
1201 return Spec_File_Name;
1204 ---------------------------------
1205 -- Data declarations for Check --
1206 ---------------------------------
1208 Full_Lib_File : File_Name_Type;
1209 -- Full name of current library file
1211 Full_Obj_File : File_Name_Type;
1212 -- Full name of the object file corresponding to Lib_File.
1214 Lib_Stamp : Time_Stamp_Type;
1215 -- Time stamp of the current ada library file.
1217 Obj_Stamp : Time_Stamp_Type;
1218 -- Time stamp of the current object file.
1220 Modified_Source : File_Name_Type;
1221 -- The first source in Lib_File whose current time stamp differs
1222 -- from that stored in Lib_File.
1224 New_Spec : File_Name_Type;
1225 -- If Lib_File contains in its W (with) section a body (for a
1226 -- subprogram) for which there exists a spec and the spec did not
1227 -- appear in the Sdep section of Lib_File, New_Spec contains the file
1228 -- name of this new spec.
1230 Source_Name : Name_Id;
1231 Text : Text_Buffer_Ptr;
1233 Prev_Switch : String_Access;
1234 -- Previous switch processed
1236 Arg : Arg_Id := Arg_Id'First;
1237 -- Current index in Args.Table for a given unit (init to stop warning)
1239 Switch_Found : Boolean;
1240 -- True if a given switch has been found
1242 -- Start of processing for Check
1245 pragma Assert (Lib_File /= No_File);
1247 -- If the ALI file is read-only, set temporarily
1248 -- Check_Object_Consistency to False: we don't care if the object file
1249 -- is not there; presumably, a library will be used for linking.
1253 Saved_Check_Object_Consistency : constant Boolean :=
1254 Check_Object_Consistency;
1256 Check_Object_Consistency := False;
1257 Text := Read_Library_Info (Lib_File);
1258 Check_Object_Consistency := Saved_Check_Object_Consistency;
1262 Text := Read_Library_Info (Lib_File);
1265 Full_Lib_File := Full_Library_Info_Name;
1266 Full_Obj_File := Full_Object_File_Name;
1267 Lib_Stamp := Current_Library_File_Stamp;
1268 Obj_Stamp := Current_Object_File_Stamp;
1270 if Full_Lib_File = No_File then
1271 Verbose_Msg (Lib_File, "being checked ...", Prefix => " ");
1273 Verbose_Msg (Full_Lib_File, "being checked ...", Prefix => " ");
1277 O_File := Full_Obj_File;
1278 O_Stamp := Obj_Stamp;
1281 if Full_Lib_File = No_File then
1282 Verbose_Msg (Lib_File, "missing.");
1284 elsif Obj_Stamp (Obj_Stamp'First) = ' ' then
1285 Verbose_Msg (Full_Obj_File, "missing.");
1289 (Full_Lib_File, "(" & String (Lib_Stamp) & ") newer than",
1290 Full_Obj_File, "(" & String (Obj_Stamp) & ")");
1294 ALI := Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
1297 if ALI = No_ALI_Id then
1298 Verbose_Msg (Full_Lib_File, "incorrectly formatted ALI file");
1301 elsif ALIs.Table (ALI).Ver (1 .. ALIs.Table (ALI).Ver_Len) /=
1302 Verbose_Library_Version
1304 Verbose_Msg (Full_Lib_File, "compiled with old GNAT version");
1309 -- Don't take Ali file into account if it was generated with
1312 if ALIs.Table (ALI).Compile_Errors then
1313 Verbose_Msg (Full_Lib_File, "had errors, must be recompiled");
1318 -- Don't take Ali file into account if it was generated without
1321 if Operating_Mode /= Check_Semantics
1322 and then ALIs.Table (ALI).No_Object
1324 Verbose_Msg (Full_Lib_File, "has no corresponding object");
1329 -- Check for matching compiler switches if needed
1331 if Check_Switches then
1333 -- First, collect all the switches
1335 Collect_Arguments (Source_File, Source_Index, The_Args);
1337 Prev_Switch := Dummy_Switch;
1339 Get_Name_String (ALIs.Table (ALI).Sfile);
1341 Switches_To_Check.Set_Last (0);
1343 for J in 1 .. Last_Argument loop
1345 -- Skip non switches -c, -I and -o switches
1347 if Arguments (J) (1) = '-'
1348 and then Arguments (J) (2) /= 'c
'
1349 and then Arguments (J) (2) /= 'o
'
1350 and then Arguments (J) (2) /= 'I
'
1352 Normalize_Compiler_Switches
1354 Normalized_Switches,
1357 for K in 1 .. Last_Norm_Switch loop
1358 Switches_To_Check.Increment_Last;
1359 Switches_To_Check.Table (Switches_To_Check.Last) :=
1360 Normalized_Switches (K);
1365 for J in 1 .. Switches_To_Check.Last loop
1367 -- Comparing switches is delicate because gcc reorders
1368 -- a number of switches, according to lang-specs.h, but
1369 -- gnatmake doesn't have the sufficient knowledge to
1370 -- perform the same reordering. Instead, we ignore orders
1371 -- between different "first letter" switches, but keep
1372 -- orders between same switches, e.g -O -O2 is different
1373 -- than -O2 -O, but -g -O is equivalent to -O -g.
1375 if Switches_To_Check.Table (J) (2) /= Prev_Switch (2) or else
1376 (Prev_Switch'Length >= 6 and then
1377 Prev_Switch (2 .. 5) = "gnat" and then
1378 Switches_To_Check.Table (J)'Length >= 6 and then
1379 Switches_To_Check.Table (J) (2 .. 5) = "gnat" and then
1380 Prev_Switch (6) /= Switches_To_Check.Table (J) (6))
1382 Prev_Switch := Switches_To_Check.Table (J);
1384 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg;
1387 Switch_Found := False;
1390 Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1393 Switches_To_Check.Table (J).all = Args.Table (K).all
1396 Switch_Found := True;
1401 if not Switch_Found then
1402 if Verbose_Mode then
1403 Verbose_Msg (ALIs.Table (ALI).Sfile,
1404 "switch mismatch """ &
1405 Switches_To_Check.Table (J).all & '"');
1413 if Switches_To_Check.Last /=
1414 Integer (Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg -
1415 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg + 1)
1417 if Verbose_Mode then
1418 Verbose_Msg (ALIs.Table (ALI).Sfile,
1419 "different number
of switches
");
1421 for K in Units.Table (ALIs.Table (ALI).First_Unit).First_Arg
1422 .. Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1424 Write_Str (Args.Table (K).all);
1430 for J in 1 .. Switches_To_Check.Last loop
1431 Write_Str (Switches_To_Check.Table (J).all);
1443 -- Get the source files and their message digests. Note that some
1444 -- sources may be missing if ALI is out-of-date.
1446 Set_Source_Table (ALI);
1448 Modified_Source := Time_Stamp_Mismatch (ALI, Read_Only);
1450 if Modified_Source /= No_File then
1453 if Verbose_Mode then
1454 Source_Name := Full_Source_Name (Modified_Source);
1456 if Source_Name /= No_File then
1457 Verbose_Msg (Source_Name, "time stamp mismatch
");
1459 Verbose_Msg (Modified_Source, "missing
");
1464 New_Spec := First_New_Spec (ALI);
1466 if New_Spec /= No_File then
1469 if Verbose_Mode then
1470 Source_Name := Full_Source_Name (New_Spec);
1472 if Source_Name /= No_File then
1473 Verbose_Msg (Source_Name, "new spec
");
1475 Verbose_Msg (New_Spec, "old spec missing
");
1483 ------------------------
1484 -- Check_For_S_Switch --
1485 ------------------------
1487 procedure Check_For_S_Switch is
1489 -- By default, we generate an object file
1491 Output_Is_Object := True;
1493 for Arg in 1 .. Last_Argument loop
1494 if Arguments (Arg).all = "-S
" then
1495 Output_Is_Object := False;
1497 elsif Arguments (Arg).all = "-c
" then
1498 Output_Is_Object := True;
1501 end Check_For_S_Switch;
1503 --------------------------
1504 -- Check_Linker_Options --
1505 --------------------------
1507 procedure Check_Linker_Options
1508 (E_Stamp : Time_Stamp_Type;
1509 O_File : out File_Name_Type;
1510 O_Stamp : out Time_Stamp_Type)
1512 procedure Check_File (File : File_Name_Type);
1513 -- Update O_File and O_Stamp if the given file is younger than E_Stamp
1514 -- and O_Stamp, or if O_File is No_File and File does not exist.
1516 function Get_Library_File (Name : String) return File_Name_Type;
1517 -- Return the full file name including path of a library based
1518 -- on the name specified with the -l linker option, using the
1519 -- Ada object path. Return No_File if no such file can be found.
1521 type Char_Array is array (Natural) of Character;
1522 type Char_Array_Access is access constant Char_Array;
1524 Template : Char_Array_Access;
1525 pragma Import (C, Template, "__gnat_library_template
");
1531 procedure Check_File (File : File_Name_Type) is
1532 Stamp : Time_Stamp_Type;
1533 Name : File_Name_Type := File;
1536 Get_Name_String (Name);
1538 -- Remove any trailing NUL characters
1540 while Name_Len >= Name_Buffer'First
1541 and then Name_Buffer (Name_Len) = NUL
1543 Name_Len := Name_Len - 1;
1546 if Name_Len <= 0 then
1549 elsif Name_Buffer (1) = '-' then
1551 -- Do not check if File is a switch other than "-l
"
1553 if Name_Buffer (2) /= 'l' then
1557 -- The argument is a library switch, get actual name. It
1558 -- is necessary to make a copy of the relevant part of
1559 -- Name_Buffer as Get_Library_Name uses Name_Buffer as well.
1562 Base_Name : constant String := Name_Buffer (3 .. Name_Len);
1565 Name := Get_Library_File (Base_Name);
1568 if Name = No_File then
1573 Stamp := File_Stamp (Name);
1575 -- Find the youngest object file that is younger than the
1576 -- executable. If no such file exist, record the first object
1577 -- file that is not found.
1579 if (O_Stamp < Stamp and then E_Stamp < Stamp)
1580 or else (O_File = No_File and then Stamp (Stamp'First) = ' ')
1585 -- Strip the trailing NUL if present
1587 Get_Name_String (O_File);
1589 if Name_Buffer (Name_Len) = NUL then
1590 Name_Len := Name_Len - 1;
1591 O_File := Name_Find;
1596 ----------------------
1597 -- Get_Library_Name --
1598 ----------------------
1600 -- See comments in a-adaint.c about template syntax
1602 function Get_Library_File (Name : String) return File_Name_Type is
1603 File : File_Name_Type := No_File;
1608 for Ptr in Template'Range loop
1609 case Template (Ptr) is
1611 Add_Str_To_Name_Buffer (Name);
1614 File := Full_Lib_File_Name (Name_Find);
1615 exit when File /= No_File;
1622 Add_Char_To_Name_Buffer (Template (Ptr));
1626 -- The for loop exited because the end of the template
1627 -- was reached. File contains the last possible file name
1630 if File = No_File and then Name_Len > 0 then
1631 File := Full_Lib_File_Name (Name_Find);
1635 end Get_Library_File;
1637 -- Start of processing for Check_Linker_Options
1641 O_Stamp := (others => ' ');
1643 -- Process linker options from the ALI files.
1645 for Opt in 1 .. Linker_Options.Last loop
1646 Check_File (Linker_Options.Table (Opt).Name);
1649 -- Process options given on the command line.
1651 for Opt in Linker_Switches.First .. Linker_Switches.Last loop
1653 -- Check if the previous Opt has one of the two switches
1654 -- that take an extra parameter. (See GCC manual.)
1656 if Opt = Linker_Switches.First
1657 or else (Linker_Switches.Table (Opt - 1).all /= "-u
"
1659 Linker_Switches.Table (Opt - 1).all /= "-Xlinker
"
1661 Linker_Switches.Table (Opt - 1).all /= "-L
")
1664 Add_Str_To_Name_Buffer (Linker_Switches.Table (Opt).all);
1665 Check_File (Name_Find);
1669 end Check_Linker_Options;
1675 procedure Check_Steps is
1677 -- If either -c, -b or -l has been specified, we will not necessarily
1678 -- execute all steps.
1681 Do_Compile_Step := Do_Compile_Step and Compile_Only;
1682 Do_Bind_Step := Do_Bind_Step and Bind_Only;
1683 Do_Link_Step := Do_Link_Step and Link_Only;
1685 -- If -c has been specified, but not -b, ignore any potential -l
1687 if Do_Compile_Step and then not Do_Bind_Step then
1688 Do_Link_Step := False;
1693 -----------------------
1694 -- Collect_Arguments --
1695 -----------------------
1697 procedure Collect_Arguments
1698 (Source_File : File_Name_Type;
1700 Args : Argument_List)
1703 Arguments_Collected := True;
1704 Arguments_Project := No_Project;
1706 Add_Arguments (Args);
1708 if Main_Project /= No_Project then
1710 Source_File_Name : constant String :=
1711 Get_Name_String (Source_File);
1712 Compiler_Package : Prj.Package_Id;
1713 Switches : Prj.Variable_Value;
1714 Data : Project_Data;
1719 (Source_File_Name => Source_File_Name,
1720 Project => Arguments_Project,
1721 Path => Arguments_Path_Name);
1723 -- If the source is not a source of a project file, check if
1726 if Arguments_Project = No_Project then
1727 if not External_Unit_Compilation_Allowed then
1728 Make_Failed ("external source
(", Source_File_Name,
1729 ") is not part
of any project
; cannot be
" &
1730 "compiled without gnatmake switch
-x
");
1733 -- If it is allowed, simply add the saved gcc switches
1735 Add_Arguments (The_Saved_Gcc_Switches.all);
1738 -- We get the project directory for the relative path
1739 -- switches and arguments.
1741 Data := Projects.Table (Arguments_Project);
1743 -- If the source is in an extended project, we go to
1744 -- the ultimate extending project.
1746 while Data.Extended_By /= No_Project loop
1747 Arguments_Project := Data.Extended_By;
1748 Data := Projects.Table (Arguments_Project);
1751 -- If building a dynamic or relocatable library, compile with
1752 -- PIC option, if it exists.
1754 if Data.Library and then Data.Library_Kind /= Static then
1756 PIC : constant String := MLib.Tgt.PIC_Option;
1760 Add_Arguments ((1 => new String'(PIC)));
1765 if Data.Dir_Path = null then
1767 new String'(Get_Name_String (Data.Display_Directory));
1768 Projects.Table (Arguments_Project) := Data;
1771 -- We now look for package Compiler
1772 -- and get the switches from this package.
1776 (Name => Name_Compiler,
1777 In_Packages => Data.Decl.Packages);
1779 if Compiler_Package /= No_Package then
1781 -- If package Gnatmake.Compiler exists, we get
1782 -- the specific switches for the current source,
1783 -- or the global switches, if any.
1785 Switches := Switches_Of
1786 (Source_File => Source_File,
1787 Source_File_Name => Source_File_Name,
1788 Source_Index => Source_Index,
1789 Naming => Data.Naming,
1790 In_Package => Compiler_Package,
1791 Allow_ALI => False);
1795 case Switches.Kind is
1797 -- We have a list of switches. We add these switches,
1798 -- plus the saved gcc switches.
1803 Current : String_List_Id := Switches.Values;
1804 Element : String_Element;
1805 Number : Natural := 0;
1808 while Current /= Nil_String loop
1809 Element := String_Elements.Table (Current);
1810 Number := Number + 1;
1811 Current := Element.Next;
1815 New_Args : Argument_List (1 .. Number);
1818 Current := Switches.Values;
1820 for Index in New_Args'Range loop
1821 Element := String_Elements.Table (Current);
1822 Get_Name_String (Element.Value);
1824 new String'(Name_Buffer (1 .. Name_Len));
1825 Test_If_Relative_Path
1826 (New_Args (Index), Parent => Data.Dir_Path);
1827 Current := Element.Next;
1831 (Configuration_Pragmas_Switch
1832 (Arguments_Project) &
1833 New_Args & The_Saved_Gcc_Switches.all);
1837 -- We have a single switch. We add this switch,
1838 -- plus the saved gcc switches.
1841 Get_Name_String (Switches.Value);
1844 New_Args : Argument_List :=
1846 (Name_Buffer (1 .. Name_Len)));
1849 Test_If_Relative_Path
1850 (New_Args (1), Parent => Data.Dir_Path);
1852 (Configuration_Pragmas_Switch (Arguments_Project) &
1853 New_Args & The_Saved_Gcc_Switches.all);
1856 -- We have no switches from Gnatmake.Compiler.
1857 -- We add the saved gcc switches.
1861 (Configuration_Pragmas_Switch (Arguments_Project) &
1862 The_Saved_Gcc_Switches.all);
1868 -- Set Output_Is_Object, depending if there is a -S switch.
1869 -- If the bind step is not performed, and there is a -S switch,
1870 -- then we will not check for a valid object file.
1873 end Collect_Arguments;
1875 ---------------------
1876 -- Compile_Sources --
1877 ---------------------
1879 procedure Compile_Sources
1880 (Main_Source : File_Name_Type;
1881 Args : Argument_List;
1882 First_Compiled_File : out Name_Id;
1883 Most_Recent_Obj_File : out Name_Id;
1884 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
1885 Main_Unit : out Boolean;
1886 Compilation_Failures : out Natural;
1887 Main_Index : Int := 0;
1888 Check_Readonly_Files : Boolean := False;
1889 Do_Not_Execute : Boolean := False;
1890 Force_Compilations : Boolean := False;
1891 Keep_Going : Boolean := False;
1892 In_Place_Mode : Boolean := False;
1893 Initialize_ALI_Data : Boolean := True;
1894 Max_Process : Positive := 1)
1896 No_Mapping_File : constant Natural := 0;
1898 type Compilation_Data is record
1900 Full_Source_File : File_Name_Type;
1901 Lib_File : File_Name_Type;
1902 Source_Unit : Unit_Name_Type;
1903 Mapping_File : Natural := No_Mapping_File;
1904 Project : Project_Id := No_Project;
1905 Syntax_Only : Boolean := False;
1906 Output_Is_Object : Boolean := True;
1909 Running_Compile : array (1 .. Max_Process) of Compilation_Data;
1910 -- Used to save information about outstanding compilations.
1912 Outstanding_Compiles : Natural := 0;
1913 -- Current number of outstanding compiles
1915 Source_Unit : Unit_Name_Type;
1916 -- Current source unit
1918 Source_File : File_Name_Type;
1919 -- Current source file
1921 Full_Source_File : File_Name_Type;
1922 -- Full name of the current source file
1924 Lib_File : File_Name_Type;
1925 -- Current library file
1927 Full_Lib_File : File_Name_Type;
1928 -- Full name of the current library file
1930 Obj_File : File_Name_Type;
1931 -- Full name of the object file corresponding to Lib_File.
1933 Obj_Stamp : Time_Stamp_Type;
1934 -- Time stamp of the current object file.
1936 Sfile : File_Name_Type;
1937 -- Contains the source file of the units withed by Source_File
1940 -- ALI Id of the current ALI file
1942 Read_Only : Boolean := False;
1944 Compilation_OK : Boolean;
1945 Need_To_Compile : Boolean;
1948 Text : Text_Buffer_Ptr;
1950 Mfile : Natural := No_Mapping_File;
1952 Need_To_Check_Standard_Library : Boolean :=
1953 Check_Readonly_Files and not Unique_Compile;
1955 Mapping_File_Arg : String_Access;
1957 procedure Add_Process
1959 Sfile : File_Name_Type;
1960 Afile : File_Name_Type;
1961 Uname : Unit_Name_Type;
1962 Mfile : Natural := No_Mapping_File);
1963 -- Adds process Pid to the current list of outstanding compilation
1964 -- processes and record the full name of the source file Sfile that
1965 -- we are compiling, the name of its library file Afile and the
1966 -- name of its unit Uname. If Mfile is not equal to No_Mapping_File,
1967 -- it is the index of the mapping file used during compilation in the
1968 -- array The_Mapping_File_Names.
1970 procedure Await_Compile
1971 (Sfile : out File_Name_Type;
1972 Afile : out File_Name_Type;
1973 Uname : out Unit_Name_Type;
1975 -- Awaits that an outstanding compilation process terminates. When
1976 -- it does set Sfile to the name of the source file that was compiled
1977 -- Afile to the name of its library file and Uname to the name of its
1978 -- unit. Note that this time stamp can be used to check whether the
1979 -- compilation did generate an object file. OK is set to True if the
1980 -- compilation succeeded. Note that Sfile, Afile and Uname could be
1981 -- resp. No_File, No_File and No_Name if there were no compilations
1984 function Bad_Compilation_Count return Natural;
1985 -- Returns the number of compilation failures.
1987 procedure Check_Standard_Library;
1988 -- Check if s-stalib.adb needs to be compiled
1990 procedure Collect_Arguments_And_Compile
1991 (Source_File : File_Name_Type; Source_Index : Int);
1992 -- Collect arguments from project file (if any) and compile
1998 Args : Argument_List) return Process_Id;
1999 -- Compiles S using Args. If S is a GNAT predefined source
2000 -- "-gnatpg
" is added to Args. Non blocking call. L corresponds to the
2001 -- expected library file name. Process_Id of the process spawned to
2002 -- execute the compile.
2004 package Good_ALI is new Table.Table (
2005 Table_Component_Type => ALI_Id,
2006 Table_Index_Type => Natural,
2007 Table_Low_Bound => 1,
2008 Table_Initial => 50,
2009 Table_Increment => 100,
2010 Table_Name => "Make
.Good_ALI
");
2011 -- Contains the set of valid ALI files that have not yet been scanned.
2013 function Good_ALI_Present return Boolean;
2014 -- Returns True if any ALI file was recorded in the previous set.
2016 procedure Get_Mapping_File (Project : Project_Id);
2017 -- Get a mapping file name. If there is one to be reused, reuse it.
2018 -- Otherwise, create a new mapping file.
2020 function Get_Next_Good_ALI return ALI_Id;
2021 -- Returns the next good ALI_Id record;
2023 procedure Record_Failure
2024 (File : File_Name_Type;
2025 Unit : Unit_Name_Type;
2026 Found : Boolean := True);
2027 -- Records in the previous table that the compilation for File failed.
2028 -- If Found is False then the compilation of File failed because we
2029 -- could not find it. Records also Unit when possible.
2031 procedure Record_Good_ALI (A : ALI_Id);
2032 -- Records in the previous set the Id of an ALI file.
2038 procedure Add_Process
2040 Sfile : File_Name_Type;
2041 Afile : File_Name_Type;
2042 Uname : Unit_Name_Type;
2043 Mfile : Natural := No_Mapping_File)
2045 OC1 : constant Positive := Outstanding_Compiles + 1;
2048 pragma Assert (OC1 <= Max_Process);
2049 pragma Assert (Pid /= Invalid_Pid);
2051 Running_Compile (OC1).Pid := Pid;
2052 Running_Compile (OC1).Full_Source_File := Sfile;
2053 Running_Compile (OC1).Lib_File := Afile;
2054 Running_Compile (OC1).Source_Unit := Uname;
2055 Running_Compile (OC1).Mapping_File := Mfile;
2056 Running_Compile (OC1).Project := Arguments_Project;
2057 Running_Compile (OC1).Syntax_Only := Syntax_Only;
2058 Running_Compile (OC1).Output_Is_Object := Output_Is_Object;
2060 Outstanding_Compiles := OC1;
2063 --------------------
2067 procedure Await_Compile
2068 (Sfile : out File_Name_Type;
2069 Afile : out File_Name_Type;
2070 Uname : out File_Name_Type;
2074 Project : Project_Id;
2077 pragma Assert (Outstanding_Compiles > 0);
2084 -- The loop here is a work-around for a problem on VMS; in some
2085 -- circumstances (shared library and several executables, for
2086 -- example), there are child processes other than compilation
2087 -- processes that are received. Until this problem is resolved,
2088 -- we will ignore such processes.
2091 Wait_Process (Pid, OK);
2093 if Pid = Invalid_Pid then
2097 for J in Running_Compile'First .. Outstanding_Compiles loop
2098 if Pid = Running_Compile (J).Pid then
2099 Sfile := Running_Compile (J).Full_Source_File;
2100 Afile := Running_Compile (J).Lib_File;
2101 Uname := Running_Compile (J).Source_Unit;
2102 Syntax_Only := Running_Compile (J).Syntax_Only;
2103 Output_Is_Object := Running_Compile (J).Output_Is_Object;
2104 Project := Running_Compile (J).Project;
2106 -- If a mapping file was used by this compilation,
2107 -- get its file name for reuse by a subsequent compilation
2109 if Running_Compile (J).Mapping_File /= No_Mapping_File then
2110 Last_Free_Indices (Project) :=
2111 Last_Free_Indices (Project) + 1;
2112 The_Free_Mapping_File_Indices
2113 (Project, Last_Free_Indices (Project)) :=
2114 Running_Compile (J).Mapping_File;
2117 -- To actually remove this Pid and related info from
2118 -- Running_Compile replace its entry with the last valid
2119 -- entry in Running_Compile.
2121 if J = Outstanding_Compiles then
2125 Running_Compile (J) :=
2126 Running_Compile (Outstanding_Compiles);
2129 Outstanding_Compiles := Outstanding_Compiles - 1;
2134 -- This child process was not one of our compilation processes;
2135 -- just ignore it for now.
2137 -- raise Program_Error;
2141 ---------------------------
2142 -- Bad_Compilation_Count --
2143 ---------------------------
2145 function Bad_Compilation_Count return Natural is
2147 return Bad_Compilation.Last - Bad_Compilation.First + 1;
2148 end Bad_Compilation_Count;
2150 ----------------------------
2151 -- Check_Standard_Library --
2152 ----------------------------
2154 procedure Check_Standard_Library is
2156 Need_To_Check_Standard_Library := False;
2158 if not Targparm.Suppress_Standard_Library_On_Target then
2161 Add_It : Boolean := True;
2164 Name_Len := Standard_Library_Package_Body_Name'Length;
2165 Name_Buffer (1 .. Name_Len) :=
2166 Standard_Library_Package_Body_Name;
2167 Sfile := Name_Enter;
2169 -- If we have a special runtime, we add the standard
2170 -- library only if we can find it.
2174 Find_File (Sfile, Osint.Source) /= No_File;
2178 if Is_Marked (Sfile) then
2179 if Is_In_Obsoleted (Sfile) then
2180 Executable_Obsolete := True;
2184 Insert_Q (Sfile, Index => 0);
2185 Mark (Sfile, Index => 0);
2190 end Check_Standard_Library;
2192 -----------------------------------
2193 -- Collect_Arguments_And_Compile --
2194 -----------------------------------
2196 procedure Collect_Arguments_And_Compile
2197 (Source_File : File_Name_Type; Source_Index : Int)
2201 -- If arguments have not yet been collected (in Check), collect them
2204 if not Arguments_Collected then
2205 Collect_Arguments (Source_File, Source_Index, Args);
2208 -- If we use mapping file (-P or -C switches), then get one
2210 if Create_Mapping_File then
2211 Get_Mapping_File (Arguments_Project);
2214 -- If the source is part of a project file, we set the ADA_*_PATHs,
2215 -- check for an eventual library project, and use the full path.
2217 if Arguments_Project /= No_Project then
2218 Prj.Env.Set_Ada_Paths (Arguments_Project, True);
2220 if MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None then
2222 The_Data : Project_Data :=
2223 Projects.Table (Arguments_Project);
2224 Prj : Project_Id := Arguments_Project;
2227 while The_Data.Extended_By /= No_Project loop
2228 Prj := The_Data.Extended_By;
2229 The_Data := Projects.Table (Prj);
2233 and then not The_Data.Need_To_Build_Lib
2235 -- Add to the Q all sources of the project that
2236 -- have not been marked
2238 Insert_Project_Sources
2239 (The_Project => Prj,
2240 All_Projects => False,
2243 -- Now mark the project as processed
2245 Projects.Table (Prj).Need_To_Build_Lib := True;
2250 -- Change to the object directory of the project file,
2253 Change_To_Object_Directory (Arguments_Project);
2255 Pid := Compile (Arguments_Path_Name, Lib_File, Source_Index,
2256 Arguments (1 .. Last_Argument));
2259 -- If this is a source outside of any project file, make sure
2260 -- it will be compiled in the object directory of the main project
2263 if Main_Project /= No_Project then
2264 Change_To_Object_Directory (Arguments_Project);
2267 Pid := Compile (Full_Source_File, Lib_File, Source_Index,
2268 Arguments (1 .. Last_Argument));
2270 end Collect_Arguments_And_Compile;
2280 Args : Argument_List) return Process_Id
2282 Comp_Args : Argument_List (Args'First .. Args'Last + 9);
2283 Comp_Next : Integer := Args'First;
2284 Comp_Last : Integer;
2286 function Ada_File_Name (Name : Name_Id) return Boolean;
2287 -- Returns True if Name is the name of an ada source file
2288 -- (i.e. suffix is .ads or .adb)
2294 function Ada_File_Name (Name : Name_Id) return Boolean is
2296 Get_Name_String (Name);
2299 and then Name_Buffer (Name_Len - 3 .. Name_Len - 1) = ".ad
"
2300 and then (Name_Buffer (Name_Len) = 'b'
2302 Name_Buffer (Name_Len) = 's');
2305 -- Start of processing for Compile
2308 Enter_Into_Obsoleted (S);
2310 -- By default, Syntax_Only is False
2312 Syntax_Only := False;
2314 for J in Args'Range loop
2315 if Args (J).all = "-gnats
" then
2317 -- If we compile with -gnats, the bind step and the link step
2318 -- are inhibited. Also, we set Syntax_Only to True, so that
2319 -- we don't fail when we don't find the ALI file, after
2322 Do_Bind_Step := False;
2323 Do_Link_Step := False;
2324 Syntax_Only := True;
2326 elsif Args (J).all = "-gnatc
" then
2328 -- If we compile with -gnatc, the bind step and the link step
2329 -- are inhibited. We set Syntax_Only to False for the case when
2330 -- -gnats was previously specified.
2332 Do_Bind_Step := False;
2333 Do_Link_Step := False;
2334 Syntax_Only := False;
2338 Comp_Args (Comp_Next) := Comp_Flag;
2339 Comp_Next := Comp_Next + 1;
2341 -- Optimize the simple case where the gcc command line looks like
2342 -- gcc -c -I. ... -I- file.adb --into-> gcc -c ... file.adb
2344 if Args (Args'First).all = "-I
" & Normalized_CWD
2345 and then Args (Args'Last).all = "-I
-"
2346 and then S = Strip_Directory (S)
2348 Comp_Last := Comp_Next + Args'Length - 3;
2349 Comp_Args (Comp_Next .. Comp_Last) :=
2350 Args (Args'First + 1 .. Args'Last - 1);
2353 Comp_Last := Comp_Next + Args'Length - 1;
2354 Comp_Args (Comp_Next .. Comp_Last) := Args;
2357 -- Set -gnatpg for predefined files (for this purpose the renamings
2358 -- such as Text_IO do not count as predefined). Note that we strip
2359 -- the directory name from the source file name becase the call to
2360 -- Fname.Is_Predefined_File_Name cannot deal with directory prefixes.
2363 Fname : constant File_Name_Type := Strip_Directory (S);
2366 if Is_Predefined_File_Name (Fname, False) then
2367 if Check_Readonly_Files then
2368 Comp_Last := Comp_Last + 1;
2369 Comp_Args (Comp_Last) := GNAT_Flag;
2373 ("not allowed to compile
""" &
2374 Get_Name_String (Fname) &
2375 """; use -a switch
, or compile file
with " &
2376 """-gnatg
"" switch
");
2381 -- Now check if the file name has one of the suffixes familiar to
2382 -- the gcc driver. If this is not the case then add the ada flag
2385 if not Ada_File_Name (S) and then not Targparm.AAMP_On_Target then
2386 Comp_Last := Comp_Last + 1;
2387 Comp_Args (Comp_Last) := Ada_Flag_1;
2388 Comp_Last := Comp_Last + 1;
2389 Comp_Args (Comp_Last) := Ada_Flag_2;
2392 if Source_Index /= 0 then
2394 Num : constant String := Source_Index'Img;
2396 Comp_Last := Comp_Last + 1;
2397 Comp_Args (Comp_Last) :=
2398 new String'("-gnateI
" & Num (Num'First + 1 .. Num'Last));
2402 if Source_Index /= 0 or else
2403 L /= Strip_Directory (L) or else
2404 Object_Directory_Path /= null
2407 -- Build -o argument.
2409 Get_Name_String (L);
2411 for J in reverse 1 .. Name_Len loop
2412 if Name_Buffer (J) = '.' then
2413 Name_Len := J + Object_Suffix'Length - 1;
2414 Name_Buffer (J .. Name_Len) := Object_Suffix;
2419 Comp_Last := Comp_Last + 1;
2420 Comp_Args (Comp_Last) := Output_Flag;
2421 Comp_Last := Comp_Last + 1;
2423 -- If an object directory was specified, prepend the object file
2424 -- name with this object directory.
2426 if Object_Directory_Path /= null then
2427 Comp_Args (Comp_Last) :=
2428 new String'(Object_Directory_Path.all &
2429 Name_Buffer (1 .. Name_Len));
2432 Comp_Args (Comp_Last) :=
2433 new String'(Name_Buffer (1 .. Name_Len));
2437 if Create_Mapping_File then
2438 Comp_Last := Comp_Last + 1;
2439 Comp_Args (Comp_Last) := Mapping_File_Arg;
2442 Get_Name_String (S);
2444 Comp_Last := Comp_Last + 1;
2445 Comp_Args (Comp_Last) := new String'(Name_Buffer (1 .. Name_Len));
2447 GNAT.OS_Lib.Normalize_Arguments (Comp_Args (Args'First .. Comp_Last));
2449 Comp_Last := Comp_Last + 1;
2450 Comp_Args (Comp_Last) := new String'("-gnatez
");
2452 Display (Gcc.all, Comp_Args (Args'First .. Comp_Last));
2454 if Gcc_Path = null then
2455 Make_Failed ("error
, unable to locate
", Gcc.all);
2459 GNAT.OS_Lib.Non_Blocking_Spawn
2460 (Gcc_Path.all, Comp_Args (Args'First .. Comp_Last));
2463 ----------------------
2464 -- Get_Mapping_File --
2465 ----------------------
2467 procedure Get_Mapping_File (Project : Project_Id) is
2469 -- If there is a mapping file ready to be reused, reuse it
2471 if Last_Free_Indices (Project) > 0 then
2472 Mfile := The_Free_Mapping_File_Indices
2473 (Project, Last_Free_Indices (Project));
2474 Last_Free_Indices (Project) := Last_Free_Indices (Project) - 1;
2476 -- Otherwise, create and initialize a new one
2479 Init_Mapping_File (Project => Project, File_Index => Mfile);
2482 -- Put the name in the mapping file argument for the invocation
2485 Free (Mapping_File_Arg);
2487 new String'("-gnatem
=" &
2489 (The_Mapping_File_Names (Project, Mfile)));
2491 end Get_Mapping_File;
2493 -----------------------
2494 -- Get_Next_Good_ALI --
2495 -----------------------
2497 function Get_Next_Good_ALI return ALI_Id is
2501 pragma Assert (Good_ALI_Present);
2502 ALI := Good_ALI.Table (Good_ALI.Last);
2503 Good_ALI.Decrement_Last;
2505 end Get_Next_Good_ALI;
2507 ----------------------
2508 -- Good_ALI_Present --
2509 ----------------------
2511 function Good_ALI_Present return Boolean is
2513 return Good_ALI.First <= Good_ALI.Last;
2514 end Good_ALI_Present;
2516 --------------------
2517 -- Record_Failure --
2518 --------------------
2520 procedure Record_Failure
2521 (File : File_Name_Type;
2522 Unit : Unit_Name_Type;
2523 Found : Boolean := True)
2526 Bad_Compilation.Increment_Last;
2527 Bad_Compilation.Table (Bad_Compilation.Last) := (File, Unit, Found);
2530 ---------------------
2531 -- Record_Good_ALI --
2532 ---------------------
2534 procedure Record_Good_ALI (A : ALI_Id) is
2536 Good_ALI.Increment_Last;
2537 Good_ALI.Table (Good_ALI.Last) := A;
2538 end Record_Good_ALI;
2540 -- Start of processing for Compile_Sources
2543 pragma Assert (Args'First = 1);
2545 -- Package and Queue initializations.
2548 Output.Set_Standard_Error;
2550 if First_Q_Initialization then
2554 if Initialize_ALI_Data then
2556 Initialize_ALI_Source;
2559 -- The following two flags affect the behavior of ALI.Set_Source_Table.
2560 -- We set Check_Source_Files to True to ensure that source file
2561 -- time stamps are checked, and we set All_Sources to False to
2562 -- avoid checking the presence of the source files listed in the
2563 -- source dependency section of an ali file (which would be a mistake
2564 -- since the ali file may be obsolete).
2566 Check_Source_Files := True;
2567 All_Sources := False;
2569 -- Only insert in the Q if it is not already done, to avoid simultaneous
2570 -- compilations if -jnnn is used.
2572 if not Is_Marked (Main_Source, Main_Index) then
2573 Insert_Q (Main_Source, Index => Main_Index);
2574 Mark (Main_Source, Main_Index);
2577 First_Compiled_File := No_File;
2578 Most_Recent_Obj_File := No_File;
2579 Most_Recent_Obj_Stamp := Empty_Time_Stamp;
2582 -- Keep looping until there is no more work to do (the Q is empty)
2583 -- and all the outstanding compilations have terminated
2585 Make_Loop : while not Empty_Q or else Outstanding_Compiles > 0 loop
2587 -- If the user does not want to keep going in case of errors then
2588 -- wait for the remaining outstanding compiles and then exit.
2590 if Bad_Compilation_Count > 0 and then not Keep_Going then
2591 while Outstanding_Compiles > 0 loop
2593 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
2595 if not Compilation_OK then
2596 Record_Failure (Full_Source_File, Source_Unit);
2603 -- PHASE 1: Check if there is more work that we can do (ie the Q
2604 -- is non empty). If there is, do it only if we have not yet used
2605 -- up all the available processes.
2607 if not Empty_Q and then Outstanding_Compiles < Max_Process then
2610 -- Index of the current unit in the current source file
2613 Extract_From_Q (Source_File, Source_Unit, Source_Index);
2614 Full_Source_File := Osint.Full_Source_Name (Source_File);
2615 Lib_File := Osint.Lib_File_Name
2616 (Source_File, Source_Index);
2617 Full_Lib_File := Osint.Full_Lib_File_Name (Lib_File);
2619 -- If this source has already been compiled, the executable is
2622 if Is_In_Obsoleted (Source_File) then
2623 Executable_Obsolete := True;
2626 -- If the library file is an Ada library skip it
2628 if Full_Lib_File /= No_File
2629 and then In_Ada_Lib_Dir (Full_Lib_File)
2632 (Lib_File, "is in an Ada library
", Prefix => " ");
2634 -- If the library file is a read-only library skip it, but
2635 -- only if, when using project files, this library file is
2636 -- in the right object directory (a read-only ALI file
2637 -- in the object directory of a project being extended
2638 -- should not be skipped).
2640 elsif Full_Lib_File /= No_File
2641 and then not Check_Readonly_Files
2642 and then Is_Readonly_Library (Full_Lib_File)
2643 and then Is_In_Object_Directory (Source_File, Full_Lib_File)
2646 (Lib_File, "is a read
-only library
", Prefix => " ");
2648 -- The source file that we are checking cannot be located
2650 elsif Full_Source_File = No_File then
2651 Record_Failure (Source_File, Source_Unit, False);
2653 -- Source and library files can be located but are internal
2656 elsif not Check_Readonly_Files
2657 and then Full_Lib_File /= No_File
2658 and then Is_Internal_File_Name (Source_File)
2660 if Force_Compilations then
2662 ("not allowed to compile
""" &
2663 Get_Name_String (Source_File) &
2664 """; use -a switch
, or compile file
with " &
2665 """-gnatg
"" switch
");
2669 (Lib_File, "is an internal library
", Prefix => " ");
2671 -- The source file that we are checking can be located
2674 Arguments_Collected := False;
2676 -- Don't waste any time if we have to recompile anyway
2678 Obj_Stamp := Empty_Time_Stamp;
2679 Need_To_Compile := Force_Compilations;
2681 if not Force_Compilations then
2683 Full_Lib_File /= No_File
2684 and then not Check_Readonly_Files
2685 and then Is_Readonly_Library (Full_Lib_File);
2686 Check (Source_File, Source_Index, Args, Lib_File,
2687 Read_Only, ALI, Obj_File, Obj_Stamp);
2688 Need_To_Compile := (ALI = No_ALI_Id);
2691 if not Need_To_Compile then
2693 -- The ALI file is up-to-date. Record its Id.
2695 Record_Good_ALI (ALI);
2697 -- Record the time stamp of the most recent object file
2698 -- as long as no (re)compilations are needed.
2700 if First_Compiled_File = No_File
2701 and then (Most_Recent_Obj_File = No_File
2702 or else Obj_Stamp > Most_Recent_Obj_Stamp)
2704 Most_Recent_Obj_File := Obj_File;
2705 Most_Recent_Obj_Stamp := Obj_Stamp;
2709 -- Is this the first file we have to compile?
2711 if First_Compiled_File = No_File then
2712 First_Compiled_File := Full_Source_File;
2713 Most_Recent_Obj_File := No_File;
2715 if Do_Not_Execute then
2720 if In_Place_Mode then
2722 -- If the library file was not found, then save the
2723 -- library file near the source file.
2725 if Full_Lib_File = No_File then
2726 Lib_File := Osint.Lib_File_Name
2727 (Full_Source_File, Source_Index);
2729 -- If the library file was found, then save the
2730 -- library file in the same place.
2733 Lib_File := Full_Lib_File;
2738 -- Start the compilation and record it. We can do this
2739 -- because there is at least one free process.
2741 Collect_Arguments_And_Compile (Source_File, Source_Index);
2743 -- Make sure we could successfully start the compilation
2745 if Pid = Invalid_Pid then
2746 Record_Failure (Full_Source_File, Source_Unit);
2760 -- PHASE 2: Now check if we should wait for a compilation to
2761 -- finish. This is the case if all the available processes are
2762 -- busy compiling sources or there is nothing else to do
2763 -- (that is the Q is empty and there are no good ALIs to process).
2765 if Outstanding_Compiles = Max_Process
2767 and then not Good_ALI_Present
2768 and then Outstanding_Compiles > 0)
2771 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
2773 if not Compilation_OK then
2774 Record_Failure (Full_Source_File, Source_Unit);
2777 if Compilation_OK or else Keep_Going then
2779 -- Re-read the updated library file
2782 Saved_Object_Consistency : constant Boolean :=
2783 Check_Object_Consistency;
2786 -- If compilation was not OK, or if output is not an
2787 -- object file and we don't do the bind step, don't check
2788 -- for object consistency.
2790 Check_Object_Consistency :=
2791 Check_Object_Consistency
2793 and (Output_Is_Object or Do_Bind_Step);
2794 Text := Read_Library_Info (Lib_File);
2796 -- Restore Check_Object_Consistency to its initial value
2798 Check_Object_Consistency := Saved_Object_Consistency;
2801 -- If an ALI file was generated by this compilation, scan
2802 -- the ALI file and record it.
2803 -- If the scan fails, a previous ali file is inconsistent with
2804 -- the unit just compiled.
2806 if Text /= null then
2808 Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
2810 if ALI = No_ALI_Id then
2812 -- Record a failure only if not already done
2814 if Compilation_OK then
2817 "incompatible ALI file
, please recompile
");
2818 Record_Failure (Full_Source_File, Source_Unit);
2822 Record_Good_ALI (ALI);
2825 -- If we could not read the ALI file that was just generated
2826 -- then there could be a problem reading either the ALI or the
2827 -- corresponding object file (if Check_Object_Consistency
2828 -- is set Read_Library_Info checks that the time stamp of the
2829 -- object file is more recent than that of the ALI). For an
2830 -- example of problems caught by this test see [6625-009].
2831 -- However, we record a failure only if not already done.
2834 if Compilation_OK and not Syntax_Only then
2837 "WARNING
: ALI
or object file
not found after compile
");
2838 Record_Failure (Full_Source_File, Source_Unit);
2844 -- PHASE 3: Check if we recorded good ALI files. If yes process
2845 -- them now in the order in which they have been recorded. There
2846 -- are two occasions in which we record good ali files. The first is
2847 -- in phase 1 when, after scanning an existing ALI file we realize
2848 -- it is up-to-date, the second instance is after a successful
2851 while Good_ALI_Present loop
2852 ALI := Get_Next_Good_ALI;
2855 Source_Index : Int := Unit_Index_Of (ALIs.Table (ALI).Afile);
2858 -- If we are processing the library file corresponding to the
2859 -- main source file check if this source can be a main unit.
2861 if ALIs.Table (ALI).Sfile = Main_Source and then
2862 Source_Index = Main_Index
2864 Main_Unit := ALIs.Table (ALI).Main_Program /= None;
2867 -- The following adds the standard library (s-stalib) to the
2868 -- list of files to be handled by gnatmake: this file and any
2869 -- files it depends on are always included in every bind,
2870 -- even if they are not in the explicit dependency list.
2871 -- Of course, it is not added if Suppress_Standard_Library
2874 -- However, to avoid annoying output about s-stalib.ali being
2875 -- read only, when "-v
" is used, we add the standard library
2876 -- only when "-a
" is used.
2878 if Need_To_Check_Standard_Library then
2879 Check_Standard_Library;
2882 -- Now insert in the Q the unmarked source files (i.e. those
2883 -- which have never been inserted in the Q and hence never
2884 -- considered). Only do that if Unique_Compile is False.
2886 if not Unique_Compile then
2888 ALIs.Table (ALI).First_Unit .. ALIs.Table (ALI).Last_Unit
2891 Units.Table (J).First_With .. Units.Table (J).Last_With
2893 Sfile := Withs.Table (K).Sfile;
2894 Add_Dependency (ALIs.Table (ALI).Sfile, Sfile);
2896 if Is_In_Obsoleted (Sfile) then
2897 Executable_Obsolete := True;
2900 if Sfile = No_File then
2902 ("Skipping
generic:", Withs.Table (K).Uname);
2906 Unit_Index_Of (Withs.Table (K).Afile);
2908 if Is_Marked (Sfile, Source_Index) then
2909 Debug_Msg ("Skipping marked file
:", Sfile);
2911 elsif not Check_Readonly_Files
2912 and then Is_Internal_File_Name (Sfile)
2914 Debug_Msg ("Skipping internal file
:", Sfile);
2918 (Sfile, Withs.Table (K).Uname, Source_Index);
2919 Mark (Sfile, Source_Index);
2928 if Display_Compilation_Progress then
2929 Write_Str ("completed
");
2930 Write_Int (Int (Q_Front));
2931 Write_Str (" out of ");
2932 Write_Int (Int (Q.Last));
2934 Write_Int (Int ((Q_Front * 100) / (Q.Last - Q.First)));
2935 Write_Str ("%)...");
2940 Compilation_Failures := Bad_Compilation_Count;
2942 -- Compilation is finished
2944 -- Delete any temporary configuration pragma file
2946 Delete_Temp_Config_Files;
2948 end Compile_Sources;
2950 ----------------------------------
2951 -- Configuration_Pragmas_Switch --
2952 ----------------------------------
2954 function Configuration_Pragmas_Switch
2955 (For_Project : Project_Id) return Argument_List
2957 The_Packages : Package_Id;
2958 Gnatmake : Package_Id;
2959 Compiler : Package_Id;
2961 Global_Attribute : Variable_Value := Nil_Variable_Value;
2962 Local_Attribute : Variable_Value := Nil_Variable_Value;
2964 Global_Attribute_Present : Boolean := False;
2965 Local_Attribute_Present : Boolean := False;
2967 Result : Argument_List (1 .. 3);
2968 Last : Natural := 0;
2970 function Absolute_Path
2972 Project : Project_Id) return String;
2973 -- Returns an absolute path for a configuration pragmas file.
2979 function Absolute_Path
2981 Project : Project_Id) return String
2984 Get_Name_String (Path);
2987 Path_Name : constant String := Name_Buffer (1 .. Name_Len);
2990 if Is_Absolute_Path (Path_Name) then
2995 Parent_Directory : constant String :=
2996 Get_Name_String (Projects.Table (Project).Directory);
2999 if Parent_Directory (Parent_Directory'Last) =
3002 return Parent_Directory & Path_Name;
3005 return Parent_Directory & Directory_Separator & Path_Name;
3012 -- Start of processing for Configuration_Pragmas_Switch
3015 Prj.Env.Create_Config_Pragmas_File (For_Project, Main_Project);
3017 if Projects.Table (For_Project).Config_File_Name /= No_Name then
3018 Temporary_Config_File :=
3019 Projects.Table (For_Project).Config_File_Temp;
3025 (Projects.Table (For_Project).Config_File_Name));
3028 Temporary_Config_File := False;
3031 -- Check for attribute Builder'Global_Configuration_Pragmas
3033 The_Packages := Projects.Table (Main_Project).Decl.Packages;
3036 (Name => Name_Builder,
3037 In_Packages => The_Packages);
3039 if Gnatmake /= No_Package then
3040 Global_Attribute := Prj.Util.Value_Of
3041 (Variable_Name => Name_Global_Configuration_Pragmas,
3042 In_Variables => Packages.Table (Gnatmake).Decl.Attributes);
3043 Global_Attribute_Present :=
3044 Global_Attribute /= Nil_Variable_Value
3045 and then Get_Name_String (Global_Attribute.Value) /= "";
3047 if Global_Attribute_Present then
3049 Path : constant String :=
3051 (Global_Attribute.Value, Global_Attribute.Project);
3053 if not Is_Regular_File (Path) then
3055 ("cannot find configuration pragmas file
", Path);
3059 Result (Last) := new String'("-gnatec
=" & Path);
3064 -- Check for attribute Compiler'Local_Configuration_Pragmas
3066 The_Packages := Projects.Table (For_Project).Decl.Packages;
3069 (Name => Name_Compiler,
3070 In_Packages => The_Packages);
3072 if Compiler /= No_Package then
3073 Local_Attribute := Prj.Util.Value_Of
3074 (Variable_Name => Name_Local_Configuration_Pragmas,
3075 In_Variables => Packages.Table (Compiler).Decl.Attributes);
3076 Local_Attribute_Present :=
3077 Local_Attribute /= Nil_Variable_Value
3078 and then Get_Name_String (Local_Attribute.Value) /= "";
3080 if Local_Attribute_Present then
3082 Path : constant String :=
3084 (Local_Attribute.Value, Local_Attribute.Project);
3086 if not Is_Regular_File (Path) then
3088 ("cannot find configuration pragmas file
", Path);
3092 Result (Last) := new String'("-gnatec
=" & Path);
3097 return Result (1 .. Last);
3098 end Configuration_Pragmas_Switch;
3104 procedure Debug_Msg (S : String; N : Name_Id) is
3106 if Debug.Debug_Flag_W then
3107 Write_Str (" ... ");
3115 ---------------------------
3116 -- Delete_All_Temp_Files --
3117 ---------------------------
3119 procedure Delete_All_Temp_Files is
3121 if Gnatmake_Called and not Debug.Debug_Flag_N then
3122 Delete_Mapping_Files;
3123 Delete_Temp_Config_Files;
3124 Prj.Env.Delete_All_Path_Files;
3126 end Delete_All_Temp_Files;
3128 --------------------------
3129 -- Delete_Mapping_Files --
3130 --------------------------
3132 procedure Delete_Mapping_Files is
3135 if not Debug.Debug_Flag_N then
3136 if The_Mapping_File_Names /= null then
3137 for Project in The_Mapping_File_Names'Range (1) loop
3138 for Index in 1 .. Last_Mapping_File_Names (Project) loop
3140 (Name => Get_Name_String
3141 (The_Mapping_File_Names (Project, Index)),
3142 Success => Success);
3147 end Delete_Mapping_Files;
3149 ------------------------------
3150 -- Delete_Temp_Config_Files --
3151 ------------------------------
3153 procedure Delete_Temp_Config_Files is
3156 if (not Debug.Debug_Flag_N) and Main_Project /= No_Project then
3157 for Project in 1 .. Projects.Last loop
3158 if Projects.Table (Project).Config_File_Temp then
3159 if Verbose_Mode then
3160 Write_Str ("Deleting temp configuration file
""");
3161 Write_Str (Get_Name_String
3162 (Projects.Table (Project).Config_File_Name));
3167 (Name => Get_Name_String
3168 (Projects.Table (Project).Config_File_Name),
3169 Success => Success);
3171 -- Make sure that we don't have a config file for this
3172 -- project, in case when there are several mains.
3173 -- In this case, we will recreate another config file:
3174 -- we cannot reuse the one that we just deleted!
3176 Projects.Table (Project).Config_Checked := False;
3177 Projects.Table (Project).Config_File_Name := No_Name;
3178 Projects.Table (Project).Config_File_Temp := False;
3182 end Delete_Temp_Config_Files;
3188 procedure Display (Program : String; Args : Argument_List) is
3190 pragma Assert (Args'First = 1);
3192 if Display_Executed_Programs then
3193 Write_Str (Program);
3195 for J in Args'Range loop
3197 -- Never display -gnatez
3199 if Args (J).all /= "-gnatez
" then
3201 -- Do not display the mapping file argument automatically
3202 -- created when using a project file.
3204 if Main_Project = No_Project
3205 or else Debug.Debug_Flag_N
3206 or else Args (J)'Length < 8
3208 Args (J) (Args (J)'First .. Args (J)'First + 6) /= "-gnatem
"
3210 -- When -dn is not specified, do not display the config
3211 -- pragmas switch (-gnatec) for the temporary file created
3212 -- by the project manager (always the first -gnatec switch).
3213 -- Reset Temporary_Config_File to False so that the eventual
3214 -- other -gnatec switches will be displayed.
3216 if (not Debug.Debug_Flag_N)
3217 and then Temporary_Config_File
3218 and then Args (J)'Length > 7
3219 and then Args (J) (Args (J)'First .. Args (J)'First + 6)
3222 Temporary_Config_File := False;
3224 -- Do not display the -F=mapping_file switch for
3225 -- gnatbind, if -dn is not specified.
3227 elsif Debug.Debug_Flag_N
3228 or else Args (J)'Length < 4
3230 Args (J) (Args (J)'First .. Args (J)'First + 2) /= "-F
="
3233 Write_Str (Args (J).all);
3243 ----------------------
3244 -- Display_Commands --
3245 ----------------------
3247 procedure Display_Commands (Display : Boolean := True) is
3249 Display_Executed_Programs := Display;
3250 end Display_Commands;
3256 function Empty_Q return Boolean is
3258 if Debug.Debug_Flag_P then
3259 Write_Str (" Q
:= [");
3261 for J in Q_Front .. Q.Last - 1 loop
3263 Write_Name (Q.Table (J).File);
3272 return Q_Front >= Q.Last;
3275 --------------------------
3276 -- Enter_Into_Obsoleted --
3277 --------------------------
3279 procedure Enter_Into_Obsoleted (F : Name_Id) is
3280 Name : constant String := Get_Name_String (F);
3281 First : Natural := Name'Last;
3285 while First > Name'First
3286 and then Name (First - 1) /= Directory_Separator
3287 and then Name (First - 1) /= '/'
3292 if First /= Name'First then
3294 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
3298 Debug_Msg ("New entry in Obsoleted table
:", F2);
3299 Obsoleted.Set (F2, True);
3300 end Enter_Into_Obsoleted;
3302 ---------------------
3303 -- Extract_Failure --
3304 ---------------------
3306 procedure Extract_Failure
3307 (File : out File_Name_Type;
3308 Unit : out Unit_Name_Type;
3309 Found : out Boolean)
3312 File := Bad_Compilation.Table (Bad_Compilation.Last).File;
3313 Unit := Bad_Compilation.Table (Bad_Compilation.Last).Unit;
3314 Found := Bad_Compilation.Table (Bad_Compilation.Last).Found;
3315 Bad_Compilation.Decrement_Last;
3316 end Extract_Failure;
3318 --------------------
3319 -- Extract_From_Q --
3320 --------------------
3322 procedure Extract_From_Q
3323 (Source_File : out File_Name_Type;
3324 Source_Unit : out Unit_Name_Type;
3325 Source_Index : out Int)
3327 File : constant File_Name_Type := Q.Table (Q_Front).File;
3328 Unit : constant Unit_Name_Type := Q.Table (Q_Front).Unit;
3329 Index : constant Int := Q.Table (Q_Front).Index;
3332 if Debug.Debug_Flag_Q then
3333 Write_Str (" Q
:= Q
- [ ");
3345 Q_Front := Q_Front + 1;
3346 Source_File := File;
3347 Source_Unit := Unit;
3348 Source_Index := Index;
3355 procedure Gnatmake is
3356 Main_Source_File : File_Name_Type;
3357 -- The source file containing the main compilation unit
3359 Compilation_Failures : Natural;
3361 Total_Compilation_Failures : Natural := 0;
3363 Is_Main_Unit : Boolean;
3364 -- Set to True by Compile_Sources if the Main_Source_File can be a
3367 Main_ALI_File : File_Name_Type;
3368 -- The ali file corresponding to Main_Source_File
3370 Executable : File_Name_Type := No_File;
3371 -- The file name of an executable
3373 Non_Std_Executable : Boolean := False;
3374 -- Non_Std_Executable is set to True when there is a possibility
3375 -- that the linker will not choose the correct executable file name.
3377 Current_Work_Dir : constant String_Access :=
3378 new String'(Get_Current_Dir);
3379 -- The current working directory, used to modify some relative path
3380 -- switches on the command line when a project file is used.
3382 Current_Main_Index : Int := 0;
3383 -- If not zero, the index of the current main unit in its source file
3385 There_Are_Stand_Alone_Libraries : Boolean := False;
3386 -- Set to True when there are Stand-Alone Libraries, so that gnatbind
3387 -- is invoked with the -F switch to force checking of elaboration flags.
3389 Mapping_Path : Name_Id := No_Name;
3390 -- The path name of the mapping file
3394 procedure Check_Mains;
3395 -- Check that the main subprograms do exist and that they all
3396 -- belong to the same project file.
3398 procedure Create_Binder_Mapping_File
3399 (Args : in out Argument_List; Last_Arg : in out Natural);
3400 -- Create a binder mapping file and add the necessary switch
3406 procedure Check_Mains is
3407 Real_Main_Project : Project_Id := No_Project;
3408 -- The project of the first main
3410 Proj : Project_Id := No_Project;
3411 -- The project of the current main
3413 Data : Project_Data;
3415 Real_Path : String_Access;
3424 Main : constant String := Mains.Next_Main;
3425 -- The name specified on the command line may include
3426 -- directory information.
3428 File_Name : constant String := Base_Name (Main);
3429 -- The simple file name of the current main main
3432 exit when Main = "";
3434 -- Get the project of the current main
3436 Proj := Prj.Env.Project_Of (File_Name, Main_Project);
3438 -- Fail if the current main is not a source of a
3441 if Proj = No_Project then
3444 """ is not a source
of any project
");
3447 -- If there is directory information, check that
3448 -- the source exists and, if it does, that the path
3449 -- is the actual path of a source of a project.
3451 if Main /= File_Name then
3452 Data := Projects.Table (Main_Project);
3458 (Data.Naming.Current_Body_Suffix),
3460 if Real_Path = null then
3465 (Data.Naming.Current_Spec_Suffix),
3469 if Real_Path = null then
3471 Locate_Regular_File (Main, "");
3474 -- Fail if the file cannot be found
3476 if Real_Path = null then
3478 ("file
""" & Main & """ does
not exist
");
3482 Project_Path : constant String :=
3483 Prj.Env.File_Name_Of_Library_Unit_Body
3485 Project => Main_Project,
3486 Main_Project_Only => False,
3488 Normed_Path : constant String :=
3491 Case_Sensitive => False);
3492 Proj_Path : constant String :=
3495 Case_Sensitive => False);
3500 -- Fail if it is not the correct path
3502 if Normed_Path /= Proj_Path then
3503 if Verbose_Mode then
3504 Write_Str (Normed_Path);
3506 Write_Line (Proj_Path);
3511 """ is not a source
of any project
");
3516 if not Unique_Compile then
3518 -- Record the project, if it is the first main
3520 if Real_Main_Project = No_Project then
3521 Real_Main_Project := Proj;
3523 elsif Proj /= Real_Main_Project then
3525 -- Fail, as the current main is not a source
3526 -- of the same project as the first main.
3530 """ is not a source
of project
" &
3533 (Real_Main_Project).Name));
3538 -- If -u and -U are not used, we may have mains that
3539 -- are sources of a project that is not the one
3540 -- specified with switch -P.
3542 if not Unique_Compile then
3543 Main_Project := Real_Main_Project;
3549 --------------------------------
3550 -- Create_Binder_Mapping_File --
3551 --------------------------------
3553 procedure Create_Binder_Mapping_File
3554 (Args : in out Argument_List; Last_Arg : in out Natural)
3556 Mapping_FD : File_Descriptor := Invalid_FD;
3557 -- A File Descriptor for an eventual mapping file
3559 ALI_Unit : Name_Id := No_Name;
3560 -- The unit name of an ALI file
3562 ALI_Name : Name_Id := No_Name;
3563 -- The file name of the ALI file
3565 ALI_Project : Project_Id := No_Project;
3566 -- The project of the ALI file
3569 OK : Boolean := True;
3572 -- For call to Close
3575 Tempdir.Create_Temp_File (Mapping_FD, Mapping_Path);
3577 if Mapping_FD /= Invalid_FD then
3579 -- Traverse all units
3581 for J in Prj.Com.Units.First .. Prj.Com.Units.Last loop
3583 Unit : constant Prj.Com.Unit_Data :=
3584 Prj.Com.Units.Table (J);
3588 if Unit.Name /= No_Name then
3590 -- If there is a body, put it in the mapping
3592 if Unit.File_Names (Body_Part).Name /= No_Name
3593 and then Unit.File_Names (Body_Part).Project
3596 Get_Name_String (Unit.Name);
3598 (Name_Len + 1 .. Name_Len + 2) := "%b
";
3599 Name_Len := Name_Len + 2;
3600 ALI_Unit := Name_Find;
3603 (Unit.File_Names (Body_Part).Name);
3605 Unit.File_Names (Body_Part).Project;
3607 -- Otherwise, if there is a spec, put it
3610 elsif Unit.File_Names (Specification).Name
3612 and then Unit.File_Names
3613 (Specification).Project
3616 Get_Name_String (Unit.Name);
3618 (Name_Len + 1 .. Name_Len + 2) := "%s
";
3619 Name_Len := Name_Len + 2;
3620 ALI_Unit := Name_Find;
3621 ALI_Name := Lib_File_Name
3622 (Unit.File_Names (Specification).Name);
3624 Unit.File_Names (Specification).Project;
3627 ALI_Name := No_Name;
3630 -- If we have something to put in the mapping
3631 -- then we do it now. However, if the project
3632 -- is extended, we don't put anything in the
3633 -- mapping file, because we do not know where
3634 -- the ALI file is: it might be in the ext-
3635 -- ended project obj dir as well as in the
3636 -- extending project obj dir.
3638 if ALI_Name /= No_Name
3640 Projects.Table (ALI_Project).Extended_By = No_Project
3642 Projects.Table (ALI_Project).Extends = No_Project
3644 -- First line is the unit name
3646 Get_Name_String (ALI_Unit);
3647 Name_Len := Name_Len + 1;
3648 Name_Buffer (Name_Len) := ASCII.LF;
3652 Name_Buffer (1)'Address,
3654 OK := Bytes = Name_Len;
3658 -- Second line it the ALI file name
3660 Get_Name_String (ALI_Name);
3661 Name_Len := Name_Len + 1;
3662 Name_Buffer (Name_Len) := ASCII.LF;
3666 Name_Buffer (1)'Address,
3668 OK := Bytes = Name_Len;
3672 -- Third line it the ALI path name,
3673 -- concatenation of the project
3674 -- directory with the ALI file name.
3677 ALI : constant String :=
3678 Get_Name_String (ALI_Name);
3681 (Projects.Table (ALI_Project).
3684 if Name_Buffer (Name_Len) /=
3687 Name_Len := Name_Len + 1;
3688 Name_Buffer (Name_Len) :=
3689 Directory_Separator;
3694 Name_Len + ALI'Length) := ALI;
3696 Name_Len + ALI'Length + 1;
3697 Name_Buffer (Name_Len) := ASCII.LF;
3701 Name_Buffer (1)'Address,
3703 OK := Bytes = Name_Len;
3706 -- If OK is False, it means we were unable
3707 -- to write a line. No point in continuing
3708 -- with the other units.
3716 Close (Mapping_FD, Status);
3718 OK := OK and Status;
3720 -- If the creation of the mapping file was successful,
3721 -- we add the switch to the arguments of gnatbind.
3724 Last_Arg := Last_Arg + 1;
3726 new String'("-F
=" & Get_Name_String (Mapping_Path));
3729 end Create_Binder_Mapping_File;
3731 -- Start of processing for Gnatmake
3733 -- This body is very long, should be broken down ???
3736 Gnatmake_Called := True;
3738 Install_Int_Handler (Sigint_Intercepted'Access);
3740 Do_Compile_Step := True;
3741 Do_Bind_Step := True;
3742 Do_Link_Step := True;
3748 Bind_Shared := No_Shared_Switch'Access;
3749 Link_With_Shared_Libgcc := No_Shared_Libgcc_Switch'Access;
3751 Failed_Links.Set_Last (0);
3752 Successful_Links.Set_Last (0);
3754 if Hostparm.Java_VM then
3755 Gcc := new String'("jgnat
");
3756 Gnatbind := new String'("jgnatbind
");
3757 Gnatlink := new String'("jgnatlink
");
3759 -- Do not check for an object file (".o
") when compiling to
3760 -- Java bytecode since ".class
" files are generated instead.
3762 Check_Object_Consistency := False;
3765 -- Special case when switch -B was specified
3767 if Build_Bind_And_Link_Full_Project then
3769 -- When switch -B is specified, there must be a project file
3771 if Main_Project = No_Project then
3772 Make_Failed ("-B cannot be used without a project file
");
3774 -- No main program may be specified on the command line
3776 elsif Osint.Number_Of_Files /= 0 then
3777 Make_Failed ("-B cannot be used
with a main specified on
" &
3778 "the command line
");
3780 -- And the project file cannot be a library project file
3782 elsif Projects.Table (Main_Project).Library then
3783 Make_Failed ("-B cannot be used
for a library project file
");
3786 Insert_Project_Sources
3787 (The_Project => Main_Project,
3788 All_Projects => Unique_Compile_All_Projects,
3791 -- If there are no sources to compile, we fail
3793 if Osint.Number_Of_Files = 0 then
3794 Make_Failed ("no sources to compile
");
3797 -- Specify -n for gnatbind and add the ALI files of all the
3798 -- sources, except the one which is a fake main subprogram:
3799 -- this is the one for the binder generated file and it will be
3800 -- transmitted to gnatlink. These sources are those that are
3803 Add_Switch ("-n
", Binder, And_Save => True);
3805 for J in Q.First .. Q.Last - 1 loop
3808 (Lib_File_Name (Q.Table (J).File)),
3809 Binder, And_Save => True);
3813 elsif Main_Index /= 0 and then Osint.Number_Of_Files > 1 then
3814 Make_Failed ("cannot specify several mains
with a multi
-unit index
");
3816 elsif Main_Project /= No_Project then
3818 -- If the main project file is a library project file, main(s)
3819 -- cannot be specified on the command line.
3821 if Osint.Number_Of_Files /= 0 then
3822 if Projects.Table (Main_Project).Library
3823 and then not Unique_Compile
3824 and then ((not Make_Steps) or else Bind_Only or else Link_Only)
3826 Make_Failed ("cannot specify a main program
" &
3827 "on the command line
for a library project file
");
3830 -- Check that each main on the command line is a source of a
3831 -- project file and, if there are several mains, each of them
3832 -- is a source of the same project file.
3837 -- If no mains have been specified on the command line,
3838 -- and we are using a project file, we either find the main(s)
3839 -- in the attribute Main of the main project, or we put all
3840 -- the sources of the project file as mains.
3843 if Main_Index /= 0 then
3844 Make_Failed ("cannot specify a multi
-unit index but no main
" &
3845 "on the command line
");
3849 Value : String_List_Id := Projects.Table (Main_Project).Mains;
3852 -- The attribute Main is an empty list or not specified,
3853 -- or else gnatmake was invoked with the switch "-u
".
3855 if Value = Prj.Nil_String or else Unique_Compile then
3857 if (not Make_Steps) or else Compile_Only
3858 or else not Projects.Table (Main_Project).Library
3860 -- First make sure that the binder and the linker
3861 -- will not be invoked.
3863 Do_Bind_Step := False;
3864 Do_Link_Step := False;
3866 -- Put all the sources in the queue
3868 Insert_Project_Sources
3869 (The_Project => Main_Project,
3870 All_Projects => Unique_Compile_All_Projects,
3873 -- If there are no sources to compile, we fail
3875 if Osint.Number_Of_Files = 0 then
3876 Make_Failed ("no sources to compile
");
3881 -- The attribute Main is not an empty list.
3882 -- Put all the main subprograms in the list as if there
3883 -- were specified on the command line. However, if attribute
3884 -- Languages includes a language other than Ada, only
3885 -- include the Ada mains; if there is no Ada main, compile
3886 -- all the sources of the project.
3889 Data : constant Project_Data :=
3890 Projects.Table (Main_Project);
3892 Languages : constant Variable_Value :=
3894 (Name_Languages, Data.Decl.Attributes);
3896 Current : String_List_Id;
3897 Element : String_Element;
3899 Foreign_Language : Boolean := False;
3900 At_Least_One_Main : Boolean := False;
3903 -- First, determine if there is a foreign language in
3904 -- attribute Languages.
3906 if not Languages.Default then
3907 Current := Languages.Values;
3910 while Current /= Nil_String loop
3911 Element := String_Elements.Table (Current);
3912 Get_Name_String (Element.Value);
3913 To_Lower (Name_Buffer (1 .. Name_Len));
3915 if Name_Buffer (1 .. Name_Len) /= "ada
" then
3916 Foreign_Language := True;
3917 exit Look_For_Foreign;
3920 Current := Element.Next;
3921 end loop Look_For_Foreign;
3924 -- Then, find all mains, or if there is a foreign
3925 -- language, all the Ada mains.
3927 while Value /= Prj.Nil_String loop
3928 Get_Name_String (String_Elements.Table (Value).Value);
3930 -- To know if a main is an Ada main, get its project.
3931 -- It should be the project specified on the command
3934 if (not Foreign_Language) or else
3936 (Name_Buffer (1 .. Name_Len), Main_Project) =
3939 At_Least_One_Main := True;
3942 (String_Elements.Table (Value).Value),
3943 Index => String_Elements.Table (Value).Index);
3946 Value := String_Elements.Table (Value).Next;
3949 -- If we did not get any main, it means that all mains
3950 -- in attribute Mains are in a foreign language and -B
3951 -- was not specified to gnatmake; so, we fail.
3953 if not At_Least_One_Main then
3955 ("no Ada mains
; use -B to build foreign main
");
3964 if Verbose_Mode then
3966 Write_Str ("GNATMAKE
");
3967 Write_Str (Gnatvsn.Gnat_Version_String);
3969 Write_Str ("Copyright
1995-2004 Free Software Foundation
, Inc
.");
3973 if Osint.Number_Of_Files = 0 then
3974 if Main_Project /= No_Project
3975 and then Projects.Table (Main_Project).Library
3978 and then not Projects.Table (Main_Project).Standalone_Library
3980 Make_Failed ("only stand
-alone libraries may be bound
");
3983 -- Add the default search directories to be able to find libgnat
3985 Osint.Add_Default_Search_Dirs;
3987 -- And bind and or link the library
3989 MLib.Prj.Build_Library
3990 (For_Project => Main_Project,
3991 Gnatbind => Gnatbind.all,
3992 Gnatbind_Path => Gnatbind_Path,
3994 Gcc_Path => Gcc_Path,
3997 Exit_Program (E_Success);
4000 -- Output usage information if no files to compile
4003 Exit_Program (E_Fatal);
4007 -- If -M was specified, behave as if -n was specified
4009 if List_Dependencies then
4010 Do_Not_Execute := True;
4013 -- Note that Osint.Next_Main_Source will always return the (possibly
4014 -- abbreviated file) without any directory information.
4016 Main_Source_File := Next_Main_Source;
4018 if Current_File_Index /= No_Index then
4019 Main_Index := Current_File_Index;
4022 Add_Switch ("-I
-", Binder, And_Save => True);
4023 Add_Switch ("-I
-", Compiler, And_Save => True);
4025 if Main_Project = No_Project then
4026 if Look_In_Primary_Dir then
4030 Normalize_Directory_Name
4031 (Get_Primary_Src_Search_Directory.all).all,
4032 Compiler, Append_Switch => False,
4035 Add_Switch ("-aO
" & Normalized_CWD,
4037 Append_Switch => False,
4042 -- If we use a project file, we have already checked that a main
4043 -- specified on the command line with directory information has the
4044 -- path name corresponding to a correct source in the project tree.
4045 -- So, we don't need the directory information to be taken into
4046 -- account by Find_File, and in fact it may lead to take the wrong
4047 -- sources for other compilation units, when there are extending
4050 Look_In_Primary_Dir := False;
4053 -- If the user wants a program without a main subprogram, add the
4054 -- appropriate switch to the binder.
4056 if No_Main_Subprogram then
4057 Add_Switch ("-z
", Binder, And_Save => True);
4060 if Main_Project /= No_Project then
4062 if Projects.Table (Main_Project).Object_Directory = No_Name then
4063 Make_Failed ("no sources to compile
");
4066 -- Change the current directory to the object directory of the main
4070 Project_Object_Directory := No_Project;
4071 Change_To_Object_Directory (Main_Project);
4074 when Directory_Error =>
4076 -- This should never happen. But, if it does, display the
4077 -- content of the parent directory of the obj dir.
4080 Parent : constant Dir_Name_Str :=
4083 (Projects.Table (Main_Project).Object_Directory));
4085 Str : String (1 .. 200);
4089 Write_Str ("Contents
of directory
""");
4096 Read (Dir, Str, Last);
4099 Write_Line (Str (1 .. Last));
4106 Write_Line ("(unexpected
exception)");
4107 Write_Line (Exception_Information (X));
4109 if Is_Open (Dir) then
4114 Make_Failed ("unable to change working directory to
""",
4116 (Projects.Table (Main_Project).Object_Directory),
4120 -- Source file lookups should be cached for efficiency.
4121 -- Source files are not supposed to change.
4123 Osint.Source_File_Data (Cache => True);
4125 -- Find the file name of the (first) main unit
4128 Main_Source_File_Name : constant String :=
4129 Get_Name_String (Main_Source_File);
4130 Main_Unit_File_Name : constant String :=
4131 Prj.Env.File_Name_Of_Library_Unit_Body
4132 (Name => Main_Source_File_Name,
4133 Project => Main_Project,
4134 Main_Project_Only =>
4135 not Unique_Compile);
4137 The_Packages : constant Package_Id :=
4138 Projects.Table (Main_Project).Decl.Packages;
4140 Builder_Package : constant Prj.Package_Id :=
4142 (Name => Name_Builder,
4143 In_Packages => The_Packages);
4145 Binder_Package : constant Prj.Package_Id :=
4147 (Name => Name_Binder,
4148 In_Packages => The_Packages);
4150 Linker_Package : constant Prj.Package_Id :=
4152 (Name => Name_Linker,
4153 In_Packages => The_Packages);
4156 -- We fail if we cannot find the main source file
4158 if Main_Unit_File_Name = "" then
4159 Make_Failed ('"' & Main_Source_File_Name,
4160 """ is not a unit of project ",
4161 Project_File_Name.all & ".");
4163 -- Remove any directory information from the main
4164 -- source file name.
4167 Pos : Natural := Main_Unit_File_Name'Last;
4171 exit when Pos < Main_Unit_File_Name'First or else
4172 Main_Unit_File_Name (Pos) = Directory_Separator;
4176 Name_Len := Main_Unit_File_Name'Last - Pos;
4178 Name_Buffer (1 .. Name_Len) :=
4180 (Pos + 1 .. Main_Unit_File_Name'Last);
4182 Main_Source_File := Name_Find;
4184 -- We only output the main source file if there is only one
4186 if Verbose_Mode and then Osint.Number_Of_Files = 1 then
4187 Write_Str ("Main source file: """);
4188 Write_Str (Main_Unit_File_Name
4189 (Pos + 1 .. Main_Unit_File_Name'Last));
4195 -- If there is a package Builder in the main project file, add
4196 -- the switches from it.
4198 if Builder_Package /= No_Package then
4200 -- If there is only one main, we attempt to get the gnatmake
4201 -- switches for this main (if any). If there are no specific
4202 -- switch for this particular main, get the general gnatmake
4203 -- switches (if any).
4205 if Osint.Number_Of_Files = 1 then
4206 if Verbose_Mode then
4207 Write_Str ("Adding gnatmake switches for """);
4208 Write_Str (Main_Unit_File_Name);
4213 (File_Name => Main_Unit_File_Name,
4214 Index => Main_Index,
4215 The_Package => Builder_Package,
4219 -- If there are several mains, we always get the general
4220 -- gnatmake switches (if any).
4222 -- Warn the user, if necessary, so that he is not surprized
4223 -- that specific switches are not taken into account.
4226 Defaults : constant Variable_Value :=
4230 Attribute_Or_Array_Name => Name_Default_Switches,
4231 In_Package => Builder_Package);
4233 Switches : constant Array_Element_Id :=
4235 (Name => Name_Switches,
4237 Packages.Table (Builder_Package).Decl.Arrays);
4240 if Defaults /= Nil_Variable_Value then
4241 if (not Quiet_Output)
4242 and then Switches /= No_Array_Element
4245 ("Warning: using Builder'Default_Switches" &
4246 "(""Ada""), as there are several mains");
4249 -- As there is never a source with name " ", we are
4250 -- guaranteed to always get the general switches.
4255 The_Package => Builder_Package,
4258 elsif (not Quiet_Output)
4259 and then Switches /= No_Array_Element
4262 ("Warning: using no switches from package Builder," &
4263 " as there are several mains");
4269 Osint.Add_Default_Search_Dirs;
4271 -- Record the current last switch index for table Binder_Switches
4272 -- and Linker_Switches, so that these tables may be reset before
4273 -- for each main, before adding swiches from the project file
4274 -- and from the command line.
4276 Last_Binder_Switch := Binder_Switches.Last;
4277 Last_Linker_Switch := Linker_Switches.Last;
4281 -- Add binder switches from the project file for the first main
4283 if Do_Bind_Step and Binder_Package /= No_Package then
4284 if Verbose_Mode then
4285 Write_Str ("Adding binder switches for """);
4286 Write_Str (Main_Unit_File_Name);
4291 (File_Name => Main_Unit_File_Name,
4292 Index => Main_Index,
4293 The_Package => Binder_Package,
4297 -- Add linker switches from the project file for the first main
4299 if Do_Link_Step and Linker_Package /= No_Package then
4300 if Verbose_Mode then
4301 Write_Str ("Adding linker switches for""");
4302 Write_Str (Main_Unit_File_Name);
4307 (File_Name => Main_Unit_File_Name,
4308 Index => Main_Index,
4309 The_Package => Linker_Package,
4315 -- Get the target parameters, which are only needed for a couple of
4316 -- cases in gnatmake. Protect against an exception, such as the case
4317 -- of system.ads missing from the library, and fail gracefully.
4320 Targparm.Get_Target_Parameters;
4323 when Unrecoverable_Error =>
4324 Make_Failed ("*** make failed.");
4327 Display_Commands (not Quiet_Output);
4331 if Main_Project /= No_Project then
4333 -- For all library project, if the library file does not exist
4334 -- put all the project sources in the queue, and flag the project
4335 -- so that the library is generated.
4337 if MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None then
4338 for Proj in Projects.First .. Projects.Last loop
4339 if Projects.Table (Proj).Library then
4340 Projects.Table (Proj).Need_To_Build_Lib :=
4341 not MLib.Tgt.Library_Exists_For (Proj);
4343 if Projects.Table (Proj).Need_To_Build_Lib then
4344 -- If there is no object directory, then it will be
4345 -- impossible to build the library. So, we fail
4348 if Projects.Table (Proj).Object_Directory = No_Name then
4350 ("no object files to build library for project """,
4351 Get_Name_String (Projects.Table (Proj).Name),
4353 Projects.Table (Proj).Need_To_Build_Lib := False;
4356 if Verbose_Mode then
4358 ("Library file does not exist for project """);
4360 (Get_Name_String (Projects.Table (Proj).Name));
4364 Insert_Project_Sources
4365 (The_Project => Proj,
4366 All_Projects => False,
4374 -- If a relative path output file has been specified, we add
4375 -- the exec directory.
4377 for J in reverse 1 .. Saved_Linker_Switches.Last - 1 loop
4378 if Saved_Linker_Switches.Table (J).all = Output_Flag.all then
4380 Exec_File_Name : constant String :=
4381 Saved_Linker_Switches.Table (J + 1).all;
4384 if not Is_Absolute_Path (Exec_File_Name) then
4385 for Index in Exec_File_Name'Range loop
4386 if Exec_File_Name (Index) = Directory_Separator then
4387 Make_Failed ("relative executable (""",
4389 """) with directory part not " &
4390 "allowed when using project files");
4394 Get_Name_String (Projects.Table
4395 (Main_Project).Exec_Directory);
4397 if Name_Buffer (Name_Len) /= Directory_Separator then
4398 Name_Len := Name_Len + 1;
4399 Name_Buffer (Name_Len) := Directory_Separator;
4402 Name_Buffer (Name_Len + 1 ..
4403 Name_Len + Exec_File_Name'Length) :=
4405 Name_Len := Name_Len + Exec_File_Name'Length;
4406 Saved_Linker_Switches.Table (J + 1) :=
4407 new String'(Name_Buffer
(1 .. Name_Len
));
4415 -- If we are using a project file, for relative paths we add the
4416 -- current working directory for any relative path on the command
4417 -- line and the project directory, for any relative path in the
4421 Dir_Path
: constant String_Access
:=
4422 new String'(Get_Name_String
4423 (Projects.Table (Main_Project).Directory));
4425 for J in 1 .. Binder_Switches.Last loop
4426 Test_If_Relative_Path
4427 (Binder_Switches.Table (J),
4428 Parent => Dir_Path, Including_L_Switch => False);
4431 for J in 1 .. Saved_Binder_Switches.Last loop
4432 Test_If_Relative_Path
4433 (Saved_Binder_Switches.Table (J),
4434 Parent => Current_Work_Dir, Including_L_Switch => False);
4437 for J in 1 .. Linker_Switches.Last loop
4438 Test_If_Relative_Path
4439 (Linker_Switches.Table (J), Parent => Dir_Path);
4442 for J in 1 .. Saved_Linker_Switches.Last loop
4443 Test_If_Relative_Path
4444 (Saved_Linker_Switches.Table (J), Parent => Current_Work_Dir);
4447 for J in 1 .. Gcc_Switches.Last loop
4448 Test_If_Relative_Path
4449 (Gcc_Switches.Table (J), Parent => Dir_Path);
4452 for J in 1 .. Saved_Gcc_Switches.Last loop
4453 Test_If_Relative_Path
4454 (Saved_Gcc_Switches.Table (J), Parent => Current_Work_Dir);
4459 -- We now put in the Binder_Switches and Linker_Switches tables,
4460 -- the binder and linker switches of the command line that have been
4461 -- put in the Saved_ tables. If a project file was used, then the
4462 -- command line switches will follow the project file switches.
4464 for J in 1 .. Saved_Binder_Switches.Last loop
4466 (Saved_Binder_Switches.Table (J),
4471 for J in 1 .. Saved_Linker_Switches.Last loop
4473 (Saved_Linker_Switches.Table (J),
4478 -- If no project file is used, we just put the gcc switches
4479 -- from the command line in the Gcc_Switches table.
4481 if Main_Project = No_Project then
4482 for J in 1 .. Saved_Gcc_Switches.Last loop
4484 (Saved_Gcc_Switches.Table (J),
4490 -- And we put the command line gcc switches in the variable
4491 -- The_Saved_Gcc_Switches. They are going to be used later
4492 -- in procedure Compile_Sources.
4494 The_Saved_Gcc_Switches :=
4495 new Argument_List (1 .. Saved_Gcc_Switches.Last + 1);
4497 for J in 1 .. Saved_Gcc_Switches.Last loop
4498 The_Saved_Gcc_Switches (J) := Saved_Gcc_Switches.Table (J);
4501 -- We never use gnat.adc when a project file is used
4503 The_Saved_Gcc_Switches (The_Saved_Gcc_Switches'Last) :=
4508 -- If there was a --GCC, --GNATBIND or --GNATLINK switch on
4509 -- the command line, then we have to use it, even if there was
4510 -- another switch in the project file.
4512 if Saved_Gcc /= null then
4516 if Saved_Gnatbind /= null then
4517 Gnatbind := Saved_Gnatbind;
4520 if Saved_Gnatlink /= null then
4521 Gnatlink := Saved_Gnatlink;
4524 Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
4525 Gnatbind_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
4526 Gnatlink_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
4528 -- If we have specified -j switch both from the project file
4529 -- and on the command line, the one from the command line takes
4532 if Saved_Maximum_Processes = 0 then
4533 Saved_Maximum_Processes := Maximum_Processes;
4536 -- Allocate as many temporary mapping file names as the maximum
4537 -- number of compilation processed, for each possible project.
4539 The_Mapping_File_Names :=
4541 (No_Project .. Projects.Last, 1 .. Saved_Maximum_Processes);
4542 Last_Mapping_File_Names :=
4543 new Indices'(No_Project
.. Projects
.Last
=> 0);
4545 The_Free_Mapping_File_Indices
:=
4546 new Free_File_Indices
4547 (No_Project
.. Projects
.Last
, 1 .. Saved_Maximum_Processes
);
4548 Last_Free_Indices
:=
4549 new Indices
'(No_Project .. Projects.Last => 0);
4551 Bad_Compilation.Init;
4553 Current_Main_Index := Main_Index;
4555 -- Here is where the make process is started
4557 -- We do the same process for each main
4559 Multiple_Main_Loop : for N_File in 1 .. Osint.Number_Of_Files loop
4561 -- First, find the executable name and path
4563 Executable := No_File;
4564 Executable_Obsolete := False;
4565 Non_Std_Executable := False;
4567 -- Look inside the linker switches to see if the name
4568 -- of the final executable program was specified.
4571 J in reverse Linker_Switches.First .. Linker_Switches.Last
4573 if Linker_Switches.Table (J).all = Output_Flag.all then
4574 pragma Assert (J < Linker_Switches.Last);
4576 -- We cannot specify a single executable for several
4577 -- main subprograms!
4579 if Osint.Number_Of_Files > 1 then
4581 ("cannot specify a single executable " &
4582 "for several mains");
4585 Name_Len := Linker_Switches.Table (J + 1)'Length;
4586 Name_Buffer (1 .. Name_Len) :=
4587 Linker_Switches.Table (J + 1).all;
4588 Executable := Name_Enter;
4590 Verbose_Msg (Executable, "final executable");
4594 -- If the name of the final executable program was not
4595 -- specified then construct it from the main input file.
4597 if Executable = No_File then
4598 if Main_Project = No_Project then
4600 Executable_Name (Strip_Suffix (Main_Source_File));
4603 -- If we are using a project file, we attempt to
4604 -- remove the body (or spec) termination of the main
4605 -- subprogram. We find it the the naming scheme of the
4606 -- project file. This will avoid to generate an
4607 -- executable "main.2" for a main subprogram
4608 -- "main.2.ada", when the body termination is ".2.ada".
4610 Executable := Prj.Util.Executable_Of
4611 (Main_Project, Main_Source_File, Main_Index);
4615 if Main_Project /= No_Project then
4617 Exec_File_Name : constant String :=
4618 Get_Name_String (Executable);
4621 if not Is_Absolute_Path (Exec_File_Name) then
4622 for Index in Exec_File_Name'Range loop
4623 if Exec_File_Name (Index) = Directory_Separator then
4624 Make_Failed ("relative executable (""",
4626 """) with directory part not " &
4627 "allowed when using project files");
4631 Get_Name_String (Projects.Table
4632 (Main_Project).Exec_Directory);
4635 Name_Buffer (Name_Len) /= Directory_Separator
4637 Name_Len := Name_Len + 1;
4638 Name_Buffer (Name_Len) := Directory_Separator;
4641 Name_Buffer (Name_Len + 1 ..
4642 Name_Len + Exec_File_Name'Length) :=
4644 Name_Len := Name_Len + Exec_File_Name'Length;
4645 Executable := Name_Find;
4646 Non_Std_Executable := True;
4652 if Do_Compile_Step then
4653 Recursive_Compilation_Step : declare
4654 Args : Argument_List (1 .. Gcc_Switches.Last);
4656 First_Compiled_File : Name_Id;
4657 Youngest_Obj_File : Name_Id;
4658 Youngest_Obj_Stamp : Time_Stamp_Type;
4660 Executable_Stamp : Time_Stamp_Type;
4661 -- Executable is the final executable program.
4663 Library_Rebuilt : Boolean := False;
4666 for J in 1 .. Gcc_Switches.Last loop
4667 Args (J) := Gcc_Switches.Table (J);
4670 -- Now we invoke Compile_Sources for the current main
4673 (Main_Source => Main_Source_File,
4675 First_Compiled_File => First_Compiled_File,
4676 Most_Recent_Obj_File => Youngest_Obj_File,
4677 Most_Recent_Obj_Stamp => Youngest_Obj_Stamp,
4678 Main_Unit => Is_Main_Unit,
4679 Main_Index => Current_Main_Index,
4680 Compilation_Failures => Compilation_Failures,
4681 Check_Readonly_Files => Check_Readonly_Files,
4682 Do_Not_Execute => Do_Not_Execute,
4683 Force_Compilations => Force_Compilations,
4684 In_Place_Mode => In_Place_Mode,
4685 Keep_Going => Keep_Going,
4686 Initialize_ALI_Data => True,
4687 Max_Process => Saved_Maximum_Processes);
4689 if Verbose_Mode then
4690 Write_Str ("End of compilation");
4694 -- Make sure the queue will be reinitialized for the next round
4696 First_Q_Initialization := True;
4698 Total_Compilation_Failures :=
4699 Total_Compilation_Failures + Compilation_Failures;
4701 if Total_Compilation_Failures /= 0 then
4706 List_Bad_Compilations;
4707 raise Compilation_Failed;
4711 -- Regenerate libraries, if any, and if object files
4712 -- have been regenerated.
4714 if Main_Project /= No_Project
4715 and then MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None
4716 and then (Do_Bind_Step or Unique_Compile_All_Projects
4717 or not Compile_Only)
4718 and then (Do_Link_Step or N_File = Osint.Number_Of_Files)
4728 -- Put in Library_Projs table all library project
4729 -- file ids when the library need to be rebuilt.
4731 for Proj1 in Projects.First .. Projects.Last loop
4733 if Projects.Table (Proj1).Standalone_Library then
4734 There_Are_Stand_Alone_Libraries := True;
4737 if Projects.Table (Proj1).Library
4738 and then not Projects.Table (Proj1).Need_To_Build_Lib
4740 MLib.Prj.Check_Library (Proj1);
4743 if Projects.Table (Proj1).Need_To_Build_Lib then
4744 Library_Projs.Increment_Last;
4745 Current := Library_Projs.Last;
4746 Depth := Projects.Table (Proj1).Depth;
4748 -- Put the projects in decreasing depth order,
4749 -- so that if libA depends on libB, libB is first
4752 while Current > 1 loop
4753 Proj2 := Library_Projs.Table (Current - 1);
4754 exit when Projects.Table (Proj2).Depth >= Depth;
4755 Library_Projs.Table (Current) := Proj2;
4756 Current := Current - 1;
4759 Library_Projs.Table (Current) := Proj1;
4760 Projects.Table (Proj1).Need_To_Build_Lib := False;
4765 -- Build the libraries, if any need to be built
4767 for J in 1 .. Library_Projs.Last loop
4768 Library_Rebuilt := True;
4769 MLib.Prj.Build_Library
4770 (For_Project => Library_Projs.Table (J),
4771 Gnatbind => Gnatbind.all,
4772 Gnatbind_Path => Gnatbind_Path,
4774 Gcc_Path => Gcc_Path);
4778 if List_Dependencies then
4779 if First_Compiled_File /= No_File then
4781 (First_Compiled_File,
4782 "must be recompiled. Can't generate dependence list.");
4787 elsif First_Compiled_File = No_File
4788 and then not Do_Bind_Step
4789 and then not Quiet_Output
4790 and then not Library_Rebuilt
4791 and then Osint.Number_Of_Files = 1
4793 Inform (Msg => "objects up to date.");
4795 elsif Do_Not_Execute
4796 and then First_Compiled_File /= No_File
4798 Write_Name (First_Compiled_File);
4802 -- Stop after compile step if any of:
4804 -- 1) -n (Do_Not_Execute) specified
4806 -- 2) -M (List_Dependencies) specified (also sets
4807 -- Do_Not_Execute above, so this is probably superfluous).
4809 -- 3) -c (Compile_Only) specified, but not -b (Bind_Only)
4811 -- 4) Made unit cannot be a main unit
4814 or List_Dependencies
4816 or not Is_Main_Unit)
4817 and then not No_Main_Subprogram
4818 and then not Build_Bind_And_Link_Full_Project
4820 if Osint.Number_Of_Files = 1 then
4821 exit Multiple_Main_Loop;
4828 -- If the objects were up-to-date check if the executable file
4829 -- is also up-to-date. For now always bind and link on the JVM
4830 -- since there is currently no simple way to check the
4831 -- up-to-date status of objects
4833 if not Hostparm.Java_VM
4834 and then First_Compiled_File = No_File
4836 Executable_Stamp := File_Stamp (Executable);
4838 if not Executable_Obsolete then
4839 Executable_Obsolete :=
4840 Youngest_Obj_Stamp > Executable_Stamp;
4843 if not Executable_Obsolete then
4844 for Index in reverse 1 .. Dependencies.Last loop
4846 (Dependencies.Table (Index).Depends_On)
4848 Enter_Into_Obsoleted
4849 (Dependencies.Table (Index).This);
4853 Executable_Obsolete := Is_In_Obsoleted (Main_Source_File);
4857 if not Executable_Obsolete then
4859 -- If no Ada object files obsolete the executable, check
4860 -- for younger or missing linker files.
4862 Check_Linker_Options
4865 Youngest_Obj_Stamp);
4867 Executable_Obsolete := Youngest_Obj_File /= No_File;
4870 -- Return if the executable is up to date
4871 -- and otherwise motivate the relink/rebind.
4873 if not Executable_Obsolete then
4874 if not Quiet_Output then
4875 Inform (Executable, "up to date.");
4878 if Osint.Number_Of_Files = 1 then
4879 exit Multiple_Main_Loop;
4886 if Executable_Stamp (1) = ' ' then
4887 Verbose_Msg (Executable, "missing.", Prefix => " ");
4889 elsif Youngest_Obj_Stamp (1) = ' ' then
4895 elsif Youngest_Obj_Stamp > Executable_Stamp then
4898 "(" & String (Youngest_Obj_Stamp) & ") newer than",
4900 "(" & String (Executable_Stamp) & ")");
4904 (Executable, "needs to be rebuild.",
4909 end Recursive_Compilation_Step;
4912 -- For binding and linking, we need to be in the object directory of
4913 -- the main project.
4915 if Main_Project /= No_Project then
4916 Change_To_Object_Directory (Main_Project);
4919 -- If we are here, it means that we need to rebuilt the current
4920 -- main. So we set Executable_Obsolete to True to make sure that
4921 -- the subsequent mains will be rebuilt.
4923 Main_ALI_In_Place_Mode_Step : declare
4924 ALI_File : File_Name_Type;
4925 Src_File : File_Name_Type;
4928 Src_File := Strip_Directory (Main_Source_File);
4929 ALI_File := Lib_File_Name (Src_File, Current_Main_Index);
4930 Main_ALI_File := Full_Lib_File_Name (ALI_File);
4932 -- When In_Place_Mode, the library file can be located in the
4933 -- Main_Source_File directory which may not be present in the
4934 -- library path. In this case, use the corresponding library file
4937 if Main_ALI_File = No_File and then In_Place_Mode then
4938 Get_Name_String (Get_Directory (Full_Source_Name (Src_File)));
4939 Get_Name_String_And_Append (ALI_File);
4940 Main_ALI_File := Name_Find;
4941 Main_ALI_File := Full_Lib_File_Name (Main_ALI_File);
4944 if Main_ALI_File = No_File then
4945 Make_Failed ("could not find the main ALI file");
4947 end Main_ALI_In_Place_Mode_Step;
4949 if Do_Bind_Step then
4951 Args : Argument_List
4952 (Binder_Switches.First .. Binder_Switches.Last + 2);
4953 -- The arguments for the invocation of gnatbind
4955 Last_Arg : Natural := Binder_Switches.Last;
4956 -- Index of the last argument in Args
4958 Shared_Libs : Boolean := False;
4959 -- Set to True when there are shared library project files or
4960 -- when gnatbind is invoked with -shared.
4963 -- Check if there are shared libraries, so that gnatbind is
4964 -- called with -shared. Check also if gnatbind is called with
4965 -- -shared, so that gnatlink is called with -shared-libgcc
4966 -- for GCC version 3 and above, ensuring that the shared
4967 -- version of libgcc will be used.
4969 if Main_Project /= No_Project
4970 and then MLib.Tgt.Support_For_Libraries /= MLib.Tgt.None
4972 for Proj in Projects.First .. Projects.Last loop
4973 if Projects.Table (Proj).Library and then
4974 Projects.Table (Proj).Library_Kind /= Static
4976 Shared_Libs := True;
4977 Bind_Shared := Shared_Switch'Access;
4983 -- Check now for switch -shared
4985 if not Shared_Libs then
4986 for J in Binder_Switches.First .. Last_Arg loop
4987 if Binder_Switches.Table (J).all = "-shared" then
4988 Shared_Libs := True;
4994 -- If there are shared libraries, invoke gnatlink with
4995 -- -shared-libgcc if GCC version is 3 or more.
4997 if Shared_Libs and then GCC_Version >= 3 then
4998 Link_With_Shared_Libgcc := Shared_Libgcc_Switch'Access;
5001 -- Get all the binder switches
5003 for J in Binder_Switches.First .. Last_Arg loop
5004 Args (J) := Binder_Switches.Table (J);
5007 if There_Are_Stand_Alone_Libraries then
5008 Last_Arg := Last_Arg + 1;
5009 Args (Last_Arg) := Force_Elab_Flags_String'Access;
5012 if Main_Project /= No_Project then
5014 -- Put all the source directories in ADA_INCLUDE_PATH,
5015 -- and all the object directories in ADA_OBJECTS_PATH
5017 Prj.Env.Set_Ada_Paths (Main_Project, False);
5019 -- If switch -C was specified, create a binder mapping file
5021 if Create_Mapping_File then
5022 Create_Binder_Mapping_File (Args, Last_Arg);
5028 Bind (Main_ALI_File,
5029 Bind_Shared.all & Args (Args'First .. Last_Arg));
5034 -- If -dn was not specified, delete the temporary mapping
5035 -- file, if one was created.
5037 if not Debug.Debug_Flag_N
5038 and then Mapping_Path /= No_Name
5040 Delete_File (Get_Name_String (Mapping_Path), Discard);
5043 -- And reraise the exception
5048 -- If -dn was not specified, delete the temporary mapping file,
5049 -- if one was created.
5051 if not Debug.Debug_Flag_N and then Mapping_Path /= No_Name then
5052 Delete_File (Get_Name_String (Mapping_Path), Discard);
5057 if Do_Link_Step then
5059 There_Are_Libraries : Boolean := False;
5060 Linker_Switches_Last : constant Integer := Linker_Switches.Last;
5061 Path_Option : constant String_Access :=
5062 MLib.Linker_Library_Path_Option;
5068 if not Run_Path_Option then
5069 Linker_Switches.Increment_Last;
5070 Linker_Switches.Table (Linker_Switches.Last) :=
5074 if Main_Project
/= No_Project
then
5075 Library_Paths
.Set_Last
(0);
5078 if MLib
.Tgt
.Support_For_Libraries
/= MLib
.Tgt
.None
then
5079 -- Check for library projects
5081 for Proj1
in 1 .. Projects
.Last
loop
5082 if Proj1
/= Main_Project
5083 and then Projects
.Table
(Proj1
).Library
5085 -- Add this project to table Library_Projs
5087 There_Are_Libraries
:= True;
5088 Depth
:= Projects
.Table
(Proj1
).Depth
;
5089 Library_Projs
.Increment_Last
;
5090 Current
:= Library_Projs
.Last
;
5092 -- Any project with a greater depth should be
5093 -- after this project in the list.
5095 while Current
> 1 loop
5096 Proj2
:= Library_Projs
.Table
(Current
- 1);
5097 exit when Projects
.Table
(Proj2
).Depth
<= Depth
;
5098 Library_Projs
.Table
(Current
) := Proj2
;
5099 Current
:= Current
- 1;
5102 Library_Projs
.Table
(Current
) := Proj1
;
5104 -- If it is not a static library and path option
5105 -- is set, add it to the Library_Paths table.
5107 if Projects
.Table
(Proj1
).Library_Kind
/= Static
5108 and then Path_Option
/= null
5110 Library_Paths
.Increment_Last
;
5111 Library_Paths
.Table
(Library_Paths
.Last
) :=
5114 (Projects.Table (Proj1).Library_Dir));
5119 for Index in 1 .. Library_Projs.Last loop
5120 -- Add the -L switch
5122 Linker_Switches.Increment_Last;
5123 Linker_Switches.Table (Linker_Switches.Last) :=
5127 (Library_Projs
.Table
(Index
)).
5130 -- Add the -l switch
5132 Linker_Switches
.Increment_Last
;
5133 Linker_Switches
.Table
(Linker_Switches
.Last
) :=
5137 (Library_Projs.Table (Index)).
5142 if There_Are_Libraries then
5144 -- If Path_Option is not null, create the switch
5145 -- ("-Wl,-rpath," or equivalent) with all the non static
5146 -- library dirs plus the standard GNAT library dir.
5147 -- We do that only if Run_Path_Option is True
5148 -- (not disabled by -R switch).
5150 if Run_Path_Option and Path_Option /= null then
5152 Option : String_Access;
5153 Length : Natural := Path_Option'Length;
5158 Library_Paths.First .. Library_Paths.Last
5160 -- Add the length of the library dir plus one
5161 -- for the directory separator.
5165 Library_Paths.Table (Index)'Length + 1;
5168 -- Finally, add the length of the standard GNAT
5171 Length := Length + MLib.Utl.Lib_Directory'Length;
5172 Option := new String (1 .. Length);
5173 Option (1 .. Path_Option'Length) := Path_Option.all;
5174 Current := Path_Option'Length;
5176 -- Put each library dir followed by a dir separator
5179 Library_Paths.First .. Library_Paths.Last
5184 Library_Paths.Table (Index)'Length) :=
5185 Library_Paths.Table (Index).all;
5188 Library_Paths.Table (Index)'Length + 1;
5189 Option (Current) := Path_Separator;
5192 -- Finally put the standard GNAT library dir
5196 Current + MLib.Utl.Lib_Directory'Length) :=
5197 MLib.Utl.Lib_Directory;
5199 -- And add the switch to the linker switches
5201 Linker_Switches.Increment_Last;
5202 Linker_Switches.Table (Linker_Switches.Last) :=
5209 -- Put the object directories in ADA_OBJECTS_PATH
5211 Prj.Env.Set_Ada_Paths (Main_Project, False);
5213 -- Check for attributes Linker'Linker_Options in projects
5214 -- other than the main project
5217 Linker_Options : constant String_List :=
5218 Linker_Options_Switches (Main_Project);
5221 for Option in Linker_Options'Range loop
5222 Linker_Switches.Increment_Last;
5223 Linker_Switches.Table (Linker_Switches.Last) :=
5224 Linker_Options (Option);
5230 Args : Argument_List
5231 (Linker_Switches.First .. Linker_Switches.Last + 2);
5233 Last_Arg : Integer := Linker_Switches.First - 1;
5234 Skip : Boolean := False;
5237 -- Get all the linker switches
5239 for J in Linker_Switches.First .. Linker_Switches.Last loop
5243 elsif Non_Std_Executable
5244 and then Linker_Switches.Table (J).all = "-o"
5249 Last_Arg := Last_Arg + 1;
5250 Args (Last_Arg) := Linker_Switches.Table (J);
5254 -- If need be, add the -o switch
5256 if Non_Std_Executable then
5257 Last_Arg := Last_Arg + 1;
5258 Args (Last_Arg) := new String'("-o");
5259 Last_Arg
:= Last_Arg
+ 1;
5261 new String'(Get_Name_String (Executable));
5264 -- And invoke the linker
5267 Link (Main_ALI_File,
5268 Link_With_Shared_Libgcc.all &
5269 Args (Args'First .. Last_Arg));
5270 Successful_Links.Increment_Last;
5271 Successful_Links.Table (Successful_Links.Last) :=
5276 if Osint.Number_Of_Files = 1 or not Keep_Going then
5280 Write_Line ("*** link failed");
5281 Failed_Links.Increment_Last;
5282 Failed_Links.Table (Failed_Links.Last) :=
5288 Linker_Switches.Set_Last (Linker_Switches_Last);
5292 -- We go to here when we skip the bind and link steps.
5296 -- We go to the next main, if we did not process the last one
5298 if N_File < Osint.Number_Of_Files then
5299 Main_Source_File := Next_Main_Source;
5301 if Current_File_Index /= No_Index then
5302 Main_Index := Current_File_Index;
5305 if Main_Project /= No_Project then
5307 -- Find the file name of the main unit
5310 Main_Source_File_Name : constant String :=
5311 Get_Name_String (Main_Source_File);
5313 Main_Unit_File_Name : constant String :=
5315 File_Name_Of_Library_Unit_Body
5316 (Name => Main_Source_File_Name,
5317 Project => Main_Project,
5318 Main_Project_Only =>
5319 not Unique_Compile);
5321 The_Packages : constant Package_Id :=
5322 Projects.Table (Main_Project).Decl.Packages;
5324 Binder_Package : constant Prj.Package_Id :=
5326 (Name => Name_Binder,
5327 In_Packages => The_Packages);
5329 Linker_Package : constant Prj.Package_Id :=
5331 (Name => Name_Linker,
5332 In_Packages => The_Packages);
5335 -- We fail if we cannot find the main source file
5336 -- as an immediate source of the main project file.
5338 if Main_Unit_File_Name = "" then
5339 Make_Failed ('"' & Main_Source_File_Name,
5340 """ is not a unit
of project
",
5341 Project_File_Name.all & ".");
5344 -- Remove any directory information from the main
5345 -- source file name.
5348 Pos : Natural := Main_Unit_File_Name'Last;
5352 exit when Pos < Main_Unit_File_Name'First
5354 Main_Unit_File_Name (Pos) = Directory_Separator;
5358 Name_Len := Main_Unit_File_Name'Last - Pos;
5360 Name_Buffer (1 .. Name_Len) :=
5362 (Pos + 1 .. Main_Unit_File_Name'Last);
5364 Main_Source_File := Name_Find;
5368 -- We now deal with the binder and linker switches.
5369 -- If no project file is used, there is nothing to do
5370 -- because the binder and linker switches are the same
5373 -- Reset the tables Binder_Switches and Linker_Switches
5375 Binder_Switches.Set_Last (Last_Binder_Switch);
5376 Linker_Switches.Set_Last (Last_Linker_Switch);
5378 -- Add binder switches from the project file for this main,
5381 if Do_Bind_Step and Binder_Package /= No_Package then
5382 if Verbose_Mode then
5383 Write_Str ("Adding binder switches
for """);
5384 Write_Str (Main_Unit_File_Name);
5389 (File_Name => Main_Unit_File_Name,
5390 Index => Main_Index,
5391 The_Package => Binder_Package,
5395 -- Add linker switches from the project file for this main,
5398 if Do_Link_Step and Linker_Package /= No_Package then
5399 if Verbose_Mode then
5400 Write_Str ("Adding linker switches
for""");
5401 Write_Str (Main_Unit_File_Name);
5406 (File_Name => Main_Unit_File_Name,
5407 Index => Main_Index,
5408 The_Package => Linker_Package,
5412 -- As we are using a project file, for relative paths we add
5413 -- the current working directory for any relative path on
5414 -- the command line and the project directory, for any
5415 -- relative path in the project file.
5418 Dir_Path : constant String_Access :=
5419 new String'(Get_Name_String
5420 (Projects.Table (Main_Project).Directory));
5423 J in Last_Binder_Switch + 1 .. Binder_Switches.Last
5425 Test_If_Relative_Path
5426 (Binder_Switches.Table (J),
5427 Parent => Dir_Path, Including_L_Switch => False);
5431 J in Last_Linker_Switch + 1 .. Linker_Switches.Last
5433 Test_If_Relative_Path
5434 (Linker_Switches.Table (J), Parent => Dir_Path);
5438 -- We now put in the Binder_Switches and Linker_Switches
5439 -- tables, the binder and linker switches of the command
5440 -- line that have been put in the Saved_ tables.
5441 -- These switches will follow the project file switches.
5443 for J in 1 .. Saved_Binder_Switches.Last loop
5445 (Saved_Binder_Switches.Table (J),
5450 for J in 1 .. Saved_Linker_Switches.Last loop
5452 (Saved_Linker_Switches.Table (J),
5460 -- Remove all marks to be sure to check sources for all executables,
5461 -- as the switches may be different and -s may be in use.
5464 end loop Multiple_Main_Loop;
5466 if Failed_Links.Last > 0 then
5467 for Index in 1 .. Successful_Links.Last loop
5468 Write_Str ("Linking
of """);
5469 Write_Str (Get_Name_String (Successful_Links.Table (Index)));
5470 Write_Line (""" succeeded
.");
5473 for Index in 1 .. Failed_Links.Last loop
5474 Write_Str ("Linking
of """);
5475 Write_Str (Get_Name_String (Failed_Links.Table (Index)));
5476 Write_Line (""" failed
.");
5479 if Total_Compilation_Failures = 0 then
5480 raise Compilation_Failed;
5484 if Total_Compilation_Failures /= 0 then
5485 List_Bad_Compilations;
5486 raise Compilation_Failed;
5489 -- Delete the temporary mapping file that was created if we are
5490 -- using project files.
5492 if not Debug.Debug_Flag_N then
5493 Delete_Mapping_Files;
5494 Prj.Env.Delete_All_Path_Files;
5497 Exit_Program (E_Success);
5501 Make_Failed ("*** bind failed
.");
5503 when Compilation_Failed =>
5504 if not Debug.Debug_Flag_N then
5505 Delete_Mapping_Files;
5506 Prj.Env.Delete_All_Path_Files;
5509 Exit_Program (E_Fatal);
5512 Make_Failed ("*** link failed
.");
5515 Write_Line (Exception_Information (X));
5516 Make_Failed ("INTERNAL ERROR
. Please report
.");
5523 function Hash (F : Name_Id) return Header_Num is
5525 return Header_Num (1 + F mod Max_Header);
5528 --------------------
5529 -- In_Ada_Lib_Dir --
5530 --------------------
5532 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean is
5533 D : constant Name_Id := Get_Directory (File);
5534 B : constant Byte := Get_Name_Table_Byte (D);
5536 return (B and Ada_Lib_Dir) /= 0;
5543 procedure Inform (N : Name_Id := No_Name; Msg : String) is
5545 Osint.Write_Program_Name;
5549 if N /= No_Name then
5559 -----------------------
5560 -- Init_Mapping_File --
5561 -----------------------
5563 procedure Init_Mapping_File
5564 (Project : Project_Id;
5565 File_Index : in out Natural)
5567 FD : File_Descriptor;
5570 -- For call to Close
5573 -- Increase the index of the last mapping file for this project
5575 Last_Mapping_File_Names (Project) :=
5576 Last_Mapping_File_Names (Project) + 1;
5578 -- If there is a project file, call Create_Mapping_File with
5581 if Project /= No_Project then
5582 Prj.Env.Create_Mapping_File
5584 The_Mapping_File_Names
5585 (Project, Last_Mapping_File_Names (Project)));
5587 -- Otherwise, just create an empty file
5590 Tempdir.Create_Temp_File
5592 The_Mapping_File_Names
5593 (No_Project, Last_Mapping_File_Names (No_Project)));
5594 if FD = Invalid_FD then
5595 Make_Failed ("disk full
");
5601 Make_Failed ("disk full
");
5605 -- And return the index of the newly created file
5607 File_Index := Last_Mapping_File_Names (Project);
5608 end Init_Mapping_File;
5616 First_Q_Initialization := False;
5618 Q.Set_Last (Q.First);
5625 procedure Initialize is
5627 -- Override default initialization of Check_Object_Consistency
5628 -- since this is normally False for GNATBIND, but is True for
5629 -- GNATMAKE since we do not need to check source consistency
5630 -- again once GNATMAKE has looked at the sources to check.
5632 Check_Object_Consistency := True;
5634 -- Package initializations. The order of calls is important here.
5636 Output.Set_Standard_Error;
5639 Binder_Switches.Init;
5640 Linker_Switches.Init;
5651 RTS_Specified := null;
5655 -- Add the directory where gnatmake is invoked in front of the
5656 -- path, if gnatmake is invoked with directory information.
5657 -- Only do this if the platform is not VMS, where the notion of path
5658 -- does not really exist.
5662 Command : constant String := Command_Name;
5665 for Index in reverse Command'Range loop
5666 if Command (Index) = Directory_Separator then
5668 Absolute_Dir : constant String :=
5670 (Command (Command'First .. Index));
5672 PATH : constant String :=
5675 Getenv ("PATH
").all;
5678 Setenv ("PATH
", PATH);
5687 -- Scan the switches and arguments
5689 Scan_Args : for Next_Arg in 1 .. Argument_Count loop
5690 Scan_Make_Arg (Argument (Next_Arg), And_Save => True);
5693 if Usage_Requested then
5697 -- Test for trailing -P switch
5699 if Project_File_Name_Present and then Project_File_Name = null then
5700 Make_Failed ("project file name missing after
-P
");
5702 -- Test for trailing -o switch
5704 elsif Output_File_Name_Present
5705 and then not Output_File_Name_Seen
5707 Make_Failed ("output file name missing after
-o
");
5709 -- Test for trailing -D switch
5711 elsif Object_Directory_Present
5712 and then not Object_Directory_Seen then
5713 Make_Failed ("object directory missing after
-D
");
5716 -- Test for simultaneity of -i and -D
5718 if Object_Directory_Path /= null and then In_Place_Mode then
5719 Make_Failed ("-i
and -D cannot be used simutaneously
");
5722 -- Deal with -C= switch
5724 if Gnatmake_Mapping_File /= null then
5725 -- First, check compatibility with other switches
5727 if Project_File_Name /= null then
5728 Make_Failed ("-C
= switch
is not compatible
with -P switch
");
5730 elsif Saved_Maximum_Processes > 1 then
5731 Make_Failed ("-C
= switch
is not compatible
with -jnnn switch
");
5734 Fmap.Initialize (Gnatmake_Mapping_File.all);
5736 ("-gnatem
=" & Gnatmake_Mapping_File.all,
5741 if Project_File_Name /= null then
5743 -- A project file was specified by a -P switch
5745 if Verbose_Mode then
5747 Write_Str ("Parsing Project File
""");
5748 Write_Str (Project_File_Name.all);
5753 -- Avoid looking in the current directory for ALI files
5755 -- Look_In_Primary_Dir := False;
5757 -- Set the project parsing verbosity to whatever was specified
5758 -- by a possible -vP switch.
5760 Prj.Pars.Set_Verbosity (To => Current_Verbosity);
5762 -- Parse the project file.
5763 -- If there is an error, Main_Project will still be No_Project.
5766 (Project => Main_Project,
5767 Project_File_Name => Project_File_Name.all,
5768 Packages_To_Check => Packages_To_Check_By_Gnatmake);
5770 if Main_Project = No_Project then
5771 Make_Failed ("""", Project_File_Name.all, """ processing failed
");
5774 if Verbose_Mode then
5776 Write_Str ("Parsing
of Project File
""");
5777 Write_Str (Project_File_Name.all);
5778 Write_Str (""" is finished
.");
5782 -- We add the source directories and the object directories
5783 -- to the search paths.
5785 Add_Source_Directories (Main_Project);
5786 Add_Object_Directories (Main_Project);
5788 -- Compute depth of each project
5790 for Proj in 1 .. Projects.Last loop
5791 Projects.Table (Proj).Seen := False;
5792 Projects.Table (Proj).Depth := 0;
5795 Recursive_Compute_Depth
5796 (Main_Project, Depth => 1);
5800 Osint.Add_Default_Search_Dirs;
5802 -- Source file lookups should be cached for efficiency.
5803 -- Source files are not supposed to change. However, we do that now
5804 -- only if no project file is used; if a project file is used, we
5805 -- do it just after changing the directory to the object directory.
5807 Osint.Source_File_Data (Cache => True);
5809 -- Read gnat.adc file to initialize Fname.UF
5811 Fname.UF.Initialize;
5814 Fname.SF.Read_Source_File_Name_Pragmas;
5817 when Err : SFN_Scan.Syntax_Error_In_GNAT_ADC =>
5818 Make_Failed (Exception_Message (Err));
5822 -- Make sure no project object directory is recorded
5824 Project_Object_Directory := No_Project;
5828 ----------------------------
5829 -- Insert_Project_Sources --
5830 ----------------------------
5832 procedure Insert_Project_Sources
5833 (The_Project : Project_Id;
5834 All_Projects : Boolean;
5837 Put_In_Q : Boolean := Into_Q;
5838 Unit : Com.Unit_Data;
5841 Extending : constant Boolean :=
5842 Projects.Table (The_Project).Extends /= No_Project;
5844 function Check_Project (P : Project_Id) return Boolean;
5845 -- Returns True if P is The_Project or a project extended by
5852 function Check_Project (P : Project_Id) return Boolean is
5854 if All_Projects or P = The_Project then
5856 elsif Extending then
5858 Data : Project_Data := Projects.Table (The_Project);
5862 if P = Data.Extends then
5866 Data := Projects.Table (Data.Extends);
5867 exit when Data.Extends = No_Project;
5875 -- Start of processing of Insert_Project_Sources
5878 -- For all the sources in the project files,
5880 for Id in Com.Units.First .. Com.Units.Last loop
5881 Unit := Com.Units.Table (Id);
5884 -- If there is a source for the body, and the body has not been
5887 if Unit.File_Names (Com.Body_Part).Name /= No_Name
5888 and then Unit.File_Names (Com.Body_Part).Path /= Slash
5891 -- And it is a source for the specified project
5893 if Check_Project (Unit.File_Names (Com.Body_Part).Project) then
5895 -- If we don't have a spec, we cannot consider the source
5896 -- if it is a subunit
5898 if Unit.File_Names (Com.Specification).Name = No_Name then
5900 Src_Ind : Source_File_Index;
5902 -- Here we are cheating a little bit: we don't want to
5903 -- use Sinput.L, because it depends on the GNAT tree
5904 -- (Atree, Sinfo, ...). So, we pretend that it is
5905 -- a project file, and we use Sinput.P.
5906 -- Source_File_Is_Subunit is just scanning through
5907 -- the file until it finds one of the reserved words
5908 -- separate, procedure, function, generic or package.
5909 -- Fortunately, these Ada reserved words are also
5910 -- reserved for project files.
5913 Src_Ind := Sinput.P.Load_Project_File
5915 (Unit.File_Names (Com.Body_Part).Path));
5917 -- If it is a subunit, discard it
5919 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
5923 Sfile := Unit.File_Names (Com.Body_Part).Name;
5928 Sfile := Unit.File_Names (Com.Body_Part).Name;
5932 elsif Unit.File_Names (Com.Specification).Name /= No_Name
5933 and then Unit.File_Names (Com.Specification).Path /= Slash
5934 and then Check_Project (Unit.File_Names (Com.Specification).Project)
5936 -- If there is no source for the body, but there is a source
5937 -- for the spec which has not been locally removed, then we take
5940 Sfile := Unit.File_Names (Com.Specification).Name;
5943 -- If Put_In_Q is True, we insert into the Q
5947 -- For the first source inserted into the Q, we need
5948 -- to initialize the Q, but not for the subsequent sources.
5950 if First_Q_Initialization then
5954 -- And of course, we only insert in the Q if the source
5957 if Sfile /= No_Name and then not Is_Marked (Sfile) then
5958 if Verbose_Mode then
5959 Write_Str ("Adding
""");
5960 Write_Str (Get_Name_String (Sfile));
5961 Write_Line (""" to the queue
");
5968 elsif Sfile /= No_Name then
5970 -- If Put_In_Q is False, we add the source as it it were
5971 -- specified on the command line, and we set Put_In_Q to True,
5972 -- so that the following sources will be put directly in the
5973 -- queue. This will allow parallel compilation processes if -jx
5976 if Verbose_Mode then
5977 Write_Str ("Adding
""");
5978 Write_Str (Get_Name_String (Sfile));
5979 Write_Line (""" as
if on the command line
");
5982 Osint.Add_File (Get_Name_String (Sfile));
5986 end Insert_Project_Sources;
5993 (Source_File : File_Name_Type;
5994 Source_Unit : Unit_Name_Type := No_Name;
5998 if Debug.Debug_Flag_Q then
5999 Write_Str (" Q
:= Q
+ [ ");
6000 Write_Name (Source_File);
6012 (File => Source_File,
6013 Unit => Source_Unit,
6018 ---------------------
6019 -- Is_In_Obsoleted --
6020 ---------------------
6022 function Is_In_Obsoleted (F : Name_Id) return Boolean is
6029 Name : constant String := Get_Name_String (F);
6030 First : Natural := Name'Last;
6034 while First > Name'First
6035 and then Name (First - 1) /= Directory_Separator
6036 and then Name (First - 1) /= '/'
6041 if First /= Name'First then
6043 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
6047 return Obsoleted.Get (F2);
6050 end Is_In_Obsoleted;
6052 ----------------------------
6053 -- Is_In_Object_Directory --
6054 ----------------------------
6056 function Is_In_Object_Directory
6057 (Source_File : File_Name_Type;
6058 Full_Lib_File : File_Name_Type) return Boolean
6061 -- There is something to check only when using project files.
6062 -- Otherwise, this function returns True (last line of the function).
6064 if Main_Project /= No_Project then
6066 Source_File_Name : constant String :=
6067 Get_Name_String (Source_File);
6068 Saved_Verbosity : constant Verbosity := Prj.Com.Current_Verbosity;
6069 Project : Project_Id := No_Project;
6070 Path_Name : Name_Id := No_Name;
6071 Data : Project_Data;
6074 -- Call Get_Reference to know the ultimate extending project of
6075 -- the source. Call it with verbosity default to avoid verbose
6078 Prj.Com.Current_Verbosity := Default;
6081 (Source_File_Name => Source_File_Name,
6084 Prj.Com.Current_Verbosity := Saved_Verbosity;
6086 -- If this source is in a project, check that the ALI file is
6087 -- in its object directory. If it is not, return False, so that
6088 -- the ALI file will not be skipped.
6090 -- If the source is not in an extending project, we fall back to
6091 -- the general case and return True at the end of the function.
6093 if Project /= No_Project
6094 and then Projects.Table (Project).Extends /= No_Project
6096 Data := Projects.Table (Project);
6099 Object_Directory : constant String :=
6102 (Data.Object_Directory));
6104 Olast : Natural := Object_Directory'Last;
6106 Lib_File_Directory : constant String :=
6107 Normalize_Pathname (Dir_Name
6108 (Get_Name_String (Full_Lib_File)));
6110 Llast : Natural := Lib_File_Directory'Last;
6113 -- For directories, Normalize_Pathname may or may not put
6114 -- a directory separator at the end, depending on its input.
6115 -- Remove any last directory separator before comparaison.
6116 -- Returns True only if the two directories are the same.
6118 if Object_Directory (Olast) = Directory_Separator then
6122 if Lib_File_Directory (Llast) = Directory_Separator then
6126 return Object_Directory (Object_Directory'First .. Olast) =
6127 Lib_File_Directory (Lib_File_Directory'First .. Llast);
6133 -- When the source is not in a project file, always return True
6136 end Is_In_Object_Directory;
6142 procedure Link (ALI_File : File_Name_Type; Args : Argument_List) is
6143 Link_Args : Argument_List (1 .. Args'Length + 1);
6147 Get_Name_String (ALI_File);
6148 Link_Args (1) := new String'(Name_Buffer (1 .. Name_Len));
6150 Link_Args (2 .. Args'Length + 1) := Args;
6152 GNAT.OS_Lib.Normalize_Arguments (Link_Args);
6154 Display (Gnatlink.all, Link_Args);
6156 if Gnatlink_Path = null then
6157 Make_Failed ("error
, unable to locate
", Gnatlink.all);
6160 GNAT.OS_Lib.Spawn (Gnatlink_Path.all, Link_Args, Success);
6167 ---------------------------
6168 -- List_Bad_Compilations --
6169 ---------------------------
6171 procedure List_Bad_Compilations is
6173 for J in Bad_Compilation.First .. Bad_Compilation.Last loop
6174 if Bad_Compilation.Table (J).File = No_File then
6176 elsif not Bad_Compilation.Table (J).Found then
6177 Inform (Bad_Compilation.Table (J).File, "not found
");
6179 Inform (Bad_Compilation.Table (J).File, "compilation error
");
6182 end List_Bad_Compilations;
6188 procedure List_Depend is
6195 Line_Size : constant := 77;
6198 Set_Standard_Output;
6200 for A in ALIs.First .. ALIs.Last loop
6201 Lib_Name := ALIs.Table (A).Afile;
6203 -- We have to provide the full library file name in In_Place_Mode
6205 if In_Place_Mode then
6206 Lib_Name := Full_Lib_File_Name (Lib_Name);
6209 Obj_Name := Object_File_Name (Lib_Name);
6210 Write_Name (Obj_Name);
6213 Get_Name_String (Obj_Name);
6215 Line_Pos := Len + 2;
6217 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
6218 Src_Name := Sdep.Table (D).Sfile;
6220 if Is_Internal_File_Name (Src_Name)
6221 and then not Check_Readonly_Files
6225 if not Quiet_Output then
6226 Src_Name := Full_Source_Name (Src_Name);
6229 Get_Name_String (Src_Name);
6232 if Line_Pos + Len + 1 > Line_Size then
6238 Line_Pos
:= Line_Pos
+ Len
+ 1;
6241 Write_Name
(Src_Name
);
6255 procedure Make_Failed
(S1
: String; S2
: String := ""; S3
: String := "") is
6257 Delete_All_Temp_Files
;
6258 Osint
.Fail
(S1
, S2
, S3
);
6261 --------------------
6262 -- Mark_Directory --
6263 --------------------
6265 procedure Mark_Directory
6267 Mark
: Lib_Mark_Type
)
6273 -- Dir last character is supposed to be a directory separator.
6275 Name_Len
:= Dir
'Length;
6276 Name_Buffer
(1 .. Name_Len
) := Dir
;
6278 if not Is_Directory_Separator
(Name_Buffer
(Name_Len
)) then
6279 Name_Len
:= Name_Len
+ 1;
6280 Name_Buffer
(Name_Len
) := Directory_Separator
;
6283 -- Add flags to the already existing flags
6286 B
:= Get_Name_Table_Byte
(N
);
6287 Set_Name_Table_Byte
(N
, B
or Mark
);
6290 -----------------------------
6291 -- Recursive_Compute_Depth --
6292 -----------------------------
6294 procedure Recursive_Compute_Depth
6295 (Project
: Project_Id
;
6298 List
: Project_List
;
6302 -- Nothing to do if there is no project or if the project has already
6303 -- been seen or if the depth is large enough.
6305 if Project
= No_Project
6306 or else Projects
.Table
(Project
).Seen
6307 or else Projects
.Table
(Project
).Depth
>= Depth
6312 Projects
.Table
(Project
).Depth
:= Depth
;
6314 -- Mark the project as Seen to avoid endless loop caused by limited
6317 Projects
.Table
(Project
).Seen
:= True;
6319 List
:= Projects
.Table
(Project
).Imported_Projects
;
6321 -- Visit each imported project
6323 while List
/= Empty_Project_List
loop
6324 Proj
:= Project_Lists
.Table
(List
).Project
;
6325 List
:= Project_Lists
.Table
(List
).Next
;
6326 Recursive_Compute_Depth
6328 Depth
=> Depth
+ 1);
6331 -- Visit a project being extended, if any
6333 Recursive_Compute_Depth
6334 (Project
=> Projects
.Table
(Project
).Extends
,
6335 Depth
=> Depth
+ 1);
6337 -- Reset the Seen flag, as we leave this project
6339 Projects
.Table
(Project
).Seen
:= False;
6340 end Recursive_Compute_Depth
;
6342 -----------------------
6343 -- Sigint_Intercpted --
6344 -----------------------
6346 procedure Sigint_Intercepted
is
6348 Write_Line
("*** Interrupted ***");
6349 Delete_All_Temp_Files
;
6351 end Sigint_Intercepted
;
6357 procedure Scan_Make_Arg
(Argv
: String; And_Save
: Boolean) is
6359 pragma Assert
(Argv
'First = 1);
6361 if Argv
'Length = 0 then
6365 -- If the previous switch has set the Project_File_Name_Present
6366 -- flag (that is we have seen a -P alone), then the next argument is
6367 -- the name of the project file.
6369 if Project_File_Name_Present
and then Project_File_Name
= null then
6370 if Argv
(1) = '-' then
6371 Make_Failed
("project file name missing after -P");
6374 Project_File_Name_Present
:= False;
6375 Project_File_Name
:= new String'(Argv);
6378 -- If the previous switch has set the Output_File_Name_Present
6379 -- flag (that is we have seen a -o), then the next argument is
6380 -- the name of the output executable.
6382 elsif Output_File_Name_Present
6383 and then not Output_File_Name_Seen
6385 Output_File_Name_Seen := True;
6387 if Argv (1) = '-' then
6388 Make_Failed ("output file name missing after -o");
6391 Add_Switch ("-o", Linker, And_Save => And_Save);
6393 -- Automatically add the executable suffix if it has not been
6394 -- specified explicitly.
6397 Canonical_Argv : String := Argv;
6399 -- Get the file name in canonical case to accept as is
6400 -- names ending with ".EXE" on VMS and Windows.
6402 Canonical_Case_File_Name (Canonical_Argv);
6404 if Executable_Suffix'Length /= 0
6405 and then (Canonical_Argv'Length <= Executable_Suffix'Length
6406 or else Canonical_Argv
6407 (Canonical_Argv'Last -
6408 Executable_Suffix'Length + 1
6409 .. Canonical_Argv'Last)
6410 /= Executable_Suffix)
6413 (Argv & Executable_Suffix,
6415 And_Save => And_Save);
6417 Add_Switch (Argv, Linker, And_Save => And_Save);
6422 -- If the previous switch has set the Object_Directory_Present flag
6423 -- (that is we have seen a -D), then the next argument is
6424 -- the path name of the object directory..
6426 elsif Object_Directory_Present
6427 and then not Object_Directory_Seen
6429 Object_Directory_Seen := True;
6431 if Argv (1) = '-' then
6432 Make_Failed ("object directory path name missing after -D");
6434 elsif not Is_Directory (Argv) then
6435 Make_Failed ("cannot find object directory """, Argv, """");
6438 Add_Lib_Search_Dir (Argv);
6440 -- Specify the object directory to the binder
6442 Add_Switch ("-aO" & Argv, Binder, And_Save => And_Save);
6444 -- Record the object directory. Make sure it ends with a directory
6447 if Argv (Argv'Last) = Directory_Separator then
6448 Object_Directory_Path := new String'(Argv
);
6451 Object_Directory_Path
:=
6452 new String'(Argv & Directory_Separator);
6456 -- Then check if we are dealing with -cargs/-bargs/-largs/-margs
6458 elsif Argv = "-bargs"
6467 when 'c
' => Program_Args := Compiler;
6468 when 'b
' => Program_Args := Binder;
6469 when 'l
' => Program_Args := Linker;
6470 when 'm
' => Program_Args := None;
6473 raise Program_Error;
6476 -- A special test is needed for the -o switch within a -largs
6477 -- since that is another way to specify the name of the final
6480 elsif Program_Args = Linker
6481 and then Argv = "-o"
6483 Make_Failed ("switch -o not allowed within a -largs. " &
6484 "Use -o directly.");
6486 -- Check to see if we are reading switches after a -cargs,
6487 -- -bargs or -largs switch. If yes save it.
6489 elsif Program_Args /= None then
6491 -- Check to see if we are reading -I switches in order
6492 -- to take into account in the src & lib search directories.
6494 if Argv'Length > 2 and then Argv (1 .. 2) = "-I" then
6495 if Argv (3 .. Argv'Last) = "-" then
6496 Look_In_Primary_Dir := False;
6498 elsif Program_Args = Compiler then
6499 if Argv (3 .. Argv'Last) /= "-" then
6500 Add_Src_Search_Dir (Argv (3 .. Argv'Last));
6503 elsif Program_Args = Binder then
6504 Add_Lib_Search_Dir (Argv (3 .. Argv'Last));
6508 Add_Switch (Argv, Program_Args, And_Save => And_Save);
6510 -- Handle non-default compiler, binder, linker, and handle --RTS switch
6512 elsif Argv'Length > 2 and then Argv (1 .. 2) = "--" then
6514 and then Argv (1 .. 6) = "--GCC="
6517 Program_Args : constant Argument_List_Access :=
6518 Argument_String_To_List
6519 (Argv (7 .. Argv'Last));
6523 Saved_Gcc := new String'(Program_Args
.all (1).all);
6525 Gcc
:= new String'(Program_Args.all (1).all);
6528 for J in 2 .. Program_Args.all'Last loop
6530 (Program_Args.all (J).all,
6532 And_Save => And_Save);
6536 elsif Argv'Length > 11
6537 and then Argv (1 .. 11) = "--GNATBIND="
6540 Program_Args : constant Argument_List_Access :=
6541 Argument_String_To_List
6542 (Argv (12 .. Argv'Last));
6546 Saved_Gnatbind := new String'(Program_Args
.all (1).all);
6548 Gnatbind
:= new String'(Program_Args.all (1).all);
6551 for J in 2 .. Program_Args.all'Last loop
6553 (Program_Args.all (J).all, Binder, And_Save => And_Save);
6557 elsif Argv'Length > 11
6558 and then Argv (1 .. 11) = "--GNATLINK="
6561 Program_Args : constant Argument_List_Access :=
6562 Argument_String_To_List
6563 (Argv (12 .. Argv'Last));
6566 Saved_Gnatlink := new String'(Program_Args
.all (1).all);
6568 Gnatlink
:= new String'(Program_Args.all (1).all);
6571 for J in 2 .. Program_Args.all'Last loop
6572 Add_Switch (Program_Args.all (J).all, Linker);
6576 elsif Argv'Length >= 5 and then
6577 Argv (1 .. 5) = "--RTS"
6579 Add_Switch (Argv, Compiler, And_Save => And_Save);
6580 Add_Switch (Argv, Binder, And_Save => And_Save);
6582 if Argv'Length <= 6 or else Argv (6) /= '=' then
6583 Make_Failed ("missing path for --RTS");
6586 -- Check that this is the first time we see this switch or
6587 -- if it is not the first time, the same path is specified.
6589 if RTS_Specified = null then
6590 RTS_Specified := new String'(Argv
(7 .. Argv
'Last));
6592 elsif RTS_Specified
.all /= Argv
(7 .. Argv
'Last) then
6593 Make_Failed
("--RTS cannot be specified multiple times");
6596 -- Valid --RTS switch
6603 Src_Path_Name
: constant String_Ptr
:=
6605 (Argv
(7 .. Argv
'Last), Include
);
6607 Lib_Path_Name
: constant String_Ptr
:=
6609 (Argv
(7 .. Argv
'Last), Objects
);
6612 if Src_Path_Name
/= null and then
6613 Lib_Path_Name
/= null
6615 -- Set the RTS_*_Path_Name variables, so that the correct
6616 -- directories will be set when
6617 -- Osint.Add_Default_Search_Dirs will be called later.
6619 RTS_Src_Path_Name
:= Src_Path_Name
;
6620 RTS_Lib_Path_Name
:= Lib_Path_Name
;
6622 elsif Src_Path_Name
= null
6623 and Lib_Path_Name
= null then
6624 Make_Failed
("RTS path not valid: missing " &
6625 "adainclude and adalib directories");
6627 elsif Src_Path_Name
= null then
6628 Make_Failed
("RTS path not valid: missing adainclude " &
6631 elsif Lib_Path_Name
= null then
6632 Make_Failed
("RTS path not valid: missing adalib " &
6639 Make_Failed
("unknown switch: ", Argv
);
6642 -- If we have seen a regular switch process it
6644 elsif Argv
(1) = '-' then
6646 if Argv
'Length = 1 then
6647 Make_Failed
("switch character cannot be followed by a blank");
6651 elsif Argv
(2 .. Argv
'Last) = "I-" then
6652 Look_In_Primary_Dir
:= False;
6654 -- Forbid -?- or -??- where ? is any character
6656 elsif (Argv
'Length = 3 and then Argv
(3) = '-')
6657 or else (Argv
'Length = 4 and then Argv
(4) = '-')
6659 Make_Failed
("trailing ""-"" at the end of ", Argv
, " forbidden.");
6663 elsif Argv
(2) = 'I' then
6664 Add_Src_Search_Dir
(Argv
(3 .. Argv
'Last));
6665 Add_Lib_Search_Dir
(Argv
(3 .. Argv
'Last));
6666 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
6667 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
6669 -- -aIdir (to gcc this is like a -I switch)
6671 elsif Argv
'Length >= 3 and then Argv
(2 .. 3) = "aI" then
6672 Add_Src_Search_Dir
(Argv
(4 .. Argv
'Last));
6673 Add_Switch
("-I" & Argv
(4 .. Argv
'Last),
6675 And_Save
=> And_Save
);
6676 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
6680 elsif Argv
'Length >= 3 and then Argv
(2 .. 3) = "aO" then
6681 Add_Lib_Search_Dir
(Argv
(4 .. Argv
'Last));
6682 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
6684 -- -aLdir (to gnatbind this is like a -aO switch)
6686 elsif Argv
'Length >= 3 and then Argv
(2 .. 3) = "aL" then
6687 Mark_Directory
(Argv
(4 .. Argv
'Last), Ada_Lib_Dir
);
6688 Add_Lib_Search_Dir
(Argv
(4 .. Argv
'Last));
6689 Add_Switch
("-aO" & Argv
(4 .. Argv
'Last),
6691 And_Save
=> And_Save
);
6693 -- -Adir (to gnatbind this is like a -aO switch, to gcc like a -I)
6695 elsif Argv
(2) = 'A' then
6696 Mark_Directory
(Argv
(3 .. Argv
'Last), Ada_Lib_Dir
);
6697 Add_Src_Search_Dir
(Argv
(3 .. Argv
'Last));
6698 Add_Lib_Search_Dir
(Argv
(3 .. Argv
'Last));
6699 Add_Switch
("-I" & Argv
(3 .. Argv
'Last),
6701 And_Save
=> And_Save
);
6702 Add_Switch
("-aO" & Argv
(3 .. Argv
'Last),
6704 And_Save
=> And_Save
);
6708 elsif Argv
(2) = 'L' then
6709 Add_Switch
(Argv
, Linker
, And_Save
=> And_Save
);
6711 -- For -gxxxxx, -pg, -mxxx, -fxxx: give the switch to both the
6712 -- compiler and the linker (except for -gnatxxx which is only for
6713 -- the compiler). Some of the -mxxx (for example -m64) and -fxxx
6714 -- (for example -ftest-coverage for gcov) need to be used when
6715 -- compiling the binder generated files, and using all these gcc
6716 -- switches for the binder generated files should not be a problem.
6719 (Argv
(2) = 'g' and then (Argv
'Last < 5
6720 or else Argv
(2 .. 5) /= "gnat"))
6721 or else Argv
(2 .. Argv
'Last) = "pg"
6722 or else (Argv
(2) = 'm' and then Argv
'Last > 2)
6723 or else (Argv
(2) = 'f' and then Argv
'Last > 2)
6725 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
6726 Add_Switch
(Argv
, Linker
, And_Save
=> And_Save
);
6728 -- -C=<mapping file>
6730 elsif Argv
'Last > 2 and then Argv
(2) = 'C' then
6732 if Argv
(3) /= '=' or else Argv
'Last <= 3 then
6733 Make_Failed
("illegal switch ", Argv
);
6736 Gnatmake_Mapping_File
:= new String'(Argv (4 .. Argv'Last));
6741 elsif Argv'Last = 2 and then Argv (2) = 'D
' then
6742 if Project_File_Name /= null then
6743 Make_Failed ("-D cannot be used in conjunction with a " &
6747 Scan_Make_Switches (Argv);
6752 elsif Argv (2) = 'd
'
6753 and then Argv'Last = 2
6755 Display_Compilation_Progress := True;
6759 elsif Argv'Last = 2 and then Argv (2) = 'i
' then
6760 if Project_File_Name /= null then
6761 Make_Failed ("-i cannot be used in conjunction with a " &
6765 Scan_Make_Switches (Argv);
6768 -- -j (need to save the result)
6770 elsif Argv (2) = 'j
' then
6771 Scan_Make_Switches (Argv);
6774 Saved_Maximum_Processes := Maximum_Processes;
6779 elsif Argv (2) = 'm
'
6780 and then Argv'Last = 2
6782 Minimal_Recompilation := True;
6786 elsif Argv (2) = 'u
'
6787 and then Argv'Last = 2
6789 Unique_Compile := True;
6790 Compile_Only := True;
6791 Do_Bind_Step := False;
6792 Do_Link_Step := False;
6796 elsif Argv (2) = 'U
'
6797 and then Argv'Last = 2
6799 Unique_Compile_All_Projects := True;
6800 Unique_Compile := True;
6801 Compile_Only := True;
6802 Do_Bind_Step := False;
6803 Do_Link_Step := False;
6805 -- -Pprj or -P prj (only once, and only on the command line)
6807 elsif Argv (2) = 'P
' then
6808 if Project_File_Name /= null then
6809 Make_Failed ("cannot have several project files specified");
6811 elsif Object_Directory_Path /= null then
6812 Make_Failed ("-D cannot be used in conjunction with a " &
6815 elsif In_Place_Mode then
6816 Make_Failed ("-i cannot be used in conjunction with a " &
6819 elsif not And_Save then
6821 -- It could be a tool other than gnatmake (i.e, gnatdist)
6822 -- or a -P switch inside a project file.
6825 ("either the tool is not ""project-aware"" or " &
6826 "a project file is specified inside a project file");
6828 elsif Argv'Last = 2 then
6830 -- -P is used alone: the project file name is the next option
6832 Project_File_Name_Present := True;
6835 Project_File_Name := new String'(Argv
(3 .. Argv
'Last));
6838 -- -vPx (verbosity of the parsing of the project files)
6841 and then Argv
(2 .. 3) = "vP"
6842 and then Argv
(4) in '0' .. '2'
6847 Current_Verbosity
:= Prj
.Default
;
6849 Current_Verbosity
:= Prj
.Medium
;
6851 Current_Verbosity
:= Prj
.High
;
6857 -- -Xext=val (External assignment)
6859 elsif Argv
(2) = 'X'
6860 and then Is_External_Assignment
(Argv
)
6862 -- Is_External_Assignment has side effects
6863 -- when it returns True;
6867 -- If -gnath is present, then generate the usage information
6868 -- right now and do not pass this option on to the compiler calls.
6870 elsif Argv
= "-gnath" then
6873 -- If -gnatc is specified, make sure the bind step and the link
6874 -- step are not executed.
6876 elsif Argv
'Length >= 6 and then Argv
(2 .. 6) = "gnatc" then
6878 -- If -gnatc is specified, make sure the bind step and the link
6879 -- step are not executed.
6881 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
6882 Operating_Mode
:= Check_Semantics
;
6883 Check_Object_Consistency
:= False;
6884 Compile_Only
:= True;
6885 Do_Bind_Step
:= False;
6886 Do_Link_Step
:= False;
6888 elsif Argv
(2 .. Argv
'Last) = "nostdlib" then
6890 -- Don't pass -nostdlib to gnatlink, it will disable
6891 -- linking with all standard library files.
6895 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
6896 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
6898 elsif Argv
(2 .. Argv
'Last) = "nostdinc" then
6900 -- Pass -nostdinc to the Compiler and to gnatbind
6903 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
6904 Add_Switch
(Argv
, Binder
, And_Save
=> And_Save
);
6906 -- By default all switches with more than one character
6907 -- or one character switches which are not in 'a' .. 'z'
6908 -- (except 'C', 'F', 'M' and 'B') are passed to the compiler,
6909 -- unless we are dealing with a debug switch (starts with 'd')
6910 -- or an extended gnatmake switch (starts with 'e').
6912 elsif Argv
(2) /= 'd'
6913 and then Argv
(2) /= 'e'
6914 and then Argv
(2 .. Argv
'Last) /= "C"
6915 and then Argv
(2 .. Argv
'Last) /= "F"
6916 and then Argv
(2 .. Argv
'Last) /= "M"
6917 and then Argv
(2 .. Argv
'Last) /= "B"
6918 and then (Argv
'Length > 2 or else Argv
(2) not in 'a' .. 'z')
6920 Add_Switch
(Argv
, Compiler
, And_Save
=> And_Save
);
6922 -- All other options are handled by Scan_Make_Switches
6925 Scan_Make_Switches
(Argv
);
6928 -- If not a switch it must be a file name
6932 Mains
.Add_Main
(Argv
);
6940 function Switches_Of
6941 (Source_File
: Name_Id
;
6942 Source_File_Name
: String;
6944 Naming
: Naming_Data
;
6945 In_Package
: Package_Id
;
6946 Allow_ALI
: Boolean) return Variable_Value
6948 Switches
: Variable_Value
;
6950 Defaults
: constant Array_Element_Id
:=
6952 (Name
=> Name_Default_Switches
,
6954 Packages
.Table
(In_Package
).Decl
.Arrays
);
6956 Switches_Array
: constant Array_Element_Id
:=
6958 (Name
=> Name_Switches
,
6960 Packages
.Table
(In_Package
).Decl
.Arrays
);
6965 (Index
=> Source_File
,
6966 Src_Index
=> Source_Index
,
6967 In_Array
=> Switches_Array
);
6969 if Switches
= Nil_Variable_Value
then
6971 Name
: String (1 .. Source_File_Name
'Length + 3);
6972 Last
: Positive := Source_File_Name
'Length;
6973 Spec_Suffix
: constant String :=
6974 Get_Name_String
(Naming
.Current_Spec_Suffix
);
6975 Body_Suffix
: constant String :=
6976 Get_Name_String
(Naming
.Current_Body_Suffix
);
6977 Truncated
: Boolean := False;
6980 Name
(1 .. Last
) := Source_File_Name
;
6982 if Last
> Body_Suffix
'Length
6983 and then Name
(Last
- Body_Suffix
'Length + 1 .. Last
) =
6987 Last
:= Last
- Body_Suffix
'Length;
6991 and then Last
> Spec_Suffix
'Length
6992 and then Name
(Last
- Spec_Suffix
'Length + 1 .. Last
) =
6996 Last
:= Last
- Spec_Suffix
'Length;
7001 Name_Buffer
(1 .. Name_Len
) := Name
(1 .. Last
);
7004 (Index
=> Name_Find
,
7006 In_Array
=> Switches_Array
);
7008 if Switches
= Nil_Variable_Value
7011 Last
:= Source_File_Name
'Length;
7013 while Name
(Last
) /= '.' loop
7017 Name
(Last
+ 1 .. Last
+ 3) := "ali";
7018 Name_Len
:= Last
+ 3;
7019 Name_Buffer
(1 .. Name_Len
) := Name
(1 .. Name_Len
);
7022 (Index
=> Name_Find
,
7024 In_Array
=> Switches_Array
);
7030 if Switches
= Nil_Variable_Value
then
7035 In_Array
=> Defaults
);
7047 if Usage_Needed
then
7048 Usage_Needed
:= False;
7057 procedure Verbose_Msg
7060 N2
: Name_Id
:= No_Name
;
7062 Prefix
: String := " -> ")
7065 if not Verbose_Mode
then
7075 if N2
/= No_Name
then
7086 -- Make sure that in case of failure, the temp files will be deleted
7088 Prj
.Com
.Fail
:= Make_Failed
'Access;
7089 MLib
.Fail
:= Make_Failed
'Access;
7090 Makeutl
.Do_Fail
:= Make_Failed
'Access;