| 1 | dnl @synopsis AX_CHECK_LLONG_MINMAX |
|---|
| 2 | dnl |
|---|
| 3 | dnl This macro will fix up LLONG_MIN and LLONG_MAX as appropriate. I'm finding |
|---|
| 4 | dnl it quite difficult to believe that so many hoops are necessary. The world |
|---|
| 5 | dnl seems to have gone quite mad. |
|---|
| 6 | dnl |
|---|
| 7 | dnl This gem is adapted from the OpenSSH configure script so here's |
|---|
| 8 | dnl the original copyright notice: |
|---|
| 9 | dnl |
|---|
| 10 | dnl Copyright (c) 1999-2004 Damien Miller |
|---|
| 11 | dnl |
|---|
| 12 | dnl Permission to use, copy, modify, and distribute this software for any |
|---|
| 13 | dnl purpose with or without fee is hereby granted, provided that the above |
|---|
| 14 | dnl copyright notice and this permission notice appear in all copies. |
|---|
| 15 | dnl |
|---|
| 16 | dnl @category C |
|---|
| 17 | dnl @author Martin Ebourne and Damien Miller |
|---|
| 18 | dnl @version 2005/07/07 |
|---|
| 19 | |
|---|
| 20 | AC_DEFUN([AX_CHECK_LLONG_MINMAX], [ |
|---|
| 21 | AC_CHECK_DECL([LLONG_MAX], [have_llong_max=1], , [[#include <limits.h>]]) |
|---|
| 22 | if test -z "$have_llong_max"; then |
|---|
| 23 | AC_MSG_CHECKING([[for max value of long long]]) |
|---|
| 24 | AC_RUN_IFELSE([AC_LANG_SOURCE([[ |
|---|
| 25 | #include <stdio.h> |
|---|
| 26 | /* Why is this so damn hard? */ |
|---|
| 27 | #undef __GNUC__ |
|---|
| 28 | #undef __USE_ISOC99 |
|---|
| 29 | #define __USE_ISOC99 |
|---|
| 30 | #include <limits.h> |
|---|
| 31 | #define DATA "conftest.llminmax" |
|---|
| 32 | int main(void) { |
|---|
| 33 | FILE *f; |
|---|
| 34 | long long i, llmin, llmax = 0; |
|---|
| 35 | |
|---|
| 36 | if((f = fopen(DATA,"w")) == NULL) |
|---|
| 37 | exit(1); |
|---|
| 38 | |
|---|
| 39 | #if defined(LLONG_MIN) && defined(LLONG_MAX) |
|---|
| 40 | fprintf(stderr, "Using system header for LLONG_MIN and LLONG_MAX\n"); |
|---|
| 41 | llmin = LLONG_MIN; |
|---|
| 42 | llmax = LLONG_MAX; |
|---|
| 43 | #else |
|---|
| 44 | fprintf(stderr, "Calculating LLONG_MIN and LLONG_MAX\n"); |
|---|
| 45 | /* This will work on one's complement and two's complement */ |
|---|
| 46 | for (i = 1; i > llmax; i <<= 1, i++) |
|---|
| 47 | llmax = i; |
|---|
| 48 | llmin = llmax + 1LL; /* wrap */ |
|---|
| 49 | #endif |
|---|
| 50 | |
|---|
| 51 | /* Sanity check */ |
|---|
| 52 | if (llmin + 1 < llmin || llmin - 1 < llmin || llmax + 1 > llmax || llmax - 1 > llmax) { |
|---|
| 53 | fprintf(f, "unknown unknown\n"); |
|---|
| 54 | exit(2); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | if (fprintf(f ,"%lld %lld", llmin, llmax) < 0) |
|---|
| 58 | exit(3); |
|---|
| 59 | |
|---|
| 60 | exit(0); |
|---|
| 61 | } |
|---|
| 62 | ]])], [ |
|---|
| 63 | read llong_min llong_max < conftest.llminmax |
|---|
| 64 | AC_MSG_RESULT([$llong_max]) |
|---|
| 65 | AC_DEFINE_UNQUOTED([LLONG_MAX], [${llong_max}LL], |
|---|
| 66 | [max value of long long calculated by configure]) |
|---|
| 67 | AC_MSG_CHECKING([[for min value of long long]]) |
|---|
| 68 | AC_MSG_RESULT([$llong_min]) |
|---|
| 69 | AC_DEFINE_UNQUOTED([LLONG_MIN], [${llong_min}LL], |
|---|
| 70 | [min value of long long calculated by configure]) |
|---|
| 71 | ], |
|---|
| 72 | [AC_MSG_RESULT(not found)], |
|---|
| 73 | [AC_MSG_WARN([[cross compiling: not checking]])] |
|---|
| 74 | ) |
|---|
| 75 | fi |
|---|
| 76 | ])dnl |
|---|