# -*- 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               muniversal 1.0

name                    freetype
version                 2.14.2
revision                0
set docdistname         ${name}-doc-${version}
use_xz                  yes
checksums               ${distname}${extract.suffix} \
                        rmd160  d6628d0fb53d3e6aacb776f15c82e393c4514693 \
                        sha256  4b62dcab4c920a1a860369933221814362e699e26f55792516d671e6ff55b5e1 \
                        size    2667092 \
                        ${docdistname}${extract.suffix} \
                        rmd160  38a4561549b937e1712895fb1454601c8e92d05b \
                        sha256  0514edfd6a7b480f753aa48789d7112038a218b0b06afdca320c4bcbc2f66e6b \
                        size    2176140

categories              print graphics
maintainers             {ryandesign @ryandesign}
license                 {FreeType GPL-2}
homepage                https://www.freetype.org
use_parallel_build      yes

description \
    A software font engine

long_description \
    FreeType2 is a software font engine that is designed to \
    be small, efficient, highly customizable and portable while \
    capable of producing high-quality output (glyph images). \
    It can be used in graphics libraries, display servers, font \
    conversion tools, text image generation tools, and many \
    other products as well.

master_sites            sourceforge:project/freetype/freetype2/${version}:source \
                        sourceforge:project/freetype/freetype-docs/${version}:docs \
                        https://download.savannah.gnu.org/releases/freetype/

distfiles               ${distname}${extract.suffix}:source \
                        ${docdistname}${extract.suffix}:docs

patchfiles \
    freetype-config-no-pkg-config.patch \
    patch-src_base_ftrfork.c.diff \
    patch-modules.cfg.diff

depends_build           path:bin/pkg-config:pkgconfig

depends_lib             port:brotli \
                        port:bzip2 \
                        port:libpng \
                        port:zlib

configure.checks.implicit_function_declaration.whitelist-append strchr

# See http://trac.macports.org/ticket/18232
configure.cppflags-replace  -I${prefix}/include -isystem${prefix}/include
platform darwin {
    # Needs to use a full path with dlopen since ${prefix} is not
    # usually in the search path.
    configure.cppflags-append   {-DFT_LIBHARFBUZZ=\"${prefix}/lib/libharfbuzz.0.dylib\"}
}

configure.args          --with-brotli \
                        --with-bzip2 \
                        --with-png \
                        --with-zlib \
                        --with-harfbuzz=dynamic \
                        --without-librsvg \
                        ac_cv_prog_AWK=/usr/bin/awk

variant no_freetype_config description {Don't install the freetype-config script} {}
if {![variant_isset no_freetype_config]} {
    configure.args-append --enable-freetype-config
}

configure.universal_args-delete --disable-dependency-tracking

set docdir              ${prefix}/share/doc/${name}

post-destroot {
    xinstall -m 0755 -d ${destroot}${docdir}
    
    xinstall -m 0644 -W ${worksrcpath} \
        ChangeLog \
        LICENSE.TXT \
        README \
        ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath}/docs \
        CHANGES \
        FTL.TXT \
        GPLv2.TXT \
        PROBLEMS \
        TODO \
        formats.txt \
        raster.txt \
        ${destroot}${docdir}
    
    xinstall -m 0755 -d ${destroot}${docdir}/html
    xinstall -m 0644 -W ${worksrcpath}/docs ft2faq.html ${destroot}${docdir}/html
    foreach dir {design glyphs reference tutorial} {
        copy ${worksrcpath}/docs/${dir} ${destroot}${docdir}/html
    }
}

if {${os.arch} eq "i386"} {
    if { ${os.major}>=10 } {
        set merger_configure_env(ppc) CC_BUILD=${configure.cc}
    }
    set merger_configure_env(ppc64)   CC_BUILD=${configure.cc}
} else {
    set merger_configure_env(i386)    CC_BUILD=${configure.cc}
    set merger_configure_env(x86_64)  CC_BUILD=${configure.cc}
}

livecheck.type          sourceforge
livecheck.regex         {/freetype2/([0-9.]+)/}
