Files
uosc/tools/build
tomasklaen c173641ea5 chore: restructured repo to eliminate dist directory
As pointed out in #757, having scripts in `dist` would cause github's code indexing to ignore them.

This also updates packaging tool/scripts, which before wouldn't mark binaries placed inside `uosc.zip` as executable when built on windows. I can't believe there is no CLI tool on windows to do this and I had to write one in go...
2023-11-01 11:08:23 +01:00

82 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# Script to build one of uosc binaries.
# Requirements: go, upx (if compressing)
# Usage: tools/build <name> [-c]
# <name> 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="./dist/scripts/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 --brute "$out_dir/ziggy-windows.exe"
upx --brute "$out_dir/ziggy-linux"
upx --brute "$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 <name> [-c]"
echo "<name> can be: tools, ziggy"
echo "-c enables binary compression (requires upx)"
fi