Skip to content

Commit

Permalink
added static build as options
Browse files Browse the repository at this point in the history
  • Loading branch information
JayBeale committed May 15, 2024
1 parent a8efa07 commit 6eb9dda
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion peirates.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var UseAuthCanI bool = true
// Main starts Peirates[]
func Main() {
// Peirates version string
var version = "1.1.22a"
var version = "1.1.22b"

var err error

Expand Down
5 changes: 4 additions & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
# v0.2 - 08 May 2023 - Minor tweaks

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

exit_code=$?

if [ $exit_code -eq 0 ] ; then
Expand Down
27 changes: 14 additions & 13 deletions scripts/dist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function usage() {
echo "-r Build for arm64"
echo "-t Build for 386"
echo "-x Build all architectures"
echo "-s Build statically-linked"
}

function compress() {
Expand All @@ -30,21 +31,15 @@ function compress() {
rmdir peirates-${OS}-${ARCH}
}

function build-dynamic() {
function build() {
echo "Building for arch: ${ARCH}"
GOOS=${OS} GOARCH=${ARCH} go build -ldflags="-s -w" $(realpath ../cmd/peirates)
if [ ! -d peirates-${OS}-${ARCH} ] ; then
mkdir peirates-${OS}-${ARCH}
fi
mv peirates peirates-${OS}-${ARCH}
if [ $COMPRESS == "yes" ] ; then
compress ${ARCH}

if [ $STATIC == "static" ] ; then
GOOS=${OS} GOARCH=${ARCH} go build -tags netgo,osusergo --ldflags '-extldflags "-static"' $(realpath ../cmd/peirates)
else
GOOS=${OS} GOARCH=${ARCH} go build -ldflags="-s -w" $(realpath ../cmd/peirates)
fi
}

function build() {
echo "Building for arch: ${ARCH}"
GOOS=${OS} GOARCH=${ARCH} go build -ldflags="-s -w" $(realpath ../cmd/peirates)
if [ ! -d peirates-${OS}-${ARCH} ] ; then
mkdir peirates-${OS}-${ARCH}
fi
Expand All @@ -63,11 +58,14 @@ function main() {
for xx in ${ARCHITECTURES[@]};
do
ARCH="${xx}"
#build-dynamic ${ARCH}
build ${ARCH}
done
}

while getopts "haCmrtx" option; do
STATIC="dynamic"

while getopts "haCmrstx" option; do
case $option in
h)
usage
Expand All @@ -85,6 +83,9 @@ while getopts "haCmrtx" option; do
r)
ARCHITECTURES=( "arm64" )
;;
s)
STATIC="static"
;;
t)
ARCHITECTURES=( "386" )
;;
Expand Down

0 comments on commit 6eb9dda

Please sign in to comment.