Browse Source

Initial Cygwin port

Compiles and CPU mines, at least
Luke Dashjr 13 years ago
parent
commit
26459c5f13
8 changed files with 63 additions and 17 deletions
  1. 1 1
      ADL/adl_sdk.h
  2. 11 0
      Makefile.am
  3. 13 10
      adl.c
  4. 1 1
      adl_functions.h
  5. 3 1
      api.c
  6. 25 2
      configure.ac
  7. 8 1
      driver-cairnsmore.c
  8. 1 1
      libblkmaker

+ 1 - 1
ADL/adl_sdk.h

@@ -24,7 +24,7 @@
 #include "adl_structures.h"
 #include "adl_structures.h"
 
 
 typedef void*(
 typedef void*(
-#ifdef WIN32
+#ifdef __stdcall
 	__stdcall
 	__stdcall
 #endif
 #endif
 *ADL_MAIN_MALLOC_CALLBACK)(int);
 *ADL_MAIN_MALLOC_CALLBACK)(int);

+ 11 - 0
Makefile.am

@@ -22,18 +22,29 @@ bfgminer_LDADD	= $(DLOPEN_FLAGS) @LIBCURL_LIBS@ @JANSSON_LIBS@ @PTHREAD_LIBS@ \
 		  @MATH_LIBS@ lib/libgnu.a ccan/libccan.a
 		  @MATH_LIBS@ lib/libgnu.a ccan/libccan.a
 bfgminer_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib
 bfgminer_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib
 
 
+bfgminer_CPPFLAGS += $(NCURSES_CPPFLAGS)
+
 # common sources
 # common sources
 bfgminer_SOURCES := miner.c
 bfgminer_SOURCES := miner.c
 
 
 bfgminer_SOURCES	+= elist.h miner.h compat.h bench_block.h	\
 bfgminer_SOURCES	+= elist.h miner.h compat.h bench_block.h	\
 		   util.c uthash.h logging.h			\
 		   util.c uthash.h logging.h			\
 		   sha2.c sha2.h api.c
 		   sha2.c sha2.h api.c
+bfgminer_DEPENDENCIES =
 
 
 if NEED_LIBBLKMAKER
 if NEED_LIBBLKMAKER
 SUBDIRS           += libblkmaker
 SUBDIRS           += libblkmaker
 bfgminer_CPPFLAGS += -Ilibblkmaker
 bfgminer_CPPFLAGS += -Ilibblkmaker
 bfgminer_LDFLAGS  += -Llibblkmaker/.libs -Wl,-rpath,libblkmaker/.libs
 bfgminer_LDFLAGS  += -Llibblkmaker/.libs -Wl,-rpath,libblkmaker/.libs
 bfgminer_LDADD    += -lblkmaker-0.1 -lblkmaker_jansson-0.1
 bfgminer_LDADD    += -lblkmaker-0.1 -lblkmaker_jansson-0.1
+
+if HAVE_CYGWIN
+bfgminer_DEPENDENCIES += cygblkmaker-0.1-0.dll cygblkmaker_jansson-0.1-0.dll
+
+cyg%.dll: libblkmaker/.libs/cyg%.dll
+	cp -p $< $@
+endif
+
 endif
 endif
 
 
 bfgminer_SOURCES	+= logging.c
 bfgminer_SOURCES	+= logging.c

+ 13 - 10
adl.c

@@ -9,7 +9,7 @@
 
 
 #include "config.h"
 #include "config.h"
 
 
-#if defined(HAVE_ADL) && (defined(__linux) || defined (WIN32))
+#ifdef HAVE_ADL
 
 
 #include <stdio.h>
 #include <stdio.h>
 #include <string.h>
 #include <string.h>
@@ -23,7 +23,7 @@
 #include "ADL/adl_sdk.h"
 #include "ADL/adl_sdk.h"
 #include "compat.h"
 #include "compat.h"
 
 
-#if defined (__linux)
+#ifndef WIN32
 #include <dlfcn.h>
 #include <dlfcn.h>
 #include <stdlib.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <unistd.h>
@@ -33,7 +33,7 @@
 #endif
 #endif
 #include "adl_functions.h"
 #include "adl_functions.h"
 
 
-#ifndef WIN32
+#ifndef __stdcall
 #define __stdcall
 #define __stdcall
 #endif
 #endif
 
 
@@ -73,7 +73,7 @@ static void __stdcall ADL_Main_Memory_Free (void **lpBuffer)
 	}
 	}
 }
 }
 
 
-#if defined (LINUX)
+#ifndef WIN32
 // equivalent functions in linux
 // equivalent functions in linux
 static void *GetProcAddress(void *pLibrary, const char *name)
 static void *GetProcAddress(void *pLibrary, const char *name)
 {
 {
@@ -99,9 +99,9 @@ static	ADL_OVERDRIVE5_POWERCONTROL_GET	ADL_Overdrive5_PowerControl_Get;
 static	ADL_OVERDRIVE5_POWERCONTROL_SET	ADL_Overdrive5_PowerControl_Set;
 static	ADL_OVERDRIVE5_POWERCONTROL_SET	ADL_Overdrive5_PowerControl_Set;
 static	ADL_OVERDRIVE5_FANSPEEDTODEFAULT_SET	ADL_Overdrive5_FanSpeedToDefault_Set;
 static	ADL_OVERDRIVE5_FANSPEEDTODEFAULT_SET	ADL_Overdrive5_FanSpeedToDefault_Set;
 
 
-#if defined (LINUX)
+#ifndef WIN32
 	static void *hDLL;	// Handle to .so library
 	static void *hDLL;	// Handle to .so library
-#else
+#else /* WIN32 */
 	HINSTANCE hDLL;		// Handle to DLL
 	HINSTANCE hDLL;		// Handle to DLL
 #endif
 #endif
 static int iNumberAdapters;
 static int iNumberAdapters;
@@ -137,14 +137,17 @@ static bool prepare_adl(void)
 {
 {
 	int result;
 	int result;
 
 
-#if defined (LINUX)
-	hDLL = dlopen( "libatiadlxx.so", RTLD_LAZY|RTLD_GLOBAL);
-#else
+#if defined(WIN32) || defined(__CYGWIN__)
+#	ifdef __CYGWIN__
+#		define LoadLibrary(x) dlopen(x, RTLD_LAZY|RTLD_GLOBAL);
+#	endif
 	hDLL = LoadLibrary("atiadlxx.dll");
 	hDLL = LoadLibrary("atiadlxx.dll");
 	if (hDLL == NULL)
 	if (hDLL == NULL)
 		// A 32 bit calling application on 64 bit OS will fail to LoadLIbrary.
 		// A 32 bit calling application on 64 bit OS will fail to LoadLIbrary.
 		// Try to load the 32 bit library (atiadlxy.dll) instead
 		// Try to load the 32 bit library (atiadlxy.dll) instead
 		hDLL = LoadLibrary("atiadlxy.dll");
 		hDLL = LoadLibrary("atiadlxy.dll");
+#else
+	hDLL = dlopen( "libatiadlxx.so", RTLD_LAZY|RTLD_GLOBAL);
 #endif
 #endif
 	if (hDLL == NULL) {
 	if (hDLL == NULL) {
 		applog(LOG_INFO, "Unable to load ati adl library");
 		applog(LOG_INFO, "Unable to load ati adl library");
@@ -1383,7 +1386,7 @@ static void free_adl(void)
 {
 {
 	ADL_Main_Memory_Free ((void **)&lpInfo);
 	ADL_Main_Memory_Free ((void **)&lpInfo);
 	ADL_Main_Control_Destroy ();
 	ADL_Main_Control_Destroy ();
-#if defined (LINUX)
+#ifndef WIN32
 	dlclose(hDLL);
 	dlclose(hDLL);
 #else
 #else
 	FreeLibrary(hDLL);
 	FreeLibrary(hDLL);

+ 1 - 1
adl_functions.h

@@ -29,7 +29,7 @@
 // AMD ADL function types from Version 3.0
 // AMD ADL function types from Version 3.0
 // ------------------------------------------------------------------------------------------------------------
 // ------------------------------------------------------------------------------------------------------------
 
 
-#if defined (linux)
+#ifndef WIN32
  #include <dlfcn.h>	//dyopen, dlsym, dlclose
  #include <dlfcn.h>	//dyopen, dlsym, dlclose
  #include <stdlib.h>
  #include <stdlib.h>
  #include <string.h>	//memeset
  #include <string.h>	//memeset

+ 3 - 1
api.c

@@ -221,7 +221,9 @@ static const char *OSINFO =
 #if defined(__APPLE__)
 #if defined(__APPLE__)
 			"Apple";
 			"Apple";
 #else
 #else
-#if defined (WIN32)
+#if defined (__CYGWIN__)
+			"Cygwin";
+#elif defined (WIN32)
 			"Windows";
 			"Windows";
 #else
 #else
 #if defined(unix)
 #if defined(unix)

+ 25 - 2
configure.ac

@@ -62,6 +62,7 @@ AC_CHECK_HEADERS([sys/prctl.h])
 
 
 AC_FUNC_ALLOCA
 AC_FUNC_ALLOCA
 
 
+have_cygwin=false
 have_win32=false
 have_win32=false
 PTHREAD_FLAGS="-lpthread"
 PTHREAD_FLAGS="-lpthread"
 USB_LIBS=""
 USB_LIBS=""
@@ -97,6 +98,9 @@ case $target in
     WS2_LIBS="-lws2_32"
     WS2_LIBS="-lws2_32"
 	TIMER_LIBS="-lwinmm"
 	TIMER_LIBS="-lwinmm"
     ;;
     ;;
+  *-*-cygwin*)
+	have_cygwin=true
+	;;
   powerpc-*-darwin*)
   powerpc-*-darwin*)
     CFLAGS="$CFLAGS -faltivec"
     CFLAGS="$CFLAGS -faltivec"
     PTHREAD_FLAGS=""
     PTHREAD_FLAGS=""
@@ -233,10 +237,22 @@ AC_ARG_WITH([curses],
 if test "x$curses" = "xno"; then
 if test "x$curses" = "xno"; then
 	cursesmsg='User specified --without-curses. TUI support DISABLED'
 	cursesmsg='User specified --without-curses. TUI support DISABLED'
 else
 else
+	if test "x$cross_compiling" != "xyes"; then
+		for curses_lib in ncurses{w,}{,6,5}; do
+			if ${curses_lib}-config --cflags >/dev/null 2>/dev/null; then
+				curses=yes
+				cursesmsg="FOUND: ${curses_lib}"
+				NCURSES_LIBS=`${curses_lib}-config --libs`
+				NCURSES_CPPFLAGS=`${curses_lib}-config --cflags`
+				break
+			fi
+		done
+	fi
+	if test "x$curses" != "xyes"; then
+
 	AC_SEARCH_LIBS(addstr, ncurses pdcurses, [
 	AC_SEARCH_LIBS(addstr, ncurses pdcurses, [
 		curses=yes
 		curses=yes
 		cursesmsg="FOUND: ${ac_cv_search_addstr:2}"
 		cursesmsg="FOUND: ${ac_cv_search_addstr:2}"
-		AC_DEFINE([HAVE_CURSES], [1], [Defined to 1 if curses TUI support is wanted])
 	], [
 	], [
 		if test "x$curses" = "xyes"; then
 		if test "x$curses" = "xyes"; then
 			AC_MSG_ERROR([Could not find curses library - please install libncurses-dev or pdcurses-dev (or configure --without-curses)])
 			AC_MSG_ERROR([Could not find curses library - please install libncurses-dev or pdcurses-dev (or configure --without-curses)])
@@ -246,6 +262,11 @@ else
 			cursesmsg='NOT FOUND. TUI support DISABLED'
 			cursesmsg='NOT FOUND. TUI support DISABLED'
 		fi
 		fi
 	])
 	])
+
+	fi
+	if test "x$curses" = "xyes"; then
+		AC_DEFINE([HAVE_CURSES], [1], [Defined to 1 if curses TUI support is wanted])
+	fi
 fi
 fi
 
 
 
 
@@ -256,6 +277,7 @@ AM_CONDITIONAL([NEED_DYNCLOCK], [test x$icarus$modminer$ztex != xnonono])
 AM_CONDITIONAL([NEED_FPGAUTILS], [test x$icarus$bitforce$modminer$ztex != xnononono])
 AM_CONDITIONAL([NEED_FPGAUTILS], [test x$icarus$bitforce$modminer$ztex != xnononono])
 AM_CONDITIONAL([HAS_SCRYPT], [test x$scrypt = xyes])
 AM_CONDITIONAL([HAS_SCRYPT], [test x$scrypt = xyes])
 AM_CONDITIONAL([HAVE_CURSES], [test x$curses = xyes])
 AM_CONDITIONAL([HAVE_CURSES], [test x$curses = xyes])
+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])
 
 
@@ -372,6 +394,7 @@ AC_SUBST(JANSSON_LIBS)
 AC_SUBST(PTHREAD_FLAGS)
 AC_SUBST(PTHREAD_FLAGS)
 AC_SUBST(DLOPEN_FLAGS)
 AC_SUBST(DLOPEN_FLAGS)
 AC_SUBST(PTHREAD_LIBS)
 AC_SUBST(PTHREAD_LIBS)
+AC_SUBST(NCURSES_CPPFLAGS)
 AC_SUBST(NCURSES_LIBS)
 AC_SUBST(NCURSES_LIBS)
 AC_SUBST(PDCURSES_LIBS)
 AC_SUBST(PDCURSES_LIBS)
 AC_SUBST(WS2_LIBS)
 AC_SUBST(WS2_LIBS)
@@ -465,7 +488,7 @@ fi
 
 
 echo
 echo
 echo "Compilation............: make (or gmake)"
 echo "Compilation............: make (or gmake)"
-echo "  CPPFLAGS.............: $CPPFLAGS"
+echo "  CPPFLAGS.............: $CPPFLAGS $NCURSES_CPPFLAGS"
 echo "  CFLAGS...............: $CFLAGS"
 echo "  CFLAGS...............: $CFLAGS"
 echo "  LDFLAGS..............: $LDFLAGS $PTHREAD_FLAGS $USB_FLAGS"
 echo "  LDFLAGS..............: $LDFLAGS $PTHREAD_FLAGS $USB_FLAGS"
 echo "  LDADD................: $DLOPEN_FLAGS $LIBCURL_LIBS $JANSSON_LIBS $PTHREAD_LIBS $NCURSES_LIBS $PDCURSES_LIBS $WS2_LIBS $TIMER_LIBS $MATH_LIBS $UDEV_LIBS $USB_LIBS"
 echo "  LDADD................: $DLOPEN_FLAGS $LIBCURL_LIBS $JANSSON_LIBS $PTHREAD_LIBS $NCURSES_LIBS $PDCURSES_LIBS $WS2_LIBS $TIMER_LIBS $MATH_LIBS $UDEV_LIBS $USB_LIBS"

+ 8 - 1
driver-cairnsmore.c

@@ -24,6 +24,8 @@
 
 
 struct device_api cairnsmore_api;
 struct device_api cairnsmore_api;
 
 
+static void cairnsmore_api_init();
+
 static bool cairnsmore_detect_one(const char *devpath)
 static bool cairnsmore_detect_one(const char *devpath)
 {
 {
 	struct ICARUS_INFO *info = calloc(1, sizeof(struct ICARUS_INFO));
 	struct ICARUS_INFO *info = calloc(1, sizeof(struct ICARUS_INFO));
@@ -56,6 +58,7 @@ static int cairnsmore_detect_auto(void)
 
 
 static void cairnsmore_detect()
 static void cairnsmore_detect()
 {
 {
+	cairnsmore_api_init();
 	// Actual serial detection is handled by Icarus driver
 	// Actual serial detection is handled by Icarus driver
 	serial_detect_auto_byname(&cairnsmore_api, cairnsmore_detect_one, cairnsmore_detect_auto);
 	serial_detect_auto_byname(&cairnsmore_api, cairnsmore_detect_one, cairnsmore_detect_auto);
 }
 }
@@ -192,7 +195,6 @@ static bool cairnsmore_identify(struct cgpu_info *cm1)
 
 
 extern struct device_api icarus_api;
 extern struct device_api icarus_api;
 
 
-__attribute__((constructor(1000)))
 static void cairnsmore_api_init()
 static void cairnsmore_api_init()
 {
 {
 	cairnsmore_api = icarus_api;
 	cairnsmore_api = icarus_api;
@@ -203,3 +205,8 @@ static void cairnsmore_api_init()
 	cairnsmore_api.identify_device = cairnsmore_identify;
 	cairnsmore_api.identify_device = cairnsmore_identify;
 	cairnsmore_api.get_api_extra_device_status = cairnsmore_api_extra_device_status;
 	cairnsmore_api.get_api_extra_device_status = cairnsmore_api_extra_device_status;
 }
 }
+
+struct device_api cairnsmore_api = {
+	// Needed to get to cairnsmore_api_init at all
+	.api_detect = cairnsmore_detect,
+};

+ 1 - 1
libblkmaker

@@ -1 +1 @@
-Subproject commit 7f153402d6699d6748fc3ac6585c9076375c4b53
+Subproject commit e0b627c6522fdbd7c65f883a2c76e3aa437ce910