PortSystem          1.0

name                bochs
version             2.6.8
revision            2
categories          emulators
license             LGPL-2.1+
platforms           darwin
maintainers         @Nax

description         cross platform x86 and x86_64 emulator

long_description    Bochs is a highly portable open source x86 and x86_64 \
                    PC emulator written in C++, that runs on most popular \
                    platforms. It emulates the Intel x86 CPU, common I/O \
                    devices, and a custom BIOS.

homepage            http://bochs.sourceforge.net/
master_sites        sourceforge

checksums           sha256  79700ef0914a0973f62d9908ff700ef7def62d4a28ed5de418ef61f3576585ce \
                    rmd160  cf6f9a427559c79e18c208a89e7146b6e9798ea5

patchfiles          patch-.bochsrc.diff \
                    patch-cdrom_osx.cc.diff

depends_lib         port:gettext \
                    port:readline

configure.args      --exec-prefix=${prefix} \
                    --bindir=${prefix}/bin \
                    --mandir=${prefix}/share/man \
                    --enable-cpu-level=6 \
                    --enable-all-optimizations \
                    --enable-x86-64 \
                    --enable-pci \
                    --enable-vbe \
                    --enable-clgd54xx \
                    --enable-voodoo \
                    --enable-ne2000 \
                    --enable-e1000 \
                    --enable-usb \
                    --enable-usb-ohci \
                    --enable-usb-xhci \
                    --enable-cdrom \
                    --enable-logging \
                    --enable-plugins \
                    --enable-readline \
                    --with-nogui

variant debugger description {Enable bochs internal debugger} conflicts gdbstub {
    configure.args-append --enable-debugger --enable-disasm
}

variant smp description {Enable symmetric multi-processor support} conflicts gdbstub {
    configure.args-append --enable-smp
}

variant gdbstub description {Enable GDB stub debugging} conflicts smp debugger {
    configure.args-append --enable-gdb-stub
}

variant avx description {Enable AVX support} {
    configure.args-append --enable-avx --enable-evex
}

variant x11 {
    configure.args-append   --with-x11
    depends_lib-append      port:xorg-libX11 \
                            port:xorg-libsm \
                            port:xpm
}

variant sdl description {Enable SDL GUI} {
    configure.args-append   --with-sdl
    depends_lib-append      port:libsdl
}

variant sdl2 description {Enable SDL2 GUI} {
    configure.args-append   --with-sdl2
    depends_lib-append      port:libsdl2
}

variant term description {Enable text-mode GUI} {
    configure.args-append   --with-term
    depends_lib-append      port:ncurses
}

default_variants +smp +avx +sdl2 +term

post-destroot {
    reinplace "s|\$BXSHARE/|${prefix}/share/bochs/|g" \
        ${destroot}${prefix}/share/doc/bochs/bochsrc-sample.txt
}

post-activate {
    if {![file exists ${prefix}/share/bochs/bochsrc.txt]} {
        ui_msg "File ${prefix}/share/bochs/bochsrc.txt not found, installing sample configuration file"
        xinstall -m 0644 ${prefix}/share/doc/bochs/bochsrc-sample.txt ${prefix}/share/bochs/bochsrc.txt
    }
}

notes "
To prepare bochs for use:

1) Create a disk image for the emulator.
     cd ${prefix}/share/bochs
     sudo bximage (prompts will guide you)
     sudo chmod 777 <diskimg-name>

2) Remove the current 'ata0-master:' statement in ${prefix}/share/bochs/bochsrc.txt
   and replace it with the 'ata0-master:' string displayed at the end of the bximage
   process.

3) Format the disk image using FreeDOS (http://bochs.sourceforge.net/diskimages.html)
   according to the bochs documentation. (http://bochs.sourceforge.net/)

4) Now start bochs from the command line.
"

livecheck.type      regex
livecheck.url       http://sourceforge.net/projects/${name}/files/
livecheck.regex     /${name}-(\[0-9.\]+)${extract.suffix}