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

set csname          CoreLocationCLI
github.setup        fulldecent [string tolower ${csname}] 4.0.6
github.tarball_from archive
revision            0
platforms           {darwin >= 19}
categories          sysutils
license             MIT
maintainers         {i0ntempest @i0ntempest} openmaintainer

description         Command line program to print location information from CoreLocation
long_description    ${csname} gets the physical location of your device and prints it to standard output.\
                    If you move it can also print your updated location.

checksums           rmd160  0d6d9c9f17080a625249618d2fc75ef4f594887a \
                    sha256  611323f1194c10c1f777a9f528d24da37242a0adcb6946607475ac32b07f87b1 \
                    size    11745

use_configure       no
universal_variant   yes

post-patch {
    system -W ${worksrcpath} "/usr/libexec/PlistBuddy -c \"Set :CFBundleShortVersionString ${version}\" Info.plist"
}

build.cmd           swiftc
build.target        Sources/${csname}/main.swift
build.args          -O -whole-module-optimization -o ${csname}

if {${universal_possible} && [variant_isset universal]} {
    foreach arch "${muniversal.architectures}" {
        build.args.${arch}-append -target "${arch}-${triplet.vendor}-${triplet.os}"
    }
}

destroot {
    # Binary must be packaged as an app and signed to pass macOS Privacy checks and function properly
    # But it does not have a GUI so not putting it into ${applications_dir}
    file mkdir ${destroot}${prefix}/libexec/${name}/${csname}.app/Contents/MacOS/
    xinstall -m 755 ${worksrcpath}/${csname} ${destroot}${prefix}/libexec/${name}/${csname}.app/Contents/MacOS/
    xinstall -m 644 ${worksrcpath}/Info.plist ${destroot}${prefix}/libexec/${name}/${csname}.app/Contents/
    system -W ${destroot}${prefix}/libexec/${name} "/usr/bin/codesign --sign - --deep --force ${csname}.app"
    ln -s ${prefix}/libexec/${name}/${csname}.app/Contents/MacOS/${csname} ${destroot}${prefix}/bin/${name}
}
