Blame m4/inttypes.m4

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