#!/usr/bin/env sh

# SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
#
# SPDX-License-Identifier: CC0-1.0

export CGO_ENABLED=0

if ! git describe --tags --exact-match HEAD; then
    echo "Not a tagged commit, refusing to build for all platforms."
    exit 0
fi

TAG=$(git describe --tags --exact-match HEAD)
NAME=$(basename "$(pwd)")

mkdir -p "out/$TAG"

while read -r LOOP_OS LOOP_ARCH; do
    echo "Building $NAME-$LOOP_OS-$LOOP_ARCH"
    GOOS="$LOOP_OS" GOARCH="$LOOP_ARCH" go build -ldflags="-s -w" -o "out/$TAG/$NAME-$LOOP_OS-$LOOP_ARCH"
done <<EOF
aix ppc64
darwin amd64
darwin arm64
dragonfly amd64
freebsd 386
freebsd amd64
freebsd arm
illumos amd64
linux 386
linux amd64
linux arm
linux arm64
linux loong64
linux mips
linux mipsle
linux mips64
linux mips64le
linux ppc64
linux ppc64le
linux riscv64
linux s390x
netbsd 386
netbsd amd64
netbsd arm
openbsd 386
openbsd amd64
openbsd arm
openbsd arm64
plan9 386
plan9 amd64
plan9 arm
solaris amd64
windows 386
windows amd64
windows arm
windows arm64
EOF
