Local Cache for Prerequisites
The difficulty arises when we’d like to copy the prerequisites to a local cache directory which is used for actual target prerequisites. We might do this to enable local experimental edits to otherwise “released” input files. One option is to segregate the files from each other in the local cache location. Some policy would have to be devised to name subdirectories in the cache with some unique component from, or related to, the source locations. However, if we’d like to decouple the knowledge of the source location policy from the dependent use, we’d put all the prerequisites in a single directory in the local cache. This is where our Makefile gets tricky. We’re headed toward a pattern rule, but there is a snag. The first step, capturing the list of local cache files to be used as prerequisites, is similar to the previous in-place example:
cache_prereqs = $(addprefix $(CACHE_PATH)/,\
$(srcfiles_default) $(srcfiles_override))
However, the copy into the cache directory from multiple source locations is not so easy:
$(CACHE_PATH)/%.tcl: $(DEFAULT_PATH)/%.tcl
cp $< $@
$(CACHE_PATH)/%.tcl: $(OVERRIDE_PATH)/%.tcl
cp $< $@
Make will politely inform you that the first rule is being ignored
and overridden with the second one. What substitution can you perform
that assigns the correct source path to each cache file prerequisite?
Answer: none. We don’t have enough information. One option is to use a
GMSL map to store the file-by-file source location. Alternatively, we
can use Make’s $(foreach ...)
function to create a rule for each prerequisite separately: