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 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 Extended : in out Boolean);
698 -- Add all the source directories of a project to the path only if
699 -- this project has not been visited. Calls itself recursively for
700 -- projects being extended, and imported projects.
702 procedure Add_Dir (Value : Path_Name_Type);
703 -- Add directory Value in table Directories, if it is defined and not
710 procedure Add_Dir (Value : Path_Name_Type) is
711 Add_It : Boolean := True;
714 if Value /= No_Path then
715 for Index in 1 .. Directories.Last loop
716 if Directories.Table (Index) = Value then
723 Directories.Increment_Last;
724 Directories.Table (Directories.Last) := Value;
733 procedure Recursive_Add
734 (Project : Project_Id;
735 Tree : Project_Tree_Ref;
736 Extended : in out Boolean)
738 Current : String_List_Id;
739 Dir : String_Element;
740 OK : Boolean := False;
741 Lang_Proc : Language_Ptr := Project.Languages;
744 -- Add to path all directories of this project
746 if Activity = Compilation then
748 while Lang_Proc /= No_Language_Index loop
749 for J in Languages'Range loop
750 OK := Lang_Proc.Name = Languages (J);
751 exit Lang_Loop when OK;
754 Lang_Proc := Lang_Proc.Next;
758 Current := Project.Source_Dirs;
760 while Current /= Nil_String loop
761 Dir := Tree.Shared.String_Elements.Table (Current);
762 Add_Dir (Path_Name_Type (Dir.Value));
767 elsif Project.Library then
768 if Activity = SAL_Binding and then Extended then
769 Add_Dir (Project.Object_Directory.Display_Name);
772 Add_Dir (Project.Library_ALI_Dir.Display_Name);
776 Add_Dir (Project.Object_Directory.Display_Name);
779 if Project.Extends = No_Project then
784 procedure For_All_Projects is
785 new For_Every_Project_Imported (Boolean, Recursive_Add);
787 Extended : Boolean := True;
789 -- Start of processing for Get_Directories
793 For_All_Projects (For_Project, Project_Tree, Extended);
800 procedure Get_Switches
801 (Source : Prj.Source_Id;
803 Project_Tree : Project_Tree_Ref;
804 Value : out Variable_Value;
805 Is_Default : out Boolean)
809 (Source_File => Source.File,
810 Source_Lang => Source.Language.Name,
811 Source_Prj => Source.Project,
812 Pkg_Name => Pkg_Name,
813 Project_Tree => Project_Tree,
815 Is_Default => Is_Default);
822 procedure Get_Switches
823 (Source_File : File_Name_Type;
824 Source_Lang : Name_Id;
825 Source_Prj : Project_Id;
827 Project_Tree : Project_Tree_Ref;
828 Value : out Variable_Value;
829 Is_Default : out Boolean;
830 Test_Without_Suffix : Boolean := False;
831 Check_ALI_Suffix : Boolean := False)
833 Project : constant Project_Id :=
834 Ultimate_Extending_Project_Of (Source_Prj);
835 Pkg : constant Package_Id :=
838 In_Packages => Project.Decl.Packages,
839 Shared => Project_Tree.Shared);
845 if Source_File /= No_File then
846 Value := Prj.Util.Value_Of
847 (Name => Name_Id (Source_File),
848 Attribute_Or_Array_Name => Name_Switches,
850 Shared => Project_Tree.Shared,
851 Allow_Wildcards => True);
854 if Value = Nil_Variable_Value and then Test_Without_Suffix then
856 Get_Language_From_Name (Project, Get_Name_String (Source_Lang));
860 Naming : Lang_Naming_Data renames Lang.Config.Naming_Data;
861 SF_Name : constant String := Get_Name_String (Source_File);
862 Last : Positive := SF_Name'Length;
863 Name : String (1 .. Last + 3);
864 Spec_Suffix : String := Get_Name_String (Naming.Spec_Suffix);
865 Body_Suffix : String := Get_Name_String (Naming.Body_Suffix);
866 Truncated : Boolean := False;
869 Canonical_Case_File_Name (Spec_Suffix);
870 Canonical_Case_File_Name (Body_Suffix);
871 Name (1 .. Last) := SF_Name;
873 if Last > Body_Suffix'Length
875 Name (Last - Body_Suffix'Length + 1 .. Last) = Body_Suffix
878 Last := Last - Body_Suffix'Length;
882 and then Last > Spec_Suffix'Length
884 Name (Last - Spec_Suffix'Length + 1 .. Last) = Spec_Suffix
887 Last := Last - Spec_Suffix'Length;
892 Add_Str_To_Name_Buffer (Name (1 .. Last));
894 Value := Prj.Util.Value_Of
896 Attribute_Or_Array_Name => Name_Switches,
898 Shared => Project_Tree.Shared,
899 Allow_Wildcards => True);
902 if Value = Nil_Variable_Value and then Check_ALI_Suffix then
903 Last := SF_Name'Length;
904 while Name (Last) /= '.' loop
909 Add_Str_To_Name_Buffer (Name (1 .. Last));
910 Add_Str_To_Name_Buffer ("ali");
912 Value := Prj.Util.Value_Of
914 Attribute_Or_Array_Name => Name_Switches,
916 Shared => Project_Tree.Shared,
917 Allow_Wildcards => True);
923 if Value = Nil_Variable_Value then
927 (Name => Source_Lang,
928 Attribute_Or_Array_Name => Name_Switches,
930 Shared => Project_Tree.Shared,
931 Force_Lower_Case_Index => True);
934 if Value = Nil_Variable_Value then
937 (Name => All_Other_Names,
938 Attribute_Or_Array_Name => Name_Switches,
940 Shared => Project_Tree.Shared,
941 Force_Lower_Case_Index => True);
944 if Value = Nil_Variable_Value then
947 (Name => Source_Lang,
948 Attribute_Or_Array_Name => Name_Default_Switches,
950 Shared => Project_Tree.Shared);
958 procedure Inform (N : File_Name_Type; Msg : String) is
960 Inform (Name_Id (N), Msg);
963 procedure Inform (N : Name_Id := No_Name; Msg : String) is
965 Osint.Write_Program_Name;
973 Name : constant String := Get_Name_String (N);
975 if Debug.Debug_Flag_F and then Is_Absolute_Path (Name) then
976 Write_Str (File_Name (Name));
989 ------------------------------
990 -- Initialize_Source_Record --
991 ------------------------------
993 procedure Initialize_Source_Record (Source : Prj.Source_Id) is
995 procedure Set_Object_Project
997 Obj_Proj : Project_Id;
998 Obj_Path : Path_Name_Type;
999 Stamp : Time_Stamp_Type);
1000 -- Update information about object file, switches file,...
1002 ------------------------
1003 -- Set_Object_Project --
1004 ------------------------
1006 procedure Set_Object_Project
1008 Obj_Proj : Project_Id;
1009 Obj_Path : Path_Name_Type;
1010 Stamp : Time_Stamp_Type) is
1012 Source.Object_Project := Obj_Proj;
1013 Source.Object_Path := Obj_Path;
1014 Source.Object_TS := Stamp;
1016 if Source.Language.Config.Dependency_Kind /= None then
1018 Dep_Path : constant String :=
1021 Get_Name_String (Source.Dep_Name),
1022 Resolve_Links => Opt.Follow_Links_For_Files,
1023 Directory => Obj_Dir);
1025 Source.Dep_Path := Create_Name (Dep_Path);
1026 Source.Dep_TS := Osint.Unknown_Attributes;
1030 -- Get the path of the switches file, even if Opt.Check_Switches is
1031 -- not set, as switch -s may be in the Builder switches that have not
1032 -- been scanned yet.
1035 Switches_Path : constant String :=
1038 Get_Name_String (Source.Switches),
1039 Resolve_Links => Opt.Follow_Links_For_Files,
1040 Directory => Obj_Dir);
1042 Source.Switches_Path := Create_Name (Switches_Path);
1044 if Stamp /= Empty_Time_Stamp then
1045 Source.Switches_TS := File_Stamp (Source.Switches_Path);
1048 end Set_Object_Project;
1050 Obj_Proj : Project_Id;
1053 -- Nothing to do if source record has already been fully initialized
1055 if Source.Initialized then
1059 -- Systematically recompute the time stamp
1061 Source.Source_TS := File_Stamp (Source.Path.Display_Name);
1063 -- Parse the source file to check whether we have a subunit
1065 if Source.Language.Config.Kind = Unit_Based
1066 and then Source.Kind = Impl
1067 and then Is_Subunit (Source)
1072 if Source.Language.Config.Object_Generated
1073 and then Is_Compilable (Source)
1075 -- First, get the correct object file name and dependency file name
1076 -- if the source is in a multi-unit file.
1078 if Source.Index /= 0 then
1081 (Source_File_Name => Source.File,
1082 Source_Index => Source.Index,
1084 Source.Language.Config.Multi_Unit_Object_Separator,
1085 Object_File_Suffix =>
1086 Source.Language.Config.Object_File_Suffix);
1090 (Source.Object, Source.Language.Config.Dependency_Kind);
1093 -- Find the object file for that source. It could be either in the
1094 -- current project or in an extended project (it might actually not
1095 -- exist yet in the ultimate extending project, but if not found
1096 -- elsewhere that's where we'll expect to find it).
1098 Obj_Proj := Source.Project;
1100 while Obj_Proj /= No_Project loop
1102 Dir : constant String :=
1104 (Obj_Proj.Object_Directory.Display_Name);
1106 Object_Path : constant String :=
1109 Get_Name_String (Source.Object),
1110 Resolve_Links => Opt.Follow_Links_For_Files,
1113 Obj_Path : constant Path_Name_Type := Create_Name (Object_Path);
1114 Stamp : Time_Stamp_Type := Empty_Time_Stamp;
1117 -- For specs, we do not check object files if there is a body.
1118 -- This saves a system call. On the other hand, we do need to
1119 -- know the object_path, in case the user has passed the .ads
1120 -- on the command line to compile the spec only.
1122 if Source.Kind /= Spec
1123 or else Source.Unit = No_Unit_Index
1124 or else Source.Unit.File_Names (Impl) = No_Source
1126 Stamp := File_Stamp (Obj_Path);
1129 if Stamp /= Empty_Time_Stamp
1130 or else (Obj_Proj.Extended_By = No_Project
1131 and then Source.Object_Project = No_Project)
1133 Set_Object_Project (Dir, Obj_Proj, Obj_Path, Stamp);
1136 Obj_Proj := Obj_Proj.Extended_By;
1140 elsif Source.Language.Config.Dependency_Kind = Makefile then
1142 Object_Dir : constant String :=
1144 (Source.Project.Object_Directory.Display_Name);
1145 Dep_Path : constant String :=
1147 (Name => Get_Name_String (Source.Dep_Name),
1149 Opt.Follow_Links_For_Files,
1150 Directory => Object_Dir);
1152 Source.Dep_Path := Create_Name (Dep_Path);
1153 Source.Dep_TS := Osint.Unknown_Attributes;
1157 Source.Initialized := True;
1158 end Initialize_Source_Record;
1160 ----------------------------
1161 -- Is_External_Assignment --
1162 ----------------------------
1164 function Is_External_Assignment
1165 (Env : Prj.Tree.Environment;
1166 Argv : String) return Boolean
1168 Start : Positive := 3;
1169 Finish : Natural := Argv'Last;
1171 pragma Assert (Argv'First = 1);
1172 pragma Assert (Argv (1 .. 2) = "-X");
1175 if Argv'Last < 5 then
1178 elsif Argv (3) = '"' then
1179 if Argv (Argv'Last) /= '"' or else Argv'Last < 7 then
1183 Finish := Argv'Last - 1;
1187 return Prj.Ext.Check
1188 (Self => Env.External,
1189 Declaration => Argv (Start .. Finish));
1190 end Is_External_Assignment;
1196 function Is_Subunit (Source : Prj.Source_Id) return Boolean is
1197 Src_Ind : Source_File_Index;
1200 if Source.Kind = Sep then
1203 -- A Spec, a file based language source or a body with a spec cannot be
1206 elsif Source.Kind = Spec
1207 or else Source.Unit = No_Unit_Index
1208 or else Other_Part (Source) /= No_Source
1213 -- Here, we are assuming that the language is Ada, as it is the only
1214 -- unit based language that we know.
1217 Sinput.P.Load_Project_File
1218 (Get_Name_String (Source.Path.Display_Name));
1220 return Sinput.P.Source_File_Is_Subunit (Src_Ind);
1223 -----------------------------
1224 -- Linker_Options_Switches --
1225 -----------------------------
1227 function Linker_Options_Switches
1228 (Project : Project_Id;
1229 Do_Fail : Fail_Proc;
1230 In_Tree : Project_Tree_Ref) return String_List
1232 procedure Recursive_Add
1234 In_Tree : Project_Tree_Ref;
1235 Dummy : in out Boolean);
1236 -- The recursive routine used to add linker options
1242 procedure Recursive_Add
1244 In_Tree : Project_Tree_Ref;
1245 Dummy : in out Boolean)
1247 pragma Unreferenced (Dummy);
1249 Linker_Package : Package_Id;
1250 Options : Variable_Value;
1255 (Name => Name_Linker,
1256 In_Packages => Proj.Decl.Packages,
1257 Shared => In_Tree.Shared);
1263 Attribute_Or_Array_Name => Name_Linker_Options,
1264 In_Package => Linker_Package,
1265 Shared => In_Tree.Shared);
1267 -- If attribute is present, add the project with the attribute to
1268 -- table Linker_Opts.
1270 if Options /= Nil_Variable_Value then
1271 Linker_Opts.Increment_Last;
1272 Linker_Opts.Table (Linker_Opts.Last) :=
1273 (Project => Proj, Options => Options.Values);
1277 procedure For_All_Projects is
1278 new For_Every_Project_Imported (Boolean, Recursive_Add);
1280 Dummy : Boolean := False;
1282 -- Start of processing for Linker_Options_Switches
1287 For_All_Projects (Project, In_Tree, Dummy, Imported_First => True);
1289 Last_Linker_Option := 0;
1291 for Index in reverse 1 .. Linker_Opts.Last loop
1293 Options : String_List_Id;
1294 Proj : constant Project_Id :=
1295 Linker_Opts.Table (Index).Project;
1297 Dir_Path : constant String :=
1298 Get_Name_String (Proj.Directory.Name);
1301 Options := Linker_Opts.Table (Index).Options;
1302 while Options /= Nil_String loop
1303 Option := In_Tree.Shared.String_Elements.Table (Options).Value;
1304 Get_Name_String (Option);
1306 -- Do not consider empty linker options
1308 if Name_Len /= 0 then
1309 Add_Linker_Option (Name_Buffer (1 .. Name_Len));
1311 -- Object files and -L switches specified with relative
1312 -- paths must be converted to absolute paths.
1314 Test_If_Relative_Path
1315 (Switch => Linker_Options_Buffer (Last_Linker_Option),
1318 Including_L_Switch => True);
1321 Options := In_Tree.Shared.String_Elements.Table (Options).Next;
1326 return Linker_Options_Buffer (1 .. Last_Linker_Option);
1327 end Linker_Options_Switches;
1333 package body Mains is
1335 package Names is new Table.Table
1336 (Table_Component_Type => Main_Info,
1337 Table_Index_Type => Integer,
1338 Table_Low_Bound => 1,
1339 Table_Initial => 10,
1340 Table_Increment => 100,
1341 Table_Name => "Makeutl.Mains.Names");
1342 -- The table that stores the mains
1344 Current : Natural := 0;
1345 -- The index of the last main retrieved from the table
1347 Count_Of_Mains_With_No_Tree : Natural := 0;
1348 -- Number of main units for which we do not know the project tree
1357 Location : Source_Ptr := No_Location;
1358 Project : Project_Id := No_Project;
1359 Tree : Project_Tree_Ref := null)
1362 if Current_Verbosity = High then
1363 Debug_Output ("Add_Main """ & Name & """ " & Index'Img
1365 & Boolean'Image (Tree /= null));
1369 Add_Str_To_Name_Buffer (Name);
1370 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1372 Names.Increment_Last;
1373 Names.Table (Names.Last) :=
1374 (Name_Find, Index, Location, No_Source, Project, Tree);
1376 if Tree /= null then
1377 Builder_Data (Tree).Number_Of_Mains :=
1378 Builder_Data (Tree).Number_Of_Mains + 1;
1381 Mains.Count_Of_Mains_With_No_Tree :=
1382 Mains.Count_Of_Mains_With_No_Tree + 1;
1386 --------------------
1387 -- Complete_Mains --
1388 --------------------
1390 procedure Complete_Mains
1391 (Flags : Processing_Flags;
1392 Root_Project : Project_Id;
1393 Project_Tree : Project_Tree_Ref)
1395 procedure Do_Complete (Project : Project_Id; Tree : Project_Tree_Ref);
1396 -- Check the mains for this specific project
1398 procedure Complete_All is new For_Project_And_Aggregated
1401 procedure Add_Multi_Unit_Sources
1402 (Tree : Project_Tree_Ref;
1403 Source : Prj.Source_Id);
1404 -- Add all units from the same file as the multi-unit Source
1406 function Find_File_Add_Extension
1407 (Tree : Project_Tree_Ref;
1408 Base_Main : String) return Prj.Source_Id;
1409 -- Search for Main in the project, adding body or spec extensions
1411 ----------------------------
1412 -- Add_Multi_Unit_Sources --
1413 ----------------------------
1415 procedure Add_Multi_Unit_Sources
1416 (Tree : Project_Tree_Ref;
1417 Source : Prj.Source_Id)
1419 Iter : Source_Iterator;
1420 Src : Prj.Source_Id;
1424 ("found multi-unit source file in project", Source.Project.Name);
1426 Iter := For_Each_Source
1427 (In_Tree => Tree, Project => Source.Project);
1429 while Element (Iter) /= No_Source loop
1430 Src := Element (Iter);
1432 if Src.File = Source.File
1433 and then Src.Index /= Source.Index
1435 if Src.File = Source.File then
1437 ("add main in project, index=" & Src.Index'Img);
1440 Names.Increment_Last;
1441 Names.Table (Names.Last) :=
1444 Location => No_Location,
1446 Project => Src.Project,
1449 Builder_Data (Tree).Number_Of_Mains :=
1450 Builder_Data (Tree).Number_Of_Mains + 1;
1455 end Add_Multi_Unit_Sources;
1457 -----------------------------
1458 -- Find_File_Add_Extension --
1459 -----------------------------
1461 function Find_File_Add_Extension
1462 (Tree : Project_Tree_Ref;
1463 Base_Main : String) return Prj.Source_Id
1465 Spec_Source : Prj.Source_Id := No_Source;
1466 Source : Prj.Source_Id;
1467 Iter : Source_Iterator;
1468 Suffix : File_Name_Type;
1471 Source := No_Source;
1472 Iter := For_Each_Source (Tree); -- In all projects
1474 Source := Prj.Element (Iter);
1475 exit when Source = No_Source;
1477 if Source.Kind = Impl then
1478 Get_Name_String (Source.File);
1480 if Name_Len > Base_Main'Length
1481 and then Name_Buffer (1 .. Base_Main'Length) = Base_Main
1484 Source.Language.Config.Naming_Data.Body_Suffix;
1486 if Suffix /= No_File then
1488 Suffix_Str : String := Get_Name_String (Suffix);
1490 Canonical_Case_File_Name (Suffix_Str);
1492 Name_Buffer (Base_Main'Length + 1 .. Name_Len) =
1498 elsif Source.Kind = Spec then
1499 -- A spec needs to be taken into account unless there is
1500 -- also a body. So we delay the decision for them.
1502 Get_Name_String (Source.File);
1504 if Name_Len > Base_Main'Length
1505 and then Name_Buffer (1 .. Base_Main'Length) = Base_Main
1507 Suffix := Source.Language.Config.Naming_Data.Spec_Suffix;
1509 if Suffix /= No_File then
1511 Suffix_Str : String := Get_Name_String (Suffix);
1514 Canonical_Case_File_Name (Suffix_Str);
1516 if Name_Buffer (Base_Main'Length + 1 .. Name_Len) =
1519 Spec_Source := Source;
1529 if Source = No_Source then
1530 Source := Spec_Source;
1534 end Find_File_Add_Extension;
1540 procedure Do_Complete
1541 (Project : Project_Id; Tree : Project_Tree_Ref)
1546 if Mains.Number_Of_Mains (Tree) > 0
1547 or else Mains.Count_Of_Mains_With_No_Tree > 0
1549 -- Traverse in reverse order, since in the case of multi-unit
1550 -- files we will be adding extra files at the end, and there's
1551 -- no need to process them in turn.
1556 File : Main_Info := Names.Table (J);
1557 Main_Id : File_Name_Type := File.File;
1558 Main : constant String :=
1559 Get_Name_String (Main_Id);
1560 Base : constant String := Base_Name (Main);
1561 Source : Prj.Source_Id := No_Source;
1562 Is_Absolute : Boolean := False;
1565 if Base /= Main then
1566 Is_Absolute := True;
1568 if Is_Absolute_Path (Main) then
1569 Main_Id := Create_Name (Base);
1571 -- Not an absolute path
1574 -- Always resolve links here, so that users can be
1575 -- specify any name on the command line. If the
1576 -- project itself uses links, the user will be
1577 -- using -eL anyway, and thus files are also stored
1578 -- with resolved names.
1581 Absolute : constant String :=
1585 Resolve_Links => True,
1586 Case_Sensitive => False);
1588 File.File := Create_Name (Absolute);
1589 Main_Id := Create_Name (Base);
1594 -- If no project or tree was specified for the main, it
1595 -- came from the command line.
1596 -- Note that the assignments below will not modify inside
1597 -- the table itself.
1599 if File.Project = null then
1600 File.Project := Project;
1603 if File.Tree = null then
1607 if File.Source = null then
1608 if Current_Verbosity = High then
1610 ("search for main """ & Main
1611 & '"' & File.Index'Img & " in "
1612 & Get_Name_String (Debug_Name (File.Tree))
1613 & ", project", Project.Name);
1616 -- First, look for the main as specified. We need to
1617 -- search for the base name though, and if needed
1618 -- check later that we found the correct file.
1620 Source := Find_Source
1621 (In_Tree => File.Tree,
1622 Project => File.Project,
1623 Base_Name => Main_Id,
1624 Index => File.Index,
1625 In_Imported_Only => True);
1627 if Source = No_Source then
1628 Source := Find_File_Add_Extension
1629 (Tree, Get_Name_String (Main_Id));
1633 and then Source /= No_Source
1635 File_Name_Type (Source.Path.Name) /= File.File
1638 ("Found a non-matching file",
1639 Name_Id (Source.Path.Display_Name));
1640 Source := No_Source;
1643 if Source /= No_Source then
1644 if not Is_Allowed_Language
1645 (Source.Language.Name)
1647 -- Remove any main that is not in the list of
1648 -- restricted languages.
1650 Names.Table (J .. Names.Last - 1) :=
1651 Names.Table (J + 1 .. Names.Last);
1652 Names.Set_Last (Names.Last - 1);
1655 -- If we have found a multi-unit source file but
1656 -- did not specify an index initially, we'll
1657 -- need to compile all the units from the same
1660 if Source.Index /= 0 and then File.Index = 0 then
1661 Add_Multi_Unit_Sources (File.Tree, Source);
1664 -- Now update the original Main, otherwise it
1665 -- will be reported as not found.
1668 ("found main in project", Source.Project.Name);
1669 Names.Table (J).File := Source.File;
1670 Names.Table (J).Project := Source.Project;
1672 if Names.Table (J).Tree = null then
1673 Names.Table (J).Tree := File.Tree;
1675 Builder_Data (File.Tree).Number_Of_Mains :=
1676 Builder_Data (File.Tree).Number_Of_Mains
1678 Mains.Count_Of_Mains_With_No_Tree :=
1679 Mains.Count_Of_Mains_With_No_Tree - 1;
1682 Names.Table (J).Source := Source;
1683 Names.Table (J).Index := Source.Index;
1686 elsif File.Location /= No_Location then
1688 -- If the main is declared in package Builder of
1689 -- the main project, report an error. If the main
1690 -- is on the command line, it may be a main from
1691 -- another project, so do nothing: if the main does
1692 -- not exist in another project, an error will be
1695 Error_Msg_File_1 := Main_Id;
1696 Error_Msg_Name_1 := Root_Project.Name;
1698 (Flags, "{ is not a source of project %%",
1699 File.Location, Project);
1705 exit when J < Names.First;
1709 if Total_Errors_Detected > 0 then
1710 Fail_Program (Tree, "problems with main sources");
1714 -- Start of processing for Complete_Mains
1717 Complete_All (Root_Project, Project_Tree);
1719 if Mains.Count_Of_Mains_With_No_Tree > 0 then
1720 for J in Names.First .. Names.Last loop
1721 if Names.Table (J).Source = No_Source then
1723 (Project_Tree, '"' & Get_Name_String (Names.Table (J).File)
1724 & """ is not a source of any project");
1740 -----------------------
1741 -- Fill_From_Project --
1742 -----------------------
1744 procedure Fill_From_Project
1745 (Root_Project : Project_Id;
1746 Project_Tree : Project_Tree_Ref)
1748 procedure Add_Mains_From_Project
1749 (Project : Project_Id;
1750 Tree : Project_Tree_Ref);
1751 -- Add the main units from this project into Mains.
1752 -- This takes into account the aggregated projects
1754 ----------------------------
1755 -- Add_Mains_From_Project --
1756 ----------------------------
1758 procedure Add_Mains_From_Project
1759 (Project : Project_Id;
1760 Tree : Project_Tree_Ref)
1762 List : String_List_Id;
1763 Element : String_Element;
1766 if Number_Of_Mains (Tree) = 0
1767 and then Mains.Count_Of_Mains_With_No_Tree = 0
1769 Debug_Output ("Add_Mains_From_Project", Project.Name);
1770 List := Project.Mains;
1772 if List /= Prj.Nil_String then
1774 -- The attribute Main is not an empty list. Get the mains in
1777 while List /= Prj.Nil_String loop
1778 Element := Tree.Shared.String_Elements.Table (List);
1779 Debug_Output ("Add_Main", Element.Value);
1781 if Project.Library then
1784 "cannot specify a main program " &
1785 "for a library project file");
1788 Add_Main (Name => Get_Name_String (Element.Value),
1789 Index => Element.Index,
1790 Location => Element.Location,
1793 List := Element.Next;
1798 if Total_Errors_Detected > 0 then
1799 Fail_Program (Tree, "problems with main sources");
1801 end Add_Mains_From_Project;
1803 procedure Fill_All is new For_Project_And_Aggregated
1804 (Add_Mains_From_Project);
1806 -- Start of processing for Fill_From_Project
1809 Fill_All (Root_Project, Project_Tree);
1810 end Fill_From_Project;
1816 function Next_Main return String is
1817 Info : constant Main_Info := Next_Main;
1819 if Info = No_Main_Info then
1822 return Get_Name_String (Info.File);
1826 function Next_Main return Main_Info is
1828 if Current >= Names.Last then
1829 return No_Main_Info;
1831 Current := Current + 1;
1833 -- If not using projects, and in the gnatmake case, the main file
1834 -- may have not have the extension. Try ".adb" first then ".ads"
1836 if Names.Table (Current).Project = No_Project then
1838 Orig_Main : constant File_Name_Type :=
1839 Names.Table (Current).File;
1840 Current_Main : File_Name_Type;
1843 if Strip_Suffix (Orig_Main) = Orig_Main then
1844 Get_Name_String (Orig_Main);
1845 Add_Str_To_Name_Buffer (".adb");
1846 Current_Main := Name_Find;
1848 if Full_Source_Name (Current_Main) = No_File then
1849 Get_Name_String (Orig_Main);
1850 Add_Str_To_Name_Buffer (".ads");
1851 Current_Main := Name_Find;
1853 if Full_Source_Name (Current_Main) /= No_File then
1854 Names.Table (Current).File := Current_Main;
1858 Names.Table (Current).File := Current_Main;
1864 return Names.Table (Current);
1868 ---------------------
1869 -- Number_Of_Mains --
1870 ---------------------
1872 function Number_Of_Mains (Tree : Project_Tree_Ref) return Natural is
1877 return Builder_Data (Tree).Number_Of_Mains;
1879 end Number_Of_Mains;
1890 --------------------------
1891 -- Set_Multi_Unit_Index --
1892 --------------------------
1894 procedure Set_Multi_Unit_Index
1895 (Project_Tree : Project_Tree_Ref := null;
1900 if Names.Last = 0 then
1903 "cannot specify a multi-unit index but no main " &
1904 "on the command line");
1906 elsif Names.Last > 1 then
1909 "cannot specify several mains with a multi-unit index");
1912 Names.Table (Names.Last).Index := Index;
1915 end Set_Multi_Unit_Index;
1919 -----------------------
1920 -- Path_Or_File_Name --
1921 -----------------------
1923 function Path_Or_File_Name (Path : Path_Name_Type) return String is
1924 Path_Name : constant String := Get_Name_String (Path);
1926 if Debug.Debug_Flag_F then
1927 return File_Name (Path_Name);
1931 end Path_Or_File_Name;
1933 ---------------------------
1934 -- Test_If_Relative_Path --
1935 ---------------------------
1937 procedure Test_If_Relative_Path
1938 (Switch : in out String_Access;
1940 Do_Fail : Fail_Proc;
1941 Including_L_Switch : Boolean := True;
1942 Including_Non_Switch : Boolean := True;
1943 Including_RTS : Boolean := False)
1946 if Switch /= null then
1948 Sw : String (1 .. Switch'Length);
1954 if Sw (1) = '-' then
1956 and then (Sw (2) = 'A'
1957 or else Sw (2) = 'I'
1958 or else (Including_L_Switch and then Sw (2) = 'L'))
1966 elsif Sw'Length >= 4
1967 and then (Sw (2 .. 3) = "aL"
1976 and then Sw'Length >= 7
1977 and then Sw (2 .. 6) = "-RTS="
1985 -- Because relative path arguments to --RTS= may be relative to
1986 -- the search directory prefix, those relative path arguments
1987 -- are converted only when they include directory information.
1989 if not Is_Absolute_Path (Sw (Start .. Sw'Last)) then
1990 if Parent'Length = 0 then
1992 ("relative search path switches ("""
1994 & """) are not allowed");
1996 elsif Including_RTS then
1997 for J in Start .. Sw'Last loop
1998 if Sw (J) = Directory_Separator then
2001 (Sw (1 .. Start - 1) &
2003 Directory_Separator &
2004 Sw (Start .. Sw'Last));
2012 (Sw (1 .. Start - 1) &
2014 Directory_Separator &
2015 Sw (Start .. Sw'Last));
2019 elsif Including_Non_Switch then
2020 if not Is_Absolute_Path (Sw) then
2021 if Parent'Length = 0 then
2023 ("relative paths (""" & Sw & """) are not allowed");
2025 Switch := new String'(Parent & Directory_Separator & Sw);
2031 end Test_If_Relative_Path;
2037 function Unit_Index_Of (ALI_File : File_Name_Type) return Int is
2043 Get_Name_String (ALI_File);
2045 -- First, find the last dot
2049 while Finish >= 1 and then Name_Buffer (Finish) /= '.' loop
2050 Finish := Finish - 1;
2057 -- Now check that the dot is preceded by digits
2060 Finish := Finish - 1;
2061 while Start >= 1 and then Name_Buffer (Start - 1) in '0' .. '9' loop
2065 -- If there are no digits, or if the digits are not preceded by the
2066 -- character that precedes a unit index, this is not the ALI file of
2067 -- a unit in a multi-unit source.
2071 or else Name_Buffer (Start - 1) /= Multi_Unit_Index_Character
2076 -- Build the index from the digit(s)
2078 while Start <= Finish loop
2079 Result := Result * 10 +
2080 Character'Pos (Name_Buffer (Start)) - Character'Pos ('0');
2091 procedure Verbose_Msg
2094 N2 : Name_Id := No_Name;
2096 Prefix : String := " -> ";
2097 Minimum_Verbosity : Opt.Verbosity_Level_Type := Opt.Low)
2100 if not Opt.Verbose_Mode
2101 or else Minimum_Verbosity > Opt.Verbosity_Level
2112 if N2 /= No_Name then
2122 procedure Verbose_Msg
2123 (N1 : File_Name_Type;
2125 N2 : File_Name_Type := No_File;
2127 Prefix : String := " -> ";
2128 Minimum_Verbosity : Opt.Verbosity_Level_Type := Opt.Low)
2132 (Name_Id (N1), S1, Name_Id (N2), S2, Prefix, Minimum_Verbosity);
2139 package body Queue is
2141 type Q_Record is record
2143 Processed : Boolean;
2146 package Q is new Table.Table
2147 (Table_Component_Type => Q_Record,
2148 Table_Index_Type => Natural,
2149 Table_Low_Bound => 1,
2150 Table_Initial => 1000,
2151 Table_Increment => 100,
2152 Table_Name => "Makeutl.Queue.Q");
2153 -- This is the actual Queue
2155 package Busy_Obj_Dirs is new GNAT.HTable.Simple_HTable
2156 (Header_Num => Prj.Header_Num,
2158 No_Element => False,
2159 Key => Path_Name_Type,
2163 type Mark_Key is record
2164 File : File_Name_Type;
2167 -- Identify either a mono-unit source (when Index = 0) or a specific
2168 -- unit (index = 1's origin index of unit) in a multi-unit source.
2170 Max_Mask_Num : constant := 2048;
2171 subtype Mark_Num is Union_Id range 0 .. Max_Mask_Num - 1;
2173 function Hash (Key : Mark_Key) return Mark_Num;
2175 package Marks is new GNAT.HTable.Simple_HTable
2176 (Header_Num => Mark_Num,
2178 No_Element => False,
2182 -- A hash table to keep tracks of the marked units.
2183 -- These are the units that have already been processed, when using the
2184 -- gnatmake format. When using the gprbuild format, we can directly
2185 -- store in the source_id whether the file has already been processed.
2187 procedure Mark (Source_File : File_Name_Type; Index : Int := 0);
2188 -- Mark a unit, identified by its source file and, when Index is not 0,
2189 -- the index of the unit in the source file. Marking is used to signal
2190 -- that the unit has already been inserted in the Q.
2193 (Source_File : File_Name_Type;
2194 Index : Int := 0) return Boolean;
2195 -- Returns True if the unit was previously marked
2197 Q_Processed : Natural := 0;
2198 Q_Initialized : Boolean := False;
2200 Q_First : Natural := 1;
2201 -- Points to the first valid element in the queue
2203 One_Queue_Per_Obj_Dir : Boolean := False;
2204 -- See parameter to Initialize
2206 function Available_Obj_Dir (S : Source_Info) return Boolean;
2207 -- Whether the object directory for S is available for a build
2209 procedure Debug_Display (S : Source_Info);
2210 -- A debug display for S
2212 function Was_Processed (S : Source_Info) return Boolean;
2213 -- Whether S has already been processed. This marks the source as
2214 -- processed, if it hasn't already been processed.
2216 function Insert_No_Roots (Source : Source_Info) return Boolean;
2217 -- Insert Source, but do not look for its roots (see doc for Insert)
2223 function Was_Processed (S : Source_Info) return Boolean is
2226 when Format_Gprbuild =>
2227 if S.Id.In_The_Queue then
2231 S.Id.In_The_Queue := True;
2233 when Format_Gnatmake =>
2234 if Is_Marked (S.File, S.Index) then
2238 Mark (S.File, Index => S.Index);
2244 -----------------------
2245 -- Available_Obj_Dir --
2246 -----------------------
2248 function Available_Obj_Dir (S : Source_Info) return Boolean is
2251 when Format_Gprbuild =>
2252 return not Busy_Obj_Dirs.Get
2253 (S.Id.Project.Object_Directory.Name);
2255 when Format_Gnatmake =>
2256 return S.Project = No_Project
2258 not Busy_Obj_Dirs.Get (S.Project.Object_Directory.Name);
2260 end Available_Obj_Dir;
2266 procedure Debug_Display (S : Source_Info) is
2269 when Format_Gprbuild =>
2270 Write_Name (S.Id.File);
2272 if S.Id.Index /= 0 then
2274 Write_Int (S.Id.Index);
2277 when Format_Gnatmake =>
2278 Write_Name (S.File);
2280 if S.Index /= 0 then
2282 Write_Int (S.Index);
2291 function Hash (Key : Mark_Key) return Mark_Num is
2293 return Union_Id (Key.File) mod Max_Mask_Num;
2301 (Source_File : File_Name_Type;
2302 Index : Int := 0) return Boolean
2305 return Marks.Get (K => (File => Source_File, Index => Index));
2312 procedure Mark (Source_File : File_Name_Type; Index : Int := 0) is
2314 Marks.Set (K => (File => Source_File, Index => Index), E => True);
2322 (Found : out Boolean;
2323 Source : out Source_Info)
2328 if One_Queue_Per_Obj_Dir then
2329 for J in Q_First .. Q.Last loop
2330 if not Q.Table (J).Processed
2331 and then Available_Obj_Dir (Q.Table (J).Info)
2334 Source := Q.Table (J).Info;
2335 Q.Table (J).Processed := True;
2338 while Q_First <= Q.Last
2339 and then Q.Table (Q_First).Processed
2341 Q_First := Q_First + 1;
2349 elsif Q_First <= Q.Last then
2350 Source := Q.Table (Q_First).Info;
2351 Q.Table (Q_First).Processed := True;
2352 Q_First := Q_First + 1;
2357 Q_Processed := Q_Processed + 1;
2360 if Found and then Debug.Debug_Flag_Q then
2361 Write_Str (" Q := Q - [ ");
2362 Debug_Display (Source);
2366 Write_Str (" Q_First =");
2367 Write_Int (Int (Q_First));
2370 Write_Str (" Q.Last =");
2371 Write_Int (Int (Q.Last));
2380 function Processed return Natural is
2389 procedure Initialize
2390 (Queue_Per_Obj_Dir : Boolean;
2391 Force : Boolean := False)
2394 if Force or else not Q_Initialized then
2395 Q_Initialized := True;
2397 for J in 1 .. Q.Last loop
2398 case Q.Table (J).Info.Format is
2399 when Format_Gprbuild =>
2400 Q.Table (J).Info.Id.In_The_Queue := False;
2401 when Format_Gnatmake =>
2409 One_Queue_Per_Obj_Dir := Queue_Per_Obj_Dir;
2413 ---------------------
2414 -- Insert_No_Roots --
2415 ---------------------
2417 function Insert_No_Roots (Source : Source_Info) return Boolean is
2420 (Source.Format = Format_Gnatmake or else Source.Id /= No_Source);
2422 -- Only insert in the Q if it is not already done, to avoid
2423 -- simultaneous compilations if -jnnn is used.
2425 if Was_Processed (Source) then
2429 if Current_Verbosity = High then
2430 Write_Str ("Adding """);
2431 Debug_Display (Source);
2432 Write_Line (""" to the queue");
2435 Q.Append (New_Val => (Info => Source, Processed => False));
2437 if Debug.Debug_Flag_Q then
2438 Write_Str (" Q := Q + [ ");
2439 Debug_Display (Source);
2443 Write_Str (" Q_First =");
2444 Write_Int (Int (Q_First));
2447 Write_Str (" Q.Last =");
2448 Write_Int (Int (Q.Last));
2453 end Insert_No_Roots;
2460 (Source : Source_Info;
2461 With_Roots : Boolean := False) return Boolean
2463 Root_Arr : Array_Element_Id;
2464 Roots : Variable_Value;
2465 List : String_List_Id;
2466 Elem : String_Element;
2467 Unit_Name : Name_Id;
2469 Root_Pattern : Regexp;
2470 Root_Found : Boolean;
2471 Roots_Found : Boolean;
2472 Root_Source : Prj.Source_Id;
2473 Iter : Source_Iterator;
2476 pragma Unreferenced (Dummy);
2479 if not Insert_No_Roots (Source) then
2481 -- Was already in the queue
2486 if With_Roots and then Source.Format = Format_Gprbuild then
2487 Debug_Output ("looking for roots of", Name_Id (Source.Id.File));
2491 (Name => Name_Roots,
2492 In_Arrays => Source.Id.Project.Decl.Arrays,
2493 Shared => Source.Tree.Shared);
2497 (Index => Name_Id (Source.Id.File),
2499 In_Array => Root_Arr,
2500 Shared => Source.Tree.Shared);
2502 -- If there is no roots for the specific main, try the language
2504 if Roots = Nil_Variable_Value then
2507 (Index => Source.Id.Language.Name,
2509 In_Array => Root_Arr,
2510 Shared => Source.Tree.Shared,
2511 Force_Lower_Case_Index => True);
2516 if Roots = Nil_Variable_Value then
2518 Name_Buffer (1) := '*';
2522 (Index => Name_Find,
2524 In_Array => Root_Arr,
2525 Shared => Source.Tree.Shared,
2526 Force_Lower_Case_Index => True);
2529 if Roots = Nil_Variable_Value then
2530 Debug_Output (" -> no roots declared");
2533 List := Roots.Values;
2536 while List /= Nil_String loop
2537 Elem := Source.Tree.Shared.String_Elements.Table (List);
2538 Get_Name_String (Elem.Value);
2539 To_Lower (Name_Buffer (1 .. Name_Len));
2540 Unit_Name := Name_Find;
2542 -- Check if it is a unit name or a pattern
2546 for J in 1 .. Name_Len loop
2547 if Name_Buffer (J) not in 'a' .. 'z' and then
2548 Name_Buffer (J) not in '0' .. '9' and then
2549 Name_Buffer (J) /= '_' and then
2550 Name_Buffer (J) /= '.'
2561 (Pattern => Name_Buffer (1 .. Name_Len),
2565 when Error_In_Regexp =>
2566 Err_Vars.Error_Msg_Name_1 := Unit_Name;
2568 ("invalid pattern %", Roots.Location);
2573 Roots_Found := False;
2574 Iter := For_Each_Source (Source.Tree);
2578 Root_Source := Prj.Element (Iter);
2579 exit Source_Loop when Root_Source = No_Source;
2581 Root_Found := False;
2583 Root_Found := Root_Source.Unit /= No_Unit_Index
2585 (Get_Name_String (Root_Source.Unit.Name),
2590 Root_Source.Unit /= No_Unit_Index
2591 and then Root_Source.Unit.Name = Unit_Name;
2595 case Root_Source.Kind is
2600 Root_Found := Other_Part (Root_Source) = No_Source;
2603 Root_Found := False;
2608 Roots_Found := True;
2610 (" -> ", Name_Id (Root_Source.Display_File));
2611 Dummy := Queue.Insert_No_Roots
2612 (Source => (Format => Format_Gprbuild,
2613 Tree => Source.Tree,
2614 Id => Root_Source));
2616 Initialize_Source_Record (Root_Source);
2618 if Other_Part (Root_Source) /= No_Source then
2619 Initialize_Source_Record (Other_Part (Root_Source));
2622 -- Save the root for the binder
2624 Source.Id.Roots := new Source_Roots'
2625 (Root => Root_Source,
2626 Next => Source.Id.Roots);
2628 exit Source_Loop when not Pat_Root;
2632 end loop Source_Loop;
2634 if not Roots_Found then
2636 if not Quiet_Output then
2637 Error_Msg_Name_1 := Unit_Name;
2639 ("?no unit matches pattern %", Roots.Location);
2644 ("Unit " & Get_Name_String (Unit_Name)
2645 & " does not exist", Roots.Location);
2650 end loop Pattern_Loop;
2662 (Source : Source_Info;
2663 With_Roots : Boolean := False)
2666 pragma Unreferenced (Discard);
2668 Discard := Insert (Source, With_Roots);
2675 function Is_Empty return Boolean is
2677 return Q_Processed >= Q.Last;
2680 ------------------------
2681 -- Is_Virtually_Empty --
2682 ------------------------
2684 function Is_Virtually_Empty return Boolean is
2686 if One_Queue_Per_Obj_Dir then
2687 for J in Q_First .. Q.Last loop
2688 if not Q.Table (J).Processed
2689 and then Available_Obj_Dir (Q.Table (J).Info)
2700 end Is_Virtually_Empty;
2702 ----------------------
2703 -- Set_Obj_Dir_Busy --
2704 ----------------------
2706 procedure Set_Obj_Dir_Busy (Obj_Dir : Path_Name_Type) is
2708 if One_Queue_Per_Obj_Dir then
2709 Busy_Obj_Dirs.Set (Obj_Dir, True);
2711 end Set_Obj_Dir_Busy;
2713 ----------------------
2714 -- Set_Obj_Dir_Free --
2715 ----------------------
2717 procedure Set_Obj_Dir_Free (Obj_Dir : Path_Name_Type) is
2719 if One_Queue_Per_Obj_Dir then
2720 Busy_Obj_Dirs.Set (Obj_Dir, False);
2722 end Set_Obj_Dir_Free;
2728 function Size return Natural is
2737 function Element (Rank : Positive) return File_Name_Type is
2739 if Rank <= Q.Last then
2740 case Q.Table (Rank).Info.Format is
2741 when Format_Gprbuild =>
2742 return Q.Table (Rank).Info.Id.File;
2743 when Format_Gnatmake =>
2744 return Q.Table (Rank).Info.File;
2755 procedure Remove_Marks is
2760 ----------------------------
2761 -- Insert_Project_Sources --
2762 ----------------------------
2764 procedure Insert_Project_Sources
2765 (Project : Project_Id;
2766 Project_Tree : Project_Tree_Ref;
2767 All_Projects : Boolean;
2768 Unique_Compile : Boolean)
2770 procedure Do_Insert (Project : Project_Id; Tree : Project_Tree_Ref);
2776 procedure Do_Insert (Project : Project_Id; Tree : Project_Tree_Ref) is
2777 Unit_Based : constant Boolean :=
2779 or else not Builder_Data (Tree).Closure_Needed;
2780 -- When Unit_Based is True, put in the queue all compilable
2781 -- sources including the unit based (Ada) one. When Unit_Based is
2782 -- False, put the Ada sources only when they are in a library
2785 Iter : Source_Iterator;
2786 Source : Prj.Source_Id;
2789 -- Nothing to do when "-u" was specified and some files were
2790 -- specified on the command line
2793 and then Mains.Number_Of_Mains (Tree) > 0
2798 Iter := For_Each_Source (Tree);
2800 Source := Prj.Element (Iter);
2801 exit when Source = No_Source;
2803 if Is_Allowed_Language (Source.Language.Name)
2804 and then Is_Compilable (Source)
2807 or else Is_Extending (Project, Source.Project))
2808 and then not Source.Locally_Removed
2809 and then Source.Replaced_By = No_Source
2811 (not Source.Project.Externally_Built
2813 (Is_Extending (Project, Source.Project)
2814 and then not Project.Externally_Built))
2815 and then Source.Kind /= Sep
2816 and then Source.Path /= No_Path_Information
2818 if Source.Kind = Impl
2819 or else (Source.Unit /= No_Unit_Index
2820 and then Source.Kind = Spec
2821 and then (Other_Part (Source) = No_Source
2823 Other_Part (Source).Locally_Removed))
2826 or else Source.Unit = No_Unit_Index
2827 or else Source.Project.Library)
2828 and then not Is_Subunit (Source)
2831 (Source => (Format => Format_Gprbuild,
2842 procedure Insert_All is new For_Project_And_Aggregated (Do_Insert);
2845 Insert_All (Project, Project_Tree);
2846 end Insert_Project_Sources;
2848 -------------------------------
2849 -- Insert_Withed_Sources_For --
2850 -------------------------------
2852 procedure Insert_Withed_Sources_For
2853 (The_ALI : ALI.ALI_Id;
2854 Project_Tree : Project_Tree_Ref;
2855 Excluding_Shared_SALs : Boolean := False)
2857 Sfile : File_Name_Type;
2858 Afile : File_Name_Type;
2859 Src_Id : Prj.Source_Id;
2862 -- Insert in the queue the unmarked source files (i.e. those which
2863 -- have never been inserted in the queue and hence never considered).
2865 for J in ALI.ALIs.Table (The_ALI).First_Unit ..
2866 ALI.ALIs.Table (The_ALI).Last_Unit
2868 for K in ALI.Units.Table (J).First_With ..
2869 ALI.Units.Table (J).Last_With
2871 Sfile := ALI.Withs.Table (K).Sfile;
2875 if Sfile /= No_File then
2876 Afile := ALI.Withs.Table (K).Afile;
2878 Src_Id := Source_Files_Htable.Get
2879 (Project_Tree.Source_Files_HT, Sfile);
2880 while Src_Id /= No_Source loop
2881 Initialize_Source_Record (Src_Id);
2883 if Is_Compilable (Src_Id)
2884 and then Src_Id.Dep_Name = Afile
2889 Bdy : constant Prj.Source_Id :=
2890 Other_Part (Src_Id);
2893 and then not Bdy.Locally_Removed
2895 Src_Id := Other_Part (Src_Id);
2900 if Is_Subunit (Src_Id) then
2901 Src_Id := No_Source;
2905 Src_Id := No_Source;
2911 Src_Id := Src_Id.Next_With_File_Name;
2914 -- If Excluding_Shared_SALs is True, do not insert in the
2915 -- queue the sources of a shared Stand-Alone Library.
2917 if Src_Id /= No_Source
2918 and then (not Excluding_Shared_SALs
2919 or else Src_Id.Project.Standalone_Library = No
2920 or else Src_Id.Project.Library_Kind = Static)
2923 (Source => (Format => Format_Gprbuild,
2924 Tree => Project_Tree,
2930 end Insert_Withed_Sources_For;
2938 procedure Free (Data : in out Builder_Project_Tree_Data) is
2939 procedure Unchecked_Free is new Ada.Unchecked_Deallocation
2940 (Binding_Data_Record, Binding_Data);
2942 TmpB, Binding : Binding_Data := Data.Binding;
2945 while Binding /= null loop
2946 TmpB := Binding.Next;
2947 Unchecked_Free (Binding);
2956 function Builder_Data
2957 (Tree : Project_Tree_Ref) return Builder_Data_Access
2960 if Tree.Appdata = null then
2961 Tree.Appdata := new Builder_Project_Tree_Data;
2964 return Builder_Data_Access (Tree.Appdata);
2967 --------------------------------
2968 -- Compute_Compilation_Phases --
2969 --------------------------------
2971 procedure Compute_Compilation_Phases
2972 (Tree : Project_Tree_Ref;
2973 Root_Project : Project_Id;
2974 Option_Unique_Compile : Boolean := False; -- Was "-u" specified ?
2975 Option_Compile_Only : Boolean := False; -- Was "-c" specified ?
2976 Option_Bind_Only : Boolean := False;
2977 Option_Link_Only : Boolean := False)
2979 procedure Do_Compute (Project : Project_Id; Tree : Project_Tree_Ref);
2985 procedure Do_Compute (Project : Project_Id; Tree : Project_Tree_Ref) is
2986 Data : constant Builder_Data_Access := Builder_Data (Tree);
2987 All_Phases : constant Boolean :=
2988 not Option_Compile_Only
2989 and then not Option_Bind_Only
2990 and then not Option_Link_Only;
2991 -- Whether the command line asked for all three phases. Depending on
2992 -- the project settings, we might still disable some of the phases.
2994 Has_Mains : constant Boolean := Data.Number_Of_Mains > 0;
2995 -- Whether there are some main units defined for this project tree
2996 -- (either from one of the projects, or from the command line)
2999 if Option_Unique_Compile then
3001 -- If -u or -U is specified on the command line, disregard any -c,
3002 -- -b or -l switch: only perform compilation.
3004 Data.Closure_Needed := False;
3005 Data.Need_Compilation := True;
3006 Data.Need_Binding := False;
3007 Data.Need_Linking := False;
3010 Data.Closure_Needed := Has_Mains;
3011 Data.Need_Compilation := All_Phases or Option_Compile_Only;
3012 Data.Need_Binding := All_Phases or Option_Bind_Only;
3013 Data.Need_Linking := (All_Phases or Option_Link_Only)
3017 if Current_Verbosity = High then
3018 Debug_Output ("compilation phases: "
3019 & " compile=" & Data.Need_Compilation'Img
3020 & " bind=" & Data.Need_Binding'Img
3021 & " link=" & Data.Need_Linking'Img
3022 & " closure=" & Data.Closure_Needed'Img
3023 & " mains=" & Data.Number_Of_Mains'Img,
3028 procedure Compute_All is new For_Project_And_Aggregated (Do_Compute);
3031 Compute_All (Root_Project, Tree);
3032 end Compute_Compilation_Phases;
3034 ------------------------------
3035 -- Compute_Builder_Switches --
3036 ------------------------------
3038 procedure Compute_Builder_Switches
3039 (Project_Tree : Project_Tree_Ref;
3040 Root_Environment : in out Prj.Tree.Environment;
3041 Main_Project : Project_Id;
3042 Only_For_Lang : Name_Id := No_Name)
3044 Builder_Package : constant Package_Id :=
3045 Value_Of (Name_Builder, Main_Project.Decl.Packages,
3046 Project_Tree.Shared);
3048 Global_Compilation_Array : Array_Element_Id;
3049 Global_Compilation_Elem : Array_Element;
3050 Global_Compilation_Switches : Variable_Value;
3052 Default_Switches_Array : Array_Id;
3054 Builder_Switches_Lang : Name_Id := No_Name;
3056 List : String_List_Id;
3057 Element : String_Element;
3060 Source : Prj.Source_Id;
3062 Lang : Name_Id := No_Name; -- language index for Switches
3063 Switches_For_Lang : Variable_Value := Nil_Variable_Value;
3064 -- Value of Builder'Default_Switches(lang)
3066 Name : Name_Id := No_Name; -- main file index for Switches
3067 Switches_For_Main : Variable_Value := Nil_Variable_Value;
3068 -- Switches for a specific main. When there are several mains, Name is
3069 -- set to No_Name, and Switches_For_Main might be left with an actual
3070 -- value (so that we can display a warning that it was ignored).
3072 Other_Switches : Variable_Value := Nil_Variable_Value;
3073 -- Value of Builder'Switches(others)
3075 Defaults : Variable_Value := Nil_Variable_Value;
3077 Switches : Variable_Value := Nil_Variable_Value;
3078 -- The computed builder switches
3080 Success : Boolean := False;
3082 if Builder_Package /= No_Package then
3085 -- If there is no main, and there is only one compilable language,
3086 -- use this language as the switches index.
3088 if Mains.Number_Of_Mains (Project_Tree) = 0 then
3089 if Only_For_Lang = No_Name then
3091 Language : Language_Ptr := Main_Project.Languages;
3094 while Language /= No_Language_Index loop
3095 if Language.Config.Compiler_Driver /= No_File
3096 and then Language.Config.Compiler_Driver /= Empty_File
3098 if Lang /= No_Name then
3102 Lang := Language.Name;
3105 Language := Language.Next;
3109 Lang := Only_For_Lang;
3113 for Index in 1 .. Mains.Number_Of_Mains (Project_Tree) loop
3114 Source := Mains.Next_Main.Source;
3116 if Source /= No_Source then
3117 if Switches_For_Main = Nil_Variable_Value then
3118 Switches_For_Main := Value_Of
3119 (Name => Name_Id (Source.File),
3120 Attribute_Or_Array_Name => Name_Switches,
3121 In_Package => Builder_Package,
3122 Shared => Project_Tree.Shared,
3123 Force_Lower_Case_Index => False,
3124 Allow_Wildcards => True);
3126 -- If not found, try without extension.
3127 -- That's because gnatmake accepts truncated file names
3128 -- in Builder'Switches
3130 if Switches_For_Main = Nil_Variable_Value
3131 and then Source.Unit /= null
3133 Switches_For_Main := Value_Of
3134 (Name => Source.Unit.Name,
3135 Attribute_Or_Array_Name => Name_Switches,
3136 In_Package => Builder_Package,
3137 Shared => Project_Tree.Shared,
3138 Force_Lower_Case_Index => False,
3139 Allow_Wildcards => True);
3144 Lang := Source.Language.Name;
3145 Name := Name_Id (Source.File);
3147 Name := No_Name; -- Can't use main specific switches
3149 if Lang /= Source.Language.Name then
3157 Global_Compilation_Array := Value_Of
3158 (Name => Name_Global_Compilation_Switches,
3159 In_Arrays => Project_Tree.Shared.Packages.Table
3160 (Builder_Package).Decl.Arrays,
3161 Shared => Project_Tree.Shared);
3163 Default_Switches_Array :=
3164 Project_Tree.Shared.Packages.Table (Builder_Package).Decl.Arrays;
3166 while Default_Switches_Array /= No_Array
3168 Project_Tree.Shared.Arrays.Table (Default_Switches_Array).Name /=
3169 Name_Default_Switches
3171 Default_Switches_Array :=
3172 Project_Tree.Shared.Arrays.Table (Default_Switches_Array).Next;
3175 if Global_Compilation_Array /= No_Array_Element
3176 and then Default_Switches_Array /= No_Array
3179 (Root_Environment.Flags,
3180 "Default_Switches forbidden in presence of " &
3181 "Global_Compilation_Switches. Use Switches instead.",
3182 Project_Tree.Shared.Arrays.Table
3183 (Default_Switches_Array).Location);
3186 "*** illegal combination of Builder attributes");
3189 if Lang /= No_Name then
3190 Switches_For_Lang := Prj.Util.Value_Of
3193 Attribute_Or_Array_Name => Name_Switches,
3194 In_Package => Builder_Package,
3195 Shared => Project_Tree.Shared,
3196 Force_Lower_Case_Index => True);
3198 Defaults := Prj.Util.Value_Of
3201 Attribute_Or_Array_Name => Name_Default_Switches,
3202 In_Package => Builder_Package,
3203 Shared => Project_Tree.Shared,
3204 Force_Lower_Case_Index => True);
3207 Other_Switches := Prj.Util.Value_Of
3208 (Name => All_Other_Names,
3210 Attribute_Or_Array_Name => Name_Switches,
3211 In_Package => Builder_Package,
3212 Shared => Project_Tree.Shared);
3215 and then Mains.Number_Of_Mains (Project_Tree) > 1
3216 and then Switches_For_Main /= Nil_Variable_Value
3218 -- More than one main, but we had main-specific switches that
3221 if Switches_For_Lang /= Nil_Variable_Value then
3223 ("Warning: using Builder'Switches("""
3224 & Get_Name_String (Lang)
3225 & """), as there are several mains");
3227 elsif Other_Switches /= Nil_Variable_Value then
3229 ("Warning: using Builder'Switches(others), "
3230 & "as there are several mains");
3232 elsif Defaults /= Nil_Variable_Value then
3234 ("Warning: using Builder'Default_Switches("""
3235 & Get_Name_String (Lang)
3236 & """), as there are several mains");
3239 ("Warning: using no switches from package "
3240 & "Builder, as there are several mains");
3244 Builder_Switches_Lang := Lang;
3246 if Name /= No_Name then
3247 -- Get the switches for the single main
3248 Switches := Switches_For_Main;
3251 if Switches = Nil_Variable_Value or else Switches.Default then
3252 -- Get the switches for the common language of the mains
3253 Switches := Switches_For_Lang;
3256 if Switches = Nil_Variable_Value or else Switches.Default then
3257 Switches := Other_Switches;
3260 -- For backward compatibility with gnatmake, if no Switches
3261 -- are declared, check for Default_Switches (<language>).
3263 if Switches = Nil_Variable_Value or else Switches.Default then
3264 Switches := Defaults;
3267 -- If switches have been found, scan them
3269 if Switches /= Nil_Variable_Value and then not Switches.Default then
3270 List := Switches.Values;
3272 while List /= Nil_String loop
3273 Element := Project_Tree.Shared.String_Elements.Table (List);
3274 Get_Name_String (Element.Value);
3276 if Name_Len /= 0 then
3278 -- Add_Switch might itself be using the name_buffer, so
3279 -- we make a temporary here.
3280 Switch : constant String := Name_Buffer (1 .. Name_Len);
3282 Success := Add_Switch
3284 For_Lang => Builder_Switches_Lang,
3285 For_Builder => True,
3286 Has_Global_Compilation_Switches =>
3287 Global_Compilation_Array /= No_Array_Element);
3291 for J in reverse 1 .. Name_Len loop
3292 Name_Buffer (J + J) := Name_Buffer (J);
3293 Name_Buffer (J + J - 1) := ''';
3296 Name_Len := Name_Len + Name_Len;
3299 (Root_Environment.Flags,
3300 '"' & Name_Buffer (1 .. Name_Len) &
3301 """ is not a builder switch. Consider moving " &
3302 "it to Global_Compilation_Switches.",
3306 "*** illegal switch """ &
3307 Get_Name_String (Element.Value) & '"');
3311 List := Element.Next;
3315 -- Reset the Builder Switches language
3317 Builder_Switches_Lang := No_Name;
3319 -- Take into account attributes Global_Compilation_Switches
3321 while Global_Compilation_Array /= No_Array_Element loop
3322 Global_Compilation_Elem :=
3323 Project_Tree.Shared.Array_Elements.Table
3324 (Global_Compilation_Array);
3326 Get_Name_String (Global_Compilation_Elem.Index);
3327 To_Lower (Name_Buffer (1 .. Name_Len));
3330 if Only_For_Lang = No_Name or else Index = Only_For_Lang then
3331 Global_Compilation_Switches := Global_Compilation_Elem.Value;
3333 if Global_Compilation_Switches /= Nil_Variable_Value
3334 and then not Global_Compilation_Switches.Default
3336 -- We have found an attribute
3337 -- Global_Compilation_Switches for a language: put the
3338 -- switches in the appropriate table.
3340 List := Global_Compilation_Switches.Values;
3341 while List /= Nil_String loop
3343 Project_Tree.Shared.String_Elements.Table (List);
3345 if Element.Value /= No_Name then
3346 Success := Add_Switch
3347 (Switch => Get_Name_String (Element.Value),
3349 For_Builder => False,
3350 Has_Global_Compilation_Switches =>
3351 Global_Compilation_Array /= No_Array_Element);
3354 List := Element.Next;
3359 Global_Compilation_Array := Global_Compilation_Elem.Next;
3362 end Compute_Builder_Switches;
3364 ---------------------
3365 -- Write_Path_File --
3366 ---------------------
3368 procedure Write_Path_File (FD : File_Descriptor) is
3375 for Index in Directories.First .. Directories.Last loop
3376 Add_Str_To_Name_Buffer (Get_Name_String (Directories.Table (Index)));
3377 Add_Char_To_Name_Buffer (ASCII.LF);
3380 Last := Write (FD, Name_Buffer (1)'Address, Name_Len);
3382 if Last = Name_Len then
3389 Prj.Com.Fail ("could not write temporary file");
3391 end Write_Path_File;