diff --git a/setup.py b/setup.py index 18aa20f6..1f643ea2 100755 --- a/setup.py +++ b/setup.py @@ -1,5 +1,7 @@ #!/usr/bin/env python import os +import sys + from distutils.core import setup, Extension sources = [ 'src/python/core.c', @@ -28,10 +30,22 @@ 'src/libethash/sha3.h', 'src/libethash/util.h', ] + +WIN32 = sys.platform.startswith("win") + +ccargs=[ + "/Isrc/", + "/Wall" +] if WIN32 else [ + "-Isrc/", + "-std=gnu99", + "-Wall" +] + pyethash = Extension('pyethash', sources=sources, depends=depends, - extra_compile_args=["-Isrc/", "-std=gnu99", "-Wall"]) + extra_compile_args=ccargs) setup( name='pyethash', diff --git a/src/libethash/endian.h b/src/libethash/endian.h index 5b8abf03..d34b3ed5 100644 --- a/src/libethash/endian.h +++ b/src/libethash/endian.h @@ -24,7 +24,10 @@ # include #endif -#if defined(_WIN32) +#if defined(__GNUC__) +#define ethash_swap_u32 __builtin_bswap32 +#define ethash_swap_u64 __builtin_bswap64 +#elif defined(_WIN32) #include #define ethash_swap_u32(input_) _byteswap_ulong(input_) #define ethash_swap_u64(input_) _byteswap_uint64(input_) diff --git a/src/libethash/io_win32.c b/src/libethash/io_win32.c index 34f1aaa7..f5d248b7 100644 --- a/src/libethash/io_win32.c +++ b/src/libethash/io_win32.c @@ -29,13 +29,21 @@ FILE* ethash_fopen(char const* file_name, char const* mode) { +#if __GNUC__ + return fopen(file_name, mode); +#else FILE* f; return fopen_s(&f, file_name, mode) == 0 ? f : NULL; +#endif } char* ethash_strncat(char* dest, size_t dest_size, char const* src, size_t count) { +#if __GNUC__ + return strlen(dest) + count + 1 <= dest_size ? strncat(dest, src, count) : NULL; +#else return strncat_s(dest, dest_size, src, count) == 0 ? dest : NULL; +#endif } bool ethash_mkdir(char const* dirname) diff --git a/src/libethash/mmap_win32.c b/src/libethash/mmap_win32.c index 42968b98..f5cbb333 100644 --- a/src/libethash/mmap_win32.c +++ b/src/libethash/mmap_win32.c @@ -11,6 +11,8 @@ * UnmapViewOfFile: http://msdn.microsoft.com/en-us/library/aa366882(VS.85).aspx */ +#pragma comment(lib, "Shell32.lib") + #include #include #include "mmap.h" diff --git a/src/libethash/util_win32.c b/src/libethash/util_win32.c index 268e6db0..90b83593 100644 --- a/src/libethash/util_win32.c +++ b/src/libethash/util_win32.c @@ -18,6 +18,8 @@ * @author Tim Hughes * @date 2015 */ +#ifdef _MSC_VER + #include #include #include "util.h" @@ -36,3 +38,5 @@ void debugf(char const* str, ...) buf[sizeof(buf)-1] = '\0'; OutputDebugStringA(buf); } + +#endif diff --git a/src/python/core.c b/src/python/core.c index c66e03c5..79f6018b 100644 --- a/src/python/core.c +++ b/src/python/core.c @@ -1,8 +1,10 @@ #include +#ifndef _MSC_VER #include #include #include #include +#endif #include "../libethash/ethash.h" #include "../libethash/internal.h"