augmented search for libusb
[debian/gnuradio] / config / usrp_libusb.m4
1 dnl Copyright 2003,2008,2009 Free Software Foundation, Inc.
2 dnl 
3 dnl This file is part of GNU Radio
4 dnl 
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)
8 dnl any later version.
9 dnl 
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.
14 dnl 
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.
19
20 # $1 is $req_libusb1:
21 #   yes : check libusb-1.0
22 #   no  : check libusb-0.12
23 #   ""  : check libusb-0.12
24
25
26 AC_DEFUN([USRP_LIBUSB], [
27   dnl Use PKGCONFIG to check for packages first, then check to
28   dnl make sure the USB_* variables work (whether from PKGCONFIG
29   dnl or overridden by the user)
30
31   libusbok=no
32   have_libusb1=no
33   if test x$1 = xyes; then
34     PKG_CHECK_MODULES(USB, libusb-1.0, [
35       libusbok=yes
36       have_libusb1=yes
37       usb_header='libusb-1.0/libusb.h'
38       usb_lib_func='libusb_bulk_transfer'
39       usb_lib_name='usb-1.0'
40     ])
41   fi
42   if test $libusbok = no; then
43     dnl not using libusb1, or PKGCONFIG check for libusb1 failed;
44     dnl see if legacy version is found.
45     dnl it might be installed under the name either 'libusb' or
46     dnl 'libusb-legacy'. check them in that order.
47
48     dnl see if the pkgconfig module 'libusb' is available
49     PKG_CHECK_MODULES(USB, libusb, [libusbok=yes], [libusbok=no])
50     dnl PKG_CHECK_MODULES does not work correctly when embedded
51     if test $libusbok = no; then
52       dnl if not, see if the pkgconfig module 'libusb-legacy' is available
53       PKG_CHECK_MODULES(USB, [libusb-legacy], [libusbok=yes], [libusbok=no])
54     fi
55     if test $libusbok = yes; then
56       dnl if PKGCONFIG worked, set variables for further testing
57       usb_header='usb.h'
58       usb_lib_func='usb_bulk_write'
59       usb_lib_name='usb'
60     fi
61   fi
62   if test $libusbok = no; then
63     AC_MSG_RESULT([USRP requires libusb, which was not found. See http://www.libusb.org])
64   else
65
66     dnl either some pkgconfig LIBUSB* variant was found, or USB_*
67     dnl variables were overridden by the user as arguments to configure.
68     dnl either way, check the USB_* variables to make sure they work
69
70     AC_LANG_PUSH(C)
71     save_CPPFLAGS="$CPPFLAGS"
72     if test x$USB_INCLUDEDIR != x; then
73       USB_INCLUDES="-I$USB_INCLUDEDIR"
74       CPPFLAGS="$CPPFLAGS $USB_INCLUDES"
75       AC_SUBST(USB_INCLUDES)
76     fi
77     AC_CHECK_HEADERS([$usb_header], [], [libusbok=no])
78     CPPFLAGS="$save_CPPFLAGS"
79     AC_LANG_POP(C)
80
81     if test $libusbok = no; then
82       AC_MSG_RESULT([USRP requires libusb header '$usb_header' which was not found or was not usable. See http://www.libusb.org])
83     else
84
85       dnl found the header; now make sure the library is OK
86
87       AC_LANG_PUSH(C)
88       save_LIBS="$LIBS"
89       case "$host_os" in
90         darwin*)
91           USB_LIBS="$USB_LIBS -lIOKit"
92           ;;
93         *) ;;
94       esac
95       LIBS="$LIBS $USB_LIBS"
96       AC_CHECK_LIB([$usb_lib_name], [$usb_lib_func], [], [
97         libusbok=no
98         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])
99       ])
100       LIBS="$save_LIBS"
101       AC_LANG_POP(C)
102     fi
103   fi
104   if test $libusbok = yes; then
105     AC_SUBST(USB_LIBS)
106     ifelse([$2], , :, [$2])
107   else
108     USB_INCLUDES=
109     USB_LIBS=
110     ifelse([$3], , :, [$3])
111   fi
112 ])