with Activity;
with Compilation;
with Debug_Tools;
with Io;  
with Library;
with Links;
with Log;
with Profile;

procedure Install (Commands : String := "!machine.release.current.commands";
                   The_Activity : String := Activity.The_Current_Activity;
                   Subsystem : String := "!Tools.Kermit") is

    Spec : constant String := "Rev2_4_Spec";
    Load : constant String := "Code2_4_0";

    Both : constant String := Subsystem & ".[" & Spec & "," & Load & "]";
    Success : Boolean := True;
begin
    Log.Put_Line ("Install " & Both, Profile.Auxiliary_Msg);
    Log.Put_Line ("Compilation.Make", Profile.Auxiliary_Msg);
    begin
        Compilation.Make (Both & ".Units",
                          Response => "~:::,~---, RAISE_ERROR, <PROFILE>");
    exception
        when others =>
            Log.Put_Line ("Compilation.Make failed (" &
                          Debug_Tools.Get_Exception_Name & ").",
                          Profile.Exception_Msg);
            Success := False;
    end;
    Log.Put_Line ("Activity.Add", Profile.Auxiliary_Msg);
    begin
        Activity.Remove (Subsystem => Subsystem, The_Activity => The_Activity);
    exception
        when others =>
            null;
    end;
    begin
        Activity.Add (Subsystem => Subsystem,
                      Spec_Value => Spec,
                      Load_Value => Load,
                      The_Activity => The_Activity,
                      Response => "<RAISE_EXCEPTION>");
    exception
        when others =>
            Log.Put_Line ("Activity.Add failed (" &
                          Debug_Tools.Get_Exception_Name & ").",
                          Profile.Exception_Msg);
            Success := False;
    end;
    Activity.Display (Subsystem => Subsystem, The_Activity => The_Activity);
    Io.New_Line;
    Log.Put_Line ("Links.Add", Profile.Auxiliary_Msg);
    begin
        Links.Delete ("[Kermit,Kermit_Defs]", World => Commands);
    exception
        when others =>
            null;
    end;
    begin
        Links.Add (Source => Subsystem & "." & Spec & "`[Kermit,Kermit_Defs]",
                   World => Commands,
                   Response => "<RAISE_EXCEPTION>");
    exception
        when others =>
            Log.Put_Line ("Links.Add failed (" &
                          Debug_Tools.Get_Exception_Name & ").",
                          Profile.Exception_Msg);
            Success := False;
    end;
    Links.Display (Source => Subsystem & "." & Spec & "?", World => Commands);
    if Success then
        begin
            Library.Freeze (Both,
                            Response => "~---,~+++, PERSEVERE, <PROFILE>");
        exception
            when others =>
                null;
        end;
        Log.Put_Line (Both & " installed.", Profile.Positive_Msg);
        Log.Put_Line ("See \Kermit$Documentation to learn about Kermit.");
    else
        Log.Put_Line ("Kermit is not completely installed.",
                      Profile.Negative_Msg);
        if Profile.Propagate then
            raise Profile.Error;
        end if;
    end if;
end Install;