1dnl -*- shell-script -*-
2dnl
3dnl Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
4dnl                         University Research and Technology
5dnl                         Corporation.  All rights reserved.
6dnl Copyright (c) 2004-2005 The University of Tennessee and The University
7dnl                         of Tennessee Research Foundation.  All rights
8dnl                         reserved.
9dnl Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
10dnl                         University of Stuttgart.  All rights reserved.
11dnl Copyright (c) 2004-2005 The Regents of the University of California.
12dnl                         All rights reserved.
13dnl Copyright (c) 2010-2015 Cisco Systems, Inc.  All rights reserved.
14dnl Copyright (c) 2015      Research Organization for Information Science
15dnl                         and Technology (RIST). All rights reserved.
16dnl $COPYRIGHT$
17dnl
18dnl Additional copyrights may follow
19dnl
20dnl $HEADER$
21dnl
22
23dnl
24dnl Check whether Fortran compiler supports the "only" clause properly
25dnl when using modules.  Specifically, if we "use a :: only foo" and "use
26dnl b :: only bar", and modules a and b have a conflicting "yow"
27dnl definition, it *should* be ignored because of the "only" clauses.  PGI
28dnl 15.7 (and probably prior versions) does not -- but only when
29dnl compiling with -g (!).
30dnl
31
32dnl OMPI_FORTRAN_CHECK_USE_ONLY([action if supported],
33dnl                                [action if not supported])
34dnl ----------------------------------------------------
35AC_DEFUN([OMPI_FORTRAN_CHECK_USE_ONLY],[
36    AS_VAR_PUSHDEF([use_only_var], [ompi_cv_fortran_use_only])
37    OPAL_VAR_SCOPE_PUSH([FCFLAGS_save])
38    FCFLAGS_save=$FCFLAGS
39    FCFLAGS="-I. $FCFLAGS"
40
41    AC_CACHE_CHECK([if Fortran compiler supports USE...ONLY], use_only_var,
42       [AC_LANG_PUSH([Fortran])
43        cat > aaa.f90 << EOF
44MODULE aaa
45INTEGER :: CMON(1)
46COMMON/CMMON/CMON
47INTEGER :: global_aaa
48END MODULE aaa
49EOF
50        cat > bbb.f90 << EOF
51MODULE bbb
52integer, bind(C, name="cmmon_") :: CMON
53INTEGER :: global_bbb
54END MODULE bbb
55EOF
56        OPAL_LOG_COMMAND([$FC $FCFLAGS -c aaa.f90],
57                         [OPAL_LOG_COMMAND([$FC $FCFLAGS -c bbb.f90],
58                                           [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[PROGRAM test
59USE aaa, ONLY : global_aaa
60USE bbb, ONLY : global_bbb
61implicit none
62END PROGRAM]])],
63                                                              [AS_VAR_SET(use_only_var, yes)],
64                                                              [AS_VAR_SET(use_only_var, no)])],
65                                           [AS_VAR_SET(use_only_var, no)])],
66                         [AS_VAR_SET(use_only_var, no)])
67        rm -rf aaa.f90 aaa.o bbb.f90 bbb.o *.mod 2>/dev/null
68        AC_LANG_POP([Fortran])
69       ])
70
71    AS_VAR_IF(use_only_var, [yes], [$1], [$2])
72    FCFLAGS=$FCFLAGS_save
73    OPAL_VAR_SCOPE_POP
74    AS_VAR_POPDEF([use_only_var])dnl
75])
76