test/make/TestCopyFiles.gmk
changeset 47751 f7e430cbfe34
parent 47334 09d386ddaa42
child 47879 3812717dc3e9
--- a/test/make/TestCopyFiles.gmk	Wed Nov 15 23:25:40 2017 +0530
+++ b/test/make/TestCopyFiles.gmk	Wed Nov 15 11:50:55 2017 -0800
@@ -44,6 +44,7 @@
 DEST_DIR := $(OUTPUT_DIR)/dest
 
 $(OUTPUT_DIR)/_src_created: $(DEPS)
+	$(RM) -r $(DEST_DIR)
 	$(RM) -r $(SRC_DIR)
 	$(MKDIR) -p $(SRC_DIR)
 	$(MKDIR) -p $(SRC_DIR)/foo
@@ -51,7 +52,7 @@
 	$(TOUCH) $(SRC_DIR)/foo/foofile
 	$(TOUCH) "$(SRC_DIR)/foo/foo file"
         # Spaces in directories only works with gnu make 4.0 or later
-        ifeq (4.0, $(firstword $(sort 4.0 $(MAKE_VERSION))))
+        ifeq (4.0dfd, $(firstword $(sort 4.0 $(MAKE_VERSION))))
 	  $(MKDIR) -p "$(SRC_DIR)/foo bar"
 	  $(TOUCH) "$(SRC_DIR)/foo bar/foobarfile"
 	  $(TOUCH) "$(SRC_DIR)/foo bar/foo bar file"
@@ -65,15 +66,32 @@
     FILES := $(call CacheFind, $(SRC_DIR)), \
 ))
 
+# Optionally define a rule that deletes all the target files after the makefile
+# has been parsed. GNU make has specific problems with this in combination with
+# spaces in directory names.
+ifeq ($(DELETE_FIRST), true)
+  delete-targets:
+	$(RM) -r $(DEST_DIR)
+	$(ECHO) '$(DEST_DIR)/foo' '$(wildcard $(DEST_DIR)/foo)'
+
+  $(COPY_1): delete-targets
+endif
+
 do-copy1: $(COPY_1)
 
 run-test1: $(OUTPUT_DIR)/_src_created
+	$(ECHO) "Copy 1 first time"
 	+$(MAKE) -f $(THIS_FILE) do-copy1
 	$(DIFF) -r $(SRC_DIR) $(DEST_DIR)
+        # Rerun the copy a second time, with the targets present at make parse
+        # time, but then deleted by a prerequisite rule.
+	$(ECHO) "Copy 1 second time"
+	+$(MAKE) -f $(THIS_FILE) do-copy1 DELETE_FIRST=true
+	$(DIFF) -r $(SRC_DIR) $(DEST_DIR)
 
 TEST_TARGETS += run-test1
 
-.PHONY: do-copy1 run-test1
+.PHONY: do-copy1 run-test1 delete-targets
 
 ################################################################################