Commit 5ea6a8eaa2d449f4809623d8a70ffe59e7764ed8

Con Kolivas 2013-10-23T22:45:56

Merge branch 'master' into hashfast Conflicts: Makefile.am

diff --git a/Makefile.am b/Makefile.am
index 7448600..8eedeb6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -22,8 +22,6 @@ INCLUDES	= $(PTHREAD_FLAGS) -fno-strict-aliasing $(JANSSON_INCLUDES) $(USBUTILS_
 
 bin_PROGRAMS	= cgminer
 
-bin_SCRIPTS	= $(top_srcdir)/*.cl
-
 cgminer_LDFLAGS	= $(PTHREAD_FLAGS)
 cgminer_LDADD	= $(DLOPEN_FLAGS) @LIBCURL_LIBS@ @JANSSON_LIBS@ @PTHREAD_LIBS@ \
 		  @OPENCL_LIBS@ @NCURSES_LIBS@ @PDCURSES_LIBS@ @WS2_LIBS@ \
@@ -47,11 +45,10 @@ cgminer_SOURCES	+= elist.h miner.h compat.h bench_block.h	\
 
 cgminer_SOURCES	+= logging.c
 
-# GPU sources, TODO: make them selectable
-# the GPU portion extracted from original main.c
-cgminer_SOURCES += driver-opencl.h driver-opencl.c
+if HAS_OPENCL
+bin_SCRIPTS	= $(top_srcdir)/*.cl
 
-# the original GPU related sources, unchanged
+cgminer_SOURCES += driver-opencl.h driver-opencl.c
 cgminer_SOURCES += ocl.c ocl.h findnonce.c findnonce.h
 cgminer_SOURCES += adl.c adl.h adl_functions.h
 cgminer_SOURCES += *.cl
@@ -60,7 +57,8 @@ if HAS_SCRYPT
 cgminer_SOURCES += scrypt.c scrypt.h
 endif
 
-# Extra utilities required
+endif
+
 if NEED_FPGAUTILS
 cgminer_SOURCES += fpgautils.c fpgautils.h
 endif
diff --git a/cgminer.c b/cgminer.c
index b3dacae..850d6f0 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -4975,8 +4975,10 @@ static void *input_thread(void __maybe_unused *userdata)
 			display_pools();
 		else if (!strncasecmp(&input, "s", 1))
 			set_options();
+#if HAVE_OPENCL
 		else if (have_opencl && !strncasecmp(&input, "g", 1))
 			manage_gpu();
+#endif
 		if (opt_realquiet) {
 			disable_curses();
 			break;
diff --git a/compat/Makefile.am b/compat/Makefile.am
index 4ed10f8..4cd32d2 100644
--- a/compat/Makefile.am
+++ b/compat/Makefile.am
@@ -2,5 +2,7 @@
 SUBDIRS	= jansson-2.5
 
 if WANT_USBUTILS
+if WANT_STATIC_LIBUSB
 SUBDIRS += libusb-1.0
 endif
+endif
diff --git a/configure.ac b/configure.ac
index 27c68ba..e0bc70a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -135,10 +135,10 @@ if test -n "$CGMINER_SDK"; then
 	LDFLAGS="-L$CGMINER_SDK/lib/$target $LDFLAGS"
 fi
 
-opencl="yes"
+opencl="no"
 
 AC_ARG_ENABLE([opencl],
-	[AC_HELP_STRING([--disable-opencl],[Override detection and disable building with opencl])],
+	[AC_HELP_STRING([--enable-opencl],[Enable support for GPU mining with opencl])],
 	[opencl=$enableval]
 	)
 if test "x$opencl" != xno; then
@@ -171,6 +171,7 @@ else
 	OPENCL_FLAGS=""
 	OPENCL_LIBS=""
 fi
+AM_CONDITIONAL([HAS_OPENCL], [test x$opencl = xyes])
 
 has_winpthread=false
 if test "x$have_win32" = xtrue; then
@@ -344,21 +345,42 @@ AM_CONDITIONAL([HAVE_CURSES], [test x$curses = xyes])
 AM_CONDITIONAL([HAVE_WINDOWS], [test x$have_win32 = xtrue])
 AM_CONDITIONAL([HAVE_x86_64], [test x$have_x86_64 = xtrue])
 
-AC_CONFIG_SUBDIRS([compat/libusb-1.0])
 if test "x$want_usbutils" != xfalse; then
+	dlibusb="no"
 	AC_DEFINE([USE_USBUTILS], [1], [Defined to 1 if usbutils support required])
-	LIBUSB_LIBS="compat/libusb-1.0/libusb/.libs/libusb-1.0.a"
-	if test "x$have_linux" = "xtrue"; then
-		PKG_CHECK_MODULES([UDEV], [libudev], LIBUSB_LIBS+=" -ludev", [AC_MSG_ERROR([Missing required libudev dev])])
-	fi
-	if test "x$have_darwin" = "xtrue"; then
-		LIBUSB_LIBS+=" -lobjc"
-		LDFLAGS+=" -framework CoreFoundation -framework IOKit"
+	AC_ARG_WITH([system-libusb],
+		[AC_HELP_STRING([--with-system-libusb],[Compile against dynamic system libusb (default use included static libusb)])],
+		[dlibusb=$withval]
+	)
+
+	if test "x$dlibusb" != xno; then
+		case $target in
+			*-*-freebsd*)
+				LIBUSB_LIBS="-lusb"
+				LIBUSB_CFLAGS=""
+				AC_DEFINE(HAVE_LIBUSB, 1, [Define if you have libusb-1.0])
+				;;
+			*)
+				PKG_CHECK_MODULES(LIBUSB, libusb-1.0, [AC_DEFINE(HAVE_LIBUSB, 1, [Define if you have libusb-1.0])], [AC_MSG_ERROR([Could not find usb library - please install libusb-1.0])])
+				;;
+		esac
+	else
+		AC_CONFIG_SUBDIRS([compat/libusb-1.0])
+		LIBUSB_LIBS="compat/libusb-1.0/libusb/.libs/libusb-1.0.a"
+		if test "x$have_linux" = "xtrue"; then
+			LIBUSB_LIBS+=" -ludev"
+		fi
+		if test "x$have_darwin" = "xtrue"; then
+			LIBUSB_LIBS+=" -lobjc"
+			LDFLAGS+=" -framework CoreFoundation -framework IOKit"
+		fi
 	fi
 else
 	LIBUSB_LIBS=""
 fi
 
+AM_CONDITIONAL([WANT_STATIC_LIBUSB], [test x$dlibusb = xno])
+
 AC_CONFIG_SUBDIRS([compat/jansson-2.5])
 JANSSON_LIBS="compat/jansson-2.5/src/.libs/libjansson.a"
 
diff --git a/miner.h b/miner.h
index 6f2ff63..00eeb82 100644
--- a/miner.h
+++ b/miner.h
@@ -886,6 +886,13 @@ static inline void _mutex_init(pthread_mutex_t *lock, const char *file, const ch
 	INITLOCK(lock, CGLOCK_MUTEX, file, func, line);
 }
 
+static inline void mutex_destroy(pthread_mutex_t *lock)
+{
+	/* Ignore return code. This only invalidates the mutex on linux but
+	 * releases resources on windows. */
+	pthread_mutex_destroy(lock);
+}
+
 static inline void _rwlock_init(pthread_rwlock_t *lock, const char *file, const char *func, const int line)
 {
 	if (unlikely(pthread_rwlock_init(lock, NULL)))
@@ -893,12 +900,23 @@ static inline void _rwlock_init(pthread_rwlock_t *lock, const char *file, const 
 	INITLOCK(lock, CGLOCK_RW, file, func, line);
 }
 
+static inline void rwlock_destroy(pthread_rwlock_t *lock)
+{
+	pthread_rwlock_destroy(lock);
+}
+
 static inline void _cglock_init(cglock_t *lock, const char *file, const char *func, const int line)
 {
 	_mutex_init(&lock->mutex, file, func, line);
 	_rwlock_init(&lock->rwlock, file, func, line);
 }
 
+static inline void cglock_destroy(cglock_t *lock)
+{
+	rwlock_destroy(&lock->rwlock);
+	mutex_destroy(&lock->mutex);
+}
+
 /* Read lock variant of cglock. Cannot be promoted. */
 static inline void _cg_rlock(cglock_t *lock, const char *file, const char *func, const int line)
 {