# Maintainer: Wu, Zhenyu <whenyu@ustc.edu>
# Contributor: Dirk Stolle

_realname=fq
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.16.0
pkgrel=1
pkgdesc="Tool, language and decoders for inspecting binary data (mingw-w64)"
arch=(any)
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/wader/fq"
msys2_changelog_url='https://github.com/wader/fq/blob/master/CHANGES.md'
msys2_references=(
  'anitya: 279636'
  'archlinux: fq'
  'gentoo: dev-util/fq'
  'purl: pkg:golang/github.com/wader/fq'
)
license=('MIT')
makedepends=('git' "${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-go")
# LTO renders GO BUILDID unreproducible: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108534
options=(!lto)
source=("${url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('c0bfc8caa6ecb0ca558a803d704316b1cdde18fda96e77836c0d95c2bcdb2ee6')

prepare() {
  cd "${_realname}-${pkgver}"
  mkdir -p dist/
}

build() {
  cd "${_realname}-${pkgver}"

  # set Go flags
  export CC=cc
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"

  go build \
    -trimpath \
    -buildmode=pie \
    -mod=readonly \
    -modcacherw \
    -ldflags "-linkmode external -extldflags \"${LDFLAGS}\" ${_BUILDINFO}" \
    -o dist/fq.exe \
    .
}

package() {
  cd "${_realname}-${pkgver}"
  install -Dm 755 "dist/${_realname}.exe" -t "${pkgdir}/$MINGW_PREFIX/bin"
  install -Dm 644 LICENSE  -t "${pkgdir}/$MINGW_PREFIX/share/licenses/${_realname}"
  install -Dm 644 README.md -t "${pkgdir}/$MINGW_PREFIX/share/doc/${_realname}"
}

# vim:set ts=2 sw=2 et:
