1 # $NetBSD: bsd.clean.mk,v 1.5 2011/11/22 18:25:48 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.
20 # MKCLEANVERIFY Whether or not to verify that the file deletion worked.
23 .if
!defined
(_BSD_CLEAN_MK_
)
26 .
include <bsd.init.mk
>
31 clean: .PHONY __doclean
32 __doclean
: .PHONY .MADE __cleanuse CLEANFILES
33 cleandir
: .PHONY
clean __docleandir
34 __docleandir
: .PHONY .MADE __cleanuse CLEANDIRFILES
36 # __cleanuse is invoked with ${.ALLSRC} as the name of a variable
37 # (such as CLEANFILES or CLEANDIRFILES), or possibly a list of
38 # variable names. ${.ALLSRC:@v@${${v}}@} will be the list of
39 # files to delete. (We pass the variable name, e.g. CLEANFILES,
40 # instead of the file names, e.g. ${CLEANFILES}, because we don't
41 # want make to replace any of the file names with the result of
44 # If the list of files is empty, then the commands
45 # reduce to "true", with an "@" prefix to prevent echoing.
47 # The use of :M* is needed to handle the case that CLEANFILES
48 # or CLEANDIRFILES is not completely empty but contains spaces.
49 # This can easily happen when CLEANFILES or CLEANDIRFILES is set
50 # from other variables that happen to be empty.)
52 # The use of :Q is needed to handle the case that CLEANFILES
53 # or CLEANDIRFILES contains quoted strings, such as
54 # CLEANFILES = "filename with spaces".
57 .if
0 # print "# clean CLEANFILES" for debugging
58 ${"${.ALLSRC:@v@${${v}:M*}@:Q}" == "":?@true
:${_MKMSG} \
61 .for _d in
${"${.OBJDIR}" == "${.CURDIR}" ||
"${MKCLEANSRC}" == "no" \
63 : ${.OBJDIR
} ${.CURDIR
} }
64 ${"${.ALLSRC:@v@${${v}:M*}@:Q}" == "":?@true
: \
65 (cd
${_d} && rm -f
${.ALLSRC
:@v@
${${v}}@
} || true
) }
66 .if
"${MKCLEANVERIFY}" == "yes"
67 @
${"${.ALLSRC:@v@${${v}:M*}@:Q}" == "":?true
: \
68 bad
="\$(cd ${_d} && ls -d ${.ALLSRC:@v@${${v}}@} 2>/dev/null)"; \
69 if
test -n
"\$bad"; then \
70 echo
"Failed to remove files from ${_d}:" ; \
77 # Don't automatically load ".depend" files during "make clean"
79 .if make
(clean) || make
(cleandir
)
80 .MAKE.DEPENDFILE
:= .depend.no-such-file
83 .
endif # !defined(_BSD_CLEAN_MK)