From 4e35ab38478f981f01f24cd2aeac9cc9213fc060 Mon Sep 17 00:00:00 2001 From: Adrian Perez de Castro Date: Tue, 23 Feb 2021 19:37:04 +0200 Subject: [PATCH] xbuild: Utility script to cross-compile static binaries --- xbuild | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 xbuild diff --git a/xbuild b/xbuild new file mode 100755 index 0000000..6154950 --- /dev/null +++ b/xbuild @@ -0,0 +1,57 @@ +#! /bin/bash +set -e + +declare -a TARGETS=( + x86_64-linux-musl + aarch64-linux-musl + arm-linux-musleabi + arm-linux-musleabihf + i386-linux-musl + mips-linux-musl + mipsel-linux-musl + #mips64-linux-musl + #mips64el-linux-musl + powerpc-linux-musl + riscv32-linux-musl + riscv64-linux-musl +) + +declare -a CFLAGS=( + -Os + -flto + -fPIE + -D_FORTIFY_SOURCE=2 + -pipe + -fstack-protector-strong + -fno-plt +) +declare -a LDFLAGS=( + -O1 + -s + -flto + -fPIE + -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now,--icf=safe,--gc-sections +) + +V=$(jq -r .version package.json) + +for T in "${TARGETS[@]}" +do + O="dmon-$V-${T%-musl}" + echo "===== $O ====" + if [[ -x $O ]] ; then + echo ' -> Already built' + continue + fi + + make -s clean + make -sj$(nproc) \ + AR='llvm-ar' \ + CC="zig cc -target $T" \ + CFLAGS="${CFLAGS[*]}" \ + CPPFLAGS="${CPPFLAGS[*]}" + mv dmon "$O" + llvm-strip -x --strip-unneeded "$O" + echo ' -> Done' +done +make -s clean -- 2.45.2