# -*- 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.3 3.2 3.1 3.0 2.7
ruby.setup          nokogiri 1.16.7 gem
revision            0
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  86c12ed3e90fd2c7a9f0a74e6da6b1ec3e10b3aa \
                    sha256  f819cbfdfb0a7b19c9c52c6f2ca63df0e58a6125f4f139707b586b9511d7fe95 \
                    size    4626944

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:libxml2 \
                        port:libxslt \
                        port:zlib \
                        port:libiconv \
                        port:rb${ruby.suffix}-mini_portile2

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

    destroot.env-append NOKOGIRI_USE_SYSTEM_LIBRARIES=YES
}
