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

github.setup            GPGTools pinentry 1.3.1.1 v
name                    pinentry-mac
github.tarball_from     archive
categories              aqua security
license                 GPL-3+
maintainers             nomaintainer
platforms               {macosx >= 12}

description             Cocoa interface for the password entry software pinentry.
long_description        {*}${description} \
                        It is based on the upstream version of pinentry, adding a \
                        custom interface based on Cocoa for OS X look and feel.

checksums               rmd160 4a6aeedb6596b38bd7194d857362bc6e8ebeed92 \
                        sha256 ba929dd1c57b102fbfca12bc2d784be441498e7c82ee97a1231cbe03dcda7ae9

# Utilizes ARC which is x86_64/arm64-only. #45949
supported_archs         x86_64 arm64
installs_libs           no
use_xcode               yes

# The UI layout file uses Xcode 8 format and its features
# available on macOS 10.11 and newer; this patch restores compatibility
# Unfortunately, the layout makes extensive use of the Auto Layout feature,
# which has been properly implemented since Xcode 5
# (meaning it is only compatible with macOS >=10.8)
if {${os.platform} eq "darwin" && ${os.major} < 15} {
      patchfiles-append \
                        patch-xib-compatibility.diff
}

# add missing defines on macOS <10.9
if {${os.platform} eq "darwin" && ${os.major} < 13} {
      patchfiles-append \
                        patch-defines-for-legacy-sdks.diff
}

depends_build           path:bin/pkg-config:pkgconfig \
                        port:gettext

depends_lib             port:libassuan \
                        port:libgpg-error

use_autoreconf          yes
configure.args          --disable-pinentry-curses \
                        --disable-fallback-curses \
                        --disable-pinentry-tty \
                        --disable-pinentry-emacs \
                        --disable-inside-emacs \
                        --disable-pinentry-efl \
                        --disable-pinentry-gtk2 \
                        --disable-pinentry-gnome3 \
                        --disable-pinentry-qt4 \
                        --disable-pinentry-qt5 \
                        --disable-pinentry-qt \
                        --disable-pinentry-tqt \
                        --disable-pinentry-fltk \
                        --disable-libsecret \
                        --disable-doc

destroot {
    file copy ${worksrcpath}/macosx/pinentry-mac.app \
        ${destroot}${applications_dir}
}

platform macosx {
    notes   "
             If you previously didn't have pinentry or gpg-agent installed\
             and ${name} has been installed as a dependency of gpg-agent\
             you don't need to do anything to use ${name}.

             If you want to switch to the GTK2, ncurses or Qt4 based pinentry\
             program, please install pinentry with the correct use flags and\
             follow the instructions below substituting the ${name} program\
             path with ${prefix}/bin/pinentry.


             If you previously had pinentry and gpg-agent installed and would\
             like to switch to ${name}, you will have to set\
             it as your pinentry program in \$HOME/.gnupg/gpg-agent.conf.

             Add the following line to the mentioned file:
             pinentry-program ${applications_dir}/${name}.app/Contents/MacOS/${name}


             Be sure to comment previous \"pinentry-program\" lines, for example:

             pinentry-program SAMPLE

             becomes

             #pinentry-program SAMPLE


             Afterwards, run
             killall -HUP gpg-agent

             or simply log out and back in again.
            "
}
