summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-05-24 18:00:30 +0200
committerYorhel <git@yorhel.nl>2019-05-24 18:00:30 +0200
commit9474aaa190938cb5de21ec0513192fc462bacb21 (patch)
tree1e509fe7f8696f1d2ae5ff63deffb37cd97e220a
parent1adcd9cfe15260b757a8234d67feb18bdbba0668 (diff)
Some improvements + support for a musl-based static build
-rw-r--r--README.md11
-rwxr-xr-xbuild.sh35
-rwxr-xr-xclean.sh2
-rwxr-xr-xx86_64-linux-musl.sh12
4 files changed, 42 insertions, 18 deletions
diff --git a/README.md b/README.md
index 29d88a9..baed43f 100644
--- a/README.md
+++ b/README.md
@@ -18,11 +18,18 @@ This repo builds:
- Make
- Autotools
-The build has only been tested on Linux so far.
-
# Usage
+The build has only been tested on Linux so far, but I plan to add support for
+Windows & OS X as well.
+
- Make sure you have all the required dependencies..
- Run `./build.sh`
- Wait.
- 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.
diff --git a/build.sh b/build.sh
index 917aa4d..00b99da 100755
--- a/build.sh
+++ b/build.sh
@@ -2,23 +2,27 @@
set -e
-mkdir -p build
-PWD=`pwd`
-PREFIX="$PWD/build"
+mkdir -p _build
+PREFIX="`pwd`/_build"
+[ -z "$MAKE" ] && MAKE="make -j4"
+
+HOSTFLAG=
+[ -n "$HOST" ] && HOSTFLAG="--host=$HOST"
+
build_zlib() {
cd zlib
- ./configure --prefix="$PREFIX"
- make -j4
- make install
+ ./configure --prefix="$PREFIX" --static
+ $MAKE
+ $MAKE install
cd ..
}
build_openssl() {
cd openssl
./config --prefix="$PREFIX" no-shared no-dso no-zlib
- make build_libs
- make install_dev
+ $MAKE build_libs
+ $MAKE install_dev
cd ..
}
@@ -27,9 +31,9 @@ build_libevent() {
./autogen.sh
./configure --prefix="$PREFIX" --disable-shared --enable-static --with-pic\
--disable-samples -disable-libevent-regress\
- "CPPFLAGS=-I$PREFIX/include", "LDFLAGS=-L$PREFIX/lib"
- make -j4
- make install
+ "CPPFLAGS=-I$PREFIX/include" "LDFLAGS=-L$PREFIX/lib" "$HOSTFLAG"
+ $MAKE
+ $MAKE install
cd ..
}
@@ -42,10 +46,11 @@ build_tor() {
--enable-static-openssl --with-openssl-dir="$PREFIX"\
--enable-static-zlib --with-zlib-dir="$PREFIX"\
--disable-systemd --disable-lzma --disable-zstd --disable-rust\
- --disable-seccomp --disable-libscrypt\
- "CPPFLAGS=-I$PREFIX/include" "LDFLAGS=-L$PREFIX/lib"
- make -j4 V=1
- make install
+ --disable-seccomp --disable-libscrypt $HOSTFLAG\
+ --disable-tool-name-check\
+ "CPPFLAGS=-I$PREFIX/include" "LDFLAGS=-L$PREFIX/lib $LDFLAGS"
+ $MAKE V=1
+ $MAKE install
cd ..
}
diff --git a/clean.sh b/clean.sh
index 377553a..0d97d79 100755
--- a/clean.sh
+++ b/clean.sh
@@ -2,7 +2,7 @@
set -e
-rm -rf build/ tor-static
+rm -rf _build/ tor-static
for d in zlib tor openssl libevent
do
diff --git a/x86_64-linux-musl.sh b/x86_64-linux-musl.sh
new file mode 100755
index 0000000..0fb15ab
--- /dev/null
+++ b/x86_64-linux-musl.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+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
+
+exec ./build.sh