Skip to content

Commit e0275ca

Browse files
committed
Fix Fortran build
As reported by #51
1 parent 4989a8d commit e0275ca

6 files changed

Lines changed: 93 additions & 8 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: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ AC_INIT([MATIO],[1.5.30],[t-beu@users.sourceforge.net],[],[https://sourceforge.n
1212
AC_CONFIG_SRCDIR([src/matio.h])
1313
AC_CONFIG_AUX_DIR([config])
1414
AC_CONFIG_MACRO_DIR([config])
15-
AM_INIT_AUTOMAKE([foreign 1.8 no-dependencies])
15+
AM_INIT_AUTOMAKE([foreign 1.8 no-dependencies subdir-objects])
1616
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES])
1717
AM_MAINTAINER_MODE
1818
AC_PREREQ([2.60])
@@ -26,16 +26,45 @@ PACKAGE_RELEASE_DATE="6 January 2026"
2626
AC_DEFINE_UNQUOTED([MATIO_VERSION_STR],"1.5.30",[Matio version number])
2727
AC_SUBST(PACKAGE_RELEASE_DATE)
2828

29-
AC_ARG_VAR([FCLDFLAGS],[Fortran compiler-specific flags at link time])
3029
AC_ARG_VAR([LT_CFLAGS],[C compiler flags passed to libtool in compile mode])
3130
AC_ARG_VAR([LT_LDFLAGS],[Flags passed to libtool in link mode])
3231

32+
dnl
33+
# Enable fortran interface
34+
AC_ARG_ENABLE(fortran,
35+
[ --enable-fortran enable fortran interface to mat library],
36+
[if test "$enableval" = "no" ; then
37+
enable_fortran=no
38+
else
39+
enable_fortran=yes
40+
fi],
41+
enable_fortran=no)
42+
3343
dnl
3444
dnl Build programs, C compiler, F77 compiler, make, install, etc.
3545
dnl
3646
AC_PROG_CC([pgcc icc gcc cc])
3747
AC_USE_SYSTEM_EXTENSIONS
3848

49+
if test "$enable_fortran" = "yes"
50+
then
51+
AC_PROG_FC([pgf95 pgf90 ifort gfortran g95])
52+
AC_FC_WRAPPERS
53+
AC_FC_LIBRARY_LDFLAGS
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 needs -fallow-argument-mismatch])
57+
case "$FC" in
58+
*gfortran*)
59+
FCFLAGS="$FCFLAGS -fallow-argument-mismatch"
60+
AC_MSG_RESULT([yes])
61+
;;
62+
*)
63+
AC_MSG_RESULT([no])
64+
;;
65+
esac
66+
fi
67+
3968
AC_ARG_ENABLE(coverage,
4069
[ --enable-coverage Enable coverage testing],
4170
[CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage"])
@@ -105,6 +134,10 @@ then
105134
FCFLAGS="$PROFILE_FCFLAGS $FCFLAGS"
106135
fi
107136

137+
dnl
138+
dnl Try to avoid having libtool search for a fortran compiler
139+
dnl
140+
F77=$FC
108141
AC_ENABLE_SHARED
109142
AC_ENABLE_STATIC
110143
LT_INIT
@@ -368,6 +401,18 @@ esac
368401
AM_CONDITIONAL([LINUX], [test "x$linux" = "xyes"])
369402
AM_CONDITIONAL([WINNT], [test "x$winnt" = "xyes"])
370403
AM_CONDITIONAL([SUN], [test "x$sun" = "xyes"])
404+
AM_CONDITIONAL([ENABLE_FORTRAN], [test "x$enable_fortran" = "xyes"])
405+
406+
dnl
407+
dnl Without this, the linker line is incorrect on platforms without a fortran
408+
dnl compiler even if we are not using fortran sources
409+
dnl
410+
if test "x$enable_fortran" != "xyes"; then
411+
FCLINK='$(LINK)'
412+
else
413+
FCLINK='$(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(FCLD) $(AM_FCFLAGS) $(FCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@'
414+
fi
415+
AC_SUBST(FCLINK)
371416

372417
winnt="no"
373418
case "${host_os}" in
@@ -396,9 +441,13 @@ AC_MSG_RESULT([])
396441
AC_MSG_RESULT([ MATIO Configuration Summary ])
397442
AC_MSG_RESULT([==============================================================])
398443
AC_MSG_RESULT([ C Compiler: $CC])
444+
AC_MSG_RESULT([ Fortran Compiler: $FC])
399445
AC_MSG_RESULT([ CFLAGS: $CFLAGS])
446+
AC_MSG_RESULT([ FCFLAGS: $FCFLAGS])
447+
AC_MSG_RESULT([ FCLIBS: $FCLIBS])
400448
AC_MSG_RESULT([ Shared Libraries: $enable_shared])
401449
AC_MSG_RESULT([ Static Libraries: $enable_static])
450+
AC_MSG_RESULT([ Fortran Interface: $enable_fortran])
402451
AC_MSG_RESULT([ default MAT version: $file_ver])
403452
AC_MSG_RESULT([])
404453
AC_MSG_RESULT([Features --------------------------------------------])

src/Makefile.am

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,30 @@ 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+
noinst_LTLIBRARIES = libfmatio.la
44+
libfmatio_la_SOURCES = fortran/matio_internal.c fortran/matio.f90
45+
libfmatio_la_CFLAGS = $(AM_CFLAGS)
46+
libfmatio_la_LDFLAGS =
47+
libmatio_la_LIBADD += libfmatio.la $(FCLIBS)
48+
libmatio_la_LDFLAGS = -no-undefined $(AM_LDFLAGS)
49+
nodist_include_HEADERS += matio.mod
50+
noinst_HEADERS += fortran/create.f90 fortran/read_data.f90 \
51+
fortran/write_data.f90 fortran/write.f90
52+
else
53+
libmatio_la_LDFLAGS = -no-undefined -export-symbols @srcdir@/matio.sym $(AM_LDFLAGS)
54+
endif
55+
56+
matio.mod: libfmatio.la
57+
4258
dosubst = sed -e 's,[@]PACKAGE[@],$(PACKAGE),g' \
4359
-e 's,[@]VERSION[@],$(VERSION),g' \
4460
-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)

src/fortran/matio_t.inc.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
! Copyright (c) 2008-2014, Christopher C. Hulbert
44
! All rights reserved.
55
!
6-
| SPDX-License-Identifier: BSD-2-Clause
6+
! SPDX-License-Identifier: BSD-2-Clause
77
!
88

99
INTEGER,PARAMETER :: mat_ptr = @SIZEOF_VOID_P@

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)