From baf468a6317b40388166aa11d435887770290cee Mon Sep 17 00:00:00 2001 From: neurolabusc Date: Sat, 22 Feb 2020 11:06:30 -0500 Subject: [PATCH] MinGW64 support for non-Latin characters (https://github.com/madler/pigz/issues/62) --- src/Makefile | 16 ++++++++++++++-- src/pigz.c | 39 ++++++++++++++++++++++++++++++++------- 2 files changed, 46 insertions(+), 9 deletions(-) mode change 100644 => 100755 src/Makefile mode change 100755 => 100644 src/pigz.c diff --git a/src/Makefile b/src/Makefile old mode 100644 new mode 100755 index eec3221..6494d4e --- a/src/Makefile +++ b/src/Makefile @@ -1,13 +1,25 @@ CC=gcc CFLAGS=-O3 -Wall -Wextra -Wno-unknown-pragmas LDFLAGS= -#LIBS=-lm -lpthread -lz +UNPIGZ=ln -f pigz unpigz LIBS=-lm -lpthread -I./linux ./linux/libz.a +#LIBS=-lm -lpthread -lz + ifneq ($(OS),Windows_NT) OS = $(shell uname) ifeq "$(OS)" "Darwin" LIBS=-lm -lpthread -I./darwin ./darwin/libz.a endif +else + ifeq ($(PROCESSOR_ARCHITEW6432),AMD64) + LDFLAGS= -municode + else + ifeq ($(PROCESSOR_ARCHITECTURE),AMD64) + LDFLAGS= -municode + endif + endif + LIBS=-lm -lpthread -lz + UNPIGZ=cp pigz.exe unpigz.exe endif ZOPFLI=zopfli/src/zopfli/ @@ -17,7 +29,7 @@ ZOP=deflate.o blocksplitter.o tree.o lz77.o cache.o hash.o util.o squeeze.o kata pigz: pigz.o yarn.o try.o $(ZOP) $(CC) $(LDFLAGS) -o pigz pigz.o yarn.o try.o $(ZOP) $(LIBS) - ln -f pigz unpigz + $(UNPIGZ) pigz.o: pigz.c yarn.h try.h $(ZOPFLI)deflate.h $(ZOPFLI)util.h diff --git a/src/pigz.c b/src/pigz.c old mode 100755 new mode 100644 index dfac0d7..71d34ea --- a/src/pigz.c +++ b/src/pigz.c @@ -352,6 +352,19 @@ typedef SSIZE_T ssize_t; #include // ssize_t #include // chmod(), stat(), fstat(), lstat(), struct stat, // S_IFDIR, S_IFLNK, S_IFMT, S_IFREG +#ifdef __MINGW32__ + #include + #include + #include + #ifndef _UNICODE + #define _UNICODE + #endif + #ifndef UNICODE + #define UNICODE + #endif + #include +#endif + #ifndef _MSC_VER #include // utimes(), gettimeofday(), struct timeval #include // unlink(), _exit(), read(), write(), close(), @@ -397,7 +410,7 @@ typedef SSIZE_T ssize_t; # define S_IFLNK 0 #endif -#ifdef _MSC_VER +#if defined(_MSC_VER) || defined(__MINGW64__) //https://www.nu42.com/2017/02/unicode-windows-command-line.html //https://raw.githubusercontent.com/gypified/libmp3lame/master/frontend/main.c @@ -477,10 +490,18 @@ int unlinkUTF8(const char *path) { #ifdef __MINGW32__ # define chown(p,o,g) 0 # define utimes(p,t) 0 -# define lstat(p,s) stat(p,s) +#if defined(__MINGW64__) + //lstat defined for unicode +#else + # define lstat(p,s) stat(p,s) +#endif # define _exit(s) exit(s) #endif + + + + #include "zlib.h" // deflateInit2(), deflateReset(), deflate(), // deflateEnd(), deflateSetDictionary(), crc32(), // adler32(), inflateBackInit(), inflateBack(), @@ -3726,7 +3747,8 @@ local void touch(char *path, time_t t) { -#ifdef _MSC_VER +//#ifdef +#if defined(_MSC_VER) || defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) /* http://ab-initio.mit.edu/octave-Faddeeva/gnulib/lib/fsync.c Emulate fsync on platforms that lack it, primarily Windows and cross-compilers like MinGW. @@ -4469,10 +4491,10 @@ local void cut_yarn(int err) { #endif // Process command line arguments. -#ifndef _MSC_VER -int main(int argc, char **argv) { -#else +#if defined(_MSC_VER) || defined(__MINGW64__) int c_main(int argc, char *argv[]) { +#else +int main(int argc, char **argv) { #endif int n; // general index int nop; // index before which "-" means stdin @@ -4614,7 +4636,10 @@ int c_main(int argc, char *argv[]) { return g.ret; } -#ifdef _MSC_VER +#if defined(_MSC_VER) || defined(__MINGW64__) +// beware, only some versions of MinGW support wmain and -municode linker flag +// use this version: http://mingw-w64.org/doku.php +// for details: https://sourceforge.net/p/mingw-w64/wiki2/Unicode%20apps/ int wmain(int argc, wchar_t* argv[]) { //convert each argument to UTF8 char **utf8_argv; int ret;