~iheino+ub/+junk/nut-upsconf-docfix

« back to all changes in this revision

Viewing changes to m4/nut_check_libusb.m4

  • Committer: Tuomas Heino
  • Author(s): Laurent Bigonville
  • Date: 2014-04-22 20:46:12 UTC
  • Revision ID: iheino+ub@cc.hut.fi-20140422204612-1x2gh3nkezfsdao4
Tags: upstream-2.7.2
ImportĀ upstreamĀ versionĀ 2.7.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
dnl Check for LIBUSB compiler flags. On success, set nut_have_libusb="yes"
 
2
dnl and set LIBUSB_CFLAGS and LIBUSB_LIBS. On failure, set
 
3
dnl nut_have_libusb="no". This macro can be run multiple times, but will
 
4
dnl do the checking only once.
 
5
 
 
6
AC_DEFUN([NUT_CHECK_LIBUSB],
 
7
[
 
8
if test -z "${nut_have_libusb_seen}"; then
 
9
        nut_have_libusb_seen=yes
 
10
 
 
11
        dnl save CFLAGS and LIBS
 
12
        CFLAGS_ORIG="${CFLAGS}"
 
13
        LIBS_ORIG="${LIBS}"
 
14
 
 
15
        AC_MSG_CHECKING(for libusb version via pkg-config)
 
16
        LIBUSB_VERSION="`pkg-config --silence-errors --modversion libusb 2>/dev/null`"
 
17
        if test "$?" = "0" -a -n "${LIBUSB_VERSION}"; then
 
18
                CFLAGS="`pkg-config --silence-errors --cflags libusb 2>/dev/null`"
 
19
                LIBS="`pkg-config --silence-errors --libs libusb 2>/dev/null`"
 
20
        else
 
21
                AC_MSG_CHECKING(via libusb-config)
 
22
                LIBUSB_VERSION="`libusb-config --version 2>/dev/null`"
 
23
                if test "$?" = "0" -a -n "${LIBUSB_VERSION}"; then
 
24
                        CFLAGS="`libusb-config --cflags 2>/dev/null`"
 
25
                        LIBS="`libusb-config --libs 2>/dev/null`"
 
26
                else
 
27
                        LIBUSB_VERSION="none"
 
28
                        CFLAGS=""
 
29
                        LIBS="-lusb"
 
30
                fi
 
31
        fi
 
32
        AC_MSG_RESULT(${LIBUSB_VERSION} found)
 
33
 
 
34
        AC_MSG_CHECKING(for libusb cflags)
 
35
        AC_ARG_WITH(usb-includes,
 
36
                AS_HELP_STRING([@<:@--with-usb-includes=CFLAGS@:>@], [include flags for the libusb library]),
 
37
        [
 
38
                case "${withval}" in
 
39
                yes|no)
 
40
                        AC_MSG_ERROR(invalid option --with(out)-usb-includes - see docs/configure.txt)
 
41
                        ;;
 
42
                *)
 
43
                        CFLAGS="${withval}"
 
44
                        ;;
 
45
                esac
 
46
        ], [])
 
47
        AC_MSG_RESULT([${CFLAGS}])
 
48
 
 
49
        AC_MSG_CHECKING(for libusb ldflags)
 
50
        AC_ARG_WITH(usb-libs,
 
51
                AS_HELP_STRING([@<:@--with-usb-libs=LIBS@:>@], [linker flags for the libusb library]),
 
52
        [
 
53
                case "${withval}" in
 
54
                yes|no)
 
55
                        AC_MSG_ERROR(invalid option --with(out)-usb-libs - see docs/configure.txt)
 
56
                        ;;
 
57
                *)
 
58
                        LIBS="${withval}"
 
59
                        ;;
 
60
                esac
 
61
        ], [])
 
62
        AC_MSG_RESULT([${LIBS}])
 
63
 
 
64
        dnl check if libusb is usable
 
65
        AC_CHECK_HEADERS(usb.h, [nut_have_libusb=yes], [nut_have_libusb=no], [AC_INCLUDES_DEFAULT])
 
66
        AC_CHECK_FUNCS(usb_init, [], [nut_have_libusb=no])
 
67
 
 
68
        if test "${nut_have_libusb}" = "yes"; then
 
69
                dnl Check for libusb "force driver unbind" availability
 
70
                AC_CHECK_FUNCS(usb_detach_kernel_driver_np)
 
71
                LIBUSB_CFLAGS="${CFLAGS}"
 
72
                LIBUSB_LIBS="${LIBS}"
 
73
        fi
 
74
 
 
75
        dnl restore original CFLAGS and LIBS
 
76
        CFLAGS="${CFLAGS_ORIG}"
 
77
        LIBS="${LIBS_ORIG}"
 
78
fi
 
79
])