1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2004-2013, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
27 with Atree
; use Atree
;
29 with Err_Vars
; use Err_Vars
;
33 with Osint
; use Osint
;
34 with Output
; use Output
;
39 with Prj
.Util
; use Prj
.Util
;
43 with Ada
.Command_Line
; use Ada
.Command_Line
;
44 with Ada
.Unchecked_Deallocation
;
46 with GNAT
.Case_Util
; use GNAT
.Case_Util
;
47 with GNAT
.Directory_Operations
; use GNAT
.Directory_Operations
;
49 with GNAT
.Regexp
; use GNAT
.Regexp
;
51 package body Makeutl
is
53 type Linker_Options_Data
is record
55 Options
: String_List_Id
;
58 Linker_Option_Initial_Count
: constant := 20;
60 Linker_Options_Buffer
: String_List_Access
:=
61 new String_List
(1 .. Linker_Option_Initial_Count
);
63 Last_Linker_Option
: Natural := 0;
65 package Linker_Opts
is new Table
.Table
(
66 Table_Component_Type
=> Linker_Options_Data
,
67 Table_Index_Type
=> Integer,
70 Table_Increment
=> 100,
71 Table_Name
=> "Make.Linker_Opts");
73 procedure Add_Linker_Option
(Option
: String);
80 (Option
: String_Access
;
81 To
: in out String_List_Access
;
82 Last
: in out Natural)
85 if Last
= To
'Last then
87 New_Options
: constant String_List_Access
:=
88 new String_List
(1 .. To
'Last * 2);
91 New_Options
(To
'Range) := To
.all;
93 -- Set all elements of the original options to null to avoid
94 -- deallocation of copies.
96 To
.all := (others => null);
109 To
: in out String_List_Access
;
110 Last
: in out Natural)
113 Add
(Option
=> new String'(Option), To => To, Last => Last);
116 -----------------------
117 -- Add_Linker_Option --
118 -----------------------
120 procedure Add_Linker_Option (Option : String) is
122 if Option'Length > 0 then
123 if Last_Linker_Option = Linker_Options_Buffer'Last then
125 New_Buffer : constant String_List_Access :=
127 (1 .. Linker_Options_Buffer'Last +
128 Linker_Option_Initial_Count);
130 New_Buffer (Linker_Options_Buffer'Range) :=
131 Linker_Options_Buffer.all;
132 Linker_Options_Buffer.all := (others => null);
133 Free (Linker_Options_Buffer);
134 Linker_Options_Buffer := New_Buffer;
138 Last_Linker_Option := Last_Linker_Option + 1;
139 Linker_Options_Buffer (Last_Linker_Option) := new String'(Option
);
141 end Add_Linker_Option
;
147 function Absolute_Path
148 (Path
: Path_Name_Type
;
149 Project
: Project_Id
) return String
152 Get_Name_String
(Path
);
155 Path_Name
: constant String := Name_Buffer
(1 .. Name_Len
);
158 if Is_Absolute_Path
(Path_Name
) then
163 Parent_Directory
: constant String :=
165 (Project
.Directory
.Display_Name
);
168 return Parent_Directory
& Path_Name
;
174 -------------------------
175 -- Base_Name_Index_For --
176 -------------------------
178 function Base_Name_Index_For
181 Index_Separator
: Character) return File_Name_Type
183 Result
: File_Name_Type
;
187 Add_Str_To_Name_Buffer
(Base_Name
(Main
));
189 -- Remove the extension, if any, that is the last part of the base name
190 -- starting with a dot and following some characters.
192 for J
in reverse 2 .. Name_Len
loop
193 if Name_Buffer
(J
) = '.' then
199 -- Add the index info, if index is different from 0
201 if Main_Index
> 0 then
202 Add_Char_To_Name_Buffer
(Index_Separator
);
205 Img
: constant String := Main_Index
'Img;
207 Add_Str_To_Name_Buffer
(Img
(2 .. Img
'Last));
213 end Base_Name_Index_For
;
215 ------------------------------
216 -- Check_Source_Info_In_ALI --
217 ------------------------------
219 function Check_Source_Info_In_ALI
221 Tree
: Project_Tree_Ref
) return Name_Id
223 Result
: Name_Id
:= No_Name
;
227 -- Loop through units
229 for U
in ALIs
.Table
(The_ALI
).First_Unit
..
230 ALIs
.Table
(The_ALI
).Last_Unit
232 -- Check if the file name is one of the source of the unit
234 Get_Name_String
(Units
.Table
(U
).Uname
);
235 Name_Len
:= Name_Len
- 2;
236 Unit_Name
:= Name_Find
;
238 if File_Not_A_Source_Of
(Tree
, Unit_Name
, Units
.Table
(U
).Sfile
) then
242 if Result
= No_Name
then
246 -- Loop to do same check for each of the withed units
248 for W
in Units
.Table
(U
).First_With
.. Units
.Table
(U
).Last_With
loop
250 WR
: ALI
.With_Record
renames Withs
.Table
(W
);
253 if WR
.Sfile
/= No_File
then
254 Get_Name_String
(WR
.Uname
);
255 Name_Len
:= Name_Len
- 2;
256 Unit_Name
:= Name_Find
;
258 if File_Not_A_Source_Of
(Tree
, Unit_Name
, WR
.Sfile
) then
266 -- Loop to check subunits and replaced sources
268 for D
in ALIs
.Table
(The_ALI
).First_Sdep
..
269 ALIs
.Table
(The_ALI
).Last_Sdep
272 SD
: Sdep_Record
renames Sdep
.Table
(D
);
275 Unit_Name
:= SD
.Subunit_Name
;
277 if Unit_Name
= No_Name
then
279 -- Check if this source file has been replaced by a source with
280 -- a different file name.
282 if Tree
/= null and then Tree
.Replaced_Source_Number
> 0 then
284 Replacement
: constant File_Name_Type
:=
285 Replaced_Source_HTable
.Get
286 (Tree
.Replaced_Sources
, SD
.Sfile
);
289 if Replacement
/= No_File
then
293 Get_Name_String
(SD
.Sfile
) &
294 " has been replaced by " &
295 Get_Name_String
(Replacement
));
304 -- For separates, the file is no longer associated with the
305 -- unit ("proc-sep.adb" is not associated with unit "proc.sep")
306 -- so we need to check whether the source file still exists in
307 -- the source tree: it will if it matches the naming scheme
308 -- (and then will be for the same unit).
312 Project
=> No_Project
,
313 Base_Name
=> SD
.Sfile
) = No_Source
315 -- If this is not a runtime file or if, when gnatmake switch
316 -- -a is used, we are not able to find this subunit in the
317 -- source directories, then recompilation is needed.
319 if not Fname
.Is_Internal_File_Name
(SD
.Sfile
)
321 (Check_Readonly_Files
322 and then Full_Source_Name
(SD
.Sfile
) = No_File
)
326 ("While parsing ALI file, file "
327 & Get_Name_String
(SD
.Sfile
)
328 & " is indicated as containing subunit "
329 & Get_Name_String
(Unit_Name
)
330 & " but this does not match what was found while"
331 & " parsing the project. Will recompile");
342 end Check_Source_Info_In_ALI
;
344 --------------------------------
345 -- Create_Binder_Mapping_File --
346 --------------------------------
348 function Create_Binder_Mapping_File
349 (Project_Tree
: Project_Tree_Ref
) return Path_Name_Type
351 Mapping_Path
: Path_Name_Type
:= No_Path
;
353 Mapping_FD
: File_Descriptor
:= Invalid_FD
;
354 -- A File Descriptor for an eventual mapping file
356 ALI_Unit
: Unit_Name_Type
:= No_Unit_Name
;
357 -- The unit name of an ALI file
359 ALI_Name
: File_Name_Type
:= No_File
;
360 -- The file name of the ALI file
362 ALI_Project
: Project_Id
:= No_Project
;
363 -- The project of the ALI file
366 OK
: Boolean := False;
372 Iter
: Source_Iterator
:= For_Each_Source
373 (In_Tree
=> Project_Tree
,
374 Language
=> Name_Ada
,
375 Encapsulated_Libs
=> False,
376 Locally_Removed
=> False);
378 Source
: Prj
.Source_Id
;
381 Tempdir
.Create_Temp_File
(Mapping_FD
, Mapping_Path
);
382 Record_Temp_File
(Project_Tree
.Shared
, Mapping_Path
);
384 if Mapping_FD
/= Invalid_FD
then
388 Source
:= Element
(Iter
);
389 exit when Source
= No_Source
;
393 if Source
.Replaced_By
/= No_Source
394 or else Unit
= No_Unit_Index
395 or else Unit
.Name
= No_Name
399 -- If this is a body, put it in the mapping
401 elsif Source
.Kind
= Impl
402 and then Unit
.File_Names
(Impl
) /= No_Source
403 and then Unit
.File_Names
(Impl
).Project
/= No_Project
405 Get_Name_String
(Unit
.Name
);
406 Add_Str_To_Name_Buffer
("%b");
407 ALI_Unit
:= Name_Find
;
409 Lib_File_Name
(Unit
.File_Names
(Impl
).Display_File
);
410 ALI_Project
:= Unit
.File_Names
(Impl
).Project
;
412 -- Otherwise, if this is a spec and there is no body, put it in
415 elsif Source
.Kind
= Spec
416 and then Unit
.File_Names
(Impl
) = No_Source
417 and then Unit
.File_Names
(Spec
) /= No_Source
418 and then Unit
.File_Names
(Spec
).Project
/= No_Project
420 Get_Name_String
(Unit
.Name
);
421 Add_Str_To_Name_Buffer
("%s");
422 ALI_Unit
:= Name_Find
;
424 Lib_File_Name
(Unit
.File_Names
(Spec
).Display_File
);
425 ALI_Project
:= Unit
.File_Names
(Spec
).Project
;
431 -- If we have something to put in the mapping then do it now. If
432 -- the project is extended, look for the ALI file in the project,
433 -- then in the extending projects in order, and use the last one
436 if ALI_Name
/= No_File
then
438 -- Look in the project and the projects that are extending it
439 -- to find the real ALI file.
442 ALI
: constant String := Get_Name_String
(ALI_Name
);
443 ALI_Path
: Name_Id
:= No_Name
;
447 -- For library projects, use the library ALI directory,
448 -- for other projects, use the object directory.
450 if ALI_Project
.Library
then
452 (ALI_Project
.Library_ALI_Dir
.Display_Name
);
455 (ALI_Project
.Object_Directory
.Display_Name
);
458 Add_Str_To_Name_Buffer
(ALI
);
460 if Is_Regular_File
(Name_Buffer
(1 .. Name_Len
)) then
461 ALI_Path
:= Name_Find
;
464 ALI_Project
:= ALI_Project
.Extended_By
;
465 exit when ALI_Project
= No_Project
;
468 if ALI_Path
/= No_Name
then
470 -- First line is the unit name
472 Get_Name_String
(ALI_Unit
);
473 Add_Char_To_Name_Buffer
(ASCII
.LF
);
477 Name_Buffer
(1)'Address,
479 OK
:= Bytes
= Name_Len
;
483 -- Second line is the ALI file name
485 Get_Name_String
(ALI_Name
);
486 Add_Char_To_Name_Buffer
(ASCII
.LF
);
490 Name_Buffer
(1)'Address,
492 OK
:= (Bytes
= Name_Len
);
496 -- Third line is the ALI path name
498 Get_Name_String
(ALI_Path
);
499 Add_Char_To_Name_Buffer
(ASCII
.LF
);
503 Name_Buffer
(1)'Address,
505 OK
:= (Bytes
= Name_Len
);
507 -- If OK is False, it means we were unable to write a
508 -- line. No point in continuing with the other units.
518 Close
(Mapping_FD
, Status
);
523 -- If the creation of the mapping file was successful, we add the switch
524 -- to the arguments of gnatbind.
532 end Create_Binder_Mapping_File
;
538 function Create_Name
(Name
: String) return File_Name_Type
is
541 Add_Str_To_Name_Buffer
(Name
);
545 function Create_Name
(Name
: String) return Name_Id
is
548 Add_Str_To_Name_Buffer
(Name
);
552 function Create_Name
(Name
: String) return Path_Name_Type
is
555 Add_Str_To_Name_Buffer
(Name
);
559 ---------------------------
560 -- Ensure_Absolute_Path --
561 ---------------------------
563 procedure Ensure_Absolute_Path
564 (Switch
: in out String_Access
;
567 For_Gnatbind
: Boolean := False;
568 Including_Non_Switch
: Boolean := True;
569 Including_RTS
: Boolean := False)
572 if Switch
/= null then
574 Sw
: String (1 .. Switch
'Length);
582 and then (Sw
(2) = 'I'
583 or else (not For_Gnatbind
584 and then (Sw
(2) = 'L'
595 and then (Sw
(2 .. 3) = "aL"
601 (For_Gnatbind
and then Sw
(2 .. 3) = "A="))
606 and then Sw
'Length >= 7
607 and then Sw
(2 .. 6) = "-RTS="
615 -- Because relative path arguments to --RTS= may be relative to
616 -- the search directory prefix, those relative path arguments
617 -- are converted only when they include directory information.
619 if not Is_Absolute_Path
(Sw
(Start
.. Sw
'Last)) then
620 if Parent
'Length = 0 then
622 ("relative search path switches ("""
624 & """) are not allowed");
626 elsif Including_RTS
then
627 for J
in Start
.. Sw
'Last loop
628 if Sw
(J
) = Directory_Separator
then
631 (Sw (1 .. Start - 1) &
633 Directory_Separator &
634 Sw (Start .. Sw'Last));
642 (Sw
(1 .. Start
- 1) &
644 Directory_Separator
&
645 Sw
(Start
.. Sw
'Last));
649 elsif Including_Non_Switch
then
650 if not Is_Absolute_Path
(Sw
) then
651 if Parent
'Length = 0 then
653 ("relative paths (""" & Sw
& """) are not allowed");
655 Switch
:= new String'(Parent & Directory_Separator & Sw);
661 end Ensure_Absolute_Path;
663 ----------------------------
664 -- Executable_Prefix_Path --
665 ----------------------------
667 function Executable_Prefix_Path return String is
668 Exec_Name : constant String := Command_Name;
670 function Get_Install_Dir (S : String) return String;
671 -- S is the executable name preceded by the absolute or relative path,
672 -- e.g. "c:\usr\bin\gcc.exe". Returns the absolute directory where "bin"
673 -- lies (in the example "C:\usr"). If the executable is not in a "bin"
674 -- directory, return "".
676 ---------------------
677 -- Get_Install_Dir --
678 ---------------------
680 function Get_Install_Dir (S : String) return String is
682 Path_Last : Integer := 0;
685 for J in reverse Exec'Range loop
686 if Exec (J) = Directory_Separator then
692 if Path_Last >= Exec'First + 2 then
693 To_Lower (Exec (Path_Last - 2 .. Path_Last));
696 if Path_Last < Exec'First + 2
697 or else Exec (Path_Last - 2 .. Path_Last) /= "bin"
698 or else (Path_Last - 3 >= Exec'First
699 and then Exec (Path_Last - 3) /= Directory_Separator)
704 return Normalize_Pathname
705 (Exec (Exec'First .. Path_Last - 4),
706 Resolve_Links => Opt.Follow_Links_For_Dirs)
707 & Directory_Separator;
710 -- Beginning of Executable_Prefix_Path
713 -- For VMS, the path returned is always /gnu/
715 if Hostparm.OpenVMS then
719 -- First determine if a path prefix was placed in front of the
722 for J in reverse Exec_Name'Range loop
723 if Exec_Name (J) = Directory_Separator then
724 return Get_Install_Dir (Exec_Name);
728 -- If we get here, the user has typed the executable name with no
732 Path : String_Access := Locate_Exec_On_Path (Exec_Name);
738 Dir : constant String := Get_Install_Dir (Path.all);
745 end Executable_Prefix_Path;
751 procedure Fail_Program
752 (Project_Tree : Project_Tree_Ref;
754 Flush_Messages : Boolean := True)
757 if Flush_Messages then
758 if Total_Errors_Detected /= 0 or else Warnings_Detected /= 0 then
763 Finish_Program (Project_Tree, E_Fatal, S => S);
770 procedure Finish_Program
771 (Project_Tree : Project_Tree_Ref;
772 Exit_Code : Osint.Exit_Code_Type := Osint.E_Success;
776 if not Debug.Debug_Flag_N then
777 Delete_Temp_Config_Files (Project_Tree);
779 if Project_Tree /= null then
780 Delete_All_Temp_Files (Project_Tree.Shared);
785 if Exit_Code /= E_Success then
792 -- Output Namet statistics
796 Exit_Program (Exit_Code);
799 --------------------------
800 -- File_Not_A_Source_Of --
801 --------------------------
803 function File_Not_A_Source_Of
804 (Project_Tree : Project_Tree_Ref;
806 Sfile : File_Name_Type) return Boolean
808 Unit : constant Unit_Index :=
809 Units_Htable.Get (Project_Tree.Units_HT, Uname);
811 At_Least_One_File : Boolean := False;
814 if Unit /= No_Unit_Index then
815 for F in Unit.File_Names'Range loop
816 if Unit.File_Names (F) /= null then
817 At_Least_One_File := True;
818 if Unit.File_Names (F).File = Sfile then
824 if not At_Least_One_File then
826 -- The unit was probably created initially for a separate unit
827 -- (which are initially created as IMPL when both suffixes are the
828 -- same). Later on, Override_Kind changed the type of the file,
829 -- and the unit is no longer valid in fact.
834 Verbose_Msg (Uname, "sources do not include ", Name_Id (Sfile));
839 end File_Not_A_Source_Of;
841 ---------------------
842 -- Get_Directories --
843 ---------------------
845 procedure Get_Directories
846 (Project_Tree : Project_Tree_Ref;
847 For_Project : Project_Id;
848 Activity : Activity_Type;
849 Languages : Name_Ids)
852 procedure Recursive_Add
853 (Project : Project_Id;
854 Tree : Project_Tree_Ref;
855 Extended : in out Boolean);
856 -- Add all the source directories of a project to the path only if
857 -- this project has not been visited. Calls itself recursively for
858 -- projects being extended, and imported projects.
860 procedure Add_Dir (Value : Path_Name_Type);
861 -- Add directory Value in table Directories, if it is defined and not
868 procedure Add_Dir (Value : Path_Name_Type) is
869 Add_It : Boolean := True;
872 if Value /= No_Path then
873 for Index in 1 .. Directories.Last loop
874 if Directories.Table (Index) = Value then
881 Directories.Increment_Last;
882 Directories.Table (Directories.Last) := Value;
891 procedure Recursive_Add
892 (Project : Project_Id;
893 Tree : Project_Tree_Ref;
894 Extended : in out Boolean)
896 Current : String_List_Id;
897 Dir : String_Element;
898 OK : Boolean := False;
899 Lang_Proc : Language_Ptr := Project.Languages;
902 -- Add to path all directories of this project
904 if Activity = Compilation then
906 while Lang_Proc /= No_Language_Index loop
907 for J in Languages'Range loop
908 OK := Lang_Proc.Name = Languages (J);
909 exit Lang_Loop when OK;
912 Lang_Proc := Lang_Proc.Next;
916 Current := Project.Source_Dirs;
918 while Current /= Nil_String loop
919 Dir := Tree.Shared.String_Elements.Table (Current);
920 Add_Dir (Path_Name_Type (Dir.Value));
925 elsif Project.Library then
926 if Activity = SAL_Binding and then Extended then
927 Add_Dir (Project.Object_Directory.Display_Name);
930 Add_Dir (Project.Library_ALI_Dir.Display_Name);
934 Add_Dir (Project.Object_Directory.Display_Name);
937 if Project.Extends = No_Project then
942 procedure For_All_Projects is
943 new For_Every_Project_Imported (Boolean, Recursive_Add);
945 Extended : Boolean := True;
947 -- Start of processing for Get_Directories
951 For_All_Projects (For_Project, Project_Tree, Extended);
958 procedure Get_Switches
959 (Source : Prj.Source_Id;
961 Project_Tree : Project_Tree_Ref;
962 Value : out Variable_Value;
963 Is_Default : out Boolean)
967 (Source_File => Source.File,
968 Source_Lang => Source.Language.Name,
969 Source_Prj => Source.Project,
970 Pkg_Name => Pkg_Name,
971 Project_Tree => Project_Tree,
973 Is_Default => Is_Default);
980 procedure Get_Switches
981 (Source_File : File_Name_Type;
982 Source_Lang : Name_Id;
983 Source_Prj : Project_Id;
985 Project_Tree : Project_Tree_Ref;
986 Value : out Variable_Value;
987 Is_Default : out Boolean;
988 Test_Without_Suffix : Boolean := False;
989 Check_ALI_Suffix : Boolean := False)
991 Project : constant Project_Id :=
992 Ultimate_Extending_Project_Of (Source_Prj);
993 Pkg : constant Package_Id :=
996 In_Packages => Project.Decl.Packages,
997 Shared => Project_Tree.Shared);
1001 Is_Default := False;
1003 if Source_File /= No_File then
1004 Value := Prj.Util.Value_Of
1005 (Name => Name_Id (Source_File),
1006 Attribute_Or_Array_Name => Name_Switches,
1008 Shared => Project_Tree.Shared,
1009 Allow_Wildcards => True);
1012 if Value = Nil_Variable_Value and then Test_Without_Suffix then
1014 Get_Language_From_Name (Project, Get_Name_String (Source_Lang));
1016 if Lang /= null then
1018 Naming : Lang_Naming_Data renames Lang.Config.Naming_Data;
1019 SF_Name : constant String := Get_Name_String (Source_File);
1020 Last : Positive := SF_Name'Length;
1021 Name : String (1 .. Last + 3);
1022 Spec_Suffix : String := Get_Name_String (Naming.Spec_Suffix);
1023 Body_Suffix : String := Get_Name_String (Naming.Body_Suffix);
1024 Truncated : Boolean := False;
1027 Canonical_Case_File_Name (Spec_Suffix);
1028 Canonical_Case_File_Name (Body_Suffix);
1029 Name (1 .. Last) := SF_Name;
1031 if Last > Body_Suffix'Length
1033 Name (Last - Body_Suffix'Length + 1 .. Last) = Body_Suffix
1036 Last := Last - Body_Suffix'Length;
1040 and then Last > Spec_Suffix'Length
1042 Name (Last - Spec_Suffix'Length + 1 .. Last) = Spec_Suffix
1045 Last := Last - Spec_Suffix'Length;
1050 Add_Str_To_Name_Buffer (Name (1 .. Last));
1052 Value := Prj.Util.Value_Of
1054 Attribute_Or_Array_Name => Name_Switches,
1056 Shared => Project_Tree.Shared,
1057 Allow_Wildcards => True);
1060 if Value = Nil_Variable_Value and then Check_ALI_Suffix then
1061 Last := SF_Name'Length;
1062 while Name (Last) /= '.' loop
1067 Add_Str_To_Name_Buffer (Name (1 .. Last));
1068 Add_Str_To_Name_Buffer ("ali");
1070 Value := Prj.Util.Value_Of
1072 Attribute_Or_Array_Name => Name_Switches,
1074 Shared => Project_Tree.Shared,
1075 Allow_Wildcards => True);
1081 if Value = Nil_Variable_Value then
1085 (Name => Source_Lang,
1086 Attribute_Or_Array_Name => Name_Switches,
1088 Shared => Project_Tree.Shared,
1089 Force_Lower_Case_Index => True);
1092 if Value = Nil_Variable_Value then
1095 (Name => All_Other_Names,
1096 Attribute_Or_Array_Name => Name_Switches,
1098 Shared => Project_Tree.Shared,
1099 Force_Lower_Case_Index => True);
1102 if Value = Nil_Variable_Value then
1105 (Name => Source_Lang,
1106 Attribute_Or_Array_Name => Name_Default_Switches,
1108 Shared => Project_Tree.Shared);
1116 procedure Inform (N : File_Name_Type; Msg : String) is
1118 Inform (Name_Id (N), Msg);
1121 procedure Inform (N : Name_Id := No_Name; Msg : String) is
1123 Osint.Write_Program_Name;
1127 if N /= No_Name then
1131 Name : constant String := Get_Name_String (N);
1133 if Debug.Debug_Flag_F and then Is_Absolute_Path (Name) then
1134 Write_Str (File_Name (Name));
1147 ------------------------------
1148 -- Initialize_Source_Record --
1149 ------------------------------
1151 procedure Initialize_Source_Record (Source : Prj.Source_Id) is
1153 procedure Set_Object_Project
1155 Obj_Proj : Project_Id;
1156 Obj_Path : Path_Name_Type;
1157 Stamp : Time_Stamp_Type);
1158 -- Update information about object file, switches file,...
1160 ------------------------
1161 -- Set_Object_Project --
1162 ------------------------
1164 procedure Set_Object_Project
1166 Obj_Proj : Project_Id;
1167 Obj_Path : Path_Name_Type;
1168 Stamp : Time_Stamp_Type) is
1170 Source.Object_Project := Obj_Proj;
1171 Source.Object_Path := Obj_Path;
1172 Source.Object_TS := Stamp;
1174 if Source.Language.Config.Dependency_Kind /= None then
1176 Dep_Path : constant String :=
1179 Get_Name_String (Source.Dep_Name),
1180 Resolve_Links => Opt.Follow_Links_For_Files,
1181 Directory => Obj_Dir);
1183 Source.Dep_Path := Create_Name (Dep_Path);
1184 Source.Dep_TS := Osint.Unknown_Attributes;
1188 -- Get the path of the switches file, even if Opt.Check_Switches is
1189 -- not set, as switch -s may be in the Builder switches that have not
1190 -- been scanned yet.
1193 Switches_Path : constant String :=
1196 Get_Name_String (Source.Switches),
1197 Resolve_Links => Opt.Follow_Links_For_Files,
1198 Directory => Obj_Dir);
1200 Source.Switches_Path := Create_Name (Switches_Path);
1202 if Stamp /= Empty_Time_Stamp then
1203 Source.Switches_TS := File_Stamp (Source.Switches_Path);
1206 end Set_Object_Project;
1208 Obj_Proj : Project_Id;
1211 -- Nothing to do if source record has already been fully initialized
1213 if Source.Initialized then
1217 -- Systematically recompute the time stamp
1219 Source.Source_TS := File_Stamp (Source.Path.Display_Name);
1221 -- Parse the source file to check whether we have a subunit
1223 if Source.Language.Config.Kind = Unit_Based
1224 and then Source.Kind = Impl
1225 and then Is_Subunit (Source)
1230 if Source.Language.Config.Object_Generated
1231 and then Is_Compilable (Source)
1233 -- First, get the correct object file name and dependency file name
1234 -- if the source is in a multi-unit file.
1236 if Source.Index /= 0 then
1239 (Source_File_Name => Source.File,
1240 Source_Index => Source.Index,
1242 Source.Language.Config.Multi_Unit_Object_Separator,
1243 Object_File_Suffix =>
1244 Source.Language.Config.Object_File_Suffix);
1248 (Source.Object, Source.Language.Config.Dependency_Kind);
1251 -- Find the object file for that source. It could be either in the
1252 -- current project or in an extended project (it might actually not
1253 -- exist yet in the ultimate extending project, but if not found
1254 -- elsewhere that's where we'll expect to find it).
1256 Obj_Proj := Source.Project;
1258 while Obj_Proj /= No_Project loop
1259 if Obj_Proj.Object_Directory /= No_Path_Information then
1261 Dir : constant String :=
1262 Get_Name_String (Obj_Proj.Object_Directory.Display_Name);
1264 Object_Path : constant String :=
1266 (Name => Get_Name_String (Source.Object),
1267 Resolve_Links => Opt.Follow_Links_For_Files,
1270 Obj_Path : constant Path_Name_Type :=
1271 Create_Name (Object_Path);
1273 Stamp : Time_Stamp_Type := Empty_Time_Stamp;
1276 -- For specs, we do not check object files if there is a
1277 -- body. This saves a system call. On the other hand, we do
1278 -- need to know the object_path, in case the user has passed
1279 -- the .ads on the command line to compile the spec only.
1281 if Source.Kind /= Spec
1282 or else Source.Unit = No_Unit_Index
1283 or else Source.Unit.File_Names (Impl) = No_Source
1285 Stamp := File_Stamp (Obj_Path);
1288 if Stamp /= Empty_Time_Stamp
1289 or else (Obj_Proj.Extended_By = No_Project
1290 and then Source.Object_Project = No_Project)
1292 Set_Object_Project (Dir, Obj_Proj, Obj_Path, Stamp);
1297 Obj_Proj := Obj_Proj.Extended_By;
1300 elsif Source.Language.Config.Dependency_Kind = Makefile then
1302 Object_Dir : constant String :=
1303 Get_Name_String (Source.Project.Object_Directory.Display_Name);
1304 Dep_Path : constant String :=
1306 (Name => Get_Name_String (Source.Dep_Name),
1307 Resolve_Links => Opt.Follow_Links_For_Files,
1308 Directory => Object_Dir);
1310 Source.Dep_Path := Create_Name (Dep_Path);
1311 Source.Dep_TS := Osint.Unknown_Attributes;
1315 Source.Initialized := True;
1316 end Initialize_Source_Record;
1318 ----------------------------
1319 -- Is_External_Assignment --
1320 ----------------------------
1322 function Is_External_Assignment
1323 (Env : Prj.Tree.Environment;
1324 Argv : String) return Boolean
1326 Start : Positive := 3;
1327 Finish : Natural := Argv'Last;
1329 pragma Assert (Argv'First = 1);
1330 pragma Assert (Argv (1 .. 2) = "-X");
1333 if Argv'Last < 5 then
1336 elsif Argv (3) = '"' then
1337 if Argv (Argv'Last) /= '"' or else Argv'Last < 7 then
1341 Finish := Argv'Last - 1;
1345 return Prj.Ext.Check
1346 (Self => Env.External,
1347 Declaration => Argv (Start .. Finish));
1348 end Is_External_Assignment;
1354 function Is_Subunit (Source : Prj.Source_Id) return Boolean is
1355 Src_Ind : Source_File_Index;
1358 if Source.Kind = Sep then
1361 -- A Spec, a file based language source or a body with a spec cannot be
1364 elsif Source.Kind = Spec
1365 or else Source.Unit = No_Unit_Index
1366 or else Other_Part (Source) /= No_Source
1371 -- Here, we are assuming that the language is Ada, as it is the only
1372 -- unit based language that we know.
1375 Sinput.P.Load_Project_File
1376 (Get_Name_String (Source.Path.Display_Name));
1378 return Sinput.P.Source_File_Is_Subunit (Src_Ind);
1381 -----------------------------
1382 -- Linker_Options_Switches --
1383 -----------------------------
1385 function Linker_Options_Switches
1386 (Project : Project_Id;
1387 Do_Fail : Fail_Proc;
1388 In_Tree : Project_Tree_Ref) return String_List
1390 procedure Recursive_Add
1392 In_Tree : Project_Tree_Ref;
1393 Dummy : in out Boolean);
1394 -- The recursive routine used to add linker options
1400 procedure Recursive_Add
1402 In_Tree : Project_Tree_Ref;
1403 Dummy : in out Boolean)
1405 pragma Unreferenced (Dummy);
1407 Linker_Package : Package_Id;
1408 Options : Variable_Value;
1413 (Name => Name_Linker,
1414 In_Packages => Proj.Decl.Packages,
1415 Shared => In_Tree.Shared);
1421 Attribute_Or_Array_Name => Name_Linker_Options,
1422 In_Package => Linker_Package,
1423 Shared => In_Tree.Shared);
1425 -- If attribute is present, add the project with the attribute to
1426 -- table Linker_Opts.
1428 if Options /= Nil_Variable_Value then
1429 Linker_Opts.Increment_Last;
1430 Linker_Opts.Table (Linker_Opts.Last) :=
1431 (Project => Proj, Options => Options.Values);
1435 procedure For_All_Projects is
1436 new For_Every_Project_Imported (Boolean, Recursive_Add);
1438 Dummy : Boolean := False;
1440 -- Start of processing for Linker_Options_Switches
1445 For_All_Projects (Project, In_Tree, Dummy, Imported_First => True);
1447 Last_Linker_Option := 0;
1449 for Index in reverse 1 .. Linker_Opts.Last loop
1451 Options : String_List_Id;
1452 Proj : constant Project_Id :=
1453 Linker_Opts.Table (Index).Project;
1455 Dir_Path : constant String :=
1456 Get_Name_String (Proj.Directory.Name);
1459 Options := Linker_Opts.Table (Index).Options;
1460 while Options /= Nil_String loop
1461 Option := In_Tree.Shared.String_Elements.Table (Options).Value;
1462 Get_Name_String (Option);
1464 -- Do not consider empty linker options
1466 if Name_Len /= 0 then
1467 Add_Linker_Option (Name_Buffer (1 .. Name_Len));
1469 -- Object files and -L switches specified with relative
1470 -- paths must be converted to absolute paths.
1472 Ensure_Absolute_Path
1474 Linker_Options_Buffer (Last_Linker_Option),
1477 For_Gnatbind => False);
1480 Options := In_Tree.Shared.String_Elements.Table (Options).Next;
1485 return Linker_Options_Buffer (1 .. Last_Linker_Option);
1486 end Linker_Options_Switches;
1492 package body Mains is
1494 package Names is new Table.Table
1495 (Table_Component_Type => Main_Info,
1496 Table_Index_Type => Integer,
1497 Table_Low_Bound => 1,
1498 Table_Initial => 10,
1499 Table_Increment => 100,
1500 Table_Name => "Makeutl.Mains.Names");
1501 -- The table that stores the mains
1503 Current : Natural := 0;
1504 -- The index of the last main retrieved from the table
1506 Count_Of_Mains_With_No_Tree : Natural := 0;
1507 -- Number of main units for which we do not know the project tree
1516 Location : Source_Ptr := No_Location;
1517 Project : Project_Id := No_Project;
1518 Tree : Project_Tree_Ref := null)
1521 if Current_Verbosity = High then
1522 Debug_Output ("Add_Main """ & Name & """ " & Index'Img
1524 & Boolean'Image (Tree /= null));
1528 Add_Str_To_Name_Buffer (Name);
1529 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1531 Names.Increment_Last;
1532 Names.Table (Names.Last) :=
1533 (Name_Find, Index, Location, No_Source, Project, Tree);
1535 if Tree /= null then
1536 Builder_Data (Tree).Number_Of_Mains :=
1537 Builder_Data (Tree).Number_Of_Mains + 1;
1540 Mains.Count_Of_Mains_With_No_Tree :=
1541 Mains.Count_Of_Mains_With_No_Tree + 1;
1545 --------------------
1546 -- Complete_Mains --
1547 --------------------
1549 procedure Complete_Mains
1550 (Flags : Processing_Flags;
1551 Root_Project : Project_Id;
1552 Project_Tree : Project_Tree_Ref)
1554 procedure Do_Complete (Project : Project_Id; Tree : Project_Tree_Ref);
1555 -- Check the mains for this specific project
1557 procedure Complete_All is new For_Project_And_Aggregated
1560 procedure Add_Multi_Unit_Sources
1561 (Tree : Project_Tree_Ref;
1562 Source : Prj.Source_Id);
1563 -- Add all units from the same file as the multi-unit Source
1565 function Find_File_Add_Extension
1566 (Tree : Project_Tree_Ref;
1567 Base_Main : String) return Prj.Source_Id;
1568 -- Search for Main in the project, adding body or spec extensions
1570 ----------------------------
1571 -- Add_Multi_Unit_Sources --
1572 ----------------------------
1574 procedure Add_Multi_Unit_Sources
1575 (Tree : Project_Tree_Ref;
1576 Source : Prj.Source_Id)
1578 Iter : Source_Iterator;
1579 Src : Prj.Source_Id;
1583 ("found multi-unit source file in project", Source.Project.Name);
1585 Iter := For_Each_Source
1586 (In_Tree => Tree, Project => Source.Project);
1588 while Element (Iter) /= No_Source loop
1589 Src := Element (Iter);
1591 if Src.File = Source.File
1592 and then Src.Index /= Source.Index
1594 if Src.File = Source.File then
1596 ("add main in project, index=" & Src.Index'Img);
1599 Names.Increment_Last;
1600 Names.Table (Names.Last) :=
1603 Location => No_Location,
1605 Project => Src.Project,
1608 Builder_Data (Tree).Number_Of_Mains :=
1609 Builder_Data (Tree).Number_Of_Mains + 1;
1614 end Add_Multi_Unit_Sources;
1616 -----------------------------
1617 -- Find_File_Add_Extension --
1618 -----------------------------
1620 function Find_File_Add_Extension
1621 (Tree : Project_Tree_Ref;
1622 Base_Main : String) return Prj.Source_Id
1624 Spec_Source : Prj.Source_Id := No_Source;
1625 Source : Prj.Source_Id;
1626 Iter : Source_Iterator;
1627 Suffix : File_Name_Type;
1630 Source := No_Source;
1631 Iter := For_Each_Source (Tree); -- In all projects
1633 Source := Prj.Element (Iter);
1634 exit when Source = No_Source;
1636 if Source.Kind = Impl then
1637 Get_Name_String (Source.File);
1639 if Name_Len > Base_Main'Length
1640 and then Name_Buffer (1 .. Base_Main'Length) = Base_Main
1643 Source.Language.Config.Naming_Data.Body_Suffix;
1645 if Suffix /= No_File then
1647 Suffix_Str : String := Get_Name_String (Suffix);
1649 Canonical_Case_File_Name (Suffix_Str);
1651 Name_Buffer (Base_Main'Length + 1 .. Name_Len) =
1657 elsif Source.Kind = Spec then
1658 -- A spec needs to be taken into account unless there is
1659 -- also a body. So we delay the decision for them.
1661 Get_Name_String (Source.File);
1663 if Name_Len > Base_Main'Length
1664 and then Name_Buffer (1 .. Base_Main'Length) = Base_Main
1666 Suffix := Source.Language.Config.Naming_Data.Spec_Suffix;
1668 if Suffix /= No_File then
1670 Suffix_Str : String := Get_Name_String (Suffix);
1673 Canonical_Case_File_Name (Suffix_Str);
1675 if Name_Buffer (Base_Main'Length + 1 .. Name_Len) =
1678 Spec_Source := Source;
1688 if Source = No_Source then
1689 Source := Spec_Source;
1693 end Find_File_Add_Extension;
1699 procedure Do_Complete
1700 (Project : Project_Id; Tree : Project_Tree_Ref)
1705 if Mains.Number_Of_Mains (Tree) > 0
1706 or else Mains.Count_Of_Mains_With_No_Tree > 0
1708 -- Traverse in reverse order, since in the case of multi-unit
1709 -- files we will be adding extra files at the end, and there's
1710 -- no need to process them in turn.
1715 File : Main_Info := Names.Table (J);
1716 Main_Id : File_Name_Type := File.File;
1717 Main : constant String :=
1718 Get_Name_String (Main_Id);
1719 Base : constant String := Base_Name (Main);
1720 Source : Prj.Source_Id := No_Source;
1721 Is_Absolute : Boolean := False;
1724 if Base /= Main then
1725 Is_Absolute := True;
1727 if Is_Absolute_Path (Main) then
1728 Main_Id := Create_Name (Base);
1730 -- Not an absolute path
1733 -- Always resolve links here, so that users can be
1734 -- specify any name on the command line. If the
1735 -- project itself uses links, the user will be
1736 -- using -eL anyway, and thus files are also stored
1737 -- with resolved names.
1740 Absolute : constant String :=
1744 Resolve_Links => True,
1745 Case_Sensitive => False);
1747 File.File := Create_Name (Absolute);
1748 Main_Id := Create_Name (Base);
1753 -- If no project or tree was specified for the main, it
1754 -- came from the command line.
1755 -- Note that the assignments below will not modify inside
1756 -- the table itself.
1758 if File.Project = null then
1759 File.Project := Project;
1762 if File.Tree = null then
1766 if File.Source = null then
1767 if Current_Verbosity = High then
1769 ("search for main """ & Main
1770 & '"' & File.Index'Img & " in "
1771 & Get_Name_String (Debug_Name (File.Tree))
1772 & ", project
", Project.Name);
1775 -- First, look for the main as specified. We need to
1776 -- search for the base name though, and if needed
1777 -- check later that we found the correct file.
1779 Source := Find_Source
1780 (In_Tree => File.Tree,
1781 Project => File.Project,
1782 Base_Name => Main_Id,
1783 Index => File.Index,
1784 In_Imported_Only => True);
1786 if Source = No_Source then
1787 Source := Find_File_Add_Extension
1788 (Tree, Get_Name_String (Main_Id));
1792 and then Source /= No_Source
1794 File_Name_Type (Source.Path.Name) /= File.File
1797 ("Found a non
-matching file
",
1798 Name_Id (Source.Path.Display_Name));
1799 Source := No_Source;
1802 if Source /= No_Source then
1803 if not Is_Allowed_Language
1804 (Source.Language.Name)
1806 -- Remove any main that is not in the list of
1807 -- restricted languages.
1809 Names.Table (J .. Names.Last - 1) :=
1810 Names.Table (J + 1 .. Names.Last);
1811 Names.Set_Last (Names.Last - 1);
1814 -- If we have found a multi-unit source file but
1815 -- did not specify an index initially, we'll
1816 -- need to compile all the units from the same
1819 if Source.Index /= 0 and then File.Index = 0 then
1820 Add_Multi_Unit_Sources (File.Tree, Source);
1823 -- Now update the original Main, otherwise it
1824 -- will be reported as not found.
1827 ("found main
in project
", Source.Project.Name);
1828 Names.Table (J).File := Source.File;
1829 Names.Table (J).Project := Source.Project;
1831 if Names.Table (J).Tree = null then
1832 Names.Table (J).Tree := File.Tree;
1834 Builder_Data (File.Tree).Number_Of_Mains :=
1835 Builder_Data (File.Tree).Number_Of_Mains
1837 Mains.Count_Of_Mains_With_No_Tree :=
1838 Mains.Count_Of_Mains_With_No_Tree - 1;
1841 Names.Table (J).Source := Source;
1842 Names.Table (J).Index := Source.Index;
1845 elsif File.Location /= No_Location then
1847 -- If the main is declared in package Builder of
1848 -- the main project, report an error. If the main
1849 -- is on the command line, it may be a main from
1850 -- another project, so do nothing: if the main does
1851 -- not exist in another project, an error will be
1854 Error_Msg_File_1 := Main_Id;
1855 Error_Msg_Name_1 := Root_Project.Name;
1857 (Flags, "{ is not a source
of project
%%",
1858 File.Location, Project);
1864 exit when J < Names.First;
1868 if Total_Errors_Detected > 0 then
1869 Fail_Program (Tree, "problems
with main sources
");
1873 -- Start of processing for Complete_Mains
1876 Complete_All (Root_Project, Project_Tree);
1878 if Mains.Count_Of_Mains_With_No_Tree > 0 then
1879 for J in Names.First .. Names.Last loop
1880 if Names.Table (J).Source = No_Source then
1882 (Project_Tree, '"' & Get_Name_String (Names.Table (J).File)
1883 & """ is not a source of any project");
1899 -----------------------
1900 -- Fill_From_Project --
1901 -----------------------
1903 procedure Fill_From_Project
1904 (Root_Project : Project_Id;
1905 Project_Tree : Project_Tree_Ref)
1907 procedure Add_Mains_From_Project
1908 (Project : Project_Id;
1909 Tree : Project_Tree_Ref);
1910 -- Add the main units from this project into Mains.
1911 -- This takes into account the aggregated projects
1913 ----------------------------
1914 -- Add_Mains_From_Project --
1915 ----------------------------
1917 procedure Add_Mains_From_Project
1918 (Project : Project_Id;
1919 Tree : Project_Tree_Ref)
1921 List : String_List_Id;
1922 Element : String_Element;
1925 if Number_Of_Mains (Tree) = 0
1926 and then Mains.Count_Of_Mains_With_No_Tree = 0
1928 Debug_Output ("Add_Mains_From_Project", Project.Name);
1929 List := Project.Mains;
1931 if List /= Prj.Nil_String then
1933 -- The attribute Main is not an empty list. Get the mains in
1936 while List /= Prj.Nil_String loop
1937 Element := Tree.Shared.String_Elements.Table (List);
1938 Debug_Output ("Add_Main", Element.Value);
1940 if Project.Library then
1943 "cannot specify a main program " &
1944 "for a library project file");
1947 Add_Main (Name => Get_Name_String (Element.Value),
1948 Index => Element.Index,
1949 Location => Element.Location,
1952 List := Element.Next;
1957 if Total_Errors_Detected > 0 then
1958 Fail_Program (Tree, "problems with main sources");
1960 end Add_Mains_From_Project;
1962 procedure Fill_All is new For_Project_And_Aggregated
1963 (Add_Mains_From_Project);
1965 -- Start of processing for Fill_From_Project
1968 Fill_All (Root_Project, Project_Tree);
1969 end Fill_From_Project;
1975 function Next_Main return String is
1976 Info : constant Main_Info := Next_Main;
1978 if Info = No_Main_Info then
1981 return Get_Name_String (Info.File);
1985 function Next_Main return Main_Info is
1987 if Current >= Names.Last then
1988 return No_Main_Info;
1990 Current := Current + 1;
1992 -- If not using projects, and in the gnatmake case, the main file
1993 -- may have not have the extension. Try ".adb" first then ".ads"
1995 if Names.Table (Current).Project = No_Project then
1997 Orig_Main : constant File_Name_Type :=
1998 Names.Table (Current).File;
1999 Current_Main : File_Name_Type;
2002 if Strip_Suffix (Orig_Main) = Orig_Main then
2003 Get_Name_String (Orig_Main);
2004 Add_Str_To_Name_Buffer (".adb");
2005 Current_Main := Name_Find;
2007 if Full_Source_Name (Current_Main) = No_File then
2008 Get_Name_String (Orig_Main);
2009 Add_Str_To_Name_Buffer (".ads");
2010 Current_Main := Name_Find;
2012 if Full_Source_Name (Current_Main) /= No_File then
2013 Names.Table (Current).File := Current_Main;
2017 Names.Table (Current).File := Current_Main;
2023 return Names.Table (Current);
2027 ---------------------
2028 -- Number_Of_Mains --
2029 ---------------------
2031 function Number_Of_Mains (Tree : Project_Tree_Ref) return Natural is
2036 return Builder_Data (Tree).Number_Of_Mains;
2038 end Number_Of_Mains;
2049 --------------------------
2050 -- Set_Multi_Unit_Index --
2051 --------------------------
2053 procedure Set_Multi_Unit_Index
2054 (Project_Tree : Project_Tree_Ref := null;
2059 if Names.Last = 0 then
2062 "cannot specify a multi-unit index but no main " &
2063 "on the command line");
2065 elsif Names.Last > 1 then
2068 "cannot specify several mains with a multi-unit index");
2071 Names.Table (Names.Last).Index := Index;
2074 end Set_Multi_Unit_Index;
2078 -----------------------
2079 -- Path_Or_File_Name --
2080 -----------------------
2082 function Path_Or_File_Name (Path : Path_Name_Type) return String is
2083 Path_Name : constant String := Get_Name_String (Path);
2085 if Debug.Debug_Flag_F then
2086 return File_Name (Path_Name);
2090 end Path_Or_File_Name;
2096 function Unit_Index_Of (ALI_File : File_Name_Type) return Int is
2102 Get_Name_String (ALI_File);
2104 -- First, find the last dot
2108 while Finish >= 1 and then Name_Buffer (Finish) /= '.' loop
2109 Finish := Finish - 1;
2116 -- Now check that the dot is preceded by digits
2119 Finish := Finish - 1;
2120 while Start >= 1 and then Name_Buffer (Start - 1) in '0' .. '9' loop
2124 -- If there are no digits, or if the digits are not preceded by the
2125 -- character that precedes a unit index, this is not the ALI file of
2126 -- a unit in a multi-unit source.
2130 or else Name_Buffer (Start - 1) /= Multi_Unit_Index_Character
2135 -- Build the index from the digit(s)
2137 while Start <= Finish loop
2138 Result := Result * 10 +
2139 Character'Pos (Name_Buffer (Start)) - Character'Pos ('0');
2150 procedure Verbose_Msg
2153 N2 : Name_Id := No_Name;
2155 Prefix : String := " -> ";
2156 Minimum_Verbosity : Opt.Verbosity_Level_Type := Opt.Low)
2159 if not Opt.Verbose_Mode
2160 or else Minimum_Verbosity > Opt.Verbosity_Level
2171 if N2 /= No_Name then
2181 procedure Verbose_Msg
2182 (N1 : File_Name_Type;
2184 N2 : File_Name_Type := No_File;
2186 Prefix : String := " -> ";
2187 Minimum_Verbosity : Opt.Verbosity_Level_Type := Opt.Low)
2191 (Name_Id (N1), S1, Name_Id (N2), S2, Prefix, Minimum_Verbosity);
2198 package body Queue is
2200 type Q_Record is record
2202 Processed : Boolean;
2205 package Q is new Table.Table
2206 (Table_Component_Type => Q_Record,
2207 Table_Index_Type => Natural,
2208 Table_Low_Bound => 1,
2209 Table_Initial => 1000,
2210 Table_Increment => 100,
2211 Table_Name => "Makeutl.Queue.Q");
2212 -- This is the actual Queue
2214 package Busy_Obj_Dirs is new GNAT.HTable.Simple_HTable
2215 (Header_Num => Prj.Header_Num,
2217 No_Element => False,
2218 Key => Path_Name_Type,
2222 type Mark_Key is record
2223 File : File_Name_Type;
2226 -- Identify either a mono-unit source (when Index = 0) or a specific
2227 -- unit (index = 1's origin index of unit) in a multi-unit source.
2229 Max_Mask_Num : constant := 2048;
2230 subtype Mark_Num is Union_Id range 0 .. Max_Mask_Num - 1;
2232 function Hash (Key : Mark_Key) return Mark_Num;
2234 package Marks is new GNAT.HTable.Simple_HTable
2235 (Header_Num => Mark_Num,
2237 No_Element => False,
2241 -- A hash table to keep tracks of the marked units.
2242 -- These are the units that have already been processed, when using the
2243 -- gnatmake format. When using the gprbuild format, we can directly
2244 -- store in the source_id whether the file has already been processed.
2246 procedure Mark (Source_File : File_Name_Type; Index : Int := 0);
2247 -- Mark a unit, identified by its source file and, when Index is not 0,
2248 -- the index of the unit in the source file. Marking is used to signal
2249 -- that the unit has already been inserted in the Q.
2252 (Source_File : File_Name_Type;
2253 Index : Int := 0) return Boolean;
2254 -- Returns True if the unit was previously marked
2256 Q_Processed : Natural := 0;
2257 Q_Initialized : Boolean := False;
2259 Q_First : Natural := 1;
2260 -- Points to the first valid element in the queue
2262 One_Queue_Per_Obj_Dir : Boolean := False;
2263 -- See parameter to Initialize
2265 function Available_Obj_Dir (S : Source_Info) return Boolean;
2266 -- Whether the object directory for S is available for a build
2268 procedure Debug_Display (S : Source_Info);
2269 -- A debug display for S
2271 function Was_Processed (S : Source_Info) return Boolean;
2272 -- Whether S has already been processed. This marks the source as
2273 -- processed, if it hasn't already been processed.
2275 function Insert_No_Roots (Source : Source_Info) return Boolean;
2276 -- Insert Source, but do not look for its roots (see doc for Insert)
2282 function Was_Processed (S : Source_Info) return Boolean is
2285 when Format_Gprbuild =>
2286 if S.Id.In_The_Queue then
2290 S.Id.In_The_Queue := True;
2292 when Format_Gnatmake =>
2293 if Is_Marked (S.File, S.Index) then
2297 Mark (S.File, Index => S.Index);
2303 -----------------------
2304 -- Available_Obj_Dir --
2305 -----------------------
2307 function Available_Obj_Dir (S : Source_Info) return Boolean is
2310 when Format_Gprbuild =>
2311 return not Busy_Obj_Dirs.Get
2312 (S.Id.Project.Object_Directory.Name);
2314 when Format_Gnatmake =>
2315 return S.Project = No_Project
2317 not Busy_Obj_Dirs.Get (S.Project.Object_Directory.Name);
2319 end Available_Obj_Dir;
2325 procedure Debug_Display (S : Source_Info) is
2328 when Format_Gprbuild =>
2329 Write_Name (S.Id.File);
2331 if S.Id.Index /= 0 then
2333 Write_Int (S.Id.Index);
2336 when Format_Gnatmake =>
2337 Write_Name (S.File);
2339 if S.Index /= 0 then
2341 Write_Int (S.Index);
2350 function Hash (Key : Mark_Key) return Mark_Num is
2352 return Union_Id (Key.File) mod Max_Mask_Num;
2360 (Source_File : File_Name_Type;
2361 Index : Int := 0) return Boolean
2364 return Marks.Get (K => (File => Source_File, Index => Index));
2371 procedure Mark (Source_File : File_Name_Type; Index : Int := 0) is
2373 Marks.Set (K => (File => Source_File, Index => Index), E => True);
2381 (Found : out Boolean;
2382 Source : out Source_Info)
2387 if One_Queue_Per_Obj_Dir then
2388 for J in Q_First .. Q.Last loop
2389 if not Q.Table (J).Processed
2390 and then Available_Obj_Dir (Q.Table (J).Info)
2393 Source := Q.Table (J).Info;
2394 Q.Table (J).Processed := True;
2397 while Q_First <= Q.Last
2398 and then Q.Table (Q_First).Processed
2400 Q_First := Q_First + 1;
2408 elsif Q_First <= Q.Last then
2409 Source := Q.Table (Q_First).Info;
2410 Q.Table (Q_First).Processed := True;
2411 Q_First := Q_First + 1;
2416 Q_Processed := Q_Processed + 1;
2419 if Found and then Debug.Debug_Flag_Q then
2420 Write_Str (" Q := Q - [ ");
2421 Debug_Display (Source);
2425 Write_Str (" Q_First =");
2426 Write_Int (Int (Q_First));
2429 Write_Str (" Q.Last =");
2430 Write_Int (Int (Q.Last));
2439 function Processed return Natural is
2448 procedure Initialize
2449 (Queue_Per_Obj_Dir : Boolean;
2450 Force : Boolean := False)
2453 if Force or else not Q_Initialized then
2454 Q_Initialized := True;
2456 for J in 1 .. Q.Last loop
2457 case Q.Table (J).Info.Format is
2458 when Format_Gprbuild =>
2459 Q.Table (J).Info.Id.In_The_Queue := False;
2460 when Format_Gnatmake =>
2468 One_Queue_Per_Obj_Dir := Queue_Per_Obj_Dir;
2472 ---------------------
2473 -- Insert_No_Roots --
2474 ---------------------
2476 function Insert_No_Roots (Source : Source_Info) return Boolean is
2479 (Source.Format = Format_Gnatmake or else Source.Id /= No_Source);
2481 -- Only insert in the Q if it is not already done, to avoid
2482 -- simultaneous compilations if -jnnn is used.
2484 if Was_Processed (Source) then
2488 if Current_Verbosity = High then
2489 Write_Str ("Adding """);
2490 Debug_Display (Source);
2491 Write_Line (""" to the queue");
2494 Q.Append (New_Val => (Info => Source, Processed => False));
2496 if Debug.Debug_Flag_Q then
2497 Write_Str (" Q := Q + [ ");
2498 Debug_Display (Source);
2502 Write_Str (" Q_First =");
2503 Write_Int (Int (Q_First));
2506 Write_Str (" Q.Last =");
2507 Write_Int (Int (Q.Last));
2512 end Insert_No_Roots;
2519 (Source : Source_Info;
2520 With_Roots : Boolean := False) return Boolean
2522 Root_Arr : Array_Element_Id;
2523 Roots : Variable_Value;
2524 List : String_List_Id;
2525 Elem : String_Element;
2526 Unit_Name : Name_Id;
2528 Root_Pattern : Regexp;
2529 Root_Found : Boolean;
2530 Roots_Found : Boolean;
2531 Root_Source : Prj.Source_Id;
2532 Iter : Source_Iterator;
2535 pragma Unreferenced (Dummy);
2538 if not Insert_No_Roots (Source) then
2540 -- Was already in the queue
2545 if With_Roots and then Source.Format = Format_Gprbuild then
2546 Debug_Output ("looking for roots of", Name_Id (Source.Id.File));
2550 (Name => Name_Roots,
2551 In_Arrays => Source.Id.Project.Decl.Arrays,
2552 Shared => Source.Tree.Shared);
2556 (Index => Name_Id (Source.Id.File),
2558 In_Array => Root_Arr,
2559 Shared => Source.Tree.Shared);
2561 -- If there is no roots for the specific main, try the language
2563 if Roots = Nil_Variable_Value then
2566 (Index => Source.Id.Language.Name,
2568 In_Array => Root_Arr,
2569 Shared => Source.Tree.Shared,
2570 Force_Lower_Case_Index => True);
2575 if Roots = Nil_Variable_Value then
2577 Name_Buffer (1) := '*';
2581 (Index => Name_Find,
2583 In_Array => Root_Arr,
2584 Shared => Source.Tree.Shared,
2585 Force_Lower_Case_Index => True);
2588 if Roots = Nil_Variable_Value then
2589 Debug_Output (" -> no roots declared");
2592 List := Roots.Values;
2595 while List /= Nil_String loop
2596 Elem := Source.Tree.Shared.String_Elements.Table (List);
2597 Get_Name_String (Elem.Value);
2598 To_Lower (Name_Buffer (1 .. Name_Len));
2599 Unit_Name := Name_Find;
2601 -- Check if it is a unit name or a pattern
2605 for J in 1 .. Name_Len loop
2606 if Name_Buffer (J) not in 'a
' .. 'z
' and then
2607 Name_Buffer (J) not in '0' .. '9' and then
2608 Name_Buffer (J) /= '_
' and then
2609 Name_Buffer (J) /= '.'
2620 (Pattern => Name_Buffer (1 .. Name_Len),
2624 when Error_In_Regexp =>
2625 Err_Vars.Error_Msg_Name_1 := Unit_Name;
2627 ("invalid pattern %", Roots.Location);
2632 Roots_Found := False;
2633 Iter := For_Each_Source (Source.Tree);
2637 Root_Source := Prj.Element (Iter);
2638 exit Source_Loop when Root_Source = No_Source;
2640 Root_Found := False;
2642 Root_Found := Root_Source.Unit /= No_Unit_Index
2644 (Get_Name_String (Root_Source.Unit.Name),
2649 Root_Source.Unit /= No_Unit_Index
2650 and then Root_Source.Unit.Name = Unit_Name;
2654 case Root_Source.Kind is
2659 Root_Found := Other_Part (Root_Source) = No_Source;
2662 Root_Found := False;
2667 Roots_Found := True;
2669 (" -> ", Name_Id (Root_Source.Display_File));
2670 Dummy := Queue.Insert_No_Roots
2671 (Source => (Format => Format_Gprbuild,
2672 Tree => Source.Tree,
2673 Id => Root_Source));
2675 Initialize_Source_Record (Root_Source);
2677 if Other_Part (Root_Source) /= No_Source then
2678 Initialize_Source_Record (Other_Part (Root_Source));
2681 -- Save the root for the binder
2683 Source.Id.Roots := new Source_Roots'
2684 (Root
=> Root_Source
,
2685 Next
=> Source
.Id
.Roots
);
2687 exit Source_Loop
when not Pat_Root
;
2691 end loop Source_Loop
;
2693 if not Roots_Found
then
2695 if not Quiet_Output
then
2696 Error_Msg_Name_1
:= Unit_Name
;
2698 ("?no unit matches pattern %", Roots
.Location
);
2703 ("Unit " & Get_Name_String
(Unit_Name
)
2704 & " does not exist", Roots
.Location
);
2709 end loop Pattern_Loop
;
2721 (Source
: Source_Info
;
2722 With_Roots
: Boolean := False)
2725 pragma Unreferenced
(Discard
);
2727 Discard
:= Insert
(Source
, With_Roots
);
2734 function Is_Empty
return Boolean is
2736 return Q_Processed
>= Q
.Last
;
2739 ------------------------
2740 -- Is_Virtually_Empty --
2741 ------------------------
2743 function Is_Virtually_Empty
return Boolean is
2745 if One_Queue_Per_Obj_Dir
then
2746 for J
in Q_First
.. Q
.Last
loop
2747 if not Q
.Table
(J
).Processed
2748 and then Available_Obj_Dir
(Q
.Table
(J
).Info
)
2759 end Is_Virtually_Empty
;
2761 ----------------------
2762 -- Set_Obj_Dir_Busy --
2763 ----------------------
2765 procedure Set_Obj_Dir_Busy
(Obj_Dir
: Path_Name_Type
) is
2767 if One_Queue_Per_Obj_Dir
then
2768 Busy_Obj_Dirs
.Set
(Obj_Dir
, True);
2770 end Set_Obj_Dir_Busy
;
2772 ----------------------
2773 -- Set_Obj_Dir_Free --
2774 ----------------------
2776 procedure Set_Obj_Dir_Free
(Obj_Dir
: Path_Name_Type
) is
2778 if One_Queue_Per_Obj_Dir
then
2779 Busy_Obj_Dirs
.Set
(Obj_Dir
, False);
2781 end Set_Obj_Dir_Free
;
2787 function Size
return Natural is
2796 function Element
(Rank
: Positive) return File_Name_Type
is
2798 if Rank
<= Q
.Last
then
2799 case Q
.Table
(Rank
).Info
.Format
is
2800 when Format_Gprbuild
=>
2801 return Q
.Table
(Rank
).Info
.Id
.File
;
2802 when Format_Gnatmake
=>
2803 return Q
.Table
(Rank
).Info
.File
;
2814 procedure Remove_Marks
is
2819 ----------------------------
2820 -- Insert_Project_Sources --
2821 ----------------------------
2823 procedure Insert_Project_Sources
2824 (Project
: Project_Id
;
2825 Project_Tree
: Project_Tree_Ref
;
2826 All_Projects
: Boolean;
2827 Unique_Compile
: Boolean)
2829 procedure Do_Insert
(Project
: Project_Id
; Tree
: Project_Tree_Ref
);
2835 procedure Do_Insert
(Project
: Project_Id
; Tree
: Project_Tree_Ref
) is
2836 Unit_Based
: constant Boolean :=
2838 or else not Builder_Data
(Tree
).Closure_Needed
;
2839 -- When Unit_Based is True, put in the queue all compilable
2840 -- sources including the unit based (Ada) one. When Unit_Based is
2841 -- False, put the Ada sources only when they are in a library
2844 Iter
: Source_Iterator
;
2845 Source
: Prj
.Source_Id
;
2848 -- Nothing to do when "-u" was specified and some files were
2849 -- specified on the command line
2852 and then Mains
.Number_Of_Mains
(Tree
) > 0
2857 Iter
:= For_Each_Source
(Tree
);
2859 Source
:= Prj
.Element
(Iter
);
2860 exit when Source
= No_Source
;
2862 if Is_Allowed_Language
(Source
.Language
.Name
)
2863 and then Is_Compilable
(Source
)
2866 or else Is_Extending
(Project
, Source
.Project
))
2867 and then not Source
.Locally_Removed
2868 and then Source
.Replaced_By
= No_Source
2870 (not Source
.Project
.Externally_Built
2872 (Is_Extending
(Project
, Source
.Project
)
2873 and then not Project
.Externally_Built
))
2874 and then Source
.Kind
/= Sep
2875 and then Source
.Path
/= No_Path_Information
2877 if Source
.Kind
= Impl
2878 or else (Source
.Unit
/= No_Unit_Index
2879 and then Source
.Kind
= Spec
2880 and then (Other_Part
(Source
) = No_Source
2882 Other_Part
(Source
).Locally_Removed
))
2885 or else Source
.Unit
= No_Unit_Index
2886 or else Source
.Project
.Library
)
2887 and then not Is_Subunit
(Source
)
2890 (Source
=> (Format
=> Format_Gprbuild
,
2901 procedure Insert_All
is new For_Project_And_Aggregated
(Do_Insert
);
2904 Insert_All
(Project
, Project_Tree
);
2905 end Insert_Project_Sources
;
2907 -------------------------------
2908 -- Insert_Withed_Sources_For --
2909 -------------------------------
2911 procedure Insert_Withed_Sources_For
2912 (The_ALI
: ALI
.ALI_Id
;
2913 Project_Tree
: Project_Tree_Ref
;
2914 Excluding_Shared_SALs
: Boolean := False)
2916 Sfile
: File_Name_Type
;
2917 Afile
: File_Name_Type
;
2918 Src_Id
: Prj
.Source_Id
;
2921 -- Insert in the queue the unmarked source files (i.e. those which
2922 -- have never been inserted in the queue and hence never considered).
2924 for J
in ALI
.ALIs
.Table
(The_ALI
).First_Unit
..
2925 ALI
.ALIs
.Table
(The_ALI
).Last_Unit
2927 for K
in ALI
.Units
.Table
(J
).First_With
..
2928 ALI
.Units
.Table
(J
).Last_With
2930 Sfile
:= ALI
.Withs
.Table
(K
).Sfile
;
2934 if Sfile
/= No_File
then
2935 Afile
:= ALI
.Withs
.Table
(K
).Afile
;
2937 Src_Id
:= Source_Files_Htable
.Get
2938 (Project_Tree
.Source_Files_HT
, Sfile
);
2939 while Src_Id
/= No_Source
loop
2940 Initialize_Source_Record
(Src_Id
);
2942 if Is_Compilable
(Src_Id
)
2943 and then Src_Id
.Dep_Name
= Afile
2948 Bdy
: constant Prj
.Source_Id
:=
2949 Other_Part
(Src_Id
);
2952 and then not Bdy
.Locally_Removed
2954 Src_Id
:= Other_Part
(Src_Id
);
2959 if Is_Subunit
(Src_Id
) then
2960 Src_Id
:= No_Source
;
2964 Src_Id
:= No_Source
;
2970 Src_Id
:= Src_Id
.Next_With_File_Name
;
2973 -- If Excluding_Shared_SALs is True, do not insert in the
2974 -- queue the sources of a shared Stand-Alone Library.
2976 if Src_Id
/= No_Source
2977 and then (not Excluding_Shared_SALs
2978 or else Src_Id
.Project
.Standalone_Library
= No
2979 or else Src_Id
.Project
.Library_Kind
= Static
)
2982 (Source
=> (Format
=> Format_Gprbuild
,
2983 Tree
=> Project_Tree
,
2989 end Insert_Withed_Sources_For
;
2997 procedure Free
(Data
: in out Builder_Project_Tree_Data
) is
2998 procedure Unchecked_Free
is new Ada
.Unchecked_Deallocation
2999 (Binding_Data_Record
, Binding_Data
);
3001 TmpB
, Binding
: Binding_Data
:= Data
.Binding
;
3004 while Binding
/= null loop
3005 TmpB
:= Binding
.Next
;
3006 Unchecked_Free
(Binding
);
3015 function Builder_Data
3016 (Tree
: Project_Tree_Ref
) return Builder_Data_Access
3019 if Tree
.Appdata
= null then
3020 Tree
.Appdata
:= new Builder_Project_Tree_Data
;
3023 return Builder_Data_Access
(Tree
.Appdata
);
3026 --------------------------------
3027 -- Compute_Compilation_Phases --
3028 --------------------------------
3030 procedure Compute_Compilation_Phases
3031 (Tree
: Project_Tree_Ref
;
3032 Root_Project
: Project_Id
;
3033 Option_Unique_Compile
: Boolean := False; -- Was "-u" specified ?
3034 Option_Compile_Only
: Boolean := False; -- Was "-c" specified ?
3035 Option_Bind_Only
: Boolean := False;
3036 Option_Link_Only
: Boolean := False)
3038 procedure Do_Compute
(Project
: Project_Id
; Tree
: Project_Tree_Ref
);
3044 procedure Do_Compute
(Project
: Project_Id
; Tree
: Project_Tree_Ref
) is
3045 Data
: constant Builder_Data_Access
:= Builder_Data
(Tree
);
3046 All_Phases
: constant Boolean :=
3047 not Option_Compile_Only
3048 and then not Option_Bind_Only
3049 and then not Option_Link_Only
;
3050 -- Whether the command line asked for all three phases. Depending on
3051 -- the project settings, we might still disable some of the phases.
3053 Has_Mains
: constant Boolean := Data
.Number_Of_Mains
> 0;
3054 -- Whether there are some main units defined for this project tree
3055 -- (either from one of the projects, or from the command line)
3058 if Option_Unique_Compile
then
3060 -- If -u or -U is specified on the command line, disregard any -c,
3061 -- -b or -l switch: only perform compilation.
3063 Data
.Closure_Needed
:= False;
3064 Data
.Need_Compilation
:= True;
3065 Data
.Need_Binding
:= False;
3066 Data
.Need_Linking
:= False;
3069 Data
.Closure_Needed
:= Has_Mains
;
3070 Data
.Need_Compilation
:= All_Phases
or Option_Compile_Only
;
3071 Data
.Need_Binding
:= All_Phases
or Option_Bind_Only
;
3072 Data
.Need_Linking
:= (All_Phases
or Option_Link_Only
)
3076 if Current_Verbosity
= High
then
3077 Debug_Output
("compilation phases: "
3078 & " compile=" & Data
.Need_Compilation
'Img
3079 & " bind=" & Data
.Need_Binding
'Img
3080 & " link=" & Data
.Need_Linking
'Img
3081 & " closure=" & Data
.Closure_Needed
'Img
3082 & " mains=" & Data
.Number_Of_Mains
'Img,
3087 procedure Compute_All
is new For_Project_And_Aggregated
(Do_Compute
);
3090 Compute_All
(Root_Project
, Tree
);
3091 end Compute_Compilation_Phases
;
3093 ------------------------------
3094 -- Compute_Builder_Switches --
3095 ------------------------------
3097 procedure Compute_Builder_Switches
3098 (Project_Tree
: Project_Tree_Ref
;
3099 Root_Environment
: in out Prj
.Tree
.Environment
;
3100 Main_Project
: Project_Id
;
3101 Only_For_Lang
: Name_Id
:= No_Name
)
3103 Builder_Package
: constant Package_Id
:=
3104 Value_Of
(Name_Builder
, Main_Project
.Decl
.Packages
,
3105 Project_Tree
.Shared
);
3107 Global_Compilation_Array
: Array_Element_Id
;
3108 Global_Compilation_Elem
: Array_Element
;
3109 Global_Compilation_Switches
: Variable_Value
;
3111 Default_Switches_Array
: Array_Id
;
3113 Builder_Switches_Lang
: Name_Id
:= No_Name
;
3115 List
: String_List_Id
;
3116 Element
: String_Element
;
3119 Source
: Prj
.Source_Id
;
3121 Lang
: Name_Id
:= No_Name
; -- language index for Switches
3122 Switches_For_Lang
: Variable_Value
:= Nil_Variable_Value
;
3123 -- Value of Builder'Default_Switches(lang)
3125 Name
: Name_Id
:= No_Name
; -- main file index for Switches
3126 Switches_For_Main
: Variable_Value
:= Nil_Variable_Value
;
3127 -- Switches for a specific main. When there are several mains, Name is
3128 -- set to No_Name, and Switches_For_Main might be left with an actual
3129 -- value (so that we can display a warning that it was ignored).
3131 Other_Switches
: Variable_Value
:= Nil_Variable_Value
;
3132 -- Value of Builder'Switches(others)
3134 Defaults
: Variable_Value
:= Nil_Variable_Value
;
3136 Switches
: Variable_Value
:= Nil_Variable_Value
;
3137 -- The computed builder switches
3139 Success
: Boolean := False;
3141 if Builder_Package
/= No_Package
then
3144 -- If there is no main, and there is only one compilable language,
3145 -- use this language as the switches index.
3147 if Mains
.Number_Of_Mains
(Project_Tree
) = 0 then
3148 if Only_For_Lang
= No_Name
then
3150 Language
: Language_Ptr
:= Main_Project
.Languages
;
3153 while Language
/= No_Language_Index
loop
3154 if Language
.Config
.Compiler_Driver
/= No_File
3155 and then Language
.Config
.Compiler_Driver
/= Empty_File
3157 if Lang
/= No_Name
then
3161 Lang
:= Language
.Name
;
3164 Language
:= Language
.Next
;
3168 Lang
:= Only_For_Lang
;
3172 for Index
in 1 .. Mains
.Number_Of_Mains
(Project_Tree
) loop
3173 Source
:= Mains
.Next_Main
.Source
;
3175 if Source
/= No_Source
then
3176 if Switches_For_Main
= Nil_Variable_Value
then
3177 Switches_For_Main
:= Value_Of
3178 (Name
=> Name_Id
(Source
.File
),
3179 Attribute_Or_Array_Name
=> Name_Switches
,
3180 In_Package
=> Builder_Package
,
3181 Shared
=> Project_Tree
.Shared
,
3182 Force_Lower_Case_Index
=> False,
3183 Allow_Wildcards
=> True);
3185 -- If not found, try without extension.
3186 -- That's because gnatmake accepts truncated file names
3187 -- in Builder'Switches
3189 if Switches_For_Main
= Nil_Variable_Value
3190 and then Source
.Unit
/= null
3192 Switches_For_Main
:= Value_Of
3193 (Name
=> Source
.Unit
.Name
,
3194 Attribute_Or_Array_Name
=> Name_Switches
,
3195 In_Package
=> Builder_Package
,
3196 Shared
=> Project_Tree
.Shared
,
3197 Force_Lower_Case_Index
=> False,
3198 Allow_Wildcards
=> True);
3203 Lang
:= Source
.Language
.Name
;
3204 Name
:= Name_Id
(Source
.File
);
3206 Name
:= No_Name
; -- Can't use main specific switches
3208 if Lang
/= Source
.Language
.Name
then
3216 Global_Compilation_Array
:= Value_Of
3217 (Name
=> Name_Global_Compilation_Switches
,
3218 In_Arrays
=> Project_Tree
.Shared
.Packages
.Table
3219 (Builder_Package
).Decl
.Arrays
,
3220 Shared
=> Project_Tree
.Shared
);
3222 Default_Switches_Array
:=
3223 Project_Tree
.Shared
.Packages
.Table
(Builder_Package
).Decl
.Arrays
;
3225 while Default_Switches_Array
/= No_Array
3227 Project_Tree
.Shared
.Arrays
.Table
(Default_Switches_Array
).Name
/=
3228 Name_Default_Switches
3230 Default_Switches_Array
:=
3231 Project_Tree
.Shared
.Arrays
.Table
(Default_Switches_Array
).Next
;
3234 if Global_Compilation_Array
/= No_Array_Element
3235 and then Default_Switches_Array
/= No_Array
3238 (Root_Environment
.Flags
,
3239 "Default_Switches forbidden in presence of " &
3240 "Global_Compilation_Switches. Use Switches instead.",
3241 Project_Tree
.Shared
.Arrays
.Table
3242 (Default_Switches_Array
).Location
);
3245 "*** illegal combination of Builder attributes");
3248 if Lang
/= No_Name
then
3249 Switches_For_Lang
:= Prj
.Util
.Value_Of
3252 Attribute_Or_Array_Name
=> Name_Switches
,
3253 In_Package
=> Builder_Package
,
3254 Shared
=> Project_Tree
.Shared
,
3255 Force_Lower_Case_Index
=> True);
3257 Defaults
:= Prj
.Util
.Value_Of
3260 Attribute_Or_Array_Name
=> Name_Default_Switches
,
3261 In_Package
=> Builder_Package
,
3262 Shared
=> Project_Tree
.Shared
,
3263 Force_Lower_Case_Index
=> True);
3266 Other_Switches
:= Prj
.Util
.Value_Of
3267 (Name
=> All_Other_Names
,
3269 Attribute_Or_Array_Name
=> Name_Switches
,
3270 In_Package
=> Builder_Package
,
3271 Shared
=> Project_Tree
.Shared
);
3274 and then Mains
.Number_Of_Mains
(Project_Tree
) > 1
3275 and then Switches_For_Main
/= Nil_Variable_Value
3277 -- More than one main, but we had main-specific switches that
3280 if Switches_For_Lang
/= Nil_Variable_Value
then
3282 ("Warning: using Builder'Switches("""
3283 & Get_Name_String
(Lang
)
3284 & """), as there are several mains");
3286 elsif Other_Switches
/= Nil_Variable_Value
then
3288 ("Warning: using Builder'Switches(others), "
3289 & "as there are several mains");
3291 elsif Defaults
/= Nil_Variable_Value
then
3293 ("Warning: using Builder'Default_Switches("""
3294 & Get_Name_String
(Lang
)
3295 & """), as there are several mains");
3298 ("Warning: using no switches from package "
3299 & "Builder, as there are several mains");
3303 Builder_Switches_Lang
:= Lang
;
3305 if Name
/= No_Name
then
3306 -- Get the switches for the single main
3307 Switches
:= Switches_For_Main
;
3310 if Switches
= Nil_Variable_Value
or else Switches
.Default
then
3311 -- Get the switches for the common language of the mains
3312 Switches
:= Switches_For_Lang
;
3315 if Switches
= Nil_Variable_Value
or else Switches
.Default
then
3316 Switches
:= Other_Switches
;
3319 -- For backward compatibility with gnatmake, if no Switches
3320 -- are declared, check for Default_Switches (<language>).
3322 if Switches
= Nil_Variable_Value
or else Switches
.Default
then
3323 Switches
:= Defaults
;
3326 -- If switches have been found, scan them
3328 if Switches
/= Nil_Variable_Value
and then not Switches
.Default
then
3329 List
:= Switches
.Values
;
3331 while List
/= Nil_String
loop
3332 Element
:= Project_Tree
.Shared
.String_Elements
.Table
(List
);
3333 Get_Name_String
(Element
.Value
);
3335 if Name_Len
/= 0 then
3337 -- Add_Switch might itself be using the name_buffer, so
3338 -- we make a temporary here.
3339 Switch
: constant String := Name_Buffer
(1 .. Name_Len
);
3341 Success
:= Add_Switch
3343 For_Lang
=> Builder_Switches_Lang
,
3344 For_Builder
=> True,
3345 Has_Global_Compilation_Switches
=>
3346 Global_Compilation_Array
/= No_Array_Element
);
3350 for J
in reverse 1 .. Name_Len
loop
3351 Name_Buffer
(J
+ J
) := Name_Buffer
(J
);
3352 Name_Buffer
(J
+ J
- 1) := ''';
3355 Name_Len
:= Name_Len
+ Name_Len
;
3358 (Root_Environment
.Flags
,
3359 '"' & Name_Buffer
(1 .. Name_Len
) &
3360 """ is not a builder switch. Consider moving " &
3361 "it to Global_Compilation_Switches.",
3365 "*** illegal switch """ &
3366 Get_Name_String
(Element
.Value
) & '"');
3370 List
:= Element
.Next
;
3374 -- Reset the Builder Switches language
3376 Builder_Switches_Lang
:= No_Name
;
3378 -- Take into account attributes Global_Compilation_Switches
3380 while Global_Compilation_Array
/= No_Array_Element
loop
3381 Global_Compilation_Elem
:=
3382 Project_Tree
.Shared
.Array_Elements
.Table
3383 (Global_Compilation_Array
);
3385 Get_Name_String
(Global_Compilation_Elem
.Index
);
3386 To_Lower
(Name_Buffer
(1 .. Name_Len
));
3389 if Only_For_Lang
= No_Name
or else Index
= Only_For_Lang
then
3390 Global_Compilation_Switches
:= Global_Compilation_Elem
.Value
;
3392 if Global_Compilation_Switches
/= Nil_Variable_Value
3393 and then not Global_Compilation_Switches
.Default
3395 -- We have found an attribute
3396 -- Global_Compilation_Switches for a language: put the
3397 -- switches in the appropriate table.
3399 List
:= Global_Compilation_Switches
.Values
;
3400 while List
/= Nil_String
loop
3402 Project_Tree
.Shared
.String_Elements
.Table
(List
);
3404 if Element
.Value
/= No_Name
then
3405 Success
:= Add_Switch
3406 (Switch
=> Get_Name_String
(Element
.Value
),
3408 For_Builder
=> False,
3409 Has_Global_Compilation_Switches
=>
3410 Global_Compilation_Array
/= No_Array_Element
);
3413 List
:= Element
.Next
;
3418 Global_Compilation_Array
:= Global_Compilation_Elem
.Next
;
3421 end Compute_Builder_Switches
;
3423 ---------------------
3424 -- Write_Path_File --
3425 ---------------------
3427 procedure Write_Path_File
(FD
: File_Descriptor
) is
3434 for Index
in Directories
.First
.. Directories
.Last
loop
3435 Add_Str_To_Name_Buffer
(Get_Name_String
(Directories
.Table
(Index
)));
3436 Add_Char_To_Name_Buffer
(ASCII
.LF
);
3439 Last
:= Write
(FD
, Name_Buffer
(1)'Address, Name_Len
);
3441 if Last
= Name_Len
then
3448 Prj
.Com
.Fail
("could not write temporary file");
3450 end Write_Path_File
;