OSDN Git Service

2003-07-28 Phil Edwards <pme@gcc.gnu.org>
[pf3gnuchains/gcc-fork.git] / libiberty / aclocal.m4
1 sinclude(../config/accross.m4)
2
3 dnl See whether strncmp reads past the end of its string parameters.
4 dnl On some versions of SunOS4 at least, strncmp reads a word at a time
5 dnl but erroneously reads past the end of strings.  This can cause
6 dnl a SEGV in some cases.
7 AC_DEFUN(libiberty_AC_FUNC_STRNCMP,
8 [AC_REQUIRE([AC_FUNC_MMAP])
9 AC_CACHE_CHECK([for working strncmp], ac_cv_func_strncmp_works,
10 [AC_TRY_RUN([
11 /* Test by Jim Wilson and Kaveh Ghazi.
12    Check whether strncmp reads past the end of its string parameters. */
13 #include <sys/types.h>
14
15 #ifdef HAVE_FCNTL_H
16 #include <fcntl.h>
17 #endif
18
19 #ifdef HAVE_SYS_MMAN_H
20 #include <sys/mman.h>
21 #endif
22
23 #ifndef MAP_ANON
24 #ifdef MAP_ANONYMOUS
25 #define MAP_ANON MAP_ANONYMOUS
26 #else
27 #define MAP_ANON MAP_FILE
28 #endif
29 #endif
30
31 #ifndef MAP_FILE
32 #define MAP_FILE 0
33 #endif
34 #ifndef O_RDONLY
35 #define O_RDONLY 0
36 #endif
37
38 #define MAP_LEN 0x10000
39
40 main ()
41 {
42 #if defined(HAVE_MMAP) || defined(HAVE_MMAP_ANYWHERE)
43   char *p;
44   int dev_zero;
45
46   dev_zero = open ("/dev/zero", O_RDONLY);
47   if (dev_zero < 0)
48     exit (1);
49   
50   p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE,
51                      MAP_ANON|MAP_PRIVATE, dev_zero, 0);
52   if (p == (char *)-1)
53     p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE,
54                        MAP_ANON|MAP_PRIVATE, -1, 0);
55   if (p == (char *)-1)
56     exit (2);
57   else
58     {
59       char *string = "__si_type_info";
60       char *q = (char *) p + MAP_LEN - strlen (string) - 2;
61       char *r = (char *) p + 0xe;
62
63       strcpy (q, string);
64       strcpy (r, string);
65       strncmp (r, q, 14);
66     }
67 #endif /* HAVE_MMAP || HAVE_MMAP_ANYWHERE */
68   exit (0);
69 }
70 ], ac_cv_func_strncmp_works=yes, ac_cv_func_strncmp_works=no,
71   ac_cv_func_strncmp_works=no)
72 rm -f core core.* *.core])
73 if test $ac_cv_func_strncmp_works = no ; then
74   LIBOBJS="$LIBOBJS strncmp.o"
75 fi
76 ])
77
78 dnl See if errno must be declared even when <errno.h> is included.
79 AC_DEFUN(libiberty_AC_DECLARE_ERRNO,
80 [AC_CACHE_CHECK(whether errno must be declared, libiberty_cv_declare_errno,
81 [AC_TRY_COMPILE(
82 [#include <errno.h>],
83 [int x = errno;],
84 libiberty_cv_declare_errno=no,
85 libiberty_cv_declare_errno=yes)])
86 if test $libiberty_cv_declare_errno = yes
87 then AC_DEFINE(NEED_DECLARATION_ERRNO, 1,
88   [Define if errno must be declared even when <errno.h> is included.])
89 fi
90 ])
91
92 dnl See whether we need a declaration for a function.
93 AC_DEFUN(libiberty_NEED_DECLARATION,
94 [AC_MSG_CHECKING([whether $1 must be declared])
95 AC_CACHE_VAL(libiberty_cv_decl_needed_$1,
96 [AC_TRY_COMPILE([
97 #include "confdefs.h"
98 #include <stdio.h>
99 #ifdef HAVE_STRING_H
100 #include <string.h>
101 #else
102 #ifdef HAVE_STRINGS_H
103 #include <strings.h>
104 #endif
105 #endif
106 #ifdef HAVE_STDLIB_H
107 #include <stdlib.h>
108 #endif
109 #ifdef HAVE_UNISTD_H
110 #include <unistd.h>
111 #endif],
112 [char *(*pfn) = (char *(*)) $1],
113 libiberty_cv_decl_needed_$1=no, libiberty_cv_decl_needed_$1=yes)])
114 AC_MSG_RESULT($libiberty_cv_decl_needed_$1)
115 if test $libiberty_cv_decl_needed_$1 = yes; then
116   AC_DEFINE([NEED_DECLARATION_]translit($1, [a-z], [A-Z]), 1,
117             [Define if $1 is not declared in system header files.])
118 fi
119 ])dnl
120
121 # FIXME: We temporarily define our own version of AC_PROG_CC.  This is
122 # copied from autoconf 2.12, but does not call AC_PROG_CC_WORKS.  We
123 # are probably using a cross compiler, which will not be able to fully
124 # link an executable.  This should really be fixed in autoconf
125 # itself.
126
127 AC_DEFUN(LIB_AC_PROG_CC,
128 [AC_BEFORE([$0], [AC_PROG_CPP])dnl
129 AC_PROVIDE([AC_PROG_CC])
130 AC_CHECK_PROG(CC, gcc, gcc)
131 if test -z "$CC"; then
132   AC_CHECK_PROG(CC, cc, cc, , , /usr/ucb/cc)
133   test -z "$CC" && AC_MSG_ERROR([no acceptable cc found in \$PATH])
134 fi
135
136 AC_PROG_CC_GNU
137
138 if test $ac_cv_prog_gcc = yes; then
139   GCC=yes
140   ac_libiberty_warn_cflags='-W -Wall -Wtraditional -pedantic'
141 dnl Check whether -g works, even if CFLAGS is set, in case the package
142 dnl plays around with CFLAGS (such as to build both debugging and
143 dnl normal versions of a library), tasteless as that idea is.
144   ac_test_CFLAGS="${CFLAGS+set}"
145   ac_save_CFLAGS="$CFLAGS"
146   CFLAGS=
147   AC_PROG_CC_G
148   if test "$ac_test_CFLAGS" = set; then
149     CFLAGS="$ac_save_CFLAGS"
150   elif test $ac_cv_prog_cc_g = yes; then
151     CFLAGS="-g -O2"
152   else
153     CFLAGS="-O2"
154   fi
155 else
156   GCC=
157   ac_libiberty_warn_cflags=
158   test "${CFLAGS+set}" = set || CFLAGS="-g"
159 fi
160 AC_SUBST(ac_libiberty_warn_cflags)
161 ])
162
163 # Work around a bug in autoheader.  This can go away when we switch to
164 # autoconf >2.50.  The use of define instead of AC_DEFUN is
165 # deliberate.
166 define(AC_DEFINE_NOAUTOHEADER,
167 [cat >> confdefs.h <<\EOF
168 [#define] $1 ifelse($#, 2, [$2], $#, 3, [$2], 1)
169 EOF
170 ])
171
172 # We always want a C version of alloca() compiled into libiberty,
173 # because native-compiler support for the real alloca is so !@#$%
174 # unreliable that GCC has decided to use it only when being compiled
175 # by GCC.  This is the part of AC_FUNC_ALLOCA that calculates the
176 # information alloca.c needs.
177 AC_DEFUN(libiberty_AC_FUNC_C_ALLOCA,
178 [AC_CACHE_CHECK(whether alloca needs Cray hooks, ac_cv_os_cray,
179 [AC_EGREP_CPP(webecray,
180 [#if defined(CRAY) && ! defined(CRAY2)
181 webecray
182 #else
183 wenotbecray
184 #endif
185 ], ac_cv_os_cray=yes, ac_cv_os_cray=no)])
186 if test $ac_cv_os_cray = yes; then
187   for ac_func in _getb67 GETB67 getb67; do
188     AC_CHECK_FUNC($ac_func, 
189       [AC_DEFINE_UNQUOTED(CRAY_STACKSEG_END, $ac_func, 
190   [Define to one of _getb67, GETB67, getb67 for Cray-2 and Cray-YMP
191    systems. This function is required for alloca.c support on those
192    systems.])  break])
193   done
194 fi
195
196 AC_CACHE_CHECK(stack direction for C alloca, ac_cv_c_stack_direction,
197 [AC_TRY_RUN([find_stack_direction ()
198 {
199   static char *addr = 0;
200   auto char dummy;
201   if (addr == 0)
202     {
203       addr = &dummy;
204       return find_stack_direction ();
205     }
206   else
207     return (&dummy > addr) ? 1 : -1;
208 }
209 main ()
210 {
211   exit (find_stack_direction() < 0);
212 }], 
213   ac_cv_c_stack_direction=1,
214   ac_cv_c_stack_direction=-1,
215   ac_cv_c_stack_direction=0)])
216 AC_DEFINE_UNQUOTED(STACK_DIRECTION, $ac_cv_c_stack_direction,
217   [Define if you know the direction of stack growth for your system;
218    otherwise it will be automatically deduced at run-time.
219         STACK_DIRECTION > 0 => grows toward higher addresses
220         STACK_DIRECTION < 0 => grows toward lower addresses
221         STACK_DIRECTION = 0 => direction of growth unknown])
222 ])