# $Id: Portfile 91510 2012-04-03 21:59:59Z jeremyhu@macports.org $

PortSystem 1.0

name			itk
version			3.3
revision		3
categories		x11 tk
maintainers		nomaintainer
description		\[incr Tk\] A.K.A. \"itk\".  Object oriented extension to Tk.
long_description	${description}
homepage		http://incrtcl.sourceforge.net/itk/itk.html
platforms		darwin

master_sites		sourceforge:incrtcl:itk \
			sourceforge:tcl:tcl
dist_subdir		tcltk
distname                ${name}${version}
# Set tclv and md5 checksum to the current MacPorts Tcl port version, though port doesn't
# break if they aren't in sync.

set tclv		8.5.9

distfiles		${distname}.tar.gz:itk \
				tcl${tclv}-src.tar.gz:tcl
checksums		${name}${version}.tar.gz md5 a97c17f3cfa5e377f43073c653c501b5 \
				tcl${tclv}-src.tar.gz md5 8512d8db3233041dd68a81476906012a
depends_build           port:tk port:itcl
build.args              CPPFLAGS=-I${prefix}/include
worksrcdir              ${name}${version}

set tclconfig ${prefix}/lib

configure.env		TCLROOT=${prefix}
configure.cflags	"-I${workpath}/tcl${tclv}/generic -I${workpath}/tcl${tclv}/unix"
configure.ldflags-append	-ltcl -lX11

configure.args		--with-tcl=${tclconfig} \
			--with-itcl=${prefix}/lib/itcl3.4 \
			--with-tk=${prefix}/lib

post-patch {
	reinplace "s|@itk_LIB_SPEC@|-L${prefix}/lib -litk|g" \
                ${worksrcpath}/itkConfig.sh.in
	reinplace "s|@ITK_BUILD_LIB_SPEC@|-L${prefix}/lib -litk|g" \
                ${worksrcpath}/itkConfig.sh.in
	reinplace "s|\"@PKG_LIB_FILE@\"|.. @PKG_LIB_FILE@|g" \
                ${worksrcpath}/pkgIndex.tcl.in
}

destroot {
	set _d ${destroot}${prefix}
	set _w ${worksrcpath}
	file mkdir ${_d}/lib/itk3.3
	xinstall -m 755 ${_w}/itkConfig.sh ${_d}/lib/itk3.3

	foreach x [glob ${worksrcpath}/library/*] {
		file copy -force $x ${_d}/lib/itk3.3
        }
	file copy -force ${_w}/pkgIndex.tcl ${_d}/lib/itk3.3

	file copy -force ${_w}/libitk3.3.dylib ${_d}/lib

	file mkdir ${_d}/include
	foreach x {itk.h itkDecls.h } {
                file copy -force ${_w}/generic/$x ${_d}/include
        }
	foreach x [glob ${_w}/doc/*.n] {
		file copy -force $x ${_d}/share/man/mann
	file delete -force ${_d}/share/man/mann/Toplevel.n
	}
}
