# $Id: Portfile,v 1.9 2006/05/24 11:29:47 takanori Exp $

#Synced with Fink, Version 1.5.1-1021

PortSystem 1.0
name		koffice
version		1.5.1
set kdeadmin	kde-admindir-full-3.5.2-2
categories	kde
maintainers	ben@opendarwin.org takanori@opendarwin.org
description	KDE office suite. \
                NB KDE sound does not work.
platforms	darwin
master_sites	kde:stable/${name}-${version}/src \
		http://ranger.befunk.com/fink/:admin \
		http://www.opendarwin.org/~takanori/mirror/${name}/${version}_${revision}/:patch
extract.suffix	.tar.bz2
use_bzip2	yes
distname	${name}-${version}
set distpatch	${name}-${version}_${revision}-tiger.patch
distfiles	${distname}.tar.bz2 ${kdeadmin}.tar.bz2:admin ${distpatch}:patch
depends_build	port:autoconf \
		port:unsermake
depends_lib	port:kdebase3 \
		port:ImageMagick \
		port:lcms \
		port:libwpd \
		port:mysql4 \
		port:ruby \
		port:wv2
#		port:python24 \ can't be found. looking for .so
#		port:postgresql8 \ can't be found. looking for .so

checksums	${distname}.tar.bz2 md5 50897bd5dfd4eba8a0d78a02003a6ec9 \
		${kdeadmin}.tar.bz2 md5 b2afdafba2c416555105667c17046e32 \
		${name}-${version}_${revision}-panther.patch md5 4d368326b6c3302e717d5d42104ddbf1 \
		${name}-${version}_${revision}-tiger.patch md5 06740e27241092328bfbbe2168ca37cf

extract.only ${distname}.tar.bz2
post-extract { system "cd ${worksrcpath} && bzcat -dc ${distpath}/${kdeadmin}.tar.bz2 | tar xf -" }

patchfiles	dp01.patch
patch		{
		cd ${worksrcpath}
		system "sed -e 's,@FINKPREFIX@,${prefix},g' ${distpath}/${distpatch} | patch -p1"
		foreach file $patchfiles {
			system "sed -e 's,@FINKPREFIX@,${prefix},g' ${portpath}/${filesdir}/${file} | patch -p1"
		}
}
post-patch      {
		reinplace "s|lib/freetype219/||g" ${worksrcpath}/environment-helper.sh
		reinplace "s|include/qt|include/qt3|g" ${worksrcpath}/environment-helper.sh
		reinplace "s|--with-ssl-dir=/usr|--with-ssl-dir=\$PREFIX|g" ${worksrcpath}/environment-helper.sh
		foreach file [glob ${worksrcpath}/admin/*] {
		    reinplace "s|-O2|-Os|g" $file
		    reinplace "s|doc/HTML|doc/kde|g" $file
		    reinplace "s|/usr/share/doc/packages/qt3/html|${prefix}/share/doc/qt3/html|g" $file
		}
		foreach file {CompileScript.sh InstallScript.sh} {
		    file copy ${portpath}/${filesdir}/${file} ${worksrcpath}
		    reinplace "s|%p|${prefix}|g" ${worksrcpath}/${file}
		    reinplace "s|%N|${name}|g" ${worksrcpath}/${file}
		    reinplace "s|%v|${version}|g" ${worksrcpath}/${file}
		    reinplace "s|%r|${revision}|g" ${worksrcpath}/${file}
		    reinplace "s|%c|${configure.args}|g" ${worksrcpath}/${file}
		    reinplace "s|%d|${destroot}|g" ${worksrcpath}/${file}
		    reinplace "s|%i|${destroot}${prefix}|g" ${worksrcpath}/${file}
		    file attributes ${worksrcpath}/${file} -permissions 0755
		}
}

configure.args --enable-mysql --with-distribution='DarwinPorts/Mac OS X' --without-arts
# (libpqxx is missing.)
# --enable-pgsql --with-pgsqlincdir=${prefix}/include/pgsql8 --with-pgsqllibdir=${prefix}/lib/pgsql8 --with-pqxx-includes=${prefix}/include --with-pqxx-libraries=${prefix}/lib 

configure	{}
build		{ system "cd ${worksrcpath} && ./CompileScript.sh" }
destroot	{ system "cd ${worksrcpath} && ./InstallScript.sh" }

post-destroot   {
		xinstall -m 755 -d ${destroot}${prefix}/share/doc/${name}
		xinstall -m 644 -W ${worksrcpath} AUTHORS COPYING COPYING.LIB INSTALL README ${destroot}${prefix}/share/doc/${name}
}

platform darwin 7 {
		distfiles-delete	${distpatch}:patch
		set distpatch		${name}-${version}_${revision}-panther.patch
		distfiles-append	${distpatch}:patch
		post-patch {
#			if {[variant_isset with-ruby]} {
			system "perl -pi -e \"s|-bundle|-bundle -bundle_loader /usr/lib/crt1.o|g\" ${worksrcpath}/admin/libtool.m4.in"
#			}
		}
}

#not tested on OSX 10.2.
platform darwin 6 {
		depends_lib-append	lib:libdl:dlcompat
		distfiles-delete	${distpatch}:patch
		set distpatch		${name}-${version}_${revision}-panther.patch
		distfiles-append	${distpatch}:patch
		post-patch {
#			if {[variant_isset with-ruby]} {
			system "perl -pi -e \"s|-bundle|-bundle -bundle_loader /usr/lib/crt1.o|g\" ${worksrcpath}/admin/libtool.m4.in"
#			}
		}
}
