3 AT_BANNER([Fortran low level compiling/preprocessing macros.])
5 # Copyright (C) 2000, 2001, 2003, 2008, 2009, 2010 Free Software
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # Since the macros which compile are required by most tests, check
22 # them first. But remember that looking for a compiler is even more
23 # primitive, so check those first.
26 ## --------------------- ##
27 ## Fortran 77 Compiler. ##
28 ## --------------------- ##
31 AT_CHECK_MACRO([GNU Fortran 77],
35 if AC_TRY_COMMAND([$F77 --version | grep GNU >&2]); then
36 # Be sure to remove files which might be created by compilers that
37 # don't support --version.
39 # Has GNU in --version.
41 AC_MSG_ERROR([failed to recognize GNU Fortran 77 compiler])
43 # Be sure to remove files which might be created by compilers that
44 # don't support --version.
48 AC_MSG_ERROR([incorrectly recognized a GNU Fortran 77 compiler])
54 ## ------------------ ##
55 ## Fortran Compiler. ##
56 ## ------------------ ##
59 AT_CHECK_MACRO([GNU Fortran],
63 # No Fortran compiler is known not to support "*.f".
66 # GNU Fortran is known to support freeform.
68 [AC_MSG_WARN([Fortran does not accept free-form source])])
69 if test "$ac_compiler_gnu" = yes; then
72 *) AC_MSG_ERROR([failed to recognize GNU Fortran's -ffree-form option]);;
78 ## ------------------------- ##
79 ## AC_OPENMP and Fortran 77. ##
80 ## ------------------------- ##
82 AT_SETUP([AC_OPENMP and Fortran 77])
84 AT_DATA([configure.ac],
89 if test "X$ac_cv_prog_f77_openmp" = Xunsupported; then
92 FFLAGS="$FFLAGS $OPENMP_FFLAGS"
93 AC_CONFIG_FILES([Makefile])
97 AT_DATA([Makefile.in],
98 [[foo@EXEEXT@: foo.@OBJEXT@
99 @F77@ @FFLAGS@ @LDFLAGS@ -o $@ foo.@OBJEXT@
102 @F77@ @FFLAGS@ -c foo.f
111 AT_CHECK([env ACLOCAL=true autoreconf -vi], [], [ignore], [ignore])
113 AT_CHECK([$MAKE], [], [ignore], [ignore])
118 ## ---------------------- ##
119 ## AC_OPENMP and Fortran. ##
120 ## ---------------------- ##
122 AT_SETUP([AC_OPENMP and Fortran])
124 AT_DATA([configure.ac],
129 if test "X$ac_cv_prog_fc_openmp" = Xunsupported; then
132 FCFLAGS="$FCFLAGS $OPENMP_FCFLAGS"
133 AC_CONFIG_FILES([Makefile])
137 AT_DATA([Makefile.in],
138 [[foo@EXEEXT@: foo.@OBJEXT@
139 @FC@ @FCFLAGS@ @LDFLAGS@ -o $@ foo.@OBJEXT@
142 @FC@ @FCFLAGS@ -c foo.f
151 AT_CHECK([env ACLOCAL=true autoreconf -vi], [], [ignore], [ignore])
153 AT_CHECK([$MAKE], [], [ignore], [ignore])
158 # We don't test the AC_F77_LIBRARY_LDFLAGS macro on its own because of
159 # (autoconf.info)Fortran Compiler:
160 # The macros `AC_F77_DUMMY_MAIN' and `AC_FC_DUMMY_MAIN' or
161 # `AC_F77_MAIN' and `AC_FC_MAIN' are probably also necessary to link
162 # C/C++ with Fortran; see below.
164 # and we would need libtool to create shared libraries.
166 # Further, for any sensible test of the AC_F{77,C}(_DUMMY)?_MAIN macros
167 # we also need to use AC_F{77,C}_WRAPPERS, in order to be able to actually
168 # call the functions.
170 ## ------------------------ ##
171 ## AC_F77_DUMMY_MAIN usage. ##
172 ## ------------------------ ##
174 AT_SETUP([AC_F77_DUMMY_MAIN usage])
176 AT_DATA([configure.ac],
178 AC_CONFIG_HEADERS([config.h:config.hin])
180 AC_F77_DUMMY_MAIN([], [AC_MSG_FAILURE([failed to determine F77 dummy main], [77])])
183 AC_CONFIG_FILES([Makefile])
187 AT_DATA([Makefile.in],
189 all: cprogram@EXEEXT@
191 cprogram@EXEEXT@: cprogram.@OBJEXT@ foobar.@OBJEXT@
192 @CC@ @CFLAGS@ @LDFLAGS@ -o $@ cprogram.@OBJEXT@ foobar.@OBJEXT@ @LIBS@ @FLIBS@
194 .SUFFIXES: .c .f .@OBJEXT@
198 @CC@ @DEFS@ -I. @CPPFLAGS@ @CFLAGS@ -c $<
202 [[C This is just a purely numeric routine, no I/O needed.
203 C Taken from autoconf.texi:Fortran Compiler.
204 subroutine foobar (x, y)
205 double precision x, y
211 AT_DATA([cprogram.c],
212 [[#include <config.h>
215 /* Taken from autoconf.texi:Fortran Compiler. */
216 #define FOOBAR_F77 F77_FUNC (foobar, FOOBAR)
218 extern "C" /* prevent C++ name mangling */
220 void FOOBAR_F77 (double *x, double *y);
222 /* Taken from autoconf.texi:Fortran Compiler. */
223 #ifdef F77_DUMMY_MAIN
227 int F77_DUMMY_MAIN () { return 1; }
230 int main(int argc, char *argv[])
232 double x = 2.7183, y;
234 if (fabs (8.539784097 - y) > 1.e-6)
244 AT_CHECK([$MAKE], [], [ignore], [ignore])
245 dnl AT_CHECK([./cprogram])
250 ## ----------------------- ##
251 ## AC_FC_DUMMY_MAIN usage. ##
252 ## ----------------------- ##
254 AT_SETUP([AC_FC_DUMMY_MAIN usage])
256 AT_DATA([configure.ac],
258 AC_CONFIG_HEADERS([config.h:config.hin])
261 AC_FC_DUMMY_MAIN([], [AC_MSG_FAILURE([failed to determine FC dummy main], [77])])
264 AC_CONFIG_FILES([Makefile])
268 AT_DATA([Makefile.in],
270 all: cprogram@EXEEXT@
272 cprogram@EXEEXT@: cprogram.@OBJEXT@ foobar.@OBJEXT@
273 @CC@ @CFLAGS@ @LDFLAGS@ -o $@ cprogram.@OBJEXT@ foobar.@OBJEXT@ @LIBS@ @FCLIBS@
275 .SUFFIXES: .c .f .@OBJEXT@
279 @CC@ @DEFS@ -I. @CPPFLAGS@ @CFLAGS@ -c $<
283 [[C This is just a purely numeric routine, no I/O needed.
284 C Taken from autoconf.texi:Fortran Compiler.
285 subroutine foobar (x, y)
286 double precision x, y
292 AT_DATA([cprogram.c],
293 [[#include <config.h>
296 /* Taken from autoconf.texi:Fortran Compiler. */
297 #define FOOBAR_FC FC_FUNC (foobar, FOOBAR)
299 extern "C" /* prevent C++ name mangling */
301 void FOOBAR_FC(double *x, double *y);
303 /* Taken from autoconf.texi:Fortran Compiler. */
308 int FC_DUMMY_MAIN () { return 1; }
311 int main (int argc, char *argv[])
313 double x = 2.7183, y;
315 if (fabs (8.539784097 - y) > 1.e-6)
325 AT_CHECK([$MAKE], [], [ignore], [ignore])
326 dnl AT_CHECK([./cprogram])
331 ## ------------------ ##
332 ## AC_F77_MAIN usage. ##
333 ## ------------------ ##
335 AT_SETUP([AC_F77_MAIN usage])
337 AT_DATA([configure.ac],
339 AC_CONFIG_HEADERS([config.h:config.hin])
344 AC_CONFIG_FILES([Makefile])
348 AT_DATA([Makefile.in],
350 all: cprogram@EXEEXT@
352 cprogram@EXEEXT@: cprogram.@OBJEXT@ foobar.@OBJEXT@
353 @CC@ @CFLAGS@ @LDFLAGS@ -o $@ cprogram.@OBJEXT@ foobar.@OBJEXT@ @LIBS@ @FLIBS@
355 .SUFFIXES: .c .f .@OBJEXT@
359 @CC@ @DEFS@ -I. @CPPFLAGS@ @CFLAGS@ -c $<
363 [[C This uses Fortran I/O, so is likely to require Fortran startup.
364 subroutine foobar (x)
367 write(*,*) 'some output from Fortran sources'
372 AT_DATA([cprogram.c],
373 [[#include <config.h>
376 /* Taken from autoconf.texi:Fortran Compiler. */
377 #define FOOBAR_F77 F77_FUNC (foobar, FOOBAR)
379 extern "C" /* prevent C++ name mangling */
381 void FOOBAR_F77 (int *x);
383 /* Taken from autoconf.texi:Fortran Compiler. */
387 int F77_MAIN (int argc, char *argv[]);
389 int F77_MAIN (int argc, char *argv[])
392 puts ("output from C main");
395 puts ("more output from C main");
404 AT_CHECK([$MAKE], [], [ignore], [ignore])
405 dnl AT_CHECK([./cprogram], [], [output from C main
406 dnl some output from Fortran sources
407 dnl more output from C main
413 ## ----------------- ##
414 ## AC_FC_MAIN usage. ##
415 ## ----------------- ##
417 AT_SETUP([AC_FC_MAIN usage])
419 AT_DATA([configure.ac],
421 AC_CONFIG_HEADERS([config.h:config.hin])
427 AC_CONFIG_FILES([Makefile])
431 AT_DATA([Makefile.in],
432 [[all: cprogram@EXEEXT@
434 cprogram@EXEEXT@: cprogram.@OBJEXT@ foobar.@OBJEXT@
435 @CC@ @CFLAGS@ @LDFLAGS@ -o $@ cprogram.@OBJEXT@ foobar.@OBJEXT@ @LIBS@ @FCLIBS@
437 .SUFFIXES: .c .f .@OBJEXT@
441 @CC@ @DEFS@ -I. @CPPFLAGS@ @CFLAGS@ -c $<
445 [[C This uses Fortran I/O, so is likely to require Fortran startup.
446 subroutine foobar (x)
449 write (*,*) 'some output from Fortran sources'
454 AT_DATA([cprogram.c],
455 [[#include <config.h>
458 /* Taken from autoconf.texi:Fortran Compiler. */
459 #define FOOBAR_FC FC_FUNC (foobar, FOOBAR)
461 extern "C" /* prevent C++ name mangling */
463 void FOOBAR_FC (int *x);
465 /* Taken from autoconf.texi:Fortran Compiler. */
469 int FC_MAIN (int argc, char *argv[]);
471 int FC_MAIN (int argc, char *argv[])
474 puts ("output from C main");
477 puts ("more output from C main");
486 AT_CHECK([$MAKE], [], [ignore], [ignore])
487 dnl AT_CHECK([./cprogram], [], [output from C main
488 dnl some output from Fortran sources
489 dnl more output from C main
495 ## ------------------ ##
496 ## AC_F77_FUNC usage. ##
497 ## ------------------ ##
499 AT_SETUP([AC_F77_FUNC usage])
501 AT_DATA([configure.ac],
504 AC_F77_FUNC([foobar])
507 AC_CONFIG_FILES([cprogram.c:cprogram.in])
508 AC_CONFIG_FILES([Makefile])
512 AT_DATA([Makefile.in],
514 all: cprogram@EXEEXT@
516 cprogram@EXEEXT@: cprogram.@OBJEXT@ foobar.@OBJEXT@
517 @CC@ @CFLAGS@ @LDFLAGS@ -o $@ cprogram.@OBJEXT@ foobar.@OBJEXT@ @LIBS@ @FLIBS@
519 .SUFFIXES: .c .f .@OBJEXT@
523 @CC@ @DEFS@ @CPPFLAGS@ @CFLAGS@ -c $<
527 [[ subroutine foobar (x)
534 AT_DATA([cprogram.in],
538 extern "C" /* prevent C++ name mangling */
540 void @foobar@ (int *x);
542 /* Taken from autoconf.texi:Fortran Compiler. */
543 #ifdef F77_DUMMY_MAIN
547 int F77_DUMMY_MAIN () { return 1; }
550 int main(int argc, char *argv[])
563 AT_CHECK([$MAKE], [], [ignore], [ignore])
564 dnl AT_CHECK([./cprogram])
569 ## ----------------- ##
570 ## AC_FC_FUNC usage. ##
571 ## ----------------- ##
573 AT_SETUP([AC_FC_FUNC usage])
575 AT_DATA([configure.ac],
581 AC_CONFIG_FILES([cprogram.c:cprogram.in])
582 AC_CONFIG_FILES([Makefile])
586 AT_DATA([Makefile.in],
588 all: cprogram@EXEEXT@
590 cprogram@EXEEXT@: cprogram.@OBJEXT@ foobar.@OBJEXT@
591 @CC@ @CFLAGS@ @LDFLAGS@ -o $@ cprogram.@OBJEXT@ foobar.@OBJEXT@ @LIBS@ @FCLIBS@
593 .SUFFIXES: .c .f .@OBJEXT@
597 @CC@ @DEFS@ @CPPFLAGS@ @CFLAGS@ -c $<
601 [[ subroutine foobar (x)
608 AT_DATA([cprogram.in],
612 extern "C" /* prevent C++ name mangling */
614 void @foobar@ (int *x);
616 /* Taken from autoconf.texi:Fortran Compiler. */
621 int FC_DUMMY_MAIN () { return 1; }
624 int main(int argc, char *argv[])
637 AT_CHECK([$MAKE], [], [ignore], [ignore])
638 dnl AT_CHECK([./cprogram])
642 ## ------------------- ##
643 ## AC_FC_SRCEXT usage. ##
644 ## ------------------- ##
646 AT_SETUP([AC_FC_SRCEXT usage])
648 AT_DATA([configure.ac],
651 FCFLAGS_NOFREE=$FCFLAGS
652 AC_SUBST([FCFLAGS_NOFREE])
654 # Unconditionally require .f to work.
656 # For each other extension, fail gracefully if it does not work:
657 # Not all compilers support all extensions/language versions.
658 m4@&t@_foreach([ext], [f77, f90, f95, f03, f08],
659 [AC_FC_SRCEXT(ext, ext[_object='foo]ext[.$(OBJEXT)'], ext[_object=])
660 AC_SUBST(ext[_object])])
661 AC_CONFIG_FILES([Makefile])
665 AT_DATA([Makefile.in],
669 prog@EXEEXT@: foof.@OBJEXT@ @f77_object@ @f90_object@ \
670 @f95_object@ @f03_object@ @f08_object@
671 @FC@ @FCFLAGS@ -o $@ foof.@OBJEXT@ @f77_object@ @f90_object@ \
672 @f95_object@ @f03_object@ @f08_object@
674 .SUFFIXES: .f .f77 .f90 .f95 .f03 .f08 .@OBJEXT@
676 @FC@ -c @FCFLAGS_NOFREE@ @FCFLAGS_f@ $<
678 @FC@ -c @FCFLAGS_NOFREE@ @FCFLAGS_f77@ $<
680 @FC@ -c @FCFLAGS@ @FCFLAGS_f90@ $<
682 @FC@ -c @FCFLAGS@ @FCFLAGS_f95@ $<
684 @FC@ -c @FCFLAGS@ @FCFLAGS_f03@ $<
686 @FC@ -c @FCFLAGS@ @FCFLAGS_f08@ $<
694 AT_DATA([foof77.f77],
699 AT_DATA([foof90.f90],
704 AT_DATA([foof95.f95],
709 AT_DATA([foof03.f03],
714 AT_DATA([foof08.f08],
722 AT_CHECK([$MAKE], [], [ignore], [ignore])
727 ## --------------- ##
728 ## AC_FC_FREEFORM. ##
729 ## --------------- ##
731 AT_SETUP([AC_FC_FREEFORM])
733 AT_DATA([configure.ac],
737 AC_CONFIG_FILES([Makefile])
741 AT_DATA([Makefile.in],
742 [[prog: prog.@OBJEXT@
743 @FC@ @FCFLAGS@ -o $@ prog.@OBJEXT@ @LIBS@
745 .SUFFIXES: .f .@OBJEXT@
758 AT_CHECK([$MAKE], [], [ignore], [ignore])
759 dnl AT_CHECK([./prog])
764 ## --------------------------------- ##
765 ## AC_FC_FREEFORM with AC_FC_SRCEXT. ##
766 ## --------------------------------- ##
768 AT_SETUP([AC_FC_FREEFORM with AC_FC_SRCEXT])
770 AT_DATA([configure.ac],
772 AC_FC_SRCEXT([f90], [], [AS_EXIT([77])])
775 AC_CONFIG_FILES([Makefile])
779 AT_DATA([Makefile.in],
780 [[prog: prog.@OBJEXT@
781 @FC@ @FCFLAGS@ -o $@ prog.@OBJEXT@ @LIBS@
783 .SUFFIXES: .f90 .@OBJEXT@
785 @FC@ @FCFLAGS@ -c @FCFLAGS_f90@ $<
796 AT_CHECK([$MAKE], [], [ignore], [ignore])
797 dnl AT_CHECK([./prog])
802 ## ---------------- ##
803 ## AC_FC_FIXEDFORM. ##
804 ## ---------------- ##
806 AT_SETUP([AC_FC_FIXEDFORM])
808 AT_DATA([configure.ac],
812 AC_CONFIG_FILES([Makefile])
816 AT_DATA([Makefile.in],
817 [[prog: prog.@OBJEXT@
818 @FC@ @FCFLAGS@ -o $@ prog.@OBJEXT@ @LIBS@
820 .SUFFIXES: .f .@OBJEXT@
827 C fixed-form style comment
834 AT_CHECK([$MAKE], [], [ignore], [ignore])
835 dnl AT_CHECK([./prog])
840 ## ---------------------------------- ##
841 ## AC_FC_FIXEDFORM with AC_FC_SRCEXT. ##
842 ## ---------------------------------- ##
844 AT_SETUP([AC_FC_FIXEDFORM with AC_FC_SRCEXT])
846 AT_DATA([configure.ac],
849 AC_FC_SRCEXT([f90], [], [AS_EXIT([77])])
851 AC_CONFIG_FILES([Makefile])
855 AT_DATA([Makefile.in],
856 [[prog: prog.@OBJEXT@
857 @FC@ @FCFLAGS@ -o $@ prog.@OBJEXT@ @LIBS@
859 .SUFFIXES: .f90 .@OBJEXT@
861 @FC@ @FCFLAGS@ -c @FCFLAGS_f90@ $<
866 C fixed-form style comment
873 AT_CHECK([$MAKE], [], [ignore], [ignore])
874 dnl AT_CHECK([./prog])
879 ## ------------------ ##
880 ## AC_FC_LINE_LENGTH. ##
881 ## ------------------ ##
883 AT_SETUP([AC_FC_LINE_LENGTH])
885 AT_DATA([Makefile.in],
886 [[prog@EXEEXT@: prog.@OBJEXT@
887 @FC@ @FCFLAGS@ -o $@ prog.@OBJEXT@ @LIBS@
889 .SUFFIXES: .f .@OBJEXT@
891 @FC@ @FCFLAGS@ -c @FCFLAGS_f@ $<
894 rm -f *.@OBJEXT@ prog@EEXEXT@
898 'subroutine foo(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11)'
900 'subroutine foo(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,'\
901 'arg12,arg13,arg14,arg15,arg16,arg17,arg18,arg19)'
903 'subroutine foo(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,'\
904 'arg12,arg13,arg14,arg15,arg16,arg17,arg18,arg19,arg20,arg21,arg22,arg23,'\
905 'arg24,arg25,arg26,arg27,arg28,arg29,arg30,arg31,arg32,arg33,arg34,arg35,'\
906 'arg36,arg37,arg38,arg39,arg40)'
908 for len in 80 132 254
910 if test $len -eq 254; then arg=unlimited; else arg=$len; fi
911 eval long_line=\$line_$len
913 # Try free-form first, it has a bigger chance of succeeding.
914 for fixed_or_free in FREEFORM FIXEDFORM
917 cat >configure.ac <<EOF
922 AC_FC_LINE_LENGTH([$arg])
923 AC_CONFIG_FILES([Makefile])
937 AT_CHECK([$MAKE], [], [ignore], [ignore])
938 dnl AT_CHECK([./prog])
939 AT_CHECK([$MAKE clean], [], [ignore], [ignore])