1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- G N A T L B R --
-- --
-- B o d y --
-- --
-- Copyright (C) 1997-2003 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, 59 Temple Place - Suite 330, Boston, --
-- MA 02111-1307, USA. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- Program to create, set, or delete an alternate runtime library.
-- Works by calling an appropriate target specific Makefile residing
-- in the default library object (e.g. adalib) directory from the context
-- of the new library objects directory.
-- Command line arguments are:
-- 1st: --[create | set | delete]=<directory_spec>
-- --create : Build a library
-- --set : Set environment variables to point to a library
-- --delete : Delete a library
-- 2nd: --config=<file_spec>
-- A -gnatg valid file containing desired configuration pragmas
-- This program is currently used only on Alpha/VMS
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Text_IO; use Ada.Text_IO;
with GNAT.OS_Lib; use GNAT.OS_Lib;
with Gnatvsn; use Gnatvsn;
with Interfaces.C_Streams; use Interfaces.C_Streams;
with Osint; use Osint;
with System;
procedure GnatLbr is
pragma Ident (Gnat_Static_Version_String);
type Lib_Mode is (None, Create, Set, Delete);
Next_Arg : Integer;
Mode : Lib_Mode := None;
ADC_File : String_Access := null;
Lib_Dir : String_Access := null;
Make : constant String := "make";
Make_Path : String_Access;
procedure Create_Directory (Name : System.Address; Mode : Integer);
pragma Import (C, Create_Directory, "mkdir");
begin
if Argument_Count = 0 then
Put ("Usage: ");
Put_Line
("gnatlbr --[create|set|delete]=<directory> [--config=<file>]");
Exit_Program (E_Fatal);
end if;
Next_Arg := 1;
loop
exit when Next_Arg > Argument_Count;
Process_One_Arg : declare
Arg : String := Argument (Next_Arg);
begin
if Arg'Length > 9 and then Arg (1 .. 9) = "--create=" then
if Mode = None then
Mode := Create;
Lib_Dir := new String'(Arg (10 .. Arg'Last));
else
Put_Line (Standard_Error, "Error: Multiple modes specified");
Exit_Program (E_Fatal);
end if;
elsif Arg'Length > 6 and then Arg (1 .. 6) = "--set=" then
if Mode = None then
Mode := Set;
Lib_Dir := new String'(Arg (7 .. Arg'Last));
else
Put_Line (Standard_Error, "Error: Multiple modes specified");
Exit_Program (E_Fatal);
end if;
elsif Arg'Length > 9 and then Arg (1 .. 9) = "--delete=" then
if Mode = None then
Mode := Delete;
Lib_Dir := new String'(Arg (10 .. Arg'Last));
else
Put_Line (Standard_Error, "Error: Multiple modes specified");
Exit_Program (E_Fatal);
end if;
elsif Arg'Length > 9 and then Arg (1 .. 9) = "--config=" then
if ADC_File /= null then
Put_Line (Standard_Error,
"Error: Multiple gnat.adc files specified");
Exit_Program (E_Fatal);
end if;
ADC_File := new String'(Arg (10 .. Arg'Last));
else
Put_Line (Standard_Error, "Error: Unrecognized option: " & Arg);
Exit_Program (E_Fatal);
end if;
end Process_One_Arg;
Next_Arg := Next_Arg + 1;
end loop;
case Mode is
when Create =>
-- Validate arguments
if Lib_Dir = null then
Put_Line (Standard_Error, "Error: No library directory specified");
Exit_Program (E_Fatal);
end if;
if Is_Directory (Lib_Dir.all) then
Put_Line (Standard_Error,
"Error:" & Lib_Dir.all & " already exists");
Exit_Program (E_Fatal);
end if;
if ADC_File = null then
Put_Line (Standard_Error,
"Error: No configuration file specified");
Exit_Program (E_Fatal);
end if;
if not Is_Regular_File (ADC_File.all) then
Put_Line (Standard_Error,
"Error: " & ADC_File.all & " doesn't exist");
Exit_Program (E_Fatal);
end if;
Create_Block : declare
Success : Boolean;
Make_Args : Argument_List (1 .. 9);
C_Lib_Dir : String := Lib_Dir.all & ASCII.Nul;
C_ADC_File : String := ADC_File.all & ASCII.Nul;
F_ADC_File : String (1 .. max_path_len);
F_ADC_File_Len : Integer := max_path_len;
Include_Dirs : Integer;
Object_Dirs : Integer;
Include_Dir : array (Integer range 1 .. 256) of String_Access;
Object_Dir : array (Integer range 1 .. 256) of String_Access;
Include_Dir_Name : String_Access;
Object_Dir_Name : String_Access;
begin
-- Create the new top level library directory
if not Is_Directory (Lib_Dir.all) then
Create_Directory (C_Lib_Dir'Address, 8#755#);
end if;
full_name (C_ADC_File'Address, F_ADC_File'Address);
for I in 1 .. max_path_len loop
if F_ADC_File (I) = ASCII.Nul then
F_ADC_File_Len := I - 1;
exit;
end if;
end loop;
--
-- Make a list of the default library source and object
-- directories. Usually only one, except on VMS where
-- there are two.
--
Include_Dirs := 0;
Include_Dir_Name := new String'(Include_Dir_Default_Prefix);
Get_Next_Dir_In_Path_Init (String_Access (Include_Dir_Name));
loop
declare
Dir : String_Access := String_Access
(Get_Next_Dir_In_Path (String_Access (Include_Dir_Name)));
begin
exit when Dir = null;
Include_Dirs := Include_Dirs + 1;
Include_Dir (Include_Dirs)
:= String_Access (Normalize_Directory_Name (Dir.all));
end;
end loop;
Object_Dirs := 0;
Object_Dir_Name := new String'(Object_Dir_Default_Prefix);
Get_Next_Dir_In_Path_Init (String_Access (Object_Dir_Name));
loop
declare
Dir : String_Access := String_Access
(Get_Next_Dir_In_Path (String_Access (Object_Dir_Name)));
begin
exit when Dir = null;
Object_Dirs := Object_Dirs + 1;
Object_Dir (Object_Dirs)
:= String_Access (Normalize_Directory_Name (Dir.all));
end;
end loop;
-- "Make" an alternate sublibrary for each default sublibrary.
for Dirs in 1 .. Object_Dirs loop
Make_Args (1) :=
new String'("-C");
Make_Args (2) :=
new String'(Lib_Dir.all);
-- Resolve /gnu on VMS by converting to host format and then
-- convert resolved path back to canonical format for the
-- make program. This fixes the problem that can occur when
-- GNU: is a search path pointing to multiple versions of GNAT.
Make_Args (3) :=
new String'("ADA_INCLUDE_PATH=" &
To_Canonical_Dir_Spec
(To_Host_Dir_Spec
(Include_Dir (Dirs).all, True).all, True).all);
Make_Args (4) :=
new String'("ADA_OBJECTS_PATH=" &
To_Canonical_Dir_Spec
(To_Host_Dir_Spec
(Object_Dir (Dirs).all, True).all, True).all);
Make_Args (5) :=
new String'("GNAT_ADC_FILE="
& F_ADC_File (1 .. F_ADC_File_Len));
Make_Args (6) :=
new String'("LIBRARY_VERSION=" & '"' & Library_Version & '"');
Make_Args (7) :=
new String'("-f");
Make_Args (8) :=
new String'(Object_Dir (Dirs).all & "Makefile.lib");
Make_Args (9) :=
new String'("create");
Make_Path := Locate_Exec_On_Path (Make);
Put (Make);
for I in 1 .. Make_Args'Last loop
Put (" ");
Put (Make_Args (I).all);
end loop;
New_Line;
Spawn (Make_Path.all, Make_Args, Success);
if not Success then
Put_Line (Standard_Error, "Error: Make failed");
Exit_Program (E_Fatal);
end if;
end loop;
end Create_Block;
when Set =>
-- Validate arguments.
if Lib_Dir = null then
Put_Line (Standard_Error,
"Error: No library directory specified");
Exit_Program (E_Fatal);
end if;
if not Is_Directory (Lib_Dir.all) then
Put_Line (Standard_Error,
"Error: " & Lib_Dir.all & " doesn't exist");
Exit_Program (E_Fatal);
end if;
if ADC_File = null then
Put_Line (Standard_Error,
"Error: No configuration file specified");
Exit_Program (E_Fatal);
end if;
if not Is_Regular_File (ADC_File.all) then
Put_Line (Standard_Error,
"Error: " & ADC_File.all & " doesn't exist");
Exit_Program (E_Fatal);
end if;
-- Give instructions.
Put_Line ("Copy the contents of "
& ADC_File.all & " into your GNAT.ADC file");
Put_Line ("and use GNAT Make qualifier /OBJECT_SEARCH=("
& To_Host_Dir_Spec
(Lib_Dir (Lib_Dir'First .. Lib_Dir'Last) & "/declib", False).all
& ","
& To_Host_Dir_Spec
(Lib_Dir (Lib_Dir'First .. Lib_Dir'Last) & "/adalib", False).all
& ")");
Put_Line ("or else define ADA_OBJECTS_PATH as " & '"'
& To_Host_Dir_Spec
(Lib_Dir (Lib_Dir'First .. Lib_Dir'Last) & "/declib", False).all
& ','
& To_Host_Dir_Spec
(Lib_Dir (Lib_Dir'First .. Lib_Dir'Last) & "/adalib", False).all
& '"');
when Delete =>
-- Give instructions.
Put_Line ("GNAT Librarian DELETE not yet implemented.");
Put_Line ("Use appropriate system tools to remove library");
when None =>
Put_Line (Standard_Error,
"Error: No mode (create|set|delete) specified");
Exit_Program (E_Fatal);
end case;
end GnatLbr;
|