build.sh

#!/bin/sh
# Build the native application with this system's Go, C compiler, and GTK4 SDK.
set -eu

usage() {
    cat <<'EOF'
Usage: ./build.sh [--clean | --help]

  (no option)  Build ./splotch-blot from ./cmd/native with GTK4 enabled.
  --clean      Remove ./splotch-blot and exit (does not clean Go's cache).
  --help       Show this help.

Run this in a Linux environment with Go, a C compiler, and GTK4 development
headers installed. It does not install packages or build an AppImage/.deb.
EOF
}

if [ "$#" -gt 1 ]; then
    usage >&2
    exit 2
fi
case "${1:-}" in
    '') ;;
    --help) usage; exit 0 ;;
    --clean) ;;
    *) usage >&2; exit 2 ;;
esac

root=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
if [ "${1:-}" = --clean ]; then
    rm -f -- "$root/splotch-blot"
    printf 'Removed %s/splotch-blot (if present).\n' "$root"
    exit 0
fi

cd -- "$root"
# cgo's link probe declares function pointers as extern void name(). Keep the
# pre-C23 meaning (unspecified parameters), including for libc's free symbol.
export CGO_CFLAGS="${CGO_CFLAGS:--O2 -g} -std=gnu17"
CGO_ENABLED=1 go build -tags gtk -o splotch-blot ./cmd/native
printf 'Built %s/splotch-blot\n' "$root"