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