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