1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2010, 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.
236 procedure Add_Argument (S : String) is
238 if Argument_Number = Arguments'Last then
240 New_Args : constant String_List_Access :=
241 new String_List (1 .. 2 * Arguments'Last);
244 -- Copy the String_Accesses and set them to null in Arguments
245 -- so that they will not be deallocated by the call to
248 New_Args (Arguments'Range) := Arguments.all;
249 Arguments.all := (others => null);
251 Arguments := New_Args;
255 Argument_Number := Argument_Number + 1;
256 Arguments (Argument_Number) := new String'(S
);
263 function ALI_File_Name
(Source
: String) return String is
265 -- If the source name has an extension, then replace it with
268 for Index
in reverse Source
'First + 1 .. Source
'Last loop
269 if Source
(Index
) = '.' then
270 return Source
(Source
'First .. Index
- 1) & ALI_Suffix
;
274 -- If there is no dot, or if it is the first character, just add the
277 return Source
& ALI_Suffix
;
284 procedure Build_Library
285 (For_Project
: Project_Id
;
286 In_Tree
: Project_Tree_Ref
;
288 Gnatbind_Path
: String_Access
;
290 Gcc_Path
: String_Access
;
291 Bind
: Boolean := True;
292 Link
: Boolean := True)
294 Maximum_Size
: Integer;
295 pragma Import
(C
, Maximum_Size
, "__gnat_link_max");
296 -- Maximum number of bytes to put in an invocation of the
300 -- The number of bytes for the invocation of the gnatbind
302 Warning_For_Library
: Boolean := False;
303 -- Set to True for the first warning about a unit missing from the
306 Current_Proj
: Project_Id
;
308 Libgnarl_Needed
: Yes_No_Unknown
:= For_Project
.Libgnarl_Needed
;
309 -- Set to True if library needs to be linked with libgnarl
311 Libdecgnat_Needed
: Boolean := False;
312 -- On OpenVMS, set to True if library needs to be linked with libdecgnat
314 Gtrasymobj_Needed
: Boolean := False;
315 -- On OpenVMS, set to True if library needs to be linked with
318 Object_Directory_Path
: constant String :=
320 (For_Project
.Object_Directory
.Display_Name
);
322 Standalone
: constant Boolean := For_Project
.Standalone_Library
;
324 Project_Name
: constant String := Get_Name_String
(For_Project
.Name
);
326 Current_Dir
: constant String := Get_Current_Dir
;
328 Lib_Filename
: String_Access
;
329 Lib_Dirpath
: String_Access
;
330 Lib_Version
: String_Access
:= new String'("");
332 The_Build_Mode : Build_Mode_State := None;
334 Success : Boolean := False;
336 Library_Options : Variable_Value := Nil_Variable_Value;
338 Driver_Name : Name_Id := No_Name;
340 In_Main_Object_Directory : Boolean := True;
342 Foreign_Sources : Boolean;
344 Rpath : String_Access := null;
345 -- Allocated only if Path Option is supported
347 Rpath_Last : Natural := 0;
348 -- Index of last valid character of Rpath
350 Initial_Rpath_Length : constant := 200;
351 -- Initial size of Rpath, when first allocated
353 Path_Option : String_Access := Linker_Library_Path_Option;
354 -- If null, Path Option is not supported.
355 -- Not a constant so that it can be deallocated.
357 First_ALI : File_Name_Type := No_File;
358 -- Store the ALI file name of a source of the library (the first found)
360 procedure Add_ALI_For (Source : File_Name_Type);
361 -- Add the name of the ALI file corresponding to Source to the
364 procedure Add_Rpath (Path : String);
365 -- Add a path name to Rpath
367 function Check_Project (P : Project_Id) return Boolean;
368 -- Returns True if P is For_Project or a project extended by For_Project
370 procedure Check_Libs (ALI_File : String; Main_Project : Boolean);
371 -- Set Libgnarl_Needed if the ALI_File indicates that there is a need
372 -- to link with -lgnarl (this is the case when there is a dependency
373 -- on s-osinte.ads). On OpenVMS, set Libdecgnat_Needed if the ALI file
374 -- indicates that there is a need to link with -ldecgnat (this is the
375 -- case when there is a dependency on dec.ads), and set
376 -- Gtrasymobj_Needed if there is a dependency on g-trasym.ads.
378 procedure Process (The_ALI : File_Name_Type);
379 -- Check if the closure of a library unit which is or should be in the
380 -- interface set is also in the interface set. Issue a warning for each
381 -- missing library unit.
383 procedure Process_Imported_Libraries;
384 -- Add the -L and -l switches for the imported Library Project Files,
385 -- and, if Path Option is supported, the library directory path names
392 procedure Add_ALI_For (Source : File_Name_Type) is
393 ALI : constant String := ALI_File_Name (Get_Name_String (Source));
394 ALI_Id : File_Name_Type;
402 Add_Str_To_Name_Buffer (S => ALI);
405 -- Add the ALI file name to the library ALIs
408 Library_ALIs.Set (ALI_Id, True);
411 -- Set First_ALI, if not already done
413 if First_ALI = No_File then
422 procedure Add_Rpath (Path : String) is
432 New_Rpath : constant String_Access :=
433 new String (1 .. 2 * Rpath'Length);
435 New_Rpath (1 .. Rpath_Last) := Rpath (1 .. Rpath_Last);
440 -- Start of processing for Add_Rpath
443 -- If first path, allocate initial Rpath
446 Rpath := new String (1 .. Initial_Rpath_Length);
450 -- Otherwise, add a path separator between two path names
452 if Rpath_Last = Rpath'Last then
456 Rpath_Last := Rpath_Last + 1;
457 Rpath (Rpath_Last) := Path_Separator;
460 -- Increase Rpath size until it is large enough
462 while Rpath_Last + Path'Length > Rpath'Last loop
468 Rpath (Rpath_Last + 1 .. Rpath_Last + Path'Length) := Path;
469 Rpath_Last := Rpath_Last + Path'Length;
476 function Check_Project (P : Project_Id) return Boolean is
478 if P = For_Project then
481 elsif P /= No_Project then
487 while Proj.Extends /= No_Project loop
488 if P = Proj.Extends then
492 Proj := Proj.Extends;
504 procedure Check_Libs (ALI_File : String; Main_Project : Boolean) is
505 Lib_File : File_Name_Type;
506 Text : Text_Buffer_Ptr;
510 if Libgnarl_Needed /= Yes
513 and then OpenVMS_On_Target
514 and then ((not Libdecgnat_Needed) or (not Gtrasymobj_Needed)))
518 Name_Len := ALI_File'Length;
519 Name_Buffer (1 .. Name_Len) := ALI_File;
520 Lib_File := Name_Find;
521 Text := Read_Library_Info (Lib_File, True);
531 -- Look for s-osinte.ads in the dependencies
533 for Index in ALI.ALIs.Table (Id).First_Sdep ..
534 ALI.ALIs.Table (Id).Last_Sdep
536 if ALI.Sdep.Table (Index).Sfile = S_Osinte_Ads then
537 Libgnarl_Needed := Yes;
540 For_Project.Libgnarl_Needed := Yes;
545 elsif OpenVMS_On_Target then
546 if ALI.Sdep.Table (Index).Sfile = S_Dec_Ads then
547 Libdecgnat_Needed := True;
549 elsif ALI.Sdep.Table (Index).Sfile = G_Trasym_Ads then
550 Gtrasymobj_Needed := True;
561 procedure Process (The_ALI : File_Name_Type) is
562 Text : Text_Buffer_Ptr;
564 First_Unit : ALI.Unit_Id;
565 Last_Unit : ALI.Unit_Id;
566 Unit_Data : Unit_Record;
567 Afile : File_Name_Type;
570 -- Nothing to do if the ALI file has already been processed.
571 -- This happens if an interface imports another interface.
573 if not Processed_ALIs.Get (The_ALI) then
574 Processed_ALIs.Set (The_ALI, True);
575 Text := Read_Library_Info (The_ALI);
586 if Idread /= No_ALI_Id then
587 First_Unit := ALI.ALIs.Table (Idread).First_Unit;
588 Last_Unit := ALI.ALIs.Table (Idread).Last_Unit;
590 -- Process both unit (spec and body) if the body is needed
591 -- by the spec (inline or generic). Otherwise, just process
594 if First_Unit /= Last_Unit and then
595 not ALI.Units.Table (Last_Unit).Body_Needed_For_SAL
597 First_Unit := Last_Unit;
600 for Unit in First_Unit .. Last_Unit loop
601 Unit_Data := ALI.Units.Table (Unit);
603 -- Check if each withed unit which is in the library is
604 -- also in the interface set, if it has not yet been
607 for W in Unit_Data.First_With .. Unit_Data.Last_With loop
608 Afile := Withs.Table (W).Afile;
610 if Afile /= No_File and then Library_ALIs.Get (Afile)
611 and then not Processed_ALIs.Get (Afile)
613 if not Interface_ALIs.Get (Afile) then
614 if not Warning_For_Library then
615 Write_Str ("Warning: In library project """);
616 Get_Name_String (Current_Proj.Name);
617 To_Mixed (Name_Buffer (1 .. Name_Len));
618 Write_Str (Name_Buffer (1 .. Name_Len));
620 Warning_For_Library := True;
623 Write_Str (" Unit """);
624 Get_Name_String (Withs.Table (W).Uname);
625 To_Mixed (Name_Buffer (1 .. Name_Len - 2));
626 Write_Str (Name_Buffer (1 .. Name_Len - 2));
627 Write_Line (""" is not in the interface set");
628 Write_Str (" but it is needed by ");
630 case Unit_Data.Utype is
632 Write_Str ("the spec of ");
635 Write_Str ("the body of ");
642 Get_Name_String (Unit_Data.Uname);
643 To_Mixed (Name_Buffer (1 .. Name_Len - 2));
644 Write_Str (Name_Buffer (1 .. Name_Len - 2));
648 -- Now, process this unit
659 --------------------------------
660 -- Process_Imported_Libraries --
661 --------------------------------
663 procedure Process_Imported_Libraries is
664 Current : Project_Id;
666 procedure Process_Project (Project : Project_Id);
667 -- Process Project and its imported projects recursively.
668 -- Add any library projects to table Library_Projs.
670 ---------------------
671 -- Process_Project --
672 ---------------------
674 procedure Process_Project (Project : Project_Id) is
675 Imported : Project_List;
678 -- Nothing to do if process has already been processed
680 if not Processed_Projects.Get (Project.Name) then
681 Processed_Projects.Set (Project.Name, True);
683 -- Call Process_Project recursively for any imported project.
684 -- We first process the imported projects to guarantee that
685 -- we have a proper reverse order for the libraries.
687 Imported := Project.Imported_Projects;
688 while Imported /= null loop
689 if Imported.Project /= No_Project then
690 Process_Project (Imported.Project);
693 Imported := Imported.Next;
696 -- If it is a library project, add it to Library_Projs
698 if Project /= For_Project and then Project.Library then
699 Library_Projs.Increment_Last;
700 Library_Projs.Table (Library_Projs.Last) := Project;
702 -- Check if because of this library we need to use libgnarl
704 if Libgnarl_Needed = Unknown then
705 if Project.Libgnarl_Needed = Unknown
706 and then Project.Object_Directory /= No_Path_Information
708 -- Check if libgnarl is needed for this library
711 Object_Dir_Path : constant String :=
713 (Project.Object_Directory.
715 Object_Dir : Dir_Type;
716 Filename : String (1 .. 255);
720 Open (Object_Dir, Object_Dir_Path);
722 -- For all entries in the object directory
725 Read (Object_Dir, Filename, Last);
728 -- Check if it is an object file
730 if Is_Obj (Filename (1 .. Last)) then
732 Object_Path : constant String :=
735 Directory_Separator &
736 Filename (1 .. Last));
737 ALI_File : constant String :=
739 (Object_Path, "ali");
742 if Is_Regular_File (ALI_File) then
744 -- Find out if for this ALI file,
745 -- libgnarl is necessary.
748 (ALI_File, Main_Project => False);
750 if Libgnarl_Needed = Yes then
751 Project.Libgnarl_Needed := Yes;
752 For_Project.Libgnarl_Needed := Yes;
764 if Project.Libgnarl_Needed = Yes then
765 Libgnarl_Needed := Yes;
766 For_Project.Libgnarl_Needed := Yes;
773 -- Start of processing for Process_Imported_Libraries
776 -- Build list of library projects imported directly or indirectly,
777 -- in the reverse order.
779 Process_Project (For_Project);
781 -- Add the -L and -l switches and, if the Rpath option is supported,
782 -- add the directory to the Rpath. As the library projects are in the
783 -- wrong order, process from the last to the first.
785 for Index in reverse 1 .. Library_Projs.Last loop
786 Current := Library_Projs.Table (Index);
788 Get_Name_String (Current.Library_Dir.Display_Name);
790 Opts.Table (Opts.Last) :=
791 new String'("-L" & Name_Buffer
(1 .. Name_Len
));
793 if Path_Option
/= null then
794 Add_Rpath
(Name_Buffer
(1 .. Name_Len
));
798 Opts
.Table
(Opts
.Last
) :=
799 new String'("-l" & Get_Name_String (Current.Library_Name));
801 end Process_Imported_Libraries;
803 -- Start of processing for Build_Library
808 -- Fail if project is not a library project
810 if not For_Project.Library then
811 Com.Fail ("project """ & Project_Name & """ has no library");
814 -- Do not attempt to build the library if it is externally built
816 if For_Project.Externally_Built then
820 -- If this is the first time Build_Library is called, get the Name_Id
821 -- of "s-osinte.ads".
823 if S_Osinte_Ads = No_File then
825 Add_Str_To_Name_Buffer ("s-osinte.ads");
826 S_Osinte_Ads := Name_Find;
829 if S_Dec_Ads = No_File then
831 Add_Str_To_Name_Buffer ("dec.ads");
832 S_Dec_Ads := Name_Find;
835 if G_Trasym_Ads = No_File then
837 Add_Str_To_Name_Buffer ("g-trasym.ads");
838 G_Trasym_Ads := Name_Find;
841 -- We work in the object directory
843 Change_Dir (Object_Directory_Path);
847 -- Call gnatbind only if Bind is True
850 if Gnatbind_Path = null then
851 Com.Fail ("unable to locate " & Gnatbind);
854 if Gcc_Path = null then
855 Com.Fail ("unable to locate " & Gcc);
858 -- Allocate Arguments, if it is the first time we see a standalone
861 if Arguments = No_Argument then
862 Arguments := new String_List (1 .. Initial_Argument_Max);
865 -- Add "-n -o b~<lib>.adb (b__<lib>.adb on VMS) -L<lib>"
867 Argument_Number := 2;
868 Arguments (1) := No_Main;
869 Arguments (2) := Output_Switch;
871 if OpenVMS_On_Target then
872 B_Start := new String'("b__");
877 & Get_Name_String
(For_Project
.Library_Name
) & ".adb");
878 Add_Argument
("-L" & Get_Name_String
(For_Project
.Library_Name
));
880 if For_Project
.Lib_Auto_Init
and then SALs_Use_Constructors
then
881 Add_Argument
(Auto_Initialize
);
884 -- Check if Binder'Default_Switches ("Ada") is defined. If it is,
885 -- add these switches to call gnatbind.
888 Binder_Package
: constant Package_Id
:=
890 (Name
=> Name_Binder
,
891 In_Packages
=> For_Project
.Decl
.Packages
,
895 if Binder_Package
/= No_Package
then
897 Defaults
: constant Array_Element_Id
:=
899 (Name
=> Name_Default_Switches
,
901 In_Tree
.Packages
.Table
902 (Binder_Package
).Decl
.Arrays
,
904 Switches
: Variable_Value
:= Nil_Variable_Value
;
906 Switch
: String_List_Id
:= Nil_String
;
909 if Defaults
/= No_Array_Element
then
914 In_Array
=> Defaults
,
917 if not Switches
.Default
then
918 Switch
:= Switches
.Values
;
920 while Switch
/= Nil_String
loop
923 (In_Tree
.String_Elements
.Table
925 Switch
:= In_Tree
.String_Elements
.
935 -- Get all the ALI files of the project file. We do that even if
936 -- Bind is False, so that First_ALI is set.
943 Interface_ALIs
.Reset
;
944 Processed_ALIs
.Reset
;
946 Unit
:= Units_Htable
.Get_First
(In_Tree
.Units_HT
);
947 while Unit
/= No_Unit_Index
loop
948 if Unit
.File_Names
(Impl
) /= null
949 and then not Unit
.File_Names
(Impl
).Locally_Removed
951 if Check_Project
(Unit
.File_Names
(Impl
).Project
) then
952 if Unit
.File_Names
(Spec
) = null then
954 Src_Ind
: Source_File_Index
;
957 Src_Ind
:= Sinput
.P
.Load_Project_File
959 (Unit
.File_Names
(Impl
).Path
.Name
));
961 -- Add the ALI file only if it is not a subunit
964 Sinput
.P
.Source_File_Is_Subunit
(Src_Ind
)
966 Add_ALI_For
(Unit
.File_Names
(Impl
).File
);
972 Add_ALI_For
(Unit
.File_Names
(Impl
).File
);
977 elsif Unit
.File_Names
(Spec
) /= null
978 and then not Unit
.File_Names
(Spec
).Locally_Removed
979 and then Check_Project
(Unit
.File_Names
(Spec
).Project
)
981 Add_ALI_For
(Unit
.File_Names
(Spec
).File
);
985 Unit
:= Units_Htable
.Get_Next
(In_Tree
.Units_HT
);
989 -- Continue setup and call gnatbind if Bind is True
993 -- Get an eventual --RTS from the ALI file
995 if First_ALI
/= No_File
then
1001 -- Load the ALI file
1003 T
:= Read_Library_Info
(First_ALI
, True);
1008 (First_ALI
, T
, Ignore_ED
=> False, Err
=> False);
1010 if A
/= No_ALI_Id
then
1013 (ALI
.ALIs
.Table
(A
).First_Unit
).First_Arg
..
1015 (ALI
.ALIs
.Table
(A
).First_Unit
).Last_Arg
1017 -- If --RTS found, add switch to call gnatbind
1020 Arg
: String_Ptr
renames Args
.Table
(Index
);
1022 if Arg
'Length >= 6 and then
1023 Arg
(Arg
'First + 2 .. Arg
'First + 5) = "RTS="
1025 Add_Argument
(Arg
.all);
1037 (Project
=> For_Project
,
1039 Including_Libraries
=> True);
1041 -- Display the gnatbind command, if not in quiet output
1046 for J
in 1 .. Argument_Number
loop
1047 Size
:= Size
+ Arguments
(J
)'Length + 1;
1050 -- Invoke gnatbind with the arguments if the size is not too large
1052 if Size
<= Maximum_Size
then
1055 Arguments
(1 .. Argument_Number
),
1059 -- Otherwise create a temporary response file
1062 FD
: File_Descriptor
;
1063 Path
: Path_Name_Type
;
1064 Args
: Argument_List
(1 .. 1);
1065 EOL
: constant String (1 .. 1) := (1 => ASCII
.LF
);
1068 Quotes_Needed
: Boolean;
1069 Last_Char
: Natural;
1073 Tempdir
.Create_Temp_File
(FD
, Path
);
1074 Args
(1) := new String'("@" & Get_Name_String (Path));
1076 for J in 1 .. Argument_Number loop
1078 -- Check if the argument should be quoted
1080 Quotes_Needed := False;
1081 Last_Char := Arguments (J)'Length;
1083 for K in Arguments (J)'Range loop
1084 Ch := Arguments (J) (K);
1086 if Ch = ' ' or else Ch = ASCII.HT or else Ch = '"' then
1087 Quotes_Needed := True;
1092 if Quotes_Needed then
1094 -- Quote the argument, doubling '"'
1097 Arg : String (1 .. Arguments (J)'Length * 2 + 2);
1103 for K in Arguments (J)'Range loop
1104 Ch := Arguments (J) (K);
1105 Last_Char := Last_Char + 1;
1106 Arg (Last_Char) := Ch;
1109 Last_Char := Last_Char + 1;
1110 Arg (Last_Char) := '"';
1114 Last_Char := Last_Char + 1;
1115 Arg (Last_Char) := '"';
1117 Status := Write (FD, Arg'Address, Last_Char);
1123 Arguments (J) (Arguments (J)'First)'Address,
1127 if Status /= Last_Char then
1131 Status := Write (FD, EOL (1)'Address, 1);
1140 -- And invoke gnatbind with this response file
1142 Spawn (Gnatbind_Path.all, Args, Success);
1144 Delete_File (Get_Name_String (Path), Succ);
1153 Com.Fail ("could not bind standalone library "
1154 & Get_Name_String (For_Project.Library_Name));
1158 -- Compile the binder generated file only if Link is true
1165 (Project => For_Project,
1167 Including_Libraries => True);
1169 -- Invoke <gcc> -c b__<lib>.adb
1171 -- Allocate Arguments, if it is the first time we see a standalone
1174 if Arguments = No_Argument then
1175 Arguments := new String_List (1 .. Initial_Argument_Max);
1178 Argument_Number := 1;
1179 Arguments (1) := Compile_Switch;
1181 if OpenVMS_On_Target then
1182 B_Start := new String'("b__");
1187 & Get_Name_String
(For_Project
.Library_Name
) & ".adb");
1189 -- If necessary, add the PIC option
1191 if PIC_Option
/= "" then
1192 Add_Argument
(PIC_Option
);
1195 -- Get the back-end switches and --RTS from the ALI file
1197 if First_ALI
/= No_File
then
1199 T
: Text_Buffer_Ptr
;
1203 -- Load the ALI file
1205 T
:= Read_Library_Info
(First_ALI
, True);
1210 Scan_ALI
(First_ALI
, T
, Ignore_ED
=> False, Err
=> False);
1212 if A
/= No_ALI_Id
then
1215 (ALI
.ALIs
.Table
(A
).First_Unit
).First_Arg
..
1217 (ALI
.ALIs
.Table
(A
).First_Unit
).Last_Arg
1219 -- Do not compile with the front end switches except
1223 Arg
: String_Ptr
renames Args
.Table
(Index
);
1225 if not Is_Front_End_Switch
(Arg
.all)
1227 Arg
(Arg
'First + 2 .. Arg
'First + 5) = "RTS="
1229 Add_Argument
(Arg
.all);
1237 -- Now that all the arguments are set, compile the binder
1242 (Gcc_Path
.all, Arguments
(1 .. Argument_Number
), Success
);
1246 ("could not compile binder generated file for library "
1247 & Get_Name_String
(For_Project
.Library_Name
));
1250 -- Process binder generated file for pragmas Linker_Options
1252 Process_Binder_File
(Arguments
(2).all & ASCII
.NUL
);
1256 -- Build the library only if Link is True
1260 -- If attributes Library_GCC or Linker'Driver were specified, get the
1263 if For_Project
.Config
.Shared_Lib_Driver
/= No_File
then
1264 Driver_Name
:= Name_Id
(For_Project
.Config
.Shared_Lib_Driver
);
1267 -- If attribute Library_Options was specified, add these additional
1270 Library_Options
:= Value_Of
1271 (Name_Library_Options
, For_Project
.Decl
.Attributes
, In_Tree
);
1273 if not Library_Options
.Default
then
1275 Current
: String_List_Id
;
1276 Element
: String_Element
;
1279 Current
:= Library_Options
.Values
;
1280 while Current
/= Nil_String
loop
1281 Element
:= In_Tree
.String_Elements
.Table
(Current
);
1282 Get_Name_String
(Element
.Value
);
1284 if Name_Len
/= 0 then
1285 Opts
.Increment_Last
;
1286 Opts
.Table
(Opts
.Last
) :=
1287 new String'(Name_Buffer (1 .. Name_Len));
1290 Current := Element.Next;
1296 new String'(Get_Name_String
(For_Project
.Library_Dir
.Display_Name
));
1297 Lib_Filename
:= new String'
1298 (Get_Name_String (For_Project.Library_Name));
1300 case For_Project.Library_Kind is
1302 The_Build_Mode := Static;
1305 The_Build_Mode := Dynamic;
1308 The_Build_Mode := Relocatable;
1310 if PIC_Option /= "" then
1311 Opts.Increment_Last;
1312 Opts.Table (Opts.Last) := new String'(PIC_Option
);
1316 -- Get the library version, if any
1318 if For_Project
.Lib_Internal_Name
/= No_Name
then
1320 new String'(Get_Name_String (For_Project.Lib_Internal_Name));
1323 -- Add the objects found in the object directory and the object
1324 -- directories of the extended files, if any, except for generated
1325 -- object files (b~.. or B__..) from extended projects.
1326 -- When there are one or more extended files, only add an object file
1327 -- if no object file with the same name have already been added.
1329 In_Main_Object_Directory := True;
1331 -- For gnatmake, when the project specifies more than just Ada as a
1332 -- language (even if course we could not find any source file for
1333 -- the other languages), we will take all object files found in the
1334 -- object directories. Since we know the project supports at least
1335 -- Ada, we just have to test whether it has at least two languages,
1336 -- and not care about the sources.
1338 Foreign_Sources := For_Project.Languages.Next /= null;
1339 Current_Proj := For_Project;
1341 if Current_Proj.Object_Directory /= No_Path_Information then
1343 -- The following code gets far too indented, I suggest some
1344 -- procedural abstraction here. How about making this declare
1345 -- block a named procedure???
1348 Object_Dir_Path : constant String :=
1350 (Current_Proj.Object_Directory
1353 Object_Dir : Dir_Type;
1354 Filename : String (1 .. 255);
1359 Open (Dir => Object_Dir, Dir_Name => Object_Dir_Path);
1361 -- For all entries in the object directory
1364 Read (Object_Dir, Filename, Last);
1368 -- Check if it is an object file
1370 if Is_Obj (Filename (1 .. Last)) then
1372 Object_Path : constant String :=
1375 & Directory_Separator
1376 & Filename (1 .. Last));
1377 Object_File : constant String :=
1378 Filename (1 .. Last);
1380 C_Filename : String := Object_File;
1383 Canonical_Case_File_Name (C_Filename);
1385 -- If in the object directory of an extended
1386 -- project, do not consider generated object files.
1388 if In_Main_Object_Directory
1391 C_Filename (1 .. B_Start'Length) /= B_Start.all
1394 Add_Str_To_Name_Buffer (C_Filename);
1397 if not Objects_Htable.Get (Id) then
1399 ALI_File : constant String :=
1400 Ext_To (C_Filename, "ali");
1402 ALI_Path : constant String :=
1403 Ext_To (Object_Path, "ali");
1406 Fname : File_Name_Type;
1411 -- The following assignment could use
1419 C_Filename (1 .. B_Start'Length)
1422 if Is_Regular_File (ALI_Path) then
1424 -- If there is an ALI file, check if
1425 -- the object file should be added to
1426 -- the library. If there are foreign
1427 -- sources we put all object files in
1432 Units_Htable.Get_First
1434 while Index /= null loop
1435 if Index.File_Names (Impl) /=
1439 Index.File_Names (Impl)
1442 Index.File_Names (Impl).File;
1444 elsif Index.File_Names (Spec) /=
1448 Index.File_Names (Spec)
1451 Index.File_Names (Spec).File;
1457 Add_It := Proj /= No_Project;
1459 -- If the source is in the
1460 -- project or a project it
1461 -- extends, we may put it in
1465 Add_It := Check_Project (Proj);
1468 -- But we don't, if the ALI file
1469 -- does not correspond to the
1474 F : constant String :=
1479 Add_It := F = ALI_File;
1486 Units_Htable.Get_Next
1492 Objects_Htable.Set (Id, True);
1494 (new String'(Object_Path
));
1496 -- Record the ALI file
1498 ALIs
.Append
(new String'(ALI_Path));
1500 -- Find out if for this ALI file,
1501 -- libgnarl or libdecgnat or
1502 -- g-trasym.obj (on OpenVMS) is
1505 Check_Libs (ALI_Path, True);
1508 elsif Foreign_Sources then
1510 (new String'(Object_Path
));
1519 Close
(Dir
=> Object_Dir
);
1522 when Directory_Error
=>
1523 Com
.Fail
("cannot find object directory """
1525 (Current_Proj
.Object_Directory
.Display_Name
)
1530 exit when Current_Proj
.Extends
= No_Project
;
1532 In_Main_Object_Directory
:= False;
1533 Current_Proj
:= Current_Proj
.Extends
;
1536 -- Add the -L and -l switches for the imported Library Project Files,
1537 -- and, if Path Option is supported, the library directory path names
1540 Process_Imported_Libraries
;
1542 -- Link with libgnat and possibly libgnarl
1544 Opts
.Increment_Last
;
1545 Opts
.Table
(Opts
.Last
) := new String'("-L" & Lib_Directory);
1547 -- If Path Option is supported, add libgnat directory path name to
1550 if Path_Option /= null then
1552 Libdir : constant String := Lib_Directory;
1553 GCC_Index : Natural := 0;
1558 -- For shared libraries, add to the Path Option the directory
1559 -- of the shared version of libgcc.
1561 if The_Build_Mode /= Static then
1562 GCC_Index := Index (Libdir, "/lib/");
1564 if GCC_Index = 0 then
1568 Directory_Separator & "lib" & Directory_Separator);
1571 if GCC_Index /= 0 then
1572 Add_Rpath (Libdir (Libdir'First .. GCC_Index + 3));
1578 if Libgnarl_Needed = Yes then
1579 Opts.Increment_Last;
1581 if The_Build_Mode = Static then
1582 Opts.Table (Opts.Last) := new String'("-lgnarl");
1584 Opts
.Table
(Opts
.Last
) := new String'(Shared_Lib ("gnarl"));
1588 if Gtrasymobj_Needed then
1589 Opts.Increment_Last;
1590 Opts.Table (Opts.Last) :=
1591 new String'(Lib_Directory
& "/g-trasym.obj");
1594 if Libdecgnat_Needed
then
1595 Opts
.Increment_Last
;
1597 Opts
.Table
(Opts
.Last
) :=
1598 new String'("-L" & Lib_Directory & "/../declib");
1600 Opts.Increment_Last;
1602 if The_Build_Mode = Static then
1603 Opts.Table (Opts.Last) := new String'("-ldecgnat");
1605 Opts
.Table
(Opts
.Last
) := new String'(Shared_Lib ("decgnat"));
1609 Opts.Increment_Last;
1611 if The_Build_Mode = Static then
1612 Opts.Table (Opts.Last) := new String'("-lgnat");
1614 Opts
.Table
(Opts
.Last
) := new String'(Shared_Lib ("gnat"));
1617 -- If Path Option is supported, add the necessary switch with the
1618 -- content of Rpath. As Rpath contains at least libgnat directory
1619 -- path name, it is guaranteed that it is not null.
1621 if Path_Option /= null then
1622 Opts.Increment_Last;
1623 Opts.Table (Opts.Last) :=
1624 new String'(Path_Option
.all & Rpath
(1 .. Rpath_Last
));
1631 (Argument_List (Objects.Table (1 .. Objects.Last)));
1634 new Argument_List'(Argument_List
(ALIs
.Table
(1 .. ALIs
.Last
)));
1637 new Argument_List
'(Argument_List (Opts.Table (1 .. Opts.Last)));
1639 -- We fail if there are no object to put in the library
1640 -- (Ada or foreign objects).
1642 if Object_Files'Length = 0 then
1643 Com.Fail ("no object files for library """ &
1644 Lib_Filename.all & '"');
1647 if not Opt.Quiet_Output then
1649 Write_Str ("building
");
1650 Write_Str (Ada.Characters.Handling.To_Lower
1651 (Build_Mode_State'Image (The_Build_Mode)));
1652 Write_Str (" library
for project
");
1653 Write_Line (Project_Name);
1655 -- Only output list of object files and ALI files in verbose mode
1657 if Opt.Verbose_Mode then
1660 Write_Line ("object files
:");
1662 for Index in Object_Files'Range loop
1664 Write_Line (Object_Files (Index).all);
1669 if Ali_Files'Length = 0 then
1670 Write_Line ("NO ALI files
");
1673 Write_Line ("ALI files
:");
1675 for Index in Ali_Files'Range loop
1677 Write_Line (Ali_Files (Index).all);
1685 -- We check that all object files are regular files
1689 -- Delete the existing library file, if it exists. Fail if the
1690 -- library file is not writable, or if it is not possible to delete
1694 DLL_Name : aliased String :=
1695 Lib_Dirpath.all & Directory_Separator & DLL_Prefix &
1696 Lib_Filename.all & "." & DLL_Ext;
1698 Archive_Name : aliased String :=
1699 Lib_Dirpath.all & Directory_Separator & "lib
" &
1700 Lib_Filename.all & "." & Archive_Ext;
1702 type Str_Ptr is access all String;
1703 -- This type is necessary to meet the accessibility rules of Ada.
1704 -- It is not possible to use String_Access here.
1706 Full_Lib_Name : Str_Ptr;
1707 -- Designates the full library path name. Either DLL_Name or
1708 -- Archive_Name, depending on the library kind.
1711 pragma Warnings (Off, Success);
1712 -- Used to call Delete_File
1715 if The_Build_Mode = Static then
1716 Full_Lib_Name := Archive_Name'Access;
1718 Full_Lib_Name := DLL_Name'Access;
1721 if Is_Regular_File (Full_Lib_Name.all) then
1722 if Is_Writable_File (Full_Lib_Name.all) then
1723 Delete_File (Full_Lib_Name.all, Success);
1726 if Is_Regular_File (Full_Lib_Name.all) then
1727 Com.Fail ("could
not delete
""" & Full_Lib_Name.all & """");
1732 Argument_Number := 0;
1734 -- If we have a standalone library, gather all the interface ALI.
1735 -- They are passed to Build_Dynamic_Library, where they are used by
1736 -- some platforms (VMS, for example) to decide what symbols should be
1737 -- exported. They are also flagged as Interface when we copy them to
1738 -- the library directory (by Copy_ALI_Files, below).
1741 Current_Proj := For_Project;
1744 Iface : String_List_Id := For_Project.Lib_Interface_ALIs;
1745 ALI : File_Name_Type;
1748 while Iface /= Nil_String loop
1751 (In_Tree.String_Elements.Table (Iface).Value);
1752 Interface_ALIs.Set (ALI, True);
1754 (In_Tree.String_Elements.Table (Iface).Value);
1755 Add_Argument (Name_Buffer (1 .. Name_Len));
1756 Iface := In_Tree.String_Elements.Table (Iface).Next;
1759 Iface := For_Project.Lib_Interface_ALIs;
1761 if not Opt.Quiet_Output then
1763 -- Check that the interface set is complete: any unit in the
1764 -- library that is needed by an interface should also be an
1765 -- interface. If it is not the case, output a warning.
1767 while Iface /= Nil_String loop
1770 (In_Tree.String_Elements.Table (Iface).Value);
1772 Iface := In_Tree.String_Elements.Table (Iface).Next;
1779 Current_Dir : constant String := Get_Current_Dir;
1782 Name : String (1 .. 200);
1785 Disregard : Boolean;
1786 pragma Warnings (Off, Disregard);
1788 DLL_Name : aliased constant String :=
1789 Lib_Filename.all & "." & DLL_Ext;
1791 Archive_Name : aliased constant String :=
1792 Lib_Filename.all & "." & Archive_Ext;
1794 Delete : Boolean := False;
1797 -- Clean the library directory: remove any file with the name of
1798 -- the library file and any ALI file of a source of the project.
1801 Get_Name_String (For_Project.Library_Dir.Display_Name);
1802 Change_Dir (Name_Buffer (1 .. Name_Len));
1807 ("unable to
access library directory
"""
1808 & Name_Buffer (1 .. Name_Len)
1815 Read (Dir, Name, Last);
1819 Filename : constant String := Name (1 .. Last);
1822 if Is_Regular_File (Filename) then
1823 Canonical_Case_File_Name (Name (1 .. Last));
1826 if (The_Build_Mode = Static
1827 and then Name (1 .. Last) = Archive_Name)
1829 ((The_Build_Mode = Dynamic
1831 The_Build_Mode = Relocatable)
1832 and then Name (1 .. Last) = DLL_Name)
1837 and then Name (Last - 3 .. Last) = ".ali
"
1843 -- Compare with ALI file names of the project
1845 Unit := Units_Htable.Get_First (In_Tree.Units_HT);
1846 while Unit /= No_Unit_Index loop
1847 if Unit.File_Names (Impl) /= null
1848 and then Unit.File_Names (Impl).Project /=
1851 if Ultimate_Extending_Project_Of
1852 (Unit.File_Names (Impl).Project) =
1856 (Unit.File_Names (Impl).File);
1860 (Name (1 .. Name_Len))'Length;
1862 if Name_Buffer (1 .. Name_Len) =
1863 Name (1 .. Last - 4)
1870 elsif Unit.File_Names (Spec) /= null
1871 and then Ultimate_Extending_Project_Of
1872 (Unit.File_Names (Spec).Project) =
1875 Get_Name_String (Unit.File_Names (Spec).File);
1878 File_Extension (Name (1 .. Last))'Length;
1880 if Name_Buffer (1 .. Name_Len) =
1881 Name (1 .. Last - 4)
1888 Unit := Units_Htable.Get_Next (In_Tree.Units_HT);
1894 Set_Writable (Filename);
1895 Delete_File (Filename, Disregard);
1903 Change_Dir (Current_Dir);
1906 -- Call procedure to build the library, depending on the build mode
1908 case The_Build_Mode is
1909 when Dynamic | Relocatable =>
1910 Build_Dynamic_Library
1911 (Ofiles => Object_Files.all,
1912 Options => Options.all,
1913 Interfaces => Arguments (1 .. Argument_Number),
1914 Lib_Filename => Lib_Filename.all,
1915 Lib_Dir => Lib_Dirpath.all,
1916 Symbol_Data => Current_Proj.Symbol_Data,
1917 Driver_Name => Driver_Name,
1918 Lib_Version => Lib_Version.all,
1919 Auto_Init => Current_Proj.Lib_Auto_Init);
1931 -- We need to copy the ALI files from the object directory to the
1932 -- library ALI directory, so that the linker find them there, and
1933 -- does not need to look in the object directory where it would also
1934 -- find the object files; and we don't want that: we want the linker
1935 -- to use the library.
1937 -- Copy the ALI files and make the copies read-only. For interfaces,
1938 -- mark the copies as interfaces.
1941 (Files => Ali_Files.all,
1942 To => For_Project.Library_ALI_Dir.Display_Name,
1943 Interfaces => Arguments (1 .. Argument_Number));
1945 -- Copy interface sources if Library_Src_Dir specified
1948 and then For_Project.Library_Src_Dir /= No_Path_Information
1950 -- Clean the interface copy directory: remove any source that
1951 -- could be a source of the project.
1954 Get_Name_String (For_Project.Library_Src_Dir.Display_Name);
1955 Change_Dir (Name_Buffer (1 .. Name_Len));
1960 ("unable to
access library source copy directory
"""
1961 & Name_Buffer (1 .. Name_Len)
1967 Delete : Boolean := False;
1970 Name : String (1 .. 200);
1973 Disregard : Boolean;
1974 pragma Warnings (Off, Disregard);
1980 Read (Dir, Name, Last);
1983 if Is_Regular_File (Name (1 .. Last)) then
1984 Canonical_Case_File_Name (Name (1 .. Last));
1987 -- Compare with source file names of the project
1989 Unit := Units_Htable.Get_First (In_Tree.Units_HT);
1990 while Unit /= No_Unit_Index loop
1991 if Unit.File_Names (Impl) /= null
1992 and then Ultimate_Extending_Project_Of
1993 (Unit.File_Names (Impl).Project) = For_Project
1996 (Unit.File_Names (Impl).File) =
2003 if Unit.File_Names (Spec) /= null
2004 and then Ultimate_Extending_Project_Of
2005 (Unit.File_Names (Spec).Project) =
2009 (Unit.File_Names (Spec).File) =
2016 Unit := Units_Htable.Get_Next (In_Tree.Units_HT);
2021 Set_Writable (Name (1 .. Last));
2022 Delete_File (Name (1 .. Last), Disregard);
2029 Copy_Interface_Sources
2030 (For_Project => For_Project,
2032 Interfaces => Arguments (1 .. Argument_Number),
2033 To_Dir => For_Project.Library_Src_Dir.Display_Name);
2037 -- Reset the current working directory to its previous value
2039 Change_Dir (Current_Dir);
2046 procedure Check (Filename : String) is
2048 if not Is_Regular_File (Filename) then
2049 Com.Fail (Filename & " not found
.");
2057 procedure Check_Context is
2059 -- Check that each object file exists
2061 for F in Object_Files'Range loop
2062 Check (Object_Files (F).all);
2070 procedure Check_Library
2071 (For_Project : Project_Id; In_Tree : Project_Tree_Ref)
2073 Lib_TS : Time_Stamp_Type;
2074 Current : constant Dir_Name_Str := Get_Current_Dir;
2077 -- No need to build the library if there is no object directory,
2078 -- hence no object files to build the library.
2080 if For_Project.Library then
2082 Lib_Name : constant File_Name_Type :=
2083 Library_File_Name_For (For_Project, In_Tree);
2086 (Get_Name_String (For_Project.Library_Dir.Display_Name));
2087 Lib_TS := File_Stamp (Lib_Name);
2088 For_Project.Library_TS := Lib_TS;
2091 if not For_Project.Externally_Built
2092 and then not For_Project.Need_To_Build_Lib
2093 and then For_Project.Object_Directory /= No_Path_Information
2096 Obj_TS : Time_Stamp_Type;
2097 Object_Dir : Dir_Type;
2100 if OpenVMS_On_Target then
2101 B_Start := new String'("b__
");
2104 -- If the library file does not exist, then the time stamp will
2105 -- be Empty_Time_Stamp, earlier than any other time stamp.
2108 (Get_Name_String (For_Project.Object_Directory.Display_Name));
2109 Open (Dir => Object_Dir, Dir_Name => ".");
2111 -- For all entries in the object directory
2114 Read (Object_Dir, Name_Buffer, Name_Len);
2115 exit when Name_Len = 0;
2117 -- Check if it is an object file, but ignore any binder
2120 if Is_Obj (Name_Buffer (1 .. Name_Len))
2121 and then Name_Buffer (1 .. B_Start'Length) /= B_Start.all
2123 -- Get the object file time stamp
2125 Obj_TS := File_Stamp (File_Name_Type'(Name_Find));
2127 -- If library file time stamp is earlier, set
2128 -- Need_To_Build_Lib and return. String comparison is
2129 -- used, otherwise time stamps may be too close and the
2130 -- comparison would return True, which would trigger
2131 -- an unnecessary rebuild of the library.
2133 if String (Lib_TS) < String (Obj_TS) then
2135 -- Library must be rebuilt
2137 For_Project.Need_To_Build_Lib := True;
2147 Change_Dir (Current);
2151 ----------------------------
2152 -- Copy_Interface_Sources --
2153 ----------------------------
2155 procedure Copy_Interface_Sources
2156 (For_Project : Project_Id;
2157 In_Tree : Project_Tree_Ref;
2158 Interfaces : Argument_List;
2159 To_Dir : Path_Name_Type)
2161 Current : constant Dir_Name_Str := Get_Current_Dir;
2162 -- The current directory, where to return to at the end
2164 Target : constant Dir_Name_Str := Get_Name_String (To_Dir);
2165 -- The directory where to copy sources
2167 Text : Text_Buffer_Ptr;
2168 The_ALI : ALI.ALI_Id;
2169 Lib_File : File_Name_Type;
2171 First_Unit : ALI.Unit_Id;
2172 Second_Unit : ALI.Unit_Id;
2174 Copy_Subunits : Boolean := False;
2175 -- When True, indicates that subunits, if any, need to be copied too
2177 procedure Copy (File_Name : File_Name_Type);
2178 -- Copy one source of the project to the target directory
2184 procedure Copy (File_Name : File_Name_Type) is
2186 pragma Warnings (Off, Success);
2188 Source : Standard.Prj.Source_Id;
2190 Source := Find_Source
2191 (In_Tree, For_Project,
2192 In_Extended_Only => True,
2193 Base_Name => File_Name);
2195 if Source /= No_Source
2196 and then not Source.Locally_Removed
2197 and then Source.Replaced_By = No_Source
2200 (Get_Name_String (Source.Path.Name),
2204 Preserve => Preserve);
2208 -- Start of processing for Copy_Interface_Sources
2211 -- Change the working directory to the object directory
2213 Change_Dir (Get_Name_String (For_Project.Object_Directory.Display_Name));
2215 for Index in Interfaces'Range loop
2217 -- First, load the ALI file
2220 Add_Str_To_Name_Buffer (Interfaces (Index).all);
2221 Lib_File := Name_Find;
2222 Text := Read_Library_Info (Lib_File);
2223 The_ALI := Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
2226 Second_Unit := No_Unit_Id;
2227 First_Unit := ALI.ALIs.Table (The_ALI).First_Unit;
2228 Copy_Subunits := True;
2230 -- If there is both a spec and a body, check if they are both needed
2232 if ALI.Units.Table (First_Unit).Utype = Is_Body then
2233 Second_Unit := ALI.ALIs.Table (The_ALI).Last_Unit;
2235 -- If the body is not needed, then reset First_Unit
2237 if not ALI.Units.Table (Second_Unit).Body_Needed_For_SAL then
2238 First_Unit := No_Unit_Id;
2239 Copy_Subunits := False;
2242 elsif ALI.Units.Table (First_Unit).Utype = Is_Spec_Only then
2243 Copy_Subunits := False;
2246 -- Copy the file(s) that need to be copied
2248 if First_Unit /= No_Unit_Id then
2249 Copy (File_Name => ALI.Units.Table (First_Unit).Sfile);
2252 if Second_Unit /= No_Unit_Id then
2253 Copy (File_Name => ALI.Units.Table (Second_Unit).Sfile);
2256 -- Copy all the separates, if any
2258 if Copy_Subunits then
2259 for Dep in ALI.ALIs.Table (The_ALI).First_Sdep ..
2260 ALI.ALIs.Table (The_ALI).Last_Sdep
2262 if Sdep.Table (Dep).Subunit_Name /= No_Name then
2263 Copy (File_Name => Sdep.Table (Dep).Sfile);
2269 -- Restore the initial working directory
2271 Change_Dir (Current);
2272 end Copy_Interface_Sources;
2278 procedure Display (Executable : String) is
2280 if not Opt.Quiet_Output then
2281 Write_Str (Executable);
2283 for Index in 1 .. Argument_Number loop
2285 Write_Str (Arguments (Index).all);
2287 if not Opt.Verbose_Mode and then Index > 4 then
2301 function Index (S, Pattern : String) return Natural is
2302 Len : constant Natural := Pattern'Length;
2305 for J in reverse S'First .. S'Last - Len + 1 loop
2306 if Pattern = S (J .. J + Len - 1) then
2314 -------------------------
2315 -- Process_Binder_File --
2316 -------------------------
2318 procedure Process_Binder_File (Name : String) is
2320 -- Binder file's descriptor
2322 Read_Mode : constant String := "r
" & ASCII.NUL;
2325 Status : Interfaces.C_Streams.int;
2326 pragma Unreferenced (Status);
2329 Begin_Info : constant String := "-- BEGIN Object file/option list";
2330 End_Info
: constant String := "-- END Object file/option list ";
2332 Next_Line
: String (1 .. 1000);
2333 -- Current line value
2334 -- Where does this odd constant 1000 come from, looks suspicious ???
2337 -- End of line slice (the slice does not contain the line terminator)
2339 procedure Get_Next_Line
;
2340 -- Read the next line from the binder file without the line terminator
2346 procedure Get_Next_Line
is
2350 Fchars
:= fgets
(Next_Line
'Address, Next_Line
'Length, Fd
);
2352 if Fchars
= System
.Null_Address
then
2353 Fail
("Error reading binder output");
2357 while Nlast
<= Next_Line
'Last
2358 and then Next_Line
(Nlast
) /= ASCII
.LF
2359 and then Next_Line
(Nlast
) /= ASCII
.CR
2367 -- Start of processing for Process_Binder_File
2370 Fd
:= fopen
(Name
'Address, Read_Mode
'Address);
2372 if Fd
= NULL_Stream
then
2373 Fail
("Failed to open binder output");
2376 -- Skip up to the Begin Info line
2380 exit when Next_Line
(1 .. Nlast
) = Begin_Info
;
2383 -- Find the first switch
2388 exit when Next_Line
(1 .. Nlast
) = End_Info
;
2390 -- As the binder generated file is in Ada, remove the first eight
2391 -- characters " -- ".
2393 Next_Line
(1 .. Nlast
- 8) := Next_Line
(9 .. Nlast
);
2396 -- Stop when the first switch is found
2398 exit when Next_Line
(1) = '-';
2401 if Next_Line
(1 .. Nlast
) /= End_Info
then
2403 -- Ignore -static and -shared, since -shared will be used
2406 -- Ignore -lgnat, -lgnarl and -ldecgnat as they will be added
2407 -- later, because they are also needed for non Stand-Alone shared
2410 -- Also ignore the shared libraries which are :
2412 -- UNIX / Windows VMS
2413 -- -lgnat-<version> -lgnat_<version> (7 + version'length chars)
2414 -- -lgnarl-<version> -lgnarl_<version> (8 + version'length chars)
2416 if Next_Line
(1 .. Nlast
) /= "-static" and then
2417 Next_Line
(1 .. Nlast
) /= "-shared" and then
2418 Next_Line
(1 .. Nlast
) /= "-ldecgnat" and then
2419 Next_Line
(1 .. Nlast
) /= "-lgnarl" and then
2420 Next_Line
(1 .. Nlast
) /= "-lgnat" and then
2422 (1 .. Natural'Min (Nlast
, 10 + Library_Version
'Length)) /=
2423 Shared_Lib
("decgnat") and then
2425 (1 .. Natural'Min (Nlast
, 8 + Library_Version
'Length)) /=
2426 Shared_Lib
("gnarl") and then
2428 (1 .. Natural'Min (Nlast
, 7 + Library_Version
'Length)) /=
2431 if Next_Line
(1) /= '-' then
2433 -- This is not an option, should we add it?
2435 if Add_Object_Files
then
2436 Opts
.Increment_Last
;
2437 Opts
.Table
(Opts
.Last
) :=
2438 new String'(Next_Line (1 .. Nlast));
2442 -- Add all other options
2444 Opts.Increment_Last;
2445 Opts.Table (Opts.Last) :=
2446 new String'(Next_Line
(1 .. Nlast
));
2450 -- Next option, if any
2453 exit when Next_Line
(1 .. Nlast
) = End_Info
;
2455 -- Remove first eight characters " -- "
2457 Next_Line
(1 .. Nlast
- 8) := Next_Line
(9 .. Nlast
);
2462 Status
:= fclose
(Fd
);
2464 -- Is it really right to ignore any close error ???
2466 end Process_Binder_File
;
2472 procedure Reset_Tables
is
2475 Objects_Htable
.Reset
;
2478 Processed_Projects
.Reset
;
2482 ---------------------------
2483 -- SALs_Use_Constructors --
2484 ---------------------------
2486 function SALs_Use_Constructors
return Boolean is
2487 function C_SALs_Init_Using_Constructors
return Integer;
2488 pragma Import
(C
, C_SALs_Init_Using_Constructors
,
2489 "__gnat_sals_init_using_constructors");
2491 return C_SALs_Init_Using_Constructors
/= 0;
2492 end SALs_Use_Constructors
;