From 26f80f0b525b70b3f33eb8d4a5a6c94da7a20c9d Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 1 May 2020 15:32:02 -0400 Subject: [PATCH] GNUmakefile: simplify recursive logic and eliminate a "pdflatex" call. In the recursive $(MAKE), the sub-$(MAKE) can succeed and then subsequently delete its "previous" file. When that returns control to the parent $(MAKE), the parent will try to diff the (now missing) "previous" file against the latest one, which of course fails. This leads to an extra build of the same, current, not-gonna-change PDF. A slight change in the logic both simplifies things and eliminates that extra rebuild. Thanks to Wojtek Kosior who pointed out the bug in an email. --- GNUmakefile | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 6225707..1ce4ddc 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -88,26 +88,21 @@ endif # in a makefile? # # At the start of this target, we call $(LATEX) to compile $(PN).tex. -# The first step is to check for the existence of a "previous" -# file. If there isn't one, this is the first time that we've tried to -# build the PDF. In that case, take the PDF that we've just built and -# make *that* the previous file. Then start all over. If there is a -# previous file, then this is the second (or more) time that we've -# tried to build the PDF. We diff the PDF file that we've just built -# against the previous file; if they're the same, then we've succeeded -# and stop. Otherwise, we make the new PDF the previous file, and -# start all over. The end result is that we will loop until the -# newly-created PDF and the previous file are identical. +# Afterwards, we check for the existence of a "previous" file. If +# there isn't one, then this is the first time that we've built the +# PDF. In that case, we take the PDF that we've just built and make it +# the "previous" file before starting all over. If, on the other hand, +# there already *was* a "previous" file, then this is the second (or +# third...) time that we've built the PDF. We diff the newly-built PDF +# against the "previous" file; if they're the same, then we've +# succeeded and stop. Otherwise, we make the new PDF the "previous" +# one, and start all over. The end result is that we will loop until +# the newly-created PDF and the "previous" one are identical. # $(PN).pdf: $(SRCS) $(PN).bbl $(INDEX_DSTS) $(LATEX) $(PN).tex - if [ ! -f $@.previous ]; then \ - mv $@ $@.previous; \ - $(MAKE) $@; \ - fi; - - if cmp -s $@ $@.previous; then \ + if [ -f $@.previous ] && cmp -s $@ $@.previous; then \ rm $@.previous; \ else \ mv $@ $@.previous; \ -- 2.44.2