1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 1992-2002 Free Software Foundation, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
26 ------------------------------------------------------------------------------
29 with ALI
.Util
; use ALI
.Util
;
30 with Bcheck
; use Bcheck
;
31 with Binde
; use Binde
;
32 with Binderr
; use Binderr
;
33 with Bindgen
; use Bindgen
;
35 with Butil
; use Butil
;
37 with Gnatvsn
; use Gnatvsn
;
38 with Namet
; use Namet
;
40 with Osint
; use Osint
;
41 with Osint
.B
; use Osint
.B
;
42 with Output
; use Output
;
43 with Switch
; use Switch
;
44 with Switch
.B
; use Switch
.B
;
45 with Targparm
; use Targparm
;
46 with Types
; use Types
;
50 Total_Errors
: Nat
:= 0;
51 -- Counts total errors in all files
53 Total_Warnings
: Nat
:= 0;
54 -- Total warnings in all files
56 Main_Lib_File
: File_Name_Type
;
57 -- Current main library file
59 Std_Lib_File
: File_Name_Type
;
62 Text
: Text_Buffer_Ptr
;
67 Output_File_Name_Seen
: Boolean := False;
69 Output_File_Name
: String_Ptr
:= new String'("");
71 procedure Scan_Bind_Arg (Argv : String);
72 -- Scan and process binder specific arguments. Argv is a single argument.
73 -- All the one character arguments are still handled by Switch. This
74 -- routine handles -aO -aI and -I-.
80 procedure Scan_Bind_Arg (Argv : String) is
82 -- Now scan arguments that are specific to the binder and are not
83 -- handled by the common circuitry in Switch.
85 if Opt.Output_File_Name_Present
86 and then not Output_File_Name_Seen
88 Output_File_Name_Seen := True;
91 or else (Argv'Length >= 1 and then Argv (1) = '-')
93 Fail ("output File_Name missing after -o");
96 Output_File_Name := new String'(Argv
);
99 elsif Argv
'Length >= 2 and then Argv
(1) = '-' then
103 if Argv
(2 .. Argv
'Last) = "I-" then
104 Opt
.Look_In_Primary_Dir
:= False;
108 elsif Argv
(2) = 'I' then
109 Add_Src_Search_Dir
(Argv
(3 .. Argv
'Last));
110 Add_Lib_Search_Dir
(Argv
(3 .. Argv
'Last));
114 elsif Argv
(2) = 'L' then
115 if Argv
'Length >= 3 then
116 Opt
.Bind_For_Library
:= True;
118 new String'(Argv (3 .. Argv'Last) & Opt.Ada_Init_Suffix);
119 Opt.Ada_Final_Name :=
120 new String'(Argv
(3 .. Argv
'Last) & Opt
.Ada_Final_Suffix
);
122 new String'(Argv (3 .. Argv'Last) & Opt.Ada_Main_Name_Suffix);
124 -- This option (-Lxxx) implies -n
126 Opt.Bind_Main_Program := False;
129 ("Prefix of initialization and finalization " &
130 "procedure names missing in -L");
133 -- -Sin -Slo -Shi -Sxx
135 elsif Argv'Length = 4
136 and then Argv (2) = 'S
'
139 C1 : Character := Argv (3);
140 C2 : Character := Argv (4);
143 if C1 in 'a
' .. 'z
' then
144 C1 := Character'Val (Character'Pos (C1) - 32);
147 if C2 in 'a
' .. 'z
' then
148 C2 := Character'Val (Character'Pos (C2) - 32);
151 if C1 = 'I
' and then C2 = 'N
' then
152 Initialize_Scalars_Mode := 'I
';
154 elsif C1 = 'L
' and then C2 = 'O
' then
155 Initialize_Scalars_Mode := 'L
';
157 elsif C1 = 'H
' and then C2 = 'I
' then
158 Initialize_Scalars_Mode := 'H
';
160 elsif (C1 in '0' .. '9' or else C1 in 'A
' .. 'F
')
162 (C2 in '0' .. '9' or else C2 in 'A
' .. 'F
')
164 Initialize_Scalars_Mode := 'X
';
165 Initialize_Scalars_Val (1) := C1;
166 Initialize_Scalars_Val (2) := C2;
168 -- Invalid -S switch, let Switch give error
171 Scan_Binder_Switches (Argv);
177 elsif Argv'Length >= 3
178 and then Argv (2 .. 3) = "aI"
180 Add_Src_Search_Dir (Argv (4 .. Argv'Last));
184 elsif Argv'Length >= 3
185 and then Argv (2 .. 3) = "aO"
187 Add_Lib_Search_Dir (Argv (4 .. Argv'Last));
191 elsif Argv (2 .. Argv'Last) = "nostdlib" then
192 Opt.No_Stdlib := True;
196 elsif Argv (2 .. Argv'Last) = "nostdinc" then
197 Opt.No_Stdinc := True;
201 elsif Argv (2 .. Argv'Last) = "static" then
202 Opt.Shared_Libgnat := False;
206 elsif Argv (2 .. Argv'Last) = "shared" then
207 Opt.Shared_Libgnat := True;
211 elsif Argv'Length >= 3 and then Argv (2) = 'M
' then
212 Opt.Bind_Alternate_Main_Name := True;
213 Opt.Alternate_Main_Name := new String '(Argv
(3 .. Argv
'Last));
215 -- All other options are single character and are handled
216 -- by Scan_Binder_Switches.
219 Scan_Binder_Switches
(Argv
);
222 -- Not a switch, so must be a file name (if non-empty)
224 elsif Argv
'Length /= 0 then
226 and then Argv
(Argv
'Last - 3 .. Argv
'Last) = ".ali"
230 Add_File
(Argv
& ".ali");
235 -- Start of processing for Gnatbind
239 -- Set default for Shared_Libgnat option
242 Shared_Libgnat_Default
: Character;
243 pragma Import
(C
, Shared_Libgnat_Default
, "shared_libgnat_default");
245 SHARED
: constant Character := 'H';
246 STATIC
: constant Character := 'T';
250 (Shared_Libgnat_Default
= SHARED
252 Shared_Libgnat_Default
= STATIC
);
253 Shared_Libgnat
:= (Shared_Libgnat_Default
= SHARED
);
256 -- Use low level argument routines to avoid dragging in the secondary stack
259 Scan_Args
: while Next_Arg
< Arg_Count
loop
261 Next_Argv
: String (1 .. Len_Arg
(Next_Arg
));
264 Fill_Arg
(Next_Argv
'Address, Next_Arg
);
265 Scan_Bind_Arg
(Next_Argv
);
267 Next_Arg
:= Next_Arg
+ 1;
270 -- Test for trailing -o switch
272 if Opt
.Output_File_Name_Present
273 and then not Output_File_Name_Seen
275 Fail
("output file name missing after -o");
278 -- Output usage if requested
280 if Usage_Requested
then
284 -- Check that the Ada binder file specified has extension .adb and that
285 -- the C binder file has extension .c
287 if Opt
.Output_File_Name_Present
288 and then Output_File_Name_Seen
290 Check_Extensions
: declare
291 Length
: constant Natural := Output_File_Name
'Length;
292 Last
: constant Natural := Output_File_Name
'Last;
295 if Ada_Bind_File
then
297 or else Output_File_Name
(Last
- 3 .. Last
) /= ".adb"
299 Fail
("output file name should have .adb extension");
304 or else Output_File_Name
(Last
- 1 .. Last
) /= ".c"
306 Fail
("output file name should have .c extension");
309 end Check_Extensions
;
312 Osint
.Add_Default_Search_Dirs
;
316 Targparm
.Get_Target_Parameters
;
319 Write_Str
("GNATBIND ");
321 if Targparm
.High_Integrity_Mode_On_Target
then
322 Write_Str
("Pro High Integrity ");
325 Write_Str
(Gnat_Version_String
);
326 Write_Str
(" Copyright 1995-2002 Free Software Foundation, Inc.");
330 -- Output usage information if no files
332 if not More_Lib_Files
then
334 Exit_Program
(E_Fatal
);
337 -- The block here is to catch the Unrecoverable_Error exception in the
338 -- case where we exceed the maximum number of permissible errors or some
339 -- other unrecoverable error occurs.
342 -- Carry out package initializations. These are initializations which
343 -- might logically be performed at elaboration time, but Namet at
344 -- least can't be done that way (because it is used in the Compiler),
345 -- and we decide to be consistent. Like elaboration, the order in
346 -- which these calls are made is in some cases important.
352 Initialize_ALI_Source
;
360 while More_Lib_Files
loop
361 Main_Lib_File
:= Next_Main_Lib_File
;
365 Write_Str
("Checking: ");
367 Write_Str
("Binding: ");
370 Write_Name
(Main_Lib_File
);
374 Text
:= Read_Library_Info
(Main_Lib_File
, True);
378 Ignore_ED
=> Force_RM_Elaboration_Order
,
383 -- Add System.Standard_Library to list to ensure that these files are
384 -- included in the bind, even if not directly referenced from Ada code
385 -- This is of course omitted in No_Run_Time mode
387 if not No_Run_Time_Specified
then
388 Name_Buffer
(1 .. 12) := "s-stalib.ali";
390 Std_Lib_File
:= Name_Find
;
391 Text
:= Read_Library_Info
(Std_Lib_File
, True);
396 Ignore_ED
=> Force_RM_Elaboration_Order
,
401 -- Acquire all information in ALI files that have been read in
403 for Index
in ALIs
.First
.. ALIs
.Last
loop
407 -- Warn if -f switch used
409 if Force_RM_Elaboration_Order
then
411 ("?-f is obsolescent and should not be used");
413 ("?may result in missing run-time elaboration checks");
415 ("?use -gnatE, pragma Suppress (Elaboration_Checks) instead");
418 -- Quit if some file needs compiling
420 if No_Object_Specified
then
421 raise Unrecoverable_Error
;
424 -- Build source file table from the ALI files we have read in
428 -- Check that main library file is a suitable main program
431 and then ALIs
.Table
(ALIs
.First
).Main_Program
= None
432 and then not No_Main_Subprogram
434 Error_Msg_Name_1
:= Main_Lib_File
;
435 Error_Msg
("% does not contain a unit that can be a main program");
438 -- Perform consistency and correctness checks
440 Check_Duplicated_Subunits
;
443 Check_Configuration_Consistency
;
445 -- Complete bind if no errors
447 if Errors_Detected
= 0 then
450 if Errors_Detected
= 0 then
451 if Elab_Order_Output
then
453 Write_Str
("ELABORATION ORDER");
456 for J
in Elab_Order
.First
.. Elab_Order
.Last
loop
458 Write_Unit_Name
(Units
.Table
(Elab_Order
.Table
(J
)).Uname
);
465 if not Check_Only
then
466 Gen_Output_File
(Output_File_Name
.all);
471 Total_Errors
:= Total_Errors
+ Errors_Detected
;
472 Total_Warnings
:= Total_Warnings
+ Warnings_Detected
;
475 when Unrecoverable_Error
=>
476 Total_Errors
:= Total_Errors
+ Errors_Detected
;
477 Total_Warnings
:= Total_Warnings
+ Warnings_Detected
;
480 -- All done. Set proper exit status.
485 if Total_Errors
> 0 then
486 Exit_Program
(E_Errors
);
487 elsif Total_Warnings
> 0 then
488 Exit_Program
(E_Warnings
);
490 Exit_Program
(E_Success
);