]> err.no Git - yubikey-personalization.old/commitdiff
Implement autoconf based backend chosing.
authorSimon Josefsson <simon@josefsson.org>
Thu, 7 May 2009 18:18:32 +0000 (18:18 +0000)
committerSimon Josefsson <simon@josefsson.org>
Thu, 7 May 2009 18:18:32 +0000 (18:18 +0000)
configure.ac
ykcore/Makefile.am
ykcore/ykcore.c
ykcore/ykcore_libusb.c

index 6712f0eeaf487e76968d5c7266d596a738e81094..df4475fd961360db2e5bc46af1790bbe76741f50 100644 (file)
@@ -44,17 +44,34 @@ AC_PROG_CC
 AC_LIBTOOL_WIN32_DLL
 AC_PROG_LIBTOOL
 
-AC_LIB_HAVE_LINKFLAGS(usb,, [#include <usb.h>], [usb_init()])
-if test "$ac_cv_libusb" != yes; then
-   AC_MSG_ERROR([libusb not found, please install usb.h and libusb.so])
-fi
-
 AC_LIB_HAVE_LINKFLAGS(yubikey,, [#include <yubikey.h>],
                                [yubikey_modhex_decode(0,0,0)])
 if test "$ac_cv_libyubikey" != yes; then
    AC_MSG_ERROR([libyubikey not found, see http://code.google.com/p/yubico-c/])
 fi
 
+AC_ARG_WITH([backend],
+  [AS_HELP_STRING([--with-backend=ARG],
+    [use specific backend; 'libusb' or 'osx'])])
+AC_MSG_CHECKING([for backend])
+if test x$with_backend != xosx && test x$with_backend != xlibusb; then
+  AC_CANONICAL_HOST
+  case "$host" in
+    *-darwin*) with_backend=osx ;;
+    *) with_backend=libusb ;;
+  esac
+fi
+AC_MSG_RESULT([$with_backend])
+AM_CONDITIONAL([BACKEND_LIBUSB], test x$with_backend = xlibusb)
+AM_CONDITIONAL([BACKEND_OSX], test x$with_backend = xosx)
+
+if test x$with_backend = libusb; then
+  AC_LIB_HAVE_LINKFLAGS(usb,, [#include <usb.h>], [usb_init()])
+  if test "$ac_cv_libusb" != yes; then
+     AC_MSG_ERROR([libusb not found, please install usb.h and libusb.so])
+  fi
+fi
+
 AC_CONFIG_FILES([
   Makefile
   ykcore/Makefile
index cb488dbdf46b7c6b3656d9e0193c7a4cd3b58596..38422a2b3e6c3e7c139fc65ea9481f6ca8da3989 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2008, Yubico AB
+# Copyright (c) 2008, 2009, Yubico AB
 # All rights reserved.
 # 
 # Redistribution and use in source and binary forms, with or without
@@ -29,4 +29,11 @@ noinst_LTLIBRARIES = libykcore.la
 libykcore_la_SOURCES = ykdef.h ykcore.h ykcore_backend.h ykcore.c \
        ykstatus.h ykstatus.c
 libykcore_la_LIBADD = $(LTLIBYUBIKEY)
-EXTRA_DIST = ykcore_libusb.c ykcore_win32.c
+
+if BACKEND_LIBUSB
+libykcore_la_SOURCES += ykcore_libusb.c
+endif
+
+if BACKEND_OSX
+libykcore_la_SOURCES += ykcore_osx.c
+endif
index e35fa6b155a7c905df2458ef14c1a015fcbc196b..8da2b19283e4d9c93ac4c1f5715d0e4cdb7b1e62 100644 (file)
 #include "ykdef.h"
 #include "ykcore_backend.h"
 
-/* Include platform-specific backends for the USB routines */
-#ifdef _WIN32
-# include "ykcore_win32.c"
-#elif defined(__APPLE__)
-# include "ykcore_osx.c"
-#else
-# include "ykcore_libusb.c"
-#endif
-
 #include <yubikey.h>
 
+#ifndef _WIN32
+#define Sleep(x) usleep((x)*1000)
+#endif
+
 int yk_init(void)
 {
        _ykusb_start();
index 144422d406d8cba84456d0bdc69614171c7be053..5f826568ed84a906c9ffb5188397e448f77fe56b 100644 (file)
@@ -1,6 +1,6 @@
 /* -*- mode:C; c-file-style: "bsd" -*- */
 /*
- * Copyright (c) 2008, Yubico AB
+ * Copyright (c) 2008, 2009, Yubico AB
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #include <stdio.h>
 #include <string.h>
 
+#include "ykcore.h"
+#include "ykdef.h"
 #include "ykcore_backend.h"
 
-#ifndef _WIN32
-#define Sleep(x) usleep((x)*1000)
-#endif
-
 #define HID_GET_REPORT                 0x01
 #define HID_SET_REPORT                 0x09