# -*- 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 56907 2009-09-03 13:10:50Z krischik@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			port: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 "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

	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!"		{
	set hpil1 nonpareil-patch-20090131.diff
	set hpil2 nonpareil-patch-20090201.diff
	set hpil3 nonpareil-patch-20090202.diff
	set hpil4 nonpareil-patch-20090208.diff
	set hpil5 nonpareil-patch-20090210.diff

	distfiles-append		${hpil1}.gz:hpil	\
							${hpil2}.gz:hpil	\
							${hpil3}.gz:hpil	\
							${hpil4}.gz:hpil	\
							${hpil5}.gz:hpil	

	checksums-append		${hpil1}.gz \
							md5		6c5e2b38172794c9d4e15fc0e6a3d0bf \
							sha1	d46f6f3e35c82b160929f15390bc62c5add6cc45 \
							rmd160	332fde37754e081c1f83c3386f4047d13aadb83c \
							${hpil2}.gz \
							md5		cdcfe2b495c9a53478924d9ca2079b62 \
							sha1	40c4edae934f5b0c23c3f6dc28646d6b38f8ab47 \
							rmd160	ef90137f54b99850e1ff32d9546e237010bdf188 \
							${hpil3}.gz \
							md5		ae9fb42887c73ab13e07083da2796a69 \
							sha1	426d34b403444aa7c6d1666ce3de44ae2e849812 \
							rmd160	f6c96fa350c5ba45ddf11428f125765175fcea1b \
							${hpil4}.gz \
							md5		d277908b12033bbe371eca4f1d13c19d \
							sha1	3c202f7a0f30bbed6f07de88e409bb43357a7e6c \
							rmd160	ab86c58b223db93ae39c4c5392b6ed64df965f57 \
							${hpil5}.gz \
							md5		c1acee0f07bac5b995d2f4a4e0ba992c \
							sha1	345b8666ac6f7999fcb4e785fbb50e1e1d40b6e4 \
							rmd160	9cc19d32e7712819a16ae61d44c0fe311ad8137f

	#patchfiles-append		osx.patch
	patchfiles-delete		patch-src-util.diff
	build.cmd				"scons"
	destroot.cmd			"scons"

	post-extract {
		foreach patch { nonpareil-patch-20090131.diff nonpareil-patch-20090201.diff nonpareil-patch-20090202.diff nonpareil-patch-20090208.diff nonpareil-patch-20090210.diff } {
			system "
				gzip --verbose --decompress --stdout ${distpath}/${patch}.gz >${workpath}/${patch};
			"
		}
	}
	post-patch {
		foreach patch { nonpareil-patch-20090131.diff nonpareil-patch-20090201.diff nonpareil-patch-20090202.diff nonpareil-patch-20090208.diff nonpareil-patch-20090210.diff } {
			system "
				pushd ${workpath};
					patch -p0 < ${workpath}/${patch}
				popd;
			"
		}
	}
}

