Skip to content

Commit f84cbfc

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

5 files changed

Lines changed: 73 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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,30 @@ 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+
fi
56+
3957
AC_ARG_ENABLE(coverage,
4058
[ --enable-coverage Enable coverage testing],
4159
[CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage"])
@@ -105,6 +123,10 @@ then
105123
FCFLAGS="$PROFILE_FCFLAGS $FCFLAGS"
106124
fi
107125

126+
dnl
127+
dnl Try to avoid having libtool search for a fortran compiler
128+
dnl
129+
F77=$FC
108130
AC_ENABLE_SHARED
109131
AC_ENABLE_STATIC
110132
LT_INIT
@@ -368,6 +390,18 @@ esac
368390
AM_CONDITIONAL([LINUX], [test "x$linux" = "xyes"])
369391
AM_CONDITIONAL([WINNT], [test "x$winnt" = "xyes"])
370392
AM_CONDITIONAL([SUN], [test "x$sun" = "xyes"])
393+
AM_CONDITIONAL([ENABLE_FORTRAN], [test "x$enable_fortran" = "xyes"])
394+
395+
dnl
396+
dnl Without this, the linker line is incorrect on platforms without a fortran
397+
dnl compiler even if we are not using fortran sources
398+
dnl
399+
if test "x$enable_fortran" != "xyes"; then
400+
FCLINK='$(LINK)'
401+
else
402+
FCLINK='$(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(FCLD) $(AM_FCFLAGS) $(FCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@'
403+
fi
404+
AC_SUBST(FCLINK)
371405

372406
winnt="no"
373407
case "${host_os}" in
@@ -396,9 +430,13 @@ AC_MSG_RESULT([])
396430
AC_MSG_RESULT([ MATIO Configuration Summary ])
397431
AC_MSG_RESULT([==============================================================])
398432
AC_MSG_RESULT([ C Compiler: $CC])
433+
AC_MSG_RESULT([ Fortran Compiler: $FC])
399434
AC_MSG_RESULT([ CFLAGS: $CFLAGS])
435+
AC_MSG_RESULT([ FCFLAGS: $FCFLAGS])
436+
AC_MSG_RESULT([ FCLDFLAGS: $FCLDFLAGS])
400437
AC_MSG_RESULT([ Shared Libraries: $enable_shared])
401438
AC_MSG_RESULT([ Static Libraries: $enable_static])
439+
AC_MSG_RESULT([ Fortran Interface: $enable_fortran])
402440
AC_MSG_RESULT([ default MAT version: $file_ver])
403441
AC_MSG_RESULT([])
404442
AC_MSG_RESULT([Features --------------------------------------------])

src/Makefile.am

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,24 @@ 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_SOURCES += fortran/matio_internal.c fortran/matio.f90
45+
nodist_include_HEADERS += $(top_builddir)/src/matio.mod
46+
noinst_HEADERS += fortran/create.f90 fortran/read_data.f90 \
47+
fortran/write_data.f90 fortran/write.f90
48+
else
49+
libmatio_la_LDFLAGS = -no-undefined -export-symbols @srcdir@/matio.sym $(AM_LDFLAGS)
50+
endif
51+
4252
dosubst = sed -e 's,[@]PACKAGE[@],$(PACKAGE),g' \
4353
-e 's,[@]VERSION[@],$(VERSION),g' \
4454
-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)