OSDN Git Service

gcc/fortran/
[pf3gnuchains/gcc-fork.git] / libgfortran / acinclude.m4
1 dnl Check:
2 dnl * If we have gettimeofday;
3 dnl * If we have struct timezone for use in calling it;
4 dnl * If calling it with a timezone pointer actually works -- this is deemed
5 dnl   obsolete or undefined on some systems which say you should use a null
6 dnl   pointer -- and undefine HAVE_TIMEZONE if so;
7 dnl * Whether it only takes one arg.
8 AC_DEFUN([LIBGFOR_GETTIMEOFDAY], [
9   AC_CHECK_FUNCS(gettimeofday)
10   if test "$ac_cv_func_gettimeofday" = yes; then
11     AC_CACHE_CHECK([for struct timezone], gfor_cv_struct_timezone,
12       [AC_TRY_COMPILE([#include <sys/time.h>],
13       [struct timezone tz;],
14       gfor_cv_struct_timezone=yes, gfor_cv_struct_timezone=no)])
15     if test $gfor_cv_struct_timezone = yes; then
16       dnl It may be that we can't call gettimeofday with a non-null pointer.
17       dnl In that case we'll lie about struct timezone.
18       AC_TRY_RUN([
19 #ifdef TIME_WITH_SYS_TIME
20 #include <sys/time.h>
21 #include <time.h>
22 #else
23 #ifdef HAVE_SYS_TIME_H
24 #include <sys/time.h>
25 #else
26 #include <time.h>
27 #endif
28 #endif
29 main ()
30 {
31   struct timeval time;
32   struct timezone dummy;
33   if (gettimeofday (&time, &dummy))
34     exit (1);
35   else
36     exit (0);
37 }],
38         [gfor_have_struct_timezone=yes], [gfor_have_struct_timezone=no],
39         [gfor_have_struct_timezone=yes])
40       if test $gfor_have_struct_timezone = yes; then
41         AC_DEFINE(HAVE_TIMEZONE, 1, [Do we have struct timezone])
42       fi
43     fi
44     AC_REQUIRE([AC_HEADER_TIME])
45     AC_CACHE_CHECK([whether gettimeofday can accept two arguments],
46       emacs_cv_gettimeofday_two_arguments,
47       [AC_TRY_LINK([
48 #ifdef TIME_WITH_SYS_TIME
49 #include <sys/time.h>
50 #include <time.h>
51 #else
52 #ifdef HAVE_SYS_TIME_H
53 #include <sys/time.h>
54 #else
55 #include <time.h>
56 #endif
57 #endif
58       ],
59       [
60       struct timeval time;
61 #ifdef HAVE_TIMEZONE
62       struct timezone dummy;
63 #define DUMMY &dummy
64 #else
65 #define DUMMY NULL
66 #endif
67       gettimeofday (&time, DUMMY);],
68       emacs_cv_gettimeofday_two_arguments=yes,
69       emacs_cv_gettimeofday_two_arguments=no)])
70     if test $emacs_cv_gettimeofday_two_arguments = no; then
71       AC_DEFINE(GETTIMEOFDAY_ONE_ARGUMENT, 1,
72         [Does gettimeofday take a single argument])
73     fi
74   fi])
75
76 sinclude(../libtool.m4)
77 dnl The lines below arrange for aclocal not to bring an installed
78 dnl libtool.m4 into aclocal.m4, while still arranging for automake to
79 dnl add a definition of LIBTOOL to Makefile.in.
80 ifelse(,,,[AC_SUBST(LIBTOOL)
81 AC_DEFUN([AM_PROG_LIBTOOL])
82 AC_DEFUN([AC_LIBTOOL_DLOPEN])
83 AC_DEFUN([AC_PROG_LD])
84 ])
85
86 dnl Check whether the target is ILP32.
87 AC_DEFUN([LIBGFOR_TARGET_ILP32], [
88   AC_CACHE_CHECK([whether the target is ILP32], target_ilp32, [
89   save_CFLAGS="$CFLAGS"
90   CFLAGS="-O2"
91   AC_TRY_LINK(,[
92 if (sizeof(int) == 4 && sizeof(long) == 4 && sizeof(void *) == 4)
93   ;
94 else
95   undefined_function ();
96                ],
97                target_ilp32=yes,
98                target_ilp32=no)
99   CFLAGS="$save_CFLAGS"])
100   if test $target_ilp32 = yes; then
101     AC_DEFINE(TARGET_ILP32, 1,
102       [Define to 1 if the target is ILP32.])
103   fi
104   ])
105
106 dnl Check whether the target supports hidden visibility.
107 AC_DEFUN([LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY], [
108   AC_CACHE_CHECK([whether the target supports hidden visibility],
109                  have_attribute_visibility, [
110   save_CFLAGS="$CFLAGS"
111   CFLAGS="$CFLAGS -Werror"
112   AC_TRY_COMPILE([void __attribute__((visibility("hidden"))) foo(void) { }],
113                  [], have_attribute_visibility=yes,
114                  have_attribute_visibility=no)
115   CFLAGS="$save_CFLAGS"])
116   if test $have_attribute_visibility = yes; then
117     AC_DEFINE(HAVE_ATTRIBUTE_VISIBILITY, 1,
118       [Define to 1 if the target supports __attribute__((visibility(...))).])
119   fi])
120
121 dnl Check whether the target supports dllexport
122 AC_DEFUN([LIBGFOR_CHECK_ATTRIBUTE_DLLEXPORT], [
123   AC_CACHE_CHECK([whether the target supports dllexport],
124                  have_attribute_dllexport, [
125   save_CFLAGS="$CFLAGS"
126   CFLAGS="$CFLAGS -Werror"
127   AC_TRY_COMPILE([void __attribute__((dllexport)) foo(void) { }],
128                  [], have_attribute_dllexport=yes,
129                  have_attribute_dllexport=no)
130   CFLAGS="$save_CFLAGS"])
131   if test $have_attribute_dllexport = yes; then
132     AC_DEFINE(HAVE_ATTRIBUTE_DLLEXPORT, 1,
133       [Define to 1 if the target supports __attribute__((dllexport)).])
134   fi])
135
136 dnl Check whether the target supports symbol aliases.
137 AC_DEFUN([LIBGFOR_CHECK_ATTRIBUTE_ALIAS], [
138   AC_CACHE_CHECK([whether the target supports symbol aliases],
139                  have_attribute_alias, [
140   AC_TRY_LINK([
141 #define ULP     STR1(__USER_LABEL_PREFIX__)
142 #define STR1(x) STR2(x)
143 #define STR2(x) #x
144 void foo(void) { }
145 extern void bar(void) __attribute__((alias(ULP "foo")));],
146     [bar();], have_attribute_alias=yes, have_attribute_alias=no)])
147   if test $have_attribute_alias = yes; then
148     AC_DEFINE(HAVE_ATTRIBUTE_ALIAS, 1,
149       [Define to 1 if the target supports __attribute__((alias(...))).])
150   fi])
151
152 dnl Check whether the target supports __sync_fetch_and_add.
153 AC_DEFUN([LIBGFOR_CHECK_SYNC_FETCH_AND_ADD], [
154   AC_CACHE_CHECK([whether the target supports __sync_fetch_and_add],
155                  have_sync_fetch_and_add, [
156   AC_TRY_LINK([int foovar = 0;], [
157 if (foovar <= 0) return __sync_fetch_and_add (&foovar, 1);
158 if (foovar > 10) return __sync_add_and_fetch (&foovar, -1);],
159               have_sync_fetch_and_add=yes, have_sync_fetch_and_add=no)])
160   if test $have_sync_fetch_and_add = yes; then
161     AC_DEFINE(HAVE_SYNC_FETCH_AND_ADD, 1,
162               [Define to 1 if the target supports __sync_fetch_and_add])
163   fi])
164
165 dnl Check if threads are supported.
166 AC_DEFUN([LIBGFOR_CHECK_GTHR_DEFAULT], [
167   AC_CACHE_CHECK([configured target thread model],
168                  target_thread_file, [
169 target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`])
170
171   if test $target_thread_file != single; then
172     AC_DEFINE(HAVE_GTHR_DEFAULT, 1,
173               [Define if the compiler has a thread header that is non single.])
174   fi])
175
176 dnl Check for pragma weak.
177 AC_DEFUN([LIBGFOR_CHECK_PRAGMA_WEAK], [
178   AC_CACHE_CHECK([whether pragma weak works],
179                  have_pragma_weak, [
180   gfor_save_CFLAGS="$CFLAGS"
181   CFLAGS="$CFLAGS -Wunknown-pragmas"
182   AC_TRY_COMPILE([void foo (void);
183 #pragma weak foo], [if (foo) foo ();],
184                  have_pragma_weak=yes, have_pragma_weak=no)])
185   if test $have_pragma_weak = yes; then
186     AC_DEFINE(HAVE_PRAGMA_WEAK, 1,
187               [Define to 1 if the target supports #pragma weak])
188   fi])
189
190 dnl Check whether target can unlink a file still open.
191 AC_DEFUN([LIBGFOR_CHECK_UNLINK_OPEN_FILE], [
192   AC_CACHE_CHECK([whether the target can unlink an open file],
193                   have_unlink_open_file, [
194   AC_TRY_RUN([
195 #include <errno.h>
196 #include <fcntl.h>
197 #include <unistd.h>
198 #include <sys/stat.h>
199
200 int main ()
201 {
202   int fd;
203
204   fd = open ("testfile", O_RDWR | O_CREAT, S_IWRITE | S_IREAD);
205   if (fd <= 0)
206     return 0;
207   if (unlink ("testfile") == -1)
208     return 1;
209   write (fd, "This is a test\n", 15);
210   close (fd);
211
212   if (open ("testfile", O_RDONLY, S_IWRITE | S_IREAD) == -1 && errno == ENOENT)
213     return 0;
214   else
215     return 1;
216 }], have_unlink_open_file=yes, have_unlink_open_file=no, [
217 case "${target}" in
218   *mingw*) have_unlink_open_file=no ;;
219   *) have_unlink_open_file=yes;;
220 esac])])
221 if test x"$have_unlink_open_file" = xyes; then
222   AC_DEFINE(HAVE_UNLINK_OPEN_FILE, 1, [Define if target can unlink open files.])
223 fi])
224
225 dnl Check whether CRLF is the line terminator
226 AC_DEFUN([LIBGFOR_CHECK_CRLF], [
227   AC_CACHE_CHECK([whether the target has CRLF as line terminator],
228                   have_crlf, [
229   AC_TRY_RUN([
230 /* This test program should exit with status 0 if system uses a CRLF as
231    line terminator, and status 1 otherwise.  
232    Since it is used to check for mingw systems, and should return 0 in any
233    other case, in case of a failure we will not use CRLF.  */
234 #include <sys/stat.h>
235 #include <stdlib.h>
236 #include <fcntl.h>
237 #include <stdio.h>
238
239 int main ()
240 {
241 #ifndef O_BINARY
242   exit(1);
243 #else
244   int fd, bytes;
245   char buff[5];
246
247   fd = open ("foo", O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
248   if (fd < 0)
249     exit(1);
250   if (write (fd, "\n", 1) < 0)
251     perror ("write");
252   
253   close (fd);
254   
255   if ((fd = open ("foo", O_RDONLY | O_BINARY, S_IRWXU)) < 0)
256     exit(1);
257   bytes = read (fd, buff, 5);
258   if (bytes == 2 && buff[0] == '\r' && buff[1] == '\n')
259     exit(0);
260   else
261     exit(1);
262 #endif
263 }], have_crlf=yes, have_crlf=no, [
264 case "${target}" in
265   *mingw*) have_crlf=yes ;;
266   *) have_crlf=no;;
267 esac])])
268 if test x"$have_crlf" = xyes; then
269   AC_DEFINE(HAVE_CRLF, 1, [Define if CRLF is line terminator.])
270 fi])
271
272 dnl Check whether isfinite is broken.
273 dnl The most common problem is that it does not work on long doubles.
274 AC_DEFUN([LIBGFOR_CHECK_FOR_BROKEN_ISFINITE], [
275   AC_CACHE_CHECK([whether isfinite is broken],
276                   have_broken_isfinite, [
277   libgfor_check_for_broken_isfinite_save_LIBS=$LIBS
278   LIBS="$LIBS -lm"
279   AC_TRY_RUN([
280 #ifdef HAVE_MATH_H
281 #include <math.h>
282 #endif
283 #include <float.h>
284 int main ()
285 {
286 #ifdef isfinite
287 #ifdef LDBL_MAX
288   if (!isfinite(LDBL_MAX)) return 1;
289 #endif
290 #ifdef DBL_MAX
291   if (!isfinite(DBL_MAX)) return 1;
292 #endif
293 #endif
294 return 0;
295 }], have_broken_isfinite=no, have_broken_isfinite=yes, [
296 case "${target}" in
297   hppa*-*-hpux*) have_broken_isfinite=yes ;;
298   *) have_broken_isfinite=no ;;
299 esac])]
300   LIBS=$libgfor_check_for_broken_isfinite_save_LIBS)
301 if test x"$have_broken_isfinite" = xyes; then
302   AC_DEFINE(HAVE_BROKEN_ISFINITE, 1, [Define if isfinite is broken.])
303 fi])
304
305 dnl Check whether isnan is broken.
306 dnl The most common problem is that it does not work on long doubles.
307 AC_DEFUN([LIBGFOR_CHECK_FOR_BROKEN_ISNAN], [
308   AC_CACHE_CHECK([whether isnan is broken],
309                   have_broken_isnan, [
310   libgfor_check_for_broken_isnan_save_LIBS=$LIBS
311   LIBS="$LIBS -lm"
312   AC_TRY_RUN([
313 #ifdef HAVE_MATH_H
314 #include <math.h>
315 #endif
316 #include <float.h>
317 int main ()
318 {
319 #ifdef isnan
320 #ifdef LDBL_MAX
321   {
322     long double x;
323     x = __builtin_nanl ("");
324     if (!isnan(x)) return 1;
325     if (isnan(LDBL_MAX)) return 1;
326 #ifdef NAN
327     x = (long double) NAN;
328     if (!isnan(x)) return 1;
329 #endif
330   }
331 #endif
332 #ifdef DBL_MAX
333   {
334     double y;
335     y = __builtin_nan ("");
336     if (!isnan(y)) return 1;
337     if (isnan(DBL_MAX)) return 1;
338 #ifdef NAN
339     y = (double) NAN;
340     if (!isnan(y)) return 1;
341 #endif
342   }
343 #endif
344 #endif
345 return 0;
346 }], have_broken_isnan=no, have_broken_isnan=yes, [
347 case "${target}" in
348   hppa*-*-hpux*) have_broken_isnan=yes ;;
349   *) have_broken_isnan=no ;;
350 esac])]
351   LIBS=$libgfor_check_for_broken_isnan_save_LIBS)
352 if test x"$have_broken_isnan" = xyes; then
353   AC_DEFINE(HAVE_BROKEN_ISNAN, 1, [Define if isnan is broken.])
354 fi])
355
356 dnl Check whether fpclassify is broken.
357 dnl The most common problem is that it does not work on long doubles.
358 AC_DEFUN([LIBGFOR_CHECK_FOR_BROKEN_FPCLASSIFY], [
359   AC_CACHE_CHECK([whether fpclassify is broken],
360                   have_broken_fpclassify, [
361   libgfor_check_for_broken_fpclassify_save_LIBS=$LIBS
362   LIBS="$LIBS -lm"
363   AC_TRY_RUN([
364 #ifdef HAVE_MATH_H
365 #include <math.h>
366 #endif
367 #include <float.h>
368 int main ()
369 {
370 #ifdef fpclassify
371 #ifdef LDBL_MAX
372         if (fpclassify(LDBL_MAX) == FP_NAN
373             || fpclassify(LDBL_MAX) == FP_INFINITE) return 1;
374 #endif
375 #ifdef DBL_MAX
376         if (fpclassify(DBL_MAX) == FP_NAN
377             || fpclassify(DBL_MAX) == FP_INFINITE) return 1;
378 #endif
379 #endif
380 return 0;
381 }], have_broken_fpclassify=no, have_broken_fpclassify=yes, [
382 case "${target}" in
383   hppa*-*-hpux*) have_broken_fpclassify=yes ;;
384   *) have_broken_fpclassify=no ;;
385 esac])]
386   LIBS=$libgfor_check_for_broken_fpclassify_save_LIBS)
387 if test x"$have_broken_fpclassify" = xyes; then
388   AC_DEFINE(HAVE_BROKEN_FPCLASSIFY, 1, [Define if fpclassify is broken.])
389 fi])
390
391 dnl Check whether the st_ino and st_dev stat fields taken together uniquely
392 dnl identify the file within the system. This is should be true for POSIX
393 dnl systems; it is known to be false on mingw32.
394 AC_DEFUN([LIBGFOR_CHECK_WORKING_STAT], [
395   AC_CACHE_CHECK([whether the target stat is reliable],
396                   have_working_stat, [
397   AC_TRY_RUN([
398 #include <stdio.h>
399 #include <sys/types.h>
400 #include <sys/stat.h>
401 #include <unistd.h>
402
403 int main ()
404
405   FILE *f, *g;
406   struct stat st1, st2;
407
408   f = fopen ("foo", "w");
409   g = fopen ("bar", "w");
410   if (stat ("foo", &st1) != 0 || stat ("bar", &st2))
411     return 1;
412   if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino)
413     return 1;
414   fclose(f);
415   fclose(g);
416   return 0;
417 }], have_working_stat=yes, have_working_stat=no, [
418 case "${target}" in
419   *mingw*) have_working_stat=no ;;
420   *) have_working_stat=yes;;
421 esac])])
422 if test x"$have_working_stat" = xyes; then
423   AC_DEFINE(HAVE_WORKING_STAT, 1, [Define if target has a reliable stat.])
424 fi])
425
426 dnl Checks for fpsetmask function.
427 AC_DEFUN([LIBGFOR_CHECK_FPSETMASK], [
428   AC_CACHE_CHECK([whether fpsetmask is present], have_fpsetmask, [
429     AC_TRY_LINK([
430 #if HAVE_FLOATINGPOINT_H
431 # include <floatingpoint.h>
432 #endif /* HAVE_FLOATINGPOINT_H */
433 #if HAVE_IEEEFP_H
434 # include <ieeefp.h>
435 #endif /* HAVE_IEEEFP_H */],[fpsetmask(0);],
436     eval "have_fpsetmask=yes", eval "have_fpsetmask=no")
437   ])
438   if test x"$have_fpsetmask" = xyes; then
439     AC_DEFINE(HAVE_FPSETMASK, 1, [Define if you have fpsetmask.])
440   fi
441 ])