Home | History | Annotate | Line # | Download | only in mk
bsd.clean.mk revision 1.2
      1  1.2  apb # $NetBSD: bsd.clean.mk,v 1.2 2011/09/10 19:25:10 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.1  apb 
     17  1.1  apb .if !defined(_BSD_CLEAN_MK_)
     18  1.1  apb _BSD_CLEAN_MK_=1
     19  1.1  apb 
     20  1.1  apb .include <bsd.init.mk>
     21  1.1  apb 
     22  1.1  apb clean:		.PHONY __doclean
     23  1.1  apb __doclean:	.PHONY .MADE __cleanuse CLEANFILES
     24  1.1  apb cleandir:	.PHONY clean __docleandir
     25  1.1  apb __docleandir:	.PHONY .MADE __cleanuse CLEANDIRFILES
     26  1.1  apb 
     27  1.1  apb # __cleanuse is invoked with ${.ALLSRC} as the name of a variable
     28  1.1  apb # (such as CLEANFILES or CLEANDIRFILES), or possibly a list of
     29  1.1  apb # variable names.  ${.ALLSRC:@v@${${v}}@} will be the list of
     30  1.1  apb # files to delete.  (We pass the variable name, e.g. CLEANFILES,
     31  1.1  apb # instead of the file names, e.g. ${CLEANFILES}, because we don't
     32  1.1  apb # want make to replace any of the file names with the result of
     33  1.1  apb # searching .PATH.)
     34  1.1  apb #
     35  1.1  apb # If the list of file names is non-empty then use "rm -f" to
     36  1.1  apb # delete the files, and "ls -d" to check that the deletion was
     37  1.1  apb # successful.  If the list of files is empty, then the commands
     38  1.1  apb # reduce to "true", with an "@" prefix to prevent echoing.
     39  1.1  apb #
     40  1.1  apb # If .OBJDIR is different from .SRCDIR then repeat all this for
     41  1.1  apb # both .OBJDIR and .SRCDIR.
     42  1.1  apb #
     43  1.1  apb __cleanuse: .USE
     44  1.1  apb 	${"${.ALLSRC:@v@${${v}}@}" == "":?@true:${_MKMSG} \
     45  1.1  apb 		"clean" ${.ALLSRC} }
     46  1.1  apb .for _d in ${"${.OBJDIR}" == "${.CURDIR}" \
     47  1.1  apb 		:? ${.OBJDIR} \
     48  1.1  apb 		:  ${.OBJDIR} ${.CURDIR} }
     49  1.1  apb 	-${"${.ALLSRC:@v@${${v}}@}" == "":?@true: \
     50  1.1  apb 	    (cd ${_d} && rm -f ${.ALLSRC:@v@${${v}}@}) }
     51  1.1  apb 	@${"${.ALLSRC:@v@${${v}}@}" == "":?true: \
     52  1.1  apb 	    bad="\$(cd ${_d} && ls -d ${.ALLSRC:@v@${${v}}@} 2>/dev/null)"; \
     53  1.1  apb 	    if test -n "\$bad"; then \
     54  1.1  apb 	        echo "Failed to remove files from ${_d}:" ; \
     55  1.1  apb 	        echo "\$bad" ; \
     56  1.1  apb 	        false ; \
     57  1.1  apb 	    fi }
     58  1.1  apb .endfor
     59  1.1  apb 
     60  1.2  apb # Don't automatically load ".depend" files during "make clean"
     61  1.2  apb # or "make cleandir".
     62  1.2  apb .if make(clean) || make(cleandir)
     63  1.2  apb .MAKE.DEPENDFILE := .depend.no-such-file
     64  1.2  apb .endif
     65  1.2  apb 
     66  1.1  apb .endif	# !defined(_BSD_CLEAN_MK)
     67