tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Changing "make clean" and "make cleandir"



On Wed, 07 Sep 2011, Matt Thomas wrote:
I would like to make "make clean" and "make cleandir" delete leftover files in the source directory as well as the obj directory. This should help with the case that the current build uses .OBJDIR != .CURDIR, but an earlier build with .OBJDIR = .CURDIR had left some output files in the source directory.

Have you tried it on a read-only source tree?

Does it appropriately fail when it can't remove a file it should have?

I attach a new version of bsd.clean.mk that uses "ls" to verify that all files have been removed.

I have tested this with read-only or writable source tree, with or without obj dirs, with or without build products in the src directory.

When it works, you see stuff like this:

cleandir ===> etc
(cd /home/apb/netbsd/current/work.ro/OBJDIR/etc && rm -f MAKEDEV etc-release
a.out [Ee]rrs mklog core *.core .gdbinit)
(cd /home/apb/netbsd/current/src.ro/etc && rm -f MAKEDEV etc-release
a.out [Ee]rrs mklog core *.core .gdbinit)

When it can't delete a file, it fails like this:

rm: MAKEDEV: Read-only file system
[a few lines of messages from make]
Failed to remove files from /home/apb/netbsd/current/src.ro/etc:
MAKEDEV
[more messages from make]

--apb (Alan Barrett)
# $NetBSD$

# <bsd.clean.mk>
#
# Public targets:
#
# clean:        Delete files listed in ${CLEANFILES}.
# cleandir:     Delete files listed in ${CLEANFILES} and ${CLEANDIRFILES}.
#
# Public variables:
#
# CLEANFILES    Files to remove for both the clean and cleandir targets.
#
# CLEANDIRFILES Files to remove for the cleandir target, but not for
#               the clean target.

.if !defined(_BSD_CLEAN_MK_)
_BSD_CLEAN_MK_=1

clean:          .PHONY __doclean
__doclean:      .PHONY .MADE __cleanuse CLEANFILES
cleandir:       .PHONY clean __docleandir
__docleandir:   .PHONY .MADE __cleanuse CLEANDIRFILES

# __cleanuse is invoked with ${.ALLSRC} as the name of a variable
# (such as CLEANFILES or CLEANDIRFILES), or possibly a list of
# variable names.  ${.ALLSRC:@v@${${v}}@} will be the list of
# files to delete.  (We pass the variable name, e.g. CLEANFILES,
# instead of the file names, e.g. ${CLEANFILES}, because we don't
# want make to replace any of the file names with the result of
# searching .PATH.)
#
# If the list of file names is non-empty then use "rm -f" to
# delete the files, and "ls -d" to check that the deletion was
# successful.
#
# If .OBJDIR is different from .SRCDIR then repeat all this for
# both .OBJDIR and .SRCDIR.
#
__cleanuse: .USE
.for _d in ${.OBJDIR} ${"${.OBJDIR}" != "${.CURDIR}":?${.CURDIR}:}
        -${"${.ALLSRC:@v@${${v}}@}" == "":?true: \
            (cd ${_d} && rm -f ${.ALLSRC:@v@${${v}}@}) }
        @${"${.ALLSRC:@v@${${v}}@}" == "":?true: \
            bad="\$(cd ${_d} && ls -d ${.ALLSRC:@v@${${v}}@} 2>/dev/null)"; \
            if test -n "\$bad"; then \
                echo "Failed to remove files from ${_d}:" ; \
                echo "\$bad" ; \
                false ; \
            fi }
.endfor

.endif  # !defined(_BSD_CLEAN_MK)


Home | Main Index | Thread Index | Old Index