source: trunk/m4/yat_lt_link_ifelse.m4

Last change on this file was 3114, checked in by Peter, 8 years ago

update copyright years

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Date
File size: 4.0 KB
Line 
1## $Id: yat_lt_link_ifelse.m4 3114 2013-11-10 23:51:47Z peter $
2#
3# SYNOPSIS
4#
5#   YAT_LT_LINK_IFELSE(program, [action-if-true], [action-if-not-true])
6#
7# DESCRIPTION
8#
9# COPYLEFT
10#
11#   Copyright (C) 2010, 2011, 2013 Peter Johansson
12#
13#   This file is part of the yat library, http://dev.thep.lu.se/yat
14#
15#   The yat library is free software; you can redistribute it and/or
16#   modify it under the terms of the GNU General Public License as
17#   published by the Free Software Foundation; either version 3 of the
18#   License, or (at your option) any later version.
19#
20#   The yat library is distributed in the hope that it will be useful,
21#   but WITHOUT ANY WARRANTY; without even the implied warranty of
22#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23#   General Public License for more details.
24#
25#   You should have received a copy of the GNU General Public License
26#   along with yat. If not, see <http://www.gnu.org/licenses/>.
27#
28
29# Based on _KPSE_USE_LIBTOOL by
30# Peter Breitenlohner <peb@mppmu.mpg.de> shared here
31# http://www.mail-archive.com/autoconf@gnu.org/msg19948.html
32
33#
34# serial 5 (yat 0.11)
35#
36
37# YAT_LT_LINK_IFELSE(PROG, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
38# -------------------------------------------------------------
39# Same as AC_LINK_IFELSE but linking via libtool
40AC_DEFUN([YAT_LT_LINK_IFELSE],
41[
42  YAT_USE_LIBTOOL_PUSH
43  AC_LINK_IFELSE($@)
44  YAT_USE_LIBTOOL_POP
45]) # YAT_LT_LINK_IFELSE
46
47
48# YAT_USE_LIBTOOL_PUSH
49# --------------------
50# Assign `$ac_link' to use libtool. Variable is saved so they can be
51# restored with YAT_USE_LIBTOOL_POP
52AC_DEFUN([YAT_USE_LIBTOOL_PUSH],
53[
54m4_defn([LT_INIT])
55m4_ifdef([_YAT_USE_LIBTOOL], [],
56  [LT_OUTPUT
57   yat_use_libtool_ac_link=$ac_link;
58   ac_link='./libtool --mode=link --tag=_YAT_USE_LIBTOOL_TAG '"$ac_link";
59  ]) dnl
60m4_pushdef([_YAT_USE_LIBTOOL], [yes])
61]) # YAT_USE_LIBTOOL_PUSH
62
63
64# YAT_USE_LIBTOOL_POP
65# --------------------
66# Restore values of `$ac_link' and `$ac_compile' to what they were
67# prior YAT_USE_LIBTOOL_PUSH
68AC_DEFUN([YAT_USE_LIBTOOL_POP],
69[
70m4_popdef([_YAT_USE_LIBTOOL])
71m4_ifndef([_YAT_USE_LIBTOOL], dnl
72  [ac_link=$yat_use_libtool_ac_link;
73  ])
74]) # YAT_USE_LIBTOOL_POP
75
76
77# YAT_LT_LINK_LA_IFELSE(input, [action-if-true], [action-if-false])
78# -----------------------------------------------------------------
79# Try to create a libtool archive in two steps. First, run the
80# compiler on input similar to AC_COMPILE_IFELSE, but input is not
81# expected to have a main() function. If successful, try to create a
82# libconftest.la with created object as input and linking with
83# $LIBS. If both steps are successful, execute shell code
84# action-if-true, otherwise execute action-if-false.
85#
86# Note, that this macro can be used to check if libraries in $LIBS are
87# suitable to be linked into a libtool archive, but not that if input
88# is not using lib the test will test will succeed regardless whether
89# the lib is suitable or not.
90AC_DEFUN([YAT_LT_LINK_LA_IFELSE],
91[
92YAT_USE_LIBTOOL_PUSH
93AC_LANG_CONFTEST([AC_LANG_SOURCE([$1])])
94
95m4_pushdef([ACTION_IF_FALSE],
96           [_YAT_MSG_LOG_CONFTEST
97            $3])
98YAT_RUN_LOG([./libtool --mode=compile --tag=_YAT_USE_LIBTOOL_TAG \
99       $CXX $CPPFLAGS $CXXFLAGS -c -o conftest.lo conftest.$ac_ext],
100  [YAT_RUN_LOG([./libtool --mode=link --tag=_YAT_USE_LIBTOOL_TAG \
101                $CXX $CXXFLAGS $LDFLAGS -o libconftest.la \
102                -rpath `pwd` conftest.lo $LIBS],
103               [$2], [ACTION_IF_FALSE])],
104  [ACTION_IF_FALSE])
105
106./libtool --mode=clean rm -f conftest.lo libconftest.la >&AS_MESSAGE_LOG_FD
107rm -f conftest.$ac_ext
108m4_popdef([ACTION_IF_FALSE])
109YAT_USE_LIBTOOL_POP
110]) # YAT_LT_LINK_LA_IFELSE
111
112# _YAT_MSG_LOG_CONFTEST
113# ---------------------
114# log source file conftest.$ac_ext
115m4_define([_YAT_MSG_LOG_CONFTEST],
116[AS_ECHO(["$as_me: failed code was:"]) >&AS_MESSAGE_LOG_FD
117sed 's/^/| /' conftest.$ac_ext >&AS_MESSAGE_LOG_FD
118])
119
120# _YAT_USE_LIBTOOL_TAG
121# --------------------
122# internal macro to select tag depending on active language
123m4_define([_YAT_USE_LIBTOOL_TAG],
124[AC_LANG_CASE([C],[CC],[C++],[CXX],[Fortran 77], [F77],[Fortran], [FC])])
Note: See TracBrowser for help on using the repository browser.