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