# -*- 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
# $Id: Portfile 114348 2013-12-05 15:13:10Z ryandesign@macports.org $

PortSystem          1.0
PortGroup           cmake 1.0
PortGroup           muniversal 1.0

name                graphite2
version             1.2.4
categories          graphics
platforms           darwin
maintainers         ryandesign openmaintainer
license             LGPL-2.1+

description         a “smart font” system for lesser-known languages

long_description    Graphite is a “smart font” system developed specifically \
                    to handle the complexities of lesser-known languages of \
                    the world.

homepage            http://graphite.sil.org/
master_sites        sourceforge:project/silgraphite/graphite2
extract.suffix      .tgz

checksums           rmd160  a4adc89befc86a9adcab3b0dbd6caf2ac3866fb4 \
                    sha256  4bc3d5168029bcc0aa00eb2c973269d29407be2796ff56f9c80e10736bd8b003

patchfiles          missing-include.patch \
                    patch-src-CMakeLists.txt.diff

# gcc version 4.0.1 (Apple Computer, Inc. build 5370) (from Xcode 2.5 on Tiger) is affected.
# apple-gcc42 @5666.3_10 doesn't contain a c++ compiler so it falls back to the affected Xcode compiler.
# gcc version 4.0.1 (Apple Inc. build 5493) (from Xcode 3.1.4 on Leopard) is not affected.
# Other versions of gcc 4.0 not tested. Later versions of gcc are not affected.
platform darwin 8 {
    post-patch {
        # https://sourceforge.net/p/silgraphite/bugs/50/
        reinplace "s|-fno-stack-protector||g" ${worksrcpath}/src/CMakeLists.txt ${worksrcpath}/tests/CMakeLists.txt
    }
}

post-patch {
    # https://trac.macports.org/ticket/37947
    # https://sourceforge.net/p/silgraphite/bugs/54/
    reinplace "/add_subdirectory(featuremap)/d" ${worksrcpath}/tests/CMakeLists.txt
}

# fix upgrade failure
configure.cppflags-replace -I${prefix}/include -isystem${prefix}/include

test.run            yes
test.env            DYLD_LIBRARY_PATH=${worksrcpath}/src

pre-test {
    # https://sourceforge.net/p/silgraphite/bugs/48/
    set python_installed_version [strsed [exec python --version 2>@1] {g/Python //}]
    set python_minimum_version 2.6
    if {[vercmp ${python_installed_version} ${python_minimum_version}] < 0} {
        ui_error "Testing ${name} requires Python ${python_minimum_version} or later but your “python” is version ${python_installed_version}."
        return -code error "incompatible python version"
    }
}

# Disable segment caching code on PowerPC where it fails to build.
# https://sourceforge.net/p/silgraphite/bugs/49/
set merger_configure_args(ppc) -DGRAPHITE2_NSEGCACHE:BOOL=ON
set merger_configure_args(ppc64) -DGRAPHITE2_NSEGCACHE:BOOL=ON
if {![variant_isset universal] && [info exists merger_configure_args(${configure.build_arch})]} {
    configure.args-append $merger_configure_args(${configure.build_arch})
}

livecheck.regex     /${name}-(\[0-9.\]+)${extract.suffix}
