2020-09-02 10:54:03 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-09-05 07:49:21 +02:00
|
|
|
APP=mqttListener
|
2020-09-02 10:54:03 +02:00
|
|
|
|
2020-09-04 12:44:54 +02:00
|
|
|
# expand PATH for go tools
|
2020-09-02 18:02:40 +02:00
|
|
|
export PATH=$PATH:~/go/bin
|
2020-09-02 10:54:03 +02:00
|
|
|
|
|
|
|
|
2020-09-02 18:02:40 +02:00
|
|
|
RED='\e[0;31m'
|
|
|
|
GREEN='\e[0;32m'
|
|
|
|
LIGHT_YELLOW='\e[93m'
|
|
|
|
NC='\e[0m' # No Color
|
|
|
|
BOLD='\e[1m'
|
|
|
|
NORMAL='\e[21m'
|
|
|
|
|
2020-09-04 12:44:54 +02:00
|
|
|
#######################################################################################
|
|
|
|
# defaults
|
|
|
|
GO_BUILD_OPTIONS=-v
|
|
|
|
#GO_BUILD_OPTIONS="-a -v"
|
|
|
|
DEFAULT_TARGET=amd64
|
2020-09-02 18:02:40 +02:00
|
|
|
|
|
|
|
#######################################################################################
|
|
|
|
# functions
|
|
|
|
|
|
|
|
die() { echo -e "\n${RED}$@${NC}" 1>&2 ; exit 1; }
|
|
|
|
|
2020-09-04 12:44:54 +02:00
|
|
|
usage() {
|
|
|
|
echo "usage: `basename $0` [<TARGET>] [all]"
|
|
|
|
}
|
2020-09-02 18:02:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
#######################################################################################
|
2020-09-04 12:44:54 +02:00
|
|
|
# build functions
|
2020-09-02 18:02:40 +02:00
|
|
|
|
2020-09-04 12:44:54 +02:00
|
|
|
build_linux_amd64() {
|
|
|
|
echo -e "\nBuilding for Linux amd64:"
|
2020-09-13 17:57:50 +02:00
|
|
|
|
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
|
2020-09-04 12:44:54 +02:00
|
|
|
echo -e "\t\t${GREEN}... done${NC}"
|
|
|
|
}
|
|
|
|
|
|
|
|
build_linux_arm() {
|
|
|
|
echo -e "\nBuilding for arm:"
|
2020-09-13 17:57:50 +02:00
|
|
|
|
|
|
|
# setup environment
|
|
|
|
export CGO_ENABLED=1
|
|
|
|
export PATH=$PATH:/opt/devel/ptu4/buildrootBuild/host/usr/bin
|
|
|
|
export CC=arm-linux-gcc
|
|
|
|
export PKG_CONFIG_PATH=/opt/devel/ptu4/buildrootBuild/host/usr/lib/pkgconfig
|
|
|
|
|
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
|
2020-09-04 12:44:54 +02:00
|
|
|
echo -e "\t\t${GREEN}... done${NC}"
|
|
|
|
|
|
|
|
echo -e "\nstipping arm binary:"
|
2020-09-13 17:57:50 +02:00
|
|
|
strip -o ${TARGET}-linux-arm-stripped ${APP}-linux-arm
|
2020-09-04 12:44:54 +02:00
|
|
|
echo -e "\t\t${GREEN}... done${NC}"
|
|
|
|
}
|
2020-09-02 10:54:03 +02:00
|
|
|
|
2020-09-04 12:44:54 +02:00
|
|
|
#######################################################################################
|
|
|
|
# checks
|
|
|
|
|
|
|
|
echo -e "${NC}\n "
|
|
|
|
|
|
|
|
|
|
|
|
if [ ! command -v govvv &> /dev/null ] ; then
|
|
|
|
die "govvv is not installed"
|
2020-09-02 18:02:40 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
2020-09-04 12:44:54 +02:00
|
|
|
if [ $# -eq 0 ] ; then
|
|
|
|
echo -e "\nbuilding for default TARGET ${DEFAULT_TARGET}..."
|
|
|
|
TARGET=${DEFAULT_TARGET}
|
|
|
|
else
|
|
|
|
TARGET=$1
|
|
|
|
fi
|
2020-09-02 18:02:40 +02:00
|
|
|
|
|
|
|
#######################################################################################
|
|
|
|
# build
|
|
|
|
|
2020-09-04 12:44:54 +02:00
|
|
|
#cd /src
|
|
|
|
|
|
|
|
|
|
|
|
if [ "$2" == "all" ] ; then
|
|
|
|
echo -e "\nforce rebuilding of all packages..."
|
|
|
|
GO_BUILD_OPTIONS="-a -v"
|
|
|
|
fi
|
2020-09-02 10:54:03 +02:00
|
|
|
|
|
|
|
|
2020-09-04 12:44:54 +02:00
|
|
|
case "${TARGET}" in
|
|
|
|
"arm"|"ARM")
|
|
|
|
build_linux_arm
|
|
|
|
;;
|
|
|
|
"amd64"|"AMD64")
|
|
|
|
build_linux_amd64
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage
|
|
|
|
die "Target ${TARGET} is not defined"
|
|
|
|
;;
|
|
|
|
esac
|
2020-09-02 10:54:03 +02:00
|
|
|
|