root/tags/jabberd-2.1.4/acinclude.m4

Revision 2, 14.6 KB (checked in by smoku, 3 years ago)

jabberstudio CVS import

Line 
1dnl ******** AC_COMPILE_CHECK_SIZEOF
2dnl Available from the GNU Autoconf Macro Archive at:
3dnl http://www.gnu.org/software/ac-archive/htmldoc/ac_compile_check_sizeof.html
4dnl
5AC_DEFUN([AC_COMPILE_CHECK_SIZEOF],
6[changequote(<<, >>)dnl
7dnl The name to #define.
8define(<<AC_TYPE_NAME>>, translit(sizeof_$1, [a-z *], [A-Z_P]))dnl
9dnl The cache variable name.
10define(<<AC_CV_NAME>>, translit(ac_cv_sizeof_$1, [ *], [_p]))dnl
11changequote([, ])dnl
12AC_MSG_CHECKING(size of $1)
13AC_CACHE_VAL(AC_CV_NAME,
14[for ac_size in 4 8 1 2 16 $2 ; do # List sizes in rough order of prevalence.
15  AC_TRY_COMPILE([#include "confdefs.h"
16#include <sys/types.h>
17$2
18], [switch (0) case 0: case (sizeof ($1) == $ac_size):;], AC_CV_NAME=$ac_size)
19  if test x$AC_CV_NAME != x ; then break; fi
20done
21])
22if test x$AC_CV_NAME = x ; then
23  AC_MSG_ERROR([cannot determine a size for $1])
24fi
25AC_MSG_RESULT($AC_CV_NAME)
26AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [The number of bytes in type $1])
27undefine([AC_TYPE_NAME])dnl
28undefine([AC_CV_NAME])dnl
29])
30
31dnl ******** AC_CREATE_STDINT_H
32dnl Available from the GNU Autoconf Macro Archive at:
33dnl http://www.gnu.org/software/ac-archive/htmldoc/ac_create_stdint_h.html
34dnl
35AC_DEFUN([AC_CREATE_STDINT_H],
36[# ------ AC CREATE STDINT H -------------------------------------
37AC_MSG_CHECKING([for stdint-types....])
38ac_stdint_h=`echo ifelse($1, , _stdint.h, $1)`
39if test "$ac_stdint_h" = "stdint.h" ; then
40 AC_MSG_RESULT("(are you sure you want them in ./stdint.h?)")
41elif test "$ac_stdint_h" = "inttypes.h" ; then
42 AC_MSG_RESULT("(are you sure you want them in ./inttypes.h?)")
43else
44 AC_MSG_RESULT("(putting them into $ac_stdint_h)")
45fi
46
47inttype_headers=`echo inttypes.h sys/inttypes.h sys/inttypes.h $2 \
48| sed -e 's/,/ /g'`
49
50 ac_cv_header_stdint_x="no-file"
51 ac_cv_header_stdint_o="no-file"
52 ac_cv_header_stdint_u="no-file"
53 for i in stdint.h $inttype_headers ; do
54   unset ac_cv_type_uintptr_t
55   unset ac_cv_type_uint64_t
56   _AC_CHECK_TYPE_NEW(uintptr_t,[ac_cv_header_stdint_x=$i],dnl
57     continue,[#include <$i>])
58   AC_CHECK_TYPE(uint64_t,[and64="(uint64_t too)"],[and64=""],[#include<$i>])
59   AC_MSG_RESULT(... seen our uintptr_t in $i $and64)
60   break;
61 done
62 if test "$ac_cv_header_stdint_x" = "no-file" ; then
63 for i in stdint.h $inttype_headers ; do
64   unset ac_cv_type_uint32_t
65   unset ac_cv_type_uint64_t
66   AC_CHECK_TYPE(uint32_t,[ac_cv_header_stdint_o=$i],dnl
67     continue,[#include <$i>])
68   AC_CHECK_TYPE(uint64_t,[and64="(uint64_t too)"],[and64=""],[#include<$i>])
69   AC_MSG_RESULT(... seen our uint32_t in $i $and64)
70   break;
71 done
72 if test "$ac_cv_header_stdint_o" = "no-file" ; then
73 for i in sys/types.h $inttype_headers ; do
74   unset ac_cv_type_u_int32_t
75   unset ac_cv_type_u_int64_t
76   AC_CHECK_TYPE(u_int32_t,[ac_cv_header_stdint_u=$i],dnl
77     continue,[#include <$i>])
78   AC_CHECK_TYPE(uint64_t,[and64="(u_int64_t too)"],[and64=""],[#include<$i>])
79   AC_MSG_RESULT(... seen our u_int32_t in $i $and64)
80   break;
81 done
82 fi
83 fi
84
85# ----------------- DONE inttypes.h checks MAYBE C basic types --------
86
87if test "$ac_cv_header_stdint_x" = "no-file" ; then
88   AC_COMPILE_CHECK_SIZEOF(char)
89   AC_COMPILE_CHECK_SIZEOF(short)
90   AC_COMPILE_CHECK_SIZEOF(int)
91   AC_COMPILE_CHECK_SIZEOF(long)
92   AC_COMPILE_CHECK_SIZEOF(void*)
93   ac_cv_header_stdint_test="yes"
94else
95   ac_cv_header_stdint_test="no"
96fi
97
98# ----------------- DONE inttypes.h checks START header -------------
99_ac_stdint_h=AS_TR_CPP(_$ac_stdint_h)
100AC_MSG_RESULT(creating $ac_stdint_h : $_ac_stdint_h)
101echo "#ifndef" $_ac_stdint_h >$ac_stdint_h
102echo "#define" $_ac_stdint_h "1" >>$ac_stdint_h
103echo "#ifndef" _GENERATED_STDINT_H >>$ac_stdint_h
104echo "#define" _GENERATED_STDINT_H '"'$PACKAGE $VERSION'"' >>$ac_stdint_h
105if test "$GCC" = "yes" ; then
106  echo "/* generated using a gnu compiler version" `$CC --version` "*/" \
107  >>$ac_stdint_h
108else
109  echo "/* generated using $CC */" >>$ac_stdint_h
110fi
111echo "" >>$ac_stdint_h
112
113if test "$ac_cv_header_stdint_x" != "no-file" ; then
114   ac_cv_header_stdint="$ac_cv_header_stdint_x"
115elif  test "$ac_cv_header_stdint_o" != "no-file" ; then
116   ac_cv_header_stdint="$ac_cv_header_stdint_o"
117elif  test "$ac_cv_header_stdint_u" != "no-file" ; then
118   ac_cv_header_stdint="$ac_cv_header_stdint_u"
119else
120   ac_cv_header_stdint="stddef.h"
121fi
122
123# ----------------- See if int_least and int_fast types are present
124unset ac_cv_type_int_least32_t
125unset ac_cv_type_int_fast32_t
126AC_CHECK_TYPE(int_least32_t,,,[#include <$ac_cv_header_stdint>])
127AC_CHECK_TYPE(int_fast32_t,,,[#include<$ac_cv_header_stdint>])
128
129if test "$ac_cv_header_stdint" != "stddef.h" ; then
130if test "$ac_cv_header_stdint" != "stdint.h" ; then
131AC_MSG_RESULT(..adding include stddef.h)
132   echo "#include <stddef.h>" >>$ac_stdint_h
133fi ; fi
134AC_MSG_RESULT(..adding include $ac_cv_header_stdint)
135   echo "#include <$ac_cv_header_stdint>" >>$ac_stdint_h
136echo "" >>$ac_stdint_h
137
138# ----------------- DONE header START basic int types -------------
139if test "$ac_cv_header_stdint_x" = "no-file" ; then
140   AC_MSG_RESULT(... need to look at C basic types)
141dnl ac_cv_header_stdint_test="yes" # moved up before creating the file
142else
143   AC_MSG_RESULT(... seen good stdint.h inttypes)
144dnl ac_cv_header_stdint_test="no"  # moved up before creating the file
145fi
146
147if test "$ac_cv_header_stdint_u" != "no-file" ; then
148   AC_MSG_RESULT(... seen bsd/sysv typedefs)
149   cat >>$ac_stdint_h <<EOF
150
151/* int8_t int16_t int32_t defined by inet code, redeclare the u_intXX types */
152typedef u_int8_t uint8_t;
153typedef u_int16_t uint16_t;
154typedef u_int32_t uint32_t;
155EOF
156    cat >>$ac_stdint_h <<EOF
157
158/* glibc compatibility */
159#ifndef __int8_t_defined
160#define __int8_t_defined
161#endif
162EOF
163fi
164
165ac_cv_sizeof_x="$ac_cv_sizeof_char:$ac_cv_sizeof_short"
166ac_cv_sizeof_X="$ac_cv_sizeof_x:$ac_cv_sizeof_int"
167ac_cv_sizeof_X="$ac_cv_sizeof_X:$ac_cv_sizeof_voidp:$ac_cv_sizeof_long"
168if test "$ac_cv_header_stdint" = "stddef.h" ; then
169#   we must guess all the basic types. Apart from byte-adressable system,
170# there a few 32-bit-only dsp-systems. nibble-addressable systems are way off.
171    cat >>$ac_stdint_h <<EOF
172/* ------------ BITSPECIFIC INTTYPES SECTION --------------- */
173EOF
174    t="typedefs for a"
175    case "$ac_cv_sizeof_X" in
176     1:2:2:2:4) AC_MSG_RESULT(..adding $t normal 16-bit system)
177                cat >>$ac_stdint_h <<EOF
178/*              a normal 16-bit system                       */
179typedef unsigned char   uint8_t;
180typedef unsigned short  uint16_t;
181typedef unsigned long   uint32_t;
182#ifndef __int8_t_defined
183#define __int8_t_defined
184typedef          char    int8_t;
185typedef          short   int16_t;
186typedef          long    int32_t;
187#endif
188EOF
189;;
190     1:2:2:4:4) AC_MSG_RESULT(..adding $t 32-bit system derived from a 16-bit)
191                cat >>$ac_stdint_h <<EOF
192/*              a 32-bit system derived from a 16-bit        */
193typedef unsigned char   uint8_t;
194typedef unsigned short  uint16_t;
195typedef unsigned int    uint32_t;
196#ifndef __int8_t_defined
197#define __int8_t_defined
198typedef          char    int8_t;
199typedef          short   int16_t;
200typedef          int     int32_t;
201#endif
202EOF
203;;
204     1:2:4:4:4) AC_MSG_RESULT(..adding $t normal 32-bit system)
205                cat >>$ac_stdint_h <<EOF
206/*              a normal 32-bit system                       */
207typedef unsigned char   uint8_t;
208typedef unsigned short  uint16_t;
209typedef unsigned int    uint32_t;
210#ifndef __int8_t_defined
211#define __int8_t_defined
212typedef          char    int8_t;
213typedef          short   int16_t;
214typedef          int     int32_t;
215#endif
216EOF
217;;
218     1:2:4:4:8) AC_MSG_RESULT(..adding $t 32-bit system prepared for 64-bit)
219                cat >>$ac_stdint_h <<EOF
220
221/*              a 32-bit system prepared for 64-bit          */
222typedef unsigned char   uint8_t;
223typedef unsigned short  uint16_t;
224typedef unsigned int    uint32_t;
225#ifndef __int8_t_defined
226#define __int8_t_defined
227typedef          char    int8_t;
228typedef          short   int16_t;
229typedef          int     int32_t;
230#endif
231EOF
232;;
233     1:2:4:8:8) AC_MSG_RESULT(..adding $t normal 64-bit system)
234                cat >>$ac_stdint_h <<EOF
235
236/*              a normal 64-bit system                       */
237typedef unsigned char   uint8_t;
238typedef unsigned short  uint16_t;
239typedef unsigned int    uint32_t;
240#ifndef __int8_t_defined
241#define __int8_t_defined
242typedef          char    int8_t;
243typedef          short   int16_t;
244typedef          int     int32_t;
245#endif
246EOF
247;;
248     1:2:4:8:4) AC_MSG_RESULT(..adding $t 64-bit system derived from a 32-bit)
249                cat >>$ac_stdint_h <<EOF
250
251/*              a 64-bit system derived from a 32-bit system */
252typedef unsigned char   uint8_t;
253typedef unsigned short  uint16_t;
254typedef unsigned int    uint32_t;
255#ifndef __int8_t_defined
256#define __int8_t_defined
257typedef          char    int8_t;
258typedef          short   int16_t;
259typedef          int     int32_t;
260#endif
261EOF
262;;
263  *)
264    AC_MSG_ERROR([ $ac_cv_sizeof_X dnl
265 what is that a system? contact the author, quick! http://ac-archive.sf.net])
266    exit 1
267;;
268   esac
269fi
270
271# ------------- DONE basic int types START int64_t types ------------
272if test "$ac_cv_type_uint64_t" = "yes"
273then AC_MSG_RESULT(... seen good uint64_t)
274     cat >>$ac_stdint_h <<EOF
275
276/* system headers have good uint64_t */
277#ifndef _HAVE_UINT64_T
278#define _HAVE_UINT64_T
279#endif
280EOF
281
282elif test "$ac_cv_type_u_int64_t" = "yes"
283then AC_MSG_RESULT(..adding typedef u_int64_t uint64_t)
284     cat >>$ac_stdint_h <<EOF
285
286/* system headers have an u_int64_t */
287#ifndef _HAVE_UINT64_T
288#define _HAVE_UINT64_T
289typedef u_int64_t uint64_t;
290#endif
291EOF
292else AC_MSG_RESULT(..adding generic uint64_t runtime checks)
293     cat >>$ac_stdint_h <<EOF
294
295/* -------------------- 64 BIT GENERIC SECTION -------------------- */
296/* here are some common heuristics using compiler runtime specifics */
297#if defined __STDC_VERSION__ && defined __STDC_VERSION__ > 199901L
298
299#ifndef _HAVE_UINT64_T
300#define _HAVE_UINT64_T
301typedef long long int64_t;
302typedef unsigned long long uint64_t;
303#endif
304
305#elif !defined __STRICT_ANSI__
306#if defined _MSC_VER || defined __WATCOMC__ || defined __BORLANDC__
307
308#ifndef _HAVE_UINT64_T
309#define _HAVE_UINT64_T
310typedef __int64 int64_t;
311typedef unsigned __int64 uint64_t;
312#endif
313
314#elif defined __GNUC__ || defined __MWERKS__ || defined __ELF__
315dnl /* note: all ELF-systems seem to have loff-support which needs 64-bit */
316
317#if !defined _NO_LONGLONG
318#ifndef _HAVE_UINT64_T
319#define _HAVE_UINT64_T
320typedef long long int64_t;
321typedef unsigned long long uint64_t;
322#endif
323#endif
324
325#elif defined __alpha || (defined __mips && defined _ABIN32)
326
327#if !defined _NO_LONGLONG
328#ifndef _HAVE_UINT64_T
329#define _HAVE_UINT64_T
330typedef long int64_t;
331typedef unsigned long uint64_t;
332#endif
333#endif
334  /* compiler/cpu type ... or just ISO C99 */
335#endif
336#endif
337EOF
338
339# plus a default 64-bit for systems that are likely to be 64-bit ready
340  case "$ac_cv_sizeof_x:$ac_cv_sizeof_voidp:$ac_cv_sizeof_long" in
341    1:2:8:8) AC_MSG_RESULT(..adding uint64_t default, normal 64-bit system)
342cat >>$ac_stdint_h <<EOF
343/* DEFAULT: */
344/* seen normal 64-bit system, CC has sizeof(long and void*) == 8 bytes */
345#ifndef _HAVE_UINT64_T
346#define _HAVE_UINT64_T
347typedef long int64_t;
348typedef unsigned long uint64_t;
349#endif
350EOF
351;;
352    1:2:4:8) AC_MSG_RESULT(..adding uint64_t default, typedef to long)
353cat >>$ac_stdint_h <<EOF
354/* DEFAULT: */
355/* seen 32-bit system prepared for 64-bit, CC has sizeof(long) == 8 bytes */
356#ifndef _HAVE_UINT64_T
357#define _HAVE_UINT64_T
358typedef long int64_t;
359typedef unsigned long uint64_t;
360#endif
361EOF
362;;
363    1:2:8:4) AC_MSG_RESULT(..adding uint64_t default, typedef long long)
364cat >>$ac_stdint_h <<EOF
365/* DEFAULT: */
366/* seen 64-bit derived from a 32-bit, CC has sizeof(long) == 4 bytes */
367#ifndef _HAVE_UINT64_T
368#define _HAVE_UINT64_T
369typedef long long int64_t;
370typedef unsigned long long uint64_t;
371#endif
372EOF
373;;
374   *)
375cat >>$ac_stdint_h <<EOF
376/* NOTE: */
377/* the configure-checks for the basic types did not make us believe */
378/* that we could add a fallback to a 'long long' typedef to int64_t */
379EOF
380  esac
381fi
382
383# ------------- DONE int64_t types START intptr types ------------
384if test "$ac_cv_header_stdint_x" = "no-file" ; then
385  cat >>$ac_stdint_h <<EOF
386
387/* -------------------------- INPTR SECTION --------------------------- */
388EOF
389  case "$ac_cv_sizeof_x:$ac_cv_sizeof_voidp" in
390  1:2:2)
391    a="int16_t" ; cat >>$ac_stdint_h <<EOF
392/* we tested sizeof(void*) to be of 2 chars, hence we declare it 16-bit */
393
394typedef uint16_t uintptr_t;
395typedef  int16_t  intptr_t;
396EOF
397;;
398  1:2:4)
399    a="int32_t" ; cat >>$ac_stdint_h <<EOF
400/* we tested sizeof(void*) to be of 4 chars, hence we declare it 32-bit */
401
402typedef uint32_t uintptr_t;
403typedef  int32_t  intptr_t;
404EOF
405;;
406  1:2:8)
407    a="int64_t" ; cat >>$ac_stdint_h <<EOF
408/* we tested sizeof(void*) to be of 8 chars, hence we declare it 64-bit */
409
410typedef uint64_t uintptr_t;
411typedef  int64_t  intptr_t;
412EOF
413;;
414  *)
415    a="long" ; cat >>$ac_stdint_h <<EOF
416/* we tested sizeof(void*) but got no guess, hence we declare it as if long */
417
418typedef unsigned long uintptr_t;
419typedef          long  intptr_t;
420EOF
421;;
422  esac
423AC_MSG_RESULT(..adding typedef $a intptr_t)
424fi
425
426# ------------- DONE intptr types START int_least types ------------
427if test "$ac_cv_type_int_least32_t" = "no"; then
428AC_MSG_RESULT(..adding generic int_least-types)
429     cat >>$ac_stdint_h <<EOF
430
431/* --------------GENERIC INT_LEAST ------------------ */
432
433typedef  int8_t    int_least8_t;
434typedef  int16_t   int_least16_t;
435typedef  int32_t   int_least32_t;
436#ifdef _HAVE_UINT64_T
437typedef  int64_t   int_least64_t;
438#endif
439
440typedef uint8_t   uint_least8_t;
441typedef uint16_t  uint_least16_t;
442typedef uint32_t  uint_least32_t;
443#ifdef _HAVE_UINT64_T
444typedef uint64_t  uint_least64_t;
445#endif
446EOF
447fi
448
449# ------------- DONE intptr types START int_least types ------------
450if test "$ac_cv_type_int_fast32_t" = "no"; then
451AC_MSG_RESULT(..adding generic int_fast-types)
452     cat >>$ac_stdint_h <<EOF
453
454/* --------------GENERIC INT_FAST ------------------ */
455
456typedef  int8_t    int_fast8_t;
457typedef  int32_t   int_fast16_t;
458typedef  int32_t   int_fast32_t;
459#ifdef _HAVE_UINT64_T
460typedef  int64_t   int_fast64_t;
461#endif
462
463typedef uint8_t   uint_fast8_t;
464typedef uint32_t  uint_fast16_t;
465typedef uint32_t  uint_fast32_t;
466#ifdef _HAVE_UINT64_T
467typedef uint64_t  uint_fast64_t;
468#endif
469EOF
470fi
471
472if test "$ac_cv_header_stdint_x" = "no-file" ; then
473     cat >>$ac_stdint_h <<EOF
474
475#ifdef _HAVE_UINT64_T
476typedef int64_t        intmax_t;
477typedef uint64_t      uintmax_t;
478#else
479typedef long int       intmax_t;
480typedef unsigned long uintmax_t;
481#endif
482EOF
483fi
484
485AC_MSG_RESULT(... DONE $ac_stdint_h)
486   cat >>$ac_stdint_h <<EOF
487
488  /* once */
489#endif
490#endif
491EOF
492])
493
494dnl quote from SunOS-5.8 sys/inttypes.h:
495dnl Use at your own risk.  As of February 1996, the committee is squarely
496dnl behind the fixed sized types; the "least" and "fast" types are still being
497dnl discussed.  The probability that the "fast" types may be removed before
498dnl the standard is finalized is high enough that they are not currently
499dnl implemented.
Note: See TracBrowser for help on using the browser.