annotate gcc/ada/mdll.adb @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- M D L L --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
kono
parents:
diff changeset
17 -- for more details. You should have received a copy of the GNU General --
kono
parents:
diff changeset
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
kono
parents:
diff changeset
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
kono
parents:
diff changeset
20 -- --
kono
parents:
diff changeset
21 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
23 -- --
kono
parents:
diff changeset
24 ------------------------------------------------------------------------------
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 -- This package provides the core high level routines used by GNATDLL
kono
parents:
diff changeset
27 -- to build Windows DLL.
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 with Ada.Text_IO;
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 with GNAT.Directory_Operations;
kono
parents:
diff changeset
32 with MDLL.Utl;
kono
parents:
diff changeset
33 with MDLL.Fil;
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 package body MDLL is
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 use Ada;
kono
parents:
diff changeset
38 use GNAT;
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 -- Convention used for the library names on Windows:
kono
parents:
diff changeset
41 -- DLL: <name>.dll
kono
parents:
diff changeset
42 -- Import library: lib<name>.dll
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 function Get_Dll_Name (Lib_Filename : String) return String;
kono
parents:
diff changeset
45 -- Returns <Lib_Filename> if it contains a file extension otherwise it
kono
parents:
diff changeset
46 -- returns <Lib_Filename>.dll.
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 ---------------------------
kono
parents:
diff changeset
49 -- Build_Dynamic_Library --
kono
parents:
diff changeset
50 ---------------------------
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 procedure Build_Dynamic_Library
kono
parents:
diff changeset
53 (Ofiles : Argument_List;
kono
parents:
diff changeset
54 Afiles : Argument_List;
kono
parents:
diff changeset
55 Options : Argument_List;
kono
parents:
diff changeset
56 Bargs_Options : Argument_List;
kono
parents:
diff changeset
57 Largs_Options : Argument_List;
kono
parents:
diff changeset
58 Lib_Filename : String;
kono
parents:
diff changeset
59 Def_Filename : String;
kono
parents:
diff changeset
60 Lib_Address : String := "";
kono
parents:
diff changeset
61 Build_Import : Boolean := False;
kono
parents:
diff changeset
62 Relocatable : Boolean := False;
kono
parents:
diff changeset
63 Map_File : Boolean := False)
kono
parents:
diff changeset
64 is
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 use type OS_Lib.Argument_List;
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 Base_Filename : constant String := MDLL.Fil.Ext_To (Lib_Filename);
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 Def_File : aliased constant String := Def_Filename;
kono
parents:
diff changeset
71 Jnk_File : aliased String := Base_Filename & ".jnk";
kono
parents:
diff changeset
72 Bas_File : aliased constant String := Base_Filename & ".base";
kono
parents:
diff changeset
73 Dll_File : aliased String := Get_Dll_Name (Lib_Filename);
kono
parents:
diff changeset
74 Exp_File : aliased String := Base_Filename & ".exp";
kono
parents:
diff changeset
75 Lib_File : aliased constant String := "lib" & Base_Filename & ".dll.a";
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 Bas_Opt : aliased String := "-Wl,--base-file," & Bas_File;
kono
parents:
diff changeset
78 Lib_Opt : aliased String := "-mdll";
kono
parents:
diff changeset
79 Out_Opt : aliased String := "-o";
kono
parents:
diff changeset
80 Adr_Opt : aliased String := "-Wl,--image-base=" & Lib_Address;
kono
parents:
diff changeset
81 Map_Opt : aliased String := "-Wl,-Map," & Lib_Filename & ".map";
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 L_Afiles : Argument_List := Afiles;
kono
parents:
diff changeset
84 -- Local afiles list. This list can be reordered to ensure that the
kono
parents:
diff changeset
85 -- binder ALI file is not the first entry in this list.
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 All_Options : constant Argument_List := Options & Largs_Options;
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 procedure Build_Reloc_DLL;
kono
parents:
diff changeset
90 -- Build a relocatable DLL with only objects file specified. This uses
kono
parents:
diff changeset
91 -- the well known five step build (see GNAT User's Guide).
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 procedure Ada_Build_Reloc_DLL;
kono
parents:
diff changeset
94 -- Build a relocatable DLL with Ada code. This uses the well known five
kono
parents:
diff changeset
95 -- step build (see GNAT User's Guide).
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 procedure Build_Non_Reloc_DLL;
kono
parents:
diff changeset
98 -- Build a non relocatable DLL containing no Ada code
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 procedure Ada_Build_Non_Reloc_DLL;
kono
parents:
diff changeset
101 -- Build a non relocatable DLL with Ada code
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 ---------------------
kono
parents:
diff changeset
104 -- Build_Reloc_DLL --
kono
parents:
diff changeset
105 ---------------------
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 procedure Build_Reloc_DLL is
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 Objects_Exp_File : constant OS_Lib.Argument_List :=
kono
parents:
diff changeset
110 Exp_File'Unchecked_Access & Ofiles;
kono
parents:
diff changeset
111 -- Objects plus the export table (.exp) file
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 Success : Boolean;
kono
parents:
diff changeset
114 pragma Warnings (Off, Success);
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 begin
kono
parents:
diff changeset
117 if not Quiet then
kono
parents:
diff changeset
118 Text_IO.Put_Line ("building relocatable DLL...");
kono
parents:
diff changeset
119 Text_IO.Put ("make " & Dll_File);
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 if Build_Import then
kono
parents:
diff changeset
122 Text_IO.Put_Line (" and " & Lib_File);
kono
parents:
diff changeset
123 else
kono
parents:
diff changeset
124 Text_IO.New_Line;
kono
parents:
diff changeset
125 end if;
kono
parents:
diff changeset
126 end if;
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 -- 1) Build base file with objects files
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 Utl.Gcc (Output_File => Jnk_File,
kono
parents:
diff changeset
131 Files => Ofiles,
kono
parents:
diff changeset
132 Options => All_Options,
kono
parents:
diff changeset
133 Base_File => Bas_File,
kono
parents:
diff changeset
134 Build_Lib => True);
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 -- 2) Build exp from base file
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 Utl.Dlltool (Def_File, Dll_File, Lib_File,
kono
parents:
diff changeset
139 Base_File => Bas_File,
kono
parents:
diff changeset
140 Exp_Table => Exp_File,
kono
parents:
diff changeset
141 Build_Import => False);
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 -- 3) Build base file with exp file and objects files
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 Utl.Gcc (Output_File => Jnk_File,
kono
parents:
diff changeset
146 Files => Objects_Exp_File,
kono
parents:
diff changeset
147 Options => All_Options,
kono
parents:
diff changeset
148 Base_File => Bas_File,
kono
parents:
diff changeset
149 Build_Lib => True);
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 -- 4) Build new exp from base file and the lib file (.a)
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 Utl.Dlltool (Def_File, Dll_File, Lib_File,
kono
parents:
diff changeset
154 Base_File => Bas_File,
kono
parents:
diff changeset
155 Exp_Table => Exp_File,
kono
parents:
diff changeset
156 Build_Import => Build_Import);
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 -- 5) Build the dynamic library
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 declare
kono
parents:
diff changeset
161 Params : constant OS_Lib.Argument_List :=
kono
parents:
diff changeset
162 Map_Opt'Unchecked_Access &
kono
parents:
diff changeset
163 Adr_Opt'Unchecked_Access & All_Options;
kono
parents:
diff changeset
164 First_Param : Positive := Params'First + 1;
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 begin
kono
parents:
diff changeset
167 if Map_File then
kono
parents:
diff changeset
168 First_Param := Params'First;
kono
parents:
diff changeset
169 end if;
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 Utl.Gcc
kono
parents:
diff changeset
172 (Output_File => Dll_File,
kono
parents:
diff changeset
173 Files => Objects_Exp_File,
kono
parents:
diff changeset
174 Options => Params (First_Param .. Params'Last),
kono
parents:
diff changeset
175 Build_Lib => True);
kono
parents:
diff changeset
176 end;
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178 OS_Lib.Delete_File (Exp_File, Success);
kono
parents:
diff changeset
179 OS_Lib.Delete_File (Bas_File, Success);
kono
parents:
diff changeset
180 OS_Lib.Delete_File (Jnk_File, Success);
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 exception
kono
parents:
diff changeset
183 when others =>
kono
parents:
diff changeset
184 OS_Lib.Delete_File (Exp_File, Success);
kono
parents:
diff changeset
185 OS_Lib.Delete_File (Bas_File, Success);
kono
parents:
diff changeset
186 OS_Lib.Delete_File (Jnk_File, Success);
kono
parents:
diff changeset
187 raise;
kono
parents:
diff changeset
188 end Build_Reloc_DLL;
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 -------------------------
kono
parents:
diff changeset
191 -- Ada_Build_Reloc_DLL --
kono
parents:
diff changeset
192 -------------------------
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194 procedure Ada_Build_Reloc_DLL is
kono
parents:
diff changeset
195 Success : Boolean;
kono
parents:
diff changeset
196 pragma Warnings (Off, Success);
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 begin
kono
parents:
diff changeset
199 if not Quiet then
kono
parents:
diff changeset
200 Text_IO.Put_Line ("Building relocatable DLL...");
kono
parents:
diff changeset
201 Text_IO.Put ("make " & Dll_File);
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 if Build_Import then
kono
parents:
diff changeset
204 Text_IO.Put_Line (" and " & Lib_File);
kono
parents:
diff changeset
205 else
kono
parents:
diff changeset
206 Text_IO.New_Line;
kono
parents:
diff changeset
207 end if;
kono
parents:
diff changeset
208 end if;
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 -- 1) Build base file with objects files
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 Utl.Gnatbind (L_Afiles, Options & Bargs_Options);
kono
parents:
diff changeset
213
kono
parents:
diff changeset
214 declare
kono
parents:
diff changeset
215 Params : constant OS_Lib.Argument_List :=
kono
parents:
diff changeset
216 Out_Opt'Unchecked_Access &
kono
parents:
diff changeset
217 Jnk_File'Unchecked_Access &
kono
parents:
diff changeset
218 Lib_Opt'Unchecked_Access &
kono
parents:
diff changeset
219 Bas_Opt'Unchecked_Access &
kono
parents:
diff changeset
220 Ofiles &
kono
parents:
diff changeset
221 All_Options;
kono
parents:
diff changeset
222 begin
kono
parents:
diff changeset
223 Utl.Gnatlink (L_Afiles (L_Afiles'Last).all, Params);
kono
parents:
diff changeset
224 end;
kono
parents:
diff changeset
225
kono
parents:
diff changeset
226 -- 2) Build exp from base file
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 Utl.Dlltool (Def_File, Dll_File, Lib_File,
kono
parents:
diff changeset
229 Base_File => Bas_File,
kono
parents:
diff changeset
230 Exp_Table => Exp_File,
kono
parents:
diff changeset
231 Build_Import => False);
kono
parents:
diff changeset
232
kono
parents:
diff changeset
233 -- 3) Build base file with exp file and objects files
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 Utl.Gnatbind (L_Afiles, Options & Bargs_Options);
kono
parents:
diff changeset
236
kono
parents:
diff changeset
237 declare
kono
parents:
diff changeset
238 Params : constant OS_Lib.Argument_List :=
kono
parents:
diff changeset
239 Out_Opt'Unchecked_Access &
kono
parents:
diff changeset
240 Jnk_File'Unchecked_Access &
kono
parents:
diff changeset
241 Lib_Opt'Unchecked_Access &
kono
parents:
diff changeset
242 Bas_Opt'Unchecked_Access &
kono
parents:
diff changeset
243 Exp_File'Unchecked_Access &
kono
parents:
diff changeset
244 Ofiles &
kono
parents:
diff changeset
245 All_Options;
kono
parents:
diff changeset
246 begin
kono
parents:
diff changeset
247 Utl.Gnatlink (L_Afiles (L_Afiles'Last).all, Params);
kono
parents:
diff changeset
248 end;
kono
parents:
diff changeset
249
kono
parents:
diff changeset
250 -- 4) Build new exp from base file and the lib file (.a)
kono
parents:
diff changeset
251
kono
parents:
diff changeset
252 Utl.Dlltool (Def_File, Dll_File, Lib_File,
kono
parents:
diff changeset
253 Base_File => Bas_File,
kono
parents:
diff changeset
254 Exp_Table => Exp_File,
kono
parents:
diff changeset
255 Build_Import => Build_Import);
kono
parents:
diff changeset
256
kono
parents:
diff changeset
257 -- 5) Build the dynamic library
kono
parents:
diff changeset
258
kono
parents:
diff changeset
259 Utl.Gnatbind (L_Afiles, Options & Bargs_Options);
kono
parents:
diff changeset
260
kono
parents:
diff changeset
261 declare
kono
parents:
diff changeset
262 Params : constant OS_Lib.Argument_List :=
kono
parents:
diff changeset
263 Map_Opt'Unchecked_Access &
kono
parents:
diff changeset
264 Out_Opt'Unchecked_Access &
kono
parents:
diff changeset
265 Dll_File'Unchecked_Access &
kono
parents:
diff changeset
266 Lib_Opt'Unchecked_Access &
kono
parents:
diff changeset
267 Exp_File'Unchecked_Access &
kono
parents:
diff changeset
268 Adr_Opt'Unchecked_Access &
kono
parents:
diff changeset
269 Ofiles &
kono
parents:
diff changeset
270 All_Options;
kono
parents:
diff changeset
271 First_Param : Positive := Params'First + 1;
kono
parents:
diff changeset
272
kono
parents:
diff changeset
273 begin
kono
parents:
diff changeset
274 if Map_File then
kono
parents:
diff changeset
275 First_Param := Params'First;
kono
parents:
diff changeset
276 end if;
kono
parents:
diff changeset
277
kono
parents:
diff changeset
278 Utl.Gnatlink
kono
parents:
diff changeset
279 (L_Afiles (L_Afiles'Last).all,
kono
parents:
diff changeset
280 Params (First_Param .. Params'Last));
kono
parents:
diff changeset
281 end;
kono
parents:
diff changeset
282
kono
parents:
diff changeset
283 OS_Lib.Delete_File (Exp_File, Success);
kono
parents:
diff changeset
284 OS_Lib.Delete_File (Bas_File, Success);
kono
parents:
diff changeset
285 OS_Lib.Delete_File (Jnk_File, Success);
kono
parents:
diff changeset
286
kono
parents:
diff changeset
287 exception
kono
parents:
diff changeset
288 when others =>
kono
parents:
diff changeset
289 OS_Lib.Delete_File (Exp_File, Success);
kono
parents:
diff changeset
290 OS_Lib.Delete_File (Bas_File, Success);
kono
parents:
diff changeset
291 OS_Lib.Delete_File (Jnk_File, Success);
kono
parents:
diff changeset
292 raise;
kono
parents:
diff changeset
293 end Ada_Build_Reloc_DLL;
kono
parents:
diff changeset
294
kono
parents:
diff changeset
295 -------------------------
kono
parents:
diff changeset
296 -- Build_Non_Reloc_DLL --
kono
parents:
diff changeset
297 -------------------------
kono
parents:
diff changeset
298
kono
parents:
diff changeset
299 procedure Build_Non_Reloc_DLL is
kono
parents:
diff changeset
300 Success : Boolean;
kono
parents:
diff changeset
301 pragma Warnings (Off, Success);
kono
parents:
diff changeset
302
kono
parents:
diff changeset
303 begin
kono
parents:
diff changeset
304 if not Quiet then
kono
parents:
diff changeset
305 Text_IO.Put_Line ("building non relocatable DLL...");
kono
parents:
diff changeset
306 Text_IO.Put ("make " & Dll_File &
kono
parents:
diff changeset
307 " using address " & Lib_Address);
kono
parents:
diff changeset
308
kono
parents:
diff changeset
309 if Build_Import then
kono
parents:
diff changeset
310 Text_IO.Put_Line (" and " & Lib_File);
kono
parents:
diff changeset
311 else
kono
parents:
diff changeset
312 Text_IO.New_Line;
kono
parents:
diff changeset
313 end if;
kono
parents:
diff changeset
314 end if;
kono
parents:
diff changeset
315
kono
parents:
diff changeset
316 -- Build exp table and the lib .a file
kono
parents:
diff changeset
317
kono
parents:
diff changeset
318 Utl.Dlltool (Def_File, Dll_File, Lib_File,
kono
parents:
diff changeset
319 Exp_Table => Exp_File,
kono
parents:
diff changeset
320 Build_Import => Build_Import);
kono
parents:
diff changeset
321
kono
parents:
diff changeset
322 -- Build the DLL
kono
parents:
diff changeset
323
kono
parents:
diff changeset
324 declare
kono
parents:
diff changeset
325 Params : OS_Lib.Argument_List :=
kono
parents:
diff changeset
326 Adr_Opt'Unchecked_Access & All_Options;
kono
parents:
diff changeset
327 begin
kono
parents:
diff changeset
328 if Map_File then
kono
parents:
diff changeset
329 Params := Map_Opt'Unchecked_Access & Params;
kono
parents:
diff changeset
330 end if;
kono
parents:
diff changeset
331
kono
parents:
diff changeset
332 Utl.Gcc (Output_File => Dll_File,
kono
parents:
diff changeset
333 Files => Exp_File'Unchecked_Access & Ofiles,
kono
parents:
diff changeset
334 Options => Params,
kono
parents:
diff changeset
335 Build_Lib => True);
kono
parents:
diff changeset
336 end;
kono
parents:
diff changeset
337
kono
parents:
diff changeset
338 OS_Lib.Delete_File (Exp_File, Success);
kono
parents:
diff changeset
339
kono
parents:
diff changeset
340 exception
kono
parents:
diff changeset
341 when others =>
kono
parents:
diff changeset
342 OS_Lib.Delete_File (Exp_File, Success);
kono
parents:
diff changeset
343 raise;
kono
parents:
diff changeset
344 end Build_Non_Reloc_DLL;
kono
parents:
diff changeset
345
kono
parents:
diff changeset
346 -----------------------------
kono
parents:
diff changeset
347 -- Ada_Build_Non_Reloc_DLL --
kono
parents:
diff changeset
348 -----------------------------
kono
parents:
diff changeset
349
kono
parents:
diff changeset
350 -- Build a non relocatable DLL with Ada code
kono
parents:
diff changeset
351
kono
parents:
diff changeset
352 procedure Ada_Build_Non_Reloc_DLL is
kono
parents:
diff changeset
353 Success : Boolean;
kono
parents:
diff changeset
354 pragma Warnings (Off, Success);
kono
parents:
diff changeset
355
kono
parents:
diff changeset
356 begin
kono
parents:
diff changeset
357 if not Quiet then
kono
parents:
diff changeset
358 Text_IO.Put_Line ("building non relocatable DLL...");
kono
parents:
diff changeset
359 Text_IO.Put ("make " & Dll_File &
kono
parents:
diff changeset
360 " using address " & Lib_Address);
kono
parents:
diff changeset
361
kono
parents:
diff changeset
362 if Build_Import then
kono
parents:
diff changeset
363 Text_IO.Put_Line (" and " & Lib_File);
kono
parents:
diff changeset
364 else
kono
parents:
diff changeset
365 Text_IO.New_Line;
kono
parents:
diff changeset
366 end if;
kono
parents:
diff changeset
367 end if;
kono
parents:
diff changeset
368
kono
parents:
diff changeset
369 -- Build exp table and the lib .a file
kono
parents:
diff changeset
370
kono
parents:
diff changeset
371 Utl.Dlltool (Def_File, Dll_File, Lib_File,
kono
parents:
diff changeset
372 Exp_Table => Exp_File,
kono
parents:
diff changeset
373 Build_Import => Build_Import);
kono
parents:
diff changeset
374
kono
parents:
diff changeset
375 -- Build the DLL
kono
parents:
diff changeset
376
kono
parents:
diff changeset
377 Utl.Gnatbind (L_Afiles, Options & Bargs_Options);
kono
parents:
diff changeset
378
kono
parents:
diff changeset
379 declare
kono
parents:
diff changeset
380 Params : OS_Lib.Argument_List :=
kono
parents:
diff changeset
381 Out_Opt'Unchecked_Access &
kono
parents:
diff changeset
382 Dll_File'Unchecked_Access &
kono
parents:
diff changeset
383 Lib_Opt'Unchecked_Access &
kono
parents:
diff changeset
384 Exp_File'Unchecked_Access &
kono
parents:
diff changeset
385 Adr_Opt'Unchecked_Access &
kono
parents:
diff changeset
386 Ofiles &
kono
parents:
diff changeset
387 All_Options;
kono
parents:
diff changeset
388 begin
kono
parents:
diff changeset
389 if Map_File then
kono
parents:
diff changeset
390 Params := Map_Opt'Unchecked_Access & Params;
kono
parents:
diff changeset
391 end if;
kono
parents:
diff changeset
392
kono
parents:
diff changeset
393 Utl.Gnatlink (L_Afiles (L_Afiles'Last).all, Params);
kono
parents:
diff changeset
394 end;
kono
parents:
diff changeset
395
kono
parents:
diff changeset
396 OS_Lib.Delete_File (Exp_File, Success);
kono
parents:
diff changeset
397
kono
parents:
diff changeset
398 exception
kono
parents:
diff changeset
399 when others =>
kono
parents:
diff changeset
400 OS_Lib.Delete_File (Exp_File, Success);
kono
parents:
diff changeset
401 raise;
kono
parents:
diff changeset
402 end Ada_Build_Non_Reloc_DLL;
kono
parents:
diff changeset
403
kono
parents:
diff changeset
404 -- Start of processing for Build_Dynamic_Library
kono
parents:
diff changeset
405
kono
parents:
diff changeset
406 begin
kono
parents:
diff changeset
407 -- On Windows the binder file must not be in the first position in the
kono
parents:
diff changeset
408 -- list. This is due to the way DLL's are built on Windows. We swap the
kono
parents:
diff changeset
409 -- first ali with the last one if it is the case.
kono
parents:
diff changeset
410
kono
parents:
diff changeset
411 if L_Afiles'Length > 1 then
kono
parents:
diff changeset
412 declare
kono
parents:
diff changeset
413 Filename : constant String :=
kono
parents:
diff changeset
414 Directory_Operations.Base_Name
kono
parents:
diff changeset
415 (L_Afiles (L_Afiles'First).all);
kono
parents:
diff changeset
416 First : constant Positive := Filename'First;
kono
parents:
diff changeset
417
kono
parents:
diff changeset
418 begin
kono
parents:
diff changeset
419 if Filename (First .. First + 1) = "b~" then
kono
parents:
diff changeset
420 L_Afiles (L_Afiles'Last) := Afiles (Afiles'First);
kono
parents:
diff changeset
421 L_Afiles (L_Afiles'First) := Afiles (Afiles'Last);
kono
parents:
diff changeset
422 end if;
kono
parents:
diff changeset
423 end;
kono
parents:
diff changeset
424 end if;
kono
parents:
diff changeset
425
kono
parents:
diff changeset
426 case Relocatable is
kono
parents:
diff changeset
427 when True =>
kono
parents:
diff changeset
428 if L_Afiles'Length = 0 then
kono
parents:
diff changeset
429 Build_Reloc_DLL;
kono
parents:
diff changeset
430 else
kono
parents:
diff changeset
431 Ada_Build_Reloc_DLL;
kono
parents:
diff changeset
432 end if;
kono
parents:
diff changeset
433
kono
parents:
diff changeset
434 when False =>
kono
parents:
diff changeset
435 if L_Afiles'Length = 0 then
kono
parents:
diff changeset
436 Build_Non_Reloc_DLL;
kono
parents:
diff changeset
437 else
kono
parents:
diff changeset
438 Ada_Build_Non_Reloc_DLL;
kono
parents:
diff changeset
439 end if;
kono
parents:
diff changeset
440 end case;
kono
parents:
diff changeset
441 end Build_Dynamic_Library;
kono
parents:
diff changeset
442
kono
parents:
diff changeset
443 --------------------------
kono
parents:
diff changeset
444 -- Build_Import_Library --
kono
parents:
diff changeset
445 --------------------------
kono
parents:
diff changeset
446
kono
parents:
diff changeset
447 procedure Build_Import_Library
kono
parents:
diff changeset
448 (Lib_Filename : String;
kono
parents:
diff changeset
449 Def_Filename : String)
kono
parents:
diff changeset
450 is
kono
parents:
diff changeset
451 procedure Build_Import_Library (Lib_Filename : String);
kono
parents:
diff changeset
452 -- Build an import library. This is to build only a .a library to link
kono
parents:
diff changeset
453 -- against a DLL.
kono
parents:
diff changeset
454
kono
parents:
diff changeset
455 --------------------------
kono
parents:
diff changeset
456 -- Build_Import_Library --
kono
parents:
diff changeset
457 --------------------------
kono
parents:
diff changeset
458
kono
parents:
diff changeset
459 procedure Build_Import_Library (Lib_Filename : String) is
kono
parents:
diff changeset
460
kono
parents:
diff changeset
461 function No_Lib_Prefix (Filename : String) return String;
kono
parents:
diff changeset
462 -- Return Filename without the lib prefix if present
kono
parents:
diff changeset
463
kono
parents:
diff changeset
464 -------------------
kono
parents:
diff changeset
465 -- No_Lib_Prefix --
kono
parents:
diff changeset
466 -------------------
kono
parents:
diff changeset
467
kono
parents:
diff changeset
468 function No_Lib_Prefix (Filename : String) return String is
kono
parents:
diff changeset
469 begin
kono
parents:
diff changeset
470 if Filename (Filename'First .. Filename'First + 2) = "lib" then
kono
parents:
diff changeset
471 return Filename (Filename'First + 3 .. Filename'Last);
kono
parents:
diff changeset
472 else
kono
parents:
diff changeset
473 return Filename;
kono
parents:
diff changeset
474 end if;
kono
parents:
diff changeset
475 end No_Lib_Prefix;
kono
parents:
diff changeset
476
kono
parents:
diff changeset
477 -- Local variables
kono
parents:
diff changeset
478
kono
parents:
diff changeset
479 Def_File : String renames Def_Filename;
kono
parents:
diff changeset
480 Dll_File : constant String := Get_Dll_Name (Lib_Filename);
kono
parents:
diff changeset
481 Base_Filename : constant String :=
kono
parents:
diff changeset
482 MDLL.Fil.Ext_To (No_Lib_Prefix (Lib_Filename));
kono
parents:
diff changeset
483 Lib_File : constant String := "lib" & Base_Filename & ".dll.a";
kono
parents:
diff changeset
484
kono
parents:
diff changeset
485 -- Start of processing for Build_Import_Library
kono
parents:
diff changeset
486
kono
parents:
diff changeset
487 begin
kono
parents:
diff changeset
488 if not Quiet then
kono
parents:
diff changeset
489 Text_IO.Put_Line ("Building import library...");
kono
parents:
diff changeset
490 Text_IO.Put_Line
kono
parents:
diff changeset
491 ("make " & Lib_File & " to use dynamic library " & Dll_File);
kono
parents:
diff changeset
492 end if;
kono
parents:
diff changeset
493
kono
parents:
diff changeset
494 Utl.Dlltool
kono
parents:
diff changeset
495 (Def_File, Dll_File, Lib_File, Build_Import => True);
kono
parents:
diff changeset
496 end Build_Import_Library;
kono
parents:
diff changeset
497
kono
parents:
diff changeset
498 -- Start of processing for Build_Import_Library
kono
parents:
diff changeset
499
kono
parents:
diff changeset
500 begin
kono
parents:
diff changeset
501 Build_Import_Library (Lib_Filename);
kono
parents:
diff changeset
502 end Build_Import_Library;
kono
parents:
diff changeset
503
kono
parents:
diff changeset
504 ------------------
kono
parents:
diff changeset
505 -- Get_Dll_Name --
kono
parents:
diff changeset
506 ------------------
kono
parents:
diff changeset
507
kono
parents:
diff changeset
508 function Get_Dll_Name (Lib_Filename : String) return String is
kono
parents:
diff changeset
509 begin
kono
parents:
diff changeset
510 if MDLL.Fil.Get_Ext (Lib_Filename) = "" then
kono
parents:
diff changeset
511 return Lib_Filename & ".dll";
kono
parents:
diff changeset
512 else
kono
parents:
diff changeset
513 return Lib_Filename;
kono
parents:
diff changeset
514 end if;
kono
parents:
diff changeset
515 end Get_Dll_Name;
kono
parents:
diff changeset
516
kono
parents:
diff changeset
517 end MDLL;