Home | History | Annotate | Line # | Download | only in mk
bsd.clean.mk revision 1.5.6.2
      1  1.5.6.2  tls # $NetBSD: bsd.clean.mk,v 1.5.6.2 2013/02/25 00:28:16 tls 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.5.6.2  tls # 		in addition to the object directory.  Defaults to "yes".
     19      1.4  apb #
     20      1.4  apb # MKCLEANVERIFY	Whether or not to verify that the file deletion worked.
     21  1.5.6.2  tls #		Defaults to "yes".
     22      1.4  apb #
     23  1.5.6.2  tls # The files listed in CLEANFILES and CLEANDIRFILES must not be
     24  1.5.6.2  tls # directories, because the potential risk from running "rm -rf" commands
     25  1.5.6.2  tls # in bsd.clean.mk is considered too great.  If you want to recursively
     26  1.5.6.2  tls # delete a directory as part of "make clean" or "make cleandir" then you
     27  1.5.6.2  tls # need to provide your own target.
     28      1.1  apb 
     29      1.1  apb .if !defined(_BSD_CLEAN_MK_)
     30      1.1  apb _BSD_CLEAN_MK_=1
     31      1.1  apb 
     32      1.1  apb .include <bsd.init.mk>
     33      1.1  apb 
     34      1.4  apb MKCLEANSRC?=	yes
     35      1.4  apb MKCLEANVERIFY?=	yes
     36      1.4  apb 
     37      1.1  apb clean:		.PHONY __doclean
     38      1.1  apb __doclean:	.PHONY .MADE __cleanuse CLEANFILES
     39      1.1  apb cleandir:	.PHONY clean __docleandir
     40      1.1  apb __docleandir:	.PHONY .MADE __cleanuse CLEANDIRFILES
     41      1.1  apb 
     42      1.1  apb # __cleanuse is invoked with ${.ALLSRC} as the name of a variable
     43      1.1  apb # (such as CLEANFILES or CLEANDIRFILES), or possibly a list of
     44      1.1  apb # variable names.  ${.ALLSRC:@v@${${v}}@} will be the list of
     45      1.1  apb # files to delete.  (We pass the variable name, e.g. CLEANFILES,
     46      1.1  apb # instead of the file names, e.g. ${CLEANFILES}, because we don't
     47      1.1  apb # want make to replace any of the file names with the result of
     48      1.1  apb # searching .PATH.)
     49      1.1  apb #
     50      1.4  apb # If the list of files is empty, then the commands
     51      1.1  apb # reduce to "true", with an "@" prefix to prevent echoing.
     52      1.1  apb #
     53      1.5  apb # The use of :M* is needed to handle the case that CLEANFILES
     54      1.5  apb # or CLEANDIRFILES is not completely empty but contains spaces.
     55      1.5  apb # This can easily happen when CLEANFILES or CLEANDIRFILES is set
     56      1.5  apb # from other variables that happen to be empty.)
     57      1.5  apb #
     58      1.5  apb # The use of :Q is needed to handle the case that CLEANFILES
     59      1.5  apb # or CLEANDIRFILES contains quoted strings, such as
     60      1.5  apb # CLEANFILES = "filename with spaces".
     61      1.5  apb #
     62      1.1  apb __cleanuse: .USE
     63      1.3  apb .if 0	# print "# clean CLEANFILES" for debugging
     64      1.5  apb 	${"${.ALLSRC:@v@${${v}:M*}@:Q}" == "":?@true:${_MKMSG} \
     65      1.1  apb 		"clean" ${.ALLSRC} }
     66      1.3  apb .endif
     67      1.4  apb .for _d in ${"${.OBJDIR}" == "${.CURDIR}" || "${MKCLEANSRC}" == "no" \
     68      1.1  apb 		:? ${.OBJDIR} \
     69      1.1  apb 		:  ${.OBJDIR} ${.CURDIR} }
     70      1.5  apb 	${"${.ALLSRC:@v@${${v}:M*}@:Q}" == "":?@true: \
     71      1.3  apb 	    (cd ${_d} && rm -f ${.ALLSRC:@v@${${v}}@} || true) }
     72      1.4  apb .if "${MKCLEANVERIFY}" == "yes"
     73      1.5  apb 	@${"${.ALLSRC:@v@${${v}:M*}@:Q}" == "":?true: \
     74  1.5.6.1  tls 	    bad="\$(cd ${_d} && ls -1d ${.ALLSRC:@v@${${v}}@} 2>/dev/null)"; \
     75      1.1  apb 	    if test -n "\$bad"; then \
     76  1.5.6.1  tls 	        echo "Failed to remove the following files from ${_d}:" ; \
     77  1.5.6.1  tls 	        echo "\$bad" | while read file ; do \
     78  1.5.6.1  tls 		    echo "	\$file" ; \
     79  1.5.6.1  tls 		done ; \
     80      1.1  apb 	        false ; \
     81      1.1  apb 	    fi }
     82      1.4  apb .endif
     83      1.1  apb .endfor
     84      1.1  apb 
     85      1.2  apb # Don't automatically load ".depend" files during "make clean"
     86      1.2  apb # or "make cleandir".
     87      1.2  apb .if make(clean) || make(cleandir)
     88      1.2  apb .MAKE.DEPENDFILE := .depend.no-such-file
     89      1.2  apb .endif
     90      1.2  apb 
     91      1.1  apb .endif	# !defined(_BSD_CLEAN_MK)
     92