autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: proposed gnulib-related additions to Autoconf


From: Ralf Wildenhues
Subject: Re: proposed gnulib-related additions to Autoconf
Date: Fri, 7 Apr 2006 21:21:59 +0200
User-agent: Mutt/1.5.9i

My current version of only the range macros, should have all concerns
addressed.  The factoring out for use in a list (or later, factoring
out in a shell function), is not completely done yet.

The macro should be fully functional, though, and the remaining
factorization should not need a change to the public macro.  The
public macro will have to be called with literals though, just like
AC_CHECK_HEADERS.

Suggested documentation:

@defmac AC_C_TYPE_RANGE_INTEGER (@var{type}, @ovar{min-variable}, 
@var{max-variable}, @ovar{value-bits-variable}, @dvar{includes, 
default-includes})
@acindex{C_TYPE_RANGE_INTEGER}
Compute the bounds, and optionally the value bits, of the integer
@var{type} and define @var{min-variable}, @var{max-variable}, and
@var{value-bits-variable} to those bounds and bits, respectively.
The bounds are integer constant expressions that are suitable for use
even in the preprocessor, the value bits is an integer literal.
If one or both of @var{min-variable} or @var{value-bits-variable} are
absent, do not define them.  If either of the three variables is already
defined through @var{includes}, do not define it.  If @var{type} does
not work, do not define either variable.  This macros works if cross
compiling.
@end defmac

Cheers,
Ralf

2006-04-07  Paul Eggert  <address@hidden>,
            Ralf Wildenhues <address@hidden>

        * lib/autoconf/c.m4 (_AC_C_TYPE_SIGNBIT_INTEGER)
        (_AC_C_TYPE_VALUE_BITS_INTEGER, _AC_C_TYPE_RANGE_INTEGER)
        (AC_C_TYPE_RANGE_INTEGER): New macros.
        * tests/mktests.sh (ac_exclude_list): Add
        AC_C_TYPE_RANGE_INTEGER.

Index: tests/mktests.sh
===================================================================
RCS file: /cvsroot/autoconf/autoconf/tests/mktests.sh,v
retrieving revision 1.52
diff -u -r1.52 mktests.sh
--- tests/mktests.sh    6 Apr 2006 17:56:43 -0000       1.52
+++ tests/mktests.sh    7 Apr 2006 19:18:42 -0000
@@ -89,7 +89,7 @@
 
        # Need an argument.
        /^AC_CANONICALIZE|AC_PREFIX_PROGRAM|AC_PREREQ$/ {next}
-       /^AC_SEARCH_LIBS|AC_REPLACE_FUNCS$/ {next}
+       /^AC_SEARCH_LIBS|AC_REPLACE_FUNCS|AC_C_TYPE_RANGE_INTEGER$/ {next}
 
        # Performed in the semantics tests.
        
/^AC_CHECK_(ALIGNOF|DECL|FILE|FUNC|HEADER|LIB|MEMBER|PROG|SIZEOF|(TARGET_)?TOOL|TYPE)S?$/
 {next}
Index: lib/autoconf/c.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/autoconf/c.m4,v
retrieving revision 1.220
diff -u -r1.220 c.m4
--- lib/autoconf/c.m4   6 Apr 2006 11:24:00 -0000       1.220
+++ lib/autoconf/c.m4   7 Apr 2006 19:07:03 -0000
@@ -1635,3 +1635,233 @@
     fi
   fi
 ])
+
+
+
+# _AC_C_TYPE_SIGNBIT_INTEGER(TYPE, [INCLUDES = DEFAULT-INCLUDES])
+# ---------------------------------------------------------------
+# Compute the number of sign bits for TYPE.  The cache variable
+# is set to empty if the type is not defined.
+m4_define([_AC_C_TYPE_SIGNBIT_INTEGER],
+[
+  AS_VAR_PUSHDEF([ac_sbits], [ac_cv_signbits_$1])dnl
+  AC_CACHE_CHECK([for sign bits of $1], ac_sbits,
+    [AS_VAR_SET(ac_sbits, [])
+     AC_COMPILE_IFELSE(
+       [AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT([$2])], [($1) -1 < 0])],
+       [AS_VAR_SET(ac_sbits, 1)],
+       [AC_COMPILE_IFELSE(
+         [AC_LANG_BOOL_COMPILE_TRY(
+            [AC_INCLUDES_DEFAULT([$2])], [0 < ($1) -1])],
+         [AS_VAR_SET(ac_sbits, [0])])])
+    ])
+  AS_VAR_POPDEF([ac_sbits])dnl
+])# _AC_C_TYPE_SIGNBIT_INTEGER
+
+
+# _AC_C_TYPE_VALUE_BITS_INTEGER(TYPE, [VALUE-BITS-VARIABLE],
+#                                     [INCLUDES = DEFAULT-INCLUDES])
+# ------------------------------------------------------------------
+# Compute the number of value bits for TYPE.  If VALUE-BITS-VARIABLE
+# is given, store the result there.
+# This macro needs the number of sign bits as computed by
+# _AC_C_TYPE_SIGNBIT_INTEGER.
+m4_define([_AC_C_TYPE_VALUE_BITS_INTEGER],
+[
+  AS_VAR_PUSHDEF([ac_vbits], [ac_cv_valuebits_$1])dnl
+  AS_VAR_PUSHDEF([ac_sbits], [ac_cv_signbits_$1])dnl
+  AC_CACHE_CHECK([for value bits of $1], ac_vbits,
+    [ac_signbit=AS_VAR_GET(ac_sbits)
+     case $ac_signbit in #(
+     1) ac_suffix=; ac_unsigned=;; #(
+     0) ac_suffix=U; ac_unsigned=unsigned;;
+     esac
+     if test -n "$ac_signbit"; then
+       ac_bits=8; ac_1=1
+       for ac_type in \
+           "$ac_unsigned int" \
+           "$ac_unsigned long int" \
+           "$ac_unsigned long long int"; do
+         AC_COMPILE_IFELSE(
+           [AC_LANG_PROGRAM(
+              [$3
+              extern $ac_type ac__var_;
+              extern $1 ac__var_;],
+              [return !ac__var_;])],
+           [ac_1=1$ac_suffix
+            case $ac_type in #(
+            *long\ long*) ac_bits=64; ac_1=${ac_1}LL ;; #(
+            *long*)       ac_bits=32; ac_1=${ac_1}L ;; #(
+           *)            ac_bits=16 ;;
+            esac
+            break])
+       done
+
+       if test "$ac_1$ac_unsigned" = 1unsigned; then
+        AC_COMPILE_IFELSE(
+          [AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT([$3])],
+             [($1) -1 == (int) ($1) -1 && 0 < (int) ($1) -1])],
+          [],
+          [ac_1=1U])
+       fi
+
+       ac_shiftbits=`expr $ac_bits - 1 - $ac_signbit`
+       ac_max="((((($1) 1 << $ac_shiftbits) - 1) << 1) + 1)"
+
+       # Double the number of bits until this fails.
+       while
+         ac_bits1=`expr $ac_bits '*' 2`
+         ac_shiftbits=`expr $ac_bits1 - 1 - $ac_signbit`
+         ac_max1="((((($1) 1 << $ac_shiftbits) - 1) << 1) + 1)"
+         ac_max2="((((($1) 1 << ($ac_shiftbits - 1)) - 1) << 1) + 1)"
+
+         AC_COMPILE_IFELSE(
+           [AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT([$3])],
+              [$ac_max < $ac_max1 && ($1) $ac_max1 == $ac_max1
+              && $ac_max2 < $ac_max1])],
+           [ac_bits=$ac_bits1; ac_max=$ac_max1])
+         test "$ac_max" = "$ac_max1"
+       do :
+       done
+
+       # Add 1 to the number of bits until this fails.
+       while
+         ac_bits1=`expr $ac_bits + 1`
+         ac_shiftbits=`expr $ac_bits1 - 1 - $ac_signbit`
+         ac_max1="((((($1) 1 << $ac_shiftbits) - 1) << 1) + 1)"
+
+         AC_COMPILE_IFELSE(
+           [AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT([$3])],
+              [$ac_max < $ac_max1 && ($1) $ac_max1 == $ac_max1])],
+           [ac_bits=$ac_bits1; ac_max=$ac_max1])
+        test "$ac_max" = "$ac_max1"
+       do :
+       done
+
+       AS_VAR_SET(ac_vbits, [`expr $ac_bits - $ac_signbit`])
+     fi
+    ])
+  m4_ifval([$2],
+    [case $2:AS_VAR_GET(ac_vbits) in #(
+     ?*:?*)
+       AC_DEFINE_UNQUOTED([$2], [AS_VAR_GET(ac_vbits)],
+        [Define to the number of value bits for the integer type `$1', if it
+         is a valid type.]);;
+     esac])
+  AS_VAR_POPDEF([ac_vbits])dnl
+  AS_VAR_POPDEF([ac_sbits])dnl
+])# _AC_C_TYPE_VALUE_BITS_INTEGER
+
+
+# _AC_C_TYPE_RANGE_INTEGER(TYPE, [MIN-VARIABLE], MAX-VARIABLE,
+#                        [VALUE-BITS-VARIABLE],
+#                        [INCLUDES = DEFAULT-INCLUDES])
+# ------------------------------------------------------------
+# Compute the bounds (and optionally the value bits) of the integer TYPE
+# and define MIN-VARIABLE, MAX-VARIABLE, and VALUE-BITS-VARIABLE to those
+# bounds and bits, respectively.  The bounds are expressions that are
+# suitable for use in the preprocessor, the value bits is an integer literal.
+# If one or both of MIN-VARIABLE or VALUE-BITS-VARIABLE are absent, do not
+# define them.  If either of the three variables is already defined through
+# INCLUDES, do not define it.  If TYPE does not work, do not define either
+# variable.  Works OK if cross compiling.
+#
+# This macro makes use of the internals ac_1, ac_bits, ac_signbit of the
+# previous macro.
+AC_DEFUN([_AC_C_TYPE_RANGE_INTEGER],
+[
+  m4_ifval([$3], [], [m4_fatal([$0: need MAX-VARIABLE argument])])dnl
+  AS_VAR_PUSHDEF([ac_sbits], [ac_cv_signbits_$1])dnl
+  AS_VAR_PUSHDEF([ac_vbits], [ac_cv_valuebits_$1])dnl
+  AS_VAR_PUSHDEF([ac_cache_min], [ac_cv_value_$2])dnl
+  AS_VAR_PUSHDEF([ac_cache_max], [ac_cv_value_$3])dnl
+
+  _AC_C_TYPE_SIGNBIT_INTEGER([$1], [$5])
+
+  if test -n "AS_VAR_GET(ac_sbits)"; then
+    dnl Since AC_CACHE_CHECK does not have the functionality to
+    dnl execute some COMMANDS-TO-SET-THEM when one of multiple
+    dnl CACHE-IDs is not set, we have to commit a minor Autoconf crime
+    dnl here by precomputing and only feeding the cache variable with
+    dnl the result afterwards, to avoid garbled output.
+    dnl (The crime being that the work is done before the output that
+    dnl naturally associates with it is seen by the impatient user.)
+    ac_val_defined=
+    if test -z "AS_VAR_GET(ac_cache_max)"; then
+      AC_COMPILE_IFELSE(
+        [AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT([$5])], [$3 == $3])],
+        [ac_val_defined=yes], [ac_val_defined=no])
+    fi
+    dnl Compute the value bits if
+    dnl - either ac_val_defined=no and they are not cached yet,
+    dnl - or we want to know the value bits anyway.
+    case AS_VAR_GET(ac_cache_max):$ac_val_defined:$4 in #(
+    :no:* | *:*:?* )
+      _AC_C_TYPE_VALUE_BITS_INTEGER([$1], [$4], [$5]) ;;
+    esac
+  fi
+  AC_CACHE_CHECK([for $3], ac_cache_max,
+  [case $ac_val_defined:AS_VAR_GET(ac_sbits) in #(
+   *:)    AS_VAR_SET(ac_cache_max, [no]) ;; #(
+   yes:*) AS_VAR_SET(ac_cache_max, [yes]) ;; #(
+   *)     ac_shiftbits=`expr $ac_bits - 1 - $ac_signbit`
+         AS_VAR_SET(ac_cache_max,
+            ["(((($ac_1 << $ac_shiftbits) - 1) << 1) + 1)"]) ;;
+   esac])
+
+  case AS_VAR_GET(ac_cache_max) in #(
+  yes|no) ;; #(
+  *)
+    AC_DEFINE_UNQUOTED([$3], [AS_VAR_GET(ac_cache_max)],
+      [Define to the maximum value for the integer type `$1', if the
+       usual headers do not define $3 and if `$1' is a valid type.]);;
+  esac
+
+  m4_ifval([$2],
+    [if test -n "$2"; then
+       AC_CACHE_CHECK([for $2], ac_cache_min,
+        [if test "AS_VAR_GET(ac_cache_max)" = no; then
+           AS_VAR_SET(ac_cache_min, [no])
+         else
+           AC_COMPILE_IFELSE(
+             [AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT([$5])],
+                [$2 == $2])],
+             [AS_VAR_SET(ac_cache_min, [yes])],
+             [ac_min="(- $3)"
+              ac_min1="(-1 - $3)"
+              AC_COMPILE_IFELSE(
+                [AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT([$5])],
+                   [$ac_min1 < $ac_min && ($1) $ac_min1 == $ac_min1
+                    && ($1) $ac_min1 < 0])],
+                [ac_min=$ac_min1],
+                [AC_COMPILE_IFELSE(
+                   [AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT([$5])],
+                      [($1) -1 < 0])],
+                   [],
+                   [ac_min=0])])
+              AS_VAR_SET(ac_cache_min, [$ac_min])])
+          fi])
+
+     case AS_VAR_GET(ac_cache_min) in #(
+     yes|no) ;; #(
+     *)
+       AC_DEFINE_UNQUOTED([$2], [AS_VAR_GET(ac_cache_min)],
+        [Define to the minimum value for the integer type `$1', if the
+         usual headers do not define $2 and if `$1' is a valid type.]);;
+     esac
+     fi])
+  AS_VAR_POPDEF([ac_cache_max])dnl
+  AS_VAR_POPDEF([ac_cache_min])dnl
+  AS_VAR_POPDEF([ac_vbits])dnl
+  AS_VAR_POPDEF([ac_sbits])dnl
+])# _AC_C_TYPE_RANGE_INTEGER
+
+
+# AC_C_TYPE_RANGE_INTEGER(TYPE, [MIN-VARIABLE], MAX-VARIABLE,
+#                        [VALUE-BITS-VARIABLE],
+#                        [INCLUDES = DEFAULT-INCLUDES])
+# -----------------------------------------------------------
+# Public wrapper around the actual implementation.
+AC_DEFUN([AC_C_TYPE_RANGE_INTEGER],
+[_$0($@)
+])# AC_C_TYPE_RANGE_INTEGER




reply via email to

[Prev in Thread] Current Thread [Next in Thread]