libtool
[Top][All Lists]
Advanced

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

Fortran 90/95 (FC) support


From: Ralf Wildenhues
Subject: Fortran 90/95 (FC) support
Date: Fri, 10 Jun 2005 00:24:00 +0200
User-agent: Mutt/1.5.9i

In order to make the Libtool build and test suite a bit slower  :->
I hacked in initial `modern Fortran' support, i.e., support for
Autoconf's FC interface.

Please understand this as a call for testing from the Fortran people to
know how it goes (thus the cross-post to libtool).  There are still
tweaks necessary.

Changes/questions/issues so far:
- This patch currently needs the boilerplate patch, the
  _LT_COMPILER_OPTION sed patch, and the patch for fixing the m4 loop
  applied beforehand.
- _LT_SYS_HIDDEN_LIBDEPS enabled (patch for F77 pending).
- Tests are freeform.  AC_SRCEXT should be honored, default ext is .f90,
  (due to Intel ifc/ifort constraints).
- Test suite fcdemo new, mostly copied over from f77demo, but with .f90,
  AC_FC_SRCEXT, and AC_FC_FREEFORM (and actual free-form-only code).
- Test code inside libtool.m4 should conform to both free and fixed form,
  uses given source extension (as encoded inside $ac_compile).
- For full FC support, we need to wait for fixed Automake.
- `ifort -static' is falsely detected as broken, because it shows
  link-warnings.

The patch is based on branch-2-0, but should apply mostly to HEAD as
well.  Tested with:
gfortran-4.0.0, ifort-8.1, pgi-5.2/6.0 (all linux-gnu/x86_64/x86),
Solaris 8 f90/f95 (which has the usual open -no-undefined problem),
AIX 5.1 xlf90/xlf95.

Note that some things may be factored out better with m4 trickery.
I refrained from doing that yet -- it may just as well be done when
we're fairly sure no more issues (F77/FC differences) show up.

Many thanks to Steven G. Johnson for help; see also this thread:
http://lists.gnu.org/archive/html/autoconf/2005-06/msg00033.html

Thanks,
Ralf

        * m4/libtool.m4 (_LT_PROG_FC, _LT_LANG_FC_CONFIG): New macros
        for modern Fortran.
        (LT_LANG, _LT_LANG_DEFAULT_CONFIG, _LT_SYS_DYNAMIC_LINKER,
        _LT_SYS_HIDDEN_LIBDEPS): Adjust.
        * tests/fcdemo-conf.test, tests/fcdemo-exec.test,
        tests/fcdemo-make.test, tests/fcdemo-shared.test,
        tests/fcdemo-static.test, tests/fcdemo/Makefile.am, tests/fcdemo/README,
        tests/fcdemo/configure.ac, tests/fcdemo/cprogram.c, tests/fcdemo/foo.h,
        tests/fcdemo/fooc.c, tests/fcdemo/foof.f90, tests/fcdemo/foof2.f90,
        tests/fcdemo/foof3.f90, tests/fcdemo/fprogram.f90: New tests for 
Fortran.
        * Makefile.am, configure.ac: Adjust.
        * NEWS: Update.

Index: Makefile.am
===================================================================
RCS file: /cvsroot/libtool/libtool/Makefile.am,v
retrieving revision 1.130.2.17
diff -u -r1.130.2.17 Makefile.am
--- Makefile.am 5 Jun 2005 18:18:17 -0000       1.130.2.17
+++ Makefile.am 9 Jun 2005 17:06:19 -0000
@@ -274,9 +274,9 @@
        OBJEXT="$(OBJEXT)" EXEEXT="$(EXEEXT)" CONFIG_SHELL="$(SHELL)" \
        CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS)" CXXCPP="$(CXXCPP)" \
        F77="$(F77)" FFLAGS="$(FFLAGS)" \
+        FC="$(FC)" FCFLAGS="$(FCFLAGS)" \
        GCJ="$(GCJ)" GCJFLAGS="$(GCJFLAGS)"
 
-
 CXX_TESTS = \
        tests/tagdemo-static.test tests/tagdemo-make.test \
        tests/tagdemo-exec.test tests/tagdemo-conf.test \
@@ -292,6 +292,13 @@
        tests/f77demo-shared.test tests/f77demo-make.test \
        tests/f77demo-exec.test
 
+FC_TESTS = \
+       tests/fcdemo-static.test tests/fcdemo-make.test \
+       tests/fcdemo-exec.test tests/fcdemo-conf.test \
+       tests/fcdemo-make.test tests/fcdemo-exec.test \
+       tests/fcdemo-shared.test tests/fcdemo-make.test \
+       tests/fcdemo-exec.test
+
 COMMON_TESTS = \
        tests/link.test tests/link-2.test tests/nomode.test \
        tests/objectlist.test tests/quote.test tests/sh.test \
@@ -334,24 +341,21 @@
        tests/cdemo-undef.test tests/cdemo-make.test tests/cdemo-exec.test \
        tests/duplicate_members.test
 
+TESTS = $(COMMON_TESTS)
 if HAVE_CXX
-if HAVE_F77
-TESTS = $(COMMON_TESTS) $(CXX_TESTS) $(F77_TESTS)
-else
-TESTS = $(COMMON_TESTS) $(CXX_TESTS)
+TESTS += $(CXX_TESTS)
 endif
-else
 if HAVE_F77
-TESTS = $(COMMON_TESTS) $(F77_TESTS)
-else
-TESTS = $(COMMON_TESTS)
+TESTS += $(F77_TESTS)
 endif
+if HAVE_FC
+TESTS += $(FC_TESTS)
 endif
 
 tests/demo-conf.test: libtool
 
 EXTRA_DIST     += tests/defs.in tests/defs.m4sh \
-                 $(COMMON_TESTS) $(CXX_TESTS) $(F77_TESTS)
+                 $(COMMON_TESTS) $(CXX_TESTS) $(F77_TESTS) $(FC_TESTS)
 DIST_SUBDIRS   += $(CONF_SUBDIRS)
 
 # The defs script shouldn't be recreated whenever the Makefile is
@@ -374,7 +378,7 @@
 # We need to remove any files that the above tests created.
 clean-local:
        -cd tests; \
-       for dir in cdemo demo depdemo f77demo mdemo mdemo2 pdemo tagdemo; \
+       for dir in cdemo demo depdemo f77demo fcdemo mdemo mdemo2 pdemo 
tagdemo; \
        do \
            test -f $$dir/Makefile && ( cd $$dir && $(MAKE) distclean; ); \
        done
Index: NEWS
===================================================================
RCS file: /cvsroot/libtool/libtool/NEWS,v
retrieving revision 1.168.2.18
diff -u -r1.168.2.18 NEWS
--- NEWS        15 Apr 2005 13:37:28 -0000      1.168.2.18
+++ NEWS        9 Jun 2005 17:06:19 -0000
@@ -10,6 +10,7 @@
 * Allow shell special characters like `$' in source file names, but not
   in object names, to enhance GCJ support.
 * Detection of compiler wrappers like distcc/ccache and $host_alias prefix.
+* Initial Support for FC (modern Fortran).
 
 New in 1.9f: 2004-10-23; CVS version 1.9e, Libtool team:
 * Calculate dllsearchpath correctly for wrapper scripts on cygwin.
Index: configure.ac
===================================================================
RCS file: /cvsroot/libtool/libtool/configure.ac,v
retrieving revision 1.56.2.12
diff -u -r1.56.2.12 configure.ac
--- configure.ac        25 Apr 2005 15:06:43 -0000      1.56.2.12
+++ configure.ac        9 Jun 2005 17:06:19 -0000
@@ -137,8 +137,8 @@
 
 # All subdirectories that are configured on demand, but that must be
 # included in the distribution.
-CONF_SUBDIRS="tests/cdemo tests/demo tests/depdemo tests/f77demo tests/mdemo \
-       tests/mdemo2 tests/pdemo tests/tagdemo"
+CONF_SUBDIRS="tests/cdemo tests/demo tests/depdemo tests/f77demo tests/fcdemo \
+       tests/mdemo tests/mdemo2 tests/pdemo tests/tagdemo"
 AC_SUBST([CONF_SUBDIRS])
 
 DIST_MAKEFILE_LIST=
@@ -168,6 +168,7 @@
 # Enable all the language support we can
 LT_LANG(C++)
 LT_LANG(Fortran 77)
+LT_LANG(Fortran)
 LT_LANG(Java)
 LT_LANG(Windows Resource)
 
@@ -177,6 +178,7 @@
 ## --------------------------- ##
 AM_CONDITIONAL(HAVE_CXX,[test -n "[$]_LT_TAGVAR(compiler, CXX)"])
 AM_CONDITIONAL(HAVE_F77,[test -n "[$]_LT_TAGVAR(compiler, F77)"])
+AM_CONDITIONAL(HAVE_FC,[test -n "[$]_LT_TAGVAR(compiler, FC)"])
 AM_CONDITIONAL(HAVE_GCJ, [test -n "[$]_LT_TAGVAR(compiler, GCJ)"])
 AM_CONDITIONAL(HAVE_RC, [test -n "[$]_LT_TAGVAR(compiler, RC)"])
 
Index: m4/libtool.m4
===================================================================
RCS file: /cvsroot/libtool/libtool/m4/libtool.m4,v
retrieving revision 1.125.2.58
diff -u -r1.125.2.58 libtool.m4
--- m4/libtool.m4       6 Jun 2005 16:13:23 -0000       1.125.2.58
+++ m4/libtool.m4       9 Jun 2005 17:06:19 -0000
@@ -606,6 +608,7 @@
   [C++],               [_LT_LANG(CXX)],
   [Java],              [_LT_LANG(GCJ)],
   [Fortran 77],                [_LT_LANG(F77)],
+  [Fortran],           [_LT_LANG(FC)],
   [Windows Resource],  [_LT_LANG(RC)],
   [m4_ifdef([_LT_LANG_]$1[_CONFIG],
     [_LT_LANG($1)],
@@ -633,6 +636,10 @@
   [LT_LANG(F77)],
   [m4_define([AC_PROG_F77], defn([AC_PROG_F77])[LT_LANG(F77)])])
 
+AC_PROVIDE_IFELSE([AC_PROG_FC],
+  [LT_LANG(FC)],
+  [m4_define([AC_PROG_FC], defn([AC_PROG_FC])[LT_LANG(FC)])])
+
 dnl The call to [A][M_PROG_GCJ] is quoted like that to stop aclocal
 dnl pulling things in needlessly.
 AC_PROVIDE_IFELSE([AC_PROG_GCJ],
@@ -656,10 +663,12 @@
 # Obsolete macros:
 AU_DEFUN([AC_LIBTOOL_CXX], [LT_LANG(C++)])
 AU_DEFUN([AC_LIBTOOL_F77], [LT_LANG(Fortran 77)])
+AU_DEFUN([AC_LIBTOOL_FC], [LT_LANG(Fortran)])
 AU_DEFUN([AC_LIBTOOL_GCJ], [LT_LANG(Java)])
 dnl aclocal-1.4 backwards compatibility:
 dnl AC_DEFUN([AC_LIBTOOL_CXX], [])
 dnl AC_DEFUN([AC_LIBTOOL_F77], [])
+dnl AC_DEFUN([AC_LIBTOOL_FC], [])
 dnl AC_DEFUN([AC_LIBTOOL_GCJ], [])
 
 
@@ -1646,6 +1655,7 @@
        [C], [withGCC=$GCC],
        [CXX], [withGCC=$GXX],
        [F77], [withGCC=$G77],
+       [FC], [withGCC=$ac_cv_fc_compiler_gnu],
        [withGCC=$GCC])
 library_names_spec=
 libname_spec='lib$name'
@@ -5631,6 +5641,14 @@
       return
       end
 _LT_EOF
+], [$1], [FC], [cat > conftest.$ac_ext <<_LT_EOF
+      subroutine foo
+      implicit none
+      integer a
+      a=0
+      return
+      end
+_LT_EOF
 ], [$1], [GCJ], [cat > conftest.$ac_ext <<_LT_EOF
 public class foo {
   private int a;
@@ -5872,6 +5891,136 @@
 ])# _LT_LANG_F77_CONFIG
 
 
+# _LT_PROG_FC
+# -----------
+# Since AC_PROG_FC is broken, in that it returns the empty string
+# if there is no fortran compiler, we have our own version here.
+m4_defun([_LT_PROG_FC],
+[
+pushdef([AC_MSG_ERROR], [_lt_caught_FC_error=yes])
+AC_PROG_FC
+if test -z "$FC"; then
+  _lt_caught_FC_error=yes
+fi
+popdef([AC_MSG_ERROR])
+])# _LT_PROG_FC
+
+
+# _LT_LANG_FC_CONFIG([TAG])
+# --------------------------
+# Ensure that the configuration variables for a Fortran compiler are
+# suitably defined.  These variables are subsequently used by _LT_CONFIG
+# to write the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_FC_CONFIG],
+[AC_REQUIRE([_LT_PROG_FC])dnl
+AC_LANG_PUSH(Fortran)
+
+_LT_TAGVAR(archive_cmds_need_lc, $1)=no
+_LT_TAGVAR(allow_undefined_flag, $1)=
+_LT_TAGVAR(always_export_symbols, $1)=no
+_LT_TAGVAR(archive_expsym_cmds, $1)=
+_LT_TAGVAR(export_dynamic_flag_spec, $1)=
+_LT_TAGVAR(hardcode_direct, $1)=no
+_LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+_LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)=
+_LT_TAGVAR(hardcode_libdir_separator, $1)=
+_LT_TAGVAR(hardcode_minus_L, $1)=no
+_LT_TAGVAR(hardcode_automatic, $1)=no
+_LT_TAGVAR(inherit_rpath, $1)=no
+_LT_TAGVAR(module_cmds, $1)=
+_LT_TAGVAR(module_expsym_cmds, $1)=
+_LT_TAGVAR(link_all_deplibs, $1)=unknown
+_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
+_LT_TAGVAR(no_undefined_flag, $1)=
+_LT_TAGVAR(whole_archive_flag_spec, $1)=
+_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no
+
+# Source file extension for fc test sources.
+ac_ext=${ac_fc_srcext-f}
+
+# Object file extension for compiled fc test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# No sense in running all these tests if we already determined that
+# the FC compiler isn't working.  Some variables (like enable_shared)
+# are currently assumed to apply to all compilers on this platform,
+# and will be corrupted by setting them based on a non-working compiler.
+if test "$_lt_caught_FC_error" != yes; then
+  # Code to be used in simple compile tests
+  lt_simple_compile_test_code="      subroutine t\n      return\n      end\n"
+
+  # Code to be used in simple link tests
+  lt_simple_link_test_code="      program t\n      end\n"
+
+  # ltmain only uses $CC for tagged configurations so make sure $CC is set.
+  _LT_TAG_COMPILER
+
+  # Allow CC to be a program name with arguments.
+  lt_save_CC="$CC"
+  CC=${FC-"f95"}
+  compiler=$CC
+  _LT_TAGVAR(compiler, $1)=$CC
+  _LT_CC_BASENAME([$compiler])
+
+  if test -n "$compiler"; then
+    AC_MSG_CHECKING([if libtool supports shared libraries])
+    AC_MSG_RESULT([$can_build_shared])
+
+    AC_MSG_CHECKING([whether to build shared libraries])
+    test "$can_build_shared" = "no" && enable_shared=no
+
+    # On AIX, shared libraries and static libraries use the same namespace, and
+    # are all built from PIC.
+    case $host_os in
+      aix3*)
+        test "$enable_shared" = yes && enable_static=no
+        if test -n "$RANLIB"; then
+          archive_cmds="$archive_cmds~\$RANLIB \$lib"
+          postinstall_cmds='$RANLIB $lib'
+        fi
+        ;;
+      aix4* | aix5*)
+       if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; 
then
+         test "$enable_shared" = yes && enable_static=no
+       fi
+        ;;
+    esac
+    AC_MSG_RESULT([$enable_shared])
+
+    AC_MSG_CHECKING([whether to build static libraries])
+    # Make sure either enable_shared or enable_static is yes.
+    test "$enable_shared" = yes || enable_static=yes
+    AC_MSG_RESULT([$enable_static])
+
+    test "$_LT_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no
+
+    _LT_TAGVAR(GCC, $1)="$ac_cv_fc_compiler_gnu"
+    _LT_TAGVAR(LD, $1)="$LD"
+
+    ## CAVEAT EMPTOR:
+    ## There is no encapsulation within the following macros, do not change
+    ## the running order or otherwise move them around unless you know exactly
+    ## what you are doing...
+    _LT_SYS_HIDDEN_LIBDEPS($1)
+    _LT_COMPILER_PIC($1)
+    _LT_COMPILER_C_O($1)
+    _LT_COMPILER_FILE_LOCKS($1)
+    _LT_LINKER_SHLIBS($1)
+    _LT_SYS_DYNAMIC_LINKER($1)
+    _LT_LINKER_HARDCODE_LIBPATH($1)
+    _LT_CMD_STRIPLIB
+
+    _LT_CONFIG($1)
+  fi # test -n "$compiler"
+
+  CC="$lt_save_CC"
+fi # test "$_lt_caught_FC_error" != yes
+
+AC_LANG_POP
+])# _LT_LANG_FC_CONFIG
+
+
 # _LT_LANG_GCJ_CONFIG([TAG])
 # --------------------------
 # Ensure that the configuration variables for the GNU Java Compiler compiler



--- /dev/null   2005-06-02 11:44:08.554003640 +0200
+++ tests/fcdemo-conf.test      2005-06-03 18:02:58.000000000 +0200
@@ -0,0 +1,32 @@
+#! /bin/sh
+# fcdemo-conf.test - try configuring the fcdemo subdirectory
+
+# Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
+# This is free software; see the source for copying conditions.  There is NO
+# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, a copy can be downloaded from
+# http://www.gnu.org/copyleft/gpl.html, or by writing to the Free
+# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+. tests/defs || exit 1
+
+func_mkprefixdir
+func_cd "tests/fcdemo"
+func_make_distclean
+func_configure
+func_check_static_shared "yes" "yes"
+
+exit 0
--- /dev/null   2005-06-02 11:44:08.554003640 +0200
+++ tests/fcdemo-exec.test      2005-06-03 18:03:14.000000000 +0200
@@ -0,0 +1,33 @@
+#! /bin/sh
+# fcdemo-exec.test - check that programs in the fcdemo subdirectory are viable
+
+# Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
+# This is free software; see the source for copying conditions.  There is NO
+# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, a copy can be downloaded from
+# http://www.gnu.org/copyleft/gpl.html, or by writing to the Free
+# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+. tests/defs || exit 1
+
+func_require "fcdemo-make" "tests/fcdemo/fprogram$EXEEXT" 
"tests/fcdemo/cprogram$EXEEXT"
+
+func_rmprefixdir
+func_exec_init "uninstalled"
+func_exec "tests/fcdemo/fprogram"
+func_exec "tests/fcdemo/cprogram"
+
+exit $exec_status
--- /dev/null   2005-06-02 11:44:08.554003640 +0200
+++ tests/fcdemo-make.test      2005-06-03 18:09:33.000000000 +0200
@@ -0,0 +1,34 @@
+#! /bin/sh
+# fcdemo-make.test - try building in the fcdemo subdirectory
+
+# Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
+# This is free software; see the source for copying conditions.  There is NO
+# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, a copy can be downloaded from
+# http://www.gnu.org/copyleft/gpl.html, or by writing to the Free
+# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+. tests/defs || exit 1
+
+func_require "fcdemo-conf" "tests/fcdemo/Makefile"
+
+func_rmprefixdir
+func_cd "tests/fcdemo"
+# May fail make on some platforms, simply "skip" in that case
+#func_make
+eval $MAKE || func_skip "The improved fortran tests catch a known failure mode"
+
+exit 0
--- /dev/null   2005-06-02 11:44:08.554003640 +0200
+++ tests/fcdemo-shared.test    2005-06-03 18:09:37.000000000 +0200
@@ -0,0 +1,32 @@
+#! /bin/sh
+# fcdemo-shared.test - try configuring the fcdemo subdirectory for shared libs
+
+# Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
+# This is free software; see the source for copying conditions.  There is NO
+# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, a copy can be downloaded from
+# http://www.gnu.org/copyleft/gpl.html, or by writing to the Free
+# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+. tests/defs || exit 1
+
+func_mkprefixdir
+func_cd "tests/fcdemo"
+func_make_distclean
+func_configure "--disable-static"
+func_check_static_shared "no" "yes"
+
+exit 0
--- /dev/null   2005-06-02 11:44:08.554003640 +0200
+++ tests/fcdemo-static.test    2005-06-03 18:09:40.000000000 +0200
@@ -0,0 +1,32 @@
+#! /bin/sh
+# fcdemo-static.test - try configuring the fcdemo subdirectory for static libs
+
+# Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
+# This is free software; see the source for copying conditions.  There is NO
+# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, a copy can be downloaded from
+# http://www.gnu.org/copyleft/gpl.html, or by writing to the Free
+# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+. tests/defs || exit 1
+
+func_mkprefixdir
+func_cd "tests/fcdemo"
+func_make_distclean
+func_configure "--disable-shared"
+func_check_static_shared "yes" "no"
+
+exit 0
--- /dev/null   2005-06-02 11:44:08.554003640 +0200
+++ tests/fcdemo/Makefile.am    2005-06-06 14:01:13.000000000 +0200
@@ -0,0 +1,51 @@
+## Makefile.am -- Process this file with automake to produce Makefile.in
+##
+## Copyright (C) 2003, 2004, 2005 Free Software Foundation
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; see the file COPYING.  If not, write to
+## the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+## Boston, MA 02110-1301, USA.
+
+AUTOMAKE_OPTIONS = no-dependencies foreign
+ACLOCAL_AMFLAGS  = -I ../../m4
+AM_CPPFLAGS     = -I$(top_srcdir)/../..
+
+lib_LTLIBRARIES = libfoo.la libmix.la libfoo2.la libfoo3.la
+
+libfoo_la_SOURCES = foof.f90
+libfoo_la_LDFLAGS = -no-undefined
+libfoo_la_LIBADD = libfoo2.la
+
+libfoo2_la_SOURCES = foof2.f90
+libfoo2_la_LDFLAGS = -no-undefined
+
+libfoo3_la_SOURCES = foof3.f90
+libfoo3_la_LDFLAGS = -no-undefined
+
+libmix_la_SOURCES = foof.f90 foof2.f90 fooc.c
+libmix_la_LDFLAGS = -no-undefined
+
+noinst_HEADERS = foo.h
+
+bin_PROGRAMS = fprogram cprogram
+
+fprogram_SOURCES = fprogram.f90
+fprogram_LDADD = libfoo.la libfoo3.la
+
+cprogram_SOURCES = cprogram.c
+cprogram_LDADD = libmix.la $(FCLIBS)
+
+$(OBJECTS): libtool
+libtool: $(LIBTOOL_DEPS)
+       $(SHELL) ./config.status --recheck
--- /dev/null   2005-06-02 11:44:08.554003640 +0200
+++ tests/fcdemo/README 2005-06-03 17:58:39.000000000 +0200
@@ -0,0 +1,16 @@
+This is a short demo of the fortran support in libtool.
+
+fprogram is a pure-fortran program which is linked 
+against the fortran-only library libfoo.la
+
+cprogram is a C program, which is linked against the
+mixed C and fortran library libmix.la. The program
+calls a C function, which in turn calls a fortran 
+function.
+
+This demo requires GNU autoconf, automake, 
+libtool with the FC tag and quite obvious Fortran.
+
+
+
+
--- /dev/null   2005-06-02 11:44:08.554003640 +0200
+++ tests/fcdemo/configure.ac   2005-06-06 14:23:49.000000000 +0200
@@ -0,0 +1,79 @@
+## Process this file with autoconf to create configure. -*- autoconf -*-
+# Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301  USA
+
+AC_PREREQ(2.54)
+
+## ------------------------ ##
+## Autoconf initialisation. ##
+## ------------------------ ##
+AC_INIT([fcdemo], [1.0], address@hidden)
+AC_CONFIG_HEADERS([config.h:config-h.in])
+AC_CONFIG_SRCDIR([foof.f90])
+AC_CONFIG_AUX_DIR([../../config])
+
+## ------------------------ ##
+## Automake Initialisation. ##
+## ------------------------ ##
+AM_INIT_AUTOMAKE
+
+
+## ------------------ ##
+## C compiler checks. ##
+## ------------------ ##
+AC_PROG_CC
+
+## ------------------------ ##
+## Fortran compiler checks. ##
+## ------------------------ ##
+AC_LANG_PUSH([Fortran])
+AC_PROG_FC
+dnl Check the flags needed to link fc programs with ld (i.e. cc)
+AC_FC_LIBRARY_LDFLAGS
+dnl Check for underscoring of external names
+AC_FC_WRAPPERS
+dnl We need to use .f90 and not .f to enable Automake FC support
+dnl Some Intel ifc/ifort do not understand .f95.  :-/
+AC_FC_SRCEXT([f90])
+dnl Yes, we want free form Fortran!
+AC_FC_FREEFORM
+AC_LANG_POP
+
+
+# As of the writing of this demo, GNU Autoconf's AC_OBJEXT and
+# AC_EXEEXT macros only works for C compilers!
+# Libtool's setup macro calls AC_OBJEXT and AC_EXEEXT without setting
+# the test language to C.  We do it before any libtool setup macros are
+# called so that the proper values are cached beforehand.  We also do
+# it before any linker flags (LDFLAGS) are set so that fortran specific
+# ones don't break the tests.
+AC_LANG_PUSH([C])
+AC_OBJEXT
+AC_EXEEXT
+AC_LANG_POP
+
+## ----------------------- ##
+## Libtool initialisation. ##
+## ----------------------- ##
+LT_INIT
+AC_SUBST([LIBTOOL_DEPS])
+
+## -------- ##
+## Outputs. ##
+## -------- ##
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
--- /dev/null   2005-06-02 11:44:08.554003640 +0200
+++ tests/fcdemo/cprogram.c     2005-06-03 17:59:10.000000000 +0200
@@ -0,0 +1,47 @@
+/*
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
+USA. */
+
+#include "foo.h"
+#include <stdio.h>
+
+int
+main(int argc, char **argv)
+{
+  int arg,cres,fres;
+  
+  printf ("Welcome to GNU libtool mixed C/Fortran demo!\n");
+  
+  arg=2;
+  
+  cres=csub(arg);
+  
+  printf ("The C subroutine returned, claiming that 2*%d = %d\n",arg,cres);
+  
+  if(cres==2*arg)
+    printf ("The C subroutine is ok!\n");
+  
+  printf("\nCalling the C wrapper routine...\n");
+  fres=fwrapper(arg);
+  
+  printf ("The C wrapper to the fortran subroutine returned,\n"
+         "claiming that 2*%d = %d\n",arg,fres);
+  
+  if(fres==2*arg)
+    printf ("The Fortran subroutine is ok!\n");
+  
+  return 0;
+}
+
--- /dev/null   2005-06-02 11:44:08.554003640 +0200
+++ tests/fcdemo/foo.h  2005-06-03 18:10:23.000000000 +0200
@@ -0,0 +1,47 @@
+/* foo.h -- interface to fortran and C libraries
+   Copyright (C) 1998-1999, 2005 Free Software Foundation, Inc.
+   This file is part of GNU Libtool.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
+USA. */
+
+#ifndef _FOO_H_
+#define _FOO_H_ 1
+
+/* config.h is necessary for the fortran name mangling */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/* csub is an extremely useful subroutine that
+ * returns the argument multiplied by two :-)
+ */
+extern int csub(int);
+
+/* This routine performs the same action, but
+ * calls the fortran subroutine fsub to do the 
+ * real work.
+ */
+extern int fwrapper(int);
+
+/* fsub does the same thing as csub, i.e. res=arg*2.
+ * Use autoconf macro for fortran function names.
+ * Note that fortran passes args by reference, so
+ * you need to provide pointers to your ints.
+ */
+extern void FC_FUNC(fsub,FSUB)(int *arg, int *res);
+
+
+#endif
--- /dev/null   2005-06-02 11:44:08.554003640 +0200
+++ tests/fcdemo/fooc.c 2005-06-03 17:59:48.000000000 +0200
@@ -0,0 +1,17 @@
+#include "foo.h"
+#include <stdio.h>
+
+int csub(int arg)
+{
+  return (2*arg);
+}
+
+
+int fwrapper(int arg)
+{
+  int res;
+  printf("Calling the Fortran subroutine from the C wrapper...\n");
+  FC_FUNC(fsub,FSUB)(&arg,&res);
+  printf("Returned from the Fortran subroutine...\n");
+  return res;
+}
--- /dev/null   2005-06-02 11:44:08.554003640 +0200
+++ tests/fcdemo/foof.f90       2005-06-06 14:01:29.000000000 +0200
@@ -0,0 +1,11 @@
+! 
+! This program is free software; you can redistribute it and/or
+! modify it under the terms of the GNU General Public License
+! as published by the Free Software Foundation; either version 2
+! of the License, or (at your option) any later version.
+! 
+subroutine fsub(arg,res)
+  write(*,*) 'fsub called'
+  call fsubf(arg,res)
+  return
+end
--- /dev/null   2005-06-02 11:44:08.554003640 +0200
+++ tests/fcdemo/foof2.f90      2005-06-06 14:26:35.000000000 +0200
@@ -0,0 +1,13 @@
+! 
+! This program is free software; you can redistribute it and/or
+! modify it under the terms of the GNU General Public License
+! as published by the Free Software Foundation; either version 2
+! of the License, or (at your option) any later version.
+! 
+subroutine fsubf(arg,res)
+  implicit none
+  integer arg,res
+  write(*,*) 'fsubf called'
+  res=arg*2
+  return
+end
--- /dev/null   2005-06-02 11:44:08.554003640 +0200
+++ tests/fcdemo/foof3.f90      2005-06-06 14:26:40.000000000 +0200
@@ -0,0 +1,13 @@
+! 
+! This program is free software; you can redistribute it and/or
+! modify it under the terms of the GNU General Public License
+! as published by the Free Software Foundation; either version 2
+! of the License, or (at your option) any later version.
+! 
+subroutine fsub3(arg,res)
+  implicit none
+  integer arg,res
+  write(*,*) 'fsub3 called'
+  res=arg*4
+  return
+end
--- /dev/null   2005-06-02 11:44:08.554003640 +0200
+++ tests/fcdemo/fprogram.f90   2005-06-06 14:26:43.000000000 +0200
@@ -0,0 +1,32 @@
+! 
+! This program is free software; you can redistribute it and/or
+! modify it under the terms of the GNU General Public License
+! as published by the Free Software Foundation; either version 2
+! of the License, or (at your option) any later version.
+! 
+program fprogram
+  implicit none
+  integer arg,res
+
+  write(*,*) 'Welcome to GNU libtool Fortran demo!'
+  write(*,*) 'Real programmers write in FORTRAN.'
+  arg=2
+
+  call fsub(arg,res)
+
+  write(*,*) 'fsub returned, saying that 2 *',arg,' =',res
+
+  if (res.eq.4) then
+     write(*,*) 'fsub is ok!'
+  endif
+
+  call fsub3(arg,res)
+
+  write(*,*) 'fsub3 returned, saying that 4 *',arg,' =',res
+
+  if (res.eq.8) then
+     write(*,*) 'fsub3 is ok!'
+  endif
+
+  stop
+end




reply via email to

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