summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-06-12 15:47:36 +0200
committerYorhel <git@yorhel.nl>2019-06-12 15:47:36 +0200
commitf423f9835a90ebf195a4edd3dfb9674adf10f4b2 (patch)
treebae4894af2f5c4e296675ff78272dbd68a67990f
parent1906bf176323ae669257e7142044e6b4b410fca8 (diff)
Support cross-compilation from Linux to Windows
-rw-r--r--README.md15
-rwxr-xr-xbuild.sh25
-rwxr-xr-xx86_64-linux-musl.sh4
3 files changed, 30 insertions, 14 deletions
diff --git a/README.md b/README.md
index 9d9ac41..88d327d 100644
--- a/README.md
+++ b/README.md
@@ -29,7 +29,14 @@ For Arch Linux & MSYS2-MinGW64: `pacman -S base-devel`
- Discover that you suddenly have a working `tor-static` binary.
The generated binary is not *entirely* static because it still links against
-your system libraries. If you have
-[musl-cross](https://bitbucket.org/GregorR/musl-cross/) built and installed in
-`/opt/cross`, then you can run `./x86_64-linux-musl.sh` to "cross"-compile a
-fully static binary. Scripts for other arches are TBD.
+your system libc. Handy scripts are included for cross-compilation:
+
+- `x86_64-linux-musl.sh` will build a fully static binary linked against musl
+ libc. Requirements: musl-based cross compiler in `/opt/cross`, you can get
+ these from [musl-cross](https://bitbucket.org/GregorR/musl-cross/) or
+ [musl.cc](https://musl.cc/).
+- `x86_64-w64-mingw32.sh` will cross-compile a Windows binary, requires a
+ mingw32 cross compiler in `/opt/cross` ([musl.cc](https://musl.cc/) has
+ these).
+
+More targets TBD.
diff --git a/build.sh b/build.sh
index ea6f8e9..b4c6eb9 100755
--- a/build.sh
+++ b/build.sh
@@ -7,15 +7,25 @@ PREFIX="`pwd`/_build"
[ -z "$MAKE" ] && MAKE="make -j4"
HOSTFLAG=
-[ -n "$HOST" ] && HOSTFLAG="--host=$HOST"
-
-[ -z "$CC" ] && CC=gcc
+if [ -n "$HOST" ]; then
+ HOSTFLAG="--host=$HOST"
+ [ -z "$CC" ] && export CC=$HOST-gcc
+ [ -z "$AR" ] && export AR=$HOST-ar
+ [ -z "$RANLIB" ] && export RANLIB=$HOST-ranlib
+ [ -z "$LD" ] && export LD=$HOST-ld
+ [ -z "$STRIP" ] && export STRIP=$HOST-strip
+else
+ [ -z "$CC" ] && CC=gcc
+ [ -z "$STRIP"] && STRIP=strip
+fi
build_zlib() {
cd zlib
if $CC -dumpmachine | grep -q 'w64-mingw32'; then
- $MAKE -f win32/Makefile.gcc
+ TOOLPREFIX=
+ [ -n "$HOST" ] && TOOLPREFIX="$HOST-"
+ $MAKE -f win32/Makefile.gcc PREFIX="$TOOLPREFIX"
$MAKE -f win32/Makefile.gcc install\
INCLUDE_PATH="$PREFIX/include" LIBRARY_PATH="$PREFIX/lib" BINARY_PATH="$PREFIX/bin"
else
@@ -78,5 +88,8 @@ build_openssl
build_libevent
build_tor
-cp "$PREFIX/bin/tor" tor-static
-strip tor-static{,.exe}
+EXT=
+[ -e "$PREFIX/bin/tor.exe" ] && EXT=.exe
+
+cp "$PREFIX/bin/tor$EXT" tor-static$EXT
+$STRIP tor-static$EXT
diff --git a/x86_64-linux-musl.sh b/x86_64-linux-musl.sh
index 0fb15ab..51c8027 100755
--- a/x86_64-linux-musl.sh
+++ b/x86_64-linux-musl.sh
@@ -2,10 +2,6 @@
export PATH="/opt/cross/x86_64-linux-musl/bin:$PATH"
export HOST=x86_64-musl-linux
-export CC=x86_64-linux-musl-gcc
-export AR=x86_64-linux-musl-ar
-export RANLIB=x86_64-linux-musl-ranlib
-export LD=x86_64-linux-musl-ld
export LDFLAGS=-static