bsd.clean.mk revision 1.2 1 # $NetBSD: bsd.clean.mk,v 1.2 2011/09/10 19:25:10 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 ${"${.ALLSRC:@v@${${v}}@}" == "":?@true:${_MKMSG} \
45 "clean" ${.ALLSRC} }
46 .for _d in ${"${.OBJDIR}" == "${.CURDIR}" \
47 :? ${.OBJDIR} \
48 : ${.OBJDIR} ${.CURDIR} }
49 -${"${.ALLSRC:@v@${${v}}@}" == "":?@true: \
50 (cd ${_d} && rm -f ${.ALLSRC:@v@${${v}}@}) }
51 @${"${.ALLSRC:@v@${${v}}@}" == "":?true: \
52 bad="\$(cd ${_d} && ls -d ${.ALLSRC:@v@${${v}}@} 2>/dev/null)"; \
53 if test -n "\$bad"; then \
54 echo "Failed to remove files from ${_d}:" ; \
55 echo "\$bad" ; \
56 false ; \
57 fi }
58 .endfor
59
60 # Don't automatically load ".depend" files during "make clean"
61 # or "make cleandir".
62 .if make(clean) || make(cleandir)
63 .MAKE.DEPENDFILE := .depend.no-such-file
64 .endif
65
66 .endif # !defined(_BSD_CLEAN_MK)
67