# -*- 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

PortSystem          1.0

name                x48
version             0.6.4
revision            1

categories          emulators math
platforms           darwin
license             GPL-2
maintainers         {puffin.lb.shuttle.de:michael.klein @mklein-de} openmaintainer

description         HP48 calculator emulator
long_description \
    This emulator is capable of providing a faithful \
    replication of the HP48. It also has a debugger for the \
    saturn processor.

homepage            https://sourceforge.net/projects/x48.berlios/
master_sites        sourceforge:x48.berlios

use_bzip2           yes

extract.only        ${distname}${extract.suffix}

patchfiles          patch-src-debugger.c.diff \
                    patch-src-emulate.c.diff

checksums           ${distname}${extract.suffix} \
                    rmd160  a5d7ddb4eb47426c639941d8cf53926bd3451ef5 \
                    sha256  dd42fb3dfde860abb758f8e6d5ccd01845bbf0dcd808b87786eec3ef7091067f \
                    size    227991

depends_build       port:autoconf \
                    port:automake \
                    port:pkgconfig \
                    port:xorg-libXt

depends_lib         port:readline \
                    port:xorg-libXext

extract.mkdir       yes

set gxrom           gxrom-r
set sxrom           sxrom-j

set docdir          ${prefix}/share/doc/${name}
set romdir          ${prefix}/share/${name}

pre-configure {
    system "cd ${worksrcpath} && ./autogen.sh"
}

post-destroot {
    xinstall -d ${destroot}${docdir}
    copy ${worksrcpath}/README ${destroot}${docdir}
}

default_variants    +roms

variant roms description "download and install ROM images" {
    distfiles-append ${gxrom}.bz2
    checksums-append ${gxrom}.bz2 \
        rmd160  1dafce5902310161cb60f3dde401941565fd031c \
        sha256  f89eb7bf979e62db53d436e3218b963c693f66c52797218c01d6552f1bbe014f \
        size    332316

    distfiles-append ${sxrom}.bz2
    checksums-append ${sxrom}.bz2 \
        rmd160  8fb5f6f1284fb2dc15aa5d7603bbe3bfb8f30638 \
        sha256  abd7f59cc07dcd22d1ac62bff901172d37e1ea4f01e1afdd099aa4bcf77e14a8 \
        size    193349

    post-destroot {
        xinstall -d ${destroot}${romdir}
        system "bzcat ${distpath}/${gxrom}.bz2 > ${destroot}${romdir}/${gxrom}"
        system "bzcat ${distpath}/${sxrom}.bz2 > ${destroot}${romdir}/${sxrom}"
    }
}

if {[variant_isset roms]} {
    notes "Calculator ROMS have been installed to ${romdir}
Execute one of the commands below to initialize the emulator:

x48 -initialize -rom ${romdir}/${gxrom}
x48 -initialize -rom ${romdir}/${sxrom}
"
} else {
    notes "No calculator ROMS have been installed. To use this emulator you need to
obtain a ROM dump first.

Check ${docdir}/README for details
"
}

livecheck.distname  ${name}
