1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2002 Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
28 with ALI
.Util
; use ALI
.Util
;
29 with Bcheck
; use Bcheck
;
30 with Binde
; use Binde
;
31 with Binderr
; use Binderr
;
32 with Bindgen
; use Bindgen
;
34 with Butil
; use Butil
;
36 with Gnatvsn
; use Gnatvsn
;
37 with Namet
; use Namet
;
39 with Osint
; use Osint
;
40 with Osint
.B
; use Osint
.B
;
41 with Output
; use Output
;
42 with Switch
; use Switch
;
43 with Switch
.B
; use Switch
.B
;
44 with Targparm
; use Targparm
;
45 with Types
; use Types
;
49 Total_Errors
: Nat
:= 0;
50 -- Counts total errors in all files
52 Total_Warnings
: Nat
:= 0;
53 -- Total warnings in all files
55 Main_Lib_File
: File_Name_Type
;
56 -- Current main library file
58 Std_Lib_File
: File_Name_Type
;
61 Text
: Text_Buffer_Ptr
;
66 Output_File_Name_Seen
: Boolean := False;
68 Output_File_Name
: String_Ptr
:= new String'("");
70 procedure Scan_Bind_Arg (Argv : String);
71 -- Scan and process binder specific arguments. Argv is a single argument.
72 -- All the one character arguments are still handled by Switch. This
73 -- routine handles -aO -aI and -I-.
79 procedure Scan_Bind_Arg (Argv : String) is
81 -- Now scan arguments that are specific to the binder and are not
82 -- handled by the common circuitry in Switch.
84 if Opt.Output_File_Name_Present
85 and then not Output_File_Name_Seen
87 Output_File_Name_Seen := True;
90 or else (Argv'Length >= 1 and then Argv (1) = '-')
92 Fail ("output File_Name missing after -o");
95 Output_File_Name := new String'(Argv
);
98 elsif Argv
'Length >= 2 and then Argv
(1) = '-' then
102 if Argv
(2 .. Argv
'Last) = "I-" then
103 Opt
.Look_In_Primary_Dir
:= False;
107 elsif Argv
(2) = 'I' then
108 Add_Src_Search_Dir
(Argv
(3 .. Argv
'Last));
109 Add_Lib_Search_Dir
(Argv
(3 .. Argv
'Last));
113 elsif Argv
(2) = 'L' then
114 if Argv
'Length >= 3 then
115 Opt
.Bind_For_Library
:= True;
117 new String'(Argv (3 .. Argv'Last) & Opt.Ada_Init_Suffix);
118 Opt.Ada_Final_Name :=
119 new String'(Argv
(3 .. Argv
'Last) & Opt
.Ada_Final_Suffix
);
121 new String'(Argv (3 .. Argv'Last) & Opt.Ada_Main_Name_Suffix);
123 -- This option (-Lxxx) implies -n
125 Opt.Bind_Main_Program := False;
128 ("Prefix of initialization and finalization " &
129 "procedure names missing in -L");
132 -- -Sin -Slo -Shi -Sxx
134 elsif Argv'Length = 4
135 and then Argv (2) = 'S
'
138 C1 : Character := Argv (3);
139 C2 : Character := Argv (4);
142 if C1 in 'a
' .. 'z
' then
143 C1 := Character'Val (Character'Pos (C1) - 32);
146 if C2 in 'a
' .. 'z
' then
147 C2 := Character'Val (Character'Pos (C2) - 32);
150 if C1 = 'I
' and then C2 = 'N
' then
151 Initialize_Scalars_Mode := 'I
';
153 elsif C1 = 'L
' and then C2 = 'O
' then
154 Initialize_Scalars_Mode := 'L
';
156 elsif C1 = 'H
' and then C2 = 'I
' then
157 Initialize_Scalars_Mode := 'H
';
159 elsif (C1 in '0' .. '9' or else C1 in 'A
' .. 'F
')
161 (C2 in '0' .. '9' or else C2 in 'A
' .. 'F
')
163 Initialize_Scalars_Mode := 'X
';
164 Initialize_Scalars_Val (1) := C1;
165 Initialize_Scalars_Val (2) := C2;
167 -- Invalid -S switch, let Switch give error
170 Scan_Binder_Switches (Argv);
176 elsif Argv'Length >= 3
177 and then Argv (2 .. 3) = "aI"
179 Add_Src_Search_Dir (Argv (4 .. Argv'Last));
183 elsif Argv'Length >= 3
184 and then Argv (2 .. 3) = "aO"
186 Add_Lib_Search_Dir (Argv (4 .. Argv'Last));
190 elsif Argv (2 .. Argv'Last) = "nostdlib" then
191 Opt.No_Stdlib := True;
195 elsif Argv (2 .. Argv'Last) = "nostdinc" then
196 Opt.No_Stdinc := True;
200 elsif Argv (2 .. Argv'Last) = "static" then
201 Opt.Shared_Libgnat := False;
205 elsif Argv (2 .. Argv'Last) = "shared" then
206 Opt.Shared_Libgnat := True;
210 elsif Argv'Length >= 3 and then Argv (2) = 'M
' then
211 Opt.Bind_Alternate_Main_Name := True;
212 Opt.Alternate_Main_Name := new String '(Argv
(3 .. Argv
'Last));
214 -- All other options are single character and are handled
215 -- by Scan_Binder_Switches.
218 Scan_Binder_Switches
(Argv
);
221 -- Not a switch, so must be a file name (if non-empty)
223 elsif Argv
'Length /= 0 then
225 and then Argv
(Argv
'Last - 3 .. Argv
'Last) = ".ali"
229 Add_File
(Argv
& ".ali");
234 -- Start of processing for Gnatbind
238 -- Set default for Shared_Libgnat option
241 Shared_Libgnat_Default
: Character;
242 pragma Import
(C
, Shared_Libgnat_Default
, "shared_libgnat_default");
244 SHARED
: constant Character := 'H';
245 STATIC
: constant Character := 'T';
249 (Shared_Libgnat_Default
= SHARED
251 Shared_Libgnat_Default
= STATIC
);
252 Shared_Libgnat
:= (Shared_Libgnat_Default
= SHARED
);
255 -- Use low level argument routines to avoid dragging in the secondary stack
258 Scan_Args
: while Next_Arg
< Arg_Count
loop
260 Next_Argv
: String (1 .. Len_Arg
(Next_Arg
));
263 Fill_Arg
(Next_Argv
'Address, Next_Arg
);
264 Scan_Bind_Arg
(Next_Argv
);
266 Next_Arg
:= Next_Arg
+ 1;
269 -- Test for trailing -o switch
271 if Opt
.Output_File_Name_Present
272 and then not Output_File_Name_Seen
274 Fail
("output file name missing after -o");
277 -- Output usage if requested
279 if Usage_Requested
then
283 -- Check that the Ada binder file specified has extension .adb and that
284 -- the C binder file has extension .c
286 if Opt
.Output_File_Name_Present
287 and then Output_File_Name_Seen
289 Check_Extensions
: declare
290 Length
: constant Natural := Output_File_Name
'Length;
291 Last
: constant Natural := Output_File_Name
'Last;
294 if Ada_Bind_File
then
296 or else Output_File_Name
(Last
- 3 .. Last
) /= ".adb"
298 Fail
("output file name should have .adb extension");
303 or else Output_File_Name
(Last
- 1 .. Last
) /= ".c"
305 Fail
("output file name should have .c extension");
308 end Check_Extensions
;
311 Osint
.Add_Default_Search_Dirs
;
315 Targparm
.Get_Target_Parameters
;
318 Write_Str
("GNATBIND ");
320 if Targparm
.High_Integrity_Mode_On_Target
then
321 Write_Str
("Pro High Integrity ");
324 Write_Str
(Gnat_Version_String
);
325 Write_Str
(" Copyright 1995-2002 Free Software Foundation, Inc.");
329 -- Output usage information if no files
331 if not More_Lib_Files
then
333 Exit_Program
(E_Fatal
);
336 -- The block here is to catch the Unrecoverable_Error exception in the
337 -- case where we exceed the maximum number of permissible errors or some
338 -- other unrecoverable error occurs.
341 -- Carry out package initializations. These are initializations which
342 -- might logically be performed at elaboration time, but Namet at
343 -- least can't be done that way (because it is used in the Compiler),
344 -- and we decide to be consistent. Like elaboration, the order in
345 -- which these calls are made is in some cases important.
351 Initialize_ALI_Source
;
359 while More_Lib_Files
loop
360 Main_Lib_File
:= Next_Main_Lib_File
;
364 Write_Str
("Checking: ");
366 Write_Str
("Binding: ");
369 Write_Name
(Main_Lib_File
);
373 Text
:= Read_Library_Info
(Main_Lib_File
, True);
377 Ignore_ED
=> Force_RM_Elaboration_Order
,
382 -- Add System.Standard_Library to list to ensure that these files are
383 -- included in the bind, even if not directly referenced from Ada code
384 -- This is of course omitted in No_Run_Time mode
386 if not No_Run_Time_Specified
then
387 Name_Buffer
(1 .. 12) := "s-stalib.ali";
389 Std_Lib_File
:= Name_Find
;
390 Text
:= Read_Library_Info
(Std_Lib_File
, True);
395 Ignore_ED
=> Force_RM_Elaboration_Order
,
400 -- Acquire all information in ALI files that have been read in
402 for Index
in ALIs
.First
.. ALIs
.Last
loop
406 -- Warn if -f switch used
408 if Force_RM_Elaboration_Order
then
410 ("?-f is obsolescent and should not be used");
412 ("?may result in missing run-time elaboration checks");
414 ("?use -gnatE, pragma Suppress (Elaboration_Checks) instead");
417 -- Quit if some file needs compiling
419 if No_Object_Specified
then
420 raise Unrecoverable_Error
;
423 -- Build source file table from the ALI files we have read in
427 -- Check that main library file is a suitable main program
430 and then ALIs
.Table
(ALIs
.First
).Main_Program
= None
431 and then not No_Main_Subprogram
433 Error_Msg_Name_1
:= Main_Lib_File
;
434 Error_Msg
("% does not contain a unit that can be a main program");
437 -- Perform consistency and correctness checks
439 Check_Duplicated_Subunits
;
442 Check_Configuration_Consistency
;
444 -- Complete bind if no errors
446 if Errors_Detected
= 0 then
449 if Errors_Detected
= 0 then
450 if Elab_Order_Output
then
452 Write_Str
("ELABORATION ORDER");
455 for J
in Elab_Order
.First
.. Elab_Order
.Last
loop
457 Write_Unit_Name
(Units
.Table
(Elab_Order
.Table
(J
)).Uname
);
464 if not Check_Only
then
465 Gen_Output_File
(Output_File_Name
.all);
470 Total_Errors
:= Total_Errors
+ Errors_Detected
;
471 Total_Warnings
:= Total_Warnings
+ Warnings_Detected
;
474 when Unrecoverable_Error
=>
475 Total_Errors
:= Total_Errors
+ Errors_Detected
;
476 Total_Warnings
:= Total_Warnings
+ Warnings_Detected
;
479 -- All done. Set proper exit status.
484 if Total_Errors
> 0 then
485 Exit_Program
(E_Errors
);
486 elsif Total_Warnings
> 0 then
487 Exit_Program
(E_Warnings
);
489 Exit_Program
(E_Success
);