configure: compile-time word size detection
authorAaron Carroll <aaronc@cse.unsw.edu.au>
Thu, 14 Mar 2013 05:57:39 +0000 (16:57 +1100)
committerJens Axboe <axboe@kernel.dk>
Thu, 14 Mar 2013 14:01:58 +0000 (15:01 +0100)
Signed-off-by: Aaron Carroll <aaronc@cse.unsw.edu.au>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
configure

index 1fa9b635ade84b3fe8f9eedfd0789176ab7bb795..84c6af28f4ffe9d3903affeb530d9cc5a80f58c1 100755 (executable)
--- a/configure
+++ b/configure
@@ -348,16 +348,20 @@ echo
 # check for wordsize
 wordsize="0"
 cat > $TMPC <<EOF
 # check for wordsize
 wordsize="0"
 cat > $TMPC <<EOF
-#include <stdio.h>
+#include <limits.h>
+#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
 int main(void)
 {
 int main(void)
 {
-  unsigned int wsize = sizeof(long) * 8;
-  printf("%d\n", wsize);
+  BUILD_BUG_ON(sizeof(long)*CHAR_BIT != WORDSIZE);
   return 0;
 }
 EOF
   return 0;
 }
 EOF
-if compile_prog "" "" "wordsize"; then
-  wordsize=`$TMPE`
+if compile_prog "-DWORDSIZE=32" "" "wordsize"; then
+  wordsize="32"
+elif compile_prog "-DWORDSIZE=64" "" "wordsize"; then
+  wordsize="64"
+else
+  fatal "Unknown wordsize"
 fi
 echo "Wordsize                      $wordsize"
 
 fi
 echo "Wordsize                      $wordsize"