Blame m4/inttypes.m4

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