# -*- 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.7
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  900d677ee29e2a54126bcfd8e019abe5c1e7faff \
                    sha256  b2183bf35e4294020421b7f7717fb4481c9cc91d7f1c363a3f48b809b844e22f \
                    size    9004

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}
}
