summaryrefslogtreecommitdiff
path: root/mk/tree.mk
diff options
context:
space:
mode:
Diffstat (limited to 'mk/tree.mk')
-rw-r--r--mk/tree.mk21
1 files changed, 21 insertions, 0 deletions
diff --git a/mk/tree.mk b/mk/tree.mk
index 2010c362f3..564e55353c 100644
--- a/mk/tree.mk
+++ b/mk/tree.mk
@@ -74,3 +74,24 @@ RM_OPTS = -f
RM_OPTS_REC = -rf
endif
+# If $1 is empty then we don't do anything (as "rm -rf" fails on
+# Solaris; trac #4916).
+# If $1 contains a * then we fail; globbing needs to be done at the call
+# site using $(wildcard ...). This makes it a little safer, as it's
+# harder to accidentally delete something you didn't mean to.
+# Similarly, we fail if any argument contains ".." or starts with a "/".
+
+removeFiles = $(call removeHelper,removeFiles,"$(RM)",$(RM_OPTS),$1)
+removeTrees = $(call removeHelper,removeTrees,"$(RM)",$(RM_OPTS_REC),$1)
+
+removeHelper = $(if $(strip $4),\
+ $(if $(findstring *,$4),\
+ $(error $1: Got a star: $4),\
+ $(if $(findstring ..,$4),\
+ $(error $1: Got dot-dot: $4),\
+ $(if $(filter /%,$4),\
+ $(error $1: Got leading slash: $4),\
+ $2 $3 $4\
+ )))\
+ )
+