diff --git a/arch/arm/crypto/Makefile b/arch/arm/crypto/Makefile
index bd5bceef0605f1c22d158bdca6b875a4b58311c0..89f88abba698d548957fea7d8151fe9990732452 100644
--- a/arch/arm/crypto/Makefile
+++ b/arch/arm/crypto/Makefile
@@ -65,4 +65,4 @@ $(src)/sha512-core.S_shipped: $(src)/sha512-armv4.pl
 	$(call cmd,perl)
 endif
 
-targets += sha256-core.S sha512-core.S
+clean-files += sha256-core.S sha512-core.S
diff --git a/arch/arm64/crypto/Makefile b/arch/arm64/crypto/Makefile
index f476fede09ba489463b9d1fb5e19b7345d100e0e..860d9312ccf986498d4d02b2c517de96873d1c12 100644
--- a/arch/arm64/crypto/Makefile
+++ b/arch/arm64/crypto/Makefile
@@ -75,4 +75,4 @@ $(src)/sha512-core.S_shipped: $(src)/sha512-armv8.pl
 	$(call cmd,perlasm)
 endif
 
-targets += sha256-core.S sha512-core.S
+clean-files += sha256-core.S sha512-core.S
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index 87e188609ef7a295bd4eee8e774635798d0f1a8b..4f138620865bee5fa3d49541a01b528d0f2d093c 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -358,3 +358,6 @@ endef
 
 # delete partially updated (i.e. corrupted) files on error
 .DELETE_ON_ERROR:
+
+# do not delete intermediate files automatically
+.SECONDARY:
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index ed9b6467ebde2f26d47dec2546e33f6123f2e006..aa05423c8418a52044570be6bfb10c978cc76941 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -529,8 +529,4 @@ $(shell mkdir -p $(obj-dirs))
 endif
 endif
 
-# Some files contained in $(targets) are intermediate artifacts.
-# We never want them to be removed automatically.
-.SECONDARY: $(targets)
-
 .PHONY: $(PHONY)