# -*- 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.3
revision                0
categories              print graphics x11
maintainers             {ryandesign @ryandesign}
license                 {FreeType GPL-2}
homepage                https://www.${name}.org

description             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/${name}/${name}2/${version}:source \
                        sourceforge:project/${name}/${name}-docs/${version}:docs \
                        https://download.savannah.gnu.org/releases/${name}/

set docdistname         ${name}-doc-${version}
distfiles               ${distname}${extract.suffix}:source \
                        ${docdistname}${extract.suffix}:docs
checksums               ${distname}${extract.suffix} \
                        rmd160  2250215fb59ccb848986f828eecd0b4dccc89550 \
                        sha256  e61b31ab26358b946e767ed7eb7f4bb2e507da1cfefeb7a8861ace7fd5c899a1 \
                        size    4134916 \
                        ${docdistname}${extract.suffix} \
                        rmd160  3c85ecf929a694b85d9a93d42bdf4d00c71d16f4 \
                        sha256  5cff09612e151ea496877df332b4614078fcf977cfe36e6e480beae5bb9b84b2 \
                        size    2303248

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

configure.args          --with-brotli \
                        --with-bzip2 \
                        --with-harfbuzz=dynamic \
                        --with-png \
                        --with-zlib \
                        --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

platform macosx {
    if {${os.major} < 9} {
        configure.args-append \
            --with-old-mac-fonts
    }
}

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.]+)/}
