# -*- 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
PortGroup               xcodeversion 1.0

github.setup            yonaskolb Mint 0.18.0
revision                0
github.tarball_from     archive

name                    mint
categories              devel
license                 MIT
maintainers             {kylelanchman.com:macports @klanchman} openmaintainer

description             A package manager that installs and runs executable Swift packages
long_description        {*}${description}

checksums               rmd160  c38493f232c0d7ea28db427d642cba51beabc4e3 \
                        sha256  e99c0a351cf7452451d72180c8ccd18e1da710dc55d036502809a0db52779a99 \
                        size    24765

minimum_xcodeversions-append {18 11}

if {${os.platform} eq "darwin" && ${os.major} < 18} {
    known_fail yes
    pre-fetch {
        ui_error "${name} requires macOS 10.14 or later."
        return -code error "incompatible macOS version"
    }
}

# Xcode 12 (Swift 5.3) adds the --arch flag, letting us make a universal build.
set can_build_universal [expr [vercmp ${xcodeversion} 12.0] >= 0]

universal_variant       ${can_build_universal}

use_configure           no
use_xcode               yes

build.cmd               swift
build.target            build
build.args              --configuration release --disable-sandbox

set builtproductdir     ${worksrcpath}/.build/release

if {${universal_possible} && ${can_build_universal} && [variant_isset universal]} {
    foreach arch ${configure.universal_archs} {
        build.args-append --arch ${arch}
    }

    # Building universal changes the output directory of the product.
    set builtproductdir ${worksrcpath}/.build/apple/Products/Release
}

destroot {
    xinstall -m 755 ${builtproductdir}/${name} ${destroot}${prefix}/bin/
}
