configure.ac: Abstract out common pattern in CPU/ABI variable defs.
[catacomb] / configure.ac
index 6171efd..32a80e0 100644 (file)
@@ -120,35 +120,27 @@ else
   esac
 fi
 
-dnl Figure out the current CPU.
-catacomb_CPU_FAMILIES([catacomb_CLEAR_FLAGS])
-case $CPUFAM in
-  m4_define([catacomb_DEFINE_CPU],
-    [m4_ifdef([catacomb_seen_cpu/$2], [],
-      [$2)
-       AC_DEFINE([CPUFAM_]m4_translit([$2], [a-z], [A-Z]), [1],
-                 [Define if host CPU family is \`$2\'.])
-       ;;m4_define([catacomb_seen_cpu/$2], [t])])])
-  catacomb_CPU_FAMILIES([catacomb_DEFINE_CPU])
+dnl A hairy macro used to set the `CPUFAM_...' and `ABI_...' variables.  We
+dnl basically need to do the same thing for the family and ABI, so it's worth
+dnl some effort to hide the ugliness.
+m4_define([catacomb_DEFINE_CPU_OR_ABI],
+[case $$1 in
+  m4_define([_def],
+    [m4_ifdef([catacomb_seen_$3/$$2], [],
+      [$$2)
+       AC_DEFINE([$4]m4_translit([$$2], [a-z], [A-Z]), [1], [$5])
+       ;;m4_define([catacomb_seen_$3/$$2], [t])])])
+  catacomb_CPU_FAMILIES([_def])
   nil) ;;
-  *) AC_MSG_ERROR([BUG: unexpected cpufam \`$CPUFAM']) ;;
-esac
-AC_SUBST([CPUFAM])
+  *) AC_MSG_ERROR([BUG: unexpected $1 \`$1']) ;;
+esac])
 
-dnl Figure out the current ABI.
+dnl Figure out the target CPU family and ABI.
 catacomb_CPU_FAMILIES([catacomb_CLEAR_FLAGS])
-case $ABI in
-  m4_define([catacomb_DEFINE_ABI],
-    [m4_ifdef([catacomb_seen_abi/$3], [],
-      [$3)
-       AC_DEFINE([ABI_]m4_translit([$3], [a-z], [A-Z]), [1],
-                 [Define if host ABI variant is \`$3\'.])
-       ;;m4_define([catacomb_seen_abi/$3], [t])])])
-  catacomb_CPU_FAMILIES([catacomb_DEFINE_ABI])
-  nil) ;;
-  *) AC_MSG_ERROR([BUG: unexpected ABI \`$ABI']) ;;
-esac
-AC_SUBST([ABI])
+catacomb_DEFINE_CPU_OR_ABI([CPUFAM], [2], [cpu],
+  [CPUFAM_], [Define if target CPU is \`$][2\'.])
+catacomb_DEFINE_CPU_OR_ABI([ABI], [3], [abi],
+  [ABI_], [Define if target ABI is \`$][3\'.])
 
 dnl Establish Automake conditions for things.
 catacomb_CPU_FAMILIES([catacomb_CLEAR_FLAGS])
@@ -307,6 +299,21 @@ fi
 catacomb_LIMIT([SIZET],                [=0],           [~(size_t)0])
 AC_SUBST([limits])
 
+dnl Figure out other aspects of the implementation's arithmetic.
+AC_CACHE_CHECK([whether negative numbers use two's complement],
+       [catacomb_cv_neg_twoc],
+[AC_TRY_COMPILE(
+[#include <limits.h>],
+[int check[2*!!(-INT_MAX == INT_MIN + 1) - 1];],
+[catacomb_cv_neg_twoc=yes],
+[catacomb_cv_neg_twoc=no])])
+case $catacomb_cv_neg_twoc in
+  yes)
+    AC_DEFINE([NEG_TWOC], [1],
+     [Define if signed numbers are represented in two's complement.])
+    ;;
+esac
+
 dnl Functions used for noise-gathering.
 AC_CHECK_FUNCS([setgroups])
 AC_CHECK_HEADERS([linux/random.h])