1# $NetBSD: bsd.clean.mk,v 1.4 2011/10/05 12:34:04 apb Exp $ 2 3# <bsd.clean.mk> 4# 5# Public targets: 6# 7# clean: Delete files listed in ${CLEANFILES}. 8# cleandir: Delete files listed in ${CLEANFILES} and ${CLEANDIRFILES}. 9# 10# Public variables: 11# 12# CLEANFILES Files to remove for both the clean and cleandir targets. 13# 14# CLEANDIRFILES Files to remove for the cleandir target, but not for 15# the clean target. 16# 17# MKCLEANSRC Whether or not to clean the source directory 18# in addition to the object directory. 19# 20# MKCLEANVERIFY Whether or not to verify that the file deletion worked. 21# 22 23.if !defined(_BSD_CLEAN_MK_) 24_BSD_CLEAN_MK_=1 25 26.include <bsd.init.mk> 27 28MKCLEANSRC?= yes 29MKCLEANVERIFY?= yes 30 31clean: .PHONY __doclean 32__doclean: .PHONY .MADE __cleanuse CLEANFILES 33cleandir: .PHONY clean __docleandir 34__docleandir: .PHONY .MADE __cleanuse CLEANDIRFILES 35 36# __cleanuse is invoked with ${.ALLSRC} as the name of a variable 37# (such as CLEANFILES or CLEANDIRFILES), or possibly a list of 38# variable names. ${.ALLSRC:@v@${${v}}@} will be the list of 39# files to delete. (We pass the variable name, e.g. CLEANFILES, 40# instead of the file names, e.g. ${CLEANFILES}, because we don't 41# want make to replace any of the file names with the result of 42# searching .PATH.) 43# 44# If the list of files is empty, then the commands 45# reduce to "true", with an "@" prefix to prevent echoing. 46# 47# The use of :M* is needed to handle the case that CLEANFILES 48# or CLEANDIRFILES is not completely empty but contains spaces. 49# This can easily happen when CLEANFILES or CLEANDIRFILES is set 50# from other variables that happen to be empty.) 51# 52# The use of :Q is needed to handle the case that CLEANFILES 53# or CLEANDIRFILES contains quoted strings, such as 54# CLEANFILES = "filename with spaces". 55# 56__cleanuse: .USE 57.if 0 # print "# clean CLEANFILES" for debugging 58 ${"${.ALLSRC:@v@${${v}:M*}@:Q}" == "":?@true:${_MKMSG} \ 59 "clean" ${.ALLSRC} } 60.endif 61.for _d in ${"${.OBJDIR}" == "${.CURDIR}" || "${MKCLEANSRC}" == "no" \ 62 :? ${.OBJDIR} \ 63 : ${.OBJDIR} ${.CURDIR} } 64 ${"${.ALLSRC:@v@${${v}:M*}@:Q}" == "":?@true: \ 65 (cd ${_d} && rm -f ${.ALLSRC:@v@${${v}}@} || true) } 66.if "${MKCLEANVERIFY}" == "yes" 67 @${"${.ALLSRC:@v@${${v}:M*}@:Q}" == "":?true: \ 68 bad="\$(cd ${_d} && ls -d ${.ALLSRC:@v@${${v}}@} 2>/dev/null)"; \ 69 if test -n "\$bad"; then \ 70 echo "Failed to remove files from ${_d}:" ; \ 71 echo "\$bad" ; \ 72 false ; \ 73 fi } 74.endif 75.endfor 76 77# Don't automatically load ".depend" files during "make clean" 78# or "make cleandir". 79.if make(clean) || make(cleandir) 80.MAKE.DEPENDFILE := .depend.no-such-file 81.endif 82 83.endif # !defined(_BSD_CLEAN_MK) 84