Tizen 2.0 Release
[external/nettle.git] / aclocal.m4
1 dnl Try to detect the type of the third arg to getsockname() et al
2 AC_DEFUN([LSH_TYPE_SOCKLEN_T],
3 [AH_TEMPLATE([socklen_t], [Length type used by getsockopt])
4 AC_CACHE_CHECK([for socklen_t in sys/socket.h], ac_cv_type_socklen_t,
5 [AC_EGREP_HEADER(socklen_t, sys/socket.h,
6   [ac_cv_type_socklen_t=yes], [ac_cv_type_socklen_t=no])])
7 if test $ac_cv_type_socklen_t = no; then
8         AC_MSG_CHECKING(for AIX)
9         AC_EGREP_CPP(yes, [
10 #ifdef _AIX
11  yes
12 #endif
13 ],[
14 AC_MSG_RESULT(yes)
15 AC_DEFINE(socklen_t, size_t)
16 ],[
17 AC_MSG_RESULT(no)
18 AC_DEFINE(socklen_t, int)
19 ])
20 fi
21 ])
22
23 dnl Choose cc flags for compiling position independent code
24 dnl FIXME: Doesn't do the right thing when crosscompiling.
25 AC_DEFUN([LSH_CCPIC],
26 [AC_REQUIRE([AC_CANONICAL_HOST])dnl
27 AC_MSG_CHECKING(CCPIC)
28 AC_CACHE_VAL(lsh_cv_sys_ccpic,[
29   if test -z "$CCPIC" ; then
30     if test "$GCC" = yes ; then
31       case "$host_os" in
32         bsdi4.*)        CCPIC="-fPIC" ;;
33         bsdi*)          CCPIC="" ;;
34         darwin*)        CCPIC="-fPIC" ;;
35         # Could also use -fpic, depending on the number of symbol references
36         solaris*)       CCPIC="-fPIC" ;;
37         cygwin*)        CCPIC="" ;;
38         mingw32*)       CCPIC="" ;;
39         *)              CCPIC="-fpic" ;;
40       esac
41     else
42       case "$host_os" in
43         darwin*)        CCPIC="-fPIC" ;;
44         irix*)          CCPIC="-share" ;;
45         hpux*)          CCPIC="+z"; ;;
46         *freebsd*)      CCPIC="-fpic" ;;
47         sco*|sysv4.*)   CCPIC="-KPIC -dy -Bdynamic" ;;
48         solaris*)       CCPIC="-KPIC -Bdynamic" ;;
49         winnt*)         CCPIC="-shared" ;;
50         *)              CCPIC="" ;;
51       esac
52     fi
53   fi
54   OLD_CFLAGS="$CFLAGS"
55   CFLAGS="$CFLAGS $CCPIC"
56   AC_TRY_COMPILE([], [exit(0);],
57     lsh_cv_sys_ccpic="$CCPIC", lsh_cv_sys_ccpic='')
58   CFLAGS="$OLD_CFLAGS"
59 ])
60 CCPIC="$lsh_cv_sys_ccpic"
61 AC_MSG_RESULT($CCPIC)
62 AC_SUBST([CCPIC])])
63
64 dnl LSH_PATH_ADD(path-id, directory)
65 AC_DEFUN([LSH_PATH_ADD],
66 [AC_MSG_CHECKING($2)
67 ac_exists=no
68 if test -d "$2/." ; then
69   ac_real_dir=`cd $2 && pwd`
70   if test -n "$ac_real_dir" ; then
71     ac_exists=yes
72     for old in $1_REAL_DIRS ; do
73       ac_found=no
74       if test x$ac_real_dir = x$old ; then
75         ac_found=yes;
76         break;
77       fi
78     done
79     if test $ac_found = yes ; then
80       AC_MSG_RESULT(already added)
81     else
82       AC_MSG_RESULT(added)
83       # LDFLAGS="$LDFLAGS -L $2"
84       $1_REAL_DIRS="$ac_real_dir [$]$1_REAL_DIRS"
85       $1_DIRS="$2 [$]$1_DIRS"
86     fi
87   fi
88 fi
89 if test $ac_exists = no ; then
90   AC_MSG_RESULT(not found)
91 fi
92 ])
93
94 dnl LSH_RPATH_ADD(dir)
95 AC_DEFUN([LSH_RPATH_ADD], [LSH_PATH_ADD(RPATH_CANDIDATE, $1)])
96
97 dnl LSH_RPATH_INIT(candidates)
98 AC_DEFUN([LSH_RPATH_INIT],
99 [AC_REQUIRE([AC_CANONICAL_HOST])dnl
100 AC_MSG_CHECKING([for -R flag])
101 RPATHFLAG=''
102 case "$host_os" in
103   osf1*)                RPATHFLAG="-rpath " ;;
104   irix6.*|irix5.*)      RPATHFLAG="-rpath " ;;
105   solaris*)
106     if test "$TCC" = "yes"; then
107       # tcc doesn't know about -R
108       RPATHFLAG="-Wl,-R,"
109     else
110       RPATHFLAG=-R
111     fi
112     ;;
113   linux*)               RPATHFLAG="-Wl,-rpath," ;;
114   *)                    RPATHFLAG="" ;;
115 esac
116
117 if test x$RPATHFLAG = x ; then
118   AC_MSG_RESULT(none)
119 else
120   AC_MSG_RESULT([using $RPATHFLAG])
121 fi
122
123 RPATH_CANDIDATE_REAL_DIRS=''
124 RPATH_CANDIDATE_DIRS=''
125
126 AC_MSG_RESULT([Searching for libraries])
127
128 for d in $1 ; do
129   LSH_RPATH_ADD($d)
130 done
131 ])    
132
133 dnl Try to execute a main program, and if it fails, try adding some
134 dnl -R flag.
135 dnl LSH_RPATH_FIX
136 AC_DEFUN([LSH_RPATH_FIX],
137 [if test $cross_compiling = no -a "x$RPATHFLAG" != x ; then
138   ac_success=no
139   AC_TRY_RUN([int main(int argc, char **argv) { return 0; }],
140     ac_success=yes, ac_success=no, :)
141   
142   if test $ac_success = no ; then
143     AC_MSG_CHECKING([Running simple test program failed. Trying -R flags])
144 dnl echo RPATH_CANDIDATE_DIRS = $RPATH_CANDIDATE_DIRS
145     ac_remaining_dirs=''
146     ac_rpath_save_LDFLAGS="$LDFLAGS"
147     for d in $RPATH_CANDIDATE_DIRS ; do
148       if test $ac_success = yes ; then
149         ac_remaining_dirs="$ac_remaining_dirs $d"
150       else
151         LDFLAGS="$RPATHFLAG$d $LDFLAGS"
152 dnl echo LDFLAGS = $LDFLAGS
153         AC_TRY_RUN([int main(int argc, char **argv) { return 0; }],
154           [ac_success=yes
155           ac_rpath_save_LDFLAGS="$LDFLAGS"
156           AC_MSG_RESULT([adding $RPATHFLAG$d])
157           ],
158           [ac_remaining_dirs="$ac_remaining_dirs $d"], :)
159         LDFLAGS="$ac_rpath_save_LDFLAGS"
160       fi
161     done
162     RPATH_CANDIDATE_DIRS=$ac_remaining_dirs
163   fi
164   if test $ac_success = no ; then
165     AC_MSG_RESULT(failed)
166   fi
167 fi
168 ])
169
170 dnl Like AC_CHECK_LIB, but uses $KRB_LIBS rather than $LIBS.
171 dnl LSH_CHECK_KRB_LIB(LIBRARY, FUNCTION, [, ACTION-IF-FOUND [,
172 dnl                  ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]])
173
174 AC_DEFUN([LSH_CHECK_KRB_LIB],
175 [AC_CHECK_LIB([$1], [$2],
176   ifelse([$3], ,
177       [[ac_tr_lib=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \
178             -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
179         AC_DEFINE_UNQUOTED($ac_tr_lib)
180         KRB_LIBS="-l$1 $KRB_LIBS"
181       ]], [$3]),
182   ifelse([$4], , , [$4
183 ])dnl
184 , [$5 $KRB_LIBS])
185 ])
186
187 dnl LSH_LIB_ARGP(ACTION-IF-OK, ACTION-IF-BAD)
188 AC_DEFUN([LSH_LIB_ARGP],
189 [ ac_argp_save_LIBS="$LIBS"
190   ac_argp_save_LDFLAGS="$LDFLAGS"
191   ac_argp_ok=no
192   # First check if we can link with argp.
193   AC_SEARCH_LIBS(argp_parse, argp,
194   [ LSH_RPATH_FIX
195     AC_CACHE_CHECK([for working argp],
196       lsh_cv_lib_argp_works,
197       [ AC_TRY_RUN(
198 [#include <argp.h>
199 #include <stdlib.h>
200
201 static const struct argp_option
202 options[] =
203 {
204   { NULL, 0, NULL, 0, NULL, 0 }
205 };
206
207 struct child_state
208 {
209   int n;
210 };
211
212 static error_t
213 child_parser(int key, char *arg, struct argp_state *state)
214 {
215   struct child_state *input = (struct child_state *) state->input;
216   
217   switch(key)
218     {
219     default:
220       return ARGP_ERR_UNKNOWN;
221     case ARGP_KEY_END:
222       if (!input->n)
223         input->n = 1;
224       break;
225     }
226   return 0;
227 }
228
229 const struct argp child_argp =
230 {
231   options,
232   child_parser,
233   NULL, NULL, NULL, NULL, NULL
234 };
235
236 struct main_state
237 {
238   struct child_state child;
239   int m;
240 };
241
242 static error_t
243 main_parser(int key, char *arg, struct argp_state *state)
244 {
245   struct main_state *input = (struct main_state *) state->input;
246
247   switch(key)
248     {
249     default:
250       return ARGP_ERR_UNKNOWN;
251     case ARGP_KEY_INIT:
252       state->child_inputs[0] = &input->child;
253       break;
254     case ARGP_KEY_END:
255       if (!input->m)
256         input->m = input->child.n;
257       
258       break;
259     }
260   return 0;
261 }
262
263 static const struct argp_child
264 main_children[] =
265 {
266   { &child_argp, 0, "", 0 },
267   { NULL, 0, NULL, 0}
268 };
269
270 static const struct argp
271 main_argp =
272 { options, main_parser, 
273   NULL,
274   NULL,
275   main_children,
276   NULL, NULL
277 };
278
279 int main(int argc, char **argv)
280 {
281   struct main_state input = { { 0 }, 0 };
282   char *v[2] = { "foo", NULL };
283
284   argp_parse(&main_argp, 1, v, 0, NULL, &input);
285
286   if ( (input.m == 1) && (input.child.n == 1) )
287     return 0;
288   else
289     return 1;
290 }
291 ], lsh_cv_lib_argp_works=yes,
292    lsh_cv_lib_argp_works=no,
293    lsh_cv_lib_argp_works=no)])
294
295   if test x$lsh_cv_lib_argp_works = xyes ; then
296     ac_argp_ok=yes
297   else
298     # Reset link flags
299     LIBS="$ac_argp_save_LIBS"
300     LDFLAGS="$ac_argp_save_LDFLAGS"
301   fi])
302
303   if test x$ac_argp_ok = xyes ; then
304     ifelse([$1],, true, [$1])
305   else
306     ifelse([$2],, true, [$2])
307   fi   
308 ])
309
310 dnl LSH_GCC_ATTRIBUTES
311 dnl Check for gcc's __attribute__ construction
312
313 AC_DEFUN([LSH_GCC_ATTRIBUTES],
314 [AC_CACHE_CHECK(for __attribute__,
315                lsh_cv_c_attribute,
316 [ AC_TRY_COMPILE([
317 #include <stdlib.h>
318
319 static void foo(void) __attribute__ ((noreturn));
320
321 static void __attribute__ ((noreturn))
322 foo(void)
323 {
324   exit(1);
325 }
326 ],[],
327 lsh_cv_c_attribute=yes,
328 lsh_cv_c_attribute=no)])
329
330 AH_TEMPLATE([HAVE_GCC_ATTRIBUTE], [Define if the compiler understands __attribute__])
331 if test "x$lsh_cv_c_attribute" = "xyes"; then
332   AC_DEFINE(HAVE_GCC_ATTRIBUTE)
333 fi
334
335 AH_BOTTOM(
336 [#if __GNUC__ && HAVE_GCC_ATTRIBUTE
337 # define NORETURN __attribute__ ((__noreturn__))
338 # define PRINTF_STYLE(f, a) __attribute__ ((__format__ (__printf__, f, a)))
339 # define UNUSED __attribute__ ((__unused__))
340 #else
341 # define NORETURN
342 # define PRINTF_STYLE(f, a)
343 # define UNUSED
344 #endif
345 ])])
346
347 # Check for alloca, and include the standard blurb in config.h
348 AC_DEFUN([LSH_FUNC_ALLOCA],
349 [AC_FUNC_ALLOCA
350 AC_CHECK_HEADERS([malloc.h])
351 AH_BOTTOM(
352 [/* AIX requires this to be the first thing in the file.  */
353 #ifndef __GNUC__
354 # if HAVE_ALLOCA_H
355 #  include <alloca.h>
356 # else
357 #  ifdef _AIX
358  #pragma alloca
359 #  else
360 #   ifndef alloca /* predefined by HP cc +Olibcalls */
361 char *alloca ();
362 #   endif
363 #  endif
364 /* Needed for alloca on windows */
365 #  if HAVE_MALLOC_H
366 #   include <malloc.h>
367 #  endif
368 # endif
369 #else /* defined __GNUC__ */
370 # if HAVE_ALLOCA_H
371 #  include <alloca.h>
372 # endif
373 #endif
374 ])])
375
376 AC_DEFUN([LSH_FUNC_STRERROR],
377 [AC_CHECK_FUNCS(strerror)
378 AH_BOTTOM(
379 [#if HAVE_STRERROR
380 #define STRERROR strerror
381 #else
382 #define STRERROR(x) (sys_errlist[x])
383 #endif
384 ])])
385
386 AC_DEFUN([LSH_FUNC_STRSIGNAL],
387 [AC_CHECK_FUNCS(strsignal)
388 AC_CHECK_DECLS([sys_siglist, _sys_siglist])
389 AH_BOTTOM(
390 [#if HAVE_STRSIGNAL
391 # define STRSIGNAL strsignal
392 #else /* !HAVE_STRSIGNAL */
393 # if HAVE_DECL_SYS_SIGLIST
394 #  define STRSIGNAL(x) (sys_siglist[x])
395 # else
396 #  if HAVE_DECL__SYS_SIGLIST
397 #   define STRSIGNAL(x) (_sys_siglist[x])
398 #  else
399 #   define STRSIGNAL(x) "Unknown signal"
400 #   if __GNUC__
401 #    warning Using dummy STRSIGNAL
402 #   endif
403 #  endif
404 # endif
405 #endif /* !HAVE_STRSIGNAL */
406 ])])
407
408 dnl LSH_MAKE_CONDITIONAL(symbol, test)
409 AC_DEFUN([LSH_MAKE_CONDITIONAL],
410 [if $2 ; then
411   IF_$1=''
412   UNLESS_$1='# '
413 else
414   IF_$1='# '
415   UNLESS_$1=''
416 fi 
417 AC_SUBST(IF_$1)
418 AC_SUBST(UNLESS_$1)])
419
420 dnl LSH_DEPENDENCY_TRACKING
421
422 dnl Defines compiler flags DEP_FLAGS to generate dependency
423 dnl information, and DEP_PROCESS that is any shell commands needed for
424 dnl massaging the dependency information further. Dependencies are
425 dnl generated as a side effect of compilation. Dependency files
426 dnl themselves are not treated as targets.
427
428 AC_DEFUN([LSH_DEPENDENCY_TRACKING],
429 [AC_ARG_ENABLE(dependency_tracking,
430   AC_HELP_STRING([--disable-dependency-tracking],
431     [Disable dependency tracking. Dependency tracking doesn't work with BSD make]),,
432   [enable_dependency_tracking=yes])
433
434 DEP_FLAGS=''
435 DEP_PROCESS='true'
436 if test x$enable_dependency_tracking = xyes ; then
437   if test x$GCC = xyes ; then
438     gcc_version=`gcc --version | head -1`
439     case "$gcc_version" in
440       2.*|*[[!0-9.]]2.*)
441         enable_dependency_tracking=no
442         AC_MSG_WARN([Dependency tracking disabled, gcc-3.x is needed])
443       ;;
444       *)
445         DEP_FLAGS='-MT $[]@ -MD -MP -MF $[]@.d'
446         DEP_PROCESS='true'
447       ;;
448     esac
449   else
450     enable_dependency_tracking=no
451     AC_MSG_WARN([Dependency tracking disabled])
452   fi
453 fi
454
455 if test x$enable_dependency_tracking = xyes ; then
456   DEP_INCLUDE='include '
457 else
458   DEP_INCLUDE='# '
459 fi
460
461 AC_SUBST([DEP_INCLUDE])
462 AC_SUBST([DEP_FLAGS])
463 AC_SUBST([DEP_PROCESS])])
464
465 dnl  GMP_TRY_ASSEMBLE(asm-code,[action-success][,action-fail])
466 dnl  ----------------------------------------------------------
467 dnl  Attempt to assemble the given code.
468 dnl  Do "action-success" if this succeeds, "action-fail" if not.
469 dnl
470 dnl  conftest.o and conftest.out are available for inspection in
471 dnl  "action-success".  If either action does a "break" out of a loop then
472 dnl  an explicit "rm -f conftest*" will be necessary.
473 dnl
474 dnl  This is not unlike AC_TRY_COMPILE, but there's no default includes or
475 dnl  anything in "asm-code", everything wanted must be given explicitly.
476
477 AC_DEFUN([GMP_TRY_ASSEMBLE],
478 [cat >conftest.s <<EOF
479 [$1]
480 EOF
481 gmp_assemble="$CC $CFLAGS $CPPFLAGS -c conftest.s >conftest.out 2>&1"
482 if AC_TRY_EVAL(gmp_assemble); then
483   cat conftest.out >&AC_FD_CC
484   ifelse([$2],,:,[$2])
485 else
486   cat conftest.out >&AC_FD_CC
487   echo "configure: failed program was:" >&AC_FD_CC
488   cat conftest.s >&AC_FD_CC
489   ifelse([$3],,:,[$3])
490 fi
491 rm -f conftest*
492 ])
493
494 dnl @synopsis AX_CREATE_STDINT_H [( HEADER-TO-GENERATE [, HEADERS-TO-CHECK])]
495 dnl
496 dnl the "ISO C9X: 7.18 Integer types <stdint.h>" section requires the
497 dnl existence of an include file <stdint.h> that defines a set of 
498 dnl typedefs, especially uint8_t,int32_t,uintptr_t.
499 dnl Many older installations will not provide this file, but some will
500 dnl have the very same definitions in <inttypes.h>. In other enviroments
501 dnl we can use the inet-types in <sys/types.h> which would define the
502 dnl typedefs int8_t and u_int8_t respectivly.
503 dnl
504 dnl This macros will create a local "_stdint.h" or the headerfile given as 
505 dnl an argument. In many cases that file will just "#include <stdint.h>" 
506 dnl or "#include <inttypes.h>", while in other environments it will provide 
507 dnl the set of basic 'stdint's definitions/typedefs: 
508 dnl   int8_t,uint8_t,int16_t,uint16_t,int32_t,uint32_t,intptr_t,uintptr_t
509 dnl   int_least32_t.. int_fast32_t.. intmax_t
510 dnl which may or may not rely on the definitions of other files,
511 dnl or using the AC_CHECK_SIZEOF macro to determine the actual
512 dnl sizeof each type.
513 dnl
514 dnl if your header files require the stdint-types you will want to create an
515 dnl installable file mylib-int.h that all your other installable header
516 dnl may include. So if you have a library package named "mylib", just use
517 dnl      AX_CREATE_STDINT_H(mylib-int.h) 
518 dnl in configure.ac and go to install that very header file in Makefile.am
519 dnl along with the other headers (mylib.h) - and the mylib-specific headers
520 dnl can simply use "#include <mylib-int.h>" to obtain the stdint-types.
521 dnl
522 dnl Remember, if the system already had a valid <stdint.h>, the generated
523 dnl file will include it directly. No need for fuzzy HAVE_STDINT_H things...
524 dnl
525 dnl @, (status: used on new platforms) (see http://ac-archive.sf.net/gstdint/)
526 dnl @version $Id: aclocal.m4,v 1.1 2007/05/03 20:49:15 nisse Exp $
527 dnl @author  Guido Draheim <guidod@gmx.de> 
528
529 AC_DEFUN([AX_CREATE_STDINT_H],
530 [# ------ AX CREATE STDINT H -------------------------------------
531 AC_MSG_CHECKING([for stdint types])
532 ac_stdint_h=`echo ifelse($1, , _stdint.h, $1)`
533 # try to shortcircuit - if the default include path of the compiler
534 # can find a "stdint.h" header then we assume that all compilers can.
535 AC_CACHE_VAL([ac_cv_header_stdint_t],[
536 old_CXXFLAGS="$CXXFLAGS" ; CXXFLAGS=""
537 old_CPPFLAGS="$CPPFLAGS" ; CPPFLAGS=""
538 old_CFLAGS="$CFLAGS"     ; CFLAGS=""
539 AC_TRY_COMPILE([#include <stdint.h>],[int_least32_t v = 0;],
540 [ac_cv_stdint_result="(assuming C99 compatible system)"
541  ac_cv_header_stdint_t="stdint.h"; ],
542 [ac_cv_header_stdint_t=""])
543 CXXFLAGS="$old_CXXFLAGS"
544 CPPFLAGS="$old_CPPFLAGS"
545 CFLAGS="$old_CFLAGS" ])
546
547 v="... $ac_cv_header_stdint_h"
548 if test "$ac_stdint_h" = "stdint.h" ; then
549  AC_MSG_RESULT([(are you sure you want them in ./stdint.h?)])
550 elif test "$ac_stdint_h" = "inttypes.h" ; then
551  AC_MSG_RESULT([(are you sure you want them in ./inttypes.h?)])
552 elif test "_$ac_cv_header_stdint_t" = "_" ; then
553  AC_MSG_RESULT([(putting them into $ac_stdint_h)$v])
554 else
555  ac_cv_header_stdint="$ac_cv_header_stdint_t"
556  AC_MSG_RESULT([$ac_cv_header_stdint (shortcircuit)])
557 fi
558
559 if test "_$ac_cv_header_stdint_t" = "_" ; then # can not shortcircuit..
560
561 dnl .....intro message done, now do a few system checks.....
562 dnl btw, all CHECK_TYPE macros do automatically "DEFINE" a type, therefore
563 dnl we use the autoconf implementation detail _AC CHECK_TYPE_NEW instead
564
565 inttype_headers=`echo $2 | sed -e 's/,/ /g'`
566
567 ac_cv_stdint_result="(no helpful system typedefs seen)"
568 AC_CACHE_CHECK([for stdint uintptr_t], [ac_cv_header_stdint_x],[
569  ac_cv_header_stdint_x="" # the 1997 typedefs (inttypes.h)
570   AC_MSG_RESULT([(..)])
571   for i in stdint.h inttypes.h sys/inttypes.h $inttype_headers ; do
572    unset ac_cv_type_uintptr_t 
573    unset ac_cv_type_uint64_t
574    _AC_CHECK_TYPE_NEW(uintptr_t,[ac_cv_header_stdint_x=$i],dnl
575      continue,[#include <$i>])
576    AC_CHECK_TYPE(uint64_t,[and64="/uint64_t"],[and64=""],[#include<$i>])
577    ac_cv_stdint_result="(seen uintptr_t$and64 in $i)"
578    break;
579   done
580   AC_MSG_CHECKING([for stdint uintptr_t])
581  ])
582
583 if test "_$ac_cv_header_stdint_x" = "_" ; then
584 AC_CACHE_CHECK([for stdint uint32_t], [ac_cv_header_stdint_o],[
585  ac_cv_header_stdint_o="" # the 1995 typedefs (sys/inttypes.h)
586   AC_MSG_RESULT([(..)])
587   for i in inttypes.h sys/inttypes.h stdint.h $inttype_headers ; do
588    unset ac_cv_type_uint32_t
589    unset ac_cv_type_uint64_t
590    AC_CHECK_TYPE(uint32_t,[ac_cv_header_stdint_o=$i],dnl
591      continue,[#include <$i>])
592    AC_CHECK_TYPE(uint64_t,[and64="/uint64_t"],[and64=""],[#include<$i>])
593    ac_cv_stdint_result="(seen uint32_t$and64 in $i)"
594    break;
595   done
596   AC_MSG_CHECKING([for stdint uint32_t])
597  ])
598 fi
599
600 if test "_$ac_cv_header_stdint_x" = "_" ; then
601 if test "_$ac_cv_header_stdint_o" = "_" ; then
602 AC_CACHE_CHECK([for stdint u_int32_t], [ac_cv_header_stdint_u],[
603  ac_cv_header_stdint_u="" # the BSD typedefs (sys/types.h)
604   AC_MSG_RESULT([(..)])
605   for i in sys/types.h inttypes.h sys/inttypes.h $inttype_headers ; do
606    unset ac_cv_type_u_int32_t
607    unset ac_cv_type_u_int64_t
608    AC_CHECK_TYPE(u_int32_t,[ac_cv_header_stdint_u=$i],dnl
609      continue,[#include <$i>])
610    AC_CHECK_TYPE(u_int64_t,[and64="/u_int64_t"],[and64=""],[#include<$i>])
611    ac_cv_stdint_result="(seen u_int32_t$and64 in $i)"
612    break;
613   done
614   AC_MSG_CHECKING([for stdint u_int32_t])
615  ])
616 fi fi
617
618 dnl if there was no good C99 header file, do some typedef checks...
619 if test "_$ac_cv_header_stdint_x" = "_" ; then
620    AC_MSG_CHECKING([for stdint datatype model])
621    AC_MSG_RESULT([(..)])
622    AC_CHECK_SIZEOF(char)
623    AC_CHECK_SIZEOF(short)
624    AC_CHECK_SIZEOF(int)
625    AC_CHECK_SIZEOF(long)
626    AC_CHECK_SIZEOF(void*)
627    ac_cv_stdint_char_model=""
628    ac_cv_stdint_char_model="$ac_cv_stdint_char_model$ac_cv_sizeof_char"
629    ac_cv_stdint_char_model="$ac_cv_stdint_char_model$ac_cv_sizeof_short"
630    ac_cv_stdint_char_model="$ac_cv_stdint_char_model$ac_cv_sizeof_int"
631    ac_cv_stdint_long_model=""
632    ac_cv_stdint_long_model="$ac_cv_stdint_long_model$ac_cv_sizeof_int"
633    ac_cv_stdint_long_model="$ac_cv_stdint_long_model$ac_cv_sizeof_long"
634    ac_cv_stdint_long_model="$ac_cv_stdint_long_model$ac_cv_sizeof_voidp"
635    name="$ac_cv_stdint_long_model"
636    case "$ac_cv_stdint_char_model/$ac_cv_stdint_long_model" in
637     122/242)     name="$name,  IP16 (standard 16bit machine)" ;;
638     122/244)     name="$name,  LP32 (standard 32bit mac/win)" ;;
639     122/*)       name="$name        (unusual int16 model)" ;; 
640     124/444)     name="$name, ILP32 (standard 32bit unixish)" ;;
641     124/488)     name="$name,  LP64 (standard 64bit unixish)" ;;
642     124/448)     name="$name, LLP64 (unusual  64bit unixish)" ;;
643     124/*)       name="$name        (unusual int32 model)" ;; 
644     128/888)     name="$name, ILP64 (unusual  64bit numeric)" ;;
645     128/*)       name="$name        (unusual int64 model)" ;; 
646     222/*|444/*) name="$name        (unusual dsptype)" ;;
647      *)          name="$name        (very unusal model)" ;;
648    esac
649    AC_MSG_RESULT([combined for stdint datatype model...  $name])
650 fi
651
652 if test "_$ac_cv_header_stdint_x" != "_" ; then
653    ac_cv_header_stdint="$ac_cv_header_stdint_x"
654 elif  test "_$ac_cv_header_stdint_o" != "_" ; then
655    ac_cv_header_stdint="$ac_cv_header_stdint_o"
656 elif  test "_$ac_cv_header_stdint_u" != "_" ; then
657    ac_cv_header_stdint="$ac_cv_header_stdint_u"
658 else
659    ac_cv_header_stdint="stddef.h"
660 fi
661
662 AC_MSG_CHECKING([for extra inttypes in chosen header])
663 AC_MSG_RESULT([($ac_cv_header_stdint)])
664 dnl see if int_least and int_fast types are present in _this_ header.
665 unset ac_cv_type_int_least32_t
666 unset ac_cv_type_int_fast32_t
667 AC_CHECK_TYPE(int_least32_t,,,[#include <$ac_cv_header_stdint>])
668 AC_CHECK_TYPE(int_fast32_t,,,[#include<$ac_cv_header_stdint>])
669 AC_CHECK_TYPE(intmax_t,,,[#include <$ac_cv_header_stdint>])
670
671 fi # shortcircut to system "stdint.h"
672 # ------------------ PREPARE VARIABLES ------------------------------
673 if test "$GCC" = "yes" ; then
674 ac_cv_stdint_message="using gnu compiler "`$CC --version | head -1` 
675 else
676 ac_cv_stdint_message="using $CC"
677 fi
678
679 AC_MSG_RESULT([make use of $ac_cv_header_stdint in $ac_stdint_h dnl
680 $ac_cv_stdint_result])
681
682 # ----------------- DONE inttypes.h checks START header -------------
683 AC_CONFIG_COMMANDS([$ac_stdint_h],[
684 AC_MSG_NOTICE(creating $ac_stdint_h : $_ac_stdint_h)
685 ac_stdint=$tmp/_stdint.h
686
687 echo "#ifndef" $_ac_stdint_h >$ac_stdint
688 echo "#define" $_ac_stdint_h "1" >>$ac_stdint
689 echo "#ifndef" _GENERATED_STDINT_H >>$ac_stdint
690 echo "#define" _GENERATED_STDINT_H '"'$PACKAGE $VERSION'"' >>$ac_stdint
691 echo "/* generated $ac_cv_stdint_message */" >>$ac_stdint
692 if test "_$ac_cv_header_stdint_t" != "_" ; then 
693 echo "#define _STDINT_HAVE_STDINT_H" "1" >>$ac_stdint
694 fi
695
696 cat >>$ac_stdint <<STDINT_EOF
697
698 /* ................... shortcircuit part ........................... */
699
700 #if defined HAVE_STDINT_H || defined _STDINT_HAVE_STDINT_H
701 #include <stdint.h>
702 #else
703 #include <stddef.h>
704
705 /* .................... configured part ............................ */
706
707 STDINT_EOF
708
709 echo "/* whether we have a C99 compatible stdint header file */" >>$ac_stdint
710 if test "_$ac_cv_header_stdint_x" != "_" ; then
711   ac_header="$ac_cv_header_stdint_x"
712   echo "#define _STDINT_HEADER_INTPTR" '"'"$ac_header"'"' >>$ac_stdint
713 else
714   echo "/* #undef _STDINT_HEADER_INTPTR */" >>$ac_stdint
715 fi
716
717 echo "/* whether we have a C96 compatible inttypes header file */" >>$ac_stdint
718 if  test "_$ac_cv_header_stdint_o" != "_" ; then
719   ac_header="$ac_cv_header_stdint_o"
720   echo "#define _STDINT_HEADER_UINT32" '"'"$ac_header"'"' >>$ac_stdint
721 else
722   echo "/* #undef _STDINT_HEADER_UINT32 */" >>$ac_stdint
723 fi
724
725 echo "/* whether we have a BSD compatible inet types header */" >>$ac_stdint
726 if  test "_$ac_cv_header_stdint_u" != "_" ; then
727   ac_header="$ac_cv_header_stdint_u"
728   echo "#define _STDINT_HEADER_U_INT32" '"'"$ac_header"'"' >>$ac_stdint
729 else
730   echo "/* #undef _STDINT_HEADER_U_INT32 */" >>$ac_stdint
731 fi
732
733 echo "" >>$ac_stdint
734
735 if test "_$ac_header" != "_" ; then if test "$ac_header" != "stddef.h" ; then
736   echo "#include <$ac_header>" >>$ac_stdint
737   echo "" >>$ac_stdint
738 fi fi
739
740 echo "/* which 64bit typedef has been found */" >>$ac_stdint
741 if test "$ac_cv_type_uint64_t" = "yes" ; then
742 echo "#define   _STDINT_HAVE_UINT64_T" "1"  >>$ac_stdint
743 else
744 echo "/* #undef _STDINT_HAVE_UINT64_T */" >>$ac_stdint
745 fi
746 if test "$ac_cv_type_u_int64_t" = "yes" ; then
747 echo "#define   _STDINT_HAVE_U_INT64_T" "1"  >>$ac_stdint
748 else
749 echo "/* #undef _STDINT_HAVE_U_INT64_T */" >>$ac_stdint
750 fi
751 echo "" >>$ac_stdint
752
753 echo "/* which type model has been detected */" >>$ac_stdint
754 if test "_$ac_cv_stdint_char_model" != "_" ; then
755 echo "#define   _STDINT_CHAR_MODEL" "$ac_cv_stdint_char_model" >>$ac_stdint
756 echo "#define   _STDINT_LONG_MODEL" "$ac_cv_stdint_long_model" >>$ac_stdint
757 else
758 echo "/* #undef _STDINT_CHAR_MODEL // skipped */" >>$ac_stdint
759 echo "/* #undef _STDINT_LONG_MODEL // skipped */" >>$ac_stdint
760 fi
761 echo "" >>$ac_stdint
762
763 echo "/* whether int_least types were detected */" >>$ac_stdint
764 if test "$ac_cv_type_int_least32_t" = "yes"; then
765 echo "#define   _STDINT_HAVE_INT_LEAST32_T" "1"  >>$ac_stdint
766 else
767 echo "/* #undef _STDINT_HAVE_INT_LEAST32_T */" >>$ac_stdint
768 fi
769 echo "/* whether int_fast types were detected */" >>$ac_stdint
770 if test "$ac_cv_type_int_fast32_t" = "yes"; then
771 echo "#define   _STDINT_HAVE_INT_FAST32_T" "1" >>$ac_stdint
772 else
773 echo "/* #undef _STDINT_HAVE_INT_FAST32_T */" >>$ac_stdint
774 fi
775 echo "/* whether intmax_t type was detected */" >>$ac_stdint
776 if test "$ac_cv_type_intmax_t" = "yes"; then
777 echo "#define   _STDINT_HAVE_INTMAX_T" "1" >>$ac_stdint
778 else
779 echo "/* #undef _STDINT_HAVE_INTMAX_T */" >>$ac_stdint
780 fi
781 echo "" >>$ac_stdint
782
783   cat >>$ac_stdint <<STDINT_EOF
784 /* .................... detections part ............................ */
785
786 /* whether we need to define bitspecific types from compiler base types */
787 #ifndef _STDINT_HEADER_INTPTR
788 #ifndef _STDINT_HEADER_UINT32
789 #ifndef _STDINT_HEADER_U_INT32
790 #define _STDINT_NEED_INT_MODEL_T
791 #else
792 #define _STDINT_HAVE_U_INT_TYPES
793 #endif
794 #endif
795 #endif
796
797 #ifdef _STDINT_HAVE_U_INT_TYPES
798 #undef _STDINT_NEED_INT_MODEL_T
799 #endif
800
801 #ifdef  _STDINT_CHAR_MODEL
802 #if     _STDINT_CHAR_MODEL+0 == 122 || _STDINT_CHAR_MODEL+0 == 124
803 #ifndef _STDINT_BYTE_MODEL
804 #define _STDINT_BYTE_MODEL 12
805 #endif
806 #endif
807 #endif
808
809 #ifndef _STDINT_HAVE_INT_LEAST32_T
810 #define _STDINT_NEED_INT_LEAST_T
811 #endif
812
813 #ifndef _STDINT_HAVE_INT_FAST32_T
814 #define _STDINT_NEED_INT_FAST_T
815 #endif
816
817 #ifndef _STDINT_HEADER_INTPTR
818 #define _STDINT_NEED_INTPTR_T
819 #ifndef _STDINT_HAVE_INTMAX_T
820 #define _STDINT_NEED_INTMAX_T
821 #endif
822 #endif
823
824
825 /* .................... definition part ............................ */
826
827 /* some system headers have good uint64_t */
828 #ifndef _HAVE_UINT64_T
829 #if     defined _STDINT_HAVE_UINT64_T  || defined HAVE_UINT64_T
830 #define _HAVE_UINT64_T
831 #elif   defined _STDINT_HAVE_U_INT64_T || defined HAVE_U_INT64_T
832 #define _HAVE_UINT64_T
833 typedef u_int64_t uint64_t;
834 #endif
835 #endif
836
837 #ifndef _HAVE_UINT64_T
838 /* .. here are some common heuristics using compiler runtime specifics */
839 #if defined __STDC_VERSION__ && defined __STDC_VERSION__ >= 199901L
840 #define _HAVE_UINT64_T
841 typedef long long int64_t;
842 typedef unsigned long long uint64_t;
843
844 #elif !defined __STRICT_ANSI__
845 #if defined _MSC_VER || defined __WATCOMC__ || defined __BORLANDC__
846 #define _HAVE_UINT64_T
847 typedef __int64 int64_t;
848 typedef unsigned __int64 uint64_t;
849
850 #elif defined __GNUC__ || defined __MWERKS__ || defined __ELF__
851 /* note: all ELF-systems seem to have loff-support which needs 64-bit */
852 #if !defined _NO_LONGLONG
853 #define _HAVE_UINT64_T
854 typedef long long int64_t;
855 typedef unsigned long long uint64_t;
856 #endif
857
858 #elif defined __alpha || (defined __mips && defined _ABIN32)
859 #if !defined _NO_LONGLONG
860 typedef long int64_t;
861 typedef unsigned long uint64_t;
862 #endif
863   /* compiler/cpu type to define int64_t */
864 #endif
865 #endif
866 #endif
867
868 #if defined _STDINT_HAVE_U_INT_TYPES
869 /* int8_t int16_t int32_t defined by inet code, redeclare the u_intXX types */
870 typedef u_int8_t uint8_t;
871 typedef u_int16_t uint16_t;
872 typedef u_int32_t uint32_t;
873
874 /* glibc compatibility */
875 #ifndef __int8_t_defined
876 #define __int8_t_defined
877 #endif
878 #endif
879
880 #ifdef _STDINT_NEED_INT_MODEL_T
881 /* we must guess all the basic types. Apart from byte-adressable system, */
882 /* there a few 32-bit-only dsp-systems that we guard with BYTE_MODEL 8-} */
883 /* (btw, those nibble-addressable systems are way off, or so we assume) */
884
885 dnl   /* have a look at "64bit and data size neutrality" at */
886 dnl   /* http://unix.org/version2/whatsnew/login_64bit.html */
887 dnl   /* (the shorthand "ILP" types always have a "P" part) */
888
889 #if defined _STDINT_BYTE_MODEL
890 #if _STDINT_LONG_MODEL+0 == 242
891 /* 2:4:2 =  IP16 = a normal 16-bit system                */
892 typedef unsigned char   uint8_t;
893 typedef unsigned short  uint16_t;
894 typedef unsigned long   uint32_t;
895 #ifndef __int8_t_defined
896 #define __int8_t_defined
897 typedef          char    int8_t;
898 typedef          short   int16_t;
899 typedef          long    int32_t;
900 #endif
901 #elif _STDINT_LONG_MODEL+0 == 244 || _STDINT_LONG_MODEL == 444
902 /* 2:4:4 =  LP32 = a 32-bit system derived from a 16-bit */
903 /* 4:4:4 = ILP32 = a normal 32-bit system                */
904 typedef unsigned char   uint8_t;
905 typedef unsigned short  uint16_t;
906 typedef unsigned int    uint32_t;
907 #ifndef __int8_t_defined
908 #define __int8_t_defined
909 typedef          char    int8_t;
910 typedef          short   int16_t;
911 typedef          int     int32_t;
912 #endif
913 #elif _STDINT_LONG_MODEL+0 == 484 || _STDINT_LONG_MODEL+0 == 488
914 /* 4:8:4 =  IP32 = a 32-bit system prepared for 64-bit    */
915 /* 4:8:8 =  LP64 = a normal 64-bit system                 */
916 typedef unsigned char   uint8_t;
917 typedef unsigned short  uint16_t;
918 typedef unsigned int    uint32_t;
919 #ifndef __int8_t_defined
920 #define __int8_t_defined
921 typedef          char    int8_t;
922 typedef          short   int16_t;
923 typedef          int     int32_t;
924 #endif
925 /* this system has a "long" of 64bit */
926 #ifndef _HAVE_UINT64_T
927 #define _HAVE_UINT64_T
928 typedef unsigned long   uint64_t;
929 typedef          long    int64_t;
930 #endif
931 #elif _STDINT_LONG_MODEL+0 == 448
932 /*      LLP64   a 64-bit system derived from a 32-bit system */
933 typedef unsigned char   uint8_t;
934 typedef unsigned short  uint16_t;
935 typedef unsigned int    uint32_t;
936 #ifndef __int8_t_defined
937 #define __int8_t_defined
938 typedef          char    int8_t;
939 typedef          short   int16_t;
940 typedef          int     int32_t;
941 #endif
942 /* assuming the system has a "long long" */
943 #ifndef _HAVE_UINT64_T
944 #define _HAVE_UINT64_T
945 typedef unsigned long long uint64_t;
946 typedef          long long  int64_t;
947 #endif
948 #else
949 #define _STDINT_NO_INT32_T
950 #endif
951 #else
952 #define _STDINT_NO_INT8_T
953 #define _STDINT_NO_INT32_T
954 #endif
955 #endif
956
957 /*
958  * quote from SunOS-5.8 sys/inttypes.h:
959  * Use at your own risk.  As of February 1996, the committee is squarely
960  * behind the fixed sized types; the "least" and "fast" types are still being
961  * discussed.  The probability that the "fast" types may be removed before
962  * the standard is finalized is high enough that they are not currently
963  * implemented.
964  */
965
966 #if defined _STDINT_NEED_INT_LEAST_T
967 typedef  int8_t    int_least8_t;
968 typedef  int16_t   int_least16_t;
969 typedef  int32_t   int_least32_t;
970 #ifdef _HAVE_UINT64_T
971 typedef  int64_t   int_least64_t;
972 #endif
973
974 typedef uint8_t   uint_least8_t;
975 typedef uint16_t  uint_least16_t;
976 typedef uint32_t  uint_least32_t;
977 #ifdef _HAVE_UINT64_T
978 typedef uint64_t  uint_least64_t;
979 #endif
980   /* least types */
981 #endif
982
983 #if defined _STDINT_NEED_INT_FAST_T
984 typedef  int8_t    int_fast8_t; 
985 typedef  int       int_fast16_t;
986 typedef  int32_t   int_fast32_t;
987 #ifdef _HAVE_UINT64_T
988 typedef  int64_t   int_fast64_t;
989 #endif
990
991 typedef uint8_t   uint_fast8_t; 
992 typedef unsigned  uint_fast16_t;
993 typedef uint32_t  uint_fast32_t;
994 #ifdef _HAVE_UINT64_T
995 typedef uint64_t  uint_fast64_t;
996 #endif
997   /* fast types */
998 #endif
999
1000 #ifdef _STDINT_NEED_INTMAX_T
1001 #ifdef _HAVE_UINT64_T
1002 typedef  int64_t       intmax_t;
1003 typedef uint64_t      uintmax_t;
1004 #else
1005 typedef          long  intmax_t;
1006 typedef unsigned long uintmax_t;
1007 #endif
1008 #endif
1009
1010 #ifdef _STDINT_NEED_INTPTR_T
1011 #ifndef __intptr_t_defined
1012 #define __intptr_t_defined
1013 /* we encourage using "long" to store pointer values, never use "int" ! */
1014 #if   _STDINT_LONG_MODEL+0 == 242 || _STDINT_LONG_MODEL+0 == 484
1015 typedef  unsinged int   uintptr_t;
1016 typedef           int    intptr_t;
1017 #elif _STDINT_LONG_MODEL+0 == 244 || _STDINT_LONG_MODEL+0 == 444
1018 typedef  unsigned long  uintptr_t;
1019 typedef           long   intptr_t;
1020 #elif _STDINT_LONG_MODEL+0 == 448 && defined _HAVE_UINT64_T
1021 typedef        uint64_t uintptr_t;
1022 typedef         int64_t  intptr_t;
1023 #else /* matches typical system types ILP32 and LP64 - but not IP16 or LLP64 */
1024 typedef  unsigned long  uintptr_t;
1025 typedef           long   intptr_t;
1026 #endif
1027 #endif
1028 #endif
1029
1030   /* shortcircuit*/
1031 #endif
1032   /* once */
1033 #endif
1034 #endif
1035 STDINT_EOF
1036     if cmp -s $ac_stdint_h $ac_stdint 2>/dev/null; then
1037       AC_MSG_NOTICE([$ac_stdint_h is unchanged])
1038     else
1039       ac_dir=`AS_DIRNAME(["$ac_stdint_h"])`
1040       AS_MKDIR_P(["$ac_dir"])
1041       rm -f $ac_stdint_h
1042       mv $ac_stdint $ac_stdint_h
1043     fi
1044 ],[# variables for create stdint.h replacement
1045 PACKAGE="$PACKAGE"
1046 VERSION="$VERSION"
1047 ac_stdint_h="$ac_stdint_h"
1048 _ac_stdint_h=AS_TR_CPP(_$PACKAGE-$ac_stdint_h)
1049 ac_cv_stdint_message="$ac_cv_stdint_message"
1050 ac_cv_header_stdint_t="$ac_cv_header_stdint_t"
1051 ac_cv_header_stdint_x="$ac_cv_header_stdint_x"
1052 ac_cv_header_stdint_o="$ac_cv_header_stdint_o"
1053 ac_cv_header_stdint_u="$ac_cv_header_stdint_u"
1054 ac_cv_type_uint64_t="$ac_cv_type_uint64_t"
1055 ac_cv_type_u_int64_t="$ac_cv_type_u_int64_t"
1056 ac_cv_stdint_char_model="$ac_cv_stdint_char_model"
1057 ac_cv_stdint_long_model="$ac_cv_stdint_long_model"
1058 ac_cv_type_int_least32_t="$ac_cv_type_int_least32_t"
1059 ac_cv_type_int_fast32_t="$ac_cv_type_int_fast32_t"
1060 ac_cv_type_intmax_t="$ac_cv_type_intmax_t"
1061 ])
1062 ])