1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2007, AdaCore --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
28 with Gnatvsn; use Gnatvsn;
29 with MLib.Fil; use MLib.Fil;
30 with MLib.Tgt; use MLib.Tgt;
31 with MLib.Utl; use MLib.Utl;
33 with Output; use Output;
34 with Prj.Com; use Prj.Com;
35 with Prj.Env; use Prj.Env;
36 with Prj.Util; use Prj.Util;
38 with Snames; use Snames;
39 with Switch; use Switch;
41 with Targparm; use Targparm;
43 with Types; use Types;
45 with Ada.Characters.Handling;
47 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
50 with Interfaces.C_Streams; use Interfaces.C_Streams;
51 with System; use System;
52 with System.Case_Util; use System.Case_Util;
54 package body MLib.Prj is
56 Prj_Add_Obj_Files : Types.Int;
57 pragma Import (C, Prj_Add_Obj_Files, "__gnat_prj_add_obj_files");
58 Add_Object_Files : constant Boolean := Prj_Add_Obj_Files /= 0;
59 -- Indicates if object files in pragmas Linker_Options (found in the
60 -- binder generated file) should be taken when linking a stand-alone
61 -- library. False for Windows, True for other platforms.
63 ALI_Suffix : constant String := ".ali";
65 B_Start : String_Ptr := new String'("b~");
66 -- Prefix of bind file, changed to b__ for VMS
68 S_Osinte_Ads : File_Name_Type := No_File;
69 -- Name_Id for "s-osinte.ads"
71 S_Dec_Ads : File_Name_Type := No_File;
72 -- Name_Id for "dec.ads"
74 G_Trasym_Ads : File_Name_Type := No_File;
75 -- Name_Id for "g-trasym.ads"
77 No_Argument_List : aliased String_List := (1 .. 0 => null);
78 No_Argument : constant String_List_Access := No_Argument_List'Access;
80 Arguments : String_List_Access := No_Argument;
81 -- Used to accumulate arguments for the invocation of gnatbind and of
82 -- the compiler. Also used to collect the interface ALI when copying
83 -- the ALI files to the library directory.
85 Argument_Number : Natural := 0;
86 -- Index of the last argument in Arguments
88 Initial_Argument_Max : constant := 10;
90 No_Main_String : aliased String := "-n";
91 No_Main : constant String_Access := No_Main_String'Access;
93 Output_Switch_String : aliased String := "-o";
94 Output_Switch : constant String_Access := Output_Switch_String'Access;
96 Compile_Switch_String : aliased String := "-c";
97 Compile_Switch : constant String_Access := Compile_Switch_String'Access;
99 Auto_Initialize : constant String := "-a";
101 -- List of objects to put inside the library
103 Object_Files : Argument_List_Access;
105 package Objects is new Table.Table
106 (Table_Name => "Mlib.Prj.Objects",
107 Table_Component_Type => String_Access,
108 Table_Index_Type => Natural,
109 Table_Low_Bound => 1,
111 Table_Increment => 100);
113 package Objects_Htable is new GNAT.HTable.Simple_HTable
114 (Header_Num => Header_Num,
121 -- List of non-Ada object files
123 Foreign_Objects : Argument_List_Access;
125 package Foreigns is new Table.Table
126 (Table_Name => "Mlib.Prj.Foreigns",
127 Table_Component_Type => String_Access,
128 Table_Index_Type => Natural,
129 Table_Low_Bound => 1,
131 Table_Increment => 100);
135 Ali_Files : Argument_List_Access;
137 package ALIs is new Table.Table
138 (Table_Name => "Mlib.Prj.Alis",
139 Table_Component_Type => String_Access,
140 Table_Index_Type => Natural,
141 Table_Low_Bound => 1,
143 Table_Increment => 100);
145 -- List of options set in the command line
147 Options : Argument_List_Access;
149 package Opts is new Table.Table
150 (Table_Name => "Mlib.Prj.Opts",
151 Table_Component_Type => String_Access,
152 Table_Index_Type => Natural,
153 Table_Low_Bound => 1,
155 Table_Increment => 100);
157 -- All the ALI file in the library
159 package Library_ALIs is new GNAT.HTable.Simple_HTable
160 (Header_Num => Header_Num,
163 Key => File_Name_Type,
167 -- The ALI files in the interface sets
169 package Interface_ALIs is new GNAT.HTable.Simple_HTable
170 (Header_Num => Header_Num,
173 Key => File_Name_Type,
177 -- The ALI files that have been processed to check if the corresponding
178 -- library unit is in the interface set.
180 package Processed_ALIs is new GNAT.HTable.Simple_HTable
181 (Header_Num => Header_Num,
184 Key => File_Name_Type,
188 -- The projects imported directly or indirectly
190 package Processed_Projects is new GNAT.HTable.Simple_HTable
191 (Header_Num => Header_Num,
198 -- The library projects imported directly or indirectly
200 package Library_Projs is new Table.Table (
201 Table_Component_Type => Project_Id,
202 Table_Index_Type => Integer,
203 Table_Low_Bound => 1,
205 Table_Increment => 10,
206 Table_Name => "Make.Library_Projs");
208 type Build_Mode_State is (None, Static, Dynamic, Relocatable);
210 procedure Add_Argument (S : String);
211 -- Add one argument to Arguments array, if array is full, double its size
213 function ALI_File_Name (Source : String) return String;
214 -- Return the ALI file name corresponding to a source
216 procedure Check (Filename : String);
217 -- Check if filename is a regular file. Fail if it is not
219 procedure Check_Context;
220 -- Check each object files in table Object_Files
221 -- Fail if any of them is not a regular file
223 procedure Copy_Interface_Sources
224 (For_Project : Project_Id;
225 In_Tree : Project_Tree_Ref;
226 Interfaces : Argument_List;
227 To_Dir : Path_Name_Type);
228 -- Copy the interface sources of a SAL to directory To_Dir
230 procedure Display (Executable : String);
231 -- Display invocation of gnatbind and of the compiler with the arguments
232 -- in Arguments, except when Quiet_Output is True.
234 function Index (S, Pattern : String) return Natural;
235 -- Return the last occurrence of Pattern in S, or 0 if none
237 procedure Process_Binder_File (Name : String);
238 -- For Stand-Alone libraries, get the Linker Options in the binder
241 procedure Reset_Tables;
242 -- Make sure that all the above tables are empty
243 -- (Objects, ALIs, Options, ...).
245 function SALs_Use_Constructors return Boolean;
246 -- Indicate if Stand-Alone Libraries are automatically initialized using
247 -- the constructor mechanism.
249 function Ultimate_Extension_Of
250 (Project : Project_Id;
251 In_Tree : Project_Tree_Ref) return Project_Id;
252 -- Returns the Project_Id of project Project. Returns No_Project
253 -- if Project is No_Project.
259 procedure Add_Argument (S : String) is
261 if Argument_Number = Arguments'Last then
263 New_Args : constant String_List_Access :=
264 new String_List (1 .. 2 * Arguments'Last);
267 -- Copy the String_Accesses and set them to null in Arguments
268 -- so that they will not be deallocated by the call to
271 New_Args (Arguments'Range) := Arguments.all;
272 Arguments.all := (others => null);
274 Arguments := New_Args;
278 Argument_Number := Argument_Number + 1;
279 Arguments (Argument_Number) := new String'(S);
286 function ALI_File_Name (Source : String) return String is
288 -- If the source name has an extension, then replace it with
291 for Index in reverse Source'First + 1 .. Source'Last loop
292 if Source (Index) = '.' then
293 return Source (Source'First .. Index - 1) & ALI_Suffix;
297 -- If there is no dot, or if it is the first character, just add the
300 return Source & ALI_Suffix;
307 procedure Build_Library
308 (For_Project : Project_Id;
309 In_Tree : Project_Tree_Ref;
311 Gnatbind_Path : String_Access;
313 Gcc_Path : String_Access;
314 Bind : Boolean := True;
315 Link : Boolean := True)
317 Maximum_Size : Integer;
318 pragma Import (C, Maximum_Size, "__gnat_link_max");
319 -- Maximum number of bytes to put in an invocation of the
323 -- The number of bytes for the invocation of the gnatbind
325 Warning_For_Library : Boolean := False;
326 -- Set to True for the first warning about a unit missing from the
329 Gtrasymobj_Needed : Boolean := False;
330 -- On OpenVMS, set to True if library needs to be linked with
333 Data : Project_Data := In_Tree.Projects.Table (For_Project);
335 Libgnarl_Needed : Yes_No_Unknown := Data.Libgnarl_Needed;
336 -- Set to True if library needs to be linked with libgnarl
338 Libdecgnat_Needed : Boolean := False;
339 -- On OpenVMS, set to True if library needs to be linked with libdecgnat
341 Object_Directory_Path : constant String :=
342 Get_Name_String (Data.Display_Object_Dir);
344 Standalone : constant Boolean := Data.Standalone_Library;
346 Project_Name : constant String := Get_Name_String (Data.Name);
348 Current_Dir : constant String := Get_Current_Dir;
350 Lib_Filename : String_Access;
351 Lib_Dirpath : String_Access;
352 Lib_Version : String_Access := new String'("");
354 The_Build_Mode : Build_Mode_State := None;
356 Success : Boolean := False;
358 Library_Options : Variable_Value := Nil_Variable_Value;
359 Library_GCC : Variable_Value := Nil_Variable_Value;
361 Driver_Name : Name_Id := No_Name;
363 In_Main_Object_Directory : Boolean := True;
365 Rpath : String_Access := null;
366 -- Allocated only if Path Option is supported
368 Rpath_Last : Natural := 0;
369 -- Index of last valid character of Rpath
371 Initial_Rpath_Length : constant := 200;
372 -- Initial size of Rpath, when first allocated
374 Path_Option : String_Access := Linker_Library_Path_Option;
375 -- If null, Path Option is not supported.
376 -- Not a constant so that it can be deallocated.
378 First_ALI : File_Name_Type := No_File;
379 -- Store the ALI file name of a source of the library (the first found)
381 procedure Add_ALI_For (Source : File_Name_Type);
382 -- Add the name of the ALI file corresponding to Source to the arguments
384 procedure Add_Rpath (Path : String);
385 -- Add a path name to Rpath
387 function Check_Project (P : Project_Id) return Boolean;
388 -- Returns True if P is For_Project or a project extended by For_Project
390 procedure Check_Libs (ALI_File : String; Main_Project : Boolean);
391 -- Set Libgnarl_Needed if the ALI_File indicates that there is a need
392 -- to link with -lgnarl (this is the case when there is a dependency
393 -- on s-osinte.ads). On OpenVMS, set Libdecgnat_Needed if the ALI file
394 -- indicates that there is a need to link with -ldecgnat (this is the
395 -- case when there is a dependency on dec.ads), and set
396 -- Gtrasymobj_Needed if there is a dependency on g-trasym.ads.
398 procedure Process (The_ALI : File_Name_Type);
399 -- Check if the closure of a library unit which is or should be in the
400 -- interface set is also in the interface set. Issue a warning for each
401 -- missing library unit.
403 procedure Process_Imported_Libraries;
404 -- Add the -L and -l switches for the imported Library Project Files,
405 -- and, if Path Option is supported, the library directory path names
412 procedure Add_ALI_For (Source : File_Name_Type) is
413 ALI : constant String := ALI_File_Name (Get_Name_String (Source));
414 ALI_Id : File_Name_Type;
422 Add_Str_To_Name_Buffer (S => ALI);
425 -- Add the ALI file name to the library ALIs
428 Library_ALIs.Set (ALI_Id, True);
431 -- Set First_ALI, if not already done
433 if First_ALI = No_File then
442 procedure Add_Rpath (Path : String) is
452 New_Rpath : constant String_Access :=
453 new String (1 .. 2 * Rpath'Length);
455 New_Rpath (1 .. Rpath_Last) := Rpath (1 .. Rpath_Last);
460 -- Start of processing for Add_Rpath
463 -- If firt path, allocate initial Rpath
466 Rpath := new String (1 .. Initial_Rpath_Length);
470 -- Otherwise, add a path separator between two path names
472 if Rpath_Last = Rpath'Last then
476 Rpath_Last := Rpath_Last + 1;
477 Rpath (Rpath_Last) := Path_Separator;
480 -- Increase Rpath size until it is large enough
482 while Rpath_Last + Path'Length > Rpath'Last loop
488 Rpath (Rpath_Last + 1 .. Rpath_Last + Path'Length) := Path;
489 Rpath_Last := Rpath_Last + Path'Length;
496 function Check_Project (P : Project_Id) return Boolean is
498 if P = For_Project then
501 elsif P /= No_Project then
503 Data : Project_Data :=
504 In_Tree.Projects.Table (For_Project);
506 while Data.Extends /= No_Project loop
507 if P = Data.Extends then
511 Data := In_Tree.Projects.Table (Data.Extends);
523 procedure Check_Libs (ALI_File : String; Main_Project : Boolean) is
524 Lib_File : File_Name_Type;
525 Text : Text_Buffer_Ptr;
529 if Libgnarl_Needed /= Yes
532 and then OpenVMS_On_Target
533 and then ((not Libdecgnat_Needed) or (not Gtrasymobj_Needed)))
537 Name_Len := ALI_File'Length;
538 Name_Buffer (1 .. Name_Len) := ALI_File;
539 Lib_File := Name_Find;
540 Text := Read_Library_Info (Lib_File, True);
550 -- Look for s-osinte.ads in the dependencies
552 for Index in ALI.ALIs.Table (Id).First_Sdep ..
553 ALI.ALIs.Table (Id).Last_Sdep
555 if ALI.Sdep.Table (Index).Sfile = S_Osinte_Ads then
556 Libgnarl_Needed := Yes;
559 In_Tree.Projects.Table (For_Project).Libgnarl_Needed :=
565 elsif OpenVMS_On_Target then
566 if ALI.Sdep.Table (Index).Sfile = S_Dec_Ads then
567 Libdecgnat_Needed := True;
569 elsif ALI.Sdep.Table (Index).Sfile = G_Trasym_Ads then
570 Gtrasymobj_Needed := True;
581 procedure Process (The_ALI : File_Name_Type) is
582 Text : Text_Buffer_Ptr;
584 First_Unit : ALI.Unit_Id;
585 Last_Unit : ALI.Unit_Id;
586 Unit_Data : Unit_Record;
587 Afile : File_Name_Type;
590 -- Nothing to do if the ALI file has already been processed.
591 -- This happens if an interface imports another interface.
593 if not Processed_ALIs.Get (The_ALI) then
594 Processed_ALIs.Set (The_ALI, True);
595 Text := Read_Library_Info (The_ALI);
606 if Idread /= No_ALI_Id then
607 First_Unit := ALI.ALIs.Table (Idread).First_Unit;
608 Last_Unit := ALI.ALIs.Table (Idread).Last_Unit;
610 -- Process both unit (spec and body) if the body is needed
611 -- by the spec (inline or generic). Otherwise, just process
614 if First_Unit /= Last_Unit and then
615 not ALI.Units.Table (Last_Unit).Body_Needed_For_SAL
617 First_Unit := Last_Unit;
620 for Unit in First_Unit .. Last_Unit loop
621 Unit_Data := ALI.Units.Table (Unit);
623 -- Check if each withed unit which is in the library is
624 -- also in the interface set, if it has not yet been
627 for W in Unit_Data.First_With .. Unit_Data.Last_With loop
628 Afile := Withs.Table (W).Afile;
630 if Afile /= No_File and then Library_ALIs.Get (Afile)
631 and then not Processed_ALIs.Get (Afile)
633 if not Interface_ALIs.Get (Afile) then
634 if not Warning_For_Library then
635 Write_Str ("Warning: In library project """);
636 Get_Name_String (Data.Name);
637 To_Mixed (Name_Buffer (1 .. Name_Len));
638 Write_Str (Name_Buffer (1 .. Name_Len));
640 Warning_For_Library := True;
643 Write_Str (" Unit """);
644 Get_Name_String (Withs.Table (W).Uname);
645 To_Mixed (Name_Buffer (1 .. Name_Len - 2));
646 Write_Str (Name_Buffer (1 .. Name_Len - 2));
647 Write_Line (""" is not in the interface set");
648 Write_Str (" but it is needed by ");
650 case Unit_Data.Utype is
652 Write_Str ("the spec of ");
655 Write_Str ("the body of ");
662 Get_Name_String (Unit_Data.Uname);
663 To_Mixed (Name_Buffer (1 .. Name_Len - 2));
664 Write_Str (Name_Buffer (1 .. Name_Len - 2));
668 -- Now, process this unit
679 --------------------------------
680 -- Process_Imported_Libraries --
681 --------------------------------
683 procedure Process_Imported_Libraries is
684 Current : Project_Id;
686 procedure Process_Project (Project : Project_Id);
687 -- Process Project and its imported projects recursively.
688 -- Add any library projects to table Library_Projs.
690 ---------------------
691 -- Process_Project --
692 ---------------------
694 procedure Process_Project (Project : Project_Id) is
695 Data : Project_Data := In_Tree.Projects.Table (Project);
696 Imported : Project_List := Data.Imported_Projects;
697 Element : Project_Element;
700 -- Nothing to do if process has already been processed
702 if not Processed_Projects.Get (Data.Name) then
703 Processed_Projects.Set (Data.Name, True);
705 -- Call Process_Project recursively for any imported project.
706 -- We first process the imported projects to guarantee that
707 -- we have a proper reverse order for the libraries.
709 while Imported /= Empty_Project_List loop
711 In_Tree.Project_Lists.Table (Imported);
713 if Element.Project /= No_Project then
714 Process_Project (Element.Project);
717 Imported := Element.Next;
720 -- If it is a library project, add it to Library_Projs
722 if Project /= For_Project and then Data.Library then
723 Library_Projs.Increment_Last;
724 Library_Projs.Table (Library_Projs.Last) := Project;
726 -- Check if because of this library we need to use libgnarl
728 if Libgnarl_Needed = Unknown then
729 if Data.Libgnarl_Needed = Unknown
730 and then Data.Object_Directory /= No_Path
732 -- Check if libgnarl is needed for this library
735 Object_Dir_Path : constant String :=
737 (Data.Display_Object_Dir);
738 Object_Dir : Dir_Type;
739 Filename : String (1 .. 255);
743 Open (Object_Dir, Object_Dir_Path);
745 -- For all entries in the object directory
748 Read (Object_Dir, Filename, Last);
751 -- Check if it is an object file
753 if Is_Obj (Filename (1 .. Last)) then
755 Object_Path : constant String :=
758 Directory_Separator &
759 Filename (1 .. Last));
760 ALI_File : constant String :=
762 (Object_Path, "ali");
765 if Is_Regular_File (ALI_File) then
767 -- Find out if for this ALI file,
768 -- libgnarl is necessary.
771 (ALI_File, Main_Project => False);
773 if Libgnarl_Needed = Yes then
774 Data.Libgnarl_Needed := Yes;
775 In_Tree.Projects.Table
776 (For_Project).Libgnarl_Needed :=
789 if Data.Libgnarl_Needed = Yes then
790 Libgnarl_Needed := Yes;
791 In_Tree.Projects.Table (For_Project).Libgnarl_Needed :=
800 -- Start of processing for Process_Imported_Libraries
803 -- Build list of library projects imported directly or indirectly,
804 -- in the reverse order.
806 Process_Project (For_Project);
808 -- Add the -L and -l switches and, if the Rpath option is supported,
809 -- add the directory to the Rpath.
811 -- As the library projects are in the wrong order, process from the
812 -- last to the first.
814 for Index in reverse 1 .. Library_Projs.Last loop
815 Current := Library_Projs.Table (Index);
818 (In_Tree.Projects.Table (Current).Display_Library_Dir);
820 Opts.Table (Opts.Last) :=
821 new String'("-L" & Name_Buffer (1 .. Name_Len));
823 if Path_Option /= null then
824 Add_Rpath (Name_Buffer (1 .. Name_Len));
828 Opts.Table (Opts.Last) :=
832 (In_Tree.Projects.Table
833 (Current).Library_Name));
835 end Process_Imported_Libraries;
837 -- Start of processing for Build_Library
842 -- Fail if project is not a library project
844 if not Data.Library then
845 Com.Fail ("project """, Project_Name, """ has no library");
848 -- If this is the first time Build_Library is called, get the Name_Id
849 -- values of "s-osinte.ads", "dec.ads", and "g-trasym.ads".
851 if S_Osinte_Ads = No_File then
853 Add_Str_To_Name_Buffer ("s-osinte.ads");
854 S_Osinte_Ads := Name_Find;
857 if S_Dec_Ads = No_File then
859 Add_Str_To_Name_Buffer ("dec.ads");
860 S_Dec_Ads := Name_Find;
863 if G_Trasym_Ads = No_File then
865 Add_Str_To_Name_Buffer ("g-trasym.ads");
866 G_Trasym_Ads := Name_Find;
869 -- We work in the object directory
871 Change_Dir (Object_Directory_Path);
875 -- Call gnatbind only if Bind is True
878 if Gnatbind_Path = null then
879 Com.Fail ("unable to locate ", Gnatbind);
882 if Gcc_Path = null then
883 Com.Fail ("unable to locate ", Gcc);
886 -- Allocate Arguments, if it is the first time we see a standalone
889 if Arguments = No_Argument then
890 Arguments := new String_List (1 .. Initial_Argument_Max);
893 -- Add "-n -o b~<lib>.adb (b__<lib>.adb on VMS) -L<lib>"
895 Argument_Number := 2;
896 Arguments (1) := No_Main;
897 Arguments (2) := Output_Switch;
899 if OpenVMS_On_Target then
900 B_Start := new String'("b__");
904 (B_Start.all & Get_Name_String (Data.Library_Name) & ".adb");
905 Add_Argument ("-L" & Get_Name_String (Data.Library_Name));
907 if Data.Lib_Auto_Init and then SALs_Use_Constructors then
908 Add_Argument (Auto_Initialize);
911 -- Check if Binder'Default_Switches ("Ada") is defined. If it is,
912 -- add these switches to call gnatbind.
915 Binder_Package : constant Package_Id :=
917 (Name => Name_Binder,
918 In_Packages => Data.Decl.Packages,
922 if Binder_Package /= No_Package then
924 Defaults : constant Array_Element_Id :=
926 (Name => Name_Default_Switches,
928 In_Tree.Packages.Table
929 (Binder_Package).Decl.Arrays,
931 Switches : Variable_Value := Nil_Variable_Value;
933 Switch : String_List_Id := Nil_String;
936 if Defaults /= No_Array_Element then
941 In_Array => Defaults,
944 if not Switches.Default then
945 Switch := Switches.Values;
947 while Switch /= Nil_String loop
950 (In_Tree.String_Elements.Table
952 Switch := In_Tree.String_Elements.
962 -- Get all the ALI files of the project file. We do that even if
963 -- Bind is False, so that First_ALI is set.
970 Interface_ALIs.Reset;
971 Processed_ALIs.Reset;
973 for Source in Unit_Table.First ..
974 Unit_Table.Last (In_Tree.Units)
976 Unit := In_Tree.Units.Table (Source);
978 if Unit.File_Names (Body_Part).Name /= No_File
979 and then Unit.File_Names (Body_Part).Path /= Slash
982 Check_Project (Unit.File_Names (Body_Part).Project)
984 if Unit.File_Names (Specification).Name = No_File then
986 Src_Ind : Source_File_Index;
989 Src_Ind := Sinput.P.Load_Project_File
991 (Unit.File_Names (Body_Part).Path));
993 -- Add the ALI file only if it is not a subunit
996 not Sinput.P.Source_File_Is_Subunit (Src_Ind)
999 (Unit.File_Names (Body_Part).Name);
1005 Add_ALI_For (Unit.File_Names (Body_Part).Name);
1010 elsif Unit.File_Names (Specification).Name /= No_File
1011 and then Unit.File_Names (Specification).Path /= Slash
1012 and then Check_Project
1013 (Unit.File_Names (Specification).Project)
1015 Add_ALI_For (Unit.File_Names (Specification).Name);
1021 -- Continue setup and call gnatbind if Bind is True
1025 -- Get an eventual --RTS from the ALI file
1027 if First_ALI /= No_File then
1029 T : Text_Buffer_Ptr;
1033 -- Load the ALI file
1035 T := Read_Library_Info (First_ALI, True);
1040 (First_ALI, T, Ignore_ED => False, Err => False);
1042 if A /= No_ALI_Id then
1045 (ALI.ALIs.Table (A).First_Unit).First_Arg ..
1047 (ALI.ALIs.Table (A).First_Unit).Last_Arg
1049 -- Look for --RTS. If found, add the switch to call
1053 Arg : String_Ptr renames Args.Table (Index);
1055 if Arg'Length >= 6 and then
1056 Arg (Arg'First + 2 .. Arg'First + 5) = "RTS="
1058 Add_Argument (Arg.all);
1070 (Project => For_Project,
1072 Including_Libraries => True);
1074 -- Display the gnatbind command, if not in quiet output
1078 -- Check the size of the arguments
1081 for J in 1 .. Argument_Number loop
1082 Size := Size + Arguments (J)'Length + 1;
1085 -- Invoke gnatbind with the arguments if the size is not too large
1087 if Size <= Maximum_Size then
1090 Arguments (1 .. Argument_Number),
1094 -- Otherwise create a temporary response file
1097 FD : File_Descriptor;
1098 Path : Path_Name_Type;
1099 Args : Argument_List (1 .. 1);
1100 EOL : constant String (1 .. 1) := (1 => ASCII.LF);
1103 Quotes_Needed : Boolean;
1104 Last_Char : Natural;
1108 Tempdir.Create_Temp_File (FD, Path);
1109 Args (1) := new String'("@" & Get_Name_String (Path));
1111 for J in 1 .. Argument_Number loop
1113 -- Check if the argument should be quoted
1115 Quotes_Needed := False;
1116 Last_Char := Arguments (J)'Length;
1118 for K in Arguments (J)'Range loop
1119 Ch := Arguments (J) (K);
1121 if Ch = ' ' or else Ch = ASCII.HT or else Ch = '"' then
1122 Quotes_Needed := True;
1127 if Quotes_Needed then
1129 -- Quote the argument, doubling '"'
1132 Arg : String (1 .. Arguments (J)'Length * 2 + 2);
1138 for K in Arguments (J)'Range loop
1139 Ch := Arguments (J) (K);
1140 Last_Char := Last_Char + 1;
1141 Arg (Last_Char) := Ch;
1144 Last_Char := Last_Char + 1;
1145 Arg (Last_Char) := '"';
1149 Last_Char := Last_Char + 1;
1150 Arg (Last_Char) := '"';
1152 Status := Write (FD, Arg'Address, Last_Char);
1158 Arguments (J) (Arguments (J)'First)'Address,
1162 if Status /= Last_Char then
1166 Status := Write (FD, EOL (1)'Address, 1);
1175 -- And invoke gnatbind with this this response file
1177 Spawn (Gnatbind_Path.all, Args, Success);
1179 Delete_File (Get_Name_String (Path), Succ);
1188 Com.Fail ("could not bind standalone library ",
1189 Get_Name_String (Data.Library_Name));
1193 -- Compile the binder generated file only if Link is true
1200 (Project => For_Project,
1202 Including_Libraries => True);
1204 -- Invoke <gcc> -c b__<lib>.adb
1206 -- Allocate Arguments, if it is the first time we see a standalone
1209 if Arguments = No_Argument then
1210 Arguments := new String_List (1 .. Initial_Argument_Max);
1213 Argument_Number := 1;
1214 Arguments (1) := Compile_Switch;
1216 if OpenVMS_On_Target then
1217 B_Start := new String'("b__");
1221 (B_Start.all & Get_Name_String (Data.Library_Name) & ".adb");
1223 -- If necessary, add the PIC option
1225 if PIC_Option /= "" then
1226 Add_Argument (PIC_Option);
1229 -- Get the back-end switches and --RTS from the ALI file
1231 if First_ALI /= No_File then
1233 T : Text_Buffer_Ptr;
1237 -- Load the ALI file
1239 T := Read_Library_Info (First_ALI, True);
1244 (First_ALI, T, Ignore_ED => False, Err => False);
1246 if A /= No_ALI_Id then
1249 (ALI.ALIs.Table (A).First_Unit).First_Arg ..
1251 (ALI.ALIs.Table (A).First_Unit).Last_Arg
1253 -- Do not compile with the front end switches except
1257 Arg : String_Ptr renames Args.Table (Index);
1259 if not Is_Front_End_Switch (Arg.all)
1261 Arg (Arg'First + 2 .. Arg'First + 5) = "RTS="
1263 Add_Argument (Arg.all);
1271 -- Now that all the arguments are set, compile the binder
1276 (Gcc_Path.all, Arguments (1 .. Argument_Number), Success);
1280 ("could not compile binder generated file for library ",
1281 Get_Name_String (Data.Library_Name));
1284 -- Process binder generated file for pragmas Linker_Options
1286 Process_Binder_File (Arguments (2).all & ASCII.NUL);
1290 -- Build the library only if Link is True
1293 -- If attribute Library_GCC was specified, get the driver name
1296 Value_Of (Name_Library_GCC, Data.Decl.Attributes, In_Tree);
1298 if not Library_GCC.Default then
1299 Driver_Name := Library_GCC.Value;
1302 -- If attribute Library_Options was specified, add these additional
1306 Value_Of (Name_Library_Options, Data.Decl.Attributes, In_Tree);
1308 if not Library_Options.Default then
1310 Current : String_List_Id := Library_Options.Values;
1311 Element : String_Element;
1314 while Current /= Nil_String loop
1316 In_Tree.String_Elements.Table (Current);
1317 Get_Name_String (Element.Value);
1319 if Name_Len /= 0 then
1320 Opts.Increment_Last;
1321 Opts.Table (Opts.Last) :=
1322 new String'(Name_Buffer (1 .. Name_Len));
1325 Current := Element.Next;
1331 new String'(Get_Name_String (Data.Display_Library_Dir));
1333 new String'(Get_Name_String (Data.Library_Name));
1335 case Data.Library_Kind is
1337 The_Build_Mode := Static;
1340 The_Build_Mode := Dynamic;
1343 The_Build_Mode := Relocatable;
1345 if PIC_Option /= "" then
1346 Opts.Increment_Last;
1347 Opts.Table (Opts.Last) := new String'(PIC_Option);
1351 -- Get the library version, if any
1353 if Data.Lib_Internal_Name /= No_File then
1355 new String'(Get_Name_String (Data.Lib_Internal_Name));
1358 -- Add the objects found in the object directory and the object
1359 -- directories of the extended files, if any, except for generated
1360 -- object files (b~.. or B__..) from extended projects.
1362 -- When there are one or more extended files, only add an object file
1363 -- if no object file with the same name have already been added.
1365 In_Main_Object_Directory := True;
1369 Object_Dir_Path : constant String :=
1370 Get_Name_String (Data.Display_Object_Dir);
1371 Object_Dir : Dir_Type;
1372 Filename : String (1 .. 255);
1377 Open (Dir => Object_Dir, Dir_Name => Object_Dir_Path);
1379 -- For all entries in the object directory
1382 Read (Object_Dir, Filename, Last);
1386 -- Check if it is an object file
1388 if Is_Obj (Filename (1 .. Last)) then
1390 Object_Path : constant String :=
1392 (Object_Dir_Path & Directory_Separator &
1393 Filename (1 .. Last));
1394 C_Object_Path : String := Object_Path;
1395 C_Filename : String := Filename (1 .. Last);
1398 Canonical_Case_File_Name (C_Object_Path);
1399 Canonical_Case_File_Name (C_Filename);
1401 -- If in the object directory of an extended project,
1402 -- do not consider generated object files.
1404 if In_Main_Object_Directory
1406 or else C_Filename (1 .. B_Start'Length) /=
1410 Name_Buffer (1 .. Name_Len) :=
1411 C_Filename (1 .. Last);
1414 if not Objects_Htable.Get (Id) then
1416 -- Record this object file
1418 Objects_Htable.Set (Id, True);
1419 Objects.Increment_Last;
1420 Objects.Table (Objects.Last) :=
1421 new String'(Object_Path);
1424 ALI_File : constant String :=
1425 Ext_To (Object_Path, "ali");
1428 if Is_Regular_File (ALI_File) then
1430 -- Record the ALI file
1432 ALIs.Increment_Last;
1433 ALIs.Table (ALIs.Last) :=
1434 new String'(ALI_File);
1436 -- Find out if for this ALI file, libgnarl
1437 -- or libdecgnat or g-trasym.obj (on
1438 -- OpenVMS) is necessary.
1440 Check_Libs (ALI_File, True);
1443 -- Object file is a foreign object file
1445 Foreigns.Increment_Last;
1446 Foreigns.Table (Foreigns.Last) :=
1447 new String'(Object_Path);
1456 Close (Dir => Object_Dir);
1459 when Directory_Error =>
1460 Com.Fail ("cannot find object directory """,
1461 Get_Name_String (Data.Object_Directory),
1465 exit when Data.Extends = No_Project;
1467 In_Main_Object_Directory := False;
1468 Data := In_Tree.Projects.Table (Data.Extends);
1471 -- Add the -L and -l switches for the imported Library Project Files,
1472 -- and, if Path Option is supported, the library directory path names
1475 Process_Imported_Libraries;
1477 -- Link with libgnat and possibly libgnarl
1479 Opts.Increment_Last;
1480 Opts.Table (Opts.Last) := new String'("-L" & Lib_Directory);
1482 -- If Path Option is supported, add libgnat directory path name to
1485 if Path_Option /= null then
1487 Libdir : constant String := Lib_Directory;
1488 GCC_Index : Natural := 0;
1493 -- For shared libraries, add to the Path Option the directory
1494 -- of the shared version of libgcc.
1496 if The_Build_Mode /= Static then
1497 GCC_Index := Index (Libdir, "/lib/");
1499 if GCC_Index = 0 then
1503 Directory_Separator & "lib" & Directory_Separator);
1506 if GCC_Index /= 0 then
1507 Add_Rpath (Libdir (Libdir'First .. GCC_Index + 3));
1513 if Libgnarl_Needed = Yes then
1514 Opts.Increment_Last;
1516 if The_Build_Mode = Static then
1517 Opts.Table (Opts.Last) := new String'("-lgnarl");
1519 Opts.Table (Opts.Last) := new String'(Shared_Lib ("gnarl"));
1523 In_Tree.Projects.Table (For_Project).Libgnarl_Needed := No;
1526 if Gtrasymobj_Needed then
1527 Opts.Increment_Last;
1528 Opts.Table (Opts.Last) :=
1529 new String'(Lib_Directory & "/g-trasym.obj");
1532 if Libdecgnat_Needed then
1533 Opts.Increment_Last;
1535 Opts.Table (Opts.Last) :=
1536 new String'("-L" & Lib_Directory & "/../declib");
1538 Opts.Increment_Last;
1540 if The_Build_Mode = Static then
1541 Opts.Table (Opts.Last) := new String'("-ldecgnat");
1543 Opts.Table (Opts.Last) := new String'(Shared_Lib ("decgnat"));
1547 Opts.Increment_Last;
1549 if The_Build_Mode = Static then
1550 Opts.Table (Opts.Last) := new String'("-lgnat");
1552 Opts.Table (Opts.Last) := new String'(Shared_Lib ("gnat"));
1555 -- If Path Option is supported, add the necessary switch with the
1556 -- content of Rpath. As Rpath contains at least libgnat directory
1557 -- path name, it is guaranteed that it is not null.
1559 if Path_Option /= null then
1560 Opts.Increment_Last;
1561 Opts.Table (Opts.Last) :=
1562 new String'(Path_Option.all & Rpath (1 .. Rpath_Last));
1569 (Argument_List (Objects.Table (1 .. Objects.Last)));
1572 new Argument_List'(Argument_List
1573 (Foreigns.Table (1 .. Foreigns.Last)));
1576 new Argument_List'(Argument_List (ALIs.Table (1 .. ALIs.Last)));
1579 new Argument_List'(Argument_List (Opts.Table (1 .. Opts.Last)));
1581 -- We fail if there are no object to put in the library (Ada or
1582 -- foreign objects).
1584 if Object_Files'Length = 0 then
1585 Com.Fail ("no object files for library """ &
1586 Lib_Filename.all & '"');
1589 if not Opt.Quiet_Output then
1591 Write_Str ("building ");
1592 Write_Str (Ada.Characters.Handling.To_Lower
1593 (Build_Mode_State'Image (The_Build_Mode)));
1594 Write_Str (" library for project ");
1595 Write_Line (Project_Name);
1597 -- Only output list of object files and ALI files in verbose mode
1599 if Opt.Verbose_Mode then
1602 Write_Line ("object files:");
1604 for Index in Object_Files'Range loop
1606 Write_Line (Object_Files (Index).all);
1611 if Ali_Files'Length = 0 then
1612 Write_Line ("NO ALI files");
1615 Write_Line ("ALI files:");
1617 for Index in Ali_Files'Range loop
1619 Write_Line (Ali_Files (Index).all);
1627 -- We check that all object files are regular files
1631 -- Delete the existing library file, if it exists. Fail if the
1632 -- library file is not writable, or if it is not possible to delete
1636 DLL_Name : aliased String :=
1637 Lib_Dirpath.all & Directory_Separator & DLL_Prefix &
1638 Lib_Filename.all & "." & DLL_Ext;
1640 Archive_Name : aliased String :=
1641 Lib_Dirpath.all & Directory_Separator & "lib" &
1642 Lib_Filename.all & "." & Archive_Ext;
1644 type Str_Ptr is access all String;
1645 -- This type is necessary to meet the accessibility rules of Ada.
1646 -- It is not possible to use String_Access here.
1648 Full_Lib_Name : Str_Ptr;
1649 -- Designates the full library path name. Either DLL_Name or
1650 -- Archive_Name, depending on the library kind.
1652 Success : Boolean := False;
1653 -- Used to call Delete_File
1656 if The_Build_Mode = Static then
1657 Full_Lib_Name := Archive_Name'Access;
1659 Full_Lib_Name := DLL_Name'Access;
1662 if Is_Regular_File (Full_Lib_Name.all) then
1663 if Is_Writable_File (Full_Lib_Name.all) then
1664 Delete_File (Full_Lib_Name.all, Success);
1667 if Is_Regular_File (Full_Lib_Name.all) then
1668 Com.Fail ("could not delete """ & Full_Lib_Name.all & """");
1673 Argument_Number := 0;
1675 -- If we have a standalone library, gather all the interface ALI.
1676 -- They are passed to Build_Dynamic_Library, where they are used by
1677 -- some platforms (VMS, for example) to decide what symbols should be
1678 -- exported. They are also flagged as Interface when we copy them to
1679 -- the library directory (by Copy_ALI_Files, below).
1682 Data := In_Tree.Projects.Table (For_Project);
1685 Iface : String_List_Id;
1686 ALI : File_Name_Type;
1689 Iface := Data.Lib_Interface_ALIs;
1690 while Iface /= Nil_String loop
1693 (In_Tree.String_Elements.Table (Iface).Value);
1694 Interface_ALIs.Set (ALI, True);
1696 (In_Tree.String_Elements.Table (Iface).Value);
1697 Add_Argument (Name_Buffer (1 .. Name_Len));
1698 Iface := In_Tree.String_Elements.Table (Iface).Next;
1701 Iface := Data.Lib_Interface_ALIs;
1703 if not Opt.Quiet_Output then
1705 -- Check that the interface set is complete: any unit in the
1706 -- library that is needed by an interface should also be an
1707 -- interface. If it is not the case, output a warning.
1709 while Iface /= Nil_String loop
1712 (In_Tree.String_Elements.Table (Iface).Value);
1714 Iface := In_Tree.String_Elements.Table (Iface).Next;
1721 Current_Dir : constant String := Get_Current_Dir;
1722 DLL_Name : aliased constant String :=
1723 Lib_Filename.all & "." & DLL_Ext;
1724 Archive_Name : aliased constant String :=
1725 Lib_Filename.all & "." & Archive_Ext;
1727 Name : String (1 .. 200);
1729 Disregard : Boolean;
1730 Delete : Boolean := False;
1733 -- Clean the library directory: remove any file with the name of
1734 -- the library file and any ALI file of a source of the project.
1738 (In_Tree.Projects.Table (For_Project).Library_Dir);
1739 Change_Dir (Name_Buffer (1 .. Name_Len));
1744 ("unable to access library directory """,
1745 Name_Buffer (1 .. Name_Len),
1752 Read (Dir, Name, Last);
1756 Filename : constant String := Name (1 .. Last);
1759 if Is_Regular_File (Filename) then
1760 Canonical_Case_File_Name (Name (1 .. Last));
1763 if (The_Build_Mode = Static and then
1764 Name (1 .. Last) = Archive_Name)
1766 ((The_Build_Mode = Dynamic or else
1767 The_Build_Mode = Relocatable)
1769 Name (1 .. Last) = DLL_Name)
1774 and then Name (Last - 3 .. Last) = ".ali"
1780 -- Compare with ALI file names of the project
1783 1 .. Unit_Table.Last (In_Tree.Units)
1785 Unit := In_Tree.Units.Table (Index);
1787 if Unit.File_Names (Body_Part).Project /=
1790 if Ultimate_Extension_Of
1791 (Unit.File_Names (Body_Part).Project,
1792 In_Tree) = For_Project
1795 (Unit.File_Names (Body_Part).Name);
1796 Name_Len := Name_Len -
1798 (Name (1 .. Name_Len))'Length;
1799 if Name_Buffer (1 .. Name_Len) =
1800 Name (1 .. Last - 4)
1807 elsif Ultimate_Extension_Of
1808 (Unit.File_Names (Specification).Project,
1809 In_Tree) = For_Project
1812 (Unit.File_Names (Specification).Name);
1813 Name_Len := Name_Len -
1815 (Name (1 .. Name_Len))'Length;
1817 if Name_Buffer (1 .. Name_Len) =
1818 Name (1 .. Last - 4)
1829 Set_Writable (Filename);
1830 Delete_File (Filename, Disregard);
1838 Change_Dir (Current_Dir);
1841 -- Call procedure to build the library, depending on the build mode
1843 case The_Build_Mode is
1844 when Dynamic | Relocatable =>
1845 Build_Dynamic_Library
1846 (Ofiles => Object_Files.all,
1847 Foreign => Foreign_Objects.all,
1848 Afiles => Ali_Files.all,
1849 Options => Options.all,
1850 Options_2 => No_Argument_List,
1851 Interfaces => Arguments (1 .. Argument_Number),
1852 Lib_Filename => Lib_Filename.all,
1853 Lib_Dir => Lib_Dirpath.all,
1854 Symbol_Data => Data.Symbol_Data,
1855 Driver_Name => Driver_Name,
1856 Lib_Version => Lib_Version.all,
1857 Auto_Init => Data.Lib_Auto_Init);
1870 -- We need to copy the ALI files from the object directory to
1871 -- the library ALI directory, so that the linker find them there,
1872 -- and does not need to look in the object directory where it
1873 -- would also find the object files; and we don't want that:
1874 -- we want the linker to use the library.
1876 -- Copy the ALI files and make the copies read-only. For interfaces,
1877 -- mark the copies as interfaces.
1880 (Files => Ali_Files.all,
1881 To => In_Tree.Projects.Table
1882 (For_Project).Display_Library_ALI_Dir,
1883 Interfaces => Arguments (1 .. Argument_Number));
1885 -- Copy interface sources if Library_Src_Dir specified
1888 and then In_Tree.Projects.Table
1889 (For_Project).Library_Src_Dir /= No_Path
1891 -- Clean the interface copy directory: remove any source that
1892 -- could be a source of the project.
1896 (In_Tree.Projects.Table (For_Project).Library_Src_Dir);
1897 Change_Dir (Name_Buffer (1 .. Name_Len));
1902 ("unable to access library source copy directory """,
1903 Name_Buffer (1 .. Name_Len),
1909 Delete : Boolean := False;
1911 Name : String (1 .. 200);
1913 Disregard : Boolean;
1919 Read (Dir, Name, Last);
1923 Filename : constant String := Name (1 .. Last);
1926 if Is_Regular_File (Filename) then
1927 Canonical_Case_File_Name (Name (1 .. Last));
1930 -- Compare with source file names of the project
1932 for Index in 1 .. Unit_Table.Last (In_Tree.Units) loop
1933 Unit := In_Tree.Units.Table (Index);
1935 if Ultimate_Extension_Of
1936 (Unit.File_Names (Body_Part).Project, In_Tree) =
1940 (Unit.File_Names (Body_Part).Name) =
1947 if Ultimate_Extension_Of
1949 (Specification).Project, In_Tree) = For_Project
1952 (Unit.File_Names (Specification).Name) =
1962 Set_Writable (Filename);
1963 Delete_File (Filename, Disregard);
1971 Copy_Interface_Sources
1972 (For_Project => For_Project,
1974 Interfaces => Arguments (1 .. Argument_Number),
1975 To_Dir => In_Tree.Projects.Table
1976 (For_Project).Display_Library_Src_Dir);
1980 -- Reset the current working directory to its previous value
1982 Change_Dir (Current_Dir);
1989 procedure Check (Filename : String) is
1991 if not Is_Regular_File (Filename) then
1992 Com.Fail (Filename, " not found.");
2000 procedure Check_Context is
2002 -- Check that each object file exists
2004 for F in Object_Files'Range loop
2005 Check (Object_Files (F).all);
2013 procedure Check_Library
2014 (For_Project : Project_Id;
2015 In_Tree : Project_Tree_Ref)
2017 Data : constant Project_Data :=
2018 In_Tree.Projects.Table (For_Project);
2019 Lib_TS : Time_Stamp_Type;
2020 Current : constant Dir_Name_Str := Get_Current_Dir;
2023 -- No need to build the library if there is no object directory,
2024 -- hence no object files to build the library.
2026 if Data.Library then
2028 Lib_Name : constant File_Name_Type :=
2029 Library_File_Name_For (For_Project, In_Tree);
2031 Change_Dir (Get_Name_String (Data.Library_Dir));
2032 Lib_TS := File_Stamp (Lib_Name);
2033 In_Tree.Projects.Table (For_Project).Library_TS := Lib_TS;
2036 if not Data.Externally_Built
2037 and then not Data.Need_To_Build_Lib
2038 and then Data.Object_Directory /= No_Path
2041 Obj_TS : Time_Stamp_Type;
2042 Object_Dir : Dir_Type;
2045 if OpenVMS_On_Target then
2046 B_Start := new String'("b__");
2049 -- If the library file does not exist, then the time stamp will
2050 -- be Empty_Time_Stamp, earlier than any other time stamp.
2052 Change_Dir (Get_Name_String (Data.Object_Directory));
2053 Open (Dir => Object_Dir, Dir_Name => ".");
2055 -- For all entries in the object directory
2058 Read (Object_Dir, Name_Buffer, Name_Len);
2059 exit when Name_Len = 0;
2061 -- Check if it is an object file, but ignore any binder
2064 if Is_Obj (Name_Buffer (1 .. Name_Len))
2065 and then Name_Buffer (1 .. B_Start'Length) /= B_Start.all
2067 -- Get the object file time stamp
2069 Obj_TS := File_Stamp (File_Name_Type'(Name_Find));
2071 -- If library file time stamp is earlier, set
2072 -- Need_To_Build_Lib and return. String comparaison is
2073 -- used, otherwise time stamps may be too close and the
2074 -- comparaison would return True, which would trigger
2075 -- an unnecessary rebuild of the library.
2077 if String (Lib_TS) < String (Obj_TS) then
2079 -- Library must be rebuilt
2081 In_Tree.Projects.Table
2082 (For_Project).Need_To_Build_Lib := True;
2092 Change_Dir (Current);
2096 ----------------------------
2097 -- Copy_Interface_Sources --
2098 ----------------------------
2100 procedure Copy_Interface_Sources
2101 (For_Project : Project_Id;
2102 In_Tree : Project_Tree_Ref;
2103 Interfaces : Argument_List;
2104 To_Dir : Path_Name_Type)
2106 Current : constant Dir_Name_Str := Get_Current_Dir;
2107 -- The current directory, where to return to at the end
2109 Target : constant Dir_Name_Str := Get_Name_String (To_Dir);
2110 -- The directory where to copy sources
2112 Text : Text_Buffer_Ptr;
2113 The_ALI : ALI.ALI_Id;
2114 Lib_File : File_Name_Type;
2116 First_Unit : ALI.Unit_Id;
2117 Second_Unit : ALI.Unit_Id;
2121 Copy_Subunits : Boolean := False;
2122 -- When True, indicates that subunits, if any, need to be copied too
2124 procedure Copy (File_Name : File_Name_Type);
2125 -- Copy one source of the project to the target directory
2127 function Is_Same_Or_Extension
2128 (Extending : Project_Id;
2129 Extended : Project_Id) return Boolean;
2130 -- Return True if project Extending is equal to or extends project
2137 procedure Copy (File_Name : File_Name_Type) is
2138 Success : Boolean := False;
2142 for Index in Unit_Table.First ..
2143 Unit_Table.Last (In_Tree.Units)
2145 Data := In_Tree.Units.Table (Index);
2147 -- Find and copy the immediate or inherited source
2149 for J in Data.File_Names'Range loop
2150 if Is_Same_Or_Extension
2151 (For_Project, Data.File_Names (J).Project)
2152 and then Data.File_Names (J).Name = File_Name
2155 (Get_Name_String (Data.File_Names (J).Path),
2159 Preserve => Preserve);
2166 --------------------------
2167 -- Is_Same_Or_Extension --
2168 --------------------------
2170 function Is_Same_Or_Extension
2171 (Extending : Project_Id;
2172 Extended : Project_Id) return Boolean
2174 Ext : Project_Id := Extending;
2177 while Ext /= No_Project loop
2178 if Ext = Extended then
2182 Ext := In_Tree.Projects.Table (Ext).Extends;
2186 end Is_Same_Or_Extension;
2188 -- Start of processing for Copy_Interface_Sources
2191 -- Change the working directory to the object directory
2195 (In_Tree.Projects.Table
2196 (For_Project).Object_Directory));
2198 for Index in Interfaces'Range loop
2200 -- First, load the ALI file
2203 Add_Str_To_Name_Buffer (Interfaces (Index).all);
2204 Lib_File := Name_Find;
2205 Text := Read_Library_Info (Lib_File);
2206 The_ALI := Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
2209 Second_Unit := No_Unit_Id;
2210 First_Unit := ALI.ALIs.Table (The_ALI).First_Unit;
2211 Copy_Subunits := True;
2213 -- If there is both a spec and a body, check if they are both needed
2215 if ALI.Units.Table (First_Unit).Utype = Is_Body then
2216 Second_Unit := ALI.ALIs.Table (The_ALI).Last_Unit;
2218 -- If the body is not needed, then reset First_Unit
2220 if not ALI.Units.Table (Second_Unit).Body_Needed_For_SAL then
2221 First_Unit := No_Unit_Id;
2222 Copy_Subunits := False;
2225 elsif ALI.Units.Table (First_Unit).Utype = Is_Spec_Only then
2226 Copy_Subunits := False;
2229 -- Copy the file(s) that need to be copied
2231 if First_Unit /= No_Unit_Id then
2232 Copy (File_Name => ALI.Units.Table (First_Unit).Sfile);
2235 if Second_Unit /= No_Unit_Id then
2236 Copy (File_Name => ALI.Units.Table (Second_Unit).Sfile);
2239 -- Copy all the separates, if any
2241 if Copy_Subunits then
2242 for Dep in ALI.ALIs.Table (The_ALI).First_Sdep ..
2243 ALI.ALIs.Table (The_ALI).Last_Sdep
2245 if Sdep.Table (Dep).Subunit_Name /= No_Name then
2246 Copy (File_Name => Sdep.Table (Dep).Sfile);
2252 -- Restore the initial working directory
2254 Change_Dir (Current);
2255 end Copy_Interface_Sources;
2261 procedure Display (Executable : String) is
2263 if not Opt.Quiet_Output then
2264 Write_Str (Executable);
2266 for Index in 1 .. Argument_Number loop
2268 Write_Str (Arguments (Index).all);
2279 function Index (S, Pattern : String) return Natural is
2280 Len : constant Natural := Pattern'Length;
2283 for J in reverse S'First .. S'Last - Len + 1 loop
2284 if Pattern = S (J .. J + Len - 1) then
2292 -------------------------
2293 -- Process_Binder_File --
2294 -------------------------
2296 procedure Process_Binder_File (Name : String) is
2298 -- Binder file's descriptor
2300 Read_Mode : constant String := "r" & ASCII.Nul;
2303 Status : Interfaces.C_Streams.int;
2304 pragma Unreferenced (Status);
2307 Begin_Info : constant String := "-- BEGIN Object file/option list";
2308 End_Info : constant String := "-- END Object file/option list ";
2310 Next_Line : String (1 .. 1000);
2311 -- Current line value
2312 -- Where does this odd constant 1000 come from, looks suspicious ???
2315 -- End of line slice (the slice does not contain the line terminator)
2317 procedure Get_Next_Line;
2318 -- Read the next line from the binder file without the line terminator
2324 procedure Get_Next_Line is
2328 Fchars := fgets (Next_Line'Address, Next_Line'Length, Fd);
2330 if Fchars = System.Null_Address then
2331 Fail ("Error reading binder output");
2335 while Nlast <= Next_Line'Last
2336 and then Next_Line (Nlast) /= ASCII.LF
2337 and then Next_Line (Nlast) /= ASCII.CR
2345 -- Start of processing for Process_Binder_File
2348 Fd := fopen (Name'Address, Read_Mode'Address);
2350 if Fd = NULL_Stream then
2351 Fail ("Failed to open binder output");
2354 -- Skip up to the Begin Info line
2358 exit when Next_Line (1 .. Nlast) = Begin_Info;
2361 -- Find the first switch
2366 exit when Next_Line (1 .. Nlast) = End_Info;
2368 -- As the binder generated file is in Ada, remove the first eight
2369 -- characters " -- ".
2371 Next_Line (1 .. Nlast - 8) := Next_Line (9 .. Nlast);
2374 -- Stop when the first switch is found
2376 exit when Next_Line (1) = '-';
2379 if Next_Line (1 .. Nlast) /= End_Info then
2381 -- Ignore -static and -shared, since -shared will be used
2384 -- Ignore -lgnat, -lgnarl and -ldecgnat as they will be added
2385 -- later, because they are also needed for non Stand-Alone shared
2388 -- Also ignore the shared libraries which are :
2390 -- UNIX / Windows VMS
2391 -- -lgnat-<version> -lgnat_<version> (7 + version'length chars)
2392 -- -lgnarl-<version> -lgnarl_<version> (8 + version'length chars)
2394 if Next_Line (1 .. Nlast) /= "-static" and then
2395 Next_Line (1 .. Nlast) /= "-shared" and then
2396 Next_Line (1 .. Nlast) /= "-ldecgnat" and then
2397 Next_Line (1 .. Nlast) /= "-lgnarl" and then
2398 Next_Line (1 .. Nlast) /= "-lgnat" and then
2400 (1 .. Natural'Min (Nlast, 10 + Library_Version'Length)) /=
2401 Shared_Lib ("decgnat") and then
2403 (1 .. Natural'Min (Nlast, 8 + Library_Version'Length)) /=
2404 Shared_Lib ("gnarl") and then
2406 (1 .. Natural'Min (Nlast, 7 + Library_Version'Length)) /=
2409 if Next_Line (1) /= '-' then
2411 -- This is not an option, should we add it?
2413 if Add_Object_Files then
2414 Opts.Increment_Last;
2415 Opts.Table (Opts.Last) :=
2416 new String'(Next_Line (1 .. Nlast));
2420 -- Add all other options
2422 Opts.Increment_Last;
2423 Opts.Table (Opts.Last) :=
2424 new String'(Next_Line (1 .. Nlast));
2428 -- Next option, if any
2431 exit when Next_Line (1 .. Nlast) = End_Info;
2433 -- Remove first eight characters " -- "
2435 Next_Line (1 .. Nlast - 8) := Next_Line (9 .. Nlast);
2440 Status := fclose (Fd);
2442 -- Is it really right to ignore any close error ???
2444 end Process_Binder_File;
2450 procedure Reset_Tables is
2453 Objects_Htable.Reset;
2457 Processed_Projects.Reset;
2461 ---------------------------
2462 -- SALs_Use_Constructors --
2463 ---------------------------
2465 function SALs_Use_Constructors return Boolean is
2466 function C_SALs_Init_Using_Constructors return Integer;
2467 pragma Import (C, C_SALs_Init_Using_Constructors,
2468 "__gnat_sals_init_using_constructors");
2470 return C_SALs_Init_Using_Constructors /= 0;
2471 end SALs_Use_Constructors;
2473 ---------------------------
2474 -- Ultimate_Extension_Of --
2475 ---------------------------
2477 function Ultimate_Extension_Of
2478 (Project : Project_Id;
2479 In_Tree : Project_Tree_Ref) return Project_Id
2481 Result : Project_Id := Project;
2482 Data : Project_Data;
2485 if Project /= No_Project then
2487 Data := In_Tree.Projects.Table (Result);
2488 exit when Data.Extended_By = No_Project;
2489 Result := Data.Extended_By;
2494 end Ultimate_Extension_Of;