1 dnl Copyright 2003,2008,2009 Free Software Foundation, Inc.
3 dnl This file is part of GNU Radio
5 dnl GNU Radio is free software; you can redistribute it and/or modify
6 dnl it under the terms of the GNU General Public License as published by
7 dnl the Free Software Foundation; either version 3, or (at your option)
10 dnl GNU Radio is distributed in the hope that it will be useful,
11 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
12 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 dnl GNU General Public License for more details.
15 dnl You should have received a copy of the GNU General Public License
16 dnl along with GNU Radio; see the file COPYING. If not, write to
17 dnl the Free Software Foundation, Inc., 51 Franklin Street,
18 dnl Boston, MA 02110-1301, USA.
21 # yes : check libusb-1.0
22 # no : check libusb-0.12
23 # "" : check libusb-0.12
26 AC_DEFUN([USRP_LIBUSB], [
27 dnl do not use LDFLAGS, except on Windows
28 saved_LDFLAGS=${LDFLAGS}
37 dnl this variable is set in usrp/usrp.pc.in as a requirement
38 dnl for libusrp; it is OK to be empty.
39 LIBUSB_PKG_CONFIG_NAME=
41 dnl for Windows (cygin, mingw), do not use PKGCONFIG since LIBUSB
42 dnl does not install a .pc file. For all other OSs, use
43 dnl PKGCONFIG to check for various package names first.
50 dnl create the list of libusb PKGCONFIG modules to test
51 if test x$1 = xyes; then
52 dnl libusb-1.0 was requested; just test for it
53 libusb_list="libusb-1.0"
55 dnl test for legacy libusb only
56 libusb_list="libusb libusb-legacy"
61 dnl loop over various possible 'libusb' names, and
62 dnl choose the first one that meets both the user's selection
63 dnl (via configure flags) as well as what is installed
64 for libusb_name in ${libusb_list}; do
65 dnl clear internal variables
78 usb_lib_func='usb_bulk_write'
83 AC_MSG_NOTICE([Checking for LIBUSB version '${libusb_name}'])
84 if test ${libusb_name} = "libusb-1.0"; then
85 dnl see if the pkgconfig module is available
86 PKG_CHECK_MODULES(USB, ${libusb_name}, [
89 usb_header='libusb-1.0/libusb.h'
90 usb_lib_func='libusb_bulk_transfer'
93 dnl see if the pkgconfig module is available
94 PKG_CHECK_MODULES(USB, ${libusb_name}, [
97 usb_lib_func='usb_bulk_write'
102 if test $libusbok = yes; then
103 dnl PKGCONFIG found a version of LIBUSB, or the info was
104 dnl provided by the user, or the OS is Windows.
106 dnl Check it to make sure it meets enough criteria:
107 dnl Verify that $usb_header is a valid header. If so, then
108 dnl verify that $usb_lib_func can be found in the library
109 dnl $usb_lib_name. if so, verify that the symbol 'usb_debug' is
110 dnl found in the library if not using Windows.
112 dnl Check for the header. Similar to AC_CHECK_HEADERS,
113 dnl but doesn't append to known \#defines.
114 dnl If PKGCONFIG found variable USB_INCLUDEDIR, and it is
115 dnl not empty, use it for checking for $usb_header.
116 dnl Otherwise, maybe the user's shell environment is already
117 dnl configured to find this header.
119 save_CPPFLAGS="$CPPFLAGS"
120 if test x$USB_INCLUDEDIR != x; then
121 USB_INCLUDES="-I$USB_INCLUDEDIR"
122 CPPFLAGS="$USB_INCLUDES"
124 AC_MSG_CHECKING([$libusb_name for header $usb_header])
125 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
126 #include "$usb_header"
128 [libusbok=yes],[libusbok=no])
129 AC_MSG_RESULT([$libusbok])
130 CPPFLAGS="$save_CPPFLAGS"
133 if test $libusbok = yes; then
134 dnl found the header; now make sure the library is OK
135 dnl On Darwin, need to include the IOKit library.
141 USB_LIBS="$USB_LIBS -lIOKit"
147 dnl find the library link name
148 usb_lib_name=`echo $USB_LIBS | sed -e "s@.*-l\(usb[[^ ]]*\).*@\1@"`
150 dnl Check for the function in the library. Similar to
151 dnl AC_CHECK_LIB, but doesn't append to known \#defines.
152 AC_MSG_CHECKING([$libusb_name for function $usb_lib_func in library $usb_lib_name])
153 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
157 char $usb_lib_func ();
158 ]], [[return $usb_lib_func ();]])],
159 [libusbok=yes],[libusbok=no])
160 AC_MSG_RESULT([$libusbok])
164 if test $libusbok = yes; then
165 if test ${libusb_name} != "libusb-1.0"; then
166 dnl PKGCONFIG found a legacy version of libusb; make sure the
167 dnl variable _usb_debug is available in the found library.
168 dnl Do not test on Windows, since that symbol is not defined.
174 save_CPPFLAGS="$CPPFLAGS"
175 if test x$USB_INCLUDEDIR != x; then
176 CPPFLAGS="$USB_INCLUDES"
180 AC_MSG_CHECKING([$libusb_name for symbol usb_debug in library $usb_lib_name])
181 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
182 extern int usb_debug;]],
183 [[usb_debug = 0;]])],
184 [libusbok=yes],[libusbok=no])
185 AC_MSG_RESULT([$libusbok])
187 CPPFLAGS="$save_CPPFLAGS"
195 dnl if everything checks out OK, finish up
196 if test $libusbok = yes; then
201 LIBUSB_PKG_CONFIG_NAME="${libusb_name}"
206 dnl something wasn't found in this LIBUSB version.
207 dnl HACK: clear cache variables for header and library
216 if test $libusbok = yes; then
217 dnl final error checking, mostly to create #define's
219 save_CPPFLAGS="$CPPFLAGS"
220 if test x$USB_INCLUDEDIR != x; then
221 CPPFLAGS="$USB_INCLUDES"
223 dnl Check for the header.
224 AC_CHECK_HEADERS([$usb_header], [], [libusbok=no])
225 CPPFLAGS="$save_CPPFLAGS"
228 if test $libusbok = no; then
229 AC_MSG_RESULT([USRP requires libusb header '$usb_header' which was not found or was not usable. See http://www.libusb.org])
231 dnl check for the library (again)
233 save_CPPFLAGS="$CPPFLAGS"
234 if test x$USB_INCLUDEDIR != x; then
235 CPPFLAGS="$USB_INCLUDES"
239 AC_CHECK_LIB([$usb_lib_name], [$usb_lib_func], [], [
241 AC_MSG_RESULT([USRP requires library '$usb_lib_name' with function '$usb_lib_func', which was either not found or was not usable. See http://www.libusb.org])])
249 CPPFLAGS="$save_CPPFLAGS"
254 if test $libusbok = yes; then
256 AC_MSG_NOTICE([Using LIBUSB version '${libusb_name}'])
257 ifelse([$2], , :, [$2])
259 dnl not found; clear substitution variables
260 LIBUSB_PKG_CONFIG_NAME=
263 ifelse([$3], , :, [$3])
266 dnl create substitution variables
267 AC_SUBST(USB_INCLUDES)
269 AC_SUBST(LIBUSB_PKG_CONFIG_NAME)
272 LDFLAGS=${saved_LDFLAGS}