# $Id: Portfile,v 1.5 2006/05/21 05:02:00 markd Exp $

PortSystem			1.0
name				pgplot
version				5.2.2
revision			3
categories			graphics devel
maintainers			darwinports@opendarwin.org
description			C/Fortran graphics library
long_description \
	The PGPLOT Graphics Subroutine Library is a Fortran- or C-callable, \
	device-independent graphics package for making simple scientific \
	graphs.  It is intended for making graphical images of publication \
	quality with minimum effort on the part of the user. For most \
	applications, the program can be device-independent, and the output can \
	be directed to the appropriate device at run time.

platforms			darwin

homepage			http://www.astro.caltech.edu/~tjp/pgplot/
master_sites            ftp://ftp.astro.caltech.edu/pub/pgplot/:pgplot \
                        sourceforge:aquaterm:aqt

set aqtversion		1.0.0

distfiles			${name}5.2.tar.gz:pgplot

distname			${name}5.2:pgplot \
				aquaterm_src.${aqtversion}:aqt

worksrcdir			${name}/build:pgplot
				

checksums			${name}5.2.tar.gz md5 e8a6e8d0d5ef9d1709dfb567724525ae \
				aquaterm_src.${aqtversion}.tar.gz md5 937461dfefb62178bee960bfe88e0991

depends_lib			lib:libpng:libpng lib:libz:zlib bin:g77-dp-3.4:gcc34

patchfiles			patch-makemake patch-src_grgfil.f patch-drivers.list \
					patch-pgdispd_proccom.c

post-extract {
	file mkdir ${worksrcpath}
}

pre-patch {
	file copy ${worksrcpath}/../drivers.list ${worksrcpath}/drivers.list
}

post-patch {
	reinplace "s|@@PREFIX@@|${prefix}|g" ${worksrcpath}/../src/grgfil.f
}

configure {
	cd ${worksrcpath}
	system "../makemake .. ${ppMakeMakeTarget}"
}

build.target		all

post-build {
	cd ${worksrcpath}
	system "make cpg"
}

destroot {
	xinstall -m 755 -d ${destroot}/${prefix}/share/${name} \
		${destroot}/${prefix}/share/doc/${name}
	xinstall -m 644 -W ${worksrcpath} grfont.dat rgb.txt \
		${destroot}/${prefix}/share/${name}
	xinstall -m 644 -W ${worksrcpath} libpgplot.a libcpgplot.a \
		${destroot}/${prefix}/lib
	system "ranlib ${destroot}/${prefix}/lib/libpgplot.a \
		${destroot}/${prefix}/lib/libcpgplot.a"
	xinstall -m 644 -W ${worksrcpath} cpgplot.h ${destroot}/${prefix}/include
	xinstall -m 644 -W ${worksrcpath} pgplot.doc ../copyright.notice \
		${destroot}/${prefix}/share/doc/${name}
	if {[variant_isset x11]} {
		xinstall -m 755 -W ${worksrcpath} pgdisp pgxwin_server \
			${destroot}/${prefix}/bin
	}
}

variant x11 {
	depends_lib-append	lib:libX11:XFree86

	patchfiles-append	patch-drivers_x11.list
}

variant darwin {
	global ppMakeMakeTarget
	set ppMakeMakeTarget	darwin
	patchfiles-append		patch-sys_darwin_aaaread.me \
							patch-sys_darwin_g77_gcc.conf
	post-patch {
		reinplace "s|@@PREFIX@@|${prefix}|g" \
			${worksrcpath}/../sys_darwin/g77_gcc.conf
		reinplace "s|@@X11PREFIX@@|${x11prefix}|g" \
			${worksrcpath}/../sys_darwin/g77_gcc.conf
	}
}

variant aqt {
# Variant that adds aquaterm driver support
	distfiles-append	aquaterm_src.${aqtversion}.tar.gz:aqt
	patchfiles-append	patch-drivers.list_aqt \
						patch-sys_darwin_g77_gcc.conf_aqt \
						patch-makemake_aqt \
						patch-aqdriv.m_aqt
	
	pre-patch {
		file copy ${workpath}/adapters/pgplot/aqdriv.m ${workpath}/pgplot/drivers/
	}
}
