Merge pull request #150 from Cyan4973/msys2

Fix compilation under msys2
This commit is contained in:
Yann Collet 2018-10-11 12:19:30 -07:00 committed by GitHub
commit 74c2c63348
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 76 additions and 17 deletions

2
.gitignore vendored
View File

@ -8,9 +8,11 @@ libxxhash.*
xxh32sum
xxh64sum
xxhsum
xxhsum.exe
xxhsum32
xxhsum_privateXXH
xxhsum_inlinedXXH
xxhsum_inlinedXXH.exe
# Mac OS-X artefacts
*.dSYM

View File

@ -84,8 +84,10 @@ default: lib xxhsum_and_links
.PHONY: all
all: lib xxhsum xxhsum_inlinedXXH
xxhsum : xxhash.o xxhsum.o
xxhsum32: CFLAGS += -m32
xxhsum xxhsum32: xxhash.c xxhsum.c
xxhsum32: xxhash.c xxhsum.c
$(CC) $(FLAGS) $^ $(LDFLAGS) -o $@$(EXT)
.PHONY: xxhsum_and_links
@ -94,30 +96,29 @@ xxhsum_and_links: xxhsum xxh32sum xxh64sum
xxh32sum xxh64sum: xxhsum
ln -sf $^ $@
xxhsum_inlinedXXH: CPPFLAGS += -DXXH_INLINE_ALL
xxhsum_inlinedXXH: xxhsum.c
$(CC) $(FLAGS) -DXXH_PRIVATE_API $^ -o $@$(EXT)
$(CC) $(FLAGS) $^ -o $@$(EXT)
# library
libxxhash.a: ARFLAGS = rcs
libxxhash.a: xxhash.o
@echo compiling static library
@$(AR) $(ARFLAGS) $@ $^
$(AR) $(ARFLAGS) $@ $^
$(LIBXXH): LDFLAGS += -shared
ifeq (,$(filter Windows%,$(OS)))
$(LIBXXH): CFLAGS += -fPIC
endif
$(LIBXXH): xxhash.c
@echo compiling dynamic library $(LIBVER)
$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
@echo creating versioned links
@ln -sf $@ libxxhash.$(SHARED_EXT_MAJOR)
@ln -sf $@ libxxhash.$(SHARED_EXT)
ln -sf $@ libxxhash.$(SHARED_EXT_MAJOR)
ln -sf $@ libxxhash.$(SHARED_EXT)
libxxhash : $(LIBXXH)
.PHONY: lib
lib: libxxhash.a libxxhash
@ -177,12 +178,16 @@ clangtest: clean
CC=clang MOREFLAGS="-Werror -Wconversion -Wno-sign-conversion" $(MAKE) all
cxxtest: clean
@echo ---- test g++ compilation ----
@echo ---- test C++ compilation ----
CC="$(CXX) -Wno-deprecated" $(MAKE) all CFLAGS="-O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror -fPIC"
c90test: clean
.PHONY: c90test
c90test: CPPFLAGS += -DXXH_NO_LONG_LONG
c90test: CFLAGS += -std=c90 -Werror -pedantic
c90test: xxhash.c
@echo ---- test strict C90 compilation [xxh32 only] ----
$(CC) -std=c90 -Werror -pedantic -DXXH_NO_LONG_LONG -c xxhash.c
$(RM) xxhash.o
$(CC) $(FLAGS) $^ $(LDFLAGS) -c
$(RM) xxhash.o
usan: CC=clang
@ -200,6 +205,7 @@ cppcheck:
@echo ---- static analyzer - cppcheck ----
cppcheck . --force --enable=warning,portability,performance,style --error-exitcode=1 > /dev/null
.PHONY: namespaceTest
namespaceTest:
$(CC) -c xxhash.c
$(CC) -DXXH_NAMESPACE=TEST_ -c xxhash.c -o xxhash2.o
@ -209,6 +215,7 @@ namespaceTest:
xxhsum.1: xxhsum.1.md
cat $^ | $(MD2ROFF) $(MD2ROFF_FLAGS) | sed -n '/^\.\\\".*/!p' > $@
.PHONY: man
man: xxhsum.1
clean-man:

View File

@ -63,15 +63,65 @@
/* ************************************
* OS-Specific Includes
**************************************/
#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) _setmode(_fileno(file), _O_BINARY)
#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)) /* UNIX-like OS */ \
|| defined(__midipix__) || defined(__VMS))
# if (defined(__APPLE__) && defined(__MACH__)) || defined(__SVR4) || defined(_AIX) || defined(__hpux) /* POSIX.1-2001 (SUSv3) conformant */ \
|| defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) /* BSD distros */
# define PLATFORM_POSIX_VERSION 200112L
# else
# if defined(__linux__) || defined(__linux)
# ifndef _POSIX_C_SOURCE
# define _POSIX_C_SOURCE 200112L /* use feature test macro */
# endif
# endif
# include <unistd.h> /* declares _POSIX_VERSION */
# if defined(_POSIX_VERSION) /* POSIX compliant */
# define PLATFORM_POSIX_VERSION _POSIX_VERSION
# else
# define PLATFORM_POSIX_VERSION 0
# endif
# endif
#endif
#if !defined(PLATFORM_POSIX_VERSION)
# define PLATFORM_POSIX_VERSION -1
#endif
#if (defined(__linux__) && (PLATFORM_POSIX_VERSION >= 1)) \
|| (PLATFORM_POSIX_VERSION >= 200112L) \
|| defined(__DJGPP__) \
|| defined(__MSYS__)
# include <unistd.h> /* isatty */
# define IS_CONSOLE(stdStream) isatty(fileno(stdStream))
#elif defined(MSDOS) || defined(OS2) || defined(__CYGWIN__)
# include <io.h> /* _isatty */
# define IS_CONSOLE(stdStream) _isatty(_fileno(stdStream))
#elif defined(WIN32) || defined(_WIN32)
# include <io.h> /* _isatty */
# include <windows.h> /* DeviceIoControl, HANDLE, FSCTL_SET_SPARSE */
# include <stdio.h> /* FILE */
static __inline int IS_CONSOLE(FILE* stdStream) {
DWORD dummy;
return _isatty(_fileno(stdStream)) && GetConsoleMode((HANDLE)_get_osfhandle(_fileno(stdStream)), &dummy);
}
#else
# define IS_CONSOLE(stdStream) 0
#endif
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32)
# include <fcntl.h> /* _O_BINARY */
# include <io.h> /* _setmode, _fileno, _get_osfhandle */
# if !defined(__DJGPP__)
# include <windows.h> /* DeviceIoControl, HANDLE, FSCTL_SET_SPARSE */
# include <winioctl.h> /* FSCTL_SET_SPARSE */
# define SET_BINARY_MODE(file) { int const unused=_setmode(_fileno(file), _O_BINARY); (void)unused; }
# define SET_SPARSE_FILE_MODE(file) { DWORD dw; DeviceIoControl((HANDLE) _get_osfhandle(_fileno(file)), FSCTL_SET_SPARSE, 0, 0, 0, 0, &dw, 0); }
# else
# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
# define SET_SPARSE_FILE_MODE(file)
# endif
#else
# include <unistd.h> /* isatty, STDIN_FILENO */
# define SET_BINARY_MODE(file)
# define IS_CONSOLE(stdStream) isatty(STDIN_FILENO)
# define SET_SPARSE_FILE_MODE(file)
#endif
#if !defined(S_ISREG)