Home | History | Annotate | Line # | Download | only in mk
bsd.clean.mk revision 1.6
      1  1.6  apb # $NetBSD: bsd.clean.mk,v 1.6 2012/11/18 19:52:40 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.5  apb # The use of :M* is needed to handle the case that CLEANFILES
     48  1.5  apb # or CLEANDIRFILES is not completely empty but contains spaces.
     49  1.5  apb # This can easily happen when CLEANFILES or CLEANDIRFILES is set
     50  1.5  apb # from other variables that happen to be empty.)
     51  1.5  apb #
     52  1.5  apb # The use of :Q is needed to handle the case that CLEANFILES
     53  1.5  apb # or CLEANDIRFILES contains quoted strings, such as
     54  1.5  apb # CLEANFILES = "filename with spaces".
     55  1.5  apb #
     56  1.1  apb __cleanuse: .USE
     57  1.3  apb .if 0	# print "# clean CLEANFILES" for debugging
     58  1.5  apb 	${"${.ALLSRC:@v@${${v}:M*}@:Q}" == "":?@true:${_MKMSG} \
     59  1.1  apb 		"clean" ${.ALLSRC} }
     60  1.3  apb .endif
     61  1.4  apb .for _d in ${"${.OBJDIR}" == "${.CURDIR}" || "${MKCLEANSRC}" == "no" \
     62  1.1  apb 		:? ${.OBJDIR} \
     63  1.1  apb 		:  ${.OBJDIR} ${.CURDIR} }
     64  1.5  apb 	${"${.ALLSRC:@v@${${v}:M*}@:Q}" == "":?@true: \
     65  1.3  apb 	    (cd ${_d} && rm -f ${.ALLSRC:@v@${${v}}@} || true) }
     66  1.4  apb .if "${MKCLEANVERIFY}" == "yes"
     67  1.5  apb 	@${"${.ALLSRC:@v@${${v}:M*}@:Q}" == "":?true: \
     68  1.6  apb 	    bad="\$(cd ${_d} && ls -1d ${.ALLSRC:@v@${${v}}@} 2>/dev/null)"; \
     69  1.1  apb 	    if test -n "\$bad"; then \
     70  1.6  apb 	        echo "Failed to remove the following files from ${_d}:" ; \
     71  1.6  apb 	        echo "\$bad" | while read file ; do \
     72  1.6  apb 		    echo "	\$file" ; \
     73  1.6  apb 		done ; \
     74  1.1  apb 	        false ; \
     75  1.1  apb 	    fi }
     76  1.4  apb .endif
     77  1.1  apb .endfor
     78  1.1  apb 
     79  1.2  apb # Don't automatically load ".depend" files during "make clean"
     80  1.2  apb # or "make cleandir".
     81  1.2  apb .if make(clean) || make(cleandir)
     82  1.2  apb .MAKE.DEPENDFILE := .depend.no-such-file
     83  1.2  apb .endif
     84  1.2  apb 
     85  1.1  apb .endif	# !defined(_BSD_CLEAN_MK)
     86