[BACK]Return to bsd.clean.mk CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / share / mk

File: [cvs.NetBSD.org] / src / share / mk / bsd.clean.mk (download)

Revision 1.8, Mon Nov 19 16:04:54 2012 UTC (11 years, 5 months ago) by apb
Branch: MAIN
CVS Tags: yamt-pagecache-base9, yamt-pagecache-base8, yamt-pagecache-base7, tls-maxphys-base, tls-earlyentropy-base, tls-earlyentropy, riastradh-xf86-video-intel-2-7-1-pre-2-21-15, riastradh-drm2-base3, riastradh-drm2-base2, riastradh-drm2-base1, riastradh-drm2-base, riastradh-drm2, prg-localcount2-base3, prg-localcount2-base2, prg-localcount2-base1, prg-localcount2-base, prg-localcount2, phil-wifi-base, phil-wifi-20200421, phil-wifi-20200411, phil-wifi-20200406, phil-wifi-20191119, phil-wifi-20190609, phil-wifi, pgoyette-localcount-base, pgoyette-localcount-20170426, pgoyette-localcount-20170320, pgoyette-localcount-20170107, pgoyette-localcount-20161104, pgoyette-localcount-20160806, pgoyette-localcount-20160726, pgoyette-localcount, pgoyette-compat-merge-20190127, pgoyette-compat-base, pgoyette-compat-20190127, pgoyette-compat-20190118, pgoyette-compat-1226, pgoyette-compat-1126, pgoyette-compat-1020, pgoyette-compat-0930, pgoyette-compat-0906, pgoyette-compat-0728, pgoyette-compat-0625, pgoyette-compat-0521, pgoyette-compat-0502, pgoyette-compat-0422, pgoyette-compat-0415, pgoyette-compat-0407, pgoyette-compat-0330, pgoyette-compat-0322, pgoyette-compat-0315, pgoyette-compat, perseant-stdc-iso10646-base, perseant-stdc-iso10646, netbsd-9-base, netbsd-9-3-RELEASE, netbsd-9-2-RELEASE, netbsd-9-1-RELEASE, netbsd-9-0-RELEASE, netbsd-9-0-RC2, netbsd-9-0-RC1, netbsd-9, netbsd-8-base, netbsd-8-2-RELEASE, netbsd-8-1-RELEASE, netbsd-8-1-RC1, netbsd-8-0-RELEASE, netbsd-8-0-RC2, netbsd-8-0-RC1, netbsd-8, netbsd-7-nhusb-base-20170116, netbsd-7-nhusb-base, netbsd-7-nhusb, netbsd-7-base, netbsd-7-2-RELEASE, netbsd-7-1-RELEASE, netbsd-7-1-RC2, netbsd-7-1-RC1, netbsd-7-1-2-RELEASE, netbsd-7-1-1-RELEASE, netbsd-7-1, netbsd-7-0-RELEASE, netbsd-7-0-RC3, netbsd-7-0-RC2, netbsd-7-0-RC1, netbsd-7-0-2-RELEASE, netbsd-7-0-1-RELEASE, netbsd-7-0, netbsd-7, matt-nb8-mediatek-base, matt-nb8-mediatek, localcount-20160914, is-mlppp-base, is-mlppp, cjep_sun2x-base1, cjep_sun2x-base, cjep_sun2x, cjep_staticlib_x-base1, cjep_staticlib_x-base, cjep_staticlib_x, bouyer-socketcan-base1, bouyer-socketcan-base, bouyer-socketcan, agc-symver-base, agc-symver
Changes since 1.7: +9 -3 lines

On second thoughts, don't run "rm -rf" in bsd.clean.mk.  Instead,
document that CLEANFILES and CLEANDIRFILES must not contain
directory names.

# $NetBSD: bsd.clean.mk,v 1.8 2012/11/19 16:04:54 apb Exp $

# <bsd.clean.mk>
#
# Public targets:
#
# clean:	Delete files listed in ${CLEANFILES}.
# cleandir:	Delete files listed in ${CLEANFILES} and ${CLEANDIRFILES}.
#
# Public variables:
#
# CLEANFILES	Files to remove for both the clean and cleandir targets.
#
# CLEANDIRFILES	Files to remove for the cleandir target, but not for
#		the clean target.
#
# MKCLEANSRC	Whether or not to clean the source directory
# 		in addition to the object directory.  Defaults to "yes".
#
# MKCLEANVERIFY	Whether or not to verify that the file deletion worked.
#		Defaults to "yes".
#
# The files listed in CLEANFILES and CLEANDIRFILES must not be
# directories, because the potential risk from running "rm -rf" commands
# in bsd.clean.mk is considered too great.  If you want to recursively
# delete a directory as part of "make clean" or "make cleandir" then you
# need to provide your own target.

.if !defined(_BSD_CLEAN_MK_)
_BSD_CLEAN_MK_=1

.include <bsd.init.mk>

MKCLEANSRC?=	yes
MKCLEANVERIFY?=	yes

clean:		.PHONY __doclean
__doclean:	.PHONY .MADE __cleanuse CLEANFILES
cleandir:	.PHONY clean __docleandir
__docleandir:	.PHONY .MADE __cleanuse CLEANDIRFILES

# __cleanuse is invoked with ${.ALLSRC} as the name of a variable
# (such as CLEANFILES or CLEANDIRFILES), or possibly a list of
# variable names.  ${.ALLSRC:@v@${${v}}@} will be the list of
# files to delete.  (We pass the variable name, e.g. CLEANFILES,
# instead of the file names, e.g. ${CLEANFILES}, because we don't
# want make to replace any of the file names with the result of
# searching .PATH.)
#
# If the list of files is empty, then the commands
# reduce to "true", with an "@" prefix to prevent echoing.
#
# The use of :M* is needed to handle the case that CLEANFILES
# or CLEANDIRFILES is not completely empty but contains spaces.
# This can easily happen when CLEANFILES or CLEANDIRFILES is set
# from other variables that happen to be empty.)
#
# The use of :Q is needed to handle the case that CLEANFILES
# or CLEANDIRFILES contains quoted strings, such as
# CLEANFILES = "filename with spaces".
#
__cleanuse: .USE
.if 0	# print "# clean CLEANFILES" for debugging
	${"${.ALLSRC:@v@${${v}:M*}@:Q}" == "":?@true:${_MKMSG} \
		"clean" ${.ALLSRC} }
.endif
.for _d in ${"${.OBJDIR}" == "${.CURDIR}" || "${MKCLEANSRC}" == "no" \
		:? ${.OBJDIR} \
		:  ${.OBJDIR} ${.CURDIR} }
	${"${.ALLSRC:@v@${${v}:M*}@:Q}" == "":?@true: \
	    (cd ${_d} && rm -f ${.ALLSRC:@v@${${v}}@} || true) }
.if "${MKCLEANVERIFY}" == "yes"
	@${"${.ALLSRC:@v@${${v}:M*}@:Q}" == "":?true: \
	    bad="\$(cd ${_d} && ls -1d ${.ALLSRC:@v@${${v}}@} 2>/dev/null)"; \
	    if test -n "\$bad"; then \
	        echo "Failed to remove the following files from ${_d}:" ; \
	        echo "\$bad" | while read file ; do \
		    echo "	\$file" ; \
		done ; \
	        false ; \
	    fi }
.endif
.endfor

# Don't automatically load ".depend" files during "make clean"
# or "make cleandir".
.if make(clean) || make(cleandir)
.MAKE.DEPENDFILE := .depend.no-such-file
.endif

.endif	# !defined(_BSD_CLEAN_MK)