1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2008, 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 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
27 with Gnatvsn
; use Gnatvsn
;
28 with MLib
.Fil
; use MLib
.Fil
;
29 with MLib
.Tgt
; use MLib
.Tgt
;
30 with MLib
.Utl
; use MLib
.Utl
;
32 with Output
; use Output
;
33 with Prj
.Com
; use Prj
.Com
;
34 with Prj
.Env
; use Prj
.Env
;
35 with Prj
.Util
; use Prj
.Util
;
37 with Snames
; use Snames
;
38 with Switch
; use Switch
;
40 with Targparm
; use Targparm
;
42 with Types
; use Types
;
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 : File_Name_Type := No_File;
67 -- Name_Id for "s-osinte.ads"
69 S_Dec_Ads : File_Name_Type := No_File;
70 -- Name_Id for "dec.ads"
72 G_Trasym_Ads : File_Name_Type := No_File;
73 -- Name_Id for "g-trasym.ads"
75 Arguments : String_List_Access := No_Argument;
76 -- Used to accumulate arguments for the invocation of gnatbind and of
77 -- the compiler. Also used to collect the interface ALI when copying
78 -- the ALI files to the library directory.
80 Argument_Number : Natural := 0;
81 -- Index of the last argument in Arguments
83 Initial_Argument_Max : constant := 10;
85 No_Main_String : aliased String := "-n";
86 No_Main : constant String_Access := No_Main_String'Access;
88 Output_Switch_String : aliased String := "-o";
89 Output_Switch : constant String_Access := Output_Switch_String'Access;
91 Compile_Switch_String : aliased String := "-c";
92 Compile_Switch : constant String_Access := Compile_Switch_String'Access;
94 Auto_Initialize : constant String := "-a";
96 -- List of objects to put inside the library
98 Object_Files : Argument_List_Access;
100 package Objects is new Table.Table
101 (Table_Name => "Mlib.Prj.Objects",
102 Table_Component_Type => String_Access,
103 Table_Index_Type => Natural,
104 Table_Low_Bound => 1,
106 Table_Increment => 100);
108 package Objects_Htable is new GNAT.HTable.Simple_HTable
109 (Header_Num => Header_Num,
118 Ali_Files : Argument_List_Access;
120 package ALIs is new Table.Table
121 (Table_Name => "Mlib.Prj.Alis",
122 Table_Component_Type => String_Access,
123 Table_Index_Type => Natural,
124 Table_Low_Bound => 1,
126 Table_Increment => 100);
128 -- List of options set in the command line
130 Options : Argument_List_Access;
132 package Opts is new Table.Table
133 (Table_Name => "Mlib.Prj.Opts",
134 Table_Component_Type => String_Access,
135 Table_Index_Type => Natural,
136 Table_Low_Bound => 1,
138 Table_Increment => 100);
140 -- All the ALI file in the library
142 package Library_ALIs is new GNAT.HTable.Simple_HTable
143 (Header_Num => Header_Num,
146 Key => File_Name_Type,
150 -- The ALI files in the interface sets
152 package Interface_ALIs is new GNAT.HTable.Simple_HTable
153 (Header_Num => Header_Num,
156 Key => File_Name_Type,
160 -- The ALI files that have been processed to check if the corresponding
161 -- library unit is in the interface set.
163 package Processed_ALIs is new GNAT.HTable.Simple_HTable
164 (Header_Num => Header_Num,
167 Key => File_Name_Type,
171 -- The projects imported directly or indirectly
173 package Processed_Projects is new GNAT.HTable.Simple_HTable
174 (Header_Num => Header_Num,
181 -- The library projects imported directly or indirectly
183 package Library_Projs is new Table.Table (
184 Table_Component_Type => Project_Id,
185 Table_Index_Type => Integer,
186 Table_Low_Bound => 1,
188 Table_Increment => 10,
189 Table_Name => "Make.Library_Projs");
191 type Build_Mode_State is (None, Static, Dynamic, Relocatable);
193 procedure Add_Argument (S : String);
194 -- Add one argument to Arguments array, if array is full, double its size
196 function ALI_File_Name (Source : String) return String;
197 -- Return the ALI file name corresponding to a source
199 procedure Check (Filename : String);
200 -- Check if filename is a regular file. Fail if it is not
202 procedure Check_Context;
203 -- Check each object files in table Object_Files
204 -- Fail if any of them is not a regular file
206 procedure Copy_Interface_Sources
207 (For_Project : Project_Id;
208 In_Tree : Project_Tree_Ref;
209 Interfaces : Argument_List;
210 To_Dir : Path_Name_Type);
211 -- Copy the interface sources of a SAL to directory To_Dir
213 procedure Display (Executable : String);
214 -- Display invocation of gnatbind and of the compiler with the arguments
215 -- in Arguments, except when Quiet_Output is True.
217 function Index (S, Pattern : String) return Natural;
218 -- Return the last occurrence of Pattern in S, or 0 if none
220 procedure Process_Binder_File (Name : String);
221 -- For Stand-Alone libraries, get the Linker Options in the binder
224 procedure Reset_Tables;
225 -- Make sure that all the above tables are empty
226 -- (Objects, Ali_Files, Options).
228 function SALs_Use_Constructors return Boolean;
229 -- Indicate if Stand-Alone Libraries are automatically initialized using
230 -- the constructor mechanism.
232 function Ultimate_Extension_Of
233 (Project : Project_Id;
234 In_Tree : Project_Tree_Ref) return Project_Id;
235 -- Returns the Project_Id of project Project. Returns No_Project
236 -- if Project is No_Project.
242 procedure Add_Argument (S : String) is
244 if Argument_Number = Arguments'Last then
246 New_Args : constant String_List_Access :=
247 new String_List (1 .. 2 * Arguments'Last);
250 -- Copy the String_Accesses and set them to null in Arguments
251 -- so that they will not be deallocated by the call to
254 New_Args (Arguments'Range) := Arguments.all;
255 Arguments.all := (others => null);
257 Arguments := New_Args;
261 Argument_Number := Argument_Number + 1;
262 Arguments (Argument_Number) := new String'(S
);
269 function ALI_File_Name
(Source
: String) return String is
271 -- If the source name has an extension, then replace it with
274 for Index
in reverse Source
'First + 1 .. Source
'Last loop
275 if Source
(Index
) = '.' then
276 return Source
(Source
'First .. Index
- 1) & ALI_Suffix
;
280 -- If there is no dot, or if it is the first character, just add the
283 return Source
& ALI_Suffix
;
290 procedure Build_Library
291 (For_Project
: Project_Id
;
292 In_Tree
: Project_Tree_Ref
;
294 Gnatbind_Path
: String_Access
;
296 Gcc_Path
: String_Access
;
297 Bind
: Boolean := True;
298 Link
: Boolean := True)
300 Maximum_Size
: Integer;
301 pragma Import
(C
, Maximum_Size
, "__gnat_link_max");
302 -- Maximum number of bytes to put in an invocation of the
306 -- The number of bytes for the invocation of the gnatbind
308 Warning_For_Library
: Boolean := False;
309 -- Set to True for the first warning about a unit missing from the
312 Data
: Project_Data
:= In_Tree
.Projects
.Table
(For_Project
);
314 Libgnarl_Needed
: Yes_No_Unknown
:= Data
.Libgnarl_Needed
;
315 -- Set to True if library needs to be linked with libgnarl
317 Libdecgnat_Needed
: Boolean := False;
318 -- On OpenVMS, set to True if library needs to be linked with libdecgnat
320 Gtrasymobj_Needed
: Boolean := False;
321 -- On OpenVMS, set to True if library needs to be linked with
324 Object_Directory_Path
: constant String :=
326 (Data
.Object_Directory
.Display_Name
);
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 first 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_Information
719 -- Check if libgnarl is needed for this library
722 Object_Dir_Path : constant String :=
724 (Data.Object_Directory.
726 Object_Dir : Dir_Type;
727 Filename : String (1 .. 255);
731 Open (Object_Dir, Object_Dir_Path);
733 -- For all entries in the object directory
736 Read (Object_Dir, Filename, Last);
739 -- Check if it is an object file
741 if Is_Obj (Filename (1 .. Last)) then
743 Object_Path : constant String :=
746 Directory_Separator &
747 Filename (1 .. Last));
748 ALI_File : constant String :=
750 (Object_Path, "ali");
753 if Is_Regular_File (ALI_File) then
755 -- Find out if for this ALI file,
756 -- libgnarl is necessary.
759 (ALI_File, Main_Project => False);
761 if Libgnarl_Needed = Yes then
762 Data.Libgnarl_Needed := Yes;
763 In_Tree.Projects.Table
764 (For_Project).Libgnarl_Needed :=
777 if Data.Libgnarl_Needed = Yes then
778 Libgnarl_Needed := Yes;
779 In_Tree.Projects.Table (For_Project).Libgnarl_Needed :=
788 -- Start of processing for Process_Imported_Libraries
791 -- Build list of library projects imported directly or indirectly,
792 -- in the reverse order.
794 Process_Project (For_Project);
796 -- Add the -L and -l switches and, if the Rpath option is supported,
797 -- add the directory to the Rpath. As the library projects are in the
798 -- wrong order, process from the last to the first.
800 for Index in reverse 1 .. Library_Projs.Last loop
801 Current := Library_Projs.Table (Index);
804 (In_Tree.Projects.Table (Current).Library_Dir.Display_Name);
806 Opts.Table (Opts.Last) :=
807 new String'("-L" & Name_Buffer
(1 .. Name_Len
));
809 if Path_Option
/= null then
810 Add_Rpath
(Name_Buffer
(1 .. Name_Len
));
814 Opts
.Table
(Opts
.Last
) :=
818 (In_Tree.Projects.Table
819 (Current).Library_Name));
821 end Process_Imported_Libraries;
823 -- Start of processing for Build_Library
828 -- Fail if project is not a library project
830 if not Data.Library then
831 Com.Fail ("project """, Project_Name, """ has no library");
834 -- Do not attempt to build the library if it is externally built
836 if Data.Externally_Built then
840 -- If this is the first time Build_Library is called, get the Name_Id
841 -- of "s-osinte.ads".
843 if S_Osinte_Ads = No_File then
845 Add_Str_To_Name_Buffer ("s-osinte.ads");
846 S_Osinte_Ads := Name_Find;
849 if S_Dec_Ads = No_File then
851 Add_Str_To_Name_Buffer ("dec.ads");
852 S_Dec_Ads := Name_Find;
855 if G_Trasym_Ads = No_File then
857 Add_Str_To_Name_Buffer ("g-trasym.ads");
858 G_Trasym_Ads := Name_Find;
861 -- We work in the object directory
863 Change_Dir (Object_Directory_Path);
867 -- Call gnatbind only if Bind is True
870 if Gnatbind_Path = null then
871 Com.Fail ("unable to locate ", Gnatbind);
874 if Gcc_Path = null then
875 Com.Fail ("unable to locate ", Gcc);
878 -- Allocate Arguments, if it is the first time we see a standalone
881 if Arguments = No_Argument then
882 Arguments := new String_List (1 .. Initial_Argument_Max);
885 -- Add "-n -o b~<lib>.adb (b__<lib>.adb on VMS) -L<lib>"
887 Argument_Number := 2;
888 Arguments (1) := No_Main;
889 Arguments (2) := Output_Switch;
891 if OpenVMS_On_Target then
892 B_Start := new String'("b__");
896 (B_Start
.all & Get_Name_String
(Data
.Library_Name
) & ".adb");
897 Add_Argument
("-L" & Get_Name_String
(Data
.Library_Name
));
899 if Data
.Lib_Auto_Init
and then SALs_Use_Constructors
then
900 Add_Argument
(Auto_Initialize
);
903 -- Check if Binder'Default_Switches ("Ada") is defined. If it is,
904 -- add these switches to call gnatbind.
907 Binder_Package
: constant Package_Id
:=
909 (Name
=> Name_Binder
,
910 In_Packages
=> Data
.Decl
.Packages
,
914 if Binder_Package
/= No_Package
then
916 Defaults
: constant Array_Element_Id
:=
918 (Name
=> Name_Default_Switches
,
920 In_Tree
.Packages
.Table
921 (Binder_Package
).Decl
.Arrays
,
923 Switches
: Variable_Value
:= Nil_Variable_Value
;
925 Switch
: String_List_Id
:= Nil_String
;
928 if Defaults
/= No_Array_Element
then
933 In_Array
=> Defaults
,
936 if not Switches
.Default
then
937 Switch
:= Switches
.Values
;
939 while Switch
/= Nil_String
loop
942 (In_Tree
.String_Elements
.Table
944 Switch
:= In_Tree
.String_Elements
.
954 -- Get all the ALI files of the project file. We do that even if
955 -- Bind is False, so that First_ALI is set.
962 Interface_ALIs
.Reset
;
963 Processed_ALIs
.Reset
;
965 for Source
in Unit_Table
.First
..
966 Unit_Table
.Last
(In_Tree
.Units
)
968 Unit
:= In_Tree
.Units
.Table
(Source
);
970 if Unit
.File_Names
(Body_Part
).Name
/= No_File
971 and then Unit
.File_Names
(Body_Part
).Path
.Name
/= Slash
974 Check_Project
(Unit
.File_Names
(Body_Part
).Project
)
976 if Unit
.File_Names
(Specification
).Name
= No_File
then
978 Src_Ind
: Source_File_Index
;
981 Src_Ind
:= Sinput
.P
.Load_Project_File
984 (Body_Part
).Path
.Name
));
986 -- Add the ALI file only if it is not a subunit
989 Sinput
.P
.Source_File_Is_Subunit
(Src_Ind
)
992 (Unit
.File_Names
(Body_Part
).Name
);
998 Add_ALI_For
(Unit
.File_Names
(Body_Part
).Name
);
1003 elsif Unit
.File_Names
(Specification
).Name
/= No_File
1004 and then Unit
.File_Names
(Specification
).Path
.Name
/= Slash
1005 and then Check_Project
1006 (Unit
.File_Names
(Specification
).Project
)
1008 Add_ALI_For
(Unit
.File_Names
(Specification
).Name
);
1014 -- Continue setup and call gnatbind if Bind is True
1018 -- Get an eventual --RTS from the ALI file
1020 if First_ALI
/= No_File
then
1022 T
: Text_Buffer_Ptr
;
1026 -- Load the ALI file
1028 T
:= Read_Library_Info
(First_ALI
, True);
1033 (First_ALI
, T
, Ignore_ED
=> False, Err
=> False);
1035 if A
/= No_ALI_Id
then
1038 (ALI
.ALIs
.Table
(A
).First_Unit
).First_Arg
..
1040 (ALI
.ALIs
.Table
(A
).First_Unit
).Last_Arg
1042 -- Look for --RTS. If found, add the switch to call
1046 Arg
: String_Ptr
renames Args
.Table
(Index
);
1048 if Arg
'Length >= 6 and then
1049 Arg
(Arg
'First + 2 .. Arg
'First + 5) = "RTS="
1051 Add_Argument
(Arg
.all);
1063 (Project
=> For_Project
,
1065 Including_Libraries
=> True);
1067 -- Display the gnatbind command, if not in quiet output
1072 for J
in 1 .. Argument_Number
loop
1073 Size
:= Size
+ Arguments
(J
)'Length + 1;
1076 -- Invoke gnatbind with the arguments if the size is not too large
1078 if Size
<= Maximum_Size
then
1081 Arguments
(1 .. Argument_Number
),
1085 -- Otherwise create a temporary response file
1088 FD
: File_Descriptor
;
1089 Path
: Path_Name_Type
;
1090 Args
: Argument_List
(1 .. 1);
1091 EOL
: constant String (1 .. 1) := (1 => ASCII
.LF
);
1094 Quotes_Needed
: Boolean;
1095 Last_Char
: Natural;
1099 Tempdir
.Create_Temp_File
(FD
, Path
);
1100 Args
(1) := new String'("@" & Get_Name_String (Path));
1102 for J in 1 .. Argument_Number loop
1104 -- Check if the argument should be quoted
1106 Quotes_Needed := False;
1107 Last_Char := Arguments (J)'Length;
1109 for K in Arguments (J)'Range loop
1110 Ch := Arguments (J) (K);
1112 if Ch = ' ' or else Ch = ASCII.HT or else Ch = '"' then
1113 Quotes_Needed := True;
1118 if Quotes_Needed then
1120 -- Quote the argument, doubling '"'
1123 Arg : String (1 .. Arguments (J)'Length * 2 + 2);
1129 for K in Arguments (J)'Range loop
1130 Ch := Arguments (J) (K);
1131 Last_Char := Last_Char + 1;
1132 Arg (Last_Char) := Ch;
1135 Last_Char := Last_Char + 1;
1136 Arg (Last_Char) := '"';
1140 Last_Char := Last_Char + 1;
1141 Arg (Last_Char) := '"';
1143 Status := Write (FD, Arg'Address, Last_Char);
1149 Arguments (J) (Arguments (J)'First)'Address,
1153 if Status /= Last_Char then
1157 Status := Write (FD, EOL (1)'Address, 1);
1166 -- And invoke gnatbind with this this response file
1168 Spawn (Gnatbind_Path.all, Args, Success);
1170 Delete_File (Get_Name_String (Path), Succ);
1179 Com.Fail ("could not bind standalone library ",
1180 Get_Name_String (Data.Library_Name));
1184 -- Compile the binder generated file only if Link is true
1191 (Project => For_Project,
1193 Including_Libraries => True);
1195 -- Invoke <gcc> -c b__<lib>.adb
1197 -- Allocate Arguments, if it is the first time we see a standalone
1200 if Arguments = No_Argument then
1201 Arguments := new String_List (1 .. Initial_Argument_Max);
1204 Argument_Number := 1;
1205 Arguments (1) := Compile_Switch;
1207 if OpenVMS_On_Target then
1208 B_Start := new String'("b__");
1212 (B_Start
.all & Get_Name_String
(Data
.Library_Name
) & ".adb");
1214 -- If necessary, add the PIC option
1216 if PIC_Option
/= "" then
1217 Add_Argument
(PIC_Option
);
1220 -- Get the back-end switches and --RTS from the ALI file
1222 if First_ALI
/= No_File
then
1224 T
: Text_Buffer_Ptr
;
1228 -- Load the ALI file
1230 T
:= Read_Library_Info
(First_ALI
, True);
1235 Scan_ALI
(First_ALI
, T
, Ignore_ED
=> False, Err
=> False);
1237 if A
/= No_ALI_Id
then
1240 (ALI
.ALIs
.Table
(A
).First_Unit
).First_Arg
..
1242 (ALI
.ALIs
.Table
(A
).First_Unit
).Last_Arg
1244 -- Do not compile with the front end switches except
1248 Arg
: String_Ptr
renames Args
.Table
(Index
);
1250 if not Is_Front_End_Switch
(Arg
.all)
1252 Arg
(Arg
'First + 2 .. Arg
'First + 5) = "RTS="
1254 Add_Argument
(Arg
.all);
1262 -- Now that all the arguments are set, compile the binder
1267 (Gcc_Path
.all, Arguments
(1 .. Argument_Number
), Success
);
1271 ("could not compile binder generated file for library ",
1272 Get_Name_String
(Data
.Library_Name
));
1275 -- Process binder generated file for pragmas Linker_Options
1277 Process_Binder_File
(Arguments
(2).all & ASCII
.NUL
);
1281 -- Build the library only if Link is True
1285 -- If attribute Library_GCC was specified, get the driver name
1288 Value_Of
(Name_Library_GCC
, Data
.Decl
.Attributes
, In_Tree
);
1290 if not Library_GCC
.Default
then
1291 Driver_Name
:= Library_GCC
.Value
;
1294 -- If attribute Library_Options was specified, add these additional
1298 Value_Of
(Name_Library_Options
, Data
.Decl
.Attributes
, In_Tree
);
1300 if not Library_Options
.Default
then
1302 Current
: String_List_Id
;
1303 Element
: String_Element
;
1306 Current
:= Library_Options
.Values
;
1307 while Current
/= Nil_String
loop
1308 Element
:= In_Tree
.String_Elements
.Table
(Current
);
1309 Get_Name_String
(Element
.Value
);
1311 if Name_Len
/= 0 then
1312 Opts
.Increment_Last
;
1313 Opts
.Table
(Opts
.Last
) :=
1314 new String'(Name_Buffer (1 .. Name_Len));
1317 Current := Element.Next;
1323 new String'(Get_Name_String
(Data
.Library_Dir
.Display_Name
));
1324 Lib_Filename
:= new String'(Get_Name_String (Data.Library_Name));
1326 case Data.Library_Kind is
1328 The_Build_Mode := Static;
1331 The_Build_Mode := Dynamic;
1334 The_Build_Mode := Relocatable;
1336 if PIC_Option /= "" then
1337 Opts.Increment_Last;
1338 Opts.Table (Opts.Last) := new String'(PIC_Option
);
1342 -- Get the library version, if any
1344 if Data
.Lib_Internal_Name
/= No_Name
then
1346 new String'(Get_Name_String (Data.Lib_Internal_Name));
1349 -- Add the objects found in the object directory and the object
1350 -- directories of the extended files, if any, except for generated
1351 -- object files (b~.. or B__..) from extended projects.
1352 -- When there are one or more extended files, only add an object file
1353 -- if no object file with the same name have already been added.
1355 In_Main_Object_Directory := True;
1357 There_Are_Foreign_Sources := Data.Other_Sources_Present;
1360 if Data.Object_Directory /= No_Path_Information then
1362 Object_Dir_Path : constant String :=
1364 (Data.Object_Directory.Display_Name);
1365 Object_Dir : Dir_Type;
1366 Filename : String (1 .. 255);
1371 Open (Dir => Object_Dir, Dir_Name => Object_Dir_Path);
1373 -- For all entries in the object directory
1376 Read (Object_Dir, Filename, Last);
1380 -- Check if it is an object file
1382 if Is_Obj (Filename (1 .. Last)) then
1384 Object_Path : constant String :=
1387 Directory_Separator &
1388 Filename (1 .. Last));
1389 C_Object_Path : String := Object_Path;
1390 C_Filename : String := Filename (1 .. Last);
1393 Canonical_Case_File_Name (C_Object_Path);
1394 Canonical_Case_File_Name (C_Filename);
1396 -- If in the object directory of an extended
1397 -- project, do not consider generated object files.
1399 if In_Main_Object_Directory
1402 C_Filename (1 .. B_Start'Length) /= B_Start.all
1405 Name_Buffer (1 .. Name_Len) :=
1406 C_Filename (1 .. Last);
1409 if not Objects_Htable.Get (Id) then
1411 ALI_File : constant String :=
1414 (1 .. Last), "ali");
1415 ALI_Path : constant String :=
1416 Ext_To (C_Object_Path, "ali");
1418 There_Are_Foreign_Sources
1423 (1 .. B_Start'Length) =
1425 Fname : File_Name_Type;
1429 if Is_Regular_File (ALI_Path) then
1431 -- If there is an ALI file, check if
1432 -- the object file should be added to
1433 -- the library. If there are foreign
1434 -- sources we put all object files in
1439 1 .. Unit_Table.Last
1442 if In_Tree.Units.Table
1444 (Body_Part).Name /= No_File
1447 In_Tree.Units.Table (Index).
1449 (Body_Part).Project;
1451 In_Tree.Units.Table (Index).
1452 File_Names (Body_Part).Name;
1457 (Specification).Name /=
1463 (Specification).Project;
1467 (Specification).Name;
1473 Add_It := Proj /= No_Project;
1475 -- If the source is in the
1476 -- project or a project it
1477 -- extends, we may put it in
1481 Add_It := Check_Project (Proj);
1484 -- But we don't, if the ALI file
1485 -- does not correspond to the
1490 F : constant String :=
1495 Add_It := F = ALI_File;
1504 Objects_Htable.Set (Id, True);
1506 (new String'(Object_Path
));
1508 -- Record the ALI file
1510 ALIs
.Append
(new String'(ALI_Path));
1512 -- Find out if for this ALI file,
1513 -- libgnarl or libdecgnat or
1514 -- g-trasym.obj (on OpenVMS) is
1517 Check_Libs (ALI_Path, True);
1520 elsif There_Are_Foreign_Sources then
1522 (new String'(Object_Path
));
1531 Close
(Dir
=> Object_Dir
);
1534 when Directory_Error
=>
1535 Com
.Fail
("cannot find object directory """,
1537 (Data
.Object_Directory
.Display_Name
),
1542 exit when Data
.Extends
= No_Project
;
1544 In_Main_Object_Directory
:= False;
1545 Data
:= In_Tree
.Projects
.Table
(Data
.Extends
);
1548 -- Add the -L and -l switches for the imported Library Project Files,
1549 -- and, if Path Option is supported, the library directory path names
1552 Process_Imported_Libraries
;
1554 -- Link with libgnat and possibly libgnarl
1556 Opts
.Increment_Last
;
1557 Opts
.Table
(Opts
.Last
) := new String'("-L" & Lib_Directory);
1559 -- If Path Option is supported, add libgnat directory path name to
1562 if Path_Option /= null then
1564 Libdir : constant String := Lib_Directory;
1565 GCC_Index : Natural := 0;
1570 -- For shared libraries, add to the Path Option the directory
1571 -- of the shared version of libgcc.
1573 if The_Build_Mode /= Static then
1574 GCC_Index := Index (Libdir, "/lib/");
1576 if GCC_Index = 0 then
1580 Directory_Separator & "lib" & Directory_Separator);
1583 if GCC_Index /= 0 then
1584 Add_Rpath (Libdir (Libdir'First .. GCC_Index + 3));
1590 if Libgnarl_Needed = Yes then
1591 Opts.Increment_Last;
1593 if The_Build_Mode = Static then
1594 Opts.Table (Opts.Last) := new String'("-lgnarl");
1596 Opts
.Table
(Opts
.Last
) := new String'(Shared_Lib ("gnarl"));
1600 if Gtrasymobj_Needed then
1601 Opts.Increment_Last;
1602 Opts.Table (Opts.Last) :=
1603 new String'(Lib_Directory
& "/g-trasym.obj");
1606 if Libdecgnat_Needed
then
1607 Opts
.Increment_Last
;
1609 Opts
.Table
(Opts
.Last
) :=
1610 new String'("-L" & Lib_Directory & "/../declib");
1612 Opts.Increment_Last;
1614 if The_Build_Mode = Static then
1615 Opts.Table (Opts.Last) := new String'("-ldecgnat");
1617 Opts
.Table
(Opts
.Last
) := new String'(Shared_Lib ("decgnat"));
1621 Opts.Increment_Last;
1623 if The_Build_Mode = Static then
1624 Opts.Table (Opts.Last) := new String'("-lgnat");
1626 Opts
.Table
(Opts
.Last
) := new String'(Shared_Lib ("gnat"));
1629 -- If Path Option is supported, add the necessary switch with the
1630 -- content of Rpath. As Rpath contains at least libgnat directory
1631 -- path name, it is guaranteed that it is not null.
1633 if Path_Option /= null then
1634 Opts.Increment_Last;
1635 Opts.Table (Opts.Last) :=
1636 new String'(Path_Option
.all & Rpath
(1 .. Rpath_Last
));
1643 (Argument_List (Objects.Table (1 .. Objects.Last)));
1646 new Argument_List'(Argument_List
(ALIs
.Table
(1 .. ALIs
.Last
)));
1649 new Argument_List
'(Argument_List (Opts.Table (1 .. Opts.Last)));
1651 -- We fail if there are no object to put in the library
1652 -- (Ada or foreign objects).
1654 if Object_Files'Length = 0 then
1655 Com.Fail ("no object files for library """ &
1656 Lib_Filename.all & '"');
1659 if not Opt.Quiet_Output then
1661 Write_Str ("building
");
1662 Write_Str (Ada.Characters.Handling.To_Lower
1663 (Build_Mode_State'Image (The_Build_Mode)));
1664 Write_Str (" library
for project
");
1665 Write_Line (Project_Name);
1667 -- Only output list of object files and ALI files in verbose mode
1669 if Opt.Verbose_Mode then
1672 Write_Line ("object files
:");
1674 for Index in Object_Files'Range loop
1676 Write_Line (Object_Files (Index).all);
1681 if Ali_Files'Length = 0 then
1682 Write_Line ("NO ALI files
");
1685 Write_Line ("ALI files
:");
1687 for Index in Ali_Files'Range loop
1689 Write_Line (Ali_Files (Index).all);
1697 -- We check that all object files are regular files
1701 -- Delete the existing library file, if it exists. Fail if the
1702 -- library file is not writable, or if it is not possible to delete
1706 DLL_Name : aliased String :=
1707 Lib_Dirpath.all & Directory_Separator & DLL_Prefix &
1708 Lib_Filename.all & "." & DLL_Ext;
1710 Archive_Name : aliased String :=
1711 Lib_Dirpath.all & Directory_Separator & "lib
" &
1712 Lib_Filename.all & "." & Archive_Ext;
1714 type Str_Ptr is access all String;
1715 -- This type is necessary to meet the accessibility rules of Ada.
1716 -- It is not possible to use String_Access here.
1718 Full_Lib_Name : Str_Ptr;
1719 -- Designates the full library path name. Either DLL_Name or
1720 -- Archive_Name, depending on the library kind.
1723 pragma Warnings (Off, Success);
1724 -- Used to call Delete_File
1727 if The_Build_Mode = Static then
1728 Full_Lib_Name := Archive_Name'Access;
1730 Full_Lib_Name := DLL_Name'Access;
1733 if Is_Regular_File (Full_Lib_Name.all) then
1734 if Is_Writable_File (Full_Lib_Name.all) then
1735 Delete_File (Full_Lib_Name.all, Success);
1738 if Is_Regular_File (Full_Lib_Name.all) then
1739 Com.Fail ("could
not delete
""" & Full_Lib_Name.all & """");
1744 Argument_Number := 0;
1746 -- If we have a standalone library, gather all the interface ALI.
1747 -- They are passed to Build_Dynamic_Library, where they are used by
1748 -- some platforms (VMS, for example) to decide what symbols should be
1749 -- exported. They are also flagged as Interface when we copy them to
1750 -- the library directory (by Copy_ALI_Files, below).
1753 Data := In_Tree.Projects.Table (For_Project);
1756 Iface : String_List_Id := Data.Lib_Interface_ALIs;
1757 ALI : File_Name_Type;
1760 while Iface /= Nil_String loop
1763 (In_Tree.String_Elements.Table (Iface).Value);
1764 Interface_ALIs.Set (ALI, True);
1766 (In_Tree.String_Elements.Table (Iface).Value);
1767 Add_Argument (Name_Buffer (1 .. Name_Len));
1768 Iface := In_Tree.String_Elements.Table (Iface).Next;
1771 Iface := Data.Lib_Interface_ALIs;
1773 if not Opt.Quiet_Output then
1775 -- Check that the interface set is complete: any unit in the
1776 -- library that is needed by an interface should also be an
1777 -- interface. If it is not the case, output a warning.
1779 while Iface /= Nil_String loop
1782 (In_Tree.String_Elements.Table (Iface).Value);
1784 Iface := In_Tree.String_Elements.Table (Iface).Next;
1791 Current_Dir : constant String := Get_Current_Dir;
1794 Name : String (1 .. 200);
1797 Disregard : Boolean;
1798 pragma Warnings (Off, Disregard);
1800 DLL_Name : aliased constant String :=
1801 Lib_Filename.all & "." & DLL_Ext;
1803 Archive_Name : aliased constant String :=
1804 Lib_Filename.all & "." & Archive_Ext;
1806 Delete : Boolean := False;
1809 -- Clean the library directory: remove any file with the name of
1810 -- the library file and any ALI file of a source of the project.
1814 (In_Tree.Projects.Table (For_Project).Library_Dir.Name);
1815 Change_Dir (Name_Buffer (1 .. Name_Len));
1820 ("unable to
access library directory
""",
1821 Name_Buffer (1 .. Name_Len),
1828 Read (Dir, Name, Last);
1832 Filename : constant String := Name (1 .. Last);
1835 if Is_Regular_File (Filename) then
1836 Canonical_Case_File_Name (Name (1 .. Last));
1839 if (The_Build_Mode = Static and then
1840 Name (1 .. Last) = Archive_Name)
1842 ((The_Build_Mode = Dynamic or else
1843 The_Build_Mode = Relocatable)
1845 Name (1 .. Last) = DLL_Name)
1850 and then Name (Last - 3 .. Last) = ".ali
"
1856 -- Compare with ALI file names of the project
1859 1 .. Unit_Table.Last (In_Tree.Units)
1861 Unit := In_Tree.Units.Table (Index);
1863 if Unit.File_Names (Body_Part).Project /=
1866 if Ultimate_Extension_Of
1867 (Unit.File_Names (Body_Part).Project,
1868 In_Tree) = For_Project
1871 (Unit.File_Names (Body_Part).Name);
1872 Name_Len := Name_Len -
1874 (Name (1 .. Name_Len))'Length;
1875 if Name_Buffer (1 .. Name_Len) =
1876 Name (1 .. Last - 4)
1883 elsif Ultimate_Extension_Of
1884 (Unit.File_Names (Specification).Project,
1885 In_Tree) = For_Project
1888 (Unit.File_Names (Specification).Name);
1892 (Name (1 .. Name_Len))'Length;
1894 if Name_Buffer (1 .. Name_Len) =
1895 Name (1 .. Last - 4)
1906 Set_Writable (Filename);
1907 Delete_File (Filename, Disregard);
1915 Change_Dir (Current_Dir);
1918 -- Call procedure to build the library, depending on the build mode
1920 case The_Build_Mode is
1921 when Dynamic | Relocatable =>
1922 Build_Dynamic_Library
1923 (Ofiles => Object_Files.all,
1924 Options => Options.all,
1925 Interfaces => Arguments (1 .. Argument_Number),
1926 Lib_Filename => Lib_Filename.all,
1927 Lib_Dir => Lib_Dirpath.all,
1928 Symbol_Data => Data.Symbol_Data,
1929 Driver_Name => Driver_Name,
1930 Lib_Version => Lib_Version.all,
1931 Auto_Init => Data.Lib_Auto_Init);
1943 -- We need to copy the ALI files from the object directory to the
1944 -- library ALI directory, so that the linker find them there, and
1945 -- does not need to look in the object directory where it would also
1946 -- find the object files; and we don't want that: we want the linker
1947 -- to use the library.
1949 -- Copy the ALI files and make the copies read-only. For interfaces,
1950 -- mark the copies as interfaces.
1953 (Files => Ali_Files.all,
1954 To => In_Tree.Projects.Table
1955 (For_Project).Library_ALI_Dir.Name,
1956 Interfaces => Arguments (1 .. Argument_Number));
1958 -- Copy interface sources if Library_Src_Dir specified
1961 and then In_Tree.Projects.Table
1962 (For_Project).Library_Src_Dir /= No_Path_Information
1964 -- Clean the interface copy directory: remove any source that
1965 -- could be a source of the project.
1969 (In_Tree.Projects.Table (For_Project).Library_Src_Dir.Name);
1970 Change_Dir (Name_Buffer (1 .. Name_Len));
1975 ("unable to
access library source copy directory
""",
1976 Name_Buffer (1 .. Name_Len),
1982 Delete : Boolean := False;
1985 Name : String (1 .. 200);
1988 Disregard : Boolean;
1989 pragma Warnings (Off, Disregard);
1995 Read (Dir, Name, Last);
1998 if Is_Regular_File (Name (1 .. Last)) then
1999 Canonical_Case_File_Name (Name (1 .. Last));
2002 -- Compare with source file names of the project
2004 for Index in 1 .. Unit_Table.Last (In_Tree.Units) loop
2005 Unit := In_Tree.Units.Table (Index);
2007 if Ultimate_Extension_Of
2008 (Unit.File_Names (Body_Part).Project, In_Tree) =
2012 (Unit.File_Names (Body_Part).Name) =
2019 if Ultimate_Extension_Of
2020 (Unit.File_Names (Specification).Project, In_Tree) =
2024 (Unit.File_Names (Specification).Name) =
2034 Set_Writable (Name (1 .. Last));
2035 Delete_File (Name (1 .. Last), Disregard);
2042 Copy_Interface_Sources
2043 (For_Project => For_Project,
2045 Interfaces => Arguments (1 .. Argument_Number),
2046 To_Dir => In_Tree.Projects.Table
2047 (For_Project).Library_Src_Dir.Display_Name);
2051 -- Reset the current working directory to its previous value
2053 Change_Dir (Current_Dir);
2060 procedure Check (Filename : String) is
2062 if not Is_Regular_File (Filename) then
2063 Com.Fail (Filename, " not found
.");
2071 procedure Check_Context is
2073 -- Check that each object file exists
2075 for F in Object_Files'Range loop
2076 Check (Object_Files (F).all);
2084 procedure Check_Library
2085 (For_Project : Project_Id; In_Tree : Project_Tree_Ref)
2087 Data : constant Project_Data :=
2088 In_Tree.Projects.Table (For_Project);
2089 Lib_TS : Time_Stamp_Type;
2090 Current : constant Dir_Name_Str := Get_Current_Dir;
2093 -- No need to build the library if there is no object directory,
2094 -- hence no object files to build the library.
2096 if Data.Library then
2098 Lib_Name : constant File_Name_Type :=
2099 Library_File_Name_For (For_Project, In_Tree);
2101 Change_Dir (Get_Name_String (Data.Library_Dir.Name));
2102 Lib_TS := File_Stamp (Lib_Name);
2103 In_Tree.Projects.Table (For_Project).Library_TS := Lib_TS;
2106 if not Data.Externally_Built
2107 and then not Data.Need_To_Build_Lib
2108 and then Data.Object_Directory /= No_Path_Information
2111 Obj_TS : Time_Stamp_Type;
2112 Object_Dir : Dir_Type;
2115 if OpenVMS_On_Target then
2116 B_Start := new String'("b__
");
2119 -- If the library file does not exist, then the time stamp will
2120 -- be Empty_Time_Stamp, earlier than any other time stamp.
2122 Change_Dir (Get_Name_String (Data.Object_Directory.Name));
2123 Open (Dir => Object_Dir, Dir_Name => ".");
2125 -- For all entries in the object directory
2128 Read (Object_Dir, Name_Buffer, Name_Len);
2129 exit when Name_Len = 0;
2131 -- Check if it is an object file, but ignore any binder
2134 if Is_Obj (Name_Buffer (1 .. Name_Len))
2135 and then Name_Buffer (1 .. B_Start'Length) /= B_Start.all
2137 -- Get the object file time stamp
2139 Obj_TS := File_Stamp (File_Name_Type'(Name_Find));
2141 -- If library file time stamp is earlier, set
2142 -- Need_To_Build_Lib and return. String comparison is
2143 -- used, otherwise time stamps may be too close and the
2144 -- comparison would return True, which would trigger
2145 -- an unnecessary rebuild of the library.
2147 if String (Lib_TS) < String (Obj_TS) then
2149 -- Library must be rebuilt
2151 In_Tree.Projects.Table
2152 (For_Project).Need_To_Build_Lib := True;
2162 Change_Dir (Current);
2166 ----------------------------
2167 -- Copy_Interface_Sources --
2168 ----------------------------
2170 procedure Copy_Interface_Sources
2171 (For_Project : Project_Id;
2172 In_Tree : Project_Tree_Ref;
2173 Interfaces : Argument_List;
2174 To_Dir : Path_Name_Type)
2176 Current : constant Dir_Name_Str := Get_Current_Dir;
2177 -- The current directory, where to return to at the end
2179 Target : constant Dir_Name_Str := Get_Name_String (To_Dir);
2180 -- The directory where to copy sources
2182 Text : Text_Buffer_Ptr;
2183 The_ALI : ALI.ALI_Id;
2184 Lib_File : File_Name_Type;
2186 First_Unit : ALI.Unit_Id;
2187 Second_Unit : ALI.Unit_Id;
2191 Copy_Subunits : Boolean := False;
2192 -- When True, indicates that subunits, if any, need to be copied too
2194 procedure Copy (File_Name : File_Name_Type);
2195 -- Copy one source of the project to the target directory
2197 function Is_Same_Or_Extension
2198 (Extending : Project_Id;
2199 Extended : Project_Id) return Boolean;
2200 -- Return True if project Extending is equal to or extends project
2207 procedure Copy (File_Name : File_Name_Type) is
2209 pragma Warnings (Off, Success);
2213 for Index in Unit_Table.First ..
2214 Unit_Table.Last (In_Tree.Units)
2216 Data := In_Tree.Units.Table (Index);
2218 -- Find and copy the immediate or inherited source
2220 for J in Data.File_Names'Range loop
2221 if Is_Same_Or_Extension
2222 (For_Project, Data.File_Names (J).Project)
2223 and then Data.File_Names (J).Name = File_Name
2226 (Get_Name_String (Data.File_Names (J).Path.Name),
2230 Preserve => Preserve);
2237 --------------------------
2238 -- Is_Same_Or_Extension --
2239 --------------------------
2241 function Is_Same_Or_Extension
2242 (Extending : Project_Id;
2243 Extended : Project_Id) return Boolean
2249 while Ext /= No_Project loop
2250 if Ext = Extended then
2254 Ext := In_Tree.Projects.Table (Ext).Extends;
2258 end Is_Same_Or_Extension;
2260 -- Start of processing for Copy_Interface_Sources
2263 -- Change the working directory to the object directory
2267 (In_Tree.Projects.Table (For_Project).Object_Directory.Name));
2269 for Index in Interfaces'Range loop
2271 -- First, load the ALI file
2274 Add_Str_To_Name_Buffer (Interfaces (Index).all);
2275 Lib_File := Name_Find;
2276 Text := Read_Library_Info (Lib_File);
2277 The_ALI := Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
2280 Second_Unit := No_Unit_Id;
2281 First_Unit := ALI.ALIs.Table (The_ALI).First_Unit;
2282 Copy_Subunits := True;
2284 -- If there is both a spec and a body, check if they are both needed
2286 if ALI.Units.Table (First_Unit).Utype = Is_Body then
2287 Second_Unit := ALI.ALIs.Table (The_ALI).Last_Unit;
2289 -- If the body is not needed, then reset First_Unit
2291 if not ALI.Units.Table (Second_Unit).Body_Needed_For_SAL then
2292 First_Unit := No_Unit_Id;
2293 Copy_Subunits := False;
2296 elsif ALI.Units.Table (First_Unit).Utype = Is_Spec_Only then
2297 Copy_Subunits := False;
2300 -- Copy the file(s) that need to be copied
2302 if First_Unit /= No_Unit_Id then
2303 Copy (File_Name => ALI.Units.Table (First_Unit).Sfile);
2306 if Second_Unit /= No_Unit_Id then
2307 Copy (File_Name => ALI.Units.Table (Second_Unit).Sfile);
2310 -- Copy all the separates, if any
2312 if Copy_Subunits then
2313 for Dep in ALI.ALIs.Table (The_ALI).First_Sdep ..
2314 ALI.ALIs.Table (The_ALI).Last_Sdep
2316 if Sdep.Table (Dep).Subunit_Name /= No_Name then
2317 Copy (File_Name => Sdep.Table (Dep).Sfile);
2323 -- Restore the initial working directory
2325 Change_Dir (Current);
2326 end Copy_Interface_Sources;
2332 procedure Display (Executable : String) is
2334 if not Opt.Quiet_Output then
2335 Write_Str (Executable);
2337 for Index in 1 .. Argument_Number loop
2339 Write_Str (Arguments (Index).all);
2350 function Index (S, Pattern : String) return Natural is
2351 Len : constant Natural := Pattern'Length;
2354 for J in reverse S'First .. S'Last - Len + 1 loop
2355 if Pattern = S (J .. J + Len - 1) then
2363 -------------------------
2364 -- Process_Binder_File --
2365 -------------------------
2367 procedure Process_Binder_File (Name : String) is
2369 -- Binder file's descriptor
2371 Read_Mode : constant String := "r
" & ASCII.NUL;
2374 Status : Interfaces.C_Streams.int;
2375 pragma Unreferenced (Status);
2378 Begin_Info : constant String := "-- BEGIN Object file/option list";
2379 End_Info
: constant String := "-- END Object file/option list ";
2381 Next_Line
: String (1 .. 1000);
2382 -- Current line value
2383 -- Where does this odd constant 1000 come from, looks suspicious ???
2386 -- End of line slice (the slice does not contain the line terminator)
2388 procedure Get_Next_Line
;
2389 -- Read the next line from the binder file without the line terminator
2395 procedure Get_Next_Line
is
2399 Fchars
:= fgets
(Next_Line
'Address, Next_Line
'Length, Fd
);
2401 if Fchars
= System
.Null_Address
then
2402 Fail
("Error reading binder output");
2406 while Nlast
<= Next_Line
'Last
2407 and then Next_Line
(Nlast
) /= ASCII
.LF
2408 and then Next_Line
(Nlast
) /= ASCII
.CR
2416 -- Start of processing for Process_Binder_File
2419 Fd
:= fopen
(Name
'Address, Read_Mode
'Address);
2421 if Fd
= NULL_Stream
then
2422 Fail
("Failed to open binder output");
2425 -- Skip up to the Begin Info line
2429 exit when Next_Line
(1 .. Nlast
) = Begin_Info
;
2432 -- Find the first switch
2437 exit when Next_Line
(1 .. Nlast
) = End_Info
;
2439 -- As the binder generated file is in Ada, remove the first eight
2440 -- characters " -- ".
2442 Next_Line
(1 .. Nlast
- 8) := Next_Line
(9 .. Nlast
);
2445 -- Stop when the first switch is found
2447 exit when Next_Line
(1) = '-';
2450 if Next_Line
(1 .. Nlast
) /= End_Info
then
2452 -- Ignore -static and -shared, since -shared will be used
2455 -- Ignore -lgnat, -lgnarl and -ldecgnat as they will be added
2456 -- later, because they are also needed for non Stand-Alone shared
2459 -- Also ignore the shared libraries which are :
2461 -- UNIX / Windows VMS
2462 -- -lgnat-<version> -lgnat_<version> (7 + version'length chars)
2463 -- -lgnarl-<version> -lgnarl_<version> (8 + version'length chars)
2465 if Next_Line
(1 .. Nlast
) /= "-static" and then
2466 Next_Line
(1 .. Nlast
) /= "-shared" and then
2467 Next_Line
(1 .. Nlast
) /= "-ldecgnat" and then
2468 Next_Line
(1 .. Nlast
) /= "-lgnarl" and then
2469 Next_Line
(1 .. Nlast
) /= "-lgnat" and then
2471 (1 .. Natural'Min (Nlast
, 10 + Library_Version
'Length)) /=
2472 Shared_Lib
("decgnat") and then
2474 (1 .. Natural'Min (Nlast
, 8 + Library_Version
'Length)) /=
2475 Shared_Lib
("gnarl") and then
2477 (1 .. Natural'Min (Nlast
, 7 + Library_Version
'Length)) /=
2480 if Next_Line
(1) /= '-' then
2482 -- This is not an option, should we add it?
2484 if Add_Object_Files
then
2485 Opts
.Increment_Last
;
2486 Opts
.Table
(Opts
.Last
) :=
2487 new String'(Next_Line (1 .. Nlast));
2491 -- Add all other options
2493 Opts.Increment_Last;
2494 Opts.Table (Opts.Last) :=
2495 new String'(Next_Line
(1 .. Nlast
));
2499 -- Next option, if any
2502 exit when Next_Line
(1 .. Nlast
) = End_Info
;
2504 -- Remove first eight characters " -- "
2506 Next_Line
(1 .. Nlast
- 8) := Next_Line
(9 .. Nlast
);
2511 Status
:= fclose
(Fd
);
2513 -- Is it really right to ignore any close error ???
2515 end Process_Binder_File
;
2521 procedure Reset_Tables
is
2524 Objects_Htable
.Reset
;
2527 Processed_Projects
.Reset
;
2531 ---------------------------
2532 -- SALs_Use_Constructors --
2533 ---------------------------
2535 function SALs_Use_Constructors
return Boolean is
2536 function C_SALs_Init_Using_Constructors
return Integer;
2537 pragma Import
(C
, C_SALs_Init_Using_Constructors
,
2538 "__gnat_sals_init_using_constructors");
2540 return C_SALs_Init_Using_Constructors
/= 0;
2541 end SALs_Use_Constructors
;
2543 ---------------------------
2544 -- Ultimate_Extension_Of --
2545 ---------------------------
2547 function Ultimate_Extension_Of
2548 (Project
: Project_Id
;
2549 In_Tree
: Project_Tree_Ref
) return Project_Id
2551 Result
: Project_Id
:= Project
;
2552 Data
: Project_Data
;
2555 if Project
/= No_Project
then
2557 Data
:= In_Tree
.Projects
.Table
(Result
);
2558 exit when Data
.Extended_By
= No_Project
;
2559 Result
:= Data
.Extended_By
;
2564 end Ultimate_Extension_Of
;