summaryrefslogtreecommitdiff
path: root/mk
diff options
context:
space:
mode:
authorIan Lynagh <igloo@earth.li>2011-11-19 01:29:05 +0000
committerIan Lynagh <igloo@earth.li>2011-11-19 01:52:32 +0000
commit80e9070c77718b7ff0e913182e54842754726ce8 (patch)
tree12804916372a3675a7d1beb00bd41e70083c5edf /mk
parent042841713eb6468696eeb437de994c52eb7a858e (diff)
downloadhaskell-80e9070c77718b7ff0e913182e54842754726ce8.tar.gz
Improve the way we call "rm" in the build system; fixes trac #4916
We avoid calling "rm -rf" with no file arguments; this fixes cleaning on Solaris, where that fails. We also check for suspicious arguments: anything containing "..", starting "/", or containing a "*" (you need to call $(wildcard ...) yourself now if you really want globbing). This should make things a little safer.
Diffstat (limited to '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\
+ )))\
+ )
+