@@ -22,6 +22,7 @@ function usage() {
22
22
echo " -r Build for arm64"
23
23
echo " -t Build for 386"
24
24
echo " -x Build all architectures"
25
+ echo " -s Build statically-linked"
25
26
}
26
27
27
28
function compress() {
@@ -30,21 +31,15 @@ function compress() {
30
31
rmdir peirates-${OS} -${ARCH}
31
32
}
32
33
33
- function build-dynamic () {
34
+ function build() {
34
35
echo " Building for arch: ${ARCH} "
35
- GOOS=${OS} GOARCH=${ARCH} go build -ldflags=" -s -w" $( realpath ../cmd/peirates)
36
- if [ ! -d peirates-${OS} -${ARCH} ] ; then
37
- mkdir peirates-${OS} -${ARCH}
38
- fi
39
- mv peirates peirates-${OS} -${ARCH}
40
- if [ $COMPRESS == " yes" ] ; then
41
- compress ${ARCH}
36
+
37
+ if [ $STATIC == " static" ] ; then
38
+ GOOS=${OS} GOARCH=${ARCH} go build -tags netgo,osusergo --ldflags ' -extldflags "-static"' $( realpath ../cmd/peirates)
39
+ else
40
+ GOOS=${OS} GOARCH=${ARCH} go build -ldflags=" -s -w" $( realpath ../cmd/peirates)
42
41
fi
43
- }
44
42
45
- function build() {
46
- echo " Building for arch: ${ARCH} "
47
- GOOS=${OS} GOARCH=${ARCH} go build -ldflags=" -s -w" $( realpath ../cmd/peirates)
48
43
if [ ! -d peirates-${OS} -${ARCH} ] ; then
49
44
mkdir peirates-${OS} -${ARCH}
50
45
fi
@@ -63,11 +58,14 @@ function main() {
63
58
for xx in ${ARCHITECTURES[@]} ;
64
59
do
65
60
ARCH=" ${xx} "
61
+ # build-dynamic ${ARCH}
66
62
build ${ARCH}
67
63
done
68
64
}
69
65
70
- while getopts " haCmrtx" option; do
66
+ STATIC=" dynamic"
67
+
68
+ while getopts " haCmrstx" option; do
71
69
case $option in
72
70
h)
73
71
usage
@@ -85,6 +83,9 @@ while getopts "haCmrtx" option; do
85
83
r)
86
84
ARCHITECTURES=( " arm64" )
87
85
;;
86
+ s)
87
+ STATIC=" static"
88
+ ;;
88
89
t)
89
90
ARCHITECTURES=( " 386" )
90
91
;;
0 commit comments