# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0

name                birdfont
version             2.33.4
checksums           rmd160  efad98015eb66542eff8c5df959c26b9c3666cb2 \
                    sha256  0f688dc24b65bb71a55ba7e36389f847359fabd753bb868f77a6ec4b9c50400e \
                    size    2542704

maintainers         openmaintainer {gmail.com:johan.mattsson.m @johanmattssonm}
categories          graphics
description         Font editor
long_description    ${description}
homepage            http://birdfont.org
license             GPL-3

depends_build       port:pkgconfig \
                    port:python314 \
                    path:bin/vala:vala

depends_lib         path:lib/pkgconfig/webkit2gtk-4.1.pc:webkit2-gtk \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    path:lib/pkgconfig/cairo.pc:cairo \
                    path:lib/pkgconfig/gdk-pixbuf-2.0.pc:gdk-pixbuf2 \
                    path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
                    port:libgee \
                    port:libsoup-2.4 \
                    port:libnotify \
                    port:xmlbird

master_sites        http://birdfont.org/releases/
use_xz              yes

post-patch {
    reinplace "s|/usr/bin/python3|${prefix}/bin/python3.14|" \
        configure \
        build.py \
        install.py
}

# I'm not convinced it wouldn't be possible to build this +universal, just
# haven't had the time to find out how to pass all necessary flags
universal_variant   no

configure.cflags-append \
                    -DMAC

configure.args      --cc=${configure.cc} \
                    --cflags="${configure.cflags}" \
                    --ldflags="${configure.ldflags}" \
                    --dest="${destroot}"

build.cmd           ./build.py

destroot.cmd        ./install.py
destroot.target
destroot.args       --dest="${destroot}" \
                    --manpages-directory=/share/man/man1

post-destroot {
    # Fix install names: the build system doesn't set -install_name on macOS,
    # so dylibs have a relative build-directory path as their id.
    foreach dylib [glob ${destroot}${prefix}/lib/libbirdfont*.dylib \
                        ${destroot}${prefix}/lib/libbirdgems*.dylib] {
        if {![catch {file type $dylib} ftype] && $ftype ne "link"} {
            system "install_name_tool -id ${prefix}/lib/[file tail ${dylib}] ${dylib}"
        }
    }
    foreach bin [glob ${destroot}${prefix}/bin/birdfont*] {
        foreach dylib {libbirdfont libbirdgems} {
            catch {system "install_name_tool -change ./build/bin/${dylib}.36.0.dylib ${prefix}/lib/${dylib}.36.0.dylib ${bin}"}
            catch {system "install_name_tool -change ./build/bin/${dylib}.0.0.dylib ${prefix}/lib/${dylib}.0.0.dylib ${bin}"}
        }
    }
    # Also fix libbirdfont's reference to libbirdgems
    foreach dylib [glob ${destroot}${prefix}/lib/libbirdfont*.dylib] {
        if {![catch {file type $dylib} ftype] && $ftype ne "link"} {
            catch {system "install_name_tool -change ./build/bin/libbirdgems.0.0.dylib ${prefix}/lib/libbirdgems.0.0.dylib ${dylib}"}
        }
    }
}

livecheck.regex     "${name}-(\\d+(?:\\.\\d+)*)${extract.suffix}"
