1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2007, AdaCore --
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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
28 with Gnatvsn; use Gnatvsn;
29 with MLib.Fil; use MLib.Fil;
30 with MLib.Tgt; use MLib.Tgt;
31 with MLib.Utl; use MLib.Utl;
33 with Output; use Output;
34 with Prj.Com; use Prj.Com;
35 with Prj.Env; use Prj.Env;
36 with Prj.Util; use Prj.Util;
38 with Snames; use Snames;
39 with Switch; use Switch;
41 with Targparm; use Targparm;
43 with Types; use Types;
45 with Ada.Characters.Handling;
47 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
49 with Interfaces.C_Streams; use Interfaces.C_Streams;
50 with System; use System;
51 with System.Case_Util; use System.Case_Util;
53 package body MLib.Prj is
55 Prj_Add_Obj_Files : Types.Int;
56 pragma Import (C, Prj_Add_Obj_Files, "__gnat_prj_add_obj_files");
57 Add_Object_Files : constant Boolean := Prj_Add_Obj_Files /= 0;
58 -- Indicates if object files in pragmas Linker_Options (found in the
59 -- binder generated file) should be taken when linking a stand-alone
60 -- library. False for Windows, True for other platforms.
62 ALI_Suffix : constant String := ".ali";
64 B_Start : String_Ptr := new String'("b~");
65 -- Prefix of bind file, changed to b__ for VMS
67 S_Osinte_Ads : File_Name_Type := No_File;
68 -- Name_Id for "s-osinte.ads"
70 S_Dec_Ads : File_Name_Type := No_File;
71 -- Name_Id for "dec.ads"
73 G_Trasym_Ads : File_Name_Type := No_File;
74 -- Name_Id for "g-trasym.ads"
76 Arguments : String_List_Access := No_Argument;
77 -- Used to accumulate arguments for the invocation of gnatbind and of
78 -- the compiler. Also used to collect the interface ALI when copying
79 -- the ALI files to the library directory.
81 Argument_Number : Natural := 0;
82 -- Index of the last argument in Arguments
84 Initial_Argument_Max : constant := 10;
86 No_Main_String : aliased String := "-n";
87 No_Main : constant String_Access := No_Main_String'Access;
89 Output_Switch_String : aliased String := "-o";
90 Output_Switch : constant String_Access := Output_Switch_String'Access;
92 Compile_Switch_String : aliased String := "-c";
93 Compile_Switch : constant String_Access := Compile_Switch_String'Access;
95 Auto_Initialize : constant String := "-a";
97 -- List of objects to put inside the library
99 Object_Files : Argument_List_Access;
101 package Objects is new Table.Table
102 (Table_Name => "Mlib.Prj.Objects",
103 Table_Component_Type => String_Access,
104 Table_Index_Type => Natural,
105 Table_Low_Bound => 1,
107 Table_Increment => 100);
109 package Objects_Htable is new GNAT.HTable.Simple_HTable
110 (Header_Num => Header_Num,
119 Ali_Files : Argument_List_Access;
121 package ALIs is new Table.Table
122 (Table_Name => "Mlib.Prj.Alis",
123 Table_Component_Type => String_Access,
124 Table_Index_Type => Natural,
125 Table_Low_Bound => 1,
127 Table_Increment => 100);
129 -- List of options set in the command line
131 Options : Argument_List_Access;
133 package Opts is new Table.Table
134 (Table_Name => "Mlib.Prj.Opts",
135 Table_Component_Type => String_Access,
136 Table_Index_Type => Natural,
137 Table_Low_Bound => 1,
139 Table_Increment => 100);
141 -- All the ALI file in the library
143 package Library_ALIs is new GNAT.HTable.Simple_HTable
144 (Header_Num => Header_Num,
147 Key => File_Name_Type,
151 -- The ALI files in the interface sets
153 package Interface_ALIs is new GNAT.HTable.Simple_HTable
154 (Header_Num => Header_Num,
157 Key => File_Name_Type,
161 -- The ALI files that have been processed to check if the corresponding
162 -- library unit is in the interface set.
164 package Processed_ALIs is new GNAT.HTable.Simple_HTable
165 (Header_Num => Header_Num,
168 Key => File_Name_Type,
172 -- The projects imported directly or indirectly
174 package Processed_Projects is new GNAT.HTable.Simple_HTable
175 (Header_Num => Header_Num,
182 -- The library projects imported directly or indirectly
184 package Library_Projs is new Table.Table (
185 Table_Component_Type => Project_Id,
186 Table_Index_Type => Integer,
187 Table_Low_Bound => 1,
189 Table_Increment => 10,
190 Table_Name => "Make.Library_Projs");
192 type Build_Mode_State is (None, Static, Dynamic, Relocatable);
194 procedure Add_Argument (S : String);
195 -- Add one argument to Arguments array, if array is full, double its size
197 function ALI_File_Name (Source : String) return String;
198 -- Return the ALI file name corresponding to a source
200 procedure Check (Filename : String);
201 -- Check if filename is a regular file. Fail if it is not
203 procedure Check_Context;
204 -- Check each object files in table Object_Files
205 -- Fail if any of them is not a regular file
207 procedure Copy_Interface_Sources
208 (For_Project : Project_Id;
209 In_Tree : Project_Tree_Ref;
210 Interfaces : Argument_List;
211 To_Dir : Path_Name_Type);
212 -- Copy the interface sources of a SAL to directory To_Dir
214 procedure Display (Executable : String);
215 -- Display invocation of gnatbind and of the compiler with the arguments
216 -- in Arguments, except when Quiet_Output is True.
218 function Index (S, Pattern : String) return Natural;
219 -- Return the last occurrence of Pattern in S, or 0 if none
221 procedure Process_Binder_File (Name : String);
222 -- For Stand-Alone libraries, get the Linker Options in the binder
225 procedure Reset_Tables;
226 -- Make sure that all the above tables are empty
227 -- (Objects, Ali_Files, Options).
229 function SALs_Use_Constructors return Boolean;
230 -- Indicate if Stand-Alone Libraries are automatically initialized using
231 -- the constructor mechanism.
233 function Ultimate_Extension_Of
234 (Project : Project_Id;
235 In_Tree : Project_Tree_Ref) return Project_Id;
236 -- Returns the Project_Id of project Project. Returns No_Project
237 -- if Project is No_Project.
243 procedure Add_Argument (S : String) is
245 if Argument_Number = Arguments'Last then
247 New_Args : constant String_List_Access :=
248 new String_List (1 .. 2 * Arguments'Last);
251 -- Copy the String_Accesses and set them to null in Arguments
252 -- so that they will not be deallocated by the call to
255 New_Args (Arguments'Range) := Arguments.all;
256 Arguments.all := (others => null);
258 Arguments := New_Args;
262 Argument_Number := Argument_Number + 1;
263 Arguments (Argument_Number) := new String'(S);
270 function ALI_File_Name (Source : String) return String is
272 -- If the source name has an extension, then replace it with
275 for Index in reverse Source'First + 1 .. Source'Last loop
276 if Source (Index) = '.' then
277 return Source (Source'First .. Index - 1) & ALI_Suffix;
281 -- If there is no dot, or if it is the first character, just add the
284 return Source & ALI_Suffix;
291 procedure Build_Library
292 (For_Project : Project_Id;
293 In_Tree : Project_Tree_Ref;
295 Gnatbind_Path : String_Access;
297 Gcc_Path : String_Access;
298 Bind : Boolean := True;
299 Link : Boolean := True)
301 Maximum_Size : Integer;
302 pragma Import (C, Maximum_Size, "__gnat_link_max");
303 -- Maximum number of bytes to put in an invocation of the
307 -- The number of bytes for the invocation of the gnatbind
309 Warning_For_Library : Boolean := False;
310 -- Set to True for the first warning about a unit missing from the
313 Data : Project_Data := In_Tree.Projects.Table (For_Project);
315 Libgnarl_Needed : Yes_No_Unknown := Data.Libgnarl_Needed;
316 -- Set to True if library needs to be linked with libgnarl
318 Libdecgnat_Needed : Boolean := False;
319 -- On OpenVMS, set to True if library needs to be linked with libdecgnat
321 Gtrasymobj_Needed : Boolean := False;
322 -- On OpenVMS, set to True if library needs to be linked with
325 Object_Directory_Path : constant String :=
326 Get_Name_String (Data.Display_Object_Dir);
328 Standalone : constant Boolean := Data.Standalone_Library;
330 Project_Name : constant String := Get_Name_String (Data.Name);
332 Current_Dir : constant String := Get_Current_Dir;
334 Lib_Filename : String_Access;
335 Lib_Dirpath : String_Access;
336 Lib_Version : String_Access := new String'("");
338 The_Build_Mode : Build_Mode_State := None;
340 Success : Boolean := False;
342 Library_Options : Variable_Value := Nil_Variable_Value;
343 Library_GCC : Variable_Value := Nil_Variable_Value;
345 Driver_Name : Name_Id := No_Name;
347 In_Main_Object_Directory : Boolean := True;
349 There_Are_Foreign_Sources : Boolean;
351 Rpath : String_Access := null;
352 -- Allocated only if Path Option is supported
354 Rpath_Last : Natural := 0;
355 -- Index of last valid character of Rpath
357 Initial_Rpath_Length : constant := 200;
358 -- Initial size of Rpath, when first allocated
360 Path_Option : String_Access := Linker_Library_Path_Option;
361 -- If null, Path Option is not supported.
362 -- Not a constant so that it can be deallocated.
364 First_ALI : File_Name_Type := No_File;
365 -- Store the ALI file name of a source of the library (the first found)
367 procedure Add_ALI_For (Source : File_Name_Type);
368 -- Add the name of the ALI file corresponding to Source to the
371 procedure Add_Rpath (Path : String);
372 -- Add a path name to Rpath
374 function Check_Project (P : Project_Id) return Boolean;
375 -- Returns True if P is For_Project or a project extended by For_Project
377 procedure Check_Libs (ALI_File : String; Main_Project : Boolean);
378 -- Set Libgnarl_Needed if the ALI_File indicates that there is a need
379 -- to link with -lgnarl (this is the case when there is a dependency
380 -- on s-osinte.ads). On OpenVMS, set Libdecgnat_Needed if the ALI file
381 -- indicates that there is a need to link with -ldecgnat (this is the
382 -- case when there is a dependency on dec.ads), and set
383 -- Gtrasymobj_Needed if there is a dependency on g-trasym.ads.
385 procedure Process (The_ALI : File_Name_Type);
386 -- Check if the closure of a library unit which is or should be in the
387 -- interface set is also in the interface set. Issue a warning for each
388 -- missing library unit.
390 procedure Process_Imported_Libraries;
391 -- Add the -L and -l switches for the imported Library Project Files,
392 -- and, if Path Option is supported, the library directory path names
399 procedure Add_ALI_For (Source : File_Name_Type) is
400 ALI : constant String := ALI_File_Name (Get_Name_String (Source));
401 ALI_Id : File_Name_Type;
409 Add_Str_To_Name_Buffer (S => ALI);
412 -- Add the ALI file name to the library ALIs
415 Library_ALIs.Set (ALI_Id, True);
418 -- Set First_ALI, if not already done
420 if First_ALI = No_File then
429 procedure Add_Rpath (Path : String) is
439 New_Rpath : constant String_Access :=
440 new String (1 .. 2 * Rpath'Length);
442 New_Rpath (1 .. Rpath_Last) := Rpath (1 .. Rpath_Last);
447 -- Start of processing for Add_Rpath
450 -- If firt path, allocate initial Rpath
453 Rpath := new String (1 .. Initial_Rpath_Length);
457 -- Otherwise, add a path separator between two path names
459 if Rpath_Last = Rpath'Last then
463 Rpath_Last := Rpath_Last + 1;
464 Rpath (Rpath_Last) := Path_Separator;
467 -- Increase Rpath size until it is large enough
469 while Rpath_Last + Path'Length > Rpath'Last loop
475 Rpath (Rpath_Last + 1 .. Rpath_Last + Path'Length) := Path;
476 Rpath_Last := Rpath_Last + Path'Length;
483 function Check_Project (P : Project_Id) return Boolean is
485 if P = For_Project then
488 elsif P /= No_Project then
490 Data : Project_Data :=
491 In_Tree.Projects.Table (For_Project);
493 while Data.Extends /= No_Project loop
494 if P = Data.Extends then
498 Data := In_Tree.Projects.Table (Data.Extends);
510 procedure Check_Libs (ALI_File : String; Main_Project : Boolean) is
511 Lib_File : File_Name_Type;
512 Text : Text_Buffer_Ptr;
516 if Libgnarl_Needed /= Yes
519 and then OpenVMS_On_Target
520 and then ((not Libdecgnat_Needed) or (not Gtrasymobj_Needed)))
524 Name_Len := ALI_File'Length;
525 Name_Buffer (1 .. Name_Len) := ALI_File;
526 Lib_File := Name_Find;
527 Text := Read_Library_Info (Lib_File, True);
537 -- Look for s-osinte.ads in the dependencies
539 for Index in ALI.ALIs.Table (Id).First_Sdep ..
540 ALI.ALIs.Table (Id).Last_Sdep
542 if ALI.Sdep.Table (Index).Sfile = S_Osinte_Ads then
543 Libgnarl_Needed := Yes;
546 In_Tree.Projects.Table (For_Project).Libgnarl_Needed :=
552 elsif OpenVMS_On_Target then
553 if ALI.Sdep.Table (Index).Sfile = S_Dec_Ads then
554 Libdecgnat_Needed := True;
556 elsif ALI.Sdep.Table (Index).Sfile = G_Trasym_Ads then
557 Gtrasymobj_Needed := True;
568 procedure Process (The_ALI : File_Name_Type) is
569 Text : Text_Buffer_Ptr;
571 First_Unit : ALI.Unit_Id;
572 Last_Unit : ALI.Unit_Id;
573 Unit_Data : Unit_Record;
574 Afile : File_Name_Type;
577 -- Nothing to do if the ALI file has already been processed.
578 -- This happens if an interface imports another interface.
580 if not Processed_ALIs.Get (The_ALI) then
581 Processed_ALIs.Set (The_ALI, True);
582 Text := Read_Library_Info (The_ALI);
593 if Idread /= No_ALI_Id then
594 First_Unit := ALI.ALIs.Table (Idread).First_Unit;
595 Last_Unit := ALI.ALIs.Table (Idread).Last_Unit;
597 -- Process both unit (spec and body) if the body is needed
598 -- by the spec (inline or generic). Otherwise, just process
601 if First_Unit /= Last_Unit and then
602 not ALI.Units.Table (Last_Unit).Body_Needed_For_SAL
604 First_Unit := Last_Unit;
607 for Unit in First_Unit .. Last_Unit loop
608 Unit_Data := ALI.Units.Table (Unit);
610 -- Check if each withed unit which is in the library is
611 -- also in the interface set, if it has not yet been
614 for W in Unit_Data.First_With .. Unit_Data.Last_With loop
615 Afile := Withs.Table (W).Afile;
617 if Afile /= No_File and then Library_ALIs.Get (Afile)
618 and then not Processed_ALIs.Get (Afile)
620 if not Interface_ALIs.Get (Afile) then
621 if not Warning_For_Library then
622 Write_Str ("Warning: In library project """);
623 Get_Name_String (Data.Name);
624 To_Mixed (Name_Buffer (1 .. Name_Len));
625 Write_Str (Name_Buffer (1 .. Name_Len));
627 Warning_For_Library := True;
630 Write_Str (" Unit """);
631 Get_Name_String (Withs.Table (W).Uname);
632 To_Mixed (Name_Buffer (1 .. Name_Len - 2));
633 Write_Str (Name_Buffer (1 .. Name_Len - 2));
634 Write_Line (""" is not in the interface set");
635 Write_Str (" but it is needed by ");
637 case Unit_Data.Utype is
639 Write_Str ("the spec of ");
642 Write_Str ("the body of ");
649 Get_Name_String (Unit_Data.Uname);
650 To_Mixed (Name_Buffer (1 .. Name_Len - 2));
651 Write_Str (Name_Buffer (1 .. Name_Len - 2));
655 -- Now, process this unit
666 --------------------------------
667 -- Process_Imported_Libraries --
668 --------------------------------
670 procedure Process_Imported_Libraries is
671 Current : Project_Id;
673 procedure Process_Project (Project : Project_Id);
674 -- Process Project and its imported projects recursively.
675 -- Add any library projects to table Library_Projs.
677 ---------------------
678 -- Process_Project --
679 ---------------------
681 procedure Process_Project (Project : Project_Id) is
682 Data : Project_Data := In_Tree.Projects.Table (Project);
683 Imported : Project_List := Data.Imported_Projects;
684 Element : Project_Element;
687 -- Nothing to do if process has already been processed
689 if not Processed_Projects.Get (Data.Name) then
690 Processed_Projects.Set (Data.Name, True);
692 -- Call Process_Project recursively for any imported project.
693 -- We first process the imported projects to guarantee that
694 -- we have a proper reverse order for the libraries.
696 while Imported /= Empty_Project_List loop
698 In_Tree.Project_Lists.Table (Imported);
700 if Element.Project /= No_Project then
701 Process_Project (Element.Project);
704 Imported := Element.Next;
707 -- If it is a library project, add it to Library_Projs
709 if Project /= For_Project and then Data.Library then
710 Library_Projs.Increment_Last;
711 Library_Projs.Table (Library_Projs.Last) := Project;
713 -- Check if because of this library we need to use libgnarl
715 if Libgnarl_Needed = Unknown then
716 if Data.Libgnarl_Needed = Unknown
717 and then Data.Object_Directory /= No_Path
719 -- Check if libgnarl is needed for this library
722 Object_Dir_Path : constant String :=
724 (Data.Display_Object_Dir);
725 Object_Dir : Dir_Type;
726 Filename : String (1 .. 255);
730 Open (Object_Dir, Object_Dir_Path);
732 -- For all entries in the object directory
735 Read (Object_Dir, Filename, Last);
738 -- Check if it is an object file
740 if Is_Obj (Filename (1 .. Last)) then
742 Object_Path : constant String :=
745 Directory_Separator &
746 Filename (1 .. Last));
747 ALI_File : constant String :=
749 (Object_Path, "ali");
752 if Is_Regular_File (ALI_File) then
754 -- Find out if for this ALI file,
755 -- libgnarl is necessary.
758 (ALI_File, Main_Project => False);
760 if Libgnarl_Needed = Yes then
761 Data.Libgnarl_Needed := Yes;
762 In_Tree.Projects.Table
763 (For_Project).Libgnarl_Needed :=
776 if Data.Libgnarl_Needed = Yes then
777 Libgnarl_Needed := Yes;
778 In_Tree.Projects.Table (For_Project).Libgnarl_Needed :=
787 -- Start of processing for Process_Imported_Libraries
790 -- Build list of library projects imported directly or indirectly,
791 -- in the reverse order.
793 Process_Project (For_Project);
795 -- Add the -L and -l switches and, if the Rpath option is supported,
796 -- add the directory to the Rpath. As the library projects are in the
797 -- wrong order, process from the last to the first.
799 for Index in reverse 1 .. Library_Projs.Last loop
800 Current := Library_Projs.Table (Index);
803 (In_Tree.Projects.Table (Current).Display_Library_Dir);
805 Opts.Table (Opts.Last) :=
806 new String'("-L" & Name_Buffer (1 .. Name_Len));
808 if Path_Option /= null then
809 Add_Rpath (Name_Buffer (1 .. Name_Len));
813 Opts.Table (Opts.Last) :=
817 (In_Tree.Projects.Table
818 (Current).Library_Name));
820 end Process_Imported_Libraries;
822 -- Start of processing for Build_Library
827 -- Fail if project is not a library project
829 if not Data.Library then
830 Com.Fail ("project """, Project_Name, """ has no library");
833 -- If this is the first time Build_Library is called, get the Name_Id
834 -- of "s-osinte.ads".
836 if S_Osinte_Ads = No_File then
838 Add_Str_To_Name_Buffer ("s-osinte.ads");
839 S_Osinte_Ads := Name_Find;
842 if S_Dec_Ads = No_File then
844 Add_Str_To_Name_Buffer ("dec.ads");
845 S_Dec_Ads := Name_Find;
848 if G_Trasym_Ads = No_File then
850 Add_Str_To_Name_Buffer ("g-trasym.ads");
851 G_Trasym_Ads := Name_Find;
854 -- We work in the object directory
856 Change_Dir (Object_Directory_Path);
860 -- Call gnatbind only if Bind is True
863 if Gnatbind_Path = null then
864 Com.Fail ("unable to locate ", Gnatbind);
867 if Gcc_Path = null then
868 Com.Fail ("unable to locate ", Gcc);
871 -- Allocate Arguments, if it is the first time we see a standalone
874 if Arguments = No_Argument then
875 Arguments := new String_List (1 .. Initial_Argument_Max);
878 -- Add "-n -o b~<lib>.adb (b__<lib>.adb on VMS) -L<lib>"
880 Argument_Number := 2;
881 Arguments (1) := No_Main;
882 Arguments (2) := Output_Switch;
884 if OpenVMS_On_Target then
885 B_Start := new String'("b__");
889 (B_Start.all & Get_Name_String (Data.Library_Name) & ".adb");
890 Add_Argument ("-L" & Get_Name_String (Data.Library_Name));
892 if Data.Lib_Auto_Init and then SALs_Use_Constructors then
893 Add_Argument (Auto_Initialize);
896 -- Check if Binder'Default_Switches ("Ada") is defined. If it is,
897 -- add these switches to call gnatbind.
900 Binder_Package : constant Package_Id :=
902 (Name => Name_Binder,
903 In_Packages => Data.Decl.Packages,
907 if Binder_Package /= No_Package then
909 Defaults : constant Array_Element_Id :=
911 (Name => Name_Default_Switches,
913 In_Tree.Packages.Table
914 (Binder_Package).Decl.Arrays,
916 Switches : Variable_Value := Nil_Variable_Value;
918 Switch : String_List_Id := Nil_String;
921 if Defaults /= No_Array_Element then
926 In_Array => Defaults,
929 if not Switches.Default then
930 Switch := Switches.Values;
932 while Switch /= Nil_String loop
935 (In_Tree.String_Elements.Table
937 Switch := In_Tree.String_Elements.
947 -- Get all the ALI files of the project file. We do that even if
948 -- Bind is False, so that First_ALI is set.
955 Interface_ALIs.Reset;
956 Processed_ALIs.Reset;
958 for Source in Unit_Table.First ..
959 Unit_Table.Last (In_Tree.Units)
961 Unit := In_Tree.Units.Table (Source);
963 if Unit.File_Names (Body_Part).Name /= No_File
964 and then Unit.File_Names (Body_Part).Path /= Slash
967 Check_Project (Unit.File_Names (Body_Part).Project)
969 if Unit.File_Names (Specification).Name = No_File then
971 Src_Ind : Source_File_Index;
974 Src_Ind := Sinput.P.Load_Project_File
979 -- Add the ALI file only if it is not a subunit
982 Sinput.P.Source_File_Is_Subunit (Src_Ind)
985 (Unit.File_Names (Body_Part).Name);
991 Add_ALI_For (Unit.File_Names (Body_Part).Name);
996 elsif Unit.File_Names (Specification).Name /= No_File
997 and then Unit.File_Names (Specification).Path /= Slash
998 and then Check_Project
999 (Unit.File_Names (Specification).Project)
1001 Add_ALI_For (Unit.File_Names (Specification).Name);
1007 -- Continue setup and call gnatbind if Bind is True
1011 -- Get an eventual --RTS from the ALI file
1013 if First_ALI /= No_File then
1015 T : Text_Buffer_Ptr;
1019 -- Load the ALI file
1021 T := Read_Library_Info (First_ALI, True);
1026 (First_ALI, T, Ignore_ED => False, Err => False);
1028 if A /= No_ALI_Id then
1031 (ALI.ALIs.Table (A).First_Unit).First_Arg ..
1033 (ALI.ALIs.Table (A).First_Unit).Last_Arg
1035 -- Look for --RTS. If found, add the switch to call
1039 Arg : String_Ptr renames Args.Table (Index);
1041 if Arg'Length >= 6 and then
1042 Arg (Arg'First + 2 .. Arg'First + 5) = "RTS="
1044 Add_Argument (Arg.all);
1056 (Project => For_Project,
1058 Including_Libraries => True);
1060 -- Display the gnatbind command, if not in quiet output
1065 for J in 1 .. Argument_Number loop
1066 Size := Size + Arguments (J)'Length + 1;
1069 -- Invoke gnatbind with the arguments if the size is not too large
1071 if Size <= Maximum_Size then
1074 Arguments (1 .. Argument_Number),
1078 -- Otherwise create a temporary response file
1081 FD : File_Descriptor;
1082 Path : Path_Name_Type;
1083 Args : Argument_List (1 .. 1);
1084 EOL : constant String (1 .. 1) := (1 => ASCII.LF);
1087 Quotes_Needed : Boolean;
1088 Last_Char : Natural;
1092 Tempdir.Create_Temp_File (FD, Path);
1093 Args (1) := new String'("@" & Get_Name_String (Path));
1095 for J in 1 .. Argument_Number loop
1097 -- Check if the argument should be quoted
1099 Quotes_Needed := False;
1100 Last_Char := Arguments (J)'Length;
1102 for K in Arguments (J)'Range loop
1103 Ch := Arguments (J) (K);
1105 if Ch = ' ' or else Ch = ASCII.HT or else Ch = '"' then
1106 Quotes_Needed := True;
1111 if Quotes_Needed then
1113 -- Quote the argument, doubling '"'
1116 Arg : String (1 .. Arguments (J)'Length * 2 + 2);
1122 for K in Arguments (J)'Range loop
1123 Ch := Arguments (J) (K);
1124 Last_Char := Last_Char + 1;
1125 Arg (Last_Char) := Ch;
1128 Last_Char := Last_Char + 1;
1129 Arg (Last_Char) := '"';
1133 Last_Char := Last_Char + 1;
1134 Arg (Last_Char) := '"';
1136 Status := Write (FD, Arg'Address, Last_Char);
1142 Arguments (J) (Arguments (J)'First)'Address,
1146 if Status /= Last_Char then
1150 Status := Write (FD, EOL (1)'Address, 1);
1159 -- And invoke gnatbind with this this response file
1161 Spawn (Gnatbind_Path.all, Args, Success);
1163 Delete_File (Get_Name_String (Path), Succ);
1172 Com.Fail ("could not bind standalone library ",
1173 Get_Name_String (Data.Library_Name));
1177 -- Compile the binder generated file only if Link is true
1184 (Project => For_Project,
1186 Including_Libraries => True);
1188 -- Invoke <gcc> -c b__<lib>.adb
1190 -- Allocate Arguments, if it is the first time we see a standalone
1193 if Arguments = No_Argument then
1194 Arguments := new String_List (1 .. Initial_Argument_Max);
1197 Argument_Number := 1;
1198 Arguments (1) := Compile_Switch;
1200 if OpenVMS_On_Target then
1201 B_Start := new String'("b__");
1205 (B_Start.all & Get_Name_String (Data.Library_Name) & ".adb");
1207 -- If necessary, add the PIC option
1209 if PIC_Option /= "" then
1210 Add_Argument (PIC_Option);
1213 -- Get the back-end switches and --RTS from the ALI file
1215 if First_ALI /= No_File then
1217 T : Text_Buffer_Ptr;
1221 -- Load the ALI file
1223 T := Read_Library_Info (First_ALI, True);
1228 Scan_ALI (First_ALI, T, Ignore_ED => False, Err => False);
1230 if A /= No_ALI_Id then
1233 (ALI.ALIs.Table (A).First_Unit).First_Arg ..
1235 (ALI.ALIs.Table (A).First_Unit).Last_Arg
1237 -- Do not compile with the front end switches except
1241 Arg : String_Ptr renames Args.Table (Index);
1243 if not Is_Front_End_Switch (Arg.all)
1245 Arg (Arg'First + 2 .. Arg'First + 5) = "RTS="
1247 Add_Argument (Arg.all);
1255 -- Now that all the arguments are set, compile the binder
1260 (Gcc_Path.all, Arguments (1 .. Argument_Number), Success);
1264 ("could not compile binder generated file for library ",
1265 Get_Name_String (Data.Library_Name));
1268 -- Process binder generated file for pragmas Linker_Options
1270 Process_Binder_File (Arguments (2).all & ASCII.NUL);
1274 -- Build the library only if Link is True
1278 -- If attribute Library_GCC was specified, get the driver name
1281 Value_Of (Name_Library_GCC, Data.Decl.Attributes, In_Tree);
1283 if not Library_GCC.Default then
1284 Driver_Name := Library_GCC.Value;
1287 -- If attribute Library_Options was specified, add these additional
1291 Value_Of (Name_Library_Options, Data.Decl.Attributes, In_Tree);
1293 if not Library_Options.Default then
1295 Current : String_List_Id;
1296 Element : String_Element;
1299 Current := Library_Options.Values;
1300 while Current /= Nil_String loop
1301 Element := In_Tree.String_Elements.Table (Current);
1302 Get_Name_String (Element.Value);
1304 if Name_Len /= 0 then
1305 Opts.Increment_Last;
1306 Opts.Table (Opts.Last) :=
1307 new String'(Name_Buffer (1 .. Name_Len));
1310 Current := Element.Next;
1316 new String'(Get_Name_String (Data.Display_Library_Dir));
1317 Lib_Filename := new String'(Get_Name_String (Data.Library_Name));
1319 case Data.Library_Kind is
1321 The_Build_Mode := Static;
1324 The_Build_Mode := Dynamic;
1327 The_Build_Mode := Relocatable;
1329 if PIC_Option /= "" then
1330 Opts.Increment_Last;
1331 Opts.Table (Opts.Last) := new String'(PIC_Option);
1335 -- Get the library version, if any
1337 if Data.Lib_Internal_Name /= No_Name then
1339 new String'(Get_Name_String (Data.Lib_Internal_Name));
1342 -- Add the objects found in the object directory and the object
1343 -- directories of the extended files, if any, except for generated
1344 -- object files (b~.. or B__..) from extended projects.
1345 -- When there are one or more extended files, only add an object file
1346 -- if no object file with the same name have already been added.
1348 In_Main_Object_Directory := True;
1350 There_Are_Foreign_Sources := Data.Other_Sources_Present;
1354 Object_Dir_Path : constant String :=
1355 Get_Name_String (Data.Display_Object_Dir);
1356 Object_Dir : Dir_Type;
1357 Filename : String (1 .. 255);
1362 Open (Dir => Object_Dir, Dir_Name => Object_Dir_Path);
1364 -- For all entries in the object directory
1367 Read (Object_Dir, Filename, Last);
1371 -- Check if it is an object file
1373 if Is_Obj (Filename (1 .. Last)) then
1375 Object_Path : constant String :=
1377 (Object_Dir_Path & Directory_Separator &
1378 Filename (1 .. Last));
1379 C_Object_Path : String := Object_Path;
1380 C_Filename : String := Filename (1 .. Last);
1383 Canonical_Case_File_Name (C_Object_Path);
1384 Canonical_Case_File_Name (C_Filename);
1386 -- If in the object directory of an extended project,
1387 -- do not consider generated object files.
1389 if In_Main_Object_Directory
1391 or else C_Filename (1 .. B_Start'Length) /=
1395 Name_Buffer (1 .. Name_Len) :=
1396 C_Filename (1 .. Last);
1399 if not Objects_Htable.Get (Id) then
1401 ALI_File : constant String :=
1403 (Filename (1 .. Last), "ali");
1404 ALI_Path : constant String :=
1405 Ext_To (Object_Path, "ali");
1407 There_Are_Foreign_Sources
1412 (1 .. B_Start'Length) =
1414 Fname : File_Name_Type;
1418 if Is_Regular_File (ALI_Path) then
1420 -- If there is an ALI file, check if the
1421 -- object file should be added to the
1422 -- library. If there are foreign sources
1423 -- we put all object files in the library.
1427 1 .. Unit_Table.Last (In_Tree.Units)
1429 if In_Tree.Units.Table
1431 (Body_Part).Name /= No_File
1434 In_Tree.Units.Table (Index).
1436 (Body_Part).Project;
1438 In_Tree.Units.Table (Index).
1439 File_Names (Body_Part).Name;
1444 (Specification).Name /= No_File
1449 (Specification).Project;
1453 (Specification).Name;
1459 Add_It := Proj /= No_Project;
1461 -- If the source is in the project
1462 -- or a project it extends, we may
1463 -- put it in the library.
1466 Add_It := Check_Project (Proj);
1469 -- But we don't, if the ALI file
1470 -- does not correspond to the unit.
1474 F : constant String :=
1479 Add_It := F = ALI_File;
1488 Objects_Htable.Set (Id, True);
1490 (new String'(Object_Path));
1492 -- Record the ALI file
1494 ALIs.Append (new String'(ALI_Path));
1496 -- Find out if for this ALI file,
1497 -- libgnarl or libdecgnat or
1498 -- g-trasym.obj (on OpenVMS) is
1501 Check_Libs (ALI_Path, True);
1504 elsif There_Are_Foreign_Sources then
1505 Objects.Append (new String'(Object_Path));
1514 Close (Dir => Object_Dir);
1517 when Directory_Error =>
1518 Com.Fail ("cannot find object directory """,
1519 Get_Name_String (Data.Object_Directory),
1523 exit when Data.Extends = No_Project;
1525 In_Main_Object_Directory := False;
1526 Data := In_Tree.Projects.Table (Data.Extends);
1529 -- Add the -L and -l switches for the imported Library Project Files,
1530 -- and, if Path Option is supported, the library directory path names
1533 Process_Imported_Libraries;
1535 -- Link with libgnat and possibly libgnarl
1537 Opts.Increment_Last;
1538 Opts.Table (Opts.Last) := new String'("-L" & Lib_Directory);
1540 -- If Path Option is supported, add libgnat directory path name to
1543 if Path_Option /= null then
1545 Libdir : constant String := Lib_Directory;
1546 GCC_Index : Natural := 0;
1551 -- For shared libraries, add to the Path Option the directory
1552 -- of the shared version of libgcc.
1554 if The_Build_Mode /= Static then
1555 GCC_Index := Index (Libdir, "/lib/");
1557 if GCC_Index = 0 then
1561 Directory_Separator & "lib" & Directory_Separator);
1564 if GCC_Index /= 0 then
1565 Add_Rpath (Libdir (Libdir'First .. GCC_Index + 3));
1571 if Libgnarl_Needed = Yes then
1572 Opts.Increment_Last;
1574 if The_Build_Mode = Static then
1575 Opts.Table (Opts.Last) := new String'("-lgnarl");
1577 Opts.Table (Opts.Last) := new String'(Shared_Lib ("gnarl"));
1581 if Gtrasymobj_Needed then
1582 Opts.Increment_Last;
1583 Opts.Table (Opts.Last) :=
1584 new String'(Lib_Directory & "/g-trasym.obj");
1587 if Libdecgnat_Needed then
1588 Opts.Increment_Last;
1590 Opts.Table (Opts.Last) :=
1591 new String'("-L" & Lib_Directory & "/../declib");
1593 Opts.Increment_Last;
1595 if The_Build_Mode = Static then
1596 Opts.Table (Opts.Last) := new String'("-ldecgnat");
1598 Opts.Table (Opts.Last) := new String'(Shared_Lib ("decgnat"));
1602 Opts.Increment_Last;
1604 if The_Build_Mode = Static then
1605 Opts.Table (Opts.Last) := new String'("-lgnat");
1607 Opts.Table (Opts.Last) := new String'(Shared_Lib ("gnat"));
1610 -- If Path Option is supported, add the necessary switch with the
1611 -- content of Rpath. As Rpath contains at least libgnat directory
1612 -- path name, it is guaranteed that it is not null.
1614 if Path_Option /= null then
1615 Opts.Increment_Last;
1616 Opts.Table (Opts.Last) :=
1617 new String'(Path_Option.all & Rpath (1 .. Rpath_Last));
1624 (Argument_List (Objects.Table (1 .. Objects.Last)));
1627 new Argument_List'(Argument_List (ALIs.Table (1 .. ALIs.Last)));
1630 new Argument_List'(Argument_List (Opts.Table (1 .. Opts.Last)));
1632 -- We fail if there are no object to put in the library
1633 -- (Ada or foreign objects).
1635 if Object_Files'Length = 0 then
1636 Com.Fail ("no object files for library """ &
1637 Lib_Filename.all & '"');
1640 if not Opt.Quiet_Output then
1642 Write_Str ("building ");
1643 Write_Str (Ada.Characters.Handling.To_Lower
1644 (Build_Mode_State'Image (The_Build_Mode)));
1645 Write_Str (" library for project ");
1646 Write_Line (Project_Name);
1648 -- Only output list of object files and ALI files in verbose mode
1650 if Opt.Verbose_Mode then
1653 Write_Line ("object files:");
1655 for Index in Object_Files'Range loop
1657 Write_Line (Object_Files (Index).all);
1662 if Ali_Files'Length = 0 then
1663 Write_Line ("NO ALI files");
1666 Write_Line ("ALI files:");
1668 for Index in Ali_Files'Range loop
1670 Write_Line (Ali_Files (Index).all);
1678 -- We check that all object files are regular files
1682 -- Delete the existing library file, if it exists. Fail if the
1683 -- library file is not writable, or if it is not possible to delete
1687 DLL_Name : aliased String :=
1688 Lib_Dirpath.all & Directory_Separator & DLL_Prefix &
1689 Lib_Filename.all & "." & DLL_Ext;
1691 Archive_Name : aliased String :=
1692 Lib_Dirpath.all & Directory_Separator & "lib" &
1693 Lib_Filename.all & "." & Archive_Ext;
1695 type Str_Ptr is access all String;
1696 -- This type is necessary to meet the accessibility rules of Ada.
1697 -- It is not possible to use String_Access here.
1699 Full_Lib_Name : Str_Ptr;
1700 -- Designates the full library path name. Either DLL_Name or
1701 -- Archive_Name, depending on the library kind.
1703 Success : Boolean := False;
1704 -- Used to call Delete_File
1707 if The_Build_Mode = Static then
1708 Full_Lib_Name := Archive_Name'Access;
1710 Full_Lib_Name := DLL_Name'Access;
1713 if Is_Regular_File (Full_Lib_Name.all) then
1714 if Is_Writable_File (Full_Lib_Name.all) then
1715 Delete_File (Full_Lib_Name.all, Success);
1718 if Is_Regular_File (Full_Lib_Name.all) then
1719 Com.Fail ("could not delete """ & Full_Lib_Name.all & """");
1724 Argument_Number := 0;
1726 -- If we have a standalone library, gather all the interface ALI.
1727 -- They are passed to Build_Dynamic_Library, where they are used by
1728 -- some platforms (VMS, for example) to decide what symbols should be
1729 -- exported. They are also flagged as Interface when we copy them to
1730 -- the library directory (by Copy_ALI_Files, below).
1733 Data := In_Tree.Projects.Table (For_Project);
1736 Iface : String_List_Id := Data.Lib_Interface_ALIs;
1737 ALI : File_Name_Type;
1740 while Iface /= Nil_String loop
1743 (In_Tree.String_Elements.Table (Iface).Value);
1744 Interface_ALIs.Set (ALI, True);
1746 (In_Tree.String_Elements.Table (Iface).Value);
1747 Add_Argument (Name_Buffer (1 .. Name_Len));
1748 Iface := In_Tree.String_Elements.Table (Iface).Next;
1751 Iface := Data.Lib_Interface_ALIs;
1753 if not Opt.Quiet_Output then
1755 -- Check that the interface set is complete: any unit in the
1756 -- library that is needed by an interface should also be an
1757 -- interface. If it is not the case, output a warning.
1759 while Iface /= Nil_String loop
1762 (In_Tree.String_Elements.Table (Iface).Value);
1764 Iface := In_Tree.String_Elements.Table (Iface).Next;
1771 Current_Dir : constant String := Get_Current_Dir;
1774 Name : String (1 .. 200);
1777 Disregard : Boolean;
1779 DLL_Name : aliased constant String :=
1780 Lib_Filename.all & "." & DLL_Ext;
1782 Archive_Name : aliased constant String :=
1783 Lib_Filename.all & "." & Archive_Ext;
1785 Delete : Boolean := False;
1788 -- Clean the library directory: remove any file with the name of
1789 -- the library file and any ALI file of a source of the project.
1793 (In_Tree.Projects.Table (For_Project).Library_Dir);
1794 Change_Dir (Name_Buffer (1 .. Name_Len));
1799 ("unable to access library directory """,
1800 Name_Buffer (1 .. Name_Len),
1807 Read (Dir, Name, Last);
1811 Filename : constant String := Name (1 .. Last);
1814 if Is_Regular_File (Filename) then
1815 Canonical_Case_File_Name (Name (1 .. Last));
1818 if (The_Build_Mode = Static and then
1819 Name (1 .. Last) = Archive_Name)
1821 ((The_Build_Mode = Dynamic or else
1822 The_Build_Mode = Relocatable)
1824 Name (1 .. Last) = DLL_Name)
1829 and then Name (Last - 3 .. Last) = ".ali"
1835 -- Compare with ALI file names of the project
1838 1 .. Unit_Table.Last (In_Tree.Units)
1840 Unit := In_Tree.Units.Table (Index);
1842 if Unit.File_Names (Body_Part).Project /=
1845 if Ultimate_Extension_Of
1846 (Unit.File_Names (Body_Part).Project,
1847 In_Tree) = For_Project
1850 (Unit.File_Names (Body_Part).Name);
1851 Name_Len := Name_Len -
1853 (Name (1 .. Name_Len))'Length;
1854 if Name_Buffer (1 .. Name_Len) =
1855 Name (1 .. Last - 4)
1862 elsif Ultimate_Extension_Of
1863 (Unit.File_Names (Specification).Project,
1864 In_Tree) = For_Project
1867 (Unit.File_Names (Specification).Name);
1871 (Name (1 .. Name_Len))'Length;
1873 if Name_Buffer (1 .. Name_Len) =
1874 Name (1 .. Last - 4)
1885 Set_Writable (Filename);
1886 Delete_File (Filename, Disregard);
1894 Change_Dir (Current_Dir);
1897 -- Call procedure to build the library, depending on the build mode
1899 case The_Build_Mode is
1900 when Dynamic | Relocatable =>
1901 Build_Dynamic_Library
1902 (Ofiles => Object_Files.all,
1903 Options => Options.all,
1904 Interfaces => Arguments (1 .. Argument_Number),
1905 Lib_Filename => Lib_Filename.all,
1906 Lib_Dir => Lib_Dirpath.all,
1907 Symbol_Data => Data.Symbol_Data,
1908 Driver_Name => Driver_Name,
1909 Lib_Version => Lib_Version.all,
1910 Auto_Init => Data.Lib_Auto_Init);
1922 -- We need to copy the ALI files from the object directory to the
1923 -- library ALI directory, so that the linker find them there, and
1924 -- does not need to look in the object directory where it would also
1925 -- find the object files; and we don't want that: we want the linker
1926 -- to use the library.
1928 -- Copy the ALI files and make the copies read-only. For interfaces,
1929 -- mark the copies as interfaces.
1932 (Files => Ali_Files.all,
1933 To => In_Tree.Projects.Table (For_Project).Library_ALI_Dir,
1934 Interfaces => Arguments (1 .. Argument_Number));
1936 -- Copy interface sources if Library_Src_Dir specified
1939 and then In_Tree.Projects.Table
1940 (For_Project).Library_Src_Dir /= No_Path
1942 -- Clean the interface copy directory: remove any source that
1943 -- could be a source of the project.
1947 (In_Tree.Projects.Table (For_Project).Library_Src_Dir);
1948 Change_Dir (Name_Buffer (1 .. Name_Len));
1953 ("unable to access library source copy directory """,
1954 Name_Buffer (1 .. Name_Len),
1960 Delete : Boolean := False;
1963 Name : String (1 .. 200);
1966 Disregard : Boolean;
1972 Read (Dir, Name, Last);
1975 if Is_Regular_File (Name (1 .. Last)) then
1976 Canonical_Case_File_Name (Name (1 .. Last));
1979 -- Compare with source file names of the project
1981 for Index in 1 .. Unit_Table.Last (In_Tree.Units) loop
1982 Unit := In_Tree.Units.Table (Index);
1984 if Ultimate_Extension_Of
1985 (Unit.File_Names (Body_Part).Project, In_Tree) =
1989 (Unit.File_Names (Body_Part).Name) =
1996 if Ultimate_Extension_Of
1997 (Unit.File_Names (Specification).Project, In_Tree) =
2001 (Unit.File_Names (Specification).Name) =
2011 Set_Writable (Name (1 .. Last));
2012 Delete_File (Name (1 .. Last), Disregard);
2019 Copy_Interface_Sources
2020 (For_Project => For_Project,
2022 Interfaces => Arguments (1 .. Argument_Number),
2023 To_Dir => In_Tree.Projects.Table
2024 (For_Project).Display_Library_Src_Dir);
2028 -- Reset the current working directory to its previous value
2030 Change_Dir (Current_Dir);
2037 procedure Check (Filename : String) is
2039 if not Is_Regular_File (Filename) then
2040 Com.Fail (Filename, " not found.");
2048 procedure Check_Context is
2050 -- Check that each object file exists
2052 for F in Object_Files'Range loop
2053 Check (Object_Files (F).all);
2061 procedure Check_Library
2062 (For_Project : Project_Id; In_Tree : Project_Tree_Ref)
2064 Data : constant Project_Data :=
2065 In_Tree.Projects.Table (For_Project);
2066 Lib_TS : Time_Stamp_Type;
2067 Current : constant Dir_Name_Str := Get_Current_Dir;
2070 -- No need to build the library if there is no object directory,
2071 -- hence no object files to build the library.
2073 if Data.Library then
2075 Lib_Name : constant File_Name_Type :=
2076 Library_File_Name_For (For_Project, In_Tree);
2078 Change_Dir (Get_Name_String (Data.Library_Dir));
2079 Lib_TS := File_Stamp (Lib_Name);
2080 In_Tree.Projects.Table (For_Project).Library_TS := Lib_TS;
2083 if not Data.Externally_Built
2084 and then not Data.Need_To_Build_Lib
2085 and then Data.Object_Directory /= No_Path
2088 Obj_TS : Time_Stamp_Type;
2089 Object_Dir : Dir_Type;
2092 if OpenVMS_On_Target then
2093 B_Start := new String'("b__");
2096 -- If the library file does not exist, then the time stamp will
2097 -- be Empty_Time_Stamp, earlier than any other time stamp.
2099 Change_Dir (Get_Name_String (Data.Object_Directory));
2100 Open (Dir => Object_Dir, Dir_Name => ".");
2102 -- For all entries in the object directory
2105 Read (Object_Dir, Name_Buffer, Name_Len);
2106 exit when Name_Len = 0;
2108 -- Check if it is an object file, but ignore any binder
2111 if Is_Obj (Name_Buffer (1 .. Name_Len))
2112 and then Name_Buffer (1 .. B_Start'Length) /= B_Start.all
2114 -- Get the object file time stamp
2116 Obj_TS := File_Stamp (File_Name_Type'(Name_Find));
2118 -- If library file time stamp is earlier, set
2119 -- Need_To_Build_Lib and return. String comparaison is
2120 -- used, otherwise time stamps may be too close and the
2121 -- comparaison would return True, which would trigger
2122 -- an unnecessary rebuild of the library.
2124 if String (Lib_TS) < String (Obj_TS) then
2126 -- Library must be rebuilt
2128 In_Tree.Projects.Table
2129 (For_Project).Need_To_Build_Lib := True;
2139 Change_Dir (Current);
2143 ----------------------------
2144 -- Copy_Interface_Sources --
2145 ----------------------------
2147 procedure Copy_Interface_Sources
2148 (For_Project : Project_Id;
2149 In_Tree : Project_Tree_Ref;
2150 Interfaces : Argument_List;
2151 To_Dir : Path_Name_Type)
2153 Current : constant Dir_Name_Str := Get_Current_Dir;
2154 -- The current directory, where to return to at the end
2156 Target : constant Dir_Name_Str := Get_Name_String (To_Dir);
2157 -- The directory where to copy sources
2159 Text : Text_Buffer_Ptr;
2160 The_ALI : ALI.ALI_Id;
2161 Lib_File : File_Name_Type;
2163 First_Unit : ALI.Unit_Id;
2164 Second_Unit : ALI.Unit_Id;
2168 Copy_Subunits : Boolean := False;
2169 -- When True, indicates that subunits, if any, need to be copied too
2171 procedure Copy (File_Name : File_Name_Type);
2172 -- Copy one source of the project to the target directory
2174 function Is_Same_Or_Extension
2175 (Extending : Project_Id;
2176 Extended : Project_Id) return Boolean;
2177 -- Return True if project Extending is equal to or extends project
2184 procedure Copy (File_Name : File_Name_Type) is
2185 Success : Boolean := False;
2189 for Index in Unit_Table.First ..
2190 Unit_Table.Last (In_Tree.Units)
2192 Data := In_Tree.Units.Table (Index);
2194 -- Find and copy the immediate or inherited source
2196 for J in Data.File_Names'Range loop
2197 if Is_Same_Or_Extension
2198 (For_Project, Data.File_Names (J).Project)
2199 and then Data.File_Names (J).Name = File_Name
2202 (Get_Name_String (Data.File_Names (J).Path),
2206 Preserve => Preserve);
2213 --------------------------
2214 -- Is_Same_Or_Extension --
2215 --------------------------
2217 function Is_Same_Or_Extension
2218 (Extending : Project_Id;
2219 Extended : Project_Id) return Boolean
2225 while Ext /= No_Project loop
2226 if Ext = Extended then
2230 Ext := In_Tree.Projects.Table (Ext).Extends;
2234 end Is_Same_Or_Extension;
2236 -- Start of processing for Copy_Interface_Sources
2239 -- Change the working directory to the object directory
2243 (In_Tree.Projects.Table
2244 (For_Project).Object_Directory));
2246 for Index in Interfaces'Range loop
2248 -- First, load the ALI file
2251 Add_Str_To_Name_Buffer (Interfaces (Index).all);
2252 Lib_File := Name_Find;
2253 Text := Read_Library_Info (Lib_File);
2254 The_ALI := Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
2257 Second_Unit := No_Unit_Id;
2258 First_Unit := ALI.ALIs.Table (The_ALI).First_Unit;
2259 Copy_Subunits := True;
2261 -- If there is both a spec and a body, check if they are both needed
2263 if ALI.Units.Table (First_Unit).Utype = Is_Body then
2264 Second_Unit := ALI.ALIs.Table (The_ALI).Last_Unit;
2266 -- If the body is not needed, then reset First_Unit
2268 if not ALI.Units.Table (Second_Unit).Body_Needed_For_SAL then
2269 First_Unit := No_Unit_Id;
2270 Copy_Subunits := False;
2273 elsif ALI.Units.Table (First_Unit).Utype = Is_Spec_Only then
2274 Copy_Subunits := False;
2277 -- Copy the file(s) that need to be copied
2279 if First_Unit /= No_Unit_Id then
2280 Copy (File_Name => ALI.Units.Table (First_Unit).Sfile);
2283 if Second_Unit /= No_Unit_Id then
2284 Copy (File_Name => ALI.Units.Table (Second_Unit).Sfile);
2287 -- Copy all the separates, if any
2289 if Copy_Subunits then
2290 for Dep in ALI.ALIs.Table (The_ALI).First_Sdep ..
2291 ALI.ALIs.Table (The_ALI).Last_Sdep
2293 if Sdep.Table (Dep).Subunit_Name /= No_Name then
2294 Copy (File_Name => Sdep.Table (Dep).Sfile);
2300 -- Restore the initial working directory
2302 Change_Dir (Current);
2303 end Copy_Interface_Sources;
2309 procedure Display (Executable : String) is
2311 if not Opt.Quiet_Output then
2312 Write_Str (Executable);
2314 for Index in 1 .. Argument_Number loop
2316 Write_Str (Arguments (Index).all);
2327 function Index (S, Pattern : String) return Natural is
2328 Len : constant Natural := Pattern'Length;
2331 for J in reverse S'First .. S'Last - Len + 1 loop
2332 if Pattern = S (J .. J + Len - 1) then
2340 -------------------------
2341 -- Process_Binder_File --
2342 -------------------------
2344 procedure Process_Binder_File (Name : String) is
2346 -- Binder file's descriptor
2348 Read_Mode : constant String := "r" & ASCII.Nul;
2351 Status : Interfaces.C_Streams.int;
2352 pragma Unreferenced (Status);
2355 Begin_Info : constant String := "-- BEGIN Object file/option list";
2356 End_Info : constant String := "-- END Object file/option list ";
2358 Next_Line : String (1 .. 1000);
2359 -- Current line value
2360 -- Where does this odd constant 1000 come from, looks suspicious ???
2363 -- End of line slice (the slice does not contain the line terminator)
2365 procedure Get_Next_Line;
2366 -- Read the next line from the binder file without the line terminator
2372 procedure Get_Next_Line is
2376 Fchars := fgets (Next_Line'Address, Next_Line'Length, Fd);
2378 if Fchars = System.Null_Address then
2379 Fail ("Error reading binder output");
2383 while Nlast <= Next_Line'Last
2384 and then Next_Line (Nlast) /= ASCII.LF
2385 and then Next_Line (Nlast) /= ASCII.CR
2393 -- Start of processing for Process_Binder_File
2396 Fd := fopen (Name'Address, Read_Mode'Address);
2398 if Fd = NULL_Stream then
2399 Fail ("Failed to open binder output");
2402 -- Skip up to the Begin Info line
2406 exit when Next_Line (1 .. Nlast) = Begin_Info;
2409 -- Find the first switch
2414 exit when Next_Line (1 .. Nlast) = End_Info;
2416 -- As the binder generated file is in Ada, remove the first eight
2417 -- characters " -- ".
2419 Next_Line (1 .. Nlast - 8) := Next_Line (9 .. Nlast);
2422 -- Stop when the first switch is found
2424 exit when Next_Line (1) = '-';
2427 if Next_Line (1 .. Nlast) /= End_Info then
2429 -- Ignore -static and -shared, since -shared will be used
2432 -- Ignore -lgnat, -lgnarl and -ldecgnat as they will be added
2433 -- later, because they are also needed for non Stand-Alone shared
2436 -- Also ignore the shared libraries which are :
2438 -- UNIX / Windows VMS
2439 -- -lgnat-<version> -lgnat_<version> (7 + version'length chars)
2440 -- -lgnarl-<version> -lgnarl_<version> (8 + version'length chars)
2442 if Next_Line (1 .. Nlast) /= "-static" and then
2443 Next_Line (1 .. Nlast) /= "-shared" and then
2444 Next_Line (1 .. Nlast) /= "-ldecgnat" and then
2445 Next_Line (1 .. Nlast) /= "-lgnarl" and then
2446 Next_Line (1 .. Nlast) /= "-lgnat" and then
2448 (1 .. Natural'Min (Nlast, 10 + Library_Version'Length)) /=
2449 Shared_Lib ("decgnat") and then
2451 (1 .. Natural'Min (Nlast, 8 + Library_Version'Length)) /=
2452 Shared_Lib ("gnarl") and then
2454 (1 .. Natural'Min (Nlast, 7 + Library_Version'Length)) /=
2457 if Next_Line (1) /= '-' then
2459 -- This is not an option, should we add it?
2461 if Add_Object_Files then
2462 Opts.Increment_Last;
2463 Opts.Table (Opts.Last) :=
2464 new String'(Next_Line (1 .. Nlast));
2468 -- Add all other options
2470 Opts.Increment_Last;
2471 Opts.Table (Opts.Last) :=
2472 new String'(Next_Line (1 .. Nlast));
2476 -- Next option, if any
2479 exit when Next_Line (1 .. Nlast) = End_Info;
2481 -- Remove first eight characters " -- "
2483 Next_Line (1 .. Nlast - 8) := Next_Line (9 .. Nlast);
2488 Status := fclose (Fd);
2490 -- Is it really right to ignore any close error ???
2492 end Process_Binder_File;
2498 procedure Reset_Tables is
2501 Objects_Htable.Reset;
2504 Processed_Projects.Reset;
2508 ---------------------------
2509 -- SALs_Use_Constructors --
2510 ---------------------------
2512 function SALs_Use_Constructors return Boolean is
2513 function C_SALs_Init_Using_Constructors return Integer;
2514 pragma Import (C, C_SALs_Init_Using_Constructors,
2515 "__gnat_sals_init_using_constructors");
2517 return C_SALs_Init_Using_Constructors /= 0;
2518 end SALs_Use_Constructors;
2520 ---------------------------
2521 -- Ultimate_Extension_Of --
2522 ---------------------------
2524 function Ultimate_Extension_Of
2525 (Project : Project_Id;
2526 In_Tree : Project_Tree_Ref) return Project_Id
2528 Result : Project_Id := Project;
2529 Data : Project_Data;
2532 if Project /= No_Project then
2534 Data := In_Tree.Projects.Table (Result);
2535 exit when Data.Extended_By = No_Project;
2536 Result := Data.Extended_By;
2541 end Ultimate_Extension_Of;