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

github.setup            biscuitehh pam-watchid 6061b86e96c766085718d4589c974184d86cf1d3
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from     tarball
version                 20201011
revision                0
platforms               {darwin >= 19}
categories              security
maintainers             {i0ntempest @i0ntempest} openmaintainer
license                 public-domain

description             PAM plugin module that allows the Apple Watch to be used for authentication
long_description        A PAM plugin that allows the Apple Watch to be used for authentication, \
                        using the new kLAPolicyDeviceOwnerAuthenticationWithBiometricsOrWatch \
                        API in macOS 10.15, written in Swift.

checksums               rmd160  961cae147fbd38e0133cfcfa7e970fa2ace41eee \
                        sha256  48c5f07c8b8495e348ed2416fa5f3e5ef89ab8ec9155652e58b564f552c08283 \
                        size    1312638

# Makefile fix-ups and enable verbose
post-patch {
    reinplace "s| = | ?= |g" ${worksrcpath}/Makefile
    reinplace "s|install: all|install:|" ${worksrcpath}/Makefile
    reinplace "s|swiftc|swiftc -v|g" ${worksrcpath}/Makefile
}

build.env-append        TARGET=${build_arch}-apple-darwin${os.major}
destroot.env-append     DESTINATION=${destroot}${prefix}/lib/pam
universal_variant       no

notes-append "
    Edit /etc/pam.d/sudo to include the following line as the first line (not including comments)\
    to enable authentication with Apple Watch for sudo:
    auth       sufficient     ${prefix}/lib/pam/pam_watchid.so       \"reason=execute a command as root\"
    
    Remove this line before uninstalling this port or sudo will stop working.
"

if {${os.platform} eq "darwin" && ${os.major} == 19} {
    # Fix "error: redefinition of module 'libxml2'"
    use_xcode yes
}