#!/usr/bin/env sh set -euo pipefail ROOT="$(cd -- "$(dirname "$0")/.." && pwd)" BIN_DIR="$ROOT/bin" BIN="$BIN_DIR/img2pdf" GOFLAGS_DEFAULT="-tags=wayland" CGO_CFLAGS_DEFAULT="-D_GNU_SOURCE" # Keep caches inside the repo to avoid $HOME permission issues. export GOCACHE="${GOCACHE:-$ROOT/.cache/go-build}" export GOMODCACHE="${GOMODCACHE:-$ROOT/.cache/go-mod}" export GOFLAGS="${GOFLAGS:-$GOFLAGS_DEFAULT}" export CGO_CFLAGS="${CGO_CFLAGS:-$CGO_CFLAGS_DEFAULT}" export CGO_CXXFLAGS="${CGO_CXXFLAGS:-$CGO_CFLAGS}" mkdir -p "$GOCACHE" "$GOMODCACHE" "$BIN_DIR" patch_glfw_wayland() { # Drop the redundant _GNU_SOURCE define in GLFW's Wayland file to avoid macro redefinition warnings. local wl_file="$GOMODCACHE/github.com/go-gl/glfw/v3.3/glfw@v0.0.0-20221017161538-93cebf72946b/glfw/src/wl_window.c" if [ -f "$wl_file" ] && grep -q '^#define _GNU_SOURCE$' "$wl_file"; then chmod u+w "$wl_file" tmp="$(mktemp)" sed '/^#define _GNU_SOURCE$/d' "$wl_file" >"$tmp" && mv "$tmp" "$wl_file" fi } cd "$ROOT" patch_glfw_wayland go build -o "$BIN" ./cmd/img2pdf echo "Built: $BIN"