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

PortSystem          1.0
PortGroup           github 1.0
PortGroup           xcodeversion 1.0

use_xcode           yes
github.setup        Carthage Carthage 0.40.0
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
name                carthage
categories          devel

universal_variant   no
license             MIT
maintainers         {saagarjha.com:saagar @saagarjha} openmaintainer

description         A simple, decentralized dependency manager for Cocoa
long_description    {*}${description}

# Fetch from git instead of distfile because it needs submodules
fetch.type          git

use_configure       no
# everything is built during the prefix_install target
build               {}

minimum_xcodeversions-append {17 10.0}

if {${os.major} < 17} {
    known_fail      yes
    pre-fetch {
        ui_error "${name} @${version} requires macOS 10.13 or later."
        return -code error "incompatible macOS version"
    }
}

destroot {
    system -W ${worksrcpath} "${build.cmd} prefix_install PREFIX=${destroot}${prefix} CARTHAGE_TEMPORARY_FOLDER=${destroot} SWIFTPM_DISABLE_SANDBOX_SHOULD_BE_FLAGGED=should_be_flagged"

    # Install shell completions
    set completions_path ${destroot}${prefix}/share/bash-completion/completions
    xinstall -d ${completions_path}
    xinstall -m 644 ${worksrcpath}/Source/Scripts/carthage-bash-completion ${completions_path}/${name}

    set completions_path ${destroot}${prefix}/share/zsh/site-functions
    xinstall -d ${completions_path}
    xinstall ${worksrcpath}/Source/Scripts/carthage-zsh-completion ${completions_path}/_${name}

    set completions_path ${destroot}${prefix}/share/fish/vendor_completions.d
    xinstall -d ${completions_path}
    xinstall -m 644 ${worksrcpath}/Source/Scripts/carthage-fish-completion ${completions_path}/${name}.fish
}
