unknownbrackets / maxcso

Fast cso compressor
ISC License
390 stars 23 forks source link

Support MinGW-w64 #46

Closed KOLANICH closed 3 years ago

KOLANICH commented 3 years ago

This issue is mostly documenting the easiest way to build the projects in its current state on 64-bit Windows for usage on the same machine using MinGW-w64. The maintainer of this repo may want to integrate the stuff from this issue, but IMHO the right way is not to rely on makefiles, but use CMake.

To build using MinGW-w64 one needs:

diff --git a/Makefile b/Makefile
index 58ece5f..14d028a 100644
--- a/Makefile
+++ b/Makefile
@@ -5,20 +5,27 @@ MANDIR ?= $(PREFIX)/share/man
 CC ?= gcc
 CXX ?= g++

-CFLAGS ?= -O2
+CFLAGS ?= -march=native
 CXXFLAGS ?= $(CFLAGS)

 LIBS ?= libuv liblz4 zlib

-SRC_CFLAGS += -W -Wall -Wextra -Wno-implicit-function-declaration -DNDEBUG=1
-SRC_CXXFLAGS += -W -Wall -Wextra -std=c++11 -Izopfli/src -I7zip -DNDEBUG=1 \
-   -Ilibdeflate -Wno-unused-parameter -Wno-unused-variable -pthread \
-   `pkg-config --cflags $(LIBS)`
+SRC_CFLAGS += -W -Wall -Wextra -Wno-implicit-function-declaration -Ilibuv/include -Ilibuv/src -Ilibdeflate/lib -Ilibdeflate -Ilibdeflate/lib/x86 -DNDEBUG=1
+SRC_CXXFLAGS += -W -Wall -Wextra -std=c++11 -Izopfli/src -I7zip -Ilibuv/include -Ilz4/lib -DNDEBUG=1 \
+   -Ilibdeflate -Wno-unused-parameter -Wno-unused-variable -pthread

 SRC_CXX_SRC = $(wildcard src/*.cpp)
 SRC_CXX_OBJ = $(SRC_CXX_SRC:.cpp=.o)
 CLI_CXX_SRC = $(wildcard cli/*.cpp)
 CLI_CXX_OBJ = $(CLI_CXX_SRC:.cpp=.o)
+DFL_CC_SRC = $(wildcard libdeflate/lib/*.c libdeflate/lib/x86/*.c )
+DFL_CC_OBJ = $(DFL_CC_SRC:.c=.o)
+ZL_CC_SRC = $(wildcard zlib/*.c)
+ZL_CC_OBJ = $(ZL_CC_SRC:.c=.o)
+LZ4_CC_SRC = $(wildcard lz4/lib/*.c)
+LZ4_CC_OBJ = $(LZ4_CC_SRC:.c=.o)
+UV_CC_SRC = $(wildcard libuv/src/*.c libuv/src/win/*.c)
+UV_CC_OBJ = $(UV_CC_SRC:.c=.o)
 ZOPFLI_C_SRC = zopfli/src/zopfli/blocksplitter.c zopfli/src/zopfli/cache.c \
                zopfli/src/zopfli/deflate.c zopfli/src/zopfli/gzip_container.c \
                zopfli/src/zopfli/hash.c zopfli/src/zopfli/katajainen.c \
@@ -34,14 +41,14 @@ ZOPFLI_C_OBJ = $(ZOPFLI_C_SRC:.c=.o)
    $(CC) -c $(SRC_CFLAGS) $(CFLAGS) -o $@ $<

 # TODO: Perhaps detect and use system libdeflate if available.
-maxcso: $(SRC_CXX_OBJ) $(CLI_CXX_OBJ) $(ZOPFLI_C_OBJ) 7zip/7zip.a libdeflate/libdeflate.a
-   $(CXX) -o $@ $(SRC_CXXFLAGS) $(CXXFLAGS) $^ `pkg-config --libs $(LIBS)`
+maxcso: $(SRC_CXX_OBJ) $(CLI_CXX_OBJ) $(ZOPFLI_C_OBJ) $(UV_CC_OBJ) $(DFL_CC_OBJ) $(ZL_CC_OBJ) $(LZ4_CC_OBJ) 7zip/7zip.a libdeflate/libdeflate.dll
+   $(CXX) -o $@ $(SRC_CXXFLAGS) $(CXXFLAGS) $^ -lwsock32 -lws2_32 -lwininet -lpsapi -liphlpapi -lUserEnv -luuid 

 7zip/7zip.a:
    $(MAKE) -C 7zip 7zip.a

-libdeflate/libdeflate.a:
-   $(MAKE) -C libdeflate libdeflate.a

 install: all
    mkdir -p $(DESTDIR)$(BINDIR)
unknownbrackets commented 3 years ago

I went ahead and fixed mingw support in 16d2a25. Just use msys2 or something, similar procedure to building something like FFmpeg. Install libraries via pacman, there's no need to compile libdeflate as a dll or similar. Select your compiler using the shortcuts or using CC/CXX and keep -O2.

Of course, you can also use WSL2 or just msvc. I wouldn't expect better performance from mingw64.

-[Unknown]