1dnl  This file is part of MED.
2dnl
3dnl  COPYRIGHT (C) 1999 - 2019  EDF R&D, CEA/DEN
4dnl  MED is free software: you can redistribute it and/or modify
5dnl  it under the terms of the GNU Lesser General Public License as published by
6dnl  the Free Software Foundation, either version 3 of the License, or
7dnl  (at your option) any later version.
8dnl
9dnl  MED is distributed in the hope that it will be useful,
10dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
11dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12dnl  GNU Lesser General Public License for more details.
13dnl
14dnl  You should have received a copy of the GNU Lesser General Public License
15dnl  along with MED.  If not, see <http://www.gnu.org/licenses/>.
16dnl
17
18AC_DEFUN([AC_CHECK_SIZEOF_FORTRAN], [
19  AC_REQUIRE([AC_F77_WRAPPERS])
20  AC_CACHE_CHECK([size of Fortran [$1]], [ac_cv_sizeof_fortran_[]translit($1, [A-Z *], [a-z_p])],[
21    AC_LANG_SAVE()
22    AC_LANG([Fortran 77])
23    AC_COMPILE_IFELSE([
24      AC_LANG_SOURCE([
25        subroutine fsize()
26        $1 i(2)
27        call csize(i(1), i(2))
28        end
29      ])
30    ],[
31      AC_LANG([C])
32      cp conftest.$ac_objext conftestf.$ac_objext
33      old_LDFLAGS="$LDFLAGS"
34      LDFLAGS="conftestf.$ac_objext $LDFLAGS"
35#"$ac_cv_f77_libs"
36      AC_TRY_RUN([
37#       include <stdio.h>
38#         define CSIZE F77_FUNC(csize,CSIZE)
39#         define FSIZE F77_FUNC(fsize,FSIZE)
40	void FSIZE();
41        static long size_val;
42        /* Called by Fortran */
43        void CSIZE (i1p, i2p)
44        char *i1p, *i2p;
45        {
46          size_val = (i2p - i1p);
47        }
48        int main() {
49          FILE *f=fopen ("conftestval","w");
50          if (!f) return 1;
51          /* Call the Fortran function */
52          FSIZE ();
53          fprintf (f, "%ld\n", size_val);
54          return 0;
55        }
56     ])
57     LDFLAGS="$old_LDFLAGS"
58     ac_cv_sizeof_fortran_[]translit($1, [A-Z *], [a-z_p])=`cat conftestval`
59     rm -f conftestval conftestf.$ac_objext
60    ])
61    AC_LANG_RESTORE()
62  ])
63  AC_DEFINE_UNQUOTED(SIZEOF_FORTRAN_[]translit($1, [a-z *], [A-Z_p]),
64                     [$ac_cv_sizeof_fortran_[]translit($1, [A-Z *], [a-z_p])],
65                     [The size of a Fortran `$1', as computed by sizeof.])
66
67])
68