# $Id: Portfile,v 1.2 2006/07/20 15:13:19 pguyot Exp $

PortSystem 1.0
name				XeTeX
version				0.994a
categories			tex print textproc
maintainers			pguyot@kallisys.net
description			The XeTeX typesetting system
long_description	The XeTeX typesetting system is based on a merger of TeX \
					with Unicode and MacOS X font technologies.
homepage			http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&item_id=XeTeX
platforms			darwin
depends_lib			port:teTeX \
					port:xdvipdfmx
distname			[string tolower $name]-${version}
master_sites		http://scripts.sil.org/svn-view/xetex/TAGS/
checksums			md5 1b44a1039118cb48d0f72d9b76a5564c \
					rmd160 9f6af83f92dad2800b0ad9f872e5ecf4c9117136 \
					sha1 585b30e8f388097143bfec3911097ca51162934c
# This patch makes sure we use DP's path instead of relying on kpsewhich.
patchfiles			patch-runConfigure.sh \
					patch-install-xetex
post-patch {
	reinplace "s|__PREFIX|${prefix}|g" ${worksrcpath}/runConfigure.sh
	reinplace "s|__PREFIX|${prefix}|g" ${worksrcpath}/install-xetex
	reinplace "s|__DESTROOT|${destroot}|g" ${worksrcpath}/install-xetex
}

use_configure	no
pre-build {
	system "chmod +x ${worksrcpath}/build-xetex"
}
build.cmd "./build-xetex"

set hyphen_files [list \
	czhyph.tex \
	dehyphn.tex \
	dehypht.tex \
	dkhyphen.tex \
	gahyph.tex \
	hrhyph.tex \
	huhyph.tex \
	plhyph.tex \
	rohyphen.tex \
	sihyph23.tex \
	skhyph.tex \
	trhyph.tex]
set hyphen_files_prefix ${prefix}/share/texmf-dist/tex/generic/hyphen/

pre-destroot {
	system "chmod +x ${worksrcpath}/install-xetex"
}
destroot.cmd "./install-xetex"

post-destroot {
	# fmtutil.cnf
	file mkdir ${destroot}${prefix}/share/texmf-config/web2c/
	xinstall -m 644 ${portpath}/${filesdir}/fmtutil.cnf \
			${destroot}${prefix}/share/texmf-config/web2c/

	# hyphen files
	foreach hyphen_file $hyphen_files {
		system "mv ${destroot}${hyphen_files_prefix}${hyphen_file} \
		${destroot}${hyphen_files_prefix}${hyphen_file}.xetex"
	}
	
	file mkdir ${destroot}${prefix}/share/texmf-dist/tex/generic/config/
	xinstall -m 644 ${portpath}/${filesdir}/language.dat \
		${destroot}${prefix}/share/texmf-dist/tex/generic/config/language.dat.xetex
}

post-activate	{
	system "\
		texhash && \
		fmtutil-sys --enablefmt xetex && \
		fmtutil-sys --byfmt xetex && \
		fmtutil-sys --enablefmt xelatex && \
		fmtutil-sys --byfmt xelatex && \
		texlinks --silent"

	# hyphen files
	foreach hyphen_file $hyphen_files {
		system "cp -p ${hyphen_files_prefix}${hyphen_file}.xetex \
		${hyphen_files_prefix}${hyphen_file}"
	}
	
	# language.dat file
	system "cp -p \
		${prefix}/share/texmf-dist/tex/generic/config/language.dat.xetex \
		${prefix}/share/texmf-dist/tex/generic/config/language.dat"

	# These are required so that local additions are picked
	# up if teTeX is updated:
	system "mktexlsr"
	system "updmap-sys"
}