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

go.setup            github.com/Picocrypt-NG/Picocrypt-NG 2.10
name                [string tolower ${go.project}]
revision            1
categories          security
maintainers         {i0ntempest @i0ntempest} openmaintainer
license             GPL-3

description         very small, very simple, yet very secure encryption tool
long_description    ${name} is a ${description} that you can use to protect your files. It's designed\
                    to be the go-to tool for file encryption, with a focus on security, simplicity, and\
                    reliability. ${name} uses the secure XChaCha20 cipher and the Argon2id key derivation\
                    function to provide a high level of security.

dist_subdir         ${name}/${version}_${revision}

checksums           rmd160  488a144d525ed4239edc85de39f31b8aca40423f \
                    sha256  e333ad0e15d6391ec500f62f0cd8bb9be222461deddff9f9e36bdcffbfdf126d \
                    size    1465988

go.offline_build    no

post-patch {
    system -W ${worksrcpath}/dist/macos "/usr/libexec/PlistBuddy -c \"Set :CFBundleShortVersionString ${version}\" Info.plist"
    system -W ${worksrcpath}/dist/macos "/usr/libexec/PlistBuddy -c \"Set :CFBundleVersion ${version}\" Info.plist"
    system -W ${worksrcpath}/dist/macos "/usr/libexec/PlistBuddy -c \"Set :LSMinimumSystemVersion ${macosx_deployment_target}\" Info.plist"
    system -W ${worksrcpath}/dist/macos "/usr/libexec/PlistBuddy -c \"Delete :CFBundleDocumentTypes:0:CFBundleTypeIconFile\" Info.plist"
    system -W ${worksrcpath}/dist/macos "/usr/libexec/PlistBuddy -c \"Delete :UTExportedTypeDeclarations:0:UTTypeIconFile\" Info.plist"
}

build.args          -ldflags='-s -w' -o ${go.project}
build.post_args     ./cmd/[lindex [split ${name} '-'] 0]
build.dir           ${worksrcpath}/src

destroot {
    # Build app bundle manually with provided plist
    set app_path ${applications_dir}/${go.project}.app/
    set dest_app_path ${destroot}${app_path}
    foreach d {Resources MacOS} {
        xinstall -d ${dest_app_path}/Contents/$d/
    }
    xinstall -m 0755 ${worksrcpath}/src/${go.project} ${dest_app_path}/Contents/MacOS/
    xinstall -m 0644 ${worksrcpath}/dist/macos/iconSmall.icns ${dest_app_path}/Contents/Resources/icon.icns
    xinstall -m 0644 ${worksrcpath}/dist/macos/Info.plist ${dest_app_path}/Contents/
    set fp [open ${dest_app_path}/Contents/PkgInfo w]
    puts -nonewline ${fp} "APPL????"
    close ${fp}
    system -W ${destroot}${applications_dir} "/usr/bin/codesign --sign - ${go.project}.app"
    ln -s ${app_path}/Contents/MacOS/${go.project} ${destroot}${prefix}/bin/[string tolower ${go.project}]-cli
}
