@@ -32,6 +32,7 @@ with GPR2.Containers;
3232with GPR2.Log ;
3333with GPR2.Path_Name ;
3434with GPR2.Project.Attribute ;
35+ with GPR2.Project.Attribute_Index ;
3536with GPR2.Project.Configuration ;
3637with GPR2.Project.Registry.Attribute ;
3738with GPR2.Project.Tree ;
@@ -169,6 +170,11 @@ package body Setup_RTS is
169170 -- project to install. Use a filename that will match the Install'Artifacts
170171 -- attribute in the runtime project file.
171172
173+ function Has_Shared_Lib
174+ (RTS_Dir : String; Shared_Lib_Ext : String) return Boolean;
175+ -- Return whether there is any file with extension Shared_Lib_Ext in the
176+ -- directory RTS_Dir/adalib.
177+
172178 -- ----------------
173179 -- Load_Project --
174180 -- ----------------
@@ -491,23 +497,64 @@ package body Setup_RTS is
491497 end ;
492498 end if ;
493499
494- -- Query the support for libraries in this configuration. When GPRconfig
495- -- fails to find the toolchain for the requested target/RTS, it only
496- -- emits warnings (no Invalid_Project exception raised in the call to
497- -- Load above). In this case, we reach this point and have an empty
498- -- string for the Library_Support attribute.
500+ -- First, determine what kind of library is supported by the current
501+ -- target / RTS configuration. If we have full library support, still
502+ -- try to determine if we have access to a shared Ada runtime as it is
503+ -- not always available.
504+ --
505+ -- To do this, we search in the <Runtime_Dir>/adalib directory any file
506+ -- with a <Shared_Library_Suffix> extension. If we can't find anything
507+ -- then assume only static libraries are supported.
508+ --
509+ -- If GPRconfig fails to find a toolchain, it only emits warnings (no
510+ -- Invalid_Project exception raise in the call to Load above), so when
511+ -- reaching this point, assume empty strings for all the attributes,
512+ -- (and thus no library support).
499513
500514 declare
501- Attr_Id : constant GPR2.Q_Attribute_Id :=
502- GPR2.Project.Registry.Attribute.Library_Support;
503- Attr : constant GPR2.Project.Attribute.Object :=
504- Prj.Configuration.Corresponding_View.Attribute (Attr_Id);
505- LS : constant String :=
506- (if Attr.Is_Defined
507- then String (Attr.Value.Text)
508- else " " );
515+ function Config_Attribute
516+ (Id : GPR2.Q_Attribute_Id;
517+ Index : GPR2.Project.Attribute_Index.Object :=
518+ GPR2.Project.Attribute_Index.Undefined) return String;
519+ -- Return the string value for the attribute denoted by Id, at Index.
520+ -- If the attribute value is not defined, return the empty string.
521+
522+ -- --------------------
523+ -- Config_Attribute --
524+ -- --------------------
525+
526+ function Config_Attribute
527+ (Id : GPR2.Q_Attribute_Id;
528+ Index : GPR2.Project.Attribute_Index.Object :=
529+ GPR2.Project.Attribute_Index.Undefined) return String
530+ is
531+ Attr : constant GPR2.Project.Attribute.Object :=
532+ Prj.Configuration.Corresponding_View.Attribute (Id, Index);
533+ begin
534+ return (if Attr.Is_Defined then String (Attr.Value.Text) else " " );
535+ end Config_Attribute ;
536+
537+ Lib_Support_Str : constant String :=
538+ Config_Attribute (GPR2.Project.Registry.Attribute.Library_Support);
539+
540+ RTS_Dir : constant String :=
541+ Config_Attribute
542+ (GPR2.Project.Registry.Attribute.Runtime_Dir,
543+ Index =>
544+ GPR2.Project.Attribute_Index.Create (GPR2.Ada_Language));
545+
546+ Shared_Lib_Ext : constant String :=
547+ Config_Attribute
548+ (GPR2.Project.Registry.Attribute.Shared_Library_Suffix);
509549 begin
510- Lib_Support := Library_Support'Value (LS);
550+ Lib_Support := Library_Support'Value (Lib_Support_Str);
551+
552+ if Lib_Support = Full
553+ and then not Has_Shared_Lib (RTS_Dir, Shared_Lib_Ext)
554+ then
555+ Lib_Support := Static_Only;
556+ end if ;
557+
511558 exception
512559 when Constraint_Error =>
513560 Fatal_Error (" Cannot get library support for this configuration" );
@@ -1114,4 +1161,35 @@ package body Setup_RTS is
11141161 return Had_Warnings;
11151162 end Check_RTS_Profile ;
11161163
1164+ -- ------------------
1165+ -- Has_Shared_Lib --
1166+ -- ------------------
1167+
1168+ function Has_Shared_Lib
1169+ (RTS_Dir : String; Shared_Lib_Ext : String) return Boolean
1170+ is
1171+ Lib_Dir_Search : Search_Type;
1172+ begin
1173+ if not Exists (RTS_Dir) then
1174+ return False;
1175+ end if ;
1176+
1177+ Start_Search
1178+ (Lib_Dir_Search,
1179+ Directory =>
1180+ RTS_Dir & GNAT.OS_Lib.Directory_Separator & " adalib" ,
1181+ Pattern => " *" & Shared_Lib_Ext,
1182+ Filter =>
1183+ (Ordinary_File => True, others => False));
1184+
1185+ return Res : constant Boolean := More_Entries (Lib_Dir_Search) do
1186+ End_Search (Lib_Dir_Search);
1187+ end return ;
1188+
1189+ exception
1190+ when Ada.Directories.Name_Error =>
1191+ End_Search (Lib_Dir_Search);
1192+ return False;
1193+ end Has_Shared_Lib ;
1194+
11171195end Setup_RTS ;
0 commit comments