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

# error: use of undeclared identifier 'CLOCK_MONOTONIC'
PortGroup           legacysupport 1.0

# error: "Define MSB_FIRST or LSB_FIRST!"
PortGroup           muniversal 1.0

name                mednafen
epoch               1
version             1.22.2
revision            1
checksums           rmd160  7dbec84f5802ac43a21646337de70ae21ca702be \
                    sha256  fad433ac694696d69ea38f6f4be1d0a6c1aa3609ec7f46ce75412be2f2df2f95 \
                    size    3270004

platforms           darwin
categories          emulators games
license             GPL-2
maintainers         nomaintainer

description         Super-fast and super-compatible emulator for many video game systems

long_description    Mednafen is a portable, argument-driven multi-system \
                    emulator using OpenGL and SDL. \
                    Mednafen has the ability to remap hotkey functions and \
                    virtual system inputs to a keyboard, a joystick, or both \
                    simultaneously.\
                    Save states are supported, as is real-time game rewinding. \
                    Screen snapshots may be taken, in the PNG file format, at \
                    the press of a button. \
                    Mednafen can record audiovisual movies in the QuickTime \
                    file format, with several different lossless codecs \
                    supported. \
                    \n \
                    \nThe following systems are supported: \
                    \n \
                    \n* Apple II/II+ \
                    \n* Atari Lynx \
                    \n* Neo Geo Pocket (Color) \
                    \n* WonderSwan \
                    \n* GameBoy (Color) \
                    \n* GameBoy Advance \
                    \n* Nintendo Entertainment System \
                    \n* Super Nintendo Entertainment System/Super Famicom \
                    \n* Virtual Boy \
                    \n* PC Engine/TurboGrafx 16 (CD) \
                    \n* SuperGrafx \
                    \n* PC-FX \
                    \n* Sega Game Gear \
                    \n* Sega Genesis/Megadrive \
                    \n* Sega Master System \
                    \n* Sega Saturn (experimental, x86_64 only) \
                    \n* Sony PlayStation \
                    \n \
                    \nRefer to the emulation module documentation for more \
                    details.

homepage            https://mednafen.github.io
master_sites        ${homepage}/releases/files/
use_xz              yes

depends_build       port:pkgconfig

depends_lib         port:gettext \
                    port:jack \
                    port:libcdio \
                    port:libiconv \
                    port:libsdl2 \
                    port:libsndfile \
                    port:zlib

worksrcdir          ${name}

patchfiles          clang-version.patch

compiler.c_standard 1999
compiler.cxx_standard   2011

# This is how the build system decides what architecture to build for.
lappend merger_configure_args(i386)     --host=i386-apple-darwin${os.version}
lappend merger_configure_args(ppc)      --host=powerpc-apple-darwin${os.version}
lappend merger_configure_args(ppc64)    --host=powerpc-apple-darwin${os.version}
lappend merger_configure_args(x86_64)   --host=x86_64-apple-darwin${os.version}

if {!([variant_exists universal] && [variant_isset universal]) && [info exists merger_configure_args(${configure.build_arch})]} {
    configure.args-append {*}$merger_configure_args(${configure.build_arch})
}

# ld: illegal text-relocation to '__ZTISt12length_error' in /usr/lib/libc++.dylib from '__ZNSt3__114__split_bufferIN8Mednafen16AddressSpaceTypeERNS_9allocatorIS2_EEEC2EmmS5_' in debug.o for architecture i386
configure.ldflags-append -read_only_relocs suppress

set docdir ${prefix}/share/doc/${subport}

post-destroot {
    xinstall -m 0755 -d ${destroot}${docdir}
    xinstall -m 0755 ${worksrcpath}/README ${destroot}${docdir}
    xinstall -m 0755 ${worksrcpath}/ChangeLog ${destroot}${docdir}
    xinstall {*}[glob -directory ${worksrcpath}/Documentation/ *.css *.html *.png] ${destroot}${docdir}
}

notes "
Mednafen works by executing the ROM file of a game console you'd like to\
emulate. Note that no ROM files are included with Mednafen, so first you must\
obtain the game console ROM file of your choice, by legal means of course.

Supported ROM file formats are listed in section 'File Formats/Expansion\
Hardware' in the Mednafen documenation at ${docdir}. Once\
you've obtained a supported type of game console ROM file, start the Mednafen\
command-line executable and use the ROM filename (including path) as an\
argument. See the documentation for more options.
"

livecheck.type      regex
livecheck.regex     ${name}-(\[0-9.\]+)${extract.suffix}