# -*- 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           python 1.0
PortGroup           app 1.0
PortGroup           github 1.0

name                zim
platforms           {darwin any}
supported_archs     noarch
categories          editors
maintainers         nomaintainer
license             GPL-2+

description         Personal desktop wiki
long_description \
    Zim is a graphical text editor used to maintain a collection of wiki pages. \
    Each page can contain links to other pages, simple formatting and images. \
    Pages are stored in a folder structure, like in an outliner, and can have \
    attachments. Creating a new page is as easy as linking to a nonexistent \
    page. All data is stored in plain text files with wiki formatting. Various \
    plugins provide additional functionality, like a task list manager, an \
    equation editor, a tray icon, and support for version control.

homepage            https://zim-wiki.org
github.setup        zim-desktop-wiki zim-desktop-wiki 0.75.1
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision            1
checksums           rmd160  5b5062a5634ef90fb5abe23d5b26f32e1f7842ca \
                    sha256  e24f801ab6d2c0233eaf3bd36b23672282bdc602eadee1005d9c4487642f08fe \
                    size    3212275

python.default_version  310
python.link_binaries    no
python.test_framework   ""

destroot.destdir-append \
    --install-data=${prefix}

depends_lib-append \
    path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
    port:py${python.version}-gobject3 \
    port:py${python.version}-pyxdg

depends_run-append \
    port:adwaita-icon-theme \
    port:desktop-file-utils

# Fixed after 0.75.1 release, see
# https://github.com/zim-desktop-wiki/zim-desktop-wiki/pull/2251
patchfiles          patch-2251-fix-path-parsing.diff

# Dummy variants, to ensure user's choice cascades to dependencies
variant quartz conflicts x11 {}
variant x11 conflicts quartz {}

if {![variant_isset quartz]} {
    default_variants +x11
}
if {![variant_isset x11]} {
    default_variants +quartz
}
if {![variant_isset quartz] && ![variant_isset x11]} {
    error "Either +x11 or +quartz is required"
}

pre-destroot {
    xinstall -m 755 ${filespath}/zim ${destroot}${prefix}/bin
    reinplace "s|__PREFIX__|${prefix}|g" ${destroot}${prefix}/bin/zim
    reinplace "s|__PYTHON_BINDIR__|${python.prefix}/bin|g" ${destroot}${prefix}/bin/zim
}

post-activate {
    system "${prefix}/bin/update-desktop-database -v ${prefix}/share/applications"
    system "env XDG_DATA_DIRS=${prefix}/share ${prefix}/bin/update-mime-database -Vn ${prefix}/share/mime"
}

app.create yes
app.name Zim
app.executable zim
app.icon icons/zim.ico
app.retina yes

# tests fail to start when run via 'sudo port test'
# when run manually in the destroot directory, tests all run although 3 of 984
# result in a failure.  See
# https://github.com/zim-desktop-wiki/zim-desktop-wiki/discussions/2282#discussioncomment-4595418
test.run            yes
test.cmd            ${python.bin}
test.target         test.py --verbose --debug
