yggdrasil-go/build
Jan Sarenik c4aed82f94 Compile really static with no pie
On Alpine Linux (musl-libc based GNU/Linux distribution)

Before: $ file yggdrasil
yggdrasil: ELF 64-bit LSB pie executable x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-x86_64.so.1, stripped

After: $ file yggdrasil
yggdrasil: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped
2018-12-12 18:25:28 +01:00

37 lines
839 B
Bash
Executable file

#!/bin/sh
PKGSRC=${PKGSRC:-github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil}
PKGNAME=${PKGNAME:-$(sh contrib/semver/name.sh)}
PKGVER=${PKGVER:-$(sh contrib/semver/version.sh --bare)}
LDFLAGS="-X $PKGSRC.buildName=$PKGNAME -X $PKGSRC.buildVersion=$PKGVER"
LDFLAGS="$LDFLAGS -extldflags '-static -no-pie'"
while getopts "udtc:l:" option
do
case "${option}"
in
u) UPX=true;;
d) DEBUG=true;;
t) TABLES=true;;
c) GCFLAGS="$GCFLAGS $OPTARG";;
l) LDFLAGS="$LDFLAGS $OPTARG";;
esac
done
if [ -z $TABLES ]; then
STRIP="-s -w"
fi
for CMD in `ls cmd/` ; do
echo "Building: $CMD"
if [ $DEBUG ]; then
go build -ldflags="$LDFLAGS" -gcflags="$GCFLAGS" -tags debug -v ./cmd/$CMD
else
go build -ldflags="$LDFLAGS $STRIP" -gcflags="$GCFLAGS" -v ./cmd/$CMD
fi
if [ $UPX ]; then
upx --brute $CMD
fi
done