# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# vim: set fileencoding=utf-8 tabstop=4 shiftwidth=4 softtabstop=4 noexpandtab filetype=tcl :

PortSystem          1.0

name                nonpareil
version             0.79
revision            8
categories          emulators
license             GPL-2
maintainers         {krischik @krischik} openmaintainer
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 \
                    sha256  3bcb2f9a829a4cad003f84a42c6f0e31a7bf527e634aea9cf13e370b6c175841 \
                    size    4761552 \
                    ${appbundles} \
                    md5     b71f77851f4204b984b80e57c4ad7e65 \
                    sha1    4798b1ae8a56275a4c2eb4df54f352c457f1ff0a \
                    rmd160  f0aa0eea748297f652f08c239fe1922b9f61e31d \
                    sha256  7242663b7debb30e8acd04657ee177d69508144d841b0b118932227f3e2f52f8 \
                    size    4301000

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

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

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

patchfiles          osx.patch                               \
                    patch-src-printer.c.diff                \
                    patch-src-util.diff                     \
                    patch-sconstruct.diff                   \
                    patch-src-sconscript.diff

use_parallel_build  yes
use_configure       no
build.cmd           ${prefix}/bin/scons
build.args          prefix=${prefix}
build.target

destroot.args       prefix=${prefix} destdir=${destroot}

post-patch {
    reinplace s|@PREFIX@|${prefix}|g ${worksrcpath}/src/SConscript
}

post-destroot {
    # avoids conflict with nss
    # ref: https://trac.macports.org/ticket/58683
    file rename ${destroot}${prefix}/bin/modutil ${destroot}${prefix}/bin/modutil-${name}
}

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 licensed)."        {

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

    distfiles-append        ${voyager}:voyager

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

    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 -W ${worksrcpath} "
            cp -R -v ../voyager-r${patchversion}/* .
        "
    }
    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 for HP-41 and Voyager Models."     {
    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.
This features is experimental and last updated 2009.
See http://pagesperso-orange.fr/kdntl/hp41/nonpareil-patch-doc.html" {

    global hpil
    set hpil nonpareil-wholepatch-20090714.diff.bz2

    # can't just add to patchfiles because this one needs -p1 but the rest -p0
    distfiles-append        ${hpil}:hpil
    master_sites-append     http://pagesperso-orange.fr/kdntl/hp41:hpil

    checksums-append        ${hpil} \
                    md5     2bc700c9cb49ec4e0fe0240ab5653688 \
                    sha1    e77648269e6e8cb04f6b4b275077ed8493b451ae \
                    rmd160  ec3bea3f6eda7d29a480a880a7875d4e9fc6c8cf

    patchfiles-delete       patch-src-util.diff

	post-patch {
        system -W ${worksrcpath} "bzcat ${distpath}/${hpil} | patch -p1"
    }
}
