Cleanup discrepancies between r5178 and r5251.  This version should work well now.

git-svn-id: svn+ssh://svn.code.sf.net/p/mingw-w64/code/trunk@5258 4407c894-4637-0410-b4f5-ada5f102cad1
diff --git a/mingw-w64-headers/configure b/mingw-w64-headers/configure
index 50694aa..a0dae24 100755
--- a/mingw-w64-headers/configure
+++ b/mingw-w64-headers/configure
@@ -606,7 +606,6 @@
 HAVE_WIDL_FALSE
 HAVE_WIDL_TRUE
 WIDL
-widl_prog
 SED
 host_os
 host_vendor
@@ -625,6 +624,7 @@
 am__leading_dot
 SET_MAKE
 AWK
+mkdir_p
 MKDIR_P
 INSTALL_STRIP_PROGRAM
 STRIP
@@ -1323,7 +1323,8 @@
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
   --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
-  --with-widl=PATH        use widl to update idl-based headers
+  --with-widl=PATH        use widl to update idl-based headers. Optionally
+                          search for a compatible widl in PATH
 
 Report bugs to <mingw-w64-public@lists.sourceforge.net>.
 _ACEOF
@@ -2261,6 +2262,12 @@
 
 MAKEINFO=${MAKEINFO-"${am_missing_run}makeinfo"}
 
+# For better backward compatibility.  To be removed once Automake 1.9.x
+# dies out for good.  For more background, see:
+# <http://lists.gnu.org/archive/html/automake/2012-07/msg00001.html>
+# <http://lists.gnu.org/archive/html/automake/2012-07/msg00014.html>
+mkdir_p='$(MKDIR_P)'
+
 # We need awk for the "check" target.  The system "awk" is bad on
 # some platforms.
 # Always define AMTAR for backward compatibility.  Yes, it's still used
@@ -2440,6 +2447,12 @@
   rm -f conftest.sed
 
 
+# Search for a usable widl.  If PATH is given, search there.  Otherwise, search
+# in $PATH.  In all cases, search for a canonicalized name first ($host-widl),
+# followed by a non-canonicalized name (widl).  If these fail, error out.
+# NB: $host from this perspective is the same as $target while building widl.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to rebuild headers with widl" >&5
+$as_echo_n "checking whether to rebuild headers with widl... " >&6; }
 
 # Check whether --with-widl was given.
 if test "${with_widl+set}" = set; then :
@@ -2448,35 +2461,38 @@
   with_widl=no
 fi
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_widl" >&5
+$as_echo "$with_widl" >&6; }
 
+if test "x$with_widl" = xyes; then :
+  with_widl="$PATH"
+fi
 if test "x$with_widl" = xno; then :
 
 else
 
-  if test "x$with_widl" = xyes; then :
-
-    for ac_prog in $host-widl widl
+  for ac_prog in $host-widl widl
 do
   # Extract the first word of "$ac_prog", so it can be a program name with args.
 set dummy $ac_prog; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_widl_prog+:} false; then :
+if ${ac_cv_path_WIDL+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $widl_prog in
+  case $WIDL in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_widl_prog="$widl_prog" # Let the user override the test with a path.
+  ac_cv_path_WIDL="$WIDL" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
+for as_dir in $with_widl
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
   if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-    ac_cv_path_widl_prog="$as_dir/$ac_word$ac_exec_ext"
+    ac_cv_path_WIDL="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -2487,48 +2503,25 @@
   ;;
 esac
 fi
-widl_prog=$ac_cv_path_widl_prog
-if test -n "$widl_prog"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $widl_prog" >&5
-$as_echo "$widl_prog" >&6; }
+WIDL=$ac_cv_path_WIDL
+if test -n "$WIDL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $WIDL" >&5
+$as_echo "$WIDL" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-  test -n "$widl_prog" && break
+  test -n "$WIDL" && break
 done
 
-    if ${widl_prog:+false} :; then :
-
-      as_fn_error $? "--with-widl is specified, but widl installation could not be found." "$LINENO" 5
-fi
-
-else
-
-    if { ac_try='$with_widl -V'
-  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; }; then :
-  widl_prog=$with_widl
-else
-  as_fn_error $? "Specified widl command is not valid" "$LINENO" 5
-fi
-
+  if ${WIDL:+false} :; then :
+  as_fn_error $? "--with-widl is specified, but widl installation could not be found." "$LINENO" 5
 fi
 fi
 
-if ${widl_prog:+false} :; then :
-
-else
-  WIDL="$widl_prog"
-fi
-
-
- if test -n "$widl_prog"; then
+ if ${WIDL+:} false; then
   HAVE_WIDL_TRUE=
   HAVE_WIDL_FALSE='#'
 else
diff --git a/mingw-w64-headers/configure.ac b/mingw-w64-headers/configure.ac
index b294e5a..28871f0 100644
--- a/mingw-w64-headers/configure.ac
+++ b/mingw-w64-headers/configure.ac
@@ -15,27 +15,24 @@
 # Checks for programs.
 AC_PROG_SED
 
+# Search for a usable widl.  If PATH is given, search there.  Otherwise, search
+# in $PATH.  In all cases, search for a canonicalized name first ($host-widl),
+# followed by a non-canonicalized name (widl).  If these fail, error out.
+# NB: $host from this perspective is the same as $target while building widl.
+AC_MSG_CHECKING([whether to rebuild headers with widl])
 AC_ARG_WITH([widl],
   AS_HELP_STRING([--with-widl=PATH],
-    [use widl to update idl-based headers]),
+    [use widl to update idl-based headers.  Optionally search for a compatible widl in PATH]),
   [],
-  [with_widl=no])
+  [AS_VAR_SET([with_widl],[no])])
+AC_MSG_RESULT([$with_widl])
 
+AS_VAR_IF([with_widl],[yes],[AS_VAR_SET([with_widl],["$PATH"])])
 AS_VAR_IF([with_widl],[no],[],[
-  AS_VAR_IF([with_widl],[yes],[
-    AC_PATH_PROGS([widl_prog], [$host-widl widl])
-    AS_VAR_IF([widl_prog],[],[
-      AC_MSG_ERROR([--with-widl is specified, but widl installation could not be found.])])
-  ],[
-    AS_IF(AC_TRY_COMMAND([$with_widl -V]),
-      [widl_prog=$with_widl],
-      [AC_MSG_ERROR([Specified widl command is not valid])])]
-  )])
+  AC_PATH_PROGS([WIDL], [$host-widl widl], [], [$with_widl])
+  AS_VAR_IF([WIDL],[],[AC_MSG_ERROR([--with-widl is specified, but widl installation could not be found.])])])
 
-AS_VAR_IF([widl_prog],[],[],[WIDL="$widl_prog"])
-
-AC_SUBST([WIDL])
-AM_CONDITIONAL([HAVE_WIDL],[test -n "$widl_prog"])
+AM_CONDITIONAL([HAVE_WIDL],[AS_VAR_TEST_SET([WIDL])])
 
 # Checks for libraries.