>From 73bb870a6a71344d7aaac199e6b72a24a883de7b Mon Sep 17 00:00:00 2001
From: Nils Goroll <nils.goroll@uplex.de>
Date: Tue, 20 Aug 2013 11:39:30 +0200
Subject: [PATCH] improve configure auto-magic

- Makefile and prepare-source.mak should not keep a configure.sh output from a failed
  autoconf run
- the configure wrapper tool should always call prepare-source to rebuild configure.sh
  when required
- Makefile and prepare-source.mak should rebuild aclocal.m4 when configure.ac changes
---
 Makefile.in        |    5 ++++-
 configure          |   14 +++++++-------
 prepare-source.mak |    5 ++++-
 3 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index 2cb50bc..7c94c10 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -143,10 +143,13 @@ gensend: gen
 conf:
 	cd $(srcdir) && $(MAKE) -f prepare-source.mak conf
 
+aclocal.m4: configure.ac
+	aclocal -I m4
+
 configure.sh config.h.in: configure.ac aclocal.m4
 	@if test -f configure.sh; then cp -p configure.sh configure.sh.old; else touch configure.sh.old; fi
 	@if test -f config.h.in; then cp -p config.h.in config.h.in.old; else touch config.h.in.old; fi
-	autoconf -o configure.sh
+	autoconf -o configure.sh || ( rm configure.sh ; false )
 	autoheader && touch config.h.in
 	@if diff configure.sh configure.sh.old >/dev/null 2>&1; then \
 	    echo "configure.sh is unchanged."; \
diff --git a/configure b/configure
index 32cc3b5..24efc5e 100755
--- a/configure
+++ b/configure
@@ -15,13 +15,13 @@ if test ! -f "$realconfigure"; then
     else
 	actions='build'
     fi
-    if "$dir/prepare-source" $actions; then
-	:
-    else
-	echo 'Failed to build configure.sh and/or config.h.in -- giving up.' >&2
-	rm -f "$realconfigure"
-	exit 1
-    fi
+fi
+if "$dir/prepare-source" $actions; then
+    :
+else
+    echo 'Failed to build configure.sh and/or config.h.in -- giving up.' >&2
+    rm -f "$realconfigure"
+    exit 1
 fi
 
 exec "$realconfigure" "${@}"
diff --git a/prepare-source.mak b/prepare-source.mak
index 054bab7..7d088fd 100644
--- a/prepare-source.mak
+++ b/prepare-source.mak
@@ -1,7 +1,10 @@
 conf: configure.sh config.h.in
 
+aclocal.m4: configure.ac
+	aclocal -I m4
+
 configure.sh: configure.ac aclocal.m4
-	autoconf -o configure.sh
+	autoconf -o configure.sh || ( rm configure.sh ; false )
 
 config.h.in: configure.ac aclocal.m4
 	autoheader && touch config.h.in
-- 
1.5.6.5

