autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Fortran Cray pointer macro support


From: Marshall Ward
Subject: [PATCH] Fortran Cray pointer macro support
Date: Tue, 6 Oct 2020 12:17:59 -0400

This patch addes a macro, AC_FC_CRAY_POINTER, which tests if the Fortran
compiler supports Cray pointers.

It provides additional tests for particular flags required by GFortran
and PGI compilers.  The current set of flags is sparse, but can be
extended for other compilers if needed.

Documentation and a minimal test of the macro have been included.
---
 doc/autoconf.texi       | 19 +++++++++++++++
 lib/autoconf/fortran.m4 | 52 +++++++++++++++++++++++++++++++++++++++++
 tests/fortran.at        | 43 ++++++++++++++++++++++++++++++++++
 3 files changed, 114 insertions(+)

diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index dea85e4a..0e104fde 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -8565,6 +8565,25 @@ The substituted value of @code{FC_MODOUT} may refer to 
the
 the significant trailing whitespace in a @file{Makefile}.
 @end defmac
 
+@defmac AC_FC_CRAY_POINTER (@ovar{action-if-success}, @
+  @dvar{action-if-failure, AC_MSG_FAILURE})
+@acindex{FC_CRAY_POINTER}
+@caindex fc_cray_pointer
+
+Try to ensure that the Fortran compiler (@code{$FC}) accepts Cray
+pointers.  If successful, the @var{action-if-success} is called and any
+needed flags are added to @code{FCFLAGS}.  Otherwise,
+@var{action-if-failure} is called, which defaults to failing with an
+error message.
+
+Cray pointers are a non-standard extension supported by many Fortran
+compilers which allow an integer to be declared as C-like pointer to
+a target variable.
+
+The result of this test, or @samp{none} or @samp{unknown}, is cached in
+the @code{ac_cv_fc_cray_ptr} variable.
+@end defmac
+
 
 @node Go Compiler
 @subsection Go Compiler Characteristics
diff --git a/lib/autoconf/fortran.m4 b/lib/autoconf/fortran.m4
index 59a8859b..faa1ef4e 100644
--- a/lib/autoconf/fortran.m4
+++ b/lib/autoconf/fortran.m4
@@ -1857,3 +1857,55 @@ AC_CONFIG_COMMANDS_PRE([case $FC_MODOUT in #(
   *\ ) FC_MODOUT=$FC_MODOUT'${ac_empty}' ;;
 esac])dnl
 ])
+
+
+# AC_FC_CRAY_POINTER([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
+#-------------------------------------------------------------
+# Try to ensure that the Fortran compiler ($FC) supports Cray pointers, a
+# non-standard extension that provides a C-like pointer in Fortran.
+#
+# If successful, ACTION-IF-SUCCESS is called.  If no argument is provided, then
+# any necessary flags are added to FCFLAGS.  Otherwise, ACTION-IF-FAILURE is
+# called, which defaults to failing with an error message.
+#
+# Most compilers provide an implementation of Cray pointers, and often no
+# additional flags are required to enable support.  A partial list of compilers
+# and flags which may be required are listed below.
+#
+# The known flags are:
+#   -fcray-pointer: gfortran
+#   -Mcray-pointer: PGI
+AC_DEFUN([AC_FC_CRAY_POINTER], [
+  AC_LANG_PUSH([Fortran])
+  AC_MSG_CHECKING([for $FC option to support Cray pointers])
+  AC_CACHE_VAL([ac_cv_fc_cray_ptr], [
+    ac_cv_fc_cray_ptr='unknown'
+    ac_save_FCFLAGS=$FCFLAGS
+    for ac_option in none -fcray-pointer -Mcray=pointer; do
+      test "$ac_option" != none && FCFLAGS="$ac_save_FCFLAGS $ac_option"
+      AC_COMPILE_IFELSE(
+        [AC_LANG_PROGRAM([], [
+      integer aptr(2)
+      pointer (iptr, aptr)
+        ])],
+        [ac_cv_fc_cray_ptr=$ac_option],
+      )
+      FCFLAGS=$ac_save_FCFLAGS
+      AS_IF([test "$ac_cv_fc_cray_ptr" != unknown], [break])
+    done
+  ])
+  AS_CASE([ac_cv_fc_cray_ptr],
+    [none], [AC_MSG_RESULT([none_needed])],
+    [unknown], [AC_MSG_RESULT([unsupported])],
+    [AC_MSG_RESULT([$ac_cv_fc_cray_ptr])]
+  )
+  AS_IF([test "$ac_cv_fc_cray_ptr" != unknown], [
+    m4_default([$1], [
+      AS_IF([test "$ac_cv_fc_cray_ptr" != none],
+        [FCFLAGS="$FCFLAGS $ac_cv_fc_cray_ptr"]
+      )
+    ])],
+    [m4_default([$2], [AC_MSG_ERROR(["$FC does not support Cray pointers"])])]
+  )
+  AC_LANG_POP([Fortran])
+])
diff --git a/tests/fortran.at b/tests/fortran.at
index cf4d9fef..e62f9a0b 100644
--- a/tests/fortran.at
+++ b/tests/fortran.at
@@ -1180,3 +1180,46 @@ AT_CHECK([./prog], [], [ignore], [ignore])
 AT_CHECK_MAKE([clean])
 
 AT_CLEANUP
+
+
+## ------------------- ##
+## AC_FC_CRAY_POINTER. ##
+## ------------------- ##
+
+AT_SETUP([AC_FC_CRAY_POINTER])
+
+AT_DATA([configure.ac],
+[[AC_INIT
+AC_PROG_FC
+AC_FC_SRCEXT([f])
+AC_FC_CRAY_POINTER
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+]])
+
+AT_DATA([Makefile.in],
+[[prog@EXEEXT@: prog.@OBJEXT@
+       @FC@ @FCFLAGS@ -o $@ prog.@OBJEXT@ @LIBS@
+
+.SUFFIXES: .f .@OBJEXT@
+.f.@OBJEXT@:
+       @FC@ @FCFLAGS@ -c @FCFLAGS_f@ $<
+
+clean:
+       rm -f *.@OBJEXT@ prog@EEXEXT@
+]])
+
+AT_DATA([prog.f],
+[[      program main
+      integer aptr(2)
+      pointer (iptr, aptr)
+      end
+]])
+
+AT_CHECK_AUTOCONF
+AT_CHECK_CONFIGURE
+AT_CHECK_MAKE
+AT_CHECK([./prog])
+AT_CHECK_MAKE([clean])
+
+AT_CLEANUP
-- 
2.28.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]