1 # $NetBSD: bsd.clean.mk,v 1.8 2012/11/19 16:04:54 apb Exp $
7 # clean: Delete files listed in ${CLEANFILES}.
8 # cleandir: Delete files listed in ${CLEANFILES} and ${CLEANDIRFILES}.
12 # CLEANFILES Files to remove for both the clean and cleandir targets.
14 # CLEANDIRFILES Files to remove for the cleandir target, but not for
17 # MKCLEANSRC Whether or not to clean the source directory
18 # in addition to the object directory. Defaults to "yes".
20 # MKCLEANVERIFY Whether or not to verify that the file deletion worked.
23 # The files listed in CLEANFILES and CLEANDIRFILES must not be
24 # directories, because the potential risk from running "rm -rf" commands
25 # in bsd.clean.mk is considered too great. If you want to recursively
26 # delete a directory as part of "make clean" or "make cleandir" then you
27 # need to provide your own target.
29 .if
!defined
(_BSD_CLEAN_MK_
)
32 .
include <bsd.init.mk
>
37 clean: .PHONY __doclean
38 __doclean
: .PHONY .MADE __cleanuse CLEANFILES
39 cleandir
: .PHONY
clean __docleandir
40 __docleandir
: .PHONY .MADE __cleanuse CLEANDIRFILES
42 # __cleanuse is invoked with ${.ALLSRC} as the name of a variable
43 # (such as CLEANFILES or CLEANDIRFILES), or possibly a list of
44 # variable names. ${.ALLSRC:@v@${${v}}@} will be the list of
45 # files to delete. (We pass the variable name, e.g. CLEANFILES,
46 # instead of the file names, e.g. ${CLEANFILES}, because we don't
47 # want make to replace any of the file names with the result of
50 # If the list of files is empty, then the commands
51 # reduce to "true", with an "@" prefix to prevent echoing.
53 # The use of :M* is needed to handle the case that CLEANFILES
54 # or CLEANDIRFILES is not completely empty but contains spaces.
55 # This can easily happen when CLEANFILES or CLEANDIRFILES is set
56 # from other variables that happen to be empty.)
58 # The use of :Q is needed to handle the case that CLEANFILES
59 # or CLEANDIRFILES contains quoted strings, such as
60 # CLEANFILES = "filename with spaces".
63 .if
0 # print "# clean CLEANFILES" for debugging
64 ${"${.ALLSRC:@v@${${v}:M*}@:Q}" == "":?@true
:${_MKMSG} \
67 .for _d in
${"${.OBJDIR}" == "${.CURDIR}" ||
"${MKCLEANSRC}" == "no" \
69 : ${.OBJDIR
} ${.CURDIR
} }
70 ${"${.ALLSRC:@v@${${v}:M*}@:Q}" == "":?@true
: \
71 (cd
${_d} && rm -f
${.ALLSRC
:@v@
${${v}}@
} || true
) }
72 .if
"${MKCLEANVERIFY}" == "yes"
73 @
${"${.ALLSRC:@v@${${v}:M*}@:Q}" == "":?true
: \
74 bad
="\$(cd ${_d} && ls -1d ${.ALLSRC:@v@${${v}}@} 2>/dev/null)"; \
75 if
test -n
"\$bad"; then \
76 echo
"Failed to remove the following files from ${_d}:" ; \
77 echo
"\$bad" | while read file
; do \
85 # Don't automatically load ".depend" files during "make clean"
87 .if make
(clean) || make
(cleandir
)
88 .MAKE.DEPENDFILE
:= .depend.no-such-file
91 .
endif # !defined(_BSD_CLEAN_MK)