# -*- 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            2
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  db62393d2cd769149fc4efa843e67e83fed5ad1b \
                    sha256  089ee0af8070fc74b8cfc23ae1f74c1e120a8eea079e4b310eacb4a14cd8fd0b \
                    size    1469933

go.offline_build    no

# see https://github.com/Picocrypt-NG/Picocrypt-NG/pull/132
patchfiles-append   patch-132.diff
patch.args          -p1

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

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
}
