1dnl AC_COMPILE_CHECK_SIZEOF (TYPE SUPPOSED-SIZE)
2dnl abort if the given type does not have the supposed size
3AC_DEFUN([AC_COMPILE_CHECK_SIZEOF], [
4    AC_MSG_CHECKING(that size of $1 is $2)
5    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[switch (0) case 0: case (sizeof ($1) == $2):;]])],
6                      [AC_MSG_RESULT([yes])], [AC_MSG_ERROR([can not build a default inttypes.h])])
7])
8
9dnl
10AC_DEFUN([AC_CHECK_LIRC],
11  [AC_ARG_ENABLE(lirc,
12     AS_HELP_STRING([--disable-lirc], [turn off LIRC support]),
13     enable_lirc=$enableval, enable_lirc=yes)
14
15  if test x"$enable_lirc" = xyes; then
16     have_lirc=yes
17     AC_REQUIRE_CPP
18     AC_CHECK_LIB(lirc_client,lirc_init,
19           AC_CHECK_HEADER(lirc/lirc_client.h, true, have_lirc=no), have_lirc=no)
20     if test "$have_lirc" = "yes"; then
21
22        if test x"$LIRC_PREFIX" != "x"; then
23           lirc_libprefix="$LIRC_PREFIX/lib"
24	   LIRC_INCLUDE="-I$LIRC_PREFIX/include"
25        fi
26        for llirc in $lirc_libprefix /lib /usr/lib /usr/local/lib; do
27          AC_CHECK_FILE("$llirc/liblirc_client.a",
28             LIRC_LIBS="$llirc/liblirc_client.a"
29             AC_DEFINE(HAVE_LIRC),,)
30        done
31     else
32         AC_MSG_RESULT([*** LIRC client support not available, LIRC support will be disabled ***]);
33     fi
34  fi
35
36     AC_SUBST(LIRC_LIBS)
37     AC_SUBST(LIRC_INCLUDE)
38])
39
40dnl AC_CHECK_GENERATE_INTTYPES_H (INCLUDE-DIRECTORY)
41dnl generate a default inttypes.h if the header file does not exist already
42AC_DEFUN([AC_CHECK_GENERATE_INTTYPES],
43    [AC_CHECK_HEADER([inttypes.h],,
44        [if test ! -d $1; then mkdir $1; fi
45        AC_CHECK_HEADER([stdint.h],
46            [cat >$1/inttypes.h << EOF
47#ifndef _INTTYPES_H
48#define _INTTYPES_H
49/* helper inttypes.h for people who do not have it on their system */
50
51#include <stdint.h>
52EOF
53            ],
54            [AC_COMPILE_CHECK_SIZEOF([char],[1])
55            AC_COMPILE_CHECK_SIZEOF([short],[2])
56            AC_COMPILE_CHECK_SIZEOF([int],[4])
57            AC_COMPILE_CHECK_SIZEOF([long long],[8])
58        cat >$1/inttypes.h << EOF
59#ifndef _INTTYPES_H
60#define _INTTYPES_H
61/* default inttypes.h for people who do not have it on their system */
62#if (!defined __int8_t_defined) && (!defined __BIT_TYPES_DEFINED__)
63#define __int8_t_defined
64typedef signed char int8_t;
65typedef signed short int16_t;
66typedef signed int int32_t;
67#ifdef ARCH_X86
68typedef signed long long int64_t;
69#endif
70#endif
71#if (!defined __uint8_t_defined) && (!defined _LINUX_TYPES_H)
72#define __uint8_t_defined
73typedef unsigned char uint8_t;
74typedef unsigned short uint16_t;
75typedef unsigned int uint32_t;
76#ifdef ARCH_X86
77typedef unsigned long long uint64_t;
78#endif
79#endif
80EOF
81            ])
82        cat >>$1/inttypes.h << EOF
83
84#ifdef WIN32
85#  define PRI64_PREFIX "I64"
86#else
87#  define PRI64_PREFIX "l"
88#endif
89
90#ifndef PRId8
91#  define PRId8 "d"
92#endif
93#ifndef PRId16
94#  define PRId16 "d"
95#endif
96#ifndef PRId32
97#  define PRId32 "d"
98#endif
99#ifndef PRId64
100#  define PRId64 PRI64_PREFIX "d"
101#endif
102
103#ifndef PRIu8
104#  define PRIu8 "u"
105#endif
106#ifndef PRIu16
107#  define PRIu16 "u"
108#endif
109#ifndef PRIu32
110#  define PRIu32 "u"
111#endif
112#ifndef PRIu64
113#  define PRIu64 PRI64_PREFIX "u"
114#endif
115
116#ifndef PRIx8
117#  define PRIx8 "x"
118#endif
119#ifndef PRIx16
120#  define PRIx16 "x"
121#endif
122#ifndef PRIx32
123#  define PRIx32 "x"
124#endif
125#ifndef PRIx64
126#  define PRIx64 PRI64_PREFIX "x"
127#endif
128
129#ifndef PRIX8
130#  define PRIX8 "X"
131#endif
132#ifndef PRIX16
133#  define PRIX16 "X"
134#endif
135#ifndef PRIX32
136#  define PRIX32 "X"
137#endif
138#ifndef PRIX64
139#  define PRIX64 PRI64_PREFIX "X"
140#endif
141
142#ifndef PRIdFAST8
143#  define PRIdFAST8 "d"
144#endif
145#ifndef PRIdFAST16
146#  define PRIdFAST16 "d"
147#endif
148#ifndef PRIdFAST32
149#  define PRIdFAST32 "d"
150#endif
151#ifndef PRIdFAST64
152#  define PRIdFAST64 "d"
153#endif
154
155#ifndef PRIuFAST8
156#  define PRIuFAST8 "u"
157#endif
158#ifndef PRIuFAST16
159#  define PRIuFAST16 "u"
160#endif
161#ifndef PRIuFAST32
162#  define PRIuFAST32 "u"
163#endif
164#ifndef PRIuFAST64
165#  define PRIuFAST64 PRI64_PREFIX "u"
166#endif
167
168#ifndef PRIxFAST8
169#  define PRIxFAST8 "x"
170#endif
171#ifndef PRIxFAST16
172#  define PRIxFAST16 "x"
173#endif
174#ifndef PRIxFAST32
175#  define PRIxFAST32 "x"
176#endif
177#ifndef PRIxFAST64
178#  define PRIxFAST64 PRI64_PREFIX "x"
179#endif
180
181#ifndef SCNd8
182#  define SCNd8 "hhd"
183#endif
184#ifndef SCNd16
185#  define SCNd16 "hd"
186#endif
187#ifndef SCNd32
188#  define SCNd32 "d"
189#endif
190#ifndef SCNd64
191#  define SCNd64 PRI64_PREFIX "d"
192#endif
193
194#ifndef SCNu8
195#  define SCNu8 "hhu"
196#endif
197#ifndef SCNu16
198#  define SCNu16 "hu"
199#endif
200#ifndef SCNu32
201#  define SCNu32 "u"
202#endif
203#ifndef SCNu64
204#  define SCNu64 PRI64_PREFIX "u"
205#endif
206
207#ifndef PRIdMAX
208#  define PRIdMAX PRId64
209#endif
210#ifndef PRIuMAX
211#  define PRIuMAX PRIu64
212#endif
213#ifndef PRIxMAX
214#  define PRIxMAX PRIx64
215#endif
216#ifndef SCNdMAX
217#  define SCNdMAX SCNd64
218#endif
219
220#endif
221EOF
222        ])])
223
224
225dnl Check for the type of the third argument of getsockname
226AC_DEFUN([AC_CHECK_SOCKLEN_T], [
227    AC_MSG_CHECKING([for socklen_t])
228    AC_LANG_PUSH([C])
229    AC_CACHE_VAL([ac_cv_socklen_t],
230                 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
231                                                       #ifdef _WIN32
232                                                       # include <winsock2.h>
233                                                       # include <ws2tcpip.h>
234                                                       #else
235                                                       # include <sys/socket.h>
236                                                       #endif]],
237                                                     [[socklen_t a=0; getsockname(0,(struct sockaddr*)0, &a)]])],
238                                    [ac_cv_socklen_t=socklen_t], [ac_cv_socklen_t=''])
239                  if test x"$ac_cv_socklen_t" = x""; then
240                      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
241                                                           #ifdef _WIN32
242                                                           # include <winsock2.h>
243                                                           # include <ws2tcpip.h>
244                                                           #else
245                                                           # include <sys/socket.h>
246                                                           #endif]],
247                                                         [[int a=0; getsockname(0,(struct sockaddr*)0, &a);]])],
248                                        [ac_cv_socklen_t=int], [ac_cv_socklen_t=size_t])
249                  fi])
250    AC_LANG_POP([C])
251    AC_MSG_RESULT([$ac_cv_socklen_t])
252    if test x"$ac_cv_socklen_t" != x"socklen_t"; then
253        AC_DEFINE_UNQUOTED([socklen_t], [$ac_cv_socklen_t], [Define the real type of socklen_t])
254    fi
255])
256