Calling the Rule-Generating Macro
Now let’s put our handiwork to the test. We create the local cache file rules using a pair of foreach loops that call our newly defined function, one for each unique source location (and file list). We’ve broken the loops for readability, but they are actually single-line statements in the Make file:
$(foreach p,$(srcfiles_override),\
$(eval $(call single_prereq_rule,\
$(CACHEDIR),$(p),$(OVERRIDE_PATH))))
$(foreach p,$(srcfiles_default),\
$(eval $(call single_prereq_rule,\
$(CACHEDIR),$(p),$(DEFAULT_PATH))))
$(CACHEDIR):
mkdir -p $@
Voila! We now have a a working set of Make rules (definitions,
recipes, etc) that will cache a list of prerequisites that come from
multiple locations. Files that appear in the OVERRIDE
source directory are copied from there to the local cache, and files that appear only in the DEFAULT
source directory are copied from there. Here’s what the command line output looks like:
$ make -f cached_multi_loc_prereq.mk all_cache
mkdir -p build/cache
cp srcloc_override/override_fileG.tcl build/cache/override_fileG.tcl
cp srcloc_override/bothloc_fileB.tcl build/cache/bothloc_fileB.tcl
cp srcloc_override/bothloc_fileE.tcl build/cache/bothloc_fileE.tcl
cp srcloc_override/override_fileF.tcl build/cache/override_fileF.tcl
cp srcloc_default/default_fileC.tcl build/cache/default_fileC.tcl
cp srcloc_default/default_fileA.tcl build/cache/default_fileA.tcl
cp srcloc_default/default_fileD.tcl build/cache/default_fileD.tcl
Executing recipe for all_cache...
(First time run, should see copy commands for prerequisites)
The adventurous reader might explore a clever way to further reduce the two loops to a single loop or function call. We hope you enjoy using Make to its full potential! For further reading:
- More articles on specific uses of Make appear on our Resources page.
- Also on our Resources page are white papers on Make and creating a Physical Design Framework.
- Example make files can be downloaded from the sidebar to the right.
- Please contact us with questions, comments, or tips.
- Find out how we can help you upgrade, develop, replace, or assess your physical design framework through our home page.
Thanks for reading!