+ declare
+ Current_Dir : constant String := Get_Current_Dir;
+ Dir : Dir_Type;
+
+ Name : String (1 .. 200);
+ Last : Natural;
+
+ Disregard : Boolean;
+ pragma Warnings (Off, Disregard);
+
+ DLL_Name : aliased constant String :=
+ Lib_Filename.all & "." & DLL_Ext;
+
+ Archive_Name : aliased constant String :=
+ Lib_Filename.all & "." & Archive_Ext;
+
+ Delete : Boolean := False;
+
+ begin
+ -- Clean the library directory: remove any file with the name of
+ -- the library file and any ALI file of a source of the project.
+
+ begin
+ Get_Name_String (For_Project.Library_Dir.Display_Name);
+ Change_Dir (Name_Buffer (1 .. Name_Len));
+
+ exception
+ when others =>
+ Com.Fail
+ ("unable to access library directory """
+ & Name_Buffer (1 .. Name_Len)
+ & """");
+ end;
+
+ Open (Dir, ".");
+
+ loop
+ Read (Dir, Name, Last);
+ exit when Last = 0;
+
+ declare
+ Filename : constant String := Name (1 .. Last);
+
+ begin
+ if Is_Regular_File (Filename) then
+ Canonical_Case_File_Name (Name (1 .. Last));
+ Delete := False;
+
+ if (The_Build_Mode = Static
+ and then Name (1 .. Last) = Archive_Name)
+ or else
+ ((The_Build_Mode = Dynamic
+ or else
+ The_Build_Mode = Relocatable)
+ and then Name (1 .. Last) = DLL_Name)
+ then
+ Delete := True;
+
+ elsif Last > 4
+ and then Name (Last - 3 .. Last) = ".ali"
+ then
+ declare
+ Unit : Unit_Index;
+
+ begin
+ -- Compare with ALI file names of the project
+
+ Unit := Units_Htable.Get_First (In_Tree.Units_HT);
+ while Unit /= No_Unit_Index loop
+ if Unit.File_Names (Impl) /= null
+ and then Unit.File_Names (Impl).Project /=
+ No_Project
+ then
+ if Ultimate_Extending_Project_Of
+ (Unit.File_Names (Impl).Project) =
+ For_Project
+ then
+ Get_Name_String
+ (Unit.File_Names (Impl).File);
+ Name_Len :=
+ Name_Len -
+ File_Extension
+ (Name (1 .. Name_Len))'Length;
+
+ if Name_Buffer (1 .. Name_Len) =
+ Name (1 .. Last - 4)
+ then
+ Delete := True;
+ exit;
+ end if;
+ end if;
+
+ elsif Unit.File_Names (Spec) /= null
+ and then Ultimate_Extending_Project_Of
+ (Unit.File_Names (Spec).Project) =
+ For_Project
+ then
+ Get_Name_String (Unit.File_Names (Spec).File);
+ Name_Len :=
+ Name_Len -
+ File_Extension (Name (1 .. Last))'Length;
+
+ if Name_Buffer (1 .. Name_Len) =
+ Name (1 .. Last - 4)
+ then
+ Delete := True;
+ exit;
+ end if;
+ end if;
+
+ Unit := Units_Htable.Get_Next (In_Tree.Units_HT);
+ end loop;
+ end;
+ end if;
+
+ if Delete then
+ Set_Writable (Filename);
+ Delete_File (Filename, Disregard);
+ end if;
+ end if;
+ end;
+ end loop;