## $Id$
#
# SYNOPSIS
#
# YAT_LT_LINK_IFELSE(program, [action-if-true], [action-if-not-true])
#
# DESCRIPTION
#
# COPYLEFT
#
# Copyright (C) 2010, 2011, 2013 Peter Johansson
#
# This file is part of the yat library, http://dev.thep.lu.se/yat
#
# The yat library 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 3 of the
# License, or (at your option) any later version.
#
# The yat library 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 yat. If not, see .
#
# Based on _KPSE_USE_LIBTOOL by
# Peter Breitenlohner shared here
# http://www.mail-archive.com/autoconf@gnu.org/msg19948.html
#
# serial 5 (yat 0.11)
#
# YAT_LT_LINK_IFELSE(PROG, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
# -------------------------------------------------------------
# Same as AC_LINK_IFELSE but linking via libtool
AC_DEFUN([YAT_LT_LINK_IFELSE],
[
YAT_USE_LIBTOOL_PUSH
AC_LINK_IFELSE($@)
YAT_USE_LIBTOOL_POP
]) # YAT_LT_LINK_IFELSE
# YAT_USE_LIBTOOL_PUSH
# --------------------
# Assign `$ac_link' to use libtool. Variable is saved so they can be
# restored with YAT_USE_LIBTOOL_POP
AC_DEFUN([YAT_USE_LIBTOOL_PUSH],
[
m4_defn([LT_INIT])
m4_ifdef([_YAT_USE_LIBTOOL], [],
[LT_OUTPUT
yat_use_libtool_ac_link=$ac_link;
ac_link='./libtool --mode=link --tag=_YAT_USE_LIBTOOL_TAG '"$ac_link";
]) dnl
m4_pushdef([_YAT_USE_LIBTOOL], [yes])
]) # YAT_USE_LIBTOOL_PUSH
# YAT_USE_LIBTOOL_POP
# --------------------
# Restore values of `$ac_link' and `$ac_compile' to what they were
# prior YAT_USE_LIBTOOL_PUSH
AC_DEFUN([YAT_USE_LIBTOOL_POP],
[
m4_popdef([_YAT_USE_LIBTOOL])
m4_ifndef([_YAT_USE_LIBTOOL], dnl
[ac_link=$yat_use_libtool_ac_link;
])
]) # YAT_USE_LIBTOOL_POP
# YAT_LT_LINK_LA_IFELSE(input, [action-if-true], [action-if-false])
# -----------------------------------------------------------------
# Try to create a libtool archive in two steps. First, run the
# compiler on input similar to AC_COMPILE_IFELSE, but input is not
# expected to have a main() function. If successful, try to create a
# libconftest.la with created object as input and linking with
# $LIBS. If both steps are successful, execute shell code
# action-if-true, otherwise execute action-if-false.
#
# Note, that this macro can be used to check if libraries in $LIBS are
# suitable to be linked into a libtool archive, but not that if input
# is not using lib the test will test will succeed regardless whether
# the lib is suitable or not.
AC_DEFUN([YAT_LT_LINK_LA_IFELSE],
[
YAT_USE_LIBTOOL_PUSH
AC_LANG_CONFTEST([AC_LANG_SOURCE([$1])])
m4_pushdef([ACTION_IF_FALSE],
[_YAT_MSG_LOG_CONFTEST
$3])
YAT_RUN_LOG([./libtool --mode=compile --tag=_YAT_USE_LIBTOOL_TAG \
$CXX $CPPFLAGS $CXXFLAGS -c -o conftest.lo conftest.$ac_ext],
[YAT_RUN_LOG([./libtool --mode=link --tag=_YAT_USE_LIBTOOL_TAG \
$CXX $CXXFLAGS $LDFLAGS -o libconftest.la \
-rpath `pwd` conftest.lo $LIBS],
[$2], [ACTION_IF_FALSE])],
[ACTION_IF_FALSE])
./libtool --mode=clean rm -f conftest.lo libconftest.la >&AS_MESSAGE_LOG_FD
rm -f conftest.$ac_ext
m4_popdef([ACTION_IF_FALSE])
YAT_USE_LIBTOOL_POP
]) # YAT_LT_LINK_LA_IFELSE
# _YAT_MSG_LOG_CONFTEST
# ---------------------
# log source file conftest.$ac_ext
m4_define([_YAT_MSG_LOG_CONFTEST],
[AS_ECHO(["$as_me: failed code was:"]) >&AS_MESSAGE_LOG_FD
sed 's/^/| /' conftest.$ac_ext >&AS_MESSAGE_LOG_FD
])
# _YAT_USE_LIBTOOL_TAG
# --------------------
# internal macro to select tag depending on active language
m4_define([_YAT_USE_LIBTOOL_TAG],
[AC_LANG_CASE([C],[CC],[C++],[CXX],[Fortran 77], [F77],[Fortran], [FC])])