1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
|
# f77demo.at -- Fortran 77 language support. -*- Autotest -*-
#
# Copyright (C) 2003, 2005-2006, 2011-2019, 2021-2024 Free Software
# Foundation, Inc.
# Written by Eric Lindahl, 2002
# Written by Gary V. Vaughan, 2003
#
# This file is part of GNU Libtool.
#
# GNU Libtool 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.
#
# GNU Libtool 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 GNU Libtool. If not, see <https://www.gnu.org/licenses/>.
####
AT_BANNER([F77 language support.])
# _LT_SETUP
# ---------
m4_define([_LT_SETUP],
[LT_AT_TAG([F77])
AT_KEYWORDS([libtool])
AT_DATA([configure.ac],
[[AC_INIT([f77demo], ]AT_PACKAGE_VERSION[, ]AT_PACKAGE_BUGREPORT[)
AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE
AC_PROG_CC
AC_PROG_F77
dnl When configuring for 'make dist' purposes, skip checks that may yield fatal
dnl errors when there is no working F77 compiler.
if test -z "$with_dist"; then
dnl Check the flags needed to link f77 programs with ld (i.e. cc)
AC_F77_LIBRARY_LDFLAGS
dnl Check for underscoring of external names
AC_F77_WRAPPERS
fi
LT_INIT
AC_SUBST([LIBTOOL_DEPS])
AC_CONFIG_FILES([Makefile])
AC_CONFIG_HEADERS([config.h:config.in.h])
AC_OUTPUT
]])
AT_DATA([Makefile.am],
[[AUTOMAKE_OPTIONS = no-dependencies foreign
ACLOCAL_AMFLAGS = -I m4
lib_LTLIBRARIES = libfoo.la libmix.la libfoo2.la libfoo3.la
libfoo_la_SOURCES = foof.f
libfoo_la_LIBADD = libfoo2.la
libfoo_la_LDFLAGS = -no-undefined
libfoo2_la_SOURCES = foof2.f
libfoo2_la_LDFLAGS = -no-undefined
libfoo3_la_SOURCES = foof3.f
libfoo3_la_LDFLAGS = -no-undefined
libmix_la_SOURCES = foof.f foof2.f fooc.c
libmix_la_LDFLAGS = -no-undefined
noinst_HEADERS = foo.h
bin_PROGRAMS = fprogram cprogram
fprogram_SOURCES = fprogram.f
fprogram_LDADD = libfoo.la libfoo3.la
cprogram_SOURCES = cprogram.c
cprogram_LDADD = libmix.la $(FLIBS)
libtool: $(LIBTOOL_DEPS)
$(SHELL) ./config.status --recheck
]])
AT_DATA([fprogram.f],
[[ program fprogram
implicit none
integer*4 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
]])
AT_DATA([cprogram.c],
[[#include <config.h>
#include <stdio.h>
#include "foo.h"
int
main ()
{
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 77 subroutine is ok!\n");
return 0;
}
]])
AT_DATA([foo.h],
[[#ifndef _FOO_H_
#define _FOO_H_ 1
/* config.h is necessary for the fortran name mangling */
#include <config.h>
/* 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
#ifdef __cplusplus
"C"
#endif
void F77_FUNC(fsub,FSUB)(int *arg, int *res);
#endif
]])
AT_DATA([fooc.c],
[[#include <config.h>
#include <stdio.h>
#include "foo.h"
int csub(int arg)
{
return (2*arg);
}
int fwrapper(int arg)
{
int res;
printf("Calling the Fortran 77 subroutine from the C wrapper...\n");
F77_FUNC(fsub,FSUB)(&arg,&res);
printf("Returned from the Fortran 77 subroutine...\n");
return res;
}
]])
AT_DATA([foof.f],
[[ subroutine fsub(arg,res)
write(*,*) 'fsub called'
call fsubf(arg,res)
return
end
]])
AT_DATA([foof2.f],
[[ subroutine fsubf(arg,res)
implicit none
integer*4 arg,res
write(*,*) 'fsubf called'
res=arg*2
return
end
]])
AT_DATA([foof3.f],
[[ subroutine fsub3(arg,res)
implicit none
integer*4 arg,res
write(*,*) 'fsub3 called'
res=arg*4
return
end
]])
LT_AT_AUTOHEADER
]) # _LT_SETUP
# _LT_CHECK_EXECUTE
# -----------------
# Run the default make rule, and check that the built binaries work.
m4_define([_LT_CHECK_EXECUTE],
[LT_AT_MAKE
# Due to differences in line-endings between C stdout and Fortran
# stdout, as well as unpredictable output ordering between platforms
# and runtimes, we can't reliably check the output here... although
# it should be some variation of the following:
LT_AT_HOST_DATA([expout],
[[ Welcome to GNU libtool Fortran demo!
Real programmers write in FORTRAN.
fsub called
fsubf called
fsub returned, saying that 2 * 2 = 4
fsub is ok!
fsub3 called
fsub3 returned, saying that 4 * 2 = 8
fsub3 is ok!
]])
LT_AT_EXEC_CHECK([./fprogram], 0, [stdout])
# A weaker output content check that is agnostic to the issues above.
AT_CHECK([$GREP 'Welcome to GNU libtool Fortran demo!' stdout],
[0], [ignore])
# Similarly, we can't reliably compare actual output with the following.
LT_AT_HOST_DATA([expout],
[[Welcome to GNU libtool mixed C/Fortran demo!
The C subroutine returned, claiming that 2*2 = 4
The C subroutine is ok!
Calling the C wrapper routine...
Calling the Fortran 77 subroutine from the C wrapper...
fsub called
fsubf called
Returned from the Fortran 77 subroutine...
The C wrapper to the fortran subroutine returned,
claiming that 2*2 = 4
The Fortran 77 subroutine is ok!
]])
LT_AT_EXEC_CHECK([./cprogram], 0, [stdout])
# A weaker output content check that is agnostic to the issues above.
AT_CHECK([$GREP 'Welcome to GNU libtool mixed C/Fortran demo!' stdout],
[0], [ignore])
])
## --------------- ##
## F77demo static. ##
## --------------- ##
AT_SETUP([static library])
# Using clang with fsanitize results in an incompatible ASan runtime.
# It results in the warning message "linked against incompatible ASan
# runtimes". This only occurs with the mixed Fortran/C demo.
if $LIBTOOL --config | $EGREP '^CC="clang';
then
AT_CHECK([echo "$LDFLAGS" | $EGREP 'fsanitize=' && (exit 77)], 1)
fi
# Executing the static fprogram might be interactive on MSYS.
AT_KEYWORDS([interactive])
_LT_SETUP
LT_AT_CHECK_CONFIG([--disable-shared],
[^build_old_libs=yes], [^build_libtool_libs=no])
_LT_CHECK_EXECUTE
AT_CLEANUP
## --------------- ##
## F77demo shared. ##
## --------------- ##
AT_SETUP([shared library])
# Using clang with fsanitize results in an incompatible ASan runtime.
# It results in the warning message "linked against incompatible ASan
# runtimes". This only occurs with the mixed Fortran/C demo.
if $LIBTOOL --config | $EGREP '^CC="clang';
then
AT_CHECK([echo "$LDFLAGS" | $EGREP 'fsanitize=' && (exit 77)], 1)
fi
_LT_SETUP
LT_AT_CHECK_CONFIG([--disable-static],
[^build_old_libs=no], [^build_libtool_libs=yes])
_LT_CHECK_EXECUTE
AT_CLEANUP
## ------------- ##
## F77demo conf. ##
## ------------- ##
AT_SETUP([shared and static together])
# Using clang with fsanitize results in an incompatible ASan runtime.
# It results in the warning message "linked against incompatible ASan
# runtimes". This only occurs with the mixed Fortran/C demo.
if $LIBTOOL --config | $EGREP '^CC="clang';
then
AT_CHECK([echo "$LDFLAGS" | $EGREP 'fsanitize=' && (exit 77)], 1)
fi
_LT_SETUP
LT_AT_CHECK_CONFIG([],
[^build_old_libs=yes], [^build_libtool_libs=yes])
_LT_CHECK_EXECUTE
AT_CLEANUP
|