Browse Source

Check for Windows DDK headers, and where they are (and build without them if unavailable)

Luke Dashjr 12 years ago
parent
commit
2e7088b640
3 changed files with 47 additions and 11 deletions
  1. 3 1
      Makefile.am
  2. 28 2
      configure.ac
  3. 16 8
      fpgautils.c

+ 3 - 1
Makefile.am

@@ -42,7 +42,6 @@ bin_PROGRAMS	= bfgminer
 
 
 bfgminer_LDFLAGS	= $(PTHREAD_FLAGS)
 bfgminer_LDFLAGS	= $(PTHREAD_FLAGS)
 bfgminer_LDADD	= $(DLOPEN_FLAGS) @LIBCURL_LIBS@ @JANSSON_LIBS@ @PTHREAD_LIBS@ \
 bfgminer_LDADD	= $(DLOPEN_FLAGS) @LIBCURL_LIBS@ @JANSSON_LIBS@ @PTHREAD_LIBS@ \
-		  @AUTOSCAN_LIBS@ \
 		  @NCURSES_LIBS@ @PDCURSES_LIBS@ @WS2_LIBS@ \
 		  @NCURSES_LIBS@ @PDCURSES_LIBS@ @WS2_LIBS@ \
 		  @UDEV_LIBS@ @LIBUSB_LIBS@ @MM_LIBS@ @RT_LIBS@ \
 		  @UDEV_LIBS@ @LIBUSB_LIBS@ @MM_LIBS@ @RT_LIBS@ \
 		  @MATH_LIBS@ lib/libgnu.a ccan/libccan.a
 		  @MATH_LIBS@ lib/libgnu.a ccan/libccan.a
@@ -54,6 +53,9 @@ bfgminer_CPPFLAGS += @JANSSON_CFLAGS@
 bfgminer_CPPFLAGS += $(PTHREAD_FLAGS)
 bfgminer_CPPFLAGS += $(PTHREAD_FLAGS)
 bfgminer_CPPFLAGS += $(NCURSES_CPPFLAGS)
 bfgminer_CPPFLAGS += $(NCURSES_CPPFLAGS)
 
 
+bfgminer_CPPFLAGS += $(AUTOSCAN_CPPFLAGS)
+bfgminer_LDADD += $(AUTOSCAN_LIBS)
+
 bfgminer_LDADD += $(libblkmaker_LIBS)
 bfgminer_LDADD += $(libblkmaker_LIBS)
 bfgminer_LDFLAGS += $(libblkmaker_LDFLAGS)
 bfgminer_LDFLAGS += $(libblkmaker_LDFLAGS)
 bfgminer_CPPFLAGS += $(libblkmaker_CFLAGS)
 bfgminer_CPPFLAGS += $(libblkmaker_CFLAGS)

+ 28 - 2
configure.ac

@@ -115,6 +115,7 @@ need_lowlevel=no
 have_cygwin=false
 have_cygwin=false
 have_win32=false
 have_win32=false
 have_macho=false
 have_macho=false
+AUTOSCAN_CPPFLAGS=""
 AUTOSCAN_LIBS=""
 AUTOSCAN_LIBS=""
 DLOPEN_FLAGS="-ldl"
 DLOPEN_FLAGS="-ldl"
 WS2_LIBS=""
 WS2_LIBS=""
@@ -142,7 +143,6 @@ esac
 case $target in
 case $target in
   *-*-mingw*)
   *-*-mingw*)
     have_win32=true
     have_win32=true
-    AUTOSCAN_LIBS="-lsetupapi"
     DLOPEN_FLAGS=""
     DLOPEN_FLAGS=""
     WS2_LIBS="-lws2_32"
     WS2_LIBS="-lws2_32"
     MM_LIBS="-lwinmm"
     MM_LIBS="-lwinmm"
@@ -716,6 +716,30 @@ if test x$need_fpgautils = xyes; then
 	
 	
 	if $have_win32; then
 	if $have_win32; then
 		echo '#include <iospeeds.h>' >iospeeds_local.h
 		echo '#include <iospeeds.h>' >iospeeds_local.h
+		
+		found_ddkusb=false
+		AC_CHECK_HEADER([usbiodef.h],[
+			found_ddkusb=true
+		],[
+			AC_CHECK_HEADER([ddk/usbiodef.h],[
+				found_ddkusb=true
+				AUTOSCAN_CPPFLAGS="-I"`echo '#include <ddk/usbiodef.h>' | ${CPP} -M - 2>/dev/null | tr -d '\\n\\r\\\\' | sed -e 's/^.*[[:space:]:]\(\/[^[:space:]]*\)usbiodef\.h[[:space:]].*$/\1/' -e t -e d`
+			],[
+				true
+			],[
+				#include <windows.h>
+				#include <ddk/usbioctl.h>
+				AC_INCLUDES_DEFAULT
+			])
+		],[
+			#include <windows.h>
+			#include <usbioctl.h>
+			AC_INCLUDES_DEFAULT
+		])
+		if $found_ddkusb; then
+			AUTOSCAN_LIBS="-lsetupapi"
+			AC_DEFINE([HAVE_WIN_DDKUSB],[1],[Defined to 1 if Windows DDK USB headers are being used])
+		fi
 	else
 	else
 		AC_MSG_CHECKING([what baud rates your system supports])
 		AC_MSG_CHECKING([what baud rates your system supports])
 		echo '#include <termios.h>' | ${CPP} -dM - 2>/dev/null | sed 's/.*[ 	]B\([0-9][0-9]*\)[ 	].*/IOSPEED(\1)/' | grep IOSPEED >iospeeds_local.h
 		echo '#include <termios.h>' | ${CPP} -dM - 2>/dev/null | sed 's/.*[ 	]B\([0-9][0-9]*\)[ 	].*/IOSPEED(\1)/' | grep IOSPEED >iospeeds_local.h
@@ -892,6 +916,7 @@ AM_CONDITIONAL([HAVE_SENSORS], [test x$with_sensors = xyes])
 AM_CONDITIONAL([HAVE_CYGWIN], [test x$have_cygwin = xtrue])
 AM_CONDITIONAL([HAVE_CYGWIN], [test x$have_cygwin = xtrue])
 AM_CONDITIONAL([HAVE_WINDOWS], [test x$have_win32 = xtrue])
 AM_CONDITIONAL([HAVE_WINDOWS], [test x$have_win32 = xtrue])
 AM_CONDITIONAL([HAVE_x86_64], [test x$have_x86_64 = xtrue])
 AM_CONDITIONAL([HAVE_x86_64], [test x$have_x86_64 = xtrue])
+AM_CONDITIONAL([HAVE_WIN_DDKUSB], [test x$found_ddkusb = xtrue])
 AM_CONDITIONAL([HAS_FPGA], [test x$bitforce$icarus$modminer$x6500$ztex != xnonononono])
 AM_CONDITIONAL([HAS_FPGA], [test x$bitforce$icarus$modminer$x6500$ztex != xnonononono])
 AM_CONDITIONAL([HAS_ASIC], [test x$avalon$bfsb$bigpic$icarus$httpsrv$metabank != xnononononono])
 AM_CONDITIONAL([HAS_ASIC], [test x$avalon$bfsb$bigpic$icarus$httpsrv$metabank != xnononononono])
 
 
@@ -1223,6 +1248,7 @@ AC_DEFINE_UNQUOTED([DIABLO_KERNNAME], ["diablo130302"], [Filename for diablo ker
 AC_DEFINE_UNQUOTED([SCRYPT_KERNNAME], ["scrypt130511"], [Filename for scrypt kernel])
 AC_DEFINE_UNQUOTED([SCRYPT_KERNNAME], ["scrypt130511"], [Filename for scrypt kernel])
 
 
 
 
+AC_SUBST(AUTOSCAN_CPPFLAGS)
 AC_SUBST(AUTOSCAN_LIBS)
 AC_SUBST(AUTOSCAN_LIBS)
 AC_SUBST(PTHREAD_FLAGS)
 AC_SUBST(PTHREAD_FLAGS)
 AC_SUBST(DLOPEN_FLAGS)
 AC_SUBST(DLOPEN_FLAGS)
@@ -1296,7 +1322,7 @@ BFG_PRINT_LIST([Options...],[optlist])
 
 
 echo
 echo
 echo "Compilation............: make (or gmake)"
 echo "Compilation............: make (or gmake)"
-echo "  CFLAGS...............: $CPPFLAGS $NCURSES_CPPFLAGS $PTHREAD_FLAGS $CFLAGS $LIBUSB_CFLAGS $JANSSON_CFLAGS $PTHREAD_FLAGS $libblkmaker_CFLAGS $hidapi_CFLAGS"
+echo "  CFLAGS...............: $CPPFLAGS $AUTOSCAN_CPPFLAGS $NCURSES_CPPFLAGS $PTHREAD_FLAGS $CFLAGS $LIBUSB_CFLAGS $JANSSON_CFLAGS $PTHREAD_FLAGS $libblkmaker_CFLAGS $hidapi_CFLAGS"
 echo "  LDFLAGS..............: $LDFLAGS $AUTOSCAN_LIBS $PTHREAD_FLAGS $libblkmaker_LDFLAGS $PTHREAD_LIBS $LIBS $DLOPEN_FLAGS $LIBCURL_LIBS $JANSSON_LIBS $NCURSES_LIBS $PDCURSES_LIBS $WS2_LIBS $MATH_LIBS $UDEV_LIBS $LIBUSB_LIBS $RT_LIBS $sensors_LIBS $libblkmaker_LIBS"
 echo "  LDFLAGS..............: $LDFLAGS $AUTOSCAN_LIBS $PTHREAD_FLAGS $libblkmaker_LDFLAGS $PTHREAD_LIBS $LIBS $DLOPEN_FLAGS $LIBCURL_LIBS $JANSSON_LIBS $NCURSES_LIBS $PDCURSES_LIBS $WS2_LIBS $MATH_LIBS $UDEV_LIBS $LIBUSB_LIBS $RT_LIBS $sensors_LIBS $libblkmaker_LIBS"
 echo
 echo
 echo "Installation...........: make install$maybe_ldconfig #(as root if needed, with 'su' or 'sudo')"
 echo "Installation...........: make install$maybe_ldconfig #(as root if needed, with 'su' or 'sudo')"

+ 16 - 8
fpgautils.c

@@ -46,10 +46,13 @@
 #endif
 #endif
 #else  /* WIN32 */
 #else  /* WIN32 */
 #include <windows.h>
 #include <windows.h>
+
+#ifdef HAVE_WIN_DDKUSB
 #include <setupapi.h>
 #include <setupapi.h>
+#include <usbioctl.h>
+#include <usbiodef.h>
+#endif
 
 
-#include <ddk/usbioctl.h>
-#include <ddk/usbiodef.h>
 #include <io.h>
 #include <io.h>
 
 
 #include <utlist.h>
 #include <utlist.h>
@@ -80,6 +83,8 @@ enum {
 
 
 #include "logging.h"
 #include "logging.h"
 #include "miner.h"
 #include "miner.h"
+#include "util.h"
+
 #include "fpgautils.h"
 #include "fpgautils.h"
 
 
 #define SEARCH_NEEDLES_BEGIN()  {  \
 #define SEARCH_NEEDLES_BEGIN()  {  \
@@ -384,7 +389,7 @@ int _serial_autodetect_sysfs(detectone_func_t detectone, va_list needles)
 #	define _serial_autodetect_sysfs(...)  (0)
 #	define _serial_autodetect_sysfs(...)  (0)
 #endif
 #endif
 
 
-#ifdef WIN32
+#ifdef HAVE_WIN_DDKUSB
 
 
 static const GUID WIN_GUID_DEVINTERFACE_USB_HOST_CONTROLLER = { 0x3ABF6F2D, 0x71C4, 0x462A, {0x8A, 0x92, 0x1E, 0x68, 0x61, 0xE6, 0xAF, 0x27} };
 static const GUID WIN_GUID_DEVINTERFACE_USB_HOST_CONTROLLER = { 0x3ABF6F2D, 0x71C4, 0x462A, {0x8A, 0x92, 0x1E, 0x68, 0x61, 0xE6, 0xAF, 0x27} };
 
 
@@ -413,7 +418,7 @@ char *windows_usb_get_port_path(HANDLE hubh, const int portno)
 	if (!(DeviceIoControl(hubh, IOCTL_USB_GET_NODE_CONNECTION_NAME, path, bufsz, path, bufsz, &rsz, NULL) && rsz >= sizeof(*path)))
 	if (!(DeviceIoControl(hubh, IOCTL_USB_GET_NODE_CONNECTION_NAME, path, bufsz, path, bufsz, &rsz, NULL) && rsz >= sizeof(*path)))
 		applogfailinfor(NULL, LOG_ERR, "ioctl (2)", "%s", bfg_strerror(GetLastError(), BST_SYSTEM));
 		applogfailinfor(NULL, LOG_ERR, "ioctl (2)", "%s", bfg_strerror(GetLastError(), BST_SYSTEM));
 	
 	
-	return ucs2to8bit_dup(path->NodeName, path->ActualLength);
+	return ucs2tochar_dup(path->NodeName, path->ActualLength);
 }
 }
 
 
 static
 static
@@ -446,7 +451,7 @@ char *windows_usb_get_string(HANDLE hubh, const int portno, const uint8_t descid
 	if (descsz < 2 || desc->bDescriptorType != USB_STRING_DESCRIPTOR_TYPE || desc->bLength > descsz - sizeof(USB_DESCRIPTOR_REQUEST) || desc->bLength % 2)
 	if (descsz < 2 || desc->bDescriptorType != USB_STRING_DESCRIPTOR_TYPE || desc->bLength > descsz - sizeof(USB_DESCRIPTOR_REQUEST) || desc->bLength % 2)
 		applogfailr(NULL, LOG_ERR, "sanity check");
 		applogfailr(NULL, LOG_ERR, "sanity check");
 	
 	
-	return ucs2to8bit_dup(desc->bString, desc->bLength);
+	return ucs2tochar_dup(desc->bString, desc->bLength);
 }
 }
 
 
 static void _serial_autodetect_windows__hub(detectone_func_t, va_list, int *, const char *);
 static void _serial_autodetect_windows__hub(detectone_func_t, va_list, int *, const char *);
@@ -577,7 +582,7 @@ char *windows_usb_get_root_hub_path(HANDLE hcntlrh)
 	if (!(DeviceIoControl(hcntlrh, IOCTL_USB_GET_ROOT_HUB_NAME, NULL, 0, hubpath, bufsz, &rsz, NULL) && rsz >= sizeof(*hubpath)))
 	if (!(DeviceIoControl(hcntlrh, IOCTL_USB_GET_ROOT_HUB_NAME, NULL, 0, hubpath, bufsz, &rsz, NULL) && rsz >= sizeof(*hubpath)))
 		applogfailinfor(NULL, LOG_ERR, "ioctl (2)", "%s", bfg_strerror(GetLastError(), BST_SYSTEM));
 		applogfailinfor(NULL, LOG_ERR, "ioctl (2)", "%s", bfg_strerror(GetLastError(), BST_SYSTEM));
 	
 	
-	return ucs2to8bit_dup(hubpath->RootHubName, hubpath->ActualLength);
+	return ucs2tochar_dup(hubpath->RootHubName, hubpath->ActualLength);
 }
 }
 
 
 static
 static
@@ -621,7 +626,10 @@ int _serial_autodetect_windows(detectone_func_t detectone, va_list needles)
 	return found;
 	return found;
 }
 }
 
 
+#endif
+
 
 
+#ifdef WIN32
 #define LOAD_SYM(sym)  do { \
 #define LOAD_SYM(sym)  do { \
 	if (!(sym = dlsym(dll, #sym))) {  \
 	if (!(sym = dlsym(dll, #sym))) {  \
 		applog(LOG_DEBUG, "Failed to load " #sym ", not using FTDI autodetect");  \
 		applog(LOG_DEBUG, "Failed to load " #sym ", not using FTDI autodetect");  \
@@ -729,10 +737,10 @@ int _serial_autodetect(detectone_func_t detectone, ...)
 		_serial_autodetect_udev     (detectone, needles) ?:
 		_serial_autodetect_udev     (detectone, needles) ?:
 		_serial_autodetect_sysfs    (detectone, needles) ?:
 		_serial_autodetect_sysfs    (detectone, needles) ?:
 		_serial_autodetect_devserial(detectone, needles) ?:
 		_serial_autodetect_devserial(detectone, needles) ?:
-#ifdef WIN32
+#ifdef HAVE_WIN_DDKUSB
 		_serial_autodetect_windows  (detectone, needles) ?:
 		_serial_autodetect_windows  (detectone, needles) ?:
-		_serial_autodetect_ftdi     (detectone, needles) ?:
 #endif
 #endif
+		_serial_autodetect_ftdi     (detectone, needles) ?:
 		0);
 		0);
 	va_end(needles);
 	va_end(needles);
 	return rv;
 	return rv;