From 67078db6594b25d9f5ac242002c504df345ef864 Mon Sep 17 00:00:00 2001
From: Jaroslav Hajek <hajek@hajek.vzlu.local>
Date: Wed, 8 Sep 2010 10:30:14 +0200
Subject: [PATCH 2/2] check for correct integer size in ax_blas_f77_func

---
 m4/ax_blas_f77_func.m4 |   30 +++++++++++++++++++++++++++++-
 1 files changed, 29 insertions(+), 1 deletions(-)

diff --git a/m4/ax_blas_f77_func.m4 b/m4/ax_blas_f77_func.m4
index 3c96a1e..51bcef9 100644
--- a/m4/ax_blas_f77_func.m4
+++ b/m4/ax_blas_f77_func.m4
@@ -142,6 +142,33 @@ elif test x"$ax_blas_ok" = xyes; then
       ]]),[ax_blas_zdotu_fcall_ok=yes],
 	[ax_blas_zdotu_fcall_ok=no])
 	AC_MSG_RESULT([$ax_blas_zdotu_fcall_ok])
+# Check for correct integer size
+# FIXME: this may fail with things like -ftrapping-math.
+        AC_MSG_CHECKING([whether the integer size is correct])
+        AC_RUN_IFELSE(AC_LANG_PROGRAM(,[[
+      integer n,nn(3)
+      real s,a(1),b(1),sdot
+      a(1) = 1.0
+      b(1) = 1.0
+c Generate -2**33 + 1, if possible
+      n = 2
+      n = -4 * (n ** 30)
+      n = n + 1
+      if (n >= 0) goto 1
+c This means we're on 64-bit integers. Check whether the BLAS is, too.
+      s = sdot(n,a,1,b,1)
+      if (s .ne. 0.0) stop 1
+    1 continue
+c We may be on 32-bit integers, and the BLAS on 64 bits. This is almost bound
+c to have already failed, but just in case, we'll check.
+      nn(1) = -1
+      nn(2) = 1
+      nn(3) = -1
+      s = sdot(nn(2),a,1,b,1)
+      if (s .ne. 1.0) stop 1
+       ]]),[acx_blas_integer_size_ok=yes],
+	[ax_blas_integer_size_ok=no])
+	AC_MSG_RESULT([$ax_blas_integer_size_ok])
 
 	AC_LANG_POP(Fortran 77)
 
@@ -150,7 +177,8 @@ elif test x"$ax_blas_ok" = xyes; then
 		-a $ax_blas_sdot_fcall_ok = yes \
 		-a $ax_blas_ddot_fcall_ok = yes \
 		-a $ax_blas_cdotu_fcall_ok = yes \
-		-a $ax_blas_zdotu_fcall_ok = yes ; then
+		-a $ax_blas_zdotu_fcall_ok = yes \
+		-a $ax_blas_integer_size_ok = yes; then
 		ax_blas_f77_func_ok=yes;
 		$1
 	else
-- 
1.6.4.2

