test/make/TestCopyFiles.gmk
changeset 47751 f7e430cbfe34
parent 47334 09d386ddaa42
child 47879 3812717dc3e9
equal deleted inserted replaced
47750:0084b493dfc9 47751:f7e430cbfe34
    42 
    42 
    43 SRC_DIR := $(OUTPUT_DIR)/src
    43 SRC_DIR := $(OUTPUT_DIR)/src
    44 DEST_DIR := $(OUTPUT_DIR)/dest
    44 DEST_DIR := $(OUTPUT_DIR)/dest
    45 
    45 
    46 $(OUTPUT_DIR)/_src_created: $(DEPS)
    46 $(OUTPUT_DIR)/_src_created: $(DEPS)
       
    47 	$(RM) -r $(DEST_DIR)
    47 	$(RM) -r $(SRC_DIR)
    48 	$(RM) -r $(SRC_DIR)
    48 	$(MKDIR) -p $(SRC_DIR)
    49 	$(MKDIR) -p $(SRC_DIR)
    49 	$(MKDIR) -p $(SRC_DIR)/foo
    50 	$(MKDIR) -p $(SRC_DIR)/foo
    50 	$(TOUCH) $(SRC_DIR)/file
    51 	$(TOUCH) $(SRC_DIR)/file
    51 	$(TOUCH) $(SRC_DIR)/foo/foofile
    52 	$(TOUCH) $(SRC_DIR)/foo/foofile
    52 	$(TOUCH) "$(SRC_DIR)/foo/foo file"
    53 	$(TOUCH) "$(SRC_DIR)/foo/foo file"
    53         # Spaces in directories only works with gnu make 4.0 or later
    54         # Spaces in directories only works with gnu make 4.0 or later
    54         ifeq (4.0, $(firstword $(sort 4.0 $(MAKE_VERSION))))
    55         ifeq (4.0dfd, $(firstword $(sort 4.0 $(MAKE_VERSION))))
    55 	  $(MKDIR) -p "$(SRC_DIR)/foo bar"
    56 	  $(MKDIR) -p "$(SRC_DIR)/foo bar"
    56 	  $(TOUCH) "$(SRC_DIR)/foo bar/foobarfile"
    57 	  $(TOUCH) "$(SRC_DIR)/foo bar/foobarfile"
    57 	  $(TOUCH) "$(SRC_DIR)/foo bar/foo bar file"
    58 	  $(TOUCH) "$(SRC_DIR)/foo bar/foo bar file"
    58         endif
    59         endif
    59 	$(LN) -s file "$(SRC_DIR)/link to file"
    60 	$(LN) -s file "$(SRC_DIR)/link to file"
    63     SRC := $(SRC_DIR), \
    64     SRC := $(SRC_DIR), \
    64     DEST := $(DEST_DIR), \
    65     DEST := $(DEST_DIR), \
    65     FILES := $(call CacheFind, $(SRC_DIR)), \
    66     FILES := $(call CacheFind, $(SRC_DIR)), \
    66 ))
    67 ))
    67 
    68 
       
    69 # Optionally define a rule that deletes all the target files after the makefile
       
    70 # has been parsed. GNU make has specific problems with this in combination with
       
    71 # spaces in directory names.
       
    72 ifeq ($(DELETE_FIRST), true)
       
    73   delete-targets:
       
    74 	$(RM) -r $(DEST_DIR)
       
    75 	$(ECHO) '$(DEST_DIR)/foo' '$(wildcard $(DEST_DIR)/foo)'
       
    76 
       
    77   $(COPY_1): delete-targets
       
    78 endif
       
    79 
    68 do-copy1: $(COPY_1)
    80 do-copy1: $(COPY_1)
    69 
    81 
    70 run-test1: $(OUTPUT_DIR)/_src_created
    82 run-test1: $(OUTPUT_DIR)/_src_created
       
    83 	$(ECHO) "Copy 1 first time"
    71 	+$(MAKE) -f $(THIS_FILE) do-copy1
    84 	+$(MAKE) -f $(THIS_FILE) do-copy1
       
    85 	$(DIFF) -r $(SRC_DIR) $(DEST_DIR)
       
    86         # Rerun the copy a second time, with the targets present at make parse
       
    87         # time, but then deleted by a prerequisite rule.
       
    88 	$(ECHO) "Copy 1 second time"
       
    89 	+$(MAKE) -f $(THIS_FILE) do-copy1 DELETE_FIRST=true
    72 	$(DIFF) -r $(SRC_DIR) $(DEST_DIR)
    90 	$(DIFF) -r $(SRC_DIR) $(DEST_DIR)
    73 
    91 
    74 TEST_TARGETS += run-test1
    92 TEST_TARGETS += run-test1
    75 
    93 
    76 .PHONY: do-copy1 run-test1
    94 .PHONY: do-copy1 run-test1 delete-targets
    77 
    95 
    78 ################################################################################
    96 ################################################################################
    79 
    97 
    80 all: $(TEST_TARGETS)
    98 all: $(TEST_TARGETS)