# -*- 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
# $Id: Portfile 115137 2013-12-26 02:12:09Z jeremyhu@macports.org $

PortSystem          1.0

name                birdfont
version             0.18
revision            2
maintainers         openmaintainer gmail.com:johan.mattsson
categories          graphics
description         Font editor
long_description    ${description}
homepage            http://birdfont.org
license             GPL-3

checksums           rmd160  358f540c4fb6d8862ab416e8529e2dde6009c6d5 \
                    sha256  f1432dba6c19ee9f8d26b6680af7f6601254430d175ce4046176c90a15a29194

platforms           darwin

patchfiles          patch_use_cc_and_ldflags_install_icons_and_translations.diff

depends_build       port:pkgconfig \
                    port:vala

depends_lib         path:lib/pkgconfig/webkit-1.0.pc:webkit-gtk \
                    port:gtk2 \
                    port:libxml2

master_sites        http://birdfont.org/releases/

livecheck.type      regex
livecheck.url       http://birdfont.org/releases
livecheck.regex     birdfont-(\\d+.\\d+).tar.gz

# 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

# TODO: Fix the actual bug.  This just masks the problem to force a successful build.
if {[string match *clang* ${configure.compiler}]} {
    configure.cflags-append -Wno-return-type
}

configure.cmd       ./scripts/macport_configure.py

build.cmd           ./scripts/macport_build.py
build.args          --prefix=${prefix} \
                    --cc=${configure.cc} \
                    --cflags="${configure.cflags}" \
                    --ldflags="${configure.ldflags}"

destroot.cmd        ./scripts/macport_install.py
destroot.args       --prefix=${prefix} --dest=${destroot}

post-destroot {
    file attributes ${worksrcpath}/build/BirdFont.app/Contents/MacOS/birdfont.sh -permissions 0755
    file copy ${worksrcpath}/build/BirdFont.app ${destroot}${applications_dir}
}

# TODO: Check ${configure.cxx_stdlib} directly once MacPorts 2.3 is released
platform darwin {
    set cxxstdlib {}

    if {[info exists configure.cxx_stdlib] &&
        ${configure.cxx_stdlib} ne {} &&
        [string match *clang* ${configure.cxx}]} {
        set cxxstdlib ${configure.cxx_stdlib}
    } elseif {[string match *clang* ${configure.cxx}] &&
              ${os.major} >= 13} {
        set cxxstdlib libc++
    } else {
        set cxxstdlib libstdc++
    }

    if {${cxxstdlib} eq "libstdc++"} {
       depends_lib-delete path:lib/pkgconfig/webkit-1.0.pc:webkit-gtk
       depends_lib-append path:lib/pkgconfig/webkit-1.0.pc:webkit-gtk-2.0
    }
}
