Remove empty rules for check_elf_files.timestamp

If we don't have any new dependencies, or we never set up the
check_elf_files.timestamp rule, don't create an empty one now.

There were >7000 of these unused and empty rules in my AOSP
aosp_cf_x86_phone build.

This was initially brought to my attention by the new checks in
https://github.com/google/kati/pull/189

Test: diff out/build-aosp_cf_x86_phone.ninja, only removed phony rules
Change-Id: Ia43cbbd04df4a01d2182b14e3ccbe5d5ecbcabad
diff --git a/core/check_elf_file.mk b/core/check_elf_file.mk
index da4168d..d54a5b7 100644
--- a/core/check_elf_file.mk
+++ b/core/check_elf_file.mk
@@ -38,6 +38,8 @@
 	    $<
 	$(hide) touch $@
 
+CHECK_ELF_FILES.$(check_elf_files_stamp) := 1
+
 ifneq ($(strip $(LOCAL_CHECK_ELF_FILES)),false)
 ifneq ($(strip $(BUILD_BROKEN_PREBUILT_ELF_FILES)),true)
 $(LOCAL_BUILT_MODULE): $(check_elf_files_stamp)
diff --git a/core/main.mk b/core/main.mk
index 465a396..68303cf 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -795,9 +795,10 @@
     $($(if $(2),$($(1)2ND_ARCH_VAR_PREFIX))TARGET_OUT_INTERMEDIATES)/SHARED_LIBRARIES/%,\
     $(call module-built-files,$(mod)))))\
   \
-  $(if $(r),\
+  $(if $(and $(r),$(deps)),\
     $(eval stamp := $(dir $(r))check_elf_files.timestamp)\
-    $(eval $(call add-elf-file-check-shared-lib,$(stamp),$(deps)))\
+    $(if $(CHECK_ELF_FILES.$(stamp)),\
+      $(eval $(call add-elf-file-check-shared-lib,$(stamp),$(deps))))\
   ))
 endef