# -*- 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           github 1.0
PortGroup           perl5 1.0
PortGroup           active_variants 1.1

github.setup        mquinson po4a 0.74 v
revision            0

# NOTE: Presently this port assumes core module Pod::Parser, which
#   is being phased out. Indeed, it's no longer included in
#   Perl5 distributions starting with perl5.32

# UPDATE: Pod::Parser is now available as port p5-pod-parser for use with perls
#   where it is no longer in core. See conditional dependency below which allows
#   po4a to build on perl5.32+

perl5.require_variant   yes
perl5.conflict_variants yes
perl5.branches          5.28 5.30 5.32 5.34
perl5.default_branch    5.34
perl5.create_variants   ${perl5.branches}

categories          textproc
license             GPL-2+
maintainers         nomaintainer

description         framework to translate documentation and other materials
long_description    The po4a (PO for anything) project goal is to ease \
                    translations (and more interestingly, the \
                    maintenance of translations) using gettext tools \
                    on areas where they were not expected like documentation.

homepage            https://po4a.org/
github.tarball_from releases

checksums           rmd160  22095b77e395025afc2dc1de365e51d79ab7fbc5 \
                    sha256  25fc323f2ba37bbd48c3af0ebf49952644b0e468261f98633e91219a838fe7c2 \
                    size    5907018

# TODO: check and fix dependencies
depends_lib-append  port:p${perl5.major}-locale-gettext \
                    port:p${perl5.major}-sgmlspm \
                    port:p${perl5.major}-sgml-parser-opensp \
                    port:p${perl5.major}-term-readkey \
                    port:p${perl5.major}-text-wrapi18n \
                    port:p${perl5.major}-unicode-linebreak \
                    port:p${perl5.major}-yaml-tiny

# Temporary workwround for macOS 14 where system perl is being picked up
depends_lib-append  port:perl5
require_active_variants \
                    perl5 perl[string map {. _} ${perl5.major}]

if {${perl5.major} > 5.30} {
    depends_lib-append \
                    port:p${perl5.major}-pod-parser
}

depends_build-append \
                    port:docbook-xml-4.1.2 \
                    port:docbook-xml-4.2 \
                    port:docbook-xml-4.3 \
                    port:docbook-xml-4.4 \
                    port:docbook-xml-4.5 \
                    port:docbook-xml-5.0 \
                    port:docbook-xsl-nons \
                    port:docbook-xsl-ns \
                    port:libxslt \
                    port:p${perl5.major}-data-dumper \
                    port:p${perl5.major}-extutils-manifest \
                    port:p${perl5.major}-file-path \
                    port:p${perl5.major}-getopt-long \
                    port:p${perl5.major}-html-parser \
                    port:p${perl5.major}-parent \
                    port:p${perl5.major}-pathtools \
                    port:p${perl5.major}-text-parsewords

post-patch {
    reinplace "s|/usr/bin/perl|${perl5.bin}|" ${worksrcpath}/Build.PL
    reinplace "s|/usr/bin/env perl|${perl5.bin}|" ${worksrcpath}/scripts/msgsearch
    reinplace "s|/usr/bin/env perl|${perl5.bin}|" ${worksrcpath}/lib/Locale/Po4a/Gemtext.pm
    reinplace -W ${worksrcpath}/lib/Locale/Po4a "s|/usr/bin/perl|${perl5.bin}|" \
        {*}[glob -tails -directory ${worksrcpath}/lib/Locale/Po4a *.pm]
    reinplace -W ${worksrcpath}/lib/Locale/Po4a/InProgress "s|/usr/bin/perl|${perl5.bin}|" \
        {*}[glob -tails -directory ${worksrcpath}/lib/Locale/Po4a/InProgress *.pm]
    reinplace -W ${worksrcpath}/t "s|/usr/bin/perl|${perl5.bin}|" \
        {*}[glob -tails -directory ${worksrcpath}/t *.t]
    # Make sure all binaries use the correct MacPorts-provided perl version
    reinplace -W ${worksrcpath} "s|/usr/bin/env perl|${perl5.bin}|" \
        msguntypot \
        po4a \
        po4a-gettextize \
        po4a-normalize \
        po4a-translate \
        po4a-updatepo
}

configure.args      "installdirs=core --config cc=\"${configure.cc}\" --config ld=\"${configure.cc}\""
perl5.use_module_build
configure.cmd       ${perl5.bin}
