Some of the *_FOR_TARGET environment variables (e.g. CC_FOR_TARGET) were 
already preserved because they use the NCN_STRICT_CHECK_TARGET_TOOLS macro 
directly. Other *_FOR_TARGET environment variables (e.g. AS_FOR_TARGET) use the 
ACX_CHECK_INSTALLED_TARGET_TOOL macro, which falls back to 
NCN_STRICT_CHECK_TARGET_TOOLS but overwrote the environment variable in some 
cases before that. E.g. in the case `$build != $host`, the environment variable 
was not preserved.

With this patch, each of the *_FOR_TARGET environment variables and their 
unsuffixed (“for host”) correspondents are handled consistently in the sense 
that a non-empty value takes precedence over:

- cached values
- values inferred by checking for a suitable program in PATH
- tools in the directory passed to --with-build-time-tools (applies only to 
*_FOR_TARGET)

Signed-off-by: Manuel Jacob <[email protected]>
---
 config/acx.m4 |  5 ++++
 configure     | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+)

diff --git a/config/acx.m4 b/config/acx.m4
index 7304d7b82ad..91083126c9d 100644
--- a/config/acx.m4
+++ b/config/acx.m4
@@ -340,6 +340,11 @@ rm conftest.c
 AC_DEFUN([ACX_CHECK_INSTALLED_TARGET_TOOL], [
 AC_REQUIRE([ACX_TOOL_DIRS])
 AC_REQUIRE([ACX_HAVE_GCC_FOR_TARGET])
+if test -n "[$]$1"; then
+  ac_cv_path_$1=[$]$1
+elif test -n "$ac_cv_path_$1"; then
+  $1=$ac_cv_path_$1
+fi
 if test -z "$ac_cv_path_$1" ; then
   if test -n "$with_build_time_tools"; then
     AC_MSG_CHECKING([for $2 in $with_build_time_tools])
diff --git a/configure b/configure
index 083e8823d2b..b9a036adb60 100755
--- a/configure
+++ b/configure
@@ -16502,6 +16502,11 @@ rm conftest.c
 
 
 
+if test -n "$AR_FOR_TARGET"; then
+  ac_cv_path_AR_FOR_TARGET=$AR_FOR_TARGET
+elif test -n "$ac_cv_path_AR_FOR_TARGET"; then
+  AR_FOR_TARGET=$ac_cv_path_AR_FOR_TARGET
+fi
 if test -z "$ac_cv_path_AR_FOR_TARGET" ; then
   if test -n "$with_build_time_tools"; then
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ar in 
$with_build_time_tools" >&5
@@ -16732,6 +16737,11 @@ fi
 
 
 
+if test -n "$AS_FOR_TARGET"; then
+  ac_cv_path_AS_FOR_TARGET=$AS_FOR_TARGET
+elif test -n "$ac_cv_path_AS_FOR_TARGET"; then
+  AS_FOR_TARGET=$ac_cv_path_AS_FOR_TARGET
+fi
 if test -z "$ac_cv_path_AS_FOR_TARGET" ; then
   if test -n "$with_build_time_tools"; then
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for as in 
$with_build_time_tools" >&5
@@ -16962,6 +16972,11 @@ fi
 
 
 
+if test -n "$DLLTOOL_FOR_TARGET"; then
+  ac_cv_path_DLLTOOL_FOR_TARGET=$DLLTOOL_FOR_TARGET
+elif test -n "$ac_cv_path_DLLTOOL_FOR_TARGET"; then
+  DLLTOOL_FOR_TARGET=$ac_cv_path_DLLTOOL_FOR_TARGET
+fi
 if test -z "$ac_cv_path_DLLTOOL_FOR_TARGET" ; then
   if test -n "$with_build_time_tools"; then
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlltool in 
$with_build_time_tools" >&5
@@ -17192,6 +17207,11 @@ fi
 
 
 
+if test -n "$DSYMUTIL_FOR_TARGET"; then
+  ac_cv_path_DSYMUTIL_FOR_TARGET=$DSYMUTIL_FOR_TARGET
+elif test -n "$ac_cv_path_DSYMUTIL_FOR_TARGET"; then
+  DSYMUTIL_FOR_TARGET=$ac_cv_path_DSYMUTIL_FOR_TARGET
+fi
 if test -z "$ac_cv_path_DSYMUTIL_FOR_TARGET" ; then
   if test -n "$with_build_time_tools"; then
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dsymutil in 
$with_build_time_tools" >&5
@@ -17422,6 +17442,11 @@ fi
 
 
 
+if test -n "$LD_FOR_TARGET"; then
+  ac_cv_path_LD_FOR_TARGET=$LD_FOR_TARGET
+elif test -n "$ac_cv_path_LD_FOR_TARGET"; then
+  LD_FOR_TARGET=$ac_cv_path_LD_FOR_TARGET
+fi
 if test -z "$ac_cv_path_LD_FOR_TARGET" ; then
   if test -n "$with_build_time_tools"; then
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld in 
$with_build_time_tools" >&5
@@ -17652,6 +17677,11 @@ fi
 
 
 
+if test -n "$LIPO_FOR_TARGET"; then
+  ac_cv_path_LIPO_FOR_TARGET=$LIPO_FOR_TARGET
+elif test -n "$ac_cv_path_LIPO_FOR_TARGET"; then
+  LIPO_FOR_TARGET=$ac_cv_path_LIPO_FOR_TARGET
+fi
 if test -z "$ac_cv_path_LIPO_FOR_TARGET" ; then
   if test -n "$with_build_time_tools"; then
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for lipo in 
$with_build_time_tools" >&5
@@ -17882,6 +17912,11 @@ fi
 
 
 
+if test -n "$NM_FOR_TARGET"; then
+  ac_cv_path_NM_FOR_TARGET=$NM_FOR_TARGET
+elif test -n "$ac_cv_path_NM_FOR_TARGET"; then
+  NM_FOR_TARGET=$ac_cv_path_NM_FOR_TARGET
+fi
 if test -z "$ac_cv_path_NM_FOR_TARGET" ; then
   if test -n "$with_build_time_tools"; then
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for nm in 
$with_build_time_tools" >&5
@@ -18112,6 +18147,11 @@ fi
 
 
 
+if test -n "$OBJCOPY_FOR_TARGET"; then
+  ac_cv_path_OBJCOPY_FOR_TARGET=$OBJCOPY_FOR_TARGET
+elif test -n "$ac_cv_path_OBJCOPY_FOR_TARGET"; then
+  OBJCOPY_FOR_TARGET=$ac_cv_path_OBJCOPY_FOR_TARGET
+fi
 if test -z "$ac_cv_path_OBJCOPY_FOR_TARGET" ; then
   if test -n "$with_build_time_tools"; then
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for objcopy in 
$with_build_time_tools" >&5
@@ -18342,6 +18382,11 @@ fi
 
 
 
+if test -n "$OBJDUMP_FOR_TARGET"; then
+  ac_cv_path_OBJDUMP_FOR_TARGET=$OBJDUMP_FOR_TARGET
+elif test -n "$ac_cv_path_OBJDUMP_FOR_TARGET"; then
+  OBJDUMP_FOR_TARGET=$ac_cv_path_OBJDUMP_FOR_TARGET
+fi
 if test -z "$ac_cv_path_OBJDUMP_FOR_TARGET" ; then
   if test -n "$with_build_time_tools"; then
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for objdump in 
$with_build_time_tools" >&5
@@ -18572,6 +18617,11 @@ fi
 
 
 
+if test -n "$OTOOL_FOR_TARGET"; then
+  ac_cv_path_OTOOL_FOR_TARGET=$OTOOL_FOR_TARGET
+elif test -n "$ac_cv_path_OTOOL_FOR_TARGET"; then
+  OTOOL_FOR_TARGET=$ac_cv_path_OTOOL_FOR_TARGET
+fi
 if test -z "$ac_cv_path_OTOOL_FOR_TARGET" ; then
   if test -n "$with_build_time_tools"; then
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for otool in 
$with_build_time_tools" >&5
@@ -18802,6 +18852,11 @@ fi
 
 
 
+if test -n "$RANLIB_FOR_TARGET"; then
+  ac_cv_path_RANLIB_FOR_TARGET=$RANLIB_FOR_TARGET
+elif test -n "$ac_cv_path_RANLIB_FOR_TARGET"; then
+  RANLIB_FOR_TARGET=$ac_cv_path_RANLIB_FOR_TARGET
+fi
 if test -z "$ac_cv_path_RANLIB_FOR_TARGET" ; then
   if test -n "$with_build_time_tools"; then
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ranlib in 
$with_build_time_tools" >&5
@@ -19032,6 +19087,11 @@ fi
 
 
 
+if test -n "$READELF_FOR_TARGET"; then
+  ac_cv_path_READELF_FOR_TARGET=$READELF_FOR_TARGET
+elif test -n "$ac_cv_path_READELF_FOR_TARGET"; then
+  READELF_FOR_TARGET=$ac_cv_path_READELF_FOR_TARGET
+fi
 if test -z "$ac_cv_path_READELF_FOR_TARGET" ; then
   if test -n "$with_build_time_tools"; then
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for readelf in 
$with_build_time_tools" >&5
@@ -19262,6 +19322,11 @@ fi
 
 
 
+if test -n "$STRIP_FOR_TARGET"; then
+  ac_cv_path_STRIP_FOR_TARGET=$STRIP_FOR_TARGET
+elif test -n "$ac_cv_path_STRIP_FOR_TARGET"; then
+  STRIP_FOR_TARGET=$ac_cv_path_STRIP_FOR_TARGET
+fi
 if test -z "$ac_cv_path_STRIP_FOR_TARGET" ; then
   if test -n "$with_build_time_tools"; then
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for strip in 
$with_build_time_tools" >&5
@@ -19492,6 +19557,11 @@ fi
 
 
 
+if test -n "$WINDRES_FOR_TARGET"; then
+  ac_cv_path_WINDRES_FOR_TARGET=$WINDRES_FOR_TARGET
+elif test -n "$ac_cv_path_WINDRES_FOR_TARGET"; then
+  WINDRES_FOR_TARGET=$ac_cv_path_WINDRES_FOR_TARGET
+fi
 if test -z "$ac_cv_path_WINDRES_FOR_TARGET" ; then
   if test -n "$with_build_time_tools"; then
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for windres in 
$with_build_time_tools" >&5
@@ -19722,6 +19792,11 @@ fi
 
 
 
+if test -n "$WINDMC_FOR_TARGET"; then
+  ac_cv_path_WINDMC_FOR_TARGET=$WINDMC_FOR_TARGET
+elif test -n "$ac_cv_path_WINDMC_FOR_TARGET"; then
+  WINDMC_FOR_TARGET=$ac_cv_path_WINDMC_FOR_TARGET
+fi
 if test -z "$ac_cv_path_WINDMC_FOR_TARGET" ; then
   if test -n "$with_build_time_tools"; then
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for windmc in 
$with_build_time_tools" >&5
-- 
2.53.0

Reply via email to