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