aboutsummaryrefslogtreecommitdiff
path: root/Makefile.inc1
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile.inc1')
-rw-r--r--Makefile.inc130
1 files changed, 30 insertions, 0 deletions
diff --git a/Makefile.inc1 b/Makefile.inc1
index c49bc4ce89ca..d6942f0822f2 100644
--- a/Makefile.inc1
+++ b/Makefile.inc1
@@ -2205,6 +2205,36 @@ builddtb:
###############
+# cleanworld
+# 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 file flags 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. Removing all
+# files without file flags set in the first 'rm' instance saves time,
+# because 'chflags' will need to operate on fewer files afterwards.
+#
+# 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.
+#
+BW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
+cleanworld: .PHONY
+.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
+
.if defined(TARGET) && defined(TARGET_ARCH)
.if ${TARGET} == ${MACHINE} && ${TARGET_ARCH} == ${MACHINE_ARCH}