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

gitlab.instance             https://gitlab.freedesktop.org
gitlab.setup                fontconfig fontconfig 2.18.2
revision                    0
checksums                   rmd160  ffab1a88d47ae05beeb75b0baa43879e905717f6 \
                            sha256  cf8e6576ef0484c15079bdaf77cd9c51c464df5365814ada4d3ee7331ea31eb5 \
                            size    1347988

categories                  graphics
maintainers                 {ryandesign @ryandesign}
license                     fontconfig

description                 An XML-based font configuration API for X Windows
long_description            Fontconfig is a library for configuring and \
                            customizing font access.

homepage                    https://www.freedesktop.org/wiki/Software/fontconfig/
# the tarball from GitLab has no configure script, this appears to be the "release"
# but the gitlab PG does not support this. See: https://trac.macports.org/ticket/71113
master_sites                https://gitlab.freedesktop.org/api/v4/projects/890/packages/generic/fontconfig/${version}
use_xz                      yes

set python_version          3.14

depends_build-append        port:gettext \
                            path:bin/pkg-config:pkgconfig \
                            port:python[string map {. {}} ${python_version}]

depends_lib                 port:expat \
                            port:freetype \
                            port:gettext-runtime \
                            port:libiconv

set add_fonts               "/usr/X11/lib/X11/fonts ${prefix}/share/fonts"
set docdir                  ${prefix}/share/doc/${name}

patchfiles-append           patch-docbook-4.2.diff
patchfiles-append           no-json-c.patch

configure.checks.implicit_function_declaration.whitelist-append strchr
configure.args              --disable-silent-rules \
                            --enable-iconv \
                            --enable-shared \
                            --enable-static \
                            --with-expat=${prefix} \
                            --with-libiconv=${prefix} \
                            --with-libiconv-prefix=${prefix} \
                            --with-libintl-prefix=${prefix} \
                            HASDOCBOOK=no
configure.python            ${prefix}/bin/python${python_version}

# We put this into a pre-configure block so it can be evaluated _after_ platform selection.
pre-configure {
    configure.args-append   --with-add-fonts=[join ${add_fonts} ,]

    # Fix building for older macOS versions via MACOSX_DEPLOYMENT_TARGET
    # https://bugs.freedesktop.org/show_bug.cgi?id=102986
    if {${os.platform} eq "darwin" && [vercmp ${macos_version} >= 10.12]} {
        if {[vercmp ${macosx_deployment_target} < 10.12]} {
            configure.args-append ac_cv_func_mkostemp=no
        }
    }
}

post-destroot {
    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath} \
        AUTHORS \
        COPYING \
        NEWS \
        README.md \
        ${destroot}${docdir}
}

post-activate {
    # fc-cache can fail due to /Network/Library/Fonts being unavailable, so force success.
    system "${prefix}/bin/fc-cache -sv || true"
    system "${prefix}/bin/fc-cache -v || true"
}

pre-pkg {
    xinstall -m 0755 ${filespath}/postinstall ${package.scripts}/
    reinplace -locale C "s|@PREFIX@|${prefix}|g" ${package.scripts}/postinstall
    long_description-append  Install prefix: ${prefix}
}

platform macosx {
    lappend add_fonts       /Library/Fonts \
                            /Network/Library/Fonts \
                            /System/Library/Fonts
}

merger_arch_flag            no
merger_arch_compiler        yes
if {${os.arch} eq "i386"} {
    if { ${os.major} >= 10 } {
        set merger_configure_args(ppc) --with-arch=ppc
        set merger_configure_env(ppc)  CC_FOR_BUILD=${configure.cc}
    }
    set merger_configure_args(ppc64)   --with-arch=ppc64
    set merger_configure_env(ppc64)    CC_FOR_BUILD=${configure.cc}
} else {
    set merger_configure_args(i386)    --with-arch=i386
    set merger_configure_args(x86_64)  --with-arch=x86_64
    set merger_configure_env(i386)     CC_FOR_BUILD=${configure.cc}
    set merger_configure_env(x86_64)   CC_FOR_BUILD=${configure.cc}
}
