# -*- 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 perl5 1.0
PortGroup texlive 1.0

# biber-ms is the multiscript variant of biber by the same upstream
# author. It's distributed by CTAN  and has its own version number.
name            biblatex-biber-ms

perl5.branches  5.34

perl5.setup     Biber 4.0
version         4.0

categories      tex
license         {Artistic-2 GPL}
maintainers     {dports @drkp}
description     multiscript variant of biber for use with biblatex-ms
long_description \
    biber-ms is the multiscript variant of biber, designed to work       \
    with the biblatex-ms LaTeX package. It supports bibliographies that  \
    mix multiple scripts (e.g. Latin, Cyrillic, CJK) by allowing each    \
    entry field to carry per-script forms and per-language translations. \
    It installs alongside biber as a separate biber-ms executable, so    \
    biblatex documents continue to use biber while biblatex-ms documents \
    use biber-ms.

platforms       {darwin any}
supported_archs noarch

homepage        https://ctan.org/pkg/biber-ms
master_sites    tex_ctan:biblio/biber-ms/base/source
distname        biblatex-biber-ms
worksrcdir      biblatex-biber-${version}

checksums       rmd160  526998fa15e5da5f498c4298a8bd6390b202919a \
                sha256  40ec36918c9ef2832e33c42dd6b96a65f4f376096341f580ecee512538ce56e1 \
                size    1073630

depends_build-append    port:p${perl5.major}-config-autoconf \
                        port:p${perl5.major}-extutils-libbuilder \
                        port:p${perl5.major}-test-differences

depends_lib-append      port:p${perl5.major}-autovivification \
                        port:p${perl5.major}-business-isbn \
                        port:p${perl5.major}-business-ismn \
                        port:p${perl5.major}-business-issn \
                        port:p${perl5.major}-class-accessor \
                        port:p${perl5.major}-data-compare \
                        port:p${perl5.major}-data-dump \
                        port:p${perl5.major}-data-uniqid \
                        port:p${perl5.major}-datetime-calendar-julian \
                        port:p${perl5.major}-datetime-format-builder \
                        port:p${perl5.major}-encode-eucjpascii \
                        port:p${perl5.major}-encode-hanextra \
                        port:p${perl5.major}-encode-jis2k \
                        port:p${perl5.major}-encode-locale \
                        port:p${perl5.major}-file-slurper \
                        port:p${perl5.major}-file-which \
                        port:p${perl5.major}-ipc-cmd \
                        port:p${perl5.major}-ipc-run3 \
                        port:p${perl5.major}-io-string \
                        port:p${perl5.major}-libwww-perl \
                        port:p${perl5.major}-lingua-translit \
                        port:p${perl5.major}-list-allutils \
                        port:p${perl5.major}-list-moreutils \
                        port:p${perl5.major}-log-log4perl \
                        port:p${perl5.major}-mozilla-ca \
                        port:p${perl5.major}-parse-recdescent \
                        port:p${perl5.major}-perlio-utf8_strict \
                        port:p${perl5.major}-regexp-common \
                        port:p${perl5.major}-sort-key \
                        port:p${perl5.major}-storable \
                        port:p${perl5.major}-text-balanced \
                        port:p${perl5.major}-text-bibtex \
                        port:p${perl5.major}-text-csv \
                        port:p${perl5.major}-text-csv_xs \
                        port:p${perl5.major}-text-roman \
                        port:p${perl5.major}-unicode-collate \
                        port:p${perl5.major}-unicode-linebreak \
                        port:p${perl5.major}-unicode-normalize \
                        port:p${perl5.major}-uri \
                        port:p${perl5.major}-xml-libxml-simple \
                        port:p${perl5.major}-xml-libxslt \
                        port:p${perl5.major}-xml-writer \
                        bin:mktexlsr:texlive-basic

perl5.use_module_build

# biber-ms uses the same Biber:: perl namespace as biber, so
# install its modules and script into a private directory to avoid
# clashing with biblatex-biber. We update the script to point to
# this directory and rename it to biber-ms.
set biberms_libdir ${prefix}/libexec/${name}
configure.args  --install_base=${biberms_libdir}

post-patch {
    reinplace -W ${worksrcpath}/bin \
        "s|#!/usr/bin/env perl|#!${perl5.bin}|g" biber
    reinplace -W ${worksrcpath}/bin \
        "s|^use Biber;|use lib '${biberms_libdir}/lib/perl5'; use Biber;|" biber
}

pre-destroot {
    # The perl5 PortGroup's post-destroot fs-traverses ${perl5.lib} to
    # rewrite .packlist files; create the directory so it doesn't
    # fail. (We do the same rewriting below.)
    xinstall -d ${destroot}${perl5.lib}
}

post-destroot {
    file rename ${destroot}${biberms_libdir}/bin/biber \
                ${destroot}${biberms_libdir}/bin/biber-ms

    ln -s ${biberms_libdir}/bin/biber-ms \
          ${destroot}${prefix}/bin/biber-ms

    # Strip the destroot prefix from .packlist
    fs-traverse file ${destroot}${biberms_libdir} {
        if {[file isfile ${file}] && [file tail ${file}] eq ".packlist"} {
            reinplace -n -q "s|${destroot}||p" ${file}
        }
    }
}

pre-activate {
    # Avoid conflict with texlive-bibtex-extra which used to list
    # biber-ms in texlive.binaries.
    if {![catch {set vers [lindex [registry_active texlive-bibtex-extra] 0]}]
        && [vercmp [lindex $vers 2] 1] < 0} {
        registry_deactivate_composite texlive-bibtex-extra "" \
            [list ports_nodepcheck 1]
    }
}

post-activate {
    texlive.mktexlsr
}

post-deactivate {
    texlive.mktexlsr
}

livecheck.type  regex
livecheck.url   https://ctan.org/pkg/biber-ms
livecheck.regex {Version</td><td>(\d+(?:\.\d+)*)}
