# -*- 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
# $Id: Portfile 79385 2011-06-12 07:59:29Z jmr@macports.org $

PortSystem      1.0
PortGroup       texlive 1.0

name            texlive-bin
version         2010
revision        4

categories      tex
maintainers     dports
description     TeX Live Binaries.
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.

homepage        http://www.tug.org/texlive/
platforms       darwin

master_sites    tex_ctan:systems/texlive/Source/
set distversion 20100720
distname        texlive-${distversion}-source
worksrcdir      ${distname}
use_xz          yes
checksums       md5     2a2201b84fdbf210032e1df70bc59157 \
                sha1    713b861123e3d9e073e2c93d7ed3e13262d82c34 \
                rmd160  b1120f3377ca45b4d86911b99a95c2e6e45927b5

universal_variant no

depends_lib     port:fontconfig \
                port:freetype \
                port:gd2 \
                port:libpng \
                port:ncurses \
                port:zlib \
                port:libzzip \
                port:t1lib \
                port:poppler \
                port:xorg-libXp \
                port:texlive-common

depends_run     port:ghostscript

depends_build   path:bin/perl:perl5 \
                path:bin/pkg-config:pkgconfig

patchfiles      patch-configure.diff \
                patch-libs_icu_Makefile.in.diff \
                patch-libs_icu_icu-4.4_configure.diff \
                patch-libs_icu_icu-4.4_tools_icuinfo_Makefile.in.diff \
                patch-libs-freetype-Makefile.in.diff \
                patch-texk_texlive_linked_scripts_Makefile.in.diff \
                patch-texk_tex4htk_Makefile.in.diff \
                patch-texk_xdvik_xdvi-sh.in.diff

post-patch {
    reinplace "s|@@TEXMFMAIN@@|${texlive_texmfmain}|" ${worksrcpath}/texk/texlive/linked_scripts/Makefile.in
    reinplace "s|@@TEXMFDIST@@|${texlive_texmfdist}|" ${worksrcpath}/texk/texlive/linked_scripts/Makefile.in
    reinplace "s|@@TEXMFDIST@@|${texlive_texmfdist}|" ${worksrcpath}/texk/tex4htk/Makefile.in
    reinplace "s|@@TEXLIVE_BINDIR@@|${texlive_bindir}|" ${worksrcpath}/texk/xdvik/xdvi-sh.in

    # Link our texmf.cnf in so that the proper paths are compiled into kpathsea
    delete ${worksrcpath}/texk/kpathsea/texmf.cnf
    ln -s ${texlive_texmfsysconfig}/texmf.cnf ${worksrcpath}/texk/kpathsea/texmf.cnf

    if {![variant_isset atsui]} {
        # Force configure to believe that Carbon API is
        # unavailable. This test is actually used to determine whether
        # ATSUI should be used.
        reinplace "s|kpse_cv_have_Carbon=yes|kpse_cv_have_Carbon=no|" ${worksrcpath}/texk/web2c/configure
        reinplace "s|kpse_cv_have_Carbon=yes|kpse_cv_have_Carbon=no|" ${worksrcpath}/texk/xdv2pdf/configure
    }
    
    # Do the same for xdvipdfmx regardless of whether +atsui is set,
    # because it will want to use deprecated fontconfig APIs that are
    # only available if fontconfig is compiled with
    # --with-old-mac-fonts
    reinplace "s|kpse_cv_have_ApplicationServices=yes|kpse_cv_have_ApplicationServices=no|" ${worksrcpath}/texk/xdvipdfmx/configure
}


# We use MacPorts-provided libraries instead of the ones included in
# texlive whenever possible, to avoid redundancy and to better keep
# current with respect to security updates and the like.
#
# Exceptions are freetype1 (not in MacPorts anymore) and icu (the
# texlive version is non-standard)
configure.args  --bindir=${texlive_bindir} \
                --mandir=${texlive_bindir} \
                --infodir=${prefix}/share/info \
                --disable-multiplatform \
                --disable-native-texlive-build \
                --without-old-mac-fonts \
                --with-banner-add="/MacPorts ${version}_${revision}" \
                --enable-shared \
                --with-system-freetype2 \
                --without-system-freetype \
                --without-system-icu \
                --with-system-gd \
                --with-system-libpng \
                --with-libpng-includes=${prefix}/include \
                --with-libpng-libdir=${prefix}/lib \
                --with-system-ncurses \
                --with-system-t1lib \
                --with-t1lib-includes=${prefix}/include \
                --with-t1lib-libdir=${prefix}/lib \
                --with-system-xpdf \
                --with-system-zlib \
                --with-system-zziplib \
                --disable-etex \
                --disable-detex \
                --disable-dvi2tty \
                --disable-ps2eps \
                --disable-psutils \
                --disable-t1utils \
                --disable-texinfo \
                --disable-xindy

configure.cppflags-delete   -I${prefix}/include
configure.ldflags-delete    -L${prefix}/lib
configure.env-append        C_INCLUDE_PATH=${prefix}/include
configure.env-append        CPLUS_INCLUDE_PATH=${prefix}/include
configure.env-append        LIBRARY_PATH=${prefix}/lib

# work around bug in texlive makefiles where $OBJC is not recorded
# during configure phase
pre-build {
    append_list_to_environment_value build "OBJC" ${configure.objc}
    append_list_to_environment_value build "OBJCFLAGS" ${configure.objcflags}
    append_list_to_environment_value build "OBJCFLAGS" ${configure.objc_archflags}
}

post-destroot   {
    # texmf and texmf-dist will be installed by other texlive ports
    delete ${destroot}${prefix}/texmf
    delete ${destroot}${prefix}/texmf-dist

    # Do not install symlinks to scripts that we will not install
    delete ${destroot}${texlive_bindir}/latexmk
    delete ${destroot}${texlive_bindir}/tlmgr

    # gzip manpages that are installed into texlive_bindir
    foreach manpage [glob -directory ${destroot}${texlive_bindir} man*/*] {
        # need to make sure it isn't a symlink
        if {[file type $manpage] == "file"} {
            system "gzip $manpage"
        }
    }
}

pre-activate {
    if { [file exists ${texlive_texmfdist}/scripts/tex4ht/ht.sh]
         && ![catch {set vers [lindex [registry_active texlive-htmlxml] 0]}]
         && [rpm-vercomp [lindex $vers 1] 13822] == 0
         && [lindex $vers 2] <3} {
        set deactivate_proc registry_deactivate_composite
        if {[info commands registry_deactivate_composite] == {}} {
            set deactivate_proc registry_deactivate
        }
        $deactivate_proc texlive-htmlxml "" [list ports_nodepcheck 1]
    }
}

post-activate {
    system "${texlive_bindir}/mktexlsr"
}

variant atsui description {Use ATSUI instead of freetype for XeTeX font rendering (forces 32-bit)} {
    # force 32-bit build
    supported_archs i386 ppc
}

if {![variant_isset "atsui"]} {
    notes-append "XeTeX is built without support for Apple Type Services for Unicode Imaging (ATSUI) or Apple Advanced Typography (AAT). To enable it, build texlive-bin with the +atsui variant. Note that this will force texlive and all of its dependencies to be built 32-bit."
}


if {![variant_isset no_x11] && ![variant_isset motif] && ![variant_isset xaw] && ![variant_isset xaw3d] && ![variant_isset nextaw]} {
    default_variants    +motif
}

variant no_x11 conflicts xaw motif xaw3d nextaw {
    depends_lib-delete port:xorg-libXp
    configure.args-append --without-x --without-pdfopen
    configure.args-delete  --x-includes=${prefix}/include \
                           --x-libraries=${prefix}/lib
}
variant motif conflicts no_x11 xaw xaw3d nextaw description {Use Motif to build xdvi} {
     depends_lib-append lib:libXm:openmotif
     configure.args-append --with-xdvi-x-toolkit=motif
}
variant xaw conflicts no_x11 motif xaw3d nextaw description {Use Xaw to build xdvi} {
    depends_lib-append port:xorg-libXaw
    configure.args-append --with-xdvi-x-toolkit=xaw
}
variant xaw3d conflicts no_x11 motif xaw nextaw description {Use Xaw3d to build xdvi} {
    depends_lib-append port:Xaw3d
    configure.args-append --with-xdvi-x-toolkit=xaw3d
}
variant nextaw conflicts no_x11 motif xaw xaw3d description {Use neXtaw to build xdvi} {
    depends_lib-append port:neXtaw
    configure.args-append --with-xdvi-x-toolkit=neXtaw
}

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