1dnl AC_C_RESTRICT
2dnl Do nothing if the compiler accepts the restrict keyword.
3dnl Otherwise define restrict to __restrict__ or __restrict if one of
4dnl those work, otherwise define restrict to be empty.
5AC_DEFUN([AC_C_RESTRICT],
6    [AC_MSG_CHECKING([for restrict])
7    ac_cv_c_restrict=no
8    for ac_kw in restrict __restrict__ __restrict; do
9	AC_TRY_COMPILE([],[char * $ac_kw p;],[ac_cv_c_restrict=$ac_kw; break])
10    done
11    AC_MSG_RESULT([$ac_cv_c_restrict])
12    case $ac_cv_c_restrict in
13	restrict) ;;
14	no)	AC_DEFINE([restrict],,
15		    [Define as `__restrict' if that's what the C compiler calls
16		    it, or to nothing if it is not supported.]) ;;
17	*)	AC_DEFINE_UNQUOTED([restrict],$ac_cv_c_restrict) ;;
18    esac])
19
20dnl AC_C_ALWAYS_INLINE
21dnl Define inline to something appropriate, including the new always_inline
22dnl attribute from gcc 3.1
23AC_DEFUN([AC_C_ALWAYS_INLINE],
24    [AC_C_INLINE
25    if test x"$GCC" = x"yes" -a x"$ac_cv_c_inline" = x"inline"; then
26	AC_MSG_CHECKING([for always_inline])
27	SAVE_CFLAGS="$CFLAGS"
28	CFLAGS="$CFLAGS -Wall -Werror"
29	AC_TRY_COMPILE([],[__attribute__ ((__always_inline__)) void f (void);],
30	    [ac_cv_always_inline=yes],[ac_cv_always_inline=no])
31	CFLAGS="$SAVE_CFLAGS"
32	AC_MSG_RESULT([$ac_cv_always_inline])
33	if test x"$ac_cv_always_inline" = x"yes"; then
34	    AC_DEFINE_UNQUOTED([inline],[__attribute__ ((__always_inline__))])
35	fi
36    fi])
37
38dnl AC_C_ATTRIBUTE_ALIGNED
39dnl define ATTRIBUTE_ALIGNED_MAX to the maximum alignment if this is supported
40AC_DEFUN([AC_C_ATTRIBUTE_ALIGNED],
41    [AC_CACHE_CHECK([__attribute__ ((aligned ())) support],
42	[ac_cv_c_attribute_aligned],
43	[ac_cv_c_attribute_aligned=0
44	for ac_cv_c_attr_align_try in 2 4 8 16 32 64; do
45	    AC_TRY_COMPILE([],
46		[static char c __attribute__ ((aligned($ac_cv_c_attr_align_try))) = 0; return c;],
47		[ac_cv_c_attribute_aligned=$ac_cv_c_attr_align_try])
48	done])
49    if test x"$ac_cv_c_attribute_aligned" != x"0"; then
50	AC_DEFINE_UNQUOTED([ATTRIBUTE_ALIGNED_MAX],
51	    [$ac_cv_c_attribute_aligned],[maximum supported data alignment])
52    fi])
53
54dnl AC_TRY_CFLAGS (CFLAGS, [ACTION-IF-WORKS], [ACTION-IF-FAILS])
55dnl check if $CC supports a given set of cflags
56AC_DEFUN([AC_TRY_CFLAGS],
57    [AC_MSG_CHECKING([if $CC supports $1 flags])
58    SAVE_CFLAGS="$CFLAGS"
59    CFLAGS="$1"
60    AC_TRY_COMPILE([],[],[ac_cv_try_cflags_ok=yes],[ac_cv_try_cflags_ok=no])
61    CFLAGS="$SAVE_CFLAGS"
62    AC_MSG_RESULT([$ac_cv_try_cflags_ok])
63    if test x"$ac_cv_try_cflags_ok" = x"yes"; then
64	ifelse([$2],[],[:],[$2])
65    else
66	ifelse([$3],[],[:],[$3])
67    fi])
68
69
70dnl AC_CHECK_GENERATE_INTTYPES_H (INCLUDE-DIRECTORY)
71dnl generate a default inttypes.h if the header file does not exist already
72AC_DEFUN([AC_CHECK_GENERATE_INTTYPES],
73    [rm -f $1/inttypes.h
74    AC_CHECK_HEADER([inttypes.h],[],
75	[AC_CHECK_SIZEOF([char])
76	AC_CHECK_SIZEOF([short])
77	AC_CHECK_SIZEOF([int])
78	if test x"$ac_cv_sizeof_char" != x"1" -o \
79	    x"$ac_cv_sizeof_short" != x"2" -o \
80	    x"$ac_cv_sizeof_int" != x"4"; then
81	    AC_MSG_ERROR([can not build a default inttypes.h])
82	fi
83	cat >$1/inttypes.h << EOF
84/* default inttypes.h for people who do not have it on their system */
85
86#ifndef _INTTYPES_H
87#define _INTTYPES_H
88#if (!defined __int8_t_defined) && (!defined __BIT_TYPES_DEFINED__)
89#define __int8_t_defined
90typedef signed char int8_t;
91typedef signed short int16_t;
92typedef signed int int32_t;
93#ifdef ARCH_X86
94typedef signed long long int64_t;
95#endif
96#endif
97#if (!defined _LINUX_TYPES_H)
98typedef unsigned char uint8_t;
99typedef unsigned short uint16_t;
100typedef unsigned int uint32_t;
101#ifdef ARCH_X86
102typedef unsigned long long uint64_t;
103#endif
104#endif
105#endif
106EOF
107	])])
108