source: box/trunk/infrastructure/m4/ax_check_llong_minmax.m4 @ 1490

Revision 1490, 2.5 KB checked in by chris, 5 years ago (diff)

Merge new m4 from trunk. (refs #3, merges [1453])

Line 
1dnl @synopsis AX_CHECK_LLONG_MINMAX
2dnl
3dnl This macro will fix up LLONG_MIN and LLONG_MAX as appropriate. I'm finding
4dnl it quite difficult to believe that so many hoops are necessary. The world
5dnl seems to have gone quite mad.
6dnl
7dnl This gem is adapted from the OpenSSH configure script so here's
8dnl the original copyright notice:
9dnl
10dnl Copyright (c) 1999-2004 Damien Miller
11dnl
12dnl Permission to use, copy, modify, and distribute this software for any
13dnl purpose with or without fee is hereby granted, provided that the above
14dnl copyright notice and this permission notice appear in all copies.
15dnl
16dnl @category C
17dnl @author Martin Ebourne and Damien Miller
18dnl @version 2005/07/07
19
20AC_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
Note: See TracBrowser for help on using the repository browser.