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

name            texlive
version         2025

categories      tex
maintainers     {dports @drkp}
description     TeX Live metaport
long_description    TeX Live is an easy way to get up and running with TeX. \
    It provides a comprehensive TeX system with binaries for most flavors   \
    of Unix, including GNU/Linux, and also Windows. It includes all the     \
    major TeX-related programs, macro packages, and fonts that are free     \
    software, including support for many languages around the world.        \
                                                                            \
    This is a metaport that installs collections of TeX Live packages.      \
    See the variants list for options about which collections to install.


homepage        https://www.tug.org/texlive/
platforms       any
supported_archs noarch

# TeX Live consists of thousands of individual CTAN packages with
# different licenses -- usually some combination of the GPL, LaTeX
# Project Public License, or plain old public domain -- but all of
# them should be redistributable in source or binary form, which is
# what we care about. See http://www.tug.org/texlive/LICENSE.TL
#
# (Actually, *this* port is just a metaport and doesn't install
# anything.)
license         Permissive

distfiles
use_configure   no
build           {}

set scheme ""
set scheme_desc ""

proc add_notes {} {
    global scheme scheme_desc
    
    notes "The \"${scheme}\" installation of TeX Live was selected. ${scheme_desc}\n"
    
    if {$scheme != "full"} {
        notes-append " \n"
        notes-append "Additional TeX Live packages are available. To see a list, use 'port list texlive-* and not installed'. If you want a full installation (very large), reinstall this metaport with the +full variant."
    }
}
destroot {
    # Create a dummy file so the port can be successfully activated
    xinstall -d ${destroot}${prefix}/share/doc/texlive
    set docfile [open ${destroot}${prefix}/share/doc/texlive/README.${name}.txt "w"]
    puts $docfile "TeX Live ${version} (MacPorts revision ${version}_${revision})\n"
    puts $docfile "${long_description}\n"
    puts $docfile "\nThe \"${scheme}\" scheme was installed. ${scheme_desc}\n"
    puts $docfile "The other files in this directory list the versions and contents of each TeX Live port installed."
    close $docfile
}

variant minimal \
    description "Minimal installation scheme (plain TeX only; no LaTeX)" \
    conflicts basic medium full {
        set scheme "minimal"
        set scheme_desc "This installation provides the bare minimum support for plain TeX; it does not include LaTeX or any add-on packages."
        add_notes

        depends_lib port:texlive-basic
    }

variant basic \
    description "Basic installation scheme for plain TeX or LaTeX documents" \
    conflicts minimal medium full {
        set scheme "basic"
        set scheme_desc "This installation provides support for plain TeX and LaTeX, but no add-on packages."
        add_notes

        depends_lib port:texlive-basic \
            port:texlive-latex
    }

variant medium \
    description "Medium installation scheme: plain, latex, recommended packages, some languages" \
    conflicts minimal basic full {
        set scheme "medium"
        set scheme_desc "This is the standard installation containing basic and recommended packages for TeX, LaTeX, and ConTeXt, as well as support files for several common European languages."
        add_notes
        
        depends_lib port:texlive-basic \
                    port:texlive-bin-extra \
                    port:texlive-context \
                    port:texlive-fontutils \
                    port:texlive-fonts-recommended \
                    port:texlive-lang-czechslovak \
                    port:texlive-lang-english \
                    port:texlive-lang-european \
                    port:texlive-lang-french \
                    port:texlive-lang-german \
                    port:texlive-lang-italian \
                    port:texlive-lang-polish \
                    port:texlive-lang-portuguese \
                    port:texlive-lang-spanish \
                    port:texlive-latex \
                    port:texlive-latex-recommended \
                    port:texlive-luatex \
                    port:texlive-math-science \
                    port:texlive-metapost \
                    port:texlive-plain-generic \
                    port:texlive-xetex

        if {![variant_isset "doc"]} {
            texlive.removedocdepends
        }
    }

variant full \
    description "Full installation scheme (very large!)" \
    conflicts minimal basic medium {
        set scheme "full"
        set scheme_desc "This is a full installation of all TeX Live packages, including all languages and their associated documentation."
        add_notes

        depends_lib port:texlive-basic \
                    port:texlive-bibtex-extra \
                    port:texlive-bin-extra \
                    port:texlive-context \
                    port:texlive-fonts-extra \
                    port:texlive-fonts-recommended \
                    port:texlive-fontutils \
                    port:texlive-formats-extra \
                    port:texlive-games \
                    port:texlive-humanities \
                    port:texlive-lang-arabic \
                    port:texlive-lang-chinese \
                    port:texlive-lang-cjk \
                    port:texlive-lang-cyrillic \
                    port:texlive-lang-czechslovak \
                    port:texlive-lang-english \
                    port:texlive-lang-european \
                    port:texlive-lang-french \
                    port:texlive-lang-german \
                    port:texlive-lang-greek \
                    port:texlive-lang-italian \
                    port:texlive-lang-japanese \
                    port:texlive-lang-korean \
                    port:texlive-lang-other \
                    port:texlive-lang-polish \
                    port:texlive-lang-portuguese \
                    port:texlive-lang-spanish \
                    port:texlive-latex \
                    port:texlive-latex-extra \
                    port:texlive-latex-recommended \
                    port:texlive-luatex \
                    port:texlive-math-science \
                    port:texlive-metapost \
                    port:texlive-music \
                    port:texlive-pictures \
                    port:texlive-plain-generic \
                    port:texlive-pstricks \
                    port:texlive-publishers \
                    port:texlive-xetex \
                    port:biblatex-biber

        if {![variant_isset "doc"]} {
            texlive.removedocdepends
        }
    }

variant letter description {Set paper format to letter} {
    post-activate {
        system "texconfig-sys paper letter"
    }
}

# These variants are mainly for the underlying texmf ports; list them
# here so they get shown in 'port variants texlive'
variant doc description {Install documentation} { }
variant src description {Install TeX source} { }

default_variants +doc

if {![variant_isset minimal]
    && ![variant_isset basic]
    && ![variant_isset full]} {
    default_variants-append    +medium
}


livecheck.type      regex
livecheck.url       ${homepage}
livecheck.regex     "TeX Live (\[0-9\]+) is available"
