Blame m4/inttypes.m4

Packit 33f14e
# inttypes.m4 serial 26
Packit 33f14e
dnl Copyright (C) 2006-2017 Free Software Foundation, Inc.
Packit 33f14e
dnl This file is free software; the Free Software Foundation
Packit 33f14e
dnl gives unlimited permission to copy and/or distribute it,
Packit 33f14e
dnl with or without modifications, as long as this notice is preserved.
Packit 33f14e
Packit 33f14e
dnl From Derek Price, Bruno Haible.
Packit 33f14e
dnl Test whether <inttypes.h> is supported or must be substituted.
Packit 33f14e
Packit 33f14e
AC_DEFUN([gl_INTTYPES_H],
Packit 33f14e
[
Packit 33f14e
  AC_REQUIRE([gl_INTTYPES_INCOMPLETE])
Packit 33f14e
  gl_INTTYPES_PRI_SCN
Packit 33f14e
])
Packit 33f14e
Packit 33f14e
AC_DEFUN_ONCE([gl_INTTYPES_INCOMPLETE],
Packit 33f14e
[
Packit 33f14e
  AC_REQUIRE([gl_STDINT_H])
Packit 33f14e
  AC_CHECK_HEADERS_ONCE([inttypes.h])
Packit 33f14e
Packit 33f14e
  dnl Override <inttypes.h> always, so that the portability warnings work.
Packit 33f14e
  AC_REQUIRE([gl_INTTYPES_H_DEFAULTS])
Packit 33f14e
  gl_CHECK_NEXT_HEADERS([inttypes.h])
Packit 33f14e
Packit 33f14e
  AC_REQUIRE([gl_MULTIARCH])
Packit 33f14e
Packit 33f14e
  dnl Check for declarations of anything we want to poison if the
Packit 33f14e
  dnl corresponding gnulib module is not in use.
Packit 33f14e
  gl_WARN_ON_USE_PREPARE([[#include <inttypes.h>
Packit 33f14e
    ]], [imaxabs imaxdiv strtoimax strtoumax])
Packit 33f14e
])
Packit 33f14e
Packit 33f14e
# Ensure that the PRI* and SCN* macros are defined appropriately.
Packit 33f14e
AC_DEFUN([gl_INTTYPES_PRI_SCN],
Packit 33f14e
[
Packit 33f14e
  AC_REQUIRE([gt_INTTYPES_PRI])
Packit 33f14e
Packit 33f14e
  PRIPTR_PREFIX=
Packit 33f14e
  if test -n "$STDINT_H"; then
Packit 33f14e
    dnl Using the gnulib <stdint.h>. It always defines intptr_t to 'long'.
Packit 33f14e
    PRIPTR_PREFIX='"l"'
Packit 33f14e
  else
Packit 33f14e
    dnl Using the system's <stdint.h>.
Packit 33f14e
    for glpfx in '' l ll I64; do
Packit 33f14e
      case $glpfx in
Packit 33f14e
        '')  gltype1='int';;
Packit 33f14e
        l)   gltype1='long int';;
Packit 33f14e
        ll)  gltype1='long long int';;
Packit 33f14e
        I64) gltype1='__int64';;
Packit 33f14e
      esac
Packit 33f14e
      AC_COMPILE_IFELSE(
Packit 33f14e
        [AC_LANG_PROGRAM([[#include <stdint.h>
Packit 33f14e
           extern intptr_t foo;
Packit 33f14e
           extern $gltype1 foo;]])],
Packit 33f14e
        [PRIPTR_PREFIX='"'$glpfx'"'])
Packit 33f14e
      test -n "$PRIPTR_PREFIX" && break
Packit 33f14e
    done
Packit 33f14e
  fi
Packit 33f14e
  AC_SUBST([PRIPTR_PREFIX])
Packit 33f14e
Packit 33f14e
  gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
Packit 33f14e
    [INT32_MAX_LT_INTMAX_MAX],
Packit 33f14e
    [defined INT32_MAX && defined INTMAX_MAX],
Packit 33f14e
    [INT32_MAX < INTMAX_MAX],
Packit 33f14e
    [sizeof (int) < sizeof (long long int)])
Packit 33f14e
  if test $APPLE_UNIVERSAL_BUILD = 0; then
Packit 33f14e
    gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
Packit 33f14e
      [INT64_MAX_EQ_LONG_MAX],
Packit 33f14e
      [defined INT64_MAX],
Packit 33f14e
      [INT64_MAX == LONG_MAX],
Packit 33f14e
      [sizeof (long long int) == sizeof (long int)])
Packit 33f14e
  else
Packit 33f14e
    INT64_MAX_EQ_LONG_MAX=-1
Packit 33f14e
  fi
Packit 33f14e
  gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
Packit 33f14e
    [UINT32_MAX_LT_UINTMAX_MAX],
Packit 33f14e
    [defined UINT32_MAX && defined UINTMAX_MAX],
Packit 33f14e
    [UINT32_MAX < UINTMAX_MAX],
Packit 33f14e
    [sizeof (unsigned int) < sizeof (unsigned long long int)])
Packit 33f14e
  if test $APPLE_UNIVERSAL_BUILD = 0; then
Packit 33f14e
    gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
Packit 33f14e
      [UINT64_MAX_EQ_ULONG_MAX],
Packit 33f14e
      [defined UINT64_MAX],
Packit 33f14e
      [UINT64_MAX == ULONG_MAX],
Packit 33f14e
      [sizeof (unsigned long long int) == sizeof (unsigned long int)])
Packit 33f14e
  else
Packit 33f14e
    UINT64_MAX_EQ_ULONG_MAX=-1
Packit 33f14e
  fi
Packit 33f14e
])
Packit 33f14e
Packit 33f14e
# Define the symbol $1 to be 1 if the condition is true, 0 otherwise.
Packit 33f14e
# If $2 is true, the condition is $3; otherwise if long long int is supported
Packit 33f14e
# approximate the condition with $4; otherwise, assume the condition is false.
Packit 33f14e
# The condition should work on all C99 platforms; the approximations should be
Packit 33f14e
# good enough to work on all practical pre-C99 platforms.
Packit 33f14e
# $2 is evaluated by the C preprocessor, $3 and $4 as compile-time constants.
Packit 33f14e
AC_DEFUN([gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION],
Packit 33f14e
[
Packit 33f14e
  AC_CACHE_CHECK([whether $3],
Packit 33f14e
    [gl_cv_test_$1],
Packit 33f14e
    [AC_COMPILE_IFELSE(
Packit 33f14e
       [AC_LANG_PROGRAM(
Packit 33f14e
          [[/* Work also in C++ mode.  */
Packit 33f14e
            #define __STDC_LIMIT_MACROS 1
Packit 33f14e
Packit 33f14e
            /* Work if build is not clean.  */
Packit 33f14e
            #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H
Packit 33f14e
Packit 33f14e
            #include <limits.h>
Packit 33f14e
            #if HAVE_STDINT_H
Packit 33f14e
             #include <stdint.h>
Packit 33f14e
            #endif
Packit 33f14e
Packit 33f14e
            #if $2
Packit 33f14e
             #define CONDITION ($3)
Packit 33f14e
            #elif HAVE_LONG_LONG_INT
Packit 33f14e
             #define CONDITION ($4)
Packit 33f14e
            #else
Packit 33f14e
             #define CONDITION 0
Packit 33f14e
            #endif
Packit 33f14e
            int test[CONDITION ? 1 : -1];]])],
Packit 33f14e
       [gl_cv_test_$1=yes],
Packit 33f14e
       [gl_cv_test_$1=no])])
Packit 33f14e
  if test $gl_cv_test_$1 = yes; then
Packit 33f14e
    $1=1;
Packit 33f14e
  else
Packit 33f14e
    $1=0;
Packit 33f14e
  fi
Packit 33f14e
  AC_SUBST([$1])
Packit 33f14e
])
Packit 33f14e
Packit 33f14e
AC_DEFUN([gl_INTTYPES_MODULE_INDICATOR],
Packit 33f14e
[
Packit 33f14e
  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
Packit 33f14e
  AC_REQUIRE([gl_INTTYPES_H_DEFAULTS])
Packit 33f14e
  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
Packit 33f14e
])
Packit 33f14e
Packit 33f14e
AC_DEFUN([gl_INTTYPES_H_DEFAULTS],
Packit 33f14e
[
Packit 33f14e
  GNULIB_IMAXABS=0;      AC_SUBST([GNULIB_IMAXABS])
Packit 33f14e
  GNULIB_IMAXDIV=0;      AC_SUBST([GNULIB_IMAXDIV])
Packit 33f14e
  GNULIB_STRTOIMAX=0;    AC_SUBST([GNULIB_STRTOIMAX])
Packit 33f14e
  GNULIB_STRTOUMAX=0;    AC_SUBST([GNULIB_STRTOUMAX])
Packit 33f14e
  dnl Assume proper GNU behavior unless another module says otherwise.
Packit 33f14e
  HAVE_DECL_IMAXABS=1;   AC_SUBST([HAVE_DECL_IMAXABS])
Packit 33f14e
  HAVE_DECL_IMAXDIV=1;   AC_SUBST([HAVE_DECL_IMAXDIV])
Packit 33f14e
  HAVE_DECL_STRTOIMAX=1; AC_SUBST([HAVE_DECL_STRTOIMAX])
Packit 33f14e
  HAVE_DECL_STRTOUMAX=1; AC_SUBST([HAVE_DECL_STRTOUMAX])
Packit 33f14e
  REPLACE_STRTOIMAX=0;   AC_SUBST([REPLACE_STRTOIMAX])
Packit 33f14e
  REPLACE_STRTOUMAX=0;   AC_SUBST([REPLACE_STRTOUMAX])
Packit 33f14e
  INT32_MAX_LT_INTMAX_MAX=1;  AC_SUBST([INT32_MAX_LT_INTMAX_MAX])
Packit 33f14e
  INT64_MAX_EQ_LONG_MAX='defined _LP64';  AC_SUBST([INT64_MAX_EQ_LONG_MAX])
Packit 33f14e
  PRI_MACROS_BROKEN=0;   AC_SUBST([PRI_MACROS_BROKEN])
Packit 33f14e
  PRIPTR_PREFIX=__PRIPTR_PREFIX;  AC_SUBST([PRIPTR_PREFIX])
Packit 33f14e
  UINT32_MAX_LT_UINTMAX_MAX=1;  AC_SUBST([UINT32_MAX_LT_UINTMAX_MAX])
Packit 33f14e
  UINT64_MAX_EQ_ULONG_MAX='defined _LP64';  AC_SUBST([UINT64_MAX_EQ_ULONG_MAX])
Packit 33f14e
])