Hello,

On Tue, Aug 16, 2005 at 12:45:14PM -0700, Noah Misch wrote:
> >  case $[#] in
> > +  0|1) set "";;
> > +  *)   shift; shift;;
> >  esac
> 
> This case statement now merely avoids shifting an empty argument list.
> Given that this code splits canonical platform names, which have three
> or more fields, why not just shift twice, unconditionally?

perhaps config.sub is broken, perhaps ac_cv_build came from config.site
or from a broken config.cache.

But yes, your idea is good: we can check that the variable has the
required form, and then remove the case statement.

Attached please find a patch which implements this.  Moreover, it moves
more common code to _AC_CANONICAL_SPLIT.

OK to commit?

Stepan
2005-08-17  Stepan Kasal  <[EMAIL PROTECTED]>

        * lib/autoconf/general.m4 (AC_CANONICAL_BUILD, AC_CANONICAL_HOST,
        AC_CANONICAL_TARGET): Factor out common code ...
        (_AC_CANONICAL_SPLIT): ... here.  Verify that the value is really
        canonical.  Simplify the actual split, relying on that.  Moreover,
        we rely on the fact that $* concatenates the parameters by the first
        character from IFS.

Index: lib/autoconf/general.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/autoconf/general.m4,v
retrieving revision 1.880
diff -u -r1.880 general.m4
--- lib/autoconf/general.m4     16 Aug 2005 09:11:06 -0000      1.880
+++ lib/autoconf/general.m4     17 Aug 2005 08:26:28 -0000
@@ -1654,24 +1654,39 @@
 # _AC_CANONICAL_SPLIT(THING)
 # --------------------------
 # Generate the variables THING, THING_{alias cpu vendor os}.
+#
 m4_define([_AC_CANONICAL_SPLIT],
-[AC_SUBST([$1],       [$ac_cv_$1])dnl
+[AC_CACHE_CHECK([$1 system type], [ac_cv_$1],
+[m4_if([$1], [build],
+[ac_build_alias=$build_alias
+test "x$ac_build_alias" = x &&
+  ac_build_alias=`$ac_config_guess`
+test "x$ac_build_alias" = x &&
+  AC_MSG_ERROR([cannot guess build type; you must specify one])
+ac_cv_build=`$ac_config_sub $ac_build_alias` ||
+  AC_MSG_ERROR([$ac_config_sub $ac_build_alias failed])
+],
+[dnl TARGET is host or target:
+if test "x$$1_alias" = x; then
+  ac_cv_$1=$ac_cv_[]m4_if([$1], [host], [build], [host])
+else
+  ac_cv_$1=`$ac_config_sub $$1_alias` ||
+    AC_MSG_ERROR([$ac_config_sub $$1_alias failed])
+fi
+])dnl
+])
+case $ac_cv_$1 in
+  [[!-]]*-*-*) ;;
+  *) AC_MSG_ERROR([non-canonical value of ac_cv_$1: $ac_cv_$1]);;
+esac
+AC_SUBST([$1], [$ac_cv_$1])dnl
 ac_save_IFS=$IFS; IFS='-'
-set x $ac_cv_$1
-shift
-IFS=$ac_save_IFS
-
+set $ac_cv_$1
 AC_SUBST([$1_cpu], [$[1]])dnl
 AC_SUBST([$1_vendor], [$[2]])dnl
-AC_SUBST([$1_os], [$[3]])dnl
-case $[#] in
-0|1|2) ;;
-*)
-  shift; shift; shift
-  for ac_arg
-  do $1_os=[$]$1_os-$ac_arg
-  done;;
-esac
+shift; shift
+AC_SUBST([$1_os], [$[*]])dnl
+IFS=$ac_save_IFS
 ])# _AC_CANONICAL_SPLIT
 
 
@@ -1688,16 +1703,6 @@
 # Make sure we can run config.sub.
 $ac_config_sub sun4 >/dev/null 2>&1 ||
   AC_MSG_ERROR([cannot run $ac_config_sub])
-
-AC_CACHE_CHECK([build system type], [ac_cv_build],
-[ac_build_alias=$build_alias
-test "x$ac_build_alias" = x &&
-  ac_build_alias=`$ac_config_guess`
-test "x$ac_build_alias" = x &&
-  AC_MSG_ERROR([cannot guess build type; you must specify one])
-ac_cv_build=`$ac_config_sub $ac_build_alias` ||
-  AC_MSG_ERROR([$ac_config_sub $ac_build_alias failed])
-])
 _AC_CANONICAL_SPLIT(build)
 ])# AC_CANONICAL_BUILD
 
@@ -1708,14 +1713,6 @@
 [AC_REQUIRE([AC_CANONICAL_BUILD])dnl
 m4_divert_text([HELP_CANON],
 [[  --host=HOST       cross-compile to build programs to run on HOST 
[BUILD]]])dnl
-AC_CACHE_CHECK([host system type], [ac_cv_host],
-[if test "x$host_alias" = x; then
-  ac_cv_host=$ac_cv_build
-else
-  ac_cv_host=`$ac_config_sub $host_alias` ||
-    AC_MSG_ERROR([$ac_config_sub $host_alias failed])
-fi
-])
 _AC_CANONICAL_SPLIT([host])
 ])# AC_CANONICAL_HOST
 
@@ -1727,14 +1724,6 @@
 AC_BEFORE([$0], [AC_ARG_PROGRAM])dnl
 m4_divert_text([HELP_CANON],
 [[  --target=TARGET   configure for building compilers for TARGET [HOST]]])dnl
-AC_CACHE_CHECK([target system type], [ac_cv_target],
-[if test "x$target_alias" = x; then
-  ac_cv_target=$ac_cv_host
-else
-  ac_cv_target=`$ac_config_sub $target_alias` ||
-    AC_MSG_ERROR([$ac_config_sub $target_alias failed])
-fi
-])
 _AC_CANONICAL_SPLIT([target])
 
 # The aliases save the names the user supplied, while $host etc.

Reply via email to