Fix longstanding bug in dual-arch support, which originated in
memcheck/tests/Makefile.am and was copied into drd/tests/Makefile.am.

When building regtests for a 32-bit only build on a 64-bit CPU, the
use of $(VG_ARCH) in these Makefiles is incorrect, because VG_ARCH
will be set to the 64-bit architecture, not the 32-bit architecture.

See comments on VG_ARCH_PRI and VG_ARCH_MAX in configure.in for more
details.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@8623 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/configure.in b/configure.in
index 001c45c..422406c 100644
--- a/configure.in
+++ b/configure.in
@@ -126,15 +126,22 @@
 esac
 
 
-# Checks for the platform, with the aim of setting VG_ARCH.  Note
-# that VG_ARCH must be set to reflect the most that this CPU can
-# do: for example if it is a 64-bit capable PowerPC, then it must
-# be set to ppc64 and not ppc32.  Ditto for amd64.
+# Checks for the platform, with the aim of setting VG_ARCH_MAX.  Note
+# that VG_ARCH_MAX must be set to reflect the most that this CPU can
+# do: for example if it is a 64-bit capable PowerPC, then it must be
+# set to ppc64 and not ppc32.  Ditto for amd64.
+#
+# We will later in this file set VG_ARCH_PRI, which is the arch for
+# the primary target.  For example, suppose we do a build on an amd64
+# machine, but --enable-only32bit has been requested.  Then
+# VG_ARCH_MAX will be "amd64" since that reflects the most that this
+# cpu can do, but VG_ARCH_PRI will be "x86", since that reflects the
+# arch corresponding to the primary build (VG_PLATFORM_PRI).
 
 AC_CANONICAL_HOST
 
 AC_MSG_CHECKING([for a supported CPU])
-AC_SUBST(VG_ARCH)
+AC_SUBST(VG_ARCH_MAX)
 
 AC_SUBST(VG_ARCH_ALL)
 VG_ARCH_ALL="amd64 ppc32 ppc64 x86"
@@ -144,14 +151,14 @@
 case "${host_cpu}" in
      i?86) 
 	AC_MSG_RESULT([ok (${host_cpu})])
-        VG_ARCH="x86"
+        VG_ARCH_MAX="x86"
         valt_load_address_normal="0x38000000"
         valt_load_address_inner="0x28000000"
         ;;
 
      x86_64) 
         AC_MSG_RESULT([ok (${host_cpu})])
-        VG_ARCH="amd64"
+        VG_ARCH_MAX="amd64"
         valt_load_address_normal="0x38000000"
         valt_load_address_inner="0x28000000"
         ;;
@@ -159,7 +166,7 @@
      powerpc64)
 #       This value can only happen on Linux, not on AIX
         AC_MSG_RESULT([ok (${host_cpu})])
-        VG_ARCH="ppc64"
+        VG_ARCH_MAX="ppc64"
         valt_load_address_normal="0x38000000"
         valt_load_address_inner="0x28000000"
         ;;
@@ -170,10 +177,10 @@
         AC_MSG_RESULT([ok (${host_cpu})])
 	case "${host_os}" in
 	   aix5.*)
-	      VG_ARCH="ppc64"
+	      VG_ARCH_MAX="ppc64"
               ;;
            *)
-              VG_ARCH="ppc32"
+              VG_ARCH_MAX="ppc32"
               ;;
         esac
         valt_load_address_normal="0x38000000"
@@ -287,7 +294,7 @@
 # supports building 32 bit programs and disable 32 bit support if it
 # does not support building 32 bit programs
 
-case "$VG_ARCH-$VG_OS" in
+case "$VG_ARCH_MAX-$VG_OS" in
      amd64-linux|ppc64-linux)
         AC_MSG_CHECKING([for 32 bit build support])
         safe_CFLAGS=$CFLAGS
@@ -317,12 +324,23 @@
 # possible.  The system will also be built for this target, but not
 # the regression or performance tests.
 #
+# Also establish VG_ARCH_PRI, which is the arch for the primary
+# build target.  The various makefiles building regression tests
+# sometimes need to see this.
 AC_MSG_CHECKING([for a supported CPU/OS combination])
 
 AC_SUBST(VG_PLATFORM_PRI)
 AC_SUBST(VG_PLATFORM_SEC)
+AC_SUBST(VG_ARCH_PRI)
 
-case "$VG_ARCH-$VG_OS" in
+# By default, the primary arch is the same as the "max" arch, as
+# commented above (at the definition of VG_ARCH_MAX).  We may choose
+# to downgrade it in the big case statement just below here, in the
+# case where we're building on a 64 bit machine but have been
+# requested only to do a 32 bit build.
+VG_ARCH_PRI=$VG_ARCH_MAX
+
+case "$VG_ARCH_MAX-$VG_OS" in
      x86-linux)
 	VG_PLATFORM_PRI="X86_LINUX"
 	VG_PLATFORM_SEC=""
@@ -335,6 +353,7 @@
 	elif test x$vg_cv_only32bit = xyes; then
 	   VG_PLATFORM_PRI="X86_LINUX"
 	   VG_PLATFORM_SEC=""
+	   VG_ARCH_PRI="x86"
 	else
 	   VG_PLATFORM_PRI="AMD64_LINUX"
 	   VG_PLATFORM_SEC="X86_LINUX"
@@ -353,6 +372,7 @@
 	elif test x$vg_cv_only32bit = xyes; then
 	   VG_PLATFORM_PRI="PPC32_AIX5"
 	   VG_PLATFORM_SEC=""
+	   VG_ARCH_PRI="ppc32"
 	else
 	   VG_PLATFORM_PRI="PPC64_AIX5"
 	   VG_PLATFORM_SEC="PPC32_AIX5"
@@ -366,6 +386,7 @@
 	elif test x$vg_cv_only32bit = xyes; then
 	   VG_PLATFORM_PRI="PPC32_LINUX"
 	   VG_PLATFORM_SEC=""
+	   VG_ARCH_PRI="ppc32"
 	else
 	   VG_PLATFORM_PRI="PPC64_LINUX"
 	   VG_PLATFORM_SEC="PPC32_LINUX"
@@ -1529,9 +1550,12 @@
 
 cat<<EOF
 
-   Primary build target: ${VG_PLATFORM_PRI}
- Secondary build target: ${VG_PLATFORM_SEC}
-     Default supp files: ${DEFAULT_SUPP}
+ configure.in: VG_ARCH_MAX = ${VG_ARCH_MAX}
+ configure.in: VG_ARCH_PRI = ${VG_ARCH_PRI}
+
+       Primary build target: ${VG_PLATFORM_PRI}
+     Secondary build target: ${VG_PLATFORM_SEC}
+         Default supp files: ${DEFAULT_SUPP}
 
 EOF