dnl CF_LDFLAGS_STATIC version: 10 updated: 2011/09/24 12:51:48
dnl -----------------
dnl Check for compiler/linker flags used to temporarily force usage of static
dnl libraries.  This depends on the compiler and platform.  Use this to help
dnl ensure that the linker picks up a given library based on its position in
dnl the list of linker options and libraries.
AC_DEFUN([CF_LDFLAGS_STATIC],[

if test "$GCC" = yes ; then
	case $cf_cv_system_name in #(
	OS/2*|os2*|aix[[4]]*|solaris2.1[[0-9]]|darwin*) 	#( vi
		LDFLAGS_STATIC=
		LDFLAGS_SHARED=
		;;
    *) 	#( normally, except when broken
        LDFLAGS_STATIC=-static
        LDFLAGS_SHARED=-dynamic
        ;;
    esac
else
	case $cf_cv_system_name in #(
	aix[[4-7]]*) 	#( from ld manpage
		LDFLAGS_STATIC=-bstatic
		LDFLAGS_SHARED=-bdynamic
		;;
	hpux*)		#( from ld manpage for hpux10.20, hpux11.11
		# We could also use just "archive" and "shared".
		LDFLAGS_STATIC=-Wl,-a,archive_shared
		LDFLAGS_SHARED=-Wl,-a,shared_archive
		;;
	irix*)		#( from ld manpage IRIX64
		LDFLAGS_STATIC=-Bstatic
		LDFLAGS_SHARED=-Bdynamic
		;;
	osf[[45]]*)	#( from ld manpage osf4.0d, osf5.1
		# alternative "-oldstyle_liblookup" (not in cc manpage)
		LDFLAGS_STATIC=-noso
		LDFLAGS_SHARED=-so_archive
		;;
	solaris2*)
		LDFLAGS_STATIC=-Bstatic
		LDFLAGS_SHARED=-Bdynamic
		;;
	esac
fi

if test -n "$LDFLAGS_STATIC" && test -n "$LDFLAGS_SHARED"
then
	AC_MSG_CHECKING(if linker supports switching between static/dynamic)

	rm -f libconftest.a
	cat >conftest.$ac_ext <<EOF
#line __oline__ "configure"
#include <stdio.h>
int cf_ldflags_static(FILE *fp) { return fflush(fp); }
EOF
	if AC_TRY_EVAL(ac_compile) ; then
		( $AR $ARFLAGS libconftest.a conftest.o ) 2>&AC_FD_CC 1>/dev/null
		( eval $RANLIB libconftest.a ) 2>&AC_FD_CC >/dev/null
	fi
	rm -f conftest.*

	cf_save_LIBS="$LIBS"

	LIBS="$LDFLAGS_STATIC -L`pwd` -lconftest $LDFLAGS_DYNAMIC $LIBS"
	AC_TRY_LINK([
#line __oline__ "configure"
#include <stdio.h>
int cf_ldflags_static(FILE *fp);
],[
	return cf_ldflags_static(stdin);
],[
	# some linkers simply ignore the -dynamic
	case x`file conftest$ac_exeext 2>/dev/null` in #(vi
	*static*) # (vi
		cf_ldflags_static=no
		;;
	*)
		cf_ldflags_static=yes
		;;
	esac
],[cf_ldflags_static=no])

	rm -f libconftest.*
	LIBS="$cf_save_LIBS"

	AC_MSG_RESULT($cf_ldflags_static)

	if test $cf_ldflags_static != yes
	then
		LDFLAGS_STATIC=
		LDFLAGS_SHARED=
	fi
else
	LDFLAGS_STATIC=
	LDFLAGS_SHARED=
fi

AC_SUBST(LDFLAGS_STATIC)
AC_SUBST(LDFLAGS_SHARED)
])
