# -*- coding: utf-8; mode: tcl; tab-width: 4; truncate-lines: t; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4
# $Id: Portfile 48919 2009-03-31 11:03:54Z ryandesign@macports.org $
# vim: set fileencoding=utf-8 tabstop=4 shiftwidth=4 softtabstop=4 noexpandtab filetype=tcl :

PortSystem			1.0

name				nonpareil
version				0.79
revision			1
platforms			darwin
categories			emulators
maintainers			krischik@me.com
description			a high-fidelity simulator for calculators.
long_description	Nonpareil is a high-fidelity simulator for calculators. \
					It currently supports many HP calculators models		\
					introduced between 1972 and 1982. Simulation fidelity	\
					is achieved through the use of the actual microcode of	\
					the calculators, thus in most cases the simulation		\
					behavior exactly matches that of the real calculator.	\
					In particular, numerical results will be identical,		\
					because the simulator is using the BCD arithmetic		\
					algorithms from the calculator.

homepage			http://nonpareil.brouhaha.com/
master_sites		http://nonpareil.brouhaha.com/download:prog \
					macports:nonpareil:appbundles				\
					macports:nonpareil:voyager
				
set patchversion	47826
set prog			nonpareil-${version}.tar.gz
set appbundles		nonpareil-appbundles-r${patchversion}.tar.gz

distfiles			${prog}:prog				\
					${appbundles}:appbundles

checksums			${prog} \
					md5		4274dee70d9633304194a904b2573489 \
					sha1	83bc2f57e6ece9ce19e3449cce075ef246a9f4c2 \
					rmd160	0bbf88e7c4614ac757bebbc1089804bea088d181 \
					${appbundles} \
					md5		b71f77851f4204b984b80e57c4ad7e65 \
					sha1	4798b1ae8a56275a4c2eb4df54f352c457f1ff0a \
					rmd160	f0aa0eea748297f652f08c239fe1922b9f61e31d \

depends_lib			port:glib2								\
					port:gtk2								\
					port:libxml2							\
					port:netpbm

depends_build		port:bison								\
					port:flex								\
					port:pkgconfig							\
					port:python23							\
					port:scons

patchfiles			patch-src-util.diff

worksrcdir			${name}-${version}
use_parallel_build	yes
use_configure		no
build.cmd			"scons-local/scons.py"
build.args			prefix=${prefix}
build.target

destroot.cmd		"scons-local/scons.py"
destroot.args		prefix=${prefix} destdir=${destroot}

post-extract {
	system "cd ${workpath}/${name}-${version}/scons-local; tar -xzf scons-local-0.96.90.tar.gz"
}

platform macosx {
	post-destroot {
		xinstall -d ${destroot}${applications_dir}/Nonpareil
		foreach calc {HP-21 HP-25 HP-32E HP-33C HP-34C HP-37E HP-38C HP-38E HP-41CV HP-41CX HP-45 HP-55 HP-80} {
			copy														\
				${workpath}/appbundles-r${patchversion}/${calc}.app	\
				${destroot}${applications_dir}/Nonpareil
			reinplace s|@PREFIX@|${prefix}|g \
				${destroot}${applications_dir}/Nonpareil/${calc}.app/Contents/MacOS/${calc}.command
		}
	}
}

variant voyager														\
	description "Include Voyager Models (Not GPL licenced)!"		{

	set voyager				nonpareil-voyager-r${patchversion}.tar.gz

	distfiles-append		${voyager}:voyager

	checksums-append		${voyager} \
							md5		fbb227a28045c0bf8165bba86f199ec9 \
							sha1	8a51f656a523c5739d82a35ad933f8c448be58e6 \
							rmd160	4f7fec5af3b387fd6a7df44ce0a7b019eeb4a253

	depends_build-append	port:p7zip	\
							port:netpbm

	patchfiles-append		patch-image-voyager.diff	\
							patch-kml-voyager.diff		\
							patch-rom-voyager.diff		\
							patch-src-voyager.diff

	post-patch {
		system "
			pushd ${workpath}/${name}-${version};
				cp -r -v ../voyager-r${patchversion}/* .
			popd;
		"
	}
	post-destroot {
		foreach calc {HP-11C HP-12C HP-15C HP-16C} {
			copy													\
				${workpath}/appbundles-r${patchversion}/${calc}.app	\
				${destroot}${applications_dir}/Nonpareil
			reinplace s|@PREFIX@|${prefix}|g \
				${destroot}${applications_dir}/Nonpareil/${calc}.app/Contents/MacOS/${calc}.command
		}
	}
}

variant debugger						\
	description "Include Debugger!"		{
	build.args-append			debug=yes has_debugger_gui=yes
	destroot.args-append 		debug=yes has_debugger_gui=yes
}
