diff options
Diffstat (limited to 'make.sh')
-rwxr-xr-x | make.sh | 151 |
1 files changed, 110 insertions, 41 deletions
@@ -4,7 +4,8 @@ export VERSION=$(go run ./cmd/gotop -V) rm -f build.log -function candz() { +# Set up some common environment variables +function out() { export GOOS=$1 export GOARCH=$2 OUT=build/gotop_${VERSION}_${GOOS}_${GOARCH} @@ -12,64 +13,132 @@ function candz() { export GOARM=$3 OUT=${OUT}_v${GOARM} fi - OUT=${OUT}.zip - if [[ -e $OUT ]]; then - echo SKIP $OUT - return - fi D=build/gotop if [[ $GOOS == "windows" ]]; then D=${D}.exe + AR=${OUT}.zip + else + AR=${OUT}.tgz fi +} +# 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 go build -o $D ./cmd/gotop >> build.log 2>&1 if [[ $? -ne 0 ]]; then printenv | grep GO >> build.log - echo "############### FAILED ###############" >> build.log - echo >> build.log - echo >> build.log - echo FAILED $OUT + 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 return fi - unset GOOS GOARCH GOARM CGO_ENABLED cd build - zip $(basename $OUT) $(basename $D) >> ../build.log 2>&1 - cd .. - rm -f $D + if [[ $GOOS == "windows" ]]; then + zip -q $(basename $AR) $(basename $D) + else + tar -czf $(basename $AR) $(basename $D) + fi if [[ $? -ne 0 ]]; then - echo "############### FAILED ###############" >> build.log - echo >> build.log - echo >> build.log - echo FAILED $OUT + echo "############### FAILED ###############" + echo FAILED ARCHIVE $AR + cd .. return fi - echo BUILT $OUT + cd .. + echo BUILT $AR } - -candz linux arm64 -for x in 5 6 7; do - candz linux arm $x -done -for x in 386 amd64; do - candz linux $x - - sed -i "s/arch: .*/arch: \"${x}\"/" build/nfpm.yml +# 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 for y in rpm deb; do - OUT=build/gotop_${VERSION}_linux_${x}.${y} - if [[ -e $OUT ]]; then - echo SKIP $OUT + local AR=build/gotop_${VERSION}_linux_${GOARCH}.${y} + if [[ -e $AR ]]; then + echo SKIP $AR else - echo Building $OUT - nfpm pkg -t ${OUT} -f build/nfpm.yml + echo Building $AR + nfpm pkg -t ${AR} -f build/nfpm.yml fi done +} +# Cross-compile the darwin executable. This requires docker. +function cdarwinz() { + if [[ ! -d darwin ]]; then + git clone . darwin + cd darwin + else + cd darwin + 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 +} - candz windows $x - candz freebsd $x +########################################################## +# 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 - export CGO_ENABLED=1 - candz darwin $x - candz openbsd $x - unset CGO_ENABLED -done + for x in 5 6 7; do + candz linux arm $x + done -rm -f build/gotop + 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 + + # TODO Preliminary OpenBSD support [#112] [#117] [#118] + # candz openbsd $x + done + cdarwinz +fi |