help-make
[Top][All Lists]
Advanced

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

RE: Q: How to delete all out of date targets


From: Cook, Malcolm
Subject: RE: Q: How to delete all out of date targets
Date: Wed, 10 Mar 2021 08:13:45 +0000

Hi, thanks all for your suggestions, I'm replying directly to Kaz whose 
solution is working in my hands now....

>> Is it possible using Gnu Make to delete all out of date targets?
>
>We can do this using text processing around the output of the -d option,
>together with a dry run -n. The verbose -d output has the information
>about out of date targets.

Yes - thanks - I like this approach and will adopt it....

>Example run:
>
>Let's touch lib.c, making lib.o out of date, and consequently, the txr
>executable out of date:
>
>sun-go:~/txr$ touch lib.c
>sun-go:a opt/lib.o, out of date wrt lib.c
>removing opt/lib.o, out of date wrt lib.c
>removing txr, out of date wrt opt/lib.o
>
>Now, re-make those targets:
>
>sun-go:~/txr$ make
>CC lib.c -> opt/lib.o
>LINK opt/txr.o opt/lex.yy.o opt/y.tab.o opt/match.o opt/lib.o 
>opt/regex.o opt/gc.o opt/unwind.o opt/stream.o opt/arith.o opt/hash.o 
>opt/utf8.o opt/filter.o opt/eval.o opt/parser.o opt/rand.o opt/combi.o 
>opt/sysif.o opt/args.o opt/lisplib.o opt/cadr.o opt/struct.o 
>opt/itypes.o opt/buf.o opt/jmp.o opt/protsym.o opt/ffi.o opt/strudel.o 
>opt/vm.o opt/chksum.o opt/chksums/sha256.o opt/chksums/crc32.o 
>opt/chksums/md5.o opt/tree.o opt/time.o opt/mpi/mpi.o opt/debug.o 
>opt/syslog.o opt/glob.o opt/ftw.o opt/signal.o opt/socket.o 
>opt/termios.o opt/linenoise/linenoise.o -> txr
>
>The rm-ood-targets.txr program runs make -n -d in a hopefully C
>locale, so the messages are in English. It looks for messages
>indicating out of date targets and extracts the pieces of
>text from them:
>
>sun-go:~/txr$ cat rm-ood-targets.txr
>#!/usr/bin/env txr
>@(next (open-command `LANG=C LC_ALL=C make -n -d`))
>@(repeat)
>Prerequisite '@pre' is newer than target '@targ'.
>@(do
>(put-line `removing @targ, out of date wrt @pre`)
>(remove-path targ))
>@(end)
>
>This could be cobbed together with some grep job, but I eat my own
>dogfood.

Looks tasty, but despite being a lover of lisps, m4, regexp, and such, I will 
refrain from taking the opportunity to learn txr, and will reach for perl to 
extract the out of date targets, and gnu parallel to iterate over them.

Like this:

<SomeMakeCommand>  -dn | LANG=C LC_ALL=C  perl -lne 'print if 
s|^\s*Prerequisite .* is newer than target .(.*).\.|$1|' | sort -r | uniq | 
parallel rm

>
>Note, however that a missing prerequisite is also treated as if the
>dependent target is out of date.

Understood - that is desirable in my case

>
>sun-go:~/txr$ rm opt/lib.o
>sun-go:~/txr$ ./rm-ood-targets.txr
>removing txr, out of date wrt opt/lib.o
>
>Depending on the parsing of human-readable diagnostics from a tool
>isn't the greatest idea on the planet, but in this case, the odds
>seem good that the specific messages are quite stable,
>and they are delimited by occurring on a separate line.

Works for me.

>
>GNU Make is integrated with the Guile Scheme language, but the
>integration is very light; you can't do much with it.
>
>Suppose that Make's object database were available via Guile API.
>A Guile script could then walk the rules, discover out-of-date
>targets, and do whatever it wants. This script could then
>be integrated into a Makefile.

Thanks.  I really appreciate your discussion of these considerations.  

Regards,

~Malcolm

>Cheers ...



reply via email to

[Prev in Thread] Current Thread [Next in Thread]