Commit cde53380fb7c04c54f8423de4e07e91f69256922
1 parent
5d0f0d74
initial version
Showing
1 changed file
with
181 additions
and
0 deletions
m4/ac_find_lib_headers.m4
0 → 100644
| 1 | +##### | |
| 2 | +# | |
| 3 | +# SYNOPSIS | |
| 4 | +# | |
| 5 | +# AC_FIND_LIB_HEADERS(LIBRARY, FUNCTION, HEADERS | |
| 6 | +# [ACTION-IF-FOUND], | |
| 7 | +# [ACTION-IF-NOT-FOUND], | |
| 8 | +# [OTHER-LIBRARIES]) | |
| 9 | +# | |
| 10 | +# DESCRIPTION | |
| 11 | +# | |
| 12 | +# This macro searches for a particular library on your system by | |
| 13 | +# scanning a number of default directories. You can use the optional | |
| 14 | +# third argument to search also for headers using AC_CHECK_HEADERS. | |
| 15 | +# | |
| 16 | +# The directories that are searched are (in the given order): | |
| 17 | +# $gammalib_prefix/lib64 | |
| 18 | +# $gammalib_prefix/lib | |
| 19 | +# /opt/local/lib64 (for Mac OS X) | |
| 20 | +# /opt/local/lib (for Mac OS X) | |
| 21 | +# /usr/local/lib64 | |
| 22 | +# /usr/local/lib | |
| 23 | +# /usr/lib64 | |
| 24 | +# /usr/lib | |
| 25 | +# /lib64 (for readline/ncurses is some distros) | |
| 26 | +# /lib (for readline/ncurses is some distros) | |
| 27 | +# | |
| 28 | +# If the library is found, the function adds it's name to LIBS. | |
| 29 | +# Furthermore, if the library is found in a specific directory, the | |
| 30 | +# directory name is added to LDFLAGS. If the headers are found in a | |
| 31 | +# specific directory, the directory name is added to CPPFLAGS. | |
| 32 | +# | |
| 33 | +# In configure.in, use as: | |
| 34 | +# | |
| 35 | +# AC_FIND_LIB_HEADERS([readline], [readline], [], [], [], []) | |
| 36 | +# | |
| 37 | +# LAST MODIFICATION | |
| 38 | +# | |
| 39 | +# 2011-07-13 | |
| 40 | +# | |
| 41 | +# COPYLEFT | |
| 42 | +# | |
| 43 | +# Copyright (c) 2011 Juergen Knodlseder <knodlseder@cesr.fr> | |
| 44 | +# | |
| 45 | +# This program is free software: you can redistribute it and/or modify | |
| 46 | +# it under the terms of the GNU General Public License as published by | |
| 47 | +# the Free Software Foundation, either version 3 of the License, or | |
| 48 | +# (at your option) any later version. | |
| 49 | +# | |
| 50 | +# This program is distributed in the hope that it will be useful, | |
| 51 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 52 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 53 | +# GNU General Public License for more details. | |
| 54 | +# | |
| 55 | +# You should have received a copy of the GNU General Public License | |
| 56 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 57 | + | |
| 58 | +AC_DEFUN([AC_FIND_LIB_HEADER],[ | |
| 59 | + # | |
| 60 | + # Initialise status | |
| 61 | + # | |
| 62 | + AS_VAR_SET([ac_find_lib_status], [no]) | |
| 63 | + AS_VAR_SET([ac_find_header_status], [no]) | |
| 64 | + # | |
| 65 | + # Signal checking | |
| 66 | + # | |
| 67 | + AC_MSG_CHECKING([for $2 in -l$1]) | |
| 68 | + # | |
| 69 | + # Save original values | |
| 70 | + # | |
| 71 | + # echo "in: "$LIBS $LDFLAGS $CPPFLAGS | |
| 72 | + ac_find_lib_save_LIBS=$LIBS | |
| 73 | + ac_find_lib_save_LDFLAGS=$LDFLAGS | |
| 74 | + ac_find_lib_add_LDFLAGS= | |
| 75 | + ac_find_lib_base= | |
| 76 | + # | |
| 77 | + # Set link flags for testing | |
| 78 | + # | |
| 79 | + LIBS="-l$1 $6 $LIBS" | |
| 80 | + # | |
| 81 | + # Loop over all directories | |
| 82 | + # | |
| 83 | + for i in '' "$gammalib_prefix" /opt/local /usr/local /usr /; do | |
| 84 | + # | |
| 85 | + # Search library in lib64 first | |
| 86 | + # | |
| 87 | + if test -z "$i"; then | |
| 88 | + LDFLAGS="$ac_find_lib_save_LDFLAGS" | |
| 89 | + ac_message="found" | |
| 90 | + else | |
| 91 | + LDFLAGS="$ac_find_lib_save_LDFLAGS -L$i/lib64" | |
| 92 | + ac_message="found in $i/lib64" | |
| 93 | + fi | |
| 94 | + AC_LINK_IFELSE([AC_LANG_CALL([], [$2])], | |
| 95 | + [AS_VAR_SET([ac_find_lib_status], [yes])], | |
| 96 | + [AS_VAR_SET([ac_find_lib_status], [no])]) | |
| 97 | + LDFLAGS=$ac_find_lib_save_LDFLAGS | |
| 98 | + if test "x$ac_find_lib_status" = "xyes"; then | |
| 99 | + if test -z "$i"; then | |
| 100 | + ac_find_lib_add_LDFLAGS= | |
| 101 | + else | |
| 102 | + ac_find_lib_add_LDFLAGS=" -L$i/lib64" | |
| 103 | + ac_find_lib_base="$i" | |
| 104 | + fi | |
| 105 | + break | |
| 106 | + fi | |
| 107 | + # | |
| 108 | + # If still alive, check library in lib next | |
| 109 | + # | |
| 110 | + if test -z "$i"; then | |
| 111 | + LDFLAGS="$ac_find_lib_save_LDFLAGS" | |
| 112 | + ac_message="found" | |
| 113 | + else | |
| 114 | + LDFLAGS="$ac_find_lib_save_LDFLAGS -L$i/lib" | |
| 115 | + ac_message="found in $i/lib" | |
| 116 | + fi | |
| 117 | + AC_LINK_IFELSE([AC_LANG_CALL([], [$2])], | |
| 118 | + [AS_VAR_SET([ac_find_lib_status], [yes])], | |
| 119 | + [AS_VAR_SET([ac_find_lib_status], [no])]) | |
| 120 | + LDFLAGS=$ac_find_lib_save_LDFLAGS | |
| 121 | + if test "x$ac_find_lib_status" = "xyes"; then | |
| 122 | + if test -z "$i"; then | |
| 123 | + ac_find_lib_add_LDFLAGS= | |
| 124 | + else | |
| 125 | + ac_find_lib_add_LDFLAGS=" -L$i/lib" | |
| 126 | + ac_find_lib_base="$i" | |
| 127 | + fi | |
| 128 | + break | |
| 129 | + fi | |
| 130 | + done | |
| 131 | + # | |
| 132 | + # Recover original values | |
| 133 | + # | |
| 134 | + LIBS=$ac_find_lib_save_LIBS | |
| 135 | + LDFLAGS=$ac_find_lib_save_LDFLAGS | |
| 136 | + # | |
| 137 | + # Inform about test result | |
| 138 | + # | |
| 139 | + if test "x$ac_find_lib_status" = "xyes"; then | |
| 140 | + AC_MSG_RESULT($ac_message) | |
| 141 | + else | |
| 142 | + AC_MSG_RESULT([not found]) | |
| 143 | + fi | |
| 144 | + # | |
| 145 | + # Optionally check for presence of headers (see AC_CHECK_HEADERS) | |
| 146 | + # | |
| 147 | + if test "x$3" != "x"; then | |
| 148 | + ac_find_lib_save_CPPFLAGS=$CPPFLAGS | |
| 149 | + ac_find_lib_add_CPPFLAGS= | |
| 150 | + if test -z "$ac_find_lib_base"; then | |
| 151 | + CPPFLAGS="$ac_find_lib_save_CPPFLAGS" | |
| 152 | + else | |
| 153 | + CPPFLAGS="$ac_find_lib_save_CPPFLAGS -I$ac_find_lib_base/include" | |
| 154 | + fi | |
| 155 | + AC_CHECK_HEADERS([$3], | |
| 156 | + [AS_VAR_SET([ac_find_header_status], [yes]) | |
| 157 | + break]) | |
| 158 | + CPPFLAGS=$ac_find_lib_save_CPPFLAGS | |
| 159 | + if test "x$ac_find_header_status" = "xyes"; then | |
| 160 | + if test -z "$ac_find_lib_base"; then | |
| 161 | + CPPFLAGS="$CPPFLAGS" | |
| 162 | + AC_MSG_NOTICE([$1 headers found]) | |
| 163 | + else | |
| 164 | + CPPFLAGS="$CPPFLAGS -I$ac_find_lib_base/include" | |
| 165 | + AC_MSG_NOTICE([$1 headers found in $ac_find_lib_base/include]) | |
| 166 | + fi | |
| 167 | + else | |
| 168 | + AC_MSG_WARN([No $1 headers found]) | |
| 169 | + fi | |
| 170 | + AS_IF([test "$ac_find_lib_status" != no -a "ac_find_header_status" != no ], | |
| 171 | + [LIBS="-l$1 $LIBS" | |
| 172 | + LDFLAGS="$LDFLAGS $ac_find_lib_add_LDFLAGS" | |
| 173 | + $4], [$5]) | |
| 174 | + else | |
| 175 | + AS_IF([test "$ac_find_lib_status" != no], | |
| 176 | + [LIBS="-l$1 $LIBS" | |
| 177 | + LDFLAGS="$LDFLAGS $ac_find_lib_add_LDFLAGS" | |
| 178 | + $4], [$5]) | |
| 179 | + fi | |
| 180 | + # echo "out: "$LIBS $LDFLAGS $CPPFLAGS | |
| 181 | +]) | ... | ... |