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: Kaz Kylheku (gmake)
Subject: Re: Q: How to delete all out of date targets
Date: Tue, 09 Mar 2021 08:45:45 -0800
User-agent: Roundcube Webmail/0.9.2

On 2021-03-08 21:10, Cook, Malcolm wrote:
Hi,

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.

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:~/txr$ ./rm-ood-targets.txr
  removing 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.

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

  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.

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.

Cheers ...



reply via email to

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