# -*- 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               golang 1.0

# Given the frequency of updates from upstream, this Portfile
# maintains a release schedule. Update every 5th release, unless
# a hotfix is necessary, only.

go.setup                github.com/blacktop/ipsw 3.1.581 v
revision                0
categories              security devel
license                 MIT
platforms               {darwin >= 19}
installs_libs           no
maintainers             {@TheRealKeto gmail.com:therealketo} openmaintainer

description             iOS/macOS Research Swiss Army Knife
long_description        {*}${description}. Everything you need to start \
                        researching Apple security and internals.

homepage                https://blacktop.github.io/ipsw

checksums               rmd160  44a3440d5dc2c2e6814c8ec4a5f95d5f43e01491 \
                        sha256  6542dfbfc3d3c76b48ff8851c76ed2498895cff83ad56a08e910c33f834db3b1 \
                        size    12708690

depends_build-append    path:bin/pkg-config:pkgconfig

depends_lib-append      path:lib/pkgconfig/libusb-1.0.pc:libusb \
                        port:unicorn

# Vendored libraries cause failure, fetch them at build time
go.offline_build        no

build.args-append       -tags libusb,unicorn \
                        -ldflags \"-X ${go.package}/cmd/ipsw/cmd.AppVersion=${version} \
                                   -X ${go.package}/cmd/ipsw/cmd.AppBuildCommit=MacPorts\"

build.post_args-append  ./cmd/${name}

post-build {
    # Generate shell completions for supported shells
    foreach shell {zsh bash fish} {
        system -W ${worksrcpath} "./${name} completion ${shell} > ipsw.${shell}"
    }

    # Generate individual command manpages
    file mkdir ${worksrcpath}/man
    system "${worksrcpath}/${name} man ${worksrcpath}/man"
}

destroot {
    xinstall -m 755 ${worksrcpath}/${name} ${destroot}${prefix}/bin/${name}
    file copy {*}[glob ${worksrcpath}/man/*.1] \
        ${destroot}${prefix}/share/man/man1/

    xinstall -d ${destroot}${prefix}/share/zsh/site-functions
    xinstall -m 644 ${worksrcpath}/${name}.zsh \
        ${destroot}${prefix}/share/zsh/site-functions/_${name}

    xinstall -d ${destroot}${prefix}/share/bash-completion/completions
    xinstall -m 644 ${worksrcpath}/${name}.bash \
        ${destroot}${prefix}/share/bash-completion/completions/${name}

    xinstall -d ${destroot}${prefix}/share/fish/vendor_completions.d
    xinstall -m 644 ${worksrcpath}/${name}.fish \
        ${destroot}${prefix}/share/fish/vendor_completions.d

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