# -*- 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           cmake 1.1
PortGroup           github 1.0
PortGroup           legacysupport 1.1
PortGroup           wxWidgets 1.0

# wxcrt.h:175:66: error: 'strnlen' was not declared in this scope; did you mean 'strlen'?
legacysupport.newest_darwin_requires_legacy 10

github.setup        aardappel treesheets 14020763227
version             20250323
revision            0

checksums           rmd160  fc722f10113e4e4e81990a0576d24fe738e55ef0 \
                    sha256  1325bbe33dbd3dde160d0197ad1d809ba8c5b603f6e844935f8cbbf6e211c53b \
                    size    3229474
github.tarball_from archive

homepage            https://strlen.com/treesheets

description         Free-Form Data Organizer (Hierarchical Spreadsheet)

long_description    {*}${description}

categories          editors
license             zlib

maintainers         {gmail.com:herby.gillot @herbygillot} \
                    openmaintainer

compiler.cxx_standard \
                    2020

# TreeSheets(12970) malloc: *** error for object 0xa00a6754: pointer being freed was not allocated
legacysupport.redirect_bins TreeSheets

# Earlier fix was modified at request from upstream.
# Unfortunately, in that form it fails to have a desired effect.
# lobster/src/lobster/tools.h:33:19: error: conflicting declaration 'typedef ptrdiff_t ssize_t'
# /usr/include/string.h:70:33: note: previous declaration as 'typedef __darwin_ssize_t ssize_t'
patchfiles-append   0001-Fix-ssize_t-for-Darwin-again.patch

# CarbonCore.framework/Headers/Files.h:543:8: error: redefinition of 'struct DirInfo'
# lobster/src/lobster/platform.h:57:8: note: previous definition of 'struct DirInfo'
patchfiles-append   0002-Avoid-conflict-with-macOS-headers-over-DirInfo.patch

# Undefined symbols: "_CFBundleCopyResourcesDirectoryURL" etc.
patchfiles-append   0003-Fix-linking-on-macOS.patch

# We do not really want a bundle.
patchfiles-append   0004-Do-not-produce-a-bundle.patch

# Info.plist hardcodes an arbitrary macOS version, eh.
# post-patch {
#     reinplace "s|10.15|${macosx_deployment_target}|" ${worksrcpath}/osx/Info.plist
# }

# cmake.install_prefix \
                    ${applications_dir}

if {${os.platform} eq "darwin" && ${os.major} > 17} {
    wxWidgets.use   wxWidgets-3.2
} else {
    wxWidgets.use   wxGTK-3.2
}

depends_lib-append  port:${wxWidgets.port}

depends_run-append  port:desktop-file-utils

configure.env-append \
                    PATH=$env(PATH):${wxWidgets.prefix}/bin

build.env-append    PATH=$env(PATH):${wxWidgets.prefix}/bin

configure.args-append \
                    -DGIT_WXWIDGETS_SUBMODULES=OFF \
                    -DwxWidgets_CONFIG_EXECUTABLE=${wxWidgets.wxconfig}

post-activate {
    system "${prefix}/bin/update-desktop-database ${prefix}/share/applications"
}
