# -*- 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.9.12
revision            1
categories          textproc
platforms           darwin
license             MIT
maintainers         nomaintainer

description         GNOME XML C parser and toolkit
long_description    Libxml is the XML C library developed for the GNOMEproject.  \
                    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            http://xmlsoft.org/

depends_build       port:pkgconfig

depends_lib         port:libiconv \
                    port:icu \
                    port:xz \
                    port:zlib

master_sites        ${homepage}sources/ \
                    ftp://xmlsoft.org/${name}/

checksums           rmd160  766b9460b9e62b8152f431747c30c88c868c0c7e \
                    sha256  c8d6681e38c56f172892c85ddc0852e1fd4b53b4209e7f4ebf17f7e2eae71d92 \
                    size    5681632

set icu_cxx_version 201103L

patchfiles-append   include.patch

post-patch {
    reinplace "s|@ICONV_PREFIX@|${prefix}|" ${worksrcpath}/include/libxml/encoding.h
    reinplace "s|@ICU_PREFIX@|${prefix}|" ${worksrcpath}/include/libxml/encoding.h
    reinplace "s|@ICU_CXX_VERSION@|${icu_cxx_version}|" ${worksrcpath}/include/libxml/encoding.h
    reinplace -locale C "s|/etc|${prefix}/etc|g" \
        ${worksrcpath}/catalog.c \
        ${worksrcpath}/runtest.c \
        ${worksrcpath}/xmlcatalog.c \
        ${worksrcpath}/xmllint.c \
        ${worksrcpath}/doc/xmlcatalog.1 \
        ${worksrcpath}/doc/xmllint.1
}

configure.args      --disable-silent-rules \
                    --enable-static \
                    --with-icu \
                    --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.regex     {"LATEST_LIBXML2_IS_([^"]+)"}
