File : mlib-tgt-specific-aix.adb


   1 ------------------------------------------------------------------------------
   2 --                                                                          --
   3 --                         GNAT COMPILER COMPONENTS                         --
   4 --                                                                          --
   5 --                     M L I B . T G T . S P E C I F I C                    --
   6 --                              (AIX Version)                               --
   7 --                                                                          --
   8 --                                 B o d y                                  --
   9 --                                                                          --
  10 --                     Copyright (C) 2003-2008, AdaCore                     --
  11 --                                                                          --
  12 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
  13 -- terms of the  GNU General Public License as published  by the Free Soft- --
  14 -- ware  Foundation;  either version 3,  or (at your option) any later ver- --
  15 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
  16 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  17 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  18 -- for  more details.  You should have  received  a copy of the GNU General --
  19 -- Public License  distributed with GNAT; see file COPYING3.  If not, go to --
  20 -- http://www.gnu.org/licenses for a complete copy of the license.          --
  21 --                                                                          --
  22 -- GNAT was originally developed  by the GNAT team at  New York University. --
  23 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
  24 --                                                                          --
  25 ------------------------------------------------------------------------------
  26 
  27 --  This is the AIX version of the body
  28 
  29 with Ada.Strings.Fixed; use Ada.Strings.Fixed;
  30 
  31 with MLib.Fil;
  32 with MLib.Utl;
  33 with Opt;
  34 with Output;   use Output;
  35 with Prj.Com;
  36 with Prj.Util; use Prj.Util;
  37 
  38 package body MLib.Tgt.Specific is
  39 
  40    --  Local subprograms
  41    --  These *ALL* require comments ???
  42 
  43    function Archive_Indexer return String;
  44    --  What is this???
  45 
  46    procedure Build_Dynamic_Library
  47      (Ofiles       : Argument_List;
  48       Options      : Argument_List;
  49       Interfaces   : Argument_List;
  50       Lib_Filename : String;
  51       Lib_Dir      : String;
  52       Symbol_Data  : Symbol_Record;
  53       Driver_Name  : Name_Id := No_Name;
  54       Lib_Version  : String  := "";
  55       Auto_Init    : Boolean := False);
  56 
  57    function DLL_Ext return String;
  58 
  59    function Library_Major_Minor_Id_Supported return Boolean;
  60 
  61    function Support_For_Libraries return Library_Support;
  62 
  63    --  Local variables
  64 
  65    No_Arguments        : aliased Argument_List         := (1 .. 0 => null);
  66    Empty_Argument_List : constant Argument_List_Access := No_Arguments'Access;
  67 
  68    Bexpall : aliased String := "-Wl,-bexpall";
  69    Bexpall_Option : constant String_Access := Bexpall'Access;
  70    --  The switch to export all symbols
  71 
  72    Lpthreads : aliased String := "-lpthreads";
  73    Native_Thread_Options : aliased Argument_List := (1 => Lpthreads'Access);
  74    --  The switch to use when linking a library against libgnarl when using
  75    --  Native threads.
  76 
  77    Lgthreads : aliased String := "-lgthreads";
  78    Lmalloc   : aliased String := "-lmalloc";
  79    FSU_Thread_Options : aliased Argument_List :=
  80                           (1 => Lgthreads'Access, 2 => Lmalloc'Access);
  81    --  The switches to use when linking a library against libgnarl when using
  82    --  FSU threads.
  83 
  84    Thread_Options : Argument_List_Access := Empty_Argument_List;
  85    --  Designate the thread switches to used when linking a library against
  86    --  libgnarl. Depends on the thread library (Native or FSU). Resolved for
  87    --  the first library linked against libgnarl.
  88 
  89    ---------------------
  90    -- Archive_Indexer --
  91    ---------------------
  92 
  93    function Archive_Indexer return String is
  94    begin
  95       return "";
  96    end Archive_Indexer;
  97 
  98    ---------------------------
  99    -- Build_Dynamic_Library --
 100    ---------------------------
 101 
 102    procedure Build_Dynamic_Library
 103      (Ofiles       : Argument_List;
 104       Options      : Argument_List;
 105       Interfaces   : Argument_List;
 106       Lib_Filename : String;
 107       Lib_Dir      : String;
 108       Symbol_Data  : Symbol_Record;
 109       Driver_Name  : Name_Id := No_Name;
 110       Lib_Version  : String  := "";
 111       Auto_Init    : Boolean := False)
 112    is
 113       pragma Unreferenced (Interfaces);
 114       pragma Unreferenced (Symbol_Data);
 115       pragma Unreferenced (Lib_Version);
 116       pragma Unreferenced (Auto_Init);
 117 
 118       Lib_File : constant String :=
 119                    Lib_Dir & Directory_Separator & "lib" &
 120                    MLib.Fil.Append_To (Lib_Filename, DLL_Ext);
 121       --  The file name of the library
 122 
 123       Thread_Opts : Argument_List_Access := Empty_Argument_List;
 124       --  Set to Thread_Options if -lgnarl is found in the Options
 125 
 126    begin
 127       if Opt.Verbose_Mode then
 128          Write_Str ("building relocatable shared library ");
 129          Write_Line (Lib_File);
 130       end if;
 131 
 132       --  Look for -lgnarl in Options. If found, set the thread options
 133 
 134       for J in Options'Range loop
 135          if Options (J).all = "-lgnarl" then
 136 
 137             --  If Thread_Options is null, read s-osinte.ads to discover the
 138             --  thread library and set Thread_Options accordingly.
 139 
 140             if Thread_Options = null then
 141                declare
 142                   File : Text_File;
 143                   Line : String (1 .. 100);
 144                   Last : Natural;
 145 
 146                begin
 147                   Open
 148                     (File, Include_Dir_Default_Prefix & "/s-osinte.ads");
 149 
 150                   while not End_Of_File (File) loop
 151                      Get_Line (File, Line, Last);
 152 
 153                      if Index (Line (1 .. Last), "-lpthreads") /= 0 then
 154                         Thread_Options := Native_Thread_Options'Access;
 155                         exit;
 156 
 157                      elsif Index (Line (1 .. Last), "-lgthreads") /= 0 then
 158                         Thread_Options := FSU_Thread_Options'Access;
 159                         exit;
 160                      end if;
 161                   end loop;
 162 
 163                   Close (File);
 164 
 165                   if Thread_Options = null then
 166                      Prj.Com.Fail ("cannot find the thread library in use");
 167                   end if;
 168 
 169                exception
 170                   when others =>
 171                      Prj.Com.Fail ("cannot open s-osinte.ads");
 172                end;
 173             end if;
 174 
 175             Thread_Opts := Thread_Options;
 176             exit;
 177          end if;
 178       end loop;
 179 
 180       --  Finally, call GCC (or the driver specified) to build the library
 181 
 182       MLib.Utl.Gcc
 183         (Output_File => Lib_File,
 184          Objects     => Ofiles,
 185          Options     => Options & Bexpall_Option,
 186          Driver_Name => Driver_Name,
 187          Options_2   => Thread_Opts.all);
 188    end Build_Dynamic_Library;
 189 
 190    -------------
 191    -- DLL_Ext --
 192    -------------
 193 
 194    function DLL_Ext return String is
 195    begin
 196       return "a";
 197    end DLL_Ext;
 198 
 199    --------------------------------------
 200    -- Library_Major_Minor_Id_Supported --
 201    --------------------------------------
 202 
 203    function Library_Major_Minor_Id_Supported return Boolean is
 204    begin
 205       return False;
 206    end Library_Major_Minor_Id_Supported;
 207 
 208    ---------------------------
 209    -- Support_For_Libraries --
 210    ---------------------------
 211 
 212    function Support_For_Libraries return Library_Support is
 213    begin
 214       return Static_Only;
 215    end Support_For_Libraries;
 216 
 217 begin
 218    Archive_Indexer_Ptr := Archive_Indexer'Access;
 219    Build_Dynamic_Library_Ptr := Build_Dynamic_Library'Access;
 220    DLL_Ext_Ptr := DLL_Ext'Access;
 221    Library_Major_Minor_Id_Supported_Ptr :=
 222                                 Library_Major_Minor_Id_Supported'Access;
 223    Support_For_Libraries_Ptr := Support_For_Libraries'Access;
 224 
 225 end MLib.Tgt.Specific;