1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2004-2012, 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 Name_Id
191 Result : Name_Id := No_Name;
195 -- Loop through units
197 for U in ALIs.Table (The_ALI).First_Unit ..
198 ALIs.Table (The_ALI).Last_Unit
200 -- Check if the file name is one of the source of the unit
202 Get_Name_String (Units.Table (U).Uname);
203 Name_Len := Name_Len - 2;
204 Unit_Name := Name_Find;
206 if File_Not_A_Source_Of (Tree, Unit_Name, Units.Table (U).Sfile) then
210 if Result = No_Name then
214 -- Loop to do same check for each of the withed units
216 for W in Units.Table (U).First_With .. Units.Table (U).Last_With loop
218 WR : ALI.With_Record renames Withs.Table (W);
221 if WR.Sfile /= No_File then
222 Get_Name_String (WR.Uname);
223 Name_Len := Name_Len - 2;
224 Unit_Name := Name_Find;
226 if File_Not_A_Source_Of (Tree, Unit_Name, WR.Sfile) then
234 -- Loop to check subunits and replaced sources
236 for D in ALIs.Table (The_ALI).First_Sdep ..
237 ALIs.Table (The_ALI).Last_Sdep
240 SD : Sdep_Record renames Sdep.Table (D);
243 Unit_Name := SD.Subunit_Name;
245 if Unit_Name = No_Name then
247 -- Check if this source file has been replaced by a source with
248 -- a different file name.
250 if Tree /= null and then Tree.Replaced_Source_Number > 0 then
252 Replacement : constant File_Name_Type :=
253 Replaced_Source_HTable.Get
254 (Tree.Replaced_Sources, SD.Sfile);
257 if Replacement /= No_File then
261 Get_Name_String (SD.Sfile) &
262 " has been replaced by " &
263 Get_Name_String (Replacement));
272 -- For separates, the file is no longer associated with the
273 -- unit ("proc-sep.adb" is not associated with unit "proc.sep")
274 -- so we need to check whether the source file still exists in
275 -- the source tree: it will if it matches the naming scheme
276 -- (and then will be for the same unit).
280 Project => No_Project,
281 Base_Name => SD.Sfile) = No_Source
283 -- If this is not a runtime file or if, when gnatmake switch
284 -- -a is used, we are not able to find this subunit in the
285 -- source directories, then recompilation is needed.
287 if not Fname.Is_Internal_File_Name (SD.Sfile)
289 (Check_Readonly_Files
290 and then Full_Source_Name (SD.Sfile) = No_File)
294 ("While parsing ALI file, file "
295 & Get_Name_String (SD.Sfile)
296 & " is indicated as containing subunit "
297 & Get_Name_String (Unit_Name)
298 & " but this does not match what was found while"
299 & " parsing the project. Will recompile");
310 end Check_Source_Info_In_ALI;
312 --------------------------------
313 -- Create_Binder_Mapping_File --
314 --------------------------------
316 function Create_Binder_Mapping_File
317 (Project_Tree : Project_Tree_Ref) return Path_Name_Type
319 Mapping_Path : Path_Name_Type := No_Path;
321 Mapping_FD : File_Descriptor := Invalid_FD;
322 -- A File Descriptor for an eventual mapping file
324 ALI_Unit : Unit_Name_Type := No_Unit_Name;
325 -- The unit name of an ALI file
327 ALI_Name : File_Name_Type := No_File;
328 -- The file name of the ALI file
330 ALI_Project : Project_Id := No_Project;
331 -- The project of the ALI file
334 OK : Boolean := False;
341 Tempdir.Create_Temp_File (Mapping_FD, Mapping_Path);
342 Record_Temp_File (Project_Tree.Shared, Mapping_Path);
344 if Mapping_FD /= Invalid_FD then
347 -- Traverse all units
349 Unit := Units_Htable.Get_First (Project_Tree.Units_HT);
350 while Unit /= No_Unit_Index loop
351 if Unit.Name /= No_Name then
353 -- If there is a body, put it in the mapping
355 if Unit.File_Names (Impl) /= No_Source
356 and then Unit.File_Names (Impl).Project /= No_Project
358 Get_Name_String (Unit.Name);
359 Add_Str_To_Name_Buffer ("%b");
360 ALI_Unit := Name_Find;
362 Lib_File_Name (Unit.File_Names (Impl).Display_File);
363 ALI_Project := Unit.File_Names (Impl).Project;
365 -- Otherwise, if there is a spec, put it in the mapping
367 elsif Unit.File_Names (Spec) /= No_Source
368 and then Unit.File_Names (Spec).Project /= No_Project
370 Get_Name_String (Unit.Name);
371 Add_Str_To_Name_Buffer ("%s");
372 ALI_Unit := Name_Find;
374 Lib_File_Name (Unit.File_Names (Spec).Display_File);
375 ALI_Project := Unit.File_Names (Spec).Project;
381 -- If we have something to put in the mapping then do it now.
382 -- However, if the project is extended, we don't put anything
383 -- in the mapping file, since we don't know where the ALI file
384 -- is: it might be in the extended project object directory as
385 -- well as in the extending project object directory.
387 if ALI_Name /= No_File
388 and then ALI_Project.Extended_By = No_Project
389 and then ALI_Project.Extends = No_Project
391 -- First check if the ALI file exists. If it does not, do
392 -- not put the unit in the mapping file.
395 ALI : constant String := Get_Name_String (ALI_Name);
398 -- For library projects, use the library ALI directory,
399 -- for other projects, use the object directory.
401 if ALI_Project.Library then
403 (ALI_Project.Library_ALI_Dir.Display_Name);
406 (ALI_Project.Object_Directory.Display_Name);
409 Add_Str_To_Name_Buffer (ALI);
410 Add_Char_To_Name_Buffer (ASCII.LF);
413 ALI_Path_Name : constant String :=
414 Name_Buffer (1 .. Name_Len);
418 (ALI_Path_Name (1 .. ALI_Path_Name'Last - 1))
420 -- First line is the unit name
422 Get_Name_String (ALI_Unit);
423 Add_Char_To_Name_Buffer (ASCII.LF);
427 Name_Buffer (1)'Address,
429 OK := Bytes = Name_Len;
433 -- Second line it the ALI file name
435 Get_Name_String (ALI_Name);
436 Add_Char_To_Name_Buffer (ASCII.LF);
440 Name_Buffer (1)'Address,
442 OK := (Bytes = Name_Len);
446 -- Third line it the ALI path name
451 ALI_Path_Name (1)'Address,
452 ALI_Path_Name'Length);
453 OK := (Bytes = ALI_Path_Name'Length);
455 -- If OK is False, it means we were unable to
456 -- write a line. No point in continuing with the
466 Unit := Units_Htable.Get_Next (Project_Tree.Units_HT);
469 Close (Mapping_FD, Status);
474 -- If the creation of the mapping file was successful, we add the switch
475 -- to the arguments of gnatbind.
483 end Create_Binder_Mapping_File;
489 function Create_Name (Name : String) return File_Name_Type is
492 Add_Str_To_Name_Buffer (Name);
496 function Create_Name (Name : String) return Name_Id is
499 Add_Str_To_Name_Buffer (Name);
503 function Create_Name (Name : String) return Path_Name_Type is
506 Add_Str_To_Name_Buffer (Name);
510 ----------------------------
511 -- Executable_Prefix_Path --
512 ----------------------------
514 function Executable_Prefix_Path return String is
515 Exec_Name : constant String := Command_Name;
517 function Get_Install_Dir (S : String) return String;
518 -- S is the executable name preceded by the absolute or relative path,
519 -- e.g. "c:\usr\bin\gcc.exe". Returns the absolute directory where "bin"
520 -- lies (in the example "C:\usr"). If the executable is not in a "bin"
521 -- directory, return "".
523 ---------------------
524 -- Get_Install_Dir --
525 ---------------------
527 function Get_Install_Dir (S : String) return String is
529 Path_Last : Integer := 0;
532 for J in reverse Exec'Range loop
533 if Exec (J) = Directory_Separator then
539 if Path_Last >= Exec'First + 2 then
540 To_Lower (Exec (Path_Last - 2 .. Path_Last));
543 if Path_Last < Exec'First + 2
544 or else Exec (Path_Last - 2 .. Path_Last) /= "bin"
545 or else (Path_Last - 3 >= Exec'First
546 and then Exec (Path_Last - 3) /= Directory_Separator)
551 return Normalize_Pathname
552 (Exec (Exec'First .. Path_Last - 4),
553 Resolve_Links => Opt.Follow_Links_For_Dirs)
554 & Directory_Separator;
557 -- Beginning of Executable_Prefix_Path
560 -- For VMS, the path returned is always /gnu/
562 if Hostparm.OpenVMS then
566 -- First determine if a path prefix was placed in front of the
569 for J in reverse Exec_Name'Range loop
570 if Exec_Name (J) = Directory_Separator then
571 return Get_Install_Dir (Exec_Name);
575 -- If we get here, the user has typed the executable name with no
579 Path : String_Access := Locate_Exec_On_Path (Exec_Name);
585 Dir : constant String := Get_Install_Dir (Path.all);
592 end Executable_Prefix_Path;
598 procedure Fail_Program
599 (Project_Tree : Project_Tree_Ref;
601 Flush_Messages : Boolean := True)
604 if Flush_Messages then
605 if Total_Errors_Detected /= 0 or else Warnings_Detected /= 0 then
610 Finish_Program (Project_Tree, E_Fatal, S => S);
617 procedure Finish_Program
618 (Project_Tree : Project_Tree_Ref;
619 Exit_Code : Osint.Exit_Code_Type := Osint.E_Success;
623 if not Debug.Debug_Flag_N then
624 Delete_Temp_Config_Files (Project_Tree);
626 if Project_Tree /= null then
627 Delete_All_Temp_Files (Project_Tree.Shared);
632 if Exit_Code /= E_Success then
639 -- Output Namet statistics
643 Exit_Program (Exit_Code);
646 --------------------------
647 -- File_Not_A_Source_Of --
648 --------------------------
650 function File_Not_A_Source_Of
651 (Project_Tree : Project_Tree_Ref;
653 Sfile : File_Name_Type) return Boolean
655 Unit : constant Unit_Index :=
656 Units_Htable.Get (Project_Tree.Units_HT, Uname);
658 At_Least_One_File : Boolean := False;
661 if Unit /= No_Unit_Index then
662 for F in Unit.File_Names'Range loop
663 if Unit.File_Names (F) /= null then
664 At_Least_One_File := True;
665 if Unit.File_Names (F).File = Sfile then
671 if not At_Least_One_File then
673 -- The unit was probably created initially for a separate unit
674 -- (which are initially created as IMPL when both suffixes are the
675 -- same). Later on, Override_Kind changed the type of the file,
676 -- and the unit is no longer valid in fact.
681 Verbose_Msg (Uname, "sources do not include ", Name_Id (Sfile));
686 end File_Not_A_Source_Of;
688 ---------------------
689 -- Get_Directories --
690 ---------------------
692 procedure Get_Directories
693 (Project_Tree : Project_Tree_Ref;
694 For_Project : Project_Id;
695 Activity : Activity_Type;
696 Languages : Name_Ids)
699 procedure Recursive_Add
700 (Project : Project_Id;
701 Tree : Project_Tree_Ref;
702 Extended : in out Boolean);
703 -- Add all the source directories of a project to the path only if
704 -- this project has not been visited. Calls itself recursively for
705 -- projects being extended, and imported projects.
707 procedure Add_Dir (Value : Path_Name_Type);
708 -- Add directory Value in table Directories, if it is defined and not
715 procedure Add_Dir (Value : Path_Name_Type) is
716 Add_It : Boolean := True;
719 if Value /= No_Path then
720 for Index in 1 .. Directories.Last loop
721 if Directories.Table (Index) = Value then
728 Directories.Increment_Last;
729 Directories.Table (Directories.Last) := Value;
738 procedure Recursive_Add
739 (Project : Project_Id;
740 Tree : Project_Tree_Ref;
741 Extended : in out Boolean)
743 Current : String_List_Id;
744 Dir : String_Element;
745 OK : Boolean := False;
746 Lang_Proc : Language_Ptr := Project.Languages;
749 -- Add to path all directories of this project
751 if Activity = Compilation then
753 while Lang_Proc /= No_Language_Index loop
754 for J in Languages'Range loop
755 OK := Lang_Proc.Name = Languages (J);
756 exit Lang_Loop when OK;
759 Lang_Proc := Lang_Proc.Next;
763 Current := Project.Source_Dirs;
765 while Current /= Nil_String loop
766 Dir := Tree.Shared.String_Elements.Table (Current);
767 Add_Dir (Path_Name_Type (Dir.Value));
772 elsif Project.Library then
773 if Activity = SAL_Binding and then Extended then
774 Add_Dir (Project.Object_Directory.Display_Name);
777 Add_Dir (Project.Library_ALI_Dir.Display_Name);
781 Add_Dir (Project.Object_Directory.Display_Name);
784 if Project.Extends = No_Project then
789 procedure For_All_Projects is
790 new For_Every_Project_Imported (Boolean, Recursive_Add);
792 Extended : Boolean := True;
794 -- Start of processing for Get_Directories
798 For_All_Projects (For_Project, Project_Tree, Extended);
805 procedure Get_Switches
806 (Source : Prj.Source_Id;
808 Project_Tree : Project_Tree_Ref;
809 Value : out Variable_Value;
810 Is_Default : out Boolean)
814 (Source_File => Source.File,
815 Source_Lang => Source.Language.Name,
816 Source_Prj => Source.Project,
817 Pkg_Name => Pkg_Name,
818 Project_Tree => Project_Tree,
820 Is_Default => Is_Default);
827 procedure Get_Switches
828 (Source_File : File_Name_Type;
829 Source_Lang : Name_Id;
830 Source_Prj : Project_Id;
832 Project_Tree : Project_Tree_Ref;
833 Value : out Variable_Value;
834 Is_Default : out Boolean;
835 Test_Without_Suffix : Boolean := False;
836 Check_ALI_Suffix : Boolean := False)
838 Project : constant Project_Id :=
839 Ultimate_Extending_Project_Of (Source_Prj);
840 Pkg : constant Package_Id :=
843 In_Packages => Project.Decl.Packages,
844 Shared => Project_Tree.Shared);
850 if Source_File /= No_File then
851 Value := Prj.Util.Value_Of
852 (Name => Name_Id (Source_File),
853 Attribute_Or_Array_Name => Name_Switches,
855 Shared => Project_Tree.Shared,
856 Allow_Wildcards => True);
859 if Value = Nil_Variable_Value and then Test_Without_Suffix then
861 Get_Language_From_Name (Project, Get_Name_String (Source_Lang));
865 Naming : Lang_Naming_Data renames Lang.Config.Naming_Data;
866 SF_Name : constant String := Get_Name_String (Source_File);
867 Last : Positive := SF_Name'Length;
868 Name : String (1 .. Last + 3);
869 Spec_Suffix : String := Get_Name_String (Naming.Spec_Suffix);
870 Body_Suffix : String := Get_Name_String (Naming.Body_Suffix);
871 Truncated : Boolean := False;
874 Canonical_Case_File_Name (Spec_Suffix);
875 Canonical_Case_File_Name (Body_Suffix);
876 Name (1 .. Last) := SF_Name;
878 if Last > Body_Suffix'Length
880 Name (Last - Body_Suffix'Length + 1 .. Last) = Body_Suffix
883 Last := Last - Body_Suffix'Length;
887 and then Last > Spec_Suffix'Length
889 Name (Last - Spec_Suffix'Length + 1 .. Last) = Spec_Suffix
892 Last := Last - Spec_Suffix'Length;
897 Add_Str_To_Name_Buffer (Name (1 .. Last));
899 Value := Prj.Util.Value_Of
901 Attribute_Or_Array_Name => Name_Switches,
903 Shared => Project_Tree.Shared,
904 Allow_Wildcards => True);
907 if Value = Nil_Variable_Value and then Check_ALI_Suffix then
908 Last := SF_Name'Length;
909 while Name (Last) /= '.' loop
914 Add_Str_To_Name_Buffer (Name (1 .. Last));
915 Add_Str_To_Name_Buffer ("ali");
917 Value := Prj.Util.Value_Of
919 Attribute_Or_Array_Name => Name_Switches,
921 Shared => Project_Tree.Shared,
922 Allow_Wildcards => True);
928 if Value = Nil_Variable_Value then
932 (Name => Source_Lang,
933 Attribute_Or_Array_Name => Name_Switches,
935 Shared => Project_Tree.Shared,
936 Force_Lower_Case_Index => True);
939 if Value = Nil_Variable_Value then
942 (Name => All_Other_Names,
943 Attribute_Or_Array_Name => Name_Switches,
945 Shared => Project_Tree.Shared,
946 Force_Lower_Case_Index => True);
949 if Value = Nil_Variable_Value then
952 (Name => Source_Lang,
953 Attribute_Or_Array_Name => Name_Default_Switches,
955 Shared => Project_Tree.Shared);
963 procedure Inform (N : File_Name_Type; Msg : String) is
965 Inform (Name_Id (N), Msg);
968 procedure Inform (N : Name_Id := No_Name; Msg : String) is
970 Osint.Write_Program_Name;
978 Name : constant String := Get_Name_String (N);
980 if Debug.Debug_Flag_F and then Is_Absolute_Path (Name) then
981 Write_Str (File_Name (Name));
994 ------------------------------
995 -- Initialize_Source_Record --
996 ------------------------------
998 procedure Initialize_Source_Record (Source : Prj.Source_Id) is
1000 procedure Set_Object_Project
1002 Obj_Proj : Project_Id;
1003 Obj_Path : Path_Name_Type;
1004 Stamp : Time_Stamp_Type);
1005 -- Update information about object file, switches file,...
1007 ------------------------
1008 -- Set_Object_Project --
1009 ------------------------
1011 procedure Set_Object_Project
1013 Obj_Proj : Project_Id;
1014 Obj_Path : Path_Name_Type;
1015 Stamp : Time_Stamp_Type) is
1017 Source.Object_Project := Obj_Proj;
1018 Source.Object_Path := Obj_Path;
1019 Source.Object_TS := Stamp;
1021 if Source.Language.Config.Dependency_Kind /= None then
1023 Dep_Path : constant String :=
1026 Get_Name_String (Source.Dep_Name),
1027 Resolve_Links => Opt.Follow_Links_For_Files,
1028 Directory => Obj_Dir);
1030 Source.Dep_Path := Create_Name (Dep_Path);
1031 Source.Dep_TS := Osint.Unknown_Attributes;
1035 -- Get the path of the switches file, even if Opt.Check_Switches is
1036 -- not set, as switch -s may be in the Builder switches that have not
1037 -- been scanned yet.
1040 Switches_Path : constant String :=
1043 Get_Name_String (Source.Switches),
1044 Resolve_Links => Opt.Follow_Links_For_Files,
1045 Directory => Obj_Dir);
1047 Source.Switches_Path := Create_Name (Switches_Path);
1049 if Stamp /= Empty_Time_Stamp then
1050 Source.Switches_TS := File_Stamp (Source.Switches_Path);
1053 end Set_Object_Project;
1055 Obj_Proj : Project_Id;
1058 -- Nothing to do if source record has already been fully initialized
1060 if Source.Initialized then
1064 -- Systematically recompute the time stamp
1066 Source.Source_TS := File_Stamp (Source.Path.Display_Name);
1068 -- Parse the source file to check whether we have a subunit
1070 if Source.Language.Config.Kind = Unit_Based
1071 and then Source.Kind = Impl
1072 and then Is_Subunit (Source)
1077 if Source.Language.Config.Object_Generated
1078 and then Is_Compilable (Source)
1080 -- First, get the correct object file name and dependency file name
1081 -- if the source is in a multi-unit file.
1083 if Source.Index /= 0 then
1086 (Source_File_Name => Source.File,
1087 Source_Index => Source.Index,
1089 Source.Language.Config.Multi_Unit_Object_Separator,
1090 Object_File_Suffix =>
1091 Source.Language.Config.Object_File_Suffix);
1095 (Source.Object, Source.Language.Config.Dependency_Kind);
1098 -- Find the object file for that source. It could be either in the
1099 -- current project or in an extended project (it might actually not
1100 -- exist yet in the ultimate extending project, but if not found
1101 -- elsewhere that's where we'll expect to find it).
1103 Obj_Proj := Source.Project;
1105 while Obj_Proj /= No_Project loop
1107 Dir : constant String :=
1109 (Obj_Proj.Object_Directory.Display_Name);
1111 Object_Path : constant String :=
1114 Get_Name_String (Source.Object),
1115 Resolve_Links => Opt.Follow_Links_For_Files,
1118 Obj_Path : constant Path_Name_Type := Create_Name (Object_Path);
1119 Stamp : Time_Stamp_Type := Empty_Time_Stamp;
1122 -- For specs, we do not check object files if there is a body.
1123 -- This saves a system call. On the other hand, we do need to
1124 -- know the object_path, in case the user has passed the .ads
1125 -- on the command line to compile the spec only.
1127 if Source.Kind /= Spec
1128 or else Source.Unit = No_Unit_Index
1129 or else Source.Unit.File_Names (Impl) = No_Source
1131 Stamp := File_Stamp (Obj_Path);
1134 if Stamp /= Empty_Time_Stamp
1135 or else (Obj_Proj.Extended_By = No_Project
1136 and then Source.Object_Project = No_Project)
1138 Set_Object_Project (Dir, Obj_Proj, Obj_Path, Stamp);
1141 Obj_Proj := Obj_Proj.Extended_By;
1145 elsif Source.Language.Config.Dependency_Kind = Makefile then
1147 Object_Dir : constant String :=
1149 (Source.Project.Object_Directory.Display_Name);
1150 Dep_Path : constant String :=
1152 (Name => Get_Name_String (Source.Dep_Name),
1154 Opt.Follow_Links_For_Files,
1155 Directory => Object_Dir);
1157 Source.Dep_Path := Create_Name (Dep_Path);
1158 Source.Dep_TS := Osint.Unknown_Attributes;
1162 Source.Initialized := True;
1163 end Initialize_Source_Record;
1165 ----------------------------
1166 -- Is_External_Assignment --
1167 ----------------------------
1169 function Is_External_Assignment
1170 (Env : Prj.Tree.Environment;
1171 Argv : String) return Boolean
1173 Start : Positive := 3;
1174 Finish : Natural := Argv'Last;
1176 pragma Assert (Argv'First = 1);
1177 pragma Assert (Argv (1 .. 2) = "-X");
1180 if Argv'Last < 5 then
1183 elsif Argv (3) = '"' then
1184 if Argv (Argv'Last) /= '"' or else Argv'Last < 7 then
1188 Finish := Argv'Last - 1;
1192 return Prj.Ext.Check
1193 (Self => Env.External,
1194 Declaration => Argv (Start .. Finish));
1195 end Is_External_Assignment;
1201 function Is_Subunit (Source : Prj.Source_Id) return Boolean is
1202 Src_Ind : Source_File_Index;
1205 if Source.Kind = Sep then
1208 -- A Spec, a file based language source or a body with a spec cannot be
1211 elsif Source.Kind = Spec
1212 or else Source.Unit = No_Unit_Index
1213 or else Other_Part (Source) /= No_Source
1218 -- Here, we are assuming that the language is Ada, as it is the only
1219 -- unit based language that we know.
1222 Sinput.P.Load_Project_File
1223 (Get_Name_String (Source.Path.Display_Name));
1225 return Sinput.P.Source_File_Is_Subunit (Src_Ind);
1228 -----------------------------
1229 -- Linker_Options_Switches --
1230 -----------------------------
1232 function Linker_Options_Switches
1233 (Project : Project_Id;
1234 Do_Fail : Fail_Proc;
1235 In_Tree : Project_Tree_Ref) return String_List
1237 procedure Recursive_Add
1239 In_Tree : Project_Tree_Ref;
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 Dummy : in out Boolean)
1252 pragma Unreferenced (Dummy);
1254 Linker_Package : Package_Id;
1255 Options : Variable_Value;
1260 (Name => Name_Linker,
1261 In_Packages => Proj.Decl.Packages,
1262 Shared => In_Tree.Shared);
1268 Attribute_Or_Array_Name => Name_Linker_Options,
1269 In_Package => Linker_Package,
1270 Shared => In_Tree.Shared);
1272 -- If attribute is present, add the project with the attribute to
1273 -- table Linker_Opts.
1275 if Options /= Nil_Variable_Value then
1276 Linker_Opts.Increment_Last;
1277 Linker_Opts.Table (Linker_Opts.Last) :=
1278 (Project => Proj, Options => Options.Values);
1282 procedure For_All_Projects is
1283 new For_Every_Project_Imported (Boolean, Recursive_Add);
1285 Dummy : Boolean := False;
1287 -- Start of processing for Linker_Options_Switches
1292 For_All_Projects (Project, In_Tree, Dummy, Imported_First => True);
1294 Last_Linker_Option := 0;
1296 for Index in reverse 1 .. Linker_Opts.Last loop
1298 Options : String_List_Id;
1299 Proj : constant Project_Id :=
1300 Linker_Opts.Table (Index).Project;
1302 Dir_Path : constant String :=
1303 Get_Name_String (Proj.Directory.Name);
1306 Options := Linker_Opts.Table (Index).Options;
1307 while Options /= Nil_String loop
1308 Option := In_Tree.Shared.String_Elements.Table (Options).Value;
1309 Get_Name_String (Option);
1311 -- Do not consider empty linker options
1313 if Name_Len /= 0 then
1314 Add_Linker_Option (Name_Buffer (1 .. Name_Len));
1316 -- Object files and -L switches specified with relative
1317 -- paths must be converted to absolute paths.
1319 Test_If_Relative_Path
1320 (Switch => Linker_Options_Buffer (Last_Linker_Option),
1323 Including_L_Switch => True);
1326 Options := In_Tree.Shared.String_Elements.Table (Options).Next;
1331 return Linker_Options_Buffer (1 .. Last_Linker_Option);
1332 end Linker_Options_Switches;
1338 package body Mains is
1340 package Names is new Table.Table
1341 (Table_Component_Type => Main_Info,
1342 Table_Index_Type => Integer,
1343 Table_Low_Bound => 1,
1344 Table_Initial => 10,
1345 Table_Increment => 100,
1346 Table_Name => "Makeutl.Mains.Names");
1347 -- The table that stores the mains
1349 Current : Natural := 0;
1350 -- The index of the last main retrieved from the table
1352 Count_Of_Mains_With_No_Tree : Natural := 0;
1353 -- Number of main units for which we do not know the project tree
1362 Location : Source_Ptr := No_Location;
1363 Project : Project_Id := No_Project;
1364 Tree : Project_Tree_Ref := null)
1367 if Current_Verbosity = High then
1368 Debug_Output ("Add_Main """ & Name & """ " & Index'Img
1370 & Boolean'Image (Tree /= null));
1374 Add_Str_To_Name_Buffer (Name);
1375 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1377 Names.Increment_Last;
1378 Names.Table (Names.Last) :=
1379 (Name_Find, Index, Location, No_Source, Project, Tree);
1381 if Tree /= null then
1382 Builder_Data (Tree).Number_Of_Mains :=
1383 Builder_Data (Tree).Number_Of_Mains + 1;
1386 Mains.Count_Of_Mains_With_No_Tree :=
1387 Mains.Count_Of_Mains_With_No_Tree + 1;
1391 --------------------
1392 -- Complete_Mains --
1393 --------------------
1395 procedure Complete_Mains
1396 (Flags : Processing_Flags;
1397 Root_Project : Project_Id;
1398 Project_Tree : Project_Tree_Ref)
1400 procedure Do_Complete (Project : Project_Id; Tree : Project_Tree_Ref);
1401 -- Check the mains for this specific project
1403 procedure Complete_All is new For_Project_And_Aggregated
1406 procedure Add_Multi_Unit_Sources
1407 (Tree : Project_Tree_Ref;
1408 Source : Prj.Source_Id);
1409 -- Add all units from the same file as the multi-unit Source
1411 function Find_File_Add_Extension
1412 (Tree : Project_Tree_Ref;
1413 Base_Main : String) return Prj.Source_Id;
1414 -- Search for Main in the project, adding body or spec extensions
1416 ----------------------------
1417 -- Add_Multi_Unit_Sources --
1418 ----------------------------
1420 procedure Add_Multi_Unit_Sources
1421 (Tree : Project_Tree_Ref;
1422 Source : Prj.Source_Id)
1424 Iter : Source_Iterator;
1425 Src : Prj.Source_Id;
1429 ("found multi-unit source file in project", Source.Project.Name);
1431 Iter := For_Each_Source
1432 (In_Tree => Tree, Project => Source.Project);
1434 while Element (Iter) /= No_Source loop
1435 Src := Element (Iter);
1437 if Src.File = Source.File
1438 and then Src.Index /= Source.Index
1440 if Src.File = Source.File then
1442 ("add main in project, index=" & Src.Index'Img);
1445 Names.Increment_Last;
1446 Names.Table (Names.Last) :=
1449 Location => No_Location,
1451 Project => Src.Project,
1454 Builder_Data (Tree).Number_Of_Mains :=
1455 Builder_Data (Tree).Number_Of_Mains + 1;
1460 end Add_Multi_Unit_Sources;
1462 -----------------------------
1463 -- Find_File_Add_Extension --
1464 -----------------------------
1466 function Find_File_Add_Extension
1467 (Tree : Project_Tree_Ref;
1468 Base_Main : String) return Prj.Source_Id
1470 Spec_Source : Prj.Source_Id := No_Source;
1471 Source : Prj.Source_Id;
1472 Iter : Source_Iterator;
1473 Suffix : File_Name_Type;
1476 Source := No_Source;
1477 Iter := For_Each_Source (Tree); -- In all projects
1479 Source := Prj.Element (Iter);
1480 exit when Source = No_Source;
1482 if Source.Kind = Impl then
1483 Get_Name_String (Source.File);
1485 if Name_Len > Base_Main'Length
1486 and then Name_Buffer (1 .. Base_Main'Length) = Base_Main
1489 Source.Language.Config.Naming_Data.Body_Suffix;
1491 if Suffix /= No_File then
1493 Suffix_Str : String := Get_Name_String (Suffix);
1495 Canonical_Case_File_Name (Suffix_Str);
1497 Name_Buffer (Base_Main'Length + 1 .. Name_Len) =
1503 elsif Source.Kind = Spec then
1504 -- A spec needs to be taken into account unless there is
1505 -- also a body. So we delay the decision for them.
1507 Get_Name_String (Source.File);
1509 if Name_Len > Base_Main'Length
1510 and then Name_Buffer (1 .. Base_Main'Length) = Base_Main
1512 Suffix := Source.Language.Config.Naming_Data.Spec_Suffix;
1514 if Suffix /= No_File then
1516 Suffix_Str : String := Get_Name_String (Suffix);
1519 Canonical_Case_File_Name (Suffix_Str);
1521 if Name_Buffer (Base_Main'Length + 1 .. Name_Len) =
1524 Spec_Source := Source;
1534 if Source = No_Source then
1535 Source := Spec_Source;
1539 end Find_File_Add_Extension;
1545 procedure Do_Complete
1546 (Project : Project_Id; Tree : Project_Tree_Ref)
1551 if Mains.Number_Of_Mains (Tree) > 0
1552 or else Mains.Count_Of_Mains_With_No_Tree > 0
1554 -- Traverse in reverse order, since in the case of multi-unit
1555 -- files we will be adding extra files at the end, and there's
1556 -- no need to process them in turn.
1561 File : Main_Info := Names.Table (J);
1562 Main_Id : File_Name_Type := File.File;
1563 Main : constant String :=
1564 Get_Name_String (Main_Id);
1565 Base : constant String := Base_Name (Main);
1566 Source : Prj.Source_Id := No_Source;
1567 Is_Absolute : Boolean := False;
1570 if Base /= Main then
1571 Is_Absolute := True;
1573 if Is_Absolute_Path (Main) then
1574 Main_Id := Create_Name (Base);
1576 -- Not an absolute path
1579 -- Always resolve links here, so that users can be
1580 -- specify any name on the command line. If the
1581 -- project itself uses links, the user will be
1582 -- using -eL anyway, and thus files are also stored
1583 -- with resolved names.
1586 Absolute : constant String :=
1590 Resolve_Links => True,
1591 Case_Sensitive => False);
1593 File.File := Create_Name (Absolute);
1594 Main_Id := Create_Name (Base);
1599 -- If no project or tree was specified for the main, it
1600 -- came from the command line.
1601 -- Note that the assignments below will not modify inside
1602 -- the table itself.
1604 if File.Project = null then
1605 File.Project := Project;
1608 if File.Tree = null then
1612 if File.Source = null then
1613 if Current_Verbosity = High then
1615 ("search for main """ & Main
1616 & '"' & File.Index'Img & " in "
1617 & Get_Name_String (Debug_Name (File.Tree))
1618 & ", project", Project.Name);
1621 -- First, look for the main as specified. We need to
1622 -- search for the base name though, and if needed
1623 -- check later that we found the correct file.
1625 Source := Find_Source
1626 (In_Tree => File.Tree,
1627 Project => File.Project,
1628 Base_Name => Main_Id,
1629 Index => File.Index,
1630 In_Imported_Only => True);
1632 if Source = No_Source then
1633 Source := Find_File_Add_Extension
1634 (Tree, Get_Name_String (Main_Id));
1638 and then Source /= No_Source
1640 File_Name_Type (Source.Path.Name) /= File.File
1643 ("Found a non-matching file",
1644 Name_Id (Source.Path.Display_Name));
1645 Source := No_Source;
1648 if Source /= No_Source then
1649 if not Is_Allowed_Language
1650 (Source.Language.Name)
1652 -- Remove any main that is not in the list of
1653 -- restricted languages.
1655 Names.Table (J .. Names.Last - 1) :=
1656 Names.Table (J + 1 .. Names.Last);
1657 Names.Set_Last (Names.Last - 1);
1660 -- If we have found a multi-unit source file but
1661 -- did not specify an index initially, we'll
1662 -- need to compile all the units from the same
1665 if Source.Index /= 0 and then File.Index = 0 then
1666 Add_Multi_Unit_Sources (File.Tree, Source);
1669 -- Now update the original Main, otherwise it
1670 -- will be reported as not found.
1673 ("found main in project", Source.Project.Name);
1674 Names.Table (J).File := Source.File;
1675 Names.Table (J).Project := Source.Project;
1677 if Names.Table (J).Tree = null then
1678 Names.Table (J).Tree := File.Tree;
1680 Builder_Data (File.Tree).Number_Of_Mains :=
1681 Builder_Data (File.Tree).Number_Of_Mains
1683 Mains.Count_Of_Mains_With_No_Tree :=
1684 Mains.Count_Of_Mains_With_No_Tree - 1;
1687 Names.Table (J).Source := Source;
1688 Names.Table (J).Index := Source.Index;
1691 elsif File.Location /= No_Location then
1693 -- If the main is declared in package Builder of
1694 -- the main project, report an error. If the main
1695 -- is on the command line, it may be a main from
1696 -- another project, so do nothing: if the main does
1697 -- not exist in another project, an error will be
1700 Error_Msg_File_1 := Main_Id;
1701 Error_Msg_Name_1 := Root_Project.Name;
1703 (Flags, "{ is not a source of project %%",
1704 File.Location, Project);
1710 exit when J < Names.First;
1714 if Total_Errors_Detected > 0 then
1715 Fail_Program (Tree, "problems with main sources");
1719 -- Start of processing for Complete_Mains
1722 Complete_All (Root_Project, Project_Tree);
1724 if Mains.Count_Of_Mains_With_No_Tree > 0 then
1725 for J in Names.First .. Names.Last loop
1726 if Names.Table (J).Source = No_Source then
1728 (Project_Tree, '"' & Get_Name_String (Names.Table (J).File)
1729 & """ is not a source of any project");
1745 -----------------------
1746 -- Fill_From_Project --
1747 -----------------------
1749 procedure Fill_From_Project
1750 (Root_Project : Project_Id;
1751 Project_Tree : Project_Tree_Ref)
1753 procedure Add_Mains_From_Project
1754 (Project : Project_Id;
1755 Tree : Project_Tree_Ref);
1756 -- Add the main units from this project into Mains.
1757 -- This takes into account the aggregated projects
1759 ----------------------------
1760 -- Add_Mains_From_Project --
1761 ----------------------------
1763 procedure Add_Mains_From_Project
1764 (Project : Project_Id;
1765 Tree : Project_Tree_Ref)
1767 List : String_List_Id;
1768 Element : String_Element;
1771 if Number_Of_Mains (Tree) = 0
1772 and then Mains.Count_Of_Mains_With_No_Tree = 0
1774 Debug_Output ("Add_Mains_From_Project", Project.Name);
1775 List := Project.Mains;
1777 if List /= Prj.Nil_String then
1779 -- The attribute Main is not an empty list. Get the mains in
1782 while List /= Prj.Nil_String loop
1783 Element := Tree.Shared.String_Elements.Table (List);
1784 Debug_Output ("Add_Main", Element.Value);
1786 if Project.Library then
1789 "cannot specify a main program " &
1790 "for a library project file");
1793 Add_Main (Name => Get_Name_String (Element.Value),
1794 Index => Element.Index,
1795 Location => Element.Location,
1798 List := Element.Next;
1803 if Total_Errors_Detected > 0 then
1804 Fail_Program (Tree, "problems with main sources");
1806 end Add_Mains_From_Project;
1808 procedure Fill_All is new For_Project_And_Aggregated
1809 (Add_Mains_From_Project);
1811 -- Start of processing for Fill_From_Project
1814 Fill_All (Root_Project, Project_Tree);
1815 end Fill_From_Project;
1821 function Next_Main return String is
1822 Info : constant Main_Info := Next_Main;
1824 if Info = No_Main_Info then
1827 return Get_Name_String (Info.File);
1831 function Next_Main return Main_Info is
1833 if Current >= Names.Last then
1834 return No_Main_Info;
1836 Current := Current + 1;
1838 -- If not using projects, and in the gnatmake case, the main file
1839 -- may have not have the extension. Try ".adb" first then ".ads"
1841 if Names.Table (Current).Project = No_Project then
1843 Orig_Main : constant File_Name_Type :=
1844 Names.Table (Current).File;
1845 Current_Main : File_Name_Type;
1848 if Strip_Suffix (Orig_Main) = Orig_Main then
1849 Get_Name_String (Orig_Main);
1850 Add_Str_To_Name_Buffer (".adb");
1851 Current_Main := Name_Find;
1853 if Full_Source_Name (Current_Main) = No_File then
1854 Get_Name_String (Orig_Main);
1855 Add_Str_To_Name_Buffer (".ads");
1856 Current_Main := Name_Find;
1858 if Full_Source_Name (Current_Main) /= No_File then
1859 Names.Table (Current).File := Current_Main;
1863 Names.Table (Current).File := Current_Main;
1869 return Names.Table (Current);
1873 ---------------------
1874 -- Number_Of_Mains --
1875 ---------------------
1877 function Number_Of_Mains (Tree : Project_Tree_Ref) return Natural is
1882 return Builder_Data (Tree).Number_Of_Mains;
1884 end Number_Of_Mains;
1895 --------------------------
1896 -- Set_Multi_Unit_Index --
1897 --------------------------
1899 procedure Set_Multi_Unit_Index
1900 (Project_Tree : Project_Tree_Ref := null;
1905 if Names.Last = 0 then
1908 "cannot specify a multi-unit index but no main " &
1909 "on the command line");
1911 elsif Names.Last > 1 then
1914 "cannot specify several mains with a multi-unit index");
1917 Names.Table (Names.Last).Index := Index;
1920 end Set_Multi_Unit_Index;
1924 -----------------------
1925 -- Path_Or_File_Name --
1926 -----------------------
1928 function Path_Or_File_Name (Path : Path_Name_Type) return String is
1929 Path_Name : constant String := Get_Name_String (Path);
1931 if Debug.Debug_Flag_F then
1932 return File_Name (Path_Name);
1936 end Path_Or_File_Name;
1938 ---------------------------
1939 -- Test_If_Relative_Path --
1940 ---------------------------
1942 procedure Test_If_Relative_Path
1943 (Switch : in out String_Access;
1945 Do_Fail : Fail_Proc;
1946 Including_L_Switch : Boolean := True;
1947 Including_Non_Switch : Boolean := True;
1948 Including_RTS : Boolean := False)
1951 if Switch /= null then
1953 Sw : String (1 .. Switch'Length);
1959 if Sw (1) = '-' then
1961 and then (Sw (2) = 'A'
1962 or else Sw (2) = 'I'
1963 or else (Including_L_Switch and then Sw (2) = 'L'))
1971 elsif Sw'Length >= 4
1972 and then (Sw (2 .. 3) = "aL"
1981 and then Sw'Length >= 7
1982 and then Sw (2 .. 6) = "-RTS="
1990 -- Because relative path arguments to --RTS= may be relative to
1991 -- the search directory prefix, those relative path arguments
1992 -- are converted only when they include directory information.
1994 if not Is_Absolute_Path (Sw (Start .. Sw'Last)) then
1995 if Parent'Length = 0 then
1997 ("relative search path switches ("""
1999 & """) are not allowed");
2001 elsif Including_RTS then
2002 for J in Start .. Sw'Last loop
2003 if Sw (J) = Directory_Separator then
2006 (Sw (1 .. Start - 1) &
2008 Directory_Separator &
2009 Sw (Start .. Sw'Last));
2017 (Sw (1 .. Start - 1) &
2019 Directory_Separator &
2020 Sw (Start .. Sw'Last));
2024 elsif Including_Non_Switch then
2025 if not Is_Absolute_Path (Sw) then
2026 if Parent'Length = 0 then
2028 ("relative paths (""" & Sw & """) are not allowed");
2030 Switch := new String'(Parent & Directory_Separator & Sw);
2036 end Test_If_Relative_Path;
2042 function Unit_Index_Of (ALI_File : File_Name_Type) return Int is
2048 Get_Name_String (ALI_File);
2050 -- First, find the last dot
2054 while Finish >= 1 and then Name_Buffer (Finish) /= '.' loop
2055 Finish := Finish - 1;
2062 -- Now check that the dot is preceded by digits
2065 Finish := Finish - 1;
2066 while Start >= 1 and then Name_Buffer (Start - 1) in '0' .. '9' loop
2070 -- If there are no digits, or if the digits are not preceded by the
2071 -- character that precedes a unit index, this is not the ALI file of
2072 -- a unit in a multi-unit source.
2076 or else Name_Buffer (Start - 1) /= Multi_Unit_Index_Character
2081 -- Build the index from the digit(s)
2083 while Start <= Finish loop
2084 Result := Result * 10 +
2085 Character'Pos (Name_Buffer (Start)) - Character'Pos ('0');
2096 procedure Verbose_Msg
2099 N2 : Name_Id := No_Name;
2101 Prefix : String := " -> ";
2102 Minimum_Verbosity : Opt.Verbosity_Level_Type := Opt.Low)
2105 if not Opt.Verbose_Mode
2106 or else Minimum_Verbosity > Opt.Verbosity_Level
2117 if N2 /= No_Name then
2127 procedure Verbose_Msg
2128 (N1 : File_Name_Type;
2130 N2 : File_Name_Type := No_File;
2132 Prefix : String := " -> ";
2133 Minimum_Verbosity : Opt.Verbosity_Level_Type := Opt.Low)
2137 (Name_Id (N1), S1, Name_Id (N2), S2, Prefix, Minimum_Verbosity);
2144 package body Queue is
2146 type Q_Record is record
2148 Processed : Boolean;
2151 package Q is new Table.Table
2152 (Table_Component_Type => Q_Record,
2153 Table_Index_Type => Natural,
2154 Table_Low_Bound => 1,
2155 Table_Initial => 1000,
2156 Table_Increment => 100,
2157 Table_Name => "Makeutl.Queue.Q");
2158 -- This is the actual Queue
2160 package Busy_Obj_Dirs is new GNAT.HTable.Simple_HTable
2161 (Header_Num => Prj.Header_Num,
2163 No_Element => False,
2164 Key => Path_Name_Type,
2168 type Mark_Key is record
2169 File : File_Name_Type;
2172 -- Identify either a mono-unit source (when Index = 0) or a specific
2173 -- unit (index = 1's origin index of unit) in a multi-unit source.
2175 Max_Mask_Num : constant := 2048;
2176 subtype Mark_Num is Union_Id range 0 .. Max_Mask_Num - 1;
2178 function Hash (Key : Mark_Key) return Mark_Num;
2180 package Marks is new GNAT.HTable.Simple_HTable
2181 (Header_Num => Mark_Num,
2183 No_Element => False,
2187 -- A hash table to keep tracks of the marked units.
2188 -- These are the units that have already been processed, when using the
2189 -- gnatmake format. When using the gprbuild format, we can directly
2190 -- store in the source_id whether the file has already been processed.
2192 procedure Mark (Source_File : File_Name_Type; Index : Int := 0);
2193 -- Mark a unit, identified by its source file and, when Index is not 0,
2194 -- the index of the unit in the source file. Marking is used to signal
2195 -- that the unit has already been inserted in the Q.
2198 (Source_File : File_Name_Type;
2199 Index : Int := 0) return Boolean;
2200 -- Returns True if the unit was previously marked
2202 Q_Processed : Natural := 0;
2203 Q_Initialized : Boolean := False;
2205 Q_First : Natural := 1;
2206 -- Points to the first valid element in the queue
2208 One_Queue_Per_Obj_Dir : Boolean := False;
2209 -- See parameter to Initialize
2211 function Available_Obj_Dir (S : Source_Info) return Boolean;
2212 -- Whether the object directory for S is available for a build
2214 procedure Debug_Display (S : Source_Info);
2215 -- A debug display for S
2217 function Was_Processed (S : Source_Info) return Boolean;
2218 -- Whether S has already been processed. This marks the source as
2219 -- processed, if it hasn't already been processed.
2221 function Insert_No_Roots (Source : Source_Info) return Boolean;
2222 -- Insert Source, but do not look for its roots (see doc for Insert)
2228 function Was_Processed (S : Source_Info) return Boolean is
2231 when Format_Gprbuild =>
2232 if S.Id.In_The_Queue then
2236 S.Id.In_The_Queue := True;
2238 when Format_Gnatmake =>
2239 if Is_Marked (S.File, S.Index) then
2243 Mark (S.File, Index => S.Index);
2249 -----------------------
2250 -- Available_Obj_Dir --
2251 -----------------------
2253 function Available_Obj_Dir (S : Source_Info) return Boolean is
2256 when Format_Gprbuild =>
2257 return not Busy_Obj_Dirs.Get
2258 (S.Id.Project.Object_Directory.Name);
2260 when Format_Gnatmake =>
2261 return S.Project = No_Project
2263 not Busy_Obj_Dirs.Get (S.Project.Object_Directory.Name);
2265 end Available_Obj_Dir;
2271 procedure Debug_Display (S : Source_Info) is
2274 when Format_Gprbuild =>
2275 Write_Name (S.Id.File);
2277 if S.Id.Index /= 0 then
2279 Write_Int (S.Id.Index);
2282 when Format_Gnatmake =>
2283 Write_Name (S.File);
2285 if S.Index /= 0 then
2287 Write_Int (S.Index);
2296 function Hash (Key : Mark_Key) return Mark_Num is
2298 return Union_Id (Key.File) mod Max_Mask_Num;
2306 (Source_File : File_Name_Type;
2307 Index : Int := 0) return Boolean
2310 return Marks.Get (K => (File => Source_File, Index => Index));
2317 procedure Mark (Source_File : File_Name_Type; Index : Int := 0) is
2319 Marks.Set (K => (File => Source_File, Index => Index), E => True);
2327 (Found : out Boolean;
2328 Source : out Source_Info)
2333 if One_Queue_Per_Obj_Dir then
2334 for J in Q_First .. Q.Last loop
2335 if not Q.Table (J).Processed
2336 and then Available_Obj_Dir (Q.Table (J).Info)
2339 Source := Q.Table (J).Info;
2340 Q.Table (J).Processed := True;
2343 while Q_First <= Q.Last
2344 and then Q.Table (Q_First).Processed
2346 Q_First := Q_First + 1;
2354 elsif Q_First <= Q.Last then
2355 Source := Q.Table (Q_First).Info;
2356 Q.Table (Q_First).Processed := True;
2357 Q_First := Q_First + 1;
2362 Q_Processed := Q_Processed + 1;
2365 if Found and then Debug.Debug_Flag_Q then
2366 Write_Str (" Q := Q - [ ");
2367 Debug_Display (Source);
2371 Write_Str (" Q_First =");
2372 Write_Int (Int (Q_First));
2375 Write_Str (" Q.Last =");
2376 Write_Int (Int (Q.Last));
2385 function Processed return Natural is
2394 procedure Initialize
2395 (Queue_Per_Obj_Dir : Boolean;
2396 Force : Boolean := False)
2399 if Force or else not Q_Initialized then
2400 Q_Initialized := True;
2402 for J in 1 .. Q.Last loop
2403 case Q.Table (J).Info.Format is
2404 when Format_Gprbuild =>
2405 Q.Table (J).Info.Id.In_The_Queue := False;
2406 when Format_Gnatmake =>
2414 One_Queue_Per_Obj_Dir := Queue_Per_Obj_Dir;
2418 ---------------------
2419 -- Insert_No_Roots --
2420 ---------------------
2422 function Insert_No_Roots (Source : Source_Info) return Boolean is
2425 (Source.Format = Format_Gnatmake or else Source.Id /= No_Source);
2427 -- Only insert in the Q if it is not already done, to avoid
2428 -- simultaneous compilations if -jnnn is used.
2430 if Was_Processed (Source) then
2434 if Current_Verbosity = High then
2435 Write_Str ("Adding """);
2436 Debug_Display (Source);
2437 Write_Line (""" to the queue");
2440 Q.Append (New_Val => (Info => Source, Processed => False));
2442 if Debug.Debug_Flag_Q then
2443 Write_Str (" Q := Q + [ ");
2444 Debug_Display (Source);
2448 Write_Str (" Q_First =");
2449 Write_Int (Int (Q_First));
2452 Write_Str (" Q.Last =");
2453 Write_Int (Int (Q.Last));
2458 end Insert_No_Roots;
2465 (Source : Source_Info;
2466 With_Roots : Boolean := False) return Boolean
2468 Root_Arr : Array_Element_Id;
2469 Roots : Variable_Value;
2470 List : String_List_Id;
2471 Elem : String_Element;
2472 Unit_Name : Name_Id;
2474 Root_Pattern : Regexp;
2475 Root_Found : Boolean;
2476 Roots_Found : Boolean;
2477 Root_Source : Prj.Source_Id;
2478 Iter : Source_Iterator;
2481 pragma Unreferenced (Dummy);
2484 if not Insert_No_Roots (Source) then
2486 -- Was already in the queue
2491 if With_Roots and then Source.Format = Format_Gprbuild then
2492 Debug_Output ("looking for roots of", Name_Id (Source.Id.File));
2496 (Name => Name_Roots,
2497 In_Arrays => Source.Id.Project.Decl.Arrays,
2498 Shared => Source.Tree.Shared);
2502 (Index => Name_Id (Source.Id.File),
2504 In_Array => Root_Arr,
2505 Shared => Source.Tree.Shared);
2507 -- If there is no roots for the specific main, try the language
2509 if Roots = Nil_Variable_Value then
2512 (Index => Source.Id.Language.Name,
2514 In_Array => Root_Arr,
2515 Shared => Source.Tree.Shared,
2516 Force_Lower_Case_Index => True);
2521 if Roots = Nil_Variable_Value then
2523 Name_Buffer (1) := '*';
2527 (Index => Name_Find,
2529 In_Array => Root_Arr,
2530 Shared => Source.Tree.Shared,
2531 Force_Lower_Case_Index => True);
2534 if Roots = Nil_Variable_Value then
2535 Debug_Output (" -> no roots declared");
2538 List := Roots.Values;
2541 while List /= Nil_String loop
2542 Elem := Source.Tree.Shared.String_Elements.Table (List);
2543 Get_Name_String (Elem.Value);
2544 To_Lower (Name_Buffer (1 .. Name_Len));
2545 Unit_Name := Name_Find;
2547 -- Check if it is a unit name or a pattern
2551 for J in 1 .. Name_Len loop
2552 if Name_Buffer (J) not in 'a' .. 'z' and then
2553 Name_Buffer (J) not in '0' .. '9' and then
2554 Name_Buffer (J) /= '_' and then
2555 Name_Buffer (J) /= '.'
2566 (Pattern => Name_Buffer (1 .. Name_Len),
2570 when Error_In_Regexp =>
2571 Err_Vars.Error_Msg_Name_1 := Unit_Name;
2573 ("invalid pattern %", Roots.Location);
2578 Roots_Found := False;
2579 Iter := For_Each_Source (Source.Tree);
2583 Root_Source := Prj.Element (Iter);
2584 exit Source_Loop when Root_Source = No_Source;
2586 Root_Found := False;
2588 Root_Found := Root_Source.Unit /= No_Unit_Index
2590 (Get_Name_String (Root_Source.Unit.Name),
2595 Root_Source.Unit /= No_Unit_Index
2596 and then Root_Source.Unit.Name = Unit_Name;
2600 case Root_Source.Kind is
2605 Root_Found := Other_Part (Root_Source) = No_Source;
2608 Root_Found := False;
2613 Roots_Found := True;
2615 (" -> ", Name_Id (Root_Source.Display_File));
2616 Dummy := Queue.Insert_No_Roots
2617 (Source => (Format => Format_Gprbuild,
2618 Tree => Source.Tree,
2619 Id => Root_Source));
2621 Initialize_Source_Record (Root_Source);
2623 if Other_Part (Root_Source) /= No_Source then
2624 Initialize_Source_Record (Other_Part (Root_Source));
2627 -- Save the root for the binder
2629 Source.Id.Roots := new Source_Roots'
2630 (Root => Root_Source,
2631 Next => Source.Id.Roots);
2633 exit Source_Loop when not Pat_Root;
2637 end loop Source_Loop;
2639 if not Roots_Found then
2641 if not Quiet_Output then
2642 Error_Msg_Name_1 := Unit_Name;
2644 ("?no unit matches pattern %", Roots.Location);
2649 ("Unit " & Get_Name_String (Unit_Name)
2650 & " does not exist", Roots.Location);
2655 end loop Pattern_Loop;
2667 (Source : Source_Info;
2668 With_Roots : Boolean := False)
2671 pragma Unreferenced (Discard);
2673 Discard := Insert (Source, With_Roots);
2680 function Is_Empty return Boolean is
2682 return Q_Processed >= Q.Last;
2685 ------------------------
2686 -- Is_Virtually_Empty --
2687 ------------------------
2689 function Is_Virtually_Empty return Boolean is
2691 if One_Queue_Per_Obj_Dir then
2692 for J in Q_First .. Q.Last loop
2693 if not Q.Table (J).Processed
2694 and then Available_Obj_Dir (Q.Table (J).Info)
2705 end Is_Virtually_Empty;
2707 ----------------------
2708 -- Set_Obj_Dir_Busy --
2709 ----------------------
2711 procedure Set_Obj_Dir_Busy (Obj_Dir : Path_Name_Type) is
2713 if One_Queue_Per_Obj_Dir then
2714 Busy_Obj_Dirs.Set (Obj_Dir, True);
2716 end Set_Obj_Dir_Busy;
2718 ----------------------
2719 -- Set_Obj_Dir_Free --
2720 ----------------------
2722 procedure Set_Obj_Dir_Free (Obj_Dir : Path_Name_Type) is
2724 if One_Queue_Per_Obj_Dir then
2725 Busy_Obj_Dirs.Set (Obj_Dir, False);
2727 end Set_Obj_Dir_Free;
2733 function Size return Natural is
2742 function Element (Rank : Positive) return File_Name_Type is
2744 if Rank <= Q.Last then
2745 case Q.Table (Rank).Info.Format is
2746 when Format_Gprbuild =>
2747 return Q.Table (Rank).Info.Id.File;
2748 when Format_Gnatmake =>
2749 return Q.Table (Rank).Info.File;
2760 procedure Remove_Marks is
2765 ----------------------------
2766 -- Insert_Project_Sources --
2767 ----------------------------
2769 procedure Insert_Project_Sources
2770 (Project : Project_Id;
2771 Project_Tree : Project_Tree_Ref;
2772 All_Projects : Boolean;
2773 Unique_Compile : Boolean)
2775 procedure Do_Insert (Project : Project_Id; Tree : Project_Tree_Ref);
2781 procedure Do_Insert (Project : Project_Id; Tree : Project_Tree_Ref) is
2782 Unit_Based : constant Boolean :=
2784 or else not Builder_Data (Tree).Closure_Needed;
2785 -- When Unit_Based is True, put in the queue all compilable
2786 -- sources including the unit based (Ada) one. When Unit_Based is
2787 -- False, put the Ada sources only when they are in a library
2790 Iter : Source_Iterator;
2791 Source : Prj.Source_Id;
2794 -- Nothing to do when "-u" was specified and some files were
2795 -- specified on the command line
2798 and then Mains.Number_Of_Mains (Tree) > 0
2803 Iter := For_Each_Source (Tree);
2805 Source := Prj.Element (Iter);
2806 exit when Source = No_Source;
2808 if Is_Allowed_Language (Source.Language.Name)
2809 and then Is_Compilable (Source)
2812 or else Is_Extending (Project, Source.Project))
2813 and then not Source.Locally_Removed
2814 and then Source.Replaced_By = No_Source
2816 (not Source.Project.Externally_Built
2818 (Is_Extending (Project, Source.Project)
2819 and then not Project.Externally_Built))
2820 and then Source.Kind /= Sep
2821 and then Source.Path /= No_Path_Information
2823 if Source.Kind = Impl
2824 or else (Source.Unit /= No_Unit_Index
2825 and then Source.Kind = Spec
2826 and then (Other_Part (Source) = No_Source
2828 Other_Part (Source).Locally_Removed))
2831 or else Source.Unit = No_Unit_Index
2832 or else Source.Project.Library)
2833 and then not Is_Subunit (Source)
2836 (Source => (Format => Format_Gprbuild,
2847 procedure Insert_All is new For_Project_And_Aggregated (Do_Insert);
2850 Insert_All (Project, Project_Tree);
2851 end Insert_Project_Sources;
2853 -------------------------------
2854 -- Insert_Withed_Sources_For --
2855 -------------------------------
2857 procedure Insert_Withed_Sources_For
2858 (The_ALI : ALI.ALI_Id;
2859 Project_Tree : Project_Tree_Ref;
2860 Excluding_Shared_SALs : Boolean := False)
2862 Sfile : File_Name_Type;
2863 Afile : File_Name_Type;
2864 Src_Id : Prj.Source_Id;
2867 -- Insert in the queue the unmarked source files (i.e. those which
2868 -- have never been inserted in the queue and hence never considered).
2870 for J in ALI.ALIs.Table (The_ALI).First_Unit ..
2871 ALI.ALIs.Table (The_ALI).Last_Unit
2873 for K in ALI.Units.Table (J).First_With ..
2874 ALI.Units.Table (J).Last_With
2876 Sfile := ALI.Withs.Table (K).Sfile;
2880 if Sfile /= No_File then
2881 Afile := ALI.Withs.Table (K).Afile;
2883 Src_Id := Source_Files_Htable.Get
2884 (Project_Tree.Source_Files_HT, Sfile);
2885 while Src_Id /= No_Source loop
2886 Initialize_Source_Record (Src_Id);
2888 if Is_Compilable (Src_Id)
2889 and then Src_Id.Dep_Name = Afile
2894 Bdy : constant Prj.Source_Id :=
2895 Other_Part (Src_Id);
2898 and then not Bdy.Locally_Removed
2900 Src_Id := Other_Part (Src_Id);
2905 if Is_Subunit (Src_Id) then
2906 Src_Id := No_Source;
2910 Src_Id := No_Source;
2916 Src_Id := Src_Id.Next_With_File_Name;
2919 -- If Excluding_Shared_SALs is True, do not insert in the
2920 -- queue the sources of a shared Stand-Alone Library.
2922 if Src_Id /= No_Source
2923 and then (not Excluding_Shared_SALs
2924 or else Src_Id.Project.Standalone_Library = No
2925 or else Src_Id.Project.Library_Kind = Static)
2928 (Source => (Format => Format_Gprbuild,
2929 Tree => Project_Tree,
2935 end Insert_Withed_Sources_For;
2943 procedure Free (Data : in out Builder_Project_Tree_Data) is
2944 procedure Unchecked_Free is new Ada.Unchecked_Deallocation
2945 (Binding_Data_Record, Binding_Data);
2947 TmpB, Binding : Binding_Data := Data.Binding;
2950 while Binding /= null loop
2951 TmpB := Binding.Next;
2952 Unchecked_Free (Binding);
2961 function Builder_Data
2962 (Tree : Project_Tree_Ref) return Builder_Data_Access
2965 if Tree.Appdata = null then
2966 Tree.Appdata := new Builder_Project_Tree_Data;
2969 return Builder_Data_Access (Tree.Appdata);
2972 --------------------------------
2973 -- Compute_Compilation_Phases --
2974 --------------------------------
2976 procedure Compute_Compilation_Phases
2977 (Tree : Project_Tree_Ref;
2978 Root_Project : Project_Id;
2979 Option_Unique_Compile : Boolean := False; -- Was "-u" specified ?
2980 Option_Compile_Only : Boolean := False; -- Was "-c" specified ?
2981 Option_Bind_Only : Boolean := False;
2982 Option_Link_Only : Boolean := False)
2984 procedure Do_Compute (Project : Project_Id; Tree : Project_Tree_Ref);
2990 procedure Do_Compute (Project : Project_Id; Tree : Project_Tree_Ref) is
2991 Data : constant Builder_Data_Access := Builder_Data (Tree);
2992 All_Phases : constant Boolean :=
2993 not Option_Compile_Only
2994 and then not Option_Bind_Only
2995 and then not Option_Link_Only;
2996 -- Whether the command line asked for all three phases. Depending on
2997 -- the project settings, we might still disable some of the phases.
2999 Has_Mains : constant Boolean := Data.Number_Of_Mains > 0;
3000 -- Whether there are some main units defined for this project tree
3001 -- (either from one of the projects, or from the command line)
3004 if Option_Unique_Compile then
3006 -- If -u or -U is specified on the command line, disregard any -c,
3007 -- -b or -l switch: only perform compilation.
3009 Data.Closure_Needed := False;
3010 Data.Need_Compilation := True;
3011 Data.Need_Binding := False;
3012 Data.Need_Linking := False;
3015 Data.Closure_Needed := Has_Mains;
3016 Data.Need_Compilation := All_Phases or Option_Compile_Only;
3017 Data.Need_Binding := All_Phases or Option_Bind_Only;
3018 Data.Need_Linking := (All_Phases or Option_Link_Only)
3022 if Current_Verbosity = High then
3023 Debug_Output ("compilation phases: "
3024 & " compile=" & Data.Need_Compilation'Img
3025 & " bind=" & Data.Need_Binding'Img
3026 & " link=" & Data.Need_Linking'Img
3027 & " closure=" & Data.Closure_Needed'Img
3028 & " mains=" & Data.Number_Of_Mains'Img,
3033 procedure Compute_All is new For_Project_And_Aggregated (Do_Compute);
3036 Compute_All (Root_Project, Tree);
3037 end Compute_Compilation_Phases;
3039 ------------------------------
3040 -- Compute_Builder_Switches --
3041 ------------------------------
3043 procedure Compute_Builder_Switches
3044 (Project_Tree : Project_Tree_Ref;
3045 Root_Environment : in out Prj.Tree.Environment;
3046 Main_Project : Project_Id;
3047 Only_For_Lang : Name_Id := No_Name)
3049 Builder_Package : constant Package_Id :=
3050 Value_Of (Name_Builder, Main_Project.Decl.Packages,
3051 Project_Tree.Shared);
3053 Global_Compilation_Array : Array_Element_Id;
3054 Global_Compilation_Elem : Array_Element;
3055 Global_Compilation_Switches : Variable_Value;
3057 Default_Switches_Array : Array_Id;
3059 Builder_Switches_Lang : Name_Id := No_Name;
3061 List : String_List_Id;
3062 Element : String_Element;
3065 Source : Prj.Source_Id;
3067 Lang : Name_Id := No_Name; -- language index for Switches
3068 Switches_For_Lang : Variable_Value := Nil_Variable_Value;
3069 -- Value of Builder'Default_Switches(lang)
3071 Name : Name_Id := No_Name; -- main file index for Switches
3072 Switches_For_Main : Variable_Value := Nil_Variable_Value;
3073 -- Switches for a specific main. When there are several mains, Name is
3074 -- set to No_Name, and Switches_For_Main might be left with an actual
3075 -- value (so that we can display a warning that it was ignored).
3077 Other_Switches : Variable_Value := Nil_Variable_Value;
3078 -- Value of Builder'Switches(others)
3080 Defaults : Variable_Value := Nil_Variable_Value;
3082 Switches : Variable_Value := Nil_Variable_Value;
3083 -- The computed builder switches
3085 Success : Boolean := False;
3087 if Builder_Package /= No_Package then
3090 -- If there is no main, and there is only one compilable language,
3091 -- use this language as the switches index.
3093 if Mains.Number_Of_Mains (Project_Tree) = 0 then
3094 if Only_For_Lang = No_Name then
3096 Language : Language_Ptr := Main_Project.Languages;
3099 while Language /= No_Language_Index loop
3100 if Language.Config.Compiler_Driver /= No_File
3101 and then Language.Config.Compiler_Driver /= Empty_File
3103 if Lang /= No_Name then
3107 Lang := Language.Name;
3110 Language := Language.Next;
3114 Lang := Only_For_Lang;
3118 for Index in 1 .. Mains.Number_Of_Mains (Project_Tree) loop
3119 Source := Mains.Next_Main.Source;
3121 if Source /= No_Source then
3122 if Switches_For_Main = Nil_Variable_Value then
3123 Switches_For_Main := Value_Of
3124 (Name => Name_Id (Source.File),
3125 Attribute_Or_Array_Name => Name_Switches,
3126 In_Package => Builder_Package,
3127 Shared => Project_Tree.Shared,
3128 Force_Lower_Case_Index => False,
3129 Allow_Wildcards => True);
3131 -- If not found, try without extension.
3132 -- That's because gnatmake accepts truncated file names
3133 -- in Builder'Switches
3135 if Switches_For_Main = Nil_Variable_Value
3136 and then Source.Unit /= null
3138 Switches_For_Main := Value_Of
3139 (Name => Source.Unit.Name,
3140 Attribute_Or_Array_Name => Name_Switches,
3141 In_Package => Builder_Package,
3142 Shared => Project_Tree.Shared,
3143 Force_Lower_Case_Index => False,
3144 Allow_Wildcards => True);
3149 Lang := Source.Language.Name;
3150 Name := Name_Id (Source.File);
3152 Name := No_Name; -- Can't use main specific switches
3154 if Lang /= Source.Language.Name then
3162 Global_Compilation_Array := Value_Of
3163 (Name => Name_Global_Compilation_Switches,
3164 In_Arrays => Project_Tree.Shared.Packages.Table
3165 (Builder_Package).Decl.Arrays,
3166 Shared => Project_Tree.Shared);
3168 Default_Switches_Array :=
3169 Project_Tree.Shared.Packages.Table (Builder_Package).Decl.Arrays;
3171 while Default_Switches_Array /= No_Array
3173 Project_Tree.Shared.Arrays.Table (Default_Switches_Array).Name /=
3174 Name_Default_Switches
3176 Default_Switches_Array :=
3177 Project_Tree.Shared.Arrays.Table (Default_Switches_Array).Next;
3180 if Global_Compilation_Array /= No_Array_Element
3181 and then Default_Switches_Array /= No_Array
3184 (Root_Environment.Flags,
3185 "Default_Switches forbidden in presence of " &
3186 "Global_Compilation_Switches. Use Switches instead.",
3187 Project_Tree.Shared.Arrays.Table
3188 (Default_Switches_Array).Location);
3191 "*** illegal combination of Builder attributes");
3194 if Lang /= No_Name then
3195 Switches_For_Lang := Prj.Util.Value_Of
3198 Attribute_Or_Array_Name => Name_Switches,
3199 In_Package => Builder_Package,
3200 Shared => Project_Tree.Shared,
3201 Force_Lower_Case_Index => True);
3203 Defaults := Prj.Util.Value_Of
3206 Attribute_Or_Array_Name => Name_Default_Switches,
3207 In_Package => Builder_Package,
3208 Shared => Project_Tree.Shared,
3209 Force_Lower_Case_Index => True);
3212 Other_Switches := Prj.Util.Value_Of
3213 (Name => All_Other_Names,
3215 Attribute_Or_Array_Name => Name_Switches,
3216 In_Package => Builder_Package,
3217 Shared => Project_Tree.Shared);
3220 and then Mains.Number_Of_Mains (Project_Tree) > 1
3221 and then Switches_For_Main /= Nil_Variable_Value
3223 -- More than one main, but we had main-specific switches that
3226 if Switches_For_Lang /= Nil_Variable_Value then
3228 ("Warning: using Builder'Switches("""
3229 & Get_Name_String (Lang)
3230 & """), as there are several mains");
3232 elsif Other_Switches /= Nil_Variable_Value then
3234 ("Warning: using Builder'Switches(others), "
3235 & "as there are several mains");
3237 elsif Defaults /= Nil_Variable_Value then
3239 ("Warning: using Builder'Default_Switches("""
3240 & Get_Name_String (Lang)
3241 & """), as there are several mains");
3244 ("Warning: using no switches from package "
3245 & "Builder, as there are several mains");
3249 Builder_Switches_Lang := Lang;
3251 if Name /= No_Name then
3252 -- Get the switches for the single main
3253 Switches := Switches_For_Main;
3256 if Switches = Nil_Variable_Value or else Switches.Default then
3257 -- Get the switches for the common language of the mains
3258 Switches := Switches_For_Lang;
3261 if Switches = Nil_Variable_Value or else Switches.Default then
3262 Switches := Other_Switches;
3265 -- For backward compatibility with gnatmake, if no Switches
3266 -- are declared, check for Default_Switches (<language>).
3268 if Switches = Nil_Variable_Value or else Switches.Default then
3269 Switches := Defaults;
3272 -- If switches have been found, scan them
3274 if Switches /= Nil_Variable_Value and then not Switches.Default then
3275 List := Switches.Values;
3277 while List /= Nil_String loop
3278 Element := Project_Tree.Shared.String_Elements.Table (List);
3279 Get_Name_String (Element.Value);
3281 if Name_Len /= 0 then
3283 -- Add_Switch might itself be using the name_buffer, so
3284 -- we make a temporary here.
3285 Switch : constant String := Name_Buffer (1 .. Name_Len);
3287 Success := Add_Switch
3289 For_Lang => Builder_Switches_Lang,
3290 For_Builder => True,
3291 Has_Global_Compilation_Switches =>
3292 Global_Compilation_Array /= No_Array_Element);
3296 for J in reverse 1 .. Name_Len loop
3297 Name_Buffer (J + J) := Name_Buffer (J);
3298 Name_Buffer (J + J - 1) := ''';
3301 Name_Len := Name_Len + Name_Len;
3304 (Root_Environment.Flags,
3305 '"' & Name_Buffer (1 .. Name_Len) &
3306 """ is not a builder switch. Consider moving " &
3307 "it to Global_Compilation_Switches.",
3311 "*** illegal switch """ &
3312 Get_Name_String (Element.Value) & '"');
3316 List := Element.Next;
3320 -- Reset the Builder Switches language
3322 Builder_Switches_Lang := No_Name;
3324 -- Take into account attributes Global_Compilation_Switches
3326 while Global_Compilation_Array /= No_Array_Element loop
3327 Global_Compilation_Elem :=
3328 Project_Tree.Shared.Array_Elements.Table
3329 (Global_Compilation_Array);
3331 Get_Name_String (Global_Compilation_Elem.Index);
3332 To_Lower (Name_Buffer (1 .. Name_Len));
3335 if Only_For_Lang = No_Name or else Index = Only_For_Lang then
3336 Global_Compilation_Switches := Global_Compilation_Elem.Value;
3338 if Global_Compilation_Switches /= Nil_Variable_Value
3339 and then not Global_Compilation_Switches.Default
3341 -- We have found an attribute
3342 -- Global_Compilation_Switches for a language: put the
3343 -- switches in the appropriate table.
3345 List := Global_Compilation_Switches.Values;
3346 while List /= Nil_String loop
3348 Project_Tree.Shared.String_Elements.Table (List);
3350 if Element.Value /= No_Name then
3351 Success := Add_Switch
3352 (Switch => Get_Name_String (Element.Value),
3354 For_Builder => False,
3355 Has_Global_Compilation_Switches =>
3356 Global_Compilation_Array /= No_Array_Element);
3359 List := Element.Next;
3364 Global_Compilation_Array := Global_Compilation_Elem.Next;
3367 end Compute_Builder_Switches;
3369 ---------------------
3370 -- Write_Path_File --
3371 ---------------------
3373 procedure Write_Path_File (FD : File_Descriptor) is
3380 for Index in Directories.First .. Directories.Last loop
3381 Add_Str_To_Name_Buffer (Get_Name_String (Directories.Table (Index)));
3382 Add_Char_To_Name_Buffer (ASCII.LF);
3385 Last := Write (FD, Name_Buffer (1)'Address, Name_Len);
3387 if Last = Name_Len then
3394 Prj.Com.Fail ("could not write temporary file");
3396 end Write_Path_File;