# $Id: Portfile,v 1.8 2006/02/20 05:57:49 jmpp Exp $

PortSystem		1.0

name			aquaterm
version			1.0.0
revision		0
categories		aqua math science
maintainers		darwinports@opendarwin.org
description		AquaTerm is a viewer that displays vector graphics on Mac OS X
long_description	AquaTerm is a viewer app that displays vector \
					graphics.  Other apps connect to AquaTerm using a \
					simple remote object messaging protocol.  By adding \
					"adapters" to legacy code very little coding is \
					needed to bring it to OS X.
platforms		darwin
homepage		http://aquaterm.sourceforge.net/
master_sites	sourceforge
distname		${name}_src.${version}
checksums	md5 aquaterm_src.1.0.0.tar.gz 937461dfefb62178bee960bfe88e0991 \
				sha1 aquaterm_src.1.0.0.tar.gz b45f84265710fb39efa6ad8dd7b89bb5b00827b2 \
				rmd160 aquaterm_src.1.0.0.tar.gz e89074ad5ab7ee610b3bc620143e895a53d8392f \
worksrcdir		.

patch {
	# gcc 4 cannot find aquaterm/AQTAdapter.h in ObjC source files.
	# adding a -I would be the right thing to do, but I'm not sure about
	# how to patch the ProjectBuilder project.
	reinplace "s|#import <aquaterm/AQTAdapter.h>|#import \"AQTAdapter.h\"|g" \
		${workpath}/aquaterm/Demo.m
	reinplace "s|#import <aquaterm/AQTAdapter.h>|#import \"AQTAdapter.h\"|g" \
		${workpath}/aquaterm/Bugs.m
	reinplace "s|#import <aquaterm/AQTAdapter.h>|#import \"AQTAdapter.h\"|g" \
		${workpath}/aquaterm/Timing.m
}

configure {
	cd ${workpath}/${name}
	reinplace "s|/Users/per/Documents/Source/aquaterm/||" \
		AquaTerm.pbproj/project.pbxproj
	reinplace "s|/tmp/AquaTerm.dst||" \
		AquaTerm.pbproj/project.pbxproj
	reinplace "s|/usr/local/lib|${prefix}/lib|" \
		AquaTerm.pbproj/project.pbxproj
	file mkdir build/include
	system "ln -s ../.. build/include/aquaterm"

	cd ${workpath}/adapters
	reinplace "s|/usr/local|${prefix}|g" \
		pgplot/ChangeLog pgplot/g77_gcc_AQT.conf pgplot/xlf_gcc_AQT.conf
	reinplace "s|\$(HOME)|${prefix}|g" \
		c/Makefile fortran/Makefile
	reinplace "s|/*<PREFIX>|${prefix}|g" \
		pgplot/g77_cc_AQT.conf pgplot/g77_gcc_AQT.conf pgplot/xlf_gcc_AQT.conf
	reinplace "s|/sw|${prefix}|g" \
		pgplot/ReadMe
}

set xcodebuilddir		build

platform darwin 7 {
	 post-extract {
	 	      cd ${workpath}/${name}
	 	      file link -symbolic AquaTermFwk-Info.plist AquaTerm.framework-Info.plist
	}
}

platform darwin 8 {
if {$xcodeversion == "2.1"} {
	set xcodebuilddir	build/Deployment
}
}

build.type		pbx
build.dir		${workpath}/${name}
build.target	-buildstyle Deployment -target AquaTerm
post-build {
	system "install_name_tool -id ${prefix}/lib/libaquaterm.1.dylib \
		${workpath}/${name}/${xcodebuilddir}/AquaTerm.framework/Versions/Current/AquaTerm"
	system "install_name_tool -change /Library/Frameworks/AquaTerm.framework/Versions/A/AquaTerm ${prefix}/lib/libaquaterm.1.dylib \
		${workpath}/${name}/${xcodebuilddir}/AquaTerm.app/Contents/MacOS/AquaTerm"
}

destroot {
	cd ${workpath}/${name}
	xinstall -d -m 0755 ${destroot}${prefix}/include/${name}
	xinstall -m 0644 AQTAdapter.h aquaterm.h \
		${destroot}${prefix}/include/${name}

	cd ${workpath}/${name}/${xcodebuilddir}
	system "ln AquaTerm.framework/Versions/Current/AquaTerm libaquaterm.1.0.0.dylib"
	xinstall -m 0755 libaquaterm.1.0.0.dylib ${destroot}${prefix}/lib
	system "ln -s libaquaterm.1.0.0.dylib \
		${destroot}${prefix}/lib/libaquaterm.dylib"
	system "ln -s libaquaterm.1.0.0.dylib \
		${destroot}${prefix}/lib/libaquaterm.1.dylib"
	xinstall -d -m 0755 ${destroot}/Applications/DarwinPorts
	system "cp -R AquaTerm.app ${destroot}/Applications/DarwinPorts"

	cd ${workpath}/adapters
	xinstall -d -m 0755 ${destroot}${prefix}/share/${name}
	system "cp -R c fortran gnuplot pgplot plplot \
		${destroot}${prefix}/share/${name}"
}

