From 9c45babb8c7772fd1439a69a8432047fc9f28202 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Mon, 5 Mar 2012 11:38:35 +0100
Subject: [PATCH] Makefile: improve the fix for .DELETE_ON_ERROR
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

I've investigated more and it seems that .DELETE_ON_ERROR not working
is a bug/regression in some versions of make; testing with make 3.82
from Debian experimental makes this special target work as
expected. Also, make 3.81 works on trivial Makefiles, but not on our
complex one.

In the meantime, let's improve the fix for the building of man pages:
make the removal implicit, instead of explicit, via the use of 'trap'
on EXIT. I just hope this behaves consistently across all bash
versions :)

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: RenΓ© Nussbaumer <rn@google.com>
---
 Makefile.am | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index bda29274e..5ca0d3e4c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -919,10 +919,12 @@ man/%.7.in man/%.8.in man/%.1.in: man/%.gen man/footer.man
 	@test -n "$(PANDOC)" || \
 	  { echo 'pandoc' not found during configure; exit 1; }
 	set -o pipefail ; \
+	trap 'echo auto-removing $@; rm $@' EXIT; \
 	$(PANDOC) -s -f rst -t man -A man/footer.man $< | \
-	  sed -e 's/\\@/@/g' > $@
-	if test -n "$(MAN_HAS_WARNINGS)"; then $(CHECK_MAN) $@ || \
-	  { rm -f "$@"; exit 1; } ; fi
+	  sed -e 's/\\@/@/g' > $@; \
+	if test -n "$(MAN_HAS_WARNINGS)"; then $(CHECK_MAN) $@; fi; \
+	trap - EXIT
+
 
 man/%.html.in: man/%.gen man/footer.html
 	@test -n "$(PANDOC)" || \
-- 
GitLab