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

name                DiskJockey
version             2.1
checksums           rmd160  5a3735730c87cbec6c42c6a09574b44578905f1e \
                    sha256  a27ddaf46a1deee57da30dfcd47530b09b80d45fd293e0c745af6c1251698f7d \
                    size    7737747
if {${subport} eq ${name}} {
    revision        0
}
subport djjr {
    revision        0
}

categories          aqua
maintainers         {ryandesign @ryandesign} openmaintainer

description         program for creating, analyzing, and converting \
                    disk images for emulators and devices like \
                    BlueSCSI and RaSCSI

long_description    ${name} is a macOS GUI application that can create \
                    disk images of arbitrary size or using presets for \
                    vintage Mac models, partitioned and with drivers \
                    installed, ready for use with devices like \
                    BlueSCSI and RaSCSI. It can also show the contents \
                    of HFS and MFS disk images and convert disk images \
                    between formats. The companion command line \
                    utility djjr is available in a separate port.

homepage            https://bluescsi.onegeekarmy.eu/diskjockey/
master_sites        https://bluescsi.onegeekarmy.eu/files/
distname            Disk-Jockey-v${version}
use_zip             yes

extract.mkdir       yes

use_configure       no

variant universal {}

# The pre-compiled app is built for these architectures.
supported_archs     arm64 x86_64

set appname         {Disk Jockey}
set app             ${appname}.app

build {
    if {${subport} eq ${name}} {
        set files [list ${app}/Contents/MacOS/${appname}]
    } else {
        set files [list ${subport}]
    }

    if {![variant_exists universal] || ![variant_isset universal]} {
        foreach file ${files} {
            system -W ${worksrcpath} \
                "lipo -thin ${configure.build_arch} [shellescape ${file}] -output [shellescape ${file}]"
        }
    }
}

if {${subport} eq ${name}} {
    destroot {
        copy ${worksrcpath}/${app} ${destroot}${applications_dir}
    }
} elseif {${subport} eq "djjr"} {
    description     command line disk image builder
    long_description \
                    Disk Jockey Jr is a disk image builder that runs on the command line.

    homepage        ${homepage}#disk-jockey-jr-djjr

    depends_extract-append \
                    bin:gunzip:gzip \
                    bin:xar:xar

    post-extract {
        system -W ${worksrcpath} "xar -xf [shellescape "${app}/Contents/SharedSupport/${appname} Jr.pkg"] Payload"
        system -W ${worksrcpath} "gunzip -c Payload | cpio -idmu --quiet usr/local/bin/${subport}"
        move ${worksrcpath}/usr/local/bin/${subport} ${worksrcpath}/${subport}
        delete ${worksrcpath}/usr
    }

    destroot {
        copy ${worksrcpath}/${subport} ${destroot}${prefix}/bin
    }
}

if {${os.platform} ne "darwin" || ${os.major} < 15} {
    known_fail      yes
    pre-fetch {
        ui_error "${subport} @${version} requires OS X 10.11 or greater"
        return -code error "incompatible OS X version"
    }
}

if {${subport} eq ${name}} {
    livecheck.type  regex
    livecheck.url   ${homepage}
    livecheck.regex {>Disk Jockey v([0-9.]+)<}
} else {
    livecheck.type  none
}
