Revision ddbb914d config/usrp_libusb.m4

b/config/usrp_libusb.m4
28 28
  dnl make sure the USB_* variables work (whether from PKGCONFIG
29 29
  dnl or overridden by the user)
30 30

31
  libusbok=no
32
  have_libusb1=no
33
  LIBUSB_PKG_CONFIG_NAME=''
31
  dnl do not use LDFLAGS, since PKGCONFIG will provide everything
32
  saved_LDFLAGS=${LDFLAGS}
33
  LDFLAGS=
34
  LIBUSB_PKG_CONFIG_NAME=
35

36
  dnl loop over various possible 'libusb' PKGCONFIG names, and choose
37
  dnl the first one that meets both the user's selection (via
38
  dnl configure flags) as well as what is installed
39

40
  dnl create the list of libusb PKGCONFIG modules to test
41
  libusb_list=''
34 42
  if test x$1 = xyes; then
35
    PKG_CHECK_MODULES(USB, libusb-1.0, [
36
      libusbok=yes
37
      have_libusb1=yes
38
      usb_header='libusb-1.0/libusb.h'
39
      usb_lib_func='libusb_bulk_transfer'
40
      usb_lib_name='usb-1.0'
41
      LIBUSB_PKG_CONFIG_NAME='libusb-1.0'
42
    ])
43
    dnl libusb-1.0 was requested; just test for it
44
    libusb_list="libusb-1.0"
43 45
  else
44
    dnl not using libusb1 (for now); see if legacy version is found.
45
    dnl it might be installed under the name either 'libusb' or
46
    dnl 'libusb-legacy', or just available via the
47
    dnl user's shell environment
48

49
    dnl see if the pkgconfig module 'libusb' is available
50
    PKG_CHECK_MODULES(USB, libusb, [
51
      libusbok=yes
52
      LIBUSB_PKG_CONFIG_NAME='libusb'
46
    dnl test for legacy libusb only
47
    libusb_list="libusb libusb-legacy"
48
  fi
49
  for libusb_name in ${libusb_list}; do
50
    dnl clear internal variables
51
    libusbok=no
52
    have_libusb1=no
53
    usb_header=''
54
    usb_lib_func=''
55
    usb_lib_name=''
56

57
    dnl start checks
58
    AC_MSG_NOTICE([Checking for LIBUSB version '${libusb_name}'])
59
    if test ${libusb_name} = "libusb-1.0"; then
60
      dnl see if the pkgconfig module is available
61
      PKG_CHECK_MODULES(USB, ${libusb_name}, [
62
        libusbok=yes
63
        have_libusb1=yes
64
        usb_header='libusb-1.0/libusb.h'
65
        usb_lib_func='libusb_bulk_transfer'
53 66
      ], [libusbok=no])
54
    dnl PKG_CHECK_MODULES does not work correctly when embedded
55
    if test $libusbok = no; then
56
      dnl if not, see if the pkgconfig module 'libusb-legacy' is available
57
      PKG_CHECK_MODULES(USB, [libusb-legacy], [
67
    else
68
      dnl see if the pkgconfig module is available
69
      PKG_CHECK_MODULES(USB, ${libusb_name}, [
58 70
        libusbok=yes
59
        LIBUSB_PKG_CONFIG_NAME='libusb-legacy'
60
        ], [libusbok=no])
71
        usb_header='usb.h'
72
        usb_lib_func='usb_bulk_write'
73
      ], [libusbok=no])
61 74
    fi
62
    dnl set variables for further testing
63
    usb_header='usb.h'
64
    usb_lib_func='usb_bulk_write'
65
    usb_lib_name='usb'
66
  fi
67
  AC_SUBST(LIBUSB_PKG_CONFIG_NAME)
68
  if test x$1 != xyes || test $have_libusb1 = yes; then
69
    dnl Either (1) libusb1 was specified and found; or
70
    dnl (2) libusb1 was not specified. Restart checking.
71
    libusbok=yes
75
    if test $libusbok = yes; then
76
      dnl PKGCONFIG found a version of LIBUSB.
77
      dnl Check it to make sure it meets enough criteria:
78
      dnl Verify that $usb_header is a valid header. If so, then
79
      dnl verify that $usb_lib_func can be found in the library
80
      dnl $usb_lib_name.  if so, verify that the symbol 'usb_debug' is
81
      dnl found in the library.
82

83
      dnl Check for the header.  Similar to AC_CHECK_HEADERS,
84
      dnl but doesn't append to known \#defines.
85
      dnl If PKGCONFIG found variable USB_INCLUDEDIR, and it is
86
      dnl not empty, use it for checking for $usb_header.
87
      dnl Otherwise, maybe the user's shell environment is already
88
      dnl configured to find this header.
89
      AC_LANG_PUSH(C)
90
      save_CPPFLAGS="$CPPFLAGS"
91
      if test x$USB_INCLUDEDIR != x; then
92
        USB_INCLUDES="-I$USB_INCLUDEDIR"
93
        CPPFLAGS="$USB_INCLUDES"
94
      fi
95
      AC_MSG_CHECKING([$libusb_name for header $usb_header])
96
      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
97
        #include "$usb_header"
98
        ]], [])],
99
        [libusbok=yes],[libusbok=no])
100
      AC_MSG_RESULT([$libusbok])
101
      CPPFLAGS="$save_CPPFLAGS"
102
      AC_LANG_POP(C)
103

104
      if test $libusbok = yes; then
105
        dnl found the header; now make sure the library is OK
106
        dnl On Darwin, need to include the IOKit library.     
72 107

73
    dnl Verify that $usb_header is a valid header, and if so,
74
    dnl then verify that $usb_lib_func can be found in the
75
    dnl library $usb_lib_name.
108
        AC_LANG_PUSH(C)
109
        save_LIBS="$LIBS"
110
        LIBS=""
111
        case "$host_os" in
112
          darwin*)
113
            USB_LIBS="$USB_LIBS -lIOKit"
114
            LIBS="$USB_LIBS"
115
            ;;
116
          *) ;;
117
        esac
76 118

77
    dnl If PKGCONFIG found variable USB_INCLUDEDIR, and it is
78
    dnl not empty, use it for checking for $usb_header.
79
    dnl Otherwise, maybe the user's shell environment is already
80
    dnl configured to find this header.
119
 	dnl find the library link name
120
        usb_lib_name=`echo $USB_LIBS | sed -e "s@.*-l\(usb[[^ ]]*\).*@\1@"`
81 121

122
        dnl Check for the function in the library.  Similar to
123
        dnl AC_CHECK_LIB, but doesn't append to known \#defines.
124
        AC_MSG_CHECKING([$libusb_name for function $usb_lib_func in library $usb_lib_name])
125
        AC_LINK_IFELSE([AC_LANG_PROGRAM([[
126
          #ifdef __cplusplus
127
          extern "C"
128
          #endif
129
          char $usb_lib_func ();
130
          ]], [[return $usb_lib_func ();]])],
131
          [libusbok=yes],[libusbok=no])
132
        AC_MSG_RESULT([$libusbok])
133
        case "$host_os" in
134
          cygwin* | mingw*)
135
            USB_LIBS="$LIBS"
136
            ;;
137
          *) ;;
138
        esac
139
        LIBS="$save_LIBS"
140
        AC_LANG_POP(C)
141

142
        if test $libusbok = yes; then
143
          if test ${libusb_name} != "libusb-1.0"; then
144
            dnl PKGCONFIG found a legacy version of libusb; make sure the
145
            dnl variable _usb_debug is available in the found library
146
            AC_LANG_PUSH(C)
147
            save_CPPFLAGS="$CPPFLAGS"
148
            CPPFLAGS="$USB_INCLUDES"
149
            save_LIBS="$LIBS"
150
            LIBS="$USB_LIBS"
151
            AC_MSG_CHECKING([$libusb_name for symbol usb_debug in library $usb_lib_name])
152
            AC_LINK_IFELSE([AC_LANG_PROGRAM([[
153
              extern int usb_debug;]],
154
              [[usb_debug = 0;]])],
155
              [libusbok=yes],[libusbok=no])
156
            AC_MSG_RESULT([$libusbok])
157
            LIBS="$save_LIBS"
158
            CPPFLAGS="$save_CPPFLAGS"
159
            AC_LANG_POP(C)
160
          fi
161
        fi
162
      fi
163
    fi
164
    dnl if everything checks out OK, finish up
165
    if test $libusbok = yes; then
166
      LIBUSB_PKG_CONFIG_NAME="${libusb_name}"
167
      break
168
    else
169
      dnl something wasn't found in this LIBUSB version.
170
      dnl HACK: clear cache variables for header and library
171
      unset USB_INCLUDEDIR
172
      unset USB_INCLUDES
173
      unset USB_LIBS
174
      unset $as_ac_Header
175
      unset $as_ac_Lib
176
    fi
177
  done
178

179
  if test $libusbok = yes; then
180
    dnl final error checking, mostly to create #define's
82 181
    AC_LANG_PUSH(C)
83 182
    save_CPPFLAGS="$CPPFLAGS"
84
    if test x$USB_INCLUDEDIR != x; then
85
      USB_INCLUDES="-I$USB_INCLUDEDIR"
86
      CPPFLAGS="$CPPFLAGS $USB_INCLUDES"
87
      AC_SUBST(USB_INCLUDES)
88
    fi
183
    CPPFLAGS="$USB_INCLUDES"
184
    dnl Check for the header.
89 185
    AC_CHECK_HEADERS([$usb_header], [], [libusbok=no])
90 186
    CPPFLAGS="$save_CPPFLAGS"
91 187
    AC_LANG_POP(C)
......
93 189
    if test $libusbok = no; then
94 190
      AC_MSG_RESULT([USRP requires libusb header '$usb_header' which was not found or was not usable. See http://www.libusb.org])
95 191
    else
96

97
      dnl found the header; now make sure the library is OK
98
      dnl On Darwin, need to include the IOKit library.     
99

192
      dnl check for the library (again)
100 193
      AC_LANG_PUSH(C)
194
      save_CPPFLAGS="$CPPFLAGS"
195
      CPPFLAGS="$USB_INCLUDES"
101 196
      save_LIBS="$LIBS"
102
      LIBS=""
103
      case "$host_os" in
104
        darwin*)
105
          USB_LIBS="$USB_LIBS -lIOKit"
106
          LIBS="$USB_LIBS"
107
          ;;
108
        *) ;;
109
      esac
197
      LIBS="$USB_LIBS"
110 198
      AC_CHECK_LIB([$usb_lib_name], [$usb_lib_func], [], [
111 199
        libusbok=no
112
        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])
113
      ])
114
      case "$host_os" in
115
        cygwin* | mingw*)
116
          USB_LIBS="$LIBS"
117
          ;;
118
        *) ;;
119
      esac
200
        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])])
120 201
      LIBS="$save_LIBS"
202
      CPPFLAGS="$save_CPPFLAGS"
121 203
      AC_LANG_POP(C)
122 204
    fi
123 205
  fi
206

124 207
  if test $libusbok = yes; then
125
    AC_SUBST(USB_LIBS)
208
    dnl success
209
    AC_MSG_NOTICE([Using LIBUSB version '${libusb_name}'])
126 210
    ifelse([$2], , :, [$2])
127 211
  else
212
    dnl not found; clear substitution variables
213
    LIBUSB_PKG_CONFIG_NAME=
128 214
    USB_INCLUDES=
129 215
    USB_LIBS=
130 216
    ifelse([$3], , :, [$3])
131 217
  fi
218

219
  dnl create substitution variables
220
  AC_SUBST(USB_INCLUDES)
221
  AC_SUBST(USB_LIBS)
222
  AC_SUBST(LIBUSB_PKG_CONFIG_NAME)
223

224
  dnl restore LDFLAGS
225
  LDFLAGS=${saved_LDFLAGS}
132 226
])

Also available in: Unified diff