X-Git-Url: https://mattmccutchen.net/mgear/mgear.git/blobdiff_plain/ba4686f9228c319539806b173ea150a5f7c81487..59ba5775171ada02731636b6ec3877f493085153:/mgear.mk diff --git a/mgear.mk b/mgear.mk index 22465ce..d456fd5 100644 --- a/mgear.mk +++ b/mgear.mk @@ -272,6 +272,30 @@ mg-maybe-move-target={ cmp -s $@ $@.tmp || { echo >$@.g && mv -f $@.tmp $@; }; } mg-define-prereq=$(eval $1: $2) +# CLEAN + +# A command that finds all genfiles in a given directory and deletes them and +# the corresponding generated files. If a file is overridden, only the genfile +# is deleted. +# +# Example: +# +# clean: +# $(call mg-clean-cmd,.) +# .PHONY: clean + +define mg-clean-cmd + @exec 3>&1 &&\ + find $1 -name '*.g' | while read gf; do\ + f="$${gf%.g}" &&\ + if ! [ "$$f" -nt "$$gf" ]; then\ + echo "rm -f '$$f'" >&3 && echo "$$f";\ + fi &&\ + echo "$$gf";\ + done | xargs rm -f +endef + + # DEPENDENCY-LOGGING COMMANDS mg-dlc-static-run-oid:=$(mg-genfile-oid)