From 1906bf176323ae669257e7142044e6b4b410fca8 Mon Sep 17 00:00:00 2001 From: Yorhel Date: Thu, 30 May 2019 15:12:33 +0200 Subject: Add support for Windows/MinGW through MSYS2 I'll see if I can fix a MinGW-based cross compile from Linux now that this works. --- README.md | 6 +++--- build.sh | 29 ++++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index baed43f..9d9ac41 100644 --- a/README.md +++ b/README.md @@ -14,14 +14,14 @@ This repo builds: # Requirements +- Linux or Windows+MSYS2 - A proper C compiler toolchain. - Make - Autotools -# Usage +For Arch Linux & MSYS2-MinGW64: `pacman -S base-devel` -The build has only been tested on Linux so far, but I plan to add support for -Windows & OS X as well. +# Usage - Make sure you have all the required dependencies.. - Run `./build.sh` diff --git a/build.sh b/build.sh index 00b99da..ea6f8e9 100755 --- a/build.sh +++ b/build.sh @@ -9,12 +9,20 @@ PREFIX="`pwd`/_build" HOSTFLAG= [ -n "$HOST" ] && HOSTFLAG="--host=$HOST" +[ -z "$CC" ] && CC=gcc + build_zlib() { cd zlib - ./configure --prefix="$PREFIX" --static - $MAKE - $MAKE install + if $CC -dumpmachine | grep -q 'w64-mingw32'; then + $MAKE -f win32/Makefile.gcc + $MAKE -f win32/Makefile.gcc install\ + INCLUDE_PATH="$PREFIX/include" LIBRARY_PATH="$PREFIX/lib" BINARY_PATH="$PREFIX/bin" + else + ./configure --prefix="$PREFIX" --static + $MAKE + $MAKE install + fi cd .. } @@ -40,6 +48,17 @@ build_libevent() { build_tor() { cd tor ./autogen.sh + + # The order of linker flags is always a major pain in the ass when linking + # static binaries, and the tor configure script doesn't provide much + # flexibility to influence the flag order. So, as a workaround, let's just + # pass *all* the flags necessary for openssl. There will be some duplicate + # link flags in the final build, but that's alright. + # The -static is needed on MinGW in order to remove the dependency on + # libssp and libwinpthread. + TOR_LIBS= + $CC -dumpmachine | grep -q 'w64-mingw32' && TOR_LIBS="-lssl -lcrypto -lcrypt32 -lgdi32 -lws2_32 -static" + # TODO: See if we can enable some more features (seccomp, rust, zstd, lzma, scrypt (what's that used for?)) ./configure --prefix="$PREFIX" --disable-asciidoc --disable-unittests\ --enable-static-libevent --with-libevent-dir="$PREFIX"\ @@ -48,7 +67,7 @@ build_tor() { --disable-systemd --disable-lzma --disable-zstd --disable-rust\ --disable-seccomp --disable-libscrypt $HOSTFLAG\ --disable-tool-name-check\ - "CPPFLAGS=-I$PREFIX/include" "LDFLAGS=-L$PREFIX/lib $LDFLAGS" + "CPPFLAGS=-I$PREFIX/include" "LDFLAGS=-L$PREFIX/lib $LDFLAGS" "LIBS=$TOR_LIBS" $MAKE V=1 $MAKE install cd .. @@ -60,4 +79,4 @@ build_libevent build_tor cp "$PREFIX/bin/tor" tor-static -strip tor-static +strip tor-static{,.exe} -- cgit v1.2.3