ac_find_lib_headers.m4
5.83 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
#####
#
# 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
# /usr/local/lib64
# /usr/local/lib
# /usr/lib64
# /usr/lib
# /opt/local/lib64 (for Mac OS X)
# /opt/local/lib (for Mac OS X)
#
# 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_save_CPPFLAGS=$CPPFLAGS
ac_find_lib_add_LDFLAGS=
ac_find_lib_add_CPPFLAGS=
# Set link flags for testing
LIBS="-l$1 $6 $LIBS"
# Loop over all directories
for i in '' "$gammalib_prefix" /usr/local /usr /opt/local; do
for l in lib64 lib; do
# Case A: headers are required
if test "x$3" != "x"; then
for header in $3; do
if test "x$i" == "x"; then
ac_find_lib_add_LDFLAGS=
ac_find_lib_add_CPPFLAGS=
LDFLAGS="$ac_find_lib_save_LDFLAGS"
CPPFLAGS="$ac_find_lib_save_CPPFLAGS"
ac_message="found"
else
ac_find_lib_add_LDFLAGS=" -L$i/$l"
ac_find_lib_add_CPPFLAGS=" -I$i/include"
LDFLAGS="$ac_find_lib_save_LDFLAGS$ac_find_lib_add_LDFLAGS"
CPPFLAGS="$ac_find_lib_save_CPPFLAGS$ac_find_lib_add_CPPFLAGS"
ac_message="found in $i/$lib and $i/$include"
fi
# Test if we can link the library
AC_LINK_IFELSE([AC_LANG_CALL([], [$2])],
[AS_VAR_SET([ac_find_lib_status], [yes])],
[AS_VAR_SET([ac_find_lib_status], [no])])
# Test if the preprocessor can handle the header
AC_PREPROC_IFELSE([AC_LANG_SOURCE([@%:@include <$header>])],
[AS_VAR_SET([ac_find_header_status], [yes])],
[AS_VAR_SET([ac_find_header_status], [no])])
# Test if we can compile the header (not used as problems with
# readline
#AC_COMPILE_IFELSE([AC_LANG_SOURCE([@%:@include <$header>])],
# [AS_VAR_SET([ac_find_header_status], [yes])],
# [AS_VAR_SET([ac_find_header_status], [no])])
# Recover old flags
LDFLAGS=$ac_find_lib_save_LDFLAGS
CPPFLAGS=$ac_find_lib_save_CPPFLAGS
if test "x$ac_find_lib_status" = "xyes" -a "x$ac_find_header_status" = "xyes"; then
break
else
ac_find_lib_status="no"
fi
done
if test "x$ac_find_lib_status" = "xyes"; then
break
fi
# Case B: no headers are required
else
if test -z "$i"; then
ac_find_lib_add_LDFLAGS=
LDFLAGS="$ac_find_lib_save_LDFLAGS"
ac_message="found"
else
ac_find_lib_add_LDFLAGS=" -L$i/$l"
LDFLAGS="$ac_find_lib_save_LDFLAGS$ac_find_lib_add_LDFLAGS"
ac_message="found in $ac_find_lib_add_LDFLAGS"
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
break
fi
fi
done
if test "x$ac_find_lib_status" = "xyes"; then
break
fi
done
# Recover original LIBS value
LIBS=$ac_find_lib_save_LIBS
# Set flags
if test "x$3" != "x"; then
AS_IF([test "$ac_find_lib_status" = yes ],
[LIBS="-l$1 $LIBS"
LDFLAGS="$LDFLAGS$ac_find_lib_add_LDFLAGS"
CPPFLAGS="$CPPFLAGS$ac_find_lib_add_CPPFLAGS"
AC_MSG_RESULT($ac_message)
$4],
[AC_MSG_RESULT([not found])
$5])
else
AS_IF([test "$ac_find_lib_status" = yes ],
[LIBS="-l$1 $LIBS"
LDFLAGS="$LDFLAGS$ac_find_lib_add_LDFLAGS"
AC_MSG_RESULT($ac_message)
$4],
[AC_MSG_RESULT([not found])
$5])
fi
# Kluge to set include directives
if test "x$3" != "x" -a "$ac_find_lib_status" = yes; then
AC_CHECK_HEADERS([$header $3], [break])
fi
# echo "out: "$LIBS $LDFLAGS $CPPFLAGS
])