aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-10-27 05:04:12 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2017-11-01 18:23:38 +0100
commit157f7545104216889e32b3a28f55364a78fbd0c2 (patch)
tree7cf68beba45524a05ad96738d8c537f528e67448
parentPrepare version 0.1.0 (diff)
downloadwireguard-android-157f7545104216889e32b3a28f55364a78fbd0c2.tar.xz
wireguard-android-157f7545104216889e32b3a28f55364a78fbd0c2.zip
cli: add wg(8) build script
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rwxr-xr-xcli/make-me-an-android-wg-command.sh59
1 files changed, 59 insertions, 0 deletions
diff --git a/cli/make-me-an-android-wg-command.sh b/cli/make-me-an-android-wg-command.sh
new file mode 100755
index 0000000..5a84547
--- /dev/null
+++ b/cli/make-me-an-android-wg-command.sh
@@ -0,0 +1,59 @@
+#!/bin/bash
+
+set -e
+
+ARCH="arm64"
+ANDROID_PLATFORM="24"
+WIREGUARD_VERSION="0.0.20171101"
+LIBMNL_VERSION="1.0.4"
+
+case "$ARCH" in
+ arm) ANDROID_MACHINE="arm-linux-androideabi"; ;;
+ arm64) ANDROID_MACHINE="aarch64-linux-android"; ;;
+ mips) ANDROID_MACHINE="mipsel-linux-android"; ;;
+ mips64) ANDROID_MACHINE="mips64el-linux-android"; ;;
+ x86) ANDROID_MACHINE="x86-linux-android"; ;;
+ x86_64) ANDROID_MACHINE="x86_64-linux-android"; ;;
+ *) echo "Error: unknown architecture" >&2; exit 1; ;;
+esac
+
+GCC_VERSION="4.9"
+ANDROID_PLATFORM="/opt/android-ndk/platforms/android-$ANDROID_PLATFORM/arch-$ARCH/usr"
+ANDROID_TOOLCHAIN="/opt/android-ndk/toolchains/$ANDROID_MACHINE-$GCC_VERSION/prebuilt/linux-$(uname -m)/bin"
+
+export PATH="$ANDROID_TOOLCHAIN:$PATH"
+export CC="$ANDROID_MACHINE-gcc --sysroot $ANDROID_PLATFORM"
+export LD="$ANDROID_MACHINE-ld --sysroot $ANDROID_PLATFORM"
+export CFLAGS="-O3 -fomit-frame-pointer -I$ANDROID_PLATFORM/include -fPIE"
+export LDFLAGS="-pie"
+
+trap 'cd /; rm -rf "$where"' EXIT
+where="$(mktemp -d)"
+here="$PWD"
+cd "$where"
+
+wget "http://ftp.netfilter.org/pub/libmnl/libmnl-$LIBMNL_VERSION.tar.bz2"
+wget "https://git.zx2c4.com/WireGuard/snapshot/WireGuard-$WIREGUARD_VERSION.tar.xz"
+
+tar xjf "libmnl-$LIBMNL_VERSION.tar.bz2"
+tar xJf "WireGuard-$WIREGUARD_VERSION.tar.xz"
+
+cd "libmnl-$LIBMNL_VERSION"
+./configure --enable-static --disable-shared --host="$ANDROID_MACHINE"
+make -j$(nproc)
+
+cd ..
+
+cd "WireGuard-$WIREGUARD_VERSION/src/tools"
+export CFLAGS="$CFLAGS -I../../../libmnl-$LIBMNL_VERSION/include"
+export LDFLAGS="$LDFLAGS -L../../../libmnl-$LIBMNL_VERSION/src/.libs"
+make -j$(nproc)
+"$ANDROID_MACHINE-strip" wg
+mv wg "$here/wg"
+
+echo
+echo
+echo ===============================================
+echo Build complete:
+ls -l "$here/wg"
+echo ===============================================