1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2011, 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 Makeutl
; use Makeutl
;
29 with MLib
.Fil
; use MLib
.Fil
;
30 with MLib
.Tgt
; use MLib
.Tgt
;
31 with MLib
.Utl
; use MLib
.Utl
;
33 with Output
; use Output
;
34 with Prj
.Com
; use Prj
.Com
;
35 with Prj
.Env
; use Prj
.Env
;
36 with Prj
.Util
; use Prj
.Util
;
38 with Snames
; use Snames
;
39 with Switch
; use Switch
;
41 with Targparm
; use Targparm
;
43 with Types
; use Types
;
45 with Ada
.Characters
.Handling
;
47 with GNAT
.Directory_Operations
; use GNAT
.Directory_Operations
;
49 with Interfaces
.C_Streams
; use Interfaces
.C_Streams
;
50 with System
; use System
;
51 with System
.Case_Util
; use System
.Case_Util
;
53 package body MLib
.Prj
is
55 Prj_Add_Obj_Files
: Types
.Int
;
56 pragma Import
(C
, Prj_Add_Obj_Files
, "__gnat_prj_add_obj_files");
57 Add_Object_Files
: constant Boolean := Prj_Add_Obj_Files
/= 0;
58 -- Indicates if object files in pragmas Linker_Options (found in the
59 -- binder generated file) should be taken when linking a stand-alone
60 -- library. False for Windows, True for other platforms.
62 ALI_Suffix
: constant String := ".ali";
64 B_Start
: String_Ptr
:= new String'("b~");
65 -- Prefix of bind file, changed to b__ for VMS
67 S_Osinte_Ads : File_Name_Type := No_File;
68 -- Name_Id for "s-osinte.ads"
70 S_Dec_Ads : File_Name_Type := No_File;
71 -- Name_Id for "dec.ads"
73 Arguments : String_List_Access := No_Argument;
74 -- Used to accumulate arguments for the invocation of gnatbind and of the
75 -- compiler. Also used to collect the interface ALI when copying the ALI
76 -- files to the library directory.
78 Argument_Number : Natural := 0;
79 -- Index of the last argument in Arguments
81 Initial_Argument_Max : constant := 10;
82 -- Where does the magic constant 10 come from???
84 No_Main_String : aliased String := "-n";
85 No_Main : constant String_Access := No_Main_String'Access;
87 Output_Switch_String : aliased String := "-o";
88 Output_Switch : constant String_Access :=
89 Output_Switch_String'Access;
91 Compile_Switch_String : aliased String := "-c";
92 Compile_Switch : constant String_Access :=
93 Compile_Switch_String'Access;
95 No_Warning_String : aliased String := "-gnatws";
96 No_Warning : constant String_Access := No_Warning_String'Access;
98 Auto_Initialize : constant String := "-a";
100 -- List of objects to put inside the library
102 Object_Files : Argument_List_Access;
104 package Objects is new Table.Table
105 (Table_Name => "Mlib.Prj.Objects",
106 Table_Component_Type => String_Access,
107 Table_Index_Type => Natural,
108 Table_Low_Bound => 1,
110 Table_Increment => 100);
112 package Objects_Htable is new GNAT.HTable.Simple_HTable
113 (Header_Num => Header_Num,
122 Ali_Files : Argument_List_Access;
124 package ALIs is new Table.Table
125 (Table_Name => "Mlib.Prj.Alis",
126 Table_Component_Type => String_Access,
127 Table_Index_Type => Natural,
128 Table_Low_Bound => 1,
130 Table_Increment => 100);
132 -- List of options set in the command line
134 Options : Argument_List_Access;
136 package Opts is new Table.Table
137 (Table_Name => "Mlib.Prj.Opts",
138 Table_Component_Type => String_Access,
139 Table_Index_Type => Natural,
140 Table_Low_Bound => 1,
142 Table_Increment => 100);
144 -- All the ALI file in the library
146 package Library_ALIs is new GNAT.HTable.Simple_HTable
147 (Header_Num => Header_Num,
150 Key => File_Name_Type,
154 -- The ALI files in the interface sets
156 package Interface_ALIs is new GNAT.HTable.Simple_HTable
157 (Header_Num => Header_Num,
160 Key => File_Name_Type,
164 -- The ALI files that have been processed to check if the corresponding
165 -- library unit is in the interface set.
167 package Processed_ALIs is new GNAT.HTable.Simple_HTable
168 (Header_Num => Header_Num,
171 Key => File_Name_Type,
175 -- The projects imported directly or indirectly
177 package Processed_Projects is new GNAT.HTable.Simple_HTable
178 (Header_Num => Header_Num,
185 -- The library projects imported directly or indirectly
187 package Library_Projs is new Table.Table (
188 Table_Component_Type => Project_Id,
189 Table_Index_Type => Integer,
190 Table_Low_Bound => 1,
192 Table_Increment => 10,
193 Table_Name => "Make.Library_Projs");
195 type Build_Mode_State is (None, Static, Dynamic, Relocatable);
197 procedure Add_Argument (S : String);
198 -- Add one argument to Arguments array, if array is full, double its size
200 function ALI_File_Name (Source : String) return String;
201 -- Return the ALI file name corresponding to a source
203 procedure Check (Filename : String);
204 -- Check if filename is a regular file. Fail if it is not
206 procedure Check_Context;
207 -- Check each object files in table Object_Files
208 -- Fail if any of them is not a regular file
210 procedure Copy_Interface_Sources
211 (For_Project : Project_Id;
212 In_Tree : Project_Tree_Ref;
213 Interfaces : Argument_List;
214 To_Dir : Path_Name_Type);
215 -- Copy the interface sources of a SAL to directory To_Dir
217 procedure Display (Executable : String);
218 -- Display invocation of gnatbind and of the compiler with the arguments
219 -- in Arguments, except when Quiet_Output is True.
221 function Index (S, Pattern : String) return Natural;
222 -- Return the last occurrence of Pattern in S, or 0 if none
224 procedure Process_Binder_File (Name : String);
225 -- For Stand-Alone libraries, get the Linker Options in the binder
228 procedure Reset_Tables;
229 -- Make sure that all the above tables are empty
230 -- (Objects, Ali_Files, Options).
232 function SALs_Use_Constructors return Boolean;
233 -- Indicate if Stand-Alone Libraries are automatically initialized using
234 -- the constructor mechanism.
240 procedure Add_Argument (S : String) is
242 if Argument_Number = Arguments'Last then
244 New_Args : constant String_List_Access :=
245 new String_List (1 .. 2 * Arguments'Last);
248 -- Copy the String_Accesses and set them to null in Arguments
249 -- so that they will not be deallocated by the call to
252 New_Args (Arguments'Range) := Arguments.all;
253 Arguments.all := (others => null);
255 Arguments := New_Args;
259 Argument_Number := Argument_Number + 1;
260 Arguments (Argument_Number) := new String'(S
);
267 function ALI_File_Name
(Source
: String) return String is
269 -- If the source name has an extension, then replace it with
272 for Index
in reverse Source
'First + 1 .. Source
'Last loop
273 if Source
(Index
) = '.' then
274 return Source
(Source
'First .. Index
- 1) & ALI_Suffix
;
278 -- If there is no dot, or if it is the first character, just add the
281 return Source
& ALI_Suffix
;
288 procedure Build_Library
289 (For_Project
: Project_Id
;
290 In_Tree
: Project_Tree_Ref
;
292 Gnatbind_Path
: String_Access
;
294 Gcc_Path
: String_Access
;
295 Bind
: Boolean := True;
296 Link
: Boolean := True)
298 Maximum_Size
: Integer;
299 pragma Import
(C
, Maximum_Size
, "__gnat_link_max");
300 -- Maximum number of bytes to put in an invocation of gnatbind
303 -- The number of bytes for the invocation of gnatbind
305 Warning_For_Library
: Boolean := False;
306 -- Set True for first warning for a unit missing from the interface set
308 Current_Proj
: Project_Id
;
310 Libgnarl_Needed
: Yes_No_Unknown
:= For_Project
.Libgnarl_Needed
;
311 -- Set True if library needs to be linked with libgnarl
313 Libdecgnat_Needed
: Boolean := False;
314 -- On OpenVMS, set True if library needs to be linked with libdecgnat
316 Object_Directory_Path
: constant String :=
318 (For_Project
.Object_Directory
.Display_Name
);
320 Standalone
: constant Boolean := For_Project
.Standalone_Library
/= No
;
322 Project_Name
: constant String := Get_Name_String
(For_Project
.Name
);
324 Current_Dir
: constant String := Get_Current_Dir
;
326 Lib_Filename
: String_Access
;
327 Lib_Dirpath
: String_Access
;
328 Lib_Version
: String_Access
:= new String'("");
330 The_Build_Mode : Build_Mode_State := None;
332 Success : Boolean := False;
334 Library_Options : Variable_Value := Nil_Variable_Value;
336 Driver_Name : Name_Id := No_Name;
338 In_Main_Object_Directory : Boolean := True;
340 Foreign_Sources : Boolean;
342 Rpath : String_Access := null;
343 -- Allocated only if Path Option is supported
345 Rpath_Last : Natural := 0;
346 -- Index of last valid character of Rpath
348 Initial_Rpath_Length : constant := 200;
349 -- Initial size of Rpath, when first allocated
351 Path_Option : String_Access := Linker_Library_Path_Option;
352 -- If null, Path Option is not supported. Not a constant so that it can
355 First_ALI : File_Name_Type := No_File;
356 -- Store the ALI file name of a source of the library (the first found)
358 procedure Add_ALI_For (Source : File_Name_Type);
359 -- Add name of the ALI file corresponding to Source to the Arguments
361 procedure Add_Rpath (Path : String);
362 -- Add a path name to Rpath
364 function Check_Project (P : Project_Id) return Boolean;
365 -- Returns True if P is For_Project or a project extended by For_Project
367 procedure Check_Libs (ALI_File : String; Main_Project : Boolean);
368 -- Set Libgnarl_Needed if the ALI_File indicates that there is a need
369 -- to link with -lgnarl (this is the case when there is a dependency
370 -- on s-osinte.ads). On OpenVMS, set Libdecgnat_Needed if the ALI file
371 -- indicates that there is a need to link with -ldecgnat (this is the
372 -- case when there is a dependency on dec.ads).
374 procedure Process (The_ALI : File_Name_Type);
375 -- Check if the closure of a library unit which is or should be in the
376 -- interface set is also in the interface set. Issue a warning for each
377 -- missing library unit.
379 procedure Process_Imported_Libraries;
380 -- Add the -L and -l switches for the imported Library Project Files,
381 -- and, if Path Option is supported, the library directory path names
388 procedure Add_ALI_For (Source : File_Name_Type) is
389 ALI : constant String := ALI_File_Name (Get_Name_String (Source));
390 ALI_Id : File_Name_Type;
398 Add_Str_To_Name_Buffer (S => ALI);
401 -- Add the ALI file name to the library ALIs
404 Library_ALIs.Set (ALI_Id, True);
407 -- Set First_ALI, if not already done
409 if First_ALI = No_File then
418 procedure Add_Rpath (Path : String) is
428 New_Rpath : constant String_Access :=
429 new String (1 .. 2 * Rpath'Length);
431 New_Rpath (1 .. Rpath_Last) := Rpath (1 .. Rpath_Last);
436 -- Start of processing for Add_Rpath
439 -- If first path, allocate initial Rpath
442 Rpath := new String (1 .. Initial_Rpath_Length);
446 -- Otherwise, add a path separator between two path names
448 if Rpath_Last = Rpath'Last then
452 Rpath_Last := Rpath_Last + 1;
453 Rpath (Rpath_Last) := Path_Separator;
456 -- Increase Rpath size until it is large enough
458 while Rpath_Last + Path'Length > Rpath'Last loop
464 Rpath (Rpath_Last + 1 .. Rpath_Last + Path'Length) := Path;
465 Rpath_Last := Rpath_Last + Path'Length;
472 function Check_Project (P : Project_Id) return Boolean is
474 if P = For_Project then
477 elsif P /= No_Project then
483 while Proj.Extends /= No_Project loop
484 if P = Proj.Extends then
488 Proj := Proj.Extends;
500 procedure Check_Libs (ALI_File : String; Main_Project : Boolean) is
501 Lib_File : File_Name_Type;
502 Text : Text_Buffer_Ptr;
506 if Libgnarl_Needed /= Yes
509 and then OpenVMS_On_Target)
513 Name_Len := ALI_File'Length;
514 Name_Buffer (1 .. Name_Len) := ALI_File;
515 Lib_File := Name_Find;
516 Text := Read_Library_Info (Lib_File, True);
526 -- Look for s-osinte.ads in the dependencies
528 for Index in ALI.ALIs.Table (Id).First_Sdep ..
529 ALI.ALIs.Table (Id).Last_Sdep
531 if ALI.Sdep.Table (Index).Sfile = S_Osinte_Ads then
532 Libgnarl_Needed := Yes;
535 For_Project.Libgnarl_Needed := Yes;
540 elsif OpenVMS_On_Target then
541 if ALI.Sdep.Table (Index).Sfile = S_Dec_Ads then
542 Libdecgnat_Needed := True;
553 procedure Process (The_ALI : File_Name_Type) is
554 Text : Text_Buffer_Ptr;
556 First_Unit : ALI.Unit_Id;
557 Last_Unit : ALI.Unit_Id;
558 Unit_Data : Unit_Record;
559 Afile : File_Name_Type;
562 -- Nothing to do if the ALI file has already been processed.
563 -- This happens if an interface imports another interface.
565 if not Processed_ALIs.Get (The_ALI) then
566 Processed_ALIs.Set (The_ALI, True);
567 Text := Read_Library_Info (The_ALI);
578 if Idread /= No_ALI_Id then
579 First_Unit := ALI.ALIs.Table (Idread).First_Unit;
580 Last_Unit := ALI.ALIs.Table (Idread).Last_Unit;
582 -- Process both unit (spec and body) if the body is needed
583 -- by the spec (inline or generic). Otherwise, just process
586 if First_Unit /= Last_Unit and then
587 not ALI.Units.Table (Last_Unit).Body_Needed_For_SAL
589 First_Unit := Last_Unit;
592 for Unit in First_Unit .. Last_Unit loop
593 Unit_Data := ALI.Units.Table (Unit);
595 -- Check if each withed unit which is in the library is
596 -- also in the interface set, if it has not yet been
599 for W in Unit_Data.First_With .. Unit_Data.Last_With loop
600 Afile := Withs.Table (W).Afile;
602 if Afile /= No_File and then Library_ALIs.Get (Afile)
603 and then not Processed_ALIs.Get (Afile)
605 if not Interface_ALIs.Get (Afile) then
606 if not Warning_For_Library then
607 Write_Str ("Warning: In library project """);
608 Get_Name_String (Current_Proj.Name);
609 To_Mixed (Name_Buffer (1 .. Name_Len));
610 Write_Str (Name_Buffer (1 .. Name_Len));
612 Warning_For_Library := True;
615 Write_Str (" Unit """);
616 Get_Name_String (Withs.Table (W).Uname);
617 To_Mixed (Name_Buffer (1 .. Name_Len - 2));
618 Write_Str (Name_Buffer (1 .. Name_Len - 2));
619 Write_Line (""" is not in the interface set");
620 Write_Str (" but it is needed by ");
622 case Unit_Data.Utype is
624 Write_Str ("the spec of ");
627 Write_Str ("the body of ");
634 Get_Name_String (Unit_Data.Uname);
635 To_Mixed (Name_Buffer (1 .. Name_Len - 2));
636 Write_Str (Name_Buffer (1 .. Name_Len - 2));
640 -- Now, process this unit
651 --------------------------------
652 -- Process_Imported_Libraries --
653 --------------------------------
655 procedure Process_Imported_Libraries is
656 Current : Project_Id;
658 procedure Process_Project (Project : Project_Id);
659 -- Process Project and its imported projects recursively.
660 -- Add any library projects to table Library_Projs.
662 ---------------------
663 -- Process_Project --
664 ---------------------
666 procedure Process_Project (Project : Project_Id) is
667 Imported : Project_List;
670 -- Nothing to do if process has already been processed
672 if not Processed_Projects.Get (Project.Name) then
673 Processed_Projects.Set (Project.Name, True);
675 -- Call Process_Project recursively for any imported project.
676 -- We first process the imported projects to guarantee that
677 -- we have a proper reverse order for the libraries.
679 Imported := Project.Imported_Projects;
680 while Imported /= null loop
681 if Imported.Project /= No_Project then
682 Process_Project (Imported.Project);
685 Imported := Imported.Next;
688 -- If it is a library project, add it to Library_Projs
690 if Project /= For_Project and then Project.Library then
691 Library_Projs.Increment_Last;
692 Library_Projs.Table (Library_Projs.Last) := Project;
694 -- Check if because of this library we need to use libgnarl
696 if Libgnarl_Needed = Unknown then
697 if Project.Libgnarl_Needed = Unknown
698 and then Project.Object_Directory /= No_Path_Information
700 -- Check if libgnarl is needed for this library
703 Object_Dir_Path : constant String :=
705 (Project.Object_Directory.
707 Object_Dir : Dir_Type;
708 Filename : String (1 .. 255);
712 Open (Object_Dir, Object_Dir_Path);
714 -- For all entries in the object directory
717 Read (Object_Dir, Filename, Last);
720 -- Check if it is an object file
722 if Is_Obj (Filename (1 .. Last)) then
724 Object_Path : constant String :=
727 Directory_Separator &
728 Filename (1 .. Last));
729 ALI_File : constant String :=
731 (Object_Path, "ali");
734 if Is_Regular_File (ALI_File) then
736 -- Find out if for this ALI file,
737 -- libgnarl is necessary.
740 (ALI_File, Main_Project => False);
742 if Libgnarl_Needed = Yes then
743 Project.Libgnarl_Needed := Yes;
744 For_Project.Libgnarl_Needed := Yes;
756 if Project.Libgnarl_Needed = Yes then
757 Libgnarl_Needed := Yes;
758 For_Project.Libgnarl_Needed := Yes;
765 -- Start of processing for Process_Imported_Libraries
768 -- Build list of library projects imported directly or indirectly,
769 -- in the reverse order.
771 Process_Project (For_Project);
773 -- Add the -L and -l switches and, if the Rpath option is supported,
774 -- add the directory to the Rpath. As the library projects are in the
775 -- wrong order, process from the last to the first.
777 for Index in reverse 1 .. Library_Projs.Last loop
778 Current := Library_Projs.Table (Index);
780 Get_Name_String (Current.Library_Dir.Display_Name);
782 Opts.Table (Opts.Last) :=
783 new String'("-L" & Name_Buffer
(1 .. Name_Len
));
785 if Path_Option
/= null then
786 Add_Rpath
(Name_Buffer
(1 .. Name_Len
));
790 Opts
.Table
(Opts
.Last
) :=
791 new String'("-l" & Get_Name_String (Current.Library_Name));
793 end Process_Imported_Libraries;
795 Path_FD : File_Descriptor := Invalid_FD;
796 -- Used for setting the source and object paths
798 -- Start of processing for Build_Library
803 -- Fail if project is not a library project
805 if not For_Project.Library then
806 Com.Fail ("project """ & Project_Name & """ has no library");
809 -- Do not attempt to build the library if it is externally built
811 if For_Project.Externally_Built then
815 -- If this is the first time Build_Library is called, get the Name_Id
816 -- of "s-osinte.ads".
818 if S_Osinte_Ads = No_File then
820 Add_Str_To_Name_Buffer ("s-osinte.ads");
821 S_Osinte_Ads := Name_Find;
824 if S_Dec_Ads = No_File then
826 Add_Str_To_Name_Buffer ("dec.ads");
827 S_Dec_Ads := Name_Find;
830 -- We work in the object directory
832 Change_Dir (Object_Directory_Path);
836 -- Call gnatbind only if Bind is True
839 if Gnatbind_Path = null then
840 Com.Fail ("unable to locate " & Gnatbind);
843 if Gcc_Path = null then
844 Com.Fail ("unable to locate " & Gcc);
847 -- Allocate Arguments, if it is the first time we see a standalone
850 if Arguments = No_Argument then
851 Arguments := new String_List (1 .. Initial_Argument_Max);
854 -- Add "-n -o b~<lib>.adb (b__<lib>.adb on VMS) -L<lib>_"
856 Argument_Number := 2;
857 Arguments (1) := No_Main;
858 Arguments (2) := Output_Switch;
860 if OpenVMS_On_Target then
861 B_Start := new String'("b__");
866 & Get_Name_String
(For_Project
.Library_Name
) & ".adb");
868 -- Make sure that the init procedure is never "adainit"
870 Get_Name_String
(For_Project
.Library_Name
);
872 if Name_Buffer
(1 .. Name_Len
) = "ada" then
873 Add_Argument
("-Lada_");
876 ("-L" & Get_Name_String
(For_Project
.Library_Name
));
879 if For_Project
.Lib_Auto_Init
and then SALs_Use_Constructors
then
880 Add_Argument
(Auto_Initialize
);
883 -- Check if Binder'Default_Switches ("Ada") is defined. If it is,
884 -- add these switches to call gnatbind.
887 Binder_Package
: constant Package_Id
:=
889 (Name
=> Name_Binder
,
890 In_Packages
=> For_Project
.Decl
.Packages
,
891 Shared
=> In_Tree
.Shared
);
894 if Binder_Package
/= No_Package
then
896 Defaults
: constant Array_Element_Id
:=
898 (Name
=> Name_Default_Switches
,
900 In_Tree
.Shared
.Packages
.Table
901 (Binder_Package
).Decl
.Arrays
,
902 Shared
=> In_Tree
.Shared
);
904 Switches
: Variable_Value
:= Nil_Variable_Value
;
905 Switch
: String_List_Id
:= Nil_String
;
908 if Defaults
/= No_Array_Element
then
913 In_Array
=> Defaults
,
914 Shared
=> In_Tree
.Shared
);
916 if not Switches
.Default
then
917 Switch
:= Switches
.Values
;
919 while Switch
/= Nil_String
loop
922 (In_Tree
.Shared
.String_Elements
.Table
924 Switch
:= In_Tree
.Shared
.String_Elements
.
934 -- Get all the ALI files of the project file. We do that even if
935 -- Bind is False, so that First_ALI is set.
942 Interface_ALIs
.Reset
;
943 Processed_ALIs
.Reset
;
945 Unit
:= Units_Htable
.Get_First
(In_Tree
.Units_HT
);
946 while Unit
/= No_Unit_Index
loop
947 if Unit
.File_Names
(Impl
) /= null
948 and then not Unit
.File_Names
(Impl
).Locally_Removed
950 if Check_Project
(Unit
.File_Names
(Impl
).Project
) then
951 if Unit
.File_Names
(Spec
) = null then
953 -- Add the ALI file only if it is not a subunit
956 Src_Ind
: constant Source_File_Index
:=
957 Sinput
.P
.Load_Project_File
959 (Unit
.File_Names
(Impl
).Path
.Name
));
962 Sinput
.P
.Source_File_Is_Subunit
(Src_Ind
)
964 Add_ALI_For
(Unit
.File_Names
(Impl
).File
);
970 Add_ALI_For
(Unit
.File_Names
(Impl
).File
);
975 elsif Unit
.File_Names
(Spec
) /= null
976 and then not Unit
.File_Names
(Spec
).Locally_Removed
977 and then Check_Project
(Unit
.File_Names
(Spec
).Project
)
979 Add_ALI_For
(Unit
.File_Names
(Spec
).File
);
983 Unit
:= Units_Htable
.Get_Next
(In_Tree
.Units_HT
);
987 -- Continue setup and call gnatbind if Bind is True
991 -- Get an eventual --RTS from the ALI file
993 if First_ALI
/= No_File
then
1001 T
:= Read_Library_Info
(First_ALI
, True);
1006 (First_ALI
, T
, Ignore_ED
=> False, Err
=> False);
1008 if A
/= No_ALI_Id
then
1011 (ALI
.ALIs
.Table
(A
).First_Unit
).First_Arg
..
1013 (ALI
.ALIs
.Table
(A
).First_Unit
).Last_Arg
1015 -- If --RTS found, add switch to call gnatbind
1018 Arg
: String_Ptr
renames Args
.Table
(Index
);
1020 if Arg
'Length >= 6 and then
1021 Arg
(Arg
'First + 2 .. Arg
'First + 5) = "RTS="
1023 Add_Argument
(Arg
.all);
1034 -- First the source path
1036 if For_Project
.Include_Path_File
= No_Path
then
1038 (Project_Tree
=> In_Tree
,
1039 For_Project
=> For_Project
,
1040 Activity
=> Compilation
,
1041 Languages
=> Ada_Only
);
1043 Create_New_Path_File
1044 (In_Tree
.Shared
, Path_FD
, For_Project
.Include_Path_File
);
1046 Write_Path_File
(Path_FD
);
1047 Path_FD
:= Invalid_FD
;
1050 if Current_Source_Path_File_Of
(In_Tree
.Shared
) /=
1051 For_Project
.Include_Path_File
1053 Set_Current_Source_Path_File_Of
1054 (In_Tree
.Shared
, For_Project
.Include_Path_File
);
1056 (Project_Include_Path_File
,
1057 Get_Name_String
(For_Project
.Include_Path_File
));
1060 -- Then, the object path
1063 (Project_Tree
=> In_Tree
,
1064 For_Project
=> For_Project
,
1065 Activity
=> SAL_Binding
,
1066 Languages
=> Ada_Only
);
1069 Path_File_Name
: Path_Name_Type
;
1072 Create_New_Path_File
(In_Tree
.Shared
, Path_FD
, Path_File_Name
);
1074 Write_Path_File
(Path_FD
);
1075 Path_FD
:= Invalid_FD
;
1078 (Project_Objects_Path_File
, Get_Name_String
(Path_File_Name
));
1079 Set_Current_Source_Path_File_Of
1080 (In_Tree
.Shared
, Path_File_Name
);
1083 -- Display the gnatbind command, if not in quiet output
1088 for J
in 1 .. Argument_Number
loop
1089 Size
:= Size
+ Arguments
(J
)'Length + 1;
1092 -- Invoke gnatbind with the arguments if the size is not too large
1094 if Size
<= Maximum_Size
then
1097 Arguments
(1 .. Argument_Number
),
1100 -- Otherwise create a temporary response file
1104 FD
: File_Descriptor
;
1105 Path
: Path_Name_Type
;
1106 Args
: Argument_List
(1 .. 1);
1107 EOL
: constant String (1 .. 1) := (1 => ASCII
.LF
);
1110 Quotes_Needed
: Boolean;
1111 Last_Char
: Natural;
1115 Tempdir
.Create_Temp_File
(FD
, Path
);
1116 Args
(1) := new String'("@" & Get_Name_String (Path));
1118 for J in 1 .. Argument_Number loop
1120 -- Check if the argument should be quoted
1122 Quotes_Needed := False;
1123 Last_Char := Arguments (J)'Length;
1125 for K in Arguments (J)'Range loop
1126 Ch := Arguments (J) (K);
1128 if Ch = ' ' or else Ch = ASCII.HT or else Ch = '"' then
1129 Quotes_Needed := True;
1134 if Quotes_Needed then
1136 -- Quote the argument, doubling '"'
1139 Arg : String (1 .. Arguments (J)'Length * 2 + 2);
1145 for K in Arguments (J)'Range loop
1146 Ch := Arguments (J) (K);
1147 Last_Char := Last_Char + 1;
1148 Arg (Last_Char) := Ch;
1151 Last_Char := Last_Char + 1;
1152 Arg (Last_Char) := '"';
1156 Last_Char := Last_Char + 1;
1157 Arg (Last_Char) := '"';
1159 Status := Write (FD, Arg'Address, Last_Char);
1165 Arguments (J) (Arguments (J)'First)'Address,
1169 if Status /= Last_Char then
1173 Status := Write (FD, EOL (1)'Address, 1);
1182 -- And invoke gnatbind with this response file
1184 Spawn (Gnatbind_Path.all, Args, Success);
1186 Delete_File (Get_Name_String (Path), Succ);
1195 Com.Fail ("could not bind standalone library "
1196 & Get_Name_String (For_Project.Library_Name));
1200 -- Compile the binder generated file only if Link is true
1207 (Project => For_Project,
1209 Including_Libraries => True);
1211 -- Invoke <gcc> -c b__<lib>.adb
1213 -- Allocate Arguments, if first time we see a standalone library
1215 if Arguments = No_Argument then
1216 Arguments := new String_List (1 .. Initial_Argument_Max);
1219 Argument_Number := 2;
1220 Arguments (1) := Compile_Switch;
1221 Arguments (2) := No_Warning;
1223 if OpenVMS_On_Target then
1224 B_Start := new String'("b__");
1229 & Get_Name_String
(For_Project
.Library_Name
) & ".adb");
1231 -- If necessary, add the PIC option
1233 if PIC_Option
/= "" then
1234 Add_Argument
(PIC_Option
);
1237 -- Get the back-end switches and --RTS from the ALI file
1239 if First_ALI
/= No_File
then
1241 T
: Text_Buffer_Ptr
;
1245 -- Load the ALI file
1247 T
:= Read_Library_Info
(First_ALI
, True);
1252 Scan_ALI
(First_ALI
, T
, Ignore_ED
=> False, Err
=> False);
1254 if A
/= No_ALI_Id
then
1257 (ALI
.ALIs
.Table
(A
).First_Unit
).First_Arg
..
1259 (ALI
.ALIs
.Table
(A
).First_Unit
).Last_Arg
1261 -- Do not compile with the front end switches except
1265 Arg
: String_Ptr
renames Args
.Table
(Index
);
1267 if not Is_Front_End_Switch
(Arg
.all)
1269 Arg
(Arg
'First + 2 .. Arg
'First + 5) = "RTS="
1271 Add_Argument
(Arg
.all);
1279 -- Now all the arguments are set, compile binder generated file
1283 (Gcc_Path
.all, Arguments
(1 .. Argument_Number
), Success
);
1287 ("could not compile binder generated file for library "
1288 & Get_Name_String
(For_Project
.Library_Name
));
1291 -- Process binder generated file for pragmas Linker_Options
1293 Process_Binder_File
(Arguments
(3).all & ASCII
.NUL
);
1297 -- Build the library only if Link is True
1301 -- If attributes Library_GCC or Linker'Driver were specified, get the
1304 if For_Project
.Config
.Shared_Lib_Driver
/= No_File
then
1305 Driver_Name
:= Name_Id
(For_Project
.Config
.Shared_Lib_Driver
);
1308 -- If attribute Library_Options was specified, add these options
1310 Library_Options
:= Value_Of
1311 (Name_Library_Options
, For_Project
.Decl
.Attributes
,
1314 if not Library_Options
.Default
then
1316 Current
: String_List_Id
;
1317 Element
: String_Element
;
1320 Current
:= Library_Options
.Values
;
1321 while Current
/= Nil_String
loop
1322 Element
:= In_Tree
.Shared
.String_Elements
.Table
(Current
);
1323 Get_Name_String
(Element
.Value
);
1325 if Name_Len
/= 0 then
1326 Opts
.Increment_Last
;
1327 Opts
.Table
(Opts
.Last
) :=
1328 new String'(Name_Buffer (1 .. Name_Len));
1331 Current := Element.Next;
1337 new String'(Get_Name_String
(For_Project
.Library_Dir
.Display_Name
));
1339 new String'(Get_Name_String (For_Project.Library_Name));
1341 case For_Project.Library_Kind is
1343 The_Build_Mode := Static;
1346 The_Build_Mode := Dynamic;
1349 The_Build_Mode := Relocatable;
1351 if PIC_Option /= "" then
1352 Opts.Increment_Last;
1353 Opts.Table (Opts.Last) := new String'(PIC_Option
);
1357 -- Get the library version, if any
1359 if For_Project
.Lib_Internal_Name
/= No_Name
then
1361 new String'(Get_Name_String (For_Project.Lib_Internal_Name));
1364 -- Add the objects found in the object directory and the object
1365 -- directories of the extended files, if any, except for generated
1366 -- object files (b~.. or B__..) from extended projects.
1367 -- When there are one or more extended files, only add an object file
1368 -- if no object file with the same name have already been added.
1370 In_Main_Object_Directory := True;
1372 -- For gnatmake, when the project specifies more than just Ada as a
1373 -- language (even if course we could not find any source file for
1374 -- the other languages), we will take all object files found in the
1375 -- object directories. Since we know the project supports at least
1376 -- Ada, we just have to test whether it has at least two languages,
1377 -- and not care about the sources.
1379 Foreign_Sources := For_Project.Languages.Next /= null;
1380 Current_Proj := For_Project;
1382 if Current_Proj.Object_Directory /= No_Path_Information then
1384 -- The following code gets far too indented ... suggest some
1385 -- procedural abstraction here. How about making this declare
1386 -- block a named procedure???
1389 Object_Dir_Path : constant String :=
1391 (Current_Proj.Object_Directory
1394 Object_Dir : Dir_Type;
1395 Filename : String (1 .. 255);
1400 Open (Dir => Object_Dir, Dir_Name => Object_Dir_Path);
1402 -- For all entries in the object directory
1405 Read (Object_Dir, Filename, Last);
1409 -- Check if it is an object file
1411 if Is_Obj (Filename (1 .. Last)) then
1413 Object_Path : constant String :=
1416 & Directory_Separator
1417 & Filename (1 .. Last));
1418 Object_File : constant String :=
1419 Filename (1 .. Last);
1421 C_Filename : String := Object_File;
1424 Canonical_Case_File_Name (C_Filename);
1426 -- If in the object directory of an extended
1427 -- project, do not consider generated object files.
1429 if In_Main_Object_Directory
1432 C_Filename (1 .. B_Start'Length) /= B_Start.all
1435 Add_Str_To_Name_Buffer (C_Filename);
1438 if not Objects_Htable.Get (Id) then
1440 ALI_File : constant String :=
1441 Ext_To (C_Filename, "ali");
1443 ALI_Path : constant String :=
1444 Ext_To (Object_Path, "ali");
1447 Fname : File_Name_Type;
1452 -- The following assignment could use
1460 C_Filename (1 .. B_Start'Length)
1463 if Is_Regular_File (ALI_Path) then
1465 -- If there is an ALI file, check if
1466 -- the object file should be added to
1467 -- the library. If there are foreign
1468 -- sources we put all object files in
1473 Units_Htable.Get_First
1475 while Index /= null loop
1476 if Index.File_Names (Impl) /=
1480 Index.File_Names (Impl)
1483 Index.File_Names (Impl).File;
1485 elsif Index.File_Names (Spec) /=
1489 Index.File_Names (Spec)
1492 Index.File_Names (Spec).File;
1498 Add_It := Proj /= No_Project;
1500 -- If the source is in the
1501 -- project or a project it
1502 -- extends, we may put it in
1506 Add_It := Check_Project (Proj);
1509 -- But we don't, if the ALI file
1510 -- does not correspond to the
1515 F : constant String :=
1520 Add_It := F = ALI_File;
1527 Units_Htable.Get_Next
1533 Objects_Htable.Set (Id, True);
1535 (new String'(Object_Path
));
1537 -- Record the ALI file
1539 ALIs
.Append
(new String'(ALI_Path));
1541 -- Find out if for this ALI file,
1542 -- libgnarl or libdecgnat is
1545 Check_Libs (ALI_Path, True);
1548 elsif Foreign_Sources then
1550 (new String'(Object_Path
));
1559 Close
(Dir
=> Object_Dir
);
1562 when Directory_Error
=>
1563 Com
.Fail
("cannot find object directory """
1565 (Current_Proj
.Object_Directory
.Display_Name
)
1570 exit when Current_Proj
.Extends
= No_Project
;
1572 In_Main_Object_Directory
:= False;
1573 Current_Proj
:= Current_Proj
.Extends
;
1576 -- Add the -L and -l switches for the imported Library Project Files,
1577 -- and, if Path Option is supported, the library directory path names
1580 Process_Imported_Libraries
;
1582 -- Link with libgnat and possibly libgnarl
1584 Opts
.Increment_Last
;
1585 Opts
.Table
(Opts
.Last
) := new String'("-L" & Lib_Directory);
1587 -- If Path Option supported, add libgnat directory path name to Rpath
1589 if Path_Option /= null then
1591 Libdir : constant String := Lib_Directory;
1592 GCC_Index : Natural := 0;
1597 -- For shared libraries, add to the Path Option the directory
1598 -- of the shared version of libgcc.
1600 if The_Build_Mode /= Static then
1601 GCC_Index := Index (Libdir, "/lib/");
1603 if GCC_Index = 0 then
1607 Directory_Separator & "lib" & Directory_Separator);
1610 if GCC_Index /= 0 then
1611 Add_Rpath (Libdir (Libdir'First .. GCC_Index + 3));
1617 if Libgnarl_Needed = Yes then
1618 Opts.Increment_Last;
1620 if The_Build_Mode = Static then
1621 Opts.Table (Opts.Last) := new String'("-lgnarl");
1623 Opts
.Table
(Opts
.Last
) := new String'(Shared_Lib ("gnarl"));
1627 if Libdecgnat_Needed then
1628 Opts.Increment_Last;
1630 Opts.Table (Opts.Last) :=
1631 new String'("-L" & Lib_Directory
& "/../declib");
1633 Opts
.Increment_Last
;
1635 if The_Build_Mode
= Static
then
1636 Opts
.Table
(Opts
.Last
) := new String'("-ldecgnat");
1638 Opts.Table (Opts.Last) := new String'(Shared_Lib
("decgnat"));
1642 Opts
.Increment_Last
;
1644 if The_Build_Mode
= Static
then
1645 Opts
.Table
(Opts
.Last
) := new String'("-lgnat");
1647 Opts.Table (Opts.Last) := new String'(Shared_Lib
("gnat"));
1650 -- If Path Option is supported, add the necessary switch with the
1651 -- content of Rpath. As Rpath contains at least libgnat directory
1652 -- path name, it is guaranteed that it is not null.
1654 if Path_Option
/= null then
1655 Opts
.Increment_Last
;
1656 Opts
.Table
(Opts
.Last
) :=
1657 new String'(Path_Option.all & Rpath (1 .. Rpath_Last));
1664 (Argument_List
(Objects
.Table
(1 .. Objects
.Last
)));
1667 new Argument_List
'(Argument_List (ALIs.Table (1 .. ALIs.Last)));
1670 new Argument_List'(Argument_List
(Opts
.Table
(1 .. Opts
.Last
)));
1672 -- We fail if there are no object to put in the library
1673 -- (Ada or foreign objects).
1675 if Object_Files
'Length = 0 then
1676 Com
.Fail
("no object files for library """ &
1677 Lib_Filename
.all & '"');
1680 if not Opt
.Quiet_Output
then
1682 Write_Str
("building ");
1683 Write_Str
(Ada
.Characters
.Handling
.To_Lower
1684 (Build_Mode_State
'Image (The_Build_Mode
)));
1685 Write_Str
(" library for project ");
1686 Write_Line
(Project_Name
);
1688 -- Only output list of object files and ALI files in verbose mode
1690 if Opt
.Verbose_Mode
then
1693 Write_Line
("object files:");
1695 for Index
in Object_Files
'Range loop
1697 Write_Line
(Object_Files
(Index
).all);
1702 if Ali_Files
'Length = 0 then
1703 Write_Line
("NO ALI files");
1706 Write_Line
("ALI files:");
1708 for Index
in Ali_Files
'Range loop
1710 Write_Line
(Ali_Files
(Index
).all);
1718 -- We check that all object files are regular files
1722 -- Delete the existing library file, if it exists. Fail if the
1723 -- library file is not writable, or if it is not possible to delete
1727 DLL_Name
: aliased String :=
1728 Lib_Dirpath
.all & Directory_Separator
& DLL_Prefix
&
1729 Lib_Filename
.all & "." & DLL_Ext
;
1731 Archive_Name
: aliased String :=
1732 Lib_Dirpath
.all & Directory_Separator
& "lib" &
1733 Lib_Filename
.all & "." & Archive_Ext
;
1735 type Str_Ptr
is access all String;
1736 -- This type is necessary to meet the accessibility rules of Ada.
1737 -- It is not possible to use String_Access here.
1739 Full_Lib_Name
: Str_Ptr
;
1740 -- Designates the full library path name. Either DLL_Name or
1741 -- Archive_Name, depending on the library kind.
1744 pragma Warnings
(Off
, Success
);
1745 -- Used to call Delete_File
1748 if The_Build_Mode
= Static
then
1749 Full_Lib_Name
:= Archive_Name
'Access;
1751 Full_Lib_Name
:= DLL_Name
'Access;
1754 if Is_Regular_File
(Full_Lib_Name
.all) then
1755 if Is_Writable_File
(Full_Lib_Name
.all) then
1756 Delete_File
(Full_Lib_Name
.all, Success
);
1759 if Is_Regular_File
(Full_Lib_Name
.all) then
1760 Com
.Fail
("could not delete """ & Full_Lib_Name
.all & """");
1765 Argument_Number
:= 0;
1767 -- If we have a standalone library, gather all the interface ALI.
1768 -- They are passed to Build_Dynamic_Library, where they are used by
1769 -- some platforms (VMS, for example) to decide what symbols should be
1770 -- exported. They are also flagged as Interface when we copy them to
1771 -- the library directory (by Copy_ALI_Files, below).
1774 Current_Proj
:= For_Project
;
1777 Iface
: String_List_Id
:= For_Project
.Lib_Interface_ALIs
;
1778 ALI
: File_Name_Type
;
1781 while Iface
/= Nil_String
loop
1784 (In_Tree
.Shared
.String_Elements
.Table
(Iface
).Value
);
1785 Interface_ALIs
.Set
(ALI
, True);
1787 (In_Tree
.Shared
.String_Elements
.Table
(Iface
).Value
);
1788 Add_Argument
(Name_Buffer
(1 .. Name_Len
));
1789 Iface
:= In_Tree
.Shared
.String_Elements
.Table
(Iface
).Next
;
1792 Iface
:= For_Project
.Lib_Interface_ALIs
;
1794 if not Opt
.Quiet_Output
then
1796 -- Check that the interface set is complete: any unit in the
1797 -- library that is needed by an interface should also be an
1798 -- interface. If it is not the case, output a warning.
1800 while Iface
/= Nil_String
loop
1803 (In_Tree
.Shared
.String_Elements
.Table
(Iface
).Value
);
1806 In_Tree
.Shared
.String_Elements
.Table
(Iface
).Next
;
1813 Current_Dir
: constant String := Get_Current_Dir
;
1816 Name
: String (1 .. 200);
1819 Disregard
: Boolean;
1820 pragma Warnings
(Off
, Disregard
);
1822 DLL_Name
: aliased constant String :=
1823 Lib_Filename
.all & "." & DLL_Ext
;
1825 Archive_Name
: aliased constant String :=
1826 Lib_Filename
.all & "." & Archive_Ext
;
1828 Delete
: Boolean := False;
1831 -- Clean the library directory: remove any file with the name of
1832 -- the library file and any ALI file of a source of the project.
1835 Get_Name_String
(For_Project
.Library_Dir
.Display_Name
);
1836 Change_Dir
(Name_Buffer
(1 .. Name_Len
));
1841 ("unable to access library directory """
1842 & Name_Buffer
(1 .. Name_Len
)
1849 Read
(Dir
, Name
, Last
);
1853 Filename
: constant String := Name
(1 .. Last
);
1856 if Is_Regular_File
(Filename
) then
1857 Canonical_Case_File_Name
(Name
(1 .. Last
));
1860 if (The_Build_Mode
= Static
1861 and then Name
(1 .. Last
) = Archive_Name
)
1863 ((The_Build_Mode
= Dynamic
1865 The_Build_Mode
= Relocatable
)
1866 and then Name
(1 .. Last
) = DLL_Name
)
1871 and then Name
(Last
- 3 .. Last
) = ".ali"
1877 -- Compare with ALI file names of the project
1879 Unit
:= Units_Htable
.Get_First
(In_Tree
.Units_HT
);
1880 while Unit
/= No_Unit_Index
loop
1881 if Unit
.File_Names
(Impl
) /= null
1882 and then Unit
.File_Names
(Impl
).Project
/=
1885 if Ultimate_Extending_Project_Of
1886 (Unit
.File_Names
(Impl
).Project
) =
1890 (Unit
.File_Names
(Impl
).File
);
1894 (Name
(1 .. Name_Len
))'Length;
1896 if Name_Buffer
(1 .. Name_Len
) =
1897 Name
(1 .. Last
- 4)
1904 elsif Unit
.File_Names
(Spec
) /= null
1905 and then Ultimate_Extending_Project_Of
1906 (Unit
.File_Names
(Spec
).Project
) =
1909 Get_Name_String
(Unit
.File_Names
(Spec
).File
);
1912 File_Extension
(Name
(1 .. Last
))'Length;
1914 if Name_Buffer
(1 .. Name_Len
) =
1915 Name
(1 .. Last
- 4)
1922 Unit
:= Units_Htable
.Get_Next
(In_Tree
.Units_HT
);
1928 Set_Writable
(Filename
);
1929 Delete_File
(Filename
, Disregard
);
1937 Change_Dir
(Current_Dir
);
1940 -- Call procedure to build the library, depending on the build mode
1942 case The_Build_Mode
is
1943 when Dynamic | Relocatable
=>
1944 Build_Dynamic_Library
1945 (Ofiles
=> Object_Files
.all,
1946 Options
=> Options
.all,
1947 Interfaces
=> Arguments
(1 .. Argument_Number
),
1948 Lib_Filename
=> Lib_Filename
.all,
1949 Lib_Dir
=> Lib_Dirpath
.all,
1950 Symbol_Data
=> Current_Proj
.Symbol_Data
,
1951 Driver_Name
=> Driver_Name
,
1952 Lib_Version
=> Lib_Version
.all,
1953 Auto_Init
=> Current_Proj
.Lib_Auto_Init
);
1965 -- We need to copy the ALI files from the object directory to the
1966 -- library ALI directory, so that the linker find them there, and
1967 -- does not need to look in the object directory where it would also
1968 -- find the object files; and we don't want that: we want the linker
1969 -- to use the library.
1971 -- Copy the ALI files and make the copies read-only. For interfaces,
1972 -- mark the copies as interfaces.
1975 (Files
=> Ali_Files
.all,
1976 To
=> For_Project
.Library_ALI_Dir
.Display_Name
,
1977 Interfaces
=> Arguments
(1 .. Argument_Number
));
1979 -- Copy interface sources if Library_Src_Dir specified
1982 and then For_Project
.Library_Src_Dir
/= No_Path_Information
1984 -- Clean the interface copy directory: remove any source that
1985 -- could be a source of the project.
1988 Get_Name_String
(For_Project
.Library_Src_Dir
.Display_Name
);
1989 Change_Dir
(Name_Buffer
(1 .. Name_Len
));
1994 ("unable to access library source copy directory """
1995 & Name_Buffer
(1 .. Name_Len
)
2001 Delete
: Boolean := False;
2004 Name
: String (1 .. 200);
2007 Disregard
: Boolean;
2008 pragma Warnings
(Off
, Disregard
);
2014 Read
(Dir
, Name
, Last
);
2017 if Is_Regular_File
(Name
(1 .. Last
)) then
2018 Canonical_Case_File_Name
(Name
(1 .. Last
));
2021 -- Compare with source file names of the project
2023 Unit
:= Units_Htable
.Get_First
(In_Tree
.Units_HT
);
2024 while Unit
/= No_Unit_Index
loop
2025 if Unit
.File_Names
(Impl
) /= null
2026 and then Ultimate_Extending_Project_Of
2027 (Unit
.File_Names
(Impl
).Project
) = For_Project
2030 (Unit
.File_Names
(Impl
).File
) =
2037 if Unit
.File_Names
(Spec
) /= null
2038 and then Ultimate_Extending_Project_Of
2039 (Unit
.File_Names
(Spec
).Project
) =
2043 (Unit
.File_Names
(Spec
).File
) =
2050 Unit
:= Units_Htable
.Get_Next
(In_Tree
.Units_HT
);
2055 Set_Writable
(Name
(1 .. Last
));
2056 Delete_File
(Name
(1 .. Last
), Disregard
);
2063 Copy_Interface_Sources
2064 (For_Project
=> For_Project
,
2066 Interfaces
=> Arguments
(1 .. Argument_Number
),
2067 To_Dir
=> For_Project
.Library_Src_Dir
.Display_Name
);
2071 -- Reset the current working directory to its previous value
2073 Change_Dir
(Current_Dir
);
2080 procedure Check
(Filename
: String) is
2082 if not Is_Regular_File
(Filename
) then
2083 Com
.Fail
(Filename
& " not found.");
2091 procedure Check_Context
is
2093 -- Check that each object file exists
2095 for F
in Object_Files
'Range loop
2096 Check
(Object_Files
(F
).all);
2104 procedure Check_Library
2105 (For_Project
: Project_Id
; In_Tree
: Project_Tree_Ref
)
2107 Lib_TS
: Time_Stamp_Type
;
2108 Current
: constant Dir_Name_Str
:= Get_Current_Dir
;
2111 -- No need to build the library if there is no object directory,
2112 -- hence no object files to build the library.
2114 if For_Project
.Library
then
2116 Lib_Name
: constant File_Name_Type
:=
2117 Library_File_Name_For
(For_Project
, In_Tree
);
2120 (Get_Name_String
(For_Project
.Library_Dir
.Display_Name
));
2121 Lib_TS
:= File_Stamp
(Lib_Name
);
2122 For_Project
.Library_TS
:= Lib_TS
;
2125 if not For_Project
.Externally_Built
2126 and then not For_Project
.Need_To_Build_Lib
2127 and then For_Project
.Object_Directory
/= No_Path_Information
2130 Obj_TS
: Time_Stamp_Type
;
2131 Object_Dir
: Dir_Type
;
2134 if OpenVMS_On_Target
then
2135 B_Start
:= new String'("b__");
2138 -- If the library file does not exist, then the time stamp will
2139 -- be Empty_Time_Stamp, earlier than any other time stamp.
2142 (Get_Name_String (For_Project.Object_Directory.Display_Name));
2143 Open (Dir => Object_Dir, Dir_Name => ".");
2145 -- For all entries in the object directory
2148 Read (Object_Dir, Name_Buffer, Name_Len);
2149 exit when Name_Len = 0;
2151 -- Check if it is an object file, but ignore any binder
2154 if Is_Obj (Name_Buffer (1 .. Name_Len))
2155 and then Name_Buffer (1 .. B_Start'Length) /= B_Start.all
2157 -- Get the object file time stamp
2159 Obj_TS := File_Stamp (File_Name_Type'(Name_Find
));
2161 -- If library file time stamp is earlier, set
2162 -- Need_To_Build_Lib and return. String comparison is
2163 -- used, otherwise time stamps may be too close and the
2164 -- comparison would return True, which would trigger
2165 -- an unnecessary rebuild of the library.
2167 if String (Lib_TS
) < String (Obj_TS
) then
2169 -- Library must be rebuilt
2171 For_Project
.Need_To_Build_Lib
:= True;
2181 Change_Dir
(Current
);
2185 ----------------------------
2186 -- Copy_Interface_Sources --
2187 ----------------------------
2189 procedure Copy_Interface_Sources
2190 (For_Project
: Project_Id
;
2191 In_Tree
: Project_Tree_Ref
;
2192 Interfaces
: Argument_List
;
2193 To_Dir
: Path_Name_Type
)
2195 Current
: constant Dir_Name_Str
:= Get_Current_Dir
;
2196 -- The current directory, where to return to at the end
2198 Target
: constant Dir_Name_Str
:= Get_Name_String
(To_Dir
);
2199 -- The directory where to copy sources
2201 Text
: Text_Buffer_Ptr
;
2202 The_ALI
: ALI
.ALI_Id
;
2203 Lib_File
: File_Name_Type
;
2205 First_Unit
: ALI
.Unit_Id
;
2206 Second_Unit
: ALI
.Unit_Id
;
2208 Copy_Subunits
: Boolean := False;
2209 -- When True, indicates that subunits, if any, need to be copied too
2211 procedure Copy
(File_Name
: File_Name_Type
);
2212 -- Copy one source of the project to the target directory
2218 procedure Copy
(File_Name
: File_Name_Type
) is
2220 pragma Warnings
(Off
, Success
);
2222 Source
: Standard
.Prj
.Source_Id
;
2224 Source
:= Find_Source
2225 (In_Tree
, For_Project
,
2226 In_Extended_Only
=> True,
2227 Base_Name
=> File_Name
);
2229 if Source
/= No_Source
2230 and then not Source
.Locally_Removed
2231 and then Source
.Replaced_By
= No_Source
2234 (Get_Name_String
(Source
.Path
.Name
),
2238 Preserve
=> Preserve
);
2242 -- Start of processing for Copy_Interface_Sources
2245 -- Change the working directory to the object directory
2247 Change_Dir
(Get_Name_String
(For_Project
.Object_Directory
.Display_Name
));
2249 for Index
in Interfaces
'Range loop
2251 -- First, load the ALI file
2254 Add_Str_To_Name_Buffer
(Interfaces
(Index
).all);
2255 Lib_File
:= Name_Find
;
2256 Text
:= Read_Library_Info
(Lib_File
);
2257 The_ALI
:= Scan_ALI
(Lib_File
, Text
, Ignore_ED
=> False, Err
=> True);
2260 Second_Unit
:= No_Unit_Id
;
2261 First_Unit
:= ALI
.ALIs
.Table
(The_ALI
).First_Unit
;
2262 Copy_Subunits
:= True;
2264 -- If there is both a spec and a body, check if they are both needed
2266 if ALI
.Units
.Table
(First_Unit
).Utype
= Is_Body
then
2267 Second_Unit
:= ALI
.ALIs
.Table
(The_ALI
).Last_Unit
;
2269 -- If the body is not needed, then reset First_Unit
2271 if not ALI
.Units
.Table
(Second_Unit
).Body_Needed_For_SAL
then
2272 First_Unit
:= No_Unit_Id
;
2273 Copy_Subunits
:= False;
2276 elsif ALI
.Units
.Table
(First_Unit
).Utype
= Is_Spec_Only
then
2277 Copy_Subunits
:= False;
2280 -- Copy the file(s) that need to be copied
2282 if First_Unit
/= No_Unit_Id
then
2283 Copy
(File_Name
=> ALI
.Units
.Table
(First_Unit
).Sfile
);
2286 if Second_Unit
/= No_Unit_Id
then
2287 Copy
(File_Name
=> ALI
.Units
.Table
(Second_Unit
).Sfile
);
2290 -- Copy all the separates, if any
2292 if Copy_Subunits
then
2293 for Dep
in ALI
.ALIs
.Table
(The_ALI
).First_Sdep
..
2294 ALI
.ALIs
.Table
(The_ALI
).Last_Sdep
2296 if Sdep
.Table
(Dep
).Subunit_Name
/= No_Name
then
2297 Copy
(File_Name
=> Sdep
.Table
(Dep
).Sfile
);
2303 -- Restore the initial working directory
2305 Change_Dir
(Current
);
2306 end Copy_Interface_Sources
;
2312 procedure Display
(Executable
: String) is
2314 if not Opt
.Quiet_Output
then
2315 Write_Str
(Executable
);
2317 for Index
in 1 .. Argument_Number
loop
2319 Write_Str
(Arguments
(Index
).all);
2321 if not Opt
.Verbose_Mode
and then Index
> 4 then
2335 function Index
(S
, Pattern
: String) return Natural is
2336 Len
: constant Natural := Pattern
'Length;
2339 for J
in reverse S
'First .. S
'Last - Len
+ 1 loop
2340 if Pattern
= S
(J
.. J
+ Len
- 1) then
2348 -------------------------
2349 -- Process_Binder_File --
2350 -------------------------
2352 procedure Process_Binder_File
(Name
: String) is
2354 -- Binder file's descriptor
2356 Read_Mode
: constant String := "r" & ASCII
.NUL
;
2359 Status
: Interfaces
.C_Streams
.int
;
2360 pragma Unreferenced
(Status
);
2363 Begin_Info
: constant String := "-- BEGIN Object file/option list";
2364 End_Info
: constant String := "-- END Object file/option list ";
2366 Next_Line
: String (1 .. 1000);
2367 -- Current line value
2368 -- Where does this odd constant 1000 come from, looks suspicious ???
2371 -- End of line slice (the slice does not contain the line terminator)
2373 procedure Get_Next_Line
;
2374 -- Read the next line from the binder file without the line terminator
2380 procedure Get_Next_Line
is
2384 Fchars
:= fgets
(Next_Line
'Address, Next_Line
'Length, Fd
);
2386 if Fchars
= System
.Null_Address
then
2387 Fail
("Error reading binder output");
2391 while Nlast
<= Next_Line
'Last
2392 and then Next_Line
(Nlast
) /= ASCII
.LF
2393 and then Next_Line
(Nlast
) /= ASCII
.CR
2401 -- Start of processing for Process_Binder_File
2404 Fd
:= fopen
(Name
'Address, Read_Mode
'Address);
2406 if Fd
= NULL_Stream
then
2407 Fail
("Failed to open binder output");
2410 -- Skip up to the Begin Info line
2414 exit when Next_Line
(1 .. Nlast
) = Begin_Info
;
2417 -- Find the first switch
2422 exit when Next_Line
(1 .. Nlast
) = End_Info
;
2424 -- As the binder generated file is in Ada, remove the first eight
2425 -- characters " -- ".
2427 Next_Line
(1 .. Nlast
- 8) := Next_Line
(9 .. Nlast
);
2430 -- Stop when the first switch is found
2432 exit when Next_Line
(1) = '-';
2435 if Next_Line
(1 .. Nlast
) /= End_Info
then
2437 -- Ignore -static and -shared, since -shared will be used
2440 -- Ignore -lgnat, -lgnarl and -ldecgnat as they will be added
2441 -- later, because they are also needed for non Stand-Alone shared
2444 -- Also ignore the shared libraries which are :
2446 -- UNIX / Windows VMS
2447 -- -lgnat-<version> -lgnat_<version> (7 + version'length chars)
2448 -- -lgnarl-<version> -lgnarl_<version> (8 + version'length chars)
2450 if Next_Line
(1 .. Nlast
) /= "-static" and then
2451 Next_Line
(1 .. Nlast
) /= "-shared" and then
2452 Next_Line
(1 .. Nlast
) /= "-ldecgnat" and then
2453 Next_Line
(1 .. Nlast
) /= "-lgnarl" and then
2454 Next_Line
(1 .. Nlast
) /= "-lgnat" and then
2456 (1 .. Natural'Min (Nlast
, 10 + Library_Version
'Length)) /=
2457 Shared_Lib
("decgnat") and then
2459 (1 .. Natural'Min (Nlast
, 8 + Library_Version
'Length)) /=
2460 Shared_Lib
("gnarl") and then
2462 (1 .. Natural'Min (Nlast
, 7 + Library_Version
'Length)) /=
2465 if Next_Line
(1) /= '-' then
2467 -- This is not an option, should we add it?
2469 if Add_Object_Files
then
2470 Opts
.Increment_Last
;
2471 Opts
.Table
(Opts
.Last
) :=
2472 new String'(Next_Line (1 .. Nlast));
2476 -- Add all other options
2478 Opts.Increment_Last;
2479 Opts.Table (Opts.Last) :=
2480 new String'(Next_Line
(1 .. Nlast
));
2484 -- Next option, if any
2487 exit when Next_Line
(1 .. Nlast
) = End_Info
;
2489 -- Remove first eight characters " -- "
2491 Next_Line
(1 .. Nlast
- 8) := Next_Line
(9 .. Nlast
);
2496 Status
:= fclose
(Fd
);
2498 -- Is it really right to ignore any close error ???
2500 end Process_Binder_File
;
2506 procedure Reset_Tables
is
2509 Objects_Htable
.Reset
;
2512 Processed_Projects
.Reset
;
2516 ---------------------------
2517 -- SALs_Use_Constructors --
2518 ---------------------------
2520 function SALs_Use_Constructors
return Boolean is
2521 function C_SALs_Init_Using_Constructors
return Integer;
2522 pragma Import
(C
, C_SALs_Init_Using_Constructors
,
2523 "__gnat_sals_init_using_constructors");
2525 return C_SALs_Init_Using_Constructors
/= 0;
2526 end SALs_Use_Constructors
;