1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2006, 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;
32 with Namet; use Namet;
34 with Output; use Output;
35 with Prj.Com; use Prj.Com;
36 with Prj.Env; use Prj.Env;
37 with Prj.Util; use Prj.Util;
39 with Snames; use Snames;
40 with Switch; use Switch;
42 with Targparm; use Targparm;
44 with Ada.Characters.Handling;
46 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
48 with Interfaces.C_Streams; use Interfaces.C_Streams;
49 with System; use System;
50 with System.Case_Util; use System.Case_Util;
52 package body MLib.Prj is
54 Prj_Add_Obj_Files : Types.Int;
55 pragma Import (C, Prj_Add_Obj_Files, "__gnat_prj_add_obj_files");
56 Add_Object_Files : constant Boolean := Prj_Add_Obj_Files /= 0;
57 -- Indicates if object files in pragmas Linker_Options (found in the
58 -- binder generated file) should be taken when linking a stand-alone
59 -- library. False for Windows, True for other platforms.
61 ALI_Suffix : constant String := ".ali";
63 B_Start : String_Ptr := new String'("b~");
64 -- Prefix of bind file, changed to b__ for VMS
66 S_Osinte_Ads : Name_Id := No_Name;
67 -- Name_Id for "s-osinte.ads"
69 S_Dec_Ads : Name_Id := No_Name;
70 -- Name_Id for "dec.ads"
72 G_Trasym_Ads : Name_Id := No_Name;
73 -- Name_Id for "g-trasym.ads"
75 No_Argument_List : aliased String_List := (1 .. 0 => null);
76 No_Argument : constant String_List_Access := No_Argument_List'Access;
78 Arguments : String_List_Access := No_Argument;
79 -- Used to accumulate arguments for the invocation of gnatbind and of
80 -- the compiler. Also used to collect the interface ALI when copying
81 -- the ALI files to the library directory.
83 Argument_Number : Natural := 0;
84 -- Index of the last argument in Arguments
86 Initial_Argument_Max : constant := 10;
88 No_Main_String : aliased String := "-n";
89 No_Main : constant String_Access := No_Main_String'Access;
91 Output_Switch_String : aliased String := "-o";
92 Output_Switch : constant String_Access := Output_Switch_String'Access;
94 Compile_Switch_String : aliased String := "-c";
95 Compile_Switch : constant String_Access := Compile_Switch_String'Access;
97 Auto_Initialize : constant String := "-a";
99 -- List of objects to put inside the library
101 Object_Files : Argument_List_Access;
103 package Objects is new Table.Table
104 (Table_Name => "Mlib.Prj.Objects",
105 Table_Component_Type => String_Access,
106 Table_Index_Type => Natural,
107 Table_Low_Bound => 1,
109 Table_Increment => 100);
111 package Objects_Htable is new GNAT.HTable.Simple_HTable
112 (Header_Num => Header_Num,
119 -- List of non-Ada object files
121 Foreign_Objects : Argument_List_Access;
123 package Foreigns is new Table.Table
124 (Table_Name => "Mlib.Prj.Foreigns",
125 Table_Component_Type => String_Access,
126 Table_Index_Type => Natural,
127 Table_Low_Bound => 1,
129 Table_Increment => 100);
133 Ali_Files : Argument_List_Access;
135 package ALIs is new Table.Table
136 (Table_Name => "Mlib.Prj.Alis",
137 Table_Component_Type => String_Access,
138 Table_Index_Type => Natural,
139 Table_Low_Bound => 1,
141 Table_Increment => 100);
143 -- List of options set in the command line
145 Options : Argument_List_Access;
147 package Opts is new Table.Table
148 (Table_Name => "Mlib.Prj.Opts",
149 Table_Component_Type => String_Access,
150 Table_Index_Type => Natural,
151 Table_Low_Bound => 1,
153 Table_Increment => 100);
155 -- All the ALI file in the library
157 package Library_ALIs is new GNAT.HTable.Simple_HTable
158 (Header_Num => Header_Num,
165 -- The ALI files in the interface sets
167 package Interface_ALIs is new GNAT.HTable.Simple_HTable
168 (Header_Num => Header_Num,
175 -- The ALI files that have been processed to check if the corresponding
176 -- library unit is in the interface set.
178 package Processed_ALIs is new GNAT.HTable.Simple_HTable
179 (Header_Num => Header_Num,
186 -- The projects imported directly or indirectly
188 package Processed_Projects is new GNAT.HTable.Simple_HTable
189 (Header_Num => Header_Num,
196 -- The library projects imported directly or indirectly
198 package Library_Projs is new Table.Table (
199 Table_Component_Type => Project_Id,
200 Table_Index_Type => Integer,
201 Table_Low_Bound => 1,
203 Table_Increment => 10,
204 Table_Name => "Make.Library_Projs");
206 type Build_Mode_State is (None, Static, Dynamic, Relocatable);
208 procedure Add_Argument (S : String);
209 -- Add one argument to Arguments array, if array is full, double its size
211 function ALI_File_Name (Source : String) return String;
212 -- Return the ALI file name corresponding to a source
214 procedure Check (Filename : String);
215 -- Check if filename is a regular file. Fail if it is not
217 procedure Check_Context;
218 -- Check each object files in table Object_Files
219 -- Fail if any of them is not a regular file
221 procedure Copy_Interface_Sources
222 (For_Project : Project_Id;
223 In_Tree : Project_Tree_Ref;
224 Interfaces : Argument_List;
226 -- Copy the interface sources of a SAL to directory To_Dir
228 procedure Display (Executable : String);
229 -- Display invocation of gnatbind and of the compiler with the arguments
230 -- in Arguments, except when Quiet_Output is True.
232 function Index (S, Pattern : String) return Natural;
233 -- Return the last occurrence of Pattern in S, or 0 if none
235 procedure Process_Binder_File (Name : String);
236 -- For Stand-Alone libraries, get the Linker Options in the binder
239 procedure Reset_Tables;
240 -- Make sure that all the above tables are empty
241 -- (Objects, Foreign_Objects, Ali_Files, Options).
243 function SALs_Use_Constructors return Boolean;
244 -- Indicate if Stand-Alone Libraries are automatically initialized using
245 -- the constructor mechanism.
247 function Ultimate_Extension_Of
248 (Project : Project_Id;
249 In_Tree : Project_Tree_Ref) return Project_Id;
250 -- Returns the Project_Id of project Project. Returns No_Project
251 -- if Project is No_Project.
257 procedure Add_Argument (S : String) is
259 if Argument_Number = Arguments'Last then
261 New_Args : constant String_List_Access :=
262 new String_List (1 .. 2 * Arguments'Last);
265 -- Copy the String_Accesses and set them to null in Arguments
266 -- so that they will not be deallocated by the call to
269 New_Args (Arguments'Range) := Arguments.all;
270 Arguments.all := (others => null);
272 Arguments := New_Args;
276 Argument_Number := Argument_Number + 1;
277 Arguments (Argument_Number) := new String'(S);
284 function ALI_File_Name (Source : String) return String is
286 -- If the source name has an extension, then replace it with
289 for Index in reverse Source'First + 1 .. Source'Last loop
290 if Source (Index) = '.' then
291 return Source (Source'First .. Index - 1) & ALI_Suffix;
295 -- If there is no dot, or if it is the first character, just add the
298 return Source & ALI_Suffix;
305 procedure Build_Library
306 (For_Project : Project_Id;
307 In_Tree : Project_Tree_Ref;
309 Gnatbind_Path : String_Access;
311 Gcc_Path : String_Access;
312 Bind : Boolean := True;
313 Link : Boolean := True)
315 Warning_For_Library : Boolean := False;
316 -- Set to True for the first warning about a unit missing from the
319 Libgnarl_Needed : Boolean := False;
320 -- Set to True if library needs to be linked with libgnarl
322 Libdecgnat_Needed : Boolean := False;
323 -- On OpenVMS, set to True if library needs to be linked with libdecgnat
325 Gtrasymobj_Needed : Boolean := False;
326 -- On OpenVMS, set to True if library needs to be linked with
329 Data : Project_Data := In_Tree.Projects.Table (For_Project);
331 Object_Directory_Path : constant String :=
332 Get_Name_String (Data.Object_Directory);
334 Standalone : constant Boolean := Data.Standalone_Library;
336 Project_Name : constant String := Get_Name_String (Data.Name);
338 Current_Dir : constant String := Get_Current_Dir;
340 Lib_Filename : String_Access;
341 Lib_Dirpath : String_Access;
342 Lib_Version : String_Access := new String'("");
344 The_Build_Mode : Build_Mode_State := None;
346 Success : Boolean := False;
348 Library_Options : Variable_Value := Nil_Variable_Value;
350 Library_GCC : Variable_Value := Nil_Variable_Value;
352 Driver_Name : Name_Id := No_Name;
354 In_Main_Object_Directory : Boolean := True;
356 Rpath : String_Access := null;
357 -- Allocated only if Path Option is supported
359 Rpath_Last : Natural := 0;
360 -- Index of last valid character of Rpath
362 Initial_Rpath_Length : constant := 200;
363 -- Initial size of Rpath, when first allocated
365 Path_Option : String_Access := Linker_Library_Path_Option;
366 -- If null, Path Option is not supported.
367 -- Not a constant so that it can be deallocated.
369 First_ALI : Name_Id := No_Name;
370 -- Store the ALI file name of a source of the library (the first found)
372 procedure Add_ALI_For (Source : Name_Id);
373 -- Add the name of the ALI file corresponding to Source to the
376 procedure Add_Rpath (Path : String);
377 -- Add a path name to Rpath
379 function Check_Project (P : Project_Id) return Boolean;
380 -- Returns True if P is For_Project or a project extended by For_Project
382 procedure Check_Libs (ALI_File : String);
383 -- Set Libgnarl_Needed if the ALI_File indicates that there is a need
384 -- to link with -lgnarl (this is the case when there is a dependency
385 -- on s-osinte.ads). On OpenVMS, set Libdecgnat_Needed if the ALI file
386 -- indicates that there is a need to link with -ldecgnat (this is the
387 -- case when there is a dependency on dec.ads), and set
388 -- Gtrasymobj_Needed if there is a dependency on g-trasym.ads.
390 procedure Process (The_ALI : File_Name_Type);
391 -- Check if the closure of a library unit which is or should be in the
392 -- interface set is also in the interface set. Issue a warning for each
393 -- missing library unit.
395 procedure Process_Imported_Libraries;
396 -- Add the -L and -l switches for the imported Library Project Files,
397 -- and, if Path Option is supported, the library directory path names
404 procedure Add_ALI_For (Source : Name_Id) is
405 ALI : constant String := ALI_File_Name (Get_Name_String (Source));
414 Add_Str_To_Name_Buffer (S => ALI);
417 -- Add the ALI file name to the library ALIs
420 Library_ALIs.Set (ALI_Id, True);
423 -- Set First_ALI, if not already done
425 if First_ALI = No_Name then
434 procedure Add_Rpath (Path : String) is
444 New_Rpath : constant String_Access :=
445 new String (1 .. 2 * Rpath'Length);
447 New_Rpath (1 .. Rpath_Last) := Rpath (1 .. Rpath_Last);
452 -- Start of processing for Add_Rpath
455 -- If firt path, allocate initial Rpath
458 Rpath := new String (1 .. Initial_Rpath_Length);
462 -- Otherwise, add a path separator between two path names
464 if Rpath_Last = Rpath'Last then
468 Rpath_Last := Rpath_Last + 1;
469 Rpath (Rpath_Last) := Path_Separator;
472 -- Increase Rpath size until it is large enough
474 while Rpath_Last + Path'Length > Rpath'Last loop
480 Rpath (Rpath_Last + 1 .. Rpath_Last + Path'Length) := Path;
481 Rpath_Last := Rpath_Last + Path'Length;
488 function Check_Project (P : Project_Id) return Boolean is
490 if P = For_Project then
493 elsif P /= No_Project then
495 Data : Project_Data :=
496 In_Tree.Projects.Table (For_Project);
498 while Data.Extends /= No_Project loop
499 if P = Data.Extends then
503 Data := In_Tree.Projects.Table (Data.Extends);
515 procedure Check_Libs (ALI_File : String) is
517 Text : Text_Buffer_Ptr;
521 if not Libgnarl_Needed or
522 (OpenVMS_On_Target and then
523 ((not Libdecgnat_Needed) or
524 (not Gtrasymobj_Needed)))
528 Name_Len := ALI_File'Length;
529 Name_Buffer (1 .. Name_Len) := ALI_File;
530 Lib_File := Name_Find;
531 Text := Read_Library_Info (Lib_File, True);
541 -- Look for s-osinte.ads in the dependencies
543 for Index in ALI.ALIs.Table (Id).First_Sdep ..
544 ALI.ALIs.Table (Id).Last_Sdep
546 if ALI.Sdep.Table (Index).Sfile = S_Osinte_Ads then
547 Libgnarl_Needed := True;
549 elsif OpenVMS_On_Target then
550 if ALI.Sdep.Table (Index).Sfile = S_Dec_Ads then
551 Libdecgnat_Needed := True;
553 elsif ALI.Sdep.Table (Index).Sfile = G_Trasym_Ads then
554 Gtrasymobj_Needed := True;
565 procedure Process (The_ALI : File_Name_Type) is
566 Text : Text_Buffer_Ptr;
568 First_Unit : ALI.Unit_Id;
569 Last_Unit : ALI.Unit_Id;
570 Unit_Data : Unit_Record;
571 Afile : File_Name_Type;
574 -- Nothing to do if the ALI file has already been processed.
575 -- This happens if an interface imports another interface.
577 if not Processed_ALIs.Get (The_ALI) then
578 Processed_ALIs.Set (The_ALI, True);
579 Text := Read_Library_Info (The_ALI);
590 if Idread /= No_ALI_Id then
591 First_Unit := ALI.ALIs.Table (Idread).First_Unit;
592 Last_Unit := ALI.ALIs.Table (Idread).Last_Unit;
594 -- Process both unit (spec and body) if the body is needed
595 -- by the spec (inline or generic). Otherwise, just process
598 if First_Unit /= Last_Unit and then
599 not ALI.Units.Table (Last_Unit).Body_Needed_For_SAL
601 First_Unit := Last_Unit;
604 for Unit in First_Unit .. Last_Unit loop
605 Unit_Data := ALI.Units.Table (Unit);
607 -- Check if each withed unit which is in the library is
608 -- also in the interface set, if it has not yet been
611 for W in Unit_Data.First_With .. Unit_Data.Last_With loop
612 Afile := Withs.Table (W).Afile;
614 if Afile /= No_Name and then Library_ALIs.Get (Afile)
615 and then not Processed_ALIs.Get (Afile)
617 if not Interface_ALIs.Get (Afile) then
618 if not Warning_For_Library then
619 Write_Str ("Warning: In library project """);
620 Get_Name_String (Data.Name);
621 To_Mixed (Name_Buffer (1 .. Name_Len));
622 Write_Str (Name_Buffer (1 .. Name_Len));
624 Warning_For_Library := True;
627 Write_Str (" Unit """);
628 Get_Name_String (Withs.Table (W).Uname);
629 To_Mixed (Name_Buffer (1 .. Name_Len - 2));
630 Write_Str (Name_Buffer (1 .. Name_Len - 2));
631 Write_Line (""" is not in the interface set");
632 Write_Str (" but it is needed by ");
634 case Unit_Data.Utype is
636 Write_Str ("the spec of ");
639 Write_Str ("the body of ");
646 Get_Name_String (Unit_Data.Uname);
647 To_Mixed (Name_Buffer (1 .. Name_Len - 2));
648 Write_Str (Name_Buffer (1 .. Name_Len - 2));
652 -- Now, process this unit
663 --------------------------------
664 -- Process_Imported_Libraries --
665 --------------------------------
667 procedure Process_Imported_Libraries is
668 Current : Project_Id;
670 procedure Process_Project (Project : Project_Id);
671 -- Process Project and its imported projects recursively.
672 -- Add any library projects to table Library_Projs.
674 ---------------------
675 -- Process_Project --
676 ---------------------
678 procedure Process_Project (Project : Project_Id) is
679 Data : constant Project_Data :=
680 In_Tree.Projects.Table (Project);
681 Imported : Project_List := Data.Imported_Projects;
682 Element : Project_Element;
685 -- Nothing to do if process has already been processed
687 if not Processed_Projects.Get (Data.Name) then
688 Processed_Projects.Set (Data.Name, True);
690 -- Call Process_Project recursively for any imported project.
691 -- We first process the imported projects to guarantee that
692 -- we have a proper reverse order for the libraries.
694 while Imported /= Empty_Project_List loop
696 In_Tree.Project_Lists.Table (Imported);
698 if Element.Project /= No_Project then
699 Process_Project (Element.Project);
702 Imported := Element.Next;
705 -- If it is a library project, add it to Library_Projs
707 if Project /= For_Project and then Data.Library then
708 Library_Projs.Increment_Last;
709 Library_Projs.Table (Library_Projs.Last) := Project;
715 -- Start of processing for Process_Imported_Libraries
718 -- Build list of library projects imported directly or indirectly,
719 -- in the reverse order.
721 Process_Project (For_Project);
723 -- Add the -L and -l switches and, if the Rpath option is supported,
724 -- add the directory to the Rpath.
725 -- As the library projects are in the wrong order, process from the
726 -- last to the first.
728 for Index in reverse 1 .. Library_Projs.Last loop
729 Current := Library_Projs.Table (Index);
732 (In_Tree.Projects.Table (Current).Library_Dir);
734 Opts.Table (Opts.Last) :=
735 new String'("-L" & Name_Buffer (1 .. Name_Len));
737 if Path_Option /= null then
738 Add_Rpath (Name_Buffer (1 .. Name_Len));
742 Opts.Table (Opts.Last) :=
746 (In_Tree.Projects.Table
747 (Current).Library_Name));
749 end Process_Imported_Libraries;
751 -- Start of processing for Build_Library
756 -- Fail if project is not a library project
758 if not Data.Library then
759 Com.Fail ("project """, Project_Name, """ has no library");
762 -- If this is the first time Build_Library is called, get the Name_Id
763 -- of "s-osinte.ads".
765 if S_Osinte_Ads = No_Name then
767 Add_Str_To_Name_Buffer ("s-osinte.ads");
768 S_Osinte_Ads := Name_Find;
771 if S_Dec_Ads = No_Name then
773 Add_Str_To_Name_Buffer ("dec.ads");
774 S_Dec_Ads := Name_Find;
777 if G_Trasym_Ads = No_Name then
779 Add_Str_To_Name_Buffer ("g-trasym.ads");
780 G_Trasym_Ads := Name_Find;
783 -- We work in the object directory
785 Change_Dir (Object_Directory_Path);
788 -- Call gnatbind only if Bind is True
791 if Gnatbind_Path = null then
792 Com.Fail ("unable to locate ", Gnatbind);
795 if Gcc_Path = null then
796 Com.Fail ("unable to locate ", Gcc);
799 -- Allocate Arguments, if it is the first time we see a standalone
802 if Arguments = No_Argument then
803 Arguments := new String_List (1 .. Initial_Argument_Max);
806 -- Add "-n -o b~<lib>.adb (b__<lib>.adb on VMS) -L<lib>"
808 Argument_Number := 2;
809 Arguments (1) := No_Main;
810 Arguments (2) := Output_Switch;
812 if OpenVMS_On_Target then
813 B_Start := new String'("b__");
817 (B_Start.all & Get_Name_String (Data.Library_Name) & ".adb");
818 Add_Argument ("-L" & Get_Name_String (Data.Library_Name));
820 if Data.Lib_Auto_Init and then SALs_Use_Constructors then
821 Add_Argument (Auto_Initialize);
824 -- Check if Binder'Default_Switches ("Ada") is defined. If it is,
825 -- add these switches to call gnatbind.
828 Binder_Package : constant Package_Id :=
830 (Name => Name_Binder,
831 In_Packages => Data.Decl.Packages,
835 if Binder_Package /= No_Package then
837 Defaults : constant Array_Element_Id :=
839 (Name => Name_Default_Switches,
841 In_Tree.Packages.Table
842 (Binder_Package).Decl.Arrays,
844 Switches : Variable_Value := Nil_Variable_Value;
846 Switch : String_List_Id := Nil_String;
849 if Defaults /= No_Array_Element then
854 In_Array => Defaults,
857 if not Switches.Default then
858 Switch := Switches.Values;
860 while Switch /= Nil_String loop
863 (In_Tree.String_Elements.Table
865 Switch := In_Tree.String_Elements.
875 -- Get all the ALI files of the project file. We do that even if
876 -- Bind is False, so that First_ALI is set.
883 Interface_ALIs.Reset;
884 Processed_ALIs.Reset;
886 for Source in Unit_Table.First ..
887 Unit_Table.Last (In_Tree.Units)
889 Unit := In_Tree.Units.Table (Source);
891 if Unit.File_Names (Body_Part).Name /= No_Name
892 and then Unit.File_Names (Body_Part).Path /= Slash
895 Check_Project (Unit.File_Names (Body_Part).Project)
897 if Unit.File_Names (Specification).Name = No_Name then
899 Src_Ind : Source_File_Index;
902 Src_Ind := Sinput.P.Load_Project_File
907 -- Add the ALI file only if it is not a subunit
910 not Sinput.P.Source_File_Is_Subunit (Src_Ind)
913 (Unit.File_Names (Body_Part).Name);
919 Add_ALI_For (Unit.File_Names (Body_Part).Name);
924 elsif Unit.File_Names (Specification).Name /= No_Name
925 and then Unit.File_Names (Specification).Path /= Slash
926 and then Check_Project
927 (Unit.File_Names (Specification).Project)
929 Add_ALI_For (Unit.File_Names (Specification).Name);
935 -- Continue setup and call gnatbind if Bind is True
939 -- Get an eventual --RTS from the ALI file
941 if First_ALI /= No_Name then
949 T := Read_Library_Info (First_ALI, True);
954 (First_ALI, T, Ignore_ED => False, Err => False);
956 if A /= No_ALI_Id then
959 (ALI.ALIs.Table (A).First_Unit).First_Arg ..
961 (ALI.ALIs.Table (A).First_Unit).Last_Arg
963 -- Look for --RTS. If found, add the switch to call
967 Arg : String_Ptr renames Args.Table (Index);
969 if Arg'Length >= 6 and then
970 Arg (Arg'First + 2 .. Arg'First + 5) = "RTS="
972 Add_Argument (Arg.all);
984 (Project => For_Project,
986 Including_Libraries => True);
988 -- Display the gnatbind command, if not in quiet output
995 (Gnatbind_Path.all, Arguments (1 .. Argument_Number), Success);
998 Com.Fail ("could not bind standalone library ",
999 Get_Name_String (Data.Library_Name));
1003 -- Compile the binder generated file only if Link is true
1009 (Project => For_Project,
1011 Including_Libraries => True);
1013 -- Invoke <gcc> -c b__<lib>.adb
1015 -- Allocate Arguments, if it is the first time we see a standalone
1018 if Arguments = No_Argument then
1019 Arguments := new String_List (1 .. Initial_Argument_Max);
1022 Argument_Number := 1;
1023 Arguments (1) := Compile_Switch;
1025 if OpenVMS_On_Target then
1026 B_Start := new String'("b__");
1030 (B_Start.all & Get_Name_String (Data.Library_Name) & ".adb");
1032 -- If necessary, add the PIC option
1034 if PIC_Option /= "" then
1035 Add_Argument (PIC_Option);
1038 -- Get the back-end switches and --RTS from the ALI file
1040 if First_ALI /= No_Name then
1042 T : Text_Buffer_Ptr;
1046 -- Load the ALI file
1048 T := Read_Library_Info (First_ALI, True);
1053 (First_ALI, T, Ignore_ED => False, Err => False);
1055 if A /= No_ALI_Id then
1058 (ALI.ALIs.Table (A).First_Unit).First_Arg ..
1060 (ALI.ALIs.Table (A).First_Unit).Last_Arg
1062 -- Do not compile with the front end switches except
1066 Arg : String_Ptr renames Args.Table (Index);
1068 if not Is_Front_End_Switch (Arg.all)
1070 Arg (Arg'First + 2 .. Arg'First + 5) = "RTS="
1072 Add_Argument (Arg.all);
1080 -- Now that all the arguments are set, compile the binder
1085 (Gcc_Path.all, Arguments (1 .. Argument_Number), Success);
1089 ("could not compile binder generated file for library ",
1090 Get_Name_String (Data.Library_Name));
1093 -- Process binder generated file for pragmas Linker_Options
1095 Process_Binder_File (Arguments (2).all & ASCII.NUL);
1099 -- Build the library only if Link is True
1102 -- If attribute Library_GCC was specified, get the driver name
1105 Value_Of (Name_Library_GCC, Data.Decl.Attributes, In_Tree);
1107 if not Library_GCC.Default then
1108 Driver_Name := Library_GCC.Value;
1111 -- If attribute Library_Options was specified, add these additional
1115 Value_Of (Name_Library_Options, Data.Decl.Attributes, In_Tree);
1117 if not Library_Options.Default then
1119 Current : String_List_Id := Library_Options.Values;
1120 Element : String_Element;
1123 while Current /= Nil_String loop
1125 In_Tree.String_Elements.Table (Current);
1126 Get_Name_String (Element.Value);
1128 if Name_Len /= 0 then
1129 Opts.Increment_Last;
1130 Opts.Table (Opts.Last) :=
1131 new String'(Name_Buffer (1 .. Name_Len));
1134 Current := Element.Next;
1139 Lib_Dirpath := new String'(Get_Name_String (Data.Library_Dir));
1140 Lib_Filename := new String'(Get_Name_String (Data.Library_Name));
1142 case Data.Library_Kind is
1144 The_Build_Mode := Static;
1147 The_Build_Mode := Dynamic;
1150 The_Build_Mode := Relocatable;
1152 if PIC_Option /= "" then
1153 Opts.Increment_Last;
1154 Opts.Table (Opts.Last) := new String'(PIC_Option);
1158 -- Get the library version, if any
1160 if Data.Lib_Internal_Name /= No_Name then
1162 new String'(Get_Name_String (Data.Lib_Internal_Name));
1165 -- Add the objects found in the object directory and the object
1166 -- directories of the extended files, if any, except for generated
1167 -- object files (b~.. or B__..) from extended projects.
1168 -- When there are one or more extended files, only add an object file
1169 -- if no object file with the same name have already been added.
1171 In_Main_Object_Directory := True;
1175 Object_Dir_Path : constant String :=
1176 Get_Name_String (Data.Object_Directory);
1177 Object_Dir : Dir_Type;
1178 Filename : String (1 .. 255);
1183 Open (Dir => Object_Dir, Dir_Name => Object_Dir_Path);
1185 -- For all entries in the object directory
1188 Read (Object_Dir, Filename, Last);
1192 -- Check if it is an object file
1194 if Is_Obj (Filename (1 .. Last)) then
1196 Object_Path : String :=
1198 (Object_Dir_Path & Directory_Separator &
1199 Filename (1 .. Last));
1202 Canonical_Case_File_Name (Object_Path);
1203 Canonical_Case_File_Name (Filename (1 .. Last));
1205 -- If in the object directory of an extended project,
1206 -- do not consider generated object files.
1208 if In_Main_Object_Directory
1210 or else Filename (1 .. B_Start'Length) /= B_Start.all
1213 Name_Buffer (1 .. Name_Len) := Filename (1 .. Last);
1216 if not Objects_Htable.Get (Id) then
1218 -- Record this object file
1220 Objects_Htable.Set (Id, True);
1221 Objects.Increment_Last;
1222 Objects.Table (Objects.Last) :=
1223 new String'(Object_Path);
1226 ALI_File : constant String :=
1227 Ext_To (Object_Path, "ali");
1230 if Is_Regular_File (ALI_File) then
1232 -- Record the ALI file
1234 ALIs.Increment_Last;
1235 ALIs.Table (ALIs.Last) :=
1236 new String'(ALI_File);
1238 -- Find out if for this ALI file,
1239 -- libgnarl or libdecgnat or g-trasym.obj
1240 -- (on OpenVMS) is necessary.
1242 Check_Libs (ALI_File);
1245 -- Object file is a foreign object file
1247 Foreigns.Increment_Last;
1248 Foreigns.Table (Foreigns.Last) :=
1249 new String'(Object_Path);
1258 Close (Dir => Object_Dir);
1261 when Directory_Error =>
1262 Com.Fail ("cannot find object directory """,
1263 Get_Name_String (Data.Object_Directory),
1267 exit when Data.Extends = No_Project;
1269 In_Main_Object_Directory := False;
1270 Data := In_Tree.Projects.Table (Data.Extends);
1273 -- Add the -L and -l switches for the imported Library Project Files,
1274 -- and, if Path Option is supported, the library directory path names
1277 Process_Imported_Libraries;
1279 -- Link with libgnat and possibly libgnarl
1281 Opts.Increment_Last;
1282 Opts.Table (Opts.Last) := new String'("-L" & Lib_Directory);
1284 -- If Path Option is supported, add libgnat directory path name to
1287 if Path_Option /= null then
1289 Libdir : constant String := Lib_Directory;
1290 GCC_Index : Natural := 0;
1295 -- For shared libraries, add to the Path Option the directory
1296 -- of the shared version of libgcc.
1298 if The_Build_Mode /= Static then
1299 GCC_Index := Index (Libdir, "/lib/");
1301 if GCC_Index = 0 then
1305 Directory_Separator & "lib" & Directory_Separator);
1308 if GCC_Index /= 0 then
1309 Add_Rpath (Libdir (Libdir'First .. GCC_Index + 3));
1315 if Libgnarl_Needed then
1316 Opts.Increment_Last;
1318 if The_Build_Mode = Static then
1319 Opts.Table (Opts.Last) := new String'("-lgnarl");
1321 Opts.Table (Opts.Last) := new String'(Shared_Lib ("gnarl"));
1325 if Gtrasymobj_Needed then
1326 Opts.Increment_Last;
1327 Opts.Table (Opts.Last) :=
1328 new String'(Lib_Directory & "/g-trasym.obj");
1331 if Libdecgnat_Needed then
1332 Opts.Increment_Last;
1334 Opts.Table (Opts.Last) :=
1335 new String'("-L" & Lib_Directory & "/../declib");
1337 Opts.Increment_Last;
1339 if The_Build_Mode = Static then
1340 Opts.Table (Opts.Last) := new String'("-ldecgnat");
1342 Opts.Table (Opts.Last) := new String'(Shared_Lib ("decgnat"));
1346 Opts.Increment_Last;
1348 if The_Build_Mode = Static then
1349 Opts.Table (Opts.Last) := new String'("-lgnat");
1351 Opts.Table (Opts.Last) := new String'(Shared_Lib ("gnat"));
1354 -- If Path Option is supported, add the necessary switch with the
1355 -- content of Rpath. As Rpath contains at least libgnat directory
1356 -- path name, it is guaranteed that it is not null.
1358 if Path_Option /= null then
1359 Opts.Increment_Last;
1360 Opts.Table (Opts.Last) :=
1361 new String'(Path_Option.all & Rpath (1 .. Rpath_Last));
1368 (Argument_List (Objects.Table (1 .. Objects.Last)));
1371 new Argument_List'(Argument_List
1372 (Foreigns.Table (1 .. Foreigns.Last)));
1375 new Argument_List'(Argument_List (ALIs.Table (1 .. ALIs.Last)));
1378 new Argument_List'(Argument_List (Opts.Table (1 .. Opts.Last)));
1380 -- We fail if there are no object to put in the library
1381 -- (Ada or foreign objects).
1383 if Object_Files'Length = 0 then
1384 Com.Fail ("no object files for library """ &
1385 Lib_Filename.all & '"');
1388 if not Opt.Quiet_Output then
1390 Write_Str ("building ");
1391 Write_Str (Ada.Characters.Handling.To_Lower
1392 (Build_Mode_State'Image (The_Build_Mode)));
1393 Write_Str (" library for project ");
1394 Write_Line (Project_Name);
1398 Write_Line ("object files:");
1400 for Index in Object_Files'Range loop
1402 Write_Line (Object_Files (Index).all);
1407 if Ali_Files'Length = 0 then
1408 Write_Line ("NO ALI files");
1411 Write_Line ("ALI files:");
1413 for Index in Ali_Files'Range loop
1415 Write_Line (Ali_Files (Index).all);
1422 -- We check that all object files are regular files
1426 -- Delete the existing library file, if it exists.
1427 -- Fail if the library file is not writable, or if it is not possible
1428 -- to delete the file.
1431 DLL_Name : aliased String :=
1432 Lib_Dirpath.all & '/' & DLL_Prefix &
1433 Lib_Filename.all & "." & DLL_Ext;
1435 Archive_Name : aliased String :=
1436 Lib_Dirpath.all & "/lib" &
1437 Lib_Filename.all & "." & Archive_Ext;
1439 type Str_Ptr is access all String;
1440 -- This type is necessary to meet the accessibility rules of Ada.
1441 -- It is not possible to use String_Access here.
1443 Full_Lib_Name : Str_Ptr;
1444 -- Designates the full library path name. Either DLL_Name or
1445 -- Archive_Name, depending on the library kind.
1447 Success : Boolean := False;
1448 -- Used to call Delete_File
1451 if The_Build_Mode = Static then
1452 Full_Lib_Name := Archive_Name'Access;
1454 Full_Lib_Name := DLL_Name'Access;
1457 if Is_Regular_File (Full_Lib_Name.all) then
1458 if Is_Writable_File (Full_Lib_Name.all) then
1459 Delete_File (Full_Lib_Name.all, Success);
1462 if Is_Regular_File (Full_Lib_Name.all) then
1463 Com.Fail ("could not delete """ & Full_Lib_Name.all & """");
1468 Argument_Number := 0;
1470 -- If we have a standalone library, gather all the interface ALI.
1471 -- They are passed to Build_Dynamic_Library, where they are used by
1472 -- some platforms (VMS, for example) to decide what symbols should be
1473 -- exported. They are also flagged as Interface when we copy them to
1474 -- the library directory (by Copy_ALI_Files, below).
1477 Data := In_Tree.Projects.Table (For_Project);
1480 Iface : String_List_Id := Data.Lib_Interface_ALIs;
1481 ALI : File_Name_Type;
1484 while Iface /= Nil_String loop
1486 In_Tree.String_Elements.Table (Iface).Value;
1487 Interface_ALIs.Set (ALI, True);
1489 (In_Tree.String_Elements.Table (Iface).Value);
1490 Add_Argument (Name_Buffer (1 .. Name_Len));
1492 In_Tree.String_Elements.Table (Iface).Next;
1495 Iface := Data.Lib_Interface_ALIs;
1497 if not Opt.Quiet_Output then
1499 -- Check that the interface set is complete: any unit in the
1500 -- library that is needed by an interface should also be an
1501 -- interface. If it is not the case, output a warning.
1503 while Iface /= Nil_String loop
1504 ALI := In_Tree.String_Elements.Table
1508 In_Tree.String_Elements.Table (Iface).Next;
1515 Current_Dir : constant String := Get_Current_Dir;
1518 Name : String (1 .. 200);
1521 Disregard : Boolean;
1523 DLL_Name : aliased constant String :=
1524 Lib_Filename.all & "." & DLL_Ext;
1526 Archive_Name : aliased constant String :=
1527 Lib_Filename.all & "." & Archive_Ext;
1529 Delete : Boolean := False;
1532 -- Clean the library directory: remove any file with the name of
1533 -- the library file and any ALI file of a source of the project.
1537 (In_Tree.Projects.Table (For_Project).Library_Dir);
1538 Change_Dir (Name_Buffer (1 .. Name_Len));
1543 ("unable to access library directory """,
1544 Name_Buffer (1 .. Name_Len),
1551 Read (Dir, Name, Last);
1554 if Is_Regular_File (Name (1 .. Last)) then
1555 Canonical_Case_File_Name (Name (1 .. Last));
1558 if (The_Build_Mode = Static and then
1559 Name (1 .. Last) = Archive_Name)
1561 ((The_Build_Mode = Dynamic or else
1562 The_Build_Mode = Relocatable)
1564 Name (1 .. Last) = DLL_Name)
1568 elsif Last > 4 and then Name (Last - 3 .. Last) = ".ali" then
1572 -- Compare with ALI file names of the project
1574 for Index in 1 .. Unit_Table.Last (In_Tree.Units) loop
1575 Unit := In_Tree.Units.Table (Index);
1577 if Unit.File_Names (Body_Part).Project /=
1580 if Ultimate_Extension_Of
1581 (Unit.File_Names (Body_Part).Project, In_Tree)
1585 (Unit.File_Names (Body_Part).Name);
1586 Name_Len := Name_Len -
1588 (Name (1 .. Name_Len))'Length;
1589 if Name_Buffer (1 .. Name_Len) =
1590 Name (1 .. Last - 4)
1597 elsif Ultimate_Extension_Of
1598 (Unit.File_Names (Specification).Project, In_Tree)
1602 (Unit.File_Names (Specification).Name);
1603 Name_Len := Name_Len -
1604 File_Extension (Name (1 .. Name_Len))'Length;
1606 if Name_Buffer (1 .. Name_Len) =
1607 Name (1 .. Last - 4)
1618 Set_Writable (Name (1 .. Last));
1619 Delete_File (Name (1 .. Last), Disregard);
1626 Change_Dir (Current_Dir);
1629 -- Call procedure to build the library, depending on the build mode
1631 case The_Build_Mode is
1632 when Dynamic | Relocatable =>
1633 Build_Dynamic_Library
1634 (Ofiles => Object_Files.all,
1635 Foreign => Foreign_Objects.all,
1636 Afiles => Ali_Files.all,
1637 Options => Options.all,
1638 Options_2 => No_Argument_List,
1639 Interfaces => Arguments (1 .. Argument_Number),
1640 Lib_Filename => Lib_Filename.all,
1641 Lib_Dir => Lib_Dirpath.all,
1642 Symbol_Data => Data.Symbol_Data,
1643 Driver_Name => Driver_Name,
1644 Lib_Version => Lib_Version.all,
1645 Auto_Init => Data.Lib_Auto_Init);
1658 -- We need to copy the ALI files from the object directory to
1659 -- the library ALI directory, so that the linker find them there,
1660 -- and does not need to look in the object directory where it
1661 -- would also find the object files; and we don't want that:
1662 -- we want the linker to use the library.
1664 -- Copy the ALI files and make the copies read-only. For interfaces,
1665 -- mark the copies as interfaces.
1668 (Files => Ali_Files.all,
1669 To => In_Tree.Projects.Table (For_Project).Library_ALI_Dir,
1670 Interfaces => Arguments (1 .. Argument_Number));
1672 -- Copy interface sources if Library_Src_Dir specified
1675 and then In_Tree.Projects.Table
1676 (For_Project).Library_Src_Dir /= No_Name
1678 -- Clean the interface copy directory: remove any source that
1679 -- could be a source of the project.
1683 (In_Tree.Projects.Table (For_Project).Library_Src_Dir);
1684 Change_Dir (Name_Buffer (1 .. Name_Len));
1689 ("unable to access library source copy directory """,
1690 Name_Buffer (1 .. Name_Len),
1696 Delete : Boolean := False;
1699 Name : String (1 .. 200);
1702 Disregard : Boolean;
1708 Read (Dir, Name, Last);
1711 if Is_Regular_File (Name (1 .. Last)) then
1712 Canonical_Case_File_Name (Name (1 .. Last));
1715 -- Compare with source file names of the project
1717 for Index in 1 .. Unit_Table.Last (In_Tree.Units) loop
1718 Unit := In_Tree.Units.Table (Index);
1720 if Ultimate_Extension_Of
1721 (Unit.File_Names (Body_Part).Project, In_Tree) =
1725 (Unit.File_Names (Body_Part).Name) =
1732 if Ultimate_Extension_Of
1733 (Unit.File_Names (Specification).Project, In_Tree) =
1737 (Unit.File_Names (Specification).Name) =
1747 Set_Writable (Name (1 .. Last));
1748 Delete_File (Name (1 .. Last), Disregard);
1755 Copy_Interface_Sources
1756 (For_Project => For_Project,
1758 Interfaces => Arguments (1 .. Argument_Number),
1759 To_Dir => In_Tree.Projects.Table
1760 (For_Project).Library_Src_Dir);
1764 -- Reset the current working directory to its previous value
1766 Change_Dir (Current_Dir);
1773 procedure Check (Filename : String) is
1775 if not Is_Regular_File (Filename) then
1776 Com.Fail (Filename, " not found.");
1784 procedure Check_Context is
1786 -- Check that each object file exists
1788 for F in Object_Files'Range loop
1789 Check (Object_Files (F).all);
1797 procedure Check_Library
1798 (For_Project : Project_Id; In_Tree : Project_Tree_Ref)
1800 Data : constant Project_Data :=
1801 In_Tree.Projects.Table (For_Project);
1802 Lib_TS : Time_Stamp_Type;
1803 Current : constant Dir_Name_Str := Get_Current_Dir;
1806 -- No need to build the library if there is no object directory,
1807 -- hence no object files to build the library.
1809 if Data.Library then
1811 Lib_Name : constant Name_Id :=
1812 Library_File_Name_For (For_Project, In_Tree);
1814 Change_Dir (Get_Name_String (Data.Library_Dir));
1815 Lib_TS := File_Stamp (Lib_Name);
1816 In_Tree.Projects.Table (For_Project).Library_TS := Lib_TS;
1819 if not Data.Externally_Built
1820 and then not Data.Need_To_Build_Lib
1821 and then Data.Object_Directory /= No_Name
1824 Obj_TS : Time_Stamp_Type;
1825 Object_Dir : Dir_Type;
1828 if OpenVMS_On_Target then
1829 B_Start := new String'("b__");
1832 -- If the library file does not exist, then the time stamp will
1833 -- be Empty_Time_Stamp, earlier than any other time stamp.
1835 Change_Dir (Get_Name_String (Data.Object_Directory));
1836 Open (Dir => Object_Dir, Dir_Name => ".");
1838 -- For all entries in the object directory
1841 Read (Object_Dir, Name_Buffer, Name_Len);
1842 exit when Name_Len = 0;
1844 -- Check if it is an object file, but ignore any binder
1847 if Is_Obj (Name_Buffer (1 .. Name_Len))
1848 and then Name_Buffer (1 .. B_Start'Length) /= B_Start.all
1850 -- Get the object file time stamp
1852 Obj_TS := File_Stamp (Name_Find);
1854 -- If library file time stamp is earlier, set
1855 -- Need_To_Build_Lib and return. String comparaison is
1856 -- used, otherwise time stamps may be too close and the
1857 -- comparaison would return True, which would trigger
1858 -- an unnecessary rebuild of the library.
1860 if String (Lib_TS) < String (Obj_TS) then
1862 -- Library must be rebuilt
1864 In_Tree.Projects.Table
1865 (For_Project).Need_To_Build_Lib := True;
1875 Change_Dir (Current);
1879 ----------------------------
1880 -- Copy_Interface_Sources --
1881 ----------------------------
1883 procedure Copy_Interface_Sources
1884 (For_Project : Project_Id;
1885 In_Tree : Project_Tree_Ref;
1886 Interfaces : Argument_List;
1889 Current : constant Dir_Name_Str := Get_Current_Dir;
1890 -- The current directory, where to return to at the end
1892 Target : constant Dir_Name_Str := Get_Name_String (To_Dir);
1893 -- The directory where to copy sources
1895 Text : Text_Buffer_Ptr;
1896 The_ALI : ALI.ALI_Id;
1899 First_Unit : ALI.Unit_Id;
1900 Second_Unit : ALI.Unit_Id;
1904 Copy_Subunits : Boolean := False;
1905 -- When True, indicates that subunits, if any, need to be copied too
1907 procedure Copy (File_Name : Name_Id);
1908 -- Copy one source of the project to the target directory
1910 function Is_Same_Or_Extension
1911 (Extending : Project_Id;
1912 Extended : Project_Id) return Boolean;
1913 -- Return True if project Extending is equal to or extends project
1920 procedure Copy (File_Name : Name_Id) is
1921 Success : Boolean := False;
1925 for Index in Unit_Table.First ..
1926 Unit_Table.Last (In_Tree.Units)
1928 Data := In_Tree.Units.Table (Index);
1930 -- Find and copy the immediate or inherited source
1932 for J in Data.File_Names'Range loop
1933 if Is_Same_Or_Extension
1934 (For_Project, Data.File_Names (J).Project)
1935 and then Data.File_Names (J).Name = File_Name
1938 (Get_Name_String (Data.File_Names (J).Path),
1942 Preserve => Preserve);
1949 --------------------------
1950 -- Is_Same_Or_Extension --
1951 --------------------------
1953 function Is_Same_Or_Extension
1954 (Extending : Project_Id;
1955 Extended : Project_Id) return Boolean
1957 Ext : Project_Id := Extending;
1960 while Ext /= No_Project loop
1961 if Ext = Extended then
1965 Ext := In_Tree.Projects.Table (Ext).Extends;
1969 end Is_Same_Or_Extension;
1971 -- Start of processing for Copy_Interface_Sources
1974 -- Change the working directory to the object directory
1978 (In_Tree.Projects.Table
1979 (For_Project).Object_Directory));
1981 for Index in Interfaces'Range loop
1983 -- First, load the ALI file
1986 Add_Str_To_Name_Buffer (Interfaces (Index).all);
1987 Lib_File := Name_Find;
1988 Text := Read_Library_Info (Lib_File);
1989 The_ALI := Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
1992 Second_Unit := No_Unit_Id;
1993 First_Unit := ALI.ALIs.Table (The_ALI).First_Unit;
1994 Copy_Subunits := True;
1996 -- If there is both a spec and a body, check if they are both needed
1998 if ALI.Units.Table (First_Unit).Utype = Is_Body then
1999 Second_Unit := ALI.ALIs.Table (The_ALI).Last_Unit;
2001 -- If the body is not needed, then reset First_Unit
2003 if not ALI.Units.Table (Second_Unit).Body_Needed_For_SAL then
2004 First_Unit := No_Unit_Id;
2005 Copy_Subunits := False;
2008 elsif ALI.Units.Table (First_Unit).Utype = Is_Spec_Only then
2009 Copy_Subunits := False;
2012 -- Copy the file(s) that need to be copied
2014 if First_Unit /= No_Unit_Id then
2015 Copy (File_Name => ALI.Units.Table (First_Unit).Sfile);
2018 if Second_Unit /= No_Unit_Id then
2019 Copy (File_Name => ALI.Units.Table (Second_Unit).Sfile);
2022 -- Copy all the separates, if any
2024 if Copy_Subunits then
2025 for Dep in ALI.ALIs.Table (The_ALI).First_Sdep ..
2026 ALI.ALIs.Table (The_ALI).Last_Sdep
2028 if Sdep.Table (Dep).Subunit_Name /= No_Name then
2029 Copy (File_Name => Sdep.Table (Dep).Sfile);
2035 -- Restore the initial working directory
2037 Change_Dir (Current);
2038 end Copy_Interface_Sources;
2044 procedure Display (Executable : String) is
2046 if not Opt.Quiet_Output then
2047 Write_Str (Executable);
2049 for Index in 1 .. Argument_Number loop
2051 Write_Str (Arguments (Index).all);
2062 function Index (S, Pattern : String) return Natural is
2063 Len : constant Natural := Pattern'Length;
2066 for J in reverse S'First .. S'Last - Len + 1 loop
2067 if Pattern = S (J .. J + Len - 1) then
2075 -------------------------
2076 -- Process_Binder_File --
2077 -------------------------
2079 procedure Process_Binder_File (Name : String) is
2081 -- Binder file's descriptor
2083 Read_Mode : constant String := "r" & ASCII.Nul;
2086 Status : Interfaces.C_Streams.int;
2087 pragma Unreferenced (Status);
2090 Begin_Info : constant String := "-- BEGIN Object file/option list";
2091 End_Info : constant String := "-- END Object file/option list ";
2093 Next_Line : String (1 .. 1000);
2094 -- Current line value
2095 -- Where does this odd constant 1000 come from, looks suspicious ???
2098 -- End of line slice (the slice does not contain the line terminator)
2100 procedure Get_Next_Line;
2101 -- Read the next line from the binder file without the line terminator
2107 procedure Get_Next_Line is
2111 Fchars := fgets (Next_Line'Address, Next_Line'Length, Fd);
2113 if Fchars = System.Null_Address then
2114 Fail ("Error reading binder output");
2118 while Nlast <= Next_Line'Last
2119 and then Next_Line (Nlast) /= ASCII.LF
2120 and then Next_Line (Nlast) /= ASCII.CR
2128 -- Start of processing for Process_Binder_File
2131 Fd := fopen (Name'Address, Read_Mode'Address);
2133 if Fd = NULL_Stream then
2134 Fail ("Failed to open binder output");
2137 -- Skip up to the Begin Info line
2141 exit when Next_Line (1 .. Nlast) = Begin_Info;
2144 -- Find the first switch
2149 exit when Next_Line (1 .. Nlast) = End_Info;
2151 -- As the binder generated file is in Ada, remove the first eight
2152 -- characters " -- ".
2154 Next_Line (1 .. Nlast - 8) := Next_Line (9 .. Nlast);
2157 -- Stop when the first switch is found
2159 exit when Next_Line (1) = '-';
2162 if Next_Line (1 .. Nlast) /= End_Info then
2164 -- Ignore -static and -shared, since -shared will be used
2167 -- Ignore -lgnat, -lgnarl and -ldecgnat as they will be added
2168 -- later, because they are also needed for non Stand-Alone shared
2171 -- Also ignore the shared libraries which are :
2173 -- UNIX / Windows VMS
2174 -- -lgnat-<version> -lgnat_<version> (7 + version'length chars)
2175 -- -lgnarl-<version> -lgnarl_<version> (8 + version'length chars)
2177 if Next_Line (1 .. Nlast) /= "-static" and then
2178 Next_Line (1 .. Nlast) /= "-shared" and then
2179 Next_Line (1 .. Nlast) /= "-ldecgnat" and then
2180 Next_Line (1 .. Nlast) /= "-lgnarl" and then
2181 Next_Line (1 .. Nlast) /= "-lgnat" and then
2183 (1 .. Natural'Min (Nlast, 10 + Library_Version'Length)) /=
2184 Shared_Lib ("decgnat") and then
2186 (1 .. Natural'Min (Nlast, 8 + Library_Version'Length)) /=
2187 Shared_Lib ("gnarl") and then
2189 (1 .. Natural'Min (Nlast, 7 + Library_Version'Length)) /=
2192 if Next_Line (1) /= '-' then
2194 -- This is not an option, should we add it?
2196 if Add_Object_Files then
2197 Opts.Increment_Last;
2198 Opts.Table (Opts.Last) :=
2199 new String'(Next_Line (1 .. Nlast));
2203 -- Add all other options
2205 Opts.Increment_Last;
2206 Opts.Table (Opts.Last) :=
2207 new String'(Next_Line (1 .. Nlast));
2211 -- Next option, if any
2214 exit when Next_Line (1 .. Nlast) = End_Info;
2216 -- Remove first eight characters " -- "
2218 Next_Line (1 .. Nlast - 8) := Next_Line (9 .. Nlast);
2223 Status := fclose (Fd);
2225 -- Is it really right to ignore any close error ???
2227 end Process_Binder_File;
2233 procedure Reset_Tables is
2236 Objects_Htable.Reset;
2240 Processed_Projects.Reset;
2244 ---------------------------
2245 -- SALs_Use_Constructors --
2246 ---------------------------
2248 function SALs_Use_Constructors return Boolean is
2249 function C_SALs_Init_Using_Constructors return Integer;
2250 pragma Import (C, C_SALs_Init_Using_Constructors,
2251 "__gnat_sals_init_using_constructors");
2253 return C_SALs_Init_Using_Constructors /= 0;
2254 end SALs_Use_Constructors;
2256 ---------------------------
2257 -- Ultimate_Extension_Of --
2258 ---------------------------
2260 function Ultimate_Extension_Of
2261 (Project : Project_Id;
2262 In_Tree : Project_Tree_Ref) return Project_Id
2264 Result : Project_Id := Project;
2265 Data : Project_Data;
2268 if Project /= No_Project then
2270 Data := In_Tree.Projects.Table (Result);
2271 exit when Data.Extended_By = No_Project;
2272 Result := Data.Extended_By;
2277 end Ultimate_Extension_Of;