1dnl @synopsis GCC_HEADER_STDINT [( HEADER-TO-GENERATE [, HEADERS-TO-CHECK])] 2dnl 3dnl the "ISO C9X: 7.18 Integer types <stdint.h>" section requires the 4dnl existence of an include file <stdint.h> that defines a set of 5dnl typedefs, especially uint8_t,int32_t,uintptr_t. 6dnl Many older installations will not provide this file, but some will 7dnl have the very same definitions in <inttypes.h>. In other enviroments 8dnl we can use the inet-types in <sys/types.h> which would define the 9dnl typedefs int8_t and u_int8_t respectivly. 10dnl 11dnl This macros will create a local "_stdint.h" or the headerfile given as 12dnl an argument. In many cases that file will pick the definition from a 13dnl "#include <stdint.h>" or "#include <inttypes.h>" statement, while 14dnl in other environments it will provide the set of basic 'stdint's defined: 15dnl int8_t,uint8_t,int16_t,uint16_t,int32_t,uint32_t,intptr_t,uintptr_t 16dnl int_least32_t.. int_fast32_t.. intmax_t 17dnl which may or may not rely on the definitions of other files. 18dnl 19dnl Sometimes the stdint.h or inttypes.h headers conflict with sys/types.h, 20dnl so we test the headers together with sys/types.h and always include it 21dnl into the generated header (to match the tests with the generated file). 22dnl Hopefully this is not a big annoyance. 23dnl 24dnl If your installed header files require the stdint-types you will want to 25dnl create an installable file mylib-int.h that all your other installable 26dnl header may include. So, for a library package named "mylib", just use 27dnl GCC_HEADER_STDINT(mylib-int.h) 28dnl in configure.in and install that header file in Makefile.am along with 29dnl the other headers (mylib.h). The mylib-specific headers can simply 30dnl use "#include <mylib-int.h>" to obtain the stdint-types. 31dnl 32dnl Remember, if the system already had a valid <stdint.h>, the generated 33dnl file will include it directly. No need for fuzzy HAVE_STDINT_H things... 34dnl 35dnl @author Guido Draheim <guidod@gmx.de>, Paolo Bonzini <bonzini@gnu.org> 36 37AC_DEFUN([GCC_HEADER_STDINT], 38[m4_define(_GCC_STDINT_H, m4_ifval($1, $1, _stdint.h)) 39 40inttype_headers=`echo inttypes.h sys/inttypes.h $2 | sed -e 's/,/ /g'` 41 42acx_cv_header_stdint=stddef.h 43acx_cv_header_stdint_kind="(already complete)" 44for i in stdint.h $inttype_headers; do 45 unset ac_cv_type_uintptr_t 46 unset ac_cv_type_uintmax_t 47 unset ac_cv_type_int_least32_t 48 unset ac_cv_type_int_fast32_t 49 unset ac_cv_type_uint64_t 50 _AS_ECHO_N([looking for a compliant stdint.h in $i, ]) 51 AC_CHECK_TYPE(uintmax_t,[acx_cv_header_stdint=$i],continue,[#include <sys/types.h> 52#include <$i>]) 53 AC_CHECK_TYPE(uintptr_t,,[acx_cv_header_stdint_kind="(mostly complete)"], [#include <sys/types.h> 54#include <$i>]) 55 AC_CHECK_TYPE(int_least32_t,,[acx_cv_header_stdint_kind="(mostly complete)"], [#include <sys/types.h> 56#include <$i>]) 57 AC_CHECK_TYPE(int_fast32_t,,[acx_cv_header_stdint_kind="(mostly complete)"], [#include <sys/types.h> 58#include <$i>]) 59 AC_CHECK_TYPE(uint64_t,,[acx_cv_header_stdint_kind="(lacks uint64_t)"], [#include <sys/types.h> 60#include <$i>]) 61 break 62done 63if test "$acx_cv_header_stdint" = stddef.h; then 64 acx_cv_header_stdint_kind="(lacks uintptr_t)" 65 for i in stdint.h $inttype_headers; do 66 unset ac_cv_type_uint32_t 67 unset ac_cv_type_uint64_t 68 _AS_ECHO_N([looking for an incomplete stdint.h in $i, ]) 69 AC_CHECK_TYPE(uint32_t,[acx_cv_header_stdint=$i],continue,[#include <sys/types.h> 70#include <$i>]) 71 AC_CHECK_TYPE(uint64_t,,[acx_cv_header_stdint_kind="(lacks uintptr_t and uint64_t)"], [#include <sys/types.h> 72#include <$i>]) 73 break 74 done 75fi 76if test "$acx_cv_header_stdint" = stddef.h; then 77 acx_cv_header_stdint_kind="(u_intXX_t style)" 78 for i in sys/types.h $inttype_headers; do 79 unset ac_cv_type_u_int32_t 80 unset ac_cv_type_u_int64_t 81 _AS_ECHO_N([looking for u_intXX_t types in $i, ]) 82 AC_CHECK_TYPE(u_int32_t,[acx_cv_header_stdint=$i],continue,[#include <sys/types.h> 83#include <$i>]) 84 AC_CHECK_TYPE(u_int64_t,,[acx_cv_header_stdint_kind="(u_intXX_t style, lacks u_int64_t)"], [#include <sys/types.h> 85#include <$i>]) 86 break 87 done 88fi 89if test "$acx_cv_header_stdint" = stddef.h; then 90 acx_cv_header_stdint_kind="(using manual detection)" 91fi 92 93test -z "$ac_cv_type_uintptr_t" && ac_cv_type_uintptr_t=no 94test -z "$ac_cv_type_uint64_t" && ac_cv_type_uint64_t=no 95test -z "$ac_cv_type_u_int64_t" && ac_cv_type_u_int64_t=no 96test -z "$ac_cv_type_int_least32_t" && ac_cv_type_int_least32_t=no 97test -z "$ac_cv_type_int_fast32_t" && ac_cv_type_int_fast32_t=no 98 99# ----------------- Summarize what we found so far 100 101AC_MSG_CHECKING([what to include in _GCC_STDINT_H]) 102 103case `AS_BASENAME(_GCC_STDINT_H)` in 104 stdint.h) AC_MSG_WARN([are you sure you want it there?]) ;; 105 inttypes.h) AC_MSG_WARN([are you sure you want it there?]) ;; 106 *) ;; 107esac 108 109AC_MSG_RESULT($acx_cv_header_stdint $acx_cv_header_stdint_kind) 110 111# ----------------- done included file, check C basic types -------- 112 113# Lacking an uintptr_t? Test size of void * 114case "$acx_cv_header_stdint:$ac_cv_type_uintptr_t" in 115 stddef.h:* | *:no) AC_CHECK_SIZEOF(void *) ;; 116esac 117 118# Lacking an uint64_t? Test size of long 119case "$acx_cv_header_stdint:$ac_cv_type_uint64_t:$ac_cv_type_u_int64_t" in 120 stddef.h:*:* | *:no:no) AC_CHECK_SIZEOF(long) ;; 121esac 122 123if test $acx_cv_header_stdint = stddef.h; then 124 # Lacking a good header? Test size of everything and deduce all types. 125 AC_CHECK_SIZEOF(int) 126 AC_CHECK_SIZEOF(short) 127 AC_CHECK_SIZEOF(char) 128 129 AC_MSG_CHECKING(for type equivalent to int8_t) 130 case "$ac_cv_sizeof_char" in 131 1) acx_cv_type_int8_t=char ;; 132 *) AC_MSG_ERROR(no 8-bit type, please report a bug) 133 esac 134 AC_MSG_RESULT($acx_cv_type_int8_t) 135 136 AC_MSG_CHECKING(for type equivalent to int16_t) 137 case "$ac_cv_sizeof_int:$ac_cv_sizeof_short" in 138 2:*) acx_cv_type_int16_t=int ;; 139 *:2) acx_cv_type_int16_t=short ;; 140 *) AC_MSG_ERROR(no 16-bit type, please report a bug) 141 esac 142 AC_MSG_RESULT($acx_cv_type_int16_t) 143 144 AC_MSG_CHECKING(for type equivalent to int32_t) 145 case "$ac_cv_sizeof_int:$ac_cv_sizeof_long" in 146 4:*) acx_cv_type_int32_t=int ;; 147 *:4) acx_cv_type_int32_t=long ;; 148 *) AC_MSG_ERROR(no 32-bit type, please report a bug) 149 esac 150 AC_MSG_RESULT($acx_cv_type_int32_t) 151fi 152 153# These tests are here to make the output prettier 154 155if test "$ac_cv_type_uint64_t" != yes && test "$ac_cv_type_u_int64_t" != yes; then 156 case "$ac_cv_sizeof_long" in 157 8) acx_cv_type_int64_t=long ;; 158 esac 159 AC_MSG_CHECKING(for type equivalent to int64_t) 160 AC_MSG_RESULT(${acx_cv_type_int64_t-'using preprocessor symbols'}) 161fi 162 163# Now we can use the above types 164 165if test "$ac_cv_type_uintptr_t" != yes; then 166 AC_MSG_CHECKING(for type equivalent to intptr_t) 167 case $ac_cv_sizeof_void_p in 168 2) acx_cv_type_intptr_t=int16_t ;; 169 4) acx_cv_type_intptr_t=int32_t ;; 170 8) acx_cv_type_intptr_t=int64_t ;; 171 *) AC_MSG_ERROR(no equivalent for intptr_t, please report a bug) 172 esac 173 AC_MSG_RESULT($acx_cv_type_intptr_t) 174fi 175 176# ----------------- done all checks, emit header ------------- 177AC_CONFIG_COMMANDS(_GCC_STDINT_H, [ 178if test "$GCC" = yes; then 179 echo "/* generated for " `$CC --version | sed 1q` "*/" > tmp-stdint.h 180else 181 echo "/* generated for $CC */" > tmp-stdint.h 182fi 183 184sed 's/^ *//' >> tmp-stdint.h <<EOF 185 186 #ifndef GCC_GENERATED_STDINT_H 187 #define GCC_GENERATED_STDINT_H 1 188 189 #include <sys/types.h> 190EOF 191 192if test "$acx_cv_header_stdint" != stdint.h; then 193 echo "#include <stddef.h>" >> tmp-stdint.h 194fi 195if test "$acx_cv_header_stdint" != stddef.h; then 196 echo "#include <$acx_cv_header_stdint>" >> tmp-stdint.h 197fi 198 199sed 's/^ *//' >> tmp-stdint.h <<EOF 200 /* glibc uses these symbols as guards to prevent redefinitions. */ 201 #ifdef __int8_t_defined 202 #define _INT8_T 203 #define _INT16_T 204 #define _INT32_T 205 #endif 206 #ifdef __uint32_t_defined 207 #define _UINT32_T 208 #endif 209 210EOF 211 212# ----------------- done header, emit basic int types ------------- 213if test "$acx_cv_header_stdint" = stddef.h; then 214 sed 's/^ *//' >> tmp-stdint.h <<EOF 215 216 #ifndef _UINT8_T 217 #define _UINT8_T 218 typedef unsigned $acx_cv_type_int8_t uint8_t; 219 #endif 220 221 #ifndef _UINT16_T 222 #define _UINT16_T 223 typedef unsigned $acx_cv_type_int16_t uint16_t; 224 #endif 225 226 #ifndef _UINT32_T 227 #define _UINT32_T 228 typedef unsigned $acx_cv_type_int32_t uint32_t; 229 #endif 230 231 #ifndef _INT8_T 232 #define _INT8_T 233 typedef $acx_cv_type_int8_t int8_t; 234 #endif 235 236 #ifndef _INT16_T 237 #define _INT16_T 238 typedef $acx_cv_type_int16_t int16_t; 239 #endif 240 241 #ifndef _INT32_T 242 #define _INT32_T 243 typedef $acx_cv_type_int32_t int32_t; 244 #endif 245EOF 246elif test "$ac_cv_type_u_int32_t" = yes; then 247 sed 's/^ *//' >> tmp-stdint.h <<EOF 248 249 /* int8_t int16_t int32_t defined by inet code, we do the u_intXX types */ 250 #ifndef _INT8_T 251 #define _INT8_T 252 #endif 253 #ifndef _INT16_T 254 #define _INT16_T 255 #endif 256 #ifndef _INT32_T 257 #define _INT32_T 258 #endif 259 260 #ifndef _UINT8_T 261 #define _UINT8_T 262 typedef u_int8_t uint8_t; 263 #endif 264 265 #ifndef _UINT16_T 266 #define _UINT16_T 267 typedef u_int16_t uint16_t; 268 #endif 269 270 #ifndef _UINT32_T 271 #define _UINT32_T 272 typedef u_int32_t uint32_t; 273 #endif 274EOF 275else 276 sed 's/^ *//' >> tmp-stdint.h <<EOF 277 278 /* Some systems have guard macros to prevent redefinitions, define them. */ 279 #ifndef _INT8_T 280 #define _INT8_T 281 #endif 282 #ifndef _INT16_T 283 #define _INT16_T 284 #endif 285 #ifndef _INT32_T 286 #define _INT32_T 287 #endif 288 #ifndef _UINT8_T 289 #define _UINT8_T 290 #endif 291 #ifndef _UINT16_T 292 #define _UINT16_T 293 #endif 294 #ifndef _UINT32_T 295 #define _UINT32_T 296 #endif 297EOF 298fi 299 300# ------------- done basic int types, emit int64_t types ------------ 301if test "$ac_cv_type_uint64_t" = yes; then 302 sed 's/^ *//' >> tmp-stdint.h <<EOF 303 304 /* system headers have good uint64_t and int64_t */ 305 #ifndef _INT64_T 306 #define _INT64_T 307 #endif 308 #ifndef _UINT64_T 309 #define _UINT64_T 310 #endif 311EOF 312elif test "$ac_cv_type_u_int64_t" = yes; then 313 sed 's/^ *//' >> tmp-stdint.h <<EOF 314 315 /* system headers have an u_int64_t (and int64_t) */ 316 #ifndef _INT64_T 317 #define _INT64_T 318 #endif 319 #ifndef _UINT64_T 320 #define _UINT64_T 321 typedef u_int64_t uint64_t; 322 #endif 323EOF 324elif test -n "$acx_cv_type_int64_t"; then 325 sed 's/^ *//' >> tmp-stdint.h <<EOF 326 327 /* architecture has a 64-bit type, $acx_cv_type_int64_t */ 328 #ifndef _INT64_T 329 #define _INT64_T 330 typedef $acx_cv_type_int64_t int64_t; 331 #endif 332 #ifndef _UINT64_T 333 #define _UINT64_T 334 typedef unsigned $acx_cv_type_int64_t uint64_t; 335 #endif 336EOF 337else 338 sed 's/^ *//' >> tmp-stdint.h <<EOF 339 340 /* some common heuristics for int64_t, using compiler-specific tests */ 341 #if defined __STDC_VERSION__ && (__STDC_VERSION__-0) >= 199901L 342 #ifndef _INT64_T 343 #define _INT64_T 344 typedef long long int64_t; 345 #endif 346 #ifndef _UINT64_T 347 #define _UINT64_T 348 typedef unsigned long long uint64_t; 349 #endif 350 351 #elif defined __GNUC__ && defined (__STDC__) && __STDC__-0 352 /* NextStep 2.0 cc is really gcc 1.93 but it defines __GNUC__ = 2 and 353 does not implement __extension__. But that compiler doesn't define 354 __GNUC_MINOR__. */ 355 # if __GNUC__ < 2 || (__NeXT__ && !__GNUC_MINOR__) 356 # define __extension__ 357 # endif 358 359 # ifndef _INT64_T 360 # define _INT64_T 361 __extension__ typedef long long int64_t; 362 # endif 363 # ifndef _UINT64_T 364 # define _UINT64_T 365 __extension__ typedef unsigned long long uint64_t; 366 # endif 367 368 #elif !defined __STRICT_ANSI__ 369 # if defined _MSC_VER || defined __WATCOMC__ || defined __BORLANDC__ 370 371 # ifndef _INT64_T 372 # define _INT64_T 373 typedef __int64 int64_t; 374 # endif 375 # ifndef _UINT64_T 376 # define _UINT64_T 377 typedef unsigned __int64 uint64_t; 378 # endif 379 # endif /* compiler */ 380 381 #endif /* ANSI version */ 382EOF 383fi 384 385# ------------- done int64_t types, emit intptr types ------------ 386if test "$ac_cv_type_uintptr_t" != yes; then 387 sed 's/^ *//' >> tmp-stdint.h <<EOF 388 389 /* Define intptr_t based on sizeof(void*) = $ac_cv_sizeof_void_p */ 390 typedef u$acx_cv_type_intptr_t uintptr_t; 391 typedef $acx_cv_type_intptr_t intptr_t; 392EOF 393fi 394 395# ------------- done intptr types, emit int_least types ------------ 396if test "$ac_cv_type_int_least32_t" != yes; then 397 sed 's/^ *//' >> tmp-stdint.h <<EOF 398 399 /* Define int_least types */ 400 typedef int8_t int_least8_t; 401 typedef int16_t int_least16_t; 402 typedef int32_t int_least32_t; 403 #ifdef _INT64_T 404 typedef int64_t int_least64_t; 405 #endif 406 407 typedef uint8_t uint_least8_t; 408 typedef uint16_t uint_least16_t; 409 typedef uint32_t uint_least32_t; 410 #ifdef _UINT64_T 411 typedef uint64_t uint_least64_t; 412 #endif 413EOF 414fi 415 416# ------------- done intptr types, emit int_fast types ------------ 417if test "$ac_cv_type_int_fast32_t" != yes; then 418 dnl NOTE: The following code assumes that sizeof (int) > 1. 419 dnl Fix when strange machines are reported. 420 sed 's/^ *//' >> tmp-stdint.h <<EOF 421 422 /* Define int_fast types. short is often slow */ 423 typedef int8_t int_fast8_t; 424 typedef int int_fast16_t; 425 typedef int32_t int_fast32_t; 426 #ifdef _INT64_T 427 typedef int64_t int_fast64_t; 428 #endif 429 430 typedef uint8_t uint_fast8_t; 431 typedef unsigned int uint_fast16_t; 432 typedef uint32_t uint_fast32_t; 433 #ifdef _UINT64_T 434 typedef uint64_t uint_fast64_t; 435 #endif 436EOF 437fi 438 439if test "$ac_cv_type_uintmax_t" != yes; then 440 sed 's/^ *//' >> tmp-stdint.h <<EOF 441 442 /* Define intmax based on what we found */ 443 #ifdef _INT64_T 444 typedef int64_t intmax_t; 445 #else 446 typedef long intmax_t; 447 #endif 448 #ifdef _UINT64_T 449 typedef uint64_t uintmax_t; 450 #else 451 typedef unsigned long uintmax_t; 452 #endif 453EOF 454fi 455 456sed 's/^ *//' >> tmp-stdint.h <<EOF 457 458 #endif /* GCC_GENERATED_STDINT_H */ 459EOF 460 461if test -r ]_GCC_STDINT_H[ && cmp -s tmp-stdint.h ]_GCC_STDINT_H[; then 462 rm -f tmp-stdint.h 463else 464 mv -f tmp-stdint.h ]_GCC_STDINT_H[ 465fi 466 467], [ 468GCC="$GCC" 469CC="$CC" 470acx_cv_header_stdint="$acx_cv_header_stdint" 471acx_cv_type_int8_t="$acx_cv_type_int8_t" 472acx_cv_type_int16_t="$acx_cv_type_int16_t" 473acx_cv_type_int32_t="$acx_cv_type_int32_t" 474acx_cv_type_int64_t="$acx_cv_type_int64_t" 475acx_cv_type_intptr_t="$acx_cv_type_intptr_t" 476ac_cv_type_uintmax_t="$ac_cv_type_uintmax_t" 477ac_cv_type_uintptr_t="$ac_cv_type_uintptr_t" 478ac_cv_type_uint64_t="$ac_cv_type_uint64_t" 479ac_cv_type_u_int64_t="$ac_cv_type_u_int64_t" 480ac_cv_type_u_int32_t="$ac_cv_type_u_int32_t" 481ac_cv_type_int_least32_t="$ac_cv_type_int_least32_t" 482ac_cv_type_int_fast32_t="$ac_cv_type_int_fast32_t" 483ac_cv_sizeof_void_p="$ac_cv_sizeof_void_p" 484]) 485 486]) 487