Skip to content

Commit e14e3c1

Browse files
committed
Fix Fortran build
As reported by #51
1 parent 30d4568 commit e14e3c1

5 files changed

Lines changed: 83 additions & 5 deletions

File tree

.github/workflows/autotools.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ jobs:
1919
matrix:
2020
toolchain:
2121
- linux-gcc
22+
- linux-gcc-fortran
2223
- macos-clang
2324
include:
2425
- toolchain: linux-gcc
2526
os: ubuntu-latest
2627
compiler: gcc
28+
- toolchain: linux-gcc-fortran
29+
os: ubuntu-latest
30+
compiler: gcc
31+
fortran: true
2732
- toolchain: macos-clang
2833
os: macos-latest
2934
compiler: clang
@@ -40,6 +45,9 @@ jobs:
4045
else
4146
pip install --user cpp-coveralls
4247
fi
48+
if [ "${{ matrix.fortran }}" == "true" ]; then
49+
sudo apt-get install -y gfortran
50+
fi
4351
- name: Install hdf5
4452
timeout-minutes: 5
4553
run: |
@@ -52,7 +60,11 @@ jobs:
5260
- name: Configure
5361
run: |
5462
./autogen.sh
55-
./configure --quiet --enable-shared --enable-coverage --enable-debug --enable-mat73 --enable-extended-sparse --with-pic --with-hdf5=${GITHUB_WORKSPACE}/hdf5
63+
FORTRAN_FLAG=""
64+
if [ "${{ matrix.fortran }}" == "true" ]; then
65+
FORTRAN_FLAG="--enable-fortran"
66+
fi
67+
./configure --quiet --enable-shared --enable-coverage --enable-debug --enable-mat73 --enable-extended-sparse --with-pic --with-hdf5=${GITHUB_WORKSPACE}/hdf5 $FORTRAN_FLAG
5668
- name: Build with ${{ matrix.compiler }}
5769
run: make -j8
5870
- name: Test

configure.ac

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,39 @@ AC_ARG_VAR([FCLDFLAGS],[Fortran compiler-specific flags at link time])
3030
AC_ARG_VAR([LT_CFLAGS],[C compiler flags passed to libtool in compile mode])
3131
AC_ARG_VAR([LT_LDFLAGS],[Flags passed to libtool in link mode])
3232

33+
dnl
34+
# Enable fortran interface
35+
AC_ARG_ENABLE(fortran,
36+
[ --enable-fortran enable fortran interface to mat library],
37+
[if test "$enableval" = "no" ; then
38+
enable_fortran=no
39+
else
40+
enable_fortran=yes
41+
fi],
42+
enable_fortran=no)
43+
3344
dnl
3445
dnl Build programs, C compiler, F77 compiler, make, install, etc.
3546
dnl
3647
AC_PROG_CC([pgcc icc gcc cc])
3748
AC_USE_SYSTEM_EXTENSIONS
3849

50+
if test "$enable_fortran" = "yes"
51+
then
52+
AC_PROG_FC([pgf95 pgf90 ifort gfortran g95])
53+
AC_FC_WRAPPERS
54+
AC_CONFIG_FILES([src/fortran/matio_t.inc])
55+
dnl gfortran >= 10 requires -fallow-argument-mismatch for legacy interfaces
56+
AC_MSG_CHECKING([whether $FC supports -fallow-argument-mismatch])
57+
saved_FCFLAGS="$FCFLAGS"
58+
FCFLAGS="$FCFLAGS -fallow-argument-mismatch"
59+
AC_LANG_PUSH([Fortran])
60+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
61+
[AC_MSG_RESULT([yes])],
62+
[AC_MSG_RESULT([no]); FCFLAGS="$saved_FCFLAGS"])
63+
AC_LANG_POP([Fortran])
64+
fi
65+
3966
AC_ARG_ENABLE(coverage,
4067
[ --enable-coverage Enable coverage testing],
4168
[CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage"])
@@ -105,6 +132,10 @@ then
105132
FCFLAGS="$PROFILE_FCFLAGS $FCFLAGS"
106133
fi
107134

135+
dnl
136+
dnl Try to avoid having libtool search for a fortran compiler
137+
dnl
138+
F77=$FC
108139
AC_ENABLE_SHARED
109140
AC_ENABLE_STATIC
110141
LT_INIT
@@ -368,6 +399,18 @@ esac
368399
AM_CONDITIONAL([LINUX], [test "x$linux" = "xyes"])
369400
AM_CONDITIONAL([WINNT], [test "x$winnt" = "xyes"])
370401
AM_CONDITIONAL([SUN], [test "x$sun" = "xyes"])
402+
AM_CONDITIONAL([ENABLE_FORTRAN], [test "x$enable_fortran" = "xyes"])
403+
404+
dnl
405+
dnl Without this, the linker line is incorrect on platforms without a fortran
406+
dnl compiler even if we are not using fortran sources
407+
dnl
408+
if test "x$enable_fortran" != "xyes"; then
409+
FCLINK='$(LINK)'
410+
else
411+
FCLINK='$(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(FCLD) $(AM_FCFLAGS) $(FCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@'
412+
fi
413+
AC_SUBST(FCLINK)
371414

372415
winnt="no"
373416
case "${host_os}" in
@@ -396,9 +439,13 @@ AC_MSG_RESULT([])
396439
AC_MSG_RESULT([ MATIO Configuration Summary ])
397440
AC_MSG_RESULT([==============================================================])
398441
AC_MSG_RESULT([ C Compiler: $CC])
442+
AC_MSG_RESULT([ Fortran Compiler: $FC])
399443
AC_MSG_RESULT([ CFLAGS: $CFLAGS])
444+
AC_MSG_RESULT([ FCFLAGS: $FCFLAGS])
445+
AC_MSG_RESULT([ FCLDFLAGS: $FCLDFLAGS])
400446
AC_MSG_RESULT([ Shared Libraries: $enable_shared])
401447
AC_MSG_RESULT([ Static Libraries: $enable_static])
448+
AC_MSG_RESULT([ Fortran Interface: $enable_fortran])
402449
AC_MSG_RESULT([ default MAT version: $file_ver])
403450
AC_MSG_RESULT([])
404451
AC_MSG_RESULT([Features --------------------------------------------])

src/Makefile.am

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,25 @@ libmatio_la_SOURCES = endian.c io.c $(ZLIB_SRC) read_data.c \
3131
mat5.c mat4.c mat.c matvar_cell.c matvar_struct.c \
3232
mcos.c
3333
libmatio_la_LIBADD = $(HDF5_LIBS) $(ZLIB_LIBS) $(SNPRINTF_LIBS)
34-
libmatio_la_LDFLAGS = -no-undefined -export-symbols @srcdir@/matio.sym $(AM_LDFLAGS)
3534

3635
if MAT73
3736
libmatio_la_SOURCES += mat73.c
3837
endif
3938

4039
EXTRA_DIST = matio.sym
4140

41+
if ENABLE_FORTRAN
42+
AM_FCFLAGS = -I. -I$(top_builddir)/src/fortran
43+
AM_LDFLAGS += $(FCLDFLAGS)
44+
libmatio_la_LDFLAGS = $(AM_LDFLAGS)
45+
libmatio_la_SOURCES += fortran/matio_internal.c fortran/matio.f90
46+
nodist_include_HEADERS += $(top_builddir)/src/matio.mod
47+
noinst_HEADERS += fortran/create.f90 fortran/read_data.f90 \
48+
fortran/write_data.f90 fortran/write.f90
49+
else
50+
libmatio_la_LDFLAGS = -no-undefined -export-symbols @srcdir@/matio.sym $(AM_LDFLAGS)
51+
endif
52+
4253
dosubst = sed -e 's,[@]PACKAGE[@],$(PACKAGE),g' \
4354
-e 's,[@]VERSION[@],$(VERSION),g' \
4455
-e 's,\/,\\,g'

src/fortran/matio_internal.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@
66
* SPDX-License-Identifier: BSD-2-Clause
77
*/
88

9+
#include "matio_private.h"
910
#include <stdlib.h>
10-
#include <stdio.h>
1111
#include <string.h>
1212
#if defined(HAVE_STRINGS_H)
1313
#include <strings.h>
1414
#endif
15-
#include "matio.h"
16-
#include "matio_private.h"
1715

1816
#define fmat_loginit_c \
1917
FC_FUNC_(fmat_loginit_c,FMAT_LOGINIT_C)

test/Makefile.am

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,16 @@ TEST_LFLAGS = -L$(top_builddir)/src
783783

784784
noinst_PROGRAMS = test_mat test_snprintf
785785

786+
if ENABLE_FORTRAN
787+
noinst_PROGRAMS += test_matf
788+
789+
test_matf_SOURCES = test_matf.f90
790+
test_matf_CFLAGS = -I$(top_builddir)/src -I$(top_builddir)/src/fortran
791+
test_matf_FCFLAGS = -I$(top_builddir)/src -I$(top_builddir)/src/fortran
792+
test_matf_LDFLAGS = -L$(top_builddir)/src -L$(top_builddir)/src/fortran
793+
test_matf_LDADD = $(TEST_LIBS)
794+
endif
795+
786796
test_mat_SOURCES = test_mat.c
787797
test_mat_LDADD = $(TEST_LIBS)
788798
test_mat_LDFLAGS = $(TEST_LFLAGS)

0 commit comments

Comments
 (0)