OSDN Git Service

2009-08-10 Robert Dewar <dewar@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / mdll.adb
index 2e7ae46..e6eb5e9 100644 (file)
@@ -6,18 +6,17 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2006, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2007, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
--- ware  Foundation;  either version 2,  or (at your option) any later ver- --
+-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
 -- for  more details.  You should have  received  a copy of the GNU General --
--- Public License  distributed with GNAT;  see file COPYING.  If not, write --
--- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
--- Boston, MA 02110-1301, USA.                                              --
+-- Public License  distributed with GNAT; see file COPYING3.  If not, go to --
+-- http://www.gnu.org/licenses for a complete copy of the license.          --
 --                                                                          --
 -- GNAT was originally developed  by the GNAT team at  New York University. --
 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
@@ -25,7 +24,7 @@
 ------------------------------------------------------------------------------
 
 --  This package provides the core high level routines used by GNATDLL
---  to build Windows DLL
+--  to build Windows DLL.
 
 with Ada.Text_IO;
 
@@ -38,6 +37,10 @@ package body MDLL is
    use Ada;
    use GNAT;
 
+   --  Convention used for the library names on Windows:
+   --  DLL:            <name>.dll
+   --  Import library: lib<name>.dll
+
    function Get_Dll_Name (Lib_Filename : String) return String;
    --  Returns <Lib_Filename> if it contains a file extension otherwise it
    --  returns <Lib_Filename>.dll.
@@ -69,7 +72,7 @@ package body MDLL is
       Bas_File : aliased constant String := Base_Filename & ".base";
       Dll_File : aliased          String := Get_Dll_Name (Lib_Filename);
       Exp_File : aliased          String := Base_Filename & ".exp";
-      Lib_File : aliased constant String := "lib" & Base_Filename & ".a";
+      Lib_File : aliased constant String := "lib" & Base_Filename & ".dll.a";
 
       Bas_Opt  : aliased String := "-Wl,--base-file," & Bas_File;
       Lib_Opt  : aliased String := "-mdll";
@@ -108,6 +111,7 @@ package body MDLL is
          --  Objects plus the export table (.exp) file
 
          Success : Boolean;
+         pragma Warnings (Off, Success);
 
       begin
          if not Quiet then
@@ -189,6 +193,7 @@ package body MDLL is
 
       procedure Ada_Build_Reloc_DLL is
          Success : Boolean;
+         pragma Warnings (Off, Success);
 
       begin
          if not Quiet then
@@ -293,6 +298,7 @@ package body MDLL is
 
       procedure Build_Non_Reloc_DLL is
          Success : Boolean;
+         pragma Warnings (Off, Success);
 
       begin
          if not Quiet then
@@ -345,6 +351,7 @@ package body MDLL is
 
       procedure Ada_Build_Non_Reloc_DLL is
          Success : Boolean;
+         pragma Warnings (Off, Success);
 
       begin
          if not Quiet then
@@ -394,6 +401,8 @@ package body MDLL is
             raise;
       end Ada_Build_Non_Reloc_DLL;
 
+   --  Start of processing for Build_Dynamic_Library
+
    begin
       --  On Windows the binder file must not be in the first position in the
       --  list. This is due to the way DLL's are built on Windows. We swap the
@@ -402,13 +411,14 @@ package body MDLL is
       if L_Afiles'Length > 1 then
          declare
             Filename : constant String :=
-                         Directory_Operations.Base_Name (L_Afiles (1).all);
+                         Directory_Operations.Base_Name
+                           (L_Afiles (L_Afiles'First).all);
             First    : constant Positive := Filename'First;
 
          begin
             if Filename (First .. First + 1) = "b~" then
-               L_Afiles (L_Afiles'Last) := Afiles (1);
-               L_Afiles (1) := Afiles (Afiles'Last);
+               L_Afiles (L_Afiles'Last) := Afiles (Afiles'First);
+               L_Afiles (L_Afiles'First) := Afiles (Afiles'Last);
             end if;
          end;
       end if;
@@ -438,7 +448,6 @@ package body MDLL is
      (Lib_Filename : String;
       Def_Filename : String)
    is
-
       procedure Build_Import_Library (Lib_Filename : String);
       --  Build an import library. This is to build only a .a library to link
       --  against a DLL.
@@ -448,10 +457,32 @@ package body MDLL is
       --------------------------
 
       procedure Build_Import_Library (Lib_Filename : String) is
+
+         function No_Lib_Prefix (Filename : String) return String;
+         --  Return Filename without the lib prefix if present
+
+         -------------------
+         -- No_Lib_Prefix --
+         -------------------
+
+         function No_Lib_Prefix (Filename : String) return String is
+         begin
+            if Filename (Filename'First .. Filename'First + 2) = "lib" then
+               return Filename (Filename'First + 3 .. Filename'Last);
+            else
+               return Filename;
+            end if;
+         end No_Lib_Prefix;
+
+         --  Local variables
+
          Def_File      : String renames Def_Filename;
          Dll_File      : constant String := Get_Dll_Name (Lib_Filename);
-         Base_Filename : constant String := MDLL.Fil.Ext_To (Lib_Filename);
-         Lib_File      : constant String := "lib" & Base_Filename & ".a";
+         Base_Filename : constant String :=
+                           MDLL.Fil.Ext_To (No_Lib_Prefix (Lib_Filename));
+         Lib_File      : constant String := "lib" & Base_Filename & ".dll.a";
+
+      --  Start of processing for Build_Import_Library
 
       begin
          if not Quiet then
@@ -467,16 +498,7 @@ package body MDLL is
    --  Start of processing for Build_Import_Library
 
    begin
-      --  If the library has the form lib<name>.a then the def file should be
-      --  <name>.def and the DLL to link against <name>.dll. This is a Windows
-      --  convention and we try as much as possible to follow the platform
-      --  convention.
-
-      if Lib_Filename'Length > 3 and then Lib_Filename (1 .. 3) = "lib" then
-         Build_Import_Library (Lib_Filename (4 .. Lib_Filename'Last));
-      else
-         Build_Import_Library (Lib_Filename);
-      end if;
+      Build_Import_Library (Lib_Filename);
    end Build_Import_Library;
 
    ------------------