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

# If you update this port, also update the port rb-mini_portile2 to the latest
# compatible with this port.
#
#   ../rb-mini_portile2/Portfile
#
# See https://rubygems.org/gems/nokogiri
ruby.branches       3.4 3.3 3.2 3.1 3.0 2.7
ruby.setup          nokogiri 1.18.10 gem
revision            1
maintainers         {kimuraw @kimuraw} \
                    {judaew @judaew} openmaintainer
description         Nokogiri is an HTML, XML, SAX, and Reader parser.
long_description    Nokogiri is an HTML, XML, SAX, and Reader parser. \
                    Among Nokogiri's many features is the ability to search \
                    documents via XPath or CSS3 selectors.
license             MIT
homepage            https://nokogiri.org

checksums           rmd160  9b413bb2906364da9248323e7f950d154efca21f \
                    sha256  d5cc0731008aa3b3a87b361203ea3d19b2069628cb55e46ac7d84a0445e69cc1 \
                    size    4365824

if {${name} ne ${subport}} {
    depends_extract     port:rb${ruby.suffix}-gem-patch

    post-patch {
        copy ${filespath}/patch-extconf.rb.diff ${worksrcpath}
        reinplace "s|@@PREFIX@@|${prefix}|g" ${worksrcpath}/patch-extconf.rb.diff
        system -W ${worksrcpath} "${ruby.gem} patch ${ruby.filename}.gem patch-extconf.rb.diff -o ${ruby.filename}.gem -p0"
    }

    depends_lib-append  port:libiconv \
                        port:libxml2 \
                        port:libxslt \
                        port:rb${ruby.suffix}-mini_portile2 \
                        port:zlib

    if {${ruby.branch} < 3.3} {
        depends_run-append \
                        port:rb${ruby.suffix}-racc
    }

    destroot.env-append NOKOGIRI_USE_SYSTEM_LIBRARIES=YES
}
