# Description: A shell parser, formatter, and interpreter with bash support
# URL: https://github.com/mvdan/sh
# Maintainer: Tim Biermann, tbier at posteo dot de
# Depends on: go
# Optional: scdoc

name=shfmt
version=3.13.1
release=1
source=(https://github.com/mvdan/sh/archive/v$version/$name-$version.tar.gz)

build() {
  cd sh-$version/cmd/shfmt

  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"

  mkdir "$PKGMK_SOURCE_DIR/gopath" || true
  export GOPATH="$PKGMK_SOURCE_DIR/gopath"

  go build \
    -trimpath \
    -buildmode=pie \
    -mod=readonly \
    -modcacherw \
    -o shfmt .

  install -Dm755 shfmt $PKG/usr/bin/shfmt
  if prt-get isinst scdoc; then
    scdoc < shfmt.1.scd | gzip > shfmt.1.gz
    install -Dm644 -t $PKG/usr/share/man/man1/ shfmt.1.gz
  fi
}
