#!/usr/bin/env bash # Script to build one of uosc binaries. # Requirements: go, upx (if compressing) # Usage: tools/build [-c] # can be: tools, ziggy # -c enables binary compression with upx (only needed for builds being released) abort() { echo "Error: $1" exit 1 } if [ ! -d "$PWD/src" ]; then abort "'src' directory not found. Make sure this script is run in uosc's repository root as current working directory." fi if [ "$1" = "tools" ]; then export GOARCH="amd64" src="./src/tools/tools.go" out_dir="./tools" echo "Building for Windows..." export GOOS="windows" go build -ldflags "-s -w" -o "$out_dir/tools.exe" $src echo "Building for Linux..." export GOOS="linux" go build -ldflags "-s -w" -o "$out_dir/tools-linux" $src echo "Building for MacOS..." export GOOS="darwin" go build -ldflags "-s -w" -o "$out_dir/tools-darwin" $src if [ "$2" = "-c" ]; then echo "Compressing binaries..." upx --brute "$out_dir/tools.exe" upx --brute "$out_dir/tools-linux" upx --brute "$out_dir/tools-darwin" fi unset GOARCH unset GOOS elif [ "$1" = "ziggy" ]; then export GOARCH="amd64" src="./src/ziggy/ziggy.go" out_dir="./src/uosc/bin" if [ ! -d $out_dir ]; then mkdir -pv $out_dir fi echo "Building for Windows..." export GOOS="windows" go build -ldflags "-s -w" -o "$out_dir/ziggy-windows.exe" $src echo "Building for Linux..." export GOOS="linux" go build -ldflags "-s -w" -o "$out_dir/ziggy-linux" $src echo "Building for MacOS..." export GOOS="darwin" go build -ldflags "-s -w" -o "$out_dir/ziggy-darwin" $src if [ "$2" = "-c" ]; then echo "Compressing binaries..." upx "$out_dir/ziggy-windows.exe" upx "$out_dir/ziggy-linux" upx "$out_dir/ziggy-darwin" fi unset GOARCH unset GOOS else echo "Tool to build one of uosc binaries. Requires go to be installed and in path." echo "Requirements: go, upx (if compressing)" echo "Usage: tools/build [-c]" echo " can be: tools, ziggy" echo "-c enables binary compression (requires upx)" fi