with ALI; use ALI;
with ALI.Util; use ALI.Util;
with Bcheck; use Bcheck;
with Binde; use Binde;
with Binderr; use Binderr;
with Bindgen; use Bindgen;
with Bindusg;
with Butil; use Butil;
with Csets;
with Gnatvsn; use Gnatvsn;
with Namet; use Namet;
with Opt; use Opt;
with Osint; use Osint;
with Osint.B; use Osint.B;
with Output; use Output;
with Switch; use Switch;
with Switch.B; use Switch.B;
with Targparm; use Targparm;
with Types; use Types;
procedure Gnatbind is
Total_Errors : Nat := 0;
Total_Warnings : Nat := 0;
Main_Lib_File : File_Name_Type;
Std_Lib_File : File_Name_Type;
Text : Text_Buffer_Ptr;
Id : ALI_Id;
Next_Arg : Positive;
Output_File_Name_Seen : Boolean := False;
Output_File_Name : String_Ptr := new String'("");
procedure Scan_Bind_Arg (Argv : String);
procedure Scan_Bind_Arg (Argv : String) is
begin
if Opt.Output_File_Name_Present
and then not Output_File_Name_Seen
then
Output_File_Name_Seen := True;
if Argv'Length = 0
or else (Argv'Length >= 1 and then Argv (1) = '-')
then
Fail ("output File_Name missing after -o");
else
Output_File_Name := new String'(Argv);
end if;
elsif Argv'Length >= 2 and then Argv (1) = '-' then
if Argv (2 .. Argv'Last) = "I-" then
Opt.Look_In_Primary_Dir := False;
elsif Argv (2) = 'I' then
Add_Src_Search_Dir (Argv (3 .. Argv'Last));
Add_Lib_Search_Dir (Argv (3 .. Argv'Last));
elsif Argv (2) = 'L' then
if Argv'Length >= 3 then
Opt.Bind_For_Library := True;
Opt.Ada_Init_Name :=
new String'(Argv (3 .. Argv'Last) & Opt.Ada_Init_Suffix);
Opt.Ada_Final_Name :=
new String'(Argv (3 .. Argv'Last) & Opt.Ada_Final_Suffix);
Opt.Ada_Main_Name :=
new String'(Argv (3 .. Argv'Last) & Opt.Ada_Main_Name_Suffix);
Opt.Bind_Main_Program := False;
else
Fail
("Prefix of initialization and finalization " &
"procedure names missing in -L");
end if;
elsif Argv'Length = 4
and then Argv (2) = 'S'
then
declare
C1 : Character := Argv (3);
C2 : Character := Argv (4);
begin
if C1 in 'a' .. 'z' then
C1 := Character'Val (Character'Pos (C1) - 32);
end if;
if C2 in 'a' .. 'z' then
C2 := Character'Val (Character'Pos (C2) - 32);
end if;
if C1 = 'I' and then C2 = 'N' then
Initialize_Scalars_Mode := 'I';
elsif C1 = 'L' and then C2 = 'O' then
Initialize_Scalars_Mode := 'L';
elsif C1 = 'H' and then C2 = 'I' then
Initialize_Scalars_Mode := 'H';
elsif (C1 in '0' .. '9' or else C1 in 'A' .. 'F')
and then
(C2 in '0' .. '9' or else C2 in 'A' .. 'F')
then
Initialize_Scalars_Mode := 'X';
Initialize_Scalars_Val (1) := C1;
Initialize_Scalars_Val (2) := C2;
else
Scan_Binder_Switches (Argv);
end if;
end;
elsif Argv'Length >= 3
and then Argv (2 .. 3) = "aI"
then
Add_Src_Search_Dir (Argv (4 .. Argv'Last));
elsif Argv'Length >= 3
and then Argv (2 .. 3) = "aO"
then
Add_Lib_Search_Dir (Argv (4 .. Argv'Last));
elsif Argv (2 .. Argv'Last) = "nostdlib" then
Opt.No_Stdlib := True;
elsif Argv (2 .. Argv'Last) = "nostdinc" then
Opt.No_Stdinc := True;
elsif Argv (2 .. Argv'Last) = "static" then
Opt.Shared_Libgnat := False;
elsif Argv (2 .. Argv'Last) = "shared" then
Opt.Shared_Libgnat := True;
elsif Argv'Length >= 3 and then Argv (2) = 'M' then
Opt.Bind_Alternate_Main_Name := True;
Opt.Alternate_Main_Name := new String '(Argv (3 .. Argv'Last));
else
Scan_Binder_Switches (Argv);
end if;
elsif Argv'Length /= 0 then
if Argv'Length > 4
and then Argv (Argv'Last - 3 .. Argv'Last) = ".ali"
then
Add_File (Argv);
else
Add_File (Argv & ".ali");
end if;
end if;
end Scan_Bind_Arg;
begin
declare
Shared_Libgnat_Default : Character;
pragma Import (C, Shared_Libgnat_Default, "shared_libgnat_default");
SHARED : constant Character := 'H';
STATIC : constant Character := 'T';
begin
pragma Assert
(Shared_Libgnat_Default = SHARED
or else
Shared_Libgnat_Default = STATIC);
Shared_Libgnat := (Shared_Libgnat_Default = SHARED);
end;
Next_Arg := 1;
Scan_Args : while Next_Arg < Arg_Count loop
declare
Next_Argv : String (1 .. Len_Arg (Next_Arg));
begin
Fill_Arg (Next_Argv'Address, Next_Arg);
Scan_Bind_Arg (Next_Argv);
end;
Next_Arg := Next_Arg + 1;
end loop Scan_Args;
if Opt.Output_File_Name_Present
and then not Output_File_Name_Seen
then
Fail ("output file name missing after -o");
end if;
if Usage_Requested then
Bindusg;
end if;
if Opt.Output_File_Name_Present
and then Output_File_Name_Seen
then
Check_Extensions : declare
Length : constant Natural := Output_File_Name'Length;
Last : constant Natural := Output_File_Name'Last;
begin
if Ada_Bind_File then
if Length <= 4
or else Output_File_Name (Last - 3 .. Last) /= ".adb"
then
Fail ("output file name should have .adb extension");
end if;
else
if Length <= 2
or else Output_File_Name (Last - 1 .. Last) /= ".c"
then
Fail ("output file name should have .c extension");
end if;
end if;
end Check_Extensions;
end if;
Osint.Add_Default_Search_Dirs;
if Verbose_Mode then
Namet.Initialize;
Targparm.Get_Target_Parameters;
Write_Eol;
Write_Str ("GNATBIND ");
if Targparm.High_Integrity_Mode_On_Target then
Write_Str ("Pro High Integrity ");
end if;
Write_Str (Gnat_Version_String);
Write_Str (" Copyright 1995-2002 Free Software Foundation, Inc.");
Write_Eol;
end if;
if not More_Lib_Files then
Bindusg;
Exit_Program (E_Fatal);
end if;
begin
Csets.Initialize;
Namet.Initialize;
Initialize_Binderr;
Initialize_ALI;
Initialize_ALI_Source;
if Verbose_Mode then
Write_Eol;
end if;
while More_Lib_Files loop
Main_Lib_File := Next_Main_Lib_File;
if Verbose_Mode then
if Check_Only then
Write_Str ("Checking: ");
else
Write_Str ("Binding: ");
end if;
Write_Name (Main_Lib_File);
Write_Eol;
end if;
Text := Read_Library_Info (Main_Lib_File, True);
Id := Scan_ALI
(F => Main_Lib_File,
T => Text,
Ignore_ED => Force_RM_Elaboration_Order,
Err => False);
Free (Text);
end loop;
if not No_Run_Time_Specified then
Name_Buffer (1 .. 12) := "s-stalib.ali";
Name_Len := 12;
Std_Lib_File := Name_Find;
Text := Read_Library_Info (Std_Lib_File, True);
Id :=
Scan_ALI
(F => Std_Lib_File,
T => Text,
Ignore_ED => Force_RM_Elaboration_Order,
Err => False);
Free (Text);
end if;
for Index in ALIs.First .. ALIs.Last loop
Read_ALI (Index);
end loop;
if Force_RM_Elaboration_Order then
Error_Msg
("?-f is obsolescent and should not be used");
Error_Msg
("?may result in missing run-time elaboration checks");
Error_Msg
("?use -gnatE, pragma Suppress (Elaboration_Checks) instead");
end if;
if No_Object_Specified then
raise Unrecoverable_Error;
end if;
Set_Source_Table;
if Bind_Main_Program
and then ALIs.Table (ALIs.First).Main_Program = None
and then not No_Main_Subprogram
then
Error_Msg_Name_1 := Main_Lib_File;
Error_Msg ("% does not contain a unit that can be a main program");
end if;
Check_Duplicated_Subunits;
Check_Versions;
Check_Consistency;
Check_Configuration_Consistency;
if Errors_Detected = 0 then
Find_Elab_Order;
if Errors_Detected = 0 then
if Elab_Order_Output then
Write_Eol;
Write_Str ("ELABORATION ORDER");
Write_Eol;
for J in Elab_Order.First .. Elab_Order.Last loop
Write_Str (" ");
Write_Unit_Name (Units.Table (Elab_Order.Table (J)).Uname);
Write_Eol;
end loop;
Write_Eol;
end if;
if not Check_Only then
Gen_Output_File (Output_File_Name.all);
end if;
end if;
end if;
Total_Errors := Total_Errors + Errors_Detected;
Total_Warnings := Total_Warnings + Warnings_Detected;
exception
when Unrecoverable_Error =>
Total_Errors := Total_Errors + Errors_Detected;
Total_Warnings := Total_Warnings + Warnings_Detected;
end;
Finalize_Binderr;
Namet.Finalize;
if Total_Errors > 0 then
Exit_Program (E_Errors);
elsif Total_Warnings > 0 then
Exit_Program (E_Warnings);
else
Exit_Program (E_Success);
end if;
end Gnatbind;