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

if {[string match *gcc* ${configure.compiler}]} {
    # https://trac.macports.org/ticket/65995
    PortGroup       muniversal 1.0

}

name                texinfo
version             7.1
revision            1
categories          textproc
license             GPL-3+
maintainers         nomaintainer

installs_libs       no

description         The official documentation format of the GNU project
long_description    Texinfo is the official documentation format of \
                    the GNU project. It uses a single source file to \
                    produce output in a number of formats, both \
                    online and printed (dvi, info, html, xml, etc.). \
                    This means that instead of writing different \
                    documents for online information and another for \
                    a printed manual, you need write only one \
                    document. Some features need texlive (unnecessary \
                    if only the info command is used).
homepage            https://www.gnu.org/software/texinfo/

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

depends_build       port:gettext \
                    port:help2man
depends_lib         port:gettext-runtime \
                    port:libiconv \
                    port:ncurses \
                    port:perl${perl5.major}

master_sites        gnu
use_xz              yes

checksums           rmd160  06ef5a2e7a25855805c1f3723a4a36170105bf2f \
                    sha256  deeec9f19f159e046fdf8ad22231981806dac332cc372f1c763504ad82b30953 \
                    size    5545720

# patch gnublib Tiger regression,  https://trac.macports.org/ticket/67248
patchfiles          patch-texinfo-gnulib-tiger-regression.diff

# https://trac.macports.org/wiki/WimplicitFunctionDeclaration#strchr
configure.checks.implicit_function_declaration.whitelist-append strchr

configure.perl      ${perl5.bin}
pre-configure {
    configure.env-append \
        PERL_EXT_CFLAGS=[get_canonical_archflags cc] \
        PERL_EXT_LDFLAGS=[get_canonical_archflags ld]
}

# If not disabled, the port builds /opt/local/lib/texinfo/MiscXS.so and other libs,
# which link to libunistring and leave the port broken if that is deactivated.
configure.args-append   --disable-perl-xs

destroot.target-append  install-tex
destroot.args           TEXMF=${prefix}/share/texmf

pre-destroot {
    xinstall -d ${destroot}${prefix}/share/doc/${name}
    xinstall -m 644 -v -W ${worksrcpath} \
        AUTHORS COPYING ChangeLog NEWS README TODO doc/refcard/txirefcard.pdf \
        ${destroot}${prefix}/share/doc/${name}
}

post-destroot {
    file delete -force ${destroot}${prefix}/lib/charset.alias
}

# mktexlsr is provided by texlive-bin (and needed only if texlive-bin
# is installed). texlive-bin may be installed/uninstalled independently
# of texinfo (but not at the same time, unless a locking mechanism is
# provided). The use of a variant would not be flexible enough.

post-activate {
    if {[file exists ${prefix}/bin/mktexlsr]} {
        ui_debug {Rebuilding TeX ls-R filename databases}
        system ${prefix}/bin/mktexlsr
    }
}

post-deactivate {
    if {[file exists ${prefix}/bin/mktexlsr]} {
        ui_debug {Rebuilding TeX ls-R filename databases}
        system ${prefix}/bin/mktexlsr
    }
}

# We need to support names like 'texinfo-4.8a.tar.bz2'.
livecheck.type      regex
livecheck.url       https://ftp.gnu.org/gnu/texinfo/?C=M\;O=D
livecheck.regex     ${name}-(\[0-9.a-s\]+)\\.tar
