1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2004-2014, 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 -- Aggregate_Libraries_In --
176 ----------------------------
178 function Aggregate_Libraries_In
(Tree
: Project_Tree_Ref
) return Boolean is
182 List
:= Tree
.Projects
;
183 while List
/= null loop
184 if List
.Project
.Qualifier
= Aggregate_Library
then
192 end Aggregate_Libraries_In
;
194 -------------------------
195 -- Base_Name_Index_For --
196 -------------------------
198 function Base_Name_Index_For
201 Index_Separator
: Character) return File_Name_Type
203 Result
: File_Name_Type
;
207 Add_Str_To_Name_Buffer
(Base_Name
(Main
));
209 -- Remove the extension, if any, that is the last part of the base name
210 -- starting with a dot and following some characters.
212 for J
in reverse 2 .. Name_Len
loop
213 if Name_Buffer
(J
) = '.' then
219 -- Add the index info, if index is different from 0
221 if Main_Index
> 0 then
222 Add_Char_To_Name_Buffer
(Index_Separator
);
225 Img
: constant String := Main_Index
'Img;
227 Add_Str_To_Name_Buffer
(Img
(2 .. Img
'Last));
233 end Base_Name_Index_For
;
235 ------------------------------
236 -- Check_Source_Info_In_ALI --
237 ------------------------------
239 function Check_Source_Info_In_ALI
241 Tree
: Project_Tree_Ref
) return Name_Id
243 Result
: Name_Id
:= No_Name
;
247 -- Loop through units
249 for U
in ALIs
.Table
(The_ALI
).First_Unit
..
250 ALIs
.Table
(The_ALI
).Last_Unit
252 -- Check if the file name is one of the source of the unit
254 Get_Name_String
(Units
.Table
(U
).Uname
);
255 Name_Len
:= Name_Len
- 2;
256 Unit_Name
:= Name_Find
;
258 if File_Not_A_Source_Of
(Tree
, Unit_Name
, Units
.Table
(U
).Sfile
) then
262 if Result
= No_Name
then
266 -- Loop to do same check for each of the withed units
268 for W
in Units
.Table
(U
).First_With
.. Units
.Table
(U
).Last_With
loop
270 WR
: ALI
.With_Record
renames Withs
.Table
(W
);
273 if WR
.Sfile
/= No_File
then
274 Get_Name_String
(WR
.Uname
);
275 Name_Len
:= Name_Len
- 2;
276 Unit_Name
:= Name_Find
;
278 if File_Not_A_Source_Of
(Tree
, Unit_Name
, WR
.Sfile
) then
286 -- Loop to check subunits and replaced sources
288 for D
in ALIs
.Table
(The_ALI
).First_Sdep
..
289 ALIs
.Table
(The_ALI
).Last_Sdep
292 SD
: Sdep_Record
renames Sdep
.Table
(D
);
295 Unit_Name
:= SD
.Subunit_Name
;
297 if Unit_Name
= No_Name
then
299 -- Check if this source file has been replaced by a source with
300 -- a different file name.
302 if Tree
/= null and then Tree
.Replaced_Source_Number
> 0 then
304 Replacement
: constant File_Name_Type
:=
305 Replaced_Source_HTable
.Get
306 (Tree
.Replaced_Sources
, SD
.Sfile
);
309 if Replacement
/= No_File
then
313 & Get_Name_String
(SD
.Sfile
)
314 & " has been replaced by "
315 & Get_Name_String
(Replacement
));
323 -- Check that a dependent source for a unit that is from a
324 -- project is indeed a source of this unit.
326 Unit_Name
:= SD
.Unit_Name
;
328 if Unit_Name
/= No_Name
329 and then not Fname
.Is_Internal_File_Name
(SD
.Sfile
)
330 and then File_Not_A_Source_Of
(Tree
, Unit_Name
, SD
.Sfile
)
336 -- For separates, the file is no longer associated with the
337 -- unit ("proc-sep.adb" is not associated with unit "proc.sep")
338 -- so we need to check whether the source file still exists in
339 -- the source tree: it will if it matches the naming scheme
340 -- (and then will be for the same unit).
344 Project
=> No_Project
,
345 Base_Name
=> SD
.Sfile
) = No_Source
347 -- If this is not a runtime file or if, when gnatmake switch
348 -- -a is used, we are not able to find this subunit in the
349 -- source directories, then recompilation is needed.
351 if not Fname
.Is_Internal_File_Name
(SD
.Sfile
)
353 (Check_Readonly_Files
354 and then Full_Source_Name
(SD
.Sfile
) = No_File
)
358 ("While parsing ALI file, file "
359 & Get_Name_String
(SD
.Sfile
)
360 & " is indicated as containing subunit "
361 & Get_Name_String
(Unit_Name
)
362 & " but this does not match what was found while"
363 & " parsing the project. Will recompile");
374 end Check_Source_Info_In_ALI
;
376 --------------------------------
377 -- Create_Binder_Mapping_File --
378 --------------------------------
380 function Create_Binder_Mapping_File
381 (Project_Tree
: Project_Tree_Ref
) return Path_Name_Type
383 Mapping_Path
: Path_Name_Type
:= No_Path
;
385 Mapping_FD
: File_Descriptor
:= Invalid_FD
;
386 -- A File Descriptor for an eventual mapping file
388 ALI_Unit
: Unit_Name_Type
:= No_Unit_Name
;
389 -- The unit name of an ALI file
391 ALI_Name
: File_Name_Type
:= No_File
;
392 -- The file name of the ALI file
394 ALI_Project
: Project_Id
:= No_Project
;
395 -- The project of the ALI file
398 OK
: Boolean := False;
404 Iter
: Source_Iterator
:= For_Each_Source
405 (In_Tree
=> Project_Tree
,
406 Language
=> Name_Ada
,
407 Encapsulated_Libs
=> False,
408 Locally_Removed
=> False);
410 Source
: Prj
.Source_Id
;
413 Tempdir
.Create_Temp_File
(Mapping_FD
, Mapping_Path
);
414 Record_Temp_File
(Project_Tree
.Shared
, Mapping_Path
);
416 if Mapping_FD
/= Invalid_FD
then
420 Source
:= Element
(Iter
);
421 exit when Source
= No_Source
;
425 if Source
.Replaced_By
/= No_Source
426 or else Unit
= No_Unit_Index
427 or else Unit
.Name
= No_Name
431 -- If this is a body, put it in the mapping
433 elsif Source
.Kind
= Impl
434 and then Unit
.File_Names
(Impl
) /= No_Source
435 and then Unit
.File_Names
(Impl
).Project
/= No_Project
437 Get_Name_String
(Unit
.Name
);
438 Add_Str_To_Name_Buffer
("%b");
439 ALI_Unit
:= Name_Find
;
441 Lib_File_Name
(Unit
.File_Names
(Impl
).Display_File
);
442 ALI_Project
:= Unit
.File_Names
(Impl
).Project
;
444 -- Otherwise, if this is a spec and there is no body, put it in
447 elsif Source
.Kind
= Spec
448 and then Unit
.File_Names
(Impl
) = No_Source
449 and then Unit
.File_Names
(Spec
) /= No_Source
450 and then Unit
.File_Names
(Spec
).Project
/= No_Project
452 Get_Name_String
(Unit
.Name
);
453 Add_Str_To_Name_Buffer
("%s");
454 ALI_Unit
:= Name_Find
;
456 Lib_File_Name
(Unit
.File_Names
(Spec
).Display_File
);
457 ALI_Project
:= Unit
.File_Names
(Spec
).Project
;
463 -- If we have something to put in the mapping then do it now. If
464 -- the project is extended, look for the ALI file in the project,
465 -- then in the extending projects in order, and use the last one
468 if ALI_Name
/= No_File
then
470 -- Look in the project and the projects that are extending it
471 -- to find the real ALI file.
474 ALI
: constant String := Get_Name_String
(ALI_Name
);
475 ALI_Path
: Name_Id
:= No_Name
;
479 -- For library projects, use the library ALI directory,
480 -- for other projects, use the object directory.
482 if ALI_Project
.Library
then
484 (ALI_Project
.Library_ALI_Dir
.Display_Name
);
487 (ALI_Project
.Object_Directory
.Display_Name
);
490 Add_Str_To_Name_Buffer
(ALI
);
492 if Is_Regular_File
(Name_Buffer
(1 .. Name_Len
)) then
493 ALI_Path
:= Name_Find
;
496 ALI_Project
:= ALI_Project
.Extended_By
;
497 exit when ALI_Project
= No_Project
;
500 if ALI_Path
/= No_Name
then
502 -- First line is the unit name
504 Get_Name_String
(ALI_Unit
);
505 Add_Char_To_Name_Buffer
(ASCII
.LF
);
509 Name_Buffer
(1)'Address,
511 OK
:= Bytes
= Name_Len
;
515 -- Second line is the ALI file name
517 Get_Name_String
(ALI_Name
);
518 Add_Char_To_Name_Buffer
(ASCII
.LF
);
522 Name_Buffer
(1)'Address,
524 OK
:= (Bytes
= Name_Len
);
528 -- Third line is the ALI path name
530 Get_Name_String
(ALI_Path
);
531 Add_Char_To_Name_Buffer
(ASCII
.LF
);
535 Name_Buffer
(1)'Address,
537 OK
:= (Bytes
= Name_Len
);
539 -- If OK is False, it means we were unable to write a
540 -- line. No point in continuing with the other units.
550 Close
(Mapping_FD
, Status
);
555 -- If the creation of the mapping file was successful, we add the switch
556 -- to the arguments of gnatbind.
564 end Create_Binder_Mapping_File
;
570 function Create_Name
(Name
: String) return File_Name_Type
is
573 Add_Str_To_Name_Buffer
(Name
);
577 function Create_Name
(Name
: String) return Name_Id
is
580 Add_Str_To_Name_Buffer
(Name
);
584 function Create_Name
(Name
: String) return Path_Name_Type
is
587 Add_Str_To_Name_Buffer
(Name
);
591 ---------------------------
592 -- Ensure_Absolute_Path --
593 ---------------------------
595 procedure Ensure_Absolute_Path
596 (Switch
: in out String_Access
;
599 For_Gnatbind
: Boolean := False;
600 Including_Non_Switch
: Boolean := True;
601 Including_RTS
: Boolean := False)
604 if Switch
/= null then
606 Sw
: String (1 .. Switch
'Length);
614 and then (Sw
(2) = 'I'
615 or else (not For_Gnatbind
616 and then (Sw
(2) = 'L'
627 and then (Sw
(2 .. 3) = "aL"
633 (For_Gnatbind
and then Sw
(2 .. 3) = "A="))
638 and then Sw
'Length >= 7
639 and then Sw
(2 .. 6) = "-RTS="
647 -- Because relative path arguments to --RTS= may be relative to
648 -- the search directory prefix, those relative path arguments
649 -- are converted only when they include directory information.
651 if not Is_Absolute_Path
(Sw
(Start
.. Sw
'Last)) then
652 if Parent
'Length = 0 then
654 ("relative search path switches ("""
656 & """) are not allowed");
658 elsif Including_RTS
then
659 for J
in Start
.. Sw
'Last loop
660 if Sw
(J
) = Directory_Separator
then
665 & Directory_Separator
666 & Sw (Start .. Sw'Last));
676 & Directory_Separator
677 & Sw
(Start
.. Sw
'Last));
681 elsif Including_Non_Switch
then
682 if not Is_Absolute_Path
(Sw
) then
683 if Parent
'Length = 0 then
685 ("relative paths (""" & Sw
& """) are not allowed");
687 Switch
:= new String'(Parent & Directory_Separator & Sw);
693 end Ensure_Absolute_Path;
695 ----------------------------
696 -- Executable_Prefix_Path --
697 ----------------------------
699 function Executable_Prefix_Path return String is
700 Exec_Name : constant String := Command_Name;
702 function Get_Install_Dir (S : String) return String;
703 -- S is the executable name preceded by the absolute or relative path,
704 -- e.g. "c:\usr\bin\gcc.exe". Returns the absolute directory where "bin"
705 -- lies (in the example "C:\usr"). If the executable is not in a "bin"
706 -- directory, return "".
708 ---------------------
709 -- Get_Install_Dir --
710 ---------------------
712 function Get_Install_Dir (S : String) return String is
714 Path_Last : Integer := 0;
717 for J in reverse Exec'Range loop
718 if Exec (J) = Directory_Separator then
724 if Path_Last >= Exec'First + 2 then
725 To_Lower (Exec (Path_Last - 2 .. Path_Last));
728 if Path_Last < Exec'First + 2
729 or else Exec (Path_Last - 2 .. Path_Last) /= "bin"
730 or else (Path_Last - 3 >= Exec'First
731 and then Exec (Path_Last - 3) /= Directory_Separator)
736 return Normalize_Pathname
737 (Exec (Exec'First .. Path_Last - 4),
738 Resolve_Links => Opt.Follow_Links_For_Dirs)
739 & Directory_Separator;
742 -- Beginning of Executable_Prefix_Path
745 -- For VMS, the path returned is always /gnu/
747 if Hostparm.OpenVMS then
751 -- First determine if a path prefix was placed in front of the
754 for J in reverse Exec_Name'Range loop
755 if Exec_Name (J) = Directory_Separator then
756 return Get_Install_Dir (Exec_Name);
760 -- If we get here, the user has typed the executable name with no
764 Path : String_Access := Locate_Exec_On_Path (Exec_Name);
770 Dir : constant String := Get_Install_Dir (Path.all);
777 end Executable_Prefix_Path;
783 procedure Fail_Program
784 (Project_Tree : Project_Tree_Ref;
786 Flush_Messages : Boolean := True)
789 if Flush_Messages then
790 if Total_Errors_Detected /= 0 or else Warnings_Detected /= 0 then
795 Finish_Program (Project_Tree, E_Fatal, S => S);
802 procedure Finish_Program
803 (Project_Tree : Project_Tree_Ref;
804 Exit_Code : Osint.Exit_Code_Type := Osint.E_Success;
808 if not Debug.Debug_Flag_N then
809 Delete_Temp_Config_Files (Project_Tree);
811 if Project_Tree /= null then
812 Delete_All_Temp_Files (Project_Tree.Shared);
817 if Exit_Code /= E_Success then
824 -- Output Namet statistics
828 Exit_Program (Exit_Code);
831 --------------------------
832 -- File_Not_A_Source_Of --
833 --------------------------
835 function File_Not_A_Source_Of
836 (Project_Tree : Project_Tree_Ref;
838 Sfile : File_Name_Type) return Boolean
840 Unit : constant Unit_Index :=
841 Units_Htable.Get (Project_Tree.Units_HT, Uname);
843 At_Least_One_File : Boolean := False;
846 if Unit /= No_Unit_Index then
847 for F in Unit.File_Names'Range loop
848 if Unit.File_Names (F) /= null then
849 At_Least_One_File := True;
850 if Unit.File_Names (F).File = Sfile then
856 if not At_Least_One_File then
858 -- The unit was probably created initially for a separate unit
859 -- (which are initially created as IMPL when both suffixes are the
860 -- same). Later on, Override_Kind changed the type of the file,
861 -- and the unit is no longer valid in fact.
866 Verbose_Msg (Uname, "sources do not include ", Name_Id (Sfile));
871 end File_Not_A_Source_Of;
873 ---------------------
874 -- Get_Directories --
875 ---------------------
877 procedure Get_Directories
878 (Project_Tree : Project_Tree_Ref;
879 For_Project : Project_Id;
880 Activity : Activity_Type;
881 Languages : Name_Ids)
884 procedure Recursive_Add
885 (Project : Project_Id;
886 Tree : Project_Tree_Ref;
887 Extended : in out Boolean);
888 -- Add all the source directories of a project to the path only if
889 -- this project has not been visited. Calls itself recursively for
890 -- projects being extended, and imported projects.
892 procedure Add_Dir (Value : Path_Name_Type);
893 -- Add directory Value in table Directories, if it is defined and not
900 procedure Add_Dir (Value : Path_Name_Type) is
901 Add_It : Boolean := True;
904 if Value /= No_Path then
905 for Index in 1 .. Directories.Last loop
906 if Directories.Table (Index) = Value then
913 Directories.Increment_Last;
914 Directories.Table (Directories.Last) := Value;
923 procedure Recursive_Add
924 (Project : Project_Id;
925 Tree : Project_Tree_Ref;
926 Extended : in out Boolean)
928 Current : String_List_Id;
929 Dir : String_Element;
930 OK : Boolean := False;
931 Lang_Proc : Language_Ptr := Project.Languages;
934 -- Add to path all directories of this project
936 if Activity = Compilation then
938 while Lang_Proc /= No_Language_Index loop
939 for J in Languages'Range loop
940 OK := Lang_Proc.Name = Languages (J);
941 exit Lang_Loop when OK;
944 Lang_Proc := Lang_Proc.Next;
948 Current := Project.Source_Dirs;
950 while Current /= Nil_String loop
951 Dir := Tree.Shared.String_Elements.Table (Current);
952 Add_Dir (Path_Name_Type (Dir.Value));
957 elsif Project.Library then
958 if Activity = SAL_Binding and then Extended then
959 Add_Dir (Project.Object_Directory.Display_Name);
962 Add_Dir (Project.Library_ALI_Dir.Display_Name);
966 Add_Dir (Project.Object_Directory.Display_Name);
969 if Project.Extends = No_Project then
974 procedure For_All_Projects is
975 new For_Every_Project_Imported (Boolean, Recursive_Add);
977 Extended : Boolean := True;
979 -- Start of processing for Get_Directories
983 For_All_Projects (For_Project, Project_Tree, Extended);
990 procedure Get_Switches
991 (Source : Prj.Source_Id;
993 Project_Tree : Project_Tree_Ref;
994 Value : out Variable_Value;
995 Is_Default : out Boolean)
999 (Source_File => Source.File,
1000 Source_Lang => Source.Language.Name,
1001 Source_Prj => Source.Project,
1002 Pkg_Name => Pkg_Name,
1003 Project_Tree => Project_Tree,
1005 Is_Default => Is_Default);
1012 procedure Get_Switches
1013 (Source_File : File_Name_Type;
1014 Source_Lang : Name_Id;
1015 Source_Prj : Project_Id;
1017 Project_Tree : Project_Tree_Ref;
1018 Value : out Variable_Value;
1019 Is_Default : out Boolean;
1020 Test_Without_Suffix : Boolean := False;
1021 Check_ALI_Suffix : Boolean := False)
1023 Project : constant Project_Id :=
1024 Ultimate_Extending_Project_Of (Source_Prj);
1025 Pkg : constant Package_Id :=
1028 In_Packages => Project.Decl.Packages,
1029 Shared => Project_Tree.Shared);
1030 Lang : Language_Ptr;
1033 Is_Default := False;
1035 if Source_File /= No_File then
1036 Value := Prj.Util.Value_Of
1037 (Name => Name_Id (Source_File),
1038 Attribute_Or_Array_Name => Name_Switches,
1040 Shared => Project_Tree.Shared,
1041 Allow_Wildcards => True);
1044 if Value = Nil_Variable_Value and then Test_Without_Suffix then
1046 Get_Language_From_Name (Project, Get_Name_String (Source_Lang));
1048 if Lang /= null then
1050 Naming : Lang_Naming_Data renames Lang.Config.Naming_Data;
1051 SF_Name : constant String := Get_Name_String (Source_File);
1052 Last : Positive := SF_Name'Length;
1053 Name : String (1 .. Last + 3);
1054 Spec_Suffix : String := Get_Name_String (Naming.Spec_Suffix);
1055 Body_Suffix : String := Get_Name_String (Naming.Body_Suffix);
1056 Truncated : Boolean := False;
1059 Canonical_Case_File_Name (Spec_Suffix);
1060 Canonical_Case_File_Name (Body_Suffix);
1061 Name (1 .. Last) := SF_Name;
1063 if Last > Body_Suffix'Length
1065 Name (Last - Body_Suffix'Length + 1 .. Last) = Body_Suffix
1068 Last := Last - Body_Suffix'Length;
1072 and then Last > Spec_Suffix'Length
1074 Name (Last - Spec_Suffix'Length + 1 .. Last) = Spec_Suffix
1077 Last := Last - Spec_Suffix'Length;
1082 Add_Str_To_Name_Buffer (Name (1 .. Last));
1084 Value := Prj.Util.Value_Of
1086 Attribute_Or_Array_Name => Name_Switches,
1088 Shared => Project_Tree.Shared,
1089 Allow_Wildcards => True);
1092 if Value = Nil_Variable_Value and then Check_ALI_Suffix then
1093 Last := SF_Name'Length;
1094 while Name (Last) /= '.' loop
1099 Add_Str_To_Name_Buffer (Name (1 .. Last));
1100 Add_Str_To_Name_Buffer ("ali");
1102 Value := Prj.Util.Value_Of
1104 Attribute_Or_Array_Name => Name_Switches,
1106 Shared => Project_Tree.Shared,
1107 Allow_Wildcards => True);
1113 if Value = Nil_Variable_Value then
1117 (Name => Source_Lang,
1118 Attribute_Or_Array_Name => Name_Switches,
1120 Shared => Project_Tree.Shared,
1121 Force_Lower_Case_Index => True);
1124 if Value = Nil_Variable_Value then
1127 (Name => All_Other_Names,
1128 Attribute_Or_Array_Name => Name_Switches,
1130 Shared => Project_Tree.Shared,
1131 Force_Lower_Case_Index => True);
1134 if Value = Nil_Variable_Value then
1137 (Name => Source_Lang,
1138 Attribute_Or_Array_Name => Name_Default_Switches,
1140 Shared => Project_Tree.Shared);
1148 procedure Inform (N : File_Name_Type; Msg : String) is
1150 Inform (Name_Id (N), Msg);
1153 procedure Inform (N : Name_Id := No_Name; Msg : String) is
1155 Osint.Write_Program_Name;
1159 if N /= No_Name then
1163 Name : constant String := Get_Name_String (N);
1165 if Debug.Debug_Flag_F and then Is_Absolute_Path (Name) then
1166 Write_Str (File_Name (Name));
1179 ------------------------------
1180 -- Initialize_Source_Record --
1181 ------------------------------
1183 procedure Initialize_Source_Record (Source : Prj.Source_Id) is
1185 procedure Set_Object_Project
1187 Obj_Proj : Project_Id;
1188 Obj_Path : Path_Name_Type;
1189 Stamp : Time_Stamp_Type);
1190 -- Update information about object file, switches file,...
1192 ------------------------
1193 -- Set_Object_Project --
1194 ------------------------
1196 procedure Set_Object_Project
1198 Obj_Proj : Project_Id;
1199 Obj_Path : Path_Name_Type;
1200 Stamp : Time_Stamp_Type) is
1202 Source.Object_Project := Obj_Proj;
1203 Source.Object_Path := Obj_Path;
1204 Source.Object_TS := Stamp;
1206 if Source.Language.Config.Dependency_Kind /= None then
1208 Dep_Path : constant String :=
1211 Get_Name_String (Source.Dep_Name),
1212 Resolve_Links => Opt.Follow_Links_For_Files,
1213 Directory => Obj_Dir);
1215 Source.Dep_Path := Create_Name (Dep_Path);
1216 Source.Dep_TS := Osint.Unknown_Attributes;
1220 -- Get the path of the switches file, even if Opt.Check_Switches is
1221 -- not set, as switch -s may be in the Builder switches that have not
1222 -- been scanned yet.
1225 Switches_Path : constant String :=
1228 Get_Name_String (Source.Switches),
1229 Resolve_Links => Opt.Follow_Links_For_Files,
1230 Directory => Obj_Dir);
1232 Source.Switches_Path := Create_Name (Switches_Path);
1234 if Stamp /= Empty_Time_Stamp then
1235 Source.Switches_TS := File_Stamp (Source.Switches_Path);
1238 end Set_Object_Project;
1240 Obj_Proj : Project_Id;
1243 -- Nothing to do if source record has already been fully initialized
1245 if Source.Initialized then
1249 -- Systematically recompute the time stamp
1251 Source.Source_TS := File_Stamp (Source.Path.Display_Name);
1253 -- Parse the source file to check whether we have a subunit
1255 if Source.Language.Config.Kind = Unit_Based
1256 and then Source.Kind = Impl
1257 and then Is_Subunit (Source)
1262 if Source.Language.Config.Object_Generated
1263 and then Is_Compilable (Source)
1265 -- First, get the correct object file name and dependency file name
1266 -- if the source is in a multi-unit file.
1268 if Source.Index /= 0 then
1271 (Source_File_Name => Source.File,
1272 Source_Index => Source.Index,
1274 Source.Language.Config.Multi_Unit_Object_Separator,
1275 Object_File_Suffix =>
1276 Source.Language.Config.Object_File_Suffix);
1280 (Source.Object, Source.Language.Config.Dependency_Kind);
1283 -- Find the object file for that source. It could be either in the
1284 -- current project or in an extended project (it might actually not
1285 -- exist yet in the ultimate extending project, but if not found
1286 -- elsewhere that's where we'll expect to find it).
1288 Obj_Proj := Source.Project;
1290 while Obj_Proj /= No_Project loop
1291 if Obj_Proj.Object_Directory /= No_Path_Information then
1293 Dir : constant String :=
1294 Get_Name_String (Obj_Proj.Object_Directory.Display_Name);
1296 Object_Path : constant String :=
1298 (Name => Get_Name_String (Source.Object),
1299 Resolve_Links => Opt.Follow_Links_For_Files,
1302 Obj_Path : constant Path_Name_Type :=
1303 Create_Name (Object_Path);
1305 Stamp : Time_Stamp_Type := Empty_Time_Stamp;
1308 -- For specs, we do not check object files if there is a
1309 -- body. This saves a system call. On the other hand, we do
1310 -- need to know the object_path, in case the user has passed
1311 -- the .ads on the command line to compile the spec only.
1313 if Source.Kind /= Spec
1314 or else Source.Unit = No_Unit_Index
1315 or else Source.Unit.File_Names (Impl) = No_Source
1317 Stamp := File_Stamp (Obj_Path);
1320 if Stamp /= Empty_Time_Stamp
1321 or else (Obj_Proj.Extended_By = No_Project
1322 and then Source.Object_Project = No_Project)
1324 Set_Object_Project (Dir, Obj_Proj, Obj_Path, Stamp);
1329 Obj_Proj := Obj_Proj.Extended_By;
1332 elsif Source.Language.Config.Dependency_Kind = Makefile then
1334 Object_Dir : constant String :=
1335 Get_Name_String (Source.Project.Object_Directory.Display_Name);
1336 Dep_Path : constant String :=
1338 (Name => Get_Name_String (Source.Dep_Name),
1339 Resolve_Links => Opt.Follow_Links_For_Files,
1340 Directory => Object_Dir);
1342 Source.Dep_Path := Create_Name (Dep_Path);
1343 Source.Dep_TS := Osint.Unknown_Attributes;
1347 Source.Initialized := True;
1348 end Initialize_Source_Record;
1350 ----------------------------
1351 -- Is_External_Assignment --
1352 ----------------------------
1354 function Is_External_Assignment
1355 (Env : Prj.Tree.Environment;
1356 Argv : String) return Boolean
1358 Start : Positive := 3;
1359 Finish : Natural := Argv'Last;
1361 pragma Assert (Argv'First = 1);
1362 pragma Assert (Argv (1 .. 2) = "-X");
1365 if Argv'Last < 5 then
1368 elsif Argv (3) = '"' then
1369 if Argv (Argv'Last) /= '"' or else Argv'Last < 7 then
1373 Finish := Argv'Last - 1;
1377 return Prj.Ext.Check
1378 (Self => Env.External,
1379 Declaration => Argv (Start .. Finish));
1380 end Is_External_Assignment;
1386 function Is_Subunit (Source : Prj.Source_Id) return Boolean is
1387 Src_Ind : Source_File_Index;
1390 if Source.Kind = Sep then
1393 -- A Spec, a file based language source or a body with a spec cannot be
1396 elsif Source.Kind = Spec
1397 or else Source.Unit = No_Unit_Index
1398 or else Other_Part (Source) /= No_Source
1403 -- Here, we are assuming that the language is Ada, as it is the only
1404 -- unit based language that we know.
1407 Sinput.P.Load_Project_File
1408 (Get_Name_String (Source.Path.Display_Name));
1410 return Sinput.P.Source_File_Is_Subunit (Src_Ind);
1413 -----------------------------
1414 -- Linker_Options_Switches --
1415 -----------------------------
1417 function Linker_Options_Switches
1418 (Project : Project_Id;
1419 Do_Fail : Fail_Proc;
1420 In_Tree : Project_Tree_Ref) return String_List
1422 procedure Recursive_Add
1424 In_Tree : Project_Tree_Ref;
1425 Dummy : in out Boolean);
1426 -- The recursive routine used to add linker options
1432 procedure Recursive_Add
1434 In_Tree : Project_Tree_Ref;
1435 Dummy : in out Boolean)
1437 pragma Unreferenced (Dummy);
1439 Linker_Package : Package_Id;
1440 Options : Variable_Value;
1445 (Name => Name_Linker,
1446 In_Packages => Proj.Decl.Packages,
1447 Shared => In_Tree.Shared);
1453 Attribute_Or_Array_Name => Name_Linker_Options,
1454 In_Package => Linker_Package,
1455 Shared => In_Tree.Shared);
1457 -- If attribute is present, add the project with the attribute to
1458 -- table Linker_Opts.
1460 if Options /= Nil_Variable_Value then
1461 Linker_Opts.Increment_Last;
1462 Linker_Opts.Table (Linker_Opts.Last) :=
1463 (Project => Proj, Options => Options.Values);
1467 procedure For_All_Projects is
1468 new For_Every_Project_Imported (Boolean, Recursive_Add);
1470 Dummy : Boolean := False;
1472 -- Start of processing for Linker_Options_Switches
1477 For_All_Projects (Project, In_Tree, Dummy, Imported_First => True);
1479 Last_Linker_Option := 0;
1481 for Index in reverse 1 .. Linker_Opts.Last loop
1483 Options : String_List_Id;
1484 Proj : constant Project_Id :=
1485 Linker_Opts.Table (Index).Project;
1487 Dir_Path : constant String :=
1488 Get_Name_String (Proj.Directory.Name);
1491 Options := Linker_Opts.Table (Index).Options;
1492 while Options /= Nil_String loop
1493 Option := In_Tree.Shared.String_Elements.Table (Options).Value;
1494 Get_Name_String (Option);
1496 -- Do not consider empty linker options
1498 if Name_Len /= 0 then
1499 Add_Linker_Option (Name_Buffer (1 .. Name_Len));
1501 -- Object files and -L switches specified with relative
1502 -- paths must be converted to absolute paths.
1504 Ensure_Absolute_Path
1506 Linker_Options_Buffer (Last_Linker_Option),
1509 For_Gnatbind => False);
1512 Options := In_Tree.Shared.String_Elements.Table (Options).Next;
1517 return Linker_Options_Buffer (1 .. Last_Linker_Option);
1518 end Linker_Options_Switches;
1524 package body Mains is
1526 package Names is new Table.Table
1527 (Table_Component_Type => Main_Info,
1528 Table_Index_Type => Integer,
1529 Table_Low_Bound => 1,
1530 Table_Initial => 10,
1531 Table_Increment => 100,
1532 Table_Name => "Makeutl.Mains.Names");
1533 -- The table that stores the mains
1535 Current : Natural := 0;
1536 -- The index of the last main retrieved from the table
1538 Count_Of_Mains_With_No_Tree : Natural := 0;
1539 -- Number of main units for which we do not know the project tree
1548 Location : Source_Ptr := No_Location;
1549 Project : Project_Id := No_Project;
1550 Tree : Project_Tree_Ref := null)
1553 if Current_Verbosity = High then
1554 Debug_Output ("Add_Main """ & Name & """ " & Index'Img
1556 & Boolean'Image (Tree /= null));
1560 Add_Str_To_Name_Buffer (Name);
1561 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1563 Names.Increment_Last;
1564 Names.Table (Names.Last) :=
1565 (Name_Find, Index, Location, No_Source, Project, Tree);
1567 if Tree /= null then
1568 Builder_Data (Tree).Number_Of_Mains :=
1569 Builder_Data (Tree).Number_Of_Mains + 1;
1572 Mains.Count_Of_Mains_With_No_Tree :=
1573 Mains.Count_Of_Mains_With_No_Tree + 1;
1577 --------------------
1578 -- Complete_Mains --
1579 --------------------
1581 procedure Complete_Mains
1582 (Flags : Processing_Flags;
1583 Root_Project : Project_Id;
1584 Project_Tree : Project_Tree_Ref)
1586 procedure Do_Complete (Project : Project_Id; Tree : Project_Tree_Ref);
1587 -- Check the mains for this specific project
1589 procedure Complete_All is new For_Project_And_Aggregated
1592 procedure Add_Multi_Unit_Sources
1593 (Tree : Project_Tree_Ref;
1594 Source : Prj.Source_Id);
1595 -- Add all units from the same file as the multi-unit Source
1597 function Find_File_Add_Extension
1598 (Tree : Project_Tree_Ref;
1599 Base_Main : String) return Prj.Source_Id;
1600 -- Search for Main in the project, adding body or spec extensions
1602 ----------------------------
1603 -- Add_Multi_Unit_Sources --
1604 ----------------------------
1606 procedure Add_Multi_Unit_Sources
1607 (Tree : Project_Tree_Ref;
1608 Source : Prj.Source_Id)
1610 Iter : Source_Iterator;
1611 Src : Prj.Source_Id;
1615 ("found multi-unit source file in project", Source.Project.Name);
1617 Iter := For_Each_Source
1618 (In_Tree => Tree, Project => Source.Project);
1620 while Element (Iter) /= No_Source loop
1621 Src := Element (Iter);
1623 if Src.File = Source.File
1624 and then Src.Index /= Source.Index
1626 if Src.File = Source.File then
1628 ("add main in project, index=" & Src.Index'Img);
1631 Names.Increment_Last;
1632 Names.Table (Names.Last) :=
1635 Location => No_Location,
1637 Project => Src.Project,
1640 Builder_Data (Tree).Number_Of_Mains :=
1641 Builder_Data (Tree).Number_Of_Mains + 1;
1646 end Add_Multi_Unit_Sources;
1648 -----------------------------
1649 -- Find_File_Add_Extension --
1650 -----------------------------
1652 function Find_File_Add_Extension
1653 (Tree : Project_Tree_Ref;
1654 Base_Main : String) return Prj.Source_Id
1656 Spec_Source : Prj.Source_Id := No_Source;
1657 Source : Prj.Source_Id;
1658 Iter : Source_Iterator;
1659 Suffix : File_Name_Type;
1662 Source := No_Source;
1663 Iter := For_Each_Source (Tree); -- In all projects
1665 Source := Prj.Element (Iter);
1666 exit when Source = No_Source;
1668 if Source.Kind = Impl then
1669 Get_Name_String (Source.File);
1671 if Name_Len > Base_Main'Length
1672 and then Name_Buffer (1 .. Base_Main'Length) = Base_Main
1675 Source.Language.Config.Naming_Data.Body_Suffix;
1677 if Suffix /= No_File then
1679 Suffix_Str : String := Get_Name_String (Suffix);
1681 Canonical_Case_File_Name (Suffix_Str);
1683 Name_Buffer (Base_Main'Length + 1 .. Name_Len) =
1689 elsif Source.Kind = Spec
1690 and then Source.Language.Config.Kind = Unit_Based
1692 -- An Ada spec needs to be taken into account unless there
1693 -- is also a body. So we delay the decision for them.
1695 Get_Name_String (Source.File);
1697 if Name_Len > Base_Main'Length
1698 and then Name_Buffer (1 .. Base_Main'Length) = Base_Main
1700 Suffix := Source.Language.Config.Naming_Data.Spec_Suffix;
1702 if Suffix /= No_File then
1704 Suffix_Str : String := Get_Name_String (Suffix);
1707 Canonical_Case_File_Name (Suffix_Str);
1709 if Name_Buffer (Base_Main'Length + 1 .. Name_Len) =
1712 Spec_Source := Source;
1722 if Source = No_Source then
1723 Source := Spec_Source;
1727 end Find_File_Add_Extension;
1733 procedure Do_Complete
1734 (Project : Project_Id; Tree : Project_Tree_Ref)
1739 if Mains.Number_Of_Mains (Tree) > 0
1740 or else Mains.Count_Of_Mains_With_No_Tree > 0
1742 -- Traverse in reverse order, since in the case of multi-unit
1743 -- files we will be adding extra files at the end, and there's
1744 -- no need to process them in turn.
1749 File : Main_Info := Names.Table (J);
1750 Main_Id : File_Name_Type := File.File;
1751 Main : constant String :=
1752 Get_Name_String (Main_Id);
1753 Base : constant String := Base_Name (Main);
1754 Source : Prj.Source_Id := No_Source;
1755 Is_Absolute : Boolean := False;
1758 if Base /= Main then
1759 Is_Absolute := True;
1761 if Is_Absolute_Path (Main) then
1762 Main_Id := Create_Name (Base);
1764 -- Not an absolute path
1767 -- Always resolve links here, so that users can be
1768 -- specify any name on the command line. If the
1769 -- project itself uses links, the user will be
1770 -- using -eL anyway, and thus files are also stored
1771 -- with resolved names.
1774 Absolute : constant String :=
1778 Resolve_Links => True,
1779 Case_Sensitive => False);
1781 File.File := Create_Name (Absolute);
1782 Main_Id := Create_Name (Base);
1787 -- If no project or tree was specified for the main, it
1788 -- came from the command line.
1789 -- Note that the assignments below will not modify inside
1790 -- the table itself.
1792 if File.Project = null then
1793 File.Project := Project;
1796 if File.Tree = null then
1800 if File.Source = null then
1801 if Current_Verbosity = High then
1803 ("search for main """ & Main
1804 & '"' & File.Index'Img & " in "
1805 & Get_Name_String (Debug_Name (File.Tree))
1806 & ", project
", Project.Name);
1809 -- First, look for the main as specified. We need to
1810 -- search for the base name though, and if needed
1811 -- check later that we found the correct file.
1814 Sources : constant Source_Ids :=
1816 (In_Tree => File.Tree,
1817 Project => File.Project,
1818 Base_Name => Main_Id,
1819 Index => File.Index,
1820 In_Imported_Only => True);
1824 for J in Sources'Range loop
1825 if File_Name_Type (Sources (J).Path.Name) =
1828 Source := Sources (J);
1833 elsif Sources'Length > 1 then
1835 -- This is only allowed if the units are from
1836 -- the same multi-unit source file.
1838 Source := Sources (1);
1840 for J in 2 .. Sources'Last loop
1841 if Sources (J).Path /= Source.Path
1842 or else Sources (J).Index = Source.Index
1844 Error_Msg_File_1 := Main_Id;
1846 (Flags, "several main sources
{",
1847 No_Location, File.Project);
1852 elsif Sources'Length = 1 then
1853 Source := Sources (Sources'First);
1857 if Source = No_Source then
1858 Source := Find_File_Add_Extension
1859 (File.Tree, Get_Name_String (Main_Id));
1863 and then Source /= No_Source
1865 File_Name_Type (Source.Path.Name) /= File.File
1868 ("Found a non
-matching file
",
1869 Name_Id (Source.Path.Display_Name));
1870 Source := No_Source;
1873 if Source /= No_Source then
1874 if not Is_Allowed_Language
1875 (Source.Language.Name)
1877 -- Remove any main that is not in the list of
1878 -- restricted languages.
1880 Names.Table (J .. Names.Last - 1) :=
1881 Names.Table (J + 1 .. Names.Last);
1882 Names.Set_Last (Names.Last - 1);
1885 -- If we have found a multi-unit source file but
1886 -- did not specify an index initially, we'll
1887 -- need to compile all the units from the same
1890 if Source.Index /= 0 and then File.Index = 0 then
1891 Add_Multi_Unit_Sources (File.Tree, Source);
1894 -- Now update the original Main, otherwise it
1895 -- will be reported as not found.
1898 ("found main
in project
", Source.Project.Name);
1899 Names.Table (J).File := Source.File;
1900 Names.Table (J).Project := Source.Project;
1902 if Names.Table (J).Tree = null then
1903 Names.Table (J).Tree := File.Tree;
1905 Builder_Data (File.Tree).Number_Of_Mains :=
1906 Builder_Data (File.Tree).Number_Of_Mains
1908 Mains.Count_Of_Mains_With_No_Tree :=
1909 Mains.Count_Of_Mains_With_No_Tree - 1;
1912 Names.Table (J).Source := Source;
1913 Names.Table (J).Index := Source.Index;
1916 elsif File.Location /= No_Location then
1918 -- If the main is declared in package Builder of
1919 -- the main project, report an error. If the main
1920 -- is on the command line, it may be a main from
1921 -- another project, so do nothing: if the main does
1922 -- not exist in another project, an error will be
1925 Error_Msg_File_1 := Main_Id;
1926 Error_Msg_Name_1 := File.Project.Name;
1928 (Flags, "{ is not a source
of project
%%",
1929 File.Location, File.Project);
1935 exit Main_Loop when J < Names.First;
1939 if Total_Errors_Detected > 0 then
1940 Fail_Program (Tree, "problems
with main sources
");
1944 -- Start of processing for Complete_Mains
1947 Complete_All (Root_Project, Project_Tree);
1949 if Mains.Count_Of_Mains_With_No_Tree > 0 then
1950 for J in Names.First .. Names.Last loop
1951 if Names.Table (J).Source = No_Source then
1953 (Project_Tree, '"' & Get_Name_String (Names.Table (J).File)
1954 & """ is not a source of any project");
1970 -----------------------
1971 -- Fill_From_Project --
1972 -----------------------
1974 procedure Fill_From_Project
1975 (Root_Project : Project_Id;
1976 Project_Tree : Project_Tree_Ref)
1978 procedure Add_Mains_From_Project
1979 (Project : Project_Id;
1980 Tree : Project_Tree_Ref);
1981 -- Add the main units from this project into Mains.
1982 -- This takes into account the aggregated projects
1984 ----------------------------
1985 -- Add_Mains_From_Project --
1986 ----------------------------
1988 procedure Add_Mains_From_Project
1989 (Project : Project_Id;
1990 Tree : Project_Tree_Ref)
1992 List : String_List_Id;
1993 Element : String_Element;
1996 if Number_Of_Mains (Tree) = 0
1997 and then Mains.Count_Of_Mains_With_No_Tree = 0
1999 Debug_Output ("Add_Mains_From_Project", Project.Name);
2000 List := Project.Mains;
2002 if List /= Prj.Nil_String then
2004 -- The attribute Main is not an empty list. Get the mains in
2007 while List /= Prj.Nil_String loop
2008 Element := Tree.Shared.String_Elements.Table (List);
2009 Debug_Output ("Add_Main", Element.Value);
2011 if Project.Library then
2014 "cannot specify a main program "
2015 & "for a library project file");
2018 Add_Main (Name => Get_Name_String (Element.Value),
2019 Index => Element.Index,
2020 Location => Element.Location,
2023 List := Element.Next;
2028 if Total_Errors_Detected > 0 then
2029 Fail_Program (Tree, "problems with main sources");
2031 end Add_Mains_From_Project;
2033 procedure Fill_All is new For_Project_And_Aggregated
2034 (Add_Mains_From_Project);
2036 -- Start of processing for Fill_From_Project
2039 Fill_All (Root_Project, Project_Tree);
2040 end Fill_From_Project;
2046 function Next_Main return String is
2047 Info : constant Main_Info := Next_Main;
2049 if Info = No_Main_Info then
2052 return Get_Name_String (Info.File);
2056 function Next_Main return Main_Info is
2058 if Current >= Names.Last then
2059 return No_Main_Info;
2061 Current := Current + 1;
2063 -- If not using projects, and in the gnatmake case, the main file
2064 -- may have not have the extension. Try ".adb" first then ".ads"
2066 if Names.Table (Current).Project = No_Project then
2068 Orig_Main : constant File_Name_Type :=
2069 Names.Table (Current).File;
2070 Current_Main : File_Name_Type;
2073 if Strip_Suffix (Orig_Main) = Orig_Main then
2074 Get_Name_String (Orig_Main);
2075 Add_Str_To_Name_Buffer (".adb");
2076 Current_Main := Name_Find;
2078 if Full_Source_Name (Current_Main) = No_File then
2079 Get_Name_String (Orig_Main);
2080 Add_Str_To_Name_Buffer (".ads");
2081 Current_Main := Name_Find;
2083 if Full_Source_Name (Current_Main) /= No_File then
2084 Names.Table (Current).File := Current_Main;
2088 Names.Table (Current).File := Current_Main;
2094 return Names.Table (Current);
2098 ---------------------
2099 -- Number_Of_Mains --
2100 ---------------------
2102 function Number_Of_Mains (Tree : Project_Tree_Ref) return Natural is
2107 return Builder_Data (Tree).Number_Of_Mains;
2109 end Number_Of_Mains;
2120 --------------------------
2121 -- Set_Multi_Unit_Index --
2122 --------------------------
2124 procedure Set_Multi_Unit_Index
2125 (Project_Tree : Project_Tree_Ref := null;
2130 if Names.Last = 0 then
2133 "cannot specify a multi-unit index but no main "
2134 & "on the command line");
2136 elsif Names.Last > 1 then
2139 "cannot specify several mains with a multi-unit index");
2142 Names.Table (Names.Last).Index := Index;
2145 end Set_Multi_Unit_Index;
2149 -----------------------
2150 -- Path_Or_File_Name --
2151 -----------------------
2153 function Path_Or_File_Name (Path : Path_Name_Type) return String is
2154 Path_Name : constant String := Get_Name_String (Path);
2156 if Debug.Debug_Flag_F then
2157 return File_Name (Path_Name);
2161 end Path_Or_File_Name;
2167 function Unit_Index_Of (ALI_File : File_Name_Type) return Int is
2173 Get_Name_String (ALI_File);
2175 -- First, find the last dot
2179 while Finish >= 1 and then Name_Buffer (Finish) /= '.' loop
2180 Finish := Finish - 1;
2187 -- Now check that the dot is preceded by digits
2190 Finish := Finish - 1;
2191 while Start >= 1 and then Name_Buffer (Start - 1) in '0' .. '9' loop
2195 -- If there are no digits, or if the digits are not preceded by the
2196 -- character that precedes a unit index, this is not the ALI file of
2197 -- a unit in a multi-unit source.
2201 or else Name_Buffer (Start - 1) /= Multi_Unit_Index_Character
2206 -- Build the index from the digit(s)
2208 while Start <= Finish loop
2209 Result := Result * 10 +
2210 Character'Pos (Name_Buffer (Start)) - Character'Pos ('0');
2221 procedure Verbose_Msg
2224 N2 : Name_Id := No_Name;
2226 Prefix : String := " -> ";
2227 Minimum_Verbosity : Opt.Verbosity_Level_Type := Opt.Low)
2230 if not Opt.Verbose_Mode
2231 or else Minimum_Verbosity > Opt.Verbosity_Level
2242 if N2 /= No_Name then
2252 procedure Verbose_Msg
2253 (N1 : File_Name_Type;
2255 N2 : File_Name_Type := No_File;
2257 Prefix : String := " -> ";
2258 Minimum_Verbosity : Opt.Verbosity_Level_Type := Opt.Low)
2262 (Name_Id (N1), S1, Name_Id (N2), S2, Prefix, Minimum_Verbosity);
2269 package body Queue is
2271 type Q_Record is record
2273 Processed : Boolean;
2276 package Q is new Table.Table
2277 (Table_Component_Type => Q_Record,
2278 Table_Index_Type => Natural,
2279 Table_Low_Bound => 1,
2280 Table_Initial => 1000,
2281 Table_Increment => 100,
2282 Table_Name => "Makeutl.Queue.Q");
2283 -- This is the actual Queue
2285 package Busy_Obj_Dirs is new GNAT.HTable.Simple_HTable
2286 (Header_Num => Prj.Header_Num,
2288 No_Element => False,
2289 Key => Path_Name_Type,
2293 type Mark_Key is record
2294 File : File_Name_Type;
2297 -- Identify either a mono-unit source (when Index = 0) or a specific
2298 -- unit (index = 1's origin index of unit) in a multi-unit source.
2300 Max_Mask_Num : constant := 2048;
2301 subtype Mark_Num is Union_Id range 0 .. Max_Mask_Num - 1;
2303 function Hash (Key : Mark_Key) return Mark_Num;
2305 package Marks is new GNAT.HTable.Simple_HTable
2306 (Header_Num => Mark_Num,
2308 No_Element => False,
2312 -- A hash table to keep tracks of the marked units.
2313 -- These are the units that have already been processed, when using the
2314 -- gnatmake format. When using the gprbuild format, we can directly
2315 -- store in the source_id whether the file has already been processed.
2317 procedure Mark (Source_File : File_Name_Type; Index : Int := 0);
2318 -- Mark a unit, identified by its source file and, when Index is not 0,
2319 -- the index of the unit in the source file. Marking is used to signal
2320 -- that the unit has already been inserted in the Q.
2323 (Source_File : File_Name_Type;
2324 Index : Int := 0) return Boolean;
2325 -- Returns True if the unit was previously marked
2327 Q_Processed : Natural := 0;
2328 Q_Initialized : Boolean := False;
2330 Q_First : Natural := 1;
2331 -- Points to the first valid element in the queue
2333 One_Queue_Per_Obj_Dir : Boolean := False;
2334 -- See parameter to Initialize
2336 function Available_Obj_Dir (S : Source_Info) return Boolean;
2337 -- Whether the object directory for S is available for a build
2339 procedure Debug_Display (S : Source_Info);
2340 -- A debug display for S
2342 function Was_Processed (S : Source_Info) return Boolean;
2343 -- Whether S has already been processed. This marks the source as
2344 -- processed, if it hasn't already been processed.
2346 function Insert_No_Roots (Source : Source_Info) return Boolean;
2347 -- Insert Source, but do not look for its roots (see doc for Insert)
2353 function Was_Processed (S : Source_Info) return Boolean is
2356 when Format_Gprbuild =>
2357 if S.Id.In_The_Queue then
2361 S.Id.In_The_Queue := True;
2363 when Format_Gnatmake =>
2364 if Is_Marked (S.File, S.Index) then
2368 Mark (S.File, Index => S.Index);
2374 -----------------------
2375 -- Available_Obj_Dir --
2376 -----------------------
2378 function Available_Obj_Dir (S : Source_Info) return Boolean is
2381 when Format_Gprbuild =>
2382 return not Busy_Obj_Dirs.Get
2383 (S.Id.Project.Object_Directory.Name);
2385 when Format_Gnatmake =>
2386 return S.Project = No_Project
2388 not Busy_Obj_Dirs.Get (S.Project.Object_Directory.Name);
2390 end Available_Obj_Dir;
2396 procedure Debug_Display (S : Source_Info) is
2399 when Format_Gprbuild =>
2400 Write_Name (S.Id.File);
2402 if S.Id.Index /= 0 then
2404 Write_Int (S.Id.Index);
2407 when Format_Gnatmake =>
2408 Write_Name (S.File);
2410 if S.Index /= 0 then
2412 Write_Int (S.Index);
2421 function Hash (Key : Mark_Key) return Mark_Num is
2423 return Union_Id (Key.File) mod Max_Mask_Num;
2431 (Source_File : File_Name_Type;
2432 Index : Int := 0) return Boolean
2435 return Marks.Get (K => (File => Source_File, Index => Index));
2442 procedure Mark (Source_File : File_Name_Type; Index : Int := 0) is
2444 Marks.Set (K => (File => Source_File, Index => Index), E => True);
2452 (Found : out Boolean;
2453 Source : out Source_Info)
2458 if One_Queue_Per_Obj_Dir then
2459 for J in Q_First .. Q.Last loop
2460 if not Q.Table (J).Processed
2461 and then Available_Obj_Dir (Q.Table (J).Info)
2464 Source := Q.Table (J).Info;
2465 Q.Table (J).Processed := True;
2468 while Q_First <= Q.Last
2469 and then Q.Table (Q_First).Processed
2471 Q_First := Q_First + 1;
2479 elsif Q_First <= Q.Last then
2480 Source := Q.Table (Q_First).Info;
2481 Q.Table (Q_First).Processed := True;
2482 Q_First := Q_First + 1;
2487 Q_Processed := Q_Processed + 1;
2490 if Found and then Debug.Debug_Flag_Q then
2491 Write_Str (" Q := Q - [ ");
2492 Debug_Display (Source);
2496 Write_Str (" Q_First =");
2497 Write_Int (Int (Q_First));
2500 Write_Str (" Q.Last =");
2501 Write_Int (Int (Q.Last));
2510 function Processed return Natural is
2519 procedure Initialize
2520 (Queue_Per_Obj_Dir : Boolean;
2521 Force : Boolean := False)
2524 if Force or else not Q_Initialized then
2525 Q_Initialized := True;
2527 for J in 1 .. Q.Last loop
2528 case Q.Table (J).Info.Format is
2529 when Format_Gprbuild =>
2530 Q.Table (J).Info.Id.In_The_Queue := False;
2531 when Format_Gnatmake =>
2539 One_Queue_Per_Obj_Dir := Queue_Per_Obj_Dir;
2543 ---------------------
2544 -- Insert_No_Roots --
2545 ---------------------
2547 function Insert_No_Roots (Source : Source_Info) return Boolean is
2550 (Source.Format = Format_Gnatmake or else Source.Id /= No_Source);
2552 -- Only insert in the Q if it is not already done, to avoid
2553 -- simultaneous compilations if -jnnn is used.
2555 if Was_Processed (Source) then
2559 -- For gprbuild, check if a source has already been inserted in the
2560 -- queue from the same project in a different project tree.
2562 if Source.Format = Format_Gprbuild then
2563 for J in 1 .. Q.Last loop
2564 if Source.Id.Path.Name = Q.Table (J).Info.Id.Path.Name
2565 and then Source.Id.Index = Q.Table (J).Info.Id.Index
2566 and then Source.Id.Project.Path.Name =
2567 Q.Table (J).Info.Id.Project.Path.Name
2569 -- No need to insert this source in the queue, but still
2570 -- return True as we may need to insert its roots.
2577 if Current_Verbosity = High then
2578 Write_Str ("Adding """);
2579 Debug_Display (Source);
2580 Write_Line (""" to the queue");
2583 Q.Append (New_Val => (Info => Source, Processed => False));
2585 if Debug.Debug_Flag_Q then
2586 Write_Str (" Q := Q + [ ");
2587 Debug_Display (Source);
2591 Write_Str (" Q_First =");
2592 Write_Int (Int (Q_First));
2595 Write_Str (" Q.Last =");
2596 Write_Int (Int (Q.Last));
2601 end Insert_No_Roots;
2608 (Source : Source_Info;
2609 With_Roots : Boolean := False) return Boolean
2611 Root_Arr : Array_Element_Id;
2612 Roots : Variable_Value;
2613 List : String_List_Id;
2614 Elem : String_Element;
2615 Unit_Name : Name_Id;
2617 Root_Pattern : Regexp;
2618 Root_Found : Boolean;
2619 Roots_Found : Boolean;
2620 Root_Source : Prj.Source_Id;
2621 Iter : Source_Iterator;
2624 pragma Unreferenced (Dummy);
2627 if not Insert_No_Roots (Source) then
2629 -- Was already in the queue
2634 if With_Roots and then Source.Format = Format_Gprbuild then
2635 Debug_Output ("looking for roots of", Name_Id (Source.Id.File));
2639 (Name => Name_Roots,
2640 In_Arrays => Source.Id.Project.Decl.Arrays,
2641 Shared => Source.Tree.Shared);
2645 (Index => Name_Id (Source.Id.File),
2647 In_Array => Root_Arr,
2648 Shared => Source.Tree.Shared);
2650 -- If there is no roots for the specific main, try the language
2652 if Roots = Nil_Variable_Value then
2655 (Index => Source.Id.Language.Name,
2657 In_Array => Root_Arr,
2658 Shared => Source.Tree.Shared,
2659 Force_Lower_Case_Index => True);
2664 if Roots = Nil_Variable_Value then
2666 Name_Buffer (1) := '*';
2670 (Index => Name_Find,
2672 In_Array => Root_Arr,
2673 Shared => Source.Tree.Shared,
2674 Force_Lower_Case_Index => True);
2677 if Roots = Nil_Variable_Value then
2678 Debug_Output (" -> no roots declared");
2681 List := Roots.Values;
2684 while List /= Nil_String loop
2685 Elem := Source.Tree.Shared.String_Elements.Table (List);
2686 Get_Name_String (Elem.Value);
2687 To_Lower (Name_Buffer (1 .. Name_Len));
2688 Unit_Name := Name_Find;
2690 -- Check if it is a unit name or a pattern
2694 for J in 1 .. Name_Len loop
2695 if Name_Buffer (J) not in 'a
' .. 'z
' and then
2696 Name_Buffer (J) not in '0' .. '9' and then
2697 Name_Buffer (J) /= '_
' and then
2698 Name_Buffer (J) /= '.'
2709 (Pattern => Name_Buffer (1 .. Name_Len),
2713 when Error_In_Regexp =>
2714 Err_Vars.Error_Msg_Name_1 := Unit_Name;
2716 ("invalid pattern %", Roots.Location);
2721 Roots_Found := False;
2722 Iter := For_Each_Source (Source.Tree);
2726 Root_Source := Prj.Element (Iter);
2727 exit Source_Loop when Root_Source = No_Source;
2729 Root_Found := False;
2731 Root_Found := Root_Source.Unit /= No_Unit_Index
2733 (Get_Name_String (Root_Source.Unit.Name),
2738 Root_Source.Unit /= No_Unit_Index
2739 and then Root_Source.Unit.Name = Unit_Name;
2743 case Root_Source.Kind is
2748 Root_Found := Other_Part (Root_Source) = No_Source;
2751 Root_Found := False;
2756 Roots_Found := True;
2758 (" -> ", Name_Id (Root_Source.Display_File));
2759 Dummy := Queue.Insert_No_Roots
2760 (Source => (Format => Format_Gprbuild,
2761 Tree => Source.Tree,
2762 Id => Root_Source));
2764 Initialize_Source_Record (Root_Source);
2766 if Other_Part (Root_Source) /= No_Source then
2767 Initialize_Source_Record (Other_Part (Root_Source));
2770 -- Save the root for the binder
2772 Source.Id.Roots := new Source_Roots'
2773 (Root
=> Root_Source
,
2774 Next
=> Source
.Id
.Roots
);
2776 exit Source_Loop
when not Pat_Root
;
2780 end loop Source_Loop
;
2782 if not Roots_Found
then
2784 if not Quiet_Output
then
2785 Error_Msg_Name_1
:= Unit_Name
;
2787 ("?no unit matches pattern %", Roots
.Location
);
2792 ("Unit " & Get_Name_String
(Unit_Name
)
2793 & " does not exist", Roots
.Location
);
2798 end loop Pattern_Loop
;
2810 (Source
: Source_Info
;
2811 With_Roots
: Boolean := False)
2815 Discard
:= Insert
(Source
, With_Roots
);
2822 function Is_Empty
return Boolean is
2824 return Q_Processed
>= Q
.Last
;
2827 ------------------------
2828 -- Is_Virtually_Empty --
2829 ------------------------
2831 function Is_Virtually_Empty
return Boolean is
2833 if One_Queue_Per_Obj_Dir
then
2834 for J
in Q_First
.. Q
.Last
loop
2835 if not Q
.Table
(J
).Processed
2836 and then Available_Obj_Dir
(Q
.Table
(J
).Info
)
2847 end Is_Virtually_Empty
;
2849 ----------------------
2850 -- Set_Obj_Dir_Busy --
2851 ----------------------
2853 procedure Set_Obj_Dir_Busy
(Obj_Dir
: Path_Name_Type
) is
2855 if One_Queue_Per_Obj_Dir
then
2856 Busy_Obj_Dirs
.Set
(Obj_Dir
, True);
2858 end Set_Obj_Dir_Busy
;
2860 ----------------------
2861 -- Set_Obj_Dir_Free --
2862 ----------------------
2864 procedure Set_Obj_Dir_Free
(Obj_Dir
: Path_Name_Type
) is
2866 if One_Queue_Per_Obj_Dir
then
2867 Busy_Obj_Dirs
.Set
(Obj_Dir
, False);
2869 end Set_Obj_Dir_Free
;
2875 function Size
return Natural is
2884 function Element
(Rank
: Positive) return File_Name_Type
is
2886 if Rank
<= Q
.Last
then
2887 case Q
.Table
(Rank
).Info
.Format
is
2888 when Format_Gprbuild
=>
2889 return Q
.Table
(Rank
).Info
.Id
.File
;
2890 when Format_Gnatmake
=>
2891 return Q
.Table
(Rank
).Info
.File
;
2902 procedure Remove_Marks
is
2907 ----------------------------
2908 -- Insert_Project_Sources --
2909 ----------------------------
2911 procedure Insert_Project_Sources
2912 (Project
: Project_Id
;
2913 Project_Tree
: Project_Tree_Ref
;
2914 All_Projects
: Boolean;
2915 Unique_Compile
: Boolean)
2917 procedure Do_Insert
(Project
: Project_Id
; Tree
: Project_Tree_Ref
);
2923 procedure Do_Insert
(Project
: Project_Id
; Tree
: Project_Tree_Ref
) is
2924 Unit_Based
: constant Boolean :=
2926 or else not Builder_Data
(Tree
).Closure_Needed
;
2927 -- When Unit_Based is True, put in the queue all compilable
2928 -- sources including the unit based (Ada) one. When Unit_Based is
2929 -- False, put the Ada sources only when they are in a library
2932 Iter
: Source_Iterator
;
2933 Source
: Prj
.Source_Id
;
2936 -- Nothing to do when "-u" was specified and some files were
2937 -- specified on the command line
2940 and then Mains
.Number_Of_Mains
(Tree
) > 0
2945 Iter
:= For_Each_Source
(Tree
);
2947 Source
:= Prj
.Element
(Iter
);
2948 exit when Source
= No_Source
;
2950 if Is_Allowed_Language
(Source
.Language
.Name
)
2951 and then Is_Compilable
(Source
)
2954 or else Is_Extending
(Project
, Source
.Project
))
2955 and then not Source
.Locally_Removed
2956 and then Source
.Replaced_By
= No_Source
2958 (not Source
.Project
.Externally_Built
2960 (Is_Extending
(Project
, Source
.Project
)
2961 and then not Project
.Externally_Built
))
2962 and then Source
.Kind
/= Sep
2963 and then Source
.Path
/= No_Path_Information
2965 if Source
.Kind
= Impl
2966 or else (Source
.Unit
/= No_Unit_Index
2967 and then Source
.Kind
= Spec
2968 and then (Other_Part
(Source
) = No_Source
2970 Other_Part
(Source
).Locally_Removed
))
2973 or else Source
.Unit
= No_Unit_Index
2974 or else Source
.Project
.Library
)
2975 and then not Is_Subunit
(Source
)
2978 (Source
=> (Format
=> Format_Gprbuild
,
2989 procedure Insert_All
is new For_Project_And_Aggregated
(Do_Insert
);
2992 Insert_All
(Project
, Project_Tree
);
2993 end Insert_Project_Sources
;
2995 -------------------------------
2996 -- Insert_Withed_Sources_For --
2997 -------------------------------
2999 procedure Insert_Withed_Sources_For
3000 (The_ALI
: ALI
.ALI_Id
;
3001 Project_Tree
: Project_Tree_Ref
;
3002 Excluding_Shared_SALs
: Boolean := False)
3004 Sfile
: File_Name_Type
;
3005 Afile
: File_Name_Type
;
3006 Src_Id
: Prj
.Source_Id
;
3009 -- Insert in the queue the unmarked source files (i.e. those which
3010 -- have never been inserted in the queue and hence never considered).
3012 for J
in ALI
.ALIs
.Table
(The_ALI
).First_Unit
..
3013 ALI
.ALIs
.Table
(The_ALI
).Last_Unit
3015 for K
in ALI
.Units
.Table
(J
).First_With
..
3016 ALI
.Units
.Table
(J
).Last_With
3018 Sfile
:= ALI
.Withs
.Table
(K
).Sfile
;
3022 if Sfile
/= No_File
then
3023 Afile
:= ALI
.Withs
.Table
(K
).Afile
;
3025 Src_Id
:= Source_Files_Htable
.Get
3026 (Project_Tree
.Source_Files_HT
, Sfile
);
3027 while Src_Id
/= No_Source
loop
3028 Initialize_Source_Record
(Src_Id
);
3030 if Is_Compilable
(Src_Id
)
3031 and then Src_Id
.Dep_Name
= Afile
3036 Bdy
: constant Prj
.Source_Id
:=
3037 Other_Part
(Src_Id
);
3040 and then not Bdy
.Locally_Removed
3042 Src_Id
:= Other_Part
(Src_Id
);
3047 if Is_Subunit
(Src_Id
) then
3048 Src_Id
:= No_Source
;
3052 Src_Id
:= No_Source
;
3058 Src_Id
:= Src_Id
.Next_With_File_Name
;
3061 -- If Excluding_Shared_SALs is True, do not insert in the
3062 -- queue the sources of a shared Stand-Alone Library.
3064 if Src_Id
/= No_Source
3065 and then (not Excluding_Shared_SALs
3066 or else Src_Id
.Project
.Standalone_Library
= No
3067 or else Src_Id
.Project
.Library_Kind
= Static
)
3070 (Source
=> (Format
=> Format_Gprbuild
,
3071 Tree
=> Project_Tree
,
3077 end Insert_Withed_Sources_For
;
3085 procedure Free
(Data
: in out Builder_Project_Tree_Data
) is
3086 procedure Unchecked_Free
is new Ada
.Unchecked_Deallocation
3087 (Binding_Data_Record
, Binding_Data
);
3089 TmpB
, Binding
: Binding_Data
:= Data
.Binding
;
3092 while Binding
/= null loop
3093 TmpB
:= Binding
.Next
;
3094 Unchecked_Free
(Binding
);
3103 function Builder_Data
3104 (Tree
: Project_Tree_Ref
) return Builder_Data_Access
3107 if Tree
.Appdata
= null then
3108 Tree
.Appdata
:= new Builder_Project_Tree_Data
;
3111 return Builder_Data_Access
(Tree
.Appdata
);
3114 --------------------------------
3115 -- Compute_Compilation_Phases --
3116 --------------------------------
3118 procedure Compute_Compilation_Phases
3119 (Tree
: Project_Tree_Ref
;
3120 Root_Project
: Project_Id
;
3121 Option_Unique_Compile
: Boolean := False; -- Was "-u" specified ?
3122 Option_Compile_Only
: Boolean := False; -- Was "-c" specified ?
3123 Option_Bind_Only
: Boolean := False;
3124 Option_Link_Only
: Boolean := False)
3126 procedure Do_Compute
(Project
: Project_Id
; Tree
: Project_Tree_Ref
);
3132 procedure Do_Compute
(Project
: Project_Id
; Tree
: Project_Tree_Ref
) is
3133 Data
: constant Builder_Data_Access
:= Builder_Data
(Tree
);
3134 All_Phases
: constant Boolean :=
3135 not Option_Compile_Only
3136 and then not Option_Bind_Only
3137 and then not Option_Link_Only
;
3138 -- Whether the command line asked for all three phases. Depending on
3139 -- the project settings, we might still disable some of the phases.
3141 Has_Mains
: constant Boolean := Data
.Number_Of_Mains
> 0;
3142 -- Whether there are some main units defined for this project tree
3143 -- (either from one of the projects, or from the command line)
3146 if Option_Unique_Compile
then
3148 -- If -u or -U is specified on the command line, disregard any -c,
3149 -- -b or -l switch: only perform compilation.
3151 Data
.Closure_Needed
:= False;
3152 Data
.Need_Compilation
:= True;
3153 Data
.Need_Binding
:= False;
3154 Data
.Need_Linking
:= False;
3157 Data
.Closure_Needed
:= Has_Mains
;
3158 Data
.Need_Compilation
:= All_Phases
or Option_Compile_Only
;
3159 Data
.Need_Binding
:= All_Phases
or Option_Bind_Only
;
3160 Data
.Need_Linking
:= (All_Phases
or Option_Link_Only
)
3164 if Current_Verbosity
= High
then
3165 Debug_Output
("compilation phases: "
3166 & " compile=" & Data
.Need_Compilation
'Img
3167 & " bind=" & Data
.Need_Binding
'Img
3168 & " link=" & Data
.Need_Linking
'Img
3169 & " closure=" & Data
.Closure_Needed
'Img
3170 & " mains=" & Data
.Number_Of_Mains
'Img,
3175 procedure Compute_All
is new For_Project_And_Aggregated
(Do_Compute
);
3178 Compute_All
(Root_Project
, Tree
);
3179 end Compute_Compilation_Phases
;
3181 ------------------------------
3182 -- Compute_Builder_Switches --
3183 ------------------------------
3185 procedure Compute_Builder_Switches
3186 (Project_Tree
: Project_Tree_Ref
;
3187 Env
: in out Prj
.Tree
.Environment
;
3188 Main_Project
: Project_Id
;
3189 Only_For_Lang
: Name_Id
:= No_Name
)
3191 Builder_Package
: constant Package_Id
:=
3192 Value_Of
(Name_Builder
, Main_Project
.Decl
.Packages
,
3193 Project_Tree
.Shared
);
3195 Global_Compilation_Array
: Array_Element_Id
;
3196 Global_Compilation_Elem
: Array_Element
;
3197 Global_Compilation_Switches
: Variable_Value
;
3199 Default_Switches_Array
: Array_Id
;
3201 Builder_Switches_Lang
: Name_Id
:= No_Name
;
3203 List
: String_List_Id
;
3204 Element
: String_Element
;
3207 Source
: Prj
.Source_Id
;
3209 Lang
: Name_Id
:= No_Name
; -- language index for Switches
3210 Switches_For_Lang
: Variable_Value
:= Nil_Variable_Value
;
3211 -- Value of Builder'Default_Switches(lang)
3213 Name
: Name_Id
:= No_Name
; -- main file index for Switches
3214 Switches_For_Main
: Variable_Value
:= Nil_Variable_Value
;
3215 -- Switches for a specific main. When there are several mains, Name is
3216 -- set to No_Name, and Switches_For_Main might be left with an actual
3217 -- value (so that we can display a warning that it was ignored).
3219 Other_Switches
: Variable_Value
:= Nil_Variable_Value
;
3220 -- Value of Builder'Switches(others)
3222 Defaults
: Variable_Value
:= Nil_Variable_Value
;
3224 Switches
: Variable_Value
:= Nil_Variable_Value
;
3225 -- The computed builder switches
3227 Success
: Boolean := False;
3229 if Builder_Package
/= No_Package
then
3232 -- If there is no main, and there is only one compilable language,
3233 -- use this language as the switches index.
3235 if Mains
.Number_Of_Mains
(Project_Tree
) = 0 then
3236 if Only_For_Lang
= No_Name
then
3238 Language
: Language_Ptr
:= Main_Project
.Languages
;
3241 while Language
/= No_Language_Index
loop
3242 if Language
.Config
.Compiler_Driver
/= No_File
3243 and then Language
.Config
.Compiler_Driver
/= Empty_File
3245 if Lang
/= No_Name
then
3249 Lang
:= Language
.Name
;
3252 Language
:= Language
.Next
;
3256 Lang
:= Only_For_Lang
;
3260 for Index
in 1 .. Mains
.Number_Of_Mains
(Project_Tree
) loop
3261 Source
:= Mains
.Next_Main
.Source
;
3263 if Source
/= No_Source
then
3264 if Switches_For_Main
= Nil_Variable_Value
then
3265 Switches_For_Main
:= Value_Of
3266 (Name
=> Name_Id
(Source
.File
),
3267 Attribute_Or_Array_Name
=> Name_Switches
,
3268 In_Package
=> Builder_Package
,
3269 Shared
=> Project_Tree
.Shared
,
3270 Force_Lower_Case_Index
=> False,
3271 Allow_Wildcards
=> True);
3273 -- If not found, try without extension.
3274 -- That's because gnatmake accepts truncated file names
3275 -- in Builder'Switches
3277 if Switches_For_Main
= Nil_Variable_Value
3278 and then Source
.Unit
/= null
3280 Switches_For_Main
:= Value_Of
3281 (Name
=> Source
.Unit
.Name
,
3282 Attribute_Or_Array_Name
=> Name_Switches
,
3283 In_Package
=> Builder_Package
,
3284 Shared
=> Project_Tree
.Shared
,
3285 Force_Lower_Case_Index
=> False,
3286 Allow_Wildcards
=> True);
3291 Lang
:= Source
.Language
.Name
;
3292 Name
:= Name_Id
(Source
.File
);
3294 Name
:= No_Name
; -- Can't use main specific switches
3296 if Lang
/= Source
.Language
.Name
then
3304 Global_Compilation_Array
:= Value_Of
3305 (Name
=> Name_Global_Compilation_Switches
,
3306 In_Arrays
=> Project_Tree
.Shared
.Packages
.Table
3307 (Builder_Package
).Decl
.Arrays
,
3308 Shared
=> Project_Tree
.Shared
);
3310 Default_Switches_Array
:=
3311 Project_Tree
.Shared
.Packages
.Table
(Builder_Package
).Decl
.Arrays
;
3313 while Default_Switches_Array
/= No_Array
3315 Project_Tree
.Shared
.Arrays
.Table
(Default_Switches_Array
).Name
/=
3316 Name_Default_Switches
3318 Default_Switches_Array
:=
3319 Project_Tree
.Shared
.Arrays
.Table
(Default_Switches_Array
).Next
;
3322 if Global_Compilation_Array
/= No_Array_Element
3323 and then Default_Switches_Array
/= No_Array
3327 "Default_Switches forbidden in presence of "
3328 & "Global_Compilation_Switches. Use Switches instead.",
3329 Project_Tree
.Shared
.Arrays
.Table
3330 (Default_Switches_Array
).Location
);
3332 (Project_Tree
, "*** illegal combination of Builder attributes");
3335 if Lang
/= No_Name
then
3336 Switches_For_Lang
:= Prj
.Util
.Value_Of
3339 Attribute_Or_Array_Name
=> Name_Switches
,
3340 In_Package
=> Builder_Package
,
3341 Shared
=> Project_Tree
.Shared
,
3342 Force_Lower_Case_Index
=> True);
3344 Defaults
:= Prj
.Util
.Value_Of
3347 Attribute_Or_Array_Name
=> Name_Default_Switches
,
3348 In_Package
=> Builder_Package
,
3349 Shared
=> Project_Tree
.Shared
,
3350 Force_Lower_Case_Index
=> True);
3353 Other_Switches
:= Prj
.Util
.Value_Of
3354 (Name
=> All_Other_Names
,
3356 Attribute_Or_Array_Name
=> Name_Switches
,
3357 In_Package
=> Builder_Package
,
3358 Shared
=> Project_Tree
.Shared
);
3361 and then Mains
.Number_Of_Mains
(Project_Tree
) > 1
3362 and then Switches_For_Main
/= Nil_Variable_Value
3364 -- More than one main, but we had main-specific switches that
3367 if Switches_For_Lang
/= Nil_Variable_Value
then
3369 ("Warning: using Builder'Switches("""
3370 & Get_Name_String
(Lang
)
3371 & """), as there are several mains");
3373 elsif Other_Switches
/= Nil_Variable_Value
then
3375 ("Warning: using Builder'Switches(others), "
3376 & "as there are several mains");
3378 elsif Defaults
/= Nil_Variable_Value
then
3380 ("Warning: using Builder'Default_Switches("""
3381 & Get_Name_String
(Lang
)
3382 & """), as there are several mains");
3385 ("Warning: using no switches from package "
3386 & "Builder, as there are several mains");
3390 Builder_Switches_Lang
:= Lang
;
3392 if Name
/= No_Name
then
3393 -- Get the switches for the single main
3394 Switches
:= Switches_For_Main
;
3397 if Switches
= Nil_Variable_Value
or else Switches
.Default
then
3398 -- Get the switches for the common language of the mains
3399 Switches
:= Switches_For_Lang
;
3402 if Switches
= Nil_Variable_Value
or else Switches
.Default
then
3403 Switches
:= Other_Switches
;
3406 -- For backward compatibility with gnatmake, if no Switches
3407 -- are declared, check for Default_Switches (<language>).
3409 if Switches
= Nil_Variable_Value
or else Switches
.Default
then
3410 Switches
:= Defaults
;
3413 -- If switches have been found, scan them
3415 if Switches
/= Nil_Variable_Value
and then not Switches
.Default
then
3416 List
:= Switches
.Values
;
3418 while List
/= Nil_String
loop
3419 Element
:= Project_Tree
.Shared
.String_Elements
.Table
(List
);
3420 Get_Name_String
(Element
.Value
);
3422 if Name_Len
/= 0 then
3424 -- Add_Switch might itself be using the name_buffer, so
3425 -- we make a temporary here.
3426 Switch
: constant String := Name_Buffer
(1 .. Name_Len
);
3428 Success
:= Add_Switch
3430 For_Lang
=> Builder_Switches_Lang
,
3431 For_Builder
=> True,
3432 Has_Global_Compilation_Switches
=>
3433 Global_Compilation_Array
/= No_Array_Element
);
3437 for J
in reverse 1 .. Name_Len
loop
3438 Name_Buffer
(J
+ J
) := Name_Buffer
(J
);
3439 Name_Buffer
(J
+ J
- 1) := ''';
3442 Name_Len
:= Name_Len
+ Name_Len
;
3446 '"' & Name_Buffer
(1 .. Name_Len
)
3447 & """ is not a builder switch. Consider moving "
3448 & "it to Global_Compilation_Switches.",
3452 "*** illegal switch """
3453 & Get_Name_String
(Element
.Value
) & '"');
3457 List
:= Element
.Next
;
3461 -- Reset the Builder Switches language
3463 Builder_Switches_Lang
:= No_Name
;
3465 -- Take into account attributes Global_Compilation_Switches
3467 while Global_Compilation_Array
/= No_Array_Element
loop
3468 Global_Compilation_Elem
:=
3469 Project_Tree
.Shared
.Array_Elements
.Table
3470 (Global_Compilation_Array
);
3472 Get_Name_String
(Global_Compilation_Elem
.Index
);
3473 To_Lower
(Name_Buffer
(1 .. Name_Len
));
3476 if Only_For_Lang
= No_Name
or else Index
= Only_For_Lang
then
3477 Global_Compilation_Switches
:= Global_Compilation_Elem
.Value
;
3479 if Global_Compilation_Switches
/= Nil_Variable_Value
3480 and then not Global_Compilation_Switches
.Default
3482 -- We have found an attribute
3483 -- Global_Compilation_Switches for a language: put the
3484 -- switches in the appropriate table.
3486 List
:= Global_Compilation_Switches
.Values
;
3487 while List
/= Nil_String
loop
3489 Project_Tree
.Shared
.String_Elements
.Table
(List
);
3491 if Element
.Value
/= No_Name
then
3492 Success
:= Add_Switch
3493 (Switch
=> Get_Name_String
(Element
.Value
),
3495 For_Builder
=> False,
3496 Has_Global_Compilation_Switches
=>
3497 Global_Compilation_Array
/= No_Array_Element
);
3500 List
:= Element
.Next
;
3505 Global_Compilation_Array
:= Global_Compilation_Elem
.Next
;
3508 end Compute_Builder_Switches
;
3510 ---------------------
3511 -- Write_Path_File --
3512 ---------------------
3514 procedure Write_Path_File
(FD
: File_Descriptor
) is
3521 for Index
in Directories
.First
.. Directories
.Last
loop
3522 Add_Str_To_Name_Buffer
(Get_Name_String
(Directories
.Table
(Index
)));
3523 Add_Char_To_Name_Buffer
(ASCII
.LF
);
3526 Last
:= Write
(FD
, Name_Buffer
(1)'Address, Name_Len
);
3528 if Last
= Name_Len
then
3535 Prj
.Com
.Fail
("could not write temporary file");
3537 end Write_Path_File
;