diff options
author | Pete Batard <pbatard@gmail.com> | 2010-01-15 01:19:47 +0000 |
---|---|---|
committer | Pete Batard <pbatard@gmail.com> | 2010-01-15 01:19:47 +0000 |
commit | 3cb9ac7d88f2d7513b2b914510cd16def8eb8e1e (patch) | |
tree | 40c5d20c264e735de7c215f5ce9cb39231545997 | |
parent | 1626ee00424d3f9b90db1b9fc3834cfbbadda465 (diff) | |
download | libusb-3cb9ac7d88f2d7513b2b914510cd16def8eb8e1e.tar.gz |
r76: added cygwin support
- use AM_CFLAGS instead of CFLAGS (configure.ac)
- added -Werror in visibility attribute test to properly detect on cygwin (configure.ac)
- moved -Wshadow to AM_CFLAGS and disabled it on cygwin (configure.ac)
- emulated _open_osfhandle in windows_compat.c
- removed unneeded <tchar> include in windows_usb.c
-rw-r--r-- | configure.ac | 20 | ||||
-rw-r--r-- | libusb/os/windows_compat.c | 24 | ||||
-rw-r--r-- | libusb/os/windows_usb.c | 1 |
3 files changed, 39 insertions, 6 deletions
diff --git a/configure.ac b/configure.ac index 441370f..5aea8b2 100644 --- a/configure.ac +++ b/configure.ac @@ -20,7 +20,7 @@ case $host in AC_MSG_RESULT([Linux]) backend="linux" AC_CHECK_LIB(rt, clock_gettime) - CFLAGS="-pthread" + AM_CFLAGS="-pthread -Wshadow" AM_LDFLAGS="" ;; *-darwin*) @@ -29,7 +29,7 @@ case $host in AC_DEFINE(USBI_OS_HANDLES_TIMEOUT, [], [Backend handles timeout]) AC_MSG_RESULT([Darwin/MacOS X]) backend="darwin" - CFLAGS="-pthread" + AM_CFLAGS="-pthread -Wshadow" AM_LDFLAGS="-Wl,-framework -Wl,IOKit -Wl,-framework -Wl,CoreFoundation -Wl,-prebind -no-undefined" ;; *-mingw*) @@ -38,9 +38,18 @@ case $host in AC_MSG_RESULT([Windows]) backend="windows" LIBS="-lpthreadGC2 -lsetupapi -lole32" - CFLAGS="" + AM_CFLAGS="-Wshadow" AM_LDFLAGS="" ;; +*-cygwin*) + AC_DEFINE(OS_WINDOWS, [], [Windows backend]) + AC_SUBST(OS_WINDOWS) + AC_MSG_RESULT([Windows]) + backend="windows" + LIBS="-lpthread -lsetupapi -lole32" + AM_CFLAGS="" + AM_LDFLAGS="" + ;; *) AC_MSG_ERROR([unsupported operating system]) esac @@ -116,7 +125,8 @@ CFLAGS="$saved_cflags" # check for -fvisibility=hidden compiler support (GCC >= 3.4) saved_cflags="$CFLAGS" -CFLAGS="$CFLAGS -fvisibility=hidden" +# -Werror required for cygwin +CFLAGS="$CFLAGS -Werror -fvisibility=hidden" AC_COMPILE_IFELSE(AC_LANG_PROGRAM([]), [VISIBILITY_CFLAGS="-fvisibility=hidden" AC_DEFINE([API_EXPORTED], [__attribute__((visibility("default")))], [Default visibility]) ], @@ -132,7 +142,7 @@ AC_COMPILE_IFELSE(AC_LANG_PROGRAM([]), nopointersign_cflags="-Wno-pointer-sign", nopointersign_cflags="") CFLAGS="$saved_cflags" -AM_CFLAGS="-std=gnu99 $inline_cflags -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration $nopointersign_cflags -Wshadow" +AM_CFLAGS="$AM_CFLAGS -std=gnu99 $inline_cflags -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration $nopointersign_cflags" AC_SUBST(VISIBILITY_CFLAGS) AC_SUBST(AM_CFLAGS) diff --git a/libusb/os/windows_compat.c b/libusb/os/windows_compat.c index 641ef15..711d553 100644 --- a/libusb/os/windows_compat.c +++ b/libusb/os/windows_compat.c @@ -88,6 +88,30 @@ #endif #endif +#if defined(__CYGWIN__ ) +// _open_osfhandle() is not available on cygwin, but we can emulate +// it for our needs with cygwin_attach_handle_to_fd() +static inline int _open_osfhandle(intptr_t osfhandle, int flags) +{ + int access; + switch (flags) { + case _O_RDONLY: + access = GENERIC_READ; + break; + case _O_WRONLY: + access = GENERIC_WRITE; + break; + case _O_RDWR: + access = GENERIC_READ|GENERIC_WRITE; + break; + default: + printb("_open_osfhandle (emulated): unuspported access mode\n"); + return -1; + } + return cygwin_attach_handle_to_fd("/dev/null", -1, osfhandle, -1, access); +} +#endif + #define CHECK_INIT_POLLING do {if(!is_polling_set) init_polling();} while(0) // public fd data diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c index fb14cd0..d628e1f 100644 --- a/libusb/os/windows_usb.c +++ b/libusb/os/windows_usb.c @@ -37,7 +37,6 @@ #include <pthread.h> #include <stdio.h> #include <windows.h> -#include <tchar.h> #include <setupapi.h> #if defined(_MSC_VER) // Fixes DDK errors |