I have a patch suggestion that fixes some problems with the above macro,
one of which is IMO a bug (see 4. below). There was one problem
(5. below) which I couldn't actually "fix" in a general manner.
I have tested the macro on Linux (with g77, NAG f95, and Lahey f90),
AIX (whith xlf), Solaris (with native f77 and g77) and IRIX (with native f77).
After applying the patch, the macro works fine on these systems.
Before, I had a couple of errors especially on Solaris.
The problems fixed are:
1. -v flag: Not all compilers use -v as the flag to produce verbose linking
output. I have written a small macro (AC_F77_VERBOSE) that tries to
guess the flag.
2. -lm: For some reason that I don't quite understand, the original
AC_F77_LIBRARY_LDFLAGS swallows occurences of -lm in the
linker output. This causes link failure with fortran compilers that need
libm, and C/C++ compilers that don't link with it by default.
3. -YP,... : On my Solaris system, the flags reads -Y P,... rather than -YP,...
I have added code that checks for this case (Remark: on Solaris, it
seems not to be necessary to parse this rather complex expression -
linking succeeded without it in my case.
However, I wasn't sure it is never needed, so I tried to fix it).
4. ac_i: The code for parsing -YP,... (see above) uses a loop variable ac_i.
This is a bug, since the called macro AC_LIST_MEMBER_OF also
uses ac_i, leading to a meaningless 'if test"x$ac_i" = "x$ac_i" '
construct in the shell code. The patch changes ac_i to ac_j.
Moreover, I felt that true and false clauses in the AC_LIST_MEMBER_OF
call were incorrect (my assumption was that all directories in the
-YP,... construct should be included in the library search path
unless already there, and rewrote the macro with that in mind).
5. LD_RUN_PATH: The related code enters "/some/directory" to the
linker flags if LD_RUN_PATH is set, leading to a link error (Solaris).
Perhaps it should rather be "-L/Some/directory" ? No error occurs
if the compiler doesn't set LD_RUN_PATH.
I don't quite understand the reason why LD_RUN_PATH is
considered in the macro, thus I couldn't
actually "fix" it - I just commented it out and had no problems.
Regards
Martin
Martin Wilck, Inst. for Tropospheric Research, 04303 Leipzig, Germany
--- aclang.m4.p1 Fri Jun 30 20:42:34 2000
+++ aclang.m4.p3 Mon Jul 3 00:14:47 2000
@@ -1292,6 +1292,43 @@
# 4d. Fortan 77 compiler characteristics. #
# ---------------------------------------- #
+# AC_F77_VERBOSE
+# ---------------
+#
+# Determine the flag that causes the Fortran 77 compiler to print
+# information of library and object files (normally -v)
+# (needed for AC_F77_LIBRARY_FLAGS)
+AC_DEFUN([AC_F77_VERBOSE],
+[AC_REQUIRE([AC_PROG_F77])dnl
+AC_CACHE_CHECK([how to get verbose linking output from $F77],
+ ac_cv_f77_verbose,
+[AC_LANG_PUSH(Fortran 77)
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
+[ac_cv_f77_verbose=
+ac_save_FFLAGS=$FFLAGS
+# Try some options frequently used verbose output
+for ac_verb in -v -verbose --verbose -V; do
+ FFLAGS="$ac_save_FFLAGS $ac_verb"
+ ac_link_output=`eval $ac_link AC_FD_LOG>&1 2>&1 | grep -v 'Driving:'`
+ # look for -l* and *.a constructs in the output
+ for ac_arg in $ac_link_output; do
+ case $ac_arg in
+ /*.a | -[[lLRu]]*)
+ ac_cv_f77_verbose=$ac_verb
+ break 2
+ ;;
+ *)
+ :
+ ;;
+ esac
+ done
+done
+FFLAGS=$ac_save_FFLAGS
+if test "x$ac_cv_f77_verbose" = "x"; then
+ AC_MSG_WARN([Couldn't determine how to obtain linking information from $F77])
+fi ],
+[ac_cv_f77_verbose=""])
+])]) # AC_F77_VERBOSE
# AC_F77_LIBRARY_LDFLAGS
# ----------------------
@@ -1322,7 +1359,7 @@
# in "octave-2.0.13/aclocal.m4", and full credit should go to John
# W. Eaton for writing this extremely useful macro. Thank you John.
AC_DEFUN([AC_F77_LIBRARY_LDFLAGS],
-[AC_REQUIRE([AC_PROG_F77])dnl
+[AC_REQUIRE([AC_F77_VERBOSE])dnl
AC_CACHE_CHECK([for Fortran 77 libraries], ac_cv_flibs,
[if test "x$FLIBS" != "x"; then
ac_cv_flibs="$FLIBS" # Let the user override the test.
@@ -1339,7 +1376,7 @@
# we can then parse for the Fortran 77 linker flags. I don't know
# what to do if your compiler doesn't have -v.
ac_save_FFLAGS=$FFLAGS
-FFLAGS="$FFLAGS -v"
+FFLAGS="$FFLAGS $ac_cv_f77_verbose"
ac_link_output=`eval $ac_link AC_FD_LOG>&1 2>&1 | grep -v 'Driving:'`
FFLAGS=$ac_save_FFLAGS
@@ -1397,7 +1434,7 @@
ac_arg=, [AC_LINKER_OPTION([$ac_arg], ac_seen)])
;;
# Ignore these flags.
- -lang* | -lcrt0.o | -l[[cm]] | -lgcc | -LANG:=*)
+ -lang* | -lcrt0.o | -lc | -lgcc | -LANG:=*)
ac_arg=
;;
-lkernel32)
@@ -1408,18 +1445,18 @@
ac_seen="$ac_seen $ac_arg"
fi
;;
- -[[LRu]])
+ -[[LRuY]])
# These flags, when seen by themselves, take an argument.
ac_save_arg=$ac_arg
ac_arg=
;;
-YP,*)
temp_arg=
- for ac_i in `echo $ac_arg | sed -e 's%^P,%-L%' -e 's%:% -L%g'`; do
+ for ac_j in `echo $ac_arg | sed -e 's%-YP,%-L%' -e 's%:% -L%g'`; do
# Append to AC_SEEN if it's not already there.
- AC_LIST_MEMBER_OF($ac_i, $ac_seen,
- temp_arg="$temp_arg $ac_i",
- ac_seen="$ac_seen $ac_i")
+ AC_LIST_MEMBER_OF($ac_j, $ac_seen, ,
+ [temp_arg="$temp_arg $ac_j"
+ ac_seen="$ac_seen $ac_j"])
done
ac_arg=$temp_arg
;;
@@ -1437,6 +1474,20 @@
-[[LRu]])
ac_arg="$ac_previous_arg $ac_arg"
;;
+ -Y)
+ case $ac_arg in
+ P,*)
+ for ac_j in `echo $ac_arg | sed -e 's%^P,%-L%' -e 's%:% -L%g'`; do
+ # Append to AC_SEEN if it's not already there.
+ AC_LIST_MEMBER_OF($ac_j, $ac_seen, ,
+ [temp_arg="$temp_arg $ac_j"
+ ac_seen="$ac_seen $ac_j"])
+ done
+ ac_arg=$temp_arg
+ ac_save_arg=
+ ;;
+ esac
+ ;;
esac
# If "ac_arg" has survived up until this point, then put it in FLIBS.
@@ -1446,9 +1497,14 @@
# Assumption: We only see "LD_RUN_PATH" on Solaris systems. If this
# is seen, then we insist that the "run path" must be an absolute
# path (i.e. it must begin with a "/").
-ac_ld_run_path=`echo $ac_link_output |
- sed -n -e 's%^.*LD_RUN_PATH *= *\(/[[^ ]]*\).*$%\1%p'`
-test "x$ac_ld_run_path" != x && FLIBS="$ac_ld_run_path $FLIBS"
+#
+# MW the following code produces "/some/directory" if LD_RUN_PATH is set,
+# leading to a link error
+#
+# ac_ld_run_path=`echo $ac_link_output |
+# sed -n -e 's%^.*LD_RUN_PATH *= *\(/[[^ ]]*\).*$%\1%p'`
+# test "x$ac_ld_run_path" != x && FLIBS="$ac_ld_run_path $FLIBS"
+
ac_cv_flibs=$FLIBS
fi # test "x$FLIBS" = "x"
])