# -*- 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            otfried ipe-tools 7.2.24.1 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from     tarball

revision                0
categories              graphics
maintainers             {gmx.de:Torsten.Maehne @maehne} \
                        openmaintainer
license                 {GPL-2 GPL-3}

description             Tools for the Ipe extensible drawing editor

long_description        The following tools for the Ipe extensible drawing \
                        editor are provided: \
                        svgtoipe, pdftoipe, figtoipe, ipe5toxml

homepage                https://ipe.otfried.org/

checksums               rmd160  0d86d01aa3e6d3038bab29e385342d2d98303892 \
                        sha256  1cf2f639c434f2239fd7ecd4e059f4c8912109e65d81bf7fbb1c34b71aeb708e \
                        size    239310

# pdftoipe patches from https://aur.archlinux.org/packages/ipe-tools-git
patchfiles              patch-svgtoipe-svgtoipe.py.diff \
                        pdftoipe-c++20.patch \
                        pdftoipe-fix-building-with-poppler.patch \
                        pdftoipe-fix-poppler-xmloutput.patch

post-patch {
    reinplace "s|__MP_PYTHON_BIN__|${prefix}/bin/python3|" ${worksrcpath}/svgtoipe/svgtoipe.py
}

set python.pkgd ${frameworks_dir}/Python.framework/Versions/3.12/lib/python3.12/site-packages
depends_build           path:bin/pkg-config:pkgconfig
depends_lib             path:lib/pkgconfig/poppler.pc:poppler \
                        path:${python.pkgd}/PIL:py312-Pillow

# cc1plus: error: unrecognized command line option "-std=c++20"
compiler.cxx_standard   2020

use_configure           no
use_parallel_build      no

set build_env "CPPFLAGS+='${configure.cppflags}'\
               CFLAGS+='${configure.cppflags} ${configure.cflags} ${configure.cc_archflags}'\
               CXXFLAGS+='${configure.cxxflags} ${configure.cxx_archflags}'\
               LDFLAGS+='${configure.cc_archflags}'\
               CC='${configure.cc}' CXX='${configure.cxx}'"

build {
        system -W ${worksrcpath}/figtoipe "${build_env} ${build.cmd} ${build.target} CXX=${configure.cxx}"
        system -W ${worksrcpath}/ipe5toxml "${build_env} ${build.cmd}"
        system -W ${worksrcpath}/pdftoipe "${build_env} CC=${configure.cxx} ${build.cmd} ${build.target}"
}

destroot {
        xinstall -m 755 ${worksrcpath}/figtoipe/figtoipe ${destroot}${prefix}/bin
        xinstall -m 644 ${worksrcpath}/figtoipe/figtoipe.1 ${destroot}${prefix}/share/man/man1
        xinstall -m 755 ${worksrcpath}/ipe5toxml/ipe5toxml ${destroot}${prefix}/bin
        xinstall -m 644 ${worksrcpath}/ipe5toxml/ipe5toxml.1 ${destroot}${prefix}/share/man/man1
        xinstall -m 755 ${worksrcpath}/pdftoipe/pdftoipe ${destroot}${prefix}/bin
        xinstall -m 644 ${worksrcpath}/pdftoipe/pdftoipe.1 ${destroot}${prefix}/share/man/man1
        xinstall -m 755 ${worksrcpath}/svgtoipe/svgtoipe.py ${destroot}${prefix}/bin
}
