yggdrasil-go/build
2021-09-13 00:47:43 +03:00

57 lines
1.6 KiB
Bash
Executable file

#!/bin/sh
set -ef
PKGSRC=${PKGSRC:-github.com/RiV-chain/RiV-mesh/src/version}
PKGNAME=${PKGNAME:-$(sh contrib/semver/name.sh)}
PKGVER=${PKGVER:-$(sh contrib/semver/version.sh --bare)}
if [ "$LDFLAGS" ]; then
LDFLAGS="$LDFLAGS -X $PKGSRC.buildName=$PKGNAME -X $PKGSRC.buildVersion=$PKGVER"
else
LDFLAGS="-X $PKGSRC.buildName=$PKGNAME -X $PKGSRC.buildVersion=$PKGVER"
fi
ARGS="-v"
while getopts "uaitc:l:dro:p" option
do
case "$option"
in
u) UPX=true;;
i) IOS=true;;
a) ANDROID=true;;
t) TABLES=true;;
c) GCFLAGS="$GCFLAGS $OPTARG";;
l) LDFLAGS="$LDFLAGS $OPTARG";;
d) ARGS="$ARGS -tags debug" DEBUG=true;;
r) ARGS="$ARGS -race";;
o) ARGS="$ARGS -o $OPTARG";;
p) ARGS="$ARGS -buildmode=pie";;
esac
done
if [ -z $TABLES ] && [ -z $DEBUG ]; then
LDFLAGS="$LDFLAGS -s -w"
fi
if [ $IOS ]; then
echo "Building framework for iOS"
go get golang.org/x/mobile/bind
gomobile bind -target ios -tags mobile -o Mesh.framework -ldflags="$LDFLAGS $STRIP" -gcflags="$GCFLAGS" \
github.com/RiV-chain/RiV-mesh-extras/src/mobile \
github.com/RiV-chain/RiV-mesh/src/config
elif [ $ANDROID ]; then
echo "Building aar for Android"
go get golang.org/x/mobile/bind
gomobile bind -target android -tags mobile -o mesh.aar -ldflags="$LDFLAGS $STRIP" -gcflags="$GCFLAGS" \
github.com/RiV-chain/RiV-mesh-extras/src/mobile \
github.com/RiV-chain/RiV-mesh/src/config
else
for CMD in ./cmd/mesh ./cmd/meshctl ./contrib/ui/mesh-ui ; do
echo "Building: $CMD"
go build $ARGS -ldflags "$LDFLAGS" -gcflags "$GCFLAGS" $CMD
if [ $UPX ]; then
upx --brute $CMD
fi
done
fi