Merge pull request #1331 from facebook/mingw

fix mingw compatibility
dev
Yann Collet 2018-09-22 16:11:55 -07:00 committed by GitHub
commit 7d9f386a0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 32 deletions

View File

@ -18,17 +18,6 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || \
defined(__CYGWIN__)
#include <io.h> /* _isatty */
#define IS_CONSOLE(stdStream) _isatty(_fileno(stdStream))
#elif defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || defined(_POSIX_SOURCE) || (defined(__APPLE__) && defined(__MACH__)) || \
defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) /* https://sourceforge.net/p/predef/wiki/OperatingSystems/ */
#include <unistd.h> /* isatty */
#define IS_CONSOLE(stdStream) isatty(fileno(stdStream))
#else
#define IS_CONSOLE(stdStream) 0
#endif
namespace pzstd { namespace pzstd {

View File

@ -6,6 +6,7 @@
* LICENSE file in the root directory of this source tree) and the GPLv2 (found * LICENSE file in the root directory of this source tree) and the GPLv2 (found
* in the COPYING file in the root directory of this source tree). * in the COPYING file in the root directory of this source tree).
*/ */
#include "platform.h" /* Large Files support, SET_BINARY_MODE */
#include "Pzstd.h" #include "Pzstd.h"
#include "SkippableFrame.h" #include "SkippableFrame.h"
#include "utils/FileSystem.h" #include "utils/FileSystem.h"
@ -21,14 +22,6 @@
#include <memory> #include <memory>
#include <string> #include <string>
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
# include <fcntl.h> /* _O_BINARY */
# include <io.h> /* _setmode, _isatty */
# define SET_BINARY_MODE(file) { if (_setmode(_fileno(file), _O_BINARY) == -1) perror("Cannot set _O_BINARY"); }
#else
# include <unistd.h> /* isatty */
# define SET_BINARY_MODE(file)
#endif
namespace pzstd { namespace pzstd {

View File

@ -94,8 +94,6 @@ else
SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER) SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER)
endif endif
LIBZSTD = libzstd.$(SHARED_EXT_VER)
.PHONY: default all clean install uninstall .PHONY: default all clean install uninstall
@ -111,19 +109,28 @@ libzstd.a: $(ZSTD_OBJ)
libzstd.a-mt: CPPFLAGS += -DZSTD_MULTITHREAD libzstd.a-mt: CPPFLAGS += -DZSTD_MULTITHREAD
libzstd.a-mt: libzstd.a libzstd.a-mt: libzstd.a
ifneq (,$(filter Windows%,$(OS)))
LIBZSTD = dll\libzstd.dll
$(LIBZSTD): $(ZSTD_FILES)
@echo compiling dynamic library $(LIBVER)
@$(CC) $(FLAGS) -DZSTD_DLL_EXPORT=1 -shared $^ -o $@
dlltool -D $@ -d dll\libzstd.def -l dll\libzstd.lib
else
LIBZSTD = libzstd.$(SHARED_EXT_VER)
$(LIBZSTD): LDFLAGS += -shared -fPIC -fvisibility=hidden $(LIBZSTD): LDFLAGS += -shared -fPIC -fvisibility=hidden
$(LIBZSTD): $(ZSTD_FILES) $(LIBZSTD): $(ZSTD_FILES)
@echo compiling dynamic library $(LIBVER) @echo compiling dynamic library $(LIBVER)
ifneq (,$(filter Windows%,$(OS)))
@$(CC) $(FLAGS) -DZSTD_DLL_EXPORT=1 -shared $^ -o dll\libzstd.dll
dlltool -D dll\libzstd.dll -d dll\libzstd.def -l dll\libzstd.lib
else
@$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@ @$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
@echo creating versioned links @echo creating versioned links
@ln -sf $@ libzstd.$(SHARED_EXT_MAJOR) @ln -sf $@ libzstd.$(SHARED_EXT_MAJOR)
@ln -sf $@ libzstd.$(SHARED_EXT) @ln -sf $@ libzstd.$(SHARED_EXT)
endif endif
libzstd : $(LIBZSTD) libzstd : $(LIBZSTD)
libzstd-mt : CPPFLAGS += -DZSTD_MULTITHREAD libzstd-mt : CPPFLAGS += -DZSTD_MULTITHREAD

View File

@ -20,6 +20,9 @@
# define _POSIX_SOURCE 1 /* disable %llu warnings with MinGW on Windows */ # define _POSIX_SOURCE 1 /* disable %llu warnings with MinGW on Windows */
#endif #endif
#if defined(__linux__) || (defined(__APPLE__) && defined(__MACH__))
# define BACKTRACES_ENABLE 1
#endif
/*-************************************* /*-*************************************
* Includes * Includes
@ -31,8 +34,8 @@
#include <string.h> /* strcmp, strlen */ #include <string.h> /* strcmp, strlen */
#include <errno.h> /* errno */ #include <errno.h> /* errno */
#include <signal.h> #include <signal.h>
#ifndef _WIN32 #ifdef BACKTRACES_ENABLE
#include <execinfo.h> /* backtrace, backtrace_symbols */ # include <execinfo.h> /* backtrace, backtrace_symbols */
#endif #endif
#if defined (_MSC_VER) #if defined (_MSC_VER)
@ -162,9 +165,10 @@ static void clearHandler(void)
/*-********************************************************* /*-*********************************************************
* Termination signal trapping (Print debug stack trace) * Termination signal trapping (Print debug stack trace)
***********************************************************/ ***********************************************************/
#ifdef BACKTRACES_ENABLE
#define MAX_STACK_FRAMES 50 #define MAX_STACK_FRAMES 50
#ifndef _WIN32
static void ABRThandler(int sig) { static void ABRThandler(int sig) {
const char* name; const char* name;
void* addrlist[MAX_STACK_FRAMES]; void* addrlist[MAX_STACK_FRAMES];
@ -202,7 +206,7 @@ static void ABRThandler(int sig) {
void FIO_addAbortHandler() void FIO_addAbortHandler()
{ {
#ifndef _WIN32 #ifdef BACKTRACES_ENABLE
signal(SIGABRT, ABRThandler); signal(SIGABRT, ABRThandler);
signal(SIGFPE, ABRThandler); signal(SIGFPE, ABRThandler);
signal(SIGILL, ABRThandler); signal(SIGILL, ABRThandler);

View File

@ -170,7 +170,11 @@ static int g_utilDisplayLevel;
return ((clockEnd - clockStart) * (U64)rate.numer) / ((U64)rate.denom); return ((clockEnd - clockStart) * (U64)rate.numer) / ((U64)rate.denom);
} }
#elif (PLATFORM_POSIX_VERSION >= 200112L) && (defined __UCLIBC__ || ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 17) || __GLIBC__ > 2)) #elif (PLATFORM_POSIX_VERSION >= 200112L) \
&& (defined(__UCLIBC__) \
|| (defined(__GLIBC__) \
&& ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 17) \
|| (__GLIBC__ > 2))))
#define UTIL_TIME_INITIALIZER { 0, 0 } #define UTIL_TIME_INITIALIZER { 0, 0 }
typedef struct timespec UTIL_freq_t; typedef struct timespec UTIL_freq_t;

View File

@ -1,5 +1,5 @@
/* gzguts.h contains minimal changes required to be compiled with zlibWrapper: /* gzguts.h contains minimal changes required to be compiled with zlibWrapper:
* - #include "zlib.h" was changed to #include "zstd_zlibwrapper.h" * - #include "zlib.h" was changed to #include "zstd_zlibwrapper.h"
* - gz_statep was converted to union to work with -Wstrict-aliasing=1 */ * - gz_statep was converted to union to work with -Wstrict-aliasing=1 */
/* gzguts.h -- zlib internal header definitions for gz* operations /* gzguts.h -- zlib internal header definitions for gz* operations
@ -44,7 +44,7 @@
# include <io.h> # include <io.h>
#endif #endif
#if defined(_WIN32) || defined(__CYGWIN__) #if defined(_WIN32)
# define WIDECHAR # define WIDECHAR
#endif #endif