# Contributor: @ifurther <55025025+ifurther@users.noreply.github.com>

_realname=hugo
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.151.1
pkgrel=1
pkgdesc='A Fast and Flexible Static Site Generator built with love by bep, spf13 and friends in Go. (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://gohugo.io/'
msys2_repository_url='https://github.com/gohugoio/hugo/'
msys2_references=(
  'anitya: 12959'
  'archlinux: hugo'
  'aur: hugo-git'
  "cpe: cpe:/a:gohugo:hugo"
  'gentoo: www-apps/hugo'
  'purl: pkg:golang/github.com/gohugoio/hugo'
)
license=('spdx:Apache-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-go" "${MINGW_PACKAGE_PREFIX}-cc" "git")
optdepends=("git: To interact with repositories")
options=('!strip')
source=("https://github.com/gohugoio/hugo/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('7750d644c5ea762ba400001d753a9d37dc4f1467ca470f01cffff2b2a87c9232')

build() {
    cd "${_realname}-${pkgver}"
    export GOOS=windows
    export GOROOT=${MINGW_PREFIX}/lib/go
    export CGO_CPPFLAGS="${CPPFLAGS}"
    export CGO_CFLAGS="${CFLAGS}"
    export CGO_CXXFLAGS="${CXXFLAGS}"
    export CGO_LDFLAGS="${LDFLAGS}"
    export GO_LDFLAGS="-s -w"
    export GOFLAGS="-trimpath -mod=readonly -modcacherw -ldflags=-linkmode=external"

    go build -tags extended

    ./hugo.exe gen man
    ./hugo.exe completion bash > hugo.bash-completion
    ./hugo.exe completion fish > hugo.fish
    ./hugo.exe completion zsh > hugo.zsh
}

check() {
    cd "${_realname}-${pkgver}"
    go test
}

package() {
    cd "${_realname}-${pkgver}"
    install -Dm755 "hugo.exe" "${pkgdir}${MINGW_PREFIX}/bin/hugo.exe"
    install -Dm644 "LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
    install -Dm644 "README.md" "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/README.md"

    install -Dm644 man/*.1  -t "${pkgdir}${MINGW_PREFIX}"/share/man/man1/

    install -Dm644 hugo.bash-completion "${pkgdir}${MINGW_PREFIX}"/share/bash-completion/completions/hugo
    install -Dm644 hugo.fish "${pkgdir}${MINGW_PREFIX}"/share/fish/vendor_completions.d/hugo.fish
    install -Dm644 hugo.zsh "${pkgdir}${MINGW_PREFIX}"/share/zsh/site-functions/_hugo
}
