1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
27 with ALI.Util; use ALI.Util;
32 with Fname; use Fname;
33 with Fname.SF; use Fname.SF;
34 with Fname.UF; use Fname.UF;
35 with Gnatvsn; use Gnatvsn;
36 with Hostparm; use Hostparm;
38 with Makeutl; use Makeutl;
41 with MLib.Tgt; use MLib.Tgt;
43 with Namet; use Namet;
45 with Osint.M; use Osint.M;
46 with Osint; use Osint;
47 with Output; use Output;
55 with Snames; use Snames;
56 with Switch; use Switch;
57 with Switch.M; use Switch.M;
58 with Targparm; use Targparm;
61 with Types; use Types;
63 with Ada.Exceptions; use Ada.Exceptions;
64 with Ada.Command_Line; use Ada.Command_Line;
66 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
67 with GNAT.Case_Util; use GNAT.Case_Util;
68 with GNAT.OS_Lib; use GNAT.OS_Lib;
75 -- Make control characters visible
77 Standard_Library_Package_Body_Name : constant String := "s-stalib.adb";
78 -- Every program depends on this package, that must then be checked,
79 -- especially when -f and -a are used.
81 procedure Kill (Pid : Process_Id; Sig_Num : Integer; Close : Integer);
82 pragma Import (C, Kill, "__gnat_kill");
83 -- Called by Sigint_Intercepted to kill all spawned compilation processes
85 type Sigint_Handler is access procedure;
86 pragma Convention (C, Sigint_Handler);
88 procedure Install_Int_Handler (Handler : Sigint_Handler);
89 pragma Import (C, Install_Int_Handler, "__gnat_install_int_handler");
90 -- Called by Gnatmake to install the SIGINT handler below
92 procedure Sigint_Intercepted;
93 pragma Convention (C, Sigint_Intercepted);
94 -- Called when the program is interrupted by Ctrl-C to delete the
95 -- temporary mapping files and configuration pragmas files.
97 No_Mapping_File : constant Natural := 0;
99 type Compilation_Data is record
101 Full_Source_File : File_Name_Type;
102 Lib_File : File_Name_Type;
103 Source_Unit : Unit_Name_Type;
104 Mapping_File : Natural := No_Mapping_File;
105 Project : Project_Id := No_Project;
106 Syntax_Only : Boolean := False;
107 Output_Is_Object : Boolean := True;
109 -- Data recorded for each compilation process spawned
111 type Comp_Data_Arr is array (Positive range <>) of Compilation_Data;
112 type Comp_Data_Ptr is access Comp_Data_Arr;
113 Running_Compile : Comp_Data_Ptr;
114 -- Used to save information about outstanding compilations
116 Outstanding_Compiles : Natural := 0;
117 -- Current number of outstanding compiles
119 -------------------------
120 -- Note on terminology --
121 -------------------------
123 -- In this program, we use the phrase "termination" of a file name to refer
124 -- to the suffix that appears after the unit name portion. Very often this
125 -- is simply the extension, but in some cases, the sequence may be more
126 -- complex, for example in main.1.ada, the termination in this name is
127 -- ".1.ada" and in main_.ada the termination is "_.ada".
129 -------------------------------------
130 -- Queue (Q) Manipulation Routines --
131 -------------------------------------
133 -- The Q is used in Compile_Sources below. Its implementation uses the GNAT
134 -- generic package Table (basically an extensible array). Q_Front points to
135 -- the first valid element in the Q, whereas Q.First is the first element
136 -- ever enqueued, while Q.Last - 1 is the last element in the Q.
138 -- +---+--------------+---+---+---+-----------+---+--------
139 -- Q | | ........ | | | | ....... | |
140 -- +---+--------------+---+---+---+-----------+---+--------
142 -- Q.First Q_Front Q.Last - 1
144 -- The elements comprised between Q.First and Q_Front - 1 are the elements
145 -- that have been enqueued and then dequeued, while the elements between
146 -- Q_Front and Q.Last - 1 are the elements currently in the Q. When the Q
147 -- is initialized Q_Front = Q.First = Q.Last. After Compile_Sources has
148 -- terminated its execution, Q_Front = Q.Last and the elements contained
149 -- between Q.Front and Q.Last-1 are those that were explored and thus
150 -- marked by Compile_Sources. Whenever the Q is reinitialized, the elements
151 -- between Q.First and Q.Last - 1 are unmarked.
154 -- Must be called to (re)initialize the Q
157 (Source_File : File_Name_Type;
158 Source_Unit : Unit_Name_Type := No_Unit_Name;
160 -- Inserts Source_File at the end of Q. Provide Source_Unit when possible
161 -- for external use (gnatdist). Provide index for multi-unit sources.
163 function Empty_Q return Boolean;
164 -- Returns True if Q is empty
166 procedure Extract_From_Q
167 (Source_File : out File_Name_Type;
168 Source_Unit : out Unit_Name_Type;
169 Source_Index : out Int);
170 -- Extracts the first element from the Q
172 procedure Insert_Project_Sources
173 (The_Project : Project_Id;
174 All_Projects : Boolean;
176 -- If Into_Q is True, insert all sources of the project file(s) that are
177 -- not already marked into the Q. If Into_Q is False, call Osint.Add_File
178 -- for the first source, then insert all other sources that are not already
179 -- marked into the Q. If All_Projects is True, all sources of all projects
180 -- are concerned; otherwise, only sources of The_Project are concerned,
181 -- including, if The_Project is an extending project, sources inherited
182 -- from projects being extended.
184 First_Q_Initialization : Boolean := True;
185 -- Will be set to false after Init_Q has been called once
188 -- Points to the first valid element in the Q
190 Unique_Compile : Boolean := False;
191 -- Set to True if -u or -U or a project file with no main is used
193 Unique_Compile_All_Projects : Boolean := False;
194 -- Set to True if -U is used
196 RTS_Specified : String_Access := null;
197 -- Used to detect multiple --RTS= switches
199 type Q_Record is record
200 File : File_Name_Type;
201 Unit : Unit_Name_Type;
204 -- File is the name of the file to compile. Unit is for gnatdist
205 -- use in order to easily get the unit name of a file to compile
206 -- when its name is krunched or declared in gnat.adc. Index, when not 0,
207 -- is the index of the unit in a multi-unit source.
209 package Q is new Table.Table (
210 Table_Component_Type => Q_Record,
211 Table_Index_Type => Natural,
212 Table_Low_Bound => 0,
213 Table_Initial => 4000,
214 Table_Increment => 100,
215 Table_Name => "Make.Q");
216 -- This is the actual Q
218 -- The 3 following packages are used to store gcc, gnatbind and gnatlink
219 -- switches found in the project files.
221 package Gcc_Switches is new Table.Table (
222 Table_Component_Type => String_Access,
223 Table_Index_Type => Integer,
224 Table_Low_Bound => 1,
226 Table_Increment => 100,
227 Table_Name => "Make.Gcc_Switches");
229 package Binder_Switches is new Table.Table (
230 Table_Component_Type => String_Access,
231 Table_Index_Type => Integer,
232 Table_Low_Bound => 1,
234 Table_Increment => 100,
235 Table_Name => "Make.Binder_Switches");
237 package Linker_Switches is new Table.Table (
238 Table_Component_Type => String_Access,
239 Table_Index_Type => Integer,
240 Table_Low_Bound => 1,
242 Table_Increment => 100,
243 Table_Name => "Make.Linker_Switches");
245 -- The following instantiations and variables are necessary to save what
246 -- is found on the command line, in case there is a project file specified.
248 package Saved_Gcc_Switches is new Table.Table (
249 Table_Component_Type => String_Access,
250 Table_Index_Type => Integer,
251 Table_Low_Bound => 1,
253 Table_Increment => 100,
254 Table_Name => "Make.Saved_Gcc_Switches");
256 package Saved_Binder_Switches is new Table.Table (
257 Table_Component_Type => String_Access,
258 Table_Index_Type => Integer,
259 Table_Low_Bound => 1,
261 Table_Increment => 100,
262 Table_Name => "Make.Saved_Binder_Switches");
264 package Saved_Linker_Switches is new Table.Table
265 (Table_Component_Type => String_Access,
266 Table_Index_Type => Integer,
267 Table_Low_Bound => 1,
269 Table_Increment => 100,
270 Table_Name => "Make.Saved_Linker_Switches");
272 package Switches_To_Check is new Table.Table (
273 Table_Component_Type => String_Access,
274 Table_Index_Type => Integer,
275 Table_Low_Bound => 1,
277 Table_Increment => 100,
278 Table_Name => "Make.Switches_To_Check");
280 package Library_Paths is new Table.Table (
281 Table_Component_Type => String_Access,
282 Table_Index_Type => Integer,
283 Table_Low_Bound => 1,
285 Table_Increment => 100,
286 Table_Name => "Make.Library_Paths");
288 package Failed_Links is new Table.Table (
289 Table_Component_Type => File_Name_Type,
290 Table_Index_Type => Integer,
291 Table_Low_Bound => 1,
293 Table_Increment => 100,
294 Table_Name => "Make.Failed_Links");
296 package Successful_Links is new Table.Table (
297 Table_Component_Type => File_Name_Type,
298 Table_Index_Type => Integer,
299 Table_Low_Bound => 1,
301 Table_Increment => 100,
302 Table_Name => "Make.Successful_Links");
304 package Library_Projs is new Table.Table (
305 Table_Component_Type => Project_Id,
306 Table_Index_Type => Integer,
307 Table_Low_Bound => 1,
309 Table_Increment => 100,
310 Table_Name => "Make.Library_Projs");
312 -- Two variables to keep the last binder and linker switch index in tables
313 -- Binder_Switches and Linker_Switches, before adding switches from the
314 -- project file (if any) and switches from the command line (if any).
316 Last_Binder_Switch : Integer := 0;
317 Last_Linker_Switch : Integer := 0;
319 Normalized_Switches : Argument_List_Access := new Argument_List (1 .. 10);
320 Last_Norm_Switch : Natural := 0;
322 Saved_Maximum_Processes : Natural := 0;
324 Gnatmake_Switch_Found : Boolean;
325 -- Set by Scan_Make_Arg. True when the switch is a gnatmake switch.
326 -- Tested by Add_Switches when switches in package Builder must all be
327 -- gnatmake switches.
329 Switch_May_Be_Passed_To_The_Compiler : Boolean;
330 -- Set by Add_Switches and Switches_Of. True when unrecognized switches
331 -- are passed to the Ada compiler.
333 type Arg_List_Ref is access Argument_List;
334 The_Saved_Gcc_Switches : Arg_List_Ref;
336 Project_File_Name : String_Access := null;
337 -- The path name of the main project file, if any
339 Project_File_Name_Present : Boolean := False;
340 -- True when -P is used with a space between -P and the project file name
342 Current_Verbosity : Prj.Verbosity := Prj.Default;
343 -- Verbosity to parse the project files
345 Project_Tree : constant Project_Tree_Ref := new Project_Tree_Data;
347 Main_Project : Prj.Project_Id := No_Project;
348 -- The project id of the main project file, if any
350 Project_Of_Current_Object_Directory : Project_Id := No_Project;
351 -- The object directory of the project for the last compilation. Avoid
352 -- calling Change_Dir if the current working directory is already this
355 -- Packages of project files where unknown attributes are errors
357 Naming_String : aliased String := "naming";
358 Builder_String : aliased String := "builder";
359 Compiler_String : aliased String := "compiler";
360 Binder_String : aliased String := "binder";
361 Linker_String : aliased String := "linker";
363 Gnatmake_Packages : aliased String_List :=
364 (Naming_String 'Access,
365 Builder_String 'Access,
366 Compiler_String 'Access,
367 Binder_String 'Access,
368 Linker_String 'Access);
370 Packages_To_Check_By_Gnatmake : constant String_List_Access :=
371 Gnatmake_Packages'Access;
373 procedure Add_Library_Search_Dir
375 On_Command_Line : Boolean);
376 -- Call Add_Lib_Search_Dir with an absolute directory path. If Path is
377 -- relative path, when On_Command_Line is True, it is relative to the
378 -- current working directory. When On_Command_Line is False, it is relative
379 -- to the project directory of the main project.
381 procedure Add_Source_Search_Dir
383 On_Command_Line : Boolean);
384 -- Call Add_Src_Search_Dir with an absolute directory path. If Path is a
385 -- relative path, when On_Command_Line is True, it is relative to the
386 -- current working directory. When On_Command_Line is False, it is relative
387 -- to the project directory of the main project.
389 procedure Add_Source_Dir (N : String);
390 -- Call Add_Src_Search_Dir (output one line when in verbose mode)
392 procedure Add_Source_Directories is
393 new Prj.Env.For_All_Source_Dirs (Action => Add_Source_Dir);
395 procedure Add_Object_Dir (N : String);
396 -- Call Add_Lib_Search_Dir (output one line when in verbose mode)
398 procedure Add_Object_Directories is
399 new Prj.Env.For_All_Object_Dirs (Action => Add_Object_Dir);
401 procedure Change_To_Object_Directory (Project : Project_Id);
402 -- Change to the object directory of project Project, if this is not
403 -- already the current working directory.
405 type Bad_Compilation_Info is record
406 File : File_Name_Type;
407 Unit : Unit_Name_Type;
410 -- File is the name of the file for which a compilation failed. Unit is for
411 -- gnatdist use in order to easily get the unit name of a file when its
412 -- name is krunched or declared in gnat.adc. Found is False if the
413 -- compilation failed because the file could not be found.
415 package Bad_Compilation is new Table.Table (
416 Table_Component_Type => Bad_Compilation_Info,
417 Table_Index_Type => Natural,
418 Table_Low_Bound => 1,
420 Table_Increment => 100,
421 Table_Name => "Make.Bad_Compilation");
422 -- Full name of all the source files for which compilation fails
424 Do_Compile_Step : Boolean := True;
425 Do_Bind_Step : Boolean := True;
426 Do_Link_Step : Boolean := True;
427 -- Flags to indicate what step should be executed. Can be set to False
428 -- with the switches -c, -b and -l. These flags are reset to True for
429 -- each invocation of procedure Gnatmake.
431 Shared_String : aliased String := "-shared";
432 Force_Elab_Flags_String : aliased String := "-F";
434 No_Shared_Switch : aliased Argument_List := (1 .. 0 => null);
435 Shared_Switch : aliased Argument_List := (1 => Shared_String'Access);
436 Bind_Shared : Argument_List_Access := No_Shared_Switch'Access;
437 -- Switch to added in front of gnatbind switches. By default no switch is
438 -- added. Switch "-shared" is added if there is a non-static Library
441 Shared_Libgcc : aliased String := "-shared-libgcc";
443 No_Shared_Libgcc_Switch : aliased Argument_List := (1 .. 0 => null);
444 Shared_Libgcc_Switch : aliased Argument_List :=
445 (1 => Shared_Libgcc'Access);
446 Link_With_Shared_Libgcc : Argument_List_Access :=
447 No_Shared_Libgcc_Switch'Access;
449 procedure Make_Failed (S : String);
450 -- Delete all temp files created by Gnatmake and call Osint.Fail, with the
451 -- parameter S (see osint.ads). This is called from the Prj hierarchy and
452 -- the MLib hierarchy.
454 --------------------------
455 -- Obsolete Executables --
456 --------------------------
458 Executable_Obsolete : Boolean := False;
459 -- Executable_Obsolete is initially set to False for each executable,
460 -- and is set to True whenever one of the source of the executable is
461 -- compiled, or has already been compiled for another executable.
463 Max_Header : constant := 200;
464 -- This needs a proper comment, it used to say "arbitrary"
465 -- that's not an adequate comment ???
467 type Header_Num is range 1 .. Max_Header;
468 -- Header_Num for the hash table Obsoleted below
470 function Hash (F : File_Name_Type) return Header_Num;
471 -- Hash function for the hash table Obsoleted below
473 package Obsoleted is new System.HTable.Simple_HTable
474 (Header_Num => Header_Num,
477 Key => File_Name_Type,
480 -- A hash table to keep all files that have been compiled, to detect
481 -- if an executable is up to date or not.
483 procedure Enter_Into_Obsoleted (F : File_Name_Type);
484 -- Enter a file name, without directory information, into the hash table
487 function Is_In_Obsoleted (F : File_Name_Type) return Boolean;
488 -- Check if a file name, without directory information, has already been
489 -- entered into the hash table Obsoleted.
491 type Dependency is record
492 This : File_Name_Type;
493 Depends_On : File_Name_Type;
495 -- Components of table Dependencies below
497 package Dependencies is new Table.Table (
498 Table_Component_Type => Dependency,
499 Table_Index_Type => Integer,
500 Table_Low_Bound => 1,
502 Table_Increment => 100,
503 Table_Name => "Make.Dependencies");
504 -- A table to keep dependencies, to be able to decide if an executable
505 -- is obsolete. More explanation needed ???
507 -- procedure Add_Dependency (S : File_Name_Type; On : File_Name_Type);
508 -- -- Add one entry in table Dependencies
510 ----------------------------
511 -- Arguments and Switches --
512 ----------------------------
514 Arguments : Argument_List_Access;
515 -- Used to gather the arguments for invocation of the compiler
517 Last_Argument : Natural := 0;
518 -- Last index of arguments in Arguments above
520 Arguments_Collected : Boolean := False;
521 -- Set to True when the arguments for the next invocation of the compiler
522 -- have been collected.
524 Arguments_Project : Project_Id;
525 -- Project id, if any, of the source to be compiled
527 Arguments_Path_Name : Path_Name_Type;
528 -- Full path of the source to be compiled, when Arguments_Project is not
531 Dummy_Switch : constant String_Access := new String'("- ");
532 -- Used to initialized Prev_Switch in procedure Check
534 procedure Add_Arguments (Args : Argument_List);
535 -- Add arguments to global variable Arguments, increasing its size
536 -- if necessary and adjusting Last_Argument.
538 function Configuration_Pragmas_Switch
539 (For_Project : Project_Id) return Argument_List;
540 -- Return an argument list of one element, if there is a configuration
541 -- pragmas file to be specified for For_Project,
542 -- otherwise return an empty argument list.
548 procedure List_Depend;
549 -- Prints to standard output the list of object dependencies. This list
550 -- can be used directly in a Makefile. A call to Compile_Sources must
551 -- precede the call to List_Depend. Also because this routine uses the
552 -- ALI files that were originally loaded and scanned by Compile_Sources,
553 -- no additional ALI files should be scanned between the two calls (i.e.
554 -- between the call to Compile_Sources and List_Depend.)
556 procedure List_Bad_Compilations;
557 -- Prints out the list of all files for which the compilation failed
559 procedure Verbose_Msg
562 N2 : Name_Id := No_Name;
564 Prefix : String := " -> ";
565 Minimum_Verbosity : Verbosity_Level_Type := Opt.Low);
566 procedure Verbose_Msg
567 (N1 : File_Name_Type;
569 N2 : File_Name_Type := No_File;
571 Prefix : String := " -> ";
572 Minimum_Verbosity : Verbosity_Level_Type := Opt.Low);
573 -- If the verbose flag (Verbose_Mode) is set and the verbosity level is
574 -- at least equal to Minimum_Verbosity, then print Prefix to standard
575 -- output followed by N1 and S1. If N2 /= No_Name then N2 is printed after
576 -- S1. S2 is printed last. Both N1 and N2 are printed in quotation marks.
578 Usage_Needed : Boolean := True;
579 -- Flag used to make sure Makeusg is call at most once
582 -- Call Makeusg, if Usage_Needed is True.
583 -- Set Usage_Needed to False.
585 procedure Debug_Msg (S : String; N : Name_Id);
586 procedure Debug_Msg (S : String; N : File_Name_Type);
587 procedure Debug_Msg (S : String; N : Unit_Name_Type);
588 -- If Debug.Debug_Flag_W is set outputs string S followed by name N
590 procedure Recursive_Compute_Depth
591 (Project : Project_Id;
593 -- Compute depth of Project and of the projects it depends on
595 procedure Compute_All_Imported_Projects (Project : Project_Id);
596 -- Compute, the list of the projects imported directly or indirectly by
599 -----------------------
600 -- Gnatmake Routines --
601 -----------------------
603 subtype Lib_Mark_Type is Byte;
604 -- Used in Mark_Directory
606 Ada_Lib_Dir : constant Lib_Mark_Type := 1;
607 -- Used to mark a directory as a GNAT lib dir
609 -- Note that the notion of GNAT lib dir is no longer used. The code related
610 -- to it has not been removed to give an idea on how to use the directory
611 -- prefix marking mechanism.
613 -- An Ada library directory is a directory containing ali and object files
614 -- but no source files for the bodies (the specs can be in the same or some
615 -- other directory). These directories are specified in the Gnatmake
616 -- command line with the switch "-Adir" (to specify the spec location -Idir
617 -- cab be used). Gnatmake skips the missing sources whose ali are in Ada
618 -- library directories. For an explanation of why Gnatmake behaves that
619 -- way, see the spec of Make.Compile_Sources. The directory lookup penalty
620 -- is incurred every single time this routine is called.
622 procedure Check_Steps;
623 -- Check what steps (Compile, Bind, Link) must be executed.
624 -- Set the step flags accordingly.
626 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean;
627 -- Get directory prefix of this file and get lib mark stored in name
628 -- table for this directory. Then check if an Ada lib mark has been set.
630 procedure Mark_Directory
632 Mark : Lib_Mark_Type;
633 On_Command_Line : Boolean);
634 -- Store the absolute path from Dir in name table and set lib mark as name
635 -- info to identify Ada libraries.
637 -- If Dir is a relative path, when On_Command_Line is True, it is relative
638 -- to the current working directory; when On_Command_Line is False, it is
639 -- relative to the project directory of the main project.
641 Output_Is_Object : Boolean := True;
642 -- Set to False when using a switch -S for the compiler
644 procedure Check_For_S_Switch;
645 -- Set Output_Is_Object to False when the -S switch is used for the
649 (Source_File : File_Name_Type;
650 Source_File_Name : String;
652 Naming : Naming_Data;
653 In_Package : Package_Id;
654 Allow_ALI : Boolean) return Variable_Value;
655 -- Return the switches for the source file in the specified package of a
656 -- project file. If the Source_File ends with a standard GNAT extension
657 -- (".ads" or ".adb"), try first the full name, then the name without the
658 -- extension, then, if Allow_ALI is True, the name with the extension
659 -- ".ali". If there is no switches for either names, try first Switches
660 -- (others) then the default switches for Ada. If all failed, return
661 -- No_Variable_Value.
663 function Is_In_Object_Directory
664 (Source_File : File_Name_Type;
665 Full_Lib_File : File_Name_Type) return Boolean;
666 -- Check if, when using a project file, the ALI file is in the project
667 -- directory of the ultimate extending project. If it is not, we ignore
668 -- the fact that this ALI file is read-only.
670 ----------------------------------------------------
671 -- Compiler, Binder & Linker Data and Subprograms --
672 ----------------------------------------------------
674 Gcc : String_Access := Program_Name ("gcc", "gnatmake");
675 Gnatbind : String_Access := Program_Name ("gnatbind", "gnatmake");
676 Gnatlink : String_Access := Program_Name ("gnatlink", "gnatmake");
677 -- Default compiler, binder, linker programs
679 Saved_Gcc : String_Access := null;
680 Saved_Gnatbind : String_Access := null;
681 Saved_Gnatlink : String_Access := null;
682 -- Given by the command line. Will be used, if non null
684 Gcc_Path : String_Access :=
685 GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
686 Gnatbind_Path : String_Access :=
687 GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
688 Gnatlink_Path : String_Access :=
689 GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
690 -- Path for compiler, binder, linker programs, defaulted now for gnatdist.
691 -- Changed later if overridden on command line.
693 Comp_Flag : constant String_Access := new String'("-c");
694 Output_Flag : constant String_Access := new String'("-o");
695 Ada_Flag_1 : constant String_Access := new String'("-x");
696 Ada_Flag_2 : constant String_Access := new String'("ada");
697 No_gnat_adc : constant String_Access := new String'("-gnatA");
698 GNAT_Flag : constant String_Access := new String'("-gnatpg");
699 Do_Not_Check_Flag : constant String_Access := new String'("-x");
701 Object_Suffix : constant String := Get_Target_Object_Suffix.all;
703 Syntax_Only : Boolean := False;
704 -- Set to True when compiling with -gnats
706 Display_Executed_Programs : Boolean := True;
707 -- Set to True if name of commands should be output on stderr (or on stdout
708 -- if the Commands_To_Stdout flag was set by use of the -eS switch).
710 Output_File_Name_Seen : Boolean := False;
711 -- Set to True after having scanned the file_name for
712 -- switch "-o file_name"
714 Object_Directory_Seen : Boolean := False;
715 -- Set to True after having scanned the object directory for
716 -- switch "-D obj_dir".
718 Object_Directory_Path : String_Access := null;
719 -- The path name of the object directory, set with switch -D
721 type Make_Program_Type is (None, Compiler, Binder, Linker);
723 Program_Args : Make_Program_Type := None;
724 -- Used to indicate if we are scanning gnatmake, gcc, gnatbind, or gnatbind
725 -- options within the gnatmake command line. Used in Scan_Make_Arg only,
726 -- but must be global since value preserved from one call to another.
728 Temporary_Config_File : Boolean := False;
729 -- Set to True when there is a temporary config file used for a project
730 -- file, to avoid displaying the -gnatec switch for a temporary file.
732 procedure Add_Switches
733 (The_Package : Package_Id;
736 Program : Make_Program_Type;
737 Unknown_Switches_To_The_Compiler : Boolean := True);
740 Program : Make_Program_Type;
741 Append_Switch : Boolean := True;
742 And_Save : Boolean := True);
745 Program : Make_Program_Type;
746 Append_Switch : Boolean := True;
747 And_Save : Boolean := True);
748 -- Make invokes one of three programs (the compiler, the binder or the
749 -- linker). For the sake of convenience, some program specific switches
750 -- can be passed directly on the gnatmake command line. This procedure
751 -- records these switches so that gnatmake can pass them to the right
752 -- program. S is the switch to be added at the end of the command line
753 -- for Program if Append_Switch is True. If Append_Switch is False S is
754 -- added at the beginning of the command line.
757 (Source_File : File_Name_Type;
759 Is_Main_Source : Boolean;
760 The_Args : Argument_List;
761 Lib_File : File_Name_Type;
764 O_File : out File_Name_Type;
765 O_Stamp : out Time_Stamp_Type);
766 -- Determines whether the library file Lib_File is up-to-date or not. The
767 -- full name (with path information) of the object file corresponding to
768 -- Lib_File is returned in O_File. Its time stamp is saved in O_Stamp.
769 -- ALI is the ALI_Id corresponding to Lib_File. If Lib_File in not
770 -- up-to-date, then the corresponding source file needs to be recompiled.
771 -- In this case ALI = No_ALI_Id.
773 procedure Check_Linker_Options
774 (E_Stamp : Time_Stamp_Type;
775 O_File : out File_Name_Type;
776 O_Stamp : out Time_Stamp_Type);
777 -- Checks all linker options for linker files that are newer
778 -- than E_Stamp. If such objects are found, the youngest object
779 -- is returned in O_File and its stamp in O_Stamp.
781 -- If no obsolete linker files were found, the first missing
782 -- linker file is returned in O_File and O_Stamp is empty.
783 -- Otherwise O_File is No_File.
785 procedure Collect_Arguments
786 (Source_File : File_Name_Type;
788 Is_Main_Source : Boolean;
789 Args : Argument_List);
790 -- Collect all arguments for a source to be compiled, including those
791 -- that come from a project file.
793 procedure Display (Program : String; Args : Argument_List);
794 -- Displays Program followed by the arguments in Args if variable
795 -- Display_Executed_Programs is set. The lower bound of Args must be 1.
797 procedure Report_Compilation_Failed;
798 -- Delete all temporary files and fail graciously
804 type Temp_Path_Names is
805 array (Project_Id range <>, Positive range <>) of Path_Name_Type;
807 type Temp_Path_Ptr is access Temp_Path_Names;
809 type Indices is array (Project_Id range <>) of Natural;
811 type Indices_Ptr is access Indices;
813 type Free_File_Indices is array
814 (Project_Id range <>, Positive range <>) of Positive;
816 type Free_Indices_Ptr is access Free_File_Indices;
818 The_Mapping_File_Names : Temp_Path_Ptr;
819 -- For each project, the name ids of the temporary mapping files used
821 Last_Mapping_File_Names : Indices_Ptr;
822 -- For each project, the index of the last mapping file created
824 The_Free_Mapping_File_Indices : Free_Indices_Ptr;
825 -- For each project, the indices in The_Mapping_File_Names of the mapping
826 -- file names that can be reused for subsequent compilations.
828 Last_Free_Indices : Indices_Ptr;
829 -- For each project, the number of mapping files that can be reused
831 Gnatmake_Mapping_File : String_Access := null;
832 -- The path name of a mapping file specified by switch -C=
834 procedure Delete_Mapping_Files;
835 -- Delete all temporary mapping files. Called only in Delete_All_Temp_Files
836 -- which ensures that Debug_Flag_N is False.
838 procedure Init_Mapping_File
839 (Project : Project_Id;
840 File_Index : in out Natural);
841 -- Create a new temporary mapping file, and fill it with the project file
842 -- mappings, when using project file(s). The out parameter File_Index is
843 -- the index to the name of the file in the array The_Mapping_File_Names.
845 procedure Delete_Temp_Config_Files;
846 -- Delete all temporary config files. Must not be called if Debug_Flag_N
849 procedure Delete_All_Temp_Files;
850 -- Delete all temp files (config files, mapping files, path files), unless
851 -- Debug_Flag_N is True (in which case all temp files are left for user
854 -------------------------------------------------
855 -- Subprogram declarations moved from the spec --
856 -------------------------------------------------
858 procedure Bind (ALI_File : File_Name_Type; Args : Argument_List);
859 -- Binds ALI_File. Args are the arguments to pass to the binder.
860 -- Args must have a lower bound of 1.
862 procedure Display_Commands (Display : Boolean := True);
863 -- The default behavior of Make commands (Compile_Sources, Bind, Link)
864 -- is to display them on stderr. This behavior can be changed repeatedly
865 -- by invoking this procedure.
867 -- If a compilation, bind or link failed one of the following 3 exceptions
868 -- is raised. These need to be handled by the calling routines.
870 procedure Compile_Sources
871 (Main_Source : File_Name_Type;
872 Args : Argument_List;
873 First_Compiled_File : out File_Name_Type;
874 Most_Recent_Obj_File : out File_Name_Type;
875 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
876 Main_Unit : out Boolean;
877 Compilation_Failures : out Natural;
878 Main_Index : Int := 0;
879 Check_Readonly_Files : Boolean := False;
880 Do_Not_Execute : Boolean := False;
881 Force_Compilations : Boolean := False;
882 Keep_Going : Boolean := False;
883 In_Place_Mode : Boolean := False;
884 Initialize_ALI_Data : Boolean := True;
885 Max_Process : Positive := 1);
886 -- Compile_Sources will recursively compile all the sources needed by
887 -- Main_Source. Before calling this routine make sure Namet has been
888 -- initialized. This routine can be called repeatedly with different
889 -- Main_Source file as long as all the source (-I flags), library
890 -- (-B flags) and ada library (-A flags) search paths between calls are
891 -- *exactly* the same. The default directory must also be the same.
893 -- Args contains the arguments to use during the compilations.
894 -- The lower bound of Args must be 1.
896 -- First_Compiled_File is set to the name of the first file that is
897 -- compiled or that needs to be compiled. This is set to No_Name if no
898 -- compilations were needed.
900 -- Most_Recent_Obj_File is set to the full name of the most recent
901 -- object file found when no compilations are needed, that is when
902 -- First_Compiled_File is set to No_Name. When First_Compiled_File
903 -- is set then Most_Recent_Obj_File is set to No_Name.
905 -- Most_Recent_Obj_Stamp is the time stamp of Most_Recent_Obj_File.
907 -- Main_Unit is set to True if Main_Source can be a main unit.
908 -- If Do_Not_Execute is False and First_Compiled_File /= No_Name
909 -- the value of Main_Unit is always False.
910 -- Is this used any more??? It is certainly not used by gnatmake???
912 -- Compilation_Failures is a count of compilation failures. This count
913 -- is used to extract compilation failure reports with Extract_Failure.
915 -- Main_Index, when not zero, is the index of the main unit in source
916 -- file Main_Source which is a multi-unit source.
917 -- Zero indicates that Main_Source is a single unit source file.
919 -- Check_Readonly_Files set it to True to compile source files
920 -- which library files are read-only. When compiling GNAT predefined
921 -- files the "-gnatg" flag is used.
923 -- Do_Not_Execute set it to True to find out the first source that
924 -- needs to be recompiled, but without recompiling it. This file is
925 -- saved in First_Compiled_File.
927 -- Force_Compilations forces all compilations no matter what but
928 -- recompiles read-only files only if Check_Readonly_Files
931 -- Keep_Going when True keep compiling even in the presence of
932 -- compilation errors.
934 -- In_Place_Mode when True save library/object files in their object
935 -- directory if they already exist; otherwise, in the source directory.
937 -- Initialize_ALI_Data set it to True when you want to initialize ALI
938 -- data-structures. This is what you should do most of the time.
939 -- (especially the first time around when you call this routine).
940 -- This parameter is set to False to preserve previously recorded
943 -- Max_Process is the maximum number of processes that should be spawned
944 -- to carry out compilations.
946 -- Flags in Package Opt Affecting Compile_Sources
947 -- -----------------------------------------------
949 -- Check_Object_Consistency set it to False to omit all consistency
950 -- checks between an .ali file and its corresponding object file.
951 -- When this flag is set to true, every time an .ali is read,
952 -- package Osint checks that the corresponding object file
953 -- exists and is more recent than the .ali.
955 -- Use of Name Table Info
956 -- ----------------------
958 -- All file names manipulated by Compile_Sources are entered into the
959 -- Names table. The Byte field of a source file is used to mark it.
961 -- Calling Compile_Sources Several Times
962 -- -------------------------------------
964 -- Upon return from Compile_Sources all the ALI data structures are left
965 -- intact for further browsing. HOWEVER upon entry to this routine ALI
966 -- data structures are re-initialized if parameter Initialize_ALI_Data
967 -- above is set to true. Typically this is what you want the first time
968 -- you call Compile_Sources. You should not load an ali file, call this
969 -- routine with flag Initialize_ALI_Data set to True and then expect
970 -- that ALI information to be around after the call. Note that the first
971 -- time you call Compile_Sources you better set Initialize_ALI_Data to
972 -- True unless you have called Initialize_ALI yourself.
974 -- Compile_Sources ALGORITHM : Compile_Sources (Main_Source)
975 -- -------------------------
977 -- 1. Insert Main_Source in a Queue (Q) and mark it.
979 -- 2. Let unit.adb be the file at the head of the Q. If unit.adb is
980 -- missing but its corresponding ali file is in an Ada library directory
981 -- (see below) then, remove unit.adb from the Q and goto step 4.
982 -- Otherwise, look at the files under the D (dependency) section of
983 -- unit.ali. If unit.ali does not exist or some of the time stamps do
984 -- not match, (re)compile unit.adb.
986 -- An Ada library directory is a directory containing Ada specs, ali
987 -- and object files but no source files for the bodies. An Ada library
988 -- directory is communicated to gnatmake by means of some switch so that
989 -- gnatmake can skip the sources whole ali are in that directory.
990 -- There are two reasons for skipping the sources in this case. Firstly,
991 -- Ada libraries typically come without full sources but binding and
992 -- linking against those libraries is still possible. Secondly, it would
993 -- be very wasteful for gnatmake to systematically check the consistency
994 -- of every external Ada library used in a program. The binder is
995 -- already in charge of catching any potential inconsistencies.
997 -- 3. Look into the W section of unit.ali and insert into the Q all
998 -- unmarked source files. Mark all files newly inserted in the Q.
999 -- Specifically, assuming that the W section looks like
1001 -- W types%s types.adb types.ali
1002 -- W unchecked_deallocation%s
1003 -- W xref_tab%s xref_tab.adb xref_tab.ali
1005 -- Then xref_tab.adb and types.adb are inserted in the Q if they are not
1007 -- Note that there is no file listed under W unchecked_deallocation%s
1008 -- so no generic body should ever be explicitly compiled (unless the
1009 -- Main_Source at the start was a generic body).
1011 -- 4. Repeat steps 2 and 3 above until the Q is empty
1013 -- Note that the above algorithm works because the units withed in
1014 -- subunits are transitively included in the W section (with section) of
1015 -- the main unit. Likewise the withed units in a generic body needed
1016 -- during a compilation are also transitively included in the W section
1017 -- of the originally compiled file.
1019 procedure Initialize;
1020 -- Performs default and package initialization. Therefore,
1021 -- Compile_Sources can be called by an external unit.
1024 (ALI_File : File_Name_Type;
1025 Args : Argument_List;
1026 Success : out Boolean);
1027 -- Links ALI_File. Args are the arguments to pass to the linker.
1028 -- Args must have a lower bound of 1. Success indicates if the link
1029 -- succeeded or not.
1031 procedure Scan_Make_Arg (Argv : String; And_Save : Boolean);
1032 -- Scan make arguments. Argv is a single argument to be processed
1038 procedure Add_Arguments (Args : Argument_List) is
1040 if Arguments = null then
1041 Arguments := new Argument_List (1 .. Args'Length + 10);
1044 while Last_Argument + Args'Length > Arguments'Last loop
1046 New_Arguments : constant Argument_List_Access :=
1047 new Argument_List (1 .. Arguments'Last * 2);
1049 New_Arguments (1 .. Last_Argument) :=
1050 Arguments (1 .. Last_Argument);
1051 Arguments := New_Arguments;
1056 Arguments (Last_Argument + 1 .. Last_Argument + Args'Length) := Args;
1057 Last_Argument := Last_Argument + Args'Length;
1060 -- --------------------
1061 -- -- Add_Dependency --
1062 -- --------------------
1064 -- procedure Add_Dependency (S : File_Name_Type; On : File_Name_Type) is
1066 -- Dependencies.Increment_Last;
1067 -- Dependencies.Table (Dependencies.Last) := (S, On);
1068 -- end Add_Dependency;
1070 ----------------------------
1071 -- Add_Library_Search_Dir --
1072 ----------------------------
1074 procedure Add_Library_Search_Dir
1076 On_Command_Line : Boolean)
1079 if On_Command_Line then
1080 Add_Lib_Search_Dir (Normalize_Pathname (Path));
1084 (Project_Tree.Projects.Table (Main_Project).Directory.Display_Name);
1086 (Normalize_Pathname (Path, Name_Buffer (1 .. Name_Len)));
1088 end Add_Library_Search_Dir;
1090 --------------------
1091 -- Add_Object_Dir --
1092 --------------------
1094 procedure Add_Object_Dir (N : String) is
1096 Add_Lib_Search_Dir (N);
1098 if Verbose_Mode then
1099 Write_Str ("Adding object directory """);
1106 --------------------
1107 -- Add_Source_Dir --
1108 --------------------
1110 procedure Add_Source_Dir (N : String) is
1112 Add_Src_Search_Dir (N);
1114 if Verbose_Mode then
1115 Write_Str ("Adding source directory """);
1122 ---------------------------
1123 -- Add_Source_Search_Dir --
1124 ---------------------------
1126 procedure Add_Source_Search_Dir
1128 On_Command_Line : Boolean)
1131 if On_Command_Line then
1132 Add_Src_Search_Dir (Normalize_Pathname (Path));
1136 (Project_Tree.Projects.Table (Main_Project).Directory.Display_Name);
1138 (Normalize_Pathname (Path, Name_Buffer (1 .. Name_Len)));
1140 end Add_Source_Search_Dir;
1146 procedure Add_Switch
1148 Program : Make_Program_Type;
1149 Append_Switch : Boolean := True;
1150 And_Save : Boolean := True)
1153 with package T is new Table.Table (<>);
1154 procedure Generic_Position (New_Position : out Integer);
1155 -- Generic procedure that chooses a position for S in T at the
1156 -- beginning or the end, depending on the boolean Append_Switch.
1157 -- Calling this procedure may expand the table.
1159 ----------------------
1160 -- Generic_Position --
1161 ----------------------
1163 procedure Generic_Position (New_Position : out Integer) is
1167 if Append_Switch then
1168 New_Position := Integer (T.Last);
1170 for J in reverse T.Table_Index_Type'Succ (T.First) .. T.Last loop
1171 T.Table (J) := T.Table (T.Table_Index_Type'Pred (J));
1174 New_Position := Integer (T.First);
1176 end Generic_Position;
1178 procedure Gcc_Switches_Pos is new Generic_Position (Gcc_Switches);
1179 procedure Binder_Switches_Pos is new Generic_Position (Binder_Switches);
1180 procedure Linker_Switches_Pos is new Generic_Position (Linker_Switches);
1182 procedure Saved_Gcc_Switches_Pos is new
1183 Generic_Position (Saved_Gcc_Switches);
1185 procedure Saved_Binder_Switches_Pos is new
1186 Generic_Position (Saved_Binder_Switches);
1188 procedure Saved_Linker_Switches_Pos is new
1189 Generic_Position (Saved_Linker_Switches);
1191 New_Position : Integer;
1193 -- Start of processing for Add_Switch
1199 Saved_Gcc_Switches_Pos (New_Position);
1200 Saved_Gcc_Switches.Table (New_Position) := S;
1203 Saved_Binder_Switches_Pos (New_Position);
1204 Saved_Binder_Switches.Table (New_Position) := S;
1207 Saved_Linker_Switches_Pos (New_Position);
1208 Saved_Linker_Switches.Table (New_Position) := S;
1211 raise Program_Error;
1217 Gcc_Switches_Pos (New_Position);
1218 Gcc_Switches.Table (New_Position) := S;
1221 Binder_Switches_Pos (New_Position);
1222 Binder_Switches.Table (New_Position) := S;
1225 Linker_Switches_Pos (New_Position);
1226 Linker_Switches.Table (New_Position) := S;
1229 raise Program_Error;
1234 procedure Add_Switch
1236 Program : Make_Program_Type;
1237 Append_Switch : Boolean := True;
1238 And_Save : Boolean := True)
1241 Add_Switch (S => new String'(S),
1243 Append_Switch => Append_Switch,
1244 And_Save => And_Save);
1251 procedure Add_Switches
1252 (The_Package : Package_Id;
1255 Program : Make_Program_Type;
1256 Unknown_Switches_To_The_Compiler : Boolean := True)
1258 Switches : Variable_Value;
1259 Switch_List : String_List_Id;
1260 Element : String_Element;
1263 Switch_May_Be_Passed_To_The_Compiler :=
1264 Unknown_Switches_To_The_Compiler;
1266 if File_Name'Length > 0 then
1267 Name_Len := File_Name'Length;
1268 Name_Buffer (1 .. Name_Len) := File_Name;
1271 (Source_File => Name_Find,
1272 Source_File_Name => File_Name,
1273 Source_Index => Index,
1274 Naming => Project_Tree.Projects.Table
1275 (Main_Project).Naming,
1276 In_Package => The_Package,
1277 Allow_ALI => Program = Binder or else Program = Linker);
1279 if Switches.Kind = List then
1280 Program_Args := Program;
1282 Switch_List := Switches.Values;
1283 while Switch_List /= Nil_String loop
1284 Element := Project_Tree.String_Elements.Table (Switch_List);
1285 Get_Name_String (Element.Value);
1287 if Name_Len > 0 then
1289 Argv : constant String := Name_Buffer (1 .. Name_Len);
1290 -- We need a copy, because Name_Buffer may be modified
1293 if Verbose_Mode then
1294 Write_Str (" Adding ");
1298 Scan_Make_Arg (Argv, And_Save => False);
1300 if not Gnatmake_Switch_Found
1301 and then not Switch_May_Be_Passed_To_The_Compiler
1305 """ is not a gnatmake switch. Consider moving " &
1306 "it to Global_Compilation_Switches.",
1309 Make_Failed ("*** illegal switch """ & Argv & """");
1314 Switch_List := Element.Next;
1324 procedure Bind (ALI_File : File_Name_Type; Args : Argument_List) is
1325 Bind_Args : Argument_List (1 .. Args'Last + 2);
1326 Bind_Last : Integer;
1330 pragma Assert (Args'First = 1);
1332 -- Optimize the simple case where the gnatbind command line looks like
1333 -- gnatbind -aO. -I- file.ali --into-> gnatbind file.adb
1336 and then Args (Args'First).all = "-aO" & Normalized_CWD
1337 and then Args (Args'Last).all = "-I-"
1338 and then ALI_File = Strip_Directory (ALI_File)
1340 Bind_Last := Args'First - 1;
1343 Bind_Last := Args'Last;
1344 Bind_Args (Args'Range) := Args;
1347 -- It is completely pointless to re-check source file time stamps. This
1348 -- has been done already by gnatmake
1350 Bind_Last := Bind_Last + 1;
1351 Bind_Args (Bind_Last) := Do_Not_Check_Flag;
1353 Get_Name_String (ALI_File);
1355 Bind_Last := Bind_Last + 1;
1356 Bind_Args (Bind_Last) := new String'(Name_Buffer (1 .. Name_Len));
1358 GNAT.OS_Lib.Normalize_Arguments (Bind_Args (Args'First .. Bind_Last));
1360 Display (Gnatbind.all, Bind_Args (Args'First .. Bind_Last));
1362 if Gnatbind_Path = null then
1363 Make_Failed ("error, unable to locate " & Gnatbind.all);
1367 (Gnatbind_Path.all, Bind_Args (Args'First .. Bind_Last), Success);
1370 Make_Failed ("*** bind failed.");
1374 --------------------------------
1375 -- Change_To_Object_Directory --
1376 --------------------------------
1378 procedure Change_To_Object_Directory (Project : Project_Id) is
1379 Actual_Project : Project_Id;
1380 Object_Directory : Path_Name_Type;
1383 -- For sources outside of any project, compilation occurs in the object
1384 -- directory of the main project, otherwise we use the project given.
1386 if Project = No_Project then
1387 Actual_Project := Main_Project;
1389 Actual_Project := Project;
1392 -- Nothing to do if the current working directory is already the correct
1393 -- object directory.
1395 if Project_Of_Current_Object_Directory /= Actual_Project then
1396 Project_Of_Current_Object_Directory := Actual_Project;
1398 Project_Tree.Projects.Table (Actual_Project).Object_Directory.Name;
1400 -- Set the working directory to the object directory of the actual
1403 if Verbose_Mode then
1404 Write_Str ("Changing to object directory of """);
1406 (Project_Tree.Projects.Table (Actual_Project).Display_Name);
1407 Write_Str (""": """);
1408 Write_Name (Object_Directory);
1412 Change_Dir (Get_Name_String (Object_Directory));
1416 -- Fail if unable to change to the object directory
1418 when Directory_Error =>
1419 Make_Failed ("unable to change to object directory """ &
1421 (Project_Tree.Projects.Table
1422 (Actual_Project).Object_Directory.Name) &
1424 Get_Name_String (Project_Tree.Projects.Table
1425 (Actual_Project).Display_Name));
1426 end Change_To_Object_Directory;
1433 (Source_File : File_Name_Type;
1435 Is_Main_Source : Boolean;
1436 The_Args : Argument_List;
1437 Lib_File : File_Name_Type;
1438 Read_Only : Boolean;
1440 O_File : out File_Name_Type;
1441 O_Stamp : out Time_Stamp_Type)
1443 function File_Not_A_Source_Of
1445 Sfile : File_Name_Type) return Boolean;
1447 function First_New_Spec (A : ALI_Id) return File_Name_Type;
1448 -- Looks in the with table entries of A and returns the spec file name
1449 -- of the first withed unit (subprogram) for which no spec existed when
1450 -- A was generated but for which there exists one now, implying that A
1451 -- is now obsolete. If no such unit is found No_File is returned.
1452 -- Otherwise the spec file name of the unit is returned.
1454 -- **WARNING** in the event of Uname format modifications, one *MUST*
1455 -- make sure this function is also updated.
1457 -- Note: This function should really be in ali.adb and use Uname
1458 -- services, but this causes the whole compiler to be dragged along
1459 -- for gnatbind and gnatmake.
1461 --------------------------
1462 -- File_Not_A_Source_Of --
1463 --------------------------
1465 function File_Not_A_Source_Of
1467 Sfile : File_Name_Type) return Boolean
1469 UID : Prj.Unit_Index;
1473 UID := Units_Htable.Get (Project_Tree.Units_HT, Uname);
1475 if UID /= Prj.No_Unit_Index then
1476 U_Data := Project_Tree.Units.Table (UID);
1478 if U_Data.File_Names (Body_Part).Name /= Sfile
1479 and then U_Data.File_Names (Specification).Name /= Sfile
1481 Verbose_Msg (Uname, "sources do not include ", Name_Id (Sfile));
1487 end File_Not_A_Source_Of;
1489 --------------------
1490 -- First_New_Spec --
1491 --------------------
1493 function First_New_Spec (A : ALI_Id) return File_Name_Type is
1494 Spec_File_Name : File_Name_Type := No_File;
1496 function New_Spec (Uname : Unit_Name_Type) return Boolean;
1497 -- Uname is the name of the spec or body of some ada unit. This
1498 -- function returns True if the Uname is the name of a body which has
1499 -- a spec not mentioned in ALI file A. If True is returned
1500 -- Spec_File_Name above is set to the name of this spec file.
1506 function New_Spec (Uname : Unit_Name_Type) return Boolean is
1507 Spec_Name : Unit_Name_Type;
1508 File_Name : File_Name_Type;
1511 -- Test whether Uname is the name of a body unit (i.e. ends
1514 Get_Name_String (Uname);
1516 Assert (Name_Len > 2 and then Name_Buffer (Name_Len - 1) = '%');
1518 if Name_Buffer (Name_Len) /= 'b' then
1522 -- Convert unit name into spec name
1524 -- ??? this code seems dubious in presence of pragma
1525 -- Source_File_Name since there is no more direct relationship
1526 -- between unit name and file name.
1528 -- ??? Further, what about alternative subunit naming
1530 Name_Buffer (Name_Len) := 's';
1531 Spec_Name := Name_Find;
1532 File_Name := Get_File_Name (Spec_Name, Subunit => False);
1534 -- Look if File_Name is mentioned in A's sdep list.
1535 -- If not look if the file exists. If it does return True.
1538 ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep
1540 if Sdep.Table (D).Sfile = File_Name then
1545 if Full_Source_Name (File_Name) /= No_File then
1546 Spec_File_Name := File_Name;
1553 -- Start of processing for First_New_Spec
1557 ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit
1559 exit U_Chk when Units.Table (U).Utype = Is_Body_Only
1560 and then New_Spec (Units.Table (U).Uname);
1562 for W in Units.Table (U).First_With
1564 Units.Table (U).Last_With
1567 Withs.Table (W).Afile /= No_File
1568 and then New_Spec (Withs.Table (W).Uname);
1572 return Spec_File_Name;
1575 ---------------------------------
1576 -- Data declarations for Check --
1577 ---------------------------------
1579 Full_Lib_File : File_Name_Type;
1580 -- Full name of current library file
1582 Full_Obj_File : File_Name_Type;
1583 -- Full name of the object file corresponding to Lib_File
1585 Lib_Stamp : Time_Stamp_Type;
1586 -- Time stamp of the current ada library file
1588 Obj_Stamp : Time_Stamp_Type;
1589 -- Time stamp of the current object file
1591 Modified_Source : File_Name_Type;
1592 -- The first source in Lib_File whose current time stamp differs
1593 -- from that stored in Lib_File.
1595 New_Spec : File_Name_Type;
1596 -- If Lib_File contains in its W (with) section a body (for a
1597 -- subprogram) for which there exists a spec and the spec did not
1598 -- appear in the Sdep section of Lib_File, New_Spec contains the file
1599 -- name of this new spec.
1601 Source_Name : File_Name_Type;
1602 Text : Text_Buffer_Ptr;
1604 Prev_Switch : String_Access;
1605 -- Previous switch processed
1607 Arg : Arg_Id := Arg_Id'First;
1608 -- Current index in Args.Table for a given unit (init to stop warning)
1610 Switch_Found : Boolean;
1611 -- True if a given switch has been found
1613 ALI_Project : Project_Id;
1614 -- If the ALI file is in the object directory of a project, this is
1617 -- Start of processing for Check
1620 pragma Assert (Lib_File /= No_File);
1622 -- If ALI file is read-only, temporarily set Check_Object_Consistency to
1623 -- False. We don't care if the object file is not there (presumably a
1624 -- library will be used for linking.)
1628 Saved_Check_Object_Consistency : constant Boolean :=
1629 Check_Object_Consistency;
1631 Check_Object_Consistency := False;
1632 Text := Read_Library_Info (Lib_File);
1633 Check_Object_Consistency := Saved_Check_Object_Consistency;
1637 Text := Read_Library_Info (Lib_File);
1640 Full_Lib_File := Full_Library_Info_Name;
1641 Full_Obj_File := Full_Object_File_Name;
1642 Lib_Stamp := Current_Library_File_Stamp;
1643 Obj_Stamp := Current_Object_File_Stamp;
1645 if Full_Lib_File = No_File then
1648 "being checked ...",
1650 Minimum_Verbosity => Opt.Medium);
1654 "being checked ...",
1656 Minimum_Verbosity => Opt.Medium);
1660 O_File := Full_Obj_File;
1661 O_Stamp := Obj_Stamp;
1664 if Full_Lib_File = No_File then
1665 Verbose_Msg (Lib_File, "missing.");
1667 elsif Obj_Stamp (Obj_Stamp'First) = ' ' then
1668 Verbose_Msg (Full_Obj_File, "missing.");
1672 (Full_Lib_File, "(" & String (Lib_Stamp) & ") newer than",
1673 Full_Obj_File, "(" & String (Obj_Stamp) & ")");
1677 ALI := Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
1680 if ALI = No_ALI_Id then
1681 Verbose_Msg (Full_Lib_File, "incorrectly formatted ALI file");
1684 elsif ALIs.Table (ALI).Ver (1 .. ALIs.Table (ALI).Ver_Len) /=
1685 Verbose_Library_Version
1687 Verbose_Msg (Full_Lib_File, "compiled with old GNAT version");
1692 -- Don't take Ali file into account if it was generated with
1695 if ALIs.Table (ALI).Compile_Errors then
1696 Verbose_Msg (Full_Lib_File, "had errors, must be recompiled");
1701 -- Don't take Ali file into account if it was generated without
1704 if Operating_Mode /= Check_Semantics
1705 and then ALIs.Table (ALI).No_Object
1707 Verbose_Msg (Full_Lib_File, "has no corresponding object");
1712 -- Check for matching compiler switches if needed
1714 if Check_Switches then
1716 -- First, collect all the switches
1719 (Source_File, Source_Index, Is_Main_Source, The_Args);
1721 Prev_Switch := Dummy_Switch;
1723 Get_Name_String (ALIs.Table (ALI).Sfile);
1725 Switches_To_Check.Set_Last (0);
1727 for J in 1 .. Last_Argument loop
1729 -- Skip non switches -c, -I and -o switches
1731 if Arguments (J) (1) = '-'
1732 and then Arguments (J) (2) /= 'c'
1733 and then Arguments (J) (2) /= 'o'
1734 and then Arguments (J) (2) /= 'I'
1736 Normalize_Compiler_Switches
1738 Normalized_Switches,
1741 for K in 1 .. Last_Norm_Switch loop
1742 Switches_To_Check.Increment_Last;
1743 Switches_To_Check.Table (Switches_To_Check.Last) :=
1744 Normalized_Switches (K);
1749 for J in 1 .. Switches_To_Check.Last loop
1751 -- Comparing switches is delicate because gcc reorders a number
1752 -- of switches, according to lang-specs.h, but gnatmake doesn't
1753 -- have sufficient knowledge to perform the same reordering.
1754 -- Instead, we ignore orders between different "first letter"
1755 -- switches, but keep orders between same switches, e.g -O -O2
1756 -- is different than -O2 -O, but -g -O is equivalent to -O -g.
1758 if Switches_To_Check.Table (J) (2) /= Prev_Switch (2) or else
1759 (Prev_Switch'Length >= 6 and then
1760 Prev_Switch (2 .. 5) = "gnat" and then
1761 Switches_To_Check.Table (J)'Length >= 6 and then
1762 Switches_To_Check.Table (J) (2 .. 5) = "gnat" and then
1763 Prev_Switch (6) /= Switches_To_Check.Table (J) (6))
1765 Prev_Switch := Switches_To_Check.Table (J);
1767 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg;
1770 Switch_Found := False;
1773 Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1776 Switches_To_Check.Table (J).all = Args.Table (K).all
1779 Switch_Found := True;
1784 if not Switch_Found then
1785 if Verbose_Mode then
1786 Verbose_Msg (ALIs.Table (ALI).Sfile,
1787 "switch mismatch """ &
1788 Switches_To_Check.Table (J).all & '"');
1796 if Switches_To_Check.Last /=
1797 Integer (Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg -
1798 Units.Table (ALIs.Table (ALI).First_Unit).First_Arg + 1)
1800 if Verbose_Mode then
1801 Verbose_Msg (ALIs.Table (ALI).Sfile,
1802 "different number of switches");
1804 for K in Units.Table (ALIs.Table (ALI).First_Unit).First_Arg
1805 .. Units.Table (ALIs.Table (ALI).First_Unit).Last_Arg
1807 Write_Str (Args.Table (K).all);
1813 for J in 1 .. Switches_To_Check.Last loop
1814 Write_Str (Switches_To_Check.Table (J).all);
1826 -- Get the source files and their message digests. Note that some
1827 -- sources may be missing if ALI is out-of-date.
1829 Set_Source_Table (ALI);
1831 Modified_Source := Time_Stamp_Mismatch (ALI, Read_Only);
1833 if Modified_Source /= No_File then
1836 if Verbose_Mode then
1837 Source_Name := Full_Source_Name (Modified_Source);
1839 if Source_Name /= No_File then
1840 Verbose_Msg (Source_Name, "time stamp mismatch");
1842 Verbose_Msg (Modified_Source, "missing");
1847 New_Spec := First_New_Spec (ALI);
1849 if New_Spec /= No_File then
1852 if Verbose_Mode then
1853 Source_Name := Full_Source_Name (New_Spec);
1855 if Source_Name /= No_File then
1856 Verbose_Msg (Source_Name, "new spec");
1858 Verbose_Msg (New_Spec, "old spec missing");
1862 elsif not Read_Only and then Main_Project /= No_Project then
1864 -- Check if a file name does not correspond to the mapping of
1865 -- units to file names.
1870 Unit_Name : Name_Id;
1874 for U in ALIs.Table (ALI).First_Unit ..
1875 ALIs.Table (ALI).Last_Unit
1877 -- Check if the file name is one of the source of the
1880 Get_Name_String (Units.Table (U).Uname);
1881 Name_Len := Name_Len - 2;
1882 Unit_Name := Name_Find;
1884 if File_Not_A_Source_Of
1885 (Unit_Name, Units.Table (U).Sfile)
1891 -- Do the same check for each of the withed units
1894 for W in Units.Table (U).First_With
1896 Units.Table (U).Last_With
1898 WR := Withs.Table (W);
1900 if WR.Sfile /= No_File then
1901 Get_Name_String (WR.Uname);
1902 Name_Len := Name_Len - 2;
1903 Unit_Name := Name_Find;
1905 if File_Not_A_Source_Of (Unit_Name, WR.Sfile) then
1913 -- Check also the subunits
1916 for D in ALIs.Table (ALI).First_Sdep ..
1917 ALIs.Table (ALI).Last_Sdep
1919 SD := Sdep.Table (D);
1920 Unit_Name := SD.Subunit_Name;
1922 if Unit_Name /= No_Name then
1923 if File_Not_A_Source_Of (Unit_Name, SD.Sfile) then
1931 -- Check that the ALI file is in the correct object directory.
1932 -- If it is in the object directory of a project that is
1933 -- extended and it depends on a source that is in one of its
1934 -- extending projects, then the ALI file is not in the correct
1935 -- object directory.
1937 -- First, find the project of this ALI file. As there may be
1938 -- several projects with the same object directory, we first
1939 -- need to find the project of the source.
1941 ALI_Project := No_Project;
1944 Udata : Prj.Unit_Data;
1947 for U in 1 .. Unit_Table.Last (Project_Tree.Units) loop
1948 Udata := Project_Tree.Units.Table (U);
1950 if Udata.File_Names (Body_Part).Name = Source_File then
1951 ALI_Project := Udata.File_Names (Body_Part).Project;
1955 Udata.File_Names (Specification).Name = Source_File
1958 Udata.File_Names (Specification).Project;
1964 if ALI_Project = No_Project then
1969 Obj_Dir : Path_Name_Type;
1970 Res_Obj_Dir : constant String :=
1973 (Get_Name_String (Full_Lib_File)),
1974 Resolve_Links => True,
1975 Case_Sensitive => False);
1979 Add_Str_To_Name_Buffer (Res_Obj_Dir);
1981 if Name_Len > 1 and then
1982 (Name_Buffer (Name_Len) = '/'
1984 Name_Buffer (Name_Len) = Directory_Separator)
1986 Name_Len := Name_Len - 1;
1989 Obj_Dir := Name_Find;
1991 while ALI_Project /= No_Project and then
1993 Project_Tree.Projects.Table
1994 (ALI_Project).Object_Directory.Name
1997 Project_Tree.Projects.Table (ALI_Project).Extended_By;
2001 if ALI_Project = No_Project then
2005 (Lib_File, " wrong object directory");
2009 -- If the ALI project is not extended, then it must be in
2010 -- the correct object directory.
2012 if Project_Tree.Projects.Table (ALI_Project).Extended_By =
2018 -- Count the extending projects
2026 Proj := ALI_Project;
2028 Proj := Project_Tree.Projects.Table (Proj).Extended_By;
2029 exit when Proj = No_Project;
2030 Num_Ext := Num_Ext + 1;
2033 -- Make a list of the extending projects
2036 Projects : array (1 .. Num_Ext) of Project_Id;
2038 OK : Boolean := True;
2041 Proj := ALI_Project;
2042 for J in Projects'Range loop
2043 Proj := Project_Tree.Projects.Table (Proj).Extended_By;
2044 Projects (J) := Proj;
2047 -- Now check if any of the dependant sources are in
2048 -- any of these extending projects.
2051 for D in ALIs.Table (ALI).First_Sdep ..
2052 ALIs.Table (ALI).Last_Sdep
2054 Dep := Sdep.Table (D);
2060 UID in 1 .. Unit_Table.Last (Project_Tree.Units)
2062 if Project_Tree.Units.Table (UID).
2063 File_Names (Body_Part).Name = Dep.Sfile
2065 Proj := Project_Tree.Units.Table (UID).
2066 File_Names (Body_Part).Project;
2068 elsif Project_Tree.Units.Table (UID).
2069 File_Names (Specification).Name = Dep.Sfile
2071 Proj := Project_Tree.Units.Table (UID).
2072 File_Names (Specification).Project;
2075 -- If a source is in a project, check if it is one
2078 if Proj /= No_Project then
2079 for J in Projects'Range loop
2080 if Proj = Projects (J) then
2091 -- If one of the dependent sources is in one project of
2092 -- the list, then we must recompile.
2096 Verbose_Msg (Lib_File, " wrong object directory");
2105 ------------------------
2106 -- Check_For_S_Switch --
2107 ------------------------
2109 procedure Check_For_S_Switch is
2111 -- By default, we generate an object file
2113 Output_Is_Object := True;
2115 for Arg in 1 .. Last_Argument loop
2116 if Arguments (Arg).all = "-S" then
2117 Output_Is_Object := False;
2119 elsif Arguments (Arg).all = "-c" then
2120 Output_Is_Object := True;
2123 end Check_For_S_Switch;
2125 --------------------------
2126 -- Check_Linker_Options --
2127 --------------------------
2129 procedure Check_Linker_Options
2130 (E_Stamp : Time_Stamp_Type;
2131 O_File : out File_Name_Type;
2132 O_Stamp : out Time_Stamp_Type)
2134 procedure Check_File (File : File_Name_Type);
2135 -- Update O_File and O_Stamp if the given file is younger than E_Stamp
2136 -- and O_Stamp, or if O_File is No_File and File does not exist.
2138 function Get_Library_File (Name : String) return File_Name_Type;
2139 -- Return the full file name including path of a library based
2140 -- on the name specified with the -l linker option, using the
2141 -- Ada object path. Return No_File if no such file can be found.
2143 type Char_Array is array (Natural) of Character;
2144 type Char_Array_Access is access constant Char_Array;
2146 Template : Char_Array_Access;
2147 pragma Import (C, Template, "__gnat_library_template");
2153 procedure Check_File (File : File_Name_Type) is
2154 Stamp : Time_Stamp_Type;
2155 Name : File_Name_Type := File;
2158 Get_Name_String (Name);
2160 -- Remove any trailing NUL characters
2162 while Name_Len >= Name_Buffer'First
2163 and then Name_Buffer (Name_Len) = NUL
2165 Name_Len := Name_Len - 1;
2168 if Name_Len = 0 then
2171 elsif Name_Buffer (1) = '-' then
2173 -- Do not check if File is a switch other than "-l"
2175 if Name_Buffer (2) /= 'l' then
2179 -- The argument is a library switch, get actual name. It
2180 -- is necessary to make a copy of the relevant part of
2181 -- Name_Buffer as Get_Library_Name uses Name_Buffer as well.
2184 Base_Name : constant String := Name_Buffer (3 .. Name_Len);
2187 Name := Get_Library_File (Base_Name);
2190 if Name = No_File then
2195 Stamp := File_Stamp (Name);
2197 -- Find the youngest object file that is younger than the
2198 -- executable. If no such file exist, record the first object
2199 -- file that is not found.
2201 if (O_Stamp < Stamp and then E_Stamp < Stamp)
2202 or else (O_File = No_File and then Stamp (Stamp'First) = ' ')
2207 -- Strip the trailing NUL if present
2209 Get_Name_String (O_File);
2211 if Name_Buffer (Name_Len) = NUL then
2212 Name_Len := Name_Len - 1;
2213 O_File := Name_Find;
2218 ----------------------
2219 -- Get_Library_Name --
2220 ----------------------
2222 -- See comments in a-adaint.c about template syntax
2224 function Get_Library_File (Name : String) return File_Name_Type is
2225 File : File_Name_Type := No_File;
2230 for Ptr in Template'Range loop
2231 case Template (Ptr) is
2233 Add_Str_To_Name_Buffer (Name);
2236 File := Full_Lib_File_Name (Name_Find);
2237 exit when File /= No_File;
2244 Add_Char_To_Name_Buffer (Template (Ptr));
2248 -- The for loop exited because the end of the template
2249 -- was reached. File contains the last possible file name
2252 if File = No_File and then Name_Len > 0 then
2253 File := Full_Lib_File_Name (Name_Find);
2257 end Get_Library_File;
2259 -- Start of processing for Check_Linker_Options
2263 O_Stamp := (others => ' ');
2265 -- Process linker options from the ALI files
2267 for Opt in 1 .. Linker_Options.Last loop
2268 Check_File (File_Name_Type (Linker_Options.Table (Opt).Name));
2271 -- Process options given on the command line
2273 for Opt in Linker_Switches.First .. Linker_Switches.Last loop
2275 -- Check if the previous Opt has one of the two switches
2276 -- that take an extra parameter. (See GCC manual.)
2278 if Opt = Linker_Switches.First
2279 or else (Linker_Switches.Table (Opt - 1).all /= "-u"
2281 Linker_Switches.Table (Opt - 1).all /= "-Xlinker"
2283 Linker_Switches.Table (Opt - 1).all /= "-L")
2286 Add_Str_To_Name_Buffer (Linker_Switches.Table (Opt).all);
2287 Check_File (Name_Find);
2291 end Check_Linker_Options;
2297 procedure Check_Steps is
2299 -- If either -c, -b or -l has been specified, we will not necessarily
2300 -- execute all steps.
2303 Do_Compile_Step := Do_Compile_Step and Compile_Only;
2304 Do_Bind_Step := Do_Bind_Step and Bind_Only;
2305 Do_Link_Step := Do_Link_Step and Link_Only;
2307 -- If -c has been specified, but not -b, ignore any potential -l
2309 if Do_Compile_Step and then not Do_Bind_Step then
2310 Do_Link_Step := False;
2315 -----------------------
2316 -- Collect_Arguments --
2317 -----------------------
2319 procedure Collect_Arguments
2320 (Source_File : File_Name_Type;
2322 Is_Main_Source : Boolean;
2323 Args : Argument_List)
2326 Arguments_Collected := True;
2327 Arguments_Project := No_Project;
2329 Add_Arguments (Args);
2331 if Main_Project /= No_Project then
2333 Source_File_Name : constant String :=
2334 Get_Name_String (Source_File);
2335 Compiler_Package : Prj.Package_Id;
2336 Switches : Prj.Variable_Value;
2337 Data : Project_Data;
2342 (Source_File_Name => Source_File_Name,
2343 Project => Arguments_Project,
2344 Path => Arguments_Path_Name,
2345 In_Tree => Project_Tree);
2347 -- If the source is not a source of a project file, add the
2348 -- recorded arguments. Check will be done later if the source
2349 -- need to be compiled that the switch -x has been used.
2351 if Arguments_Project = No_Project then
2352 Add_Arguments (The_Saved_Gcc_Switches.all);
2354 elsif not Project_Tree.Projects.Table
2355 (Arguments_Project).Externally_Built
2357 -- We get the project directory for the relative path
2358 -- switches and arguments.
2360 Data := Project_Tree.Projects.Table (Arguments_Project);
2362 -- If the source is in an extended project, we go to
2363 -- the ultimate extending project.
2365 while Data.Extended_By /= No_Project loop
2366 Arguments_Project := Data.Extended_By;
2367 Data := Project_Tree.Projects.Table (Arguments_Project);
2370 -- If building a dynamic or relocatable library, compile with
2371 -- PIC option, if it exists.
2373 if Data.Library and then Data.Library_Kind /= Static then
2375 PIC : constant String := MLib.Tgt.PIC_Option;
2379 Add_Arguments ((1 => new String'(PIC)));
2384 if Data.Dir_Path = null then
2386 new String'(Get_Name_String (Data.Directory.Display_Name));
2387 Project_Tree.Projects.Table (Arguments_Project) :=
2391 -- We now look for package Compiler and get the switches from
2396 (Name => Name_Compiler,
2397 In_Packages => Data.Decl.Packages,
2398 In_Tree => Project_Tree);
2400 if Compiler_Package /= No_Package then
2402 -- If package Gnatmake.Compiler exists, we get the specific
2403 -- switches for the current source, or the global switches,
2408 (Source_File => Source_File,
2409 Source_File_Name => Source_File_Name,
2410 Source_Index => Source_Index,
2411 Naming => Data.Naming,
2412 In_Package => Compiler_Package,
2413 Allow_ALI => False);
2417 case Switches.Kind is
2419 -- We have a list of switches. We add these switches,
2420 -- plus the saved gcc switches.
2425 Current : String_List_Id := Switches.Values;
2426 Element : String_Element;
2427 Number : Natural := 0;
2430 while Current /= Nil_String loop
2431 Element := Project_Tree.String_Elements.
2433 Number := Number + 1;
2434 Current := Element.Next;
2438 New_Args : Argument_List (1 .. Number);
2439 Last_New : Natural := 0;
2442 Current := Switches.Values;
2444 for Index in New_Args'Range loop
2445 Element := Project_Tree.String_Elements.
2447 Get_Name_String (Element.Value);
2449 if Name_Len > 0 then
2450 Last_New := Last_New + 1;
2451 New_Args (Last_New) :=
2452 new String'(Name_Buffer (1 .. Name_Len));
2453 Test_If_Relative_Path
2454 (New_Args (Last_New),
2455 Parent => Data.Dir_Path,
2456 Including_Non_Switch => False);
2459 Current := Element.Next;
2463 (Configuration_Pragmas_Switch
2464 (Arguments_Project) &
2465 New_Args (1 .. Last_New) &
2466 The_Saved_Gcc_Switches.all);
2470 -- We have a single switch. We add this switch,
2471 -- plus the saved gcc switches.
2474 Get_Name_String (Switches.Value);
2477 New_Args : Argument_List :=
2479 (Name_Buffer (1 .. Name_Len)));
2482 Test_If_Relative_Path
2484 Parent => Data.Dir_Path,
2485 Including_Non_Switch => False);
2487 (Configuration_Pragmas_Switch (Arguments_Project) &
2488 New_Args & The_Saved_Gcc_Switches.all);
2491 -- We have no switches from Gnatmake.Compiler.
2492 -- We add the saved gcc switches.
2496 (Configuration_Pragmas_Switch (Arguments_Project) &
2497 The_Saved_Gcc_Switches.all);
2503 -- For VMS, when compiling the main source, add switch
2504 -- -mdebug-main=_ada_ so that the executable can be debugged
2505 -- by the standard VMS debugger.
2507 if not No_Main_Subprogram
2508 and then Targparm.OpenVMS_On_Target
2509 and then Is_Main_Source
2511 -- First, check if compilation will be invoked with -g
2513 for J in 1 .. Last_Argument loop
2514 if Arguments (J)'Length >= 2
2515 and then Arguments (J) (1 .. 2) = "-g"
2516 and then (Arguments (J)'Length < 5
2517 or else Arguments (J) (1 .. 5) /= "-gnat")
2520 ((1 => new String'("-mdebug-main=_ada_")));
2526 -- Set Output_Is_Object, depending if there is a -S switch.
2527 -- If the bind step is not performed, and there is a -S switch,
2528 -- then we will not check for a valid object file.
2531 end Collect_Arguments;
2533 ---------------------
2534 -- Compile_Sources --
2535 ---------------------
2537 procedure Compile_Sources
2538 (Main_Source : File_Name_Type;
2539 Args : Argument_List;
2540 First_Compiled_File : out File_Name_Type;
2541 Most_Recent_Obj_File : out File_Name_Type;
2542 Most_Recent_Obj_Stamp : out Time_Stamp_Type;
2543 Main_Unit : out Boolean;
2544 Compilation_Failures : out Natural;
2545 Main_Index : Int := 0;
2546 Check_Readonly_Files : Boolean := False;
2547 Do_Not_Execute : Boolean := False;
2548 Force_Compilations : Boolean := False;
2549 Keep_Going : Boolean := False;
2550 In_Place_Mode : Boolean := False;
2551 Initialize_ALI_Data : Boolean := True;
2552 Max_Process : Positive := 1)
2554 Source_Unit : Unit_Name_Type;
2555 -- Current source unit
2557 Source_File : File_Name_Type;
2558 -- Current source file
2560 Full_Source_File : File_Name_Type;
2561 -- Full name of the current source file
2563 Lib_File : File_Name_Type;
2564 -- Current library file
2566 Full_Lib_File : File_Name_Type;
2567 -- Full name of the current library file
2569 Obj_File : File_Name_Type;
2570 -- Full name of the object file corresponding to Lib_File
2572 Obj_Stamp : Time_Stamp_Type;
2573 -- Time stamp of the current object file
2575 Sfile : File_Name_Type;
2576 -- Contains the source file of the units withed by Source_File
2578 Uname : Unit_Name_Type;
2579 -- Contains the unit name of the units withed by Source_File
2582 -- ALI Id of the current ALI file
2584 -- Comment following declarations ???
2586 Read_Only : Boolean := False;
2588 Compilation_OK : Boolean;
2589 Need_To_Compile : Boolean;
2592 Text : Text_Buffer_Ptr;
2594 Mfile : Natural := No_Mapping_File;
2596 Need_To_Check_Standard_Library : Boolean :=
2597 Check_Readonly_Files
2598 and not Unique_Compile;
2600 Mapping_File_Arg : String_Access;
2602 Process_Created : Boolean := False;
2604 procedure Add_Process
2606 Sfile : File_Name_Type;
2607 Afile : File_Name_Type;
2608 Uname : Unit_Name_Type;
2609 Mfile : Natural := No_Mapping_File);
2610 -- Adds process Pid to the current list of outstanding compilation
2611 -- processes and record the full name of the source file Sfile that
2612 -- we are compiling, the name of its library file Afile and the
2613 -- name of its unit Uname. If Mfile is not equal to No_Mapping_File,
2614 -- it is the index of the mapping file used during compilation in the
2615 -- array The_Mapping_File_Names.
2617 procedure Await_Compile
2618 (Sfile : out File_Name_Type;
2619 Afile : out File_Name_Type;
2620 Uname : out Unit_Name_Type;
2622 -- Awaits that an outstanding compilation process terminates. When
2623 -- it does set Sfile to the name of the source file that was compiled
2624 -- Afile to the name of its library file and Uname to the name of its
2625 -- unit. Note that this time stamp can be used to check whether the
2626 -- compilation did generate an object file. OK is set to True if the
2627 -- compilation succeeded. Note that Sfile, Afile and Uname could be
2628 -- resp. No_File, No_File and No_Name if there were no compilations
2631 function Bad_Compilation_Count return Natural;
2632 -- Returns the number of compilation failures
2634 procedure Check_Standard_Library;
2635 -- Check if s-stalib.adb needs to be compiled
2637 procedure Collect_Arguments_And_Compile
2638 (Source_File : File_Name_Type;
2639 Source_Index : Int);
2640 -- Collect arguments from project file (if any) and compile
2643 (S : File_Name_Type;
2646 Args : Argument_List) return Process_Id;
2647 -- Compiles S using Args. If S is a GNAT predefined source "-gnatpg" is
2648 -- added to Args. Non blocking call. L corresponds to the expected
2649 -- library file name. Process_Id of the process spawned to execute the
2652 package Good_ALI is new Table.Table (
2653 Table_Component_Type => ALI_Id,
2654 Table_Index_Type => Natural,
2655 Table_Low_Bound => 1,
2656 Table_Initial => 50,
2657 Table_Increment => 100,
2658 Table_Name => "Make.Good_ALI");
2659 -- Contains the set of valid ALI files that have not yet been scanned
2661 function Good_ALI_Present return Boolean;
2662 -- Returns True if any ALI file was recorded in the previous set
2664 procedure Get_Mapping_File (Project : Project_Id);
2665 -- Get a mapping file name. If there is one to be reused, reuse it.
2666 -- Otherwise, create a new mapping file.
2668 function Get_Next_Good_ALI return ALI_Id;
2669 -- Returns the next good ALI_Id record
2671 procedure Record_Failure
2672 (File : File_Name_Type;
2673 Unit : Unit_Name_Type;
2674 Found : Boolean := True);
2675 -- Records in the previous table that the compilation for File failed.
2676 -- If Found is False then the compilation of File failed because we
2677 -- could not find it. Records also Unit when possible.
2679 procedure Record_Good_ALI (A : ALI_Id);
2680 -- Records in the previous set the Id of an ALI file
2686 procedure Add_Process
2688 Sfile : File_Name_Type;
2689 Afile : File_Name_Type;
2690 Uname : Unit_Name_Type;
2691 Mfile : Natural := No_Mapping_File)
2693 OC1 : constant Positive := Outstanding_Compiles + 1;
2696 pragma Assert (OC1 <= Max_Process);
2697 pragma Assert (Pid /= Invalid_Pid);
2699 Running_Compile (OC1).Pid := Pid;
2700 Running_Compile (OC1).Full_Source_File := Sfile;
2701 Running_Compile (OC1).Lib_File := Afile;
2702 Running_Compile (OC1).Source_Unit := Uname;
2703 Running_Compile (OC1).Mapping_File := Mfile;
2704 Running_Compile (OC1).Project := Arguments_Project;
2705 Running_Compile (OC1).Syntax_Only := Syntax_Only;
2706 Running_Compile (OC1).Output_Is_Object := Output_Is_Object;
2708 Outstanding_Compiles := OC1;
2711 --------------------
2715 procedure Await_Compile
2716 (Sfile : out File_Name_Type;
2717 Afile : out File_Name_Type;
2718 Uname : out Unit_Name_Type;
2722 Project : Project_Id;
2725 pragma Assert (Outstanding_Compiles > 0);
2729 Uname := No_Unit_Name;
2732 -- The loop here is a work-around for a problem on VMS; in some
2733 -- circumstances (shared library and several executables, for
2734 -- example), there are child processes other than compilation
2735 -- processes that are received. Until this problem is resolved,
2736 -- we will ignore such processes.
2739 Wait_Process (Pid, OK);
2741 if Pid = Invalid_Pid then
2745 for J in Running_Compile'First .. Outstanding_Compiles loop
2746 if Pid = Running_Compile (J).Pid then
2747 Sfile := Running_Compile (J).Full_Source_File;
2748 Afile := Running_Compile (J).Lib_File;
2749 Uname := Running_Compile (J).Source_Unit;
2750 Syntax_Only := Running_Compile (J).Syntax_Only;
2751 Output_Is_Object := Running_Compile (J).Output_Is_Object;
2752 Project := Running_Compile (J).Project;
2754 -- If a mapping file was used by this compilation,
2755 -- get its file name for reuse by a subsequent compilation
2757 if Running_Compile (J).Mapping_File /= No_Mapping_File then
2758 Last_Free_Indices (Project) :=
2759 Last_Free_Indices (Project) + 1;
2760 The_Free_Mapping_File_Indices
2761 (Project, Last_Free_Indices (Project)) :=
2762 Running_Compile (J).Mapping_File;
2765 -- To actually remove this Pid and related info from
2766 -- Running_Compile replace its entry with the last valid
2767 -- entry in Running_Compile.
2769 if J = Outstanding_Compiles then
2773 Running_Compile (J) :=
2774 Running_Compile (Outstanding_Compiles);
2777 Outstanding_Compiles := Outstanding_Compiles - 1;
2782 -- This child process was not one of our compilation processes;
2783 -- just ignore it for now.
2785 -- raise Program_Error;
2789 ---------------------------
2790 -- Bad_Compilation_Count --
2791 ---------------------------
2793 function Bad_Compilation_Count return Natural is
2795 return Bad_Compilation.Last - Bad_Compilation.First + 1;
2796 end Bad_Compilation_Count;
2798 ----------------------------
2799 -- Check_Standard_Library --
2800 ----------------------------
2802 procedure Check_Standard_Library is
2804 Need_To_Check_Standard_Library := False;
2806 if not Targparm.Suppress_Standard_Library_On_Target then
2808 Sfile : File_Name_Type;
2809 Add_It : Boolean := True;
2812 Name_Len := Standard_Library_Package_Body_Name'Length;
2813 Name_Buffer (1 .. Name_Len) :=
2814 Standard_Library_Package_Body_Name;
2815 Sfile := Name_Enter;
2817 -- If we have a special runtime, we add the standard
2818 -- library only if we can find it.
2822 Find_File (Sfile, Osint.Source) /= No_File;
2826 if Is_Marked (Sfile) then
2827 if Is_In_Obsoleted (Sfile) then
2828 Executable_Obsolete := True;
2832 Insert_Q (Sfile, Index => 0);
2833 Mark (Sfile, Index => 0);
2838 end Check_Standard_Library;
2840 -----------------------------------
2841 -- Collect_Arguments_And_Compile --
2842 -----------------------------------
2844 procedure Collect_Arguments_And_Compile
2845 (Source_File : File_Name_Type;
2849 -- Process_Created will be set True if an attempt is made to compile
2850 -- the source, that is if it is not in an externally built project.
2852 Process_Created := False;
2854 -- If arguments not yet collected (in Check), collect them now
2856 if not Arguments_Collected then
2858 (Source_File, Source_Index, Source_File = Main_Source, Args);
2861 -- If we use mapping file (-P or -C switches), then get one
2863 if Create_Mapping_File then
2864 Get_Mapping_File (Arguments_Project);
2867 -- If the source is part of a project file, we set the ADA_*_PATHs,
2868 -- check for an eventual library project, and use the full path.
2870 if Arguments_Project /= No_Project then
2871 if not Project_Tree.Projects.Table
2872 (Arguments_Project).Externally_Built
2874 Prj.Env.Set_Ada_Paths (Arguments_Project, Project_Tree, True);
2876 if not Unique_Compile
2877 and then MLib.Tgt.Support_For_Libraries /= Prj.None
2880 The_Data : Project_Data :=
2881 Project_Tree.Projects.Table
2882 (Arguments_Project);
2884 Prj : Project_Id := Arguments_Project;
2887 while The_Data.Extended_By /= No_Project loop
2888 Prj := The_Data.Extended_By;
2889 The_Data := Project_Tree.Projects.Table (Prj);
2893 and then not The_Data.Externally_Built
2894 and then not The_Data.Need_To_Build_Lib
2896 -- Add to the Q all sources of the project that
2897 -- have not been marked
2899 Insert_Project_Sources
2900 (The_Project => Prj,
2901 All_Projects => False,
2904 -- Now mark the project as processed
2906 Project_Tree.Projects.Table
2907 (Prj).Need_To_Build_Lib := True;
2912 -- Change to the object directory of the project file,
2915 Change_To_Object_Directory (Arguments_Project);
2919 (File_Name_Type (Arguments_Path_Name),
2922 Arguments (1 .. Last_Argument));
2923 Process_Created := True;
2927 -- If this is a source outside of any project file, make sure it
2928 -- will be compiled in object directory of the main project file.
2930 if Main_Project /= No_Project then
2931 Change_To_Object_Directory (Arguments_Project);
2934 Pid := Compile (Full_Source_File, Lib_File, Source_Index,
2935 Arguments (1 .. Last_Argument));
2936 Process_Created := True;
2938 end Collect_Arguments_And_Compile;
2945 (S : File_Name_Type;
2948 Args : Argument_List) return Process_Id
2950 Comp_Args : Argument_List (Args'First .. Args'Last + 10);
2951 Comp_Next : Integer := Args'First;
2952 Comp_Last : Integer;
2953 Arg_Index : Integer;
2955 function Ada_File_Name (Name : File_Name_Type) return Boolean;
2956 -- Returns True if Name is the name of an ada source file
2957 -- (i.e. suffix is .ads or .adb)
2963 function Ada_File_Name (Name : File_Name_Type) return Boolean is
2965 Get_Name_String (Name);
2968 and then Name_Buffer (Name_Len - 3 .. Name_Len - 1) = ".ad"
2969 and then (Name_Buffer (Name_Len) = 'b'
2971 Name_Buffer (Name_Len) = 's');
2974 -- Start of processing for Compile
2977 Enter_Into_Obsoleted (S);
2979 -- By default, Syntax_Only is False
2981 Syntax_Only := False;
2983 for J in Args'Range loop
2984 if Args (J).all = "-gnats" then
2986 -- If we compile with -gnats, the bind step and the link step
2987 -- are inhibited. Also, we set Syntax_Only to True, so that
2988 -- we don't fail when we don't find the ALI file, after
2991 Do_Bind_Step := False;
2992 Do_Link_Step := False;
2993 Syntax_Only := True;
2995 elsif Args (J).all = "-gnatc" then
2997 -- If we compile with -gnatc, the bind step and the link step
2998 -- are inhibited. We set Syntax_Only to False for the case when
2999 -- -gnats was previously specified.
3001 Do_Bind_Step := False;
3002 Do_Link_Step := False;
3003 Syntax_Only := False;
3007 Comp_Args (Comp_Next) := new String'("-gnatea");
3008 Comp_Next := Comp_Next + 1;
3010 Comp_Args (Comp_Next) := Comp_Flag;
3011 Comp_Next := Comp_Next + 1;
3013 -- Optimize the simple case where the gcc command line looks like
3014 -- gcc -c -I. ... -I- file.adb --into-> gcc -c ... file.adb
3016 if Args (Args'First).all = "-I" & Normalized_CWD
3017 and then Args (Args'Last).all = "-I-"
3018 and then S = Strip_Directory (S)
3020 Comp_Last := Comp_Next + Args'Length - 3;
3021 Arg_Index := Args'First + 1;
3024 Comp_Last := Comp_Next + Args'Length - 1;
3025 Arg_Index := Args'First;
3028 -- Make a deep copy of the arguments, because Normalize_Arguments
3029 -- may deallocate some arguments.
3031 for J in Comp_Next .. Comp_Last loop
3032 Comp_Args (J) := new String'(Args (Arg_Index).all);
3033 Arg_Index := Arg_Index + 1;
3036 -- Set -gnatpg for predefined files (for this purpose the renamings
3037 -- such as Text_IO do not count as predefined). Note that we strip
3038 -- the directory name from the source file name because the call to
3039 -- Fname.Is_Predefined_File_Name cannot deal with directory prefixes.
3042 Fname : constant File_Name_Type := Strip_Directory (S);
3045 if Is_Predefined_File_Name (Fname, False) then
3046 if Check_Readonly_Files then
3047 Comp_Args (Comp_Args'First + 2 .. Comp_Last + 1) :=
3048 Comp_Args (Comp_Args'First + 1 .. Comp_Last);
3049 Comp_Last := Comp_Last + 1;
3050 Comp_Args (Comp_Args'First + 1) := GNAT_Flag;
3054 ("not allowed to compile """ &
3055 Get_Name_String (Fname) &
3056 """; use -a switch, or compile file with " &
3057 """-gnatg"" switch");
3062 -- Now check if the file name has one of the suffixes familiar to
3063 -- the gcc driver. If this is not the case then add the ada flag
3066 if not Ada_File_Name (S) and then not Targparm.AAMP_On_Target then
3067 Comp_Last := Comp_Last + 1;
3068 Comp_Args (Comp_Last) := Ada_Flag_1;
3069 Comp_Last := Comp_Last + 1;
3070 Comp_Args (Comp_Last) := Ada_Flag_2;
3073 if Source_Index /= 0 then
3075 Num : constant String := Source_Index'Img;
3077 Comp_Last := Comp_Last + 1;
3078 Comp_Args (Comp_Last) :=
3079 new String'("-gnateI" & Num (Num'First + 1 .. Num'Last));
3083 if Source_Index /= 0
3084 or else L /= Strip_Directory (L)
3085 or else Object_Directory_Path /= null
3087 -- Build -o argument
3089 Get_Name_String (L);
3091 for J in reverse 1 .. Name_Len loop
3092 if Name_Buffer (J) = '.' then
3093 Name_Len := J + Object_Suffix'Length - 1;
3094 Name_Buffer (J .. Name_Len) := Object_Suffix;
3099 Comp_Last := Comp_Last + 1;
3100 Comp_Args (Comp_Last) := Output_Flag;
3101 Comp_Last := Comp_Last + 1;
3103 -- If an object directory was specified, prepend the object file
3104 -- name with this object directory.
3106 if Object_Directory_Path /= null then
3107 Comp_Args (Comp_Last) :=
3108 new String'(Object_Directory_Path.all &
3109 Name_Buffer (1 .. Name_Len));
3112 Comp_Args (Comp_Last) :=
3113 new String'(Name_Buffer (1 .. Name_Len));
3117 if Create_Mapping_File then
3118 Comp_Last := Comp_Last + 1;
3119 Comp_Args (Comp_Last) := Mapping_File_Arg;
3122 Get_Name_String (S);
3124 Comp_Last := Comp_Last + 1;
3125 Comp_Args (Comp_Last) := new String'(Name_Buffer (1 .. Name_Len));
3127 GNAT.OS_Lib.Normalize_Arguments (Comp_Args (Args'First .. Comp_Last));
3129 Comp_Last := Comp_Last + 1;
3130 Comp_Args (Comp_Last) := new String'("-gnatez");
3132 Display (Gcc.all, Comp_Args (Args'First .. Comp_Last));
3134 if Gcc_Path = null then
3135 Make_Failed ("error, unable to locate " & Gcc.all);
3139 GNAT.OS_Lib.Non_Blocking_Spawn
3140 (Gcc_Path.all, Comp_Args (Args'First .. Comp_Last));
3143 ----------------------
3144 -- Get_Mapping_File --
3145 ----------------------
3147 procedure Get_Mapping_File (Project : Project_Id) is
3149 -- If there is a mapping file ready to be reused, reuse it
3151 if Last_Free_Indices (Project) > 0 then
3152 Mfile := The_Free_Mapping_File_Indices
3153 (Project, Last_Free_Indices (Project));
3154 Last_Free_Indices (Project) := Last_Free_Indices (Project) - 1;
3156 -- Otherwise, create and initialize a new one
3159 Init_Mapping_File (Project => Project, File_Index => Mfile);
3162 -- Put the name in the mapping file argument for the invocation
3165 Free (Mapping_File_Arg);
3167 new String'("-gnatem=" &
3169 (The_Mapping_File_Names (Project, Mfile)));
3171 end Get_Mapping_File;
3173 -----------------------
3174 -- Get_Next_Good_ALI --
3175 -----------------------
3177 function Get_Next_Good_ALI return ALI_Id is
3181 pragma Assert (Good_ALI_Present);
3182 ALI := Good_ALI.Table (Good_ALI.Last);
3183 Good_ALI.Decrement_Last;
3185 end Get_Next_Good_ALI;
3187 ----------------------
3188 -- Good_ALI_Present --
3189 ----------------------
3191 function Good_ALI_Present return Boolean is
3193 return Good_ALI.First <= Good_ALI.Last;
3194 end Good_ALI_Present;
3196 --------------------
3197 -- Record_Failure --
3198 --------------------
3200 procedure Record_Failure
3201 (File : File_Name_Type;
3202 Unit : Unit_Name_Type;
3203 Found : Boolean := True)
3206 Bad_Compilation.Increment_Last;
3207 Bad_Compilation.Table (Bad_Compilation.Last) := (File, Unit, Found);
3210 ---------------------
3211 -- Record_Good_ALI --
3212 ---------------------
3214 procedure Record_Good_ALI (A : ALI_Id) is
3216 Good_ALI.Increment_Last;
3217 Good_ALI.Table (Good_ALI.Last) := A;
3218 end Record_Good_ALI;
3220 -- Start of processing for Compile_Sources
3223 pragma Assert (Args'First = 1);
3225 Outstanding_Compiles := 0;
3226 Running_Compile := new Comp_Data_Arr (1 .. Max_Process);
3228 -- Package and Queue initializations
3232 if First_Q_Initialization then
3236 if Initialize_ALI_Data then
3238 Initialize_ALI_Source;
3241 -- The following two flags affect the behavior of ALI.Set_Source_Table.
3242 -- We set Check_Source_Files to True to ensure that source file
3243 -- time stamps are checked, and we set All_Sources to False to
3244 -- avoid checking the presence of the source files listed in the
3245 -- source dependency section of an ali file (which would be a mistake
3246 -- since the ali file may be obsolete).
3248 Check_Source_Files := True;
3249 All_Sources := False;
3251 -- Only insert in the Q if it is not already done, to avoid simultaneous
3252 -- compilations if -jnnn is used.
3254 if not Is_Marked (Main_Source, Main_Index) then
3255 Insert_Q (Main_Source, Index => Main_Index);
3256 Mark (Main_Source, Main_Index);
3259 First_Compiled_File := No_File;
3260 Most_Recent_Obj_File := No_File;
3261 Most_Recent_Obj_Stamp := Empty_Time_Stamp;
3264 -- Keep looping until there is no more work to do (the Q is empty)
3265 -- and all the outstanding compilations have terminated
3267 Make_Loop : while not Empty_Q or else Outstanding_Compiles > 0 loop
3269 -- If the user does not want to keep going in case of errors then
3270 -- wait for the remaining outstanding compiles and then exit.
3272 if Bad_Compilation_Count > 0 and then not Keep_Going then
3273 while Outstanding_Compiles > 0 loop
3275 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
3277 if not Compilation_OK then
3278 Record_Failure (Full_Source_File, Source_Unit);
3285 -- PHASE 1: Check if there is more work that we can do (i.e. the Q
3286 -- is non empty). If there is, do it only if we have not yet used
3287 -- up all the available processes.
3289 if not Empty_Q and then Outstanding_Compiles < Max_Process then
3292 -- Index of the current unit in the current source file
3295 Extract_From_Q (Source_File, Source_Unit, Source_Index);
3296 Full_Source_File := Osint.Full_Source_Name (Source_File);
3297 Lib_File := Osint.Lib_File_Name
3298 (Source_File, Source_Index);
3299 Full_Lib_File := Osint.Full_Lib_File_Name (Lib_File);
3301 -- If this source has already been compiled, the executable is
3304 if Is_In_Obsoleted (Source_File) then
3305 Executable_Obsolete := True;
3308 -- If the library file is an Ada library skip it
3310 if Full_Lib_File /= No_File
3311 and then In_Ada_Lib_Dir (Full_Lib_File)
3315 "is in an Ada library",
3317 Minimum_Verbosity => Opt.High);
3319 -- If the library file is a read-only library skip it, but
3320 -- only if, when using project files, this library file is
3321 -- in the right object directory (a read-only ALI file
3322 -- in the object directory of a project being extended
3323 -- should not be skipped).
3325 elsif Full_Lib_File /= No_File
3326 and then not Check_Readonly_Files
3327 and then Is_Readonly_Library (Full_Lib_File)
3328 and then Is_In_Object_Directory (Source_File, Full_Lib_File)
3332 "is a read-only library",
3334 Minimum_Verbosity => Opt.High);
3336 -- The source file that we are checking cannot be located
3338 elsif Full_Source_File = No_File then
3339 Record_Failure (Source_File, Source_Unit, False);
3341 -- Source and library files can be located but are internal
3344 elsif not Check_Readonly_Files
3345 and then Full_Lib_File /= No_File
3346 and then Is_Internal_File_Name (Source_File, False)
3348 if Force_Compilations then
3350 ("not allowed to compile """ &
3351 Get_Name_String (Source_File) &
3352 """; use -a switch, or compile file with " &
3353 """-gnatg"" switch");
3358 "is an internal library",
3360 Minimum_Verbosity => Opt.High);
3362 -- The source file that we are checking can be located
3365 Arguments_Collected := False;
3367 Collect_Arguments (Source_File, Source_Index,
3368 Source_File = Main_Source, Args);
3370 -- Do nothing if project of source is externally built
3372 if Arguments_Project = No_Project
3373 or else not Project_Tree.Projects.Table
3374 (Arguments_Project).Externally_Built
3376 -- Don't waste any time if we have to recompile anyway
3378 Obj_Stamp := Empty_Time_Stamp;
3379 Need_To_Compile := Force_Compilations;
3381 if not Force_Compilations then
3383 Full_Lib_File /= No_File
3384 and then not Check_Readonly_Files
3385 and then Is_Readonly_Library (Full_Lib_File);
3386 Check (Source_File, Source_Index,
3387 Source_File = Main_Source, Args, Lib_File,
3388 Read_Only, ALI, Obj_File, Obj_Stamp);
3389 Need_To_Compile := (ALI = No_ALI_Id);
3392 if not Need_To_Compile then
3393 -- The ALI file is up-to-date. Record its Id
3395 Record_Good_ALI (ALI);
3397 -- Record the time stamp of the most recent object
3398 -- file as long as no (re)compilations are needed.
3400 if First_Compiled_File = No_File
3401 and then (Most_Recent_Obj_File = No_File
3402 or else Obj_Stamp > Most_Recent_Obj_Stamp)
3404 Most_Recent_Obj_File := Obj_File;
3405 Most_Recent_Obj_Stamp := Obj_Stamp;
3409 -- Check that switch -x has been used if a source
3410 -- outside of project files need to be compiled.
3412 if Main_Project /= No_Project
3413 and then Arguments_Project = No_Project
3414 and then not External_Unit_Compilation_Allowed
3416 Make_Failed ("external source ("
3417 & Get_Name_String (Source_File)
3418 & ") is not part of any project;"
3419 & " cannot be compiled without"
3420 & " gnatmake switch -x");
3423 -- Is this the first file we have to compile?
3425 if First_Compiled_File = No_File then
3426 First_Compiled_File := Full_Source_File;
3427 Most_Recent_Obj_File := No_File;
3429 if Do_Not_Execute then
3434 if In_Place_Mode then
3436 -- If the library file was not found, then save
3437 -- the library file near the source file.
3439 if Full_Lib_File = No_File then
3440 Lib_File := Osint.Lib_File_Name
3441 (Full_Source_File, Source_Index);
3443 -- If the library file was found, then save the
3444 -- library file in the same place.
3447 Lib_File := Full_Lib_File;
3452 -- Start the compilation and record it. We can do
3453 -- this because there is at least one free process.
3455 Collect_Arguments_And_Compile
3456 (Source_File, Source_Index);
3458 -- Make sure we could successfully start
3461 if Process_Created then
3462 if Pid = Invalid_Pid then
3463 Record_Failure (Full_Source_File, Source_Unit);
3479 -- PHASE 2: Now check if we should wait for a compilation to
3480 -- finish. This is the case if all the available processes are
3481 -- busy compiling sources or there is nothing else to do
3482 -- (that is the Q is empty and there are no good ALIs to process).
3484 if Outstanding_Compiles = Max_Process
3486 and then not Good_ALI_Present
3487 and then Outstanding_Compiles > 0)
3490 (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
3492 if not Compilation_OK then
3493 Record_Failure (Full_Source_File, Source_Unit);
3496 if Compilation_OK or else Keep_Going then
3498 -- Re-read the updated library file
3501 Saved_Object_Consistency : constant Boolean :=
3502 Check_Object_Consistency;
3505 -- If compilation was not OK, or if output is not an
3506 -- object file and we don't do the bind step, don't check
3507 -- for object consistency.
3509 Check_Object_Consistency :=
3510 Check_Object_Consistency
3512 and (Output_Is_Object or Do_Bind_Step);
3513 Text := Read_Library_Info (Lib_File);
3515 -- Restore Check_Object_Consistency to its initial value
3517 Check_Object_Consistency := Saved_Object_Consistency;
3520 -- If an ALI file was generated by this compilation, scan
3521 -- the ALI file and record it.
3523 -- If the scan fails, a previous ali file is inconsistent with
3524 -- the unit just compiled.
3526 if Text /= null then
3528 Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
3530 if ALI = No_ALI_Id then
3532 -- Record a failure only if not already done
3534 if Compilation_OK then
3537 "incompatible ALI file, please recompile");
3538 Record_Failure (Full_Source_File, Source_Unit);
3542 Record_Good_ALI (ALI);
3545 -- If we could not read the ALI file that was just generated
3546 -- then there could be a problem reading either the ALI or the
3547 -- corresponding object file (if Check_Object_Consistency is
3548 -- set Read_Library_Info checks that the time stamp of the
3549 -- object file is more recent than that of the ALI). However,
3550 -- we record a failure only if not already done.
3553 if Compilation_OK and not Syntax_Only then
3556 "WARNING: ALI or object file not found after compile");
3557 Record_Failure (Full_Source_File, Source_Unit);
3563 -- PHASE 3: Check if we recorded good ALI files. If yes process
3564 -- them now in the order in which they have been recorded. There
3565 -- are two occasions in which we record good ali files. The first is
3566 -- in phase 1 when, after scanning an existing ALI file we realize
3567 -- it is up-to-date, the second instance is after a successful
3570 while Good_ALI_Present loop
3571 ALI := Get_Next_Good_ALI;
3574 Source_Index : Int := Unit_Index_Of (ALIs.Table (ALI).Afile);
3577 -- If we are processing the library file corresponding to the
3578 -- main source file check if this source can be a main unit.
3580 if ALIs.Table (ALI).Sfile = Main_Source and then
3581 Source_Index = Main_Index
3583 Main_Unit := ALIs.Table (ALI).Main_Program /= None;
3586 -- The following adds the standard library (s-stalib) to the
3587 -- list of files to be handled by gnatmake: this file and any
3588 -- files it depends on are always included in every bind,
3589 -- even if they are not in the explicit dependency list.
3590 -- Of course, it is not added if Suppress_Standard_Library
3593 -- However, to avoid annoying output about s-stalib.ali being
3594 -- read only, when "-v" is used, we add the standard library
3595 -- only when "-a" is used.
3597 if Need_To_Check_Standard_Library then
3598 Check_Standard_Library;
3601 -- Now insert in the Q the unmarked source files (i.e. those
3602 -- which have never been inserted in the Q and hence never
3603 -- considered). Only do that if Unique_Compile is False.
3605 if not Unique_Compile then
3607 ALIs.Table (ALI).First_Unit .. ALIs.Table (ALI).Last_Unit
3610 Units.Table (J).First_With .. Units.Table (J).Last_With
3612 Sfile := Withs.Table (K).Sfile;
3613 Uname := Withs.Table (K).Uname;
3615 -- If project files are used, find the proper source
3616 -- to compile, in case Sfile is the spec, but there
3619 if Main_Project /= No_Project then
3621 Unit_Name : Name_Id;
3622 Uid : Prj.Unit_Index;
3626 Get_Name_String (Uname);
3627 Name_Len := Name_Len - 2;
3628 Unit_Name := Name_Find;
3631 (Project_Tree.Units_HT, Unit_Name);
3633 if Uid /= Prj.No_Unit_Index then
3634 Udata := Project_Tree.Units.Table (Uid);
3637 Udata.File_Names (Body_Part).Name /=
3640 Udata.File_Names (Body_Part).Path.Name /=
3643 Sfile := Udata.File_Names (Body_Part).Name;
3645 Udata.File_Names (Body_Part).Index;
3648 Udata.File_Names (Specification).Name /=
3652 (Specification).Path.Name /= Slash
3655 Udata.File_Names (Specification).Name;
3657 Udata.File_Names (Specification).Index;
3663 Dependencies.Append ((ALIs.Table (ALI).Sfile, Sfile));
3665 if Is_In_Obsoleted (Sfile) then
3666 Executable_Obsolete := True;
3669 if Sfile = No_File then
3671 ("Skipping generic:", Withs.Table (K).Uname);
3675 Unit_Index_Of (Withs.Table (K).Afile);
3677 if Is_Marked (Sfile, Source_Index) then
3678 Debug_Msg ("Skipping marked file:", Sfile);
3680 elsif not Check_Readonly_Files
3681 and then Is_Internal_File_Name (Sfile, False)
3683 Debug_Msg ("Skipping internal file:", Sfile);
3687 (Sfile, Withs.Table (K).Uname, Source_Index);
3688 Mark (Sfile, Source_Index);
3697 if Display_Compilation_Progress then
3698 Write_Str ("completed ");
3699 Write_Int (Int (Q_Front));
3700 Write_Str (" out of ");
3701 Write_Int (Int (Q.Last));
3703 Write_Int (Int ((Q_Front * 100) / (Q.Last - Q.First)));
3704 Write_Str ("%)...");
3709 Compilation_Failures := Bad_Compilation_Count;
3711 -- Compilation is finished
3713 -- Delete any temporary configuration pragma file
3715 if not Debug.Debug_Flag_N then
3716 Delete_Temp_Config_Files;
3718 end Compile_Sources;
3720 -----------------------------------
3721 -- Compute_All_Imported_Projects --
3722 -----------------------------------
3724 procedure Compute_All_Imported_Projects (Project : Project_Id) is
3725 procedure Add_To_List (Prj : Project_Id);
3726 -- Add a project to the list All_Imported_Projects of project Project
3728 procedure Recursive_Add_Imported (Project : Project_Id);
3729 -- Recursively add the projects imported by project Project, but not
3730 -- those that are extended.
3736 procedure Add_To_List (Prj : Project_Id) is
3737 Element : constant Project_Element :=
3738 (Prj, Project_Tree.Projects.Table (Project).All_Imported_Projects);
3739 List : Project_List;
3741 Project_List_Table.Increment_Last (Project_Tree.Project_Lists);
3742 List := Project_List_Table.Last (Project_Tree.Project_Lists);
3743 Project_Tree.Project_Lists.Table (List) := Element;
3744 Project_Tree.Projects.Table (Project).All_Imported_Projects := List;
3747 ----------------------------
3748 -- Recursive_Add_Imported --
3749 ----------------------------
3751 procedure Recursive_Add_Imported (Project : Project_Id) is
3752 List : Project_List;
3753 Element : Project_Element;
3757 if Project /= No_Project then
3759 -- For all the imported projects
3761 List := Project_Tree.Projects.Table (Project).Imported_Projects;
3762 while List /= Empty_Project_List loop
3763 Element := Project_Tree.Project_Lists.Table (List);
3764 Prj := Element.Project;
3766 -- Get the ultimate extending project
3769 Project_Tree.Projects.Table (Prj).Extended_By /= No_Project
3771 Prj := Project_Tree.Projects.Table (Prj).Extended_By;
3774 -- If project has not yet been visited, add to list and recurse
3776 if not Project_Tree.Projects.Table (Prj).Seen then
3777 Project_Tree.Projects.Table (Prj).Seen := True;
3779 Recursive_Add_Imported (Prj);
3782 List := Element.Next;
3785 -- Recurse on projects being imported, if any
3787 Recursive_Add_Imported
3788 (Project_Tree.Projects.Table (Project).Extends);
3790 end Recursive_Add_Imported;
3793 -- Reset the Seen flag for all projects
3795 for Index in 1 .. Project_Table.Last (Project_Tree.Projects) loop
3796 Project_Tree.Projects.Table (Index).Seen := False;
3799 -- Make sure the list is empty
3801 Project_Tree.Projects.Table (Project).All_Imported_Projects :=
3804 -- Add to the list all projects imported directly or indirectly
3806 Recursive_Add_Imported (Project);
3807 end Compute_All_Imported_Projects;
3809 ----------------------------------
3810 -- Configuration_Pragmas_Switch --
3811 ----------------------------------
3813 function Configuration_Pragmas_Switch
3814 (For_Project : Project_Id) return Argument_List
3816 The_Packages : Package_Id;
3817 Gnatmake : Package_Id;
3818 Compiler : Package_Id;
3820 Global_Attribute : Variable_Value := Nil_Variable_Value;
3821 Local_Attribute : Variable_Value := Nil_Variable_Value;
3823 Global_Attribute_Present : Boolean := False;
3824 Local_Attribute_Present : Boolean := False;
3826 Result : Argument_List (1 .. 3);
3827 Last : Natural := 0;
3829 function Absolute_Path
3830 (Path : Path_Name_Type;
3831 Project : Project_Id) return String;
3832 -- Returns an absolute path for a configuration pragmas file
3838 function Absolute_Path
3839 (Path : Path_Name_Type;
3840 Project : Project_Id) return String
3843 Get_Name_String (Path);
3846 Path_Name : constant String := Name_Buffer (1 .. Name_Len);
3849 if Is_Absolute_Path (Path_Name) then
3854 Parent_Directory : constant String :=
3856 (Project_Tree.Projects.Table
3857 (Project).Directory.Display_Name);
3860 if Parent_Directory (Parent_Directory'Last) =
3863 return Parent_Directory & Path_Name;
3866 return Parent_Directory & Directory_Separator & Path_Name;
3873 -- Start of processing for Configuration_Pragmas_Switch
3876 Prj.Env.Create_Config_Pragmas_File
3877 (For_Project, Main_Project, Project_Tree);
3879 if Project_Tree.Projects.Table
3880 (For_Project).Config_File_Name /= No_Path
3882 Temporary_Config_File :=
3883 Project_Tree.Projects.Table (For_Project).Config_File_Temp;
3889 (Project_Tree.Projects.Table
3890 (For_Project).Config_File_Name));
3893 Temporary_Config_File := False;
3896 -- Check for attribute Builder'Global_Configuration_Pragmas
3898 The_Packages := Project_Tree.Projects.Table
3899 (Main_Project).Decl.Packages;
3902 (Name => Name_Builder,
3903 In_Packages => The_Packages,
3904 In_Tree => Project_Tree);
3906 if Gnatmake /= No_Package then
3907 Global_Attribute := Prj.Util.Value_Of
3908 (Variable_Name => Name_Global_Configuration_Pragmas,
3909 In_Variables => Project_Tree.Packages.Table
3910 (Gnatmake).Decl.Attributes,
3911 In_Tree => Project_Tree);
3912 Global_Attribute_Present :=
3913 Global_Attribute /= Nil_Variable_Value
3914 and then Get_Name_String (Global_Attribute.Value) /= "";
3916 if Global_Attribute_Present then
3918 Path : constant String :=
3920 (Path_Name_Type (Global_Attribute.Value),
3921 Global_Attribute.Project);
3923 if not Is_Regular_File (Path) then
3924 if Debug.Debug_Flag_F then
3926 ("cannot find configuration pragmas file "
3927 & File_Name (Path));
3930 ("cannot find configuration pragmas file " & Path);
3935 Result (Last) := new String'("-gnatec=" & Path);
3940 -- Check for attribute Compiler'Local_Configuration_Pragmas
3943 Project_Tree.Projects.Table (For_Project).Decl.Packages;
3946 (Name => Name_Compiler,
3947 In_Packages => The_Packages,
3948 In_Tree => Project_Tree);
3950 if Compiler /= No_Package then
3951 Local_Attribute := Prj.Util.Value_Of
3952 (Variable_Name => Name_Local_Configuration_Pragmas,
3953 In_Variables => Project_Tree.Packages.Table
3954 (Compiler).Decl.Attributes,
3955 In_Tree => Project_Tree);
3956 Local_Attribute_Present :=
3957 Local_Attribute /= Nil_Variable_Value
3958 and then Get_Name_String (Local_Attribute.Value) /= "";
3960 if Local_Attribute_Present then
3962 Path : constant String :=
3964 (Path_Name_Type (Local_Attribute.Value),
3965 Local_Attribute.Project);
3967 if not Is_Regular_File (Path) then
3968 if Debug.Debug_Flag_F then
3970 ("cannot find configuration pragmas file "
3971 & File_Name (Path));
3975 ("cannot find configuration pragmas file " & Path);
3980 Result (Last) := new String'("-gnatec=" & Path);
3985 return Result (1 .. Last);
3986 end Configuration_Pragmas_Switch;
3992 procedure Debug_Msg (S : String; N : Name_Id) is
3994 if Debug.Debug_Flag_W then
3995 Write_Str (" ... ");
4003 procedure Debug_Msg (S : String; N : File_Name_Type) is
4005 Debug_Msg (S, Name_Id (N));
4008 procedure Debug_Msg (S : String; N : Unit_Name_Type) is
4010 Debug_Msg (S, Name_Id (N));
4013 ---------------------------
4014 -- Delete_All_Temp_Files --
4015 ---------------------------
4017 procedure Delete_All_Temp_Files is
4019 if not Debug.Debug_Flag_N then
4020 Delete_Mapping_Files;
4021 Delete_Temp_Config_Files;
4022 Prj.Env.Delete_All_Path_Files (Project_Tree);
4024 end Delete_All_Temp_Files;
4026 --------------------------
4027 -- Delete_Mapping_Files --
4028 --------------------------
4030 procedure Delete_Mapping_Files is
4032 pragma Warnings (Off, Success);
4035 -- The caller is responsible for ensuring that Debug_Flag_N is False
4037 pragma Assert (not Debug.Debug_Flag_N);
4039 if The_Mapping_File_Names /= null then
4040 for Project in The_Mapping_File_Names'Range (1) loop
4041 for Index in 1 .. Last_Mapping_File_Names (Project) loop
4043 (Name => Get_Name_String
4044 (The_Mapping_File_Names (Project, Index)),
4045 Success => Success);
4049 end Delete_Mapping_Files;
4051 ------------------------------
4052 -- Delete_Temp_Config_Files --
4053 ------------------------------
4055 procedure Delete_Temp_Config_Files is
4057 pragma Warnings (Off, Success);
4060 -- The caller is responsible for ensuring that Debug_Flag_N is False
4062 pragma Assert (not Debug.Debug_Flag_N);
4064 if Main_Project /= No_Project then
4065 for Project in Project_Table.First ..
4066 Project_Table.Last (Project_Tree.Projects)
4069 Project_Tree.Projects.Table (Project).Config_File_Temp
4071 if Verbose_Mode then
4072 Write_Str ("Deleting temp configuration file """);
4073 Write_Str (Get_Name_String
4074 (Project_Tree.Projects.Table
4075 (Project).Config_File_Name));
4080 (Name => Get_Name_String
4081 (Project_Tree.Projects.Table
4082 (Project).Config_File_Name),
4083 Success => Success);
4085 -- Make sure that we don't have a config file for this project,
4086 -- in case there are several mains. In this case, we will
4087 -- recreate another config file: we cannot reuse the one that
4090 Project_Tree.Projects.Table (Project).
4091 Config_Checked := False;
4092 Project_Tree.Projects.Table (Project).
4093 Config_File_Name := No_Path;
4094 Project_Tree.Projects.Table (Project).
4095 Config_File_Temp := False;
4099 end Delete_Temp_Config_Files;
4105 procedure Display (Program : String; Args : Argument_List) is
4107 pragma Assert (Args'First = 1);
4109 if Display_Executed_Programs then
4110 Write_Str (Program);
4112 for J in Args'Range loop
4114 -- Never display -gnatea nor -gnatez
4116 if Args (J).all /= "-gnatea"
4118 Args (J).all /= "-gnatez"
4120 -- Do not display the mapping file argument automatically
4121 -- created when using a project file.
4123 if Main_Project = No_Project
4124 or else Debug.Debug_Flag_N
4125 or else Args (J)'Length < 8
4127 Args (J) (Args (J)'First .. Args (J)'First + 6) /= "-gnatem"
4129 -- When -dn is not specified, do not display the config
4130 -- pragmas switch (-gnatec) for the temporary file created
4131 -- by the project manager (always the first -gnatec switch).
4132 -- Reset Temporary_Config_File to False so that the eventual
4133 -- other -gnatec switches will be displayed.
4135 if (not Debug.Debug_Flag_N)
4136 and then Temporary_Config_File
4137 and then Args (J)'Length > 7
4138 and then Args (J) (Args (J)'First .. Args (J)'First + 6)
4141 Temporary_Config_File := False;
4143 -- Do not display the -F=mapping_file switch for
4144 -- gnatbind, if -dn is not specified.
4146 elsif Debug.Debug_Flag_N
4147 or else Args (J)'Length < 4
4149 Args (J) (Args (J)'First .. Args (J)'First + 2) /= "-F="
4153 -- If -df is used, only display file names, not path
4156 if Debug.Debug_Flag_F then
4158 Equal_Pos : Natural;
4160 Equal_Pos := Args (J)'First - 1;
4161 for K in Args (J)'Range loop
4162 if Args (J) (K) = '=' then
4169 (Args (J) (Equal_Pos + 1 .. Args (J)'Last))
4172 (Args (J) (Args (J)'First .. Equal_Pos));
4176 (Equal_Pos + 1 .. Args (J)'Last)));
4179 Write_Str (Args (J).all);
4184 Write_Str (Args (J).all);
4195 ----------------------
4196 -- Display_Commands --
4197 ----------------------
4199 procedure Display_Commands (Display : Boolean := True) is
4201 Display_Executed_Programs := Display;
4202 end Display_Commands;
4208 function Empty_Q return Boolean is
4210 if Debug.Debug_Flag_P then
4211 Write_Str (" Q := [");
4213 for J in Q_Front .. Q.Last - 1 loop
4215 Write_Name (Q.Table (J).File);
4224 return Q_Front >= Q.Last;
4227 --------------------------
4228 -- Enter_Into_Obsoleted --
4229 --------------------------
4231 procedure Enter_Into_Obsoleted (F : File_Name_Type) is
4232 Name : constant String := Get_Name_String (F);
4234 F2 : File_Name_Type;
4238 while First > Name'First
4239 and then Name (First - 1) /= Directory_Separator
4240 and then Name (First - 1) /= '/'
4245 if First /= Name'First then
4247 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
4254 Debug_Msg ("New entry in Obsoleted table:", F2);
4255 Obsoleted.Set (F2, True);
4256 end Enter_Into_Obsoleted;
4258 --------------------
4259 -- Extract_From_Q --
4260 --------------------
4262 procedure Extract_From_Q
4263 (Source_File : out File_Name_Type;
4264 Source_Unit : out Unit_Name_Type;
4265 Source_Index : out Int)
4267 File : constant File_Name_Type := Q.Table (Q_Front).File;
4268 Unit : constant Unit_Name_Type := Q.Table (Q_Front).Unit;
4269 Index : constant Int := Q.Table (Q_Front).Index;
4272 if Debug.Debug_Flag_Q then
4273 Write_Str (" Q := Q - [ ");
4285 Q_Front := Q_Front + 1;
4286 Source_File := File;
4287 Source_Unit := Unit;
4288 Source_Index := Index;
4295 procedure Gnatmake is
4296 Main_Source_File : File_Name_Type;
4297 -- The source file containing the main compilation unit
4299 Compilation_Failures : Natural;
4301 Total_Compilation_Failures : Natural := 0;
4303 Is_Main_Unit : Boolean;
4304 -- Set to True by Compile_Sources if the Main_Source_File can be a
4307 Main_ALI_File : File_Name_Type;
4308 -- The ali file corresponding to Main_Source_File
4310 Executable : File_Name_Type := No_File;
4311 -- The file name of an executable
4313 Non_Std_Executable : Boolean := False;
4314 -- Non_Std_Executable is set to True when there is a possibility
4315 -- that the linker will not choose the correct executable file name.
4317 Current_Work_Dir : constant String_Access :=
4318 new String'(Get_Current_Dir);
4319 -- The current working directory, used to modify some relative path
4320 -- switches on the command line when a project file is used.
4322 Current_Main_Index : Int := 0;
4323 -- If not zero, the index of the current main unit in its source file
4325 There_Are_Stand_Alone_Libraries : Boolean := False;
4326 -- Set to True when there are Stand-Alone Libraries, so that gnatbind
4327 -- is invoked with the -F switch to force checking of elaboration flags.
4329 Mapping_Path : Path_Name_Type := No_Path;
4330 -- The path name of the mapping file
4333 pragma Warnings (Off, Discard);
4335 procedure Check_Mains;
4336 -- Check that the main subprograms do exist and that they all
4337 -- belong to the same project file.
4339 procedure Create_Binder_Mapping_File
4340 (Args : in out Argument_List; Last_Arg : in out Natural);
4341 -- Create a binder mapping file and add the necessary switch
4347 procedure Check_Mains is
4348 Real_Main_Project : Project_Id := No_Project;
4349 -- The project of the first main
4351 Proj : Project_Id := No_Project;
4352 -- The project of the current main
4354 Data : Project_Data;
4356 Real_Path : String_Access;
4365 Main : constant String := Mains.Next_Main;
4366 -- The name specified on the command line may include
4367 -- directory information.
4369 File_Name : constant String := Base_Name (Main);
4370 -- The simple file name of the current main
4373 exit when Main = "";
4375 -- Get the project of the current main
4377 Proj := Prj.Env.Project_Of
4378 (File_Name, Main_Project, Project_Tree);
4380 -- Fail if the current main is not a source of a
4383 if Proj = No_Project then
4385 ("""" & Main & """ is not a source of any project");
4388 -- If there is directory information, check that
4389 -- the source exists and, if it does, that the path
4390 -- is the actual path of a source of a project.
4392 if Main /= File_Name then
4394 Project_Tree.Projects.Table (Main_Project);
4399 Body_Suffix_Of (Project_Tree, "ada", Data.Naming),
4401 if Real_Path = null then
4405 Spec_Suffix_Of (Project_Tree, "ada", Data.Naming),
4409 if Real_Path = null then
4411 Locate_Regular_File (Main, "");
4414 -- Fail if the file cannot be found
4416 if Real_Path = null then
4417 Make_Failed ("file """ & Main & """ does not exist");
4421 Project_Path : constant String :=
4422 Prj.Env.File_Name_Of_Library_Unit_Body
4424 Project => Main_Project,
4425 In_Tree => Project_Tree,
4426 Main_Project_Only => False,
4428 Normed_Path : constant String :=
4431 Case_Sensitive => False);
4432 Proj_Path : constant String :=
4435 Case_Sensitive => False);
4440 -- Fail if it is not the correct path
4442 if Normed_Path /= Proj_Path then
4443 if Verbose_Mode then
4445 Write_Str (Normed_Path);
4447 Write_Line (Proj_Path);
4452 """ is not a source of any project");
4457 if not Unique_Compile then
4459 -- Record the project, if it is the first main
4461 if Real_Main_Project = No_Project then
4462 Real_Main_Project := Proj;
4464 elsif Proj /= Real_Main_Project then
4466 -- Fail, as the current main is not a source
4467 -- of the same project as the first main.
4471 """ is not a source of project " &
4473 (Project_Tree.Projects.Table
4474 (Real_Main_Project).Name));
4479 -- If -u and -U are not used, we may have mains that
4480 -- are sources of a project that is not the one
4481 -- specified with switch -P.
4483 if not Unique_Compile then
4484 Main_Project := Real_Main_Project;
4490 --------------------------------
4491 -- Create_Binder_Mapping_File --
4492 --------------------------------
4494 procedure Create_Binder_Mapping_File
4495 (Args : in out Argument_List; Last_Arg : in out Natural)
4497 Mapping_FD : File_Descriptor := Invalid_FD;
4498 -- A File Descriptor for an eventual mapping file
4500 ALI_Unit : Unit_Name_Type := No_Unit_Name;
4501 -- The unit name of an ALI file
4503 ALI_Name : File_Name_Type := No_File;
4504 -- The file name of the ALI file
4506 ALI_Project : Project_Id := No_Project;
4507 -- The project of the ALI file
4510 OK : Boolean := True;
4513 -- For call to Close
4516 Tempdir.Create_Temp_File (Mapping_FD, Mapping_Path);
4517 Record_Temp_File (Mapping_Path);
4519 if Mapping_FD /= Invalid_FD then
4521 -- Traverse all units
4523 for J in Unit_Table.First ..
4524 Unit_Table.Last (Project_Tree.Units)
4527 Unit : constant Unit_Data := Project_Tree.Units.Table (J);
4529 if Unit.Name /= No_Name then
4531 -- If there is a body, put it in the mapping
4533 if Unit.File_Names (Body_Part).Name /= No_File
4534 and then Unit.File_Names (Body_Part).Project /=
4537 Get_Name_String (Unit.Name);
4538 Name_Buffer (Name_Len + 1 .. Name_Len + 2) := "%b";
4539 Name_Len := Name_Len + 2;
4540 ALI_Unit := Name_Find;
4543 (Unit.File_Names (Body_Part).Display_Name);
4545 Unit.File_Names (Body_Part).Project;
4547 -- Otherwise, if there is a spec, put it
4550 elsif Unit.File_Names (Specification).Name /= No_File
4551 and then Unit.File_Names (Specification).Project /=
4554 Get_Name_String (Unit.Name);
4555 Name_Buffer (Name_Len + 1 .. Name_Len + 2) := "%s";
4556 Name_Len := Name_Len + 2;
4557 ALI_Unit := Name_Find;
4560 (Unit.File_Names (Specification).Display_Name);
4562 Unit.File_Names (Specification).Project;
4565 ALI_Name := No_File;
4568 -- If we have something to put in the mapping
4569 -- then we do it now. However, if the project
4570 -- is extended, we don't put anything in the
4571 -- mapping file, because we do not know where
4572 -- the ALI file is: it might be in the ext-
4573 -- ended project obj dir as well as in the
4574 -- extending project obj dir.
4576 if ALI_Name /= No_File
4578 Project_Tree.Projects.Table
4579 (ALI_Project).Extended_By = No_Project
4581 Project_Tree.Projects.Table
4582 (ALI_Project).Extends = No_Project
4584 -- First check if the ALI file exists. If it does not,
4585 -- do not put the unit in the mapping file.
4588 ALI : constant String :=
4589 Get_Name_String (ALI_Name);
4590 PD : Project_Data renames
4591 Project_Tree.Projects.Table (ALI_Project);
4594 -- For library projects, use the library directory,
4595 -- for other projects, use the object directory.
4598 Get_Name_String (PD.Library_Dir.Name);
4600 Get_Name_String (PD.Object_Directory.Name);
4603 if Name_Buffer (Name_Len) /=
4606 Name_Len := Name_Len + 1;
4607 Name_Buffer (Name_Len) :=
4608 Directory_Separator;
4613 Name_Len + ALI'Length) := ALI;
4615 Name_Len + ALI'Length + 1;
4616 Name_Buffer (Name_Len) := ASCII.LF;
4619 ALI_Path_Name : constant String :=
4620 Name_Buffer (1 .. Name_Len);
4624 (ALI_Path_Name (1 .. ALI_Path_Name'Last - 1))
4627 -- First line is the unit name
4629 Get_Name_String (ALI_Unit);
4630 Name_Len := Name_Len + 1;
4631 Name_Buffer (Name_Len) := ASCII.LF;
4635 Name_Buffer (1)'Address,
4637 OK := Bytes = Name_Len;
4641 -- Second line it the ALI file name
4643 Get_Name_String (ALI_Name);
4644 Name_Len := Name_Len + 1;
4645 Name_Buffer (Name_Len) := ASCII.LF;
4649 Name_Buffer (1)'Address,
4651 OK := Bytes = Name_Len;
4655 -- Third line it the ALI path name
4660 ALI_Path_Name (1)'Address,
4661 ALI_Path_Name'Length);
4662 OK := Bytes = ALI_Path_Name'Length;
4664 -- If OK is False, it means we were unable
4665 -- to write a line. No point in continuing
4666 -- with the other units.
4677 Close (Mapping_FD, Status);
4679 OK := OK and Status;
4681 -- If the creation of the mapping file was successful,
4682 -- we add the switch to the arguments of gnatbind.
4685 Last_Arg := Last_Arg + 1;
4687 new String'("-F=" & Get_Name_String (Mapping_Path));
4690 end Create_Binder_Mapping_File;
4692 -- Start of processing for Gnatmake
4694 -- This body is very long, should be broken down ???
4697 Install_Int_Handler (Sigint_Intercepted'Access);
4699 Do_Compile_Step := True;
4700 Do_Bind_Step := True;
4701 Do_Link_Step := True;
4707 Bind_Shared := No_Shared_Switch'Access;
4708 Link_With_Shared_Libgcc := No_Shared_Libgcc_Switch'Access;
4710 Failed_Links.Set_Last (0);
4711 Successful_Links.Set_Last (0);
4713 -- Special case when switch -B was specified
4715 if Build_Bind_And_Link_Full_Project then
4717 -- When switch -B is specified, there must be a project file
4719 if Main_Project = No_Project then
4720 Make_Failed ("-B cannot be used without a project file");
4722 -- No main program may be specified on the command line
4724 elsif Osint.Number_Of_Files /= 0 then
4725 Make_Failed ("-B cannot be used with a main specified on " &
4726 "the command line");
4728 -- And the project file cannot be a library project file
4730 elsif Project_Tree.Projects.Table (Main_Project).Library then
4731 Make_Failed ("-B cannot be used for a library project file");
4734 No_Main_Subprogram := True;
4735 Insert_Project_Sources
4736 (The_Project => Main_Project,
4737 All_Projects => Unique_Compile_All_Projects,
4740 -- If there are no sources to compile, we fail
4742 if Osint.Number_Of_Files = 0 then
4743 Make_Failed ("no sources to compile");
4746 -- Specify -n for gnatbind and add the ALI files of all the
4747 -- sources, except the one which is a fake main subprogram:
4748 -- this is the one for the binder generated file and it will be
4749 -- transmitted to gnatlink. These sources are those that are
4752 Add_Switch ("-n", Binder, And_Save => True);
4754 for J in Q.First .. Q.Last - 1 loop
4757 (Lib_File_Name (Q.Table (J).File)),
4758 Binder, And_Save => True);
4762 elsif Main_Index /= 0 and then Osint.Number_Of_Files > 1 then
4763 Make_Failed ("cannot specify several mains with a multi-unit index");
4765 elsif Main_Project /= No_Project then
4767 -- If the main project file is a library project file, main(s)
4768 -- cannot be specified on the command line.
4770 if Osint.Number_Of_Files /= 0 then
4771 if Project_Tree.Projects.Table (Main_Project).Library
4772 and then not Unique_Compile
4773 and then ((not Make_Steps) or else Bind_Only or else Link_Only)
4775 Make_Failed ("cannot specify a main program " &
4776 "on the command line for a library project file");
4779 -- Check that each main on the command line is a source of a
4780 -- project file and, if there are several mains, each of them
4781 -- is a source of the same project file.
4786 -- If no mains have been specified on the command line,
4787 -- and we are using a project file, we either find the main(s)
4788 -- in the attribute Main of the main project, or we put all
4789 -- the sources of the project file as mains.
4792 if Main_Index /= 0 then
4793 Make_Failed ("cannot specify a multi-unit index but no main " &
4794 "on the command line");
4798 Value : String_List_Id :=
4799 Project_Tree.Projects.Table (Main_Project).Mains;
4802 -- The attribute Main is an empty list or not specified,
4803 -- or else gnatmake was invoked with the switch "-u".
4805 if Value = Prj.Nil_String or else Unique_Compile then
4807 if (not Make_Steps) or else Compile_Only
4808 or else not Project_Tree.Projects.Table
4809 (Main_Project).Library
4811 -- First make sure that the binder and the linker
4812 -- will not be invoked.
4814 Do_Bind_Step := False;
4815 Do_Link_Step := False;
4817 -- Put all the sources in the queue
4819 No_Main_Subprogram := True;
4820 Insert_Project_Sources
4821 (The_Project => Main_Project,
4822 All_Projects => Unique_Compile_All_Projects,
4825 -- If no sources to compile, then there is nothing to do
4827 if Osint.Number_Of_Files = 0 then
4828 if not Quiet_Output then
4829 Osint.Write_Program_Name;
4830 Write_Line (": no sources to compile");
4833 Delete_All_Temp_Files;
4834 Exit_Program (E_Success);
4839 -- The attribute Main is not an empty list.
4840 -- Put all the main subprograms in the list as if there
4841 -- were specified on the command line. However, if attribute
4842 -- Languages includes a language other than Ada, only
4843 -- include the Ada mains; if there is no Ada main, compile
4844 -- all the sources of the project.
4847 Data : constant Project_Data :=
4848 Project_Tree.Projects.Table (Main_Project);
4850 Languages : constant Variable_Value :=
4853 Data.Decl.Attributes,
4856 Current : String_List_Id;
4857 Element : String_Element;
4859 Foreign_Language : Boolean := False;
4860 At_Least_One_Main : Boolean := False;
4863 -- First, determine if there is a foreign language in
4864 -- attribute Languages.
4866 if not Languages.Default then
4867 Current := Languages.Values;
4870 while Current /= Nil_String loop
4871 Element := Project_Tree.String_Elements.
4873 Get_Name_String (Element.Value);
4874 To_Lower (Name_Buffer (1 .. Name_Len));
4876 if Name_Buffer (1 .. Name_Len) /= "ada" then
4877 Foreign_Language := True;
4878 exit Look_For_Foreign;
4881 Current := Element.Next;
4882 end loop Look_For_Foreign;
4885 -- Then, find all mains, or if there is a foreign
4886 -- language, all the Ada mains.
4888 while Value /= Prj.Nil_String loop
4890 (Project_Tree.String_Elements.Table
4893 -- To know if a main is an Ada main, get its project.
4894 -- It should be the project specified on the command
4897 if (not Foreign_Language) or else
4899 (Name_Buffer (1 .. Name_Len),
4904 At_Least_One_Main := True;
4907 (Project_Tree.String_Elements.Table
4910 Project_Tree.String_Elements.Table
4914 Value := Project_Tree.String_Elements.Table
4918 -- If we did not get any main, it means that all mains
4919 -- in attribute Mains are in a foreign language and -B
4920 -- was not specified to gnatmake; so, we fail.
4922 if not At_Least_One_Main then
4924 ("no Ada mains, use -B to build foreign main");
4933 if Verbose_Mode then
4935 Display_Version ("GNATMAKE", "1995");
4938 if Main_Project /= No_Project
4939 and then Project_Tree.Projects.Table
4940 (Main_Project).Externally_Built
4943 ("nothing to do for a main project that is externally built");
4946 if Osint.Number_Of_Files = 0 then
4947 if Main_Project /= No_Project
4948 and then Project_Tree.Projects.Table (Main_Project).Library
4951 and then not Project_Tree.Projects.Table
4952 (Main_Project).Standalone_Library
4954 Make_Failed ("only stand-alone libraries may be bound");
4957 -- Add the default search directories to be able to find libgnat
4959 Osint.Add_Default_Search_Dirs;
4961 -- Get the target parameters, so that the correct binder generated
4962 -- files are generated if OpenVMS is the target.
4965 Targparm.Get_Target_Parameters;
4968 when Unrecoverable_Error =>
4969 Make_Failed ("*** make failed.");
4972 -- And bind and or link the library
4974 MLib.Prj.Build_Library
4975 (For_Project => Main_Project,
4976 In_Tree => Project_Tree,
4977 Gnatbind => Gnatbind.all,
4978 Gnatbind_Path => Gnatbind_Path,
4980 Gcc_Path => Gcc_Path,
4984 Delete_All_Temp_Files;
4985 Exit_Program (E_Success);
4988 -- Output usage information if no files to compile
4991 Exit_Program (E_Fatal);
4995 -- If -M was specified, behave as if -n was specified
4997 if List_Dependencies then
4998 Do_Not_Execute := True;
5001 -- Note that Osint.M.Next_Main_Source will always return the (possibly
5002 -- abbreviated file) without any directory information.
5004 Main_Source_File := Next_Main_Source;
5006 if Current_File_Index /= No_Index then
5007 Main_Index := Current_File_Index;
5010 Add_Switch ("-I-", Compiler, And_Save => True);
5012 if Main_Project = No_Project then
5013 if Look_In_Primary_Dir then
5017 Normalize_Directory_Name
5018 (Get_Primary_Src_Search_Directory.all).all,
5019 Compiler, Append_Switch => False,
5025 -- If we use a project file, we have already checked that a main
5026 -- specified on the command line with directory information has the
5027 -- path name corresponding to a correct source in the project tree.
5028 -- So, we don't need the directory information to be taken into
5029 -- account by Find_File, and in fact it may lead to take the wrong
5030 -- sources for other compilation units, when there are extending
5033 Look_In_Primary_Dir := False;
5034 Add_Switch ("-I-", Binder, And_Save => True);
5037 -- If the user wants a program without a main subprogram, add the
5038 -- appropriate switch to the binder.
5040 if No_Main_Subprogram then
5041 Add_Switch ("-z", Binder, And_Save => True);
5044 if Main_Project /= No_Project then
5046 if Project_Tree.Projects.Table
5047 (Main_Project).Object_Directory /= No_Path_Information
5049 -- Change current directory to object directory of main project
5051 Project_Of_Current_Object_Directory := No_Project;
5052 Change_To_Object_Directory (Main_Project);
5055 -- Source file lookups should be cached for efficiency.
5056 -- Source files are not supposed to change.
5058 Osint.Source_File_Data (Cache => True);
5060 -- Find the file name of the (first) main unit
5063 Main_Source_File_Name : constant String :=
5064 Get_Name_String (Main_Source_File);
5065 Main_Unit_File_Name : constant String :=
5066 Prj.Env.File_Name_Of_Library_Unit_Body
5067 (Name => Main_Source_File_Name,
5068 Project => Main_Project,
5069 In_Tree => Project_Tree,
5070 Main_Project_Only =>
5071 not Unique_Compile);
5073 The_Packages : constant Package_Id :=
5074 Project_Tree.Projects.Table
5075 (Main_Project).Decl.Packages;
5077 Builder_Package : constant Prj.Package_Id :=
5079 (Name => Name_Builder,
5080 In_Packages => The_Packages,
5081 In_Tree => Project_Tree);
5083 Binder_Package : constant Prj.Package_Id :=
5085 (Name => Name_Binder,
5086 In_Packages => The_Packages,
5087 In_Tree => Project_Tree);
5089 Linker_Package : constant Prj.Package_Id :=
5091 (Name => Name_Linker,
5092 In_Packages => The_Packages,
5093 In_Tree => Project_Tree);
5095 Default_Switches_Array : Array_Id;
5097 Global_Compilation_Array : Array_Element_Id;
5098 Global_Compilation_Elem : Array_Element;
5099 Global_Compilation_Switches : Variable_Value;
5102 -- We fail if we cannot find the main source file
5104 if Main_Unit_File_Name = "" then
5105 Make_Failed ('"' & Main_Source_File_Name
5106 & """ is not a unit of project "
5107 & Project_File_Name.all & ".");
5109 -- Remove any directory information from the main
5110 -- source file name.
5113 Pos : Natural := Main_Unit_File_Name'Last;
5117 exit when Pos < Main_Unit_File_Name'First or else
5118 Main_Unit_File_Name (Pos) = Directory_Separator;
5122 Name_Len := Main_Unit_File_Name'Last - Pos;
5124 Name_Buffer (1 .. Name_Len) :=
5126 (Pos + 1 .. Main_Unit_File_Name'Last);
5128 Main_Source_File := Name_Find;
5130 -- We only output the main source file if there is only one
5132 if Verbose_Mode and then Osint.Number_Of_Files = 1 then
5133 Write_Str ("Main source file: """);
5134 Write_Str (Main_Unit_File_Name
5135 (Pos + 1 .. Main_Unit_File_Name'Last));
5141 -- If there is a package Builder in the main project file, add
5142 -- the switches from it.
5144 if Builder_Package /= No_Package then
5146 Global_Compilation_Array := Prj.Util.Value_Of
5147 (Name => Name_Global_Compilation_Switches,
5148 In_Arrays => Project_Tree.Packages.Table
5149 (Builder_Package).Decl.Arrays,
5150 In_Tree => Project_Tree);
5152 Default_Switches_Array :=
5153 Project_Tree.Packages.Table
5154 (Builder_Package).Decl.Arrays;
5156 while Default_Switches_Array /= No_Array and then
5157 Project_Tree.Arrays.Table (Default_Switches_Array).Name /=
5158 Name_Default_Switches
5160 Default_Switches_Array :=
5161 Project_Tree.Arrays.Table (Default_Switches_Array).Next;
5164 if Global_Compilation_Array /= No_Array_Element and then
5165 Default_Switches_Array /= No_Array
5168 ("Default_Switches forbidden in presence of " &
5169 "Global_Compilation_Switches. Use Switches instead.",
5170 Project_Tree.Arrays.Table
5171 (Default_Switches_Array).Location);
5174 ("*** illegal combination of Builder attributes");
5177 -- If there is only one main, we attempt to get the gnatmake
5178 -- switches for this main (if any). If there are no specific
5179 -- switch for this particular main, get the general gnatmake
5180 -- switches (if any).
5182 if Osint.Number_Of_Files = 1 then
5183 if Verbose_Mode then
5184 Write_Str ("Adding gnatmake switches for """);
5185 Write_Str (Main_Unit_File_Name);
5190 (File_Name => Main_Unit_File_Name,
5191 Index => Main_Index,
5192 The_Package => Builder_Package,
5194 Unknown_Switches_To_The_Compiler =>
5195 Global_Compilation_Array = No_Array_Element);
5198 -- If there are several mains, we always get the general
5199 -- gnatmake switches (if any).
5201 -- Warn the user, if necessary, so that he is not surprised
5202 -- that specific switches are not taken into account.
5205 Defaults : constant Variable_Value :=
5209 Attribute_Or_Array_Name =>
5210 Name_Default_Switches,
5213 In_Tree => Project_Tree);
5215 Switches : constant Array_Element_Id :=
5217 (Name => Name_Switches,
5219 Project_Tree.Packages.Table
5220 (Builder_Package).Decl.Arrays,
5221 In_Tree => Project_Tree);
5223 Other_Switches : constant Variable_Value :=
5225 (Name => All_Other_Names,
5227 Attribute_Or_Array_Name
5229 In_Package => Builder_Package,
5230 In_Tree => Project_Tree);
5233 if Other_Switches /= Nil_Variable_Value then
5235 and then Switches /= No_Array_Element
5236 and then Project_Tree.Array_Elements.Table
5237 (Switches).Next /= No_Array_Element
5240 ("Warning: using Builder'Switches(others), "
5241 & "as there are several mains");
5247 The_Package => Builder_Package,
5249 Unknown_Switches_To_The_Compiler => False);
5251 elsif Defaults /= Nil_Variable_Value then
5253 and then Switches /= No_Array_Element
5256 ("Warning: using Builder'Default_Switches"
5257 & "(""Ada""), as there are several mains");
5263 The_Package => Builder_Package,
5266 elsif not Quiet_Output
5267 and then Switches /= No_Array_Element
5270 ("Warning: using no switches from package "
5271 & "Builder, as there are several mains");
5276 -- Take into account attribute Global_Compilation_Switches
5281 List : String_List_Id;
5282 Elem : String_Element;
5285 while Global_Compilation_Array /= No_Array_Element loop
5286 Global_Compilation_Elem :=
5287 Project_Tree.Array_Elements.Table
5288 (Global_Compilation_Array);
5290 Get_Name_String (Global_Compilation_Elem.Index);
5291 To_Lower (Name_Buffer (1 .. Name_Len));
5294 if Index = Name_Ada then
5295 Global_Compilation_Switches :=
5296 Global_Compilation_Elem.Value;
5298 if Global_Compilation_Switches /= Nil_Variable_Value
5299 and then not Global_Compilation_Switches.Default
5301 -- We have found attribute
5302 -- Global_Compilation_Switches ("Ada"): put the
5303 -- switches in the appropriate table.
5305 List := Global_Compilation_Switches.Values;
5307 while List /= Nil_String loop
5309 Project_Tree.String_Elements.Table (List);
5311 if Elem.Value /= No_Name then
5313 (Get_Name_String (Elem.Value),
5325 Global_Compilation_Array := Global_Compilation_Elem.Next;
5330 Osint.Add_Default_Search_Dirs;
5332 -- Record the current last switch index for table Binder_Switches
5333 -- and Linker_Switches, so that these tables may be reset before
5334 -- for each main, before adding switches from the project file
5335 -- and from the command line.
5337 Last_Binder_Switch := Binder_Switches.Last;
5338 Last_Linker_Switch := Linker_Switches.Last;
5342 -- Add binder switches from the project file for the first main
5344 if Do_Bind_Step and Binder_Package /= No_Package then
5345 if Verbose_Mode then
5346 Write_Str ("Adding binder switches for """);
5347 Write_Str (Main_Unit_File_Name);
5352 (File_Name => Main_Unit_File_Name,
5353 Index => Main_Index,
5354 The_Package => Binder_Package,
5358 -- Add linker switches from the project file for the first main
5360 if Do_Link_Step and Linker_Package /= No_Package then
5361 if Verbose_Mode then
5362 Write_Str ("Adding linker switches for""");
5363 Write_Str (Main_Unit_File_Name);
5368 (File_Name => Main_Unit_File_Name,
5369 Index => Main_Index,
5370 The_Package => Linker_Package,
5376 -- Get the target parameters, which are only needed for a couple of
5377 -- cases in gnatmake. Protect against an exception, such as the case
5378 -- of system.ads missing from the library, and fail gracefully.
5381 Targparm.Get_Target_Parameters;
5383 when Unrecoverable_Error =>
5384 Make_Failed ("*** make failed.");
5387 -- Special processing for VM targets
5389 if Targparm.VM_Target /= No_VM then
5391 -- Set proper processing commands
5393 case Targparm.VM_Target is
5394 when Targparm.JVM_Target =>
5396 -- Do not check for an object file (".o") when compiling to
5397 -- JVM machine since ".class" files are generated instead.
5399 Check_Object_Consistency := False;
5400 Gcc := new String'("jvm-gnatcompile");
5402 when Targparm.CLI_Target =>
5403 Gcc := new String'("dotnet-gnatcompile");
5405 when Targparm.No_VM =>
5406 raise Program_Error;
5410 Display_Commands (not Quiet_Output);
5414 if Main_Project /= No_Project then
5416 -- For all library project, if the library file does not exist, put
5417 -- all the project sources in the queue, and flag the project so that
5418 -- the library is generated.
5420 if not Unique_Compile
5421 and then MLib.Tgt.Support_For_Libraries /= Prj.None
5423 for Proj in Project_Table.First ..
5424 Project_Table.Last (Project_Tree.Projects)
5426 if Project_Tree.Projects.Table (Proj).Library then
5427 Project_Tree.Projects.Table
5428 (Proj).Need_To_Build_Lib :=
5429 (not MLib.Tgt.Library_Exists_For (Proj, Project_Tree))
5430 and then (not Project_Tree.Projects.Table
5431 (Proj).Externally_Built);
5433 if Project_Tree.Projects.Table (Proj).Need_To_Build_Lib then
5435 -- If there is no object directory, then it will be
5436 -- impossible to build the library. So fail immediately.
5438 if Project_Tree.Projects.Table (Proj).Object_Directory =
5442 ("no object files to build library for project """
5444 (Project_Tree.Projects.Table (Proj).Name)
5446 Project_Tree.Projects.Table
5447 (Proj).Need_To_Build_Lib := False;
5450 if Verbose_Mode then
5452 ("Library file does not exist for project """);
5455 (Project_Tree.Projects.Table
5460 Insert_Project_Sources
5461 (The_Project => Proj,
5462 All_Projects => False,
5470 -- If a relative path output file has been specified, we add
5471 -- the exec directory.
5473 for J in reverse 1 .. Saved_Linker_Switches.Last - 1 loop
5474 if Saved_Linker_Switches.Table (J).all = Output_Flag.all then
5476 Exec_File_Name : constant String :=
5477 Saved_Linker_Switches.Table (J + 1).all;
5480 if not Is_Absolute_Path (Exec_File_Name) then
5482 (Project_Tree.Projects.Table
5483 (Main_Project).Exec_Directory.Name);
5485 if Name_Buffer (Name_Len) /= Directory_Separator then
5486 Name_Len := Name_Len + 1;
5487 Name_Buffer (Name_Len) := Directory_Separator;
5490 Name_Buffer (Name_Len + 1 ..
5491 Name_Len + Exec_File_Name'Length) :=
5493 Name_Len := Name_Len + Exec_File_Name'Length;
5494 Saved_Linker_Switches.Table (J + 1) :=
5495 new String'(Name_Buffer (1 .. Name_Len));
5503 -- If we are using a project file, for relative paths we add the
5504 -- current working directory for any relative path on the command
5505 -- line and the project directory, for any relative path in the
5509 Dir_Path : constant String_Access :=
5510 new String'(Get_Name_String
5511 (Project_Tree.Projects.Table
5512 (Main_Project).Directory.Name));
5514 for J in 1 .. Binder_Switches.Last loop
5515 Test_If_Relative_Path
5516 (Binder_Switches.Table (J),
5517 Parent => Dir_Path, Including_L_Switch => False);
5520 for J in 1 .. Saved_Binder_Switches.Last loop
5521 Test_If_Relative_Path
5522 (Saved_Binder_Switches.Table (J),
5523 Parent => Current_Work_Dir, Including_L_Switch => False);
5526 for J in 1 .. Linker_Switches.Last loop
5527 Test_If_Relative_Path
5528 (Linker_Switches.Table (J), Parent => Dir_Path);
5531 for J in 1 .. Saved_Linker_Switches.Last loop
5532 Test_If_Relative_Path
5533 (Saved_Linker_Switches.Table (J), Parent => Current_Work_Dir);
5536 for J in 1 .. Gcc_Switches.Last loop
5537 Test_If_Relative_Path
5538 (Gcc_Switches.Table (J),
5540 Including_Non_Switch => False);
5543 for J in 1 .. Saved_Gcc_Switches.Last loop
5544 Test_If_Relative_Path
5545 (Saved_Gcc_Switches.Table (J),
5546 Parent => Current_Work_Dir,
5547 Including_Non_Switch => False);
5552 -- We now put in the Binder_Switches and Linker_Switches tables, the
5553 -- binder and linker switches of the command line that have been put in
5554 -- the Saved_ tables. If a project file was used, then the command line
5555 -- switches will follow the project file switches.
5557 for J in 1 .. Saved_Binder_Switches.Last loop
5559 (Saved_Binder_Switches.Table (J),
5564 for J in 1 .. Saved_Linker_Switches.Last loop
5566 (Saved_Linker_Switches.Table (J),
5571 -- If no project file is used, we just put the gcc switches
5572 -- from the command line in the Gcc_Switches table.
5574 if Main_Project = No_Project then
5575 for J in 1 .. Saved_Gcc_Switches.Last loop
5577 (Saved_Gcc_Switches.Table (J),
5583 -- If there is a project, put the command line gcc switches in the
5584 -- variable The_Saved_Gcc_Switches. They are going to be used later
5585 -- in procedure Compile_Sources.
5587 The_Saved_Gcc_Switches :=
5588 new Argument_List (1 .. Saved_Gcc_Switches.Last + 1);
5590 for J in 1 .. Saved_Gcc_Switches.Last loop
5591 The_Saved_Gcc_Switches (J) := Saved_Gcc_Switches.Table (J);
5594 -- We never use gnat.adc when a project file is used
5596 The_Saved_Gcc_Switches (The_Saved_Gcc_Switches'Last) :=
5600 -- If there was a --GCC, --GNATBIND or --GNATLINK switch on
5601 -- the command line, then we have to use it, even if there was
5602 -- another switch in the project file.
5604 if Saved_Gcc /= null then
5608 if Saved_Gnatbind /= null then
5609 Gnatbind := Saved_Gnatbind;
5612 if Saved_Gnatlink /= null then
5613 Gnatlink := Saved_Gnatlink;
5616 Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gcc.all);
5617 Gnatbind_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatbind.all);
5618 Gnatlink_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Gnatlink.all);
5620 -- If we have specified -j switch both from the project file
5621 -- and on the command line, the one from the command line takes
5624 if Saved_Maximum_Processes = 0 then
5625 Saved_Maximum_Processes := Maximum_Processes;
5628 -- Allocate as many temporary mapping file names as the maximum
5629 -- number of compilation processed, for each possible project.
5631 The_Mapping_File_Names :=
5633 (No_Project .. Project_Table.Last (Project_Tree.Projects),
5634 1 .. Saved_Maximum_Processes);
5635 Last_Mapping_File_Names :=
5637 (No_Project .. Project_Table.Last (Project_Tree.Projects)
5640 The_Free_Mapping_File_Indices :=
5641 new Free_File_Indices
5642 (No_Project .. Project_Table.Last (Project_Tree.Projects),
5643 1 .. Saved_Maximum_Processes);
5644 Last_Free_Indices :=
5645 new Indices'(No_Project .. Project_Table.Last
5646 (Project_Tree.Projects) => 0);
5648 Bad_Compilation.Init;
5650 -- If project files are used, create the mapping of all the sources,
5651 -- so that the correct paths will be found. Otherwise, if there is
5652 -- a file which is not a source with the same name in a source directory
5653 -- this file may be incorrectly found.
5655 if Main_Project /= No_Project then
5656 Prj.Env.Create_Mapping (Project_Tree);
5659 Current_Main_Index := Main_Index;
5661 -- Here is where the make process is started
5663 -- We do the same process for each main
5665 Multiple_Main_Loop : for N_File in 1 .. Osint.Number_Of_Files loop
5667 -- First, find the executable name and path
5669 Executable := No_File;
5670 Executable_Obsolete := False;
5671 Non_Std_Executable :=
5672 Targparm.Executable_Extension_On_Target /= No_Name;
5674 -- Look inside the linker switches to see if the name of the final
5675 -- executable program was specified.
5678 J in reverse Linker_Switches.First .. Linker_Switches.Last
5680 if Linker_Switches.Table (J).all = Output_Flag.all then
5681 pragma Assert (J < Linker_Switches.Last);
5683 -- We cannot specify a single executable for several
5684 -- main subprograms!
5686 if Osint.Number_Of_Files > 1 then
5688 ("cannot specify a single executable " &
5689 "for several mains");
5692 Name_Len := Linker_Switches.Table (J + 1)'Length;
5693 Name_Buffer (1 .. Name_Len) :=
5694 Linker_Switches.Table (J + 1).all;
5695 Executable := Name_Enter;
5697 Verbose_Msg (Executable, "final executable");
5701 -- If the name of the final executable program was not specified
5702 -- then construct it from the main input file.
5704 if Executable = No_File then
5705 if Main_Project = No_Project then
5707 Executable_Name (Strip_Suffix (Main_Source_File));
5710 -- If we are using a project file, we attempt to remove the
5711 -- body (or spec) termination of the main subprogram. We find
5712 -- it the naming scheme of the project file. This avoids
5713 -- generating an executable "main.2" for a main subprogram
5714 -- "main.2.ada", when the body termination is ".2.ada".
5717 Prj.Util.Executable_Of
5718 (Main_Project, Project_Tree, Main_Source_File, Main_Index);
5722 if Main_Project /= No_Project
5724 Project_Tree.Projects.Table
5725 (Main_Project).Exec_Directory /= No_Path_Information
5728 Exec_File_Name : constant String :=
5729 Get_Name_String (Executable);
5732 if not Is_Absolute_Path (Exec_File_Name) then
5734 (Project_Tree.Projects.Table
5735 (Main_Project).Exec_Directory.Display_Name);
5737 if Name_Buffer (Name_Len) /= Directory_Separator then
5738 Name_Len := Name_Len + 1;
5739 Name_Buffer (Name_Len) := Directory_Separator;
5742 Name_Buffer (Name_Len + 1 ..
5743 Name_Len + Exec_File_Name'Length) :=
5746 Name_Len := Name_Len + Exec_File_Name'Length;
5747 Executable := Name_Find;
5750 Non_Std_Executable := True;
5754 if Do_Compile_Step then
5755 Recursive_Compilation_Step : declare
5756 Args : Argument_List (1 .. Gcc_Switches.Last);
5758 First_Compiled_File : File_Name_Type;
5759 Youngest_Obj_File : File_Name_Type;
5760 Youngest_Obj_Stamp : Time_Stamp_Type;
5762 Executable_Stamp : Time_Stamp_Type;
5763 -- Executable is the final executable program
5765 Library_Rebuilt : Boolean := False;
5768 for J in 1 .. Gcc_Switches.Last loop
5769 Args (J) := Gcc_Switches.Table (J);
5772 -- Now we invoke Compile_Sources for the current main
5775 (Main_Source => Main_Source_File,
5777 First_Compiled_File => First_Compiled_File,
5778 Most_Recent_Obj_File => Youngest_Obj_File,
5779 Most_Recent_Obj_Stamp => Youngest_Obj_Stamp,
5780 Main_Unit => Is_Main_Unit,
5781 Main_Index => Current_Main_Index,
5782 Compilation_Failures => Compilation_Failures,
5783 Check_Readonly_Files => Check_Readonly_Files,
5784 Do_Not_Execute => Do_Not_Execute,
5785 Force_Compilations => Force_Compilations,
5786 In_Place_Mode => In_Place_Mode,
5787 Keep_Going => Keep_Going,
5788 Initialize_ALI_Data => True,
5789 Max_Process => Saved_Maximum_Processes);
5791 if Verbose_Mode then
5792 Write_Str ("End of compilation");
5796 -- Make sure the queue will be reinitialized for the next round
5798 First_Q_Initialization := True;
5800 Total_Compilation_Failures :=
5801 Total_Compilation_Failures + Compilation_Failures;
5803 if Total_Compilation_Failures /= 0 then
5807 List_Bad_Compilations;
5808 Report_Compilation_Failed;
5812 -- Regenerate libraries, if there are any and if object files
5813 -- have been regenerated.
5815 if Main_Project /= No_Project
5816 and then MLib.Tgt.Support_For_Libraries /= Prj.None
5817 and then (Do_Bind_Step
5818 or Unique_Compile_All_Projects
5819 or not Compile_Only)
5820 and then (Do_Link_Step or N_File = Osint.Number_Of_Files)
5828 procedure Add_To_Library_Projs (Proj : Project_Id);
5829 -- Add project Project to table Library_Projs in
5830 -- decreasing depth order.
5832 --------------------------
5833 -- Add_To_Library_Projs --
5834 --------------------------
5836 procedure Add_To_Library_Projs (Proj : Project_Id) is
5840 Library_Projs.Increment_Last;
5841 Depth := Project_Tree.Projects.Table (Proj).Depth;
5843 -- Put the projects in decreasing depth order, so that
5844 -- if libA depends on libB, libB is first in order.
5846 Current := Library_Projs.Last;
5847 while Current > 1 loop
5848 Prj := Library_Projs.Table (Current - 1);
5849 exit when Project_Tree.Projects.Table
5850 (Prj).Depth >= Depth;
5851 Library_Projs.Table (Current) := Prj;
5852 Current := Current - 1;
5855 Library_Projs.Table (Current) := Proj;
5856 end Add_To_Library_Projs;
5858 -- Start of processing for ??? (should name declare block
5859 -- or probably better, break this out as a nested proc).
5862 -- Put in Library_Projs table all library project
5863 -- file ids when the library need to be rebuilt.
5865 for Proj1 in Project_Table.First ..
5866 Project_Table.Last (Project_Tree.Projects)
5868 if Project_Tree.Projects.Table
5869 (Proj1).Standalone_Library
5871 There_Are_Stand_Alone_Libraries := True;
5874 if Project_Tree.Projects.Table (Proj1).Library then
5875 MLib.Prj.Check_Library (Proj1, Project_Tree);
5878 if Project_Tree.Projects.Table
5879 (Proj1).Need_To_Build_Lib
5881 Add_To_Library_Projs (Proj1);
5885 -- Check if importing libraries should be regenerated
5886 -- because at least an imported library will be
5887 -- regenerated or is more recent.
5889 for Proj1 in Project_Table.First ..
5890 Project_Table.Last (Project_Tree.Projects)
5892 if Project_Tree.Projects.Table (Proj1).Library
5894 Project_Tree.Projects.Table (Proj1).Library_Kind /=
5896 and then not Project_Tree.Projects.Table
5897 (Proj1).Need_To_Build_Lib
5898 and then not Project_Tree.Projects.Table
5899 (Proj1).Externally_Built
5902 List : Project_List;
5903 Element : Project_Element;
5905 Rebuild : Boolean := False;
5907 Lib_Timestamp1 : constant Time_Stamp_Type :=
5908 Project_Tree.Projects.Table
5912 List := Project_Tree.Projects.Table (Proj1).
5913 All_Imported_Projects;
5914 while List /= Empty_Project_List loop
5916 Project_Tree.Project_Lists.Table (List);
5917 Proj2 := Element.Project;
5920 Project_Tree.Projects.Table (Proj2).Library
5922 if Project_Tree.Projects.Table (Proj2).
5926 Project_Tree.Projects.Table
5934 List := Element.Next;
5938 Project_Tree.Projects.Table
5939 (Proj1).Need_To_Build_Lib := True;
5940 Add_To_Library_Projs (Proj1);
5946 -- Reset the flags Need_To_Build_Lib for the next main,
5947 -- to avoid rebuilding libraries uselessly.
5949 for Proj1 in Project_Table.First ..
5950 Project_Table.Last (Project_Tree.Projects)
5952 Project_Tree.Projects.Table
5953 (Proj1).Need_To_Build_Lib := False;
5957 -- Build the libraries, if any need to be built
5959 for J in 1 .. Library_Projs.Last loop
5960 Library_Rebuilt := True;
5962 -- If a library is rebuilt, then executables are obsolete
5964 Executable_Obsolete := True;
5966 MLib.Prj.Build_Library
5967 (For_Project => Library_Projs.Table (J),
5968 In_Tree => Project_Tree,
5969 Gnatbind => Gnatbind.all,
5970 Gnatbind_Path => Gnatbind_Path,
5972 Gcc_Path => Gcc_Path);
5976 if List_Dependencies then
5977 if First_Compiled_File /= No_File then
5979 (First_Compiled_File,
5980 "must be recompiled. Can't generate dependence list.");
5985 elsif First_Compiled_File = No_File
5986 and then not Do_Bind_Step
5987 and then not Quiet_Output
5988 and then not Library_Rebuilt
5989 and then Osint.Number_Of_Files = 1
5991 Inform (Msg => "objects up to date.");
5993 elsif Do_Not_Execute
5994 and then First_Compiled_File /= No_File
5996 Write_Name (First_Compiled_File);
6000 -- Stop after compile step if any of:
6002 -- 1) -n (Do_Not_Execute) specified
6004 -- 2) -M (List_Dependencies) specified (also sets
6005 -- Do_Not_Execute above, so this is probably superfluous).
6007 -- 3) -c (Compile_Only) specified, but not -b (Bind_Only)
6009 -- 4) Made unit cannot be a main unit
6012 or List_Dependencies
6014 or not Is_Main_Unit)
6015 and then not No_Main_Subprogram
6016 and then not Build_Bind_And_Link_Full_Project)
6017 or else Unique_Compile
6019 if Osint.Number_Of_Files = 1 then
6020 exit Multiple_Main_Loop;
6027 -- If the objects were up-to-date check if the executable file
6028 -- is also up-to-date. For now always bind and link on the JVM
6029 -- since there is currently no simple way to check the
6030 -- up-to-date status of objects
6032 if Targparm.VM_Target /= JVM_Target
6033 and then First_Compiled_File = No_File
6035 Executable_Stamp := File_Stamp (Executable);
6037 if not Executable_Obsolete then
6038 Executable_Obsolete :=
6039 Youngest_Obj_Stamp > Executable_Stamp;
6042 if not Executable_Obsolete then
6043 for Index in reverse 1 .. Dependencies.Last loop
6045 (Dependencies.Table (Index).Depends_On)
6047 Enter_Into_Obsoleted
6048 (Dependencies.Table (Index).This);
6052 Executable_Obsolete := Is_In_Obsoleted (Main_Source_File);
6056 if not Executable_Obsolete then
6058 -- If no Ada object files obsolete the executable, check
6059 -- for younger or missing linker files.
6061 Check_Linker_Options
6064 Youngest_Obj_Stamp);
6066 Executable_Obsolete := Youngest_Obj_File /= No_File;
6069 -- Return if the executable is up to date
6070 -- and otherwise motivate the relink/rebind.
6072 if not Executable_Obsolete then
6073 if not Quiet_Output then
6074 Inform (Executable, "up to date.");
6077 if Osint.Number_Of_Files = 1 then
6078 exit Multiple_Main_Loop;
6085 if Executable_Stamp (1) = ' ' then
6086 if not No_Main_Subprogram then
6087 Verbose_Msg (Executable, "missing.", Prefix => " ");
6090 elsif Youngest_Obj_Stamp (1) = ' ' then
6092 (Youngest_Obj_File, "missing.", Prefix => " ");
6094 elsif Youngest_Obj_Stamp > Executable_Stamp then
6097 "(" & String (Youngest_Obj_Stamp) & ") newer than",
6099 "(" & String (Executable_Stamp) & ")");
6103 (Executable, "needs to be rebuilt", Prefix => " ");
6107 end Recursive_Compilation_Step;
6110 -- For binding and linking, we need to be in the object directory of
6111 -- the main project.
6113 if Main_Project /= No_Project then
6114 Change_To_Object_Directory (Main_Project);
6117 -- If we are here, it means that we need to rebuilt the current
6118 -- main. So we set Executable_Obsolete to True to make sure that
6119 -- the subsequent mains will be rebuilt.
6121 Main_ALI_In_Place_Mode_Step : declare
6122 ALI_File : File_Name_Type;
6123 Src_File : File_Name_Type;
6126 Src_File := Strip_Directory (Main_Source_File);
6127 ALI_File := Lib_File_Name (Src_File, Current_Main_Index);
6128 Main_ALI_File := Full_Lib_File_Name (ALI_File);
6130 -- When In_Place_Mode, the library file can be located in the
6131 -- Main_Source_File directory which may not be present in the
6132 -- library path. If it is not present then use the corresponding
6133 -- library file name.
6135 if Main_ALI_File = No_File and then In_Place_Mode then
6136 Get_Name_String (Get_Directory (Full_Source_Name (Src_File)));
6137 Get_Name_String_And_Append (ALI_File);
6138 Main_ALI_File := Name_Find;
6139 Main_ALI_File := Full_Lib_File_Name (Main_ALI_File);
6142 if Main_ALI_File = No_File then
6143 Make_Failed ("could not find the main ALI file");
6145 end Main_ALI_In_Place_Mode_Step;
6147 if Do_Bind_Step then
6149 Args : Argument_List
6150 (Binder_Switches.First .. Binder_Switches.Last + 2);
6151 -- The arguments for the invocation of gnatbind
6153 Last_Arg : Natural := Binder_Switches.Last;
6154 -- Index of the last argument in Args
6156 Shared_Libs : Boolean := False;
6157 -- Set to True when there are shared library project files or
6158 -- when gnatbind is invoked with -shared.
6161 -- Check if there are shared libraries, so that gnatbind is
6162 -- called with -shared. Check also if gnatbind is called with
6163 -- -shared, so that gnatlink is called with -shared-libgcc
6164 -- ensuring that the shared version of libgcc will be used.
6166 if Main_Project /= No_Project
6167 and then MLib.Tgt.Support_For_Libraries /= Prj.None
6169 for Proj in Project_Table.First ..
6170 Project_Table.Last (Project_Tree.Projects)
6172 if Project_Tree.Projects.Table (Proj).Library
6173 and then Project_Tree.Projects.Table
6174 (Proj).Library_Kind /= Static
6176 Shared_Libs := True;
6177 Bind_Shared := Shared_Switch'Access;
6183 -- Check now for switch -shared
6185 if not Shared_Libs then
6186 for J in Binder_Switches.First .. Last_Arg loop
6187 if Binder_Switches.Table (J).all = "-shared" then
6188 Shared_Libs := True;
6194 -- If shared libraries present, invoke gnatlink with
6198 Link_With_Shared_Libgcc := Shared_Libgcc_Switch'Access;
6201 -- Get all the binder switches
6203 for J in Binder_Switches.First .. Last_Arg loop
6204 Args (J) := Binder_Switches.Table (J);
6207 if There_Are_Stand_Alone_Libraries then
6208 Last_Arg := Last_Arg + 1;
6209 Args (Last_Arg) := Force_Elab_Flags_String'Access;
6212 if Main_Project /= No_Project then
6214 -- Put all the source directories in ADA_INCLUDE_PATH,
6215 -- and all the object directories in ADA_OBJECTS_PATH.
6217 Prj.Env.Set_Ada_Paths (Main_Project, Project_Tree, True);
6219 -- If switch -C was specified, create a binder mapping file
6221 if Create_Mapping_File then
6222 Create_Binder_Mapping_File (Args, Last_Arg);
6228 Bind (Main_ALI_File,
6229 Bind_Shared.all & Args (Args'First .. Last_Arg));
6234 -- If -dn was not specified, delete the temporary mapping
6235 -- file, if one was created.
6237 if not Debug.Debug_Flag_N
6238 and then Mapping_Path /= No_Path
6240 Delete_File (Get_Name_String (Mapping_Path), Discard);
6243 -- And reraise the exception
6248 -- If -dn was not specified, delete the temporary mapping file,
6249 -- if one was created.
6251 if not Debug.Debug_Flag_N and then Mapping_Path /= No_Path then
6252 Delete_File (Get_Name_String (Mapping_Path), Discard);
6257 if Do_Link_Step then
6259 Linker_Switches_Last : constant Integer := Linker_Switches.Last;
6260 Path_Option : constant String_Access :=
6261 MLib.Linker_Library_Path_Option;
6262 There_Are_Libraries : Boolean := False;
6268 if not Run_Path_Option then
6269 Linker_Switches.Increment_Last;
6270 Linker_Switches.Table (Linker_Switches.Last) :=
6274 if Main_Project /= No_Project then
6275 Library_Paths.Set_Last (0);
6278 if MLib.Tgt.Support_For_Libraries /= Prj.None then
6280 -- Check for library projects
6282 for Proj1 in Project_Table.First ..
6283 Project_Table.Last (Project_Tree.Projects)
6285 if Proj1 /= Main_Project
6287 Project_Tree.Projects.Table (Proj1).Library
6289 -- Add this project to table Library_Projs
6291 There_Are_Libraries := True;
6292 Depth := Project_Tree.Projects.Table (Proj1).Depth;
6293 Library_Projs.Increment_Last;
6294 Current := Library_Projs.Last;
6296 -- Any project with a greater depth should be
6297 -- after this project in the list.
6299 while Current > 1 loop
6300 Proj2 := Library_Projs.Table (Current - 1);
6301 exit when Project_Tree.Projects.Table
6302 (Proj2).Depth <= Depth;
6303 Library_Projs.Table (Current) := Proj2;
6304 Current := Current - 1;
6307 Library_Projs.Table (Current) := Proj1;
6309 -- If it is not a static library and path option
6310 -- is set, add it to the Library_Paths table.
6312 if Project_Tree.Projects.Table
6313 (Proj1).Library_Kind /= Static
6314 and then Path_Option /= null
6316 Library_Paths.Increment_Last;
6317 Library_Paths.Table (Library_Paths.Last) :=
6320 (Project_Tree.Projects.Table
6321 (Proj1).Library_Dir.Display_Name));
6326 for Index in 1 .. Library_Projs.Last loop
6328 -- Add the -L switch
6330 Linker_Switches.Increment_Last;
6331 Linker_Switches.Table (Linker_Switches.Last) :=
6334 (Project_Tree.Projects.Table
6335 (Library_Projs.Table (Index)).
6336 Library_Dir.Display_Name));
6338 -- Add the -l switch
6340 Linker_Switches.Increment_Last;
6341 Linker_Switches.Table (Linker_Switches.Last) :=
6344 (Project_Tree.Projects.Table
6345 (Library_Projs.Table (Index)).
6350 if There_Are_Libraries then
6352 -- If Path_Option is not null, create the switch
6353 -- ("-Wl,-rpath," or equivalent) with all the non static
6354 -- library dirs plus the standard GNAT library dir.
6355 -- We do that only if Run_Path_Option is True
6356 -- (not disabled by -R switch).
6358 if Run_Path_Option and Path_Option /= null then
6360 Option : String_Access;
6361 Length : Natural := Path_Option'Length;
6365 if MLib.Separate_Run_Path_Options then
6367 -- We are going to create one switch of the form
6368 -- "-Wl,-rpath,dir_N" for each directory to
6371 -- One switch for each library directory
6374 Library_Paths.First .. Library_Paths.Last
6376 Linker_Switches.Increment_Last;
6377 Linker_Switches.Table
6378 (Linker_Switches.Last) := new String'
6380 Library_Paths.Table (Index).all);
6383 -- One switch for the standard GNAT library dir
6385 Linker_Switches.Increment_Last;
6386 Linker_Switches.Table
6387 (Linker_Switches.Last) := new String'
6388 (Path_Option.all & MLib.Utl.Lib_Directory);
6391 -- We are going to create one switch of the form
6392 -- "-Wl,-rpath,dir_1:dir_2:dir_3"
6395 Library_Paths.First .. Library_Paths.Last
6397 -- Add the length of the library dir plus one
6398 -- for the directory separator.
6402 Library_Paths.Table (Index)'Length + 1;
6405 -- Finally, add the length of the standard GNAT
6408 Length := Length + MLib.Utl.Lib_Directory'Length;
6409 Option := new String (1 .. Length);
6410 Option (1 .. Path_Option'Length) :=
6412 Current := Path_Option'Length;
6414 -- Put each library dir followed by a dir
6418 Library_Paths.First .. Library_Paths.Last
6423 Library_Paths.Table (Index)'Length) :=
6424 Library_Paths.Table (Index).all;
6427 Library_Paths.Table (Index)'Length + 1;
6428 Option (Current) := Path_Separator;
6431 -- Finally put the standard GNAT library dir
6435 Current + MLib.Utl.Lib_Directory'Length) :=
6436 MLib.Utl.Lib_Directory;
6438 -- And add the switch to the linker switches
6440 Linker_Switches.Increment_Last;
6441 Linker_Switches.Table (Linker_Switches.Last) :=
6449 -- Put the object directories in ADA_OBJECTS_PATH
6451 Prj.Env.Set_Ada_Paths (Main_Project, Project_Tree, False);
6453 -- Check for attributes Linker'Linker_Options in projects
6454 -- other than the main project
6457 Linker_Options : constant String_List :=
6458 Linker_Options_Switches
6459 (Main_Project, Project_Tree);
6461 for Option in Linker_Options'Range loop
6462 Linker_Switches.Increment_Last;
6463 Linker_Switches.Table (Linker_Switches.Last) :=
6464 Linker_Options (Option);
6470 Args : Argument_List
6471 (Linker_Switches.First .. Linker_Switches.Last + 2);
6473 Last_Arg : Integer := Linker_Switches.First - 1;
6474 Skip : Boolean := False;
6477 -- Get all the linker switches
6479 for J in Linker_Switches.First .. Linker_Switches.Last loop
6483 elsif Non_Std_Executable
6484 and then Linker_Switches.Table (J).all = "-o"
6488 -- Here we capture and duplicate the linker argument. We
6489 -- need to do the duplication since the arguments will
6490 -- get normalized. Not doing so will result in calling
6491 -- normalized two times for the same set of arguments if
6492 -- gnatmake is passed multiple mains. This can result in
6493 -- the wrong argument being passed to the linker.
6496 Last_Arg := Last_Arg + 1;
6498 new String'(Linker_Switches.Table (J).all);
6502 -- If need be, add the -o switch
6504 if Non_Std_Executable then
6505 Last_Arg := Last_Arg + 1;
6506 Args (Last_Arg) := new String'("-o");
6507 Last_Arg := Last_Arg + 1;
6509 new String'(Get_Name_String (Executable));
6512 -- And invoke the linker
6515 Success : Boolean := False;
6517 Link (Main_ALI_File,
6518 Link_With_Shared_Libgcc.all &
6519 Args (Args'First .. Last_Arg),
6523 Successful_Links.Increment_Last;
6524 Successful_Links.Table (Successful_Links.Last) :=
6527 elsif Osint.Number_Of_Files = 1 or not Keep_Going then
6528 Make_Failed ("*** link failed.");
6532 Write_Line ("*** link failed");
6534 if Commands_To_Stdout then
6535 Set_Standard_Output;
6538 Failed_Links.Increment_Last;
6539 Failed_Links.Table (Failed_Links.Last) :=
6545 Linker_Switches.Set_Last (Linker_Switches_Last);
6549 -- We go to here when we skip the bind and link steps
6553 -- We go to the next main, if we did not process the last one
6555 if N_File < Osint.Number_Of_Files then
6556 Main_Source_File := Next_Main_Source;
6558 if Current_File_Index /= No_Index then
6559 Main_Index := Current_File_Index;
6562 if Main_Project /= No_Project then
6564 -- Find the file name of the main unit
6567 Main_Source_File_Name : constant String :=
6568 Get_Name_String (Main_Source_File);
6570 Main_Unit_File_Name : constant String :=
6572 File_Name_Of_Library_Unit_Body
6573 (Name => Main_Source_File_Name,
6574 Project => Main_Project,
6575 In_Tree => Project_Tree,
6576 Main_Project_Only =>
6577 not Unique_Compile);
6579 The_Packages : constant Package_Id :=
6580 Project_Tree.Projects.Table
6581 (Main_Project).Decl.Packages;
6583 Binder_Package : constant Prj.Package_Id :=
6585 (Name => Name_Binder,
6586 In_Packages => The_Packages,
6587 In_Tree => Project_Tree);
6589 Linker_Package : constant Prj.Package_Id :=
6591 (Name => Name_Linker,
6592 In_Packages => The_Packages,
6593 In_Tree => Project_Tree);
6596 -- We fail if we cannot find the main source file
6597 -- as an immediate source of the main project file.
6599 if Main_Unit_File_Name = "" then
6600 Make_Failed ('"' & Main_Source_File_Name
6601 & """ is not a unit of project "
6602 & Project_File_Name.all & ".");
6605 -- Remove any directory information from the main
6606 -- source file name.
6609 Pos : Natural := Main_Unit_File_Name'Last;
6613 exit when Pos < Main_Unit_File_Name'First
6615 Main_Unit_File_Name (Pos) = Directory_Separator;
6619 Name_Len := Main_Unit_File_Name'Last - Pos;
6621 Name_Buffer (1 .. Name_Len) :=
6623 (Pos + 1 .. Main_Unit_File_Name'Last);
6625 Main_Source_File := Name_Find;
6629 -- We now deal with the binder and linker switches.
6630 -- If no project file is used, there is nothing to do
6631 -- because the binder and linker switches are the same
6634 -- Reset the tables Binder_Switches and Linker_Switches
6636 Binder_Switches.Set_Last (Last_Binder_Switch);
6637 Linker_Switches.Set_Last (Last_Linker_Switch);
6639 -- Add binder switches from the project file for this main,
6642 if Do_Bind_Step and Binder_Package /= No_Package then
6643 if Verbose_Mode then
6644 Write_Str ("Adding binder switches for """);
6645 Write_Str (Main_Unit_File_Name);
6650 (File_Name => Main_Unit_File_Name,
6651 Index => Main_Index,
6652 The_Package => Binder_Package,
6656 -- Add linker switches from the project file for this main,
6659 if Do_Link_Step and Linker_Package /= No_Package then
6660 if Verbose_Mode then
6661 Write_Str ("Adding linker switches for""");
6662 Write_Str (Main_Unit_File_Name);
6667 (File_Name => Main_Unit_File_Name,
6668 Index => Main_Index,
6669 The_Package => Linker_Package,
6673 -- As we are using a project file, for relative paths we add
6674 -- the current working directory for any relative path on
6675 -- the command line and the project directory, for any
6676 -- relative path in the project file.
6679 Dir_Path : constant String_Access :=
6680 new String'(Get_Name_String
6681 (Project_Tree.Projects.Table
6682 (Main_Project).Directory.Name));
6685 J in Last_Binder_Switch + 1 .. Binder_Switches.Last
6687 Test_If_Relative_Path
6688 (Binder_Switches.Table (J),
6689 Parent => Dir_Path, Including_L_Switch => False);
6693 J in Last_Linker_Switch + 1 .. Linker_Switches.Last
6695 Test_If_Relative_Path
6696 (Linker_Switches.Table (J), Parent => Dir_Path);
6700 -- We now put in the Binder_Switches and Linker_Switches
6701 -- tables, the binder and linker switches of the command
6702 -- line that have been put in the Saved_ tables.
6703 -- These switches will follow the project file switches.
6705 for J in 1 .. Saved_Binder_Switches.Last loop
6707 (Saved_Binder_Switches.Table (J),
6712 for J in 1 .. Saved_Linker_Switches.Last loop
6714 (Saved_Linker_Switches.Table (J),
6722 -- Remove all marks to be sure to check sources for all executables,
6723 -- as the switches may be different and -s may be in use.
6726 end loop Multiple_Main_Loop;
6728 if Failed_Links.Last > 0 then
6729 for Index in 1 .. Successful_Links.Last loop
6730 Write_Str ("Linking of """);
6731 Write_Str (Get_Name_String (Successful_Links.Table (Index)));
6732 Write_Line (""" succeeded.");
6737 for Index in 1 .. Failed_Links.Last loop
6738 Write_Str ("Linking of """);
6739 Write_Str (Get_Name_String (Failed_Links.Table (Index)));
6740 Write_Line (""" failed.");
6743 if Commands_To_Stdout then
6744 Set_Standard_Output;
6747 if Total_Compilation_Failures = 0 then
6748 Report_Compilation_Failed;
6752 if Total_Compilation_Failures /= 0 then
6753 List_Bad_Compilations;
6754 Report_Compilation_Failed;
6757 -- Delete the temporary mapping file that was created if we are
6758 -- using project files.
6760 Delete_All_Temp_Files;
6765 Write_Line (Exception_Information (X));
6766 Make_Failed ("INTERNAL ERROR. Please report.");
6773 function Hash (F : File_Name_Type) return Header_Num is
6775 return Header_Num (1 + F mod Max_Header);
6778 --------------------
6779 -- In_Ada_Lib_Dir --
6780 --------------------
6782 function In_Ada_Lib_Dir (File : File_Name_Type) return Boolean is
6783 D : constant File_Name_Type := Get_Directory (File);
6784 B : constant Byte := Get_Name_Table_Byte (D);
6786 return (B and Ada_Lib_Dir) /= 0;
6789 -----------------------
6790 -- Init_Mapping_File --
6791 -----------------------
6793 procedure Init_Mapping_File
6794 (Project : Project_Id;
6795 File_Index : in out Natural)
6797 FD : File_Descriptor;
6799 -- For call to Close
6802 -- Increase the index of the last mapping file for this project
6804 Last_Mapping_File_Names (Project) :=
6805 Last_Mapping_File_Names (Project) + 1;
6807 -- If there is a project file, call Create_Mapping_File with
6810 if Project /= No_Project then
6811 Prj.Env.Create_Mapping_File
6813 In_Tree => Project_Tree,
6814 Language => No_Name,
6815 Name => The_Mapping_File_Names
6816 (Project, Last_Mapping_File_Names (Project)));
6818 -- Otherwise, just create an empty file
6821 Tempdir.Create_Temp_File
6823 The_Mapping_File_Names
6824 (No_Project, Last_Mapping_File_Names (No_Project)));
6826 if FD = Invalid_FD then
6827 Make_Failed ("disk full");
6831 (The_Mapping_File_Names
6832 (No_Project, Last_Mapping_File_Names (No_Project)));
6838 Make_Failed ("disk full");
6842 -- And return the index of the newly created file
6844 File_Index := Last_Mapping_File_Names (Project);
6845 end Init_Mapping_File;
6853 First_Q_Initialization := False;
6855 Q.Set_Last (Q.First);
6862 procedure Initialize is
6864 procedure Check_Version_And_Help is
6865 new Check_Version_And_Help_G (Makeusg);
6867 -- Start of processing for Initialize
6870 Prj.Set_Mode (Ada_Only);
6872 -- Override default initialization of Check_Object_Consistency since
6873 -- this is normally False for GNATBIND, but is True for GNATMAKE since
6874 -- we do not need to check source consistency again once GNATMAKE has
6875 -- looked at the sources to check.
6877 Check_Object_Consistency := True;
6879 -- Package initializations. The order of calls is important here
6881 Output.Set_Standard_Error;
6884 Binder_Switches.Init;
6885 Linker_Switches.Init;
6892 Prj.Initialize (Project_Tree);
6896 RTS_Specified := null;
6900 -- Add the directory where gnatmake is invoked in front of the
6901 -- path, if gnatmake is invoked from a bin directory or with directory
6902 -- information. Only do this if the platform is not VMS, where the
6903 -- notion of path does not really exist.
6907 Prefix : constant String := Executable_Prefix_Path;
6908 Command : constant String := Command_Name;
6911 if Prefix'Length > 0 then
6913 PATH : constant String :=
6914 Prefix & Directory_Separator & "bin" &
6916 Getenv ("PATH").all;
6918 Setenv ("PATH", PATH);
6922 for Index in reverse Command'Range loop
6923 if Command (Index) = Directory_Separator then
6925 Absolute_Dir : constant String :=
6927 (Command (Command'First .. Index));
6928 PATH : constant String :=
6931 Getenv ("PATH").all;
6933 Setenv ("PATH", PATH);
6943 -- Scan the switches and arguments
6945 -- First, scan to detect --version and/or --help
6947 Check_Version_And_Help ("GNATMAKE", "1995");
6949 -- Scan again the switch and arguments, now that we are sure that they
6950 -- do not include --version or --help.
6952 Scan_Args : for Next_Arg in 1 .. Argument_Count loop
6953 Scan_Make_Arg (Argument (Next_Arg), And_Save => True);
6956 if Commands_To_Stdout then
6957 Set_Standard_Output;
6960 if Usage_Requested then
6964 -- Test for trailing -P switch
6966 if Project_File_Name_Present and then Project_File_Name = null then
6967 Make_Failed ("project file name missing after -P");
6969 -- Test for trailing -o switch
6971 elsif Output_File_Name_Present
6972 and then not Output_File_Name_Seen
6974 Make_Failed ("output file name missing after -o");
6976 -- Test for trailing -D switch
6978 elsif Object_Directory_Present
6979 and then not Object_Directory_Seen then
6980 Make_Failed ("object directory missing after -D");
6983 -- Test for simultaneity of -i and -D
6985 if Object_Directory_Path /= null and then In_Place_Mode then
6986 Make_Failed ("-i and -D cannot be used simultaneously");
6989 -- Deal with -C= switch
6991 if Gnatmake_Mapping_File /= null then
6993 -- First, check compatibility with other switches
6995 if Project_File_Name /= null then
6996 Make_Failed ("-C= switch is not compatible with -P switch");
6998 elsif Saved_Maximum_Processes > 1 then
6999 Make_Failed ("-C= switch is not compatible with -jnnn switch");
7002 Fmap.Initialize (Gnatmake_Mapping_File.all);
7004 ("-gnatem=" & Gnatmake_Mapping_File.all,
7009 if Project_File_Name /= null then
7011 -- A project file was specified by a -P switch
7013 if Verbose_Mode then
7015 Write_Str ("Parsing project file """);
7016 Write_Str (Project_File_Name.all);
7021 -- Avoid looking in the current directory for ALI files
7023 -- Look_In_Primary_Dir := False;
7025 -- Set the project parsing verbosity to whatever was specified
7026 -- by a possible -vP switch.
7028 Prj.Pars.Set_Verbosity (To => Current_Verbosity);
7030 -- Parse the project file.
7031 -- If there is an error, Main_Project will still be No_Project.
7034 (Project => Main_Project,
7035 In_Tree => Project_Tree,
7036 Project_File_Name => Project_File_Name.all,
7037 Packages_To_Check => Packages_To_Check_By_Gnatmake);
7039 -- The parsing of project files may have changed the current output
7041 if Commands_To_Stdout then
7042 Set_Standard_Output;
7047 if Main_Project = No_Project then
7049 ("""" & Project_File_Name.all & """ processing failed");
7052 Create_Mapping_File := True;
7054 if Verbose_Mode then
7056 Write_Str ("Parsing of project file """);
7057 Write_Str (Project_File_Name.all);
7058 Write_Str (""" is finished.");
7062 -- We add the source directories and the object directories
7063 -- to the search paths.
7065 Add_Source_Directories (Main_Project, Project_Tree);
7066 Add_Object_Directories (Main_Project, Project_Tree);
7068 -- Compute depth of each project
7070 for Proj in Project_Table.First ..
7071 Project_Table.Last (Project_Tree.Projects)
7073 Project_Tree.Projects.Table (Proj).Seen := False;
7074 Project_Tree.Projects.Table (Proj).Depth := 0;
7077 Recursive_Compute_Depth (Main_Project, Depth => 1);
7079 -- For each project compute the list of the projects it imports
7080 -- directly or indirectly.
7082 for Proj in Project_Table.First ..
7083 Project_Table.Last (Project_Tree.Projects)
7085 Compute_All_Imported_Projects (Proj);
7090 Osint.Add_Default_Search_Dirs;
7092 -- Source file lookups should be cached for efficiency. Source files
7093 -- are not supposed to change. However, we do that now only if no
7094 -- project file is used; if a project file is used, we do it just
7095 -- after changing the directory to the object directory.
7097 Osint.Source_File_Data (Cache => True);
7099 -- Read gnat.adc file to initialize Fname.UF
7101 Fname.UF.Initialize;
7104 Fname.SF.Read_Source_File_Name_Pragmas;
7107 when Err : SFN_Scan.Syntax_Error_In_GNAT_ADC =>
7108 Make_Failed (Exception_Message (Err));
7112 -- Make sure no project object directory is recorded
7114 Project_Of_Current_Object_Directory := No_Project;
7118 ----------------------------
7119 -- Insert_Project_Sources --
7120 ----------------------------
7122 procedure Insert_Project_Sources
7123 (The_Project : Project_Id;
7124 All_Projects : Boolean;
7127 Put_In_Q : Boolean := Into_Q;
7129 Sfile : File_Name_Type;
7132 Extending : constant Boolean :=
7133 Project_Tree.Projects.Table
7134 (The_Project).Extends /= No_Project;
7136 function Check_Project (P : Project_Id) return Boolean;
7137 -- Returns True if P is The_Project or a project extended by The_Project
7143 function Check_Project (P : Project_Id) return Boolean is
7145 if All_Projects or P = The_Project then
7148 elsif Extending then
7150 Data : Project_Data :=
7151 Project_Tree.Projects.Table (The_Project);
7155 if P = Data.Extends then
7159 Data := Project_Tree.Projects.Table (Data.Extends);
7160 exit when Data.Extends = No_Project;
7168 -- Start of processing for Insert_Project_Sources
7171 -- For all the sources in the project files,
7173 for Id in Unit_Table.First ..
7174 Unit_Table.Last (Project_Tree.Units)
7176 Unit := Project_Tree.Units.Table (Id);
7180 -- If there is a source for the body, and the body has not been
7183 if Unit.File_Names (Body_Part).Name /= No_File
7184 and then Unit.File_Names (Body_Part).Path.Name /= Slash
7186 -- And it is a source for the specified project
7188 if Check_Project (Unit.File_Names (Body_Part).Project) then
7190 -- If we don't have a spec, we cannot consider the source
7191 -- if it is a subunit
7193 if Unit.File_Names (Specification).Name = No_File then
7195 Src_Ind : Source_File_Index;
7197 -- Here we are cheating a little bit: we don't want to
7198 -- use Sinput.L, because it depends on the GNAT tree
7199 -- (Atree, Sinfo, ...). So, we pretend that it is a
7200 -- project file, and we use Sinput.P.
7202 -- Source_File_Is_Subunit is just scanning through the
7203 -- file until it finds one of the reserved words
7204 -- separate, procedure, function, generic or package.
7205 -- Fortunately, these Ada reserved words are also
7206 -- reserved for project files.
7209 Src_Ind := Sinput.P.Load_Project_File
7211 (Unit.File_Names (Body_Part).Path.Name));
7213 -- If it is a subunit, discard it
7215 if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
7219 Sfile := Unit.File_Names (Body_Part).Display_Name;
7220 Index := Unit.File_Names (Body_Part).Index;
7225 Sfile := Unit.File_Names (Body_Part).Display_Name;
7226 Index := Unit.File_Names (Body_Part).Index;
7230 elsif Unit.File_Names (Specification).Name /= No_File
7231 and then Unit.File_Names (Specification).Path.Name /= Slash
7232 and then Check_Project (Unit.File_Names (Specification).Project)
7234 -- If there is no source for the body, but there is a source
7235 -- for the spec which has not been locally removed, then we take
7238 Sfile := Unit.File_Names (Specification).Display_Name;
7239 Index := Unit.File_Names (Specification).Index;
7242 -- If Put_In_Q is True, we insert into the Q
7246 -- For the first source inserted into the Q, we need to initialize
7247 -- the Q, but not for the subsequent sources.
7249 if First_Q_Initialization then
7253 -- And of course, we only insert in the Q if the source is not
7256 if Sfile /= No_File and then not Is_Marked (Sfile, Index) then
7257 if Verbose_Mode then
7258 Write_Str ("Adding """);
7259 Write_Str (Get_Name_String (Sfile));
7260 Write_Line (""" to the queue");
7263 Insert_Q (Sfile, Index => Index);
7264 Mark (Sfile, Index);
7267 elsif Sfile /= No_File then
7269 -- If Put_In_Q is False, we add the source as if it were specified
7270 -- on the command line, and we set Put_In_Q to True, so that the
7271 -- following sources will be put directly in the queue. This will
7272 -- allow parallel compilation processes if -jx switch is used.
7274 if Verbose_Mode then
7275 Write_Str ("Adding """);
7276 Write_Str (Get_Name_String (Sfile));
7277 Write_Line (""" as if on the command line");
7280 Osint.Add_File (Get_Name_String (Sfile), Index);
7283 -- As we may look into the Q later, ensure the Q has been
7284 -- initialized to avoid errors.
7286 if First_Q_Initialization then
7291 end Insert_Project_Sources;
7298 (Source_File : File_Name_Type;
7299 Source_Unit : Unit_Name_Type := No_Unit_Name;
7303 if Debug.Debug_Flag_Q then
7304 Write_Str (" Q := Q + [ ");
7305 Write_Name (Source_File);
7317 (File => Source_File,
7318 Unit => Source_Unit,
7323 ---------------------
7324 -- Is_In_Obsoleted --
7325 ---------------------
7327 function Is_In_Obsoleted (F : File_Name_Type) return Boolean is
7334 Name : constant String := Get_Name_String (F);
7336 F2 : File_Name_Type;
7340 while First > Name'First
7341 and then Name (First - 1) /= Directory_Separator
7342 and then Name (First - 1) /= '/'
7347 if First /= Name'First then
7349 Add_Str_To_Name_Buffer (Name (First .. Name'Last));
7356 return Obsoleted.Get (F2);
7359 end Is_In_Obsoleted;
7361 ----------------------------
7362 -- Is_In_Object_Directory --
7363 ----------------------------
7365 function Is_In_Object_Directory
7366 (Source_File : File_Name_Type;
7367 Full_Lib_File : File_Name_Type) return Boolean
7370 -- There is something to check only when using project files.
7371 -- Otherwise, this function returns True (last line of the function).
7373 if Main_Project /= No_Project then
7375 Source_File_Name : constant String :=
7376 Get_Name_String (Source_File);
7377 Saved_Verbosity : constant Verbosity := Current_Verbosity;
7378 Project : Project_Id := No_Project;
7379 Data : Project_Data;
7381 Path_Name : Path_Name_Type := No_Path;
7382 pragma Warnings (Off, Path_Name);
7385 -- Call Get_Reference to know the ultimate extending project of
7386 -- the source. Call it with verbosity default to avoid verbose
7389 Current_Verbosity := Default;
7390 Prj.Env.Get_Reference
7391 (Source_File_Name => Source_File_Name,
7393 In_Tree => Project_Tree,
7395 Current_Verbosity := Saved_Verbosity;
7397 -- If this source is in a project, check that the ALI file is
7398 -- in its object directory. If it is not, return False, so that
7399 -- the ALI file will not be skipped.
7401 if Project /= No_Project then
7402 Data := Project_Tree.Projects.Table (Project);
7405 Object_Directory : constant String :=
7408 (Data.Object_Directory.Display_Name));
7410 Olast : Natural := Object_Directory'Last;
7412 Lib_File_Directory : constant String :=
7413 Normalize_Pathname (Dir_Name
7414 (Get_Name_String (Full_Lib_File)));
7416 Llast : Natural := Lib_File_Directory'Last;
7419 -- For directories, Normalize_Pathname may or may not put
7420 -- a directory separator at the end, depending on its input.
7421 -- Remove any last directory separator before comparison.
7422 -- Returns True only if the two directories are the same.
7424 if Object_Directory (Olast) = Directory_Separator then
7428 if Lib_File_Directory (Llast) = Directory_Separator then
7432 return Object_Directory (Object_Directory'First .. Olast) =
7433 Lib_File_Directory (Lib_File_Directory'First .. Llast);
7439 -- When the source is not in a project file, always return True
7442 end Is_In_Object_Directory;
7449 (ALI_File : File_Name_Type;
7450 Args : Argument_List;
7451 Success : out Boolean)
7453 Link_Args : Argument_List (1 .. Args'Length + 1);
7456 Get_Name_String (ALI_File);
7457 Link_Args (1) := new String'(Name_Buffer (1 .. Name_Len));
7459 Link_Args (2 .. Args'Length + 1) := Args;
7461 GNAT.OS_Lib.Normalize_Arguments (Link_Args);
7463 Display (Gnatlink.all, Link_Args);
7465 if Gnatlink_Path = null then
7466 Make_Failed ("error, unable to locate " & Gnatlink.all);
7469 GNAT.OS_Lib.Spawn (Gnatlink_Path.all, Link_Args, Success);
7472 ---------------------------
7473 -- List_Bad_Compilations --
7474 ---------------------------
7476 procedure List_Bad_Compilations is
7478 for J in Bad_Compilation.First .. Bad_Compilation.Last loop
7479 if Bad_Compilation.Table (J).File = No_File then
7481 elsif not Bad_Compilation.Table (J).Found then
7482 Inform (Bad_Compilation.Table (J).File, "not found");
7484 Inform (Bad_Compilation.Table (J).File, "compilation error");
7487 end List_Bad_Compilations;
7493 procedure List_Depend is
7494 Lib_Name : File_Name_Type;
7495 Obj_Name : File_Name_Type;
7496 Src_Name : File_Name_Type;
7500 Line_Size : constant := 77;
7503 Set_Standard_Output;
7505 for A in ALIs.First .. ALIs.Last loop
7506 Lib_Name := ALIs.Table (A).Afile;
7508 -- We have to provide the full library file name in In_Place_Mode
7510 if In_Place_Mode then
7511 Lib_Name := Full_Lib_File_Name (Lib_Name);
7514 Obj_Name := Object_File_Name (Lib_Name);
7515 Write_Name (Obj_Name);
7518 Get_Name_String (Obj_Name);
7520 Line_Pos := Len + 2;
7522 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
7523 Src_Name := Sdep.Table (D).Sfile;
7525 if Is_Internal_File_Name (Src_Name)
7526 and then not Check_Readonly_Files
7530 if not Quiet_Output then
7531 Src_Name := Full_Source_Name (Src_Name);
7534 Get_Name_String (Src_Name);
7537 if Line_Pos + Len + 1 > Line_Size then
7543 Line_Pos := Line_Pos + Len + 1;
7546 Write_Name (Src_Name);
7553 if not Commands_To_Stdout then
7562 procedure Make_Failed (S : String) is
7564 Delete_All_Temp_Files;
7568 --------------------
7569 -- Mark_Directory --
7570 --------------------
7572 procedure Mark_Directory
7574 Mark : Lib_Mark_Type;
7575 On_Command_Line : Boolean)
7581 if On_Command_Line then
7583 Real_Path : constant String := Normalize_Pathname (Dir);
7586 if Real_Path'Length = 0 then
7587 Name_Len := Dir'Length;
7588 Name_Buffer (1 .. Name_Len) := Dir;
7591 Name_Len := Real_Path'Length;
7592 Name_Buffer (1 .. Name_Len) := Real_Path;
7598 Real_Path : constant String :=
7602 (Project_Tree.Projects.Table
7603 (Main_Project).Directory.Display_Name));
7606 if Real_Path'Length = 0 then
7607 Name_Len := Dir'Length;
7608 Name_Buffer (1 .. Name_Len) := Dir;
7611 Name_Len := Real_Path'Length;
7612 Name_Buffer (1 .. Name_Len) := Real_Path;
7617 -- Last character is supposed to be a directory separator
7619 if not Is_Directory_Separator (Name_Buffer (Name_Len)) then
7620 Name_Len := Name_Len + 1;
7621 Name_Buffer (Name_Len) := Directory_Separator;
7624 -- Add flags to the already existing flags
7627 B := Get_Name_Table_Byte (N);
7628 Set_Name_Table_Byte (N, B or Mark);
7631 -----------------------------
7632 -- Recursive_Compute_Depth --
7633 -----------------------------
7635 procedure Recursive_Compute_Depth
7636 (Project : Project_Id;
7639 List : Project_List;
7643 -- Nothing to do if there is no project or if the project has already
7644 -- been seen or if the depth is large enough.
7646 if Project = No_Project
7647 or else Project_Tree.Projects.Table (Project).Seen
7648 or else Project_Tree.Projects.Table (Project).Depth >= Depth
7653 Project_Tree.Projects.Table (Project).Depth := Depth;
7655 -- Mark project as Seen to avoid endless loop caused by limited withs
7657 Project_Tree.Projects.Table (Project).Seen := True;
7659 List := Project_Tree.Projects.Table (Project).Imported_Projects;
7661 -- Visit each imported project
7663 while List /= Empty_Project_List loop
7664 Proj := Project_Tree.Project_Lists.Table (List).Project;
7665 List := Project_Tree.Project_Lists.Table (List).Next;
7666 Recursive_Compute_Depth
7668 Depth => Depth + 1);
7671 -- Visit a project being extended, if any
7673 Recursive_Compute_Depth
7674 (Project => Project_Tree.Projects.Table (Project).Extends,
7675 Depth => Depth + 1);
7677 -- Reset the Seen flag, as we leave this project
7679 Project_Tree.Projects.Table (Project).Seen := False;
7680 end Recursive_Compute_Depth;
7682 -------------------------------
7683 -- Report_Compilation_Failed --
7684 -------------------------------
7686 procedure Report_Compilation_Failed is
7688 Delete_All_Temp_Files;
7689 Exit_Program (E_Fatal);
7690 end Report_Compilation_Failed;
7692 ------------------------
7693 -- Sigint_Intercepted --
7694 ------------------------
7696 procedure Sigint_Intercepted is
7697 SIGINT : constant := 2;
7700 Write_Line ("*** Interrupted ***");
7702 -- Send SIGINT to all outstanding compilation processes spawned
7704 for J in 1 .. Outstanding_Compiles loop
7705 Kill (Running_Compile (J).Pid, SIGINT, 1);
7708 Delete_All_Temp_Files;
7710 -- ??? OS_Exit (1) is equivalent to Exit_Program (E_No_Compile),
7711 -- shouldn't that be Exit_Program (E_Abort) instead?
7712 end Sigint_Intercepted;
7718 procedure Scan_Make_Arg (Argv : String; And_Save : Boolean) is
7722 Gnatmake_Switch_Found := True;
7724 pragma Assert (Argv'First = 1);
7726 if Argv'Length = 0 then
7730 -- If the previous switch has set the Project_File_Name_Present flag
7731 -- (that is we have seen a -P alone), then the next argument is the name
7732 -- of the project file.
7734 if Project_File_Name_Present and then Project_File_Name = null then
7735 if Argv (1) = '-' then
7736 Make_Failed ("project file name missing after -P");
7739 Project_File_Name_Present := False;
7740 Project_File_Name := new String'(Argv);
7743 -- If the previous switch has set the Output_File_Name_Present flag
7744 -- (that is we have seen a -o), then the next argument is the name of
7745 -- the output executable.
7747 elsif Output_File_Name_Present
7748 and then not Output_File_Name_Seen
7750 Output_File_Name_Seen := True;
7752 if Argv (1) = '-' then
7753 Make_Failed ("output file name missing after -o");
7756 Add_Switch ("-o", Linker, And_Save => And_Save);
7757 Add_Switch (Executable_Name (Argv), Linker, And_Save => And_Save);
7760 -- If the previous switch has set the Object_Directory_Present flag
7761 -- (that is we have seen a -D), then the next argument is the path name
7762 -- of the object directory..
7764 elsif Object_Directory_Present
7765 and then not Object_Directory_Seen
7767 Object_Directory_Seen := True;
7769 if Argv (1) = '-' then
7770 Make_Failed ("object directory path name missing after -D");
7772 elsif not Is_Directory (Argv) then
7773 Make_Failed ("cannot find object directory """ & Argv & """");
7776 Add_Lib_Search_Dir (Argv);
7778 -- Specify the object directory to the binder
7780 Add_Switch ("-aO" & Argv, Binder, And_Save => And_Save);
7782 -- Record the object directory. Make sure it ends with a directory
7785 if Argv (Argv'Last) = Directory_Separator then
7786 Object_Directory_Path :=
7789 Object_Directory_Path :=
7790 new String'(Argv & Directory_Separator);
7794 -- Then check if we are dealing with -cargs/-bargs/-largs/-margs
7796 elsif Argv = "-bargs"
7805 when 'c' => Program_Args := Compiler;
7806 when 'b' => Program_Args := Binder;
7807 when 'l' => Program_Args := Linker;
7808 when 'm' => Program_Args := None;
7811 raise Program_Error;
7814 -- A special test is needed for the -o switch within a -largs
7815 -- since that is another way to specify the name of the final
7818 elsif Program_Args = Linker
7819 and then Argv = "-o"
7821 Make_Failed ("switch -o not allowed within a -largs. " &
7822 "Use -o directly.");
7824 -- Check to see if we are reading switches after a -cargs,
7825 -- -bargs or -largs switch. If yes save it.
7827 elsif Program_Args /= None then
7829 -- Check to see if we are reading -I switches in order
7830 -- to take into account in the src & lib search directories.
7832 if Argv'Length > 2 and then Argv (1 .. 2) = "-I" then
7833 if Argv (3 .. Argv'Last) = "-" then
7834 Look_In_Primary_Dir := False;
7836 elsif Program_Args = Compiler then
7837 if Argv (3 .. Argv'Last) /= "-" then
7838 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7841 elsif Program_Args = Binder then
7842 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
7846 Add_Switch (Argv, Program_Args, And_Save => And_Save);
7848 -- Handle non-default compiler, binder, linker, and handle --RTS switch
7850 elsif Argv'Length > 2 and then Argv (1 .. 2) = "--" then
7852 and then Argv (1 .. 6) = "--GCC="
7855 Program_Args : constant Argument_List_Access :=
7856 Argument_String_To_List
7857 (Argv (7 .. Argv'Last));
7861 Saved_Gcc := new String'(Program_Args.all (1).all);
7863 Gcc := new String'(Program_Args.all (1).all);
7866 for J in 2 .. Program_Args.all'Last loop
7868 (Program_Args.all (J).all,
7870 And_Save => And_Save);
7874 elsif Argv'Length > 11
7875 and then Argv (1 .. 11) = "--GNATBIND="
7878 Program_Args : constant Argument_List_Access :=
7879 Argument_String_To_List
7880 (Argv (12 .. Argv'Last));
7884 Saved_Gnatbind := new String'(Program_Args.all (1).all);
7886 Gnatbind := new String'(Program_Args.all (1).all);
7889 for J in 2 .. Program_Args.all'Last loop
7891 (Program_Args.all (J).all, Binder, And_Save => And_Save);
7895 elsif Argv'Length > 11
7896 and then Argv (1 .. 11) = "--GNATLINK="
7899 Program_Args : constant Argument_List_Access :=
7900 Argument_String_To_List
7901 (Argv (12 .. Argv'Last));
7904 Saved_Gnatlink := new String'(Program_Args.all (1).all);
7906 Gnatlink := new String'(Program_Args.all (1).all);
7909 for J in 2 .. Program_Args.all'Last loop
7910 Add_Switch (Program_Args.all (J).all, Linker);
7914 elsif Argv'Length >= 5 and then
7915 Argv (1 .. 5) = "--RTS"
7917 Add_Switch (Argv, Compiler, And_Save => And_Save);
7918 Add_Switch (Argv, Binder, And_Save => And_Save);
7920 if Argv'Length <= 6 or else Argv (6) /= '=' then
7921 Make_Failed ("missing path for --RTS");
7924 -- Check that this is the first time we see this switch or
7925 -- if it is not the first time, the same path is specified.
7927 if RTS_Specified = null then
7928 RTS_Specified := new String'(Argv (7 .. Argv'Last));
7930 elsif RTS_Specified.all /= Argv (7 .. Argv'Last) then
7931 Make_Failed ("--RTS cannot be specified multiple times");
7934 -- Valid --RTS switch
7941 Src_Path_Name : constant String_Ptr :=
7943 (Argv (7 .. Argv'Last), Include);
7945 Lib_Path_Name : constant String_Ptr :=
7947 (Argv (7 .. Argv'Last), Objects);
7950 if Src_Path_Name /= null
7951 and then Lib_Path_Name /= null
7953 -- Set RTS_*_Path_Name variables, so that correct direct-
7954 -- ories will be set when Osint.Add_Default_Search_Dirs
7957 RTS_Src_Path_Name := Src_Path_Name;
7958 RTS_Lib_Path_Name := Lib_Path_Name;
7960 elsif Src_Path_Name = null
7961 and Lib_Path_Name = null
7963 Make_Failed ("RTS path not valid: missing " &
7964 "adainclude and adalib directories");
7966 elsif Src_Path_Name = null then
7967 Make_Failed ("RTS path not valid: missing adainclude " &
7970 elsif Lib_Path_Name = null then
7971 Make_Failed ("RTS path not valid: missing adalib " &
7978 Scan_Make_Switches (Argv, Success);
7981 -- If we have seen a regular switch process it
7983 elsif Argv (1) = '-' then
7984 if Argv'Length = 1 then
7985 Make_Failed ("switch character cannot be followed by a blank");
7987 -- Incorrect switches that should start with "--"
7989 elsif (Argv'Length > 5 and then Argv (1 .. 5) = "-RTS=")
7990 or else (Argv'Length > 5 and then Argv (1 .. 5) = "-GCC=")
7991 or else (Argv'Length > 10 and then Argv (1 .. 10) = "-GNATLINK=")
7992 or else (Argv'Length > 10 and then Argv (1 .. 10) = "-GNATBIND=")
7994 Make_Failed ("option " & Argv & " should start with '--'");
7998 elsif Argv (2 .. Argv'Last) = "I-" then
7999 Look_In_Primary_Dir := False;
8001 -- Forbid -?- or -??- where ? is any character
8003 elsif (Argv'Length = 3 and then Argv (3) = '-')
8004 or else (Argv'Length = 4 and then Argv (4) = '-')
8007 ("trailing ""-"" at the end of " & Argv & " forbidden.");
8011 elsif Argv (2) = 'I' then
8012 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
8013 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
8014 Add_Switch (Argv, Compiler, And_Save => And_Save);
8015 Add_Switch (Argv, Binder, And_Save => And_Save);
8017 -- -aIdir (to gcc this is like a -I switch)
8019 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aI" then
8020 Add_Source_Search_Dir (Argv (4 .. Argv'Last), And_Save);
8021 Add_Switch ("-I" & Argv (4 .. Argv'Last),
8023 And_Save => And_Save);
8024 Add_Switch (Argv, Binder, And_Save => And_Save);
8028 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aO" then
8029 Add_Library_Search_Dir (Argv (4 .. Argv'Last), And_Save);
8030 Add_Switch (Argv, Binder, And_Save => And_Save);
8032 -- -aLdir (to gnatbind this is like a -aO switch)
8034 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aL" then
8035 Mark_Directory (Argv (4 .. Argv'Last), Ada_Lib_Dir, And_Save);
8036 Add_Library_Search_Dir (Argv (4 .. Argv'Last), And_Save);
8037 Add_Switch ("-aO" & Argv (4 .. Argv'Last),
8039 And_Save => And_Save);
8043 elsif Argv'Length >= 13 and then Argv (2 .. 13) = "aamp_target=" then
8044 Add_Switch (Argv, Compiler, And_Save => And_Save);
8046 -- Set the aamp_target environment variable so that the binder and
8047 -- linker will use the proper target library. This is consistent
8048 -- with how things work when -aamp_target is passed on the command
8049 -- line to gnaampmake.
8051 Setenv ("aamp_target", Argv (14 .. Argv'Last));
8053 -- -Adir (to gnatbind this is like a -aO switch, to gcc like a -I)
8055 elsif Argv (2) = 'A' then
8056 Mark_Directory (Argv (3 .. Argv'Last), Ada_Lib_Dir, And_Save);
8057 Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
8058 Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
8059 Add_Switch ("-I" & Argv (3 .. Argv'Last),
8061 And_Save => And_Save);
8062 Add_Switch ("-aO" & Argv (3 .. Argv'Last),
8064 And_Save => And_Save);
8068 elsif Argv (2) = 'L' then
8069 Add_Switch (Argv, Linker, And_Save => And_Save);
8071 -- For -gxxxxx, -pg, -mxxx, -fxxx: give the switch to both the
8072 -- compiler and the linker (except for -gnatxxx which is only for
8073 -- the compiler). Some of the -mxxx (for example -m64) and -fxxx
8074 -- (for example -ftest-coverage for gcov) need to be used when
8075 -- compiling the binder generated files, and using all these gcc
8076 -- switches for the binder generated files should not be a problem.
8079 (Argv (2) = 'g' and then (Argv'Last < 5
8080 or else Argv (2 .. 5) /= "gnat"))
8081 or else Argv (2 .. Argv'Last) = "pg"
8082 or else (Argv (2) = 'm' and then Argv'Last > 2)
8083 or else (Argv (2) = 'f' and then Argv'Last > 2)
8085 Add_Switch (Argv, Compiler, And_Save => And_Save);
8086 Add_Switch (Argv, Linker, And_Save => And_Save);
8088 -- -C=<mapping file>
8090 elsif Argv'Last > 2 and then Argv (2) = 'C' then
8092 if Argv (3) /= '=' or else Argv'Last <= 3 then
8093 Make_Failed ("illegal switch " & Argv);
8096 Gnatmake_Mapping_File := new String'(Argv (4 .. Argv'Last));
8101 elsif Argv'Last = 2 and then Argv (2) = 'D' then
8102 if Project_File_Name /= null then
8103 Make_Failed ("-D cannot be used in conjunction with a " &
8107 Scan_Make_Switches (Argv, Success);
8112 elsif Argv (2) = 'd'
8113 and then Argv'Last = 2
8115 Display_Compilation_Progress := True;
8119 elsif Argv'Last = 2 and then Argv (2) = 'i' then
8120 if Project_File_Name /= null then
8121 Make_Failed ("-i cannot be used in conjunction with a " &
8124 Scan_Make_Switches (Argv, Success);
8127 -- -j (need to save the result)
8129 elsif Argv (2) = 'j' then
8130 Scan_Make_Switches (Argv, Success);
8133 Saved_Maximum_Processes := Maximum_Processes;
8138 elsif Argv (2) = 'm'
8139 and then Argv'Last = 2
8141 Minimal_Recompilation := True;
8145 elsif Argv (2) = 'u'
8146 and then Argv'Last = 2
8148 Unique_Compile := True;
8149 Compile_Only := True;
8150 Do_Bind_Step := False;
8151 Do_Link_Step := False;
8155 elsif Argv (2) = 'U'
8156 and then Argv'Last = 2
8158 Unique_Compile_All_Projects := True;
8159 Unique_Compile := True;
8160 Compile_Only := True;
8161 Do_Bind_Step := False;
8162 Do_Link_Step := False;
8164 -- -Pprj or -P prj (only once, and only on the command line)
8166 elsif Argv (2) = 'P' then
8167 if Project_File_Name /= null then
8168 Make_Failed ("cannot have several project files specified");
8170 elsif Object_Directory_Path /= null then
8171 Make_Failed ("-D cannot be used in conjunction with a " &
8174 elsif In_Place_Mode then
8175 Make_Failed ("-i cannot be used in conjunction with a " &
8178 elsif not And_Save then
8180 -- It could be a tool other than gnatmake (i.e, gnatdist)
8181 -- or a -P switch inside a project file.
8184 ("either the tool is not ""project-aware"" or " &
8185 "a project file is specified inside a project file");
8187 elsif Argv'Last = 2 then
8189 -- -P is used alone: the project file name is the next option
8191 Project_File_Name_Present := True;
8194 Project_File_Name := new String'(Argv (3 .. Argv'Last));
8197 -- -vPx (verbosity of the parsing of the project files)
8200 and then Argv (2 .. 3) = "vP"
8201 and then Argv (4) in '0' .. '2'
8206 Current_Verbosity := Prj.Default;
8208 Current_Verbosity := Prj.Medium;
8210 Current_Verbosity := Prj.High;
8216 -- -Xext=val (External assignment)
8218 elsif Argv (2) = 'X'
8219 and then Is_External_Assignment (Argv)
8221 -- Is_External_Assignment has side effects
8222 -- when it returns True;
8226 -- If -gnath is present, then generate the usage information
8227 -- right now and do not pass this option on to the compiler calls.
8229 elsif Argv = "-gnath" then
8232 -- If -gnatc is specified, make sure the bind step and the link
8233 -- step are not executed.
8235 elsif Argv'Length >= 6 and then Argv (2 .. 6) = "gnatc" then
8237 -- If -gnatc is specified, make sure the bind step and the link
8238 -- step are not executed.
8240 Add_Switch (Argv, Compiler, And_Save => And_Save);
8241 Operating_Mode := Check_Semantics;
8242 Check_Object_Consistency := False;
8243 Compile_Only := True;
8244 Do_Bind_Step := False;
8245 Do_Link_Step := False;
8247 elsif Argv (2 .. Argv'Last) = "nostdlib" then
8249 -- Don't pass -nostdlib to gnatlink, it will disable
8250 -- linking with all standard library files.
8254 Add_Switch (Argv, Compiler, And_Save => And_Save);
8255 Add_Switch (Argv, Binder, And_Save => And_Save);
8257 elsif Argv (2 .. Argv'Last) = "nostdinc" then
8259 -- Pass -nostdinc to the Compiler and to gnatbind
8262 Add_Switch (Argv, Compiler, And_Save => And_Save);
8263 Add_Switch (Argv, Binder, And_Save => And_Save);
8265 -- All other switches are processed by Scan_Make_Switches. If the
8266 -- call returns with Gnatmake_Switch_Found = False, then the switch
8267 -- is passed to the compiler.
8270 Scan_Make_Switches (Argv, Gnatmake_Switch_Found);
8272 if not Gnatmake_Switch_Found then
8273 Add_Switch (Argv, Compiler, And_Save => And_Save);
8277 -- If not a switch it must be a file name
8281 Mains.Add_Main (Argv);
8289 function Switches_Of
8290 (Source_File : File_Name_Type;
8291 Source_File_Name : String;
8293 Naming : Naming_Data;
8294 In_Package : Package_Id;
8295 Allow_ALI : Boolean) return Variable_Value
8297 Switches : Variable_Value;
8299 Defaults : constant Array_Element_Id :=
8301 (Name => Name_Default_Switches,
8303 Project_Tree.Packages.Table
8304 (In_Package).Decl.Arrays,
8305 In_Tree => Project_Tree);
8307 Switches_Array : constant Array_Element_Id :=
8309 (Name => Name_Switches,
8311 Project_Tree.Packages.Table
8312 (In_Package).Decl.Arrays,
8313 In_Tree => Project_Tree);
8316 -- First, try Switches (<file name>)
8320 (Index => Name_Id (Source_File),
8321 Src_Index => Source_Index,
8322 In_Array => Switches_Array,
8323 In_Tree => Project_Tree);
8325 -- Check also without the suffix
8327 if Switches = Nil_Variable_Value then
8329 Name : String (1 .. Source_File_Name'Length + 3);
8330 Last : Positive := Source_File_Name'Length;
8331 Spec_Suffix : constant String :=
8332 Spec_Suffix_Of (Project_Tree, "ada", Naming);
8333 Body_Suffix : constant String :=
8334 Body_Suffix_Of (Project_Tree, "ada", Naming);
8335 Truncated : Boolean := False;
8338 Name (1 .. Last) := Source_File_Name;
8340 if Last > Body_Suffix'Length
8341 and then Name (Last - Body_Suffix'Length + 1 .. Last) =
8345 Last := Last - Body_Suffix'Length;
8349 and then Last > Spec_Suffix'Length
8350 and then Name (Last - Spec_Suffix'Length + 1 .. Last) =
8354 Last := Last - Spec_Suffix'Length;
8359 Name_Buffer (1 .. Name_Len) := Name (1 .. Last);
8362 (Index => Name_Find,
8364 In_Array => Switches_Array,
8365 In_Tree => Project_Tree);
8367 if Switches = Nil_Variable_Value
8370 Last := Source_File_Name'Length;
8372 while Name (Last) /= '.' loop
8376 Name (Last + 1 .. Last + 3) := "ali";
8377 Name_Len := Last + 3;
8378 Name_Buffer (1 .. Name_Len) := Name (1 .. Name_Len);
8381 (Index => Name_Find,
8383 In_Array => Switches_Array,
8384 In_Tree => Project_Tree);
8390 -- Next, try Switches ("Ada")
8392 if Switches = Nil_Variable_Value then
8397 In_Array => Switches_Array,
8398 In_Tree => Project_Tree,
8399 Force_Lower_Case_Index => True);
8401 if Switches /= Nil_Variable_Value then
8402 Switch_May_Be_Passed_To_The_Compiler := False;
8406 -- Next, try Switches (others)
8408 if Switches = Nil_Variable_Value then
8411 (Index => All_Other_Names,
8413 In_Array => Switches_Array,
8414 In_Tree => Project_Tree);
8416 if Switches /= Nil_Variable_Value then
8417 Switch_May_Be_Passed_To_The_Compiler := False;
8421 -- And finally, Default_Switches ("Ada")
8423 if Switches = Nil_Variable_Value then
8428 In_Array => Defaults,
8429 In_Tree => Project_Tree);
8441 if Usage_Needed then
8442 Usage_Needed := False;
8451 procedure Verbose_Msg
8454 N2 : Name_Id := No_Name;
8456 Prefix : String := " -> ";
8457 Minimum_Verbosity : Verbosity_Level_Type := Opt.Low)
8460 if (not Verbose_Mode) or else (Minimum_Verbosity > Verbosity_Level) then
8470 if N2 /= No_Name then
8480 procedure Verbose_Msg
8481 (N1 : File_Name_Type;
8483 N2 : File_Name_Type := No_File;
8485 Prefix : String := " -> ";
8486 Minimum_Verbosity : Verbosity_Level_Type := Opt.Low)
8490 (Name_Id (N1), S1, Name_Id (N2), S2, Prefix, Minimum_Verbosity);
8494 -- Make sure that in case of failure, the temp files will be deleted
8496 Prj.Com.Fail := Make_Failed'Access;
8497 MLib.Fail := Make_Failed'Access;
8498 Makeutl.Do_Fail := Make_Failed'Access;