Skip to content

Commit

Permalink
configure.ac rework
Browse files Browse the repository at this point in the history
- Put libusb and PC/SC check in m4 macros.
- Suppress --disable-pcsclite and --disable-libusb
- Add --with-drivers option: we now could choose which driver to build. without this option a default set is build (ATM all drivers except PN532_UART)
  • Loading branch information
neomilium committed Apr 15, 2010
1 parent b747573 commit b55400a
Show file tree
Hide file tree
Showing 13 changed files with 228 additions and 120 deletions.
95 changes: 8 additions & 87 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ then
fi
AC_SUBST([DEBUG_CFLAGS])

# Handle --with-drivers option
LIBNFC_ARG_WITH_DRIVERS

# Serial autoprobing support (default:no)
AC_ARG_ENABLE([serial-autoprobe],AS_HELP_STRING([--enable-serial-autoprobe],[Allow serial ports to be probed (can seriously disturb connected serial devices)]),[enable_serial_autoprobe=$enableval],[enable_serial_autoprobe="no"])

Expand All @@ -72,30 +75,6 @@ then
CFLAGS="$CFLAGS -DSERIAL_AUTOPROBE_ENABLED"
fi

# PCSC-lite support (default: yes)
AC_ARG_ENABLE([pcsc-lite],AS_HELP_STRING([--disable-pcsc-lite],[Disable PCSC-lite dependency (removes ACR122 support)]),[enable_pcsc_lite=$enableval],[enable_pcsc_lite="yes"])

AC_MSG_CHECKING(for pcsc-lite support)
AC_MSG_RESULT($enable_pcsc_lite)

if test x"$enable_pcsc_lite" = "xno"
then
WITH_PCSC=0
fi
AM_CONDITIONAL(PCSC_LITE_ENABLED, [test x"$enable_pcsc_lite" = xyes])

# libusb support (default: yes)
AC_ARG_ENABLE([libusb],AS_HELP_STRING([--disable-libusb],[Disable libusb dependency (removes PN531USB and PN533USB support)]),[enable_libusb=$enableval],[enable_libusb="yes"])

AC_MSG_CHECKING(for libusb support)
AC_MSG_RESULT($enable_libusb)

if test x"$enable_libusb" = "xno"
then
WITH_LIBUSB=0
fi
AM_CONDITIONAL(LIBUSB_ENABLED, [test x"$enable_libusb" = xyes])

# Documentation (default: no)
AC_ARG_ENABLE([doc],AS_HELP_STRING([--enable-doc],[Enable documentation generation.]),[enable_doc=$enableval],[enable_doc="no"])

Expand All @@ -114,73 +93,15 @@ AM_CONDITIONAL(DOC_ENABLED, [test x"$enable_doc" = xyes])

# Dependencies
PKG_CONFIG_REQUIRES=""
## libusb
if test "x$enable_libusb" = "xyes"; then
WITH_USB=0

# Search using pkg-config
if test x"$PKG_CONFIG" != "x"; then
PKG_CHECK_MODULES([LIBUSB], [libusb], [WITH_USB=1], [WITH_USB=0])
if test x"$WITH_USB" = "x1"; then
if test x"$PKG_CONFIG_REQUIRES" != x""; then
PKG_CONFIG_REQUIRES="$PKG_CONFIG_REQUIRES,"
fi
PKG_CONFIG_REQUIRES="$PKG_CONFIG_REQUIRES libusb"
fi
fi

# Search using libusb-config
if test x"$WITH_USB" = "x0"; then
AC_PATH_PROG(LIBUSB_CONFIG,libusb-config)
if test x"$LIBUSB_CONFIG" != "x" ; then
LIBUSB_CFLAGS=`$LIBUSB_CONFIG --cflags`
LIBUSB_LIBS=`$LIBUSB_CONFIG --libs`
WITH_USB=1
fi
fi

# Search the library and headers directly (last chance)
if test x"$WITH_USB" = "x0"; then
AC_CHECK_HEADER(usb.h, [], [AC_MSG_ERROR([The libusb headers are missing])])
AC_CHECK_LIB(usb, libusb_init, [], [AC_MSG_ERROR([The libusb library is missing])])

LIBUSB_LIBS="-lusb"
WITH_USB=1
fi

if test x"$WITH_USB" = "x0"; then
AC_MSG_ERROR([libusb is mandatory.])
fi

AC_SUBST(LIBUSB_LIBS)
AC_SUBST(LIBUSB_CFLAGS)
fi

## libpcsclite
if test "x$enable_pcsc_lite" = "xyes"; then
case "$host" in
*darwin*)
AC_MSG_WARN(Using darwin PCSC Framework)
LIBPCSCLITE_LIBS="-Wl,-framework,PCSC"
LIBPCSCLITE_CFLAGS="-I/System/Library/Frameworks/PCSC.framework/Headers"
;;
*)
PKG_CHECK_MODULES([LIBPCSCLITE], [libpcsclite], [WITH_PCSC=1], [WITH_PCSC=0])
if test x"$WITH_PCSC" = "x0" ; then
AC_MSG_ERROR([libpcsclite is mandatory.])
fi
if test x"$PKG_CONFIG_REQUIRES" != x""; then
PKG_CONFIG_REQUIRES="$PKG_CONFIG_REQUIRES,"
fi
PKG_CONFIG_REQUIRES="$PKG_CONFIG_REQUIRES libpcsclite"
;;
esac
AC_SUBST(LIBPCSCLITE_LIBS)
AC_SUBST(LIBPCSCLITE_CFLAGS)
fi
LIBNFC_CHECK_LIBUSB
LIBNFC_CHECK_PCSC

AC_SUBST(PKG_CONFIG_REQUIRES)

AM_CONDITIONAL(LIBUSB_ENABLED, [test "$HAVE_LIBUSB" = "1"])
AM_CONDITIONAL(PCSC_ENABLED, [test "$HAVE_PCSC" = "1"])

# Defines and C flags
CFLAGS="$CFLAGS -std=c99"

Expand Down
17 changes: 9 additions & 8 deletions libnfc/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
SUBDIRS = chips buses drivers .

# set the include path found by configure
INCLUDES= $(all_includes) $(LIBNFC_CFLAGS)
INCLUDES = $(all_includes) $(LIBNFC_CFLAGS)

noinst_HEADERS = chips.h buses.h drivers.h bitutils.h
lib_LTLIBRARIES = libnfc.la
libnfc_la_SOURCES = nfc.c bitutils.c
libnfc_la_LDFLAGS = -no-undefined -version-info=0:0:0
libnfc_la_CFLAGS =
libnfc_la_CFLAGS = @DRIVERS_CFLAGS@
libnfc_la_LIBADD = \
$(top_builddir)/libnfc/chips/libnfcchips.la \
$(top_builddir)/libnfc/buses/libnfcbuses.la \
$(top_builddir)/libnfc/drivers/libnfcdrivers.la

if PCSC_LITE_ENABLED
libnfc_la_CFLAGS += @LIBPCSCLITE_CFLAGS@ -DHAVE_PCSC_LITE
libnfc_la_LIBADD += @LIBPCSCLITE_LIBS@
if PCSC_ENABLED
libnfc_la_CFLAGS += @libpcsclite_CFLAGS@ -DHAVE_PCSC
libnfc_la_LIBADD += @libpcsclite_LIBS@
endif

if LIBUSB_ENABLED
libnfc_la_CFLAGS += @LIBUSB_CFLAGS@ -DHAVE_LIBUSB
libnfc_la_LIBADD += @LIBUSB_LIBS@
libnfc_la_CFLAGS += @libusb_CFLAGS@ -DHAVE_LIBUSB
libnfc_la_LIBADD += @libusb_LIBS@
endif

EXTRA_DIST = CMakeLists.txt chips.h buses.h drivers.h bitutils.h
EXTRA_DIST = CMakeLists.txt
43 changes: 30 additions & 13 deletions libnfc/drivers.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,50 @@

#include <nfc/nfc-types.h>

#ifdef HAVE_PCSC_LITE
#if defined (DRIVER_ACR122_ENABLED)
#include "drivers/acr122.h"
#endif /* HAVE_PCSC_LITE */
#endif /* DRIVER_ACR122_ENABLED */

#ifdef HAVE_LIBUSB
#if defined (DRIVER_PN531_USB_ENABLED) || defined (DRIVER_PN533_USB_ENABLED)
#include "drivers/pn53x_usb.h"
#endif /* DRIVER_PN531_USB_ENABLED || DRIVER_PN533_USB_ENABLED */

#if defined (DRIVER_PN531_USB_ENABLED)
#include "drivers/pn531_usb.h"
#endif /* DRIVER_PN531_USB_ENABLED */

#if defined (DRIVER_PN533_USB_ENABLED)
#include "drivers/pn533_usb.h"
#endif /* HAVE_LIBUSB */
#endif /* DRIVER_PN533_USB_ENABLED */

#if defined (DRIVER_ARYGON_ENABLED)
#include "drivers/arygon.h"
#endif /* DRIVER_ARYGON_ENABLED */

#include "drivers/arygon.h"
#include "drivers/pn532_uart.h"
#if defined (DRIVER_PN532_UART_ENABLED)
#include "drivers/pn532_uart.h"
#endif /* DRIVER_PN532_UART_ENABLED */

#define DRIVERS_MAX_DEVICES 16
#define MAX_FRAME_LEN 264

static const struct driver_callbacks drivers_callbacks_list[] = {
// Driver Name Pick Device List Devices Connect Transceive Disconnect
#ifdef HAVE_PCSC_LITE
#if defined (DRIVER_ACR122_ENABLED)
{ ACR122_DRIVER_NAME, acr122_pick_device, acr122_list_devices, acr122_connect, acr122_transceive, acr122_disconnect },
#endif /* HAVE_PCSC_LITE */
#ifdef HAVE_LIBUSB
{ PN531_USB_DRIVER_NAME, pn531_usb_pick_device, pn531_usb_list_devices, pn531_usb_connect, pn53x_usb_transceive, pn53x_usb_disconnect },
{ PN533_USB_DRIVER_NAME, pn533_usb_pick_device, pn533_usb_list_devices, pn533_usb_connect, pn53x_usb_transceive, pn53x_usb_disconnect },
#endif /* HAVE_LIBUSB */
{ PN532_UART_DRIVER_NAME, pn532_uart_pick_device, pn532_uart_list_devices, pn532_uart_connect, pn532_uart_transceive, pn532_uart_disconnect },
#endif /* DRIVER_ACR122_ENABLED */
#if defined (DRIVER_PN531_USB_ENABLED)
{ PN531_USB_DRIVER_NAME, pn531_usb_pick_device, pn531_usb_list_devices, pn531_usb_connect, pn53x_usb_transceive, pn53x_usb_disconnect },
#endif /* DRIVER_PN531_USB_ENABLED */
#if defined (DRIVER_PN533_USB_ENABLED)
{ PN533_USB_DRIVER_NAME, pn533_usb_pick_device, pn533_usb_list_devices, pn533_usb_connect, pn53x_usb_transceive, pn53x_usb_disconnect },
#endif /* DRIVER_PN533_USB_ENABLED */
#if defined (DRIVER_ARYGON_ENABLED)
{ ARYGON_DRIVER_NAME, arygon_pick_device, arygon_list_devices, arygon_connect, arygon_transceive, arygon_disconnect }
#endif /* DRIVER_ARYGON_ENABLED */
#if defined (DRIVER_PN532_UART_ENABLED)
{ PN532_UART_DRIVER_NAME, pn532_uart_pick_device, pn532_uart_list_devices, pn532_uart_connect, pn532_uart_transceive, pn532_uart_disconnect },
#endif /* DRIVER_PN532_UART_ENABLED */
};

#endif // __NFC_DRIVERS_H__
Expand Down
20 changes: 8 additions & 12 deletions libnfc/drivers/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
# set the include path found by configure
INCLUDES= $(all_includes) $(LIBNFC_CFLAGS)

noinst_HEADERS = arygon.h pn532_uart.h
noinst_HEADERS = acr122.h arygon.h pn531_usb.h pn532_uart.h pn533_usb.h pn53x_usb.h
noinst_LTLIBRARIES = libnfcdrivers.la
libnfcdrivers_la_SOURCES = arygon.c pn532_uart.c
libnfcdrivers_la_CFLAGS = -I$(top_srcdir)/libnfc -I$(top_srcdir)/libnfc/buses
libnfcdrivers_la_SOURCES = acr122.c arygon.c pn531_usb.c pn532_uart.c pn533_usb.c pn53x_usb.c
libnfcdrivers_la_CFLAGS = @DRIVERS_CFLAGS@ -I$(top_srcdir)/libnfc -I$(top_srcdir)/libnfc/buses
libnfcdrivers_la_LIBADD =

if PCSC_LITE_ENABLED
noinst_HEADERS += acr122.h
libnfcdrivers_la_CFLAGS += @LIBPCSCLITE_CFLAGS@ -DHAVE_PCSC_LITE
libnfcdrivers_la_SOURCES += acr122.c
libnfcdrivers_la_LIBADD += @LIBPCSCLITE_LIBS@
if PCSC_ENABLED
libnfcdrivers_la_CFLAGS += @libpcsclite_CFLAGS@
libnfcdrivers_la_LIBADD += @libpcsclite_LIBS@
endif

if LIBUSB_ENABLED
noinst_HEADERS += pn531_usb.h pn533_usb.h pn53x_usb.h
libnfcdrivers_la_CFLAGS += @LIBUSB_CFLAGS@ -DHAVE_LIBUSB
libnfcdrivers_la_SOURCES += pn531_usb.c pn533_usb.c pn53x_usb.c
libnfcdrivers_la_LIBADD += @LIBUSB_LIBS@
libnfcdrivers_la_CFLAGS += @libusb_CFLAGS@
libnfcdrivers_la_LIBADD += @libusb_LIBS@
endif

4 changes: 4 additions & 0 deletions libnfc/drivers/acr122.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* @brief
*/

#ifdef DRIVER_ACR122_ENABLED

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif // HAVE_CONFIG_H
Expand Down Expand Up @@ -361,3 +363,5 @@ bool acr122_led_red(const nfc_device_spec_t nds, bool bOn)
}
}

#endif // DRIVER_ACR122_ENABLED

5 changes: 5 additions & 0 deletions libnfc/drivers/arygon.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
* UART connection can be direct (host<->arygon_uc) or could be provided by internal USB to serial interface (e.g. host<->ftdi_chip<->arygon_uc)
*/

#ifdef DRIVER_ARYGON_ENABLED

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif // HAVE_CONFIG_H
Expand Down Expand Up @@ -297,3 +299,6 @@ bool arygon_transceive(const nfc_device_spec_t nds, const byte_t* pbtTx, const s

return true;
}

#endif // DRIVER_ARYGON_ENABLED

5 changes: 5 additions & 0 deletions libnfc/drivers/pn531_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
Thanks to d18c7db and Okko for example code
*/

#ifdef DRIVER_PN531_USB_ENABLED

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif // HAVE_CONFIG_H
Expand Down Expand Up @@ -70,3 +72,6 @@ nfc_device_t* pn531_usb_connect(const nfc_device_desc_t* pndd)
{
return pn53x_usb_connect(pndd, pndd->acDevice, NC_PN531);
}

#endif // DRIVER_PN531_USB_ENABLED

5 changes: 5 additions & 0 deletions libnfc/drivers/pn532_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* @brief PN532 driver using UART bus (UART, RS232, etc.)
*/

#ifdef DRIVER_PN532_UART_ENABLED

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif // HAVE_CONFIG_H
Expand Down Expand Up @@ -310,3 +312,6 @@ pn532_uart_wakeup(const nfc_device_spec_t nds)
}
return true;
}

#endif // DRIVER_PN532_UART_ENABLED

5 changes: 5 additions & 0 deletions libnfc/drivers/pn533_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
Thanks to d18c7db and Okko for example code
*/

#ifdef DRIVER_PN533_USB_ENABLED

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif // HAVE_CONFIG_H
Expand Down Expand Up @@ -68,3 +70,6 @@ nfc_device_t* pn533_usb_connect(const nfc_device_desc_t* pndd)
{
return pn53x_usb_connect(pndd, pndd->acDevice, NC_PN533);
}

#endif // DRIVER_PN533_USB_ENABLED

4 changes: 4 additions & 0 deletions libnfc/drivers/pn53x_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
Thanks to d18c7db and Okko for example code
*/

#if defined (DRIVER_PN531_USB_ENABLED) || defined (DRIVER_PN533_USB_ENABLED)

#include <stdio.h>
#include <stdlib.h>
#include <usb.h>
Expand Down Expand Up @@ -329,3 +331,5 @@ bool pn53x_usb_transceive(const nfc_device_spec_t nds, const byte_t* pbtTx, cons

return true;
}

#endif // DRIVER_PN531_USB_ENABLED || DRIVER_PN533_USB_ENABLED
52 changes: 52 additions & 0 deletions m4/libnfc_check_libusb.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
dnl Check for LIBUSB
dnl On success, HAVE_LIBUSB is set to 1 and PKG_CONFIG_REQUIRES is filled when
dnl libusb is found using pkg-config

AC_DEFUN([LIBNFC_CHECK_LIBUSB],
[
if test x"$libusb_required" = "xyes"; then
HAVE_LIBUSB=0
# Search using pkg-config
if test x"$PKG_CONFIG" != "x"; then
PKG_CHECK_MODULES([libusb], [libusb], [HAVE_LIBUSB=1], [HAVE_LIBUSB=0])
if test x"$HAVE_LIBUSB" = "x1"; then
if test x"$PKG_CONFIG_REQUIRES" != x""; then
PKG_CONFIG_REQUIRES="$PKG_CONFIG_REQUIRES,"
fi
PKG_CONFIG_REQUIRES="$PKG_CONFIG_REQUIRES libusb"
fi
fi
AC_MSG_CHECKING(for libusb)
# Search using libusb-config
if test x"$HAVE_LIBUSB" = "x0"; then
AC_PATH_PROG(libusb_CONFIG,libusb-config)
if test x"$libusb_CONFIG" != "x" ; then
libusb_CFLAGS=`$libusb_CONFIG --cflags`
libusb_LIBS=`$libusb_CONFIG --libs`
HAVE_LIBUSB=1
fi
fi
# Search the library and headers directly (last chance)
if test x"$HAVE_LIBUSB" = "x0"; then
AC_CHECK_HEADER(usb.h, [], [AC_MSG_ERROR([The libusb headers are missing])])
AC_CHECK_LIB(usb, libusb_init, [], [AC_MSG_ERROR([The libusb library is missing])])
libusb_LIBS="-lusb"
HAVE_LIBUSB=1
fi
if test x"$HAVE_LIBUSB" = "x0"; then
AC_MSG_RESULT(no)
AC_MSG_ERROR([libusb is mandatory.])
else
AC_MSG_RESULT(yes)
fi
AC_SUBST(libusb_LIBS)
AC_SUBST(libusb_CFLAGS)
fi
])
Loading

0 comments on commit b55400a

Please sign in to comment.