Add phony target to check all PCF ELF prebuilts

Add phony target check-elf-prebuilt-product-copy-files that asserts
PRODUCT_COPY_FILES doesn't have ELF prebuilts.
This helps triage PCF ELF errors by providing a convenient target to
check / list all errors.

Bug: 140560012
Bug: 156534160
Test: lunch aosp_cf_x86_phone
Test: m USE_NDK_TRANSLATION_BINARY=true \
  check-elf-prebuilt-product-copy-files -k
Change-Id: Ic7fa43c10b0c30b3b1d9b7c2fae75cc6ea4a3513
diff --git a/core/Makefile b/core/Makefile
index 5f62234..23ef48d 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -40,6 +40,10 @@
 )
 endef
 
+# Phony target to check PRODUCT_COPY_FILES copy pairs don't contain ELF files
+.PHONY: check-elf-prebuilt-product-copy-files
+check-elf-prebuilt-product-copy-files:
+
 check_elf_prebuilt_product_copy_files := true
 ifneq (,$(filter true,$(BUILD_BROKEN_ELF_PREBUILT_PRODUCT_COPY_FILES)))
 check_elf_prebuilt_product_copy_files :=
diff --git a/core/definitions.mk b/core/definitions.mk
index daac652..d560644 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -2491,15 +2491,25 @@
 # $(2): destination file
 # $(3): message to print on error
 define copy-non-elf-file-checked
-$(2): $(1) $(LLVM_READOBJ)
-	@echo "Copy non-ELF: $$@"
+$(eval check_non_elf_file_timestamp := \
+    $(call intermediates-dir-for,FAKE,check-non-elf-file-timestamps)/$(2).timestamp)
+$(check_non_elf_file_timestamp): $(1) $(LLVM_READOBJ)
+	@echo "Check non-ELF: $$<"
+	$(hide) mkdir -p "$$(dir $$@)"
+	$(hide) rm -f "$$@"
 	$(hide) \
-	    if $(LLVM_READOBJ) -h $$< >/dev/null 2>&1; then \
-	        $(call echo-error,$$@,$(3)); \
-	        $(call echo-error,$$@,found ELF file: $$<); \
+	    if $(LLVM_READOBJ) -h "$$<" >/dev/null 2>&1; then \
+	        $(call echo-error,$(2),$(3)); \
+	        $(call echo-error,$(2),found ELF file: $$<); \
 	        false; \
 	    fi
+	$(hide) touch "$$@"
+
+$(2): $(1) $(check_non_elf_file_timestamp)
+	@echo "Copy non-ELF: $$@"
 	$$(copy-file-to-target)
+
+check-elf-prebuilt-product-copy-files: $(check_non_elf_file_timestamp)
 endef
 
 # The -t option to acp and the -p option to cp is