# $Id: Portfile 119188 2014-04-19 15:23:06Z raimue@macports.org $

PortSystem 1.0

name                    qemu
version                 2.0.0
categories              emulators
license                 GPL-2+
platforms               darwin
maintainers             raimue openmaintainer

description             Emulator for various architectures
long_description        QEMU is a generic and open source machine emulator. \
                        It can run OSes and programs made for one machine on a \
                        different machine. By using dynamic translation, it \
                        achieves very good performance.

homepage                http://qemu.org
master_sites            ${homepage}/download
use_bzip2 yes

checksums               rmd160  ecd05e036431c14930ae2455a032495dd7ebaf85 \
                        sha256  60cc1aa0cad39cec891f970bed60ca8a484f071adad4943123599ac223543a3b

patchfiles              patch-configure.diff

depends_build           port:texinfo \
                        port:libtool \
                        port:pkgconfig

# python is only used for build scripts, no linking
depends_build-append    port:python27
license_noconflict      python27

depends_lib             port:curl \
                        path:lib/pkgconfig/glib-2.0.pc:glib2 \
                        port:zlib \
                        path:lib/pkgconfig/pixman-1.pc:libpixman

# see #39058
compiler.blacklist      gcc-4.0 gcc-3.3 apple-gcc-4.0

# Select compiler
configure.args          --cpu=${configure.build_arch} \
                        --cc=${configure.cc} \
                        --objcc=${configure.objc} \
                        --host-cc=${configure.cc} \
                        --python=${prefix}/bin/python2.7 \

# Select features
configure.args-append   --disable-cocoa \
                        --disable-curses \
                        --disable-sdl \
                        --disable-gtk \
                        --enable-curl \
                        --enable-uuid \
                        --enable-vhdx \
                        --with-system-pixman \
                        --disable-attr \
                        --disable-vde \
                        --disable-brlapi \
                        --disable-bluez \
                        --disable-cap-ng \
                        --disable-spice \
                        --disable-libiscsi \
                        --disable-rbd \
                        --disable-smartcard-nss \
                        --disable-libusb \
                        --disable-usb-redir \
                        --disable-seccomp \
                        --disable-glusterfs \
                        --disable-rdma \
                        --disable-libssh2 \
                        --disable-vnc

# libtool: unknown option character `-' in: --mode=compile
configure.env-append   LIBTOOL=${prefix}/bin/glibtool

set target_list {}
pre-configure {
    configure.args-append --target-list=${target_list}
}

# disable silent rules
build.args-append       V=1

default_variants        +usb

foreach t {i386 x86_64 alpha arm cris lm32 m68k {microblaze microblazeel} {mips mipsel mips64 mips64el} \
           or32 {ppc ppcemb ppc64} {sh4 sh4eb} {sparc sparc64} s390x {xtensa xtensaeb} unicore32} {
    variant target_[lindex $t 0] description "Add target support for [join $t {, }]" "append target_list \",[join $t -softmmu,]-softmmu\""
}
default_variants-append +target_i386 +target_x86_64

if {![variant_isset curses]} {
    default_variants-append +cocoa
}

variant cocoa description {Use the native Mac OS X graphical user interface} conflicts curses {
    configure.args-replace  --disable-cocoa --enable-cocoa
}

variant curses description {Use the curses text-only user interface} conflicts cocoa {
    configure.args-replace --disable-curses --enable-curses
    depends_lib-append      port:ncurses
}

# XXX: Builds, but does not work as expected on runtime
#variant gtk3 description {Build GTK+ GUI for GTK+ 3 (experimental)} conflicts cocoa {
#    configure.args-replace --disable-gtk --enable-gtk
#    configure.args-append --with-gtkabi=3.0
#    depends_lib-append     port:gtk3 port:vte
#}

# XXX: Build broken due to missing port for vte 0.24 / pkg-config package vte
#variant gtk2 description {Use the GTK+ 2 graphical user interface} conflicts cocoa curses gtk3 {
#    configure.args-replace --disable-gtk --enable-gtk
#    configure.args-append  --with-gtkabi=2.0
#    depends_lib-append     port:gtk2 port:vte
#}

# XXX: Build broken due to missing X11 symbols
#variant sdl description {Use the SDL graphical user interface} conflicts cocoa curses gtk2 gtk3 {
#    configure.args-replace --disable-sdl --enable-sdl
#    depends_lib-append      port:libsdl
#}

variant usb description {Support forwarding of USB devices to the guest} {
    configure.args-replace  --disable-libusb --enable-libusb
    depends_lib-append      path:lib/pkgconfig/libusb-1.0.pc:libusb
}

variant vnc description {Support VNC server} {
    configure.args-replace  --disable-vnc --enable-vnc
    configure.args-append   --enable-vnc-tls --enable-vnc-ws --enable-vnc-sasl --enable-vnc-jpeg --enable-vnc-png
    depends_lib-append      port:gnutls \
                            port:cyrus-sasl2 \
                            path:lib/libjpeg.dylib:jpeg \
                            port:libpng
}

variant vde description {Support VDE networking} {
    configure.args-replace  --disable-vde --enable-vde
    depends_lib-append      port:vde2
}

variant ssh description {Support remote block devices over SSH} {
    configure.args-replace  --disable-libssh2 --enable-libssh2
    depends_lib-append      port:libssh2
}

# Default universal variant does not work
universal_variant       no

platform darwin 8 {
    depends_build-append port:gmake
    build.cmd ${prefix}/bin/gmake
}

livecheck.type  regex
livecheck.url   [lindex ${master_sites} 0]
livecheck.regex ${name}-(\\d+(?:\\.\\d+)*)(?:-\\d+)*\\.tar
