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

name                    freetype
version                 2.13.3
revision                0
set docdistname         ${name}-doc-${version}
use_xz                  yes
checksums               ${distname}${extract.suffix} \
                        rmd160  7cba05b86a0ff15029fcef0e567ecc3d3e3df499 \
                        sha256  0550350666d427c74daeb85d5ac7bb353acba5f76956395995311a9c6f063289 \
                        size    2617564 \
                        ${docdistname}${extract.suffix} \
                        rmd160  5bb361e95f142f43c55c9918e88b696fe05d2504 \
                        sha256  b7b66149bea769e226fd3d6d1eee6160e5b6beb4249b088071434fbe85fd1070 \
                        size    2173852

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           port:pkgconfig

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

# __builtin_bswap16
# https://gitlab.freedesktop.org/freetype/freetype/-/issues/1260
compiler.blacklist      {clang < 500}

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-png \
                        --with-zlib \
                        --without-harfbuzz \
                        --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.]+)/}
