1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 1997-2000 Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- Extensive contributions were provided by Ada Core Technologies Inc. --
27 ------------------------------------------------------------------------------
29 -- Program to create, set, or delete an alternate runtime library.
31 -- Works by calling an appropriate target specific Makefile residing
32 -- in the default library object (e.g. adalib) directory from the context
33 -- of the new library objects directory.
35 -- Command line arguments are:
36 -- 1st: --[create | set | delete]=<directory_spec>
37 -- --create : Build a library
38 -- --set : Set environment variables to point to a library
39 -- --delete : Delete a library
41 -- 2nd: --config=<file_spec>
42 -- A -gnatg valid file containing desired configuration pragmas
44 -- This program is currently used only on Alpha/VMS
46 with Ada
.Command_Line
; use Ada
.Command_Line
;
47 with Ada
.Text_IO
; use Ada
.Text_IO
;
48 with GNAT
.OS_Lib
; use GNAT
.OS_Lib
;
49 with Gnatvsn
; use Gnatvsn
;
50 with Interfaces
.C_Streams
; use Interfaces
.C_Streams
;
51 with Osint
; use Osint
;
52 with Sdefault
; use Sdefault
;
56 pragma Ident
(Gnat_Version_String
);
58 type Lib_Mode
is (None
, Create
, Set
, Delete
);
60 Mode
: Lib_Mode
:= None
;
61 ADC_File
: String_Access
:= null;
62 Lib_Dir
: String_Access
:= null;
63 Make
: constant String := "make";
64 Make_Path
: String_Access
;
66 procedure Create_Directory
(Name
: System
.Address
; Mode
: Integer);
67 pragma Import
(C
, Create_Directory
, "mkdir");
70 if Argument_Count
= 0 then
73 ("gnatlbr --[create|set|delete]=<directory> [--config=<file>]");
74 Exit_Program
(E_Fatal
);
80 exit when Next_Arg
> Argument_Count
;
82 Process_One_Arg
: declare
83 Arg
: String := Argument
(Next_Arg
);
87 if Arg
'Length > 9 and then Arg
(1 .. 9) = "--create=" then
90 Lib_Dir
:= new String'(Arg (10 .. Arg'Last));
92 Put_Line (Standard_Error, "Error: Multiple modes specified");
93 Exit_Program (E_Fatal);
96 elsif Arg'Length > 6 and then Arg (1 .. 6) = "--set=" then
99 Lib_Dir := new String'(Arg
(7 .. Arg
'Last));
101 Put_Line
(Standard_Error
, "Error: Multiple modes specified");
102 Exit_Program
(E_Fatal
);
105 elsif Arg
'Length > 9 and then Arg
(1 .. 9) = "--delete=" then
108 Lib_Dir
:= new String'(Arg (10 .. Arg'Last));
110 Put_Line (Standard_Error, "Error: Multiple modes specified");
111 Exit_Program (E_Fatal);
114 elsif Arg'Length > 9 and then Arg (1 .. 9) = "--config=" then
115 if ADC_File /= null then
116 Put_Line (Standard_Error,
117 "Error: Multiple gnat.adc files specified");
118 Exit_Program (E_Fatal);
121 ADC_File := new String'(Arg
(10 .. Arg
'Last));
124 Put_Line
(Standard_Error
, "Error: Unrecognized option: " & Arg
);
125 Exit_Program
(E_Fatal
);
130 Next_Arg
:= Next_Arg
+ 1;
136 -- Validate arguments
138 if Lib_Dir
= null then
139 Put_Line
(Standard_Error
, "Error: No library directory specified");
140 Exit_Program
(E_Fatal
);
143 if Is_Directory
(Lib_Dir
.all) then
144 Put_Line
(Standard_Error
,
145 "Error:" & Lib_Dir
.all & " already exists");
146 Exit_Program
(E_Fatal
);
149 if ADC_File
= null then
150 Put_Line
(Standard_Error
,
151 "Error: No configuration file specified");
152 Exit_Program
(E_Fatal
);
155 if not Is_Regular_File
(ADC_File
.all) then
156 Put_Line
(Standard_Error
,
157 "Error: " & ADC_File
.all & " doesn't exist");
158 Exit_Program
(E_Fatal
);
161 Create_Block
: declare
163 Make_Args
: Argument_List
(1 .. 9);
164 C_Lib_Dir
: String := Lib_Dir
.all & ASCII
.Nul
;
165 C_ADC_File
: String := ADC_File
.all & ASCII
.Nul
;
166 F_ADC_File
: String (1 .. max_path_len
);
167 F_ADC_File_Len
: Integer := max_path_len
;
168 Include_Dirs
: Integer;
169 Object_Dirs
: Integer;
170 Include_Dir
: array (Integer range 1 .. 256) of String_Access
;
171 Object_Dir
: array (Integer range 1 .. 256) of String_Access
;
172 Include_Dir_Name
: String_Access
;
173 Object_Dir_Name
: String_Access
;
176 -- Create the new top level library directory
178 if not Is_Directory
(Lib_Dir
.all) then
179 Create_Directory
(C_Lib_Dir
'Address, 8#
755#
);
182 full_name
(C_ADC_File
'Address, F_ADC_File
'Address);
184 for I
in 1 .. max_path_len
loop
185 if F_ADC_File
(I
) = ASCII
.Nul
then
186 F_ADC_File_Len
:= I
- 1;
192 -- Make a list of the default library source and object
193 -- directories. Usually only one, except on VMS where
197 Include_Dir_Name
:= String_Access
(Include_Dir_Default_Name
);
198 Get_Next_Dir_In_Path_Init
(String_Access
(Include_Dir_Name
));
202 Dir
: String_Access
:= String_Access
203 (Get_Next_Dir_In_Path
(String_Access
(Include_Dir_Name
)));
205 exit when Dir
= null;
206 Include_Dirs
:= Include_Dirs
+ 1;
207 Include_Dir
(Include_Dirs
)
208 := String_Access
(Normalize_Directory_Name
(Dir
.all));
213 Object_Dir_Name
:= String_Access
(Object_Dir_Default_Name
);
214 Get_Next_Dir_In_Path_Init
(String_Access
(Object_Dir_Name
));
218 Dir
: String_Access
:= String_Access
219 (Get_Next_Dir_In_Path
(String_Access
(Object_Dir_Name
)));
221 exit when Dir
= null;
222 Object_Dirs
:= Object_Dirs
+ 1;
223 Object_Dir
(Object_Dirs
)
224 := String_Access
(Normalize_Directory_Name
(Dir
.all));
228 -- "Make" an alternate sublibrary for each default sublibrary.
230 for Dirs
in 1 .. Object_Dirs
loop
236 new String'(Lib_Dir
.all);
238 -- Resolve /gnu on VMS by converting to host format and then
239 -- convert resolved path back to canonical format for the
240 -- make program. This fixes the problem that can occur when
241 -- GNU: is a search path pointing to multiple versions of GNAT.
244 new String'("ADA_INCLUDE_PATH=" &
245 To_Canonical_Dir_Spec
247 (Include_Dir (Dirs).all, True).all, True).all);
250 new String'("ADA_OBJECTS_PATH=" &
251 To_Canonical_Dir_Spec
253 (Object_Dir
(Dirs
).all, True).all, True).all);
256 new String'("GNAT_ADC_FILE="
257 & F_ADC_File (1 .. F_ADC_File_Len));
260 new String'("LIBRARY_VERSION=" & '"' & Library_Version
& '"');
266 new String'(Object_Dir
(Dirs
).all & "Makefile.lib");
269 new String'("create");
271 Make_Path := Locate_Exec_On_Path (Make);
274 for I in 1 .. Make_Args'Last loop
276 Put (Make_Args (I).all);
280 Spawn (Make_Path.all, Make_Args, Success);
282 Put_Line (Standard_Error, "Error: Make failed");
283 Exit_Program (E_Fatal);
290 -- Validate arguments.
292 if Lib_Dir = null then
293 Put_Line (Standard_Error,
294 "Error: No library directory specified");
295 Exit_Program (E_Fatal);
298 if not Is_Directory (Lib_Dir.all) then
299 Put_Line (Standard_Error,
300 "Error: " & Lib_Dir.all & " doesn't exist");
301 Exit_Program (E_Fatal);
304 if ADC_File = null then
305 Put_Line (Standard_Error,
306 "Error: No configuration file specified");
307 Exit_Program (E_Fatal);
310 if not Is_Regular_File (ADC_File.all) then
311 Put_Line (Standard_Error,
312 "Error: " & ADC_File.all & " doesn't exist");
313 Exit_Program (E_Fatal);
316 -- Give instructions.
318 Put_Line ("Copy the contents of "
319 & ADC_File.all & " into your GNAT.ADC file");
320 Put_Line ("and use GNAT Make qualifier /OBJECT_SEARCH=("
322 (Lib_Dir (Lib_Dir'First .. Lib_Dir'Last) & "/declib", False).all
325 (Lib_Dir (Lib_Dir'First .. Lib_Dir'Last) & "/adalib", False).all
327 Put_Line ("or else define ADA_OBJECTS_PATH as " & '"'
329 (Lib_Dir (Lib_Dir'First .. Lib_Dir'Last) & "/declib
", False).all
332 (Lib_Dir (Lib_Dir'First .. Lib_Dir'Last) & "/adalib
", False).all
337 -- Give instructions.
339 Put_Line ("GNAT Librarian DELETE not yet implemented.");
340 Put_Line ("Use appropriate system tools to remove library");
343 Put_Line (Standard_Error,
344 "Error: No mode (create|set|delete) specified");
345 Exit_Program (E_Fatal);