Skip to content

Commit 6eb9dda

Browse files
committed
added static build as options
1 parent a8efa07 commit 6eb9dda

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

peirates.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var UseAuthCanI bool = true
2727
// Main starts Peirates[]
2828
func Main() {
2929
// Peirates version string
30-
var version = "1.1.22a"
30+
var version = "1.1.22b"
3131

3232
var err error
3333

scripts/build.sh

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
# v0.2 - 08 May 2023 - Minor tweaks
66

77
echo "Building for Linux on AMD64..."
8-
GOOS=linux GOARCH=amd64 go build -v -ldflags="-s -w" $(realpath ../cmd/peirates)
8+
# For static build, uncomment the below line and comment the one below it.
9+
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" $(realpath ../cmd/peirates)
10+
#GOOS=linux GOARCH=amd64 go build -tags netgo,osusergo -a --ldflags '-extldflags "-static"' $(realpath ../cmd/peirates)
11+
912
exit_code=$?
1013

1114
if [ $exit_code -eq 0 ] ; then

scripts/dist.sh

+14-13
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function usage() {
2222
echo "-r Build for arm64"
2323
echo "-t Build for 386"
2424
echo "-x Build all architectures"
25+
echo "-s Build statically-linked"
2526
}
2627

2728
function compress() {
@@ -30,21 +31,15 @@ function compress() {
3031
rmdir peirates-${OS}-${ARCH}
3132
}
3233

33-
function build-dynamic() {
34+
function build() {
3435
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)
4241
fi
43-
}
4442

45-
function build() {
46-
echo "Building for arch: ${ARCH}"
47-
GOOS=${OS} GOARCH=${ARCH} go build -ldflags="-s -w" $(realpath ../cmd/peirates)
4843
if [ ! -d peirates-${OS}-${ARCH} ] ; then
4944
mkdir peirates-${OS}-${ARCH}
5045
fi
@@ -63,11 +58,14 @@ function main() {
6358
for xx in ${ARCHITECTURES[@]};
6459
do
6560
ARCH="${xx}"
61+
#build-dynamic ${ARCH}
6662
build ${ARCH}
6763
done
6864
}
6965

70-
while getopts "haCmrtx" option; do
66+
STATIC="dynamic"
67+
68+
while getopts "haCmrstx" option; do
7169
case $option in
7270
h)
7371
usage
@@ -85,6 +83,9 @@ while getopts "haCmrtx" option; do
8583
r)
8684
ARCHITECTURES=( "arm64" )
8785
;;
86+
s)
87+
STATIC="static"
88+
;;
8889
t)
8990
ARCHITECTURES=( "386" )
9091
;;

0 commit comments

Comments
 (0)