diff --git a/autogen.sh b/autogen.sh
index bf4d01829bbd8c11ff01b392706781ed75041215..a3bec6b48bff99448d489073c147ea92e0a9ff50 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -1,76 +1,7 @@
 #!/bin/sh
 
-for arg in "$@"; do
-  case ${arg} in
-    --help | -h)
-      cat <<EOF
-Usage: $0 [OPTION]
-
-Generate the configure script and other Autotools files.
-
-Options:
-  -h, --help              display this help and exit
-  -d, --download          download the most recent versions
-                          of \`config.guess' and \`config.sub'
-
-EOF
-    exit 0
-    ;;
-    --download | -d)
-      download=yes
-    ;;
-    *)
-      echo "ERROR: unrecognized option '${arg}': try \`$0 --help' for more information" >&2
-      exit 2
-    ;;
-  esac
-done
-
 script_dir=`echo "$0" | sed 's@[^/]*$@@'`
-echo "Running autoreconf in $script_dir"
 (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
 cd "$script_dir"
 
-autoreconf -fvi || exit $?
-
-# Patch libtool.m4:
-for patch in \
-  contrib/000debian-no-overlink-patch/debian-no-overlink.patch \
-  ; do
-    echo "applying $patch"
-    patch -p 1 --no-backup-if-mismatch --forward -r - -i $patch -d .
-    # The program 'patch' exits with exitcode=1 if the patch has already been applied.
-    # Consider this a normal scenario:
-    exitcode=$?; if test $exitcode -ne 0 && test $exitcode -ne 1; then exit $exitcode; fi
-done
-autoconf -f || exit $?
-# Reset libtool.m4 timestamps to avoid confusing make:
-touch -r m4/ltversion.m4 m4/libtool.m4 || exit $?
-
-# Patch the rest of the files:
-for patch in \
-  contrib/100nagfor-libtool-patch/nagfor-libtool-2.4.6.patch \
-  contrib/101aix-deplib-rpath-patch/aix-deplib-libtool.patch \
-  contrib/103ltmain-ld-groups-patch/ltmain-ld-groups-libtool-2.4.6.patch \
-  contrib/104ltmain-xlinker-patch/ltmain-xlinker-patch.patch \
-  contrib/105macos-nagfor-patch/macos-nagfor.patch \
-  contrib/106ltmain_nag_pthread-patch/ltmain_nag_pthread.patch \
-  contrib/107ltmain-early-xcompile-patch/ltmain-early-xcompile-libtool-2.4.6.patch \
-  contrib/108ltmain-parallel-printf-patch/ltmain-parallel-printf.patch \
-  ; do
-    echo "applying $patch"
-    patch -p 1 --no-backup-if-mismatch --forward -r - -i $patch -d .
-    exitcode=$?; if test $exitcode -ne 0 && test $exitcode -ne 1; then exit $exitcode; fi
-done
-
-if test x"$download" = xyes; then
-  url_base='https://git.savannah.gnu.org/cgit/config.git/plain'
-
-  for file in config.guess config.sub; do
-    echo "downloading $file"
-    src="$url_base/$file"; dst="config/$file"
-    wget -o /dev/null -O "$dst" "$src" || {
-      echo "ERROR: failed to download from $src" >&2
-      exit 1; }
-  done
-fi
+./scripts/reconfigure
diff --git a/contrib/100nagfor-libtool-patch/README.txt b/contrib/00nagfor-libtool-patch/README.txt
similarity index 100%
rename from contrib/100nagfor-libtool-patch/README.txt
rename to contrib/00nagfor-libtool-patch/README.txt
diff --git a/contrib/00nagfor-libtool-patch/nagfor-libtool-2.4.2.patch b/contrib/00nagfor-libtool-patch/nagfor-libtool-2.4.2.patch
new file mode 100644
index 0000000000000000000000000000000000000000..5a5a4af38a4ef1c4e770a283d63813ba3c0aa51d
--- /dev/null
+++ b/contrib/00nagfor-libtool-patch/nagfor-libtool-2.4.2.patch
@@ -0,0 +1,137 @@
+--- a/config/ltmain.sh	2012-06-12 00:20:43.000000000 +0200
++++ b/config/ltmain.sh	2014-08-19 16:34:48.161235251 +0200
+@@ -3229,6 +3229,25 @@
+ 
+ test "$opt_mode" = install && func_mode_install ${1+"$@"}
+ 
++func_add2xrpath ()
++{
++  dir="$1"
++  # We need an absolute path.
++  case $dir in
++    [\\/]* | [A-Za-z]:[\\/]*) ;;
++    =*)
++    func_stripname '=' '' "$dir"
++    dir=$lt_sysroot$func_stripname_result
++      ;;
++    *)
++      func_fatal_error "only absolute run-paths are allowed"
++      ;;
++  esac
++  case "$xrpath " in
++    *" $dir "*) ;;
++    *) func_append xrpath " $dir" ;;
++  esac
++}
+ 
+ # func_generate_dlsyms outputname originator pic_p
+ # Extract symbols from dlprefiles and create ${outputname}S.o with
+@@ -5727,20 +5746,7 @@
+ 	func_stripname '-R' '' "$arg"
+ 	dir=$func_stripname_result
+ 	# We need an absolute path.
+-	case $dir in
+-	[\\/]* | [A-Za-z]:[\\/]*) ;;
+-	=*)
+-	  func_stripname '=' '' "$dir"
+-	  dir=$lt_sysroot$func_stripname_result
+-	  ;;
+-	*)
+-	  func_fatal_error "only absolute run-paths are allowed"
+-	  ;;
+-	esac
+-	case "$xrpath " in
+-	*" $dir "*) ;;
+-	*) func_append xrpath " $dir" ;;
+-	esac
++	func_add2xrpath "$dir"
+ 	continue
+ 	;;
+ 
+@@ -5801,18 +5807,58 @@
+ 	;;
+ 
+       -Wl,*)
++	wlprefix=`expr x"$wl" : '.*' - 1`
++	wlprefix=`expr x"$arg" : 'x\(.\{'"$wlprefix"'\}\)'`
++	if test x"$wlprefix" = x"$wl" -a x"$wl" != x"-Wl,"; then
++	  func_append compiler_flags " $arg"
++	  func_append compile_command " $arg"
++	  func_append finalize_command " $arg"
++	  if expr "x$arg" : '^x'"$wl"'-rpath,,' >/dev/null ; then
++	    func_stripname "$wl"'-rpath,,' '' "$arg"
++	    dir=$func_stripname_result
++	    func_add2xrpath "$dir"
++	  elif expr "x$arg" : '^x'"$wl"'-rpath$' >/dev/null ; then
++	    func_stripname "$wl" '' "$1"
++	    dir=$func_stripname_result
++	    if ! expr "x$1" : '^x'"$wl" >/dev/null \
++	    || ! test -d "$dir" ; then
++	    func_fatal_error "$wl"'-rpath must be followed by '"$wl"'-escaped directory'
++	    fi
++	    shift
++	    func_add2xrpath "$dir"
++	    continue
++	  else
++	    func_stripname "$wl" '' "$arg"
++	    func_append new_inherited_linker_flags " -Wl,$func_stripname_result"
++	  fi
++	  continue
++	elif expr "x$arg" : '^x-Wl,-rpath,' >/dev/null ; then
++	  func_stripname '-Wl,-rpath,' '' "$arg"
++	  dir=$func_stripname_result
++	  func_add2xrpath "$dir"
++	  continue
++	elif expr "x$arg" : '^x-Wl,-rpath$' >/dev/null ; then
++	  func_stripname '-Wl,' '' "$1"
++	  dir=$func_stripname_result
++	  if ! expr "x$1" : '^x-Wl,' >/dev/null \
++	    || ! test -d "$dir" ; then
++	    func_fatal_error '-Wl,-rpath must be followed by -Wl-escaped directory'
++	  fi
++	  func_quote_for_eval "$1"
++	  func_append libtool_args " $func_quote_for_eval_result"
++	  shift
++	  func_add2xrpath "$dir"
++	  continue
++	fi
+ 	func_stripname '-Wl,' '' "$arg"
+ 	args=$func_stripname_result
+ 	arg=
+-	save_ifs="$IFS"; IFS=','
++	save_ifs=$IFS; IFS=,
+ 	for flag in $args; do
+-	  IFS="$save_ifs"
++	  IFS=$save_ifs
+           func_quote_for_eval "$flag"
+ 	  func_append arg " $wl$func_quote_for_eval_result"
+ 	  func_append compiler_flags " $wl$func_quote_for_eval_result"
+ 	  func_append linker_flags " $func_quote_for_eval_result"
+ 	done
+-	IFS="$save_ifs"
++	IFS=$save_ifs
+ 	func_stripname ' ' '' "$arg"
+ 	arg=$func_stripname_result
+ 	;;
+@@ -9515,6 +9562,10 @@
+ 	  *) func_append new_libs " $deplib" ;;
+ 	  esac
+ 	  ;;
++	-Wl,*)
++	  func_stripname -Wl, '' "$deplib"
++	  func_append new_libs " $wl$func_stripname_result"
++	  ;;
+ 	*) func_append new_libs " $deplib" ;;
+ 	esac
+       done
+@@ -10247,6 +10298,10 @@
+ 	  *) func_append new_libs " $deplib" ;;
+ 	  esac
+ 	  ;;
++	-Wl,*)
++	  func_stripname -Wl, '' "$deplib"
++	  func_append new_libs " $wl$func_stripname_result"
++	  ;;
+ 	*) func_append new_libs " $deplib" ;;
+ 	esac
+       done
diff --git a/contrib/100nagfor-libtool-patch/nagfor-libtool-2.4.6.patch b/contrib/00nagfor-libtool-patch/nagfor-libtool-2.4.6.patch
similarity index 100%
rename from contrib/100nagfor-libtool-patch/nagfor-libtool-2.4.6.patch
rename to contrib/00nagfor-libtool-patch/nagfor-libtool-2.4.6.patch
diff --git a/contrib/00nagfor-libtool-patch/nagfor-libtool.patch b/contrib/00nagfor-libtool-patch/nagfor-libtool.patch
new file mode 100644
index 0000000000000000000000000000000000000000..9677b1666963501864636f115774ed319fff844c
--- /dev/null
+++ b/contrib/00nagfor-libtool-patch/nagfor-libtool.patch
@@ -0,0 +1,112 @@
+--- a/config/ltmain.sh	2012-06-12 00:20:43.000000000 +0200
++++ b/config/ltmain.sh	2014-08-19 16:34:48.161235251 +0200
+@@ -3229,6 +3229,25 @@
+ 
+ test "$opt_mode" = install && func_mode_install ${1+"$@"}
+ 
++func_add2xrpath ()
++{
++  dir="$1"
++  # We need an absolute path.
++  case $dir in
++    [\\/]* | [A-Za-z]:[\\/]*) ;;
++    =*)
++    func_stripname '=' '' "$dir"
++    dir=$lt_sysroot$func_stripname_result
++      ;;
++    *)
++      func_fatal_error "only absolute run-paths are allowed"
++      ;;
++  esac
++  case "$xrpath " in
++    *" $dir "*) ;;
++    *) func_append xrpath " $dir" ;;
++  esac
++}
+ 
+ # func_generate_dlsyms outputname originator pic_p
+ # Extract symbols from dlprefiles and create ${outputname}S.o with
+@@ -5727,20 +5746,7 @@
+ 	func_stripname '-R' '' "$arg"
+ 	dir=$func_stripname_result
+ 	# We need an absolute path.
+-	case $dir in
+-	[\\/]* | [A-Za-z]:[\\/]*) ;;
+-	=*)
+-	  func_stripname '=' '' "$dir"
+-	  dir=$lt_sysroot$func_stripname_result
+-	  ;;
+-	*)
+-	  func_fatal_error "only absolute run-paths are allowed"
+-	  ;;
+-	esac
+-	case "$xrpath " in
+-	*" $dir "*) ;;
+-	*) func_append xrpath " $dir" ;;
+-	esac
++	func_add2xrpath "$dir"
+ 	continue
+ 	;;
+ 
+@@ -5801,18 +5807,58 @@
+ 	;;
+ 
+       -Wl,*)
++	wlprefix=`expr x"$wl" : '.*' - 1`
++	wlprefix=`expr x"$arg" : 'x\(.\{'"$wlprefix"'\}\)'`
++	if test x"$wlprefix" = x"$wl" -a x"$wl" != x"-Wl,"; then
++	  func_append compiler_flags " $arg"
++	  func_append compile_command " $arg"
++	  func_append finalize_command " $arg"
++	  if expr "x$arg" : '^x'"$wl"'-rpath,,' >/dev/null ; then
++           func_stripname "$wl"'-rpath,,' '' "$arg"
++	    dir=$func_stripname_result
++	    func_add2xrpath "$dir"
++	  elif expr "x$arg" : '^x'"$wl"'-rpath$' >/dev/null ; then
++	    func_stripname "$wl" '' "$1"
++	    dir=$func_stripname_result
++	    if ! expr "x$1" : '^x'"$wl" >/dev/null \
++	    || ! test -d "$dir" ; then
++	    func_fatal_error "$wl"'-rpath must be followed by '"$wl"'-escaped directory'
++           fi
++	    shift
++	    func_add2xrpath "$dir"
++	    continue
++	  else
++	    func_append new_inherited_linker_flags " $arg"
++	  fi
++	  continue
++	elif expr "x$arg" : '^x-Wl,-rpath,' >/dev/null ; then
++	  func_stripname '-Wl,-rpath,' '' "$arg"
++	  dir=$func_stripname_result
++	  func_add2xrpath "$dir"
++	  continue
++	elif expr "x$arg" : '^x-Wl,-rpath$' >/dev/null ; then
++	  func_stripname '-Wl,' '' "$1"
++	  dir=$func_stripname_result
++	  if ! expr "x$1" : '^x-Wl,' >/dev/null \
++	    || ! test -d "$dir" ; then
++	    func_fatal_error '-Wl,-rpath must be followed by -Wl-escaped directory'
++         fi
++	  shift
++	  func_add2xrpath "$dir"
++	  continue
++	fi
+ 	func_stripname '-Wl,' '' "$arg"
+ 	args=$func_stripname_result
+ 	arg=
+-	save_ifs="$IFS"; IFS=','
++	save_ifs=$IFS; IFS=,
+ 	for flag in $args; do
+-	  IFS="$save_ifs"
++	  IFS=$save_ifs
+           func_quote_for_eval "$flag"
+ 	  func_append arg " $wl$func_quote_for_eval_result"
+ 	  func_append compiler_flags " $wl$func_quote_for_eval_result"
+ 	  func_append linker_flags " $func_quote_for_eval_result"
+ 	done
+-	IFS="$save_ifs"
++	IFS=$save_ifs
+ 	func_stripname ' ' '' "$arg"
+ 	arg=$func_stripname_result
+ 	;;
diff --git a/contrib/101aix-deplib-rpath-patch/README b/contrib/01aix-deplib-rpath-patch/README
similarity index 100%
rename from contrib/101aix-deplib-rpath-patch/README
rename to contrib/01aix-deplib-rpath-patch/README
diff --git a/contrib/101aix-deplib-rpath-patch/aix-deplib-libtool.patch b/contrib/01aix-deplib-rpath-patch/aix-deplib-libtool.patch
similarity index 100%
rename from contrib/101aix-deplib-rpath-patch/aix-deplib-libtool.patch
rename to contrib/01aix-deplib-rpath-patch/aix-deplib-libtool.patch
diff --git a/contrib/02nagfor53-shared-patch/README.txt b/contrib/02nagfor53-shared-patch/README.txt
new file mode 100644
index 0000000000000000000000000000000000000000..4fb7b1a1fd1b62ea33b1a70a4e178471c32e1a81
--- /dev/null
+++ b/contrib/02nagfor53-shared-patch/README.txt
@@ -0,0 +1,3 @@
+This patch changes NAG Fortran (nagfor) compilations of shared
+libraries to correctly pass the -shared flag to the underlying
+compiler.
diff --git a/contrib/02nagfor53-shared-patch/nagfor53-shared.patch b/contrib/02nagfor53-shared-patch/nagfor53-shared.patch
new file mode 100644
index 0000000000000000000000000000000000000000..fbf69f01f1db14b4435df119763bc4c8fd7f7366
--- /dev/null
+++ b/contrib/02nagfor53-shared-patch/nagfor53-shared.patch
@@ -0,0 +1,11 @@
+--- a/m4/libtool.m4	2013-08-01 11:23:32.749610298 +0200
++++ b/m4/libtool.m4	2014-04-04 15:30:02.855209645 +0200
+@@ -4817,6 +4817,8 @@
+ 	lf95*)				# Lahey Fortran 8.1
+ 	  _LT_TAGVAR(whole_archive_flag_spec, $1)=
+ 	  tmp_sharedflag='--shared' ;;
++        nagfor*)                        # NAGFOR 5.3
++          tmp_sharedflag='-Wl,-shared' ;;
+ 	xl[[cC]]* | bgxl[[cC]]* | mpixl[[cC]]*) # IBM XL C 8.0 on PPC (deal with xlf below)
+ 	  tmp_sharedflag='-qmkshrobj'
+ 	  tmp_addflag= ;;
diff --git a/contrib/103ltmain-ld-groups-patch/README b/contrib/03ltmain-ld-groups-patch/README
similarity index 100%
rename from contrib/103ltmain-ld-groups-patch/README
rename to contrib/03ltmain-ld-groups-patch/README
diff --git a/contrib/03ltmain-ld-groups-patch/ltmain-ld-groups-libtool-2.4.2.patch b/contrib/03ltmain-ld-groups-patch/ltmain-ld-groups-libtool-2.4.2.patch
new file mode 100644
index 0000000000000000000000000000000000000000..c319cb66497fe06022d626571fc39139cc2bc12f
--- /dev/null
+++ b/contrib/03ltmain-ld-groups-patch/ltmain-ld-groups-libtool-2.4.2.patch
@@ -0,0 +1,30 @@
+--- a/config/ltmain.sh	2016-10-27 18:58:49.860787638 +0200
++++ b/config/ltmain.sh	2016-10-27 18:59:21.497411984 +0200
+@@ -5806,6 +5806,11 @@
+ 	arg=$func_stripname_result
+ 	;;
+ 
++      -Wl,--start-group|-Wl,--end-group|-Wl,-\(|-Wl,-\))
++	func_append deplibs " $arg"
++	continue
++	;;
++
+       -Wl,*)
+ 	wlprefix=`expr x"$wl" : '.*' - 1`
+ 	wlprefix=`expr x"$arg" : 'x\(.\{'"$wlprefix"'\}\)'`
+@@ -6434,6 +6439,15 @@
+ 	  alldeplibs=yes
+ 	  continue
+ 	  ;;
++	 -Wl,--start-group|-Wl,--end-group|-Wl,-\(|-Wl,-\))
++	  if test "$linkmode,$pass" = "prog,link"; then
++	    compile_deplibs="$deplib $compile_deplibs"
++	    finalize_deplibs="$deplib $finalize_deplibs"
++	  else
++	    deplibs="$deplib $deplibs"
++	  fi
++	  continue
++	  ;;
+ 	esac # case $deplib
+ 
+ 	if test "$found" = yes || test -f "$lib"; then :
diff --git a/contrib/103ltmain-ld-groups-patch/ltmain-ld-groups-libtool-2.4.6.patch b/contrib/03ltmain-ld-groups-patch/ltmain-ld-groups-libtool-2.4.6.patch
similarity index 100%
rename from contrib/103ltmain-ld-groups-patch/ltmain-ld-groups-libtool-2.4.6.patch
rename to contrib/03ltmain-ld-groups-patch/ltmain-ld-groups-libtool-2.4.6.patch
diff --git a/contrib/104ltmain-xlinker-patch/README b/contrib/04ltmain-xlinker-patch/README
similarity index 100%
rename from contrib/104ltmain-xlinker-patch/README
rename to contrib/04ltmain-xlinker-patch/README
diff --git a/contrib/104ltmain-xlinker-patch/ltmain-xlinker-patch.patch b/contrib/04ltmain-xlinker-patch/ltmain-xlinker-patch.patch
similarity index 100%
rename from contrib/104ltmain-xlinker-patch/ltmain-xlinker-patch.patch
rename to contrib/04ltmain-xlinker-patch/ltmain-xlinker-patch.patch
diff --git a/contrib/105macos-nagfor-patch/macos-nagfor.patch b/contrib/05macos-nagfor-patch/macos-nagfor.patch
similarity index 100%
rename from contrib/105macos-nagfor-patch/macos-nagfor.patch
rename to contrib/05macos-nagfor-patch/macos-nagfor.patch
diff --git a/contrib/106ltmain_nag_pthread-patch/ltmain_nag_pthread.patch b/contrib/06ltmain_nag_pthread-patch/ltmain_nag_pthread.patch
similarity index 100%
rename from contrib/106ltmain_nag_pthread-patch/ltmain_nag_pthread.patch
rename to contrib/06ltmain_nag_pthread-patch/ltmain_nag_pthread.patch
diff --git a/contrib/107ltmain-early-xcompile-patch/README b/contrib/07ltmain-early-xcompile-patch/README
similarity index 100%
rename from contrib/107ltmain-early-xcompile-patch/README
rename to contrib/07ltmain-early-xcompile-patch/README
diff --git a/contrib/107ltmain-early-xcompile-patch/ltmain-early-xcompile-libtool-2.4.6.patch b/contrib/07ltmain-early-xcompile-patch/ltmain-early-xcompile-libtool-2.4.6.patch
similarity index 100%
rename from contrib/107ltmain-early-xcompile-patch/ltmain-early-xcompile-libtool-2.4.6.patch
rename to contrib/07ltmain-early-xcompile-patch/ltmain-early-xcompile-libtool-2.4.6.patch
diff --git a/contrib/108ltmain-parallel-printf-patch/ltmain-parallel-printf.patch b/contrib/08ltmain-parallel-printf-patch/ltmain-parallel-printf.patch
similarity index 100%
rename from contrib/108ltmain-parallel-printf-patch/ltmain-parallel-printf.patch
rename to contrib/08ltmain-parallel-printf-patch/ltmain-parallel-printf.patch
diff --git a/contrib/000debian-no-overlink-patch/README.txt b/contrib/09debian-no-overlink-patch/README.txt
similarity index 100%
rename from contrib/000debian-no-overlink-patch/README.txt
rename to contrib/09debian-no-overlink-patch/README.txt
diff --git a/contrib/000debian-no-overlink-patch/debian-no-overlink.patch b/contrib/09debian-no-overlink-patch/debian-no-overlink.libtool.m4.patch
similarity index 51%
rename from contrib/000debian-no-overlink-patch/debian-no-overlink.patch
rename to contrib/09debian-no-overlink-patch/debian-no-overlink.libtool.m4.patch
index 405cfb5846ec4761069dfa3d99e28e35931290c1..080e4a21a3e94ba090fc2cbd33e07b55ee7fc208 100644
--- a/contrib/000debian-no-overlink-patch/debian-no-overlink.patch
+++ b/contrib/09debian-no-overlink-patch/debian-no-overlink.libtool.m4.patch
@@ -1,47 +1,3 @@
---- a/config/ltmain.sh
-+++ b/config/ltmain.sh
-@@ -7568,7 +7568,10 @@ func_mode_link ()
- 	case $pass in
- 	dlopen) libs=$dlfiles ;;
- 	dlpreopen) libs=$dlprefiles ;;
--	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
-+	link)
-+	  libs="$deplibs %DEPLIBS%"
-+	  test "X$link_all_deplibs" != Xno && libs="$libs $dependency_libs"
-+	  ;;
- 	esac
-       fi
-       if test lib,dlpreopen = "$linkmode,$pass"; then
-@@ -7887,19 +7890,19 @@ func_mode_link ()
- 	    # It is a libtool convenience library, so add in its objects.
- 	    func_append convenience " $ladir/$objdir/$old_library"
- 	    func_append old_convenience " $ladir/$objdir/$old_library"
-+	    tmp_libs=
-+	    for deplib in $dependency_libs; do
-+	      deplibs="$deplib $deplibs"
-+	      if $opt_preserve_dup_deps; then
-+		case "$tmp_libs " in
-+		*" $deplib "*) func_append specialdeplibs " $deplib" ;;
-+		esac
-+	      fi
-+	      func_append tmp_libs " $deplib"
-+	    done
- 	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
- 	    func_fatal_error "'$lib' is not a convenience library"
- 	  fi
--	  tmp_libs=
--	  for deplib in $dependency_libs; do
--	    deplibs="$deplib $deplibs"
--	    if $opt_preserve_dup_deps; then
--	      case "$tmp_libs " in
--	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
--	      esac
--	    fi
--	    func_append tmp_libs " $deplib"
--	  done
- 	  continue
- 	fi # $pass = conv
- 
 --- a/m4/libtool.m4
 +++ b/m4/libtool.m4
 @@ -4936,6 +4936,9 @@ m4_if([$1], [CXX], [
diff --git a/contrib/09debian-no-overlink-patch/debian-no-overlink.patch b/contrib/09debian-no-overlink-patch/debian-no-overlink.patch
new file mode 100644
index 0000000000000000000000000000000000000000..1ae35c1ae8654514dbcfe8f90e5fbd5cc3145ac2
--- /dev/null
+++ b/contrib/09debian-no-overlink-patch/debian-no-overlink.patch
@@ -0,0 +1,44 @@
+--- a/config/ltmain.sh
++++ b/config/ltmain.sh
+@@ -7646,7 +7646,10 @@ func_mode_link ()
+ 	case $pass in
+ 	dlopen) libs=$dlfiles ;;
+ 	dlpreopen) libs=$dlprefiles ;;
+-	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
++	link)
++	  libs="$deplibs %DEPLIBS%"
++	  test "X$link_all_deplibs" != Xno && libs="$libs $dependency_libs"
++	  ;;
+ 	esac
+       fi
+       if test lib,dlpreopen = "$linkmode,$pass"; then
+@@ -7980,19 +7983,19 @@ func_mode_link ()
+ 	    # It is a libtool convenience library, so add in its objects.
+ 	    func_append convenience " $ladir/$objdir/$old_library"
+ 	    func_append old_convenience " $ladir/$objdir/$old_library"
++	    tmp_libs=
++	    for deplib in $dependency_libs; do
++	      deplibs="$deplib $deplibs"
++	      if $opt_preserve_dup_deps; then
++		case "$tmp_libs " in
++		*" $deplib "*) func_append specialdeplibs " $deplib" ;;
++		esac
++	      fi
++	      func_append tmp_libs " $deplib"
++	    done
+ 	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
+ 	    func_fatal_error "'$lib' is not a convenience library"
+ 	  fi
+-	  tmp_libs=
+-	  for deplib in $dependency_libs; do
+-	    deplibs="$deplib $deplibs"
+-	    if $opt_preserve_dup_deps; then
+-	      case "$tmp_libs " in
+-	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
+-	      esac
+-	    fi
+-	    func_append tmp_libs " $deplib"
+-	  done
+ 	  continue
+ 	fi # $pass = conv
+ 
diff --git a/scripts/reconfigure b/scripts/reconfigure
new file mode 100755
index 0000000000000000000000000000000000000000..664d3def76f910bb0f02b3f4ef2e6bf2c43b1f5e
--- /dev/null
+++ b/scripts/reconfigure
@@ -0,0 +1,49 @@
+#! /bin/bash
+#
+# This script contains all the necessary steps to recreate the
+# autotools files to build CDI.
+#
+libtoolize --force --copy
+libtoolversion=$(libtoolize --version \
+                      | sed -e 's/^libtoolize \(([^)]*) \)\{0,1\}\([0-9.]*\)/\2/;q')
+declare -a patches
+case "$libtoolversion" in
+  2.4.6)
+    patches=(contrib/00nagfor-libtool-patch/nagfor-libtool-2.4.6.patch \
+      contrib/01aix-deplib-rpath-patch/aix-deplib-libtool.patch \
+      contrib/03ltmain-ld-groups-patch/ltmain-ld-groups-libtool-2.4.6.patch \
+      contrib/04ltmain-xlinker-patch/ltmain-xlinker-patch.patch \
+      contrib/05macos-nagfor-patch/macos-nagfor.patch \
+      contrib/06ltmain_nag_pthread-patch/ltmain_nag_pthread.patch \
+      contrib/07ltmain-early-xcompile-patch/ltmain-early-xcompile-libtool-2.4.6.patch \
+      contrib/08ltmain-parallel-printf-patch/ltmain-parallel-printf.patch \
+      contrib/09debian-no-overlink-patch/debian-no-overlink.patch)
+    ;;
+  2.4.2)
+    patches=(contrib/00nagfor-libtool-patch/nagfor-libtool.patch \
+      contrib/01aix-deplib-rpath-patch/aix-deplib-libtool.patch \
+      contrib/02nagfor53-shared-patch/nagfor53-shared.patch \
+      contrib/03ltmain-ld-groups-patch/ltmain-ld-groups-libtool-2.4.2.patch \
+      contrib/04ltmain-xlinker-patch/ltmain-xlinker-patch.patch \
+      contrib/05macos-nagfor-patch/macos-nagfor.patch \
+      contrib/06ltmain_nag_pthread-patch/ltmain_nag_pthread.patch)
+    ;;
+esac
+for patch in "${patches[@]}"; do
+  echo "applying $patch" >&2
+  patch -p1 <$patch
+done
+autoreconf -i
+find . -name Makefile.in -print0 | xargs -0 sed -i -e 's/[	 ][	 ]*$//'
+\rm -f config/ltmain.sh.orig m4/libtool.m4.orig
+wget -o /dev/null -O config/config.guess \
+     'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD'
+wget -o /dev/null -O config/config.sub \
+     'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD'
+
+#
+# to test if this succeeded, one can run
+# diff -x autom4te.cache -x .git -ur orig/libcdi new/libcdi 2>&1 |less
+# if a known good checkout is at orig/libcdi and a newly reconfigured
+# tree is at new/libcdi
+#
diff --git a/scripts/reconfigure-mistral b/scripts/reconfigure-mistral
new file mode 100755
index 0000000000000000000000000000000000000000..abd40e2d3033926a61ff4e8d22741ff968d718ba
--- /dev/null
+++ b/scripts/reconfigure-mistral
@@ -0,0 +1,10 @@
+#! /bin/bash
+. /sw/rhel6-x64/etc/profile.mistral
+module load autoconf/2.69 automake/1.14.1 libtool/2.4.6
+autoconf --version
+automake --version
+libtoolize --version
+scripts/reconfigure
+if [ -x scripts/recreate-testsuite.sh ]; then
+  exec scripts/recreate-testsuite.sh
+fi