# $Id: Portfile 76374 2011-02-21 16:46:15Z jmr@macports.org $

PortSystem			1.0

name				kxterm
version				5.0pl3
revision			2
categories			x11 chinese
maintainers			nomaintainer
description			Chinese-capable xterm with dictionary-lookup capability
long_description \
	kxterm is an extension of cxterm, where cxterm is a terminal emulator \
	for X11, just like xterm, but with the capability of displaying and \
	inputting Chinese.  kxterms enhancement is that, while reading Chinese \
	text, each time you see a character you do not know, click on it with \
	the left mouse button.  Pronunciations in Cantonese (Sidney Lau system), \
	then Mandarin (standard pinyin), as well as an approximate English \
	translation, for the character will then appear at the bottom of the \
	kxterm screen.  If this character, along with neighboring characters, \
	forms a character-compound found in Compound.b5, this compound will be \
	displayed as well.

platforms			darwin

homepage			http://heather.cs.ucdavis.edu/~matloff/Chinese/KX/Index.html
master_sites		http://heather.cs.ucdavis.edu/~matloff/Chinese/KX/Packages/
distname			KXTerm

worksrcdir			cxterm-5.0

checksums			md5 ece6a83c1fe1c3451e3667f51c77b2ec

depends_build			port:mkfontdir port:bdftopcf
depends_lib			port:xorg-libXaw

use_xmkmf yes

patchfiles			patch-cxterm_misc.c.diff patch-CXterm.ad.diff \
				patch-cxterm_HZtable.h.diff patch-utils_hzimctrl.c.diff

configure {
	system "cd ${worksrcpath} && xmkmf"
}

build.target		-f Makefile.ini World

destroot.args		DOCHTMLDIR="${prefix}/share/doc/${name}" \
					MANPATH="${prefix}/share/man" \
					DICTDIR="${prefix}/share/${name}" \
					FONTINSTDIR="${prefix}/share/${name}/fonts" \
					INSTALLFLAGS="-c" INSTUIDFLAGS=""

post-destroot {
	# Docs
	xinstall -m 755 -d ${destroot}${prefix}/share/doc/${name}
	xinstall -m 644 -W ${worksrcpath} README.kxterm \
		${destroot}${prefix}/share/doc/${name}
	xinstall -m 644 -W ${worksrcpath}/cxterm SampleText.b5 SampleText.gb \
		${destroot}${prefix}/share/doc/${name}
	eval file copy [glob ${worksrcpath}/Doc/*] \
		${destroot}${prefix}/share/doc/${name}
	# Fix doc file and dir perms
	system "find ${destroot}${prefix}/share/doc/${name} -type f -print0 | \
		xargs -0 chmod +r"
	system "find ${destroot}${prefix}/share/doc/${name} -type d -print0 | \
		xargs -0 chmod +rx"
	# MP-specific readme
	xinstall -m 644 -W ${filespath} MacPorts_ReadMe.txt \
		${destroot}${prefix}/share/doc/${name}
	reinplace "s|@@PREFIX@@|${prefix}|g" \
		${destroot}${prefix}/share/doc/${name}/MacPorts_ReadMe.txt
	reinplace "s|@@NAME@@|${name}|g" \
		${destroot}${prefix}/share/doc/${name}/MacPorts_ReadMe.txt

	# X resource file
	xinstall -m 644 -W ${worksrcpath} CXterm.ad \
		${destroot}${prefix}/share/${name}
	reinplace "s|cxterm-5.0/dict|${prefix}/share/${name}|g" \
		${destroot}${prefix}/share/${name}/CXterm.ad

	# Files not installed via make
	xinstall -m 644 -W ${worksrcpath}/cxterm CanMan.b5 Compound.b5 \
		${destroot}${prefix}/share/${name}/big5
	xinstall -m 644 -W ${worksrcpath}/cxterm CanMan.gb Compound.gb \
		${destroot}${prefix}/share/${name}/gb

	# Convenience link for big5 usage
	system "ln -s ${prefix}/bin/cxterm ${destroot}${prefix}/bin/cxtermb5"

	# Wrapper script (install as CXterm.sh since CXterm would interfere
	# with cxterm on certain filesystems
	xinstall -m 755 -W ${filespath} CXterm.sh.head \
		${destroot}${prefix}/bin/CXterm.sh
	reinplace "s|@@PREFIX@@|${prefix}|g" ${destroot}${prefix}/bin/CXterm.sh
	system "cat ${worksrcpath}/scripts/CXterm.sh >> \
		${destroot}${prefix}/bin/CXterm.sh"
}

notes "
Three lines need to be added to your .xinitrc file (and to others
who wish to use kxterm):

xrdb -merge ${prefix}/share/${name}/CXterm.ad
xset fp+ ${prefix}/share/${name}/fonts
xset fp rehash

Be sure to have a look at
${prefix}/share/doc/${name}/README if the basic configuration
as set by the MacPorts install does not do enough for you
(cxterm and cxtermb5 are both installed, for GB and Big5 use,
respectively).
${prefix}/share/doc/${name}/MacPorts_ReadMe.txt also
contains this information."

platform darwin {
	patchfiles-append	patch-cxterm_Imakefile.diff
}
