# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.su>

_realname=minio
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2025.10.15
_timever=T17-29-55Z
_pkgver="${pkgver//./-}${_timever//:/-}"
pkgrel=1
pkgdesc='Object storage server compatible with Amazon S3 (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://minio.io'
msys2_repository_url='https://github.com/minio/minio'
msys2_references=(
  'archlinux: minio'
  'cpe: cpe:2.3:a:minio:minio'
  'purl: pkg:golang/github.com/minio/minio'
)
license=('spdx:AGPL-3.0-or-later')
makedepends=("${MINGW_PACKAGE_PREFIX}-go" "${MINGW_PACKAGE_PREFIX}-cc" "git")
options=('!strip')
source=("${msys2_repository_url}/archive/RELEASE.${_pkgver}/${_realname}-RELEASE.${_pkgver}.tar.gz")
sha256sums=('be6d0bd3696c3a13a35f02d3a0280b64319c67918b4501c5c3d87f96d000085c')

build() {
  [[ -d "${srcdir}/build-${MSYSTEM}" ]] && rm -rf "${srcdir}/build-${MSYSTEM}"
  cp -r "${srcdir}/${_realname}-RELEASE.${_pkgver}" "${srcdir}/build-${MSYSTEM}"
  cd "${srcdir}/build-${MSYSTEM}" && mkdir build

  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 GOFLAGS="-trimpath -mod=readonly -modcacherw"
  case "${CARCH}" in
    i686|x86_64)
      GOFLAGS+=" -buildmode=pie"
      ;;
  esac
  export MINIO_RELEASE="RELEASE"
  GO_LDFLAGS="\
    -linkmode=external \
    -compressdwarf=false \
    $(${MINGW_PREFIX}/bin/go run buildscripts/gen-ldflags.go)"

  ${MINGW_PREFIX}/bin/go build -v \
    -ldflags "${GO_LDFLAGS}" \
    -o build \
    .
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  install -Dm755 "build/minio.exe" "${pkgdir}${MINGW_PREFIX}/bin/minio.exe"

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
