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

# Please keep the version of the libxml2 and py-libxml2 ports the same.

name                libxml2
version             2.13.8
revision            0
checksums           rmd160  bef522c66620e210b207b02c3aedd4e46e7dbc51 \
                    sha256  277294cb33119ab71b2bc81f2f445e9bc9435b893ad15bb2cd2b0e859a0ee84a \
                    size    2423128

set branch          [join [lrange [split ${version} .] 0 1] .]
categories          textproc
maintainers         {ryandesign @ryandesign} openmaintainer
license             MIT

description         GNOME XML C parser and toolkit
long_description    Libxml is the XML C library developed for the GNOME project.  \
                    XML itself is a metalanguage to design markup languages. \
                    Though the library is written in C, a variety of language bindings make it \
                    available in other environments.

homepage            https://gitlab.gnome.org/GNOME/libxml2/-/wikis/home
master_sites        gnome:sources/libxml2/${branch}/

depends_build       path:bin/pkg-config:pkgconfig

depends_lib         port:libiconv \
                    path:lib/pkgconfig/icu-uc.pc:icu \
                    port:xz \
                    port:zlib

use_xz              yes

patchfiles-append   include.patch

post-patch {
    reinplace "s|@ICONV_PREFIX@|${prefix}|" ${worksrcpath}/include/libxml/encoding.h
    reinplace -W ${worksrcpath}/doc "s|/etc|${prefix}/etc|g" xmlcatalog.1 xmllint.1
    # Remove next release
    # https://github.com/GNOME/libxml2/commit/b57e022d75425ef8b617a1c3153198ee0a941da8
    reinplace "s|icu-i18n|icu-uc|g" ${worksrcpath}/configure
}

# https://trac.macports.org/wiki/WimplicitFunctionDeclaration#strchr
configure.checks.implicit_function_declaration.whitelist-append strchr

configure.args      --disable-silent-rules \
                    --enable-static \
                    --with-ftp \
                    --with-http \
                    --with-icu \
                    --with-lzma \
                    --with-zlib \
                    --without-python

destroot.keepdirs   ${destroot}${prefix}/etc/xml
post-destroot {
    xinstall -m 0755 -d ${destroot}${prefix}/etc/xml
    ln -s ${prefix}/include/unicode ${destroot}${prefix}/include/libxml2/unicode
}

test.run            yes
test.target         check

variant debug description {Enable debug build} {
    configure.optflags      -O0 -g -Wno-uninitialized
    configure.args-append   --with-run-debug
}

variant readline description {Enable readline support} {
    configure.args-append   --with-readline \
                            --with-history
    depends_lib-append      port:readline
}

livecheck.type      gnome-with-unstable
