# -*- 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        HodsonTech palm365-mac 1.7 v
github.tarball_from archive
revision            0

name                palm365-mac
categories          palm python
license             {GPL-2 MIT}
maintainers         {jeff.hodson:hodsontech.com @HodsonTech} openmaintainer
conflicts           palmgoogle-mac

description         Sync a Palm OS PDA with Microsoft 365 via a jpilot plugin
long_description    palm365-mac bidirectionally syncs a Palm OS PDA's \
                    calendar, tasks, and contacts with a Microsoft 365 \
                    account. It runs automatically as a jpilot plugin -- a \
                    down-sync when jpilot launches, and a full push-up + \
                    down-sync right after every HotSync -- with no manual \
                    sync command needed day to day. One-time setup requires \
                    creating a free Microsoft 365 app registration, which \
                    ${prefix}/share/${name}/setup.py walks through. Not \
                    installable alongside palmgoogle-mac -- both are \
                    full-rebuild engines against the same Palm databases, \
                    and running two independent ones at once is a real \
                    hazard, not a supported configuration.

homepage            https://github.com/HodsonTech/palm365-mac

checksums           rmd160  331df43232f4b4a5c38f6612bf7af58b109a35cf \
                    sha256  153edd39e7812b321e22a1fb01bd576bd85988a84228eadc0b31ae353bf849b2 \
                    size    30898

set py_ver          3.14
set py_ver_nodot    [string map {. {}} ${py_ver}]

depends_build-append \
                    path:lib/pkgconfig/gtk+-3.0.pc:gtk3

depends_lib-append \
                    port:jpilot \
                    port:pilot-link \
                    port:python${py_ver_nodot} \
                    port:py${py_ver_nodot}-msal \
                    port:py${py_ver_nodot}-requests \
                    port:py${py_ver_nodot}-palm-sync-core

use_configure       no

build {
    system -W ${worksrcpath}/jpilot-plugin \
        "${configure.cc} -arch ${configure.build_arch} -bundle \
         -Wl,-undefined,dynamic_lookup \
         -DPYTHON_BIN=\\\"${prefix}/bin/python${py_ver}\\\" \
         -DSYNC_CWD=\\\"${prefix}/share/${name}\\\" \
         -I vendor \
         `${prefix}/bin/pkg-config --cflags gtk+-3.0` \
         -o libpalm365plugin.so palm365plugin.c"
}

destroot {
    xinstall -d ${destroot}${prefix}/lib/jpilot/plugins
    xinstall -m 755 ${worksrcpath}/jpilot-plugin/libpalm365plugin.so \
        ${destroot}${prefix}/lib/jpilot/plugins/

    xinstall -d ${destroot}${prefix}/share/${name}
    foreach f {config.example.toml graph_client.py graph_field_mapper.py \
               pc3_seed.py setup.py sync_to_palm.py README.md LICENSE} {
        xinstall -m 644 ${worksrcpath}/${f} ${destroot}${prefix}/share/${name}/
    }

    xinstall -d ${destroot}${prefix}/share/doc/${name}
    xinstall -m 644 ${worksrcpath}/jpilot-plugin/COPYING \
        ${destroot}${prefix}/share/doc/${name}/COPYING.plugin
}

notes "
palm365-mac needs a one-time setup step before it can sync anything --\n\
it creates a free Microsoft 365 app registration (a real Microsoft\n\
requirement, not something this port can skip) and writes your config.\n\
\n\
    cd ${prefix}/share/${name} && ${prefix}/bin/python${py_ver} setup.py\n\
\n\
After that, just launch jpilot and HotSync -- syncing happens\n\
automatically from then on, no manual commands needed.
"
