chiark / gitweb /
Avoid simple memory dumps via ptrace
[gnupg2.git] / m4 / libusb.m4
1 dnl Check for libusb
2 dnl Copyright (C) 2004, 2005 Free Software Foundation, Inc.
3 dnl
4 dnl This file is free software, distributed under the terms of the GNU
5 dnl General Public License.  As a special exception to the GNU General
6 dnl Public License, this file may be distributed as part of a program
7 dnl that contains a configuration script generated by Autoconf, under
8 dnl the same distribution terms as the rest of that program.
9 dnl
10 dnl Defines HAVE_LIBUSB to 1 if a working libusb setup is found, and sets
11 dnl @LIBUSB@ to the necessary libraries.  HAVE_USB_GET_BUSSES is set if
12 dnl usb_get_busses() exists.
13
14 AC_DEFUN([GNUPG_CHECK_LIBUSB],
15 [
16   AC_ARG_WITH(libusb,
17      AC_HELP_STRING([--with-libusb=DIR],
18         [look for the libusb library in DIR]),
19      [_do_libusb=$withval],[_do_libusb=yes])
20
21   if test "$_do_libusb" != "no" ; then
22      if test -d "$withval" ; then
23         CPPFLAGS="${CPPFLAGS} -I$withval/include"
24         LDFLAGS="${LDFLAGS} -L$withval/lib"
25         AC_PATH_PROG([_usb_config],["$_do_libusb/bin/libusb-config"])
26      else
27         AC_PATH_PROG([_usb_config],[libusb-config])
28      fi
29
30      _libusb_save_libs=$LIBS
31      _libusb_save_cflags=$CFLAGS
32
33      if test x$_usb_config != "x" ; then
34         _libusb_try_libs=`$LIBS $_usb_config --libs`
35         _libusb_try_cflags=`$LIBS $_usb_config --cflags`
36      else
37         _libusb_try_libs="-lusb"
38         _libusb_try_cflags=""
39      fi
40
41      LIBS="$LIBS $_libusb_try_libs"
42      CFLAGS="$CFLAGS $_libusb_try_cflags"
43
44      AC_MSG_CHECKING([whether libusb is present and sane])
45
46      AC_LINK_IFELSE(AC_LANG_PROGRAM([#include <usb.h>],[
47 usb_bulk_write(NULL,0,NULL,0,0);
48 ]),_found_libusb=yes,_found_libusb=no)
49
50      AC_MSG_RESULT([$_found_libusb])
51
52      if test $_found_libusb = yes ; then
53         AC_DEFINE(HAVE_LIBUSB,1,
54            [Define to 1 if you have a fully functional libusb library.])
55         AC_SUBST(LIBUSB_CPPFLAGS,$_libusb_try_cflags)
56         AC_SUBST(LIBUSB,$_libusb_try_libs)
57         AC_CHECK_FUNCS(usb_get_busses)
58      fi
59
60      LIBS=$_libusb_save_libs
61      CFLAGS=$_libusb_save_cflags
62
63      unset _libusb_save_libs
64      unset _libusb_save_cflags
65      unset _libusb_try_libs
66      unset _libusb_try_cflags
67      unset _found_libusb
68   fi
69 ])dnl