source: trunk/m4/yat_check_libs.m4

Last change on this file was 4019, checked in by Peter, 7 months ago

merge 0.18 into trunk

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Date
File size: 2.3 KB
Line 
1## $Id: yat_check_libs.m4 4019 2020-11-06 01:55:37Z peter $
2#
3# serial 3 (yat 0.18)
4#
5# see http://www.gnu.org/software/automake/manual/automake.html#Serials
6#
7# SYNOPSIS
8#
9#   YAT_CHECK_LIBS(MESSAGE, CACHE-ID, SEARCH-LIBS, INPUT,
10#                  [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
11#
12# DESCRIPTION
13#
14#   Similar to AC_SEARCH_LIBS.
15#
16#   First try compiling and linking code INPUT. If it fails, loop over
17#   libraries SEARCH-LIBS and try linking again. If there is no
18#   library that makes the code link, execute ACTION-IF-NOT-FOUND. If
19#   there is a library, prepend -llibrary to $LIBS. Result is saved in
20#   cache variable CACHE-ID, which must contain '_cv_'
21#
22# COPYLEFT
23#
24#   Copyright (C) 2020 Peter Johansson
25#
26#   This file is part of the yat library, http://dev.thep.lu.se/yat
27#
28#   The yat library is free software; you can redistribute it and/or
29#   modify it under the terms of the GNU General Public License as
30#   published by the Free Software Foundation; either version 3 of the
31#   License, or (at your option) any later version.
32#
33#   The yat library is distributed in the hope that it will be useful,
34#   but WITHOUT ANY WARRANTY; without even the implied warranty of
35#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
36#   General Public License for more details.
37#
38#   You should have received a copy of the GNU General Public License
39#   along with yat. If not, see <http://www.gnu.org/licenses/>.
40#
41
42AC_DEFUN([YAT_CHECK_LIBS],
43[
44  m4_pushdef([yat_MESSAGE], [$1])
45  m4_pushdef([yat_CACHE], [$2])
46  m4_pushdef([yat_SEARCH_LIBS], [$3])
47  m4_pushdef([yat_DEFAULT_RESULT], ["none required"])
48  AC_LANG_CONFTEST([$4])
49  AC_CACHE_CHECK([yat_MESSAGE], [yat_CACHE], [
50    save_LIBS=$LIBS
51    for yat_lib in '' yat_SEARCH_LIBS; do
52      AS_VAR_IF([yat_lib], [''],[
53        yat_result=yat_DEFAULT_RESULT
54      ], [
55        yat_result=-l$yat_lib
56        LIBS="-l$yat_lib $save_LIBS"
57      ])
58      AC_LINK_IFELSE([], [yat_CACHE=$yat_result])
59      AS_VAR_SET_IF([yat_CACHE], [break])
60    done
61    AS_VAR_SET_IF([yat_CACHE], [], [yat_CACHE=no])
62    rm conftest.$ac_ext
63    LIBS=$save_LIBS
64  ])
65  yat_result=$yat_CACHE
66
67  # action
68  AS_VAR_IF([yat_result], [no], [$6], [
69    AS_VAR_IF([yat_result], [yat_DEFAULT_RESULT], [],
70              [LIBS="$yat_result $LIBS"])
71    $5
72  ])
73
74  m4_popdef([yat_MESSAGE])
75  m4_popdef([yat_CACHE])
76  m4_popdef([yat_SEARCH_LIBS])
77  m4_popdef([yat_DEFAULT_RESULT])
78])
Note: See TracBrowser for help on using the repository browser.