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