worldstone: add -s for statistical profiling
[minix.git] / share / mk / bsd.clean.mk
blob32fba13b1f514454d96f3ffc221976d05979c41b
1 # $NetBSD: bsd.clean.mk,v 1.5 2011/11/22 18:25:48 apb Exp $
3 # <bsd.clean.mk>
5 # Public targets:
7 # clean: Delete files listed in ${CLEANFILES}.
8 # cleandir: Delete files listed in ${CLEANFILES} and ${CLEANDIRFILES}.
10 # Public variables:
12 # CLEANFILES Files to remove for both the clean and cleandir targets.
14 # CLEANDIRFILES Files to remove for the cleandir target, but not for
15 # the clean target.
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_)
24 _BSD_CLEAN_MK_=1
26 .include <bsd.init.mk>
28 MKCLEANSRC?= yes
29 MKCLEANVERIFY?= yes
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
42 # searching .PATH.)
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".
56 __cleanuse: .USE
57 .if 0 # print "# clean CLEANFILES" for debugging
58 ${"${.ALLSRC:@v@${${v}:M*}@:Q}" == "":?@true:${_MKMSG} \
59 "clean" ${.ALLSRC} }
60 .endif
61 .for _d in ${"${.OBJDIR}" == "${.CURDIR}" || "${MKCLEANSRC}" == "no" \
62 :? ${.OBJDIR} \
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}:" ; \
71 echo "\$bad" ; \
72 false ; \
73 fi }
74 .endif
75 .endfor
77 # Don't automatically load ".depend" files during "make clean"
78 # or "make cleandir".
79 .if make(clean) || make(cleandir)
80 .MAKE.DEPENDFILE := .depend.no-such-file
81 .endif
83 .endif # !defined(_BSD_CLEAN_MK)