Description: Handle --with-nvml correctly in autotools
 If unset, nvml is enable with default path on both Windows and Linux.
 If set to no, nvml support is disabled during build.
 if set to something else, this name/path will be used in dlopen.
 .
 ccminer-klaust (8.19-2+cuda9) unstable; urgency=medium
 .
   * New patch to handle properly nvml library name from autotools.
   * Pass --with-nvml=libnvidia-ml.so.1 to trigger dlopen on libnvidia-ml for
     hardware monitoring.
Author: Adam Cecile <acecile@le-vert.net>

---
Origin: other
Bug: https://github.com/KlausT/ccminer/issues/190
Forwarded: https://github.com/KlausT/ccminer/issues/190
Last-Update: 2018-01-31

--- ccminer-klaust-8.19.orig/configure.ac
+++ ccminer-klaust-8.19/configure.ac
@@ -143,10 +143,23 @@ dnl Setup CUDA paths
 AC_ARG_WITH([cuda],
    [  --with-cuda=PATH    prefix where cuda is installed [default=/usr/local/cuda]])
 
+# nvml library
+if test "x$have_win32" = xtrue; then
+  # Windows (do not use slashes, else ExpandEnvironmentStrings will mix them)
+  NVML_LIBPATH="%PROGRAMFILES%\\\\NVIDIA Corporation\\\\NVSMI\\\\nvml.dll"
+  m4_define([NVML_LIBPATH_HELP], [nvidia-ml library path/filename [default=%PROGRAMFILES%\\\\NVIDIA Corporation\\\\NVSMI\\\\nvml.dll]])
+else
+  # Should be libnvidia-ml.so.1 ?
+  NVML_LIBPATH="libnvidia-ml.so"
+  m4_define([NVML_LIBPATH_HELP], [nvidia-ml library path/filename [default=libnvidia-ml.so]])
+fi
 AC_ARG_WITH([nvml],
-   [  --with-nvml=PATH    prefix where libnvml is installed [default=/usr/lib]])
+  [AS_HELP_STRING([--with-nvml],
+  NVML_LIBPATH_HELP)],
+  [with_nvml=$withval],
+  [with_nvml=$NVML_LIBPATH])
 
-AM_CONDITIONAL([HAVE_NVML], [test -n "$with_nvml"])
+AM_CONDITIONAL([HAVE_NVML], [test "x$with_nvml" != xno])
 
 NVCC="nvcc"
 
@@ -164,11 +177,13 @@ else
   CUDA_LDFLAGS="-L/usr/local/cuda/lib$SUFFIX"
 fi
 
-if test -n "$with_nvml" ; then
-  NVML_LIBPATH=$with_nvml
+if test "x$with_nvml" != xno ; then
+  if test "x$with_nvml" != xyes ; then
+    NVML_LIBPATH=$with_nvml
+  fi
   CUDA_LDFLAGS="$CUDA_LDFLAGS -ldl"
 fi
-AC_SUBST(NVML_LIBPATH)
+AC_DEFINE_UNQUOTED(NVML_LIBPATH, ["$NVML_LIBPATH"], [nvml library to dlopen])
 
 AC_SUBST(CUDA_CFLAGS)
 AC_SUBST(CUDA_INCLUDES)
--- ccminer-klaust-8.19.orig/nvml.cpp
+++ ccminer-klaust-8.19/nvml.cpp
@@ -15,6 +15,12 @@
  *
  */
 
+#ifndef WIN32
+#include "ccminer-config.h"
+#else
+#include "ccminer-config-win.h"
+#endif
+
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -94,19 +100,11 @@ nvml_handle * nvml_create()
 	int i=0;
 	nvml_handle *nvmlh = NULL;
 
-#ifdef WIN32
-	/* Windows (do not use slashes, else ExpandEnvironmentStrings will mix them) */
-#define  libnvidia_ml "%PROGRAMFILES%\\NVIDIA Corporation\\NVSMI\\nvml.dll"
-#else
-	/* linux assumed */
-#define  libnvidia_ml "libnvidia-ml.so"
-#endif
-
 	char tmp[512];
 #ifdef WIN32
-	ExpandEnvironmentStrings(libnvidia_ml, tmp, sizeof(tmp));
+	ExpandEnvironmentStrings(NVML_LIBPATH, tmp, sizeof(tmp));
 #else
-	strcpy(tmp, libnvidia_ml);
+	strcpy(tmp, NVML_LIBPATH);
 #endif
 
 	void *nvml_dll = wrap_dlopen(tmp);
