# $Id: Portfile 50980 2009-05-14 19:41:55Z and.damore@macports.org $

PortSystem 1.0
name			teTeX
version			3.0
revision		6
epoch			20080130
categories		print textproc
maintainers		gwright
description		TeX and METAFONT
long_description	teTeX is a TeX distribution for UNIX compatible	\
			systems.  It contains the latest versions of	\
			TeX & friends and nearly everything you need	\
			for happy TeX'ing.  For more information have	\
			a look at the lengthy FEATURES file of the	\
			distribution.
homepage		http://www.tug.org/teTeX/
platforms		darwin

set tetex_src		tetex-src-${version}.tar.gz
set tetex_texmf		tetex-texmf-${version}po.tar.gz
set tetex_top		${prefix}/share/texmf
set tetex_texmftree	${destroot}${prefix}/share/texmf-dist

master_sites		ftp://tug.ctan.org/tex-archive/systems/unix/teTeX/current/distrib/ \
			ftp://cam.ctan.org/tex-archive/systems/unix/teTeX/current/distrib/ \
			ftp://dante.ctan.org/tex-archive/systems/unix/teTeX/current/distrib/ 

distfiles		${tetex_src} ${tetex_texmf}

checksums		${tetex_src}   md5 944a4641e79e61043fdaf8f38ecbb4b3 \
			${tetex_texmf} md5 ed9d30d9162d16ac8d5065cde6e0f6fa 

#user_notes	The layout of the installed files has changed. Now	\
#		runtime configuration data is stored separately from	\
#		the main teTeX distribution.

#bugs		Note that the configuration process for teTeX uses	\
#		hand-crafted configure and Makefiles, so the whole	\
#		procedure is quite fragile. In particular, slight	\
#		misconfigurations can cause the build to silently	\
#		fail to produce some targets. When changing this	\
#		Portfile, check carefully to be sure that everything	\
#		you think should be built was in fact built.
	
extract.only		${tetex_src}
worksrcdir		tetex-src-${version}

post-extract	{ file mkdir ${tetex_texmftree}
		  file mkdir ${destroot}${tetex_top}
		  system "tar vxz -C ${tetex_texmftree} -f ${distpath}/${tetex_texmf}"

		  # Patch to enable french hyphenation:

		  system "cd ${tetex_texmftree} && patch -p0 < ${portpath}/${filesdir}/patch-language.dat"

		  # This fixes a pattern space overflow in BSD sed, which
		  # can be triggered if MacPorts is installed in a
		  # nonstandard location:

		  reinplace "s|sed -f|${prefix}/bin/gsed -f|g" ${workpath}/${worksrcdir}/texk/make/man.mk
		  reinplace "s|sed -n|${prefix}/bin/gsed -n|g" ${workpath}/${worksrcdir}/texk/make/man.mk
		  reinplace "s|sed -e|${prefix}/bin/gsed -e|g" ${workpath}/${worksrcdir}/texk/make/man.mk
		}

depends_build		port:gawk		\
			port:gsed
depends_lib 		port:Xft2 \
			port:xorg-libXaw \
			port:xorg-libXmu \
			port:xorg-libXp \
			port:xpm \
			port:libpng
depends_run		port:ghostscript	\
			port:texinfo		\
			port:texi2html \
			port:gzip

configure.args		--prefix=${destroot}${prefix}			\
			--datadir=${destroot}${prefix}/share		\
			--infodir=${destroot}${prefix}/share/info	\
			--mandir=${destroot}${prefix}/share/man		\
			--without-texinfo				\
			--without-texi2html				\
			--disable-multiplatform	

variant no_x11	{ 
		  depends_lib-delete \
			port:Xft2 \
			port:xorg-libXaw \
			port:xorg-libXmu \
			port:xorg-libXp \
			port:xpm \
			port:libpng
		  configure.args-append --without-x11 \
					--without-oxdvik \
					--without-xdvik \
					--with-mfw=no
		}

post-destroot	{ # Delete the texi2pdf script: it will be provided
		  # by the texinfo port.
		  file delete ${destroot}${prefix}/bin/texi2pdf

		  # Modify mktex.opt to force use of varfonts
		  reinplace "s|MT_FEATURES=appendonlydir|MT_FEATURES=appendonlydir:varfonts|g" ${destroot}/${tetex_top}/web2c/mktex.opt

		  # happiness is ranlib.
		  system "ranlib ${destroot}${prefix}/lib/libkpathsea.a"

		  # Add a directory for local enhancements
		  file mkdir ${destroot}${prefix}/share/texmf-local
		  system "touch ${destroot}${prefix}/share/texmf-local/.turd"
		}

post-activate	{ system "fmtutil-sys --all"

		  # These are required so that local additions are picked
		  # up if teTeX is updated:

		  system "mktexlsr"
		  system "updmap-sys"
		}

