common/autoconf/autogen.sh
changeset 22722 03797b5d2ba3
parent 22714 a752920c4317
--- a/common/autoconf/autogen.sh	Mon Feb 24 12:16:58 2014 +0100
+++ b/common/autoconf/autogen.sh	Mon Feb 24 13:29:26 2014 +0100
@@ -22,6 +22,23 @@
 # questions.
 #
 
+generate_configure_script() {
+  # First create a header
+  cat > $1 << EOT
+#!/bin/bash
+#
+# ##########################################################
+# ### THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT. ###
+# ##########################################################
+#
+EOT
+  # Then replace "magic" variables in configure.ac and append the output
+  # from autoconf. $2 is either cat (just a no-op) or a filter.
+  cat $script_dir/configure.ac | sed -e "s|@DATE_WHEN_GENERATED@|$TIMESTAMP|" | \
+      eval $2 | ${AUTOCONF} -W all -I$script_dir - >> $1
+  rm -rf autom4te.cache
+}
+
 script_dir=`dirname $0`
 
 # Create a timestamp as seconds since epoch
@@ -36,7 +53,8 @@
 fi
 
 if test "x$CUSTOM_CONFIG_DIR" = "x"; then
-  custom_script_dir="$script_dir/../../closed/autoconf"
+  topdir=`cd $script_dir/../..  >/dev/null && pwd`
+  custom_script_dir="$topdir/closed/autoconf"
 else
   custom_script_dir=$CUSTOM_CONFIG_DIR
 fi
@@ -45,25 +63,23 @@
 
 AUTOCONF="`which autoconf 2> /dev/null | grep -v '^no autoconf in'`"
 
-echo "Autoconf found: ${AUTOCONF}"
-
 if test "x${AUTOCONF}" = x; then
-  echo You need autoconf installed to be able to regenerate the configure script
-  echo Error: Cannot find autoconf 1>&2
+  echo "You need autoconf installed to be able to regenerate the configure script"
+  echo "Error: Cannot find autoconf" 1>&2
   exit 1
 fi
 
-echo Generating generated-configure.sh with ${AUTOCONF}
-cat $script_dir/configure.ac  | sed -e "s|@DATE_WHEN_GENERATED@|$TIMESTAMP|" | ${AUTOCONF} -W all -I$script_dir - > $script_dir/generated-configure.sh
-rm -rf autom4te.cache
+autoconf_version=`$AUTOCONF --version | head -1`
+echo "Using autoconf at ${AUTOCONF} [$autoconf_version]"
+
+echo "Generating generated-configure.sh"
+generate_configure_script "$script_dir/generated-configure.sh" 'cat'
 
 if test -e $custom_hook; then
-  echo Generating custom generated-configure.sh
   # We have custom sources available; also generate configure script
   # with custom hooks compiled in.
-  cat $script_dir/configure.ac | sed -e "s|@DATE_WHEN_GENERATED@|$TIMESTAMP|" | \
-      sed -e "s|#CUSTOM_AUTOCONF_INCLUDE|m4_include([$custom_hook])|" | ${AUTOCONF} -W all -I$script_dir - > $custom_script_dir/generated-configure.sh
-  rm -rf autom4te.cache
+  echo "Generating custom generated-configure.sh"
+  generate_configure_script "$custom_script_dir/generated-configure.sh" 'sed -e "s|#CUSTOM_AUTOCONF_INCLUDE|m4_include([$custom_hook])|"'
 else
-  echo No custom hook found:  $custom_hook
+  echo "(No custom hook found at $custom_hook)"
 fi