Alan Barrett | 7 Sep 2011 23:51
Gravatar

Changing "make clean" and "make cleandir"

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.

The appended patch makes the following changes to how "make clean" 
and "make cleandir" work:

* The real work is done in a new include file, bsd.clean.mk.

* A new variable, CLEANDIRFILES, contains a list of files to be
   deleted by "make cleandir", analogous to the existing CLEANFILES
   variable used by "make clean".

* Other bsd.*.mk files no longer define their own "clean" or
   "cleandir" targets; instead, they append to the CLEANFILES or
   CLEANDIRFILES variables, and .include <bsd.clean.mk>.  (There were
   some cases where the CLEANFILES variable was used by a cleandir
   target; these have been changed to use the CLEANDIRFILES variable
   instead.)

* If ${.OBJDIR} and ${.CURDIR} are different, then "make clean" and
   "make cleandir" delete files from both directories.

--apb (Alan Barrett)

Index: share/mk/bsd.README
===================================================================
--- share/mk/bsd.README	30 Jun 2011 18:13:51 -0000	1.284
(Continue reading)

Matt Thomas | 8 Sep 2011 01:01

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


On Sep 7, 2011, at 2:51 PM, Alan Barrett 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?
Alan Barrett | 8 Sep 2011 08:36
Gravatar

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?

The current draft just does "rm -f".  If the source tree is read-only
but contains files that should be removed, it will silently fail to
remove those files.

I can add code to test whether any files remain after the "rm -f",
and to fail if so.  Checking for empty output from ls should do it.

--apb (Alan Barrett)

Alan Barrett | 8 Sep 2011 08:46
Gravatar

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

On Thu, 08 Sep 2011, Alan Barrett wrote:
>> Have you tried it on a read-only source tree?
>>
>> Does it appropriately fail when it can't remove a file it 
>> should have?
>
> The current draft just does "rm -f".  If the source tree is 
> read-only but contains files that should be removed, it will 
> silently fail to remove those files.

I hadn't actually tested that.  When I do test it, what happens 
on NetBSD is that "rm -f file_that_exists" complains about a 
read-only file system, and causes the "make cleandir" to fail.

> I can add code to test whether any files remain after the "rm 
> -f", and to fail if so.  Checking for empty output from ls 
> should do it.

I still think that this may be worthwhile, in case the build host 
has a "rm" command that behaves differently.

--apb (Alan Barrett)

matthew green | 8 Sep 2011 10:14
Picon
Favicon

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?
> 
> The current draft just does "rm -f".  If the source tree is read-only
> but contains files that should be removed, it will silently fail to
> remove those files.
> 
> I can add code to test whether any files remain after the "rm -f",
> and to fail if so.  Checking for empty output from ls should do it.

did you check this?  my /usr/src is r/o:

phat-bass /usr/src> rm -f Makefile
rm: Makefile: Read-only file system
phat-bass /usr/src> echo $?
1

.mrg.

(Continue reading)

Alan Barrett | 8 Sep 2011 17:10
Gravatar

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:

(Continue reading)


Gmane