source: trunk/m4/yat_lt_link_ifelse.m4 @ 3073

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

improve docs and send clean up message to log (rather than stdout).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Date
File size: 4.1 KB
Line 
1## $Id: yat_lt_link_ifelse.m4 3073 2013-08-30 02:54:26Z 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 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' and `$ac_compile' to use libtool. Variables are
51# saved so they can be 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_compile=$ac_compile;
58   ac_compile='./libtool --mode=compile --tag=_YAT_USE_LIBTOOL_TAG '"$ac_compile";
59   yat_use_libtool_ac_link=$ac_link;
60   ac_link='./libtool --mode=link --tag=_YAT_USE_LIBTOOL_TAG '"$ac_link";
61  ]) dnl
62m4_pushdef([_YAT_USE_LIBTOOL], [yes])
63]) # YAT_USE_LIBTOOL_PUSH
64
65
66# YAT_USE_LIBTOOL_POP
67# --------------------
68# Restore values of `$ac_link' and `$ac_compile' to what they were
69# prior YAT_USE_LIBTOOL_PUSH
70AC_DEFUN([YAT_USE_LIBTOOL_POP],
71[
72m4_popdef([_YAT_USE_LIBTOOL])
73m4_ifndef([_YAT_USE_LIBTOOL], dnl
74  [ac_compile=$yat_use_libtool_ac_compile;
75   ac_link=$yat_use_libtool_ac_link;
76  ])
77]) # YAT_USE_LIBTOOL_POP
78
79
80# YAT_LT_LINK_LA_IFELSE(input, [action-if-true], [action-if-false])
81# -----------------------------------------------------------------
82# Try to create a libtool archive in two steps. First, run the
83# compiler on input similar to AC_COMPILE_IFELSE, but input is not
84# expected to have a main() function. If successful, try to create a
85# libconftest.la with created object as input and linking with
86# $LIBS. If both steps are successful, execute shell code
87# action-if-true, otherwise execute action-if-false.
88#
89# Note, that this macro can be used to check if libraries in $LIBS are
90# suitable to be linked into a libtool archive, but not that if input
91# is not using lib the test will test will succeed regardless whether
92# the lib is suitable or not.
93AC_DEFUN([YAT_LT_LINK_LA_IFELSE],
94[
95YAT_USE_LIBTOOL_PUSH
96cat > conftest.$ac_ext << EOF
97$1
98EOF
99
100m4_pushdef([ACTION_IF_FALSE],
101           [_YAT_MSG_LOG_CONFTEST
102            $3])
103YAT_RUN_LOG([./libtool --mode=compile --tag=_YAT_USE_LIBTOOL_TAG \
104       $CXX $CPPFLAGS $CXXFLAGS -c -o conftest.lo conftest.$ac_ext],
105  [YAT_RUN_LOG([./libtool --mode=link --tag=_YAT_USE_LIBTOOL_TAG \
106                $CXX $CXXFLAGS $LDFLAGS -o libconftest.la \
107                -rpath `pwd` conftest.lo $LIBS],
108               [$2], [ACTION_IF_FALSE])],
109  [ACTION_IF_FALSE])
110
111./libtool --mode=clean rm -f conftest.lo libconftest.la >&AS_MESSAGE_LOG_FD
112rm -f conftest.$ac_ext
113m4_popdef([ACTION_IF_FALSE])
114YAT_USE_LIBTOOL_POP
115]) # YAT_LT_LINK_STATIC_IFELSE
116
117# _YAT_MSG_LOG_CONFTEST
118# ---------------------
119# log source file conftest.$ac_ext
120m4_define([_YAT_MSG_LOG_CONFTEST],
121[AS_ECHO(["$as_me: failed code was:"]) >&AS_MESSAGE_LOG_FD
122sed 's/^/| /' conftest.$ac_ext >&AS_MESSAGE_LOG_FD
123])
124
125# _YAT_USE_LIBTOOL_TAG
126# --------------------
127# internal macro to select tag depending on active language
128m4_define([_YAT_USE_LIBTOOL_TAG],
129[AC_LANG_CASE([C],[CC],[C++],[CXX],[Fortran 77], [F77],[Fortran], [FC])])
Note: See TracBrowser for help on using the repository browser.