# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           github 1.0

# Not planning to update minio past this version for minio port; major breaking
# change. Keeping minio-mc at matching revision.
version             2022-10-22T03-39-29Z
set commit          88796ea618092bb27368c00e2b387857945357fb

set relversion      [regsub {(T..)-(..)-(..Z)} $version {\1:\2:\3}]
# This is not used for fetching, but is compiled into the executable

github.setup        minio mc $version RELEASE.
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
name                minio-mc
revision            0

categories          www
maintainers         {eborisch @eborisch} openmaintainer
description         Provides cloud-enabled UNIX commands like ls, cat, cp, etc.
long_description \
    {*}${description} It supports filesystems and Amazon S3 compatible cloud \
    storage service (AWS Signature v2 and v4). See minio port for server.

license             AGPL-3

checksums \
    rmd160  3eb8d89b9eace2af1d8e75c262c72c7dc01e498f \
    sha256  2508afbf5239db46233af407ba2db674a50d49a7e545d0b42f3df90def936e89 \
    size    521026

set goproj          github.com/${github.author}/${github.project}

conflicts           mc
depends_lib         port:go
use_configure       no
worksrcdir          src/${goproj}

variant altname description "Rename mc to minio-mc to avoid name conflict" {
    conflicts-delete    mc
}

post-extract {
    xinstall -d ${workpath}/src/github.com/${github.author}
    move ${workpath}/mc-${github.version} \
        ${worksrcpath}
}

build {
    system -W ${worksrcpath} "GOPATH=${workpath} GO111MODULE=on CGO_ENABLED=0  \
      ${prefix}/bin/go build -tags kqueue -v -o ${workpath}/${github.project} \
      -ldflags '-X ${goproj}/cmd.Version=${relversion} \
                -X ${goproj}/cmd.ReleaseTag=RELEASE.${version} \
                -X ${goproj}/cmd.CommitID=${commit} \
                -X ${goproj}/cmd.ShortCommitId=[string range ${commit} 0 11]'"
}

destroot {
    if {[variant_isset altname]} {
        set instname    minio-mc
    } else {
        set instname    mc
    }

    xinstall ${workpath}/mc ${destroot}${prefix}/bin/${instname}

    set docdir ${prefix}/share/doc/${instname}
    xinstall -d ${destroot}${docdir}
    xinstall -m 644 -W ${worksrcpath} \
        README.md LICENSE NOTICE ${destroot}${docdir}
}
