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