forked from yggdrasil-network/yggdrasil-go
-
Notifications
You must be signed in to change notification settings - Fork 4
/
build
executable file
·73 lines (63 loc) · 1.47 KB
/
build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
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)}
echo "Building: $PKGVER"
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"
TARGET_PATH=$(pwd)
while getopts "utc:l:dro:psg:b:" option
do
case "$option"
in
u) UPX=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";;
# statically linked executable
s) STATIC=" -linkmode external -extldflags=-static";;
# build target
g) TARGET=$OPTARG;;
# build path
b) TARGET_PATH=$OPTARG;;
esac
done
if [ -z $TABLES ] && [ -z $DEBUG ]; then
LDFLAGS="$LDFLAGS -s -w"
fi
#could be static
buildbin() {
local CMD=$(realpath $1)
echo "Building: $CMD for $GOOS-$GOARCH"
(cd "$TARGET_PATH" && go build $ARGS -ldflags "${LDFLAGS}${LDFLAGS2}" -gcflags "$GCFLAGS" "$CMD")
if [ $UPX ]; then
upx --brute "$CMD"
fi
}
build_mesh() {
LDFLAGS2="${STATIC}" buildbin ./cmd/mesh
}
build_meshctl() {
LDFLAGS2="${STATIC}" buildbin ./cmd/meshctl
}
case $TARGET in
"mesh")
build_mesh
;;
"meshctl")
build_meshctl
;;
*)
build_mesh
build_meshctl
;;
esac