Imported Upstream version 2.9.0
[debian/cc1111] / support / cpp / aclocal.m4
1 dnl See if stdbool.h properly defines bool and true/false.
2 AC_DEFUN(gcc_AC_HEADER_STDBOOL,
3 [AC_CACHE_CHECK([for working stdbool.h],
4   ac_cv_header_stdbool_h,
5 [AC_TRY_COMPILE([#include <stdbool.h>],
6 [bool foo = false;],
7 ac_cv_header_stdbool_h=yes, ac_cv_header_stdbool_h=no)])
8 if test $ac_cv_header_stdbool_h = yes; then
9   AC_DEFINE(HAVE_STDBOOL_H, 1,
10   [Define if you have a working <stdbool.h> header file.])
11 fi
12 ])
13
14 dnl See whether we can include both string.h and strings.h.
15 AC_DEFUN(gcc_AC_HEADER_STRING,
16 [AC_CACHE_CHECK([whether string.h and strings.h may both be included],
17   gcc_cv_header_string,
18 [AC_TRY_COMPILE([#include <string.h>
19 #include <strings.h>], , gcc_cv_header_string=yes, gcc_cv_header_string=no)])
20 if test $gcc_cv_header_string = yes; then
21   AC_DEFINE(STRING_WITH_STRINGS, 1, [Define if you can safely include both <string.h> and <strings.h>.])
22 fi
23 ])
24
25 dnl See whether we need a declaration for a function.
26 dnl The result is highly dependent on the INCLUDES passed in, so make sure
27 dnl to use a different cache variable name in this macro if it is invoked
28 dnl in a different context somewhere else.
29 dnl gcc_AC_CHECK_DECL(SYMBOL,
30 dnl     [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND [, INCLUDES]]])
31 AC_DEFUN(gcc_AC_CHECK_DECL,
32 [AC_MSG_CHECKING([whether $1 is declared])
33 AC_CACHE_VAL(gcc_cv_have_decl_$1,
34 [AC_TRY_COMPILE([$4],
35 [#ifndef $1
36 char *(*pfn) = (char *(*)) $1 ;
37 #endif], eval "gcc_cv_have_decl_$1=yes", eval "gcc_cv_have_decl_$1=no")])
38 if eval "test \"`echo '$gcc_cv_have_decl_'$1`\" = yes"; then
39   AC_MSG_RESULT(yes) ; ifelse([$2], , :, [$2])
40 else
41   AC_MSG_RESULT(no) ; ifelse([$3], , :, [$3])
42 fi
43 ])dnl
44
45 dnl Check multiple functions to see whether each needs a declaration.
46 dnl Arrange to define HAVE_DECL_<FUNCTION> to 0 or 1 as appropriate.
47 dnl gcc_AC_CHECK_DECLS(SYMBOLS,
48 dnl     [ACTION-IF-NEEDED [, ACTION-IF-NOT-NEEDED [, INCLUDES]]])
49 AC_DEFUN(gcc_AC_CHECK_DECLS,
50 [for ac_func in $1
51 do
52 changequote(, )dnl
53   ac_tr_decl=HAVE_DECL_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
54 changequote([, ])dnl
55 gcc_AC_CHECK_DECL($ac_func,
56   [AC_DEFINE_UNQUOTED($ac_tr_decl, 1) $2],
57   [AC_DEFINE_UNQUOTED($ac_tr_decl, 0) $3],
58 dnl It is possible that the include files passed in here are local headers
59 dnl which supply a backup declaration for the relevant prototype based on
60 dnl the definition of (or lack of) the HAVE_DECL_ macro.  If so, this test
61 dnl will always return success.  E.g. see libiberty.h's handling of
62 dnl `basename'.  To avoid this, we define the relevant HAVE_DECL_ macro to
63 dnl 1 so that any local headers used do not provide their own prototype
64 dnl during this test.
65 #undef $ac_tr_decl
66 #define $ac_tr_decl 1
67   $4
68 )
69 done
70 dnl Automatically generate config.h entries via autoheader.
71 if test x = y ; then
72   patsubst(translit([$1], [a-z], [A-Z]), [\w+],
73     [AC_DEFINE([HAVE_DECL_\&], 1,
74       [Define to 1 if we found this declaration otherwise define to 0.])])dnl
75 fi
76 ])
77
78 dnl See if symbolic links work and if not, try to substitute either hard links or simple copy.
79 AC_DEFUN(gcc_AC_PROG_LN_S,
80 [AC_MSG_CHECKING(whether ln -s works)
81 AC_CACHE_VAL(gcc_cv_prog_LN_S,
82 [rm -f conftestdata_t
83 echo >conftestdata_f
84 if ln -s conftestdata_f conftestdata_t 2>/dev/null
85 then
86   gcc_cv_prog_LN_S="ln -s"
87 else
88   if ln conftestdata_f conftestdata_t 2>/dev/null
89   then
90     gcc_cv_prog_LN_S=ln
91   else
92     gcc_cv_prog_LN_S=cp
93   fi
94 fi
95 rm -f conftestdata_f conftestdata_t
96 ])dnl
97 LN_S="$gcc_cv_prog_LN_S"
98 if test "$gcc_cv_prog_LN_S" = "ln -s"; then
99   AC_MSG_RESULT(yes)
100 else
101   if test "$gcc_cv_prog_LN_S" = "ln"; then
102     AC_MSG_RESULT([no, using ln])
103   else
104     AC_MSG_RESULT([no, and neither does ln, so using cp])
105   fi
106 fi
107 AC_SUBST(LN_S)dnl
108 ])
109
110 dnl See if hard links work and if not, try to substitute either symbolic links or simple copy.
111 AC_DEFUN(gcc_AC_PROG_LN,
112 [AC_MSG_CHECKING(whether ln works)
113 AC_CACHE_VAL(gcc_cv_prog_LN,
114 [rm -f conftestdata_t
115 echo >conftestdata_f
116 if ln conftestdata_f conftestdata_t 2>/dev/null
117 then
118   gcc_cv_prog_LN="ln"
119 else
120   if ln -s conftestdata_f conftestdata_t 2>/dev/null
121   then
122     gcc_cv_prog_LN="ln -s"
123   else
124     gcc_cv_prog_LN=cp
125   fi
126 fi
127 rm -f conftestdata_f conftestdata_t
128 ])dnl
129 LN="$gcc_cv_prog_LN"
130 if test "$gcc_cv_prog_LN" = "ln"; then
131   AC_MSG_RESULT(yes)
132 else
133   if test "$gcc_cv_prog_LN" = "ln -s"; then
134     AC_MSG_RESULT([no, using ln -s])
135   else
136     AC_MSG_RESULT([no, and neither does ln -s, so using cp])
137   fi
138 fi
139 AC_SUBST(LN)dnl
140 ])
141
142 dnl Check whether _Bool is built-in.
143 AC_DEFUN(gcc_AC_C__BOOL,
144 [AC_CACHE_CHECK(for built-in _Bool, gcc_cv_c__bool,
145 [AC_TRY_COMPILE(,
146 [_Bool foo;],
147 gcc_cv_c__bool=yes, gcc_cv_c__bool=no)
148 ])
149 if test $gcc_cv_c__bool = yes; then
150   AC_DEFINE(HAVE__BOOL, 1, [Define if the \`_Bool' type is built-in.])
151 fi
152 ])
153
154 dnl Define MKDIR_TAKES_ONE_ARG if mkdir accepts only one argument instead
155 dnl of the usual 2.
156 AC_DEFUN(gcc_AC_FUNC_MKDIR_TAKES_ONE_ARG,
157 [AC_CACHE_CHECK([if mkdir takes one argument], gcc_cv_mkdir_takes_one_arg,
158 [AC_TRY_COMPILE([
159 #include <sys/types.h>
160 #ifdef HAVE_SYS_STAT_H
161 # include <sys/stat.h>
162 #endif
163 #ifdef HAVE_UNISTD_H
164 # include <unistd.h>
165 #endif
166 #ifdef HAVE_DIRECT_H
167 # include <direct.h>
168 #endif], [mkdir ("foo", 0);],
169         gcc_cv_mkdir_takes_one_arg=no, gcc_cv_mkdir_takes_one_arg=yes)])
170 if test $gcc_cv_mkdir_takes_one_arg = yes ; then
171   AC_DEFINE(MKDIR_TAKES_ONE_ARG, 1, [Define if host mkdir takes a single argument.])
172 fi
173 ])
174
175 AC_DEFUN(gcc_AC_PROG_INSTALL,
176 [AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl
177 # Find a good install program.  We prefer a C program (faster),
178 # so one script is as good as another.  But avoid the broken or
179 # incompatible versions:
180 # SysV /etc/install, /usr/sbin/install
181 # SunOS /usr/etc/install
182 # IRIX /sbin/install
183 # AIX /bin/install
184 # AFS /usr/afsws/bin/install, which mishandles nonexistent args
185 # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
186 # ./install, which can be erroneously created by make from ./install.sh.
187 AC_MSG_CHECKING(for a BSD compatible install)
188 if test -z "$INSTALL"; then
189 AC_CACHE_VAL(ac_cv_path_install,
190 [  IFS="${IFS=  }"; ac_save_IFS="$IFS"; IFS="${IFS}:"
191   for ac_dir in $PATH; do
192     # Account for people who put trailing slashes in PATH elements.
193     case "$ac_dir/" in
194     /|./|.//|/etc/*|/usr/sbin/*|/usr/etc/*|/sbin/*|/usr/afsws/bin/*|/usr/ucb/*) ;;
195     *)
196       # OSF1 and SCO ODT 3.0 have their own names for install.
197       for ac_prog in ginstall scoinst install; do
198         if test -f $ac_dir/$ac_prog; then
199           if test $ac_prog = install &&
200             grep dspmsg $ac_dir/$ac_prog >/dev/null 2>&1; then
201             # AIX install.  It has an incompatible calling convention.
202             # OSF/1 installbsd also uses dspmsg, but is usable.
203             :
204           else
205             ac_cv_path_install="$ac_dir/$ac_prog -c"
206             break 2
207           fi
208         fi
209       done
210       ;;
211     esac
212   done
213   IFS="$ac_save_IFS"
214 ])dnl
215   if test "${ac_cv_path_install+set}" = set; then
216     INSTALL="$ac_cv_path_install"
217   else
218     # As a last resort, use the slow shell script.  We don't cache a
219     # path for INSTALL within a source directory, because that will
220     # break other packages using the cache if that directory is
221     # removed, or if the path is relative.
222     INSTALL="$ac_install_sh"
223   fi
224 fi
225 dnl We do special magic for INSTALL instead of AC_SUBST, to get
226 dnl relative paths right.
227 AC_MSG_RESULT($INSTALL)
228 AC_SUBST(INSTALL)dnl
229
230 # Use test -z because SunOS4 sh mishandles braces in ${var-val}.
231 # It thinks the first close brace ends the variable substitution.
232 test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
233 AC_SUBST(INSTALL_PROGRAM)dnl
234
235 test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
236 AC_SUBST(INSTALL_DATA)dnl
237 ])
238
239 #serial 1
240 dnl This test replaces the one in autoconf.
241 dnl Currently this macro should have the same name as the autoconf macro
242 dnl because gettext's gettext.m4 (distributed in the automake package)
243 dnl still uses it.  Otherwise, the use in gettext.m4 makes autoheader
244 dnl give these diagnostics:
245 dnl   configure.in:556: AC_TRY_COMPILE was called before AC_ISC_POSIX
246 dnl   configure.in:556: AC_TRY_RUN was called before AC_ISC_POSIX
247
248 undefine([AC_ISC_POSIX])
249 AC_DEFUN(AC_ISC_POSIX,
250   [
251     dnl This test replaces the obsolescent AC_ISC_POSIX kludge.
252     AC_CHECK_LIB(cposix, strerror, [LIBS="$LIBS -lcposix"])
253   ]
254 )
255
256
257 dnl GCC_PATH_PROG(VARIABLE, PROG-TO-CHECK-FOR [, VALUE-IF-NOT-FOUND [, PATH]])
258 dnl like AC_PATH_PROG but use other cache variables
259 AC_DEFUN(GCC_PATH_PROG,
260 [# Extract the first word of "$2", so it can be a program name with args.
261 set dummy $2; ac_word=[$]2
262 AC_MSG_CHECKING([for $ac_word])
263 AC_CACHE_VAL(gcc_cv_path_$1,
264 [case "[$]$1" in
265   /*)
266   gcc_cv_path_$1="[$]$1" # Let the user override the test with a path.
267   ;;
268   ?:/*)
269   gcc_cv_path_$1="[$]$1" # Let the user override the test with a dos path.
270   ;;
271   *)
272   IFS="${IFS=   }"; ac_save_ifs="$IFS"; IFS=":"
273 dnl $ac_dummy forces splitting on constant user-supplied paths.
274 dnl POSIX.2 word splitting is done only on the output of word expansions,
275 dnl not every word.  This closes a longstanding sh security hole.
276   ac_dummy="ifelse([$4], , $PATH, [$4])"
277   for ac_dir in $ac_dummy; do
278     test -z "$ac_dir" && ac_dir=.
279     if test -f $ac_dir/$ac_word; then
280       gcc_cv_path_$1="$ac_dir/$ac_word"
281       break
282     fi
283   done
284   IFS="$ac_save_ifs"
285 dnl If no 3rd arg is given, leave the cache variable unset,
286 dnl so GCC_PATH_PROGS will keep looking.
287 ifelse([$3], , , [  test -z "[$]gcc_cv_path_$1" && gcc_cv_path_$1="$3"
288 ])dnl
289   ;;
290 esac])dnl
291 $1="$gcc_cv_path_$1"
292 if test -n "[$]$1"; then
293   AC_MSG_RESULT([$]$1)
294 else
295   AC_MSG_RESULT(no)
296 fi
297 AC_SUBST($1)dnl
298 ])
299
300
301
302 dnl GCC_PATH_PROG_WITH_TEST(VARIABLE, PROG-TO-CHECK-FOR,
303 dnl   TEST-PERFORMED-ON-FOUND_PROGRAM [, VALUE-IF-NOT-FOUND [, PATH]])
304 AC_DEFUN(GCC_PATH_PROG_WITH_TEST,
305 [# Extract the first word of "$2", so it can be a program name with args.
306 set dummy $2; ac_word=[$]2
307 AC_MSG_CHECKING([for $ac_word])
308 AC_CACHE_VAL(gcc_cv_path_$1,
309 [case "[$]$1" in
310   /*)
311   gcc_cv_path_$1="[$]$1" # Let the user override the test with a path.
312   ;;
313   *)
314   IFS="${IFS=   }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
315   for ac_dir in ifelse([$5], , $PATH, [$5]); do
316     test -z "$ac_dir" && ac_dir=.
317     if test -f $ac_dir/$ac_word; then
318       if [$3]; then
319         gcc_cv_path_$1="$ac_dir/$ac_word"
320         break
321       fi
322     fi
323   done
324   IFS="$ac_save_ifs"
325 dnl If no 4th arg is given, leave the cache variable unset,
326 dnl so GCC_PATH_PROGS will keep looking.
327 ifelse([$4], , , [  test -z "[$]gcc_cv_path_$1" && gcc_cv_path_$1="$4"
328 ])dnl
329   ;;
330 esac])dnl
331 $1="$gcc_cv_path_$1"
332 if test -n "[$]$1"; then
333   AC_MSG_RESULT([$]$1)
334 else
335   AC_MSG_RESULT(no)
336 fi
337 AC_SUBST($1)dnl
338 ])
339
340 # Check whether mmap can map an arbitrary page from /dev/zero or with
341 # MAP_ANONYMOUS, without MAP_FIXED.
342 AC_DEFUN([AC_FUNC_MMAP_ANYWHERE],
343 [AC_CHECK_FUNCS(getpagesize)
344 # The test program for the next two tests is the same except for one
345 # set of ifdefs.
346 changequote({{{,}}})dnl
347 {{{cat >ct-mmap.inc <<'EOF'
348 #include <sys/types.h>
349 #include <sys/mman.h>
350 #include <fcntl.h>
351 #include <signal.h>
352 #include <setjmp.h>
353 #include <stdio.h>
354
355 #if !defined (MAP_ANONYMOUS) && defined (MAP_ANON)
356 # define MAP_ANONYMOUS MAP_ANON
357 #endif
358
359 /* This mess was copied from the GNU getpagesize.h.  */
360 #ifndef HAVE_GETPAGESIZE
361 # ifdef HAVE_UNISTD_H
362 #  include <unistd.h>
363 # endif
364
365 /* Assume that all systems that can run configure have sys/param.h.  */
366 # ifndef HAVE_SYS_PARAM_H
367 #  define HAVE_SYS_PARAM_H 1
368 # endif
369
370 # ifdef _SC_PAGESIZE
371 #  define getpagesize() sysconf(_SC_PAGESIZE)
372 # else /* no _SC_PAGESIZE */
373 #  ifdef HAVE_SYS_PARAM_H
374 #   include <sys/param.h>
375 #   ifdef EXEC_PAGESIZE
376 #    define getpagesize() EXEC_PAGESIZE
377 #   else /* no EXEC_PAGESIZE */
378 #    ifdef NBPG
379 #     define getpagesize() NBPG * CLSIZE
380 #     ifndef CLSIZE
381 #      define CLSIZE 1
382 #     endif /* no CLSIZE */
383 #    else /* no NBPG */
384 #     ifdef NBPC
385 #      define getpagesize() NBPC
386 #     else /* no NBPC */
387 #      ifdef PAGESIZE
388 #       define getpagesize() PAGESIZE
389 #      endif /* PAGESIZE */
390 #     endif /* no NBPC */
391 #    endif /* no NBPG */
392 #   endif /* no EXEC_PAGESIZE */
393 #  else /* no HAVE_SYS_PARAM_H */
394 #   define getpagesize() 8192   /* punt totally */
395 #  endif /* no HAVE_SYS_PARAM_H */
396 # endif /* no _SC_PAGESIZE */
397
398 #endif /* no HAVE_GETPAGESIZE */
399
400 #ifndef MAP_FAILED
401 # define MAP_FAILED -1
402 #endif
403
404 #undef perror_exit
405 #define perror_exit(str, val) \
406   do { perror(str); exit(val); } while (0)
407
408 /* Some versions of cygwin mmap require that munmap is called with the
409    same parameters as mmap.  GCC expects that this is not the case.
410    Test for various forms of this problem.  Warning - icky signal games.  */
411
412 static sigset_t unblock_sigsegv;
413 static jmp_buf r;
414 static size_t pg;
415 static int devzero;
416
417 static char *
418 anonmap (size)
419      size_t size;
420 {
421 #ifdef USE_MAP_ANON
422   return (char *) mmap (0, size, PROT_READ|PROT_WRITE,
423                         MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
424 #else
425   return (char *) mmap (0, size, PROT_READ|PROT_WRITE,
426                         MAP_PRIVATE, devzero, 0);
427 #endif
428 }
429
430 static void
431 sigsegv (unused)
432      int unused;
433 {
434   sigprocmask (SIG_UNBLOCK, &unblock_sigsegv, 0);
435   longjmp (r, 1);
436 }
437
438 /* Basic functionality test.  */
439 void
440 test_0 ()
441 {
442   char *x = anonmap (pg);
443   if (x == (char *) MAP_FAILED)
444     perror_exit("test 0 mmap", 2);
445
446   *(int *)x += 1;
447
448   if (munmap(x, pg) < 0)
449     perror_exit("test 0 munmap", 3);
450 }
451
452 /* 1. If we map a 2-page region and unmap its second page, the first page
453    must remain.  */
454 static void
455 test_1 ()
456 {
457   char *x = anonmap (pg * 2);
458   if (x == (char *)MAP_FAILED)
459     perror_exit ("test 1 mmap", 4);
460
461   signal (SIGSEGV, sigsegv);
462   if (setjmp (r))
463     perror_exit ("test 1 fault", 5);
464
465   x[0] = 1;
466   x[pg] = 1;
467
468   if (munmap (x + pg, pg) < 0)
469     perror_exit ("test 1 munmap 1", 6);
470   x[0] = 2;
471
472   if (setjmp (r) == 0)
473     {
474       x[pg] = 1;
475       perror_exit ("test 1 no fault", 7);
476     }
477   if (munmap (x, pg) < 0)
478     perror_exit ("test 1 munmap 2", 8);
479 }
480
481 /* 2. If we map a 2-page region and unmap its first page, the second
482    page must remain.  */
483 static void
484 test_2 ()
485 {
486   char *x = anonmap (pg * 2);
487   if (x == (char *)MAP_FAILED)
488     perror_exit ("test 2 mmap", 9);
489
490   signal (SIGSEGV, sigsegv);
491   if (setjmp (r))
492     perror_exit ("test 2 fault", 10);
493
494   x[0] = 1;
495   x[pg] = 1;
496
497   if (munmap (x, pg) < 0)
498     perror_exit ("test 2 munmap 1", 11);
499
500   x[pg] = 2;
501
502   if (setjmp (r) == 0)
503     {
504       x[0] = 1;
505       perror_exit ("test 2 no fault", 12);
506     }
507
508   if (munmap (x+pg, pg) < 0)
509     perror_exit ("test 2 munmap 2", 13);
510 }
511
512 /* 3. If we map two adjacent 1-page regions and unmap them both with
513    one munmap, both must go away.
514
515    Getting two adjacent 1-page regions with two mmap calls is slightly
516    tricky.  All OS's tested skip over already-allocated blocks; therefore
517    we have been careful to unmap all allocated regions in previous tests.
518    HP/UX allocates pages backward in memory.  No OS has yet been observed
519    to be so perverse as to leave unmapped space between consecutive calls
520    to mmap.  */
521
522 static void
523 test_3 ()
524 {
525   char *x, *y, *z;
526
527   x = anonmap (pg);
528   if (x == (char *)MAP_FAILED)
529     perror_exit ("test 3 mmap 1", 14);
530   y = anonmap (pg);
531   if (y == (char *)MAP_FAILED)
532     perror_exit ("test 3 mmap 2", 15);
533
534   if (y != x + pg)
535     {
536       if (y == x - pg)
537         z = y, y = x, x = z;
538       else
539         {
540           fprintf (stderr, "test 3 nonconsecutive pages - %lx, %lx\n",
541                    (unsigned long)x, (unsigned long)y);
542           exit (16);
543         }
544     }
545
546   signal (SIGSEGV, sigsegv);
547   if (setjmp (r))
548     perror_exit ("test 3 fault", 17);
549
550   x[0] = 1;
551   y[0] = 1;
552
553   if (munmap (x, pg*2) < 0)
554     perror_exit ("test 3 munmap", 18);
555
556   if (setjmp (r) == 0)
557     {
558       x[0] = 1;
559       perror_exit ("test 3 no fault 1", 19);
560     }
561
562   signal (SIGSEGV, sigsegv);
563   if (setjmp (r) == 0)
564     {
565       y[0] = 1;
566       perror_exit ("test 3 no fault 2", 20);
567     }
568 }
569
570 int
571 main ()
572 {
573   sigemptyset (&unblock_sigsegv);
574   sigaddset (&unblock_sigsegv, SIGSEGV);
575   pg = getpagesize ();
576 #ifndef USE_MAP_ANON
577   devzero = open ("/dev/zero", O_RDWR);
578   if (devzero < 0)
579     perror_exit ("open /dev/zero", 1);
580 #endif
581
582   test_0();
583   test_1();
584   test_2();
585   test_3();
586
587   exit(0);
588 }
589 EOF}}}
590 changequote([,])dnl
591
592 AC_CACHE_CHECK(for working mmap from /dev/zero,
593   ac_cv_func_mmap_dev_zero,
594 [AC_TRY_RUN(
595  [#include "ct-mmap.inc"],
596  ac_cv_func_mmap_dev_zero=yes,
597  [if test $? -lt 4
598  then ac_cv_func_mmap_dev_zero=no
599  else ac_cv_func_mmap_dev_zero=buggy
600  fi],
601  # If this is not cygwin, and /dev/zero is a character device, it's probably
602  # safe to assume it works.
603  [case "$host_os" in
604    cygwin* | win32 | pe | mingw* ) ac_cv_func_mmap_dev_zero=buggy ;;
605    * ) if test -c /dev/zero
606        then ac_cv_func_mmap_dev_zero=yes
607        else ac_cv_func_mmap_dev_zero=no
608        fi ;;
609   esac])
610 ])
611 if test $ac_cv_func_mmap_dev_zero = yes; then
612   AC_DEFINE(HAVE_MMAP_DEV_ZERO, 1,
613             [Define if mmap can get us zeroed pages from /dev/zero.])
614 fi
615
616 AC_CACHE_CHECK([for working mmap with MAP_ANON(YMOUS)],
617   ac_cv_func_mmap_anon,
618 [AC_TRY_RUN(
619  [#define USE_MAP_ANON
620 #include "ct-mmap.inc"],
621  ac_cv_func_mmap_anon=yes,
622  [if test $? -lt 4
623  then ac_cv_func_mmap_anon=no
624  else ac_cv_func_mmap_anon=buggy
625  fi],
626  # Unlike /dev/zero, it is not safe to assume MAP_ANON(YMOUS) works
627  # just because it's there. Some SCO Un*xen define it but don't implement it.
628  ac_cv_func_mmap_anon=no)
629 ])
630 if test $ac_cv_func_mmap_anon = yes; then
631   AC_DEFINE(HAVE_MMAP_ANON, 1,
632             [Define if mmap can get us zeroed pages using MAP_ANON(YMOUS).])
633 fi
634 rm -f ct-mmap.inc
635 ])
636
637 # Check whether mmap can map a plain file, without MAP_FIXED.
638 AC_DEFUN([AC_FUNC_MMAP_FILE],
639 [AC_CACHE_CHECK(for working mmap of a file, ac_cv_func_mmap_file,
640 [# Create a file one thousand bytes long.
641 for i in 1 2 3 4 5 6 7 8 9 0
642 do for j in 1 2 3 4 5 6 7 8 9 0
643 do echo $i $j xxxxx
644 done
645 done > conftestdata$$
646
647 AC_TRY_RUN([
648 /* Test by Zack Weinberg.  Modified from MMAP_ANYWHERE test by
649    Richard Henderson and Alexandre Oliva.
650    Check whether read-only mmap of a plain file works. */
651 #include <sys/types.h>
652 #include <sys/stat.h>
653 #include <fcntl.h>
654 #include <sys/mman.h>
655
656 int main()
657 {
658   char *x;
659   int fd;
660   struct stat st;
661
662   fd = open("conftestdata$$", O_RDONLY);
663   if (fd < 0)
664     exit(1);
665
666   if (fstat (fd, &st))
667     exit(2);
668
669   x = (char*)mmap(0, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
670   if (x == (char *) -1)
671     exit(3);
672
673   if (x[0] != '1' || x[1] != ' ' || x[2] != '1' || x[3] != ' ')
674     exit(4);
675
676   if (munmap(x, st.st_size) < 0)
677     exit(5);
678
679   exit(0);
680 }], ac_cv_func_mmap_file=yes, ac_cv_func_mmap_file=no,
681 ac_cv_func_mmap_file=no)])
682 if test $ac_cv_func_mmap_file = yes; then
683   AC_DEFINE(HAVE_MMAP_FILE, 1,
684             [Define if read-only mmap of a plain file works.])
685 fi
686 ])
687
688 dnl Locate a program and check that its version is acceptable.
689 dnl AC_PROG_CHECK_VER(var, name, version-switch,
690 dnl                  version-extract-regexp, version-glob)
691 AC_DEFUN(gcc_AC_CHECK_PROG_VER,
692 [AC_CHECK_PROG([$1], [$2], [$2])
693 if test -n "[$]$1"; then
694   # Found it, now check the version.
695   AC_CACHE_CHECK(for modern $2, gcc_cv_prog_$2_modern,
696 [changequote(<<,>>)dnl
697   ac_prog_version=`<<$>>$1 $3 2>&1 |
698                    sed -n 's/^.*patsubst(<<$4>>,/,\/).*$/\1/p'`
699 changequote([,])dnl
700   echo "configure:__oline__: version of $2 is $ac_prog_version" >&AC_FD_CC
701 changequote(<<,>>)dnl
702   case $ac_prog_version in
703     '')     gcc_cv_prog_$2_modern=no;;
704     <<$5>>)
705             gcc_cv_prog_$2_modern=yes;;
706     *)      gcc_cv_prog_$2_modern=no;;
707   esac
708 changequote([,])dnl
709 ])
710 else
711   gcc_cv_prog_$2_modern=no
712 fi
713 ])
714
715 dnl Determine if enumerated bitfields are unsigned.   ISO C says they can
716 dnl be either signed or unsigned.
717 dnl
718 AC_DEFUN(gcc_AC_C_ENUM_BF_UNSIGNED,
719 [AC_CACHE_CHECK(for unsigned enumerated bitfields, gcc_cv_enum_bf_unsigned,
720 [AC_TRY_RUN(#include <stdlib.h>
721 enum t { BLAH = 128 } ;
722 struct s_t { enum t member : 8; } s ;
723 int main(void)
724 {
725         s.member = BLAH;
726         if (s.member < 0) exit(1);
727         exit(0);
728
729 }, gcc_cv_enum_bf_unsigned=yes, gcc_cv_enum_bf_unsigned=no, gcc_cv_enum_bf_unsigned=yes)])
730 if test $gcc_cv_enum_bf_unsigned = yes; then
731   AC_DEFINE(ENUM_BITFIELDS_ARE_UNSIGNED, 1,
732     [Define if enumerated bitfields are treated as unsigned values.])
733 fi])
734
735 dnl Host type sizes probe.
736 dnl By Kaveh R. Ghazi.  One typo fixed since.
737 dnl
738 AC_DEFUN([gcc_AC_COMPILE_CHECK_SIZEOF],
739 [changequote(<<, >>)dnl
740 dnl The name to #define.
741 define(<<AC_TYPE_NAME>>, translit(sizeof_$1, [a-z *], [A-Z_P]))dnl
742 dnl The cache variable name.
743 define(<<AC_CV_NAME>>, translit(ac_cv_sizeof_$1, [ *], [_p]))dnl
744 changequote([, ])dnl
745 AC_MSG_CHECKING(size of $1)
746 AC_CACHE_VAL(AC_CV_NAME,
747 [for ac_size in 4 8 1 2 16 $3 ; do # List sizes in rough order of prevalence.
748   AC_TRY_COMPILE([#include "confdefs.h"
749 #include <sys/types.h>
750 $2
751 ], [switch (0) case 0: case (sizeof ($1) == $ac_size):;], AC_CV_NAME=$ac_size)
752   if test x$AC_CV_NAME != x ; then break; fi
753 done
754 ])
755 if test x$AC_CV_NAME = x ; then
756   AC_MSG_ERROR([cannot determine a size for $1])
757 fi
758 AC_MSG_RESULT($AC_CV_NAME)
759 AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [The number of bytes in type $1])
760 undefine([AC_TYPE_NAME])dnl
761 undefine([AC_CV_NAME])dnl
762 ])
763
764 dnl Probe number of bits in a byte.
765 dnl Note C89 requires CHAR_BIT >= 8.
766 dnl
767 AC_DEFUN(gcc_AC_C_CHAR_BIT,
768 [AC_CACHE_CHECK(for CHAR_BIT, gcc_cv_decl_char_bit,
769 [AC_EGREP_CPP(found,
770 [#ifdef HAVE_LIMITS_H
771 #include <limits.h>
772 #endif
773 #ifdef CHAR_BIT
774 found
775 #endif], gcc_cv_decl_char_bit=yes, gcc_cv_decl_char_bit=no)
776 ])
777 if test $gcc_cv_decl_char_bit = no; then
778   AC_CACHE_CHECK(number of bits in a byte, gcc_cv_c_nbby,
779 [i=8
780  gcc_cv_c_nbby=
781  while test $i -lt 65; do
782    AC_TRY_COMPILE(,
783      [switch(0) {
784   case (unsigned char)((unsigned long)1 << $i) == ((unsigned long)1 << $i):
785   case (unsigned char)((unsigned long)1<<($i-1)) == ((unsigned long)1<<($i-1)):
786   ; }],
787      [gcc_cv_c_nbby=$i; break])
788    i=`expr $i + 1`
789  done
790  test -z "$gcc_cv_c_nbby" && gcc_cv_c_nbby=failed
791 ])
792 if test $gcc_cv_c_nbby = failed; then
793   AC_MSG_ERROR(cannot determine number of bits in a byte)
794 else
795   AC_DEFINE_UNQUOTED(CHAR_BIT, $gcc_cv_c_nbby,
796   [Define as the number of bits in a byte, if \`limits.h' doesn't.])
797 fi
798 fi])
799
800 dnl Host character set probe.
801 dnl The EBCDIC values match the table in config/i370/i370.c;
802 dnl there are other versions of EBCDIC but GCC won't work with them.
803 dnl
804 AC_DEFUN([gcc_AC_C_CHARSET],
805 [AC_CACHE_CHECK(execution character set, ac_cv_c_charset,
806   [AC_EGREP_CPP(ASCII,
807 [#if '\n' == 0x0A && ' ' == 0x20 && '0' == 0x30 \
808    && 'A' == 0x41 && 'a' == 0x61 && '!' == 0x21
809 ASCII
810 #endif], ac_cv_c_charset=ASCII)
811   if test x${ac_cv_c_charset+set} != xset; then
812     AC_EGREP_CPP(EBCDIC,
813 [#if '\n' == 0x15 && ' ' == 0x40 && '0' == 0xF0 \
814    && 'A' == 0xC1 && 'a' == 0x81 && '!' == 0x5A
815 EBCDIC
816 #endif], ac_cv_c_charset=EBCDIC)
817   fi
818   if test x${ac_cv_c_charset+set} != xset; then
819     ac_cv_c_charset=unknown
820   fi])
821 if test $ac_cv_c_charset = unknown; then
822   AC_MSG_ERROR([*** Cannot determine host character set.])
823 elif test $ac_cv_c_charset = EBCDIC; then
824   AC_DEFINE(HOST_EBCDIC, 1,
825   [Define if the host execution character set is EBCDIC.])
826 fi])
827
828 dnl Utility macro used by next two tests.
829 dnl AC_EXAMINE_OBJECT(C source code,
830 dnl     commands examining object file,
831 dnl     [commands to run if compile failed]):
832 dnl
833 dnl Compile the source code to an object file; then convert it into a
834 dnl printable representation.  All unprintable characters and
835 dnl asterisks (*) are replaced by dots (.).  All white space is
836 dnl deleted.  Newlines (ASCII 0x10) in the input are preserved in the
837 dnl output, but runs of newlines are compressed to a single newline.
838 dnl Finally, line breaks are forcibly inserted so that no line is
839 dnl longer than 80 columns and the file ends with a newline.  The
840 dnl result of all this processing is in the file conftest.dmp, which
841 dnl may be examined by the commands in the second argument.
842 dnl
843 AC_DEFUN([gcc_AC_EXAMINE_OBJECT],
844 [AC_LANG_SAVE
845 AC_LANG_C
846 dnl Next bit cribbed from AC_TRY_COMPILE.
847 cat > conftest.$ac_ext <<EOF
848 [#line __oline__ "configure"
849 #include "confdefs.h"
850 $1
851 ]EOF
852 if AC_TRY_EVAL(ac_compile); then
853   od -c conftest.o |
854     sed ['s/^[0-7]*[    ]*/ /
855           s/\*/./g
856           s/ \\n/*/g
857           s/ [0-9][0-9][0-9]/./g
858           s/  \\[^ ]/./g'] |
859     tr -d '
860  ' | tr -s '*' '
861 ' | fold | sed '$a\
862 ' > conftest.dmp
863   $2
864 ifelse($3, , , else
865   $3
866 )dnl
867 fi
868 rm -rf conftest*
869 AC_LANG_RESTORE])
870
871 dnl Host endianness probe.
872 dnl This tests byte-within-word endianness.  GCC actually needs
873 dnl to know word-within-larger-object endianness.  They are the
874 dnl same on all presently supported hosts.
875 dnl Differs from AC_C_BIGENDIAN in that it does not require
876 dnl running a program on the host, and it defines the macro we
877 dnl want to see.
878 dnl
879 AC_DEFUN([gcc_AC_C_COMPILE_ENDIAN],
880 [AC_CACHE_CHECK(byte ordering, ac_cv_c_compile_endian,
881 [ac_cv_c_compile_endian=unknown
882 gcc_AC_EXAMINE_OBJECT([
883 #ifdef HAVE_LIMITS_H
884 # include <limits.h>
885 #endif
886 /* This structure must have no internal padding.  */
887   struct {
888     char prefix[sizeof "\nendian:" - 1];
889     short word;
890     char postfix[2];
891  } tester = {
892     "\nendian:",
893 #if SIZEOF_SHORT == 4
894     ('A' << (CHAR_BIT * 3)) | ('B' << (CHAR_BIT * 2)) |
895 #endif
896     ('A' << CHAR_BIT) | 'B',
897     'X', '\n'
898 };],
899  [if   grep 'endian:AB' conftest.dmp >/dev/null 2>&1; then
900     ac_cv_c_compile_endian=big-endian
901   elif grep 'endian:BA' conftest.dmp >/dev/null 2>&1; then
902     ac_cv_c_compile_endian=little-endian
903   fi])
904 ])
905 if test $ac_cv_c_compile_endian = unknown; then
906   AC_MSG_ERROR([*** unable to determine endianness])
907 elif test $ac_cv_c_compile_endian = big-endian; then
908   AC_DEFINE(HOST_WORDS_BIG_ENDIAN, 1,
909   [Define if the host machine stores words of multi-word integers in
910    big-endian order.])
911 fi
912 ])
913