2020-02-18 03:00:52 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-07-15 22:19:28 +08:00
|
|
|
export VERSION=$(go run ./cmd/gotop -V | grep -oP '\d+\.\d+\.\d+')
|
2020-02-18 03:00:52 +08:00
|
|
|
|
|
|
|
rm -f build.log
|
|
|
|
|
2020-02-21 00:05:58 +08:00
|
|
|
# Set up some common environment variables
|
|
|
|
function out() {
|
2020-02-18 03:00:52 +08:00
|
|
|
export GOOS=$1
|
|
|
|
export GOARCH=$2
|
|
|
|
OUT=build/gotop_${VERSION}_${GOOS}_${GOARCH}
|
|
|
|
if [[ -n $3 ]]; then
|
|
|
|
export GOARM=$3
|
|
|
|
OUT=${OUT}_v${GOARM}
|
|
|
|
fi
|
|
|
|
D=build/gotop
|
|
|
|
if [[ $GOOS == "windows" ]]; then
|
|
|
|
D=${D}.exe
|
2020-02-21 00:05:58 +08:00
|
|
|
AR=${OUT}.zip
|
|
|
|
else
|
|
|
|
AR=${OUT}.tgz
|
2020-02-18 03:00:52 +08:00
|
|
|
fi
|
2020-02-21 00:05:58 +08:00
|
|
|
}
|
|
|
|
# Clean up environment variables
|
|
|
|
function uset() {
|
|
|
|
unset GOOS GOARCH GOARM CGO_ENABLED OUT D AR
|
|
|
|
}
|
|
|
|
# Compile something that can be cross-compiled without docker
|
|
|
|
function c() {
|
|
|
|
out $1 $2 $3
|
2020-02-18 03:00:52 +08:00
|
|
|
go build -o $D ./cmd/gotop >> build.log 2>&1
|
|
|
|
if [[ $? -ne 0 ]]; then
|
|
|
|
printenv | grep GO >> build.log
|
2020-02-21 00:05:58 +08:00
|
|
|
echo "############### FAILED ###############"
|
|
|
|
echo FAILED COMPILE $OUT
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
# Zip up something that's been compiled
|
|
|
|
function z() {
|
|
|
|
out $1 $2 $3
|
|
|
|
if [[ -e $AR ]]; then
|
|
|
|
echo SKIP $AR
|
2020-02-18 03:00:52 +08:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
cd build
|
2020-02-21 00:05:58 +08:00
|
|
|
if [[ $GOOS == "windows" ]]; then
|
|
|
|
zip -q $(basename $AR) $(basename $D)
|
|
|
|
else
|
|
|
|
tar -czf $(basename $AR) $(basename $D)
|
|
|
|
fi
|
2020-02-18 03:00:52 +08:00
|
|
|
if [[ $? -ne 0 ]]; then
|
2020-02-21 00:05:58 +08:00
|
|
|
echo "############### FAILED ###############"
|
|
|
|
echo FAILED ARCHIVE $AR
|
|
|
|
cd ..
|
2020-02-18 03:00:52 +08:00
|
|
|
return
|
|
|
|
fi
|
2020-02-21 00:05:58 +08:00
|
|
|
cd ..
|
|
|
|
echo BUILT $AR
|
2020-02-18 03:00:52 +08:00
|
|
|
}
|
2020-02-21 00:05:58 +08:00
|
|
|
# Do c(), then z(), and then clean up.
|
|
|
|
function candz() {
|
|
|
|
unset OUT
|
|
|
|
out $1 $2 $3
|
|
|
|
local AR=${OUT}.zip
|
|
|
|
if [[ -e $AR ]]; then
|
|
|
|
echo SKIP $AR
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
c $1 $2 $3
|
|
|
|
z $1 $2 $3
|
|
|
|
rm -f $D
|
|
|
|
uset
|
|
|
|
}
|
|
|
|
# Build the deb and rpm archives
|
|
|
|
function nfpmAR() {
|
|
|
|
out $1 $2 $3
|
|
|
|
sed -i "s/arch: .*/arch: \"${GOARCH}\"/" build/nfpm.yml
|
2020-02-18 03:00:52 +08:00
|
|
|
for y in rpm deb; do
|
2020-02-21 00:05:58 +08:00
|
|
|
local AR=build/gotop_${VERSION}_linux_${GOARCH}.${y}
|
|
|
|
if [[ -e $AR ]]; then
|
|
|
|
echo SKIP $AR
|
2020-02-18 03:00:52 +08:00
|
|
|
else
|
2020-02-21 00:05:58 +08:00
|
|
|
echo Building $AR
|
|
|
|
nfpm pkg -t ${AR} -f build/nfpm.yml
|
2020-02-18 03:00:52 +08:00
|
|
|
fi
|
|
|
|
done
|
2020-02-21 00:05:58 +08:00
|
|
|
}
|
|
|
|
# Cross-compile the darwin executable. This requires docker.
|
|
|
|
function cdarwinz() {
|
|
|
|
if [[ ! -d darwin ]]; then
|
|
|
|
git clone . darwin
|
|
|
|
cd darwin
|
|
|
|
else
|
|
|
|
cd darwin
|
2020-02-28 08:51:28 +08:00
|
|
|
git checkout -- .
|
2020-02-21 00:05:58 +08:00
|
|
|
git pull
|
|
|
|
fi
|
|
|
|
export CGO_ENABLED=1
|
|
|
|
if [[ `docker images -q gotopdarwin` == "" ]]; then
|
|
|
|
docker run -it --name osxcross --mount type=bind,source="$(pwd)",target=/mnt dockercore/golang-cross /bin/bash /mnt/build/osx.sh
|
|
|
|
local ID=`docker commit osxcross dockercore/golang-cross | cut -d : -f 2`
|
|
|
|
docker tag $ID gotopdarwin
|
|
|
|
else
|
|
|
|
docker run -it --name osxcross --mount type=bind,source="$(pwd)",target=/mnt gotopdarwin /bin/bash /mnt/build/osx.sh
|
|
|
|
fi
|
|
|
|
cd ..
|
|
|
|
mv darwin/build/gotop*darwin*.tgz build/
|
|
|
|
docker rm osxcross
|
|
|
|
uset
|
|
|
|
}
|
2020-02-18 03:00:52 +08:00
|
|
|
|
2020-02-21 00:05:58 +08:00
|
|
|
##########################################################
|
|
|
|
# Iterate through the OS/ARCH permutations and build an
|
|
|
|
# archive for each, using the previously defined functions.
|
|
|
|
if [[ $1 == "darwin" ]]; then
|
|
|
|
export MACOSX_DEPLOYMENT_TARGET=10.10.0
|
|
|
|
export CC=o64-clang
|
|
|
|
export CXX=o64-clang++
|
|
|
|
export CGO_ENABLED=1
|
|
|
|
c darwin 386
|
|
|
|
z darwin 386
|
|
|
|
c darwin amd64
|
|
|
|
z darwin amd64
|
|
|
|
else
|
|
|
|
candz linux arm64
|
2020-02-18 03:00:52 +08:00
|
|
|
|
2020-02-21 00:05:58 +08:00
|
|
|
for x in 5 6 7; do
|
|
|
|
candz linux arm $x
|
|
|
|
done
|
2020-02-18 03:00:52 +08:00
|
|
|
|
2020-02-21 00:05:58 +08:00
|
|
|
for x in 386 amd64; do
|
|
|
|
c linux $x
|
|
|
|
z linux $x
|
|
|
|
nfpmAR linux $x
|
|
|
|
rm -f $D
|
|
|
|
uset
|
|
|
|
|
|
|
|
candz windows $x
|
|
|
|
candz freebsd $x
|
|
|
|
|
2020-02-21 03:26:39 +08:00
|
|
|
# TODO Preliminary OpenBSD support [#112] [#117] [#118]
|
2020-02-21 00:05:58 +08:00
|
|
|
# candz openbsd $x
|
|
|
|
done
|
|
|
|
cdarwinz
|
|
|
|
fi
|