1# _GA_FC_LIBRARY_LDFLAGS
2# ======================
3#
4# GA HACK!!!
5# Until autoconf is fixed to support Sun Studio compilers using -Y, we replace
6# _AC_FC_LIBRARY_LDFLAGS.  The rest of the marco is directly copied from
7# autoconf-2.67/lib/autoconf/fortran.m4
8# ----------------------------------------------------------------------------
9#
10# Determine the linker flags (e.g. "-L" and "-l") for the Fortran
11# intrinsic and runtime libraries that are required to successfully
12# link a Fortran program or shared library.  The output variable
13# FLIBS/FCLIBS is set to these flags.
14#
15# This macro is intended to be used in those situations when it is
16# necessary to mix, e.g. C++ and Fortran, source code into a single
17# program or shared library.
18#
19# For example, if object files from a C++ and Fortran compiler must
20# be linked together, then the C++ compiler/linker must be used for
21# linking (since special C++-ish things need to happen at link time
22# like calling global constructors, instantiating templates, enabling
23# exception support, etc.).
24#
25# However, the Fortran intrinsic and runtime libraries must be
26# linked in as well, but the C++ compiler/linker doesn't know how to
27# add these Fortran libraries.  Hence, the macro
28# "AC_F77_LIBRARY_LDFLAGS" was created to determine these Fortran
29# libraries.
30#
31# This macro was packaged in its current form by Matthew D. Langston.
32# However, nearly all of this macro came from the "OCTAVE_FLIBS" macro
33# in "octave-2.0.13/aclocal.m4", and full credit should go to John
34# W. Eaton for writing this extremely useful macro.  Thank you John.
35AC_DEFUN([_GA_FC_LIBRARY_LDFLAGS],
36[_AC_FORTRAN_ASSERT()dnl
37_AC_PROG_FC_V
38AC_CACHE_CHECK([for _AC_LANG libraries of $[]_AC_FC[]], ac_cv_[]_AC_LANG_ABBREV[]_libs,
39[if test "x$[]_AC_LANG_PREFIX[]LIBS" != "x"; then
40  ac_cv_[]_AC_LANG_ABBREV[]_libs="$[]_AC_LANG_PREFIX[]LIBS" # Let the user override the test.
41else
42
43_AC_PROG_FC_V_OUTPUT
44
45ac_cv_[]_AC_LANG_ABBREV[]_libs=
46
47# Save positional arguments (if any)
48ac_save_positional="$[@]"
49
50set X $ac_[]_AC_LANG_ABBREV[]_v_output
51while test $[@%:@] != 1; do
52  shift
53  ac_arg=$[1]
54  case $ac_arg in
55	[[\\/]]*.a | ?:[[\\/]]*.a)
56	  _AC_LIST_MEMBER_IF($ac_arg, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
57	      ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg")
58	  ;;
59	-bI:*)
60	  _AC_LIST_MEMBER_IF($ac_arg, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
61	     [_AC_LINKER_OPTION([$ac_arg], ac_cv_[]_AC_LANG_ABBREV[]_libs)])
62	  ;;
63	  # Ignore these flags.
64	-lang* | -lcrt*.o | -lc | -lgcc* | -lSystem | -libmil | -little \
65	  |-LANG:=* | -LIST:* | -LNO:* | -link)
66	  ;;
67	-lkernel32)
68	  test x"$CYGWIN" != xyes && ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg"
69	  ;;
70	-[[LRuYz]])
71	  # These flags, when seen by themselves, take an argument.
72	  # We remove the space between option and argument and re-iterate
73	  # unless we find an empty arg or a new option (starting with -)
74	  case $[2] in
75	     "" | -*);;
76	     *)
77		ac_arg="$ac_arg$[2]"
78		shift; shift
79		set X $ac_arg "$[@]"
80		;;
81	  esac
82	  ;;
83	-YP,*)
84	  for ac_j in `AS_ECHO(["$ac_arg"]) | sed -e 's/-YP,/-L/;s/:/ -L/g'`; do
85	    _AC_LIST_MEMBER_IF($ac_j, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
86			       [ac_arg="$ac_arg $ac_j"
87			       ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_j"])
88	  done
89	  ;;
90dnl begin GA addition
91	-Y*)
92	  for ac_j in `AS_ECHO(["$ac_arg"]) | sed -e 's/-Y/-L/;s/"//g;s/:/ -L/g'`; do
93	    _AC_LIST_MEMBER_IF($ac_j, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
94			       [ac_arg="$ac_arg $ac_j"
95			       ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_j"])
96	  done
97	  ;;
98dnl end GA addition
99	-[[lLR]]*)
100	  _AC_LIST_MEMBER_IF($ac_arg, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
101			     ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg")
102	  ;;
103	-zallextract*| -zdefaultextract)
104	  ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg"
105	  ;;
106	  # Ignore everything else.
107  esac
108done
109# restore positional arguments
110set X $ac_save_positional; shift
111
112# We only consider "LD_RUN_PATH" on Solaris systems.  If this is seen,
113# then we insist that the "run path" must be an absolute path (i.e. it
114# must begin with a "/").
115case `(uname -sr) 2>/dev/null` in
116   "SunOS 5"*)
117      ac_ld_run_path=`AS_ECHO(["$ac_[]_AC_LANG_ABBREV[]_v_output"]) |
118			sed -n 's,^.*LD_RUN_PATH *= *\(/[[^ ]]*\).*$,-R\1,p'`
119      test "x$ac_ld_run_path" != x &&
120	_AC_LINKER_OPTION([$ac_ld_run_path], ac_cv_[]_AC_LANG_ABBREV[]_libs)
121      ;;
122esac
123fi # test "x$[]_AC_LANG_PREFIX[]LIBS" = "x"
124])
125[]_AC_LANG_PREFIX[]LIBS="$ac_cv_[]_AC_LANG_ABBREV[]_libs"
126AC_SUBST([]_AC_LANG_PREFIX[]LIBS)
127])# _GA_FC_LIBRARY_LDFLAGS
128
129
130# GA_F77_LIBRARY_LDFLAGS
131# ----------------------
132# Wrap AC_F77_LIBRARY_LDFLAGS in case user disables Fortran 77.
133# When mixing gcc and ifort, we sometimes need to add -lgcc_s to the FLIBS.
134# Lastly, Sun Studio compilers are not (yet) completely supported.
135AC_DEFUN([GA_F77_LIBRARY_LDFLAGS], [
136    GA_MPI_UNWRAP_PUSH()
137    AC_F77_LIBRARY_LDFLAGS
138    GA_MPI_UNWRAP_POP()
139    AC_CACHE_CHECK([whether FLIBS needs -lgcc_s], [ga_cv_flibs_gcc_s],
140        [happy=yes
141         ga_save_LIBS="$LIBS";  LIBS="$LIBS $FLIBS"
142         ga_save_FLIBS="$FLIBS"
143         AC_LANG_PUSH([C])
144         AC_LINK_IFELSE(
145            [AC_LANG_PROGRAM([],[])],
146            [ga_cv_flibs_gcc_s=no],
147            [LIBS="$LIBS -lgcc_s"
148             AC_LINK_IFELSE(
149                [AC_LANG_PROGRAM([],[])],
150                [FLIBS="$FLIBS -lgcc_s"
151                 ga_cv_flibs_gcc_s=yes],
152                [happy=no
153                 FLIBS="$ga_save_FLIBS"
154                 ga_cv_flibs_gcc_s=no])])
155         LIBS="$ga_save_LIBS"
156         AC_LANG_POP([C])])
157dnl hack to support Sun Studio -Y linker flag
158    AS_IF([test "x$happy" = xno],
159        [AS_UNSET([ac_cv_f77_libs])
160         AS_UNSET([FLIBS])
161         _GA_FC_LIBRARY_LDFLAGS
162         ga_save_LIBS="$LIBS";  LIBS="$LIBS $FLIBS"
163         AC_LANG_PUSH([C])
164         AC_LINK_IFELSE(
165            [AC_LANG_PROGRAM([],[])],
166            [happy=yes], [happy=no])
167         LIBS="$ga_save_LIBS"
168         AC_LANG_POP([C])])
169    AS_IF([test "x$happy" = xno],
170        [AC_MSG_WARN([FLIBS does not work])])
171])dnl
172