# -*- 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 61460 2009-12-11 22:16:58Z 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			3
platforms			darwin
categories			emulators
maintainers			krischik
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				\
					http://pagesperso-orange.fr/kdntl/hp41:hpil	\
					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 \

extract.only		${prog}									\
					${appbundles}							

depends_lib			path:lib/pkgconfig/glib-2.0.pc:glib2	\
					port:gtk2								\
					port:libxml2							\
					port:libsdl_sound						\
					port:netpbm

depends_build		port:bison								\
					port:flex								\
					port:pkgconfig							\
					port:python25							\
					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 "
		pushd ${workpath}/${name}-${version}/scons-local;
			tar -xzf scons-local-0.96.90.tar.gz
		popd
	"
}

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

	extract.only-append		${voyager}

	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
}

variant hpil												\
	description "Include HP-Interface-Loop emulation (experimental) See http://pagesperso-orange.fr/kdntl/hp41/nonpareil-patch-doc.html"	{

	set hpil nonpareil-wholepatch-20090714.diff

	distfiles-append		${hpil}.bz2:hpil	

	checksums-append		${hpil}.bz2 \
	                md5     2bc700c9cb49ec4e0fe0240ab5653688 \
                    sha1    e77648269e6e8cb04f6b4b275077ed8493b451ae \
                    rmd160  ec3bea3f6eda7d29a480a880a7875d4e9fc6c8cf
	
	patchfiles-delete		patch-src-util.diff
	build.cmd				"scons"
	destroot.cmd			"scons"

	post-extract {
		system "
			bzip2 --verbose --decompress --stdout ${distpath}/nonpareil-wholepatch-20090714.diff.bz2 >${workpath}/nonpareil-wholepatch-20090714.diff;
		"
	}
	pre-patch {
		file copy ${filespath}/osx.patch ${filespath}/osx.patch.diff 
		reinplace s|@PREFIX@|${prefix}|g ${filespath}/osx.patch.diff
	}
	post-patch {
		system "
			pushd ${workpath};
				patch -p0 < ${workpath}/nonpareil-wholepatch-20090714.diff;
				pushd ${worksrcdir};
					patch -p0 < ${filespath}/osx.patch.diff;
				popd;
			popd;
		"
		file delete ${filespath}/osx.patch.diff
	}
}

