2006-10-31 Robert Dewar <dewar@adacore.com> Thomas Quinot <quinot@adacore.com> Arnaud Charlet <charlet@adacore.com> * fmap.adb: Put routines in alpha order * g-boumai.ads: Remove redundant 'in' keywords * g-cgi.adb: Minor reformatting * g-cgi.ads: Remove redundant 'in' keywords * get_targ.adb: Put routines in alpha order * prj-attr.ads: Minor reformatting * s-atacco.ads: Minor reformatting * scn.adb: Put routines in alpha order * sinput-l.adb: Minor comment fix * sinput-p.adb: Minor comment fix * s-maccod.ads: Minor reformatting * s-memory.adb: Minor reformatting * s-htable.adb: Fix typo in comment. * s-secsta.adb: Minor comment update. * s-soflin.adb: Minor reformatting * s-stoele.ads: Add comment about odd qualification in Storage_Offset declaration * s-strxdr.adb: Remove unnecessary 'in' keywords for formal parameters. * treeprs.adt: Minor reformatting * urealp.adb: Put routines in alpha order * s-wchcon.ads, s-wchcon.adb (Get_WC_Encoding_Method): New version taking string. * s-asthan-vms-alpha.adb: Remove redundant 'in' keywords * g-trasym-vms-ia64.adb: Remove redundant 'in' keywords * env.c (__gnat_unsetenv): Unsetenv is unavailable on LynxOS, so workaround as on other platforms. * g-eacodu-vms.adb: Remove redundant 'in' keywords * g-expect-vms.adb: Remove redundant 'in' keywords * gnatdll.adb (Add_Files_From_List): Handle Name_Error and report a clear error message if the list-of-files file cannot be opened. * g-thread.adb (Unregister_Thread_Id): Add use type Thread_Id so the equality operator is always visible. * lang.opt: Woverlength-strings: New option. * nmake.adt: Update copyright, since nmake.ads and nmake.adb have changed. * osint-b.ads, osint-b.adb (Time_From_Last_Bind): removed function . (Binder_Output_Time_Stamps_Set): removed. (Old_Binder_Output_Time_Stamp): idem. (New_Binder_Output_Time_Stamp): idem. (Recording_Time_From_Last_Bind): idem. (Recording_Time_From_Last_Bind): Make constant. * output.ads, output.adb (Write_Str): Allow LF characters (Write_Spaces): New procedure * prepcomp.adb (Preproc_Data_Table): Change Increment from 5% to 100% * inline.adb: Minor reformatting * s-asthan-vms-alpha.adb: Remove redundant 'in' keywords * s-mastop-vms.adb: Remove redundant 'in' keywords * s-osprim-vms.adb: Remove redundant 'in' keywords * s-trafor-default.adb: Remove redundant 'in' keywords * 9drpc.adb: Remove redundant 'in' keywords * s-osinte-mingw.ads: Minor reformatting * s-inmaop-posix.adb: Minor reformatting * a-direio.ads: Remove quotes from Compile_Time_Warning message * a-exexda.adb: Minor code reorganization * a-filico.adb: Minor reformatting * a-finali.adb: Minor reformatting * a-nudira.ads: Remove quote from Compile_Time_Warning message * a-numeri.ads: Minor reformatting * a-sequio.ads: Remove quotes from Compile_Time_Warning message * exp_pakd.ads: Fix obsolete comment * a-ztenau.adb, a-ztenio.adb, a-wtenau.adb, a-tienau.adb, a-wtenio.adb (Put): Avoid assuming low bound of string is 1. Probably not a bug, but certainly neater and more efficient. * a-tienio.adb: Minor reformatting * comperr.adb (Compiler_Abort): Call Cancel_Special_Output at start Avoid assuming low bound of string is 1. * gnatbind.adb: Change Bindusg to package and rename procedure as Display, which now ensures that it only outputs usage information once. (Scan_Bind_Arg): Avoid assuming low bound of string is 1. * g-pehage.adb (Build_Identical_Keysets): Replace use of 1 by Table'First. * g-regpat.adb (Insert_Operator): Add pragma Warnings (Off) to kill warning. (Match): Add pragma Assert to ensure that Matches'First is zero * g-regpat.ads (Match): Document that Matches lower bound must be zero * makeutl.adb (Is_External_Assignment): Add pragma Assert's to check documented preconditions (also kills warnings about bad indexes). * mdll.adb (Build_Dynamic_Library): Avoid assumption that Afiles'First is 1. (Build_Import_Library): Ditto; * mdll-utl.adb: (Gnatbind): Avoid assumption that Alis'First = 1 * rtsfind.adb (RTE_Error_Msg): Avoid assuming low bound of string is 1. * sem_case.adb (Analyze_Choices): Add pragma Assert to check that lower bound of choice table is 1. * sem_case.ads (Analyze_Choices): Document that lower bound of Choice_Table is 1. * s-imgdec.adb (Set_Decimal_Digits): Avoid assuming low bound of string is 1. * uintp.adb (Init_Operand): Document that low bound of Vec is always 1, and add appropriate Assert pragma to suppress warnings. * atree.h, atree.ads, atree.adb Change Elist24 to Elist25 Add definitions of Field28 and Node28 (Traverse_Field): Use new syntactic parent table in sinfo. * cstand.adb: Change name Is_Ada_2005 to Is_Ada_2005_Only * itypes.adb: Change name Is_Ada_2005 to Is_Ada_2005_Only * exp_tss.adb: Put routines in alpha order * fe.h: Remove redundant declarations. From-SVN: r118330
502 lines
17 KiB
Ada
502 lines
17 KiB
Ada
------------------------------------------------------------------------------
|
|
-- --
|
|
-- GNAT COMPILER COMPONENTS --
|
|
-- --
|
|
-- M D L L --
|
|
-- --
|
|
-- B o d y --
|
|
-- --
|
|
-- Copyright (C) 1992-2006, 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- --
|
|
-- 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. --
|
|
-- --
|
|
-- GNAT was originally developed by the GNAT team at New York University. --
|
|
-- Extensive contributions were provided by Ada Core Technologies Inc. --
|
|
-- --
|
|
------------------------------------------------------------------------------
|
|
|
|
-- This package provides the core high level routines used by GNATDLL
|
|
-- to build Windows DLL
|
|
|
|
with Ada.Text_IO;
|
|
|
|
with GNAT.Directory_Operations;
|
|
with MDLL.Utl;
|
|
with MDLL.Fil;
|
|
|
|
package body MDLL is
|
|
|
|
use Ada;
|
|
use GNAT;
|
|
|
|
function Get_Dll_Name (Lib_Filename : String) return String;
|
|
-- Returns <Lib_Filename> if it contains a file extension otherwise it
|
|
-- returns <Lib_Filename>.dll.
|
|
|
|
---------------------------
|
|
-- Build_Dynamic_Library --
|
|
---------------------------
|
|
|
|
procedure Build_Dynamic_Library
|
|
(Ofiles : Argument_List;
|
|
Afiles : Argument_List;
|
|
Options : Argument_List;
|
|
Bargs_Options : Argument_List;
|
|
Largs_Options : Argument_List;
|
|
Lib_Filename : String;
|
|
Def_Filename : String;
|
|
Lib_Address : String := "";
|
|
Build_Import : Boolean := False;
|
|
Relocatable : Boolean := False;
|
|
Map_File : Boolean := False)
|
|
is
|
|
|
|
use type OS_Lib.Argument_List;
|
|
|
|
Base_Filename : constant String := MDLL.Fil.Ext_To (Lib_Filename);
|
|
|
|
Def_File : aliased constant String := Def_Filename;
|
|
Jnk_File : aliased String := Base_Filename & ".jnk";
|
|
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";
|
|
|
|
Bas_Opt : aliased String := "-Wl,--base-file," & Bas_File;
|
|
Lib_Opt : aliased String := "-mdll";
|
|
Out_Opt : aliased String := "-o";
|
|
Adr_Opt : aliased String := "-Wl,--image-base=" & Lib_Address;
|
|
Map_Opt : aliased String := "-Wl,-Map," & Lib_Filename & ".map";
|
|
|
|
L_Afiles : Argument_List := Afiles;
|
|
-- Local afiles list. This list can be reordered to ensure that the
|
|
-- binder ALI file is not the first entry in this list.
|
|
|
|
All_Options : constant Argument_List := Options & Largs_Options;
|
|
|
|
procedure Build_Reloc_DLL;
|
|
-- Build a relocatable DLL with only objects file specified. This uses
|
|
-- the well known five step build (see GNAT User's Guide).
|
|
|
|
procedure Ada_Build_Reloc_DLL;
|
|
-- Build a relocatable DLL with Ada code. This uses the well known five
|
|
-- step build (see GNAT User's Guide).
|
|
|
|
procedure Build_Non_Reloc_DLL;
|
|
-- Build a non relocatable DLL containing no Ada code
|
|
|
|
procedure Ada_Build_Non_Reloc_DLL;
|
|
-- Build a non relocatable DLL with Ada code
|
|
|
|
---------------------
|
|
-- Build_Reloc_DLL --
|
|
---------------------
|
|
|
|
procedure Build_Reloc_DLL is
|
|
|
|
Objects_Exp_File : constant OS_Lib.Argument_List :=
|
|
Exp_File'Unchecked_Access & Ofiles;
|
|
-- Objects plus the export table (.exp) file
|
|
|
|
Success : Boolean;
|
|
|
|
begin
|
|
if not Quiet then
|
|
Text_IO.Put_Line ("building relocatable DLL...");
|
|
Text_IO.Put ("make " & Dll_File);
|
|
|
|
if Build_Import then
|
|
Text_IO.Put_Line (" and " & Lib_File);
|
|
else
|
|
Text_IO.New_Line;
|
|
end if;
|
|
end if;
|
|
|
|
-- 1) Build base file with objects files
|
|
|
|
Utl.Gcc (Output_File => Jnk_File,
|
|
Files => Ofiles,
|
|
Options => All_Options,
|
|
Base_File => Bas_File,
|
|
Build_Lib => True);
|
|
|
|
-- 2) Build exp from base file
|
|
|
|
Utl.Dlltool (Def_File, Dll_File, Lib_File,
|
|
Base_File => Bas_File,
|
|
Exp_Table => Exp_File,
|
|
Build_Import => False);
|
|
|
|
-- 3) Build base file with exp file and objects files
|
|
|
|
Utl.Gcc (Output_File => Jnk_File,
|
|
Files => Objects_Exp_File,
|
|
Options => All_Options,
|
|
Base_File => Bas_File,
|
|
Build_Lib => True);
|
|
|
|
-- 4) Build new exp from base file and the lib file (.a)
|
|
|
|
Utl.Dlltool (Def_File, Dll_File, Lib_File,
|
|
Base_File => Bas_File,
|
|
Exp_Table => Exp_File,
|
|
Build_Import => Build_Import);
|
|
|
|
-- 5) Build the dynamic library
|
|
|
|
declare
|
|
Params : constant OS_Lib.Argument_List :=
|
|
Map_Opt'Unchecked_Access &
|
|
Adr_Opt'Unchecked_Access & All_Options;
|
|
First_Param : Positive := Params'First + 1;
|
|
|
|
begin
|
|
if Map_File then
|
|
First_Param := Params'First;
|
|
end if;
|
|
|
|
Utl.Gcc
|
|
(Output_File => Dll_File,
|
|
Files => Objects_Exp_File,
|
|
Options => Params (First_Param .. Params'Last),
|
|
Build_Lib => True);
|
|
end;
|
|
|
|
OS_Lib.Delete_File (Exp_File, Success);
|
|
OS_Lib.Delete_File (Bas_File, Success);
|
|
OS_Lib.Delete_File (Jnk_File, Success);
|
|
|
|
exception
|
|
when others =>
|
|
OS_Lib.Delete_File (Exp_File, Success);
|
|
OS_Lib.Delete_File (Bas_File, Success);
|
|
OS_Lib.Delete_File (Jnk_File, Success);
|
|
raise;
|
|
end Build_Reloc_DLL;
|
|
|
|
-------------------------
|
|
-- Ada_Build_Reloc_DLL --
|
|
-------------------------
|
|
|
|
procedure Ada_Build_Reloc_DLL is
|
|
Success : Boolean;
|
|
|
|
begin
|
|
if not Quiet then
|
|
Text_IO.Put_Line ("Building relocatable DLL...");
|
|
Text_IO.Put ("make " & Dll_File);
|
|
|
|
if Build_Import then
|
|
Text_IO.Put_Line (" and " & Lib_File);
|
|
else
|
|
Text_IO.New_Line;
|
|
end if;
|
|
end if;
|
|
|
|
-- 1) Build base file with objects files
|
|
|
|
Utl.Gnatbind (L_Afiles, Options & Bargs_Options);
|
|
|
|
declare
|
|
Params : constant OS_Lib.Argument_List :=
|
|
Out_Opt'Unchecked_Access &
|
|
Jnk_File'Unchecked_Access &
|
|
Lib_Opt'Unchecked_Access &
|
|
Bas_Opt'Unchecked_Access &
|
|
Ofiles &
|
|
All_Options;
|
|
begin
|
|
Utl.Gnatlink (L_Afiles (L_Afiles'Last).all, Params);
|
|
end;
|
|
|
|
-- 2) Build exp from base file
|
|
|
|
Utl.Dlltool (Def_File, Dll_File, Lib_File,
|
|
Base_File => Bas_File,
|
|
Exp_Table => Exp_File,
|
|
Build_Import => False);
|
|
|
|
-- 3) Build base file with exp file and objects files
|
|
|
|
Utl.Gnatbind (L_Afiles, Options & Bargs_Options);
|
|
|
|
declare
|
|
Params : constant OS_Lib.Argument_List :=
|
|
Out_Opt'Unchecked_Access &
|
|
Jnk_File'Unchecked_Access &
|
|
Lib_Opt'Unchecked_Access &
|
|
Bas_Opt'Unchecked_Access &
|
|
Exp_File'Unchecked_Access &
|
|
Ofiles &
|
|
All_Options;
|
|
begin
|
|
Utl.Gnatlink (L_Afiles (L_Afiles'Last).all, Params);
|
|
end;
|
|
|
|
-- 4) Build new exp from base file and the lib file (.a)
|
|
|
|
Utl.Dlltool (Def_File, Dll_File, Lib_File,
|
|
Base_File => Bas_File,
|
|
Exp_Table => Exp_File,
|
|
Build_Import => Build_Import);
|
|
|
|
-- 5) Build the dynamic library
|
|
|
|
Utl.Gnatbind (L_Afiles, Options & Bargs_Options);
|
|
|
|
declare
|
|
Params : constant OS_Lib.Argument_List :=
|
|
Map_Opt'Unchecked_Access &
|
|
Out_Opt'Unchecked_Access &
|
|
Dll_File'Unchecked_Access &
|
|
Lib_Opt'Unchecked_Access &
|
|
Exp_File'Unchecked_Access &
|
|
Adr_Opt'Unchecked_Access &
|
|
Ofiles &
|
|
All_Options;
|
|
First_Param : Positive := Params'First + 1;
|
|
|
|
begin
|
|
if Map_File then
|
|
First_Param := Params'First;
|
|
end if;
|
|
|
|
Utl.Gnatlink
|
|
(L_Afiles (L_Afiles'Last).all,
|
|
Params (First_Param .. Params'Last));
|
|
end;
|
|
|
|
OS_Lib.Delete_File (Exp_File, Success);
|
|
OS_Lib.Delete_File (Bas_File, Success);
|
|
OS_Lib.Delete_File (Jnk_File, Success);
|
|
|
|
exception
|
|
when others =>
|
|
OS_Lib.Delete_File (Exp_File, Success);
|
|
OS_Lib.Delete_File (Bas_File, Success);
|
|
OS_Lib.Delete_File (Jnk_File, Success);
|
|
raise;
|
|
end Ada_Build_Reloc_DLL;
|
|
|
|
-------------------------
|
|
-- Build_Non_Reloc_DLL --
|
|
-------------------------
|
|
|
|
procedure Build_Non_Reloc_DLL is
|
|
Success : Boolean;
|
|
|
|
begin
|
|
if not Quiet then
|
|
Text_IO.Put_Line ("building non relocatable DLL...");
|
|
Text_IO.Put ("make " & Dll_File &
|
|
" using address " & Lib_Address);
|
|
|
|
if Build_Import then
|
|
Text_IO.Put_Line (" and " & Lib_File);
|
|
else
|
|
Text_IO.New_Line;
|
|
end if;
|
|
end if;
|
|
|
|
-- Build exp table and the lib .a file
|
|
|
|
Utl.Dlltool (Def_File, Dll_File, Lib_File,
|
|
Exp_Table => Exp_File,
|
|
Build_Import => Build_Import);
|
|
|
|
-- Build the DLL
|
|
|
|
declare
|
|
Params : OS_Lib.Argument_List :=
|
|
Adr_Opt'Unchecked_Access & All_Options;
|
|
begin
|
|
if Map_File then
|
|
Params := Map_Opt'Unchecked_Access & Params;
|
|
end if;
|
|
|
|
Utl.Gcc (Output_File => Dll_File,
|
|
Files => Exp_File'Unchecked_Access & Ofiles,
|
|
Options => Params,
|
|
Build_Lib => True);
|
|
end;
|
|
|
|
OS_Lib.Delete_File (Exp_File, Success);
|
|
|
|
exception
|
|
when others =>
|
|
OS_Lib.Delete_File (Exp_File, Success);
|
|
raise;
|
|
end Build_Non_Reloc_DLL;
|
|
|
|
-----------------------------
|
|
-- Ada_Build_Non_Reloc_DLL --
|
|
-----------------------------
|
|
|
|
-- Build a non relocatable DLL with Ada code
|
|
|
|
procedure Ada_Build_Non_Reloc_DLL is
|
|
Success : Boolean;
|
|
|
|
begin
|
|
if not Quiet then
|
|
Text_IO.Put_Line ("building non relocatable DLL...");
|
|
Text_IO.Put ("make " & Dll_File &
|
|
" using address " & Lib_Address);
|
|
|
|
if Build_Import then
|
|
Text_IO.Put_Line (" and " & Lib_File);
|
|
else
|
|
Text_IO.New_Line;
|
|
end if;
|
|
end if;
|
|
|
|
-- Build exp table and the lib .a file
|
|
|
|
Utl.Dlltool (Def_File, Dll_File, Lib_File,
|
|
Exp_Table => Exp_File,
|
|
Build_Import => Build_Import);
|
|
|
|
-- Build the DLL
|
|
|
|
Utl.Gnatbind (L_Afiles, Options & Bargs_Options);
|
|
|
|
declare
|
|
Params : OS_Lib.Argument_List :=
|
|
Out_Opt'Unchecked_Access &
|
|
Dll_File'Unchecked_Access &
|
|
Lib_Opt'Unchecked_Access &
|
|
Exp_File'Unchecked_Access &
|
|
Adr_Opt'Unchecked_Access &
|
|
Ofiles &
|
|
All_Options;
|
|
begin
|
|
if Map_File then
|
|
Params := Map_Opt'Unchecked_Access & Params;
|
|
end if;
|
|
|
|
Utl.Gnatlink (L_Afiles (L_Afiles'Last).all, Params);
|
|
end;
|
|
|
|
OS_Lib.Delete_File (Exp_File, Success);
|
|
|
|
exception
|
|
when others =>
|
|
OS_Lib.Delete_File (Exp_File, Success);
|
|
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
|
|
-- first ali with the last one if it is the case.
|
|
|
|
if L_Afiles'Length > 1 then
|
|
declare
|
|
Filename : constant String :=
|
|
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 (Afiles'First);
|
|
L_Afiles (L_Afiles'First) := Afiles (Afiles'Last);
|
|
end if;
|
|
end;
|
|
end if;
|
|
|
|
case Relocatable is
|
|
when True =>
|
|
if L_Afiles'Length = 0 then
|
|
Build_Reloc_DLL;
|
|
else
|
|
Ada_Build_Reloc_DLL;
|
|
end if;
|
|
|
|
when False =>
|
|
if L_Afiles'Length = 0 then
|
|
Build_Non_Reloc_DLL;
|
|
else
|
|
Ada_Build_Non_Reloc_DLL;
|
|
end if;
|
|
end case;
|
|
end Build_Dynamic_Library;
|
|
|
|
--------------------------
|
|
-- Build_Import_Library --
|
|
--------------------------
|
|
|
|
procedure Build_Import_Library
|
|
(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.
|
|
|
|
--------------------------
|
|
-- Build_Import_Library --
|
|
--------------------------
|
|
|
|
procedure Build_Import_Library (Lib_Filename : String) is
|
|
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";
|
|
|
|
begin
|
|
if not Quiet then
|
|
Text_IO.Put_Line ("Building import library...");
|
|
Text_IO.Put_Line
|
|
("make " & Lib_File & " to use dynamic library " & Dll_File);
|
|
end if;
|
|
|
|
Utl.Dlltool
|
|
(Def_File, Dll_File, Lib_File, Build_Import => True);
|
|
end Build_Import_Library;
|
|
|
|
-- 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 (Lib_Filename'First .. Lib_Filename'First + 2) = "lib"
|
|
then
|
|
Build_Import_Library
|
|
(Lib_Filename (Lib_Filename'First + 3 .. Lib_Filename'Last));
|
|
else
|
|
Build_Import_Library (Lib_Filename);
|
|
end if;
|
|
end Build_Import_Library;
|
|
|
|
------------------
|
|
-- Get_Dll_Name --
|
|
------------------
|
|
|
|
function Get_Dll_Name (Lib_Filename : String) return String is
|
|
begin
|
|
if MDLL.Fil.Get_Ext (Lib_Filename) = "" then
|
|
return Lib_Filename & ".dll";
|
|
else
|
|
return Lib_Filename;
|
|
end if;
|
|
end Get_Dll_Name;
|
|
|
|
end MDLL;
|