1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2004-2011, 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 ------------------------------------------------------------------------------
28 with Err_Vars; use Err_Vars;
32 with Osint; use Osint;
33 with Output; use Output;
38 with Prj.Util; use Prj.Util;
42 with Ada.Command_Line; use Ada.Command_Line;
43 with Ada.Unchecked_Deallocation;
45 with GNAT.Case_Util; use GNAT.Case_Util;
46 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
48 with GNAT.Regexp; use GNAT.Regexp;
50 package body Makeutl is
52 type Linker_Options_Data is record
54 Options : String_List_Id;
57 Linker_Option_Initial_Count : constant := 20;
59 Linker_Options_Buffer : String_List_Access :=
60 new String_List (1 .. Linker_Option_Initial_Count);
62 Last_Linker_Option : Natural := 0;
64 package Linker_Opts is new Table.Table (
65 Table_Component_Type => Linker_Options_Data,
66 Table_Index_Type => Integer,
69 Table_Increment => 100,
70 Table_Name => "Make.Linker_Opts");
72 procedure Add_Linker_Option (Option : String);
79 (Option : String_Access;
80 To : in out String_List_Access;
81 Last : in out Natural)
84 if Last = To'Last then
86 New_Options : constant String_List_Access :=
87 new String_List (1 .. To'Last * 2);
90 New_Options (To'Range) := To.all;
92 -- Set all elements of the original options to null to avoid
93 -- deallocation of copies.
95 To.all := (others => null);
108 To : in out String_List_Access;
109 Last : in out Natural)
112 Add (Option => new String'(Option), To => To, Last => Last);
115 -----------------------
116 -- Add_Linker_Option --
117 -----------------------
119 procedure Add_Linker_Option (Option : String) is
121 if Option'Length > 0 then
122 if Last_Linker_Option = Linker_Options_Buffer'Last then
124 New_Buffer : constant String_List_Access :=
126 (1 .. Linker_Options_Buffer'Last +
127 Linker_Option_Initial_Count);
129 New_Buffer (Linker_Options_Buffer'Range) :=
130 Linker_Options_Buffer.all;
131 Linker_Options_Buffer.all := (others => null);
132 Free (Linker_Options_Buffer);
133 Linker_Options_Buffer := New_Buffer;
137 Last_Linker_Option := Last_Linker_Option + 1;
138 Linker_Options_Buffer (Last_Linker_Option) := new String'(Option);
140 end Add_Linker_Option;
142 -------------------------
143 -- Base_Name_Index_For --
144 -------------------------
146 function Base_Name_Index_For
149 Index_Separator : Character) return File_Name_Type
151 Result : File_Name_Type;
155 Add_Str_To_Name_Buffer (Base_Name (Main));
157 -- Remove the extension, if any, that is the last part of the base name
158 -- starting with a dot and following some characters.
160 for J in reverse 2 .. Name_Len loop
161 if Name_Buffer (J) = '.' then
167 -- Add the index info, if index is different from 0
169 if Main_Index > 0 then
170 Add_Char_To_Name_Buffer (Index_Separator);
173 Img : constant String := Main_Index'Img;
175 Add_Str_To_Name_Buffer (Img (2 .. Img'Last));
181 end Base_Name_Index_For;
183 ------------------------------
184 -- Check_Source_Info_In_ALI --
185 ------------------------------
187 function Check_Source_Info_In_ALI
189 Tree : Project_Tree_Ref) return Boolean
194 -- Loop through units
196 for U in ALIs.Table (The_ALI).First_Unit ..
197 ALIs.Table (The_ALI).Last_Unit
199 -- Check if the file name is one of the source of the unit
201 Get_Name_String (Units.Table (U).Uname);
202 Name_Len := Name_Len - 2;
203 Unit_Name := Name_Find;
205 if File_Not_A_Source_Of (Tree, Unit_Name, Units.Table (U).Sfile) then
209 -- Loop to do same check for each of the withed units
211 for W in Units.Table (U).First_With .. Units.Table (U).Last_With loop
213 WR : ALI.With_Record renames Withs.Table (W);
216 if WR.Sfile /= No_File then
217 Get_Name_String (WR.Uname);
218 Name_Len := Name_Len - 2;
219 Unit_Name := Name_Find;
221 if File_Not_A_Source_Of (Tree, Unit_Name, WR.Sfile) then
229 -- Loop to check subunits and replaced sources
231 for D in ALIs.Table (The_ALI).First_Sdep ..
232 ALIs.Table (The_ALI).Last_Sdep
235 SD : Sdep_Record renames Sdep.Table (D);
238 Unit_Name := SD.Subunit_Name;
240 if Unit_Name = No_Name then
242 -- Check if this source file has been replaced by a source with
243 -- a different file name.
245 if Tree /= null and then Tree.Replaced_Source_Number > 0 then
247 Replacement : constant File_Name_Type :=
248 Replaced_Source_HTable.Get
249 (Tree.Replaced_Sources, SD.Sfile);
252 if Replacement /= No_File then
256 Get_Name_String (SD.Sfile) &
257 " has been replaced by " &
258 Get_Name_String (Replacement));
267 -- For separates, the file is no longer associated with the
268 -- unit ("proc-sep.adb" is not associated with unit "proc.sep")
269 -- so we need to check whether the source file still exists in
270 -- the source tree: it will if it matches the naming scheme
271 -- (and then will be for the same unit).
275 Project => No_Project,
276 Base_Name => SD.Sfile) = No_Source
278 -- If this is not a runtime file or if, when gnatmake switch
279 -- -a is used, we are not able to find this subunit in the
280 -- source directories, then recompilation is needed.
282 if not Fname.Is_Internal_File_Name (SD.Sfile)
284 (Check_Readonly_Files
285 and then Full_Source_Name (SD.Sfile) = No_File)
289 ("While parsing ALI file, file "
290 & Get_Name_String (SD.Sfile)
291 & " is indicated as containing subunit "
292 & Get_Name_String (Unit_Name)
293 & " but this does not match what was found while"
294 & " parsing the project. Will recompile");
305 end Check_Source_Info_In_ALI;
307 --------------------------------
308 -- Create_Binder_Mapping_File --
309 --------------------------------
311 function Create_Binder_Mapping_File
312 (Project_Tree : Project_Tree_Ref) return Path_Name_Type
314 Mapping_Path : Path_Name_Type := No_Path;
316 Mapping_FD : File_Descriptor := Invalid_FD;
317 -- A File Descriptor for an eventual mapping file
319 ALI_Unit : Unit_Name_Type := No_Unit_Name;
320 -- The unit name of an ALI file
322 ALI_Name : File_Name_Type := No_File;
323 -- The file name of the ALI file
325 ALI_Project : Project_Id := No_Project;
326 -- The project of the ALI file
329 OK : Boolean := False;
336 Tempdir.Create_Temp_File (Mapping_FD, Mapping_Path);
337 Record_Temp_File (Project_Tree.Shared, Mapping_Path);
339 if Mapping_FD /= Invalid_FD then
342 -- Traverse all units
344 Unit := Units_Htable.Get_First (Project_Tree.Units_HT);
345 while Unit /= No_Unit_Index loop
346 if Unit.Name /= No_Name then
348 -- If there is a body, put it in the mapping
350 if Unit.File_Names (Impl) /= No_Source
351 and then Unit.File_Names (Impl).Project /= No_Project
353 Get_Name_String (Unit.Name);
354 Add_Str_To_Name_Buffer ("%b");
355 ALI_Unit := Name_Find;
357 Lib_File_Name (Unit.File_Names (Impl).Display_File);
358 ALI_Project := Unit.File_Names (Impl).Project;
360 -- Otherwise, if there is a spec, put it in the mapping
362 elsif Unit.File_Names (Spec) /= No_Source
363 and then Unit.File_Names (Spec).Project /= No_Project
365 Get_Name_String (Unit.Name);
366 Add_Str_To_Name_Buffer ("%s");
367 ALI_Unit := Name_Find;
369 Lib_File_Name (Unit.File_Names (Spec).Display_File);
370 ALI_Project := Unit.File_Names (Spec).Project;
376 -- If we have something to put in the mapping then do it now.
377 -- However, if the project is extended, we don't put anything
378 -- in the mapping file, since we don't know where the ALI file
379 -- is: it might be in the extended project object directory as
380 -- well as in the extending project object directory.
382 if ALI_Name /= No_File
383 and then ALI_Project.Extended_By = No_Project
384 and then ALI_Project.Extends = No_Project
386 -- First check if the ALI file exists. If it does not, do
387 -- not put the unit in the mapping file.
390 ALI : constant String := Get_Name_String (ALI_Name);
393 -- For library projects, use the library ALI directory,
394 -- for other projects, use the object directory.
396 if ALI_Project.Library then
398 (ALI_Project.Library_ALI_Dir.Display_Name);
401 (ALI_Project.Object_Directory.Display_Name);
404 Add_Str_To_Name_Buffer (ALI);
405 Add_Char_To_Name_Buffer (ASCII.LF);
408 ALI_Path_Name : constant String :=
409 Name_Buffer (1 .. Name_Len);
413 (ALI_Path_Name (1 .. ALI_Path_Name'Last - 1))
415 -- First line is the unit name
417 Get_Name_String (ALI_Unit);
418 Add_Char_To_Name_Buffer (ASCII.LF);
422 Name_Buffer (1)'Address,
424 OK := Bytes = Name_Len;
428 -- Second line it the ALI file name
430 Get_Name_String (ALI_Name);
431 Add_Char_To_Name_Buffer (ASCII.LF);
435 Name_Buffer (1)'Address,
437 OK := (Bytes = Name_Len);
441 -- Third line it the ALI path name
446 ALI_Path_Name (1)'Address,
447 ALI_Path_Name'Length);
448 OK := (Bytes = ALI_Path_Name'Length);
450 -- If OK is False, it means we were unable to
451 -- write a line. No point in continuing with the
461 Unit := Units_Htable.Get_Next (Project_Tree.Units_HT);
464 Close (Mapping_FD, Status);
469 -- If the creation of the mapping file was successful, we add the switch
470 -- to the arguments of gnatbind.
478 end Create_Binder_Mapping_File;
484 function Create_Name (Name : String) return File_Name_Type is
487 Add_Str_To_Name_Buffer (Name);
491 function Create_Name (Name : String) return Name_Id is
494 Add_Str_To_Name_Buffer (Name);
498 function Create_Name (Name : String) return Path_Name_Type is
501 Add_Str_To_Name_Buffer (Name);
505 ----------------------------
506 -- Executable_Prefix_Path --
507 ----------------------------
509 function Executable_Prefix_Path return String is
510 Exec_Name : constant String := Command_Name;
512 function Get_Install_Dir (S : String) return String;
513 -- S is the executable name preceded by the absolute or relative path,
514 -- e.g. "c:\usr\bin\gcc.exe". Returns the absolute directory where "bin"
515 -- lies (in the example "C:\usr"). If the executable is not in a "bin"
516 -- directory, return "".
518 ---------------------
519 -- Get_Install_Dir --
520 ---------------------
522 function Get_Install_Dir (S : String) return String is
524 Path_Last : Integer := 0;
527 for J in reverse Exec'Range loop
528 if Exec (J) = Directory_Separator then
534 if Path_Last >= Exec'First + 2 then
535 To_Lower (Exec (Path_Last - 2 .. Path_Last));
538 if Path_Last < Exec'First + 2
539 or else Exec (Path_Last - 2 .. Path_Last) /= "bin"
540 or else (Path_Last - 3 >= Exec'First
541 and then Exec (Path_Last - 3) /= Directory_Separator)
546 return Normalize_Pathname
547 (Exec (Exec'First .. Path_Last - 4),
548 Resolve_Links => Opt.Follow_Links_For_Dirs)
549 & Directory_Separator;
552 -- Beginning of Executable_Prefix_Path
555 -- For VMS, the path returned is always /gnu/
557 if Hostparm.OpenVMS then
561 -- First determine if a path prefix was placed in front of the
564 for J in reverse Exec_Name'Range loop
565 if Exec_Name (J) = Directory_Separator then
566 return Get_Install_Dir (Exec_Name);
570 -- If we get here, the user has typed the executable name with no
574 Path : String_Access := Locate_Exec_On_Path (Exec_Name);
580 Dir : constant String := Get_Install_Dir (Path.all);
587 end Executable_Prefix_Path;
593 procedure Fail_Program
594 (Project_Tree : Project_Tree_Ref;
596 Flush_Messages : Boolean := True)
599 if Flush_Messages then
600 if Total_Errors_Detected /= 0 or else Warnings_Detected /= 0 then
605 Finish_Program (Project_Tree, E_Fatal, S => S);
612 procedure Finish_Program
613 (Project_Tree : Project_Tree_Ref;
614 Exit_Code : Osint.Exit_Code_Type := Osint.E_Success;
618 if not Debug.Debug_Flag_N then
619 Delete_Temp_Config_Files (Project_Tree);
621 if Project_Tree /= null then
622 Delete_All_Temp_Files (Project_Tree.Shared);
627 if Exit_Code /= E_Success then
634 -- Output Namet statistics
638 Exit_Program (Exit_Code);
641 --------------------------
642 -- File_Not_A_Source_Of --
643 --------------------------
645 function File_Not_A_Source_Of
646 (Project_Tree : Project_Tree_Ref;
648 Sfile : File_Name_Type) return Boolean
650 Unit : constant Unit_Index :=
651 Units_Htable.Get (Project_Tree.Units_HT, Uname);
653 At_Least_One_File : Boolean := False;
656 if Unit /= No_Unit_Index then
657 for F in Unit.File_Names'Range loop
658 if Unit.File_Names (F) /= null then
659 At_Least_One_File := True;
660 if Unit.File_Names (F).File = Sfile then
666 if not At_Least_One_File then
668 -- The unit was probably created initially for a separate unit
669 -- (which are initially created as IMPL when both suffixes are the
670 -- same). Later on, Override_Kind changed the type of the file,
671 -- and the unit is no longer valid in fact.
676 Verbose_Msg (Uname, "sources do not include ", Name_Id (Sfile));
681 end File_Not_A_Source_Of;
683 ---------------------
684 -- Get_Directories --
685 ---------------------
687 procedure Get_Directories
688 (Project_Tree : Project_Tree_Ref;
689 For_Project : Project_Id;
690 Activity : Activity_Type;
691 Languages : Name_Ids)
694 procedure Recursive_Add
695 (Project : Project_Id;
696 Tree : Project_Tree_Ref;
697 In_Aggregate_Lib : Boolean;
698 Extended : in out Boolean);
699 -- Add all the source directories of a project to the path only if
700 -- this project has not been visited. Calls itself recursively for
701 -- projects being extended, and imported projects.
703 procedure Add_Dir (Value : Path_Name_Type);
704 -- Add directory Value in table Directories, if it is defined and not
711 procedure Add_Dir (Value : Path_Name_Type) is
712 Add_It : Boolean := True;
715 if Value /= No_Path then
716 for Index in 1 .. Directories.Last loop
717 if Directories.Table (Index) = Value then
724 Directories.Increment_Last;
725 Directories.Table (Directories.Last) := Value;
734 procedure Recursive_Add
735 (Project : Project_Id;
736 Tree : Project_Tree_Ref;
737 In_Aggregate_Lib : Boolean;
738 Extended : in out Boolean)
740 pragma Unreferenced (In_Aggregate_Lib);
742 Current : String_List_Id;
743 Dir : String_Element;
744 OK : Boolean := False;
745 Lang_Proc : Language_Ptr := Project.Languages;
748 -- Add to path all directories of this project
750 if Activity = Compilation then
752 while Lang_Proc /= No_Language_Index loop
753 for J in Languages'Range loop
754 OK := Lang_Proc.Name = Languages (J);
755 exit Lang_Loop when OK;
758 Lang_Proc := Lang_Proc.Next;
762 Current := Project.Source_Dirs;
764 while Current /= Nil_String loop
765 Dir := Tree.Shared.String_Elements.Table (Current);
766 Add_Dir (Path_Name_Type (Dir.Value));
771 elsif Project.Library then
772 if Activity = SAL_Binding and then Extended then
773 Add_Dir (Project.Object_Directory.Display_Name);
776 Add_Dir (Project.Library_ALI_Dir.Display_Name);
780 Add_Dir (Project.Object_Directory.Display_Name);
783 if Project.Extends = No_Project then
788 procedure For_All_Projects is
789 new For_Every_Project_Imported (Boolean, Recursive_Add);
791 Extended : Boolean := True;
793 -- Start of processing for Get_Directories
797 For_All_Projects (For_Project, Project_Tree, Extended);
804 procedure Get_Switches
805 (Source : Prj.Source_Id;
807 Project_Tree : Project_Tree_Ref;
808 Value : out Variable_Value;
809 Is_Default : out Boolean)
813 (Source_File => Source.File,
814 Source_Lang => Source.Language.Name,
815 Source_Prj => Source.Project,
816 Pkg_Name => Pkg_Name,
817 Project_Tree => Project_Tree,
819 Is_Default => Is_Default);
826 procedure Get_Switches
827 (Source_File : File_Name_Type;
828 Source_Lang : Name_Id;
829 Source_Prj : Project_Id;
831 Project_Tree : Project_Tree_Ref;
832 Value : out Variable_Value;
833 Is_Default : out Boolean;
834 Test_Without_Suffix : Boolean := False;
835 Check_ALI_Suffix : Boolean := False)
837 Project : constant Project_Id :=
838 Ultimate_Extending_Project_Of (Source_Prj);
839 Pkg : constant Package_Id :=
842 In_Packages => Project.Decl.Packages,
843 Shared => Project_Tree.Shared);
849 if Source_File /= No_File then
850 Value := Prj.Util.Value_Of
851 (Name => Name_Id (Source_File),
852 Attribute_Or_Array_Name => Name_Switches,
854 Shared => Project_Tree.Shared,
855 Allow_Wildcards => True);
858 if Value = Nil_Variable_Value and then Test_Without_Suffix then
860 Get_Language_From_Name (Project, Get_Name_String (Source_Lang));
864 Naming : Lang_Naming_Data renames Lang.Config.Naming_Data;
865 SF_Name : constant String := Get_Name_String (Source_File);
866 Last : Positive := SF_Name'Length;
867 Name : String (1 .. Last + 3);
868 Spec_Suffix : String := Get_Name_String (Naming.Spec_Suffix);
869 Body_Suffix : String := Get_Name_String (Naming.Body_Suffix);
870 Truncated : Boolean := False;
873 Canonical_Case_File_Name (Spec_Suffix);
874 Canonical_Case_File_Name (Body_Suffix);
875 Name (1 .. Last) := SF_Name;
877 if Last > Body_Suffix'Length
879 Name (Last - Body_Suffix'Length + 1 .. Last) = Body_Suffix
882 Last := Last - Body_Suffix'Length;
886 and then Last > Spec_Suffix'Length
888 Name (Last - Spec_Suffix'Length + 1 .. Last) = Spec_Suffix
891 Last := Last - Spec_Suffix'Length;
896 Add_Str_To_Name_Buffer (Name (1 .. Last));
898 Value := Prj.Util.Value_Of
900 Attribute_Or_Array_Name => Name_Switches,
902 Shared => Project_Tree.Shared,
903 Allow_Wildcards => True);
906 if Value = Nil_Variable_Value and then Check_ALI_Suffix then
907 Last := SF_Name'Length;
908 while Name (Last) /= '.' loop
913 Add_Str_To_Name_Buffer (Name (1 .. Last));
914 Add_Str_To_Name_Buffer ("ali");
916 Value := Prj.Util.Value_Of
918 Attribute_Or_Array_Name => Name_Switches,
920 Shared => Project_Tree.Shared,
921 Allow_Wildcards => True);
927 if Value = Nil_Variable_Value then
931 (Name => Source_Lang,
932 Attribute_Or_Array_Name => Name_Switches,
934 Shared => Project_Tree.Shared,
935 Force_Lower_Case_Index => True);
938 if Value = Nil_Variable_Value then
941 (Name => All_Other_Names,
942 Attribute_Or_Array_Name => Name_Switches,
944 Shared => Project_Tree.Shared,
945 Force_Lower_Case_Index => True);
948 if Value = Nil_Variable_Value then
951 (Name => Source_Lang,
952 Attribute_Or_Array_Name => Name_Default_Switches,
954 Shared => Project_Tree.Shared);
962 procedure Inform (N : File_Name_Type; Msg : String) is
964 Inform (Name_Id (N), Msg);
967 procedure Inform (N : Name_Id := No_Name; Msg : String) is
969 Osint.Write_Program_Name;
977 Name : constant String := Get_Name_String (N);
979 if Debug.Debug_Flag_F and then Is_Absolute_Path (Name) then
980 Write_Str (File_Name (Name));
993 ------------------------------
994 -- Initialize_Source_Record --
995 ------------------------------
997 procedure Initialize_Source_Record (Source : Prj.Source_Id) is
999 procedure Set_Object_Project
1001 Obj_Proj : Project_Id;
1002 Obj_Path : Path_Name_Type;
1003 Stamp : Time_Stamp_Type);
1004 -- Update information about object file, switches file,...
1006 ------------------------
1007 -- Set_Object_Project --
1008 ------------------------
1010 procedure Set_Object_Project
1012 Obj_Proj : Project_Id;
1013 Obj_Path : Path_Name_Type;
1014 Stamp : Time_Stamp_Type) is
1016 Source.Object_Project := Obj_Proj;
1017 Source.Object_Path := Obj_Path;
1018 Source.Object_TS := Stamp;
1020 if Source.Language.Config.Dependency_Kind /= None then
1022 Dep_Path : constant String :=
1025 Get_Name_String (Source.Dep_Name),
1026 Resolve_Links => Opt.Follow_Links_For_Files,
1027 Directory => Obj_Dir);
1029 Source.Dep_Path := Create_Name (Dep_Path);
1030 Source.Dep_TS := Osint.Unknown_Attributes;
1034 -- Get the path of the switches file, even if Opt.Check_Switches is
1035 -- not set, as switch -s may be in the Builder switches that have not
1036 -- been scanned yet.
1039 Switches_Path : constant String :=
1042 Get_Name_String (Source.Switches),
1043 Resolve_Links => Opt.Follow_Links_For_Files,
1044 Directory => Obj_Dir);
1046 Source.Switches_Path := Create_Name (Switches_Path);
1048 if Stamp /= Empty_Time_Stamp then
1049 Source.Switches_TS := File_Stamp (Source.Switches_Path);
1052 end Set_Object_Project;
1054 Obj_Proj : Project_Id;
1057 -- Nothing to do if source record has already been fully initialized
1059 if Source.Initialized then
1063 -- Systematically recompute the time stamp
1065 Source.Source_TS := File_Stamp (Source.Path.Display_Name);
1067 -- Parse the source file to check whether we have a subunit
1069 if Source.Language.Config.Kind = Unit_Based
1070 and then Source.Kind = Impl
1071 and then Is_Subunit (Source)
1076 if Source.Language.Config.Object_Generated
1077 and then Is_Compilable (Source)
1079 -- First, get the correct object file name and dependency file name
1080 -- if the source is in a multi-unit file.
1082 if Source.Index /= 0 then
1085 (Source_File_Name => Source.File,
1086 Source_Index => Source.Index,
1088 Source.Language.Config.Multi_Unit_Object_Separator,
1089 Object_File_Suffix =>
1090 Source.Language.Config.Object_File_Suffix);
1094 (Source.Object, Source.Language.Config.Dependency_Kind);
1097 -- Find the object file for that source. It could be either in the
1098 -- current project or in an extended project (it might actually not
1099 -- exist yet in the ultimate extending project, but if not found
1100 -- elsewhere that's where we'll expect to find it).
1102 Obj_Proj := Source.Project;
1104 while Obj_Proj /= No_Project loop
1106 Dir : constant String :=
1108 (Obj_Proj.Object_Directory.Display_Name);
1110 Object_Path : constant String :=
1113 Get_Name_String (Source.Object),
1114 Resolve_Links => Opt.Follow_Links_For_Files,
1117 Obj_Path : constant Path_Name_Type := Create_Name (Object_Path);
1118 Stamp : Time_Stamp_Type := Empty_Time_Stamp;
1121 -- For specs, we do not check object files if there is a body.
1122 -- This saves a system call. On the other hand, we do need to
1123 -- know the object_path, in case the user has passed the .ads
1124 -- on the command line to compile the spec only.
1126 if Source.Kind /= Spec
1127 or else Source.Unit = No_Unit_Index
1128 or else Source.Unit.File_Names (Impl) = No_Source
1130 Stamp := File_Stamp (Obj_Path);
1133 if Stamp /= Empty_Time_Stamp
1134 or else (Obj_Proj.Extended_By = No_Project
1135 and then Source.Object_Project = No_Project)
1137 Set_Object_Project (Dir, Obj_Proj, Obj_Path, Stamp);
1140 Obj_Proj := Obj_Proj.Extended_By;
1144 elsif Source.Language.Config.Dependency_Kind = Makefile then
1146 Object_Dir : constant String :=
1148 (Source.Project.Object_Directory.Display_Name);
1149 Dep_Path : constant String :=
1151 (Name => Get_Name_String (Source.Dep_Name),
1153 Opt.Follow_Links_For_Files,
1154 Directory => Object_Dir);
1156 Source.Dep_Path := Create_Name (Dep_Path);
1157 Source.Dep_TS := Osint.Unknown_Attributes;
1161 Source.Initialized := True;
1162 end Initialize_Source_Record;
1164 ----------------------------
1165 -- Is_External_Assignment --
1166 ----------------------------
1168 function Is_External_Assignment
1169 (Env : Prj.Tree.Environment;
1170 Argv : String) return Boolean
1172 Start : Positive := 3;
1173 Finish : Natural := Argv'Last;
1175 pragma Assert (Argv'First = 1);
1176 pragma Assert (Argv (1 .. 2) = "-X");
1179 if Argv'Last < 5 then
1182 elsif Argv (3) = '"' then
1183 if Argv (Argv'Last) /= '"' or else Argv'Last < 7 then
1187 Finish := Argv'Last - 1;
1191 return Prj.Ext.Check
1192 (Self => Env.External,
1193 Declaration => Argv (Start .. Finish));
1194 end Is_External_Assignment;
1200 function Is_Subunit (Source : Prj.Source_Id) return Boolean is
1201 Src_Ind : Source_File_Index;
1204 if Source.Kind = Sep then
1207 -- A Spec, a file based language source or a body with a spec cannot be
1210 elsif Source.Kind = Spec
1211 or else Source.Unit = No_Unit_Index
1212 or else Other_Part (Source) /= No_Source
1217 -- Here, we are assuming that the language is Ada, as it is the only
1218 -- unit based language that we know.
1221 Sinput.P.Load_Project_File
1222 (Get_Name_String (Source.Path.Display_Name));
1224 return Sinput.P.Source_File_Is_Subunit (Src_Ind);
1227 -----------------------------
1228 -- Linker_Options_Switches --
1229 -----------------------------
1231 function Linker_Options_Switches
1232 (Project : Project_Id;
1233 Do_Fail : Fail_Proc;
1234 In_Tree : Project_Tree_Ref) return String_List
1236 procedure Recursive_Add
1238 In_Tree : Project_Tree_Ref;
1239 In_Aggregate_Lib : Boolean;
1240 Dummy : in out Boolean);
1241 -- The recursive routine used to add linker options
1247 procedure Recursive_Add
1249 In_Tree : Project_Tree_Ref;
1250 In_Aggregate_Lib : Boolean;
1251 Dummy : in out Boolean)
1253 pragma Unreferenced (Dummy, In_Aggregate_Lib);
1255 Linker_Package : Package_Id;
1256 Options : Variable_Value;
1261 (Name => Name_Linker,
1262 In_Packages => Proj.Decl.Packages,
1263 Shared => In_Tree.Shared);
1269 Attribute_Or_Array_Name => Name_Linker_Options,
1270 In_Package => Linker_Package,
1271 Shared => In_Tree.Shared);
1273 -- If attribute is present, add the project with the attribute to
1274 -- table Linker_Opts.
1276 if Options /= Nil_Variable_Value then
1277 Linker_Opts.Increment_Last;
1278 Linker_Opts.Table (Linker_Opts.Last) :=
1279 (Project => Proj, Options => Options.Values);
1283 procedure For_All_Projects is
1284 new For_Every_Project_Imported (Boolean, Recursive_Add);
1286 Dummy : Boolean := False;
1288 -- Start of processing for Linker_Options_Switches
1293 For_All_Projects (Project, In_Tree, Dummy, Imported_First => True);
1295 Last_Linker_Option := 0;
1297 for Index in reverse 1 .. Linker_Opts.Last loop
1299 Options : String_List_Id;
1300 Proj : constant Project_Id :=
1301 Linker_Opts.Table (Index).Project;
1303 Dir_Path : constant String :=
1304 Get_Name_String (Proj.Directory.Name);
1307 Options := Linker_Opts.Table (Index).Options;
1308 while Options /= Nil_String loop
1309 Option := In_Tree.Shared.String_Elements.Table (Options).Value;
1310 Get_Name_String (Option);
1312 -- Do not consider empty linker options
1314 if Name_Len /= 0 then
1315 Add_Linker_Option (Name_Buffer (1 .. Name_Len));
1317 -- Object files and -L switches specified with relative
1318 -- paths must be converted to absolute paths.
1320 Test_If_Relative_Path
1321 (Switch => Linker_Options_Buffer (Last_Linker_Option),
1324 Including_L_Switch => True);
1327 Options := In_Tree.Shared.String_Elements.Table (Options).Next;
1332 return Linker_Options_Buffer (1 .. Last_Linker_Option);
1333 end Linker_Options_Switches;
1339 package body Mains is
1341 package Names is new Table.Table
1342 (Table_Component_Type => Main_Info,
1343 Table_Index_Type => Integer,
1344 Table_Low_Bound => 1,
1345 Table_Initial => 10,
1346 Table_Increment => 100,
1347 Table_Name => "Makeutl.Mains.Names");
1348 -- The table that stores the mains
1350 Current : Natural := 0;
1351 -- The index of the last main retrieved from the table
1353 Count_Of_Mains_With_No_Tree : Natural := 0;
1354 -- Number of main units for which we do not know the project tree
1363 Location : Source_Ptr := No_Location;
1364 Project : Project_Id := No_Project;
1365 Tree : Project_Tree_Ref := null)
1368 if Current_Verbosity = High then
1369 Debug_Output ("Add_Main """ & Name & """ " & Index'Img
1371 & Boolean'Image (Tree /= null));
1375 Add_Str_To_Name_Buffer (Name);
1376 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1378 Names.Increment_Last;
1379 Names.Table (Names.Last) :=
1380 (Name_Find, Index, Location, No_Source, Project, Tree);
1382 if Tree /= null then
1383 Builder_Data (Tree).Number_Of_Mains :=
1384 Builder_Data (Tree).Number_Of_Mains + 1;
1387 Mains.Count_Of_Mains_With_No_Tree :=
1388 Mains.Count_Of_Mains_With_No_Tree + 1;
1392 --------------------
1393 -- Complete_Mains --
1394 --------------------
1396 procedure Complete_Mains
1397 (Flags : Processing_Flags;
1398 Root_Project : Project_Id;
1399 Project_Tree : Project_Tree_Ref)
1401 procedure Do_Complete (Project : Project_Id; Tree : Project_Tree_Ref);
1402 -- Check the mains for this specific project
1404 procedure Complete_All is new For_Project_And_Aggregated
1407 procedure Add_Multi_Unit_Sources
1408 (Tree : Project_Tree_Ref;
1409 Source : Prj.Source_Id);
1410 -- Add all units from the same file as the multi-unit Source
1412 function Find_File_Add_Extension
1413 (Tree : Project_Tree_Ref;
1414 Base_Main : String) return Prj.Source_Id;
1415 -- Search for Main in the project, adding body or spec extensions
1417 ----------------------------
1418 -- Add_Multi_Unit_Sources --
1419 ----------------------------
1421 procedure Add_Multi_Unit_Sources
1422 (Tree : Project_Tree_Ref;
1423 Source : Prj.Source_Id)
1425 Iter : Source_Iterator;
1426 Src : Prj.Source_Id;
1430 ("found multi-unit source file in project", Source.Project.Name);
1432 Iter := For_Each_Source
1433 (In_Tree => Tree, Project => Source.Project);
1435 while Element (Iter) /= No_Source loop
1436 Src := Element (Iter);
1438 if Src.File = Source.File
1439 and then Src.Index /= Source.Index
1441 if Src.File = Source.File then
1443 ("add main in project, index=" & Src.Index'Img);
1446 Names.Increment_Last;
1447 Names.Table (Names.Last) :=
1450 Location => No_Location,
1452 Project => Src.Project,
1455 Builder_Data (Tree).Number_Of_Mains :=
1456 Builder_Data (Tree).Number_Of_Mains + 1;
1461 end Add_Multi_Unit_Sources;
1463 -----------------------------
1464 -- Find_File_Add_Extension --
1465 -----------------------------
1467 function Find_File_Add_Extension
1468 (Tree : Project_Tree_Ref;
1469 Base_Main : String) return Prj.Source_Id
1471 Spec_Source : Prj.Source_Id := No_Source;
1472 Source : Prj.Source_Id;
1473 Iter : Source_Iterator;
1474 Suffix : File_Name_Type;
1477 Source := No_Source;
1478 Iter := For_Each_Source (Tree); -- In all projects
1480 Source := Prj.Element (Iter);
1481 exit when Source = No_Source;
1483 if Source.Kind = Impl then
1484 Get_Name_String (Source.File);
1486 if Name_Len > Base_Main'Length
1487 and then Name_Buffer (1 .. Base_Main'Length) = Base_Main
1490 Source.Language.Config.Naming_Data.Body_Suffix;
1492 if Suffix /= No_File then
1494 Suffix_Str : String := Get_Name_String (Suffix);
1496 Canonical_Case_File_Name (Suffix_Str);
1498 Name_Buffer (Base_Main'Length + 1 .. Name_Len) =
1504 elsif Source.Kind = Spec then
1505 -- A spec needs to be taken into account unless there is
1506 -- also a body. So we delay the decision for them.
1508 Get_Name_String (Source.File);
1510 if Name_Len > Base_Main'Length
1511 and then Name_Buffer (1 .. Base_Main'Length) = Base_Main
1513 Suffix := Source.Language.Config.Naming_Data.Spec_Suffix;
1515 if Suffix /= No_File then
1517 Suffix_Str : String := Get_Name_String (Suffix);
1520 Canonical_Case_File_Name (Suffix_Str);
1522 if Name_Buffer (Base_Main'Length + 1 .. Name_Len) =
1525 Spec_Source := Source;
1535 if Source = No_Source then
1536 Source := Spec_Source;
1540 end Find_File_Add_Extension;
1546 procedure Do_Complete
1547 (Project : Project_Id; Tree : Project_Tree_Ref)
1552 if Mains.Number_Of_Mains (Tree) > 0
1553 or else Mains.Count_Of_Mains_With_No_Tree > 0
1555 -- Traverse in reverse order, since in the case of multi-unit
1556 -- files we will be adding extra files at the end, and there's
1557 -- no need to process them in turn.
1562 File : Main_Info := Names.Table (J);
1563 Main_Id : File_Name_Type := File.File;
1564 Main : constant String :=
1565 Get_Name_String (Main_Id);
1566 Base : constant String := Base_Name (Main);
1567 Source : Prj.Source_Id := No_Source;
1568 Is_Absolute : Boolean := False;
1571 if Base /= Main then
1572 Is_Absolute := True;
1574 if Is_Absolute_Path (Main) then
1575 Main_Id := Create_Name (Base);
1577 -- Not an absolute path
1580 -- Always resolve links here, so that users can be
1581 -- specify any name on the command line. If the
1582 -- project itself uses links, the user will be
1583 -- using -eL anyway, and thus files are also stored
1584 -- with resolved names.
1587 Absolute : constant String :=
1591 Resolve_Links => True,
1592 Case_Sensitive => False);
1594 File.File := Create_Name (Absolute);
1595 Main_Id := Create_Name (Base);
1600 -- If no project or tree was specified for the main, it
1601 -- came from the command line.
1602 -- Note that the assignments below will not modify inside
1603 -- the table itself.
1605 if File.Project = null then
1606 File.Project := Project;
1609 if File.Tree = null then
1613 if File.Source = null then
1614 if Current_Verbosity = High then
1616 ("search for main """ & Main
1617 & '"' & File.Index'Img & " in "
1618 & Get_Name_String (Debug_Name (File.Tree))
1619 & ", project", Project.Name);
1622 -- First, look for the main as specified. We need to
1623 -- search for the base name though, and if needed
1624 -- check later that we found the correct file.
1626 Source := Find_Source
1627 (In_Tree => File.Tree,
1628 Project => File.Project,
1629 Base_Name => Main_Id,
1630 Index => File.Index,
1631 In_Imported_Only => True);
1633 if Source = No_Source then
1634 Source := Find_File_Add_Extension
1635 (Tree, Get_Name_String (Main_Id));
1639 and then Source /= No_Source
1641 File_Name_Type (Source.Path.Name) /= File.File
1644 ("Found a non-matching file",
1645 Name_Id (Source.Path.Display_Name));
1646 Source := No_Source;
1649 if Source /= No_Source then
1650 if not Is_Allowed_Language
1651 (Source.Language.Name)
1653 -- Remove any main that is not in the list of
1654 -- restricted languages.
1656 Names.Table (J .. Names.Last - 1) :=
1657 Names.Table (J + 1 .. Names.Last);
1658 Names.Set_Last (Names.Last - 1);
1661 -- If we have found a multi-unit source file but
1662 -- did not specify an index initially, we'll
1663 -- need to compile all the units from the same
1666 if Source.Index /= 0 and then File.Index = 0 then
1667 Add_Multi_Unit_Sources (File.Tree, Source);
1670 -- Now update the original Main, otherwise it
1671 -- will be reported as not found.
1674 ("found main in project", Source.Project.Name);
1675 Names.Table (J).File := Source.File;
1676 Names.Table (J).Project := Source.Project;
1678 if Names.Table (J).Tree = null then
1679 Names.Table (J).Tree := File.Tree;
1681 Builder_Data (File.Tree).Number_Of_Mains :=
1682 Builder_Data (File.Tree).Number_Of_Mains
1684 Mains.Count_Of_Mains_With_No_Tree :=
1685 Mains.Count_Of_Mains_With_No_Tree - 1;
1688 Names.Table (J).Source := Source;
1689 Names.Table (J).Index := Source.Index;
1692 elsif File.Location /= No_Location then
1694 -- If the main is declared in package Builder of
1695 -- the main project, report an error. If the main
1696 -- is on the command line, it may be a main from
1697 -- another project, so do nothing: if the main does
1698 -- not exist in another project, an error will be
1701 Error_Msg_File_1 := Main_Id;
1702 Error_Msg_Name_1 := Root_Project.Name;
1704 (Flags, "{ is not a source of project %%",
1705 File.Location, Project);
1711 exit when J < Names.First;
1715 if Total_Errors_Detected > 0 then
1716 Fail_Program (Tree, "problems with main sources");
1720 -- Start of processing for Complete_Mains
1723 Complete_All (Root_Project, Project_Tree);
1725 if Mains.Count_Of_Mains_With_No_Tree > 0 then
1726 for J in Names.First .. Names.Last loop
1727 if Names.Table (J).Source = No_Source then
1729 (Project_Tree, '"' & Get_Name_String (Names.Table (J).File)
1730 & """ is not a source of any project");
1746 -----------------------
1747 -- Fill_From_Project --
1748 -----------------------
1750 procedure Fill_From_Project
1751 (Root_Project : Project_Id;
1752 Project_Tree : Project_Tree_Ref)
1754 procedure Add_Mains_From_Project
1755 (Project : Project_Id;
1756 Tree : Project_Tree_Ref);
1757 -- Add the main units from this project into Mains.
1758 -- This takes into account the aggregated projects
1760 ----------------------------
1761 -- Add_Mains_From_Project --
1762 ----------------------------
1764 procedure Add_Mains_From_Project
1765 (Project : Project_Id;
1766 Tree : Project_Tree_Ref)
1768 List : String_List_Id;
1769 Element : String_Element;
1772 if Number_Of_Mains (Tree) = 0
1773 and then Mains.Count_Of_Mains_With_No_Tree = 0
1775 Debug_Output ("Add_Mains_From_Project", Project.Name);
1776 List := Project.Mains;
1778 if List /= Prj.Nil_String then
1780 -- The attribute Main is not an empty list. Get the mains in
1783 while List /= Prj.Nil_String loop
1784 Element := Tree.Shared.String_Elements.Table (List);
1785 Debug_Output ("Add_Main", Element.Value);
1787 if Project.Library then
1790 "cannot specify a main program " &
1791 "for a library project file");
1794 Add_Main (Name => Get_Name_String (Element.Value),
1795 Index => Element.Index,
1796 Location => Element.Location,
1799 List := Element.Next;
1804 if Total_Errors_Detected > 0 then
1805 Fail_Program (Tree, "problems with main sources");
1807 end Add_Mains_From_Project;
1809 procedure Fill_All is new For_Project_And_Aggregated
1810 (Add_Mains_From_Project);
1812 -- Start of processing for Fill_From_Project
1815 Fill_All (Root_Project, Project_Tree);
1816 end Fill_From_Project;
1822 function Next_Main return String is
1823 Info : constant Main_Info := Next_Main;
1825 if Info = No_Main_Info then
1828 return Get_Name_String (Info.File);
1832 function Next_Main return Main_Info is
1834 if Current >= Names.Last then
1835 return No_Main_Info;
1837 Current := Current + 1;
1839 -- If not using projects, and in the gnatmake case, the main file
1840 -- may have not have the extension. Try ".adb" first then ".ads"
1842 if Names.Table (Current).Project = No_Project then
1844 Orig_Main : constant File_Name_Type :=
1845 Names.Table (Current).File;
1846 Current_Main : File_Name_Type;
1849 if Strip_Suffix (Orig_Main) = Orig_Main then
1850 Get_Name_String (Orig_Main);
1851 Add_Str_To_Name_Buffer (".adb");
1852 Current_Main := Name_Find;
1854 if Full_Source_Name (Current_Main) = No_File then
1855 Get_Name_String (Orig_Main);
1856 Add_Str_To_Name_Buffer (".ads");
1857 Current_Main := Name_Find;
1859 if Full_Source_Name (Current_Main) /= No_File then
1860 Names.Table (Current).File := Current_Main;
1864 Names.Table (Current).File := Current_Main;
1870 return Names.Table (Current);
1874 ---------------------
1875 -- Number_Of_Mains --
1876 ---------------------
1878 function Number_Of_Mains (Tree : Project_Tree_Ref) return Natural is
1883 return Builder_Data (Tree).Number_Of_Mains;
1885 end Number_Of_Mains;
1896 --------------------------
1897 -- Set_Multi_Unit_Index --
1898 --------------------------
1900 procedure Set_Multi_Unit_Index
1901 (Project_Tree : Project_Tree_Ref := null;
1906 if Names.Last = 0 then
1909 "cannot specify a multi-unit index but no main " &
1910 "on the command line");
1912 elsif Names.Last > 1 then
1915 "cannot specify several mains with a multi-unit index");
1918 Names.Table (Names.Last).Index := Index;
1921 end Set_Multi_Unit_Index;
1925 -----------------------
1926 -- Path_Or_File_Name --
1927 -----------------------
1929 function Path_Or_File_Name (Path : Path_Name_Type) return String is
1930 Path_Name : constant String := Get_Name_String (Path);
1932 if Debug.Debug_Flag_F then
1933 return File_Name (Path_Name);
1937 end Path_Or_File_Name;
1939 ---------------------------
1940 -- Test_If_Relative_Path --
1941 ---------------------------
1943 procedure Test_If_Relative_Path
1944 (Switch : in out String_Access;
1946 Do_Fail : Fail_Proc;
1947 Including_L_Switch : Boolean := True;
1948 Including_Non_Switch : Boolean := True;
1949 Including_RTS : Boolean := False)
1952 if Switch /= null then
1954 Sw : String (1 .. Switch'Length);
1960 if Sw (1) = '-' then
1962 and then (Sw (2) = 'A'
1963 or else Sw (2) = 'I'
1964 or else (Including_L_Switch and then Sw (2) = 'L'))
1972 elsif Sw'Length >= 4
1973 and then (Sw (2 .. 3) = "aL"
1982 and then Sw'Length >= 7
1983 and then Sw (2 .. 6) = "-RTS="
1991 -- Because relative path arguments to --RTS= may be relative to
1992 -- the search directory prefix, those relative path arguments
1993 -- are converted only when they include directory information.
1995 if not Is_Absolute_Path (Sw (Start .. Sw'Last)) then
1996 if Parent'Length = 0 then
1998 ("relative search path switches ("""
2000 & """) are not allowed");
2002 elsif Including_RTS then
2003 for J in Start .. Sw'Last loop
2004 if Sw (J) = Directory_Separator then
2007 (Sw (1 .. Start - 1) &
2009 Directory_Separator &
2010 Sw (Start .. Sw'Last));
2018 (Sw (1 .. Start - 1) &
2020 Directory_Separator &
2021 Sw (Start .. Sw'Last));
2025 elsif Including_Non_Switch then
2026 if not Is_Absolute_Path (Sw) then
2027 if Parent'Length = 0 then
2029 ("relative paths (""" & Sw & """) are not allowed");
2031 Switch := new String'(Parent & Directory_Separator & Sw);
2037 end Test_If_Relative_Path;
2043 function Unit_Index_Of (ALI_File : File_Name_Type) return Int is
2049 Get_Name_String (ALI_File);
2051 -- First, find the last dot
2055 while Finish >= 1 and then Name_Buffer (Finish) /= '.' loop
2056 Finish := Finish - 1;
2063 -- Now check that the dot is preceded by digits
2066 Finish := Finish - 1;
2067 while Start >= 1 and then Name_Buffer (Start - 1) in '0' .. '9' loop
2071 -- If there are no digits, or if the digits are not preceded by the
2072 -- character that precedes a unit index, this is not the ALI file of
2073 -- a unit in a multi-unit source.
2077 or else Name_Buffer (Start - 1) /= Multi_Unit_Index_Character
2082 -- Build the index from the digit(s)
2084 while Start <= Finish loop
2085 Result := Result * 10 +
2086 Character'Pos (Name_Buffer (Start)) - Character'Pos ('0');
2097 procedure Verbose_Msg
2100 N2 : Name_Id := No_Name;
2102 Prefix : String := " -> ";
2103 Minimum_Verbosity : Opt.Verbosity_Level_Type := Opt.Low)
2106 if not Opt.Verbose_Mode
2107 or else Minimum_Verbosity > Opt.Verbosity_Level
2118 if N2 /= No_Name then
2128 procedure Verbose_Msg
2129 (N1 : File_Name_Type;
2131 N2 : File_Name_Type := No_File;
2133 Prefix : String := " -> ";
2134 Minimum_Verbosity : Opt.Verbosity_Level_Type := Opt.Low)
2138 (Name_Id (N1), S1, Name_Id (N2), S2, Prefix, Minimum_Verbosity);
2145 package body Queue is
2147 type Q_Record is record
2149 Processed : Boolean;
2152 package Q is new Table.Table
2153 (Table_Component_Type => Q_Record,
2154 Table_Index_Type => Natural,
2155 Table_Low_Bound => 1,
2156 Table_Initial => 1000,
2157 Table_Increment => 100,
2158 Table_Name => "Makeutl.Queue.Q");
2159 -- This is the actual Queue
2161 package Busy_Obj_Dirs is new GNAT.HTable.Simple_HTable
2162 (Header_Num => Prj.Header_Num,
2164 No_Element => False,
2165 Key => Path_Name_Type,
2169 type Mark_Key is record
2170 File : File_Name_Type;
2173 -- Identify either a mono-unit source (when Index = 0) or a specific
2174 -- unit (index = 1's origin index of unit) in a multi-unit source.
2176 Max_Mask_Num : constant := 2048;
2177 subtype Mark_Num is Union_Id range 0 .. Max_Mask_Num - 1;
2179 function Hash (Key : Mark_Key) return Mark_Num;
2181 package Marks is new GNAT.HTable.Simple_HTable
2182 (Header_Num => Mark_Num,
2184 No_Element => False,
2188 -- A hash table to keep tracks of the marked units.
2189 -- These are the units that have already been processed, when using the
2190 -- gnatmake format. When using the gprbuild format, we can directly
2191 -- store in the source_id whether the file has already been processed.
2193 procedure Mark (Source_File : File_Name_Type; Index : Int := 0);
2194 -- Mark a unit, identified by its source file and, when Index is not 0,
2195 -- the index of the unit in the source file. Marking is used to signal
2196 -- that the unit has already been inserted in the Q.
2199 (Source_File : File_Name_Type;
2200 Index : Int := 0) return Boolean;
2201 -- Returns True if the unit was previously marked
2203 Q_Processed : Natural := 0;
2204 Q_Initialized : Boolean := False;
2206 Q_First : Natural := 1;
2207 -- Points to the first valid element in the queue
2209 One_Queue_Per_Obj_Dir : Boolean := False;
2210 -- See parameter to Initialize
2212 function Available_Obj_Dir (S : Source_Info) return Boolean;
2213 -- Whether the object directory for S is available for a build
2215 procedure Debug_Display (S : Source_Info);
2216 -- A debug display for S
2218 function Was_Processed (S : Source_Info) return Boolean;
2219 -- Whether S has already been processed. This marks the source as
2220 -- processed, if it hasn't already been processed.
2222 function Insert_No_Roots (Source : Source_Info) return Boolean;
2223 -- Insert Source, but do not look for its roots (see doc for Insert)
2229 function Was_Processed (S : Source_Info) return Boolean is
2232 when Format_Gprbuild =>
2233 if S.Id.In_The_Queue then
2237 S.Id.In_The_Queue := True;
2239 when Format_Gnatmake =>
2240 if Is_Marked (S.File, S.Index) then
2244 Mark (S.File, Index => S.Index);
2250 -----------------------
2251 -- Available_Obj_Dir --
2252 -----------------------
2254 function Available_Obj_Dir (S : Source_Info) return Boolean is
2257 when Format_Gprbuild =>
2258 return not Busy_Obj_Dirs.Get
2259 (S.Id.Project.Object_Directory.Name);
2261 when Format_Gnatmake =>
2262 return S.Project = No_Project
2264 not Busy_Obj_Dirs.Get (S.Project.Object_Directory.Name);
2266 end Available_Obj_Dir;
2272 procedure Debug_Display (S : Source_Info) is
2275 when Format_Gprbuild =>
2276 Write_Name (S.Id.File);
2278 if S.Id.Index /= 0 then
2280 Write_Int (S.Id.Index);
2283 when Format_Gnatmake =>
2284 Write_Name (S.File);
2286 if S.Index /= 0 then
2288 Write_Int (S.Index);
2297 function Hash (Key : Mark_Key) return Mark_Num is
2299 return Union_Id (Key.File) mod Max_Mask_Num;
2307 (Source_File : File_Name_Type;
2308 Index : Int := 0) return Boolean
2311 return Marks.Get (K => (File => Source_File, Index => Index));
2318 procedure Mark (Source_File : File_Name_Type; Index : Int := 0) is
2320 Marks.Set (K => (File => Source_File, Index => Index), E => True);
2328 (Found : out Boolean;
2329 Source : out Source_Info)
2334 if One_Queue_Per_Obj_Dir then
2335 for J in Q_First .. Q.Last loop
2336 if not Q.Table (J).Processed
2337 and then Available_Obj_Dir (Q.Table (J).Info)
2340 Source := Q.Table (J).Info;
2341 Q.Table (J).Processed := True;
2344 while Q_First <= Q.Last
2345 and then Q.Table (Q_First).Processed
2347 Q_First := Q_First + 1;
2355 elsif Q_First <= Q.Last then
2356 Source := Q.Table (Q_First).Info;
2357 Q.Table (Q_First).Processed := True;
2358 Q_First := Q_First + 1;
2363 Q_Processed := Q_Processed + 1;
2366 if Found and then Debug.Debug_Flag_Q then
2367 Write_Str (" Q := Q - [ ");
2368 Debug_Display (Source);
2372 Write_Str (" Q_First =");
2373 Write_Int (Int (Q_First));
2376 Write_Str (" Q.Last =");
2377 Write_Int (Int (Q.Last));
2386 function Processed return Natural is
2395 procedure Initialize
2396 (Queue_Per_Obj_Dir : Boolean;
2397 Force : Boolean := False)
2400 if Force or else not Q_Initialized then
2401 Q_Initialized := True;
2403 for J in 1 .. Q.Last loop
2404 case Q.Table (J).Info.Format is
2405 when Format_Gprbuild =>
2406 Q.Table (J).Info.Id.In_The_Queue := False;
2407 when Format_Gnatmake =>
2415 One_Queue_Per_Obj_Dir := Queue_Per_Obj_Dir;
2419 ---------------------
2420 -- Insert_No_Roots --
2421 ---------------------
2423 function Insert_No_Roots (Source : Source_Info) return Boolean is
2426 (Source.Format = Format_Gnatmake or else Source.Id /= No_Source);
2428 -- Only insert in the Q if it is not already done, to avoid
2429 -- simultaneous compilations if -jnnn is used.
2431 if Was_Processed (Source) then
2435 if Current_Verbosity = High then
2436 Write_Str ("Adding """);
2437 Debug_Display (Source);
2438 Write_Line (""" to the queue");
2441 Q.Append (New_Val => (Info => Source, Processed => False));
2443 if Debug.Debug_Flag_Q then
2444 Write_Str (" Q := Q + [ ");
2445 Debug_Display (Source);
2449 Write_Str (" Q_First =");
2450 Write_Int (Int (Q_First));
2453 Write_Str (" Q.Last =");
2454 Write_Int (Int (Q.Last));
2459 end Insert_No_Roots;
2466 (Source : Source_Info;
2467 With_Roots : Boolean := False) return Boolean
2469 Root_Arr : Array_Element_Id;
2470 Roots : Variable_Value;
2471 List : String_List_Id;
2472 Elem : String_Element;
2473 Unit_Name : Name_Id;
2475 Root_Pattern : Regexp;
2476 Root_Found : Boolean;
2477 Roots_Found : Boolean;
2478 Root_Source : Prj.Source_Id;
2479 Iter : Source_Iterator;
2482 pragma Unreferenced (Dummy);
2485 if not Insert_No_Roots (Source) then
2487 -- Was already in the queue
2492 if With_Roots and then Source.Format = Format_Gprbuild then
2493 Debug_Output ("looking for roots of", Name_Id (Source.Id.File));
2497 (Name => Name_Roots,
2498 In_Arrays => Source.Id.Project.Decl.Arrays,
2499 Shared => Source.Tree.Shared);
2503 (Index => Name_Id (Source.Id.File),
2505 In_Array => Root_Arr,
2506 Shared => Source.Tree.Shared);
2508 -- If there is no roots for the specific main, try the language
2510 if Roots = Nil_Variable_Value then
2513 (Index => Source.Id.Language.Name,
2515 In_Array => Root_Arr,
2516 Shared => Source.Tree.Shared,
2517 Force_Lower_Case_Index => True);
2522 if Roots = Nil_Variable_Value then
2524 Name_Buffer (1) := '*';
2528 (Index => Name_Find,
2530 In_Array => Root_Arr,
2531 Shared => Source.Tree.Shared,
2532 Force_Lower_Case_Index => True);
2535 if Roots = Nil_Variable_Value then
2536 Debug_Output (" -> no roots declared");
2539 List := Roots.Values;
2542 while List /= Nil_String loop
2543 Elem := Source.Tree.Shared.String_Elements.Table (List);
2544 Get_Name_String (Elem.Value);
2545 To_Lower (Name_Buffer (1 .. Name_Len));
2546 Unit_Name := Name_Find;
2548 -- Check if it is a unit name or a pattern
2552 for J in 1 .. Name_Len loop
2553 if Name_Buffer (J) not in 'a' .. 'z' and then
2554 Name_Buffer (J) not in '0' .. '9' and then
2555 Name_Buffer (J) /= '_' and then
2556 Name_Buffer (J) /= '.'
2567 (Pattern => Name_Buffer (1 .. Name_Len),
2571 when Error_In_Regexp =>
2572 Err_Vars.Error_Msg_Name_1 := Unit_Name;
2574 ("invalid pattern %", Roots.Location);
2579 Roots_Found := False;
2580 Iter := For_Each_Source (Source.Tree);
2584 Root_Source := Prj.Element (Iter);
2585 exit Source_Loop when Root_Source = No_Source;
2587 Root_Found := False;
2589 Root_Found := Root_Source.Unit /= No_Unit_Index
2591 (Get_Name_String (Root_Source.Unit.Name),
2596 Root_Source.Unit /= No_Unit_Index
2597 and then Root_Source.Unit.Name = Unit_Name;
2601 case Root_Source.Kind is
2606 Root_Found := Other_Part (Root_Source) = No_Source;
2609 Root_Found := False;
2614 Roots_Found := True;
2616 (" -> ", Name_Id (Root_Source.Display_File));
2617 Dummy := Queue.Insert_No_Roots
2618 (Source => (Format => Format_Gprbuild,
2619 Tree => Source.Tree,
2620 Id => Root_Source));
2622 Initialize_Source_Record (Root_Source);
2624 if Other_Part (Root_Source) /= No_Source then
2625 Initialize_Source_Record (Other_Part (Root_Source));
2628 -- Save the root for the binder
2630 Source.Id.Roots := new Source_Roots'
2631 (Root => Root_Source,
2632 Next => Source.Id.Roots);
2634 exit Source_Loop when not Pat_Root;
2638 end loop Source_Loop;
2640 if not Roots_Found then
2642 if not Quiet_Output then
2643 Error_Msg_Name_1 := Unit_Name;
2645 ("?no unit matches pattern %", Roots.Location);
2650 ("Unit " & Get_Name_String (Unit_Name)
2651 & " does not exist", Roots.Location);
2656 end loop Pattern_Loop;
2668 (Source : Source_Info;
2669 With_Roots : Boolean := False)
2672 pragma Unreferenced (Discard);
2674 Discard := Insert (Source, With_Roots);
2681 function Is_Empty return Boolean is
2683 return Q_Processed >= Q.Last;
2686 ------------------------
2687 -- Is_Virtually_Empty --
2688 ------------------------
2690 function Is_Virtually_Empty return Boolean is
2692 if One_Queue_Per_Obj_Dir then
2693 for J in Q_First .. Q.Last loop
2694 if not Q.Table (J).Processed
2695 and then Available_Obj_Dir (Q.Table (J).Info)
2706 end Is_Virtually_Empty;
2708 ----------------------
2709 -- Set_Obj_Dir_Busy --
2710 ----------------------
2712 procedure Set_Obj_Dir_Busy (Obj_Dir : Path_Name_Type) is
2714 if One_Queue_Per_Obj_Dir then
2715 Busy_Obj_Dirs.Set (Obj_Dir, True);
2717 end Set_Obj_Dir_Busy;
2719 ----------------------
2720 -- Set_Obj_Dir_Free --
2721 ----------------------
2723 procedure Set_Obj_Dir_Free (Obj_Dir : Path_Name_Type) is
2725 if One_Queue_Per_Obj_Dir then
2726 Busy_Obj_Dirs.Set (Obj_Dir, False);
2728 end Set_Obj_Dir_Free;
2734 function Size return Natural is
2743 function Element (Rank : Positive) return File_Name_Type is
2745 if Rank <= Q.Last then
2746 case Q.Table (Rank).Info.Format is
2747 when Format_Gprbuild =>
2748 return Q.Table (Rank).Info.Id.File;
2749 when Format_Gnatmake =>
2750 return Q.Table (Rank).Info.File;
2761 procedure Remove_Marks is
2766 ----------------------------
2767 -- Insert_Project_Sources --
2768 ----------------------------
2770 procedure Insert_Project_Sources
2771 (Project : Project_Id;
2772 Project_Tree : Project_Tree_Ref;
2773 All_Projects : Boolean;
2774 Unique_Compile : Boolean)
2776 procedure Do_Insert (Project : Project_Id; Tree : Project_Tree_Ref);
2782 procedure Do_Insert (Project : Project_Id; Tree : Project_Tree_Ref) is
2783 Unit_Based : constant Boolean :=
2785 or else not Builder_Data (Tree).Closure_Needed;
2786 -- When Unit_Based is True, put in the queue all compilable
2787 -- sources including the unit based (Ada) one. When Unit_Based is
2788 -- False, put the Ada sources only when they are in a library
2791 Iter : Source_Iterator;
2792 Source : Prj.Source_Id;
2795 -- Nothing to do when "-u" was specified and some files were
2796 -- specified on the command line
2799 and then Mains.Number_Of_Mains (Tree) > 0
2804 Iter := For_Each_Source (Tree);
2806 Source := Prj.Element (Iter);
2807 exit when Source = No_Source;
2809 if Is_Allowed_Language (Source.Language.Name)
2810 and then Is_Compilable (Source)
2813 or else Is_Extending (Project, Source.Project))
2814 and then not Source.Locally_Removed
2815 and then Source.Replaced_By = No_Source
2817 (not Source.Project.Externally_Built
2819 (Is_Extending (Project, Source.Project)
2820 and then not Project.Externally_Built))
2821 and then Source.Kind /= Sep
2822 and then Source.Path /= No_Path_Information
2824 if Source.Kind = Impl
2825 or else (Source.Unit /= No_Unit_Index
2826 and then Source.Kind = Spec
2827 and then (Other_Part (Source) = No_Source
2829 Other_Part (Source).Locally_Removed))
2832 or else Source.Unit = No_Unit_Index
2833 or else Source.Project.Library)
2834 and then not Is_Subunit (Source)
2837 (Source => (Format => Format_Gprbuild,
2848 procedure Insert_All is new For_Project_And_Aggregated (Do_Insert);
2851 Insert_All (Project, Project_Tree);
2852 end Insert_Project_Sources;
2854 -------------------------------
2855 -- Insert_Withed_Sources_For --
2856 -------------------------------
2858 procedure Insert_Withed_Sources_For
2859 (The_ALI : ALI.ALI_Id;
2860 Project_Tree : Project_Tree_Ref;
2861 Excluding_Shared_SALs : Boolean := False)
2863 Sfile : File_Name_Type;
2864 Afile : File_Name_Type;
2865 Src_Id : Prj.Source_Id;
2868 -- Insert in the queue the unmarked source files (i.e. those which
2869 -- have never been inserted in the queue and hence never considered).
2871 for J in ALI.ALIs.Table (The_ALI).First_Unit ..
2872 ALI.ALIs.Table (The_ALI).Last_Unit
2874 for K in ALI.Units.Table (J).First_With ..
2875 ALI.Units.Table (J).Last_With
2877 Sfile := ALI.Withs.Table (K).Sfile;
2881 if Sfile /= No_File then
2882 Afile := ALI.Withs.Table (K).Afile;
2884 Src_Id := Source_Files_Htable.Get
2885 (Project_Tree.Source_Files_HT, Sfile);
2886 while Src_Id /= No_Source loop
2887 Initialize_Source_Record (Src_Id);
2889 if Is_Compilable (Src_Id)
2890 and then Src_Id.Dep_Name = Afile
2895 Bdy : constant Prj.Source_Id :=
2896 Other_Part (Src_Id);
2899 and then not Bdy.Locally_Removed
2901 Src_Id := Other_Part (Src_Id);
2906 if Is_Subunit (Src_Id) then
2907 Src_Id := No_Source;
2911 Src_Id := No_Source;
2917 Src_Id := Src_Id.Next_With_File_Name;
2920 -- If Excluding_Shared_SALs is True, do not insert in the
2921 -- queue the sources of a shared Stand-Alone Library.
2923 if Src_Id /= No_Source
2924 and then (not Excluding_Shared_SALs
2925 or else Src_Id.Project.Standalone_Library = No
2926 or else Src_Id.Project.Library_Kind = Static)
2929 (Source => (Format => Format_Gprbuild,
2930 Tree => Project_Tree,
2936 end Insert_Withed_Sources_For;
2944 procedure Free (Data : in out Builder_Project_Tree_Data) is
2945 procedure Unchecked_Free is new Ada.Unchecked_Deallocation
2946 (Binding_Data_Record, Binding_Data);
2948 TmpB, Binding : Binding_Data := Data.Binding;
2951 while Binding /= null loop
2952 TmpB := Binding.Next;
2953 Unchecked_Free (Binding);
2962 function Builder_Data
2963 (Tree : Project_Tree_Ref) return Builder_Data_Access
2966 if Tree.Appdata = null then
2967 Tree.Appdata := new Builder_Project_Tree_Data;
2970 return Builder_Data_Access (Tree.Appdata);
2973 --------------------------------
2974 -- Compute_Compilation_Phases --
2975 --------------------------------
2977 procedure Compute_Compilation_Phases
2978 (Tree : Project_Tree_Ref;
2979 Root_Project : Project_Id;
2980 Option_Unique_Compile : Boolean := False; -- Was "-u" specified ?
2981 Option_Compile_Only : Boolean := False; -- Was "-c" specified ?
2982 Option_Bind_Only : Boolean := False;
2983 Option_Link_Only : Boolean := False)
2985 procedure Do_Compute (Project : Project_Id; Tree : Project_Tree_Ref);
2991 procedure Do_Compute (Project : Project_Id; Tree : Project_Tree_Ref) is
2992 Data : constant Builder_Data_Access := Builder_Data (Tree);
2993 All_Phases : constant Boolean :=
2994 not Option_Compile_Only
2995 and then not Option_Bind_Only
2996 and then not Option_Link_Only;
2997 -- Whether the command line asked for all three phases. Depending on
2998 -- the project settings, we might still disable some of the phases.
3000 Has_Mains : constant Boolean := Data.Number_Of_Mains > 0;
3001 -- Whether there are some main units defined for this project tree
3002 -- (either from one of the projects, or from the command line)
3005 if Option_Unique_Compile then
3007 -- If -u or -U is specified on the command line, disregard any -c,
3008 -- -b or -l switch: only perform compilation.
3010 Data.Closure_Needed := False;
3011 Data.Need_Compilation := True;
3012 Data.Need_Binding := False;
3013 Data.Need_Linking := False;
3016 Data.Closure_Needed := Has_Mains;
3017 Data.Need_Compilation := All_Phases or Option_Compile_Only;
3018 Data.Need_Binding := All_Phases or Option_Bind_Only;
3019 Data.Need_Linking := (All_Phases or Option_Link_Only)
3023 if Current_Verbosity = High then
3024 Debug_Output ("compilation phases: "
3025 & " compile=" & Data.Need_Compilation'Img
3026 & " bind=" & Data.Need_Binding'Img
3027 & " link=" & Data.Need_Linking'Img
3028 & " closure=" & Data.Closure_Needed'Img
3029 & " mains=" & Data.Number_Of_Mains'Img,
3034 procedure Compute_All is new For_Project_And_Aggregated (Do_Compute);
3037 Compute_All (Root_Project, Tree);
3038 end Compute_Compilation_Phases;
3040 ------------------------------
3041 -- Compute_Builder_Switches --
3042 ------------------------------
3044 procedure Compute_Builder_Switches
3045 (Project_Tree : Project_Tree_Ref;
3046 Root_Environment : in out Prj.Tree.Environment;
3047 Main_Project : Project_Id;
3048 Only_For_Lang : Name_Id := No_Name)
3050 Builder_Package : constant Package_Id :=
3051 Value_Of (Name_Builder, Main_Project.Decl.Packages,
3052 Project_Tree.Shared);
3054 Global_Compilation_Array : Array_Element_Id;
3055 Global_Compilation_Elem : Array_Element;
3056 Global_Compilation_Switches : Variable_Value;
3058 Default_Switches_Array : Array_Id;
3060 Builder_Switches_Lang : Name_Id := No_Name;
3062 List : String_List_Id;
3063 Element : String_Element;
3066 Source : Prj.Source_Id;
3068 Lang : Name_Id := No_Name; -- language index for Switches
3069 Switches_For_Lang : Variable_Value := Nil_Variable_Value;
3070 -- Value of Builder'Default_Switches(lang)
3072 Name : Name_Id := No_Name; -- main file index for Switches
3073 Switches_For_Main : Variable_Value := Nil_Variable_Value;
3074 -- Switches for a specific main. When there are several mains, Name is
3075 -- set to No_Name, and Switches_For_Main might be left with an actual
3076 -- value (so that we can display a warning that it was ignored).
3078 Other_Switches : Variable_Value := Nil_Variable_Value;
3079 -- Value of Builder'Switches(others)
3081 Defaults : Variable_Value := Nil_Variable_Value;
3083 Switches : Variable_Value := Nil_Variable_Value;
3084 -- The computed builder switches
3086 Success : Boolean := False;
3088 if Builder_Package /= No_Package then
3091 -- If there is no main, and there is only one compilable language,
3092 -- use this language as the switches index.
3094 if Mains.Number_Of_Mains (Project_Tree) = 0 then
3095 if Only_For_Lang = No_Name then
3097 Language : Language_Ptr := Main_Project.Languages;
3100 while Language /= No_Language_Index loop
3101 if Language.Config.Compiler_Driver /= No_File
3102 and then Language.Config.Compiler_Driver /= Empty_File
3104 if Lang /= No_Name then
3108 Lang := Language.Name;
3111 Language := Language.Next;
3115 Lang := Only_For_Lang;
3119 for Index in 1 .. Mains.Number_Of_Mains (Project_Tree) loop
3120 Source := Mains.Next_Main.Source;
3122 if Source /= No_Source then
3123 if Switches_For_Main = Nil_Variable_Value then
3124 Switches_For_Main := Value_Of
3125 (Name => Name_Id (Source.File),
3126 Attribute_Or_Array_Name => Name_Switches,
3127 In_Package => Builder_Package,
3128 Shared => Project_Tree.Shared,
3129 Force_Lower_Case_Index => False,
3130 Allow_Wildcards => True);
3132 -- If not found, try without extension.
3133 -- That's because gnatmake accepts truncated file names
3134 -- in Builder'Switches
3136 if Switches_For_Main = Nil_Variable_Value
3137 and then Source.Unit /= null
3139 Switches_For_Main := Value_Of
3140 (Name => Source.Unit.Name,
3141 Attribute_Or_Array_Name => Name_Switches,
3142 In_Package => Builder_Package,
3143 Shared => Project_Tree.Shared,
3144 Force_Lower_Case_Index => False,
3145 Allow_Wildcards => True);
3150 Lang := Source.Language.Name;
3151 Name := Name_Id (Source.File);
3153 Name := No_Name; -- Can't use main specific switches
3155 if Lang /= Source.Language.Name then
3163 Global_Compilation_Array := Value_Of
3164 (Name => Name_Global_Compilation_Switches,
3165 In_Arrays => Project_Tree.Shared.Packages.Table
3166 (Builder_Package).Decl.Arrays,
3167 Shared => Project_Tree.Shared);
3169 Default_Switches_Array :=
3170 Project_Tree.Shared.Packages.Table (Builder_Package).Decl.Arrays;
3172 while Default_Switches_Array /= No_Array
3174 Project_Tree.Shared.Arrays.Table (Default_Switches_Array).Name /=
3175 Name_Default_Switches
3177 Default_Switches_Array :=
3178 Project_Tree.Shared.Arrays.Table (Default_Switches_Array).Next;
3181 if Global_Compilation_Array /= No_Array_Element
3182 and then Default_Switches_Array /= No_Array
3185 (Root_Environment.Flags,
3186 "Default_Switches forbidden in presence of " &
3187 "Global_Compilation_Switches. Use Switches instead.",
3188 Project_Tree.Shared.Arrays.Table
3189 (Default_Switches_Array).Location);
3192 "*** illegal combination of Builder attributes");
3195 if Lang /= No_Name then
3196 Switches_For_Lang := Prj.Util.Value_Of
3199 Attribute_Or_Array_Name => Name_Switches,
3200 In_Package => Builder_Package,
3201 Shared => Project_Tree.Shared,
3202 Force_Lower_Case_Index => True);
3204 Defaults := Prj.Util.Value_Of
3207 Attribute_Or_Array_Name => Name_Default_Switches,
3208 In_Package => Builder_Package,
3209 Shared => Project_Tree.Shared,
3210 Force_Lower_Case_Index => True);
3213 Other_Switches := Prj.Util.Value_Of
3214 (Name => All_Other_Names,
3216 Attribute_Or_Array_Name => Name_Switches,
3217 In_Package => Builder_Package,
3218 Shared => Project_Tree.Shared);
3221 and then Mains.Number_Of_Mains (Project_Tree) > 1
3222 and then Switches_For_Main /= Nil_Variable_Value
3224 -- More than one main, but we had main-specific switches that
3227 if Switches_For_Lang /= Nil_Variable_Value then
3229 ("Warning: using Builder'Switches("""
3230 & Get_Name_String (Lang)
3231 & """), as there are several mains");
3233 elsif Other_Switches /= Nil_Variable_Value then
3235 ("Warning: using Builder'Switches(others), "
3236 & "as there are several mains");
3238 elsif Defaults /= Nil_Variable_Value then
3240 ("Warning: using Builder'Default_Switches("""
3241 & Get_Name_String (Lang)
3242 & """), as there are several mains");
3245 ("Warning: using no switches from package "
3246 & "Builder, as there are several mains");
3250 Builder_Switches_Lang := Lang;
3252 if Name /= No_Name then
3253 -- Get the switches for the single main
3254 Switches := Switches_For_Main;
3257 if Switches = Nil_Variable_Value or else Switches.Default then
3258 -- Get the switches for the common language of the mains
3259 Switches := Switches_For_Lang;
3262 if Switches = Nil_Variable_Value or else Switches.Default then
3263 Switches := Other_Switches;
3266 -- For backward compatibility with gnatmake, if no Switches
3267 -- are declared, check for Default_Switches (<language>).
3269 if Switches = Nil_Variable_Value or else Switches.Default then
3270 Switches := Defaults;
3273 -- If switches have been found, scan them
3275 if Switches /= Nil_Variable_Value and then not Switches.Default then
3276 List := Switches.Values;
3278 while List /= Nil_String loop
3279 Element := Project_Tree.Shared.String_Elements.Table (List);
3280 Get_Name_String (Element.Value);
3282 if Name_Len /= 0 then
3284 -- Add_Switch might itself be using the name_buffer, so
3285 -- we make a temporary here.
3286 Switch : constant String := Name_Buffer (1 .. Name_Len);
3288 Success := Add_Switch
3290 For_Lang => Builder_Switches_Lang,
3291 For_Builder => True,
3292 Has_Global_Compilation_Switches =>
3293 Global_Compilation_Array /= No_Array_Element);
3297 for J in reverse 1 .. Name_Len loop
3298 Name_Buffer (J + J) := Name_Buffer (J);
3299 Name_Buffer (J + J - 1) := ''';
3302 Name_Len := Name_Len + Name_Len;
3305 (Root_Environment.Flags,
3306 '"' & Name_Buffer (1 .. Name_Len) &
3307 """ is not a builder switch. Consider moving " &
3308 "it to Global_Compilation_Switches.",
3312 "*** illegal switch """ &
3313 Get_Name_String (Element.Value) & '"');
3317 List := Element.Next;
3321 -- Reset the Builder Switches language
3323 Builder_Switches_Lang := No_Name;
3325 -- Take into account attributes Global_Compilation_Switches
3327 while Global_Compilation_Array /= No_Array_Element loop
3328 Global_Compilation_Elem :=
3329 Project_Tree.Shared.Array_Elements.Table
3330 (Global_Compilation_Array);
3332 Get_Name_String (Global_Compilation_Elem.Index);
3333 To_Lower (Name_Buffer (1 .. Name_Len));
3336 if Only_For_Lang = No_Name or else Index = Only_For_Lang then
3337 Global_Compilation_Switches := Global_Compilation_Elem.Value;
3339 if Global_Compilation_Switches /= Nil_Variable_Value
3340 and then not Global_Compilation_Switches.Default
3342 -- We have found an attribute
3343 -- Global_Compilation_Switches for a language: put the
3344 -- switches in the appropriate table.
3346 List := Global_Compilation_Switches.Values;
3347 while List /= Nil_String loop
3349 Project_Tree.Shared.String_Elements.Table (List);
3351 if Element.Value /= No_Name then
3352 Success := Add_Switch
3353 (Switch => Get_Name_String (Element.Value),
3355 For_Builder => False,
3356 Has_Global_Compilation_Switches =>
3357 Global_Compilation_Array /= No_Array_Element);
3360 List := Element.Next;
3365 Global_Compilation_Array := Global_Compilation_Elem.Next;
3368 end Compute_Builder_Switches;
3370 ---------------------
3371 -- Write_Path_File --
3372 ---------------------
3374 procedure Write_Path_File (FD : File_Descriptor) is
3381 for Index in Directories.First .. Directories.Last loop
3382 Add_Str_To_Name_Buffer (Get_Name_String (Directories.Table (Index)));
3383 Add_Char_To_Name_Buffer (ASCII.LF);
3386 Last := Write (FD, Name_Buffer (1)'Address, Name_Len);
3388 if Last = Name_Len then
3395 Prj.Com.Fail ("could not write temporary file");
3397 end Write_Path_File;