cfgloopmanip.c (copy_loop_info): New function.
[official-gcc.git] / gcc / ada / makeutl.adb
bloba2ea435269dec8f3499e1424f41c9dc23db3948b
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- M A K E U T L --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2004-2012, Free Software Foundation, Inc. --
10 -- --
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. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with ALI; use ALI;
27 with Debug;
28 with Err_Vars; use Err_Vars;
29 with Errutil;
30 with Fname;
31 with Hostparm;
32 with Osint; use Osint;
33 with Output; use Output;
34 with Opt; use Opt;
35 with Prj.Com;
36 with Prj.Err;
37 with Prj.Ext;
38 with Prj.Util; use Prj.Util;
39 with Sinput.P;
40 with Tempdir;
42 with Ada.Command_Line; use Ada.Command_Line;
43 with Ada.Unchecked_Deallocation;
45 with GNAT.Case_Util; use GNAT.Case_Util;
46 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
47 with GNAT.HTable;
48 with GNAT.Regexp; use GNAT.Regexp;
50 package body Makeutl is
52 type Linker_Options_Data is record
53 Project : Project_Id;
54 Options : String_List_Id;
55 end record;
57 Linker_Option_Initial_Count : constant := 20;
59 Linker_Options_Buffer : String_List_Access :=
60 new String_List (1 .. Linker_Option_Initial_Count);
62 Last_Linker_Option : Natural := 0;
64 package Linker_Opts is new Table.Table (
65 Table_Component_Type => Linker_Options_Data,
66 Table_Index_Type => Integer,
67 Table_Low_Bound => 1,
68 Table_Initial => 10,
69 Table_Increment => 100,
70 Table_Name => "Make.Linker_Opts");
72 procedure Add_Linker_Option (Option : String);
74 ---------
75 -- Add --
76 ---------
78 procedure Add
79 (Option : String_Access;
80 To : in out String_List_Access;
81 Last : in out Natural)
83 begin
84 if Last = To'Last then
85 declare
86 New_Options : constant String_List_Access :=
87 new String_List (1 .. To'Last * 2);
89 begin
90 New_Options (To'Range) := To.all;
92 -- Set all elements of the original options to null to avoid
93 -- deallocation of copies.
95 To.all := (others => null);
97 Free (To);
98 To := New_Options;
99 end;
100 end if;
102 Last := Last + 1;
103 To (Last) := Option;
104 end Add;
106 procedure Add
107 (Option : String;
108 To : in out String_List_Access;
109 Last : in out Natural)
111 begin
112 Add (Option => new String'(Option), To => To, Last => Last);
113 end Add;
115 -----------------------
116 -- Add_Linker_Option --
117 -----------------------
119 procedure Add_Linker_Option (Option : String) is
120 begin
121 if Option'Length > 0 then
122 if Last_Linker_Option = Linker_Options_Buffer'Last then
123 declare
124 New_Buffer : constant String_List_Access :=
125 new String_List
126 (1 .. Linker_Options_Buffer'Last +
127 Linker_Option_Initial_Count);
128 begin
129 New_Buffer (Linker_Options_Buffer'Range) :=
130 Linker_Options_Buffer.all;
131 Linker_Options_Buffer.all := (others => null);
132 Free (Linker_Options_Buffer);
133 Linker_Options_Buffer := New_Buffer;
134 end;
135 end if;
137 Last_Linker_Option := Last_Linker_Option + 1;
138 Linker_Options_Buffer (Last_Linker_Option) := new String'(Option);
139 end if;
140 end Add_Linker_Option;
142 -------------------
143 -- Absolute_Path --
144 -------------------
146 function Absolute_Path
147 (Path : Path_Name_Type;
148 Project : Project_Id) return String
150 begin
151 Get_Name_String (Path);
153 declare
154 Path_Name : constant String := Name_Buffer (1 .. Name_Len);
156 begin
157 if Is_Absolute_Path (Path_Name) then
158 return Path_Name;
160 else
161 declare
162 Parent_Directory : constant String :=
163 Get_Name_String
164 (Project.Directory.Display_Name);
166 begin
167 return Parent_Directory & Path_Name;
168 end;
169 end if;
170 end;
171 end Absolute_Path;
173 -------------------------
174 -- Base_Name_Index_For --
175 -------------------------
177 function Base_Name_Index_For
178 (Main : String;
179 Main_Index : Int;
180 Index_Separator : Character) return File_Name_Type
182 Result : File_Name_Type;
184 begin
185 Name_Len := 0;
186 Add_Str_To_Name_Buffer (Base_Name (Main));
188 -- Remove the extension, if any, that is the last part of the base name
189 -- starting with a dot and following some characters.
191 for J in reverse 2 .. Name_Len loop
192 if Name_Buffer (J) = '.' then
193 Name_Len := J - 1;
194 exit;
195 end if;
196 end loop;
198 -- Add the index info, if index is different from 0
200 if Main_Index > 0 then
201 Add_Char_To_Name_Buffer (Index_Separator);
203 declare
204 Img : constant String := Main_Index'Img;
205 begin
206 Add_Str_To_Name_Buffer (Img (2 .. Img'Last));
207 end;
208 end if;
210 Result := Name_Find;
211 return Result;
212 end Base_Name_Index_For;
214 ------------------------------
215 -- Check_Source_Info_In_ALI --
216 ------------------------------
218 function Check_Source_Info_In_ALI
219 (The_ALI : ALI_Id;
220 Tree : Project_Tree_Ref) return Name_Id
222 Result : Name_Id := No_Name;
223 Unit_Name : Name_Id;
225 begin
226 -- Loop through units
228 for U in ALIs.Table (The_ALI).First_Unit ..
229 ALIs.Table (The_ALI).Last_Unit
230 loop
231 -- Check if the file name is one of the source of the unit
233 Get_Name_String (Units.Table (U).Uname);
234 Name_Len := Name_Len - 2;
235 Unit_Name := Name_Find;
237 if File_Not_A_Source_Of (Tree, Unit_Name, Units.Table (U).Sfile) then
238 return No_Name;
239 end if;
241 if Result = No_Name then
242 Result := Unit_Name;
243 end if;
245 -- Loop to do same check for each of the withed units
247 for W in Units.Table (U).First_With .. Units.Table (U).Last_With loop
248 declare
249 WR : ALI.With_Record renames Withs.Table (W);
251 begin
252 if WR.Sfile /= No_File then
253 Get_Name_String (WR.Uname);
254 Name_Len := Name_Len - 2;
255 Unit_Name := Name_Find;
257 if File_Not_A_Source_Of (Tree, Unit_Name, WR.Sfile) then
258 return No_Name;
259 end if;
260 end if;
261 end;
262 end loop;
263 end loop;
265 -- Loop to check subunits and replaced sources
267 for D in ALIs.Table (The_ALI).First_Sdep ..
268 ALIs.Table (The_ALI).Last_Sdep
269 loop
270 declare
271 SD : Sdep_Record renames Sdep.Table (D);
273 begin
274 Unit_Name := SD.Subunit_Name;
276 if Unit_Name = No_Name then
278 -- Check if this source file has been replaced by a source with
279 -- a different file name.
281 if Tree /= null and then Tree.Replaced_Source_Number > 0 then
282 declare
283 Replacement : constant File_Name_Type :=
284 Replaced_Source_HTable.Get
285 (Tree.Replaced_Sources, SD.Sfile);
287 begin
288 if Replacement /= No_File then
289 if Verbose_Mode then
290 Write_Line
291 ("source file" &
292 Get_Name_String (SD.Sfile) &
293 " has been replaced by " &
294 Get_Name_String (Replacement));
295 end if;
297 return No_Name;
298 end if;
299 end;
300 end if;
302 else
303 -- For separates, the file is no longer associated with the
304 -- unit ("proc-sep.adb" is not associated with unit "proc.sep")
305 -- so we need to check whether the source file still exists in
306 -- the source tree: it will if it matches the naming scheme
307 -- (and then will be for the same unit).
309 if Find_Source
310 (In_Tree => Tree,
311 Project => No_Project,
312 Base_Name => SD.Sfile) = No_Source
313 then
314 -- If this is not a runtime file or if, when gnatmake switch
315 -- -a is used, we are not able to find this subunit in the
316 -- source directories, then recompilation is needed.
318 if not Fname.Is_Internal_File_Name (SD.Sfile)
319 or else
320 (Check_Readonly_Files
321 and then Full_Source_Name (SD.Sfile) = No_File)
322 then
323 if Verbose_Mode then
324 Write_Line
325 ("While parsing ALI file, file "
326 & Get_Name_String (SD.Sfile)
327 & " is indicated as containing subunit "
328 & Get_Name_String (Unit_Name)
329 & " but this does not match what was found while"
330 & " parsing the project. Will recompile");
331 end if;
333 return No_Name;
334 end if;
335 end if;
336 end if;
337 end;
338 end loop;
340 return Result;
341 end Check_Source_Info_In_ALI;
343 --------------------------------
344 -- Create_Binder_Mapping_File --
345 --------------------------------
347 function Create_Binder_Mapping_File
348 (Project_Tree : Project_Tree_Ref) return Path_Name_Type
350 Mapping_Path : Path_Name_Type := No_Path;
352 Mapping_FD : File_Descriptor := Invalid_FD;
353 -- A File Descriptor for an eventual mapping file
355 ALI_Unit : Unit_Name_Type := No_Unit_Name;
356 -- The unit name of an ALI file
358 ALI_Name : File_Name_Type := No_File;
359 -- The file name of the ALI file
361 ALI_Project : Project_Id := No_Project;
362 -- The project of the ALI file
364 Bytes : Integer;
365 OK : Boolean := False;
366 Unit : Unit_Index;
368 Status : Boolean;
369 -- For call to Close
371 begin
372 Tempdir.Create_Temp_File (Mapping_FD, Mapping_Path);
373 Record_Temp_File (Project_Tree.Shared, Mapping_Path);
375 if Mapping_FD /= Invalid_FD then
376 OK := True;
378 -- Traverse all units
380 Unit := Units_Htable.Get_First (Project_Tree.Units_HT);
381 while Unit /= No_Unit_Index loop
382 if Unit.Name /= No_Name then
384 -- If there is a body, put it in the mapping
386 if Unit.File_Names (Impl) /= No_Source
387 and then Unit.File_Names (Impl).Project /= No_Project
388 then
389 Get_Name_String (Unit.Name);
390 Add_Str_To_Name_Buffer ("%b");
391 ALI_Unit := Name_Find;
392 ALI_Name :=
393 Lib_File_Name (Unit.File_Names (Impl).Display_File);
394 ALI_Project := Unit.File_Names (Impl).Project;
396 -- Otherwise, if there is a spec, put it in the mapping
398 elsif Unit.File_Names (Spec) /= No_Source
399 and then Unit.File_Names (Spec).Project /= No_Project
400 then
401 Get_Name_String (Unit.Name);
402 Add_Str_To_Name_Buffer ("%s");
403 ALI_Unit := Name_Find;
404 ALI_Name :=
405 Lib_File_Name (Unit.File_Names (Spec).Display_File);
406 ALI_Project := Unit.File_Names (Spec).Project;
408 else
409 ALI_Name := No_File;
410 end if;
412 -- If we have something to put in the mapping then do it now.
413 -- However, if the project is extended, we don't put anything
414 -- in the mapping file, since we don't know where the ALI file
415 -- is: it might be in the extended project object directory as
416 -- well as in the extending project object directory.
418 if ALI_Name /= No_File
419 and then ALI_Project.Extended_By = No_Project
420 and then ALI_Project.Extends = No_Project
421 then
422 -- First check if the ALI file exists. If it does not, do
423 -- not put the unit in the mapping file.
425 declare
426 ALI : constant String := Get_Name_String (ALI_Name);
428 begin
429 -- For library projects, use the library ALI directory,
430 -- for other projects, use the object directory.
432 if ALI_Project.Library then
433 Get_Name_String
434 (ALI_Project.Library_ALI_Dir.Display_Name);
435 else
436 Get_Name_String
437 (ALI_Project.Object_Directory.Display_Name);
438 end if;
440 Add_Str_To_Name_Buffer (ALI);
441 Add_Char_To_Name_Buffer (ASCII.LF);
443 declare
444 ALI_Path_Name : constant String :=
445 Name_Buffer (1 .. Name_Len);
447 begin
448 if Is_Regular_File
449 (ALI_Path_Name (1 .. ALI_Path_Name'Last - 1))
450 then
451 -- First line is the unit name
453 Get_Name_String (ALI_Unit);
454 Add_Char_To_Name_Buffer (ASCII.LF);
455 Bytes :=
456 Write
457 (Mapping_FD,
458 Name_Buffer (1)'Address,
459 Name_Len);
460 OK := Bytes = Name_Len;
462 exit when not OK;
464 -- Second line it the ALI file name
466 Get_Name_String (ALI_Name);
467 Add_Char_To_Name_Buffer (ASCII.LF);
468 Bytes :=
469 Write
470 (Mapping_FD,
471 Name_Buffer (1)'Address,
472 Name_Len);
473 OK := (Bytes = Name_Len);
475 exit when not OK;
477 -- Third line it the ALI path name
479 Bytes :=
480 Write
481 (Mapping_FD,
482 ALI_Path_Name (1)'Address,
483 ALI_Path_Name'Length);
484 OK := (Bytes = ALI_Path_Name'Length);
486 -- If OK is False, it means we were unable to
487 -- write a line. No point in continuing with the
488 -- other units.
490 exit when not OK;
491 end if;
492 end;
493 end;
494 end if;
495 end if;
497 Unit := Units_Htable.Get_Next (Project_Tree.Units_HT);
498 end loop;
500 Close (Mapping_FD, Status);
502 OK := OK and Status;
503 end if;
505 -- If the creation of the mapping file was successful, we add the switch
506 -- to the arguments of gnatbind.
508 if OK then
509 return Mapping_Path;
511 else
512 return No_Path;
513 end if;
514 end Create_Binder_Mapping_File;
516 -----------------
517 -- Create_Name --
518 -----------------
520 function Create_Name (Name : String) return File_Name_Type is
521 begin
522 Name_Len := 0;
523 Add_Str_To_Name_Buffer (Name);
524 return Name_Find;
525 end Create_Name;
527 function Create_Name (Name : String) return Name_Id is
528 begin
529 Name_Len := 0;
530 Add_Str_To_Name_Buffer (Name);
531 return Name_Find;
532 end Create_Name;
534 function Create_Name (Name : String) return Path_Name_Type is
535 begin
536 Name_Len := 0;
537 Add_Str_To_Name_Buffer (Name);
538 return Name_Find;
539 end Create_Name;
541 ---------------------------
542 -- Ensure_Absolute_Path --
543 ---------------------------
545 procedure Ensure_Absolute_Path
546 (Switch : in out String_Access;
547 Parent : String;
548 Do_Fail : Fail_Proc;
549 For_Gnatbind : Boolean := False;
550 Including_Non_Switch : Boolean := True;
551 Including_RTS : Boolean := False)
553 begin
554 if Switch /= null then
555 declare
556 Sw : String (1 .. Switch'Length);
557 Start : Positive;
559 begin
560 Sw := Switch.all;
562 if Sw (1) = '-' then
563 if Sw'Length >= 3
564 and then (Sw (2) = 'I'
565 or else (not For_Gnatbind
566 and then (Sw (2) = 'L'
567 or else Sw (2) = 'A')))
568 then
569 Start := 3;
571 if Sw = "-I-" then
572 return;
573 end if;
575 elsif Sw'Length >= 4
576 and then (Sw (2 .. 3) = "aL"
577 or else
578 Sw (2 .. 3) = "aO"
579 or else
580 Sw (2 .. 3) = "aI"
581 or else
582 (For_Gnatbind and then Sw (2 .. 3) = "A="))
583 then
584 Start := 4;
586 elsif Including_RTS
587 and then Sw'Length >= 7
588 and then Sw (2 .. 6) = "-RTS="
589 then
590 Start := 7;
592 else
593 return;
594 end if;
596 -- Because relative path arguments to --RTS= may be relative to
597 -- the search directory prefix, those relative path arguments
598 -- are converted only when they include directory information.
600 if not Is_Absolute_Path (Sw (Start .. Sw'Last)) then
601 if Parent'Length = 0 then
602 Do_Fail
603 ("relative search path switches ("""
604 & Sw
605 & """) are not allowed");
607 elsif Including_RTS then
608 for J in Start .. Sw'Last loop
609 if Sw (J) = Directory_Separator then
610 Switch :=
611 new String'
612 (Sw (1 .. Start - 1) &
613 Parent &
614 Directory_Separator &
615 Sw (Start .. Sw'Last));
616 return;
617 end if;
618 end loop;
620 else
621 Switch :=
622 new String'
623 (Sw (1 .. Start - 1) &
624 Parent &
625 Directory_Separator &
626 Sw (Start .. Sw'Last));
627 end if;
628 end if;
630 elsif Including_Non_Switch then
631 if not Is_Absolute_Path (Sw) then
632 if Parent'Length = 0 then
633 Do_Fail
634 ("relative paths (""" & Sw & """) are not allowed");
635 else
636 Switch := new String'(Parent & Directory_Separator & Sw);
637 end if;
638 end if;
639 end if;
640 end;
641 end if;
642 end Ensure_Absolute_Path;
644 ----------------------------
645 -- Executable_Prefix_Path --
646 ----------------------------
648 function Executable_Prefix_Path return String is
649 Exec_Name : constant String := Command_Name;
651 function Get_Install_Dir (S : String) return String;
652 -- S is the executable name preceded by the absolute or relative path,
653 -- e.g. "c:\usr\bin\gcc.exe". Returns the absolute directory where "bin"
654 -- lies (in the example "C:\usr"). If the executable is not in a "bin"
655 -- directory, return "".
657 ---------------------
658 -- Get_Install_Dir --
659 ---------------------
661 function Get_Install_Dir (S : String) return String is
662 Exec : String := S;
663 Path_Last : Integer := 0;
665 begin
666 for J in reverse Exec'Range loop
667 if Exec (J) = Directory_Separator then
668 Path_Last := J - 1;
669 exit;
670 end if;
671 end loop;
673 if Path_Last >= Exec'First + 2 then
674 To_Lower (Exec (Path_Last - 2 .. Path_Last));
675 end if;
677 if Path_Last < Exec'First + 2
678 or else Exec (Path_Last - 2 .. Path_Last) /= "bin"
679 or else (Path_Last - 3 >= Exec'First
680 and then Exec (Path_Last - 3) /= Directory_Separator)
681 then
682 return "";
683 end if;
685 return Normalize_Pathname
686 (Exec (Exec'First .. Path_Last - 4),
687 Resolve_Links => Opt.Follow_Links_For_Dirs)
688 & Directory_Separator;
689 end Get_Install_Dir;
691 -- Beginning of Executable_Prefix_Path
693 begin
694 -- For VMS, the path returned is always /gnu/
696 if Hostparm.OpenVMS then
697 return "/gnu/";
698 end if;
700 -- First determine if a path prefix was placed in front of the
701 -- executable name.
703 for J in reverse Exec_Name'Range loop
704 if Exec_Name (J) = Directory_Separator then
705 return Get_Install_Dir (Exec_Name);
706 end if;
707 end loop;
709 -- If we get here, the user has typed the executable name with no
710 -- directory prefix.
712 declare
713 Path : String_Access := Locate_Exec_On_Path (Exec_Name);
714 begin
715 if Path = null then
716 return "";
717 else
718 declare
719 Dir : constant String := Get_Install_Dir (Path.all);
720 begin
721 Free (Path);
722 return Dir;
723 end;
724 end if;
725 end;
726 end Executable_Prefix_Path;
728 ------------------
729 -- Fail_Program --
730 ------------------
732 procedure Fail_Program
733 (Project_Tree : Project_Tree_Ref;
734 S : String;
735 Flush_Messages : Boolean := True)
737 begin
738 if Flush_Messages then
739 if Total_Errors_Detected /= 0 or else Warnings_Detected /= 0 then
740 Errutil.Finalize;
741 end if;
742 end if;
744 Finish_Program (Project_Tree, E_Fatal, S => S);
745 end Fail_Program;
747 --------------------
748 -- Finish_Program --
749 --------------------
751 procedure Finish_Program
752 (Project_Tree : Project_Tree_Ref;
753 Exit_Code : Osint.Exit_Code_Type := Osint.E_Success;
754 S : String := "")
756 begin
757 if not Debug.Debug_Flag_N then
758 Delete_Temp_Config_Files (Project_Tree);
760 if Project_Tree /= null then
761 Delete_All_Temp_Files (Project_Tree.Shared);
762 end if;
763 end if;
765 if S'Length > 0 then
766 if Exit_Code /= E_Success then
767 Osint.Fail (S);
768 else
769 Write_Str (S);
770 end if;
771 end if;
773 -- Output Namet statistics
775 Namet.Finalize;
777 Exit_Program (Exit_Code);
778 end Finish_Program;
780 --------------------------
781 -- File_Not_A_Source_Of --
782 --------------------------
784 function File_Not_A_Source_Of
785 (Project_Tree : Project_Tree_Ref;
786 Uname : Name_Id;
787 Sfile : File_Name_Type) return Boolean
789 Unit : constant Unit_Index :=
790 Units_Htable.Get (Project_Tree.Units_HT, Uname);
792 At_Least_One_File : Boolean := False;
794 begin
795 if Unit /= No_Unit_Index then
796 for F in Unit.File_Names'Range loop
797 if Unit.File_Names (F) /= null then
798 At_Least_One_File := True;
799 if Unit.File_Names (F).File = Sfile then
800 return False;
801 end if;
802 end if;
803 end loop;
805 if not At_Least_One_File then
807 -- The unit was probably created initially for a separate unit
808 -- (which are initially created as IMPL when both suffixes are the
809 -- same). Later on, Override_Kind changed the type of the file,
810 -- and the unit is no longer valid in fact.
812 return False;
813 end if;
815 Verbose_Msg (Uname, "sources do not include ", Name_Id (Sfile));
816 return True;
817 end if;
819 return False;
820 end File_Not_A_Source_Of;
822 ---------------------
823 -- Get_Directories --
824 ---------------------
826 procedure Get_Directories
827 (Project_Tree : Project_Tree_Ref;
828 For_Project : Project_Id;
829 Activity : Activity_Type;
830 Languages : Name_Ids)
833 procedure Recursive_Add
834 (Project : Project_Id;
835 Tree : Project_Tree_Ref;
836 Extended : in out Boolean);
837 -- Add all the source directories of a project to the path only if
838 -- this project has not been visited. Calls itself recursively for
839 -- projects being extended, and imported projects.
841 procedure Add_Dir (Value : Path_Name_Type);
842 -- Add directory Value in table Directories, if it is defined and not
843 -- already there.
845 -------------
846 -- Add_Dir --
847 -------------
849 procedure Add_Dir (Value : Path_Name_Type) is
850 Add_It : Boolean := True;
852 begin
853 if Value /= No_Path then
854 for Index in 1 .. Directories.Last loop
855 if Directories.Table (Index) = Value then
856 Add_It := False;
857 exit;
858 end if;
859 end loop;
861 if Add_It then
862 Directories.Increment_Last;
863 Directories.Table (Directories.Last) := Value;
864 end if;
865 end if;
866 end Add_Dir;
868 -------------------
869 -- Recursive_Add --
870 -------------------
872 procedure Recursive_Add
873 (Project : Project_Id;
874 Tree : Project_Tree_Ref;
875 Extended : in out Boolean)
877 Current : String_List_Id;
878 Dir : String_Element;
879 OK : Boolean := False;
880 Lang_Proc : Language_Ptr := Project.Languages;
882 begin
883 -- Add to path all directories of this project
885 if Activity = Compilation then
886 Lang_Loop :
887 while Lang_Proc /= No_Language_Index loop
888 for J in Languages'Range loop
889 OK := Lang_Proc.Name = Languages (J);
890 exit Lang_Loop when OK;
891 end loop;
893 Lang_Proc := Lang_Proc.Next;
894 end loop Lang_Loop;
896 if OK then
897 Current := Project.Source_Dirs;
899 while Current /= Nil_String loop
900 Dir := Tree.Shared.String_Elements.Table (Current);
901 Add_Dir (Path_Name_Type (Dir.Value));
902 Current := Dir.Next;
903 end loop;
904 end if;
906 elsif Project.Library then
907 if Activity = SAL_Binding and then Extended then
908 Add_Dir (Project.Object_Directory.Display_Name);
910 else
911 Add_Dir (Project.Library_ALI_Dir.Display_Name);
912 end if;
914 else
915 Add_Dir (Project.Object_Directory.Display_Name);
916 end if;
918 if Project.Extends = No_Project then
919 Extended := False;
920 end if;
921 end Recursive_Add;
923 procedure For_All_Projects is
924 new For_Every_Project_Imported (Boolean, Recursive_Add);
926 Extended : Boolean := True;
928 -- Start of processing for Get_Directories
930 begin
931 Directories.Init;
932 For_All_Projects (For_Project, Project_Tree, Extended);
933 end Get_Directories;
935 ------------------
936 -- Get_Switches --
937 ------------------
939 procedure Get_Switches
940 (Source : Prj.Source_Id;
941 Pkg_Name : Name_Id;
942 Project_Tree : Project_Tree_Ref;
943 Value : out Variable_Value;
944 Is_Default : out Boolean)
946 begin
947 Get_Switches
948 (Source_File => Source.File,
949 Source_Lang => Source.Language.Name,
950 Source_Prj => Source.Project,
951 Pkg_Name => Pkg_Name,
952 Project_Tree => Project_Tree,
953 Value => Value,
954 Is_Default => Is_Default);
955 end Get_Switches;
957 ------------------
958 -- Get_Switches --
959 ------------------
961 procedure Get_Switches
962 (Source_File : File_Name_Type;
963 Source_Lang : Name_Id;
964 Source_Prj : Project_Id;
965 Pkg_Name : Name_Id;
966 Project_Tree : Project_Tree_Ref;
967 Value : out Variable_Value;
968 Is_Default : out Boolean;
969 Test_Without_Suffix : Boolean := False;
970 Check_ALI_Suffix : Boolean := False)
972 Project : constant Project_Id :=
973 Ultimate_Extending_Project_Of (Source_Prj);
974 Pkg : constant Package_Id :=
975 Prj.Util.Value_Of
976 (Name => Pkg_Name,
977 In_Packages => Project.Decl.Packages,
978 Shared => Project_Tree.Shared);
979 Lang : Language_Ptr;
981 begin
982 Is_Default := False;
984 if Source_File /= No_File then
985 Value := Prj.Util.Value_Of
986 (Name => Name_Id (Source_File),
987 Attribute_Or_Array_Name => Name_Switches,
988 In_Package => Pkg,
989 Shared => Project_Tree.Shared,
990 Allow_Wildcards => True);
991 end if;
993 if Value = Nil_Variable_Value and then Test_Without_Suffix then
994 Lang :=
995 Get_Language_From_Name (Project, Get_Name_String (Source_Lang));
997 if Lang /= null then
998 declare
999 Naming : Lang_Naming_Data renames Lang.Config.Naming_Data;
1000 SF_Name : constant String := Get_Name_String (Source_File);
1001 Last : Positive := SF_Name'Length;
1002 Name : String (1 .. Last + 3);
1003 Spec_Suffix : String := Get_Name_String (Naming.Spec_Suffix);
1004 Body_Suffix : String := Get_Name_String (Naming.Body_Suffix);
1005 Truncated : Boolean := False;
1007 begin
1008 Canonical_Case_File_Name (Spec_Suffix);
1009 Canonical_Case_File_Name (Body_Suffix);
1010 Name (1 .. Last) := SF_Name;
1012 if Last > Body_Suffix'Length
1013 and then
1014 Name (Last - Body_Suffix'Length + 1 .. Last) = Body_Suffix
1015 then
1016 Truncated := True;
1017 Last := Last - Body_Suffix'Length;
1018 end if;
1020 if not Truncated
1021 and then Last > Spec_Suffix'Length
1022 and then
1023 Name (Last - Spec_Suffix'Length + 1 .. Last) = Spec_Suffix
1024 then
1025 Truncated := True;
1026 Last := Last - Spec_Suffix'Length;
1027 end if;
1029 if Truncated then
1030 Name_Len := 0;
1031 Add_Str_To_Name_Buffer (Name (1 .. Last));
1033 Value := Prj.Util.Value_Of
1034 (Name => Name_Find,
1035 Attribute_Or_Array_Name => Name_Switches,
1036 In_Package => Pkg,
1037 Shared => Project_Tree.Shared,
1038 Allow_Wildcards => True);
1039 end if;
1041 if Value = Nil_Variable_Value and then Check_ALI_Suffix then
1042 Last := SF_Name'Length;
1043 while Name (Last) /= '.' loop
1044 Last := Last - 1;
1045 end loop;
1047 Name_Len := 0;
1048 Add_Str_To_Name_Buffer (Name (1 .. Last));
1049 Add_Str_To_Name_Buffer ("ali");
1051 Value := Prj.Util.Value_Of
1052 (Name => Name_Find,
1053 Attribute_Or_Array_Name => Name_Switches,
1054 In_Package => Pkg,
1055 Shared => Project_Tree.Shared,
1056 Allow_Wildcards => True);
1057 end if;
1058 end;
1059 end if;
1060 end if;
1062 if Value = Nil_Variable_Value then
1063 Is_Default := True;
1064 Value :=
1065 Prj.Util.Value_Of
1066 (Name => Source_Lang,
1067 Attribute_Or_Array_Name => Name_Switches,
1068 In_Package => Pkg,
1069 Shared => Project_Tree.Shared,
1070 Force_Lower_Case_Index => True);
1071 end if;
1073 if Value = Nil_Variable_Value then
1074 Value :=
1075 Prj.Util.Value_Of
1076 (Name => All_Other_Names,
1077 Attribute_Or_Array_Name => Name_Switches,
1078 In_Package => Pkg,
1079 Shared => Project_Tree.Shared,
1080 Force_Lower_Case_Index => True);
1081 end if;
1083 if Value = Nil_Variable_Value then
1084 Value :=
1085 Prj.Util.Value_Of
1086 (Name => Source_Lang,
1087 Attribute_Or_Array_Name => Name_Default_Switches,
1088 In_Package => Pkg,
1089 Shared => Project_Tree.Shared);
1090 end if;
1091 end Get_Switches;
1093 ------------
1094 -- Inform --
1095 ------------
1097 procedure Inform (N : File_Name_Type; Msg : String) is
1098 begin
1099 Inform (Name_Id (N), Msg);
1100 end Inform;
1102 procedure Inform (N : Name_Id := No_Name; Msg : String) is
1103 begin
1104 Osint.Write_Program_Name;
1106 Write_Str (": ");
1108 if N /= No_Name then
1109 Write_Str ("""");
1111 declare
1112 Name : constant String := Get_Name_String (N);
1113 begin
1114 if Debug.Debug_Flag_F and then Is_Absolute_Path (Name) then
1115 Write_Str (File_Name (Name));
1116 else
1117 Write_Str (Name);
1118 end if;
1119 end;
1121 Write_Str (""" ");
1122 end if;
1124 Write_Str (Msg);
1125 Write_Eol;
1126 end Inform;
1128 ------------------------------
1129 -- Initialize_Source_Record --
1130 ------------------------------
1132 procedure Initialize_Source_Record (Source : Prj.Source_Id) is
1134 procedure Set_Object_Project
1135 (Obj_Dir : String;
1136 Obj_Proj : Project_Id;
1137 Obj_Path : Path_Name_Type;
1138 Stamp : Time_Stamp_Type);
1139 -- Update information about object file, switches file,...
1141 ------------------------
1142 -- Set_Object_Project --
1143 ------------------------
1145 procedure Set_Object_Project
1146 (Obj_Dir : String;
1147 Obj_Proj : Project_Id;
1148 Obj_Path : Path_Name_Type;
1149 Stamp : Time_Stamp_Type) is
1150 begin
1151 Source.Object_Project := Obj_Proj;
1152 Source.Object_Path := Obj_Path;
1153 Source.Object_TS := Stamp;
1155 if Source.Language.Config.Dependency_Kind /= None then
1156 declare
1157 Dep_Path : constant String :=
1158 Normalize_Pathname
1159 (Name =>
1160 Get_Name_String (Source.Dep_Name),
1161 Resolve_Links => Opt.Follow_Links_For_Files,
1162 Directory => Obj_Dir);
1163 begin
1164 Source.Dep_Path := Create_Name (Dep_Path);
1165 Source.Dep_TS := Osint.Unknown_Attributes;
1166 end;
1167 end if;
1169 -- Get the path of the switches file, even if Opt.Check_Switches is
1170 -- not set, as switch -s may be in the Builder switches that have not
1171 -- been scanned yet.
1173 declare
1174 Switches_Path : constant String :=
1175 Normalize_Pathname
1176 (Name =>
1177 Get_Name_String (Source.Switches),
1178 Resolve_Links => Opt.Follow_Links_For_Files,
1179 Directory => Obj_Dir);
1180 begin
1181 Source.Switches_Path := Create_Name (Switches_Path);
1183 if Stamp /= Empty_Time_Stamp then
1184 Source.Switches_TS := File_Stamp (Source.Switches_Path);
1185 end if;
1186 end;
1187 end Set_Object_Project;
1189 Obj_Proj : Project_Id;
1191 begin
1192 -- Nothing to do if source record has already been fully initialized
1194 if Source.Initialized then
1195 return;
1196 end if;
1198 -- Systematically recompute the time stamp
1200 Source.Source_TS := File_Stamp (Source.Path.Display_Name);
1202 -- Parse the source file to check whether we have a subunit
1204 if Source.Language.Config.Kind = Unit_Based
1205 and then Source.Kind = Impl
1206 and then Is_Subunit (Source)
1207 then
1208 Source.Kind := Sep;
1209 end if;
1211 if Source.Language.Config.Object_Generated
1212 and then Is_Compilable (Source)
1213 then
1214 -- First, get the correct object file name and dependency file name
1215 -- if the source is in a multi-unit file.
1217 if Source.Index /= 0 then
1218 Source.Object :=
1219 Object_Name
1220 (Source_File_Name => Source.File,
1221 Source_Index => Source.Index,
1222 Index_Separator =>
1223 Source.Language.Config.Multi_Unit_Object_Separator,
1224 Object_File_Suffix =>
1225 Source.Language.Config.Object_File_Suffix);
1227 Source.Dep_Name :=
1228 Dependency_Name
1229 (Source.Object, Source.Language.Config.Dependency_Kind);
1230 end if;
1232 -- Find the object file for that source. It could be either in the
1233 -- current project or in an extended project (it might actually not
1234 -- exist yet in the ultimate extending project, but if not found
1235 -- elsewhere that's where we'll expect to find it).
1237 Obj_Proj := Source.Project;
1239 while Obj_Proj /= No_Project loop
1240 declare
1241 Dir : constant String :=
1242 Get_Name_String
1243 (Obj_Proj.Object_Directory.Display_Name);
1245 Object_Path : constant String :=
1246 Normalize_Pathname
1247 (Name =>
1248 Get_Name_String (Source.Object),
1249 Resolve_Links => Opt.Follow_Links_For_Files,
1250 Directory => Dir);
1252 Obj_Path : constant Path_Name_Type := Create_Name (Object_Path);
1253 Stamp : Time_Stamp_Type := Empty_Time_Stamp;
1255 begin
1256 -- For specs, we do not check object files if there is a body.
1257 -- This saves a system call. On the other hand, we do need to
1258 -- know the object_path, in case the user has passed the .ads
1259 -- on the command line to compile the spec only.
1261 if Source.Kind /= Spec
1262 or else Source.Unit = No_Unit_Index
1263 or else Source.Unit.File_Names (Impl) = No_Source
1264 then
1265 Stamp := File_Stamp (Obj_Path);
1266 end if;
1268 if Stamp /= Empty_Time_Stamp
1269 or else (Obj_Proj.Extended_By = No_Project
1270 and then Source.Object_Project = No_Project)
1271 then
1272 Set_Object_Project (Dir, Obj_Proj, Obj_Path, Stamp);
1273 end if;
1275 Obj_Proj := Obj_Proj.Extended_By;
1276 end;
1277 end loop;
1279 elsif Source.Language.Config.Dependency_Kind = Makefile then
1280 declare
1281 Object_Dir : constant String :=
1282 Get_Name_String
1283 (Source.Project.Object_Directory.Display_Name);
1284 Dep_Path : constant String :=
1285 Normalize_Pathname
1286 (Name => Get_Name_String (Source.Dep_Name),
1287 Resolve_Links =>
1288 Opt.Follow_Links_For_Files,
1289 Directory => Object_Dir);
1290 begin
1291 Source.Dep_Path := Create_Name (Dep_Path);
1292 Source.Dep_TS := Osint.Unknown_Attributes;
1293 end;
1294 end if;
1296 Source.Initialized := True;
1297 end Initialize_Source_Record;
1299 ----------------------------
1300 -- Is_External_Assignment --
1301 ----------------------------
1303 function Is_External_Assignment
1304 (Env : Prj.Tree.Environment;
1305 Argv : String) return Boolean
1307 Start : Positive := 3;
1308 Finish : Natural := Argv'Last;
1310 pragma Assert (Argv'First = 1);
1311 pragma Assert (Argv (1 .. 2) = "-X");
1313 begin
1314 if Argv'Last < 5 then
1315 return False;
1317 elsif Argv (3) = '"' then
1318 if Argv (Argv'Last) /= '"' or else Argv'Last < 7 then
1319 return False;
1320 else
1321 Start := 4;
1322 Finish := Argv'Last - 1;
1323 end if;
1324 end if;
1326 return Prj.Ext.Check
1327 (Self => Env.External,
1328 Declaration => Argv (Start .. Finish));
1329 end Is_External_Assignment;
1331 ----------------
1332 -- Is_Subunit --
1333 ----------------
1335 function Is_Subunit (Source : Prj.Source_Id) return Boolean is
1336 Src_Ind : Source_File_Index;
1338 begin
1339 if Source.Kind = Sep then
1340 return True;
1342 -- A Spec, a file based language source or a body with a spec cannot be
1343 -- a subunit.
1345 elsif Source.Kind = Spec
1346 or else Source.Unit = No_Unit_Index
1347 or else Other_Part (Source) /= No_Source
1348 then
1349 return False;
1350 end if;
1352 -- Here, we are assuming that the language is Ada, as it is the only
1353 -- unit based language that we know.
1355 Src_Ind :=
1356 Sinput.P.Load_Project_File
1357 (Get_Name_String (Source.Path.Display_Name));
1359 return Sinput.P.Source_File_Is_Subunit (Src_Ind);
1360 end Is_Subunit;
1362 -----------------------------
1363 -- Linker_Options_Switches --
1364 -----------------------------
1366 function Linker_Options_Switches
1367 (Project : Project_Id;
1368 Do_Fail : Fail_Proc;
1369 In_Tree : Project_Tree_Ref) return String_List
1371 procedure Recursive_Add
1372 (Proj : Project_Id;
1373 In_Tree : Project_Tree_Ref;
1374 Dummy : in out Boolean);
1375 -- The recursive routine used to add linker options
1377 -------------------
1378 -- Recursive_Add --
1379 -------------------
1381 procedure Recursive_Add
1382 (Proj : Project_Id;
1383 In_Tree : Project_Tree_Ref;
1384 Dummy : in out Boolean)
1386 pragma Unreferenced (Dummy);
1388 Linker_Package : Package_Id;
1389 Options : Variable_Value;
1391 begin
1392 Linker_Package :=
1393 Prj.Util.Value_Of
1394 (Name => Name_Linker,
1395 In_Packages => Proj.Decl.Packages,
1396 Shared => In_Tree.Shared);
1398 Options :=
1399 Prj.Util.Value_Of
1400 (Name => Name_Ada,
1401 Index => 0,
1402 Attribute_Or_Array_Name => Name_Linker_Options,
1403 In_Package => Linker_Package,
1404 Shared => In_Tree.Shared);
1406 -- If attribute is present, add the project with the attribute to
1407 -- table Linker_Opts.
1409 if Options /= Nil_Variable_Value then
1410 Linker_Opts.Increment_Last;
1411 Linker_Opts.Table (Linker_Opts.Last) :=
1412 (Project => Proj, Options => Options.Values);
1413 end if;
1414 end Recursive_Add;
1416 procedure For_All_Projects is
1417 new For_Every_Project_Imported (Boolean, Recursive_Add);
1419 Dummy : Boolean := False;
1421 -- Start of processing for Linker_Options_Switches
1423 begin
1424 Linker_Opts.Init;
1426 For_All_Projects (Project, In_Tree, Dummy, Imported_First => True);
1428 Last_Linker_Option := 0;
1430 for Index in reverse 1 .. Linker_Opts.Last loop
1431 declare
1432 Options : String_List_Id;
1433 Proj : constant Project_Id :=
1434 Linker_Opts.Table (Index).Project;
1435 Option : Name_Id;
1436 Dir_Path : constant String :=
1437 Get_Name_String (Proj.Directory.Name);
1439 begin
1440 Options := Linker_Opts.Table (Index).Options;
1441 while Options /= Nil_String loop
1442 Option := In_Tree.Shared.String_Elements.Table (Options).Value;
1443 Get_Name_String (Option);
1445 -- Do not consider empty linker options
1447 if Name_Len /= 0 then
1448 Add_Linker_Option (Name_Buffer (1 .. Name_Len));
1450 -- Object files and -L switches specified with relative
1451 -- paths must be converted to absolute paths.
1453 Ensure_Absolute_Path
1454 (Switch =>
1455 Linker_Options_Buffer (Last_Linker_Option),
1456 Parent => Dir_Path,
1457 Do_Fail => Do_Fail,
1458 For_Gnatbind => False);
1459 end if;
1461 Options := In_Tree.Shared.String_Elements.Table (Options).Next;
1462 end loop;
1463 end;
1464 end loop;
1466 return Linker_Options_Buffer (1 .. Last_Linker_Option);
1467 end Linker_Options_Switches;
1469 -----------
1470 -- Mains --
1471 -----------
1473 package body Mains is
1475 package Names is new Table.Table
1476 (Table_Component_Type => Main_Info,
1477 Table_Index_Type => Integer,
1478 Table_Low_Bound => 1,
1479 Table_Initial => 10,
1480 Table_Increment => 100,
1481 Table_Name => "Makeutl.Mains.Names");
1482 -- The table that stores the mains
1484 Current : Natural := 0;
1485 -- The index of the last main retrieved from the table
1487 Count_Of_Mains_With_No_Tree : Natural := 0;
1488 -- Number of main units for which we do not know the project tree
1490 --------------
1491 -- Add_Main --
1492 --------------
1494 procedure Add_Main
1495 (Name : String;
1496 Index : Int := 0;
1497 Location : Source_Ptr := No_Location;
1498 Project : Project_Id := No_Project;
1499 Tree : Project_Tree_Ref := null)
1501 begin
1502 if Current_Verbosity = High then
1503 Debug_Output ("Add_Main """ & Name & """ " & Index'Img
1504 & " with_tree? "
1505 & Boolean'Image (Tree /= null));
1506 end if;
1508 Name_Len := 0;
1509 Add_Str_To_Name_Buffer (Name);
1510 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1512 Names.Increment_Last;
1513 Names.Table (Names.Last) :=
1514 (Name_Find, Index, Location, No_Source, Project, Tree);
1516 if Tree /= null then
1517 Builder_Data (Tree).Number_Of_Mains :=
1518 Builder_Data (Tree).Number_Of_Mains + 1;
1520 else
1521 Mains.Count_Of_Mains_With_No_Tree :=
1522 Mains.Count_Of_Mains_With_No_Tree + 1;
1523 end if;
1524 end Add_Main;
1526 --------------------
1527 -- Complete_Mains --
1528 --------------------
1530 procedure Complete_Mains
1531 (Flags : Processing_Flags;
1532 Root_Project : Project_Id;
1533 Project_Tree : Project_Tree_Ref)
1535 procedure Do_Complete (Project : Project_Id; Tree : Project_Tree_Ref);
1536 -- Check the mains for this specific project
1538 procedure Complete_All is new For_Project_And_Aggregated
1539 (Do_Complete);
1541 procedure Add_Multi_Unit_Sources
1542 (Tree : Project_Tree_Ref;
1543 Source : Prj.Source_Id);
1544 -- Add all units from the same file as the multi-unit Source
1546 function Find_File_Add_Extension
1547 (Tree : Project_Tree_Ref;
1548 Base_Main : String) return Prj.Source_Id;
1549 -- Search for Main in the project, adding body or spec extensions
1551 ----------------------------
1552 -- Add_Multi_Unit_Sources --
1553 ----------------------------
1555 procedure Add_Multi_Unit_Sources
1556 (Tree : Project_Tree_Ref;
1557 Source : Prj.Source_Id)
1559 Iter : Source_Iterator;
1560 Src : Prj.Source_Id;
1562 begin
1563 Debug_Output
1564 ("found multi-unit source file in project", Source.Project.Name);
1566 Iter := For_Each_Source
1567 (In_Tree => Tree, Project => Source.Project);
1569 while Element (Iter) /= No_Source loop
1570 Src := Element (Iter);
1572 if Src.File = Source.File
1573 and then Src.Index /= Source.Index
1574 then
1575 if Src.File = Source.File then
1576 Debug_Output
1577 ("add main in project, index=" & Src.Index'Img);
1578 end if;
1580 Names.Increment_Last;
1581 Names.Table (Names.Last) :=
1582 (File => Src.File,
1583 Index => Src.Index,
1584 Location => No_Location,
1585 Source => Src,
1586 Project => Src.Project,
1587 Tree => Tree);
1589 Builder_Data (Tree).Number_Of_Mains :=
1590 Builder_Data (Tree).Number_Of_Mains + 1;
1591 end if;
1593 Next (Iter);
1594 end loop;
1595 end Add_Multi_Unit_Sources;
1597 -----------------------------
1598 -- Find_File_Add_Extension --
1599 -----------------------------
1601 function Find_File_Add_Extension
1602 (Tree : Project_Tree_Ref;
1603 Base_Main : String) return Prj.Source_Id
1605 Spec_Source : Prj.Source_Id := No_Source;
1606 Source : Prj.Source_Id;
1607 Iter : Source_Iterator;
1608 Suffix : File_Name_Type;
1610 begin
1611 Source := No_Source;
1612 Iter := For_Each_Source (Tree); -- In all projects
1613 loop
1614 Source := Prj.Element (Iter);
1615 exit when Source = No_Source;
1617 if Source.Kind = Impl then
1618 Get_Name_String (Source.File);
1620 if Name_Len > Base_Main'Length
1621 and then Name_Buffer (1 .. Base_Main'Length) = Base_Main
1622 then
1623 Suffix :=
1624 Source.Language.Config.Naming_Data.Body_Suffix;
1626 if Suffix /= No_File then
1627 declare
1628 Suffix_Str : String := Get_Name_String (Suffix);
1629 begin
1630 Canonical_Case_File_Name (Suffix_Str);
1631 exit when
1632 Name_Buffer (Base_Main'Length + 1 .. Name_Len) =
1633 Suffix_Str;
1634 end;
1635 end if;
1636 end if;
1638 elsif Source.Kind = Spec then
1639 -- A spec needs to be taken into account unless there is
1640 -- also a body. So we delay the decision for them.
1642 Get_Name_String (Source.File);
1644 if Name_Len > Base_Main'Length
1645 and then Name_Buffer (1 .. Base_Main'Length) = Base_Main
1646 then
1647 Suffix := Source.Language.Config.Naming_Data.Spec_Suffix;
1649 if Suffix /= No_File then
1650 declare
1651 Suffix_Str : String := Get_Name_String (Suffix);
1653 begin
1654 Canonical_Case_File_Name (Suffix_Str);
1656 if Name_Buffer (Base_Main'Length + 1 .. Name_Len) =
1657 Suffix_Str
1658 then
1659 Spec_Source := Source;
1660 end if;
1661 end;
1662 end if;
1663 end if;
1664 end if;
1666 Next (Iter);
1667 end loop;
1669 if Source = No_Source then
1670 Source := Spec_Source;
1671 end if;
1673 return Source;
1674 end Find_File_Add_Extension;
1676 -----------------
1677 -- Do_Complete --
1678 -----------------
1680 procedure Do_Complete
1681 (Project : Project_Id; Tree : Project_Tree_Ref)
1683 J : Integer;
1685 begin
1686 if Mains.Number_Of_Mains (Tree) > 0
1687 or else Mains.Count_Of_Mains_With_No_Tree > 0
1688 then
1689 -- Traverse in reverse order, since in the case of multi-unit
1690 -- files we will be adding extra files at the end, and there's
1691 -- no need to process them in turn.
1693 J := Names.Last;
1694 loop
1695 declare
1696 File : Main_Info := Names.Table (J);
1697 Main_Id : File_Name_Type := File.File;
1698 Main : constant String :=
1699 Get_Name_String (Main_Id);
1700 Base : constant String := Base_Name (Main);
1701 Source : Prj.Source_Id := No_Source;
1702 Is_Absolute : Boolean := False;
1704 begin
1705 if Base /= Main then
1706 Is_Absolute := True;
1708 if Is_Absolute_Path (Main) then
1709 Main_Id := Create_Name (Base);
1711 -- Not an absolute path
1713 else
1714 -- Always resolve links here, so that users can be
1715 -- specify any name on the command line. If the
1716 -- project itself uses links, the user will be
1717 -- using -eL anyway, and thus files are also stored
1718 -- with resolved names.
1720 declare
1721 Absolute : constant String :=
1722 Normalize_Pathname
1723 (Name => Main,
1724 Directory => "",
1725 Resolve_Links => True,
1726 Case_Sensitive => False);
1727 begin
1728 File.File := Create_Name (Absolute);
1729 Main_Id := Create_Name (Base);
1730 end;
1731 end if;
1732 end if;
1734 -- If no project or tree was specified for the main, it
1735 -- came from the command line.
1736 -- Note that the assignments below will not modify inside
1737 -- the table itself.
1739 if File.Project = null then
1740 File.Project := Project;
1741 end if;
1743 if File.Tree = null then
1744 File.Tree := Tree;
1745 end if;
1747 if File.Source = null then
1748 if Current_Verbosity = High then
1749 Debug_Output
1750 ("search for main """ & Main
1751 & '"' & File.Index'Img & " in "
1752 & Get_Name_String (Debug_Name (File.Tree))
1753 & ", project", Project.Name);
1754 end if;
1756 -- First, look for the main as specified. We need to
1757 -- search for the base name though, and if needed
1758 -- check later that we found the correct file.
1760 Source := Find_Source
1761 (In_Tree => File.Tree,
1762 Project => File.Project,
1763 Base_Name => Main_Id,
1764 Index => File.Index,
1765 In_Imported_Only => True);
1767 if Source = No_Source then
1768 Source := Find_File_Add_Extension
1769 (Tree, Get_Name_String (Main_Id));
1770 end if;
1772 if Is_Absolute
1773 and then Source /= No_Source
1774 and then
1775 File_Name_Type (Source.Path.Name) /= File.File
1776 then
1777 Debug_Output
1778 ("Found a non-matching file",
1779 Name_Id (Source.Path.Display_Name));
1780 Source := No_Source;
1781 end if;
1783 if Source /= No_Source then
1784 if not Is_Allowed_Language
1785 (Source.Language.Name)
1786 then
1787 -- Remove any main that is not in the list of
1788 -- restricted languages.
1790 Names.Table (J .. Names.Last - 1) :=
1791 Names.Table (J + 1 .. Names.Last);
1792 Names.Set_Last (Names.Last - 1);
1794 else
1795 -- If we have found a multi-unit source file but
1796 -- did not specify an index initially, we'll
1797 -- need to compile all the units from the same
1798 -- source file.
1800 if Source.Index /= 0 and then File.Index = 0 then
1801 Add_Multi_Unit_Sources (File.Tree, Source);
1802 end if;
1804 -- Now update the original Main, otherwise it
1805 -- will be reported as not found.
1807 Debug_Output
1808 ("found main in project", Source.Project.Name);
1809 Names.Table (J).File := Source.File;
1810 Names.Table (J).Project := Source.Project;
1812 if Names.Table (J).Tree = null then
1813 Names.Table (J).Tree := File.Tree;
1815 Builder_Data (File.Tree).Number_Of_Mains :=
1816 Builder_Data (File.Tree).Number_Of_Mains
1817 + 1;
1818 Mains.Count_Of_Mains_With_No_Tree :=
1819 Mains.Count_Of_Mains_With_No_Tree - 1;
1820 end if;
1822 Names.Table (J).Source := Source;
1823 Names.Table (J).Index := Source.Index;
1824 end if;
1826 elsif File.Location /= No_Location then
1828 -- If the main is declared in package Builder of
1829 -- the main project, report an error. If the main
1830 -- is on the command line, it may be a main from
1831 -- another project, so do nothing: if the main does
1832 -- not exist in another project, an error will be
1833 -- reported later.
1835 Error_Msg_File_1 := Main_Id;
1836 Error_Msg_Name_1 := Root_Project.Name;
1837 Prj.Err.Error_Msg
1838 (Flags, "{ is not a source of project %%",
1839 File.Location, Project);
1840 end if;
1841 end if;
1842 end;
1844 J := J - 1;
1845 exit when J < Names.First;
1846 end loop;
1847 end if;
1849 if Total_Errors_Detected > 0 then
1850 Fail_Program (Tree, "problems with main sources");
1851 end if;
1852 end Do_Complete;
1854 -- Start of processing for Complete_Mains
1856 begin
1857 Complete_All (Root_Project, Project_Tree);
1859 if Mains.Count_Of_Mains_With_No_Tree > 0 then
1860 for J in Names.First .. Names.Last loop
1861 if Names.Table (J).Source = No_Source then
1862 Fail_Program
1863 (Project_Tree, '"' & Get_Name_String (Names.Table (J).File)
1864 & """ is not a source of any project");
1865 end if;
1866 end loop;
1867 end if;
1868 end Complete_Mains;
1870 ------------
1871 -- Delete --
1872 ------------
1874 procedure Delete is
1875 begin
1876 Names.Set_Last (0);
1877 Mains.Reset;
1878 end Delete;
1880 -----------------------
1881 -- Fill_From_Project --
1882 -----------------------
1884 procedure Fill_From_Project
1885 (Root_Project : Project_Id;
1886 Project_Tree : Project_Tree_Ref)
1888 procedure Add_Mains_From_Project
1889 (Project : Project_Id;
1890 Tree : Project_Tree_Ref);
1891 -- Add the main units from this project into Mains.
1892 -- This takes into account the aggregated projects
1894 ----------------------------
1895 -- Add_Mains_From_Project --
1896 ----------------------------
1898 procedure Add_Mains_From_Project
1899 (Project : Project_Id;
1900 Tree : Project_Tree_Ref)
1902 List : String_List_Id;
1903 Element : String_Element;
1905 begin
1906 if Number_Of_Mains (Tree) = 0
1907 and then Mains.Count_Of_Mains_With_No_Tree = 0
1908 then
1909 Debug_Output ("Add_Mains_From_Project", Project.Name);
1910 List := Project.Mains;
1912 if List /= Prj.Nil_String then
1914 -- The attribute Main is not an empty list. Get the mains in
1915 -- the list.
1917 while List /= Prj.Nil_String loop
1918 Element := Tree.Shared.String_Elements.Table (List);
1919 Debug_Output ("Add_Main", Element.Value);
1921 if Project.Library then
1922 Fail_Program
1923 (Tree,
1924 "cannot specify a main program " &
1925 "for a library project file");
1926 end if;
1928 Add_Main (Name => Get_Name_String (Element.Value),
1929 Index => Element.Index,
1930 Location => Element.Location,
1931 Project => Project,
1932 Tree => Tree);
1933 List := Element.Next;
1934 end loop;
1935 end if;
1936 end if;
1938 if Total_Errors_Detected > 0 then
1939 Fail_Program (Tree, "problems with main sources");
1940 end if;
1941 end Add_Mains_From_Project;
1943 procedure Fill_All is new For_Project_And_Aggregated
1944 (Add_Mains_From_Project);
1946 -- Start of processing for Fill_From_Project
1948 begin
1949 Fill_All (Root_Project, Project_Tree);
1950 end Fill_From_Project;
1952 ---------------
1953 -- Next_Main --
1954 ---------------
1956 function Next_Main return String is
1957 Info : constant Main_Info := Next_Main;
1958 begin
1959 if Info = No_Main_Info then
1960 return "";
1961 else
1962 return Get_Name_String (Info.File);
1963 end if;
1964 end Next_Main;
1966 function Next_Main return Main_Info is
1967 begin
1968 if Current >= Names.Last then
1969 return No_Main_Info;
1970 else
1971 Current := Current + 1;
1973 -- If not using projects, and in the gnatmake case, the main file
1974 -- may have not have the extension. Try ".adb" first then ".ads"
1976 if Names.Table (Current).Project = No_Project then
1977 declare
1978 Orig_Main : constant File_Name_Type :=
1979 Names.Table (Current).File;
1980 Current_Main : File_Name_Type;
1982 begin
1983 if Strip_Suffix (Orig_Main) = Orig_Main then
1984 Get_Name_String (Orig_Main);
1985 Add_Str_To_Name_Buffer (".adb");
1986 Current_Main := Name_Find;
1988 if Full_Source_Name (Current_Main) = No_File then
1989 Get_Name_String (Orig_Main);
1990 Add_Str_To_Name_Buffer (".ads");
1991 Current_Main := Name_Find;
1993 if Full_Source_Name (Current_Main) /= No_File then
1994 Names.Table (Current).File := Current_Main;
1995 end if;
1997 else
1998 Names.Table (Current).File := Current_Main;
1999 end if;
2000 end if;
2001 end;
2002 end if;
2004 return Names.Table (Current);
2005 end if;
2006 end Next_Main;
2008 ---------------------
2009 -- Number_Of_Mains --
2010 ---------------------
2012 function Number_Of_Mains (Tree : Project_Tree_Ref) return Natural is
2013 begin
2014 if Tree = null then
2015 return Names.Last;
2016 else
2017 return Builder_Data (Tree).Number_Of_Mains;
2018 end if;
2019 end Number_Of_Mains;
2021 -----------
2022 -- Reset --
2023 -----------
2025 procedure Reset is
2026 begin
2027 Current := 0;
2028 end Reset;
2030 --------------------------
2031 -- Set_Multi_Unit_Index --
2032 --------------------------
2034 procedure Set_Multi_Unit_Index
2035 (Project_Tree : Project_Tree_Ref := null;
2036 Index : Int := 0)
2038 begin
2039 if Index /= 0 then
2040 if Names.Last = 0 then
2041 Fail_Program
2042 (Project_Tree,
2043 "cannot specify a multi-unit index but no main " &
2044 "on the command line");
2046 elsif Names.Last > 1 then
2047 Fail_Program
2048 (Project_Tree,
2049 "cannot specify several mains with a multi-unit index");
2051 else
2052 Names.Table (Names.Last).Index := Index;
2053 end if;
2054 end if;
2055 end Set_Multi_Unit_Index;
2057 end Mains;
2059 -----------------------
2060 -- Path_Or_File_Name --
2061 -----------------------
2063 function Path_Or_File_Name (Path : Path_Name_Type) return String is
2064 Path_Name : constant String := Get_Name_String (Path);
2065 begin
2066 if Debug.Debug_Flag_F then
2067 return File_Name (Path_Name);
2068 else
2069 return Path_Name;
2070 end if;
2071 end Path_Or_File_Name;
2073 -------------------
2074 -- Unit_Index_Of --
2075 -------------------
2077 function Unit_Index_Of (ALI_File : File_Name_Type) return Int is
2078 Start : Natural;
2079 Finish : Natural;
2080 Result : Int := 0;
2082 begin
2083 Get_Name_String (ALI_File);
2085 -- First, find the last dot
2087 Finish := Name_Len;
2089 while Finish >= 1 and then Name_Buffer (Finish) /= '.' loop
2090 Finish := Finish - 1;
2091 end loop;
2093 if Finish = 1 then
2094 return 0;
2095 end if;
2097 -- Now check that the dot is preceded by digits
2099 Start := Finish;
2100 Finish := Finish - 1;
2101 while Start >= 1 and then Name_Buffer (Start - 1) in '0' .. '9' loop
2102 Start := Start - 1;
2103 end loop;
2105 -- If there are no digits, or if the digits are not preceded by the
2106 -- character that precedes a unit index, this is not the ALI file of
2107 -- a unit in a multi-unit source.
2109 if Start > Finish
2110 or else Start = 1
2111 or else Name_Buffer (Start - 1) /= Multi_Unit_Index_Character
2112 then
2113 return 0;
2114 end if;
2116 -- Build the index from the digit(s)
2118 while Start <= Finish loop
2119 Result := Result * 10 +
2120 Character'Pos (Name_Buffer (Start)) - Character'Pos ('0');
2121 Start := Start + 1;
2122 end loop;
2124 return Result;
2125 end Unit_Index_Of;
2127 -----------------
2128 -- Verbose_Msg --
2129 -----------------
2131 procedure Verbose_Msg
2132 (N1 : Name_Id;
2133 S1 : String;
2134 N2 : Name_Id := No_Name;
2135 S2 : String := "";
2136 Prefix : String := " -> ";
2137 Minimum_Verbosity : Opt.Verbosity_Level_Type := Opt.Low)
2139 begin
2140 if not Opt.Verbose_Mode
2141 or else Minimum_Verbosity > Opt.Verbosity_Level
2142 then
2143 return;
2144 end if;
2146 Write_Str (Prefix);
2147 Write_Str ("""");
2148 Write_Name (N1);
2149 Write_Str (""" ");
2150 Write_Str (S1);
2152 if N2 /= No_Name then
2153 Write_Str (" """);
2154 Write_Name (N2);
2155 Write_Str (""" ");
2156 end if;
2158 Write_Str (S2);
2159 Write_Eol;
2160 end Verbose_Msg;
2162 procedure Verbose_Msg
2163 (N1 : File_Name_Type;
2164 S1 : String;
2165 N2 : File_Name_Type := No_File;
2166 S2 : String := "";
2167 Prefix : String := " -> ";
2168 Minimum_Verbosity : Opt.Verbosity_Level_Type := Opt.Low)
2170 begin
2171 Verbose_Msg
2172 (Name_Id (N1), S1, Name_Id (N2), S2, Prefix, Minimum_Verbosity);
2173 end Verbose_Msg;
2175 -----------
2176 -- Queue --
2177 -----------
2179 package body Queue is
2181 type Q_Record is record
2182 Info : Source_Info;
2183 Processed : Boolean;
2184 end record;
2186 package Q is new Table.Table
2187 (Table_Component_Type => Q_Record,
2188 Table_Index_Type => Natural,
2189 Table_Low_Bound => 1,
2190 Table_Initial => 1000,
2191 Table_Increment => 100,
2192 Table_Name => "Makeutl.Queue.Q");
2193 -- This is the actual Queue
2195 package Busy_Obj_Dirs is new GNAT.HTable.Simple_HTable
2196 (Header_Num => Prj.Header_Num,
2197 Element => Boolean,
2198 No_Element => False,
2199 Key => Path_Name_Type,
2200 Hash => Hash,
2201 Equal => "=");
2203 type Mark_Key is record
2204 File : File_Name_Type;
2205 Index : Int;
2206 end record;
2207 -- Identify either a mono-unit source (when Index = 0) or a specific
2208 -- unit (index = 1's origin index of unit) in a multi-unit source.
2210 Max_Mask_Num : constant := 2048;
2211 subtype Mark_Num is Union_Id range 0 .. Max_Mask_Num - 1;
2213 function Hash (Key : Mark_Key) return Mark_Num;
2215 package Marks is new GNAT.HTable.Simple_HTable
2216 (Header_Num => Mark_Num,
2217 Element => Boolean,
2218 No_Element => False,
2219 Key => Mark_Key,
2220 Hash => Hash,
2221 Equal => "=");
2222 -- A hash table to keep tracks of the marked units.
2223 -- These are the units that have already been processed, when using the
2224 -- gnatmake format. When using the gprbuild format, we can directly
2225 -- store in the source_id whether the file has already been processed.
2227 procedure Mark (Source_File : File_Name_Type; Index : Int := 0);
2228 -- Mark a unit, identified by its source file and, when Index is not 0,
2229 -- the index of the unit in the source file. Marking is used to signal
2230 -- that the unit has already been inserted in the Q.
2232 function Is_Marked
2233 (Source_File : File_Name_Type;
2234 Index : Int := 0) return Boolean;
2235 -- Returns True if the unit was previously marked
2237 Q_Processed : Natural := 0;
2238 Q_Initialized : Boolean := False;
2240 Q_First : Natural := 1;
2241 -- Points to the first valid element in the queue
2243 One_Queue_Per_Obj_Dir : Boolean := False;
2244 -- See parameter to Initialize
2246 function Available_Obj_Dir (S : Source_Info) return Boolean;
2247 -- Whether the object directory for S is available for a build
2249 procedure Debug_Display (S : Source_Info);
2250 -- A debug display for S
2252 function Was_Processed (S : Source_Info) return Boolean;
2253 -- Whether S has already been processed. This marks the source as
2254 -- processed, if it hasn't already been processed.
2256 function Insert_No_Roots (Source : Source_Info) return Boolean;
2257 -- Insert Source, but do not look for its roots (see doc for Insert)
2259 -------------------
2260 -- Was_Processed --
2261 -------------------
2263 function Was_Processed (S : Source_Info) return Boolean is
2264 begin
2265 case S.Format is
2266 when Format_Gprbuild =>
2267 if S.Id.In_The_Queue then
2268 return True;
2269 end if;
2271 S.Id.In_The_Queue := True;
2273 when Format_Gnatmake =>
2274 if Is_Marked (S.File, S.Index) then
2275 return True;
2276 end if;
2278 Mark (S.File, Index => S.Index);
2279 end case;
2281 return False;
2282 end Was_Processed;
2284 -----------------------
2285 -- Available_Obj_Dir --
2286 -----------------------
2288 function Available_Obj_Dir (S : Source_Info) return Boolean is
2289 begin
2290 case S.Format is
2291 when Format_Gprbuild =>
2292 return not Busy_Obj_Dirs.Get
2293 (S.Id.Project.Object_Directory.Name);
2295 when Format_Gnatmake =>
2296 return S.Project = No_Project
2297 or else
2298 not Busy_Obj_Dirs.Get (S.Project.Object_Directory.Name);
2299 end case;
2300 end Available_Obj_Dir;
2302 -------------------
2303 -- Debug_Display --
2304 -------------------
2306 procedure Debug_Display (S : Source_Info) is
2307 begin
2308 case S.Format is
2309 when Format_Gprbuild =>
2310 Write_Name (S.Id.File);
2312 if S.Id.Index /= 0 then
2313 Write_Str (", ");
2314 Write_Int (S.Id.Index);
2315 end if;
2317 when Format_Gnatmake =>
2318 Write_Name (S.File);
2320 if S.Index /= 0 then
2321 Write_Str (", ");
2322 Write_Int (S.Index);
2323 end if;
2324 end case;
2325 end Debug_Display;
2327 ----------
2328 -- Hash --
2329 ----------
2331 function Hash (Key : Mark_Key) return Mark_Num is
2332 begin
2333 return Union_Id (Key.File) mod Max_Mask_Num;
2334 end Hash;
2336 ---------------
2337 -- Is_Marked --
2338 ---------------
2340 function Is_Marked
2341 (Source_File : File_Name_Type;
2342 Index : Int := 0) return Boolean
2344 begin
2345 return Marks.Get (K => (File => Source_File, Index => Index));
2346 end Is_Marked;
2348 ----------
2349 -- Mark --
2350 ----------
2352 procedure Mark (Source_File : File_Name_Type; Index : Int := 0) is
2353 begin
2354 Marks.Set (K => (File => Source_File, Index => Index), E => True);
2355 end Mark;
2357 -------------
2358 -- Extract --
2359 -------------
2361 procedure Extract
2362 (Found : out Boolean;
2363 Source : out Source_Info)
2365 begin
2366 Found := False;
2368 if One_Queue_Per_Obj_Dir then
2369 for J in Q_First .. Q.Last loop
2370 if not Q.Table (J).Processed
2371 and then Available_Obj_Dir (Q.Table (J).Info)
2372 then
2373 Found := True;
2374 Source := Q.Table (J).Info;
2375 Q.Table (J).Processed := True;
2377 if J = Q_First then
2378 while Q_First <= Q.Last
2379 and then Q.Table (Q_First).Processed
2380 loop
2381 Q_First := Q_First + 1;
2382 end loop;
2383 end if;
2385 exit;
2386 end if;
2387 end loop;
2389 elsif Q_First <= Q.Last then
2390 Source := Q.Table (Q_First).Info;
2391 Q.Table (Q_First).Processed := True;
2392 Q_First := Q_First + 1;
2393 Found := True;
2394 end if;
2396 if Found then
2397 Q_Processed := Q_Processed + 1;
2398 end if;
2400 if Found and then Debug.Debug_Flag_Q then
2401 Write_Str (" Q := Q - [ ");
2402 Debug_Display (Source);
2403 Write_Str (" ]");
2404 Write_Eol;
2406 Write_Str (" Q_First =");
2407 Write_Int (Int (Q_First));
2408 Write_Eol;
2410 Write_Str (" Q.Last =");
2411 Write_Int (Int (Q.Last));
2412 Write_Eol;
2413 end if;
2414 end Extract;
2416 ---------------
2417 -- Processed --
2418 ---------------
2420 function Processed return Natural is
2421 begin
2422 return Q_Processed;
2423 end Processed;
2425 ----------------
2426 -- Initialize --
2427 ----------------
2429 procedure Initialize
2430 (Queue_Per_Obj_Dir : Boolean;
2431 Force : Boolean := False)
2433 begin
2434 if Force or else not Q_Initialized then
2435 Q_Initialized := True;
2437 for J in 1 .. Q.Last loop
2438 case Q.Table (J).Info.Format is
2439 when Format_Gprbuild =>
2440 Q.Table (J).Info.Id.In_The_Queue := False;
2441 when Format_Gnatmake =>
2442 null;
2443 end case;
2444 end loop;
2446 Q.Init;
2447 Q_Processed := 0;
2448 Q_First := 1;
2449 One_Queue_Per_Obj_Dir := Queue_Per_Obj_Dir;
2450 end if;
2451 end Initialize;
2453 ---------------------
2454 -- Insert_No_Roots --
2455 ---------------------
2457 function Insert_No_Roots (Source : Source_Info) return Boolean is
2458 begin
2459 pragma Assert
2460 (Source.Format = Format_Gnatmake or else Source.Id /= No_Source);
2462 -- Only insert in the Q if it is not already done, to avoid
2463 -- simultaneous compilations if -jnnn is used.
2465 if Was_Processed (Source) then
2466 return False;
2467 end if;
2469 if Current_Verbosity = High then
2470 Write_Str ("Adding """);
2471 Debug_Display (Source);
2472 Write_Line (""" to the queue");
2473 end if;
2475 Q.Append (New_Val => (Info => Source, Processed => False));
2477 if Debug.Debug_Flag_Q then
2478 Write_Str (" Q := Q + [ ");
2479 Debug_Display (Source);
2480 Write_Str (" ] ");
2481 Write_Eol;
2483 Write_Str (" Q_First =");
2484 Write_Int (Int (Q_First));
2485 Write_Eol;
2487 Write_Str (" Q.Last =");
2488 Write_Int (Int (Q.Last));
2489 Write_Eol;
2490 end if;
2492 return True;
2493 end Insert_No_Roots;
2495 ------------
2496 -- Insert --
2497 ------------
2499 function Insert
2500 (Source : Source_Info;
2501 With_Roots : Boolean := False) return Boolean
2503 Root_Arr : Array_Element_Id;
2504 Roots : Variable_Value;
2505 List : String_List_Id;
2506 Elem : String_Element;
2507 Unit_Name : Name_Id;
2508 Pat_Root : Boolean;
2509 Root_Pattern : Regexp;
2510 Root_Found : Boolean;
2511 Roots_Found : Boolean;
2512 Root_Source : Prj.Source_Id;
2513 Iter : Source_Iterator;
2515 Dummy : Boolean;
2516 pragma Unreferenced (Dummy);
2518 begin
2519 if not Insert_No_Roots (Source) then
2521 -- Was already in the queue
2523 return False;
2524 end if;
2526 if With_Roots and then Source.Format = Format_Gprbuild then
2527 Debug_Output ("looking for roots of", Name_Id (Source.Id.File));
2529 Root_Arr :=
2530 Prj.Util.Value_Of
2531 (Name => Name_Roots,
2532 In_Arrays => Source.Id.Project.Decl.Arrays,
2533 Shared => Source.Tree.Shared);
2535 Roots :=
2536 Prj.Util.Value_Of
2537 (Index => Name_Id (Source.Id.File),
2538 Src_Index => 0,
2539 In_Array => Root_Arr,
2540 Shared => Source.Tree.Shared);
2542 -- If there is no roots for the specific main, try the language
2544 if Roots = Nil_Variable_Value then
2545 Roots :=
2546 Prj.Util.Value_Of
2547 (Index => Source.Id.Language.Name,
2548 Src_Index => 0,
2549 In_Array => Root_Arr,
2550 Shared => Source.Tree.Shared,
2551 Force_Lower_Case_Index => True);
2552 end if;
2554 -- Then try "*"
2556 if Roots = Nil_Variable_Value then
2557 Name_Len := 1;
2558 Name_Buffer (1) := '*';
2560 Roots :=
2561 Prj.Util.Value_Of
2562 (Index => Name_Find,
2563 Src_Index => 0,
2564 In_Array => Root_Arr,
2565 Shared => Source.Tree.Shared,
2566 Force_Lower_Case_Index => True);
2567 end if;
2569 if Roots = Nil_Variable_Value then
2570 Debug_Output (" -> no roots declared");
2572 else
2573 List := Roots.Values;
2575 Pattern_Loop :
2576 while List /= Nil_String loop
2577 Elem := Source.Tree.Shared.String_Elements.Table (List);
2578 Get_Name_String (Elem.Value);
2579 To_Lower (Name_Buffer (1 .. Name_Len));
2580 Unit_Name := Name_Find;
2582 -- Check if it is a unit name or a pattern
2584 Pat_Root := False;
2586 for J in 1 .. Name_Len loop
2587 if Name_Buffer (J) not in 'a' .. 'z' and then
2588 Name_Buffer (J) not in '0' .. '9' and then
2589 Name_Buffer (J) /= '_' and then
2590 Name_Buffer (J) /= '.'
2591 then
2592 Pat_Root := True;
2593 exit;
2594 end if;
2595 end loop;
2597 if Pat_Root then
2598 begin
2599 Root_Pattern :=
2600 Compile
2601 (Pattern => Name_Buffer (1 .. Name_Len),
2602 Glob => True);
2604 exception
2605 when Error_In_Regexp =>
2606 Err_Vars.Error_Msg_Name_1 := Unit_Name;
2607 Errutil.Error_Msg
2608 ("invalid pattern %", Roots.Location);
2609 exit Pattern_Loop;
2610 end;
2611 end if;
2613 Roots_Found := False;
2614 Iter := For_Each_Source (Source.Tree);
2616 Source_Loop :
2617 loop
2618 Root_Source := Prj.Element (Iter);
2619 exit Source_Loop when Root_Source = No_Source;
2621 Root_Found := False;
2622 if Pat_Root then
2623 Root_Found := Root_Source.Unit /= No_Unit_Index
2624 and then Match
2625 (Get_Name_String (Root_Source.Unit.Name),
2626 Root_Pattern);
2628 else
2629 Root_Found :=
2630 Root_Source.Unit /= No_Unit_Index
2631 and then Root_Source.Unit.Name = Unit_Name;
2632 end if;
2634 if Root_Found then
2635 case Root_Source.Kind is
2636 when Impl =>
2637 null;
2639 when Spec =>
2640 Root_Found := Other_Part (Root_Source) = No_Source;
2642 when Sep =>
2643 Root_Found := False;
2644 end case;
2645 end if;
2647 if Root_Found then
2648 Roots_Found := True;
2649 Debug_Output
2650 (" -> ", Name_Id (Root_Source.Display_File));
2651 Dummy := Queue.Insert_No_Roots
2652 (Source => (Format => Format_Gprbuild,
2653 Tree => Source.Tree,
2654 Id => Root_Source));
2656 Initialize_Source_Record (Root_Source);
2658 if Other_Part (Root_Source) /= No_Source then
2659 Initialize_Source_Record (Other_Part (Root_Source));
2660 end if;
2662 -- Save the root for the binder
2664 Source.Id.Roots := new Source_Roots'
2665 (Root => Root_Source,
2666 Next => Source.Id.Roots);
2668 exit Source_Loop when not Pat_Root;
2669 end if;
2671 Next (Iter);
2672 end loop Source_Loop;
2674 if not Roots_Found then
2675 if Pat_Root then
2676 if not Quiet_Output then
2677 Error_Msg_Name_1 := Unit_Name;
2678 Errutil.Error_Msg
2679 ("?no unit matches pattern %", Roots.Location);
2680 end if;
2682 else
2683 Errutil.Error_Msg
2684 ("Unit " & Get_Name_String (Unit_Name)
2685 & " does not exist", Roots.Location);
2686 end if;
2687 end if;
2689 List := Elem.Next;
2690 end loop Pattern_Loop;
2691 end if;
2692 end if;
2694 return True;
2695 end Insert;
2697 ------------
2698 -- Insert --
2699 ------------
2701 procedure Insert
2702 (Source : Source_Info;
2703 With_Roots : Boolean := False)
2705 Discard : Boolean;
2706 pragma Unreferenced (Discard);
2707 begin
2708 Discard := Insert (Source, With_Roots);
2709 end Insert;
2711 --------------
2712 -- Is_Empty --
2713 --------------
2715 function Is_Empty return Boolean is
2716 begin
2717 return Q_Processed >= Q.Last;
2718 end Is_Empty;
2720 ------------------------
2721 -- Is_Virtually_Empty --
2722 ------------------------
2724 function Is_Virtually_Empty return Boolean is
2725 begin
2726 if One_Queue_Per_Obj_Dir then
2727 for J in Q_First .. Q.Last loop
2728 if not Q.Table (J).Processed
2729 and then Available_Obj_Dir (Q.Table (J).Info)
2730 then
2731 return False;
2732 end if;
2733 end loop;
2735 return True;
2737 else
2738 return Is_Empty;
2739 end if;
2740 end Is_Virtually_Empty;
2742 ----------------------
2743 -- Set_Obj_Dir_Busy --
2744 ----------------------
2746 procedure Set_Obj_Dir_Busy (Obj_Dir : Path_Name_Type) is
2747 begin
2748 if One_Queue_Per_Obj_Dir then
2749 Busy_Obj_Dirs.Set (Obj_Dir, True);
2750 end if;
2751 end Set_Obj_Dir_Busy;
2753 ----------------------
2754 -- Set_Obj_Dir_Free --
2755 ----------------------
2757 procedure Set_Obj_Dir_Free (Obj_Dir : Path_Name_Type) is
2758 begin
2759 if One_Queue_Per_Obj_Dir then
2760 Busy_Obj_Dirs.Set (Obj_Dir, False);
2761 end if;
2762 end Set_Obj_Dir_Free;
2764 ----------
2765 -- Size --
2766 ----------
2768 function Size return Natural is
2769 begin
2770 return Q.Last;
2771 end Size;
2773 -------------
2774 -- Element --
2775 -------------
2777 function Element (Rank : Positive) return File_Name_Type is
2778 begin
2779 if Rank <= Q.Last then
2780 case Q.Table (Rank).Info.Format is
2781 when Format_Gprbuild =>
2782 return Q.Table (Rank).Info.Id.File;
2783 when Format_Gnatmake =>
2784 return Q.Table (Rank).Info.File;
2785 end case;
2786 else
2787 return No_File;
2788 end if;
2789 end Element;
2791 ------------------
2792 -- Remove_Marks --
2793 ------------------
2795 procedure Remove_Marks is
2796 begin
2797 Marks.Reset;
2798 end Remove_Marks;
2800 ----------------------------
2801 -- Insert_Project_Sources --
2802 ----------------------------
2804 procedure Insert_Project_Sources
2805 (Project : Project_Id;
2806 Project_Tree : Project_Tree_Ref;
2807 All_Projects : Boolean;
2808 Unique_Compile : Boolean)
2810 procedure Do_Insert (Project : Project_Id; Tree : Project_Tree_Ref);
2812 ---------------
2813 -- Do_Insert --
2814 ---------------
2816 procedure Do_Insert (Project : Project_Id; Tree : Project_Tree_Ref) is
2817 Unit_Based : constant Boolean :=
2818 Unique_Compile
2819 or else not Builder_Data (Tree).Closure_Needed;
2820 -- When Unit_Based is True, put in the queue all compilable
2821 -- sources including the unit based (Ada) one. When Unit_Based is
2822 -- False, put the Ada sources only when they are in a library
2823 -- project.
2825 Iter : Source_Iterator;
2826 Source : Prj.Source_Id;
2828 begin
2829 -- Nothing to do when "-u" was specified and some files were
2830 -- specified on the command line
2832 if Unique_Compile
2833 and then Mains.Number_Of_Mains (Tree) > 0
2834 then
2835 return;
2836 end if;
2838 Iter := For_Each_Source (Tree);
2839 loop
2840 Source := Prj.Element (Iter);
2841 exit when Source = No_Source;
2843 if Is_Allowed_Language (Source.Language.Name)
2844 and then Is_Compilable (Source)
2845 and then
2846 (All_Projects
2847 or else Is_Extending (Project, Source.Project))
2848 and then not Source.Locally_Removed
2849 and then Source.Replaced_By = No_Source
2850 and then
2851 (not Source.Project.Externally_Built
2852 or else
2853 (Is_Extending (Project, Source.Project)
2854 and then not Project.Externally_Built))
2855 and then Source.Kind /= Sep
2856 and then Source.Path /= No_Path_Information
2857 then
2858 if Source.Kind = Impl
2859 or else (Source.Unit /= No_Unit_Index
2860 and then Source.Kind = Spec
2861 and then (Other_Part (Source) = No_Source
2862 or else
2863 Other_Part (Source).Locally_Removed))
2864 then
2865 if (Unit_Based
2866 or else Source.Unit = No_Unit_Index
2867 or else Source.Project.Library)
2868 and then not Is_Subunit (Source)
2869 then
2870 Queue.Insert
2871 (Source => (Format => Format_Gprbuild,
2872 Tree => Tree,
2873 Id => Source));
2874 end if;
2875 end if;
2876 end if;
2878 Next (Iter);
2879 end loop;
2880 end Do_Insert;
2882 procedure Insert_All is new For_Project_And_Aggregated (Do_Insert);
2884 begin
2885 Insert_All (Project, Project_Tree);
2886 end Insert_Project_Sources;
2888 -------------------------------
2889 -- Insert_Withed_Sources_For --
2890 -------------------------------
2892 procedure Insert_Withed_Sources_For
2893 (The_ALI : ALI.ALI_Id;
2894 Project_Tree : Project_Tree_Ref;
2895 Excluding_Shared_SALs : Boolean := False)
2897 Sfile : File_Name_Type;
2898 Afile : File_Name_Type;
2899 Src_Id : Prj.Source_Id;
2901 begin
2902 -- Insert in the queue the unmarked source files (i.e. those which
2903 -- have never been inserted in the queue and hence never considered).
2905 for J in ALI.ALIs.Table (The_ALI).First_Unit ..
2906 ALI.ALIs.Table (The_ALI).Last_Unit
2907 loop
2908 for K in ALI.Units.Table (J).First_With ..
2909 ALI.Units.Table (J).Last_With
2910 loop
2911 Sfile := ALI.Withs.Table (K).Sfile;
2913 -- Skip generics
2915 if Sfile /= No_File then
2916 Afile := ALI.Withs.Table (K).Afile;
2918 Src_Id := Source_Files_Htable.Get
2919 (Project_Tree.Source_Files_HT, Sfile);
2920 while Src_Id /= No_Source loop
2921 Initialize_Source_Record (Src_Id);
2923 if Is_Compilable (Src_Id)
2924 and then Src_Id.Dep_Name = Afile
2925 then
2926 case Src_Id.Kind is
2927 when Spec =>
2928 declare
2929 Bdy : constant Prj.Source_Id :=
2930 Other_Part (Src_Id);
2931 begin
2932 if Bdy /= No_Source
2933 and then not Bdy.Locally_Removed
2934 then
2935 Src_Id := Other_Part (Src_Id);
2936 end if;
2937 end;
2939 when Impl =>
2940 if Is_Subunit (Src_Id) then
2941 Src_Id := No_Source;
2942 end if;
2944 when Sep =>
2945 Src_Id := No_Source;
2946 end case;
2948 exit;
2949 end if;
2951 Src_Id := Src_Id.Next_With_File_Name;
2952 end loop;
2954 -- If Excluding_Shared_SALs is True, do not insert in the
2955 -- queue the sources of a shared Stand-Alone Library.
2957 if Src_Id /= No_Source
2958 and then (not Excluding_Shared_SALs
2959 or else Src_Id.Project.Standalone_Library = No
2960 or else Src_Id.Project.Library_Kind = Static)
2961 then
2962 Queue.Insert
2963 (Source => (Format => Format_Gprbuild,
2964 Tree => Project_Tree,
2965 Id => Src_Id));
2966 end if;
2967 end if;
2968 end loop;
2969 end loop;
2970 end Insert_Withed_Sources_For;
2972 end Queue;
2974 ----------
2975 -- Free --
2976 ----------
2978 procedure Free (Data : in out Builder_Project_Tree_Data) is
2979 procedure Unchecked_Free is new Ada.Unchecked_Deallocation
2980 (Binding_Data_Record, Binding_Data);
2982 TmpB, Binding : Binding_Data := Data.Binding;
2984 begin
2985 while Binding /= null loop
2986 TmpB := Binding.Next;
2987 Unchecked_Free (Binding);
2988 Binding := TmpB;
2989 end loop;
2990 end Free;
2992 ------------------
2993 -- Builder_Data --
2994 ------------------
2996 function Builder_Data
2997 (Tree : Project_Tree_Ref) return Builder_Data_Access
2999 begin
3000 if Tree.Appdata = null then
3001 Tree.Appdata := new Builder_Project_Tree_Data;
3002 end if;
3004 return Builder_Data_Access (Tree.Appdata);
3005 end Builder_Data;
3007 --------------------------------
3008 -- Compute_Compilation_Phases --
3009 --------------------------------
3011 procedure Compute_Compilation_Phases
3012 (Tree : Project_Tree_Ref;
3013 Root_Project : Project_Id;
3014 Option_Unique_Compile : Boolean := False; -- Was "-u" specified ?
3015 Option_Compile_Only : Boolean := False; -- Was "-c" specified ?
3016 Option_Bind_Only : Boolean := False;
3017 Option_Link_Only : Boolean := False)
3019 procedure Do_Compute (Project : Project_Id; Tree : Project_Tree_Ref);
3021 ----------------
3022 -- Do_Compute --
3023 ----------------
3025 procedure Do_Compute (Project : Project_Id; Tree : Project_Tree_Ref) is
3026 Data : constant Builder_Data_Access := Builder_Data (Tree);
3027 All_Phases : constant Boolean :=
3028 not Option_Compile_Only
3029 and then not Option_Bind_Only
3030 and then not Option_Link_Only;
3031 -- Whether the command line asked for all three phases. Depending on
3032 -- the project settings, we might still disable some of the phases.
3034 Has_Mains : constant Boolean := Data.Number_Of_Mains > 0;
3035 -- Whether there are some main units defined for this project tree
3036 -- (either from one of the projects, or from the command line)
3038 begin
3039 if Option_Unique_Compile then
3041 -- If -u or -U is specified on the command line, disregard any -c,
3042 -- -b or -l switch: only perform compilation.
3044 Data.Closure_Needed := False;
3045 Data.Need_Compilation := True;
3046 Data.Need_Binding := False;
3047 Data.Need_Linking := False;
3049 else
3050 Data.Closure_Needed := Has_Mains;
3051 Data.Need_Compilation := All_Phases or Option_Compile_Only;
3052 Data.Need_Binding := All_Phases or Option_Bind_Only;
3053 Data.Need_Linking := (All_Phases or Option_Link_Only)
3054 and Has_Mains;
3055 end if;
3057 if Current_Verbosity = High then
3058 Debug_Output ("compilation phases: "
3059 & " compile=" & Data.Need_Compilation'Img
3060 & " bind=" & Data.Need_Binding'Img
3061 & " link=" & Data.Need_Linking'Img
3062 & " closure=" & Data.Closure_Needed'Img
3063 & " mains=" & Data.Number_Of_Mains'Img,
3064 Project.Name);
3065 end if;
3066 end Do_Compute;
3068 procedure Compute_All is new For_Project_And_Aggregated (Do_Compute);
3070 begin
3071 Compute_All (Root_Project, Tree);
3072 end Compute_Compilation_Phases;
3074 ------------------------------
3075 -- Compute_Builder_Switches --
3076 ------------------------------
3078 procedure Compute_Builder_Switches
3079 (Project_Tree : Project_Tree_Ref;
3080 Root_Environment : in out Prj.Tree.Environment;
3081 Main_Project : Project_Id;
3082 Only_For_Lang : Name_Id := No_Name)
3084 Builder_Package : constant Package_Id :=
3085 Value_Of (Name_Builder, Main_Project.Decl.Packages,
3086 Project_Tree.Shared);
3088 Global_Compilation_Array : Array_Element_Id;
3089 Global_Compilation_Elem : Array_Element;
3090 Global_Compilation_Switches : Variable_Value;
3092 Default_Switches_Array : Array_Id;
3094 Builder_Switches_Lang : Name_Id := No_Name;
3096 List : String_List_Id;
3097 Element : String_Element;
3099 Index : Name_Id;
3100 Source : Prj.Source_Id;
3102 Lang : Name_Id := No_Name; -- language index for Switches
3103 Switches_For_Lang : Variable_Value := Nil_Variable_Value;
3104 -- Value of Builder'Default_Switches(lang)
3106 Name : Name_Id := No_Name; -- main file index for Switches
3107 Switches_For_Main : Variable_Value := Nil_Variable_Value;
3108 -- Switches for a specific main. When there are several mains, Name is
3109 -- set to No_Name, and Switches_For_Main might be left with an actual
3110 -- value (so that we can display a warning that it was ignored).
3112 Other_Switches : Variable_Value := Nil_Variable_Value;
3113 -- Value of Builder'Switches(others)
3115 Defaults : Variable_Value := Nil_Variable_Value;
3117 Switches : Variable_Value := Nil_Variable_Value;
3118 -- The computed builder switches
3120 Success : Boolean := False;
3121 begin
3122 if Builder_Package /= No_Package then
3123 Mains.Reset;
3125 -- If there is no main, and there is only one compilable language,
3126 -- use this language as the switches index.
3128 if Mains.Number_Of_Mains (Project_Tree) = 0 then
3129 if Only_For_Lang = No_Name then
3130 declare
3131 Language : Language_Ptr := Main_Project.Languages;
3133 begin
3134 while Language /= No_Language_Index loop
3135 if Language.Config.Compiler_Driver /= No_File
3136 and then Language.Config.Compiler_Driver /= Empty_File
3137 then
3138 if Lang /= No_Name then
3139 Lang := No_Name;
3140 exit;
3141 else
3142 Lang := Language.Name;
3143 end if;
3144 end if;
3145 Language := Language.Next;
3146 end loop;
3147 end;
3148 else
3149 Lang := Only_For_Lang;
3150 end if;
3152 else
3153 for Index in 1 .. Mains.Number_Of_Mains (Project_Tree) loop
3154 Source := Mains.Next_Main.Source;
3156 if Source /= No_Source then
3157 if Switches_For_Main = Nil_Variable_Value then
3158 Switches_For_Main := Value_Of
3159 (Name => Name_Id (Source.File),
3160 Attribute_Or_Array_Name => Name_Switches,
3161 In_Package => Builder_Package,
3162 Shared => Project_Tree.Shared,
3163 Force_Lower_Case_Index => False,
3164 Allow_Wildcards => True);
3166 -- If not found, try without extension.
3167 -- That's because gnatmake accepts truncated file names
3168 -- in Builder'Switches
3170 if Switches_For_Main = Nil_Variable_Value
3171 and then Source.Unit /= null
3172 then
3173 Switches_For_Main := Value_Of
3174 (Name => Source.Unit.Name,
3175 Attribute_Or_Array_Name => Name_Switches,
3176 In_Package => Builder_Package,
3177 Shared => Project_Tree.Shared,
3178 Force_Lower_Case_Index => False,
3179 Allow_Wildcards => True);
3180 end if;
3181 end if;
3183 if Index = 1 then
3184 Lang := Source.Language.Name;
3185 Name := Name_Id (Source.File);
3186 else
3187 Name := No_Name; -- Can't use main specific switches
3189 if Lang /= Source.Language.Name then
3190 Lang := No_Name;
3191 end if;
3192 end if;
3193 end if;
3194 end loop;
3195 end if;
3197 Global_Compilation_Array := Value_Of
3198 (Name => Name_Global_Compilation_Switches,
3199 In_Arrays => Project_Tree.Shared.Packages.Table
3200 (Builder_Package).Decl.Arrays,
3201 Shared => Project_Tree.Shared);
3203 Default_Switches_Array :=
3204 Project_Tree.Shared.Packages.Table (Builder_Package).Decl.Arrays;
3206 while Default_Switches_Array /= No_Array
3207 and then
3208 Project_Tree.Shared.Arrays.Table (Default_Switches_Array).Name /=
3209 Name_Default_Switches
3210 loop
3211 Default_Switches_Array :=
3212 Project_Tree.Shared.Arrays.Table (Default_Switches_Array).Next;
3213 end loop;
3215 if Global_Compilation_Array /= No_Array_Element
3216 and then Default_Switches_Array /= No_Array
3217 then
3218 Prj.Err.Error_Msg
3219 (Root_Environment.Flags,
3220 "Default_Switches forbidden in presence of " &
3221 "Global_Compilation_Switches. Use Switches instead.",
3222 Project_Tree.Shared.Arrays.Table
3223 (Default_Switches_Array).Location);
3224 Fail_Program
3225 (Project_Tree,
3226 "*** illegal combination of Builder attributes");
3227 end if;
3229 if Lang /= No_Name then
3230 Switches_For_Lang := Prj.Util.Value_Of
3231 (Name => Lang,
3232 Index => 0,
3233 Attribute_Or_Array_Name => Name_Switches,
3234 In_Package => Builder_Package,
3235 Shared => Project_Tree.Shared,
3236 Force_Lower_Case_Index => True);
3238 Defaults := Prj.Util.Value_Of
3239 (Name => Lang,
3240 Index => 0,
3241 Attribute_Or_Array_Name => Name_Default_Switches,
3242 In_Package => Builder_Package,
3243 Shared => Project_Tree.Shared,
3244 Force_Lower_Case_Index => True);
3245 end if;
3247 Other_Switches := Prj.Util.Value_Of
3248 (Name => All_Other_Names,
3249 Index => 0,
3250 Attribute_Or_Array_Name => Name_Switches,
3251 In_Package => Builder_Package,
3252 Shared => Project_Tree.Shared);
3254 if not Quiet_Output
3255 and then Mains.Number_Of_Mains (Project_Tree) > 1
3256 and then Switches_For_Main /= Nil_Variable_Value
3257 then
3258 -- More than one main, but we had main-specific switches that
3259 -- are ignored.
3261 if Switches_For_Lang /= Nil_Variable_Value then
3262 Write_Line
3263 ("Warning: using Builder'Switches("""
3264 & Get_Name_String (Lang)
3265 & """), as there are several mains");
3267 elsif Other_Switches /= Nil_Variable_Value then
3268 Write_Line
3269 ("Warning: using Builder'Switches(others), "
3270 & "as there are several mains");
3272 elsif Defaults /= Nil_Variable_Value then
3273 Write_Line
3274 ("Warning: using Builder'Default_Switches("""
3275 & Get_Name_String (Lang)
3276 & """), as there are several mains");
3277 else
3278 Write_Line
3279 ("Warning: using no switches from package "
3280 & "Builder, as there are several mains");
3281 end if;
3282 end if;
3284 Builder_Switches_Lang := Lang;
3286 if Name /= No_Name then
3287 -- Get the switches for the single main
3288 Switches := Switches_For_Main;
3289 end if;
3291 if Switches = Nil_Variable_Value or else Switches.Default then
3292 -- Get the switches for the common language of the mains
3293 Switches := Switches_For_Lang;
3294 end if;
3296 if Switches = Nil_Variable_Value or else Switches.Default then
3297 Switches := Other_Switches;
3298 end if;
3300 -- For backward compatibility with gnatmake, if no Switches
3301 -- are declared, check for Default_Switches (<language>).
3303 if Switches = Nil_Variable_Value or else Switches.Default then
3304 Switches := Defaults;
3305 end if;
3307 -- If switches have been found, scan them
3309 if Switches /= Nil_Variable_Value and then not Switches.Default then
3310 List := Switches.Values;
3312 while List /= Nil_String loop
3313 Element := Project_Tree.Shared.String_Elements.Table (List);
3314 Get_Name_String (Element.Value);
3316 if Name_Len /= 0 then
3317 declare
3318 -- Add_Switch might itself be using the name_buffer, so
3319 -- we make a temporary here.
3320 Switch : constant String := Name_Buffer (1 .. Name_Len);
3321 begin
3322 Success := Add_Switch
3323 (Switch => Switch,
3324 For_Lang => Builder_Switches_Lang,
3325 For_Builder => True,
3326 Has_Global_Compilation_Switches =>
3327 Global_Compilation_Array /= No_Array_Element);
3328 end;
3330 if not Success then
3331 for J in reverse 1 .. Name_Len loop
3332 Name_Buffer (J + J) := Name_Buffer (J);
3333 Name_Buffer (J + J - 1) := ''';
3334 end loop;
3336 Name_Len := Name_Len + Name_Len;
3338 Prj.Err.Error_Msg
3339 (Root_Environment.Flags,
3340 '"' & Name_Buffer (1 .. Name_Len) &
3341 """ is not a builder switch. Consider moving " &
3342 "it to Global_Compilation_Switches.",
3343 Element.Location);
3344 Fail_Program
3345 (Project_Tree,
3346 "*** illegal switch """ &
3347 Get_Name_String (Element.Value) & '"');
3348 end if;
3349 end if;
3351 List := Element.Next;
3352 end loop;
3353 end if;
3355 -- Reset the Builder Switches language
3357 Builder_Switches_Lang := No_Name;
3359 -- Take into account attributes Global_Compilation_Switches
3361 while Global_Compilation_Array /= No_Array_Element loop
3362 Global_Compilation_Elem :=
3363 Project_Tree.Shared.Array_Elements.Table
3364 (Global_Compilation_Array);
3366 Get_Name_String (Global_Compilation_Elem.Index);
3367 To_Lower (Name_Buffer (1 .. Name_Len));
3368 Index := Name_Find;
3370 if Only_For_Lang = No_Name or else Index = Only_For_Lang then
3371 Global_Compilation_Switches := Global_Compilation_Elem.Value;
3373 if Global_Compilation_Switches /= Nil_Variable_Value
3374 and then not Global_Compilation_Switches.Default
3375 then
3376 -- We have found an attribute
3377 -- Global_Compilation_Switches for a language: put the
3378 -- switches in the appropriate table.
3380 List := Global_Compilation_Switches.Values;
3381 while List /= Nil_String loop
3382 Element :=
3383 Project_Tree.Shared.String_Elements.Table (List);
3385 if Element.Value /= No_Name then
3386 Success := Add_Switch
3387 (Switch => Get_Name_String (Element.Value),
3388 For_Lang => Index,
3389 For_Builder => False,
3390 Has_Global_Compilation_Switches =>
3391 Global_Compilation_Array /= No_Array_Element);
3392 end if;
3394 List := Element.Next;
3395 end loop;
3396 end if;
3397 end if;
3399 Global_Compilation_Array := Global_Compilation_Elem.Next;
3400 end loop;
3401 end if;
3402 end Compute_Builder_Switches;
3404 ---------------------
3405 -- Write_Path_File --
3406 ---------------------
3408 procedure Write_Path_File (FD : File_Descriptor) is
3409 Last : Natural;
3410 Status : Boolean;
3412 begin
3413 Name_Len := 0;
3415 for Index in Directories.First .. Directories.Last loop
3416 Add_Str_To_Name_Buffer (Get_Name_String (Directories.Table (Index)));
3417 Add_Char_To_Name_Buffer (ASCII.LF);
3418 end loop;
3420 Last := Write (FD, Name_Buffer (1)'Address, Name_Len);
3422 if Last = Name_Len then
3423 Close (FD, Status);
3424 else
3425 Status := False;
3426 end if;
3428 if not Status then
3429 Prj.Com.Fail ("could not write temporary file");
3430 end if;
3431 end Write_Path_File;
3433 end Makeutl;