MQTTListener/build.sh

95 lines
1.9 KiB
Bash
Raw Normal View History

#!/bin/bash
2020-09-05 07:49:21 +02:00
APP=mqttListener
# expand PATH for go tools
export PATH=$PATH:~/go/bin
RED='\e[0;31m'
GREEN='\e[0;32m'
LIGHT_YELLOW='\e[93m'
NC='\e[0m' # No Color
BOLD='\e[1m'
NORMAL='\e[21m'
#######################################################################################
# defaults
GO_BUILD_OPTIONS=-v
#GO_BUILD_OPTIONS="-a -v"
DEFAULT_TARGET=amd64
#######################################################################################
# functions
die() { echo -e "\n${RED}$@${NC}" 1>&2 ; exit 1; }
usage() {
echo "usage: `basename $0` [<TARGET>] [all]"
}
#######################################################################################
# build functions
build_linux_amd64() {
echo -e "\nBuilding for Linux amd64:"
2020-09-05 07:49:21 +02:00
env GOOS=linux GOARCH=amd64 go build ${GO_BUILD_OPTIONS} -ldflags "$(govvv -flags)" -o ${APP}-linux-amd64
echo -e "\t\t${GREEN}... done${NC}"
}
build_linux_arm() {
echo -e "\nBuilding for arm:"
2020-09-05 07:49:21 +02:00
env GOOS=linux GOARCH=arm go build ${GO_BUILD_OPTIONS} -ldflags "$(govvv -flags)" -o ${APP}-linux-arm
echo -e "\t\t${GREEN}... done${NC}"
echo -e "\nstipping arm binary:"
strip -o ${TARGET}-linux-arm-stripped ${TARGET}-linux-arm
echo -e "\t\t${GREEN}... done${NC}"
}
#######################################################################################
# checks
echo -e "${NC}\n "
if [ ! command -v govvv &> /dev/null ] ; then
die "govvv is not installed"
fi
if [ $# -eq 0 ] ; then
echo -e "\nbuilding for default TARGET ${DEFAULT_TARGET}..."
TARGET=${DEFAULT_TARGET}
else
TARGET=$1
fi
#######################################################################################
# build
#cd /src
if [ "$2" == "all" ] ; then
echo -e "\nforce rebuilding of all packages..."
GO_BUILD_OPTIONS="-a -v"
fi
case "${TARGET}" in
"arm"|"ARM")
build_linux_arm
;;
"amd64"|"AMD64")
build_linux_amd64
;;
*)
usage
die "Target ${TARGET} is not defined"
;;
esac