102 lines
2.2 KiB
Bash
Executable File
102 lines
2.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
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:"
|
|
|
|
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:"
|
|
|
|
# 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
|
|
|
|
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 ${APP}-linux-arm-stripped ${APP}-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
|
|
|