aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorGarance A Drosehn <gad@FreeBSD.org>2004-02-19 21:09:58 +0000
committerGarance A Drosehn <gad@FreeBSD.org>2004-02-19 21:09:58 +0000
commit1a974787f9206849bf695431f5b3e340c0387685 (patch)
treedf98d31b31e7c8d093102c2a60b60548e30ef6da /Makefile
parent57f22bd4afcdf114d36431cf485a0a73c2c2d79f (diff)
downloadsrc-1a974787f9206849bf695431f5b3e340c0387685.tar.gz
src-1a974787f9206849bf695431f5b3e340c0387685.zip
Improvements on the 'make realclean' target. Some are style improvements,
but the biggest issue is that there are situatons when ${.OBJDIR} == ${.SRCDIR}, and in those situations the previous version would happily remove all your /usr/src while it was cleaning out the objects. Not that *you* would be happy about it... Thanks to bde for immediately noticing this serious possibility. More improvements will be made to this target, but I wanted to commit this safer version right now, before anyone lost their /usr/src due to it. Reviewed by: bde MFC after: 10 days
Notes
Notes: svn path=/head/; revision=126024
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile41
1 files changed, 28 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index 487535c59301..e3de2fa62ebd 100644
--- a/Makefile
+++ b/Makefile
@@ -104,19 +104,34 @@ buildworld: upgrade_checks
.endif
#
-# This 'realclean' target is not included in TGTS, because it is not
-# a recursive target. All of the work for it is done right here.
-# The first 'rm' will usually remove all files and directories. If
-# it does not, then there are probably some files with chflags set.
-# Unset all special chflags, and try the 'rm' a second time.
-realclean :
- -rm -Rf ${.OBJDIR}/* 2>/dev/null
- @-if [ "`echo ${.OBJDIR}/*`" != "${.OBJDIR}/*" ] ; then \
- echo "chflags -R 0 ${.OBJDIR}/*" ; \
- chflags -R 0 ${.OBJDIR}/* ; \
- echo "rm -Rf ${.OBJDIR}/*" ; \
- rm -Rf ${.OBJDIR}/* ; \
- fi
+# This 'realclean' target is not included in TGTS, because it is not a
+# recursive target. All of the work for it is done right here. It is
+# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
+# created by bsd.obj.mk, except that we don't want to .include that file
+# in this makefile.
+#
+# In the following, the first 'rm' in a series will usually remove all
+# files and directories. If it does not, then there are probably some
+# files with chflags set, so this unsets them and tries the 'rm' a
+# second time. There are situations where this target will be cleaning
+# some directories via more than one method, but that duplication is
+# needed to correctly handle all the possible situations.
+#
+BW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
+realclean:
+.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
+.if exists(${BW_CANONICALOBJDIR}/)
+ -rm -rf ${BW_CANONICALOBJDIR}/*
+ chflags -R 0 ${BW_CANONICALOBJDIR}
+ rm -rf ${BW_CANONICALOBJDIR}/*
+.endif
+ # To be safe in this case, fall back to a 'make cleandir'
+ @cd ${.CURDIR}; ${_MAKE} cleandir
+.else
+ -rm -rf ${.OBJDIR}/*
+ chflags -R 0 ${.OBJDIR}
+ rm -rf ${.OBJDIR}/*
+.endif
#
# Handle the user-driven targets, using the source relative mk files.