From 83b7a5555b8fe49a951433265387cb32a7ca4ad9 Mon Sep 17 00:00:00 2001 From: simon75j Date: Thu, 7 May 2009 18:18:32 +0000 Subject: [PATCH] Implement autoconf based backend chosing. git-svn-id: https://yubikey-personalization.googlecode.com/svn/trunk@66 b62f149e-849f-11dd-9899-c7ba65f7c4c7 --- configure.ac | 27 ++++++++++++++++++++++----- ykcore/Makefile.am | 11 +++++++++-- ykcore/ykcore.c | 13 ++++--------- ykcore/ykcore_libusb.c | 8 +++----- 4 files changed, 38 insertions(+), 21 deletions(-) diff --git a/configure.ac b/configure.ac index 6712f0e..df4475f 100644 --- a/configure.ac +++ b/configure.ac @@ -44,17 +44,34 @@ AC_PROG_CC AC_LIBTOOL_WIN32_DLL AC_PROG_LIBTOOL -AC_LIB_HAVE_LINKFLAGS(usb,, [#include ], [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_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_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 diff --git a/ykcore/Makefile.am b/ykcore/Makefile.am index cb488db..38422a2 100644 --- a/ykcore/Makefile.am +++ b/ykcore/Makefile.am @@ -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 diff --git a/ykcore/ykcore.c b/ykcore/ykcore.c index e35fa6b..8da2b19 100644 --- a/ykcore/ykcore.c +++ b/ykcore/ykcore.c @@ -32,17 +32,12 @@ #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 +#ifndef _WIN32 +#define Sleep(x) usleep((x)*1000) +#endif + int yk_init(void) { _ykusb_start(); diff --git a/ykcore/ykcore_libusb.c b/ykcore/ykcore_libusb.c index 144422d..5f82656 100644 --- a/ykcore/ykcore_libusb.c +++ b/ykcore/ykcore_libusb.c @@ -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 @@ -32,12 +32,10 @@ #include #include +#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 -- 2.39.5